From 4b230860a51b00755cd9937a3ca8139782c83cb4 Mon Sep 17 00:00:00 2001 From: Filipi Fuchter Date: Fri, 28 Nov 2025 05:51:28 -0300 Subject: [PATCH] Simple script for testing if we are correctly gathering the ice candidates in the browser. --- examples/aws-agentcore/scripts/turn-test.js | 47 +++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 examples/aws-agentcore/scripts/turn-test.js diff --git a/examples/aws-agentcore/scripts/turn-test.js b/examples/aws-agentcore/scripts/turn-test.js new file mode 100644 index 000000000..9dcb4bdce --- /dev/null +++ b/examples/aws-agentcore/scripts/turn-test.js @@ -0,0 +1,47 @@ +// Simple script for testing if we are correctly gathering the ice candidates from a specific +// turn server in the browser +(async () => { + console.clear(); + console.log("Starting ICE candidate test…"); + + const turnServer = { + urls: "turn:turn.cloudflare.com:80?transport=tcp", + username: "username", + credential: "password" + }; + + const pc = new RTCPeerConnection({ + iceServers: [ turnServer ], + iceTransportPolicy: "all" // or "relay" if you want only TURN + }); + + let gotRelay = false; + + pc.onicecandidate = event => { + if (!event.candidate) { + console.log("ICE gathering finished."); + if (gotRelay) { + console.log("%cTURN relay candidate FOUND ✔️", "color: green; font-weight: bold;"); + } else { + console.log("%cNo TURN relay candidates detected ❌", "color: red; font-weight: bold;"); + } + return; + } + + const cand = event.candidate.candidate; + console.log("ICE Candidate:", cand); + + if (cand.includes("typ relay")) { + console.log("%cTURN relay candidate detected!", "color: green;"); + gotRelay = true; + } + }; + + // Create empty data channel (required to trigger ICE) + pc.createDataChannel("test"); + + const offer = await pc.createOffer(); + await pc.setLocalDescription(offer); + + console.log("Gathering ICE candidates…"); +})(); \ No newline at end of file