---
title: Multiplay Room
slug: world-sdk-guide/multiplay-room
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

## Room Connection Process

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-9_rdZyDRLkm1_dgfSR1fh-20240904-102419.png)

:::hint{type="success"}
👍 **Room Connection Process**

1. Request connection from client
2. ZEPETO Multiplay server generates the Client Session and connects to Room
3. If Room is successfully connected
   - share the Room ID and Session ID connected to the client
4. If the client cannot access the Room
   - generate a new Room and connect
:::



## Server API

The server code should be implemented in World.multiplay package → index.ts file.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-dplxIaxdzMxhJzX_l0cAg-20240904-102419.png)



Server provides the following Room Lifecycle events:

| **Room Lifecycle Event**                            | **Description**                                                                                                               |
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| onCreate(options: SandboxOptions)                   | Called once room has been created. Room initialize logic can be added here.                                                   |
| onJoin(client: SandboxPlayer)                       | Called when the client joined the room.<br />The parameter client (SandboxPlayer) contains the client's sessionId identifier. |
| onLeave(client: SandboxPlayer, consented?: boolean) | Called when the client left the room.<br />The parameter consented is true when the disconnect is requested by the client.    |
| onTick(deltaTime: number)                           | Step interval event call on server side, the interval time can be set in SandboxOptions.<br />(tickInterval : 100ms)          |

:::hint{type="danger"}
- The `OnLeave()` event occurs when you press 'Home button > Leave' in the upper left corner during mobile test status.
  - The `OnLeave()` event does not occur in the Unity editor.
:::



If you're interested in the ZEPETO.Multiplay Server API, refer to the documentation:

:::hint{type="info"}
**📘&#x20;**&#x50;lease refer to the following guide. \[[ZEPETO.Multiplay(Server) API](https://developer.zepeto.me/docs/multiplay-server/)]
:::



## Client API

ZepetoWorldMultiplay component provides an interface for clients to subscribe to the World play session (Room) events from ZEPETO Multiplay server.

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-xYDw9NldehRFhDN7rCOqA-20240904-102419.png)

List of available events:

| **Room EventListener**    | **Description**                                                                                  |
| ------------------------- | ------------------------------------------------------------------------------------------------ |
| RoomCreated(Room)         | Called when a Room is created and accessible. Provides a Room parameter.                         |
| RoomJoined(Room)          | Called when a Room is connected. Provides a Room parameter.                                      |
| RoomLeave(RoomLeaveEvent) | Called when disconnecting from a Room.<br />Provides a RoomLeaveEvent parameter.                 |
| RoomReconnected(Room)     | Called when the corresponding Room is reconnected. Provides a Room parameter.                    |
| RoomError(RoomErrorEvent) | Called when an error occurs in the corresponding Room.<br />Provides a RoomErrorEvent parameter. |
| RoomWeakConnection        | Called when the connection is unstable.                                                          |

