예제 #1
0
 private List <string> GetConnectionIdList(string messageId, CommentAccount commentAccount)
 {
     if (RoomDictionary.ContainsKey(messageId))
     {
         //TODO 防止重覆加
         RoomDictionary[messageId].Add(commentAccount);
     }
     else
     {
         RoomDictionary.Add(messageId, new List <CommentAccount> {
             commentAccount
         });
     }
     return(RoomDictionary[messageId].Select(x => x.ConnectionId).ToList());
 }
예제 #2
0
            public void JoinRoom(string messageId, int userId)
            {
                //string messageId = GetMessageId();
                var commentAccount = new CommentAccount
                {
                    Account            = userId,
                    ConnectionId       = Context.ConnectionId,
                    CommentAccountType = CommentAccountType.PostAccount
                };
                var connectionIds = GetConnectionIdList(messageId, commentAccount);

                //Clients.All.connected($"ConnectionId:{Context.ConnectionId},messageId:{messageId},int userId:{userId}");
                //Clients.Clients(connectionIds).joinRoom(messageId, $"int userId:{userId}");
                Clients.Group(messageId).joinRoom(messageId, $"int userId:{userId}");
            }