despia-native 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -17,7 +17,7 @@ Despia provides native device capabilities to web applications through a simple
17
17
  ## Installation
18
18
 
19
19
  ```bash
20
- npm install despia
20
+ npm install despia-native
21
21
  ```
22
22
 
23
23
  ## Usage
@@ -25,7 +25,7 @@ npm install despia
25
25
  ### Basic Despia Command Execution
26
26
 
27
27
  ```javascript
28
- import despia from 'despia';
28
+ import despia from 'despia-native';
29
29
 
30
30
  // Execute a Despia protocol command (no response needed)
31
31
  despia('lighthaptic://');
@@ -403,7 +403,7 @@ Your app can access these native features:
403
403
  Full TypeScript definitions are included:
404
404
 
405
405
  ```typescript
406
- import despia from 'despia';
406
+ import despia from 'despia-native';
407
407
 
408
408
  // Type-safe usage with Despia commands
409
409
  const result: { versionNumber: string; bundleNumber: string } = await despia(
@@ -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.d.ts CHANGED
@@ -103,7 +103,7 @@ interface DespiaFunction {
103
103
  *
104
104
  * @example
105
105
  * ```typescript
106
- * import despia from 'despia';
106
+ * import despia from 'despia-native';
107
107
  *
108
108
  * // Execute Despia protocol commands
109
109
  * await despia('applinks://open?url=https://maps.apple.com');
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.3",
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",