Ejemplo n.º 1
0
 void OnEventReceived(EventReceivedEventArgs e)
 {
     if (EventReceived != null)
     {
         EventReceived(this, e);
     }
 }
Ejemplo n.º 2
0
        private void OnEventReceived(EventReceivedEventArgs e)
        {
            // ISSUE: reference to a compiler-generated field
            EventHandler <EventReceivedEventArgs> eventReceived = this.EventReceived;

            if (eventReceived == null)
            {
                return;
            }
            EventReceivedEventArgs e1 = e;

            eventReceived((object)this, e1);
        }
Ejemplo n.º 3
0
        void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            switch (e.Event.MessageType)
            {
            case MessageType.UserControlMessage:
                var m = (UserControlMessage)e.Event;
                if (m.EventType == UserControlMessageType.PingRequest)
                {
                    Console.WriteLine("Client Ping Request");
                    WriteProtocolControlMessage(new UserControlMessage(UserControlMessageType.PingResponse, m.Values));
                }
                else if (m.EventType == UserControlMessageType.SetBufferLength)
                {
                    Console.WriteLine("Set Buffer Length");
                    // TODO
                }
                else if (m.EventType == UserControlMessageType.PingResponse)
                {
                    Console.WriteLine("Ping Response");
                    var message = m as UserControlMessage;
                    callbackManager.SetResult(message.Values[0], null);
                }
                break;

            case MessageType.DataAmf3:
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                break;

            case MessageType.CommandAmf3:
            case MessageType.DataAmf0:
            case MessageType.CommandAmf0:
                var command = (Command)e.Event;
                var call    = command.MethodCall;
                var param   = call.Parameters.Length == 1 ? call.Parameters[0] : call.Parameters;
                switch (call.Name)
                {
                case "connect":
                    Console.WriteLine("Connect");
                    StreamId = server.RequestStreamId();
                    HandleConnectInvokeAsync(command);
                    HasConnected = true;
                    break;

                case "_result":
                    // unwrap Flex class, if present
                    var ack = param as AcknowledgeMessage;
                    callbackManager.SetResult(command.InvokeId, ack != null ? ack.Body : param);
                    break;

                case "_error":
                    // unwrap Flex class, if present
                    var error = param as ErrorMessage;
                    callbackManager.SetException(command.InvokeId, error != null ? new InvocationException(error) : new InvocationException());
                    break;

                case "receiveAudio":
                    // TODO
                    break;

                case "releaseStream":
                    Console.WriteLine("ReleaseStream");
                    // TODO
                    break;

                case "publish":
                    Console.WriteLine("publish");
                    HandlePublish(command);
                    break;

                case "unpublish":
                    HandleUnpublish(command);
                    break;

                case "FCpublish":
                case "FCPublish":
                    Console.WriteLine("FCPublish");
                    // TODO
                    break;

                case "FCUnpublish":
                case "FCunPublish":
                    Console.WriteLine("FCUnpublish");
                    HandleUnpublish(command);
                    break;

                case "createStream":
                    SetResultValInvoke(StreamId, command.InvokeId);
                    Console.WriteLine("create stream");
                    // TODO
                    break;

                case "play":
                    Console.WriteLine("play");
                    // TODO
                    HandlePlay(command);
                    break;

                case "deleteStream":
                    Console.WriteLine("deleteStream");
                    // TODO
                    break;

                case "@setDataFrame":
                    Console.WriteLine("SetDataFrame");
                    SetDataFrame(command);
                    // TODO
                    break;

                default:
#if DEBUG
                    System.Diagnostics.Debug.Print($"unknown rtmp command: {call.Name}");
                    System.Diagnostics.Debugger.Break();
#endif
                    break;
                }
                break;

            case MessageType.WindowAcknowledgementSize:
                var msg = (WindowAcknowledgementSize)e.Event;
                break;

            case MessageType.Video:
                var video_data = e.Event as VideoData;
                if (is_not_set_video_config && video_data.Data.Length >= 2 && video_data.Data[1] == 0)
                {
                    is_not_set_video_config = false;
                    AvCConfigureRecord      = video_data;
                }
                if (ChannelDataReceived != null)
                {
                    ChannelDataReceived(this, new ChannelDataReceivedEventArgs(ChannelType.Video, e.Event));
                }
                break;

            case MessageType.Audio:
                var audio_data = e.Event as AudioData;
                if (is_not_set_auido_config && audio_data.Data.Length >= 2 && audio_data.Data[1] == 0)
                {
                    is_not_set_auido_config = false;
                    AACConfigureRecord      = audio_data;
                }
                if (ChannelDataReceived != null)
                {
                    ChannelDataReceived(this, new ChannelDataReceivedEventArgs(ChannelType.Audio, e.Event));
                }
                break;

            case MessageType.Acknowledgement:
                break;

            default:
                Console.WriteLine(string.Format("Unknown message type {0}", e.Event.MessageType));
                break;
            }
        }
