Ejemplo n.º 1
0
        public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
        {
            return SendCommand(new WebSocketMessage<PlaystateRequest>
            {
                MessageType = "Playstate",
                Data = command

            }, cancellationToken);
        }
Ejemplo n.º 2
0
        public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
        {
            var socket = GetActiveSocket();

            return socket.SendAsync(new WebSocketMessage<PlaystateRequest>
            {
                MessageType = "Playstate",
                Data = command

            }, cancellationToken);
        }
Ejemplo n.º 3
0
        public Task SendPlaystateCommand(string controllingSessionId, string sessionId, PlaystateRequest command, CancellationToken cancellationToken)
        {
            var session = GetSession(sessionId);

            var controllingSession = GetSession(controllingSessionId);
            AssertCanControl(session, controllingSession);
            if (controllingSession.UserId.HasValue)
            {
                command.ControllingUserId = controllingSession.UserId.Value.ToString("N");
            }

            return session.SessionController.SendPlaystateCommand(command, cancellationToken);
        }
        public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
        {
            var args = new Dictionary<string, string>();

            if (command.Command == PlaystateCommand.Seek)
            {
                if (!command.SeekPositionTicks.HasValue)
                {
                    throw new ArgumentException("SeekPositionTicks cannot be null");
                }

                args["SeekPositionTicks"] = command.SeekPositionTicks.Value.ToString(CultureInfo.InvariantCulture);
            }

            return SendMessage(command.Command.ToString(), args, cancellationToken);
        }
Ejemplo n.º 5
0
        public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
        {
            switch (command.Command)
            {
                case PlaystateCommand.Stop:
                    Playlist.Clear();
                    return _device.SetStop();

                case PlaystateCommand.Pause:
                    return _device.SetPause();

                case PlaystateCommand.Unpause:
                    return _device.SetPlay();

                case PlaystateCommand.Seek:
                    {
                        return Seek(command.SeekPositionTicks ?? 0);
                    }

                case PlaystateCommand.NextTrack:
                    return SetPlaylistIndex(_currentPlaylistIndex + 1);

                case PlaystateCommand.PreviousTrack:
                    return SetPlaylistIndex(_currentPlaylistIndex - 1);
            }

            return Task.FromResult(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Sends the playstate command.
        /// </summary>
        /// <param name="sessionId">The session id.</param>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public Task SendPlaystateCommand(Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken)
        {
            var session = GetSessionForRemoteControl(sessionId);

            var tasks = GetControllers(session).Select(i => i.SendPlaystateCommand(session, command, cancellationToken));

            return Task.WhenAll(tasks);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sends the playstate command.
        /// </summary>
        /// <param name="sessionId">The session id.</param>
        /// <param name="command">The command.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public Task SendPlaystateCommand(Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken)
        {
            var session = GetSessionForRemoteControl(sessionId);

            if (command.Command == PlaystateCommand.Seek && !session.CanSeek)
            {
                throw new ArgumentException(string.Format("Session {0} is unable to seek.", session.Id));
            }

            return session.SessionController.SendPlaystateCommand(command, cancellationToken);
        }
        private async Task SendCommand(string commandString, long? seekAmount = null)
        {
            if (CanSendCommand())
            {
                var request = new PlaystateRequest
                {
                    Command = commandString.ToPlaystateCommandEnum()
                };

                if (seekAmount.HasValue)
                {
                    request.SeekPositionTicks = SelectedClient.NowPlayingPositionTicks + seekAmount.Value;
                }

                try
                {
                    SendingCommand = true;
                    await _apiClient.SendPlaystateCommandAsync(SelectedClient.Id, request);
                }
                catch (HttpException ex)
                {
                    Log.ErrorException("SendPlaystateCommand(" + commandString + ")", ex);
                }

                SendingCommand = false;
            }
        }
Ejemplo n.º 9
0
        public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
        {
            switch (command.Command)
            {
                case PlaystateCommand.Stop:
                    Playlist.Clear();
                    return _device.SetStop();

                case PlaystateCommand.Pause:
                    return _device.SetPause();

                case PlaystateCommand.Unpause:
                    return _device.SetPlay();

                case PlaystateCommand.Seek:
                    var playlistItem = Playlist.FirstOrDefault(p => p.PlayState == 1);
                    if (playlistItem != null && playlistItem.Transcode && playlistItem.IsVideo && _currentItem != null)
                    {
                        var newItem = CreatePlaylistItem(_currentItem, command.SeekPositionTicks ?? 0, GetServerAddress());
                        playlistItem.StartPositionTicks = newItem.StartPositionTicks;
                        playlistItem.StreamUrl = newItem.StreamUrl;
                        playlistItem.Didl = newItem.Didl;
                        return _device.SetAvTransport(playlistItem.StreamUrl, playlistItem.DlnaHeaders, playlistItem.Didl);

                    }
                    return _device.Seek(TimeSpan.FromTicks(command.SeekPositionTicks ?? 0));


                case PlaystateCommand.NextTrack:
                    _currentItem = null;
                    return SetNext();

                case PlaystateCommand.PreviousTrack:
                    _currentItem = null;
                    return SetPrevious();
            }

            return Task.FromResult(true);
        }
Ejemplo n.º 10
0
        private async Task SendCommand(string commandString, long? seekPosition = null)
        {
            if (CanSendCommand())
            {
                var request = new PlaystateRequest
                {
                    Command = commandString.ToPlaystateCommandEnum()
                };

                if (seekPosition.HasValue)
                {
                    request.SeekPositionTicks = seekPosition;
                }

                try
                {
                    SendingCommand = true;
                    await ApiClient.SendPlaystateCommandAsync(SelectedClient.Id, request);
                }
                catch (HttpException ex)
                {
                    Utils.HandleHttpException("SendPlaystateCommand(" + commandString + ")", ex, NavigationService, Log);
                }

                SendingCommand = false;
            }
        }
Ejemplo n.º 11
0
        public Task SendPlaystateCommand(Guid controllingSessionId, Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken)
        {
            var session = GetSessionForRemoteControl(sessionId);

            if (command.Command == PlaystateCommand.Seek && !session.CanSeek)
            {
                throw new ArgumentException(string.Format("Session {0} is unable to seek.", session.Id));
            }

            var controllingSession = GetSession(controllingSessionId);
            AssertCanControl(session, controllingSession);
            if (controllingSession.UserId.HasValue)
            {
                command.ControllingUserId = controllingSession.UserId.Value.ToString("N");
            }

            return session.SessionController.SendPlaystateCommand(command, cancellationToken);
        }