Skip to main content

A network interceptor that gives flexible control over the chat feature of the game. This also allows for custom commands to be added.

Example

const chat = new VOXELIZE.Chat();

// Listen to incoming chat messages.
chat.onChat = (chat: ChatMessage) => {
console.log(chat);
};

// Sending a chat message.
chat.send({
type: "CLIENT",
sender: "Mr. Robot",
body: "Hello world!",
});

// Register to the network.
network.register(chat);

Chat

Type parameters​

NameType
Textends ChatProtocol = ChatProtocol

Implements​

Constructors​

constructor​

• new Chat<T>(): Chat<T>

Type parameters​

NameType
Textends ChatProtocol = ChatProtocol

Returns​

Chat<T>

Properties​

joinHistory​

• joinHistory: ChatHistoryUpdate = null

The history replay of the latest (re)join, kept so a listener attached after the INIT arrived can still read it.


onChat​

• onChat: (chat: T) => void

Type declaration​

▸ (chat): void

Parameters​
NameType
chatT
Returns​

void


onHistory​

• Optional onHistory: (update: ChatHistoryUpdate) => void

Called with every page of the world's chat history: the replay a (re)join brings, then each page requestHistory asks for. Those lines never pass through onChat, so nothing a live line triggers (speech bubbles, client actions in its metadata) runs again for them.

Type declaration​

▸ (update): void

Parameters​
NameType
updateChatHistoryUpdate
Returns​

void

Accessors​

commandSymbol​

• get commandSymbol(): string

The symbol that is used to trigger commands.

Returns​

string


commandSymbolCode​

• get commandSymbolCode(): string

Returns​

string


isHistoryPending​

• get isHistoryPending(): boolean

Whether a history page request is waiting for its answer.

Returns​

boolean

Methods​

addCommand​

▸ addCommand<T>(trigger, process, options): () => void

Add a command to the chat system. Commands are case sensitive.

Type parameters​

NameType
Textends ZodObject<Record<string, ZodTypeAny>, UnknownKeysParam, ZodTypeAny, {}, {}> = ZodObject<Record<string, never>, UnknownKeysParam, ZodTypeAny, {}, {}>

Parameters​

NameTypeDescription
triggerstringThe text to trigger the command, needs to be one single word without spaces.
process(args: TypeOf<T>) => voidThe process run when this command is triggered, receives parsed typed args.
optionsCommandOptions<T>Configuration for the command including Zod schema for args.

Returns​

fn

▸ (): void

Returns​

void


getAllCommands​

▸ getAllCommands(): { aliases: string[] ; args: ArgMetadata[] ; category?: string ; description: string ; flags: string[] ; isTabCompletePreFiltered: boolean ; trigger: string }[]

Get all registered commands with their documentation. This filters out aliases and returns only the primary command triggers.

Returns​

{ aliases: string[] ; args: ArgMetadata[] ; category?: string ; description: string ; flags: string[] ; isTabCompletePreFiltered: boolean ; trigger: string }[]

An array of command triggers with their descriptions, categories, aliases, and arg schemas.


removeCommand​

▸ removeCommand(trigger): boolean

Remove a command from the chat system. Case sensitive.

Parameters​

NameTypeDescription
triggerstringThe trigger to remove.

Returns​

boolean


requestHistory​

▸ requestHistory(before, limit?): boolean

Ask the server for up to limit lines older than before (a line's seq). One request is in flight at a time; returns whether this one was queued.

Parameters​

NameTypeDefault value
beforenumberundefined
limitnumberCHAT_HISTORY_PAGE_SIZE

Returns​

boolean


send​

▸ send(chat): void

Send a chat to the server.

Parameters​

NameTypeDescription
chatTThe chat message to send.

Returns​

void


setFallbackCommand​

▸ setFallbackCommand(fallback): void

Set a fallback command to be executed when no matching command is found.

Parameters​

NameTypeDescription
fallback(rest: string) => voidThe fallback command processor.

Returns​

void