Fixes audio level interface in the single user in conference case.

This commit is contained in:
yanas 2014-07-24 16:14:37 +02:00
parent 1dcbf7fce6
commit 913cdb9c7a
2 changed files with 32 additions and 21 deletions

7
app.js
View File

@ -293,7 +293,8 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
data.stream.onended = function () { data.stream.onended = function () {
console.log('stream ended', this.id); console.log('stream ended', this.id);
// Mark video as removed to cancel waiting loop(if video is removed before has started) // Mark video as removed to cancel waiting loop(if video is removed
// before has started)
sel.removed = true; sel.removed = true;
sel.remove(); sel.remove();
@ -455,7 +456,6 @@ function statsUpdated(statsCollector)
var peerStats = statsCollector.jid2stats[jid]; var peerStats = statsCollector.jid2stats[jid];
Object.keys(peerStats.ssrc2AudioLevel).forEach(function (ssrc) Object.keys(peerStats.ssrc2AudioLevel).forEach(function (ssrc)
{ {
if (jid !== connection.emuc.myRoomJid)
AudioLevels.updateAudioLevel( Strophe.getResourceFromJid(jid), AudioLevels.updateAudioLevel( Strophe.getResourceFromJid(jid),
peerStats.ssrc2AudioLevel[ssrc]); peerStats.ssrc2AudioLevel[ssrc]);
}); });
@ -469,9 +469,8 @@ function statsUpdated(statsCollector)
*/ */
function localStatsUpdated(statsCollector) function localStatsUpdated(statsCollector)
{ {
if (connection.emuc.myRoomJid)
AudioLevels.updateAudioLevel( AudioLevels.updateAudioLevel(
Strophe.getResourceFromJid(connection.emuc.myRoomJid), AudioLevels.LOCAL_LEVEL,
statsCollector.audioLevel); statsCollector.audioLevel);
} }

View File

@ -7,6 +7,8 @@ var AudioLevels = (function(my) {
var SHADOW_COLOR = '#00ccff'; var SHADOW_COLOR = '#00ccff';
var audioLevelCanvasCache = {}; var audioLevelCanvasCache = {};
my.LOCAL_LEVEL = 'local';
/** /**
* Updates the audio level canvas for the given peerJid. If the canvas * Updates the audio level canvas for the given peerJid. If the canvas
* didn't exist we create it. * didn't exist we create it.
@ -71,12 +73,7 @@ var AudioLevels = (function(my) {
my.updateAudioLevel = function (resourceJid, audioLevel) { my.updateAudioLevel = function (resourceJid, audioLevel) {
drawAudioLevelCanvas(resourceJid, audioLevel); drawAudioLevelCanvas(resourceJid, audioLevel);
var videoSpanId = null; var videoSpanId = getVideoSpanId(resourceJid);
if (resourceJid
=== Strophe.getResourceFromJid(connection.emuc.myroomjid))
videoSpanId = 'localVideoContainer';
else
videoSpanId = 'participant_' + resourceJid;
var audioLevelCanvas = $('#' + videoSpanId + '>canvas').get(0); var audioLevelCanvas = $('#' + videoSpanId + '>canvas').get(0);
@ -92,6 +89,9 @@ var AudioLevels = (function(my) {
drawContext.drawImage(canvasCache, 0, 0); drawContext.drawImage(canvasCache, 0, 0);
}; };
/**
* Resizes the given audio level canvas to match the given thumbnail size.
*/
function resizeAudioLevelCanvas(audioLevelCanvas, function resizeAudioLevelCanvas(audioLevelCanvas,
thumbnailWidth, thumbnailWidth,
thumbnailHeight) { thumbnailHeight) {
@ -108,12 +108,8 @@ var AudioLevels = (function(my) {
*/ */
function drawAudioLevelCanvas(resourceJid, audioLevel) { function drawAudioLevelCanvas(resourceJid, audioLevel) {
if (!audioLevelCanvasCache[resourceJid]) { if (!audioLevelCanvasCache[resourceJid]) {
var videoSpanId = null;
if (resourceJid var videoSpanId = getVideoSpanId(resourceJid);
=== Strophe.getResourceFromJid(connection.emuc.myroomjid))
videoSpanId = 'localVideoContainer';
else
videoSpanId = 'participant_' + resourceJid;
var audioLevelCanvasOrig = $('#' + videoSpanId + '>canvas').get(0); var audioLevelCanvasOrig = $('#' + videoSpanId + '>canvas').get(0);
@ -173,6 +169,22 @@ var AudioLevels = (function(my) {
return shadowLevel; return shadowLevel;
}; };
/**
* Returns the video span id corresponding to the given resourceJid or local
* user.
*/
function getVideoSpanId(resourceJid) {
var videoSpanId = null;
if (resourceJid === AudioLevels.LOCAL_LEVEL
|| (connection.emuc.myroomjid && resourceJid
=== Strophe.getResourceFromJid(connection.emuc.myroomjid)))
videoSpanId = 'localVideoContainer';
else
videoSpanId = 'participant_' + resourceJid;
return videoSpanId;
};
/** /**
* Indicates that the remote video has been resized. * Indicates that the remote video has been resized.
*/ */