added support for multi user video display

This commit is contained in:
Taichi Kato 2020-05-29 00:21:07 +08:00
parent 6141039522
commit 79e6a860cd
3 changed files with 34 additions and 16 deletions

3
public/chat.html vendored
View File

@ -46,7 +46,8 @@
</div> </div>
<p id="remote-video-text"></p> <p id="remote-video-text"></p>
<video id="remote-video" autoplay playsinline></video> <div id="wrapper">
</div>
<div id="moveable"> <div id="moveable">
<p id="local-video-text">No webcam input</p> <p id="local-video-text">No webcam input</p>
<video id="local-video" autoplay muted playsinline></video> <video id="local-video" autoplay muted playsinline></video>

26
public/css/chat.css vendored
View File

@ -109,11 +109,26 @@ a {
background: #16171a; background: #16171a;
} }
#wrapper {
display: grid;
grid-gap: 10px;
justify-content: center;
padding: 0;
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 65%;
max-height: 100%;
max-width: 100%;
}
/*caption text*/ /*caption text*/
#remote-video-text { #remote-video-text {
box-sizing: border-box; box-sizing: border-box;
margin: 0; margin: 0;
width: 65vw;
position: absolute; position: absolute;
top: calc(80%); top: calc(80%);
left: 20vw; left: 20vw;
@ -131,15 +146,8 @@ a {
#remote-video { #remote-video {
padding: 0; padding: 0;
margin: 0; margin: 0;
position: absolute; width: 100%;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 65%;
height: auto; height: auto;
max-height: 100%;
max-width: 100%;
border-radius: 10px; border-radius: 10px;
background-image: url(../images/loader.gif); background-image: url(../images/loader.gif);
background-size: 400px auto; background-size: 400px auto;

View File

@ -20,6 +20,7 @@ const isWebRTCSupported =
const chatInput = document.querySelector(".compose input"); const chatInput = document.querySelector(".compose input");
const remoteVideoVanilla = document.getElementById("remote-video"); const remoteVideoVanilla = document.getElementById("remote-video");
const remoteVideo = $("#remote-video"); const remoteVideo = $("#remote-video");
const remoteVideosWrapper = $("#wrapper");
const captionText = $("#remote-video-text"); const captionText = $("#remote-video-text");
const localVideoText = $("#local-video-text"); const localVideoText = $("#local-video-text");
const captionButtontext = $("#caption-button-text"); const captionButtontext = $("#caption-button-text");
@ -31,7 +32,7 @@ var VideoChat = {
willInitiateCall: false, willInitiateCall: false,
localICECandidates: [], localICECandidates: [],
socket: io(), socket: io(),
remoteVideo: document.getElementById("remote-video"), remoteVideoWrapper: document.getElementById("wrapper"),
localVideo: document.getElementById("local-video"), localVideo: document.getElementById("local-video"),
recognition: undefined, recognition: undefined,
@ -303,12 +304,20 @@ var VideoChat = {
// Called when a stream is added to the peer connection // Called when a stream is added to the peer connection
onAddStream: function (event) { onAddStream: function (event) {
logIt("onAddStream <<< Received new stream from remote. Adding it..."); logIt("onAddStream <<< Received new stream from remote. Adding it...");
// Create new remote video source in wrapper
// Create a <video> node
var node = document.createElement("video");
node.setAttribute("autoplay", "");
node.setAttribute("playsinline", "");
node.setAttribute("id", "remote-video");
VideoChat.remoteVideoWrapper.appendChild(node);
// Update remote video source // Update remote video source
VideoChat.remoteVideo.srcObject = event.stream; console.log(VideoChat.remoteVideoWrapper.children);
VideoChat.remoteVideoWrapper.lastChild.srcObject = event.stream;
// Close the initial share url snackbar // Close the initial share url snackbar
Snackbar.close(); Snackbar.close();
// Remove the loading gif from video // Remove the loading gif from video
VideoChat.remoteVideo.style.background = "none"; VideoChat.remoteVideoWrapper.lastChild.style.background = "none";
// Update connection status // Update connection status
VideoChat.connected = true; VideoChat.connected = true;
// Hide caption status text // Hide caption status text
@ -360,7 +369,7 @@ function chatRoomFull() {
// Reposition local video to top left of remote video // Reposition local video to top left of remote video
function rePositionLocalVideo() { function rePositionLocalVideo() {
// Get position of remote video // Get position of remote video
var bounds = remoteVideo.position(); var bounds = remoteVideosWrapper.position();
let localVideo = $("#local-video"); let localVideo = $("#local-video");
if ( if (
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
@ -380,9 +389,9 @@ function rePositionLocalVideo() {
// Reposition captions to bottom of video // Reposition captions to bottom of video
function rePositionCaptions() { function rePositionCaptions() {
// Get remote video position // Get remote video position
var bounds = remoteVideo.position(); var bounds = remoteVideosWrapper.position();
bounds.top -= 10; bounds.top -= 10;
bounds.top = bounds.top + remoteVideo.height() - 1 * captionText.height(); bounds.top = bounds.top + remoteVideosWrapper.height() - 1 * captionText.height();
// Reposition captions // Reposition captions
captionText.css(bounds); captionText.css(bounds);
} }