From 54d335a581556a80dd6b2772c810295bf3ef7781 Mon Sep 17 00:00:00 2001 From: PaperElectron Date: Thu, 27 Jun 2013 01:27:39 -0400 Subject: [PATCH 1/4] Update Read Me with an example clean shutdown command. --- lib/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/README.md b/lib/README.md index 48b81c8..f519ef1 100644 --- a/lib/README.md +++ b/lib/README.md @@ -1,4 +1,3 @@ - # API Reference This gives details on the new top level objects for __express.io__. @@ -40,6 +39,14 @@ app.io.route('special', function(req) { }) ``` +You can also access all of the socket.io sockets, an example to disconnect all clients before shutdown +```js +app.io.sockets.clients().forEach(function (socket) { + socket.disconnect(); + logger.info(socket.username + ' disconnected for shutdown'); +}); +``` + You can also use the `AppIO` object to configure your io server. For available options, check [here](https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO). ```js From c0ccfeff26bdb8cdadac816d17bd119f84c6f74b Mon Sep 17 00:00:00 2001 From: PaperElectron Date: Thu, 27 Jun 2013 01:35:35 -0400 Subject: [PATCH 2/4] Added external routes file example --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2082488..1543c25 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,24 @@ app.io.route('my-realtime-route', function(req) { // respond to the event }); ``` - +Or put your routes into a separate file for that nice and tidy look +```js +//in app.js pass in "app" so you can use it anywhere. +var realtime = require('./realtime')(app) + +//in realtime.js +module.exports = function(app){ + return { + ready: function(req) { + req.io.emit('lessClutter', {separate: "those concerns"}) + }, + + set: function(req){ + app.io.broadcast('talkToServer', {to: "Everyone."}) + } + } +}; +``` ## Automatic Session Support Sessions work automatically, just set them up like normal using express. From e56b92823ea0e8bd0d11d0ffa52894abae24dcc2 Mon Sep 17 00:00:00 2001 From: PaperElectron Date: Thu, 27 Jun 2013 01:36:38 -0400 Subject: [PATCH 3/4] Amend last commit, external routes file example --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1543c25..20dfa78 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,6 @@ module.exports = function(app){ ready: function(req) { req.io.emit('lessClutter', {separate: "those concerns"}) }, - set: function(req){ app.io.broadcast('talkToServer', {to: "Everyone."}) } From 302c12e0e2ae8cfcb764579ae15c0a97f36ac785 Mon Sep 17 00:00:00 2001 From: PaperElectron Date: Thu, 27 Jun 2013 01:38:15 -0400 Subject: [PATCH 4/4] Update Readme with External routing example. again --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 20dfa78..c349f14 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Or put your routes into a separate file for that nice and tidy look ```js //in app.js pass in "app" so you can use it anywhere. var realtime = require('./realtime')(app) +app.io.route('ready', realtime.ready ) //in realtime.js module.exports = function(app){