Performance: Use a shared timer for polling RTP stats
This is now only relevant in case the user has enabled the developer option to show advanced media statistics, but still an easy performance fix.
This commit is contained in:
1 parent
8aead74ab9
commit
33fc8997f8
1 file changed
+6
-1
@@ -19,10 +19,15 @@ import {
|
|||||||
startWith,
|
startWith,
|
||||||
switchMap,
|
switchMap,
|
||||||
map,
|
map,
|
||||||
|
share,
|
||||||
} from "rxjs";
|
} from "rxjs";
|
||||||
|
|
||||||
import { observeTrackReference$ } from "../observeTrackReference";
|
import { observeTrackReference$ } from "../observeTrackReference";
|
||||||
|
|
||||||
|
// Use a shared timer for all the stats observers so that we don't clog up the
|
||||||
|
// event loop with hundreds of timers in large calls
|
||||||
|
const refreshStats$ = interval(1000).pipe(share());
|
||||||
|
|
||||||
export function observeRtpStreamStats$(
|
export function observeRtpStreamStats$(
|
||||||
participant: Participant,
|
participant: Participant,
|
||||||
source: Track.Source,
|
source: Track.Source,
|
||||||
@@ -32,7 +37,7 @@ export function observeRtpStreamStats$(
|
|||||||
> {
|
> {
|
||||||
return combineLatest([
|
return combineLatest([
|
||||||
observeTrackReference$(participant, source),
|
observeTrackReference$(participant, source),
|
||||||
interval(1000).pipe(startWith(0)),
|
refreshStats$.pipe(startWith(0)),
|
||||||
]).pipe(
|
]).pipe(
|
||||||
switchMap(async ([trackReference]) => {
|
switchMap(async ([trackReference]) => {
|
||||||
const track = trackReference?.publication?.track;
|
const track = trackReference?.publication?.track;
|
||||||
|
|||||||
Reference in new issue
Block a user