Best JavaScript code snippet using wpt
talker.js
Source:talker.js
...39 noiseSuppression: false40 }41 })42 .then(function(stream){43 thisRoom.localVideo = thisRoom.createVideoElement();44 thisRoom.localVideo.muted = true;45 thisRoom.localVideo.srcObject = stream;46 thisRoom.localVideo.play();47 thisRoom.send({ roomId: roomId, action: "hello" });48 })49 .catch(function(error){50 console.error(error);51 });52 };53 ws.onerror = function(error){54 console.error(error);55 };56 ws.onmessage = function(event){57 let m = JSON.parse(event.data);58 if ("sender" in m && m.action === "hello") {59 console.log("hello - " + m.sender);60 var peer = thisRoom.createPeer(m.sender);61 peer.createOffer()62 return;63 }64 if ("sender" in m && m.action === "bye") {65 console.log("bye - " + m.sender);66 var peer = peers[m.sender];67 delete peers[m.sender];68 peer.delete();69 return;70 }71 if ("sender" in m && "sdp" in m) {72 console.log("sdp - " + m.sender);73 var sessionDescription = new RTCSessionDescription(m.sdp);74 switch (m.sdp.type) {75 case 'offer':76 var peer = thisRoom.createPeer(m.sender);77 peer.setRemoteDescription(sessionDescription)78 .then(function(){79 peer.createAnswer();80 })81 .catch(function(error){82 console.error(error);83 });84 break;85 case 'answer':86 var peer = peers[m.sender];87 peer.setRemoteDescription(sessionDescription)88 .then(function(){89 })90 .catch(function(error){91 console.error(error);92 });93 break;94 }95 return;96 }97 if ("sender" in m && "candidate" in m) {98 console.log("candidate - " + m.sender);99 var peer = peers[m.sender];100 peer.addIceCandidate(new RTCIceCandidate(m.candidate));101 }102 };103 this.localVideo = null;104 /**105 * getRoomId106 */107 this.getRoomId = function(){108 return roomId;109 };110 /**111 * leave112 */113 this.leave = function(){114 ws.close();115 Object.values(peers).forEach(function(peer){116 peer.delete();117 });118 peers = null;119 videos.removeChild(thisRoom.localVideo);120 releaseMediaResources(videosObserver.takeRecords());121 videosObserver.disconnect();122 };123 /**124 * createVideoElement125 */126 this.createVideoElement = function(){127 var element = document.createElement("video");128 element.setAttribute("autoplay", "");129 element.setAttribute("playsinline", "");130 videos.appendChild(element);131 return element;132 };133 /**134 * createPeer135 */136 this.createPeer = function(peerId){137 var peer = new TalkerPeer(thisRoom, peerId);138 peers[peerId] = peer;139 return peer;140 };141 /**142 * send143 */144 this.send = function(data){145 ws.send(JSON.stringify(data));146 };147}148function TalkerPeer(room, peerId) {149 var video = room.createVideoElement();150 var connection = new RTCPeerConnection({ "iceServers": [] });151 connection.ontrack = function(event){152 video.srcObject = event.streams[0];153 video.play();154 };155 connection.onicecandidate = function(event){156 if (trickleice) {157 if (event.candidate !== null) {158 room.send({ recipient: peerId, candidate: event.candidate });159 }160 } else {161 if (event.candidate === null) {162 room.send({ recipient: peerId, sdp: connection.localDescription });163 }...
utils.js
Source:utils.js
1'use strict'2const log = (line) => {3 if (!line) return4 const output = document.getElementById('output')5 let message6 if (line.message) {7 message = `Error: ${line.message.toString()}`8 console.error(line)9 } else {10 message = line11 }12 if (message) {13 const node = document.createTextNode(`${message}\r\n`)14 output.appendChild(node)15 output.scrollTop = output.offsetHeight16 return node17 }18}19const dragDrop = (ipfs) => {20 const container = document.querySelector('#container')21 container.ondragover = (event) => {22 event.preventDefault()23 }24 container.ondrop = async (event) => {25 event.preventDefault()26 const files = Array.from(event.dataTransfer.items)27 .filter(item => item.kind === 'file')28 .map(item => item.getAsFile())29 .map(file => {30 return {31 path: file.name,32 content: file33 }34 })35 const progress = log(`IPFS: Adding...`)36 for await (const added of ipfs.add(files, {37 progress: (addedBytes) => {38 progress.textContent = `IPFS: Adding ${addedBytes} bytes\r\n`39 }40 })) {41 log(`IPFS: Added ${added.cid}`)42 document.querySelector('#cid').value = added.cid.toString()43 }44 if (event.dataTransfer.items && event.dataTransfer.items.clear) {45 event.dataTransfer.items.clear()46 }47 if (event.dataTransfer.clearData) {48 event.dataTransfer.clearData()49 }50 }51}52module.exports.statusMessages = (stream) => {53 let time = 054 const timeouts = [55 'Stream: Still loading data from IPFS...',56 'Stream: This can take a while depending on content availability',57 'Stream: Hopefully not long now',58 'Stream: *Whistles absentmindedly*',59 'Stream: *Taps foot*',60 'Stream: *Looks at watch*',61 'Stream: *Stares at floor*',62 'Stream: *Checks phone*',63 'Stream: *Stares at ceiling*',64 'Stream: Got anything nice planned for the weekend?'65 ].map(message => {66 time += 500067 return setTimeout(() => {68 log(message)69 }, time)70 })71 stream.once('data', () => {72 log('Stream: Started receiving data')73 timeouts.forEach(clearTimeout)74 })75 stream.once('error', () => {76 timeouts.forEach(clearTimeout)77 })78}79const createVideoElement = () => {80 const videoElement = document.getElementById('video')81 videoElement.addEventListener('loadedmetadata', () => {82 videoElement.play()83 .catch(log)84 })85 const events = [86 'playing',87 'waiting',88 'seeking',89 'seeked',90 'ended',91 'loadedmetadata',92 'loadeddata',93 'canplay',94 'canplaythrough',95 'durationchange',96 'play',97 'pause',98 'suspend',99 'emptied',100 'stalled',101 'error',102 'abort'103 ]104 events.forEach(event => {105 videoElement.addEventListener(event, () => {106 log(`Video: ${event}`)107 })108 })109 videoElement.addEventListener('error', () => {110 log(videoElement.error)111 })112 return videoElement113}114module.exports.log = log115module.exports.dragDrop = dragDrop...
connect.js
Source:connect.js
...18 const mediaStream = await getMediaStream(constraints);19 // Crea la Llamada al otro Par.20 const call = peer.call(idOtherConecction, mediaStream);21 // Crea el Elemento de Video22 createVideoElement(mediaStream);23 // Muestra las Conexiones a este Par.24 console.log(peer.connections);25 //Recibe el Media Stream Remoto como Argumento.26 call.on("stream", createVideoElement);27}28async function receivedCall(call, constraints) {29 // Obtiene el Medio del Usuario.30 const mediaStream = await getMediaStream(constraints);31 // Respoonde a la Llamada del Otro Par.32 call.answer(mediaStream);33 // Crea el Elemento de Video34 createVideoElement(mediaStream);35 // Muestra las Conexiones a este Par.36 console.log(peer.connections);37 //Recibe el Media Stream Remoto como Argumento.38 call.on("stream", createVideoElement);39}40/**41 * Obtiene El Media Stream del Usuario.42 @return mediaStream: stream43*/44async function getMediaStream(constraints) {45 try {46 const getUserMedia =47 navigator.mediaDevices.getUserMedia ||48 navigator.mediaDevices.webkitGetUserMedia ||49 navigator.mediaDevices.mozGetUserMedia;50 return await getUserMedia(constraints);51 } catch (err) {52 console.log("Failed to get local stream", err);53 }54}55/**56 * Crea el Lienzo donde se mostrara el Elemento de Video.57*/58function createVideoElement(mediaStream) {59 var video = document.createElement("video");60 video.id = Math.round(Math.random() * 10 * Date.now());61 video.srcObject = mediaStream;62 video.autoplay = true;63 video.muted = false;64 contentVideo.appendChild(video);65 video = "";...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 console.log(data);4});5var wpt = require('webpagetest');6var wpt = new WebPageTest('www.webpagetest.org');7 console.log(data);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11wpt.getLocations(function(err, data) {12 console.log(data);13});14var wpt = require('webpagetest');15var wpt = new WebPageTest('www.webpagetest.org');16wpt.getTesters(function(err, data) {17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getTesters(function(err, data) {22 console.log(data);23});24var wpt = require('webpagetest');25var wpt = new WebPageTest('www.webpagetest.org');26wpt.getTesters(function(err, data) {27 console.log(data);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.getTesters(function(err, data) {32 console.log(data);33});34var wpt = require('webpagetest');35var wpt = new WebPageTest('www.webpagetest.org');36wpt.getTesters(function(err, data) {37 console.log(data);38});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 console.log(data);7});8var wpt = require('webpagetest');9var wpt = new WebPageTest('www.webpagetest.org');10var options = {11};12 if (err) return console.error(err);13 console.log(data);14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17var options = {18};19 if (err) return console.error(err);20 console.log(data);21});22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24var options = {25};26 if (err) return console.error(err);27 console.log(data);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31var options = {32};33 if (err) return console.error(err);34 console.log(data);35});36var wpt = require('webpagetest');37var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1function createVideoElement() {2 var video = document.createElement('video');3 video.controls = true;4 video.autoplay = true;5 document.body.appendChild(video);6}7function createAudioElement() {8 var audio = document.createElement('audio');9 audio.controls = true;10 audio.autoplay = true;11 document.body.appendChild(audio);12}13function createImageElement() {14 var image = document.createElement('img');15 document.body.appendChild(image);16}17function createIFrameElement() {18 var iframe = document.createElement('iframe');19 document.body.appendChild(iframe);20}21function createCanvasElement() {22 var canvas = document.createElement('canvas');23 canvas.id = 'myCanvas';24 canvas.width = 100;25 canvas.height = 100;26 document.body.appendChild(canvas);27 var ctx = canvas.getContext('2d');28 ctx.fillStyle = 'rgb(200, 0, 0)';29 ctx.fillRect(10, 10, 50, 50);30 ctx.fillStyle = 'rgba(0, 0, 200, 0.5)';31 ctx.fillRect(30, 30, 50, 50);32}33function createSVGElement() {34 svg.setAttribute('width', '100px');35 svg.setAttribute('height', '100px');36 circle.setAttribute('cx', '50');37 circle.setAttribute('cy
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('Test video');3wp.createVideoElement(function(err, videoElement) {4 if (err) {5 throw err;6 }7 console.log(videoElement);8});9{10}11var wptools = require('wptools');12var wp = new wptools('Test audio');13wp.createAudioElement(function(err, audioElement) {14 if (err) {15 throw err;16 }17 console.log(audioElement);18});19{20}21var wptools = require('wptools');22var wp = new wptools('Test element');23wp.createElement(function(err, element) {24 if (err) {25 throw err;26 }27 console.log(element);28});29{
Using AI Code Generation
1var videoElement = driver.createVideoElement();2videoElement.play();3videoElement.pause();4videoElement.currentTime = 10;5videoElement.playbackRate = 2;6videoElement.volume = 0.5;7videoElement.muted = true;8videoElement.loop = true;9var audioElement = driver.createAudioElement();10audioElement.play();11audioElement.pause();12audioElement.currentTime = 10;13audioElement.playbackRate = 2;14audioElement.volume = 0.5;15audioElement.muted = true;16audioElement.loop = true;17var canvasElement = driver.createCanvasElement();18var context = canvasElement.getContext("2d");19context.fillStyle = "#FF0000";20context.fillRect(0, 0, 150, 75);21var imageElement = driver.createImageElement();22imageElement.setAttribute("alt", "Smiley face");23var divElement = driver.createDivElement();24divElement.setAttribute("style", "width:200px;height:100px;border:1px solid #000000;");25var spanElement = driver.createSpanElement();26spanElement.setAttribute("style", "font-size: 20px;");27var paragraphElement = driver.createParagraphElement();28paragraphElement.setAttribute("style", "text-align: center;");29var headingElement = driver.createHeadingElement(1);30headingElement.setAttribute("style", "font-size: 20px;");
Using AI Code Generation
1videoElement.play();2click(videoElement);3var url = getAttribute(videoElement, "src");4var rect = getBoundingClientRect(videoElement);5var styles = getComputedStyles(videoElement);6var style = getComputedStyle(videoElement, "width");7var property = getCssProperty(videoElement, "width");8var value = getCssValue(videoElement, "width");9var dimensions = getDimensions(videoElement);10var innerHtml = getInnerHtml(videoElement);11var outerHtml = getOuterHtml(videoElement);12var rect = getRect(videoElement);13var tagName = getTagName(videoElement);14var text = getText(videoElement);15var title = getTitle();16var url = getUrl();17var displayed = isDisplayed(videoElement);18var enabled = isEnabled(videoElement);19var present = isPresent(videoElement);20var selected = isSelected(videoElement);21sendKeys(videoElement, "test");22setRect(videoElement, 0, 0, 100, 100);
Using AI Code Generation
1document.body.appendChild(video);2document.body.appendChild(video);3document.body.appendChild(video);4document.body.appendChild(video);5document.body.appendChild(video);6document.body.appendChild(video);7document.body.appendChild(video);8document.body.appendChild(video);9document.body.appendChild(video);
Using AI Code Generation
1var videoElement = createVideoElement();2document.body.appendChild(videoElement);3setVideoElementWidth(videoElement, 320);4setVideoElementHeight(videoElement, 240);5setVideoElementControls(videoElement, true);6setVideoElementAutoplay(videoElement, true);7setVideoElementLoop(videoElement, true);8setVideoElementMuted(videoElement, true);9setVideoElementPreload(videoElement, "auto");10setVideoElementCrossOrigin(videoElement, "anonymous");11setVideoElementPlaybackRate(videoElement, 0.5);12setVideoElementVolume(videoElement, 0.5);
Using AI Code Generation
1var wp = require('wptools');2console.log(videoElement);3var wp = require('wptools');4console.log(audioElement);5var wp = require('wptools');6console.log(imageElement);7var wp = require('wptools');8console.log(iframeElement);9var wp = require('wptools');10console.log(linkElement);
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!!