<commit_before>var models = require("./models");

module.exports = function(io) {

  io.on('connection', function(client){
    var room;
    //TEACHER CODE
    client.on('teacherConnect', function(data) {
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log('Teacher connected to', room);
      io.sockets.to(room).emit('teacherJoinedRoom', data);
    });

    //maybe not necessary since basically the same as above
    client.on('teacherQuickClassConnect', function(data) {
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log(data.userCount);
      console.log('Teacher connected to quick class', room);
      io.sockets.to(room).emit('teacherJoinedRoom', data);
    });

    client.on('teacherClosePoll', function(data) {
      var pollId = data.pollId;
      // var classId = data.classId;
      console.log('teacher closing poll', pollId, 'in', room);
      io.sockets.to(room).emit('closePoll', data);
    });

    client.on('teacherLeavingClass', function(data) {
      // var classId = data.classId;
      console.log('teacher leaving class', data.classId);
      client.leave(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      io.sockets.to(room).emit('teacherLeftClass', data);
      room = undefined;
    });

    //STUDENT CODE
    client.on('studentConnect', function(data) {
      // FRONTEND-LISTENER: client.on('newStudentConnected', (studentInfo) => {display(studentCount++ and studentInfo);});
      var userId = data.userId;
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log('Student', userId, 'connected to', room);
      io.sockets.to(room).emit('studentJoinedRoom', data);
      //TODO: DB.write('newStudentConnected', data);
    });

    client.on('studentQuickClassConnect', function(data) {
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log('Student connected to quick class', room);
      console.log(data.userCount);
      io.sockets.to(room).emit('studentJoinedRoom', data);
    });

    client.on('studentResponse', function(data) {
      console.log('INCOMING STUDENT RESPONSE:', data);
      data.userCount = io.sockets.adapter.rooms[room].length;
      io.sockets.to(room).emit('studentResponseForTeacher', data);

      if(data.pollId !== 'Quick Poll') {
        models.poll_responses.create({
          response_val: data.answer,
          student_id: data.userId,
          poll_id: data.pollId
        })
        .catch(function(err) {
          console.error('Error saving student', data.userId, 'poll response to DB:', err);
        });
      }<commit_msg>Remove console logs<commit_after>var models = require("./models");

module.exports = function(io) {

  io.on('connection', function(client){
    var room;
    //TEACHER CODE
    client.on('teacherConnect', function(data) {
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log('Teacher connected to', room);
      io.sockets.to(room).emit('teacherJoinedRoom', data);
    });

    //maybe not necessary since basically the same as above
    client.on('teacherQuickClassConnect', function(data) {
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log('Teacher connected to quick class', room);
      io.sockets.to(room).emit('teacherJoinedRoom', data);
    });

    client.on('teacherClosePoll', function(data) {
      var pollId = data.pollId;
      // var classId = data.classId;
      console.log('teacher closing poll', pollId, 'in', room);
      io.sockets.to(room).emit('closePoll', data);
    });

    client.on('teacherLeavingClass', function(data) {
      // var classId = data.classId;
      console.log('teacher leaving class', data.classId);
      client.leave(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      io.sockets.to(room).emit('teacherLeftClass', data);
      room = undefined;
    });

    //STUDENT CODE
    client.on('studentConnect', function(data) {
      // FRONTEND-LISTENER: client.on('newStudentConnected', (studentInfo) => {display(studentCount++ and studentInfo);});
      var userId = data.userId;
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log('Student', userId, 'connected to', room);
      io.sockets.to(room).emit('studentJoinedRoom', data);
      //TODO: DB.write('newStudentConnected', data);
    });

    client.on('studentQuickClassConnect', function(data) {
      room = 'room' + data.classId;
      client.join(room);
      data.userCount = io.sockets.adapter.rooms[room].length;
      console.log('Student connected to quick class', room);
      io.sockets.to(room).emit('studentJoinedRoom', data);
    });

    client.on('studentResponse', function(data) {
      console.log('INCOMING STUDENT RESPONSE:', data);
      data.userCount = io.sockets.adapter.rooms[room].length;
      io.sockets.to(room).emit('studentResponseForTeacher', data);

      if(data.pollId !== 'Quick Poll') {
        models.poll_responses.create({
          response_val: data.answer,
          student_id: data.userId,
          poll_id: data.pollId
        })
        .catch(function(err) {
          console.error('Error saving student', data.userId, 'poll response to DB:', err);
        });
      }
{'fraction_non_alphanumeric': 0.15430579964850616, 'fraction_numerical': 0.0, 'mean_word_length': 3.0679056468906363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1319077', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1761, 'n_words': 318}