From 0794030210c5f268f879c1b82448f3b9525dc5f9 Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Tue, 24 Oct 2017 11:54:01 +0200 Subject: [PATCH] Use secure protocols if page was loaded securely --- js/term/connection.js | 5 +++-- js/wifi.js | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/js/term/connection.js b/js/term/connection.js index d1c9ed4..733d177 100644 --- a/js/term/connection.js +++ b/js/term/connection.js @@ -5,6 +5,7 @@ try { demo = require('./demo') } catch (err) {} const RECONN_DELAY = 2000 const HEARTBEAT_TIME = 3000 +const HTTPS = window.location.protocol.match(/s:/) /** Handle connections */ module.exports = class TermConnection extends EventEmitter { @@ -192,7 +193,7 @@ module.exports = class TermConnection extends EventEmitter { this.closeSocket() - this.ws = new window.WebSocket('ws://' + window._root + '/term/update.ws') + this.ws = new window.WebSocket(`${HTTPS ? 'wss' : 'ws'}://${window._root}/term/update.ws`) this.ws.addEventListener('open', (...args) => this.onWSOpen(...args)) this.ws.addEventListener('close', (...args) => this.onWSClose(...args)) this.ws.addEventListener('message', (...args) => this.onWSMessage(...args)) @@ -211,7 +212,7 @@ module.exports = class TermConnection extends EventEmitter { sendPing () { console.log('> ping') this.emit('ping') - $.get('http://' + window._root + '/api/v1/ping', (resp, status) => { + $.get(`${HTTPS ? 'https' : 'http'}://${window._root}/api/v1/ping`, (resp, status) => { if (status === 200) { clearInterval(this.pingInterval) console.info('Server ready, opening socket…') diff --git a/js/wifi.js b/js/wifi.js index 16d5e06..656ca6b 100644 --- a/js/wifi.js +++ b/js/wifi.js @@ -2,6 +2,8 @@ const $ = require('./lib/chibi') const { mk } = require('./utils') const tr = require('./lang') +const HTTPS = window.location.protocol.match(/s:/) + { const w = window.WiFi = {} @@ -131,7 +133,7 @@ const tr = require('./lang') if (window._demo) { onScan(window._demo_aps, 200) } else { - $.get('http://' + window._root + '/cfg/wifi/scan', onScan) + $.get(`${HTTPS ? 'https' : 'http'}://${window._root}/cfg/wifi/scan`, onScan) } }