public async Task SendCandidate(int roomId, string candidate) { // Validation if (roomId <= 0) { await ReturnError("Could not send candidate", "You must specify a room."); return; } if (candidate.IsNullOrWhitespace()) { await ReturnError("Could not send candidate", "You must specify a candidate."); return; } // Permission Room room = null; await Task.Run(() => room = _roomService.GetRoom(roomId)); if (room == null || !RoomPermissionHelper.CanAddMessage(_context.CurrentUser, room)) { await ReturnError("Could not send candidate", "You do not have permission, the room may have been deleted."); return; } // Notify others in group await Clients.OthersInGroup(roomId.ToString()).SendAsync("ReceiveCandidate", candidate); }
public async Task StopBroadcast(int roomId) { // Validation if (roomId <= 0) { await ReturnError("Could not stop broadcast", "You must specify a room."); return; } // Permission Room room = null; await Task.Run(() => room = _roomService.GetRoom(roomId)); if (room == null || !RoomPermissionHelper.CanAddMessage(_context.CurrentUser, room)) { await ReturnError("Could not stop broadcast", "You do not have permission, the room may have been deleted."); return; } // Notify all in group Models.Broadcast hubBroadcast = new Models.Broadcast { UserId = _context.CurrentUser.Id, StreamId = string.Empty }; await Clients.Group(roomId.ToString()).SendAsync("ReceiveDeleteBroadcast", hubBroadcast); }
public async Task SendMessage(int roomId, string text) { // Validation if (roomId <= 0) { await ReturnError("Could not send message", "You must specify a room."); return; } if (text.IsNullOrWhitespace()) { await ReturnError("Could not send message", "Text must not be null or whitespace."); return; } // Permission Room room = null; await Task.Run(() => room = _roomService.GetRoom(roomId)); if (room == null || !RoomPermissionHelper.CanAddMessage(_context.CurrentUser, room)) { await ReturnError("Could not send message", "You do not have permission, the room may have been deleted."); return; } // Trim message if necessary if (text.Length > 2000) { text = text.Substring(0, 2000); } // Add message to room int messageId = -1; await Task.Run(() => messageId = _roomService.AddMessage(_context.CurrentUser, room, text)); // Html encode the text of the message text = HtmlEncoder.Default.Encode(text); // Notify all in group Models.Message hubMessage = new Models.Message { Id = messageId, UserName = _context.CurrentUser.UserName, UserId = _context.CurrentUser.Id, Text = text, IsDeleted = false, ModifiedId = _context.CurrentUser.Id, ModifiedUserName = _context.CurrentUser.UserName }; await Clients.Group(roomId.ToString()).SendAsync("ReceiveMessage", hubMessage); }
public async Task SendOfferToUser(int roomId, string userId, string offer) { // Validation if (roomId <= 0) { await ReturnError("Could not send offer", "You must specify a room."); return; } if (userId.IsNullOrWhitespace()) { await ReturnError("Could not send offer", "You must specify a user."); return; } if (offer.IsNullOrWhitespace()) { await ReturnError("Could not send offer", "You must specify an offer."); return; } // Permission Room room = null; await Task.Run(() => room = _roomService.GetRoom(roomId)); if (room == null || !RoomPermissionHelper.CanAddMessage(_context.CurrentUser, room)) { await ReturnError("Could not send offer", "You do not have permission, the room may have been deleted."); return; } // Notify specified user await Clients.User(userId).SendAsync("ReceiveOffer", offer, _context.CurrentUser.Id); }