private async Task ParseEvent(MemoryStream message, ObsEventObject obsEvent) { message.Seek(0, SeekOrigin.Begin); obsEvent.MessageObject = await JsonSerializer.DeserializeAsync(message, ObsWsEvent.GetType(obsEvent.EventType)).ConfigureAwait(false); object settingsObject; ReadOnlyMemory <char> settingsJson; switch (obsEvent.EventType) { case ObsEventType.SourceCreated: GetJsonElementFromObjectProperty(obsEvent.MessageObject, "SourceSettings", out settingsJson); if (!CanDeserializeSourceType(obsEvent.SourceType, settingsJson, out settingsObject)) { Trace.WriteLine($"{obsEvent.EventType} ({obsEvent.SourceType}) -> {settingsJson}"); break; } (obsEvent.MessageObject as SourceCreatedObsEvent).SourceSettingsObj = settingsObject; break; case ObsEventType.SourceFilterAdded: GetJsonElementFromObjectProperty(obsEvent.MessageObject, "FilterSettings", out settingsJson); if (!CanDeserializeSourceType(obsEvent.SourceType, settingsJson, out settingsObject)) { Trace.WriteLine($"{obsEvent.EventType} ({obsEvent.SourceType}) -> {settingsJson}"); break; } (obsEvent.MessageObject as SourceFilterAddedObsEvent).FilterSettingsObj = settingsObject; break; } NewObsEvent(obsEvent); }
private void FurtherProcessObsEvent(object sender, ObsEventObject obsEvent) { switch (obsEvent.EventType) { case ObsEventType.Heartbeat: heartBeatCheck.Enabled = (obsEvent.MessageObject as HeartbeatObsEvent).Pulse; heartBeatCheck.Enabled = true; break; default: break; } }
protected virtual void NewObsEvent(ObsEventObject obsEvent) { OnObsEvent?.Invoke(this, obsEvent); }
private async Task OBS_ParseJson(MemoryStream message) { using JsonDocument document = GetJsonDocumentFromMemoryStream(message); JsonElement root = document.RootElement; JsonElement sourceType; if (root.TryGetProperty("message-id", out JsonElement messageIdJson)) { bool sentMessageGuidExists = false; ObsRequestMetadata requestMetadata = null; if (Guid.TryParse(messageIdJson.GetString(), out Guid guid)) { sentMessageGuidExists = sentMessageGuids.TryGetValue(guid, out requestMetadata); } root.TryGetProperty("status", out JsonElement statusJson); if (sentMessageGuidExists) { ObsReplyObject obsReply = new ObsReplyObject() { MessageId = guid, Status = statusJson.GetString() }; if (sentMessageGuidExists) { obsReply.RequestMetadata = requestMetadata; sentMessageGuids.Remove(guid); } if (Enum.TryParse(requestMetadata.OriginalRequestType.ToString(), out ObsRequestType reqType)) { obsReply.RequestType = reqType; } switch (obsReply.RequestType) { case ObsRequestType.GetSourceSettings: case ObsRequestType.SetSourceSettings: root.TryGetProperty("sourceType", out sourceType); obsReply.SourceType = ObsTypes.ObsTypeNameDictionary[sourceType.ToString()]; break; case ObsRequestType.GetSourceFilterInfo: root.TryGetProperty("type", out sourceType); obsReply.SourceType = ObsTypes.ObsTypeNameDictionary[sourceType.ToString()]; break; default: break; } await ParseReply(message, obsReply).ConfigureAwait(false); } else { Trace.WriteLine($"message-id {messageIdJson} received, but no matching request found."); } } else if (root.TryGetProperty("update-type", out JsonElement updateTypeJson)) { Trace.WriteLine($"Received a message of type {updateTypeJson}."); bool isStreaming = root.TryGetProperty("stream-timecode", out JsonElement jsonStreamTimecode); bool isRecording = root.TryGetProperty("rec-timecode", out JsonElement jsonRecTimecode); ObsEventObject obsEvent = new ObsEventObject(); if (Enum.TryParse(updateTypeJson.GetString(), out ObsEventType eventType)) { obsEvent.EventType = eventType; } switch (obsEvent.EventType) { case ObsEventType.SourceCreated: root.TryGetProperty("sourceKind", out sourceType); obsEvent.SourceType = ObsTypes.ObsTypeNameDictionary[sourceType.ToString()]; break; case ObsEventType.SourceFilterAdded: root.TryGetProperty("filterType", out sourceType); obsEvent.SourceType = ObsTypes.ObsTypeNameDictionary[sourceType.ToString()]; break; default: break; } await ParseEvent(message, obsEvent).ConfigureAwait(false); } else { Trace.WriteLine("Unexpected JSON."); } }
private void WebSocket_NewObsEvent(ObsEventObject obsEventObject) { EventBase obsEvent = obsEventObject.MessageObject as EventBase; switch (obsEventObject.EventType) { case ObsEventType.SourceFilterRemoved: SourceFilterRemovedObsEvent temp1 = (obsEvent as SourceFilterRemovedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SourceFilterRemoved_format, temp1.UpdateType, temp1.FilterName, temp1.FilterType, temp1.SourceName)); break; case ObsEventType.SourceDestroyed: SourceDestroyedObsEvent temp2 = (obsEvent as SourceDestroyedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_generic_format, temp2.UpdateType, temp2.SourceName, temp2.SourceType)); break; case ObsEventType.SourceCreated: SourceCreatedObsEvent temp3 = (obsEvent as SourceCreatedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_generic_format, temp3.UpdateType, temp3.SourceName, temp3.SourceKind)); break; case ObsEventType.SourceVolumeChanged: SourceVolumeChangedObsEvent temp4 = (obsEvent as SourceVolumeChangedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SourceVolumeChanged_format, temp4.UpdateType, temp4.SourceName, temp4.Volume)); break; case ObsEventType.SourceAudioSyncOffsetChanged: SourceAudioSyncOffsetChangedObsEvent temp5 = (obsEvent as SourceAudioSyncOffsetChangedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SourceAudioSyncOffsetChanged_format, temp5.UpdateType, temp5.SourceName, temp5.SyncOffset)); break; case ObsEventType.SourceMuteStateChanged: SourceMuteStateChangedObsEvent temp6 = (obsEvent as SourceMuteStateChangedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SourceMuteStateChanged_format, temp6.UpdateType, temp6.SourceName, temp6.Muted)); break; case ObsEventType.SourceFilterAdded: SourceFilterAddedObsEvent temp7 = (obsEvent as SourceFilterAddedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SourceFilterAdded_format, temp7.UpdateType, temp7.FilterName, temp7.FilterType, temp7.SourceName)); break; case ObsEventType.SceneItemAdded: SceneItemAddedObsEvent temp8 = (obsEvent as SceneItemAddedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SceneItemAdded_format, temp8.UpdateType, temp8.ItemName, temp8.SceneName)); break; case ObsEventType.SceneItemTransformChanged: SceneItemTransformChangedObsEvent temp9 = (obsEvent as SceneItemTransformChangedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SceneItemTransformChanged_format, temp9.UpdateType, temp9.ItemName, temp9.SceneName)); break; case ObsEventType.SwitchScenes: SwitchScenesObsEvent temp10 = (obsEvent as SwitchScenesObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SwitchScenes_format, temp10.UpdateType, temp10.SceneName, temp10.Sources.Count)); break; case ObsEventType.SceneCollectionChanged: SceneCollectionChangedObsEvent temp11 = (obsEvent as SceneCollectionChangedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SceneCollectionChanged_format, temp11.UpdateType)); break; case ObsEventType.TransitionListChanged: TransitionListChangedObsEvent temp12 = (obsEvent as TransitionListChangedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_TransitionListChanged_format, temp12.UpdateType)); break; case ObsEventType.SwitchTransition: SwitchTransitionObsEvent temp13 = (obsEvent as SwitchTransitionObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_SwitchTransition_format, temp13.UpdateType, temp13.TransitionName)); break; case ObsEventType.ScenesChanged: ScenesChangedObsEvent temp14 = (obsEvent as ScenesChangedObsEvent); txtOutput.AppendText(String.Format(CultureInfo.CurrentCulture, Properties.Resources.window_obs_message_ScenesChanged_format, temp14.UpdateType)); break; default: txtOutput.AppendText((obsEventObject.MessageObject as EventBase).UpdateType); break; } txtOutput.AppendText("\n"); if (autoscroll == true) { svScroll.ScrollToBottom(); } }
private void WebSocket_NewObsEvent_ContextSwitch(object sender, ObsEventObject e) { _Context.Send( x => WebSocket_NewObsEvent(e), null); }