diff --git a/public/assests/js/message.js b/public/assests/js/message.js index 83cc9ac..73ab24b 100755 --- a/public/assests/js/message.js +++ b/public/assests/js/message.js @@ -174,7 +174,6 @@ function setConversationDetails(details) { // Update Current Conversation function updateConversation(data) { - var ele = document.getElementById("conversation"); ele.innerHTML = ""; @@ -200,7 +199,18 @@ function updateConversation(data) { var divElement1 = $("
").addClass("row message-body"); var divElement2 = $("").addClass("col-sm-12"); var divElement3 = $(""); - var messageText = $("").addClass("message-text").text(data[i].message); + var messageText = $("").addClass("message-text"); + + // Embed YouTube video if link presents in message. + var youtube_link = data[i].message.indexOf('https://www.youtube.com'); + if(youtube_link !== -1) { + messageText.html(data[i].message + ''); + } + else { + messageText.text(data[i].message); + } + var spanElement = $("").addClass("message-time pull-right").text(data[i].time); if (data[i]["sent_by"] !== data[i].start) @@ -224,6 +234,7 @@ function updateConversation(data) { ele.scrollTop = $("#conversation")[0].scrollHeight - heightFrom; } } + setConversationDetails(data[0]); } @@ -243,6 +254,16 @@ function reply() { } } +// Typing indication +function typing() { + var id = $("#text_reply").attr("name"); + var msg = { + "name": id, + "type": "typing" + }; + sendTo(msg); +} + function notFound(eleId) { eleId = "#" + eleId; $(eleId).text(""); @@ -346,7 +367,7 @@ function startDictation() { conn.onmessage = function(e) { var msg = JSON.parse(e.data); - // console.log(msg); + if (!width()) { SideBar(msg.sidebar); } else { @@ -377,6 +398,15 @@ conn.onmessage = function(e) if (typeof(msg.Compose) !== "undefined") { composeResult(msg.Compose); } + + if (typeof(msg.typing) !== "undefined") { + if($('#user_typing').length == 0) { + $('#conversation').append(' '); + var element = document.getElementById("conversation"); + element.scrollTop = element.scrollHeight; + setTimeout(function() { $('#user_typing').remove(); }, 1000); + } + } }; // Event Listeners @@ -391,6 +421,11 @@ conn.onmessage = function(e) function() { reply(); }); + + $("body").on("change keyup paste", "#text_reply", + function() { + typing(); + }); $("body").on("click", ".reply-recording", function() { diff --git a/src/Chat.php b/src/Chat.php index ea9be56..bdfd504 100755 --- a/src/Chat.php +++ b/src/Chat.php @@ -135,6 +135,14 @@ public function onMessage(ConnectionInterface $from, $msg) $msg->userId = $from->userId; $composeResult = $this->onCompose($msg); $from->send($composeResult); + } else if ($msg->type == 'typing') { + $msg->userId = $from->userId; + $msg->name = convert_uudecode(hex2bin($msg->name)); + foreach ($this->clients as $client) { + if ($client->userId == $msg->name) { + $client->send(json_encode(array('typing' => 'typing'))); + } + } } else { $msg->userId = $from->userId; $msg->name = convert_uudecode(hex2bin($msg->name));