Skip to main content
Add handlers with one of three methods, based on what you want to catch:
  • onChannel / on_channel — events on one channel.
  • onAnyChannel / on_any_channel — every channel event, on any channel.
  • onLifecycle / on_lifecycle — connection state: open, close, reconnect, error.

Channel events

A channel event has an id (the subscription it came from), a channel, and data (the decoded payload).
radion.realtime.onChannel("trading", (e) => {
  console.log(e.id, e.channel, e.data);
});

// every channel event
radion.realtime.onAnyChannel((e) => console.log(e.channel, e.data));
In TypeScript, onChannel(name, …) narrows event.data to that channel’s typed payload; the catch-all events() stream yields AnyChannelPayload. In Python ChannelEvent is generic over the payload and defaults to Any. In Rust data is the typed Payload enum, so match on it and the compiler checks you handle every case.

Lifecycle events

EventPayload
open
close{ code, reason }
reconnect{ attempt, delayMs } (TS) / { "attempt", "delay" } (Python) / Reconnect { attempt, delay } (Rust)
errorAn Error (often RadionServerError) / Error(RadionError) (Rust)
radion.realtime.onLifecycle("open", () => console.log("connected"));
radion.realtime.onLifecycle("close", ({ code, reason }) =>
  console.log("closed", code, reason)
);
radion.realtime.onLifecycle("reconnect", ({ attempt, delayMs }) =>
  console.log(`reconnect #${attempt} in ${delayMs}ms`)
);
radion.realtime.onLifecycle("error", (err) => console.error(err));
In Python, handlers can be sync or async. In TypeScript, each on* method returns the client, so you can chain calls. In Rust, channel and lifecycle events come as Streams (events(), per-subscription subscribe(...), and lifecycle()); drop the stream to stop reading. To remove a handler, use the matching off* method (offChannel / off_channel, offAnyChannel / off_any_channel, offLifecycle / off_lifecycle). Leave out the handler to remove all of them for that target.
If one of your handlers throws, the SDK reports it through the error event and does not retry it. It never blocks the other handlers from getting the event.
Last modified on July 5, 2026