Esempio n. 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;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Receives json : {socketId: (INT), message: (STRING)}
        /// </summary>
        /// <param name="socketId">Socket identifier.</param>
        /// <param name="message">Message.</param>
        public void GSSocketOnError(string data)
        {
            IDictionary <string, object> parsedJSON = (IDictionary <string, object>)GSJson.From(data);
            int    socketId             = System.Convert.ToInt32(parsedJSON["socketId"]);
            string error                = (string)parsedJSON["error"];
            IControlledWebSocket socket = GetSocket(socketId);

            if (socket != null)
            {
                socket.TriggerOnError(error);
            }
        }