mizzkey/packages/backend/src/server/api/stream/channels/server-stats.ts

43 lines
941 B
TypeScript
Raw Normal View History

2022-04-17 14:42:13 +09:00
import Xev from 'xev';
import Channel from '../channel.js';
2022-04-17 14:42:13 +09:00
const ev = new Xev();
export default class extends Channel {
public readonly chName = 'serverStats';
2018-10-11 23:07:20 +09:00
public static shouldShare = true;
2018-11-11 02:22:34 +09:00
public static requireCredential = false;
constructor(id: string, connection: Channel['connection']) {
super(id, connection);
this.onStats = this.onStats.bind(this);
this.onMessage = this.onMessage.bind(this);
}
public async init(params: any) {
ev.addListener('serverStats', this.onStats);
}
private onStats(stats: any) {
this.send('stats', stats);
}
public onMessage(type: string, body: any) {
switch (type) {
case 'requestLog':
ev.once(`serverStatsLog:${body.id}`, statsLog => {
this.send('statsLog', statsLog);
});
ev.emit('requestServerStatsLog', {
id: body.id,
2021-12-09 23:58:30 +09:00
length: body.length,
});
break;
}
}
public dispose() {
ev.removeListener('serverStats', this.onStats);
}
}