-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
165 lines (142 loc) · 5.51 KB
/
index.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
165
<html>
<head>
<title>Android Device Framer</title>
<meta name="description" content="Records your Android Screen">
<meta name="viewport" content="width=device-width">
<meta name="twitter:creator" content="@Paul_Kinlan">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Person",
"name": "Paul Kinlan",
"url": "https://paul.kinlan.me/",
"sameAs": [
"https://twitter.com/paul_kinlan",
"https://www.instagram.com/paul_kinlan/",
"https://www.linkedin.com/in/paulkinlan",
"https://plus.google.com/+paulkinlan",
"https://github.com/paulkinlan"
]
}
</script>
<link rel="stylesheet" href="./css/main.css">
<meta name="theme-color" content="#FF9800">
<link rel="manifest" href="./manifest.json">
<script src="scripts/peer.js"></script>
<script>
if(navigator.serviceWorker) {
navigator.serviceWorker.register('./sw.js')
.then(() => {
console.log('installed');
})
}
let recordBtn;
let remoteScreenElement;
let remoteStream;
let sessionElement;
let sessionUrlElement;
let recorder;
let recordedBlobs = [];
let body = document.body;
let recordUrl = new URL(window.location);
const start = function() {
console.log('Starting a peer');
var peer = new Peer({
host: 'screen-record-peerjs.herokuapp.com',
secure: true,
port:443,
config: {'iceServers': [
{ url: 'stun:stun.devicefra.me' },
{ url: 'turn:turn.devicefra.me',
username: 'whatausername',
credential: 'whatapassword' }
]} /* Sample servers, please use appropriate ones */
});
peer.on('open', function() {
document.body.classList.add('waiting');
recordUrl.pathname += 'record.html';
recordUrl.hash = peer.id;
sessionUrlElement.innerText = recordUrl.toString();
document.querySelector('#qrCodeElement').src =
'https://chart.apis.google.com/chart?cht=qr&chs=300x300&chld=H|0&chl=' +
encodeURIComponent(recordUrl.toString());
});
peer.on('disconnected', function() {
console.log('disconnected');
});
peer.on('error', function(err) {
console.log('Err: ' + err);
});
peer.on('call', function(call) {
document.body.classList.remove('waiting')
console.log('Call Recieved', call);
call.on('stream', function(remoteScreenStream) {
document.body.classList.add('streaming')
// Show stream in some video/canvas element.
remoteStream = remoteScreenStream
remoteScreenElement.src = URL.createObjectURL(remoteStream);
remoteScreenElement.play();
});
call.answer(); // Answer the call with an A/V stream.
});
};
const startRecording = function(e) {
document.body.classList.add('recording');
document.body.classList.remove('streaming');
recordScreen();
};
const stopRecording = function(e) {
document.body.classList.remove('recording');
document.body.classList.add('streaming');
recorder.stop();
};
onload = function() {
recordBtn = document.getElementById('recordBtn');
stopRecordingBtn = document.getElementById('stopRecordingBtn');
remoteScreenElement = document.getElementById('remoteScreenElement');
sessionElement = document.getElementById('sessionElement');
sessionUrlElement = document.getElementById('sessionUrlElement');
stopRecordingBtn.addEventListener('click', stopRecording);
recordBtn.addEventListener('click', startRecording);
//create peer to remote host.
start();
};
function recordScreen() {
recorder = new MediaRecorder(remoteStream, {mimeType: 'video/webm; codecs=vp9'});
recorder.ondataavailable = e => { console.log(e.data); if (e.data && e.data.size > 0) recordedBlobs.push(e.data)};
recorder.onstop = (e) => download(new Blob(recordedBlobs, {type: 'video/webm'}));
recorder.start(10); // collect 10ms chunks of data
}
function download(blob) {
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = 'test.mp4';
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 100);
}
</script>
</head>
<body class="loading">
<div id="sessionElement">
<div>Open <a id="sessionUrlElement"></a> on your Android device.</div>
<div><img id="qrCodeElement"></div>
</div>
<button id="recordBtn">Start Record</button>
<button id="stopRecordingBtn">Stop Record</button>
<video autoplay muted="true" id="remoteScreenElement"></video>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-88398808-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>