2018-10-07 04:06:17 +02:00
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import Xev from 'xev';
|
2021-08-19 14:55:45 +02:00
|
|
|
import Channel from '../channel';
|
2018-10-07 04:06:17 +02:00
|
|
|
|
|
|
|
const ev = new Xev();
|
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 16:01:57 +02:00
|
|
|
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;
|
2018-10-11 16:01:57 +02:00
|
|
|
|
2018-10-07 04:06:17 +02:00
|
|
|
@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,
|
2021-12-09 15:58:30 +01:00
|
|
|
length: body.length,
|
2018-10-07 04:06:17 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
public dispose() {
|
|
|
|
ev.removeListener('serverStats', this.onStats);
|
|
|
|
}
|
|
|
|
}
|