imQueueMgr.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 model_mgr = server.model_mgr.model_map;
  14. let mgr_map = server.common_mgr.mgr_map;
  15. //server 配置
  16. let serverIO = server.io;
  17. /**
  18. * 5.1. 更新队列元素
  19. */
  20. serverIO.route('updateQueue', function* (next, ctx, msg, cb) {
  21. yield F.imCheckParamsNull(msg.req_data,"room_id,key,uid");
  22. let operator_uid = ctx.uid;
  23. let room_id = msg.req_data.room_id;
  24. let key = msg.req_data.key;
  25. let uid = msg.req_data.uid;
  26. yield mgr_map.roomQueue.addToRoomQueue(operator_uid,room_id,key,uid,ctx.appCode);
  27. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0));
  28. });
  29. /**
  30. * 5.3 取出/删除队列元素
  31. */
  32. serverIO.route('pollQueue', function* (next, ctx, msg, cb) {
  33. yield F.imCheckParamsNull(msg.req_data,"room_id,key");
  34. let operator_uid = ctx.uid;
  35. let room_id = msg.req_data.room_id;
  36. let key = msg.req_data.key;
  37. yield mgr_map.roomQueue.delFromRoomQueue(operator_uid,room_id,key);
  38. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0));
  39. });
  40. /**
  41. * 5.4. 获取队列
  42. */
  43. serverIO.route('fetchQueue', function* (next, ctx, msg, cb) {
  44. yield F.imCheckParamsNull(msg.req_data,"room_id");
  45. let room_id = msg.req_data.room_id;
  46. let queue_list = yield mgr_map.roomQueue.getRoomQueueList(room_id);
  47. yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0, queue_list));
  48. });
  49. };