@buoy-gg/external-sync 7.0.0 → 7.0.2
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.
- package/lib/commonjs/useExternalSyncSocket.js +4 -1
- package/lib/commonjs/utils/platformUtils.js +28 -2
- package/lib/module/useExternalSyncSocket.js +4 -1
- package/lib/module/utils/platformUtils.js +28 -2
- package/lib/typescript/types.d.ts +3 -2
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/useExternalSyncSocket.d.ts.map +1 -1
- package/lib/typescript/utils/platformUtils.d.ts +2 -1
- package/lib/typescript/utils/platformUtils.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -85,7 +85,10 @@ function useExternalSyncSocket({
|
|
|
85
85
|
// outage to avoid flooding the console until the server comes back up.
|
|
86
86
|
if (hasLoggedConnectError.current) return;
|
|
87
87
|
hasLoggedConnectError.current = true;
|
|
88
|
-
|
|
88
|
+
// A localhost target on an Android device means a USB (adb reverse)
|
|
89
|
+
// setup — name the exact command instead of the generic hint.
|
|
90
|
+
const hint = platform === "android" && /localhost|127\.0\.0\.1/.test(currentSocketURL) ? `If this device is connected over USB, run: adb reverse tcp:42831 tcp:42831. ` : `If it's running on another machine or port, pass socketURL via the externalSync prop. `;
|
|
91
|
+
(0, _logger.log)(`[buoy] desktop sync: can't reach ${currentSocketURL} (is Buoy Desktop running?). ` + `Retrying in the background. ${hint}(${error.message})`, enableLogs, "warn");
|
|
89
92
|
};
|
|
90
93
|
const onConnectTimeout = () => {
|
|
91
94
|
(0, _logger.log)(`${logPrefix} Socket connection timeout`, enableLogs, "error");
|
|
@@ -4,14 +4,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getPlatformSpecificURL = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* True only on an actual Android EMULATOR, detected via the build fingerprint
|
|
9
|
+
* (same heuristic react-native-device-info uses), with no native dependency.
|
|
10
|
+
* Physical devices must NOT get the 10.0.2.2 rewrite: over USB (`adb reverse`)
|
|
11
|
+
* the Metro-derived host is "localhost", and rewriting it to the
|
|
12
|
+
* emulator-only 10.0.2.2 alias breaks the connection — keeping localhost lets
|
|
13
|
+
* `adb reverse tcp:42831 tcp:42831` forward it to the dev machine.
|
|
14
|
+
*
|
|
15
|
+
* The react-native require stays lexically inside try{} (Metro optional-dep
|
|
16
|
+
* rule) and this module is never imported from types.ts, so non-Metro
|
|
17
|
+
* bundles (the desktop app) are unaffected.
|
|
18
|
+
*/
|
|
19
|
+
const isAndroidEmulator = () => {
|
|
20
|
+
try {
|
|
21
|
+
const {
|
|
22
|
+
Platform
|
|
23
|
+
} = require("react-native");
|
|
24
|
+
if (Platform.OS !== "android") return false;
|
|
25
|
+
const fingerprint = Platform.constants?.Fingerprint ?? "";
|
|
26
|
+
return /generic|emulator|goldfish|ranchu|sdk_gphone|vbox/i.test(fingerprint);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
7
32
|
/**
|
|
8
33
|
* Get platform-specific URL for socket connection.
|
|
9
|
-
* On Android emulator, replaces localhost with 10.0.2.2
|
|
34
|
+
* On the Android emulator (only), replaces localhost with 10.0.2.2 —
|
|
35
|
+
* the emulator's alias for the host machine's loopback.
|
|
10
36
|
*/
|
|
11
37
|
const getPlatformSpecificURL = (baseUrl, platform) => {
|
|
12
38
|
try {
|
|
13
39
|
const url = new URL(baseUrl);
|
|
14
|
-
if (platform === "android" && (url.hostname === "localhost" || url.hostname === "127.0.0.1")) {
|
|
40
|
+
if (platform === "android" && (url.hostname === "localhost" || url.hostname === "127.0.0.1") && isAndroidEmulator()) {
|
|
15
41
|
url.hostname = "10.0.2.2";
|
|
16
42
|
return url.toString();
|
|
17
43
|
}
|
|
@@ -81,7 +81,10 @@ export function useExternalSyncSocket({
|
|
|
81
81
|
// outage to avoid flooding the console until the server comes back up.
|
|
82
82
|
if (hasLoggedConnectError.current) return;
|
|
83
83
|
hasLoggedConnectError.current = true;
|
|
84
|
-
|
|
84
|
+
// A localhost target on an Android device means a USB (adb reverse)
|
|
85
|
+
// setup — name the exact command instead of the generic hint.
|
|
86
|
+
const hint = platform === "android" && /localhost|127\.0\.0\.1/.test(currentSocketURL) ? `If this device is connected over USB, run: adb reverse tcp:42831 tcp:42831. ` : `If it's running on another machine or port, pass socketURL via the externalSync prop. `;
|
|
87
|
+
log(`[buoy] desktop sync: can't reach ${currentSocketURL} (is Buoy Desktop running?). ` + `Retrying in the background. ${hint}(${error.message})`, enableLogs, "warn");
|
|
85
88
|
};
|
|
86
89
|
const onConnectTimeout = () => {
|
|
87
90
|
log(`${logPrefix} Socket connection timeout`, enableLogs, "error");
|
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* True only on an actual Android EMULATOR, detected via the build fingerprint
|
|
5
|
+
* (same heuristic react-native-device-info uses), with no native dependency.
|
|
6
|
+
* Physical devices must NOT get the 10.0.2.2 rewrite: over USB (`adb reverse`)
|
|
7
|
+
* the Metro-derived host is "localhost", and rewriting it to the
|
|
8
|
+
* emulator-only 10.0.2.2 alias breaks the connection — keeping localhost lets
|
|
9
|
+
* `adb reverse tcp:42831 tcp:42831` forward it to the dev machine.
|
|
10
|
+
*
|
|
11
|
+
* The react-native require stays lexically inside try{} (Metro optional-dep
|
|
12
|
+
* rule) and this module is never imported from types.ts, so non-Metro
|
|
13
|
+
* bundles (the desktop app) are unaffected.
|
|
14
|
+
*/
|
|
15
|
+
const isAndroidEmulator = () => {
|
|
16
|
+
try {
|
|
17
|
+
const {
|
|
18
|
+
Platform
|
|
19
|
+
} = require("react-native");
|
|
20
|
+
if (Platform.OS !== "android") return false;
|
|
21
|
+
const fingerprint = Platform.constants?.Fingerprint ?? "";
|
|
22
|
+
return /generic|emulator|goldfish|ranchu|sdk_gphone|vbox/i.test(fingerprint);
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
3
28
|
/**
|
|
4
29
|
* Get platform-specific URL for socket connection.
|
|
5
|
-
* On Android emulator, replaces localhost with 10.0.2.2
|
|
30
|
+
* On the Android emulator (only), replaces localhost with 10.0.2.2 —
|
|
31
|
+
* the emulator's alias for the host machine's loopback.
|
|
6
32
|
*/
|
|
7
33
|
export const getPlatformSpecificURL = (baseUrl, platform) => {
|
|
8
34
|
try {
|
|
9
35
|
const url = new URL(baseUrl);
|
|
10
|
-
if (platform === "android" && (url.hostname === "localhost" || url.hostname === "127.0.0.1")) {
|
|
36
|
+
if (platform === "android" && (url.hostname === "localhost" || url.hostname === "127.0.0.1") && isAndroidEmulator()) {
|
|
11
37
|
url.hostname = "10.0.2.2";
|
|
12
38
|
return url.toString();
|
|
13
39
|
}
|
|
@@ -106,8 +106,9 @@ export interface UseExternalSyncSocketProps {
|
|
|
106
106
|
/**
|
|
107
107
|
* Broker URL to dial. @default derived from Metro's scriptURL host
|
|
108
108
|
* (the machine that served the bundle — Buoy Desktop's machine) on port
|
|
109
|
-
* 42831, so physical devices work zero-config
|
|
110
|
-
*
|
|
109
|
+
* 42831, so physical devices work zero-config (Android over USB: run
|
|
110
|
+
* `adb reverse tcp:42831 tcp:42831`). Pass explicitly for tunnels or a
|
|
111
|
+
* broker on another machine.
|
|
111
112
|
*/
|
|
112
113
|
socketURL?: string;
|
|
113
114
|
persistentDeviceId: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AA0B/C,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,+EAA+E;AAC/E,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC;AAMlC,mFAAmF;AACnF,MAAM,MAAM,UAAU,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M,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,QAAQ,EAAE,UAAU,CAAC;IACrB,qBAAqB;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalSyncSocket.d.ts","sourceRoot":"","sources":["../../src/useExternalSyncSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AA0B1D;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,UAAkB,GACnB,EAAE,0BAA0B;;;;;
|
|
1
|
+
{"version":3,"file":"useExternalSyncSocket.d.ts","sourceRoot":"","sources":["../../src/useExternalSyncSocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AA0B1D;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,UAAkB,GACnB,EAAE,0BAA0B;;;;;EA4O5B"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { PlatformOS } from "../types";
|
|
2
2
|
/**
|
|
3
3
|
* Get platform-specific URL for socket connection.
|
|
4
|
-
* On Android emulator, replaces localhost with 10.0.2.2
|
|
4
|
+
* On the Android emulator (only), replaces localhost with 10.0.2.2 —
|
|
5
|
+
* the emulator's alias for the host machine's loopback.
|
|
5
6
|
*/
|
|
6
7
|
export declare const getPlatformSpecificURL: (baseUrl: string, platform: PlatformOS) => string;
|
|
7
8
|
//# sourceMappingURL=platformUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/platformUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"platformUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/platformUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA4B3C;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,EACf,UAAU,UAAU,KACnB,MAkBF,CAAC"}
|