"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WsContext = void 0;
class WsContext {
    constructor(connId, socket) {
        this.socket = socket;
        this.subs = new Map();
        this.connId = connId;
    }
    send(msg) {
        if (this.socket.readyState !== this.socket.OPEN)
            return;
        this.socket.send(JSON.stringify(msg));
    }
    addSub(topic, key) {
        const set = this.subs.get(topic) ?? new Set();
        set.add(key);
        this.subs.set(topic, set);
    }
    delSub(topic, key) {
        const set = this.subs.get(topic);
        if (!set)
            return;
        set.delete(key);
        if (set.size === 0)
            this.subs.delete(topic);
    }
    hasSub(topic, key) {
        return this.subs.get(topic)?.has(key) ?? false;
    }
    clearAll() {
        this.subs.clear();
    }
}
exports.WsContext = WsContext;
