Permalink
Browse files

[example] Add disconnection/reconnection logs to the chat example (#2675

)
  • Loading branch information...
1 parent 4c5dbd8 commit a48365860748a5006f6dd80a710008e18aeac89b @darrachequesne darrachequesne committed on GitHub Nov 18, 2016
Showing with 20 additions and 1 deletion.
  1. +1 −1 examples/chat/README.md
  2. +3 −0 examples/chat/package.json
  3. +16 −0 examples/chat/public/main.js
@@ -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
@@ -8,5 +8,8 @@
"license": "BSD",
"dependencies": {
"express": "4.13.4"
+ },
+ "scripts": {
+ "start": "node index.js"
}
}
@@ -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.