/* Metro module 25; source: modules/gateway/native/fast_connect.tsx; dependencies: [26, 27, 476, 3, 477, 479, 480, 660, 12525, 5231, 12507, 12494, 20, 14, 2] */ import TTITracker from '../../tti_analytics/TTITracker.tsx'; /* Metro dependency 14 */ import AppStartPerformance from '../../../external/discord_common/js/packages/app-start-performance/AppStartPerformance.tsx'; /* Metro dependency 20 */ import CreateWebSocketAndroid from '../createWebSocket.android.tsx'; /* Metro dependency 12494 */ import * as FileImportTrackerModule from '../../../by-id/module-00002-FileImportTracker.js'; /* Metro dependency 2 */ import * as CheckEnvModule from '../../../utils/checkEnv.tsx'; /* Metro dependency 26 */ import * as ReactNativeModule from '../../../by-id/module-00027-ReactNative.js'; /* Metro dependency 27 */ import * as KvCacheVersionConstantsModule from '../../app_database/modules/KvCacheVersionConstants.tsx'; /* Metro dependency 476 */ import * as PlatformUtilsModule from '../../../utils/PlatformUtils.tsx'; /* Metro dependency 477 */ import * as AnalyticsUtilsModule from '../../../external/discord_common/js/packages/analytics-utils/AnalyticsUtils.tsx'; /* Metro dependency 480 */ import * as GatewayCapabilitiesModule from '../GatewayCapabilities.tsx'; /* Metro dependency 12525 */ function _fun1094(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#1094, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:6, offset: 0x00c531c6, size: 291 bytes, params: 8, frame: 20 const env0_0 = require; const createFastConnectSocket2 = createFastConnectSocket; const Object = global.Object; Object.defineProperty(exports, '__esModule', {value: true}); CheckEnvModule; let value = ReactNativeModule; const env0_4 = value.NativeModules; const AppState = value.AppState; value = importDefault(3) /* metro dependency 3: Logger */; value = new value('FAST CONNECT'); value.info('initial app state (import time)', AppState.currentState); createFastConnectSocket2(); (FileImportTrackerModule).fileFinishedImporting('modules/gateway/native/fast_connect.tsx'); exports.createFastConnectSocket = createFastConnectSocket2; exports.closeFastConnectSocket = closeFastConnectSocket; exports.getLastFastConnectIdentifyUserId = getLastFastConnectIdentifyUserId; exports.identifyWebSocket = identifyWebSocket; function prepareIdentify(a0, a1, a2) { // fn#1095, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:224, offset: 0x00c532e9, size: 715 bytes, params: 4, frame: 25 var r5; var r6; var DCDFastConnectManager; var analyticsInstallation; var defaultImport; var value3; var useChannelObfuscation; var defaultImport2; var prepareIdentify; var moduleValue7; var defaultImport3; var float; var moduleValue8; const binding = env0_7; binding.info('prepareIdentify: app state: ', AppState.currentState); const value2 = undefined; if (PlatformUtilsModule.isAndroid()) { defaultImport = importDefault(479) /* metro dependency 479: NativeFastConnectModule */; analyticsInstallation = defaultImport.getConstants().analyticsInstallation; value3 = null; r5 = value3 != analyticsInstallation ? analyticsInstallation : value3; } else { r5 = NativeModules.DCDFastConnectManager.analyticsInstallation; } const object = {token: a2}; const object2 = {}; const getSuperProperties = AnalyticsUtilsModule.getSuperProperties; copyDataProperties(object2, Reflect.apply(getSuperProperties, AnalyticsUtilsModule, []), undefined); object2['client_app_state'] = AppState.currentState; object2['is_fast_connect'] = true; object2['gateway_connect_reasons'] = (importAll(660) /* metro dependency 660: RequestGatewaySocket */).describeConnectionReasons(); const value5 = null; let r3 = value5 != r5 ? {installation_id: r5} : {}; copyDataProperties(object2, r3, undefined); object.properties = object2; const getClientCapabilities = GatewayCapabilitiesModule.getClientCapabilities; if (PlatformUtilsModule.isAndroid()) { defaultImport2 = importDefault(479) /* metro dependency 479: NativeFastConnectModule */; useChannelObfuscation = defaultImport2.getConstants().useChannelObfuscation; r5 = value5 != useChannelObfuscation && useChannelObfuscation; } else { useChannelObfuscation = NativeModules.DCDFastConnectManager.useChannelObfuscation; r5 = value5 != useChannelObfuscation && useChannelObfuscation; } object.capabilities = Reflect.apply(getClientCapabilities, GatewayCapabilitiesModule, [{useChannelObfuscation: r5}]); object.client_state = {guild_versions: {}}; const JSON = global.JSON; const value8 = JSON.stringify({op: 2, d: object}); if (PlatformUtilsModule.isAndroid()) { r3 = value5 == a1 ? value2 : a1.toString(); r6 = value5 != r3 ? r3 : value5; defaultImport3 = importDefault(479) /* metro dependency 479: NativeFastConnectModule */; prepareIdentify = defaultImport3.prepareIdentify; float = global.parseFloat(a0); moduleValue8 = require(5231) /* metro dependency 5231: isCacheEnabledNative */; Reflect.apply(prepareIdentify, defaultImport3, [r6, value8, float, moduleValue8.isCacheEnabled() ? VERSION_TO_FORCE_RESYNCING_ALL_DATA : value2]); } else { DCDFastConnectManager = NativeModules.DCDFastConnectManager; prepareIdentify = DCDFastConnectManager.prepareIdentify; moduleValue7 = require(5231) /* metro dependency 5231: isCacheEnabledNative */; Reflect.apply(prepareIdentify, DCDFastConnectManager, [a1, value8, a0, moduleValue7.isCacheEnabled() ? VERSION_TO_FORCE_RESYNCING_ALL_DATA : value5]); } return object.client_state; } function createFastConnectSocket() { // fn#1096, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:1230, offset: 0x00c535b4, size: 63 bytes, params: 1, frame: 11 const WebSocket = global.window.WebSocket; if (WebSocket != null) { newWebSocket(); } else { env0_7.log('Skipping fast_connect because `window.WebSocket` does not exist.'); } function newWebSocket() { // fn#1097, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:1288, owner: createFastConnectSocket.newWebSocket, offset: 0x00c535f3, size: 599 bytes, params: 1, frame: 25 var environment; var supportsZstd; var defaultImport; var isAndroid2; var object; var onerror2; const value = environment.__proto__; if (PlatformUtilsModule.isAndroid()) { defaultImport = importDefault(12507) /* metro dependency 12507: NativeCompressionModule */; supportsZstd = defaultImport.getConstants().supportsZstd; } else { supportsZstd = NativeModules.DCDCompressionManager.supportsZstd; } const r12 = supportsZstd ? 'zstd-stream' : 'zlib-stream'; let GLOBAL_ENV = global.window.GLOBAL_ENV; const GATEWAY_ENDPOINT = GLOBAL_ENV.GATEWAY_ENDPOINT; GLOBAL_ENV = global.window.GLOBAL_ENV; const API_VERSION = GLOBAL_ENV.API_VERSION; const value4 = '' + GATEWAY_ENDPOINT + '/?encoding=json&v=' + API_VERSION + '&compress=' + r12; let binding = env1_7; binding.log('[FAST CONNECT] ' + value4); const Date = global.Date; const env0_0 = Date.now(); const value5 = (CreateWebSocketAndroid)(value4); const float = global.parseFloat(value5._socketId); if (global.isNaN(float)) { binding = env1_7; binding.log('[FAST CONNECT] Unable to create socketId from NaN value ', value5._socketId); } else { isAndroid2 = PlatformUtilsModule.isAndroid(); if (supportsZstd) { if (isAndroid2) { (importDefault(12507) /* metro dependency 12507: NativeCompressionModule */).enableZstdStreamSupport(float); } else { NativeModules.DCDCompressionManager.enableZstdStreamSupport(float, 0); } } else if (isAndroid2) { (importDefault(12507) /* metro dependency 12507: NativeCompressionModule */).enableZlibStreamSupport(float); } else { NativeModules.DCDCompressionManager.enableZlibStreamSupport(float); } object = {'open': false, 'gateway': null, 'identify': false, 'messages': null, 'clientState': null, 'userId': null}; object.gateway = value4; object.messages = []; value5.onopen = onopen; onerror2 = onerror; value5.onerror = onerror2; value5.onclose = onerror2; value5.onmessage = onmessage; global.window._ws = {ws: value5, state: object}; (importDefault(20) /* metro dependency 20: AppStartPerformance */).mark('🌐', 'Fastconnect socket created'); } function onopen() { // fn#1098, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:2035, owner: createFastConnectSocket.newWebSocket.onopen, offset: 0x00c5384a, size: 144 bytes, params: 1, frame: 19 let value = environment.__proto__.__proto__; (AppStartPerformance).mark('🌐', 'Fastconnect socket opened'); const binding = env2_7; const log = binding.log; const Date = global.Date; value = Date.now(); value -= env0_0; Reflect.apply(log, binding, ['connected and identified in ' + value + 'ms didIdentify:' + env0_1.identify]); env0_1.open = true; } function onclose() { // fn#1099, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:2202, owner: createFastConnectSocket.newWebSocket.onclose, offset: 0x00c538da, size: 65 bytes, params: 1, frame: 14 const value = environment.__proto__.__proto__; (AppStartPerformance).mark('🌐', 'Fastconnect socket close'); global.window._ws = null; } function onmessage(a0) { // fn#1100, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:2285, owner: createFastConnectSocket.newWebSocket.onmessage, offset: 0x00c5391b, size: 75 bytes, params: 2, frame: 14 const value = environment.__proto__.__proto__; (AppStartPerformance).mark('🌐', 'Fastconnect socket message'); env0_1.messages.push(a0); } } } function closeFastConnectSocket() { // fn#1101, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:2760, offset: 0x00c53966, size: 71 bytes, params: 1, frame: 11 let window = global.window; if (window._ws != null) { window = global.window; window._ws.ws.close(); window = global.window; window._ws = null; } } function getLastFastConnectIdentifyUserId() { // fn#1102, offset: 0x00c539ad, size: 9 bytes, params: 1, frame: 1 return env0_8; } function identifyWebSocket() { // fn#1103, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:2971, offset: 0x00c539b6, size: 99 bytes, params: 1, frame: 11 if (global.window._ws != null) { (importDefault(14) /* metro dependency 14: TTITracker */).beginFastConnect.measure(_fun1104); } else { env0_7.log('Skipping identifyWebSocket because socket is null'); } function _fun1104() { // fn#1104, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:3052, offset: 0x00c53a19, size: 278 bytes, params: 1, frame: 20 var environment; var userId; var r7; var _ws; var ws; var state; var _socketId; var moduleValue; var defaultImport; let value = environment.__proto__; const value2 = (TTITracker).loadFastConnectNativeModule.measure(_fun1105); const value3 = null; if (value3 == value2) { env1_7.log('Skipping fast_connect because we could not find a token to connect with.'); } else if (value2 !== '') { _ws = global.window._ws; ws = _ws.ws; state = _ws.state; _socketId = ws._socketId; moduleValue = require(477) /* metro dependency 477: PlatformUtils */; if (moduleValue.isAndroid()) { defaultImport = importDefault(479) /* metro dependency 479: NativeFastConnectModule */; userId = defaultImport.getConstants().userId; } else { userId = NativeModules.DCDFastConnectManager.userId; } r7 = value3 != userId ? userId : value3; r7 = value3 != userId ? userId : value3; state.userId = r7; value = prepareIdentify(_socketId, value3 != userId ? userId : value3, value2); state.identify = true; state.clientState = value; } else { env1_7.log('Skipping fast_connect because we could not find a token to connect with.'); } function _fun1105() { // fn#1105, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:30:3109, offset: 0x00c53b2f, size: 109 bytes, params: 1, frame: 13 var r0; var token; let value = environment.__proto__.__proto__; if (PlatformUtilsModule.isAndroid()) { value = importDefault(479) /* metro dependency 479: NativeFastConnectModule */; token = value.getConstants().token; value = null; r0 = value != token ? token : value; } else { r0 = NativeModules.DCDFastConnectManager.token; } return r0; } } } } global.__d(_fun1094, 25, [26, 27, 476, 3, 477, 479, 480, 660, 12525, 5231, 12507, 12494, 20, 14, 2]) /* metro module 25, dependencies: [26, 27, 476, 3, 477, 479, 480, 660, 12525, 5231, 12507, 12494, 20, 14, 2] */;