adding notifications on connection issues, again

parent 3ab2912f
......@@ -1435,15 +1435,16 @@ module.exports = {
var action = req.param('action');
var attributes = req.param('attributes');
attributes.ui = attributes.ui ? attributes.ui : 'PCB';
var room = sails.hooks.rooms.student(attributes.id_stu);
if (req.isSocket) {
sails.hooks.rooms.subscribeToRoom(
sails.hooks.rooms.student(attributes.id_stu),
room,
req.socket,
attributes.ui
);
}
res.ok({msg: "Subscribed to student "});
res.ok(sails.hooks.rooms.getUICount(room));
},
//
......
......@@ -15,12 +15,11 @@ module.exports = function roomsHook (sails) {
return {
/**************************************************************************
* Notifies to all the room's subscribers about the number of different
* connections by UI:
* Counts the number of UIs connected to a room:
* 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)
*/
notifyRoom: function(room) {
getUICount: function (room) {
// Let's count number of connections per room and per UI
var counter = {'PCB': 0, 'PDB': 0};
//console.log('notifyRoom (' + room + ')---->\n' + JSON.stringify(sockets) + '\n' + JSON.stringify(rooms));
......@@ -34,22 +33,29 @@ module.exports = function roomsHook (sails) {
(err) => {
if (err)
sails.debug.log("Error when notifying room " + JSON.stringify(err));
else {
// Broadcast data to room's peers
sails.hooks.events.broadcastEvent(
room,
sails.hooks.events.roomSubscribersChange({
'room': room,
'pdb_count': counter['PDB'],
'pcb_count': counter['PCB']
})
);
}
else
return ({
'room': room,
'pdb_count': counter['PDB'],
'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.
* 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