2018-10-07 11:06:17 +09:00
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import Xev from 'xev';
|
|
|
|
import Channel from '../channel';
|
|
|
|
|
|
|
|
const ev = new Xev();
|
|
|
|
|
|
|
|
export default class extends Channel {
|
2018-10-11 23:01:57 +09:00
|
|
|
public readonly chName = 'serverStats';
|
|
|
|
public readonly shouldShare = true;
|
|
|
|
|
2018-10-07 11:06:17 +09: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,
|
|
|
|
length: body.length
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
public dispose() {
|
|
|
|
ev.removeListener('serverStats', this.onStats);
|
|
|
|
}
|
|
|
|
}
|