Uploaded image for project: 'Guacamole'
  1. Guacamole
  2. GUACAMOLE-732

navigator.mediaDevices.getUserMedia() returns a promises

    XMLWordPrintableJSON

Details

    Description

      navigator.mediaDevices.getUserMedia() in Line 426 of the AudioRecorder.js is not working with callbacks anymore, but with promises. See here.

      Version 1.0.0 of AudioRecorder.js contains:

       

      var beginAudioCapture = function beginAudioCapture() {
      
      
      
      // Attempt to retrieve an audio input stream from the browser
      
      navigator.mediaDevices.getUserMedia({ 'audio' : true }, function streamReceived(stream) {
      
      
      
      // Create processing node which receives appropriately-sized audio buffers
      
      processor = context.createScriptProcessor(BUFFER_SIZE, format.channels, format.channels);
      
      processor.connect(context.destination);
      
      
      
      // Send blobs when audio buffers are received
      
      processor.onaudioprocess = function processAudio(e) {
      
      writer.sendData(toSampleArray(e.inputBuffer).buffer);
      
      };
      
      
      
      // Connect processing node to user's audio input source
      
      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
      
      writer.sendEnd();
      
      
      
      // Notify of closure
      
      if (recorder.onerror)
      
      recorder.onerror();
      
      
      
      });
      
      
      
      };
      

       

       

      A possible fix would be:

       

      var beginAudioCapture = function beginAudioCapture() {
              // Attempt to retrieve an audio input stream from the browser
              navigator.mediaDevices.getUserMedia({ 'audio' : true })
                  .then(stream => {
                  // Create processing node which receives appropriately-sized audio buffers
                  processor = context.createScriptProcessor(BUFFER_SIZE, format.channels, format.channels);
                  processor.connect(context.destination);
      
      
                  // Send blobs when audio buffers are received
                  processor.onaudioprocess = function processAudio(e) {
                      writer.sendData(toSampleArray(e.inputBuffer).buffer);
                  };
                 
                  // Connect processing node to user's audio input source
                  source = context.createMediaStreamSource(stream);
                  source.connect(processor);
      
      
                  // Save stream for later cleanup
                  mediaStream = stream;
      
      
              }).catch(err => {
                  // Simply end stream if audio access is not allowed
                  writer.sendEnd();
      
      
                  // Notify of closure
                  if (recorder.onerror)
                      recorder.onerror();
      
      
              });
      

       

      Attachments

        Issue Links

          Activity

            People

              mjumper Mike Jumper
              f01spies Fabian Spieß
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: