protected override void OnFlexInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, FlexInvoke invoke) { OnInvoke(connection, channel, header, invoke); }
static ByteBuffer EncodeFlexInvoke(RtmpContext context, FlexInvoke invoke) { ByteBuffer output = ByteBuffer.Allocate(1024); output.AutoExpand = true; RtmpWriter writer = new RtmpWriter(output); //Set legacy collection flag from context writer.UseLegacyCollection = context.UseLegacyCollection; writer.UseLegacyThrowable = context.UseLegacyThrowable; writer.WriteByte(0); //writer.WriteData(context.ObjectEncoding, invoke.Cmd); IServiceCall serviceCall = invoke.ServiceCall; bool isPending = serviceCall.Status == Call.STATUS_PENDING; if (!isPending) { //log.debug("Call has been executed, send result"); if (serviceCall.IsSuccess) { writer.WriteData(context.ObjectEncoding, "_result"); } else { writer.WriteData(context.ObjectEncoding, "_error"); } } else { //log.debug("This is a pending call, send request"); writer.WriteData(context.ObjectEncoding, serviceCall.ServiceMethodName); } writer.WriteData(context.ObjectEncoding, invoke.InvokeId); writer.WriteData(context.ObjectEncoding, invoke.CmdData); //object response = invoke.Response; //writer.WriteData(context.ObjectEncoding, response); if (!isPending) { IPendingServiceCall pendingCall = (IPendingServiceCall)serviceCall; /* * if (!serviceCall.IsSuccess) * { * StatusASO status = GenerateErrorResult(StatusASO.NC_CALL_FAILED, serviceCall.Exception); * pendingCall.Result = status; * } */ writer.WriteData(context.ObjectEncoding, pendingCall.Result); } else { //log.debug("Writing params"); object[] args = invoke.ServiceCall.Arguments; if (args != null) { foreach (object element in args) { writer.WriteData(context.ObjectEncoding, element); } } } return(output); }
protected override void OnFlexInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, FlexInvoke invoke) { IMessage message = null; if (invoke.ServiceCall.Arguments != null && invoke.ServiceCall.Arguments.Length > 0) { message = invoke.ServiceCall.Arguments[0] as IMessage; } if (message != null) { MessageBroker messageBroker = this.Endpoint.GetMessageBroker(); if (message.clientId == null) { message.clientId = Guid.NewGuid().ToString("D"); /* * if( !(message is CommandMessage) ) * { * //producer may send messages without subscribing * CommandMessage commandMessageSubscribe = new CommandMessage(CommandMessage.SubscribeOperation); * commandMessageSubscribe.messageId = Guid.NewGuid().ToString("D"); * commandMessageSubscribe.headers = message.headers.Clone() as Hashtable; * commandMessageSubscribe.messageRefType = message.GetType().FullName;//"flex.messaging.messages.AsyncMessage" * commandMessageSubscribe.destination = message.destination; * * IMessage subscribeResponse = messageBroker.RouteMessage(commandMessageSubscribe, _endpoint, connection); * message.clientId = subscribeResponse.clientId; * } * } */ } IMessage response = messageBroker.RouteMessage(message, this.Endpoint); invoke.ServiceCall.Status = response is ErrorMessage ? Call.STATUS_INVOCATION_EXCEPTION : Call.STATUS_SUCCESS_RESULT; if (invoke.ServiceCall is IPendingServiceCall) { (invoke.ServiceCall as IPendingServiceCall).Result = response; } FlexInvoke reply = new FlexInvoke(); reply.InvokeId = invoke.InvokeId; reply.ServiceCall = invoke.ServiceCall; /* * if( response is ErrorMessage ) * reply.SetResponseFailure(); * else * reply.SetResponseSuccess(); * reply.Response = response; */ channel.Write(reply); } else { // If it's a callback for server remote call then pass it over to callbacks handler and return OnInvoke(connection, channel, header, invoke); } }
/// <summary> /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code. /// </summary> /// <param name="connection"></param> /// <param name="channel"></param> /// <param name="header"></param> /// <param name="invoke"></param> protected abstract void OnFlexInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, FlexInvoke invoke);
protected override void OnInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, Notify invoke) { IServiceCall serviceCall = invoke.ServiceCall; if (serviceCall.ServiceMethodName.Equals("_result") || serviceCall.ServiceMethodName.Equals("_error")) { base.HandlePendingCallResult(connection, invoke); } else { bool flag = false; string serviceMethodName = null; if (serviceCall.ServiceName == null) { StatusASO statusObject; Exception exception2; serviceMethodName = serviceCall.ServiceMethodName; switch (serviceMethodName) { case "connect": { if (connection.IsConnected) { InvokeCall(connection, serviceCall); break; } IDictionary connectionParameters = invoke.ConnectionParameters; string host = null; if (connectionParameters.Contains("tcUrl")) { host = BaseRtmpHandler.GetHostname(connectionParameters["tcUrl"] as string); } if ((host != null) && (host.IndexOf(":") != -1)) { host = host.Substring(0, host.IndexOf(":")); } string str3 = connectionParameters["app"] as string; string path = connectionParameters["app"] as string; if ((path != null) && (path.IndexOf("?") != -1)) { int index = path.IndexOf("?"); connectionParameters["queryString"] = path.Substring(index); path = path.Substring(0, index); } connectionParameters["path"] = path; connection.Setup(host, path, connectionParameters); try { IGlobalScope globalScope = this.Endpoint.GetMessageBroker().GlobalScope; if (globalScope == null) { serviceCall.Status = 0x10; if (serviceCall is IPendingServiceCall) { statusObject = StatusASO.GetStatusObject("NetConnection.Connect.InvalidApp", connection.ObjectEncoding); statusObject.description = "No global scope on this server."; (serviceCall as IPendingServiceCall).Result = statusObject; } log.Info(string.Format("No application scope found for {0} on host {1}. Misspelled or missing application folder?", path, host)); flag = true; } else { IScopeContext context = globalScope.Context; IScope scope = null; try { scope = context.ResolveScope(globalScope, path); } catch (ScopeNotFoundException) { if (log.get_IsErrorEnabled()) { log.Error(__Res.GetString("Scope_NotFound", new object[] { path })); } serviceCall.Status = 0x10; if (serviceCall is IPendingServiceCall) { statusObject = StatusASO.GetStatusObject("NetConnection.Connect.Rejected", connection.ObjectEncoding); statusObject.description = "No scope \"" + path + "\" on this server."; (serviceCall as IPendingServiceCall).Result = statusObject; } flag = true; } catch (ScopeShuttingDownException) { serviceCall.Status = 0x15; if (serviceCall is IPendingServiceCall) { statusObject = StatusASO.GetStatusObject("NetConnection.Connect.AppShutdown", connection.ObjectEncoding); statusObject.description = "Application at \"" + path + "\" is currently shutting down."; (serviceCall as IPendingServiceCall).Result = statusObject; } log.Info(string.Format("Application at {0} currently shutting down on {1}", path, host)); flag = true; } if (scope != null) { StatusASO saso2; if (log.get_IsInfoEnabled()) { log.Info(__Res.GetString("Scope_Connect", new object[] { scope.Name })); } try { bool flag2; if (str3 == string.Empty) { connection.SetIsFlexClient(true); flag2 = connection.Connect(scope, serviceCall.Arguments); if (flag2) { string str5; if ((serviceCall.Arguments != null) && (serviceCall.Arguments.Length == 3)) { str5 = serviceCall.Arguments[2] as string; AuthenticationService service = this.Endpoint.GetMessageBroker().GetService("authentication-service") as AuthenticationService; service.Authenticate(str5); } if ((serviceCall.Arguments != null) && (serviceCall.Arguments.Length == 1)) { str5 = serviceCall.Arguments[0] as string; (this.Endpoint.GetMessageBroker().GetService("authentication-service") as AuthenticationService).Authenticate(str5); } } } else { connection.SetIsFlexClient(false); flag2 = connection.Connect(scope, serviceCall.Arguments); } if (flag2) { if (log.get_IsDebugEnabled()) { log.Debug("Connected RtmpClient: " + connection.Client.Id); } serviceCall.Status = 2; if (serviceCall is IPendingServiceCall) { saso2 = StatusASO.GetStatusObject("NetConnection.Connect.Success", connection.ObjectEncoding); saso2.Add("id", connection.Client.Id); (serviceCall as IPendingServiceCall).Result = saso2; } connection.GetChannel(2).Write(new Ping(0, 0, -1)); connection.StartRoundTripMeasurement(); } else { if (log.get_IsDebugEnabled()) { log.Debug("Connect failed"); } serviceCall.Status = 0x12; if (serviceCall is IPendingServiceCall) { (serviceCall as IPendingServiceCall).Result = StatusASO.GetStatusObject("NetConnection.Connect.Rejected", connection.ObjectEncoding); } flag = true; } } catch (ClientRejectedException exception) { if (log.get_IsDebugEnabled()) { log.Debug("Connect rejected"); } serviceCall.Status = 0x12; if (serviceCall is IPendingServiceCall) { saso2 = StatusASO.GetStatusObject("NetConnection.Connect.Rejected", connection.ObjectEncoding); saso2.Application = exception.Reason; (serviceCall as IPendingServiceCall).Result = saso2; } flag = true; } } } } catch (Exception exception5) { exception2 = exception5; if (log.get_IsErrorEnabled()) { log.Error("Error connecting", exception2); } serviceCall.Status = 20; if (serviceCall is IPendingServiceCall) { (serviceCall as IPendingServiceCall).Result = StatusASO.GetStatusObject("NetConnection.Connect.Failed", connection.ObjectEncoding); } flag = true; } break; } case "disconnect": connection.Close(); break; case "createStream": case "deleteStream": case "releaseStream": case "publish": case "play": case "seek": case "pause": case "closeStream": case "receiveVideo": case "receiveAudio": { IStreamService scopeService = ScopeUtils.GetScopeService(connection.Scope, typeof(IStreamService)) as IStreamService; statusObject = null; try { if (!InvokeCall(connection, serviceCall, scopeService)) { statusObject = StatusASO.GetStatusObject("NetStream.InvalidArg", connection.ObjectEncoding); statusObject.description = string.Concat(new object[] { "Failed to ", serviceMethodName, " (stream ID: ", header.StreamId, ")" }); } } catch (Exception exception6) { exception2 = exception6; log.Error("Error while invoking " + serviceMethodName + " on stream service.", exception2); statusObject = StatusASO.GetStatusObject("NetStream.Failed", connection.ObjectEncoding); statusObject.description = string.Concat(new object[] { "Error while invoking ", serviceMethodName, " (stream ID: ", header.StreamId, ")" }); statusObject.details = exception2.Message; } if (statusObject != null) { channel.SendStatus(statusObject); } break; } default: if (connection.IsConnected) { InvokeCall(connection, serviceCall); } else { if (log.get_IsWarnEnabled()) { log.Warn("Not connected, closing connection"); } connection.Close(); } break; } } if (invoke is FlexInvoke) { FlexInvoke message = new FlexInvoke { InvokeId = invoke.InvokeId }; message.SetResponseSuccess(); if (serviceCall is IPendingServiceCall) { IPendingServiceCall call2 = (IPendingServiceCall)serviceCall; message.Response = call2.Result; } channel.Write(message); } else if (invoke is Invoke) { if ((header.StreamId != 0) && ((serviceCall.Status == 4) || (serviceCall.Status == 3))) { if (log.get_IsDebugEnabled()) { log.Debug("Method does not have return value, do not reply"); } return; } Invoke invoke3 = new Invoke { ServiceCall = serviceCall, InvokeId = invoke.InvokeId }; channel.Write(invoke3); } if (flag) { connection.Close(); } if (serviceMethodName == "connect") { connection.Context.ObjectEncoding = connection.ObjectEncoding; } } }
protected override void OnFlexInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, FlexInvoke invoke) { IMessage message = null; if ((invoke.Parameters != null) && (invoke.Parameters.Length > 0)) { message = invoke.Parameters[0] as IMessage; } if (message != null) { MessageBroker messageBroker = this.Endpoint.GetMessageBroker(); if (message.clientId == null) { message.clientId = Guid.NewGuid().ToString("D"); } IMessage message2 = messageBroker.RouteMessage(message, this.Endpoint); FlexInvoke invoke2 = new FlexInvoke { InvokeId = invoke.InvokeId }; if (message2 is ErrorMessage) { invoke2.SetResponseFailure(); } else { invoke2.SetResponseSuccess(); } invoke2.Response = message2; channel.Write(invoke2); } else { this.OnInvoke(connection, channel, header, invoke); } }