public async Task <bool> TryConnect() { string message; if (Obs != null && !Obs.IsConnected) { try { await Obs.Connect(Config.ServerAddress, Config.ServerPassword).ConfigureAwait(false); message = $"Finished attempting to connect to {Config.ServerAddress}"; if (message != lastTryConnectMessage) { Logger.log?.Info(message); lastTryConnectMessage = message; } } catch (AuthFailureException) { message = $"Authentication failed connecting to server {Config.ServerAddress}."; if (message != lastTryConnectMessage) { Logger.log?.Info(message); lastTryConnectMessage = message; } return(false); } catch (ErrorResponseException ex) { message = $"Failed to connect to server {Config.ServerAddress}: {ex.Message}."; if (message != lastTryConnectMessage) { Logger.log?.Info(message); lastTryConnectMessage = message; } Logger.log?.Debug(ex); return(false); } catch (Exception ex) { message = $"Failed to connect to server {Config.ServerAddress}: {ex.Message}."; if (message != lastTryConnectMessage) { Logger.log?.Info(message); Logger.log?.Debug(ex); lastTryConnectMessage = message; } return(false); } if (Obs.IsConnected) { Logger.log?.Info($"Connected to OBS @ {Config.ServerAddress}"); } } else { Logger.log?.Info("TryConnect: OBS is already connected."); } return(Obs?.IsConnected ?? false); }
public ObsController(OBSWebsocket obs, Application ppt) { Obs = new(obs); Ppt = new(ppt); Obs.SceneChanged += Obs_SceneChanged; Obs.Connect().GetAwaiter().GetResult(); }
private void HandleDisconnected() { if (_isConnected) { return; } Obs.Connect().GetAwaiter().GetResult(); _connectionTimer.Change(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5)); }
private void InitObs() { try { Obs.ConnectionStateChanged += Obs_ConnectionStateChanged; Obs.RecordingStateChanged += Obs_RecordingStateChanged; Obs.StreamingStateChanged += Obs_StreamingStateChanged; Obs.Connect().GetAwaiter().GetResult(); } catch { // Unable to connect to OBS } }
public bool Connect() { Obs.Connect($"ws://{_serverIp}:{_port}", _password); _connectionEstablished = true; //TODO: Temporary fix until Obs.Connect immediately returns connected state return(_connectionEstablished); }