Skip to content

Commit 20cfe39

Browse files
authored
Add several new metrics and expose original RTCStatsReport in useMediaStreamMetrics hook (#795)
* Add new metrics and RTCStatsReport in useMediaStreamMetrics * Upgrade JS SDK to 3.1.0
1 parent f1b5994 commit 20cfe39

File tree

7 files changed

+148
-96
lines changed

7 files changed

+148
-96
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14+
- Add `audioSpeakerDelayMs`, `audioUpstreamRoundTripTimeMs`, `audioUpstreamJitterMs`, `audioDownstreamJitterMs` and `currentRoundTripTimeMs` metrics to `useMediaStreamMetrics` hook. Also add `rtcStatsReport` to expose the original [`RTCStatsReport`](https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport) from [RTCPeerConnection.getStats()](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats).
15+
1416
### Removed
1517

1618
### Changed

integration/app/test-demo/package-lock.json

Lines changed: 34 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"@typescript-eslint/eslint-plugin": "^4.33.0",
8585
"@typescript-eslint/parser": "^4.33.0",
8686
"add": "^2.0.6",
87-
"amazon-chime-sdk-js": "^3.0.0",
87+
"amazon-chime-sdk-js": "^3.1.0",
8888
"babel-loader": "^8.1.0",
8989
"css-loader": "^6.7.1",
9090
"eslint": "^7.32.0",

src/hooks/sdk/docs/useMediaStreamMetrics.stories.mdx

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
# useMediaStreamMetrics
44

5-
The `useMediaStreamMetrics` hook returns the available audio, video and bandwidth metrics for the current meeting session. Video metrics contains stream metrics for all attendeeIds.
5+
The `useMediaStreamMetrics` hook returns:
6+
7+
- common metrics for audio stream
8+
- common metrics for video stream of all attendees
9+
- original [RTCStatsReport](https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport) returned by [RTCPeerConnection.getStats()](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/getStats)
610

711
This hook re-renders frequently. You should avoid using it high in your app tree, and ideally use it in your leaf components.
812

913
### Return Value
1014

11-
```javascript
15+
```ts
1216
{
1317
audioPacketsSentFractionLossPercent: number | null;
1418
audioPacketsReceivedFractionLossPercent: number | null;
19+
audioSpeakerDelayMs: number | null;
20+
audioUpstreamRoundTripTimeMs: number | null;
21+
audioUpstreamJitterMs: number | null;
22+
audioDownstreamJitterMs: number | null;
23+
currentRoundTripTimeMs: number | null;
1524
availableOutgoingBandwidth: number | null;
1625
availableIncomingBandwidth: number | null;
17-
videoStreamMetrics: { [attendeeId: string]: { [ssrc: string]: {[key: string]: number} } }
26+
rtcStatsReport: RTCStatsReport | null;
27+
videoStreamMetrics: { [attendeeId: string]: { [ssrc: string]: { [key: string]: number } } };
1828
}
1929
```
2030

@@ -30,28 +40,35 @@ The hook depends on the `AudioVideoProvider` being rendered. If you are using th
3040

3141
The `videoStreamMetrics` in return value is a map of attendee to stream of video metrics mappings. The format of `videoStreamMetrics` is shown below:
3242

33-
```
34-
videoStreamMetrics {
35-
attendeeId:{ // remote attendees will have downstream metrics
43+
```ts
44+
videoStreamMetrics: {
45+
remoteAttendeeId: {
46+
// remote attendees will have downstream metrics
3647
ssrc: {
3748
videoDownstreamBitrate: number;
3849
videoDownstreamPacketLossPercent: number;
50+
videoDownstreamPacketsReceived: number;
3951
videoDownstreamFramesDecodedPerSecond: number;
4052
videoDownstreamFrameHeight: number;
4153
videoDownstreamFrameWidth: number;
54+
videoDownstreamJitterMs: number;
55+
videoDownstreamDelayMs: number;
4256
}
4357
}
44-
attendeeId: { // local attendee will have upstream metrics
58+
localAttendeeId: {
59+
// local attendee will have upstream metrics
4560
ssrc: {
4661
videoUpstreamBitrate: number;
4762
videoUpstreamPacketsSent: number;
63+
videoUpstreamPacketLossPercent: number;
4864
videoUpstreamFramesEncodedPerSecond: number;
4965
videoUpstreamFrameHeight: number;
5066
videoUpstreamFrameWidth: number;
67+
videoUpstreamJitterMs: number;
68+
videoUpstreamRoundTripTimeMs: number;
5169
}
5270
}
5371
}
54-
5572
```
5673

5774
```jsx
@@ -69,18 +86,30 @@ const App = () => (
6986

7087
const MyChild = () => {
7188
const metrics = useMediaStreamMetrics();
89+
const rtcStatsReportValues: ReactElement[] = [];
90+
91+
metrics.rtcStatsReport?.forEach((report) =>
92+
rtcStatsReportValues.push(<pre>{JSON.stringify(report, null, 2)}</pre>)
93+
);
7294

7395
return (
74-
<>
75-
<p>Audio Uplink 1s loss: {metrics.audioPacketsSentFractionLossPercent}</p>
76-
<p>
77-
Audio Downlink 1s loss:{' '}
78-
{metrics.audioPacketsReceivedFractionLossPercent}
79-
</p>
80-
<p>Bandwidth Incoming: {metrics.availableIncomingBandwidth}</p>
81-
<p>Bandwidth Outgoing: {metrics.availableOutgoingBandwidth}</p>
82-
<p>Video Metrics: {metrics.videoStreamMetrics}</p>
83-
</>
96+
<div>
97+
<p>audioPacketsSentFractionLossPercent: {metrics.audioPacketsSentFractionLossPercent}</p>
98+
<p>audioPacketsReceivedFractionLossPercent: {metrics.audioPacketsReceivedFractionLossPercent}</p>
99+
<p>audioSpeakerDelayMs: {metrics.audioSpeakerDelayMs}</p>
100+
<p>audioUpstreamRoundTripTimeMs: {metrics.audioUpstreamRoundTripTimeMs}</p>
101+
<p>audioUpstreamJitterMs: {metrics.audioUpstreamJitterMs}</p>
102+
<p>audioDownstreamJitterMs: {metrics.audioDownstreamJitterMs}</p>
103+
<p>currentRoundTripTimeMs: {metrics.currentRoundTripTimeMs}</p>
104+
<p>availableOutgoingBandwidth: {metrics.availableOutgoingBandwidth}</p>
105+
<p>availableIncomingBandwidth: {metrics.availableIncomingBandwidth}</p>
106+
<p>videoStreamMetrics</p>
107+
<code>
108+
<pre>{JSON.stringify(metrics.videoStreamMetrics, null, 2)}</pre>
109+
</code>
110+
<p>rtcStatsReport</p>
111+
<code>{...rtcStatsReportValues}</code>
112+
</div>
84113
);
85114
};
86115
```

0 commit comments

Comments
 (0)