mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Replace AdvertisingData with AdvertisingEvent
This commit is contained in:
parent
a2391162a1
commit
748b78a6bf
12 changed files with 237 additions and 99 deletions
|
@ -278,6 +278,9 @@ impl BluetoothManager {
|
||||||
BluetoothRequest::EnableNotification(id, enable, sender) => {
|
BluetoothRequest::EnableNotification(id, enable, sender) => {
|
||||||
self.enable_notification(id, enable, sender)
|
self.enable_notification(id, enable, sender)
|
||||||
},
|
},
|
||||||
|
BluetoothRequest::WatchAdvertisements(id, sender) => {
|
||||||
|
self.watch_advertisements(id, sender)
|
||||||
|
},
|
||||||
BluetoothRequest::Test(data_set_name, sender) => {
|
BluetoothRequest::Test(data_set_name, sender) => {
|
||||||
self.test(data_set_name, sender)
|
self.test(data_set_name, sender)
|
||||||
}
|
}
|
||||||
|
@ -613,9 +616,6 @@ impl BluetoothManager {
|
||||||
let message = BluetoothDeviceMsg {
|
let message = BluetoothDeviceMsg {
|
||||||
id: device_id,
|
id: device_id,
|
||||||
name: device.get_name().ok(),
|
name: device.get_name().ok(),
|
||||||
appearance: device.get_appearance().ok(),
|
|
||||||
tx_power: device.get_tx_power().ok().map(|p| p as i8),
|
|
||||||
rssi: device.get_rssi().ok().map(|p| p as i8),
|
|
||||||
};
|
};
|
||||||
return drop(sender.send(Ok(BluetoothResponse::RequestDevice(message))));
|
return drop(sender.send(Ok(BluetoothResponse::RequestDevice(message))));
|
||||||
}
|
}
|
||||||
|
@ -1094,4 +1094,11 @@ impl BluetoothManager {
|
||||||
None => return drop(sender.send(Err(BluetoothError::InvalidState))),
|
None => return drop(sender.send(Err(BluetoothError::InvalidState))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-watchadvertisements
|
||||||
|
fn watch_advertisements(&mut self, _device_id: String, sender: IpcSender<BluetoothResponseResult>) {
|
||||||
|
// Step 2.
|
||||||
|
// TODO: Implement this when supported in lower level
|
||||||
|
return drop(sender.send(Err(BluetoothError::NotSupported)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,6 @@ pub struct BluetoothDeviceMsg {
|
||||||
// Bluetooth Device properties
|
// Bluetooth Device properties
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
// Advertising Data properties
|
|
||||||
pub appearance: Option<u16>,
|
|
||||||
pub tx_power: Option<i8>,
|
|
||||||
pub rssi: Option<i8>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
|
@ -93,6 +89,7 @@ pub enum BluetoothRequest {
|
||||||
ReadValue(String, IpcSender<BluetoothResponseResult>),
|
ReadValue(String, IpcSender<BluetoothResponseResult>),
|
||||||
WriteValue(String, Vec<u8>, IpcSender<BluetoothResponseResult>),
|
WriteValue(String, Vec<u8>, IpcSender<BluetoothResponseResult>),
|
||||||
EnableNotification(String, bool, IpcSender<BluetoothResponseResult>),
|
EnableNotification(String, bool, IpcSender<BluetoothResponseResult>),
|
||||||
|
WatchAdvertisements(String, IpcSender<BluetoothResponseResult>),
|
||||||
Test(String, IpcSender<BluetoothResult<()>>),
|
Test(String, IpcSender<BluetoothResult<()>>),
|
||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
@ -112,6 +109,7 @@ pub enum BluetoothResponse {
|
||||||
ReadValue(Vec<u8>),
|
ReadValue(Vec<u8>),
|
||||||
WriteValue(Vec<u8>),
|
WriteValue(Vec<u8>),
|
||||||
EnableNotification(()),
|
EnableNotification(()),
|
||||||
|
WatchAdvertisements(()),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BluetoothResponseListener {
|
pub trait BluetoothResponseListener {
|
||||||
|
|
|
@ -19,7 +19,6 @@ use dom::bindings::js::{MutJS, Root};
|
||||||
use dom::bindings::refcounted::{Trusted, TrustedPromise};
|
use dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||||
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
|
||||||
use dom::bluetoothdevice::BluetoothDevice;
|
use dom::bluetoothdevice::BluetoothDevice;
|
||||||
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
|
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
@ -400,14 +399,9 @@ impl AsyncBluetoothListener for Bluetooth {
|
||||||
if let Some(existing_device) = device_instance_map.get(&device.id.clone()) {
|
if let Some(existing_device) = device_instance_map.get(&device.id.clone()) {
|
||||||
return promise.resolve_native(promise_cx, &existing_device.get());
|
return promise.resolve_native(promise_cx, &existing_device.get());
|
||||||
}
|
}
|
||||||
let ad_data = BluetoothAdvertisingData::new(&self.global(),
|
|
||||||
device.appearance,
|
|
||||||
device.tx_power,
|
|
||||||
device.rssi);
|
|
||||||
let bt_device = BluetoothDevice::new(&self.global(),
|
let bt_device = BluetoothDevice::new(&self.global(),
|
||||||
DOMString::from(device.id.clone()),
|
DOMString::from(device.id.clone()),
|
||||||
device.name.map(DOMString::from),
|
device.name.map(DOMString::from),
|
||||||
&ad_data,
|
|
||||||
&self);
|
&self);
|
||||||
device_instance_map.insert(device.id, MutJS::new(&bt_device));
|
device_instance_map.insert(device.id, MutJS::new(&bt_device));
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::BluetoothAdvertisingDataBinding;
|
|
||||||
use dom::bindings::codegen::Bindings::BluetoothAdvertisingDataBinding::BluetoothAdvertisingDataMethods;
|
|
||||||
use dom::bindings::js::Root;
|
|
||||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
|
||||||
use dom::globalscope::GlobalScope;
|
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothadvertisingdata
|
|
||||||
#[dom_struct]
|
|
||||||
pub struct BluetoothAdvertisingData {
|
|
||||||
reflector_: Reflector,
|
|
||||||
appearance: Option<u16>,
|
|
||||||
tx_power: Option<i8>,
|
|
||||||
rssi: Option<i8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BluetoothAdvertisingData {
|
|
||||||
pub fn new_inherited(appearance: Option<u16>,
|
|
||||||
tx_power: Option<i8>,
|
|
||||||
rssi: Option<i8>)
|
|
||||||
-> BluetoothAdvertisingData {
|
|
||||||
BluetoothAdvertisingData {
|
|
||||||
reflector_: Reflector::new(),
|
|
||||||
appearance: appearance,
|
|
||||||
tx_power: tx_power,
|
|
||||||
rssi: rssi,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(global: &GlobalScope,
|
|
||||||
appearance: Option<u16>,
|
|
||||||
txPower: Option<i8>,
|
|
||||||
rssi: Option<i8>)
|
|
||||||
-> Root<BluetoothAdvertisingData> {
|
|
||||||
reflect_dom_object(box BluetoothAdvertisingData::new_inherited(appearance,
|
|
||||||
txPower,
|
|
||||||
rssi),
|
|
||||||
global,
|
|
||||||
BluetoothAdvertisingDataBinding::Wrap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BluetoothAdvertisingDataMethods for BluetoothAdvertisingData {
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-appearance
|
|
||||||
fn GetAppearance(&self) -> Option<u16> {
|
|
||||||
self.appearance
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-txpower
|
|
||||||
fn GetTxPower(&self) -> Option<i8> {
|
|
||||||
self.tx_power
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-rssi
|
|
||||||
fn GetRssi(&self) -> Option<i8> {
|
|
||||||
self.rssi
|
|
||||||
}
|
|
||||||
}
|
|
126
components/script/dom/bluetoothadvertisingevent.rs
Normal file
126
components/script/dom/bluetoothadvertisingevent.rs
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use dom::bindings::codegen::Bindings::BluetoothAdvertisingEventBinding::{self, BluetoothAdvertisingEventInit};
|
||||||
|
use dom::bindings::codegen::Bindings::BluetoothAdvertisingEventBinding::BluetoothAdvertisingEventMethods;
|
||||||
|
use dom::bindings::codegen::Bindings::EventBinding::EventBinding::EventMethods;
|
||||||
|
use dom::bindings::error::Fallible;
|
||||||
|
use dom::bindings::inheritance::Castable;
|
||||||
|
use dom::bindings::js::{JS, Root, RootedReference};
|
||||||
|
use dom::bindings::reflector::reflect_dom_object;
|
||||||
|
use dom::bindings::str::DOMString;
|
||||||
|
use dom::bluetoothdevice::BluetoothDevice;
|
||||||
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::globalscope::GlobalScope;
|
||||||
|
use dom::window::Window;
|
||||||
|
use servo_atoms::Atom;
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothadvertisingevent
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct BluetoothAdvertisingEvent {
|
||||||
|
event: Event,
|
||||||
|
device: JS<BluetoothDevice>,
|
||||||
|
name: Option<DOMString>,
|
||||||
|
appearance: Option<u16>,
|
||||||
|
tx_power: Option<i8>,
|
||||||
|
rssi: Option<i8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BluetoothAdvertisingEvent {
|
||||||
|
pub fn new_inherited(device: &BluetoothDevice,
|
||||||
|
name: Option<DOMString>,
|
||||||
|
appearance: Option<u16>,
|
||||||
|
tx_power: Option<i8>,
|
||||||
|
rssi: Option<i8>)
|
||||||
|
-> BluetoothAdvertisingEvent {
|
||||||
|
BluetoothAdvertisingEvent {
|
||||||
|
event: Event::new_inherited(),
|
||||||
|
device: JS::from_ref(device),
|
||||||
|
name: name,
|
||||||
|
appearance: appearance,
|
||||||
|
tx_power: tx_power,
|
||||||
|
rssi: rssi,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(global: &GlobalScope,
|
||||||
|
type_: Atom,
|
||||||
|
bubbles: EventBubbles,
|
||||||
|
cancelable: EventCancelable,
|
||||||
|
device: &BluetoothDevice,
|
||||||
|
name: Option<DOMString>,
|
||||||
|
appearance: Option<u16>,
|
||||||
|
txPower: Option<i8>,
|
||||||
|
rssi: Option<i8>)
|
||||||
|
-> Root<BluetoothAdvertisingEvent> {
|
||||||
|
let ev = reflect_dom_object(box BluetoothAdvertisingEvent::new_inherited(device,
|
||||||
|
name,
|
||||||
|
appearance,
|
||||||
|
txPower,
|
||||||
|
rssi),
|
||||||
|
global,
|
||||||
|
BluetoothAdvertisingEventBinding::Wrap);
|
||||||
|
{
|
||||||
|
let event = ev.upcast::<Event>();
|
||||||
|
event.init_event(type_, bool::from(bubbles), bool::from(cancelable));
|
||||||
|
}
|
||||||
|
ev
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingevent-bluetoothadvertisingevent
|
||||||
|
pub fn Constructor(window: &Window,
|
||||||
|
type_: DOMString,
|
||||||
|
init: &BluetoothAdvertisingEventInit)
|
||||||
|
-> Fallible<Root<BluetoothAdvertisingEvent>> {
|
||||||
|
let global = window.upcast::<GlobalScope>();
|
||||||
|
let device = init.device.r();
|
||||||
|
let name = init.name.clone();
|
||||||
|
let appearance = init.appearance.clone();
|
||||||
|
let txPower = init.txPower.clone();
|
||||||
|
let rssi = init.rssi.clone();
|
||||||
|
let bubbles = EventBubbles::from(init.parent.bubbles);
|
||||||
|
let cancelable = EventCancelable::from(init.parent.cancelable);
|
||||||
|
Ok(BluetoothAdvertisingEvent::new(global,
|
||||||
|
Atom::from(type_),
|
||||||
|
bubbles,
|
||||||
|
cancelable,
|
||||||
|
device,
|
||||||
|
name,
|
||||||
|
appearance,
|
||||||
|
txPower,
|
||||||
|
rssi))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BluetoothAdvertisingEventMethods for BluetoothAdvertisingEvent {
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingevent-device
|
||||||
|
fn Device(&self) -> Root<BluetoothDevice> {
|
||||||
|
Root::from_ref(&*self.device)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingevent-name
|
||||||
|
fn GetName(&self) -> Option<DOMString> {
|
||||||
|
self.name.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingevent-appearance
|
||||||
|
fn GetAppearance(&self) -> Option<u16> {
|
||||||
|
self.appearance
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingevent-txpower
|
||||||
|
fn GetTxPower(&self) -> Option<i8> {
|
||||||
|
self.tx_power
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingevent-rssi
|
||||||
|
fn GetRssi(&self) -> Option<i8> {
|
||||||
|
self.rssi
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://dom.spec.whatwg.org/#dom-event-istrusted
|
||||||
|
fn IsTrusted(&self) -> bool {
|
||||||
|
self.event.IsTrusted()
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,17 +2,18 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use bluetooth_traits::{BluetoothCharacteristicMsg, BluetoothDescriptorMsg, BluetoothServiceMsg};
|
use bluetooth_traits::{BluetoothCharacteristicMsg, BluetoothDescriptorMsg};
|
||||||
|
use bluetooth_traits::{BluetoothRequest, BluetoothResponse, BluetoothServiceMsg};
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
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::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
|
use dom::bindings::error::Error;
|
||||||
use dom::bindings::js::{MutJS, MutNullableJS, Root};
|
use dom::bindings::js::{MutJS, MutNullableJS, Root};
|
||||||
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
use dom::bluetooth::Bluetooth;
|
use dom::bluetooth::{AsyncBluetoothListener, Bluetooth, response_async};
|
||||||
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
|
||||||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||||
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
||||||
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
||||||
|
@ -20,8 +21,12 @@ use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer;
|
||||||
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
|
use dom::promise::Promise;
|
||||||
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
use js::jsapi::JSContext;
|
||||||
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -29,42 +34,39 @@ pub struct BluetoothDevice {
|
||||||
eventtarget: EventTarget,
|
eventtarget: EventTarget,
|
||||||
id: DOMString,
|
id: DOMString,
|
||||||
name: Option<DOMString>,
|
name: Option<DOMString>,
|
||||||
ad_data: MutJS<BluetoothAdvertisingData>,
|
|
||||||
gatt: MutNullableJS<BluetoothRemoteGATTServer>,
|
gatt: MutNullableJS<BluetoothRemoteGATTServer>,
|
||||||
context: MutJS<Bluetooth>,
|
context: MutJS<Bluetooth>,
|
||||||
attribute_instance_map: (DOMRefCell<HashMap<String, MutJS<BluetoothRemoteGATTService>>>,
|
attribute_instance_map: (DOMRefCell<HashMap<String, MutJS<BluetoothRemoteGATTService>>>,
|
||||||
DOMRefCell<HashMap<String, MutJS<BluetoothRemoteGATTCharacteristic>>>,
|
DOMRefCell<HashMap<String, MutJS<BluetoothRemoteGATTCharacteristic>>>,
|
||||||
DOMRefCell<HashMap<String, MutJS<BluetoothRemoteGATTDescriptor>>>),
|
DOMRefCell<HashMap<String, MutJS<BluetoothRemoteGATTDescriptor>>>),
|
||||||
|
watching_advertisements: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BluetoothDevice {
|
impl BluetoothDevice {
|
||||||
pub fn new_inherited(id: DOMString,
|
pub fn new_inherited(id: DOMString,
|
||||||
name: Option<DOMString>,
|
name: Option<DOMString>,
|
||||||
ad_data: &BluetoothAdvertisingData,
|
|
||||||
context: &Bluetooth)
|
context: &Bluetooth)
|
||||||
-> BluetoothDevice {
|
-> BluetoothDevice {
|
||||||
BluetoothDevice {
|
BluetoothDevice {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
ad_data: MutJS::new(ad_data),
|
|
||||||
gatt: Default::default(),
|
gatt: Default::default(),
|
||||||
context: MutJS::new(context),
|
context: MutJS::new(context),
|
||||||
attribute_instance_map: (DOMRefCell::new(HashMap::new()),
|
attribute_instance_map: (DOMRefCell::new(HashMap::new()),
|
||||||
DOMRefCell::new(HashMap::new()),
|
DOMRefCell::new(HashMap::new()),
|
||||||
DOMRefCell::new(HashMap::new())),
|
DOMRefCell::new(HashMap::new())),
|
||||||
|
watching_advertisements: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: &GlobalScope,
|
pub fn new(global: &GlobalScope,
|
||||||
id: DOMString,
|
id: DOMString,
|
||||||
name: Option<DOMString>,
|
name: Option<DOMString>,
|
||||||
adData: &BluetoothAdvertisingData,
|
|
||||||
context: &Bluetooth)
|
context: &Bluetooth)
|
||||||
-> Root<BluetoothDevice> {
|
-> Root<BluetoothDevice> {
|
||||||
reflect_dom_object(box BluetoothDevice::new_inherited(id,
|
reflect_dom_object(box BluetoothDevice::new_inherited(id,
|
||||||
name,
|
name,
|
||||||
adData,
|
|
||||||
context),
|
context),
|
||||||
global,
|
global,
|
||||||
BluetoothDeviceBinding::Wrap)
|
BluetoothDeviceBinding::Wrap)
|
||||||
|
@ -133,6 +135,10 @@ impl BluetoothDevice {
|
||||||
descriptor_map.insert(descriptor.instance_id.clone(), MutJS::new(&bt_descriptor));
|
descriptor_map.insert(descriptor.instance_id.clone(), MutJS::new(&bt_descriptor));
|
||||||
return bt_descriptor;
|
return bt_descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothRequest> {
|
||||||
|
self.global().as_window().bluetooth_thread()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BluetoothDeviceMethods for BluetoothDevice {
|
impl BluetoothDeviceMethods for BluetoothDevice {
|
||||||
|
@ -146,11 +152,6 @@ impl BluetoothDeviceMethods for BluetoothDevice {
|
||||||
self.name.clone()
|
self.name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-addata
|
|
||||||
fn AdData(&self) -> Root<BluetoothAdvertisingData> {
|
|
||||||
self.ad_data.get()
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt
|
||||||
fn Gatt(&self) -> Root<BluetoothRemoteGATTServer> {
|
fn Gatt(&self) -> Root<BluetoothRemoteGATTServer> {
|
||||||
// TODO: Step 1 - 2: Implement the Permission API.
|
// TODO: Step 1 - 2: Implement the Permission API.
|
||||||
|
@ -159,6 +160,46 @@ impl BluetoothDeviceMethods for BluetoothDevice {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-watchadvertisements
|
||||||
|
fn WatchAdvertisements(&self) -> Rc<Promise> {
|
||||||
|
let p = Promise::new(&self.global());
|
||||||
|
let sender = response_async(&p, self);
|
||||||
|
// TODO: Step 1.
|
||||||
|
// Note: Steps 2 - 3 are implemented in components/bluetooth/lib.rs in watch_advertisements function
|
||||||
|
// and in handle_response function.
|
||||||
|
self.get_bluetooth_thread().send(
|
||||||
|
BluetoothRequest::WatchAdvertisements(String::from(self.Id()), sender)).unwrap();
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-unwatchadvertisements
|
||||||
|
fn UnwatchAdvertisements(&self) -> () {
|
||||||
|
// Step 1.
|
||||||
|
self.watching_advertisements.set(false)
|
||||||
|
// TODO: Step 2.
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-watchingadvertisements
|
||||||
|
fn WatchingAdvertisements(&self) -> bool {
|
||||||
|
self.watching_advertisements.get()
|
||||||
|
}
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdeviceeventhandlers-ongattserverdisconnected
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdeviceeventhandlers-ongattserverdisconnected
|
||||||
event_handler!(gattserverdisconnected, GetOngattserverdisconnected, SetOngattserverdisconnected);
|
event_handler!(gattserverdisconnected, GetOngattserverdisconnected, SetOngattserverdisconnected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsyncBluetoothListener for BluetoothDevice {
|
||||||
|
fn handle_response(&self, response: BluetoothResponse, promise_cx: *mut JSContext, promise: &Rc<Promise>) {
|
||||||
|
match response {
|
||||||
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-unwatchadvertisements
|
||||||
|
BluetoothResponse::WatchAdvertisements(_result) => {
|
||||||
|
// Step 3.1.
|
||||||
|
self.watching_advertisements.set(true);
|
||||||
|
// Step 3.2.
|
||||||
|
promise.resolve_native(promise_cx, &());
|
||||||
|
},
|
||||||
|
_ => promise.reject_error(promise_cx, Error::Type("Something went wrong...".to_owned())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ mod create;
|
||||||
pub mod bindings;
|
pub mod bindings;
|
||||||
pub mod blob;
|
pub mod blob;
|
||||||
pub mod bluetooth;
|
pub mod bluetooth;
|
||||||
pub mod bluetoothadvertisingdata;
|
pub mod bluetoothadvertisingevent;
|
||||||
pub mod bluetoothcharacteristicproperties;
|
pub mod bluetoothcharacteristicproperties;
|
||||||
pub mod bluetoothdevice;
|
pub mod bluetoothdevice;
|
||||||
pub mod bluetoothremotegattcharacteristic;
|
pub mod bluetoothremotegattcharacteristic;
|
||||||
|
|
|
@ -2,21 +2,32 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
//https://webbluetoothcg.github.io/web-bluetooth/#bluetoothadvertisingdata
|
// https://webbluetoothcg.github.io/web-bluetooth/#advertising-events
|
||||||
|
|
||||||
/*interface BluetoothManufacturerDataMap {
|
/*interface BluetoothManufacturerDataMap {
|
||||||
readonly maplike<unsigned short, DataView>;
|
readonly maplike<unsigned short, DataView>;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface BluetoothServiceDataMap {
|
interface BluetoothServiceDataMap {
|
||||||
readonly maplike<UUID, DataView>;
|
readonly maplike<UUID, DataView>;
|
||||||
};*/
|
};*/
|
||||||
|
[Pref="dom.bluetooth.enabled", Constructor(DOMString type, BluetoothAdvertisingEventInit init)]
|
||||||
[Pref="dom.bluetooth.enabled"]
|
interface BluetoothAdvertisingEvent : Event {
|
||||||
interface BluetoothAdvertisingData {
|
readonly attribute BluetoothDevice device;
|
||||||
|
// readonly attribute FrozenArray<UUID> uuids;
|
||||||
|
readonly attribute DOMString? name;
|
||||||
readonly attribute unsigned short? appearance;
|
readonly attribute unsigned short? appearance;
|
||||||
readonly attribute byte? txPower;
|
readonly attribute byte? txPower;
|
||||||
readonly attribute byte? rssi;
|
readonly attribute byte? rssi;
|
||||||
// readonly attribute BluetoothManufacturerDataMap manufacturerData;
|
// readonly attribute BluetoothManufacturerDataMap manufacturerData;
|
||||||
// readonly attribute BluetoothServiceDataMap serviceData;
|
// readonly attribute BluetoothServiceDataMap serviceData;
|
||||||
};
|
};
|
||||||
|
dictionary BluetoothAdvertisingEventInit : EventInit {
|
||||||
|
required BluetoothDevice device;
|
||||||
|
// sequence<(DOMString or unsigned long)> uuids;
|
||||||
|
DOMString name;
|
||||||
|
unsigned short appearance;
|
||||||
|
byte txPower;
|
||||||
|
byte rssi;
|
||||||
|
// Map manufacturerData;
|
||||||
|
// Map serviceData;
|
||||||
|
};
|
|
@ -8,13 +8,11 @@
|
||||||
interface BluetoothDevice : EventTarget {
|
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.
|
|
||||||
readonly attribute BluetoothAdvertisingData adData;
|
|
||||||
readonly attribute BluetoothRemoteGATTServer gatt;
|
readonly attribute BluetoothRemoteGATTServer gatt;
|
||||||
|
|
||||||
// Promise<void> watchAdvertisements();
|
Promise<void> watchAdvertisements();
|
||||||
// void unwatchAdvertisements();
|
void unwatchAdvertisements();
|
||||||
// readonly attribute boolean watchingAdvertisements;
|
readonly attribute boolean watchingAdvertisements;
|
||||||
};
|
};
|
||||||
|
|
||||||
[NoInterfaceObject]
|
[NoInterfaceObject]
|
||||||
|
|
|
@ -6734,6 +6734,12 @@
|
||||||
"url": "/_mozilla/mozilla/binding_keyword.html"
|
"url": "/_mozilla/mozilla/binding_keyword.html"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"mozilla/bluetooth/advertisingEvent/watchAdvertisements-succeeds.html": [
|
||||||
|
{
|
||||||
|
"path": "mozilla/bluetooth/advertisingEvent/watchAdvertisements-succeeds.html",
|
||||||
|
"url": "/_mozilla/mozilla/bluetooth/advertisingEvent/watchAdvertisements-succeeds.html"
|
||||||
|
}
|
||||||
|
],
|
||||||
"mozilla/bluetooth/connect/connection-succeeds.html": [
|
"mozilla/bluetooth/connect/connection-succeeds.html": [
|
||||||
{
|
{
|
||||||
"path": "mozilla/bluetooth/connect/connection-succeeds.html",
|
"path": "mozilla/bluetooth/connect/connection-succeeds.html",
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[watchAdvertisements-succeeds.html]
|
||||||
|
type: testharness
|
||||||
|
[watchAdvertisements should succeed.]
|
||||||
|
expected: FAIL
|
|
@ -0,0 +1,14 @@
|
||||||
|
<!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]}]
|
||||||
|
})
|
||||||
|
.then(device => device.watchAdvertisements());
|
||||||
|
}, 'watchAdvertisements should succeed.');
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue