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