eeda127f53aca586ac52f8ce48cd0c142f8f7580
1 const message
= require("./public/javascripts/utils/socketMessages");
2 const params
= require("./config/parameters");
3 const AssessmentEntity
= require("./entities/assessment");
4 const ObjectId
= require("bson-objectid");
6 module
.exports = function(io
)
8 io
.of("/").on("connection", socket
=> {
9 const aid
= socket
.handshake
.query
.aid
;
11 // Student or monitor connexion
12 const isTeacher
= !!socket
.handshake
.query
.secret
&& socket
.handshake
.query
.secret
== params
.secret
;
15 socket
.on(message
.newAnswer
, m
=> { //got answer from student
16 socket
.emit(message
.newAnswer
, m
);
18 socket
.on(message
.allAnswers
, m
=> { //send feedback to student (answers)
19 if (!!students
[m
.number
]) //TODO: namespace here... room quiz
20 socket
.broadcast
.to(aid
).emit(message
.allAnswers
, m
);
25 const number
= socket
.handshake
.query
.number
;
26 const password
= socket
.handshake
.query
.password
;
27 AssessmentEntity
.checkPassword(ObjectId(aid
), number
, password
, (err
,ret
) => {
29 return; //wrong password, or some unexpected error...
30 // TODO: Prevent socket connection (just ignore) if student already connected
31 // io.of('/').in(aid).clients((error, clients) => {
34 // if (clients.some( c => { return c. .. == number; }))
35 // // Problem: we just have a list of socket IDs (not handshakes)
37 // TODO: next is conditional to "student not already taking the exam"
38 socket
.on(message
.allAnswers
, () => { //got all answers from teacher
39 socket
.emit(message
.allAnswers
, m
);
41 socket
.on("disconnect", () => {
42 //TODO: notify monitor (grey low opacity background)
43 //Also send to server: discoTime in assessment.papers ...