mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2026-04-22 23:57:20 +08:00
Initial commit
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user