diff --git a/static/js/directives/audiolevel.js b/static/js/directives/audiolevel.js
index e8f91d02..74fd62d9 100644
--- a/static/js/directives/audiolevel.js
+++ b/static/js/directives/audiolevel.js
@@ -18,11 +18,10 @@
* along with this program. If not, see .
*
*/
-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;
// Consider anyting lower than this % as no audio.
@@ -43,21 +42,22 @@ define(['jquery', 'underscore', 'rAF'], function($, _) {
// Own audio level indicator.
var element = $element[0];
+ var width = 0;
this.update = _.bind(function() {
- if (this.active) {
- requestAnimationFrame(this.update);
- }
- var width = 0;
- if (webrtc.usermedia.audioLevel) {
- width = Math.round(100 * webrtc.usermedia.audioLevel);
- // Hide low volumes.
- if (width < threshhold) {
+ if (this.active || width > 0) {
+ if (webrtc.usermedia.audioLevel) {
+ width = Math.round(100 * webrtc.usermedia.audioLevel);
+ // Hide low volumes.
+ if (width < threshhold) {
+ width = 0;
+ }
+ } else {
width = 0;
}
+ element.style.width = width + '%';
}
- element.style.width = width + '%';
}, this);
- this.update();
+ animationFrame.register(this.update);
// Talking state.
this.audioActivityHistory = [];
diff --git a/static/js/directives/audiovideo.js b/static/js/directives/audiovideo.js
index 160b12c1..60243c1d 100644
--- a/static/js/directives/audiovideo.js
+++ b/static/js/directives/audiovideo.js
@@ -18,11 +18,10 @@
* along with this program. If not, see .
*
*/
-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 controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
@@ -316,9 +315,8 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
needsRedraw = false;
redraw();
}
- requestAnimationFrame(update);
}
- _.defer(update);
+ animationFrame.register(update);
}
diff --git a/static/js/services/animationframe.js b/static/js/services/animationframe.js
new file mode 100644
index 00000000..dd6f43b4
--- /dev/null
+++ b/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 .
+ *
+ */
+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;
+
+ }];
+
+});
diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js
index 71666833..ffb81475 100644
--- a/static/js/services/buddylist.js
+++ b/static/js/services/buddylist.js
@@ -18,7 +18,7 @@
* along with this program. If not, see .
*
*/
-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() {
@@ -129,9 +129,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
};
// buddyList
- return ["$window", "$compile", "playSound", "buddyData", "buddySession", "fastScroll", "mediaStream", function($window, $compile, playSound, buddyData, buddySession, fastScroll, mediaStream) {
-
- var requestAnimationFrame = $window.requestAnimationFrame;
+ return ["$window", "$compile", "playSound", "buddyData", "buddySession", "fastScroll", "mediaStream", "animationFrame", function($window, $compile, playSound, buddyData, buddySession, fastScroll, mediaStream, animationFrame) {
var buddyTemplate = $compile(templateBuddy);
var buddyActions = $compile(templateBuddyActions);
@@ -180,9 +178,8 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text!
$window.setInterval(_.bind(this.soundLoop, this), 500);
var update = _.bind(function refreshBuddies() {
this.refreshBuddies();
- requestAnimationFrame(update);
}, this);
- requestAnimationFrame(update);
+ animationFrame.register(update);
};
diff --git a/static/js/services/services.js b/static/js/services/services.js
index 4bc5852b..c95a5205 100644
--- a/static/js/services/services.js
+++ b/static/js/services/services.js
@@ -47,7 +47,8 @@ define([
'services/contactdata',
'services/contacts',
'services/buddysession',
- 'services/localstorage'], function(_,
+ 'services/localstorage',
+ 'services/animationframe'], function(_,
desktopNotify,
playSound,
safeApply,
@@ -74,7 +75,8 @@ videoLayout,
contactData,
contacts,
buddySession,
-localStorage) {
+localStorage,
+animationFrame) {
var services = {
desktopNotify: desktopNotify,
@@ -103,7 +105,8 @@ localStorage) {
contactData: contactData,
contacts: contacts,
buddySession: buddySession,
- localStorage: localStorage
+ localStorage: localStorage,
+ animationFrame: animationFrame
};
var initialize = function(angModule) {