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.
- package/README.md +15 -2
- package/index.js +8 -9
- 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
|
-
- **
|
|
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
|
|
22
|
+
const { command } = commandQueue.shift();
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
}
|