/// <summary>
        /// Connects to the OBS WebSocket server
        /// </summary>
        /// <returns></returns>
        public void Connect(ObsWebSocketClientSettings settings)
        {
            if (obsWebSocket.IsConnected)
            {
                obsWebSocket.Disconnect();
            }

            obsWebSocket.Connect($"ws://{settings.IpAddress}:{settings.Port}", settings.Password ?? "");
        }
Example #2
0
 private void tmrWebsocketConnect_Tick(object sender, EventArgs e)
 {
     Console.WriteLine("Checking connection to OBS Websocket");
     if (_obs.IsConnected)
     {
         lblCurrentScene.Text = _obs.Api.GetCurrentScene().Name;
         chkStreaming.Checked = _obs.Api.GetStreamingStatus().IsStreaming;
         chkRecording.Checked = _obs.Api.GetStreamingStatus().IsRecording;
         Console.WriteLine("OBS IS CONNECTED");
     }
     else
     {
         Console.WriteLine("OBS IS DISCONNECTED");
         try
         {
             _obs.Connect("ws://" + Properties.Settings.Default.WebsocketHost + ":4444", Properties.Settings.Default.WebsocketPassword);
         }
         catch (AuthFailureException)
         {
             MessageBox.Show("Authentication failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         catch (ErrorResponseException ex)
         {
             MessageBox.Show("Connect failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
Example #3
0
        /// <summary>
        /// Establish a connection to OBS
        /// </summary>
        /// <param name="port"></param>
        /// <returns></returns>
        public Task Connect()
        {
            _OBS = new ObsWebSocket();
            _OBS.Connect($"ws://{_IpAddress}", "");

            return(Task.CompletedTask);
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try {
                if (!_obs.IsConnected) {
                    try {
                        //connect
                        Console.WriteLine(Properties.Settings.Default.obspassword);
                        _obs.Connect(Properties.Settings.Default.obsurl, Properties.Settings.Default.obspassword);
                    }
                    catch (AuthFailureException) {
                        MessageBox.Show("OBSが起動されている、またはアドレス、パスワードが正しいか確認してください。", "OBSの接続に失敗しました");
                        _obs.Disconnect();
                        return;
                    }
                    catch (ErrorResponseException) {
                        Console.WriteLine("あe");
                        _obs.Disconnect();
                        return;
                    }
                }
                else {
                    _obs.Disconnect();
                }

                //display running status
                ConnectOrDisconnect(null, null);
            }
            catch (ArgumentException) {
                MessageBox.Show("アドレスまたはパスワードが無効です。", "エラー");
                UrlTextbox.Text = "ws://127.0.0.1:4444";
            }

        }
Example #5
0
        private static async Task Main(string[] args)
        {
            Settings = SettingLoader.Load();

            SetTimer();

            ObsWebSocket.Connected    += ObsWebSocket_Connected;
            ObsWebSocket.Disconnected += ObsWebSocket_Disconnected;

            ObsWebSocket.Connect(Settings.Url, Settings.Password);

            await ConsoleHost.WaitAsync();

            ObsWebSocket.Disconnect();
Example #6
0
        public override void Enable()
        {
            _obs = new ObsWebSocket();

            try
            {
                _obs.Connect(OBS_URI, OBS_PASSWORD);
                _obs.Api.SetHeartbeat(true);
                _obs.Heartbeat += UpdateHeartbeat;

                DataModel.IsConnected = true;
            }
            catch
            {
                DataModel.IsConnected = false;
                //logger
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            var _obs = new ObsWebSocket();

            _obs.Connect("ws://127.0.0.1:4444", "");

            var settings = _obs.Api.GetSourceSettings("PictureOverlay");

            var currentDir = Directory.GetCurrentDirectory();
            var imagesDir  = Path.GetFullPath(Path.Combine(currentDir, @"..\..\..\..\Images"));
            var imageName  = "check";
            var filePath   = $"{imagesDir}/{imageName}.png".Replace(@"\", @"/");

            string json = "{\"file\": \"" + filePath + "\"}";

            JObject obj = JObject.Parse(json);

            _obs.Api.SetSourceSettings("PictureOverlay", new JObject(obj));

            Console.ReadLine();
        }
        public static void Open()
        {
            if (_obs != null || _running)
            {
                return;
            }

            _running = true;

            _obs = new ObsWebSocket();

            _obs.StreamStatus += OnStreamData;

            try
            {
                _connecting = true;
                _tip        = false;
                MainWindow.Form.AddInfo("尝试连接OBS中...");
                _ctip = true;
                _obs.Connect(connectTo, connectPassword);
                _thread = new Thread(CheckConnection);
                _thread.Start();
            }
            catch (AuthFailureException)
            {
                MainWindow.Form.AddInfo(InfoType.ERROR, "身份验证失败,请确认OBS Studio的WebSocket设置密码为空");
            }
            catch (ErrorResponseException ex)
            {
                MainWindow.Form.AddInfo(InfoType.ERROR, "尝试连接OBS时发生错误: " + ex.Message);
            }
            finally
            {
                _connecting = false;
            }
        }
Example #9
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     if (!_obs.IsConnected)
     {
         try
         {
             _obs.Connect(txtServerIP.Text, txtServerPassword.Text);
         }
         catch (AuthFailureException)
         {
             MessageBox.Show("Authentication failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
         }
         catch (ErrorResponseException ex)
         {
             MessageBox.Show("Connect failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
         }
     }
     else
     {
         _obs.Disconnect();
     }
 }
Example #10
0
 public Task Connect()
 {
     _OBS = new ObsWebSocket();
     _OBS.Connect($"ws://127.0.0.1:4444", "");
     return(Task.CompletedTask);
 }
 private static void CheckConnection()
 {
     while (!MainWindow._isClosing)
     {
         Thread.Sleep(1000);
         if (MainWindow._isClosing)
         {
             break;
         }
         if (_obs != null && _running)
         {
             if (!_obs.IsConnected && !_connecting)
             {
                 Connected = false;
                 _tip      = false;
                 App.Current.Dispatcher.Invoke(() =>
                 {
                     MainWindow.Form.ObsState_Connect.Content = "OBS未连接";
                 });
                 try
                 {
                     _connecting = true;
                     if (!_ctip)
                     {
                         MainWindow.Form.AddInfo("尝试连接OBS中...");
                         _ctip = true;
                     }
                     _obs.Connect(connectTo, connectPassword);
                 }
                 catch (AuthFailureException)
                 {
                     MainWindow.Form.AddInfo(InfoType.ERROR, "身份验证失败,请确认OBS Studio的WebSocket设置密码为空");
                 }
                 catch (ErrorResponseException ex)
                 {
                     MainWindow.Form.AddInfo(InfoType.ERROR, "尝试连接OBS时发生错误: " + ex.Message);
                 }
                 finally
                 {
                     _connecting = false;
                 }
             }
             else
             {
                 Connected = true;
                 App.Current.Dispatcher.Invoke(() =>
                 {
                     MainWindow.Form.ObsState_Connect.Content = "OBS已连接";
                 });
                 if (!_tip)
                 {
                     MainWindow.Form.AddInfo("已成功连接至OBS");
                 }
                 _tip = true;
             }
         }
         else
         {
             Connected = false;
             _tip      = false;
             App.Current.Dispatcher.Invoke(() =>
             {
                 MainWindow.Form.ObsState_Connect.Content = "OBS未连接";
             });
         }
     }
 }