Exemplo n.º 1
0
        /// <summary>
        /// This function will get the eventName from the packet's Payload, and optionally will decode it from Json.
        /// </summary>
        public void Call(Packet packet)
        {
            string eventName = packet.DecodeEventName();
            string typeName  = packet.SocketIOEvent != SocketIOEventTypes.Unknown ? EventNames.GetNameFor(packet.SocketIOEvent) : EventNames.GetNameFor(packet.TransportEvent);

            object[] args = null;

            if (!HasSubsciber(eventName) && !HasSubsciber(typeName))
            {
                return;
            }

            // If this is an Event or BinaryEvent message, or we have a subscriber with AutoDecodePayload, then
            //  we have to decode the packet's Payload.
            if (packet.TransportEvent == TransportEventTypes.Message && (packet.SocketIOEvent == SocketIOEventTypes.Event || packet.SocketIOEvent == SocketIOEventTypes.BinaryEvent) && ShouldDecodePayload(eventName))
            {
                args = packet.Decode(Socket.Manager.Encoder);
            }

            // call event callbacks registered for 'eventName'
            if (!string.IsNullOrEmpty(eventName))
            {
                Call(eventName, packet, args);
            }

            if (!packet.IsDecoded && ShouldDecodePayload(typeName))
            {
                args = packet.Decode(Socket.Manager.Encoder);
            }

            // call event callbacks registered for 'typeName'
            if (!string.IsNullOrEmpty(typeName))
            {
                Call(typeName, packet, args);
            }
        }