From 36d202585c4daf78353d1deb62736e3b452b67a9 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sat, 24 May 2014 13:28:07 +0200 Subject: [PATCH] Don't loop to check if MoH is needed Instead, start it once when you join the room, and check each time a peer leaves if it must be re-enabled --- public/js/vroom.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index f5bdd12..6b2fcf0 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -589,6 +589,17 @@ function initVroom(room) { peers.local.videoPaused = false; } + // Check if MoH is needed + function checkMoh(){ + if (!moh && Object.keys(peers).length < 2){ + if (!$('#pauseMohButton').is(':checked')){ + $('#mohPlayer')[0].play(); + moh = true; + } + $('.aloneEl').show(200); + } + } + // An owner is muting/unmuting ourself webrtc.on('owner_toggle_mute', function(data){ // Ignore this if the remote peer isn't the owner of the room @@ -912,16 +923,7 @@ function initVroom(room) { } } }); - // We will check if moh is needed - setInterval(function(){ - if (!moh && Object.keys(peers).length < 2){ - if (!$('#pauseMohButton').is(':checked')){ - $('#mohPlayer')[0].play(); - moh = true; - } - $('.aloneEl').show(200); - } - }, 2000); + checkMoh(); $('#videoLocalContainer').show(200); }); @@ -964,6 +966,7 @@ function initVroom(room) { }, 500); mainVid = false; } + checkMoh(); }); // Error sending something through dataChannel