Ejemplo n.º 4
0
 void OnEventReceived(EventReceivedEventArgs e)
 {
     if (EventReceived != null)
         EventReceived(this, e);
 }
Ejemplo n.º 5
0
        async void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            if (e.Event == null)
            {
                return;
            }
            switch (e.Event.MessageType)
            {
            case MessageType.UserControlMessage:
                var m = (UserControlMessage)e.Event;
                if (m.EventType == UserControlMessageType.PingRequest)
                {
                    WriteProtocolControlMessage(new UserControlMessage(UserControlMessageType.PingResponse, m.Values));
                }
                break;

            case MessageType.DataAmf3:
#if DEBUG
                // Have no idea what the contents of these packets are.
                // Study these packets if we receive them.
                System.Diagnostics.Debugger.Break();
#endif
                break;

            case MessageType.CommandAmf3:
            case MessageType.DataAmf0:
            case MessageType.CommandAmf0:
                var command = (Command)e.Event;
                var call    = command.MethodCall;

                var param = call.Parameters.Length == 1 ? call.Parameters[0] : call.Parameters;
                if (call.Name == "_result")
                {
                    // unwrap Flex class, if present
                    var ack = param as AcknowledgeMessageExt;
                    callbackManager.SetResult(command.InvokeId, ack != null ? ack.Body : param);
                }
                else if (call.Name == "_error")
                {
                    // unwrap Flex class, if present
                    var error = param as ErrorMessage;
                    callbackManager.SetException(command.InvokeId, error != null ? new InvocationException(error) : new InvocationException());
                }
                else if (call.Name == "receive")
                {
                    var message = param as AsyncMessageExt;
                    if (message == null)
                    {
                        break;
                    }

                    object subtopicObject;
                    message.Headers.TryGetValue(AsyncMessageHeaders.Subtopic, out subtopicObject);

                    var dsSubtopic = subtopicObject as string;
                    var clientId   = message.ClientId;
                    var body       = message.Body;

                    WrapCallback(() =>
                    {
                        if (MessageReceived != null)
                        {
                            MessageReceived(this, new MessageReceivedEventArgs(clientId, dsSubtopic, body));
                        }
                    });
                }
                else if (call.Name == "onstatus")
                {
                    System.Diagnostics.Debug.Print("Received status.");
                }
                else if (call.Name == "connect")
                {
                    await ConnectResultInvokeAsync(call.Parameters);
                }
                else if (param is RemotingMessage)
                {
                    var message = param as RemotingMessage;

                    object endpoint;
                    message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                    object id;
                    message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);

                    WrapCallback(() =>
                    {
                        if (ServerMessageReceived != null)
                        {
                            ServerMessageReceived(this, new RemotingMessageReceivedEventArgs(message, message.Operation, endpoint as string, message.Destination, message.MessageId, message.Body, command.InvokeId));
                        }
                    });
                }
                else if (param is CommandMessage)
                {
                    var message = param as CommandMessage;

                    object endpoint;
                    message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                    object id;
                    message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);

                    WrapCallback(() =>
                    {
                        if (ServerCommandReceived != null)
                        {
                            ServerCommandReceived(this, new CommandMessageReceivedEventArgs(message, endpoint as string, id as string, command.InvokeId));
                        }
                    });
                }
                else
                {
#if DEBUG
                    System.Diagnostics.Debug.Print("Unknown RTMP Command: " + call.Name);
                    System.Diagnostics.Debugger.Break();
#endif
                }
                break;
            }
        }
