javascript web_bluetooth.js
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript web_bluetooth.js相关的知识,希望对你有一定的参考价值。
onButtonClick() {
// Validate services UUID entered by user first.
/*
let optionalServices = document.querySelector('#optionalServices').value
.split(/, ?/).map(s => s.startsWith('0x') ? parseInt(s) : s)
.filter(s => s && BluetoothUUID.getService);
*/
let optionalServices=['000018f0-0000-1000-8000-00805f9b34fb'];
console.log('Requesting any Bluetooth Device...');
navigator.bluetooth.requestDevice({
// filters: [...] <- Prefer filters to save energy & show relevant devices.
acceptAllDevices: true,
optionalServices: optionalServices})
.then(device => {
console.log('Connecting to GATT Server...');
return device.gatt.connect();
})
.then(server => {
// Note that we could also get all services that match a specific UUID by
// passing it to getPrimaryServices().
console.log('Getting Services...');
return server.getPrimaryServices();
})
.then(services => {
console.log('Getting Characteristics...');
let queue = Promise.resolve();
services.forEach(service => {
queue = queue.then(_ => service.getCharacteristics().then(characteristics => {
console.log('> Service: ' + service.uuid);
characteristics.forEach(characteristic => {
console.log('>> Characteristic: ' + characteristic.uuid + ' ' +
getSupportedProperties(characteristic));
});
}));
});
return queue;
})
.catch(error => {
console.log('Argh! ' + error);
});
}
以上是关于javascript web_bluetooth.js的主要内容,如果未能解决你的问题,请参考以下文章
javascript的题。
javascript JavaScript isset()等效: - JavaScript
JavaScript 使用JavaScript更改CSS(JavaScript)
JavaScript之基础-1 JavaScript(概述基础语法)
前端基础-JavaScript的基本概述和语法
JavaScript