Skip to content

Commit

Permalink
allow for a configurable websocket proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ading2210 committed Feb 1, 2025
1 parent 60e353d commit 43d3673
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ CMakeFiles/
stk-editor/
.vscode/
tags.*
wasm/build/
wasm/prefix/
wasm/emsdk/
wasm/web/game

# clangd
.cache/
Expand Down
5 changes: 5 additions & 0 deletions wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/build/
/prefix/
/emsdk/
/web/game
/web/config.json
10 changes: 10 additions & 0 deletions wasm/fragments/patch_ws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* REPLACE
ws ?= ?new WebSocketConstructor\(url, ?opts\)
*/
if (globalThis.config.ws_enabled) {
ws = new WebSocket(url);
}
else {
console.error("websocket creation denied - disabled by config");
throw new TypeError("ws disabled");
}
4 changes: 4 additions & 0 deletions wasm/web/config_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ws_enabled": false,
"ws_proxy": "wss://example.com/"
}
13 changes: 12 additions & 1 deletion wasm/web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let info_container = document.getElementById("info_container");
let quality_select = document.getElementById("quality_select");

let syncing_fs = false;
let config = {};

function load_db() {
if (db) return db;
Expand Down Expand Up @@ -213,10 +214,20 @@ function set_websocket_url(url) {
Module.websocket.url = url;
}

async function load_config() {
let response = await fetch("/config.json");
config = await response.json();
globalThis.config = config;
}

async function main() {
set_websocket_url("wss://anura.pro/");
globalThis.ready = true;
await load_config();
await load_idbfs();
if (config.ws_enabled) {
set_websocket_url(config.ws_proxy);
}

start_button.onclick = start_game;
start_button.disabled = false;
status_text.innerText = "";
Expand Down

0 comments on commit 43d3673

Please sign in to comment.