How to get real time audio streams of both Calling party and called party independently

Hi,
Trying with the mentioned approach. But not getting the audio streams. So could you please help, if we missed/incorrectly used anything here. Thanks.

Running this script in the same server which we used for running the asterisk.

AudioCapture.js

const client = require('ari-client');
const util = require('util');
const rtp = require('./rtp-udp-server');

async function connect() {
  try {
   let swap16 = false;
   let audioOutput = "test.raw";
   let audioServer = new rtp.RtpUdpServerSocket("localhost:9999", swap16, audioOutput);
   const ariClient = await client.connect("http://127.0.0.1:8088", "asterisk", "asterisk");
   await ariClient.start("externalMedia");
   console.log("Connected to Asterisk ARI");
 
   const bridges = await ariClient.bridges.list();
   console.log("number of bridges :", bridges.length);

   let bridgeId = "bridgeId"   //will update the bridge id of the current call, each time for the timebeing.
   if(bridgeId){
      const bridge = await ariClient.bridges.get({ bridgeId });
      const channelsInBridge = bridge.channels;
      const snoopBridge = await ariClient.bridges.create({
             type: 'mixing'
        });

      // Snoop on each channel
      for (const channel of channelsInBridge) {
        const snoopChannel = await ariClient.channels.snoopChannel({
            channelId: channel,
            app: 'externalMedia',
            spy: 'both',
            snoopId: 'snoop-' + channel,
            });

      console.log(`Snooping on channel id`, snoopChannel.id);


       let externalChannel = await snoopChannel.externalMedia({
                                app: "externalMedia",
                                external_host: "localhost:9999",
                                format: "ulaw"
                        });


       await ariClient.bridges.addChannel({ bridgeId: snoopBridge.id, channel: externalChannel.id });

      }
    }
   console.log('Waiting for audio streams ..... ');

  } catch (error) {
    console.error("Error connecting to Asterisk ARI:", error.message);
  }
}

// Call the connect function
connect();

rtp-udp-server.js.js → we are referring from :- https://github.com/asterisk/asterisk-external-media/blob/master/lib/rtp-udp-server.js )