Example #1
0
        public async Task <GamestreamSession> StartGamestreamAsync()
        {
            var startMessage = new GamestreamStartMessage()
            {
                Configuration        = GamestreamConfiguration.GetStandardConfig(),
                ReQueryPreviewStatus = false
            };

            var startedMessageTask = MessageExtensions.WaitForMessageAsync <GamestreamStateStartedMessage, BroadcastErrorMessage, BroadcastBaseMessage>(
                _transport,
                TimeSpan.FromSeconds(2),
                () => _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));
        }
        /// <summary>
        /// get a ir commands
        /// </summary>
        /// <returns>Array of ir commands can be issued task.</returns>
        public async Task <IEnumerable <IRDevice> > GetIRCommandsAsync()
        {
            var message = new JsonBaseMessage {
                msgid = next_msg_id, request = "GetConfiguration"
            };

            var receive_task = MessageExtensions.WaitForMessageAsync <JsonBaseMessage, JsonBaseMessage>(
                _transport,
                TimeSpan.FromSeconds(10),
                () => _transport.SendAsync(message),
                (to_filter) => to_filter.msgid == message.msgid
                );

            var res = await receive_task;

            if (res.@params is JArray ja)
            {
                return(ja.ToObject <IRDevice[]>());
            }
            return(null);
        }