socketHandler.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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('/stations', cb => {
  10. core['/stations'](result => {
  11. cb(result);
  12. });
  13. });
  14. /*socket.on('/station/:id/join', (id, cb) => {
  15. console.log("JOINED!!!");
  16. core['/station/:id/join'](id, socket.id, result => {
  17. console.log("CALLBACK!!!");
  18. cb(result);
  19. });
  20. });*/
  21. socket.on('/youtube/getVideos/:query', (query, cb) => {
  22. core['/youtube/getVideos/:query'](query, result => {
  23. cb(result);
  24. });
  25. });
  26. socket.on('/songs/queue/addSongs/:songs', (songs, cb) => {
  27. core['/songs/queue/addSongs/:songs'](songs, _user, result => {
  28. cb(result);
  29. });
  30. });
  31. socket.on('/songs/queue/getSongs', (cb) => {
  32. core['/songs/queue/getSongs'](_user, result => {
  33. cb(result);
  34. });
  35. });
  36. socket.on('/songs/queue/updateSong/:id', (id, object, cb) => {
  37. core['/songs/queue/updateSong/:id'](_user, id, object, result => {
  38. cb(result);
  39. });
  40. });
  41. /*socket.on('/stations/search/:query', (query, cb) => {
  42. core['/stations/search/:query'](query, result => {
  43. cb(result);
  44. });
  45. });*/
  46. // this lets the client socket know that they can start making request
  47. socket.emit('ready', socket.request.user.logged_in);
  48. });
  49. };