How to use on_event method in wpt

Best JavaScript code snippet using wpt

mlib.core.mme.hls.js

Source:mlib.core.mme.hls.js Github

copy

Full Screen

...327 }328 if(this.on_event)329 {330 /* function({panel:install_div_panel, download:cosebase-url}){ build html-content, must let first a-link as try-flash, and second a-link is download with name=[flash|plug]} */331 this.on_event({type:"install_ui", panel:this.install_panel, download:codebase, ver_cur:this.ver_cur});332 }333 this.install_panel.style.visibility = "";334 this.install_test_panel.style.cssText = "position:absolute;left:-1px;top:-1px;width:1px;height:1px;";335 if(a = dom_get_item_by_name(this.install_panel, "*", "flash"))336 {337 mevt.bind(a, "click", function(e)338 {339 me.clear_install();340 me.status = me.plug_status.initting;341 if(null == (me.plug_obj = me.create_plug(me.parent, true, true, me.create_params)))342 {343 me.status = me.plug_status.closed;344 if(me.on_event){me.on_event({type:"missing"});};345 }346 else347 {348 if(me.on_event){me.on_event({type:"create"});};349 }350 return false;351 });352 }353 if(a = dom_get_item_by_name(this.install_panel, "*", "plug"))354 {355 mevt.bind(a, "click", function(e)356 {357 a = dom_get_item_by_name(me.install_panel, "*", "plug_installing");358 if(a)359 {360 a.style.display = "";361 a.innerHTML = me.lang.installing;362 if(a = dom_get_item_by_name(me.install_panel, "*", "plug"))363 {364 a.style.display = "none";365 }366 }367 else if(a = dom_get_item_by_name(me.install_panel, "*", "plug"))368 {369 a.innerHTML = "<b>" + ((mhack.ie || mhack.chrome)?me.lang.installing:me.lang.rebot_hint) + "</b>";370 }371 if(mhack.ie || mhack.chrome)372 {373 me.install_timer = setInterval(function(){374 if(mme.prototype.create_plug(me.install_test_panel, false, true, me.create_params))375 {376 me.clear_install();377 me.status = me.plug_status.initting;378 if(null == (me.plug_obj = me.create_plug(me.parent, true, true, me.create_params)))379 {380 me.status = me.plug_status.closed;381 if(me.on_event){me.on_event({type:"missing"});};382 }383 else384 {385 if(me.on_event){me.on_event({type:"create"});};386 }387 }388 }, 1000);389 }390 });391 }392 },393 on_plug_event:function(json)394 {395 var e = meval(json);396 if(null == e)397 {/* xxxxxx error. what append. */398 return 0;399 }400 if(e.target && e.target.type && e.target.url)401 {402 e.chl = this.chl_get(e.target.type, e.target.url)403 }404 405 switch (e.type)406 {407 case "is_ready": { return (null != this.plug_obj); break; }408 case "ready": { this.status = this.plug_status.running; break; }409 case "close":410 {411 if(e.chl){ e.chl.status = this.chl_status.closed; e.chl.id = 0; };412 break;413 }414 case "active": { break; }415 }416 if(this.is_created && this.on_event)417 {418 this.on_event(e);419 }420 return 0;421 },422 create:function(obj)423 { 424 console.log(obj,"obj_mme")425 var parent = obj.parent, me = this;426 if(undefined != obj.hls_id && null != obj.hls_id)427 {428 if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { 429 this.platform = 'ios';430 } else if (/(Android)/i.test(navigator.userAgent)) { 431 this.platform = 'android';432 } else { 433 this.platform = 'pc';434 };435 this.hls_id = obj.hls_id;436 this.ref_obj = obj.ref_obj;437 this.parent = parent;438 this.ref_obj.mme = this;439 this.on_event = obj.on_event;440 var video = null;441 if(this.platform == 'pc')442 {443 this.parent.innerHTML = '<video class="video-js vjs-default-skin vjs-big-play-centered" controls><source id="hls-vs" type="application/x-mpegURL"></video>';444 video = parent.getElementsByClassName('video-js vjs-default-skin vjs-big-play-centered')[0];445 video.width = this.parent.offsetWidth;446 video.height = this.parent.offsetHeight;447 }448 else449 {450 this.parent.innerHTML = '<video class="video-js" style="width:100%; height:100%; object-fit: fill" controls></video>';451 video = parent.getElementsByClassName('video-js')[0];452 }453 video.id = this.hls_id;454 this.player = null;455 this.on_event(this.ref_obj);456 return 0;457 }458 /* init parent and skin */459 this.skin = this.get_default_skin();460 if("object" == typeof(obj.skin))461 {462 obj_merge(this.skin, obj.skin);463 }464 this.parent = parent;465 if(undefined != obj.debug){ this.debug = obj.debug; }466 if(undefined != obj.windowless){ this.windowless = obj.windowless; }467 if(undefined != obj.enable_native_plug){ this.enable_native_plug = obj.enable_native_plug; }468 if(undefined != obj.enable_flash_plug){ this.enable_flash_plug = obj.enable_flash_plug; }469 this.on_event = obj.on_event;470 this.cam_index = -1;471 this.mic_index = -1;472 this.chls = [];473 this.create_params = obj.params||"";474 this.ref_obj = obj.ref_obj;475 this.is_created = false;476 if(obj.on_event)477 {478 this.on_event_callback = obj.on_event;479 this.on_event = function(e)480 {481 e.plug = me;482 e.ref_obj = me.ref_obj;483 me.on_event_callback(e);484 e.plug = (e.ref_obj = null);485 };486 }487 /* do create */488 this.id = (++ this.id_allocer.value);489 window["plug_" + this.id + "_on_event"] = function(s){ return me.on_plug_event(s); };490 this.status = this.plug_status.initting;491 /* try create native plugin */492 if(null == (this.plug_obj = this.create_plug(parent,493 this.enable_flash_plug && ((!obj.plug_install_mute) || ((navigator.platform != "Win32") && (navigator.platform != "MacIntel"))), //(!!obj.plug_install_mute)494 this.enable_native_plug,495 this.create_params)))496 {/* create native plug in failed */497 if(this.enable_native_plug498 && (!obj.plug_install_mute)499 && ((navigator.platform == "Win32") || (navigator.platform == "MacIntel")))500 {/* try install */501 if(this.ver_cur >= this.ver_min)502 {/* old plugin with lower version */503 me.status = me.plug_status.initting;504 if(null == (me.plug_obj = me.create_plug(parent, true, true, me.create_params)))505 {506 me.status = me.plug_status.closed;507 if(me.on_event){me.on_event({type:"missing"});};508 }509 else510 {511 if(me.on_event){me.on_event({type:"create"});};512 }513 }514 else515 {516 // this.status = this.plug_status.installing;//去掉使用普通视频播放页面517 me.status = me.plug_status.initting;518 if(null == (me.plug_obj = me.create_plug(parent, true, true, me.create_params)))519 {520 me.status = me.plug_status.closed;521 if(me.on_event){me.on_event({type:"missing"});};522 }523 else524 { 525 if(me.on_event){me.on_event({type:"create"});};526 }527 // this.install(function() //去掉使用普通视频播放页面528 // {529 // me.status = me.plug_status.initting;530 // if(null == (me.plug_obj = me.create_plug(parent, true, true, me.create_params)))531 // {532 // me.status = me.plug_status.closed;533 // if(me.on_event){me.on_event({type:"missing"});};534 // }535 // else536 // {537 // if(me.on_event){me.on_event({type:"create"});};538 // }539 // });540 }541 }542 else543 {/* can not install */544 me.status = me.plug_status.closed;545 if(me.on_event){me.on_event({type:"missing"});};546 }547 }548 else if((this.status == this.plug_status.running) && me.on_event)549 {550 setTimeout(function(){if(me.on_event){ me.on_event({type:"ready"});};}, 0);551 }552 this.is_created = true;553 },554 destroy:function()555 {556 this.clear_install();557 window["plug_" + this.id + "_on_event"] = null;558 for(var chl, i = this.chls.length - 1; 0 <= i; --i)559 {560 if(chl = this.chls[i]){ this.chl_destroy(chl); };561 }562 if(this.dev_form)563 {564 this.dev_form.onsubmit = null;565 this.dev_form.innerHTML = "";566 this.dev_form.parentNode.removeChild(this.dev_form);567 delete this.dev_form;568 }569 if(this.plug_obj){ delete this.plug_obj; };570 if(this.parent)571 {572 this.parent.innerTHML = "";573 delete this.parent;574 }575 if(this.id){ delete this.id; };576 if(this.status){ delete this.status; };577 if(this.on_event){ delete this.on_event; };578 },579 update:function()580 {581 },582 is_ready:function(func)583 { 584 return (this.plug_obj585 && (this.status == this.plug_status.running)586 && ((null == func) || (("undefined" != typeof(this.plug_obj[func]))))); 587 },588 select_device:function(cams, mics, on_done)589 {590 var dev, i, radio, radios, me = this, dev_form = this.dev_form, html = "";591 if(null == dev_form)592 {593 this.parent.appendChild(this.dev_from = (dev_form = document.createElement ('form')));594 dev_form.style.cssText = "position:absolute;left:0px;top:0px;width:100%;height:100%;overflow-y:auto;overflow-x:none;padding:0px;margin:0px;background:transparent;background:#000;color:#fff;line-height:1.5em;font-size:12px;";595 }596 dev_form.style.visibility = "hidden";597 dev_form.innerHTML = "";598 //dev_form.style.display = "";599 html += "<div style='position:absolute;left:5%;width:90%'><br/><center><span style='font-size:18x;'><b>" + this.lang.plz_select + this.lang.cam + this.lang.and + this.lang.mic + "</span></center>"600 if(cams && (0 < cams.length))601 {602 html += "<br/><span>" + this.lang.cam + "</span><br/>";603 for(i = 0; i < cams.length; i++)604 {605 dev = cams[i];606 html += "<input type='radio' name='cam' id='cam_" + dev.index + "' value='" + dev.index + "' " + ((0 == i)?"checked":"") + "/>"607 + "<label for='cam_" + dev.index + "'>" + dev.name + "</label><br/>"608 }609 }610 if(mics && (0 < mics.length))611 {612 html += "<br/><span>" + this.lang.mic + "</span><br/>";613 for(i = 0; i < mics.length; i++)614 {615 dev = mics[i];616 html += "<input type='radio' name='mic' id='mic_" + dev.index + "' value='" + dev.index + "' " + ((0 == i)?"checked":"") + "/>"617 + "<label for='mic_" + dev.index + "'>" + dev.name + "</label><br/>"618 }619 }620 html += "<br/><center>"621 + "<input type='submit' value='" + this.lang.set_done + "'"622 + " onmouseover='this.style.background=\"#666\";'"623 + " onmouseout='this.style.background=\"#333\";'"624 + " style='cursor:pointer;border:none;padding:0px;margin:0px;font-size:14px;color:#fff;width:120px;height:24px;"625 + "-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3Px;"626 + mhack.css_box_shadow(1, "#666666")627 + "line-height:32px;background:#333;'/></center></div>";628 dev_form.innerHTML = html;629 if(this.on_event)630 {/* call back */631 this.on_event({type:"select_device_ui", form:dev_form, mics:mics, cams:cams});632 }633 dev_form.style.visibility = "";634 dev_form.onsubmit = function()635 {636 for(i = 0, radios = dev_form.getElementsByTagName("input"); i < radios.length; ++i)637 {638 if(((radio = radios[i]).type == "radio") && radio.checked)639 {640 if(radio.name == "cam"){ me.cam_index = radio.value; }641 else if(radio.name == "mic"){ me.mic_index = radio.value; }642 }643 }644 dev_form.style.display = "none";645 on_done();...

Full Screen

Full Screen

parseDucks.spec.js

Source:parseDucks.spec.js Github

copy

Full Screen

1import createContext from '../../src/ctx/createContext';2import { ON_EVENT, DUCKS } from '../../src/config/constants';3describe('parseDucks', () => {4 it('should work when ducks is omitted', () => {5 const ctx = createContext({6 [ON_EVENT]: [{ on: 'd1' }, { on: ['d1', 'd2'] }]7 });8 expect(ctx[ON_EVENT]['d1'].length).toBe(2);9 });10 it('should merge declarations from the ducks', () => {11 const ctx = createContext({12 [ON_EVENT]: [{ on: 'd1' }],13 [DUCKS]: [14 {15 [ON_EVENT]: [{ on: 'd2' }]16 }17 ]18 });19 expect(Object.keys(ctx[ON_EVENT]).length).toBe(2);20 });21 it('should merge declarations normally', () => {22 const ctx = createContext({23 [ON_EVENT]: [{ on: 'd1' }, { on: ['d2', 'd3'] }],24 [DUCKS]: [25 {26 [ON_EVENT]: [{ on: 'd1' }, { on: 'd1' }, { on: ['d1', 'd2'] }]27 }28 ]29 });30 expect(ctx[ON_EVENT]['d1'].length).toBe(4);31 expect(ctx[ON_EVENT]['d2'].length).toBe(2);32 expect(ctx[ON_EVENT]['d3'].length).toBe(1);33 });34 it('should combine multiple ducks', () => {35 const ctx = createContext({36 [ON_EVENT]: [{ on: 'd1' }],37 [DUCKS]: [{ [ON_EVENT]: [{ on: 'd1' }] }, { [ON_EVENT]: [{ on: 'd1' }] }]38 });39 expect(ctx[ON_EVENT]['d1'].length).toBe(3);40 });41 it('should ignore unwanted object properties', () => {42 const ctx = createContext({43 [ON_EVENT]: [{ on: 'd1' }],44 [DUCKS]: [45 {46 [ON_EVENT]: [{ on: 'd1' }],47 test: () => {},48 bar: 'something',49 foo: 150 }51 ]52 });53 expect(ctx[ON_EVENT]['d1'].length).toBe(2);54 });55 it('should initiate props if they are not defined', () => {56 const ctx = createContext({57 [DUCKS]: [58 {59 [ON_EVENT]: [{ on: 'd1' }]60 }61 ]62 });63 expect(ctx[ON_EVENT]['d1'].length).toBe(1);64 });65 it('should be able to parse composed ducks', () => {66 const ctx = createContext({67 [ON_EVENT]: [{ on: 'd1' }],68 [DUCKS]: [69 {70 [ON_EVENT]: [{ on: 'd1' }],71 [DUCKS]: [72 {73 [ON_EVENT]: [{ on: 'd1' }],74 [DUCKS]: [75 {76 [ON_EVENT]: [{ on: 'd1' }],77 [DUCKS]: [78 {79 [ON_EVENT]: [{ on: 'd1' }]80 }81 ]82 }83 ]84 },85 {86 [ON_EVENT]: [{ on: 'd1' }],87 [DUCKS]: [88 {89 [ON_EVENT]: [{ on: 'd1' }]90 }91 ]92 }93 ]94 }95 ]96 });97 expect(ctx[ON_EVENT]['d1'].length).toBe(7);98 });...

Full Screen

Full Screen

parseSituations.spec.js

Source:parseSituations.spec.js Github

copy

Full Screen

1import createContext from '../../src/ctx/createContext';2import { ON_EVENT } from '../../src/config/constants';3describe('parseSituation', () => {4 it('should parse situations on false / falsy', () => {5 const ctx = createContext({6 [ON_EVENT]: [7 { on: 'test1', situation: false },8 { on: 'test2', situation: null },9 { on: 'test3', situation: '' },10 { on: 'test4', situation: 0 },11 { on: 'test5', situation: undefined },12 { on: 'test6' }13 ]14 });15 expect(ctx[ON_EVENT]['test1'][0].situations.length).toBe(1);16 expect(ctx[ON_EVENT]['test2'][0].situations.length).toBe(1);17 expect(ctx[ON_EVENT]['test3'][0].situations.length).toBe(1);18 expect(ctx[ON_EVENT]['test4'][0].situations.length).toBe(1);19 expect(ctx[ON_EVENT]['test5'][0].situations.length).toBe(1);20 expect(ctx[ON_EVENT]['test6'][0].situations.length).toBe(0);21 });22 it('should parse situation alias', () => {23 const ctx = createContext({24 [ON_EVENT]: [{ on: 'test1', when: false }]25 });26 expect(ctx[ON_EVENT]['test1'][0].situations.length).toBe(1);27 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1on_event("request", function(request) {2 console.log("request");3 console.log(request);4 console.log("request");5 return request;6});7on_event("response", function(response) {8 console.log("response");9 console.log(response);10 console.log("response");11 return response;12});13on_event("done", function(result) {14 console.log("done");15 console.log(result);16 console.log("done");17 return result;18});19on_event("error", function(error) {20 console.log("error");21 console.log(error);22 console.log("error");23 return error;24});25[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.on_event('done', function () {2 wpt.log('done event fired');3 wpt.log('capturing screenshot');4 wpt.screenshot();5 wpt.log('capturing har');6 wpt.har();7 wpt.log('capturing png screen shot');8 wpt.png_screen_shot();9 wpt.log('capturing video');10 wpt.video();11 wpt.log('capturing visual comparison');12 wpt.visual_comparison();13 wpt.log('capturing waterfall');14 wpt.waterfall();15 wpt.log('capturing doc comple

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.on_event("onload", function(){2 wpt.log("onload event triggered");3});4wpt.on_event("onload", function(){5 wpt.log("onload event triggered again");6});7wpt.on_event("onload", function(){8 wpt.log("onload event triggered again and again");9});10wpt.on_event("onload", function(){11 wpt.log("onload event triggered again and again and again");12});13wpt.on_event("onload", function(){14 wpt.log("onload event triggered again and again and again and again");15});16wpt.on_event("onload", function(){17 wpt.log("onload event triggered again and again and again and again and again");18});19wpt.on_event("onload", function(){20 wpt.log("onload event triggered again and again and again and again and again and again");21});22wpt.on_event("onload", function(){23 wpt.log("onload event triggered again and again and again and again and again and again and again");24});25wpt.on_event("onload", function(){26 wpt.log("onload event triggered again and again and again and again and again and again and again and again");27});28wpt.on_event("onload", function(){29 wpt.log("onload event triggered again and again and again and again and again and again and again and again and again");30});31wpt.on_event("onload", function(){32 wpt.log("onload event triggered again and again and again and again and again and again and again and again and again and again");33});34wpt.on_event("onload", function(){35 wpt.log("onload event triggered again and again and again and again and again and again and again and again and again and again and again

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt');2var wpt = new wpt();3wpt.on_event("test",function(){4 console.log("event test fired");5});6wpt.emit("test");

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