-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch10.js
129 lines (116 loc) · 3.52 KB
/
sketch10.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
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
var questions = ["Question1", "Question2", "Question3", "Question4", "Question5"];
var answers = ["Answer1", "Answer2", "Answer3", "Answer4", "Answer5"];
var questions_length = questions.length;
var counter = 0;
var showAnswer_bool = true;
document.getElementById("question").innerHTML = questions[counter % questions_length];
function nextQuestion() {
counter++;
document.getElementById("question").innerHTML = questions[counter % questions_length];
showAnswer_bool = true;
}
function previousQuestion() {
counter--;
if (counter < 0)
counter = questions_length - 1;
document.getElementById("question").innerHTML = questions[counter % questions_length];
}
function showAnswer() {
if (showAnswer_bool) {
document.getElementById("question").innerHTML = questions[counter % questions_length] + "<br><br>" + answers[counter % questions_length];
showAnswer_bool = false;
}
else {
document.getElementById("question").innerHTML = questions[counter % questions_length];
showAnswer_bool = true;
}
}
document.body.addEventListener("keypress", function (event) {
if (event.key === 'n') {
nextQuestion();
}
else if (event.key === 'p') {
previousQuestion();
}
else if (event.key === 's') {
showAnswer();
console.log("Show Answer Called");
}
});
/*Code To check whether getUser Media is working on your current Browser*/
// function hasGetUserMedia() {
// return !!(navigator.mediaDevices &&
// navigator.mediaDevices.getUserMedia);
// }
// if (hasGetUserMedia()) {
// alert('getUserMedia() is supported by your browser');
// } else {
// alert('getUserMedia() is not supported by your browser');
// }
// const constraints1 = {
// video: true
// };
const video1 = document.getElementById("video1");
const video2 = document.getElementById("video2");
function streamCam() {
const constraints1 = {
video: {
label: {exact: "c922 Pro Stream Webcam (046d:085c)"}
}
}
navigator.mediaDevices.getUserMedia(constraints1).then((stream) => {video1.srcObject = stream});
const constraints2 = {
video: {
label: {exact: "Logitech Webcam C930e (046d:0843)"}
}
}
navigator.mediaDevices.getUserMedia(constraints2).then((stream) => {video2.srcObject = stream});
}
videolist = []
function gotDevices(deviceInfos) {
for (let i = 0; i !== deviceInfos.length; ++i) {
const deviceInfo = deviceInfos[i];
if (deviceInfo.kind == "videoinput") {
var label = deviceInfo.label;
if (label.includes("c922")) {
const constraints = {
video: {
deviceId: {exact: deviceInfo.deviceId}
}
}
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {video1.srcObject = stream});
}
else if (label.includes("C930e")) {
const constraints = {
video: {
deviceId: {exact: deviceInfo.deviceId}
}
}
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {video2.srcObject = stream});
}
console.log(deviceInfo);
}
// if (deviceInfo.kind === 'videoinput') {
// videolist.push(deviceInfo);
// }
}
}
function streamCameras() {
for (var i = 0; i < 2; i++) {
console.log(videolist[i]);
const constraints = {
video: {
deviceId: {exact: videolist[i].deviceId}
}
}
if (i == 0) {
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {video1.srcObject = stream});
}
else {
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {video2.srcObject = stream});
}
}
}
navigator.mediaDevices.enumerateDevices().then(gotDevices);
// navigator.mediaDevices.enumerateDevices().then(gotDevices).then(streamCameras);
// streamCam();