Example #1
0
 /// <summary>
 /// Removes all callbacks to the given event.
 /// </summary>
 public void Off(SocketIOEventTypes type)
 {
     Off(EventNames.GetNameFor(type));
 }
Example #2
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
        {
            string eventName = EventNames.GetNameFor(type);

            EventCallbacks.Register(eventName, callback, false, autoDecodePayload);
        }
Example #3
0
 public void Once(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
 {
     EventCallbacks.Register(EventNames.GetNameFor(type), callback, true, autoDecodePayload);
 }
 /// <summary>
 /// Internal constructor. Don't use it directly!
 /// </summary>
 internal Packet(TransportEventTypes transportEvent, SocketIOEventTypes packetType, string nsp, string payload, int attachment = 0, int id = 0)
 {
     this.TransportEvent = transportEvent;
     this.SocketIOEvent = packetType;
     this.Namespace = nsp;
     this.Payload = payload;
     this.AttachmentCount = attachment;
     this.Id = id;
 }
 public static string GetNameFor(SocketIOEventTypes type)
 {
     return SocketIONames[(int)type + 1];
 }
Example #6
0
        public OutgoingPacket CreateOutgoing(Socket socket, SocketIOEventTypes socketIOEvent, int id, string name, object[] args)
        {
            builder.Length = 0;
            List <byte[]> attachements = null;

            switch (socketIOEvent)
            {
            case SocketIOEventTypes.Ack:
                if (GetBinaryCount(args) > 0)
                {
                    attachements  = CreatePlaceholders(args);
                    socketIOEvent = SocketIOEventTypes.BinaryAck;
                }
                break;

            case SocketIOEventTypes.Event:
                if (GetBinaryCount(args) > 0)
                {
                    attachements  = CreatePlaceholders(args);
                    socketIOEvent = SocketIOEventTypes.BinaryEvent;
                }
                break;
            }

            builder.Append(((int)TransportEventTypes.Message).ToString());
            builder.Append(((int)socketIOEvent).ToString());

            if (socketIOEvent == SocketIOEventTypes.BinaryEvent || socketIOEvent == SocketIOEventTypes.BinaryAck)
            {
                builder.Append(attachements.Count.ToString());
                builder.Append("-");
            }

            // Add the namespace. If there is any other then the root nsp ("/")
            // then we have to add a trailing "," if we have more data.
            bool nspAdded = false;

            if (socket.Namespace != "/")
            {
                builder.Append(socket.Namespace);
                nspAdded = true;
            }

            // ack id, if any
            if (id >= 0)
            {
                if (nspAdded)
                {
                    builder.Append(",");
                    nspAdded = false;
                }

                builder.Append(id.ToString());
            }

            // payload
            switch (socketIOEvent)
            {
            case SocketIOEventTypes.Connect:
                // No Data | Object
                if (args != null && args.Length > 0)
                {
                    if (nspAdded)
                    {
                        builder.Append(",");
                    }

                    builder.Append(BestHTTP.JSON.LitJson.JsonMapper.ToJson(args[0]));
                }
                break;

            case SocketIOEventTypes.Disconnect:
                // No Data
                break;

            case SocketIOEventTypes.Error:
                // String | Object
                if (args != null && args.Length > 0)
                {
                    if (nspAdded)
                    {
                        builder.Append(",");
                    }

                    builder.Append(BestHTTP.JSON.LitJson.JsonMapper.ToJson(args[0]));
                }
                break;

            case SocketIOEventTypes.Ack:
            case SocketIOEventTypes.BinaryAck:
                if (args != null && args.Length > 0)
                {
                    var argsJson = JSON.LitJson.JsonMapper.ToJson(args);
                    builder.Append(argsJson);
                }
                else
                {
                    builder.Append("[]");
                }
                break;

            default:
                // Array
                builder.Append('[');
                if (!string.IsNullOrEmpty(name))
                {
                    builder.Append('\"');
                    builder.Append(name);
                    builder.Append('\"');
                }

                if (args != null && args.Length > 0)
                {
                    builder.Append(',');
                    var argsJson = JSON.LitJson.JsonMapper.ToJson(args);
                    builder.Append(argsJson, 1, argsJson.Length - 2);
                }

                builder.Append(']');
                break;
            }

            return(new OutgoingPacket {
                Payload = builder.ToString(), Attachements = attachements
            });
        }
Example #7
0
 /// <summary>
 /// Remove the specified callback.
 /// </summary>
 public void Off(SocketIOEventTypes type, SocketIOCallback callback)
 {
     EventCallbacks.Unregister(EventNames.GetNameFor(type), callback);
 }
Example #8
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
        {
            string eventName = EventNames.GetNameFor(type);

            EventCallbacks.Register(eventName, callback, false, autoDecodePayload);
        }
Example #9
0
 public void Once(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
 {
     EventCallbacks.Register(EventNames.GetNameFor(type), callback, true, autoDecodePayload);
 }
Example #10
0
 public static string GetNameFor(SocketIOEventTypes type)
 {
     return(SocketIONames[(int)type + 1]);
 }
Example #11
0
 /// <summary>
 /// Emits an internal packet-less event to the root namespace without creating it if it isn't exists yet.
 /// </summary>
 void IManager.EmitEvent(SocketIOEventTypes type, params object[] args)
 {
     (this as IManager).EmitEvent(EventNames.GetNameFor(type), args);
 }
Example #12
0
 public static string GetNameFor(SocketIOEventTypes type) =>
 SocketIONames[((int)type) + 1];
Example #13
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback)
        {
            string nameFor = EventNames.GetNameFor(type);

            this.EventCallbacks.Register(nameFor, callback, false, this.AutoDecodePayload);
        }
Example #14
0
 void ISocket.EmitEvent(SocketIOEventTypes type, params object[] args)
 {
     ((ISocket)this).EmitEvent(EventNames.GetNameFor(type), args);
 }
Example #15
0
 /// <summary>
 /// Remove the specified callback.
 /// </summary>
 public void Off(SocketIOEventTypes type, SocketIOCallback callback)
 {
     EventCallbacks.Unregister(EventNames.GetNameFor(type), callback);
 }
Example #16
0
 /// <summary>
 /// Removes all callbacks to the given event.
 /// </summary>
 public void Off(SocketIOEventTypes type)
 {
     Off(EventNames.GetNameFor(type));
 }
Example #17
0
 /// <summary>
 /// Emits an internal packet-less event to the user level.
 /// </summary>
 void ISocket.EmitEvent(SocketIOEventTypes type, params object[] args)
 {
     (this as ISocket).EmitEvent(EventNames.GetNameFor(type), args);
 }
Example #18
0
 public OutgoingPacket CreateOutgoing(Socket socket, SocketIOEventTypes socketIOEvent, int id, string name, object arg)
 {
     return(CreateOutgoing(socket, socketIOEvent, id, name, arg != null ? new object[] { arg } : null));
 }