From b75ca84ee2cadbc1a14e2ee51cc3f7642173b677 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Mon, 11 Nov 2024 00:07:39 +0100 Subject: [PATCH] support keepalive for multi-model pages --- assets/js/keepalive.js | 9 +++++---- src/Elements.jl | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/assets/js/keepalive.js b/assets/js/keepalive.js index 449e890b..01a5d36e 100644 --- a/assets/js/keepalive.js +++ b/assets/js/keepalive.js @@ -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': {} }); } diff --git a/src/Elements.jl b/src/Elements.jl index 86bffa32..2301df9c 100644 --- a/src/Elements.jl +++ b/src/Elements.jl @@ -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') { @@ -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++