JSFiddle - React, Tailwind, and code Playground

by fippo

JavaScript

const pc = new RTCPeerConnection();
pc.createDataChannel('getStats');
pc.setLocalDescription().then(async () => {
  const stats = await pc.getStats(); 
  console.log([...stats.values()].map(report => report.type));
  console.log([...stats.values()].filter(report => report.type === 'data-channel'));
  console.log([...stats.values()].find(report => report.type === 'data-channel').dataChannelIdentifier);
  // ["media-playout", "certificate", "outbound-rtp", "outbound-rtp", "peer-connection", "transport", "transport"]
  // second transport will typically be thrown away when bundle is negotiated.
  
  // cheap way to get a remote offer without using a second peerconnection.
  await pc.setRemoteDescription(pc.localDescription);
  await pc.setLocalDescription();
  const newStats = await pc.getStats(); 
  console.log([...newStats.values()].map(report => report.type), pc.signalingState);
  console.log([...newStats.values()].filter(report => report.type === 'data-channel'));
  console.log([...newStats.values()].find(report => report.type === 'data-channel').dataChannelIdentifier);
  console.log('SCTP?', pc.sctp);
})