bug: improve relay handeling

This commit is contained in:
2023-01-26 10:48:21 +00:00
parent bb8f6bd070
commit 64b28263d6
8 changed files with 39 additions and 17 deletions

View File

@ -29,10 +29,12 @@ export type StateSnapshot = {
received: number,
send: number
},
info?: RelayInfo
info?: RelayInfo,
id: string
};
export default class Connection {
Id: string;
Address: string;
Socket: WebSocket | null;
Pending: Subscriptions[];
@ -50,6 +52,7 @@ export default class Connection {
EventsCallback: Map<u256, () => void>;
constructor(addr: string, options: RelaySettings) {
this.Id = uuid();
this.Address = addr;
this.Socket = null;
this.Pending = [];
@ -285,6 +288,7 @@ export default class Connection {
this.CurrentState.avgLatency = this.Stats.Latency.length > 0 ? (this.Stats.Latency.reduce((acc, v) => acc + v, 0) / this.Stats.Latency.length) : 0;
this.CurrentState.disconnects = this.Stats.Disconnects;
this.CurrentState.info = this.Info;
this.CurrentState.id = this.Id;
this.Stats.Latency = this.Stats.Latency.slice(-20); // trim
this.HasStateChange = true;
this._NotifyState();