notice.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. 'use strict';
  2. const F = require('../common/function');
  3. const _ = require('underscore');
  4. _.str = require('underscore.string');
  5. _.v = require('validator');
  6. const co = require('co');
  7. const C = require('../config');
  8. module.exports = function (app, commonManager) {
  9. let modelMap = app.model_mgr.model_map;
  10. let managerMap = commonManager.mgr_map;
  11. var model_map = app.model_mgr.model_map;
  12. var mgr_map = commonManager.mgr_map;
  13. let that = this;
  14. this.sendDingTalk = function* (errMsg) {
  15. if (!F.isNull(C.isDebug) && true == C.isDebug) return;
  16. //let route = "/robot/send?access_token=cd508442df5317b257c2ab232e602e0d60d10c8629a2588a4763efa2387583cb";
  17. let route = "/robot/send?access_token=7c3553193c3a9caf70770747eb3b6a2a6b0d17aa91e2f711f27c98a6d033dcc3";
  18. yield mgr_map.curl.httpPostJson("oapi.dingtalk.com", 443, route, {
  19. "text": {
  20. "content": C.inner_host + "机子, im预警:"+errMsg
  21. },
  22. "msgtype": "text",
  23. "at": {
  24. "atMobiles": ["13682306032", "18520124838"]
  25. }
  26. }, {"Content-Type": "application/json; charset=utf-8"}, 'utf8', 'https');
  27. }
  28. /**
  29. * 向客户端发送通知
  30. * @param socketList socket列表
  31. * @param route 路由名
  32. * @param data 发送的数据
  33. */
  34. this.push = function* (socketList, route, data, cb_data = null) {
  35. if (_.isString(socketList)) {
  36. socketList = [socketList];
  37. }
  38. F.addOtherLogs("imrw/imrw", ["push data:", route, data, " to:", socketList]);
  39. for (let i in socketList) {
  40. let socketId = _.isString(socketList[i]) ? socketList[i] : socketList[i].socket_id;
  41. if (socketId.indexOf("robot_") >= 0) continue;
  42. yield managerMap.im.sendReq(socketId, route, data, cb_data);
  43. }
  44. };
  45. ///**
  46. // * 主播即时邀请通知(拒绝+同意)
  47. // * @param inviteId 邀请IDs
  48. // * @param anchorId 主播ID
  49. // * @param roomId 场次ID
  50. // * @param roomType 场次类型
  51. // */
  52. //this.anchorInstanceInviteReply = function* (inviteId, anchorId, roomId = 0, roomType = 0, msg = '') {
  53. // //获取用户在邀请页的在线socket(只有一条)
  54. // let manSocketList = yield modelMap.live_invitation_socket_log.getOnlineListByInviteId(inviteId);
  55. // if (!F.isNull(manSocketList)) {
  56. // let anchorBasicInfo = yield modelMap.user.getUserInfoById(anchorId); //主播信息
  57. // anchorBasicInfo.avatar_img = F.getFileUrl(anchorBasicInfo.avatar_img);
  58. // //没有roomId则为拒绝
  59. // let replyType = roomId == 0 ? 0 : 1;
  60. // for (let i = 0; i < manSocketList.length; i++) {
  61. // //执行推送
  62. // co(this.push(manSocketList[i].socket_id, 'imLady/instantInviteReplyNotice', {
  63. // reply_type: replyType,
  64. // invite_id: manSocketList[i].invitation_id.toString(),
  65. // room_id: roomId.toString(),
  66. // room_type: roomType,
  67. // anchor_id: anchorId,
  68. // nick_name: anchorBasicInfo.nick_name,
  69. // avatar_img: anchorBasicInfo.avatar_img,
  70. // msg: msg
  71. // }));
  72. // }
  73. // }
  74. //};
  75. ///**
  76. // * 发送礼物推送通知
  77. // * @param data 请求的参数
  78. // */
  79. //this.sendGiftNotice = function* (data) {
  80. // //推送发礼物通知 - 获取直播间的所有在线socket
  81. // if (!F.isNull(data.is_hangout)) { // hangout
  82. // if (!F.isNull(data.is_anchor)) { // 主播发送
  83. // yield this.anchorSendHangoutGiftNotice(data);
  84. // } else { // 观众发送
  85. // yield this.manSendHangoutGiftNotice(data);
  86. // }
  87. // } else { // 非hangout
  88. // yield this.sendNormalGiftNotice(data);
  89. // }
  90. //};
  91. ///**
  92. // * 通知房间所有人
  93. // * @param roomid 房间ID
  94. // * @param route
  95. // * @param data
  96. // * @param except_user_arr 不通知的用户ID数组
  97. // */
  98. //this.noticeMsgToRoom = function* (roomid, route, data, except_user_arr = new Array()) {
  99. // let room_socket_list = yield modelMap.live_room_socket_log.getOnlineListByRoomId(roomid, except_user_arr);
  100. // co(that.push(room_socket_list, route, data));
  101. //};
  102. ///**
  103. // * 进入房间通知
  104. // * @param userid
  105. // * @param roomid
  106. // */
  107. //this.noticeMsgToEnterRoom = function* (userid, roomid, has_ticket = 0) {
  108. // // 通知房间所有人
  109. // let user_info = yield modelMap.user.getUserInfoById(userid);
  110. // if(F.isNull(user_info)) return ;
  111. // let rider_info = yield modelMap.backpack_equipment.getCarDrive(userid);
  112. // let honor_info = yield modelMap.equipment.getUserHonor(userid);
  113. // let data = {
  114. // 'userid':userid,
  115. // 'nickname':user_info.nick_name,
  116. // 'photourl':user_info.avatar_img,
  117. // 'riderid':F.isNull(rider_info[userid]) ? '' : rider_info[userid].id.toString(),
  118. // 'ridername':F.isNull(rider_info[userid]) ? '' : rider_info[userid].name,
  119. // 'riderurl':F.isNull(rider_info[userid]) ? '' : F.getFileUrl(rider_info[userid].icon_img),
  120. // 'roomid':roomid.toString(),
  121. // 'fansnum':yield modelMap.live_room.getCurrentUserNum(roomid),
  122. // 'honor_img': F.isNull(honor_info.icon_img) ? '' : F.getFileUrl(honor_info.icon_img),
  123. // 'has_ticket':has_ticket
  124. // };
  125. // let honor = yield modelMap.equipment.getUserHonor(userid);
  126. // if (!F.isNull(honor)) data.honor_url = F.getFileUrl(honor.icon_img);
  127. // yield that.noticeMsgToRoom(roomid, 'imShare/enterRoomNotice', data);
  128. //};
  129. ///**
  130. // * 离开房间通知
  131. // * @param userid
  132. // * @param roomid
  133. // */
  134. //this.noticeMsgToLeaveRoom = function* (userid, roomid) {
  135. // let user_info = yield modelMap.user.getUserInfoById(userid);
  136. // let data = {
  137. // 'userid':userid,
  138. // 'nickname':user_info.nick_name,
  139. // 'photourl':user_info.avatar_img,
  140. // 'roomid':roomid.toString(),
  141. // 'fansnum':yield modelMap.live_room.getCurrentUserNum(roomid)
  142. // };
  143. // yield that.noticeMsgToRoom(roomid, 'imShare/leaveRoomNotice', data);
  144. //};
  145. ///**
  146. // * 推送男士节目状态变更
  147. // * @param socket_list
  148. // * @param data 通过manager.roomShow.combineValueThroughShowList()方法获取
  149. // */
  150. //this.pushManShowStatusChange = function* (socket_list,data){
  151. // co(that.push(socket_list, 'imMan/statusChangeNotice', data));
  152. //}
  153. this.pushChatRoomMemberIn = function* (socket_list, room_info, enter_uid) {
  154. let member = yield mgr_map.member.getJavaUserInfo(enter_uid);
  155. let room_id = F.isNull(room_info.room_id) ? room_info.roomId : room_info.room_id;
  156. let online_num = yield mgr_map.redis.getRoomOnlineNum(room_id);
  157. member = yield mgr_map.member.extendMemberInfo(member, room_info);
  158. co(that.push(socket_list, 'chatRoomMemberIn', {
  159. 'member': member,
  160. 'online_num': online_num,
  161. 'timestamp': F.timestamp()
  162. }));
  163. };
  164. /**
  165. * 推送离开房间通知
  166. * @param socket_list
  167. * @param room_id
  168. * @param uid
  169. * @param nickname
  170. */
  171. this.pushLeaveRoomNotice = function* (socket_list, room_id, uid, nickname) {
  172. let online_num = yield mgr_map.redis.getRoomOnlineNum(room_id);
  173. co(that.push(socket_list, 'chatRoomMemberExit', {
  174. 'room_id,': room_id,
  175. 'uid': uid,
  176. 'nickname': nickname,
  177. 'online_num': online_num,
  178. 'timestamp': F.timestamp()
  179. }));
  180. };
  181. /**
  182. * 4.11通知:聊天室信息更新通知(Server->Client)
  183. * @param socket_list
  184. * @param room_info
  185. */
  186. this.pushChatRoomUpdatedNotice = function* (socket_list, room_info) {
  187. co(that.push(socket_list, 'ChatRoomInfoUpdated', {
  188. 'room_info': room_info
  189. }));
  190. };
  191. /**
  192. * 4.15.通知:聊天室黑名单添加通知
  193. * @param room_id 房间ID
  194. * @param uid 添加用户ID
  195. * @param nickname 昵称
  196. * @param avatar 头像
  197. * @returns {IterableIterator<*>}
  198. */
  199. this.pushMarkChatRoomBlackListNotice = function* (socket_list, room_id, member) {
  200. co(that.push(socket_list, 'ChatRoomMemberBlackAdd', {
  201. 'room_id': room_id,
  202. 'member': member
  203. }));
  204. };
  205. /**
  206. * 4.16.通知:聊天室黑名单删除通知
  207. * @param room_id 房间ID
  208. * @param uid 删除用户ID
  209. * @param nickname 昵称
  210. * @param avatar 头像
  211. * @returns {IterableIterator<*>}
  212. */
  213. this.pushRemoveChatRoomBlackListNotice = function* (socket_list, room_id, member) {
  214. co(that.push(socket_list, 'ChatRoomMemberBlackRemove', {
  215. 'room_id': room_id,
  216. 'member': member
  217. }));
  218. };
  219. /**
  220. * 4.18.通知:管理员添加通知
  221. * @param room_id 房间ID
  222. * @param uid 添加用户ID
  223. * @param nickname 昵称
  224. * @param avatar 头像
  225. * @returns {IterableIterator<*>}
  226. */
  227. this.pushManagerAdd = function* (socket_list, room_id, member) {
  228. co(that.push(socket_list, 'ChatRoomManagerAdd', {
  229. 'room_id': room_id,
  230. 'member': member
  231. }));
  232. }
  233. /**
  234. * 4.19.通知:管理员删除通知
  235. * @param room_id 房间ID
  236. * @param uid 删除用户ID
  237. * @param nickname 昵称
  238. * @param avatar 头像
  239. * @returns {IterableIterator<*>}
  240. */
  241. this.pushManagerRemove = function* (socket_list, room_id, member) {
  242. co(that.push(socket_list, 'ChatRoomManagerRemove', {
  243. 'room_id': room_id,
  244. 'member': member
  245. }));
  246. }
  247. /**
  248. * 4.21.通知:踢除特定成员通知
  249. * @param room_id 房间ID
  250. * @param uid 删除用户ID
  251. * @param nickname 昵称
  252. * @param avatar 头像
  253. * @returns {IterableIterator<*>}
  254. */
  255. this.pushMemberKicked = function* (socket_list, room_id, uid, nickname, avatar, reason_no, reason_msg) {
  256. co(that.push(socket_list, 'ChatRoomMemberKicked', {
  257. 'room_id': room_id,
  258. 'uid': uid,
  259. 'nickname': nickname,
  260. 'avatar': avatar,
  261. 'reason_no': reason_no,
  262. 'reason_msg': reason_msg
  263. }));
  264. };
  265. /**
  266. * 4.29.通知:禁言用户添加通知
  267. */
  268. this.pushMarkChatRoomMuteNotice = function* (socket_list, room_id, member) {
  269. co(that.push(socket_list, 'ChatRoomMemberMute', {
  270. 'room_id': room_id,
  271. 'member': member
  272. }));
  273. };
  274. /**
  275. * 4.30.通知:禁言用户移除通知
  276. */
  277. this.pushRemoveChatRoomMuteNotice = function* (socket_list, room_id, member) {
  278. co(that.push(socket_list, 'ChatRoomMemberMuteCancel', {
  279. 'room_id': room_id,
  280. 'member': member
  281. }));
  282. };
  283. /**
  284. * 5.5 通知:更新坑位信息
  285. * @param room_id 房间id
  286. * @param key 队列下标
  287. * @param mic_info 坑位信息
  288. */
  289. this.pushQueueMicUpdateNotice = function* (socket_list, room_id, key, mic_info) {
  290. co(that.push(socket_list, 'QueueMicUpdateNotice', {
  291. 'room_id': room_id,
  292. 'key': key,
  293. 'mic_info': mic_info
  294. }));
  295. }
  296. /**
  297. * 5.6 通知:队列成员被更新通知
  298. * @param room_id 房间id
  299. * @param type 整形 1:更新key 2:删除key
  300. * @param key 队列下标
  301. * @param uid 下麦的用户id
  302. */
  303. this.pushQueueMemberUpdateNotice = function* (socket_list, room_id, type, key, uid) {
  304. let value = yield mgr_map.member.getJavaUserInfo(uid);
  305. F.addOtherLogs("imrw/imrw", ["push data to:", socket_list, uid]);
  306. co(that.push(socket_list, 'QueueMemberUpdateNotice', {
  307. 'room_id': room_id,
  308. 'type': type,
  309. 'key': key,
  310. 'value': value
  311. }));
  312. };
  313. };