How to use a hook to access a js which has the function of enabling the microphone and disabling it from the client?

Basically what is happening to me is that I am using a hook to access a js which has the function of enabling the microphone and disabling it from the client. When I enable it, it works correctly, but when I want to disable it, the problems occur

Uncaught DOMException: AudioNode.disconnect: Trying to disconnect from a node we're not connected to

this is the error that occurs, which is caused in the following function

AudioRecorder.stopRecording = function() {
        streamStreaming = false;
      
        let track = globalStream.getTracks()[0];
        track.stop();
      
        input.disconnect(processor);  **(in this line to be more specific)**
        processor.disconnect(context.destination);
        context.close().then(function () {
          input = null;
          processor = null;
          context = null;
          AudioContext = null;
          
        });
      } // closes function stopRecording()

To put them a little more in context, the function where I get the error is in a recorder.js file, but I manage the hook from another file called recordehook.js. So what I’m basically asking is how do I manage the microphone so that it turns off either from phoenix in the liveview or from elixir in the channel