@onekeyfe/hd-ble-sdk 1.2.8-alpha.6 → 1.2.8-alpha.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/__tests__/device-state-events.test.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/package.json +5 -5
- package/src/index.ts +6 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
import EventEmitter from 'events';
|
|
4
|
-
import { CORE_EVENT, initCore } from '@onekeyfe/hd-core';
|
|
5
|
-
import { createDeferred } from '@onekeyfe/hd-shared';
|
|
4
|
+
import { CORE_EVENT, UI_REQUEST, initCore } from '@onekeyfe/hd-core';
|
|
5
|
+
import { HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
|
|
6
6
|
|
|
7
7
|
import sdkExport, { messagePromises } from '../src';
|
|
8
8
|
|
|
@@ -57,6 +57,17 @@ describe('SDK request cleanup', () => {
|
|
|
57
57
|
await sdk.dispose();
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
+
test.each([
|
|
61
|
+
[HardwareErrorCode.BlePoweredOff, UI_REQUEST.BLUETOOTH_POWERED_OFF],
|
|
62
|
+
[HardwareErrorCode.BleUnsupported, UI_REQUEST.BLUETOOTH_UNSUPPORTED],
|
|
63
|
+
[HardwareErrorCode.BleLocationError, UI_REQUEST.LOCATION_PERMISSION],
|
|
64
|
+
])('emits the adapter UI request for error %s', async (code, type) => {
|
|
65
|
+
const response = { success: false, payload: { code, error: 'Adapter unavailable' } };
|
|
66
|
+
core.handleMessage.mockResolvedValueOnce(response);
|
|
67
|
+
await expect(sdk.call({ method: 'searchDevices' })).resolves.toEqual(response);
|
|
68
|
+
expect(core.handleMessage).toHaveBeenNthCalledWith(2, expect.objectContaining({ type }));
|
|
69
|
+
});
|
|
70
|
+
|
|
60
71
|
test('removes only the completed request when calls settle out of order', async () => {
|
|
61
72
|
const first = createDeferred<unknown>();
|
|
62
73
|
const second = createDeferred<unknown>();
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAqKpE,QAAA,MAAM,cAAc,qCASlB,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -632,7 +632,7 @@ const init = (settings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
632
632
|
}
|
|
633
633
|
});
|
|
634
634
|
const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
635
|
-
var _b, _c, _d;
|
|
635
|
+
var _b, _c, _d, _e, _f;
|
|
636
636
|
const blockLog = HardwareSdk.getLogBlockLabel(params);
|
|
637
637
|
Log.debug('call: ', blockLog !== null && blockLog !== void 0 ? blockLog : params);
|
|
638
638
|
try {
|
|
@@ -640,13 +640,19 @@ const call = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
640
640
|
if (response) {
|
|
641
641
|
Log.debug('response: ', blockLog ? '[REDACTED]' : response);
|
|
642
642
|
if (!response.success) {
|
|
643
|
-
if (((_b = response.payload) === null || _b === void 0 ? void 0 : _b.code) === hdShared.HardwareErrorCode.
|
|
643
|
+
if (((_b = response.payload) === null || _b === void 0 ? void 0 : _b.code) === hdShared.HardwareErrorCode.BlePoweredOff) {
|
|
644
|
+
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_POWERED_OFF), false);
|
|
645
|
+
}
|
|
646
|
+
if (((_c = response.payload) === null || _c === void 0 ? void 0 : _c.code) === hdShared.HardwareErrorCode.BleUnsupported) {
|
|
647
|
+
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_UNSUPPORTED), false);
|
|
648
|
+
}
|
|
649
|
+
if (((_d = response.payload) === null || _d === void 0 ? void 0 : _d.code) === hdShared.HardwareErrorCode.BlePermissionError) {
|
|
644
650
|
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
|
|
645
651
|
}
|
|
646
|
-
if (((
|
|
652
|
+
if (((_e = response.payload) === null || _e === void 0 ? void 0 : _e.code) === hdShared.HardwareErrorCode.BleLocationError) {
|
|
647
653
|
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.LOCATION_PERMISSION), false);
|
|
648
654
|
}
|
|
649
|
-
if (((
|
|
655
|
+
if (((_f = response.payload) === null || _f === void 0 ? void 0 : _f.code) === hdShared.HardwareErrorCode.BleLocationServicesDisabled) {
|
|
650
656
|
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.LOCATION_SERVICE_PERMISSION), false);
|
|
651
657
|
}
|
|
652
658
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-ble-sdk",
|
|
3
|
-
"version": "1.2.8-alpha.
|
|
3
|
+
"version": "1.2.8-alpha.9",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "ISC",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"lint:fix": "eslint . --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-core": "1.2.8-alpha.
|
|
25
|
-
"@onekeyfe/hd-shared": "1.2.8-alpha.
|
|
26
|
-
"@onekeyfe/hd-transport-react-native": "1.2.8-alpha.
|
|
24
|
+
"@onekeyfe/hd-core": "1.2.8-alpha.9",
|
|
25
|
+
"@onekeyfe/hd-shared": "1.2.8-alpha.9",
|
|
26
|
+
"@onekeyfe/hd-transport-react-native": "1.2.8-alpha.9"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "37659eef6ee06b7aa07faeb8f791f884b1b3e890"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -162,6 +162,12 @@ const call = async (params: any) => {
|
|
|
162
162
|
Log.debug('response: ', blockLog ? '[REDACTED]' : response);
|
|
163
163
|
|
|
164
164
|
if (!response.success) {
|
|
165
|
+
if (response.payload?.code === HardwareErrorCode.BlePoweredOff) {
|
|
166
|
+
postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_POWERED_OFF), false);
|
|
167
|
+
}
|
|
168
|
+
if (response.payload?.code === HardwareErrorCode.BleUnsupported) {
|
|
169
|
+
postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_UNSUPPORTED), false);
|
|
170
|
+
}
|
|
165
171
|
if (response.payload?.code === HardwareErrorCode.BlePermissionError) {
|
|
166
172
|
/**
|
|
167
173
|
* Send message notification when there is no Bluetooth access permission
|