diff --git a/client/svelte-client/src/components/NetworkSessionWrapper.svelte b/client/svelte-client/src/components/NetworkSessionWrapper.svelte
index 233f2e1..fe6cd9b 100644
--- a/client/svelte-client/src/components/NetworkSessionWrapper.svelte
+++ b/client/svelte-client/src/components/NetworkSessionWrapper.svelte
@@ -1,12 +1,22 @@
@@ -14,5 +24,18 @@
{#if !session}
no session
{:else}
-
+ {#if sessionEvents}
+ events: {JSON.stringify(sessionEvents)}
+ {/if}
+ {#if session.state === SessionState.PENDING}
+ waiting for other player...
+
+ {:else if session.state === SessionState.CLOSED}
+ game over!
+ {:else if session.state === SessionState.RUNNING}
+
+ {:else }
+ unknown game state
+ {/if}
{/if}
+
diff --git a/client/svelte-client/src/components/SessionWrapper.svelte b/client/svelte-client/src/components/SessionWrapper.svelte
index 576b099..1e66049 100644
--- a/client/svelte-client/src/components/SessionWrapper.svelte
+++ b/client/svelte-client/src/components/SessionWrapper.svelte
@@ -8,11 +8,6 @@
export let session: Session;
- let joinLink;
- $: if(session) {
- console.log(session);
- joinLink = api.createJoinLink(session.session_id);
- }
@@ -23,18 +18,9 @@
{:else}
- {#if session.state === SessionState.PENDING}
-
waiting for other player...
-
- {:else if session.state === SessionState.CLOSED}
- game over!
- {:else if session.state === SessionState.RUNNING}
-
-
-
- {:else }
- unknown game state
- {/if}
+
+
+
{/if}
diff --git a/client/svelte-client/src/store/session.ts b/client/svelte-client/src/store/session.ts
index ff741b8..157c0a1 100644
--- a/client/svelte-client/src/store/session.ts
+++ b/client/svelte-client/src/store/session.ts
@@ -43,8 +43,10 @@ const player2KeyboardInputs = derived(
}
)
-const networkSessionEvents = (session: NetworkSession) => readable([], function(set) {
+const networkEvents = (session: NetworkSession) => readable([], function(set) {
const websocket = writable(null);
+
+ console.log("creating ws to receive/send websocket events for session: ", JSON.stringify(session))
api.createEventWebsocket(session).then(ws => {
websocket.set(ws);
});
@@ -54,6 +56,7 @@ const networkSessionEvents = (session: NetworkSession) => readable([], function(
if (!websocket) {
return;
}
+ console.log("ws ready, registering message handler")
$websocket.onmessage = event => {
events.set([...get(events), event])
}
@@ -70,8 +73,9 @@ const networkSessionEvents = (session: NetworkSession) => readable([], function(
}
})
-const networkInputEvents = (session: NetworkSession): Readable => derived(networkSessionEvents(session), $sessionEvents => $sessionEvents.filter(({input}) => input === 'topic'));
+export const networkSessionStateEvents = (session: NetworkSession): Readable => derived(networkEvents(session), $sessionEvents => $sessionEvents.filter(({topic}) => topic === 'session'));
+const networkInputEvents = (session: NetworkSession): Readable => derived(networkEvents(session), $sessionEvents => $sessionEvents.filter(({topic}) => topic === 'input'));
export const sessionInputs = (session: Session) => readable([], function(setInputs) {
let player1Inputs = writable([]);
let player2Inputs = writable([]);