forked from muaz-khan/WebRTC-Experiment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
385 lines (316 loc) · 15.5 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<!--
> Muaz Khan - www.MuazKhan.com
> MIT License - www.WebRTC-Experiment.com/licence
> Documentation - github.com/muaz-khan/getScreenId
-->
<!DOCTYPE html>
<html lang="en">
<head>
<title>getScreenId | Capture Screen on Any Domain!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="author" type="text/html" href="https://plus.google.com/+MuazKhan">
<meta name="author" content="Muaz Khan">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="https://cdn.webrtc-experiment.com/style.css">
<style>
audio {
vertical-align: bottom;
width: 10em;
}
video {
max-width: 100%;
vertical-align: top;
}
input {
border: 1px solid #d9d9d9;
border-radius: 1px;
font-size: 2em;
margin: .2em;
width: 30%;
}
p, .inner { padding: 1em; }
li {
border-bottom: 1px solid rgb(189, 189, 189);
border-left: 1px solid rgb(189, 189, 189);
padding: .5em;
}
label {
display: inline-block;
width: 8em;
}
p {
margin-top: 0!important;
margin-bottom: 0!important;
padding: 10px 10px!important;
}
blockquote {
margin: 10px;
border-radius: 10px;
background: rgb(253, 253, 253);
padding: 8px 20px;
font-size: 25px;
font-weight: 200;
line-height: 1.5;
word-spacing: 5px;
}
button {
font-size: 25px;
font-weight: 200;
line-height: 1.5;
word-spacing: 5px;
}
section blockquote {
color: #EC008C;
}
.specific-h2, h1 {
font-size: 35px;
font-weight: 200;
padding: 5px 10px;
border-bottom: 1px dotted #EC008C;
}
.specific-h2 a {
color: #EC008C;
}
h1 {
font-size: 40px;
color: #EC008C;
}
</style>
<script>
document.createElement('article');
document.createElement('footer');
</script>
<!-- script used to capture sourceId of the screen -->
<script src="https://cdn.webrtc-experiment.com/getScreenId.js"> </script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
</head>
<body>
<article>
<header style="text-align: center;">
<h1>
getScreenId | Capture Screen on Any Domain!
</h1>
<p>
<a href="https://www.webrtc-experiment.com/">HOME</a>
<span> © </span>
<a href="http://www.MuazKhan.com/" target="_blank">Muaz Khan</a>
.
<a href="http://twitter.com/WebRTCWeb" target="_blank" title="Twitter profile for WebRTC Experiments">@WebRTCWeb</a>
.
<a href="https://github.com/muaz-khan?tab=repositories" target="_blank" title="Github Profile">Github</a>
.
<a href="https://github.com/muaz-khan/getScreenId/issues?state=open" target="_blank">Latest issues</a>
.
<a href="https://github.com/muaz-khan/getScreenId/commits/master" target="_blank">What's New?</a>
</p>
</header>
<div class="github-stargazers"></div>
<blockquote>
YouTube video: <a href="https://www.youtube.com/watch?v=UHrsfe9RYAQ" target="_blank">https://www.youtube.com/watch?v=UHrsfe9RYAQ</a>
</blockquote>
<section class="experiment" style="text-align:center;">
<div id="chrome-extension-status"></div>
<br><button id="capture-screen">Capture Your Own Screen</button><hr>
<video controls autoplay playsinline style="width: 100%;background-repeat: no-repeat;background-size: 100%;background-image: url(https://lh5.googleusercontent.com/6U-gmL_hG9bbquDZdW_ajiA-1bgkfSlHOkzR24aigkyPQzXWXNoRNfyLjXS3rqV92iwq395JSQ=s640-h400-e365-rw);"></video>
</section>
<script>
var maxTries = 0;
function showChromeExtensionStatus() {
if(typeof window.getChromeExtensionStatus !== 'function') return;
var gotResponse;
window.getChromeExtensionStatus(function(status) {
gotResponse = true;
document.getElementById('chrome-extension-status').innerHTML = 'Chrome extension status is: <b>' + status + '</b>';
console.info('getChromeExtensionStatus', status);
});
maxTries++;
if(maxTries > 15) return;
setTimeout(function() {
if(!gotResponse) showChromeExtensionStatus();
}, 1000);
}
showChromeExtensionStatus();
// via: https://bugs.chromium.org/p/chromium/issues/detail?id=487935#c17
// you can capture screen on Android Chrome >= 55 with flag: "Experimental ScreenCapture android"
window.IsAndroidChrome = false;
try {
if (navigator.userAgent.toLowerCase().indexOf("android") > -1 && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)) {
window.IsAndroidChrome = true;
}
} catch (e) {}
document.getElementById('capture-screen').onclick = function() {
document.getElementById('capture-screen').disabled = true;
setTimeout(function() {
if(document.getElementById('capture-screen').disabled && !document.querySelector('video').src) {
document.getElementById('capture-screen').disabled = false;
}
}, 5000);
// edge 17 or higher
if(navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob)) {
navigator.getDisplayMedia(screen_constraints).then(stream => {
document.querySelector('video').srcObject = stream;
}, error => {
alert('Please make sure to use Edge 17 or higher.');
});
return;
}
getScreenId(function(error, sourceId, screen_constraints) {
// error == null || 'permission-denied' || 'not-installed' || 'installed-disabled' || 'not-chrome'
// sourceId == null || 'string' || 'firefox'
// getUserMedia(screen_constraints, onSuccess, onFailure);
document.getElementById('capture-screen').disabled = false;
if (IsAndroidChrome) {
screen_constraints = {
mandatory: {
chromeMediaSource: 'screen'
},
optional: []
};
screen_constraints = {
video: screen_constraints
};
error = null;
}
if(error == 'not-installed') {
alert('Please install Chrome extension. See the link below.');
return;
}
if(error == 'installed-disabled') {
alert('Please install or enable Chrome extension. Please check "chrome://extensions" page.');
return;
}
if(error == 'permission-denied') {
alert('Please make sure you are using HTTPs. Because HTTPs is required.');
return;
}
console.info('getScreenId callback \n(error, sourceId, screen_constraints) =>\n', error, sourceId, screen_constraints);
document.getElementById('capture-screen').disabled = true;
navigator.mediaDevices.getUserMedia(screen_constraints).then(function(stream) {
// share this "MediaStream" object using RTCPeerConnection API
document.querySelector('video').srcObject = stream;
stream.oninactive = stream.onended = function() {
document.querySelector('video').src = null;
document.getElementById('capture-screen').disabled = false;
};
document.getElementById('capture-screen').disabled = false;
}).catch(function(error) {
console.error('getScreenId error', error);
alert('Failed to capture your screen. Please check Chrome console logs for further information.');
});
}/*, 'we need speakers as well!'*/);
};
</script>
<blockquote class="inline">
<ol>
<li>
Install this: <a href="https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk" target="_blank">https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk</a>
</li>
<li>
Now use below codes on any HTTPs domain.
</li>
<li>
Remember, HTTPs is required.
</li>
<li>
getScreenId gives you "MediaStream" object; you can share that object with other users using AppRTC demo, SimpleWebRTC or EasyRTC or PeerJs libraries, or any standalone peer-to-peer demo.
</li>
<li>
In simple words, you have to use RTCPeerConnection API along with getScreenId to share screen with other users.
</li>
</ol>
</blockquote>
<section class="experiment">
<h2 class="header specific-h2">Prerequisites</h2>
<ol>
<li>
Chrome?
<a href="https://chrome.google.com/webstore/detail/screen-capturing/ajhifddimkapgcifgcodmmfdlknahffk" target="_blank">Store</a>
/ <a href="https://github.com/muaz-khan/Chrome-Extensions/tree/master/desktopCapture">Source Code</a>
</li>
<li>
Firefox? Requires version 52 or higher; and HTTPs.
</li>
<li>
MS-Edge requires 17 or higher; and HTTPs.
</li>
</ol>
</section>
<section class="experiment">
<h2 class="header specific-h2">
How to use <a href="https://github.com/muaz-khan/getScreenId" target="_blank">getScreenId.js</a>?</h2>
<pre class="sh_javascript sh_html">
<script src="https://cdn.WebRTC-Experiment.com/getScreenId.js"></script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script>
getScreenId(function (error, sourceId, screen_constraints) {
// error == null || 'permission-denied' || 'not-installed' || 'installed-disabled' || 'not-chrome'
// sourceId == null || 'string' || 'firefox'
if(navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob)) {
navigator.getDisplayMedia(screen_constraints).then(stream => {
document.querySelector('video').srcObject = stream;
}, error => {
alert('Please make sure to use Edge 17 or higher.');
});
return;
}
navigator.mediaDevices.getUserMedia(screen_constraints).then(function (stream) {
document.querySelector('video').srcObject = stream;
// share this "MediaStream" object using RTCPeerConnection API
}).catch(function (error) {
console.error(error);
});
}, 'pass second argument only if you want to capture speakers as well');
</script>
</pre>
</section>
<section class="experiment">
<h2 class="header specific-h2">
How to detect whether extension is installed or not?
</h2>
<pre class="sh_javascript sh_html">
<script src="https://cdn.WebRTC-Experiment.com/getScreenId.js"></script>
<script>
getChromeExtensionStatus(function(status) {
if (status === 'installed-enabled') alert('installed');
if (status === 'installed-disabled') alert('installed but disabled');
// etc.
});
</script>
</pre>
</section>
<section class="experiment">
<h2 class="header" id="feedback">Feedback</h2>
<div>
<textarea id="message" style="border: 1px solid rgb(189, 189, 189); height: 8em; margin: .2em; outline: none; resize: vertical; width: 98%;" placeholder="Have any message? Suggestions or something went wrong?"></textarea>
</div>
<button id="send-message" style="font-size: 1em;">Send Message</button><small style="margin-left: 1em;">Enter your email too; if you want "direct" reply!</small>
</section>
<section class="experiment own-widgets latest-commits">
<h2 class="header" id="updates" style="color: red; padding-bottom: .1em;"><a href="https://github.com/muaz-khan/WebRTC-Experiment/commits/master" target="_blank">Latest Updates</a></h2>
<div id="github-commits"></div>
</section>
</article>
<a href="https://github.com/muaz-khan/getScreenId" class="fork-left"></a>
<footer>
<p>
<a href="https://www.webrtc-experiment.com/">WebRTC Experiments</a>
© <a href="https://plus.google.com/+MuazKhan" rel="author" target="_blank">Muaz Khan</a>
<a href="mailto:[email protected]" target="_blank">[email protected]</a>
</p>
</footer>
<!-- commits.js is useless for you! -->
<script>
window.useThisGithubPath = 'muaz-khan/getScreenId';
</script>
<script src="https://cdn.webrtc-experiment.com/commits.js" async> </script>
<script src="https://cdn.webrtc-experiment.com/syntax/sh_main.min.js" type="text/javascript"> </script>
<script src="https://cdn.webrtc-experiment.com/syntax/sh_javascript.min.js" type="text/javascript"> </script>
<script src="https://cdn.webrtc-experiment.com/syntax/sh_html.min.js" type="text/javascript"> </script>
<link href="https://cdn.webrtc-experiment.com/syntax/sh_style.css" type="text/css" rel="stylesheet">
<script>
sh_highlightDocument();
</script>
</body>
</html>