From d13e59c7499a642d9c05b7ba3c0a0cda8088dd79 Mon Sep 17 00:00:00 2001
From: Simon Eisenmann <simon@struktur.de>
Date: Thu, 5 Mar 2015 14:10:16 +0100
Subject: [PATCH] Limit chat message send size to 200000 characters to avoid
 hanging clients.

---
 static/js/directives/chat.js  | 8 +++++++-
 static/partials/chatroom.html | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/static/js/directives/chat.js b/static/js/directives/chat.js
index 7c2ada38..75f06755 100644
--- a/static/js/directives/chat.js
+++ b/static/js/directives/chat.js
@@ -26,6 +26,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
 
 		var displayName = safeDisplayName;
 		var groupChatId = "";
+		var maxMessageSize = 200000;
 
 		var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
 
@@ -42,6 +43,8 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
 
 			$scope.currentRoom = null;
 			$scope.currentRoomActive = false;
+			$scope.maxMessageSize = maxMessageSize;
+
 			$scope.getVisibleRooms = function() {
 				var res = [];
 				for (var i = 0; i < ctrl.visibleRooms.length; i++) {
@@ -245,6 +248,10 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
 						};
 						subscope.sendChat = function(to, message, status, mid, noloop) {
 							//console.log("send chat", to, scope.peer);
+							if (message && message.length > maxMessageSize) {
+								console.log("XXXXXXX", message.length);
+								return mid;
+							}
 							var peercall = mediaStream.webrtc.findTargetCall(to);
 							if (peercall && peercall.peerconnection && peercall.peerconnection.datachannelReady) {
 								subscope.p2p(true);
@@ -254,7 +261,6 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
 								subscope.p2p(false);
 								return subscope.sendChatServer(to, message, status, mid, noloop);
 							}
-							return mid;
 						};
 						subscope.sendChatPeer2Peer = function(peercall, to, message, status, mid, noloop) {
 							if (message && !mid) {
diff --git a/static/partials/chatroom.html b/static/partials/chatroom.html
index a4bca25e..14f208bf 100644
--- a/static/partials/chatroom.html
+++ b/static/partials/chatroom.html
@@ -21,7 +21,7 @@
             </div>
             <div class="inputbox">
                 <div>
-                    <textarea class="input nicescroll form-control" ng-disabled="!(enabled)" on-enter="submit()" ng-model="input" placeholder="{{_('Type here to chat...')}}"/>
+                    <textarea class="input nicescroll form-control" maxlength="{{maxMessageSize}}" ng-disabled="!(enabled)" on-enter="submit()" ng-model="input" placeholder="{{_('Type here to chat...')}}"/>
                 </div>
                 <a ng-disabled="!(enabled)" ng-click="submit()" title="{{_('Send')}}" class="btn btn-small btn-info fa fa-play"></a>
             </div>