-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.html
68 lines (62 loc) · 2.73 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello AI World</title>
<script type='text/javascript' src='https://webrtc.github.io/adapter/adapter-latest.js'></script>
<script type='text/javascript' src='/webrtc.js'></script>
<script type='text/javascript'>
play = function() {
playStream(document.getElementById('play-stream').value, document.getElementById('video-player'));
};
send = function() {
if( sendStream(getWebsocketURL('input'), document.getElementById('send-stream').value) )
play(); // autoplay browser stream
}
window.onload = function() {
var playStream = document.getElementById('play-stream');
var sendStream = document.getElementById('send-stream');
var sendButton = document.getElementById('send-button');
playStream.value = getWebsocketURL('output');
// populate the list of browser video devices (requires HTTPS)
if( checkMediaDevices() ) {
navigator.mediaDevices.getUserMedia({audio: false, video: true}).then((stream) => { // get permission from user
navigator.mediaDevices.enumerateDevices().then((devices) => {
stream.getTracks().forEach(track => track.stop()); // close the device opened to get permissions
devices.forEach((device) => {
if( device.kind == 'videoinput' ) {
console.log(`Browser media device: ${device.kind} label=${device.label} id=${device.deviceId}`);
sendStream.add(new Option(device.label, device.deviceId));
}
});
if( sendStream.options.length == 0 ) {
sendStream.add(new Option('browser has no webcams available'));
sendButton.disabled = true;
}
});
}).catch(reportError);
}
else
{
sendStream.add(new Option('use HTTPS to enable browser webcam'));
sendButton.disabled = true;
}
}
</script>
</head>
<body style="background-color:#333333; color:#FFFFFF; font-family:Arial">
<div>
<video id="video-player" autoplay controls playsinline muted>Your browser does not support video</video>
</div>
<div>
<label for="send-stream">Webcam:</label>
<select id="send-stream" name="send-stream" style="width: 245;"></select>
<button id="send-button" onclick="send()">Send</button>
</div>
<div>
<label for="play-stream">Stream:</label>
<input id="play-stream" name="play-stream" type="text" size="32">
<button id="play-button" onclick="play()">Play</button>
</div>
</body>
</html>