-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hh-multimodel' into hh-appmacros
- Loading branch information
Showing
8 changed files
with
154 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
/* | ||
** keepalive.js // v1.0.0 // 6th January 2022 | ||
** keepalive.js // v1.1.0 // 11 November 2024 | ||
** Keeps alive the websocket connection by sending a ping every x seconds | ||
** where x = Genie.config.webchannels_keepalive_frequency | ||
*/ | ||
|
||
function keepalive() { | ||
if (window._lastMessageAt !== undefined) { | ||
if (Date.now() - window._lastMessageAt < Genie.Settings.webchannels_keepalive_frequency) { | ||
return | ||
function keepalive(WebChannel) { | ||
if (WebChannel.lastMessageAt !== undefined) { | ||
dt = Date.now() - WebChannel.lastMessageAt; | ||
// allow for a 200ms buffer | ||
if (dt + 200 < Genie.Settings.webchannels_keepalive_frequency) { | ||
keepaliveTimer(WebChannel, Genie.Settings.webchannels_keepalive_frequency - dt); | ||
return; | ||
} | ||
} | ||
|
||
if (Genie.Settings.env == 'dev') { | ||
console.info('Keeping connection alive'); | ||
if (!WebChannel.ws_disconnected) { | ||
if (Genie.Settings.env == 'dev') { | ||
console.info('Keeping connection alive'); | ||
} | ||
WebChannel.sendMessageTo(WebChannel.channel, 'keepalive', { | ||
'payload': {} | ||
}); | ||
} | ||
|
||
Genie.WebChannels.sendMessageTo(CHANNEL, 'keepalive', { | ||
'payload': {} | ||
}); | ||
} | ||
|
||
function keepaliveTimer(WebChannel, startDelay = Genie.Settings.webchannels_keepalive_frequency) { | ||
clearInterval(WebChannel.keepalive_interval); | ||
setTimeout(() => { | ||
keepalive(WebChannel); | ||
WebChannel.keepalive_interval = setInterval(() => keepalive(WebChannel), Genie.Settings.webchannels_keepalive_frequency); | ||
}, startDelay) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.