Skip to content

@my-swu/simulator-client


@my-swu/simulator-client / MatchSession

Interface: MatchSession

Defined in: packages/ts-sdk/src/match-session/types.ts:49

Main ergonomic SDK API for interacting with one live match.

A session wraps HTTP match creation/joining, WebSocket connection state, incoming snapshots/events, outgoing commands, and explicit reconnects for one private player seat.

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
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
matchSession
.
ready
()

Example

ts
import { createSimulatorClient } from '@my-swu/simulator-client'

const simulatorClient = createSimulatorClient({
  baseUrl: 'http://127.0.0.1:4000',
})
const hostAccess = { matchId: 'match_123', seatToken: 'seat_token_123' }

const matchSession = simulatorClient.session.create(hostAccess)
await matchSession.connect()
matchSession.ready()

See

Extends

  • MatchSessionMethods

Properties

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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
connectionState
} =
matchSession
console
.
log
(
connectionState
)

readonly connectionState: ConnectionState

Defined in: packages/ts-sdk/src/match-session/types.ts:51

Current transport state.


errorMessages

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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
errorMessages
} =
matchSession
console
.
log
(
errorMessages
)

readonly errorMessages: readonly string[]

Defined in: packages/ts-sdk/src/match-session/types.ts:57

Human-readable error summaries.


errors

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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
errors
} =
matchSession
console
.
log
(
errors
)

readonly errors: readonly ErrorPayload[]

Defined in: packages/ts-sdk/src/match-session/types.ts:53

Recent engine or SDK errors.


events

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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
events
} =
matchSession
console
.
log
(
events
)

readonly events: readonly GameEvent[]

Defined in: packages/ts-sdk/src/match-session/types.ts:55

Recent game events.


matchId

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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
matchId
} =
matchSession
console
.
log
(
matchId
)

readonly matchId: string | undefined

Defined in: packages/ts-sdk/src/match-session/types.ts:59

Public match id when one is known.


seat

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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
seat
:
controlledSeat
} =
matchSession
console
.
log
(
controlledSeat
)

readonly seat: Seat | undefined

Defined in: packages/ts-sdk/src/match-session/types.ts:63

Seat controlled by this session when known.


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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
snapshot
:
matchSnapshot
} =
matchSession
console
.
log
(
matchSnapshot
)

readonly snapshot: GameState | undefined

Defined in: packages/ts-sdk/src/match-session/types.ts:61

Latest authoritative private snapshot for this seat.


state

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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
state
} =
matchSession
console
.
log
(
state
)

readonly state: MatchSessionState

Defined in: packages/ts-sdk/src/match-session/types.ts:65

Token-free state snapshot.


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 this seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
const {
welcome
} =
matchSession
console
.
log
(
welcome
)

readonly welcome: WelcomePayload | undefined

Defined in: packages/ts-sdk/src/match-session/types.ts:67

Latest welcome payload when the socket handshake has completed.

Methods

close()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
matchSession
.
close
()

close(): void

Defined in: packages/ts-sdk/src/match-session/methods.ts:119

Closes the active socket.

Listeners stay registered, and stored access remains available for reconnect().

Returns

void

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

function leaveView(matchSession: MatchSession) {
  matchSession.close()
}

console.log(leaveView)

See

https://simulator-sdk.my-swu.com/guide/match-session#closing

Inherited from

MatchSessionMethods.close


connect()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
await
matchSession
.
connect
()

connect(access?, options?): Promise<MatchSession>

Defined in: packages/ts-sdk/src/match-session/methods.ts:42

Opens a socket using existing or supplied private access.

Call this after seeding access from matches.create(), matches.join(), createMatch(), or joinMatch(). Resolves after welcome and snapshot.

Parameters

access?

MatchSessionAccess

options?

MatchSessionConnectOptions

Returns

Promise<MatchSession>

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

async function resumeMatch(matchSession: MatchSession) {
  await matchSession.connect({
    matchId: 'match_123',
    seatToken: 'seat_token_123',
  })
}

console.log(resumeMatch)

See

https://simulator-sdk.my-swu.com/guide/match-session#connecting

Inherited from

MatchSessionMethods.connect


