mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
requestDevice options (filters and optionalServices)
This commit is contained in:
parent
b01c52c18f
commit
66fbc4ac46
8 changed files with 361 additions and 81 deletions
|
@ -8,6 +8,7 @@ use device::bluetooth::BluetoothGATTCharacteristic;
|
||||||
use device::bluetooth::BluetoothGATTDescriptor;
|
use device::bluetooth::BluetoothGATTDescriptor;
|
||||||
use device::bluetooth::BluetoothGATTService;
|
use device::bluetooth::BluetoothGATTService;
|
||||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||||
|
use net_traits::bluetooth_scanfilter::{RequestDeviceoptions, matches_filters};
|
||||||
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -76,8 +77,8 @@ impl BluetoothManager {
|
||||||
fn start(&mut self) {
|
fn start(&mut self) {
|
||||||
loop {
|
loop {
|
||||||
match self.receiver.recv().unwrap() {
|
match self.receiver.recv().unwrap() {
|
||||||
BluetoothMethodMsg::RequestDevice(sender) => {
|
BluetoothMethodMsg::RequestDevice(options, sender) => {
|
||||||
self.request_device(sender)
|
self.request_device(options, sender)
|
||||||
}
|
}
|
||||||
BluetoothMethodMsg::GATTServerConnect(device_id, sender) => {
|
BluetoothMethodMsg::GATTServerConnect(device_id, sender) => {
|
||||||
self.gatt_server_connect(device_id, sender)
|
self.gatt_server_connect(device_id, sender)
|
||||||
|
@ -366,7 +367,9 @@ impl BluetoothManager {
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
|
|
||||||
fn request_device(&mut self, sender: IpcSender<BluetoothObjectMsg>) {
|
fn request_device(&mut self,
|
||||||
|
options: RequestDeviceoptions,
|
||||||
|
sender: IpcSender<BluetoothObjectMsg>) {
|
||||||
let mut adapter = match self.get_adapter() {
|
let mut adapter = match self.get_adapter() {
|
||||||
Some(a) => a,
|
Some(a) => a,
|
||||||
None => send_error!(sender, "No adapter found"),
|
None => send_error!(sender, "No adapter found"),
|
||||||
|
@ -376,9 +379,8 @@ impl BluetoothManager {
|
||||||
send_error!(sender, "No device found");
|
send_error!(sender, "No device found");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO select the proper device
|
match devices.into_iter().find(|ref d| matches_filters(d, options.get_filters())) {
|
||||||
let device = &devices[0];
|
Some(device) => {
|
||||||
|
|
||||||
let message = BluetoothObjectMsg::BluetoothDevice {
|
let message = BluetoothObjectMsg::BluetoothDevice {
|
||||||
id: device.get_address().unwrap_or("".to_owned()),
|
id: device.get_address().unwrap_or("".to_owned()),
|
||||||
name: device.get_name().ok(),
|
name: device.get_name().ok(),
|
||||||
|
@ -395,9 +397,12 @@ impl BluetoothManager {
|
||||||
rssi: match device.get_rssi() {
|
rssi: match device.get_rssi() {
|
||||||
Ok(p) => Some(p as i8),
|
Ok(p) => Some(p as i8),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
sender.send(message).unwrap();
|
sender.send(message).unwrap();
|
||||||
|
},
|
||||||
|
None => send_error!(sender, "No device found, that matches the given options"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gatt_server_connect(&mut self, device_id: String, sender: IpcSender<BluetoothObjectMsg>) {
|
pub fn gatt_server_connect(&mut self, device_id: String, sender: IpcSender<BluetoothObjectMsg>) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ path = "lib.rs"
|
||||||
util = {path = "../util"}
|
util = {path = "../util"}
|
||||||
msg = {path = "../msg"}
|
msg = {path = "../msg"}
|
||||||
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
|
ipc-channel = {git = "https://github.com/servo/ipc-channel"}
|
||||||
|
device = {git = "https://github.com/servo/devices"}
|
||||||
heapsize = "0.3.0"
|
heapsize = "0.3.0"
|
||||||
heapsize_plugin = "0.1.2"
|
heapsize_plugin = "0.1.2"
|
||||||
hyper = { version = "0.9", features = [ "serde-serialization" ] }
|
hyper = { version = "0.9", features = [ "serde-serialization" ] }
|
||||||
|
|
135
components/net_traits/bluetooth_scanfilter.rs
Normal file
135
components/net_traits/bluetooth_scanfilter.rs
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
/* 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 device::bluetooth::BluetoothDevice;
|
||||||
|
|
||||||
|
// A device name can never be longer than 29 bytes. An adv packet is at most
|
||||||
|
// 31 bytes long. The length and identifier of the length field take 2 bytes.
|
||||||
|
// That least 29 bytes for the name.
|
||||||
|
const MAX_NAME_LENGTH: usize = 29;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct ServiceUUIDSequence(Vec<String>);
|
||||||
|
|
||||||
|
impl ServiceUUIDSequence {
|
||||||
|
pub fn new(vec: Vec<String>) -> ServiceUUIDSequence {
|
||||||
|
ServiceUUIDSequence(vec)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_empty(&self) -> bool {
|
||||||
|
self.0.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct BluetoothScanfilter {
|
||||||
|
name: String,
|
||||||
|
name_prefix: String,
|
||||||
|
services: ServiceUUIDSequence,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BluetoothScanfilter {
|
||||||
|
fn is_empty_or_invalid_filter(&self) -> bool {
|
||||||
|
self.name.is_empty() &&
|
||||||
|
self.name_prefix.is_empty() &&
|
||||||
|
self.services.is_empty() &&
|
||||||
|
self.name.len() > MAX_NAME_LENGTH &&
|
||||||
|
self.name_prefix.len() > MAX_NAME_LENGTH
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(name: String, name_prefix: String, services: Vec<String>) -> BluetoothScanfilter {
|
||||||
|
BluetoothScanfilter {
|
||||||
|
name: name,
|
||||||
|
name_prefix: name_prefix,
|
||||||
|
services: ServiceUUIDSequence::new(services),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct BluetoothScanfilterSequence(Vec<BluetoothScanfilter>);
|
||||||
|
|
||||||
|
impl BluetoothScanfilterSequence {
|
||||||
|
pub fn new(vec: Vec<BluetoothScanfilter>) -> BluetoothScanfilterSequence {
|
||||||
|
BluetoothScanfilterSequence(vec)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BluetoothScanfilterSequence {
|
||||||
|
fn has_empty_or_invalid_filter(&self) -> bool {
|
||||||
|
self.0.is_empty() &&
|
||||||
|
self.0.iter().all(|x| !(x.is_empty_or_invalid_filter()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct RequestDeviceoptions {
|
||||||
|
filters: BluetoothScanfilterSequence,
|
||||||
|
optional_services: ServiceUUIDSequence,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RequestDeviceoptions {
|
||||||
|
pub fn new(filters: BluetoothScanfilterSequence,
|
||||||
|
services: ServiceUUIDSequence)
|
||||||
|
-> RequestDeviceoptions {
|
||||||
|
RequestDeviceoptions {
|
||||||
|
filters: filters,
|
||||||
|
optional_services: services,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_filters(&self) -> &BluetoothScanfilterSequence {
|
||||||
|
&self.filters
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn matches_filter(device: &BluetoothDevice, filter: &BluetoothScanfilter) -> bool {
|
||||||
|
if filter.is_empty_or_invalid_filter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !filter.name.is_empty() {
|
||||||
|
if let Ok(device_name) = device.get_name() {
|
||||||
|
if !device_name.eq(&filter.name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !filter.name_prefix.is_empty() {
|
||||||
|
if let Ok(device_name) = device.get_name() {
|
||||||
|
if !device_name.starts_with(&*filter.name_prefix) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !filter.services.is_empty() {
|
||||||
|
if let Ok(stringvec) = device.get_uuids() {
|
||||||
|
for service in &filter.services.0 {
|
||||||
|
if !stringvec.iter().any(|x| x == service) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn matches_filters(device: &BluetoothDevice, filters: &BluetoothScanfilterSequence) -> bool {
|
||||||
|
if filters.has_empty_or_invalid_filter() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for filter in &filters.0 {
|
||||||
|
if matches_filter(device, filter) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -1,11 +1,12 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* 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
|
* 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_scanfilter::RequestDeviceoptions;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub enum BluetoothMethodMsg {
|
pub enum BluetoothMethodMsg {
|
||||||
RequestDevice(IpcSender<BluetoothObjectMsg>),
|
RequestDevice(RequestDeviceoptions, IpcSender<BluetoothObjectMsg>),
|
||||||
GATTServerConnect(String, IpcSender<BluetoothObjectMsg>),
|
GATTServerConnect(String, IpcSender<BluetoothObjectMsg>),
|
||||||
GATTServerDisconnect(String, IpcSender<BluetoothObjectMsg>),
|
GATTServerDisconnect(String, IpcSender<BluetoothObjectMsg>),
|
||||||
GetPrimaryService(String, String, IpcSender<BluetoothObjectMsg>),
|
GetPrimaryService(String, String, IpcSender<BluetoothObjectMsg>),
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
|
extern crate device;
|
||||||
extern crate heapsize;
|
extern crate heapsize;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate image as piston_image;
|
extern crate image as piston_image;
|
||||||
|
@ -40,6 +41,7 @@ use std::thread;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use websocket::header;
|
use websocket::header;
|
||||||
|
|
||||||
|
pub mod bluetooth_scanfilter;
|
||||||
pub mod bluetooth_thread;
|
pub mod bluetooth_thread;
|
||||||
pub mod hosts;
|
pub mod hosts;
|
||||||
pub mod image_cache_thread;
|
pub mod image_cache_thread;
|
||||||
|
|
|
@ -2,18 +2,38 @@
|
||||||
* 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 core::clone::Clone;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothBinding;
|
use dom::bindings::codegen::Bindings::BluetoothBinding;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothBinding::BluetoothMethods;
|
use dom::bindings::codegen::Bindings::BluetoothBinding::RequestDeviceOptions;
|
||||||
|
use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothScanFilter, BluetoothMethods};
|
||||||
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::VendorIDSource;
|
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::VendorIDSource;
|
||||||
|
use dom::bindings::error::Error::Type;
|
||||||
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||||
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
||||||
use dom::bluetoothdevice::BluetoothDevice;
|
use dom::bluetoothdevice::BluetoothDevice;
|
||||||
|
use dom::bluetoothuuid::BluetoothUUID;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
|
use net_traits::bluetooth_scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence};
|
||||||
|
use net_traits::bluetooth_scanfilter::{RequestDeviceoptions, ServiceUUIDSequence};
|
||||||
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
// A device name can never be longer than 29 bytes. An adv packet is at most
|
||||||
|
// 31 bytes long. The length and identifier of the length field take 2 bytes.
|
||||||
|
// That least 29 bytes for the name.
|
||||||
|
const MAX_FILTER_NAME_LENGTH: usize = 29;
|
||||||
|
// 248 is the maximum number of UTF-8 code units in a Bluetooth Device Name.
|
||||||
|
const MAX_DEVICE_NAME_LENGTH: usize = 248;
|
||||||
|
const FILTER_EMPTY_ERROR: &'static str = "'filters' member must be non - empty to find any devices.";
|
||||||
|
const FILTER_ERROR: &'static str = "A filter must restrict the devices in some way.";
|
||||||
|
const FILTER_NAME_TOO_LONG_ERROR: &'static str = "A 'name' or 'namePrefix' can't be longer then 29 bytes.";
|
||||||
|
const NAME_PREFIX_ERROR: &'static str = "'namePrefix', if present, must be non - empty.";
|
||||||
|
const NAME_TOO_LONG_ERROR: &'static str = "A device name can't be longer than 248 bytes.";
|
||||||
|
const SERVICE_ERROR: &'static str = "'services', if present, must contain at least one service.";
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct Bluetooth {
|
pub struct Bluetooth {
|
||||||
|
@ -40,12 +60,115 @@ impl Bluetooth {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Clone for BluetoothScanFilter {
|
||||||
|
fn clone(&self) -> BluetoothScanFilter {
|
||||||
|
BluetoothScanFilter {
|
||||||
|
name: self.name.clone(),
|
||||||
|
namePrefix: self.namePrefix.clone(),
|
||||||
|
services: self.services.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for RequestDeviceOptions {
|
||||||
|
fn clone(&self) -> RequestDeviceOptions {
|
||||||
|
RequestDeviceOptions {
|
||||||
|
filters: self.filters.clone(),
|
||||||
|
optionalServices: self.optionalServices.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn canonicalize_filter(filter: &BluetoothScanFilter, global: GlobalRef)
|
||||||
|
-> Fallible<BluetoothScanfilter> {
|
||||||
|
if !(filter.services.is_some() ||
|
||||||
|
filter.name.is_some() ||
|
||||||
|
filter.namePrefix.is_some()) {
|
||||||
|
return Err(Type(FILTER_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut services_vec: Vec<String> = vec!();
|
||||||
|
if let Some(services) = filter.services.clone() {
|
||||||
|
if services.is_empty() {
|
||||||
|
return Err(Type(SERVICE_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
for service in services {
|
||||||
|
match BluetoothUUID::GetService(global, service) {
|
||||||
|
Ok(valid) => services_vec.push(valid.to_string()),
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut name = String::new();
|
||||||
|
if let Some(filter_name) = filter.name.clone() {
|
||||||
|
//NOTE: DOMString::len() gives back the size in bytes
|
||||||
|
if filter_name.len() > MAX_DEVICE_NAME_LENGTH {
|
||||||
|
return Err(Type(NAME_TOO_LONG_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
if filter_name.len() > MAX_FILTER_NAME_LENGTH {
|
||||||
|
return Err(Type(FILTER_NAME_TOO_LONG_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
name = filter_name.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut name_prefix = String::new();
|
||||||
|
if let Some(filter_name_prefix) = filter.namePrefix.clone() {
|
||||||
|
if filter_name_prefix.len() == 0 {
|
||||||
|
return Err(Type(NAME_PREFIX_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
if filter_name_prefix.len() > MAX_DEVICE_NAME_LENGTH {
|
||||||
|
return Err(Type(NAME_TOO_LONG_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
if filter_name_prefix.len() > MAX_FILTER_NAME_LENGTH {
|
||||||
|
return Err(Type(FILTER_NAME_TOO_LONG_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
name_prefix = filter_name_prefix.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(BluetoothScanfilter::new(name, name_prefix, services_vec))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn convert_request_device_options(options: &RequestDeviceOptions, global: GlobalRef)
|
||||||
|
-> Fallible<RequestDeviceoptions> {
|
||||||
|
if options.filters.is_empty() {
|
||||||
|
return Err(Type(FILTER_EMPTY_ERROR.to_owned()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut filters = vec!();
|
||||||
|
for filter in &options.filters {
|
||||||
|
match canonicalize_filter(&filter, global) {
|
||||||
|
Ok(canonicalized_filter) => filters.push(canonicalized_filter),
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut optional_services = vec!();
|
||||||
|
if let Some(opt_services) = options.optionalServices.clone() {
|
||||||
|
for opt_service in opt_services {
|
||||||
|
match BluetoothUUID::GetService(global, opt_service) {
|
||||||
|
Ok(valid_service) => optional_services.push(valid_service.to_string()),
|
||||||
|
Err(err) => return Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(RequestDeviceoptions::new(BluetoothScanfilterSequence::new(filters),
|
||||||
|
ServiceUUIDSequence::new(optional_services)))
|
||||||
|
}
|
||||||
|
|
||||||
impl BluetoothMethods for Bluetooth {
|
impl BluetoothMethods for Bluetooth {
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
|
||||||
fn RequestDevice(&self) -> Option<Root<BluetoothDevice>> {
|
fn RequestDevice(&self,
|
||||||
|
option: &RequestDeviceOptions)
|
||||||
|
-> Fallible<Root<BluetoothDevice>> {
|
||||||
let (sender, receiver) = ipc::channel().unwrap();
|
let (sender, receiver) = ipc::channel().unwrap();
|
||||||
self.get_bluetooth_thread().send(BluetoothMethodMsg::RequestDevice(sender)).unwrap();
|
match convert_request_device_options(option, self.global().r()) {
|
||||||
|
Ok(option) => {
|
||||||
|
self.get_bluetooth_thread()
|
||||||
|
.send(BluetoothMethodMsg::RequestDevice(option, sender))
|
||||||
|
.unwrap();
|
||||||
let device = receiver.recv().unwrap();
|
let device = receiver.recv().unwrap();
|
||||||
match device {
|
match device {
|
||||||
BluetoothObjectMsg::BluetoothDevice {
|
BluetoothObjectMsg::BluetoothDevice {
|
||||||
|
@ -76,7 +199,7 @@ impl BluetoothMethods for Bluetooth {
|
||||||
Some(n) => Some(DOMString::from(n)),
|
Some(n) => Some(DOMString::from(n)),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
Some(BluetoothDevice::new(self.global().r(),
|
Ok(BluetoothDevice::new(self.global().r(),
|
||||||
DOMString::from(id),
|
DOMString::from(id),
|
||||||
name,
|
name,
|
||||||
ad_data,
|
ad_data,
|
||||||
|
@ -88,11 +211,11 @@ impl BluetoothMethods for Bluetooth {
|
||||||
},
|
},
|
||||||
BluetoothObjectMsg::Error {
|
BluetoothObjectMsg::Error {
|
||||||
error
|
error
|
||||||
} => {
|
} => return Err(Type(error)),
|
||||||
println!("{}", error);
|
|
||||||
None
|
|
||||||
},
|
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,22 @@
|
||||||
|
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
||||||
|
|
||||||
|
dictionary BluetoothScanFilter {
|
||||||
|
sequence<BluetoothServiceUUID> services;
|
||||||
|
DOMString name;
|
||||||
|
DOMString namePrefix;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary RequestDeviceOptions {
|
||||||
|
required sequence<BluetoothScanFilter> filters;
|
||||||
|
sequence<BluetoothServiceUUID> optionalServices /*= []*/;
|
||||||
|
};
|
||||||
|
|
||||||
[Pref="dom.bluetooth.enabled"]
|
[Pref="dom.bluetooth.enabled"]
|
||||||
interface Bluetooth {
|
interface Bluetooth {
|
||||||
// Promise<BluetoothDevice> requestDevice(RequestDeviceOptions options);
|
// Promise<BluetoothDevice> requestDevice(RequestDeviceOptions options);
|
||||||
BluetoothDevice? requestDevice(/*RequestDeviceOptions options*/);
|
[Throws]
|
||||||
|
BluetoothDevice requestDevice(RequestDeviceOptions options);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Bluetooth implements EventTarget;
|
// Bluetooth implements EventTarget;
|
||||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -1394,6 +1394,7 @@ dependencies = [
|
||||||
name = "net_traits"
|
name = "net_traits"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"device 0.0.1 (git+https://github.com/dati91/devices?branch=device-api)",
|
||||||
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"heapsize_plugin 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize_plugin 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue