Skip to content

Commit

Permalink
support keepalive for multi-model pages
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Nov 10, 2024
1 parent eac1690 commit b75ca84
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions assets/js/keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
** where x = Genie.config.webchannels_keepalive_frequency
*/

function keepalive() {
if (window._lastMessageAt !== undefined) {
if (Date.now() - window._lastMessageAt < Genie.Settings.webchannels_keepalive_frequency) {
function keepalive(WebChannel) {
if (WebChannel.lastMessageAt !== undefined) {
if (Date.now() - WebChannel.lastMessageAt + 200 < Genie.Settings.webchannels_keepalive_frequency) {
return
}
}

if (Genie.Settings.env == 'dev') {
console.info('Keeping connection alive');
console.log(WebChannel.parent.i)
}

Genie.WebChannels.sendMessageTo(CHANNEL, 'keepalive', {
WebChannel.sendMessageTo(WebChannel.channel, 'keepalive', {
'payload': {}
});
}
6 changes: 3 additions & 3 deletions src/Elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ function vue_integration(::Type{M};
"
try {
if (Genie.Settings.webchannels_keepalive_frequency > 0) {
clearInterval(app.keepalive_interval);
app.keepalive_interval = setInterval(keepalive, Genie.Settings.webchannels_keepalive_frequency);
clearInterval(app.WebChannel.keepalive_interval);
app.WebChannel.keepalive_interval = setInterval(() => keepalive(app.WebChannel), Genie.Settings.webchannels_keepalive_frequency);
}
} catch (e) {
if (Genie.Settings.env === 'dev') {
Expand All @@ -239,7 +239,7 @@ function vue_integration(::Type{M};
function create$vue_app_name() {
window.counter$vue_app_name = window.counter$vue_app_name || 1
appName = '$vue_app_name' + ((counter$vue_app_name == 1) ? '' : '_' + window.counter$vue_app_name)
const appName = '$vue_app_name' + ((counter$vue_app_name == 1) ? '' : '_' + window.counter$vue_app_name)
rootSelector = '#$vue_app_name' + ((counter$vue_app_name == 1) ? '' : '-' + window.counter$vue_app_name)
counter$vue_app_name++
Expand Down

0 comments on commit b75ca84

Please sign in to comment.