public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets) { string id = data["id"] as string; int startSeconds = 0; if (data.ContainsKey("t")) { startSeconds = (int)(long)data["t"]; } if (room != null) { var videoInfo = room.AddVideo(id, startSeconds); if (YoutubeHelper.VideoExists(id)) { if (YoutubeHelper.CanEmbed(id)) { var title = YoutubeHelper.GetTitle(id); var author = YoutubeHelper.GetAuthor(id); var channelImage = YoutubeHelper.GetChannelImage(id); var totalSeconds = YoutubeHelper.GetTotalTime(id); var totalTimeSpan = TimeSpan.FromSeconds(totalSeconds); var totalTime = string.Format("({0})", totalTimeSpan.ToString()); room.SendAddVideoToAll(videoInfo, title, totalTime, author, channelImage); room.SendChatMessageToAll(info.Name + " added " + title + " to the playlist."); if (room.CurrentPlayingVideo == null) { room.GotoNextVideo(); room.PlayVideo(); room.SendSetVideoToAll(room.CurrentPlayingVideo.VideoID, room.CurrentPlayingVideo.PlayState, (float)room.CurrentPlayingVideo.ElapsedSeconds); } } else { info.SendVideoMessage("Author of video doesn't allow embedding this video."); } } else { info.SendVideoMessage("Video does not exist on youtube."); } } else { info.SendVideoMessage("You need to join a room first."); } }
public override void HandlePacket(Dictionary <string, object> data, IWebSocketConnection socket, RemoteConnectionInfo info, Room room, ref List <IWebSocketConnection> allSockets) { if (room == null) { return; } if (!room.IsPrivileged(socket)) { return; } var state = (long)data["state"]; if (room.CurrentPlayingVideo == null) { info.SendVideoMessage("Could not edit state of video to " + state + " because the video doesn't exist."); return; } if ((int)room.CurrentPlayingVideo.PlayState != state) { string action = null; Console.WriteLine("[{0}] Elapsed Time Set: {1}", room.RoomName, data["elapsed"]); switch (state) { case 0: { action = "finished"; room.GotoNextVideo(); if (room.PlayVideo()) { room.SendSetVideoToAll(); } break; } case 1: { action = "started"; room.PlayVideo(); break; } case 2: { action = "paused"; room.PauseVideo(); break; } case 3: { action = "is buffering"; room.PauseVideo(); break; } case 5: { action = "stopped"; room.GotoNextVideo(); if (room.PlayVideo()) { room.SendSetVideoToAll(); } break; } } if (room.CurrentPlayingVideo != null) // CurrentPlayingVideo is null if playlist is empty. { // In the case that the elapsed seconds is an integer, the value will be parsed as a long. if (data["elapsed"] is long) { room.CurrentPlayingVideo.ElapsedSeconds = (long)data["elapsed"]; } else { room.CurrentPlayingVideo.ElapsedSeconds = (double)data["elapsed"]; } room.SendToAllExcept(socket, new Dictionary <string, object> { { "intent", "setVideoState" }, { "state", data["state"] }, { "elapsed", room.CurrentPlayingVideo.ElapsedSeconds }, }); //room.SendVideoMessageToAll(info.Name + " " + action + " the video."); } } }