@monitordog/detector 1.0.9 → 1.0.11
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/assets/{inference-worker-ekAaVxft.js → inference-worker-KC9Jl3J4.js} +2 -2
- package/dist/assets/sdk/detector-320.onnx.enc +0 -0
- package/dist/assets/sdk/detector-416.onnx.enc +0 -0
- package/dist/assets/sdk/detector-640.onnx.enc +0 -0
- package/dist/detect/rotation-fallback.d.ts +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/monitordog-detector.js +195 -121
- package/dist/monitordog-detector.umd.cjs +1 -1
- package/dist/service/container.d.ts +3 -0
- package/dist/service/detect-service.d.ts +6 -0
- package/dist/types.d.ts +7 -1
- package/package.json +1 -1
|
@@ -39,11 +39,11 @@ function u() {
|
|
|
39
39
|
function d(e) {
|
|
40
40
|
return e === "auto" || e === 320 || e === 416 || e === 640;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function ee(e, t) {
|
|
43
43
|
let n = e ?? "auto";
|
|
44
44
|
return n === "auto" ? t ? 416 : 640 : n;
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function f(e) {
|
|
47
47
|
if (e === void 0) return;
|
|
48
48
|
let t = e.trim();
|
|
49
49
|
if (t.length === 0) throw Error("MonitorDog runtimeAssetBaseUrl must be a non-empty string when provided.");
|
|
@@ -52,36 +52,36 @@ function p(e) {
|
|
|
52
52
|
}
|
|
53
53
|
//#endregion
|
|
54
54
|
//#region src/sdk-error.ts
|
|
55
|
-
var
|
|
55
|
+
var p = class extends Error {
|
|
56
56
|
code;
|
|
57
57
|
cause;
|
|
58
58
|
constructor(e, t, n) {
|
|
59
59
|
super(t), this.name = "MonitorDogSdkError", this.code = e, this.cause = n;
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
function
|
|
63
|
-
return e instanceof
|
|
62
|
+
function m(e) {
|
|
63
|
+
return e instanceof p;
|
|
64
64
|
}
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/events.ts
|
|
67
|
-
function
|
|
68
|
-
if (e.faceCount === 0) return
|
|
69
|
-
if (e.faceCount >= 2) return
|
|
70
|
-
if (e.phoneCount >= 1) return
|
|
67
|
+
function h(e) {
|
|
68
|
+
if (e.faceCount === 0) return v("noFaceDetected", e);
|
|
69
|
+
if (e.faceCount >= 2) return v("twoFacesDetected", e);
|
|
70
|
+
if (e.phoneCount >= 1) return v("mobileDevice", e);
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function g(e) {
|
|
73
73
|
return {
|
|
74
|
-
...
|
|
74
|
+
...y(e, (/* @__PURE__ */ new Date()).toISOString()),
|
|
75
75
|
properties: {},
|
|
76
76
|
webcam_imgs: [],
|
|
77
77
|
monitor_imgs: []
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function _(e) {
|
|
81
81
|
return e.phoneCount === 0 && e.faceCount === 1;
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
let n =
|
|
83
|
+
function v(e, t) {
|
|
84
|
+
let n = y(e, (/* @__PURE__ */ new Date()).toISOString());
|
|
85
85
|
switch (e) {
|
|
86
86
|
case "noFaceDetected": return {
|
|
87
87
|
type: e,
|
|
@@ -98,7 +98,7 @@ function y(e, t) {
|
|
|
98
98
|
payload: {
|
|
99
99
|
...n,
|
|
100
100
|
properties: {
|
|
101
|
-
confidence:
|
|
101
|
+
confidence: b(t.faceDetections),
|
|
102
102
|
spots: t.faceDetections
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -108,16 +108,16 @@ function y(e, t) {
|
|
|
108
108
|
payload: {
|
|
109
109
|
...n,
|
|
110
110
|
properties: {
|
|
111
|
-
confidence:
|
|
111
|
+
confidence: b(t.phoneDetections),
|
|
112
112
|
spots: t.phoneDetections
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
function
|
|
118
|
+
function y(e, t) {
|
|
119
119
|
return {
|
|
120
|
-
basic_event_uuid:
|
|
120
|
+
basic_event_uuid: x(e),
|
|
121
121
|
occured_at: t,
|
|
122
122
|
sended_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
123
123
|
device_type: l(),
|
|
@@ -125,10 +125,10 @@ function b(e, t) {
|
|
|
125
125
|
device_id: "browser"
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
function
|
|
128
|
+
function b(e) {
|
|
129
129
|
return e.reduce((e, t) => Math.max(e, t.score), 0);
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function x(e) {
|
|
132
132
|
switch (e) {
|
|
133
133
|
case "logout": return "12ca646a-d832-4581-b03c-48f95627507f";
|
|
134
134
|
case "login": return "4c6f98ea-88d8-4215-9b6a-9b3ccb753465";
|
|
@@ -140,9 +140,9 @@ function S(e) {
|
|
|
140
140
|
}
|
|
141
141
|
//#endregion
|
|
142
142
|
//#region src/service/auth-service.ts
|
|
143
|
-
var
|
|
143
|
+
var S = "MonitorDog token refresh was superseded.", C = 300 * 1e3, w = class {
|
|
144
144
|
services;
|
|
145
|
-
refreshBeforeMs =
|
|
145
|
+
refreshBeforeMs = C;
|
|
146
146
|
periodicRefreshIntervalMs = r;
|
|
147
147
|
token;
|
|
148
148
|
tokenExpiresAt;
|
|
@@ -236,7 +236,7 @@ var C = "MonitorDog token refresh was superseded.", w = 300 * 1e3, T = class {
|
|
|
236
236
|
if (!t) throw Error("MonitorDog login email is required to refresh SDK token.");
|
|
237
237
|
let n = await this.fetchSessionToken(t), r = i(n);
|
|
238
238
|
if (!r || typeof r != "string") throw Error("MonitorDog SDK token response did not include a token.");
|
|
239
|
-
if (e !== this.authSessionId) throw Error(
|
|
239
|
+
if (e !== this.authSessionId) throw Error(S);
|
|
240
240
|
return this.setSessionTokenPayload(n), r;
|
|
241
241
|
}
|
|
242
242
|
startPeriodicRefresh() {
|
|
@@ -259,7 +259,7 @@ var C = "MonitorDog token refresh was superseded.", w = 300 * 1e3, T = class {
|
|
|
259
259
|
return !!(this.tokenExpiresAt && Date.now() >= this.tokenExpiresAt);
|
|
260
260
|
}
|
|
261
261
|
isRefreshSupersededError(e) {
|
|
262
|
-
return e instanceof Error && e.message ===
|
|
262
|
+
return e instanceof Error && e.message === S;
|
|
263
263
|
}
|
|
264
264
|
async fetchSessionToken(e) {
|
|
265
265
|
let t = this.services.options.sessionTokenProvider;
|
|
@@ -287,24 +287,24 @@ var C = "MonitorDog token refresh was superseded.", w = 300 * 1e3, T = class {
|
|
|
287
287
|
let t = await this.authorizedFetch("/event", {
|
|
288
288
|
method: "POST",
|
|
289
289
|
headers: { "content-type": "application/json" },
|
|
290
|
-
body: JSON.stringify(
|
|
290
|
+
body: JSON.stringify(g(e))
|
|
291
291
|
});
|
|
292
292
|
if (!t.ok) throw Error(`MonitorDog ${e} event failed: ${t.status}`);
|
|
293
293
|
} catch (t) {
|
|
294
|
-
let n = this.createSdkError(
|
|
294
|
+
let n = this.createSdkError(T(e), `MonitorDog ${e} event failed.`, t);
|
|
295
295
|
if (this.services.options.onAuthError?.(n), e === "logout") throw n;
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
createSdkError(e, t, n) {
|
|
299
|
-
return n instanceof
|
|
299
|
+
return n instanceof p ? n : new p(e, t, n);
|
|
300
300
|
}
|
|
301
301
|
};
|
|
302
|
-
function
|
|
302
|
+
function T(e) {
|
|
303
303
|
return e === "logout" ? "LOGOUT_FAILED" : "SESSION_TOKEN_FAILED";
|
|
304
304
|
}
|
|
305
305
|
//#endregion
|
|
306
306
|
//#region src/service/camera-service.ts
|
|
307
|
-
var
|
|
307
|
+
var E = /(obs|virtual|xsplit|manycam|splitcam|webcammax|fake|loopback|camtwist|e2esoft|vcam|droidcam|iriun|epoccam|camo|mmhmm|nvidia broadcast|streamlabs|bandicam|wirecast|chromacam|youcam|cyberlink|altserver|logi capture|elgato|streamfx|screen capture|desktop capture)/i, te = class {
|
|
308
308
|
async createWebcamStream(e) {
|
|
309
309
|
if (!navigator.mediaDevices?.getUserMedia) throw Error("getUserMedia is not available in this browser.");
|
|
310
310
|
let t = this.getBaseWebcamConstraints(e), n = await this.createFirstCameraConstraints(t);
|
|
@@ -423,7 +423,7 @@ var D = /(obs|virtual|xsplit|manycam|splitcam|webcammax|fake|loopback|camtwist|e
|
|
|
423
423
|
}
|
|
424
424
|
isVirtualCamera(e) {
|
|
425
425
|
let t = e.label.toLowerCase();
|
|
426
|
-
return t ?
|
|
426
|
+
return t ? E.test(t) : !1;
|
|
427
427
|
}
|
|
428
428
|
isPermissionError(e) {
|
|
429
429
|
return e instanceof DOMException && (e.name === "NotAllowedError" || e.name === "SecurityError");
|
|
@@ -447,7 +447,7 @@ var D = /(obs|virtual|xsplit|manycam|splitcam|webcammax|fake|loopback|camtwist|e
|
|
|
447
447
|
};
|
|
448
448
|
//#endregion
|
|
449
449
|
//#region src/capture.ts
|
|
450
|
-
function
|
|
450
|
+
function ne(e) {
|
|
451
451
|
if (e.videoWidth === 0 || e.videoHeight === 0) throw Error("Video frame is not ready for capture.");
|
|
452
452
|
let t = document.createElement("canvas"), n = t.getContext("2d");
|
|
453
453
|
if (!n) throw Error("2D canvas context is not available.");
|
|
@@ -461,7 +461,7 @@ function ee(e) {
|
|
|
461
461
|
}, "image/jpeg", .9);
|
|
462
462
|
});
|
|
463
463
|
}
|
|
464
|
-
async function
|
|
464
|
+
async function re() {
|
|
465
465
|
if (typeof document > "u" || !document.body) return null;
|
|
466
466
|
let t = await e(document.body, {
|
|
467
467
|
backgroundColor: "#ffffff",
|
|
@@ -473,7 +473,7 @@ async function te() {
|
|
|
473
473
|
}
|
|
474
474
|
//#endregion
|
|
475
475
|
//#region src/service/detection-event-service.ts
|
|
476
|
-
var
|
|
476
|
+
var ie = class e {
|
|
477
477
|
static NO_FACE_STARTUP_GRACE_MS = 1500;
|
|
478
478
|
services;
|
|
479
479
|
detectionEventLocked = !1;
|
|
@@ -489,12 +489,12 @@ var k = class e {
|
|
|
489
489
|
this.reset();
|
|
490
490
|
return;
|
|
491
491
|
}
|
|
492
|
-
if (
|
|
492
|
+
if (_(e)) {
|
|
493
493
|
this.noFaceStartedAt = void 0, this.clearLock();
|
|
494
494
|
return;
|
|
495
495
|
}
|
|
496
496
|
if (this.detectionEventLocked || this.detectionEventInFlight) return;
|
|
497
|
-
let n =
|
|
497
|
+
let n = h(e);
|
|
498
498
|
if (!n) {
|
|
499
499
|
this.noFaceStartedAt = void 0;
|
|
500
500
|
return;
|
|
@@ -531,11 +531,11 @@ var k = class e {
|
|
|
531
531
|
}
|
|
532
532
|
async uploadWebcamImage(e) {
|
|
533
533
|
if (!(e instanceof HTMLVideoElement) || e.videoWidth === 0 || e.videoHeight === 0) return;
|
|
534
|
-
let t = await
|
|
534
|
+
let t = await ne(e);
|
|
535
535
|
return this.uploadImage(t, "webcam.jpg");
|
|
536
536
|
}
|
|
537
537
|
async uploadMonitorImage() {
|
|
538
|
-
let e = this.services.options.captureMonitorImage ? await this.services.options.captureMonitorImage() : await
|
|
538
|
+
let e = this.services.options.captureMonitorImage ? await this.services.options.captureMonitorImage() : await re();
|
|
539
539
|
if (!e) return;
|
|
540
540
|
let t = typeof File < "u" && e instanceof File ? e.name : "monitor.jpg";
|
|
541
541
|
return this.uploadImage(e, t);
|
|
@@ -552,8 +552,8 @@ var k = class e {
|
|
|
552
552
|
}
|
|
553
553
|
shouldSendEvent(e, t) {
|
|
554
554
|
switch (e) {
|
|
555
|
-
case "mobileDevice": return this.services.userPreferences.mobileDetectionEnabled &&
|
|
556
|
-
case "twoFacesDetected": return this.services.userPreferences.multiPersonDetectionEnabled &&
|
|
555
|
+
case "mobileDevice": return this.services.userPreferences.mobileDetectionEnabled && D(t.phoneDetections) >= this.services.options.confidenceThreshold;
|
|
556
|
+
case "twoFacesDetected": return this.services.userPreferences.multiPersonDetectionEnabled && D(t.faceDetections) >= this.services.userPreferences.faceDetectionThreshold;
|
|
557
557
|
case "noFaceDetected": return this.services.userPreferences.noPersonDetectionEnabled;
|
|
558
558
|
}
|
|
559
559
|
}
|
|
@@ -585,12 +585,12 @@ var k = class e {
|
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
587
|
};
|
|
588
|
-
function
|
|
589
|
-
return e.reduce((e, t) => Math.max(e, t.
|
|
588
|
+
function D(e) {
|
|
589
|
+
return e.reduce((e, t) => Math.max(e, t.score), 0);
|
|
590
590
|
}
|
|
591
591
|
//#endregion
|
|
592
592
|
//#region src/detect/inference-worker.ts?worker&url
|
|
593
|
-
var
|
|
593
|
+
var ae = "" + new URL("assets/inference-worker-KC9Jl3J4.js", import.meta.url).href, O = class {
|
|
594
594
|
worker;
|
|
595
595
|
nextRequestId = 1;
|
|
596
596
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
@@ -633,7 +633,7 @@ var j = "" + new URL("assets/inference-worker-ekAaVxft.js", import.meta.url).hre
|
|
|
633
633
|
});
|
|
634
634
|
}
|
|
635
635
|
getWorker() {
|
|
636
|
-
return this.worker || (this.worker = new Worker(
|
|
636
|
+
return this.worker || (this.worker = new Worker(ae, {
|
|
637
637
|
name: "MonitorDogInference",
|
|
638
638
|
type: "module"
|
|
639
639
|
}), this.worker.addEventListener("message", this.handleMessage), this.worker.addEventListener("error", this.handleError), this.worker.addEventListener("messageerror", this.handleError)), this.worker;
|
|
@@ -659,15 +659,15 @@ var j = "" + new URL("assets/inference-worker-ekAaVxft.js", import.meta.url).hre
|
|
|
659
659
|
};
|
|
660
660
|
//#endregion
|
|
661
661
|
//#region src/detect/preprocess.ts
|
|
662
|
-
async function
|
|
663
|
-
let { sourceWidth: t, sourceHeight: n } =
|
|
662
|
+
async function k(e) {
|
|
663
|
+
let { sourceWidth: t, sourceHeight: n } = A(e);
|
|
664
664
|
if (e instanceof ImageData) return {
|
|
665
665
|
kind: "rgba",
|
|
666
666
|
data: new Uint8ClampedArray(e.data),
|
|
667
667
|
sourceWidth: t,
|
|
668
668
|
sourceHeight: n
|
|
669
669
|
};
|
|
670
|
-
if (
|
|
670
|
+
if (j() && M()) try {
|
|
671
671
|
return {
|
|
672
672
|
kind: "bitmap",
|
|
673
673
|
bitmap: await createImageBitmap(e),
|
|
@@ -675,9 +675,9 @@ async function N(e) {
|
|
|
675
675
|
sourceHeight: n
|
|
676
676
|
};
|
|
677
677
|
} catch {}
|
|
678
|
-
return
|
|
678
|
+
return N(e, t, n);
|
|
679
679
|
}
|
|
680
|
-
function
|
|
680
|
+
function A(e) {
|
|
681
681
|
return e instanceof ImageData ? {
|
|
682
682
|
sourceWidth: e.width,
|
|
683
683
|
sourceHeight: e.height
|
|
@@ -692,13 +692,13 @@ function P(e) {
|
|
|
692
692
|
sourceHeight: e.height
|
|
693
693
|
};
|
|
694
694
|
}
|
|
695
|
-
function
|
|
695
|
+
function j() {
|
|
696
696
|
return typeof createImageBitmap == "function";
|
|
697
697
|
}
|
|
698
|
-
function
|
|
698
|
+
function M() {
|
|
699
699
|
return typeof OffscreenCanvas == "function";
|
|
700
700
|
}
|
|
701
|
-
function
|
|
701
|
+
function N(e, t, n) {
|
|
702
702
|
let r = document.createElement("canvas"), i = r.getContext("2d");
|
|
703
703
|
if (!i) throw Error("2D canvas context is not available.");
|
|
704
704
|
return r.width = t, r.height = n, i.drawImage(e, 0, 0, t, n), {
|
|
@@ -710,43 +710,52 @@ function L(e, t, n) {
|
|
|
710
710
|
}
|
|
711
711
|
//#endregion
|
|
712
712
|
//#region src/detect/rotation-fallback.ts
|
|
713
|
-
function
|
|
714
|
-
return e.map((e) =>
|
|
713
|
+
function P(e, t, n) {
|
|
714
|
+
return e.map((e) => L(e, t, n));
|
|
715
|
+
}
|
|
716
|
+
function F(e, t, n) {
|
|
717
|
+
return e.map((e) => L(e, t, n));
|
|
715
718
|
}
|
|
716
|
-
function
|
|
717
|
-
if (e.phoneDetected
|
|
718
|
-
let i =
|
|
719
|
+
function I(e, t, n, r) {
|
|
720
|
+
if (e.phoneDetected) return e;
|
|
721
|
+
let i = [...e.phoneCandidates, ...F(t.phoneCandidates, n, r)];
|
|
722
|
+
if (t.phoneDetections.length === 0) return i.length === e.phoneCandidates.length ? e : {
|
|
723
|
+
...e,
|
|
724
|
+
phoneCandidates: i
|
|
725
|
+
};
|
|
726
|
+
let a = P(t.phoneDetections, n, r);
|
|
719
727
|
return {
|
|
720
728
|
...e,
|
|
721
|
-
phoneDetected:
|
|
722
|
-
phoneCount:
|
|
723
|
-
phoneDetections:
|
|
729
|
+
phoneDetected: a.length > 0,
|
|
730
|
+
phoneCount: a.length,
|
|
731
|
+
phoneDetections: a,
|
|
732
|
+
phoneCandidates: i
|
|
724
733
|
};
|
|
725
734
|
}
|
|
726
|
-
function
|
|
735
|
+
function L(e, t, n) {
|
|
727
736
|
return {
|
|
728
737
|
...e,
|
|
729
|
-
x:
|
|
730
|
-
y:
|
|
738
|
+
x: R(t - (e.x + e.width), 0, t),
|
|
739
|
+
y: R(n - (e.y + e.height), 0, n)
|
|
731
740
|
};
|
|
732
741
|
}
|
|
733
|
-
function
|
|
742
|
+
function R(e, t, n) {
|
|
734
743
|
return Math.min(Math.max(e, t), n);
|
|
735
744
|
}
|
|
736
745
|
//#endregion
|
|
737
746
|
//#region src/video.ts
|
|
738
|
-
function
|
|
747
|
+
function z(e) {
|
|
739
748
|
return e.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && e.videoWidth > 0 && e.videoHeight > 0 && !e.paused && !e.ended;
|
|
740
749
|
}
|
|
741
|
-
function
|
|
742
|
-
return
|
|
750
|
+
function B(e, t = 1e4) {
|
|
751
|
+
return V(e) ? Promise.resolve() : new Promise((n, r) => {
|
|
743
752
|
let i = window.setTimeout(() => {
|
|
744
753
|
o(), r(/* @__PURE__ */ Error("Timed out waiting for webcam video metadata."));
|
|
745
754
|
}, t), a = window.setInterval(s, 100), o = () => {
|
|
746
755
|
window.clearTimeout(i), window.clearInterval(a), e.removeEventListener("loadedmetadata", c), e.removeEventListener("loadeddata", c), e.removeEventListener("canplay", c), e.removeEventListener("playing", c), e.removeEventListener("resize", c), e.removeEventListener("error", l);
|
|
747
756
|
};
|
|
748
757
|
function s() {
|
|
749
|
-
|
|
758
|
+
V(e) && (o(), n());
|
|
750
759
|
}
|
|
751
760
|
let c = () => {
|
|
752
761
|
s();
|
|
@@ -756,18 +765,19 @@ function U(e, t = 1e4) {
|
|
|
756
765
|
e.addEventListener("loadedmetadata", c, { once: !0 }), e.addEventListener("loadeddata", c, { once: !0 }), e.addEventListener("canplay", c, { once: !0 }), e.addEventListener("playing", c, { once: !0 }), e.addEventListener("resize", c, { once: !0 }), e.addEventListener("error", l, { once: !0 });
|
|
757
766
|
});
|
|
758
767
|
}
|
|
759
|
-
function
|
|
768
|
+
function V(e) {
|
|
760
769
|
return e.readyState >= HTMLMediaElement.HAVE_METADATA && e.videoWidth > 0 && e.videoHeight > 0;
|
|
761
770
|
}
|
|
762
771
|
//#endregion
|
|
763
772
|
//#region src/service/detect-service.ts
|
|
764
|
-
var
|
|
773
|
+
var H = 700, U = .25, oe = .8, W = class {
|
|
765
774
|
services;
|
|
766
775
|
primaryInferenceWorker;
|
|
767
776
|
rotationInferenceWorker;
|
|
768
777
|
loadPromise;
|
|
769
778
|
lastInferenceMemoryErrorAt = 0;
|
|
770
779
|
lastParallelPhoneRotationFallbackAt = -Infinity;
|
|
780
|
+
phoneCandidateHistory = [];
|
|
771
781
|
constructor(e) {
|
|
772
782
|
this.services = e;
|
|
773
783
|
}
|
|
@@ -778,24 +788,25 @@ var G = class {
|
|
|
778
788
|
await this.load();
|
|
779
789
|
let t = this.services.options, n = t.debug ? performance.now() : 0, r = t.debug ? performance.now() : 0, i = r, a;
|
|
780
790
|
if (this.shouldUseParallelPhoneRotationFallback(t) && this.shouldRunParallelPhoneRotationFallback(t)) {
|
|
781
|
-
let [n, r] = await Promise.all([
|
|
791
|
+
let [n, r] = await Promise.all([k(e), k(e)]);
|
|
782
792
|
i = t.debug ? performance.now() : 0, a = await this.runParallelPhoneRotationFallback(n, r, t);
|
|
783
793
|
} else {
|
|
784
|
-
let n = await
|
|
794
|
+
let n = await k(e);
|
|
785
795
|
i = t.debug ? performance.now() : 0, a = await this.runWorkerInference(this.getInferenceWorker(), n, t, {
|
|
786
796
|
inputRotation: "none",
|
|
787
797
|
phoneRotationFallback: t.phoneRotationFallback && t.phoneRotationFallbackExecution === "sequential"
|
|
788
798
|
});
|
|
789
799
|
}
|
|
800
|
+
let o = this.confirmTemporalPhoneCandidates(a);
|
|
790
801
|
if (t.debug) {
|
|
791
802
|
let e = performance.now();
|
|
792
803
|
console.info("[MonitorDog] detect frame", {
|
|
793
|
-
sourceMs:
|
|
794
|
-
workerRoundtripMs:
|
|
795
|
-
totalMs:
|
|
804
|
+
sourceMs: J(i - r),
|
|
805
|
+
workerRoundtripMs: J(e - i),
|
|
806
|
+
totalMs: J(e - n)
|
|
796
807
|
});
|
|
797
808
|
}
|
|
798
|
-
return
|
|
809
|
+
return o;
|
|
799
810
|
}
|
|
800
811
|
toPublicResult(e) {
|
|
801
812
|
return {
|
|
@@ -811,7 +822,7 @@ var G = class {
|
|
|
811
822
|
let t = !1, n, r = this.services.options.detectionIntervalMs, i = async () => {
|
|
812
823
|
if (!t) {
|
|
813
824
|
try {
|
|
814
|
-
if (!this.services.shouldPauseDetection &&
|
|
825
|
+
if (!this.services.shouldPauseDetection && z(e)) {
|
|
815
826
|
let n = await this.detect(e);
|
|
816
827
|
if (t) return;
|
|
817
828
|
try {
|
|
@@ -826,7 +837,7 @@ var G = class {
|
|
|
826
837
|
if (t) return;
|
|
827
838
|
await this.services.detectionEvents.handleDetectionResult(n, e).catch((e) => {
|
|
828
839
|
this.services.options.onError?.(e);
|
|
829
|
-
}),
|
|
840
|
+
}), _(n) && this.services.detectionEvents.clearTransientState();
|
|
830
841
|
}
|
|
831
842
|
} catch (e) {
|
|
832
843
|
this.handleDetectionLoopError(e);
|
|
@@ -834,15 +845,15 @@ var G = class {
|
|
|
834
845
|
t || (n = setTimeout(i, r));
|
|
835
846
|
}
|
|
836
847
|
};
|
|
837
|
-
return i(), { stop() {
|
|
838
|
-
t = !0, n && clearTimeout(n);
|
|
848
|
+
return i(), { stop: () => {
|
|
849
|
+
t = !0, this.resetPhoneCandidateHistory(), n && clearTimeout(n);
|
|
839
850
|
} };
|
|
840
851
|
}
|
|
841
852
|
async startWebcamDetection() {
|
|
842
853
|
let e = this.services.options, t = await this.services.camera.createWebcamStream(e.constraints), n = this.services.camera, r = !e.video, i = e.video ?? document.createElement("video"), a = i.muted, o = i.playsInline, s = i.srcObject;
|
|
843
854
|
i.muted = !0, i.playsInline = !0, i.srcObject = t;
|
|
844
855
|
try {
|
|
845
|
-
await Promise.all([i.play(),
|
|
856
|
+
await Promise.all([i.play(), B(i)]);
|
|
846
857
|
} catch (e) {
|
|
847
858
|
throw n.stopStream(t), i.pause(), r ? i.srcObject = null : (i.muted = a, i.playsInline = o, i.srcObject = s), e;
|
|
848
859
|
}
|
|
@@ -859,7 +870,34 @@ var G = class {
|
|
|
859
870
|
};
|
|
860
871
|
}
|
|
861
872
|
dispose() {
|
|
862
|
-
this.primaryInferenceWorker?.terminate(), this.rotationInferenceWorker?.terminate(), this.primaryInferenceWorker = void 0, this.rotationInferenceWorker = void 0, this.loadPromise = void 0, this.lastParallelPhoneRotationFallbackAt = -Infinity, this.services.detectionEvents.reset();
|
|
873
|
+
this.primaryInferenceWorker?.terminate(), this.rotationInferenceWorker?.terminate(), this.primaryInferenceWorker = void 0, this.rotationInferenceWorker = void 0, this.loadPromise = void 0, this.lastParallelPhoneRotationFallbackAt = -Infinity, this.resetPhoneCandidateHistory(), this.services.detectionEvents.reset();
|
|
874
|
+
}
|
|
875
|
+
confirmTemporalPhoneCandidates(e) {
|
|
876
|
+
if (e.phoneCandidates.length === 0) return this.prunePhoneCandidateHistory(performance.now()), e;
|
|
877
|
+
let t = performance.now(), n = this.getRecentPhoneCandidateHistory(t), r = e.phoneCandidates.filter((e) => this.isTemporallyConfirmedPhoneCandidate(e, n));
|
|
878
|
+
if (this.phoneCandidateHistory = [...n, ...e.phoneCandidates.map((e) => ({
|
|
879
|
+
candidate: e,
|
|
880
|
+
observedAt: t
|
|
881
|
+
}))], r.length === 0) return e;
|
|
882
|
+
let i = [...e.phoneDetections, ...r.map(q)];
|
|
883
|
+
return {
|
|
884
|
+
...e,
|
|
885
|
+
phoneDetected: !0,
|
|
886
|
+
phoneCount: i.length,
|
|
887
|
+
phoneDetections: i
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
isTemporallyConfirmedPhoneCandidate(e, t) {
|
|
891
|
+
return G(e) ? t.some(({ candidate: t }) => K(e, t) && se(e, t) >= U) : !1;
|
|
892
|
+
}
|
|
893
|
+
getRecentPhoneCandidateHistory(e) {
|
|
894
|
+
return this.phoneCandidateHistory.filter((t) => e - t.observedAt <= H);
|
|
895
|
+
}
|
|
896
|
+
prunePhoneCandidateHistory(e) {
|
|
897
|
+
this.phoneCandidateHistory = this.getRecentPhoneCandidateHistory(e);
|
|
898
|
+
}
|
|
899
|
+
resetPhoneCandidateHistory() {
|
|
900
|
+
this.phoneCandidateHistory = [];
|
|
863
901
|
}
|
|
864
902
|
async runParallelPhoneRotationFallback(e, t, n) {
|
|
865
903
|
let r = e.sourceWidth, i = e.sourceHeight, [a, o] = await Promise.all([this.runWorkerInference(this.getInferenceWorker(), e, n, {
|
|
@@ -869,7 +907,7 @@ var G = class {
|
|
|
869
907
|
inputRotation: "rotate180",
|
|
870
908
|
phoneRotationFallback: !1
|
|
871
909
|
})]);
|
|
872
|
-
return
|
|
910
|
+
return I(a, o, r, i);
|
|
873
911
|
}
|
|
874
912
|
runWorkerInference(e, t, n, r) {
|
|
875
913
|
return e.run({
|
|
@@ -905,10 +943,10 @@ var G = class {
|
|
|
905
943
|
return /out of memory|oom|memory access out of bounds|cannot enlarge memory|array buffer allocation|bad allocation|allocation failed/i.test(t);
|
|
906
944
|
}
|
|
907
945
|
getInferenceWorker() {
|
|
908
|
-
return this.primaryInferenceWorker ||= new
|
|
946
|
+
return this.primaryInferenceWorker ||= new O(), this.primaryInferenceWorker;
|
|
909
947
|
}
|
|
910
948
|
getRotationInferenceWorker() {
|
|
911
|
-
return this.rotationInferenceWorker ||= new
|
|
949
|
+
return this.rotationInferenceWorker ||= new O(), this.rotationInferenceWorker;
|
|
912
950
|
}
|
|
913
951
|
shouldUseParallelPhoneRotationFallback(e) {
|
|
914
952
|
return e.phoneRotationFallback && e.phoneRotationFallbackExecution === "parallel";
|
|
@@ -946,12 +984,34 @@ var G = class {
|
|
|
946
984
|
await this.getInferenceWorker().load(n);
|
|
947
985
|
}
|
|
948
986
|
};
|
|
949
|
-
function
|
|
987
|
+
function G(e) {
|
|
988
|
+
return e.handOverlapped || e.score >= oe;
|
|
989
|
+
}
|
|
990
|
+
function K(e, t) {
|
|
991
|
+
return e.handOverlapped === t.handOverlapped ? G(t) : !1;
|
|
992
|
+
}
|
|
993
|
+
function q(e) {
|
|
994
|
+
return {
|
|
995
|
+
classId: e.classId,
|
|
996
|
+
label: e.label,
|
|
997
|
+
score: e.score,
|
|
998
|
+
confidence: e.confidence,
|
|
999
|
+
x: e.x,
|
|
1000
|
+
y: e.y,
|
|
1001
|
+
width: e.width,
|
|
1002
|
+
height: e.height
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
function se(e, t) {
|
|
1006
|
+
let n = e.x + e.width, r = e.y + e.height, i = t.x + t.width, a = t.y + t.height, o = Math.max(0, Math.min(n, i) - Math.max(e.x, t.x)) * Math.max(0, Math.min(r, a) - Math.max(e.y, t.y)), s = e.width * e.height + t.width * t.height - o;
|
|
1007
|
+
return s <= 0 ? 0 : o / s;
|
|
1008
|
+
}
|
|
1009
|
+
function J(e) {
|
|
950
1010
|
return Math.round(e * 10) / 10;
|
|
951
1011
|
}
|
|
952
1012
|
//#endregion
|
|
953
1013
|
//#region src/service/webcam-service.ts
|
|
954
|
-
var
|
|
1014
|
+
var ce = class {
|
|
955
1015
|
services;
|
|
956
1016
|
isWebcamRunning = !1;
|
|
957
1017
|
stopCurrentWebcam;
|
|
@@ -1043,7 +1103,7 @@ var q = class {
|
|
|
1043
1103
|
removeVisibilityListener() {
|
|
1044
1104
|
typeof document > "u" || document.removeEventListener("visibilitychange", this.handleVisibilityChange);
|
|
1045
1105
|
}
|
|
1046
|
-
},
|
|
1106
|
+
}, le = class {
|
|
1047
1107
|
auth;
|
|
1048
1108
|
camera;
|
|
1049
1109
|
detectionEvents;
|
|
@@ -1055,7 +1115,7 @@ var q = class {
|
|
|
1055
1115
|
#t = Y();
|
|
1056
1116
|
#n;
|
|
1057
1117
|
constructor(e) {
|
|
1058
|
-
this.#n = e, this.camera = new
|
|
1118
|
+
this.#n = e, this.camera = new te(), this.auth = new w(this), this.detectionEvents = new ie(this), this.detect = new W(this), this.webcam = new ce(this);
|
|
1059
1119
|
}
|
|
1060
1120
|
get options() {
|
|
1061
1121
|
return Object.freeze({ ...this.#n() });
|
|
@@ -1072,6 +1132,9 @@ var q = class {
|
|
|
1072
1132
|
updateRequiredPasswordFromServer(e) {
|
|
1073
1133
|
this.#n().requiredPassword = e;
|
|
1074
1134
|
}
|
|
1135
|
+
setPhoneConfidenceThreshold(e) {
|
|
1136
|
+
this.#n().phoneConfidenceThreshold = e, this.syncEffectivePhoneConfidenceThreshold();
|
|
1137
|
+
}
|
|
1075
1138
|
degradeInferenceModelForMemoryPressure() {
|
|
1076
1139
|
let e = this.#n();
|
|
1077
1140
|
if (e.inputSize > 416) {
|
|
@@ -1088,11 +1151,15 @@ var q = class {
|
|
|
1088
1151
|
}
|
|
1089
1152
|
applyPolicyItems(e, t) {
|
|
1090
1153
|
let n = { ...this.#t };
|
|
1091
|
-
for (let t of e)
|
|
1092
|
-
this.#t = n, this
|
|
1154
|
+
for (let t of e) de(n, t);
|
|
1155
|
+
this.#t = n, this.syncEffectivePhoneConfidenceThreshold(), this.#n().faceConfidenceThreshold = n.faceDetectionThreshold, this.updateRequiredPasswordFromServer(!1);
|
|
1093
1156
|
}
|
|
1094
1157
|
resetAuthenticatedState() {
|
|
1095
|
-
this.#e = 0, this.#t = Y(), this.#n().requiredPassword = !1, this
|
|
1158
|
+
this.#e = 0, this.#t = Y(), this.#n().requiredPassword = !1, this.syncEffectivePhoneConfidenceThreshold(), this.#n().faceConfidenceThreshold = this.#t.faceDetectionThreshold;
|
|
1159
|
+
}
|
|
1160
|
+
syncEffectivePhoneConfidenceThreshold() {
|
|
1161
|
+
let e = this.#n();
|
|
1162
|
+
e.confidenceThreshold = e.phoneConfidenceThreshold ?? this.#t.mobileDetectionThreshold;
|
|
1096
1163
|
}
|
|
1097
1164
|
};
|
|
1098
1165
|
function Y() {
|
|
@@ -1111,19 +1178,19 @@ function Y() {
|
|
|
1111
1178
|
multiPersonDetectionMode: "auto_lock"
|
|
1112
1179
|
};
|
|
1113
1180
|
}
|
|
1114
|
-
function
|
|
1181
|
+
function ue(e) {
|
|
1115
1182
|
return e === "none";
|
|
1116
1183
|
}
|
|
1117
|
-
function
|
|
1118
|
-
let n = t.policy, r = !
|
|
1184
|
+
function de(e, t) {
|
|
1185
|
+
let n = t.policy, r = !ue(t.policy), i = t.seconds * 1e3, a = "sensitivity" in t ? 1 - t.sensitivity / 100 : void 0;
|
|
1119
1186
|
switch (t.basic_event_uuid) {
|
|
1120
|
-
case
|
|
1187
|
+
case x("mobileDevice"):
|
|
1121
1188
|
e.mobileDetectionEnabled = r, e.mobileDetectionLockDuration = i, e.mobileDetectionMode = n, a !== void 0 && (e.mobileDetectionThreshold = a);
|
|
1122
1189
|
break;
|
|
1123
|
-
case
|
|
1190
|
+
case x("twoFacesDetected"):
|
|
1124
1191
|
e.multiPersonDetectionEnabled = r, e.multiPersonLockDuration = i, e.multiPersonDetectionMode = n, a !== void 0 && (e.faceDetectionThreshold = a);
|
|
1125
1192
|
break;
|
|
1126
|
-
case
|
|
1193
|
+
case x("noFaceDetected"):
|
|
1127
1194
|
e.noPersonDetectionEnabled = r, e.noPersonLockDuration = i, e.noPersonDetectionMode = n;
|
|
1128
1195
|
break;
|
|
1129
1196
|
default: break;
|
|
@@ -1131,7 +1198,7 @@ function Z(e, t) {
|
|
|
1131
1198
|
}
|
|
1132
1199
|
//#endregion
|
|
1133
1200
|
//#region src/index.ts
|
|
1134
|
-
var
|
|
1201
|
+
var X = class e {
|
|
1135
1202
|
#e;
|
|
1136
1203
|
#t;
|
|
1137
1204
|
#n = "anonymous";
|
|
@@ -1140,20 +1207,20 @@ var Q = class e {
|
|
|
1140
1207
|
#a;
|
|
1141
1208
|
#o;
|
|
1142
1209
|
static async init(t) {
|
|
1143
|
-
return
|
|
1210
|
+
return Z = new e(t), Z;
|
|
1144
1211
|
}
|
|
1145
1212
|
constructor(e) {
|
|
1146
|
-
|
|
1147
|
-
let r =
|
|
1213
|
+
ge(e);
|
|
1214
|
+
let r = he(), i = f(e.runtimeAssetBaseUrl);
|
|
1148
1215
|
this.#t = {
|
|
1149
1216
|
...e,
|
|
1150
1217
|
apiBaseUrl: c(e.apiBaseUrl),
|
|
1151
1218
|
runtimeAssetBaseUrl: i,
|
|
1152
|
-
confidenceThreshold:
|
|
1219
|
+
confidenceThreshold: e.phoneConfidenceThreshold ?? .8,
|
|
1153
1220
|
faceConfidenceThreshold: t,
|
|
1154
1221
|
iouThreshold: n,
|
|
1155
1222
|
maxDetections: 100,
|
|
1156
|
-
inputSize:
|
|
1223
|
+
inputSize: ee(e.modelInputSize, r),
|
|
1157
1224
|
inputType: "float32",
|
|
1158
1225
|
detectionIntervalMs: e.detectionIntervalMs ?? 300,
|
|
1159
1226
|
requiredPassword: !1,
|
|
@@ -1161,7 +1228,7 @@ var Q = class e {
|
|
|
1161
1228
|
phoneRotationFallback: e.phoneRotationFallback ?? !1,
|
|
1162
1229
|
phoneRotationFallbackMinIntervalMs: e.phoneRotationFallbackMinIntervalMs ?? 500,
|
|
1163
1230
|
phoneRotationFallbackExecution: e.phoneRotationFallbackExecution ?? "sequential"
|
|
1164
|
-
}, this.#e = new
|
|
1231
|
+
}, this.#e = new le(() => this.#t), this.#e.onLoginRequired = () => this.resetLoggedOutState(), Object.freeze(this);
|
|
1165
1232
|
}
|
|
1166
1233
|
async load() {
|
|
1167
1234
|
this.assertUsable(), this.assertAuthenticated("loading detection");
|
|
@@ -1233,6 +1300,9 @@ var Q = class e {
|
|
|
1233
1300
|
setEventReportingEnabled(e) {
|
|
1234
1301
|
this.assertUsable(), this.#t.eventReportingEnabled = e, e || this.#e.detectionEvents.reset();
|
|
1235
1302
|
}
|
|
1303
|
+
setPhoneConfidenceThreshold(e) {
|
|
1304
|
+
this.assertUsable(), $(e), this.#e.setPhoneConfidenceThreshold(e);
|
|
1305
|
+
}
|
|
1236
1306
|
getUserPreferences() {
|
|
1237
1307
|
return this.assertUsable(), this.#e.userPreferences;
|
|
1238
1308
|
}
|
|
@@ -1295,7 +1365,7 @@ var Q = class e {
|
|
|
1295
1365
|
});
|
|
1296
1366
|
} catch (e) {
|
|
1297
1367
|
let t = this.createSdkError(this.getStartErrorCode(e), this.getStartErrorMessage(e), e);
|
|
1298
|
-
throw this.transitionToError(t,
|
|
1368
|
+
throw this.transitionToError(t, fe(t.code) ? "blocked" : "idle"), this.#t.onError?.(t), t;
|
|
1299
1369
|
}
|
|
1300
1370
|
}
|
|
1301
1371
|
clearSessionState() {
|
|
@@ -1341,7 +1411,7 @@ var Q = class e {
|
|
|
1341
1411
|
}
|
|
1342
1412
|
}
|
|
1343
1413
|
createSdkError(e, t, n) {
|
|
1344
|
-
return
|
|
1414
|
+
return m(n) ? n : new p(e, t, n);
|
|
1345
1415
|
}
|
|
1346
1416
|
isDetectorRunning() {
|
|
1347
1417
|
return this.#r === "running" || this.#r === "starting" || !!this.#o || this.#e.webcam.isRunning || this.#e.webcam.isStarting;
|
|
@@ -1367,36 +1437,40 @@ var Q = class e {
|
|
|
1367
1437
|
return typeof DOMException < "u" && e instanceof DOMException && e.name === "NotReadableError";
|
|
1368
1438
|
}
|
|
1369
1439
|
};
|
|
1370
|
-
function
|
|
1440
|
+
function fe(e) {
|
|
1371
1441
|
return e === "CAMERA_PERMISSION_DENIED" || e === "CAMERA_READ_FAILED";
|
|
1372
1442
|
}
|
|
1373
|
-
var
|
|
1374
|
-
function
|
|
1375
|
-
return
|
|
1443
|
+
var Z;
|
|
1444
|
+
function pe(e) {
|
|
1445
|
+
return Z = new X(e), Z;
|
|
1376
1446
|
}
|
|
1377
|
-
async function
|
|
1378
|
-
return
|
|
1447
|
+
async function me(e) {
|
|
1448
|
+
return X.init(e);
|
|
1379
1449
|
}
|
|
1380
|
-
function
|
|
1381
|
-
if (
|
|
1382
|
-
return
|
|
1450
|
+
function Q() {
|
|
1451
|
+
if (!Z) throw Error("MonitorDog is not configured. Call MonitorDogDetector.init(), createMonitorDogDetector(), or configureMonitorDogDetector() before using getDetector().");
|
|
1452
|
+
return Z;
|
|
1383
1453
|
}
|
|
1384
|
-
function
|
|
1454
|
+
function he() {
|
|
1385
1455
|
if (typeof navigator > "u") return !1;
|
|
1386
1456
|
let e = l();
|
|
1387
1457
|
return e === "mobile" || e === "tablet";
|
|
1388
1458
|
}
|
|
1389
|
-
function
|
|
1459
|
+
function ge(e) {
|
|
1390
1460
|
if (!e || typeof e.apiBaseUrl != "string" || e.apiBaseUrl.length === 0) throw Error("MonitorDog apiBaseUrl is required.");
|
|
1391
1461
|
if (typeof e.sessionTokenProvider != "function") throw Error("MonitorDog sessionTokenProvider is required.");
|
|
1392
1462
|
if (typeof e.onDetect != "function") throw Error("MonitorDog onDetect callback is required.");
|
|
1393
|
-
if (e.runtimeAssetBaseUrl !== void 0 &&
|
|
1463
|
+
if (e.runtimeAssetBaseUrl !== void 0 && f(e.runtimeAssetBaseUrl), e.modelInputSize !== void 0 && !d(e.modelInputSize)) throw Error("MonitorDog modelInputSize must be \"auto\", 320, 416, or 640.");
|
|
1394
1464
|
if (e.phoneRotationFallback !== void 0 && typeof e.phoneRotationFallback != "boolean") throw Error("MonitorDog phoneRotationFallback must be a boolean when provided.");
|
|
1395
|
-
if (e.phoneRotationFallbackMinIntervalMs !== void 0 && !
|
|
1465
|
+
if (e.phoneRotationFallbackMinIntervalMs !== void 0 && !_e(e.phoneRotationFallbackMinIntervalMs)) throw Error("MonitorDog phoneRotationFallbackMinIntervalMs must be a non-negative finite number when provided.");
|
|
1396
1466
|
if (e.phoneRotationFallbackExecution !== void 0 && e.phoneRotationFallbackExecution !== "sequential" && e.phoneRotationFallbackExecution !== "parallel") throw Error("MonitorDog phoneRotationFallbackExecution must be \"sequential\" or \"parallel\" when provided.");
|
|
1467
|
+
$(e.phoneConfidenceThreshold);
|
|
1397
1468
|
}
|
|
1398
|
-
function
|
|
1469
|
+
function _e(e) {
|
|
1399
1470
|
return typeof e == "number" && Number.isFinite(e) && e >= 0;
|
|
1400
1471
|
}
|
|
1472
|
+
function $(e) {
|
|
1473
|
+
if (e !== void 0 && (typeof e != "number" || !Number.isFinite(e) || e < 0 || e > 1)) throw Error("MonitorDog phoneConfidenceThreshold must be a finite number between 0 and 1 when provided.");
|
|
1474
|
+
}
|
|
1401
1475
|
//#endregion
|
|
1402
|
-
export {
|
|
1476
|
+
export { X as MonitorDogDetector, p as MonitorDogSdkError, pe as configureMonitorDogDetector, me as createMonitorDogDetector, Q as getDetector, m as isMonitorDogSdkError };
|