Skip to content

Commit a780e90

Browse files
committed
Undo accidentially undoing the fix
1 parent f4d5470 commit a780e90

1 file changed

Lines changed: 33 additions & 12 deletions

File tree

www/ec/code.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,39 @@ Code.connect = function(run) {
513513
Code.server = undefined;
514514
Code.service = undefined;
515515

516-
navigator.bluetooth.requestDevice( {
517-
filters: [
518-
{ services: ['0000ffe0-0000-1000-8000-00805f9b34fb' ] },
519-
{ services: ['7b130100-ce8d-45bb-9158-631b769139e9'] },
520-
{ name: 'BT Control Receiver'},
521-
{ name: 'BT Smart Controller'} ],
522-
optionalServices: [
523-
'7b130100-ce8d-45bb-9158-631b769139e9', // ft robby
524-
'0000ffe0-0000-1000-8000-00805f9b34fb', // hm-10
525-
'8ae883b4-ad7d-11e6-80f5-76304dec7eb7', // BT Smart Controller
526-
'2e58327e-c5c5-11e6-9d9d-cec0c932ce01' ] // BT Control Receiver
527-
} ).then(device => {
516+
// this will not find the fischertechnik controllers by name
517+
// see https://stackoverflow.com/questions/72903299/howto-filter-for-uuid-or-name-in-web-bluetooth
518+
let requestParms = { filters: [
519+
{ services: ['0000ffe0-0000-1000-8000-00805f9b34fb' ] },
520+
{ services: ['7b130100-ce8d-45bb-9158-631b769139e9'] },
521+
{ name: 'BT Control Receiver'},
522+
{ name: 'BT Smart Controller'}
523+
] };
524+
525+
if (navigator.userAgentData) {
526+
let vendors = window.navigator.userAgentData.brands;
527+
528+
// let vstr = "";
529+
// for(let i=0;i<vendors.length;i++)
530+
// vstr += String(vendors[i].brand) + ", "
531+
// alert(vstr);
532+
533+
// chromium but neither chrome nor edge -> workaround for name detection
534+
if ((vendors.filter(e => e.brand === 'Chromium').length > 0) &&
535+
(vendors.filter(e => e.brand === 'Google Chrome').length == 0) &&
536+
(vendors.filter(e => e.brand === 'Microsoft Edge').length == 0) ) {
537+
requestParms = { acceptAllDevices: true };
538+
}
539+
}
540+
541+
navigator.bluetooth.requestDevice(
542+
Object.assign({}, requestParms, {
543+
optionalServices: [
544+
'7b130100-ce8d-45bb-9158-631b769139e9', // ft robby
545+
'0000ffe0-0000-1000-8000-00805f9b34fb', // hm-10
546+
'8ae883b4-ad7d-11e6-80f5-76304dec7eb7', // BT Smart Controller
547+
'2e58327e-c5c5-11e6-9d9d-cec0c932ce01' ] // BT Control Receiver
548+
})).then(device => {
528549
console.log("Device",device, "found. Connecting ...");
529550
Code.device = device;
530551
device.addEventListener('gattserverdisconnected', Code.onDisconnected);

0 commit comments

Comments
 (0)