decord/stable/source/modules/analytics_sessions/SessionAdManager.tsx
github-actions e2bc0408ee chore: update source for stable 346.13
Skipped 1 file(s) >100MB (GitHub limit): source/__polyfill/04xxx/module_4821.js (118.4 MB)
2026-09-22 22:11:40 +00:00

152 lines
7.2 KiB
TypeScript

// Module ID: 14636
// Function ID: 14637
// Name: SessionAdManager
// Dependencies: [502, 1074, 1898, 7565, 1952, 573, 1090, 1230, 7823, 1240, 2]
// Module 14636 (SessionAdManager)
import DispatcherDefault from "Dispatcher" /* 573 */;
import DurationsDefault from "Durations" /* 1090 */;
import SentryUtilsDefault from "SentryUtils" /* 1230 */;
import AnalyticsUtilsDefault from "AnalyticsUtils" /* 1240 */;
import Timers from "Timers" /* 1952 */;
import SessionForegroundUtils from "SessionForegroundUtils" /* 7565 */;
import SessionAdGenerator from "SessionAdGenerator" /* 7823 */;
import AuthenticationStore from "AuthenticationStore" /* 502 */;
import LifecycleManager from "LifecycleManager" /* 1898 */;
require = fn;
const Constants = fn(1074);
({ AnalyticEvents: closure_4, AppStates: hasOwnProperty } = Constants);
const ad = "ad";
let token = AuthenticationStore.getToken();
let closure_8 = { DEFAULT: "DEFAULT", USER_LOGOUT: "USER_LOGOUT", WINDOW_FOCUS: "WINDOW_FOCUS", APP_STATE_UPDATE: "APP_STATE_UPDATE" };
class SessionAdManager extends tmp3 {
constructor() {
applyArgumentsResult = HermesBuiltin.applyArguments(new.target, new.target);
closure_0 = applyArgumentsResult;
obj = closure_0(closure_2[3]);
applyArgumentsResult.focusedOrForegrounded = obj.isForegrounded();
interval = new closure_0(closure_2[4]).Interval();
applyArgumentsResult.heartbeatInterval = interval;
applyArgumentsResult.schedulerStarted = false;
applyArgumentsResult.lastHeartbeatTimestamp = 0;
applyArgumentsResult.maybeStartHeartbeat = function maybeStartHeartbeat() {
const heartbeatInterval = applyArgumentsResult.heartbeatInterval;
if (!heartbeatInterval.isStarted()) {
obj.trackHeartbeat();
const heartbeatInterval2 = obj.heartbeatInterval;
heartbeatInterval2.start(5 * DurationsDefault.Millis.MINUTE, obj.trackHeartbeat);
}
};
applyArgumentsResult.startAnalyticHeartbeat = function startAnalyticHeartbeat() {
if (!applyArgumentsResult.schedulerStarted) {
obj.schedulerStarted = true;
const obj3 = { category: ad, message: "Starting ad session heartbeat" };
SentryUtilsDefault.addBreadcrumb(obj3);
obj.maybeStartHeartbeat();
}
};
applyArgumentsResult.trackHeartbeat = function trackHeartbeat() {
let flag = arg0;
if (arg0 === undefined) {
flag = false;
}
if (!applyArgumentsResult.schedulerStarted) {
if (!flag) {
const obj2 = { category: ad, message: "Ad heartbeat called but scheduler not started" };
SentryUtilsDefault.addBreadcrumb(obj2);
const heartbeatInterval = tmp.heartbeatInterval;
heartbeatInterval.stop();
}
}
const nowResult = performance.now();
const diff = nowResult - tmp.lastHeartbeatTimestamp;
const orRefreshAdSession = SessionAdGenerator.getOrRefreshAdSession();
AnalyticsUtilsDefault.track(constants.CLIENT_AD_HEARTBEAT, { client_ad_session_id: orRefreshAdSession.uuid, client_heartbeat_initialization_timestamp: orRefreshAdSession.createdAtTimestamp, client_heartbeat_version: 3 });
applyArgumentsResult.lastHeartbeatTimestamp = nowResult;
};
applyArgumentsResult.stopAnalyticHeartbeat = function stopAnalyticHeartbeat(DEFAULT) {
if (DEFAULT === undefined) {
DEFAULT = constants.DEFAULT;
}
if (applyArgumentsResult.schedulerStarted) {
tmp2.schedulerStarted = false;
tmp2.lastHeartbeatTimestamp = 0;
const obj2 = { category: ad, message: null };
const _HermesInternal = HermesInternal;
obj2.message = "Stopping ad session heartbeat: " + DEFAULT;
SentryUtilsDefault.addBreadcrumb(obj2);
const heartbeatInterval = tmp2.heartbeatInterval;
heartbeatInterval.stop();
}
};
applyArgumentsResult.scheduleHeartbeatTracking = function scheduleHeartbeatTracking(DEFAULT) {
if (DEFAULT === undefined) {
DEFAULT = constants.DEFAULT;
}
if (applyArgumentsResult.focusedOrForegrounded) {
if (null != token) {
try {
const result = obj.startAnalyticHeartbeat();
} catch (tmp7) {
SentryUtilsDefault.captureException(tmp7);
}
}
}
const result1 = obj.stopAnalyticHeartbeat(DEFAULT);
};
applyArgumentsResult.handleLogin = function handleLogin() {
const result = applyArgumentsResult.scheduleHeartbeatTracking();
applyArgumentsResult.trackHeartbeat(true);
};
applyArgumentsResult.handleLogout = function handleLogout() {
const result = applyArgumentsResult.stopAnalyticHeartbeat(constants.USER_LOGOUT);
SessionAdGenerator.clearAdSession();
};
applyArgumentsResult.handleEnrollmentSuccess = function handleEnrollmentSuccess() {
const orRefreshAdSession = applyArgumentsResult(dependencyMap[8]).getOrRefreshAdSession(true);
};
applyArgumentsResult.handleWindowFocus = function handleWindowFocus(focused) {
applyArgumentsResult.focusedOrForegrounded = focused.focused;
const result = applyArgumentsResult.scheduleHeartbeatTracking(constants.WINDOW_FOCUS);
};
applyArgumentsResult.handleAppStateUpdate = function handleAppStateUpdate(state) {
applyArgumentsResult.focusedOrForegrounded = state.state === constants2.ACTIVE;
const result = applyArgumentsResult.scheduleHeartbeatTracking(constants.APP_STATE_UPDATE);
};
applyArgumentsResult.handleAuthenticationChange = function handleAuthenticationChange() {
token = AuthenticationStore.getToken();
if (token !== token) {
SessionAdGenerator.clearAdSession();
const result = applyArgumentsResult.stopAnalyticHeartbeat();
}
const result1 = applyArgumentsResult.scheduleHeartbeatTracking();
};
return applyArgumentsResult;
}
}
const prototype = SessionAdManager.prototype;
prototype["_initialize"] = function _initialize() {
this.focusedOrForegrounded = SessionForegroundUtils.isForegrounded();
AuthenticationStore.addChangeListener(this.handleAuthenticationChange);
const subscription = DispatcherDefault.subscribe("WINDOW_FOCUS", this.handleWindowFocus);
const subscription1 = DispatcherDefault.subscribe("APP_STATE_UPDATE", this.handleAppStateUpdate);
const subscription2 = DispatcherDefault.subscribe("QUESTS_ENROLL_SUCCESS", this.handleEnrollmentSuccess);
const subscription3 = DispatcherDefault.subscribe("LOGIN_SUCCESS", this.handleLogin);
const subscription4 = DispatcherDefault.subscribe("LOGOUT", this.handleLogout);
const result = this.scheduleHeartbeatTracking();
};
prototype["_terminate"] = function _terminate() {
const result = this.stopAnalyticHeartbeat();
AuthenticationStore.removeChangeListener(this.handleAuthenticationChange);
DispatcherDefault.unsubscribe("WINDOW_FOCUS", this.handleWindowFocus);
DispatcherDefault.unsubscribe("APP_STATE_UPDATE", this.handleAppStateUpdate);
DispatcherDefault.unsubscribe("QUESTS_ENROLL_SUCCESS", this.handleEnrollmentSuccess);
DispatcherDefault.unsubscribe("LOGIN_SUCCESS", this.handleLogin);
DispatcherDefault.unsubscribe("LOGOUT", this.handleLogout);
};
const sessionAdManager = new SessionAdManager();
const size = fn(2);
let result = size.fileFinishedImporting("modules/analytics_sessions/SessionAdManager.tsx");
export default sessionAdManager;