Ejemplo n.º 1
0
        private (string, object[]) ReadData(SocketManager manager, IncomingPacket packet, string payload)
        {
            Socket socket = manager.GetSocket(packet.Namespace);

            string       eventName    = packet.EventName;
            Subscription subscription = socket.GetSubscription(eventName);

            object[] args = null;

            switch (packet.SocketIOEvent)
            {
            case SocketIOEventTypes.Unknown:
                // TODO: Error?
                break;

            case SocketIOEventTypes.Connect:
                // No Data | Object
                args = ReadParameters(socket, subscription, new System.IO.StringReader(payload));
                break;

            case SocketIOEventTypes.Disconnect:
                // No Data
                break;

            case SocketIOEventTypes.Error:
                // String | Object
                switch (payload[0])
                {
                case '{':
                    args = ReadParameters(socket, subscription, new System.IO.StringReader(payload));
                    break;

                default:
                    args = new object[] { new Error(payload) };
                    break;
                }
                break;

            case SocketIOEventTypes.Ack:
                eventName    = IncomingPacket.GenerateAcknowledgementNameFromId(packet.Id);
                subscription = socket.GetSubscription(eventName);

                args = ReadParameters(socket, subscription, JSON.LitJson.JsonMapper.ToObject <List <object> >(payload), 0);

                break;

            default:
                // Array

                var reader = new System.IO.StringReader(payload);
                var array  = JSON.LitJson.JsonMapper.ToObject <List <object> >(new JSON.LitJson.JsonReader(reader));
                if (array.Count > 0)
                {
                    eventName    = array[0].ToString();
                    subscription = socket.GetSubscription(eventName);
                }

                if (packet.AttachementCount == 0 || packet.Attachements != null)
                {
                    args = ReadParameters(socket, subscription, array, 1);
                }

                break;
            }

            return(eventName, args);
        }
Ejemplo n.º 2
0
        private (string, object[]) ReadData(SocketManager manager, IncomingPacket packet, IJsonReader reader)
        {
            Socket socket = manager.GetSocket(packet.Namespace);

            string       eventName    = packet.EventName;
            Subscription subscription = socket.GetSubscription(eventName);

            object[] args = null;

            switch (packet.SocketIOEvent)
            {
            case SocketIOEventTypes.Unknown:
                // TODO: Error?
                break;

            case SocketIOEventTypes.Connect:
                // No Data | Object
                args = ReadParameters(socket, subscription, reader);
                //SkipObject(reader);
                break;

            case SocketIOEventTypes.Disconnect:
                // No Data
                break;

            case SocketIOEventTypes.Error:
                // String | Object
                switch (reader.Token)
                {
                case JsonToken.StringLiteral:
                    args = new object[] { new Error(reader.ReadString()) };
                    break;

                case JsonToken.BeginObject:
                    args = ReadParameters(socket, subscription, reader);
                    if (subscription == null && args == null)
                    {
                        SkipObject(reader);
                    }
                    break;
                }
                break;

            case SocketIOEventTypes.Ack:
                eventName    = IncomingPacket.GenerateAcknowledgementNameFromId(packet.Id);
                subscription = socket.GetSubscription(eventName);

                reader.ReadArrayBegin();

                args = ReadParameters(socket, subscription, reader);

                reader.ReadArrayEnd();
                break;

            default:
                // Array
                reader.ReadArrayBegin();
                eventName = reader.ReadString();

                subscription = socket.GetSubscription(eventName);

                args = ReadParameters(socket, subscription, reader);

                reader.ReadArrayEnd();
                break;
            }

            return(eventName, args);
        }