How to use swapRidAndMidExtensionsInSimulcastOffer method in wpt

Best JavaScript code snippet using wpt

simulcast.js

Source: simulcast.js Github

copy

Full Screen

...11 'urn:ietf:params:rtp-hdrext:sdes:mid',12 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id',13 'urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id',14];15function swapRidAndMidExtensionsInSimulcastOffer(offer, rids) {16 const sections = SDPUtils.splitSections(offer.sdp);17 const dtls = SDPUtils.getDtlsParameters(sections[1], sections[0]);18 const ice = SDPUtils.getIceParameters(sections[1], sections[0]);19 const rtpParameters = SDPUtils.parseRtpParameters(sections[1]);20 /​/​ The gist of this hack is that rid and mid have the same wire format.21 const rid = rtpParameters.headerExtensions.find(ext => ext.uri === 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id');22 rtpParameters.headerExtensions = rtpParameters.headerExtensions.filter(ext => {23 return !extensionsToFilter.includes(ext.uri);24 });25 /​/​ This tells the other side that the RID packets are actually mids.26 rtpParameters.headerExtensions.push({id: rid.id, uri: 'urn:ietf:params:rtp-hdrext:sdes:mid', direction: 'sendrecv'});27 /​/​ Filter rtx as we have no way to (re)interpret rrid.28 /​/​ Not doing this makes probing use RTX, it's not understood and ramp-up is slower.29 rtpParameters.codecs = rtpParameters.codecs.filter(c => c.name.toUpperCase() !== 'RTX');30 let sdp = SDPUtils.writeSessionBoilerplate() +31 SDPUtils.writeDtlsParameters(dtls, 'actpass') +32 SDPUtils.writeIceParameters(ice) +33 'a=group:BUNDLE ' + rids.join(' ') + '\r\n';34 const baseRtpDescription = SDPUtils.writeRtpDescription('video', rtpParameters);35 rids.forEach(rid => {36 sdp += baseRtpDescription +37 'a=mid:' + rid + '\r\n' +38 'a=msid:rid-' + rid + ' rid-' + rid + '\r\n';39 });40 return sdp;41}42function swapRidAndMidExtensionsInSimulcastAnswer(answer, localDescription, rids) {43 const sections = SDPUtils.splitSections(answer.sdp);44 const dtls = SDPUtils.getDtlsParameters(sections[1], sections[0]);45 const ice = SDPUtils.getIceParameters(sections[1], sections[0]);46 const rtpParameters = SDPUtils.parseRtpParameters(sections[1]);47 rtpParameters.headerExtensions = rtpParameters.headerExtensions.filter(ext => {48 return !extensionsToFilter.includes(ext.uri);49 });50 const localMid = SDPUtils.getMid(SDPUtils.splitSections(localDescription.sdp)[1]);51 let sdp = SDPUtils.writeSessionBoilerplate() +52 SDPUtils.writeDtlsParameters(dtls, 'active') +53 SDPUtils.writeIceParameters(ice) +54 'a=group:BUNDLE ' + localMid + '\r\n';55 sdp += SDPUtils.writeRtpDescription('video', rtpParameters);56 sdp += 'a=mid:' + localMid + '\r\n';57 rids.forEach(rid => {58 sdp += 'a=rid:' + rid + ' recv\r\n';59 });60 sdp += 'a=simulcast:recv ' + rids.join(';') + '\r\n';61 /​/​ Re-add headerextensions we filtered.62 const headerExtensions = SDPUtils.parseRtpParameters(SDPUtils.splitSections(localDescription.sdp)[1]).headerExtensions;63 headerExtensions.forEach(ext => {64 if (extensionsToFilter.includes(ext.uri)) {65 sdp += 'a=extmap:' + ext.id + ' ' + ext.uri + '\r\n';66 }67 });68 return sdp;69}70async function negotiateSimulcastAndWaitForVideo(t, rids, pc1, pc2, codec) {71 exchangeIceCandidates(pc1, pc2);72 const metadataToBeLoaded = [];73 pc2.ontrack = (e) => {74 const stream = e.streams[0];75 const v = document.createElement('video');76 v.autoplay = true;77 v.srcObject = stream;78 v.id = stream.id79 metadataToBeLoaded.push(new Promise((resolve) => {80 v.addEventListener('loadedmetadata', () => {81 resolve();82 });83 }));84 };85 const sendEncodings = rids.map(rid => ({rid}));86 /​/​ Use a 2X downscale factor between each layer. To improve ramp-up time, the87 /​/​ top layer is scaled down by a factor 2. Smaller layer comes first. For88 /​/​ example if MediaStreamTrack is 720p and we want to send three layers we'll89 /​/​ get {90p, 180p, 360p}.90 let scaleResolutionDownBy = 2;91 for (let i = sendEncodings.length - 1; i >= 0; --i) {92 sendEncodings[i].scaleResolutionDownBy = scaleResolutionDownBy;93 scaleResolutionDownBy *= 2;94 }95 /​/​ Use getUserMedia as getNoiseStream does not have enough entropy to ramp-up.96 await setMediaPermission();97 const stream = await navigator.mediaDevices.getUserMedia({video: {width: 1280, height: 720}});98 t.add_cleanup(() => stream.getTracks().forEach(track => track.stop()));99 const transceiver = pc1.addTransceiver(stream.getVideoTracks()[0], {100 streams: [stream],101 sendEncodings: sendEncodings,102 });103 if (codec) {104 preferCodec(transceiver, codec.mimeType, codec.sdpFmtpLine);105 }106 const offer = await pc1.createOffer();107 await pc1.setLocalDescription(offer),108 await pc2.setRemoteDescription({109 type: 'offer',110 sdp: swapRidAndMidExtensionsInSimulcastOffer(offer, rids),111 });112 const answer = await pc2.createAnswer();113 await pc2.setLocalDescription(answer);114 await pc1.setRemoteDescription({115 type: 'answer',116 sdp: swapRidAndMidExtensionsInSimulcastAnswer(answer, pc1.localDescription, rids),117 });118 assert_equals(metadataToBeLoaded.length, rids.length);119 return Promise.all(metadataToBeLoaded);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptool = require('./​wptool');2var offer = wptool.swapRidAndMidExtensionsInSimulcastOffer(offer);3console.log(offer);4var wptool = {5 swapRidAndMidExtensionsInSimulcastOffer: function (offer) {6 var sdp = offer.sdp;7 var ridExt = "urn:3gpp:video-orientation";8 var midExt = "urn:ietf:params:rtp-hdrext:sdes:mid";9 var ridExtPos = sdp.indexOf(ridExt);10 var midExtPos = sdp.indexOf(midExt);11 var ridExtLine = sdp.substring(ridExtPos, sdp.indexOf("a=rtcp-fb", ridExtPos));12 var midExtLine = sdp.substring(midExtPos, sdp.indexOf("a=rtcp-fb", midExtPos));13 var ridExtLinePos = sdp.indexOf(ridExtLine);14 var midExtLinePos = sdp.indexOf(midExtLine);15 sdp = sdp.substring(0, ridExtLinePos) + midExtLine + sdp.substring(ridExtLinePos + ridExtLine.length);16 sdp = sdp.substring(0, midExtLinePos) + ridExtLine + sdp.substring(midExtLinePos + midExtLine.length);17 offer.sdp = sdp;18 return offer;19 }20};21module.exports = wptool;

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

27 Best Website Testing Tools In 2022

Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.

Your Favorite Dev Browser Has Evolved! The All New LT Browser 2.0

We launched LT Browser in 2020, and we were overwhelmed by the response as it was awarded as the #5 product of the day on the ProductHunt platform. Today, after 74,585 downloads and 7,000 total test runs with an average of 100 test runs each day, the LT Browser has continued to help developers build responsive web designs in a jiffy.

Difference Between Web And Mobile Application Testing

Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.

Putting Together a Testing Team

As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.

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