Skip to main content

Class: Room<StateProps, MoreMessageTypes>

Type parameters

NameType
StatePropsRecord<string, any>
MoreMessageTypesextends Record<string, unknown> = Record<string, unknown>

Constructors

constructor

new Room<StateProps, MoreMessageTypes>(room)

Type parameters

NameType
StatePropsRecord<string, any>
MoreMessageTypesextends Record<string, unknown> = Record<string, unknown>

Parameters

NameType
roomcolyseusRoom

Properties

room

room: colyseusRoom

Accessors

id

get id(): string

Returns

string


sessionID

get sessionID(): string

Returns

string


state

get state(): ClientGameState<StateProps>

Returns

ClientGameState<StateProps>

Methods

destroy

destroy(): void

Returns

void


leave

leave(): void

Returns

void


onError

onError(code, message): void

Parameters

NameType
codenumber
messagestring

Returns

void


onFirstStateChange

onFirstStateChange(state): void

Parameters

NameType
stateClientGameState<StateProps>

Returns

void


onLeave

onLeave(code): void

Parameters

NameTypeDescription
codenumberwebSocket shutdown code

Returns

void


onMessage

onMessage<M, T>(type, callback): () => void

Subscribe to messages from the server

Type parameters

NameType
Mextends RecordOfServerMessages<MoreMessageTypes & { *: unknown }> & ServerMessageTypes
Textends string | number | symbol

Parameters

NameType
typeT
callback(message: M[T]) => void

Returns

fn

method to unsubscribe

▸ (): void

Subscribe to messages from the server

Returns

void

method to unsubscribe


onStateChange

onStateChange(state): void

Parameters

NameType
stateClientGameState<StateProps>

Returns

void


send

send<T>(type, message?): void

Send a custom message from client to server.

Type parameters

NameType
Textends keyof ClientMessageTypes

Parameters

NameType
typeT
message?ClientMessageTypes[T]

Returns

void


sendInteraction

sendInteraction(interaction, entityIdxPath, data?): void

Sends an event related to entity interaction.

Parameters

NameTypeDefault valueDescription
interactionInteractionTypeundefined-
entityIdxPathnumber[]undefinedidx path to entity of interaction
dataanyundefined-

Returns

void