コード例 #1
0
ファイル: RTMPSClient.cs プロジェクト: Gabrola/LolService
 public Notify Invoke(object msg)
 {
     var inv = new FlexInvoke();
     inv.EventType = (EventType)2;
     inv.ServiceCall = new PendingCall(null, new[] { msg });
     return Call(inv);
 }
コード例 #2
0
ファイル: RtmpHandler.cs プロジェクト: apakian/fluorinefx
        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);
			}
		}
コード例 #3
0
		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;
		}
コード例 #4
0
ファイル: BaseRtmpHandler.cs プロジェクト: apakian/fluorinefx
        internal static void Push(RtmpConnection connection, IMessage message, IMessageClient messageClient)
        {
            if (connection != null)
            {
                object response = message;
                if (message is BinaryMessage)
                {
                    BinaryMessage binaryMessage = message as BinaryMessage;
                    binaryMessage.Update(messageClient);
                    byte[] binaryContent = binaryMessage.body as byte[];
                    //byte[] destClientBinaryId = messageClient.GetBinaryId();
                    //Array.Copy(destClientBinaryId, 0, binaryContent, binaryMessage.PatternPosition, destClientBinaryId.Length);

                    RawBinary result = new RawBinary(binaryContent);
                    response = result;
                }
                else
                {
                    //This should be a clone of the original message
                    message.SetHeader(MessageBase.DestinationClientIdHeader, messageClient.ClientId);
                    message.clientId = messageClient.ClientId;
                }

                RtmpChannel channel = connection.GetChannel(3);
                FlexInvoke reply = new FlexInvoke();
                Call call = new Call("receive", new object[] { response });
                reply.ServiceCall = call;
                //reply.Cmd = "receive";
                //reply.Response = response;
                reply.InvokeId = connection.InvokeId;
                channel.Write(reply);
            }
        }
コード例 #5
0
ファイル: BaseRtmpHandler.cs プロジェクト: apakian/fluorinefx
 /// <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);
コード例 #6
0
		static FlexInvoke DecodeFlexInvoke(ByteBuffer stream)
		{
			int version = stream.ReadByte();
			RtmpReader reader = new RtmpReader(stream);
            string action = reader.ReadData() as string;
			int invokeId = System.Convert.ToInt32(reader.ReadData());
			object cmdData = reader.ReadData();

            object[] parameters = Call.EmptyArguments;
            if (stream.HasRemaining)
            {
#if !(NET_1_1)
                List<object> paramList = new List<object>();
#else
            ArrayList paramList = new ArrayList();
#endif
                while (stream.HasRemaining)
                {
                    object obj = reader.ReadData();
                    paramList.Add(obj);
                }
                parameters = paramList.ToArray();
            }
            /*
            int dotIndex = action == null ? -1 : action.LastIndexOf(".");
            string serviceName = (action == -1) ? null : action.Substring(0, dotIndex);
            string serviceMethod = (dotIndex == -1) ? action : action.Substring(dotIndex + 1, action.Length - dotIndex - 1);
            */
            PendingCall call = new PendingCall(null, action, parameters);
            FlexInvoke invoke = new FlexInvoke(invokeId, cmdData);
            invoke.ServiceCall = call;
			return invoke;
		}
コード例 #7
0
 /// <summary>
 /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
 /// </summary>
 public override void Timeout()
 {
     if (!IsClosed)
     {
         if (this.IsFlexClient)
         {
             FlexInvoke flexInvoke = new FlexInvoke();
             StatusASO statusASO = new StatusASO(StatusASO.NC_CONNECT_CLOSED, StatusASO.STATUS, "Connection Timed Out", null, this.ObjectEncoding);
             Call call = new Call("onstatus", new object[] { statusASO });
             flexInvoke.ServiceCall = call;
             //flexInvoke.Cmd = "onstatus";
             //flexInvoke.Parameters = new object[] { statusASO };
             RtmpChannel channel = this.GetChannel(3);
             channel.Write(flexInvoke);
         }
         else
         {
             StatusASO statusASO = new StatusASO(StatusASO.NC_CONNECT_CLOSED, StatusASO.ERROR, "Connection Timed Out", null, this.ObjectEncoding);
             RtmpChannel channel = this.GetChannel(3);
             channel.SendStatus(statusASO);
         }
     }
 }