Exemplo n.º 1
0
        public cWebSocketServer()
        {
            FleckLog.Level = LogLevel.Debug;
            // var allSockets = new List<IWebSocketConnection>();
            allSockets = new List <IWebSocketConnection>();
            //var server = new WebSocketServer("ws://localhost:8181");
            server = new WebSocketServer("ws://localhost:8181");
            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    //Console.WriteLine("Open!");
                    allSockets.Add(socket);
                };
                socket.OnClose = () =>
                {
                    // Console.WriteLine("Close!");
                    allSockets.Remove(socket);
                };
                socket.OnMessage = message =>
                {
                    if (null != remoteEventStartStop)
                    {
                        remoteEventArgs e = new remoteEventArgs();
                        if (message.Contains("playSpotify"))
                        {
                            e.playPauseSpotify = true;
                        }
                        if (message.Contains("nextSpotify"))
                        {
                            e.nextSpotify = true;
                        }
                        if (message.Contains("pauseWorkout"))
                        {
                            e.pauseWorkout = true;
                        }
                        if (message.Contains("muteWorkout"))
                        {
                            e.muteWorkout = true;
                        }

                        remoteEventStartStop(this, e);
                    }

                    /*   var assembly = Assembly.GetExecutingAssembly();
                     * var resourceName = "CycleSoft.client.html";
                     * string[] result = assembly.GetManifestResourceNames();
                     *
                     * Stream stream = assembly.GetManifestResourceStream(resourceName);
                     * StreamReader reader = new StreamReader(stream);
                     *
                     * socket.Send(reader.ReadToEnd());
                     */
                    // return test;
                    //Console.WriteLine(message);
                    // allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
                };
            });
        }
Exemplo n.º 2
0
        public void remotePlayPauseEvent(object sender, remoteEventArgs e)
        {
            if (e.pauseWorkout)
            {
                this.Dispatcher.BeginInvoke((Action)(() =>
                {
                    playPause();
                }
                                                     ));
            }

            if (e.nextSpotify)
            {
                SpotifyClient.Value.Next();
            }

            if (e.playPauseSpotify)
            {
                SpotifyClient.Value.PlayPause();
            }
        }