Skip to content

Commit

Permalink
[example] Add disconnection/reconnection logs to the chat example (so…
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne authored Nov 18, 2016
1 parent 4c5dbd8 commit a483658
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ cd socket.io
$ npm install
$ cd examples/chat
$ npm install
$ node .
$ npm start
```

And point your browser to `http://localhost:3000`. Optionally, specify
Expand Down
3 changes: 3 additions & 0 deletions examples/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"license": "BSD",
"dependencies": {
"express": "4.13.4"
},
"scripts": {
"start": "node index.js"
}
}
16 changes: 16 additions & 0 deletions examples/chat/public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,20 @@ $(function() {
socket.on('stop typing', function (data) {
removeChatTyping(data);
});

socket.on('disconnect', function () {
log('you have been disconnected');
});

socket.on('reconnect', function () {
log('you have been reconnected');
if (username) {
socket.emit('add user', username);
}
});

socket.on('reconnect_error', function () {
log('attempt to reconnect has failed');
});

});

0 comments on commit a483658

Please sign in to comment.