示例#1
0
        protected override void InitConnection()
        {
            SetStatus(DisplayStatus.Connecting);
            ServerDiscoverer discoverer = new ServerDiscoverer();
            IpAddress        address    = null;

            do
            {
                address = discoverer.discover();
            } while (address == null && Status != DisplayStatus.Closing);
            if (Status != DisplayStatus.Closing)
            {
                websocket = new WebsocketClient(new Uri($"ws://{address}"));
                websocket.IsReconnectionEnabled = true;
                websocket.ReconnectionHappened.Subscribe(info => {
                    ExternalEventArgs args = new ExternalEventArgs();
                    args.Action            = ExternalAction.ConnectionChanged;
                    args.Command           = DisplayStatus.Connected;
                    EventReceived(args);
                    Console.WriteLine($"Reconnection happened, type: {info.Type}");
                });
                websocket.ReconnectTimeout = null;
                websocket.DisconnectionHappened.Subscribe(info => {
                    ExternalEventArgs args = new ExternalEventArgs();
                    args.Action            = ExternalAction.ConnectionChanged;
                    args.Command           = DisplayStatus.Connecting;
                    EventReceived(args);
                    Console.WriteLine($"Disconnect happened, type: {info.Type}");
                });
                websocket.MessageReceived.Subscribe(msg => MessageReceived(msg.Text));
                websocket.StartOrFail().Wait();
                SetStatus(DisplayStatus.Connected);
            }
        }
示例#2
0
        protected void SetStatus(DisplayStatus status)
        {
            this.status = status;
            ExternalEventArgs args = new ExternalEventArgs();

            args.Action  = ExternalAction.ConnectionChanged;
            args.Command = status;
            EventReceived(args);
        }
示例#3
0
        private void ExternalDisplay_EventReceived(object sender, ExternalEventArgs e)
        {
            if (e.Action == ExternalAction.Click)
            {
                KeyCode?key;
                switch (e.Command)
                {
                case "key_next":
                    key = KeyCode.MEDIA_NEXT_TRACK;
                    break;

                case "key_play_pause":
                    key = KeyCode.MEDIA_PLAY_PAUSE;
                    break;

                case "key_previous":
                    key = KeyCode.MEDIA_PREV_TRACK;
                    break;

                case "key_stop":
                    key = KeyCode.MEDIA_STOP;
                    break;

                case "key_volume_down":
                    key = KeyCode.VOLUME_DOWN;
                    break;

                case "key_volume_up":
                    key = KeyCode.VOLUME_UP;
                    break;

                default:
                    key = null;
                    break;
                }
                if (key != null)
                {
                    SendKeyPress(key.Value);
                }
            }
            else
            {
                StateChangedArgs args = new StateChangedArgs();
                if (e.Action == ExternalAction.Brightness)
                {
                    displayBrightness = Convert.ToInt32(e.Command);
                    args.Brightness   = displayBrightness;
                }
                else if (e.Action == ExternalAction.ConnectionChanged)
                {
                    args.DisplayStatus = (DisplayStatus)e.Command;
                }
                listeners?.BeginInvoke(args, (ar) => { }, null);
            }
        }
示例#4
0
        protected virtual void EventReceived(ExternalEventArgs e)
        {
            EventHandler <ExternalEventArgs> handler = OnEventReceived;

            handler?.Invoke(this, e);
        }