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);
Type parameters
Name | Type |
---|---|
T | extends ChatProtocol = ChatProtocol |
Implements
Constructors
constructor
• new Chat<T
>(): Chat
<T
>
Type parameters
Name | Type |
---|---|
T | extends ChatProtocol = ChatProtocol |
Returns
Chat
<T
>
Properties
onChat
• onChat: (chat
: T
) => void
Type declaration
▸ (chat
): void
Parameters
Name | Type |
---|---|
chat | T |
Returns
void
Accessors
commandSymbol
• get
commandSymbol(): string
The symbol that is used to trigger commands.
Returns
string
commandSymbolCode
• get
commandSymbolCode(): string
Returns
string
Methods
addCommand
▸ addCommand(trigger
, process
, aliases?
): () => void
Add a command to the chat system. Commands are case sensitive.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
trigger | string | undefined | The text to trigger the command, needs to be one single word without spaces. |
process | CommandProcessor | undefined | The process run when this command is triggered. |
aliases | string [] | [] | - |
Returns
fn
▸ (): void
Add a command to the chat system. Commands are case sensitive.
Returns
void
removeCommand
▸ removeCommand(trigger
): boolean
Remove a command from the chat system. Case sensitive.
Parameters
Name | Type | Description |
---|---|---|
trigger | string | The trigger to remove. |
Returns
boolean
send
▸ send(chat
): void
Send a chat to the server.
Parameters
Name | Type | Description |
---|---|---|
chat | T | The chat message to send. |
Returns
void
setFallbackCommand
▸ setFallbackCommand(fallback
): void
Set a fallback command to be executed when no matching command is found.
Parameters
Name | Type | Description |
---|---|---|
fallback | CommandProcessor | The fallback command processor. |
Returns
void