Skip to main content

Sandbox

ZEPETO.Multiplay.Sandbox

Represents a Multiplay Room.

Constructors

constructor

new Sandbox()

Properties

allowReconnectionTime

Readonly allowReconnectionTime: number

Time limit (in seconds) for allowing the reconnection of a client with an unstable connection.


clients

Readonly clients: IterableIterator<SandboxPlayer>

Iterable representation of the clients connected to the Multiplay Room.


locked

Readonly locked: boolean

Specifies whether the Multiplay Room is locked.


maxClients

Readonly maxClients: number

Maximum number of clients able to connect to the Multiplay Room.


private

Readonly private: boolean

Specifies whether the Multiplay Room is private.


roomId

Readonly roomId: string

ID of the Multiplay Room, assigned randomly upon creation to avoid duplication.


state

Readonly state: State

State of a Multiplay Room. The schema for the state data is defined by the Multiplay Schema.


uniqueId

Optional Readonly uniqueId: string

ID of the Multiplay Room, explicitly assigned upon creation.

Methods

broadcast

broadcast(type, message?, options?): void

Sends a message through a specified channel to every client connected to the Multiplay Room.

Parameters

NameTypeDescription
typestring | numberThe identifier of the channel to send the message through.
message?anyOptional Optional content of the message.
options?IBroadcastOptionsOptional Broadcast options.

Returns

void


kick

kick(client, reason?): Promise<void>

Kicks out a client from the Multiplay Room.

Parameters

NameTypeDescription
clientSandboxPlayerObject of the client to be kicked out.
reason?stringOptional Optionally describe the reason for the kick-out.

Returns

Promise<void>

Promise resolved upon completion of the process.


loadPlayer

loadPlayer(sessionId): SandboxPlayer

Gets the client object associated with a session ID.

Parameters

NameTypeDescription
sessionIdstringClient's session ID.

Returns

SandboxPlayer

The client object.


lock

lock(): Promise<void>

Locks the Multiplay Room.

Returns

Promise<void>

Promise resolved upon completion of the locking process.


onCreate

Optional Abstract onCreate(options): void | Promise<void>

Implementation of this abstract method is run once, when the Multiplay Room is created. Implementation can be optionally declared async.

Parameters

NameTypeDescription
optionsSandboxOptionsOptions for creating the Multiplay Room.

Returns

void | Promise<void>

If asynchronous, it returns Promise<void>. Otherwise, void.


onJoin

Optional Abstract onJoin(client): void | Promise<void>

Implementation of this abstract method is run when a client joins the Multiplay Room. Implementation can be optionally declared async.

Parameters

NameTypeDescription
clientSandboxPlayerClient object of the player.

Returns

void | Promise<void>

If asynchronous, it returns Promise<void>. Otherwise, void.


onLeave

Optional Abstract onLeave(client, consented?): void | Promise<void>

Implementation of this abstract method is run when a client leaves the Multiplay Room. Implementation can be optionally declared async.

Parameters

NameTypeDescription
clientSandboxPlayerClient object of the player.
consented?booleanOptional Specifies whether the player has consented to reconnect.

Returns

void | Promise<void>

If asynchronous, it returns Promise<void>. Otherwise, void.


onMessage

onMessage<T>(messageType, callback): void

Registers a callback to handle messages received from clients.

Type parameters

NameTypeDescription
TanyOptionally specifies the type of message in the callback.

Parameters

NameTypeDescription
messageTypestring | numberThe identifier of the channel the message was sent through.
callback(client: SandboxPlayer, message: T) => voidCallback method to handle the received message.

Returns

void


onTick

Optional onTick(deltaTime): void

Implementation of this method is executed approximately every 100 milliseconds.

Parameters

NameTypeDescription
deltaTimenumberRepresents the time difference (in milliseconds) from the previous call.

Returns

void


setPrivate

setPrivate(isPrivate): Promise<void>

Sets the private status of the Multiplay Room.

Parameters

NameTypeDescription
isPrivatebooleanSpecifies the private status of the Multiplay Room.

Returns

Promise<void>

Promise resolved upon completion of the process.


unlock

unlock(): Promise<void>

Unlocks the Multiplay Room.

Returns

Promise<void>

Promise resolved upon completion of the unlocking process.