-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
117 lines (102 loc) · 2.6 KB
/
scripts.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
const videoEl = document.querySelector("#my-video");
let stream = null; //creating a stream var so that we can use it later
let mediaStream = null; //creating a mediaStream var for shareScreen
const constraints = {
audio: true, // use your headphones, or be prepared for feedback
video: true,
};
const getMicAndCamera = async (e) => {
try {
stream = await navigator.mediaDevices.getUserMedia(constraints);
console.log(stream);
// const tracks = stream.getTracks();
// console.log(tracks);
changeButtons([
"green",
"blue",
"blue",
"grey",
"grey",
"grey",
"grey",
"grey",
]);
} catch (error) {
// user denied access to constraints
console.log("user denied access to constraints");
console.log("error: ", error);
}
};
const showMyFeed = (e) => {
if (!stream) {
alert("stream still loading...");
return;
}
videoEl.srcObject = stream; // this will set our MediaStream (stream) to <video />
const tracks = stream.getTracks();
console.log(tracks);
changeButtons([
"green",
"green",
"blue",
"blue",
"blue",
"grey",
"grey",
"blue",
]);
};
const stopMyFeed = (e) => {
if (!stream) {
alert("stream still loading...");
return;
}
const tracks = stream.getTracks();
tracks.forEach((track) => {
// console.log(track);
track.stop(); //dis-associates src from the track and sets track state to ended
});
changeButtons([
"blue",
"grey",
"grey",
"grey",
"hrey",
"grey",
"grey",
"grey",
]);
};
document
.getElementById("share")
.addEventListener("click", (e) => getMicAndCamera(e));
document
.getElementById("show-video")
.addEventListener("click", (e) => showMyFeed(e));
document
.getElementById("stop-video")
.addEventListener("click", (e) => stopMyFeed(e));
document
.getElementById("change-size")
.addEventListener("click", (e) => changeVideoSize(e));
document
.getElementById("start-record")
.addEventListener("click", (e) => startRecording(e));
document
.getElementById("stop-record")
.addEventListener("click", (e) => stopRecording(e));
document
.getElementById("play-record")
.addEventListener("click", (e) => playRecording(e));
document
.getElementById("share-screen")
.addEventListener("click", (e) => shareScreen(e));
document
.getElementById("audio-input")
.addEventListener("change", (e) => chnageAudioInput(e));
document
.getElementById("audio-output")
.addEventListener("change", (e) => chnageAudioOutput(e));
document
.getElementById("video-input")
.addEventListener("change", (e) => chnageVideo(e));