decord/source/modules/analytics_sessions/SessionHeartbeatScheduler.tsx
github-actions 7450227d0b chore: update source for alpha 345.4
Skipped 1 file(s) >100MB (GitHub limit): source/__vendor/09xxx/9596_m.js (380.6 MB)
2026-09-04 17:41:35 +00:00

665 lines
21 KiB
TypeScript

// Module ID: 7395
// Function ID: 7396
// Name: trackHeartbeat
// Dependencies: [5, 5238, 1215, 5371, 4557, 673, 684, 3, 7396, 7397, 7398, 1205, 7399, 7402, 695, 7403, 592, 7405, 665, 706, 586, 511, 2]
// Exports: getActiveSessionUnsafe, initSessionHeartbeatScheduler
// Module 7395 (trackHeartbeat)
import timestampDefault from "timestamp" /* 3 */;
import initializeDefault from "initialize" /* 586 */;
import Storage2 from "Storage" /* 592 */;
import setDefault from "set" /* 684 */;
import dispatcherDefault from "dispatcher" /* 706 */;
import _modDef1205 from "module_1205" /* 1205 */;
import isForegrounded2 from "isForegrounded" /* 7396 */;
import isActiveUserRoute2 from "isActiveUserRoute" /* 7397 */;
import monotonicNowMs from "monotonicNowMs" /* 7398 */;
import result2 from "result" /* 7405 */;
import closure_3 from "asyncGeneratorStep" /* 5 */;
import closure_4 from "_handleConnectionOpen" /* 5238 */;
import importDefaultResult from "fetchFingerprint" /* 1215 */;
import closure_6 from "checkIdleAFK" /* 5371 */;
import importDefaultResult1 from "createRTCConnection" /* 4557 */;
import ME from "ME" /* 673 */;
import isForegrounded from "isForegrounded" /* 7396 */;
import isActiveUserRoute from "isActiveUserRoute" /* 7397 */;
require = arg1;
function trackHeartbeat() {
const self = this;
const apply = _trackHeartbeat.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
function _trackHeartbeat() {
const self = this;
const tmp = callback(function*() {
if (c4 === 2) {
c4 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp4 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
return { value: "HermesInternal", done: null };
}
} else {
try {
c4 = 2;
let num2 = 0;
if (0 === closure_3) {
if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
dependencyMap = tmp5;
let lib = tmp2;
num2 = undefined;
lib = undefined;
dependencyMap = undefined;
closure_3 = undefined;
c4 = undefined;
const _Date2 = Date;
num2 = Date.now();
closure_3 = 1;
c4 = 1;
obj1 = { value: null, done: false };
obj1[0] = closure_1_38();
return obj1;
}
} else if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
const obj2 = { value: null, done: true };
obj2[0] = arg1;
return obj2;
} else {
lib = arg1;
let tmp40 = globalThis;
const _Date3 = Date;
dependencyMap = Date.now();
let track = null;
if (null != lib) {
obj1 = lib(1205);
const obj3 = { category: null, message: "Tracking Heartbeat", data: null };
obj3[0] = closure_14;
const obj4 = { initialized: null };
obj4[0] = lib.createdAtTimestamp;
obj3[2] = obj4;
obj1.addBreadcrumb(obj3);
let obj5 = { client_heartbeat_initialization_timestamp: null, client_heartbeat_version: 31 };
obj5[0] = lib.createdAtTimestamp;
obj5 = num2(7402);
const merged = Object.assign(obj5.getClientHeartbeatPiggybackProperties());
const idleSince = store.getIdleSince();
num2 = idleSince;
closure_3 = num2;
const obj6 = { is_idle: null, idle_duration_ms: null, is_afk: null, is_system_suspended: null, is_system_locked: null };
obj6[0] = store.isIdle();
const _Date = tmp40.Date;
obj6[1] = _Date.now() - closure_3;
obj6[2] = store.isAFK();
obj6[3] = store.getSystemSuspended();
obj6[4] = store.getSystemLocked();
const merged1 = Object.assign(obj6);
c4 = obj5;
tmp40 = lib(695);
track = tmp40.track;
track(constants.CLIENT_HEARTBEAT, c4);
closure_19 = num2(7398).monotonicNowMs();
const obj8 = num2(7398);
num2 = num2(7399).drainClickstream();
const obj9 = num2(7399);
} else {
obj = lib(1205);
const _Error = Error;
const _HermesInternal = HermesInternal;
obj.captureException(Error("Null session when tracking session heartbeat. Waited " + dependencyMap - num2 + "ms"));
}
c4 = 3;
}
} catch (tmp51) {
c4 = tmp;
throw tmp51;
}
}
});
closure_26 = tmp;
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
function isActive() {
const items = [];
if (tmp) {
if (closure_22) {
items.push("foregrounded");
}
if (closure_21 === constants2.RTC_CONNECTED) {
items.push("rtc_connected");
}
}
return items.length > 0;
}
function scheduleHeartbeatTracking() {
let obj = _modDef1205;
obj = { message: `Heartbeat Track State Parameters Changed. Foregrounded ${closure_22}, Connection State: ${closure_21}` };
obj.addBreadcrumb(obj);
const items = [];
if (tmp4) {
if (closure_22) {
items.push("foregrounded");
}
if (closure_21 === constants2.RTC_CONNECTED) {
items.push("rtc_connected");
}
}
if (items.length > 0) {
if (null == _null) {
let num = 0;
if (0 !== c19) {
let obj2 = monotonicNowMs;
num = closure_11 - (obj2.monotonicNowMs() - c19);
}
obj = { message: null };
const _HermesInternal = HermesInternal;
obj[0] = "Received Last Heartbeat Event Timestamp. Time Until Next Heartbeat: " + num / 1000 + " seconds. Scheduling Heartbeat";
_modDef1205.addBreadcrumb(obj);
obj1 = { type: "timeout", id: null };
const _setTimeout = setTimeout;
obj1[1] = setTimeout(() => {
callback();
const obj = {
type: "interval",
id: setInterval(() => {
callback();
}, closure_11)
};
}, num);
_null = obj1;
const tmpResult = _modDef1205;
}
} else if (null == _null) {
// // eliminated: always false
} else {
const type = _null.type;
if ("timeout" === type) {
const _clearTimeout = clearTimeout;
clearTimeout(_null.id);
_null = null;
} else if ("interval" !== type) {
const type2 = _null.type;
}
const _clearInterval = clearInterval;
clearInterval(_null.id);
}
socket = socket.getSocket();
if (socket != null) {
let tmp25 = null != closure_24;
if (tmp25) {
tmp25 = closure_23;
}
const items1 = [];
if (tmp25) {
if (closure_22) {
items1.push("foregrounded");
}
if (closure_21 === constants2.RTC_CONNECTED) {
items1.push("rtc_connected");
}
}
obj2 = { active: null, ver: 31, reasons: null };
obj2[0] = items1.length > 0;
obj2[2] = items1;
const result = socket.handleActiveStateChange(obj2);
}
}
function validateClientSession(version) {
let tmp = null;
if (null != version) {
let tmp4 = version;
if (version.version !== result2.CLIENT_SESSION_STORAGE_VERSION) {
const _HermesInternal = HermesInternal;
logger.warn("Throwing away client session with invalid version: " + version.version + ", expected " + tmp2(7405).CLIENT_SESSION_STORAGE_VERSION);
tmp4 = null;
}
tmp = tmp4;
tmp2 = require;
}
return tmp;
}
function forceDispatchSessionIdUpdate() {
const self = this;
const apply = _forceDispatchSessionIdUpdate.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
function _forceDispatchSessionIdUpdate() {
const self = this;
const tmp = callback(function*() {
if (c3 === 2) {
c3 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp4 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
return { value: "HermesInternal", done: null };
}
} else {
try {
c3 = 2;
if (0 === table) {
if (arg0 === 1) {
c3 = 3;
throw arg1;
} else if (arg0 === 2) {
c3 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
closure_1 = tmp5;
let callback = tmp2;
callback = undefined;
table = 1;
c3 = 1;
obj1 = { value: null, done: false };
obj1[0] = closure_1_38(false);
return obj1;
}
} else if (arg0 === 1) {
c3 = 3;
throw arg1;
} else if (arg0 === 2) {
c3 = 3;
const obj2 = { value: null, done: true };
obj2[0] = arg1;
return obj2;
} else {
callback = arg1;
if (null != callback) {
socket = socket.getSocket();
if (socket != null) {
({ createdAtTimestamp, uuid } = callback);
const result = socket.handleUpdateTimeSpentSessionId(createdAtTimestamp, uuid, callback(table[18]).clientLaunchId);
}
}
c3 = 3;
return { value: "HermesInternal", done: null };
}
} catch (tmp16) {
c3 = tmp;
throw tmp16;
}
}
});
closure_31 = tmp;
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
function handleAuthenticationChange() {
const token = importDefaultResult.getToken();
if (token !== token) {
const Storage = Storage2.Storage;
Storage.remove(LAST_CLIENT_HEARTBEAT_SESSION);
closure_20 = { state: "loaded", session: null };
if (null == _null) {
// // eliminated: always false
c19 = 0;
} else {
const type = _null.type;
if ("timeout" === type) {
const _clearTimeout = clearTimeout;
clearTimeout(_null.id);
_null = null;
} else if ("interval" !== type) {
const type2 = _null.type;
}
const _clearInterval = clearInterval;
clearInterval(_null.id);
}
}
scheduleHeartbeatTracking();
}
function handleRTCStateChange() {
const state = importDefaultResult1.getState();
if (state !== state) {
scheduleHeartbeatTracking();
}
}
function handleWindowFocus(focused) {
focused = focused.focused;
if (focused !== focused) {
scheduleHeartbeatTracking();
}
}
function handleLocationChange() {
const isActiveUserRouteResult = isActiveUserRoute2.isActiveUserRoute();
if (isActiveUserRouteResult !== isActiveUserRouteResult) {
scheduleHeartbeatTracking();
}
}
function handleAppStateUpdate(state) {
if (closure_22 !== state.state === constants.ACTIVE) {
closure_22 = tmp;
scheduleHeartbeatTracking();
}
}
function handleFluxInitialized() {
const state = importDefaultResult1.getState();
closure_22 = isForegrounded2.isForegrounded();
const obj = isForegrounded2;
closure_23 = isActiveUserRoute2.isActiveUserRoute();
handleAuthenticationChange();
}
function getSession() {
const self = this;
const apply = _getSession.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
function _getSession() {
const self = this;
const tmp = callback(() => {
closure_0 = arg0;
c6 = 0;
c7 = 0;
c4 = 0;
const iter = (function*() {
if (c7 === 2) {
c7 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp6 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
return { value: "HermesInternal", done: null };
}
} else {
try {
c7 = 2;
if (0 === c6) {
if (arg0 === 1) {
c7 = 3;
throw arg1;
} else if (arg0 === 2) {
c7 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
uuid = tmp3;
uuid = tmp7;
let flag;
if (flag === undefined) {
flag = true;
}
let callback2;
uuid = undefined;
uuid = undefined;
c6 = 1;
c7 = 1;
return { value: "PX_16", done: true };
}
} else {
if (1 === tmp7) {
if (arg0 === 1) {
c7 = 3;
throw arg1;
} else if (arg0 === 2) {
c7 = 3;
obj1 = { value: null, done: true };
obj1[0] = arg1;
return obj1;
} else {
uuid = null;
let tmp21 = null;
if ("loaded" === obj4.state) {
const session = obj4.session;
uuid = undefined;
if (session != null) {
uuid = session.uuid;
}
tmp21 = uuid;
}
uuid = tmp21;
let socket = 1;
if ("uninitialized" === obj4.state) {
callback2 = closure_1_29;
let Storage = callback(closure_1_2[16]).Storage;
c6 = 3;
c7 = 1;
let obj2 = { value: null, done: false };
obj2[0] = Storage.getAfterRefresh(closure_1_13);
return obj2;
} else {
uuid = obj4.session;
socket = 0;
}
}
} else if (2 === tmp7) {
socket = 0;
socket = closure_5;
obj1 = callback2(uuid[11]);
obj1.captureException(socket);
const _Date = Date;
callback2 = Date.now();
if (callback3()) {
let isSessionExpiredResult = null == tmp30;
if (!isSessionExpiredResult) {
let obj3 = flag(uuid[17]);
isSessionExpiredResult = obj3.isSessionExpired(uuid);
}
if (isSessionExpiredResult) {
obj3 = { uuid: null, createdAtTimestamp: null, lastUsedTimestamp: null, version: null };
let obj5 = flag(uuid[21]);
obj3[0] = obj5.v4();
obj3[1] = callback2;
obj3[2] = callback2;
obj3[3] = flag(uuid[17]).CLIENT_SESSION_STORAGE_VERSION;
uuid = obj3;
c18 = 0;
}
uuid.lastUsedTimestamp = callback2;
(function maybeFlushSessionToStorage(c2) {
const monotonicNowMsResult = flag(_null[10]).monotonicNowMs();
if (monotonicNowMsResult - c18 >= closure_12) {
try {
const Storage = flag(_null[16]).Storage;
const result = Storage.set(closure_13, c2);
c18 = monotonicNowMsResult;
} catch (tmp9) {
callback(tmp2[11]).captureException(tmp9);
const obj2 = callback(tmp2[11]);
}
}
})(uuid);
} else {
let isSessionExpiredResult1 = null != tmp30;
if (isSessionExpiredResult1) {
obj2 = flag(uuid[17]);
isSessionExpiredResult1 = obj2.isSessionExpired(uuid);
}
if (isSessionExpiredResult1) {
uuid = null;
}
}
obj4 = { state: "loaded", session: null };
obj4[1] = closure_1_2;
let tmp61 = null != closure_1_2;
if (tmp61) {
tmp61 = uuid !== uuid.uuid;
}
if (tmp61) {
tmp61 = flag;
}
if (tmp61) {
socket = socket.getSocket();
if (socket != null) {
({ createdAtTimestamp, uuid } = uuid);
let result = socket.handleUpdateTimeSpentSessionId(createdAtTimestamp, uuid, callback(closure_1_2[18]).clientLaunchId);
}
}
c7 = 3;
obj5 = { value: null, done: true };
obj5[0] = closure_1_2;
return obj5;
} else if (arg0 === 1) {
c7 = 3;
throw arg1;
} else if (arg0 !== 2) {
callback2(arg1);
}
socket = 0;
c7 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
}
} catch (tmp81) {
closure_5 = tmp81;
if (tmp4 === socket) {
c7 = tmp2;
throw tmp81;
} else {
c6 = tmp;
}
}
}
})();
iter.next();
return iter;
});
closure_39 = tmp;
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
}
let c5 = importDefaultResult;
({ AnalyticEvents: closure_8, AppStates: c9, RTCConnectionStates: c10 } = ME);
let closure_11 = 15 * setDefault.Millis.MINUTE;
const SECOND = setDefault.Millis.SECOND;
const LAST_CLIENT_HEARTBEAT_SESSION = "LAST_CLIENT_HEARTBEAT_SESSION";
const user = "user";
let closure_15 = new timestampDefault("SessionHeartbeatScheduler");
let c16 = null;
let c17 = null;
let c18 = 0;
let c19 = 0;
let closure_20 = { state: "uninitialized" };
let state = importDefaultResult1.getState();
let closure_22 = isForegrounded.isForegrounded();
let closure_23 = isActiveUserRoute.isActiveUserRoute();
let token = importDefaultResult.getToken();
const tmp3 = new timestampDefault("SessionHeartbeatScheduler");
let result = require("set").fileFinishedImporting("modules/analytics_sessions/SessionHeartbeatScheduler.tsx");
export const initSessionHeartbeatScheduler = function initSessionHeartbeatScheduler() {
let obj = _modDef1205;
obj.addBreadcrumb({ message: "Initializing SessionHeartbeatScheduler" });
importDefaultResult1.addChangeListener(handleRTCStateChange);
importDefaultResult.addChangeListener(handleAuthenticationChange);
const subscription = dispatcherDefault.subscribe("WINDOW_FOCUS", handleWindowFocus);
let obj2 = dispatcherDefault;
const tmp = importDefault;
const subscription1 = dispatcherDefault.subscribe("APP_STATE_UPDATE", handleAppStateUpdate);
let obj3 = dispatcherDefault;
const subscription2 = dispatcherDefault.subscribe("CONNECTION_OPEN", forceDispatchSessionIdUpdate);
const obj4 = dispatcherDefault;
let result = isActiveUserRoute2.subscribeToLocationChanges(handleLocationChange);
scheduleHeartbeatTracking();
if (null == obj) {
obj = { id: null, type: "interval" };
const _setInterval = setInterval;
obj[0] = setInterval(() => {
let result = null != closure_24;
if (result) {
result = callback(7403).shouldLogClientHeartbeatSkipped();
obj = callback(7403);
}
if (result) {
if (obj2.monotonicNowMs() - closure_19 > closure_11) {
callback2(695).track(constants.CLIENT_HEARTBEAT_SKIPPED, { client_heartbeat_version: 31 });
const obj3 = callback2(695);
}
obj2 = callback(7398);
}
}, closure_11);
}
const initialized = initializeDefault.initialized;
initialized.then(handleFluxInitialized);
};
export { getSession };
export const getActiveSessionUnsafe = function getActiveSessionUnsafe() {
if ("uninitialized" === closure_20.state) {
const Storage = Storage2.Storage;
const value = Storage.get(LAST_CLIENT_HEARTBEAT_SESSION);
let tmp7 = null;
if (null != value) {
let tmp8 = value;
if (value.version !== tmp2(7405).CLIENT_SESSION_STORAGE_VERSION) {
const _HermesInternal = HermesInternal;
logger.warn("Throwing away client session with invalid version: " + value.version + ", expected " + tmp2(7405).CLIENT_SESSION_STORAGE_VERSION);
tmp8 = null;
}
tmp7 = tmp8;
}
let session = tmp7;
} else {
session = closure_20.session;
}
let tmp12 = null;
if (null != session) {
tmp12 = null;
if (!obj.isSessionExpired(session)) {
tmp12 = session;
}
obj = result2;
}
return tmp12;
};