MOBILE-3833 capture: Fix non-null assertions and types
parent
15b6e12b04
commit
ef405e4309
|
@ -229,7 +229,8 @@ export class CoreEmulatorCaptureMediaComponent implements OnInit, OnDestroy {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.streamVideo) {
|
const streamVideo = this.streamVideo;
|
||||||
|
if (!streamVideo) {
|
||||||
throw new CoreError('Video element not found.');
|
throw new CoreError('Video element not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +246,7 @@ export class CoreEmulatorCaptureMediaComponent implements OnInit, OnDestroy {
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
// Listen for stream ready to display the stream.
|
// Listen for stream ready to display the stream.
|
||||||
this.streamVideo.nativeElement.onloadedmetadata = (): void => {
|
streamVideo.nativeElement.onloadedmetadata = (): void => {
|
||||||
if (hasLoaded) {
|
if (hasLoaded) {
|
||||||
// Already loaded or timeout triggered, stop.
|
// Already loaded or timeout triggered, stop.
|
||||||
return;
|
return;
|
||||||
|
@ -254,19 +255,13 @@ export class CoreEmulatorCaptureMediaComponent implements OnInit, OnDestroy {
|
||||||
hasLoaded = true;
|
hasLoaded = true;
|
||||||
clearTimeout(waitTimeout);
|
clearTimeout(waitTimeout);
|
||||||
this.readyToCapture = true;
|
this.readyToCapture = true;
|
||||||
this.streamVideo!.nativeElement.onloadedmetadata = null;
|
streamVideo.nativeElement.onloadedmetadata = null;
|
||||||
// Force change detection. Angular doesn't detect these async operations.
|
// Force change detection. Angular doesn't detect these async operations.
|
||||||
this.changeDetectorRef.detectChanges();
|
this.changeDetectorRef.detectChanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set the stream as the source of the video.
|
// Set the stream as the source of the video.
|
||||||
if ('srcObject' in this.streamVideo.nativeElement) {
|
streamVideo.nativeElement.srcObject = this.localMediaStream;
|
||||||
this.streamVideo.nativeElement.srcObject = this.localMediaStream;
|
|
||||||
} else {
|
|
||||||
// Fallback for old browsers.
|
|
||||||
// See https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject#Examples
|
|
||||||
this.streamVideo.nativeElement.src = window.URL.createObjectURL(this.localMediaStream);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.dismissWithError(-1, error.message || error);
|
this.dismissWithError(-1, error.message || error);
|
||||||
}
|
}
|
||||||
|
@ -399,7 +394,7 @@ export class CoreEmulatorCaptureMediaComponent implements OnInit, OnDestroy {
|
||||||
this.imgCanvas.nativeElement.getContext('2d').drawImage(this.streamVideo?.nativeElement, 0, 0, width, height);
|
this.imgCanvas.nativeElement.getContext('2d').drawImage(this.streamVideo?.nativeElement, 0, 0, width, height);
|
||||||
|
|
||||||
// Convert the image to blob and show it in an image element.
|
// Convert the image to blob and show it in an image element.
|
||||||
this.imgCanvas.nativeElement.toBlob((blob) => {
|
this.imgCanvas.nativeElement.toBlob((blob: Blob) => {
|
||||||
loadingModal.dismiss();
|
loadingModal.dismiss();
|
||||||
|
|
||||||
this.mediaBlob = blob;
|
this.mediaBlob = blob;
|
||||||
|
|
Loading…
Reference in New Issue