Skip to main content

Client Engine Hooks

Client engine hooks allow you to listen to client-side events and customize client behavior. These hooks are defined in the engine property of your client module.

Usage

Available Hooks

onStart

Description: Called when the client engine starts. Return false to prevent connection to the server. Parameters:
  • engine: RpgClientEngine - The client engine instance
Returns:
  • boolean | void - Return false to prevent server connection
Example:

onStep

Description: Called at each frame (typically 60 FPS) Parameters:
  • engine: RpgClientEngine - The client engine instance
  • t: number - Current timestamp
  • dt: number - Delta time since last frame
Example:

onInput

Description: Called when movement or action input is detected Parameters:
  • engine: RpgClientEngine - The client engine instance
  • obj: { input: string | number, action?: string | number, data?: any, playerId: number } - Input data
Example:

onConnected

Description: Called when the client successfully connects to the server. In MMORPG mode, this hook runs only after the server sends the RPGJS acceptance packet, so a refused auth() does not trigger it. Parameters:
  • engine: RpgClientEngine - The client engine instance
  • socket: any - The socket connection instance
Example:

onDisconnect

Description: Called when the client disconnects from the server Parameters:
  • engine: RpgClientEngine - The client engine instance
  • reason: any - Disconnection reason
  • socket: any - The socket connection instance
Example:

onConnectError

Description: Called when there’s an error connecting to the server. In MMORPG mode, this is also called when server-side auth() refuses the WebSocket connection. Parameters:
  • engine: RpgClientEngine - The client engine instance
  • err: any - The connection error
  • socket: any - The socket connection instance
Example:
onStart means the client engine is booting. It does not guarantee that the player has been accepted by the server. Use onConnected for accepted connections and onConnectError to show a login screen, refresh a token, or redirect the player after an authentication failure.

onWindowResize

Description: Called when the browser window is resized Example:

Complete Example