Don't fake open events in Websock

We don't know if the caller is prepared to receive those events right
now as normally they would get them on a fresh new stack later. We also
can't delay delivery since then we might deliver the event after any
pending "message" events.

Better to push the problem one layer up to the caller, which now needs
to be more aware of the state of the WebSocket object it is trying to
use.
This commit is contained in:
Pierre Ossman
2021-04-18 13:55:11 +02:00
parent 9376191fc4
commit de9fc9508c
4 changed files with 20 additions and 21 deletions

View File

@@ -247,7 +247,7 @@ export default class Websock {
this._websocket.binaryType = "arraybuffer";
this._websocket.onmessage = this._recvMessage.bind(this);
const onOpen = () => {
this._websocket.onopen = () => {
Log.Debug('>> WebSock.onopen');
if (this._websocket.protocol) {
Log.Info("Server choose sub-protocol: " + this._websocket.protocol);
@@ -257,12 +257,6 @@ export default class Websock {
Log.Debug("<< WebSock.onopen");
};
if (this.readyState === 'open') {
onOpen();
} else {
this._websocket.onopen = onOpen;
}
this._websocket.onclose = (e) => {
Log.Debug(">> WebSock.onclose");
this._eventHandlers.close(e);