adding notifications on connection issues, again

parent 3ab2912f
...@@ -1435,15 +1435,16 @@ module.exports = { ...@@ -1435,15 +1435,16 @@ module.exports = {
var action = req.param('action'); var action = req.param('action');
var attributes = req.param('attributes'); var attributes = req.param('attributes');
attributes.ui = attributes.ui ? attributes.ui : 'PCB'; attributes.ui = attributes.ui ? attributes.ui : 'PCB';
var room = sails.hooks.rooms.student(attributes.id_stu);
if (req.isSocket) { if (req.isSocket) {
sails.hooks.rooms.subscribeToRoom( sails.hooks.rooms.subscribeToRoom(
sails.hooks.rooms.student(attributes.id_stu), room,
req.socket, req.socket,
attributes.ui attributes.ui
); );
} }
res.ok({msg: "Subscribed to student "}); res.ok(sails.hooks.rooms.getUICount(room));
}, },
// //
......
...@@ -15,12 +15,11 @@ module.exports = function roomsHook (sails) { ...@@ -15,12 +15,11 @@ module.exports = function roomsHook (sails) {
return { return {
/************************************************************************** /**************************************************************************
* Notifies to all the room's subscribers about the number of different * Counts the number of UIs connected to a room:
* connections by UI:
* pdb_count (number of connections to the given room from Pictogram Web) * pdb_count (number of connections to the given room from Pictogram Web)
* pcb_count (number of connections to the given room from Pictogram Communicator/Supervisor) * pcb_count (number of connections to the given room from Pictogram Communicator/Supervisor)
*/ */
notifyRoom: function(room) { getUICount: function (room) {
// Let's count number of connections per room and per UI // Let's count number of connections per room and per UI
var counter = {'PCB': 0, 'PDB': 0}; var counter = {'PCB': 0, 'PDB': 0};
//console.log('notifyRoom (' + room + ')---->\n' + JSON.stringify(sockets) + '\n' + JSON.stringify(rooms)); //console.log('notifyRoom (' + room + ')---->\n' + JSON.stringify(sockets) + '\n' + JSON.stringify(rooms));
...@@ -34,22 +33,29 @@ module.exports = function roomsHook (sails) { ...@@ -34,22 +33,29 @@ module.exports = function roomsHook (sails) {
(err) => { (err) => {
if (err) if (err)
sails.debug.log("Error when notifying room " + JSON.stringify(err)); sails.debug.log("Error when notifying room " + JSON.stringify(err));
else { else
// Broadcast data to room's peers return ({
sails.hooks.events.broadcastEvent(
room,
sails.hooks.events.roomSubscribersChange({
'room': room, 'room': room,
'pdb_count': counter['PDB'], 'pdb_count': counter['PDB'],
'pcb_count': counter['PCB'] 'pcb_count': counter['PCB']
}) });
);
}
} }
); );
}, },
/************************************************************************** /**************************************************************************
* Notifies to all the room's subscribers about the number of different
* connections by UI
*/
notifyRoom: function(room) {
// Broadcast data to room's peers
sails.hooks.events.broadcastEvent(
room,
sails.hooks.events.roomSubscribersChange(sails.hooks.events.getUICount(room));
);
},
/**************************************************************************
* Special function that subscribes a socket to a given room. * Special function that subscribes a socket to a given room.
* This creates the connection and logs to debug with this format: * This creates the connection and logs to debug with this format:
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment