imMsgMgr.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * 房间消息管理IM接口
  3. */
  4. 'use strict';
  5. const F = require('../common/function');
  6. const C = require('../config/index');
  7. const _ = require('underscore');
  8. _.str = require('underscore.string');
  9. _.v = require('validator');
  10. const co = require('co');
  11. module.exports = function (server) {
  12. //model、manager Map对象
  13. let managerMap = server.common_mgr.mgr_map;
  14. let mgr_map = managerMap;
  15. //server 配置
  16. let imapp = server;
  17. /**
  18. * 6.1 发送非文本消息(Client -> Server)
  19. */
  20. imapp.io.route('sendMessage', function* (next, ctx, msg, cb) {
  21. yield F.imCheckParamsNull(msg.req_data, "room_id");
  22. let room_id = msg.req_data.room_id;
  23. let socket_id = ctx.uniid;
  24. let is_in_room = mgr_map.validator.isRoomSocket(room_id, socket_id);
  25. if (!is_in_room) {
  26. F.throwErrCode(100201);
  27. }
  28. let room_socket = yield mgr_map.redis.getRoomSocketList(room_id);
  29. co(mgr_map.notice.push(room_socket, 'sendMessageReport', msg.req_data));
  30. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0));
  31. });
  32. /**
  33. * 6.3 发送文本消息(Client -> Server)
  34. */
  35. imapp.io.route('sendText', function* (next, ctx, msg, cb) {
  36. yield F.imCheckParamsNull(msg.req_data, "room_id");
  37. let room_id = msg.req_data.room_id;
  38. let socket_id = ctx.uniid;
  39. let is_in_room = mgr_map.validator.isRoomSocket(room_id, socket_id);
  40. if (!is_in_room) {
  41. F.throwErrCode(100201);
  42. }
  43. let ret = yield mgr_map.validator.checkRealName(ctx.uid, 'sendtext');
  44. let result;
  45. if (ret.code == 200) {
  46. let room_socket = yield mgr_map.redis.getRoomSocketList(room_id);
  47. co(mgr_map.notice.push(room_socket, 'sendTextReport', msg.req_data));
  48. result = F.packResJson(0);
  49. } else {
  50. result = F.packResErrMsg(ret.code, ret.message);
  51. }
  52. yield mgr_map.im.sendRes(ctx.uniid, msg, result);
  53. });
  54. };