Browse Source

删除socket方法修改

lyr 8 years ago
parent
commit
3ea4c2bb49
1 changed files with 14 additions and 12 deletions
  1. 14 12
      src/doctor/models/socket.io/client.cache.js

+ 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();
        }