コード例 #1
0
        /// <summary>
        /// Connect this instance to the specified URL, and authenticate (if needed) with the specified password
        /// </summary>
        /// <param name="url">Server URL in standard URL format</param>
        /// <param name="password">Server password</param>
        public void Connect(string url, string password)
        {
            if (WSConnection != null && WSConnection.IsAlive)
            {
                Disconnect();
            }

            WSConnection = new WebSocket(url)
            {
                WaitTime = _pWSTimeout
            };
            WSConnection.OnMessage += WebsocketMessageHandler;
            WSConnection.OnClose   += (s, e) =>
            {
                Disconnected?.Invoke(this, e);
            };
            WSConnection.Connect();

            if (!WSConnection.IsAlive)
            {
                return;
            }

            OBSAuthInfo authInfo = GetAuthInfo();

            if (authInfo.AuthRequired)
            {
                Authenticate(password, authInfo);
            }

            Connected?.Invoke(this, null);
        }
コード例 #2
0
        public void OBSAuthInfo_BuildFromJSON()
        {
            string challenge = "pBWv82hj";
            string salt      = "B9fL8CF7";

            var data = new JObject();

            data.Add("authRequired", true);
            data.Add("challenge", challenge);
            data.Add("salt", salt);

            var authInfo = new OBSAuthInfo(data);

            Assert.IsTrue(authInfo.AuthRequired);
            Assert.AreEqual(challenge, authInfo.Challenge);
            Assert.AreEqual(salt, authInfo.PasswordSalt);
        }
コード例 #3
0
        private void onConnect(object sender, EventArgs e)
        {
            connection_start = true;
            websocket.SendRequestAsync(delegate(JObject r)
            {
                OBSAuthInfo authInfo = new OBSAuthInfo(r);
                if (authInfo.AuthRequired)
                {
                    websocket.AuthenticateAsync(delegate(JObject authresponse)
                    {
                        Console.WriteLine(authresponse);

                        /*cstatus = false;
                         * if (midiStatus != null) midiStatus(this, SMidiEvent.WrongPassword);
                         * return;*/
                    }, OBSPwd, authInfo);
                }
            }, "GetAuthRequired");

            if (ObsTypes == null)
            {
                ObsTypes = new List <OBSSourceTypes>();
                websocket.SendRequestAsync(delegate(JObject response)
                {
                    Version = new OBSVersion(response);
                }, "GetVersion");

                websocket.SendRequestAsync(delegate(JObject response)
                {
                    if ((string)response["status"] == "ok")
                    {
                        JArray items = (JArray)response["types"];
                        ObsTypes.Clear();
                        foreach (JObject typeData in items)
                        {
                            OBSSourceTypes t = new OBSSourceTypes(typeData);
                            ObsTypes.Add(t);
                        }
                    }
                }, "GetSourceTypesList");
            }
        }
コード例 #4
0
        /// <summary>
        /// Authenticates to the Websocket server using the challenge and salt given in the passed <see cref="OBSAuthInfo"/> object
        /// </summary>
        /// <param name="password">User password</param>
        /// <param name="authInfo">Authentication data</param>
        /// <returns>true if authentication succeeds, false otherwise</returns>
        public bool Authenticate(string password, OBSAuthInfo authInfo)
        {
            string secret       = HashEncode(password + authInfo.PasswordSalt);
            string authResponse = HashEncode(secret + authInfo.Challenge);

            var requestFields = new JObject();

            requestFields.Add("auth", authResponse);

            try
            {
                // Throws ErrorResponseException if auth fails
                SendRequest("Authenticate", requestFields);
            }
            catch (ErrorResponseException)
            {
                throw new AuthFailureException();
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Connect this instance to the specified URL, and authenticate (if needed) with the specified password
        /// </summary>
        /// <param name="url">Server URL in standard URL format</param>
        /// <param name="password">Server password</param>
        public void Connect(string url, string password)
        {
            if (Connection != null && IsConnected)
            {
                Disconnect();
            }

            Connection = new WebSocket4Net.WebSocket(url);
            Connection.MessageReceived += OnMessageReceived;
            Connection.Closed          += (sender, args) =>
            {
                Disconnected?.Invoke(this, args);
            };
            Connection.Open();

            DateTime startTime = DateTime.Now;

            do
            {
                if (Connection.State == WebSocketState.Open)
                {
                    break;
                }
            } while (startTime + Timeout < DateTime.Now);

            if (Connection.State != WebSocketState.Open)
            {
                return;
            }

            OBSAuthInfo authInfo = GetAuthInfo();

            if (authInfo.AuthRequired)
            {
                Authenticate(password, authInfo);
            }

            Connected?.Invoke(this, null);
        }