@wemap/camera 3.2.6 → 3.2.9
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/package.json +2 -3
- package/src/Camera.js +8 -11
- package/src/SharedCameras.js +31 -8
- package/src/CameraLogger.js +0 -120
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/camera"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/camera",
|
|
14
|
-
"version": "3.2.
|
|
14
|
+
"version": "3.2.9",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -23,10 +23,9 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@wemap/navigation-logger": "^3.2.6",
|
|
27
26
|
"@zxing/library": "^0.17.1",
|
|
28
27
|
"events": "^3.1.0"
|
|
29
28
|
},
|
|
30
29
|
"type": "module",
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "6cfc15b7c401c74c4cf5297f367c8420a03bc2cf"
|
|
32
31
|
}
|
package/src/Camera.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
|
|
3
|
-
import CameraLogger from './CameraLogger.js';
|
|
4
3
|
import SharedCameras from './SharedCameras.js';
|
|
5
4
|
|
|
6
5
|
const GENERIC_HARDWARE_VERTICAL_FOV = 60;
|
|
@@ -37,8 +36,6 @@ class Camera extends EventEmitter {
|
|
|
37
36
|
_hardwareVerticalFov = GENERIC_HARDWARE_VERTICAL_FOV;
|
|
38
37
|
_resizeOnWindowChange;
|
|
39
38
|
|
|
40
|
-
_cameraLogger;
|
|
41
|
-
|
|
42
39
|
/**
|
|
43
40
|
* @param {Node} container
|
|
44
41
|
* @param {boolean} resizeOnWindowChange
|
|
@@ -59,8 +56,6 @@ class Camera extends EventEmitter {
|
|
|
59
56
|
this.videoElement.setAttribute('muted', '');
|
|
60
57
|
this.videoElement.setAttribute('playsinline', '');
|
|
61
58
|
this.videoContainer.appendChild(this.videoElement);
|
|
62
|
-
|
|
63
|
-
this._cameraLogger = new CameraLogger();
|
|
64
59
|
}
|
|
65
60
|
|
|
66
61
|
async start() {
|
|
@@ -89,9 +84,10 @@ class Camera extends EventEmitter {
|
|
|
89
84
|
window.addEventListener('resize', this.notifyContainerSizeChanged);
|
|
90
85
|
}
|
|
91
86
|
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
this.emit('start', {
|
|
88
|
+
videoElement: this.videoElement,
|
|
89
|
+
stream
|
|
90
|
+
});
|
|
95
91
|
}
|
|
96
92
|
|
|
97
93
|
async stop() {
|
|
@@ -102,8 +98,6 @@ class Camera extends EventEmitter {
|
|
|
102
98
|
|
|
103
99
|
this.emit('stop');
|
|
104
100
|
|
|
105
|
-
this._cameraLogger.detachStream();
|
|
106
|
-
|
|
107
101
|
if (this.videoStream && this.videoStream.stop) {
|
|
108
102
|
// compatibility with old JS API
|
|
109
103
|
this.videoStream.stop();
|
|
@@ -120,6 +114,10 @@ class Camera extends EventEmitter {
|
|
|
120
114
|
this._isStarted = false;
|
|
121
115
|
}
|
|
122
116
|
|
|
117
|
+
release() {
|
|
118
|
+
SharedCameras._remove(this);
|
|
119
|
+
}
|
|
120
|
+
|
|
123
121
|
static async checkAvailability(testUserMedia = false) {
|
|
124
122
|
|
|
125
123
|
if (!navigator.mediaDevices) {
|
|
@@ -224,7 +222,6 @@ class Camera extends EventEmitter {
|
|
|
224
222
|
horizontal: fovH
|
|
225
223
|
};
|
|
226
224
|
|
|
227
|
-
this._cameraLogger.fov = this.fov;
|
|
228
225
|
this.emit('fov.changed', this.fov);
|
|
229
226
|
}
|
|
230
227
|
|
package/src/SharedCameras.js
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
1
3
|
import Camera from './Camera.js';
|
|
2
4
|
|
|
3
|
-
class SharedCameras {
|
|
5
|
+
class SharedCameras extends EventEmitter {
|
|
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
|
+
}
|
|
4
17
|
|
|
5
|
-
|
|
18
|
+
_list = [];
|
|
6
19
|
|
|
7
20
|
/**
|
|
8
21
|
* @param {Camera} camera
|
|
9
22
|
* @param {Node}
|
|
10
23
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
_add(camera, container) {
|
|
25
|
+
const obj = {
|
|
13
26
|
camera,
|
|
14
27
|
container
|
|
15
|
-
}
|
|
28
|
+
};
|
|
29
|
+
this._list.push(obj);
|
|
30
|
+
this.emit('added', obj);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {Camera} camera
|
|
35
|
+
*/
|
|
36
|
+
_remove(camera) {
|
|
37
|
+
this._list = this._list.filter(({ camera: _camera }) => _camera !== camera);
|
|
38
|
+
this.emit('removed', { camera });
|
|
16
39
|
}
|
|
17
40
|
|
|
18
|
-
|
|
41
|
+
get list() {
|
|
19
42
|
return this._list;
|
|
20
43
|
}
|
|
21
44
|
|
|
22
|
-
|
|
45
|
+
getCameraByContainer(container) {
|
|
23
46
|
for (const {
|
|
24
47
|
camera, container: _container
|
|
25
48
|
} of this._list) {
|
|
@@ -31,4 +54,4 @@ class SharedCameras {
|
|
|
31
54
|
}
|
|
32
55
|
}
|
|
33
56
|
|
|
34
|
-
export default SharedCameras;
|
|
57
|
+
export default SharedCameras.instance;
|
package/src/CameraLogger.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { NavigationLogger } from '@wemap/navigation-logger';
|
|
2
|
-
import { TimeUtils } from '@wemap/utils';
|
|
3
|
-
|
|
4
|
-
class CameraLogger {
|
|
5
|
-
|
|
6
|
-
static _videoPart = 0;
|
|
7
|
-
|
|
8
|
-
_videoStream = null;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
|
|
12
|
-
NavigationLogger.on('started', () => {
|
|
13
|
-
CameraLogger._videoPart = 0;
|
|
14
|
-
if (this._videoStream !== null) {
|
|
15
|
-
this._start();
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
NavigationLogger.on('stopped', () => {
|
|
20
|
-
this._stop();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
attachStream(videoStream) {
|
|
26
|
-
this._videoStream = videoStream;
|
|
27
|
-
if (NavigationLogger.isRecording) {
|
|
28
|
-
this._start();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
detachStream() {
|
|
33
|
-
this._videoStream = null;
|
|
34
|
-
this._stop();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
set fov(fov) {
|
|
38
|
-
this._fov = fov;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
_start() {
|
|
42
|
-
CameraLogger._videoPart++;
|
|
43
|
-
|
|
44
|
-
if (!('MediaRecorder' in window)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (this.mediaRecorder) {
|
|
49
|
-
throw new Error('CameraLogger is already recording');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const options = {
|
|
53
|
-
mimeType: 'video/webm;codecs=vp8',
|
|
54
|
-
bitsPerSecond: NavigationLogger.params.videoBitrate
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
let isFirstChunck = true;
|
|
58
|
-
|
|
59
|
-
const startTime = TimeUtils.preciseTime;
|
|
60
|
-
|
|
61
|
-
// https://stackoverflow.com/questions/56826079/how-to-concat-chunks-of-incoming-binary-into-video-webm-file-node-js
|
|
62
|
-
this.mediaRecorder = new MediaRecorder(this._videoStream, options);
|
|
63
|
-
this.mediaRecorder.ondataavailable = event => {
|
|
64
|
-
if (event.data && event.data.size > 0) {
|
|
65
|
-
if (isFirstChunck) {
|
|
66
|
-
this._sendEvent('video-start', {
|
|
67
|
-
// startTime: TimeUtils.preciseTime - NavigationLogger.params.flushInterval,
|
|
68
|
-
startTime,
|
|
69
|
-
part: CameraLogger._videoPart,
|
|
70
|
-
fov: this._fov
|
|
71
|
-
});
|
|
72
|
-
isFirstChunck = false;
|
|
73
|
-
}
|
|
74
|
-
this._sendChunck(CameraLogger._videoPart, event.data);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
this.mediaRecorder.start(NavigationLogger.params.flushInterval);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
_stop() {
|
|
83
|
-
|
|
84
|
-
if (!this.mediaRecorder) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this._sendEvent('video-end', {
|
|
89
|
-
time: TimeUtils.preciseTime,
|
|
90
|
-
part: CameraLogger._videoPart
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
this.mediaRecorder.stop();
|
|
94
|
-
this.mediaRecorder = null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_sendChunck(videoPart, chunck) {
|
|
98
|
-
fetch(NavigationLogger.getVideoChunckUrl(videoPart), {
|
|
99
|
-
method: 'POST',
|
|
100
|
-
headers: { 'Content-Type': 'application/octet-stream' },
|
|
101
|
-
body: chunck
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_sendEvent(eventName, data) {
|
|
106
|
-
fetch(NavigationLogger.getVideoConfigUrl(), {
|
|
107
|
-
method: 'POST',
|
|
108
|
-
headers: {
|
|
109
|
-
'Accept': 'application/json',
|
|
110
|
-
'Content-Type': 'application/json'
|
|
111
|
-
},
|
|
112
|
-
body: JSON.stringify({
|
|
113
|
-
eventName,
|
|
114
|
-
data
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export default CameraLogger;
|