-// TODO: when teacher connect on monitor, io.of("appropriate namespace").on(connect student) { ... }
-// --> 2 sockets on monitoring page: one with ns "/" et one dedicated to the exam, triggered after the first
-// --> The monitoring page should not be closed during exam (otherwise monitors won't receive any more data)
-
-// TOOD need to re-introduce disconnections count + time (showed in monitoring and stored
-
-function examRoom(socket) {
- let students = { };
- const aid = ObjectId(socket.handshake.query.aid);
-
- // Student or monitor stuff
- const isTeacher = !!socket.handshake.query.secret && socket.handshake.query.secret == params.secret;
-
- if (isTeacher)
- {
- socket.on(message.newAnswer, m => { //got answer from student
- socket.emit(message.newAnswer, m);
- });
- socket.on(message.allAnswers, m => { //send feedback to student (answers)
- if (!!students[m.number]) //TODO: namespace here... room quiz
- socket.broadcast.to(students[m.number]).emit(message.allAnswers, m);
- });
- socket.on("disconnect", m => {
- // Reset student array if no more active teacher connections (TODO: condition)
- students = { };
- });
- }
-
- else //student
- {
- const number = socket.handshake.query.number;
- const password = socket.handshake.query.password;
- AssessmentEntity.checkPassword(aid, number, password, (err,ret) => {
- if (!!err || !ret)
- return; //wrong password, or some unexpected error...
- // Prevent socket connection (just ignore) if student already connected
- if (!!students[number])
- return;
- students[number] = {
- sid: socket.id,
- password: password,
- };
- socket.on(message.allAnswers, () => { //got all answers from teacher
- socket.emit(message.allAnswers, m);
+module.exports = function(io)
+{
+ io.of("/").on("connection", socket => {
+ const aid = socket.handshake.query.aid;
+ socket.join(aid);
+ // Student or monitor connexion
+ const isTeacher = !!socket.handshake.query.secret && socket.handshake.query.secret == params.secret;
+ if (isTeacher)
+ {
+ socket.on(message.newAnswer, m => { //got answer from student
+ socket.emit(message.newAnswer, m);