/// <summary> /// Server side method called from client to subscribe to message labeled with the indicated label /// </summary> /// <param name="topic">Topic</param> /// <returns></returns> public async Task SubscribeAsync(string topic) { await Groups.AddAsync(topic); _logger.LogInformation("Client '{0}' subscribed to topic '{1}'", Context.ConnectionId, topic); }
public Task GroupAddMethod(string groupName) { return(Groups.AddAsync(Context.ConnectionId, groupName)); }
public Task AddSelfToGroup(string group) { return(Groups.AddAsync(Context.ConnectionId, group)); }
public async Task Bet(int id) { await Groups.AddAsync(Context.ConnectionId, id.ToString()); }
public async Task JoinRoom(string room) { await Groups.AddAsync(this.Context.ConnectionId, room); }
public async Task JoinGame(int sessionId) { var loggedPlayer = GetLoggedPlayer(); var groupName = MapSessionIdToGroupName(sessionId); await Groups.AddAsync(Context.ConnectionId, groupName); }
public override async Task OnConnectedAsync() { await Groups.AddAsync(Context.User.Identity.Name, "SignalR Users"); await base.OnConnectedAsync(); }
public async Task Join(string uid) { await Groups.AddAsync(Context.ConnectionId, uid); }
public Task AddGroup(string groupName) => Groups.AddAsync(Context.ConnectionId, groupName);
public async void AdminLogin() { await Groups.AddAsync(this.Context.ConnectionId, AdminGroupName); }
public async Task Join(JoinModel model) { var userId = Context.User.GetUserId(); var user = await _db.Users.FindAsync(userId); var channel = await _db.Channels.Include(i => i.Owner) .Include(i => i.Users) .ThenInclude(i => i.User) .FirstOrDefaultAsync(i => i.Id == model.ChannelId); var userEngage = await _db.ChannelUsers.FirstOrDefaultAsync(i => i.ChannelId.Equals(model.ChannelId) && i.UserId.Equals(userId)); if (user != null && channel != null) { if (!userId.Equals(channel.OwnerId)) { if (userEngage != null) { if (userEngage.State == (int)UserStates.Blocked) { await Clients.Client(Context.ConnectionId).InvokeAsync("Disconnect"); return; } } else { await Clients.Client(Context.ConnectionId).InvokeAsync("Disconnect"); } } // online users var users = (await _tracker.All(model.ChannelId.ToString())).ToList(); if (users.Any(i => i.UserId.Equals(userId))) { await Clients.Client(Context.ConnectionId).InvokeAsync("AlreadyConnnected"); return; } await Groups.AddAsync(Context.ConnectionId, model.ChannelId.ToString()); var userDetail = new UserDetail(Context.ConnectionId, user.UserName, model.ChannelId.ToString(), userId, channel.OwnerId == userId ? (int)UserStates.Authorize : userEngage.State); users.Add(userDetail); _tracker.Add(Context.Connection, userDetail); #region User List // load user list var engagedUsers = channel.Users .Where(i => i.ChannelId.Equals(model.ChannelId)) .Select(i => new UserDetail(string.Empty, i.User.UserName, model.ChannelId.ToString(), i.UserId, i.State) ) .ToList(); // add the owner engagedUsers.Add(new UserDetail(string.Empty, channel.Owner.UserName, model.ChannelId.ToString(), channel.OwnerId, (int)UserStates.Authorize)); // if users online take the connection ids foreach (var item in users) { var temp = engagedUsers.FirstOrDefault(i => i.UserId.Equals(item.UserId)); if (temp != null) { temp.ConnectionId = item.ConnectionId; } } // send user await Clients.Client(Context.ConnectionId).InvokeAsync("UserList", engagedUsers); #endregion // broadcast the user join await Clients.Group(model.ChannelId.ToString()).InvokeAsync("UserJoined", userDetail); #region Load messages var currentUser = await _tracker.Find(Context.ConnectionId); var messages = _redis_db.ListRange(userDetail.GroupId.ToString(), 0, -1); foreach (var message in messages) { TextModel text = JsonConvert.DeserializeObject <TextModel>(message); await Clients.Client(Context.ConnectionId).InvokeAsync("Receive", text); } #endregion } }
public override Task OnConnectedAsync() { Groups.AddAsync(Context.User.Identity.Name, "SignalR Users"); return(base.OnConnectedAsync()); }
public async Task SubscribeToGroup(string groupId) { await Groups.AddAsync(Context.ConnectionId, groupId); }
public async Task JoinGroup(string groupName, string UserNickName) { await Groups.AddAsync(Context.ConnectionId, groupName); }
public async Task <string> ConnectGroup(string stocName, string connectionID) { await Groups.AddAsync(connectionID, stocName); return($"{connectionID} is added {stocName}"); }
public async Task JoinGroup(string groupName, string UserNickName) { await Groups.AddAsync(Context.ConnectionId, groupName); await Clients.Group(groupName).InvokeAsync("Send", "-- " + UserNickName + " joined --"); }
public async override Task OnConnectedAsync() { await base.OnConnectedAsync(); await Groups.AddAsync(Context.ConnectionId, Context.User.GetUserId().ToString()); }
// public override Task OnConnected() // { // // Set connection id for just connected client only // return Clients.Client(Context.ConnectionId).SetConnectionId(Context.ConnectionId); // } // Server side methods called from client public Task Subscribe(string chatroom) { return(Groups.AddAsync(Context.ConnectionId, chatroom.ToString())); }
// Server side methods called from client public Task Subscribe(int chatId) { return(Groups.AddAsync(Context.ConnectionId, chatId.ToString())); }
public async Task JoinTeam(string groupName) { await Groups.AddAsync(Context.ConnectionId, groupName); await Clients.Group(groupName).SendAsync("JoinTeam", $"{Context.ConnectionId} has joined the group {groupName}."); }
public async Task OnConnected(string userID) { await Groups.AddAsync(Context.ConnectionId, userID); }
public async Task Subscribe(string subscriptionId) => await Groups.AddAsync(Context.ConnectionId, subscriptionId);
public Task JoinToGroup(Guid groupId) { return(Groups.AddAsync(Context.ConnectionId, groupId.ToString())); }
/// <summary> /// 加入房间 /// </summary> /// <param name="roomHashid">房间哈希ID</param> /// <returns>表示加入房间的任务,返回房间名和加入该房间的时间</returns> public async Task <ChatRoomInitialDisplayDto> JoinRoomAsync(string roomHashid) { var roomId = HashidsHelper.Decode(roomHashid); var userId = HashidsHelper.Decode(Context.User.FindFirst("uid").Value); var username = HttpUtility.UrlDecode(Context.User.Identity.Name); // 因为用户可能会尝试用一个账号同时登陆两个房间 // 这里查询条件不加上房间ID,前一个房间内的用户会被提示在别处登录 var connection = await _dbContext.Connection .FirstOrDefaultAsync(x => x.UserId == userId); string msgId = null; string connIdToBeRemoved = null; if (connection == null) { // 第一次进入该房间 msgId = "I001"; _dbContext.Add(new Connection { RoomId = roomId, UserId = userId, Username = username, ConnectionId = Context.ConnectionId }); } else { // 如果用户同时打开两个窗口 if (connection.IsOnline.Value) { connIdToBeRemoved = connection.ConnectionId; } // 重连的情况下 msgId = "I003"; connection.IsOnline = true; connection.ConnectionId = Context.ConnectionId; // 只保留一条记录 _dbContext.Update(connection); } await _dbContext.SaveChangesAsync(); // 将用户添加到分组 await Groups.AddAsync(Context.ConnectionId, roomHashid); // 只加载加入房间前的消息,避免消息重复显示 long unixTimeMilliseconds = new DateTimeOffset(DateTime.Now).ToUnixTimeMilliseconds(); // 显示欢迎用户加入房间的消息 await Clients.Group(roomHashid).InvokeAsync( "receiveSystemMessage", _msg.GetMessage(msgId, username)); if (!string.IsNullOrEmpty(connIdToBeRemoved)) { // 前一个窗口显示消息,告知账号已经在其他地方登陆 await Clients.Client(connIdToBeRemoved).InvokeAsync("onDuplicateLogin"); await Groups.RemoveAsync(connIdToBeRemoved, roomHashid); } // 显示用户列表 await RefreshMemberListAsync(roomHashid, roomId); var room = await _dbContext.ChatRoom .Where(r => r.Id == roomId) .Select(r => new { r.Name, r.OwnerId }) .FirstOrDefaultAsync(); return(new ChatRoomInitialDisplayDto { OwnerId = HashidsHelper.Encode(room.OwnerId), RoomName = room.Name, EntryTime = unixTimeMilliseconds }); }
public async Task JoinGroup(string groupName) { await Groups.AddAsync(Context.ConnectionId, groupName); await Clients.Group(groupName).InvokeAsync("Send", $"{Context.ConnectionId} joined {groupName}"); }
public async Task JoinGroup() { await Groups.AddAsync($"notification_{_context.User.Identity.Name}"); }
public Task Subscribe(string clientName) { return(Groups.AddAsync(Context.ConnectionId, clientName)); }
/// <summary> /// Joins user to group by name. /// </summary> /// <param name="groupName">Name of user group (self)</param> /// <returns></returns> public async Task JoinGroup(string groupName) { await Groups.AddAsync(Context.ConnectionId, groupName); Console.WriteLine($"{Context.ConnectionId} joined to group \"{groupName}\""); }
public void Subscribe(int stationId) { Groups.AddAsync(Context.ConnectionId, stationId.ToString()); }
public override async Task OnConnectedAsync() { await Groups.AddAsync(Context.ConnectionId, Context.User.Identity.Name); await base.OnConnectedAsync(); }