‘liusuyi’
2023-07-27 e279e456850734349842edd8ce52dc16fc5cdea7
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
46
47
48
49
50
51
52
 
 
class WebRTCStreamerAlgoElement extends HTMLElement {    
    static get observedAttributes() {
        return ['selected'];
    }      
    constructor() {
        super(); 
        this.shadowDOM = this.attachShadow({mode: 'open'});
        this.shadowDOM.innerHTML = `
                    <style>@import "styles.css"</style>
                    <h2>
                        <select id="algoList">
                            <option value="none">none</option>
                            <option value="cocossd">cocossd</option>
                            <option value="posenet">posenet</option>
                            <option value="deeplab">deeplab</option>
                            <option value="bodyPix">bodyPix</option>
                            <option value="blazeface">blazeface</option>
                        </select>
                    </h2>
                    `;
    }
    connectedCallback() {
        this.fillList();
    }
    
    attributeChangedCallback(attrName, oldVal, newVal) {
        if (attrName === "selected") {
            this.selected = newVal;
            let mediaList = this.shadowDOM.getElementById("algoList");
            for (const option of mediaList.getElementsByTagName('option')) {
                if (option.value === newVal) {
                    option.selected = true;
                }
            }
        }
    }    
 
    fillList() {
        let algoList = this.shadowDOM.getElementById("algoList");
        algoList.onchange = (event) => {
                this.dispatchEvent(new CustomEvent('change', {
                    detail: {
                        algo: algoList.selectedOptions[0].value,
                    }
                  }));        
            }
    }
}
 
customElements.define('webrtc-streamer-algo', WebRTCStreamerAlgoElement);