Skip to content

Commit 06169b4

Browse files
committed
Try to adopt to chromium bug
1 parent 81297a5 commit 06169b4

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

www/ec/code.js

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

516-
navigator.bluetooth.requestDevice( {
517-
// // this will not find the fischertechnik controllers by name
518-
// // see https://stackoverflow.com/questions/72903299/howto-filter-for-uuid-or-name-in-web-bluetooth
519-
// filters: [
520-
// { services: ['0000ffe0-0000-1000-8000-00805f9b34fb' ] },
521-
// { services: ['7b130100-ce8d-45bb-9158-631b769139e9'] },
522-
// { name: 'BT Control Receiver'},
523-
// { name: 'BT Smart Controller'}
524-
// ],
525-
acceptAllDevices: true,
526-
optionalServices: [
527-
'7b130100-ce8d-45bb-9158-631b769139e9', // ft robby
528-
'0000ffe0-0000-1000-8000-00805f9b34fb', // hm-10
529-
'8ae883b4-ad7d-11e6-80f5-76304dec7eb7', // BT Smart Controller
530-
'2e58327e-c5c5-11e6-9d9d-cec0c932ce01' ] // BT Control Receiver
531-
}).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+
538+
requestParms = { acceptAllDevices: true };
539+
}
540+
}
541+
542+
navigator.bluetooth.requestDevice(
543+
Object.assign({}, requestParms, {
544+
optionalServices: [
545+
'7b130100-ce8d-45bb-9158-631b769139e9', // ft robby
546+
'0000ffe0-0000-1000-8000-00805f9b34fb', // hm-10
547+
'8ae883b4-ad7d-11e6-80f5-76304dec7eb7', // BT Smart Controller
548+
'2e58327e-c5c5-11e6-9d9d-cec0c932ce01' ] // BT Control Receiver
549+
})).then(device => {
532550
console.log("Device",device, "found. Connecting ...");
533551
Code.device = device;
534552
device.addEventListener('gattserverdisconnected', Code.onDisconnected);

0 commit comments

Comments
 (0)