Пример #1
0
        public async Task ResumeVideo(string uid, float seekSeconds)
        {
            RoomState roomState = RoomManager.GetRoom(ContextRoomId);

            if (roomState != null && !string.IsNullOrEmpty(uid))
            {
                PlaylistItem item = roomState.Playlist.FirstOrDefault(el => el.Uid == uid);
                if (item != null)
                {
                    item.StartTime = seekSeconds;
                    item.IsPlaying = true;
                    item.ResetStartTimeTracking();
                    await UpdateAllRoomState();
                }
            }
        }
Пример #2
0
        public async Task SendChatMessage(string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            if (message.Length > MAX_CHAT_CHARACTERS)
            {
                message  = message.Substring(0, MAX_CHAT_CHARACTERS);
                message += "...";
            }

            //check if youtube link
            string videoId = YoutubeUtil.ExtractVideoId(message);

            if (!string.IsNullOrWhiteSpace(videoId))
            {
                PlaylistItem videoData = await YoutubeUtil.GetYoutubeVideoDetails(CONFIGURATION["youtube_api_key"], videoId);

                if (videoData != null)
                {
                    RoomState roomState = RoomManager.GetRoom(ContextRoomId);
                    if (roomState != null)
                    {
                        videoData.StartTime = YoutubeUtil.ExtractTimeStamp(message);
                        roomState.Playlist.Add(videoData);
                        if (roomState.Playlist.Count == 1)
                        {
                            //first video
                            videoData.IsPlaying = true;
                            videoData.ResetStartTimeTracking();
                        }
                        await UpdateAllRoomState();

                        await Clients.Group(ContextRoomId).PlaylistItemMessageReceived(ContextUserData, "added", videoData);
                    }
                    return;
                }
            }

            await Clients.Group(ContextRoomId).ChatMessageReceived(ContextUserData, message);
        }