DocumentationDevice interactionBeginner's guidesDiscover and connect

Connecting to a Device

There are two steps to connecting to a device:

  • Discovery: dmk.startDiscovering()
    • Returns an observable which will emit a new DiscoveredDevice for every scanned device.
    • The DiscoveredDevice objects contain information about the device model.
    • Use one of these values to connect to a given discovered device.
  • Connection: dmk.connect({ deviceId: device.id })
    • Returns a Promise resolving in a device session identifier DeviceSessionId.
    • Keep this device session identifier to further interact with the device.
    • Then, dmk.getConnectedDevice({ sessionId }) returns the ConnectedDevice, which contains information about the device model and its name.
dmk.startDiscovering().subscribe({
  next: (device) => {
    dmk.connect({ deviceId: device.id }).then((sessionId) => {
      const connectedDevice = dmk.getConnectedDevice({ sessionId });
    });
  },
  error: (error) => {
    console.error(error);
  },
});

Then once a device is connected:

  • Disconnection: dmk.disconnect({ sessionId })
  • Observe the device session state: dmk.getDeviceSessionState({ sessionId })
    • This will return an Observable<DeviceSessionState> to listen to the known information about the device:
      • device status:
        • ready to process a command
        • busy
        • locked
        • disconnected
      • device name
      • information on the OS
      • battery status
      • currently opened app
Ledger
Copyright © Ledger SAS. All rights reserved. Ledger, Ledger Nano S, Ledger Vault, Ledger OS are registered trademarks of Ledger SAS