From be169d876e18bd5c75daea93625c4dd4dcbccee9 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Wed, 20 Oct 2021 16:25:00 +0300 Subject: [PATCH] unhardcode websocket server location --- README.md | 4 +--- public/index.js | 8 ++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8f00af2..f88650a 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,7 @@ it's intended use is for small groups of people to self-host, and as such there' 3. `npm install` -4. replace all mentions of `deemix.oat.zone` in `public/index.html` with your own domain (and `wss://` with `ws://` if needed) - -5. (optionally) put the service on pm2 like such: `pm2 start src/index.js --name deemix-web-frontend` (or just run it with `node src/index.js`) +4. (optionally) put the service on pm2 like such: `pm2 start src/index.js --name deemix-web-frontend` (or just run it with `node src/index.js`) ### nginx addenum diff --git a/public/index.js b/public/index.js index c352d8c..3296985 100644 --- a/public/index.js +++ b/public/index.js @@ -35,6 +35,10 @@ function setTheme(theme) { }); } +function getWebsocketLocation() { + return window.window.location.replace('https://', 'wss://').replace('http://', 'ws://'); +} + window.onload = () => { // dirty theme hacks :tm: @@ -88,7 +92,7 @@ window.onload = () => { let coverArt document.getElementById('albums').innerHTML = ''; document.getElementById('progress-album').innerHTML = '
'; - const ws = new WebSocket('wss://deemix.oat.zone/api/album?id=' + id); + const ws = new WebSocket(getWebsocketLocation() + 'api/album?id=' + id); ws.onmessage = (m) => { const d = JSON.parse(m.data); @@ -121,7 +125,7 @@ window.onload = () => { let coverArt document.getElementById('albums').innerHTML = ''; document.getElementById('progress-album').innerHTML = '
'; - const ws = new WebSocket('wss://deemix.oat.zone/api/track?id=' + trackId); + const ws = new WebSocket(getWebsocketLocation() + 'api/track?id=' + trackId); ws.onmessage = (m) => { const d = JSON.parse(m.data); console.log(d);