Exemplo n.º 1
0
        internal void HandleMessage(object msg)
        {
            if (msg is LcdsServiceProxyResponse)
            {
                msg = LcdsServiceObject.GetObject((LcdsServiceProxyResponse)msg);
            }

            var block = blocks.FirstOrDefault(b => b.Matches(msg));

            if (block != null)
            {
                blocks.Remove(block);
                block.Supply(msg);
                return;
            }

            RtmpLogAsync(msg);

            if (msg is SimpleDialogMessage)
            {
                Log("Simple dialog message: ");
                Log("  " + JSON.Stringify(JSONSerializer.Serialize(msg), 2, 2));
            }

            var args = new HandledEventArgs <object>(msg);

            InternalMessageReceived?.Invoke(this, args);
            if (args.Handled)
            {
                return;
            }

            Log("Unhandled message: " + msg.GetType());
        }
Exemplo n.º 2
0
        private async Task DataReceiver()
        {
            try
            {
                while (true)
                {
                    if (_Token.IsCancellationRequested)
                    {
                        break;
                    }
                    MessageReceivedEventArgs msg = await MessageReadAsync();

                    if (msg != null)
                    {
                        if (EnableStatistics)
                        {
                            _Stats.IncrementReceivedMessages();
                            _Stats.AddReceivedBytes(msg.Data.Length);
                        }

                        Task internal_unawaited = Task.Run(() => InternalMessageReceived?.Invoke(this, msg), _Token);
                        if (msg.MessageType != WebSocketMessageType.Close)
                        {
                            Task unawaited = Task.Run(() => MessageReceived?.Invoke(this, msg), _Token);
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Logger?.Invoke(_Header + "data receiver canceled");
            }
            catch (WebSocketException)
            {
                Logger?.Invoke(_Header + "websocket disconnected");
            }
            catch (Exception e)
            {
                Logger?.Invoke(_Header + "exception: " + Environment.NewLine + e.ToString());
            }

            ServerDisconnected?.Invoke(this, EventArgs.Empty);
            InternalServerDisconnected?.Invoke(this, EventArgs.Empty);
        }