2023-09-21 03:20:33 -06:00
|
|
|
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
|
|
import { CameraDevice } from './CameraDevice';
|
|
|
|
|
|
|
|
const CameraDevicesManager = NativeModules.CameraDevices as {
|
|
|
|
getConstants: () => {
|
|
|
|
availableCameraDevices: CameraDevice[];
|
2023-09-21 08:29:46 -06:00
|
|
|
userPreferredCameraDevice: CameraDevice | undefined;
|
2023-09-21 03:20:33 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const constants = CameraDevicesManager.getConstants();
|
|
|
|
let devices = constants.availableCameraDevices;
|
|
|
|
|
|
|
|
const DEVICES_CHANGED_NAME = 'CameraDevicesChanged';
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
const eventEmitter = new NativeEventEmitter(CameraDevicesManager as any);
|
|
|
|
eventEmitter.addListener(DEVICES_CHANGED_NAME, (newDevices: CameraDevice[]) => {
|
|
|
|
devices = newDevices;
|
|
|
|
});
|
|
|
|
|
|
|
|
export const CameraDevices = {
|
2023-09-21 08:29:46 -06:00
|
|
|
userPreferredCameraDevice: constants.userPreferredCameraDevice,
|
2023-09-21 03:20:33 -06:00
|
|
|
getAvailableCameraDevices: () => devices,
|
|
|
|
addCameraDevicesChangedListener: (callback: (newDevices: CameraDevice[]) => void) => {
|
|
|
|
return eventEmitter.addListener(DEVICES_CHANGED_NAME, callback);
|
|
|
|
},
|
|
|
|
};
|