catalyst-core 0.2.0-beta.2 → 0.3.0-beta.1
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/babel.native.config.cjs +8 -0
- package/bin/catalyst.js +49 -105
- package/changelog.md +8 -0
- package/dist/caching.js +1 -1
- package/dist/index.jsx +8 -0
- package/dist/logger.js +74 -3
- package/dist/native/androidProject/app/build.gradle.kts +1 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +143 -4
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +26 -6
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +143 -17
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +6 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +26 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +56 -1
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +48 -8
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/PerfDeliveryState.kt +36 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/PerfEventBuffer.kt +289 -0
- package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/ProfilerNavigationState.kt +13 -0
- package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/ProfilerLifecycleTest.kt +51 -0
- package/dist/native/androidSetup.js +300 -8
- package/dist/native/bridge/WebBridge.js +481 -59
- package/dist/native/bridge/constants/NativeInterfaces.js +290 -44
- package/dist/native/bridge/errors.js +250 -26
- package/dist/native/bridge/hooks/index.js +125 -1
- package/dist/native/bridge/hooks/useCamera.js +347 -9
- package/dist/native/bridge/hooks/useDataProtection.js +200 -2
- package/dist/native/bridge/hooks/useDeviceInfo.js +71 -2
- package/dist/native/bridge/hooks/useFilePicker.js +429 -2
- package/dist/native/bridge/hooks/useGoogleSignIn.js +81 -1
- package/dist/native/bridge/hooks/useHapticFeedback.js +196 -1
- package/dist/native/bridge/hooks/useIntent.js +95 -1
- package/dist/native/bridge/hooks/useNativeTransition.js +202 -27
- package/dist/native/bridge/hooks/useNetworkStatus.js +84 -3
- package/dist/native/bridge/hooks/useNotification.js +318 -2
- package/dist/native/bridge/hooks/useSafeArea.js +84 -2
- package/dist/native/bridge/hooks/useVideoStream.js +434 -6
- package/dist/native/bridge/hooks/utils.js +27 -1
- package/dist/native/bridge/hooks.js +16 -1
- package/dist/native/bridge/perf/collectors/ApiCollector.js +85 -0
- package/dist/native/bridge/perf/collectors/CacheCollector.js +215 -0
- package/dist/native/bridge/perf/collectors/HookCollector.js +165 -0
- package/dist/native/bridge/perf/collectors/InsightsCollector.js +505 -0
- package/dist/native/bridge/perf/collectors/InteractionCollector.js +273 -0
- package/dist/native/bridge/perf/collectors/KeyboardCollector.js +124 -0
- package/dist/native/bridge/perf/collectors/NavigationCollector.js +294 -0
- package/dist/native/bridge/perf/collectors/NetworkTimingCollector.js +183 -0
- package/dist/native/bridge/perf/collectors/RenderCollector.js +284 -0
- package/dist/native/bridge/perf/collectors/ScrollCollector.js +111 -0
- package/dist/native/bridge/perf/collectors/ThreadCollector.js +111 -0
- package/dist/native/bridge/perf/core/constants.js +126 -0
- package/dist/native/bridge/perf/core/measure.js +189 -0
- package/dist/native/bridge/perf/core/session.js +100 -0
- package/dist/native/bridge/perf/core/store.js +554 -0
- package/dist/native/bridge/perf/core/summary.js +174 -0
- package/dist/native/bridge/perf/core/traceExport.js +240 -0
- package/dist/native/bridge/perf/core/waterfalls.js +146 -0
- package/dist/native/bridge/perf/index.js +402 -0
- package/dist/native/bridge/safeArea.js +53 -5
- package/dist/native/bridge/standardizedHooks.js +595 -82
- package/dist/native/bridge/useBaseHook.js +274 -38
- package/dist/native/bridge/utils/CameraUtils.js +201 -56
- package/dist/native/bridge/utils/FileObjectConverter.js +129 -18
- package/dist/native/bridge/utils/NativeBridge.js +425 -141
- package/dist/native/buildAndroid/assets.js +510 -13
- package/dist/native/buildAndroid/build.js +296 -19
- package/dist/native/buildAndroid/config.js +87 -1
- package/dist/native/buildAndroid/index.js +374 -1
- package/dist/native/buildAppAndroid.js +34 -2
- package/dist/native/buildAppIos.js +62 -2
- package/dist/native/buildIos/assets.js +609 -8
- package/dist/native/buildIos/build.js +639 -20
- package/dist/native/buildIos/config.js +294 -12
- package/dist/native/buildIos/index.js +343 -6
- package/dist/native/buildIos/plugins.js +343 -16
- package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +43 -0
- package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +28 -0
- package/dist/native/internal-plugins/device-info-plugin/manifest.json +19 -0
- package/dist/native/internalPluginUtils.js +232 -7
- package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +19 -0
- package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +4 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/BootTimingUtility.swift +5 -1
- package/dist/native/iosnativeWebView/Sources/Core/Utils/CacheManager.swift +10 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/DisplayLinkPerfMonitor.swift +89 -0
- package/dist/native/iosnativeWebView/Sources/Core/Utils/PerfEventBuffer.swift +373 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +35 -1
- package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +24 -11
- package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +9 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +126 -0
- package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +75 -1
- package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +13 -0
- package/dist/native/package.json +3 -0
- package/dist/native/plugin-bridge/PluginBridge.js +227 -1
- package/dist/native/pluginComposerAndroid.js +407 -23
- package/dist/native/pluginComposerIos.js +435 -11
- package/dist/native/renameAndroidProject.js +1094 -88
- package/dist/native/setupEmulatorIos.js +289 -22
- package/dist/native/setupServer.js +160 -19
- package/dist/native/terminalProgress.js +199 -11
- package/dist/native/utils.js +193 -15
- package/dist/offline/catalyst-sw.js +145 -1
- package/dist/offline/registerServiceWorker.js +33 -1
- package/dist/otel.js +375 -46
- package/dist/router/ClientRouter.js +14 -2
- package/dist/router/ServerRouter.js +9 -1
- package/dist/router.js +1 -1
- package/dist/scripts/build.js +112 -3
- package/dist/scripts/checkVersion.js +3 -1
- package/dist/scripts/cleanCache.js +30 -1
- package/dist/scripts/generateOfflineManifest.js +116 -1
- package/dist/scripts/loadEnvironmentVariables.js +32 -6
- package/dist/scripts/plugins.js +309 -1
- package/dist/scripts/preServerInit.js +13 -0
- package/dist/scripts/scriptUtils.js +54 -3
- package/dist/scripts/serve.js +51 -4
- package/dist/scripts/start.js +47 -10
- package/dist/scripts/validator.js +149 -1
- package/dist/sentry.cjs +127 -0
- package/dist/sentry.js +125 -5
- package/dist/server/expressServer.js +250 -5
- package/dist/server/manifestCache.js +36 -0
- package/dist/server/renderer/ChunkExtractor.js +144 -0
- package/dist/server/renderer/document/Body.jsx +59 -0
- package/dist/server/renderer/document/FastRefresh.jsx +20 -0
- package/dist/server/renderer/document/Head.jsx +60 -0
- package/dist/server/renderer/document/index.jsx +2 -0
- package/dist/server/renderer/extract.js +149 -31
- package/dist/server/renderer/handler.jsx +433 -0
- package/dist/server/renderer/index.js +8 -1
- package/dist/server/renderer/render.js +47 -0
- package/dist/server/utils/botDetectionMiddleware.js +29 -0
- package/dist/server/utils/cjsRequire.js +10 -0
- package/dist/server/utils/userAgentUtil.js +87 -9
- package/dist/server/utils/validator.js +164 -1
- package/dist/vite/FastRefresh.jsx +20 -0
- package/dist/vite/inject-cache-key-plugin.js +276 -0
- package/dist/vite/loadCustomViteConfig.js +22 -0
- package/dist/vite/manifest-categorization-plugin.js +455 -0
- package/dist/vite/node-loader.mjs +458 -0
- package/dist/vite/scssParams.js +21 -0
- package/dist/vite/vite.config.client.js +130 -0
- package/dist/vite/vite.config.js +422 -0
- package/dist/vite/vite.config.server.js +84 -0
- package/dist/web-router/components/MetaTag.jsx +34 -0
- package/dist/web-router/components/RouterDataProvider.jsx +332 -0
- package/dist/web-router/components/Split.jsx +200 -0
- package/dist/web-router/components/SplitInview.jsx +106 -0
- package/dist/web-router/components/SsrRequestContext.jsx +14 -0
- package/dist/web-router/context.jsx +12 -0
- package/dist/web-router/hooks.jsx +72 -0
- package/dist/web-router/types/components/MetaTag.d.ts +2 -0
- package/dist/web-router/types/components/RouterDataProvider.d.ts +95 -0
- package/dist/web-router/types/context.d.ts +14 -0
- package/dist/web-router/types/hooks.d.ts +1 -0
- package/dist/web-router/types/index.d.ts +3 -0
- package/dist/web-router/types/utils/metaDataUtils.d.ts +24 -0
- package/dist/web-router/utils/metaDataUtils.jsx +119 -0
- package/mcp_v2/conversion-tasks.json +35 -17
- package/mcp_v2/knowledge-base.json +124 -13
- package/mcp_v2/lib/helpers.js +10 -0
- package/mcp_v2/mcp.js +4 -4
- package/mcp_v2/package.json +1 -0
- package/mcp_v2/tools/build.js +116 -20
- package/mcp_v2/tools/conversion.js +106 -5
- package/mcp_v2/tools/tasks.js +18 -14
- package/package.json +35 -68
- package/babel.config.js +0 -32
- package/dist/index.js +0 -1
- package/dist/scripts/devBuild.js +0 -3
- package/dist/scripts/devServe.js +0 -3
- package/dist/scripts/loadScriptsBeforeServerStarts.js +0 -4
- package/dist/scripts/registerAliases.js +0 -6
- package/dist/server/renderer/document/Body.js +0 -11
- package/dist/server/renderer/document/Head.js +0 -9
- package/dist/server/renderer/document/index.js +0 -1
- package/dist/server/renderer/handler.js +0 -47
- package/dist/server/startServer.js +0 -57
- package/dist/webpack/babel-plugins/remove-client.plugin.js +0 -5
- package/dist/webpack/babel-plugins/remove-ssr.plugin.js +0 -5
- package/dist/webpack/babel.config.client.js +0 -1
- package/dist/webpack/babel.config.ssr.js +0 -1
- package/dist/webpack/base.babel.js +0 -7
- package/dist/webpack/development.client.babel.js +0 -10
- package/dist/webpack/production.client.babel.js +0 -4
- package/dist/webpack/production.ssr.babel.js +0 -8
- package/dist/webpack/scssParams.js +0 -9
|
@@ -1,144 +1,428 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.NativeBridgeUtil = void 0;
|
|
7
|
+
var _NativeInterfaces = require("../constants/NativeInterfaces.js");
|
|
8
|
+
/**
|
|
2
9
|
* NativeBridge Utility
|
|
3
10
|
* Handles communication from Web to Native platforms
|
|
4
11
|
* Supports both Android (window.NativeBridge) and iOS (webkit.messageHandlers)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*
|
|
141
|
-
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
12
|
+
*/
|
|
13
|
+
class NativeBridgeUtil {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.isAndroid = this._detectAndroid();
|
|
16
|
+
this.isIOS = this._detectIOS();
|
|
17
|
+
this.isNativeEnvironment = this.isAndroid || this.isIOS;
|
|
18
|
+
if (typeof window !== "undefined") {
|
|
19
|
+
this._logEnvironmentInfo();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Detect if running on Android WebView
|
|
25
|
+
*/
|
|
26
|
+
_detectAndroid() {
|
|
27
|
+
if (typeof window === "undefined") return false;
|
|
28
|
+
return !!(window.NativeBridge && typeof window.NativeBridge === "object");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Detect if running on iOS WebView
|
|
33
|
+
*/
|
|
34
|
+
_detectIOS() {
|
|
35
|
+
if (typeof window === "undefined") return false;
|
|
36
|
+
return !!window.webkit?.messageHandlers?.NativeBridge;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Log environment detection info for debugging
|
|
41
|
+
*/
|
|
42
|
+
_logEnvironmentInfo() {
|
|
43
|
+
console.log("🌉 NativeBridge Environment Detection:", {
|
|
44
|
+
isAndroid: this.isAndroid,
|
|
45
|
+
isIOS: this.isIOS,
|
|
46
|
+
isNativeEnvironment: this.isNativeEnvironment,
|
|
47
|
+
hasAndroidBridge: !!window.NativeBridge,
|
|
48
|
+
hasIOSBridge: !!window.webkit?.messageHandlers?.NativeBridge
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Validate command before execution
|
|
54
|
+
*/
|
|
55
|
+
_validateCommand(command) {
|
|
56
|
+
if (!command) {
|
|
57
|
+
throw new Error("Command is required");
|
|
58
|
+
}
|
|
59
|
+
if (!(0, _NativeInterfaces.isValidCommand)(command)) {
|
|
60
|
+
throw new Error(`Invalid command: ${command}. Available commands: ${Object.values(_NativeInterfaces.NATIVE_COMMANDS).join(", ")}`);
|
|
61
|
+
}
|
|
62
|
+
if (!this.isAvailable()) {
|
|
63
|
+
throw new Error("Native bridge not available. Ensure you are running in a native WebView environment.");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Execute command on Android platform
|
|
69
|
+
*/
|
|
70
|
+
_executeAndroidCommand(command, data) {
|
|
71
|
+
try {
|
|
72
|
+
if (typeof window.NativeBridge[command] === "function") {
|
|
73
|
+
console.log("🌉 Calling Android method", command, data ? {
|
|
74
|
+
data
|
|
75
|
+
} : "(no data)");
|
|
76
|
+
// Always pass data parameter to match Kotlin method signatures
|
|
77
|
+
window.NativeBridge[command](data);
|
|
78
|
+
return true;
|
|
79
|
+
} else {
|
|
80
|
+
console.error(`Android bridge method '${command}' not found`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error("Error executing Android command:", command, error);
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Execute command on iOS platform
|
|
91
|
+
*/
|
|
92
|
+
_executeIOSCommand(command, data) {
|
|
93
|
+
try {
|
|
94
|
+
// For iOS, we always send a message object
|
|
95
|
+
const message = {
|
|
96
|
+
command: command,
|
|
97
|
+
data: data // This can be null/undefined, iOS bridge should handle it
|
|
98
|
+
};
|
|
99
|
+
console.log("🌉 Calling iOS method", command, data ? {
|
|
100
|
+
data
|
|
101
|
+
} : "(no data)");
|
|
102
|
+
window.webkit.messageHandlers.NativeBridge.postMessage(message);
|
|
103
|
+
return true;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error("Error executing iOS command:", command, error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Main method to call native commands
|
|
112
|
+
* @param {string} command - The command to execute (from NATIVE_COMMANDS)
|
|
113
|
+
* @param {any} data - Optional data to pass to the native side
|
|
114
|
+
* @returns {boolean} - Success status
|
|
115
|
+
*/
|
|
116
|
+
call(command, data = null) {
|
|
117
|
+
try {
|
|
118
|
+
// Validate environment and command
|
|
119
|
+
this._validateCommand(command);
|
|
120
|
+
console.log("🌉 Executing native command:", command, data ? {
|
|
121
|
+
data
|
|
122
|
+
} : "");
|
|
123
|
+
|
|
124
|
+
// Execute on appropriate platform
|
|
125
|
+
if (this.isAndroid) {
|
|
126
|
+
return this._executeAndroidCommand(command, data);
|
|
127
|
+
} else if (this.isIOS) {
|
|
128
|
+
return this._executeIOSCommand(command, data);
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error("🌉 Failed to execute command:", command, error);
|
|
133
|
+
|
|
134
|
+
// In development, we might want to show user-friendly errors
|
|
135
|
+
if (process.env.NODE_ENV === "development") {
|
|
136
|
+
console.warn(`🌉 Development mode: Native command '${command}' failed. This is expected when running in browser.`);
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Video stream methods
|
|
144
|
+
*/
|
|
145
|
+
videoStream = {
|
|
146
|
+
/**
|
|
147
|
+
* Start native camera video stream
|
|
148
|
+
* @param {Object} options - Stream options
|
|
149
|
+
* facing: 'back' | 'front'
|
|
150
|
+
* format: 'qr' | 'barcode' | 'all' — format filter (default: 'all')
|
|
151
|
+
* zoom: { auto: true, initial: 1.0 } — auto-zoom via ML Kit, initial is multiplier (1.0=1x)
|
|
152
|
+
* zoom: { auto: false, initial: 2.0 } — manual, starts at 2x
|
|
153
|
+
*/
|
|
154
|
+
start: (options = {}) => this.call(_NativeInterfaces.NATIVE_COMMANDS.START_VIDEO_STREAM, options),
|
|
155
|
+
/**
|
|
156
|
+
* Stop native camera video stream
|
|
157
|
+
*/
|
|
158
|
+
stop: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.STOP_VIDEO_STREAM),
|
|
159
|
+
/**
|
|
160
|
+
* Set zoom level multiplier (e.g. 1.0 = 1x, 2.0 = 2x)
|
|
161
|
+
* @param {number} zoomPct - multiplier >= 1.0
|
|
162
|
+
*/
|
|
163
|
+
setZoom: zoomPct => {
|
|
164
|
+
if (zoomPct == null || typeof zoomPct !== "number" || isNaN(zoomPct)) {
|
|
165
|
+
console.warn("[NativeBridge] setZoom: invalid value, ignoring:", zoomPct);
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_ZOOM, zoomPct.toString());
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* Enable or disable torch (back camera only)
|
|
172
|
+
* @param {boolean} on
|
|
173
|
+
*/
|
|
174
|
+
setTorch: on => this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_TORCH, JSON.stringify({
|
|
175
|
+
on: !!on
|
|
176
|
+
})),
|
|
177
|
+
/**
|
|
178
|
+
* Set target FPS range — triggers session restart
|
|
179
|
+
* @param {number|null} min - minimum fps (e.g. 15), null to clear
|
|
180
|
+
* @param {number|null} max - maximum fps (e.g. 30), null to clear
|
|
181
|
+
*/
|
|
182
|
+
setFps: (min, max) => this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_FPS, JSON.stringify({
|
|
183
|
+
min: min ?? null,
|
|
184
|
+
max: max ?? null
|
|
185
|
+
})),
|
|
186
|
+
/**
|
|
187
|
+
* Flip between front and back camera — restarts the native session internally
|
|
188
|
+
* Torch resets to off after flip; ON_TORCH_CHANGED(false) fires automatically.
|
|
189
|
+
*/
|
|
190
|
+
flip: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.FLIP_VIDEO_STREAM)
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Camera-specific methods for easier usage
|
|
195
|
+
*/
|
|
196
|
+
camera = {
|
|
197
|
+
/**
|
|
198
|
+
* Open camera for photo capture
|
|
199
|
+
* @param {string} options - JSON string of camera options
|
|
200
|
+
*/
|
|
201
|
+
open: (options = null) => this.call(_NativeInterfaces.NATIVE_COMMANDS.OPEN_CAMERA, options),
|
|
202
|
+
/**
|
|
203
|
+
* Request camera permission
|
|
204
|
+
* @param {string} config - JSON string of permission config
|
|
205
|
+
*/
|
|
206
|
+
requestPermission: (config = null) => this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_CAMERA_PERMISSION, config)
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* File-specific methods for easier usage
|
|
211
|
+
*/
|
|
212
|
+
file = {
|
|
213
|
+
/**
|
|
214
|
+
* Open file picker
|
|
215
|
+
* @param {string|Object|null} options - MIME type string or options object with advanced config
|
|
216
|
+
*/
|
|
217
|
+
pick: (options = "*/*") => {
|
|
218
|
+
if (options == null) {
|
|
219
|
+
return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE, "*/*");
|
|
220
|
+
}
|
|
221
|
+
if (typeof options === "string") {
|
|
222
|
+
const mimeType = options.trim() || "*/*";
|
|
223
|
+
return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE, mimeType);
|
|
224
|
+
}
|
|
225
|
+
const payload = {
|
|
226
|
+
...options
|
|
227
|
+
};
|
|
228
|
+
if (!payload.mimeType || typeof payload.mimeType !== "string") {
|
|
229
|
+
payload.mimeType = "*/*";
|
|
230
|
+
}
|
|
231
|
+
return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE, JSON.stringify(payload));
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* Open file with external app
|
|
235
|
+
* @param {string} fileUrl - URL of the file to open
|
|
236
|
+
* @param {string} mimeType - Optional MIME type
|
|
237
|
+
*/
|
|
238
|
+
openWithIntent: (fileUrl, mimeType = null) => {
|
|
239
|
+
const params = mimeType ? `${fileUrl}|${mimeType}` : fileUrl;
|
|
240
|
+
return this.call(_NativeInterfaces.NATIVE_COMMANDS.OPEN_FILE_WITH_INTENT, params);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Network helpers
|
|
246
|
+
*/
|
|
247
|
+
network = {
|
|
248
|
+
/**
|
|
249
|
+
* Request current network status from native side
|
|
250
|
+
*/
|
|
251
|
+
getStatus: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_NETWORK_STATUS)
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Haptic feedback methods
|
|
256
|
+
*/
|
|
257
|
+
haptic = {
|
|
258
|
+
/**
|
|
259
|
+
* Request haptic feedback
|
|
260
|
+
* @param {string} feedbackType - Type of haptic feedback
|
|
261
|
+
*/
|
|
262
|
+
feedback: (feedbackType = "light") => this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_HAPTIC_FEEDBACK, feedbackType)
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Notification methods for local and push notifications
|
|
267
|
+
*/
|
|
268
|
+
notification = {
|
|
269
|
+
/**
|
|
270
|
+
* Schedule a local notification
|
|
271
|
+
* @param {Object} config - Notification configuration object
|
|
272
|
+
*/
|
|
273
|
+
scheduleLocal: config => this.call(_NativeInterfaces.NATIVE_COMMANDS.SCHEDULE_LOCAL_NOTIFICATION, JSON.stringify(config)),
|
|
274
|
+
/**
|
|
275
|
+
* Cancel a local notification
|
|
276
|
+
* @param {string} notificationId - ID of the notification to cancel
|
|
277
|
+
*/
|
|
278
|
+
cancelLocal: notificationId => this.call(_NativeInterfaces.NATIVE_COMMANDS.CANCEL_LOCAL_NOTIFICATION, notificationId),
|
|
279
|
+
/**
|
|
280
|
+
* Request notification permission
|
|
281
|
+
*/
|
|
282
|
+
requestPermission: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_NOTIFICATION_PERMISSION),
|
|
283
|
+
/**
|
|
284
|
+
* Register for push notifications
|
|
285
|
+
*/
|
|
286
|
+
registerForPush: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.REGISTER_FOR_PUSH_NOTIFICATIONS),
|
|
287
|
+
/**
|
|
288
|
+
* Update badge count
|
|
289
|
+
* @param {number} count - Badge count number
|
|
290
|
+
*/
|
|
291
|
+
updateBadge: count => this.call(_NativeInterfaces.NATIVE_COMMANDS.UPDATE_BADGE_COUNT, count?.toString()),
|
|
292
|
+
/**
|
|
293
|
+
* Subscribe to push notification topic
|
|
294
|
+
* @param {string} topic - Topic name to subscribe to
|
|
295
|
+
*/
|
|
296
|
+
subscribeToTopic: topic => this.call(_NativeInterfaces.NATIVE_COMMANDS.SUBSCRIBE_TO_TOPIC, JSON.stringify({
|
|
297
|
+
topic
|
|
298
|
+
})),
|
|
299
|
+
/**
|
|
300
|
+
* Unsubscribe from push notification topic
|
|
301
|
+
* @param {string} topic - Topic name to unsubscribe from
|
|
302
|
+
*/
|
|
303
|
+
unsubscribeFromTopic: topic => this.call(_NativeInterfaces.NATIVE_COMMANDS.UNSUBSCRIBE_FROM_TOPIC, JSON.stringify({
|
|
304
|
+
topic
|
|
305
|
+
})),
|
|
306
|
+
/**
|
|
307
|
+
* Get list of subscribed topics
|
|
308
|
+
*/
|
|
309
|
+
getSubscribedTopics: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SUBSCRIBED_TOPICS)
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Device info methods
|
|
314
|
+
*/
|
|
315
|
+
device = {
|
|
316
|
+
/**
|
|
317
|
+
* Get device information
|
|
318
|
+
* @returns {Promise} - Returns device info through callback
|
|
319
|
+
*/
|
|
320
|
+
getDeviceInfo: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_DEVICE_INFO)
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Auth methods
|
|
325
|
+
*/
|
|
326
|
+
auth = {
|
|
327
|
+
/**
|
|
328
|
+
* Trigger Google Sign-In (Credential Manager)
|
|
329
|
+
* @param {Object} options - config (clientId, nonce, autoSelect, etc.)
|
|
330
|
+
*/
|
|
331
|
+
googleSignIn: (options = {}) => {
|
|
332
|
+
const payload = options && typeof options === "object" ? JSON.stringify(options) : options?.toString?.();
|
|
333
|
+
return this.call(_NativeInterfaces.NATIVE_COMMANDS.GOOGLE_SIGN_IN, payload);
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
/** Safe area methods
|
|
338
|
+
*/
|
|
339
|
+
safeArea = {
|
|
340
|
+
/**
|
|
341
|
+
* Get current safe area insets
|
|
342
|
+
* Returns insets through ON_SAFE_AREA_INSETS_UPDATED callback
|
|
343
|
+
*/
|
|
344
|
+
get: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SAFE_AREA)
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Security methods
|
|
349
|
+
*/
|
|
350
|
+
security = {
|
|
351
|
+
/**
|
|
352
|
+
* Enable or disable FLAG_SECURE (prevents screenshots / app-switcher caching)
|
|
353
|
+
* @param {boolean} enable - true to secure, false to unsecure
|
|
354
|
+
*/
|
|
355
|
+
setScreenSecure: enable => this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_SCREEN_SECURE, JSON.stringify({
|
|
356
|
+
enable
|
|
357
|
+
})),
|
|
358
|
+
/**
|
|
359
|
+
* Query current FLAG_SECURE status
|
|
360
|
+
* Returns result through ON_SCREEN_SECURE_SET callback
|
|
361
|
+
*/
|
|
362
|
+
getScreenSecure: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SCREEN_SECURE),
|
|
363
|
+
/**
|
|
364
|
+
* Clear all WebView data (cache, history, cookies, WebStorage)
|
|
365
|
+
* Returns result through ON_WEB_DATA_CLEARED / ON_WEB_DATA_CLEAR_ERROR callback
|
|
366
|
+
*/
|
|
367
|
+
clearWebData: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.CLEAR_WEB_DATA)
|
|
368
|
+
};
|
|
369
|
+
transition = {
|
|
370
|
+
/**
|
|
371
|
+
* Begin a native transition — native takes a snapshot/overlay of the current screen.
|
|
372
|
+
* @param {Object} options
|
|
373
|
+
* type: 'slide' | 'fade'
|
|
374
|
+
* direction: 'left' | 'right' | 'up' | 'down' (slide only)
|
|
375
|
+
* duration: number (ms, default 300)
|
|
376
|
+
* timeout: number (ms, safety timer — native force-fades overlay if commitTransition is never called)
|
|
377
|
+
*/
|
|
378
|
+
start: (options = {}) => this.call(_NativeInterfaces.NATIVE_COMMANDS.START_TRANSITION, JSON.stringify(options)),
|
|
379
|
+
/**
|
|
380
|
+
* Commit the transition — native animates the snapshot overlay out, revealing the new page.
|
|
381
|
+
*/
|
|
382
|
+
commit: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.COMMIT_TRANSITION),
|
|
383
|
+
/**
|
|
384
|
+
* Cancel the transition — native removes the overlay immediately without animating.
|
|
385
|
+
*/
|
|
386
|
+
cancel: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.CANCEL_TRANSITION)
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Get environment info
|
|
391
|
+
*/
|
|
392
|
+
getEnvironmentInfo() {
|
|
393
|
+
return {
|
|
394
|
+
isAndroid: this.isAndroid,
|
|
395
|
+
isIOS: this.isIOS,
|
|
396
|
+
isNativeEnvironment: this.isNativeEnvironment,
|
|
397
|
+
platform: this.isAndroid ? "android" : this.isIOS ? "ios" : "web"
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Check if native bridge is available — live check, never stale
|
|
403
|
+
*/
|
|
404
|
+
isAvailable() {
|
|
405
|
+
return this._detectAndroid() || this._detectIOS();
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Debug method to test native bridge connectivity
|
|
410
|
+
*/
|
|
411
|
+
testConnection() {
|
|
412
|
+
console.group("🌉 NativeBridge Connection Test");
|
|
413
|
+
console.log("Environment:", this.getEnvironmentInfo());
|
|
414
|
+
console.log("Available commands:", Object.values(_NativeInterfaces.NATIVE_COMMANDS));
|
|
415
|
+
if (this.isAndroid && window.NativeBridge) {
|
|
416
|
+
console.log("Android bridge methods:", Object.getOwnPropertyNames(window.NativeBridge));
|
|
417
|
+
}
|
|
418
|
+
if (this.isIOS && window.webkit?.messageHandlers?.NativeBridge) {
|
|
419
|
+
console.log("iOS webkit bridge available");
|
|
420
|
+
}
|
|
421
|
+
console.groupEnd();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Export singleton instance
|
|
426
|
+
exports.NativeBridgeUtil = NativeBridgeUtil;
|
|
427
|
+
const nativeBridge = new NativeBridgeUtil();
|
|
428
|
+
var _default = exports.default = nativeBridge; // Also export the class for advanced usage
|