Skip to content

Commit d482fb6

Browse files
committed
first commit
0 parents  commit d482fb6

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Readme.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# weplay-presence
3+
4+
Small script that aggregates the count of connected clients from
5+
each weplay server and broadcasts it.
6+
7+
## How to install
8+
9+
```js
10+
$ npm install
11+
```
12+
13+
And run it with the following ENV vars:
14+
15+
- `WEPLAY_REDIS` - redis uri (`localhost:6379`)
16+
- `WEPLAY_INTERVAL` - how often we update clients on the total
17+
number of connected peers. We use an interval to avoid client slowdowns
18+
when too many clients connect at once (`5000`)
19+
20+
```
21+
$ node index
22+
```
23+
24+
## License
25+
26+
MIT

index.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
var redis = require('./redis');
3+
var io = require('socket.io-emitter')(redis);
4+
var interval = process.env.WEPLAY_INTERVAL || 5000;
5+
6+
setInterval(function(){
7+
redis.hgetall('weplay:connections', function(err, counts){
8+
if (!counts) return;
9+
var count = 0;
10+
for (var i in counts) count += Number(counts[i]);
11+
redis.set('weplay:connections-total', count);
12+
io.emit('connections', count);
13+
});
14+
}, interval);

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "weplay-presence",
3+
"version": "0.0.1",
4+
"description": "",
5+
"dependencies": {
6+
"debug": "0.7.4",
7+
"socket.io-emittter": "0.1.0"
8+
},
9+
"scripts": {
10+
"start": "node index.js"
11+
}
12+
}

redis.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
var redis = require('redis');
3+
var uri = process.env.WEPLAY_REDIS_URI || 'localhost:6379';
4+
var pieces = uri.split(':');
5+
6+
module.exports = function(){
7+
return redis.createClient(pieces[1], pieces[0], { return_buffers: true });
8+
};

0 commit comments

Comments
 (0)