mirror of
https://github.com/servo/servo
synced 2026-04-28 10:27:40 +02:00
59 lines
2.0 KiB
HTML
59 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<title>Included Service info</title>
|
|
<body>
|
|
<input id="service" type="text" autofocus placeholder="Bluetooth Service">
|
|
<input id="name" type="text" placeholder="Device Name">
|
|
<input id="namePrefix" type="text" placeholder="Device Name Prefix">
|
|
<button type="button" onclick="onButtonClick()">Get Primary Service Info</button>
|
|
<pre id="log"></pre>
|
|
<script src="bluetooth_functions.js"></script>
|
|
<script>
|
|
function onButtonClick() {
|
|
clear();
|
|
var options = {filters: [], optionalServices: []};
|
|
|
|
var filterService = document.getElementById('service').value;
|
|
if (filterService) {
|
|
if (filterService.startsWith('0x'))
|
|
filterService = parseInt(filterService, 16);
|
|
options.filters.push({services: [filterService]});
|
|
}
|
|
|
|
var filterName = document.getElementById('name').value;
|
|
if (filterName)
|
|
options.filters.push({name: filterName});
|
|
|
|
var filterNamePrefix = document.getElementById('namePrefix').value;
|
|
if (filterNamePrefix)
|
|
options.filters.push({namePrefix: filterNamePrefix});
|
|
|
|
log('Requesting Bluetooth Device...');
|
|
window.navigator.bluetooth.requestDevice(options)
|
|
.then(device => {
|
|
log('Connecting to GATTserver on device...');
|
|
return device.gatt.connect();
|
|
})
|
|
.then(server => {
|
|
log('Getting Primary Service...');
|
|
return server.getPrimaryService(filterService);
|
|
})
|
|
.then(service => {
|
|
log('Primary Service found on device: ' + service.device.name);
|
|
log('> UUID: ' + service.uuid);
|
|
|
|
log('Getting Included Services...');
|
|
return service.getIncludedServices();
|
|
})
|
|
.then(includedServices => {
|
|
log('> Included Services: ' +
|
|
includedServices.map(s => s.uuid).join('\n' + ' '.repeat(21)));
|
|
})
|
|
.catch(err => {
|
|
log(err);
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|