despia-native 1.0.1 → 1.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.
Files changed (3) hide show
  1. package/README.md +15 -2
  2. package/index.js +8 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -419,11 +419,24 @@ const deviceInfo: any = despia.deviceInfo;
419
419
 
420
420
  This SDK is designed to work with [Despia's native integration system](https://docs.despia.com/docs/native-integrations/getting-started). The SDK provides:
421
421
 
422
- - **Command Queuing** - Sequential execution of Despia commands
422
+ - **Command Queuing** - Sequential execution of Despia commands via `window.despia` setter
423
423
  - **Variable Watching** - Async monitoring of response variables
424
- - **Timeout Handling** - Configurable timeouts for long-running operations
424
+ - **iOS Web View Compatible** - Works with Despia's iOS web view wrapper
425
425
  - **Direct Access** - Proxy-based access to window variables
426
426
 
427
+ ### How It Works
428
+
429
+ The SDK uses the setter pattern to execute commands:
430
+ ```javascript
431
+ // When you call:
432
+ despia('lighthaptic://');
433
+
434
+ // It internally executes:
435
+ window.despia = 'lighthaptic://';
436
+ ```
437
+
438
+ This triggers the iOS web view wrapper's setter function to handle the native command.
439
+
427
440
  ## License
428
441
 
429
442
  MIT
package/index.js CHANGED
@@ -19,11 +19,14 @@
19
19
  if (processing || commandQueue.length === 0) return;
20
20
 
21
21
  processing = true;
22
- const { command, native } = commandQueue.shift();
22
+ const { command } = commandQueue.shift();
23
23
 
24
24
  try {
25
- native({ command });
26
- } catch (e) {}
25
+ // Use the setter pattern: window.despia = command
26
+ window.despia = command;
27
+ } catch (e) {
28
+ console.error('Despia command failed:', e);
29
+ }
27
30
 
28
31
  setTimeout(() => {
29
32
  processing = false;
@@ -33,12 +36,8 @@
33
36
 
34
37
  // Add command to queue
35
38
  function queueCommand(command) {
36
- const native = typeof window !== 'undefined'
37
- ? window.despia
38
- : (typeof global !== 'undefined' ? global.despia : null);
39
-
40
- if (native) {
41
- commandQueue.push({ command, native });
39
+ if (typeof window !== 'undefined') {
40
+ commandQueue.push({ command });
42
41
  processQueue();
43
42
  }
44
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "despia-native",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",