/// <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; } }
/// <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(); } }