Esempio n. 1
0
        public async Task ConnectAsync(string hostName)
        {
            Close();

            _socket            = _socketFactory.Create();
            _socket.OnMessage += OnMessage;
            _socket.Connect($"ws://{hostName}:3000");

            if (!_socket.IsAlive)
            {
                throw new ConnectionException($"Unable to conenct to television at {hostName}.");
            }

            _hostName = hostName;

            var key = await _keyStore.GetKeyAsync(hostName);

            var handshakeCommand  = new HandshakeCommand(key);
            var handshakeResponse = await SendCommandAsync <HandshakeResponse>(handshakeCommand);

            await _keyStore.StoreKeyAsync(hostName, handshakeResponse.Key);

            var mouseCommand     = new MouseGetCommand();
            var mouseGetResponse = await SendCommandAsync <MouseGetResponse>(mouseCommand);

            _mouseSocket = _socketFactory.Create();
            _mouseSocket.Connect(mouseGetResponse.SocketPath);

            if (!_mouseSocket.IsAlive)
            {
                throw new ConnectionException($"Unable to conenct to television mouse service at {hostName}.");
            }
        }
        public async void EstablishConnection()
        {
            if (_connection.IsConnected)
            {
                if (SignalingStatus.IsRegistered)
                {
                    OnRegistered?.Invoke();
                }
                else
                {
                    _connection.Register();
                }
            }
            else
            {
                _isConnecting = true;
                UpdateStatus();

                await _connection.Connect();

                _isConnecting = false;
                UpdateStatus();
            }
        }