RTCIceTransport-extension-helper.js (1506B)
1 'use strict'; 2 3 // Construct an RTCIceTransport instance. The instance will automatically be 4 // cleaned up when the test finishes. 5 function makeIceTransport(t) { 6 const iceTransport = new RTCIceTransport(); 7 t.add_cleanup(() => iceTransport.stop()); 8 return iceTransport; 9 } 10 11 // Construct two RTCIceTransport instances, configure them to exchange 12 // candidates, then gather() them. 13 // Returns a 2-list: [ RTCIceTransport, RTCIceTransport ] 14 function makeAndGatherTwoIceTransports(t) { 15 const localTransport = makeIceTransport(t); 16 const remoteTransport = makeIceTransport(t); 17 localTransport.onicecandidate = e => { 18 if (e.candidate) { 19 remoteTransport.addRemoteCandidate(e.candidate); 20 } 21 }; 22 remoteTransport.onicecandidate = e => { 23 if (e.candidate) { 24 localTransport.addRemoteCandidate(e.candidate); 25 } 26 }; 27 localTransport.gather({}); 28 remoteTransport.gather({}); 29 return [ localTransport, remoteTransport ]; 30 } 31 32 // Construct two RTCIceTransport instances, configure them to exchange 33 // candidates and parameters, then gather() and start() them. 34 // Returns a 2-list: 35 // [ controlling RTCIceTransport, 36 // controlled RTCIceTransport ] 37 function makeGatherAndStartTwoIceTransports(t) { 38 const [ localTransport, remoteTransport ] = makeAndGatherTwoIceTransports(t); 39 localTransport.start(remoteTransport.getLocalParameters(), 'controlling'); 40 remoteTransport.start(localTransport.getLocalParameters(), 'controlled'); 41 return [ localTransport, remoteTransport ]; 42 }