-
Notifications
You must be signed in to change notification settings - Fork 1
/
hellocaller.html
34 lines (32 loc) · 1.32 KB
/
hellocaller.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
<head></head>
<body>
<div style="vertical-align: top;">
<div><video id="video" autoplay playsinline></video></div>
<div><button id="button">Answer</button></div>
</div>
<div style="display: inline-block; vertical-align: top;">
<div><textarea id="offer" cols="80" rows="24"></textarea></div>
</div>
<div style="display: inline-block; vertical-align: top;">
<div><textarea id="answer" cols="80" rows="24"></textarea></div>
</div>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script>
document.querySelector("#button").addEventListener("click", e => {
const pc = window.pc = new RTCPeerConnection();
pc.ontrack = event => {
const video = document.querySelector("#video");
video.srcObject = event.streams[0];
};
pc.onicecandidate = event => {
if (!event.candidate) {
document.querySelector("#answer")
.value = pc.localDescription.sdp;
}
};
const offer = document.querySelector("#offer").value;
pc.setRemoteDescription({ type: "offer", sdp: offer });
pc.createAnswer().then(answer => pc.setLocalDescription(answer));
});
</script>
</body>