-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncoes.js
84 lines (68 loc) · 2.58 KB
/
funcoes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const startSharing = document.getElementById('startSharing');
const videoScreen = document.getElementById('screenVideoShare');
let mediaRecorder;
let recorderdChunks = [];
startSharing.addEventListener('click',async ()=>{
try {
const screenStream = await navigator.mediaDevices.getUserMedia({
video: {
cursor:'alwais'
},
audio:false
});
const audioStream = await navigator.mediaDevices.getUserMedia({
audio: true
})
const combinedStreams = new MediaStream([
...screenStream.getVideoTracks(),
...audioStream.getAudioTracks()
]);
videoScreen.srcObject = combinedStreams;
videoScreen.onloadedmetadata = () =>{
videoScreen.play();
}
combinedStreams.getVideoTracks()[0].onended = ()=>{
stopSharing();
}
startRecording();
}catch(error){
console.log("O seguinte erro ocorreu: "+error);
}
})
function startRecording (MediaStream){
mediaRecorder = new mediaRecorder(MediaStream,{MimeType:"video/webm"});
}
// mediaRecorder.ondataavailable = (event) => {
console.log(event.data);
console.log(event.data.size);
recorderdChunks.push(event.data);
//console.log(event.data);
// }
mediaRecorder.start();
mediaRecorder.onstop = () => {
downloadVideo();
}
// let interval= setInterval(function(){
//mediaRecorder.request.Data();
// },500);
function stopSharing(){
if(videoScreen.srcObject){
videoScreen.srcObject.getTracks().forEach(track=> track.stop())
videoScreen.srcObject = null;
}
if(mediaRecorder){
mediaRecorder.stop();
}
}
function downloadVideo(){
const blob = new Blob(recorderdChunks, { type: "video/webm"});
const url = Url.createObjectURL(blob);
}
//link teste destruir//
const a = document.createElement('a');
document.body.appendChild(a);
a.style.display ="none";
a.href = url;
a.download = "video=navegador.mp4";
window.URL.revokeObjectURL(url);
document.body.removeChild(a)