Skip to content

Commit

Permalink
feat: reconnect when disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Mar 3, 2024
1 parent b9f99ad commit 8baf646
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/drivers/DatabaseDriver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,20 @@ export default class DatabaseDriver {
protected client: hrana.WsClient;
protected stream?: hrana.WsStream;
protected endpoint: string = "";
protected authToken = "";

constructor(url: string, authToken: string) {
this.endpoint = url;
this.client = hrana.openWs(url, authToken);
this.authToken = authToken;
this.client = hrana.openWs(this.endpoint, this.authToken);
}

protected connect() {
if (this.stream) {
this.stream.close();
}

this.client = hrana.openWs(this.endpoint, this.authToken);
}

protected escapeId(id: string) {
Expand All @@ -90,6 +100,11 @@ export default class DatabaseDriver {

protected getStream(): hrana.WsStream {
if (this.stream) {
if (this.client.closed) {
console.info("Reconnect");
this.connect();
}

if (this.stream.closed) {
console.info("Open Stream");
this.stream = this.client.openStream();
Expand Down

0 comments on commit 8baf646

Please sign in to comment.