@simplysm/capacitor-plugin-broadcast 13.0.84 → 13.0.86
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 +90 -92
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,76 +1,52 @@
|
|
|
1
1
|
# @simplysm/capacitor-plugin-broadcast
|
|
2
2
|
|
|
3
|
-
Capacitor
|
|
3
|
+
Capacitor Android 브로드캐스트 리시버 플러그인. 바코드 스캐너, PDA 등 산업용 기기의 인텐트 브로드캐스트를 수신/발신한다.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Installation
|
|
5
|
+
## 설치
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npm install @simplysm/capacitor-plugin-broadcast
|
|
11
|
-
npx cap sync
|
|
12
9
|
```
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### `Broadcast` class
|
|
11
|
+
**Peer:** `@capacitor/core` ^7.4.4
|
|
12
|
+
**외부 의존성 없음**
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
## Export 목록
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
```typescript
|
|
17
|
+
// index.ts
|
|
18
|
+
export { Broadcast } from "./Broadcast";
|
|
19
|
+
export type { BroadcastPlugin, BroadcastResult } from "./BroadcastPlugin";
|
|
20
|
+
```
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
## 주요 사용법
|
|
25
23
|
|
|
26
|
-
|
|
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 |
|
|
24
|
+
### 브로드캐스트 구독
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
특정 인텐트 액션 필터로 구독하고, 브로드캐스트 수신 시 콜백을 실행한다.
|
|
32
27
|
|
|
33
|
-
```
|
|
28
|
+
```typescript
|
|
34
29
|
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
// 구독 (unsubscribe 함수 반환)
|
|
32
|
+
const unsubscribe = await Broadcast.subscribe(
|
|
33
|
+
["com.symbol.datawedge.api.RESULT_ACTION", "com.example.SCAN_RESULT"],
|
|
38
34
|
(result) => {
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
// result.action: 수신된 액션 이름
|
|
36
|
+
// result.extras: 추가 데이터 (Record<string, unknown>)
|
|
41
37
|
},
|
|
42
38
|
);
|
|
43
39
|
|
|
44
|
-
//
|
|
45
|
-
await
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
#### `Broadcast.unsubscribeAll()`
|
|
40
|
+
// 구독 해제
|
|
41
|
+
await unsubscribe();
|
|
51
42
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
**Returns:** `Promise<void>`
|
|
55
|
-
|
|
56
|
-
```ts
|
|
43
|
+
// 전체 구독 해제
|
|
57
44
|
await Broadcast.unsubscribeAll();
|
|
58
45
|
```
|
|
59
46
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
#### `Broadcast.send(options)`
|
|
63
|
-
|
|
64
|
-
Send an Android broadcast intent.
|
|
47
|
+
### 브로드캐스트 전송
|
|
65
48
|
|
|
66
|
-
|
|
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
|
|
49
|
+
```typescript
|
|
74
50
|
await Broadcast.send({
|
|
75
51
|
action: "com.symbol.datawedge.api.ACTION",
|
|
76
52
|
extras: {
|
|
@@ -79,68 +55,90 @@ await Broadcast.send({
|
|
|
79
55
|
});
|
|
80
56
|
```
|
|
81
57
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
---
|
|
58
|
+
### 런치 인텐트 조회
|
|
85
59
|
|
|
86
|
-
|
|
60
|
+
앱을 시작한 인텐트 정보를 가져온다.
|
|
87
61
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
**Returns:** `Promise<BroadcastResult>`
|
|
91
|
-
|
|
92
|
-
```ts
|
|
62
|
+
```typescript
|
|
93
63
|
const intent = await Broadcast.getLaunchIntent();
|
|
94
|
-
|
|
64
|
+
// { action?: string, extras?: Record<string, unknown> }
|
|
95
65
|
```
|
|
96
66
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
#### `Broadcast.addListener(eventName, callback)`
|
|
100
|
-
|
|
101
|
-
Register a listener for events emitted by the plugin.
|
|
67
|
+
### 새 인텐트 리스너
|
|
102
68
|
|
|
103
|
-
|
|
104
|
-
| ----------- | ----------------------------------- | ------------------------ |
|
|
105
|
-
| `eventName` | `"newIntent"` | Event name |
|
|
106
|
-
| `callback` | `(result: BroadcastResult) => void` | Called when the event fires |
|
|
69
|
+
앱이 실행 중일 때 수신되는 새 인텐트를 감지한다 (`onNewIntent`).
|
|
107
70
|
|
|
108
|
-
|
|
71
|
+
```typescript
|
|
72
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
|
109
73
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
74
|
+
const handle: PluginListenerHandle = await Broadcast.addListener(
|
|
75
|
+
"newIntent",
|
|
76
|
+
(data) => {
|
|
77
|
+
// data.action, data.extras
|
|
78
|
+
},
|
|
79
|
+
);
|
|
116
80
|
|
|
117
|
-
//
|
|
81
|
+
// 리스너 해제
|
|
118
82
|
await handle.remove();
|
|
83
|
+
|
|
84
|
+
// 전체 리스너 해제
|
|
85
|
+
await Broadcast.removeAllListeners();
|
|
119
86
|
```
|
|
120
87
|
|
|
121
|
-
|
|
88
|
+
## API 레퍼런스
|
|
122
89
|
|
|
123
|
-
|
|
90
|
+
### `Broadcast` (abstract class, static 메서드)
|
|
124
91
|
|
|
125
|
-
|
|
92
|
+
| 메서드 | 시그니처 | 설명 |
|
|
93
|
+
|--------|----------|------|
|
|
94
|
+
| `subscribe` | `(filters: string[], callback: (result: BroadcastResult) => void) => Promise<() => Promise<void>>` | 브로드캐스트 구독. unsubscribe 함수 반환 |
|
|
95
|
+
| `unsubscribeAll` | `() => Promise<void>` | 모든 구독 해제 |
|
|
96
|
+
| `send` | `(options: { action: string; extras?: Record<string, unknown> }) => Promise<void>` | 브로드캐스트 전송 |
|
|
97
|
+
| `getLaunchIntent` | `() => Promise<BroadcastResult>` | 런치 인텐트 조회 |
|
|
98
|
+
| `addListener` | `(eventName: "newIntent", callback: (result: BroadcastResult) => void) => Promise<PluginListenerHandle>` | 이벤트 리스너 등록 |
|
|
99
|
+
| `removeAllListeners` | `() => Promise<void>` | 모든 이벤트 리스너 해제 |
|
|
126
100
|
|
|
127
|
-
|
|
101
|
+
### `BroadcastResult` (interface)
|
|
128
102
|
|
|
129
|
-
```
|
|
130
|
-
|
|
103
|
+
```typescript
|
|
104
|
+
interface BroadcastResult {
|
|
105
|
+
action?: string; // 브로드캐스트 액션 이름
|
|
106
|
+
extras?: Record<string, unknown>; // 추가 데이터
|
|
107
|
+
}
|
|
131
108
|
```
|
|
132
109
|
|
|
133
|
-
|
|
110
|
+
### `BroadcastPlugin` (interface, 저수준)
|
|
134
111
|
|
|
135
|
-
|
|
112
|
+
`Broadcast` 클래스가 래핑하는 Capacitor 플러그인 인터페이스. 직접 사용할 일은 거의 없다.
|
|
136
113
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
114
|
+
```typescript
|
|
115
|
+
interface BroadcastPlugin {
|
|
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
|
+
}
|
|
124
|
+
```
|
|
145
125
|
|
|
146
|
-
|
|
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 타입 지원: `String`, `Integer`, `Long`, `Double`, `Boolean`, `JSONArray`(-> String[]), `JSONObject`(-> Bundle)
|
|
142
|
+
- Intent -> JSON 변환: `Bundle`의 모든 키를 순회하며 타입별 변환 (`Parcelable` -> `toString()` 포함)
|
|
143
|
+
- Android 13+: `RECEIVER_EXPORTED` 플래그 사용
|
|
144
|
+
- `handleOnDestroy`에서 모든 receiver 자동 해제
|