EdgeStream
Creating a Server
Servers are created via edgeStream.registerServer(registration) — never directly. The registration object combines identity, URL, type, and transport configuration.
IServerRegistration
export interface IServerRegistration {
id: string; // unique ID in this EdgeStream instance
type: ServerType; // 'bas' | 'chat'
name?: string; // human-readable display name
url: string; // server/hub URL
transportConfig: TransportConfig; // which transport + connection settings
}
Registration Examples
SignalR Server (Recommended for Browser Apps)
edgeStream.registerServer({
id: 'bas',
type: 'bas',
name: 'BizFirstGO Application Server',
url: 'https://app.bizfirst.com/edge-stream-hub',
transportConfig: {
type: 'signalr',
url: 'https://app.bizfirst.com/edge-stream-hub',
accessToken: authService.getToken, // string or () => string | Promise<string>
reconnect: {
maxAttempts: 0, // 0 = infinite retries
initialDelayMs: 1000, // wait 1s before first retry
maxDelayMs: 60000, // cap backoff at 60 seconds
backoffMultiplier: 2, // double the delay each attempt
},
timeoutMs: 30000, // connection timeout
}
});
WebSocket Server (Performance-Critical)
edgeStream.registerServer({
id: 'chat',
type: 'chat',
url: 'wss://chat.bizfirst.com/ws',
transportConfig: {
type: 'websocket',
url: 'wss://chat.bizfirst.com/ws',
headers: {
'Authorization': `Bearer ${token}`,
'X-Tenant-Id': tenantId,
},
reconnect: { maxAttempts: 5, initialDelayMs: 500, maxDelayMs: 5000, backoffMultiplier: 2 },
}
});
SSE Server (Server Push Only)
edgeStream.registerServer({
id: 'events',
type: 'bas',
url: '/api/edge-stream/events',
transportConfig: {
type: 'sse',
url: '/api/edge-stream/events',
queryParams: {
tenantId: currentTenantId,
userId: currentUserId,
},
}
});
Accessing the Registered Server
// After registration
const server = edgeStream.server('bas'); // returns IServer | undefined
if (!server) {
throw new Error('Server bas not registered');
}
// Non-null assertion (when you know it's registered)
const server = edgeStream.server('bas')!;
console.log(server.id); // 'bas'
console.log(server.type); // 'bas'
console.log(server.status); // 'disconnected' (until start() is called)
Preventing Double Registration
Calling registerServer with an ID that already exists logs a warning and returns — it does not overwrite the existing server:
// Internal behavior (from EdgeStream.ts)
registerServer(registration: IServerRegistration): void {
if (this.servers.has(registration.id)) {
this.logger.warn(`Server ${registration.id} already registered`);
return; // silently skip — does not replace existing server
}
// ... create and store server
}