react-native-vision-camera/package/src/CameraDevices.ts
Marc Rousavy 14721d314f
chore: Remove semicolons (#1846)
* chore: Disable `semi` in Prettier

* chore: Format w/o semi

* Remove more `;`

* Lint example

* More ;
2023-09-26 11:39:17 +02:00

28 lines
1007 B
TypeScript

import { NativeModules, NativeEventEmitter } from 'react-native'
import { CameraDevice } from './CameraDevice'
const CameraDevicesManager = NativeModules.CameraDevices as {
getConstants: () => {
availableCameraDevices: CameraDevice[]
userPreferredCameraDevice: CameraDevice | undefined
}
}
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 = {
userPreferredCameraDevice: constants.userPreferredCameraDevice,
getAvailableCameraDevices: () => devices,
addCameraDevicesChangedListener: (callback: (newDevices: CameraDevice[]) => void) => {
return eventEmitter.addListener(DEVICES_CHANGED_NAME, callback)
},
}