How to use doOfferAnswerExchange method in wpt

Best JavaScript code snippet using wpt

RTCRtpParameters-helper.js

Source:RTCRtpParameters-helper.js Github

copy

Full Screen

...5// This file depends on dictionary-helper.js which should6// be loaded from the main HTML file.7// An offer/answer exchange is necessary for getParameters() to have any8// negotiated parameters to return.9async function doOfferAnswerExchange(t, caller) {10 const callee = new RTCPeerConnection();11 t.add_cleanup(() => callee.close());12 const offer = await caller.createOffer();13 await caller.setLocalDescription(offer);14 await callee.setRemoteDescription(offer);15 const answer = await callee.createAnswer();16 await callee.setLocalDescription(answer);17 await caller.setRemoteDescription(answer);18 return callee;19}20/*21 Validates the RTCRtpParameters returned from RTCRtpSender.prototype.getParameters22 5.2. RTCRtpSender Interface23 getParameters24 - transactionId is set to a new unique identifier, used to match this getParameters25 call to a setParameters call that may occur later.26 - encodings is set to the value of the [[SendEncodings]] internal slot.27 - The headerExtensions sequence is populated based on the header extensions that28 have been negotiated for sending.29 - The codecs sequence is populated based on the codecs that have been negotiated30 for sending, and which the user agent is currently capable of sending. If31 setParameters has removed or reordered codecs, getParameters MUST return the32 shortened/reordered list. However, every time codecs are renegotiated by a33 new offer/answer exchange, the list of codecs MUST be restored to the full34 negotiated set, in the priority order indicated by the remote description,35 in effect discarding the effects of setParameters.36 - rtcp.cname is set to the CNAME of the associated RTCPeerConnection. rtcp.reducedSize37 is set to true if reduced-size RTCP has been negotiated for sending, and false otherwise.38 */39function validateSenderRtpParameters(param) {40 validateRtpParameters(param);41 assert_array_field(param, 'encodings');42 for(const encoding of param.encodings) {43 validateEncodingParameters(encoding);44 }45 assert_not_equals(param.transactionId, undefined,46 'Expect sender param.transactionId to be set');47 assert_not_equals(param.rtcp.cname, undefined,48 'Expect sender param.rtcp.cname to be set');49 assert_not_equals(param.rtcp.reducedSize, undefined,50 'Expect sender param.rtcp.reducedSize to be set to either true or false');51}52/*53 Validates the RTCRtpParameters returned from RTCRtpReceiver.prototype.getParameters54 5.3. RTCRtpReceiver Interface55 getParameters56 When getParameters is called, the RTCRtpParameters dictionary is constructed57 as follows:58 - The headerExtensions sequence is populated based on the header extensions that59 the receiver is currently prepared to receive.60 - The codecs sequence is populated based on the codecs that the receiver is currently61 prepared to receive.62 - rtcp.reducedSize is set to true if the receiver is currently prepared to receive63 reduced-size RTCP packets, and false otherwise. rtcp.cname is left undefined.64 - transactionId is left undefined.65 */66function validateReceiverRtpParameters(param) {67 validateRtpParameters(param);68 assert_equals(param.transactionId, undefined,69 'Expect receiver param.transactionId to be unset');70 assert_not_equals(param.rtcp.reducedSize, undefined,71 'Expect receiver param.rtcp.reducedSize to be set');72 assert_equals(param.rtcp.cname, undefined,73 'Expect receiver param.rtcp.cname to be unset');74}75/*76 dictionary RTCRtpParameters {77 DOMString transactionId;78 sequence<RTCRtpEncodingParameters> encodings;79 sequence<RTCRtpHeaderExtensionParameters> headerExtensions;80 RTCRtcpParameters rtcp;81 sequence<RTCRtpCodecParameters> codecs;82 };83 */84function validateRtpParameters(param) {85 assert_optional_string_field(param, 'transactionId');86 assert_array_field(param, 'headerExtensions');87 for(const headerExt of param.headerExtensions) {88 validateHeaderExtensionParameters(headerExt);89 }90 assert_dict_field(param, 'rtcp');91 validateRtcpParameters(param.rtcp);92 assert_array_field(param, 'codecs');93 for(const codec of param.codecs) {94 validateCodecParameters(codec);95 }96}97/*98 dictionary RTCRtpEncodingParameters {99 boolean active;100 unsigned long maxBitrate;101 [readonly]102 DOMString rid;103 double scaleResolutionDownBy;104 };105 */106function validateEncodingParameters(encoding) {107 assert_optional_boolean_field(encoding, 'active');108 assert_optional_unsigned_int_field(encoding, 'maxBitrate');109 assert_optional_string_field(encoding, 'rid');110 assert_optional_number_field(encoding, 'scaleResolutionDownBy');111}112/*113 dictionary RTCRtcpParameters {114 [readonly]115 DOMString cname;116 [readonly]117 boolean reducedSize;118 };119 */120function validateRtcpParameters(rtcp) {121 assert_optional_string_field(rtcp, 'cname');122 assert_optional_boolean_field(rtcp, 'reducedSize');123}124/*125 dictionary RTCRtpHeaderExtensionParameters {126 [readonly]127 DOMString uri;128 [readonly]129 unsigned short id;130 [readonly]131 boolean encrypted;132 };133 */134function validateHeaderExtensionParameters(headerExt) {135 assert_optional_string_field(headerExt, 'uri');136 assert_optional_unsigned_int_field(headerExt, 'id');137 assert_optional_boolean_field(headerExt, 'encrypted');138}139/*140 dictionary RTCRtpCodecParameters {141 [readonly]142 unsigned short payloadType;143 [readonly]144 DOMString mimeType;145 [readonly]146 unsigned long clockRate;147 [readonly]148 unsigned short channels;149 [readonly]150 DOMString sdpFmtpLine;151 };152 */153function validateCodecParameters(codec) {154 assert_optional_unsigned_int_field(codec, 'payloadType');155 assert_optional_string_field(codec, 'mimeType');156 assert_optional_unsigned_int_field(codec, 'clockRate');157 assert_optional_unsigned_int_field(codec, 'channels');158 assert_optional_string_field(codec, 'sdpFmtpLine');159}160// Get the first encoding in param.encodings.161// Asserts that param.encodings has at least one element.162function getFirstEncoding(param) {163 const {164 encodings165 } = param;166 assert_equals(encodings.length, 1);167 return encodings[0];168}169// Helper function to test that modifying an encoding field should succeed170function test_modified_encoding(kind, field, value1, value2, desc) {171 promise_test(async t => {172 const pc = new RTCPeerConnection();173 t.add_cleanup(() => pc.close());174 const {175 sender176 } = pc.addTransceiver(kind, {177 sendEncodings: [{178 [field]: value1179 }]180 });181 await doOfferAnswerExchange(t, pc);182 const param1 = sender.getParameters();183 validateSenderRtpParameters(param1);184 const encoding1 = getFirstEncoding(param1);185 assert_equals(encoding1[field], value1);186 encoding1[field] = value2;187 await sender.setParameters(param1);188 const param2 = sender.getParameters();189 validateSenderRtpParameters(param2);190 const encoding2 = getFirstEncoding(param2);191 assert_equals(encoding2[field], value2);192 }, desc + ' with RTCRtpTransceiverInit');193 promise_test(async t => {194 const pc = new RTCPeerConnection();195 t.add_cleanup(() => pc.close());196 const {197 sender198 } = pc.addTransceiver(kind);199 await doOfferAnswerExchange(t, pc);200 const initParam = sender.getParameters();201 validateSenderRtpParameters(initParam);202 initParam.encodings[0][field] = value1;203 await sender.setParameters(initParam);204 const param1 = sender.getParameters();205 validateSenderRtpParameters(param1);206 const encoding1 = getFirstEncoding(param1);207 assert_equals(encoding1[field], value1);208 encoding1[field] = value2;209 await sender.setParameters(param1);210 const param2 = sender.getParameters();211 validateSenderRtpParameters(param2);212 const encoding2 = getFirstEncoding(param2);213 assert_equals(encoding2[field], value2);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var offer = "offer";3var answer = "answer";4var exchange = wptoolkit.doOfferAnswerExchange(offer, answer);5console.log(exchange);6var wptoolkit = require('wptoolkit');7var offer = "offer";8var answer = "answer";9var exchange = wptoolkit.doOfferAnswerExchange(offer, answer);10console.log(exchange);11var wptoolkit = require('wptoolkit');12var offer = "offer";13var answer = "answer";14var exchange = wptoolkit.doOfferAnswerExchange(offer, answer);15console.log(exchange);16var wptoolkit = require('wptoolkit');17var offer = "offer";18var answer = "answer";19var exchange = wptoolkit.doOfferAnswerExchange(offer, answer);20console.log(exchange);21var wptoolkit = require('wptoolkit');22var offer = "offer";23var answer = "answer";24var exchange = wptoolkit.doOfferAnswerExchange(offer, answer);25console.log(exchange);26var wptoolkit = require('wptoolkit');27var offer = "offer";28var answer = "answer";29var exchange = wptoolkit.doOfferAnswerExchange(offer, answer);30console.log(exchange);31var wptoolkit = require('wptoolkit');32var offer = "offer";33var answer = "answer";34var exchange = wptoolkit.doOfferAnswerExchange(offer, answer);35console.log(exchange);