Ejemplo n.º 6
0
        private void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            try
            {
                switch (e.Event.MessageType)
                {
                case MessageType.UserControlMessage:
                    UserControlMessage userControlMessage = (UserControlMessage)e.Event;
                    if (userControlMessage.EventType != UserControlMessageType.PingRequest)
                    {
                        break;
                    }
                    this.WriteProtocolControlMessage((RtmpEvent) new UserControlMessage(UserControlMessageType.PingResponse, userControlMessage.Values));
                    break;

                case MessageType.CommandAmf3:
                case MessageType.DataAmf0:
                case MessageType.CommandAmf0:
                    Command command    = (Command)e.Event;
                    Method  methodCall = command.MethodCall;
                    object  obj1       = methodCall.Parameters.Length == 1 ? methodCall.Parameters[0] : (object)methodCall.Parameters;
                    if (methodCall.Name == "_result" && !(obj1 is AcknowledgeMessageExt))
                    {
                        AcknowledgeMessageExt acknowledgeMessageExt = new AcknowledgeMessageExt();
                        object obj2 = obj1;
                        acknowledgeMessageExt.Body = obj2;
                        AcknowledgeMessageExt result = acknowledgeMessageExt;
                        this._callbackManager.SetResult(command.InvokeId, result);
                        break;
                    }
                    if (methodCall.Name == "_result")
                    {
                        AcknowledgeMessageExt result = (AcknowledgeMessageExt)obj1;
                        this._callbackManager.SetResult(command.InvokeId, result);
                        break;
                    }
                    if (methodCall.Name == "_error")
                    {
                        ErrorMessage errorMessage = (ErrorMessage)obj1;
                        this._callbackManager.SetException(command.InvokeId, errorMessage != null ? (Exception) new InvocationException(errorMessage) : (Exception) new InvocationException());
                        break;
                    }
                    if (methodCall.Name == "receive")
                    {
                        AsyncMessageExt message = (AsyncMessageExt)obj1;
                        if (message == null)
                        {
                            break;
                        }
                        object obj2;
                        message.Headers.TryGetValue("DSSubtopic", out obj2);
                        string dsSubtopic = obj2 as string;
                        string clientId   = message.ClientId;
                        this.WrapCallback((Action)(() =>
                        {
                            // ISSUE: reference to a compiler-generated field
                            EventHandler <MessageReceivedEventArgs> messageReceived = this.MessageReceived;
                            if (messageReceived == null)
                            {
                                return;
                            }
                            MessageReceivedEventArgs e1 = new MessageReceivedEventArgs(clientId, dsSubtopic, message);
                            messageReceived((object)this, e1);
                        }));
                        break;
                    }
                    int num = methodCall.Name == "onstatus" ? 1 : 0;
                    break;
                }
            }
            catch (ClientDisconnectedException ex)
            {
                this.Close();
            }
        }
