@simplysm/capacitor-plugin-broadcast 13.0.82 → 13.0.84

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.
Files changed (2) hide show
  1. package/README.md +146 -0
  2. package/package.json +2 -3
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @simplysm/capacitor-plugin-broadcast
2
+
3
+ Capacitor plugin for sending and receiving Android Broadcasts. Designed for industrial device integration such as barcode scanners, PDAs, and other hardware that communicates via Android Intent broadcasts.
4
+
5
+ > **Platform support:** Android only. A web stub is provided that logs warnings and returns no-op results.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @simplysm/capacitor-plugin-broadcast
11
+ npx cap sync
12
+ ```
13
+
14
+ ## API
15
+
16
+ ### `Broadcast` class
17
+
18
+ Static utility class that wraps the native Capacitor plugin. All methods are `async`.
19
+
20
+ ---
21
+
22
+ #### `Broadcast.subscribe(filters, callback)`
23
+
24
+ Register a broadcast receiver for the specified intent actions.
25
+
26
+ | Parameter | Type | Description |
27
+ | ---------- | ------------------------------------- | ------------------------------------ |
28
+ | `filters` | `string[]` | Array of intent action strings to listen for |
29
+ | `callback` | `(result: BroadcastResult) => void` | Called each time a matching broadcast is received |
30
+
31
+ **Returns:** `Promise<() => Promise<void>>` -- an unsubscribe function. Call it to stop receiving broadcasts from this subscription.
32
+
33
+ ```ts
34
+ import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
35
+
36
+ const unsub = await Broadcast.subscribe(
37
+ ["com.symbol.datawedge.api.RESULT_ACTION"],
38
+ (result) => {
39
+ console.log(result.action);
40
+ console.log(result.extras);
41
+ },
42
+ );
43
+
44
+ // Later, unsubscribe
45
+ await unsub();
46
+ ```
47
+
48
+ ---
49
+
50
+ #### `Broadcast.unsubscribeAll()`
51
+
52
+ Unsubscribe all active broadcast receivers at once.
53
+
54
+ **Returns:** `Promise<void>`
55
+
56
+ ```ts
57
+ await Broadcast.unsubscribeAll();
58
+ ```
59
+
60
+ ---
61
+
62
+ #### `Broadcast.send(options)`
63
+
64
+ Send an Android broadcast intent.
65
+
66
+ | Parameter | Type | Description |
67
+ | ----------------- | ----------------------------- | ---------------------------- |
68
+ | `options.action` | `string` | The intent action string |
69
+ | `options.extras` | `Record<string, unknown>` (optional) | Key-value extras to attach to the intent |
70
+
71
+ **Returns:** `Promise<void>`
72
+
73
+ ```ts
74
+ await Broadcast.send({
75
+ action: "com.symbol.datawedge.api.ACTION",
76
+ extras: {
77
+ "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING",
78
+ },
79
+ });
80
+ ```
81
+
82
+ Supported extras value types: `string`, `number`, `boolean`, `string[]`, and nested objects (converted to Android `Bundle`).
83
+
84
+ ---
85
+
86
+ #### `Broadcast.getLaunchIntent()`
87
+
88
+ Retrieve the intent that launched the current activity.
89
+
90
+ **Returns:** `Promise<BroadcastResult>`
91
+
92
+ ```ts
93
+ const intent = await Broadcast.getLaunchIntent();
94
+ console.log(intent.action, intent.extras);
95
+ ```
96
+
97
+ ---
98
+
99
+ #### `Broadcast.addListener(eventName, callback)`
100
+
101
+ Register a listener for events emitted by the plugin.
102
+
103
+ | Parameter | Type | Description |
104
+ | ----------- | ----------------------------------- | ------------------------ |
105
+ | `eventName` | `"newIntent"` | Event name |
106
+ | `callback` | `(result: BroadcastResult) => void` | Called when the event fires |
107
+
108
+ **Returns:** `Promise<PluginListenerHandle>` -- call `handle.remove()` to unregister.
109
+
110
+ The `"newIntent"` event fires when the app receives a new intent while it is already running (e.g., via `onNewIntent` on Android).
111
+
112
+ ```ts
113
+ const handle = await Broadcast.addListener("newIntent", (data) => {
114
+ console.log("New intent:", data.action, data.extras);
115
+ });
116
+
117
+ // Later, remove the listener
118
+ await handle.remove();
119
+ ```
120
+
121
+ ---
122
+
123
+ #### `Broadcast.removeAllListeners()`
124
+
125
+ Remove all event listeners registered via `addListener`.
126
+
127
+ **Returns:** `Promise<void>`
128
+
129
+ ```ts
130
+ await Broadcast.removeAllListeners();
131
+ ```
132
+
133
+ ---
134
+
135
+ ### `BroadcastResult` interface
136
+
137
+ Returned by `subscribe` callbacks, `getLaunchIntent`, and `addListener` callbacks.
138
+
139
+ | Property | Type | Description |
140
+ | --------- | ----------------------------- | ------------------------ |
141
+ | `action` | `string \| undefined` | The broadcast action string |
142
+ | `extras` | `Record<string, unknown> \| undefined` | Extra data from the intent |
143
+
144
+ ### `BroadcastPlugin` interface
145
+
146
+ Low-level Capacitor plugin interface. Use the `Broadcast` class instead for a simpler API with automatic subscription management.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-broadcast",
3
- "version": "13.0.82",
3
+ "version": "13.0.84",
4
4
  "description": "Simplysm Package - Capacitor Broadcast Plugin",
5
5
  "author": "simplysm",
6
6
  "license": "MIT",
@@ -15,8 +15,7 @@
15
15
  "files": [
16
16
  "dist",
17
17
  "src",
18
- "android",
19
- "docs"
18
+ "android"
20
19
  ],
21
20
  "devDependencies": {
22
21
  "@capacitor/core": "^7.6.0"