From 589a482faae83f0f13c9edf124df1b515a7b54d3 Mon Sep 17 00:00:00 2001 From: Ben Arc Date: Wed, 14 Apr 2021 22:09:33 +0100 Subject: [PATCH] check https for wss --- .../copilot/templates/copilot/compose.html | 24 +++++++++++++------ .../copilot/templates/copilot/panel.html | 24 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lnbits/extensions/copilot/templates/copilot/compose.html b/lnbits/extensions/copilot/templates/copilot/compose.html index 87a695f43..096cea2d1 100644 --- a/lnbits/extensions/copilot/templates/copilot/compose.html +++ b/lnbits/extensions/copilot/templates/copilot/compose.html @@ -85,14 +85,24 @@ }, created: function () { console.log('{{ copilot.id }}') + if (location.protocol !== 'https:') { + this.connection = new WebSocket( + 'ws://' + + document.domain + + ':' + + location.port + + '/copilot/ws/compose/{{ copilot.id }}' + ) + } else { + this.connection = new WebSocket( + 'wss://' + + document.domain + + ':' + + location.port + + '/copilot/ws/compose/{{ copilot.id }}' + ) + } - this.connection = new WebSocket( - 'ws://' + - document.domain + - ':' + - location.port + - '/copilot/ws/compose/{{ copilot.id }}' - ) this.connection.addEventListener('open', function (event) { this.connection.send('') }) diff --git a/lnbits/extensions/copilot/templates/copilot/panel.html b/lnbits/extensions/copilot/templates/copilot/panel.html index ea64c61e7..29d7fe60d 100644 --- a/lnbits/extensions/copilot/templates/copilot/panel.html +++ b/lnbits/extensions/copilot/templates/copilot/panel.html @@ -170,13 +170,23 @@ created: function () { console.log('{{ copilot.id }}') - this.connection = new WebSocket( - 'ws://' + - document.domain + - ':' + - location.port + - '/copilot/ws/panel/{{ copilot.id }}' - ) + if (location.protocol !== 'https:') { + this.connection = new WebSocket( + 'ws://' + + document.domain + + ':' + + location.port + + '/copilot/ws/compose/{{ copilot.id }}' + ) + } else { + this.connection = new WebSocket( + 'wss://' + + document.domain + + ':' + + location.port + + '/copilot/ws/compose/{{ copilot.id }}' + ) + } this.connection.addEventListener('open', function (event) {}) this.connection.addEventListener('message', function (event) {