Exemplo n.º 1
0
        /// <summary>
        /// <para>Asynchronously sends payload using eventName</para>
        /// <para>payload must a string or Json Serializable</para>
        /// <para>Mimicks Socket.IO client 'socket.emit('name',payload);' pattern</para>
        /// <para>Do not use the reserved socket.io event names: connect, disconnect, open, close, error, retry, reconnect</para>
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="payload">must be a string or a Json Serializable object</param>
        /// <remarks>ArgumentOutOfRangeException will be thrown on reserved event names</remarks>
        public void Emit(string eventName, dynamic payload, string endPoint = "", Action <dynamic> callback = null)
        {
            try
            {
                string   lceventName = eventName.ToLower();
                IMessage msg         = null;
                switch (lceventName)
                {
                case "message":
                    if (payload is string)
                    {
                        msg = new TextMessage()
                        {
                            MessageText = payload
                        }
                    }
                    ;
                    else
                    {
                        msg = new JSONMessage(payload);
                    }
                    this.Send(msg);
                    break;

                case "connect":
                case "disconnect":
                case "open":
                case "close":
                case "error":
                case "retry":
                case "reconnect":
                    throw new System.ArgumentOutOfRangeException(eventName, "Event name is reserved by socket.io, and cannot be used by clients or servers with this message type");

                default:
                    if (!string.IsNullOrWhiteSpace(endPoint) && !endPoint.StartsWith("/"))
                    {
                        endPoint = "/" + endPoint;
                    }
                    msg = new EventMessage(eventName, payload, endPoint, callback);
                    if (callback != null)
                    {
                        this.registrationManager.AddCallBack(msg);
                    }

                    this.Send(msg);
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Logger.LogException(ex);
            }
        }
 public void sendJSON(JSONMessage send)
 {
     sendString(JsonUtility.ToJson(send));
 }
Exemplo n.º 3
0
 void ShowEvent(JSONMessage eventMessage)
 {
     Debug.WriteLine("Received message id -> " + eventMessage.ID);
     _events.Insert(0, eventMessage);
     Bindings.Update();
 }