File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
www/core/components/emulator/services Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -162,17 +162,37 @@ angular.module('mm.core.emulator')
162162 }
163163
164164 if ( scope . isImage || scope . isVideo ) {
165+ var hasLoaded = false ,
166+ waitTimeout ;
167+
165168 // Set the stream as the source of the video.
166169 streamVideo = modal . modalEl . querySelector ( 'video.mm-webcam-stream' ) ;
167170 streamVideo . src = $window . URL . createObjectURL ( localMediaStream ) ;
168171
169172 // Stream ready, show modal.
170173 streamVideo . onloadedmetadata = function ( ) {
174+ if ( hasLoaded ) {
175+ // Already loaded or timeout triggered, stop.
176+ return ;
177+ }
178+
179+ hasLoaded = true ;
180+ $timeout . cancel ( waitTimeout ) ;
171181 loadingModal . dismiss ( ) ;
172182 modal . show ( ) ;
173183 scope . readyToCapture = true ;
174184 streamVideo . onloadedmetadata = null ;
175185 } ;
186+
187+ // If stream isn't ready in a while, show error.
188+ waitTimeout = $timeout ( function ( ) {
189+ if ( ! hasLoaded ) {
190+ // Show error.
191+ hasLoaded = true ;
192+ loadingModal . dismiss ( ) ;
193+ errorCallback && errorCallback ( { code : - 1 , message : 'Cannot connect to webcam.' } ) ;
194+ }
195+ } , 10000 ) ;
176196 } else {
177197 // No need to wait to show the modal.
178198 loadingModal . dismiss ( ) ;
You can’t perform that action at this time.
0 commit comments