A room management system meant to work with a redis-backed primus cluster.
npm install --save primus-concierge
const primus = require('primus');
const primus_concierge = require('primus-concierge');
const wss = primus.createServer({
port: 8000,
redis: {
host: 'localhost',
port: 6379
}
});
wss.plugin('concierge', primus_concierge);
wss.on('connection', (spark) => {
spark.on('data', (data) => {
switch(data.action) {
case 'join-room':
spark.join(data.body.room);
break;
case 'broadcast':
spark.broadcast(data.body.room, data.body.message);
break;
case 'leave-room':
spark.leave(data.body.room);
break;
case 'say':
spark.say(data.body.to, data.body.message);
break;
}
});
});
Concierge adapts the spark that is available after a connection has been established.
Spark._rooms is an array object that contains a set of rooms that the current spark belongs to. Because it is entirely in-memory, if a user "disconnects" for any reason, they are removed from all the rooms they belong to
By calling this method, you will join the current spark to the room specified. If the room does not exist, it is created. The current membership of the room is tracked in redis
This method will cause the spark to leave the specified room
This will send the message provided to all sockets within a room, except for the sender.
This will allow you to message any spark that this server has access to and send them the msg provided. This method relies on having omega-supreme installed and loaded for message support across a primus cluster. If you are not using omega-supreme, just don't use this particular message and you'll be fine
Return a list of people in the room specified. If you are looking up a room that you are a part of, please note that it will also return your socket id
[ ] Add support for room events
MIT