Browse Source

Implemented localStorage service.

pull/48/head
Simon Eisenmann 11 years ago
parent
commit
70cdfce628
  1. 3
      static/js/controllers/mediastreamcontroller.js
  2. 2
      static/js/directives/settings.js
  3. 2
      static/js/directives/usability.js
  4. 73
      static/js/services/localstorage.js
  5. 2
      static/js/services/mediastream.js
  6. 9
      static/js/services/services.js

3
static/js/controllers/mediastreamcontroller.js

@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
*/
define(['underscore', 'bigscreen', 'moment', 'sjcl', 'webrtc.adapter'], function(_, BigScreen, moment, sjcl) {
return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload) {
return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage) {
/*console.log("route", $route, $routeParams, $location);*/
@ -344,7 +344,6 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'webrtc.adapter'], function @@ -344,7 +344,6 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'webrtc.adapter'], function
});
// Load stuff from localStorage.
// TODO(longsleep): Put localStorage into Angular service.
var storedUser = localStorage.getItem("mediastream-user");
console.log("Found stored user data:", storedUser);
if (storedUser) {

2
static/js/directives/settings.js

@ -22,7 +22,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -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', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation) {
var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', 'localStorage', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation, localStorage) {
$scope.layout.settings = false;
$scope.showAdvancedSettings = true;

2
static/js/directives/usability.js

@ -24,7 +24,7 @@ define(['jquery', 'underscore', 'text!partials/usability.html'], function($, _, @@ -24,7 +24,7 @@ define(['jquery', 'underscore', 'text!partials/usability.html'], function($, _,
return ["mediaStream", function(mediaStream) {
var controller = ['$scope', "mediaStream", "safeApply", "$timeout", function($scope, mediaStream, safeApply, $timeout) {
var controller = ['$scope', "mediaStream", "safeApply", "$timeout", "localStorage", function($scope, mediaStream, safeApply, $timeout, localStorage) {
var pending = true;
var complete = false;

73
static/js/services/localstorage.js

@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
define(["modernizr"], function(Modernizr) {
// localStorage
return ["$window", function($window) {
// PersistentStorage (c)2014 struktur AG. MIT license.
var PersistentStorage = function(prefix) {
this.prefix = prefix ? prefix : "ps";
this.isPersistentStorage = true;
};
PersistentStorage.prototype.setItem = function(key, data) {
var name = this.prefix+"_"+key;
$window.document.cookie = name + "=" + data + "; path=/";
};
PersistentStorage.prototype.getItem = function(key) {
var name = this.prefix+"_"+key+"=";
var ca = $window.document.cookie.split(';');
for (var i=0; i<ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return null;
};
PersistentStorage.prototype.removeItem = function(key) {
var name = this.prefix+"_"+key;
$window.document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
};
var storage;
if (Modernizr.localStorage) {
storage = $window.localStorage;
} else {
storage = new PersistentStorage();
}
// public API.
return {
setItem: function(key, data) {
return storage.setItem(key, data);
},
getItem: function(key) {
return storage.getItem(key);
},
removeItem: function(key) {
return storage.removeItem(key);
}
}
}];
});

2
static/js/services/mediastream.js

@ -29,7 +29,7 @@ define([ @@ -29,7 +29,7 @@ define([
], function($, _, uaparser, Connector, Api, WebRTC, tokens) {
return ["globalContext", "$route", "$location", "$window", "visibility", "alertify", "$http", "safeApply", "$timeout", "$sce", function(context, $route, $location, $window, visibility, alertify, $http, safeApply, $timeout, $sce) {
return ["globalContext", "$route", "$location", "$window", "visibility", "alertify", "$http", "safeApply", "$timeout", "$sce", "localStorage", function(context, $route, $location, $window, visibility, alertify, $http, safeApply, $timeout, $sce, localStorage) {
var url = (context.Ssl ? "wss" : "ws") + "://" + context.Host + (context.Cfg.B || "/") + "ws";
var version = context.Cfg.Version || "unknown";

9
static/js/services/services.js

@ -46,7 +46,8 @@ define([ @@ -46,7 +46,8 @@ define([
'services/videolayout',
'services/contactdata',
'services/contacts',
'services/buddysession'], function(_,
'services/buddysession',
'services/localstorage'], function(_,
desktopNotify,
playSound,
safeApply,
@ -72,7 +73,8 @@ videoWaiter, @@ -72,7 +73,8 @@ videoWaiter,
videoLayout,
contactData,
contacts,
buddySession) {
buddySession,
localStorage) {
var services = {
desktopNotify: desktopNotify,
@ -100,7 +102,8 @@ buddySession) { @@ -100,7 +102,8 @@ buddySession) {
videoLayout: videoLayout,
contactData: contactData,
contacts: contacts,
buddySession: buddySession
buddySession: buddySession,
localStorage: localStorage
};
var initialize = function(angModule) {

Loading…
Cancel
Save