createMatch()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
const
createdHostAccess
= await
matchSession
.
createMatch
({
hostDeck
:
premierHostDeck
})

createMatch(request, options?): Promise<MatchAccessResponse>

Defined in: packages/ts-sdk/src/match-session/methods.ts:68

Creates a host match, stores private access, and connects.

Use this when one UI action should create a match and start live state.

Parameters

request

CreateMatchRequest

options?

MatchSessionConnectOptions

Returns

Promise<MatchAccessResponse>

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

const premierHostDeck = {
  leader: 46102,
  base: 308,
  cards: Array.from({ length: 50 }, () => 45),
}

async function hostPremier(matchSession: MatchSession) {
  return matchSession.createMatch({ hostDeck: premierHostDeck })
}

console.log(hostPremier)

See

https://simulator-sdk.my-swu.com/guide/match-lifecycle#creating-matches

Inherited from

MatchSessionMethods.createMatch


joinMatch()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
const
guestAccess
= await
matchSession
.
joinMatch
({
matchId
: 'match_123' }, {
deck
:
premierGuestDeck
})

joinMatch(match, request, options?): Promise<MatchAccessResponse>

Defined in: packages/ts-sdk/src/match-session/methods.ts:94

Joins a match, stores private access, and connects.

Use this for guest tabs or players entering through a shared match id.

Parameters

match

string | MatchReference

request

JoinMatchRequest

options?

MatchSessionConnectOptions

Returns

Promise<MatchAccessResponse>

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

const premierGuestDeck = {
  leader: 46107,
  base: 309,
  cards: Array.from({ length: 50 }, () => 35),
}

async function joinPremier(matchSession: MatchSession) {
  return matchSession.joinMatch('match_123', { deck: premierGuestDeck })
}

console.log(joinPremier)

See

https://simulator-sdk.my-swu.com/guide/match-lifecycle#joining-matches

Inherited from

MatchSessionMethods.joinMatch


on()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
const
stopListening
=
matchSession
.
on
('snapshot',
matchSnapshot
=> {
// Snapshots are the authoritative state for UI rendering.
console
.
log
(
matchSnapshot
.
phase
)
})
stopListening
()

on<TKey>(event, listener): () => void

Defined in: packages/ts-sdk/src/match-session/methods.ts:261

Registers one typed event listener and returns an unsubscribe function.

Event listeners stay registered across reconnects. Unsubscribe on unmount.

Type Parameters

TKey

TKey extends keyof MatchSessionEvents

Parameters

event

TKey

listener

(value) => void

Returns

() => void

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

function watchState(matchSession: MatchSession) {
  return matchSession.on('snapshot', actionSnapshot => {
    console.log(actionSnapshot.phase)
  })
}

console.log(watchState)

See

https://simulator-sdk.my-swu.com/guide/match-session#events

Inherited from

MatchSessionMethods.on


ping()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
matchSession
.
ping
('host-latency-1')

ping(nonce?): void

Defined in: packages/ts-sdk/src/match-session/methods.ts:199

Sends one ping frame with an optional nonce echoed by pong.

Use the nonce to match a pong to one latency measurement.

Parameters

nonce?

string | null

Returns

void

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

function measureLatency(matchSession: MatchSession) {
  matchSession.ping('latency-check-1')
}

console.log(measureLatency)

See

https://simulator-sdk.my-swu.com/guide/websocket#ping-and-pong

Inherited from

MatchSessionMethods.ping


ready()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
matchSession
.
ready
()

ready(): void

Defined in: packages/ts-sdk/src/match-session/methods.ts:159

Sends one ready message for the current seat.

Use this in lobby and setup phases when a seat must acknowledge readiness.

Returns

void

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

function markSeatReady(matchSession: MatchSession) {
  matchSession.ready()
}

console.log(markSeatReady)

See

https://simulator-sdk.my-swu.com/guide/driving-gameplay#ready-messages

Inherited from

MatchSessionMethods.ready


reconnect()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
await
matchSession
.
reconnect
({
handshakeTimeoutMs
: 5_000 })

reconnect(options?): Promise<MatchSession>

Defined in: packages/ts-sdk/src/match-session/methods.ts:139

