@my-swu/simulator-client / MatchSessionEvents
Interface: MatchSessionEvents
Defined in: packages/ts-sdk/src/match-session/session-state.ts:175
Typed event map emitted by MatchSession.
Register listeners through matchSession.on(). Each listener returns an unsubscribe function.
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
console.log(matchSessionEvents)Example
import type { GameState, MatchSessionEvents } from '@my-swu/simulator-client'
const renderSnapshot = (matchSnapshot: GameState) => {
console.log(matchSnapshot.phase)
}
const snapshotEventName: keyof MatchSessionEvents = 'snapshot'
console.log(snapshotEventName, renderSnapshot)See
https://simulator-sdk.my-swu.com/guide/match-session#events
Properties
change
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { change: matchSessionState } = matchSessionEvents
console.log(matchSessionState)change:
MatchSessionState
Defined in: packages/ts-sdk/src/match-session/session-state.ts:177
Emitted after any public session state changes.
connectionState
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { connectionState } = matchSessionEvents
console.log(connectionState)connectionState:
ConnectionState
Defined in: packages/ts-sdk/src/match-session/session-state.ts:179
Emitted when the transport state changes.
error
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { error: errorPayload } = matchSessionEvents
console.log(errorPayload)error:
ErrorPayload
Defined in: packages/ts-sdk/src/match-session/session-state.ts:181
Emitted when an engine or SDK error is recorded.
event
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { event: matchEvent } = matchSessionEvents
console.log(matchEvent)event:
GameEvent
Defined in: packages/ts-sdk/src/match-session/session-state.ts:183
Emitted for each live game event.
message
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { message: serverMessage } = matchSessionEvents
console.log(serverMessage)message:
ServerMessage
Defined in: packages/ts-sdk/src/match-session/session-state.ts:185
Emitted for every decoded server message.
pong
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { pong: pongPayload } = matchSessionEvents
console.log(pongPayload)pong:
PongPayload
Defined in: packages/ts-sdk/src/match-session/session-state.ts:187
Emitted for each socket pong.
snapshot
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { snapshot: snapshotEventPayload } = matchSessionEvents
console.log(snapshotEventPayload)snapshot:
GameState
Defined in: packages/ts-sdk/src/match-session/session-state.ts:189
Emitted when a new authoritative snapshot arrives.
welcome
Example:
import type { MatchSessionEvents } from '@my-swu/simulator-client'
import { createSimulatorClient } from '@my-swu/simulator-client'
// Point this at the simulator HTTP origin for /health and /api routes.
const simulatorClient = createSimulatorClient({
baseUrl: 'http://127.0.0.1:4000',
})
// Snapshots are fetched from the same server state used by sockets.
const matchSnapshot = await simulatorClient.matches.get('match_123')
const matchSessionEvents = {
change: { connectionState: 'open', errors: [], events: [], errorMessages: [] },
connectionState: 'open',
error: { code: 'invalid_selection', message: 'Deck must include a leader' },
event: { playerReady: { seat: 'one' } },
message: { type: 'pong', payload: { nonce: 'host-latency-1' } },
pong: { nonce: 'host-latency-1' },
snapshot: matchSnapshot,
welcome: { matchId: 'match_123', seat: 'one' },
} satisfies MatchSessionEvents
const { welcome: welcomePayload } = matchSessionEvents
console.log(welcomePayload)welcome:
WelcomePayload
Defined in: packages/ts-sdk/src/match-session/session-state.ts:191
Emitted when the socket welcome payload arrives.
