forked from Sean-Der/rtmp-to-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
40 lines (36 loc) · 973 Bytes
/
index.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
<html>
<head>
<title> RTMP to WebRTC </title>
</head>
<body>
<h1> RTMP to WebRTC </h1>
<div id="rtmpFeed"></div>
</body>
<script>
let pc = new RTCPeerConnection()
pc.ontrack = function (event) {
var el = document.createElement(event.track.kind)
el.srcObject = event.streams[0]
el.autoplay = true
el.controls = true
document.getElementById('rtmpFeed').appendChild(el)
}
pc.addTransceiver('video')
pc.addTransceiver('audio')
pc.createOffer()
.then(offer => {
pc.setLocalDescription(offer)
return fetch(`/createPeerConnection`, {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(offer)
})
})
.then(res => res.json())
.then(res => pc.setRemoteDescription(res))
.catch(alert)
</script>
</html>