diff --git a/static/js/controllers/mediastreamcontroller.js b/static/js/controllers/mediastreamcontroller.js index 53ee71a3..dbff797a 100644 --- a/static/js/controllers/mediastreamcontroller.js +++ b/static/js/controllers/mediastreamcontroller.js @@ -20,7 +20,7 @@ */ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapter'], function(_, BigScreen, moment, sjcl, Modernizr) { - return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing) { + return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", "userSettingsData", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, userSettingsData) { /*console.log("route", $route, $routeParams, $location);*/ @@ -351,11 +351,9 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte mediaStream.webrtc.setAudioMute(cameraMute); }); - // Load stuff from localStorage. - var storedUser = localStorage.getItem("mediastream-user"); - console.log("Found stored user data:", storedUser); + // Load user settings. + var storedUser = userSettingsData.load(); if (storedUser) { - storedUser = JSON.parse(storedUser); $scope.user = $.extend(true, {}, $scope.master, storedUser); $scope.user.settings = $.extend(true, {}, $scope.user.settings, $scope.master.settings, $scope.user.settings); $scope.update($scope.user, true); diff --git a/static/js/directives/settings.js b/static/js/directives/settings.js index 6928c1d4..9711e48e 100644 --- a/static/js/directives/settings.js +++ b/static/js/directives/settings.js @@ -22,7 +22,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t return ["$compile", "mediaStream", function($compile, mediaStream) { - var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', 'localStorage', 'dialogs', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation, localStorage, dialogs) { + var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', 'localStorage', 'dialogs', 'userSettingsData', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation, localStorage, dialogs, userSettingsData) { $scope.layout.settings = false; $scope.showAdvancedSettings = true; @@ -56,10 +56,10 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t $scope.update(user); $scope.layout.settings = false; if ($scope.rememberSettings) { - localStorage.setItem("mediastream-user", JSON.stringify(user)); + userSettingsData.save(user); localStorage.setItem("mediastream-language", user.settings.language || ""); } else { - localStorage.removeItem("mediastream-user"); + userSettingsData.clear(); localStorage.removeItem("mediastream-language"); localStorage.removeItem("mediastream-access-code"); } diff --git a/static/js/services/services.js b/static/js/services/services.js index 597a26cf..7b4cc4ae 100644 --- a/static/js/services/services.js +++ b/static/js/services/services.js @@ -54,7 +54,8 @@ define([ 'services/geolocation', 'services/screensharing', 'services/continueconnector', - 'services/chromeextension'], function(_, + 'services/chromeextension', + 'services/usersettingsdata'], function(_, desktopNotify, playSound, safeApply, @@ -88,7 +89,8 @@ dialogs, geolocation, screensharing, continueConnector, -chromeExtension) { +chromeExtension, +userSettingsData) { var services = { desktopNotify: desktopNotify, @@ -124,7 +126,8 @@ chromeExtension) { geolocation: geolocation, screensharing: screensharing, continueConnector: continueConnector, - chromeExtension: chromeExtension + chromeExtension: chromeExtension, + userSettingsData: userSettingsData }; var initialize = function(angModule) { diff --git a/static/js/services/usersettingsdata.js b/static/js/services/usersettingsdata.js new file mode 100644 index 00000000..b57f23fe --- /dev/null +++ b/static/js/services/usersettingsdata.js @@ -0,0 +1,58 @@ +/* + * Spreed WebRTC. + * Copyright (C) 2013-2014 struktur AG + * + * This file is part of Spreed WebRTC. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +define([], function() { + + // userSettingsData + return ["localStorage", function(localStorage) { + + var UserSettingsData = function(key) { + this.key = key + }; + + UserSettingsData.prototype.getId = function() { + return this.key; + }; + + UserSettingsData.prototype.load = function() { + var raw = localStorage.getItem(this.getId()); + console.log("Found stored user data:", raw); + if (raw) { + try { + return JSON.parse(raw); + } catch(e) {} + } + return null; + }; + + UserSettingsData.prototype.save = function(data) { + var raw = JSON.stringify(data); + localStorage.setItem(this.getId(), raw) + }; + + UserSettingsData.prototype.clear = function() { + localStorage.removeItem(this.getId()); + }; + + return new UserSettingsData("mediastream-user"); + + }]; + +});