1 |
|
2 |
|
3 |
|
4 | export function augmentWebsocket(webSocket, debug) {
|
5 | webSocket.terminate = function () {
|
6 | const noOp = () => { };
|
7 |
|
8 | this.onerror = noOp;
|
9 | this.onmessage = noOp;
|
10 | this.onopen = noOp;
|
11 | const ts = new Date();
|
12 | const id = Math.random().toString().substring(2, 8);
|
13 | const origOnClose = this.onclose;
|
14 |
|
15 | this.onclose = closeEvent => {
|
16 | const delay = new Date().getTime() - ts.getTime();
|
17 | debug(`Discarded socket (#${id}) closed after ${delay}ms, with code/reason: ${closeEvent.code}/${closeEvent.reason}`);
|
18 | };
|
19 | this.close();
|
20 | origOnClose?.call(webSocket, {
|
21 | code: 4001,
|
22 | reason: `Quick discarding socket (#${id}) without waiting for the shutdown sequence.`,
|
23 | wasClean: false,
|
24 | });
|
25 | };
|
26 | }
|
27 |
|
\ | No newline at end of file |