private void OnConnectMessageReceived(object sender, ConnectMessageEventArgs e) { if (e.Message.Operation == CommandOperation.ClientPing) { _remote = new RtmpProxyRemote(_remoteUri, _serializationContext, ObjectEncoding.Amf3); _remote.MessageReceived += OnAsyncMessageReceived; _remote.Disconnected += OnServerDisconnected; e.Result = _remote.ConnectAckAsync(e.InvokeId, e.ConnectionParameters, false, e.ClientId, e.AuthToken, e.Message).Result; if (Connected != null) { Connected(this, new EventArgs()); } } else { _remote = new RtmpProxyRemote(_remoteUri, _serializationContext, ObjectEncoding.Amf3); _remote.MessageReceived += OnAsyncMessageReceived; _remote.Disconnected += OnServerDisconnected; e.Result = _remote.ReconnectAckAsync(e.InvokeId, e.ConnectionParameters, false, e.ClientId, e.AuthToken, e.Message).Result; if (Connected != null) { Connected(this, new EventArgs()); } } }
private void OnConnectMessageReceived(object sender, ConnectMessageEventArgs e) { if (e.Message.Operation == CommandOperation.ClientPing) { this._remote = new RtmpProxyRemote(this._remoteUri, this._serializationContext, ObjectEncoding.Amf3); this._remote.MessageReceived += new EventHandler <MessageReceivedEventArgs>(this.OnAsyncMessageReceived); this._remote.Disconnected += new EventHandler(this.OnServerDisconnected); e.Result = this._remote.ConnectAckAsync(e.InvokeId, e.ConnectionParameters, (object)false, (object)e.ClientId, (object)e.AuthToken, (object)e.Message).Result; // ISSUE: reference to a compiler-generated field EventHandler <EventArgs> connected = this.Connected; if (connected == null) { return; } EventArgs e1 = new EventArgs(); connected((object)this, e1); } else { this._remote = new RtmpProxyRemote(this._remoteUri, this._serializationContext, ObjectEncoding.Amf3); this._remote.MessageReceived += new EventHandler <MessageReceivedEventArgs>(this.OnAsyncMessageReceived); this._remote.Disconnected += new EventHandler(this.OnServerDisconnected); e.Result = this._remote.ReconnectAckAsync(e.InvokeId, e.ConnectionParameters, (object)false, (object)e.ClientId, (object)e.AuthToken, (object)e.Message).Result; // ISSUE: reference to a compiler-generated field EventHandler <EventArgs> connected = this.Connected; if (connected == null) { return; } EventArgs e1 = new EventArgs(); connected((object)this, e1); } }
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) { } }
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(); } }