more stable ws stream #7

Merged
yume merged 2 commits from pick/pari-ws-stability into develop 2024-11-10 00:21:07 -06:00
Showing only changes of commit 997c5b3d35 - Show all commits

View file

@ -68,14 +68,20 @@ export function useStream(): Misskey.IStream {
if (timeoutHeartBeat) window.clearTimeout(timeoutHeartBeat);
timeoutHeartBeat = window.setTimeout(heartbeat, HEART_BEAT_INTERVAL);
// send heartbeat right now when last send time is over HEART_BEAT_INTERVAL
document.addEventListener('visibilitychange', () => {
const target = () => {
if (
!stream
|| document.visibilityState !== 'visible'
|| Date.now() - lastHeartbeatCall < HEART_BEAT_INTERVAL
) return;
heartbeat();
};
// send heartbeat right now when last send time is over HEART_BEAT_INTERVAL
document.addEventListener('visibilitychange', target);
stream.on('_disconnected_', () => {
document.removeEventListener('visibilitychange', target);
});
return stream;