@wemap/camera 9.0.0 → 9.0.7
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/index.d.ts +44 -1
- package/package.json +5 -2
- package/src/Camera.js +6 -6
- package/src/SharedCameras.js +4 -17
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type EventEmitter from 'events';
|
|
2
2
|
|
|
3
|
+
declare module '@wemap/camera' {
|
|
3
4
|
|
|
4
5
|
export type IntrinsicParams = [number, number, number, number, number, number, number, number, number];
|
|
5
6
|
export type DistortionsParams = [number, number, number, number, number];
|
|
@@ -10,8 +11,50 @@ declare module '@wemap/camera' {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export class CameraUtils {
|
|
14
|
+
static convertFov(angle: number, aspectRatio: number): number;
|
|
15
|
+
static calcDisplayedFov(
|
|
16
|
+
videoContainer: HTMLDivElement,
|
|
17
|
+
videoElement: HTMLVideoElement,
|
|
18
|
+
hardwareVerticalFov: number
|
|
19
|
+
): { vertical: number, horizontal: number };
|
|
13
20
|
static createCameraCalibrationFromWidthHeightFov(width: number, height: number, fovOfWidth: number): Calibration;
|
|
21
|
+
static canvasToBase64(canvas: HTMLCanvasElement, type?: string, quality?: any): string;
|
|
22
|
+
static convertToGrayscale(imageCanvas: HTMLCanvasElement): void;
|
|
23
|
+
static reduceImageSize(
|
|
24
|
+
imageCanvas: HTMLCanvasElement,
|
|
25
|
+
maxWidth: number,
|
|
26
|
+
maxHeight?: number
|
|
27
|
+
): HTMLCanvasElement;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type CameraOptions = {
|
|
31
|
+
width?: number,
|
|
32
|
+
height?: number,
|
|
33
|
+
resizeOnWindowChange?: boolean
|
|
14
34
|
}
|
|
15
35
|
|
|
36
|
+
export type CameraState = 'stopped' | 'starting' | 'started' | 'stopping';
|
|
37
|
+
|
|
38
|
+
export class Camera extends EventEmitter {
|
|
39
|
+
|
|
40
|
+
constructor(container: Node, options?: CameraOptions);
|
|
16
41
|
|
|
42
|
+
start(videoMediaConstraints?: MediaStreamConstraints): Promise<void>;
|
|
43
|
+
stop(): Promise<void>;
|
|
44
|
+
release(): void;
|
|
45
|
+
|
|
46
|
+
checkAvailability(testUserMedia?: boolean): Promise<void>;
|
|
47
|
+
notifyContainerSizeChanged(): void;
|
|
48
|
+
get currentImage(): Promise<HTMLCanvasElement>;
|
|
49
|
+
|
|
50
|
+
get state(): CameraState;
|
|
51
|
+
get hardwareVerticalFov(): number;
|
|
52
|
+
set hardwareVerticalFov(fov: number);
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class SharedCameras extends EventEmitter {
|
|
57
|
+
list: { container: Node, camera: Camera }[];
|
|
58
|
+
getCameraByContainer(container: Node): Camera | null;
|
|
59
|
+
}
|
|
17
60
|
}
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/camera"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/camera",
|
|
15
|
-
"version": "9.0.
|
|
15
|
+
"version": "9.0.7",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"@zxing/library": "^0.18.4",
|
|
29
29
|
"events": "^3.3.0"
|
|
30
30
|
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/events": "^3.0.0"
|
|
33
|
+
},
|
|
31
34
|
"type": "module",
|
|
32
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "d703276c4576784d85e63e28fbcec18a150c08be"
|
|
33
36
|
}
|
package/src/Camera.js
CHANGED
|
@@ -70,7 +70,7 @@ class Camera extends EventEmitter {
|
|
|
70
70
|
this.videoContainer.appendChild(this.videoElement);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
async start(videoMediaConstraints
|
|
73
|
+
async start(videoMediaConstraints) {
|
|
74
74
|
|
|
75
75
|
if (this._state !== Camera.State.STOPPED) {
|
|
76
76
|
throw new Error('Camera is already started');
|
|
@@ -81,11 +81,11 @@ class Camera extends EventEmitter {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
this._state = Camera.State.STARTING;
|
|
84
|
-
this.emit(
|
|
84
|
+
this.emit(Camera.State.STARTING);
|
|
85
85
|
|
|
86
86
|
await Camera.checkAvailability();
|
|
87
87
|
|
|
88
|
-
if (videoMediaConstraints) {
|
|
88
|
+
if (typeof videoMediaConstraints === 'object') {
|
|
89
89
|
Object.assign(this._userMediaConstraints.video,
|
|
90
90
|
this._userMediaConstraints.video, videoMediaConstraints);
|
|
91
91
|
}
|
|
@@ -107,7 +107,7 @@ class Camera extends EventEmitter {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
this._state = Camera.State.STARTED;
|
|
110
|
-
this.emit(
|
|
110
|
+
this.emit(Camera.State.STARTED, {
|
|
111
111
|
videoElement: this.videoElement,
|
|
112
112
|
stream
|
|
113
113
|
});
|
|
@@ -124,7 +124,7 @@ class Camera extends EventEmitter {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
this._state = Camera.State.STOPPING;
|
|
127
|
-
this.emit(
|
|
127
|
+
this.emit(Camera.State.STOPPING, this);
|
|
128
128
|
|
|
129
129
|
if (this.videoStream && this.videoStream.stop) {
|
|
130
130
|
// compatibility with old JS API
|
|
@@ -141,7 +141,7 @@ class Camera extends EventEmitter {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
this._state = Camera.State.STOPPED;
|
|
144
|
-
this.emit(
|
|
144
|
+
this.emit(Camera.State.STOPPED, this);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
release() {
|
package/src/SharedCameras.js
CHANGED
|
@@ -4,17 +4,6 @@ import Camera from './Camera.js';
|
|
|
4
4
|
|
|
5
5
|
class SharedCameras extends EventEmitter {
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Singleton pattern.
|
|
9
|
-
* @returns {SharedCameras}
|
|
10
|
-
*/
|
|
11
|
-
static get instance() {
|
|
12
|
-
if (!this._instance) {
|
|
13
|
-
this._instance = new SharedCameras();
|
|
14
|
-
}
|
|
15
|
-
return this._instance;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
7
|
/** @type {{container: Node, camera: Camera}[]} */
|
|
19
8
|
_list = [];
|
|
20
9
|
|
|
@@ -51,15 +40,13 @@ class SharedCameras extends EventEmitter {
|
|
|
51
40
|
* @returns {?Camera}
|
|
52
41
|
*/
|
|
53
42
|
getCameraByContainer(container) {
|
|
54
|
-
for (const {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (container === _container) {
|
|
58
|
-
return camera;
|
|
43
|
+
for (const obj of this._list) {
|
|
44
|
+
if (container === obj.container) {
|
|
45
|
+
return obj.camera;
|
|
59
46
|
}
|
|
60
47
|
}
|
|
61
48
|
return null;
|
|
62
49
|
}
|
|
63
50
|
}
|
|
64
51
|
|
|
65
|
-
export default SharedCameras
|
|
52
|
+
export default new SharedCameras();
|