Пример #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":
                if (SceneChanged != null)
                {
                    SceneChanged(this, (string)body["scene-name"]);
                }
                break;

            case "ScenesChanged":
                if (SceneListChanged != null)
                {
                    SceneListChanged(this, EventArgs.Empty);
                }
                break;

            case "SourceOrderChanged":
                if (SourceOrderChanged != null)
                {
                    SourceOrderChanged(this, (string)body["scene-name"]);
                }
                break;

            case "SceneItemAdded":
                if (SceneItemAdded != null)
                {
                    SceneItemAdded(this, (string)body["scene-name"], (string)body["item-name"]);
                }
                break;

            case "SceneItemRemoved":
                if (SceneItemRemoved != null)
                {
                    SceneItemRemoved(this, (string)body["scene-name"], (string)body["item-name"]);
                }
                break;

            case "SceneItemVisibilityChanged":
                if (SceneItemVisibilityChanged != null)
                {
                    SceneItemVisibilityChanged(this, (string)body["scene-name"], (string)body["item-name"]);
                }
                break;

            case "SceneCollectionChanged":
                if (SceneCollectionChanged != null)
                {
                    SceneCollectionChanged(this, EventArgs.Empty);
                }
                break;

            case "SceneCollectionListChanged":
                if (SceneCollectionListChanged != null)
                {
                    SceneCollectionListChanged(this, EventArgs.Empty);
                }
                break;

            case "SwitchTransition":
                if (TransitionChanged != null)
                {
                    TransitionChanged(this, (string)body["transition-name"]);
                }
                break;

            case "TransitionDurationChanged":
                if (TransitionDurationChanged != null)
                {
                    TransitionDurationChanged(this, (int)body["new-duration"]);
                }
                break;

            case "TransitionListChanged":
                if (TransitionListChanged != null)
                {
                    TransitionListChanged(this, EventArgs.Empty);
                }
                break;

            case "TransitionBegin":
                if (TransitionBegin != null)
                {
                    TransitionBegin(this, EventArgs.Empty);
                }
                break;

            case "ProfileChanged":
                if (ProfileChanged != null)
                {
                    ProfileChanged(this, EventArgs.Empty);
                }
                break;

            case "ProfileListChanged":
                if (ProfileListChanged != null)
                {
                    ProfileListChanged(this, EventArgs.Empty);
                }
                break;

            case "StreamStarting":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Starting);
                }
                break;

            case "StreamStarted":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Started);
                }
                break;

            case "StreamStopping":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Stopping);
                }
                break;

            case "StreamStopped":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Stopped);
                }
                break;

            case "RecordingStarting":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Starting);
                }
                break;

            case "RecordingStarted":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Started);
                }
                break;

            case "RecordingStopping":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Stopping);
                }
                break;

            case "RecordingStopped":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Stopped);
                }
                break;

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

            case "PreviewSceneChanged":
                if (PreviewSceneChanged != null)
                {
                    PreviewSceneChanged(this, (string)body["scene-name"]);
                }
                break;

            case "StudioModeSwitched":
                if (StudioModeSwitched != null)
                {
                    StudioModeSwitched(this, (bool)body["new-state"]);
                }
                break;

            case "ReplayStarting":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Starting);
                }
                break;

            case "ReplayStarted":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Started);
                }
                break;

            case "ReplayStopping":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Stopping);
                }
                break;

            case "ReplayStopped":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Stopped);
                }
                break;

            case "Exiting":
                if (OBSExit != null)
                {
                    OBSExit(this, EventArgs.Empty);
                }
                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;
            }
        }
