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 origOnClose = this.onclose;
|
13 |
|
14 | this.onclose = closeEvent => {
|
15 | const delay = new Date().getTime() - ts.getTime();
|
16 | debug(`Discarded socket closed after ${delay}ms, with code/reason: ${closeEvent.code}/${closeEvent.reason}`);
|
17 | };
|
18 | this.close();
|
19 | origOnClose.call(this, {
|
20 | code: 4001,
|
21 | reason: 'Heartbeat failure, discarding the socket',
|
22 | wasClean: false,
|
23 | });
|
24 | };
|
25 | }
|
26 |
|
\ | No newline at end of file |