imRoomMgr.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * 房间管理im接口
  3. */
  4. 'use strict';
  5. var F = require('../common/function');
  6. var C = require('../config/index');
  7. var _ = require('underscore');
  8. _.str = require('underscore.string');
  9. _.v = require('validator');
  10. module.exports = function (app) {
  11. var model_map = app.model_mgr.model_map;
  12. var mgr_map = app.common_mgr.mgr_map;
  13. var imapp = app;
  14. /**
  15. * 4.7.进入聊天室
  16. */
  17. imapp.io.route('enterChatRoom', function* (next, ctx, msg, cb) {
  18. yield F.imCheckParamsNull(msg.req_data, "room_id");
  19. let room_id = msg.req_data.room_id;
  20. let room_info = yield mgr_map.room.getRoomInfo(room_id);
  21. if (F.isNull(room_info)) {
  22. F.throwErrCode(100200);
  23. }
  24. // 鉴权
  25. let is_in_black_list = yield mgr_map.redis.isBlacklist(room_id, ctx.uid);
  26. if (is_in_black_list) F.throwErrCode(100202);
  27. // 在这里把离开用户之前进的房间
  28. yield mgr_map.room.leavePreRoom(ctx.uid);
  29. let member = yield mgr_map.member.getJavaUserInfo(ctx.uid);
  30. member = yield mgr_map.member.extendMemberInfo(member, room_info);
  31. yield mgr_map.room.enterRoom(ctx.uid, ctx.uniid, room_id); // 执行进入房间函数
  32. let online_user_count = yield mgr_map.redis.getRoomUserCount(room_id);
  33. room_info.onlineNum = online_user_count; // 实时取im在线人数
  34. if (room_info.uid == ctx.uid) { // 说明是房主自己进房间
  35. yield mgr_map.roomQueue.addToRoomQueue(ctx.uid, room_id, -1, ctx.uid, ctx.appCode);
  36. }
  37. let queue_list = yield mgr_map.roomQueue.getRoomQueueList(room_id);
  38. let res = {
  39. 'room_info': room_info,
  40. 'member': member,
  41. 'queue_list': queue_list,
  42. 'mic_info': ''
  43. };
  44. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0, res));
  45. });
  46. /**
  47. * 4.9.退出聊天室
  48. */
  49. imapp.io.route('exitChatRoom', function* (next, ctx, msg, cb) {
  50. yield F.imCheckParamsNull(msg.req_data, "room_id");
  51. let room_id = msg.req_data.room_id;
  52. yield mgr_map.room.leaveRoom(ctx.uid, ctx.uniid, room_id);
  53. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0));
  54. });
  55. };