diff --git a/src/stats.ts b/src/stats.ts index 1ea9ccc..39fc5cf 100644 --- a/src/stats.ts +++ b/src/stats.ts @@ -476,16 +476,7 @@ export class Stats extends events.EventEmitter { ) } - this.collectedStats = this.statsNames.reduce((prev, name: string) => { - prev[name] = { - all: new FastStats(), - byHost: {}, - byCodec: {}, - byParticipantAndTrack: {}, - } as CollectedStats - return prev - }, {} as Record) - + this.collectedStats = this.initCollectedStats() this.sessions = new Map() this.nextSessionId = startSessionId this.startTimestamp = startTimestamp @@ -541,6 +532,18 @@ export class Stats extends events.EventEmitter { } } + private initCollectedStats(): Record { + return this.statsNames.reduce((prev, name: string) => { + prev[name] = { + all: new FastStats(), + byHost: {}, + byCodec: {}, + byParticipantAndTrack: {}, + } as CollectedStats + return prev + }, {} as Record) + } + private get statsNames(): string[] { return Object.keys(PageStatsNames) .concat(Object.keys(RtcStatsMetricNames)) @@ -1836,7 +1839,7 @@ export class Stats extends events.EventEmitter { this.metrics = {} } - this.collectedStats = {} + this.collectedStats = this.initCollectedStats() this.externalCollectedStats.clear() } }