Skip to content

Web-Socket Client

The client instance present on:


This is the raw WebSocket connection coming from the ws package. There are more methods available which aren't encouraged to use along with Colyseus.


sessionId: string

Unique id per session.


In the client-side, you can find the sessionId in the room instance.

auth: any

Custom data you return during onAuth().


send(type, message)

Send message a type of message to the client. Messages are encoded with MsgPack and can hold any JSON-seriazeable data structure.

The type can be either a string or a number.

Sending a msgpack-encoded message:

// sending message with string type
client.send("powerup", { type: "ammo" });

// sending message with number type
client.send(1, { type: "ammo"});

Sending a schema-encoded message:

Sending schema-encoded messages is particularly useful for statically-typed languages such as C#.

class MyMessage extends Schema {
  @type("string") message: string;

const data = new MyMessage();
data.message = "Hello world!";


leave(code?: number)

Force disconnection of the client with the room.


This will trigger room.onLeave event on the client-side.

error(code, message)

Send an error with code and message to the client. The client can handle it on onError