Skip to content

Commit d49025a

Browse files
committed
MOBILE-839 desktop: Show error if cannot get stream.
1 parent dc4a5da commit d49025a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

www/core/components/emulator/services/mediacapture.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)