@onekeyfe/hd-transport-web-device 1.2.11-alpha.20 → 1.2.11-alpha.21
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,5 +1,10 @@
|
|
|
1
1
|
import transport, { PROTOCOL_V2_CHANNEL_BLE_UART, bytesToHex } from '@onekeyfe/hd-transport';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
EBleDisconnectReason,
|
|
4
|
+
ERRORS,
|
|
5
|
+
HardwareErrorCode,
|
|
6
|
+
createDeferred,
|
|
7
|
+
} from '@onekeyfe/hd-shared';
|
|
3
8
|
import EventEmitter from 'events';
|
|
4
9
|
|
|
5
10
|
import ElectronBleTransport from '../src/electron-ble-transport';
|
|
@@ -1492,4 +1497,356 @@ describe('ElectronBleTransport protocol detection', () => {
|
|
|
1492
1497
|
expect(nobleBle.connect).not.toHaveBeenCalled();
|
|
1493
1498
|
expect(nobleBle.disconnect).not.toHaveBeenCalled();
|
|
1494
1499
|
});
|
|
1500
|
+
|
|
1501
|
+
test('wakes a sleeping legacy V1 Classic with Initialize after silent GetFeatures without probing V2', async () => {
|
|
1502
|
+
const device = { id: 'sleeping-classic-id', name: 'K8141' };
|
|
1503
|
+
const nobleBle = createNobleBle(device);
|
|
1504
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1505
|
+
const probes = bleTransport as any;
|
|
1506
|
+
const probeProtocolV1 = jest.spyOn(probes, 'probeProtocolV1').mockResolvedValue(false);
|
|
1507
|
+
const probeProtocolV2 = jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
|
|
1508
|
+
const callProtocolV1 = jest.spyOn(probes, 'callProtocolV1').mockResolvedValue({
|
|
1509
|
+
type: 'Features',
|
|
1510
|
+
message: {},
|
|
1511
|
+
});
|
|
1512
|
+
|
|
1513
|
+
await expect(bleTransport.acquire({ uuid: device.id })).resolves.toMatchObject({
|
|
1514
|
+
uuid: device.id,
|
|
1515
|
+
protocolType: 'V1',
|
|
1516
|
+
});
|
|
1517
|
+
|
|
1518
|
+
expect(probeProtocolV1).toHaveBeenCalledTimes(1);
|
|
1519
|
+
expect(callProtocolV1).toHaveBeenCalledTimes(1);
|
|
1520
|
+
expect(callProtocolV1.mock.calls[0]?.[1]).toBe('Initialize');
|
|
1521
|
+
expect(probeProtocolV2).not.toHaveBeenCalled();
|
|
1522
|
+
});
|
|
1523
|
+
|
|
1524
|
+
test('skips Initialize wake on Electron BLE when onlyConnectBleDevice is true', async () => {
|
|
1525
|
+
const device = { id: 'only-connect-classic-id', name: 'K1361' };
|
|
1526
|
+
const nobleBle = createNobleBle(device);
|
|
1527
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1528
|
+
const probes = bleTransport as any;
|
|
1529
|
+
jest.spyOn(probes, 'probeProtocolV1').mockResolvedValue(false);
|
|
1530
|
+
jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
|
|
1531
|
+
const callProtocolV1 = jest.spyOn(probes, 'callProtocolV1').mockResolvedValue({
|
|
1532
|
+
type: 'Features',
|
|
1533
|
+
message: {},
|
|
1534
|
+
});
|
|
1535
|
+
|
|
1536
|
+
await expect(
|
|
1537
|
+
bleTransport.acquire({ uuid: device.id, onlyConnectBleDevice: true })
|
|
1538
|
+
).rejects.toBeDefined();
|
|
1539
|
+
expect(callProtocolV1).not.toHaveBeenCalled();
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
test('propagates Windows pairing rejection from GetFeatures without consuming the wake for later reconnects', async () => {
|
|
1543
|
+
const device = { id: 'win-pairing-classic-id', name: 'K8141' };
|
|
1544
|
+
const nobleBle = createNobleBle(device);
|
|
1545
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1546
|
+
const probes = bleTransport as any;
|
|
1547
|
+
const probeProtocolV2 = jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
|
|
1548
|
+
|
|
1549
|
+
// Attempt 1: host aborts GetFeatures write after Windows pairing rejection.
|
|
1550
|
+
nobleBle.write.mockRejectedValueOnce(
|
|
1551
|
+
ERRORS.TypedError(
|
|
1552
|
+
HardwareErrorCode.BleConnectedError,
|
|
1553
|
+
'Write failed with abortable error for device win-pairing-classic-id: status: 3'
|
|
1554
|
+
)
|
|
1555
|
+
);
|
|
1556
|
+
await expect(bleTransport.acquire({ uuid: device.id })).rejects.toMatchObject({
|
|
1557
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
1558
|
+
});
|
|
1559
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
1560
|
+
expect(probeProtocolV2).not.toHaveBeenCalled();
|
|
1561
|
+
|
|
1562
|
+
// Attempt 2: paired successfully, GetFeatures still silent (device asleep), so the
|
|
1563
|
+
// preserved wake sends a one-shot Initialize and confirms V1.
|
|
1564
|
+
nobleBle.write.mockClear();
|
|
1565
|
+
jest.spyOn(probes, 'probeProtocolV1').mockResolvedValueOnce(false);
|
|
1566
|
+
const callProtocolV1 = jest.spyOn(probes, 'callProtocolV1').mockResolvedValueOnce({
|
|
1567
|
+
type: 'Features',
|
|
1568
|
+
message: {},
|
|
1569
|
+
});
|
|
1570
|
+
|
|
1571
|
+
await expect(bleTransport.acquire({ uuid: device.id })).resolves.toMatchObject({
|
|
1572
|
+
uuid: device.id,
|
|
1573
|
+
protocolType: 'V1',
|
|
1574
|
+
});
|
|
1575
|
+
expect(callProtocolV1).toHaveBeenCalledWith(
|
|
1576
|
+
device.id,
|
|
1577
|
+
'Initialize',
|
|
1578
|
+
{},
|
|
1579
|
+
{ timeoutMs: 3000 },
|
|
1580
|
+
{ oneShot: true },
|
|
1581
|
+
true
|
|
1582
|
+
);
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
test('sends Initialize wake as a single one-shot native write and preserves wake when host proves write never started', async () => {
|
|
1586
|
+
const device = { id: 'oneshot-classic-id', name: 'K1361' };
|
|
1587
|
+
const nobleBle = createNobleBle(device);
|
|
1588
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1589
|
+
const probes = bleTransport as any;
|
|
1590
|
+
jest.spyOn(probes, 'probeProtocolV1').mockResolvedValue(false);
|
|
1591
|
+
jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
|
|
1592
|
+
|
|
1593
|
+
// Attempt 1: host rejects Initialize before submitting a GATT write.
|
|
1594
|
+
nobleBle.write.mockRejectedValueOnce(
|
|
1595
|
+
ERRORS.TypedError(
|
|
1596
|
+
HardwareErrorCode.BleCharacteristicNotFound,
|
|
1597
|
+
'Device oneshot-classic-id not connected or characteristics not available'
|
|
1598
|
+
)
|
|
1599
|
+
);
|
|
1600
|
+
await expect(bleTransport.acquire({ uuid: device.id })).rejects.toMatchObject({
|
|
1601
|
+
errorCode: HardwareErrorCode.BleCharacteristicNotFound,
|
|
1602
|
+
});
|
|
1603
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
1604
|
+
expect(nobleBle.write.mock.calls[0]?.[2]).toEqual({ oneShot: true });
|
|
1605
|
+
|
|
1606
|
+
// Attempt 2: wake is still armed and executes one native write with { oneShot: true }.
|
|
1607
|
+
nobleBle.write.mockClear();
|
|
1608
|
+
let notifyHandler: ((id: string, hex: string) => void) | undefined;
|
|
1609
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
1610
|
+
notifyHandler = handler;
|
|
1611
|
+
return jest.fn();
|
|
1612
|
+
});
|
|
1613
|
+
nobleBle.write.mockImplementationOnce((id: string) => {
|
|
1614
|
+
const reply = ProtocolV1.encodeTransportPackets(schemas.protocolV1, 'Success', {
|
|
1615
|
+
message: 'ok',
|
|
1616
|
+
});
|
|
1617
|
+
const packetHex = reply[0].toString('hex');
|
|
1618
|
+
const payloadLen = parseInt(packetHex.slice(10, 18), 16);
|
|
1619
|
+
notifyHandler?.(id, packetHex.slice(0, (9 + payloadLen) * 2));
|
|
1620
|
+
return Promise.resolve();
|
|
1621
|
+
});
|
|
1622
|
+
|
|
1623
|
+
await expect(bleTransport.acquire({ uuid: device.id })).resolves.toMatchObject({
|
|
1624
|
+
uuid: device.id,
|
|
1625
|
+
protocolType: 'V1',
|
|
1626
|
+
});
|
|
1627
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
1628
|
+
expect(nobleBle.write.mock.calls[0]?.[2]).toEqual({ oneShot: true });
|
|
1629
|
+
});
|
|
1630
|
+
|
|
1631
|
+
test('sends initial V1 GetFeatures probe with oneShot and rethrows TransportCallInProgress without waking', async () => {
|
|
1632
|
+
const device = { id: 'oneshot-getfeatures-id', name: 'K8141' };
|
|
1633
|
+
const nobleBle = createNobleBle(device);
|
|
1634
|
+
let notifyHandler: ((id: string, hex: string) => void) | undefined;
|
|
1635
|
+
nobleBle.onNotification.mockImplementation(handler => {
|
|
1636
|
+
notifyHandler = handler;
|
|
1637
|
+
return jest.fn();
|
|
1638
|
+
});
|
|
1639
|
+
nobleBle.write.mockImplementationOnce((id: string) => {
|
|
1640
|
+
const reply = ProtocolV1.encodeTransportPackets(schemas.protocolV1, 'Success', {
|
|
1641
|
+
message: 'ok',
|
|
1642
|
+
});
|
|
1643
|
+
const packetHex = reply[0].toString('hex');
|
|
1644
|
+
const payloadLen = parseInt(packetHex.slice(10, 18), 16);
|
|
1645
|
+
notifyHandler?.(id, packetHex.slice(0, (9 + payloadLen) * 2));
|
|
1646
|
+
return Promise.resolve();
|
|
1647
|
+
});
|
|
1648
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1649
|
+
|
|
1650
|
+
await expect(bleTransport.acquire({ uuid: device.id })).resolves.toMatchObject({
|
|
1651
|
+
uuid: device.id,
|
|
1652
|
+
protocolType: 'V1',
|
|
1653
|
+
});
|
|
1654
|
+
expect(nobleBle.write).toHaveBeenCalledTimes(1);
|
|
1655
|
+
expect(nobleBle.write.mock.calls[0]?.[2]).toEqual({ oneShot: true });
|
|
1656
|
+
|
|
1657
|
+
await bleTransport.release(device.id);
|
|
1658
|
+
|
|
1659
|
+
const probes = bleTransport as any;
|
|
1660
|
+
const inProgressErr = ERRORS.TypedError(HardwareErrorCode.TransportCallInProgress);
|
|
1661
|
+
const callSpy = jest.spyOn(probes, 'callProtocolV1').mockRejectedValueOnce(inProgressErr);
|
|
1662
|
+
const wakeSpy = jest.spyOn(probes, 'wakeSilentProtocolV1Device');
|
|
1663
|
+
|
|
1664
|
+
await expect(bleTransport.acquire({ uuid: device.id })).rejects.toMatchObject({
|
|
1665
|
+
errorCode: HardwareErrorCode.TransportCallInProgress,
|
|
1666
|
+
});
|
|
1667
|
+
expect(callSpy).toHaveBeenCalledTimes(1);
|
|
1668
|
+
expect(wakeSpy).not.toHaveBeenCalled();
|
|
1669
|
+
});
|
|
1670
|
+
|
|
1671
|
+
test('skips Electron Initialize wake if abortSignal aborts during probe state reset', async () => {
|
|
1672
|
+
const device = { id: 'abort-reset-classic-id', name: 'K8141' };
|
|
1673
|
+
const nobleBle = createNobleBle(device);
|
|
1674
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1675
|
+
const probes = bleTransport as any;
|
|
1676
|
+
const abortController = new AbortController();
|
|
1677
|
+
jest.spyOn(probes, 'probeProtocolV1').mockResolvedValue(false);
|
|
1678
|
+
jest.spyOn(probes, 'resetProbeStateAfterProtocolProbe').mockImplementation(() => {
|
|
1679
|
+
abortController.abort();
|
|
1680
|
+
return Promise.resolve();
|
|
1681
|
+
});
|
|
1682
|
+
const callProtocolV1 = jest.spyOn(probes, 'callProtocolV1');
|
|
1683
|
+
|
|
1684
|
+
await expect(
|
|
1685
|
+
bleTransport.acquire({ uuid: device.id, abortSignal: abortController.signal })
|
|
1686
|
+
).rejects.toMatchObject({
|
|
1687
|
+
errorCode: HardwareErrorCode.DeviceInterruptedFromUser,
|
|
1688
|
+
});
|
|
1689
|
+
expect(callProtocolV1).not.toHaveBeenCalled();
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
test('does not send Initialize wake when GetFeatures fails from an ordinary GATT write error', async () => {
|
|
1693
|
+
const device = { id: 'gatt-write-err-classic-id', name: 'K8141' };
|
|
1694
|
+
const nobleBle = createNobleBle(device);
|
|
1695
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1696
|
+
const probes = bleTransport as any;
|
|
1697
|
+
const wakeSpy = jest.spyOn(probes, 'wakeSilentProtocolV1Device');
|
|
1698
|
+
jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
|
|
1699
|
+
nobleBle.write.mockRejectedValueOnce(new Error('GATT write error'));
|
|
1700
|
+
|
|
1701
|
+
await expect(bleTransport.acquire({ uuid: device.id })).rejects.toMatchObject({
|
|
1702
|
+
errorCode: HardwareErrorCode.TransportProtocolProbeFailed,
|
|
1703
|
+
});
|
|
1704
|
+
expect(wakeSpy).not.toHaveBeenCalled();
|
|
1705
|
+
});
|
|
1706
|
+
|
|
1707
|
+
test('prevents a canceled acquire whose getDevice settles late from disconnecting a replacement acquire', async () => {
|
|
1708
|
+
const device = { id: 'superseded-acquire-id', name: 'K8141' };
|
|
1709
|
+
const nobleBle = createNobleBle(device);
|
|
1710
|
+
let resolveFirstGetDevice: ((d: typeof device) => void) | undefined;
|
|
1711
|
+
nobleBle.getDevice
|
|
1712
|
+
.mockImplementationOnce(
|
|
1713
|
+
() =>
|
|
1714
|
+
new Promise(resolve => {
|
|
1715
|
+
resolveFirstGetDevice = resolve;
|
|
1716
|
+
})
|
|
1717
|
+
)
|
|
1718
|
+
.mockResolvedValue(device);
|
|
1719
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1720
|
+
const abortA = new AbortController();
|
|
1721
|
+
|
|
1722
|
+
const acquireA = bleTransport.acquire({
|
|
1723
|
+
uuid: device.id,
|
|
1724
|
+
expectedProtocol: 'V1',
|
|
1725
|
+
abortSignal: abortA.signal,
|
|
1726
|
+
});
|
|
1727
|
+
abortA.abort();
|
|
1728
|
+
|
|
1729
|
+
// Acquire B succeeds while acquire A is still waiting on getDevice.
|
|
1730
|
+
await expect(
|
|
1731
|
+
bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V1' })
|
|
1732
|
+
).resolves.toMatchObject({ uuid: device.id, protocolType: 'V1' });
|
|
1733
|
+
nobleBle.disconnect.mockClear();
|
|
1734
|
+
nobleBle.unsubscribe.mockClear();
|
|
1735
|
+
|
|
1736
|
+
// Acquire A resumes when its delayed lookup settles; it must not tear down B's link.
|
|
1737
|
+
resolveFirstGetDevice?.(device);
|
|
1738
|
+
await expect(acquireA).rejects.toMatchObject({
|
|
1739
|
+
errorCode: HardwareErrorCode.DeviceInterruptedFromUser,
|
|
1740
|
+
});
|
|
1741
|
+
expect(nobleBle.unsubscribe).not.toHaveBeenCalled();
|
|
1742
|
+
expect(nobleBle.disconnect).not.toHaveBeenCalled();
|
|
1743
|
+
expect(bleTransport.getProtocolType(device.id)).toBe('V1');
|
|
1744
|
+
});
|
|
1745
|
+
|
|
1746
|
+
test('restores wake eligibility when Windows rejects the Initialize wake write with writeRejected', async () => {
|
|
1747
|
+
const device = { id: 'win-wake-reject-id', name: 'K8141' };
|
|
1748
|
+
const nobleBle = createNobleBle(device);
|
|
1749
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1750
|
+
const probes = bleTransport as any;
|
|
1751
|
+
jest.spyOn(probes, 'probeProtocolV1').mockResolvedValue(false);
|
|
1752
|
+
jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
|
|
1753
|
+
|
|
1754
|
+
nobleBle.write.mockRejectedValueOnce(
|
|
1755
|
+
ERRORS.TypedError(
|
|
1756
|
+
HardwareErrorCode.BleConnectedError,
|
|
1757
|
+
'Write failed with abortable error for device win-wake-reject-id: status: 3',
|
|
1758
|
+
{ writeRejected: true }
|
|
1759
|
+
)
|
|
1760
|
+
);
|
|
1761
|
+
await expect(bleTransport.acquire({ uuid: device.id })).rejects.toMatchObject({
|
|
1762
|
+
errorCode: HardwareErrorCode.BleConnectedError,
|
|
1763
|
+
});
|
|
1764
|
+
|
|
1765
|
+
// After pairing succeeds on the next acquire, Initialize wake must still run.
|
|
1766
|
+
const callProtocolV1 = jest.spyOn(probes, 'callProtocolV1').mockResolvedValueOnce({
|
|
1767
|
+
type: 'Features',
|
|
1768
|
+
message: {},
|
|
1769
|
+
});
|
|
1770
|
+
await expect(bleTransport.acquire({ uuid: device.id })).resolves.toMatchObject({
|
|
1771
|
+
uuid: device.id,
|
|
1772
|
+
protocolType: 'V1',
|
|
1773
|
+
});
|
|
1774
|
+
expect(callProtocolV1).toHaveBeenCalledTimes(1);
|
|
1775
|
+
expect(callProtocolV1.mock.calls[0]?.[1]).toBe('Initialize');
|
|
1776
|
+
});
|
|
1777
|
+
|
|
1778
|
+
test('disconnects an ordinary 3000ms Initialize call on timeout instead of treating it as a probe', async () => {
|
|
1779
|
+
const device = { id: 'ordinary-init-3s-id', name: 'OneKey Classic' };
|
|
1780
|
+
const nobleBle = createNobleBle(device);
|
|
1781
|
+
nobleBle.onNotification.mockImplementation(() => jest.fn());
|
|
1782
|
+
nobleBle.write.mockImplementation(() => Promise.resolve());
|
|
1783
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1784
|
+
|
|
1785
|
+
await bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V1' });
|
|
1786
|
+
jest.useFakeTimers({ doNotFake: ['performance'] });
|
|
1787
|
+
try {
|
|
1788
|
+
const pending = bleTransport.call(device.id, 'Initialize', {}, { timeoutMs: 3000 });
|
|
1789
|
+
const expectation = expect(pending).rejects.toMatchObject({
|
|
1790
|
+
errorCode: HardwareErrorCode.BleTimeoutError,
|
|
1791
|
+
});
|
|
1792
|
+
await Promise.resolve();
|
|
1793
|
+
await Promise.resolve();
|
|
1794
|
+
jest.advanceTimersByTime(3000);
|
|
1795
|
+
await expectation;
|
|
1796
|
+
} finally {
|
|
1797
|
+
jest.useRealTimers();
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
expect(nobleBle.disconnect).toHaveBeenCalledWith(device.id);
|
|
1801
|
+
expect(bleTransport.getProtocolType(device.id)).toBeUndefined();
|
|
1802
|
+
});
|
|
1803
|
+
|
|
1804
|
+
test('uses the post-connect device name for Electron legacy V1 wake when initial lookup has a placeholder name', async () => {
|
|
1805
|
+
const placeholder = { id: 'cold-classic-id', name: 'OneKey Device' };
|
|
1806
|
+
const connected = { id: 'cold-classic-id', name: 'K8141', mtu: 247 };
|
|
1807
|
+
const nobleBle = createNobleBle(placeholder);
|
|
1808
|
+
nobleBle.getDevice.mockResolvedValueOnce(placeholder).mockResolvedValueOnce(connected);
|
|
1809
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1810
|
+
const probes = bleTransport as any;
|
|
1811
|
+
jest.spyOn(probes, 'probeProtocolV1').mockResolvedValue(false);
|
|
1812
|
+
const probeProtocolV2 = jest.spyOn(probes, 'probeProtocolV2').mockResolvedValue(false);
|
|
1813
|
+
const callProtocolV1 = jest.spyOn(probes, 'callProtocolV1').mockResolvedValue({
|
|
1814
|
+
type: 'Features',
|
|
1815
|
+
message: {},
|
|
1816
|
+
});
|
|
1817
|
+
|
|
1818
|
+
await expect(bleTransport.acquire({ uuid: placeholder.id })).resolves.toMatchObject({
|
|
1819
|
+
uuid: placeholder.id,
|
|
1820
|
+
name: 'K8141',
|
|
1821
|
+
protocolType: 'V1',
|
|
1822
|
+
});
|
|
1823
|
+
expect(callProtocolV1).toHaveBeenCalledTimes(1);
|
|
1824
|
+
expect(callProtocolV1.mock.calls[0]?.[1]).toBe('Initialize');
|
|
1825
|
+
expect(probeProtocolV2).not.toHaveBeenCalled();
|
|
1826
|
+
});
|
|
1827
|
+
|
|
1828
|
+
test('rejects an already-aborted acquire without releasing an existing Electron BLE link', async () => {
|
|
1829
|
+
const device = { id: 'existing-link-id', name: 'OneKey Classic' };
|
|
1830
|
+
const nobleBle = createNobleBle(device);
|
|
1831
|
+
const bleTransport = configureTransport(nobleBle);
|
|
1832
|
+
await bleTransport.acquire({ uuid: device.id, expectedProtocol: 'V1' });
|
|
1833
|
+
|
|
1834
|
+
const aborted = new AbortController();
|
|
1835
|
+
aborted.abort();
|
|
1836
|
+
const releaseSpy = jest.spyOn(bleTransport, 'release');
|
|
1837
|
+
nobleBle.disconnect.mockClear();
|
|
1838
|
+
|
|
1839
|
+
await expect(
|
|
1840
|
+
bleTransport.acquire({
|
|
1841
|
+
uuid: device.id,
|
|
1842
|
+
expectedProtocol: 'V1',
|
|
1843
|
+
abortSignal: aborted.signal,
|
|
1844
|
+
})
|
|
1845
|
+
).rejects.toMatchObject({
|
|
1846
|
+
errorCode: HardwareErrorCode.DeviceInterruptedFromUser,
|
|
1847
|
+
});
|
|
1848
|
+
expect(releaseSpy).not.toHaveBeenCalled();
|
|
1849
|
+
expect(nobleBle.disconnect).not.toHaveBeenCalled();
|
|
1850
|
+
expect(bleTransport.getProtocolType(device.id)).toBe('V1');
|
|
1851
|
+
});
|
|
1495
1852
|
});
|
|
@@ -13,6 +13,8 @@ export type BleAcquireInput = {
|
|
|
13
13
|
forceCleanRunPromise?: boolean;
|
|
14
14
|
expectedProtocol?: ProtocolType;
|
|
15
15
|
protocolHint?: ProtocolType;
|
|
16
|
+
onlyConnectBleDevice?: boolean;
|
|
17
|
+
abortSignal?: AbortSignal;
|
|
16
18
|
};
|
|
17
19
|
export default class ElectronBleTransport {
|
|
18
20
|
private _messages;
|
|
@@ -32,6 +34,11 @@ export default class ElectronBleTransport {
|
|
|
32
34
|
private stopPromise?;
|
|
33
35
|
private deviceProtocol;
|
|
34
36
|
private deviceProtocolHints;
|
|
37
|
+
private silentDetections;
|
|
38
|
+
private probeResponseTimeoutErrors;
|
|
39
|
+
private lastV1ProbeFailedWithoutTimeout;
|
|
40
|
+
private acquireGenerations;
|
|
41
|
+
private nextAcquireGeneration;
|
|
35
42
|
private deviceMtus;
|
|
36
43
|
private devicePacketCapacities;
|
|
37
44
|
private v1Buffers;
|
|
@@ -77,6 +84,7 @@ export default class ElectronBleTransport {
|
|
|
77
84
|
private createProtocolDetectionError;
|
|
78
85
|
private clearProbeProtocol;
|
|
79
86
|
private detectProtocol;
|
|
87
|
+
private wakeSilentProtocolV1Device;
|
|
80
88
|
private createNotificationSubscription;
|
|
81
89
|
private resetProbeStateAfterProtocolProbe;
|
|
82
90
|
private probeProtocolV1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"electron-ble-transport.d.ts","sourceRoot":"","sources":["../src/electron-ble-transport.ts"],"names":[],"mappings":";AA0BA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EACV,UAAU,EAGX,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAEV,gBAAgB,EAChB,YAAY,EAEZ,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,YAAY,MAAM,QAAQ,CAAC;AAIvC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,UAAU,CAAC;KACzB;CACF;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,CAAC;AAuFF,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC,OAAO,CAAC,SAAS,CAAmE;IAEpF,OAAO,CAAC,WAAW,CAAmE;IAEtF,OAAO,CAAC,6BAA6B,CAAqB;IAE1D,IAAI,SAA0B;IAE9B,UAAU,UAAS;IAEnB,UAAU,EAAE,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,IAAI,CAAQ;IAExD,OAAO,CAAC,kBAAkB,CAAuB;IAEjD,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC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AAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -237,6 +237,8 @@ type BleAcquireInput = {
|
|
|
237
237
|
forceCleanRunPromise?: boolean;
|
|
238
238
|
expectedProtocol?: ProtocolType;
|
|
239
239
|
protocolHint?: ProtocolType;
|
|
240
|
+
onlyConnectBleDevice?: boolean;
|
|
241
|
+
abortSignal?: AbortSignal;
|
|
240
242
|
};
|
|
241
243
|
/**
|
|
242
244
|
* Desktop Electron BLE transport with automatic Protocol V1/V2 detection.
|
|
@@ -269,6 +271,11 @@ declare class ElectronBleTransport {
|
|
|
269
271
|
private stopPromise?;
|
|
270
272
|
private deviceProtocol;
|
|
271
273
|
private deviceProtocolHints;
|
|
274
|
+
private silentDetections;
|
|
275
|
+
private probeResponseTimeoutErrors;
|
|
276
|
+
private lastV1ProbeFailedWithoutTimeout;
|
|
277
|
+
private acquireGenerations;
|
|
278
|
+
private nextAcquireGeneration;
|
|
272
279
|
private deviceMtus;
|
|
273
280
|
private devicePacketCapacities;
|
|
274
281
|
private v1Buffers;
|
|
@@ -328,6 +335,7 @@ declare class ElectronBleTransport {
|
|
|
328
335
|
private createProtocolDetectionError;
|
|
329
336
|
private clearProbeProtocol;
|
|
330
337
|
private detectProtocol;
|
|
338
|
+
private wakeSilentProtocolV1Device;
|
|
331
339
|
private createNotificationSubscription;
|
|
332
340
|
private resetProbeStateAfterProtocolProbe;
|
|
333
341
|
private probeProtocolV1;
|