Esempio n. 1
0
        /// <summary>
        /// Update message handler
        /// </summary>
        /// <param name="eventType">Value of "event-type" in the JSON body</param>
        /// <param name="body">full JSON message body</param>
        protected void ProcessEventType(string eventType, JObject body)
        {
            StreamStatus status;

            switch (eventType)
            {
            case "SwitchScenes":
                SceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "ScenesChanged":
                SceneListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SourceOrderChanged":
                SourceOrderChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "SceneItemAdded":
                SceneItemAdded?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemRemoved":
                SceneItemRemoved?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemVisibilityChanged":
                SceneItemVisibilityChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneCollectionChanged":
                SceneCollectionChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SceneCollectionListChanged":
                SceneCollectionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SwitchTransition":
                TransitionChanged?.Invoke(this, (string)body["transition-name"]);
                break;

            case "TransitionDurationChanged":
                TransitionDurationChanged?.Invoke(this, (int)body["new-duration"]);
                break;

            case "TransitionListChanged":
                TransitionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "TransitionBegin":
                TransitionBegin?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileChanged":
                ProfileChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileListChanged":
                ProfileListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStarting":
                StreamingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "StreamStarted":
                StreamingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "StreamStopping":
                StreamingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "StreamStopped":
                StreamingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingStarting":
                RecordingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "RecordingStarted":
                RecordingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "RecordingStopping":
                RecordingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "RecordingStopped":
                RecordingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "StreamStatus":
                if (StreamStatus != null)
                {
                    status = new StreamStatus(body);
                    StreamStatus(this, status);
                }
                break;

            case "PreviewSceneChanged":
                PreviewSceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "StudioModeSwitched":
                StudioModeSwitched?.Invoke(this, (bool)body["new-state"]);
                break;

            case "ReplayStarting":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "ReplayStarted":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "ReplayStopping":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "ReplayStopped":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "Exiting":
                OBSExit?.Invoke(this, EventArgs.Empty);
                break;

            case "Heartbeat":
                Heartbeat?.Invoke(this, new Heartbeat(body));
                break;

            case "SceneItemDeselected":
                SceneItemDeselected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemSelected":
                SceneItemSelected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemTransformChanged":
                SceneItemTransformChanged?.Invoke(this, new SceneItemTransformInfo(body));
                break;

            case "SourceAudioMixersChanged":
                SourceAudioMixersChanged?.Invoke(this, new AudioMixersChangedInfo(body));
                break;

            case "SourceAudioSyncOffsetChanged":
                SourceAudioSyncOffsetChanged?.Invoke(this, (string)body["sourceName"], (int)body["syncOffset"]);
                break;

            case "SourceCreated":
                SourceCreated?.Invoke(this, new SourceSettings(body));
                break;

            case "SourceDestroyed":
                SourceDestroyed?.Invoke(this, (string)body["sourceName"], (string)body["sourceType"], (string)body["sourceKind"]);
                break;

            case "SourceRenamed":
                SourceRenamed?.Invoke(this, (string)body["newName"], (string)body["previousName"]);
                break;

            case "SourceMuteStateChanged":
                SourceMuteStateChanged?.Invoke(this, (string)body["sourceName"], (bool)body["muted"]);
                break;

            case "SourceVolumeChanged":
                SourceVolumeChanged?.Invoke(this, (string)body["sourceName"], (float)body["volume"]);
                break;

            case "SourceFilterAdded":
                SourceFilterAdded?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (string)body["filterType"], (JObject)body["filterSettings"]);
                break;

            case "SourceFilterRemoved":
                SourceFilterRemoved?.Invoke(this, (string)body["sourceName"], (string)body["filterName"]);
                break;

            case "SourceFiltersReordered":
                List <FilterReorderItem> filters = new List <FilterReorderItem>();
                JsonConvert.PopulateObject(body["filters"].ToString(), filters);
                SourceFiltersReordered?.Invoke(this, (string)body["sourceName"], filters);
                break;
            }
        }
        /// <summary>
        /// Update message handler
        /// </summary>
        /// <param name="eventType">Value of "event-type" in the JSON body</param>
        /// <param name="body">full JSON message body</param>
        protected void ProcessEventType(string eventType, JObject body)
        {
            StreamStatus status;

            switch (eventType)
            {
            case "SwitchScenes":
                SceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "ScenesChanged":
                SceneListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SourceOrderChanged":
                SourceOrderChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "SceneItemAdded":
                SceneItemAdded?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemRemoved":
                SceneItemRemoved?.Invoke(this, (string)body["scene-name"], (string)body["item-name"]);
                break;

            case "SceneItemVisibilityChanged":
                SceneItemVisibilityChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (bool)body["item-visible"]);
                break;

            case "SceneItemLockChanged":
                SceneItemLockChanged?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (int)body["item-id"], (bool)body["item-locked"]);
                break;

            case "SceneCollectionChanged":
                SceneCollectionChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SceneCollectionListChanged":
                SceneCollectionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "SwitchTransition":
                TransitionChanged?.Invoke(this, (string)body["transition-name"]);
                break;

            case "TransitionDurationChanged":
                TransitionDurationChanged?.Invoke(this, (int)body["new-duration"]);
                break;

            case "TransitionListChanged":
                TransitionListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "TransitionBegin":
                TransitionBegin?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["from-scene"], (string)body["to-scene"]);
                break;

            case "TransitionEnd":
                TransitionEnd?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["to-scene"]);
                break;

            case "TransitionVideoEnd":
                TransitionVideoEnd?.Invoke(this, (string)body["name"], (string)body["type"], (int)body["duration"], (string)body["from-scene"], (string)body["to-scene"]);
                break;

            case "ProfileChanged":
                ProfileChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "ProfileListChanged":
                ProfileListChanged?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStarting":
                StreamingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "StreamStarted":
                StreamingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "StreamStopping":
                StreamingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "StreamStopped":
                StreamingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingStarting":
                RecordingStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "RecordingStarted":
                RecordingStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "RecordingStopping":
                RecordingStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "RecordingStopped":
                RecordingStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "RecordingPaused":
                RecordingPaused?.Invoke(this, EventArgs.Empty);
                break;

            case "RecordingResumed":
                RecordingResumed?.Invoke(this, EventArgs.Empty);
                break;

            case "StreamStatus":
                if (StreamStatus != null)
                {
                    status = new StreamStatus(body);
                    StreamStatus(this, status);
                }
                break;

            case "PreviewSceneChanged":
                PreviewSceneChanged?.Invoke(this, (string)body["scene-name"]);
                break;

            case "StudioModeSwitched":
                StudioModeSwitched?.Invoke(this, (bool)body["new-state"]);
                break;

            case "ReplayStarting":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Starting);
                break;

            case "ReplayStarted":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Started);
                break;

            case "ReplayStopping":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopping);
                break;

            case "ReplayStopped":
                ReplayBufferStateChanged?.Invoke(this, OutputState.Stopped);
                break;

            case "Exiting":
                OBSExit?.Invoke(this, EventArgs.Empty);
                break;

            case "Heartbeat":
                Heartbeat?.Invoke(this, new Heartbeat(body));
                break;

            case "SceneItemDeselected":
                SceneItemDeselected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemSelected":
                SceneItemSelected?.Invoke(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                break;

            case "SceneItemTransformChanged":
                SceneItemTransformChanged?.Invoke(this, new SceneItemTransformInfo(body));
                break;

            case "SourceAudioMixersChanged":
                SourceAudioMixersChanged?.Invoke(this, new AudioMixersChangedInfo(body));
                break;

            case "SourceAudioSyncOffsetChanged":
                SourceAudioSyncOffsetChanged?.Invoke(this, (string)body["sourceName"], (int)body["syncOffset"]);
                break;

            case "SourceCreated":
                SourceCreated?.Invoke(this, new SourceSettings(body));
                break;

            case "SourceDestroyed":
                SourceDestroyed?.Invoke(this, (string)body["sourceName"], (string)body["sourceType"], (string)body["sourceKind"]);
                break;

            case "SourceRenamed":
                SourceRenamed?.Invoke(this, (string)body["newName"], (string)body["previousName"]);
                break;

            case "SourceMuteStateChanged":
                SourceMuteStateChanged?.Invoke(this, (string)body["sourceName"], (bool)body["muted"]);
                break;

            case "SourceAudioDeactivated":
                SourceAudioDeactivated?.Invoke(this, (string)body["sourceName"]);
                break;

            case "SourceAudioActivated":
                SourceAudioActivated?.Invoke(this, (string)body["sourceName"]);
                break;

            case "SourceVolumeChanged":
                SourceVolumeChanged?.Invoke(this, new SourceVolume(body));
                break;

            case "SourceFilterAdded":
                SourceFilterAdded?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (string)body["filterType"], (JObject)body["filterSettings"]);
                break;

            case "SourceFilterRemoved":
                SourceFilterRemoved?.Invoke(this, (string)body["sourceName"], (string)body["filterName"]);
                break;

            case "SourceFiltersReordered":
                if (SourceFiltersReordered != null)
                {
                    List <FilterReorderItem> filters = new List <FilterReorderItem>();
                    JsonConvert.PopulateObject(body["filters"].ToString(), filters);

                    SourceFiltersReordered?.Invoke(this, (string)body["sourceName"], filters);
                }
                break;

            case "SourceFilterVisibilityChanged":
                SourceFilterVisibilityChanged?.Invoke(this, (string)body["sourceName"], (string)body["filterName"], (bool)body["filterEnabled"]);
                break;

            case "BroadcastCustomMessage":
                BroadcastCustomMessageReceived?.Invoke(this, (string)body["realm"], (JObject)body["data"]);
                break;

            case "MediaEnded":
                MediaEnded?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaStarted":
                MediaStarted?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPrevious":
                MediaPrevious?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaNext":
                MediaNext?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaStopped":
                MediaStopped?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaRestarted":
                MediaRestarted?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPaused":
                MediaPaused?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "MediaPlaying":
                MediaPlaying?.Invoke(this, (string)body["sourceName"], (string)body["sourceKind"]);
                break;

            case "VirtualCamStarted":
                VirtualCameraStarted?.Invoke(this, EventArgs.Empty);
                break;

            case "VirtualCamStopped":
                VirtualCameraStopped?.Invoke(this, EventArgs.Empty);
                break;

            default:
                var message = $"Unsupported Event: {eventType}\n{body}";
                Console.WriteLine(message);
                Debug.WriteLine(message);
                break;
            }
        }