"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppEventsFactory = void 0;
const events_1 = __importDefault(require("events"));
const const_1 = require("../utils/const");
class AppEventsFactory {
    constructor() {
        this.eventEmitter = new events_1.default();
        this.eventEmitter.setMaxListeners(100000000);
    }
    static getInstance() {
        if (!AppEventsFactory.instance) {
            AppEventsFactory.instance = new AppEventsFactory();
        }
        return AppEventsFactory.instance;
    }
    sub(eventName, handler) {
        this.eventEmitter.on(eventName, handler);
    }
    unSub(evenName, handler) {
        this.eventEmitter.removeListener(evenName, handler);
    }
    pub(eventName, doc) {
        this.eventEmitter.emit(eventName, doc);
    }
    eventName(projectId, domain) {
        return const_1.Const.DB_CHANGES_EVENT.concat(domain).concat(projectId);
    }
    connected(eventName) {
        return this.eventEmitter.listenerCount(eventName);
    }
}
exports.AppEventsFactory = AppEventsFactory;
