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
 
 
class WebRTCStreamerFooterElement extends HTMLElement {    
    constructor() {
        super(); 
        this.shadowDOM = this.attachShadow({mode: 'open'});
        this.shadowDOM.innerHTML = `
                    <style>@import "styles.css"</style>
                    <footer id="footer"></footer>
                    `;
    }
 
    static get observedAttributes() {
        return ['webrtcurl'];
    }  
 
    attributeChangedCallback(attrName, oldVal, newVal) {
        if (attrName === "webrtcurl") {
            this.fillFooter();
        }
    }
 
    connectedCallback() {
        this.fillFooter();
    }
 
    fillFooter() {
        let footerElement = this.shadowDOM.getElementById("footer");
        const webrtcurl = this.getAttribute("webrtcurl") || "";
        fetch(webrtcurl + "/api/version").then(r => r.text()).then( function (response) { 
            footerElement.innerHTML = "<p><a href='https://github.com/mpromonet/webrtc-streamer'>WebRTC-Streamer</a> " + response.split(" ")[0] + "</p>";            
        });    
    
    }
 
}
 
customElements.define('webrtc-streamer-footer', WebRTCStreamerFooterElement);