bugfix
This commit is contained in:
parent
6bd9c1f53a
commit
c5812e8762
0
bricks/audio.js
Executable file → Normal file
0
bricks/audio.js
Executable file → Normal file
0
bricks/baseKnowledge.txt
Executable file → Normal file
0
bricks/baseKnowledge.txt
Executable file → Normal file
19
bricks/bricks.js
Executable file → Normal file
19
bricks/bricks.js
Executable file → Normal file
@ -484,8 +484,27 @@ bricks.App = class extends bricks.Layout {
|
|||||||
this.add_widget(this.tooltip);
|
this.add_widget(this.tooltip);
|
||||||
this._Width = this.dom_element.offsetWidth;
|
this._Width = this.dom_element.offsetWidth;
|
||||||
this._Height = this.dom_element.offsetHeight;
|
this._Height = this.dom_element.offsetHeight;
|
||||||
|
this.video_stream = null;
|
||||||
|
this.audio_stream = null;
|
||||||
document.addEventListener('keydown', this.key_down_action.bind(this));
|
document.addEventListener('keydown', this.key_down_action.bind(this));
|
||||||
}
|
}
|
||||||
|
async start_camera() {
|
||||||
|
if (this.video_stream) return;
|
||||||
|
if (navigator.mediaDevices.getUserMedia) {
|
||||||
|
this.video_stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
||||||
|
} else {
|
||||||
|
console.log("Webcam access is not supported in this browser.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async start_mic() {
|
||||||
|
if (this.audio_stream) return;
|
||||||
|
if (navigator.mediaDevices.getUserMedia) {
|
||||||
|
this.audio_stream = navigator.mediaDevices.getUserMedia({ audio: true });
|
||||||
|
} else {
|
||||||
|
console.log("mic access is not supported in this browser.");
|
||||||
|
this.stream = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
new_zindex(){
|
new_zindex(){
|
||||||
const v = this.zindex;
|
const v = this.zindex;
|
||||||
this.zindex = v + 1;
|
this.zindex = v + 1;
|
||||||
|
2
bricks/build.sh
Executable file → Normal file
2
bricks/build.sh
Executable file → Normal file
@ -1,6 +1,6 @@
|
|||||||
SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \
|
SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \
|
||||||
i18n.js widget.js layout.js bricks.js image.js html.js splitter.js \
|
i18n.js widget.js layout.js bricks.js image.js html.js splitter.js \
|
||||||
jsoncall.js myoperator.js scroll.js menu.js popup.js modal.js running.js \
|
jsoncall.js myoperator.js scroll.js menu.js popup.js camera.js modal.js running.js \
|
||||||
markdown_viewer.js video.js audio.js toolbar.js tab.js \
|
markdown_viewer.js video.js audio.js toolbar.js tab.js \
|
||||||
input.js registerfunction.js button.js accordion.js dataviewer.js \
|
input.js registerfunction.js button.js accordion.js dataviewer.js \
|
||||||
tree.js multiple_state_image.js dynamiccolumn.js form.js message.js conform.js \
|
tree.js multiple_state_image.js dynamiccolumn.js form.js message.js conform.js \
|
||||||
|
@ -8,68 +8,53 @@ bricks.Camera = class extends bricks.Popup {
|
|||||||
opts.fps = opts.fps || 60;
|
opts.fps = opts.fps || 60;
|
||||||
super(opts);
|
super(opts);
|
||||||
this.stream = null;
|
this.stream = null;
|
||||||
startCamera();
|
this.video = document.createElement('video');
|
||||||
if (this.stream) {
|
var filler = new bricks.Filler({});
|
||||||
this.video = document.createElement('video');
|
var hbox = new bricks.HBox({
|
||||||
this.video.srcObject = this.stream;
|
cheight:2
|
||||||
this.video.play();
|
});
|
||||||
var filler = new bricks.Filler({});
|
this.add_widget(filler);
|
||||||
var hbox = new bricks.HBox({
|
this.add_widget(hbox);
|
||||||
cheight:2
|
var shot_btn = new bricks.Icon({
|
||||||
});
|
url:bricks_resource('imgs/camera.png'),
|
||||||
this.add_widget(filler);
|
rate:1.5
|
||||||
this.add_widget(hbox);
|
});
|
||||||
shot_btn = new bricks.Icon({
|
var del_btn = new bricks.Icon({
|
||||||
url:bricks_resource('imgs/camera.png'),
|
url:bricks_resource('imgs/delete.png'),
|
||||||
rate:1.5
|
rate:1.5
|
||||||
});
|
})
|
||||||
del_btn = new bricks.Icon({
|
del_btn.bind('click', this.dismiss.bind(this));
|
||||||
url:bricks_resource('imgs/delete.png'),
|
shot_btn.bind('click', this.take_picture.bind(this));
|
||||||
rate:1.5
|
this.imgw = new bricks.Image({
|
||||||
})
|
width:'100%'
|
||||||
del_btn.bind('click', function(){
|
});
|
||||||
this.dismiss();
|
hbox.add_widget(shot_btn);
|
||||||
});
|
hbox.add_widget(del_btn);
|
||||||
shot.bind('click', function(){
|
filler.add_widget(this.imgw);
|
||||||
this.take_photo();
|
this.task_period = 1 / this.fps;
|
||||||
});
|
schedule_once(this.startCamera.bind(this), 0.3);
|
||||||
this.imgw = new bricks.Image({
|
|
||||||
width:'100%'
|
|
||||||
});
|
|
||||||
hbox.add_widget(shot_btn);
|
|
||||||
hbox.add_widget(del_btn);
|
|
||||||
filler.add_widget(this.ingw);
|
|
||||||
this.task_period = 1 / this.fps;
|
|
||||||
this.task = schedule_once(this.show_picture, this.task_period);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
startCamera() {
|
async startCamera() {
|
||||||
if (navigator.mediaDevices.getUserMedia) {
|
await bricks.app.start_camera();
|
||||||
navigator.mediaDevices.getUserMedia({ video: true })
|
this.stream = bricks.app.video_stream;
|
||||||
.then(function(stream) {
|
this.video.srcObject = this.stream;
|
||||||
this.stream = stream;
|
this.video.play();
|
||||||
})
|
this.task = schedule_once(this.show_picture.bind(this), this.task_period);
|
||||||
.catch(function(err) {
|
|
||||||
console.error("Error accessing webcam:", err);
|
|
||||||
this.stream = null;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log("Webcam access is not supported in this browser.");
|
|
||||||
this.stream = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
show_picture(){
|
show_picture(){
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
canvas.height = this.video.videoHeight;
|
canvas.height = this.video.videoHeight;
|
||||||
canvas.width = this.video.videoWidth;
|
canvas.width = this.video.videoWidth;
|
||||||
const context = this.canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
context.drawImage(this.video, 0, 0);
|
context.drawImage(this.video, 0, 0);
|
||||||
this.imgs.set_url(canvas.toDataURL('image/jpeg'));
|
this.imgw.set_url(canvas.toDataURL('image/jpeg'));
|
||||||
this.task = schedule_once(this.show_picture, this.task_period);
|
this.task = schedule_once(this.show_picture.bind(this), this.task_period);
|
||||||
}
|
}
|
||||||
take_picture(){
|
take_picture(){
|
||||||
var d = this.imgs.base64();
|
var d = this.imgw.base64();
|
||||||
this.dispatch('shot', d);
|
this.dispatch('shot', d);
|
||||||
// Create a blob from the canvas data URL
|
// Create a blob from the canvas data URL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bricks.Factory.register('Camera', bricks.Camera);
|
||||||
|
0
bricks/factory.js
Executable file → Normal file
0
bricks/factory.js
Executable file → Normal file
0
bricks/i18n.js
Executable file → Normal file
0
bricks/i18n.js
Executable file → Normal file
0
bricks/image.js
Executable file → Normal file
0
bricks/image.js
Executable file → Normal file
0
bricks/input.js
Executable file → Normal file
0
bricks/input.js
Executable file → Normal file
0
bricks/jsoncall.js
Executable file → Normal file
0
bricks/jsoncall.js
Executable file → Normal file
0
bricks/layout.js
Executable file → Normal file
0
bricks/layout.js
Executable file → Normal file
0
bricks/markdown_viewer.js
Executable file → Normal file
0
bricks/markdown_viewer.js
Executable file → Normal file
0
bricks/menu.js
Executable file → Normal file
0
bricks/menu.js
Executable file → Normal file
0
bricks/minify_tools.txt
Executable file → Normal file
0
bricks/minify_tools.txt
Executable file → Normal file
0
bricks/modal.js
Executable file → Normal file
0
bricks/modal.js
Executable file → Normal file
0
bricks/myoperator.js
Executable file → Normal file
0
bricks/myoperator.js
Executable file → Normal file
0
bricks/registerfunction.js
Executable file → Normal file
0
bricks/registerfunction.js
Executable file → Normal file
0
bricks/tab.js
Executable file → Normal file
0
bricks/tab.js
Executable file → Normal file
0
bricks/toolbar.js
Executable file → Normal file
0
bricks/toolbar.js
Executable file → Normal file
0
bricks/tree.js
Executable file → Normal file
0
bricks/tree.js
Executable file → Normal file
0
bricks/uitypesdef.js
Executable file → Normal file
0
bricks/uitypesdef.js
Executable file → Normal file
0
bricks/utils.js
Executable file → Normal file
0
bricks/utils.js
Executable file → Normal file
0
bricks/video.js
Executable file → Normal file
0
bricks/video.js
Executable file → Normal file
0
bricks/widget.js
Executable file → Normal file
0
bricks/widget.js
Executable file → Normal file
29
examples/camera.ui
Normal file
29
examples/camera.ui
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"widgettype":"HBox",
|
||||||
|
"options":{
|
||||||
|
"widht":"100%",
|
||||||
|
"height":"100%"
|
||||||
|
},
|
||||||
|
"subwidgets":[
|
||||||
|
{
|
||||||
|
"widgettype":"Camera",
|
||||||
|
"options":{
|
||||||
|
"width":"50%",
|
||||||
|
"height":"90%",
|
||||||
|
"archor":"cl",
|
||||||
|
"auto_open":true,
|
||||||
|
"fps":60
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"widgettype":"Camera",
|
||||||
|
"options":{
|
||||||
|
"width":"50%",
|
||||||
|
"height":"90%",
|
||||||
|
"archor":"cr",
|
||||||
|
"auto_open":true,
|
||||||
|
"fps":30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user