Commit | Line | Data |
---|---|---|
e5ec7dea | 1 | const message = require("./public/javascripts/utils/socketMessages"); |
e99c53fb | 2 | const params = require("./config/parameters"); |
71d1ca9c | 3 | const AssessmentModel = require("./models/assessment"); |
e5ec7dea | 4 | const ObjectId = require("bson-objectid"); |
e99c53fb | 5 | |
f6648c37 BA |
6 | module.exports = function(io) |
7 | { | |
8 | io.of("/").on("connection", socket => { | |
9 | const aid = socket.handshake.query.aid; | |
10 | socket.join(aid); | |
11 | // Student or monitor connexion | |
12 | const isTeacher = !!socket.handshake.query.secret && socket.handshake.query.secret == params.secret; | |
71d1ca9c | 13 | |
f6648c37 BA |
14 | if (isTeacher) |
15 | { | |
16 | socket.on(message.newAnswer, m => { //got answer from student | |
17 | socket.emit(message.newAnswer, m); | |
e5ec7dea | 18 | }); |
f6648c37 | 19 | socket.on(message.allAnswers, m => { //send feedback to student (answers) |
71d1ca9c | 20 | socket.broadcast.to(aid).emit(message.allAnswers, m); |
e5ec7dea | 21 | }); |
e99c53fb | 22 | } |
f6648c37 BA |
23 | else //student |
24 | { | |
25 | const number = socket.handshake.query.number; | |
26 | const password = socket.handshake.query.password; | |
71d1ca9c | 27 | AssessmentModel.checkPassword(ObjectId(aid), number, password, (err,ret) => { |
f6648c37 BA |
28 | if (!!err || !ret) |
29 | return; //wrong password, or some unexpected error... | |
f6648c37 BA |
30 | socket.on("disconnect", () => { |
31 | //TODO: notify monitor (grey low opacity background) | |
32 | //Also send to server: discoTime in assessment.papers ... | |
e99c53fb | 33 | }); |
f6648c37 BA |
34 | }); |
35 | } | |
e99c53fb BA |
36 | }); |
37 | } |