Bug 192601 - RTCPeerConnection#getStats returns RTCStatsReport which is very different from the spec.
Summary: RTCPeerConnection#getStats returns RTCStatsReport which is very different fro...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 12
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-12-11 12:34 PST by syerrapragada
Modified: 2022-08-26 03:16 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description syerrapragada 2018-12-11 12:34:09 PST
Spec: https://www.w3.org/TR/webrtc-stats/

RTCPeerConnection#getStats is not according to the spec above.

  1. RTCPeerConnection#getStats does not honor selector argument
  2. Cannot correlate remote tracks in stats report.
  3. StatsReport does not have local-candidate stats type.
  4. StatsReport does not have remote-candidate stats type.
  5. StatsReport does not have codec stats type.

This following fiddle should help reproduce the issues mentioned above.
https://jsfiddle.net/o6fc03uw/1/

Code in fiddle:
(async () => {
      const pc1 = new RTCPeerConnection()
      const pc2 = new RTCPeerConnection()

      const stream1 = await navigator.mediaDevices.getUserMedia({ audio: true })
      const stream2 = await navigator.mediaDevices.getUserMedia({ audio: true })
      const [track1] = stream1.getAudioTracks()
      const [track2] = stream2.getAudioTracks()

      pc2.addTrack(track1, stream1)
      pc2.addTrack(track2, stream2)

      pc1.addTransceiver('audio')
      pc1.addTransceiver('audio')

      const offer = await pc1.createOffer()
      await Promise.all([
        pc1.setLocalDescription(offer),
        pc2.setRemoteDescription(offer)
      ])

      const answer = await pc2.createAnswer()
      await Promise.all([
        pc1.setRemoteDescription(answer),
        pc2.setLocalDescription(answer)
      ])
      
      const recvrs = pc1.getReceivers()
      const statsReport = await pc1.getStats(recvrs[0].track)
    	const tracksInReport = Array.from(statsReport.values()).filter(stat => stat.type === 'track');
      
      if (tracksInReport.length > 1) {
      	console.warn('More than 1 track in stats report.' +
        	'RTCPeerConnection#getStats does not honor selector argument.');
        var remoteTrackStats = tracksInReport.find(
        	stat => stat.trackIdentifier === recvrs[0].track.id)
          
        if (!remoteTrackStats) {
        	console.warn('Cannot correlate remote tracks in stats report.');
        }
      }
			
      var localCandidateStats = Array.from(statsReport.values()).find(
      	stat => stat.type === 'local-candidate');
      if (!localCandidateStats) {
      	console.warn('StatsReport does not have local-Candidate stats type.');
      }
      
      var remoteCandidateStats = Array.from(statsReport.values()).find(
      	stat => stat.type === 'remote-candidate');
      if (!remoteCandidateStats) {
      	console.warn('StatsReport does not have remote-candidate stats type.');
      }
      
      var codecStats = Array.from(statsReport.values()).find(
      	stat => stat.type === 'codec');
      if (!codecStats) {
      	console.warn('StatsReport does not have codec stats type.');
      }
 				 
    })()
Comment 1 Radar WebKit Bug Importer 2022-06-30 16:44:11 PDT
<rdar://problem/96254880>
Comment 2 709922234 2022-08-26 03:16:16 PDT
[`RTCAudioSourceStats.audioLevel`](1) is very important for me, can display the volume of input audio.

[1]: https://www.w3.org/TR/webrtc-stats/#dom-rtcaudiosourcestats