From d2f11ad89d470c23f8d6c777df836de91c84a03d Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Tue, 6 May 2014 21:48:40 +0200 Subject: [PATCH 1/3] Catch DOMException --- index.html | 3 +++ js/glowingbear.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 1ff63a9..a728587 100644 --- a/index.html +++ b/index.html @@ -45,6 +45,9 @@
Secure connection error A secure connection with the WeeChat relay could not be initiated. This is most likely because your browser does not trust your relay's certificate. Please read the encryption instructions below!
+
+ Secure connection error Unable to connect to unencrypted relay when your are connecting to Glowing Bear over HTTPS. Please use an encrypted relay or load the page without using HTTPS. +
diff --git a/js/glowingbear.js b/js/glowingbear.js index 5594461..e62109a 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -242,6 +242,7 @@ function($rootScope, var connect = function (host, port, passwd, ssl, noCompression) { var proto = ssl ? 'wss' : 'ws'; var url = proto + "://" + host + ":" + port + "/weechat"; + $log.debug('Connecting to URL: ', url); var onopen = function () { @@ -375,7 +376,8 @@ function($rootScope, }; - ngWebsockets.connect(url, + try { + ngWebsockets.connect(url, protocol, { 'binaryType': "arraybuffer", @@ -384,6 +386,12 @@ function($rootScope, 'onmessage': onmessage, 'onerror': onerror }); + }catch(e) { + $log.debug("Websocket caught DOMException:", e); + $rootScope.lastError = Date.now(); + $rootScope.errorMessage = true; + $rootScope.securityError = true; + } }; @@ -959,6 +967,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $scope.connect = function() { $scope.requestNotificationPermission(); $rootScope.sslError = false; + $rootScope.securityError = false; $rootScope.errorMessage = false; connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl); }; From fbfeec8fcabcd3f1ec535d459910f3324545c9d7 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Tue, 6 May 2014 21:59:10 +0200 Subject: [PATCH 2/3] Change the connect button text based on connection status --- index.html | 2 +- js/glowingbear.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index a728587..edd85c9 100644 --- a/index.html +++ b/index.html @@ -85,7 +85,7 @@
- +
diff --git a/js/glowingbear.js b/js/glowingbear.js index e62109a..5d75d39 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -345,9 +345,8 @@ function($rootScope, $log.info("Disconnected from relay"); failCallbacks('disconnection'); $rootScope.connected = false; - if ($rootScope.waseverconnected) { - $rootScope.$emit('relayDisconnect'); - } else if (ssl && evt.code === 1006) { + $rootScope.$emit('relayDisconnect'); + if (ssl && evt.code === 1006) { // A password error doesn't trigger onerror, but certificate issues do. Check time of last error. if (typeof $rootScope.lastError !== "undefined" && (Date.now() - $rootScope.lastError) < 1000) { // abnormal disconnect by client, most likely ssl error @@ -643,7 +642,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', } var activeBuffer = models.getActiveBuffer(); - $rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.title; + if (activeBuffer) { + $rootScope.pageTitle = activeBuffer.shortName + ' | ' + activeBuffer.title; + } }; $scope.updateFavico = function() { @@ -730,7 +731,9 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', // Disabled it until it's fully investigated and fixed //models.reinitialize(); $rootScope.$emit('notificationChanged'); + $scope.connectbutton = 'Connect'; }); + $scope.connectbutton = 'Connect'; $scope.showSidebar = true; @@ -969,9 +972,11 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', $rootScope.sslError = false; $rootScope.securityError = false; $rootScope.errorMessage = false; + $scope.connectbutton = 'Connecting ...'; connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl); }; $scope.disconnect = function() { + $scope.connectbutton = 'Connect'; connection.disconnect(); }; $scope.install = function() { From 91b0ddc259184f4ef0c6460d34a5bd64c5f91c83 Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Wed, 7 May 2014 19:15:47 +0200 Subject: [PATCH 3/3] Fix syntax. Emit relaydisconnect so connect button changes --- js/glowingbear.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/glowingbear.js b/js/glowingbear.js index 5d75d39..9141fc2 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -385,11 +385,12 @@ function($rootScope, 'onmessage': onmessage, 'onerror': onerror }); - }catch(e) { + } catch(e) { $log.debug("Websocket caught DOMException:", e); $rootScope.lastError = Date.now(); $rootScope.errorMessage = true; $rootScope.securityError = true; + $rootScope.$emit('relayDisconnect'); } };