14721d314f
* chore: Disable `semi` in Prettier * chore: Format w/o semi * Remove more `;` * Lint example * More ;
28 lines
1007 B
TypeScript
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)
|
|
},
|
|
}
|