@@ -94,36 +94,47 @@ async function isAudioPlayingFirefox(peerConnection, audioTrack) {
94
94
return packetsStart > 0 && packetsEnd > 0 && packetsEnd > packetsStart ;
95
95
}
96
96
97
- export async function inboundSimulcastStreamStats ( peerConnection ) {
98
- const stats = await peerConnection . getStats ( ) ;
99
- let data = { height : null , width : null , framesPerSecond : 0 }
100
- for ( let [ _key , report ] of stats ) {
101
- if ( report . type == "inbound-rtp" ) {
102
- data = getDataFromReport ( report )
103
- data . framesReceived = report . framesReceived
97
+ export async function inboundSimulcastStreamStats ( room ) {
98
+ // we are accessing room's private fields, in the name of science of course...
99
+ const peerConnection = room . webrtc . connection ;
100
+
101
+ const stats = room . peers . map ( async ( peer ) => {
102
+ const videoTrack = room . peerIdToVideoTrack [ peer . id ] ;
103
+ const track_stats = await peerConnection . getStats ( videoTrack ) ;
104
+
105
+ let data = { peerId : peer . id , height : null , width : null , framesPerSecond : 0 }
106
+ for ( let [ _key , report ] of track_stats ) {
107
+ if ( report . type == "inbound-rtp" ) {
108
+ data = getDataFromReport ( report )
109
+ data . framesReceived = report . framesReceived
110
+ data . peerId = peer . id
111
+ // The following works for one peer only...
112
+ data . encoding = room . getPeerEncoding ( )
113
+ }
104
114
}
105
- }
106
-
107
- return data
108
- }
109
115
116
+ return data ;
117
+ } ) ;
110
118
119
+ return ( await Promise . all ( stats ) ) ;
120
+ }
111
121
112
- export async function outboundSimulcastStreamStats ( peerConnection ) {
122
+ export async function outboundSimulcastStreamStats ( room ) {
123
+ const peerConnection = room . webrtc . connection ;
113
124
const stats = await peerConnection . getStats ( ) ;
114
125
115
- let streams = { "l" : null , "m" : null , "h" : null }
126
+ let data = { peerId : room . selfId , "l" : null , "m" : null , "h" : null }
116
127
for ( let [ _key , report ] of stats ) {
117
128
if ( report . type == "outbound-rtp" ) {
118
129
let rid = report . rid
119
- streams [ rid ] = getDataFromReport ( report )
120
- streams [ rid ] . framesSent = report . framesSent
121
- streams [ rid ] . qualityLimitationDuration = report [ "qualityLimitationDurations" ]
122
- streams [ rid ] . qualityLimitationReason = report [ "qualityLimitationReason" ]
130
+ data [ rid ] = getDataFromReport ( report )
131
+ data [ rid ] . framesSent = report . framesSent
132
+ data [ rid ] . qualityLimitationDuration = report [ "qualityLimitationDurations" ]
133
+ data [ rid ] . qualityLimitationReason = report [ "qualityLimitationReason" ]
123
134
}
124
135
}
125
136
126
- return streams
137
+ return data
127
138
}
128
139
129
140
function getDataFromReport ( values ) {
@@ -134,7 +145,8 @@ function getDataFromReport(values) {
134
145
return data
135
146
}
136
147
137
- export async function remoteStreamsStats ( peerConnection ) {
148
+ export async function remoteStreamsStats ( room ) {
149
+ const peerConnection = room . webrtc . connection ;
138
150
const streams = peerConnection . getRemoteStreams ( ) ;
139
151
140
152
const firefoxTrackActive = peerConnection
0 commit comments