Ejemplo n.º 7
0
        private async void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            try
            {
                Command command;
                object  param;
                switch (e.Event.MessageType)
                {
                case MessageType.UserControlMessage:
                    UserControlMessage userControlMessage = (UserControlMessage)e.Event;
                    if (userControlMessage.EventType == UserControlMessageType.PingRequest)
                    {
                        this.WriteProtocolControlMessage((RtmpEvent) new UserControlMessage(UserControlMessageType.PingResponse, userControlMessage.Values));
                        break;
                    }
                    break;

                case MessageType.CommandAmf3:
                case MessageType.DataAmf0:
                case MessageType.CommandAmf0:
                    command = (Command)e.Event;
                    Method methodCall = command.MethodCall;
                    param = methodCall.Parameters.Length == 1 ? methodCall.Parameters[0] : (object)methodCall.Parameters;
                    if (methodCall.Name == "_result" || methodCall.Name == "_error" || methodCall.Name == "receive")
                    {
                        throw new InvalidDataException();
                    }
                    if (!(methodCall.Name == "onstatus"))
                    {
                        if (methodCall.Name == "connect")
                        {
                            CommandMessage parameter = (CommandMessage)methodCall.Parameters[3];
                            object         obj1;
                            parameter.Headers.TryGetValue("DSEndpoint", out obj1);
                            object obj2;
                            parameter.Headers.TryGetValue("DSId", out obj2);
                            ConnectMessageEventArgs args = new ConnectMessageEventArgs((string)methodCall.Parameters[1], (string)methodCall.Parameters[2], parameter, (string)obj1, (string)obj2, command.InvokeId, (AsObject)command.ConnectionParameters);
                            // ISSUE: reference to a compiler-generated field
                            EventHandler <ConnectMessageEventArgs> connectMessageReceived = this.ConnectMessageReceived;
                            if (connectMessageReceived != null)
                            {
                                ConnectMessageEventArgs e1 = args;
                                connectMessageReceived((object)this, e1);
                            }
                            if (parameter.Operation == CommandOperation.ClientPing)
                            {
                                AsObject asObject1 = await this.InvokeConnectResultAsync(command.InvokeId, (AsObject)args.Result.Body);
                            }
                            else
                            {
                                AsObject asObject2 = await this.InvokeReconnectResultInvokeAsync(command.InvokeId, (AsObject)args.Result.Body);
                            }
                            args = (ConnectMessageEventArgs)null;
                            break;
                        }
                        if (param is RemotingMessage)
                        {
                            RemotingMessage message = param as RemotingMessage;
                            object          obj1;
                            message.Headers.TryGetValue("DSEndpoint", out obj1);
                            object obj2;
                            message.Headers.TryGetValue("DSId", out obj2);
                            string endpoint = (string)obj1;
                            string clientId = (string)obj2;
                            int    invokeId = command.InvokeId;
                            RemotingMessageReceivedEventArgs receivedEventArgs = new RemotingMessageReceivedEventArgs(message, endpoint, clientId, invokeId);
                            // ISSUE: reference to a compiler-generated field
                            EventHandler <RemotingMessageReceivedEventArgs> remotingMessageReceived = this.RemotingMessageReceived;
                            if (remotingMessageReceived != null)
                            {
                                RemotingMessageReceivedEventArgs e1 = receivedEventArgs;
                                remotingMessageReceived((object)this, e1);
                            }
                            if (receivedEventArgs.Error == null)
                            {
                                this.InvokeResult(command.InvokeId, receivedEventArgs.Result);
                                break;
                            }
                            this.InvokeError(command.InvokeId, receivedEventArgs.Error);
                            break;
                        }
                        if (param is CommandMessage)
                        {
                            CommandMessage message = param as CommandMessage;
                            object         obj1;
                            message.Headers.TryGetValue("DSEndpoint", out obj1);
                            object obj2;
                            message.Headers.TryGetValue("DSId", out obj2);
                            string endpoint = obj1 as string;
                            string dsId     = obj2 as string;
                            int    invokeId = command.InvokeId;
                            CommandMessageReceivedEventArgs receivedEventArgs = new CommandMessageReceivedEventArgs(message, endpoint, dsId, invokeId);
                            // ISSUE: reference to a compiler-generated field
                            EventHandler <CommandMessageReceivedEventArgs> commandMessageReceived = this.CommandMessageReceived;
                            if (commandMessageReceived != null)
                            {
                                CommandMessageReceivedEventArgs e1 = receivedEventArgs;
                                commandMessageReceived((object)this, e1);
                            }
                            this.InvokeResult(command.InvokeId, receivedEventArgs.Result);
                            break;
                        }
                        break;
                    }
                    break;
                }
                command = (Command)null;
                param   = (object)null;
            }
            catch (ClientDisconnectedException ex)
            {
            }
        }
