Pusher.js 963 B

12345678910111213141516171819202122232425262728293031323334
  1. let config = require('./config/appconfig.js')
  2. export default class Pusher {
  3. constructor () { // eslint-disable-line
  4. }
  5. /**
  6. * 处理采集服务器过来的 PUSH 消息
  7. * 广播给所有在线的监控客户端
  8. *
  9. * @method doPUSH
  10. *
  11. * @param {[type]} socket [description]
  12. * @param {[type]} message [description]
  13. *
  14. * @return {[type]} [description]
  15. */
  16. static push (socket, message, username) {
  17. let userInfo = socket.handshake.session.user
  18. if (userInfo.name === config.COLLECTOR) {
  19. if (socket.auth) {
  20. socket.to(config.MONITOR).emit('PUSH', message)
  21. console.log(userInfo.name+'发送了')
  22. if (message.cmd === 'up_mine') {
  23. socket.to(config.STANDBY).emit('PUSH', message)
  24. }
  25. } else {
  26. console.log('用户尚未登录,无法 PUSH 消息!')
  27. }
  28. } else {
  29. console.warn(`用户 ${userInfo.name} 没有 PUSH 权限!`)
  30. }
  31. }
  32. }