Fixed a race condition when attaching to an existing socket

This is an error that presents itself with RTCDataChannel's, I suspect this could not
happen with a pre-existing WebSocket.

If the remote connection creates a data channel then the local (VNC) side gets a channel
created callback. It may also be the case that in that very same tick the socket is also
opened and buffered data received. This meant that (in my tests) about 1/3 of the time
noVNC would fail to respond to the initial message from the server because it was received
and subsequently not handled during that initial tick.

Also made the documentation reflect this new behaviour and document the existing behaviour.
This commit is contained in:
Tim Stableford
2021-03-23 12:58:49 +00:00
parent 89f9ac0016
commit ef27628c6d
2 changed files with 16 additions and 2 deletions

View File

@@ -168,6 +168,11 @@ connection to a specified VNC server.
**`urlOrDataChannel`**
- A `DOMString` specifying the VNC server to connect to. This must be
a valid WebSocket URL. This can also be a `WebSocket` or `RTCDataChannel`.
If a `DOMString` is supplied then the connection will be delayed until the next tick to
allow allow adding event listeners that fire on connection. If an existing object
is supplied then the connection logic happens the same tick. For instance if passing
in an existing open WebSocket then it will not be possible to listen for the `connect`
event. This is to avoid dropping data on a connection that has data as soon as its opened.
**`options`** *Optional*
- An `Object` specifying extra details about how the connection