Ejemplo n.º 8
0
        void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            switch (e.Event.MessageType)
            {
            case MessageType.UserControlMessage:
                var m = (UserControlMessage)e.Event;
                if (m.EventType == UserControlMessageType.PingRequest)
                {
                    WriteProtocolControlMessage(new UserControlMessage(UserControlMessageType.PingResponse, m.Values));
                }
                break;

            case MessageType.DataAmf3:
#if DEBUG
                // have no idea what the contents of these packets are.
                // study these packets if we receive them.
                System.Diagnostics.Debugger.Break();
#endif
                break;

            case MessageType.CommandAmf3:
            case MessageType.DataAmf0:
            case MessageType.CommandAmf0:
                var command = (Command)e.Event;
                var call    = command.MethodCall;

                var param = call.Parameters.Length == 1 ? call.Parameters[0] : call.Parameters;
                switch (call.Name)
                {
                case "_result":
                    // unwrap Flex class, if present
                    var ack = param as AcknowledgeMessage;
                    callbackManager.SetResult(command.InvokeId, ack != null ? ack.Body : param);
                    break;

                case "_error":
                    // unwrap Flex class, if present
                    var error = param as ErrorMessage;
                    callbackManager.SetException(command.InvokeId, error != null ? new InvocationException(error) : new InvocationException());
                    break;

                case "receive":
                    var message = param as AsyncMessage;
                    if (message == null)
                    {
                        break;
                    }

                    object subtopicObject;
                    message.Headers.TryGetValue(AsyncMessageHeaders.Subtopic, out subtopicObject);

                    var dsSubtopic = subtopicObject as string;
                    var clientId   = message.ClientId;
                    var body       = message.Body;

                    WrapCallback(() => MessageReceived?.Invoke(this, new MessageReceivedEventArgs(clientId, dsSubtopic, body)));
                    break;

                case "onstatus":
                    System.Diagnostics.Debug.Print("received status");
                    break;

                default:
#if DEBUG
                    System.Diagnostics.Debug.Print($"unknown rtmp command: {call.Name}");
                    System.Diagnostics.Debugger.Break();
#endif
                    break;
                }

                break;
            }
        }
Ejemplo n.º 9
0
        private void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            try
            {
                switch (e.Event.MessageType)
                {
                case MessageType.UserControlMessage:
                    var m = (UserControlMessage)e.Event;
                    if (m.EventType == UserControlMessageType.PingRequest)
                    {
                        WriteProtocolControlMessage(new UserControlMessage(UserControlMessageType.PingResponse,
                                                                           m.Values));
                    }
                    break;

                case MessageType.DataAmf3:
#if DEBUG
                    // Have no idea what the contents of these packets are.
                    // Study these packets if we receive them.
                    Debugger.Break();
#endif
                    break;

                case MessageType.CommandAmf3:
                case MessageType.DataAmf0:
                case MessageType.CommandAmf0:
                    var command = (Command)e.Event;
                    var call    = command.MethodCall;

                    var param = call.Parameters.Length == 1 ? call.Parameters[0] : call.Parameters;
                    if (call.Name == "_result" && !(param is AcknowledgeMessageExt))
                    {
                        //wrap the parameter
                        var ack = new AcknowledgeMessageExt {
                            Body = param
                        };
                        callbackManager.SetResult(command.InvokeId, ack);
                    }
                    else if (call.Name == "_result")
                    {
                        var ack = (AcknowledgeMessageExt)param;
                        callbackManager.SetResult(command.InvokeId, ack);
                    }
                    else if (call.Name == "_error")
                    {
                        // unwrap Flex class, if present
                        var error = (ErrorMessage)param;
                        callbackManager.SetException(command.InvokeId,
                                                     error != null ? new InvocationException(error) : new InvocationException());
                    }
                    else if (call.Name == "receive")
                    {
                        var message = (AsyncMessageExt)param;
                        if (message == null)
                        {
                            break;
                        }

                        object subtopicObject;
                        message.Headers.TryGetValue(AsyncMessageHeaders.Subtopic, out subtopicObject);

                        var dsSubtopic = subtopicObject as string;
                        var clientId   = message.ClientId;

                        WrapCallback(() =>
                        {
                            if (MessageReceived != null)
                            {
                                MessageReceived(this, new MessageReceivedEventArgs(clientId, dsSubtopic, message));
                            }
                        });
                    }
                    else if (call.Name == "onstatus")
                    {
                        Debug.Print("Received status.");
                    }
                    else
                    {
#if DEBUG
                        Debug.Print("Unknown RTMP Command: " + call.Name);
                        Debugger.Break();
#endif
                    }
                    break;
                }
            }
            catch (ClientDisconnectedException)
            {
                Close();
            }
        }
