Emit "close" for ws transport

This commit is contained in:
Kagami Hiiragi 2015-02-23 14:00:31 +03:00
parent cb917c6bda
commit 5f96a5d893

View File

@ -194,6 +194,12 @@ WsTransport.prototype.listen = function(options, callback) {
server.on("error", function(err) { server.on("error", function(err) {
self.emit("error", 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() { WsTransport.prototype.send = function() {
@ -221,10 +227,7 @@ WsTransport.prototype.close = function() {
if (this._client) { if (this._client) {
this._client.close(); this._client.close();
} else if (this._server) { } else if (this._server) {
// `ws` server terminates immediately without any events.
this._server.close(); this._server.close();
this.emit("close");
delete this._server;
} }
}; };