@onekeyfe/hd-transport-react-native 0.1.43 → 0.1.46

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAavC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmBjE,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,WAAW,SAAQ;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;gBAEX,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY;IAKvC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IAyET,OAAO,CAAC,KAAK,EAAE,eAAe;;;IAgMpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IA4D/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAepB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAmFpE,IAAI;IAIJ,MAAM;CAOP"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EACL,UAAU,IAAI,aAAa,EAC3B,MAAM,EAEN,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAiC,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAkB,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAC1F,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAavC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAmBjE,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,WAAW,SAAQ;IAEnB,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAExC,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,EAAE,YAAY,CAAC;gBAEX,OAAO,EAAE,gBAAgB;IAIrC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY;IAKvC,SAAS,CAAC,UAAU,EAAE,GAAG;IAMzB,MAAM;IAIN,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAYjC,SAAS;IA2ET,OAAO,CAAC,KAAK,EAAE,eAAe;;;IAgMpC,sBAAsB,CAAC,cAAc,EAAE,cAAc;IA4D/C,OAAO,CAAC,IAAI,EAAE,MAAM;IAepB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAmFpE,IAAI;IAIJ,MAAM;CAOP"}
package/dist/index.js CHANGED
@@ -1,10 +1,18 @@
1
- import { Platform } from 'react-native';
2
- import { Buffer } from 'buffer';
3
- import { BleManager as BleManager$1, BleErrorCode, ScanMode } from 'react-native-ble-plx';
4
- import ByteBuffer from 'bytebuffer';
5
- import transport, { MESSAGE_TOP_CHAR, MESSAGE_HEADER_BYTE, COMMON_HEADER_SIZE } from '@onekeyfe/hd-transport';
6
- import { ERRORS, HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
7
- import BleManager from 'react-native-ble-manager';
1
+ 'use strict';
2
+
3
+ var reactNative = require('react-native');
4
+ var buffer = require('buffer');
5
+ var reactNativeBlePlx = require('react-native-ble-plx');
6
+ var ByteBuffer = require('bytebuffer');
7
+ var transport = require('@onekeyfe/hd-transport');
8
+ var hdShared = require('@onekeyfe/hd-shared');
9
+ var BleManager = require('react-native-ble-manager');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var ByteBuffer__default = /*#__PURE__*/_interopDefaultLegacy(ByteBuffer);
14
+ var transport__default = /*#__PURE__*/_interopDefaultLegacy(transport);
15
+ var BleManager__default = /*#__PURE__*/_interopDefaultLegacy(BleManager);
8
16
 
9
17
  /******************************************************************************
10
18
  Copyright (c) Microsoft Corporation.
@@ -32,17 +40,17 @@ function __awaiter(thisArg, _arguments, P, generator) {
32
40
  }
33
41
 
34
42
  const initializeBleManager = () => {
35
- BleManager.start({ showAlert: false });
43
+ BleManager__default["default"].start({ showAlert: false });
36
44
  };
37
45
  const getConnectedDeviceIds = (serviceUuids) => __awaiter(void 0, void 0, void 0, function* () {
38
- const connectedPeripherals = yield BleManager.getConnectedPeripherals(serviceUuids);
46
+ const connectedPeripherals = yield BleManager__default["default"].getConnectedPeripherals(serviceUuids);
39
47
  return connectedPeripherals.map(peripheral => {
40
48
  const { id, name, advertising = {} } = peripheral;
41
49
  return Object.assign({ id, name }, advertising);
42
50
  });
43
51
  });
44
52
  const getBondedDevices = () => __awaiter(void 0, void 0, void 0, function* () {
45
- const peripherals = yield BleManager.getBondedPeripherals();
53
+ const peripherals = yield BleManager__default["default"].getBondedPeripherals();
46
54
  return peripherals.map(peripheral => {
47
55
  const { id, name, advertising = {} } = peripheral;
48
56
  return Object.assign({ id, name }, advertising);
@@ -88,7 +96,7 @@ const subscribeBleOn = (bleManager, ms = 1000) => new Promise((resolve, reject)
88
96
  if (done)
89
97
  return;
90
98
  subscription.remove();
91
- reject(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
99
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
92
100
  }, ms);
93
101
  });
94
102
 
@@ -137,9 +145,9 @@ const isHeaderChunk = (chunk) => {
137
145
  if (chunk.length < 9)
138
146
  return false;
139
147
  const [MagicQuestionMark, sharp1, sharp2] = chunk;
140
- if (String.fromCharCode(MagicQuestionMark) === String.fromCharCode(MESSAGE_TOP_CHAR) &&
141
- String.fromCharCode(sharp1) === String.fromCharCode(MESSAGE_HEADER_BYTE) &&
142
- String.fromCharCode(sharp2) === String.fromCharCode(MESSAGE_HEADER_BYTE)) {
148
+ if (String.fromCharCode(MagicQuestionMark) === String.fromCharCode(transport.MESSAGE_TOP_CHAR) &&
149
+ String.fromCharCode(sharp1) === String.fromCharCode(transport.MESSAGE_HEADER_BYTE) &&
150
+ String.fromCharCode(sharp2) === String.fromCharCode(transport.MESSAGE_HEADER_BYTE)) {
143
151
  return true;
144
152
  }
145
153
  return false;
@@ -156,7 +164,7 @@ class BleTransport {
156
164
  }
157
165
  }
158
166
 
159
- const { check, buildBuffers, receiveOne, parseConfigure } = transport;
167
+ const { check, buildBuffers, receiveOne, parseConfigure } = transport__default["default"];
160
168
  const transportCache = {};
161
169
  let connectOptions = {
162
170
  requestMTU: 256,
@@ -194,7 +202,7 @@ class ReactNativeBleTransport {
194
202
  getPlxManager() {
195
203
  if (this.blePlxManager)
196
204
  return Promise.resolve(this.blePlxManager);
197
- this.blePlxManager = new BleManager$1();
205
+ this.blePlxManager = new reactNativeBlePlx.BleManager();
198
206
  initializeBleManager();
199
207
  return Promise.resolve(this.blePlxManager);
200
208
  }
@@ -212,23 +220,26 @@ class ReactNativeBleTransport {
212
220
  return;
213
221
  }
214
222
  blePlxManager.startDeviceScan(null, {
215
- scanMode: ScanMode.LowLatency,
223
+ scanMode: reactNativeBlePlx.ScanMode.LowLatency,
216
224
  }, (error, device) => {
217
225
  var _a, _b;
218
226
  if (error) {
219
227
  this.Log.debug('ble scan manager: ', blePlxManager);
220
228
  this.Log.debug('ble scan error: ', error);
221
- if ([BleErrorCode.BluetoothPoweredOff, BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {
222
- reject(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
229
+ if ([reactNativeBlePlx.BleErrorCode.BluetoothPoweredOff, reactNativeBlePlx.BleErrorCode.BluetoothInUnknownState].includes(error.errorCode)) {
230
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePermissionError));
231
+ }
232
+ else if (error.errorCode === reactNativeBlePlx.BleErrorCode.BluetoothUnauthorized) {
233
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationError));
223
234
  }
224
- else if (error.errorCode === BleErrorCode.BluetoothUnauthorized) {
225
- reject(ERRORS.TypedError(HardwareErrorCode.BleLocationError));
235
+ else if (error.errorCode === reactNativeBlePlx.BleErrorCode.LocationServicesDisabled) {
236
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleLocationServicesDisabled));
226
237
  }
227
- else if (error.errorCode === BleErrorCode.ScanStartFailed) {
238
+ else if (error.errorCode === reactNativeBlePlx.BleErrorCode.ScanStartFailed) {
228
239
  timer.timeout(() => { }, this.scanTimeout);
229
240
  }
230
241
  else {
231
- reject(ERRORS.TypedError(HardwareErrorCode.BleScanError, (_a = error.reason) !== null && _a !== void 0 ? _a : ''));
242
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleScanError, (_a = error.reason) !== null && _a !== void 0 ? _a : ''));
232
243
  }
233
244
  return;
234
245
  }
@@ -263,7 +274,7 @@ class ReactNativeBleTransport {
263
274
  return __awaiter(this, void 0, void 0, function* () {
264
275
  const { uuid } = input;
265
276
  if (!uuid) {
266
- throw ERRORS.TypedError(HardwareErrorCode.BleRequiredUUID);
277
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleRequiredUUID);
267
278
  }
268
279
  let device = null;
269
280
  if (transportCache[uuid]) {
@@ -295,23 +306,23 @@ class ReactNativeBleTransport {
295
306
  }
296
307
  catch (e) {
297
308
  this.Log.debug('try to connect to device has error: ', e);
298
- if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||
299
- e.errorCode === BleErrorCode.OperationCancelled) {
309
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
310
+ e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
300
311
  connectOptions = {};
301
312
  this.Log.debug('first try to reconnect without params');
302
313
  device = yield blePlxManager.connectToDevice(uuid);
303
314
  }
304
- else if (e.errorCode === BleErrorCode.DeviceAlreadyConnected) {
315
+ else if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceAlreadyConnected) {
305
316
  this.Log.debug('device already connected');
306
- throw ERRORS.TypedError(HardwareErrorCode.BleAlreadyConnected);
317
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleAlreadyConnected);
307
318
  }
308
319
  else {
309
- throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, (_a = e.reason) !== null && _a !== void 0 ? _a : e);
320
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_a = e.reason) !== null && _a !== void 0 ? _a : e);
310
321
  }
311
322
  }
312
323
  }
313
324
  if (!device) {
314
- throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, 'unable to connect to device');
325
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, 'unable to connect to device');
315
326
  }
316
327
  if (!(yield device.isConnected())) {
317
328
  this.Log.debug('not connected, try to connect to device: ', uuid);
@@ -320,8 +331,8 @@ class ReactNativeBleTransport {
320
331
  }
321
332
  catch (e) {
322
333
  this.Log.debug('not connected, try to connect to device has error: ', e);
323
- if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed ||
324
- e.errorCode === BleErrorCode.OperationCancelled) {
334
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceMTUChangeFailed ||
335
+ e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
325
336
  connectOptions = {};
326
337
  this.Log.debug('second try to reconnect without params');
327
338
  try {
@@ -329,7 +340,7 @@ class ReactNativeBleTransport {
329
340
  }
330
341
  catch (e) {
331
342
  this.Log.debug('last try to reconnect error: ', e);
332
- if (e.errorCode === BleErrorCode.OperationCancelled) {
343
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
333
344
  this.Log.debug('last try to reconnect');
334
345
  yield device.cancelConnection();
335
346
  yield device.connect();
@@ -337,15 +348,15 @@ class ReactNativeBleTransport {
337
348
  }
338
349
  }
339
350
  else {
340
- throw ERRORS.TypedError(HardwareErrorCode.BleConnectedError, (_b = e.reason) !== null && _b !== void 0 ? _b : e);
351
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, (_b = e.reason) !== null && _b !== void 0 ? _b : e);
341
352
  }
342
353
  }
343
354
  }
344
- if (Platform.OS === 'android') {
355
+ if (reactNative.Platform.OS === 'android') {
345
356
  const bondedDevices = yield getBondedDevices();
346
357
  const hasBonded = !!bondedDevices.find(bondedDevice => bondedDevice.id === (device === null || device === void 0 ? void 0 : device.id));
347
358
  if (!hasBonded) {
348
- throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
359
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
349
360
  }
350
361
  }
351
362
  yield device.discoverAllServicesAndCharacteristics();
@@ -371,14 +382,14 @@ class ReactNativeBleTransport {
371
382
  catch (e) {
372
383
  this.Log.debug('cancel connection error when service not found: ', e.message || e.reason);
373
384
  }
374
- throw ERRORS.TypedError(HardwareErrorCode.BleServiceNotFound);
385
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleServiceNotFound);
375
386
  }
376
387
  const { serviceUuid, writeUuid, notifyUuid } = infos;
377
388
  if (!characteristics) {
378
389
  characteristics = yield device.characteristicsForService(serviceUuid);
379
390
  }
380
391
  if (!characteristics) {
381
- throw ERRORS.TypedError(HardwareErrorCode.BleCharacteristicNotFound);
392
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotFound);
382
393
  }
383
394
  let writeCharacteristic;
384
395
  let notifyCharacteristic;
@@ -391,16 +402,16 @@ class ReactNativeBleTransport {
391
402
  }
392
403
  }
393
404
  if (!writeCharacteristic) {
394
- throw ERRORS.TypedError('BLECharacteristicNotFound: write characteristic not found');
405
+ throw hdShared.ERRORS.TypedError('BLECharacteristicNotFound: write characteristic not found');
395
406
  }
396
407
  if (!notifyCharacteristic) {
397
- throw ERRORS.TypedError('BLECharacteristicNotFound: notify characteristic not found');
408
+ throw hdShared.ERRORS.TypedError('BLECharacteristicNotFound: notify characteristic not found');
398
409
  }
399
410
  if (!writeCharacteristic.isWritableWithResponse) {
400
- throw ERRORS.TypedError('BLECharacteristicNotWritable: write characteristic not writable');
411
+ throw hdShared.ERRORS.TypedError('BLECharacteristicNotWritable: write characteristic not writable');
401
412
  }
402
413
  if (!notifyCharacteristic.isNotifiable) {
403
- throw ERRORS.TypedError('BLECharacteristicNotNotifiable: notify characteristic not notifiable');
414
+ throw hdShared.ERRORS.TypedError('BLECharacteristicNotNotifiable: notify characteristic not notifiable');
404
415
  }
405
416
  const transport = new BleTransport(device, writeCharacteristic, notifyCharacteristic);
406
417
  transport.nofitySubscription = this._monitorCharacteristic(transport.notifyCharacteristic);
@@ -426,33 +437,33 @@ class ReactNativeBleTransport {
426
437
  }
427
438
  _monitorCharacteristic(characteristic) {
428
439
  let bufferLength = 0;
429
- let buffer = [];
440
+ let buffer$1 = [];
430
441
  const subscription = characteristic.monitor((error, c) => {
431
442
  var _a, _b, _c;
432
443
  if (error) {
433
444
  this.Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
434
445
  if (this.runPromise) {
435
- this.runPromise.reject(ERRORS.TypedError(HardwareErrorCode.BleCharacteristicNotifyError, (_a = error.reason) !== null && _a !== void 0 ? _a : error.message));
446
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyError, (_a = error.reason) !== null && _a !== void 0 ? _a : error.message));
436
447
  this.Log.debug(': monitor notify error, and has unreleased Promise');
437
448
  }
438
449
  return;
439
450
  }
440
451
  if (!c) {
441
- throw ERRORS.TypedError(HardwareErrorCode.BleMonitorError);
452
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleMonitorError);
442
453
  }
443
454
  try {
444
- const data = Buffer.from(c.value, 'base64');
455
+ const data = buffer.Buffer.from(c.value, 'base64');
445
456
  if (isHeaderChunk(data)) {
446
457
  bufferLength = data.readInt32BE(5);
447
- buffer = [...data.subarray(3)];
458
+ buffer$1 = [...data.subarray(3)];
448
459
  }
449
460
  else {
450
- buffer = buffer.concat([...data]);
461
+ buffer$1 = buffer$1.concat([...data]);
451
462
  }
452
- if (buffer.length - COMMON_HEADER_SIZE >= bufferLength) {
453
- const value = Buffer.from(buffer);
463
+ if (buffer$1.length - transport.COMMON_HEADER_SIZE >= bufferLength) {
464
+ const value = buffer.Buffer.from(buffer$1);
454
465
  bufferLength = 0;
455
- buffer = [];
466
+ buffer$1 = [];
456
467
  (_b = this.runPromise) === null || _b === void 0 ? void 0 : _b.resolve(value.toString('hex'));
457
468
  }
458
469
  }
@@ -473,7 +484,7 @@ class ReactNativeBleTransport {
473
484
  if (transport) {
474
485
  delete transportCache[uuid];
475
486
  (_a = transport.nofitySubscription) === null || _a === void 0 ? void 0 : _a.call(transport);
476
- if (Platform.OS === 'android') ;
487
+ if (reactNative.Platform.OS === 'android') ;
477
488
  }
478
489
  return Promise.resolve(true);
479
490
  });
@@ -481,26 +492,26 @@ class ReactNativeBleTransport {
481
492
  call(uuid, name, data) {
482
493
  return __awaiter(this, void 0, void 0, function* () {
483
494
  if (this.stopped) {
484
- return Promise.reject(ERRORS.TypedError('Transport stopped.'));
495
+ return Promise.reject(hdShared.ERRORS.TypedError('Transport stopped.'));
485
496
  }
486
497
  if (this._messages == null) {
487
- throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
498
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
488
499
  }
489
500
  if (this.runPromise) {
490
- throw ERRORS.TypedError(HardwareErrorCode.TransportCallInProgress);
501
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportCallInProgress);
491
502
  }
492
503
  const transport = transportCache[uuid];
493
504
  if (!transport) {
494
- throw ERRORS.TypedError(HardwareErrorCode.TransportNotFound);
505
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
495
506
  }
496
- this.runPromise = createDeferred();
507
+ this.runPromise = hdShared.createDeferred();
497
508
  const messages = this._messages;
498
509
  this.Log.debug('transport-react-native', 'call-', ' name: ', name, ' data: ', data);
499
510
  const buffers = buildBuffers(messages, name, data);
500
511
  if (name === 'FirmwareUpload') {
501
- const packetCapacity = Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_PACKET_LENGTH;
512
+ const packetCapacity = reactNative.Platform.OS === 'ios' ? IOS_PACKET_LENGTH : ANDROID_PACKET_LENGTH;
502
513
  let index = 0;
503
- let chunk = ByteBuffer.allocate(packetCapacity);
514
+ let chunk = ByteBuffer__default["default"].allocate(packetCapacity);
504
515
  while (index < buffers.length) {
505
516
  const buffer = buffers[index].toBuffer();
506
517
  chunk.append(buffer);
@@ -509,7 +520,7 @@ class ReactNativeBleTransport {
509
520
  chunk.reset();
510
521
  try {
511
522
  yield transport.writeCharacteristic.writeWithoutResponse(chunk.toString('base64'));
512
- chunk = ByteBuffer.allocate(packetCapacity);
523
+ chunk = ByteBuffer__default["default"].allocate(packetCapacity);
513
524
  }
514
525
  catch (e) {
515
526
  this.runPromise = null;
@@ -529,11 +540,11 @@ class ReactNativeBleTransport {
529
540
  catch (e) {
530
541
  this.Log.debug('writeCharacteristic write error: ', e);
531
542
  this.runPromise = null;
532
- if (e.errorCode === BleErrorCode.DeviceDisconnected) {
533
- throw ERRORS.TypedError(HardwareErrorCode.BleDeviceNotBonded);
543
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.DeviceDisconnected) {
544
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded);
534
545
  }
535
- if (e.errorCode === BleErrorCode.OperationStartFailed) {
536
- throw ERRORS.TypedError(HardwareErrorCode.BleWriteCharacteristicError, e.reason);
546
+ if (e.errorCode === reactNativeBlePlx.BleErrorCode.OperationStartFailed) {
547
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleWriteCharacteristicError, e.reason);
537
548
  }
538
549
  return;
539
550
  }
@@ -567,4 +578,4 @@ class ReactNativeBleTransport {
567
578
  }
568
579
  }
569
580
 
570
- export { ReactNativeBleTransport as default };
581
+ module.exports = ReactNativeBleTransport;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-react-native",
3
- "version": "0.1.43",
3
+ "version": "0.1.46",
4
4
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -19,10 +19,10 @@
19
19
  "lint:fix": "eslint . --fix"
20
20
  },
21
21
  "dependencies": {
22
- "@onekeyfe/hd-shared": "^0.1.43",
23
- "@onekeyfe/hd-transport": "^0.1.43",
22
+ "@onekeyfe/hd-shared": "^0.1.46",
23
+ "@onekeyfe/hd-transport": "^0.1.46",
24
24
  "react-native-ble-manager": "^8.1.0",
25
25
  "react-native-ble-plx": "^2.0.3"
26
26
  },
27
- "gitHead": "15d5f1b90ef26478f2183317dd192443e44adbe2"
27
+ "gitHead": "cb71b9b5f2013756b0ba8d4111e233124bf6282e"
28
28
  }
package/src/index.ts CHANGED
@@ -120,6 +120,8 @@ export default class ReactNativeBleTransport {
120
120
  reject(ERRORS.TypedError(HardwareErrorCode.BlePermissionError));
121
121
  } else if (error.errorCode === BleErrorCode.BluetoothUnauthorized) {
122
122
  reject(ERRORS.TypedError(HardwareErrorCode.BleLocationError));
123
+ } else if (error.errorCode === BleErrorCode.LocationServicesDisabled) {
124
+ reject(ERRORS.TypedError(HardwareErrorCode.BleLocationServicesDisabled));
123
125
  } else if (error.errorCode === BleErrorCode.ScanStartFailed) {
124
126
  // Android Bluetooth will report an error when the search frequency is too fast,
125
127
  // then nothing is processed and an empty array of devices is returned.