Ejemplo n.º 10
0
 void OnEventReceived(EventReceivedEventArgs e) => EventReceived?.Invoke(this, e);
 void OnEventReceived(EventReceivedEventArgs e) => EventReceived?.Invoke(this, e);
Ejemplo n.º 12
0
        private async void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            try
            {
                switch (e.Event.MessageType)
                {
                case MessageType.UserControlMessage:
                    var m = (UserControlMessage)e.Event;
                    if (m.EventType == UserControlMessageType.PingRequest)
                    {
                        WriteProtocolControlMessage(new UserControlMessage(UserControlMessageType.PingResponse,
                                                                           m.Values));
                    }
                    break;

                case MessageType.DataAmf3:
#if DEBUG
                    // Have no idea what the contents of these packets are.
                    // Study these packets if we receive them.
                    Debugger.Break();
#endif
                    break;

                case MessageType.CommandAmf3:
                case MessageType.DataAmf0:
                case MessageType.CommandAmf0:
                    var command = (Command)e.Event;
                    var call    = command.MethodCall;

                    var param = call.Parameters.Length == 1 ? call.Parameters[0] : call.Parameters;
                    if (call.Name == "_result" || call.Name == "_error" || call.Name == "receive")
                    {
                        //should not happen here
                        throw new InvalidDataException();
                    }
                    if (call.Name == "onstatus")
                    {
                        Debug.Print("Received status.");
                    }
                    else if (call.Name == "connect")
                    {
                        var    message = (CommandMessage)call.Parameters[3];
                        object endpoint;
                        message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                        object id;
                        message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);
                        //ClientId = (string) id;

                        var args = new ConnectMessageEventArgs((string)call.Parameters[1],
                                                               (string)call.Parameters[2], message, (string)endpoint, (string)id, command.InvokeId,
                                                               (AsObject)command.ConnectionParameters);
                        if (ConnectMessageReceived != null)
                        {
                            ConnectMessageReceived(this, args);
                        }
                        if (message.Operation == CommandOperation.ClientPing)
                        {
                            await InvokeConnectResultAsync(command.InvokeId, (AsObject)args.Result.Body);
                        }
                        else
                        {
                            await InvokeReconnectResultInvokeAsync(command.InvokeId, (AsObject)args.Result.Body);
                        }
                    }
                    else if (param is RemotingMessage)
                    {
                        var message = param as RemotingMessage;

                        object endpoint;
                        message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                        object id;
                        message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);

                        var args = new RemotingMessageReceivedEventArgs(message, (string)endpoint, (string)id,
                                                                        command.InvokeId);
                        if (RemotingMessageReceived != null)
                        {
                            RemotingMessageReceived(this, args);
                        }
                        if (args.Error == null)
                        {
                            InvokeResult(command.InvokeId, args.Result);
                        }
                        else
                        {
                            InvokeError(command.InvokeId, args.Error);
                        }
                    }
                    else if (param is CommandMessage)
                    {
                        var message = param as CommandMessage;

                        object endpoint;
                        message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                        object id;
                        message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);

                        var args = new CommandMessageReceivedEventArgs(message, endpoint as string, id as string,
                                                                       command.InvokeId);
                        if (CommandMessageReceived != null)
                        {
                            CommandMessageReceived(this, args);
                        }
                        InvokeResult(command.InvokeId, args.Result);
                    }
                    else
                    {
#if DEBUG
                        Debug.Print("Unknown RTMP Command: " + call.Name);
                        Debugger.Break();
#endif
                    }
                    break;
                }
            }
            catch (ClientDisconnectedException)
            {
                //Close();
            }
        }
