Jonjon Candare
Jonjon Candare

Reputation: 49

QR Code is not working on server but working on localhost

Why it is working on localhost

and it is not working on my server im using my public ip

static getCameras() {
    return new Promise((resolve, reject) => {
        // Check if necessary media-related features are supported by the browser.
        if (
            navigator.mediaDevices &&
            navigator.mediaDevices.enumerateDevices &&
            navigator.mediaDevices.getUserMedia
        ) {
            this._log("navigator.mediaDevices used");

            // Use getUserMedia to access the camera.
            navigator.mediaDevices.getUserMedia({ audio: false, video: true })
                .then(stream => {
                    // Hacky approach to close any active stream if they are active.
                    stream.oninactive = _ => this._log("All streams closed");

                    const closeActiveStreams = stream => {
                        const tracks = stream.getVideoTracks();

                        // Disable and stop each track in the stream.
                        for (var i = 0; i < tracks.length; i++) {
                            const track = tracks[i];
                            track.enabled = false;
                            track.stop();
                            stream.removeTrack(track);
                        }
                    }

                    // Enumerate available devices to find video input devices.
                    navigator.mediaDevices.enumerateDevices()
                        .then(devices => {
                            const results = [];
                            for (var i = 0; i < devices.length; i++) {
                                const device = devices[i];
                                if (device.kind == "videoinput") {
                                    results.push({
                                        id: device.deviceId,
                                        label: device.label
                                    });
                                }
                            }
                            this._log(`${results.length} results found`);
                            closeActiveStreams(stream);
                            resolve(results);
                        })
                        .catch(err => {
                            reject(`${err.name} : ${err.message}`);
                        });
                })
                .catch(err => {
                    reject(`${err.name} : ${err.message}`);
                });
        } else if (MediaStreamTrack && MediaStreamTrack.getSources) {
            // Use MediaStreamTrack.getSources as an alternative method for older browsers.
            this._log("MediaStreamTrack.getSources used");

            const callback = sourceInfos => {
                const results = [];
                for (var i = 0; i !== sourceInfos.length; ++i) {
                    const sourceInfo = sourceInfos[i];
                    if (sourceInfo.kind === 'video') {
                        results.push({
                            id: sourceInfo.id,
                            label: sourceInfo.label
                        });
                    }
                }
                this._log(`${results.length} results found`);
                resolve(results);
            }

            // Invoke MediaStreamTrack.getSources to obtain video sources.
            MediaStreamTrack.getSources(callback);
        } else {
            // If neither method is supported, log an error and reject the Promise.
            this._log("unable to query supported devices.");
            reject("unable to query supported devices.");
        }
    });
    }

i actually dont know how to fix this is there anything i need to change here to work on my server or my server is the one that is need to be fix Thank you if anyone can help me with this problem [1]: https://i.sstatic.net/2LSu1.png [2]: https://i.sstatic.net/e0wZi.png

Upvotes: 0

Views: 255

Answers (0)

Related Questions