@onekeyfe/hd-ble-sdk 1.1.34-alpha.2 → 1.1.34-alpha.3
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/__tests__/device-state-events.test.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/package.json +5 -5
- package/src/index.ts +19 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
|
|
4
|
+
describe('hd-ble-sdk device state events', () => {
|
|
5
|
+
test('forwards DEVICE.STATE to React Native SDK consumers', () => {
|
|
6
|
+
const source = readFileSync(resolve(__dirname, '../src/index.ts'), 'utf8');
|
|
7
|
+
const deviceEventHandler = source.slice(
|
|
8
|
+
source.indexOf('case DEVICE_EVENT:'),
|
|
9
|
+
source.indexOf('case IFRAME.CALLBACK:')
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
expect(deviceEventHandler).toContain('DEVICE.STATE');
|
|
13
|
+
expect(deviceEventHandler).toContain('eventEmitter.emit(message.type, message.payload)');
|
|
14
|
+
});
|
|
15
|
+
});
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AASpD,eAAO,MAAM,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;CAAO,CAAC;AA8JpE,QAAA,MAAM,cAAc,qCAUlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -539,6 +539,9 @@ const cancel = (connectId) => {
|
|
|
539
539
|
return;
|
|
540
540
|
_core.handleMessage({ event: HardwareSdk.IFRAME.CANCEL, type: HardwareSdk.IFRAME.CANCEL, payload: { connectId } });
|
|
541
541
|
};
|
|
542
|
+
const cancelOperation = (operationId) => {
|
|
543
|
+
_core === null || _core === void 0 ? void 0 : _core.cancelOperation(operationId);
|
|
544
|
+
};
|
|
542
545
|
function handleMessage(message) {
|
|
543
546
|
var _a;
|
|
544
547
|
const { event, type } = message;
|
|
@@ -571,7 +574,13 @@ function handleMessage(message) {
|
|
|
571
574
|
eventEmitter.emit(message.event, message);
|
|
572
575
|
break;
|
|
573
576
|
case HardwareSdk.DEVICE_EVENT:
|
|
574
|
-
if ([
|
|
577
|
+
if ([
|
|
578
|
+
HardwareSdk.DEVICE.CONNECT,
|
|
579
|
+
HardwareSdk.DEVICE.DISCONNECT,
|
|
580
|
+
HardwareSdk.DEVICE.FEATURES,
|
|
581
|
+
HardwareSdk.DEVICE.STATE,
|
|
582
|
+
HardwareSdk.DEVICE.SUPPORT_FEATURES,
|
|
583
|
+
].includes(message.type)) {
|
|
575
584
|
eventEmitter.emit(message.type, message.payload);
|
|
576
585
|
}
|
|
577
586
|
break;
|
|
@@ -615,11 +624,12 @@ const init = (settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
615
624
|
});
|
|
616
625
|
const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
617
626
|
var _a, _b, _c;
|
|
618
|
-
|
|
627
|
+
const logBlockLabel = HardwareSdk.getLogBlockLabel(params);
|
|
628
|
+
Log.debug('call: ', logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : params);
|
|
619
629
|
try {
|
|
620
630
|
const response = yield postMessage({ event: HardwareSdk.IFRAME.CALL, type: HardwareSdk.IFRAME.CALL, payload: params });
|
|
621
631
|
if (response) {
|
|
622
|
-
Log.debug('response: ', response);
|
|
632
|
+
Log.debug('response: ', logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : response);
|
|
623
633
|
if (!response.success) {
|
|
624
634
|
if (((_a = response.payload) === null || _a === void 0 ? void 0 : _a.code) === hdShared.HardwareErrorCode.BlePermissionError) {
|
|
625
635
|
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
|
|
@@ -647,6 +657,7 @@ const HardwareBleSdk = HardwareSdk__default["default"]({
|
|
|
647
657
|
init,
|
|
648
658
|
call,
|
|
649
659
|
cancel,
|
|
660
|
+
cancelOperation,
|
|
650
661
|
dispose,
|
|
651
662
|
uiResponse,
|
|
652
663
|
updateSettings,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-ble-sdk",
|
|
3
|
-
"version": "1.1.34-alpha.
|
|
3
|
+
"version": "1.1.34-alpha.3",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "ISC",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-core": "1.1.34-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.1.34-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport-react-native": "1.1.34-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.1.34-alpha.3",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.1.34-alpha.3",
|
|
25
|
+
"@onekeyfe/hd-transport-react-native": "1.1.34-alpha.3"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "3688bc8495eeb2ffd5616270d13fa29e8967623a"
|
|
28
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import HardwareSdk, {
|
|
|
13
13
|
createUiMessage,
|
|
14
14
|
enableLog,
|
|
15
15
|
executeCallback,
|
|
16
|
+
getLogBlockLabel,
|
|
16
17
|
getLogger,
|
|
17
18
|
initCore,
|
|
18
19
|
parseConnectSettings,
|
|
@@ -50,6 +51,10 @@ const cancel = (connectId?: string) => {
|
|
|
50
51
|
_core.handleMessage({ event: IFRAME.CANCEL, type: IFRAME.CANCEL, payload: { connectId } });
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
const cancelOperation = (operationId: string) => {
|
|
55
|
+
_core?.cancelOperation(operationId);
|
|
56
|
+
};
|
|
57
|
+
|
|
53
58
|
function handleMessage(message: CoreMessage) {
|
|
54
59
|
const { event, type } = message;
|
|
55
60
|
if (!_core) {
|
|
@@ -84,7 +89,13 @@ function handleMessage(message: CoreMessage) {
|
|
|
84
89
|
case DEVICE_EVENT:
|
|
85
90
|
if (
|
|
86
91
|
(
|
|
87
|
-
[
|
|
92
|
+
[
|
|
93
|
+
DEVICE.CONNECT,
|
|
94
|
+
DEVICE.DISCONNECT,
|
|
95
|
+
DEVICE.FEATURES,
|
|
96
|
+
DEVICE.STATE,
|
|
97
|
+
DEVICE.SUPPORT_FEATURES,
|
|
98
|
+
] as string[]
|
|
88
99
|
).includes(message.type)
|
|
89
100
|
) {
|
|
90
101
|
eventEmitter.emit(message.type, message.payload);
|
|
@@ -138,12 +149,16 @@ const init = async (settings: Partial<ConnectSettings>) => {
|
|
|
138
149
|
};
|
|
139
150
|
|
|
140
151
|
const call = async (params: any) => {
|
|
141
|
-
|
|
152
|
+
const logBlockLabel = getLogBlockLabel(params);
|
|
153
|
+
Log.debug('call: ', logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : params);
|
|
142
154
|
|
|
143
155
|
try {
|
|
144
156
|
const response = await postMessage({ event: IFRAME.CALL, type: IFRAME.CALL, payload: params });
|
|
145
157
|
if (response) {
|
|
146
|
-
Log.debug(
|
|
158
|
+
Log.debug(
|
|
159
|
+
'response: ',
|
|
160
|
+
logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : response
|
|
161
|
+
);
|
|
147
162
|
|
|
148
163
|
if (!response.success) {
|
|
149
164
|
if (response.payload?.code === HardwareErrorCode.BlePermissionError) {
|
|
@@ -179,6 +194,7 @@ const HardwareBleSdk = HardwareSdk({
|
|
|
179
194
|
init,
|
|
180
195
|
call,
|
|
181
196
|
cancel,
|
|
197
|
+
cancelOperation,
|
|
182
198
|
dispose,
|
|
183
199
|
uiResponse,
|
|
184
200
|
updateSettings,
|