publicRoom.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * 直播间男女端共用Manager
  3. */
  4. 'use strict';
  5. const F = require('../common/function');
  6. const C = require('../config');
  7. const _ = require('underscore');
  8. _.str = require('underscore.string');
  9. _.v = require('validator');
  10. const co = require('co');
  11. module.exports = function (app, commonManager) {
  12. var mgr_map = commonManager.mgr_map;
  13. /**
  14. * 进入公屏聊天室
  15. * @param room_id
  16. * @param socket_id
  17. */
  18. this.enterPublicRoom = function* (room_id, socket_id, uid) {
  19. yield mgr_map.redis.addSocketToPublicRoom(room_id, socket_id, uid);
  20. let his_list = yield mgr_map.redis.getPublicRoomHisLis(room_id);
  21. return his_list;
  22. };
  23. this.leavePublicRoom = function* (uid, socket_id) {
  24. F.addDebugLogs(["err:", "退出公聊大厅:socketId:>{}", uid, socket_id]);
  25. yield mgr_map.redis.delPublicRoomSocket(uid, socket_id);
  26. };
  27. /**
  28. * 发送公屏信息
  29. * @param room_id
  30. */
  31. this.sendPublicMsgNotice = function* (data) {
  32. let room_socket = yield mgr_map.redis.getPublicRoomSocketList(data.room_id);
  33. let server_msg_id = yield mgr_map.redis.getNextReqId("server_msg_id");
  34. data.server_msg_id = server_msg_id;
  35. if (!F.isNull(data.custom.data)) {
  36. data.custom.data.server_msg_id = server_msg_id;
  37. }
  38. yield mgr_map.redis.addPublicRoomHistory(data.room_id, data.custom);
  39. co(mgr_map.notice.push(room_socket, 'sendPublicMsgNotice', data));
  40. // 抄送Java端
  41. co(mgr_map.curl.httpPostJson(C.java_host, C.java_port, '/publicRoom/v1/pushMsg', data, null, 'utf8', 'http'))
  42. };
  43. /**
  44. * 7.4.获取公聊大厅标题(Client→Server) 军圣
  45. * @param room_id
  46. */
  47. this.getPublicRoomTitle = function* (room_id) {
  48. let uid_count = yield mgr_map.redis.getPublicRoomUserCount(room_id);
  49. let res = {
  50. "count": uid_count + 1000,
  51. "ulist": []
  52. };
  53. let uid_list = yield mgr_map.redis.getRecentPublicRoomUidList(room_id);
  54. if (F.isNull(uid_list)) {
  55. return res;
  56. }
  57. for (let i = 0; i < uid_list; i++) {
  58. if (F.isNull(uid_list[i])) {
  59. continue;
  60. }
  61. let member = yield mgr_map.member.getJavaUserInfo(uid_list[i]);
  62. if (F.isNull(member)) {
  63. continue;
  64. }
  65. res.ulist.push({"avatar": member.avatar});
  66. }
  67. return res;
  68. };
  69. };