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

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