@buoy-gg/external-sync 7.0.22 → 7.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.DEFAULT_BROKER_PORT = void 0;
|
|
7
7
|
exports.getDefaultSocketURL = getDefaultSocketURL;
|
|
8
8
|
exports.getMetroHost = getMetroHost;
|
|
9
|
+
exports.hostFromScriptURL = hostFromScriptURL;
|
|
10
|
+
exports.socketURLForHost = socketURLForHost;
|
|
9
11
|
/**
|
|
10
12
|
* Default broker-URL derivation. Kept in its own module (and never imported
|
|
11
13
|
* from types.ts) because the deep react-native require below must not reach
|
|
@@ -16,6 +18,24 @@ exports.getMetroHost = getMetroHost;
|
|
|
16
18
|
const DEFAULT_BROKER_PORT = exports.DEFAULT_BROKER_PORT = 42831;
|
|
17
19
|
const HOST_RE = /^https?:\/\/([^:/]+)/;
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Host out of a bundle's scriptURL, or null when there isn't one.
|
|
23
|
+
*
|
|
24
|
+
* Release bundles are loaded from disk (`file:///.../main.jsbundle`), so this
|
|
25
|
+
* returns null and callers fall back to localhost — correct for simulators,
|
|
26
|
+
* emulators, and Android over USB (`adb reverse tcp:42831 tcp:42831`). A
|
|
27
|
+
* physical iOS device in a release build has no derivable host at all and
|
|
28
|
+
* must be given an explicit socketURL.
|
|
29
|
+
*/
|
|
30
|
+
function hostFromScriptURL(scriptURL) {
|
|
31
|
+
return scriptURL?.match(HOST_RE)?.[1] ?? null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Broker URL for a host, falling back to localhost when none is known. */
|
|
35
|
+
function socketURLForHost(host) {
|
|
36
|
+
return `http://${host ?? "localhost"}:${DEFAULT_BROKER_PORT}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
19
39
|
/**
|
|
20
40
|
* Host of the Metro dev server that served this bundle — the machine most
|
|
21
41
|
* likely running Buoy Desktop. On a physical device this is the computer's
|
|
@@ -33,9 +53,8 @@ function getMetroHost() {
|
|
|
33
53
|
const NativeSourceCode =
|
|
34
54
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
35
55
|
require("react-native/Libraries/NativeModules/specs/NativeSourceCode").default;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
if (match) return match[1];
|
|
56
|
+
const host = hostFromScriptURL(NativeSourceCode?.getConstants?.().scriptURL);
|
|
57
|
+
if (host) return host;
|
|
39
58
|
} catch {
|
|
40
59
|
// web / RN internals moved — try the old-architecture module
|
|
41
60
|
}
|
|
@@ -43,9 +62,8 @@ function getMetroHost() {
|
|
|
43
62
|
const {
|
|
44
63
|
NativeModules
|
|
45
64
|
} = require("react-native");
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
if (match) return match[1];
|
|
65
|
+
const host = hostFromScriptURL(NativeModules?.SourceCode?.getConstants?.().scriptURL ?? NativeModules?.SourceCode?.scriptURL);
|
|
66
|
+
if (host) return host;
|
|
49
67
|
} catch {
|
|
50
68
|
// not React Native
|
|
51
69
|
}
|
|
@@ -58,5 +76,5 @@ function getMetroHost() {
|
|
|
58
76
|
* later by getPlatformSpecificURL, so localhost still works there.
|
|
59
77
|
*/
|
|
60
78
|
function getDefaultSocketURL() {
|
|
61
|
-
return
|
|
79
|
+
return socketURLForHost(getMetroHost());
|
|
62
80
|
}
|
|
@@ -10,6 +10,24 @@
|
|
|
10
10
|
export const DEFAULT_BROKER_PORT = 42831;
|
|
11
11
|
const HOST_RE = /^https?:\/\/([^:/]+)/;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Host out of a bundle's scriptURL, or null when there isn't one.
|
|
15
|
+
*
|
|
16
|
+
* Release bundles are loaded from disk (`file:///.../main.jsbundle`), so this
|
|
17
|
+
* returns null and callers fall back to localhost — correct for simulators,
|
|
18
|
+
* emulators, and Android over USB (`adb reverse tcp:42831 tcp:42831`). A
|
|
19
|
+
* physical iOS device in a release build has no derivable host at all and
|
|
20
|
+
* must be given an explicit socketURL.
|
|
21
|
+
*/
|
|
22
|
+
export function hostFromScriptURL(scriptURL) {
|
|
23
|
+
return scriptURL?.match(HOST_RE)?.[1] ?? null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Broker URL for a host, falling back to localhost when none is known. */
|
|
27
|
+
export function socketURLForHost(host) {
|
|
28
|
+
return `http://${host ?? "localhost"}:${DEFAULT_BROKER_PORT}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
13
31
|
/**
|
|
14
32
|
* Host of the Metro dev server that served this bundle — the machine most
|
|
15
33
|
* likely running Buoy Desktop. On a physical device this is the computer's
|
|
@@ -27,9 +45,8 @@ export function getMetroHost() {
|
|
|
27
45
|
const NativeSourceCode =
|
|
28
46
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
29
47
|
require("react-native/Libraries/NativeModules/specs/NativeSourceCode").default;
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (match) return match[1];
|
|
48
|
+
const host = hostFromScriptURL(NativeSourceCode?.getConstants?.().scriptURL);
|
|
49
|
+
if (host) return host;
|
|
33
50
|
} catch {
|
|
34
51
|
// web / RN internals moved — try the old-architecture module
|
|
35
52
|
}
|
|
@@ -37,9 +54,8 @@ export function getMetroHost() {
|
|
|
37
54
|
const {
|
|
38
55
|
NativeModules
|
|
39
56
|
} = require("react-native");
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
if (match) return match[1];
|
|
57
|
+
const host = hostFromScriptURL(NativeModules?.SourceCode?.getConstants?.().scriptURL ?? NativeModules?.SourceCode?.scriptURL);
|
|
58
|
+
if (host) return host;
|
|
43
59
|
} catch {
|
|
44
60
|
// not React Native
|
|
45
61
|
}
|
|
@@ -52,5 +68,5 @@ export function getMetroHost() {
|
|
|
52
68
|
* later by getPlatformSpecificURL, so localhost still works there.
|
|
53
69
|
*/
|
|
54
70
|
export function getDefaultSocketURL() {
|
|
55
|
-
return
|
|
71
|
+
return socketURLForHost(getMetroHost());
|
|
56
72
|
}
|
|
@@ -5,6 +5,18 @@
|
|
|
5
5
|
*/
|
|
6
6
|
/** Port Buoy Desktop's broker listens on. */
|
|
7
7
|
export declare const DEFAULT_BROKER_PORT = 42831;
|
|
8
|
+
/**
|
|
9
|
+
* Host out of a bundle's scriptURL, or null when there isn't one.
|
|
10
|
+
*
|
|
11
|
+
* Release bundles are loaded from disk (`file:///.../main.jsbundle`), so this
|
|
12
|
+
* returns null and callers fall back to localhost — correct for simulators,
|
|
13
|
+
* emulators, and Android over USB (`adb reverse tcp:42831 tcp:42831`). A
|
|
14
|
+
* physical iOS device in a release build has no derivable host at all and
|
|
15
|
+
* must be given an explicit socketURL.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hostFromScriptURL(scriptURL: string | null | undefined): string | null;
|
|
18
|
+
/** Broker URL for a host, falling back to localhost when none is known. */
|
|
19
|
+
export declare function socketURLForHost(host: string | null): string;
|
|
8
20
|
/**
|
|
9
21
|
* Host of the Metro dev server that served this bundle — the machine most
|
|
10
22
|
* likely running Buoy Desktop. On a physical device this is the computer's
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultSocketURL.d.ts","sourceRoot":"","sources":["../../../src/utils/getDefaultSocketURL.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6CAA6C;AAC7C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAIzC;;;;;;;;;GASG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAyB5C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
1
|
+
{"version":3,"file":"getDefaultSocketURL.d.ts","sourceRoot":"","sources":["../../../src/utils/getDefaultSocketURL.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6CAA6C;AAC7C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAIzC;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACnC,MAAM,GAAG,IAAI,CAEf;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAyB5C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|