<reponame>jackitaliano/Make23<filename>NotesApp/frontend/node_modules/subscribable-things/build/es2019/factories/media-devices.js<gh_stars>0export const createMediaDevices = (emitNotSupportedError, window, wrapSubscribeFunction) => {
    return () => wrapSubscribeFunction((observer) => {
        if (window === null ||
            window.navigator === undefined ||
            window.navigator.mediaDevices === undefined ||
            window.navigator.mediaDevices.enumerateDevices === undefined) {
            return emitNotSupportedError(observer);
        }
        let isActive = true;
        const enumerateDevices = () => {
            window.navigator.mediaDevices.enumerateDevices().then((mediaDevices) => {
                if (isActive) {
                    observer.next(mediaDevices);
                }
            }, (err) => {
                if (isActive) {
                    unsubscribe();
                    observer.error(err);
                }
            });
        };
        const unsubscribe = () => {
            isActive = false;
            window.navigator.mediaDevices.removeEventListener('devicechange', enumerateDevices);
        };
        enumerateDevices();
        window.navigator.mediaDevices.addEventListener('devicechange', enumerateDevices);
        return unsubscribe;
    });
};
//# sourceMappingURL=media-devices.js.map