Connecting to a Device
There are two steps to connecting to a device:
- Discovery:
sdk.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.
- Returns an observable which will emit a new
- Connection:
sdk.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,
sdk.getConnectedDevice({ sessionId })
returns theConnectedDevice
, which contains information about the device model and its name.
- Returns a Promise resolving in a device session identifier
sdk.startDiscovering().subscribe({
next: (device) => {
sdk.connect({ deviceId: device.id }).then((sessionId) => {
const connectedDevice = sdk.getConnectedDevice({ sessionId });
});
},
error: (error) => {
console.error(error);
},
});
Then once a device is connected:
- Disconnection:
sdk.disconnect({ sessionId })
- Observe the device session state:
sdk.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
- device status:
- This will return an