despia-native 1.0.13 → 1.0.15

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.
Files changed (3) hide show
  1. package/README.md +13 -3
  2. package/index.js +20 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Despia SDK
2
2
 
3
+ JavaScript SDK for [Despia](https://despia.com) - Add real native device features to your React web app, Vue app, Angular app, or any web framework. Transform your web app into a native iOS & Android app without writing Swift or Kotlin. This npm package provides command queuing and variable watching for seamless integration with Despia's GPU-accelerated native runtime, enabling access to 25+ device APIs through simple JavaScript calls.
4
+
5
+ ---
6
+
3
7
  ## Quick Start
4
8
 
5
9
  **Install the SDK:**
@@ -22,8 +26,6 @@ const appInfo = await despia('getappversion://', ['versionNumber']);
22
26
 
23
27
  ---
24
28
 
25
- JavaScript SDK for [Despia](https://despia.com) - Add native device features to your React web app, Vue app, Angular app, or any web framework. Transform your web app into a native iOS & Android app without writing Swift or Kotlin. This npm package provides command queuing and variable watching for seamless integration with Despia's GPU-accelerated native runtime, enabling access to 25+ device APIs through simple JavaScript calls.
26
-
27
29
  **Note: This is for web apps (React, Vue, Angular, etc.) to add native features - NOT for React Native apps.**
28
30
 
29
31
  ## Web Apps vs React Native
@@ -638,9 +640,17 @@ These CSS variables are automatically provided by the Despia native runtime and
638
640
  - **watch** (string[], optional): Array of variable names to watch for in the response
639
641
 
640
642
  Returns a Promise that resolves when all watched variables are available:
641
- - **Single variable**: 5-second timeout with simple observation
643
+ - **Single variable**: 30-second timeout with simple observation (Promise always resolves; on timeout it resolves with `undefined`)
642
644
  - **Multiple variables**: Uses VariableTracker with 5-minute auto-cleanup
643
645
 
646
+ ### Timeout behavior
647
+
648
+ When you call `despia(command, ['someVariable'])`, the SDK waits up to 30 seconds for
649
+ `window.someVariable` to be set by the native runtime. If it appears earlier, the
650
+ Promise resolves with that value. If it is never set, the Promise still resolves
651
+ after 30 seconds with `undefined` and a timeout is logged to the console. This
652
+ prevents hanging Promises for long-running or failing native operations.
653
+
644
654
  ### Direct Property Access
645
655
 
646
656
  Access any window variable directly through the despia object:
package/index.js CHANGED
@@ -42,20 +42,29 @@
42
42
  }
43
43
  }
44
44
 
45
- // Simple variable observer with 5-second timeout
46
- function observeDespiaVariable(variableName, callback, timeout = 5000) {
45
+ // Simple variable observer with longer timeout and guaranteed resolve
46
+ function observeDespiaVariable(variableName, callback, timeout = 30000) {
47
47
  const startTime = Date.now();
48
-
48
+
49
49
  function checkVariable() {
50
- if (window[variableName] !== undefined) {
51
- callback(window[variableName]);
52
- } else if (Date.now() - startTime < timeout) {
50
+ const val = window[variableName];
51
+
52
+ // Preserve existing semantics: any non-undefined value is "ready"
53
+ if (val !== undefined) {
54
+ callback(val);
55
+ return;
56
+ }
57
+
58
+ if (Date.now() - startTime < timeout) {
53
59
  setTimeout(checkVariable, 100);
54
- } else {
55
- console.error(`Despia timeout: ${variableName} was not set within ${timeout} ms`);
60
+ return;
56
61
  }
62
+
63
+ console.error(`Despia timeout: ${variableName} was not set within ${timeout} ms`);
64
+ // Ensure promises watching this variable never hang forever
65
+ callback(undefined);
57
66
  }
58
-
67
+
59
68
  checkVariable();
60
69
  }
61
70
 
@@ -125,11 +134,11 @@
125
134
  }
126
135
 
127
136
  if (variables.length === 1) {
128
- // Simple single variable observation with 5-second timeout
137
+ // Simple single variable observation with 30-second timeout
129
138
  return new Promise((resolve) => {
130
139
  observeDespiaVariable(variables[0], (value) => {
131
140
  resolve({ [variables[0]]: value });
132
- }, 5000);
141
+ }, 30000);
133
142
  });
134
143
  } else {
135
144
  // Multiple variables - use VariableTracker (no timeout, expires after 5 minutes)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "despia-native",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "JavaScript SDK for Despia native integrations with command queuing and variable watching",
5
5
  "main": "index.js",
6
6
  "module": "index.js",