From 306011077992a7ef59fc649deb263b234493111a Mon Sep 17 00:00:00 2001
From: Francois Beaufort
Date: Tue, 6 Dec 2016 13:43:15 +0100
Subject: [PATCH 1/5] bluetooth: Add acceptAllDevices
---
web-bluetooth/_includes/intro.html | 37 ++++++++++++++-----
.../automatic-reconnect-async-await.js | 10 +----
web-bluetooth/automatic-reconnect.js | 10 +----
web-bluetooth/device-info-async-await.html | 8 ++--
web-bluetooth/device-info-async-await.js | 10 ++++-
web-bluetooth/device-info.html | 8 ++--
web-bluetooth/device-info.js | 10 ++++-
...information-characteristics-async-await.js | 10 +----
.../device-information-characteristics.js | 12 +-----
...ervices-and-characteristics-async-await.js | 10 +----
.../discover-services-and-characteristics.js | 12 +-----
.../gap-characteristics-async-await.js | 10 +----
web-bluetooth/gap-characteristics.js | 12 +-----
...haracteristic-value-changed-async-await.js | 13 +------
.../read-characteristic-value-changed.js | 14 +------
15 files changed, 69 insertions(+), 117 deletions(-)
diff --git a/web-bluetooth/_includes/intro.html b/web-bluetooth/_includes/intro.html
index 05e73fced4..607de983bd 100755
--- a/web-bluetooth/_includes/intro.html
+++ b/web-bluetooth/_includes/intro.html
@@ -19,18 +19,35 @@
inputs.forEach(input => {
if (searchParams.has(input.id)) {
- input.value = searchParams.get(input.id);
- }
- input.addEventListener('input', function(event) {
- const newSearchParams = new URL(location).searchParams;
- if (event.target.value) {
- newSearchParams.set(input.id, event.target.value);
+ if (input.type == 'checkbox') {
+ input.checked = searchParams.get(input.id);
} else {
- newSearchParams.delete(input.id);
+ input.value = searchParams.get(input.id);
}
- history.replaceState({}, '', Array.from(newSearchParams).length ?
- location.pathname + '?' + newSearchParams : location.pathname);
- });
+ }
+ if (input.type == 'checkbox') {
+ input.addEventListener('change', function(event) {
+ const newSearchParams = new URL(location).searchParams;
+ if (event.target.checked) {
+ newSearchParams.set(input.id, event.target.checked);
+ } else {
+ newSearchParams.delete(input.id);
+ }
+ history.replaceState({}, '', Array.from(newSearchParams).length ?
+ location.pathname + '?' + newSearchParams : location.pathname);
+ });
+ } else {
+ input.addEventListener('input', function(event) {
+ const newSearchParams = new URL(location).searchParams;
+ if (event.target.value) {
+ newSearchParams.set(input.id, event.target.value);
+ } else {
+ newSearchParams.delete(input.id);
+ }
+ history.replaceState({}, '', Array.from(newSearchParams).length ?
+ location.pathname + '?' + newSearchParams : location.pathname);
+ });
+ }
});
});
diff --git a/web-bluetooth/automatic-reconnect-async-await.js b/web-bluetooth/automatic-reconnect-async-await.js
index 95733249e5..e3402074de 100644
--- a/web-bluetooth/automatic-reconnect-async-await.js
+++ b/web-bluetooth/automatic-reconnect-async-await.js
@@ -5,7 +5,7 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
bluetoothDevice = await navigator.bluetooth.requestDevice({
- filters: anyNamedDevice()});
+ acceptAllDevices: true});
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
connect();
} catch(error) {
@@ -52,14 +52,6 @@ async function exponentialBackoff(max, delay, toTry, success, fail) {
}
}
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
-
function time(text) {
log('[' + new Date().toJSON().substr(11, 8) + '] ' + text);
}
diff --git a/web-bluetooth/automatic-reconnect.js b/web-bluetooth/automatic-reconnect.js
index 0257660685..9c254815d7 100644
--- a/web-bluetooth/automatic-reconnect.js
+++ b/web-bluetooth/automatic-reconnect.js
@@ -3,7 +3,7 @@ var bluetoothDevice;
function onButtonClick() {
bluetoothDevice = null;
log('Requesting any Bluetooth Device...');
- navigator.bluetooth.requestDevice({filters: anyNamedDevice()})
+ navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device => {
bluetoothDevice = device;
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
@@ -51,14 +51,6 @@ function exponentialBackoff(max, delay, toTry, success, fail) {
});
}
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
-
function time(text) {
log('[' + new Date().toJSON().substr(11, 8) + '] ' + text);
}
diff --git a/web-bluetooth/device-info-async-await.html b/web-bluetooth/device-info-async-await.html
index 429577bfb0..d217b7c4f8 100755
--- a/web-bluetooth/device-info-async-await.html
+++ b/web-bluetooth/device-info-async-await.html
@@ -15,9 +15,11 @@
check out the Device Info (Promises) sample.
diff --git a/web-bluetooth/device-info-async-await.js b/web-bluetooth/device-info-async-await.js
index 295e2b14c0..daedcab3b6 100644
--- a/web-bluetooth/device-info-async-await.js
+++ b/web-bluetooth/device-info-async-await.js
@@ -19,9 +19,17 @@ async function onButtonClick() {
filters.push({namePrefix: filterNamePrefix});
}
+ let options = {
+ acceptAllDevices: document.querySelector('#allDevices').checked
+ };
+ if (filters.length) {
+ options.filters = filters;
+ }
+
try {
log('Requesting Bluetooth Device...');
- const device = await navigator.bluetooth.requestDevice({filters: filters});
+ log('with ' + JSON.stringify(options));
+ const device = await navigator.bluetooth.requestDevice(options);
log('> Name: ' + device.name);
log('> Id: ' + device.id);
diff --git a/web-bluetooth/device-info.html b/web-bluetooth/device-info.html
index 30e6e9f6ba..0b17bb5ba9 100755
--- a/web-bluetooth/device-info.html
+++ b/web-bluetooth/device-info.html
@@ -16,9 +16,11 @@
Await) sample.
diff --git a/web-bluetooth/device-info.js b/web-bluetooth/device-info.js
index 0022657d22..296d8ce0ed 100644
--- a/web-bluetooth/device-info.js
+++ b/web-bluetooth/device-info.js
@@ -19,8 +19,16 @@ function onButtonClick() {
filters.push({namePrefix: filterNamePrefix});
}
+ let options = {
+ acceptAllDevices: document.querySelector('#allDevices').checked
+ };
+ if (filters.length) {
+ options.filters = filters;
+ }
+
log('Requesting Bluetooth Device...');
- navigator.bluetooth.requestDevice({filters: filters})
+ log('with ' + JSON.stringify(options));
+ navigator.bluetooth.requestDevice(options)
.then(device => {
log('> Name: ' + device.name);
log('> Id: ' + device.id);
diff --git a/web-bluetooth/device-information-characteristics-async-await.js b/web-bluetooth/device-information-characteristics-async-await.js
index 2e6d2bd8d2..a28b7de5b4 100644
--- a/web-bluetooth/device-information-characteristics-async-await.js
+++ b/web-bluetooth/device-information-characteristics-async-await.js
@@ -2,7 +2,7 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
- filters: anyNamedDevice(), optionalServices: ['device_information']});
+ acceptAllDevices: true, optionalServices: ['device_information']});
log('Connecting to GATT Server...');
const server = await device.gatt.connect();
@@ -105,11 +105,3 @@ function getUsbVendorName(value) {
return value +
(value in valueToUsbVendorName ? ' (' + valueToUsbVendorName[value] + ')' : '');
}
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
diff --git a/web-bluetooth/device-information-characteristics.js b/web-bluetooth/device-information-characteristics.js
index 82d7b81062..53a7d01fe4 100644
--- a/web-bluetooth/device-information-characteristics.js
+++ b/web-bluetooth/device-information-characteristics.js
@@ -1,7 +1,7 @@
function onButtonClick() {
log('Requesting any Bluetooth Device...');
- navigator.bluetooth.requestDevice(
- {filters: anyNamedDevice(), optionalServices: ['device_information']})
+ navigator.bluetooth.requestDevice({
+ acceptAllDevices: true, optionalServices: ['device_information']})
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
@@ -110,11 +110,3 @@ function getUsbVendorName(value) {
return value +
(value in valueToUsbVendorName ? ' (' + valueToUsbVendorName[value] + ')' : '');
}
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
diff --git a/web-bluetooth/discover-services-and-characteristics-async-await.js b/web-bluetooth/discover-services-and-characteristics-async-await.js
index 4fa5ce1603..f8b517ca18 100644
--- a/web-bluetooth/discover-services-and-characteristics-async-await.js
+++ b/web-bluetooth/discover-services-and-characteristics-async-await.js
@@ -7,7 +7,7 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
- filters: anyNamedDevice(), optionalServices: optionalServices});
+ acceptAllDevices: true, optionalServices: optionalServices});
log('Connecting to GATT Server...');
const server = await device.gatt.connect();
@@ -43,11 +43,3 @@ function getSupportedProperties(characteristic) {
}
return '[' + supportedProperties.join(', ') + ']';
}
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
diff --git a/web-bluetooth/discover-services-and-characteristics.js b/web-bluetooth/discover-services-and-characteristics.js
index abe18af620..717554adc5 100644
--- a/web-bluetooth/discover-services-and-characteristics.js
+++ b/web-bluetooth/discover-services-and-characteristics.js
@@ -5,8 +5,8 @@ function onButtonClick() {
.filter(s => s && BluetoothUUID.getService);
log('Requesting any Bluetooth Device...');
- navigator.bluetooth.requestDevice(
- {filters: anyNamedDevice(), optionalServices: optionalServices})
+ navigator.bluetooth.requestDevice({
+ acceptAllDevices: true, optionalServices: optionalServices})
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
@@ -47,11 +47,3 @@ function getSupportedProperties(characteristic) {
}
return '[' + supportedProperties.join(', ') + ']';
}
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
diff --git a/web-bluetooth/gap-characteristics-async-await.js b/web-bluetooth/gap-characteristics-async-await.js
index 888342b522..016a5639e3 100644
--- a/web-bluetooth/gap-characteristics-async-await.js
+++ b/web-bluetooth/gap-characteristics-async-await.js
@@ -2,7 +2,7 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
- filters: anyNamedDevice(), optionalServices: ['generic_access']});
+ acceptAllDevices: true, optionalServices: ['generic_access']});
log('Connecting to GATT Server...');
const server = await device.gatt.connect();
@@ -97,11 +97,3 @@ function getDeviceType(value) {
return value +
(value in valueToDeviceType ? ' (' + valueToDeviceType[value] + ')' : '');
}
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
diff --git a/web-bluetooth/gap-characteristics.js b/web-bluetooth/gap-characteristics.js
index 8bbef77588..42cf7e2046 100644
--- a/web-bluetooth/gap-characteristics.js
+++ b/web-bluetooth/gap-characteristics.js
@@ -1,7 +1,7 @@
function onButtonClick() {
log('Requesting any Bluetooth Device...');
- navigator.bluetooth.requestDevice(
- {filters: anyNamedDevice(), optionalServices: ['generic_access']})
+ navigator.bluetooth.requestDevice({
+ acceptAllDevices: true, optionalServices: ['generic_access']})
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
@@ -107,11 +107,3 @@ function getDeviceType(value) {
return value +
(value in valueToDeviceType ? ' (' + valueToDeviceType[value] + ')' : '');
}
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
diff --git a/web-bluetooth/read-characteristic-value-changed-async-await.js b/web-bluetooth/read-characteristic-value-changed-async-await.js
index 88d7c40a67..7fc4e6075e 100644
--- a/web-bluetooth/read-characteristic-value-changed-async-await.js
+++ b/web-bluetooth/read-characteristic-value-changed-async-await.js
@@ -18,7 +18,7 @@ async function onReadBatteryLevelButtonClick() {
async function requestDevice() {
log('Requesting Bluetooth Device...');
bluetoothDevice = await navigator.bluetooth.requestDevice({
- filters: anyNamedDevice(), optionalServices: ['battery_service']});
+ acceptAllDevices: true, optionalServices: ['battery_service']});
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
}
@@ -95,14 +95,3 @@ async function onDisconnected() {
log('Argh! ' + error);
}
}
-
-
-/* Utils */
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
diff --git a/web-bluetooth/read-characteristic-value-changed.js b/web-bluetooth/read-characteristic-value-changed.js
index 2a121fc9b1..6f41df87b2 100644
--- a/web-bluetooth/read-characteristic-value-changed.js
+++ b/web-bluetooth/read-characteristic-value-changed.js
@@ -15,8 +15,8 @@ function onReadBatteryLevelButtonClick() {
function requestDevice() {
log('Requesting Bluetooth Device...');
- return navigator.bluetooth.requestDevice(
- {filters: anyNamedDevice(), optionalServices: ['battery_service']})
+ return navigator.bluetooth.requestDevice({
+ acceptAllDevices: true, optionalServices: ['battery_service']})
.then(device => {
bluetoothDevice = device;
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
@@ -99,13 +99,3 @@ function onDisconnected() {
log('Argh! ' + error);
});
}
-
-/* Utils */
-
-function anyNamedDevice() {
- // This is the closest we can get for now to get all devices.
- // https://github.com/WebBluetoothCG/web-bluetooth/issues/234
- return Array.from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
- .map(c => ({namePrefix: c}))
- .concat({name: ''});
-}
From 4ebbcd100891bb6984bc044647d36ddc914bba9b Mon Sep 17 00:00:00 2001
From: Francois Beaufort
Date: Wed, 7 Dec 2016 09:39:33 +0100
Subject: [PATCH 2/5] Don't use both acceptAllDevices and filters
---
web-bluetooth/device-info-async-await.js | 8 ++++----
web-bluetooth/device-info.js | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/web-bluetooth/device-info-async-await.js b/web-bluetooth/device-info-async-await.js
index daedcab3b6..1068e7403e 100644
--- a/web-bluetooth/device-info-async-await.js
+++ b/web-bluetooth/device-info-async-await.js
@@ -19,10 +19,10 @@ async function onButtonClick() {
filters.push({namePrefix: filterNamePrefix});
}
- let options = {
- acceptAllDevices: document.querySelector('#allDevices').checked
- };
- if (filters.length) {
+ let options = {};
+ if (document.querySelector('#allDevices').checked) {
+ options.acceptAllDevices = true;
+ } else {
options.filters = filters;
}
diff --git a/web-bluetooth/device-info.js b/web-bluetooth/device-info.js
index 296d8ce0ed..cab49de127 100644
--- a/web-bluetooth/device-info.js
+++ b/web-bluetooth/device-info.js
@@ -19,10 +19,10 @@ function onButtonClick() {
filters.push({namePrefix: filterNamePrefix});
}
- let options = {
- acceptAllDevices: document.querySelector('#allDevices').checked
- };
- if (filters.length) {
+ let options = {};
+ if (document.querySelector('#allDevices').checked) {
+ options.acceptAllDevices = true;
+ } else {
options.filters = filters;
}
From 5f0a821b2248564ca8b195adb1e8553a43658cf4 Mon Sep 17 00:00:00 2001
From: Francois Beaufort
Date: Wed, 7 Dec 2016 09:56:29 +0100
Subject: [PATCH 3/5] Add warning about acceptAllDevices
---
web-bluetooth/automatic-reconnect-async-await.js | 1 +
web-bluetooth/automatic-reconnect.js | 4 +++-
.../device-information-characteristics-async-await.js | 4 +++-
web-bluetooth/device-information-characteristics.js | 4 +++-
.../discover-services-and-characteristics-async-await.js | 4 +++-
web-bluetooth/discover-services-and-characteristics.js | 4 +++-
web-bluetooth/gap-characteristics-async-await.js | 4 +++-
web-bluetooth/gap-characteristics.js | 4 +++-
.../read-characteristic-value-changed-async-await.js | 6 ++++--
web-bluetooth/read-characteristic-value-changed.js | 6 ++++--
10 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/web-bluetooth/automatic-reconnect-async-await.js b/web-bluetooth/automatic-reconnect-async-await.js
index e3402074de..93ee13f755 100644
--- a/web-bluetooth/automatic-reconnect-async-await.js
+++ b/web-bluetooth/automatic-reconnect-async-await.js
@@ -5,6 +5,7 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
bluetoothDevice = await navigator.bluetooth.requestDevice({
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
acceptAllDevices: true});
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
connect();
diff --git a/web-bluetooth/automatic-reconnect.js b/web-bluetooth/automatic-reconnect.js
index 9c254815d7..84cc28f9be 100644
--- a/web-bluetooth/automatic-reconnect.js
+++ b/web-bluetooth/automatic-reconnect.js
@@ -3,7 +3,9 @@ var bluetoothDevice;
function onButtonClick() {
bluetoothDevice = null;
log('Requesting any Bluetooth Device...');
- navigator.bluetooth.requestDevice({acceptAllDevices: true})
+ navigator.bluetooth.requestDevice({
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true})
.then(device => {
bluetoothDevice = device;
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
diff --git a/web-bluetooth/device-information-characteristics-async-await.js b/web-bluetooth/device-information-characteristics-async-await.js
index a28b7de5b4..20e86b4dd2 100644
--- a/web-bluetooth/device-information-characteristics-async-await.js
+++ b/web-bluetooth/device-information-characteristics-async-await.js
@@ -2,7 +2,9 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: ['device_information']});
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['device_information']});
log('Connecting to GATT Server...');
const server = await device.gatt.connect();
diff --git a/web-bluetooth/device-information-characteristics.js b/web-bluetooth/device-information-characteristics.js
index 53a7d01fe4..f53f9c698d 100644
--- a/web-bluetooth/device-information-characteristics.js
+++ b/web-bluetooth/device-information-characteristics.js
@@ -1,7 +1,9 @@
function onButtonClick() {
log('Requesting any Bluetooth Device...');
navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: ['device_information']})
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['device_information']})
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
diff --git a/web-bluetooth/discover-services-and-characteristics-async-await.js b/web-bluetooth/discover-services-and-characteristics-async-await.js
index f8b517ca18..6bc006a334 100644
--- a/web-bluetooth/discover-services-and-characteristics-async-await.js
+++ b/web-bluetooth/discover-services-and-characteristics-async-await.js
@@ -7,7 +7,9 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: optionalServices});
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: optionalServices});
log('Connecting to GATT Server...');
const server = await device.gatt.connect();
diff --git a/web-bluetooth/discover-services-and-characteristics.js b/web-bluetooth/discover-services-and-characteristics.js
index 717554adc5..df8e35a2ec 100644
--- a/web-bluetooth/discover-services-and-characteristics.js
+++ b/web-bluetooth/discover-services-and-characteristics.js
@@ -6,7 +6,9 @@ function onButtonClick() {
log('Requesting any Bluetooth Device...');
navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: optionalServices})
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: optionalServices})
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
diff --git a/web-bluetooth/gap-characteristics-async-await.js b/web-bluetooth/gap-characteristics-async-await.js
index 016a5639e3..fb5b7d5dce 100644
--- a/web-bluetooth/gap-characteristics-async-await.js
+++ b/web-bluetooth/gap-characteristics-async-await.js
@@ -2,7 +2,9 @@ async function onButtonClick() {
try {
log('Requesting any Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: ['generic_access']});
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['generic_access']});
log('Connecting to GATT Server...');
const server = await device.gatt.connect();
diff --git a/web-bluetooth/gap-characteristics.js b/web-bluetooth/gap-characteristics.js
index 42cf7e2046..ab717320c9 100644
--- a/web-bluetooth/gap-characteristics.js
+++ b/web-bluetooth/gap-characteristics.js
@@ -1,7 +1,9 @@
function onButtonClick() {
log('Requesting any Bluetooth Device...');
navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: ['generic_access']})
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['generic_access']})
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
diff --git a/web-bluetooth/read-characteristic-value-changed-async-await.js b/web-bluetooth/read-characteristic-value-changed-async-await.js
index 7fc4e6075e..9d5c60f7c3 100644
--- a/web-bluetooth/read-characteristic-value-changed-async-await.js
+++ b/web-bluetooth/read-characteristic-value-changed-async-await.js
@@ -16,9 +16,11 @@ async function onReadBatteryLevelButtonClick() {
}
async function requestDevice() {
- log('Requesting Bluetooth Device...');
+ log('Requesting any Bluetooth Device...');
bluetoothDevice = await navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: ['battery_service']});
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['battery_service']});
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
}
diff --git a/web-bluetooth/read-characteristic-value-changed.js b/web-bluetooth/read-characteristic-value-changed.js
index 6f41df87b2..7c8660c069 100644
--- a/web-bluetooth/read-characteristic-value-changed.js
+++ b/web-bluetooth/read-characteristic-value-changed.js
@@ -14,9 +14,11 @@ function onReadBatteryLevelButtonClick() {
}
function requestDevice() {
- log('Requesting Bluetooth Device...');
+ log('Requesting any Bluetooth Device...');
return navigator.bluetooth.requestDevice({
- acceptAllDevices: true, optionalServices: ['battery_service']})
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['battery_service']})
.then(device => {
bluetoothDevice = device;
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
From aaf85cb1763ffb6ec10a0d891b02ecc949423da7 Mon Sep 17 00:00:00 2001
From: Francois Beaufort
Date: Thu, 22 Dec 2016 10:20:51 +0100
Subject: [PATCH 4/5] Converted missing link-loss sample
---
web-bluetooth/link-loss-async-await.js | 4 +++-
web-bluetooth/link-loss.js | 5 ++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/web-bluetooth/link-loss-async-await.js b/web-bluetooth/link-loss-async-await.js
index 1621186726..e5b98906fb 100644
--- a/web-bluetooth/link-loss-async-await.js
+++ b/web-bluetooth/link-loss-async-await.js
@@ -4,7 +4,9 @@ async function onReadButtonClick() {
try {
log('Requesting Bluetooth Device...');
const device = await navigator.bluetooth.requestDevice({
- filters: [{services: ['link_loss']}]});
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['link_loss']});
log('Connecting to GATT Server...');
const server = await device.gatt.connect();
diff --git a/web-bluetooth/link-loss.js b/web-bluetooth/link-loss.js
index c1bd009e5e..7b7d0540f9 100644
--- a/web-bluetooth/link-loss.js
+++ b/web-bluetooth/link-loss.js
@@ -2,7 +2,10 @@ var alertLevelCharacteristic;
function onReadButtonClick() {
log('Requesting Bluetooth Device...');
- navigator.bluetooth.requestDevice({filters: [{services: ['link_loss']}]})
+ navigator.bluetooth.requestDevice({
+ // filters: [...] <- Prefer filters to save energy & show relevant devices.
+ acceptAllDevices: true,
+ optionalServices: ['link_loss']})
.then(device => {
log('Connecting to GATT Server...');
return device.gatt.connect();
From d4ba4db4cd6f3a81dca1c9be074bf44ac982457f Mon Sep 17 00:00:00 2001
From: Francois Beaufort
Date: Thu, 2 Feb 2017 10:05:56 +0100
Subject: [PATCH 5/5] Remove autofocus for prefilled fields
---
web-bluetooth/_includes/intro.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/web-bluetooth/_includes/intro.html b/web-bluetooth/_includes/intro.html
index 607de983bd..071a44401a 100755
--- a/web-bluetooth/_includes/intro.html
+++ b/web-bluetooth/_includes/intro.html
@@ -23,6 +23,7 @@
input.checked = searchParams.get(input.id);
} else {
input.value = searchParams.get(input.id);
+ input.blur();
}
}
if (input.type == 'checkbox') {