Chat module
@rpgjs/chat is an optional RPGJS v5 module with a server-authoritative
message flow:
- The client submits text and a requested channel.
- The server normalizes and validates the text, applies rate limits and moderation, and reconstructs the author and timestamp.
- The server broadcasts the accepted
ChatMessage. - Each client stores the message in a reactive signal and renders it.
Install
@rpgjs/ui-css.
Configure the client
Use the explicit client entry point. This prevents server code from entering a browser bundle when standalone mode loads both runtime entry graphs.Client options
maxMessages limits client memory only. It does not create permanent history.
The server remains authoritative for maxLength; configure the same value on
both sides so the built-in input rejects exactly the same message lengths.
Configure the server
Use the explicit server entry point and register it beforeprovideServerModules():
map; any explicitly
supplied value other than map or global is rejected.
Server options and hooks
The hook order is:
Moderation example
Global chat
Global chat is opt-in because the correct broadcast mechanism depends on the deployment topology. Enable the channel and provide an adapter:Client API
Replacement components and client modules can import:sendChatMessage() does not add an optimistic message. The UI changes only
after the server broadcasts the accepted ChatMessage.
Message contract
Replace the CanvasEngine component
A replacement component does not receive the message history as props. Instead, it consumes the public chat signals. GUI data contains the configuredposition and maxLength.
Create gui/custom-chat.ce:
DOMContainer binds value={draft} in both directions.
submit={submitMessage} prevents the browser’s default form navigation and
passes (event, formData) to the handler.
Register the replacement:
Use a Vue component
Install and configure the RPGJS Vue overlay as described in Vue.js integration, then use a Vue component as the replacement:chatMessages.observable and
chatError.observable, and submit with sendChatMessage(). Remember to
unsubscribe when the component unmounts.
Themes and CSS
The default component uses semanticrpg-ui-* classes. Import the base theme:
<body>:
Errors and translations
The default client module provides these English translation keys:chatError through engine.i18n().t() instead of exposing raw
translation keys.
Run the pixel chat playground
The repository includes a complete standalone and MMORPG-compatible example:http://localhost:5189. The example demonstrates map broadcast, rate
limiting, an afterSend automated reply, a CanvasEngine GUI, and the shared
pixel theme.
Private messages, voice chat, and permanent history are intentionally outside
the core module.