aijinhui
2023-10-24 8a87e4226aa802d6a0e3566c66824fedf68e77da
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
<html>
<head>
    <link rel="icon" type="image/png" href="webrtc.png" />
    <style>
        h2 {
            margin: 0 auto;
            text-align: center; 
        }
    </style>
    <script type="module" src="webrtc-streamer-element.js"></script>
    <script type="module" src="webrtc-streamer-footer-element.js"></script>
</head>
<body>
    <h2 id="message"></h2>
    <webrtc-streamer id="stream" options="rtptransport=tcp&timeout=60&width=0&height=0&bitrate=0&rotation=0" style="display:none"></webrtc-streamer>
    <webrtc-streamer-footer></webrtc-streamer-footer>
    <script>     
        let messageElement = document.getElementById("message"); 
        customElements.whenDefined('webrtc-streamer').then(() => {
            let streamElement = document.getElementById("stream");
 
            var params = new URLSearchParams(location.search);
            if (params.has("options")) {
                streamElement.setAttribute('options', params.get("options"));
            }
            if (params.has("video") || params.has("audio")) {
                let url = { video:params.get("video"), audio:params.get("audio") };
                streamElement.setAttribute('url', JSON.stringify(url));
                streamElement.style.display = "block"
            } else {
                messageElement.innerHTML = "url should contains video or audio"
            }
        }).catch( (e) => {
            messageElement.innerText = "webrtc-streamer webcomponent fails to initialize error:" + e
        })
    </script>
</body>
</html>