@simplysm/capacitor-plugin-broadcast 12.16.30 → 12.16.31
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 +112 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-broadcast
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for sending and receiving Android Broadcasts. Designed for integrating with industrial devices such as barcode scanners and PDAs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @simplysm/capacitor-plugin-broadcast
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Requirements
|
|
13
|
+
|
|
14
|
+
- `@capacitor/core` ^7.4.4
|
|
15
|
+
|
|
16
|
+
### Platform Support
|
|
17
|
+
|
|
18
|
+
| Platform | Supported |
|
|
19
|
+
|----------|-----------|
|
|
20
|
+
| Android | Yes |
|
|
21
|
+
| Web | Stub only (shows alert) |
|
|
22
|
+
|
|
23
|
+
## API
|
|
24
|
+
|
|
25
|
+
### `Broadcast`
|
|
26
|
+
|
|
27
|
+
Static utility class for sending and receiving Android Broadcasts.
|
|
28
|
+
|
|
29
|
+
#### `Broadcast.subscribe(filters, callback)`
|
|
30
|
+
|
|
31
|
+
Registers a broadcast receiver for the specified intent filters. Returns an unsubscribe function.
|
|
32
|
+
|
|
33
|
+
| Parameter | Type | Description |
|
|
34
|
+
|------------|------------------------------------------|-------------------------------------|
|
|
35
|
+
| `filters` | `string[]` | Intent action strings to listen for |
|
|
36
|
+
| `callback` | `(result: IBroadcastResult) => void` | Called when a matching broadcast is received |
|
|
37
|
+
|
|
38
|
+
**Returns:** `Promise<() => Promise<void>>` -- an async function that unregisters this receiver when called.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
42
|
+
|
|
43
|
+
const unsub = await Broadcast.subscribe(
|
|
44
|
+
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
45
|
+
(result) => {
|
|
46
|
+
console.log(result.action);
|
|
47
|
+
console.log(result.extras);
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Later, unsubscribe
|
|
52
|
+
await unsub();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### `Broadcast.unsubscribeAll()`
|
|
56
|
+
|
|
57
|
+
Unregisters all active broadcast receivers at once.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
await Broadcast.unsubscribeAll();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### `Broadcast.send(options)`
|
|
64
|
+
|
|
65
|
+
Sends a broadcast intent.
|
|
66
|
+
|
|
67
|
+
| Parameter | Type | Description |
|
|
68
|
+
|------------------|-------------------------------|------------------------------|
|
|
69
|
+
| `options.action` | `string` | Intent action string |
|
|
70
|
+
| `options.extras` | `Record<string, unknown>` (optional) | Extra data to include in the intent |
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
await Broadcast.send({
|
|
74
|
+
action: "com.symbol.datawedge.api.ACTION",
|
|
75
|
+
extras: {
|
|
76
|
+
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING",
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### `Broadcast.getLaunchIntent()`
|
|
82
|
+
|
|
83
|
+
Retrieves the intent that launched the app.
|
|
84
|
+
|
|
85
|
+
**Returns:** `Promise<IBroadcastResult>`
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
const intent = await Broadcast.getLaunchIntent();
|
|
89
|
+
console.log(intent.action);
|
|
90
|
+
console.log(intent.extras);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `IBroadcastResult`
|
|
94
|
+
|
|
95
|
+
Result object returned by `subscribe` callbacks and `getLaunchIntent`.
|
|
96
|
+
|
|
97
|
+
| Property | Type | Description |
|
|
98
|
+
|-----------|-------------------------------|--------------------|
|
|
99
|
+
| `action` | `string` (optional) | Broadcast action |
|
|
100
|
+
| `extras` | `Record<string, unknown>` (optional) | Extra data |
|
|
101
|
+
|
|
102
|
+
### `IBroadcastPlugin`
|
|
103
|
+
|
|
104
|
+
Low-level plugin interface registered via `registerPlugin`. Use the `Broadcast` class instead for a simpler API.
|
|
105
|
+
|
|
106
|
+
| Method | Signature |
|
|
107
|
+
|--------------------|--------------------------------------------------------------------------------------------|
|
|
108
|
+
| `subscribe` | `(options: { filters: string[] }, callback: (result: IBroadcastResult) => void) => Promise<{ id: string }>` |
|
|
109
|
+
| `unsubscribe` | `(options: { id: string }) => Promise<void>` |
|
|
110
|
+
| `unsubscribeAll` | `() => Promise<void>` |
|
|
111
|
+
| `send` | `(options: { action: string; extras?: Record<string, unknown> }) => Promise<void>` |
|
|
112
|
+
| `getLaunchIntent` | `() => Promise<IBroadcastResult>` |
|