From 073d15070b71414b0d17ce799ec4f95fac734fd4 Mon Sep 17 00:00:00 2001 From: Prajith Kesava Prasad <54884015+pkesavap@users.noreply.github.com> Date: Sat, 3 Oct 2020 21:13:49 +0530 Subject: [PATCH] Only send message if its not null or not empty This PR is raised to address the empty messages being sent in zipcall . How to check the problem:- 1) Initiate a zipcall session 2) open chat 3) continuously press enter, you will be able to see multiple empty messages which is sent in the UI --- public/js/chat.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/js/chat.js b/public/js/chat.js index 381dd22..73f5af0 100644 --- a/public/js/chat.js +++ b/public/js/chat.js @@ -765,16 +765,24 @@ chatInput.addEventListener("keypress", function (event) { // Make links clickable msg = msg.autoLink(); // Send message over data channel + if (isEmptyOrSpaces(msg) == false) { dataChanel.send("mes:" + msg); - // Add message to screen addMessageToScreen(msg, true); + + } + // Add message to screen // Auto scroll chat down chatZone.scrollTop(chatZone[0].scrollHeight); // Clear chat input chatInput.value = ""; + } }); +function isEmptyOrSpaces(str){ + return str === null || str.match(/^ *$/) !== null; +} + // Called when a message is recieved over the dataChannel function handleRecieveMessage(msg) { // Add message to screen