Example #1
0
        /// <summary>
        /// Used for WebGL Exports. This is called by Javascript to inject server-to-client communication into Unity.
        /// </summary>
        public void ServerToClient(string jsonData)
        {
            var parsedJSON = GSJson.From(jsonData) as IDictionary <string, object>;

            int socketId = int.Parse(parsedJSON["socketId"].ToString());

            IControlledWebSocket socket = GetSocket(socketId);

            if (socket == null)
            {
                return;
            }

            string functionName = parsedJSON["functionName"].ToString();


            switch (functionName)
            {
            case "onError": socket.TriggerOnError(parsedJSON["data"].ToString()); break;

            case "onMessage": socket.TriggerOnMessage(parsedJSON["data"].ToString()); break;

            case "onOpen": socket.TriggerOnOpen(); break;

            case "onClose": socket.TriggerOnClose(); break;
            }
        }
Example #2
0
        /// <summary>
        /// Receives json : {socketId: (INT)}
        /// </summary>
        /// <param name="data">Data.</param>
        public void GSSocketOnClose(string data)
        {
            IDictionary <string, object> parsedJSON = (IDictionary <string, object>)GSJson.From(data);
            int socketId = System.Convert.ToInt32(parsedJSON["socketId"]);
            IControlledWebSocket socket = GetSocket(socketId);

            if (socket != null)
            {
                socket.TriggerOnClose();
            }
        }
Example #3
0
        /// <summary>
        /// Receives json : {socketId: (INT)}
        /// </summary>
        public void GSSocketOnOpen(string data)
        {
            IDictionary <string, object> parsedJSON = (IDictionary <string, object>)GSJson.From(data);

            if (parsedJSON == null)
            {
                throw new FormatException("parsed json was null. ");
            }
            if (!parsedJSON.ContainsKey("socketId"))
            {
                throw new FormatException();
            }

            int socketId = System.Convert.ToInt32(parsedJSON ["socketId"]);
            IControlledWebSocket socket = GetSocket(socketId);

            if (socket != null)
            {
                socket.TriggerOnOpen();
            }
        }
 public void RemoveWebSocket(IControlledWebSocket socket)
 {
     webSockets.Remove(socket);
 }
 public void AddWebSocket(IControlledWebSocket socket)
 {
     webSockets.Add(socket);
 }
Example #6
0
 public void AddWebSocket(IControlledWebSocket socket)
 {
     webSockets.Add(socket);
     websocketCollectionModified = true;
 }
Example #7
0
 public void RemoveWebSocket(IControlledWebSocket socket)
 {
     webSockets.Remove(socket);
     websocketCollectionModified = true;
 }
Example #8
0
 public void RemoveWebSocket(IControlledWebSocket socket)
 {
     webSockets.Remove(socket);
     websocketCollectionModified = true;
 }
Example #9
0
 public void AddWebSocket(IControlledWebSocket socket)
 {
     webSockets.Add(socket);
     websocketCollectionModified = true;
 }
Example #10
0
 public void RemoveWebSocket(IControlledWebSocket socket)
 {
     webSockets.Remove(socket);
 }
Example #11
0
 public void AddWebSocket(IControlledWebSocket socket)
 {
     webSockets.Add(socket);
 }