Skip to content

Commit

Permalink
Added 'error' TransportEvent option
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro committed Dec 10, 2023
1 parent 2ce9d10 commit cac5818
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ export class DCRFClient implements IStreamingAPI {
this.queue.processQueue();
}


public buildMultiplexedMessage(stream: string, payload: object): object {
return { stream, payload };
}
Expand Down
4 changes: 3 additions & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options as ReconnectingWebsocketOptions } from 'reconnecting-websocket';
import ReconnectingWebSocket, { Options as ReconnectingWebsocketOptions } from 'reconnecting-websocket';
import { Logger } from 'winston';

export
Expand Down Expand Up @@ -111,6 +111,7 @@ export type TransportEvent = 'open' | 'connect' | 'reconnect' | 'message' | 'err

export
interface ITransport {

/**
* Initiate the transport's connection
*
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/transports/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cac5818

Please sign in to comment.