Browse Source

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

pull/100/head
Simon Eisenmann 12 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 @@
*/ */
define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapter'], function(_, BigScreen, moment, sjcl, Modernizr) { 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);*/ /*console.log("route", $route, $routeParams, $location);*/
@ -157,7 +157,6 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
$scope.master = angular.copy($scope.defaults); $scope.master = angular.copy($scope.defaults);
// Data voids. // Data voids.
var cache = {};
var resurrect = null; var resurrect = null;
var reconnecting = false; var reconnecting = false;
var connected = false; var connected = false;
@ -187,20 +186,17 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
return $scope.status; return $scope.status;
}; };
$scope.updateStatus = function() { $scope.updateStatus = function(clear) {
// This is the user status. // This is the user status.
var status = { var status = {
displayName: $scope.master.displayName || null, displayName: $scope.master.displayName || null,
buddyPicture: $scope.master.buddyPicture || null, buddyPicture: $scope.master.buddyPicture || null,
message: $scope.master.message || null message: $scope.master.message || null
} }
if (_.isEqual(status, cache.status)) { if (clear) {
//console.log("Status update skipped, as status has not changed.") localStatus.clear();
} else {
//console.log("Updating own status", JSON.stringify(status));
mediaStream.api.updateStatus(status);
cache.status = _.clone(status);
} }
localStatus.update(status);
}; };
$scope.refreshWebrtcSettings = function() { $scope.refreshWebrtcSettings = function() {
@ -554,8 +550,7 @@ define(['underscore', 'bigscreen', 'moment', 'sjcl', 'modernizr', 'webrtc.adapte
t = "waiting"; t = "waiting";
connected = true; connected = true;
reconnecting = false; reconnecting = false;
cache = {}; // Start fresh. $scope.updateStatus(true);
$scope.updateStatus();
if (opts.soft) { if (opts.soft) {
return; return;
} }

4
static/js/services/buddylist.js

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

62
static/js/services/localstatus.js

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

Loading…
Cancel
Save