Skip to content

Commit

Permalink
Add getRTCStatsReport method to local and remote track classes (#826)
Browse files Browse the repository at this point in the history
* Add getRTCStatsReport method to local and remote track classes

* Use optional chaining in getRTCStatsReport methods
  • Loading branch information
tab1293 authored Sep 14, 2023
1 parent ad285af commit 20ffe01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/room/track/LocalTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ export default abstract class LocalTrack extends Track {
}
}

/**
* Gets the RTCStatsReport for the LocalTrack's underlying RTCRtpSender
* See https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport
*
* @returns Promise<RTCStatsReport> | undefined
*/
async getRTCStatsReport(): Promise<RTCStatsReport | undefined> {
if (!this.sender?.getStats) {
return;
}
const statsReport = await this.sender.getStats();
return statsReport;
}

/**
* Sets a processor on this track.
* See https://github.com/livekit/track-processors-js for example usage
Expand Down
14 changes: 14 additions & 0 deletions src/room/track/RemoteTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ export default abstract class RemoteTrack extends Track {
super.disable();
}

/**
* Gets the RTCStatsReport for the RemoteTrack's underlying RTCRtpReceiver
* See https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport
*
* @returns Promise<RTCStatsReport> | undefined
*/
async getRTCStatsReport(): Promise<RTCStatsReport | undefined> {
if (!this.receiver?.getStats) {
return;
}
const statsReport = await this.receiver.getStats();
return statsReport;
}

/* @internal */
startMonitor() {
if (!this.monitorInterval) {
Expand Down

0 comments on commit 20ffe01

Please sign in to comment.