function setUpSocket(io) {
  io.on('connection', socket => {
    console.log('new connection');

    socket.on('disconnect', () => {
      console.log('disconnect');
    });
  });
}

module.exports = setUpSocket;

@@ -1,169 +1,1555 @@
-function setUpSocket(io) %7B%0A  io.on('connection', socket =%3E %7B%0A    console.log('new connection');%0A%0A    socket.on('disconnect', () =%3E %7B%0A      console.log('disconnect');
+const List = require('immutable').List;%0A%0A// Global state data%0Aconst rooms = %7B%7D;%0A%0Afunction initRoom(name) %7B%0A  rooms%5Bname%5D = %7B%0A    playlist: List(), // eslint-disable-line%0A    currentPlayingVideoId: '',%0A  %7D;%0A%7D%0A%0Afunction deleteRoom(name) %7B%0A  delete rooms%5Bname%5D;%0A%7D%0A%0A// mutate the global state%0Afunction updateData(room, field, data) %7B%0A  rooms%5Broom%5D%5Bfield%5D = data;%0A%7D%0A%0Afunction setUpSocket(io) %7B%0A  io.on('connection', socket =%3E %7B%0A    let room = 'default';%0A%0A    socket.on('new user', name =%3E %7B%0A      room = name.trim() %7C%7C room;%0A      socket.join(room);%0A%0A      if (!rooms%5Broom%5D) %7B%0A        initRoom(room);%0A      %7D%0A%0A      const %7B playlist, currentPlayingVideoId %7D = rooms%5Broom%5D;%0A      socket.emit('welcome', %7B%0A        room,%0A        playlist: playlist.toArray(),%0A        currentPlayingVideoId,%0A      %7D);%0A    %7D);%0A%0A    socket.on('action', msg =%3E %7B%0A      io.in(room).emit('action', msg);%0A%0A      // store on server%0A      let field = 'playlist';%0A      switch (msg.type) %7B%0A        case 'ADD_VIDEO':%0A          return updateData(room, field, rooms%5Broom%5D%5Bfield%5D.push(msg.data));%0A        case 'DELETE_VIDEO':%0A          return updateData(room, field, rooms%5Broom%5D%5Bfield%5D.delete(msg.data));%0A        case 'PLAY':%0A          field = 'currentPlayingVideoId';%0A          return updateData(room, field, msg.data);%0A        default:%0A          return null;%0A      %7D%0A    %7D);%0A%0A    socket.on('disconnect', () =%3E %7B%0A      // clean up the room data if all users left%0A      const %7B length = 0 %7D = io.sockets.adapter.rooms%5Broom%5D %7C%7C %7B%7D;%0A      if (length === 0) %7B%0A        deleteRoom(room);%0A      %7D
 %0A   

Add socket server