mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #14276 - szeged:notify, r=jdm
Add Start/Stop notifications Add support for Start and Stop Notifications for WebBluetooth --- - [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 <!-- 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/14276) <!-- Reviewable:end -->
This commit is contained in:
commit
c4b7cc863e
18 changed files with 364 additions and 4 deletions
|
@ -275,6 +275,9 @@ impl BluetoothManager {
|
|||
BluetoothRequest::WriteValue(id, value, sender) => {
|
||||
self.write_value(id, value, sender)
|
||||
},
|
||||
BluetoothRequest::EnableNotification(id, enable, sender) => {
|
||||
self.enable_notification(id, enable, sender)
|
||||
},
|
||||
BluetoothRequest::Test(data_set_name, sender) => {
|
||||
self.test(data_set_name, sender)
|
||||
}
|
||||
|
@ -977,4 +980,25 @@ impl BluetoothManager {
|
|||
None => return drop(sender.send(Err(BluetoothError::InvalidState))),
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications
|
||||
fn enable_notification(&mut self, id: String, enable: bool, sender: IpcSender<BluetoothResponseResult>) {
|
||||
let mut adapter = get_adapter_or_return_error!(self, sender);
|
||||
match self.get_gatt_characteristic(&mut adapter, &id) {
|
||||
Some(c) => {
|
||||
let result = match enable {
|
||||
true => c.start_notify(),
|
||||
false => c.stop_notify(),
|
||||
};
|
||||
match result {
|
||||
// Step 11.
|
||||
Ok(_) => return drop(sender.send(Ok(BluetoothResponse::EnableNotification(())))),
|
||||
// Step 4.
|
||||
Err(_) => return drop(sender.send(Err(BluetoothError::NotSupported))),
|
||||
}
|
||||
},
|
||||
// Step 3.
|
||||
None => return drop(sender.send(Err(BluetoothError::InvalidState))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue