From e50be0e3b956e9a297f07f4099358593f135d78f Mon Sep 17 00:00:00 2001 From: paweldomas Date: Fri, 28 Mar 2014 13:48:51 +0100 Subject: [PATCH] Fixes extension version parsing. Increases extension version. --- config.js | 2 +- desktopsharing.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/config.js b/config.js index 6566d727e..be326bf83 100644 --- a/config.js +++ b/config.js @@ -11,5 +11,5 @@ var config = { bosh: '//lambada.jitsi.net/http-bind', // FIXME: use xep-0156 for that desktopSharing: 'ext', // Desktop sharing method. Can be set to 'ext', 'webrtc' or false to disable. chromeExtensionId: 'diibjkoicjeejcmhdnailmkgecihlobk', // Id of desktop streamer Chrome extension - minChromeExtVersion: '0.0.10' // Required version of Chrome extension + minChromeExtVersion: '0.1' // Required version of Chrome extension }; \ No newline at end of file diff --git a/desktopsharing.js b/desktopsharing.js index 43e97bb0c..8e6179c3f 100644 --- a/desktopsharing.js +++ b/desktopsharing.js @@ -202,7 +202,7 @@ function checkExtInstalled(isInstalledCallback) { // Check installed extension version var extVersion = response.version; console.log('Extension version is: '+extVersion); - var updateRequired = extVersion < config.minChromeExtVersion; + var updateRequired = isUpdateRequired(config.minChromeExtVersion, extVersion); if(updateRequired) { alert( 'Jitsi Desktop Streamer requires update. ' + @@ -214,6 +214,50 @@ function checkExtInstalled(isInstalledCallback) { ); } +/** + * Checks whether extension update is required. + * @param minVersion minimal required version + * @param extVersion current extension version + * @returns {boolean} + */ +function isUpdateRequired(minVersion, extVersion) +{ + try + { + var s1 = minVersion.split('.'); + var s2 = extVersion.split('.'); + + var len = Math.max(s1.length, s2.length); + for(var i = 0; i < len; i++) + { + var n1=0,n2=0; + + if(i < s1.length) + n1 = parseInt(s1[i]); + if(i < s2.length) + n2 = parseInt(s2[i]); + + if(isNaN(n1) || isNaN(n2)) + { + return true; + } + else if(n1 !== n2) + { + return n1 > n2; + } + } + + // will happen if boths version has identical numbers in + // their components (even if one of them is longer, has more components) + return false; + } + catch(e) + { + console.error("Failed to parse extension version", e); + return true; + } +} + function doGetStreamFromExtension(streamCallback, failCallback) { // Sends 'getStream' msg to the extension. Extension id must be defined in the config. chrome.runtime.sendMessage(