aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bluetoothremotegattserver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/bluetoothremotegattserver.rs')
-rw-r--r--components/script/dom/bluetoothremotegattserver.rs31
1 files changed, 3 insertions, 28 deletions
diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs
index 06c11f0aa21..09da6a16e4b 100644
--- a/components/script/dom/bluetoothremotegattserver.rs
+++ b/components/script/dom/bluetoothremotegattserver.rs
@@ -11,10 +11,8 @@ use dom::bindings::error::Error::{self, Network, Security};
use dom::bindings::error::ErrorResult;
use dom::bindings::js::{JS, MutHeap, Root};
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
-use dom::bindings::str::DOMString;
use dom::bluetooth::{AsyncBluetoothListener, response_async};
use dom::bluetoothdevice::BluetoothDevice;
-use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
@@ -197,6 +195,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
fn handle_response(&self, response: BluetoothResponse, promise_cx: *mut JSContext, promise: &Rc<Promise>) {
+ let device = self.Device();
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
BluetoothResponse::GATTServerConnect(connected) => {
@@ -210,17 +209,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
// Step 7.
BluetoothResponse::GetPrimaryService(service) => {
- let context = self.device.get().get_context();
- let mut service_map = context.get_service_map().borrow_mut();
- if let Some(existing_service) = service_map.get(&service.instance_id) {
- promise.resolve_native(promise_cx, &existing_service.get());
- }
- let bt_service = BluetoothRemoteGATTService::new(&self.global(),
- &self.device.get(),
- DOMString::from(service.uuid),
- service.is_primary,
- service.instance_id.clone());
- service_map.insert(service.instance_id, MutHeap::new(&bt_service));
+ let bt_service = device.get_or_create_service(&service, &self);
promise.resolve_native(promise_cx, &bt_service);
},
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
@@ -228,22 +217,8 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
// Step 7.
BluetoothResponse::GetPrimaryServices(services_vec) => {
let mut services = vec!();
- let context = self.device.get().get_context();
- let mut service_map = context.get_service_map().borrow_mut();
for service in services_vec {
- let bt_service = match service_map.get(&service.instance_id) {
- Some(existing_service) => existing_service.get(),
- None => {
- BluetoothRemoteGATTService::new(&self.global(),
- &self.device.get(),
- DOMString::from(service.uuid),
- service.is_primary,
- service.instance_id.clone())
- },
- };
- if !service_map.contains_key(&service.instance_id) {
- service_map.insert(service.instance_id, MutHeap::new(&bt_service));
- }
+ let bt_service = device.get_or_create_service(&service, &self);
services.push(bt_service);
}
promise.resolve_native(promise_cx, &services);