253 lines
9.9 KiB
TypeScript
253 lines
9.9 KiB
TypeScript
// Metro module 10609 (f10610).
|
|
import { NativeEventEmitter } from "react-native";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import RTCConnectionStore from "../../../stores/RTCConnectionStore";
|
|
import EmbeddedActivitiesStore from "../EmbeddedActivitiesStore";
|
|
import { DISALLOWED_NAVIGATION_ERROR_CLOSE_ACTIVITY } from "../Constants";
|
|
import { AnalyticEvents, ComponentActions } from "../../../Constants";
|
|
import { getWebViewProxy } from "../../../_bundle/Module6759";
|
|
import { isAndroid } from "../../../utils/PlatformUtils";
|
|
import Module10610 from "../../../_bundle/Module10610";
|
|
import getPostMessageJavaScript from "./getPostMessageJavaScript";
|
|
import SentryUtils_native from "../../../utils/SentryUtils.native";
|
|
import EmbeddedActivitiesManager from "../EmbeddedActivitiesManager";
|
|
import WebViewPostMessageTransport from "../../rpc/native/server/transports/WebViewPostMessageTransport";
|
|
import AlertActionCreators from "../../../actions/native/AlertActionCreators";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import ThermalUtils_native from "../../device/ThermalUtils.native";
|
|
import { getEmbeddedActivityLocationChannelId } from "../utils/embeddedActivityLocationUtils";
|
|
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
|
|
import Dispatcher from "../../../Dispatcher";
|
|
import { getThermalState, ThermalStates } from "../../device/useThermalState";
|
|
import { requestRespondToSeriousThermalState, stopEmbeddedActivity } from "../EmbeddedActivitiesActionCreators";
|
|
import ToastActionCreators from "../../toast/native/ToastActionCreators";
|
|
import Module10356 from "../../../_bundle/Module10356";
|
|
import { ComponentDispatch } from "../../../utils/ComponentDispatchUtils";
|
|
import { isNotNullish } from "../../../utils/GlobalUtils";
|
|
import { v4 } from "../../../_bundle/Module514";
|
|
import { HermesBuiltin } from "../../../_hermes/prelude";
|
|
let webViewProxy, c7117_11, prototype, EmbeddedActivitiesNativeManager;
|
|
const postMessageToWebView = async function postMessageToWebView(c26712_0) {
|
|
let c26712_3;
|
|
let c26712_4 = 0;
|
|
let c30240_0;
|
|
L10: {
|
|
try {
|
|
c26712_4 = 1;
|
|
await webViewProxy.injectJavaScript(getPostMessageJavaScript(c26712_0));
|
|
c26712_4 = 0;
|
|
} catch ($e) {
|
|
const r24 = $e;
|
|
let r8 = r24;
|
|
c26712_3 = r24;
|
|
if (c26712_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r55 = c26712_3;
|
|
c26712_4 = 0;
|
|
c30240_0 = r55;
|
|
SentryUtils_native.captureException(c30240_0);
|
|
break L10;
|
|
} catch (r51) {
|
|
r8 = r51;
|
|
c26712_3 = r51;
|
|
if (c26712_4 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
}
|
|
};
|
|
webViewProxy = getWebViewProxy("EMBEDDED_ACTIVITY_WEB_VIEW_KEY");
|
|
c7117_11 = isAndroid() ? new NativeEventEmitter(Module10610) : null;
|
|
const EmbeddedActivitiesNativeManager2 = class EmbeddedActivitiesNativeManager extends EmbeddedActivitiesManager {
|
|
handleRPCDisconnect = ({ reason, application }) => {
|
|
const connectedActivityLocation = EmbeddedActivitiesStore.getConnectedActivityLocation();
|
|
const id = application?.id;
|
|
this.leaveActivity({
|
|
location: connectedActivityLocation,
|
|
applicationId: id
|
|
});
|
|
this.superHandleRPCDisconnect({
|
|
reason,
|
|
application
|
|
});
|
|
};
|
|
_initialize() {
|
|
Reflect.get(Object.getPrototypeOf(prototype), "_initialize", this).call(this);
|
|
const lifecycleSubscription = this.lifecycleSubscription;
|
|
if (lifecycleSubscription != null) {
|
|
lifecycleSubscription.remove();
|
|
}
|
|
this.lifecycleSubscription = c7117_11 == null ? void 0 : c7117_11.addListener("onHostDestroy", () => {
|
|
const connectedActivityLocation = EmbeddedActivitiesStore.getConnectedActivityLocation();
|
|
const r5 = connectedActivityLocation != null ? EmbeddedActivitiesStore.getSelfEmbeddedActivityForLocation(connectedActivityLocation) : null;
|
|
if (r5 != null && connectedActivityLocation != null) {
|
|
this.leaveActivity({
|
|
location: connectedActivityLocation,
|
|
applicationId: r5.applicationId
|
|
});
|
|
}
|
|
});
|
|
const scriptMessageSubscription = this.scriptMessageSubscription;
|
|
if (scriptMessageSubscription != null) {
|
|
scriptMessageSubscription.remove();
|
|
}
|
|
this.scriptMessageSubscription = webViewProxy.addOnMessageListener((a0) => {
|
|
try {
|
|
const r11 = JSON.parse(a0.data);
|
|
const connectedActivityLocation = EmbeddedActivitiesStore.getConnectedActivityLocation();
|
|
const url = (connectedActivityLocation != null ? EmbeddedActivitiesStore.getSelfEmbeddedActivityForLocation(connectedActivityLocation) : null)?.url;
|
|
if (typeof r11 === "object" ? url != null : typeof r11 === "object") {
|
|
WebViewPostMessageTransport.handleMessage(r11, url, postMessageToWebView);
|
|
}
|
|
} catch (r33) {
|
|
if (!(r33 instanceof SyntaxError)) {
|
|
throw r33;
|
|
}
|
|
if (a0.data === DISALLOWED_NAVIGATION_ERROR_CLOSE_ACTIVITY) {
|
|
const connectedActivityLocation2 = EmbeddedActivitiesStore.getConnectedActivityLocation();
|
|
const applicationId = connectedActivityLocation2 != null ? EmbeddedActivitiesStore.getSelfEmbeddedActivityForLocation(connectedActivityLocation2)?.applicationId : void 0;
|
|
if (connectedActivityLocation2 != null && applicationId != null) {
|
|
this.leaveActivity({
|
|
location: connectedActivityLocation2,
|
|
applicationId,
|
|
showFeedback: false
|
|
});
|
|
AlertActionCreators.show({
|
|
body: intl.string(t.tYBBWz),
|
|
confirmText: intl.string(t.BddRzS)
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
const thermalStateSubscription = this.thermalStateSubscription;
|
|
if (thermalStateSubscription != null) {
|
|
thermalStateSubscription.remove();
|
|
}
|
|
this.thermalStateSubscription = ThermalUtils_native.addListener(({ rawThermalState }) => {
|
|
const connectedActivityLocation = EmbeddedActivitiesStore.getConnectedActivityLocation();
|
|
const r6 = connectedActivityLocation != null ? EmbeddedActivitiesStore.getSelfEmbeddedActivityForLocation(connectedActivityLocation) : null;
|
|
const embeddedActivityLocationChannelId = getEmbeddedActivityLocationChannelId(connectedActivityLocation);
|
|
const basicChannel = ChannelStore.getBasicChannel(embeddedActivityLocationChannelId);
|
|
const compositeInstanceId = r6?.compositeInstanceId;
|
|
const applicationId = r6?.applicationId;
|
|
AnalyticsUtils.track(AnalyticEvents.ACTIVITY_DEVICE_THERMAL_STATE_CHANGED, {
|
|
channel_id: embeddedActivityLocationChannelId,
|
|
application_id: applicationId,
|
|
activity_session_id: compositeInstanceId,
|
|
thermal_state: rawThermalState,
|
|
guild_id: basicChannel?.guild_id,
|
|
media_session_id: RTCConnectionStore.getMediaSessionId()
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "THERMAL_STATE_CHANGE",
|
|
applicationId
|
|
});
|
|
const thermalState = getThermalState();
|
|
if (compositeInstanceId != null && applicationId != null && thermalState >= ThermalStates.SERIOUS) {
|
|
requestRespondToSeriousThermalState();
|
|
}
|
|
});
|
|
}
|
|
_terminate() {
|
|
Reflect.get(Object.getPrototypeOf(prototype), "_terminate", this).call(this);
|
|
const lifecycleSubscription = this.lifecycleSubscription;
|
|
if (lifecycleSubscription != null) {
|
|
lifecycleSubscription.remove();
|
|
}
|
|
const scriptMessageSubscription = this.scriptMessageSubscription;
|
|
if (scriptMessageSubscription != null) {
|
|
scriptMessageSubscription.remove();
|
|
}
|
|
const thermalStateSubscription = this.thermalStateSubscription;
|
|
if (thermalStateSubscription != null) {
|
|
thermalStateSubscription.remove();
|
|
}
|
|
}
|
|
showErrorModal({ code, message }) {
|
|
AlertActionCreators.show({
|
|
title: intl.formatToPlainString(t.hbiAO6, {
|
|
code
|
|
}),
|
|
body: message
|
|
});
|
|
}
|
|
showLaunchErrorModal(a0) {
|
|
AlertActionCreators.show({
|
|
title: intl.string(t.PtobXW),
|
|
body: a0
|
|
});
|
|
}
|
|
showDevShelfOverrideEnabled() {
|
|
ToastActionCreators.open({
|
|
key: "EMBEDDED_ACTIVITIES_DEV_SHELF_URL_OVERRIDE_ENABLED",
|
|
content: intl.string(t.JfA7IK),
|
|
icon: Module10356,
|
|
iconColor: "status-positive"
|
|
});
|
|
}
|
|
releaseWebView() {
|
|
const id = this.releaseFrameId();
|
|
if (id != null) {
|
|
ComponentDispatch.dispatch(ComponentActions.IFRAME_UNMOUNT, {
|
|
id
|
|
});
|
|
webViewProxy.releaseWebView();
|
|
}
|
|
return id;
|
|
}
|
|
leaveActivity({ location: location2, applicationId, showFeedback }) {
|
|
const r11 = this.releaseWebView();
|
|
if (location2 != null && isNotNullish(applicationId)) {
|
|
this.clearEmbeddedActivityState(location2, applicationId, r11 != null && showFeedback);
|
|
}
|
|
}
|
|
hidePIPEmbed(a0) {
|
|
if (a0 == null) {
|
|
HermesBuiltin.throwTypeError("Cannot destructure 'undefined' or 'null'.");
|
|
throw new Error("unreachable");
|
|
}
|
|
}
|
|
clearEmbeddedActivityState(a0, a1, a2) {
|
|
stopEmbeddedActivity({
|
|
location: a0,
|
|
applicationId: a1,
|
|
showFeedback: a2
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "EMBEDDED_ACTIVITY_SET_ORIENTATION_LOCK_STATE",
|
|
applicationId: a1,
|
|
lockState: null,
|
|
pictureInPictureLockState: null
|
|
});
|
|
}
|
|
releaseFrameId() {
|
|
const frameId = this.frameId;
|
|
this.frameId = void 0;
|
|
return frameId;
|
|
}
|
|
hasFrameId() {
|
|
return this.frameId != null;
|
|
}
|
|
getOrCreateFrameId() {
|
|
const frameId = this.frameId;
|
|
if (frameId != null) {
|
|
return frameId;
|
|
}
|
|
const frameId2 = v4();
|
|
this.frameId = frameId2;
|
|
return frameId2;
|
|
}
|
|
};
|
|
const prototype2 = EmbeddedActivitiesNativeManager2.prototype;
|
|
EmbeddedActivitiesNativeManager = EmbeddedActivitiesNativeManager2;
|
|
prototype = prototype2;
|
|
const embeddedActivitiesNativeManager = new EmbeddedActivitiesNativeManager();
|
|
export default embeddedActivitiesNativeManager;
|
|
export const EMBEDDED_ACTIVITY_WEB_VIEW_KEY = "EMBEDDED_ACTIVITY_WEB_VIEW_KEY";
|