PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/app/templates/server/config/socketio(socketio).js

https://gitlab.com/javajamesb08/generator-angular-fullstack
JavaScript | 57 lines | 24 code | 11 blank | 22 comment | 0 complexity | 6c5ae24e0e36a2d2ecf7139f71efc827 MD5 | raw file
  1. /**
  2. * Socket.io configuration
  3. */
  4. 'use strict';
  5. var config = require('./environment');
  6. // When the user disconnects.. perform this
  7. function onDisconnect(socket) {
  8. }
  9. // When the user connects.. perform this
  10. function onConnect(socket) {
  11. // When the client emits 'info', this listens and executes
  12. socket.on('info', function (data) {
  13. console.info('[%s] %s', socket.address, JSON.stringify(data, null, 2));
  14. });
  15. // Insert sockets below
  16. require('../api/thing/thing.socket').register(socket);
  17. }
  18. module.exports = function (socketio) {
  19. // socket.io (v1.x.x) is powered by debug.
  20. // In order to see all the debug output, set DEBUG (in server/config/local.env.js) to including the desired scope.
  21. //
  22. // ex: DEBUG: "http*,socket.io:socket"
  23. // We can authenticate socket.io users and access their token through socket.handshake.decoded_token
  24. //
  25. // 1. You will need to send the token in `client/components/socket/socket.service.js`
  26. //
  27. // 2. Require authentication here:
  28. // socketio.use(require('socketio-jwt').authorize({
  29. // secret: config.secrets.session,
  30. // handshake: true
  31. // }));
  32. socketio.on('connection', function (socket) {
  33. socket.address = socket.handshake.address !== null ?
  34. socket.handshake.address.address + ':' + socket.handshake.address.port :
  35. process.env.DOMAIN;
  36. socket.connectedAt = new Date();
  37. // Call onDisconnect.
  38. socket.on('disconnect', function () {
  39. onDisconnect(socket);
  40. console.info('[%s] DISCONNECTED', socket.address);
  41. });
  42. // Call onConnect.
  43. onConnect(socket);
  44. console.info('[%s] CONNECTED', socket.address);
  45. });
  46. };