mirror of
https://github.com/syuilo/ai.git
synced 2024-11-22 05:08:00 +00:00
Fix
This commit is contained in:
parent
e81f9a75dc
commit
030c1e6966
|
@ -1,9 +1,7 @@
|
||||||
import * as WebSocket from 'ws';
|
|
||||||
import 藍 from '../../ai';
|
import 藍 from '../../ai';
|
||||||
import IModule from '../../module';
|
import IModule from '../../module';
|
||||||
import serifs from '../../serifs';
|
import serifs from '../../serifs';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
const ReconnectingWebSocket = require('reconnecting-websocket');
|
|
||||||
|
|
||||||
export default class ServerModule implements IModule {
|
export default class ServerModule implements IModule {
|
||||||
public readonly name = 'server';
|
public readonly name = 'server';
|
||||||
|
@ -24,24 +22,8 @@ export default class ServerModule implements IModule {
|
||||||
|
|
||||||
this.ai = ai;
|
this.ai = ai;
|
||||||
|
|
||||||
this.connection = new ReconnectingWebSocket(`${config.wsUrl}/server-stats`, [], {
|
this.connection = this.ai.connection.useSharedConnection('serverStats');
|
||||||
WebSocket: WebSocket
|
this.connection.on('stats', this.onStats);
|
||||||
});
|
|
||||||
|
|
||||||
this.connection.addEventListener('open', () => {
|
|
||||||
console.log('server-stats stream opened');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.connection.addEventListener('close', () => {
|
|
||||||
console.log('server-stats stream closed');
|
|
||||||
this.connection._shouldReconnect && this.connection._connect()
|
|
||||||
});
|
|
||||||
|
|
||||||
this.connection.addEventListener('message', message => {
|
|
||||||
const msg = JSON.parse(message.data);
|
|
||||||
|
|
||||||
this.onConnectionMessage(msg);
|
|
||||||
});
|
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.statsLogs.unshift(this.recentStat);
|
this.statsLogs.unshift(this.recentStat);
|
||||||
|
@ -65,21 +47,8 @@ export default class ServerModule implements IModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private onConnectionMessage = (msg: any) => {
|
|
||||||
switch (msg.type) {
|
|
||||||
|
|
||||||
case 'stats': {
|
|
||||||
this.onStats(msg.body);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private onStats = async (stats: any) => {
|
private onStats = async (stats: any) => {
|
||||||
this.recentStat = stats;
|
this.recentStat = stats.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
private warn = () => {
|
private warn = () => {
|
||||||
|
|
Loading…
Reference in a new issue