Skip to content

Commit 700d801

Browse files
committed
avoid duplicate Webchannels, bring back default WebChannel, opt-out via window.CHANNEL=null
1 parent b85bc20 commit 700d801

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

assets/js/channels.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ Genie.WebChannels.sendMessageTo = async (channel, message, payload = {}) => {
3636
Genie.initWebChannel = function(channel = Genie.Settings.webchannels_default_route) {
3737
// A message maps to a channel route so that channel + message = /action/controller
3838
// The payload is the data exposed in the Channel Controller
39+
40+
if (Genie.AllWebChannels.map(x=>x.channel).includes(channel)) {
41+
console.warn("Channel '" + channel + "' already exists. Please use another name.");
42+
return
43+
}
44+
3945
var WebChannel = {};
4046
WebChannel.sendMessageTo = async (channel, message, payload = {}) => {
4147
let msg = JSON.stringify({
@@ -406,7 +412,10 @@ function isDev() {
406412
}
407413

408414
// --------------- Initialize WebChannel ---------------
409-
// compatibilty with Stipple v0.28
410-
if (window.CHANNEL !== undefined) {
415+
// compatibilty with earlier Genie versions and with Stipple v0.28
416+
if (window.CHANNEL === undefined) {
417+
Genie.initWebChannel(Genie.Settings.webchannels_default_route || '____');
418+
} else if (typeof window.CHANNEL == 'string') {
411419
Genie.initWebChannel(window.CHANNEL);
412420
}
421+
// if window.CHANNEL == null, the user is responsible for initializing the WebChannel

0 commit comments

Comments
 (0)