Reopens the socket using the stored private access.

Closes the old socket, opens a new one, waits for handshake, then syncs.

Parameters

options?

MatchSessionConnectOptions

Returns

Promise<MatchSession>

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

async function restoreSocket(matchSession: MatchSession) {
  await matchSession.reconnect({ handshakeTimeoutMs: 10_000 })
}

console.log(restoreSocket)

See

https://simulator-sdk.my-swu.com/guide/reconnect

Inherited from

MatchSessionMethods.reconnect


sendCommand()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
matchSession
.
sendCommand
('pass')

sendCommand(command): void

Defined in: packages/ts-sdk/src/match-session/methods.ts:219

Sends one typed gameplay command for the current prompt.

Invalid command shapes fail SDK validation before a socket frame is sent.

Parameters

command

GameCommand

Returns

void

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

function passAction(matchSession: MatchSession) {
  matchSession.sendCommand('pass')
}

console.log(passAction)

See

https://simulator-sdk.my-swu.com/guide/driving-gameplay

Inherited from

MatchSessionMethods.sendCommand


sendFormatEvent()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
matchSession
.
sendFormatEvent
({
type
: 'readyNextGame' })

sendFormatEvent(command): void

Defined in: packages/ts-sdk/src/match-session/methods.ts:239

Sends one typed out-of-game format command for series flows.

Use for match-series actions such as readying for the next game.

Parameters

command

FormatEventCommand

Returns

void

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

function readyForSeriesGame(matchSession: MatchSession) {
  matchSession.sendFormatEvent({ type: 'readyNextGame' })
}

console.log(readyForSeriesGame)

See

https://simulator-sdk.my-swu.com/guide/match-lifecycle#format-events

Inherited from

MatchSessionMethods.sendFormatEvent


sync()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
matchSession
.
sync
()

sync(): void

Defined in: packages/ts-sdk/src/match-session/methods.ts:179

Sends one request for the latest server snapshot.

Use after reconnects, tab restores, or missed UI updates.

Returns

void

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

function requestFreshState(matchSession: MatchSession) {
  matchSession.sync()
}

console.log(requestFreshState)

See

https://simulator-sdk.my-swu.com/guide/websocket#sync-requests

Inherited from

MatchSessionMethods.sync


waitForSnapshot()

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',
}) // Use card ids; the server validates deck legality. const
premierHostDeck
= {
leader
: 46102, // Leia Organa - Someone Who Loves You
base
: 308, // Echo Base
cards
:
Array
.
from
({
length
: 50 }, () => 45), // Alliance X-Wing
} // Seat two submits a separate legal deck when joining the match. const
premierGuestDeck
= {
leader
: 46107, // Darth Vader - Unstoppable
base
: 309, // Tarkintown
cards
:
Array
.
from
({
length
: 50 }, () => 35), // TIE/ln Fighter
} // Keep seatToken private; it authenticates one player seat. const
hostAccess
= {
matchId
: 'match_123',
seatToken
: 'seat_token_123' }
const
matchSession
=
simulatorClient
.
session
.
create
(
hostAccess
)
await
matchSession
.
connect
()
const
actionSnapshot
= await
matchSession
.
waitForSnapshot
(
matchSnapshot
=>
matchSnapshot
.
phase
=== 'action',
)

waitForSnapshot(predicate?, options?): Promise<GameState>

Defined in: packages/ts-sdk/src/match-session/methods.ts:287

Resolves with the current or next matching snapshot.

Checks current state first, then waits for future snapshots until timeout.

Parameters

predicate?

MatchSessionSnapshotPredicate

options?

MatchSessionWaitOptions

Returns

Promise<GameState>

Example

ts
import type { MatchSession } from '@my-swu/simulator-client'

async function waitForAction(matchSession: MatchSession) {
  return matchSession.waitForSnapshot(
    matchSnapshot => matchSnapshot.phase === 'action',
    { timeoutMs: 5_000 },
  )
}

console.log(waitForAction)

See

https://simulator-sdk.my-swu.com/guide/match-session#waiting-for-state

Inherited from

MatchSessionMethods.waitForSnapshot

Released under the MIT License.