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:
@@ -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`
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user