socketHandler.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const passport = require('passport');
  3. module.exports = (core, io) => {
  4. io.on('connection', socket => {
  5. console.log("socketHandler: User has connected");
  6. let session = socket.request.user;
  7. socket.on('disconnect', _ => {
  8. core['/stations/leave'](session, result => {});
  9. console.log('socketHandler: User has disconnected');
  10. });
  11. socket.on('error', err => console.log(err));
  12. socket.on('/users/logout', (cb) => core['/users/logout'](socket.request, result => cb(result)));
  13. socket.on('/stations', (cb) => core['/stations'](session, result => cb(result)));
  14. socket.on('/stations/join/:id', (id, cb) => core['/stations/join/:id'](session, id, result => cb(result)));
  15. socket.on('/stations/leave', cb => core['/stations/leave'](session, result => cb(result)));
  16. socket.on('/stations/add/:song', (station, song, cb) => core['/stations/add/:song'](session, station, song, result => cb(result)));
  17. socket.on('/songs', (cb) => core['/songs'](session, result => cb(result)));
  18. socket.on('/songs/:song/update', (song, cb) => core['/songs/:song/update'](session, song, result => cb(result)));
  19. socket.on('/songs/:song/remove', (song, cb) => core['/songs/:song/remove'](session, song, result => cb(result)));
  20. socket.on('/youtube/getVideo/:query', (query, cb) => core['/youtube/getVideo/:query'](session, query, result => cb(result)));
  21. // this lets the client socket know that they can start making request
  22. socket.emit('ready', socket.request.user.logged_in);
  23. });
  24. };