Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shadow dom support without removing the video element inside shadow dom #264

Open
Switcherfaiz opened this issue Dec 9, 2024 · 0 comments

Comments

@Switcherfaiz
Copy link

It removes my video element inside shadow dom and append it to the body tag,make it update the video tag inside shadow dom without disrupting my shadow dom sructure

import QrScanner from '/qr-scanner/qr-scanner.min.js';

class scanningWindow extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
this.render();
}

scanningFunctionality() {
    const video = this.shadowRoot.querySelector('#camera');
    if (!video) {
        console.error('Video element not found in Shadow DOM');
        return;
    }

    // Set the WORKER_PATH if required
    QrScanner.WORKER_PATH = '/qr-scanner/qr-scanner-worker.min.js';

    // Create a QR Scanner instance
    const qrScanner = new QrScanner(video, (result) => {
        console.log('QR Code Content:', result);
        alert(`QR Code Scanned: ${result}`);
    });

    // Start the scanner
    qrScanner.start();
}

render() {
    this.shadowRoot.innerHTML = `
    ${this.styleSheet()}
    <!-- Video Element for Camera Stream -->
    <video id="camera"></video>
    `;
}

connectedCallback() {
    this.scanningFunctionality();
}

styleSheet() {
    return (`
    <style>
        :host {
            display: block;
            height: 100%;
            width: 100%;
        }
        #camera {
            width: 100%;
            height: 100%;
            border: 1px solid black;
        }
    </style>
    `);
}

}

customElements.define('scanning-window',scanningWindow);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant