import Xev from "xev";
import Channel from "../channel.js";
const ev = new Xev();
export default class extends Channel {
    chName = "queueStats";
    static shouldShare = true;
    static requireCredential = false;
    constructor(id, connection){
        super(id, connection);
        this.onStats = this.onStats.bind(this);
        this.onMessage = this.onMessage.bind(this);
    }
    async init(params) {
        ev.addListener("queueStats", this.onStats);
    }
    onStats(stats) {
        this.send("stats", stats);
    }
    onMessage(type, body) {
        switch(type){
            case "requestLog":
                ev.once(`queueStatsLog:${body.id}`, (statsLog)=>{
                    this.send("statsLog", statsLog);
                });
                ev.emit("requestQueueStatsLog", {
                    id: body.id,
                    length: body.length
                });
                break;
        }
    }
    dispose() {
        ev.removeListener("queueStats", this.onStats);
    }
}
