GUACAMOLE-25: Only capture as long as stream is open.
Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/4b88066f Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/4b88066f Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/4b88066f Branch: refs/heads/master Commit: 4b88066f26a42f3b57036b4a3945d64269689fcf Parents: a6ccb36 Author: Michael Jumper <[email protected]> Authored: Sun May 1 22:29:29 2016 -0700 Committer: Michael Jumper <[email protected]> Committed: Mon May 23 21:08:54 2016 -0700 ---------------------------------------------------------------------- .../src/main/webapp/modules/AudioRecorder.js | 23 ++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/4b88066f/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js ---------------------------------------------------------------------- diff --git a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js index a75dbe1..43394e5 100644 --- a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js +++ b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js @@ -213,6 +213,14 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) { var writtenSamples = 0; /** + * The audio stream provided by the browse, if allowed. If no stream has + * yet been received, this will be null. + * + * @type MediaStream + */ + var mediaStream = null; + + /** * The source node providing access to the local audio input device. * * @private @@ -386,9 +394,17 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) { if (processor) processor.disconnect(); + // Stop capture + if (mediaStream) { + var tracks = mediaStream.getTracks(); + for (var i = 0; i < tracks.length; i++) + tracks[i].stop(); + } + // Remove references to now-unneeded components processor = null; source = null; + mediaStream = null; writer.sendEnd(); return; @@ -396,7 +412,7 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) { } // Attempt to retrieve an audio input stream from the browser - getUserMedia({ 'audio' : true }, function streamReceived(mediaStream) { + getUserMedia({ 'audio' : true }, function streamReceived(stream) { // Create processing node which receives appropriately-sized audio buffers processor = context.createScriptProcessor(BUFFER_SIZE, format.channels, format.channels); @@ -408,9 +424,12 @@ Guacamole.RawAudioRecorder = function RawAudioRecorder(stream, mimetype) { }; // Connect processing node to user's audio input source - source = context.createMediaStreamSource(mediaStream); + source = context.createMediaStreamSource(stream); source.connect(processor); + // Save stream for later cleanup + mediaStream = stream; + }, function streamDenied() { // Simply end stream if audio access is not allowed
