Пример #1
0
        public void SendAndSetPrivileged(bool privileged)
        {
            var room = GetRoom();

            if (room != null)
            {
                if (privileged)
                {
                    room.AddPrivilegedUser(Socket);
                }
                else
                {
                    room.RemovePrivilegedUser(Socket);
                }

                Helper.SendQuick(Socket, new Dictionary <string, object>
                {
                    { "intent", "updatePrivileged" },
                    { "privileged", privileged },
                });

                SendChatMessage(privileged
                                                        ? "You are now a privileged user."
                                                        : "You are no longer a privileged user.", Helper.ServerRoomColor);
            }
        }
Пример #2
0
        public void SendPublicRooms()
        {
            if (publicRoomsCache == null || RoomManager.Rooms.Values.Count <= Globals.MaxAllowedRoomsBeforeCache || (DateTime.Now - lastPublicRoomRequestTime).TotalMinutes >= Globals.PublicRoomsCacheExpireTime)
            {
                var rooms = new List <object[]>();

                foreach (var room2 in RoomManager.Rooms.Values)
                {
                    rooms.Add(new object[] { room2.RoomName, room2.Sockets.Count });
                }

                publicRoomsCache          = rooms;
                lastPublicRoomRequestTime = DateTime.Now;

                Helper.SendQuick(Socket, new Dictionary <string, object>
                {
                    { "intent", "getPublicRooms" },
                    { "rooms", rooms },
                });
            }
            else
            {
                Helper.SendQuick(Socket, new Dictionary <string, object>
                {
                    { "intent", "getPublicRooms" },
                    { "rooms", publicRoomsCache },
                });
                Console.WriteLine("Rooms cache up to date");
            }
        }
Пример #3
0
 public void SendVideoMessage(string message)
 {
     Helper.SendQuick(Socket, new Dictionary <string, object>
     {
         { "intent", "videoMessage" },
         { "message", message },
     });
 }
Пример #4
0
 public void SendSetOwner(bool isOwner = true)
 {
     Helper.SendQuick(Socket, new Dictionary <string, object>
     {
         { "intent", "updateOwnership" },
         { "owner", isOwner },
     });
 }
Пример #5
0
        public void SendRemoveUser(IWebSocketConnection user)
        {
            var info = user.GetInfo();

            Helper.SendQuick(Socket, new Dictionary <string, object>
            {
                { "intent", "removeUser" },
                { "id", info.ID },
            });
        }
Пример #6
0
        public void SendDisconnect(string message, string color = "#FFF")
        {
            Helper.SendQuick(Socket, new Dictionary <string, object>
            {
                { "intent", "disconnect" },
                { "message", message },
                { "color", color }
            });

            Socket.Close();
        }
Пример #7
0
        public void SendSetName(string name, bool print, bool permanent)
        {
            Helper.SendQuick(Socket, new Dictionary <string, object>
            {
                { "intent", "newName" },
                { "newName", name },
                { "permanent", permanent },
            });

            Name = name;
        }
Пример #8
0
        public string SendChatMessage(string message, string color = Helper.ServerMessageColor, string name = null, string nameColor = null)
        {
            var jsonStr = Helper.SendQuick(Socket, new Dictionary <string, object>
            {
                { "intent", "chat" },
                { "message", message },
                { "color", color },
                { "name", name },
                { "nameColor", nameColor },
            });

            return(jsonStr);
        }
Пример #9
0
        public void SendSyncRoom(IWebSocketConnection socket)
        {
            if (CurrentPlayingVideo == null)
            {
                return;
            }

            Helper.SendQuick(socket, new Dictionary <string, object>
            {
                { "intent", "syncVideo" },
                { "state", (int)CurrentPlayingVideo.PlayState },
                { "elapsed", CurrentPlayingVideo.ElapsedSeconds },
            });
        }
Пример #10
0
        public void SendAddVideo(VideoInfo videoInfo, string title, string totalTime, string author, string channelImageUrl)
        {
            var info = Socket.GetInfo();

            Helper.SendQuick(Socket, new Dictionary <string, object>
            {
                { "intent", "addVideo" },
                { "uniqueId", videoInfo.ID },
                { "videoId", videoInfo.VideoID },
                { "title", title },
                { "length", totalTime },
                { "author", author },
                { "channelImage", channelImageUrl },
            });
        }
Пример #11
0
        public void AddSocket(IWebSocketConnection socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (Sockets.Contains(socket))
            {
                return;
            }

            socket.GetInfo().RoomName = RoomName;

            Sockets.Add(socket);

            Helper.SendQuick(socket, new Dictionary <string, object>
            {
                { "intent", "newRoom" },
                { "message", "Changed room to " + RoomName + "." },
                { "color", Helper.ServerMessageColor },
                { "history", ChatHistory },
                { "owner", socket == Owner },
                { "roomName", RoomName },
                {
                    "users", Sockets.Select(s =>
                    {
                        var info = s.GetInfo();
                        return(new object[] { info.ID, info.Name });
                    }).ToArray()
                },
            });

            SendUserToAll(socket);

            if (CurrentPlayingVideo != null)
            {
                socket.GetInfo().SendSetVideo(CurrentVideo, CurrentPlayingVideo.PlayState, CurrentPlayingVideo.ElapsedSeconds);
            }

            socket.GetInfo().SendRoomPlaylist();

            SendChatMessageToAll(socket.GetInfo().Name + " joined the room. (" + RoomName + ")");
        }
Пример #12
0
        public void SendSetVideo(VideoInfo videoInfo, PlayState state, double elapsed = 0)
        {
            var info = Socket.GetInfo();

            string   videoName     = YoutubeHelper.GetTitle(videoInfo.VideoID);
            TimeSpan videoDuration = YoutubeHelper.GetDuration(videoInfo.VideoID);

            var title       = YoutubeHelper.GetTitle(videoInfo.VideoID);
            var description = YoutubeHelper.GetDescription(videoInfo.VideoID);

            Helper.SendQuick(Socket, new Dictionary <string, object>
            {
                { "intent", "setVideo" },
                { "uniqueId", videoInfo.ID },
                { "videoId", videoInfo.VideoID },
                { "videoName", videoName },
                { "title", title },
                { "description", description },
                { "duration", (int)videoDuration.TotalSeconds },
                { "elapsed", elapsed },
                { "state", (int)state },
            });
        }