@zappar/zappar-cv 3.0.0-alpha.3 → 3.0.0-alpha.5
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/README.md +2 -2
- package/lib/mstp-camera-source.d.ts +1 -0
- package/lib/mstp-camera-source.js +16 -0
- package/lib/native.js +8 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/worker-server.js +35 -5
- package/lib/workerinterface.d.ts +5 -0
- package/lib/zappar-cv.wasm +0 -0
- package/package.json +1 -1
- package/umd/56.zappar-cv.js +1 -1
- package/umd/{86a9fb85b3e74cca3306.wasm → ab9c9962bfa90d9d8629.wasm} +0 -0
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ npm i @zappar/zappar-cv
|
|
|
18
18
|
|
|
19
19
|
You can use our CDN from within your HTML:
|
|
20
20
|
```
|
|
21
|
-
<script src="https://libs.zappar.com/zappar-cv/3.0.0-alpha.
|
|
21
|
+
<script src="https://libs.zappar.com/zappar-cv/3.0.0-alpha.5/zappar-cv.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Or you can download and host our standalone JavaScript bundle:
|
|
25
|
-
[https://libs.zappar.com/zappar-cv/3.0.0-alpha.
|
|
25
|
+
[https://libs.zappar.com/zappar-cv/3.0.0-alpha.5/zappar-cv.zip](https://libs.zappar.com/zappar-cv/3.0.0-alpha.5/zappar-cv.zip)
|
|
@@ -164,6 +164,11 @@ export class MSTPCameraSource extends Source {
|
|
|
164
164
|
});
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
|
+
streamEnded() {
|
|
168
|
+
console.log('MSTP stream ended');
|
|
169
|
+
this._stop();
|
|
170
|
+
this._syncCamera();
|
|
171
|
+
}
|
|
167
172
|
_syncCamera() {
|
|
168
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
174
|
if (this._currentStream && this._isPaused) {
|
|
@@ -187,6 +192,11 @@ export class MSTPCameraSource extends Source {
|
|
|
187
192
|
let processor = new MediaStreamTrackProcessor({
|
|
188
193
|
track: videoTracks[0]
|
|
189
194
|
});
|
|
195
|
+
const str = this._currentStream;
|
|
196
|
+
yield delay(1000);
|
|
197
|
+
if (str !== this._currentStream) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
190
200
|
let p = Pipeline.get(this._pipeline);
|
|
191
201
|
if (p)
|
|
192
202
|
p.sendCameraStreamToWorker(this._impl, processor.readable, this._isUserFacing);
|
|
@@ -239,3 +249,9 @@ export class MSTPCameraSource extends Source {
|
|
|
239
249
|
}
|
|
240
250
|
MSTPCameraSource.USER_DEFAULT_DEVICE_ID = "Simulated User Default Device ID: a908df7f-5661-4d20-b227-a1c15d2fdb4b";
|
|
241
251
|
MSTPCameraSource.DEFAULT_DEVICE_ID = "Simulated Default Device ID: a908df7f-5661-4d20-b227-a1c15d2fdb4b";
|
|
252
|
+
function delay(ms) {
|
|
253
|
+
return new Promise(resolve => {
|
|
254
|
+
setTimeout(resolve, ms);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
;
|
package/lib/native.js
CHANGED
|
@@ -25,6 +25,7 @@ import { SequenceSource } from "./sequencesource";
|
|
|
25
25
|
import { createCameraSource, getCameraSource } from "./camera-source-map";
|
|
26
26
|
import { gfx } from "./gfx";
|
|
27
27
|
import { ImageTracker } from "./imagetracker";
|
|
28
|
+
import { MSTPCameraSource } from "./mstp-camera-source";
|
|
28
29
|
let client;
|
|
29
30
|
export function initialize(opts) {
|
|
30
31
|
if (client)
|
|
@@ -71,6 +72,13 @@ export function initialize(opts) {
|
|
|
71
72
|
(_g = (_f = Pipeline.get(msgt.p)) === null || _f === void 0 ? void 0 : _f.imageBitmapFromWorker) === null || _g === void 0 ? void 0 : _g.call(_f, msgt);
|
|
72
73
|
break;
|
|
73
74
|
}
|
|
75
|
+
case "streamEndedS2C": {
|
|
76
|
+
let msgt = msg;
|
|
77
|
+
const src = getCameraSource(msgt.source);
|
|
78
|
+
if (src instanceof MSTPCameraSource)
|
|
79
|
+
src.streamEnded();
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
74
82
|
case "licerr": {
|
|
75
83
|
let div = document.createElement("div");
|
|
76
84
|
div.innerHTML = "Visit <a href='https://docs.zap.works/universal-ar/licensing/' style='color: white;'>our licensing page</a> to find out about hosting on your own domain.";
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.0.0-alpha.
|
|
1
|
+
export declare const VERSION = "3.0.0-alpha.5";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.0-alpha.
|
|
1
|
+
export const VERSION = "3.0.0-alpha.5";
|
package/lib/worker-server.js
CHANGED
|
@@ -68,7 +68,13 @@ export function launchWorkerServer(wasmUrl) {
|
|
|
68
68
|
}
|
|
69
69
|
case "streamC2S": {
|
|
70
70
|
let msgt = msg;
|
|
71
|
-
consumeStream(mod, r, msgt.s, msgt.p, msgt.userFacing, server, msgt.source)
|
|
71
|
+
consumeStream(mod, r, msgt.s, msgt.p, msgt.userFacing, server, msgt.source).then(() => {
|
|
72
|
+
let m = { t: "streamEndedS2C", p: msgt.p, source: msgt.source };
|
|
73
|
+
console.log('Stream ended, requesting new stream');
|
|
74
|
+
messageManager.postOutgoingMessage(m, []);
|
|
75
|
+
}).catch(err => {
|
|
76
|
+
console.log('Stream ended with error', err);
|
|
77
|
+
});
|
|
72
78
|
break;
|
|
73
79
|
}
|
|
74
80
|
case "cameraToScreenC2S": {
|
|
@@ -129,28 +135,52 @@ export function launchWorkerServer(wasmUrl) {
|
|
|
129
135
|
function consumeStream(mod, r, stream, p, userFacing, server, source) {
|
|
130
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
137
|
while (true) {
|
|
138
|
+
let reader;
|
|
139
|
+
try {
|
|
140
|
+
reader = yield stream.getReader();
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
console.log("Error getting reader", err);
|
|
144
|
+
yield delay(1000);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
132
147
|
try {
|
|
133
|
-
const reader = yield stream.getReader();
|
|
134
148
|
yield consumeReader(mod, r, reader, p, userFacing, server, source);
|
|
149
|
+
return;
|
|
135
150
|
}
|
|
136
151
|
catch (err) {
|
|
137
|
-
console.log("Consuming reader error", err);
|
|
152
|
+
console.log("Consuming reader error 2", err);
|
|
138
153
|
}
|
|
139
154
|
yield delay(1000);
|
|
155
|
+
return;
|
|
140
156
|
}
|
|
141
157
|
});
|
|
142
158
|
}
|
|
143
159
|
let streamDataBufferPointer = 0;
|
|
144
160
|
let streamDataBufferLength = 0;
|
|
145
161
|
let tokenId = 1;
|
|
162
|
+
function getFrameOrTimeout(reader) {
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
const token = setTimeout(() => {
|
|
165
|
+
console.log('Frame timeout');
|
|
166
|
+
reject('Frame timeout');
|
|
167
|
+
}, 2000);
|
|
168
|
+
reader.read().then(result => {
|
|
169
|
+
clearTimeout(token);
|
|
170
|
+
resolve(result);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
146
174
|
const cameraToDeviceTransform = mat4.create();
|
|
147
175
|
const cameraModel = new Float32Array([300, 300, 160, 120, 0, 0]);
|
|
148
176
|
function consumeReader(mod, r, reader, p, userFacing, server, source) {
|
|
177
|
+
var _a;
|
|
149
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
179
|
while (true) {
|
|
151
|
-
let result = yield reader
|
|
180
|
+
let result = yield getFrameOrTimeout(reader);
|
|
152
181
|
if (result.done) {
|
|
153
|
-
console.log("Stream done");
|
|
182
|
+
console.log("Stream done", userFacing);
|
|
183
|
+
(_a = result.value) === null || _a === void 0 ? void 0 : _a.close();
|
|
154
184
|
return;
|
|
155
185
|
}
|
|
156
186
|
let frame = result.value;
|
package/lib/workerinterface.d.ts
CHANGED
|
@@ -63,6 +63,11 @@ export interface ImageBitmapS2C {
|
|
|
63
63
|
frame: ImageBitmap;
|
|
64
64
|
tokenId: number;
|
|
65
65
|
}
|
|
66
|
+
export interface StreamEndedS2C {
|
|
67
|
+
t: "streamEndedS2C";
|
|
68
|
+
p: zappar_pipeline_t;
|
|
69
|
+
source: zappar_camera_source_t;
|
|
70
|
+
}
|
|
66
71
|
export interface SensorDataC2S {
|
|
67
72
|
t: "sensorDataC2S";
|
|
68
73
|
sensor: "accel" | "accel_wo_gravity_int" | "accel_w_gravity_int" | "rotation_rate_int" | "attitude_int" | "rotation_rate" | "attitude";
|
package/lib/zappar-cv.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED