socketHandler.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. module.exports = (core, io) => {
  3. io.on('connection', socket => {
  4. console.log("User has connected");
  5. let _user = socket.request.user;
  6. socket.on('disconnect', () => {
  7. console.log('User has disconnected');
  8. });
  9. /*socket.on('/station/:id/join', (id, cb) => {
  10. console.log("JOINED!!!");
  11. core['/station/:id/join'](id, socket.id, result => {
  12. console.log("CALLBACK!!!");
  13. cb(result);
  14. });
  15. });*/
  16. socket.on('/youtube/getVideo/:query', (query, cb) => {
  17. core['/youtube/getVideo/:query'](query, result => {
  18. cb(JSON.parse(result));
  19. });
  20. });
  21. socket.on('/songs/queue/add/:song', (song, cb) => {
  22. core['/songs/queue/add/:song'](song, _user, result => {
  23. cb(result);
  24. });
  25. });
  26. socket.on('/songs/queue/getSongs', (cb) => {
  27. core['/songs/queue/getSongs'](_user, result => {
  28. cb(result);
  29. });
  30. });
  31. socket.on('/songs/queue/updateSong/:id', (id, object, cb) => {
  32. core['/songs/queue/updateSong/:id'](_user, id, object, result => {
  33. cb(result);
  34. });
  35. });
  36. // this lets the client socket know that they can start making request
  37. socket.emit('ready', socket.request.user.logged_in);
  38. });
  39. };