Fixes an error caused by trying to get a property of undefined related to audio levels.

This commit is contained in:
Lyubomir Marinov 2014-07-23 19:05:56 +03:00
parent 05975e30a3
commit e9a3b45316
2 changed files with 25 additions and 5 deletions

View File

@ -117,15 +117,27 @@ var AudioLevels = (function(my) {
var audioLevelCanvasOrig = $('#' + videoSpanId + '>canvas').get(0);
audioLevelCanvasCache[resourceJid]
= CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
/*
* FIXME Testing has shown that audioLevelCanvasOrig may not exist.
* In such a case, the method CanvasUtil.cloneCanvas may throw an
* error. Since audio levels are frequently updated, the errors have
* been observed to pile into the console, strain the CPU.
*/
if (audioLevelCanvasOrig)
{
audioLevelCanvasCache[resourceJid]
= CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
}
}
var canvas = audioLevelCanvasCache[resourceJid];
if (!canvas)
return;
var drawContext = canvas.getContext('2d');
drawContext.clearRect (0, 0, canvas.width, canvas.height);
drawContext.clearRect(0, 0, canvas.width, canvas.height);
var shadowLevel = getShadowLevel(audioLevel);
@ -190,4 +202,4 @@ var AudioLevels = (function(my) {
return my;
})(AudioLevels || {});
})(AudioLevels || {});

View File

@ -81,6 +81,14 @@ var CanvasUtil = (function(my) {
* @return the new cloned canvas.
*/
my.cloneCanvas = function (oldCanvas) {
/*
* FIXME Testing has shown that oldCanvas may not exist. In such a case,
* the method CanvasUtil.cloneCanvas may throw an error. Since audio
* levels are frequently updated, the errors have been observed to pile
* into the console, strain the CPU.
*/
if (!oldCanvas)
return oldCanvas;
//create a new canvas
var newCanvas = document.createElement('canvas');
@ -98,4 +106,4 @@ var CanvasUtil = (function(my) {
};
return my;
})(CanvasUtil || {});
})(CanvasUtil || {});