bugfix
This commit is contained in:
parent
999c9ba93e
commit
5eb2e6e35e
@ -7,7 +7,7 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \
|
|||||||
paging.js datagrid.js iframe.js cols.js echartsext.js \
|
paging.js datagrid.js iframe.js cols.js echartsext.js \
|
||||||
floaticonbar.js miniform.js wterm.js dynamicaccordion.js \
|
floaticonbar.js miniform.js wterm.js dynamicaccordion.js \
|
||||||
binstreaming.js streaming_audio.js vadtext.js rtc.js docxviewer.js \
|
binstreaming.js streaming_audio.js vadtext.js rtc.js docxviewer.js \
|
||||||
llm_dialog.js llm.js websocket.js datarow.js tabular.js \
|
llm_dialog.js llm.js websocket.js datarow.js tabular.js continueaudio.js \
|
||||||
line.js pie.js bar.js gobang.js period.js iconbarpage.js \
|
line.js pie.js bar.js gobang.js period.js iconbarpage.js \
|
||||||
keypress.js asr.js webspeech.js countdown.js progressbar.js "
|
keypress.js asr.js webspeech.js countdown.js progressbar.js "
|
||||||
echo ${SOURCES}
|
echo ${SOURCES}
|
||||||
|
@ -9,6 +9,8 @@ bricks.Camera = class extends bricks.Popup {
|
|||||||
opts.fps = opts.fps || 60;
|
opts.fps = opts.fps || 60;
|
||||||
opts.auto_dismiss = false;
|
opts.auto_dismiss = false;
|
||||||
super(opts);
|
super(opts);
|
||||||
|
this.recordedChunks = [];
|
||||||
|
this.mediaRecorder = null;
|
||||||
this.stream = null;
|
this.stream = null;
|
||||||
this.video = document.createElement('video');
|
this.video = document.createElement('video');
|
||||||
var filler = new bricks.Filler({});
|
var filler = new bricks.Filler({});
|
||||||
@ -83,6 +85,31 @@ bricks.Camera = class extends bricks.Popup {
|
|||||||
this.task = schedule_once(this.show_picture.bind(this), this.task_period);
|
this.task = schedule_once(this.show_picture.bind(this), this.task_period);
|
||||||
this.show_cnt += 1;
|
this.show_cnt += 1;
|
||||||
}
|
}
|
||||||
|
videorecorder_start(){
|
||||||
|
if (!this.stream) {
|
||||||
|
throw new Error('Media stream is not initialized. Call init() first.');
|
||||||
|
}
|
||||||
|
this.recordedChunks = [];
|
||||||
|
this.mediaRecorder = new MediaRecorder(this.stream);
|
||||||
|
this.mediaRecorder.ondataavailable = (event) => {
|
||||||
|
if (event.data.size > 0) {
|
||||||
|
this.recordedChunks.push(event.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.mediaRecorder.start();
|
||||||
|
}
|
||||||
|
videorecorder_stop(){
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.mediaRecorder.onstop = () => {
|
||||||
|
const blob = new Blob(this.recordedChunks, { type: 'video/webm' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
resolve({ blob, url });
|
||||||
|
};
|
||||||
|
this.mediaRecorder.stop();
|
||||||
|
this.mediaRecorder = null;
|
||||||
|
this.recordedChunks = [];
|
||||||
|
});
|
||||||
|
}
|
||||||
take_picture(event){
|
take_picture(event){
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if (this.task){
|
if (this.task){
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
var bricks = window.bricks || {};
|
var bricks = window.bricks || {};
|
||||||
|
|
||||||
bricks.ContinueAudioPlayer = class extends class bricks.VBox {
|
bricks.ContinueAudioPlayer = class extends bricks.VBox {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
this.ws_url = options.ws_url;
|
this.ws_url = options.ws_url;
|
||||||
|
@ -1,52 +1,75 @@
|
|||||||
var bricks = window.bricks || {}
|
var bricks = window.bricks || {}
|
||||||
bricks.WebSocket = class extends bricks.VBox {
|
bricks.WebSocket = class extends bricks.VBox {
|
||||||
|
/*
|
||||||
|
options = {
|
||||||
|
ws_url:
|
||||||
|
with_session:
|
||||||
|
}
|
||||||
|
event:
|
||||||
|
onopen:
|
||||||
|
onmessage:
|
||||||
|
onerror:
|
||||||
|
onclose:
|
||||||
|
ontext:
|
||||||
|
onbase64audio
|
||||||
|
onbase64video
|
||||||
|
*/
|
||||||
constructor(opts){
|
constructor(opts){
|
||||||
super(opts);
|
super(opts);
|
||||||
this.dialog = new bricks.VScrollPanel({})
|
if (opts.with_session){
|
||||||
this.dialog.set_css('filler')
|
var session = bricks.app.get_session();
|
||||||
this.input = new bricks.UiStr({
|
this.ws = new WebSocket(this.ws_url, sessopn);
|
||||||
name:'prompt',
|
} else {
|
||||||
label:'Say something'
|
this.ws = new WebSocket(this.ws_url, sessopn);
|
||||||
});
|
}
|
||||||
this.add_widget(this.dialog);
|
|
||||||
this.add_widget(this.input);
|
|
||||||
this.input.bind('keypress', this.check_keypress.bind(this));
|
|
||||||
this.ws = new WebSocket(this.ws_url);
|
|
||||||
this.ws.onopen = function(){
|
this.ws.onopen = function(){
|
||||||
|
this.dispatch('onopen');
|
||||||
console.log("open");
|
console.log("open");
|
||||||
}
|
}
|
||||||
this.ws.onclose = function(e){
|
this.ws.onclose = function(e){
|
||||||
//当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
this.dispatch('onclose');
|
||||||
console.log("close");
|
console.log("close");
|
||||||
}
|
}
|
||||||
this.ws.onerror = function(e){
|
this.ws.onerror = function(e){
|
||||||
//如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
|
this.dispatch('onerror');
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
this.ws.onmessage = this.show_response.bind(this);
|
this.ws.onmessage = function(e){
|
||||||
}
|
var d = JSON.parse(e.data);
|
||||||
check_keypress(e){
|
var eventname = 'on' + d.type;
|
||||||
if (e.key == 'Enter'){
|
this.dispatch(eventname, d.data);
|
||||||
var v = this.input.getValue();
|
|
||||||
var s = v.prompt;
|
|
||||||
console.log('check_keypress()', v, s);
|
|
||||||
if (s != ''){
|
|
||||||
this.show_input(s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show_input(s){
|
send_text(text){
|
||||||
var w = new bricks.MdWidget({mdtext:s});
|
var d = {
|
||||||
w.set_css('user_msg');
|
type: "text",
|
||||||
this.dialog.add_widget(w);
|
data: text
|
||||||
this.ws.send(s);
|
}
|
||||||
|
this.send(d);
|
||||||
}
|
}
|
||||||
show_response(e){
|
send_base64_video(b64video){
|
||||||
var d = JSON.parse(e.data);
|
var d = {
|
||||||
console.log(e.data, d.type, d.data, d);
|
type: "base64video",
|
||||||
var w = new bricks.MdWidget({mdtext:d.data});
|
data: b64video
|
||||||
w.set_css('llm_msg');
|
}
|
||||||
this.dialog.add_widget(w);
|
this.send(d);
|
||||||
|
}
|
||||||
|
send_base64_audio(b64audio){
|
||||||
|
var d = {
|
||||||
|
type: "base64audio",
|
||||||
|
data: b64audio
|
||||||
|
}
|
||||||
|
this.send(d);
|
||||||
|
}
|
||||||
|
send(d){
|
||||||
|
/* d is a object:
|
||||||
|
{
|
||||||
|
type:
|
||||||
|
data:
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
var s = JSON.stringify(d);
|
||||||
|
this.ws.send(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bricks.Factory.register('WebSocket', bricks.WebSocket);
|
bricks.Factory.register('WebSocket', bricks.WebSocket);
|
||||||
|
Loading…
Reference in New Issue
Block a user