Small fixes
This commit is contained in:
parent
1559da44d3
commit
1fffa33fe6
@ -15,15 +15,21 @@ let videoAccess = false;
|
|||||||
// Handle form submission
|
// Handle form submission
|
||||||
document.getElementById("question_form").addEventListener("submit", function (event) {
|
document.getElementById("question_form").addEventListener("submit", function (event) {
|
||||||
event.preventDefault(); // Prevent the default form submission
|
event.preventDefault(); // Prevent the default form submission
|
||||||
|
console.log("submit button pressed");
|
||||||
// Create a FormData object
|
// Create a FormData object
|
||||||
const formData = new FormData(event.target);
|
const formData = new FormData(event.target);
|
||||||
|
|
||||||
|
console.log("form data: ",formData);
|
||||||
|
|
||||||
// Append the recorded video Blob to the FormData object
|
// Append the recorded video Blob to the FormData object
|
||||||
if (recordedVideoBlob) {
|
if (recordedVideoBlob) {
|
||||||
|
console.log("video is available: ", recordedVideoBlob);
|
||||||
formData.append("recordedVideo", recordedVideoBlob, "recordedVideo.webm");
|
formData.append("recordedVideo", recordedVideoBlob, "recordedVideo.webm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console.log("Data to be submitted: ",formData);
|
||||||
|
|
||||||
// Use fetch to send the form data and video to the backend
|
// Use fetch to send the form data and video to the backend
|
||||||
console.log("try to send the form and video");
|
console.log("try to send the form and video");
|
||||||
fetch("/send_json", {
|
fetch("/send_json", {
|
||||||
@ -40,18 +46,6 @@ document.getElementById("question_form").addEventListener("submit", function (ev
|
|||||||
// Handle error response
|
// Handle error response
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
async function main() {
|
|
||||||
// Handle data available event
|
|
||||||
mediaRecorder.addEventListener("dataavailable", (event) => {
|
|
||||||
console.log("Data available Event triggered")
|
|
||||||
if (event.data.size > 0) {
|
|
||||||
recordedVideoBlob = (event.data);
|
|
||||||
console.log("Data available:", recordedVideoBlob);
|
|
||||||
} else {
|
|
||||||
console.log("No Data available");
|
|
||||||
}
|
|
||||||
|
|
||||||
});}
|
|
||||||
|
|
||||||
async function cameraButton() {
|
async function cameraButton() {
|
||||||
if (!videoAccess) {
|
if (!videoAccess) {
|
||||||
@ -77,29 +71,35 @@ async function cameraButton() {
|
|||||||
videoContainer.style.display = 'inline-block';
|
videoContainer.style.display = 'inline-block';
|
||||||
|
|
||||||
mediaRecorder = new MediaRecorder(stream, {
|
mediaRecorder = new MediaRecorder(stream, {
|
||||||
mimeType: "video/webm",
|
mimeType: "video/webm", // could use different video format
|
||||||
|
// videoBitsPerSecond: 5000000, // Standard bitrate for video is 2,5 mbps
|
||||||
});
|
});
|
||||||
|
|
||||||
mediaRecorder.addEventListener("dataavailable", (event) => {
|
mediaRecorder.addEventListener("dataavailable", (event) => {
|
||||||
console.log("Data available Event triggered")
|
console.log("Data available Event triggered");
|
||||||
if (event.data.size > 0) {
|
if (event.data.size > 0) {
|
||||||
recordedVideoBlob = event.data;
|
recordedVideoBlob = event.data;
|
||||||
videoDisplay.src = URL.createObjectURL(event.data);
|
|
||||||
videoDisplay.controls = true;
|
|
||||||
videoDisplay.pause();
|
|
||||||
console.log("Data available:", recordedVideoBlob);
|
console.log("Data available:", recordedVideoBlob);
|
||||||
|
|
||||||
buttonRecordIcon.src = ICON_PATHS.recordicon;
|
|
||||||
buttonRecordIcon.alt = 'Stop Icon';
|
|
||||||
isRecording = false;
|
|
||||||
console.log('Recording stopped');
|
|
||||||
console.log("Src path:", videoDisplay.src);
|
|
||||||
} else {
|
} else {
|
||||||
console.log("No Data available");
|
console.log("No Data available");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mediaRecorder.addEventListener("stop", () => {
|
||||||
|
if (recordedVideoBlob) {
|
||||||
|
videoDisplay.srcObject = null;
|
||||||
|
videoDisplay.src = URL.createObjectURL(recordedVideoBlob);
|
||||||
|
videoDisplay.controls = true;
|
||||||
|
videoDisplay.pause();
|
||||||
|
|
||||||
|
buttonRecordIcon.src = ICON_PATHS.recordicon;
|
||||||
|
buttonRecordIcon.alt = 'Record Icon';
|
||||||
|
isRecording = false;
|
||||||
|
console.log('Recording stopped');
|
||||||
|
console.log("Src path:", videoDisplay.src);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("cameraButton case videoAccess = true");
|
console.log("cameraButton case videoAccess = true");
|
||||||
|
|
||||||
@ -126,10 +126,12 @@ function recordButton() {
|
|||||||
buttonDeleteIcon.classList.add("buttondisable");
|
buttonDeleteIcon.classList.add("buttondisable");
|
||||||
videoDisplay.srcObject = stream;
|
videoDisplay.srcObject = stream;
|
||||||
videoDisplay.src = null;
|
videoDisplay.src = null;
|
||||||
|
videoDisplay.controls = false;
|
||||||
mediaRecorder.start();
|
mediaRecorder.start();
|
||||||
|
console.log("video bitrate = ",mediaRecorder.videoBitsPerSecond);
|
||||||
|
|
||||||
buttonRecordIcon.src = ICON_PATHS.stopicon;
|
buttonRecordIcon.src = ICON_PATHS.stopicon;
|
||||||
buttonRecordIcon.alt = 'record icon';
|
buttonRecordIcon.alt = 'Stop Icon';
|
||||||
isRecording = true;
|
isRecording = true;
|
||||||
console.log('Recording started');
|
console.log('Recording started');
|
||||||
} else {
|
} else {
|
||||||
@ -137,19 +139,16 @@ function recordButton() {
|
|||||||
mediaRecorder.stop();
|
mediaRecorder.stop();
|
||||||
|
|
||||||
console.log("recording stops");
|
console.log("recording stops");
|
||||||
// videoDisplay.srcObject = null;
|
|
||||||
|
|
||||||
|
|
||||||
buttonDelete.removeAttribute("disabled");
|
buttonDelete.removeAttribute("disabled");
|
||||||
buttonDeleteIcon.classList.remove("buttondisable");
|
buttonDeleteIcon.classList.remove("buttondisable");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteButton() {
|
function deleteButton() {
|
||||||
// TODO delete data
|
// TODO delete data
|
||||||
|
videoDisplay.controls = false;
|
||||||
videoDisplay.srcObject = stream;
|
videoDisplay.srcObject = stream;
|
||||||
recordedVideoBlob = null
|
recordedVideoBlob = null
|
||||||
buttonDelete.setAttribute("disabled", "");
|
buttonDelete.setAttribute("disabled", "");
|
||||||
//buttonDeleteIcon.classList.add("buttondisable");
|
buttonDeleteIcon.classList.add("buttondisable");
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user