Skip to content

Commit

Permalink
fix: reset connected/connecting state when disconnecting and disposing
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Aug 26, 2020
1 parent 9ccb46b commit 2eb3cd5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ export function createClient(options: ClientOptions): Client {
// equal to 1 because this sink is the last one.
// the deletion from the map happens afterwards
if (Object.entries(subscribedSinks).length === 1) {
connected = false;
connecting = false;
if (socket.readyState === WebSocket.OPEN) {
socket.close(1000, 'Normal Closure');
}
Expand All @@ -268,6 +270,8 @@ export function createClient(options: ClientOptions): Client {

// if there is an active socket, close it with a normal closure
if (socket && socket.readyState === WebSocket.OPEN) {
connected = false;
connecting = false;
// TODO-db-200817 decide if `1001: Going Away` should be used instead
socket.close(1000, 'Normal Closure');
socket = null;
Expand Down

0 comments on commit 2eb3cd5

Please sign in to comment.