@wemap/camera 5.1.8 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wemap-camera.es.js +25 -23
- package/dist/wemap-camera.es.js.map +1 -1
- package/package.json +2 -2
- package/src/Camera.js +25 -23
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/camera"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/camera",
|
|
14
|
-
"version": "5.
|
|
14
|
+
"version": "5.3.0",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"events": "^3.3.0"
|
|
28
28
|
},
|
|
29
29
|
"type": "module",
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "e5350bc07b5b5f8df82566f78f227700f40d8678"
|
|
31
31
|
}
|
package/src/Camera.js
CHANGED
|
@@ -3,23 +3,6 @@ import EventEmitter from 'events';
|
|
|
3
3
|
import SharedCameras from './SharedCameras.js';
|
|
4
4
|
import { calcDisplayedFov } from './CameraUtils.js';
|
|
5
5
|
|
|
6
|
-
const GENERIC_HARDWARE_VERTICAL_FOV = 60;
|
|
7
|
-
|
|
8
|
-
const parameters = {
|
|
9
|
-
sourceWidth: 640,
|
|
10
|
-
sourceHeight: 480
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const userMediaConstraints = {
|
|
14
|
-
audio: false,
|
|
15
|
-
video: {
|
|
16
|
-
facingMode: 'environment',
|
|
17
|
-
width: { ideal: parameters.sourceWidth },
|
|
18
|
-
height: { ideal: parameters.sourceHeight }
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
6
|
// Helped from https://github.com/jeromeetienne/AR.js/blob/master/three.js/src/threex/threex-artoolkitsource.js
|
|
24
7
|
|
|
25
8
|
// Camera preview will fill component bounds without transformations.
|
|
@@ -27,6 +10,14 @@ const userMediaConstraints = {
|
|
|
27
10
|
// camera preview is extended then cropped.
|
|
28
11
|
class Camera extends EventEmitter {
|
|
29
12
|
|
|
13
|
+
static DEFAULT_OPTIONS = {
|
|
14
|
+
width: 1024,
|
|
15
|
+
height: 768,
|
|
16
|
+
resizeOnWindowChange: false
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
static GENERIC_HARDWARE_VERTICAL_FOV = 60;
|
|
20
|
+
|
|
30
21
|
videoContainer;
|
|
31
22
|
videoElement;
|
|
32
23
|
|
|
@@ -34,20 +25,31 @@ class Camera extends EventEmitter {
|
|
|
34
25
|
|
|
35
26
|
_isStarted = false;
|
|
36
27
|
|
|
37
|
-
_hardwareVerticalFov = GENERIC_HARDWARE_VERTICAL_FOV;
|
|
28
|
+
_hardwareVerticalFov = Camera.GENERIC_HARDWARE_VERTICAL_FOV;
|
|
38
29
|
_resizeOnWindowChange;
|
|
39
30
|
|
|
40
31
|
/**
|
|
41
32
|
* @param {Node} container
|
|
42
|
-
* @param {boolean}
|
|
33
|
+
* @param {{width: number, height: number, resizeOnWindowChange: boolean}} options
|
|
43
34
|
*/
|
|
44
|
-
constructor(container,
|
|
35
|
+
constructor(container, options = {}) {
|
|
45
36
|
super();
|
|
46
37
|
|
|
38
|
+
options = Object.assign({}, Camera.DEFAULT_OPTIONS, options);
|
|
39
|
+
|
|
47
40
|
SharedCameras._add(this, container);
|
|
48
41
|
|
|
49
42
|
this.videoContainer = container;
|
|
50
|
-
|
|
43
|
+
|
|
44
|
+
this._resizeOnWindowChange = options.resizeOnWindowChange;
|
|
45
|
+
this._userMediaConstraints = {
|
|
46
|
+
audio: false,
|
|
47
|
+
video: {
|
|
48
|
+
facingMode: 'environment',
|
|
49
|
+
width: { ideal: options.width },
|
|
50
|
+
height: { ideal: options.height }
|
|
51
|
+
}
|
|
52
|
+
};
|
|
51
53
|
|
|
52
54
|
this.videoContainer.style.overflow = 'hidden';
|
|
53
55
|
|
|
@@ -69,7 +71,7 @@ class Camera extends EventEmitter {
|
|
|
69
71
|
|
|
70
72
|
await Camera.checkAvailability();
|
|
71
73
|
|
|
72
|
-
const stream = await navigator.mediaDevices.getUserMedia(
|
|
74
|
+
const stream = await navigator.mediaDevices.getUserMedia(this._userMediaConstraints);
|
|
73
75
|
|
|
74
76
|
// Listeners have to be set before srcObject assigment or they can be never called
|
|
75
77
|
this.videoElement.oncanplaythrough = () => this.videoElement.play();
|
|
@@ -139,7 +141,7 @@ class Camera extends EventEmitter {
|
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
if (testUserMedia) {
|
|
142
|
-
const stream = await navigator.mediaDevices.getUserMedia(
|
|
144
|
+
const stream = await navigator.mediaDevices.getUserMedia(this._userMediaConstraints);
|
|
143
145
|
if (stream.stop) {
|
|
144
146
|
stream.stop();
|
|
145
147
|
} else {
|