-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.html
164 lines (151 loc) · 5.78 KB
/
view.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gabriel Santos | Screen Caster</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100;300;400&display=swap");
body {
font-family: 'Noto Sans JP', sans-serif;
margin: 0 10vh;
/* background-color: #212121;
color: white; */
}
button {
padding: 12px 24px;
border: solid 2px;
background-color: white;
box-shadow: 3px 3px;
}
button:hover {
cursor: pointer;
}
button {
margin-right: 12px;
}
header {
margin-bottom: 12px;
}
main {
display: grid;
grid-template-columns: 6;
grid-template-rows: minmax(100px, auto);
}
main video {
border: solid rgb(0, 0, 0);
box-shadow: 3px 3px;
}
header, section {
grid-column-start: 1;
grid-column-end: 7;
}
.error {
color: red;
}
.warn {
color: orange;
}
.info {
color: darkgreen;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<main>
<header>
<h1>Gabriel Santos | Screen Caster </h1>
<p>This is a simple experiment with Screen Capture API</p>
<p><a href="https://twitter/lucgbrl">Twitter</a></p>
<p><a href="http://t.me/lucgbrl">Telegram</a></p>
<button id="start"> <i class="fa fa-play"></i> Start capture</button>
<button id="stop"> <i class="fa fa-stop"></i> Stop recording</button>
<a id="download"> <button><i class="fa fa-download"></i> Download recording</button></a>
</header>
<section>
<video id="video" autoplay width="100%" height="auto"></video>
<video id="play" class="hidden" autoplay width="100%" height="auto"></video>
<div>
<strong>Status</strong>
<pre id="log"></pre>
</div>
</section>
</main>
<script>
var video = document.getElementById("play")
var videoElem = document.getElementById("video")
var logElem = document.getElementById("log")
var startElem = document.getElementById("start")
var stopElem = document.getElementById("stop")
var download = document.getElementById("download")
let recorder, stream;
let audioTrack, videoTrack;
const gdmOptions = {
video: {
cursor: "always"
},
audio: true
}
async function startCapture() {
logElem.innerHTML = "";
videoElem.classList.remove('hidden')
video.classList.add('hidden')
try {
navigator.mediaDevices.getDisplayMedia({video:true})
.then(displayStream =>{
[videoTrack] = displayStream.getVideoTracks()
navigator.mediaDevices.getUserMedia({audio:true})
.then(audioStream=>{
[audioTrack] = audioStream.getAudioTracks()
stream = new MediaStream([videoTrack, audioTrack])
videoElem.srcObject = stream
recorder = new MediaRecorder(stream)
const chunks = []
recorder.ondataavailable = e => {
chunks.push(e.data)
}
recorder.onstop = e => {
videoElem.classList.add('hidden')
video.classList.remove('hidden')
const completed = new Blob(chunks, {type: chunks[0].type})
video.src = URL.createObjectURL(completed)
download.href = window.URL.createObjectURL(completed)
}
recorder.start()
dumpOptionsInfo();
})
})
} catch(err) {
console.error("Error: " + err);
}
}
function dumpOptionsInfo() {
const videoTrack = videoElem.srcObject.getVideoTracks()[0];
console.log = msg => logElem.innerHTML += `${msg}<br>`;
logElem.innerHTML = JSON.stringify(videoTrack.getSettings(), null, 2)
console.info("Track settings:");
console.info(JSON.stringify(videoTrack.getSettings(), null, 2));
console.info("Track constraints:");
console.info(JSON.stringify(videoTrack.getConstraints(), null, 2));
}
function stopCapture(evt) {
let tracks = videoElem.srcObject.getTracks();
tracks.forEach(track => track.stop());
recorder.stop()
stream.getVideoTracks()[0].stop()
// videoElem.srcObject = null;
}
startElem.addEventListener("click", function(evt){
startCapture()
}, false)
stopElem.addEventListener("click", function(evt){
stopCapture()
}, false)
</script>
</body>
</html>