Browse Source

Implemented update status throttle delay to avoid updating status too often.

pull/100/head
Simon Eisenmann 11 years ago
parent
commit
f689fd0416
  1. 17
      static/js/controllers/mediastreamcontroller.js
  2. 4
      static/js/services/buddylist.js
  3. 62
      static/js/services/localstatus.js
  4. 11
      static/js/services/services.js

17
static/js/controllers/mediastreamcontroller.js

@ -20,7 +20,7 @@ @@ -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", "userSettingsData", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, userSettingsData) {
return ["$scope", "$rootScope", "$element", "$window", "$timeout", "safeDisplayName", "safeApply", "mediaStream", "appData", "playSound", "desktopNotify", "alertify", "toastr", "translation", "fileDownload", "localStorage", "screensharing", "userSettingsData", "localStatus", function($scope, $rootScope, $element, $window, $timeout, safeDisplayName, safeApply, mediaStream, appData, playSound, desktopNotify, alertify, toastr, translation, fileDownload, localStorage, screensharing, userSettingsData, localStatus) {
/*console.log("route", $route, $routeParams, $location);*/
@ -157,7 +157,6 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte @@ -157,7 +157,6 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
$scope.master = angular.copy($scope.defaults);
// Data voids.
var cache = {};
var resurrect = null;
var reconnecting = false;
var connected = false;
@ -187,20 +186,17 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte @@ -187,20 +186,17 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
return $scope.status;
};
$scope.updateStatus = function() {
$scope.updateStatus = function(clear) {
// This is the user status.
var status = {
displayName: $scope.master.displayName || null,
buddyPicture: $scope.master.buddyPicture || null,
message: $scope.master.message || null
}
if (_.isEqual(status, cache.status)) {
//console.log("Status update skipped, as status has not changed.")
} else {
//console.log("Updating own status", JSON.stringify(status));
mediaStream.api.updateStatus(status);
cache.status = _.clone(status);
if (clear) {
localStatus.clear();
}
localStatus.update(status);
};
$scope.refreshWebrtcSettings = function() {
@ -554,8 +550,7 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte @@ -554,8 +550,7 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
t = "waiting";
connected = true;
reconnecting = false;
cache = {}; // Start fresh.
$scope.updateStatus();
$scope.updateStatus(true);
if (opts.soft) {
return;
}

4
static/js/services/buddylist.js

@ -401,6 +401,10 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -401,6 +401,10 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
//console.log("updateDisplay", data, scope);
var status = data.Status;
if (!status) {
return;
}
var display = scope.display;
var contact = scope.contact && scope.contact.Status;
// Update display name.

62
static/js/services/localstatus.js

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
/*
* 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(['angular', 'underscore'], function(angular, underscore) {
// localStatus
return ["mediaStream", "$window", function(mediaStream, $window) {
var current = null;
var commit = false;
var localStatus = {
update: function(status) {
// Put into current.
if (current && _.isEqual(status, current)) {
return;
}
//console.log("Status update", status);
current = angular.copy(status);
if (!commit) {
commit = true;
$window.setTimeout(localStatus.commit, 1000)
}
},
commit: function() {
// TODO(longsleep): Delay the commit until connection has been established for a while and authentication is complete.
if (commit) {
commit = false;
//console.log("Status update commit", current);
mediaStream.api.updateStatus(current);
}
},
clear: function() {
current = null;
},
get: function() {
return current;
}
};
return localStatus;
}];
});

11
static/js/services/services.js

@ -55,7 +55,8 @@ define([ @@ -55,7 +55,8 @@ define([
'services/screensharing',
'services/continueconnector',
'services/chromeextension',
'services/usersettingsdata'], function(_,
'services/usersettingsdata',
'services/localstatus'], function(_,
desktopNotify,
playSound,
safeApply,
@ -90,7 +91,8 @@ geolocation, @@ -90,7 +91,8 @@ geolocation,
screensharing,
continueConnector,
chromeExtension,
userSettingsData) {
userSettingsData,
localStatus) {
var services = {
desktopNotify: desktopNotify,
@ -127,14 +129,15 @@ userSettingsData) { @@ -127,14 +129,15 @@ userSettingsData) {
screensharing: screensharing,
continueConnector: continueConnector,
chromeExtension: chromeExtension,
userSettingsData: userSettingsData
userSettingsData: userSettingsData,
localStatus: localStatus
};
var initialize = function(angModule) {
_.each(services, function(service, name) {
angModule.factory(name, service);
})
}
};
return {
initialize: initialize

Loading…
Cancel
Save