padarom / guacamole-common-js

:avocado: The JavaScript Guacamole client library modified for easy installation and usage via npm
http://guac-dev.org/
Apache License 2.0
41 stars 19 forks source link

How to access microphone data? #28

Open AmiSBr opened 1 year ago

AmiSBr commented 1 year ago

Hello,

I'm using Guacamole-common.js to create a remote desktop connection with a Windows machine. I've managed to establish the connection, add the keyboard and output audio.

Currently, I'm trying to activate the microphone. But it doesn't work. I try to use AudioWorklet. I want to make calls using this Windows machine via guacamole. I have audio output but microphone is not detected in my Windows client. My microphone is detected by the browser. But in my windows machine, I still got the error 'No input devices found'.

Has anyone tried to enable microphone access?

I've also tried to use createScriptProcessor which is deprecated. But it's not working. Any help would be appreciated.

     const tunnel = new Guacamole.WebSocketTunnel(WEB_SOCKET_TUNNEL);
     const client = new Guacamole.Client(tunnel);  

     var audioStream = client.createAudioStream("audio/L16");
     var writer = new Guacamole.ArrayBufferWriter(audioStream);

      // Attempt to retrieve an audio input stream from the browser
      navigator.mediaDevices.getUserMedia({ audio: true })
            .then(async function (stream) {

                const context = new AudioContext();
                const source = context.createMediaStreamSource(stream);

                // Load and execute the module script.
                await context.audioWorklet.addModule('worklet/processor.js');

                const processor = new AudioWorkletNode(context, "processor");

                source.connect(processor).connect(context.destination);

                console.log("Microphone access allowed");

              //How to send audio input ?

            })
            .catch(function (error) {
                console.log(error, 'error');
                console.log("Microphone access denied");
                writer.sendEnd();
            });

    // processor.js
    // This file is evaluated in the audio rendering thread
    // upon context.audioWorklet.addModule() call.

    class Processor extends AudioWorkletProcessor {
      process([input], [output]) {
        // Copy inputs to outputs.
        output[0].set(input[0]);

        return true;
      }
    }

    registerProcessor("processor", Processor);

Thanks for your support

Mariappan-s commented 1 year ago

Hi @AmiSBr Currently, I am encountering the issue you mentioned earlier. Could someone assist me in resolving the aforementioned issue?

AmiSBr commented 1 year ago

Hi @Mariappan-s I explain in this post how I managed to get audio output. https://stackoverflow.com/questions/76455664/how-to-access-microphone-in-guacamole-common-js

divyeshg94 commented 1 year ago

Hi @AmiSBr ,

I have checked this StackOverflow implementation and tried to implement the same, whereas stackoverflow missed the implementation of "toSampleArray" and its dependant functions, I tried implementing those from the guacamole common js files. But after implementing the stack overflow I couldn't click on anything in the RDP, as well as I couldn't use the microphone inside the virtual machine. Please let me know your thoughts if I miss anything.