示例#1
0
        private async Task <CallbackDelegate> OnRequestState(IDictionary <string, object> args, CallbackDelegate callback)
        {
            var screenStates = new List <DuiState>();

            foreach (var player in this.playerPool.VideoPlayers)
            {
                player.Browser.GetState();
                var state = await BrowserStateHelperScript.GetLastState();

                if (state == null)
                {
                    Debug.WriteLine($"received empty dui-state for screen: {player.ScreenName}");
                    continue;
                }

                screenStates.Add(state);
            }

            API.SendNuiMessage(
                JsonConvert.SerializeObject(
                    new { type = "HypnonemaNUI.UpdateStatuses", screenStates },
                    new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));

            callback("OK");
            return(callback);
        }
示例#2
0
        private async Task OnStateTick()
        {
            if (!this.isInitialized || this.playerPool?.VideoPlayers?.Count == 0)
            {
                return;
            }

            var stateList    = new List <DuiState>();
            var videoPlayers = this.playerPool?.VideoPlayers;

            if (videoPlayers != null)
            {
                foreach (var player in videoPlayers)
                {
                    player.Browser.GetState();
                    var duiState = await BrowserStateHelperScript.GetLastState();

                    if (duiState == null)
                    {
                        continue;
                    }

                    stateList.Add(duiState);
                }

                TriggerServerEvent(ServerEvents.OnStateTick, JsonConvert.SerializeObject(stateList));
            }
        }
示例#3
0
        private async Task EditedScreen(string jsonString)
        {
            var screen = JsonConvert.DeserializeObject <Screen>(jsonString);

            API.SendNuiMessage(
                JsonConvert.SerializeObject(
                    new { type = "HypnonemaNUI.EditedScreen", screen },
                    new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));

            var player = this.playerPool.VideoPlayers.FirstOrDefault(s => s.ScreenName == screen.Name);

            if (player != null)
            {
                // we want the current state of the dui browser,
                // so we send a request and wait as long as duiStateResponse is null but max. 5500 ms
                player.Browser.SendMessage(new { type = "getState" });
                var state = await BrowserStateHelperScript.GetLastState();

                this.playerPool.CloseScreen(player.ScreenName);
                player = await this.playerPool.CreateVideoPlayerAsync(screen);

                // stateResponse can be null ( eg. if waiting time exceeded 5500ms)
                if (state != null)
                {
                    await Delay(500);

                    player.Browser.SendMessage(
                        new
                    {
                        type        = "update",
                        src         = state.CurrentSource,
                        currentTime = state.CurrentTime,
                        paused      = state.IsPaused
                    });
                }

                this.playerPool.VideoPlayers.Add(player);
            }
        }