Exemplo n.º 1
0
        private async void _server_ConnectionRequest(object sender, ResonanceListeningServerConnectionRequestEventArgs <BluetoothAdapter> e)
        {
            IResonanceTransporter transporter = ResonanceTransporter.Builder
                                                .Create()
                                                .WithAdapter(e.Accept())
                                                .WithJsonTranscoding()
                                                .Build();

            transporter.StateChanged += (x, ee) =>
            {
                if (ee.NewState != ResonanceComponentState.Connected)
                {
                    InvokeUI(() =>
                    {
                        ConnectedDevices.Remove(transporter);
                    });
                }
            };

            transporter.RegisterRequestHandler <ChatMessageRequest, ChatMessageResponse>(OnChatRequest);

            await transporter.ConnectAsync();

            InvokeUI(() =>
            {
                ConnectedDevices.Add(transporter);
                if (SelectedDevice == null)
                {
                    SelectedDevice = transporter;
                }
            });
        }
Exemplo n.º 2
0
        private async void _udpServer_ConnectionRequest(object sender, ResonanceListeningServerConnectionRequestEventArgs <Adapters.Udp.UdpAdapter> e)
        {
            var transporter = ResonanceTransporter.Builder
                              .Create()
                              .WithAdapter(e.Accept())
                              .WithJsonTranscoding()
                              .Build();

            _clients.Add(transporter);

            transporter.ConnectionLost += (x, ee) =>
            {
                transporter.UnregisterService <IRemoteDrawingBoardService>();
                ee.FailTransporter = true;
                Logger.LogError($"A remote client connection lost. {ee.Exception.Message}");
            };

            transporter.RegisterService <IRemoteDrawingBoardService, MainWindowVM>(this);

            await transporter.ConnectAsync();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles incoming connections.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ResonanceListeningServerConnectionRequestEventArgs{Adapters.Tcp.TcpAdapter}"/> instance containing the event data.</param>
        private async void OnConnectionRequest(object sender, ResonanceListeningServerConnectionRequestEventArgs <Adapters.Tcp.TcpAdapter> e)
        {
            ResonanceTcpClient newClient = new ResonanceTcpClient();

            //Enable keep alive so we are aware of clients losing contact.
            newClient.KeepAliveConfiguration.Enabled = true;

            //Configure the transporter fail when the keep alive determines no connection.
            newClient.KeepAliveConfiguration.FailTransporterOnTimeout = true;

            newClient.CreateBuilder()
            .WithAdapter(e.Accept())
            .WithJsonTranscoding()
            .Build();

            newClient.StateChanged += OnClientStateChanged;
            newClient.RegisterRequestHandler <LoginRequest, LoginResponse>(OnClientLoginRequest);
            newClient.RegisterRequestHandler <JoinSessionRequest, JoinSessionResponse>(OnClientJoinSessionRequest);
            newClient.RegisterRequestHandler <LeaveSessionRequest>(OnClientLeaveSessionRequest);

            await newClient.ConnectAsync();
        }