Skip to content

Commit a483658

Browse files
[example] Add disconnection/reconnection logs to the chat example (#2675)
1 parent 4c5dbd8 commit a483658

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

examples/chat/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $ cd socket.io
1010
$ npm install
1111
$ cd examples/chat
1212
$ npm install
13-
$ node .
13+
$ npm start
1414
```
1515

1616
And point your browser to `http://localhost:3000`. Optionally, specify

examples/chat/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"license": "BSD",
99
"dependencies": {
1010
"express": "4.13.4"
11+
},
12+
"scripts": {
13+
"start": "node index.js"
1114
}
1215
}

examples/chat/public/main.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,20 @@ $(function() {
263263
socket.on('stop typing', function (data) {
264264
removeChatTyping(data);
265265
});
266+
267+
socket.on('disconnect', function () {
268+
log('you have been disconnected');
269+
});
270+
271+
socket.on('reconnect', function () {
272+
log('you have been reconnected');
273+
if (username) {
274+
socket.emit('add user', username);
275+
}
276+
});
277+
278+
socket.on('reconnect_error', function () {
279+
log('attempt to reconnect has failed');
280+
});
281+
266282
});

0 commit comments

Comments
 (0)