From 35ca64559a6b2ed584a253547aa4f2c0322f3205 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 2 Jun 2025 17:03:04 +0800 Subject: [PATCH] bugfix --- bricks/binstreaming.js | 38 ++++++++++++++++++++++++++++++++++++++ bricks/build.sh | 2 +- bricks/camera.js | 4 ++++ bricks/input.js | 20 +++++++++++--------- bricks/video.js | 1 + 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/bricks/binstreaming.js b/bricks/binstreaming.js index ee6e36f..a344eb5 100644 --- a/bricks/binstreaming.js +++ b/bricks/binstreaming.js @@ -32,3 +32,41 @@ bricks.UpStreaming = class extends bricks.JsWidget { this.stream_ctlr = controller; } } + +bricks.down_streaming = function(widget, response) { + const reader = response.body.getReader(); + new ReadableStream({ + start(controller) { + function push() { + // 读取下一个数据块 + reader.read().then(({ done, value }) => { + if (done) { + // 如果读取完成,关闭流 + controller.close(); + return; + } + // 将数据块放入队列 + controller.enqueue(value); + push(); + }).catch(error => { + console.error('Error reading data', error); + controller.error(error); + }); + } + push(); + } + }) + .then(stream => { + // 将ReadableStream转换为Blob + return new Response(stream).blob(); + }) + .then(blob => { + const audioSrc = widget.set_url(URL.createObjectURL(blob)); + widget.bind('canplay', () => { + widget.play(); + }); + }) + .catch(error => { + console.error('Fetching audio stream failed', error); + }); +} diff --git a/bricks/build.sh b/bricks/build.sh index 78f050a..2b98cf0 100755 --- a/bricks/build.sh +++ b/bricks/build.sh @@ -8,7 +8,7 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \ floaticonbar.js miniform.js wterm.js dynamicaccordion.js \ binstreaming.js streaming_audio.js vadtext.js rtc.js \ llm_dialog.js llm.js websocket.js datarow.js tabular.js \ - line.js pie.js bar.js gobang.js period.js " + line.js pie.js bar.js gobang.js " echo ${SOURCES} cat ${SOURCES} > ../dist/bricks.js # uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js diff --git a/bricks/camera.js b/bricks/camera.js index 90c09eb..f35ae19 100644 --- a/bricks/camera.js +++ b/bricks/camera.js @@ -52,6 +52,10 @@ bricks.Camera = class extends bricks.Popup { this.task = schedule_once(this.show_picture.bind(this), this.task_period); } take_picture(){ + if (this.task){ + this.task.cancel(); + this.task = null; + } var d = this.imgw.base64(); this.dispatch('shot', d); // Create a blob from the canvas data URL diff --git a/bricks/input.js b/bricks/input.js index 8e959fd..c1815a6 100644 --- a/bricks/input.js +++ b/bricks/input.js @@ -366,16 +366,18 @@ bricks.UiImage =class extends bricks.VBox { "height":"90%", "width":"90%" }); - camera.bind('shot', function(d){ - if (this.imgw){ - this.remove_widget(this.imgw); - } - this.imgw = new bricks.Image({ - url:d, - width:'100%' - }); - this.add_widget(this.imgw); + camera.bring_to_top(); + camera.bind('shot', this.accept_photo.bind(this)); + } + accept_photo(url){ + if (this.imgw){ + this.remove_widget(this.imgw); + } + this.imgw = new bricks.Image({ + url:d, + width:'100%' }); + this.add_widget(this.imgw); } handleFileSelect(event){ const file = event.target.files[0]; diff --git a/bricks/video.js b/bricks/video.js index f9ba8c9..08bfe8d 100644 --- a/bricks/video.js +++ b/bricks/video.js @@ -63,6 +63,7 @@ bricks.Video = class extends bricks.Layout { } } auto_play(){ + return; schedule_once(this._auto_play.bind(this), 0.5); } _auto_play(){