/// <summary>
        /// Sends a ir command.
        /// </summary>
        /// <returns>Send ir command task.</returns>
        /// <param name="state">State ir to send.</param>
        public async Task SendIRCommandStateAsync(IRCommandState state)
        {
            var msg = new JsonBaseMessage {
                msgid = next_msg_id, request = "SendKey", @params = new { button_id = $"{state.cmd}", device_id = state.stump_device }
            };

            await _transport.SendAsync(msg);
        }
Пример #2
0
        /// <summary>
        /// Initiate a Gamestream session with the host.
        /// </summary>
        /// <param name="configuration">Desired gamestream configuration</param>
        /// <returns>Task returning the GamestreamSession object</returns>
        /// <exception cref="System.TimeoutException">
        /// When console does not respond in time
        /// </exception>
        /// <exception cref="SmartGlass.Channels.Broadcast.GamestreamException">
        /// On unexpected GamestreamSession
        /// </exception>
        public async Task <GamestreamSession> StartGamestreamAsync(GamestreamConfiguration configuration)
        {
            var startMessage = new GamestreamStartMessage()
            {
                Configuration        = configuration,
                ReQueryPreviewStatus = false
            };

            var startedMessageTask = MessageExtensions.WaitForMessageAsync <GamestreamStateStartedMessage, BroadcastErrorMessage, BroadcastBaseMessage>(
                _transport,
                TimeSpan.FromSeconds(10),
                async() => await _transport.SendAsync(startMessage));

            var initializingMessageTask = MessageExtensions.WaitForMessageAsync
                                          <GamestreamStateInitializingMessage, BroadcastErrorMessage, BroadcastBaseMessage>(_transport, TimeSpan.FromSeconds(10));

            await Task.WhenAll(initializingMessageTask, startedMessageTask);

            var initializingMessage = initializingMessageTask.Result;
            var startedMessage      = startedMessageTask.Result;

            if (initializingMessage.SessionId != startedMessage.SessionId)
            {
                throw new GamestreamException("Invalid session received.", GamestreamError.General);
            }

            return(new GamestreamSession(initializingMessage.TcpPort, initializingMessage.UdpPort, configuration, initializingMessage.SessionId));
        }