-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
100 lines (94 loc) · 3.64 KB
/
index.html
File metadata and controls
100 lines (94 loc) · 3.64 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Conference</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
#container {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
align-items: center;
}
video {
width: 100%;
max-width: 800px;
border-radius: 8px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #ddd;
}
</style>
</head>
<body>
<div id="container">
<h1>Video Conference</h1>
<video id="videoElement" autoplay playsinline></video>
<video id="secondVideoElement" autoplay playsinline style="display: none;"></video>
<button id="toggleCameraButton">Toggle Camera</button>
<button id="toggleSecondCameraButton">Toggle Second Camera</button>
<button id="toggleMicrophoneButton">Toggle Microphone</button>
</div>
<script>
const videoElement = document.getElementById('videoElement');
const secondVideoElement = document.getElementById('secondVideoElement');
const toggleCameraButton = document.getElementById('toggleCameraButton');
const toggleSecondCameraButton = document.getElementById('toggleSecondCameraButton');
const toggleMicrophoneButton = document.getElementById('toggleMicrophoneButton');
async function getMedia(videoElement) {
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
videoElement.srcObject = stream;
} catch (error) {
console.error('Error accessing camera or microphone:', error);
}
}
toggleCameraButton.addEventListener('click', () => {
const videoTrack = videoElement.srcObject.getVideoTracks()[0];
videoTrack.enabled = !videoTrack.enabled;
toggleCameraButton.textContent = videoTrack.enabled ? 'Turn Camera Off' : 'Turn Camera On';
});
toggleSecondCameraButton.addEventListener('click', () => {
const secondVideoTrack = secondVideoElement.srcObject ? secondVideoElement.srcObject.getVideoTracks()[0] : null;
if (secondVideoTrack) {
secondVideoTrack.stop();
secondVideoElement.srcObject = null;
secondVideoElement.style.display = 'none';
} else {
getMedia(secondVideoElement);
secondVideoElement.style.display = 'block';
}
});
toggleMicrophoneButton.addEventListener('click', () => {
const audioTrack = videoElement.srcObject.getAudioTracks()[0];
audioTrack.enabled = !audioTrack.enabled;
toggleMicrophoneButton.textContent = audioTrack.enabled ? 'Turn Microphone Off' : 'Turn Microphone On';
});
getMedia(videoElement);
</script>
</body>
</html>