From 35f8181bdbdeeb8a0dbb6f70c26ec417cb4e83b9 Mon Sep 17 00:00:00 2001 From: "Afriza N. Arief" Date: Sat, 25 Jul 2020 14:04:06 +0700 Subject: [PATCH] Update to obs-websocket 4.8.0 --- README.md | 2 +- codegen/protocol.py | 3 + event_utils.go | 9 ++ events_scene_items.go | 160 +++++++++++++++++++ events_sources.go | 140 +--------------- events_transitions.go | 50 ++++++ requests_general.go | 117 +++++++++++++- requests_scene_items.go | 122 +++++++++----- requests_scenes.go | 296 +++++++++++++++++++++++++++++++++- requests_sources.go | 344 ++++++++++++++++++++++++++++++++++++++-- requests_streaming.go | 14 +- requests_transitions.go | 92 +++++++++++ 12 files changed, 1154 insertions(+), 195 deletions(-) create mode 100644 events_scene_items.go diff --git a/README.md b/README.md index 6970926..7488b74 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![GoDoc](https://godoc.org/github.com/christopher-dG/go-obs-websocket?status.svg)](https://godoc.org/github.com/christopher-dG/go-obs-websocket) `obsws` provides client functionality for [`obs-websocket`](https://github.com/Palakis/obs-websocket). -Currently, the target version is `4.4`. +Currently, the target version is `4.8`. ## Installation diff --git a/codegen/protocol.py b/codegen/protocol.py index 154b588..45964ed 100644 --- a/codegen/protocol.py +++ b/codegen/protocol.py @@ -26,12 +26,14 @@ "string": "string", "array": "[]interface{}", "array": "[]string", + "string | object": "interface{}", "object": "map[string]interface{}", "output": "map[string]interface{}", "array": "[]map[string]interface{}", "array": "[]map[string]interface{}", "array": "[]*Scene", "array": "[]*SceneItem", + "array": "[]*SceneItemTransform", "obsstats": "*OBSStats", "sceneitemtransform": "*SceneItemTransform", } @@ -385,6 +387,7 @@ def newlinify(s: str, comment: bool = True) -> str: def optional_type(s: str) -> Tuple[str, bool]: """Determine if a type is optional and parse the actual type name.""" + s = s.lower() if s.endswith("(optional)"): return s[: s.find("(optional)")].strip(), True return s, False diff --git a/event_utils.go b/event_utils.go index 2dad571..d3222d7 100644 --- a/event_utils.go +++ b/event_utils.go @@ -12,6 +12,8 @@ var eventMap = map[string]func() Event{ "TransitionListChanged": func() Event { return &TransitionListChangedEvent{} }, "TransitionDurationChanged": func() Event { return &TransitionDurationChangedEvent{} }, "TransitionBegin": func() Event { return &TransitionBeginEvent{} }, + "TransitionEnd": func() Event { return &TransitionEndEvent{} }, + "TransitionVideoEnd": func() Event { return &TransitionVideoEndEvent{} }, "ProfileChanged": func() Event { return &ProfileChangedEvent{} }, "ProfileListChanged": func() Event { return &ProfileListChangedEvent{} }, "StreamStarting": func() Event { return &StreamStartingEvent{} }, @@ -47,6 +49,7 @@ var eventMap = map[string]func() Event{ "SceneItemAdded": func() Event { return &SceneItemAddedEvent{} }, "SceneItemRemoved": func() Event { return &SceneItemRemovedEvent{} }, "SceneItemVisibilityChanged": func() Event { return &SceneItemVisibilityChangedEvent{} }, + "SceneItemLockChanged": func() Event { return &SceneItemLockChangedEvent{} }, "SceneItemTransformChanged": func() Event { return &SceneItemTransformChangedEvent{} }, "SceneItemSelected": func() Event { return &SceneItemSelectedEvent{} }, "SceneItemDeselected": func() Event { return &SceneItemDeselectedEvent{} }, @@ -74,6 +77,10 @@ func derefEvent(e Event) Event { return *e case *TransitionBeginEvent: return *e + case *TransitionEndEvent: + return *e + case *TransitionVideoEndEvent: + return *e case *ProfileChangedEvent: return *e case *ProfileListChangedEvent: @@ -144,6 +151,8 @@ func derefEvent(e Event) Event { return *e case *SceneItemVisibilityChangedEvent: return *e + case *SceneItemLockChangedEvent: + return *e case *SceneItemTransformChangedEvent: return *e case *SceneItemSelectedEvent: diff --git a/events_scene_items.go b/events_scene_items.go new file mode 100644 index 0000000..d5d0abc --- /dev/null +++ b/events_scene_items.go @@ -0,0 +1,160 @@ +package obsws + +// This file is automatically generated. +// https://github.com/christopher-dG/go-obs-websocket/blob/master/codegen/protocol.py + +// SourceOrderChangedEvent : Scene items have been reordered. +// +// Since obs-websocket version: 4.0.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sourceorderchanged +type SourceOrderChangedEvent struct { + // Name of the scene where items have been reordered. + // Required: Yes. + SceneName string `json:"scene-name"` + // Ordered list of scene items. + // Required: Yes. + SceneItems []map[string]interface{} `json:"scene-items"` + // Item source name. + // Required: Yes. + SceneItemsSourceName string `json:"scene-items.*.source-name"` + // Scene item unique ID. + // Required: Yes. + SceneItemsItemID int `json:"scene-items.*.item-id"` + _event `json:",squash"` +} + +// SceneItemAddedEvent : An item has been added to the current scene. +// +// Since obs-websocket version: 4.0.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemadded +type SceneItemAddedEvent struct { + // Name of the scene. + // Required: Yes. + SceneName string `json:"scene-name"` + // Name of the item added to the scene. + // Required: Yes. + ItemName string `json:"item-name"` + // Scene item ID. + // Required: Yes. + ItemID int `json:"item-id"` + _event `json:",squash"` +} + +// SceneItemRemovedEvent : An item has been removed from the current scene. +// +// Since obs-websocket version: 4.0.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemremoved +type SceneItemRemovedEvent struct { + // Name of the scene. + // Required: Yes. + SceneName string `json:"scene-name"` + // Name of the item removed from the scene. + // Required: Yes. + ItemName string `json:"item-name"` + // Scene item ID. + // Required: Yes. + ItemID int `json:"item-id"` + _event `json:",squash"` +} + +// SceneItemVisibilityChangedEvent : An item's visibility has been toggled. +// +// Since obs-websocket version: 4.0.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemvisibilitychanged +type SceneItemVisibilityChangedEvent struct { + // Name of the scene. + // Required: Yes. + SceneName string `json:"scene-name"` + // Name of the item in the scene. + // Required: Yes. + ItemName string `json:"item-name"` + // Scene item ID. + // Required: Yes. + ItemID int `json:"item-id"` + // New visibility state of the item. + // Required: Yes. + ItemVisible bool `json:"item-visible"` + _event `json:",squash"` +} + +// SceneItemLockChangedEvent : An item's locked status has been toggled. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemlockchanged +type SceneItemLockChangedEvent struct { + // Name of the scene. + // Required: Yes. + SceneName string `json:"scene-name"` + // Name of the item in the scene. + // Required: Yes. + ItemName string `json:"item-name"` + // Scene item ID. + // Required: Yes. + ItemID int `json:"item-id"` + // New locked state of the item. + // Required: Yes. + ItemLocked bool `json:"item-locked"` + _event `json:",squash"` +} + +// SceneItemTransformChangedEvent : An item's transform has been changed. +// +// Since obs-websocket version: 4.6.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemtransformchanged +type SceneItemTransformChangedEvent struct { + // Name of the scene. + // Required: Yes. + SceneName string `json:"scene-name"` + // Name of the item in the scene. + // Required: Yes. + ItemName string `json:"item-name"` + // Scene item ID. + // Required: Yes. + ItemID int `json:"item-id"` + // Scene item transform properties. + // Required: Yes. + Transform *SceneItemTransform `json:"transform"` + _event `json:",squash"` +} + +// SceneItemSelectedEvent : A scene item is selected. +// +// Since obs-websocket version: 4.6.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemselected +type SceneItemSelectedEvent struct { + // Name of the scene. + // Required: Yes. + SceneName string `json:"scene-name"` + // Name of the item in the scene. + // Required: Yes. + ItemName string `json:"item-name"` + // Name of the item in the scene. + // Required: Yes. + ItemID int `json:"item-id"` + _event `json:",squash"` +} + +// SceneItemDeselectedEvent : A scene item is deselected. +// +// Since obs-websocket version: 4.6.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemdeselected +type SceneItemDeselectedEvent struct { + // Name of the scene. + // Required: Yes. + SceneName string `json:"scene-name"` + // Name of the item in the scene. + // Required: Yes. + ItemName string `json:"item-name"` + // Name of the item in the scene. + // Required: Yes. + ItemID int `json:"item-id"` + _event `json:",squash"` +} diff --git a/events_sources.go b/events_sources.go index 70102be..948fb1b 100644 --- a/events_sources.go +++ b/events_sources.go @@ -127,7 +127,10 @@ type SourceRenamedEvent struct { // New source name. // Required: Yes. NewName string `json:"newName"` - _event `json:",squash"` + // Type of source (input, scene, filter, transition). + // Required: Yes. + SourceType string `json:"sourceType"` + _event `json:",squash"` } // SourceFilterAddedEvent : A filter was added to a source. @@ -207,138 +210,3 @@ type SourceFiltersReorderedEvent struct { FiltersType string `json:"filters.*.type"` _event `json:",squash"` } - -// SourceOrderChangedEvent : Scene items have been reordered. -// -// Since obs-websocket version: 4.0.0. -// -// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sourceorderchanged -type SourceOrderChangedEvent struct { - // Name of the scene where items have been reordered. - // Required: Yes. - SceneName string `json:"scene-name"` - // Ordered list of scene items. - // Required: Yes. - SceneItems []map[string]interface{} `json:"scene-items"` - // Item source name. - // Required: Yes. - SceneItemsSourceName string `json:"scene-items.*.source-name"` - // Scene item unique ID. - // Required: Yes. - SceneItemsItemID int `json:"scene-items.*.item-id"` - _event `json:",squash"` -} - -// SceneItemAddedEvent : An item has been added to the current scene. -// -// Since obs-websocket version: 4.0.0. -// -// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemadded -type SceneItemAddedEvent struct { - // Name of the scene. - // Required: Yes. - SceneName string `json:"scene-name"` - // Name of the item added to the scene. - // Required: Yes. - ItemName string `json:"item-name"` - // Scene item ID. - // Required: Yes. - ItemID int `json:"item-id"` - _event `json:",squash"` -} - -// SceneItemRemovedEvent : An item has been removed from the current scene. -// -// Since obs-websocket version: 4.0.0. -// -// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemremoved -type SceneItemRemovedEvent struct { - // Name of the scene. - // Required: Yes. - SceneName string `json:"scene-name"` - // Name of the item removed from the scene. - // Required: Yes. - ItemName string `json:"item-name"` - // Scene item ID. - // Required: Yes. - ItemID int `json:"item-id"` - _event `json:",squash"` -} - -// SceneItemVisibilityChangedEvent : An item's visibility has been toggled. -// -// Since obs-websocket version: 4.0.0. -// -// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemvisibilitychanged -type SceneItemVisibilityChangedEvent struct { - // Name of the scene. - // Required: Yes. - SceneName string `json:"scene-name"` - // Name of the item in the scene. - // Required: Yes. - ItemName string `json:"item-name"` - // Scene item ID. - // Required: Yes. - ItemID int `json:"item-id"` - // New visibility state of the item. - // Required: Yes. - ItemVisible bool `json:"item-visible"` - _event `json:",squash"` -} - -// SceneItemTransformChangedEvent : An item's transform has been changed. -// -// Since obs-websocket version: 4.6.0. -// -// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemtransformchanged -type SceneItemTransformChangedEvent struct { - // Name of the scene. - // Required: Yes. - SceneName string `json:"scene-name"` - // Name of the item in the scene. - // Required: Yes. - ItemName string `json:"item-name"` - // Scene item ID. - // Required: Yes. - ItemID int `json:"item-id"` - // Scene item transform properties. - // Required: Yes. - Transform *SceneItemTransform `json:"transform"` - _event `json:",squash"` -} - -// SceneItemSelectedEvent : A scene item is selected. -// -// Since obs-websocket version: 4.6.0. -// -// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemselected -type SceneItemSelectedEvent struct { - // Name of the scene. - // Required: Yes. - SceneName string `json:"scene-name"` - // Name of the item in the scene. - // Required: Yes. - ItemName string `json:"item-name"` - // Name of the item in the scene. - // Required: Yes. - ItemID int `json:"item-id"` - _event `json:",squash"` -} - -// SceneItemDeselectedEvent : A scene item is deselected. -// -// Since obs-websocket version: 4.6.0. -// -// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#sceneitemdeselected -type SceneItemDeselectedEvent struct { - // Name of the scene. - // Required: Yes. - SceneName string `json:"scene-name"` - // Name of the item in the scene. - // Required: Yes. - ItemName string `json:"item-name"` - // Name of the item in the scene. - // Required: Yes. - ItemID int `json:"item-id"` - _event `json:",squash"` -} diff --git a/events_transitions.go b/events_transitions.go index a529fc0..5c3054b 100644 --- a/events_transitions.go +++ b/events_transitions.go @@ -46,6 +46,56 @@ type TransitionBeginEvent struct { // Transition name. // Required: Yes. Name string `json:"name"` + // Transition type. + // Required: Yes. + Type_ string `json:"type"` + // Transition duration (in milliseconds). + // Will be -1 for any transition with a fixed duration, such as a Stinger, due to limitations of the OBS API. + // Required: Yes. + Duration int `json:"duration"` + // Source scene of the transition. + // Required: Yes. + FromScene string `json:"from-scene"` + // Destination scene of the transition. + // Required: Yes. + ToScene string `json:"to-scene"` + _event `json:",squash"` +} + +// TransitionEndEvent : A transition (other than "cut") has ended. +// Please note that the `from-scene` field is not available in TransitionEnd. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#transitionend +type TransitionEndEvent struct { + // Transition name. + // Required: Yes. + Name string `json:"name"` + // Transition type. + // Required: Yes. + Type_ string `json:"type"` + // Transition duration (in milliseconds). + // Required: Yes. + Duration int `json:"duration"` + // Destination scene of the transition. + // Required: Yes. + ToScene string `json:"to-scene"` + _event `json:",squash"` +} + +// TransitionVideoEndEvent : A stinger transition has finished playing its video. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#transitionvideoend +type TransitionVideoEndEvent struct { + // Transition name. + // Required: Yes. + Name string `json:"name"` + // Transition type. + // Required: Yes. + Type_ string `json:"type"` // Transition duration (in milliseconds). // Required: Yes. Duration int `json:"duration"` diff --git a/requests_general.go b/requests_general.go index 111eac6..a93b8a3 100644 --- a/requests_general.go +++ b/requests_general.go @@ -105,7 +105,10 @@ type GetVersionResponse struct { // List of available request types, formatted as a comma-separated list string (e.g. : "Method1,Method2,Method3"). // Required: Yes. AvailableRequests string `json:"available-requests"` - _response `json:",squash"` + // List of supported formats for features that use image export (like the TakeSourceScreenshot request type) formatted as a comma-separated list string. + // Required: Yes. + SupportedImageExportFormats string `json:"supported-image-export-formats"` + _response `json:",squash"` } // GetAuthRequiredRequest : Tells the client if authentication is required @@ -868,3 +871,115 @@ type GetVideoInfoResponse struct { ColorRange string `json:"colorRange"` _response `json:",squash"` } + +// OpenProjectorRequest : Open a projector window or create a projector on a monitor +// Requires OBS v24.0.4 or newer. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#openprojector +type OpenProjectorRequest struct { + // Type of projector: Preview (default), Source, Scene, StudioProgram, or Multiview (case insensitive). + // Required: No. + Type_ string `json:"type"` + // Monitor to open the projector on. + // If -1 or omitted, opens a window. + // Required: No. + Monitor int `json:"monitor"` + // Size and position of the projector window (only if monitor is -1). + // Encoded in Base64 using Qt's geometry encoding (https://doc.qt.io/qt-5/qwidget.html#saveGeometry). + // Corresponds to OBS's saved projectors. + // Required: No. + Geometry string `json:"geometry"` + // Name of the source or scene to be displayed (ignored for other projector types). + // Required: No. + Name string `json:"name"` + _request `json:",squash"` + response chan OpenProjectorResponse +} + +// NewOpenProjectorRequest returns a new OpenProjectorRequest. +func NewOpenProjectorRequest( + _type string, + monitor int, + geometry string, + name string, +) OpenProjectorRequest { + return OpenProjectorRequest{ + _type, + monitor, + geometry, + name, + _request{ + ID_: GetMessageID(), + Type_: "OpenProjector", + err: make(chan error, 1), + }, + make(chan OpenProjectorResponse, 1), + } +} + +// Send sends the request. +func (r *OpenProjectorRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp OpenProjectorResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r OpenProjectorRequest) Receive() (OpenProjectorResponse, error) { + if !r.sent { + return OpenProjectorResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return OpenProjectorResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return OpenProjectorResponse{}, err + case <-time.After(receiveTimeout): + return OpenProjectorResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r OpenProjectorRequest) SendReceive(c Client) (OpenProjectorResponse, error) { + if err := r.Send(c); err != nil { + return OpenProjectorResponse{}, err + } + return r.Receive() +} + +// OpenProjectorResponse : Response for OpenProjectorRequest. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#openprojector +type OpenProjectorResponse struct { + _response `json:",squash"` +} diff --git a/requests_scene_items.go b/requests_scene_items.go index b54d9d1..deb6bfb 100644 --- a/requests_scene_items.go +++ b/requests_scene_items.go @@ -15,13 +15,19 @@ import ( // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#getsceneitemproperties type GetSceneItemPropertiesRequest struct { - // the name of the scene that the source item belongs to. + // Name of the scene the scene item belongs to. // Defaults to the current scene. // Required: No. SceneName string `json:"scene-name"` - // The name of the source. + // Scene Item name (if this field is a string) or specification (if it is an object). // Required: Yes. - Item string `json:"item"` + Item interface{} `json:"item"` + // Scene Item name (if the `item` field is an object). + // Required: No. + ItemName string `json:"item.name"` + // Scene Item ID (if the `item` field is an object). + // Required: No. + ItemID int `json:"item.id"` _request `json:",squash"` response chan GetSceneItemPropertiesResponse } @@ -29,11 +35,15 @@ type GetSceneItemPropertiesRequest struct { // NewGetSceneItemPropertiesRequest returns a new GetSceneItemPropertiesRequest. func NewGetSceneItemPropertiesRequest( sceneName string, - item string, + item interface{}, + itemName string, + itemID int, ) GetSceneItemPropertiesRequest { return GetSceneItemPropertiesRequest{ sceneName, item, + itemName, + itemID, _request{ ID_: GetMessageID(), Type_: "GetSceneItemProperties", @@ -105,9 +115,12 @@ func (r GetSceneItemPropertiesRequest) SendReceive(c Client) (GetSceneItemProper // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#getsceneitemproperties type GetSceneItemPropertiesResponse struct { - // The name of the source. + // Scene Item name. // Required: Yes. Name string `json:"name"` + // Scene Item ID. + // Required: Yes. + ItemID int `json:"itemId"` // The x position of the source from the left. // Required: Yes. PositionX int `json:"position.x"` @@ -141,6 +154,9 @@ type GetSceneItemPropertiesResponse struct { // If the source is visible. // Required: Yes. Visible bool `json:"visible"` + // If the source is muted. + // Required: Yes. + Muted bool `json:"muted"` // If the source's transform is locked. // Required: Yes. Locked bool `json:"locked"` @@ -168,8 +184,18 @@ type GetSceneItemPropertiesResponse struct { Width float64 `json:"width"` // Scene item height (base source height multiplied by the vertical scaling factor). // Required: Yes. - Height float64 `json:"height"` - _response `json:",squash"` + Height float64 `json:"height"` + // The point on the source that the item is manipulated from. + // The sum of 1=Left or 2=Right, and 4=Top or 8=Bottom, or omit to center on that axis. + // Required: Yes. + Alignment int `json:"alignment"` + // Name of the item's parent (if this item belongs to a group). + // Required: No. + ParentGroupName string `json:"parentGroupName"` + // List of children (if this item is a group). + // Required: No. + GroupChildren []*SceneItemTransform `json:"groupChildren"` + _response `json:",squash"` } // SetSceneItemPropertiesRequest : Sets the scene specific properties of a source @@ -180,13 +206,19 @@ type GetSceneItemPropertiesResponse struct { // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setsceneitemproperties type SetSceneItemPropertiesRequest struct { - // the name of the scene that the source item belongs to. + // Name of the scene the source item belongs to. // Defaults to the current scene. // Required: No. SceneName string `json:"scene-name"` - // The name of the source. + // Scene Item name (if this field is a string) or specification (if it is an object). // Required: Yes. - Item string `json:"item"` + Item interface{} `json:"item"` + // Scene Item name (if the `item` field is an object). + // Required: No. + ItemName string `json:"item.name"` + // Scene Item ID (if the `item` field is an object). + // Required: No. + ItemID int `json:"item.id"` // The new x position of the source. // Required: No. PositionX int `json:"position.x"` @@ -246,7 +278,9 @@ type SetSceneItemPropertiesRequest struct { // NewSetSceneItemPropertiesRequest returns a new SetSceneItemPropertiesRequest. func NewSetSceneItemPropertiesRequest( sceneName string, - item string, + item interface{}, + itemName string, + itemID int, positionX int, positionY int, positionAlignment int, @@ -267,6 +301,8 @@ func NewSetSceneItemPropertiesRequest( return SetSceneItemPropertiesRequest{ sceneName, item, + itemName, + itemID, positionX, positionY, positionAlignment, @@ -363,13 +399,19 @@ type SetSceneItemPropertiesResponse struct { // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#resetsceneitem type ResetSceneItemRequest struct { - // Name of the scene the source belongs to. + // Name of the scene the scene item belongs to. // Defaults to the current scene. // Required: No. SceneName string `json:"scene-name"` - // Name of the source item. + // Scene Item name (if this field is a string) or specification (if it is an object). // Required: Yes. - Item string `json:"item"` + Item interface{} `json:"item"` + // Scene Item name (if the `item` field is an object). + // Required: No. + ItemName string `json:"item.name"` + // Scene Item ID (if the `item` field is an object). + // Required: No. + ItemID int `json:"item.id"` _request `json:",squash"` response chan ResetSceneItemResponse } @@ -377,11 +419,15 @@ type ResetSceneItemRequest struct { // NewResetSceneItemRequest returns a new ResetSceneItemRequest. func NewResetSceneItemRequest( sceneName string, - item string, + item interface{}, + itemName string, + itemID int, ) ResetSceneItemRequest { return ResetSceneItemRequest{ sceneName, item, + itemName, + itemID, _request{ ID_: GetMessageID(), Type_: "ResetSceneItem", @@ -462,30 +508,30 @@ type ResetSceneItemResponse struct { // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setsceneitemrender type SetSceneItemRenderRequest struct { - // Scene item name in the specified scene. + // Name of the scene the scene item belongs to. + // Defaults to the currently active scene. + // Required: No. + SceneName string `json:"scene-name"` + // Scene Item name. // Required: Yes. Source string `json:"source"` // true = shown ; false = hidden. // Required: Yes. - Render bool `json:"render"` - // Name of the scene where the source resides. - // Defaults to the currently active scene. - // Required: No. - SceneName string `json:"scene-name"` - _request `json:",squash"` - response chan SetSceneItemRenderResponse + Render bool `json:"render"` + _request `json:",squash"` + response chan SetSceneItemRenderResponse } // NewSetSceneItemRenderRequest returns a new SetSceneItemRenderRequest. func NewSetSceneItemRenderRequest( + sceneName string, source string, render bool, - sceneName string, ) SetSceneItemRenderRequest { return SetSceneItemRenderRequest{ + sceneName, source, render, - sceneName, _request{ ID_: GetMessageID(), Type_: "SetSceneItemRender", @@ -566,11 +612,11 @@ type SetSceneItemRenderResponse struct { // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setsceneitemposition type SetSceneItemPositionRequest struct { - // The name of the scene that the source item belongs to. + // Name of the scene the scene item belongs to. // Defaults to the current scene. // Required: No. SceneName string `json:"scene-name"` - // The name of the source item. + // Scene Item name. // Required: Yes. Item string `json:"item"` // X coordinate. @@ -675,11 +721,11 @@ type SetSceneItemPositionResponse struct { // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setsceneitemtransform type SetSceneItemTransformRequest struct { - // The name of the scene that the source item belongs to. + // Name of the scene the scene item belongs to. // Defaults to the current scene. // Required: No. SceneName string `json:"scene-name"` - // The name of the source item. + // Scene Item name. // Required: Yes. Item string `json:"item"` // Width scale factor. @@ -789,11 +835,11 @@ type SetSceneItemTransformResponse struct { // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setsceneitemcrop type SetSceneItemCropRequest struct { - // the name of the scene that the source item belongs to. + // Name of the scene the scene item belongs to. // Defaults to the current scene. // Required: No. SceneName string `json:"scene-name"` - // The name of the source. + // Scene Item name. // Required: Yes. Item string `json:"item"` // Pixel position of the top of the source item. @@ -908,17 +954,17 @@ type SetSceneItemCropResponse struct { // // https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#deletesceneitem type DeleteSceneItemRequest struct { - // Name of the scene the source belongs to. + // Name of the scene the scene item belongs to. // Defaults to the current scene. // Required: No. Scene string `json:"scene"` - // item to delete (required). + // Scene item to delete (required). // Required: Yes. Item map[string]interface{} `json:"item"` - // name of the scene item (prefer `id`, including both is acceptable). + // Scene Item name (prefer `id`, including both is acceptable). // Required: Yes. ItemName string `json:"item.name"` - // id of the scene item. + // Scene Item ID. // Required: Yes. ItemID int `json:"item.id"` _request `json:",squash"` @@ -1025,13 +1071,13 @@ type DuplicateSceneItemRequest struct { // Defaults to the current scene. // Required: No. ToScene string `json:"toScene"` - // item to duplicate (required). + // Scene Item to duplicate from the source scene (required). // Required: Yes. Item map[string]interface{} `json:"item"` - // name of the scene item (prefer `id`, including both is acceptable). + // Scene Item name (prefer `id`, including both is acceptable). // Required: Yes. ItemName string `json:"item.name"` - // id of the scene item. + // Scene Item ID. // Required: Yes. ItemID int `json:"item.id"` _request `json:",squash"` diff --git a/requests_scenes.go b/requests_scenes.go index 5eb6b74..440fa59 100644 --- a/requests_scenes.go +++ b/requests_scenes.go @@ -279,7 +279,7 @@ type GetSceneListResponse struct { // Name of the currently active scene. // Required: Yes. CurrentScene string `json:"current-scene"` - // Ordered list of the current profile's scenes (See `[GetCurrentScene](#getcurrentscene)` for more information). + // Ordered list of the current profile's scenes (See [GetCurrentScene](#getcurrentscene) for more information). // Required: Yes. Scenes []*Scene `json:"scenes"` _response `json:",squash"` @@ -395,3 +395,297 @@ func (r ReorderSceneItemsRequest) SendReceive(c Client) (ReorderSceneItemsRespon type ReorderSceneItemsResponse struct { _response `json:",squash"` } + +// SetSceneTransitionOverrideRequest : Set a scene to use a specific transition override. +// +// Since obs-websocket version: 4.9.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setscenetransitionoverride +type SetSceneTransitionOverrideRequest struct { + // Name of the scene to switch to. + // Required: Yes. + SceneName string `json:"sceneName"` + // Name of the transition to use. + // Required: Yes. + TransitionName string `json:"transitionName"` + // Duration in milliseconds of the transition if transition is not fixed. + // Defaults to the current duration specified in the UI if there is no current override and this value is not given. + // Required: No. + TransitionDuration int `json:"transitionDuration"` + _request `json:",squash"` + response chan SetSceneTransitionOverrideResponse +} + +// NewSetSceneTransitionOverrideRequest returns a new SetSceneTransitionOverrideRequest. +func NewSetSceneTransitionOverrideRequest( + sceneName string, + transitionName string, + transitionDuration int, +) SetSceneTransitionOverrideRequest { + return SetSceneTransitionOverrideRequest{ + sceneName, + transitionName, + transitionDuration, + _request{ + ID_: GetMessageID(), + Type_: "SetSceneTransitionOverride", + err: make(chan error, 1), + }, + make(chan SetSceneTransitionOverrideResponse, 1), + } +} + +// Send sends the request. +func (r *SetSceneTransitionOverrideRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp SetSceneTransitionOverrideResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r SetSceneTransitionOverrideRequest) Receive() (SetSceneTransitionOverrideResponse, error) { + if !r.sent { + return SetSceneTransitionOverrideResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return SetSceneTransitionOverrideResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return SetSceneTransitionOverrideResponse{}, err + case <-time.After(receiveTimeout): + return SetSceneTransitionOverrideResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r SetSceneTransitionOverrideRequest) SendReceive(c Client) (SetSceneTransitionOverrideResponse, error) { + if err := r.Send(c); err != nil { + return SetSceneTransitionOverrideResponse{}, err + } + return r.Receive() +} + +// SetSceneTransitionOverrideResponse : Response for SetSceneTransitionOverrideRequest. +// +// Since obs-websocket version: 4.9.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setscenetransitionoverride +type SetSceneTransitionOverrideResponse struct { + _response `json:",squash"` +} + +// RemoveSceneTransitionOverrideRequest : Remove any transition override on a scene. +// +// Since obs-websocket version: 4.9.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#removescenetransitionoverride +type RemoveSceneTransitionOverrideRequest struct { + // Name of the scene to switch to. + // Required: Yes. + SceneName string `json:"sceneName"` + _request `json:",squash"` + response chan RemoveSceneTransitionOverrideResponse +} + +// NewRemoveSceneTransitionOverrideRequest returns a new RemoveSceneTransitionOverrideRequest. +func NewRemoveSceneTransitionOverrideRequest(sceneName string) RemoveSceneTransitionOverrideRequest { + return RemoveSceneTransitionOverrideRequest{ + sceneName, + _request{ + ID_: GetMessageID(), + Type_: "RemoveSceneTransitionOverride", + err: make(chan error, 1), + }, + make(chan RemoveSceneTransitionOverrideResponse, 1), + } +} + +// Send sends the request. +func (r *RemoveSceneTransitionOverrideRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp RemoveSceneTransitionOverrideResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r RemoveSceneTransitionOverrideRequest) Receive() (RemoveSceneTransitionOverrideResponse, error) { + if !r.sent { + return RemoveSceneTransitionOverrideResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return RemoveSceneTransitionOverrideResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return RemoveSceneTransitionOverrideResponse{}, err + case <-time.After(receiveTimeout): + return RemoveSceneTransitionOverrideResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r RemoveSceneTransitionOverrideRequest) SendReceive(c Client) (RemoveSceneTransitionOverrideResponse, error) { + if err := r.Send(c); err != nil { + return RemoveSceneTransitionOverrideResponse{}, err + } + return r.Receive() +} + +// RemoveSceneTransitionOverrideResponse : Response for RemoveSceneTransitionOverrideRequest. +// +// Since obs-websocket version: 4.9.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#removescenetransitionoverride +type RemoveSceneTransitionOverrideResponse struct { + _response `json:",squash"` +} + +// GetSceneTransitionOverrideRequest : Get the current scene transition override. +// +// Since obs-websocket version: 4.9.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#getscenetransitionoverride +type GetSceneTransitionOverrideRequest struct { + // Name of the scene to switch to. + // Required: Yes. + SceneName string `json:"sceneName"` + _request `json:",squash"` + response chan GetSceneTransitionOverrideResponse +} + +// NewGetSceneTransitionOverrideRequest returns a new GetSceneTransitionOverrideRequest. +func NewGetSceneTransitionOverrideRequest(sceneName string) GetSceneTransitionOverrideRequest { + return GetSceneTransitionOverrideRequest{ + sceneName, + _request{ + ID_: GetMessageID(), + Type_: "GetSceneTransitionOverride", + err: make(chan error, 1), + }, + make(chan GetSceneTransitionOverrideResponse, 1), + } +} + +// Send sends the request. +func (r *GetSceneTransitionOverrideRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp GetSceneTransitionOverrideResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r GetSceneTransitionOverrideRequest) Receive() (GetSceneTransitionOverrideResponse, error) { + if !r.sent { + return GetSceneTransitionOverrideResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return GetSceneTransitionOverrideResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return GetSceneTransitionOverrideResponse{}, err + case <-time.After(receiveTimeout): + return GetSceneTransitionOverrideResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r GetSceneTransitionOverrideRequest) SendReceive(c Client) (GetSceneTransitionOverrideResponse, error) { + if err := r.Send(c); err != nil { + return GetSceneTransitionOverrideResponse{}, err + } + return r.Receive() +} + +// GetSceneTransitionOverrideResponse : Response for GetSceneTransitionOverrideRequest. +// +// Since obs-websocket version: 4.9.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#getscenetransitionoverride +type GetSceneTransitionOverrideResponse struct { + // Name of the current overriding transition. + // Empty string if no override is set. + // Required: Yes. + TransitionName string `json:"transitionName"` + // Transition duration. + // `-1` if no override is set. + // Required: Yes. + TransitionDuration int `json:"transitionDuration"` + _response `json:",squash"` +} diff --git a/requests_sources.go b/requests_sources.go index d26e165..6cd647c 100644 --- a/requests_sources.go +++ b/requests_sources.go @@ -235,7 +235,8 @@ type GetSourceTypesListResponse struct { _response `json:",squash"` } -// GetVolumeRequest : Get the volume of the specified source. +// GetVolumeRequest : Get the volume of the specified source +// Default response uses mul format, NOT SLIDER PERCENTAGE. // // Since obs-websocket version: 4.0.0. // @@ -243,15 +244,22 @@ type GetSourceTypesListResponse struct { type GetVolumeRequest struct { // Source name. // Required: Yes. - Source string `json:"source"` - _request `json:",squash"` - response chan GetVolumeResponse + Source string `json:"source"` + // Output volume in decibels of attenuation instead of amplitude/mul. + // Required: No. + UseDecibel bool `json:"useDecibel"` + _request `json:",squash"` + response chan GetVolumeResponse } // NewGetVolumeRequest returns a new GetVolumeRequest. -func NewGetVolumeRequest(source string) GetVolumeRequest { +func NewGetVolumeRequest( + source string, + useDecibel bool, +) GetVolumeRequest { return GetVolumeRequest{ source, + useDecibel, _request{ ID_: GetMessageID(), Type_: "GetVolume", @@ -327,7 +335,7 @@ type GetVolumeResponse struct { // Required: Yes. Name string `json:"name"` // Volume of the source. - // Between `0.0` and `1.0`. + // Between `0.0` and `1.0` if using mul, under `0.0` if using dB (since it is attenuating). // Required: Yes. Volume float64 `json:"volume"` // Indicates whether the source is muted. @@ -336,7 +344,8 @@ type GetVolumeResponse struct { _response `json:",squash"` } -// SetVolumeRequest : Set the volume of the specified source. +// SetVolumeRequest : Set the volume of the specified source +// Default request format uses mul, NOT SLIDER PERCENTAGE. // // Since obs-websocket version: 4.0.0. // @@ -346,21 +355,27 @@ type SetVolumeRequest struct { // Required: Yes. Source string `json:"source"` // Desired volume. - // Must be between `0.0` and `1.0`. + // Must be between `0.0` and `1.0` for mul, and under 0.0 for dB. + // Note: OBS will interpret dB values under -100.0 as Inf. // Required: Yes. - Volume float64 `json:"volume"` - _request `json:",squash"` - response chan SetVolumeResponse + Volume float64 `json:"volume"` + // Interperet `volume` data as decibels instead of amplitude/mul. + // Required: No. + UseDecibel bool `json:"useDecibel"` + _request `json:",squash"` + response chan SetVolumeResponse } // NewSetVolumeRequest returns a new SetVolumeRequest. func NewSetVolumeRequest( source string, volume float64, + useDecibel bool, ) SetVolumeRequest { return SetVolumeRequest{ source, volume, + useDecibel, _request{ ID_: GetMessageID(), Type_: "SetVolume", @@ -721,6 +736,106 @@ type ToggleMuteResponse struct { _response `json:",squash"` } +// SetSourceNameRequest : +// +// Note: If the new name already exists as a source, OBS will automatically modify the name to not interfere. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setsourcename +type SetSourceNameRequest struct { + // Source name. + // Required: Yes. + SourceName string `json:"sourceName"` + // New source name. + // Required: Yes. + NewName string `json:"newName"` + _request `json:",squash"` + response chan SetSourceNameResponse +} + +// NewSetSourceNameRequest returns a new SetSourceNameRequest. +func NewSetSourceNameRequest( + sourceName string, + newName string, +) SetSourceNameRequest { + return SetSourceNameRequest{ + sourceName, + newName, + _request{ + ID_: GetMessageID(), + Type_: "SetSourceName", + err: make(chan error, 1), + }, + make(chan SetSourceNameResponse, 1), + } +} + +// Send sends the request. +func (r *SetSourceNameRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp SetSourceNameResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r SetSourceNameRequest) Receive() (SetSourceNameResponse, error) { + if !r.sent { + return SetSourceNameResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return SetSourceNameResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return SetSourceNameResponse{}, err + case <-time.After(receiveTimeout): + return SetSourceNameResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r SetSourceNameRequest) SendReceive(c Client) (SetSourceNameResponse, error) { + if err := r.Send(c); err != nil { + return SetSourceNameResponse{}, err + } + return r.Receive() +} + +// SetSourceNameResponse : Response for SetSourceNameRequest. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setsourcename +type SetSourceNameResponse struct { + _response `json:",squash"` +} + // SetSyncOffsetRequest : Set the audio sync offset of a specified source. // // Since obs-websocket version: 4.2.0. @@ -3055,6 +3170,200 @@ type SetSourceFilterVisibilityResponse struct { _response `json:",squash"` } +// GetAudioMonitorTypeRequest : Get the audio monitoring type of the specified source. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#getaudiomonitortype +type GetAudioMonitorTypeRequest struct { + // Source name. + // Required: Yes. + SourceName string `json:"sourceName"` + _request `json:",squash"` + response chan GetAudioMonitorTypeResponse +} + +// NewGetAudioMonitorTypeRequest returns a new GetAudioMonitorTypeRequest. +func NewGetAudioMonitorTypeRequest(sourceName string) GetAudioMonitorTypeRequest { + return GetAudioMonitorTypeRequest{ + sourceName, + _request{ + ID_: GetMessageID(), + Type_: "GetAudioMonitorType", + err: make(chan error, 1), + }, + make(chan GetAudioMonitorTypeResponse, 1), + } +} + +// Send sends the request. +func (r *GetAudioMonitorTypeRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp GetAudioMonitorTypeResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r GetAudioMonitorTypeRequest) Receive() (GetAudioMonitorTypeResponse, error) { + if !r.sent { + return GetAudioMonitorTypeResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return GetAudioMonitorTypeResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return GetAudioMonitorTypeResponse{}, err + case <-time.After(receiveTimeout): + return GetAudioMonitorTypeResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r GetAudioMonitorTypeRequest) SendReceive(c Client) (GetAudioMonitorTypeResponse, error) { + if err := r.Send(c); err != nil { + return GetAudioMonitorTypeResponse{}, err + } + return r.Receive() +} + +// GetAudioMonitorTypeResponse : Response for GetAudioMonitorTypeRequest. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#getaudiomonitortype +type GetAudioMonitorTypeResponse struct { + // The monitor type in use. + // Options: `none`, `monitorOnly`, `monitorAndOutput`. + // Required: Yes. + MonitorType string `json:"monitorType"` + _response `json:",squash"` +} + +// SetAudioMonitorTypeRequest : Set the audio monitoring type of the specified source. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setaudiomonitortype +type SetAudioMonitorTypeRequest struct { + // Source name. + // Required: Yes. + SourceName string `json:"sourceName"` + // The monitor type to use. + // Options: `none`, `monitorOnly`, `monitorAndOutput`. + // Required: Yes. + MonitorType string `json:"monitorType"` + _request `json:",squash"` + response chan SetAudioMonitorTypeResponse +} + +// NewSetAudioMonitorTypeRequest returns a new SetAudioMonitorTypeRequest. +func NewSetAudioMonitorTypeRequest( + sourceName string, + monitorType string, +) SetAudioMonitorTypeRequest { + return SetAudioMonitorTypeRequest{ + sourceName, + monitorType, + _request{ + ID_: GetMessageID(), + Type_: "SetAudioMonitorType", + err: make(chan error, 1), + }, + make(chan SetAudioMonitorTypeResponse, 1), + } +} + +// Send sends the request. +func (r *SetAudioMonitorTypeRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp SetAudioMonitorTypeResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r SetAudioMonitorTypeRequest) Receive() (SetAudioMonitorTypeResponse, error) { + if !r.sent { + return SetAudioMonitorTypeResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return SetAudioMonitorTypeResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return SetAudioMonitorTypeResponse{}, err + case <-time.After(receiveTimeout): + return SetAudioMonitorTypeResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r SetAudioMonitorTypeRequest) SendReceive(c Client) (SetAudioMonitorTypeResponse, error) { + if err := r.Send(c); err != nil { + return SetAudioMonitorTypeResponse{}, err + } + return r.Receive() +} + +// SetAudioMonitorTypeResponse : Response for SetAudioMonitorTypeRequest. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#setaudiomonitortype +type SetAudioMonitorTypeResponse struct { + _response `json:",squash"` +} + // TakeSourceScreenshotRequest : // // At least `embedPictureFormat` or `saveToFilePath` must be specified. @@ -3080,6 +3389,15 @@ type TakeSourceScreenshotRequest struct { // Can be a relative path. // Required: No. SaveToFilePath string `json:"saveToFilePath"` + // Format to save the image file as (one of the values provided in the `supported-image-export-formats` response field of `GetVersion`). + // If not specified, tries to guess based on file extension. + // Required: No. + FileFormat string `json:"fileFormat"` + // Compression ratio between -1 and 100 to write the image with. + // -1 is automatic, 1 is smallest file/most compression, 100 is largest file/least compression. + // Varies with image type. + // Required: No. + CompressionQuality int `json:"compressionQuality"` // Screenshot width. // Defaults to the source's base width. // Required: No. @@ -3097,6 +3415,8 @@ func NewTakeSourceScreenshotRequest( sourceName string, embedPictureFormat string, saveToFilePath string, + fileFormat string, + compressionQuality int, width int, height int, ) TakeSourceScreenshotRequest { @@ -3104,6 +3424,8 @@ func NewTakeSourceScreenshotRequest( sourceName, embedPictureFormat, saveToFilePath, + fileFormat, + compressionQuality, width, height, _request{ diff --git a/requests_streaming.go b/requests_streaming.go index 88be62a..9390327 100644 --- a/requests_streaming.go +++ b/requests_streaming.go @@ -229,13 +229,13 @@ type StartStreamingRequest struct { StreamSettingsKey string `json:"stream.settings.key"` // Indicates whether authentication should be used when connecting to the streaming server. // Required: No. - StreamSettingsUseAuth bool `json:"stream.settings.use-auth"` + StreamSettingsUseAuth bool `json:"stream.settings.use_auth"` // If authentication is enabled, the username for the streaming server. - // Ignored if `use-auth` is not set to `true`. + // Ignored if `use_auth` is not set to `true`. // Required: No. StreamSettingsUsername string `json:"stream.settings.username"` // If authentication is enabled, the password for the streaming server. - // Ignored if `use-auth` is not set to `true`. + // Ignored if `use_auth` is not set to `true`. // Required: No. StreamSettingsPassword string `json:"stream.settings.password"` _request `json:",squash"` @@ -450,7 +450,7 @@ type SetStreamSettingsRequest struct { SettingsKey string `json:"settings.key"` // Indicates whether authentication should be used when connecting to the streaming server. // Required: No. - SettingsUseAuth bool `json:"settings.use-auth"` + SettingsUseAuth bool `json:"settings.use_auth"` // The username for the streaming service. // Required: No. SettingsUsername string `json:"settings.username"` @@ -657,13 +657,13 @@ type GetStreamSettingsResponse struct { SettingsKey string `json:"settings.key"` // Indicates whether authentication should be used when connecting to the streaming server. // Required: Yes. - SettingsUseAuth bool `json:"settings.use-auth"` + SettingsUseAuth bool `json:"settings.use_auth"` // The username to use when accessing the streaming server. - // Only present if `use-auth` is `true`. + // Only present if `use_auth` is `true`. // Required: Yes. SettingsUsername string `json:"settings.username"` // The password to use when accessing the streaming server. - // Only present if `use-auth` is `true`. + // Only present if `use_auth` is `true`. // Required: Yes. SettingsPassword string `json:"settings.password"` _response `json:",squash"` diff --git a/requests_transitions.go b/requests_transitions.go index 8ad30f6..87d156c 100644 --- a/requests_transitions.go +++ b/requests_transitions.go @@ -468,3 +468,95 @@ type GetTransitionDurationResponse struct { TransitionDuration int `json:"transition-duration"` _response `json:",squash"` } + +// GetTransitionPositionRequest : Get the position of the current transition. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#gettransitionposition +type GetTransitionPositionRequest struct { + _request `json:",squash"` + response chan GetTransitionPositionResponse +} + +// NewGetTransitionPositionRequest returns a new GetTransitionPositionRequest. +func NewGetTransitionPositionRequest() GetTransitionPositionRequest { + return GetTransitionPositionRequest{ + _request{ + ID_: GetMessageID(), + Type_: "GetTransitionPosition", + err: make(chan error, 1), + }, + make(chan GetTransitionPositionResponse, 1), + } +} + +// Send sends the request. +func (r *GetTransitionPositionRequest) Send(c Client) error { + if r.sent { + return ErrAlreadySent + } + future, err := c.SendRequest(r) + if err != nil { + return err + } + r.sent = true + go func() { + m := <-future + var resp GetTransitionPositionResponse + if err = mapToStruct(m, &resp); err != nil { + r.err <- err + } else if resp.Status() != StatusOK { + r.err <- errors.New(resp.Error()) + } else { + r.response <- resp + } + }() + return nil +} + +// Receive waits for the response. +func (r GetTransitionPositionRequest) Receive() (GetTransitionPositionResponse, error) { + if !r.sent { + return GetTransitionPositionResponse{}, ErrNotSent + } + if receiveTimeout == 0 { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return GetTransitionPositionResponse{}, err + } + } else { + select { + case resp := <-r.response: + return resp, nil + case err := <-r.err: + return GetTransitionPositionResponse{}, err + case <-time.After(receiveTimeout): + return GetTransitionPositionResponse{}, ErrReceiveTimeout + } + } +} + +// SendReceive sends the request then immediately waits for the response. +func (r GetTransitionPositionRequest) SendReceive(c Client) (GetTransitionPositionResponse, error) { + if err := r.Send(c); err != nil { + return GetTransitionPositionResponse{}, err + } + return r.Receive() +} + +// GetTransitionPositionResponse : Response for GetTransitionPositionRequest. +// +// Since obs-websocket version: 4.8.0. +// +// https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md#gettransitionposition +type GetTransitionPositionResponse struct { + // current transition position. + // This value will be between 0.0 and 1.0. + // Note: Transition returns 1.0 when not active. + // Required: Yes. + Position float64 `json:"position"` + _response `json:",squash"` +}