public void SendAsync(byte[] data, Action completed = null) { #if UNITY_EDITOR _socket.SendAsync(data, () => { UnityWebSocketDebuger.Send(this, data); if (completed != null) { lock (sendCallbackQueue) { sendCallbackQueue.Enqueue(completed); } } }); #else if (completed != null) { _socket.SendAsync(data, () => { lock (sendCallbackQueue) { sendCallbackQueue.Enqueue(completed); } }); } else { _socket.SendAsync(data); } #endif }
public WebSocket() { _socket = new Uniform.WebSocket(); _socket.OnOpen += (o, e) => { lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); } }; _socket.OnClose += (o, e) => { lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); } }; _socket.OnError += (o, e) => { lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); } }; _socket.OnMessage += (o, e) => { lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); } }; UnityWebSocketManager.Instance.Add(this); #if UNITY_EDITOR UnityWebSocketDebuger.Create(this); #endif }