public async Task LeaveChannel(ChannelDto channelDto) { channelDto.Id = Context.ConnectionId; ChannelHandler.ChannelDictionary.Remove(channelDto.Id); await Groups.RemoveFromGroupAsync(Context.ConnectionId, channelDto.ChannelName); await Clients.OthersInGroup(channelDto.Id).UserLeftChannel(channelDto); await Clients.Others.UsersInGroup(ChannelHandler.NumberOfUsersInChannel(channelDto.ChannelName)); }
public async Task JoinChannel(ChannelDto channelDto) { channelDto.Id = Context.ConnectionId; ChannelHandler.ChannelDictionary.Add(channelDto.Id, channelDto.ChannelName); await Groups.AddToGroupAsync(Context.ConnectionId, channelDto.ChannelName); await Clients.OthersInGroup(channelDto.ChannelName).UserJoinedChannel(channelDto); await Clients.Others.UsersInGroup(ChannelHandler.NumberOfUsersInChannel(channelDto.ChannelName)); }
public override async Task OnDisconnectedAsync(Exception exception) { var result = ChannelHandler.ChannelDictionary.TryGetValue(Context.ConnectionId, out var roomName); if (result) { await Groups.RemoveFromGroupAsync(Context.ConnectionId, roomName); await Clients.Others.UserLeftChannel(new ChannelDto { ChannelName = roomName, Id = Context.ConnectionId }); await Clients.Others.UsersInGroup(ChannelHandler.NumberOfUsersInChannel(roomName)); } await base.OnDisconnectedAsync(exception); }
public override async Task OnConnectedAsync() { var result = ChannelHandler.ChannelDictionary.TryGetValue(Context.ConnectionId, out var roomName); if (result) { await Groups.AddToGroupAsync(Context.ConnectionId, roomName); await Clients.Caller.UserJoinedChannel(new ChannelDto { ChannelName = roomName, Id = Context.ConnectionId }); await Clients.Others.UsersInGroup(ChannelHandler.NumberOfUsersInChannel(roomName)); } await base.OnConnectedAsync(); }