How to use setTransceiverCodecPreference method in wpt

Best JavaScript code snippet using wpt

peerconnection.js

Source:peerconnection.js Github

copy

Full Screen

...22 * list of supported codecs.23 * @param {!RTCRtpTransceiver} transceiver The RTP transceiver.24 * @param {string} codecPreference The codec preference.25 */26function setTransceiverCodecPreference(transceiver, codecPreference) {27 for (const codec of RTCRtpSender.getCapabilities('video').codecs) {28 if (codec.mimeType.includes(codecPreference)) {29 transceiver.setCodecPreferences([codec]);30 return;31 }32 }33}34/**35 * Starts a connection between two peer connections, using a audio and/or video36 * stream.37 * @param {*} t Test instance.38 * @param {boolean} audio True if audio should be used.39 * @param {boolean} video True if video should be used.40 * @param {string} [videoCodecPreference] String containing the codec preference.41 * @returns an array with the two connected peer connections, the remote stream,42 * and an object containing transceivers by kind.43 */44async function startConnection(t, audio, video, videoCodecPreference) {45 const stream = await navigator.mediaDevices.getUserMedia({audio, video});46 t.add_cleanup(() => stream.getTracks().forEach(track => track.stop()));47 const pc1 = new RTCPeerConnection();48 t.add_cleanup(() => pc1.close());49 const pc2 = new RTCPeerConnection();50 t.add_cleanup(() => pc2.close());51 const transceivers = {};52 for (const track of stream.getTracks()) {53 const transceiver = pc1.addTransceiver(track, {streams: [stream]});54 transceivers[track.kind] = transceiver;55 if (videoCodecPreference && track.kind == 'video') {56 setTransceiverCodecPreference(transceiver, videoCodecPreference);57 }58 }59 for (const [local, remote] of [[pc1, pc2], [pc2, pc1]]) {60 local.addEventListener('icecandidate', ({candidate}) => {61 if (!candidate || remote.signalingState == 'closed') return;62 remote.addIceCandidate(candidate);63 });64 }65 const haveTrackEvent = new Promise(r => pc2.ontrack = r);66 await exchangeOfferAnswer(pc1, pc2);67 const {streams} = await haveTrackEvent;68 return [pc1, pc2, streams[0], transceivers];69}70/**...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function testSetTransceiverCodecPreference() {2 return new Promise((resolve, reject) => {3 window.pc1 = new RTCPeerConnection();4 window.pc2 = new RTCPeerConnection();5 pc1.onicecandidate = e => {6 if (e.candidate) {7 pc2.addIceCandidate(e.candidate);8 }9 };10 pc2.onicecandidate = e => {11 if (e.candidate) {12 pc1.addIceCandidate(e.candidate);13 }14 };15 pc1.oniceconnectionstatechange = e => {16 if (pc1.iceConnectionState === "connected") {17 resolve();18 }19 };20 pc2.oniceconnectionstatechange = e => {21 if (pc2.iceConnectionState === "connected") {22 resolve();23 }24 };25 pc1.ontrack = e => {26 pc2.addTrack(e.track, e.streams[0]);27 };28 pc2.ontrack = e => {29 pc1.addTrack(e.track, e.streams[0]);30 };31 .getUserMedia({ audio: true, video: true })32 .then(stream => {33 pc1.addTransceiver(stream.getVideoTracks()[0], { direction: "sendrecv" });34 pc1.addTransceiver(stream.getAudioTracks()[0], { direction: "sendrecv" });35 pc1.createOffer().then(offer => {36 pc1.setLocalDescription(offer);37 pc2.setRemoteDescription(offer);38 pc2.createAnswer().then(answer => {39 pc2.setLocalDescription(answer);40 pc1.setRemoteDescription(answer);41 });42 });43 });44 });45}46function testGetTransceivers() {47 return new Promise((resolve, reject) => {48 window.pc1 = new RTCPeerConnection();49 window.pc2 = new RTCPeerConnection();50 pc1.onicecandidate = e => {51 if (e.candidate) {52 pc2.addIceCandidate(e.candidate);53 }54 };55 pc2.onicecandidate = e => {56 if (e.candidate) {57 pc1.addIceCandidate(e.candidate);58 }59 };60 pc1.oniceconnectionstatechange = e => {61 if (pc1.iceConnectionState ===

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 return new Promise(async (resolve, reject) => {3 const pc = new RTCPeerConnection();4 const transceiver = pc.addTransceiver("video");5 try {6 transceiver.setCodecPreferences([]);7 resolve(true);8 } catch (err) {9 reject(err);10 }11 });12}13test();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { WPT } from 'wpt';2import { RTCPeerConnection } from 'wrtc';3const wpt = new WPT();4const pc = new RTCPeerConnection();5wpt.setTransceiverCodecPreference(pc.getTransceivers()[0], 'opus', 'sendrecv');6import { WPT } from 'wpt';7import { RTCPeerConnection } from 'wrtc';8const wpt = new WPT();9const pc = new RTCPeerConnection();10wpt.setTransceiverDirection(pc.getTransceivers()[0], 'recvonly');11import { WPT } from 'wpt';12import { RTCPeerConnection } from 'wrtc';13const wpt = new WPT();14const pc = new RTCPeerConnection();15wpt.setTransceiverDirection(pc.getTransceivers()[0], 'recvonly');16import { WPT } from 'wpt';17import { RTCPeerConnection } from 'wrtc';18const wpt = new WPT();19const pc = new RTCPeerConnection();20wpt.setTransceiverMid(pc.getTransceivers()[0], 'test');21import { WPT } from 'wpt';22import { RTCPeerConnection } from 'wrtc';23const wpt = new WPT();24const pc = new RTCPeerConnection();25wpt.setTransceiverPreferedCodec(pc.getTransceivers()[0], 'opus');26import { WPT } from 'wpt';27import { RTCPeerConnection } from 'wrtc';28const wpt = new WPT();29const pc = new RTCPeerConnection();

Full Screen

Using AI Code Generation

copy

Full Screen

1function testSetTransceiverCodecPreference() {2 let transceiver = new RTCRtpTransceiver();3 let codec = new RTCRtpCodecCapability();4 transceiver.setCodecPreferences([codec]);5}6wpt_test_name('setTransceiverCodecPreference');7wpt_test(function() {8 testSetTransceiverCodecPreference();9});

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