Преглед изворни кода

Merge branch 'dev' of lyr/im.doctor into dev

linzhuo пре 8 година
родитељ
комит
28c4d14963
2 измењених фајлова са 15 додато и 21 уклоњено
  1. 1 9
      src/doctor/models/patient.js
  2. 14 12
      src/doctor/models/socket.io/client.cache.js

+ 1 - 9
src/doctor/models/patient.js

@ -81,15 +81,7 @@ class Patient extends BaseModel {
                modelUtil.emitData(self.eventEmitter, Doctor.fillMessages(msg));
                // 通过Web Socket推送给患者
                let patientClient = clientCache.findById(message.to);
                if (!patientClient) {
                    log.warn("User is not online, user id: ", message.to);
                    //发送微信模板消息
                    self.sendConsultWechatReplyTempMsg(message);
                    return;
                }
                patientClient.socketServer.sockets.emit('message', message);
                self.pushGroupMessage(message);
            });
            // 更新自身的聊天统计信息

+ 14 - 12
src/doctor/models/socket.io/client.cache.js

@ -11,46 +11,48 @@ var log = require('../../util/log');
var clientCache = null;
class ClientCache {
    constructor(){
    constructor() {
        this._clientsBySocket = new Map();
        this._clientsByUserId = new Map();
    }
    get clients(){
    get clients() {
        return this._clientsByUserId;
    }
    addClient(client){
    addClient(client) {
        this._clientsByUserId.set(client.userId, client);
        this._clientsBySocket.set(client.socket, client);
        //log.info('Current clients: ', this.clients);
    }
    removeByUserId(userId){
    removeByUserId(userId) {
        var socket = this.findById(userId);
        this._clientsByUserId.delete(userId);
        this._clientsBySocket.delete(socket);
    }
    removeByUserSocket(socket){
        var userId = this.findBySocket(socket);
    removeByUserSocket(socket) {
        var client = this.findBySocket(socket);
        this._clientsByUserId.delete(userId);
        this._clientsBySocket.delete(socket);
        if (client) {
            this._clientsByUserId.delete(client.userId);
            this._clientsBySocket.delete(socket);
        }
    }
    findById(userId){
    findById(userId) {
        return this._clientsByUserId.get(userId);
    }
    findBySocket(socket){
    findBySocket(socket) {
        return this._clientsBySocket.get(socket);
    }
    static clientCache(){
        if(clientCache === null){
    static clientCache() {
        if (clientCache === null) {
            clientCache = new ClientCache();
        }