Skip to content

Commit 43d3673

Browse files
committed
allow for a configurable websocket proxy
1 parent 60e353d commit 43d3673

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ CMakeFiles/
77
stk-editor/
88
.vscode/
99
tags.*
10-
wasm/build/
11-
wasm/prefix/
12-
wasm/emsdk/
13-
wasm/web/game
1410

1511
# clangd
1612
.cache/

wasm/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/build/
2+
/prefix/
3+
/emsdk/
4+
/web/game
5+
/web/config.json

wasm/fragments/patch_ws.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* REPLACE
2+
ws ?= ?new WebSocketConstructor\(url, ?opts\)
3+
*/
4+
if (globalThis.config.ws_enabled) {
5+
ws = new WebSocket(url);
6+
}
7+
else {
8+
console.error("websocket creation denied - disabled by config");
9+
throw new TypeError("ws disabled");
10+
}

wasm/web/config_example.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ws_enabled": false,
3+
"ws_proxy": "wss://example.com/"
4+
}

wasm/web/script.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let info_container = document.getElementById("info_container");
1313
let quality_select = document.getElementById("quality_select");
1414

1515
let syncing_fs = false;
16+
let config = {};
1617

1718
function load_db() {
1819
if (db) return db;
@@ -213,10 +214,20 @@ function set_websocket_url(url) {
213214
Module.websocket.url = url;
214215
}
215216

217+
async function load_config() {
218+
let response = await fetch("/config.json");
219+
config = await response.json();
220+
globalThis.config = config;
221+
}
222+
216223
async function main() {
217-
set_websocket_url("wss://anura.pro/");
218224
globalThis.ready = true;
225+
await load_config();
219226
await load_idbfs();
227+
if (config.ws_enabled) {
228+
set_websocket_url(config.ws_proxy);
229+
}
230+
220231
start_button.onclick = start_game;
221232
start_button.disabled = false;
222233
status_text.innerText = "";

0 commit comments

Comments
 (0)