-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
71 lines (61 loc) · 1.92 KB
/
main.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
'use strict';
var stream;
var exactButton = document.querySelector('#exact');
var heightWidthButton = document.querySelector('#heightWidth');
var stopButton = document.querySelector('#stop');
var video = document.querySelector('#video1');
var info = document.querySelector('#info');
function bridgeTemasys() {
if (!navigator.mediaDevices) {
navigator.mediaDevices = {};
navigator.mediaDevices.getUserMedia = function (constraints) {
return new Promise(function (resolve, reject) {
window.getUserMedia(constraints, resolve, reject);
});
};
}
}
function stopStream() {
if (stream) {
stream.getTracks().forEach(function (track) {
track.stop();
});
}
}
stopButton.onclick = function () {
stopStream();
info.innerHTML = '';
};
heightWidthButton.onclick = function () {
getMedia({ audio: true, video: { height: 1920, width: 1080 } }).then(function (tracks) {
console.log(tracks);
info.innerHTML = 'Please open the console to see the tracks';
});
};
exactButton.onclick = function () {
getMedia({ audio: true, video: { exact: { height: 1920, width: 1080 } } }).then(function (tracks) {
console.log(tracks);
info.innerHTML = 'Please open the console to see the tracks';
});
};
function getMedia(constraints) {
bridgeTemasys();
stopStream();
const returnedPromise = navigator.mediaDevices.getUserMedia(constraints).then(gotStream).catch(function (e) {
var message = 'getUserMedia error: ' + e.name;
alert(message);
console.log(message);
});
console.log("returnedPromise", returnedPromise)
return returnedPromise;
}
function gotStream(mediaStream) {
stream = mediaStream; // stream available to console
attachMediaStream(video, stream);
video.onloadedmetadata = function () {
video.play();
};
var videoTrack = stream.getVideoTracks()[0];
var audioTrack = stream.getAudioTracks()[0];
return { audioTrack: audioTrack, videoTrack: videoTrack };
}