summary refs log tree commit diff
path: root/gateway/src/util/Heartbeat.ts
blob: f6871cfe93a9c73ede0c9de01881a718e9df088d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
import { CLOSECODES } from "./Constants";
import { WebSocket } from "./WebSocket";

// TODO: make heartbeat timeout configurable
export function setHeartbeat(socket: WebSocket) {
	if (socket.heartbeatTimeout) clearTimeout(socket.heartbeatTimeout);

	socket.heartbeatTimeout = setTimeout(() => {
		return socket.close(CLOSECODES.Session_timed_out);
	}, 1000 * 45);
}