socketHandler.js 891 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. module.exports = function (base, io) {
  3. io.on('connection', function (socket) {
  4. socket.on('disconnect', function () {
  5. base.disconnect(function () {
  6. console.log('User has disconnected');
  7. });
  8. });
  9. socket.on('login', function (user) {
  10. base.login(user, function (result) {
  11. socket.emit('login', result);
  12. });
  13. });
  14. socket.on('register', function (user) {
  15. base.register(user, function (result) {
  16. socket.emit('register', result);
  17. });
  18. });
  19. socket.on('rooms', function () {
  20. base.rooms(function (result) {
  21. socket.emit('rooms', result);
  22. });
  23. });
  24. socket.on('room', function (id) {
  25. base.room(id, function (result) {
  26. socket.emit('room', result);
  27. });
  28. });
  29. socket.on('search', function (query) {
  30. base.search(query, function (result) {
  31. socket.emit('search', result);
  32. });
  33. });
  34. socket.emit('ready');
  35. });
  36. };