-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitchSubPub.js
More file actions
23 lines (18 loc) · 682 Bytes
/
twitchSubPub.js
File metadata and controls
23 lines (18 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// wss://pubsub-edge.twitch.tv
const WebSocket = require('ws');
const ws = new WebSocket('wss://pubsub-edge.twitch.tv');
function heartbeat() {
clearTimeout(this.pingTimeout);
// Use `WebSocket#terminate()`, which immediately destroys the connection,
// instead of `WebSocket#close()`, which waits for the close timer.
// Delay should be equal to the interval at which your server
// sends out pings plus a conservative assumption of the latency.
this.pingTimeout = setTimeout(() => {
this.terminate();
}, 30000 + 1000);
}
client.on('open', heartbeat);
client.on('ping', heartbeat);
client.on('close', function clear() {
clearTimeout(this.pingTimeout);
});