-
Notifications
You must be signed in to change notification settings - Fork 167
Add several new metrics and expose original RTCStatsReport in useMediaStreamMetrics hook #795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| availableOutgoingBandwidth, | ||
| availableIncomingBandwidth, | ||
| videoStreamMetrics, | ||
| audioPacketsSentFractionLossPercent: audioPacketLossPercent | 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Math.trunc anymore here? Earlier see that we use Math.trunc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew this could be confusing so I left comment above to explain this:
// Return 0 if the metric value is NaN, otherwise return its integer part.
The bitwise OR operator truncates the value.
for example:
NaN | 0 = 0
undefined | 0 = 0
1 | 0 = 1
1.1 | 0 = 1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this is hard to understand and readers or contributors may get confused, to keep this simple can we simply use the Math.trunc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already left comment for this, don't think it's necessary to add extra Math.trunc. I would like to change this if you have strong opinion, but personally I prefer not. Don't think this redundancy benefits too much.
setMediaStreamMetrics({
audioPacketsSentFractionLossPercent:
Math.trunc(audioPacketLossPercent) | 0,
audioPacketsReceivedFractionLossPercent:
Math.trunc(audioPacketsReceivedFractionLoss) | 0,
audioSpeakerDelayMs: Math.trunc(audioSpeakerDelayMs) | 0,
audioUpstreamRoundTripTimeMs:
Math.trunc(audioUpstreamRoundTripTimeMs) | 0,
audioUpstreamJitterMs: Math.trunc(audioUpstreamJitterMs) | 0,
audioDownstreamJitterMs: Math.trunc(audioDownstreamJitterMs) | 0,
currentRoundTripTimeMs: Math.trunc(currentRoundTripTimeMs) | 0,
availableOutgoingBandwidth:
Math.trunc(availableOutgoingBitrate / 1000) | 0,
availableIncomingBandwidth:
Math.trunc(availableIncomingBitrate / 1000) | 0,
rtcStatsReport: clientMetricReport.getRTCStatsReport(),
videoStreamMetrics: clientMetricReport.getObservableVideoMetrics(),
});setMediaStreamMetrics({
audioPacketsSentFractionLossPercent: audioPacketLossPercent | 0,
audioPacketsReceivedFractionLossPercent:
audioPacketsReceivedFractionLoss | 0,
audioSpeakerDelayMs: audioSpeakerDelayMs | 0,
audioUpstreamRoundTripTimeMs: audioUpstreamRoundTripTimeMs | 0,
audioUpstreamJitterMs: audioUpstreamJitterMs | 0,
audioDownstreamJitterMs: audioDownstreamJitterMs | 0,
currentRoundTripTimeMs: currentRoundTripTimeMs | 0,
availableOutgoingBandwidth: (availableOutgoingBitrate / 1000) | 0,
availableIncomingBandwidth: (availableIncomingBitrate / 1000) | 0,
rtcStatsReport: clientMetricReport.getRTCStatsReport(),
videoStreamMetrics: clientMetricReport.getObservableVideoMetrics(),
});There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have to trunc for units in Ms or truncing only applies to the percent metrics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyways fine to keep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have to trunc for units in Ms or truncing only applies to the percent metrics?
In the previous version, all metrics are truncated.
We did something like this:
const { audioPacketLossPercent } = clientMetricReport.getObservableMetrics();
// 1. Set the default value 0
let audioPacketsSentFractionLossPercent = 0;
// 2. Validate metric value
if (isValidMetric(audioPacketLossPercent)) {
// 3. Truncate the value
audioPacketsSentFractionLossPercent = Math.trunc(
audioPacketLossPercent
);
}
// 4. Return
setMediaStreamMetrics({
audioPacketsSentFractionLossPercent
)}It's quite redundant if there are more and more metrics, cause we have to use a local variable to store the default value for every metrics and validate all of them.
The main goal here to use | is to merge the previous step 1, 2 and 3 to simplify the logic.
Issue #:
Description of changes:
audioSpeakerDelayMs,audioUpstreamRoundTripTimeMs,audioUpstreamJitterMs,audioDownstreamJitterMsandcurrentRoundTripTimeMsmetrics touseMediaStreamMetricshook. Also addrtcStatsReportto expose the originalRTCStatsReportfrom RTCPeerConnection.getStats().Testing
Have you successfully run
npm run build:releaselocally?Yes
How did you test these changes?
Change the test demo and use the hook. Check the console log and confirm the metrics are correctly returned.
If you made changes to the component library, have you provided corresponding documentation changes?
Yes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.