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
Name | Type | Description |
---|---|---|
type | string | number | The identifier of the channel to send the message through. |
message? | any | Optional Optional content of the message. |
options? | IBroadcastOptions | Optional Broadcast options. |
Returns
void
kick
▸ kick(client
, reason?
): Promise
<void
>
Kicks out a client from the Multiplay Room.
Parameters
Name | Type | Description |
---|---|---|
client | SandboxPlayer | Object of the client to be kicked out. |
reason? | string | Optional 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
Name | Type | Description |
---|---|---|
sessionId | string | Client's session ID. |
Returns
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
Name | Type | Description |
---|---|---|
options | SandboxOptions | Options 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
Name | Type | Description |
---|---|---|
client | SandboxPlayer | Client 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
Name | Type | Description |
---|---|---|
client | SandboxPlayer | Client object of the player. |
consented? | boolean | Optional 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
Name | Type | Description |
---|---|---|
T | any | Optionally specifies the type of message in the callback . |
Parameters
Name | 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. |
Returns
void
onTick
▸ Optional
onTick(deltaTime
): void
Implementation of this method is executed approximately every 100 milliseconds.
Parameters
Name | Type | Description |
---|---|---|
deltaTime | number | Represents 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
Name | Type | Description |
---|---|---|
isPrivate | boolean | Specifies 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.