Using PeerServer you can grab two events, connection
and disconnect
. Using this you can create a internal list, which you can then have your application grab from.
Partial example:
var PeerServer = require('peer').PeerServer;
var server = new PeerServer({port: 9000, path: '/myapp'});
var connected = [];
server.on('connection', function (id) {
var idx = connected.indexOf(id); // only add id if it's not in the list yet
if (idx === -1) {connected.push(id);}
});
server.on('disconnect', function (id) {
var idx = connected.indexOf(id); // only attempt to remove id if it's in the list
if (idx !== -1) {connected.splice(idx, 1);}
});
someexpressapp.get('/connected-people', function (req, res) {
return res.json(connected);
});
Then, in your clientside code you can AJAX /connected-people
and use that list.
For metadata you could expand on the code above to add a user status and a way of updating that status.
Hope this helps!
EDIT At the time of writing the event was named connect
. It is now named connection
.
(Also I'm now going to play with PeerJS for like six hours. I hope you realize what you've done.)