mirror of
https://github.com/paricafe/misskey.git
synced 2025-02-17 13:37:29 -06:00
fix(frontend): eventListener leak
This commit is contained in:
parent
3f84e03bcb
commit
c8c0196123
1 changed files with 7 additions and 2 deletions
|
@ -68,14 +68,19 @@ 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue