Skip to content

Commit 9d56b5f

Browse files
AlexeyDeepak Kumar
authored andcommitted
Fix: Handle race condition when WebSocket is already open
1 parent dfae8df commit 9d56b5f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/stomp-handler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class StompHandler {
195195
this.onWebSocketError(errorEvent);
196196
};
197197

198-
this._webSocket.onopen = () => {
198+
const onOpen = () => {
199199
// Clone before updating
200200
const connectHeaders = (Object as any).assign({}, this.connectHeaders);
201201

@@ -207,6 +207,12 @@ export class StompHandler {
207207
].join(',');
208208
this._transmit({ command: 'CONNECT', headers: connectHeaders });
209209
};
210+
211+
if (this._webSocket.readyState === StompSocketState.OPEN) {
212+
onOpen();
213+
} else {
214+
this._webSocket.onopen = onOpen;
215+
}
210216
}
211217

212218
private readonly _serverFrameHandlers: {

0 commit comments

Comments
 (0)