Ejemplo n.º 13
0
        async void EventReceivedCallback(object sender, EventReceivedEventArgs e)
        {
            try
            {
                switch (e.Event.MessageType)
                {
                    case MessageType.UserControlMessage:
                        var m = (UserControlMessage)e.Event;
                        if (m.EventType == UserControlMessageType.PingRequest)
                            WriteProtocolControlMessage(new UserControlMessage(UserControlMessageType.PingResponse, m.Values));
                        break;

                    case MessageType.DataAmf3:
#if DEBUG
                        // Have no idea what the contents of these packets are.
                        // Study these packets if we receive them.
                        System.Diagnostics.Debugger.Break();
#endif
                        break;
                    case MessageType.CommandAmf3:
                    case MessageType.DataAmf0:
                    case MessageType.CommandAmf0:
                        var command = (Command)e.Event;
                        var call = command.MethodCall;

                        var param = call.Parameters.Length == 1 ? call.Parameters[0] : call.Parameters;
                        if (call.Name == "_result"||call.Name == "_error"||call.Name == "receive")
                        {
                            //should not happen here
                            throw new InvalidDataException();
                        }
                        else if (call.Name == "onstatus")
                        {
                            System.Diagnostics.Debug.Print("Received status.");
                        }
                        else if (call.Name == "connect")
                        {
                            var message = (CommandMessage)call.Parameters[3];
                            object endpoint;
                            message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                            object id;
                            message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);
                            //ClientId = (string) id;

                            var args = new ConnectMessageEventArgs((string) call.Parameters[1], (string) call.Parameters[2], message, (string) endpoint, (string) id, command.InvokeId, (AsObject)command.ConnectionParameters);
                            if(ConnectMessageReceived!=null)
                                ConnectMessageReceived(this, args);
                            if(message.Operation==CommandOperation.ClientPing)
                                await InvokeConnectResultAsync(command.InvokeId, (AsObject)args.Result.Body);
                            else
                                await InvokeReconnectResultInvokeAsync(command.InvokeId, (AsObject)args.Result.Body);
                        }
                        else if (param is RemotingMessage)
                        {
                            var message = param as RemotingMessage;

                            object endpoint;
                            message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                            object id;
                            message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);

                            var args = new RemotingMessageReceivedEventArgs(message, (string) endpoint, (string) id, command.InvokeId);
                            if (RemotingMessageReceived != null)
                                RemotingMessageReceived(this, args);
                            if (args.Error == null)
                                InvokeResult(command.InvokeId, args.Result);
                            else
                                InvokeError(command.InvokeId, args.Error);

                        }
                        else if (param is CommandMessage)
                        {
                            var message = param as CommandMessage;

                            object endpoint;
                            message.Headers.TryGetValue(AsyncMessageHeaders.Endpoint, out endpoint);
                            object id;
                            message.Headers.TryGetValue(AsyncMessageHeaders.ID, out id);

                            var args = new CommandMessageReceivedEventArgs(message, endpoint as string, id as string, command.InvokeId);
                            if (CommandMessageReceived != null)
                                CommandMessageReceived(this, args);
                            InvokeResult(command.InvokeId, args.Result);
                        }
                        else
                        {
#if DEBUG
                            System.Diagnostics.Debug.Print("Unknown RTMP Command: " + call.Name);
                            System.Diagnostics.Debugger.Break();
#endif
                        }
                        break;
                }
            }
            catch(ClientDisconnectedException ex)
            {
                //Close();
            }
        }