void onOpen() { receiveQueue.Enqueue(new Message(EventType.Connected)); state = ClientState.Connected; if (ConnectingSendQueue != null) { while (ConnectingSendQueue.Count > 0) { byte[] next = ConnectingSendQueue.Dequeue(); SimpleWebJSLib.Send(index, next, 0, next.Length); } ConnectingSendQueue = null; } }
public override void Send(ArraySegment <byte> segment) { if (segment.Count > maxMessageSize) { Log.Error($"Cant send message with length {segment.Count} because it is over the max size of {maxMessageSize}"); return; } if (state == ClientState.Connected) { SimpleWebJSLib.Send(index, segment.Array, segment.Offset, segment.Count); } else { if (ConnectingSendQueue == null) { ConnectingSendQueue = new Queue <byte[]>(); } ConnectingSendQueue.Enqueue(segment.ToArray()); } }
public override void Connect(Uri serverAddress) { index = SimpleWebJSLib.Connect(serverAddress.ToString(), OpenCallback, CloseCallBack, MessageCallback, ErrorCallback); instances.Add(index, this); state = ClientState.Connecting; }
public override void Disconnect() { state = ClientState.Disconnecting; // disconnect should cause closeCallback and OnDisconnect to be called SimpleWebJSLib.Disconnect(index); }
public bool CheckJsConnected() => SimpleWebJSLib.IsConnected(index);