@onekeyfe/hd-ble-sdk 1.2.0-alpha.3 → 1.2.0-alpha.30
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 -3
- package/package.json +5 -5
- package/src/index.ts +11 -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;AAuJpE,QAAA,MAAM,cAAc,qCASlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -571,7 +571,13 @@ function handleMessage(message) {
|
|
|
571
571
|
eventEmitter.emit(message.event, message);
|
|
572
572
|
break;
|
|
573
573
|
case HardwareSdk.DEVICE_EVENT:
|
|
574
|
-
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)) {
|
|
575
581
|
eventEmitter.emit(message.type, message.payload);
|
|
576
582
|
}
|
|
577
583
|
break;
|
|
@@ -615,11 +621,12 @@ const init = (settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
615
621
|
});
|
|
616
622
|
const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
617
623
|
var _a, _b, _c;
|
|
618
|
-
|
|
624
|
+
const blockLog = HardwareSdk.getLogBlockLabel(params);
|
|
625
|
+
Log.debug('call: ', blockLog !== null && blockLog !== void 0 ? blockLog : params);
|
|
619
626
|
try {
|
|
620
627
|
const response = yield postMessage({ event: HardwareSdk.IFRAME.CALL, type: HardwareSdk.IFRAME.CALL, payload: params });
|
|
621
628
|
if (response) {
|
|
622
|
-
Log.debug('response: ', response);
|
|
629
|
+
Log.debug('response: ', blockLog ? '[REDACTED]' : response);
|
|
623
630
|
if (!response.success) {
|
|
624
631
|
if (((_a = response.payload) === null || _a === void 0 ? void 0 : _a.code) === hdShared.HardwareErrorCode.BlePermissionError) {
|
|
625
632
|
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
|
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.30",
|
|
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.30",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.30",
|
|
25
|
+
"@onekeyfe/hd-transport-react-native": "1.2.0-alpha.30"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "07405d2e3dcdd0ba351ae98b7cf4f61690ef2913"
|
|
28
28
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import HardwareSdk, {
|
|
|
14
14
|
enableLog,
|
|
15
15
|
executeCallback,
|
|
16
16
|
getLogger,
|
|
17
|
+
getLogBlockLabel,
|
|
17
18
|
initCore,
|
|
18
19
|
parseConnectSettings,
|
|
19
20
|
setLoggerPostMessage,
|
|
@@ -84,7 +85,13 @@ function handleMessage(message: CoreMessage) {
|
|
|
84
85
|
case DEVICE_EVENT:
|
|
85
86
|
if (
|
|
86
87
|
(
|
|
87
|
-
[
|
|
88
|
+
[
|
|
89
|
+
DEVICE.CONNECT,
|
|
90
|
+
DEVICE.DISCONNECT,
|
|
91
|
+
DEVICE.FEATURES,
|
|
92
|
+
DEVICE.STATE,
|
|
93
|
+
DEVICE.SUPPORT_FEATURES,
|
|
94
|
+
] as string[]
|
|
88
95
|
).includes(message.type)
|
|
89
96
|
) {
|
|
90
97
|
eventEmitter.emit(message.type, message.payload);
|
|
@@ -138,12 +145,13 @@ const init = async (settings: Partial<ConnectSettings>) => {
|
|
|
138
145
|
};
|
|
139
146
|
|
|
140
147
|
const call = async (params: any) => {
|
|
141
|
-
|
|
148
|
+
const blockLog = getLogBlockLabel(params);
|
|
149
|
+
Log.debug('call: ', blockLog ?? params);
|
|
142
150
|
|
|
143
151
|
try {
|
|
144
152
|
const response = await postMessage({ event: IFRAME.CALL, type: IFRAME.CALL, payload: params });
|
|
145
153
|
if (response) {
|
|
146
|
-
Log.debug('response: ', response);
|
|
154
|
+
Log.debug('response: ', blockLog ? '[REDACTED]' : response);
|
|
147
155
|
|
|
148
156
|
if (!response.success) {
|
|
149
157
|
if (response.payload?.code === HardwareErrorCode.BlePermissionError) {
|