public void Close() { #if DOT_NET if (ClientWebSocket == null) { return; } ClientWebSocket.CloseAsync(WebSocketCloseStatus.Empty, null, CancellationToken.None); ClientWebSocket = null; #elif UNITY_WEBGL && !UNITY_EDITOR if (NativeWebSocket == null) { return; } webSocketInstances.Remove(NativeWebSocket.Id); NativeWebSocket.CloseAsync(); NativeWebSocket = null; #else if (WebSocket == null) { return; } WebSocket.CloseAsync(); WebSocket.OnOpen -= WebSocket_OnOpen; WebSocket.OnMessage -= WebSocket_OnMessage; WebSocket.OnError -= WebSocket_OnError; WebSocket.OnClose -= WebSocket_OnClose; WebSocket = 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 BrainCloud.UnityWebSocketsForWebGL.WebSocketSharp.WebSocket(url); WebSocket.ConnectAsync(); WebSocket.OnOpen += WebSocket_OnOpen; WebSocket.OnMessage += WebSocket_OnMessage; WebSocket.OnError += WebSocket_OnError; WebSocket.OnClose += WebSocket_OnClose; #endif }
public void Close() { #if DOT_NET #elif UNITY_WEBGL && !UNITY_EDITOR if (NativeWebSocket == null) { return; } webSocketInstances.Remove(NativeWebSocket.Id); NativeWebSocket.CloseAsync(); NativeWebSocket = null; #else if (WebSocket == null) { return; } WebSocket.CloseAsync(); WebSocket.OnOpen -= WebSocket_OnOpen; WebSocket.OnMessage -= WebSocket_OnMessage; WebSocket.OnError -= WebSocket_OnError; WebSocket.OnClose -= WebSocket_OnClose; WebSocket = null; #endif }