/// <summary> /// Handler for pending call result. Dispatches results to all pending call handlers. /// </summary> /// <param name="connection">Connection.</param> /// <param name="invoke">Pending call result event context.</param> protected void HandlePendingCallResult(RtmpConnection connection, Notify invoke) { IServiceCall call = invoke.ServiceCall; IPendingServiceCall pendingCall = connection.RetrievePendingCall(invoke.InvokeId); if (pendingCall != null) { pendingCall.Status = call.Status; // The client sent a response to a previously made call. object[] args = call.Arguments; if ((args != null) && (args.Length > 0)) { pendingCall.Result = args[0]; } IPendingServiceCallback[] callbacks = pendingCall.GetCallbacks(); if (callbacks != null && callbacks.Length > 0) { foreach (IPendingServiceCallback callback in callbacks) { try { callback.ResultReceived(pendingCall); } catch (Exception ex) { #if !SILVERLIGHT log.Error("Error while executing callback " + callback, ex); #endif } } } } }
internal void RegisterPendingCall(int invokeId, IPendingServiceCall call) { lock (((ICollection)this._pendingCalls).SyncRoot) { this._pendingCalls[invokeId] = call; } }
protected void HandlePendingCallResult(RtmpConnection connection, Notify invoke) { IServiceCall serviceCall = invoke.ServiceCall; IPendingServiceCall pendingCall = connection.GetPendingCall(invoke.InvokeId); if (pendingCall != null) { pendingCall.Status = serviceCall.Status; object[] arguments = serviceCall.Arguments; if ((arguments != null) && (arguments.Length > 0)) { pendingCall.Result = arguments[0]; } IPendingServiceCallback[] callbacks = pendingCall.GetCallbacks(); if ((callbacks != null) && (callbacks.Length > 0)) { foreach (IPendingServiceCallback callback in callbacks) { try { callback.ResultReceived(pendingCall); } catch (Exception exception) { log.Error("Error while executing callback " + callback, exception); } } } } }
public void ResultReceived(IPendingServiceCall call) { long tickCount = Environment.TickCount; this._pakRecv.Add(tickCount); long num2 = tickCount - ((long)this._beginningValues[2]); this._count++; if (this._count == 1) { this._latency = Math.Min(num2, 800L); this._latency = Math.Max(this._latency, 10.0); this._pakSent.Add(tickCount); this._sent++; ServiceUtils.InvokeOnConnection(this._connection, "onBWCheck", new object[] { this._connection.GetAttribute("payload") }, this); } else if (((this._count > 1) && (this._count < 3)) && (num2 < 0x3e8L)) { this._pakSent.Add(tickCount); this._sent++; this._cumLatency++; ServiceUtils.InvokeOnConnection(this._connection, "onBWCheck", new object[] { this._connection.GetAttribute("payload") }, this); } else if (((this._count >= 3) && (this._count < 6)) && (num2 < 0x3e8L)) { this._pakSent.Add(tickCount); this._sent++; this._cumLatency++; ServiceUtils.InvokeOnConnection(this._connection, "onBWCheck", new object[] { this._connection.GetAttribute("payload1") }, this); } else if ((this._count >= 6) && (num2 < 0x3e8L)) { this._pakSent.Add(tickCount); this._sent++; this._cumLatency++; ServiceUtils.InvokeOnConnection(this._connection, "onBWCheck", new object[] { this._connection.GetAttribute("payload2") }, this); } else if (this._sent == this._count) { if ((this._latency >= 100.0) && ((((long)this._pakRecv[1]) - ((long)this._pakRecv[0])) > 0x3e8L)) { this._latency = 100.0; } this._connection.RemoveAttribute("payload"); this._connection.RemoveAttribute("payload1"); this._connection.RemoveAttribute("payload2"); this._deltaDown = ((this._connection.WrittenBytes - ((long)this._beginningValues[0])) * 8L) / 0x3e8L; this._deltaTime = ((tickCount - ((long)this._beginningValues[2])) - (this._latency * this._cumLatency)) / 1000.0; if (this._deltaTime <= 0.0) { this._deltaTime = (tickCount - ((long)this._beginningValues[2])) / 0x3e8L; } this._kbitDown = Math.Round((double)(this._deltaDown / this._deltaTime)); ServiceUtils.InvokeOnConnection(this._connection, "onBWDone", new object[] { this._kbitDown, this._deltaDown, this._deltaTime, this._latency }, this); } }
public void ResultReceived(IPendingServiceCall call) { ASObject result = call.Result as ASObject; this._netConnection.RaiseNetStatus(result); if (!result.ContainsKey("level") || !(result["level"].ToString() == "error")) { this._netConnection.RaiseOnConnect(); } }
static ByteBuffer EncodeNotifyOrInvoke(RtmpContext context, Notify invoke) { //MemoryStreamEx output = new MemoryStreamEx(); 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; IServiceCall serviceCall = invoke.ServiceCall; bool isPending = serviceCall.Status == Call.STATUS_PENDING; if (!isPending) { //log.debug("Call has been executed, send result"); writer.WriteData(context.ObjectEncoding, serviceCall.IsSuccess ? "_result" : "_error"); } else { //log.debug("This is a pending call, send request"); string action = (serviceCall.ServiceName == null) ? serviceCall.ServiceMethodName : serviceCall.ServiceName + "." + serviceCall.ServiceMethodName; writer.WriteData(context.ObjectEncoding, action); } if (invoke is Invoke) { writer.WriteData(context.ObjectEncoding, invoke.InvokeId); writer.WriteData(context.ObjectEncoding, invoke.ConnectionParameters); } if (!isPending && (invoke is Invoke)) { IPendingServiceCall pendingCall = (IPendingServiceCall)serviceCall; if (!serviceCall.IsSuccess && !(pendingCall.Result is StatusASO)) { 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); }
public void ResultReceived(IPendingServiceCall call) { long now1 = System.Environment.TickCount; _pakRecv.Add(now1); long timePassed = (now1 - (long)_beginningValues[2]); _count++; if (_count == 1) { _latency = Math.Min(timePassed, 800); _latency = Math.Max(_latency, 10); // We now have a latency figure so can start sending test data. // Second call. 1st packet sent _pakSent.Add(now1); _sent++; ServiceUtils.InvokeOnConnection(_connection, "onBWCheck", new object[] { _connection.GetAttribute("payload") }, this); } //The following will progressivly increase the size of the packets been sent until 1 second has elapsed. else if ((_count > 1 && _count < 3) && (timePassed < 1000)) { _pakSent.Add(now1); _sent++; _cumLatency++; ServiceUtils.InvokeOnConnection(_connection, "onBWCheck", new object[] { _connection.GetAttribute("payload") }, this); } else if ((_count >= 3 && _count < 6) && (timePassed < 1000)) { _pakSent.Add(now1); _sent++; _cumLatency++; ServiceUtils.InvokeOnConnection(_connection, "onBWCheck", new object[] { _connection.GetAttribute("payload1") }, this); } else if (_count >= 6 && (timePassed < 1000)) { _pakSent.Add(now1); _sent++; _cumLatency++; ServiceUtils.InvokeOnConnection(_connection, "onBWCheck", new object[] { _connection.GetAttribute("payload2") }, this); } //Time elapsed now do the calcs else if (_sent == _count) { // see if we need to normalize latency if (_latency >= 100) { //make sure satelite and modem is detected properly if ((long)_pakRecv[1] - (long)_pakRecv[0] > 1000) { _latency = 100; } } _connection.RemoveAttribute("payload"); _connection.RemoveAttribute("payload1"); _connection.RemoveAttribute("payload2"); // tidy up and compute bandwidth _deltaDown = (_connection.WrittenBytes - (long)_beginningValues[0]) * 8 / 1000; // bytes to kbits _deltaTime = ((now1 - (long)_beginningValues[2]) - (_latency * _cumLatency)) / 1000; // total dl time - latency for each packet sent in secs if (_deltaTime <= 0) { _deltaTime = (now1 - (long)_beginningValues[2]) / 1000; } _kbitDown = Math.Round(_deltaDown / _deltaTime); // kbits / sec ServiceUtils.InvokeOnConnection(_connection, "onBWDone", new object[] { _kbitDown, _deltaDown, _deltaTime, _latency }, this); } }
public void ResultReceived(IPendingServiceCall call) { ASObject info = call.Result as ASObject; _netConnection.RaiseNetStatus(info); if ((info == null) || (info.ContainsKey("level") && info["level"].ToString() == "error")) { return; } _netConnection.RaiseOnConnect(); }
public void ResultReceived(IPendingServiceCall call) { if ("createStream".Equals(call.ServiceMethodName)) { RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection; object[] args = new object[3] { _name, _start, _length }; PendingCall pendingCall = new PendingCall("play", args); connection.Invoke(pendingCall, (byte)connection.GetChannelForStreamId(this.StreamId)); } }
public void ResultReceived(IPendingServiceCall call) { if ("createStream".Equals(call.ServiceMethodName)) { RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection; object[] args = new object[2] { _name, _mode }; PendingCall pendingCall = new PendingCall("publish", args); pendingCall.RegisterCallback(new PublishResultCallBack()); connection.Invoke(pendingCall, (byte)connection.GetChannelForStreamId(_stream.StreamId)); } }
public void ResultReceived(IPendingServiceCall call) { //Unwrap flex messages if (call.Result is ErrorMessage) { call.Status = Messaging.Rtmp.Service.Call.STATUS_INVOCATION_EXCEPTION; } else if (call.Result is AcknowledgeMessage) { AcknowledgeMessage ack = call.Result as AcknowledgeMessage; call.Result = ack.body; call.Status = Messaging.Rtmp.Service.Call.STATUS_SUCCESS_RESULT; } _callback.ResultReceived(call); }
/// <summary> /// The result received. /// </summary> /// <param name="call"> /// The call. /// </param> public void resultReceived(IPendingServiceCall call) { // client connected switch (this.type) { case NotificationType.Update: this.client.invoke( "notifyDomainObjectSaved", new object[] { this.domainObjectType.Name, this.vo }, null); break; case NotificationType.Delete: this.client.invoke( "notifyDomainObjectDeleted", new object[] { this.domainObjectType.Name, this.vo }, null); break; } }
private static ByteBuffer EncodeNotifyOrInvoke(RtmpContext context, Notify invoke) { ByteBuffer stream = ByteBuffer.Allocate(0x400); stream.AutoExpand = true; RtmpWriter writer = new RtmpWriter(stream); IServiceCall serviceCall = invoke.ServiceCall; bool flag = serviceCall.Status == 1; if (!flag) { writer.WriteData(context.ObjectEncoding, "_result"); } else { string data = (serviceCall.ServiceName == null) ? serviceCall.ServiceMethodName : (serviceCall.ServiceName + "." + serviceCall.ServiceMethodName); writer.WriteData(context.ObjectEncoding, data); } if (invoke is Invoke) { writer.WriteData(context.ObjectEncoding, invoke.InvokeId); writer.WriteData(context.ObjectEncoding, invoke.ConnectionParameters); } if (!flag && (invoke is Invoke)) { IPendingServiceCall call2 = (IPendingServiceCall)serviceCall; if (!serviceCall.IsSuccess) { StatusASO saso = GenerateErrorResult("NetConnection.Call.Failed", serviceCall.Exception); call2.Result = saso; } writer.WriteData(context.ObjectEncoding, call2.Result); return(stream); } object[] arguments = invoke.ServiceCall.Arguments; if (arguments != null) { foreach (object obj2 in arguments) { writer.WriteData(context.ObjectEncoding, obj2); } } return(stream); }
public IPendingServiceCall GetPendingCall(int invokeId) { IPendingServiceCall call = null; lock (((ICollection)this._pendingCalls).SyncRoot) { if (this._pendingCalls.ContainsKey(invokeId)) { call = this._pendingCalls[invokeId] as IPendingServiceCall; } if (call != null) { this._pendingCalls.Remove(invokeId); return(call); } log.Debug(string.Format("Could not find PendingServiceCall for InvokeId {0}", invokeId)); } return(call); }
public void ResultReceived(IPendingServiceCall call) { //Unwrap flex messages if (call.Result is ErrorMessage) { StatusFunction statusFunction = _responder.GetType().GetProperty("Status").GetValue(_responder, null) as StatusFunction; if (statusFunction != null) { statusFunction(new Fault(call.Result as ErrorMessage)); } } else if (call.Result is AcknowledgeMessage) { AcknowledgeMessage ack = call.Result as AcknowledgeMessage; Delegate resultFunction = _responder.GetType().GetProperty("Result").GetValue(_responder, null) as Delegate; if (resultFunction != null) { ParameterInfo[] arguments = resultFunction.Method.GetParameters(); object result = TypeHelper.ChangeType(ack.body, arguments[0].ParameterType); resultFunction.DynamicInvoke(result); } } else if (call.IsSuccess) { Delegate resultFunction = _responder.GetType().GetProperty("Result").GetValue(_responder, null) as Delegate; if (resultFunction != null) { ParameterInfo[] arguments = resultFunction.Method.GetParameters(); object result = TypeHelper.ChangeType(call.Result, arguments[0].ParameterType); resultFunction.DynamicInvoke(result); } } else { StatusFunction statusFunction = _responder.GetType().GetProperty("Status").GetValue(_responder, null) as StatusFunction; if (statusFunction != null) { statusFunction(new Fault(call.Result)); } } }
public void ResultReceived(IPendingServiceCall call) { if (call.Result is double) { int streamId = System.Convert.ToInt32((double)call.Result); #if !SILVERLIGHT if (log.IsDebugEnabled) { log.Debug(string.Format("Stream id: {0}", streamId)); } #endif //NetStreamInternal stream = new NetStreamInternal(_stream); _stream.Connection = _connection; _stream.StreamId = streamId; _connection.AddClientStream(_stream); _stream._outputStream = _connection.CreateOutputStream(streamId); _stream._connectionConsumer = new ConnectionConsumer(_connection, _stream._outputStream.Video.ChannelId, _stream._outputStream.Audio.ChannelId, _stream._outputStream.Data.ChannelId); } _callback.ResultReceived(call); }
/// <summary> /// Register pending receive (remote function receive to come). /// </summary> /// <param name="invokeId">Deferred operation id.</param> /// <param name="call">Call service.</param> internal void RegisterPendingReceive(IPendingServiceCall call) { _pendingReceive = call; }
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 OnInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, Notify invoke) { IServiceCall call = invoke.ServiceCall; if (invoke.EventType == EventType.STREAM_DATA) { #if !SILVERLIGHT if (Log.IsDebugEnabled) { Log.Debug(string.Format("Ignoring stream data notify with header {0}", header)); } #endif return; } if (call.ServiceMethodName == "_result" || call.ServiceMethodName == "_error") { if (call.ServiceMethodName == "_error") { call.Status = Messaging.Rtmp.Service.Call.STATUS_INVOCATION_EXCEPTION; } if (call.ServiceMethodName == "_result") { call.Status = Messaging.Rtmp.Service.Call.STATUS_SUCCESS_RESULT; } //Get the panding call, if any, as HandlePendingCallResult will remove it IPendingServiceCall pendingCall = connection.GetPendingCall(invoke.InvokeId); HandlePendingCallResult(connection, invoke); if (call.IsSuccess && invoke.InvokeId == 1) { // Should keep this as an Object to stay compatible with FMS3 etc IDictionary aso = call.Arguments[0] as IDictionary; if (aso != null) { object clientId = null; if (aso.Contains("clientid")) { clientId = aso["clientid"]; } #if !SILVERLIGHT if (Log.IsDebugEnabled) { Log.Debug(string.Format("Client id: {0}", clientId)); } #endif _netConnection.SetClientId(clientId != null ? clientId.ToString() : null); } } //Notify via NetConnection if no IPendingServiceCallback was defined but the call failed if (call.ServiceMethodName == "_error") { object[] args = call.Arguments; ASObject statusAso = null; if ((args != null) && (args.Length > 0)) { statusAso = args[0] as ASObject; } bool raiseError = false; if (pendingCall != null) { IPendingServiceCallback[] callbacks = pendingCall.GetCallbacks(); if (callbacks == null || callbacks.Length == 0) { raiseError = true; } } else { raiseError = true; } if (raiseError) { if (statusAso != null) { _netConnection.RaiseNetStatus(statusAso); } else { string msg = __Res.GetString(__Res.Invocation_Failed, pendingCall != null ? pendingCall.ServiceMethodName : string.Empty, "Invocation failed"); _netConnection.RaiseNetStatus(msg); } } } return; } bool onStatus = call.ServiceMethodName.Equals("onStatus") || call.ServiceMethodName.Equals("onMetaData") || call.ServiceMethodName.Equals("onPlayStatus"); if (onStatus) { /* * IDictionary aso = call.Arguments[0] as IDictionary; * // Should keep this as an Object to stay compatible with FMS3 etc * object clientId = null; * if( aso.Contains("clientid") ) * clientId = aso["clientid"]; * if (clientId == null) * clientId = header.StreamId; #if !SILVERLIGHT * if (log.IsDebugEnabled) * log.Debug(string.Format("Client id: {0}", clientId)); #endif * if (clientId != null) * { * NetStream stream = _connection.GetStreamById((int)clientId) as NetStream; * if (stream != null) * { * stream.OnStreamEvent(invoke); * } * } */ NetStream stream = _connection.GetStreamById(header.StreamId) as NetStream; if (stream != null) { stream.OnStreamEvent(invoke); } return; } if (call is IPendingServiceCall) { IPendingServiceCall psc = call as IPendingServiceCall; /* * object result = psc.Result; * object result = psc.Result; * if (result is DeferredResult) * { * DeferredResult dr = result as DeferredResult; * dr.InvokeId = invoke.InvokeId; * dr.ServiceCall = psc; * dr.Channel = channel; * connection.RegisterDeferredResult(dr); * } * else * { * Invoke reply = new Invoke(); * reply.ServiceCall = call; * reply.InvokeId = invoke.InvokeId; * channel.Write(reply); * } */ MethodInfo mi = MethodHandler.GetMethod(_netConnection.Client.GetType(), call.ServiceMethodName, call.Arguments, false, false); if (mi != null) { ParameterInfo[] parameterInfos = mi.GetParameters(); object[] args = new object[parameterInfos.Length]; call.Arguments.CopyTo(args, 0); TypeHelper.NarrowValues(args, parameterInfos); try { InvocationHandler invocationHandler = new InvocationHandler(mi); object result = invocationHandler.Invoke(_netConnection.Client, args); if (mi.ReturnType == typeof(void)) { call.Status = Messaging.Rtmp.Service.Call.STATUS_SUCCESS_VOID; } else { call.Status = result == null ? Messaging.Rtmp.Service.Call.STATUS_SUCCESS_NULL : Messaging.Rtmp.Service.Call.STATUS_SUCCESS_RESULT; psc.Result = result; } } catch (Exception exception) { call.Exception = exception; call.Status = Messaging.Rtmp.Service.Call.STATUS_INVOCATION_EXCEPTION; //log.Error("Error while invoking method " + call.ServiceMethodName + " on client", exception); } } else// if (!onStatus) { string msg = __Res.GetString(__Res.Invocation_NoSuitableMethod, call.ServiceMethodName); call.Status = Messaging.Rtmp.Service.Call.STATUS_METHOD_NOT_FOUND; call.Exception = new FluorineException(msg); _netConnection.RaiseNetStatus(call.Exception); //log.Error(msg, call.Exception); } if (call.Status == Messaging.Rtmp.Service.Call.STATUS_SUCCESS_VOID || call.Status == Messaging.Rtmp.Service.Call.STATUS_SUCCESS_NULL) { #if !SILVERLIGHT if (Log.IsDebugEnabled) { Log.Debug("Method does not have return value, do not reply"); } #endif return; } Invoke reply = new Invoke(); reply.ServiceCall = call; reply.InvokeId = invoke.InvokeId; channel.Write(reply); } else { IPendingServiceCall pendingCall = connection.RetrievePendingCall(invoke.InvokeId); Unreferenced.Parameter(pendingCall); } }
public void ResultReceived(IPendingServiceCall call) { this.Result = call.Result; this.Signal.Set(); }
public void ResultReceived(IPendingServiceCall call) { this.Result = call.Result; }
/// <summary> /// Register pending call (remote function call that is yet to finish). /// </summary> /// <param name="invokeId">Deferred operation id.</param> /// <param name="call">Call service.</param> internal void RegisterPendingCall(int invokeId, IPendingServiceCall call) { _pendingCalls[invokeId] = call; }
public void ResultReceived(IPendingServiceCall call) { if (call.Result is double) { int streamId = System.Convert.ToInt32((double)call.Result); #if !SILVERLIGHT if (log.IsDebugEnabled) log.Debug(string.Format("Stream id: {0}", streamId)); #endif //NetStreamInternal stream = new NetStreamInternal(_stream); _stream.Connection = _connection; _stream.StreamId = streamId; _connection.AddClientStream(_stream); _stream._outputStream = _connection.CreateOutputStream(streamId); _stream._connectionConsumer = new ConnectionConsumer(_connection, _stream._outputStream.Video.ChannelId, _stream._outputStream.Audio.ChannelId, _stream._outputStream.Data.ChannelId); } _callback.ResultReceived(call); }
public void ResultReceived(IPendingServiceCall call) { OnAmf3Response(new Amf3ResponseEventArgs(call)); }
public Amf3ResponseEventArgs(IPendingServiceCall call) { Call = call; }
protected override void OnInvoke(RtmpConnection connection, RtmpChannel channel, RtmpHeader header, Notify invoke) { IServiceCall serviceCall = invoke.ServiceCall; if ((serviceCall.ServiceMethodName == "_result") || (serviceCall.ServiceMethodName == "_error")) { if (serviceCall.ServiceMethodName == "_error") { serviceCall.Status = 0x13; } if (serviceCall.ServiceMethodName == "_result") { serviceCall.Status = 2; } base.HandlePendingCallResult(connection, invoke); } else if (serviceCall is IPendingServiceCall) { IPendingServiceCall call2 = serviceCall as IPendingServiceCall; MethodInfo methodInfo = MethodHandler.GetMethod(this._netConnection.Client.GetType(), serviceCall.ServiceMethodName, serviceCall.Arguments, false, false); if (methodInfo != null) { ParameterInfo[] parameters = methodInfo.GetParameters(); object[] array = new object[parameters.Length]; serviceCall.Arguments.CopyTo(array, 0); TypeHelper.NarrowValues(array, parameters); try { object obj2 = new InvocationHandler(methodInfo).Invoke(this._netConnection.Client, array); if (methodInfo.ReturnType == typeof(void)) { serviceCall.Status = 4; } else { serviceCall.Status = (obj2 == null) ? ((byte)3) : ((byte)2); call2.Result = obj2; } } catch (Exception exception) { serviceCall.Exception = exception; serviceCall.Status = 0x13; } } else { string message = __Res.GetString("Invocation_NoSuitableMethod", new object[] { serviceCall.ServiceMethodName }); serviceCall.Status = 0x11; serviceCall.Exception = new FluorineException(message); } if ((serviceCall.Status == 4) || (serviceCall.Status == 3)) { if (log.get_IsDebugEnabled()) { log.Debug("Method does not have return value, do not reply"); } } else { FluorineFx.Messaging.Rtmp.Event.Invoke invoke2 = new FluorineFx.Messaging.Rtmp.Event.Invoke { ServiceCall = serviceCall, InvokeId = invoke.InvokeId }; channel.Write(invoke2); } } }
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); }
public void ResultReceived(IPendingServiceCall call) { object result = call.Result; }