/** * 房间消息管理IM接口 */ 'use strict'; const F = require('../common/function'); const C = require('../config/index'); const _ = require('underscore'); _.str = require('underscore.string'); _.v = require('validator'); const co = require('co'); module.exports = function (server) { //model、manager Map对象 let managerMap = server.common_mgr.mgr_map; let mgr_map = managerMap; //server 配置 let imapp = server; /** * 6.1 发送非文本消息(Client -> Server) */ imapp.io.route('sendMessage', function* (next, ctx, msg, cb) { yield F.imCheckParamsNull(msg.req_data, "room_id"); let room_id = msg.req_data.room_id; let socket_id = ctx.uniid; let is_in_room = mgr_map.validator.isRoomSocket(room_id, socket_id); if (!is_in_room) { F.throwErrCode(100201); } let room_socket = yield mgr_map.redis.getRoomSocketList(room_id); co(mgr_map.notice.push(room_socket, 'sendMessageReport', msg.req_data)); yield mgr_map.im.sendRes(ctx.uniid, msg, F.packResJson(0)); }); /** * 6.3 发送文本消息(Client -> Server) */ imapp.io.route('sendText', function* (next, ctx, msg, cb) { yield F.imCheckParamsNull(msg.req_data, "room_id"); let room_id = msg.req_data.room_id; let socket_id = ctx.uniid; let is_in_room = mgr_map.validator.isRoomSocket(room_id, socket_id); if (!is_in_room) { F.throwErrCode(100201); } let ret = yield mgr_map.validator.checkRealName(ctx.uid, 'sendtext'); let result; if (ret.code == 200) { let room_socket = yield mgr_map.redis.getRoomSocketList(room_id); co(mgr_map.notice.push(room_socket, 'sendTextReport', msg.req_data)); result = F.packResJson(0); } else { result = F.packResErrMsg(ret.code, ret.message); } yield mgr_map.im.sendRes(ctx.uniid, msg, result); }); };