Skip to content

Realtime

SemitraChannel is the realtime subsystem in Semitra.

Use it for live, connection-oriented interactions where clients subscribe, receive messages, and participate in rooms.

Channels provide:

  • subscription lifecycle handling
  • inbound message parsing
  • room membership tracking
  • broadcasting
  • socket attach and detach handling
  • event observation
  • optional Durable Object coordination through a hub

The example app uses a notifications channel:

import { s } from "@semitra/cli";
import ApplicationChannel from "./application_channel.ts";
export const NotificationMessage = s.object({
type: s.string(),
body: s.string()
});
export default class NotificationsChannel extends ApplicationChannel<{
type: string;
body: string;
}> {
static message = NotificationMessage;
protected async subscribed(): Promise<void> {
await this.join("notifications");
this.transmit({ status: "connected", room: "notifications" });
}
protected async received(payload): Promise<void> {
await this.broadcastTo("notifications", {
ok: true,
type: payload.type,
body: payload.body,
room: "notifications"
});
}
}
  • live notifications
  • collaborative room updates
  • chat or presence events
  • live status indicators
  • streaming application state to connected clients

Realtime coordination maps naturally to Durable Objects because channels often need:

  • a room coordinator
  • a shared membership list
  • consistent broadcast fan-out
  • heartbeat or touch semantics

Semitra keeps that coordination abstract, but the platform fit is explicit.