Browse Source

Added service to build requestAnimationFrame calls.

pull/48/head
Simon Eisenmann 11 years ago committed by Simon Eisenmann
parent
commit
28ad495a63
  1. 16
      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

16
static/js/directives/audiolevel.js

@ -18,11 +18,10 @@ @@ -18,11 +18,10 @@
* 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;
// Consider anyting lower than this % as no audio.
@ -43,21 +42,22 @@ define(['jquery', 'underscore', 'rAF'], function($, _) { @@ -43,21 +42,22 @@ define(['jquery', 'underscore', 'rAF'], function($, _) {
// Own audio level indicator.
var element = $element[0];
this.update = _.bind(function() {
if (this.active) {
requestAnimationFrame(this.update);
}
var width = 0;
this.update = _.bind(function() {
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 + '%';
}
}, this);
this.update();
animationFrame.register(this.update);
// Talking state.
this.audioActivityHistory = [];

8
static/js/directives/audiovideo.js

@ -18,11 +18,10 @@ @@ -18,11 +18,10 @@
* 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 controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
@ -316,9 +315,8 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/ @@ -316,9 +315,8 @@ define(['jquery', 'underscore', 'text!partials/audiovideo.html', 'text!partials/
needsRedraw = false;
redraw();
}
requestAnimationFrame(update);
}
_.defer(update);
animationFrame.register(update);
}

51
static/js/services/animationframe.js

@ -0,0 +1,51 @@ @@ -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 @@ @@ -18,7 +18,7 @@
* 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() {
@ -129,9 +129,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! @@ -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! @@ -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);
};

9
static/js/services/services.js

@ -47,7 +47,8 @@ define([ @@ -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, @@ -74,7 +75,8 @@ videoLayout,
contactData,
contacts,
buddySession,
localStorage) {
localStorage,
animationFrame) {
var services = {
desktopNotify: desktopNotify,
@ -103,7 +105,8 @@ localStorage) { @@ -103,7 +105,8 @@ localStorage) {
contactData: contactData,
contacts: contacts,
buddySession: buddySession,
localStorage: localStorage
localStorage: localStorage,
animationFrame: animationFrame
};
var initialize = function(angModule) {

Loading…
Cancel
Save