Sharkey/src/server/api/stream/channels/notes-stats.ts

39 lines
797 B
TypeScript
Raw Normal View History

import autobind from 'autobind-decorator';
import Xev from 'xev';
import Channel from '../channel';
const ev = new Xev();
export default class extends Channel {
public readonly chName = 'notesStats';
2018-10-11 17:07:20 +03:00
public static shouldShare = true;
2018-11-10 19:22:34 +02:00
public static requireCredential = false;
@autobind
public async init(params: any) {
ev.addListener('notesStats', this.onStats);
}
@autobind
private onStats(stats: any) {
this.send('stats', stats);
}
@autobind
public onMessage(type: string, body: any) {
switch (type) {
case 'requestLog':
ev.once(`notesStatsLog:${body.id}`, statsLog => {
this.send('statsLog', statsLog);
});
ev.emit('requestNotesStatsLog', body.id);
break;
}
}
@autobind
public dispose() {
ev.removeListener('notesStats', this.onStats);
}
}