socketHandler.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. module.exports = function (core, io) {
  3. // tell all the users in this room that someone is joining it
  4. core.on('station-joined', function (user) {
  5. io.sockets.clients().forEach(function (socket) {
  6. if (socket.request.user.id != user.user.id && socket.request.user.roomId === id) {
  7. socket.emit('station-joined', user);
  8. }
  9. });
  10. });
  11. io.on('connection', function (socket) {
  12. socket.on('disconnect', function () {
  13. console.log('User has disconnected');
  14. });
  15. socket.on('/users/login', function (user, cb) {
  16. core['/users/login'](user, function (result) {
  17. cb(result);
  18. });
  19. });
  20. socket.on('/users/register', function (user, cb) {
  21. core['/users/register'](user, function (result) {
  22. cb(result);
  23. });
  24. });
  25. socket.on('/stations', function (cb) {
  26. core['/stations'](function (result) {
  27. cb(result);
  28. });
  29. });
  30. socket.on('/stations/join/:id', function (id, cb) {
  31. core['/stations/join/:id'](id, function (result) {
  32. cb(result);
  33. });
  34. });
  35. socket.on('/stations/search/:query', function (query, cb) {
  36. core['/stations/search/:query'](query, function (result) {
  37. cb(result);
  38. });
  39. });
  40. // this lets the client socket know that they can start making request
  41. socket.emit('ready');
  42. });
  43. };