public void SwitchAdminForRoom(string roomName, string userName) { if (!roomName.IsEmpty() && !userName.IsEmpty()) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(roomName); if (room != null) { if (room.currentAdmin.UserName == userName && room.Users.Count > 1) { Random random = new Random(); for (bool quit = false; quit != true;) { int index = random.Next(room.Users.Count); if (room.Users[index].UserName != userName) { room.currentAdmin = room.Users[index]; quit = true; Log.Debug("Old admin: " + userName + " New admin: " + room.currentAdmin.UserName); db.Save(); } } } UpdateUsersInRoom(roomName); } } } }
public void UpdatePlaylist(string roomName) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetById(roomName); if (room != null && VideosInRoom.ContainsKey(roomName)) { Clients.Caller.changeVideoSource(ToJsonRange(VideosInRoom[roomName])); } } }
public void SetCallerCurrentTime(string roomName) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(roomName); if (room != null) { //Clients.Caller.(roomTimes[roomName]); } } }
public void ValueForCallerRoomTime(string roomName, float time) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(roomName); if (room != null) { Clients.Caller.setTime(time); } } }
public void UpdateUsersInRoom(string roomName) { if (!roomName.IsEmpty()) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(roomName); if (room != null && room.Users.Count > 0) { Clients.Group(roomName).updateUsersInRoom(ToJson(room)); } } } }
public void GetUsersInRoom(string roomName) { if (!roomName.IsEmpty()) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(roomName); if (room.Users.Count > 0) { Clients.Caller.updateUsersInRoom(ToJsonRange(room.Users), room); } } } }
public void RemoveFromRoom(string roomName) { using (ApplicationDbContext db = new ApplicationDbContext()) { // Retrieve room. ConversationRoom room = db.Rooms.Find(roomName); if (room != null) { ApplicationUser user = db.Users.Include(u => u.Rooms).SingleOrDefault(u => u.UserName == Context.User.Identity.Name); room.Users.Remove(user); db.SaveChanges(); Groups.Remove(Context.User.Identity.GetUserId(), roomName); } } }
public void SwitchCurrentRoom(string newRoomName) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(newRoomName); ApplicationUser user = db.userRepository.GetById(Context.User.Identity.GetUserId()); if (room != null && user != null) { ChatViewModel newCurrentRoom = currentRooms.FirstOrDefault(r => r.room.RoomName == newRoomName); if (newCurrentRoom == null) { newCurrentRoom = new ChatViewModel(); newCurrentRoom.room.RoomName = room.RoomName; newCurrentRoom.room.currentVideoId = 0; newCurrentRoom.currentRoomTime = 0.0f; newCurrentRoom.room.Users.Add(user); currentRooms.Add(newCurrentRoom); } else { newCurrentRoom.room.Users.Add(user); Clients.Caller().timeUpdate(newCurrentRoom.currentRoomTime); } CurrentRoomsOfUsers[HttpContext.Current.User.Identity.GetUserId()] = newRoomName; foreach (ApplicationUser rUser in room.Users) { if (!CurrentRoomsOfUsers.TryGetValue(rUser.UserName, out string userName)) { continue; } Connection connection = rUser.Connections.SingleOrDefault(c => c.ConnectionID == Context.ConnectionId); if (connection != null) { Clients.Client(connection.ConnectionID).forceTimeUpdateServer(); } Clients.Caller().timeUpdate(roomTimes[newRoomName]); } //var users CurrentRoomsOfUsers[newRoomName]; //Clients. } } }
public void RequestTimeSynch(string roomName, string userName) { if (!roomName.IsEmpty()) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(roomName); if (room != null) { string connection = room.currentAdmin.currentConnectionId;//Connections.SingleOrDefault(c => c.Connected == true); if (connection != null && room.currentAdmin.Id != Context.User.Identity.GetUserId()) { Clients.Client(connection).synchWith(userName); } } } } }
public void JoinRoom(string roomName) { using (ApplicationDbContext db = new ApplicationDbContext()) { // Retrieve room. ConversationRoom room = db.Rooms.Find(roomName); if (room != null) { ApplicationUser user = db.Users.Find(Context.User.Identity.GetUserId()); //db.Users.Attach(user); room.Users.Add(user); db.SaveChanges(); Groups.Add(Context.User.Identity.GetUserId(), roomName); } } }
public static string ToJson(ConversationRoom room) { StringWriter sw = new StringWriter(); JsonTextWriter writer = new JsonTextWriter(sw); writer.WriteStartObject(); writer.WritePropertyName("roomName"); writer.WriteValue(room.RoomName); writer.WritePropertyName("Admin"); writer.WriteRawValue(ToJson(room.currentAdmin)); writer.WritePropertyName("Users"); writer.WriteRawValue(ToJsonRange(room.Users)); writer.WriteEndObject(); return(sw.ToString()); }
public void RemoveFromRoom(string roomName) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetById(roomName); if (room != null) { ApplicationUser user = db.userRepository.GetById(Context.User.Identity.GetUserId()); room.Users.Remove(user); user.Rooms.Remove(room); db.userRepository.Update(user); db.conversationRoomRepository.Update(room); db.Save(); Groups.Remove(Context.ConnectionId, roomName); } } }
public void SendGroupMessage(string roomName, string message) { string name = Context.User.Identity.Name; using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetById(roomName); ApplicationUser user = db.userRepository.GetById(Context.User.Identity.GetUserId()); if (room == null) { Clients.Caller.showErrorMessage("Could not find that room."); } else { IEnumerable <Connection> connections = user.Connections.Where(c => c.Connected == true); Message msg = new Message() { Room = room, SenderUser = user, SenderUserId = user.Id, message = message, sendDate = DateTime.Now }; Clients.OthersInGroup(roomName).addMessage(Context.User.Identity.Name, message, roomName, msg.sendDate.ToString()); Clients.Caller.addCallerMessage(Context.User.Identity.Name, message, msg.sendDate.ToString()); db.messageRepository.Create(msg); db.Save(); } } }
public void SetRoomTime(string roomName) { using (UnitOfWork db = new UnitOfWork()) { ConversationRoom room = db.conversationRoomRepository.GetByRoomName(roomName); if (room != null) { //List<ConnectionsId> ChatViewModel currentState = currentRooms.SingleOrDefault(r => r.room.RoomName == room.RoomName); foreach (ApplicationUser user in room.Users) { if (currentState.room.Users.Contains(user)) { } } foreach (ApplicationUser user in currentState.room.Users) { //var connection = user.Connections() Clients.Client(roomName).setTime(roomTimes[roomName]); } } } }
//"[{"sources":[{"src":"www.youtube.com/watch?v=1cHXjnli2fI","type":"video/youtube"}],"poster":"https://img.youtube.com/vi/1cHXjnli2fI/mqdefault.jpg"},{"sources":[{"src":"www.youtube.com/watch?v=65r_1TzJXaQ","type":"video/youtube"}],"poster":"https://img.youtube.com/vi/65r_1TzJXaQ/mqdefault.jpg"},{"sources":[{"src":"www.youtube.com/watch?v=wuYPnkDbFFU","type":"video/youtube"}],"poster":"https://img.youtube.com/vi/wuYPnkDbFFU/mqdefault.jpg"},{"sources":[{"src":"www.youtube.com/watch?v=xU-3Zdei1N0","type":"video/youtube"}],"poster":"https://img.youtube.com/vi/xU-3Zdei1N0/mqdefault.jpg"},]" public async Task <IEnumerable <YoutubeVideo> > ChangeVideoSource(string roomName, string source) { if (roomName != null && source.Contains("yotu")) { using (UnitOfWork db = new UnitOfWork()) { YoutubeClient youtubeX = new YoutubeClient(); List <YoutubeVideo> newVideos = new List <YoutubeVideo>(); ConversationRoom room = db.conversationRoomRepository.GetById(roomName); //YoutubeClient youtube = new YoutubeClient(); if (source.Contains("list=")) { YoutubeExpld.Playlists.Playlist playlist = await youtubeX.Playlists.GetAsync(source); HashSet <string> newVideoIds = new HashSet <string>(); while (true) { int i = 0; var playlistArray = await youtubeX.Playlists.GetVideosAsync(playlist.Id, 500, newVideoIds.Count(), 5, newVideoIds); foreach (YoutubeExpld.Videos.Video vid in playlistArray) { YoutubeVideo newVid = new YoutubeVideo() { source = "https://www.youtube.com/watch?v=" + vid.Id, poster = vid.Thumbnails.MediumResUrl, title = vid.Title, duration = vid.Duration.TotalSeconds, thumbnail = vid.Thumbnails.StandardResUrl }; lock (SynchronousReadLock) { newVideos.Add(newVid); } i++; } if (i == 0) { break; } //Clients.Caller.previewLoadedVideos(ToJsonRange(newVideos)); } VideosInRoom.AddOrUpdate(roomName, newVideos, (key, oldValue) => { oldValue.AddRange(newVideos); return(oldValue); }); } else if (source.Contains("watch") && !source.Contains("list=")) { var youtube = new YoutubeClient(); // You can specify video ID or URL var video = await youtube.Videos.GetAsync(source); YoutubeVideo newVid = new YoutubeVideo() { source = "https://www.youtube.com/watch?v=" + video.Id, poster = video.Thumbnails.MediumResUrl, title = video.Title, duration = video.Duration.TotalSeconds, thumbnail = video.Thumbnails.StandardResUrl }; lock (SynchronousReadLock) { newVideos.Add(newVid); } VideosInRoom.AddOrUpdate(roomName, newVideos, (key, oldValue) => { oldValue.AddRange(newVideos); return(oldValue); }); } Log.Debug("APP DOMAIN ID = " + AppDomain.CurrentDomain.Id); if (VideosInRoom.ContainsKey("roomName")) { Clients.Group(roomName).changeVideoSource(ToJsonRange(VideosInRoom[roomName])); } } } return(null); }