@snap/camera-kit
Version:
Camera Kit Web
35 lines • 1.49 kB
JavaScript
import { forActions } from "@snap/state-management";
import { map, mergeMap, take } from "rxjs";
import { Injectable } from "@snap/ts-inject";
import { getTimeMs } from "../../common/time";
import { TypedCustomEvent } from "../../events/TypedCustomEvent";
import { lensStateFactory } from "../../session/lensState";
import { metricsEventTargetFactory } from "../metricsEventTarget";
const viewTimeThresholdSec = 0.1;
export const reportLensWait = Injectable("reportLensWait", [lensStateFactory.token, metricsEventTargetFactory.token], (lensState, metricsEventTarget) => {
lensState.events
.pipe(forActions("applyLens"), mergeMap(([a]) => {
const lensId = a.data.lens.id;
const lensGroupId = a.data.lens.groupId;
const applyLensStartTime = getTimeMs();
return lensState.events.pipe(forActions("firstFrameProcessed", "applyLens"), take(1), map(() => [
(getTimeMs() - applyLensStartTime) / 1000,
lensId,
lensGroupId,
]));
}))
.subscribe({
next: ([viewTimeSec, lensId, lensGroupId]) => {
if (viewTimeSec < viewTimeThresholdSec)
return;
const lensWait = {
name: "lensWait",
lensId,
viewTimeSec,
lensGroupId,
};
metricsEventTarget.dispatchEvent(new TypedCustomEvent("lensWait", lensWait));
},
});
});
//# sourceMappingURL=reportLensWait.js.map