onEvent

View as MarkdownOpen in Claude

Register a low-level callback that fires for every inbound signalwire.event, regardless of type. This is a generic escape hatch that runs before the typed onCall() / onMessage() routing.

Most applications should use the typed onCall() and onMessage() handlers instead. Use onEvent() only when you need to observe raw events the typed handlers don’t cover.

Parameters

handler
(eventType: string, params: Record<string, any>) => void | Promise<void>Required

Callback fired for every inbound event. Receives the event type and its raw params. May be async. Errors thrown here are logged but never tear down the dispatcher.

Returns

The same handler, returned to support decorator-style usage.

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_API_TOKEN!,
6 contexts: ['default'],
7});
8
9client.onEvent((eventType, params) => {
10 console.log(`Event: ${eventType}`, params);
11});
12
13await client.run();