@simplysm/capacitor-plugin-broadcast 12.16.31 → 12.16.35
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 +81 -72
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,75 +1,117 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-broadcast
|
|
2
2
|
|
|
3
|
-
Capacitor
|
|
3
|
+
Capacitor Broadcast Plugin -- Android broadcast send/receive for industrial devices (barcode scanners, PDA, etc.). Provides subscription-based broadcast receiving, broadcast sending with extras, and launch intent retrieval.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @simplysm/capacitor-plugin-broadcast
|
|
9
|
-
npx cap sync
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
## API Overview
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
| API | Type | Description |
|
|
14
|
+
|-----|------|-------------|
|
|
15
|
+
| `Broadcast` | Abstract class | Static methods for subscribing to, sending, and managing Android broadcasts |
|
|
16
|
+
| `IBroadcastResult` | Interface | Broadcast result containing action and extras |
|
|
17
|
+
| `IBroadcastPlugin` | Interface | Low-level Capacitor plugin interface for broadcast operations |
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
## API Reference
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
### `IBroadcastResult`
|
|
22
|
+
|
|
23
|
+
Result object received from a broadcast or launch intent.
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
export interface IBroadcastResult {
|
|
27
|
+
action?: string;
|
|
28
|
+
extras?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
| Field | Type | Description |
|
|
33
|
+
|-------|------|-------------|
|
|
34
|
+
| `action` | `string \| undefined` | The broadcast action string |
|
|
35
|
+
| `extras` | `Record<string, unknown> \| undefined` | Extra data attached to the broadcast |
|
|
36
|
+
|
|
37
|
+
### `IBroadcastPlugin`
|
|
38
|
+
|
|
39
|
+
Low-level Capacitor plugin interface. Use `Broadcast` instead for a simplified API.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
export interface IBroadcastPlugin {
|
|
43
|
+
subscribe(
|
|
44
|
+
options: { filters: string[] },
|
|
45
|
+
callback: (result: IBroadcastResult) => void,
|
|
46
|
+
): Promise<{ id: string }>;
|
|
47
|
+
unsubscribe(options: { id: string }): Promise<void>;
|
|
48
|
+
unsubscribeAll(): Promise<void>;
|
|
49
|
+
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
50
|
+
getLaunchIntent(): Promise<IBroadcastResult>;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
22
53
|
|
|
23
|
-
|
|
54
|
+
| Method | Parameters | Returns | Description |
|
|
55
|
+
|--------|------------|---------|-------------|
|
|
56
|
+
| `subscribe` | `options: { filters: string[] }, callback` | `Promise<{ id: string }>` | Register a broadcast receiver with action filters |
|
|
57
|
+
| `unsubscribe` | `options: { id: string }` | `Promise<void>` | Remove a specific broadcast receiver by ID |
|
|
58
|
+
| `unsubscribeAll` | -- | `Promise<void>` | Remove all broadcast receivers |
|
|
59
|
+
| `send` | `options: { action, extras? }` | `Promise<void>` | Send a broadcast with action and optional extras |
|
|
60
|
+
| `getLaunchIntent` | -- | `Promise<IBroadcastResult>` | Get the intent that launched the app |
|
|
24
61
|
|
|
25
62
|
### `Broadcast`
|
|
26
63
|
|
|
27
|
-
|
|
64
|
+
Abstract class with static methods for Android broadcast send/receive. Designed for industrial device integration (barcode scanners, PDA, etc.).
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
export abstract class Broadcast {
|
|
68
|
+
static async subscribe(
|
|
69
|
+
filters: string[],
|
|
70
|
+
callback: (result: IBroadcastResult) => 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>;
|
|
28
79
|
|
|
29
|
-
|
|
80
|
+
static async getLaunchIntent(): Promise<IBroadcastResult>;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
30
83
|
|
|
31
|
-
|
|
84
|
+
| Method | Parameters | Returns | Description |
|
|
85
|
+
|--------|------------|---------|-------------|
|
|
86
|
+
| `subscribe` | `filters: string[], callback: (result: IBroadcastResult) => void` | `Promise<() => Promise<void>>` | Register a broadcast receiver; returns an unsubscribe function |
|
|
87
|
+
| `unsubscribeAll` | -- | `Promise<void>` | Remove all registered broadcast receivers |
|
|
88
|
+
| `send` | `options: { action: string; extras?: Record<string, unknown> }` | `Promise<void>` | Send a broadcast with action and optional extras |
|
|
89
|
+
| `getLaunchIntent` | -- | `Promise<IBroadcastResult>` | Retrieve the intent that launched the application |
|
|
32
90
|
|
|
33
|
-
|
|
34
|
-
|------------|------------------------------------------|-------------------------------------|
|
|
35
|
-
| `filters` | `string[]` | Intent action strings to listen for |
|
|
36
|
-
| `callback` | `(result: IBroadcastResult) => void` | Called when a matching broadcast is received |
|
|
91
|
+
## Usage Examples
|
|
37
92
|
|
|
38
|
-
|
|
93
|
+
### Subscribe to broadcasts from a barcode scanner
|
|
39
94
|
|
|
40
|
-
```
|
|
95
|
+
```typescript
|
|
41
96
|
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
42
97
|
|
|
43
|
-
const
|
|
98
|
+
const unsubscribe = await Broadcast.subscribe(
|
|
44
99
|
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
45
100
|
(result) => {
|
|
46
|
-
console.log(result.action);
|
|
47
|
-
console.log(result.extras);
|
|
101
|
+
console.log("Action:", result.action);
|
|
102
|
+
console.log("Extras:", result.extras);
|
|
48
103
|
},
|
|
49
104
|
);
|
|
50
105
|
|
|
51
106
|
// Later, unsubscribe
|
|
52
|
-
await
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### `Broadcast.unsubscribeAll()`
|
|
56
|
-
|
|
57
|
-
Unregisters all active broadcast receivers at once.
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
await Broadcast.unsubscribeAll();
|
|
107
|
+
await unsubscribe();
|
|
61
108
|
```
|
|
62
109
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Sends a broadcast intent.
|
|
110
|
+
### Send a broadcast to trigger a scan
|
|
66
111
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
| `options.action` | `string` | Intent action string |
|
|
70
|
-
| `options.extras` | `Record<string, unknown>` (optional) | Extra data to include in the intent |
|
|
112
|
+
```typescript
|
|
113
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
71
114
|
|
|
72
|
-
```ts
|
|
73
115
|
await Broadcast.send({
|
|
74
116
|
action: "com.symbol.datawedge.api.ACTION",
|
|
75
117
|
extras: {
|
|
@@ -77,36 +119,3 @@ await Broadcast.send({
|
|
|
77
119
|
},
|
|
78
120
|
});
|
|
79
121
|
```
|
|
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>` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplysm/capacitor-plugin-broadcast",
|
|
3
|
-
"version": "12.16.
|
|
3
|
+
"version": "12.16.35",
|
|
4
4
|
"description": "심플리즘 패키지 - Capacitor Broadcast Plugin",
|
|
5
5
|
"author": "김석래",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"@capacitor/core": "^7.4.4"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@capacitor/core": "^7.
|
|
24
|
+
"@capacitor/core": "^7.6.0"
|
|
25
25
|
}
|
|
26
26
|
}
|