-
Notifications
You must be signed in to change notification settings - Fork 0
/
Video Conferencing.js
98 lines (86 loc) · 3.13 KB
/
Video Conferencing.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
let localVideo = document.getElementById('localVideo');
let fullscreenButton = document.getElementById('fullscreen-btn');
let pipButton = document.getElementById('pip-btn');
let startButton = document.getElementById('start-call-btn');
let endButton = document.getElementById('end-call-btn');
let localStream;
let remoteStream;
let peerConnection;
// Start the video call
startButton.addEventListener('click', function() {
startButton.disabled = true;
endButton.disabled = false;
// Get user media
navigator.mediaDevices.getUserMedia({ video: true, audio: true })
.then(function(stream) {
localStream = stream;
localVideo.srcObject = localStream;
})
.catch(function(error) {
console.log('Error accessing media devices: ', error);
});
// Create and configure the peer connection
// ...
});
// End the video call
endButton.addEventListener('click', function() {
startButton.disabled = false;
endButton.disabled = true;
// Stop local video stream
if (localStream) {
localStream.getTracks().forEach(function(track) {
track.stop();
});
}
// Clear local video element
localVideo.srcObject = null;
// Close peer connection and clean up
// ...
});
// Enter full screen
fullscreenButton.addEventListener('click', function() {
let videoContainer = document.getElementById('video-container');
if (videoContainer.requestFullscreen) {
videoContainer.requestFullscreen();
} else if (videoContainer.mozRequestFullScreen) {
videoContainer.mozRequestFullScreen();
} else if (videoContainer.webkitRequestFullscreen) {
videoContainer.webkitRequestFullscreen();
} else if (videoContainer.msRequestFullscreen) {
videoContainer.msRequestFullscreen();
}
});
// Exit full screen
document.addEventListener('fullscreenchange', exitFullScreenHandler);
document.addEventListener('mozfullscreenchange', exitFullScreenHandler);
document.addEventListener('webkitfullscreenchange', exitFullScreenHandler);
document.addEventListener('msfullscreenchange', exitFullScreenHandler);
function exitFullScreenHandler() {
if (
!document.fullscreenElement &&
!document.mozFullScreenElement &&
!document.webkitFullscreenElement &&
!document.msFullscreenElement
) {
exitFullScreen();
}
}
function exitFullScreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
// Enter Picture-in-Picture mode
pipButton.addEventListener('click', function() {
if (localVideo !== document.pictureInPictureElement) {
localVideo.requestPictureInPicture();
} else {
document.exitPictureInPicture();
}
});