async componentDidMount() {
        console.log('StreamMedia', this.stream, this.id);
        let renderer = new Renderer(this.stream);
        let view;
        let videoContainer;

        const renderStream = async () => {
            if(!view) {
                view = await renderer.createView();
            }
            videoContainer = document.getElementById(`${this.id}-${this.stream.type}-${this.stream.id}`);
            videoContainer.hidden = false;
            if(!videoContainer.hasChildNodes()) { videoContainer.appendChild(view.target); }
        }

        this.stream.on('availabilityChanged', async () => {
            console.log(`stream=${this.stream.type}, availabilityChanged=${this.stream.isAvailable}`);
            if (this.stream.isAvailable) {
                this.setState({ isAvailable: true });
                await renderStream();
            } else {
                if(videoContainer) { videoContainer.hidden = true; }
                this.setState({ isAvailable: false });
            }
        });

        if (this.stream.isAvailable) {
            this.setState({ isAvailable: true });
            await renderStream();
        }
    }
/**
     * Start stream after DOM has rendered
     */
Start stream after DOM has rendered
Start stream after DOM has rendered
async componentDidMount() {
        console.log('StreamMedia', this.stream, this.id);
        let renderer = new Renderer(this.stream);
        let view;
        let videoContainer;
        const renderStream = async () => {
            if(!view) {
                view = await renderer.createView();
            }
            videoContainer = document.getElementById(`${this.id}-${this.stream.type}-${this.stream.id}`);
            videoContainer.hidden = false;
            if(!videoContainer.hasChildNodes()) { videoContainer.appendChild(view.target); }
        }
        this.stream.on('availabilityChanged', async () => {
            console.log(`stream=${this.stream.type}, availabilityChanged=${this.stream.isAvailable}`);
            if (this.stream.isAvailable) {
                this.setState({ isAvailable: true });
                await renderStream();
            } else {
                if(videoContainer) { videoContainer.hidden = true; }
                this.setState({ isAvailable: false });
            }
        });
        if (this.stream.isAvailable) {
            this.setState({ isAvailable: true });
            await renderStream();
        }
    }
async componentDidMount ( ) { console . log ( 'StreamMedia' , this . stream , this . id ) ; let renderer = new Renderer ( this . stream ) ; let view ; let videoContainer ; const renderStream = async ( ) => { if ( ! view ) { view = await renderer . createView ( ) ; } videoContainer = document . getElementById ( ` ${ this . id } ${ this . stream . type } ${ this . stream . id } ` ) ; videoContainer . hidden = false ; if ( ! videoContainer . hasChildNodes ( ) ) { videoContainer . appendChild ( view . target ) ; } } this . stream . on ( 'availabilityChanged' , async ( ) => { console . log ( ` ${ this . stream . type } ${ this . stream . isAvailable } ` ) ; if ( this . stream . isAvailable ) { this . setState ( { isAvailable : true } ) ; await renderStream ( ) ; } else { if ( videoContainer ) { videoContainer . hidden = true ; } this . setState ( { isAvailable : false } ) ; } } ) ; if ( this . stream . isAvailable ) { this . setState ( { isAvailable : true } ) ; await renderStream ( ) ; } }
Start stream after DOM has rendered
Start stream after DOM has rendered