mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add Start/Stop notifications
This commit is contained in:
parent
a89ba50180
commit
fd7cdbf19f
18 changed files with 364 additions and 4 deletions
|
@ -238,6 +238,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)
|
||||
}
|
||||
|
@ -940,4 +943,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