Emit "close" for ws transport

This commit is contained in:
Kagami Hiiragi 2015-02-23 14:00:31 +03:00
parent cb917c6bda
commit 5f96a5d893
1 changed files with 6 additions and 3 deletions

View File

@ -194,6 +194,12 @@ WsTransport.prototype.listen = function(options, callback) {
server.on("error", function(err) {
self.emit("error", err);
});
// `ws` doesn't emit "close" event by default.
server._server.on("close", function() {
self.emit("close");
delete self._server;
});
};
WsTransport.prototype.send = function() {
@ -221,10 +227,7 @@ WsTransport.prototype.close = function() {
if (this._client) {
this._client.close();
} else if (this._server) {
// `ws` server terminates immediately without any events.
this._server.close();
this.emit("close");
delete this._server;
}
};