UNPKG

3.38 kBJavaScriptView Raw
1/* eslint-disable */
2'use strict';
3/*
4 * It only for Debug Remotely mode for Android
5 * When __DEV__ === false, we can't use window.require('NativeModules')
6 */
7
8require("core-js/modules/es.symbol");
9
10require("core-js/modules/es.symbol.description");
11
12require("core-js/modules/es.symbol.iterator");
13
14require("core-js/modules/es.array.find");
15
16require("core-js/modules/es.array.is-array");
17
18require("core-js/modules/es.array.iterator");
19
20require("core-js/modules/es.function.name");
21
22require("core-js/modules/es.object.to-string");
23
24require("core-js/modules/es.regexp.exec");
25
26require("core-js/modules/es.string.iterator");
27
28require("core-js/modules/es.string.split");
29
30require("core-js/modules/web.dom-collections.iterator");
31
32Object.defineProperty(exports, "__esModule", {
33 value: true
34});
35exports["default"] = getHost;
36
37function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
38
39function getByRemoteConfig(hostname) {
40 var remoteModuleConfig = typeof window !== 'undefined' && window.__fbBatchedBridgeConfig && window.__fbBatchedBridgeConfig.remoteModuleConfig;
41 if (!Array.isArray(remoteModuleConfig) || hostname !== 'localhost' && hostname !== '127.0.0.1') return {
42 hostname: hostname,
43 passed: false
44 };
45 var constants = (remoteModuleConfig.find(getConstants) || [])[1];
46
47 if (constants) {
48 var serverHost = constants.ServerHost || hostname;
49 return {
50 hostname: serverHost.split(':')[0],
51 passed: true
52 };
53 }
54
55 return {
56 hostname: hostname,
57 passed: false
58 };
59}
60
61function getConstants(config) {
62 return config && (config[0] === 'AndroidConstants' || config[0] === 'PlatformConstants');
63}
64
65function getByRNRequirePolyfill(hostname) {
66 var NativeModules;
67 var PlatformConstants;
68 var AndroidConstants;
69
70 if (typeof window === 'undefined' || !window.__DEV__ || typeof window.require !== 'function' || // RN >= 0.56
71 // TODO: Get NativeModules for RN >= 0.56
72 window.require.name === 'metroRequire') {
73 return hostname;
74 }
75
76 NativeModules = window.require('NativeModules');
77
78 if (!NativeModules || !NativeModules.PlatformConstants && !NativeModules.AndroidConstants) {
79 return hostname;
80 }
81
82 PlatformConstants = NativeModules.PlatformConstants;
83 AndroidConstants = NativeModules.AndroidConstants;
84 var serverHost = (PlatformConstants ? PlatformConstants.ServerHost : AndroidConstants.ServerHost) || hostname;
85 return serverHost.split(':')[0];
86}
87/*
88 * Get React Native server IP if hostname is `localhost`
89 * On Android emulator, the IP of host is `10.0.2.2` (Genymotion: 10.0.3.2)
90 */
91
92
93function getHost(hostname) {
94 // Check if it in React Native environment
95 if ((typeof __fbBatchedBridge === "undefined" ? "undefined" : _typeof(__fbBatchedBridge)) !== 'object' || hostname !== 'localhost' && hostname !== '127.0.0.1') {
96 return hostname;
97 }
98
99 var result = getByRemoteConfig(hostname); // Leave if get hostname by remote config successful
100
101 if (result.passed) {
102 return result.hostname;
103 } // Otherwise, use RN's require polyfill
104
105
106 return getByRNRequirePolyfill(hostname);
107}
\No newline at end of file