Files
FrozenFriendsYume/packages/backend/built/server/api/stream/channels/queue-stats.js
T
2026-07-26 18:25:37 +09:00

36 lines
1013 B
JavaScript

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