@simplysm/capacitor-plugin-broadcast 12.16.9
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 +112 -0
- package/android/build.gradle +13 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/kr/co/simplysm/capacitor/broadcast/BroadcastPlugin.java +301 -0
- package/dist/Broadcast.d.ts +48 -0
- package/dist/Broadcast.js +62 -0
- package/dist/IBroadcastPlugin.d.ts +37 -0
- package/dist/IBroadcastPlugin.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/web/BroadcastWeb.d.ts +18 -0
- package/dist/web/BroadcastWeb.js +20 -0
- package/package.json +23 -0
- package/src/Broadcast.ts +71 -0
- package/src/IBroadcastPlugin.ts +36 -0
- package/src/index.ts +2 -0
- package/src/web/BroadcastWeb.ts +29 -0
- package/tsconfig.json +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# @simplysm/capacitor-plugin-broadcast
|
|
2
|
+
|
|
3
|
+
Android Broadcast 송수신을 위한 Capacitor 플러그인입니다.
|
|
4
|
+
|
|
5
|
+
산업용 장치(바코드 스캐너, PDA 등)와의 연동을 위해 설계되었습니다.
|
|
6
|
+
|
|
7
|
+
> ⚠️ **Android 전용** - iOS는 Broadcast 개념이 없어 지원하지 않습니다.
|
|
8
|
+
|
|
9
|
+
## 설치
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add @simplysm/capacitor-plugin-broadcast
|
|
13
|
+
npx cap sync
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## 사용법
|
|
17
|
+
|
|
18
|
+
### Broadcast 수신
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
22
|
+
|
|
23
|
+
// 수신 등록 - 해제 함수 반환
|
|
24
|
+
const unsubscribe = await Broadcast.subscribe(
|
|
25
|
+
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
26
|
+
(result) => {
|
|
27
|
+
console.log("Action:", result.action);
|
|
28
|
+
console.log("Extras:", result.extras);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// 수신 해제
|
|
33
|
+
await unsubscribe();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Broadcast 송신
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
40
|
+
|
|
41
|
+
await Broadcast.send({
|
|
42
|
+
action: "com.symbol.datawedge.api.ACTION",
|
|
43
|
+
extras: {
|
|
44
|
+
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 전체 수신기 해제
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
53
|
+
|
|
54
|
+
await Broadcast.unsubscribeAll();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 앱 시작 Intent 가져오기
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
61
|
+
|
|
62
|
+
const launchIntent = await Broadcast.getLaunchIntent();
|
|
63
|
+
console.log(launchIntent.action);
|
|
64
|
+
console.log(launchIntent.extras);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## API
|
|
68
|
+
|
|
69
|
+
| 메서드 | 설명 |
|
|
70
|
+
|--------|------|
|
|
71
|
+
| `subscribe(filters, callback)` | Broadcast 수신 등록, 해제 함수 반환 |
|
|
72
|
+
| `unsubscribeAll()` | 모든 수신기 해제 |
|
|
73
|
+
| `send({ action, extras })` | Broadcast 송신 |
|
|
74
|
+
| `getLaunchIntent()` | 앱 시작 Intent 가져오기 |
|
|
75
|
+
|
|
76
|
+
## 예제: Zebra DataWedge 연동
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { Broadcast } from "@simplysm/capacitor-plugin-broadcast";
|
|
80
|
+
|
|
81
|
+
// 바코드 스캔 결과 수신
|
|
82
|
+
const unsubscribe = await Broadcast.subscribe(
|
|
83
|
+
["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
84
|
+
(result) => {
|
|
85
|
+
const barcode = result.extras?.["com.symbol.datawedge.data_string"];
|
|
86
|
+
if (barcode) {
|
|
87
|
+
console.log("스캔된 바코드:", barcode);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// 소프트 스캔 트리거
|
|
93
|
+
await Broadcast.send({
|
|
94
|
+
action: "com.symbol.datawedge.api.ACTION",
|
|
95
|
+
extras: {
|
|
96
|
+
"com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 타입 정의
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
interface IBroadcastResult {
|
|
105
|
+
action?: string;
|
|
106
|
+
extras?: Record<string, unknown>;
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 라이선스
|
|
111
|
+
|
|
112
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
android {
|
|
4
|
+
namespace "kr.co.simplysm.capacitor.broadcast"
|
|
5
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
6
|
+
defaultConfig {
|
|
7
|
+
minSdk project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
implementation project(':capacitor-android')
|
|
13
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
package kr.co.simplysm.capacitor.broadcast;
|
|
2
|
+
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.content.IntentFilter;
|
|
7
|
+
import android.os.Build;
|
|
8
|
+
import android.os.Bundle;
|
|
9
|
+
import android.os.Parcelable;
|
|
10
|
+
import android.util.Log;
|
|
11
|
+
|
|
12
|
+
import com.getcapacitor.JSArray;
|
|
13
|
+
import com.getcapacitor.JSObject;
|
|
14
|
+
import com.getcapacitor.Plugin;
|
|
15
|
+
import com.getcapacitor.PluginCall;
|
|
16
|
+
import com.getcapacitor.PluginMethod;
|
|
17
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
18
|
+
|
|
19
|
+
import org.json.JSONArray;
|
|
20
|
+
import org.json.JSONException;
|
|
21
|
+
import org.json.JSONObject;
|
|
22
|
+
|
|
23
|
+
import java.util.HashMap;
|
|
24
|
+
import java.util.Iterator;
|
|
25
|
+
import java.util.Map;
|
|
26
|
+
import java.util.Set;
|
|
27
|
+
import java.util.UUID;
|
|
28
|
+
|
|
29
|
+
@CapacitorPlugin(name = "Broadcast")
|
|
30
|
+
public class BroadcastPlugin extends Plugin {
|
|
31
|
+
|
|
32
|
+
private static final String TAG = "BroadcastPlugin";
|
|
33
|
+
private final Map<String, BroadcastReceiver> receivers = new HashMap<>();
|
|
34
|
+
|
|
35
|
+
@Override
|
|
36
|
+
protected void handleOnNewIntent(Intent intent) {
|
|
37
|
+
super.handleOnNewIntent(intent);
|
|
38
|
+
notifyListeners("onNewIntent", intentToJson(intent));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
|
|
42
|
+
public void subscribe(PluginCall call) {
|
|
43
|
+
try {
|
|
44
|
+
JSArray filters = call.getArray("filters");
|
|
45
|
+
|
|
46
|
+
if (filters == null || filters.length() == 0) {
|
|
47
|
+
call.reject("filters is required");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
call.setKeepAlive(true);
|
|
52
|
+
|
|
53
|
+
String receiverId = UUID.randomUUID().toString();
|
|
54
|
+
|
|
55
|
+
IntentFilter intentFilter = new IntentFilter();
|
|
56
|
+
for (int i = 0; i < filters.length(); i++) {
|
|
57
|
+
intentFilter.addAction(filters.getString(i));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
61
|
+
@Override
|
|
62
|
+
public void onReceive(Context context, Intent intent) {
|
|
63
|
+
JSObject result = intentToJson(intent);
|
|
64
|
+
result.put("id", receiverId);
|
|
65
|
+
call.resolve(result);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
70
|
+
getContext().registerReceiver(receiver, intentFilter, Context.RECEIVER_EXPORTED);
|
|
71
|
+
} else {
|
|
72
|
+
getContext().registerReceiver(receiver, intentFilter);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
receivers.put(receiverId, receiver);
|
|
76
|
+
|
|
77
|
+
JSObject ret = new JSObject();
|
|
78
|
+
ret.put("id", receiverId);
|
|
79
|
+
call.resolve(ret);
|
|
80
|
+
} catch (Exception e) {
|
|
81
|
+
Log.e(TAG, "subscribe failed", e);
|
|
82
|
+
call.reject("subscribe failed: " + e.getMessage());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@PluginMethod
|
|
87
|
+
public void unsubscribe(PluginCall call) {
|
|
88
|
+
try {
|
|
89
|
+
String id = call.getString("id");
|
|
90
|
+
if (id == null) {
|
|
91
|
+
call.reject("id is required");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
BroadcastReceiver receiver = receivers.remove(id);
|
|
96
|
+
if (receiver != null) {
|
|
97
|
+
getContext().unregisterReceiver(receiver);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
call.resolve();
|
|
101
|
+
} catch (Exception e) {
|
|
102
|
+
Log.e(TAG, "unsubscribe failed", e);
|
|
103
|
+
call.reject("unsubscribe failed: " + e.getMessage());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@PluginMethod
|
|
108
|
+
public void unsubscribeAll(PluginCall call) {
|
|
109
|
+
try {
|
|
110
|
+
for (BroadcastReceiver receiver : receivers.values()) {
|
|
111
|
+
try {
|
|
112
|
+
getContext().unregisterReceiver(receiver);
|
|
113
|
+
} catch (Exception ignored) {
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
receivers.clear();
|
|
117
|
+
call.resolve();
|
|
118
|
+
} catch (Exception e) {
|
|
119
|
+
Log.e(TAG, "unsubscribeAll failed", e);
|
|
120
|
+
call.reject("unsubscribeAll failed: " + e.getMessage());
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@PluginMethod
|
|
125
|
+
public void send(PluginCall call) {
|
|
126
|
+
try {
|
|
127
|
+
String action = call.getString("action");
|
|
128
|
+
if (action == null) {
|
|
129
|
+
call.reject("action is required");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
Intent intent = new Intent(action);
|
|
134
|
+
|
|
135
|
+
JSObject extras = call.getObject("extras");
|
|
136
|
+
if (extras != null) {
|
|
137
|
+
populateExtras(intent, extras);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getContext().sendBroadcast(intent);
|
|
141
|
+
call.resolve();
|
|
142
|
+
} catch (Exception e) {
|
|
143
|
+
Log.e(TAG, "send failed", e);
|
|
144
|
+
call.reject("send failed: " + e.getMessage());
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@PluginMethod
|
|
149
|
+
public void getLaunchIntent(PluginCall call) {
|
|
150
|
+
try {
|
|
151
|
+
Intent intent = getActivity().getIntent();
|
|
152
|
+
call.resolve(intentToJson(intent));
|
|
153
|
+
} catch (Exception e) {
|
|
154
|
+
Log.e(TAG, "getLaunchIntent failed", e);
|
|
155
|
+
call.reject("getLaunchIntent failed: " + e.getMessage());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private void populateExtras(Intent intent, JSObject extras) throws JSONException {
|
|
160
|
+
Iterator<String> keys = extras.keys();
|
|
161
|
+
while (keys.hasNext()) {
|
|
162
|
+
String key = keys.next();
|
|
163
|
+
Object value = extras.get(key);
|
|
164
|
+
|
|
165
|
+
if (value instanceof String) {
|
|
166
|
+
intent.putExtra(key, (String) value);
|
|
167
|
+
} else if (value instanceof Integer) {
|
|
168
|
+
intent.putExtra(key, (Integer) value);
|
|
169
|
+
} else if (value instanceof Long) {
|
|
170
|
+
intent.putExtra(key, (Long) value);
|
|
171
|
+
} else if (value instanceof Double) {
|
|
172
|
+
intent.putExtra(key, (Double) value);
|
|
173
|
+
} else if (value instanceof Boolean) {
|
|
174
|
+
intent.putExtra(key, (Boolean) value);
|
|
175
|
+
} else if (value instanceof JSONArray) {
|
|
176
|
+
JSONArray arr = (JSONArray) value;
|
|
177
|
+
String[] strArr = new String[arr.length()];
|
|
178
|
+
for (int i = 0; i < arr.length(); i++) {
|
|
179
|
+
strArr[i] = arr.getString(i);
|
|
180
|
+
}
|
|
181
|
+
intent.putExtra(key, strArr);
|
|
182
|
+
} else if (value instanceof JSONObject) {
|
|
183
|
+
Bundle bundle = jsonToBundle((JSONObject) value);
|
|
184
|
+
intent.putExtra(key, bundle);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private Bundle jsonToBundle(JSONObject json) throws JSONException {
|
|
190
|
+
Bundle bundle = new Bundle();
|
|
191
|
+
Iterator<String> keys = json.keys();
|
|
192
|
+
while (keys.hasNext()) {
|
|
193
|
+
String key = keys.next();
|
|
194
|
+
Object value = json.get(key);
|
|
195
|
+
|
|
196
|
+
if (value instanceof String) {
|
|
197
|
+
bundle.putString(key, (String) value);
|
|
198
|
+
} else if (value instanceof Integer) {
|
|
199
|
+
bundle.putInt(key, (Integer) value);
|
|
200
|
+
} else if (value instanceof Long) {
|
|
201
|
+
bundle.putLong(key, (Long) value);
|
|
202
|
+
} else if (value instanceof Double) {
|
|
203
|
+
bundle.putDouble(key, (Double) value);
|
|
204
|
+
} else if (value instanceof Boolean) {
|
|
205
|
+
bundle.putBoolean(key, (Boolean) value);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return bundle;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private JSObject intentToJson(Intent intent) {
|
|
212
|
+
JSObject json = new JSObject();
|
|
213
|
+
|
|
214
|
+
if (intent == null) {
|
|
215
|
+
return json;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
json.put("action", intent.getAction());
|
|
220
|
+
|
|
221
|
+
Bundle extras = intent.getExtras();
|
|
222
|
+
if (extras != null) {
|
|
223
|
+
json.put("extras", bundleToJson(extras));
|
|
224
|
+
}
|
|
225
|
+
} catch (Exception e) {
|
|
226
|
+
Log.e(TAG, "intentToJson failed", e);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return json;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private JSObject bundleToJson(Bundle bundle) {
|
|
233
|
+
JSObject json = new JSObject();
|
|
234
|
+
|
|
235
|
+
if (bundle == null) {
|
|
236
|
+
return json;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
for (String key : bundle.keySet()) {
|
|
240
|
+
try {
|
|
241
|
+
Object value = bundle.get(key);
|
|
242
|
+
|
|
243
|
+
if (value == null) {
|
|
244
|
+
json.put(key, JSONObject.NULL);
|
|
245
|
+
} else if (value instanceof String) {
|
|
246
|
+
json.put(key, value);
|
|
247
|
+
} else if (value instanceof Integer) {
|
|
248
|
+
json.put(key, value);
|
|
249
|
+
} else if (value instanceof Long) {
|
|
250
|
+
json.put(key, value);
|
|
251
|
+
} else if (value instanceof Double) {
|
|
252
|
+
json.put(key, value);
|
|
253
|
+
} else if (value instanceof Float) {
|
|
254
|
+
json.put(key, ((Float) value).doubleValue());
|
|
255
|
+
} else if (value instanceof Boolean) {
|
|
256
|
+
json.put(key, value);
|
|
257
|
+
} else if (value instanceof Bundle) {
|
|
258
|
+
json.put(key, bundleToJson((Bundle) value));
|
|
259
|
+
} else if (value instanceof String[]) {
|
|
260
|
+
JSArray arr = new JSArray();
|
|
261
|
+
for (String s : (String[]) value) {
|
|
262
|
+
arr.put(s);
|
|
263
|
+
}
|
|
264
|
+
json.put(key, arr);
|
|
265
|
+
} else if (value instanceof int[]) {
|
|
266
|
+
JSArray arr = new JSArray();
|
|
267
|
+
for (int i : (int[]) value) {
|
|
268
|
+
arr.put(i);
|
|
269
|
+
}
|
|
270
|
+
json.put(key, arr);
|
|
271
|
+
} else if (value instanceof Parcelable) {
|
|
272
|
+
json.put(key, value.toString());
|
|
273
|
+
} else if (value instanceof Parcelable[]) {
|
|
274
|
+
JSArray arr = new JSArray();
|
|
275
|
+
for (Parcelable p : (Parcelable[]) value) {
|
|
276
|
+
arr.put(p.toString());
|
|
277
|
+
}
|
|
278
|
+
json.put(key, arr);
|
|
279
|
+
} else {
|
|
280
|
+
json.put(key, value.toString());
|
|
281
|
+
}
|
|
282
|
+
} catch (Exception e) {
|
|
283
|
+
Log.w(TAG, "bundleToJson key failed: " + key, e);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return json;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
@Override
|
|
291
|
+
protected void handleOnDestroy() {
|
|
292
|
+
for (BroadcastReceiver receiver : receivers.values()) {
|
|
293
|
+
try {
|
|
294
|
+
getContext().unregisterReceiver(receiver);
|
|
295
|
+
} catch (Exception ignored) {
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
receivers.clear();
|
|
299
|
+
super.handleOnDestroy();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IBroadcastResult } from "./IBroadcastPlugin";
|
|
2
|
+
/**
|
|
3
|
+
* Android Broadcast 송수신 플러그인
|
|
4
|
+
* - 산업용 장치(바코드 스캐너, PDA 등) 연동용
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class Broadcast {
|
|
7
|
+
/**
|
|
8
|
+
* Broadcast 수신 등록
|
|
9
|
+
* @returns 해제 함수
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const unsub = await Broadcast.subscribe(
|
|
14
|
+
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
15
|
+
* (result) => console.log(result.extras)
|
|
16
|
+
* );
|
|
17
|
+
*
|
|
18
|
+
* // 해제
|
|
19
|
+
* unsub();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
static subscribe(filters: string[], callback: (result: IBroadcastResult) => void): Promise<() => Promise<void>>;
|
|
23
|
+
/**
|
|
24
|
+
* 모든 Broadcast 수신기 해제
|
|
25
|
+
*/
|
|
26
|
+
static unsubscribeAll(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Broadcast 전송
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* await Broadcast.send({
|
|
33
|
+
* action: "com.symbol.datawedge.api.ACTION",
|
|
34
|
+
* extras: {
|
|
35
|
+
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
36
|
+
* }
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
static send(options: {
|
|
41
|
+
action: string;
|
|
42
|
+
extras?: Record<string, unknown>;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* 앱 시작 Intent 가져오기
|
|
46
|
+
*/
|
|
47
|
+
static getLaunchIntent(): Promise<IBroadcastResult>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { registerPlugin } from "@capacitor/core";
|
|
2
|
+
const BroadcastPlugin = registerPlugin("Broadcast", {
|
|
3
|
+
web: async () => {
|
|
4
|
+
const { BroadcastWeb } = await import("./web/BroadcastWeb");
|
|
5
|
+
return new BroadcastWeb();
|
|
6
|
+
},
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* Android Broadcast 송수신 플러그인
|
|
10
|
+
* - 산업용 장치(바코드 스캐너, PDA 등) 연동용
|
|
11
|
+
*/
|
|
12
|
+
export class Broadcast {
|
|
13
|
+
/**
|
|
14
|
+
* Broadcast 수신 등록
|
|
15
|
+
* @returns 해제 함수
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const unsub = await Broadcast.subscribe(
|
|
20
|
+
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
21
|
+
* (result) => console.log(result.extras)
|
|
22
|
+
* );
|
|
23
|
+
*
|
|
24
|
+
* // 해제
|
|
25
|
+
* unsub();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
static async subscribe(filters, callback) {
|
|
29
|
+
const { id } = await BroadcastPlugin.subscribe({ filters }, callback);
|
|
30
|
+
return async () => {
|
|
31
|
+
await BroadcastPlugin.unsubscribe({ id });
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 모든 Broadcast 수신기 해제
|
|
36
|
+
*/
|
|
37
|
+
static async unsubscribeAll() {
|
|
38
|
+
await BroadcastPlugin.unsubscribeAll();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Broadcast 전송
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* await Broadcast.send({
|
|
46
|
+
* action: "com.symbol.datawedge.api.ACTION",
|
|
47
|
+
* extras: {
|
|
48
|
+
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
49
|
+
* }
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
static async send(options) {
|
|
54
|
+
await BroadcastPlugin.send(options);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 앱 시작 Intent 가져오기
|
|
58
|
+
*/
|
|
59
|
+
static async getLaunchIntent() {
|
|
60
|
+
return await BroadcastPlugin.getLaunchIntent();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface IBroadcastResult {
|
|
2
|
+
/** Broadcast action */
|
|
3
|
+
action?: string;
|
|
4
|
+
/** Extra data */
|
|
5
|
+
extras?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface IBroadcastPlugin {
|
|
8
|
+
/**
|
|
9
|
+
* Broadcast 수신기 등록
|
|
10
|
+
*/
|
|
11
|
+
subscribe(options: {
|
|
12
|
+
filters: string[];
|
|
13
|
+
}, callback: (result: IBroadcastResult) => void): Promise<{
|
|
14
|
+
id: string;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* 특정 Broadcast 수신기 해제
|
|
18
|
+
*/
|
|
19
|
+
unsubscribe(options: {
|
|
20
|
+
id: string;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* 모든 Broadcast 수신기 해제
|
|
24
|
+
*/
|
|
25
|
+
unsubscribeAll(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Broadcast 전송
|
|
28
|
+
*/
|
|
29
|
+
send(options: {
|
|
30
|
+
action: string;
|
|
31
|
+
extras?: Record<string, unknown>;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* 앱 시작 Intent 가져오기
|
|
35
|
+
*/
|
|
36
|
+
getLaunchIntent(): Promise<IBroadcastResult>;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
import { IBroadcastPlugin, IBroadcastResult } from "../IBroadcastPlugin";
|
|
3
|
+
export declare class BroadcastWeb extends WebPlugin implements IBroadcastPlugin {
|
|
4
|
+
subscribe(_options: {
|
|
5
|
+
filters: string[];
|
|
6
|
+
}, _callback: (result: IBroadcastResult) => void): Promise<{
|
|
7
|
+
id: string;
|
|
8
|
+
}>;
|
|
9
|
+
unsubscribe(_options: {
|
|
10
|
+
id: string;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
unsubscribeAll(): Promise<void>;
|
|
13
|
+
send(_options: {
|
|
14
|
+
action: string;
|
|
15
|
+
extras?: Record<string, unknown>;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
getLaunchIntent(): Promise<IBroadcastResult>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
export class BroadcastWeb extends WebPlugin {
|
|
3
|
+
async subscribe(_options, _callback) {
|
|
4
|
+
alert("[Broadcast] 웹 환경에서는 Broadcast를 지원하지 않습니다.");
|
|
5
|
+
return await Promise.resolve({ id: "web-stub" });
|
|
6
|
+
}
|
|
7
|
+
async unsubscribe(_options) {
|
|
8
|
+
await Promise.resolve();
|
|
9
|
+
}
|
|
10
|
+
async unsubscribeAll() {
|
|
11
|
+
await Promise.resolve();
|
|
12
|
+
}
|
|
13
|
+
async send(_options) {
|
|
14
|
+
alert("[Broadcast] 웹 환경에서는 Broadcast를 지원하지 않습니다.");
|
|
15
|
+
await Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
async getLaunchIntent() {
|
|
18
|
+
return await Promise.resolve({});
|
|
19
|
+
}
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@simplysm/capacitor-plugin-broadcast",
|
|
3
|
+
"version": "12.16.9",
|
|
4
|
+
"description": "심플리즘 패키지 - Capacitor Broadcast Plugin",
|
|
5
|
+
"author": "김석래",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/kslhunter/simplysm.git",
|
|
9
|
+
"directory": "packages/capacitor-plugin-broadcast"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"capacitor": {
|
|
16
|
+
"android": {
|
|
17
|
+
"src": "android"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@capacitor/core": "^7.4.4"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/Broadcast.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { registerPlugin } from "@capacitor/core";
|
|
2
|
+
import { IBroadcastPlugin, IBroadcastResult } from "./IBroadcastPlugin";
|
|
3
|
+
|
|
4
|
+
const BroadcastPlugin = registerPlugin<IBroadcastPlugin>("Broadcast", {
|
|
5
|
+
web: async () => {
|
|
6
|
+
const { BroadcastWeb } = await import("./web/BroadcastWeb");
|
|
7
|
+
return new BroadcastWeb();
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Android Broadcast 송수신 플러그인
|
|
13
|
+
* - 산업용 장치(바코드 스캐너, PDA 등) 연동용
|
|
14
|
+
*/
|
|
15
|
+
export abstract class Broadcast {
|
|
16
|
+
/**
|
|
17
|
+
* Broadcast 수신 등록
|
|
18
|
+
* @returns 해제 함수
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const unsub = await Broadcast.subscribe(
|
|
23
|
+
* ["com.symbol.datawedge.api.RESULT_ACTION"],
|
|
24
|
+
* (result) => console.log(result.extras)
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* // 해제
|
|
28
|
+
* unsub();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
static async subscribe(
|
|
32
|
+
filters: string[],
|
|
33
|
+
callback: (result: IBroadcastResult) => void,
|
|
34
|
+
): Promise<() => Promise<void>> {
|
|
35
|
+
const { id } = await BroadcastPlugin.subscribe({ filters }, callback);
|
|
36
|
+
return async () => {
|
|
37
|
+
await BroadcastPlugin.unsubscribe({ id });
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 모든 Broadcast 수신기 해제
|
|
43
|
+
*/
|
|
44
|
+
static async unsubscribeAll(): Promise<void> {
|
|
45
|
+
await BroadcastPlugin.unsubscribeAll();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Broadcast 전송
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* await Broadcast.send({
|
|
54
|
+
* action: "com.symbol.datawedge.api.ACTION",
|
|
55
|
+
* extras: {
|
|
56
|
+
* "com.symbol.datawedge.api.SOFT_SCAN_TRIGGER": "TOGGLE_SCANNING"
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
static async send(options: { action: string; extras?: Record<string, unknown> }): Promise<void> {
|
|
62
|
+
await BroadcastPlugin.send(options);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 앱 시작 Intent 가져오기
|
|
67
|
+
*/
|
|
68
|
+
static async getLaunchIntent(): Promise<IBroadcastResult> {
|
|
69
|
+
return await BroadcastPlugin.getLaunchIntent();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface IBroadcastResult {
|
|
2
|
+
/** Broadcast action */
|
|
3
|
+
action?: string;
|
|
4
|
+
/** Extra data */
|
|
5
|
+
extras?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface IBroadcastPlugin {
|
|
9
|
+
/**
|
|
10
|
+
* Broadcast 수신기 등록
|
|
11
|
+
*/
|
|
12
|
+
subscribe(
|
|
13
|
+
options: { filters: string[] },
|
|
14
|
+
callback: (result: IBroadcastResult) => void,
|
|
15
|
+
): Promise<{ id: string }>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 특정 Broadcast 수신기 해제
|
|
19
|
+
*/
|
|
20
|
+
unsubscribe(options: { id: string }): Promise<void>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 모든 Broadcast 수신기 해제
|
|
24
|
+
*/
|
|
25
|
+
unsubscribeAll(): Promise<void>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Broadcast 전송
|
|
29
|
+
*/
|
|
30
|
+
send(options: { action: string; extras?: Record<string, unknown> }): Promise<void>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 앱 시작 Intent 가져오기
|
|
34
|
+
*/
|
|
35
|
+
getLaunchIntent(): Promise<IBroadcastResult>;
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
import { IBroadcastPlugin, IBroadcastResult } from "../IBroadcastPlugin";
|
|
3
|
+
|
|
4
|
+
export class BroadcastWeb extends WebPlugin implements IBroadcastPlugin {
|
|
5
|
+
async subscribe(
|
|
6
|
+
_options: { filters: string[] },
|
|
7
|
+
_callback: (result: IBroadcastResult) => void,
|
|
8
|
+
): Promise<{ id: string }> {
|
|
9
|
+
alert("[Broadcast] 웹 환경에서는 Broadcast를 지원하지 않습니다.");
|
|
10
|
+
return await Promise.resolve({ id: "web-stub" });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async unsubscribe(_options: { id: string }): Promise<void> {
|
|
14
|
+
await Promise.resolve();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async unsubscribeAll(): Promise<void> {
|
|
18
|
+
await Promise.resolve();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async send(_options: { action: string; extras?: Record<string, unknown> }): Promise<void> {
|
|
22
|
+
alert("[Broadcast] 웹 환경에서는 Broadcast를 지원하지 않습니다.");
|
|
23
|
+
await Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getLaunchIntent(): Promise<IBroadcastResult> {
|
|
27
|
+
return await Promise.resolve({});
|
|
28
|
+
}
|
|
29
|
+
}
|