ngx-scanner
ngx-scanner copied to clipboard
Missing error propagation and handling
Hi, i find some errors in this package. There is scanError output but it is never emited. Try to emit errors through it.
- When corrupted camera is selected there is no error and video is stucked in "loading" or "initializing" state.
- When camera is disconnected, there is only warning noted in https://github.com/zxing-js/ngx-scanner/issues/248 (It was not possible to play video). Video is black, what is fine but i want to know that camera was disconnected.
- When i have at least 2 cameras and selected CameraA is disconnect, user swap to CameraB (which work fine). Next swap back to CameraA throw OverconstrainedError, it destroy angular changeDetection and only manual call of detectChanges update template.
- Sometimes when this errors happens, after page reload correct working camera is stucked and opened by application (in another thread or not correctly closed). Then error NotReadableError https://github.com/zxing-js/ngx-scanner/issues/241 happens and reload of page doesnt fix it. Only browser reopen.
- scanFail is emitted always onInit, when is camera corrupted, video is not loaded, connection to camera was no created, camera work, etc. it always emit at least one event. It should emit event only when camera work and doesnt scan code, or?
I was having similar problems, at least in that a lot of errors from the MediaDevices API are thrown inside async methods used in Promise chains without a catch. One example:
In continuousDecodeFromInputVideoDevice:, there's no .catch, but getStreamForDevice calls getUserMedia which can throw (e.g. if camera is in use or 100 other fun things). Something like .catch(err => scan$.error(err)) At the end of the chain would wrap the error nicely and hand it to the user via scanError.
I have the same error after use the scan twice:

07-30 16:02:02.871 D/ViewRootImpl@ebba680MainActivity: ViewPostIme pointer 0
07-30 16:02:02.934 D/ViewRootImpl@ebba680MainActivity: ViewPostIme pointer 1
07-30 16:02:02.950 D/InputMethodManager(25136): HSIFW - flag : 0 Pid : 25136
07-30 16:02:03.129 D/InputMethodManager(25136): HSIFW - flag : 0 Pid : 25136
07-30 16:02:03.161 D/SensorManager(25136): registerListener :: 20, Game Rotation Vector Non-wakeup, 16666, 0,
[INFO:CONSOLE(95)] "ZXing code reader initialized", source: https://www.XXXXX.com.ar/Pendientes/Create2 (95)
07-30 16:02:03.172 I/chromium(25136): [INFO:CONSOLE(95)] "ZXing code reader initialized", source: https://www.XXXXX.com.ar/Pendientes/Create2 (95)[ERROR:web_contents_delegate.cc(224)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.
[ERROR:web_contents_delegate.cc(224)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.
07-30 16:02:03.173 E/chromium(25136): [ERROR:web_contents_delegate.cc(224)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.
07-30 16:02:03.173 E/chromium(25136): [ERROR:web_contents_delegate.cc(224)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.
07-30 16:02:03.174 W/cr_media(25136): Requires MODIFY_AUDIO_SETTINGS and RECORD_AUDIO. No audio device will be available for recording
07-30 16:02:03.182 D/SensorManager(25136): unregisterListener :: 20, Game Rotation Vector Non-wakeup,
07-30 16:02:09.013 I/Choreographer(25136): Skipped 347 frames! The application may be doing too much work on its main thread.
07-30 16:02:09.077 I/CameraManagerGlobal(25136): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_OPEN for client com.companyname.XXXXX_365 API Level 2
07-30 16:02:09.095 E/cr_VideoCapture(25136): CameraDevice.StateCallback onOpened
07-30 16:02:09.420 I/chromium(25136): [INFO:CONSOLE(1)] "It was not possible to play the video.", source: https://www.XXXXX.com.ar/Scripts/zxing161.js (1)[INFO:CONSOLE(1)] "It was not possible to play the video.", source: https://www.XXXXX.com.ar/Scripts/zxing161.js (1)
07-30 16:02:09.511 I/CameraManagerGlobal(25136): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_ACTIVE for client com.companyname.XXXXX_365 API Level 2 [INFO:CONSOLE(1)] "It was not possible to play the video.", source: https://www.XXXXX.com.ar/Scripts/zxing161.js (1)07-30 16:02:09.554 I/chromium(25136): [INFO:CONSOLE(1)] "It was not possible to play the video.", source: https://www.XXXXX.com.ar/Scripts/zxing161.js (1)
07-30 16:02:09.555 W/me.XXXXX_36(25136): Attempt to remove non-JNI local reference, dumping thread 07-30 16:02:32.888 D/InputMethodManager(25136): prepareNavigationBarInfo() DecorView@cfb11ab[MainActivity] 07-30 16:02:32.889 D/InputMethodManager(25136): getNavigationBarColor() -855310 07-30 16:02:32.889 V/InputMethodManager(25136): Starting input: tba=com.companyname.XXXXX_365 ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false 07-30 16:02:32.889 D/InputMethodManager(25136): startInputInner - Id : 0 07-30 16:02:32.889 I/InputMethodManager(25136): startInputInner - mService.startInputOrWindowGainedFocus 07-30 16:02:32.891 D/InputTransport(25136): Input channel destroyed: 'ClientS', fd=188 07-30 16:02:33.332 D/ViewRootImpl@ebba680MainActivity: stopped(true) old=false Thread started: <Thread Pool> #122 Thread started: <Thread Pool> #123 07-30 16:02:33.611 D/ViewRootImpl@ebba680MainActivity: Relayout returned: old=(0,0,1080,2220) new=(0,0,1080,2220) req=(1080,2220)8 dur=10 res=0x5 s={false 0} ch=false 07-30 16:02:33.613 D/ViewRootImpl@ebba680MainActivity: MSG_WINDOW_FOCUS_CHANGED 0 1 07-30 16:02:33.613 D/InputMethodManager(25136): prepareNavigationBarInfo() DecorView@cfb11ab[MainActivity] 07-30 16:02:33.613 D/InputMethodManager(25136): getNavigationBarColor() -855310 07-30 16:02:38.347 W/System (25136): A resource failed to call release. Thread finished: <Thread Pool> #121 Thread started: <Thread Pool> #124 El subproceso 0x79 terminó con código 0 (0x0). 07-30 16:03:33.298 E/cr_VideoCapture(25136): cameraDevice encountered an error Thread finished: <Thread Pool> #123 El subproceso 0x7b terminó con código 0 (0x0). 07-30 16:03:33.477 I/CameraManagerGlobal(25136): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_IDLE for client com.companyname.XXXXX_365 API Level 2 07-30 16:03:33.576 I/CameraManagerGlobal(25136): Camera 1 facing CAMERA_FACING_FRONT state now CAMERA_STATE_CLOSED for client com.companyname.XXXXX_365 API Level 2 Thread finished: <Thread Pool> #118 El subproceso 0x76 terminó con código 0 (0x0). Thread finished: <Thread Pool> #124 Thread started: <Thread Pool> #125 El subproceso 0x7c terminó con código 0 (0x0).