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

67 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-04-17 14:42:13 +09:00
import Xev from 'xev';
import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import Channel from '../channel.js';
2022-04-17 14:42:13 +09:00
const ev = new Xev();
2022-09-18 03:27:08 +09:00
class ServerStatsChannel 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);
}
@bindThis
public async init(params: any) {
ev.addListener('serverStats', this.onStats);
}
@bindThis
private onStats(stats: any) {
this.send('stats', stats);
}
@bindThis
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;
}
}
@bindThis
public dispose() {
ev.removeListener('serverStats', this.onStats);
}
}
2022-09-18 03:27:08 +09:00
@Injectable()
export class ServerStatsChannelService {
public readonly shouldShare = ServerStatsChannel.shouldShare;
public readonly requireCredential = ServerStatsChannel.requireCredential;
constructor(
) {
}
@bindThis
2022-09-18 03:27:08 +09:00
public create(id: string, connection: Channel['connection']): ServerStatsChannel {
return new ServerStatsChannel(
id,
connection,
);
}
}