Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c2b3087c
authored
Jan 14, 2018
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
adding notifications on connection issues, again
parent
3ab2912f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
16 deletions
sails/src/api/controllers/StudentController.js
sails/src/api/hooks/rooms.js
sails/src/api/controllers/StudentController.js
View file @
c2b3087c
...
...
@@ -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
)
);
},
//
...
...
sails/src/api/hooks/rooms.js
View file @
c2b3087c
...
...
@@ -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:
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment