Synclets logoSynclets

createDurableObjectBrokerTransport

The createDurableObjectBrokerTransport function creates a transport for brokering WebSocket messages within a Cloudflare Durable Object.

createDurableObjectBrokerTransport(options: DurableObjectBrokerTransportOptions): DurableObjectBrokerTransport
TypeDescription
optionsDurableObjectBrokerTransportOptions

The transport options, including the Durable Object reference.

returnsDurableObjectBrokerTransport

A broker transport configured for the Durable Object.

This transport enables path-based message isolation, where clients on different paths cannot communicate with each other, even though they're all connected to the same Durable Object instance. It's commonly used with BrokerOnlyDurableObject to create stateless broker servers.

Example

class MyBrokerDurableObject extends SyncletDurableObject {
  getCreateComponents() {
    return {
      transport: createDurableObjectBrokerTransport({
        durableObject: this,
        path: null, // Broker-only mode
        brokerPaths: /^room-[a-z0-9]+$/, // Only accept specific room paths
      }),
    };
  }
}

Since

v0.0.7