36 lines
1018 B
JavaScript
36 lines
1018 B
JavaScript
import Xev from "xev";
|
|
import Channel from "../channel.js";
|
|
const ev = new Xev();
|
|
export default class extends Channel {
|
|
chName = "serverStats";
|
|
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("serverStats", this.onStats);
|
|
}
|
|
onStats(stats) {
|
|
this.send("stats", stats);
|
|
}
|
|
onMessage(type, body) {
|
|
switch(type){
|
|
case "requestLog":
|
|
ev.once(`serverStatsLog:${body.id}`, (statsLog)=>{
|
|
this.send("statsLog", statsLog);
|
|
});
|
|
ev.emit("requestServerStatsLog", {
|
|
id: body.id,
|
|
length: body.length
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
dispose() {
|
|
ev.removeListener("serverStats", this.onStats);
|
|
}
|
|
}
|