How to use inputSource method in wpt

Best JavaScript code snippet using wpt

xr-input.js

Source:xr-input.js Github

copy

Full Screen

1import { EventHandler } from '../core/event-handler.js';2import { XrInputSource } from './xr-input-source.js';3/** @typedef {import('./xr-manager.js').XrManager} XrManager */4/**5 * Provides access to input sources for WebXR.6 *7 * @augments EventHandler8 */9class XrInput extends EventHandler {10 /**11 * @type {XrManager}12 * @private13 */14 manager;15 /**16 * @type {XrInputSource[]}17 * @private18 */19 _inputSources = [];20 /**21 * @type {Function}22 * @private23 */24 _onInputSourcesChangeEvt;25 /**26 * Create a new XrInput instance.27 *28 * @param {XrManager} manager - WebXR Manager.29 * @hideconstructor30 */31 constructor(manager) {32 super();33 this.manager = manager;34 this._onInputSourcesChangeEvt = (evt) => {35 this._onInputSourcesChange(evt);36 };37 this.manager.on('start', this._onSessionStart, this);38 this.manager.on('end', this._onSessionEnd, this);39 }40 /**41 * @event42 * @name XrInput#add43 * @description Fired when new {@link XrInputSource} is added to the list.44 * @param {XrInputSource} inputSource - Input source that has been added.45 * @example46 * app.xr.input.on('add', function (inputSource) {47 * // new input source is added48 * });49 */50 /**51 * @event52 * @name XrInput#remove53 * @description Fired when {@link XrInputSource} is removed to the list.54 * @param {XrInputSource} inputSource - Input source that has been removed.55 * @example56 * app.xr.input.on('remove', function (inputSource) {57 * // input source is removed58 * });59 */60 /**61 * @event62 * @name XrInput#select63 * @description Fired when {@link XrInputSource} has triggered primary action. This could be pressing a trigger button, or touching a screen.64 * @param {XrInputSource} inputSource - Input source that triggered select event.65 * @param {object} evt - XRInputSourceEvent event data from WebXR API.66 * @example67 * var ray = new pc.Ray();68 * app.xr.input.on('select', function (inputSource, evt) {69 * ray.set(inputSource.getOrigin(), inputSource.getDirection());70 * if (obj.intersectsRay(ray)) {71 * // selected an object with input source72 * }73 * });74 */75 /**76 * @event77 * @name XrInput#selectstart78 * @description Fired when {@link XrInputSource} has started to trigger primary action.79 * @param {XrInputSource} inputSource - Input source that triggered selectstart event.80 * @param {object} evt - XRInputSourceEvent event data from WebXR API.81 */82 /**83 * @event84 * @name XrInput#selectend85 * @description Fired when {@link XrInputSource} has ended triggerring primary action.86 * @param {XrInputSource} inputSource - Input source that triggered selectend event.87 * @param {object} evt - XRInputSourceEvent event data from WebXR API.88 */89 /**90 * @event91 * @name XrInput#squeeze92 * @description Fired when {@link XrInputSource} has triggered squeeze action. This is associated with "grabbing" action on the controllers.93 * @param {XrInputSource} inputSource - Input source that triggered squeeze event.94 * @param {object} evt - XRInputSourceEvent event data from WebXR API.95 */96 /**97 * @event98 * @name XrInput#squeezestart99 * @description Fired when {@link XrInputSource} has started to trigger sqeeze action.100 * @param {XrInputSource} inputSource - Input source that triggered squeezestart event.101 * @param {object} evt - XRInputSourceEvent event data from WebXR API.102 * @example103 * app.xr.input.on('squeezestart', function (inputSource, evt) {104 * if (obj.containsPoint(inputSource.getPosition())) {105 * // grabbed an object106 * }107 * });108 */109 /**110 * @event111 * @name XrInput#squeezeend112 * @description Fired when {@link XrInputSource} has ended triggerring sqeeze action.113 * @param {XrInputSource} inputSource - Input source that triggered squeezeend event.114 * @param {object} evt - XRInputSourceEvent event data from WebXR API.115 */116 /** @private */117 _onSessionStart() {118 const session = this.manager.session;119 session.addEventListener('inputsourceschange', this._onInputSourcesChangeEvt);120 session.addEventListener('select', (evt) => {121 const inputSource = this._getByInputSource(evt.inputSource);122 inputSource.update(evt.frame);123 inputSource.fire('select', evt);124 this.fire('select', inputSource, evt);125 });126 session.addEventListener('selectstart', (evt) => {127 const inputSource = this._getByInputSource(evt.inputSource);128 inputSource.update(evt.frame);129 inputSource._selecting = true;130 inputSource.fire('selectstart', evt);131 this.fire('selectstart', inputSource, evt);132 });133 session.addEventListener('selectend', (evt) => {134 const inputSource = this._getByInputSource(evt.inputSource);135 inputSource.update(evt.frame);136 inputSource._selecting = false;137 inputSource.fire('selectend', evt);138 this.fire('selectend', inputSource, evt);139 });140 session.addEventListener('squeeze', (evt) => {141 const inputSource = this._getByInputSource(evt.inputSource);142 inputSource.update(evt.frame);143 inputSource.fire('squeeze', evt);144 this.fire('squeeze', inputSource, evt);145 });146 session.addEventListener('squeezestart', (evt) => {147 const inputSource = this._getByInputSource(evt.inputSource);148 inputSource.update(evt.frame);149 inputSource._squeezing = true;150 inputSource.fire('squeezestart', evt);151 this.fire('squeezestart', inputSource, evt);152 });153 session.addEventListener('squeezeend', (evt) => {154 const inputSource = this._getByInputSource(evt.inputSource);155 inputSource.update(evt.frame);156 inputSource._squeezing = false;157 inputSource.fire('squeezeend', evt);158 this.fire('squeezeend', inputSource, evt);159 });160 // add input sources161 const inputSources = session.inputSources;162 for (let i = 0; i < inputSources.length; i++) {163 this._addInputSource(inputSources[i]);164 }165 }166 /** @private */167 _onSessionEnd() {168 let i = this._inputSources.length;169 while (i--) {170 const inputSource = this._inputSources[i];171 this._inputSources.splice(i, 1);172 inputSource.fire('remove');173 this.fire('remove', inputSource);174 }175 const session = this.manager.session;176 session.removeEventListener('inputsourceschange', this._onInputSourcesChangeEvt);177 }178 /**179 * @param {XRInputSourcesChangeEvent} evt - WebXR input sources change event.180 * @private181 */182 _onInputSourcesChange(evt) {183 // remove184 for (let i = 0; i < evt.removed.length; i++) {185 this._removeInputSource(evt.removed[i]);186 }187 // add188 for (let i = 0; i < evt.added.length; i++) {189 this._addInputSource(evt.added[i]);190 }191 }192 /**193 * @param {XRInputSource} xrInputSource - Input source to search for.194 * @returns {XrInputSource|null} The input source that matches the given WebXR input source or195 * null if no match is found.196 * @private197 */198 _getByInputSource(xrInputSource) {199 for (let i = 0; i < this._inputSources.length; i++) {200 if (this._inputSources[i].inputSource === xrInputSource) {201 return this._inputSources[i];202 }203 }204 return null;205 }206 /**207 * @param {XRInputSource} xrInputSource - Input source to add.208 * @private209 */210 _addInputSource(xrInputSource) {211 if (this._getByInputSource(xrInputSource))212 return;213 const inputSource = new XrInputSource(this.manager, xrInputSource);214 this._inputSources.push(inputSource);215 this.fire('add', inputSource);216 }217 /**218 * @param {XRInputSource} xrInputSource - Input source to remove.219 * @private220 */221 _removeInputSource(xrInputSource) {222 for (let i = 0; i < this._inputSources.length; i++) {223 if (this._inputSources[i].inputSource !== xrInputSource)224 continue;225 const inputSource = this._inputSources[i];226 this._inputSources.splice(i, 1);227 let h = inputSource.hitTestSources.length;228 while (h--) {229 inputSource.hitTestSources[h].remove();230 }231 inputSource.fire('remove');232 this.fire('remove', inputSource);233 return;234 }235 }236 /**237 * @param {*} frame - XRFrame from requestAnimationFrame callback.238 * @ignore239 */240 update(frame) {241 for (let i = 0; i < this._inputSources.length; i++) {242 this._inputSources[i].update(frame);243 }244 }245 /**246 * List of active {@link XrInputSource} instances.247 *248 * @type {XrInputSource[]}249 */250 get inputSources() {251 return this._inputSources;252 }253}...

Full Screen

Full Screen

inputSource.js

Source:inputSource.js Github

copy

Full Screen

1(function(a9){2 var inputSourcePrototype,3 validation = a9.validation,4 nodeIDAttribute = validation.nodeIDAttribute,5 u;6 function domNodeValidateOnEvent(){7 validateElementValue(validation.getNode(this.getAttribute(nodeIDAttribute)));8 }9 function validateElementValue(inputSource){10 var i,11 iMax,12 value,13 validationInstance;14 if ('valueAttribute' in inputSource){15 value = inputSource.e.getAttribute(inputSource.valueAttribute);16 } else{17 value = inputSource.e.value;18 }19 inputSource.isValidateOnce = true;20 inputSource.isValid = true;21 inputSource.value = value;22 inputSource.firstInvalid = null;23 for (i = 0, iMax = inputSource.validatorsDescriptors.length; i < iMax; i += 1){24 inputSource.isValids[i] =25 validation.validators[inputSource.validatorsDescriptors[i].n](26 value,27 inputSource.validatorsDescriptors[i],28 inputSource);29 if (!inputSource.isValids[i]){30 inputSource.isValid = false;31 if (inputSource.firstInvalid === null){32 inputSource.firstInvalid = inputSource.validatorsDescriptors[i];33 }34 }35 }36 a9.generateCustomEvent(inputSource, 'validate', inputSource.isValid, inputSource);37 if (inputSource.parent !== u){38 inputSource.parent.childValidate(inputSource);39 } else{40 validationInstance = inputSource.validationInstance;41 if (!validationInstance.isValidateOnce){42 validationInstance.isValidateOnce = true;43 }44 validationInstance.isValid = inputSource.isValid;45 a9.generateCustomEvent(validationInstance, 'validate', inputSource.isValid);46 }47 }48 function InputSource(id, nodeDescriptor, parentNode, validationInstance){49 var inputSource = this,50 valueAttribute,51 nodeDescriptorMask = nodeDescriptor.mask,52 nodeDescriptorMaskItem,53 i;54 inputSource.id = id;55 inputSource.validationInstance = validationInstance;56 inputSource.isDOMValidationNode = true;57 if (nodeDescriptor.data){58 inputSource.data = a9.cloneObject(nodeDescriptor.data);59 } else{60 inputSource.data = {};61 }62 inputSource.e = nodeDescriptor.e || a9.$(nodeDescriptor.i);63 inputSource.e.setAttribute(nodeIDAttribute, '' + id);64 inputSource.e.swf01_validation_inputSourceNode = inputSource;65 inputSource.isValid = false;66 inputSource.isValidateOnce = false;67 inputSource.isValids = [];68 inputSource.parent = parentNode;69 inputSource.message = '';70 if ('valueAttribute' in nodeDescriptor){71 valueAttribute = nodeDescriptor.valueAttribute;72 inputSource.valueAttribute = valueAttribute;73 inputSource.value = inputSource.e.getAttribute(valueAttribute);74 } else{75 inputSource.value = inputSource.e.value;76 }77 if (a9.isArray(nodeDescriptor.validators)){78 inputSource.validatorsDescriptors = nodeDescriptor.validators;79 } else{80 inputSource.validatorsDescriptors = [nodeDescriptor.validators];81 }82 if (('onValidate' in nodeDescriptor)83 && (nodeDescriptor.onValidate in validation.onValidate)){84 a9.addCustomEvent(inputSource, 'validate', validation.onValidate[nodeDescriptor.onValidate]);85 }86 if ('mask' in nodeDescriptor){87 if (typeof nodeDescriptorMask === 'string') {88 inputSource.masks = [89 a9.masking.make(90 inputSource.e,91 nodeDescriptorMask,92 nodeDescriptor.on,93 true94 )95 ];96 } else if (a9.isArray(nodeDescriptorMask)){97 inputSource.masks = [];98 for (i = nodeDescriptorMask.length; i--;) {99 nodeDescriptorMaskItem = nodeDescriptorMask[i];100 inputSource.masks.push(a9.masking.make(101 inputSource.e,102 nodeDescriptorMaskItem.n,103 nodeDescriptorMaskItem.on || nodeDescriptor.on,104 true,105 nodeDescriptorMaskItem106 ));107 }108 } else{109 inputSource.masks = [110 a9.masking.make(111 inputSource.e,112 nodeDescriptorMask.n,113 nodeDescriptorMask.on || nodeDescriptor.on,114 true,115 nodeDescriptorMask116 )117 ];118 }119 inputSource.mask = inputSource.masks[0];120 } else{121 inputSource.masks = u;122 inputSource.mask = u;123 }124 if (!('on' in nodeDescriptor) && !(nodeDescriptor.on in validation.on)){125 validation.on.blur(inputSource.e, domNodeValidateOnEvent);126 inputSource.off = validation.off.blur;127 } else{128 validation.on[nodeDescriptor.on](inputSource.e, domNodeValidateOnEvent);129 inputSource.off = validation.off[nodeDescriptor.on];130 }131 if (inputSource.value.length !== 0){132 validationInstance.onReadyStack.push(inputSource.validate, inputSource);133 }134 }135 inputSourcePrototype = InputSource.prototype;136 inputSourcePrototype.validate = function(){137 validateElementValue(this);138 };139 inputSourcePrototype.destructor = function(){140 var inputSource = this,141 inputSourceMasks = inputSource.masks,142 i;143 a9.removeAllCEListeners(inputSource);144 inputSource.id = null;145 inputSource.validationInstance = null;146 inputSource.off(inputSource.e, domNodeValidateOnEvent);147 inputSource.off = null;148 inputSource.e.removeAttribute(nodeIDAttribute);149 inputSource.e = null;150 inputSource.isValids.length = 0;151 inputSource.isValids = null;152 inputSource.validatorsDescriptors.length = 0;153 inputSource.validatorsDescriptors = null;154 inputSource.parent = null;155 inputSource.validate = null;156 inputSource.data = null;157 inputSource.message = null;158 inputSource.firstInvalid = null;159 if (inputSourceMasks !== u){160 for (i = inputSourceMasks.length; i--;) {161 inputSourceMasks[i].destructor();162 }163 inputSource.masks = null;164 inputSource.mask = null;165 }166 };167 validation.nodes.inputSource = function(id, nodeDescriptor, parentNode, validationInstance){168 return new InputSource(id, nodeDescriptor, parentNode, validationInstance);169 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 var testId = data.data.testId;8 wpt.getTestResults(testId, function(err, data) {9 if (err) return console.error(err);10 console.log(data);11 });12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15var options = {16};17wpt.runTest(url, options, function(err, data) {18 if (err) return console.error(err);19 var testId = data.data.testId;20 wpt.getTestResults(testId, function(err, data) {21 if (err) return console.error(err);22 console.log(data);23 });24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27var options = {28};29wpt.runTest(url, options, function(err, data) {30 if (err) return console.error(err);31 var testId = data.data.testId;32 wpt.getTestResults(testId, function(err, data) {33 if (err) return console.error(err);34 console.log(data);35 });36});37var wpt = require('webpagetest');38var wpt = new WebPageTest('www.webpagetest.org');39var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('./wptoolkit.js');2var inputSource = wptoolkit.inputSource;3var input = inputSource();4console.log(input);5var wptoolkit = require('./wptoolkit.js');6var inputSource = wptoolkit.inputSource;7var input = inputSource();8console.log(input);9var wptoolkit = require('./wptoolkit.js');10var inputSource = wptoolkit.inputSource;11var input = inputSource();12console.log(input);13var wptoolkit = require('./wptoolkit.js');14var inputSource = wptoolkit.inputSource;15var input = inputSource();16console.log(input);17var wptoolkit = require('./wptoolkit.js');18var inputSource = wptoolkit.inputSource;19var input = inputSource();20console.log(input);21var wptoolkit = require('./wptoolkit.js');22var inputSource = wptoolkit.inputSource;23var input = inputSource();24console.log(input);25var wptoolkit = require('./wptoolkit.js');26var inputSource = wptoolkit.inputSource;27var input = inputSource();28console.log(input);29var wptoolkit = require('./wptoolkit.js');30var inputSource = wptoolkit.inputSource;31var input = inputSource();32console.log(input);33var wptoolkit = require('./wptoolkit.js');34var inputSource = wptoolkit.inputSource;35var input = inputSource();36console.log(input);37var wptoolkit = require('./wptoolkit

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var client = wpt('API_KEY');3 if (!err) {4 console.log(data);5 }6});7{ input: 8 { inputSource: 9 [ { type: 'Keyboard',10 isAttached: true },11 { type: 'Mouse',12 isAttached: true },13 { type: 'TouchPad',14 isAttached: true } ] } }

Full Screen

Using AI Code Generation

copy

Full Screen

1var page = require('webpage').create();2page.open(url, function(status) {3 console.log("Status: " + status);4 if(status === "success") {5 var source = page.evaluate(function() {6 return document.documentElement.outerHTML;7 });8 console.log(source);9 }10 phantom.exit();11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var inputSource = require('wptoolkit').inputSource;2var currentInputSource = inputSource.inputSource();3console.log(currentInputSource);4{5 "dependencies": {6 }7}8var inputSource = require('wptoolkit').inputSource;9var currentInputSource = inputSource.inputSource();10console.log(currentInputSource);11var inputSource = require('wptoolkit').inputSource;12var currentInputSource = inputSource.inputSource();13console.log(currentInputSource);14var inputSource = require('wptoolkit').inputSource;15var currentInputSource = inputSource.inputSource();16console.log(currentInputSource);17var inputSource = require('wptoolkit').inputSource;18var currentInputSource = inputSource.inputSource();19console.log(currentInputSource);20var inputSource = require('wptoolkit').inputSource;21var currentInputSource = inputSource.inputSource();22console.log(currentInputSource);23var inputSource = require('wptoolkit').inputSource;24var currentInputSource = inputSource.inputSource();25console.log(currentInputSource);26var inputSource = require('wptoolkit').inputSource;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptk = new wptoolkit();2wptk.inputSource("test", "test", "test", "test", "test", "test", "test", "test", "test");3var wptk = new wptoolkit();4wptk.inputSource("test", "test", "test", "test", "test", "test", "test", "test", "test");5var wptk = new wptoolkit();6wptk.inputSource("test", "test", "test", "test", "test", "test", "test", "test", "test");7var wptk = new wptoolkit();8wptk.inputSource("test", "test", "test", "test", "test", "test", "test", "test", "test");9var wptk = new wptoolkit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var inputSource = wpt.inputSource;2var inputSourceInfo = inputSource.inputSourceInfo;3console.log(inputSourceInfo);4var inputSource = wpt.inputSource;5var inputSourceInfo = inputSource.inputSourceInfo;6console.log(inputSourceInfo);7var inputSource = wpt.inputSource;8var inputSourceInfo = inputSource.inputSourceInfo;9console.log(inputSourceInfo);10var inputSource = wpt.inputSource;11var inputSourceInfo = inputSource.inputSourceInfo;12console.log(inputSourceInfo);13var inputSource = wpt.inputSource;14var inputSourceInfo = inputSource.inputSourceInfo;15console.log(inputSourceInfo);16var inputSource = wpt.inputSource;17var inputSourceInfo = inputSource.inputSourceInfo;18console.log(inputSourceInfo);19var inputSource = wpt.inputSource;20var inputSourceInfo = inputSource.inputSourceInfo;21console.log(inputSourceInfo);22var inputSource = wpt.inputSource;23var inputSourceInfo = inputSource.inputSourceInfo;24console.log(inputSourceInfo);25var inputSource = wpt.inputSource;26var inputSourceInfo = inputSource.inputSourceInfo;27console.log(inputSourceInfo);28var inputSource = wpt.inputSource;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('www.webpagetest.org', 'A.0d1c7f8d3e3e7c0e2f2b7c0e2f2d7c0e');3 if(err) console.log(err);4 else console.log(data);5});6var wpt = require('webpagetest');7var test = new wpt('www.webpagetest.org', 'A.0d1c7f8d3e3e7c0e2f2b7c0e2f2d7c0e');8 if(err) console.log(err);9 else console.log(data);10});11var wpt = require('webpagetest');12var test = new wpt('www.webpagetest.org', 'A.0d1c7f8d3e3e7c0e2f2b7c0e2f2d7c0e');13 if(err) console.log(err);14 else console.log(data);15});16var wpt = require('webpagetest');17var test = new wpt('www.webpagetest.org', 'A.0d1c7f8d3e3e7c0e2f2b7c0e2f2d7c0e');18 if(err) console.log(err);19 else console.log(data);20});21var wpt = require('webpagetest');22var test = new wpt('www.webpagetest.org', 'A.0d1c

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