@onekeyfe/hd-ble-sdk 1.2.0-alpha.14 → 1.2.0-alpha.140
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 +10 -7
- package/package.json +5 -5
- package/src/index.ts +11 -8
|
@@ -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;AAuJpE,QAAA,MAAM,cAAc,qCASlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -539,9 +539,6 @@ 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
|
-
};
|
|
545
542
|
function handleMessage(message) {
|
|
546
543
|
var _a;
|
|
547
544
|
const { event, type } = message;
|
|
@@ -574,7 +571,13 @@ function handleMessage(message) {
|
|
|
574
571
|
eventEmitter.emit(message.event, message);
|
|
575
572
|
break;
|
|
576
573
|
case HardwareSdk.DEVICE_EVENT:
|
|
577
|
-
if ([
|
|
574
|
+
if ([
|
|
575
|
+
HardwareSdk.DEVICE.CONNECT,
|
|
576
|
+
HardwareSdk.DEVICE.DISCONNECT,
|
|
577
|
+
HardwareSdk.DEVICE.FEATURES,
|
|
578
|
+
HardwareSdk.DEVICE.STATE,
|
|
579
|
+
HardwareSdk.DEVICE.SUPPORT_FEATURES,
|
|
580
|
+
].includes(message.type)) {
|
|
578
581
|
eventEmitter.emit(message.type, message.payload);
|
|
579
582
|
}
|
|
580
583
|
break;
|
|
@@ -618,11 +621,12 @@ const init = (settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
618
621
|
});
|
|
619
622
|
const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
620
623
|
var _a, _b, _c;
|
|
621
|
-
|
|
624
|
+
const blockLog = HardwareSdk.getLogBlockLabel(params);
|
|
625
|
+
Log.debug('call: ', blockLog !== null && blockLog !== void 0 ? blockLog : params);
|
|
622
626
|
try {
|
|
623
627
|
const response = yield postMessage({ event: HardwareSdk.IFRAME.CALL, type: HardwareSdk.IFRAME.CALL, payload: params });
|
|
624
628
|
if (response) {
|
|
625
|
-
Log.debug('response: ', response);
|
|
629
|
+
Log.debug('response: ', blockLog ? '[REDACTED]' : response);
|
|
626
630
|
if (!response.success) {
|
|
627
631
|
if (((_a = response.payload) === null || _a === void 0 ? void 0 : _a.code) === hdShared.HardwareErrorCode.BlePermissionError) {
|
|
628
632
|
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
|
|
@@ -650,7 +654,6 @@ const HardwareBleSdk = HardwareSdk__default["default"]({
|
|
|
650
654
|
init,
|
|
651
655
|
call,
|
|
652
656
|
cancel,
|
|
653
|
-
cancelOperation,
|
|
654
657
|
dispose,
|
|
655
658
|
uiResponse,
|
|
656
659
|
updateSettings,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-ble-sdk",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.140",
|
|
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.2.0-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport-react-native": "1.2.0-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.0-alpha.140",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.140",
|
|
25
|
+
"@onekeyfe/hd-transport-react-native": "1.2.0-alpha.140"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "15e3f0dc6c543c83a96e63b5d19aad70cdd6efb1"
|
|
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,10 +51,6 @@ const cancel = (connectId?: string) => {
|
|
|
50
51
|
_core.handleMessage({ event: IFRAME.CANCEL, type: IFRAME.CANCEL, payload: { connectId } });
|
|
51
52
|
};
|
|
52
53
|
|
|
53
|
-
const cancelOperation = (operationId: string) => {
|
|
54
|
-
_core?.cancelOperation(operationId);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
54
|
function handleMessage(message: CoreMessage) {
|
|
58
55
|
const { event, type } = message;
|
|
59
56
|
if (!_core) {
|
|
@@ -88,7 +85,13 @@ function handleMessage(message: CoreMessage) {
|
|
|
88
85
|
case DEVICE_EVENT:
|
|
89
86
|
if (
|
|
90
87
|
(
|
|
91
|
-
[
|
|
88
|
+
[
|
|
89
|
+
DEVICE.CONNECT,
|
|
90
|
+
DEVICE.DISCONNECT,
|
|
91
|
+
DEVICE.FEATURES,
|
|
92
|
+
DEVICE.STATE,
|
|
93
|
+
DEVICE.SUPPORT_FEATURES,
|
|
94
|
+
] as string[]
|
|
92
95
|
).includes(message.type)
|
|
93
96
|
) {
|
|
94
97
|
eventEmitter.emit(message.type, message.payload);
|
|
@@ -142,12 +145,13 @@ const init = async (settings: Partial<ConnectSettings>) => {
|
|
|
142
145
|
};
|
|
143
146
|
|
|
144
147
|
const call = async (params: any) => {
|
|
145
|
-
|
|
148
|
+
const blockLog = getLogBlockLabel(params);
|
|
149
|
+
Log.debug('call: ', blockLog ?? params);
|
|
146
150
|
|
|
147
151
|
try {
|
|
148
152
|
const response = await postMessage({ event: IFRAME.CALL, type: IFRAME.CALL, payload: params });
|
|
149
153
|
if (response) {
|
|
150
|
-
Log.debug('response: ', response);
|
|
154
|
+
Log.debug('response: ', blockLog ? '[REDACTED]' : response);
|
|
151
155
|
|
|
152
156
|
if (!response.success) {
|
|
153
157
|
if (response.payload?.code === HardwareErrorCode.BlePermissionError) {
|
|
@@ -183,7 +187,6 @@ const HardwareBleSdk = HardwareSdk({
|
|
|
183
187
|
init,
|
|
184
188
|
call,
|
|
185
189
|
cancel,
|
|
186
|
-
cancelOperation,
|
|
187
190
|
dispose,
|
|
188
191
|
uiResponse,
|
|
189
192
|
updateSettings,
|