From 7d53c8e3a28a4ec0bd165c2b3e2e8c16dc120fed Mon Sep 17 00:00:00 2001 From: Thilo Behnke Date: Thu, 16 Jun 2022 00:03:14 +0200 Subject: [PATCH] join session with query param --- client/www/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/www/index.js b/client/www/index.js index ab63d24..020d6ee 100644 --- a/client/www/index.js +++ b/client/www/index.js @@ -210,7 +210,11 @@ window.WASM_PONG.joinOnlineSession = () => { return; } - const sessionId = document.getElementById('join-online-input').value + const sessionId = document.getElementById('join-online-input').value; + executeJoinSession(sessionId); +} + +const executeJoinSession = (sessionId) => { fetch(`/pong/api/join_session`, {method: 'POST', body: JSON.stringify({session_id: sessionId})}).then(res => res.json()).then(({data: session}) => { console.log("Joined session:") console.log(session); @@ -371,3 +375,9 @@ const getInputActions = () => { listenToKeys(); render(JSON.parse(field.objects())); requestAnimationFrame(renderLoop); + +const queryParams = location.search ? location.search.slice(1).split("&").map(it => it.split("=")) : []; +const joinSession = queryParams.find(([name,]) => name === "join_session"); +if (joinSession) { + executeJoinSession(joinSession[1]) +}