Properly close chat example when connection fails or errors

This commit is contained in:
roblabla 2015-03-06 16:43:05 +00:00
parent d8b1ce68ac
commit e94876d30a

View file

@ -84,13 +84,24 @@ client.on([states.PLAY, 0x40], function(packet) { // you can listen for packets
console.info(color('Kicked for ' + packet.reason, "blink+red"));
process.exit(1);
});
var chats = [];
client.on('connect', function() {
console.info(color('Successfully connected to ' + host + ':' + port, "blink+green"));
});
client.on('end', function() {
console.log("Connection lost");
process.exit();
});
client.on('error', function(err) {
console.log("Error occured");
console.log(err);
process.exit(1);
});
client.on('state', function(newState) {
if (newState === states.PLAY) {
chats.forEach(function(chat) {
@ -159,4 +170,4 @@ function parseChat(chatObj, parentState) {
}
return chat;
}
}
}