diff options
Diffstat (limited to 'dom/media/webrtc/tests/mochitests/iceTestUtils.js')
-rw-r--r-- | dom/media/webrtc/tests/mochitests/iceTestUtils.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/dom/media/webrtc/tests/mochitests/iceTestUtils.js b/dom/media/webrtc/tests/mochitests/iceTestUtils.js index 9e76e3f7df..23237f563b 100644 --- a/dom/media/webrtc/tests/mochitests/iceTestUtils.js +++ b/dom/media/webrtc/tests/mochitests/iceTestUtils.js @@ -75,6 +75,18 @@ async function iceConnected(pc) { }); } +async function dtlsConnected(pc) { + return new Promise((resolve, reject) => { + pc.addEventListener("connectionstatechange", () => { + if (["connected", "completed"].includes(pc.connectionState)) { + resolve(); + } else if (pc.connectionState == "failed") { + reject(new Error(`Connection failed`)); + } + }); + }); +} + // Set up trickle, but does not wait for it to complete. Can be used by itself // in cases where we do not expect any new candidates, but want to still set up // the signal handling in case new candidates _do_ show up. @@ -87,7 +99,8 @@ async function connect( answerer, timeout, context, - noTrickleWait = false + noTrickleWait = false, + waitForDtls = false ) { const trickle1 = trickleIce(offerer, answerer); const trickle2 = trickleIce(answerer, offerer); @@ -110,8 +123,12 @@ async function connect( } }; + const connectionPromises = waitForDtls + ? [dtlsConnected(offerer), dtlsConnected(answerer)] + : [iceConnected(offerer), iceConnected(answerer)]; + await Promise.race([ - Promise.all([iceConnected(offerer), iceConnected(answerer)]), + Promise.all(connectionPromises), throwOnTimeout(timeout, context), ]); } finally { |