private void configure()
        {
            #if DEBUG
              _ws.Log.Level = LogLevel.TRACE;
              #endif
              _ws.OnOpen += (sender, e) =>
              {
            var msg = createTextMessage("connection", String.Empty);
            _ws.Send(msg);
              };

              _ws.OnMessage += (sender, e) =>
              {
            switch (e.Type)
            {
              case Opcode.TEXT:
            var msg = parseTextMessage(e.Data);
            _msgQ.Enqueue(msg);
            break;
              case Opcode.BINARY:
            var audioMsg = parseAudioMessage(e.RawData);
            if (audioMsg.user_id == _user_id) goto default;
            if (_audioBox.ContainsKey(audioMsg.user_id))
            {
              _audioBox[audioMsg.user_id].Enqueue(audioMsg.buffer_array);
            }
            else
            {
              var q = Queue.Synchronized(new Queue());
              q.Enqueue(audioMsg.buffer_array);
              _audioBox.Add(audioMsg.user_id, q);
            }
            break;
              default:
            break;
            }
              };

              _ws.OnError += (sender, e) =>
              {
            enNfMessage("[AudioStreamer] error", "WS: Error: " + e.Message, "notification-message-im");
              };

              _ws.OnClose += (sender, e) =>
              {
            enNfMessage
            (
              "[AudioStreamer] disconnect",
              String.Format("WS: Close({0}: {1})", e.Code, e.Reason),
              "notification-message-im"
            );
              };

              //_ws.Compression = CompressionMethod.DEFLATE;

              _notifyMsgState = new ThreadState();
              _notifyMsg = (state) =>
              {
            while (_notifyMsgState.Enabled || _msgQ.Count > 0)
            {
              Thread.Sleep(500);

              if (_msgQ.Count > 0)
              {
            NfMessage msg = (NfMessage)_msgQ.Dequeue();
            #if NOTIFY
            Notification nf = new Notification(msg.Summary,
                                               msg.Body,
                                               msg.Icon);
            nf.AddHint("append", "allowed");
            nf.Show();
            #else
            Console.WriteLine("{0}: {1}", msg.Summary, msg.Body);
            #endif
              }
            }

            _notifyMsgState.Notification.Set();
              };

              _sendHeartbeat = (state) =>
              {
            var msg = createTextMessage("heartbeat", String.Empty);
            _ws.Send(msg);
              };
        }
Beispiel #2
0
        private void configure()
        {
            _ws.OnOpen += (sender, e) =>
            {
                var msg = createTextMessage("connection", String.Empty);
                _ws.Send(msg);
            };

            _ws.OnMessage += (sender, e) =>
            {
                switch (e.Type)
                {
                case Opcode.TEXT:
                    var msg = parseTextMessage(e.Data);
                    _msgQ.Enqueue(msg);
                    break;

                case Opcode.BINARY:
                    var audioMsg = parseAudioMessage(e.RawData);
                    if (audioMsg.user_id == _user_id)
                    {
                        goto default;
                    }
                    if (_audioBox.ContainsKey(audioMsg.user_id))
                    {
                        _audioBox[audioMsg.user_id].Enqueue(audioMsg.buffer_array);
                    }
                    else
                    {
                        var q = Queue.Synchronized(new Queue());
                        q.Enqueue(audioMsg.buffer_array);
                        _audioBox.Add(audioMsg.user_id, q);
                    }
                    break;

                default:
                    break;
                }
            };

            _ws.OnError += (sender, e) =>
            {
                enNfMessage("[AudioStreamer] error", "WS: Error: " + e.Message, "notification-message-im");
            };

            _ws.OnClose += (sender, e) =>
            {
                enNfMessage
                (
                    "[AudioStreamer] disconnect",
                    String.Format("WS: Close({0}: {1})", e.Code, e.Reason),
                    "notification-message-im"
                );
            };

            _notifyMsgState = new ThreadState();
            _notifyMsg      = (state) =>
            {
                while (_notifyMsgState.Enabled || _msgQ.Count > 0)
                {
                    Thread.Sleep(500);

                    if (_msgQ.Count > 0)
                    {
                        NfMessage msg = (NfMessage)_msgQ.Dequeue();
            #if NOTIFY
                        Notification nf = new Notification(msg.Summary,
                                                           msg.Body,
                                                           msg.Icon);
                        nf.AddHint("append", "allowed");
                        nf.Show();
            #else
                        Console.WriteLine("{0}: {1}", msg.Summary, msg.Body);
            #endif
                    }
                }

                _notifyMsgState.Notification.Set();
            };

            _sendHeartbeat = (state) =>
            {
                var msg = createTextMessage("heartbeat", String.Empty);
                _ws.Send(msg);
            };
        }