Skip to content

Channels Overview

This page covers TypeScript-specific channel details. For the general concept of what a channel is, see Channels.

All channels implement ICommandChannel. Create custom transports (WebSocket, gRPC, etc.) by implementing this interface:

interface ICommandChannel {
readonly id: string
start(): Promise<void>
close(): Promise<void>
sendMessage(message: unknown): void
on(event: 'message', listener: (message: unknown) => void): void
on(event: 'close', listener: () => void): void
}
MethodDescription
idUnique identifier for this channel
start()Initialize the channel (called automatically by the registry)
close()Close the channel and clean up resources
sendMessage()Send a message through the channel
on('message')Subscribe to incoming messages
on('close')Subscribe to channel close events
const channel = new MessagePortChannel('worker', workerPort)
await registry.registerChannel(channel)