Full Screen

Using AI Code Generation

copy

Full Screen

1var test = async_test('Create offer, setLocalDescription, setRemoteDescription, create answer, setLocalDescription, setRemoteDescription');2var pc1 = new RTCPeerConnection();3var pc2 = new RTCPeerConnection();4var offer = await pc1.createOffer();5await pc1.setLocalDescription(offer);6await pc2.setRemoteDescription(offer);7var answer = await pc2.createAnswer();8await pc2.setLocalDescription(answer);9await pc1.setRemoteDescription(answer);10test.done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var offer = await pc.createOffer();2var answer = await pc.createAnswer();3var answer2 = await pc2.createAnswer();4await pc.setLocalDescription(offer);5await pc2.setLocalDescription(answer);6await pc.setRemoteDescription(answer2);7await pc2.setRemoteDescription(offer);8const pc = new RTCPeerConnection();9const pc2 = new RTCPeerConnection();10const offer = await pc.createOffer();11await pc.setLocalDescription(offer);12await pc2.setRemoteDescription(offer);13const answer = await pc2.createAnswer();14await pc2.setLocalDescription(answer);15await pc.setRemoteDescription(answer);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptp = require('wptp');2var peer = new wptp.Peer();3var offer = peer.createOffer();4var offerString = offer.toString();5var answer = peer.createAnswer(offerString);6var answerString = answer.toString();7var answer2 = peer.createAnswer(offerString);8var answerString2 = answer2.toString();9peer.doOfferAnswerExchange(offerString, answerString);10peer.doOfferAnswerExchange(offerString, answerString2);11peer.doOfferAnswerExchange(answerString, offerString);12peer.doOfferAnswerExchange(answerString2, offerString);13peer.doOfferAnswerExchange(answerString, answerString2);14peer.doOfferAnswerExchange(answerString2, answerString);15peer.doOfferAnswerExchange(offerString, offerString);16peer.doOfferAnswerExchange(offerString, offerString);17peer.doOfferAnswerExchange(answerString, answerString);18peer.doOfferAnswerExchange(answerString2, answerString2);19peer.doOfferAnswerExchange(offerString, answerString);20peer.doOfferAnswerExchange(offerString, answerString2);21peer.doOfferAnswerExchange(answerString, offerString);22peer.doOfferAnswerExchange(answerString2, offerString);23peer.doOfferAnswerExchange(answerString, answerString2);24peer.doOfferAnswerExchange(answerString2, answerString);25peer.doOfferAnswerExchange(offerString, offerString);26peer.doOfferAnswerExchange(offerString, offerString);27peer.doOfferAnswerExchange(answerString, answerString);28peer.doOfferAnswerExchange(answerString2, answerString2);29peer.doOfferAnswerExchange(offerString, answerString);30peer.doOfferAnswerExchange(offerString, answerString2);31peer.doOfferAnswerExchange(answerString, offerString

Full Screen

Using AI Code Generation

copy

Full Screen

1var pc1 = new RTCPeerConnection();2var pc2 = new RTCPeerConnection();3var offer;4var answer;5pc1.createOffer()6.then(function(o) {7 offer = o;8 return pc1.setLocalDescription(o);9})10.then(function() {11 return pc2.setRemoteDescription(offer);12})13.then(function() {14 return pc2.createAnswer();15})16.then(function(a) {17 answer = a;18 return pc2.setLocalDescription(a);19})20.then(function() {21 return pc1.setRemoteDescription(answer);22})23.then(function() {24 test.done();25})26.catch(function(e) {27 test.step(function() {28 assert_unreached("Unexpected error: " + e);29 });30 test.done();31});32The test will pass if the following line is added after the call to pc2.setLocalDescription(a):33return pc2.setRemoteDescription(answer);34The test will also pass if the following line is added after the call to pc1.setRemoteDescription(answer):35return pc1.setLocalDescription(offer);36The test will also pass if the following line is added after the call to pc1.setRemoteDescription(answer):37return pc1.setLocalDescription(answer);

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