@simplysm/capacitor-plugin-broadcast 13.0.97 → 13.0.98
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 +133 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-broadcast
|
|
2
|
+
|
|
3
|
+
Capacitor Broadcast Plugin -- send and receive Android broadcast intents for industrial device integration (barcode scanners, PDAs, etc.).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @simplysm/capacitor-plugin-broadcast
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API Overview
|
|
12
|
+
|
|
13
|
+
### Types
|
|
14
|
+
|
|
15
|
+
| API | Type | Description |
|
|
16
|
+
|-----|------|-------------|
|
|
17
|
+
| `BroadcastResult` | interface | Broadcast result containing `action` and `extras` |
|
|
18
|
+
|
|
19
|
+
### Interfaces
|
|
20
|
+
|
|
21
|
+
| API | Type | Description |
|
|
22
|
+
|-----|------|-------------|
|
|
23
|
+
| `BroadcastPlugin` | interface | Low-level Capacitor plugin interface for broadcast operations |
|
|
24
|
+
|
|
25
|
+
### Classes
|
|
26
|
+
|
|
27
|
+
| API | Type | Description |
|
|
28
|
+
|-----|------|-------------|
|
|
29
|
+
| `Broadcast` | abstract class | Android broadcast send/receive operations |
|
|
30
|
+
|
|
31
|
+
## `BroadcastResult`
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
interface BroadcastResult {
|
|
35
|
+
/** Broadcast action */
|
|
36
|
+
action?: string;
|
|
37
|
+
/** Extra data */
|
|
38
|
+
extras?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## `BroadcastPlugin`
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
interface BroadcastPlugin {
|
|
46
|
+
subscribe(
|
|
47
|
+
options: { filters: string[] },
|
|
48
|
+
callback: (result: BroadcastResult) => void,
|
|
49
|
+
): Promise<{ id: string }>;
|
|
50
|
+
unsubscribe(options: { id: string }): Promise<void>;
|
|
51
|
+
unsubscribeAll(): Promise<void>;
|
|
52
|
+
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
53
|
+
getLaunchIntent(): Promise<BroadcastResult>;
|
|
54
|
+
addListener(
|
|
55
|
+
eventName: "newIntent",
|
|
56
|
+
listenerFunc: (data: BroadcastResult) => void,
|
|
57
|
+
): Promise<PluginListenerHandle>;
|
|
58
|
+
removeAllListeners(): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Low-level Capacitor plugin interface. Use `Broadcast` static methods instead of calling this directly.
|
|
63
|
+
|
|
64
|
+
## `Broadcast`
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
abstract class Broadcast {
|
|
68
|
+
static async subscribe(
|
|
69
|
+
filters: string[],
|
|
70
|
+
callback: (result: BroadcastResult) => void,
|
|
71
|
+
): Promise<() => Promise<void>>;
|
|
72
|
+
|
|
73
|
+
static async unsubscribeAll(): Promise<void>;
|
|
74
|
+
|
|
75
|
+
static async send(options: {
|
|
76
|
+
action: string;
|
|
77
|
+
extras?: Record<string, unknown>;
|
|
78
|
+
}): Promise<void>;
|
|
79
|
+
|
|
80
|
+
static async getLaunchIntent(): Promise<BroadcastResult>;
|
|
81
|
+
|
|
82
|
+
static async addListener(
|
|
83
|
+
eventName: "newIntent",
|
|
84
|
+
callback: (result: BroadcastResult) => void,
|
|
85
|
+
): Promise<PluginListenerHandle>;
|
|
86
|
+
|
|
87
|
+
static async removeAllListeners(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Usage Examples
|
|
92
|
+
|
|
93
|
+
### Subscribe to broadcasts
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
97
|
+
|
|
98
|
+
const unsub = await Broadcast.subscribe(
|
|
99
|
+
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
100
|
+
(result) => {
|
|
101
|
+
// handle result.action, result.extras
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Later: unsubscribe
|
|
106
|
+
await unsub();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Send a broadcast
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
113
|
+
|
|
114
|
+
await Broadcast.send({
|
|
115
|
+
action: "com.symbol.datawedge.api.ACTION",
|
|
116
|
+
extras: {
|
|
117
|
+
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING",
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Listen for new intents
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
126
|
+
|
|
127
|
+
const handle = await Broadcast.addListener("newIntent", (result) => {
|
|
128
|
+
// handle intent
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Later: remove listener
|
|
132
|
+
await handle.remove();
|
|
133
|
+
```
|