widgrensit/asobi-defold/asobi.client
The asobi client. create builds a client for one asobi server, carrying its tokens and
the realtime connection, and quick_start signs a guest in, connects and queues for a
match in one call.
- GitHub: widgrensit/asobi-defold — pinned to
v1.18.1- Pick a release from widgrensit/asobi-defold releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as client from "asobi.client"
- Pick a release from widgrensit/asobi-defold releases and add its Source code (zip) URL (or a packaged
Functions
create(host: string, port?: number, use_ssl?: boolean): Client
Creates a client for an asobi server, with its realtime connection. Nothing connects
until realtime.connect is called.
Parameters
host:string— The server's host name.port?:number— The server's port. Defaults to8084.use_ssl?:boolean— Whether to usehttpsandwss. Defaults tofalse.
Returns
Client
quick_start(opts: QuickStartOptions): Client
Signs a guest in, connects and queues for a match in one call, registering every handler
before it connects. The sign-in runs asynchronously, so the client returns at once; use
create and the realtime connection directly for entity sync or custom match state.
Parameters
opts:QuickStartOptions— The server, the mode and the callbacks.
Returns
Client— The client, for disconnecting later or reaching the rest of the API.
Types
type Payload = Record<string, unknown>
Client
Client.set_tokens(this: void, access_token: string | undefined, refresh_token: string | undefined)
Stores a new token pair and saves the refresh token with sys.save, so it survives a
restart.
Parameters
this:voidaccess_token:string | undefined— The access token.refresh_token:string | undefined— The refresh token.
Client.clear_tokens(this: void)
Forgets both tokens and erases the saved refresh token.
Parameters
this:void
Client.host: string
The server's host name.
Client.port: number
The server's port.
Client.use_ssl: boolean
Whether the client connects over https and wss.
Client.base_url: string
The REST base url, without the port when it is the scheme's default.
Client.ws_url: string
The realtime websocket url, <base>/ws, without the port when it is the scheme's default.
Client.access_token?: string
The access token, kept in memory only.
Client.refresh_token?: string
The refresh token. create loads the one an earlier session saved with sys.save, and
set_tokens and clear_tokens save it again.
Client.player_id?: string
The signed-in player's id.
Client.realtime: Realtime
The realtime connection, created with the client.
Client.http: typeof http
The REST transport every module below sends through.
Client.auth: typeof auth
Sign-in, guest devices, linked providers and the token pair.
Client.players: typeof players
Player profiles and account erasure.
Client.matchmaker: typeof matchmaker
The matchmaker queue.
Client.matches: typeof matches
Match listings.
Client.leaderboards: typeof leaderboards
Leaderboard entries and score submission.
Client.economy: typeof economy
Wallets and the store.
Client.inventory: typeof inventory
The player's items.
Client.social: typeof social
Friends, groups and chat history.
Client.tournaments: typeof tournaments
Tournament listings and entry.
Client.notifications: typeof notifications
The player's notifications.
Client.storage: typeof storage
Cloud saves and key-value storage.
Client.iap: typeof iap
In-app purchase verification.
Client.votes: typeof votes
Match votes.
Client.worlds: typeof worlds
World listings and creation.
Client.dm: typeof dm
Direct messages.
QuickStartOptions
QuickStartOptions.host: string
The server's host name.
QuickStartOptions.ssl?: boolean
Whether to connect over https and wss. Defaults to true.
QuickStartOptions.port?: number
The server's port. Defaults to 443 with ssl, 8084 without.
QuickStartOptions.mode?: string
The matchmaker mode to queue for. Defaults to "default".
QuickStartOptions.on_queued?: (payload: Payload) => void
Called when the matchmaker accepts the ticket, with ticket_id and players_needed.
QuickStartOptions.on_matched?: (payload: Payload) => void
Called when the matchmaker places the player in a match, with its match_id.
QuickStartOptions.on_state?: (state: Payload) => void
Called with each match state snapshot.
QuickStartOptions.on_failed?: (payload: Payload & { reason?: string; }) => void
Called when the guest sign-in fails, when the match cannot start, and on every realtime
error, with the failure's reason.
QuickStartOptions.on_signed_in?: (data: Payload) => void
Called after the guest sign-in succeeds, before the client connects.