@wemap/camera 9.0.0 → 9.0.8
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 +48 -1
- package/package.json +5 -2
- package/src/Camera.js +10 -7
- 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,54 @@ 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?: MediaTrackConstraints)
|
|
43
|
+
: Promise<{
|
|
44
|
+
videoElement: HTMLVideoElement,
|
|
45
|
+
stream: MediaStream
|
|
46
|
+
}>;
|
|
47
|
+
stop(): Promise<void>;
|
|
48
|
+
release(): void;
|
|
49
|
+
|
|
50
|
+
checkAvailability(testUserMedia?: boolean): Promise<void>;
|
|
51
|
+
notifyContainerSizeChanged(): void;
|
|
52
|
+
get currentImage(): Promise<HTMLCanvasElement>;
|
|
53
|
+
|
|
54
|
+
get state(): CameraState;
|
|
55
|
+
get hardwareVerticalFov(): number;
|
|
56
|
+
set hardwareVerticalFov(fov: number);
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class SharedCameras extends EventEmitter {
|
|
61
|
+
list: { container: Node, camera: Camera }[];
|
|
62
|
+
getCameraByContainer(container: Node): Camera | null;
|
|
63
|
+
}
|
|
17
64
|
}
|
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.8",
|
|
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": "68d42075fd79592fb762747c41a86d930a800625"
|
|
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,10 +107,13 @@ class Camera extends EventEmitter {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
this._state = Camera.State.STARTED;
|
|
110
|
-
|
|
110
|
+
const output = {
|
|
111
111
|
videoElement: this.videoElement,
|
|
112
112
|
stream
|
|
113
|
-
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this.emit(Camera.State.STARTED, output);
|
|
116
|
+
return output;
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
async stop() {
|
|
@@ -124,7 +127,7 @@ class Camera extends EventEmitter {
|
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
this._state = Camera.State.STOPPING;
|
|
127
|
-
this.emit(
|
|
130
|
+
this.emit(Camera.State.STOPPING, this);
|
|
128
131
|
|
|
129
132
|
if (this.videoStream && this.videoStream.stop) {
|
|
130
133
|
// compatibility with old JS API
|
|
@@ -141,7 +144,7 @@ class Camera extends EventEmitter {
|
|
|
141
144
|
}
|
|
142
145
|
|
|
143
146
|
this._state = Camera.State.STOPPED;
|
|
144
|
-
this.emit(
|
|
147
|
+
this.emit(Camera.State.STOPPED, this);
|
|
145
148
|
}
|
|
146
149
|
|
|
147
150
|
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();
|