Skip to content

Web-Socket Client

The client instance present on:

Note

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.

Properties

sessionId: string

Unique id per session.

Note

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

auth: any

Custom data you return during onAuth().

Methods

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 message:

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

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

leave(code?: number)

Force disconnection of the client with the room.

Tip

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