コード例 #1
0
ファイル: LolProxy.cs プロジェクト: chienhao10/FinalesFunkeln
 void LolProxy_ClientCommandReceived(object sender, CommandMessageReceivedEventArgs e)
 {
     if(e.Message.Operation==CommandOperation.Subscribe)
         switch (e.Message.ClientId.Substring(0, 2))
         {
             case "cn":
                 CnChannelId = e.Message.ClientId;
                 break;
             case "gn":
                 GnChannelId = e.Message.ClientId;
                 break;
             case "bc":
                 BcChannelId = e.Message.ClientId;
                 break;
         }
 }
コード例 #2
0
ファイル: RtmpServer.cs プロジェクト: osiato/LegendaryClient
        void ServerCommandReceived(object sender, CommandMessageReceivedEventArgs e)
        {
            RtmpClient client = (RtmpClient)sender;
            switch (e.Message.Operation)
            {
                case CommandOperation.Login:
                    AcknowledgeMessageExt login = new AcknowledgeMessageExt
                    {
                        Body = "success",
                        CorrelationId = e.Message.MessageId,
                        MessageId = Uuid.NewUuid(),
                        ClientId = Uuid.NewUuid(),
                        Headers = new AsObject
                        {
                            { "DSMessagingVersion", 1.0 },
                            { FlexMessageHeaders.FlexClientId, e.DSId }
                        }
                    };

                    client.InvokeResult(e.InvokeId, login);
                    break;
                case CommandOperation.Subscribe:
                    AcknowledgeMessageExt subscribe = new AcknowledgeMessageExt
                    {
                        Body = null,
                        CorrelationId = e.Message.MessageId,
                        MessageId = Uuid.NewUuid(),
                        ClientId = e.Message.ClientId
                    };

                    client.InvokeResult(e.InvokeId, subscribe);
                    break;
                case CommandOperation.Unsubscribe:
                    break;
                case CommandOperation.ClientPing:
                    break;
                case CommandOperation.Logout:
                    break;
                default:
                    throw new NotSupportedException();
            }

            if (ClientCommandReceieved != null)
            {
                ClientCommandReceieved(sender, e);
            }
        }
コード例 #3
0
 private void OnCommandMessageReceived(object sender, CommandMessageReceivedEventArgs e)
 {
     e.Result = _remote.InvokeAckAsync(e.InvokeId, null, e.Message).Result;
 }
コード例 #4
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();
            }
        }