Update examples to log when connection is lost

Normally, the client will send a kick packet if the client is
disconnected from the server, but if the connection is lost due to
network or lower-level protocol issues, the 'end' event will be emitted.
Log this event in the examples so it is clear why the scripts exit.
This commit is contained in:
deathcap 2016-01-23 18:06:51 -08:00
parent 46a134c5e9
commit 1349fdfc73
2 changed files with 6 additions and 0 deletions

View file

@ -18,6 +18,9 @@ client.on('connect', function() {
client.on('disconnect', function(packet) {
console.log('disconnected: '+ packet.reason);
});
client.on('end', function(err) {
console.log('Connection lost');
});
client.on('chat', function(packet) {
var jsonMsg = JSON.parse(packet.message);
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {

View file

@ -20,6 +20,9 @@ client.on('connect', function() {
client.on('disconnect', function(packet) {
console.log('disconnected: '+ packet.reason);
});
client.on('end', function(err) {
console.log('Connection lost');
});
client.on('chat', function(packet) {
var jsonMsg = JSON.parse(packet.message);
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {