From aade700627db0e853f87dbf3107293de10b488f3 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Tue, 18 Nov 2014 14:24:51 +0100 Subject: [PATCH] Fixed room join when not logged in by fixing authorizing flag (now in appData service). --- .../js/controllers/mediastreamcontroller.js | 7 ++- static/js/services/appdata.js | 58 ++++++++++++------- static/js/services/mediastream.js | 17 ++---- static/js/services/rooms.js | 4 +- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/static/js/controllers/mediastreamcontroller.js b/static/js/controllers/mediastreamcontroller.js index 0b9df218..ee5bb48b 100644 --- a/static/js/controllers/mediastreamcontroller.js +++ b/static/js/controllers/mediastreamcontroller.js @@ -396,17 +396,18 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder // Unmark authorization process. if (data.Userid) { - $rootScope.authorizing(false); - $rootScope.$broadcast("authorization.succeeded"); - } else if (!$rootScope.authorizing()) { + appData.authorizing(false); + } else if (!appData.authorizing()) { // Trigger user data load when not in authorizing phase. $scope.loadUserSettings(); } + // Select room if settings have an alternative default room. if (rooms.inDefaultRoom() && $scope.master.settings.defaultRoom) { console.log("Selecting default room from settings:", [$scope.master.settings.defaultRoom]); rooms.joinByName($scope.master.settings.defaultRoom, true); } + }); mediaStream.webrtc.e.on("peercall", function(event, peercall) { diff --git a/static/js/services/appdata.js b/static/js/services/appdata.js index 2ed21d6b..6cbcb735 100644 --- a/static/js/services/appdata.js +++ b/static/js/services/appdata.js @@ -37,33 +37,49 @@ define(["jquery"], function($) { // // - mainStatus(event, status) // status (string) : Status id (connected, waiting, ...) - + // + // - authorizing(event, flag) + // flag (bool) : True if authorizing, else false. + // // appData properties: // // - language (string): ISO language code of active language // appData - return ["randomGen", function(randomGen) { + return ["randomGen", "$window", function(randomGen, $window) { + + var service = this; + + service.e = $({}); + service.data = null; + service.flags = { + authorizing: false + }; + + service.language = $window.document.getElementsByTagName("html")[0].getAttribute("lang"); + service.id = randomGen.id(); + + service.get = function() { + return service.data; + }; + service.set = function(d) { + service.data = d; + return d; + }; + service.authorizing = function(value) { + // Boolean flag to indicate that an authentication is currently in progress. + if (typeof(value) !== "undefined") { + var v = !!value; + if (v !== service.flags.authorizing) { + service.flags.authorizing = v; + service.e.triggerHandler("authorizing", v); + } + } + return service.flags.authorizing; + }; - var data = { - data: null, - e: $({}) - } - var html = document.getElementsByTagName("html")[0]; - var appData = { - id: randomGen.id(), - get: function() { - return data.data; - }, - set: function(d) { - data.data = d; - return d; - }, - e: data.e, - language: html.getAttribute("lang") - } - console.info("App runtime id: "+appData.id); - return appData; + console.info("App runtime id: "+service.id); + return service; }]; diff --git a/static/js/services/mediastream.js b/static/js/services/mediastream.js index e5e4c2e7..cef9fde8 100644 --- a/static/js/services/mediastream.js +++ b/static/js/services/mediastream.js @@ -28,7 +28,7 @@ define([ ], function($, _, uaparser, sjcl, Modernizr, tokens) { - return ["globalContext", "connector", "api", "webrtc", "$rootScope", "$route", "$location", "$window", "visibility", "alertify", "$http", "safeApply", "$timeout", "$sce", "localStorage", "continueConnector", "restURL", function(context, connector, api, webrtc, $rootScope, $route, $location, $window, visibility, alertify, $http, safeApply, $timeout, $sce, localStorage, continueConnector, restURL) { + return ["globalContext", "connector", "api", "webrtc", "appData", "$route", "$location", "$window", "visibility", "alertify", "$http", "safeApply", "$timeout", "$sce", "localStorage", "continueConnector", "restURL", function(context, connector, api, webrtc, appData, $route, $location, $window, visibility, alertify, $http, safeApply, $timeout, $sce, localStorage, continueConnector, restURL) { var url = (context.Ssl ? "wss" : "ws") + "://" + context.Host + (context.Cfg.B || "/") + "ws"; var version = context.Cfg.Version; @@ -41,15 +41,6 @@ define([ // Create encryption key from server token and browser name. var secureKey = sjcl.codec.base64.fromBits(sjcl.hash.sha256.hash(context.Cfg.Token + uaparser().browser.name)); - var authorizing = context.Cfg.UsersEnabled; - $rootScope.authorizing = function(value) { - // Boolean flag to indicate that an authentication is currently in progress. - if (typeof(value) !== "undefined") { - authorizing = !!value; - } - return authorizing; - }; - var mediaStream = { version: version, ws: url, @@ -127,7 +118,7 @@ define([ } }, authorize: function(data, success_cb, error_cb) { - $rootScope.authorizing(true); + appData.authorizing(true); var url = restURL.api("sessions") + "/" + mediaStream.api.id + "/"; var login = _.clone(data); login.id = mediaStream.api.id; @@ -144,14 +135,14 @@ define([ if (data.nonce !== "" && data.success) { success_cb(data, status); } else { - $rootScope.authorizing(false); + appData.authorizing(false); if (error_cb) { error_cb(data, status); } } }). error(function(data, status) { - $rootScope.authorizing(false); + appData.authorizing(false); if (error_cb) { error_cb(data, status) } diff --git a/static/js/services/rooms.js b/static/js/services/rooms.js index bae3d9c1..5baf3d3d 100644 --- a/static/js/services/rooms.js +++ b/static/js/services/rooms.js @@ -23,7 +23,7 @@ define([ 'jquery' ], function(angular, $) { - return ["$window", "$location", "$timeout", "$q", "$route", "$rootScope", "$http", "globalContext", "safeApply", "connector", "api", "restURL", "roompin", function($window, $location, $timeout, $q, $route, $rootScope, $http, globalContext, safeApply, connector, api, restURL, roompin) { + return ["$window", "$location", "$timeout", "$q", "$route", "$rootScope", "$http", "globalContext", "safeApply", "connector", "api", "restURL", "roompin", "appData", function($window, $location, $timeout, $q, $route, $rootScope, $http, globalContext, safeApply, connector, api, restURL, roompin, appData) { var url = restURL.api("rooms"); var requestedRoomName = ""; var currentRoom = null; @@ -55,7 +55,7 @@ define([ }; var joinRequestedRoom = function() { - if ($rootScope.authorizing()) { + if (appData.authorizing()) { // Do nothing while authorizing. return; }