Skip to content

Commit

Permalink
feat: add reconnect method
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-korsa committed Jul 28, 2020
1 parent 0dbde88 commit bceea9e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ export default class OpenWebsiteStatusAPI extends EventEmitter {

public readonly onJobDelete = this.registerEvent<(jobId: string, queryId: string) => unknown>();

private readonly socket: SocketIOClient.Socket;
private readonly options: APIOptions;

private socket!: SocketIOClient.Socket;

public constructor(options: APIOptions) {
super();
this.options = options;
this.connect();
}

this.socket = io(options.server, {
path: options.path ?? '/api-socket',
private connect () {
this.socket = io(this.options.server, {
path: this.options.path ?? '/api-socket',
});

this.socket.on('connect', () => {
Expand Down Expand Up @@ -107,5 +113,11 @@ export default class OpenWebsiteStatusAPI extends EventEmitter {

public close(): void {
this.socket.close();
this.socket.removeAllListeners();
}

public reconnect(): void {
this.close();
this.connect();
}
}

0 comments on commit bceea9e

Please sign in to comment.