Best JavaScript code snippet using wpt
firefox_shim.js
Source:firefox_shim.js
1/*2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.3 *4 * Use of this source code is governed by a BSD-style license5 * that can be found in the LICENSE file in the root of the source6 * tree.7 */8/* eslint-env node */9'use strict';10import * as utils from '../utils';11export {shimGetUserMedia} from './getusermedia';12export {shimGetDisplayMedia} from './getdisplaymedia';13export function shimOnTrack(window) {14 if (typeof window === 'object' && window.RTCTrackEvent &&15 ('receiver' in window.RTCTrackEvent.prototype) &&16 !('transceiver' in window.RTCTrackEvent.prototype)) {17 Object.defineProperty(window.RTCTrackEvent.prototype, 'transceiver', {18 get() {19 return {receiver: this.receiver};20 }21 });22 }23}24export function shimPeerConnection(window, browserDetails) {25 if (typeof window !== 'object' ||26 !(window.RTCPeerConnection || window.mozRTCPeerConnection)) {27 return; // probably media.peerconnection.enabled=false in about:config28 }29 if (!window.RTCPeerConnection && window.mozRTCPeerConnection) {30 // very basic support for old versions.31 window.RTCPeerConnection = window.mozRTCPeerConnection;32 }33 if (browserDetails.version < 53) {34 // shim away need for obsolete RTCIceCandidate/RTCSessionDescription.35 ['setLocalDescription', 'setRemoteDescription', 'addIceCandidate']36 .forEach(function(method) {37 const nativeMethod = window.RTCPeerConnection.prototype[method];38 const methodObj = {[method]() {39 arguments[0] = new ((method === 'addIceCandidate') ?40 window.RTCIceCandidate :41 window.RTCSessionDescription)(arguments[0]);42 return nativeMethod.apply(this, arguments);43 }};44 window.RTCPeerConnection.prototype[method] = methodObj[method];45 });46 }47 const modernStatsTypes = {48 inboundrtp: 'inbound-rtp',49 outboundrtp: 'outbound-rtp',50 candidatepair: 'candidate-pair',51 localcandidate: 'local-candidate',52 remotecandidate: 'remote-candidate'53 };54 const nativeGetStats = window.RTCPeerConnection.prototype.getStats;55 window.RTCPeerConnection.prototype.getStats = function getStats() {56 const [selector, onSucc, onErr] = arguments;57 return nativeGetStats.apply(this, [selector || null])58 .then(stats => {59 if (browserDetails.version < 53 && !onSucc) {60 // Shim only promise getStats with spec-hyphens in type names61 // Leave callback version alone; misc old uses of forEach before Map62 try {63 stats.forEach(stat => {64 stat.type = modernStatsTypes[stat.type] || stat.type;65 });66 } catch (e) {67 if (e.name !== 'TypeError') {68 throw e;69 }70 // Avoid TypeError: "type" is read-only, in old versions. 34-43ish71 stats.forEach((stat, i) => {72 stats.set(i, Object.assign({}, stat, {73 type: modernStatsTypes[stat.type] || stat.type74 }));75 });76 }77 }78 return stats;79 })80 .then(onSucc, onErr);81 };82}83export function shimSenderGetStats(window) {84 if (!(typeof window === 'object' && window.RTCPeerConnection &&85 window.RTCRtpSender)) {86 return;87 }88 if (window.RTCRtpSender && 'getStats' in window.RTCRtpSender.prototype) {89 return;90 }91 const origGetSenders = window.RTCPeerConnection.prototype.getSenders;92 if (origGetSenders) {93 window.RTCPeerConnection.prototype.getSenders = function getSenders() {94 const senders = origGetSenders.apply(this, []);95 senders.forEach(sender => sender._pc = this);96 return senders;97 };98 }99 const origAddTrack = window.RTCPeerConnection.prototype.addTrack;100 if (origAddTrack) {101 window.RTCPeerConnection.prototype.addTrack = function addTrack() {102 const sender = origAddTrack.apply(this, arguments);103 sender._pc = this;104 return sender;105 };106 }107 window.RTCRtpSender.prototype.getStats = function getStats() {108 return this.track ? this._pc.getStats(this.track) :109 Promise.resolve(new Map());110 };111}112export function shimReceiverGetStats(window) {113 if (!(typeof window === 'object' && window.RTCPeerConnection &&114 window.RTCRtpSender)) {115 return;116 }117 if (window.RTCRtpSender && 'getStats' in window.RTCRtpReceiver.prototype) {118 return;119 }120 const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;121 if (origGetReceivers) {122 window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {123 const receivers = origGetReceivers.apply(this, []);124 receivers.forEach(receiver => receiver._pc = this);125 return receivers;126 };127 }128 utils.wrapPeerConnectionEvent(window, 'track', e => {129 e.receiver._pc = e.srcElement;130 return e;131 });132 window.RTCRtpReceiver.prototype.getStats = function getStats() {133 return this._pc.getStats(this.track);134 };135}136export function shimRemoveStream(window) {137 if (!window.RTCPeerConnection ||138 'removeStream' in window.RTCPeerConnection.prototype) {139 return;140 }141 window.RTCPeerConnection.prototype.removeStream =142 function removeStream(stream) {143 utils.deprecated('removeStream', 'removeTrack');144 this.getSenders().forEach(sender => {145 if (sender.track && stream.getTracks().includes(sender.track)) {146 this.removeTrack(sender);147 }148 });149 };150}151export function shimRTCDataChannel(window) {152 // rename DataChannel to RTCDataChannel (native fix in FF60):153 // https://bugzilla.mozilla.org/show_bug.cgi?id=1173851154 if (window.DataChannel && !window.RTCDataChannel) {155 window.RTCDataChannel = window.DataChannel;156 }157}158export function shimAddTransceiver(window) {159 // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647160 // Firefox ignores the init sendEncodings options passed to addTransceiver161 // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918162 if (!(typeof window === 'object' && window.RTCPeerConnection)) {163 return;164 }165 const origAddTransceiver = window.RTCPeerConnection.prototype.addTransceiver;166 if (origAddTransceiver) {167 window.RTCPeerConnection.prototype.addTransceiver =168 function addTransceiver() {169 this.setParametersPromises = [];170 // WebIDL input coercion and validation171 let sendEncodings = arguments[1] && arguments[1].sendEncodings;172 if (sendEncodings === undefined) {173 sendEncodings = [];174 }175 sendEncodings = [...sendEncodings];176 const shouldPerformCheck = sendEncodings.length > 0;177 if (shouldPerformCheck) {178 // If sendEncodings params are provided, validate grammar179 sendEncodings.forEach((encodingParam) => {180 if ('rid' in encodingParam) {181 const ridRegex = /^[a-z0-9]{0,16}$/i;182 if (!ridRegex.test(encodingParam.rid)) {183 throw new TypeError('Invalid RID value provided.');184 }185 }186 if ('scaleResolutionDownBy' in encodingParam) {187 if (!(parseFloat(encodingParam.scaleResolutionDownBy) >= 1.0)) {188 throw new RangeError('scale_resolution_down_by must be >= 1.0');189 }190 }191 if ('maxFramerate' in encodingParam) {192 if (!(parseFloat(encodingParam.maxFramerate) >= 0)) {193 throw new RangeError('max_framerate must be >= 0.0');194 }195 }196 });197 }198 const transceiver = origAddTransceiver.apply(this, arguments);199 if (shouldPerformCheck) {200 // Check if the init options were applied. If not we do this in an201 // asynchronous way and save the promise reference in a global object.202 // This is an ugly hack, but at the same time is way more robust than203 // checking the sender parameters before and after the createOffer204 // Also note that after the createoffer we are not 100% sure that205 // the params were asynchronously applied so we might miss the206 // opportunity to recreate offer.207 const {sender} = transceiver;208 const params = sender.getParameters();209 if (!('encodings' in params) ||210 // Avoid being fooled by patched getParameters() below.211 (params.encodings.length === 1 &&212 Object.keys(params.encodings[0]).length === 0)) {213 params.encodings = sendEncodings;214 sender.sendEncodings = sendEncodings;215 this.setParametersPromises.push(sender.setParameters(params)216 .then(() => {217 delete sender.sendEncodings;218 }).catch(() => {219 delete sender.sendEncodings;220 })221 );222 }223 }224 return transceiver;225 };226 }227}228export function shimGetParameters(window) {229 if (!(typeof window === 'object' && window.RTCRtpSender)) {230 return;231 }232 const origGetParameters = window.RTCRtpSender.prototype.getParameters;233 if (origGetParameters) {234 window.RTCRtpSender.prototype.getParameters =235 function getParameters() {236 const params = origGetParameters.apply(this, arguments);237 if (!('encodings' in params)) {238 params.encodings = [].concat(this.sendEncodings || [{}]);239 }240 return params;241 };242 }243}244export function shimCreateOffer(window) {245 // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647246 // Firefox ignores the init sendEncodings options passed to addTransceiver247 // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918248 if (!(typeof window === 'object' && window.RTCPeerConnection)) {249 return;250 }251 const origCreateOffer = window.RTCPeerConnection.prototype.createOffer;252 window.RTCPeerConnection.prototype.createOffer = function createOffer() {253 if (this.setParametersPromises && this.setParametersPromises.length) {254 return Promise.all(this.setParametersPromises)255 .then(() => {256 return origCreateOffer.apply(this, arguments);257 })258 .finally(() => {259 this.setParametersPromises = [];260 });261 }262 return origCreateOffer.apply(this, arguments);263 };264}265export function shimCreateAnswer(window) {266 // https://github.com/webrtcHacks/adapter/issues/998#issuecomment-516921647267 // Firefox ignores the init sendEncodings options passed to addTransceiver268 // https://bugzilla.mozilla.org/show_bug.cgi?id=1396918269 if (!(typeof window === 'object' && window.RTCPeerConnection)) {270 return;271 }272 const origCreateAnswer = window.RTCPeerConnection.prototype.createAnswer;273 window.RTCPeerConnection.prototype.createAnswer = function createAnswer() {274 if (this.setParametersPromises && this.setParametersPromises.length) {275 return Promise.all(this.setParametersPromises)276 .then(() => {277 return origCreateAnswer.apply(this, arguments);278 })279 .finally(() => {280 this.setParametersPromises = [];281 });282 }283 return origCreateAnswer.apply(this, arguments);284 };...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8var options = {
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');3wpt.sendEncodings('www.webpagetest.org', 'A.12345678901234567890123456789012', 'test', { encodings: 'gzip, deflate, br' }, function(err, data) {4 if (err) {5 console.error(err);6 return;7 }8 console.log(data);9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');12wpt.getLocations(function(err, data) {13 if (err) {14 console.error(err);15 return;16 }17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');21wpt.getTesters(function(err, data) {22 if (err) {23 console.error(err);24 return;25 }26 console.log(data);27});28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');30wpt.getTesters(function(err, data) {31 if (err) {32 console.error(err);33 return;34 }35 console.log(data);36});37var wpt = require('webpagetest');38var wpt = new WebPageTest('www.webpagetest.org', 'A.12345678901234567890123456789012');39wpt.getTesters(function(err, data) {40 if (err) {41 console.error(err);42 return;43 }44 console.log(data);45});46var wpt = require('webpag
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org','API_KEY');3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8})
Using AI Code Generation
1var wptools = require('wptools');2wptools.sendEncodings('en', 'Test', 'Test', 'Test', function(response) {3 console.log(response);4});5var wptools = require('wptools');6wptools.getEncodings('en', 'Test', function(response) {7 console.log(response);8});9var wptools = require('wptools');10wptools.getCategories('en', 'Test', function(response) {11 console.log(response);12});13var wptools = require('wptools');14wptools.getTemplates('en', 'Test', function(response) {15 console.log(response);16});17var wptools = require('wptools');18wptools.getLinks('en', 'Test', function(response) {19 console.log(response);20});21var wptools = require('wptools');22wptools.getTransclusions('en', 'Test', function(response) {23 console.log(response);24});25var wptools = require('wptools');26wptools.getImages('en', 'Test', function(response) {27 console.log(response);28});29var wptools = require('wptools');30wptools.getImageInfo('en', 'Test', function(response) {31 console.log(response);32});33var wptools = require('wptools');34wptools.getLangLinks('en', 'Test', function(response) {35 console.log(response);36});37var wptools = require('wptools');38wptools.getIWLinks('en', 'Test', function(response) {39 console.log(response);40});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!