From 2c500ead307a1266dd2c4912d7e27852be3d6b58 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Wed, 12 Mar 2014 17:52:15 +0100 Subject: [PATCH] Added 100ms delay while sending chat messages. --- static/js/directives/chat.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js index 97a81abe..a9c4a1db 100644 --- a/static/js/directives/chat.js +++ b/static/js/directives/chat.js @@ -172,24 +172,28 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], if (peercall && peercall.peerconnection.datachannelReady) { subscope.p2p(true); // Send out stuff through data channel. - mediaStream.api.apply("sendChat", { - send: function(type, data) { - // We also send to self, to display our own stuff. - if (!noloop) { - mediaStream.api.received({Type: data.Type, Data: data, From: mediaStream.api.id, To: peercall.id}); + _.delay(function() { + mediaStream.api.apply("sendChat", { + send: function(type, data) { + // We also send to self, to display our own stuff. + if (!noloop) { + mediaStream.api.received({Type: data.Type, Data: data, From: mediaStream.api.id, To: peercall.id}); + } + return peercall.peerconnection.send(data); } - return peercall.peerconnection.send(data); - } - })(to, message, status, mid); + })(to, message, status, mid); + }, 100); } else { subscope.p2p(false); - mediaStream.api.send2("sendChat", function(type, data) { - if (!noloop) { - //console.log("looped to self", type, data); - mediaStream.api.received({Type: data.Type, Data: data, From: mediaStream.api.id, To: to}); - } - })(to, message, status, mid); + _.delay(function() { + mediaStream.api.send2("sendChat", function(type, data) { + if (!noloop) { + //console.log("looped to self", type, data); + mediaStream.api.received({Type: data.Type, Data: data, From: mediaStream.api.id, To: to}); + } + })(to, message, status, mid); + }, 100); } return mid; }; @@ -325,7 +329,7 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], scope.hideRoom(group_chat_id); } }); - + }; };