GUACAMOLE-25: Clean up media source and processor node on end. Keep reference 
while streaming (prevent faulty garbage collection of the nodes).


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/0c0ee96a
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/0c0ee96a
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/0c0ee96a

Branch: refs/heads/master
Commit: 0c0ee96aaa18d70502f063e734d701597d11e800
Parents: 8442f7c
Author: Michael Jumper <[email protected]>
Authored: Fri Apr 29 19:09:12 2016 -0700
Committer: Michael Jumper <[email protected]>
Committed: Mon May 23 15:00:00 2016 -0700

----------------------------------------------------------------------
 .../src/main/webapp/modules/AudioRecorder.js    | 35 ++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/0c0ee96a/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 704d7e7..38e2cad 100644
--- a/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
+++ b/guacamole-common-js/src/main/webapp/modules/AudioRecorder.js
@@ -202,6 +202,23 @@ Guacamole.RawAudioRecorder = function 
RawAudioRecorder(stream, mimetype) {
     var writtenSamples = 0;
 
     /**
+     * The source node providing access to the local audio input device.
+     *
+     * @private
+     * @type {MediaStreamAudioSourceNode}
+     */
+    var source = null;
+
+    /**
+     * The script processing node which receives audio input from the media
+     * stream source node as individual audio buffers.
+     *
+     * @private
+     * @type {ScriptProcessorNode}
+     */
+    var processor = null;
+
+    /**
      * Determines the value of the waveform represented by the audio data at
      * the given location. If the value cannot be determined exactly as it does
      * not correspond to an exact sample within the audio data, the value will
@@ -294,15 +311,29 @@ Guacamole.RawAudioRecorder = function 
RawAudioRecorder(stream, mimetype) {
 
         // Abort stream if rejected
         if (status.code !== Guacamole.Status.Code.SUCCESS) {
+
+            // Disconnect media source node from script processor
+            if (source)
+                source.disconnect();
+
+            // Disconnect associated script processor node
+            if (processor)
+                processor.disconnect();
+
+            // Remove references to now-unneeded components
+            processor = null;
+            source = null;
+
             writer.sendEnd();
             return;
+
         }
 
         // Attempt to retrieve an audio input stream from the browser
         getUserMedia({ 'audio' : true }, function streamReceived(mediaStream) {
 
             // Create processing node which receives appropriately-sized audio 
buffers
-            var processor = context.createScriptProcessor(BUFFER_SIZE, 
format.channels, format.channels);
+            processor = context.createScriptProcessor(BUFFER_SIZE, 
format.channels, format.channels);
             processor.connect(context.destination);
 
             // Send blobs when audio buffers are received
@@ -311,7 +342,7 @@ Guacamole.RawAudioRecorder = function 
RawAudioRecorder(stream, mimetype) {
             };
 
             // Connect processing node to user's audio input source
-            var source = context.createMediaStreamSource(mediaStream);
+            source = context.createMediaStreamSource(mediaStream);
             source.connect(processor);
 
         }, function streamDenied() {

Reply via email to