This commit is contained in:
yumoqing 2025-04-12 22:10:49 +08:00
parent 7a3e352284
commit 36d9572bea
2 changed files with 40 additions and 22 deletions

View File

@ -1,10 +1,10 @@
bricks = window.bricks || {};
bricks.QAFrame = class extends bricks.PopupWindow {
bricks.QAFrame = class extends bricks.VBox {
/*
{
ws_url:
ws_opts:
ws_params:
title:
description:
courseware:{
@ -30,15 +30,26 @@ bricks.QAFrame = class extends bricks.PopupWindow {
this.add_widget(this.bottom_w);
var url = this.ws_url;
if (this.ws_params){
url += '?' + URLSearchParams(this.ws_params).toString();
url += '?' + new URLSearchParams(this.ws_params).toString();
}
this.ws = new bricks.WebSocket(url);
this.ws = new bricks.WebSocket({
ws_url:url
});
this.ws.bind('onopen', this.start_question_answer.bind(this));
this.ws.bind('onquestion', this.show_question.bind(this));
this.ws.bind('oncourseware', this.show_courseware.bind(this));
if (this.courseware){
this.play_course();
} else {
this.show_conform();
}
}
show_question(d){
console.log('show_question(), d=', d);
}
show_courseware(d){
console.log('show_courseware(), d=', d);
}
show_conform(){
var btn = new bricks.Button({
label: 'Start ?'
@ -58,7 +69,10 @@ bricks.QAFrame = class extends bricks.PopupWindow {
this.main_w.clear_widgets();
var d = {
'type': 'qa_start',
'data': null
'data': {
d: 'test data',
v: 100
}
};
this.ws.send(d)
}

View File

@ -22,24 +22,28 @@ bricks.WebSocket = class extends bricks.VBox {
} else {
this.ws = new WebSocket(this.ws_url);
}
this.ws.onopen = function(){
this.ws.onopen = this.on_open.bind(this);
this.ws.onmessage = this.on_message.bind(this);
this.ws.onclose = this.on_close.bind(this);
this.ws.onerror = this.on_error.bind(this);
}
on_open(e){
this.dispatch('onopen');
console.log("open");
}
this.ws.onclose = function(e){
on_close(e){
this.dispatch('onclose');
console.log("close");
}
this.ws.onerror = function(e){
on_error(e){
this.dispatch('onerror');
console.log(error);
}
this.ws.onmessage = function(e){
on_message(e){
var d = JSON.parse(e.data);
var eventname = 'on' + d.type;
this.dispatch(eventname, d.data);
}
}
send_text(text){
var d = {
type: "text",