How to use makeIceTransport method in wpt

Best JavaScript code snippet using wpt

ice.extension.js

Source:ice.extension.js Github

copy

Full Screen

...21 assert_equals(iceTransport.getRemoteParameters(), null,22 'Expect no remote parameters');23}, 'RTCIceTransport initial properties are set');24test(t => {25 const iceTransport = makeIceTransport(t);26 assert_throws_js(TypeError, () =>27 iceTransport.gather({ iceServers: null }));28}, 'gather() with { iceServers: null } should throw TypeError');29test(t => {30 const iceTransport = makeIceTransport(t);31 iceTransport.gather({ iceServers: undefined });32}, 'gather() with { iceServers: undefined } should succeed');33test(t => {34 const iceTransport = makeIceTransport(t);35 iceTransport.gather({ iceServers: [{36 urls: ['turns:turn.example.org', 'turn:turn.example.net'],37 username: 'user',38 credential: 'cred',39 }] });40}, 'gather() with one turns server, one turn server, username, credential' +41 ' should succeed');42test(t => {43 const iceTransport = makeIceTransport(t);44 iceTransport.gather({ iceServers: [{45 urls: ['stun:stun1.example.net', 'stun:stun2.example.net'],46 }] });47}, 'gather() with 2 stun servers should succeed');48test(t => {49 const iceTransport = makeIceTransport(t);50 iceTransport.stop();51 assert_throws_dom('InvalidStateError', () => iceTransport.gather({}));52}, 'gather() throws if closed');53test(t => {54 const iceTransport = makeIceTransport(t);55 iceTransport.gather({});56 assert_equals(iceTransport.gatheringState, 'gathering');57}, `gather() transitions gatheringState to 'gathering'`);58test(t => {59 const iceTransport = makeIceTransport(t);60 iceTransport.gather({});61 assert_throws_dom('InvalidStateError', () => iceTransport.gather({}));62}, 'gather() throws if called twice');63promise_test(async t => {64 const iceTransport = makeIceTransport(t);65 const watcher = new EventWatcher(t, iceTransport, 'gatheringstatechange');66 iceTransport.gather({});67 await watcher.wait_for('gatheringstatechange');68 assert_equals(iceTransport.gatheringState, 'complete');69}, `eventually transition gatheringState to 'complete'`);70promise_test(async t => {71 const iceTransport = makeIceTransport(t);72 const watcher = new EventWatcher(t, iceTransport,73 [ 'icecandidate', 'gatheringstatechange' ]);74 iceTransport.gather({});75 let candidate;76 do {77 (({ candidate } = await watcher.wait_for('icecandidate')));78 } while (candidate !== null);79 assert_equals(iceTransport.gatheringState, 'gathering');80 await watcher.wait_for('gatheringstatechange');81 assert_equals(iceTransport.gatheringState, 'complete');82}, 'onicecandidate fires with null candidate before gatheringState' +83 ` transitions to 'complete'`);84promise_test(async t => {85 const iceTransport = makeIceTransport(t);86 const watcher = new EventWatcher(t, iceTransport, 'icecandidate');87 iceTransport.gather({});88 const { candidate } = await watcher.wait_for('icecandidate');89 assert_not_equals(candidate.candidate, '');90 assert_array_equals(iceTransport.getLocalCandidates(), [candidate]);91}, 'gather() returns at least one host candidate');92promise_test(async t => {93 const iceTransport = makeIceTransport(t);94 const watcher = new EventWatcher(t, iceTransport, 'icecandidate');95 iceTransport.gather({ gatherPolicy: 'relay' });96 const { candidate } = await watcher.wait_for('icecandidate');97 assert_equals(candidate, null);98 assert_array_equals(iceTransport.getLocalCandidates(), []);99}, `gather() returns no candidates with { gatherPolicy: 'relay'} and no turn` +100 ' servers');101const dummyRemoteParameters = {102 usernameFragment: ICE_UFRAG,103 password: ICE_PWD,104};105test(() => {106 const iceTransport = new RTCIceTransport();107 iceTransport.stop();108 assert_throws_dom('InvalidStateError',109 () => iceTransport.start(dummyRemoteParameters));110 assert_equals(iceTransport.getRemoteParameters(), null);111}, `start() throws if closed`);112test(() => {113 const iceTransport = new RTCIceTransport();114 assert_throws_js(TypeError, () => iceTransport.start({}));115 assert_throws_js(TypeError,116 () => iceTransport.start({ usernameFragment: ICE_UFRAG }));117 assert_throws_js(TypeError,118 () => iceTransport.start({ password: ICE_PWD }));119 assert_equals(iceTransport.getRemoteParameters(), null);120}, 'start() throws if usernameFragment or password not set');121test(() => {122 const TEST_CASES = [123 {usernameFragment: '2sh', description: 'less than 4 characters long'},124 {125 usernameFragment: 'x'.repeat(257),126 description: 'greater than 256 characters long',127 },128 {usernameFragment: '123\n', description: 'illegal character'},129 ];130 for (const {usernameFragment, description} of TEST_CASES) {131 const iceTransport = new RTCIceTransport();132 assert_throws_dom(133 'SyntaxError',134 () => iceTransport.start({ usernameFragment, password: ICE_PWD }),135 `illegal usernameFragment (${description}) should throw a SyntaxError`);136 }137}, 'start() throws if usernameFragment does not conform to syntax');138test(() => {139 const TEST_CASES = [140 {password: 'x'.repeat(21), description: 'less than 22 characters long'},141 {142 password: 'x'.repeat(257),143 description: 'greater than 256 characters long',144 },145 {password: ('x'.repeat(21) + '\n'), description: 'illegal character'},146 ];147 for (const {password, description} of TEST_CASES) {148 const iceTransport = new RTCIceTransport();149 assert_throws_dom(150 'SyntaxError',151 () => iceTransport.start({ usernameFragment: ICE_UFRAG, password }),152 `illegal password (${description}) should throw a SyntaxError`);153 }154}, 'start() throws if password does not conform to syntax');155const assert_ice_parameters_equals = (a, b) => {156 assert_equals(a.usernameFragment, b.usernameFragment,157 'usernameFragments are equal');158 assert_equals(a.password, b.password, 'passwords are equal');159};160test(t => {161 const iceTransport = makeIceTransport(t);162 iceTransport.start(dummyRemoteParameters);163 assert_equals(iceTransport.state, 'new');164 assert_ice_parameters_equals(iceTransport.getRemoteParameters(),165 dummyRemoteParameters);166}, `start() does not transition state to 'checking' if no remote candidates ` +167 'added');168test(t => {169 const iceTransport = makeIceTransport(t);170 iceTransport.start(dummyRemoteParameters);171 assert_equals(iceTransport.role, 'controlled');172}, `start() with default role sets role attribute to 'controlled'`);173test(t => {174 const iceTransport = makeIceTransport(t);175 iceTransport.start(dummyRemoteParameters, 'controlling');176 assert_equals(iceTransport.role, 'controlling');177}, `start() sets role attribute to 'controlling'`);178const candidate1 = new RTCIceCandidate({179 candidate: 'candidate:1 1 udp 2113929471 203.0.113.100 10100 typ host',180 sdpMid: '',181});182test(() => {183 const iceTransport = new RTCIceTransport();184 iceTransport.stop();185 assert_throws_dom('InvalidStateError',186 () => iceTransport.addRemoteCandidate(candidate1));187 assert_array_equals(iceTransport.getRemoteCandidates(), []);188}, 'addRemoteCandidate() throws if closed');189test(() => {190 const iceTransport = new RTCIceTransport();191 assert_throws_dom('OperationError',192 () => iceTransport.addRemoteCandidate(193 new RTCIceCandidate({ candidate: 'invalid', sdpMid: '' })));194 assert_array_equals(iceTransport.getRemoteCandidates(), []);195}, 'addRemoteCandidate() throws on invalid candidate');196test(t => {197 const iceTransport = makeIceTransport(t);198 iceTransport.addRemoteCandidate(candidate1);199 iceTransport.start(dummyRemoteParameters);200 assert_equals(iceTransport.state, 'checking');201 assert_array_equals(iceTransport.getRemoteCandidates(), [candidate1]);202}, `start() transitions state to 'checking' if one remote candidate had been ` +203 'added');204test(t => {205 const iceTransport = makeIceTransport(t);206 iceTransport.start(dummyRemoteParameters);207 iceTransport.addRemoteCandidate(candidate1);208 assert_equals(iceTransport.state, 'checking');209 assert_array_equals(iceTransport.getRemoteCandidates(), [candidate1]);210}, `addRemoteCandidate() transitions state to 'checking' if start() had been ` +211 'called before');212test(t => {213 const iceTransport = makeIceTransport(t);214 iceTransport.start(dummyRemoteParameters);215 assert_throws_dom('InvalidStateError',216 () => iceTransport.start(dummyRemoteParameters, 'controlling'));217}, 'start() throws if later called with a different role');218test(t => {219 const iceTransport = makeIceTransport(t);220 iceTransport.start({221 usernameFragment: '1'.repeat(4),222 password: '1'.repeat(22),223 });224 iceTransport.addRemoteCandidate(candidate1);225 const changedRemoteParameters = {226 usernameFragment: '2'.repeat(4),227 password: '2'.repeat(22),228 };229 iceTransport.start(changedRemoteParameters);230 assert_equals(iceTransport.state, 'new');231 assert_array_equals(iceTransport.getRemoteCandidates(), []);232 assert_ice_parameters_equals(iceTransport.getRemoteParameters(),233 changedRemoteParameters);...

Full Screen

Full Screen

RTCIceTransport-extension-helper.js

Source:RTCIceTransport-extension-helper.js Github

copy

Full Screen

1'use strict';2// Construct an RTCIceTransport instance. The instance will automatically be3// cleaned up when the test finishes.4function makeIceTransport(t) {5 const iceTransport = new RTCIceTransport();6 t.add_cleanup(() => iceTransport.stop());7 return iceTransport;8}9// Construct two RTCIceTransport instances, configure them to exchange10// candidates, then gather() them.11// Returns a 2-list: [ RTCIceTransport, RTCIceTransport ]12function makeAndGatherTwoIceTransports(t) {13 const localTransport = makeIceTransport(t);14 const remoteTransport = makeIceTransport(t);15 localTransport.onicecandidate = e => {16 if (e.candidate) {17 remoteTransport.addRemoteCandidate(e.candidate);18 }19 };20 remoteTransport.onicecandidate = e => {21 if (e.candidate) {22 localTransport.addRemoteCandidate(e.candidate);23 }24 };25 localTransport.gather({});26 remoteTransport.gather({});27 return [ localTransport, remoteTransport ];28}...

Full Screen

Full Screen

ice.js

Source:ice.js Github

copy

Full Screen

1'use strict';2function makeIceTransport(t) {3 const iceTransport = new RTCIceTransport();4 t.add_cleanup(() => iceTransport.stop());5 return iceTransport;6}7function makeAndGatherTwoIceTransports(t) {8 const localTransport = makeIceTransport(t);9 const remoteTransport = makeIceTransport(t);10 localTransport.onicecandidate = e => {11 if (e.candidate) {12 remoteTransport.addRemoteCandidate(e.candidate);13 }14 };15 remoteTransport.onicecandidate = e => {16 if (e.candidate) {17 localTransport.addRemoteCandidate(e.candidate);18 }19 };20 localTransport.gather({});21 remoteTransport.gather({});22 return [localTransport, remoteTransport];23}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var iceTransport = wpt.makeIceTransport();2iceTransport.onstatechange = function() {3 console.log("state changed to: " + iceTransport.state);4}5iceTransport.onicestatechange = function() {6 console.log("ice state changed to: " + iceTransport.iceState);7}8iceTransport.ongatheringstatechange = function() {9 console.log("gathering state changed to: " + iceTransport.gatheringState);10}11iceTransport.onselectedcandidatepairchange = function() {12 console.log("selected candidate pair change event");13}14iceTransport.onlocalcandidate = function(event) {15 console.log("local candidate event: " + event.candidate);16}17iceTransport.onremotecandidate = function(event) {18 console.log("remote candidate event: " + event.candidate);19}20iceTransport.oncandidateerror = function(event) {21 console.log("candidate error event: " + event.candidate);22}23iceTransport.oncandidatepairchange = function(event) {24 console.log("candidate pair change event: " + event.candidate);25}26iceTransport.onicestart = function(event) {27 console.log("ice start event");28}29iceTransport.oniceend = function(event) {30 console.log("ice end event");31}32iceTransport.onicecandidate = function(event) {33 console.log("ice candidate event");34}35iceTransport.oniceconnectionstatechange = function(event) {36 console.log("ice connection state changed to: " + iceTransport.iceConnectionState);37}38iceTransport.onicegatheringstatechange = function(event) {39 console.log("ice gathering state changed to: " + iceTransport.iceGatheringState);40}41iceTransport.onicecandidateerror = function(event) {42 console.log("ice candidate error event");43}44iceTransport.onicecandidatepairchange = function(event) {45 console.log("ice candidate pair change event");46}47iceTransport.oniceconnectionstatechange = function(event) {48 console.log("ice connection state changed to: " + iceTransport.iceConnectionState);49}50iceTransport.onicegatheringstatechange = function(event) {51 console.log("ice gathering state changed to: " + iceTransport.iceGatheringState);52}53iceTransport.onicecandidateerror = function(event) {54 console.log("ice candidate error event");55}56iceTransport.onicecandidatepairchange = function(event) {57 console.log("ice candidate pair change event");58}

Full Screen

Using AI Code Generation

copy

Full Screen

1var iceTransport = makeIceTransport();2var iceTransport = makeIceTransport();3iceTransport.onstatechange = function() {4 if(iceTransport.state == 'completed') {5 var rtpReceiver = makeRtpReceiver();6 var rtpReceiver = makeRtpReceiver();7 rtpReceiver.ontrack = function(event) {8 var rtpSender = makeRtpSender();9 var rtpSender = makeRtpSender();10 rtpSender.replaceTrack(event.track);11 rtpSender.setParameters({encodings: [{maxBitrate: 1000}]});12 rtpSender.getParameters().then(function(params) {13 assert_true(params.encodings[0].maxBitrate == 1000, 'maxBitrate set to 1000');14 rtpSender.setParameters({encodings: [{maxBitrate: 2000}]});15 rtpSender.getParameters().then(function(params) {16 assert_true(params.encodings[0].maxBitrate == 2000, 'maxBitrate set to 2000');17 done();18 });19 });20 };21 var rtpTransceiver = makeRtpTransceiver();22 var rtpTransceiver = makeRtpTransceiver();23 rtpTransceiver.setDirection('sendrecv');24 rtpTransceiver.setCodecPreferences(['opus']);25 rtpTransceiver.getStats().then(function(stats) {26 assert_true(stats.hasOwnProperty('inbound-rtp'), 'stats has inbound-rtp');27 assert_true(stats.hasOwnProperty('outbound-rtp'), 'stats has outbound-rtp');28 assert_true(stats.hasOwnProperty('track'), 'stats has track');29 assert_true(stats.hasOwnProperty('transport'), 'stats has transport');30 assert_true(stats.hasOwnProperty('candidate-pair'), 'stats has candidate-pair');31 assert_true(stats.hasOwnProperty('local-candidate'), 'stats has local-candidate');32 assert_true(stats.hasOwnProperty('remote-c

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful