diff --git a/public/js/chat.js b/public/js/chat.js index af31460..3909403 100644 --- a/public/js/chat.js +++ b/public/js/chat.js @@ -39,6 +39,8 @@ var VideoChat = { localVideo: document.getElementById("local-video"), peerConnections: new Map(), recognition: undefined, + borderColor: undefined, + peerColors: {}, // Call to getUserMedia (provided by adapter.js for cross browser compatibility) // asking for access to both the video and audio streams. If the request is @@ -96,7 +98,9 @@ var VideoChat = { }, }); + VideoChat.borderColor = uuidToColor(VideoChat.socket.id); VideoChat.localVideo.srcObject = stream; + VideoChat.localVideo.style.border = `3px solid ${VideoChat.borderColor}`; // Now we're ready to join the chat room. VideoChat.socket.emit("join", roomHash); @@ -159,10 +163,6 @@ var VideoChat = { id: 0, }) ); - // Called when dataChannel is successfully opened - dataChannel.get(uuid).onopen = function (event) { - logIt("dataChannel opened"); - }; // Handle different dataChannel types dataChannel.get(uuid).onmessage = function (event) { const receivedData = event.data; @@ -170,13 +170,18 @@ var VideoChat = { const dataType = receivedData.substring(0, 4); const cleanedMessage = receivedData.slice(4); if (dataType === "mes:") { - handleRecieveMessage(cleanedMessage); + handleRecieveMessage(cleanedMessage, VideoChat.peerColors[uuid]); } else if (dataType === "cap:") { recieveCaptions(cleanedMessage); } else if (dataType === "tog:") { toggleSendCaptions(); } }; + // Called when dataChannel is successfully opened + dataChannel.get(uuid).onopen = function (event) { + logIt("dataChannel opened"); + setStreamColor(uuid); + }; // Set up callbacks for the connection generating iceCandidates or // receiving the remote media stream. Wrapping callback functions // to pass in the peer uuids. @@ -494,7 +499,7 @@ function sendToAllDataChannels(message) { // Mute microphone function muteMicrophone() { var audioTrack = null; - + VideoChat.audioEnabled = !VideoChat.audioEnabled; VideoChat.peerConnections.forEach(function (value, key, map) { value.getSenders().find(function (s) { if (s.track.kind === "audio") { @@ -503,9 +508,7 @@ function muteMicrophone() { }); audioTrack.enabled = VideoChat.audioEnabled; }); - - VideoChat.audioEnabled = !VideoChat.audioEnabled; - + // select mic button and mic button text const micButtonIcon = document.getElementById("mic-icon"); const micButtonText = document.getElementById("mic-text"); @@ -804,16 +807,16 @@ function recieveCaptions(captions) { // Text Chat // Add text message to chat screen on page -function addMessageToScreen(msg, isOwnMessage) { +function addMessageToScreen(msg, border, isOwnMessage) { if (isOwnMessage) { $(".chat-messages").append( - '