zhangnaisong
2024-01-26 638c705c6a23974ff6aea3229bc297aad0683acc
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
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="libs/adapter.min.js" ></script>
<script src="webrtcconfig.js" ></script>
<script src="webrtcstreamer.js" ></script>
<script>        
    if (location.search.slice(1)) {
        var url = { video:location.search.slice(1) };  
        var options = webrtcConfig.options;
        if (typeof URLSearchParams != 'undefined') {
            var params = new URLSearchParams(location.search);
            if (params.has("video") || params.has("audio")) {
                url = { video:params.get("video"), audio:params.get("audio") };
            }
            if (params.has("options")) {
                options = params.get("options");
            }
        }         
        window.onload         = function() {
            this.webRtcServer = new WebRtcStreamer("video", webrtcConfig.url);
            document.getElementById("title").innerHTML=url.video; 
            webRtcServer.connect(url.video,url.audio,options);
            fetch(webrtcConfig.url + "/api/version").then(r => r.text()).then( (response) => { 
                document.getElementById("footer").innerHTML = "<p><a href='https://github.com/mpromonet/webrtc-streamer'>WebRTC-Streamer</a> " + JSON.parse(response).split(" ")[0] + "</p>";            
            });            
        }
        window.onbeforeunload = function() { this.webRtcServer.disconnect() }
    } else {
        if (typeof URLSearchParams != 'undefined') {
            alert("WebRTC stream name to connect is missing\n\nUsage :" + window.location + "?video=<WebRTC video stream name>&audio=<WebRTC audio stream name>&options=<WebRTC options>")
        } else {
            alert("WebRTC stream name to connect is missing\n\nUsage :" + window.location + "?<WebRTC video stream name>")
        }
    }
</script>
</head>
<body>
  <h2 id="title"></h2>
  <div>
    <video id="video" muted playsinline controls></video>
  </div>
  <footer id="footer"></footer>
</body>
</html>