forked from stomp-js/stompjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaugment-websocket.js
More file actions
27 lines (27 loc) · 1003 Bytes
/
augment-websocket.js
File metadata and controls
27 lines (27 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* @internal
*/
export function augmentWebsocket(webSocket, debug) {
webSocket.terminate = function () {
const noOp = () => { };
// set all callbacks to no op
this.onerror = noOp;
this.onmessage = noOp;
this.onopen = noOp;
const ts = new Date();
const id = Math.random().toString().substring(2, 8); // A simulated id
const origOnClose = this.onclose;
// Track delay in actual closure of the socket
this.onclose = closeEvent => {
const delay = new Date().getTime() - ts.getTime();
debug(`Discarded socket (#${id}) closed after ${delay}ms, with code/reason: ${closeEvent.code}/${closeEvent.reason}`);
};
this.close();
origOnClose?.call(webSocket, {
code: 4001,
reason: `Quick discarding socket (#${id}) without waiting for the shutdown sequence.`,
wasClean: false,
});
};
}
//# sourceMappingURL=augment-websocket.js.map