@simplysm/capacitor-plugin-broadcast 13.0.96 → 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 +89 -100
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,144 +1,133 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-broadcast
|
|
2
2
|
|
|
3
|
-
Capacitor
|
|
3
|
+
Capacitor Broadcast Plugin -- send and receive Android broadcast intents for industrial device integration (barcode scanners, PDAs, etc.).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @simplysm/capacitor-plugin-broadcast
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
**외부 의존성 없음**
|
|
11
|
+
## API Overview
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
### Types
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export type { BroadcastPlugin, BroadcastResult } from "./BroadcastPlugin";
|
|
20
|
-
```
|
|
15
|
+
| API | Type | Description |
|
|
16
|
+
|-----|------|-------------|
|
|
17
|
+
| `BroadcastResult` | interface | Broadcast result containing `action` and `extras` |
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
### Interfaces
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
| API | Type | Description |
|
|
22
|
+
|-----|------|-------------|
|
|
23
|
+
| `BroadcastPlugin` | interface | Low-level Capacitor plugin interface for broadcast operations |
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```typescript
|
|
29
|
-
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
25
|
+
### Classes
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(result) => {
|
|
35
|
-
// result.action: 수신된 액션 이름
|
|
36
|
-
// result.extras: 추가 데이터 (Record<string, unknown>)
|
|
37
|
-
},
|
|
38
|
-
);
|
|
27
|
+
| API | Type | Description |
|
|
28
|
+
|-----|------|-------------|
|
|
29
|
+
| `Broadcast` | abstract class | Android broadcast send/receive operations |
|
|
39
30
|
|
|
40
|
-
|
|
41
|
-
await unsubscribe();
|
|
31
|
+
## `BroadcastResult`
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
```typescript
|
|
34
|
+
interface BroadcastResult {
|
|
35
|
+
/** Broadcast action */
|
|
36
|
+
action?: string;
|
|
37
|
+
/** Extra data */
|
|
38
|
+
extras?: Record<string, unknown>;
|
|
39
|
+
}
|
|
45
40
|
```
|
|
46
41
|
|
|
47
|
-
|
|
42
|
+
## `BroadcastPlugin`
|
|
48
43
|
|
|
49
44
|
```typescript
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
})
|
|
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
|
+
}
|
|
56
60
|
```
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
Low-level Capacitor plugin interface. Use `Broadcast` static methods instead of calling this directly.
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
## `Broadcast`
|
|
61
65
|
|
|
62
66
|
```typescript
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
}
|
|
65
89
|
```
|
|
66
90
|
|
|
67
|
-
|
|
91
|
+
## Usage Examples
|
|
68
92
|
|
|
69
|
-
|
|
93
|
+
### Subscribe to broadcasts
|
|
70
94
|
|
|
71
95
|
```typescript
|
|
72
|
-
import
|
|
96
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
73
97
|
|
|
74
|
-
const
|
|
75
|
-
"
|
|
76
|
-
(
|
|
77
|
-
//
|
|
98
|
+
const unsub = await Broadcast.subscribe(
|
|
99
|
+
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
100
|
+
(result) => {
|
|
101
|
+
// handle result.action, result.extras
|
|
78
102
|
},
|
|
79
103
|
);
|
|
80
104
|
|
|
81
|
-
//
|
|
82
|
-
await
|
|
83
|
-
|
|
84
|
-
// 전체 리스너 해제
|
|
85
|
-
await Broadcast.removeAllListeners();
|
|
105
|
+
// Later: unsubscribe
|
|
106
|
+
await unsub();
|
|
86
107
|
```
|
|
87
108
|
|
|
88
|
-
|
|
109
|
+
### Send a broadcast
|
|
89
110
|
|
|
90
|
-
|
|
111
|
+
```typescript
|
|
112
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
91
113
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
| `removeAllListeners` | `() => Promise<void>` | 모든 이벤트 리스너 해제 |
|
|
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
|
+
```
|
|
100
121
|
|
|
101
|
-
###
|
|
122
|
+
### Listen for new intents
|
|
102
123
|
|
|
103
124
|
```typescript
|
|
104
|
-
|
|
105
|
-
action?: string; // 브로드캐스트 액션 이름
|
|
106
|
-
extras?: Record<string, unknown>; // 추가 데이터
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### `BroadcastPlugin` (interface, 저수준)
|
|
125
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
111
126
|
|
|
112
|
-
|
|
127
|
+
const handle = await Broadcast.addListener("newIntent", (result) => {
|
|
128
|
+
// handle intent
|
|
129
|
+
});
|
|
113
130
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
subscribe(options: { filters: string[] }, callback: (result: BroadcastResult) => void): Promise<{ id: string }>;
|
|
117
|
-
unsubscribe(options: { id: string }): Promise<void>;
|
|
118
|
-
unsubscribeAll(): Promise<void>;
|
|
119
|
-
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
120
|
-
getLaunchIntent(): Promise<BroadcastResult>;
|
|
121
|
-
addListener(eventName: "newIntent", listenerFunc: (data: BroadcastResult) => void): Promise<PluginListenerHandle>;
|
|
122
|
-
removeAllListeners(): Promise<void>;
|
|
123
|
-
}
|
|
131
|
+
// Later: remove listener
|
|
132
|
+
await handle.remove();
|
|
124
133
|
```
|
|
125
|
-
|
|
126
|
-
## 플랫폼 지원
|
|
127
|
-
|
|
128
|
-
| 기능 | Android | Web |
|
|
129
|
-
|------|---------|-----|
|
|
130
|
-
| 구독 | BroadcastReceiver + IntentFilter 등록 | 경고 후 스텁 반환 (`id: "web-stub"`) |
|
|
131
|
-
| 구독 해제 | `unregisterReceiver` | no-op |
|
|
132
|
-
| 전송 | `sendBroadcast(intent)` | 경고 후 no-op |
|
|
133
|
-
| 런치 인텐트 | `Activity.getIntent()` | 빈 객체 `{}` 반환 |
|
|
134
|
-
| 새 인텐트 | `handleOnNewIntent` -> `notifyListeners` | Capacitor WebPlugin 기본 동작 |
|
|
135
|
-
|
|
136
|
-
## Android 네이티브 구현
|
|
137
|
-
|
|
138
|
-
- **패키지:** `kr.co.simplysm.capacitor.broadcast`
|
|
139
|
-
- **플러그인명:** `Broadcast`
|
|
140
|
-
- `subscribe`: `RETURN_CALLBACK` 방식 (`call.setKeepAlive`), UUID 기반 receiver ID 관리
|
|
141
|
-
- **전송 시 extras 타입 (JSON -> Intent):** `String`, `Integer`, `Long`, `Double`, `Boolean`, `JSONArray`(-> `String[]`), `JSONObject`(-> `Bundle`)
|
|
142
|
-
- **수신 시 extras 타입 (Intent -> JSON):** `String`, `Integer`, `Long`, `Double`, `Float`(-> `Double`), `Boolean`, `Bundle`(-> 재귀 변환), `String[]`, `int[]`, `Parcelable`(-> `toString()`), `Parcelable[]`, 기타(-> `toString()`)
|
|
143
|
-
- Android 13+: `RECEIVER_EXPORTED` 플래그 사용
|
|
144
|
-
- `handleOnDestroy`에서 모든 receiver 자동 해제
|