This commit is contained in:
yumoqing 2025-06-02 17:03:04 +08:00
parent dc4f4e86c1
commit 35ca64559a
5 changed files with 55 additions and 10 deletions

View File

@ -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);
});
}

View File

@ -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

View File

@ -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

View File

@ -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];

View File

@ -63,6 +63,7 @@ bricks.Video = class extends bricks.Layout {
}
}
auto_play(){
return;
schedule_once(this._auto_play.bind(this), 0.5);
}
_auto_play(){