aboutsummaryrefslogtreecommitdiff
path: root/web/bumble.js
diff options
context:
space:
mode:
Diffstat (limited to 'web/bumble.js')
-rw-r--r--web/bumble.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/web/bumble.js b/web/bumble.js
index cb807eb..c554bc2 100644
--- a/web/bumble.js
+++ b/web/bumble.js
@@ -24,6 +24,11 @@ class PacketSource {
}
class PacketSink {
+ constructor() {
+ this.queue = [];
+ this.isProcessing = false;
+ }
+
on_packet(packet) {
if (!this.writer) {
return;
@@ -31,11 +36,24 @@ class PacketSink {
const buffer = packet.toJs({create_proxies : false});
packet.destroy();
//console.log(`HCI[host->controller]: ${bufferToHex(buffer)}`);
- // TODO: create an async queue here instead of blindly calling write without awaiting
- this.writer(buffer);
+ this.queue.push(buffer);
+ this.processQueue();
+ }
+
+ async processQueue() {
+ if (this.isProcessing) {
+ return;
+ }
+ this.isProcessing = true;
+ while (this.queue.length > 0) {
+ const buffer = this.queue.shift();
+ await this.writer(buffer);
+ }
+ this.isProcessing = false;
}
}
+
class LogEvent extends Event {
constructor(message) {
super('log');
@@ -185,4 +203,4 @@ export async function setupSimpleApp(appUrl, bumbleControls, log) {
bumbleControls.onBumbleLoaded();
return app;
-} \ No newline at end of file
+}