public CSLOBSConnector() { Mode = EOBSMode.Normal; Scenes = new List <SOBSScene>(); PreviewScenes = new List <SOBSScene>(); Transitions = new List <SOBSTransition>(); Sources = new List <SOBSSource>(); AudioSources = new List <SOBSAudioSource>(); ActiveScene = new SOBSScene(); ActivePreviewScene = new SOBSScene(); ActiveTransition = new SOBSTransition(); _state = new SOBSStreamingState(); _state.Stream = EOBSStreamingState.Unkown; _state.Record = EOBSStreamingState.Unkown; _state.Replay = EOBSStreamingState.Unkown; ws = new SLOBSWebsocket(); ws.ConnectionStatus += Ws_ConnectionStatus; ws.SceneChanged += Ws_SceneChanged; ws.SceneListChanged += Ws_SceneListChanged; ws.SceneItemChanged += Ws_SceneItemChanged; ws.SourceChanged += Ws_SourceChanged; ws.StreamingStatusChanged += Ws_StreamingStatusChanged; //timer for querying Recording & Replay buffer status //SLOBS api has no events for this types yet. statusTimer = new System.Timers.Timer(5000); statusTimer.Elapsed += StatusTimer_Elapsed;; statusTimer.AutoReset = true; statusTimer.Enabled = false; }
private void Ws_StreamingStatusChanged(SLOBSWebsocket sender, ESLOBSStreamingState state) { SLOBSStreamingState input = new SLOBSStreamingState(); input.StreamingStatus = state; var output = _translateStreamingStatus(input); output.Record = _state.Record; output.Replay = _state.Replay; if (StreamingStatusChanged != null) { StreamingStatusChanged(this, output); } }
private async void Ws_SourceChanged(SLOBSWebsocket sender, SLOBSSourceEvent eventdata) { if (eventdata.Type == ESLOBSEventType.SourceAdded) { var sourceItem = _translateSource(eventdata.Source, Sources.Count + 1); Sources.Add(sourceItem); if (SourceChanged != null) { SourceChanged(this, EOBSEvent.SourceAdded, sourceItem); } //Audio item if (sourceItem.Audio) { var audio = await ws.ListAudioSources(); AudioSources.Clear(); AudioSources = _translateAudioSources(audio); if (AudioSourceChanged != null) { AudioSourceChanged(this, EOBSEvent.SourceAdded); } } } else if (eventdata.Type == ESLOBSEventType.SourceRemoved) { var sourceItem = _translateSource(eventdata.Source, 0); int reindex = 0; for (int i = 0; i < Sources.Count; i++) { if (Sources[i].Id == eventdata.Source.Id) { Sources.RemoveAt(i); sourceItem.Index = i; if (SourceChanged != null) { SourceChanged(this, EOBSEvent.SourceRemoved, sourceItem); //audio item if (sourceItem.Audio) { for (int ia = 0; ia < AudioSources.Count; ia++) { if (AudioSources[i].SourceId == sourceItem.Id) { AudioSources.RemoveAt(ia); if (AudioSourceChanged != null) { AudioSourceChanged(this, EOBSEvent.SourceUpdated); } } } } } } else { var source = Sources[i]; source.Index = reindex; Sources[i] = source; reindex++; } } } else if (eventdata.Type == ESLOBSEventType.SourceUpdated) { var sourceItem = _translateSource(eventdata.Source, 0); for (int i = 0; i < Sources.Count; i++) { if (Sources[i].Id == eventdata.Source.Id) { sourceItem.Index = i; Sources[i] = sourceItem; if (SourceChanged != null) { SourceChanged(this, EOBSEvent.SourceUpdated, sourceItem); } //audio item if (sourceItem.Audio) { var audio = await ws.ListAudioSources(); AudioSources.Clear(); AudioSources = _translateAudioSources(audio); if (AudioSourceChanged != null) { AudioSourceChanged(this, EOBSEvent.SourceUpdated); } } } } } }
private async void Ws_ConnectionStatus(SLOBSWebsocket sender, SSLOBSConnectionEvent eventdata) { if (ConnectionStatus != null) { EOBSCStatus translatedEventType = EOBSCStatus.Unknown; if (eventdata.state == ESLOBSConnectionState.Connected) { if (_auth != null) { var auth = await ws.Auth(_auth); if (auth) { translatedEventType = EOBSCStatus.Connected; Connected = true; statusTimer.Enabled = true; } else { translatedEventType = EOBSCStatus.WrongAuth; Connected = false; statusTimer.Enabled = false; } } else { translatedEventType = EOBSCStatus.Connected; Connected = true; statusTimer.Enabled = true; } } else if (eventdata.state == ESLOBSConnectionState.Connecting) { translatedEventType = EOBSCStatus.Connecting; Connected = false; statusTimer.Enabled = false; } else if (eventdata.state == ESLOBSConnectionState.Error) { translatedEventType = EOBSCStatus.Error; Connected = false; statusTimer.Enabled = false; } else if (eventdata.state == ESLOBSConnectionState.Disconnected) { translatedEventType = EOBSCStatus.Disconnected; Connected = false; statusTimer.Enabled = false; } if (Connected) { //subscribing all of possible events await ws.SubscribeToEvent("sceneSwitched", "ScenesService"); await ws.SubscribeToEvent("sceneAdded", "ScenesService"); await ws.SubscribeToEvent("sceneRemoved", "ScenesService"); await ws.SubscribeToEvent("itemAdded", "ScenesService"); await ws.SubscribeToEvent("itemRemoved", "ScenesService"); await ws.SubscribeToEvent("itemUpdated", "ScenesService"); await ws.SubscribeToEvent("streamingStatusChange", "StreamingService"); await ws.SubscribeToEvent("sourceAdded", "SourcesService"); await ws.SubscribeToEvent("sourceRemoved", "SourcesService"); await ws.SubscribeToEvent("sourceUpdated", "SourcesService"); } ConnectionStatus(this, translatedEventType); } }
private async void Ws_SceneChanged(SLOBSWebsocket sender, SLOBSSceneEvent eventdata) { if (eventdata.Type == ESLOBSEventType.SceneAdded) { SOBSScene item = _translateScene(eventdata.Scene); Scenes.Add(item); if (SceneChanged != null) { SceneChanged(this, EOBSEvent.SceneAdded, item); } } else if (eventdata.Type == ESLOBSEventType.SceneRemoved) { int reindex = 0; SOBSScene item = _translateScene(eventdata.Scene); for (int i = 0; i < Scenes.Count; i++) { if (Scenes[i].Id == eventdata.Scene.Id) { Scenes.RemoveAt(i); } else { var scene = Scenes[i]; scene.Index = reindex; Scenes[i] = scene; reindex++; } } if (SceneChanged != null) { SceneChanged(this, EOBSEvent.SceneRemoved, item); } } else if (eventdata.Type == ESLOBSEventType.SceneSwitched) { if (!_setActiveScene(eventdata.Scene)) { var ascenes = await ws.ListScenes(); Scenes.Clear(); Scenes = _translateScenes(ascenes); _setActiveScene(eventdata.Scene); } var audio = await ws.ListAudioSources(); AudioSources.Clear(); AudioSources = _translateAudioSources(audio); if (AudioSourceChanged != null) { AudioSourceChanged(this, EOBSEvent.SourceAdded); } if (SceneChanged != null) { SceneChanged(this, EOBSEvent.SceneSwitched, ActiveScene); } } else if (eventdata.Type == ESLOBSEventType.SceneCollectionChanged) { var ascenes = await ws.ListScenes(); Scenes.Clear(); Scenes = _translateScenes(ascenes); var active_scene = await ws.GetActiveScene(); if (active_scene != null) { for (int i = 0; i < Scenes.Count; i++) { if (Scenes[i].Id == ((SLOBSScene)active_scene).Id) { ActiveScene = Scenes[i]; } } } if (SceneChanged != null) { SceneChanged(this, EOBSEvent.SceneUpdated, ActiveScene); } } }
private void Ws_SceneListChanged(SLOBSWebsocket sender, List <SLOBSScene> scenes) { throw new NotImplementedException(); }
private void Ws_SceneItemChanged(SLOBSWebsocket sender, SLOBSSceneItemEvent eventdata) { if (eventdata.Type == ESLOBSEventType.SceneItemAdded) { for (int i = 0; i < Scenes.Count; i++) { if (Scenes[i].Id == eventdata.SceneItem.SceneId) { var sceneitem = _translateSceneItem(eventdata.SceneItem, Scenes[i].Items.Count); Scenes[i].Items.Add(sceneitem); if (ActiveScene.Id == Scenes[i].Id) { if (SceneItemChanged != null) { SceneItemChanged(this, EOBSEvent.SceneItemAdded, sceneitem); } } } } } else if (eventdata.Type == ESLOBSEventType.SceneItemRemoved) { int reindex = 0; for (int i = 0; i < Scenes.Count; i++) { if (Scenes[i].Id == eventdata.SceneItem.SceneId) { var sceneitem = _translateSceneItem(eventdata.SceneItem, 0); for (int si = 0; si < Scenes[i].Items.Count; si++) { if (Scenes[i].Items[si].Id == eventdata.SceneItem.Id) { Scenes[i].Items.RemoveAt(si); sceneitem.Index = si; if (ActiveScene.Id == Scenes[i].Id) { if (SceneItemChanged != null) { SceneItemChanged(this, EOBSEvent.SceneItemRemoved, sceneitem); } } } else { var item = Scenes[i].Items[si]; item.Index = reindex; Scenes[i].Items[si] = item; reindex++; } } } } } else if (eventdata.Type == ESLOBSEventType.SceneItemUpdated) { for (int i = 0; i < Scenes.Count; i++) { if (Scenes[i].Id == eventdata.SceneItem.SceneId) { var sceneitem = _translateSceneItem(eventdata.SceneItem, 0); for (int si = 0; si < Scenes[i].Items.Count; si++) { if (Scenes[i].Items[si].Id == eventdata.SceneItem.Id) { sceneitem.Index = si; Scenes[i].Items[si] = sceneitem; if (ActiveScene.Id == Scenes[i].Id) { if (SceneItemChanged != null) { SceneItemChanged(this, EOBSEvent.SceneItemUpdated, sceneitem); } } } } } } } }