correct value for 'you' in network session

This commit is contained in:
Thilo Behnke
2022-06-26 20:06:57 +02:00
parent 720594a59d
commit 0e9517256d
2 changed files with 3 additions and 2 deletions

View File

@@ -28,7 +28,6 @@
{#if !session}
<h3>no session</h3>
{:else}
{JSON.stringify(session)}
{JSON.stringify($sessionEvents)}
{#if session.state === SessionState.PENDING}
<h3>waiting for other player...</h3>

View File

@@ -84,12 +84,14 @@ const networkEvents = (session: NetworkSession) => readable([], function(set) {
})
export const networkSessionStateEvents = (session: NetworkSession): Readable<unknown[]> => derived(networkEvents(session), $sessionEvents => {
console.log("test")
const sessionEvents = $sessionEvents.filter(({topic}) => topic === 'session').map(({event}) => event);
if (!sessionEvents.length) {
return [];
}
const latestSessionEvent = sessionEvents[sessionEvents.length-1];
const session = {...latestSessionEvent.session, you: latestSessionEvent.actor, type: get(sessionStore).type}
const currentSession = get(sessionStore) as NetworkSession;
const session = {...latestSessionEvent.session, you: currentSession.you, type: currentSession.type}
console.debug("updating current session: ", session)
sessionStore.set(session);
return sessionEvents;