public void Close() { Debug.Log("[UnityWebSocket] Closing web socket connection."); #if UNITY_EDITOR || UNITY_STANDALONE if (WebSocket == null) { return; } WebSocket.CloseAsync(); WebSocket.OnOpen -= WebSocket_OnOpen; WebSocket.OnMessage -= WebSocket_OnMessage; WebSocket.OnError -= WebSocket_OnError; WebSocket.OnClose -= WebSocket_OnClose; WebSocket = null; #elif UNITY_WEBGL if (NativeWebSocket == null) { return; } NativeWebSocket.CloseAsync(); NativeWebSocket.SetOnOpen(null); NativeWebSocket.SetOnMessage(null); NativeWebSocket.SetOnError(null); NativeWebSocket.SetOnClose(null); NativeWebSocket = null; #endif }
public BrainCloudWebSocket(string url) { #if DOT_NET #elif UNITY_WEBGL && !UNITY_EDITOR NativeWebSocket = new NativeWebSocket(url); NativeWebSocket.SetOnOpen(NativeSocket_OnOpen); NativeWebSocket.SetOnMessage(NativeSocket_OnMessage); NativeWebSocket.SetOnError(NativeSocket_OnError); NativeWebSocket.SetOnClose(NativeSocket_OnClose); webSocketInstances.Add(NativeWebSocket.Id, this); #else WebSocket = new WebSocket(url); WebSocket.ConnectAsync(); WebSocket.OnOpen += WebSocket_OnOpen; WebSocket.OnMessage += WebSocket_OnMessage; WebSocket.OnError += WebSocket_OnError; WebSocket.OnClose += WebSocket_OnClose; #endif }
public UnityWebSocket(string url) { Debug.Log("[UnityWebSocket] Instantiating new websocket: " + url); #if UNITY_EDITOR || UNITY_STANDALONE WebSocket = new WebSocket(url); WebSocket.ConnectAsync(); WebSocket.AcceptAsync(); WebSocket.OnOpen += WebSocket_OnOpen; WebSocket.OnMessage += WebSocket_OnMessage; WebSocket.OnError += WebSocket_OnError; WebSocket.OnClose += WebSocket_OnClose; #elif UNITY_WEBGL NativeWebSocket = new NativeWebSocket(url); NativeWebSocket.SetOnOpen(NativeSocket_OnOpen); NativeWebSocket.SetOnMessage(NativeSocket_OnMessage); NativeWebSocket.SetOnError(NativeSocket_OnError); NativeWebSocket.SetOnClose(NativeSocket_OnClose); webSocketInstances.Add(NativeWebSocket.Id, this); #endif }