member.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. let modelMap = app.model_mgr.model_map;
  13. var model_map = app.model_mgr.model_map;
  14. var mgr_map = commonManager.mgr_map;
  15. /**
  16. * 扩展用户的房间成员信息
  17. * @param member 用户基本信息
  18. * @param room_info 房间信息
  19. */
  20. this.extendMemberInfo = function* (member, room_info) {
  21. let room_id = F.isNull(room_info.room_id)?room_info.roomId:room_info.room_id;
  22. let uid = member.account;
  23. member.is_online = true;
  24. member.is_mute = yield mgr_map.redis.isMute(room_id, uid);
  25. member.is_creator = member.account == room_info.uid;
  26. let reg_timestamp = F.timestamp(0) - (F.isNull(member.create_time) ? 0 : member.create_time);
  27. //259200000 = 3*24*60*60*1000
  28. member.is_new_user = reg_timestamp < 259200000;
  29. // 管理员查询
  30. member.is_manager = yield mgr_map.validator.isRoomManager(room_id, uid);
  31. let is_black_list = yield mgr_map.redis.isBlacklist(room_id, uid);
  32. member.is_black_list = is_black_list;
  33. member.enter_time = F.getTimeStampByDelta();
  34. return member;
  35. };
  36. this.getJavaUserInfo = function* (uid) {
  37. if (F.isNull(uid)) return null;
  38. let member = yield mgr_map.redis.getUserInfo(uid); // 先从redis获取 如果存在直接返回
  39. if (!F.isNull(member)) {
  40. return member;
  41. }
  42. // 否则到java服务器取用户信息
  43. let user_info = {};
  44. let get_res = yield mgr_map.curl.httpGet(C.java_host, C.java_port, '/user/v5/get', {'uid': uid}, null, 'utf8', 'http'); // TODO 替换成java
  45. if (get_res.result) { // 表示http成功
  46. let get_user_res = JSON.parse(get_res.data);
  47. if (get_user_res.code != 200) { // 表示业务逻辑报错
  48. F.throwErrCode(100101);
  49. }
  50. user_info = get_user_res.data;
  51. } else { // 表示http超时或返回非200
  52. F.throwErrCode(100101);
  53. }
  54. member = {};
  55. member.uid = user_info.uid;
  56. member.account = user_info.uid;
  57. member.nick = user_info.nick;
  58. member.avatar = user_info.avatar;
  59. member.headwear_url = user_info.headwearUrl;
  60. member.headwear_name = user_info.headwearName;
  61. member.car_url = user_info.carUrl;
  62. member.car_name = user_info.carName;
  63. member.exper_level = user_info.experLevel;
  64. member.charm_level = user_info.charmLevel;
  65. member.gender = user_info.gender;
  66. yield mgr_map.redis.setUserInfo(uid, member);
  67. return member;
  68. };
  69. /**
  70. * 查询房间管理员列表
  71. * @param room_id
  72. */
  73. this.fetchRoomManagers = function* (room_id) {
  74. let manager_uid_list = yield mgr_map.redis.getAllRoomManagers(room_id);
  75. let managers = [];
  76. if (F.isNull(manager_uid_list)) {
  77. return managers;
  78. }
  79. for (let i = 0; i < manager_uid_list.length; i++) {
  80. let manager = yield mgr_map.member.getJavaUserInfo(manager_uid_list[i]);
  81. //member = yield mgr_map.member.extendMemberInfo(member, room_info);
  82. managers.push(manager);
  83. }
  84. return managers;
  85. };
  86. /**
  87. * 查询房间黑名单列表
  88. * @param room_id
  89. */
  90. this.fetchRoomBlackList = function* (room_id) {
  91. let blacklist_uids = yield mgr_map.redis.getRoomBlacklist(room_id);
  92. let blacklist = [];
  93. if (F.isNull(blacklist_uids)) {
  94. return blacklist;
  95. }
  96. for (let i = 0; i < blacklist_uids.length; i++) {
  97. let member = yield mgr_map.member.getJavaUserInfo(blacklist_uids[i]);
  98. blacklist.push(member);
  99. }
  100. return blacklist;
  101. };
  102. // this.kickMember = function* (room_id, account, reason_no, reason_msg) {
  103. // let user_info = yield mgr_map.member.getJavaUserInfo(account);
  104. // if (F.isNull(user_info)) {
  105. // F.throwErrCode(100101);
  106. // }
  107. //
  108. // let socket_id = yield mgr_map.redis.getSocketListByUidAndRoomid(account, room_id);
  109. // if (F.isNull(socket_id)) {
  110. // F.throwErrCode(100201);
  111. // }
  112. //
  113. //
  114. // //1 删除下麦
  115. // yield mgr_map.roomQueue.delFromRoomQueueByUid(account, room_id, account);
  116. //
  117. // //2 离开房间删除对应redis
  118. // yield mgr_map.redis.delRoomSocketList(room_id, socket_id); // 删除房间对应socket列表记录 socket断开函数也执行
  119. // yield mgr_map.redis.delUidRoomSocketList(account, room_id, socket_id); // 删除指定用户+指定房间socket列表记录 socket断开函数也执行
  120. // yield mgr_map.redis.delSocketRoomList(socket_id, room_id); // 删除socket对应在房间记录 socket断开函数也执行
  121. // yield mgr_map.redis.delRoomUserList(room_id, account); // 删除房间对应用户列表
  122. // yield mgr_map.redis.reduceRoomOnlineNum(room_id); // 减去对应房间的人数
  123. //
  124. // // let room_socket = yield mgr_map.redis.getRoomSocketList(room_id);
  125. // let room_socket = [ socket_id ];
  126. // co(mgr_map.notice.pushMemberKicked(room_socket, room_id, user_info.uid, user_info.nick, user_info.avatar, reason_no, reason_msg));
  127. // }
  128. };