Пример #3
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":
                if (SceneChanged != null)
                {
                    SceneChanged(this, (string)body["scene-name"]);
                }
                break;

            case "ScenesChanged":
                if (SceneListChanged != null)
                {
                    SceneListChanged(this, EventArgs.Empty);
                }
                break;

            case "SourceOrderChanged":
                if (SourceOrderChanged != null)
                {
                    SourceOrderChanged(this, (string)body["scene-name"]);
                }
                break;

            case "SceneItemAdded":
                if (SceneItemAdded != null)
                {
                    SceneItemAdded(this, (string)body["scene-name"], (string)body["item-name"]);
                }
                break;

            case "SceneItemRemoved":
                if (SceneItemRemoved != null)
                {
                    SceneItemRemoved(this, (string)body["scene-name"], (string)body["item-name"]);
                }
                break;

            case "SceneItemVisibilityChanged":
                if (SceneItemVisibilityChanged != null)
                {
                    SceneItemVisibilityChanged(this, (string)body["scene-name"], (string)body["item-name"]);
                }
                break;

            case "SceneCollectionChanged":
                if (SceneCollectionChanged != null)
                {
                    SceneCollectionChanged(this, EventArgs.Empty);
                }
                break;

            case "SceneCollectionListChanged":
                if (SceneCollectionListChanged != null)
                {
                    SceneCollectionListChanged(this, EventArgs.Empty);
                }
                break;

            case "SwitchTransition":
                if (TransitionChanged != null)
                {
                    TransitionChanged(this, (string)body["transition-name"]);
                }
                break;

            case "TransitionDurationChanged":
                if (TransitionDurationChanged != null)
                {
                    TransitionDurationChanged(this, (int)body["new-duration"]);
                }
                break;

            case "TransitionListChanged":
                if (TransitionListChanged != null)
                {
                    TransitionListChanged(this, EventArgs.Empty);
                }
                break;

            case "TransitionBegin":
                if (TransitionBegin != null)
                {
                    TransitionBegin(this, EventArgs.Empty);
                }
                break;

            case "ProfileChanged":
                if (ProfileChanged != null)
                {
                    ProfileChanged(this, EventArgs.Empty);
                }
                break;

            case "ProfileListChanged":
                if (ProfileListChanged != null)
                {
                    ProfileListChanged(this, EventArgs.Empty);
                }
                break;

            case "StreamStarting":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Starting);
                }
                break;

            case "StreamStarted":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Started);
                }
                break;

            case "StreamStopping":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Stopping);
                }
                break;

            case "StreamStopped":
                if (StreamingStateChanged != null)
                {
                    StreamingStateChanged(this, OutputState.Stopped);
                }
                break;

            case "RecordingStarting":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Starting);
                }
                break;

            case "RecordingStarted":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Started);
                }
                break;

            case "RecordingStopping":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Stopping);
                }
                break;

            case "RecordingStopped":
                if (RecordingStateChanged != null)
                {
                    RecordingStateChanged(this, OutputState.Stopped);
                }
                break;

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

            case "PreviewSceneChanged":
                if (PreviewSceneChanged != null)
                {
                    PreviewSceneChanged(this, (string)body["scene-name"]);
                }
                break;

            case "StudioModeSwitched":
                if (StudioModeSwitched != null)
                {
                    StudioModeSwitched(this, (bool)body["new-state"]);
                }
                break;

            case "ReplayStarting":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Starting);
                }
                break;

            case "ReplayStarted":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Started);
                }
                break;

            case "ReplayStopping":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Stopping);
                }
                break;

            case "ReplayStopped":
                if (ReplayBufferStateChanged != null)
                {
                    ReplayBufferStateChanged(this, OutputState.Stopped);
                }
                break;

            case "Exiting":
                if (OBSExit != null)
                {
                    OBSExit(this, EventArgs.Empty);
                }
                break;

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

            case "SceneItemDeselected":
                if (SceneItemDeselected != null)
                {
                    SceneItemDeselected(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                }
                break;

            case "SceneItemSelected":
                if (SceneItemSelected != null)
                {
                    SceneItemSelected(this, (string)body["scene-name"], (string)body["item-name"], (string)body["item-id"]);
                }
                break;

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

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

            case "SourceAudioSyncOffsetChanged":
                if (SourceAudioSyncOffsetChanged != null)
                {
                    SourceAudioSyncOffsetChanged(this, (string)body["sourceName"], (int)body["syncOffset"]);
                }
                break;

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

            case "SourceDestroyed":
                if (SourceDestroyed != null)
                {
                    SourceDestroyed(this, (string)body["sourceName"], (string)body["sourceType"], (string)body["sourceKind"]);
                }
                break;

            case "SourceRenamed":
                if (SourceRenamed != null)
                {
                    SourceRenamed(this, (string)body["newName"], (string)body["previousName"]);
                }
                break;

            case "SourceMuteStateChanged":
                if (SourceMuteStateChanged != null)
                {
                    SourceMuteStateChanged(this, (string)body["sourceName"], (bool)body["muted"]);
                }
                break;

            case "SourceVolumeChanged":
                if (SourceVolumeChanged != null)
                {
                    SourceVolumeChanged(this, (string)body["sourceName"], (float)body["volume"]);
                }
                break;

            case "SourceFilterAdded":
                if (SourceFilterAdded != null)
                {
                    SourceFilterAdded(this, (string)body["sourceName"], (string)body["filterName"], (string)body["filterType"], (JObject)body["filterSettings"]);
                }
                break;

            case "SourceFilterRemoved":
                if (SourceFilterRemoved != null)
                {
                    SourceFilterRemoved(this, (string)body["sourceName"], (string)body["filterName"]);
                }
                break;

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

                if (SourceFiltersReordered != null)
                {
                    SourceFiltersReordered(this, (string)body["sourceName"], filters);
                }
                break;

                /*
                 * default:
                 *  var header = "-----------" + eventType + "-------------";
                 *  Console.WriteLine(header);
                 *  Console.WriteLine(body);
                 *  Console.WriteLine("".PadLeft(header.Length,'-'));
                 *  break;
                 */
            }
        }