mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-12 02:59:48 +00:00
local vs network session
This commit is contained in:
@@ -28,19 +28,19 @@
|
||||
}
|
||||
function createSession() {
|
||||
$network.loading = true;
|
||||
sessionStore.createSession().then(() => {
|
||||
sessionStore.createNetworkSession().then(() => {
|
||||
$network.loading = false;
|
||||
})
|
||||
}
|
||||
function joinSession(sessionId) {
|
||||
$network.loading = true;
|
||||
sessionStore.joinSession(sessionId).then(() => {
|
||||
sessionStore.joinNetworkSession(sessionId).then(() => {
|
||||
$network.loading = false;
|
||||
})
|
||||
}
|
||||
function watchSession(sessionId) {
|
||||
$network.loading = true;
|
||||
sessionStore.watchSession(sessionId).then(() => {
|
||||
sessionStore.watchNetworkSession(sessionId).then(() => {
|
||||
$network.loading = false;
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export enum SessionState {
|
||||
}
|
||||
|
||||
export enum SessionType {
|
||||
HOST = 'HOST', PEER = 'PEER', OBSERVER = 'OBSERVER'
|
||||
LOCAL = 'LOCAL', HOST = 'HOST', PEER = 'PEER', OBSERVER = 'OBSERVER'
|
||||
}
|
||||
|
||||
export type Player = {
|
||||
@@ -16,13 +16,19 @@ export type Observer = {
|
||||
id: string
|
||||
}
|
||||
|
||||
export type Session = {
|
||||
export type LocalSession = {
|
||||
state: SessionState
|
||||
}
|
||||
|
||||
export type NetworkSession = {
|
||||
session_id: string,
|
||||
state: SessionState,
|
||||
players: Player[],
|
||||
observers: Observer[]
|
||||
}
|
||||
|
||||
export type Session = LocalSession | NetworkSession;
|
||||
|
||||
export type SessionStore = {
|
||||
session?: Session,
|
||||
sessionType?: SessionType
|
||||
@@ -42,9 +48,10 @@ function makeSessionStore() {
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
createSession: () => createSession().then(session => update(() => ({session, sessionType: SessionType.HOST}))),
|
||||
joinSession: (sessionId) => joinSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.PEER}))),
|
||||
watchSession: (sessionId) => watchSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.OBSERVER}))),
|
||||
createLocalSession: () => update(() => ({session: {state: SessionState.RUNNING}})),
|
||||
createNetworkSession: () => createSession().then(session => update(() => ({session, sessionType: SessionType.HOST}))),
|
||||
joinNetworkSession: (sessionId) => joinSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.PEER}))),
|
||||
watchNetworkSession: (sessionId) => watchSession(sessionId).then(session => update(() => ({session, sessionType: SessionType.OBSERVER}))),
|
||||
reset: () => set(initialValue())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user