Add clear queue api (#171)

* Add clear queue api

* Minor improvement

* Update changelog

---------

Co-authored-by: Foti Dim <foti@navideck.com>
This commit is contained in:
Rohit Sangwan
2025-07-16 16:06:39 +05:30
committed by GitHub
parent 0f4bae71e1
commit 71e19988a9
4 changed files with 25 additions and 0 deletions
+1
View File
@@ -1,6 +1,7 @@
## 0.21.0
* BREAKING CHANGE: `connectionTimeout` argument from `connect`, `isPaired` and `pair` API renamed to `timeout`
* Add `timeout` argument to all APIs
* Add `clearQueue()` API
## 0.20.2
* Fix `BleCharacteristic.onValueReceived`
+8
View File
@@ -420,6 +420,14 @@ UniversalBle.onQueueUpdate = (String id, int remainingItems) {
};
```
To clear the queue:
```dart
/// Use [BleCommandQueue.globalQueueId] to clear the global queue.
/// To clear the queue of a specific device, use `deviceId` as [id].
/// If no [id] is provided, all queues will be cleared.
UniversalBle.clearQueue(BleCommandQueue.globalQueueId);
```
## Timeout
By default, all commands have a global timeout of 10 seconds.
+6
View File
@@ -414,6 +414,12 @@ class UniversalBle {
);
}
/// Clear a queue.
/// Use [BleCommandQueue.globalQueueId] to clear the global queue.
/// To clear the queue of a specific device, use `deviceId` as [id].
/// If no [id] is provided, all queues will be cleared.
static void clearQueue([String? id]) => _bleCommandQueue.clearQueue(id);
/// [receivesAdvertisements] returns true on web if the browser supports receiving advertisements from a certain `deviceId`.
/// The rest of the platforms will always return true.
/// If true, then you will be getting scanResult updates for this device.
+10
View File
@@ -51,4 +51,14 @@ class BleCommandQueue {
_queueMap[id] = queue;
return queue;
}
void clearQueue(String? id) {
if (id == null) {
_queueMap.forEach((k, v) => v.dispose());
_queueMap.clear();
} else {
_queueMap[id]?.dispose();
_queueMap.remove(id);
}
}
}