Initial commit

This commit is contained in:
Alexey Khit
2022-08-18 09:19:00 +03:00
commit 3e77835583
65 changed files with 6372 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>go2rtc - WebRTC</title>
<style>
body {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
width: 100%;
}
#video {
/* video "container" size */
width: 100%;
height: 100%;
background: black;
}
</style>
</head>
<body>
<!-- muted is important for autoplay -->
<video id="video" autoplay controls playsinline muted></video>
<script>
// support api_path
let baseUrl = location.origin + location.pathname.substr(
0, location.pathname.lastIndexOf("/")
);
let pc = new RTCPeerConnection({
iceServers: [{urls: 'stun:stun.l.google.com:19302'}]
});
pc.onicegatheringstatechange = async () => {
if (pc.iceGatheringState !== 'complete') return;
let r = await fetch(`${baseUrl}/api/webrtc${location.search}`, {
method: 'POST', body: pc.localDescription.sdp,
});
await pc.setRemoteDescription({
type: 'answer', sdp: await r.text()
});
}
pc.ontrack = ev => {
let video = document.getElementById('video');
if (video.srcObject === null) {
video.srcObject = ev.streams[0];
}
}
pc.addTransceiver('video');
pc.addTransceiver('audio');
pc.createOffer({
offerToReceiveVideo: true, offerToReceiveAudio: true
}).then(offer => {
pc.setLocalDescription(offer);
});
</script>
</body>
</html>