Exemplo n.º 1
0
        private CallbackDelegate GetStateResponse(IDictionary <string, object> args, CallbackDelegate callback)
        {
            bool.TryParse(args.FirstOrDefault(arg => arg.Key == "paused").Value?.ToString(), out var paused);
            float.TryParse(args.FirstOrDefault(arg => arg.Key == "currentTime").Value?.ToString(), out var currentTime);
            float.TryParse(args.FirstOrDefault(arg => arg.Key == "duration").Value?.ToString(), out var duration);
            bool.TryParse(args.FirstOrDefault(arg => arg.Key == "ended").Value?.ToString(), out var ended);
            var currentSource = args.FirstOrDefault(arg => arg.Key == "currentSource").Value?.ToString();

            var screenName = args.FirstOrDefault(arg => arg.Key == "screenName").Value?.ToString();

            if (string.IsNullOrEmpty(screenName))
            {
                Debug.WriteLine("error: received state response without valid screenName.");
                return(callback);
            }

            var state = new DuiState
            {
                CurrentTime   = currentTime,
                ScreenName    = screenName,
                Ended         = ended,
                IsPaused      = paused,
                Duration      = duration,
                CurrentSource = currentSource
            };

            StateQueue.Enqueue(state);
            return(callback);
        }
        private CallbackDelegate GetStateResponse(IDictionary <string, object> args, CallbackDelegate callback)
        {
            var screenName = ArgsReader.GetArgKeyValue <string>(args, "screenName");

            if (string.IsNullOrEmpty(screenName))
            {
                Debug.WriteLine("Warning: received state response without valid screenName.");
                callback("");
                return(callback);
            }

            var paused        = ArgsReader.GetArgKeyValue <bool>(args, "paused");
            var repeat        = ArgsReader.GetArgKeyValue <bool>(args, "repeat");
            var currentTime   = ArgsReader.GetArgKeyValue <float>(args, "currentTime");
            var duration      = ArgsReader.GetArgKeyValue <float>(args, "duration");
            var ended         = ArgsReader.GetArgKeyValue <bool>(args, "ended");
            var currentSource = ArgsReader.GetArgKeyValue <string>(args, "currentSource");

            var state = new DuiState
            {
                CurrentTime   = currentTime,
                ScreenName    = screenName,
                Ended         = ended,
                IsPaused      = paused,
                Duration      = duration,
                CurrentSource = currentSource,
                Repeat        = repeat
            };

            StateQueue.Enqueue(state);

            callback("OK");
            return(callback);
        }
Exemplo n.º 3
0
        public void Add(string key, DuiState duiState)
        {
            // whitespace removal from key is necessary
            // otherwise screen names "screen test" and "screen test1" would be considered equal.
            key = string.Concat(key.Where(c => !char.IsWhiteSpace(c)));

            this._state.AddOrUpdate(key, duiState, (k, _) => duiState);
        }
Exemplo n.º 4
0
        private CallbackDelegate OnStateTick(IDictionary <string, object> args, CallbackDelegate callback)
        {
            if (!bool.TryParse(
                    args.FirstOrDefault(arg => arg.Key == "paused").Value?.ToString(),
                    out var paused))
            {
                return(callback);
            }

            if (!float.TryParse(
                    args.FirstOrDefault(arg => arg.Key == "currentTime").Value?.ToString(),
                    out var currentTime))
            {
                return(callback);
            }

            if (!float.TryParse(
                    args.FirstOrDefault(arg => arg.Key == "duration").Value?.ToString(),
                    out var duration))
            {
                return(callback);
            }

            var currentSource = args.FirstOrDefault(arg => arg.Key == "currentSource").Value?.ToString();

            if (string.IsNullOrEmpty(currentSource))
            {
                return(callback);
            }

            if (!bool.TryParse(
                    args.FirstOrDefault(arg => arg.Key == "ended").Value?.ToString(),
                    out var ended))
            {
                return(callback);
            }

            var screenName = args.FirstOrDefault(arg => arg.Key == "screenName").Value?.ToString();

            if (string.IsNullOrEmpty(screenName))
            {
                Debug.WriteLine("warning: received empty screenName on state tick");
                return(callback);
            }
            var duiState = new DuiState
            {
                CurrentTime   = currentTime,
                ScreenName    = screenName,
                Ended         = ended,
                IsPaused      = paused,
                CurrentSource = currentSource,
                Duration      = duration
            };

            TriggerServerEvent(ServerEvents.OnStateTick, JsonConvert.SerializeObject(duiState));

            return(callback);
        }
Exemplo n.º 5
0
        public void Update(string key, DuiState duiState)
        {
            // whitespace removal from key is necessary
            // otherwise screen names "screen test" and "screen test1" would be considered equal.
            key = string.Concat(key.Where(c => !char.IsWhiteSpace(c)));

            var oldState = this.Get(key);

            if (oldState == null)
            {
                return;
            }

            this._state.TryUpdate(key, duiState, oldState);
        }
Exemplo n.º 6
0
        public async Task SynchronizeState(DuiState state)
        {
            var player = this.videoPlayers?.FirstOrDefault(s => s.PlayerName == state.ScreenName);

            if (player != null)
            {
                // no need to synchronize. player already exists.
                return;
            }

            player = await this.CreateVideoPlayer(state.Screen);

            player?.SynchronizeState(state.IsPaused, state.CurrentTime, state.CurrentSource, state.Repeat);

            this.videoPlayers?.Add(player);
        }
Exemplo n.º 7
0
        public async Task SynchronizeState(DuiState state, Shared.Models.Screen screen)
        {
            var player = this.VideoPlayers?.FirstOrDefault(p => p.ScreenName == screen.Name);

            if (player != null)
            {
                // Player exists. No need to synchronize.
                return;
            }

            player = await this.CreateVideoPlayerAsync(screen);

            if (player == null)
            {
                // Failed to create player.
                // TODO: Needs improvement.
                Debug.WriteLine("Failed to create player");
                return;
            }

            Debug.WriteLine("Synchronizing..");
            player.SynchronizeState(state.IsPaused, state.CurrentTime, state.CurrentSource);
            this.VideoPlayers.Add(player);
        }
Exemplo n.º 8
0
        public void OnPlay(Screen screen, string url)
        {
            var duiState = new DuiState(screen, url);

            this._state.Add(screen.Name, duiState);
        }