decord/source/modules/activities/native/EmbeddedActivitiesNativeManager.tsx

349 lines
14 KiB
TypeScript
Raw Normal View History

// Module ID: 9444
// Function ID: 9445
2026-07-29 08:29:29 +00:00
// Name: postMessageToWebView
// Dependencies: [5, 17, 1386, 4557, 1385, 4509, 673, 4383, 8228, 1234, 9445, 9446, 1205, 9447, 9479, 4866, 1233, 9450, 4110, 695, 706, 9494, 9433, 4194, 9495, 1228, 1394, 511, 2]
2026-07-20 16:05:17 +00:00
// Module 9444 (postMessageToWebView)
2026-09-02 09:53:35 +00:00
import v1 from "v1" /* 511 */;
import dispatcherDefault from "dispatcher" /* 706 */;
import ComponentDispatcher from "ComponentDispatcher" /* 1228 */;
import getSystemLocale from "getSystemLocale" /* 1233 */;
import isDiscordFrontendDevelopment from "isDiscordFrontendDevelopment" /* 1394 */;
2026-09-01 10:26:29 +00:00
import dispatcherDefault2 from "dispatcher" /* 4194 */;
import _modDef4866 from "module_4866" /* 4866 */;
import _runPrimaryAppCommandOrJoinEmbeddedActivity from "_runPrimaryAppCommandOrJoinEmbeddedActivity" /* 9433 */;
import enforcingDefault from "enforcing" /* 9445 */;
import getShelfItemTrackingPropertiesDefault from "getShelfItemTrackingProperties" /* 9447 */;
import NativeModulesDefault from "NativeModules" /* 9450 */;
import registerAssetDefault from "registerAsset" /* 9495 */;
2026-08-24 06:08:38 +00:00
import closure_3 from "asyncGeneratorStep" /* 5 */;
2026-09-02 09:53:35 +00:00
import closure_4 from "ensureGuildLoaded" /* 1386 */;
import closure_5 from "createRTCConnection" /* 4557 */;
2026-09-02 09:53:35 +00:00
import closure_6 from "participantFromServer" /* 1385 */;
import { DISALLOWED_NAVIGATION_ERROR_CLOSE_ACTIVITY as closure_7 } from "items3" /* 4509 */;
2026-09-02 09:53:35 +00:00
import ME from "ME" /* 673 */;
import { TransportTypes } from "RPC_SCOPE_CONFIG" /* 4383 */;
import WebView from "WebView" /* 8228 */;
2026-09-02 09:53:35 +00:00
import set from "set" /* 1234 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-20 16:05:17 +00:00
function postMessageToWebView() {
2026-07-29 08:29:29 +00:00
const self = this;
const apply = _postMessageToWebView.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
function _postMessageToWebView() {
2026-07-29 08:29:29 +00:00
const self = this;
const tmp = callback((arg0) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
c5 = 0;
c6 = 0;
c4 = 0;
2026-07-29 08:29:29 +00:00
return (function*(arg0) {
2026-08-04 21:03:28 +00:00
const table = tmp3;
2026-08-24 06:08:38 +00:00
c4 = 1;
yield closure_1_11.injectJavaScript(closure_1_1(closure_1_2[11])(closure_0));
2026-08-04 21:03:28 +00:00
if (1 === tmp7) {
c4 = 0;
2026-08-24 06:08:38 +00:00
closure_0 = closure_3;
obj1 = callback(table[12]);
2026-08-04 21:03:28 +00:00
obj1.captureException(closure_0);
2026-08-24 06:08:38 +00:00
c6 = 3;
2026-08-04 21:03:28 +00:00
} else if (arg0 === 1) {
2026-07-29 08:29:29 +00:00
c6 = 3;
2026-08-04 21:03:28 +00:00
throw arg1;
} else if (arg0 !== 2) {
c4 = 0;
2026-07-29 08:29:29 +00:00
}
2026-08-04 21:03:28 +00:00
c4 = 0;
return arg1;
2026-07-29 08:29:29 +00:00
})();
});
2026-08-24 06:08:38 +00:00
closure_14 = tmp;
2026-07-29 08:29:29 +00:00
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
({ AnalyticEvents: closure_8, ComponentActions: c9 } = ME);
2026-07-23 10:11:24 +00:00
const webViewProxy = WebView.getWebViewProxy("EMBEDDED_ACTIVITY_WEB_VIEW_KEY");
2026-07-20 16:05:17 +00:00
let nativeEventEmitter = null;
2026-07-23 10:11:24 +00:00
if (set.isAndroid()) {
2026-08-24 06:08:38 +00:00
nativeEventEmitter = new require("get ActivityIndicator").NativeEventEmitter(enforcingDefault);
2026-07-29 08:29:29 +00:00
}
2026-08-24 06:08:38 +00:00
getShelfItemTrackingPropertiesDefault;
2026-07-29 08:29:29 +00:00
class EmbeddedActivitiesNativeManager extends tmp6 {
constructor() {
applyArgumentsResult = HermesBuiltin.applyArguments(new.target, new.target);
closure_0 = applyArgumentsResult;
applyArgumentsResult.handleRPCDisconnect = function handleRPCDisconnect(reason) {
const application = reason.application;
let id;
2026-08-24 06:08:38 +00:00
const connectedActivityLocation = closure_1_6.getConnectedActivityLocation();
2026-07-29 08:29:29 +00:00
if (application != null) {
id = application.id;
}
applyArgumentsResult.leaveActivity({ location: connectedActivityLocation, applicationId: id });
const result = applyArgumentsResult.superHandleRPCDisconnect({ reason: reason.reason, application });
};
return applyArgumentsResult;
}
_initialize() {
self = this;
self = this;
_initializeResult = super._initialize();
lifecycleSubscription = this.lifecycleSubscription;
if (lifecycleSubscription != null) {
removeResult = lifecycleSubscription.remove();
}
2026-08-24 06:08:38 +00:00
obj = closure_12;
2026-07-29 08:29:29 +00:00
addListenerResult = undefined;
2026-08-24 06:08:38 +00:00
if (closure_12 != null) {
2026-07-29 08:29:29 +00:00
str = "onHostDestroy";
addListenerResult = obj.addListener("onHostDestroy", () => {
2026-08-24 06:08:38 +00:00
let obj = closure_1_6;
const connectedActivityLocation = closure_1_6.getConnectedActivityLocation();
2026-07-29 08:29:29 +00:00
let selfEmbeddedActivityForLocation = null;
if (null != connectedActivityLocation) {
selfEmbeddedActivityForLocation = obj.getSelfEmbeddedActivityForLocation(connectedActivityLocation);
}
if (tmp3) {
obj = { location: null, applicationId: null };
obj[0] = connectedActivityLocation;
obj[1] = selfEmbeddedActivityForLocation.applicationId;
self.leaveActivity(obj);
}
});
}
self.lifecycleSubscription = addListenerResult;
scriptMessageSubscription = self.scriptMessageSubscription;
if (scriptMessageSubscription != null) {
removeResult1 = scriptMessageSubscription.remove();
}
2026-08-24 06:08:38 +00:00
self.scriptMessageSubscription = closure_11.addOnMessageListener((data) => {
2026-07-29 08:29:29 +00:00
try {
const _JSON = JSON;
const parsed = JSON.parse(data.data);
2026-08-24 06:08:38 +00:00
const connectedActivityLocation = closure_1_6.getConnectedActivityLocation();
2026-07-29 08:29:29 +00:00
let selfEmbeddedActivityForLocation = null;
if (null != connectedActivityLocation) {
2026-08-24 06:08:38 +00:00
selfEmbeddedActivityForLocation = closure_1_6.getSelfEmbeddedActivityForLocation(connectedActivityLocation);
2026-07-29 08:29:29 +00:00
}
if (selfEmbeddedActivityForLocation != null) {
const url = selfEmbeddedActivityForLocation.url;
}
2026-08-04 08:36:32 +00:00
const iframeId = self.iframeId;
2026-08-04 21:03:28 +00:00
let tmp14 = typeof parsed === "object";
if (typeof parsed === "object") {
2026-08-04 08:36:32 +00:00
tmp14 = null != tmp11;
2026-07-29 08:29:29 +00:00
}
2026-08-04 08:36:32 +00:00
if (tmp14) {
tmp14 = null != iframeId;
}
if (tmp14) {
2026-08-24 06:08:38 +00:00
let obj = closure_1_1(closure_1_2[14]);
2026-08-06 08:05:19 +00:00
obj = { type: null, origin: null, iframeId: null };
2026-08-24 06:08:38 +00:00
obj[0] = closure_1_10.POST_MESSAGE;
2026-08-06 08:05:19 +00:00
obj[1] = url;
obj[2] = iframeId;
2026-08-24 06:08:38 +00:00
obj.handleMessage(parsed, obj, closure_1_13);
2026-07-29 08:29:29 +00:00
}
2026-08-06 08:05:19 +00:00
} catch (tmp22) {
2026-07-29 08:29:29 +00:00
const _SyntaxError = SyntaxError;
2026-08-06 08:05:19 +00:00
if (tmp22 instanceof SyntaxError) {
2026-08-24 06:08:38 +00:00
if (tmp2.data === closure_1_7) {
const connectedActivityLocation1 = closure_1_6.getConnectedActivityLocation();
2026-07-29 08:29:29 +00:00
if (null != connectedActivityLocation1) {
2026-08-24 06:08:38 +00:00
const selfEmbeddedActivityForLocation1 = closure_1_6.getSelfEmbeddedActivityForLocation(connectedActivityLocation1);
2026-07-29 08:29:29 +00:00
let applicationId;
if (selfEmbeddedActivityForLocation1 != null) {
applicationId = selfEmbeddedActivityForLocation1.applicationId;
}
}
2026-08-06 08:05:19 +00:00
let tmp29 = null != connectedActivityLocation1;
if (tmp29) {
tmp29 = null != tmp28;
2026-07-29 08:29:29 +00:00
}
2026-08-06 08:05:19 +00:00
if (tmp29) {
2026-07-29 08:29:29 +00:00
obj = { location: null, applicationId: null, showFeedback: false };
obj[0] = connectedActivityLocation1;
2026-08-06 08:05:19 +00:00
obj[1] = tmp28;
2026-07-29 08:29:29 +00:00
self.leaveActivity(obj);
2026-08-24 06:08:38 +00:00
obj1 = { body: null, confirmText: null };
const intl = self(closure_1_2[16]).intl;
obj1[0] = intl.string(self(closure_1_2[16]).t.tYBBWz);
const intl2 = self(closure_1_2[16]).intl;
obj1[1] = intl2.string(self(closure_1_2[16]).t.BddRzS);
closure_1_1(closure_1_2[15]).show(obj1);
const obj4 = closure_1_1(closure_1_2[15]);
2026-07-29 08:29:29 +00:00
}
}
} else {
2026-08-06 08:05:19 +00:00
throw tmp22;
2026-07-29 08:29:29 +00:00
}
}
});
thermalStateSubscription = self.thermalStateSubscription;
if (thermalStateSubscription != null) {
removeResult2 = thermalStateSubscription.remove();
}
obj2 = require("NativeModules");
self.thermalStateSubscription = obj2.addListener((rawThermalState) => {
let obj = connectedActivityLocation;
connectedActivityLocation = connectedActivityLocation.getConnectedActivityLocation();
let selfEmbeddedActivityForLocation = null;
if (null != connectedActivityLocation) {
selfEmbeddedActivityForLocation = obj.getSelfEmbeddedActivityForLocation(connectedActivityLocation);
}
2026-08-06 08:05:19 +00:00
const embeddedActivityLocationChannelId = self(table[18]).getEmbeddedActivityLocationChannelId(connectedActivityLocation);
2026-07-29 08:29:29 +00:00
basicChannel = basicChannel.getBasicChannel(embeddedActivityLocationChannelId);
let compositeInstanceId;
if (selfEmbeddedActivityForLocation != null) {
compositeInstanceId = selfEmbeddedActivityForLocation.compositeInstanceId;
}
let applicationId;
if (selfEmbeddedActivityForLocation != null) {
applicationId = selfEmbeddedActivityForLocation.applicationId;
}
2026-08-06 08:05:19 +00:00
const obj2 = self(table[18]);
2026-07-29 08:29:29 +00:00
const tmp9 = callback;
obj = { channel_id: embeddedActivityLocationChannelId, application_id: applicationId, activity_session_id: compositeInstanceId, thermal_state: rawThermalState.rawThermalState, guild_id: null, media_session_id: null };
let guild_id;
if (basicChannel != null) {
guild_id = basicChannel.guild_id;
}
obj[4] = guild_id;
obj[5] = mediaSessionId.getMediaSessionId();
2026-08-06 08:05:19 +00:00
callback(table[19]).track(constants.ACTIVITY_DEVICE_THERMAL_STATE_CHANGED, obj);
const obj3 = callback(table[19]);
tmp9(table[20]).dispatch({ type: "THERMAL_STATE_CHANGE", applicationId });
let tmp3Result = tmp3(tmp4[21]);
2026-07-29 08:29:29 +00:00
let tmp14 = null != compositeInstanceId;
const thermalState = tmp3Result.getThermalState();
if (tmp14) {
tmp14 = null != applicationId;
}
if (tmp14) {
2026-08-06 08:05:19 +00:00
tmp14 = thermalState >= tmp3(tmp4[21]).ThermalStates.SERIOUS;
2026-07-29 08:29:29 +00:00
}
if (tmp14) {
2026-08-06 08:05:19 +00:00
tmp3Result = tmp3(tmp4[22]);
2026-07-29 08:29:29 +00:00
const respondToSeriousThermalState = tmp3Result.requestRespondToSeriousThermalState();
}
});
return;
}
_terminate() {
self = this;
_terminateResult = super._terminate();
lifecycleSubscription = this.lifecycleSubscription;
if (lifecycleSubscription != null) {
removeResult = lifecycleSubscription.remove();
}
scriptMessageSubscription = self.scriptMessageSubscription;
if (scriptMessageSubscription != null) {
removeResult1 = scriptMessageSubscription.remove();
}
thermalStateSubscription = self.thermalStateSubscription;
if (thermalStateSubscription != null) {
removeResult2 = thermalStateSubscription.remove();
}
return;
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const prototype = EmbeddedActivitiesNativeManager.prototype;
prototype["showErrorModal"] = function showErrorModal(reason, id) {
({ code, message } = reason);
let obj = _modDef4866;
2026-07-29 08:29:29 +00:00
obj = { title: null, body: null };
2026-08-24 06:08:38 +00:00
const intl = getSystemLocale.intl;
obj[0] = intl.formatToPlainString(getSystemLocale.t.hbiAO6, { code });
2026-07-29 08:29:29 +00:00
obj[1] = message;
obj.show(obj);
};
prototype["showLaunchErrorModal"] = function showLaunchErrorModal(message) {
let obj = _modDef4866;
2026-07-29 08:29:29 +00:00
obj = { title: null, body: null };
2026-08-24 06:08:38 +00:00
const intl = getSystemLocale.intl;
obj[0] = intl.string(getSystemLocale.t.PtobXW);
2026-07-29 08:29:29 +00:00
obj[1] = message;
obj.show(obj);
};
prototype["showDevShelfOverrideEnabled"] = function showDevShelfOverrideEnabled() {
2026-08-24 06:08:38 +00:00
let obj = dispatcherDefault2;
2026-07-29 08:29:29 +00:00
obj = { key: "EMBEDDED_ACTIVITIES_DEV_SHELF_URL_OVERRIDE_ENABLED", content: null, icon: null, iconColor: "status-positive" };
2026-08-24 06:08:38 +00:00
const intl = getSystemLocale.intl;
obj[1] = intl.string(getSystemLocale.t.JfA7IK);
obj[2] = registerAssetDefault;
2026-07-29 08:29:29 +00:00
obj.open(obj);
};
prototype["releaseWebView"] = function releaseWebView() {
2026-08-04 08:36:32 +00:00
const releaseIframeIdResult = this.releaseIframeId();
if (null != releaseIframeIdResult) {
2026-08-24 06:08:38 +00:00
const ComponentDispatch = ComponentDispatcher.ComponentDispatch;
2026-07-29 08:29:29 +00:00
const obj = { id: null };
2026-08-04 08:36:32 +00:00
obj[0] = releaseIframeIdResult;
2026-07-29 08:29:29 +00:00
ComponentDispatch.dispatch(constants.IFRAME_UNMOUNT, obj);
2026-08-06 08:05:19 +00:00
closure_11.releaseWebView();
2026-07-29 08:29:29 +00:00
}
2026-08-04 08:36:32 +00:00
return releaseIframeIdResult;
2026-07-29 08:29:29 +00:00
};
prototype["leaveActivity"] = function leaveActivity(arg0) {
const self = this;
({ location: _location, applicationId, showFeedback } = arg0);
let isNotNullishResult = null != _location;
if (isNotNullishResult) {
2026-08-24 06:08:38 +00:00
isNotNullishResult = isDiscordFrontendDevelopment.isNotNullish(applicationId);
const obj = isDiscordFrontendDevelopment;
2026-07-29 08:29:29 +00:00
}
if (isNotNullishResult) {
let tmp5 = null != releaseWebViewResult;
if (tmp5) {
tmp5 = showFeedback;
}
const result = self.clearEmbeddedActivityState(_location, applicationId, tmp5);
}
};
prototype["hidePIPEmbed"] = function hidePIPEmbed(arg0) {
if (arg0 == null) {
HermesBuiltin.throwTypeError();
}
};
prototype["clearEmbeddedActivityState"] = function clearEmbeddedActivityState(_location, applicationId, showFeedback) {
2026-08-24 06:08:38 +00:00
let obj = _runPrimaryAppCommandOrJoinEmbeddedActivity;
2026-07-29 08:29:29 +00:00
obj = { location: _location, applicationId, showFeedback };
obj.stopEmbeddedActivity(obj);
obj = { type: "EMBEDDED_ACTIVITY_SET_ORIENTATION_LOCK_STATE", applicationId, lockState: null, pictureInPictureLockState: null };
2026-08-24 06:08:38 +00:00
dispatcherDefault.dispatch(obj);
2026-07-29 08:29:29 +00:00
};
2026-08-04 08:36:32 +00:00
prototype["releaseIframeId"] = function releaseIframeId() {
this.iframeId = undefined;
return this.iframeId;
2026-07-29 08:29:29 +00:00
};
2026-08-04 08:36:32 +00:00
prototype["hasIframeId"] = function hasIframeId() {
return null != this.iframeId;
2026-07-29 08:29:29 +00:00
};
2026-08-04 08:36:32 +00:00
prototype["getOrCreateIframeId"] = function getOrCreateIframeId() {
const iframeId = this.iframeId;
if (null != iframeId) {
return iframeId;
2026-07-29 08:29:29 +00:00
} else {
2026-08-24 06:08:38 +00:00
const v4Result = v1.v4();
2026-08-04 08:36:32 +00:00
tmp.iframeId = v4Result;
2026-07-29 08:29:29 +00:00
return v4Result;
}
};
const embeddedActivitiesNativeManager = new EmbeddedActivitiesNativeManager();
2026-07-23 10:11:24 +00:00
let result = set.fileFinishedImporting("modules/activities/native/EmbeddedActivitiesNativeManager.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default embeddedActivitiesNativeManager;
2026-07-20 16:05:17 +00:00
export const EMBEDDED_ACTIVITY_WEB_VIEW_KEY = "EMBEDDED_ACTIVITY_WEB_VIEW_KEY";