Skip to content

Commit

Permalink
fix custom display track detection
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed Mar 21, 2024
1 parent f26fcaf commit 54c9946
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions scripts/peer-connection-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async function getPeerConnectionStats(
outboundRtp: {},
}
if (track.kind === 'video') {
values.isDisplay = isDisplayTrack(track)
values.isDisplay = isSenderDisplayTrack(track)
values.videoSentActiveEncodings = encodings.length
values.videoSentMaxBitrate = encodings.reduce((prev, encoding) => {
prev += encoding.maxBitrate || 0
Expand Down Expand Up @@ -322,7 +322,7 @@ async function getPeerConnectionStats(
inboundRtp: {},
}
if (track.kind === 'video') {
values.isDisplay = isDisplayTrack(track)
values.isDisplay = window.isReceiverDisplayTrack(track)
}
for (const s of stats.values()) {
if (raw) {
Expand Down Expand Up @@ -526,11 +526,11 @@ setInterval(() => {
}, TRACK_STATS_TIMEOUT)

/**
* isDisplayTrack
* isSenderDisplayTrack
* @param {MediaStreamTrack} videoTrack
* @return {Boolean}
*/
const isDisplayTrack = videoTrack => {
const isSenderDisplayTrack = videoTrack => {
if (['detail', 'text'].indexOf(videoTrack.contentHint) !== -1) {
return true
}
Expand Down Expand Up @@ -559,6 +559,10 @@ const isDisplayTrack = videoTrack => {
}
}

window.isReceiverDisplayTrack = track => {
return isSenderDisplayTrack(track)
}

/**
* collectPeerConnectionStats
* @param {boolean} verbose
Expand Down
3 changes: 2 additions & 1 deletion src/rtcstats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ function setStats(
stats: RtcStats,
name: RtcStatsMetricNames,
key: string,
value: number | string,
value?: number | string,
): void {
assert(RtcStatsMetrics.includes(name), `Unknown stat name: ${name}`)
if (value === undefined) return
if (!stats[name]) {
stats[name] = {}
}
Expand Down

0 comments on commit 54c9946

Please sign in to comment.