Skip to content

@my-swu/simulator-client


@my-swu/simulator-client / MatchSessionEvents

Interface: MatchSessionEvents ​

Defined in: packages/ts-sdk/src/match-session/session-state.ts:250

Typed event map emitted by MatchSession.

Register listeners through matchSession.on(). Each listener returns an unsubscribe function.

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('change', changePayload => {
  console.log(changePayload)
})

stopListening()

Example ​

ts
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 ​

aiStatus ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('aiStatus', aiStatusPayload => {
  console.log(aiStatusPayload)
})

stopListening()

aiStatus: AiStatusPayload

Defined in: packages/ts-sdk/src/match-session/session-state.ts:252

Emitted when the server reports AI attachment or pause status.


change ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('change', changePayload => {
  console.log(changePayload)
})

stopListening()

change: MatchSessionState

Defined in: packages/ts-sdk/src/match-session/session-state.ts:254

Emitted after any public session state changes.


connectionState ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('connectionState', connectionStatePayload => {
  console.log(connectionStatePayload)
})

stopListening()

connectionState: ConnectionState

Defined in: packages/ts-sdk/src/match-session/session-state.ts:256

Emitted when the transport state changes.


error ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('error', errorPayload => {
  console.log(errorPayload)
})

stopListening()

error: ErrorPayload

Defined in: packages/ts-sdk/src/match-session/session-state.ts:258

Emitted when an engine or SDK error is recorded.


event ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('event', eventPayload => {
  console.log(eventPayload)
})

stopListening()

event: GameEvent

Defined in: packages/ts-sdk/src/match-session/session-state.ts:260

Emitted for each live game event.


historyEntry ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('historyEntry', historyEntryPayload => {
  console.log(historyEntryPayload)
})

stopListening()

historyEntry: MatchHistoryFeedEntry

Defined in: packages/ts-sdk/src/match-session/session-state.ts:266

Emitted when the server sends one new match-history entry.


historySnapshot ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('historySnapshot', historySnapshotPayload => {
  console.log(historySnapshotPayload)
})

stopListening()

historySnapshot: MatchHistorySnapshot

Defined in: packages/ts-sdk/src/match-session/session-state.ts:264

Emitted when the server sends a full recent match-history snapshot.


interactionCue ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('interactionCue', interactionCuePayload => {
  console.log(interactionCuePayload)
})

stopListening()

interactionCue: CardInteractionCue

Defined in: packages/ts-sdk/src/match-session/session-state.ts:262

Emitted for each transient hand-card interaction cue.


message ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('message', messagePayload => {
  console.log(messagePayload)
})

stopListening()

message: ServerMessage

Defined in: packages/ts-sdk/src/match-session/session-state.ts:268

Emitted for every decoded server message.


pong ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('pong', pongPayload => {
  console.log(pongPayload)
})

stopListening()

pong: PongPayload

Defined in: packages/ts-sdk/src/match-session/session-state.ts:270

Emitted for each socket pong.


reconnectState ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('reconnectState', reconnectStatePayload => {
  console.log(reconnectStatePayload)
})

stopListening()

reconnectState: MatchSessionReconnectState

Defined in: packages/ts-sdk/src/match-session/session-state.ts:272

Emitted when automatic reconnect progress changes.


snapshot ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('snapshot', snapshotPayload => {
  console.log(snapshotPayload)
})

stopListening()

snapshot: GameState

Defined in: packages/ts-sdk/src/match-session/session-state.ts:274

Emitted when a new authoritative snapshot arrives.


welcome ​

Example:

ts
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',
})

// Keep seatToken private; it authenticates one player seat.
const matchSession = simulatorClient.session.create({
  matchId: 'match_123',
  seatToken: 'seat_token_123',
})

// Listener payloads are typed by the event name.
const stopListening = matchSession.on('welcome', welcomePayload => {
  console.log(welcomePayload)
})

stopListening()

welcome: WelcomePayload

Defined in: packages/ts-sdk/src/match-session/session-state.ts:276

Emitted when the socket welcome payload arrives.

Released under the MIT License.