socketHandler.js 1.4 KB

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