Skip to content

Commit

Permalink
Properly handle stats stop
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed Oct 3, 2023
1 parent 018ce84 commit 4b55289
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, CollectedStats>)

this.collectedStats = this.initCollectedStats()
this.sessions = new Map()
this.nextSessionId = startSessionId
this.startTimestamp = startTimestamp
Expand Down Expand Up @@ -541,6 +532,18 @@ export class Stats extends events.EventEmitter {
}
}

private initCollectedStats(): Record<string, CollectedStats> {
return this.statsNames.reduce((prev, name: string) => {
prev[name] = {
all: new FastStats(),
byHost: {},
byCodec: {},
byParticipantAndTrack: {},
} as CollectedStats
return prev
}, {} as Record<string, CollectedStats>)
}

private get statsNames(): string[] {
return Object.keys(PageStatsNames)
.concat(Object.keys(RtcStatsMetricNames))
Expand Down Expand Up @@ -1836,7 +1839,7 @@ export class Stats extends events.EventEmitter {
this.metrics = {}
}

this.collectedStats = {}
this.collectedStats = this.initCollectedStats()
this.externalCollectedStats.clear()
}
}

0 comments on commit 4b55289

Please sign in to comment.