imPublicRoomMgr.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. * 7.1.进入公屏聊天室(Client→Server)军圣
  16. */
  17. imapp.io.route('enterPublicRoom', 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 uid = ctx.uid;
  21. let socket_id = ctx.uniid;
  22. let his_list = yield mgr_map.publicRoom.enterPublicRoom(room_id, socket_id, uid);
  23. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0, {
  24. "his_list": his_list
  25. }));
  26. });
  27. /**
  28. * 7.2.发送公屏聊天室消息(Client→Server)军圣
  29. */
  30. imapp.io.route('sendPublicMsg', function* (next, ctx, msg, cb) {
  31. // 1、校验参数
  32. yield F.imCheckParamsNull(msg.req_data, "room_id");
  33. let room_id = msg.req_data.room_id;
  34. // 2、判断用户是否在房间
  35. let is_in_public = yield mgr_map.validator.isInPublicRoom(room_id, ctx.uniid);
  36. if (!is_in_public) {
  37. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(100601));
  38. return;
  39. }
  40. // 4、往房间发送公屏消息
  41. let ret = yield mgr_map.validator.checkRealName(ctx.uid, 'sendpublic');
  42. if (ret.code == 200) {
  43. yield mgr_map.publicRoom.sendPublicMsgNotice(msg.req_data);
  44. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0));
  45. } else {
  46. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResErrMsg(ret.code, ret.message));
  47. }
  48. });
  49. /**
  50. * 7.6. 退出公聊大厅(Client→Server) 军圣
  51. */
  52. imapp.io.route('exitPublicRoom', function* (next, ctx, msg, cb) {
  53. yield F.imCheckParamsNull(msg.req_data, "room_id");
  54. let room_id = msg.req_data.room_id;
  55. yield mgr_map.publicRoom.leavePublicRoom(ctx.uid, ctx.uniid, room_id);
  56. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0));
  57. });
  58. };