2021-02-19 20:41:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								package  com.mrousavy.camera  
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  android.Manifest  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  android.content.pm.PackageManager  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  android.util.Log  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  androidx.core.content.ContextCompat  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  com.facebook.react.bridge.*  
						 
					
						
							
								
									
										
										
										
											2022-01-02 10:02:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.facebook.react.module.annotations.ReactModule  
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  com.facebook.react.modules.core.PermissionAwareActivity  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  com.facebook.react.modules.core.PermissionListener  
						 
					
						
							
								
									
										
										
										
											2022-07-20 09:02:20 -03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.facebook.react.uimanager.UIManagerHelper  
						 
					
						
							
								
									
										
										
										
											2023-10-13 18:33:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.mrousavy.camera.core.CameraError  
						 
					
						
							
								
									
										
										
										
											2024-01-30 14:26:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.mrousavy.camera.core.CameraQueues  
						 
					
						
							
								
									
										
										
										
											2023-10-13 18:33:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.mrousavy.camera.core.ViewNotFoundError  
						 
					
						
							
								
									
										
										
										
											2023-07-22 00:15:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.mrousavy.camera.frameprocessor.VisionCameraInstaller  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  com.mrousavy.camera.frameprocessor.VisionCameraProxy  
						 
					
						
							
								
									
										
										
										
											2023-10-17 11:49:04 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.mrousavy.camera.types.*  
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  com.mrousavy.camera.utils.*  
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  kotlin.coroutines.resume  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  kotlin.coroutines.resumeWithException  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  kotlin.coroutines.suspendCoroutine  
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  kotlinx.coroutines.*  
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-02 10:02:17 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@ReactModule ( name  =  CameraViewModule . TAG )  
						 
					
						
							
								
									
										
										
										
											2021-08-25 11:33:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@Suppress ( " unused " )  
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  CameraViewModule ( reactContext :  ReactApplicationContext )  :  ReactContextBaseJavaModule ( reactContext )  {  
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  companion  object  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-07-07 15:00:32 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  val  TAG  =  " CameraView " 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    var  sharedRequestCode  =  10 
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 14:17:32 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    init  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Load the native part of VisionCamera.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // Includes the OpenGL VideoPipeline, as well as Frame Processor JSI bindings
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        System . loadLibrary ( " VisionCamera " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }  catch  ( e :  UnsatisfiedLinkError )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Log . e ( VisionCameraProxy . TAG ,  " Failed to load VisionCamera C++ library! " ,  e ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        throw  e 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-01-30 14:26:55 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  private  val  coroutineScope  =  CoroutineScope ( CameraQueues . cameraQueue . coroutineDispatcher ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-27 12:37:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-22 00:15:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  override  fun  invalidate ( )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    super . invalidate ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-25 11:33:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  ( coroutineScope . isActive )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      coroutineScope . cancel ( " CameraViewModule has been destroyed. " ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-27 12:37:54 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  override  fun  getName ( ) :  String  =  TAG 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  private  suspend  fun  findCameraView ( viewId :  Int ) :  CameraView  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    suspendCoroutine  {  continuation  -> 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      UiThreadUtil . runOnUiThread  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Log . d ( TAG ,  " Finding view  $viewId ... " ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        val  view  =  if  ( reactApplicationContext  !=  null )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          UIManagerHelper . getUIManager ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            reactApplicationContext , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            viewId 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          ) ?. resolveView ( viewId )  as  CameraView ? 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          null 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Log . d ( TAG ,  if  ( reactApplicationContext  !=  null )  " Found view  $viewId ! "  else  " Couldn't find view  $viewId ! " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( view  !=  null )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          continuation . resume ( view ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          continuation . resumeWithException ( ViewNotFoundError ( viewId ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-07-22 00:15:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @ReactMethod ( isBlockingSynchronousMethod  =  true ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  fun  installFrameProcessorBindings ( ) :  Boolean  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    try  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  proxy  =  VisionCameraProxy ( reactApplicationContext ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-07-22 00:15:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      VisionCameraInstaller . install ( proxy ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      true 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  catch  ( e :  Error )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      Log . e ( TAG ,  " Failed to install Frame Processor JSI Bindings! " ,  e ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  takePhoto ( viewTag :  Int ,  options :  ReadableMap ,  promise :  Promise )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-25 11:33:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    coroutineScope . launch  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  view  =  findCameraView ( viewTag ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      withPromise ( promise )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        view . takePhoto ( options ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // TODO: startRecording() cannot be awaited, because I can't have a Promise and a onRecordedCallback in the same function. Hopefully TurboModules allows that
 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-07 13:08:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-11 22:42:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  fun  startRecording ( viewTag :  Int ,  jsOptions :  ReadableMap ,  filePath :  String ,  onRecordCallback :  Callback )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-25 11:33:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    coroutineScope . launch  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  view  =  findCameraView ( viewTag ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-07 13:08:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      try  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-11-27 17:20:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        val  options  =  RecordVideoOptions ( jsOptions ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-11 22:42:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        view . startRecording ( options ,  filePath ,  onRecordCallback ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-07 13:08:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      }  catch  ( error :  CameraError )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        val  map  =  makeErrorMap ( " ${error.domain} / ${error.id} " ,  error . message ,  error ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        onRecordCallback ( null ,  map ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }  catch  ( error :  Throwable )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        val  map  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          makeErrorMap ( " capture/unknown " ,  " An unknown error occurred while trying to start a video recording!  ${error.message} " ,  error ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-07 13:08:40 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        onRecordCallback ( null ,  map ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-03-22 10:44:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  pauseRecording ( viewTag :  Int ,  promise :  Promise )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    coroutineScope . launch  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      withPromise ( promise )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        val  view  =  findCameraView ( viewTag ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        view . pauseRecording ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return @withPromise  null 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-22 10:44:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  resumeRecording ( viewTag :  Int ,  promise :  Promise )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    coroutineScope . launch  { 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-22 10:44:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  view  =  findCameraView ( viewTag ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      withPromise ( promise )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        view . resumeRecording ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return @withPromise  null 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
									
										
										
										
											2022-03-22 10:44:58 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  stopRecording ( viewTag :  Int ,  promise :  Promise )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    coroutineScope . launch  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  view  =  findCameraView ( viewTag ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      withPromise ( promise )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        view . stopRecording ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return @withPromise  null 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  focus ( viewTag :  Int ,  point :  ReadableMap ,  promise :  Promise )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-25 11:33:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    coroutineScope . launch  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  view  =  findCameraView ( viewTag ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      withPromise ( promise )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        view . focus ( point ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return @withPromise  null 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  private  fun  canRequestPermission ( permission :  String ) :  Boolean  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    val  activity  =  currentActivity  as ?  PermissionAwareActivity 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  activity ?. shouldShowRequestPermissionRationale ( permission )  ?:  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 14:22:04 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @ReactMethod ( isBlockingSynchronousMethod  =  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  getCameraPermissionStatus ( ) :  String  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    val  status  =  ContextCompat . checkSelfPermission ( reactApplicationContext ,  Manifest . permission . CAMERA ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    var  parsed  =  PermissionStatus . fromPermissionStatus ( status ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( parsed  ==  PermissionStatus . DENIED  &&  canRequestPermission ( Manifest . permission . CAMERA ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      parsed  =  PermissionStatus . NOT _DETERMINED 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 14:22:04 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  parsed . unionValue 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 14:22:04 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  @ReactMethod ( isBlockingSynchronousMethod  =  true ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  getMicrophonePermissionStatus ( ) :  String  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    val  status  =  ContextCompat . checkSelfPermission ( reactApplicationContext ,  Manifest . permission . RECORD _AUDIO ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    var  parsed  =  PermissionStatus . fromPermissionStatus ( status ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( parsed  ==  PermissionStatus . DENIED  &&  canRequestPermission ( Manifest . permission . RECORD _AUDIO ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      parsed  =  PermissionStatus . NOT _DETERMINED 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2023-12-19 14:22:04 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  parsed . unionValue 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  requestCameraPermission ( promise :  Promise )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    val  activity  =  reactApplicationContext . currentActivity 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( activity  is  PermissionAwareActivity )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  currentRequestCode  =  sharedRequestCode ++ 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  listener  =  PermissionListener  {  requestCode :  Int ,  _ :  Array < String > ,  grantResults :  IntArray  -> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( requestCode  ==  currentRequestCode )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-26 15:39:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          val  permissionStatus  =  if  ( grantResults . isNotEmpty ( ) )  grantResults [ 0 ]  else  PackageManager . PERMISSION _DENIED 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          val  parsed  =  PermissionStatus . fromPermissionStatus ( permissionStatus ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          promise . resolve ( parsed . unionValue ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          return @PermissionListener  true 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return @PermissionListener  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      activity . requestPermissions ( arrayOf ( Manifest . permission . CAMERA ) ,  currentRequestCode ,  listener ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      promise . reject ( " NO_ACTIVITY " ,  " No PermissionAwareActivity was found! Make sure the app has launched before calling this function. " ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  @ReactMethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  fun  requestMicrophonePermission ( promise :  Promise )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    val  activity  =  reactApplicationContext . currentActivity 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( activity  is  PermissionAwareActivity )  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-09-21 11:20:33 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  currentRequestCode  =  sharedRequestCode ++ 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      val  listener  =  PermissionListener  {  requestCode :  Int ,  _ :  Array < String > ,  grantResults :  IntArray  -> 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( requestCode  ==  currentRequestCode )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-26 15:39:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          val  permissionStatus  =  if  ( grantResults . isNotEmpty ( ) )  grantResults [ 0 ]  else  PackageManager . PERMISSION _DENIED 
							 
						 
					
						
							
								
									
										
										
										
											2023-08-21 12:50:14 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          val  parsed  =  PermissionStatus . fromPermissionStatus ( permissionStatus ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          promise . resolve ( parsed . unionValue ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								          return @PermissionListener  true 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return @PermissionListener  false 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      activity . requestPermissions ( arrayOf ( Manifest . permission . RECORD _AUDIO ) ,  currentRequestCode ,  listener ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      promise . reject ( " NO_ACTIVITY " ,  " No PermissionAwareActivity was found! Make sure the app has launched before calling this function. " ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-26 10:56:20 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
									
										
										
										
											2021-02-19 16:28:14 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}