-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar.js
265 lines (244 loc) · 8.09 KB
/
sidebar.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
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
// Yeah, I don't like this code. Fix it later
class capturecard2VideoSidebar{
constructor(capturecard2Video){
this.cap2vid = capturecard2Video;
window.addEventListener('keydown', this.onkey.bind(this));
setInterval(this.refreshDevices.bind(this), 1000)
this.settingbar = document.createElement('div');
this.settingbar.id = "settingbar"
this.videobottom = document.createElement('div');
this.videobottom.id = "videobottom"
this.settingbar.appendChild(this.videobottom);
this.videobottomother = document.createElement('div');
this.videobottomother.id = "videobottomother";
this.settingbar.appendChild(this.videobottomother);
this.muteButton = document.createElement('button');
this.muteButton.textContent = 'Unmute (m)';
this.muteButton.onclick = this.toggleMute.bind(this);
this.videobottomother.appendChild(this.muteButton);
this.widthElement = document.createElement('input');
this.widthElement.onchange = (object) => {
this.videoSettings.width = object.srcElement.value
cap2vid.changeDevice()
}
this.widthElement.value = this.cap2vid.videoProperties.width;
this.videobottom.appendChild(this.widthElement)
this.heightElement = document.createElement('input');
this.heightElement.onchange = (object) => {
videoSettings.height = object.srcElement.value
cap2vid.changeDevice()
}
this.heightElement.value = this.cap2vid.videoProperties.height;
this.videobottom.appendChild(this.heightElement)
this.hoverbar = document.createElement('div');
this.hoverbar.id = "hoverbar"
this.devices = document.createElement('div');
this.devices.id = "devices"
this.settingbar.appendChild(this.devices);
this.fpsElement = document.createElement('input');
this.fpsElement.onchange = (object) => {
videoSettings.fps = object.srcElement.value
cap2vid.changeDevice()
}
this.fpsElement.value = this.cap2vid.videoProperties.fps;
this.videobottom.appendChild(this.fpsElement)
this.helpElement = document.createElement('button');
this.helpElement.onclick = this.openHelp;
this.helpElement.textContent = "Binds (?)";
this.videobottomother.appendChild(this.helpElement)
this.refreshElement = document.createElement('button');
if(this.cap2vid.video.requestPictureInPicture){
this.pipElement = document.createElement('button');
this.pipElement.onclick = this.cap2vid.video.requestPictureInPicture;
this.pipElement.textContent = "Picture in Picture (p)"
this.videobottomother.appendChild(this.pipElement);
}
this.refreshElement.onclick = this.getDevices;
document.body.appendChild(this.hoverbar);
document.body.appendChild(this.settingbar);
this.refreshDevices()
}
changeDeviceHandler(element,ms){
// ms is essentually self, THANKS JAVASCRIPT
if(element.srcElement.getAttribute('videoDevice') == null){}else{
ms.cap2vid.videoProperties.deviceId.video = element.srcElement.getAttribute('videoDevice')
}
if(element.srcElement.getAttribute('audioDevice') == null){}else{
ms.cap2vid.videoProperties.deviceId.audio = element.srcElement.getAttribute('audioDevice')
}
ms.cap2vid.changeDevice()
}
toggleMute(){
this.cap2vid.video.muted = !this.cap2vid.video.muted
if(this.cap2vid.video.muted == true){
this.muteButton.textContent = "Unmute (m)"
}else{
this.muteButton.textContent = "Mute (m)"
}
}
refreshDevices(){
this.cap2vid.mediaDevices.enumerateDevices().then((mediaDevices) => {
this.devices.innerHTML = `
`;
let d = {}
mediaDevices.forEach(mediaDevice => {
let label = "";
if(mediaDevice.label == ""){
label = "Null/Default"
}else{
label = mediaDevice.label
}
if(mediaDevice.kind == 'videoinput') {
if(typeof this.devices[mediaDevice.groupId] == "undefined"){
d[mediaDevice.groupId] = {
"label": label
}
}
d[mediaDevice.groupId]["video"] = mediaDevice.deviceId
}
if(mediaDevice.kind == 'audioinput') {
if(typeof this.devices[mediaDevice.groupId] == "undefined"){
d[mediaDevice.groupId] = {
"label": label
}
}
d[mediaDevice.groupId]["audio"] = mediaDevice.deviceId
}
});
for(let e in d){
if(typeof d[e]["video"] == "string" || typeof d[e]["audio"] == "string"){
let a = document.createElement('button');
let iconhtml = ""
if(typeof d[e]["video"] == "string" && typeof d[e]["audio"] == "string"){
a.id = "vaButton";
iconhtml = iconhtml + `<i class="bi bi-collection-play-fill"></i>`
a.setAttribute('videoDevice', d[e]["video"])
if(d[e]['video'] == this.cap2vid.videoProperties.deviceId.video && d[e]['audio'] == this.cap2vid.videoProperties.deviceId.audio){
iconhtml = '<i class="bi bi-camera-video-fill"></i>';
}
a.setAttribute('audioDevice', d[e]["audio"])
}else{
if(typeof d[e]["video"] == "string"){
a.id = "videoButton";
iconhtml = iconhtml + `<i class="bi bi-camera-video"></i>`
a.setAttribute('videoDevice', d[e]["video"])
if(d[e]['video'] == this.cap2vid.videoProperties.deviceId.video){
iconhtml = '<i class="bi bi-camera-video-fill"></i>';
}
}
if(typeof d[e]["audio"] == "string"){
a.id = "audioButton";
iconhtml = iconhtml + `<i class="bi bi-speaker"></i>`
a.setAttribute('audioDevice', d[e]["audio"])
if(d[e]['audio'] == this.cap2vid.videoProperties.deviceId.audio){
iconhtml = '<i class="bi bi-speaker-fill"></i>';
}
}
a.innerHTML = iconhtml + d[e]["label"];
a.onclick = (e) => {
this.changeDeviceHandler(e, this)
}
this.devices.appendChild(a);
}
}
}
});
}
// This is a programming warcrime
openHelp(){
let helpstring = `Keybinds:
-- Best for efficency
f : Fullscreen (or double click video)
l : Lock/Hide mouse cursor (or single click video)
m : Mutes and unmutes
c : Changes device`
if(this.cap2vid.video.requestPictureInPicture){
helpstring+=`
p : Request Picture in Picture`
}
helpstring+=`
-- Other
? or / : Show Help page
w : Set width
h : Set height
s : Set FPS`
alert(helpstring)
}
onkey(e){
if(e.key == "f"){
document.body.requestFullscreen();
}
if(e.key == "l"){
document.body.requestPointerLock();
}
// add changing devices later
if(e.key == "w"){
this.cap2vid.videoProperties.width = prompt("What width do you want to set?", this.cap2vid.videoProperties.width);
}
if(e.key == "h"){
this.cap2vid.videoProperties.height = prompt("What height do you want to set?", this.cap2vid.videoProperties.height);
}
if(e.key == "s"){
this.cap2vid.videoProperties.fps = prompt("What FPS do you want to set?", this.cap2vid.videoProperties.fps);
}
if(e.key == "p"){
console.log("PiP is not a avaliable function on firefox, so yeah.")
this.cap2vid.video.requestPictureInPicture();
}
if(e.key == "?" || e.key == "/"){
this.openHelp();
}
if(e.key == "m"){
this.toggleMute();
}
if(e.key == "c"){
this.refreshDevices()
let arr = []
let d = {}
let finalstring = ""
this.cap2vid.mediaDevices.enumerateDevices().then((mediaDevices) => {
let d = {}
mediaDevices.forEach(mediaDevice => {
let label = "";
if(mediaDevice.label == ""){
label = "Null/Default"
}else{
label = mediaDevice.label
}
if(mediaDevice.kind == 'videoinput') {
if(typeof this.devices[mediaDevice.groupId] == "undefined"){
d[mediaDevice.groupId] = {
"label": label
}
}
d[mediaDevice.groupId]["video"] = mediaDevice.deviceId
}
if(mediaDevice.kind == 'audioinput') {
if(typeof this.devices[mediaDevice.groupId] == "undefined"){
d[mediaDevice.groupId] = {
"label": label
}
}
d[mediaDevice.groupId]["audio"] = mediaDevice.deviceId
}
});
if(arr.length == 0){
alert("No devices found!")
return
}
for(let devi in arr){
finalstring += devi+": "+arr[devi].label+"\n";
}
let a = arr[prompt("What device do you want to use?\n"+finalstring)]
console.log(a)
if(typeof a['video'] == 'string'){
videoDeviceID = a['video']
}
if(typeof a['audio'] == 'string'){
audioDeviceID = a['audio']
}
this.cap2vid.changeDevice()
});
}
}
}