@farcaster/frame-sdk 0.0.37 → 0.0.38
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/dist/index.min.js +2 -2
- package/dist/index.min.js.map +3 -3
- package/dist/sdk.js +37 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/sdk.ts +43 -0
- package/src/types.ts +1 -0
package/dist/sdk.js
CHANGED
|
@@ -24,8 +24,45 @@ export function createEmitter() {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
const emitter = createEmitter();
|
|
27
|
+
let cachedIsInMiniAppResult = null;
|
|
28
|
+
/**
|
|
29
|
+
* Determines if the current environment is a MiniApp context.
|
|
30
|
+
*
|
|
31
|
+
* @param timeoutMs - Optional timeout in milliseconds (default: 50)
|
|
32
|
+
* @returns Promise resolving to boolean indicating if in MiniApp context
|
|
33
|
+
*/
|
|
34
|
+
async function isInMiniApp(timeoutMs = 50) {
|
|
35
|
+
// Return cached result if we've already determined we are in a MiniApp
|
|
36
|
+
if (cachedIsInMiniAppResult === true) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
// Check for SSR environment - definitely not a MiniApp
|
|
40
|
+
if (typeof window === 'undefined') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Short-circuit: definitely NOT a MiniApp
|
|
44
|
+
if (!window.ReactNativeWebView && window === window.parent) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// At this point, we MIGHT be in a MiniApp (iframe or RN WebView)
|
|
48
|
+
// but need to verify by checking for context communication.
|
|
49
|
+
const isInMiniApp = await Promise.race([
|
|
50
|
+
frameHost.context.then((context) => !!context), // Check if context resolves to truthy
|
|
51
|
+
new Promise((resolve) => {
|
|
52
|
+
setTimeout(() => resolve(false), timeoutMs); // Timeout resolves to false
|
|
53
|
+
}),
|
|
54
|
+
]).catch(() => {
|
|
55
|
+
return false;
|
|
56
|
+
});
|
|
57
|
+
// Cache the result ONLY if true (we are confirmed to be in a MiniApp)
|
|
58
|
+
if (isInMiniApp) {
|
|
59
|
+
cachedIsInMiniAppResult = true;
|
|
60
|
+
}
|
|
61
|
+
return isInMiniApp;
|
|
62
|
+
}
|
|
27
63
|
export const sdk = {
|
|
28
64
|
...emitter,
|
|
65
|
+
isInMiniApp,
|
|
29
66
|
context: frameHost.context,
|
|
30
67
|
actions: {
|
|
31
68
|
setPrimaryButton: frameHost.setPrimaryButton.bind(frameHost),
|