Browse Source

Added service to build requestAnimationFrame calls.

pull/48/head
Simon Eisenmann 11 years ago committed by Simon Eisenmann
parent
commit
28ad495a63
  1. 26
      static/js/directives/audiolevel.js
  2. 8
      static/js/directives/audiovideo.js
  3. 51
      static/js/services/animationframe.js
  4. 9
      static/js/services/buddylist.js
  5. 9
      static/js/services/services.js

26
static/js/directives/audiolevel.js

@ -18,11 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
define(['jquery', 'underscore', 'rAF'], function($, _) { define(['jquery', 'underscore'], function($, _) {
return ["$window", "mediaStream", "safeApply", function($window, mediaStream, safeApply) { return ["$window", "mediaStream", "safeApply", "animationFrame", function($window, mediaStream, safeApply, animationFrame) {
var requestAnimationFrame = $window.requestAnimationFrame;
var webrtc = mediaStream.webrtc; var webrtc = mediaStream.webrtc;
// Consider anyting lower than this % as no audio. // Consider anyting lower than this % as no audio.
@ -43,21 +42,22 @@ define(['jquery', 'underscore', 'rAF'], function($, _) {
// Own audio level indicator. // Own audio level indicator.
var element = $element[0]; var element = $element[0];
var width = 0;
this.update = _.bind(function() { this.update = _.bind(function() {
if (this.active) { if (this.active || width > 0) {
requestAnimationFrame(this.update); if (webrtc.usermedia.audioLevel) {
} width = Math.round(100 * webrtc.usermedia.audioLevel);
var width = 0; // Hide low volumes.
if (webrtc.usermedia.audioLevel) { if (width < threshhold) {
width = Math.round(100 * webrtc.usermedia.audioLevel); width = 0;
// Hide low volumes. }
if (width < threshhold) { } else {
width = 0; width = 0;
} }
element.style.width = width + '%';
} }
element.style.width = width + '%';
}, this); }, this);
this.update(); animationFrame.register(this.update);
// Talking state. // Talking state.
this.audioActivityHistory = []; this.audioActivityHistory = [];

8
static/js/directives/audiovideo.js

@ -18,11 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/audiovideopeer.html', 'bigscreen', 'injectCSS', 'webrtc.adapter', 'rAF'], function($, _, template, templatePeer, BigScreen) { define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/audiovideopeer.html', 'bigscreen', 'injectCSS', 'webrtc.adapter'], function($, _, template, templatePeer, BigScreen) {
return ["$window", "$compile", "$filter", "mediaStream", "safeApply", "desktopNotify", "buddyData", "videoWaiter", "videoLayout", function($window, $compile, $filter, mediaStream, safeApply, desktopNotify, buddyData, videoWaiter, videoLayout) { return ["$window", "$compile", "$filter", "mediaStream", "safeApply", "desktopNotify", "buddyData", "videoWaiter", "videoLayout", "animationFrame", function($window, $compile, $filter, mediaStream, safeApply, desktopNotify, buddyData, videoWaiter, videoLayout, animationFrame) {
var requestAnimationFrame = $window.requestAnimationFrame;
var peerTemplate = $compile(templatePeer); var peerTemplate = $compile(templatePeer);
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
@ -316,9 +315,8 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
needsRedraw = false; needsRedraw = false;
redraw(); redraw();
} }
requestAnimationFrame(update);
} }
_.defer(update); animationFrame.register(update);
} }

51
static/js/services/animationframe.js

@ -0,0 +1,51 @@
/*
* 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(["underscore", "rAF"], function(_) {
// animationFrame
return ["$window", function($window) {
var requestAnimationFrame = $window.requestAnimationFrame;
var registry = [];
var caller = function(f) {
f();
};
var worker = function() {
registry.forEach(caller)
requestAnimationFrame(worker);
};
// Public api.
var animationFrame = {
register: function(f) {
registry.push(f);
}
};
// Auto start worker.
_.defer(worker);
return animationFrame;
}];
});

9
static/js/services/buddylist.js

@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!partials/buddyactions.html', 'text!partials/buddyactionsforaudiomixer.html', 'rAF'], function(_, Modernizr, AvlTree, templateBuddy, templateBuddyActions, templateBuddyActionsForAudioMixer) { define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!partials/buddyactions.html', 'text!partials/buddyactionsforaudiomixer.html'], function(_, Modernizr, AvlTree, templateBuddy, templateBuddyActions, templateBuddyActionsForAudioMixer) {
var BuddyTree = function() { var BuddyTree = function() {
@ -129,9 +129,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
}; };
// buddyList // buddyList
return ["$window", "$compile", "playSound", "buddyData", "buddySession", "fastScroll", "mediaStream", function($window, $compile, playSound, buddyData, buddySession, fastScroll, mediaStream) { return ["$window", "$compile", "playSound", "buddyData", "buddySession", "fastScroll", "mediaStream", "animationFrame", function($window, $compile, playSound, buddyData, buddySession, fastScroll, mediaStream, animationFrame) {
var requestAnimationFrame = $window.requestAnimationFrame;
var buddyTemplate = $compile(templateBuddy); var buddyTemplate = $compile(templateBuddy);
var buddyActions = $compile(templateBuddyActions); var buddyActions = $compile(templateBuddyActions);
@ -180,9 +178,8 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
$window.setInterval(_.bind(this.soundLoop, this), 500); $window.setInterval(_.bind(this.soundLoop, this), 500);
var update = _.bind(function refreshBuddies() { var update = _.bind(function refreshBuddies() {
this.refreshBuddies(); this.refreshBuddies();
requestAnimationFrame(update);
}, this); }, this);
requestAnimationFrame(update); animationFrame.register(update);
}; };

9
static/js/services/services.js

@ -47,7 +47,8 @@ define([
'services/contactdata', 'services/contactdata',
'services/contacts', 'services/contacts',
'services/buddysession', 'services/buddysession',
'services/localstorage'], function(_, 'services/localstorage',
'services/animationframe'], function(_,
desktopNotify, desktopNotify,
playSound, playSound,
safeApply, safeApply,
@ -74,7 +75,8 @@ videoLayout,
contactData, contactData,
contacts, contacts,
buddySession, buddySession,
localStorage) { localStorage,
animationFrame) {
var services = { var services = {
desktopNotify: desktopNotify, desktopNotify: desktopNotify,
@ -103,7 +105,8 @@ localStorage) {
contactData: contactData, contactData: contactData,
contacts: contacts, contacts: contacts,
buddySession: buddySession, buddySession: buddySession,
localStorage: localStorage localStorage: localStorage,
animationFrame: animationFrame
}; };
var initialize = function(angModule) { var initialize = function(angModule) {

Loading…
Cancel
Save