30beb32373834bf152ae4863746a0f83e425b937
1 const message
= require("./public/javascripts/utils/socketMessages");
2 const params
= require("./config/parameters");
3 const AssessmentModel
= require("./models/assessment");
4 const ObjectId
= require("bson-objectid");
6 module
.exports = function(io
)
8 io
.of("/").on("connection", socket
=> { //student or monitor connexion
9 const aid
= socket
.handshake
.query
.aid
;
10 const isTeacher
= !!socket
.handshake
.query
.secret
&& socket
.handshake
.query
.secret
== params
.secret
;
14 socket
.join(aid
+ "_teacher");
15 socket
.on(message
.allAnswers
, m
=> { //send feedback to student (answers)
16 socket
.broadcast
.to(aid
+ "_student").emit(message
.allAnswers
, m
);
21 const number
= socket
.handshake
.query
.number
;
22 const password
= socket
.handshake
.query
.password
;
23 AssessmentModel
.checkPassword(ObjectId(aid
), number
, password
, (err
,ret
) => {
25 return; //wrong password, or some unexpected error...
26 AssessmentModel
.newConnection(ObjectId(aid
), number
);
27 socket
.broadcast
.to(aid
+ "_teacher").emit(message
.studentConnect
, {number: number
});
28 socket
.join(aid
+ "_student");
29 socket
.on(message
.newAnswer
, m
=> { //got answer from student client
30 socket
.broadcast
.to(aid
+ "_teacher").emit(message
.newAnswer
, m
);
32 socket
.on(message
.studentBlur
, m
=> {
33 socket
.broadcast
.to(aid
+ "_teacher").emit(message
.studentBlur
, m
);
35 socket
.on(message
.studentFocus
, m
=> {
36 socket
.broadcast
.to(aid
+ "_teacher").emit(message
.studentFocus
, m
);
38 socket
.on(message
.studentResize
, m
=> {
39 socket
.broadcast
.to(aid
+ "_teacher").emit(message
.studentResize
, m
);
41 socket
.on(message
.studentFullscreen
, m
=> {
42 socket
.broadcast
.to(aid
+ "_teacher").emit(message
.studentFullscreen
, m
);
44 socket
.on("disconnect", () => { //notify monitor + server
45 AssessmentModel
.setDiscoTime(ObjectId(aid
), number
);
46 socket
.broadcast
.to(aid
+ "_teacher").emit(message
.studentDisconnect
, {number: number
});