Exemplo 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;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Receives json : {socketId: (INT), message: (STRING)}
        /// </summary>
        /// <param name="data">Data.</param>
        public void GSSocketOnMessage(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.TriggerOnMessage((string)parsedJSON["message"]);
            }
        }