mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-10 18:20:00 +00:00
join session with query param
This commit is contained in:
@@ -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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user