hippofish/src/server/api/stream/channels/server-stats.ts

42 lines
848 B
TypeScript
Raw Normal View History

import autobind from 'autobind-decorator';
import Xev from 'xev';
import Channel from '../channel.js';
const ev = new Xev();
export default class extends Channel {
public readonly chName = 'serverStats';
2018-10-11 16:07:20 +02:00
public static shouldShare = true;
2018-11-10 18:22:34 +01:00
public static requireCredential = false;
@autobind
public async init(params: any) {
ev.addListener('serverStats', this.onStats);
}
@autobind
private onStats(stats: any) {
this.send('stats', stats);
}
@autobind
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,
length: body.length
});
break;
}
}
@autobind
public dispose() {
ev.removeListener('serverStats', this.onStats);
}
}