UNPKG

873 BJavaScriptView Raw
1/**
2 * @internal
3 */
4export function augmentWebsocket(webSocket, debug) {
5 webSocket.terminate = function () {
6 const noOp = () => { };
7 // set all callbacks to no op
8 this.onerror = noOp;
9 this.onmessage = noOp;
10 this.onopen = noOp;
11 const ts = new Date();
12 const origOnClose = this.onclose;
13 // Track delay in actual closure of the socket
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//# sourceMappingURL=augment-websocket.js.map
\No newline at end of file