ZEPETO.Multiplay
Type | Description |
|---|---|
Represents a player's client connected to the Multiplay Room. | |
Options for broadcasting messages from the Multiplay Room to clients. | |
Options for creating a Multiplay Room. | |
Sandbox | Represents a Multiplay Room. |
SandboxPlayer
interface
Represents a player's client connected to the Multiplay Room.
Properties
Name | Type | Description |
|---|---|---|
sessionId | string | Client's session ID |
userId | string | Player's user ID |
Methods
send
send(type: string | number, message?: T) → void
Sends a message through a specified channel to a client.
Parameter | Type | Description |
|---|---|---|
type | string | number | The identifier of the channel to send the message through. |
message (optional) | T | message Optional content of the message to be sent. |
IBroadcastOptions
interface
Options for broadcasting messages from the Multiplay Room to clients.
Properties
Name | Type | Description |
|---|---|---|
except | Specifies a client to be excluded from the broadcast. |
SandboxOptions
interface
Options for creating a Multiplay Room.
Properties
Name | Type | Description |
|---|---|---|
isSandbox | boolean | Specifies whether the Room is hosted locally, such as for QR Mobile testing in the Unity editor. |
Sandbox
class
Represents a Multiplay Room.
Properties
Name | Type | Description |
|---|---|---|
locked | boolean | Specifies whether the Multiplay Room is locked. |
roomId | string | ID of the Multiplay Room, assigned randomly upon creation to avoid duplication. |
uniqueId | string | ID of the Multiplay Room, explicitly assigned upon creation. |
maxClients | number | Maximum number of clients able to connect to the Multiplay Room. |
state | State | State of a Multiplay Room. The schema for the state data is defined by the Multiplay Schema. |
clients | IterableIterator<SandboxPlayer> | Iterable representation of the clients connected to the Multiplay Room. |
allowReconnectionTime | number | Time limit (in seconds) for allowing the reconnection of a client with an unstable connection. |
private | boolean | Specifies whether the Multiplay Room is private. |
Methods
onCreate
onCreate(options: SandboxOptions) → void | Promise<void>
Implementation of this abstract method is run once, when the Multiplay Room is created. Implementation can be optionally declared async.
Parameter | Type | Description |
|---|---|---|
options | Options for creating the Multiplay Room. |
Returns: void | Promise<void> — If asynchronous, it returns Promise<void>. Otherwise, void.
onJoin
onJoin(client: SandboxPlayer) → void | Promise<void>
Implementation of this abstract method is run when a client joins the Multiplay Room. Implementation can be optionally declared async.
Parameter | Type | Description |
|---|---|---|
client | Client object of the player. |
Returns: void | Promise<void> — If asynchronous, it returns Promise<void>. Otherwise, void.
onLeave
onLeave(client: SandboxPlayer, consented?: boolean) → void | Promise<void>
Implementation of this abstract method is run when a client leaves the Multiplay Room. Implementation can be optionally declared async.
Parameter | Type | Description |
|---|---|---|
client | Client object of the player. | |
consented (optional) | boolean | Specifies whether the player has consented to reconnect. |
Returns: void | Promise<void> — If asynchronous, it returns Promise<void>. Otherwise, void.
lock
lock() → Promise<void>
Locks the Multiplay Room.
Returns: Promise<void> — Promise resolved upon completion of the locking process.
unlock
unlock() → Promise<void>
Unlocks the Multiplay Room.
Returns: Promise<void> — Promise resolved upon completion of the unlocking process.
onTick
onTick(deltaTime: number) → void
Implementation of this method is executed approximately every 100 milliseconds.
Parameter | Type | Description |
|---|---|---|
deltaTime | number | Represents the time difference (in milliseconds) from the previous call. |
onMessage
onMessage(messageType: '*' | string | number, callback: (client: SandboxPlayer, message: T) => void) → void
Registers a callback to handle messages received from clients.
Parameter | Type | Description |
|---|---|---|
messageType | '*' | string | number | The identifier of the channel the message was sent through. |
callback | (client: SandboxPlayer, message: T) => void | Callback method to handle the received message. |
broadcast
broadcast(type: string | number, message?: any, options?: IBroadcastOptions) → void
Sends a message through a specified channel to every client connected to the Multiplay Room.
Parameter | Type | Description |
|---|---|---|
type | string | number | The identifier of the channel to send the message through. |
message (optional) | any | Optional content of the message. |
options (optional) | Broadcast options. |
loadPlayer
loadPlayer(sessionId: string) → SandboxPlayer | undefined
Gets the client object associated with a session ID.
Parameter | Type | Description |
|---|---|---|
sessionId | string | Client's session ID. |
Returns: SandboxPlayer | undefined — The client object.
setPrivate
setPrivate(isPrivate: boolean) → Promise<void>
Sets the private status of the Multiplay Room.
Parameter | Type | Description |
|---|---|---|
isPrivate | boolean | Specifies the private status of the Multiplay Room. |
Returns: Promise<void> — Promise resolved upon completion of the process.
kick
kick(client: SandboxPlayer, reason?: string) → Promise<void>
Kicks out a client from the Multiplay Room.
Parameter | Type | Description |
|---|---|---|
client | Object of the client to be kicked out. | |
reason (optional) | string | Optionally describe the reason for the kick-out. |
Returns: Promise<void> — Promise resolved upon completion of the process.