@simplysm/capacitor-plugin-broadcast 13.0.68 → 13.0.70
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 +10 -242
- package/dist/Broadcast.d.ts +10 -10
- package/dist/Broadcast.js +8 -8
- package/dist/IBroadcastPlugin.d.ts +6 -6
- package/dist/web/BroadcastWeb.d.ts.map +1 -1
- package/dist/web/BroadcastWeb.js +1 -1
- package/dist/web/BroadcastWeb.js.map +1 -1
- package/package.json +4 -3
- package/src/Broadcast.ts +87 -0
- package/src/IBroadcastPlugin.ts +46 -0
- package/src/index.ts +3 -0
- package/src/web/BroadcastWeb.ts +33 -0
package/README.md
CHANGED
|
@@ -1,254 +1,22 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-broadcast
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
It provides features including BroadcastReceiver registration/unregistration, Intent sending, app launch Intent retrieval, and new Intent reception listeners.
|
|
3
|
+
Simplysm Package - Capacitor Broadcast Plugin
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
npm install @simplysm/capacitor-plugin-broadcast
|
|
11
|
-
npx cap sync
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Supported Platforms
|
|
15
|
-
|
|
16
|
-
| Platform | Supported | Notes |
|
|
17
|
-
|--------|----------|------|
|
|
18
|
-
| Android | Yes | Native BroadcastReceiver implementation |
|
|
19
|
-
| iOS | No | Not supported |
|
|
20
|
-
| Web | Partial | Stub implementation (outputs warning messages, no actual functionality) |
|
|
21
|
-
|
|
22
|
-
## Main Modules
|
|
23
|
-
|
|
24
|
-
### `Broadcast` Class
|
|
25
|
-
|
|
26
|
-
A wrapper class consisting only of static methods. Access the native plugin through this class instead of using it directly.
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
| Method | Signature | Return Type | Description |
|
|
33
|
-
|--------|-----------|----------|------|
|
|
34
|
-
| `subscribe` | `(filters: string[], callback: (result: IBroadcastResult) => void)` | `Promise<() => Promise<void>>` | Registers a Broadcast receiver and returns an unsubscribe function |
|
|
35
|
-
| `unsubscribeAll` | `()` | `Promise<void>` | Unregisters all registered Broadcast receivers |
|
|
36
|
-
| `send` | `(options: { action: string; extras?: Record<string, unknown> })` | `Promise<void>` | Sends a Broadcast Intent |
|
|
37
|
-
| `getLaunchIntent` | `()` | `Promise<IBroadcastResult>` | Retrieves the Intent information that launched the app |
|
|
38
|
-
| `addNewIntentListener` | `(callback: (result: IBroadcastResult) => void)` | `Promise<PluginListenerHandle>` | Registers a listener for new Intents received while the app is running |
|
|
39
|
-
|
|
40
|
-
### `IBroadcastResult` Interface
|
|
41
|
-
|
|
42
|
-
An interface representing Broadcast reception results or Intent information.
|
|
43
|
-
|
|
44
|
-
| Property | Type | Description |
|
|
45
|
-
|------|------|------|
|
|
46
|
-
| `action` | `string \| undefined` | Broadcast action string |
|
|
47
|
-
| `extras` | `Record<string, unknown> \| undefined` | Additional data included in the Intent |
|
|
48
|
-
|
|
49
|
-
### `IBroadcastPlugin` Interface
|
|
50
|
-
|
|
51
|
-
The low-level Capacitor plugin interface. In most cases, use the `Broadcast` wrapper class instead of this interface directly. It is exported for advanced use cases such as custom plugin registration.
|
|
52
|
-
|
|
53
|
-
| Method | Signature | Return Type | Description |
|
|
54
|
-
|--------|-----------|----------|------|
|
|
55
|
-
| `subscribe` | `(options: { filters: string[] }, callback: (result: IBroadcastResult) => void)` | `Promise<{ id: string }>` | Register a BroadcastReceiver with intent filters |
|
|
56
|
-
| `unsubscribe` | `(options: { id: string })` | `Promise<void>` | Unregister a specific BroadcastReceiver by ID |
|
|
57
|
-
| `unsubscribeAll` | `()` | `Promise<void>` | Unregister all BroadcastReceivers |
|
|
58
|
-
| `send` | `(options: { action: string; extras?: Record<string, unknown> })` | `Promise<void>` | Send a Broadcast Intent |
|
|
59
|
-
| `getLaunchIntent` | `()` | `Promise<IBroadcastResult>` | Retrieve the launch Intent |
|
|
60
|
-
| `addListener` | `(eventName: "onNewIntent", listenerFunc: (data: IBroadcastResult) => void)` | `Promise<PluginListenerHandle>` | Listen for new Intents while the app is running |
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
import type { IBroadcastPlugin, IBroadcastResult } from "@simplysm/capacitor-plugin-broadcast";
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Usage Examples
|
|
67
|
-
|
|
68
|
-
### Receiving Broadcasts
|
|
69
|
-
|
|
70
|
-
Registers a Broadcast receiver for specific actions. `subscribe` returns an unsubscribe function that can be called to remove the receiver.
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
74
|
-
|
|
75
|
-
// Register Broadcast receiver
|
|
76
|
-
const unsubscribe = await Broadcast.subscribe(
|
|
77
|
-
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
78
|
-
(result) => {
|
|
79
|
-
console.log("Action:", result.action);
|
|
80
|
-
console.log("Extras:", result.extras);
|
|
81
|
-
},
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
// Unsubscribe receiver
|
|
85
|
-
await unsubscribe();
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
You can also filter multiple actions simultaneously.
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
const unsubscribe = await Broadcast.subscribe(
|
|
92
|
-
[
|
|
93
|
-
"com.symbol.datawedge.api.RESULT_ACTION",
|
|
94
|
-
"com.symbol.datawedge.api.NOTIFICATION_ACTION",
|
|
95
|
-
],
|
|
96
|
-
(result) => {
|
|
97
|
-
switch (result.action) {
|
|
98
|
-
case "com.symbol.datawedge.api.RESULT_ACTION":
|
|
99
|
-
// Handle result
|
|
100
|
-
break;
|
|
101
|
-
case "com.symbol.datawedge.api.NOTIFICATION_ACTION":
|
|
102
|
-
// Handle notification
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Unsubscribe All Receivers
|
|
110
|
-
|
|
111
|
-
Unregisters all registered Broadcast receivers at once. Use this for cleanup when the app exits or during screen transitions.
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
115
|
-
|
|
116
|
-
await Broadcast.unsubscribeAll();
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Sending Broadcasts
|
|
120
|
-
|
|
121
|
-
Sends a Broadcast Intent to other apps or the system. You can include additional data as key-value pairs in `extras`.
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
125
|
-
|
|
126
|
-
await Broadcast.send({
|
|
127
|
-
action: "com.symbol.datawedge.api.ACTION",
|
|
128
|
-
extras: {
|
|
129
|
-
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING",
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
`extras` can contain various types of values.
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
await Broadcast.send({
|
|
138
|
-
action: "com.example.MY_ACTION",
|
|
139
|
-
extras: {
|
|
140
|
-
stringValue: "hello",
|
|
141
|
-
numberValue: 42,
|
|
142
|
-
booleanValue: true,
|
|
143
|
-
arrayValue: ["item1", "item2"],
|
|
144
|
-
nestedValue: {
|
|
145
|
-
key: "value",
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### Retrieving Launch Intent
|
|
152
|
-
|
|
153
|
-
If the app was started through an Intent from another app, you can retrieve that Intent information.
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
157
|
-
|
|
158
|
-
const launchIntent = await Broadcast.getLaunchIntent();
|
|
159
|
-
if (launchIntent.action != null) {
|
|
160
|
-
console.log("Launch Action:", launchIntent.action);
|
|
161
|
-
console.log("Launch Extras:", launchIntent.extras);
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### New Intent Listener
|
|
166
|
-
|
|
167
|
-
Detects when a new Intent is received while the app is already running. Remove the listener using the `remove()` method of the returned `PluginListenerHandle`.
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
171
|
-
|
|
172
|
-
const handle = await Broadcast.addNewIntentListener((result) => {
|
|
173
|
-
console.log("New Intent received:", result.action);
|
|
174
|
-
console.log("Extras:", result.extras);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
// Remove listener
|
|
178
|
-
await handle.remove();
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### DataWedge Integration Example (Zebra Devices)
|
|
182
|
-
|
|
183
|
-
A real-world usage pattern for integrating with industrial barcode scanners (Zebra DataWedge).
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
187
|
-
|
|
188
|
-
// Register barcode scan result receiver
|
|
189
|
-
const unsubscribe = await Broadcast.subscribe(
|
|
190
|
-
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
191
|
-
(result) => {
|
|
192
|
-
const barcode = result.extras?.["com.symbol.datawedge.data_string"];
|
|
193
|
-
if (barcode != null) {
|
|
194
|
-
console.log("Scanned barcode:", barcode);
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
// Trigger soft scan
|
|
200
|
-
await Broadcast.send({
|
|
201
|
-
action: "com.symbol.datawedge.api.ACTION",
|
|
202
|
-
extras: {
|
|
203
|
-
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING",
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Supported Extras Types
|
|
209
|
-
|
|
210
|
-
The types of values that can be included in `extras` when calling `send()`, and the types they are converted to when received, are as follows.
|
|
211
|
-
|
|
212
|
-
### When Sending (TypeScript -> Android Intent)
|
|
213
|
-
|
|
214
|
-
| TypeScript Type | Android Intent Type |
|
|
215
|
-
|----------------|-------------------|
|
|
216
|
-
| `string` | `String` |
|
|
217
|
-
| `number` (integer) | `Integer` |
|
|
218
|
-
| `number` (decimal) | `Double` |
|
|
219
|
-
| `boolean` | `Boolean` |
|
|
220
|
-
| `string[]` | `String[]` |
|
|
221
|
-
| Nested object | `Bundle` |
|
|
222
|
-
|
|
223
|
-
### When Receiving (Android Intent -> TypeScript)
|
|
224
|
-
|
|
225
|
-
| Android Type | TypeScript Type |
|
|
226
|
-
|-------------|----------------|
|
|
227
|
-
| `String` | `string` |
|
|
228
|
-
| `Integer` | `number` |
|
|
229
|
-
| `Long` | `number` |
|
|
230
|
-
| `Double` | `number` |
|
|
231
|
-
| `Float` | `number` |
|
|
232
|
-
| `Boolean` | `boolean` |
|
|
233
|
-
| `Bundle` | Nested object |
|
|
234
|
-
| `String[]` | `string[]` |
|
|
235
|
-
| `int[]` | `number[]` |
|
|
236
|
-
| `Parcelable` | `string` (toString) |
|
|
237
|
-
|
|
238
|
-
## Lifecycle Management
|
|
7
|
+
pnpm add @simplysm/capacitor-plugin-broadcast
|
|
239
8
|
|
|
240
|
-
|
|
241
|
-
- On Android 13 (API 33, Tiramisu) and above, receivers are registered using the `RECEIVER_EXPORTED` flag.
|
|
242
|
-
- To prevent memory leaks, it is recommended to unregister receivers that are no longer needed using the returned unsubscribe function or `unsubscribeAll()`.
|
|
9
|
+
**Peer Dependencies:** `@capacitor/core ^7.4.4`
|
|
243
10
|
|
|
244
|
-
##
|
|
11
|
+
## Source Index
|
|
245
12
|
|
|
246
|
-
###
|
|
13
|
+
### Broadcast
|
|
247
14
|
|
|
248
|
-
|
|
|
249
|
-
|
|
250
|
-
|
|
|
15
|
+
| Source | Exports | Description | Test |
|
|
16
|
+
|--------|---------|-------------|------|
|
|
17
|
+
| `src/Broadcast.ts` | `Broadcast` | Static class to send, subscribe, and listen to Android broadcast intents | - |
|
|
18
|
+
| `src/IBroadcastPlugin.ts` | `IBroadcastResult`, `IBroadcastPlugin` | Interfaces for broadcast result data and the native broadcast plugin contract | - |
|
|
251
19
|
|
|
252
20
|
## License
|
|
253
21
|
|
|
254
|
-
|
|
22
|
+
Apache-2.0
|
package/dist/Broadcast.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { PluginListenerHandle } from "@capacitor/core";
|
|
2
2
|
import type { IBroadcastResult } from "./IBroadcastPlugin";
|
|
3
3
|
/**
|
|
4
|
-
* Android Broadcast
|
|
5
|
-
* -
|
|
4
|
+
* Android Broadcast send/receive plugin
|
|
5
|
+
* - For industrial device integration (barcode scanners, PDAs, etc.)
|
|
6
6
|
*/
|
|
7
7
|
export declare abstract class Broadcast {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @returns
|
|
9
|
+
* Register broadcast receiver
|
|
10
|
+
* @returns Unsubscribe function
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
@@ -16,17 +16,17 @@ export declare abstract class Broadcast {
|
|
|
16
16
|
* (result) => console.log(result.extras)
|
|
17
17
|
* );
|
|
18
18
|
*
|
|
19
|
-
* //
|
|
19
|
+
* // Unsubscribe
|
|
20
20
|
* unsub();
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
static subscribe(filters: string[], callback: (result: IBroadcastResult) => void): Promise<() => Promise<void>>;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Unsubscribe all broadcast receivers
|
|
26
26
|
*/
|
|
27
27
|
static unsubscribeAll(): Promise<void>;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Send broadcast
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* ```ts
|
|
@@ -43,12 +43,12 @@ export declare abstract class Broadcast {
|
|
|
43
43
|
extras?: Record<string, unknown>;
|
|
44
44
|
}): Promise<void>;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Get launch intent
|
|
47
47
|
*/
|
|
48
48
|
static getLaunchIntent(): Promise<IBroadcastResult>;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
* @returns
|
|
50
|
+
* Register listener for new intents received while app is running
|
|
51
|
+
* @returns Listener handle (release with remove())
|
|
52
52
|
*/
|
|
53
53
|
static addNewIntentListener(callback: (result: IBroadcastResult) => void): Promise<PluginListenerHandle>;
|
|
54
54
|
}
|
package/dist/Broadcast.js
CHANGED
|
@@ -7,8 +7,8 @@ const BroadcastPlugin = registerPlugin("Broadcast", {
|
|
|
7
7
|
});
|
|
8
8
|
class Broadcast {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @returns
|
|
10
|
+
* Register broadcast receiver
|
|
11
|
+
* @returns Unsubscribe function
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
@@ -17,7 +17,7 @@ class Broadcast {
|
|
|
17
17
|
* (result) => console.log(result.extras)
|
|
18
18
|
* );
|
|
19
19
|
*
|
|
20
|
-
* //
|
|
20
|
+
* // Unsubscribe
|
|
21
21
|
* unsub();
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
@@ -32,13 +32,13 @@ class Broadcast {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Unsubscribe all broadcast receivers
|
|
36
36
|
*/
|
|
37
37
|
static async unsubscribeAll() {
|
|
38
38
|
await BroadcastPlugin.unsubscribeAll();
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Send broadcast
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
@@ -54,14 +54,14 @@ class Broadcast {
|
|
|
54
54
|
await BroadcastPlugin.send(options);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Get launch intent
|
|
58
58
|
*/
|
|
59
59
|
static async getLaunchIntent() {
|
|
60
60
|
return BroadcastPlugin.getLaunchIntent();
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @returns
|
|
63
|
+
* Register listener for new intents received while app is running
|
|
64
|
+
* @returns Listener handle (release with remove())
|
|
65
65
|
*/
|
|
66
66
|
static async addNewIntentListener(callback) {
|
|
67
67
|
return BroadcastPlugin.addListener("onNewIntent", callback);
|
|
@@ -7,7 +7,7 @@ export interface IBroadcastResult {
|
|
|
7
7
|
}
|
|
8
8
|
export interface IBroadcastPlugin {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Register broadcast receiver
|
|
11
11
|
*/
|
|
12
12
|
subscribe(options: {
|
|
13
13
|
filters: string[];
|
|
@@ -15,28 +15,28 @@ export interface IBroadcastPlugin {
|
|
|
15
15
|
id: string;
|
|
16
16
|
}>;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Unsubscribe a specific broadcast receiver
|
|
19
19
|
*/
|
|
20
20
|
unsubscribe(options: {
|
|
21
21
|
id: string;
|
|
22
22
|
}): Promise<void>;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Unsubscribe all broadcast receivers
|
|
25
25
|
*/
|
|
26
26
|
unsubscribeAll(): Promise<void>;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Send broadcast
|
|
29
29
|
*/
|
|
30
30
|
send(options: {
|
|
31
31
|
action: string;
|
|
32
32
|
extras?: Record<string, unknown>;
|
|
33
33
|
}): Promise<void>;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Get launch intent
|
|
36
36
|
*/
|
|
37
37
|
getLaunchIntent(): Promise<IBroadcastResult>;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Register listener for new intents received while app is running
|
|
40
40
|
*/
|
|
41
41
|
addListener(eventName: "onNewIntent", listenerFunc: (data: IBroadcastResult) => void): Promise<PluginListenerHandle>;
|
|
42
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BroadcastWeb.d.ts","sourceRoot":"","sources":["../../src/web/BroadcastWeb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,qBAAa,YAAa,SAAQ,SAAU,YAAW,gBAAgB;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"BroadcastWeb.d.ts","sourceRoot":"","sources":["../../src/web/BroadcastWeb.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,qBAAa,YAAa,SAAQ,SAAU,YAAW,gBAAgB;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAEgD;IAE7E,SAAS,CACP,QAAQ,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAC/B,SAAS,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAC5C,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAKpB,WAAW,CAAC,QAAQ,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrC,IAAI,CAAC,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnF,eAAe,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAG7C"}
|
package/dist/web/BroadcastWeb.js
CHANGED
|
@@ -2,7 +2,7 @@ import { WebPlugin } from "@capacitor/core";
|
|
|
2
2
|
class BroadcastWeb extends WebPlugin {
|
|
3
3
|
static _warn = () => (
|
|
4
4
|
// eslint-disable-next-line no-console
|
|
5
|
-
console.warn("[Broadcast]
|
|
5
|
+
console.warn("[Broadcast] Broadcast is not supported in web environment.")
|
|
6
6
|
);
|
|
7
7
|
subscribe(_options, _callback) {
|
|
8
8
|
BroadcastWeb._warn();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/web/BroadcastWeb.ts"],
|
|
4
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAGnB,MAAM,qBAAqB,UAAsC;AAAA,EACtE,OAAwB,QAAQ;AAAA;AAAA,IAE9B,QAAQ,KAAK,
|
|
4
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAGnB,MAAM,qBAAqB,UAAsC;AAAA,EACtE,OAAwB,QAAQ;AAAA;AAAA,IAE9B,QAAQ,KAAK,4DAA4D;AAAA;AAAA,EAE3E,UACE,UACA,WACyB;AACzB,iBAAa,MAAM;AACnB,WAAO,QAAQ,QAAQ,EAAE,IAAI,WAAW,CAAC;AAAA,EAC3C;AAAA,EAEA,MAAM,YAAY,UAAyC;AAAA,EAE3D;AAAA,EAEA,MAAM,iBAAgC;AAAA,EAEtC;AAAA,EAEA,KAAK,UAA+E;AAClF,iBAAa,MAAM;AACnB,WAAO,QAAQ,QAAQ;AAAA,EACzB;AAAA,EAEA,kBAA6C;AAC3C,WAAO,QAAQ,QAAQ,CAAC,CAAC;AAAA,EAC3B;AACF;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-broadcast",
|
|
3
|
-
"version": "13.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "13.0.70",
|
|
4
|
+
"description": "Simplysm Package - Capacitor Broadcast Plugin",
|
|
5
|
+
"author": "simplysm",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
+
"src",
|
|
17
18
|
"android"
|
|
18
19
|
],
|
|
19
20
|
"devDependencies": {
|
package/src/Broadcast.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { registerPlugin } from "@capacitor/core";
|
|
2
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
|
3
|
+
import type { IBroadcastPlugin, IBroadcastResult } from "./IBroadcastPlugin";
|
|
4
|
+
|
|
5
|
+
const BroadcastPlugin = registerPlugin<IBroadcastPlugin>("Broadcast", {
|
|
6
|
+
web: async () => {
|
|
7
|
+
const { BroadcastWeb } = await import("./web/BroadcastWeb");
|
|
8
|
+
return new BroadcastWeb();
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Android Broadcast send/receive plugin
|
|
14
|
+
* - For industrial device integration (barcode scanners, PDAs, etc.)
|
|
15
|
+
*/
|
|
16
|
+
export abstract class Broadcast {
|
|
17
|
+
/**
|
|
18
|
+
* Register broadcast receiver
|
|
19
|
+
* @returns Unsubscribe function
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const unsub = await Broadcast.subscribe(
|
|
24
|
+
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
25
|
+
* (result) => console.log(result.extras)
|
|
26
|
+
* );
|
|
27
|
+
*
|
|
28
|
+
* // Unsubscribe
|
|
29
|
+
* unsub();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
static async subscribe(
|
|
33
|
+
filters: string[],
|
|
34
|
+
callback: (result: IBroadcastResult) => void,
|
|
35
|
+
): Promise<() => Promise<void>> {
|
|
36
|
+
const { id } = await BroadcastPlugin.subscribe({ filters }, (result) => {
|
|
37
|
+
// Filter out the initial resolve that only contains { id }
|
|
38
|
+
if (result.action != null) {
|
|
39
|
+
callback(result);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return async () => {
|
|
43
|
+
await BroadcastPlugin.unsubscribe({ id });
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Unsubscribe all broadcast receivers
|
|
49
|
+
*/
|
|
50
|
+
static async unsubscribeAll(): Promise<void> {
|
|
51
|
+
await BroadcastPlugin.unsubscribeAll();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Send broadcast
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* await Broadcast.send({
|
|
60
|
+
* action: "com.symbol.datawedge.api.ACTION",
|
|
61
|
+
* extras: {
|
|
62
|
+
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
63
|
+
* }
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
static async send(options: { action: string; extras?: Record<string, unknown> }): Promise<void> {
|
|
68
|
+
await BroadcastPlugin.send(options);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get launch intent
|
|
73
|
+
*/
|
|
74
|
+
static async getLaunchIntent(): Promise<IBroadcastResult> {
|
|
75
|
+
return BroadcastPlugin.getLaunchIntent();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Register listener for new intents received while app is running
|
|
80
|
+
* @returns Listener handle (release with remove())
|
|
81
|
+
*/
|
|
82
|
+
static async addNewIntentListener(
|
|
83
|
+
callback: (result: IBroadcastResult) => void,
|
|
84
|
+
): Promise<PluginListenerHandle> {
|
|
85
|
+
return BroadcastPlugin.addListener("onNewIntent", callback);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
|
2
|
+
|
|
3
|
+
export interface IBroadcastResult {
|
|
4
|
+
/** Broadcast action */
|
|
5
|
+
action?: string;
|
|
6
|
+
/** Extra data */
|
|
7
|
+
extras?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IBroadcastPlugin {
|
|
11
|
+
/**
|
|
12
|
+
* Register broadcast receiver
|
|
13
|
+
*/
|
|
14
|
+
subscribe(
|
|
15
|
+
options: { filters: string[] },
|
|
16
|
+
callback: (result: IBroadcastResult) => void,
|
|
17
|
+
): Promise<{ id: string }>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Unsubscribe a specific broadcast receiver
|
|
21
|
+
*/
|
|
22
|
+
unsubscribe(options: { id: string }): Promise<void>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Unsubscribe all broadcast receivers
|
|
26
|
+
*/
|
|
27
|
+
unsubscribeAll(): Promise<void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Send broadcast
|
|
31
|
+
*/
|
|
32
|
+
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get launch intent
|
|
36
|
+
*/
|
|
37
|
+
getLaunchIntent(): Promise<IBroadcastResult>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Register listener for new intents received while app is running
|
|
41
|
+
*/
|
|
42
|
+
addListener(
|
|
43
|
+
eventName: "onNewIntent",
|
|
44
|
+
listenerFunc: (data: IBroadcastResult) => void,
|
|
45
|
+
): Promise<PluginListenerHandle>;
|
|
46
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
import type { IBroadcastPlugin, IBroadcastResult } from "../IBroadcastPlugin";
|
|
3
|
+
|
|
4
|
+
export class BroadcastWeb extends WebPlugin implements IBroadcastPlugin {
|
|
5
|
+
private static readonly _warn = () =>
|
|
6
|
+
// eslint-disable-next-line no-console
|
|
7
|
+
console.warn("[Broadcast] Broadcast is not supported in web environment.");
|
|
8
|
+
|
|
9
|
+
subscribe(
|
|
10
|
+
_options: { filters: string[] },
|
|
11
|
+
_callback: (result: IBroadcastResult) => void,
|
|
12
|
+
): Promise<{ id: string }> {
|
|
13
|
+
BroadcastWeb._warn();
|
|
14
|
+
return Promise.resolve({ id: "web-stub" });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async unsubscribe(_options: { id: string }): Promise<void> {
|
|
18
|
+
// No-op on web
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async unsubscribeAll(): Promise<void> {
|
|
22
|
+
// No-op on web
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
send(_options: { action: string; extras?: Record<string, unknown> }): Promise<void> {
|
|
26
|
+
BroadcastWeb._warn();
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getLaunchIntent(): Promise<IBroadcastResult> {
|
|
31
|
+
return Promise.resolve({});
|
|
32
|
+
}
|
|
33
|
+
}
|