From 6f0ecdf390570a45ee81c143d8e50be5a5ff9217 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Mon, 10 Nov 2014 19:54:51 +0100 Subject: [PATCH] Make sure to clear timeout after usermedia test. --- static/js/mediastream/usermedia.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/static/js/mediastream/usermedia.js b/static/js/mediastream/usermedia.js index 93b12a52..2c1d9db5 100644 --- a/static/js/mediastream/usermedia.js +++ b/static/js/mediastream/usermedia.js @@ -63,7 +63,12 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _ console.log("Requesting testGetUserMedia"); (function(complete) { + var timeout = null; var success_helper = function(stream) { + if (timeout) { + clearTimeout(timeout); + timeout = null; + } stream.stop(); if (complete.done) { return; @@ -73,6 +78,10 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _ success_cb.apply(this, args); }; var error_helper = function() { + if (timeout) { + clearTimeout(timeout); + timeout = null; + } if (complete.done) { return; } @@ -89,7 +98,7 @@ define(['jquery', 'underscore', 'audiocontext', 'webrtc.adapter'], function($, _ console.error('getUserMedia failed with exception: ' + e.message); error_helper(e); } - setTimeout(function() { + timeout = setTimeout(function() { var e = new Error("Timeout while waiting for getUserMedia"); console.error('getUserMedia timed out'); error_helper(e);