mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #14387 - szeged:event-target, r=jdm
Add event target for bluetooth <!-- Please describe your changes on the following line: --> Add support for event listeners in webbluetooth. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14387) <!-- Reviewable:end -->
This commit is contained in:
commit
2c05bf3c42
11 changed files with 111 additions and 19 deletions
|
@ -77,3 +77,4 @@ toggle
|
||||||
statechange
|
statechange
|
||||||
controllerchange
|
controllerchange
|
||||||
fetch
|
fetch
|
||||||
|
characteristicvaluechanged
|
||||||
|
|
|
@ -11,12 +11,13 @@ use core::clone::Clone;
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothDataFilterInit, BluetoothLEScanFilterInit};
|
use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothDataFilterInit, BluetoothLEScanFilterInit};
|
||||||
use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions};
|
use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions};
|
||||||
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
|
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
|
||||||
use dom::bindings::error::Error::{self, NotFound, Security, Type};
|
use dom::bindings::error::Error::{self, NotFound, Security, Type};
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::js::{JS, MutHeap, Root};
|
use dom::bindings::js::{JS, MutHeap, Root};
|
||||||
use dom::bindings::refcounted::{Trusted, TrustedPromise};
|
use dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflectable, reflect_dom_object};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
||||||
use dom::bluetoothdevice::BluetoothDevice;
|
use dom::bluetoothdevice::BluetoothDevice;
|
||||||
|
@ -24,6 +25,7 @@ use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
||||||
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
||||||
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
||||||
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
|
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::promise::Promise;
|
use dom::promise::Promise;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
|
@ -84,7 +86,7 @@ impl<Listener: AsyncBluetoothListener + Reflectable> BluetoothResponseListener f
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct Bluetooth {
|
pub struct Bluetooth {
|
||||||
reflector_: Reflector,
|
eventtarget: EventTarget,
|
||||||
device_instance_map: DOMRefCell<HashMap<String, MutHeap<JS<BluetoothDevice>>>>,
|
device_instance_map: DOMRefCell<HashMap<String, MutHeap<JS<BluetoothDevice>>>>,
|
||||||
service_instance_map: DOMRefCell<HashMap<String, MutHeap<JS<BluetoothRemoteGATTService>>>>,
|
service_instance_map: DOMRefCell<HashMap<String, MutHeap<JS<BluetoothRemoteGATTService>>>>,
|
||||||
characteristic_instance_map: DOMRefCell<HashMap<String, MutHeap<JS<BluetoothRemoteGATTCharacteristic>>>>,
|
characteristic_instance_map: DOMRefCell<HashMap<String, MutHeap<JS<BluetoothRemoteGATTCharacteristic>>>>,
|
||||||
|
@ -94,7 +96,7 @@ pub struct Bluetooth {
|
||||||
impl Bluetooth {
|
impl Bluetooth {
|
||||||
pub fn new_inherited() -> Bluetooth {
|
pub fn new_inherited() -> Bluetooth {
|
||||||
Bluetooth {
|
Bluetooth {
|
||||||
reflector_: Reflector::new(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
device_instance_map: DOMRefCell::new(HashMap::new()),
|
device_instance_map: DOMRefCell::new(HashMap::new()),
|
||||||
service_instance_map: DOMRefCell::new(HashMap::new()),
|
service_instance_map: DOMRefCell::new(HashMap::new()),
|
||||||
characteristic_instance_map: DOMRefCell::new(HashMap::new()),
|
characteristic_instance_map: DOMRefCell::new(HashMap::new()),
|
||||||
|
@ -382,6 +384,9 @@ impl BluetoothMethods for Bluetooth {
|
||||||
// TODO(#4282): Step 3-5: Reject and resolve promise.
|
// TODO(#4282): Step 3-5: Reject and resolve promise.
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-onavailabilitychanged
|
||||||
|
event_handler!(availabilitychanged, GetOnavailabilitychanged, SetOnavailabilitychanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncBluetoothListener for Bluetooth {
|
impl AsyncBluetoothListener for Bluetooth {
|
||||||
|
|
|
@ -4,18 +4,20 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding;
|
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
|
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::js::{JS, Root, MutHeap, MutNullableHeap};
|
use dom::bindings::js::{JS, Root, MutHeap, MutNullableHeap};
|
||||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflectable, reflect_dom_object};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::bluetooth::Bluetooth;
|
use dom::bluetooth::Bluetooth;
|
||||||
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
||||||
use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer;
|
use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer;
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct BluetoothDevice {
|
pub struct BluetoothDevice {
|
||||||
reflector_: Reflector,
|
eventtarget: EventTarget,
|
||||||
id: DOMString,
|
id: DOMString,
|
||||||
name: Option<DOMString>,
|
name: Option<DOMString>,
|
||||||
ad_data: MutHeap<JS<BluetoothAdvertisingData>>,
|
ad_data: MutHeap<JS<BluetoothAdvertisingData>>,
|
||||||
|
@ -30,7 +32,7 @@ impl BluetoothDevice {
|
||||||
context: &Bluetooth)
|
context: &Bluetooth)
|
||||||
-> BluetoothDevice {
|
-> BluetoothDevice {
|
||||||
BluetoothDevice {
|
BluetoothDevice {
|
||||||
reflector_: Reflector::new(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
ad_data: MutHeap::new(ad_data),
|
ad_data: MutHeap::new(ad_data),
|
||||||
|
@ -80,4 +82,7 @@ impl BluetoothDeviceMethods for BluetoothDevice {
|
||||||
BluetoothRemoteGATTServer::new(&self.global(), self)
|
BluetoothRemoteGATTServer::new(&self.global(), self)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdeviceeventhandlers-ongattserverdisconnected
|
||||||
|
event_handler!(gattserverdisconnected, GetOngattserverdisconnected, SetOngattserverdisconnected);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,18 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::
|
||||||
BluetoothRemoteGATTCharacteristicMethods;
|
BluetoothRemoteGATTCharacteristicMethods;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::error::Error::{self, InvalidModification, Network, NotSupported, Security};
|
use dom::bindings::error::Error::{self, InvalidModification, Network, NotSupported, Security};
|
||||||
|
use dom::bindings::inheritance::Castable;
|
||||||
use dom::bindings::js::{JS, MutHeap, Root};
|
use dom::bindings::js::{JS, MutHeap, Root};
|
||||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflectable, reflect_dom_object};
|
||||||
use dom::bindings::str::{ByteString, DOMString};
|
use dom::bindings::str::{ByteString, DOMString};
|
||||||
use dom::bluetooth::{AsyncBluetoothListener, response_async};
|
use dom::bluetooth::{AsyncBluetoothListener, response_async};
|
||||||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||||
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
||||||
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
||||||
use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID};
|
use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::promise::Promise;
|
use dom::promise::Promise;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
@ -35,7 +38,7 @@ pub const MAXIMUM_ATTRIBUTE_LENGTH: usize = 512;
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct BluetoothRemoteGATTCharacteristic {
|
pub struct BluetoothRemoteGATTCharacteristic {
|
||||||
reflector_: Reflector,
|
eventtarget: EventTarget,
|
||||||
service: MutHeap<JS<BluetoothRemoteGATTService>>,
|
service: MutHeap<JS<BluetoothRemoteGATTService>>,
|
||||||
uuid: DOMString,
|
uuid: DOMString,
|
||||||
properties: MutHeap<JS<BluetoothCharacteristicProperties>>,
|
properties: MutHeap<JS<BluetoothCharacteristicProperties>>,
|
||||||
|
@ -50,7 +53,7 @@ impl BluetoothRemoteGATTCharacteristic {
|
||||||
instance_id: String)
|
instance_id: String)
|
||||||
-> BluetoothRemoteGATTCharacteristic {
|
-> BluetoothRemoteGATTCharacteristic {
|
||||||
BluetoothRemoteGATTCharacteristic {
|
BluetoothRemoteGATTCharacteristic {
|
||||||
reflector_: Reflector::new(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
service: MutHeap::new(service),
|
service: MutHeap::new(service),
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
properties: MutHeap::new(properties),
|
properties: MutHeap::new(properties),
|
||||||
|
@ -255,6 +258,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
||||||
sender)).unwrap();
|
sender)).unwrap();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-characteristiceventhandlers-oncharacteristicvaluechanged
|
||||||
|
event_handler!(characteristicvaluechanged, GetOncharacteristicvaluechanged, SetOncharacteristicvaluechanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
|
impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
|
||||||
|
@ -297,6 +303,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
|
||||||
BluetoothResponse::ReadValue(result) => {
|
BluetoothResponse::ReadValue(result) => {
|
||||||
let value = ByteString::new(result);
|
let value = ByteString::new(result);
|
||||||
*self.value.borrow_mut() = Some(value.clone());
|
*self.value.borrow_mut() = Some(value.clone());
|
||||||
|
self.upcast::<EventTarget>().fire_bubbling_event(atom!("characteristicvaluechanged"));
|
||||||
promise.resolve_native(promise_cx, &value);
|
promise.resolve_native(promise_cx, &value);
|
||||||
},
|
},
|
||||||
BluetoothResponse::WriteValue(result) => {
|
BluetoothResponse::WriteValue(result) => {
|
||||||
|
|
|
@ -8,15 +8,17 @@ use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMet
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::error::Error::{self, Network, Security};
|
use dom::bindings::error::Error::{self, Network, Security};
|
||||||
use dom::bindings::js::{JS, MutHeap, Root};
|
use dom::bindings::js::{JS, MutHeap, Root};
|
||||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflectable, reflect_dom_object};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::bluetooth::{AsyncBluetoothListener, response_async};
|
use dom::bluetooth::{AsyncBluetoothListener, response_async};
|
||||||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||||
use dom::bluetoothdevice::BluetoothDevice;
|
use dom::bluetoothdevice::BluetoothDevice;
|
||||||
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
||||||
use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, BluetoothUUID};
|
use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, BluetoothUUID};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use dom::promise::Promise;
|
use dom::promise::Promise;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
@ -26,7 +28,7 @@ use std::rc::Rc;
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct BluetoothRemoteGATTService {
|
pub struct BluetoothRemoteGATTService {
|
||||||
reflector_: Reflector,
|
eventtarget: EventTarget,
|
||||||
device: MutHeap<JS<BluetoothDevice>>,
|
device: MutHeap<JS<BluetoothDevice>>,
|
||||||
uuid: DOMString,
|
uuid: DOMString,
|
||||||
is_primary: bool,
|
is_primary: bool,
|
||||||
|
@ -40,7 +42,7 @@ impl BluetoothRemoteGATTService {
|
||||||
instance_id: String)
|
instance_id: String)
|
||||||
-> BluetoothRemoteGATTService {
|
-> BluetoothRemoteGATTService {
|
||||||
BluetoothRemoteGATTService {
|
BluetoothRemoteGATTService {
|
||||||
reflector_: Reflector::new(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
device: MutHeap::new(device),
|
device: MutHeap::new(device),
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
is_primary: is_primary,
|
is_primary: is_primary,
|
||||||
|
@ -217,6 +219,15 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
||||||
sender)).unwrap();
|
sender)).unwrap();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-serviceeventhandlers-onserviceadded
|
||||||
|
event_handler!(serviceadded, GetOnserviceadded, SetOnserviceadded);
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-serviceeventhandlers-onservicechanged
|
||||||
|
event_handler!(servicechanged, GetOnservicechanged, SetOnservicechanged);
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-serviceeventhandlers-onserviceremoved
|
||||||
|
event_handler!(serviceremoved, GetOnserviceremoved, SetOnserviceremoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncBluetoothListener for BluetoothRemoteGATTService {
|
impl AsyncBluetoothListener for BluetoothRemoteGATTService {
|
||||||
|
|
|
@ -28,9 +28,10 @@ dictionary RequestDeviceOptions {
|
||||||
};
|
};
|
||||||
|
|
||||||
[Pref="dom.bluetooth.enabled"]
|
[Pref="dom.bluetooth.enabled"]
|
||||||
interface Bluetooth {
|
interface Bluetooth : EventTarget {
|
||||||
// [SecureContext]
|
// [SecureContext]
|
||||||
// readonly attribute BluetoothDevice? referringDevice;
|
// readonly attribute BluetoothDevice? referringDevice;
|
||||||
|
attribute EventHandler onavailabilitychanged;
|
||||||
// [SecureContext]
|
// [SecureContext]
|
||||||
// Promise<boolean> getAvailability();
|
// Promise<boolean> getAvailability();
|
||||||
// [SecureContext]
|
// [SecureContext]
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
|
||||||
|
|
||||||
[Pref="dom.bluetooth.enabled"]
|
[Pref="dom.bluetooth.enabled"]
|
||||||
interface BluetoothDevice {
|
interface BluetoothDevice : EventTarget {
|
||||||
readonly attribute DOMString id;
|
readonly attribute DOMString id;
|
||||||
readonly attribute DOMString? name;
|
readonly attribute DOMString? name;
|
||||||
// TODO: remove this after BluetoothAdvertisingEvent implemented.
|
// TODO: remove this after BluetoothAdvertisingEvent implemented.
|
||||||
|
@ -17,7 +17,12 @@ interface BluetoothDevice {
|
||||||
// readonly attribute boolean watchingAdvertisements;
|
// readonly attribute boolean watchingAdvertisements;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[NoInterfaceObject]
|
||||||
|
interface BluetoothDeviceEventHandlers {
|
||||||
|
attribute EventHandler ongattserverdisconnected;
|
||||||
|
};
|
||||||
|
|
||||||
// BluetoothDevice implements EventTarget;
|
// BluetoothDevice implements EventTarget;
|
||||||
// BluetoothDevice implements BluetoothDeviceEventHandlers;
|
BluetoothDevice implements BluetoothDeviceEventHandlers;
|
||||||
// BluetoothDevice implements CharacteristicEventHandlers;
|
// BluetoothDevice implements CharacteristicEventHandlers;
|
||||||
// BluetoothDevice implements ServiceEventHandlers;
|
// BluetoothDevice implements ServiceEventHandlers;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
|
||||||
|
|
||||||
[Pref="dom.bluetooth.enabled"]
|
[Pref="dom.bluetooth.enabled"]
|
||||||
interface BluetoothRemoteGATTCharacteristic {
|
interface BluetoothRemoteGATTCharacteristic : EventTarget {
|
||||||
readonly attribute BluetoothRemoteGATTService service;
|
readonly attribute BluetoothRemoteGATTService service;
|
||||||
readonly attribute DOMString uuid;
|
readonly attribute DOMString uuid;
|
||||||
readonly attribute BluetoothCharacteristicProperties properties;
|
readonly attribute BluetoothCharacteristicProperties properties;
|
||||||
|
@ -21,5 +21,10 @@ interface BluetoothRemoteGATTCharacteristic {
|
||||||
Promise<BluetoothRemoteGATTCharacteristic> stopNotifications();
|
Promise<BluetoothRemoteGATTCharacteristic> stopNotifications();
|
||||||
};
|
};
|
||||||
|
|
||||||
//BluetootRemoteGATTCharacteristic implements EventTarget;
|
[NoInterfaceObject]
|
||||||
//BluetootRemoteGATTCharacteristic implements CharacteristicEventHandlers;
|
interface CharacteristicEventHandlers {
|
||||||
|
attribute EventHandler oncharacteristicvaluechanged;
|
||||||
|
};
|
||||||
|
|
||||||
|
// BluetoothRemoteGATTCharacteristic implements EventTarget;
|
||||||
|
BluetoothRemoteGATTCharacteristic implements CharacteristicEventHandlers;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
|
||||||
|
|
||||||
[Pref="dom.bluetooth.enabled"]
|
[Pref="dom.bluetooth.enabled"]
|
||||||
interface BluetoothRemoteGATTService {
|
interface BluetoothRemoteGATTService : EventTarget {
|
||||||
readonly attribute BluetoothDevice device;
|
readonly attribute BluetoothDevice device;
|
||||||
readonly attribute DOMString uuid;
|
readonly attribute DOMString uuid;
|
||||||
readonly attribute boolean isPrimary;
|
readonly attribute boolean isPrimary;
|
||||||
|
@ -15,3 +15,14 @@ interface BluetoothRemoteGATTService {
|
||||||
Promise<BluetoothRemoteGATTService> getIncludedService(BluetoothServiceUUID service);
|
Promise<BluetoothRemoteGATTService> getIncludedService(BluetoothServiceUUID service);
|
||||||
Promise<sequence<BluetoothRemoteGATTService>> getIncludedServices(optional BluetoothServiceUUID service);
|
Promise<sequence<BluetoothRemoteGATTService>> getIncludedServices(optional BluetoothServiceUUID service);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[NoInterfaceObject]
|
||||||
|
interface ServiceEventHandlers {
|
||||||
|
attribute EventHandler onserviceadded;
|
||||||
|
attribute EventHandler onservicechanged;
|
||||||
|
attribute EventHandler onserviceremoved;
|
||||||
|
};
|
||||||
|
|
||||||
|
// BluetoothRemoteGATTService implements EventTarget;
|
||||||
|
// BluetoothRemoteGATTService implements CharacteristicEventHandlers;
|
||||||
|
BluetoothRemoteGATTService implements ServiceEventHandlers;
|
||||||
|
|
|
@ -7268,6 +7268,12 @@
|
||||||
"url": "/_mozilla/mozilla/bluetooth/readValue/characteristic/disconnect-called-before.html"
|
"url": "/_mozilla/mozilla/bluetooth/readValue/characteristic/disconnect-called-before.html"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"mozilla/bluetooth/readValue/characteristic/event-is-fired.html": [
|
||||||
|
{
|
||||||
|
"path": "mozilla/bluetooth/readValue/characteristic/event-is-fired.html",
|
||||||
|
"url": "/_mozilla/mozilla/bluetooth/readValue/characteristic/event-is-fired.html"
|
||||||
|
}
|
||||||
|
],
|
||||||
"mozilla/bluetooth/readValue/characteristic/read-succeeds.html": [
|
"mozilla/bluetooth/readValue/characteristic/read-succeeds.html": [
|
||||||
{
|
{
|
||||||
"path": "mozilla/bluetooth/readValue/characteristic/read-succeeds.html",
|
"path": "mozilla/bluetooth/readValue/characteristic/read-succeeds.html",
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!doctype html>
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<script src="/_mozilla/mozilla/bluetooth/bluetooth-helpers.js"></script>
|
||||||
|
<script>
|
||||||
|
'use strict';
|
||||||
|
promise_test(() => {
|
||||||
|
window.testRunner.setBluetoothMockDataSet(adapter_type.heart_rate);
|
||||||
|
return window.navigator.bluetooth.requestDevice({
|
||||||
|
filters: [{services: [heart_rate.name]}],
|
||||||
|
optionalServices: [generic_access.name]
|
||||||
|
})
|
||||||
|
.then(device => device.gatt.connect())
|
||||||
|
.then(gattServer => gattServer.getPrimaryService(generic_access.name))
|
||||||
|
.then(service => service.getCharacteristic(device_name.name))
|
||||||
|
.then(characteristic => {
|
||||||
|
let event = 'characteristicvaluechanged';
|
||||||
|
let event_promise = new Promise((resolve, reject) => {
|
||||||
|
let event_listener = (e) => {
|
||||||
|
characteristic.removeEventListener(event, event_listener);
|
||||||
|
resolve(e.target.value);
|
||||||
|
};
|
||||||
|
characteristic.addEventListener(event, event_listener);
|
||||||
|
});
|
||||||
|
return characteristic.readValue()
|
||||||
|
.then(result => {
|
||||||
|
return Promise.all([result, event_promise]);
|
||||||
|
});
|
||||||
|
}).then(results => {
|
||||||
|
let read_value = results[0];
|
||||||
|
let event_value = results[1];
|
||||||
|
assert_array_equals(event_value, read_value);
|
||||||
|
});
|
||||||
|
}, 'Reading a characteristic should fire an event.');
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue