Skip to content

Commit

Permalink
CloseEvent error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Phineas committed Nov 12, 2019
1 parent f49bd1e commit 12f26ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions build/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ var SwarmClient = /** @class */ (function (_super) {
}
});
socket.addEventListener('close', function (event) {
_this.state = "closed";
_this.emit("SOCKET_STATE_CHANGE", "closed");
switch (event.code) {
case 4003: {
_this.state = event.reason;
_this.emit("SOCKET_STATE_CHANGE", event.reason);
}
default: {
_this.state = "closed";
_this.emit("SOCKET_STATE_CHANGE", "closed");
}
}
});
};
SwarmClient.prototype.sendRaw = function (data) {
Expand Down
12 changes: 10 additions & 2 deletions swarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ export class SwarmClient extends EventEmitter {
});

socket.addEventListener('close', (event) => {
this.state = "closed";
this.emit("SOCKET_STATE_CHANGE", "closed");
switch(event.code) {
case 4003: {
this.state = event.reason;
this.emit("SOCKET_STATE_CHANGE", event.reason);
}
default: {
this.state = "closed";
this.emit("SOCKET_STATE_CHANGE", "closed");
}
}
});
}

Expand Down

0 comments on commit 12f26ee

Please sign in to comment.