mirror of
https://github.com/ianramzy/decentralized-video-chat.git
synced 2025-02-21 23:45:06 +08:00
Added border colors for peer identification in chat and video, removing nicknames
This commit is contained in:
parent
d4cfda9032
commit
70b15ef04c
6
public/css/chat.css
vendored
6
public/css/chat.css
vendored
@ -337,6 +337,9 @@ button:hover {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 2px;
|
||||||
|
border-color: var(--bloc-color);
|
||||||
border-radius: 20px 20px 20px 5px;
|
border-radius: 20px 20px 20px 5px;
|
||||||
box-shadow: 6px 6px 12px #030506, -6px -6px 12px #23242a;
|
box-shadow: 6px 6px 12px #030506, -6px -6px 12px #23242a;
|
||||||
}
|
}
|
||||||
@ -345,6 +348,9 @@ button:hover {
|
|||||||
#chat-zone .message-item.customer .message-bloc {
|
#chat-zone .message-item.customer .message-bloc {
|
||||||
background-color: rgb(47, 48, 52);
|
background-color: rgb(47, 48, 52);
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 2px;
|
||||||
|
border-color: var(--bloc-color);
|
||||||
border-radius: 20px 20px 5px 20px;
|
border-radius: 20px 20px 5px 20px;
|
||||||
box-shadow: 6px 6px 12px #030506, -6px -6px 12px #22232a;
|
box-shadow: 6px 6px 12px #030506, -6px -6px 12px #22232a;
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,9 @@ const chatZone = $("#chat-zone");
|
|||||||
var dataChannel = new Map();
|
var dataChannel = new Map();
|
||||||
|
|
||||||
var VideoChat = {
|
var VideoChat = {
|
||||||
nickname: undefined,
|
|
||||||
videoEnabled: true,
|
videoEnabled: true,
|
||||||
audioEnabled: true,
|
audioEnabled: true,
|
||||||
|
borderColor: `hsl(${Math.floor(Math.random() * 360)}, 70%, 80%)`,
|
||||||
connected: new Map(),
|
connected: new Map(),
|
||||||
localICECandidates: {},
|
localICECandidates: {},
|
||||||
socket: io(),
|
socket: io(),
|
||||||
@ -97,17 +97,8 @@ var VideoChat = {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Used to identify client to other peers in chats, captions etc.
|
|
||||||
VideoChat.nickname = prompt("Please enter a nickname", "");
|
|
||||||
|
|
||||||
while (VideoChat.nickname == null || VideoChat.nickname.trim() === "") {
|
|
||||||
VideoChat.nickname = prompt(
|
|
||||||
"Nickname cannot be empty. Please enter a nickname",
|
|
||||||
""
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
VideoChat.localVideo.srcObject = stream;
|
VideoChat.localVideo.srcObject = stream;
|
||||||
|
VideoChat.localVideo.style.border = `4px solid ${VideoChat.borderColor}`;
|
||||||
|
|
||||||
// Now we're ready to join the chat room.
|
// Now we're ready to join the chat room.
|
||||||
VideoChat.socket.emit("join", roomHash);
|
VideoChat.socket.emit("join", roomHash);
|
||||||
@ -170,10 +161,6 @@ var VideoChat = {
|
|||||||
id: 0,
|
id: 0,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
// Called when dataChannel is successfully opened
|
|
||||||
dataChannel.get(uuid).onopen = function (event) {
|
|
||||||
logIt("dataChannel opened");
|
|
||||||
};
|
|
||||||
// Handle different dataChannel types
|
// Handle different dataChannel types
|
||||||
dataChannel.get(uuid).onmessage = function (event) {
|
dataChannel.get(uuid).onmessage = function (event) {
|
||||||
const receivedData = event.data;
|
const receivedData = event.data;
|
||||||
@ -186,8 +173,16 @@ var VideoChat = {
|
|||||||
recieveCaptions(cleanedMessage);
|
recieveCaptions(cleanedMessage);
|
||||||
} else if (dataType === "tog:") {
|
} else if (dataType === "tog:") {
|
||||||
toggleSendCaptions();
|
toggleSendCaptions();
|
||||||
|
} else if (dataType === "clr:") {
|
||||||
|
setStreamColor(uuid, cleanedMessage);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Called when dataChannel is successfully opened
|
||||||
|
dataChannel.get(uuid).onopen = function (event) {
|
||||||
|
logIt("dataChannel opened");
|
||||||
|
// Sending our identifier color to the other peers
|
||||||
|
dataChannel.get(uuid).send("clr:" + VideoChat.borderColor);
|
||||||
|
};
|
||||||
// Set up callbacks for the connection generating iceCandidates or
|
// Set up callbacks for the connection generating iceCandidates or
|
||||||
// receiving the remote media stream. Wrapping callback functions
|
// receiving the remote media stream. Wrapping callback functions
|
||||||
// to pass in the peer uuids.
|
// to pass in the peer uuids.
|
||||||
@ -815,17 +810,16 @@ function recieveCaptions(captions) {
|
|||||||
|
|
||||||
// Text Chat
|
// Text Chat
|
||||||
// Add text message to chat screen on page
|
// Add text message to chat screen on page
|
||||||
function addMessageToScreen(msg, isOwnMessage) {
|
function addMessageToScreen(msg, border, isOwnMessage) {
|
||||||
// If nickname is undefined or null, user didn't input a nickname
|
|
||||||
if (isOwnMessage) {
|
if (isOwnMessage) {
|
||||||
$(".chat-messages").append(
|
$(".chat-messages").append(
|
||||||
'<div class="message-item customer cssanimation fadeInBottom"><div class="message-bloc"><div class="message">' +
|
`<div class="message-item customer cssanimation fadeInBottom"><div class="message-bloc" style="--bloc-color: ${border}"><div class="message">` +
|
||||||
msg +
|
msg +
|
||||||
"</div></div></div>"
|
"</div></div></div>"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$(".chat-messages").append(
|
$(".chat-messages").append(
|
||||||
'<div class="message-item moderator cssanimation fadeInBottom"><div class="message-bloc"><div class="message">' +
|
`<div class="message-item moderator cssanimation fadeInBottom"><div class="message-bloc" style="--bloc-color: ${border}"><div class="message">` +
|
||||||
msg +
|
msg +
|
||||||
"</div></div></div>"
|
"</div></div></div>"
|
||||||
);
|
);
|
||||||
@ -843,9 +837,9 @@ chatInput.addEventListener("keypress", function (event) {
|
|||||||
// Make links clickable
|
// Make links clickable
|
||||||
msg = msg.autoLink();
|
msg = msg.autoLink();
|
||||||
// Send message over data channel
|
// Send message over data channel
|
||||||
sendToAllDataChannels("mes:" + VideoChat.nickname + ": " + msg);
|
sendToAllDataChannels("mes:" + VideoChat.borderColor + msg);
|
||||||
// Add message to screen
|
// Add message to screen
|
||||||
addMessageToScreen(msg, true);
|
addMessageToScreen(msg, VideoChat.borderColor, true);
|
||||||
// Auto scroll chat down
|
// Auto scroll chat down
|
||||||
chatZone.scrollTop(chatZone[0].scrollHeight);
|
chatZone.scrollTop(chatZone[0].scrollHeight);
|
||||||
// Clear chat input
|
// Clear chat input
|
||||||
@ -855,8 +849,12 @@ chatInput.addEventListener("keypress", function (event) {
|
|||||||
|
|
||||||
// Called when a message is recieved over the dataChannel
|
// Called when a message is recieved over the dataChannel
|
||||||
function handleRecieveMessage(msg) {
|
function handleRecieveMessage(msg) {
|
||||||
|
// Slice border color for message
|
||||||
|
const endIndex = msg.indexOf(')');
|
||||||
|
const color = msg.slice(0, endIndex);
|
||||||
|
msg = msg.slice(endIndex+1, msg.length);
|
||||||
// Add message to screen
|
// Add message to screen
|
||||||
addMessageToScreen(msg, false);
|
addMessageToScreen(msg, color, false);
|
||||||
// Auto scroll chat down
|
// Auto scroll chat down
|
||||||
chatZone.scrollTop(chatZone[0].scrollHeight);
|
chatZone.scrollTop(chatZone[0].scrollHeight);
|
||||||
// Show chat if hidden
|
// Show chat if hidden
|
||||||
@ -865,6 +863,11 @@ function handleRecieveMessage(msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets the border color of uuid's stream upon receiving color
|
||||||
|
function setStreamColor(uuid, color) {
|
||||||
|
document.querySelectorAll(`[uuid="${uuid}"]`)[0].style.border = `4px solid ${color}`;
|
||||||
|
}
|
||||||
|
|
||||||
// Show and hide chat
|
// Show and hide chat
|
||||||
function toggleChat() {
|
function toggleChat() {
|
||||||
var chatIcon = document.getElementById("chat-icon");
|
var chatIcon = document.getElementById("chat-icon");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user