diff options
author | Attila Dusnoki <dati91@gmail.com> | 2016-11-14 17:51:41 +0100 |
---|---|---|
committer | Keith Yeung <kungfukeith11@gmail.com> | 2016-11-23 01:24:33 -0800 |
commit | fd7cdbf19fd4ad6ddb173d4b4061c3098ef29520 (patch) | |
tree | d1e962d51dfb16a5826cf9c9c353d31d3e3c2b8b /components/script/dom/bluetoothremotegattcharacteristic.rs | |
parent | a89ba50180532bc652db7ff649f252ffdca33177 (diff) | |
download | servo-fd7cdbf19fd4ad6ddb173d4b4061c3098ef29520.tar.gz servo-fd7cdbf19fd4ad6ddb173d4b4061c3098ef29520.zip |
Add Start/Stop notifications
Diffstat (limited to 'components/script/dom/bluetoothremotegattcharacteristic.rs')
-rw-r--r-- | components/script/dom/bluetoothremotegattcharacteristic.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index dae5fd3e558..390878342db 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -214,6 +214,47 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap(); return p; } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications + fn StartNotifications(&self) -> Rc<Promise> { + let p = Promise::new(&self.global()); + let p_cx = p.global().get_cx(); + // Step 1. + if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) { + p.reject_error(p_cx, Security); + return p; + } + // Step 3. + if !(self.Properties().Notify() || + self.Properties().Indicate()) { + p.reject_error(p_cx, NotSupported); + return p; + } + // Step 6. + if !self.Service().Device().Gatt().Connected() { + p.reject_error(p_cx, Network); + return p; + } + let sender = response_async(&p, self); + self.get_bluetooth_thread().send( + BluetoothRequest::EnableNotification(self.get_instance_id(), + true, + sender)).unwrap(); + return p; + } + + #[allow(unrooted_must_root)] + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-stopnotifications + fn StopNotifications(&self) -> Rc<Promise> { + let p = Promise::new(&self.global()); + let sender = response_async(&p, self); + self.get_bluetooth_thread().send( + BluetoothRequest::EnableNotification(self.get_instance_id(), + false, + sender)).unwrap(); + return p; + } } impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic { @@ -263,6 +304,9 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic { *self.value.borrow_mut() = Some(value.clone()); promise.resolve_native(promise_cx, &value); }, + BluetoothResponse::EnableNotification(_result) => { + promise.resolve_native(promise_cx, self); + }, _ => promise.reject_error(promise_cx, Error::Type("Something went wrong...".to_owned())), } } |