Inheritance: IClientChannel, IServerChannel
Exemplo n.º 1
0
 private void RegisteredClient_OnGetPeerList(RegisteredClient sender, IMessage message)
 {
     sender.OnPeerList(new PeerList
     {
         ReplyFor = message.Id,
         Peers    = GetPeers(sender).Select(s => GetClientInformation(s).PeerData).ToArray()
     });
 }
Exemplo n.º 2
0
 private async void RegisteredClient_OnGetPeerList(RegisteredClient sender, IMessage message)
 {
     await sender.OnPeerListAsync(new PeerList
     {
         ReplyFor = message.Id,
         Peers    = GetPeers(sender).Select(s => GetClientInformation(s).PeerData).ToArray()
     }).CastToTask();
 }
Exemplo n.º 3
0
        private async void RegisteredClient_OnDisconnected(RegisteredClient sender)
        {
            var peers = GetPeers(sender);

            foreach (var registeredClient in peers)
            {
                await registeredClient.OnPeerPresenceAsync(GetClientInformation(sender)).CastToTask();
            }
        }
Exemplo n.º 4
0
        private void RegisteredClient_OnDisconnected(RegisteredClient sender)
        {
            var peers = GetPeers(sender);

            foreach (var registeredClient in peers)
            {
                registeredClient.OnPeerPresence(GetClientInformation(sender));
            }
        }
Exemplo n.º 5
0
        private async void RegisteredClient_OnRelayMessage(RegisteredClient sender, RelayMessage message)
        {
            RegisteredClient receiver;

            if (!Clients.TryGetValue(message.ToUserId, out receiver))
            {
                return;
            }
            message.FromUserId = sender.UserId;
            message.FromName   = sender.Name;
            message.FromAvatar = sender.Avatar;
            await receiver.ServerRelayAsync(message).CastToTask();
        }
Exemplo n.º 6
0
 private PeerUpdate GetClientInformation(RegisteredClient registeredClient)
 {
     return(new PeerUpdate
     {
         PeerData = new PeerData
         {
             UserId = registeredClient.UserId,
             Name = registeredClient.Name,
             IsOnline = registeredClient.IsOnline,
             Avatar = registeredClient.Avatar
         },
         SentDateTimeUtc = DateTimeOffset.UtcNow
     });
 }
Exemplo n.º 7
0
 private PeerUpdate GetClientInformation(RegisteredClient registeredClient)
 {
     return new PeerUpdate
     {
         PeerData = new PeerData
         {
             UserId = registeredClient.UserId,
             Name = registeredClient.Name,
             IsOnline = registeredClient.IsOnline,
             Avatar = registeredClient.Avatar
         },
         SentDateTimeUtc = DateTimeOffset.UtcNow
     };
 }
Exemplo n.º 8
0
        public async Task <bool> HandleRegistrationAsync(UnregisteredConnection unregisteredConnection,
                                                         Registration message)
        {
            Logger.Info($"Handling the registration of connection {unregisteredConnection}");
            RegisteredClient registeredClient;

            if (Clients.ContainsKey(message.UserId))
            {
                if (Clients.TryGetValue(message.UserId, out registeredClient))
                {
                    Logger.Debug($"Client identified. {registeredClient}");
                }
                else
                {
                    Logger.Warn("Error in retrieving client.");
                    return(false);
                }
            }
            else
            {
                registeredClient = new RegisteredClient
                {
                    UserId = message.UserId,
                    Domain = Name,
                    Name   = message.Name,
                    Avatar = Clients.Count + 1
                };
                registeredClient.OnConnected    += RegisteredClient_OnConnected;
                registeredClient.OnDisconnected += RegisteredClient_OnDisconnected;
                registeredClient.OnGetPeerList  += RegisteredClient_OnGetPeerList;
                registeredClient.OnRelayMessage += RegisteredClient_OnRelayMessage;

                if (Clients.TryAdd(registeredClient.UserId, registeredClient))
                {
                    Logger.Info($"Registered new client. {registeredClient}");
                }
                else
                {
                    Logger.Warn("Could not register new client.");
                    return(false);
                }
            }

            await registeredClient.SetActiveConnectionAsync(unregisteredConnection, message);

            return(true);
        }
Exemplo n.º 9
0
        public bool HandleRegistration(UnregisteredConnection unregisteredConnection, Registration message)
        {
            Logger.Info($"Handling the registration of connection {unregisteredConnection}");
            RegisteredClient registeredClient;
            if (Clients.ContainsKey(message.UserId))
            {
                if (Clients.TryGetValue(message.UserId, out registeredClient))
                {
                    Logger.Debug($"Client identified. {registeredClient}");
                }
                else
                {
                    Logger.Warn("Error in retrieving client.");
                    return false;
                }
            }
            else
            {
                registeredClient = new RegisteredClient
                {
                    UserId = message.UserId,
                    Domain = Name,
                    Name = message.Name,
                    Avatar = Clients.Count + 1
                };
                registeredClient.OnConnected += RegisteredClient_OnConnected;
                registeredClient.OnDisconnected += RegisteredClient_OnDisconnected;
                registeredClient.OnGetPeerList += RegisteredClient_OnGetPeerList;
                registeredClient.OnRelayMessage += RegisteredClient_OnRelayMessage;

                if (Clients.TryAdd(registeredClient.UserId, registeredClient))
                {
                    Logger.Info($"Registered new client. {registeredClient}");
                }
                else
                {
                    Logger.Warn("Could not register new client.");
                    return false;
                }
            }

            registeredClient.SetActiveConnection(unregisteredConnection, message);
            return true;
        }
Exemplo n.º 10
0
 private List <RegisteredClient> GetPeers(RegisteredClient sender)
 {
     return(Clients.Where(s => s.Key != sender.UserId).Select(s => s.Value).ToList());
 }
Exemplo n.º 11
0
 private void RegisteredClient_OnConnected(RegisteredClient sender)
 {
     var peers = GetPeers(sender);
     foreach (var registeredClient in peers)
     {
         registeredClient.OnPeerPresence(GetClientInformation(sender));
     }
 }
Exemplo n.º 12
0
 private List<RegisteredClient> GetPeers(RegisteredClient sender)
 {
     return Clients.Where(s => s.Key != sender.UserId).Select(s => s.Value).ToList();
 }
Exemplo n.º 13
0
 private void RegisteredClient_OnRelayMessage(RegisteredClient sender, RelayMessage message)
 {
     RegisteredClient receiver;
     if (!Clients.TryGetValue(message.ToUserId, out receiver))
     {
         return;
     }
     message.FromUserId = sender.UserId;
     message.FromName = sender.Name;
     message.FromAvatar = sender.Avatar;
     receiver.ServerRelay(message);
 }
Exemplo n.º 14
0
 private void RegisteredClient_OnGetPeerList(RegisteredClient sender, IMessage message)
 {
     sender.OnPeerList(new PeerList
     {
         ReplyFor = message.Id,
         Peers = GetPeers(sender).Select(s => GetClientInformation(s).PeerData).ToArray()
     });
 }