mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Refactoring the WebBluetooth html tests.
This commit is contained in:
parent
9c0e7b1cf2
commit
5d3556a99d
23 changed files with 1112 additions and 119 deletions
50
tests/html/bluetooth/bluetooth_primary_service_info.html
Normal file
50
tests/html/bluetooth/bluetooth_primary_service_info.html
Normal file
|
@ -0,0 +1,50 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<title>Primary 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});
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(options);
|
||||
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
log('Getting Primary Service...');
|
||||
var primaryService = server.getPrimaryService(filterService);
|
||||
|
||||
log('Primary Service found on device: ' + primaryService.device.name);
|
||||
log('> UUID: ' + primaryService.uuid);
|
||||
log('> Is primary: ' + primaryService.isPrimary);
|
||||
} catch(err) {
|
||||
log(err);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue