EdgeStream
Attaching a Transport
The transport is specified as part of the server registration via transportConfig. EdgeStream's TransportFactory instantiates the correct transport class from the config's type field.
How Transport Attachment Works
When you call registerServer(registration), the EdgeStream facade immediately calls createTransport(registration.transportConfig) and passes the result to the Server constructor. You never instantiate transports directly in application code.
// Internal — EdgeStream.registerServer()
registerServer(registration: IServerRegistration): void {
const transport = createTransport(registration.transportConfig); // factory
const server = new Server(registration, transport);
this.servers.set(registration.id, server);
}
TransportFactory
// TransportFactory selects the implementation based on type
export function createTransport(config: TransportConfig): ITransport {
const id = generatePrefixedId('transport');
switch (config.type) {
case 'signalr': return new SignalRTransport(id, config);
case 'websocket': return new RawWebSocketTransport(id, config);
case 'sse': return new SseTransport(id, config);
case 'http-polling': return new HttpPollingTransport(id, config);
default:
throw new Error(`Unknown transport type: ${(config as any).type}`);
}
}
TransportConfig Options
export interface TransportConfig {
type: 'signalr' | 'websocket' | 'sse' | 'http-polling';
url: string; // hub URL or endpoint
accessToken?: string; // JWT for SignalR auth
timeoutMs?: number; // connection timeout in ms
headers?: Record<string, string>; // for HTTP-based transports
queryParams?: Record<string, string>; // URL query parameters
reconnect?: {
maxAttempts: number; // 0 = infinite
initialDelayMs: number; // delay before first retry
maxDelayMs: number; // max backoff cap
backoffMultiplier: number; // exponential factor
};
}
Accessing the Transport After Registration
const server = edgeStream.server('bas')!;
// Access transport for status monitoring
console.log(server.transport.type); // 'signalr'
console.log(server.transport.status); // 'disconnected' until start()
console.log(server.transport.id); // 'transport-xxxx'
// Listen to transport status changes
server.transport.onStatusChange((status) => {
console.log('Transport status:', status);
// 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'error'
});
server.transport.onError((error) => {
console.error('Transport error:', error.message);
});