Skip to main content

Watch devices

@yume-chan/adb-daemon-webusb package also provides a AdbDaemonWebUsbDeviceWatcher class that wraps WebUSB API to monitor device additions and removals.

Similar to AdbDaemonWebUsbDeviceManager, it requires a WebUSB implementation. See that page for how to get one on each supported runtime.

import { AdbDaemonWebUsbDeviceWatcher } from "@yume-chan/adb-daemon-webusb";

function handleDeviceChange(addedDeviceSerial?: string) {
if (addedDeviceSerial) {
// A device with serial `addedDeviceSerial` is added
} else {
// A device is removed
}
}

const watcher = new AdbDaemonWebUsbDeviceWatcher(handleDeviceChange, navigator.usb);

// Stop watching devices
watcher.dispose();

Generally, the handler should reload the device list using AdbDaemonWebUsbDeviceManager#getDevices and update the UI.