@@ -176,7 +176,7 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
176176
177177 abstract createSuccessListener ( ) : any ;
178178
179- runDetector ( image : UIImage ) {
179+ runDetector ( image : UIImage , onComplete : ( ) => void ) {
180180 throw new Error ( "No custom detector implemented, so 'runDetector' can't do its thing" ) ;
181181 }
182182}
@@ -190,6 +190,8 @@ class TNSMLKitCameraViewDelegateImpl extends NSObject implements TNSMLKitCameraV
190190 private detector : any ;
191191 private onSuccessListener : any ;
192192
193+ private detectorBusy = false ;
194+
193195 public static createWithOwnerResultCallbackAndOptions ( owner : WeakRef < MLKitCameraView > , callback : ( message : any ) => void , options ?: any ) : TNSMLKitCameraViewDelegateImpl {
194196 // defer initialisation because the framework may not be available / used
195197 if ( TNSMLKitCameraViewDelegateImpl . ObjCProtocols . length === 0 && typeof ( TNSMLKitCameraViewDelegate ) !== "undefined" ) {
@@ -205,14 +207,30 @@ class TNSMLKitCameraViewDelegateImpl extends NSObject implements TNSMLKitCameraV
205207 }
206208
207209 cameraDidOutputImage ( image : UIImage ) : void {
208- if ( image ) {
209- if ( this . detector . detectInImageCompletion ) {
210- this . detector . detectInImageCompletion ( this . uiImageToFIRVisionImage ( image ) , this . onSuccessListener ) ;
211- } else if ( this . detector . processImageCompletion ) {
212- this . detector . processImageCompletion ( this . uiImageToFIRVisionImage ( image ) , this . onSuccessListener ) ;
213- } else {
214- this . owner . get ( ) . runDetector ( image ) ;
215- }
210+ if ( ! image || this . detectorBusy ) {
211+ return ;
212+ }
213+
214+ this . detectorBusy = true ;
215+
216+ const onComplete = ( ) => {
217+ this . detectorBusy = false ;
218+ } ;
219+
220+ if ( this . detector . detectInImageCompletion ) {
221+ this . detector . detectInImageCompletion ( this . uiImageToFIRVisionImage ( image ) , ( result , error ) => {
222+ this . onSuccessListener ( result , error ) ;
223+ onComplete ( ) ;
224+ } ) ;
225+
226+ } else if ( this . detector . processImageCompletion ) {
227+ this . detector . processImageCompletion ( this . uiImageToFIRVisionImage ( image ) , ( result , error ) => {
228+ this . onSuccessListener ( result , error ) ;
229+ onComplete ( ) ;
230+ } ) ;
231+
232+ } else {
233+ this . owner . get ( ) . runDetector ( image , onComplete ) ;
216234 }
217235 }
218236
0 commit comments