Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
open: (id: string): ?Promise<*> => {
if (id.startsWith("webble")) {
const existingDevice = webbleDevices[id];
return existingDevice
? TransportWebBLE.open(existingDevice)
: TransportWebBLE.create();
}
return null;
},
disconnect: id =>
id.startsWith("webble")
? Promise.resolve() // nothing to do
: null,
discovery: Observable.create(TransportWebUSB.listen).pipe(
map(bleDevice => {
const id = "webble|" + bleDevice.id;
webbleDevices[id] = bleDevice;
return {
type: "add",
id,
name: bleDevice.name
};
})
)
});
// provide a basic mecanism to stop polling when you leave the tab
// & immediately poll when you come back.
const addExtraPollingHooks = (schedulePoll, cancelPoll) => {
function onWindowBlur() {
open: (id: string): ?Promise<*> => {
if (id.startsWith("webusb")) {
const existingDevice = webusbDevices[id];
return existingDevice
? TransportWebUSB.open(existingDevice)
: TransportWebUSB.create();
}
return null;
},
disconnect: id =>
id.startsWith("webusb")
? Promise.resolve() // nothing to do
: null,
discovery: Observable.create(TransportWebUSB.listen).pipe(
map(usbDevice => {
const id = "webusb|" + usbDevice.vendorId + "_" + usbDevice.productId;
webusbDevices[id] = usbDevice;
return {
type: "add",
id,
name: usbDevice.productName
};
})
)
});
const webbleDevices = {};
registerTransportModule({
id: "webble",