Const
import { publicWsHeartbeat$ } from 'ts-kraken';
let lastHeartbeatTs = new Date().getTime();
publicWsHeartbeat$.subscribe(() => {
lastHeartbeatTs = new Date().getTime();
});
const maxSecondsWithoutHeartbeat = 30;
setInterval(() => {
const now = new Date().getTime();
const diff = Math.ceil((now - lastHeartbeatTs) / 1000);
if (diff >= maxSecondsWithoutHeartbeat) {
throw `Error: No heartbeat in the last ${diff} seconds`;
}
}, maxSecondsWithoutHeartbeat * 1000);
You can call
.subscribe()
on this RxJS Observable