mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-20 10:10:25 -04:00
client emits more predictable 'end' event
This commit is contained in:
parent
bb76dc8b0a
commit
1a434b9743
1 changed files with 18 additions and 8 deletions
|
@ -41,17 +41,27 @@ Client.prototype.setSocket = function(socket) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.socket.on('error', function(err) {
|
|
||||||
self.emit('error', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.socket.on('close', function() {
|
|
||||||
self.emit('end', self._endReason);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.socket.on('connect', function() {
|
self.socket.on('connect', function() {
|
||||||
self.emit('connect');
|
self.emit('connect');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.socket.on('error', onError);
|
||||||
|
self.socket.on('close', endSocket);
|
||||||
|
self.socket.on('end', endSocket);
|
||||||
|
self.socket.on('timeout', endSocket);
|
||||||
|
|
||||||
|
function onError(err) {
|
||||||
|
self.emit('error', err);
|
||||||
|
endSocket();
|
||||||
|
}
|
||||||
|
|
||||||
|
function endSocket() {
|
||||||
|
self.socket.removeListener('error', onError);
|
||||||
|
self.socket.removeListener('close', endSocket);
|
||||||
|
self.socket.removeListener('end', endSocket);
|
||||||
|
self.socket.removeListener('timeout', endSocket);
|
||||||
|
self.emit('end', self._endReason);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.connect = function(port, host) {
|
Client.prototype.connect = function(port, host) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue