Skip to content

Commit

Permalink
fixed the bug, but speechSynthesis will not be saved well.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielOnGitHub17 committed Apr 28, 2024
1 parent eac9e92 commit 6d6e2cb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
53 changes: 31 additions & 22 deletions interview.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class Interview{
navigator.mediaDevices.getUserMedia({
audio: true, video: true, facingMode: {exact: "user"}
}).then(mediaStream=>{
if (isPhone()){
// ha! (back to old implementation of spe)
this.video(mediaStream);
return
}
navigator.mediaDevices.getDisplayMedia({
audio: true, video: true
}).then(screenStream=>{
Expand Down Expand Up @@ -160,28 +165,32 @@ class Interview{
video(mediaStream, screenStream){
// for playing around, add the screen's stream
// get the video track
this.mdStm = mediaStream;
this.videoTrack = mediaStream.getVideoTracks()[0];
// stop screen's videoTrack
let screenVideo = screenStream.getVideoTracks()[0];
screenVideo.stop();
screenStream.removeTrack(screenVideo);
// merge the two streams into one audio stream
let audioCtx = new AudioContext()
, destination = audioCtx.createMediaStreamDestination();
[...arguments].forEach(stream=>{
audioCtx.createMediaStreamSource(stream).connect(destination);
})
this.dest = destination.stream;
// get the one audio track from the gotten stream
this.audioTrack= destination.stream.getAudioTracks()[0];
if (screenStream){
this.mdStm = mediaStream;
this.videoTrack = mediaStream.getVideoTracks()[0];
// stop screen's videoTrack
let screenVideo = screenStream.getVideoTracks()[0];
screenVideo.stop();
screenStream.removeTrack(screenVideo);
// merge the two streams into one audio stream
let audioCtx = new AudioContext()
, destination = audioCtx.createMediaStreamDestination();
[...arguments].forEach(stream=>{
audioCtx.createMediaStreamSource(stream).connect(destination);
})
this.dest = destination.stream;
// get the one audio track from the gotten stream
this.audioTrack= destination.stream.getAudioTracks()[0];

// create a new media stream to be used
this.mediaStream = new MediaStream();
// add video and audio tracks to this one stream
["audio", "video"].forEach(track=>{
this.mediaStream.addTrack(this[track+"Track"]);
});
// create a new media stream to be used
this.mediaStream = new MediaStream();
// add video and audio tracks to this one stream
["audio", "video"].forEach(track=>{
this.mediaStream.addTrack(this[track+"Track"]);
});
} else{
this.mediaStream = mediaStream;
}
this.mediaRecorder = new MediaRecorder(
this.mediaStream, {mimeType: "video/webm; codecs=vp9"}
);
Expand All @@ -204,7 +213,7 @@ class Interview{
REFRESHER.disabled = false;
if (this.useVideo){
say(FINALSAY.value).then(resp=>{
["screen", "media"].forEach(type=>{
(isPhone()?["media"]:["screen", "media"]).forEach(type=>{
this[type+"Stream"].getTracks().forEach(i=>i.stop());
})
this.mediaRecorder.stop();
Expand Down
20 changes: 10 additions & 10 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ function consentToRecording(){
// create a toggle to switch video options
createVideoToggle();
if (bool){
// remove if solution found
if (isPhone()){
throw alert(`
Sorry, but you cannot use a phone for the video interview.<br>
Phone browsers do not support screen recording.
Please, use a laptop to access this feature.
`)
}
// remove if solution found (removed, ha!)
// if (isPhone()){
// throw alert(`
// Sorry, but you cannot use a phone for the video interview.<br>
// Phone browsers do not support screen recording.
// Please, use a laptop to access this feature.
// `)
// }
// create voice search ui
createVoiceSearchUI()
if (localStorage.voice){
Expand All @@ -106,8 +106,8 @@ function consentToRecording(){
speechSynthesis.getVoices = ()=> [{name: "Default voice"}];
}
}).catch(error=>{
videoSwitch.switch.click();
SHOULDVIDEO.remove();
videoSwitch.switch.click();
SHOULDVIDEO.remove();
})
}

Expand Down

0 comments on commit 6d6e2cb

Please sign in to comment.