public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();

            IOnlineClient onlineClient = CreateClientForCurrentConnection();

            Logger.LogDebug("A client is connected: " + onlineClient.ToString());
            OnlineClientManager.Add(onlineClient);
        }
Пример #2
0
        public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();

            IOnlineClient onlineClient = CreateClientForCurrentConnection();

            Logger.LogDebug("A client is connected: " + onlineClient.ToString());
            OnlineClientManager.Add(onlineClient);
            if (onlineClient.TenantId.HasValue)
            {
                // 以租户为分组,将用户加入租户通讯组
                await Groups.AddToGroupAsync(onlineClient.ConnectionId, onlineClient.TenantId.Value.ToString());
            }
        }
Пример #3
0
        public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();

            IOnlineClient onlineClient = CreateClientForCurrentConnection();

            Logger.LogDebug("A client is connected: " + onlineClient.ToString());
            OnlineClientManager.Add(onlineClient);
            // 加入通讯组
            var userGroups = await UserGroupStore.GetUserGroupsAsync(onlineClient.TenantId, onlineClient.UserId.Value);

            foreach (var group in userGroups)
            {
                await Groups.AddToGroupAsync(onlineClient.ConnectionId, group.Name);
            }
        }
 public virtual async Task OnConnectedAsync(IOnlineClient client)
 {
     Logger.LogDebug("A client is connected: " + client.ToString());
     OnlineClientManager.Add(client);
     await OnClientConnectedAsync(client);
 }
Пример #5
0
        private void AddClientToRedisStore(IOnlineClient client)
        {
            var _database = GetDatabase();

            _database.HashSet(_clientStoreKey, new HashEntry[] { new HashEntry(client.ConnectionId, client.ToString()) });
            var userId = client.ToUserIdentifierOrNull();

            if (userId == null)
            {
                return;
            }

            var userClients      = new List <string>();
            var userClientsValue = _database.HashGet(_userStoreKey, userId.ToUserIdentifierString());

            if (userClientsValue.HasValue)
            {
                userClients = JsonConvert.DeserializeObject <List <string> >(userClientsValue);
            }

            if (userClients.Contains(client.ConnectionId))
            {
                return;
            }

            userClients.Add(client.ConnectionId);
            _database.HashSet(_userStoreKey, new HashEntry[] { new HashEntry(userId.ToUserIdentifierString(), userClients.ToJsonString()) });
        }