mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Update WebBluetooth to use Promises
This commit is contained in:
parent
fb52bb7c8d
commit
e05a839d25
32 changed files with 684 additions and 458 deletions
|
@ -15,10 +15,13 @@ use dom::bindings::str::DOMString;
|
|||
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
||||
use dom::bluetoothdevice::BluetoothDevice;
|
||||
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
|
||||
use dom::promise::Promise;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use js::conversions::ToJSValConvertible;
|
||||
use net_traits::bluetooth_scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence};
|
||||
use net_traits::bluetooth_scanfilter::{RequestDeviceoptions, ServiceUUIDSequence};
|
||||
use net_traits::bluetooth_thread::{BluetoothError, BluetoothMethodMsg};
|
||||
use std::rc::Rc;
|
||||
|
||||
const FILTER_EMPTY_ERROR: &'static str = "'filters' member, if present, must be nonempty to find any devices.";
|
||||
const FILTER_ERROR: &'static str = "A filter must restrict the devices in some way.";
|
||||
|
@ -61,6 +64,22 @@ impl Bluetooth {
|
|||
global_ref.as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
fn request_device(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> {
|
||||
// Step 1.
|
||||
// TODO(#4282): Reject promise.
|
||||
if (option.filters.is_some() && option.acceptAllDevices) ||
|
||||
(option.filters.is_none() && !option.acceptAllDevices) {
|
||||
return Err(Type(OPTIONS_ERROR.to_owned()));
|
||||
}
|
||||
// Step 2.
|
||||
if !option.acceptAllDevices {
|
||||
return self.request_bluetooth_devices(&option.filters, &option.optionalServices);
|
||||
}
|
||||
|
||||
self.request_bluetooth_devices(&None, &option.optionalServices)
|
||||
// TODO(#4282): Step 3-5: Reject and resolve promise.
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices
|
||||
fn request_bluetooth_devices(&self,
|
||||
filters: &Option<Vec<BluetoothRequestDeviceFilter>>,
|
||||
|
@ -252,6 +271,18 @@ fn canonicalize_filter(filter: &BluetoothRequestDeviceFilter, global: GlobalRef)
|
|||
service_data_uuid))
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn result_to_promise<T: ToJSValConvertible>(global_ref: GlobalRef,
|
||||
bluetooth_result: Fallible<T>)
|
||||
-> Rc<Promise> {
|
||||
let p = Promise::new(global_ref);
|
||||
match bluetooth_result {
|
||||
Ok(v) => p.resolve_native(p.global().r().get_cx(), &v),
|
||||
Err(e) => p.reject_error(p.global().r().get_cx(), e),
|
||||
}
|
||||
p
|
||||
}
|
||||
|
||||
impl From<BluetoothError> for Error {
|
||||
fn from(error: BluetoothError) -> Self {
|
||||
match error {
|
||||
|
@ -265,20 +296,9 @@ impl From<BluetoothError> for Error {
|
|||
}
|
||||
|
||||
impl BluetoothMethods for Bluetooth {
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
|
||||
fn RequestDevice(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> {
|
||||
// Step 1.
|
||||
// TODO(#4282): Reject promise.
|
||||
if (option.filters.is_some() && option.acceptAllDevices) ||
|
||||
(option.filters.is_none() && !option.acceptAllDevices) {
|
||||
return Err(Type(OPTIONS_ERROR.to_owned()));
|
||||
}
|
||||
// Step 2.
|
||||
if !option.acceptAllDevices {
|
||||
return self.request_bluetooth_devices(&option.filters, &option.optionalServices);
|
||||
}
|
||||
|
||||
self.request_bluetooth_devices(&None, &option.optionalServices)
|
||||
// TODO(#4282): Step 3-5: Reject and resolve promise.
|
||||
fn RequestDevice(&self, option: &RequestDeviceOptions) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.request_device(option))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,15 @@ use dom::bindings::global::GlobalRef;
|
|||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::str::{ByteString, DOMString};
|
||||
use dom::bluetooth::result_to_promise;
|
||||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
||||
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
||||
use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID};
|
||||
use dom::promise::Promise;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
use std::rc::Rc;
|
||||
|
||||
// Maximum length of an attribute value.
|
||||
// https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=286439 (Vol. 3, page 2169)
|
||||
|
@ -79,26 +82,9 @@ impl BluetoothRemoteGATTCharacteristic {
|
|||
fn get_instance_id(&self) -> String {
|
||||
self.instance_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteristic {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-properties
|
||||
fn Properties(&self) -> Root<BluetoothCharacteristicProperties> {
|
||||
self.properties.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-service
|
||||
fn Service(&self) -> Root<BluetoothRemoteGATTService> {
|
||||
self.service.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-uuid
|
||||
fn Uuid(&self) -> DOMString {
|
||||
self.uuid.clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor
|
||||
fn GetDescriptor(&self, descriptor: BluetoothDescriptorUUID) -> Fallible<Root<BluetoothRemoteGATTDescriptor>> {
|
||||
fn get_descriptor(&self, descriptor: BluetoothDescriptorUUID) -> Fallible<Root<BluetoothRemoteGATTDescriptor>> {
|
||||
let uuid = try!(BluetoothUUID::GetDescriptor(self.global().r(), descriptor)).to_string();
|
||||
if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
|
||||
return Err(Security)
|
||||
|
@ -121,9 +107,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptors
|
||||
fn GetDescriptors(&self,
|
||||
descriptor: Option<BluetoothDescriptorUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTDescriptor>>> {
|
||||
fn get_descriptors(&self,
|
||||
descriptor: Option<BluetoothDescriptorUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTDescriptor>>> {
|
||||
let mut uuid: Option<String> = None;
|
||||
if let Some(d) = descriptor {
|
||||
uuid = Some(try!(BluetoothUUID::GetDescriptor(self.global().r(), d)).to_string());
|
||||
|
@ -152,13 +138,8 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-value
|
||||
fn GetValue(&self) -> Option<ByteString> {
|
||||
self.value.borrow().clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue
|
||||
fn ReadValue(&self) -> Fallible<ByteString> {
|
||||
fn read_value(&self) -> Fallible<ByteString> {
|
||||
if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Reads) {
|
||||
return Err(Security)
|
||||
}
|
||||
|
@ -185,7 +166,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) -> ErrorResult {
|
||||
fn write_value(&self, value: Vec<u8>) -> ErrorResult {
|
||||
if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Writes) {
|
||||
return Err(Security)
|
||||
}
|
||||
|
@ -213,3 +194,51 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteristic {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-properties
|
||||
fn Properties(&self) -> Root<BluetoothCharacteristicProperties> {
|
||||
self.properties.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-service
|
||||
fn Service(&self) -> Root<BluetoothRemoteGATTService> {
|
||||
self.service.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-uuid
|
||||
fn Uuid(&self) -> DOMString {
|
||||
self.uuid.clone()
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor
|
||||
fn GetDescriptor(&self, descriptor: BluetoothDescriptorUUID) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_descriptor(descriptor))
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptors
|
||||
fn GetDescriptors(&self,
|
||||
descriptor: Option<BluetoothDescriptorUUID>)
|
||||
-> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_descriptors(descriptor))
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-value
|
||||
fn GetValue(&self) -> Option<ByteString> {
|
||||
self.value.borrow().clone()
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue
|
||||
fn ReadValue(&self) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.read_value())
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.write_value(value))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,12 @@ use dom::bindings::global::GlobalRef;
|
|||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::str::{ByteString, DOMString};
|
||||
use dom::bluetooth::result_to_promise;
|
||||
use dom::bluetoothremotegattcharacteristic::{BluetoothRemoteGATTCharacteristic, MAXIMUM_ATTRIBUTE_LENGTH};
|
||||
use dom::promise::Promise;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
use std::rc::Rc;
|
||||
|
||||
// http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor
|
||||
#[dom_struct]
|
||||
|
@ -66,26 +69,9 @@ impl BluetoothRemoteGATTDescriptor {
|
|||
fn get_instance_id(&self) -> String {
|
||||
self.instance_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-characteristic
|
||||
fn Characteristic(&self) -> Root<BluetoothRemoteGATTCharacteristic> {
|
||||
self.characteristic.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-uuid
|
||||
fn Uuid(&self) -> DOMString {
|
||||
self.uuid.clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-value
|
||||
fn GetValue(&self) -> Option<ByteString> {
|
||||
self.value.borrow().clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
|
||||
fn ReadValue(&self) -> Fallible<ByteString> {
|
||||
fn read_value(&self) -> Fallible<ByteString> {
|
||||
if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Reads) {
|
||||
return Err(Security)
|
||||
}
|
||||
|
@ -109,7 +95,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) -> ErrorResult {
|
||||
fn write_value(&self, value: Vec<u8>) -> ErrorResult {
|
||||
if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Writes) {
|
||||
return Err(Security)
|
||||
}
|
||||
|
@ -131,3 +117,32 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-characteristic
|
||||
fn Characteristic(&self) -> Root<BluetoothRemoteGATTCharacteristic> {
|
||||
self.characteristic.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-uuid
|
||||
fn Uuid(&self) -> DOMString {
|
||||
self.uuid.clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-value
|
||||
fn GetValue(&self) -> Option<ByteString> {
|
||||
self.value.borrow().clone()
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
|
||||
fn ReadValue(&self) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.read_value())
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.write_value(value))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,12 +12,15 @@ use dom::bindings::global::GlobalRef;
|
|||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::bluetooth::result_to_promise;
|
||||
use dom::bluetoothdevice::BluetoothDevice;
|
||||
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
||||
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
|
||||
use dom::promise::Promise;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver
|
||||
#[dom_struct]
|
||||
|
@ -47,21 +50,9 @@ impl BluetoothRemoteGATTServer {
|
|||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-device
|
||||
fn Device(&self) -> Root<BluetoothDevice> {
|
||||
self.device.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connected
|
||||
fn Connected(&self) -> bool {
|
||||
self.connected.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
|
||||
fn Connect(&self) -> Fallible<Root<BluetoothRemoteGATTServer>> {
|
||||
fn connect(&self) -> Fallible<Root<BluetoothRemoteGATTServer>> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GATTServerConnect(String::from(self.Device().Id()), sender)).unwrap();
|
||||
|
@ -77,25 +68,8 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect
|
||||
fn Disconnect(&self) -> ErrorResult {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GATTServerDisconnect(String::from(self.Device().Id()), sender)).unwrap();
|
||||
let server = receiver.recv().unwrap();
|
||||
match server {
|
||||
Ok(connected) => {
|
||||
self.connected.set(connected);
|
||||
Ok(())
|
||||
},
|
||||
Err(error) => {
|
||||
Err(Error::from(error))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
|
||||
fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Fallible<Root<BluetoothRemoteGATTService>> {
|
||||
fn get_primary_service(&self, service: BluetoothServiceUUID) -> Fallible<Root<BluetoothRemoteGATTService>> {
|
||||
let uuid = try!(BluetoothUUID::GetService(self.global().r(), service)).to_string();
|
||||
if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
|
||||
return Err(Security)
|
||||
|
@ -119,9 +93,9 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
|
||||
fn GetPrimaryServices(&self,
|
||||
service: Option<BluetoothServiceUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
|
||||
fn get_primary_services(&self,
|
||||
service: Option<BluetoothServiceUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
|
||||
let mut uuid: Option<String> = None;
|
||||
if let Some(s) = service {
|
||||
uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string());
|
||||
|
@ -151,3 +125,52 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-device
|
||||
fn Device(&self) -> Root<BluetoothDevice> {
|
||||
self.device.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connected
|
||||
fn Connected(&self) -> bool {
|
||||
self.connected.get()
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
|
||||
fn Connect(&self) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.connect())
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect
|
||||
fn Disconnect(&self) -> ErrorResult {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GATTServerDisconnect(String::from(self.Device().Id()), sender)).unwrap();
|
||||
let server = receiver.recv().unwrap();
|
||||
match server {
|
||||
Ok(connected) => {
|
||||
self.connected.set(connected);
|
||||
Ok(())
|
||||
},
|
||||
Err(error) => {
|
||||
Err(Error::from(error))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
|
||||
fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_primary_service(service))
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
|
||||
fn GetPrimaryServices(&self,
|
||||
service: Option<BluetoothServiceUUID>)
|
||||
-> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_primary_services(service))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,15 @@ use dom::bindings::global::GlobalRef;
|
|||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::bluetooth::result_to_promise;
|
||||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||
use dom::bluetoothdevice::BluetoothDevice;
|
||||
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
||||
use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, BluetoothUUID};
|
||||
use dom::promise::Promise;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
use std::rc::Rc;
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
|
||||
#[dom_struct]
|
||||
|
@ -66,28 +69,11 @@ impl BluetoothRemoteGATTService {
|
|||
fn get_instance_id(&self) -> String {
|
||||
self.instance_id.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-device
|
||||
fn Device(&self) -> Root<BluetoothDevice> {
|
||||
self.device.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-isprimary
|
||||
fn IsPrimary(&self) -> bool {
|
||||
self.is_primary
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-uuid
|
||||
fn Uuid(&self) -> DOMString {
|
||||
self.uuid.clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic
|
||||
fn GetCharacteristic(&self,
|
||||
characteristic: BluetoothCharacteristicUUID)
|
||||
-> Fallible<Root<BluetoothRemoteGATTCharacteristic>> {
|
||||
fn get_characteristic(&self,
|
||||
characteristic: BluetoothCharacteristicUUID)
|
||||
-> Fallible<Root<BluetoothRemoteGATTCharacteristic>> {
|
||||
let uuid = try!(BluetoothUUID::GetCharacteristic(self.global().r(), characteristic)).to_string();
|
||||
if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
|
||||
return Err(Security)
|
||||
|
@ -121,9 +107,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristics
|
||||
fn GetCharacteristics(&self,
|
||||
characteristic: Option<BluetoothCharacteristicUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTCharacteristic>>> {
|
||||
fn get_characteristics(&self,
|
||||
characteristic: Option<BluetoothCharacteristicUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTCharacteristic>>> {
|
||||
let mut uuid: Option<String> = None;
|
||||
if let Some(c) = characteristic {
|
||||
uuid = Some(try!(BluetoothUUID::GetCharacteristic(self.global().r(), c)).to_string());
|
||||
|
@ -166,9 +152,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservice
|
||||
fn GetIncludedService(&self,
|
||||
service: BluetoothServiceUUID)
|
||||
-> Fallible<Root<BluetoothRemoteGATTService>> {
|
||||
fn get_included_service(&self,
|
||||
service: BluetoothServiceUUID)
|
||||
-> Fallible<Root<BluetoothRemoteGATTService>> {
|
||||
let uuid = try!(BluetoothUUID::GetService(self.global().r(), service)).to_string();
|
||||
if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) {
|
||||
return Err(Security)
|
||||
|
@ -194,9 +180,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservices
|
||||
fn GetIncludedServices(&self,
|
||||
service: Option<BluetoothServiceUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
|
||||
fn get_included_services(&self,
|
||||
service: Option<BluetoothServiceUUID>)
|
||||
-> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
|
||||
let mut uuid: Option<String> = None;
|
||||
if let Some(s) = service {
|
||||
uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string());
|
||||
|
@ -228,3 +214,52 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-device
|
||||
fn Device(&self) -> Root<BluetoothDevice> {
|
||||
self.device.get()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-isprimary
|
||||
fn IsPrimary(&self) -> bool {
|
||||
self.is_primary
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-uuid
|
||||
fn Uuid(&self) -> DOMString {
|
||||
self.uuid.clone()
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic
|
||||
fn GetCharacteristic(&self,
|
||||
characteristic: BluetoothCharacteristicUUID)
|
||||
-> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_characteristic(characteristic))
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristics
|
||||
fn GetCharacteristics(&self,
|
||||
characteristic: Option<BluetoothCharacteristicUUID>)
|
||||
-> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_characteristics(characteristic))
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservice
|
||||
fn GetIncludedService(&self,
|
||||
service: BluetoothServiceUUID)
|
||||
-> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_included_service(service))
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservices
|
||||
fn GetIncludedServices(&self,
|
||||
service: Option<BluetoothServiceUUID>)
|
||||
-> Rc<Promise> {
|
||||
result_to_promise(self.global().r(), self.get_included_services(service))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,7 @@ interface Bluetooth {
|
|||
// [SecureContext]
|
||||
// readonly attribute BluetoothDevice? referringDevice;
|
||||
// [SecureContext]
|
||||
// Promise<BluetoothDevice> requestDevice(RequestDeviceOptions options);
|
||||
[Throws]
|
||||
BluetoothDevice requestDevice(optional RequestDeviceOptions options);
|
||||
Promise<BluetoothDevice> requestDevice(optional RequestDeviceOptions options);
|
||||
};
|
||||
|
||||
// Bluetooth implements EventTarget;
|
||||
|
|
|
@ -10,18 +10,12 @@ interface BluetoothRemoteGATTCharacteristic {
|
|||
readonly attribute DOMString uuid;
|
||||
readonly attribute BluetoothCharacteristicProperties properties;
|
||||
readonly attribute ByteString? value;
|
||||
[Throws]
|
||||
BluetoothRemoteGATTDescriptor getDescriptor(BluetoothDescriptorUUID descriptor);
|
||||
[Throws]
|
||||
sequence<BluetoothRemoteGATTDescriptor> getDescriptors(optional BluetoothDescriptorUUID descriptor);
|
||||
//Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor);
|
||||
//Promise<sequence<BluetoothRemoteGATTDescriptor>>
|
||||
//getDescriptors(optional BluetoothDescriptorUUID descriptor);
|
||||
[Throws]
|
||||
ByteString readValue();
|
||||
Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor);
|
||||
Promise<sequence<BluetoothRemoteGATTDescriptor>>
|
||||
getDescriptors(optional BluetoothDescriptorUUID descriptor);
|
||||
Promise<ByteString> readValue();
|
||||
//Promise<DataView> readValue();
|
||||
[Throws]
|
||||
void writeValue(sequence<octet> value);
|
||||
Promise<void> writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
//Promise<void> startNotifications();
|
||||
//Promise<void> stopNotifications();
|
||||
|
|
|
@ -9,10 +9,8 @@ interface BluetoothRemoteGATTDescriptor {
|
|||
readonly attribute BluetoothRemoteGATTCharacteristic characteristic;
|
||||
readonly attribute DOMString uuid;
|
||||
readonly attribute ByteString? value;
|
||||
[Throws]
|
||||
ByteString readValue();
|
||||
Promise<ByteString> readValue();
|
||||
//Promise<DataView> readValue();
|
||||
[Throws]
|
||||
void writeValue(sequence<octet> value);
|
||||
Promise<void> writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
};
|
||||
|
|
|
@ -8,15 +8,9 @@
|
|||
interface BluetoothRemoteGATTServer {
|
||||
readonly attribute BluetoothDevice device;
|
||||
readonly attribute boolean connected;
|
||||
[Throws]
|
||||
BluetoothRemoteGATTServer connect();
|
||||
Promise<BluetoothRemoteGATTServer> connect();
|
||||
[Throws]
|
||||
void disconnect();
|
||||
[Throws]
|
||||
BluetoothRemoteGATTService getPrimaryService(BluetoothServiceUUID service);
|
||||
[Throws]
|
||||
sequence<BluetoothRemoteGATTService> getPrimaryServices(optional BluetoothServiceUUID service);
|
||||
//Promise<BluetoothRemoteGATTService> getPrimaryService(BluetoothServiceUUID service);
|
||||
//Promise<sequence<BluetoothRemoteGATTService>>getPrimaryServices(optional BluetoothServiceUUID service);
|
||||
//Promise<BluetoothRemoteGATTServer> connect();
|
||||
Promise<BluetoothRemoteGATTService> getPrimaryService(BluetoothServiceUUID service);
|
||||
Promise<sequence<BluetoothRemoteGATTService>> getPrimaryServices(optional BluetoothServiceUUID service);
|
||||
};
|
||||
|
|
|
@ -9,18 +9,9 @@ interface BluetoothRemoteGATTService {
|
|||
readonly attribute BluetoothDevice device;
|
||||
readonly attribute DOMString uuid;
|
||||
readonly attribute boolean isPrimary;
|
||||
[Throws]
|
||||
BluetoothRemoteGATTCharacteristic getCharacteristic(BluetoothCharacteristicUUID characteristic);
|
||||
[Throws]
|
||||
sequence<BluetoothRemoteGATTCharacteristic> getCharacteristics
|
||||
(optional BluetoothCharacteristicUUID characteristic);
|
||||
//Promise<BluetoothRemoteGATTCharacteristic>getCharacteristic(BluetoothCharacteristicUUID characteristic);
|
||||
//Promise<sequence<BluetoothRemoteGATTCharacteristic>>
|
||||
//getCharacteristics(optional BluetoothCharacteristicUUID characteristic);
|
||||
[Throws]
|
||||
BluetoothRemoteGATTService getIncludedService(BluetoothServiceUUID service);
|
||||
[Throws]
|
||||
sequence<BluetoothRemoteGATTService> getIncludedServices(optional BluetoothServiceUUID service);
|
||||
//Promise<BluetoothRemoteGATTService>getIncludedService(BluetoothServiceUUID service);
|
||||
//Promise<sequence<BluetoothRemoteGATTService>>getIncludedServices(optional BluetoothServiceUUID service);
|
||||
Promise<BluetoothRemoteGATTCharacteristic> getCharacteristic(BluetoothCharacteristicUUID characteristic);
|
||||
Promise<sequence<BluetoothRemoteGATTCharacteristic>>
|
||||
getCharacteristics(optional BluetoothCharacteristicUUID characteristic);
|
||||
Promise<BluetoothRemoteGATTService> getIncludedService(BluetoothServiceUUID service);
|
||||
Promise<sequence<BluetoothRemoteGATTService>> getIncludedServices(optional BluetoothServiceUUID service);
|
||||
};
|
||||
|
|
|
@ -10,26 +10,30 @@
|
|||
clear();
|
||||
var options = {filters: [{services: ['battery_service']}], optionalServices: []};
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var bluetooth = window.navigator.bluetooth;
|
||||
var device = bluetooth.requestDevice(options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(options)
|
||||
.then(device => {
|
||||
log('Connecting to GATT Server on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Battery Service...');
|
||||
var service = server.getPrimaryService('battery_service');
|
||||
|
||||
return server.getPrimaryService('battery_service');
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Battery Level Characteristic...');
|
||||
var characteristic = service.getCharacteristic('battery_level');
|
||||
|
||||
return service.getCharacteristic('battery_level');
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Reading Battery Level...');
|
||||
var value = asciiToDecimal(characteristic.readValue());
|
||||
log('> Battery Level is ' + value + '%');
|
||||
} catch(err) {
|
||||
return characteristic.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Battery Level is ' + asciiToDecimal(value) + '%');
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -20,26 +20,30 @@
|
|||
if (filterNamePrefix)
|
||||
options.filters[0].namePrefix = filterNamePrefix;
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var bluetooth = window.navigator.bluetooth;
|
||||
var device = bluetooth.requestDevice(options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(options)
|
||||
.then(device => {
|
||||
log('Connecting to GATT Server on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Battery Service...');
|
||||
var service = server.getPrimaryService('battery_service');
|
||||
|
||||
return server.getPrimaryService('battery_service');
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Battery Level Characteristic...');
|
||||
var characteristic = service.getCharacteristic('battery_level');
|
||||
|
||||
return service.getCharacteristic('battery_level');
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Reading Battery Level...');
|
||||
var value = asciiToDecimal(characteristic.readValue());
|
||||
log('> Battery Level is ' + value + '%');
|
||||
} catch(err) {
|
||||
return characteristic.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Battery Level is ' + asciiToDecimal(value) + '%');
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -22,19 +22,21 @@
|
|||
if (characteristicUuid.startsWith('0x'))
|
||||
characteristicUuid = parseInt(characteristicUuid, 16);
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]});
|
||||
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATT Server on device...');
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service...');
|
||||
var primaryService = server.getPrimaryService(serviceUuid);
|
||||
|
||||
return server.getPrimaryService(serviceUuid);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic...');
|
||||
var characteristic = primaryService.getCharacteristic(characteristicUuid);
|
||||
|
||||
return service.getCharacteristic(characteristicUuid);
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Characteristic found!');
|
||||
log('> Characteristic service: ' + characteristic.service.uuid);
|
||||
log('> Characteristic UUID: ' + characteristic.uuid);
|
||||
|
@ -47,11 +49,14 @@
|
|||
log('> Signed Write: ' + characteristic.properties.authenticatedSignedWrites);
|
||||
log('> Queued Write: ' + characteristic.properties.reliableWrite);
|
||||
log('> Writable Auxiliaries: ' + characteristic.properties.writableAuxiliaries);
|
||||
characteristic.readValue();
|
||||
log('> Characteristic value: ' + asciiToDecimal(characteristic.value));
|
||||
} catch(err) {
|
||||
return characteristic.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Characteristic value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -32,32 +32,42 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]});
|
||||
|
||||
var bt_server;
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
bt_server = server;
|
||||
|
||||
log('Getting Primary Service "heart_rate"...');
|
||||
var primaryService = server.getPrimaryService('heart_rate');
|
||||
|
||||
return server.getPrimaryService('heart_rate');
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...');
|
||||
var characteristic = primaryService.getCharacteristic(testCases[testNumber].characteristic);
|
||||
|
||||
return service.getCharacteristic(testCases[testNumber].characteristic);
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Characteristic found!');
|
||||
|
||||
if (testCases[testNumber].mustDisconnect) {
|
||||
log('Disconnecting from server...');
|
||||
device.gatt.disconnect();
|
||||
bt_server.disconnect();
|
||||
}
|
||||
|
||||
log('Reading the value of the Characteristic...');
|
||||
characteristic.readValue();
|
||||
log('> Characteristic value: ' + asciiToDecimal(characteristic.value));
|
||||
} catch(err) {
|
||||
return characteristic.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Characteristic value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -34,28 +34,36 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: [0x1234]}]});
|
||||
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
var bt_server;
|
||||
|
||||
log('Getting Primary Service "Test Service"...');
|
||||
var primaryService = server.getPrimaryService(0x1234);
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: [0x1234]}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATT Server on device...');
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
bt_server = server;
|
||||
|
||||
log('Getting Primary Service...');
|
||||
return server.getPrimaryService(0x1234);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...');
|
||||
var characteristic = primaryService.getCharacteristic(testCases[testNumber].characteristic);
|
||||
|
||||
return service.getCharacteristic(testCases[testNumber].characteristic);
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Characteristic found!');
|
||||
|
||||
log('Reading the old value of the Characteristic...');
|
||||
characteristic.readValue();
|
||||
return characteristic.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Characteristic value: ' + asciiToDecimal(characteristic.value));
|
||||
|
||||
if (testCases[testNumber].mustDisconnect) {
|
||||
log('Disconnecting from server...');
|
||||
device.gatt.disconnect();
|
||||
bt_server.disconnect();
|
||||
}
|
||||
|
||||
if (testNumber !== 1) {
|
||||
|
@ -64,14 +72,18 @@
|
|||
log('Writing the value of the Characteristic with a 513 long array...');
|
||||
}
|
||||
|
||||
characteristic.writeValue(testCases[testNumber].valueToWrite);
|
||||
|
||||
return characteristic.writeValue(testCases[testNumber].valueToWrite);
|
||||
})
|
||||
.then(_ => {
|
||||
log('Reading the new value of the Characteristic...');
|
||||
characteristic.readValue();
|
||||
log('> Characteristic value: ' + asciiToDecimal(characteristic.value));
|
||||
} catch(err) {
|
||||
return characteristic.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Characteristic value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -27,30 +27,36 @@
|
|||
if (descriptorUuid.startsWith('0x'))
|
||||
descriptorUuid = parseInt(descriptorUuid, 16);
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]});
|
||||
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATT Server on device...');
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service...');
|
||||
var primaryService = server.getPrimaryService(serviceUuid);
|
||||
|
||||
return server.getPrimaryService(serviceUuid);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic...');
|
||||
var characteristic = primaryService.getCharacteristic(characteristicUuid);
|
||||
|
||||
return service.getCharacteristic(characteristicUuid);
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Getting Descriptor...');
|
||||
var descriptor = characteristic.getDescriptor(descriptorUuid);
|
||||
|
||||
return characteristic.getDescriptor(descriptorUuid);
|
||||
})
|
||||
.then(descriptor => {
|
||||
log('Descriptor found!');
|
||||
log('> Descriptor characteristic: ' + descriptor.characteristic.uuid);
|
||||
log('> Descriptor UUID: ' + descriptor.uuid);
|
||||
descriptor.readValue();
|
||||
log('> Descriptor value: ' + asciiToDecimal(descriptor.value));
|
||||
} catch(err) {
|
||||
return descriptor.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Descriptor value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -22,33 +22,46 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]});
|
||||
|
||||
var bt_server;
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
bt_server = server;
|
||||
|
||||
log('Getting Primary Service "heart_rate"...');
|
||||
var primaryService = server.getPrimaryService('heart_rate');
|
||||
|
||||
return server.getPrimaryService('heart_rate');
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic "heart_rate_measurement"...');
|
||||
var characteristic = primaryService.getCharacteristic('heart_rate_measurement');
|
||||
|
||||
return service.getCharacteristic('heart_rate_measurement');
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Getting Descriptor "' + testCases[testNumber].descriptor + '"...');
|
||||
var descriptor = characteristic.getDescriptor(testCases[testNumber].descriptor);
|
||||
|
||||
return characteristic.getDescriptor(testCases[testNumber].descriptor);
|
||||
})
|
||||
.then(descriptor => {
|
||||
log('Descriptor found!');
|
||||
|
||||
if (testCases[testNumber].mustDisconnect) {
|
||||
log('Disconecting from GATTserver');
|
||||
device.gatt.disconnect();
|
||||
bt_server.disconnect();
|
||||
}
|
||||
|
||||
log("Reading descriptor's value...");
|
||||
descriptor.readValue();
|
||||
log('> Descriptor value: ' + asciiToDecimal(descriptor.value));
|
||||
} catch(err) {
|
||||
return descriptor.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Descriptor value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -22,31 +22,44 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: [0x1234]}]});
|
||||
|
||||
var bt_server;
|
||||
var bt_descriptor;
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: [0x1234]}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
bt_server = server;
|
||||
|
||||
log('Getting Primary Service "Test Service"...');
|
||||
var primaryService = server.getPrimaryService(0x1234);
|
||||
|
||||
return server.getPrimaryService(0x1234);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic "Test Characteristic (0x2345)"...');
|
||||
var characteristic = primaryService.getCharacteristic(0x2345);
|
||||
|
||||
return service.getCharacteristic(0x2345);
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Characteristic found!');
|
||||
|
||||
log('Getting Descriptor "' + testCases[testNumber].descriptor + '"...');
|
||||
var descriptor = characteristic.getDescriptor(testCases[testNumber].descriptor);
|
||||
return characteristic.getDescriptor(testCases[testNumber].descriptor);
|
||||
})
|
||||
.then(descriptor => {
|
||||
bt_descriptor = descriptor;
|
||||
|
||||
log('Reading the old value of the Descriptor...');
|
||||
descriptor.readValue();
|
||||
log('> Descriptor value: ' + asciiToDecimal(descriptor.value));
|
||||
return descriptor.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Descriptor value: ' + asciiToDecimal(value));
|
||||
|
||||
if (testCases[testNumber].mustDisconnect) {
|
||||
log('Disconnecting from server...');
|
||||
device.gatt.disconnect();
|
||||
bt_server.disconnect();
|
||||
}
|
||||
|
||||
if (testNumber !== 1) {
|
||||
|
@ -55,14 +68,18 @@
|
|||
log('Writing the value of the Descriptor with a 513 long array...');
|
||||
}
|
||||
|
||||
descriptor.writeValue(testCases[testNumber].valueToWrite);
|
||||
|
||||
return bt_descriptor.writeValue(testCases[testNumber].valueToWrite);
|
||||
})
|
||||
.then(_ => {
|
||||
log('Reading the new value of the Descriptor...');
|
||||
descriptor.readValue();
|
||||
log('> Descriptor value: ' + asciiToDecimal(descriptor.value));
|
||||
} catch(err) {
|
||||
return bt_descriptor.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Descriptor value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -32,15 +32,18 @@
|
|||
if (filterNamePrefix)
|
||||
options.filters[0].namePrefix = filterNamePrefix;
|
||||
|
||||
try {
|
||||
clear();
|
||||
log('Requesting Bluetooth Device...');
|
||||
bluetoothDevice = window.navigator.bluetooth.requestDevice(options);
|
||||
clear();
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(options)
|
||||
.then(device => {
|
||||
bluetoothDevice = device;
|
||||
|
||||
log('Connecting to Bluetooth Device...');
|
||||
connect();
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onDisconnectButtonClick() {
|
||||
|
@ -75,12 +78,14 @@
|
|||
}
|
||||
|
||||
function connect() {
|
||||
try {
|
||||
log('Result of the connect() method of the GATT Server: ' + bluetoothDevice.gatt.connect());
|
||||
log('> Bluetooth Device connected: ' + bluetoothDevice.gatt.connected);
|
||||
} catch(err) {
|
||||
bluetoothDevice.gatt.connect()
|
||||
.then(server => {
|
||||
log('Result of the connect() method of the GATT Server: ' + server);
|
||||
log('> Bluetooth Device connected: ' + server.connected);
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -28,19 +28,19 @@
|
|||
if (filterNamePrefix)
|
||||
options.filters.push({namePrefix: filterNamePrefix});
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(options)
|
||||
.then(device => {
|
||||
log('Found a device!');
|
||||
log('> Name: ' + device.name);
|
||||
log('> Id: ' + device.id);
|
||||
log('> Appearance: ' + device.adData.appearance);
|
||||
log('> Tx Power: ' + device.adData.txPower + ' dBm');
|
||||
log('> RSSI: ' + device.adData.rssi + ' dBm');
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -44,19 +44,22 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(testCases[testNumber].options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "' + testCases[testNumber].service + '"...');
|
||||
var primaryService = server.getPrimaryService(testCases[testNumber].service);
|
||||
|
||||
return server.getPrimaryService(testCases[testNumber].service);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...');
|
||||
var characteristic = primaryService.getCharacteristic(testCases[testNumber].characteristic);
|
||||
|
||||
return service.getCharacteristic(testCases[testNumber].characteristic);
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Characteristic found!');
|
||||
log('> Characteristic service: ' + characteristic.service.uuid);
|
||||
log('> Characteristic UUID: ' + characteristic.uuid);
|
||||
|
@ -69,11 +72,14 @@
|
|||
log('> Signed Write: ' + characteristic.properties.authenticatedSignedWrites);
|
||||
log('> Queued Write: ' + characteristic.properties.reliableWrite);
|
||||
log('> Writable Auxiliaries: ' + characteristic.properties.writableAuxiliaries);
|
||||
characteristic.readValue();
|
||||
log('> Characteristic value: ' + asciiToDecimal(characteristic.value));
|
||||
} catch(err) {
|
||||
return characteristic.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Characteristic value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -43,21 +43,25 @@
|
|||
testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} });
|
||||
//Test 18
|
||||
testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', service: 'heart_rate', options: {filters: [{services: ['heart_rate']}], optionalServices: ['cycling_power']} });
|
||||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(testCases[testNumber].options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "' + testCases[testNumber].service + '"...');
|
||||
var primaryService = server.getPrimaryService(testCases[testNumber].service);
|
||||
|
||||
return server.getPrimaryService(testCases[testNumber].service);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...');
|
||||
var characteristics = primaryService.getCharacteristics(testCases[testNumber].characteristic);
|
||||
|
||||
return service.getCharacteristics(testCases[testNumber].characteristic);
|
||||
})
|
||||
.then(characteristics => {
|
||||
log('> List of Characteristics on the current device:');
|
||||
|
||||
for(i = 0; i < characteristics.length; ++i) {
|
||||
|
@ -73,12 +77,15 @@
|
|||
log('> Signed Write: ' + characteristics[i].properties.authenticatedSignedWrites);
|
||||
log('> Queued Write: ' + characteristics[i].properties.reliableWrite);
|
||||
log('> Writable Auxiliaries: ' + characteristics[i].properties.writableAuxiliaries);
|
||||
characteristics[i].readValue();
|
||||
log('> Characteristic value: ' + asciiToDecimal(characteristics[i].value));
|
||||
characteristics[i].readValue()
|
||||
.then(value => {
|
||||
log('> #' + (i+1) + ' Characteristic value: ' + asciiToDecimal(characteristics[i].value));
|
||||
});
|
||||
}
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -34,30 +34,38 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]});
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "heart_rate"...');
|
||||
var primaryService = server.getPrimaryService('heart_rate');
|
||||
return server.getPrimaryService('heart_rate');
|
||||
})
|
||||
.then(service => {
|
||||
|
||||
log('Getting Characteristic "heart_rate_measurement"...');
|
||||
var characteristic = primaryService.getCharacteristic('heart_rate_measurement');
|
||||
|
||||
return service.getCharacteristic('heart_rate_measurement');
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Getting Descriptor "' + testCases[testNumber] + '"...');
|
||||
var descriptor = characteristic.getDescriptor(testCases[testNumber]);
|
||||
|
||||
return characteristic.getDescriptor(testCases[testNumber]);
|
||||
})
|
||||
.then(descriptor => {
|
||||
log('Descriptor found!');
|
||||
log('> Descriptor characteristic: ' + descriptor.characteristic.uuid);
|
||||
log('> Descriptor UUID: ' + descriptor.uuid);
|
||||
descriptor.readValue();
|
||||
log('> Descriptor value: ' + asciiToDecimal(descriptor.value));
|
||||
} catch(err) {
|
||||
return descriptor.readValue();
|
||||
})
|
||||
.then(value => {
|
||||
log('> Descriptor value: ' + asciiToDecimal(value));
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -35,31 +35,39 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]});
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "heart_rate"...');
|
||||
var primaryService = server.getPrimaryService('heart_rate');
|
||||
|
||||
return server.getPrimaryService('heart_rate');
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Characteristic "heart_rate_measurement"...');
|
||||
var characteristic = primaryService.getCharacteristic('heart_rate_measurement');
|
||||
|
||||
return service.getCharacteristic('heart_rate_measurement');
|
||||
})
|
||||
.then(characteristic => {
|
||||
log('Getting Descriptors "' + testCases[testNumber] + '"...');
|
||||
var descriptors = characteristic.getDescriptors(testCases[testNumber]);
|
||||
|
||||
return characteristic.getDescriptors(testCases[testNumber]);
|
||||
})
|
||||
.then(descriptors => {
|
||||
for(i = 0; i < descriptors.length; ++i) {
|
||||
log('> #' + (i+1));
|
||||
log('> UUID: ' + descriptors[i].uuid);
|
||||
descriptors[i].readValue();
|
||||
log('> Descriptor value: ' + asciiToDecimal(descriptors[i].value));
|
||||
|
||||
descriptors[i].readValue()
|
||||
.then(value => {
|
||||
log('> #' + (i+1)) + 'Descriptor value: ' + asciiToDecimal(value);
|
||||
});
|
||||
}
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -37,27 +37,32 @@
|
|||
testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0xf000ffc0, options: {filters: [{services: ['battery_service']}]} });
|
||||
//Test 15
|
||||
testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00001530, options: {filters: [{services: ['battery_service']}]} });
|
||||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(testCases[testNumber].options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...');
|
||||
var primaryService = server.getPrimaryService(testCases[testNumber].requestedService);
|
||||
|
||||
return server.getPrimaryService(testCases[testNumber].requestedService);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Included Service "' + testCases[testNumber].requestedIncludedService + '"...')
|
||||
var includedService = primaryService.getIncludedService(testCases[testNumber].requestedIncludedService);
|
||||
|
||||
return service.getIncludedService(testCases[testNumber].requestedIncludedService);
|
||||
})
|
||||
.then(includedService => {
|
||||
log('Primary Service found on device: ' + includedService.device.name);
|
||||
log('> UUID: ' + includedService.uuid);
|
||||
log('> Is primary: ' + includedService.isPrimary);
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -37,29 +37,34 @@
|
|||
testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0xf000ffc0, options: {filters: [{services: ['battery_service']}]} });
|
||||
//Test 15
|
||||
testCases.push({ requestedService: 'battery_service', requestedIncludedService: 0x00001530, options: {filters: [{services: ['battery_service']}]} });
|
||||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(testCases[testNumber].options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...');
|
||||
var primaryService = server.getPrimaryService(testCases[testNumber].requestedService);
|
||||
|
||||
return server.getPrimaryService(testCases[testNumber].requestedService);
|
||||
})
|
||||
.then(service => {
|
||||
log('Getting Included Service "' + testCases[testNumber].requestedIncludedService + '"...')
|
||||
var includedServices = primaryService.getIncludedServices(testCases[testNumber].requestedIncludedService);
|
||||
|
||||
return service.getIncludedServices(testCases[testNumber].requestedIncludedService);
|
||||
})
|
||||
.then(includedServices => {
|
||||
for(i = 0; i < includedServices.length; ++i) {
|
||||
log('> #' + (i+1));
|
||||
log('> UUID: ' + includedServices[i].uuid);
|
||||
log('> Is primary: ' + includedServices[i].isPrimary);
|
||||
}
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -50,22 +50,25 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(testCases[testNumber].options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...');
|
||||
var primaryService = server.getPrimaryService(testCases[testNumber].requestedService);
|
||||
|
||||
log('Primary Service found on device: ' + primaryService.device.name);
|
||||
log('> UUID: ' + primaryService.uuid);
|
||||
log('> Is primary: ' + primaryService.isPrimary);
|
||||
} catch(err) {
|
||||
return server.getPrimaryService(testCases[testNumber].requestedService);
|
||||
})
|
||||
.then(service => {
|
||||
log('Primary Service found on device: ' + service.device.name);
|
||||
log('> UUID: ' + service.uuid);
|
||||
log('> Is primary: ' + service.isPrimary);
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -47,26 +47,30 @@
|
|||
testCases.push({ requestedService: 'cycling_power', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
|
||||
//Test 20
|
||||
testCases.push({ requestedService: '00001818-0000-1000-8000-00805f9b34fb', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
|
||||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(testCases[testNumber].options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(testCases[testNumber].options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service "' + testCases[testNumber].requestedService + '"...');
|
||||
var primaryServices = server.getPrimaryServices(testCases[testNumber].requestedService);
|
||||
|
||||
for(i = 0; i < primaryServices.length; ++i) {
|
||||
return server.getPrimaryServices(testCases[testNumber].requestedService);
|
||||
})
|
||||
.then(services => {
|
||||
for(i = 0; i < services.length; ++i) {
|
||||
log('> #' + (i+1));
|
||||
log('> UUID: ' + primaryServices[i].uuid);
|
||||
log('> Is primary: ' + primaryServices[i].isPrimary);
|
||||
log('> UUID: ' + services[i].uuid);
|
||||
log('> Is primary: ' + services[i].isPrimary);
|
||||
}
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
|
@ -28,27 +28,30 @@
|
|||
if (filterNamePrefix)
|
||||
options.filters.push({namePrefix: filterNamePrefix});
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service...');
|
||||
var primaryService = server.getPrimaryService(filterService);
|
||||
|
||||
log('Primary Service found on device: ' + primaryService.device.name);
|
||||
log('> UUID: ' + primaryService.uuid);
|
||||
return server.getPrimaryService(filterService);
|
||||
})
|
||||
.then(service => {
|
||||
log('Primary Service found on device: ' + service.device.name);
|
||||
log('> UUID: ' + service.uuid);
|
||||
|
||||
log('Getting Included Services...');
|
||||
var includedServices = primaryService.getIncludedServices();
|
||||
|
||||
return service.getIncludedServices();
|
||||
})
|
||||
.then(includedServices => {
|
||||
log('> Included Services: ' +
|
||||
includedServices.map(s => s.uuid).join('\n' + ' '.repeat(21)));
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -28,22 +28,24 @@
|
|||
if (filterNamePrefix)
|
||||
options.filters.push({namePrefix: filterNamePrefix});
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
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) {
|
||||
return server.getPrimaryService(filterService);
|
||||
})
|
||||
.then(service => {
|
||||
log('Primary Service found on device: ' + service.device.name);
|
||||
log('> UUID: ' + service.uuid);
|
||||
log('> Is primary: ' + service.isPrimary);
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -28,29 +28,30 @@
|
|||
if (filterNamePrefix)
|
||||
options.filters.push({namePrefix: filterNamePrefix});
|
||||
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(options);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(options)
|
||||
.then(device => {
|
||||
log('Connecting to GATTserver on device...');
|
||||
var server = device.gatt.connect();
|
||||
|
||||
return device.gatt.connect();
|
||||
})
|
||||
.then(server => {
|
||||
log('Getting Primary Service...');
|
||||
var primaryServices;
|
||||
if (filterService) {
|
||||
primaryServices = server.getPrimaryServices(filterService);
|
||||
} else {
|
||||
primaryServices = server.getPrimaryServices();
|
||||
}
|
||||
if (filterService)
|
||||
return server.getPrimaryServices(filterService);
|
||||
else
|
||||
return server.getPrimaryServices();
|
||||
})
|
||||
.then(services => {
|
||||
log('> List of Services on the current device:');
|
||||
for(i = 0; i < primaryServices.length; ++i) {
|
||||
for(i = 0; i < services.length; ++i) {
|
||||
log('> #' + (i+1));
|
||||
log('> UUID: ' + primaryServices[i].uuid);
|
||||
log('> Is primary: ' + primaryServices[i].isPrimary);
|
||||
log('> UUID: ' + services[i].uuid);
|
||||
log('> Is primary: ' + services[i].isPrimary);
|
||||
}
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -52,19 +52,20 @@
|
|||
|
||||
function onButtonClick(testNumber) {
|
||||
clear();
|
||||
try {
|
||||
log('Requesting Bluetooth Device...');
|
||||
var device = window.navigator.bluetooth.requestDevice(testCases[testNumber]);
|
||||
|
||||
log('Requesting Bluetooth Device...');
|
||||
window.navigator.bluetooth.requestDevice(testCases[testNumber])
|
||||
.then(device => {
|
||||
log('Found a device!');
|
||||
log('> Name: ' + device.name);
|
||||
log('> Id: ' + device.id);
|
||||
log('> Appearance: ' + device.adData.appearance);
|
||||
log('> Tx Power: ' + device.adData.txPower + ' dBm');
|
||||
log('> RSSI: ' + device.adData.rssi + ' dBm');
|
||||
} catch(err) {
|
||||
})
|
||||
.catch(err => {
|
||||
log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
populate(testCases);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue