diff --git a/src/index.ts b/src/index.ts index 6e223a7..2736492 100644 --- a/src/index.ts +++ b/src/index.ts @@ -587,6 +587,7 @@ export class DCRFClient implements IStreamingAPI { this.queue.processQueue(); } + public buildMultiplexedMessage(stream: string, payload: object): object { return { stream, payload }; } diff --git a/src/interface.ts b/src/interface.ts index 29161ae..e8bd87d 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,4 +1,4 @@ -import { Options as ReconnectingWebsocketOptions } from 'reconnecting-websocket'; +import ReconnectingWebSocket, { Options as ReconnectingWebsocketOptions } from 'reconnecting-websocket'; import { Logger } from 'winston'; export @@ -111,6 +111,7 @@ export type TransportEvent = 'open' | 'connect' | 'reconnect' | 'message' | 'err export interface ITransport { + /** * Initiate the transport's connection * @@ -140,6 +141,7 @@ interface ITransport { * - "connect": on initial connection * - "reconnect": when the connection is lost, then reestablished * - "message": when a message is received + * - "error": when an error occurs */ on(name: TransportEvent, handler: (...args: any) => void): any | null; diff --git a/src/transports/websocket.ts b/src/transports/websocket.ts index 1b8df83..f3474a7 100644 --- a/src/transports/websocket.ts +++ b/src/transports/websocket.ts @@ -46,6 +46,7 @@ export class WebsocketTransport extends EventEmitter implements ITransport { this.socket.addEventListener("message", this.handleMessage); this.socket.addEventListener("open", this.handleOpen); + this.socket.addEventListener("error", this.handleError); return true; } @@ -79,6 +80,11 @@ export class WebsocketTransport extends EventEmitter implements ITransport { this.socket.send(bytes); } + @autobind + protected handleError(event: Event) { + this.emit("error", event); + } + @autobind protected handleMessage(event: Event) { this.emit("message", event);