github.com/pion/webrtc/v4@v4.0.1/e2e/test.html (about) 1 <!-- 2 SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 3 SPDX-License-Identifier: MIT 4 --> 5 <div id="media"></div> 6 7 <script> 8 const pc = new RTCPeerConnection() 9 pc.ontrack = event => { 10 if (event.track.kind === 'audio') { 11 var el = document.createElement(event.track.kind) 12 el.srcObject = new MediaStream(event.streams[0].getAudioTracks()) 13 document.getElementById('media').appendChild(el) 14 } 15 } 16 pc.oniceconnectionstatechange = event => { 17 console.log("connection", pc.iceConnectionState) 18 if (pc.iceConnectionState == 'connected') { 19 setInterval(statsReport, 1000) 20 } 21 } 22 pc.onicecandidate = event => { 23 if (event.candidate === null) { 24 console.log("sdp", JSON.stringify(pc.localDescription)) 25 } 26 } 27 pc.addTransceiver('audio', {'direction': 'recvonly'}) 28 29 const dc = pc.createDataChannel("upper") 30 dc.onmessage = event => { 31 dc.send(event.data.toUpperCase()) 32 } 33 34 pc.createOffer().then(d => pc.setLocalDescription(d)).catch(console.log) 35 36 const statsReport = async () => { 37 const stats = await pc.getStats() 38 var data = [] 39 await stats.forEach(item => { 40 data.push(item) 41 }) 42 console.log("stats", JSON.stringify(data)) 43 } 44 45 </script>