@simplysm/capacitor-plugin-broadcast 13.0.85 → 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.
Files changed (2) hide show
  1. package/README.md +90 -92
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,76 +1,52 @@
1
1
  # @simplysm/capacitor-plugin-broadcast
2
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.
3
+ Capacitor Android 브로드캐스트 리시버 플러그인. 바코드 스캐너, PDA 산업용 기기의 인텐트 브로드캐스트를 수신/발신한다.
4
4
 
5
- > **Platform support:** Android only. A web stub is provided that logs warnings and returns no-op results.
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
- ## API
15
-
16
- ### `Broadcast` class
11
+ **Peer:** `@capacitor/core` ^7.4.4
12
+ **외부 의존성 없음**
17
13
 
18
- Static utility class that wraps the native Capacitor plugin. All methods are `async`.
14
+ ## Export 목록
19
15
 
20
- ---
21
-
22
- #### `Broadcast.subscribe(filters, callback)`
16
+ ```typescript
17
+ // index.ts
18
+ export { Broadcast } from "./Broadcast";
19
+ export type { BroadcastPlugin, BroadcastResult } from "./BroadcastPlugin";
20
+ ```
23
21
 
24
- Register a broadcast receiver for the specified intent actions.
22
+ ## 주요 사용법
25
23
 
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 |
24
+ ### 브로드캐스트 구독
30
25
 
31
- **Returns:** `Promise<() => Promise<void>>` -- an unsubscribe function. Call it to stop receiving broadcasts from this subscription.
26
+ 특정 인텐트 액션 필터로 구독하고, 브로드캐스트 수신 콜백을 실행한다.
32
27
 
33
- ```ts
28
+ ```typescript
34
29
  import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
35
30
 
36
- const unsub = await Broadcast.subscribe(
37
- ["com.symbol.datawedge.api.RESULT_ACTION"],
31
+ // 구독 (unsubscribe 함수 반환)
32
+ const unsubscribe = await Broadcast.subscribe(
33
+ ["com.symbol.datawedge.api.RESULT_ACTION", "com.example.SCAN_RESULT"],
38
34
  (result) => {
39
- console.log(result.action);
40
- console.log(result.extras);
35
+ // result.action: 수신된 액션 이름
36
+ // result.extras: 추가 데이터 (Record<string, unknown>)
41
37
  },
42
38
  );
43
39
 
44
- // Later, unsubscribe
45
- await unsub();
46
- ```
47
-
48
- ---
49
-
50
- #### `Broadcast.unsubscribeAll()`
40
+ // 구독 해제
41
+ await unsubscribe();
51
42
 
52
- Unsubscribe all active broadcast receivers at once.
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
- | 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
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
- Supported extras value types: `string`, `number`, `boolean`, `string[]`, and nested objects (converted to Android `Bundle`).
83
-
84
- ---
58
+ ### 런치 인텐트 조회
85
59
 
86
- #### `Broadcast.getLaunchIntent()`
60
+ 앱을 시작한 인텐트 정보를 가져온다.
87
61
 
88
- Retrieve the intent that launched the current activity.
89
-
90
- **Returns:** `Promise<BroadcastResult>`
91
-
92
- ```ts
62
+ ```typescript
93
63
  const intent = await Broadcast.getLaunchIntent();
94
- console.log(intent.action, intent.extras);
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
- | Parameter | Type | Description |
104
- | ----------- | ----------------------------------- | ------------------------ |
105
- | `eventName` | `"newIntent"` | Event name |
106
- | `callback` | `(result: BroadcastResult) => void` | Called when the event fires |
69
+ 앱이 실행 중일 때 수신되는 새 인텐트를 감지한다 (`onNewIntent`).
107
70
 
108
- **Returns:** `Promise<PluginListenerHandle>` -- call `handle.remove()` to unregister.
71
+ ```typescript
72
+ import type { PluginListenerHandle } from "@capacitor/core";
109
73
 
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
- });
74
+ const handle: PluginListenerHandle = await Broadcast.addListener(
75
+ "newIntent",
76
+ (data) => {
77
+ // data.action, data.extras
78
+ },
79
+ );
116
80
 
117
- // Later, remove the listener
81
+ // 리스너 해제
118
82
  await handle.remove();
83
+
84
+ // 전체 리스너 해제
85
+ await Broadcast.removeAllListeners();
119
86
  ```
120
87
 
121
- ---
88
+ ## API 레퍼런스
122
89
 
123
- #### `Broadcast.removeAllListeners()`
90
+ ### `Broadcast` (abstract class, static 메서드)
124
91
 
125
- Remove all event listeners registered via `addListener`.
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
- **Returns:** `Promise<void>`
101
+ ### `BroadcastResult` (interface)
128
102
 
129
- ```ts
130
- await Broadcast.removeAllListeners();
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
- ### `BroadcastResult` interface
112
+ `Broadcast` 클래스가 래핑하는 Capacitor 플러그인 인터페이스. 직접 사용할 일은 거의 없다.
136
113
 
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
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
- Low-level Capacitor plugin interface. Use the `Broadcast` class instead for a simpler API with automatic subscription management.
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 자동 해제
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-broadcast",
3
- "version": "13.0.85",
3
+ "version": "13.0.86",
4
4
  "description": "Simplysm Package - Capacitor Broadcast Plugin",
5
5
  "author": "simplysm",
6
6
  "license": "MIT",