|
@@ -58,9 +58,6 @@ const DEFAULT_CAMERA_OPTIONS: Readonly<Required<CameraSourceOptions>> = {
|
58
|
58
|
*/
|
59
|
59
|
export class CameraSource extends VideoSource
|
60
|
60
|
{
|
61
|
|
- /** Video element */
|
62
|
|
- private _cameraVideo: HTMLVideoElement;
|
63
|
|
-
|
64
|
61
|
/** Options of the constructor */
|
65
|
62
|
private _options: Required<CameraSourceOptions>;
|
66
|
63
|
|
|
@@ -75,7 +72,6 @@ export class CameraSource extends VideoSource
|
75
|
72
|
const video = document.createElement('video');
|
76
|
73
|
|
77
|
74
|
super(video);
|
78
|
|
- this._cameraVideo = video;
|
79
|
75
|
this._options = Object.assign({}, DEFAULT_CAMERA_OPTIONS, options);
|
80
|
76
|
}
|
81
|
77
|
|
|
@@ -108,6 +104,7 @@ export class CameraSource extends VideoSource
|
108
|
104
|
video: {
|
109
|
105
|
width: size.width,
|
110
|
106
|
height: size.height,
|
|
107
|
+ aspectRatio: options.aspectRatio,
|
111
|
108
|
...options.constraints,
|
112
|
109
|
}
|
113
|
110
|
};
|
|
@@ -115,7 +112,7 @@ export class CameraSource extends VideoSource
|
115
|
112
|
// load camera stream
|
116
|
113
|
return new Speedy.Promise<HTMLVideoElement>((resolve, reject) => {
|
117
|
114
|
navigator.mediaDevices.getUserMedia(constraints).then(stream => {
|
118
|
|
- const video = this._cameraVideo;
|
|
115
|
+ const video = this.video;
|
119
|
116
|
video.onloadedmetadata = () => {
|
120
|
117
|
const promise = video.play();
|
121
|
118
|
const success = 'Access to the webcam has been granted.';
|
|
@@ -148,7 +145,7 @@ export class CameraSource extends VideoSource
|
148
|
145
|
error
|
149
|
146
|
));
|
150
|
147
|
});
|
151
|
|
- }).then(_ => super._init()); // this will call VideoSource._handleBrowserQuirks()
|
|
148
|
+ }).then(_ => super._init()); // this will handle browser quirks
|
152
|
149
|
}
|
153
|
150
|
|
154
|
151
|
/**
|
|
@@ -158,13 +155,14 @@ export class CameraSource extends VideoSource
|
158
|
155
|
*/
|
159
|
156
|
_release(): SpeedyPromise<void>
|
160
|
157
|
{
|
161
|
|
- const stream = this._cameraVideo.srcObject as MediaStream;
|
|
158
|
+ const video = this.video;
|
|
159
|
+ const stream = video.srcObject as MediaStream;
|
162
|
160
|
const tracks = stream.getTracks();
|
163
|
161
|
|
164
|
162
|
// stop camera feed
|
165
|
163
|
tracks.forEach(track => track.stop());
|
166
|
|
- this._cameraVideo.onloadedmetadata = null;
|
167
|
|
- this._cameraVideo.srcObject = null;
|
|
164
|
+ video.onloadedmetadata = null;
|
|
165
|
+ video.srcObject = null;
|
168
|
166
|
|
169
|
167
|
// release the media
|
170
|
168
|
return super._release();
|