video.core.novtt.js 855 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359
  1. /**
  2. * @license
  3. * Video.js 7.21.4 <http://videojs.com/>
  4. * Copyright Brightcove, Inc. <https://www.brightcove.com/>
  5. * Available under Apache License Version 2.0
  6. * <https://github.com/videojs/video.js/blob/main/LICENSE>
  7. *
  8. * Includes vtt.js <https://github.com/mozilla/vtt.js>
  9. * Available under Apache License Version 2.0
  10. * <https://github.com/mozilla/vtt.js/blob/main/LICENSE>
  11. */
  12. (function (global, factory) {
  13. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  14. typeof define === 'function' && define.amd ? define(factory) :
  15. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.videojs = factory());
  16. }(this, (function () { 'use strict';
  17. var version = "7.21.4";
  18. /**
  19. * An Object that contains lifecycle hooks as keys which point to an array
  20. * of functions that are run when a lifecycle is triggered
  21. *
  22. * @private
  23. */
  24. var hooks_ = {};
  25. /**
  26. * Get a list of hooks for a specific lifecycle
  27. *
  28. * @param {string} type
  29. * the lifecyle to get hooks from
  30. *
  31. * @param {Function|Function[]} [fn]
  32. * Optionally add a hook (or hooks) to the lifecycle that your are getting.
  33. *
  34. * @return {Array}
  35. * an array of hooks, or an empty array if there are none.
  36. */
  37. var hooks = function hooks(type, fn) {
  38. hooks_[type] = hooks_[type] || [];
  39. if (fn) {
  40. hooks_[type] = hooks_[type].concat(fn);
  41. }
  42. return hooks_[type];
  43. };
  44. /**
  45. * Add a function hook to a specific videojs lifecycle.
  46. *
  47. * @param {string} type
  48. * the lifecycle to hook the function to.
  49. *
  50. * @param {Function|Function[]}
  51. * The function or array of functions to attach.
  52. */
  53. var hook = function hook(type, fn) {
  54. hooks(type, fn);
  55. };
  56. /**
  57. * Remove a hook from a specific videojs lifecycle.
  58. *
  59. * @param {string} type
  60. * the lifecycle that the function hooked to
  61. *
  62. * @param {Function} fn
  63. * The hooked function to remove
  64. *
  65. * @return {boolean}
  66. * The function that was removed or undef
  67. */
  68. var removeHook = function removeHook(type, fn) {
  69. var index = hooks(type).indexOf(fn);
  70. if (index <= -1) {
  71. return false;
  72. }
  73. hooks_[type] = hooks_[type].slice();
  74. hooks_[type].splice(index, 1);
  75. return true;
  76. };
  77. /**
  78. * Add a function hook that will only run once to a specific videojs lifecycle.
  79. *
  80. * @param {string} type
  81. * the lifecycle to hook the function to.
  82. *
  83. * @param {Function|Function[]}
  84. * The function or array of functions to attach.
  85. */
  86. var hookOnce = function hookOnce(type, fn) {
  87. hooks(type, [].concat(fn).map(function (original) {
  88. var wrapper = function wrapper() {
  89. removeHook(type, wrapper);
  90. return original.apply(void 0, arguments);
  91. };
  92. return wrapper;
  93. }));
  94. };
  95. /**
  96. * @file fullscreen-api.js
  97. * @module fullscreen-api
  98. * @private
  99. */
  100. /**
  101. * Store the browser-specific methods for the fullscreen API.
  102. *
  103. * @type {Object}
  104. * @see [Specification]{@link https://fullscreen.spec.whatwg.org}
  105. * @see [Map Approach From Screenfull.js]{@link https://github.com/sindresorhus/screenfull.js}
  106. */
  107. var FullscreenApi = {
  108. prefixed: true
  109. }; // browser API methods
  110. var apiMap = [['requestFullscreen', 'exitFullscreen', 'fullscreenElement', 'fullscreenEnabled', 'fullscreenchange', 'fullscreenerror', 'fullscreen'], // WebKit
  111. ['webkitRequestFullscreen', 'webkitExitFullscreen', 'webkitFullscreenElement', 'webkitFullscreenEnabled', 'webkitfullscreenchange', 'webkitfullscreenerror', '-webkit-full-screen'], // Mozilla
  112. ['mozRequestFullScreen', 'mozCancelFullScreen', 'mozFullScreenElement', 'mozFullScreenEnabled', 'mozfullscreenchange', 'mozfullscreenerror', '-moz-full-screen'], // Microsoft
  113. ['msRequestFullscreen', 'msExitFullscreen', 'msFullscreenElement', 'msFullscreenEnabled', 'MSFullscreenChange', 'MSFullscreenError', '-ms-fullscreen']];
  114. var specApi = apiMap[0];
  115. var browserApi; // determine the supported set of functions
  116. for (var i = 0; i < apiMap.length; i++) {
  117. // check for exitFullscreen function
  118. if (apiMap[i][1] in document) {
  119. browserApi = apiMap[i];
  120. break;
  121. }
  122. } // map the browser API names to the spec API names
  123. if (browserApi) {
  124. for (var _i = 0; _i < browserApi.length; _i++) {
  125. FullscreenApi[specApi[_i]] = browserApi[_i];
  126. }
  127. FullscreenApi.prefixed = browserApi[0] !== specApi[0];
  128. }
  129. /**
  130. * @file create-logger.js
  131. * @module create-logger
  132. */
  133. // This is the private tracking variable for the logging history.
  134. var history = [];
  135. /**
  136. * Log messages to the console and history based on the type of message
  137. *
  138. * @private
  139. * @param {string} type
  140. * The name of the console method to use.
  141. *
  142. * @param {Array} args
  143. * The arguments to be passed to the matching console method.
  144. */
  145. var LogByTypeFactory = function LogByTypeFactory(name, log) {
  146. return function (type, level, args) {
  147. var lvl = log.levels[level];
  148. var lvlRegExp = new RegExp("^(" + lvl + ")$");
  149. if (type !== 'log') {
  150. // Add the type to the front of the message when it's not "log".
  151. args.unshift(type.toUpperCase() + ':');
  152. } // Add console prefix after adding to history.
  153. args.unshift(name + ':'); // Add a clone of the args at this point to history.
  154. if (history) {
  155. history.push([].concat(args)); // only store 1000 history entries
  156. var splice = history.length - 1000;
  157. history.splice(0, splice > 0 ? splice : 0);
  158. } // If there's no console then don't try to output messages, but they will
  159. // still be stored in history.
  160. if (!window.console) {
  161. return;
  162. } // Was setting these once outside of this function, but containing them
  163. // in the function makes it easier to test cases where console doesn't exist
  164. // when the module is executed.
  165. var fn = window.console[type];
  166. if (!fn && type === 'debug') {
  167. // Certain browsers don't have support for console.debug. For those, we
  168. // should default to the closest comparable log.
  169. fn = window.console.info || window.console.log;
  170. } // Bail out if there's no console or if this type is not allowed by the
  171. // current logging level.
  172. if (!fn || !lvl || !lvlRegExp.test(type)) {
  173. return;
  174. }
  175. fn[Array.isArray(args) ? 'apply' : 'call'](window.console, args);
  176. };
  177. };
  178. function createLogger$1(name) {
  179. // This is the private tracking variable for logging level.
  180. var level = 'info'; // the curried logByType bound to the specific log and history
  181. var logByType;
  182. /**
  183. * Logs plain debug messages. Similar to `console.log`.
  184. *
  185. * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149)
  186. * of our JSDoc template, we cannot properly document this as both a function
  187. * and a namespace, so its function signature is documented here.
  188. *
  189. * #### Arguments
  190. * ##### *args
  191. * Mixed[]
  192. *
  193. * Any combination of values that could be passed to `console.log()`.
  194. *
  195. * #### Return Value
  196. *
  197. * `undefined`
  198. *
  199. * @namespace
  200. * @param {Mixed[]} args
  201. * One or more messages or objects that should be logged.
  202. */
  203. var log = function log() {
  204. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  205. args[_key] = arguments[_key];
  206. }
  207. logByType('log', level, args);
  208. }; // This is the logByType helper that the logging methods below use
  209. logByType = LogByTypeFactory(name, log);
  210. /**
  211. * Create a new sublogger which chains the old name to the new name.
  212. *
  213. * For example, doing `videojs.log.createLogger('player')` and then using that logger will log the following:
  214. * ```js
  215. * mylogger('foo');
  216. * // > VIDEOJS: player: foo
  217. * ```
  218. *
  219. * @param {string} name
  220. * The name to add call the new logger
  221. * @return {Object}
  222. */
  223. log.createLogger = function (subname) {
  224. return createLogger$1(name + ': ' + subname);
  225. };
  226. /**
  227. * Enumeration of available logging levels, where the keys are the level names
  228. * and the values are `|`-separated strings containing logging methods allowed
  229. * in that logging level. These strings are used to create a regular expression
  230. * matching the function name being called.
  231. *
  232. * Levels provided by Video.js are:
  233. *
  234. * - `off`: Matches no calls. Any value that can be cast to `false` will have
  235. * this effect. The most restrictive.
  236. * - `all`: Matches only Video.js-provided functions (`debug`, `log`,
  237. * `log.warn`, and `log.error`).
  238. * - `debug`: Matches `log.debug`, `log`, `log.warn`, and `log.error` calls.
  239. * - `info` (default): Matches `log`, `log.warn`, and `log.error` calls.
  240. * - `warn`: Matches `log.warn` and `log.error` calls.
  241. * - `error`: Matches only `log.error` calls.
  242. *
  243. * @type {Object}
  244. */
  245. log.levels = {
  246. all: 'debug|log|warn|error',
  247. off: '',
  248. debug: 'debug|log|warn|error',
  249. info: 'log|warn|error',
  250. warn: 'warn|error',
  251. error: 'error',
  252. DEFAULT: level
  253. };
  254. /**
  255. * Get or set the current logging level.
  256. *
  257. * If a string matching a key from {@link module:log.levels} is provided, acts
  258. * as a setter.
  259. *
  260. * @param {string} [lvl]
  261. * Pass a valid level to set a new logging level.
  262. *
  263. * @return {string}
  264. * The current logging level.
  265. */
  266. log.level = function (lvl) {
  267. if (typeof lvl === 'string') {
  268. if (!log.levels.hasOwnProperty(lvl)) {
  269. throw new Error("\"" + lvl + "\" in not a valid log level");
  270. }
  271. level = lvl;
  272. }
  273. return level;
  274. };
  275. /**
  276. * Returns an array containing everything that has been logged to the history.
  277. *
  278. * This array is a shallow clone of the internal history record. However, its
  279. * contents are _not_ cloned; so, mutating objects inside this array will
  280. * mutate them in history.
  281. *
  282. * @return {Array}
  283. */
  284. log.history = function () {
  285. return history ? [].concat(history) : [];
  286. };
  287. /**
  288. * Allows you to filter the history by the given logger name
  289. *
  290. * @param {string} fname
  291. * The name to filter by
  292. *
  293. * @return {Array}
  294. * The filtered list to return
  295. */
  296. log.history.filter = function (fname) {
  297. return (history || []).filter(function (historyItem) {
  298. // if the first item in each historyItem includes `fname`, then it's a match
  299. return new RegExp(".*" + fname + ".*").test(historyItem[0]);
  300. });
  301. };
  302. /**
  303. * Clears the internal history tracking, but does not prevent further history
  304. * tracking.
  305. */
  306. log.history.clear = function () {
  307. if (history) {
  308. history.length = 0;
  309. }
  310. };
  311. /**
  312. * Disable history tracking if it is currently enabled.
  313. */
  314. log.history.disable = function () {
  315. if (history !== null) {
  316. history.length = 0;
  317. history = null;
  318. }
  319. };
  320. /**
  321. * Enable history tracking if it is currently disabled.
  322. */
  323. log.history.enable = function () {
  324. if (history === null) {
  325. history = [];
  326. }
  327. };
  328. /**
  329. * Logs error messages. Similar to `console.error`.
  330. *
  331. * @param {Mixed[]} args
  332. * One or more messages or objects that should be logged as an error
  333. */
  334. log.error = function () {
  335. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  336. args[_key2] = arguments[_key2];
  337. }
  338. return logByType('error', level, args);
  339. };
  340. /**
  341. * Logs warning messages. Similar to `console.warn`.
  342. *
  343. * @param {Mixed[]} args
  344. * One or more messages or objects that should be logged as a warning.
  345. */
  346. log.warn = function () {
  347. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  348. args[_key3] = arguments[_key3];
  349. }
  350. return logByType('warn', level, args);
  351. };
  352. /**
  353. * Logs debug messages. Similar to `console.debug`, but may also act as a comparable
  354. * log if `console.debug` is not available
  355. *
  356. * @param {Mixed[]} args
  357. * One or more messages or objects that should be logged as debug.
  358. */
  359. log.debug = function () {
  360. for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  361. args[_key4] = arguments[_key4];
  362. }
  363. return logByType('debug', level, args);
  364. };
  365. return log;
  366. }
  367. /**
  368. * @file log.js
  369. * @module log
  370. */
  371. var log = createLogger$1('VIDEOJS');
  372. var createLogger = log.createLogger;
  373. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  374. function createCommonjsModule(fn, module) {
  375. return module = { exports: {} }, fn(module, module.exports), module.exports;
  376. }
  377. var _extends_1 = createCommonjsModule(function (module) {
  378. function _extends() {
  379. module.exports = _extends = Object.assign || function (target) {
  380. for (var i = 1; i < arguments.length; i++) {
  381. var source = arguments[i];
  382. for (var key in source) {
  383. if (Object.prototype.hasOwnProperty.call(source, key)) {
  384. target[key] = source[key];
  385. }
  386. }
  387. }
  388. return target;
  389. };
  390. return _extends.apply(this, arguments);
  391. }
  392. module.exports = _extends;
  393. });
  394. /**
  395. * @file obj.js
  396. * @module obj
  397. */
  398. /**
  399. * @callback obj:EachCallback
  400. *
  401. * @param {Mixed} value
  402. * The current key for the object that is being iterated over.
  403. *
  404. * @param {string} key
  405. * The current key-value for object that is being iterated over
  406. */
  407. /**
  408. * @callback obj:ReduceCallback
  409. *
  410. * @param {Mixed} accum
  411. * The value that is accumulating over the reduce loop.
  412. *
  413. * @param {Mixed} value
  414. * The current key for the object that is being iterated over.
  415. *
  416. * @param {string} key
  417. * The current key-value for object that is being iterated over
  418. *
  419. * @return {Mixed}
  420. * The new accumulated value.
  421. */
  422. var toString$1 = Object.prototype.toString;
  423. /**
  424. * Get the keys of an Object
  425. *
  426. * @param {Object}
  427. * The Object to get the keys from
  428. *
  429. * @return {string[]}
  430. * An array of the keys from the object. Returns an empty array if the
  431. * object passed in was invalid or had no keys.
  432. *
  433. * @private
  434. */
  435. var keys = function keys(object) {
  436. return isObject(object) ? Object.keys(object) : [];
  437. };
  438. /**
  439. * Array-like iteration for objects.
  440. *
  441. * @param {Object} object
  442. * The object to iterate over
  443. *
  444. * @param {obj:EachCallback} fn
  445. * The callback function which is called for each key in the object.
  446. */
  447. function each(object, fn) {
  448. keys(object).forEach(function (key) {
  449. return fn(object[key], key);
  450. });
  451. }
  452. /**
  453. * Array-like reduce for objects.
  454. *
  455. * @param {Object} object
  456. * The Object that you want to reduce.
  457. *
  458. * @param {Function} fn
  459. * A callback function which is called for each key in the object. It
  460. * receives the accumulated value and the per-iteration value and key
  461. * as arguments.
  462. *
  463. * @param {Mixed} [initial = 0]
  464. * Starting value
  465. *
  466. * @return {Mixed}
  467. * The final accumulated value.
  468. */
  469. function reduce(object, fn, initial) {
  470. if (initial === void 0) {
  471. initial = 0;
  472. }
  473. return keys(object).reduce(function (accum, key) {
  474. return fn(accum, object[key], key);
  475. }, initial);
  476. }
  477. /**
  478. * Object.assign-style object shallow merge/extend.
  479. *
  480. * @param {Object} target
  481. * @param {Object} ...sources
  482. * @return {Object}
  483. */
  484. function assign(target) {
  485. for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  486. sources[_key - 1] = arguments[_key];
  487. }
  488. if (Object.assign) {
  489. return _extends_1.apply(void 0, [target].concat(sources));
  490. }
  491. sources.forEach(function (source) {
  492. if (!source) {
  493. return;
  494. }
  495. each(source, function (value, key) {
  496. target[key] = value;
  497. });
  498. });
  499. return target;
  500. }
  501. /**
  502. * Returns whether a value is an object of any kind - including DOM nodes,
  503. * arrays, regular expressions, etc. Not functions, though.
  504. *
  505. * This avoids the gotcha where using `typeof` on a `null` value
  506. * results in `'object'`.
  507. *
  508. * @param {Object} value
  509. * @return {boolean}
  510. */
  511. function isObject(value) {
  512. return !!value && typeof value === 'object';
  513. }
  514. /**
  515. * Returns whether an object appears to be a "plain" object - that is, a
  516. * direct instance of `Object`.
  517. *
  518. * @param {Object} value
  519. * @return {boolean}
  520. */
  521. function isPlain(value) {
  522. return isObject(value) && toString$1.call(value) === '[object Object]' && value.constructor === Object;
  523. }
  524. /**
  525. * @file computed-style.js
  526. * @module computed-style
  527. */
  528. /**
  529. * A safe getComputedStyle.
  530. *
  531. * This is needed because in Firefox, if the player is loaded in an iframe with
  532. * `display:none`, then `getComputedStyle` returns `null`, so, we do a
  533. * null-check to make sure that the player doesn't break in these cases.
  534. *
  535. * @function
  536. * @param {Element} el
  537. * The element you want the computed style of
  538. *
  539. * @param {string} prop
  540. * The property name you want
  541. *
  542. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=548397
  543. */
  544. function computedStyle(el, prop) {
  545. if (!el || !prop) {
  546. return '';
  547. }
  548. if (typeof window.getComputedStyle === 'function') {
  549. var computedStyleValue;
  550. try {
  551. computedStyleValue = window.getComputedStyle(el);
  552. } catch (e) {
  553. return '';
  554. }
  555. return computedStyleValue ? computedStyleValue.getPropertyValue(prop) || computedStyleValue[prop] : '';
  556. }
  557. return '';
  558. }
  559. /**
  560. * @file browser.js
  561. * @module browser
  562. */
  563. var USER_AGENT = window.navigator && window.navigator.userAgent || '';
  564. var webkitVersionMap = /AppleWebKit\/([\d.]+)/i.exec(USER_AGENT);
  565. var appleWebkitVersion = webkitVersionMap ? parseFloat(webkitVersionMap.pop()) : null;
  566. /**
  567. * Whether or not this device is an iPod.
  568. *
  569. * @static
  570. * @const
  571. * @type {Boolean}
  572. */
  573. var IS_IPOD = /iPod/i.test(USER_AGENT);
  574. /**
  575. * The detected iOS version - or `null`.
  576. *
  577. * @static
  578. * @const
  579. * @type {string|null}
  580. */
  581. var IOS_VERSION = function () {
  582. var match = USER_AGENT.match(/OS (\d+)_/i);
  583. if (match && match[1]) {
  584. return match[1];
  585. }
  586. return null;
  587. }();
  588. /**
  589. * Whether or not this is an Android device.
  590. *
  591. * @static
  592. * @const
  593. * @type {Boolean}
  594. */
  595. var IS_ANDROID = /Android/i.test(USER_AGENT);
  596. /**
  597. * The detected Android version - or `null`.
  598. *
  599. * @static
  600. * @const
  601. * @type {number|string|null}
  602. */
  603. var ANDROID_VERSION = function () {
  604. // This matches Android Major.Minor.Patch versions
  605. // ANDROID_VERSION is Major.Minor as a Number, if Minor isn't available, then only Major is returned
  606. var match = USER_AGENT.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);
  607. if (!match) {
  608. return null;
  609. }
  610. var major = match[1] && parseFloat(match[1]);
  611. var minor = match[2] && parseFloat(match[2]);
  612. if (major && minor) {
  613. return parseFloat(match[1] + '.' + match[2]);
  614. } else if (major) {
  615. return major;
  616. }
  617. return null;
  618. }();
  619. /**
  620. * Whether or not this is a native Android browser.
  621. *
  622. * @static
  623. * @const
  624. * @type {Boolean}
  625. */
  626. var IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537;
  627. /**
  628. * Whether or not this is Mozilla Firefox.
  629. *
  630. * @static
  631. * @const
  632. * @type {Boolean}
  633. */
  634. var IS_FIREFOX = /Firefox/i.test(USER_AGENT);
  635. /**
  636. * Whether or not this is Microsoft Edge.
  637. *
  638. * @static
  639. * @const
  640. * @type {Boolean}
  641. */
  642. var IS_EDGE = /Edg/i.test(USER_AGENT);
  643. /**
  644. * Whether or not this is Google Chrome.
  645. *
  646. * This will also be `true` for Chrome on iOS, which will have different support
  647. * as it is actually Safari under the hood.
  648. *
  649. * @static
  650. * @const
  651. * @type {Boolean}
  652. */
  653. var IS_CHROME = !IS_EDGE && (/Chrome/i.test(USER_AGENT) || /CriOS/i.test(USER_AGENT));
  654. /**
  655. * The detected Google Chrome version - or `null`.
  656. *
  657. * @static
  658. * @const
  659. * @type {number|null}
  660. */
  661. var CHROME_VERSION = function () {
  662. var match = USER_AGENT.match(/(Chrome|CriOS)\/(\d+)/);
  663. if (match && match[2]) {
  664. return parseFloat(match[2]);
  665. }
  666. return null;
  667. }();
  668. /**
  669. * The detected Internet Explorer version - or `null`.
  670. *
  671. * @static
  672. * @const
  673. * @type {number|null}
  674. */
  675. var IE_VERSION = function () {
  676. var result = /MSIE\s(\d+)\.\d/.exec(USER_AGENT);
  677. var version = result && parseFloat(result[1]);
  678. if (!version && /Trident\/7.0/i.test(USER_AGENT) && /rv:11.0/.test(USER_AGENT)) {
  679. // IE 11 has a different user agent string than other IE versions
  680. version = 11.0;
  681. }
  682. return version;
  683. }();
  684. /**
  685. * Whether or not this is desktop Safari.
  686. *
  687. * @static
  688. * @const
  689. * @type {Boolean}
  690. */
  691. var IS_SAFARI = /Safari/i.test(USER_AGENT) && !IS_CHROME && !IS_ANDROID && !IS_EDGE;
  692. /**
  693. * Whether or not this is a Windows machine.
  694. *
  695. * @static
  696. * @const
  697. * @type {Boolean}
  698. */
  699. var IS_WINDOWS = /Windows/i.test(USER_AGENT);
  700. /**
  701. * Whether or not this device is touch-enabled.
  702. *
  703. * @static
  704. * @const
  705. * @type {Boolean}
  706. */
  707. var TOUCH_ENABLED = Boolean(isReal() && ('ontouchstart' in window || window.navigator.maxTouchPoints || window.DocumentTouch && window.document instanceof window.DocumentTouch));
  708. /**
  709. * Whether or not this device is an iPad.
  710. *
  711. * @static
  712. * @const
  713. * @type {Boolean}
  714. */
  715. var IS_IPAD = /iPad/i.test(USER_AGENT) || IS_SAFARI && TOUCH_ENABLED && !/iPhone/i.test(USER_AGENT);
  716. /**
  717. * Whether or not this device is an iPhone.
  718. *
  719. * @static
  720. * @const
  721. * @type {Boolean}
  722. */
  723. // The Facebook app's UIWebView identifies as both an iPhone and iPad, so
  724. // to identify iPhones, we need to exclude iPads.
  725. // http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/
  726. var IS_IPHONE = /iPhone/i.test(USER_AGENT) && !IS_IPAD;
  727. /**
  728. * Whether or not this is an iOS device.
  729. *
  730. * @static
  731. * @const
  732. * @type {Boolean}
  733. */
  734. var IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD;
  735. /**
  736. * Whether or not this is any flavor of Safari - including iOS.
  737. *
  738. * @static
  739. * @const
  740. * @type {Boolean}
  741. */
  742. var IS_ANY_SAFARI = (IS_SAFARI || IS_IOS) && !IS_CHROME;
  743. var browser = /*#__PURE__*/Object.freeze({
  744. __proto__: null,
  745. IS_IPOD: IS_IPOD,
  746. IOS_VERSION: IOS_VERSION,
  747. IS_ANDROID: IS_ANDROID,
  748. ANDROID_VERSION: ANDROID_VERSION,
  749. IS_NATIVE_ANDROID: IS_NATIVE_ANDROID,
  750. IS_FIREFOX: IS_FIREFOX,
  751. IS_EDGE: IS_EDGE,
  752. IS_CHROME: IS_CHROME,
  753. CHROME_VERSION: CHROME_VERSION,
  754. IE_VERSION: IE_VERSION,
  755. IS_SAFARI: IS_SAFARI,
  756. IS_WINDOWS: IS_WINDOWS,
  757. TOUCH_ENABLED: TOUCH_ENABLED,
  758. IS_IPAD: IS_IPAD,
  759. IS_IPHONE: IS_IPHONE,
  760. IS_IOS: IS_IOS,
  761. IS_ANY_SAFARI: IS_ANY_SAFARI
  762. });
  763. /**
  764. * @file dom.js
  765. * @module dom
  766. */
  767. /**
  768. * Detect if a value is a string with any non-whitespace characters.
  769. *
  770. * @private
  771. * @param {string} str
  772. * The string to check
  773. *
  774. * @return {boolean}
  775. * Will be `true` if the string is non-blank, `false` otherwise.
  776. *
  777. */
  778. function isNonBlankString(str) {
  779. // we use str.trim as it will trim any whitespace characters
  780. // from the front or back of non-whitespace characters. aka
  781. // Any string that contains non-whitespace characters will
  782. // still contain them after `trim` but whitespace only strings
  783. // will have a length of 0, failing this check.
  784. return typeof str === 'string' && Boolean(str.trim());
  785. }
  786. /**
  787. * Throws an error if the passed string has whitespace. This is used by
  788. * class methods to be relatively consistent with the classList API.
  789. *
  790. * @private
  791. * @param {string} str
  792. * The string to check for whitespace.
  793. *
  794. * @throws {Error}
  795. * Throws an error if there is whitespace in the string.
  796. */
  797. function throwIfWhitespace(str) {
  798. // str.indexOf instead of regex because str.indexOf is faster performance wise.
  799. if (str.indexOf(' ') >= 0) {
  800. throw new Error('class has illegal whitespace characters');
  801. }
  802. }
  803. /**
  804. * Produce a regular expression for matching a className within an elements className.
  805. *
  806. * @private
  807. * @param {string} className
  808. * The className to generate the RegExp for.
  809. *
  810. * @return {RegExp}
  811. * The RegExp that will check for a specific `className` in an elements
  812. * className.
  813. */
  814. function classRegExp(className) {
  815. return new RegExp('(^|\\s)' + className + '($|\\s)');
  816. }
  817. /**
  818. * Whether the current DOM interface appears to be real (i.e. not simulated).
  819. *
  820. * @return {boolean}
  821. * Will be `true` if the DOM appears to be real, `false` otherwise.
  822. */
  823. function isReal() {
  824. // Both document and window will never be undefined thanks to `global`.
  825. return document === window.document;
  826. }
  827. /**
  828. * Determines, via duck typing, whether or not a value is a DOM element.
  829. *
  830. * @param {Mixed} value
  831. * The value to check.
  832. *
  833. * @return {boolean}
  834. * Will be `true` if the value is a DOM element, `false` otherwise.
  835. */
  836. function isEl(value) {
  837. return isObject(value) && value.nodeType === 1;
  838. }
  839. /**
  840. * Determines if the current DOM is embedded in an iframe.
  841. *
  842. * @return {boolean}
  843. * Will be `true` if the DOM is embedded in an iframe, `false`
  844. * otherwise.
  845. */
  846. function isInFrame() {
  847. // We need a try/catch here because Safari will throw errors when attempting
  848. // to get either `parent` or `self`
  849. try {
  850. return window.parent !== window.self;
  851. } catch (x) {
  852. return true;
  853. }
  854. }
  855. /**
  856. * Creates functions to query the DOM using a given method.
  857. *
  858. * @private
  859. * @param {string} method
  860. * The method to create the query with.
  861. *
  862. * @return {Function}
  863. * The query method
  864. */
  865. function createQuerier(method) {
  866. return function (selector, context) {
  867. if (!isNonBlankString(selector)) {
  868. return document[method](null);
  869. }
  870. if (isNonBlankString(context)) {
  871. context = document.querySelector(context);
  872. }
  873. var ctx = isEl(context) ? context : document;
  874. return ctx[method] && ctx[method](selector);
  875. };
  876. }
  877. /**
  878. * Creates an element and applies properties, attributes, and inserts content.
  879. *
  880. * @param {string} [tagName='div']
  881. * Name of tag to be created.
  882. *
  883. * @param {Object} [properties={}]
  884. * Element properties to be applied.
  885. *
  886. * @param {Object} [attributes={}]
  887. * Element attributes to be applied.
  888. *
  889. * @param {module:dom~ContentDescriptor} content
  890. * A content descriptor object.
  891. *
  892. * @return {Element}
  893. * The element that was created.
  894. */
  895. function createEl(tagName, properties, attributes, content) {
  896. if (tagName === void 0) {
  897. tagName = 'div';
  898. }
  899. if (properties === void 0) {
  900. properties = {};
  901. }
  902. if (attributes === void 0) {
  903. attributes = {};
  904. }
  905. var el = document.createElement(tagName);
  906. Object.getOwnPropertyNames(properties).forEach(function (propName) {
  907. var val = properties[propName]; // See #2176
  908. // We originally were accepting both properties and attributes in the
  909. // same object, but that doesn't work so well.
  910. if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') {
  911. log.warn('Setting attributes in the second argument of createEl()\n' + 'has been deprecated. Use the third argument instead.\n' + ("createEl(type, properties, attributes). Attempting to set " + propName + " to " + val + "."));
  912. el.setAttribute(propName, val); // Handle textContent since it's not supported everywhere and we have a
  913. // method for it.
  914. } else if (propName === 'textContent') {
  915. textContent(el, val);
  916. } else if (el[propName] !== val || propName === 'tabIndex') {
  917. el[propName] = val;
  918. }
  919. });
  920. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  921. el.setAttribute(attrName, attributes[attrName]);
  922. });
  923. if (content) {
  924. appendContent(el, content);
  925. }
  926. return el;
  927. }
  928. /**
  929. * Injects text into an element, replacing any existing contents entirely.
  930. *
  931. * @param {Element} el
  932. * The element to add text content into
  933. *
  934. * @param {string} text
  935. * The text content to add.
  936. *
  937. * @return {Element}
  938. * The element with added text content.
  939. */
  940. function textContent(el, text) {
  941. if (typeof el.textContent === 'undefined') {
  942. el.innerText = text;
  943. } else {
  944. el.textContent = text;
  945. }
  946. return el;
  947. }
  948. /**
  949. * Insert an element as the first child node of another
  950. *
  951. * @param {Element} child
  952. * Element to insert
  953. *
  954. * @param {Element} parent
  955. * Element to insert child into
  956. */
  957. function prependTo(child, parent) {
  958. if (parent.firstChild) {
  959. parent.insertBefore(child, parent.firstChild);
  960. } else {
  961. parent.appendChild(child);
  962. }
  963. }
  964. /**
  965. * Check if an element has a class name.
  966. *
  967. * @param {Element} element
  968. * Element to check
  969. *
  970. * @param {string} classToCheck
  971. * Class name to check for
  972. *
  973. * @return {boolean}
  974. * Will be `true` if the element has a class, `false` otherwise.
  975. *
  976. * @throws {Error}
  977. * Throws an error if `classToCheck` has white space.
  978. */
  979. function hasClass(element, classToCheck) {
  980. throwIfWhitespace(classToCheck);
  981. if (element.classList) {
  982. return element.classList.contains(classToCheck);
  983. }
  984. return classRegExp(classToCheck).test(element.className);
  985. }
  986. /**
  987. * Add a class name to an element.
  988. *
  989. * @param {Element} element
  990. * Element to add class name to.
  991. *
  992. * @param {string} classToAdd
  993. * Class name to add.
  994. *
  995. * @return {Element}
  996. * The DOM element with the added class name.
  997. */
  998. function addClass(element, classToAdd) {
  999. if (element.classList) {
  1000. element.classList.add(classToAdd); // Don't need to `throwIfWhitespace` here because `hasElClass` will do it
  1001. // in the case of classList not being supported.
  1002. } else if (!hasClass(element, classToAdd)) {
  1003. element.className = (element.className + ' ' + classToAdd).trim();
  1004. }
  1005. return element;
  1006. }
  1007. /**
  1008. * Remove a class name from an element.
  1009. *
  1010. * @param {Element} element
  1011. * Element to remove a class name from.
  1012. *
  1013. * @param {string} classToRemove
  1014. * Class name to remove
  1015. *
  1016. * @return {Element}
  1017. * The DOM element with class name removed.
  1018. */
  1019. function removeClass(element, classToRemove) {
  1020. // Protect in case the player gets disposed
  1021. if (!element) {
  1022. log.warn("removeClass was called with an element that doesn't exist");
  1023. return null;
  1024. }
  1025. if (element.classList) {
  1026. element.classList.remove(classToRemove);
  1027. } else {
  1028. throwIfWhitespace(classToRemove);
  1029. element.className = element.className.split(/\s+/).filter(function (c) {
  1030. return c !== classToRemove;
  1031. }).join(' ');
  1032. }
  1033. return element;
  1034. }
  1035. /**
  1036. * The callback definition for toggleClass.
  1037. *
  1038. * @callback module:dom~PredicateCallback
  1039. * @param {Element} element
  1040. * The DOM element of the Component.
  1041. *
  1042. * @param {string} classToToggle
  1043. * The `className` that wants to be toggled
  1044. *
  1045. * @return {boolean|undefined}
  1046. * If `true` is returned, the `classToToggle` will be added to the
  1047. * `element`. If `false`, the `classToToggle` will be removed from
  1048. * the `element`. If `undefined`, the callback will be ignored.
  1049. */
  1050. /**
  1051. * Adds or removes a class name to/from an element depending on an optional
  1052. * condition or the presence/absence of the class name.
  1053. *
  1054. * @param {Element} element
  1055. * The element to toggle a class name on.
  1056. *
  1057. * @param {string} classToToggle
  1058. * The class that should be toggled.
  1059. *
  1060. * @param {boolean|module:dom~PredicateCallback} [predicate]
  1061. * See the return value for {@link module:dom~PredicateCallback}
  1062. *
  1063. * @return {Element}
  1064. * The element with a class that has been toggled.
  1065. */
  1066. function toggleClass(element, classToToggle, predicate) {
  1067. // This CANNOT use `classList` internally because IE11 does not support the
  1068. // second parameter to the `classList.toggle()` method! Which is fine because
  1069. // `classList` will be used by the add/remove functions.
  1070. var has = hasClass(element, classToToggle);
  1071. if (typeof predicate === 'function') {
  1072. predicate = predicate(element, classToToggle);
  1073. }
  1074. if (typeof predicate !== 'boolean') {
  1075. predicate = !has;
  1076. } // If the necessary class operation matches the current state of the
  1077. // element, no action is required.
  1078. if (predicate === has) {
  1079. return;
  1080. }
  1081. if (predicate) {
  1082. addClass(element, classToToggle);
  1083. } else {
  1084. removeClass(element, classToToggle);
  1085. }
  1086. return element;
  1087. }
  1088. /**
  1089. * Apply attributes to an HTML element.
  1090. *
  1091. * @param {Element} el
  1092. * Element to add attributes to.
  1093. *
  1094. * @param {Object} [attributes]
  1095. * Attributes to be applied.
  1096. */
  1097. function setAttributes(el, attributes) {
  1098. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  1099. var attrValue = attributes[attrName];
  1100. if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) {
  1101. el.removeAttribute(attrName);
  1102. } else {
  1103. el.setAttribute(attrName, attrValue === true ? '' : attrValue);
  1104. }
  1105. });
  1106. }
  1107. /**
  1108. * Get an element's attribute values, as defined on the HTML tag.
  1109. *
  1110. * Attributes are not the same as properties. They're defined on the tag
  1111. * or with setAttribute.
  1112. *
  1113. * @param {Element} tag
  1114. * Element from which to get tag attributes.
  1115. *
  1116. * @return {Object}
  1117. * All attributes of the element. Boolean attributes will be `true` or
  1118. * `false`, others will be strings.
  1119. */
  1120. function getAttributes(tag) {
  1121. var obj = {}; // known boolean attributes
  1122. // we can check for matching boolean properties, but not all browsers
  1123. // and not all tags know about these attributes, so, we still want to check them manually
  1124. var knownBooleans = ',' + 'autoplay,controls,playsinline,loop,muted,default,defaultMuted' + ',';
  1125. if (tag && tag.attributes && tag.attributes.length > 0) {
  1126. var attrs = tag.attributes;
  1127. for (var i = attrs.length - 1; i >= 0; i--) {
  1128. var attrName = attrs[i].name;
  1129. var attrVal = attrs[i].value; // check for known booleans
  1130. // the matching element property will return a value for typeof
  1131. if (typeof tag[attrName] === 'boolean' || knownBooleans.indexOf(',' + attrName + ',') !== -1) {
  1132. // the value of an included boolean attribute is typically an empty
  1133. // string ('') which would equal false if we just check for a false value.
  1134. // we also don't want support bad code like autoplay='false'
  1135. attrVal = attrVal !== null ? true : false;
  1136. }
  1137. obj[attrName] = attrVal;
  1138. }
  1139. }
  1140. return obj;
  1141. }
  1142. /**
  1143. * Get the value of an element's attribute.
  1144. *
  1145. * @param {Element} el
  1146. * A DOM element.
  1147. *
  1148. * @param {string} attribute
  1149. * Attribute to get the value of.
  1150. *
  1151. * @return {string}
  1152. * The value of the attribute.
  1153. */
  1154. function getAttribute(el, attribute) {
  1155. return el.getAttribute(attribute);
  1156. }
  1157. /**
  1158. * Set the value of an element's attribute.
  1159. *
  1160. * @param {Element} el
  1161. * A DOM element.
  1162. *
  1163. * @param {string} attribute
  1164. * Attribute to set.
  1165. *
  1166. * @param {string} value
  1167. * Value to set the attribute to.
  1168. */
  1169. function setAttribute(el, attribute, value) {
  1170. el.setAttribute(attribute, value);
  1171. }
  1172. /**
  1173. * Remove an element's attribute.
  1174. *
  1175. * @param {Element} el
  1176. * A DOM element.
  1177. *
  1178. * @param {string} attribute
  1179. * Attribute to remove.
  1180. */
  1181. function removeAttribute(el, attribute) {
  1182. el.removeAttribute(attribute);
  1183. }
  1184. /**
  1185. * Attempt to block the ability to select text.
  1186. */
  1187. function blockTextSelection() {
  1188. document.body.focus();
  1189. document.onselectstart = function () {
  1190. return false;
  1191. };
  1192. }
  1193. /**
  1194. * Turn off text selection blocking.
  1195. */
  1196. function unblockTextSelection() {
  1197. document.onselectstart = function () {
  1198. return true;
  1199. };
  1200. }
  1201. /**
  1202. * Identical to the native `getBoundingClientRect` function, but ensures that
  1203. * the method is supported at all (it is in all browsers we claim to support)
  1204. * and that the element is in the DOM before continuing.
  1205. *
  1206. * This wrapper function also shims properties which are not provided by some
  1207. * older browsers (namely, IE8).
  1208. *
  1209. * Additionally, some browsers do not support adding properties to a
  1210. * `ClientRect`/`DOMRect` object; so, we shallow-copy it with the standard
  1211. * properties (except `x` and `y` which are not widely supported). This helps
  1212. * avoid implementations where keys are non-enumerable.
  1213. *
  1214. * @param {Element} el
  1215. * Element whose `ClientRect` we want to calculate.
  1216. *
  1217. * @return {Object|undefined}
  1218. * Always returns a plain object - or `undefined` if it cannot.
  1219. */
  1220. function getBoundingClientRect(el) {
  1221. if (el && el.getBoundingClientRect && el.parentNode) {
  1222. var rect = el.getBoundingClientRect();
  1223. var result = {};
  1224. ['bottom', 'height', 'left', 'right', 'top', 'width'].forEach(function (k) {
  1225. if (rect[k] !== undefined) {
  1226. result[k] = rect[k];
  1227. }
  1228. });
  1229. if (!result.height) {
  1230. result.height = parseFloat(computedStyle(el, 'height'));
  1231. }
  1232. if (!result.width) {
  1233. result.width = parseFloat(computedStyle(el, 'width'));
  1234. }
  1235. return result;
  1236. }
  1237. }
  1238. /**
  1239. * Represents the position of a DOM element on the page.
  1240. *
  1241. * @typedef {Object} module:dom~Position
  1242. *
  1243. * @property {number} left
  1244. * Pixels to the left.
  1245. *
  1246. * @property {number} top
  1247. * Pixels from the top.
  1248. */
  1249. /**
  1250. * Get the position of an element in the DOM.
  1251. *
  1252. * Uses `getBoundingClientRect` technique from John Resig.
  1253. *
  1254. * @see http://ejohn.org/blog/getboundingclientrect-is-awesome/
  1255. *
  1256. * @param {Element} el
  1257. * Element from which to get offset.
  1258. *
  1259. * @return {module:dom~Position}
  1260. * The position of the element that was passed in.
  1261. */
  1262. function findPosition(el) {
  1263. if (!el || el && !el.offsetParent) {
  1264. return {
  1265. left: 0,
  1266. top: 0,
  1267. width: 0,
  1268. height: 0
  1269. };
  1270. }
  1271. var width = el.offsetWidth;
  1272. var height = el.offsetHeight;
  1273. var left = 0;
  1274. var top = 0;
  1275. while (el.offsetParent && el !== document[FullscreenApi.fullscreenElement]) {
  1276. left += el.offsetLeft;
  1277. top += el.offsetTop;
  1278. el = el.offsetParent;
  1279. }
  1280. return {
  1281. left: left,
  1282. top: top,
  1283. width: width,
  1284. height: height
  1285. };
  1286. }
  1287. /**
  1288. * Represents x and y coordinates for a DOM element or mouse pointer.
  1289. *
  1290. * @typedef {Object} module:dom~Coordinates
  1291. *
  1292. * @property {number} x
  1293. * x coordinate in pixels
  1294. *
  1295. * @property {number} y
  1296. * y coordinate in pixels
  1297. */
  1298. /**
  1299. * Get the pointer position within an element.
  1300. *
  1301. * The base on the coordinates are the bottom left of the element.
  1302. *
  1303. * @param {Element} el
  1304. * Element on which to get the pointer position on.
  1305. *
  1306. * @param {EventTarget~Event} event
  1307. * Event object.
  1308. *
  1309. * @return {module:dom~Coordinates}
  1310. * A coordinates object corresponding to the mouse position.
  1311. *
  1312. */
  1313. function getPointerPosition(el, event) {
  1314. var translated = {
  1315. x: 0,
  1316. y: 0
  1317. };
  1318. if (IS_IOS) {
  1319. var item = el;
  1320. while (item && item.nodeName.toLowerCase() !== 'html') {
  1321. var transform = computedStyle(item, 'transform');
  1322. if (/^matrix/.test(transform)) {
  1323. var values = transform.slice(7, -1).split(/,\s/).map(Number);
  1324. translated.x += values[4];
  1325. translated.y += values[5];
  1326. } else if (/^matrix3d/.test(transform)) {
  1327. var _values = transform.slice(9, -1).split(/,\s/).map(Number);
  1328. translated.x += _values[12];
  1329. translated.y += _values[13];
  1330. }
  1331. item = item.parentNode;
  1332. }
  1333. }
  1334. var position = {};
  1335. var boxTarget = findPosition(event.target);
  1336. var box = findPosition(el);
  1337. var boxW = box.width;
  1338. var boxH = box.height;
  1339. var offsetY = event.offsetY - (box.top - boxTarget.top);
  1340. var offsetX = event.offsetX - (box.left - boxTarget.left);
  1341. if (event.changedTouches) {
  1342. offsetX = event.changedTouches[0].pageX - box.left;
  1343. offsetY = event.changedTouches[0].pageY + box.top;
  1344. if (IS_IOS) {
  1345. offsetX -= translated.x;
  1346. offsetY -= translated.y;
  1347. }
  1348. }
  1349. position.y = 1 - Math.max(0, Math.min(1, offsetY / boxH));
  1350. position.x = Math.max(0, Math.min(1, offsetX / boxW));
  1351. return position;
  1352. }
  1353. /**
  1354. * Determines, via duck typing, whether or not a value is a text node.
  1355. *
  1356. * @param {Mixed} value
  1357. * Check if this value is a text node.
  1358. *
  1359. * @return {boolean}
  1360. * Will be `true` if the value is a text node, `false` otherwise.
  1361. */
  1362. function isTextNode(value) {
  1363. return isObject(value) && value.nodeType === 3;
  1364. }
  1365. /**
  1366. * Empties the contents of an element.
  1367. *
  1368. * @param {Element} el
  1369. * The element to empty children from
  1370. *
  1371. * @return {Element}
  1372. * The element with no children
  1373. */
  1374. function emptyEl(el) {
  1375. while (el.firstChild) {
  1376. el.removeChild(el.firstChild);
  1377. }
  1378. return el;
  1379. }
  1380. /**
  1381. * This is a mixed value that describes content to be injected into the DOM
  1382. * via some method. It can be of the following types:
  1383. *
  1384. * Type | Description
  1385. * -----------|-------------
  1386. * `string` | The value will be normalized into a text node.
  1387. * `Element` | The value will be accepted as-is.
  1388. * `TextNode` | The value will be accepted as-is.
  1389. * `Array` | A one-dimensional array of strings, elements, text nodes, or functions. These functions should return a string, element, or text node (any other return value, like an array, will be ignored).
  1390. * `Function` | A function, which is expected to return a string, element, text node, or array - any of the other possible values described above. This means that a content descriptor could be a function that returns an array of functions, but those second-level functions must return strings, elements, or text nodes.
  1391. *
  1392. * @typedef {string|Element|TextNode|Array|Function} module:dom~ContentDescriptor
  1393. */
  1394. /**
  1395. * Normalizes content for eventual insertion into the DOM.
  1396. *
  1397. * This allows a wide range of content definition methods, but helps protect
  1398. * from falling into the trap of simply writing to `innerHTML`, which could
  1399. * be an XSS concern.
  1400. *
  1401. * The content for an element can be passed in multiple types and
  1402. * combinations, whose behavior is as follows:
  1403. *
  1404. * @param {module:dom~ContentDescriptor} content
  1405. * A content descriptor value.
  1406. *
  1407. * @return {Array}
  1408. * All of the content that was passed in, normalized to an array of
  1409. * elements or text nodes.
  1410. */
  1411. function normalizeContent(content) {
  1412. // First, invoke content if it is a function. If it produces an array,
  1413. // that needs to happen before normalization.
  1414. if (typeof content === 'function') {
  1415. content = content();
  1416. } // Next up, normalize to an array, so one or many items can be normalized,
  1417. // filtered, and returned.
  1418. return (Array.isArray(content) ? content : [content]).map(function (value) {
  1419. // First, invoke value if it is a function to produce a new value,
  1420. // which will be subsequently normalized to a Node of some kind.
  1421. if (typeof value === 'function') {
  1422. value = value();
  1423. }
  1424. if (isEl(value) || isTextNode(value)) {
  1425. return value;
  1426. }
  1427. if (typeof value === 'string' && /\S/.test(value)) {
  1428. return document.createTextNode(value);
  1429. }
  1430. }).filter(function (value) {
  1431. return value;
  1432. });
  1433. }
  1434. /**
  1435. * Normalizes and appends content to an element.
  1436. *
  1437. * @param {Element} el
  1438. * Element to append normalized content to.
  1439. *
  1440. * @param {module:dom~ContentDescriptor} content
  1441. * A content descriptor value.
  1442. *
  1443. * @return {Element}
  1444. * The element with appended normalized content.
  1445. */
  1446. function appendContent(el, content) {
  1447. normalizeContent(content).forEach(function (node) {
  1448. return el.appendChild(node);
  1449. });
  1450. return el;
  1451. }
  1452. /**
  1453. * Normalizes and inserts content into an element; this is identical to
  1454. * `appendContent()`, except it empties the element first.
  1455. *
  1456. * @param {Element} el
  1457. * Element to insert normalized content into.
  1458. *
  1459. * @param {module:dom~ContentDescriptor} content
  1460. * A content descriptor value.
  1461. *
  1462. * @return {Element}
  1463. * The element with inserted normalized content.
  1464. */
  1465. function insertContent(el, content) {
  1466. return appendContent(emptyEl(el), content);
  1467. }
  1468. /**
  1469. * Check if an event was a single left click.
  1470. *
  1471. * @param {EventTarget~Event} event
  1472. * Event object.
  1473. *
  1474. * @return {boolean}
  1475. * Will be `true` if a single left click, `false` otherwise.
  1476. */
  1477. function isSingleLeftClick(event) {
  1478. // Note: if you create something draggable, be sure to
  1479. // call it on both `mousedown` and `mousemove` event,
  1480. // otherwise `mousedown` should be enough for a button
  1481. if (event.button === undefined && event.buttons === undefined) {
  1482. // Why do we need `buttons` ?
  1483. // Because, middle mouse sometimes have this:
  1484. // e.button === 0 and e.buttons === 4
  1485. // Furthermore, we want to prevent combination click, something like
  1486. // HOLD middlemouse then left click, that would be
  1487. // e.button === 0, e.buttons === 5
  1488. // just `button` is not gonna work
  1489. // Alright, then what this block does ?
  1490. // this is for chrome `simulate mobile devices`
  1491. // I want to support this as well
  1492. return true;
  1493. }
  1494. if (event.button === 0 && event.buttons === undefined) {
  1495. // Touch screen, sometimes on some specific device, `buttons`
  1496. // doesn't have anything (safari on ios, blackberry...)
  1497. return true;
  1498. } // `mouseup` event on a single left click has
  1499. // `button` and `buttons` equal to 0
  1500. if (event.type === 'mouseup' && event.button === 0 && event.buttons === 0) {
  1501. return true;
  1502. }
  1503. if (event.button !== 0 || event.buttons !== 1) {
  1504. // This is the reason we have those if else block above
  1505. // if any special case we can catch and let it slide
  1506. // we do it above, when get to here, this definitely
  1507. // is-not-left-click
  1508. return false;
  1509. }
  1510. return true;
  1511. }
  1512. /**
  1513. * Finds a single DOM element matching `selector` within the optional
  1514. * `context` of another DOM element (defaulting to `document`).
  1515. *
  1516. * @param {string} selector
  1517. * A valid CSS selector, which will be passed to `querySelector`.
  1518. *
  1519. * @param {Element|String} [context=document]
  1520. * A DOM element within which to query. Can also be a selector
  1521. * string in which case the first matching element will be used
  1522. * as context. If missing (or no element matches selector), falls
  1523. * back to `document`.
  1524. *
  1525. * @return {Element|null}
  1526. * The element that was found or null.
  1527. */
  1528. var $ = createQuerier('querySelector');
  1529. /**
  1530. * Finds a all DOM elements matching `selector` within the optional
  1531. * `context` of another DOM element (defaulting to `document`).
  1532. *
  1533. * @param {string} selector
  1534. * A valid CSS selector, which will be passed to `querySelectorAll`.
  1535. *
  1536. * @param {Element|String} [context=document]
  1537. * A DOM element within which to query. Can also be a selector
  1538. * string in which case the first matching element will be used
  1539. * as context. If missing (or no element matches selector), falls
  1540. * back to `document`.
  1541. *
  1542. * @return {NodeList}
  1543. * A element list of elements that were found. Will be empty if none
  1544. * were found.
  1545. *
  1546. */
  1547. var $$ = createQuerier('querySelectorAll');
  1548. var Dom = /*#__PURE__*/Object.freeze({
  1549. __proto__: null,
  1550. isReal: isReal,
  1551. isEl: isEl,
  1552. isInFrame: isInFrame,
  1553. createEl: createEl,
  1554. textContent: textContent,
  1555. prependTo: prependTo,
  1556. hasClass: hasClass,
  1557. addClass: addClass,
  1558. removeClass: removeClass,
  1559. toggleClass: toggleClass,
  1560. setAttributes: setAttributes,
  1561. getAttributes: getAttributes,
  1562. getAttribute: getAttribute,
  1563. setAttribute: setAttribute,
  1564. removeAttribute: removeAttribute,
  1565. blockTextSelection: blockTextSelection,
  1566. unblockTextSelection: unblockTextSelection,
  1567. getBoundingClientRect: getBoundingClientRect,
  1568. findPosition: findPosition,
  1569. getPointerPosition: getPointerPosition,
  1570. isTextNode: isTextNode,
  1571. emptyEl: emptyEl,
  1572. normalizeContent: normalizeContent,
  1573. appendContent: appendContent,
  1574. insertContent: insertContent,
  1575. isSingleLeftClick: isSingleLeftClick,
  1576. $: $,
  1577. $$: $$
  1578. });
  1579. /**
  1580. * @file setup.js - Functions for setting up a player without
  1581. * user interaction based on the data-setup `attribute` of the video tag.
  1582. *
  1583. * @module setup
  1584. */
  1585. var _windowLoaded = false;
  1586. var videojs$1;
  1587. /**
  1588. * Set up any tags that have a data-setup `attribute` when the player is started.
  1589. */
  1590. var autoSetup = function autoSetup() {
  1591. if (videojs$1.options.autoSetup === false) {
  1592. return;
  1593. }
  1594. var vids = Array.prototype.slice.call(document.getElementsByTagName('video'));
  1595. var audios = Array.prototype.slice.call(document.getElementsByTagName('audio'));
  1596. var divs = Array.prototype.slice.call(document.getElementsByTagName('video-js'));
  1597. var mediaEls = vids.concat(audios, divs); // Check if any media elements exist
  1598. if (mediaEls && mediaEls.length > 0) {
  1599. for (var i = 0, e = mediaEls.length; i < e; i++) {
  1600. var mediaEl = mediaEls[i]; // Check if element exists, has getAttribute func.
  1601. if (mediaEl && mediaEl.getAttribute) {
  1602. // Make sure this player hasn't already been set up.
  1603. if (mediaEl.player === undefined) {
  1604. var options = mediaEl.getAttribute('data-setup'); // Check if data-setup attr exists.
  1605. // We only auto-setup if they've added the data-setup attr.
  1606. if (options !== null) {
  1607. // Create new video.js instance.
  1608. videojs$1(mediaEl);
  1609. }
  1610. } // If getAttribute isn't defined, we need to wait for the DOM.
  1611. } else {
  1612. autoSetupTimeout(1);
  1613. break;
  1614. }
  1615. } // No videos were found, so keep looping unless page is finished loading.
  1616. } else if (!_windowLoaded) {
  1617. autoSetupTimeout(1);
  1618. }
  1619. };
  1620. /**
  1621. * Wait until the page is loaded before running autoSetup. This will be called in
  1622. * autoSetup if `hasLoaded` returns false.
  1623. *
  1624. * @param {number} wait
  1625. * How long to wait in ms
  1626. *
  1627. * @param {module:videojs} [vjs]
  1628. * The videojs library function
  1629. */
  1630. function autoSetupTimeout(wait, vjs) {
  1631. // Protect against breakage in non-browser environments
  1632. if (!isReal()) {
  1633. return;
  1634. }
  1635. if (vjs) {
  1636. videojs$1 = vjs;
  1637. }
  1638. window.setTimeout(autoSetup, wait);
  1639. }
  1640. /**
  1641. * Used to set the internal tracking of window loaded state to true.
  1642. *
  1643. * @private
  1644. */
  1645. function setWindowLoaded() {
  1646. _windowLoaded = true;
  1647. window.removeEventListener('load', setWindowLoaded);
  1648. }
  1649. if (isReal()) {
  1650. if (document.readyState === 'complete') {
  1651. setWindowLoaded();
  1652. } else {
  1653. /**
  1654. * Listen for the load event on window, and set _windowLoaded to true.
  1655. *
  1656. * We use a standard event listener here to avoid incrementing the GUID
  1657. * before any players are created.
  1658. *
  1659. * @listens load
  1660. */
  1661. window.addEventListener('load', setWindowLoaded);
  1662. }
  1663. }
  1664. /**
  1665. * @file stylesheet.js
  1666. * @module stylesheet
  1667. */
  1668. /**
  1669. * Create a DOM syle element given a className for it.
  1670. *
  1671. * @param {string} className
  1672. * The className to add to the created style element.
  1673. *
  1674. * @return {Element}
  1675. * The element that was created.
  1676. */
  1677. var createStyleElement = function createStyleElement(className) {
  1678. var style = document.createElement('style');
  1679. style.className = className;
  1680. return style;
  1681. };
  1682. /**
  1683. * Add text to a DOM element.
  1684. *
  1685. * @param {Element} el
  1686. * The Element to add text content to.
  1687. *
  1688. * @param {string} content
  1689. * The text to add to the element.
  1690. */
  1691. var setTextContent = function setTextContent(el, content) {
  1692. if (el.styleSheet) {
  1693. el.styleSheet.cssText = content;
  1694. } else {
  1695. el.textContent = content;
  1696. }
  1697. };
  1698. /**
  1699. * @file guid.js
  1700. * @module guid
  1701. */
  1702. // Default value for GUIDs. This allows us to reset the GUID counter in tests.
  1703. //
  1704. // The initial GUID is 3 because some users have come to rely on the first
  1705. // default player ID ending up as `vjs_video_3`.
  1706. //
  1707. // See: https://github.com/videojs/video.js/pull/6216
  1708. var _initialGuid = 3;
  1709. /**
  1710. * Unique ID for an element or function
  1711. *
  1712. * @type {Number}
  1713. */
  1714. var _guid = _initialGuid;
  1715. /**
  1716. * Get a unique auto-incrementing ID by number that has not been returned before.
  1717. *
  1718. * @return {number}
  1719. * A new unique ID.
  1720. */
  1721. function newGUID() {
  1722. return _guid++;
  1723. }
  1724. /**
  1725. * @file dom-data.js
  1726. * @module dom-data
  1727. */
  1728. var FakeWeakMap;
  1729. if (!window.WeakMap) {
  1730. FakeWeakMap = /*#__PURE__*/function () {
  1731. function FakeWeakMap() {
  1732. this.vdata = 'vdata' + Math.floor(window.performance && window.performance.now() || Date.now());
  1733. this.data = {};
  1734. }
  1735. var _proto = FakeWeakMap.prototype;
  1736. _proto.set = function set(key, value) {
  1737. var access = key[this.vdata] || newGUID();
  1738. if (!key[this.vdata]) {
  1739. key[this.vdata] = access;
  1740. }
  1741. this.data[access] = value;
  1742. return this;
  1743. };
  1744. _proto.get = function get(key) {
  1745. var access = key[this.vdata]; // we have data, return it
  1746. if (access) {
  1747. return this.data[access];
  1748. } // we don't have data, return nothing.
  1749. // return undefined explicitly as that's the contract for this method
  1750. log('We have no data for this element', key);
  1751. return undefined;
  1752. };
  1753. _proto.has = function has(key) {
  1754. var access = key[this.vdata];
  1755. return access in this.data;
  1756. };
  1757. _proto["delete"] = function _delete(key) {
  1758. var access = key[this.vdata];
  1759. if (access) {
  1760. delete this.data[access];
  1761. delete key[this.vdata];
  1762. }
  1763. };
  1764. return FakeWeakMap;
  1765. }();
  1766. }
  1767. /**
  1768. * Element Data Store.
  1769. *
  1770. * Allows for binding data to an element without putting it directly on the
  1771. * element. Ex. Event listeners are stored here.
  1772. * (also from jsninja.com, slightly modified and updated for closure compiler)
  1773. *
  1774. * @type {Object}
  1775. * @private
  1776. */
  1777. var DomData = window.WeakMap ? new WeakMap() : new FakeWeakMap();
  1778. /**
  1779. * @file events.js. An Event System (John Resig - Secrets of a JS Ninja http://jsninja.com/)
  1780. * (Original book version wasn't completely usable, so fixed some things and made Closure Compiler compatible)
  1781. * This should work very similarly to jQuery's events, however it's based off the book version which isn't as
  1782. * robust as jquery's, so there's probably some differences.
  1783. *
  1784. * @file events.js
  1785. * @module events
  1786. */
  1787. /**
  1788. * Clean up the listener cache and dispatchers
  1789. *
  1790. * @param {Element|Object} elem
  1791. * Element to clean up
  1792. *
  1793. * @param {string} type
  1794. * Type of event to clean up
  1795. */
  1796. function _cleanUpEvents(elem, type) {
  1797. if (!DomData.has(elem)) {
  1798. return;
  1799. }
  1800. var data = DomData.get(elem); // Remove the events of a particular type if there are none left
  1801. if (data.handlers[type].length === 0) {
  1802. delete data.handlers[type]; // data.handlers[type] = null;
  1803. // Setting to null was causing an error with data.handlers
  1804. // Remove the meta-handler from the element
  1805. if (elem.removeEventListener) {
  1806. elem.removeEventListener(type, data.dispatcher, false);
  1807. } else if (elem.detachEvent) {
  1808. elem.detachEvent('on' + type, data.dispatcher);
  1809. }
  1810. } // Remove the events object if there are no types left
  1811. if (Object.getOwnPropertyNames(data.handlers).length <= 0) {
  1812. delete data.handlers;
  1813. delete data.dispatcher;
  1814. delete data.disabled;
  1815. } // Finally remove the element data if there is no data left
  1816. if (Object.getOwnPropertyNames(data).length === 0) {
  1817. DomData["delete"](elem);
  1818. }
  1819. }
  1820. /**
  1821. * Loops through an array of event types and calls the requested method for each type.
  1822. *
  1823. * @param {Function} fn
  1824. * The event method we want to use.
  1825. *
  1826. * @param {Element|Object} elem
  1827. * Element or object to bind listeners to
  1828. *
  1829. * @param {string} type
  1830. * Type of event to bind to.
  1831. *
  1832. * @param {EventTarget~EventListener} callback
  1833. * Event listener.
  1834. */
  1835. function _handleMultipleEvents(fn, elem, types, callback) {
  1836. types.forEach(function (type) {
  1837. // Call the event method for each one of the types
  1838. fn(elem, type, callback);
  1839. });
  1840. }
  1841. /**
  1842. * Fix a native event to have standard property values
  1843. *
  1844. * @param {Object} event
  1845. * Event object to fix.
  1846. *
  1847. * @return {Object}
  1848. * Fixed event object.
  1849. */
  1850. function fixEvent(event) {
  1851. if (event.fixed_) {
  1852. return event;
  1853. }
  1854. function returnTrue() {
  1855. return true;
  1856. }
  1857. function returnFalse() {
  1858. return false;
  1859. } // Test if fixing up is needed
  1860. // Used to check if !event.stopPropagation instead of isPropagationStopped
  1861. // But native events return true for stopPropagation, but don't have
  1862. // other expected methods like isPropagationStopped. Seems to be a problem
  1863. // with the Javascript Ninja code. So we're just overriding all events now.
  1864. if (!event || !event.isPropagationStopped || !event.isImmediatePropagationStopped) {
  1865. var old = event || window.event;
  1866. event = {}; // Clone the old object so that we can modify the values event = {};
  1867. // IE8 Doesn't like when you mess with native event properties
  1868. // Firefox returns false for event.hasOwnProperty('type') and other props
  1869. // which makes copying more difficult.
  1870. // TODO: Probably best to create a whitelist of event props
  1871. for (var key in old) {
  1872. // Safari 6.0.3 warns you if you try to copy deprecated layerX/Y
  1873. // Chrome warns you if you try to copy deprecated keyboardEvent.keyLocation
  1874. // and webkitMovementX/Y
  1875. // Lighthouse complains if Event.path is copied
  1876. if (key !== 'layerX' && key !== 'layerY' && key !== 'keyLocation' && key !== 'webkitMovementX' && key !== 'webkitMovementY' && key !== 'path') {
  1877. // Chrome 32+ warns if you try to copy deprecated returnValue, but
  1878. // we still want to if preventDefault isn't supported (IE8).
  1879. if (!(key === 'returnValue' && old.preventDefault)) {
  1880. event[key] = old[key];
  1881. }
  1882. }
  1883. } // The event occurred on this element
  1884. if (!event.target) {
  1885. event.target = event.srcElement || document;
  1886. } // Handle which other element the event is related to
  1887. if (!event.relatedTarget) {
  1888. event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
  1889. } // Stop the default browser action
  1890. event.preventDefault = function () {
  1891. if (old.preventDefault) {
  1892. old.preventDefault();
  1893. }
  1894. event.returnValue = false;
  1895. old.returnValue = false;
  1896. event.defaultPrevented = true;
  1897. };
  1898. event.defaultPrevented = false; // Stop the event from bubbling
  1899. event.stopPropagation = function () {
  1900. if (old.stopPropagation) {
  1901. old.stopPropagation();
  1902. }
  1903. event.cancelBubble = true;
  1904. old.cancelBubble = true;
  1905. event.isPropagationStopped = returnTrue;
  1906. };
  1907. event.isPropagationStopped = returnFalse; // Stop the event from bubbling and executing other handlers
  1908. event.stopImmediatePropagation = function () {
  1909. if (old.stopImmediatePropagation) {
  1910. old.stopImmediatePropagation();
  1911. }
  1912. event.isImmediatePropagationStopped = returnTrue;
  1913. event.stopPropagation();
  1914. };
  1915. event.isImmediatePropagationStopped = returnFalse; // Handle mouse position
  1916. if (event.clientX !== null && event.clientX !== undefined) {
  1917. var doc = document.documentElement;
  1918. var body = document.body;
  1919. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
  1920. event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
  1921. } // Handle key presses
  1922. event.which = event.charCode || event.keyCode; // Fix button for mouse clicks:
  1923. // 0 == left; 1 == middle; 2 == right
  1924. if (event.button !== null && event.button !== undefined) {
  1925. // The following is disabled because it does not pass videojs-standard
  1926. // and... yikes.
  1927. /* eslint-disable */
  1928. event.button = event.button & 1 ? 0 : event.button & 4 ? 1 : event.button & 2 ? 2 : 0;
  1929. /* eslint-enable */
  1930. }
  1931. }
  1932. event.fixed_ = true; // Returns fixed-up instance
  1933. return event;
  1934. }
  1935. /**
  1936. * Whether passive event listeners are supported
  1937. */
  1938. var _supportsPassive;
  1939. var supportsPassive = function supportsPassive() {
  1940. if (typeof _supportsPassive !== 'boolean') {
  1941. _supportsPassive = false;
  1942. try {
  1943. var opts = Object.defineProperty({}, 'passive', {
  1944. get: function get() {
  1945. _supportsPassive = true;
  1946. }
  1947. });
  1948. window.addEventListener('test', null, opts);
  1949. window.removeEventListener('test', null, opts);
  1950. } catch (e) {// disregard
  1951. }
  1952. }
  1953. return _supportsPassive;
  1954. };
  1955. /**
  1956. * Touch events Chrome expects to be passive
  1957. */
  1958. var passiveEvents = ['touchstart', 'touchmove'];
  1959. /**
  1960. * Add an event listener to element
  1961. * It stores the handler function in a separate cache object
  1962. * and adds a generic handler to the element's event,
  1963. * along with a unique id (guid) to the element.
  1964. *
  1965. * @param {Element|Object} elem
  1966. * Element or object to bind listeners to
  1967. *
  1968. * @param {string|string[]} type
  1969. * Type of event to bind to.
  1970. *
  1971. * @param {EventTarget~EventListener} fn
  1972. * Event listener.
  1973. */
  1974. function on(elem, type, fn) {
  1975. if (Array.isArray(type)) {
  1976. return _handleMultipleEvents(on, elem, type, fn);
  1977. }
  1978. if (!DomData.has(elem)) {
  1979. DomData.set(elem, {});
  1980. }
  1981. var data = DomData.get(elem); // We need a place to store all our handler data
  1982. if (!data.handlers) {
  1983. data.handlers = {};
  1984. }
  1985. if (!data.handlers[type]) {
  1986. data.handlers[type] = [];
  1987. }
  1988. if (!fn.guid) {
  1989. fn.guid = newGUID();
  1990. }
  1991. data.handlers[type].push(fn);
  1992. if (!data.dispatcher) {
  1993. data.disabled = false;
  1994. data.dispatcher = function (event, hash) {
  1995. if (data.disabled) {
  1996. return;
  1997. }
  1998. event = fixEvent(event);
  1999. var handlers = data.handlers[event.type];
  2000. if (handlers) {
  2001. // Copy handlers so if handlers are added/removed during the process it doesn't throw everything off.
  2002. var handlersCopy = handlers.slice(0);
  2003. for (var m = 0, n = handlersCopy.length; m < n; m++) {
  2004. if (event.isImmediatePropagationStopped()) {
  2005. break;
  2006. } else {
  2007. try {
  2008. handlersCopy[m].call(elem, event, hash);
  2009. } catch (e) {
  2010. log.error(e);
  2011. }
  2012. }
  2013. }
  2014. }
  2015. };
  2016. }
  2017. if (data.handlers[type].length === 1) {
  2018. if (elem.addEventListener) {
  2019. var options = false;
  2020. if (supportsPassive() && passiveEvents.indexOf(type) > -1) {
  2021. options = {
  2022. passive: true
  2023. };
  2024. }
  2025. elem.addEventListener(type, data.dispatcher, options);
  2026. } else if (elem.attachEvent) {
  2027. elem.attachEvent('on' + type, data.dispatcher);
  2028. }
  2029. }
  2030. }
  2031. /**
  2032. * Removes event listeners from an element
  2033. *
  2034. * @param {Element|Object} elem
  2035. * Object to remove listeners from.
  2036. *
  2037. * @param {string|string[]} [type]
  2038. * Type of listener to remove. Don't include to remove all events from element.
  2039. *
  2040. * @param {EventTarget~EventListener} [fn]
  2041. * Specific listener to remove. Don't include to remove listeners for an event
  2042. * type.
  2043. */
  2044. function off(elem, type, fn) {
  2045. // Don't want to add a cache object through getElData if not needed
  2046. if (!DomData.has(elem)) {
  2047. return;
  2048. }
  2049. var data = DomData.get(elem); // If no events exist, nothing to unbind
  2050. if (!data.handlers) {
  2051. return;
  2052. }
  2053. if (Array.isArray(type)) {
  2054. return _handleMultipleEvents(off, elem, type, fn);
  2055. } // Utility function
  2056. var removeType = function removeType(el, t) {
  2057. data.handlers[t] = [];
  2058. _cleanUpEvents(el, t);
  2059. }; // Are we removing all bound events?
  2060. if (type === undefined) {
  2061. for (var t in data.handlers) {
  2062. if (Object.prototype.hasOwnProperty.call(data.handlers || {}, t)) {
  2063. removeType(elem, t);
  2064. }
  2065. }
  2066. return;
  2067. }
  2068. var handlers = data.handlers[type]; // If no handlers exist, nothing to unbind
  2069. if (!handlers) {
  2070. return;
  2071. } // If no listener was provided, remove all listeners for type
  2072. if (!fn) {
  2073. removeType(elem, type);
  2074. return;
  2075. } // We're only removing a single handler
  2076. if (fn.guid) {
  2077. for (var n = 0; n < handlers.length; n++) {
  2078. if (handlers[n].guid === fn.guid) {
  2079. handlers.splice(n--, 1);
  2080. }
  2081. }
  2082. }
  2083. _cleanUpEvents(elem, type);
  2084. }
  2085. /**
  2086. * Trigger an event for an element
  2087. *
  2088. * @param {Element|Object} elem
  2089. * Element to trigger an event on
  2090. *
  2091. * @param {EventTarget~Event|string} event
  2092. * A string (the type) or an event object with a type attribute
  2093. *
  2094. * @param {Object} [hash]
  2095. * data hash to pass along with the event
  2096. *
  2097. * @return {boolean|undefined}
  2098. * Returns the opposite of `defaultPrevented` if default was
  2099. * prevented. Otherwise, returns `undefined`
  2100. */
  2101. function trigger(elem, event, hash) {
  2102. // Fetches element data and a reference to the parent (for bubbling).
  2103. // Don't want to add a data object to cache for every parent,
  2104. // so checking hasElData first.
  2105. var elemData = DomData.has(elem) ? DomData.get(elem) : {};
  2106. var parent = elem.parentNode || elem.ownerDocument; // type = event.type || event,
  2107. // handler;
  2108. // If an event name was passed as a string, creates an event out of it
  2109. if (typeof event === 'string') {
  2110. event = {
  2111. type: event,
  2112. target: elem
  2113. };
  2114. } else if (!event.target) {
  2115. event.target = elem;
  2116. } // Normalizes the event properties.
  2117. event = fixEvent(event); // If the passed element has a dispatcher, executes the established handlers.
  2118. if (elemData.dispatcher) {
  2119. elemData.dispatcher.call(elem, event, hash);
  2120. } // Unless explicitly stopped or the event does not bubble (e.g. media events)
  2121. // recursively calls this function to bubble the event up the DOM.
  2122. if (parent && !event.isPropagationStopped() && event.bubbles === true) {
  2123. trigger.call(null, parent, event, hash); // If at the top of the DOM, triggers the default action unless disabled.
  2124. } else if (!parent && !event.defaultPrevented && event.target && event.target[event.type]) {
  2125. if (!DomData.has(event.target)) {
  2126. DomData.set(event.target, {});
  2127. }
  2128. var targetData = DomData.get(event.target); // Checks if the target has a default action for this event.
  2129. if (event.target[event.type]) {
  2130. // Temporarily disables event dispatching on the target as we have already executed the handler.
  2131. targetData.disabled = true; // Executes the default action.
  2132. if (typeof event.target[event.type] === 'function') {
  2133. event.target[event.type]();
  2134. } // Re-enables event dispatching.
  2135. targetData.disabled = false;
  2136. }
  2137. } // Inform the triggerer if the default was prevented by returning false
  2138. return !event.defaultPrevented;
  2139. }
  2140. /**
  2141. * Trigger a listener only once for an event.
  2142. *
  2143. * @param {Element|Object} elem
  2144. * Element or object to bind to.
  2145. *
  2146. * @param {string|string[]} type
  2147. * Name/type of event
  2148. *
  2149. * @param {Event~EventListener} fn
  2150. * Event listener function
  2151. */
  2152. function one(elem, type, fn) {
  2153. if (Array.isArray(type)) {
  2154. return _handleMultipleEvents(one, elem, type, fn);
  2155. }
  2156. var func = function func() {
  2157. off(elem, type, func);
  2158. fn.apply(this, arguments);
  2159. }; // copy the guid to the new function so it can removed using the original function's ID
  2160. func.guid = fn.guid = fn.guid || newGUID();
  2161. on(elem, type, func);
  2162. }
  2163. /**
  2164. * Trigger a listener only once and then turn if off for all
  2165. * configured events
  2166. *
  2167. * @param {Element|Object} elem
  2168. * Element or object to bind to.
  2169. *
  2170. * @param {string|string[]} type
  2171. * Name/type of event
  2172. *
  2173. * @param {Event~EventListener} fn
  2174. * Event listener function
  2175. */
  2176. function any(elem, type, fn) {
  2177. var func = function func() {
  2178. off(elem, type, func);
  2179. fn.apply(this, arguments);
  2180. }; // copy the guid to the new function so it can removed using the original function's ID
  2181. func.guid = fn.guid = fn.guid || newGUID(); // multiple ons, but one off for everything
  2182. on(elem, type, func);
  2183. }
  2184. var Events = /*#__PURE__*/Object.freeze({
  2185. __proto__: null,
  2186. fixEvent: fixEvent,
  2187. on: on,
  2188. off: off,
  2189. trigger: trigger,
  2190. one: one,
  2191. any: any
  2192. });
  2193. /**
  2194. * @file fn.js
  2195. * @module fn
  2196. */
  2197. var UPDATE_REFRESH_INTERVAL = 30;
  2198. /**
  2199. * Bind (a.k.a proxy or context). A simple method for changing the context of
  2200. * a function.
  2201. *
  2202. * It also stores a unique id on the function so it can be easily removed from
  2203. * events.
  2204. *
  2205. * @function
  2206. * @param {Mixed} context
  2207. * The object to bind as scope.
  2208. *
  2209. * @param {Function} fn
  2210. * The function to be bound to a scope.
  2211. *
  2212. * @param {number} [uid]
  2213. * An optional unique ID for the function to be set
  2214. *
  2215. * @return {Function}
  2216. * The new function that will be bound into the context given
  2217. */
  2218. var bind = function bind(context, fn, uid) {
  2219. // Make sure the function has a unique ID
  2220. if (!fn.guid) {
  2221. fn.guid = newGUID();
  2222. } // Create the new function that changes the context
  2223. var bound = fn.bind(context); // Allow for the ability to individualize this function
  2224. // Needed in the case where multiple objects might share the same prototype
  2225. // IF both items add an event listener with the same function, then you try to remove just one
  2226. // it will remove both because they both have the same guid.
  2227. // when using this, you need to use the bind method when you remove the listener as well.
  2228. // currently used in text tracks
  2229. bound.guid = uid ? uid + '_' + fn.guid : fn.guid;
  2230. return bound;
  2231. };
  2232. /**
  2233. * Wraps the given function, `fn`, with a new function that only invokes `fn`
  2234. * at most once per every `wait` milliseconds.
  2235. *
  2236. * @function
  2237. * @param {Function} fn
  2238. * The function to be throttled.
  2239. *
  2240. * @param {number} wait
  2241. * The number of milliseconds by which to throttle.
  2242. *
  2243. * @return {Function}
  2244. */
  2245. var throttle = function throttle(fn, wait) {
  2246. var last = window.performance.now();
  2247. var throttled = function throttled() {
  2248. var now = window.performance.now();
  2249. if (now - last >= wait) {
  2250. fn.apply(void 0, arguments);
  2251. last = now;
  2252. }
  2253. };
  2254. return throttled;
  2255. };
  2256. /**
  2257. * Creates a debounced function that delays invoking `func` until after `wait`
  2258. * milliseconds have elapsed since the last time the debounced function was
  2259. * invoked.
  2260. *
  2261. * Inspired by lodash and underscore implementations.
  2262. *
  2263. * @function
  2264. * @param {Function} func
  2265. * The function to wrap with debounce behavior.
  2266. *
  2267. * @param {number} wait
  2268. * The number of milliseconds to wait after the last invocation.
  2269. *
  2270. * @param {boolean} [immediate]
  2271. * Whether or not to invoke the function immediately upon creation.
  2272. *
  2273. * @param {Object} [context=window]
  2274. * The "context" in which the debounced function should debounce. For
  2275. * example, if this function should be tied to a Video.js player,
  2276. * the player can be passed here. Alternatively, defaults to the
  2277. * global `window` object.
  2278. *
  2279. * @return {Function}
  2280. * A debounced function.
  2281. */
  2282. var debounce = function debounce(func, wait, immediate, context) {
  2283. if (context === void 0) {
  2284. context = window;
  2285. }
  2286. var timeout;
  2287. var cancel = function cancel() {
  2288. context.clearTimeout(timeout);
  2289. timeout = null;
  2290. };
  2291. /* eslint-disable consistent-this */
  2292. var debounced = function debounced() {
  2293. var self = this;
  2294. var args = arguments;
  2295. var _later = function later() {
  2296. timeout = null;
  2297. _later = null;
  2298. if (!immediate) {
  2299. func.apply(self, args);
  2300. }
  2301. };
  2302. if (!timeout && immediate) {
  2303. func.apply(self, args);
  2304. }
  2305. context.clearTimeout(timeout);
  2306. timeout = context.setTimeout(_later, wait);
  2307. };
  2308. /* eslint-enable consistent-this */
  2309. debounced.cancel = cancel;
  2310. return debounced;
  2311. };
  2312. /**
  2313. * @file src/js/event-target.js
  2314. */
  2315. /**
  2316. * `EventTarget` is a class that can have the same API as the DOM `EventTarget`. It
  2317. * adds shorthand functions that wrap around lengthy functions. For example:
  2318. * the `on` function is a wrapper around `addEventListener`.
  2319. *
  2320. * @see [EventTarget Spec]{@link https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget}
  2321. * @class EventTarget
  2322. */
  2323. var EventTarget = function EventTarget() {};
  2324. /**
  2325. * A Custom DOM event.
  2326. *
  2327. * @typedef {Object} EventTarget~Event
  2328. * @see [Properties]{@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent}
  2329. */
  2330. /**
  2331. * All event listeners should follow the following format.
  2332. *
  2333. * @callback EventTarget~EventListener
  2334. * @this {EventTarget}
  2335. *
  2336. * @param {EventTarget~Event} event
  2337. * the event that triggered this function
  2338. *
  2339. * @param {Object} [hash]
  2340. * hash of data sent during the event
  2341. */
  2342. /**
  2343. * An object containing event names as keys and booleans as values.
  2344. *
  2345. * > NOTE: If an event name is set to a true value here {@link EventTarget#trigger}
  2346. * will have extra functionality. See that function for more information.
  2347. *
  2348. * @property EventTarget.prototype.allowedEvents_
  2349. * @private
  2350. */
  2351. EventTarget.prototype.allowedEvents_ = {};
  2352. /**
  2353. * Adds an `event listener` to an instance of an `EventTarget`. An `event listener` is a
  2354. * function that will get called when an event with a certain name gets triggered.
  2355. *
  2356. * @param {string|string[]} type
  2357. * An event name or an array of event names.
  2358. *
  2359. * @param {EventTarget~EventListener} fn
  2360. * The function to call with `EventTarget`s
  2361. */
  2362. EventTarget.prototype.on = function (type, fn) {
  2363. // Remove the addEventListener alias before calling Events.on
  2364. // so we don't get into an infinite type loop
  2365. var ael = this.addEventListener;
  2366. this.addEventListener = function () {};
  2367. on(this, type, fn);
  2368. this.addEventListener = ael;
  2369. };
  2370. /**
  2371. * An alias of {@link EventTarget#on}. Allows `EventTarget` to mimic
  2372. * the standard DOM API.
  2373. *
  2374. * @function
  2375. * @see {@link EventTarget#on}
  2376. */
  2377. EventTarget.prototype.addEventListener = EventTarget.prototype.on;
  2378. /**
  2379. * Removes an `event listener` for a specific event from an instance of `EventTarget`.
  2380. * This makes it so that the `event listener` will no longer get called when the
  2381. * named event happens.
  2382. *
  2383. * @param {string|string[]} type
  2384. * An event name or an array of event names.
  2385. *
  2386. * @param {EventTarget~EventListener} fn
  2387. * The function to remove.
  2388. */
  2389. EventTarget.prototype.off = function (type, fn) {
  2390. off(this, type, fn);
  2391. };
  2392. /**
  2393. * An alias of {@link EventTarget#off}. Allows `EventTarget` to mimic
  2394. * the standard DOM API.
  2395. *
  2396. * @function
  2397. * @see {@link EventTarget#off}
  2398. */
  2399. EventTarget.prototype.removeEventListener = EventTarget.prototype.off;
  2400. /**
  2401. * This function will add an `event listener` that gets triggered only once. After the
  2402. * first trigger it will get removed. This is like adding an `event listener`
  2403. * with {@link EventTarget#on} that calls {@link EventTarget#off} on itself.
  2404. *
  2405. * @param {string|string[]} type
  2406. * An event name or an array of event names.
  2407. *
  2408. * @param {EventTarget~EventListener} fn
  2409. * The function to be called once for each event name.
  2410. */
  2411. EventTarget.prototype.one = function (type, fn) {
  2412. // Remove the addEventListener aliasing Events.on
  2413. // so we don't get into an infinite type loop
  2414. var ael = this.addEventListener;
  2415. this.addEventListener = function () {};
  2416. one(this, type, fn);
  2417. this.addEventListener = ael;
  2418. };
  2419. EventTarget.prototype.any = function (type, fn) {
  2420. // Remove the addEventListener aliasing Events.on
  2421. // so we don't get into an infinite type loop
  2422. var ael = this.addEventListener;
  2423. this.addEventListener = function () {};
  2424. any(this, type, fn);
  2425. this.addEventListener = ael;
  2426. };
  2427. /**
  2428. * This function causes an event to happen. This will then cause any `event listeners`
  2429. * that are waiting for that event, to get called. If there are no `event listeners`
  2430. * for an event then nothing will happen.
  2431. *
  2432. * If the name of the `Event` that is being triggered is in `EventTarget.allowedEvents_`.
  2433. * Trigger will also call the `on` + `uppercaseEventName` function.
  2434. *
  2435. * Example:
  2436. * 'click' is in `EventTarget.allowedEvents_`, so, trigger will attempt to call
  2437. * `onClick` if it exists.
  2438. *
  2439. * @param {string|EventTarget~Event|Object} event
  2440. * The name of the event, an `Event`, or an object with a key of type set to
  2441. * an event name.
  2442. */
  2443. EventTarget.prototype.trigger = function (event) {
  2444. var type = event.type || event; // deprecation
  2445. // In a future version we should default target to `this`
  2446. // similar to how we default the target to `elem` in
  2447. // `Events.trigger`. Right now the default `target` will be
  2448. // `document` due to the `Event.fixEvent` call.
  2449. if (typeof event === 'string') {
  2450. event = {
  2451. type: type
  2452. };
  2453. }
  2454. event = fixEvent(event);
  2455. if (this.allowedEvents_[type] && this['on' + type]) {
  2456. this['on' + type](event);
  2457. }
  2458. trigger(this, event);
  2459. };
  2460. /**
  2461. * An alias of {@link EventTarget#trigger}. Allows `EventTarget` to mimic
  2462. * the standard DOM API.
  2463. *
  2464. * @function
  2465. * @see {@link EventTarget#trigger}
  2466. */
  2467. EventTarget.prototype.dispatchEvent = EventTarget.prototype.trigger;
  2468. var EVENT_MAP;
  2469. EventTarget.prototype.queueTrigger = function (event) {
  2470. var _this = this;
  2471. // only set up EVENT_MAP if it'll be used
  2472. if (!EVENT_MAP) {
  2473. EVENT_MAP = new Map();
  2474. }
  2475. var type = event.type || event;
  2476. var map = EVENT_MAP.get(this);
  2477. if (!map) {
  2478. map = new Map();
  2479. EVENT_MAP.set(this, map);
  2480. }
  2481. var oldTimeout = map.get(type);
  2482. map["delete"](type);
  2483. window.clearTimeout(oldTimeout);
  2484. var timeout = window.setTimeout(function () {
  2485. map["delete"](type); // if we cleared out all timeouts for the current target, delete its map
  2486. if (map.size === 0) {
  2487. map = null;
  2488. EVENT_MAP["delete"](_this);
  2489. }
  2490. _this.trigger(event);
  2491. }, 0);
  2492. map.set(type, timeout);
  2493. };
  2494. /**
  2495. * @file mixins/evented.js
  2496. * @module evented
  2497. */
  2498. var objName = function objName(obj) {
  2499. if (typeof obj.name === 'function') {
  2500. return obj.name();
  2501. }
  2502. if (typeof obj.name === 'string') {
  2503. return obj.name;
  2504. }
  2505. if (obj.name_) {
  2506. return obj.name_;
  2507. }
  2508. if (obj.constructor && obj.constructor.name) {
  2509. return obj.constructor.name;
  2510. }
  2511. return typeof obj;
  2512. };
  2513. /**
  2514. * Returns whether or not an object has had the evented mixin applied.
  2515. *
  2516. * @param {Object} object
  2517. * An object to test.
  2518. *
  2519. * @return {boolean}
  2520. * Whether or not the object appears to be evented.
  2521. */
  2522. var isEvented = function isEvented(object) {
  2523. return object instanceof EventTarget || !!object.eventBusEl_ && ['on', 'one', 'off', 'trigger'].every(function (k) {
  2524. return typeof object[k] === 'function';
  2525. });
  2526. };
  2527. /**
  2528. * Adds a callback to run after the evented mixin applied.
  2529. *
  2530. * @param {Object} object
  2531. * An object to Add
  2532. * @param {Function} callback
  2533. * The callback to run.
  2534. */
  2535. var addEventedCallback = function addEventedCallback(target, callback) {
  2536. if (isEvented(target)) {
  2537. callback();
  2538. } else {
  2539. if (!target.eventedCallbacks) {
  2540. target.eventedCallbacks = [];
  2541. }
  2542. target.eventedCallbacks.push(callback);
  2543. }
  2544. };
  2545. /**
  2546. * Whether a value is a valid event type - non-empty string or array.
  2547. *
  2548. * @private
  2549. * @param {string|Array} type
  2550. * The type value to test.
  2551. *
  2552. * @return {boolean}
  2553. * Whether or not the type is a valid event type.
  2554. */
  2555. var isValidEventType = function isValidEventType(type) {
  2556. return (// The regex here verifies that the `type` contains at least one non-
  2557. // whitespace character.
  2558. typeof type === 'string' && /\S/.test(type) || Array.isArray(type) && !!type.length
  2559. );
  2560. };
  2561. /**
  2562. * Validates a value to determine if it is a valid event target. Throws if not.
  2563. *
  2564. * @private
  2565. * @throws {Error}
  2566. * If the target does not appear to be a valid event target.
  2567. *
  2568. * @param {Object} target
  2569. * The object to test.
  2570. *
  2571. * @param {Object} obj
  2572. * The evented object we are validating for
  2573. *
  2574. * @param {string} fnName
  2575. * The name of the evented mixin function that called this.
  2576. */
  2577. var validateTarget = function validateTarget(target, obj, fnName) {
  2578. if (!target || !target.nodeName && !isEvented(target)) {
  2579. throw new Error("Invalid target for " + objName(obj) + "#" + fnName + "; must be a DOM node or evented object.");
  2580. }
  2581. };
  2582. /**
  2583. * Validates a value to determine if it is a valid event target. Throws if not.
  2584. *
  2585. * @private
  2586. * @throws {Error}
  2587. * If the type does not appear to be a valid event type.
  2588. *
  2589. * @param {string|Array} type
  2590. * The type to test.
  2591. *
  2592. * @param {Object} obj
  2593. * The evented object we are validating for
  2594. *
  2595. * @param {string} fnName
  2596. * The name of the evented mixin function that called this.
  2597. */
  2598. var validateEventType = function validateEventType(type, obj, fnName) {
  2599. if (!isValidEventType(type)) {
  2600. throw new Error("Invalid event type for " + objName(obj) + "#" + fnName + "; must be a non-empty string or array.");
  2601. }
  2602. };
  2603. /**
  2604. * Validates a value to determine if it is a valid listener. Throws if not.
  2605. *
  2606. * @private
  2607. * @throws {Error}
  2608. * If the listener is not a function.
  2609. *
  2610. * @param {Function} listener
  2611. * The listener to test.
  2612. *
  2613. * @param {Object} obj
  2614. * The evented object we are validating for
  2615. *
  2616. * @param {string} fnName
  2617. * The name of the evented mixin function that called this.
  2618. */
  2619. var validateListener = function validateListener(listener, obj, fnName) {
  2620. if (typeof listener !== 'function') {
  2621. throw new Error("Invalid listener for " + objName(obj) + "#" + fnName + "; must be a function.");
  2622. }
  2623. };
  2624. /**
  2625. * Takes an array of arguments given to `on()` or `one()`, validates them, and
  2626. * normalizes them into an object.
  2627. *
  2628. * @private
  2629. * @param {Object} self
  2630. * The evented object on which `on()` or `one()` was called. This
  2631. * object will be bound as the `this` value for the listener.
  2632. *
  2633. * @param {Array} args
  2634. * An array of arguments passed to `on()` or `one()`.
  2635. *
  2636. * @param {string} fnName
  2637. * The name of the evented mixin function that called this.
  2638. *
  2639. * @return {Object}
  2640. * An object containing useful values for `on()` or `one()` calls.
  2641. */
  2642. var normalizeListenArgs = function normalizeListenArgs(self, args, fnName) {
  2643. // If the number of arguments is less than 3, the target is always the
  2644. // evented object itself.
  2645. var isTargetingSelf = args.length < 3 || args[0] === self || args[0] === self.eventBusEl_;
  2646. var target;
  2647. var type;
  2648. var listener;
  2649. if (isTargetingSelf) {
  2650. target = self.eventBusEl_; // Deal with cases where we got 3 arguments, but we are still listening to
  2651. // the evented object itself.
  2652. if (args.length >= 3) {
  2653. args.shift();
  2654. }
  2655. type = args[0];
  2656. listener = args[1];
  2657. } else {
  2658. target = args[0];
  2659. type = args[1];
  2660. listener = args[2];
  2661. }
  2662. validateTarget(target, self, fnName);
  2663. validateEventType(type, self, fnName);
  2664. validateListener(listener, self, fnName);
  2665. listener = bind(self, listener);
  2666. return {
  2667. isTargetingSelf: isTargetingSelf,
  2668. target: target,
  2669. type: type,
  2670. listener: listener
  2671. };
  2672. };
  2673. /**
  2674. * Adds the listener to the event type(s) on the target, normalizing for
  2675. * the type of target.
  2676. *
  2677. * @private
  2678. * @param {Element|Object} target
  2679. * A DOM node or evented object.
  2680. *
  2681. * @param {string} method
  2682. * The event binding method to use ("on" or "one").
  2683. *
  2684. * @param {string|Array} type
  2685. * One or more event type(s).
  2686. *
  2687. * @param {Function} listener
  2688. * A listener function.
  2689. */
  2690. var listen = function listen(target, method, type, listener) {
  2691. validateTarget(target, target, method);
  2692. if (target.nodeName) {
  2693. Events[method](target, type, listener);
  2694. } else {
  2695. target[method](type, listener);
  2696. }
  2697. };
  2698. /**
  2699. * Contains methods that provide event capabilities to an object which is passed
  2700. * to {@link module:evented|evented}.
  2701. *
  2702. * @mixin EventedMixin
  2703. */
  2704. var EventedMixin = {
  2705. /**
  2706. * Add a listener to an event (or events) on this object or another evented
  2707. * object.
  2708. *
  2709. * @param {string|Array|Element|Object} targetOrType
  2710. * If this is a string or array, it represents the event type(s)
  2711. * that will trigger the listener.
  2712. *
  2713. * Another evented object can be passed here instead, which will
  2714. * cause the listener to listen for events on _that_ object.
  2715. *
  2716. * In either case, the listener's `this` value will be bound to
  2717. * this object.
  2718. *
  2719. * @param {string|Array|Function} typeOrListener
  2720. * If the first argument was a string or array, this should be the
  2721. * listener function. Otherwise, this is a string or array of event
  2722. * type(s).
  2723. *
  2724. * @param {Function} [listener]
  2725. * If the first argument was another evented object, this will be
  2726. * the listener function.
  2727. */
  2728. on: function on() {
  2729. var _this = this;
  2730. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2731. args[_key] = arguments[_key];
  2732. }
  2733. var _normalizeListenArgs = normalizeListenArgs(this, args, 'on'),
  2734. isTargetingSelf = _normalizeListenArgs.isTargetingSelf,
  2735. target = _normalizeListenArgs.target,
  2736. type = _normalizeListenArgs.type,
  2737. listener = _normalizeListenArgs.listener;
  2738. listen(target, 'on', type, listener); // If this object is listening to another evented object.
  2739. if (!isTargetingSelf) {
  2740. // If this object is disposed, remove the listener.
  2741. var removeListenerOnDispose = function removeListenerOnDispose() {
  2742. return _this.off(target, type, listener);
  2743. }; // Use the same function ID as the listener so we can remove it later it
  2744. // using the ID of the original listener.
  2745. removeListenerOnDispose.guid = listener.guid; // Add a listener to the target's dispose event as well. This ensures
  2746. // that if the target is disposed BEFORE this object, we remove the
  2747. // removal listener that was just added. Otherwise, we create a memory leak.
  2748. var removeRemoverOnTargetDispose = function removeRemoverOnTargetDispose() {
  2749. return _this.off('dispose', removeListenerOnDispose);
  2750. }; // Use the same function ID as the listener so we can remove it later
  2751. // it using the ID of the original listener.
  2752. removeRemoverOnTargetDispose.guid = listener.guid;
  2753. listen(this, 'on', 'dispose', removeListenerOnDispose);
  2754. listen(target, 'on', 'dispose', removeRemoverOnTargetDispose);
  2755. }
  2756. },
  2757. /**
  2758. * Add a listener to an event (or events) on this object or another evented
  2759. * object. The listener will be called once per event and then removed.
  2760. *
  2761. * @param {string|Array|Element|Object} targetOrType
  2762. * If this is a string or array, it represents the event type(s)
  2763. * that will trigger the listener.
  2764. *
  2765. * Another evented object can be passed here instead, which will
  2766. * cause the listener to listen for events on _that_ object.
  2767. *
  2768. * In either case, the listener's `this` value will be bound to
  2769. * this object.
  2770. *
  2771. * @param {string|Array|Function} typeOrListener
  2772. * If the first argument was a string or array, this should be the
  2773. * listener function. Otherwise, this is a string or array of event
  2774. * type(s).
  2775. *
  2776. * @param {Function} [listener]
  2777. * If the first argument was another evented object, this will be
  2778. * the listener function.
  2779. */
  2780. one: function one() {
  2781. var _this2 = this;
  2782. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2783. args[_key2] = arguments[_key2];
  2784. }
  2785. var _normalizeListenArgs2 = normalizeListenArgs(this, args, 'one'),
  2786. isTargetingSelf = _normalizeListenArgs2.isTargetingSelf,
  2787. target = _normalizeListenArgs2.target,
  2788. type = _normalizeListenArgs2.type,
  2789. listener = _normalizeListenArgs2.listener; // Targeting this evented object.
  2790. if (isTargetingSelf) {
  2791. listen(target, 'one', type, listener); // Targeting another evented object.
  2792. } else {
  2793. // TODO: This wrapper is incorrect! It should only
  2794. // remove the wrapper for the event type that called it.
  2795. // Instead all listners are removed on the first trigger!
  2796. // see https://github.com/videojs/video.js/issues/5962
  2797. var wrapper = function wrapper() {
  2798. _this2.off(target, type, wrapper);
  2799. for (var _len3 = arguments.length, largs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  2800. largs[_key3] = arguments[_key3];
  2801. }
  2802. listener.apply(null, largs);
  2803. }; // Use the same function ID as the listener so we can remove it later
  2804. // it using the ID of the original listener.
  2805. wrapper.guid = listener.guid;
  2806. listen(target, 'one', type, wrapper);
  2807. }
  2808. },
  2809. /**
  2810. * Add a listener to an event (or events) on this object or another evented
  2811. * object. The listener will only be called once for the first event that is triggered
  2812. * then removed.
  2813. *
  2814. * @param {string|Array|Element|Object} targetOrType
  2815. * If this is a string or array, it represents the event type(s)
  2816. * that will trigger the listener.
  2817. *
  2818. * Another evented object can be passed here instead, which will
  2819. * cause the listener to listen for events on _that_ object.
  2820. *
  2821. * In either case, the listener's `this` value will be bound to
  2822. * this object.
  2823. *
  2824. * @param {string|Array|Function} typeOrListener
  2825. * If the first argument was a string or array, this should be the
  2826. * listener function. Otherwise, this is a string or array of event
  2827. * type(s).
  2828. *
  2829. * @param {Function} [listener]
  2830. * If the first argument was another evented object, this will be
  2831. * the listener function.
  2832. */
  2833. any: function any() {
  2834. var _this3 = this;
  2835. for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  2836. args[_key4] = arguments[_key4];
  2837. }
  2838. var _normalizeListenArgs3 = normalizeListenArgs(this, args, 'any'),
  2839. isTargetingSelf = _normalizeListenArgs3.isTargetingSelf,
  2840. target = _normalizeListenArgs3.target,
  2841. type = _normalizeListenArgs3.type,
  2842. listener = _normalizeListenArgs3.listener; // Targeting this evented object.
  2843. if (isTargetingSelf) {
  2844. listen(target, 'any', type, listener); // Targeting another evented object.
  2845. } else {
  2846. var wrapper = function wrapper() {
  2847. _this3.off(target, type, wrapper);
  2848. for (var _len5 = arguments.length, largs = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  2849. largs[_key5] = arguments[_key5];
  2850. }
  2851. listener.apply(null, largs);
  2852. }; // Use the same function ID as the listener so we can remove it later
  2853. // it using the ID of the original listener.
  2854. wrapper.guid = listener.guid;
  2855. listen(target, 'any', type, wrapper);
  2856. }
  2857. },
  2858. /**
  2859. * Removes listener(s) from event(s) on an evented object.
  2860. *
  2861. * @param {string|Array|Element|Object} [targetOrType]
  2862. * If this is a string or array, it represents the event type(s).
  2863. *
  2864. * Another evented object can be passed here instead, in which case
  2865. * ALL 3 arguments are _required_.
  2866. *
  2867. * @param {string|Array|Function} [typeOrListener]
  2868. * If the first argument was a string or array, this may be the
  2869. * listener function. Otherwise, this is a string or array of event
  2870. * type(s).
  2871. *
  2872. * @param {Function} [listener]
  2873. * If the first argument was another evented object, this will be
  2874. * the listener function; otherwise, _all_ listeners bound to the
  2875. * event type(s) will be removed.
  2876. */
  2877. off: function off$1(targetOrType, typeOrListener, listener) {
  2878. // Targeting this evented object.
  2879. if (!targetOrType || isValidEventType(targetOrType)) {
  2880. off(this.eventBusEl_, targetOrType, typeOrListener); // Targeting another evented object.
  2881. } else {
  2882. var target = targetOrType;
  2883. var type = typeOrListener; // Fail fast and in a meaningful way!
  2884. validateTarget(target, this, 'off');
  2885. validateEventType(type, this, 'off');
  2886. validateListener(listener, this, 'off'); // Ensure there's at least a guid, even if the function hasn't been used
  2887. listener = bind(this, listener); // Remove the dispose listener on this evented object, which was given
  2888. // the same guid as the event listener in on().
  2889. this.off('dispose', listener);
  2890. if (target.nodeName) {
  2891. off(target, type, listener);
  2892. off(target, 'dispose', listener);
  2893. } else if (isEvented(target)) {
  2894. target.off(type, listener);
  2895. target.off('dispose', listener);
  2896. }
  2897. }
  2898. },
  2899. /**
  2900. * Fire an event on this evented object, causing its listeners to be called.
  2901. *
  2902. * @param {string|Object} event
  2903. * An event type or an object with a type property.
  2904. *
  2905. * @param {Object} [hash]
  2906. * An additional object to pass along to listeners.
  2907. *
  2908. * @return {boolean}
  2909. * Whether or not the default behavior was prevented.
  2910. */
  2911. trigger: function trigger$1(event, hash) {
  2912. validateTarget(this.eventBusEl_, this, 'trigger');
  2913. var type = event && typeof event !== 'string' ? event.type : event;
  2914. if (!isValidEventType(type)) {
  2915. var error = "Invalid event type for " + objName(this) + "#trigger; " + 'must be a non-empty string or object with a type key that has a non-empty value.';
  2916. if (event) {
  2917. (this.log || log).error(error);
  2918. } else {
  2919. throw new Error(error);
  2920. }
  2921. }
  2922. return trigger(this.eventBusEl_, event, hash);
  2923. }
  2924. };
  2925. /**
  2926. * Applies {@link module:evented~EventedMixin|EventedMixin} to a target object.
  2927. *
  2928. * @param {Object} target
  2929. * The object to which to add event methods.
  2930. *
  2931. * @param {Object} [options={}]
  2932. * Options for customizing the mixin behavior.
  2933. *
  2934. * @param {string} [options.eventBusKey]
  2935. * By default, adds a `eventBusEl_` DOM element to the target object,
  2936. * which is used as an event bus. If the target object already has a
  2937. * DOM element that should be used, pass its key here.
  2938. *
  2939. * @return {Object}
  2940. * The target object.
  2941. */
  2942. function evented(target, options) {
  2943. if (options === void 0) {
  2944. options = {};
  2945. }
  2946. var _options = options,
  2947. eventBusKey = _options.eventBusKey; // Set or create the eventBusEl_.
  2948. if (eventBusKey) {
  2949. if (!target[eventBusKey].nodeName) {
  2950. throw new Error("The eventBusKey \"" + eventBusKey + "\" does not refer to an element.");
  2951. }
  2952. target.eventBusEl_ = target[eventBusKey];
  2953. } else {
  2954. target.eventBusEl_ = createEl('span', {
  2955. className: 'vjs-event-bus'
  2956. });
  2957. }
  2958. assign(target, EventedMixin);
  2959. if (target.eventedCallbacks) {
  2960. target.eventedCallbacks.forEach(function (callback) {
  2961. callback();
  2962. });
  2963. } // When any evented object is disposed, it removes all its listeners.
  2964. target.on('dispose', function () {
  2965. target.off();
  2966. [target, target.el_, target.eventBusEl_].forEach(function (val) {
  2967. if (val && DomData.has(val)) {
  2968. DomData["delete"](val);
  2969. }
  2970. });
  2971. window.setTimeout(function () {
  2972. target.eventBusEl_ = null;
  2973. }, 0);
  2974. });
  2975. return target;
  2976. }
  2977. /**
  2978. * @file mixins/stateful.js
  2979. * @module stateful
  2980. */
  2981. /**
  2982. * Contains methods that provide statefulness to an object which is passed
  2983. * to {@link module:stateful}.
  2984. *
  2985. * @mixin StatefulMixin
  2986. */
  2987. var StatefulMixin = {
  2988. /**
  2989. * A hash containing arbitrary keys and values representing the state of
  2990. * the object.
  2991. *
  2992. * @type {Object}
  2993. */
  2994. state: {},
  2995. /**
  2996. * Set the state of an object by mutating its
  2997. * {@link module:stateful~StatefulMixin.state|state} object in place.
  2998. *
  2999. * @fires module:stateful~StatefulMixin#statechanged
  3000. * @param {Object|Function} stateUpdates
  3001. * A new set of properties to shallow-merge into the plugin state.
  3002. * Can be a plain object or a function returning a plain object.
  3003. *
  3004. * @return {Object|undefined}
  3005. * An object containing changes that occurred. If no changes
  3006. * occurred, returns `undefined`.
  3007. */
  3008. setState: function setState(stateUpdates) {
  3009. var _this = this;
  3010. // Support providing the `stateUpdates` state as a function.
  3011. if (typeof stateUpdates === 'function') {
  3012. stateUpdates = stateUpdates();
  3013. }
  3014. var changes;
  3015. each(stateUpdates, function (value, key) {
  3016. // Record the change if the value is different from what's in the
  3017. // current state.
  3018. if (_this.state[key] !== value) {
  3019. changes = changes || {};
  3020. changes[key] = {
  3021. from: _this.state[key],
  3022. to: value
  3023. };
  3024. }
  3025. _this.state[key] = value;
  3026. }); // Only trigger "statechange" if there were changes AND we have a trigger
  3027. // function. This allows us to not require that the target object be an
  3028. // evented object.
  3029. if (changes && isEvented(this)) {
  3030. /**
  3031. * An event triggered on an object that is both
  3032. * {@link module:stateful|stateful} and {@link module:evented|evented}
  3033. * indicating that its state has changed.
  3034. *
  3035. * @event module:stateful~StatefulMixin#statechanged
  3036. * @type {Object}
  3037. * @property {Object} changes
  3038. * A hash containing the properties that were changed and
  3039. * the values they were changed `from` and `to`.
  3040. */
  3041. this.trigger({
  3042. changes: changes,
  3043. type: 'statechanged'
  3044. });
  3045. }
  3046. return changes;
  3047. }
  3048. };
  3049. /**
  3050. * Applies {@link module:stateful~StatefulMixin|StatefulMixin} to a target
  3051. * object.
  3052. *
  3053. * If the target object is {@link module:evented|evented} and has a
  3054. * `handleStateChanged` method, that method will be automatically bound to the
  3055. * `statechanged` event on itself.
  3056. *
  3057. * @param {Object} target
  3058. * The object to be made stateful.
  3059. *
  3060. * @param {Object} [defaultState]
  3061. * A default set of properties to populate the newly-stateful object's
  3062. * `state` property.
  3063. *
  3064. * @return {Object}
  3065. * Returns the `target`.
  3066. */
  3067. function stateful(target, defaultState) {
  3068. assign(target, StatefulMixin); // This happens after the mixing-in because we need to replace the `state`
  3069. // added in that step.
  3070. target.state = assign({}, target.state, defaultState); // Auto-bind the `handleStateChanged` method of the target object if it exists.
  3071. if (typeof target.handleStateChanged === 'function' && isEvented(target)) {
  3072. target.on('statechanged', target.handleStateChanged);
  3073. }
  3074. return target;
  3075. }
  3076. /**
  3077. * @file string-cases.js
  3078. * @module to-lower-case
  3079. */
  3080. /**
  3081. * Lowercase the first letter of a string.
  3082. *
  3083. * @param {string} string
  3084. * String to be lowercased
  3085. *
  3086. * @return {string}
  3087. * The string with a lowercased first letter
  3088. */
  3089. var toLowerCase = function toLowerCase(string) {
  3090. if (typeof string !== 'string') {
  3091. return string;
  3092. }
  3093. return string.replace(/./, function (w) {
  3094. return w.toLowerCase();
  3095. });
  3096. };
  3097. /**
  3098. * Uppercase the first letter of a string.
  3099. *
  3100. * @param {string} string
  3101. * String to be uppercased
  3102. *
  3103. * @return {string}
  3104. * The string with an uppercased first letter
  3105. */
  3106. var toTitleCase = function toTitleCase(string) {
  3107. if (typeof string !== 'string') {
  3108. return string;
  3109. }
  3110. return string.replace(/./, function (w) {
  3111. return w.toUpperCase();
  3112. });
  3113. };
  3114. /**
  3115. * Compares the TitleCase versions of the two strings for equality.
  3116. *
  3117. * @param {string} str1
  3118. * The first string to compare
  3119. *
  3120. * @param {string} str2
  3121. * The second string to compare
  3122. *
  3123. * @return {boolean}
  3124. * Whether the TitleCase versions of the strings are equal
  3125. */
  3126. var titleCaseEquals = function titleCaseEquals(str1, str2) {
  3127. return toTitleCase(str1) === toTitleCase(str2);
  3128. };
  3129. /**
  3130. * @file merge-options.js
  3131. * @module merge-options
  3132. */
  3133. /**
  3134. * Merge two objects recursively.
  3135. *
  3136. * Performs a deep merge like
  3137. * {@link https://lodash.com/docs/4.17.10#merge|lodash.merge}, but only merges
  3138. * plain objects (not arrays, elements, or anything else).
  3139. *
  3140. * Non-plain object values will be copied directly from the right-most
  3141. * argument.
  3142. *
  3143. * @static
  3144. * @param {Object[]} sources
  3145. * One or more objects to merge into a new object.
  3146. *
  3147. * @return {Object}
  3148. * A new object that is the merged result of all sources.
  3149. */
  3150. function mergeOptions() {
  3151. var result = {};
  3152. for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
  3153. sources[_key] = arguments[_key];
  3154. }
  3155. sources.forEach(function (source) {
  3156. if (!source) {
  3157. return;
  3158. }
  3159. each(source, function (value, key) {
  3160. if (!isPlain(value)) {
  3161. result[key] = value;
  3162. return;
  3163. }
  3164. if (!isPlain(result[key])) {
  3165. result[key] = {};
  3166. }
  3167. result[key] = mergeOptions(result[key], value);
  3168. });
  3169. });
  3170. return result;
  3171. }
  3172. var MapSham = /*#__PURE__*/function () {
  3173. function MapSham() {
  3174. this.map_ = {};
  3175. }
  3176. var _proto = MapSham.prototype;
  3177. _proto.has = function has(key) {
  3178. return key in this.map_;
  3179. };
  3180. _proto["delete"] = function _delete(key) {
  3181. var has = this.has(key);
  3182. delete this.map_[key];
  3183. return has;
  3184. };
  3185. _proto.set = function set(key, value) {
  3186. this.map_[key] = value;
  3187. return this;
  3188. };
  3189. _proto.forEach = function forEach(callback, thisArg) {
  3190. for (var key in this.map_) {
  3191. callback.call(thisArg, this.map_[key], key, this);
  3192. }
  3193. };
  3194. return MapSham;
  3195. }();
  3196. var Map$1 = window.Map ? window.Map : MapSham;
  3197. var SetSham = /*#__PURE__*/function () {
  3198. function SetSham() {
  3199. this.set_ = {};
  3200. }
  3201. var _proto = SetSham.prototype;
  3202. _proto.has = function has(key) {
  3203. return key in this.set_;
  3204. };
  3205. _proto["delete"] = function _delete(key) {
  3206. var has = this.has(key);
  3207. delete this.set_[key];
  3208. return has;
  3209. };
  3210. _proto.add = function add(key) {
  3211. this.set_[key] = 1;
  3212. return this;
  3213. };
  3214. _proto.forEach = function forEach(callback, thisArg) {
  3215. for (var key in this.set_) {
  3216. callback.call(thisArg, key, key, this);
  3217. }
  3218. };
  3219. return SetSham;
  3220. }();
  3221. var Set$1 = window.Set ? window.Set : SetSham;
  3222. var keycode = createCommonjsModule(function (module, exports) {
  3223. // Source: http://jsfiddle.net/vWx8V/
  3224. // http://stackoverflow.com/questions/5603195/full-list-of-javascript-keycodes
  3225. /**
  3226. * Conenience method returns corresponding value for given keyName or keyCode.
  3227. *
  3228. * @param {Mixed} keyCode {Number} or keyName {String}
  3229. * @return {Mixed}
  3230. * @api public
  3231. */
  3232. function keyCode(searchInput) {
  3233. // Keyboard Events
  3234. if (searchInput && 'object' === typeof searchInput) {
  3235. var hasKeyCode = searchInput.which || searchInput.keyCode || searchInput.charCode;
  3236. if (hasKeyCode) searchInput = hasKeyCode;
  3237. } // Numbers
  3238. if ('number' === typeof searchInput) return names[searchInput]; // Everything else (cast to string)
  3239. var search = String(searchInput); // check codes
  3240. var foundNamedKey = codes[search.toLowerCase()];
  3241. if (foundNamedKey) return foundNamedKey; // check aliases
  3242. var foundNamedKey = aliases[search.toLowerCase()];
  3243. if (foundNamedKey) return foundNamedKey; // weird character?
  3244. if (search.length === 1) return search.charCodeAt(0);
  3245. return undefined;
  3246. }
  3247. /**
  3248. * Compares a keyboard event with a given keyCode or keyName.
  3249. *
  3250. * @param {Event} event Keyboard event that should be tested
  3251. * @param {Mixed} keyCode {Number} or keyName {String}
  3252. * @return {Boolean}
  3253. * @api public
  3254. */
  3255. keyCode.isEventKey = function isEventKey(event, nameOrCode) {
  3256. if (event && 'object' === typeof event) {
  3257. var keyCode = event.which || event.keyCode || event.charCode;
  3258. if (keyCode === null || keyCode === undefined) {
  3259. return false;
  3260. }
  3261. if (typeof nameOrCode === 'string') {
  3262. // check codes
  3263. var foundNamedKey = codes[nameOrCode.toLowerCase()];
  3264. if (foundNamedKey) {
  3265. return foundNamedKey === keyCode;
  3266. } // check aliases
  3267. var foundNamedKey = aliases[nameOrCode.toLowerCase()];
  3268. if (foundNamedKey) {
  3269. return foundNamedKey === keyCode;
  3270. }
  3271. } else if (typeof nameOrCode === 'number') {
  3272. return nameOrCode === keyCode;
  3273. }
  3274. return false;
  3275. }
  3276. };
  3277. exports = module.exports = keyCode;
  3278. /**
  3279. * Get by name
  3280. *
  3281. * exports.code['enter'] // => 13
  3282. */
  3283. var codes = exports.code = exports.codes = {
  3284. 'backspace': 8,
  3285. 'tab': 9,
  3286. 'enter': 13,
  3287. 'shift': 16,
  3288. 'ctrl': 17,
  3289. 'alt': 18,
  3290. 'pause/break': 19,
  3291. 'caps lock': 20,
  3292. 'esc': 27,
  3293. 'space': 32,
  3294. 'page up': 33,
  3295. 'page down': 34,
  3296. 'end': 35,
  3297. 'home': 36,
  3298. 'left': 37,
  3299. 'up': 38,
  3300. 'right': 39,
  3301. 'down': 40,
  3302. 'insert': 45,
  3303. 'delete': 46,
  3304. 'command': 91,
  3305. 'left command': 91,
  3306. 'right command': 93,
  3307. 'numpad *': 106,
  3308. 'numpad +': 107,
  3309. 'numpad -': 109,
  3310. 'numpad .': 110,
  3311. 'numpad /': 111,
  3312. 'num lock': 144,
  3313. 'scroll lock': 145,
  3314. 'my computer': 182,
  3315. 'my calculator': 183,
  3316. ';': 186,
  3317. '=': 187,
  3318. ',': 188,
  3319. '-': 189,
  3320. '.': 190,
  3321. '/': 191,
  3322. '`': 192,
  3323. '[': 219,
  3324. '\\': 220,
  3325. ']': 221,
  3326. "'": 222
  3327. }; // Helper aliases
  3328. var aliases = exports.aliases = {
  3329. 'windows': 91,
  3330. '⇧': 16,
  3331. '⌥': 18,
  3332. '⌃': 17,
  3333. '⌘': 91,
  3334. 'ctl': 17,
  3335. 'control': 17,
  3336. 'option': 18,
  3337. 'pause': 19,
  3338. 'break': 19,
  3339. 'caps': 20,
  3340. 'return': 13,
  3341. 'escape': 27,
  3342. 'spc': 32,
  3343. 'spacebar': 32,
  3344. 'pgup': 33,
  3345. 'pgdn': 34,
  3346. 'ins': 45,
  3347. 'del': 46,
  3348. 'cmd': 91
  3349. };
  3350. /*!
  3351. * Programatically add the following
  3352. */
  3353. // lower case chars
  3354. for (i = 97; i < 123; i++) {
  3355. codes[String.fromCharCode(i)] = i - 32;
  3356. } // numbers
  3357. for (var i = 48; i < 58; i++) {
  3358. codes[i - 48] = i;
  3359. } // function keys
  3360. for (i = 1; i < 13; i++) {
  3361. codes['f' + i] = i + 111;
  3362. } // numpad keys
  3363. for (i = 0; i < 10; i++) {
  3364. codes['numpad ' + i] = i + 96;
  3365. }
  3366. /**
  3367. * Get by code
  3368. *
  3369. * exports.name[13] // => 'Enter'
  3370. */
  3371. var names = exports.names = exports.title = {}; // title for backward compat
  3372. // Create reverse mapping
  3373. for (i in codes) {
  3374. names[codes[i]] = i;
  3375. } // Add aliases
  3376. for (var alias in aliases) {
  3377. codes[alias] = aliases[alias];
  3378. }
  3379. });
  3380. keycode.code;
  3381. keycode.codes;
  3382. keycode.aliases;
  3383. keycode.names;
  3384. keycode.title;
  3385. /**
  3386. * Player Component - Base class for all UI objects
  3387. *
  3388. * @file component.js
  3389. */
  3390. /**
  3391. * Base class for all UI Components.
  3392. * Components are UI objects which represent both a javascript object and an element
  3393. * in the DOM. They can be children of other components, and can have
  3394. * children themselves.
  3395. *
  3396. * Components can also use methods from {@link EventTarget}
  3397. */
  3398. var Component = /*#__PURE__*/function () {
  3399. /**
  3400. * A callback that is called when a component is ready. Does not have any
  3401. * paramters and any callback value will be ignored.
  3402. *
  3403. * @callback Component~ReadyCallback
  3404. * @this Component
  3405. */
  3406. /**
  3407. * Creates an instance of this class.
  3408. *
  3409. * @param {Player} player
  3410. * The `Player` that this class should be attached to.
  3411. *
  3412. * @param {Object} [options]
  3413. * The key/value store of component options.
  3414. *
  3415. * @param {Object[]} [options.children]
  3416. * An array of children objects to intialize this component with. Children objects have
  3417. * a name property that will be used if more than one component of the same type needs to be
  3418. * added.
  3419. *
  3420. * @param {string} [options.className]
  3421. * A class or space separated list of classes to add the component
  3422. *
  3423. * @param {Component~ReadyCallback} [ready]
  3424. * Function that gets called when the `Component` is ready.
  3425. */
  3426. function Component(player, options, ready) {
  3427. var _this = this;
  3428. // The component might be the player itself and we can't pass `this` to super
  3429. if (!player && this.play) {
  3430. this.player_ = player = this; // eslint-disable-line
  3431. } else {
  3432. this.player_ = player;
  3433. }
  3434. this.isDisposed_ = false; // Hold the reference to the parent component via `addChild` method
  3435. this.parentComponent_ = null; // Make a copy of prototype.options_ to protect against overriding defaults
  3436. this.options_ = mergeOptions({}, this.options_); // Updated options with supplied options
  3437. options = this.options_ = mergeOptions(this.options_, options); // Get ID from options or options element if one is supplied
  3438. this.id_ = options.id || options.el && options.el.id; // If there was no ID from the options, generate one
  3439. if (!this.id_) {
  3440. // Don't require the player ID function in the case of mock players
  3441. var id = player && player.id && player.id() || 'no_player';
  3442. this.id_ = id + "_component_" + newGUID();
  3443. }
  3444. this.name_ = options.name || null; // Create element if one wasn't provided in options
  3445. if (options.el) {
  3446. this.el_ = options.el;
  3447. } else if (options.createEl !== false) {
  3448. this.el_ = this.createEl();
  3449. }
  3450. if (options.className && this.el_) {
  3451. options.className.split(' ').forEach(function (c) {
  3452. return _this.addClass(c);
  3453. });
  3454. } // if evented is anything except false, we want to mixin in evented
  3455. if (options.evented !== false) {
  3456. // Make this an evented object and use `el_`, if available, as its event bus
  3457. evented(this, {
  3458. eventBusKey: this.el_ ? 'el_' : null
  3459. });
  3460. this.handleLanguagechange = this.handleLanguagechange.bind(this);
  3461. this.on(this.player_, 'languagechange', this.handleLanguagechange);
  3462. }
  3463. stateful(this, this.constructor.defaultState);
  3464. this.children_ = [];
  3465. this.childIndex_ = {};
  3466. this.childNameIndex_ = {};
  3467. this.setTimeoutIds_ = new Set$1();
  3468. this.setIntervalIds_ = new Set$1();
  3469. this.rafIds_ = new Set$1();
  3470. this.namedRafs_ = new Map$1();
  3471. this.clearingTimersOnDispose_ = false; // Add any child components in options
  3472. if (options.initChildren !== false) {
  3473. this.initChildren();
  3474. } // Don't want to trigger ready here or it will go before init is actually
  3475. // finished for all children that run this constructor
  3476. this.ready(ready);
  3477. if (options.reportTouchActivity !== false) {
  3478. this.enableTouchActivity();
  3479. }
  3480. }
  3481. /**
  3482. * Dispose of the `Component` and all child components.
  3483. *
  3484. * @fires Component#dispose
  3485. *
  3486. * @param {Object} options
  3487. * @param {Element} options.originalEl element with which to replace player element
  3488. */
  3489. var _proto = Component.prototype;
  3490. _proto.dispose = function dispose(options) {
  3491. if (options === void 0) {
  3492. options = {};
  3493. }
  3494. // Bail out if the component has already been disposed.
  3495. if (this.isDisposed_) {
  3496. return;
  3497. }
  3498. if (this.readyQueue_) {
  3499. this.readyQueue_.length = 0;
  3500. }
  3501. /**
  3502. * Triggered when a `Component` is disposed.
  3503. *
  3504. * @event Component#dispose
  3505. * @type {EventTarget~Event}
  3506. *
  3507. * @property {boolean} [bubbles=false]
  3508. * set to false so that the dispose event does not
  3509. * bubble up
  3510. */
  3511. this.trigger({
  3512. type: 'dispose',
  3513. bubbles: false
  3514. });
  3515. this.isDisposed_ = true; // Dispose all children.
  3516. if (this.children_) {
  3517. for (var i = this.children_.length - 1; i >= 0; i--) {
  3518. if (this.children_[i].dispose) {
  3519. this.children_[i].dispose();
  3520. }
  3521. }
  3522. } // Delete child references
  3523. this.children_ = null;
  3524. this.childIndex_ = null;
  3525. this.childNameIndex_ = null;
  3526. this.parentComponent_ = null;
  3527. if (this.el_) {
  3528. // Remove element from DOM
  3529. if (this.el_.parentNode) {
  3530. if (options.restoreEl) {
  3531. this.el_.parentNode.replaceChild(options.restoreEl, this.el_);
  3532. } else {
  3533. this.el_.parentNode.removeChild(this.el_);
  3534. }
  3535. }
  3536. this.el_ = null;
  3537. } // remove reference to the player after disposing of the element
  3538. this.player_ = null;
  3539. }
  3540. /**
  3541. * Determine whether or not this component has been disposed.
  3542. *
  3543. * @return {boolean}
  3544. * If the component has been disposed, will be `true`. Otherwise, `false`.
  3545. */
  3546. ;
  3547. _proto.isDisposed = function isDisposed() {
  3548. return Boolean(this.isDisposed_);
  3549. }
  3550. /**
  3551. * Return the {@link Player} that the `Component` has attached to.
  3552. *
  3553. * @return {Player}
  3554. * The player that this `Component` has attached to.
  3555. */
  3556. ;
  3557. _proto.player = function player() {
  3558. return this.player_;
  3559. }
  3560. /**
  3561. * Deep merge of options objects with new options.
  3562. * > Note: When both `obj` and `options` contain properties whose values are objects.
  3563. * The two properties get merged using {@link module:mergeOptions}
  3564. *
  3565. * @param {Object} obj
  3566. * The object that contains new options.
  3567. *
  3568. * @return {Object}
  3569. * A new object of `this.options_` and `obj` merged together.
  3570. */
  3571. ;
  3572. _proto.options = function options(obj) {
  3573. if (!obj) {
  3574. return this.options_;
  3575. }
  3576. this.options_ = mergeOptions(this.options_, obj);
  3577. return this.options_;
  3578. }
  3579. /**
  3580. * Get the `Component`s DOM element
  3581. *
  3582. * @return {Element}
  3583. * The DOM element for this `Component`.
  3584. */
  3585. ;
  3586. _proto.el = function el() {
  3587. return this.el_;
  3588. }
  3589. /**
  3590. * Create the `Component`s DOM element.
  3591. *
  3592. * @param {string} [tagName]
  3593. * Element's DOM node type. e.g. 'div'
  3594. *
  3595. * @param {Object} [properties]
  3596. * An object of properties that should be set.
  3597. *
  3598. * @param {Object} [attributes]
  3599. * An object of attributes that should be set.
  3600. *
  3601. * @return {Element}
  3602. * The element that gets created.
  3603. */
  3604. ;
  3605. _proto.createEl = function createEl$1(tagName, properties, attributes) {
  3606. return createEl(tagName, properties, attributes);
  3607. }
  3608. /**
  3609. * Localize a string given the string in english.
  3610. *
  3611. * If tokens are provided, it'll try and run a simple token replacement on the provided string.
  3612. * The tokens it looks for look like `{1}` with the index being 1-indexed into the tokens array.
  3613. *
  3614. * If a `defaultValue` is provided, it'll use that over `string`,
  3615. * if a value isn't found in provided language files.
  3616. * This is useful if you want to have a descriptive key for token replacement
  3617. * but have a succinct localized string and not require `en.json` to be included.
  3618. *
  3619. * Currently, it is used for the progress bar timing.
  3620. * ```js
  3621. * {
  3622. * "progress bar timing: currentTime={1} duration={2}": "{1} of {2}"
  3623. * }
  3624. * ```
  3625. * It is then used like so:
  3626. * ```js
  3627. * this.localize('progress bar timing: currentTime={1} duration{2}',
  3628. * [this.player_.currentTime(), this.player_.duration()],
  3629. * '{1} of {2}');
  3630. * ```
  3631. *
  3632. * Which outputs something like: `01:23 of 24:56`.
  3633. *
  3634. *
  3635. * @param {string} string
  3636. * The string to localize and the key to lookup in the language files.
  3637. * @param {string[]} [tokens]
  3638. * If the current item has token replacements, provide the tokens here.
  3639. * @param {string} [defaultValue]
  3640. * Defaults to `string`. Can be a default value to use for token replacement
  3641. * if the lookup key is needed to be separate.
  3642. *
  3643. * @return {string}
  3644. * The localized string or if no localization exists the english string.
  3645. */
  3646. ;
  3647. _proto.localize = function localize(string, tokens, defaultValue) {
  3648. if (defaultValue === void 0) {
  3649. defaultValue = string;
  3650. }
  3651. var code = this.player_.language && this.player_.language();
  3652. var languages = this.player_.languages && this.player_.languages();
  3653. var language = languages && languages[code];
  3654. var primaryCode = code && code.split('-')[0];
  3655. var primaryLang = languages && languages[primaryCode];
  3656. var localizedString = defaultValue;
  3657. if (language && language[string]) {
  3658. localizedString = language[string];
  3659. } else if (primaryLang && primaryLang[string]) {
  3660. localizedString = primaryLang[string];
  3661. }
  3662. if (tokens) {
  3663. localizedString = localizedString.replace(/\{(\d+)\}/g, function (match, index) {
  3664. var value = tokens[index - 1];
  3665. var ret = value;
  3666. if (typeof value === 'undefined') {
  3667. ret = match;
  3668. }
  3669. return ret;
  3670. });
  3671. }
  3672. return localizedString;
  3673. }
  3674. /**
  3675. * Handles language change for the player in components. Should be overriden by sub-components.
  3676. *
  3677. * @abstract
  3678. */
  3679. ;
  3680. _proto.handleLanguagechange = function handleLanguagechange() {}
  3681. /**
  3682. * Return the `Component`s DOM element. This is where children get inserted.
  3683. * This will usually be the the same as the element returned in {@link Component#el}.
  3684. *
  3685. * @return {Element}
  3686. * The content element for this `Component`.
  3687. */
  3688. ;
  3689. _proto.contentEl = function contentEl() {
  3690. return this.contentEl_ || this.el_;
  3691. }
  3692. /**
  3693. * Get this `Component`s ID
  3694. *
  3695. * @return {string}
  3696. * The id of this `Component`
  3697. */
  3698. ;
  3699. _proto.id = function id() {
  3700. return this.id_;
  3701. }
  3702. /**
  3703. * Get the `Component`s name. The name gets used to reference the `Component`
  3704. * and is set during registration.
  3705. *
  3706. * @return {string}
  3707. * The name of this `Component`.
  3708. */
  3709. ;
  3710. _proto.name = function name() {
  3711. return this.name_;
  3712. }
  3713. /**
  3714. * Get an array of all child components
  3715. *
  3716. * @return {Array}
  3717. * The children
  3718. */
  3719. ;
  3720. _proto.children = function children() {
  3721. return this.children_;
  3722. }
  3723. /**
  3724. * Returns the child `Component` with the given `id`.
  3725. *
  3726. * @param {string} id
  3727. * The id of the child `Component` to get.
  3728. *
  3729. * @return {Component|undefined}
  3730. * The child `Component` with the given `id` or undefined.
  3731. */
  3732. ;
  3733. _proto.getChildById = function getChildById(id) {
  3734. return this.childIndex_[id];
  3735. }
  3736. /**
  3737. * Returns the child `Component` with the given `name`.
  3738. *
  3739. * @param {string} name
  3740. * The name of the child `Component` to get.
  3741. *
  3742. * @return {Component|undefined}
  3743. * The child `Component` with the given `name` or undefined.
  3744. */
  3745. ;
  3746. _proto.getChild = function getChild(name) {
  3747. if (!name) {
  3748. return;
  3749. }
  3750. return this.childNameIndex_[name];
  3751. }
  3752. /**
  3753. * Returns the descendant `Component` following the givent
  3754. * descendant `names`. For instance ['foo', 'bar', 'baz'] would
  3755. * try to get 'foo' on the current component, 'bar' on the 'foo'
  3756. * component and 'baz' on the 'bar' component and return undefined
  3757. * if any of those don't exist.
  3758. *
  3759. * @param {...string[]|...string} names
  3760. * The name of the child `Component` to get.
  3761. *
  3762. * @return {Component|undefined}
  3763. * The descendant `Component` following the given descendant
  3764. * `names` or undefined.
  3765. */
  3766. ;
  3767. _proto.getDescendant = function getDescendant() {
  3768. for (var _len = arguments.length, names = new Array(_len), _key = 0; _key < _len; _key++) {
  3769. names[_key] = arguments[_key];
  3770. }
  3771. // flatten array argument into the main array
  3772. names = names.reduce(function (acc, n) {
  3773. return acc.concat(n);
  3774. }, []);
  3775. var currentChild = this;
  3776. for (var i = 0; i < names.length; i++) {
  3777. currentChild = currentChild.getChild(names[i]);
  3778. if (!currentChild || !currentChild.getChild) {
  3779. return;
  3780. }
  3781. }
  3782. return currentChild;
  3783. }
  3784. /**
  3785. * Add a child `Component` inside the current `Component`.
  3786. *
  3787. *
  3788. * @param {string|Component} child
  3789. * The name or instance of a child to add.
  3790. *
  3791. * @param {Object} [options={}]
  3792. * The key/value store of options that will get passed to children of
  3793. * the child.
  3794. *
  3795. * @param {number} [index=this.children_.length]
  3796. * The index to attempt to add a child into.
  3797. *
  3798. * @return {Component}
  3799. * The `Component` that gets added as a child. When using a string the
  3800. * `Component` will get created by this process.
  3801. */
  3802. ;
  3803. _proto.addChild = function addChild(child, options, index) {
  3804. if (options === void 0) {
  3805. options = {};
  3806. }
  3807. if (index === void 0) {
  3808. index = this.children_.length;
  3809. }
  3810. var component;
  3811. var componentName; // If child is a string, create component with options
  3812. if (typeof child === 'string') {
  3813. componentName = toTitleCase(child);
  3814. var componentClassName = options.componentClass || componentName; // Set name through options
  3815. options.name = componentName; // Create a new object & element for this controls set
  3816. // If there's no .player_, this is a player
  3817. var ComponentClass = Component.getComponent(componentClassName);
  3818. if (!ComponentClass) {
  3819. throw new Error("Component " + componentClassName + " does not exist");
  3820. } // data stored directly on the videojs object may be
  3821. // misidentified as a component to retain
  3822. // backwards-compatibility with 4.x. check to make sure the
  3823. // component class can be instantiated.
  3824. if (typeof ComponentClass !== 'function') {
  3825. return null;
  3826. }
  3827. component = new ComponentClass(this.player_ || this, options); // child is a component instance
  3828. } else {
  3829. component = child;
  3830. }
  3831. if (component.parentComponent_) {
  3832. component.parentComponent_.removeChild(component);
  3833. }
  3834. this.children_.splice(index, 0, component);
  3835. component.parentComponent_ = this;
  3836. if (typeof component.id === 'function') {
  3837. this.childIndex_[component.id()] = component;
  3838. } // If a name wasn't used to create the component, check if we can use the
  3839. // name function of the component
  3840. componentName = componentName || component.name && toTitleCase(component.name());
  3841. if (componentName) {
  3842. this.childNameIndex_[componentName] = component;
  3843. this.childNameIndex_[toLowerCase(componentName)] = component;
  3844. } // Add the UI object's element to the container div (box)
  3845. // Having an element is not required
  3846. if (typeof component.el === 'function' && component.el()) {
  3847. // If inserting before a component, insert before that component's element
  3848. var refNode = null;
  3849. if (this.children_[index + 1]) {
  3850. // Most children are components, but the video tech is an HTML element
  3851. if (this.children_[index + 1].el_) {
  3852. refNode = this.children_[index + 1].el_;
  3853. } else if (isEl(this.children_[index + 1])) {
  3854. refNode = this.children_[index + 1];
  3855. }
  3856. }
  3857. this.contentEl().insertBefore(component.el(), refNode);
  3858. } // Return so it can stored on parent object if desired.
  3859. return component;
  3860. }
  3861. /**
  3862. * Remove a child `Component` from this `Component`s list of children. Also removes
  3863. * the child `Component`s element from this `Component`s element.
  3864. *
  3865. * @param {Component} component
  3866. * The child `Component` to remove.
  3867. */
  3868. ;
  3869. _proto.removeChild = function removeChild(component) {
  3870. if (typeof component === 'string') {
  3871. component = this.getChild(component);
  3872. }
  3873. if (!component || !this.children_) {
  3874. return;
  3875. }
  3876. var childFound = false;
  3877. for (var i = this.children_.length - 1; i >= 0; i--) {
  3878. if (this.children_[i] === component) {
  3879. childFound = true;
  3880. this.children_.splice(i, 1);
  3881. break;
  3882. }
  3883. }
  3884. if (!childFound) {
  3885. return;
  3886. }
  3887. component.parentComponent_ = null;
  3888. this.childIndex_[component.id()] = null;
  3889. this.childNameIndex_[toTitleCase(component.name())] = null;
  3890. this.childNameIndex_[toLowerCase(component.name())] = null;
  3891. var compEl = component.el();
  3892. if (compEl && compEl.parentNode === this.contentEl()) {
  3893. this.contentEl().removeChild(component.el());
  3894. }
  3895. }
  3896. /**
  3897. * Add and initialize default child `Component`s based upon options.
  3898. */
  3899. ;
  3900. _proto.initChildren = function initChildren() {
  3901. var _this2 = this;
  3902. var children = this.options_.children;
  3903. if (children) {
  3904. // `this` is `parent`
  3905. var parentOptions = this.options_;
  3906. var handleAdd = function handleAdd(child) {
  3907. var name = child.name;
  3908. var opts = child.opts; // Allow options for children to be set at the parent options
  3909. // e.g. videojs(id, { controlBar: false });
  3910. // instead of videojs(id, { children: { controlBar: false });
  3911. if (parentOptions[name] !== undefined) {
  3912. opts = parentOptions[name];
  3913. } // Allow for disabling default components
  3914. // e.g. options['children']['posterImage'] = false
  3915. if (opts === false) {
  3916. return;
  3917. } // Allow options to be passed as a simple boolean if no configuration
  3918. // is necessary.
  3919. if (opts === true) {
  3920. opts = {};
  3921. } // We also want to pass the original player options
  3922. // to each component as well so they don't need to
  3923. // reach back into the player for options later.
  3924. opts.playerOptions = _this2.options_.playerOptions; // Create and add the child component.
  3925. // Add a direct reference to the child by name on the parent instance.
  3926. // If two of the same component are used, different names should be supplied
  3927. // for each
  3928. var newChild = _this2.addChild(name, opts);
  3929. if (newChild) {
  3930. _this2[name] = newChild;
  3931. }
  3932. }; // Allow for an array of children details to passed in the options
  3933. var workingChildren;
  3934. var Tech = Component.getComponent('Tech');
  3935. if (Array.isArray(children)) {
  3936. workingChildren = children;
  3937. } else {
  3938. workingChildren = Object.keys(children);
  3939. }
  3940. workingChildren // children that are in this.options_ but also in workingChildren would
  3941. // give us extra children we do not want. So, we want to filter them out.
  3942. .concat(Object.keys(this.options_).filter(function (child) {
  3943. return !workingChildren.some(function (wchild) {
  3944. if (typeof wchild === 'string') {
  3945. return child === wchild;
  3946. }
  3947. return child === wchild.name;
  3948. });
  3949. })).map(function (child) {
  3950. var name;
  3951. var opts;
  3952. if (typeof child === 'string') {
  3953. name = child;
  3954. opts = children[name] || _this2.options_[name] || {};
  3955. } else {
  3956. name = child.name;
  3957. opts = child;
  3958. }
  3959. return {
  3960. name: name,
  3961. opts: opts
  3962. };
  3963. }).filter(function (child) {
  3964. // we have to make sure that child.name isn't in the techOrder since
  3965. // techs are registerd as Components but can't aren't compatible
  3966. // See https://github.com/videojs/video.js/issues/2772
  3967. var c = Component.getComponent(child.opts.componentClass || toTitleCase(child.name));
  3968. return c && !Tech.isTech(c);
  3969. }).forEach(handleAdd);
  3970. }
  3971. }
  3972. /**
  3973. * Builds the default DOM class name. Should be overriden by sub-components.
  3974. *
  3975. * @return {string}
  3976. * The DOM class name for this object.
  3977. *
  3978. * @abstract
  3979. */
  3980. ;
  3981. _proto.buildCSSClass = function buildCSSClass() {
  3982. // Child classes can include a function that does:
  3983. // return 'CLASS NAME' + this._super();
  3984. return '';
  3985. }
  3986. /**
  3987. * Bind a listener to the component's ready state.
  3988. * Different from event listeners in that if the ready event has already happened
  3989. * it will trigger the function immediately.
  3990. *
  3991. * @return {Component}
  3992. * Returns itself; method can be chained.
  3993. */
  3994. ;
  3995. _proto.ready = function ready(fn, sync) {
  3996. if (sync === void 0) {
  3997. sync = false;
  3998. }
  3999. if (!fn) {
  4000. return;
  4001. }
  4002. if (!this.isReady_) {
  4003. this.readyQueue_ = this.readyQueue_ || [];
  4004. this.readyQueue_.push(fn);
  4005. return;
  4006. }
  4007. if (sync) {
  4008. fn.call(this);
  4009. } else {
  4010. // Call the function asynchronously by default for consistency
  4011. this.setTimeout(fn, 1);
  4012. }
  4013. }
  4014. /**
  4015. * Trigger all the ready listeners for this `Component`.
  4016. *
  4017. * @fires Component#ready
  4018. */
  4019. ;
  4020. _proto.triggerReady = function triggerReady() {
  4021. this.isReady_ = true; // Ensure ready is triggered asynchronously
  4022. this.setTimeout(function () {
  4023. var readyQueue = this.readyQueue_; // Reset Ready Queue
  4024. this.readyQueue_ = [];
  4025. if (readyQueue && readyQueue.length > 0) {
  4026. readyQueue.forEach(function (fn) {
  4027. fn.call(this);
  4028. }, this);
  4029. } // Allow for using event listeners also
  4030. /**
  4031. * Triggered when a `Component` is ready.
  4032. *
  4033. * @event Component#ready
  4034. * @type {EventTarget~Event}
  4035. */
  4036. this.trigger('ready');
  4037. }, 1);
  4038. }
  4039. /**
  4040. * Find a single DOM element matching a `selector`. This can be within the `Component`s
  4041. * `contentEl()` or another custom context.
  4042. *
  4043. * @param {string} selector
  4044. * A valid CSS selector, which will be passed to `querySelector`.
  4045. *
  4046. * @param {Element|string} [context=this.contentEl()]
  4047. * A DOM element within which to query. Can also be a selector string in
  4048. * which case the first matching element will get used as context. If
  4049. * missing `this.contentEl()` gets used. If `this.contentEl()` returns
  4050. * nothing it falls back to `document`.
  4051. *
  4052. * @return {Element|null}
  4053. * the dom element that was found, or null
  4054. *
  4055. * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors)
  4056. */
  4057. ;
  4058. _proto.$ = function $$1(selector, context) {
  4059. return $(selector, context || this.contentEl());
  4060. }
  4061. /**
  4062. * Finds all DOM element matching a `selector`. This can be within the `Component`s
  4063. * `contentEl()` or another custom context.
  4064. *
  4065. * @param {string} selector
  4066. * A valid CSS selector, which will be passed to `querySelectorAll`.
  4067. *
  4068. * @param {Element|string} [context=this.contentEl()]
  4069. * A DOM element within which to query. Can also be a selector string in
  4070. * which case the first matching element will get used as context. If
  4071. * missing `this.contentEl()` gets used. If `this.contentEl()` returns
  4072. * nothing it falls back to `document`.
  4073. *
  4074. * @return {NodeList}
  4075. * a list of dom elements that were found
  4076. *
  4077. * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors)
  4078. */
  4079. ;
  4080. _proto.$$ = function $$$1(selector, context) {
  4081. return $$(selector, context || this.contentEl());
  4082. }
  4083. /**
  4084. * Check if a component's element has a CSS class name.
  4085. *
  4086. * @param {string} classToCheck
  4087. * CSS class name to check.
  4088. *
  4089. * @return {boolean}
  4090. * - True if the `Component` has the class.
  4091. * - False if the `Component` does not have the class`
  4092. */
  4093. ;
  4094. _proto.hasClass = function hasClass$1(classToCheck) {
  4095. return hasClass(this.el_, classToCheck);
  4096. }
  4097. /**
  4098. * Add a CSS class name to the `Component`s element.
  4099. *
  4100. * @param {string} classToAdd
  4101. * CSS class name to add
  4102. */
  4103. ;
  4104. _proto.addClass = function addClass$1(classToAdd) {
  4105. addClass(this.el_, classToAdd);
  4106. }
  4107. /**
  4108. * Remove a CSS class name from the `Component`s element.
  4109. *
  4110. * @param {string} classToRemove
  4111. * CSS class name to remove
  4112. */
  4113. ;
  4114. _proto.removeClass = function removeClass$1(classToRemove) {
  4115. removeClass(this.el_, classToRemove);
  4116. }
  4117. /**
  4118. * Add or remove a CSS class name from the component's element.
  4119. * - `classToToggle` gets added when {@link Component#hasClass} would return false.
  4120. * - `classToToggle` gets removed when {@link Component#hasClass} would return true.
  4121. *
  4122. * @param {string} classToToggle
  4123. * The class to add or remove based on (@link Component#hasClass}
  4124. *
  4125. * @param {boolean|Dom~predicate} [predicate]
  4126. * An {@link Dom~predicate} function or a boolean
  4127. */
  4128. ;
  4129. _proto.toggleClass = function toggleClass$1(classToToggle, predicate) {
  4130. toggleClass(this.el_, classToToggle, predicate);
  4131. }
  4132. /**
  4133. * Show the `Component`s element if it is hidden by removing the
  4134. * 'vjs-hidden' class name from it.
  4135. */
  4136. ;
  4137. _proto.show = function show() {
  4138. this.removeClass('vjs-hidden');
  4139. }
  4140. /**
  4141. * Hide the `Component`s element if it is currently showing by adding the
  4142. * 'vjs-hidden` class name to it.
  4143. */
  4144. ;
  4145. _proto.hide = function hide() {
  4146. this.addClass('vjs-hidden');
  4147. }
  4148. /**
  4149. * Lock a `Component`s element in its visible state by adding the 'vjs-lock-showing'
  4150. * class name to it. Used during fadeIn/fadeOut.
  4151. *
  4152. * @private
  4153. */
  4154. ;
  4155. _proto.lockShowing = function lockShowing() {
  4156. this.addClass('vjs-lock-showing');
  4157. }
  4158. /**
  4159. * Unlock a `Component`s element from its visible state by removing the 'vjs-lock-showing'
  4160. * class name from it. Used during fadeIn/fadeOut.
  4161. *
  4162. * @private
  4163. */
  4164. ;
  4165. _proto.unlockShowing = function unlockShowing() {
  4166. this.removeClass('vjs-lock-showing');
  4167. }
  4168. /**
  4169. * Get the value of an attribute on the `Component`s element.
  4170. *
  4171. * @param {string} attribute
  4172. * Name of the attribute to get the value from.
  4173. *
  4174. * @return {string|null}
  4175. * - The value of the attribute that was asked for.
  4176. * - Can be an empty string on some browsers if the attribute does not exist
  4177. * or has no value
  4178. * - Most browsers will return null if the attibute does not exist or has
  4179. * no value.
  4180. *
  4181. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute}
  4182. */
  4183. ;
  4184. _proto.getAttribute = function getAttribute$1(attribute) {
  4185. return getAttribute(this.el_, attribute);
  4186. }
  4187. /**
  4188. * Set the value of an attribute on the `Component`'s element
  4189. *
  4190. * @param {string} attribute
  4191. * Name of the attribute to set.
  4192. *
  4193. * @param {string} value
  4194. * Value to set the attribute to.
  4195. *
  4196. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute}
  4197. */
  4198. ;
  4199. _proto.setAttribute = function setAttribute$1(attribute, value) {
  4200. setAttribute(this.el_, attribute, value);
  4201. }
  4202. /**
  4203. * Remove an attribute from the `Component`s element.
  4204. *
  4205. * @param {string} attribute
  4206. * Name of the attribute to remove.
  4207. *
  4208. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute}
  4209. */
  4210. ;
  4211. _proto.removeAttribute = function removeAttribute$1(attribute) {
  4212. removeAttribute(this.el_, attribute);
  4213. }
  4214. /**
  4215. * Get or set the width of the component based upon the CSS styles.
  4216. * See {@link Component#dimension} for more detailed information.
  4217. *
  4218. * @param {number|string} [num]
  4219. * The width that you want to set postfixed with '%', 'px' or nothing.
  4220. *
  4221. * @param {boolean} [skipListeners]
  4222. * Skip the componentresize event trigger
  4223. *
  4224. * @return {number|string}
  4225. * The width when getting, zero if there is no width. Can be a string
  4226. * postpixed with '%' or 'px'.
  4227. */
  4228. ;
  4229. _proto.width = function width(num, skipListeners) {
  4230. return this.dimension('width', num, skipListeners);
  4231. }
  4232. /**
  4233. * Get or set the height of the component based upon the CSS styles.
  4234. * See {@link Component#dimension} for more detailed information.
  4235. *
  4236. * @param {number|string} [num]
  4237. * The height that you want to set postfixed with '%', 'px' or nothing.
  4238. *
  4239. * @param {boolean} [skipListeners]
  4240. * Skip the componentresize event trigger
  4241. *
  4242. * @return {number|string}
  4243. * The width when getting, zero if there is no width. Can be a string
  4244. * postpixed with '%' or 'px'.
  4245. */
  4246. ;
  4247. _proto.height = function height(num, skipListeners) {
  4248. return this.dimension('height', num, skipListeners);
  4249. }
  4250. /**
  4251. * Set both the width and height of the `Component` element at the same time.
  4252. *
  4253. * @param {number|string} width
  4254. * Width to set the `Component`s element to.
  4255. *
  4256. * @param {number|string} height
  4257. * Height to set the `Component`s element to.
  4258. */
  4259. ;
  4260. _proto.dimensions = function dimensions(width, height) {
  4261. // Skip componentresize listeners on width for optimization
  4262. this.width(width, true);
  4263. this.height(height);
  4264. }
  4265. /**
  4266. * Get or set width or height of the `Component` element. This is the shared code
  4267. * for the {@link Component#width} and {@link Component#height}.
  4268. *
  4269. * Things to know:
  4270. * - If the width or height in an number this will return the number postfixed with 'px'.
  4271. * - If the width/height is a percent this will return the percent postfixed with '%'
  4272. * - Hidden elements have a width of 0 with `window.getComputedStyle`. This function
  4273. * defaults to the `Component`s `style.width` and falls back to `window.getComputedStyle`.
  4274. * See [this]{@link http://www.foliotek.com/devblog/getting-the-width-of-a-hidden-element-with-jquery-using-width/}
  4275. * for more information
  4276. * - If you want the computed style of the component, use {@link Component#currentWidth}
  4277. * and {@link {Component#currentHeight}
  4278. *
  4279. * @fires Component#componentresize
  4280. *
  4281. * @param {string} widthOrHeight
  4282. 8 'width' or 'height'
  4283. *
  4284. * @param {number|string} [num]
  4285. 8 New dimension
  4286. *
  4287. * @param {boolean} [skipListeners]
  4288. * Skip componentresize event trigger
  4289. *
  4290. * @return {number}
  4291. * The dimension when getting or 0 if unset
  4292. */
  4293. ;
  4294. _proto.dimension = function dimension(widthOrHeight, num, skipListeners) {
  4295. if (num !== undefined) {
  4296. // Set to zero if null or literally NaN (NaN !== NaN)
  4297. if (num === null || num !== num) {
  4298. num = 0;
  4299. } // Check if using css width/height (% or px) and adjust
  4300. if (('' + num).indexOf('%') !== -1 || ('' + num).indexOf('px') !== -1) {
  4301. this.el_.style[widthOrHeight] = num;
  4302. } else if (num === 'auto') {
  4303. this.el_.style[widthOrHeight] = '';
  4304. } else {
  4305. this.el_.style[widthOrHeight] = num + 'px';
  4306. } // skipListeners allows us to avoid triggering the resize event when setting both width and height
  4307. if (!skipListeners) {
  4308. /**
  4309. * Triggered when a component is resized.
  4310. *
  4311. * @event Component#componentresize
  4312. * @type {EventTarget~Event}
  4313. */
  4314. this.trigger('componentresize');
  4315. }
  4316. return;
  4317. } // Not setting a value, so getting it
  4318. // Make sure element exists
  4319. if (!this.el_) {
  4320. return 0;
  4321. } // Get dimension value from style
  4322. var val = this.el_.style[widthOrHeight];
  4323. var pxIndex = val.indexOf('px');
  4324. if (pxIndex !== -1) {
  4325. // Return the pixel value with no 'px'
  4326. return parseInt(val.slice(0, pxIndex), 10);
  4327. } // No px so using % or no style was set, so falling back to offsetWidth/height
  4328. // If component has display:none, offset will return 0
  4329. // TODO: handle display:none and no dimension style using px
  4330. return parseInt(this.el_['offset' + toTitleCase(widthOrHeight)], 10);
  4331. }
  4332. /**
  4333. * Get the computed width or the height of the component's element.
  4334. *
  4335. * Uses `window.getComputedStyle`.
  4336. *
  4337. * @param {string} widthOrHeight
  4338. * A string containing 'width' or 'height'. Whichever one you want to get.
  4339. *
  4340. * @return {number}
  4341. * The dimension that gets asked for or 0 if nothing was set
  4342. * for that dimension.
  4343. */
  4344. ;
  4345. _proto.currentDimension = function currentDimension(widthOrHeight) {
  4346. var computedWidthOrHeight = 0;
  4347. if (widthOrHeight !== 'width' && widthOrHeight !== 'height') {
  4348. throw new Error('currentDimension only accepts width or height value');
  4349. }
  4350. computedWidthOrHeight = computedStyle(this.el_, widthOrHeight); // remove 'px' from variable and parse as integer
  4351. computedWidthOrHeight = parseFloat(computedWidthOrHeight); // if the computed value is still 0, it's possible that the browser is lying
  4352. // and we want to check the offset values.
  4353. // This code also runs wherever getComputedStyle doesn't exist.
  4354. if (computedWidthOrHeight === 0 || isNaN(computedWidthOrHeight)) {
  4355. var rule = "offset" + toTitleCase(widthOrHeight);
  4356. computedWidthOrHeight = this.el_[rule];
  4357. }
  4358. return computedWidthOrHeight;
  4359. }
  4360. /**
  4361. * An object that contains width and height values of the `Component`s
  4362. * computed style. Uses `window.getComputedStyle`.
  4363. *
  4364. * @typedef {Object} Component~DimensionObject
  4365. *
  4366. * @property {number} width
  4367. * The width of the `Component`s computed style.
  4368. *
  4369. * @property {number} height
  4370. * The height of the `Component`s computed style.
  4371. */
  4372. /**
  4373. * Get an object that contains computed width and height values of the
  4374. * component's element.
  4375. *
  4376. * Uses `window.getComputedStyle`.
  4377. *
  4378. * @return {Component~DimensionObject}
  4379. * The computed dimensions of the component's element.
  4380. */
  4381. ;
  4382. _proto.currentDimensions = function currentDimensions() {
  4383. return {
  4384. width: this.currentDimension('width'),
  4385. height: this.currentDimension('height')
  4386. };
  4387. }
  4388. /**
  4389. * Get the computed width of the component's element.
  4390. *
  4391. * Uses `window.getComputedStyle`.
  4392. *
  4393. * @return {number}
  4394. * The computed width of the component's element.
  4395. */
  4396. ;
  4397. _proto.currentWidth = function currentWidth() {
  4398. return this.currentDimension('width');
  4399. }
  4400. /**
  4401. * Get the computed height of the component's element.
  4402. *
  4403. * Uses `window.getComputedStyle`.
  4404. *
  4405. * @return {number}
  4406. * The computed height of the component's element.
  4407. */
  4408. ;
  4409. _proto.currentHeight = function currentHeight() {
  4410. return this.currentDimension('height');
  4411. }
  4412. /**
  4413. * Set the focus to this component
  4414. */
  4415. ;
  4416. _proto.focus = function focus() {
  4417. this.el_.focus();
  4418. }
  4419. /**
  4420. * Remove the focus from this component
  4421. */
  4422. ;
  4423. _proto.blur = function blur() {
  4424. this.el_.blur();
  4425. }
  4426. /**
  4427. * When this Component receives a `keydown` event which it does not process,
  4428. * it passes the event to the Player for handling.
  4429. *
  4430. * @param {EventTarget~Event} event
  4431. * The `keydown` event that caused this function to be called.
  4432. */
  4433. ;
  4434. _proto.handleKeyDown = function handleKeyDown(event) {
  4435. if (this.player_) {
  4436. // We only stop propagation here because we want unhandled events to fall
  4437. // back to the browser. Exclude Tab for focus trapping.
  4438. if (!keycode.isEventKey(event, 'Tab')) {
  4439. event.stopPropagation();
  4440. }
  4441. this.player_.handleKeyDown(event);
  4442. }
  4443. }
  4444. /**
  4445. * Many components used to have a `handleKeyPress` method, which was poorly
  4446. * named because it listened to a `keydown` event. This method name now
  4447. * delegates to `handleKeyDown`. This means anyone calling `handleKeyPress`
  4448. * will not see their method calls stop working.
  4449. *
  4450. * @param {EventTarget~Event} event
  4451. * The event that caused this function to be called.
  4452. */
  4453. ;
  4454. _proto.handleKeyPress = function handleKeyPress(event) {
  4455. this.handleKeyDown(event);
  4456. }
  4457. /**
  4458. * Emit a 'tap' events when touch event support gets detected. This gets used to
  4459. * support toggling the controls through a tap on the video. They get enabled
  4460. * because every sub-component would have extra overhead otherwise.
  4461. *
  4462. * @private
  4463. * @fires Component#tap
  4464. * @listens Component#touchstart
  4465. * @listens Component#touchmove
  4466. * @listens Component#touchleave
  4467. * @listens Component#touchcancel
  4468. * @listens Component#touchend
  4469. */
  4470. ;
  4471. _proto.emitTapEvents = function emitTapEvents() {
  4472. // Track the start time so we can determine how long the touch lasted
  4473. var touchStart = 0;
  4474. var firstTouch = null; // Maximum movement allowed during a touch event to still be considered a tap
  4475. // Other popular libs use anywhere from 2 (hammer.js) to 15,
  4476. // so 10 seems like a nice, round number.
  4477. var tapMovementThreshold = 10; // The maximum length a touch can be while still being considered a tap
  4478. var touchTimeThreshold = 200;
  4479. var couldBeTap;
  4480. this.on('touchstart', function (event) {
  4481. // If more than one finger, don't consider treating this as a click
  4482. if (event.touches.length === 1) {
  4483. // Copy pageX/pageY from the object
  4484. firstTouch = {
  4485. pageX: event.touches[0].pageX,
  4486. pageY: event.touches[0].pageY
  4487. }; // Record start time so we can detect a tap vs. "touch and hold"
  4488. touchStart = window.performance.now(); // Reset couldBeTap tracking
  4489. couldBeTap = true;
  4490. }
  4491. });
  4492. this.on('touchmove', function (event) {
  4493. // If more than one finger, don't consider treating this as a click
  4494. if (event.touches.length > 1) {
  4495. couldBeTap = false;
  4496. } else if (firstTouch) {
  4497. // Some devices will throw touchmoves for all but the slightest of taps.
  4498. // So, if we moved only a small distance, this could still be a tap
  4499. var xdiff = event.touches[0].pageX - firstTouch.pageX;
  4500. var ydiff = event.touches[0].pageY - firstTouch.pageY;
  4501. var touchDistance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
  4502. if (touchDistance > tapMovementThreshold) {
  4503. couldBeTap = false;
  4504. }
  4505. }
  4506. });
  4507. var noTap = function noTap() {
  4508. couldBeTap = false;
  4509. }; // TODO: Listen to the original target. http://youtu.be/DujfpXOKUp8?t=13m8s
  4510. this.on('touchleave', noTap);
  4511. this.on('touchcancel', noTap); // When the touch ends, measure how long it took and trigger the appropriate
  4512. // event
  4513. this.on('touchend', function (event) {
  4514. firstTouch = null; // Proceed only if the touchmove/leave/cancel event didn't happen
  4515. if (couldBeTap === true) {
  4516. // Measure how long the touch lasted
  4517. var touchTime = window.performance.now() - touchStart; // Make sure the touch was less than the threshold to be considered a tap
  4518. if (touchTime < touchTimeThreshold) {
  4519. // Don't let browser turn this into a click
  4520. event.preventDefault();
  4521. /**
  4522. * Triggered when a `Component` is tapped.
  4523. *
  4524. * @event Component#tap
  4525. * @type {EventTarget~Event}
  4526. */
  4527. this.trigger('tap'); // It may be good to copy the touchend event object and change the
  4528. // type to tap, if the other event properties aren't exact after
  4529. // Events.fixEvent runs (e.g. event.target)
  4530. }
  4531. }
  4532. });
  4533. }
  4534. /**
  4535. * This function reports user activity whenever touch events happen. This can get
  4536. * turned off by any sub-components that wants touch events to act another way.
  4537. *
  4538. * Report user touch activity when touch events occur. User activity gets used to
  4539. * determine when controls should show/hide. It is simple when it comes to mouse
  4540. * events, because any mouse event should show the controls. So we capture mouse
  4541. * events that bubble up to the player and report activity when that happens.
  4542. * With touch events it isn't as easy as `touchstart` and `touchend` toggle player
  4543. * controls. So touch events can't help us at the player level either.
  4544. *
  4545. * User activity gets checked asynchronously. So what could happen is a tap event
  4546. * on the video turns the controls off. Then the `touchend` event bubbles up to
  4547. * the player. Which, if it reported user activity, would turn the controls right
  4548. * back on. We also don't want to completely block touch events from bubbling up.
  4549. * Furthermore a `touchmove` event and anything other than a tap, should not turn
  4550. * controls back on.
  4551. *
  4552. * @listens Component#touchstart
  4553. * @listens Component#touchmove
  4554. * @listens Component#touchend
  4555. * @listens Component#touchcancel
  4556. */
  4557. ;
  4558. _proto.enableTouchActivity = function enableTouchActivity() {
  4559. // Don't continue if the root player doesn't support reporting user activity
  4560. if (!this.player() || !this.player().reportUserActivity) {
  4561. return;
  4562. } // listener for reporting that the user is active
  4563. var report = bind(this.player(), this.player().reportUserActivity);
  4564. var touchHolding;
  4565. this.on('touchstart', function () {
  4566. report(); // For as long as the they are touching the device or have their mouse down,
  4567. // we consider them active even if they're not moving their finger or mouse.
  4568. // So we want to continue to update that they are active
  4569. this.clearInterval(touchHolding); // report at the same interval as activityCheck
  4570. touchHolding = this.setInterval(report, 250);
  4571. });
  4572. var touchEnd = function touchEnd(event) {
  4573. report(); // stop the interval that maintains activity if the touch is holding
  4574. this.clearInterval(touchHolding);
  4575. };
  4576. this.on('touchmove', report);
  4577. this.on('touchend', touchEnd);
  4578. this.on('touchcancel', touchEnd);
  4579. }
  4580. /**
  4581. * A callback that has no parameters and is bound into `Component`s context.
  4582. *
  4583. * @callback Component~GenericCallback
  4584. * @this Component
  4585. */
  4586. /**
  4587. * Creates a function that runs after an `x` millisecond timeout. This function is a
  4588. * wrapper around `window.setTimeout`. There are a few reasons to use this one
  4589. * instead though:
  4590. * 1. It gets cleared via {@link Component#clearTimeout} when
  4591. * {@link Component#dispose} gets called.
  4592. * 2. The function callback will gets turned into a {@link Component~GenericCallback}
  4593. *
  4594. * > Note: You can't use `window.clearTimeout` on the id returned by this function. This
  4595. * will cause its dispose listener not to get cleaned up! Please use
  4596. * {@link Component#clearTimeout} or {@link Component#dispose} instead.
  4597. *
  4598. * @param {Component~GenericCallback} fn
  4599. * The function that will be run after `timeout`.
  4600. *
  4601. * @param {number} timeout
  4602. * Timeout in milliseconds to delay before executing the specified function.
  4603. *
  4604. * @return {number}
  4605. * Returns a timeout ID that gets used to identify the timeout. It can also
  4606. * get used in {@link Component#clearTimeout} to clear the timeout that
  4607. * was set.
  4608. *
  4609. * @listens Component#dispose
  4610. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout}
  4611. */
  4612. ;
  4613. _proto.setTimeout = function setTimeout(fn, timeout) {
  4614. var _this3 = this;
  4615. // declare as variables so they are properly available in timeout function
  4616. // eslint-disable-next-line
  4617. var timeoutId;
  4618. fn = bind(this, fn);
  4619. this.clearTimersOnDispose_();
  4620. timeoutId = window.setTimeout(function () {
  4621. if (_this3.setTimeoutIds_.has(timeoutId)) {
  4622. _this3.setTimeoutIds_["delete"](timeoutId);
  4623. }
  4624. fn();
  4625. }, timeout);
  4626. this.setTimeoutIds_.add(timeoutId);
  4627. return timeoutId;
  4628. }
  4629. /**
  4630. * Clears a timeout that gets created via `window.setTimeout` or
  4631. * {@link Component#setTimeout}. If you set a timeout via {@link Component#setTimeout}
  4632. * use this function instead of `window.clearTimout`. If you don't your dispose
  4633. * listener will not get cleaned up until {@link Component#dispose}!
  4634. *
  4635. * @param {number} timeoutId
  4636. * The id of the timeout to clear. The return value of
  4637. * {@link Component#setTimeout} or `window.setTimeout`.
  4638. *
  4639. * @return {number}
  4640. * Returns the timeout id that was cleared.
  4641. *
  4642. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearTimeout}
  4643. */
  4644. ;
  4645. _proto.clearTimeout = function clearTimeout(timeoutId) {
  4646. if (this.setTimeoutIds_.has(timeoutId)) {
  4647. this.setTimeoutIds_["delete"](timeoutId);
  4648. window.clearTimeout(timeoutId);
  4649. }
  4650. return timeoutId;
  4651. }
  4652. /**
  4653. * Creates a function that gets run every `x` milliseconds. This function is a wrapper
  4654. * around `window.setInterval`. There are a few reasons to use this one instead though.
  4655. * 1. It gets cleared via {@link Component#clearInterval} when
  4656. * {@link Component#dispose} gets called.
  4657. * 2. The function callback will be a {@link Component~GenericCallback}
  4658. *
  4659. * @param {Component~GenericCallback} fn
  4660. * The function to run every `x` seconds.
  4661. *
  4662. * @param {number} interval
  4663. * Execute the specified function every `x` milliseconds.
  4664. *
  4665. * @return {number}
  4666. * Returns an id that can be used to identify the interval. It can also be be used in
  4667. * {@link Component#clearInterval} to clear the interval.
  4668. *
  4669. * @listens Component#dispose
  4670. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval}
  4671. */
  4672. ;
  4673. _proto.setInterval = function setInterval(fn, interval) {
  4674. fn = bind(this, fn);
  4675. this.clearTimersOnDispose_();
  4676. var intervalId = window.setInterval(fn, interval);
  4677. this.setIntervalIds_.add(intervalId);
  4678. return intervalId;
  4679. }
  4680. /**
  4681. * Clears an interval that gets created via `window.setInterval` or
  4682. * {@link Component#setInterval}. If you set an inteval via {@link Component#setInterval}
  4683. * use this function instead of `window.clearInterval`. If you don't your dispose
  4684. * listener will not get cleaned up until {@link Component#dispose}!
  4685. *
  4686. * @param {number} intervalId
  4687. * The id of the interval to clear. The return value of
  4688. * {@link Component#setInterval} or `window.setInterval`.
  4689. *
  4690. * @return {number}
  4691. * Returns the interval id that was cleared.
  4692. *
  4693. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval}
  4694. */
  4695. ;
  4696. _proto.clearInterval = function clearInterval(intervalId) {
  4697. if (this.setIntervalIds_.has(intervalId)) {
  4698. this.setIntervalIds_["delete"](intervalId);
  4699. window.clearInterval(intervalId);
  4700. }
  4701. return intervalId;
  4702. }
  4703. /**
  4704. * Queues up a callback to be passed to requestAnimationFrame (rAF), but
  4705. * with a few extra bonuses:
  4706. *
  4707. * - Supports browsers that do not support rAF by falling back to
  4708. * {@link Component#setTimeout}.
  4709. *
  4710. * - The callback is turned into a {@link Component~GenericCallback} (i.e.
  4711. * bound to the component).
  4712. *
  4713. * - Automatic cancellation of the rAF callback is handled if the component
  4714. * is disposed before it is called.
  4715. *
  4716. * @param {Component~GenericCallback} fn
  4717. * A function that will be bound to this component and executed just
  4718. * before the browser's next repaint.
  4719. *
  4720. * @return {number}
  4721. * Returns an rAF ID that gets used to identify the timeout. It can
  4722. * also be used in {@link Component#cancelAnimationFrame} to cancel
  4723. * the animation frame callback.
  4724. *
  4725. * @listens Component#dispose
  4726. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame}
  4727. */
  4728. ;
  4729. _proto.requestAnimationFrame = function requestAnimationFrame(fn) {
  4730. var _this4 = this;
  4731. // Fall back to using a timer.
  4732. if (!this.supportsRaf_) {
  4733. return this.setTimeout(fn, 1000 / 60);
  4734. }
  4735. this.clearTimersOnDispose_(); // declare as variables so they are properly available in rAF function
  4736. // eslint-disable-next-line
  4737. var id;
  4738. fn = bind(this, fn);
  4739. id = window.requestAnimationFrame(function () {
  4740. if (_this4.rafIds_.has(id)) {
  4741. _this4.rafIds_["delete"](id);
  4742. }
  4743. fn();
  4744. });
  4745. this.rafIds_.add(id);
  4746. return id;
  4747. }
  4748. /**
  4749. * Request an animation frame, but only one named animation
  4750. * frame will be queued. Another will never be added until
  4751. * the previous one finishes.
  4752. *
  4753. * @param {string} name
  4754. * The name to give this requestAnimationFrame
  4755. *
  4756. * @param {Component~GenericCallback} fn
  4757. * A function that will be bound to this component and executed just
  4758. * before the browser's next repaint.
  4759. */
  4760. ;
  4761. _proto.requestNamedAnimationFrame = function requestNamedAnimationFrame(name, fn) {
  4762. var _this5 = this;
  4763. if (this.namedRafs_.has(name)) {
  4764. return;
  4765. }
  4766. this.clearTimersOnDispose_();
  4767. fn = bind(this, fn);
  4768. var id = this.requestAnimationFrame(function () {
  4769. fn();
  4770. if (_this5.namedRafs_.has(name)) {
  4771. _this5.namedRafs_["delete"](name);
  4772. }
  4773. });
  4774. this.namedRafs_.set(name, id);
  4775. return name;
  4776. }
  4777. /**
  4778. * Cancels a current named animation frame if it exists.
  4779. *
  4780. * @param {string} name
  4781. * The name of the requestAnimationFrame to cancel.
  4782. */
  4783. ;
  4784. _proto.cancelNamedAnimationFrame = function cancelNamedAnimationFrame(name) {
  4785. if (!this.namedRafs_.has(name)) {
  4786. return;
  4787. }
  4788. this.cancelAnimationFrame(this.namedRafs_.get(name));
  4789. this.namedRafs_["delete"](name);
  4790. }
  4791. /**
  4792. * Cancels a queued callback passed to {@link Component#requestAnimationFrame}
  4793. * (rAF).
  4794. *
  4795. * If you queue an rAF callback via {@link Component#requestAnimationFrame},
  4796. * use this function instead of `window.cancelAnimationFrame`. If you don't,
  4797. * your dispose listener will not get cleaned up until {@link Component#dispose}!
  4798. *
  4799. * @param {number} id
  4800. * The rAF ID to clear. The return value of {@link Component#requestAnimationFrame}.
  4801. *
  4802. * @return {number}
  4803. * Returns the rAF ID that was cleared.
  4804. *
  4805. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/cancelAnimationFrame}
  4806. */
  4807. ;
  4808. _proto.cancelAnimationFrame = function cancelAnimationFrame(id) {
  4809. // Fall back to using a timer.
  4810. if (!this.supportsRaf_) {
  4811. return this.clearTimeout(id);
  4812. }
  4813. if (this.rafIds_.has(id)) {
  4814. this.rafIds_["delete"](id);
  4815. window.cancelAnimationFrame(id);
  4816. }
  4817. return id;
  4818. }
  4819. /**
  4820. * A function to setup `requestAnimationFrame`, `setTimeout`,
  4821. * and `setInterval`, clearing on dispose.
  4822. *
  4823. * > Previously each timer added and removed dispose listeners on it's own.
  4824. * For better performance it was decided to batch them all, and use `Set`s
  4825. * to track outstanding timer ids.
  4826. *
  4827. * @private
  4828. */
  4829. ;
  4830. _proto.clearTimersOnDispose_ = function clearTimersOnDispose_() {
  4831. var _this6 = this;
  4832. if (this.clearingTimersOnDispose_) {
  4833. return;
  4834. }
  4835. this.clearingTimersOnDispose_ = true;
  4836. this.one('dispose', function () {
  4837. [['namedRafs_', 'cancelNamedAnimationFrame'], ['rafIds_', 'cancelAnimationFrame'], ['setTimeoutIds_', 'clearTimeout'], ['setIntervalIds_', 'clearInterval']].forEach(function (_ref) {
  4838. var idName = _ref[0],
  4839. cancelName = _ref[1];
  4840. // for a `Set` key will actually be the value again
  4841. // so forEach((val, val) =>` but for maps we want to use
  4842. // the key.
  4843. _this6[idName].forEach(function (val, key) {
  4844. return _this6[cancelName](key);
  4845. });
  4846. });
  4847. _this6.clearingTimersOnDispose_ = false;
  4848. });
  4849. }
  4850. /**
  4851. * Register a `Component` with `videojs` given the name and the component.
  4852. *
  4853. * > NOTE: {@link Tech}s should not be registered as a `Component`. {@link Tech}s
  4854. * should be registered using {@link Tech.registerTech} or
  4855. * {@link videojs:videojs.registerTech}.
  4856. *
  4857. * > NOTE: This function can also be seen on videojs as
  4858. * {@link videojs:videojs.registerComponent}.
  4859. *
  4860. * @param {string} name
  4861. * The name of the `Component` to register.
  4862. *
  4863. * @param {Component} ComponentToRegister
  4864. * The `Component` class to register.
  4865. *
  4866. * @return {Component}
  4867. * The `Component` that was registered.
  4868. */
  4869. ;
  4870. Component.registerComponent = function registerComponent(name, ComponentToRegister) {
  4871. if (typeof name !== 'string' || !name) {
  4872. throw new Error("Illegal component name, \"" + name + "\"; must be a non-empty string.");
  4873. }
  4874. var Tech = Component.getComponent('Tech'); // We need to make sure this check is only done if Tech has been registered.
  4875. var isTech = Tech && Tech.isTech(ComponentToRegister);
  4876. var isComp = Component === ComponentToRegister || Component.prototype.isPrototypeOf(ComponentToRegister.prototype);
  4877. if (isTech || !isComp) {
  4878. var reason;
  4879. if (isTech) {
  4880. reason = 'techs must be registered using Tech.registerTech()';
  4881. } else {
  4882. reason = 'must be a Component subclass';
  4883. }
  4884. throw new Error("Illegal component, \"" + name + "\"; " + reason + ".");
  4885. }
  4886. name = toTitleCase(name);
  4887. if (!Component.components_) {
  4888. Component.components_ = {};
  4889. }
  4890. var Player = Component.getComponent('Player');
  4891. if (name === 'Player' && Player && Player.players) {
  4892. var players = Player.players;
  4893. var playerNames = Object.keys(players); // If we have players that were disposed, then their name will still be
  4894. // in Players.players. So, we must loop through and verify that the value
  4895. // for each item is not null. This allows registration of the Player component
  4896. // after all players have been disposed or before any were created.
  4897. if (players && playerNames.length > 0 && playerNames.map(function (pname) {
  4898. return players[pname];
  4899. }).every(Boolean)) {
  4900. throw new Error('Can not register Player component after player has been created.');
  4901. }
  4902. }
  4903. Component.components_[name] = ComponentToRegister;
  4904. Component.components_[toLowerCase(name)] = ComponentToRegister;
  4905. return ComponentToRegister;
  4906. }
  4907. /**
  4908. * Get a `Component` based on the name it was registered with.
  4909. *
  4910. * @param {string} name
  4911. * The Name of the component to get.
  4912. *
  4913. * @return {Component}
  4914. * The `Component` that got registered under the given name.
  4915. */
  4916. ;
  4917. Component.getComponent = function getComponent(name) {
  4918. if (!name || !Component.components_) {
  4919. return;
  4920. }
  4921. return Component.components_[name];
  4922. };
  4923. return Component;
  4924. }();
  4925. /**
  4926. * Whether or not this component supports `requestAnimationFrame`.
  4927. *
  4928. * This is exposed primarily for testing purposes.
  4929. *
  4930. * @private
  4931. * @type {Boolean}
  4932. */
  4933. Component.prototype.supportsRaf_ = typeof window.requestAnimationFrame === 'function' && typeof window.cancelAnimationFrame === 'function';
  4934. Component.registerComponent('Component', Component);
  4935. function _assertThisInitialized(self) {
  4936. if (self === void 0) {
  4937. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  4938. }
  4939. return self;
  4940. }
  4941. var assertThisInitialized = _assertThisInitialized;
  4942. function _inheritsLoose(subClass, superClass) {
  4943. subClass.prototype = Object.create(superClass.prototype);
  4944. subClass.prototype.constructor = subClass;
  4945. subClass.__proto__ = superClass;
  4946. }
  4947. var inheritsLoose = _inheritsLoose;
  4948. /**
  4949. * @file time-ranges.js
  4950. * @module time-ranges
  4951. */
  4952. /**
  4953. * Returns the time for the specified index at the start or end
  4954. * of a TimeRange object.
  4955. *
  4956. * @typedef {Function} TimeRangeIndex
  4957. *
  4958. * @param {number} [index=0]
  4959. * The range number to return the time for.
  4960. *
  4961. * @return {number}
  4962. * The time offset at the specified index.
  4963. *
  4964. * @deprecated The index argument must be provided.
  4965. * In the future, leaving it out will throw an error.
  4966. */
  4967. /**
  4968. * An object that contains ranges of time.
  4969. *
  4970. * @typedef {Object} TimeRange
  4971. *
  4972. * @property {number} length
  4973. * The number of time ranges represented by this object.
  4974. *
  4975. * @property {module:time-ranges~TimeRangeIndex} start
  4976. * Returns the time offset at which a specified time range begins.
  4977. *
  4978. * @property {module:time-ranges~TimeRangeIndex} end
  4979. * Returns the time offset at which a specified time range ends.
  4980. *
  4981. * @see https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges
  4982. */
  4983. /**
  4984. * Check if any of the time ranges are over the maximum index.
  4985. *
  4986. * @private
  4987. * @param {string} fnName
  4988. * The function name to use for logging
  4989. *
  4990. * @param {number} index
  4991. * The index to check
  4992. *
  4993. * @param {number} maxIndex
  4994. * The maximum possible index
  4995. *
  4996. * @throws {Error} if the timeRanges provided are over the maxIndex
  4997. */
  4998. function rangeCheck(fnName, index, maxIndex) {
  4999. if (typeof index !== 'number' || index < 0 || index > maxIndex) {
  5000. throw new Error("Failed to execute '" + fnName + "' on 'TimeRanges': The index provided (" + index + ") is non-numeric or out of bounds (0-" + maxIndex + ").");
  5001. }
  5002. }
  5003. /**
  5004. * Get the time for the specified index at the start or end
  5005. * of a TimeRange object.
  5006. *
  5007. * @private
  5008. * @param {string} fnName
  5009. * The function name to use for logging
  5010. *
  5011. * @param {string} valueIndex
  5012. * The property that should be used to get the time. should be
  5013. * 'start' or 'end'
  5014. *
  5015. * @param {Array} ranges
  5016. * An array of time ranges
  5017. *
  5018. * @param {Array} [rangeIndex=0]
  5019. * The index to start the search at
  5020. *
  5021. * @return {number}
  5022. * The time that offset at the specified index.
  5023. *
  5024. * @deprecated rangeIndex must be set to a value, in the future this will throw an error.
  5025. * @throws {Error} if rangeIndex is more than the length of ranges
  5026. */
  5027. function getRange(fnName, valueIndex, ranges, rangeIndex) {
  5028. rangeCheck(fnName, rangeIndex, ranges.length - 1);
  5029. return ranges[rangeIndex][valueIndex];
  5030. }
  5031. /**
  5032. * Create a time range object given ranges of time.
  5033. *
  5034. * @private
  5035. * @param {Array} [ranges]
  5036. * An array of time ranges.
  5037. */
  5038. function createTimeRangesObj(ranges) {
  5039. var timeRangesObj;
  5040. if (ranges === undefined || ranges.length === 0) {
  5041. timeRangesObj = {
  5042. length: 0,
  5043. start: function start() {
  5044. throw new Error('This TimeRanges object is empty');
  5045. },
  5046. end: function end() {
  5047. throw new Error('This TimeRanges object is empty');
  5048. }
  5049. };
  5050. } else {
  5051. timeRangesObj = {
  5052. length: ranges.length,
  5053. start: getRange.bind(null, 'start', 0, ranges),
  5054. end: getRange.bind(null, 'end', 1, ranges)
  5055. };
  5056. }
  5057. if (window.Symbol && window.Symbol.iterator) {
  5058. timeRangesObj[window.Symbol.iterator] = function () {
  5059. return (ranges || []).values();
  5060. };
  5061. }
  5062. return timeRangesObj;
  5063. }
  5064. /**
  5065. * Create a `TimeRange` object which mimics an
  5066. * {@link https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges|HTML5 TimeRanges instance}.
  5067. *
  5068. * @param {number|Array[]} start
  5069. * The start of a single range (a number) or an array of ranges (an
  5070. * array of arrays of two numbers each).
  5071. *
  5072. * @param {number} end
  5073. * The end of a single range. Cannot be used with the array form of
  5074. * the `start` argument.
  5075. */
  5076. function createTimeRanges(start, end) {
  5077. if (Array.isArray(start)) {
  5078. return createTimeRangesObj(start);
  5079. } else if (start === undefined || end === undefined) {
  5080. return createTimeRangesObj();
  5081. }
  5082. return createTimeRangesObj([[start, end]]);
  5083. }
  5084. /**
  5085. * @file buffer.js
  5086. * @module buffer
  5087. */
  5088. /**
  5089. * Compute the percentage of the media that has been buffered.
  5090. *
  5091. * @param {TimeRange} buffered
  5092. * The current `TimeRange` object representing buffered time ranges
  5093. *
  5094. * @param {number} duration
  5095. * Total duration of the media
  5096. *
  5097. * @return {number}
  5098. * Percent buffered of the total duration in decimal form.
  5099. */
  5100. function bufferedPercent(buffered, duration) {
  5101. var bufferedDuration = 0;
  5102. var start;
  5103. var end;
  5104. if (!duration) {
  5105. return 0;
  5106. }
  5107. if (!buffered || !buffered.length) {
  5108. buffered = createTimeRanges(0, 0);
  5109. }
  5110. for (var i = 0; i < buffered.length; i++) {
  5111. start = buffered.start(i);
  5112. end = buffered.end(i); // buffered end can be bigger than duration by a very small fraction
  5113. if (end > duration) {
  5114. end = duration;
  5115. }
  5116. bufferedDuration += end - start;
  5117. }
  5118. return bufferedDuration / duration;
  5119. }
  5120. /**
  5121. * @file media-error.js
  5122. */
  5123. /**
  5124. * A Custom `MediaError` class which mimics the standard HTML5 `MediaError` class.
  5125. *
  5126. * @param {number|string|Object|MediaError} value
  5127. * This can be of multiple types:
  5128. * - number: should be a standard error code
  5129. * - string: an error message (the code will be 0)
  5130. * - Object: arbitrary properties
  5131. * - `MediaError` (native): used to populate a video.js `MediaError` object
  5132. * - `MediaError` (video.js): will return itself if it's already a
  5133. * video.js `MediaError` object.
  5134. *
  5135. * @see [MediaError Spec]{@link https://dev.w3.org/html5/spec-author-view/video.html#mediaerror}
  5136. * @see [Encrypted MediaError Spec]{@link https://www.w3.org/TR/2013/WD-encrypted-media-20130510/#error-codes}
  5137. *
  5138. * @class MediaError
  5139. */
  5140. function MediaError(value) {
  5141. // Allow redundant calls to this constructor to avoid having `instanceof`
  5142. // checks peppered around the code.
  5143. if (value instanceof MediaError) {
  5144. return value;
  5145. }
  5146. if (typeof value === 'number') {
  5147. this.code = value;
  5148. } else if (typeof value === 'string') {
  5149. // default code is zero, so this is a custom error
  5150. this.message = value;
  5151. } else if (isObject(value)) {
  5152. // We assign the `code` property manually because native `MediaError` objects
  5153. // do not expose it as an own/enumerable property of the object.
  5154. if (typeof value.code === 'number') {
  5155. this.code = value.code;
  5156. }
  5157. assign(this, value);
  5158. }
  5159. if (!this.message) {
  5160. this.message = MediaError.defaultMessages[this.code] || '';
  5161. }
  5162. }
  5163. /**
  5164. * The error code that refers two one of the defined `MediaError` types
  5165. *
  5166. * @type {Number}
  5167. */
  5168. MediaError.prototype.code = 0;
  5169. /**
  5170. * An optional message that to show with the error. Message is not part of the HTML5
  5171. * video spec but allows for more informative custom errors.
  5172. *
  5173. * @type {String}
  5174. */
  5175. MediaError.prototype.message = '';
  5176. /**
  5177. * An optional status code that can be set by plugins to allow even more detail about
  5178. * the error. For example a plugin might provide a specific HTTP status code and an
  5179. * error message for that code. Then when the plugin gets that error this class will
  5180. * know how to display an error message for it. This allows a custom message to show
  5181. * up on the `Player` error overlay.
  5182. *
  5183. * @type {Array}
  5184. */
  5185. MediaError.prototype.status = null;
  5186. /**
  5187. * Errors indexed by the W3C standard. The order **CANNOT CHANGE**! See the
  5188. * specification listed under {@link MediaError} for more information.
  5189. *
  5190. * @enum {array}
  5191. * @readonly
  5192. * @property {string} 0 - MEDIA_ERR_CUSTOM
  5193. * @property {string} 1 - MEDIA_ERR_ABORTED
  5194. * @property {string} 2 - MEDIA_ERR_NETWORK
  5195. * @property {string} 3 - MEDIA_ERR_DECODE
  5196. * @property {string} 4 - MEDIA_ERR_SRC_NOT_SUPPORTED
  5197. * @property {string} 5 - MEDIA_ERR_ENCRYPTED
  5198. */
  5199. MediaError.errorTypes = ['MEDIA_ERR_CUSTOM', 'MEDIA_ERR_ABORTED', 'MEDIA_ERR_NETWORK', 'MEDIA_ERR_DECODE', 'MEDIA_ERR_SRC_NOT_SUPPORTED', 'MEDIA_ERR_ENCRYPTED'];
  5200. /**
  5201. * The default `MediaError` messages based on the {@link MediaError.errorTypes}.
  5202. *
  5203. * @type {Array}
  5204. * @constant
  5205. */
  5206. MediaError.defaultMessages = {
  5207. 1: 'You aborted the media playback',
  5208. 2: 'A network error caused the media download to fail part-way.',
  5209. 3: 'The media playback was aborted due to a corruption problem or because the media used features your browser did not support.',
  5210. 4: 'The media could not be loaded, either because the server or network failed or because the format is not supported.',
  5211. 5: 'The media is encrypted and we do not have the keys to decrypt it.'
  5212. }; // Add types as properties on MediaError
  5213. // e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
  5214. for (var errNum = 0; errNum < MediaError.errorTypes.length; errNum++) {
  5215. MediaError[MediaError.errorTypes[errNum]] = errNum; // values should be accessible on both the class and instance
  5216. MediaError.prototype[MediaError.errorTypes[errNum]] = errNum;
  5217. } // jsdocs for instance/static members added above
  5218. var tuple = SafeParseTuple;
  5219. function SafeParseTuple(obj, reviver) {
  5220. var json;
  5221. var error = null;
  5222. try {
  5223. json = JSON.parse(obj, reviver);
  5224. } catch (err) {
  5225. error = err;
  5226. }
  5227. return [error, json];
  5228. }
  5229. /**
  5230. * Returns whether an object is `Promise`-like (i.e. has a `then` method).
  5231. *
  5232. * @param {Object} value
  5233. * An object that may or may not be `Promise`-like.
  5234. *
  5235. * @return {boolean}
  5236. * Whether or not the object is `Promise`-like.
  5237. */
  5238. function isPromise(value) {
  5239. return value !== undefined && value !== null && typeof value.then === 'function';
  5240. }
  5241. /**
  5242. * Silence a Promise-like object.
  5243. *
  5244. * This is useful for avoiding non-harmful, but potentially confusing "uncaught
  5245. * play promise" rejection error messages.
  5246. *
  5247. * @param {Object} value
  5248. * An object that may or may not be `Promise`-like.
  5249. */
  5250. function silencePromise(value) {
  5251. if (isPromise(value)) {
  5252. value.then(null, function (e) {});
  5253. }
  5254. }
  5255. /**
  5256. * @file text-track-list-converter.js Utilities for capturing text track state and
  5257. * re-creating tracks based on a capture.
  5258. *
  5259. * @module text-track-list-converter
  5260. */
  5261. /**
  5262. * Examine a single {@link TextTrack} and return a JSON-compatible javascript object that
  5263. * represents the {@link TextTrack}'s state.
  5264. *
  5265. * @param {TextTrack} track
  5266. * The text track to query.
  5267. *
  5268. * @return {Object}
  5269. * A serializable javascript representation of the TextTrack.
  5270. * @private
  5271. */
  5272. var trackToJson_ = function trackToJson_(track) {
  5273. var ret = ['kind', 'label', 'language', 'id', 'inBandMetadataTrackDispatchType', 'mode', 'src'].reduce(function (acc, prop, i) {
  5274. if (track[prop]) {
  5275. acc[prop] = track[prop];
  5276. }
  5277. return acc;
  5278. }, {
  5279. cues: track.cues && Array.prototype.map.call(track.cues, function (cue) {
  5280. return {
  5281. startTime: cue.startTime,
  5282. endTime: cue.endTime,
  5283. text: cue.text,
  5284. id: cue.id
  5285. };
  5286. })
  5287. });
  5288. return ret;
  5289. };
  5290. /**
  5291. * Examine a {@link Tech} and return a JSON-compatible javascript array that represents the
  5292. * state of all {@link TextTrack}s currently configured. The return array is compatible with
  5293. * {@link text-track-list-converter:jsonToTextTracks}.
  5294. *
  5295. * @param {Tech} tech
  5296. * The tech object to query
  5297. *
  5298. * @return {Array}
  5299. * A serializable javascript representation of the {@link Tech}s
  5300. * {@link TextTrackList}.
  5301. */
  5302. var textTracksToJson = function textTracksToJson(tech) {
  5303. var trackEls = tech.$$('track');
  5304. var trackObjs = Array.prototype.map.call(trackEls, function (t) {
  5305. return t.track;
  5306. });
  5307. var tracks = Array.prototype.map.call(trackEls, function (trackEl) {
  5308. var json = trackToJson_(trackEl.track);
  5309. if (trackEl.src) {
  5310. json.src = trackEl.src;
  5311. }
  5312. return json;
  5313. });
  5314. return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function (track) {
  5315. return trackObjs.indexOf(track) === -1;
  5316. }).map(trackToJson_));
  5317. };
  5318. /**
  5319. * Create a set of remote {@link TextTrack}s on a {@link Tech} based on an array of javascript
  5320. * object {@link TextTrack} representations.
  5321. *
  5322. * @param {Array} json
  5323. * An array of `TextTrack` representation objects, like those that would be
  5324. * produced by `textTracksToJson`.
  5325. *
  5326. * @param {Tech} tech
  5327. * The `Tech` to create the `TextTrack`s on.
  5328. */
  5329. var jsonToTextTracks = function jsonToTextTracks(json, tech) {
  5330. json.forEach(function (track) {
  5331. var addedTrack = tech.addRemoteTextTrack(track).track;
  5332. if (!track.src && track.cues) {
  5333. track.cues.forEach(function (cue) {
  5334. return addedTrack.addCue(cue);
  5335. });
  5336. }
  5337. });
  5338. return tech.textTracks();
  5339. };
  5340. var textTrackConverter = {
  5341. textTracksToJson: textTracksToJson,
  5342. jsonToTextTracks: jsonToTextTracks,
  5343. trackToJson_: trackToJson_
  5344. };
  5345. var MODAL_CLASS_NAME = 'vjs-modal-dialog';
  5346. /**
  5347. * The `ModalDialog` displays over the video and its controls, which blocks
  5348. * interaction with the player until it is closed.
  5349. *
  5350. * Modal dialogs include a "Close" button and will close when that button
  5351. * is activated - or when ESC is pressed anywhere.
  5352. *
  5353. * @extends Component
  5354. */
  5355. var ModalDialog = /*#__PURE__*/function (_Component) {
  5356. inheritsLoose(ModalDialog, _Component);
  5357. /**
  5358. * Create an instance of this class.
  5359. *
  5360. * @param {Player} player
  5361. * The `Player` that this class should be attached to.
  5362. *
  5363. * @param {Object} [options]
  5364. * The key/value store of player options.
  5365. *
  5366. * @param {Mixed} [options.content=undefined]
  5367. * Provide customized content for this modal.
  5368. *
  5369. * @param {string} [options.description]
  5370. * A text description for the modal, primarily for accessibility.
  5371. *
  5372. * @param {boolean} [options.fillAlways=false]
  5373. * Normally, modals are automatically filled only the first time
  5374. * they open. This tells the modal to refresh its content
  5375. * every time it opens.
  5376. *
  5377. * @param {string} [options.label]
  5378. * A text label for the modal, primarily for accessibility.
  5379. *
  5380. * @param {boolean} [options.pauseOnOpen=true]
  5381. * If `true`, playback will will be paused if playing when
  5382. * the modal opens, and resumed when it closes.
  5383. *
  5384. * @param {boolean} [options.temporary=true]
  5385. * If `true`, the modal can only be opened once; it will be
  5386. * disposed as soon as it's closed.
  5387. *
  5388. * @param {boolean} [options.uncloseable=false]
  5389. * If `true`, the user will not be able to close the modal
  5390. * through the UI in the normal ways. Programmatic closing is
  5391. * still possible.
  5392. */
  5393. function ModalDialog(player, options) {
  5394. var _this;
  5395. _this = _Component.call(this, player, options) || this;
  5396. _this.handleKeyDown_ = function (e) {
  5397. return _this.handleKeyDown(e);
  5398. };
  5399. _this.close_ = function (e) {
  5400. return _this.close(e);
  5401. };
  5402. _this.opened_ = _this.hasBeenOpened_ = _this.hasBeenFilled_ = false;
  5403. _this.closeable(!_this.options_.uncloseable);
  5404. _this.content(_this.options_.content); // Make sure the contentEl is defined AFTER any children are initialized
  5405. // because we only want the contents of the modal in the contentEl
  5406. // (not the UI elements like the close button).
  5407. _this.contentEl_ = createEl('div', {
  5408. className: MODAL_CLASS_NAME + "-content"
  5409. }, {
  5410. role: 'document'
  5411. });
  5412. _this.descEl_ = createEl('p', {
  5413. className: MODAL_CLASS_NAME + "-description vjs-control-text",
  5414. id: _this.el().getAttribute('aria-describedby')
  5415. });
  5416. textContent(_this.descEl_, _this.description());
  5417. _this.el_.appendChild(_this.descEl_);
  5418. _this.el_.appendChild(_this.contentEl_);
  5419. return _this;
  5420. }
  5421. /**
  5422. * Create the `ModalDialog`'s DOM element
  5423. *
  5424. * @return {Element}
  5425. * The DOM element that gets created.
  5426. */
  5427. var _proto = ModalDialog.prototype;
  5428. _proto.createEl = function createEl() {
  5429. return _Component.prototype.createEl.call(this, 'div', {
  5430. className: this.buildCSSClass(),
  5431. tabIndex: -1
  5432. }, {
  5433. 'aria-describedby': this.id() + "_description",
  5434. 'aria-hidden': 'true',
  5435. 'aria-label': this.label(),
  5436. 'role': 'dialog'
  5437. });
  5438. };
  5439. _proto.dispose = function dispose() {
  5440. this.contentEl_ = null;
  5441. this.descEl_ = null;
  5442. this.previouslyActiveEl_ = null;
  5443. _Component.prototype.dispose.call(this);
  5444. }
  5445. /**
  5446. * Builds the default DOM `className`.
  5447. *
  5448. * @return {string}
  5449. * The DOM `className` for this object.
  5450. */
  5451. ;
  5452. _proto.buildCSSClass = function buildCSSClass() {
  5453. return MODAL_CLASS_NAME + " vjs-hidden " + _Component.prototype.buildCSSClass.call(this);
  5454. }
  5455. /**
  5456. * Returns the label string for this modal. Primarily used for accessibility.
  5457. *
  5458. * @return {string}
  5459. * the localized or raw label of this modal.
  5460. */
  5461. ;
  5462. _proto.label = function label() {
  5463. return this.localize(this.options_.label || 'Modal Window');
  5464. }
  5465. /**
  5466. * Returns the description string for this modal. Primarily used for
  5467. * accessibility.
  5468. *
  5469. * @return {string}
  5470. * The localized or raw description of this modal.
  5471. */
  5472. ;
  5473. _proto.description = function description() {
  5474. var desc = this.options_.description || this.localize('This is a modal window.'); // Append a universal closeability message if the modal is closeable.
  5475. if (this.closeable()) {
  5476. desc += ' ' + this.localize('This modal can be closed by pressing the Escape key or activating the close button.');
  5477. }
  5478. return desc;
  5479. }
  5480. /**
  5481. * Opens the modal.
  5482. *
  5483. * @fires ModalDialog#beforemodalopen
  5484. * @fires ModalDialog#modalopen
  5485. */
  5486. ;
  5487. _proto.open = function open() {
  5488. if (!this.opened_) {
  5489. var player = this.player();
  5490. /**
  5491. * Fired just before a `ModalDialog` is opened.
  5492. *
  5493. * @event ModalDialog#beforemodalopen
  5494. * @type {EventTarget~Event}
  5495. */
  5496. this.trigger('beforemodalopen');
  5497. this.opened_ = true; // Fill content if the modal has never opened before and
  5498. // never been filled.
  5499. if (this.options_.fillAlways || !this.hasBeenOpened_ && !this.hasBeenFilled_) {
  5500. this.fill();
  5501. } // If the player was playing, pause it and take note of its previously
  5502. // playing state.
  5503. this.wasPlaying_ = !player.paused();
  5504. if (this.options_.pauseOnOpen && this.wasPlaying_) {
  5505. player.pause();
  5506. }
  5507. this.on('keydown', this.handleKeyDown_); // Hide controls and note if they were enabled.
  5508. this.hadControls_ = player.controls();
  5509. player.controls(false);
  5510. this.show();
  5511. this.conditionalFocus_();
  5512. this.el().setAttribute('aria-hidden', 'false');
  5513. /**
  5514. * Fired just after a `ModalDialog` is opened.
  5515. *
  5516. * @event ModalDialog#modalopen
  5517. * @type {EventTarget~Event}
  5518. */
  5519. this.trigger('modalopen');
  5520. this.hasBeenOpened_ = true;
  5521. }
  5522. }
  5523. /**
  5524. * If the `ModalDialog` is currently open or closed.
  5525. *
  5526. * @param {boolean} [value]
  5527. * If given, it will open (`true`) or close (`false`) the modal.
  5528. *
  5529. * @return {boolean}
  5530. * the current open state of the modaldialog
  5531. */
  5532. ;
  5533. _proto.opened = function opened(value) {
  5534. if (typeof value === 'boolean') {
  5535. this[value ? 'open' : 'close']();
  5536. }
  5537. return this.opened_;
  5538. }
  5539. /**
  5540. * Closes the modal, does nothing if the `ModalDialog` is
  5541. * not open.
  5542. *
  5543. * @fires ModalDialog#beforemodalclose
  5544. * @fires ModalDialog#modalclose
  5545. */
  5546. ;
  5547. _proto.close = function close() {
  5548. if (!this.opened_) {
  5549. return;
  5550. }
  5551. var player = this.player();
  5552. /**
  5553. * Fired just before a `ModalDialog` is closed.
  5554. *
  5555. * @event ModalDialog#beforemodalclose
  5556. * @type {EventTarget~Event}
  5557. */
  5558. this.trigger('beforemodalclose');
  5559. this.opened_ = false;
  5560. if (this.wasPlaying_ && this.options_.pauseOnOpen) {
  5561. player.play();
  5562. }
  5563. this.off('keydown', this.handleKeyDown_);
  5564. if (this.hadControls_) {
  5565. player.controls(true);
  5566. }
  5567. this.hide();
  5568. this.el().setAttribute('aria-hidden', 'true');
  5569. /**
  5570. * Fired just after a `ModalDialog` is closed.
  5571. *
  5572. * @event ModalDialog#modalclose
  5573. * @type {EventTarget~Event}
  5574. */
  5575. this.trigger('modalclose');
  5576. this.conditionalBlur_();
  5577. if (this.options_.temporary) {
  5578. this.dispose();
  5579. }
  5580. }
  5581. /**
  5582. * Check to see if the `ModalDialog` is closeable via the UI.
  5583. *
  5584. * @param {boolean} [value]
  5585. * If given as a boolean, it will set the `closeable` option.
  5586. *
  5587. * @return {boolean}
  5588. * Returns the final value of the closable option.
  5589. */
  5590. ;
  5591. _proto.closeable = function closeable(value) {
  5592. if (typeof value === 'boolean') {
  5593. var closeable = this.closeable_ = !!value;
  5594. var close = this.getChild('closeButton'); // If this is being made closeable and has no close button, add one.
  5595. if (closeable && !close) {
  5596. // The close button should be a child of the modal - not its
  5597. // content element, so temporarily change the content element.
  5598. var temp = this.contentEl_;
  5599. this.contentEl_ = this.el_;
  5600. close = this.addChild('closeButton', {
  5601. controlText: 'Close Modal Dialog'
  5602. });
  5603. this.contentEl_ = temp;
  5604. this.on(close, 'close', this.close_);
  5605. } // If this is being made uncloseable and has a close button, remove it.
  5606. if (!closeable && close) {
  5607. this.off(close, 'close', this.close_);
  5608. this.removeChild(close);
  5609. close.dispose();
  5610. }
  5611. }
  5612. return this.closeable_;
  5613. }
  5614. /**
  5615. * Fill the modal's content element with the modal's "content" option.
  5616. * The content element will be emptied before this change takes place.
  5617. */
  5618. ;
  5619. _proto.fill = function fill() {
  5620. this.fillWith(this.content());
  5621. }
  5622. /**
  5623. * Fill the modal's content element with arbitrary content.
  5624. * The content element will be emptied before this change takes place.
  5625. *
  5626. * @fires ModalDialog#beforemodalfill
  5627. * @fires ModalDialog#modalfill
  5628. *
  5629. * @param {Mixed} [content]
  5630. * The same rules apply to this as apply to the `content` option.
  5631. */
  5632. ;
  5633. _proto.fillWith = function fillWith(content) {
  5634. var contentEl = this.contentEl();
  5635. var parentEl = contentEl.parentNode;
  5636. var nextSiblingEl = contentEl.nextSibling;
  5637. /**
  5638. * Fired just before a `ModalDialog` is filled with content.
  5639. *
  5640. * @event ModalDialog#beforemodalfill
  5641. * @type {EventTarget~Event}
  5642. */
  5643. this.trigger('beforemodalfill');
  5644. this.hasBeenFilled_ = true; // Detach the content element from the DOM before performing
  5645. // manipulation to avoid modifying the live DOM multiple times.
  5646. parentEl.removeChild(contentEl);
  5647. this.empty();
  5648. insertContent(contentEl, content);
  5649. /**
  5650. * Fired just after a `ModalDialog` is filled with content.
  5651. *
  5652. * @event ModalDialog#modalfill
  5653. * @type {EventTarget~Event}
  5654. */
  5655. this.trigger('modalfill'); // Re-inject the re-filled content element.
  5656. if (nextSiblingEl) {
  5657. parentEl.insertBefore(contentEl, nextSiblingEl);
  5658. } else {
  5659. parentEl.appendChild(contentEl);
  5660. } // make sure that the close button is last in the dialog DOM
  5661. var closeButton = this.getChild('closeButton');
  5662. if (closeButton) {
  5663. parentEl.appendChild(closeButton.el_);
  5664. }
  5665. }
  5666. /**
  5667. * Empties the content element. This happens anytime the modal is filled.
  5668. *
  5669. * @fires ModalDialog#beforemodalempty
  5670. * @fires ModalDialog#modalempty
  5671. */
  5672. ;
  5673. _proto.empty = function empty() {
  5674. /**
  5675. * Fired just before a `ModalDialog` is emptied.
  5676. *
  5677. * @event ModalDialog#beforemodalempty
  5678. * @type {EventTarget~Event}
  5679. */
  5680. this.trigger('beforemodalempty');
  5681. emptyEl(this.contentEl());
  5682. /**
  5683. * Fired just after a `ModalDialog` is emptied.
  5684. *
  5685. * @event ModalDialog#modalempty
  5686. * @type {EventTarget~Event}
  5687. */
  5688. this.trigger('modalempty');
  5689. }
  5690. /**
  5691. * Gets or sets the modal content, which gets normalized before being
  5692. * rendered into the DOM.
  5693. *
  5694. * This does not update the DOM or fill the modal, but it is called during
  5695. * that process.
  5696. *
  5697. * @param {Mixed} [value]
  5698. * If defined, sets the internal content value to be used on the
  5699. * next call(s) to `fill`. This value is normalized before being
  5700. * inserted. To "clear" the internal content value, pass `null`.
  5701. *
  5702. * @return {Mixed}
  5703. * The current content of the modal dialog
  5704. */
  5705. ;
  5706. _proto.content = function content(value) {
  5707. if (typeof value !== 'undefined') {
  5708. this.content_ = value;
  5709. }
  5710. return this.content_;
  5711. }
  5712. /**
  5713. * conditionally focus the modal dialog if focus was previously on the player.
  5714. *
  5715. * @private
  5716. */
  5717. ;
  5718. _proto.conditionalFocus_ = function conditionalFocus_() {
  5719. var activeEl = document.activeElement;
  5720. var playerEl = this.player_.el_;
  5721. this.previouslyActiveEl_ = null;
  5722. if (playerEl.contains(activeEl) || playerEl === activeEl) {
  5723. this.previouslyActiveEl_ = activeEl;
  5724. this.focus();
  5725. }
  5726. }
  5727. /**
  5728. * conditionally blur the element and refocus the last focused element
  5729. *
  5730. * @private
  5731. */
  5732. ;
  5733. _proto.conditionalBlur_ = function conditionalBlur_() {
  5734. if (this.previouslyActiveEl_) {
  5735. this.previouslyActiveEl_.focus();
  5736. this.previouslyActiveEl_ = null;
  5737. }
  5738. }
  5739. /**
  5740. * Keydown handler. Attached when modal is focused.
  5741. *
  5742. * @listens keydown
  5743. */
  5744. ;
  5745. _proto.handleKeyDown = function handleKeyDown(event) {
  5746. // Do not allow keydowns to reach out of the modal dialog.
  5747. event.stopPropagation();
  5748. if (keycode.isEventKey(event, 'Escape') && this.closeable()) {
  5749. event.preventDefault();
  5750. this.close();
  5751. return;
  5752. } // exit early if it isn't a tab key
  5753. if (!keycode.isEventKey(event, 'Tab')) {
  5754. return;
  5755. }
  5756. var focusableEls = this.focusableEls_();
  5757. var activeEl = this.el_.querySelector(':focus');
  5758. var focusIndex;
  5759. for (var i = 0; i < focusableEls.length; i++) {
  5760. if (activeEl === focusableEls[i]) {
  5761. focusIndex = i;
  5762. break;
  5763. }
  5764. }
  5765. if (document.activeElement === this.el_) {
  5766. focusIndex = 0;
  5767. }
  5768. if (event.shiftKey && focusIndex === 0) {
  5769. focusableEls[focusableEls.length - 1].focus();
  5770. event.preventDefault();
  5771. } else if (!event.shiftKey && focusIndex === focusableEls.length - 1) {
  5772. focusableEls[0].focus();
  5773. event.preventDefault();
  5774. }
  5775. }
  5776. /**
  5777. * get all focusable elements
  5778. *
  5779. * @private
  5780. */
  5781. ;
  5782. _proto.focusableEls_ = function focusableEls_() {
  5783. var allChildren = this.el_.querySelectorAll('*');
  5784. return Array.prototype.filter.call(allChildren, function (child) {
  5785. return (child instanceof window.HTMLAnchorElement || child instanceof window.HTMLAreaElement) && child.hasAttribute('href') || (child instanceof window.HTMLInputElement || child instanceof window.HTMLSelectElement || child instanceof window.HTMLTextAreaElement || child instanceof window.HTMLButtonElement) && !child.hasAttribute('disabled') || child instanceof window.HTMLIFrameElement || child instanceof window.HTMLObjectElement || child instanceof window.HTMLEmbedElement || child.hasAttribute('tabindex') && child.getAttribute('tabindex') !== -1 || child.hasAttribute('contenteditable');
  5786. });
  5787. };
  5788. return ModalDialog;
  5789. }(Component);
  5790. /**
  5791. * Default options for `ModalDialog` default options.
  5792. *
  5793. * @type {Object}
  5794. * @private
  5795. */
  5796. ModalDialog.prototype.options_ = {
  5797. pauseOnOpen: true,
  5798. temporary: true
  5799. };
  5800. Component.registerComponent('ModalDialog', ModalDialog);
  5801. /**
  5802. * Common functionaliy between {@link TextTrackList}, {@link AudioTrackList}, and
  5803. * {@link VideoTrackList}
  5804. *
  5805. * @extends EventTarget
  5806. */
  5807. var TrackList = /*#__PURE__*/function (_EventTarget) {
  5808. inheritsLoose(TrackList, _EventTarget);
  5809. /**
  5810. * Create an instance of this class
  5811. *
  5812. * @param {Track[]} tracks
  5813. * A list of tracks to initialize the list with.
  5814. *
  5815. * @abstract
  5816. */
  5817. function TrackList(tracks) {
  5818. var _this;
  5819. if (tracks === void 0) {
  5820. tracks = [];
  5821. }
  5822. _this = _EventTarget.call(this) || this;
  5823. _this.tracks_ = [];
  5824. /**
  5825. * @memberof TrackList
  5826. * @member {number} length
  5827. * The current number of `Track`s in the this Trackist.
  5828. * @instance
  5829. */
  5830. Object.defineProperty(assertThisInitialized(_this), 'length', {
  5831. get: function get() {
  5832. return this.tracks_.length;
  5833. }
  5834. });
  5835. for (var i = 0; i < tracks.length; i++) {
  5836. _this.addTrack(tracks[i]);
  5837. }
  5838. return _this;
  5839. }
  5840. /**
  5841. * Add a {@link Track} to the `TrackList`
  5842. *
  5843. * @param {Track} track
  5844. * The audio, video, or text track to add to the list.
  5845. *
  5846. * @fires TrackList#addtrack
  5847. */
  5848. var _proto = TrackList.prototype;
  5849. _proto.addTrack = function addTrack(track) {
  5850. var _this2 = this;
  5851. var index = this.tracks_.length;
  5852. if (!('' + index in this)) {
  5853. Object.defineProperty(this, index, {
  5854. get: function get() {
  5855. return this.tracks_[index];
  5856. }
  5857. });
  5858. } // Do not add duplicate tracks
  5859. if (this.tracks_.indexOf(track) === -1) {
  5860. this.tracks_.push(track);
  5861. /**
  5862. * Triggered when a track is added to a track list.
  5863. *
  5864. * @event TrackList#addtrack
  5865. * @type {EventTarget~Event}
  5866. * @property {Track} track
  5867. * A reference to track that was added.
  5868. */
  5869. this.trigger({
  5870. track: track,
  5871. type: 'addtrack',
  5872. target: this
  5873. });
  5874. }
  5875. /**
  5876. * Triggered when a track label is changed.
  5877. *
  5878. * @event TrackList#addtrack
  5879. * @type {EventTarget~Event}
  5880. * @property {Track} track
  5881. * A reference to track that was added.
  5882. */
  5883. track.labelchange_ = function () {
  5884. _this2.trigger({
  5885. track: track,
  5886. type: 'labelchange',
  5887. target: _this2
  5888. });
  5889. };
  5890. if (isEvented(track)) {
  5891. track.addEventListener('labelchange', track.labelchange_);
  5892. }
  5893. }
  5894. /**
  5895. * Remove a {@link Track} from the `TrackList`
  5896. *
  5897. * @param {Track} rtrack
  5898. * The audio, video, or text track to remove from the list.
  5899. *
  5900. * @fires TrackList#removetrack
  5901. */
  5902. ;
  5903. _proto.removeTrack = function removeTrack(rtrack) {
  5904. var track;
  5905. for (var i = 0, l = this.length; i < l; i++) {
  5906. if (this[i] === rtrack) {
  5907. track = this[i];
  5908. if (track.off) {
  5909. track.off();
  5910. }
  5911. this.tracks_.splice(i, 1);
  5912. break;
  5913. }
  5914. }
  5915. if (!track) {
  5916. return;
  5917. }
  5918. /**
  5919. * Triggered when a track is removed from track list.
  5920. *
  5921. * @event TrackList#removetrack
  5922. * @type {EventTarget~Event}
  5923. * @property {Track} track
  5924. * A reference to track that was removed.
  5925. */
  5926. this.trigger({
  5927. track: track,
  5928. type: 'removetrack',
  5929. target: this
  5930. });
  5931. }
  5932. /**
  5933. * Get a Track from the TrackList by a tracks id
  5934. *
  5935. * @param {string} id - the id of the track to get
  5936. * @method getTrackById
  5937. * @return {Track}
  5938. * @private
  5939. */
  5940. ;
  5941. _proto.getTrackById = function getTrackById(id) {
  5942. var result = null;
  5943. for (var i = 0, l = this.length; i < l; i++) {
  5944. var track = this[i];
  5945. if (track.id === id) {
  5946. result = track;
  5947. break;
  5948. }
  5949. }
  5950. return result;
  5951. };
  5952. return TrackList;
  5953. }(EventTarget);
  5954. /**
  5955. * Triggered when a different track is selected/enabled.
  5956. *
  5957. * @event TrackList#change
  5958. * @type {EventTarget~Event}
  5959. */
  5960. /**
  5961. * Events that can be called with on + eventName. See {@link EventHandler}.
  5962. *
  5963. * @property {Object} TrackList#allowedEvents_
  5964. * @private
  5965. */
  5966. TrackList.prototype.allowedEvents_ = {
  5967. change: 'change',
  5968. addtrack: 'addtrack',
  5969. removetrack: 'removetrack',
  5970. labelchange: 'labelchange'
  5971. }; // emulate attribute EventHandler support to allow for feature detection
  5972. for (var event in TrackList.prototype.allowedEvents_) {
  5973. TrackList.prototype['on' + event] = null;
  5974. }
  5975. /**
  5976. * Anywhere we call this function we diverge from the spec
  5977. * as we only support one enabled audiotrack at a time
  5978. *
  5979. * @param {AudioTrackList} list
  5980. * list to work on
  5981. *
  5982. * @param {AudioTrack} track
  5983. * The track to skip
  5984. *
  5985. * @private
  5986. */
  5987. var disableOthers$1 = function disableOthers(list, track) {
  5988. for (var i = 0; i < list.length; i++) {
  5989. if (!Object.keys(list[i]).length || track.id === list[i].id) {
  5990. continue;
  5991. } // another audio track is enabled, disable it
  5992. list[i].enabled = false;
  5993. }
  5994. };
  5995. /**
  5996. * The current list of {@link AudioTrack} for a media file.
  5997. *
  5998. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist}
  5999. * @extends TrackList
  6000. */
  6001. var AudioTrackList = /*#__PURE__*/function (_TrackList) {
  6002. inheritsLoose(AudioTrackList, _TrackList);
  6003. /**
  6004. * Create an instance of this class.
  6005. *
  6006. * @param {AudioTrack[]} [tracks=[]]
  6007. * A list of `AudioTrack` to instantiate the list with.
  6008. */
  6009. function AudioTrackList(tracks) {
  6010. var _this;
  6011. if (tracks === void 0) {
  6012. tracks = [];
  6013. }
  6014. // make sure only 1 track is enabled
  6015. // sorted from last index to first index
  6016. for (var i = tracks.length - 1; i >= 0; i--) {
  6017. if (tracks[i].enabled) {
  6018. disableOthers$1(tracks, tracks[i]);
  6019. break;
  6020. }
  6021. }
  6022. _this = _TrackList.call(this, tracks) || this;
  6023. _this.changing_ = false;
  6024. return _this;
  6025. }
  6026. /**
  6027. * Add an {@link AudioTrack} to the `AudioTrackList`.
  6028. *
  6029. * @param {AudioTrack} track
  6030. * The AudioTrack to add to the list
  6031. *
  6032. * @fires TrackList#addtrack
  6033. */
  6034. var _proto = AudioTrackList.prototype;
  6035. _proto.addTrack = function addTrack(track) {
  6036. var _this2 = this;
  6037. if (track.enabled) {
  6038. disableOthers$1(this, track);
  6039. }
  6040. _TrackList.prototype.addTrack.call(this, track); // native tracks don't have this
  6041. if (!track.addEventListener) {
  6042. return;
  6043. }
  6044. track.enabledChange_ = function () {
  6045. // when we are disabling other tracks (since we don't support
  6046. // more than one track at a time) we will set changing_
  6047. // to true so that we don't trigger additional change events
  6048. if (_this2.changing_) {
  6049. return;
  6050. }
  6051. _this2.changing_ = true;
  6052. disableOthers$1(_this2, track);
  6053. _this2.changing_ = false;
  6054. _this2.trigger('change');
  6055. };
  6056. /**
  6057. * @listens AudioTrack#enabledchange
  6058. * @fires TrackList#change
  6059. */
  6060. track.addEventListener('enabledchange', track.enabledChange_);
  6061. };
  6062. _proto.removeTrack = function removeTrack(rtrack) {
  6063. _TrackList.prototype.removeTrack.call(this, rtrack);
  6064. if (rtrack.removeEventListener && rtrack.enabledChange_) {
  6065. rtrack.removeEventListener('enabledchange', rtrack.enabledChange_);
  6066. rtrack.enabledChange_ = null;
  6067. }
  6068. };
  6069. return AudioTrackList;
  6070. }(TrackList);
  6071. /**
  6072. * Un-select all other {@link VideoTrack}s that are selected.
  6073. *
  6074. * @param {VideoTrackList} list
  6075. * list to work on
  6076. *
  6077. * @param {VideoTrack} track
  6078. * The track to skip
  6079. *
  6080. * @private
  6081. */
  6082. var disableOthers = function disableOthers(list, track) {
  6083. for (var i = 0; i < list.length; i++) {
  6084. if (!Object.keys(list[i]).length || track.id === list[i].id) {
  6085. continue;
  6086. } // another video track is enabled, disable it
  6087. list[i].selected = false;
  6088. }
  6089. };
  6090. /**
  6091. * The current list of {@link VideoTrack} for a video.
  6092. *
  6093. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist}
  6094. * @extends TrackList
  6095. */
  6096. var VideoTrackList = /*#__PURE__*/function (_TrackList) {
  6097. inheritsLoose(VideoTrackList, _TrackList);
  6098. /**
  6099. * Create an instance of this class.
  6100. *
  6101. * @param {VideoTrack[]} [tracks=[]]
  6102. * A list of `VideoTrack` to instantiate the list with.
  6103. */
  6104. function VideoTrackList(tracks) {
  6105. var _this;
  6106. if (tracks === void 0) {
  6107. tracks = [];
  6108. }
  6109. // make sure only 1 track is enabled
  6110. // sorted from last index to first index
  6111. for (var i = tracks.length - 1; i >= 0; i--) {
  6112. if (tracks[i].selected) {
  6113. disableOthers(tracks, tracks[i]);
  6114. break;
  6115. }
  6116. }
  6117. _this = _TrackList.call(this, tracks) || this;
  6118. _this.changing_ = false;
  6119. /**
  6120. * @member {number} VideoTrackList#selectedIndex
  6121. * The current index of the selected {@link VideoTrack`}.
  6122. */
  6123. Object.defineProperty(assertThisInitialized(_this), 'selectedIndex', {
  6124. get: function get() {
  6125. for (var _i = 0; _i < this.length; _i++) {
  6126. if (this[_i].selected) {
  6127. return _i;
  6128. }
  6129. }
  6130. return -1;
  6131. },
  6132. set: function set() {}
  6133. });
  6134. return _this;
  6135. }
  6136. /**
  6137. * Add a {@link VideoTrack} to the `VideoTrackList`.
  6138. *
  6139. * @param {VideoTrack} track
  6140. * The VideoTrack to add to the list
  6141. *
  6142. * @fires TrackList#addtrack
  6143. */
  6144. var _proto = VideoTrackList.prototype;
  6145. _proto.addTrack = function addTrack(track) {
  6146. var _this2 = this;
  6147. if (track.selected) {
  6148. disableOthers(this, track);
  6149. }
  6150. _TrackList.prototype.addTrack.call(this, track); // native tracks don't have this
  6151. if (!track.addEventListener) {
  6152. return;
  6153. }
  6154. track.selectedChange_ = function () {
  6155. if (_this2.changing_) {
  6156. return;
  6157. }
  6158. _this2.changing_ = true;
  6159. disableOthers(_this2, track);
  6160. _this2.changing_ = false;
  6161. _this2.trigger('change');
  6162. };
  6163. /**
  6164. * @listens VideoTrack#selectedchange
  6165. * @fires TrackList#change
  6166. */
  6167. track.addEventListener('selectedchange', track.selectedChange_);
  6168. };
  6169. _proto.removeTrack = function removeTrack(rtrack) {
  6170. _TrackList.prototype.removeTrack.call(this, rtrack);
  6171. if (rtrack.removeEventListener && rtrack.selectedChange_) {
  6172. rtrack.removeEventListener('selectedchange', rtrack.selectedChange_);
  6173. rtrack.selectedChange_ = null;
  6174. }
  6175. };
  6176. return VideoTrackList;
  6177. }(TrackList);
  6178. /**
  6179. * The current list of {@link TextTrack} for a media file.
  6180. *
  6181. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttracklist}
  6182. * @extends TrackList
  6183. */
  6184. var TextTrackList = /*#__PURE__*/function (_TrackList) {
  6185. inheritsLoose(TextTrackList, _TrackList);
  6186. function TextTrackList() {
  6187. return _TrackList.apply(this, arguments) || this;
  6188. }
  6189. var _proto = TextTrackList.prototype;
  6190. /**
  6191. * Add a {@link TextTrack} to the `TextTrackList`
  6192. *
  6193. * @param {TextTrack} track
  6194. * The text track to add to the list.
  6195. *
  6196. * @fires TrackList#addtrack
  6197. */
  6198. _proto.addTrack = function addTrack(track) {
  6199. var _this = this;
  6200. _TrackList.prototype.addTrack.call(this, track);
  6201. if (!this.queueChange_) {
  6202. this.queueChange_ = function () {
  6203. return _this.queueTrigger('change');
  6204. };
  6205. }
  6206. if (!this.triggerSelectedlanguagechange) {
  6207. this.triggerSelectedlanguagechange_ = function () {
  6208. return _this.trigger('selectedlanguagechange');
  6209. };
  6210. }
  6211. /**
  6212. * @listens TextTrack#modechange
  6213. * @fires TrackList#change
  6214. */
  6215. track.addEventListener('modechange', this.queueChange_);
  6216. var nonLanguageTextTrackKind = ['metadata', 'chapters'];
  6217. if (nonLanguageTextTrackKind.indexOf(track.kind) === -1) {
  6218. track.addEventListener('modechange', this.triggerSelectedlanguagechange_);
  6219. }
  6220. };
  6221. _proto.removeTrack = function removeTrack(rtrack) {
  6222. _TrackList.prototype.removeTrack.call(this, rtrack); // manually remove the event handlers we added
  6223. if (rtrack.removeEventListener) {
  6224. if (this.queueChange_) {
  6225. rtrack.removeEventListener('modechange', this.queueChange_);
  6226. }
  6227. if (this.selectedlanguagechange_) {
  6228. rtrack.removeEventListener('modechange', this.triggerSelectedlanguagechange_);
  6229. }
  6230. }
  6231. };
  6232. return TextTrackList;
  6233. }(TrackList);
  6234. /**
  6235. * @file html-track-element-list.js
  6236. */
  6237. /**
  6238. * The current list of {@link HtmlTrackElement}s.
  6239. */
  6240. var HtmlTrackElementList = /*#__PURE__*/function () {
  6241. /**
  6242. * Create an instance of this class.
  6243. *
  6244. * @param {HtmlTrackElement[]} [tracks=[]]
  6245. * A list of `HtmlTrackElement` to instantiate the list with.
  6246. */
  6247. function HtmlTrackElementList(trackElements) {
  6248. if (trackElements === void 0) {
  6249. trackElements = [];
  6250. }
  6251. this.trackElements_ = [];
  6252. /**
  6253. * @memberof HtmlTrackElementList
  6254. * @member {number} length
  6255. * The current number of `Track`s in the this Trackist.
  6256. * @instance
  6257. */
  6258. Object.defineProperty(this, 'length', {
  6259. get: function get() {
  6260. return this.trackElements_.length;
  6261. }
  6262. });
  6263. for (var i = 0, length = trackElements.length; i < length; i++) {
  6264. this.addTrackElement_(trackElements[i]);
  6265. }
  6266. }
  6267. /**
  6268. * Add an {@link HtmlTrackElement} to the `HtmlTrackElementList`
  6269. *
  6270. * @param {HtmlTrackElement} trackElement
  6271. * The track element to add to the list.
  6272. *
  6273. * @private
  6274. */
  6275. var _proto = HtmlTrackElementList.prototype;
  6276. _proto.addTrackElement_ = function addTrackElement_(trackElement) {
  6277. var index = this.trackElements_.length;
  6278. if (!('' + index in this)) {
  6279. Object.defineProperty(this, index, {
  6280. get: function get() {
  6281. return this.trackElements_[index];
  6282. }
  6283. });
  6284. } // Do not add duplicate elements
  6285. if (this.trackElements_.indexOf(trackElement) === -1) {
  6286. this.trackElements_.push(trackElement);
  6287. }
  6288. }
  6289. /**
  6290. * Get an {@link HtmlTrackElement} from the `HtmlTrackElementList` given an
  6291. * {@link TextTrack}.
  6292. *
  6293. * @param {TextTrack} track
  6294. * The track associated with a track element.
  6295. *
  6296. * @return {HtmlTrackElement|undefined}
  6297. * The track element that was found or undefined.
  6298. *
  6299. * @private
  6300. */
  6301. ;
  6302. _proto.getTrackElementByTrack_ = function getTrackElementByTrack_(track) {
  6303. var trackElement_;
  6304. for (var i = 0, length = this.trackElements_.length; i < length; i++) {
  6305. if (track === this.trackElements_[i].track) {
  6306. trackElement_ = this.trackElements_[i];
  6307. break;
  6308. }
  6309. }
  6310. return trackElement_;
  6311. }
  6312. /**
  6313. * Remove a {@link HtmlTrackElement} from the `HtmlTrackElementList`
  6314. *
  6315. * @param {HtmlTrackElement} trackElement
  6316. * The track element to remove from the list.
  6317. *
  6318. * @private
  6319. */
  6320. ;
  6321. _proto.removeTrackElement_ = function removeTrackElement_(trackElement) {
  6322. for (var i = 0, length = this.trackElements_.length; i < length; i++) {
  6323. if (trackElement === this.trackElements_[i]) {
  6324. if (this.trackElements_[i].track && typeof this.trackElements_[i].track.off === 'function') {
  6325. this.trackElements_[i].track.off();
  6326. }
  6327. if (typeof this.trackElements_[i].off === 'function') {
  6328. this.trackElements_[i].off();
  6329. }
  6330. this.trackElements_.splice(i, 1);
  6331. break;
  6332. }
  6333. }
  6334. };
  6335. return HtmlTrackElementList;
  6336. }();
  6337. /**
  6338. * @file text-track-cue-list.js
  6339. */
  6340. /**
  6341. * @typedef {Object} TextTrackCueList~TextTrackCue
  6342. *
  6343. * @property {string} id
  6344. * The unique id for this text track cue
  6345. *
  6346. * @property {number} startTime
  6347. * The start time for this text track cue
  6348. *
  6349. * @property {number} endTime
  6350. * The end time for this text track cue
  6351. *
  6352. * @property {boolean} pauseOnExit
  6353. * Pause when the end time is reached if true.
  6354. *
  6355. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcue}
  6356. */
  6357. /**
  6358. * A List of TextTrackCues.
  6359. *
  6360. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcuelist}
  6361. */
  6362. var TextTrackCueList = /*#__PURE__*/function () {
  6363. /**
  6364. * Create an instance of this class..
  6365. *
  6366. * @param {Array} cues
  6367. * A list of cues to be initialized with
  6368. */
  6369. function TextTrackCueList(cues) {
  6370. TextTrackCueList.prototype.setCues_.call(this, cues);
  6371. /**
  6372. * @memberof TextTrackCueList
  6373. * @member {number} length
  6374. * The current number of `TextTrackCue`s in the TextTrackCueList.
  6375. * @instance
  6376. */
  6377. Object.defineProperty(this, 'length', {
  6378. get: function get() {
  6379. return this.length_;
  6380. }
  6381. });
  6382. }
  6383. /**
  6384. * A setter for cues in this list. Creates getters
  6385. * an an index for the cues.
  6386. *
  6387. * @param {Array} cues
  6388. * An array of cues to set
  6389. *
  6390. * @private
  6391. */
  6392. var _proto = TextTrackCueList.prototype;
  6393. _proto.setCues_ = function setCues_(cues) {
  6394. var oldLength = this.length || 0;
  6395. var i = 0;
  6396. var l = cues.length;
  6397. this.cues_ = cues;
  6398. this.length_ = cues.length;
  6399. var defineProp = function defineProp(index) {
  6400. if (!('' + index in this)) {
  6401. Object.defineProperty(this, '' + index, {
  6402. get: function get() {
  6403. return this.cues_[index];
  6404. }
  6405. });
  6406. }
  6407. };
  6408. if (oldLength < l) {
  6409. i = oldLength;
  6410. for (; i < l; i++) {
  6411. defineProp.call(this, i);
  6412. }
  6413. }
  6414. }
  6415. /**
  6416. * Get a `TextTrackCue` that is currently in the `TextTrackCueList` by id.
  6417. *
  6418. * @param {string} id
  6419. * The id of the cue that should be searched for.
  6420. *
  6421. * @return {TextTrackCueList~TextTrackCue|null}
  6422. * A single cue or null if none was found.
  6423. */
  6424. ;
  6425. _proto.getCueById = function getCueById(id) {
  6426. var result = null;
  6427. for (var i = 0, l = this.length; i < l; i++) {
  6428. var cue = this[i];
  6429. if (cue.id === id) {
  6430. result = cue;
  6431. break;
  6432. }
  6433. }
  6434. return result;
  6435. };
  6436. return TextTrackCueList;
  6437. }();
  6438. /**
  6439. * @file track-kinds.js
  6440. */
  6441. /**
  6442. * All possible `VideoTrackKind`s
  6443. *
  6444. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-videotrack-kind
  6445. * @typedef VideoTrack~Kind
  6446. * @enum
  6447. */
  6448. var VideoTrackKind = {
  6449. alternative: 'alternative',
  6450. captions: 'captions',
  6451. main: 'main',
  6452. sign: 'sign',
  6453. subtitles: 'subtitles',
  6454. commentary: 'commentary'
  6455. };
  6456. /**
  6457. * All possible `AudioTrackKind`s
  6458. *
  6459. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-audiotrack-kind
  6460. * @typedef AudioTrack~Kind
  6461. * @enum
  6462. */
  6463. var AudioTrackKind = {
  6464. 'alternative': 'alternative',
  6465. 'descriptions': 'descriptions',
  6466. 'main': 'main',
  6467. 'main-desc': 'main-desc',
  6468. 'translation': 'translation',
  6469. 'commentary': 'commentary'
  6470. };
  6471. /**
  6472. * All possible `TextTrackKind`s
  6473. *
  6474. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-kind
  6475. * @typedef TextTrack~Kind
  6476. * @enum
  6477. */
  6478. var TextTrackKind = {
  6479. subtitles: 'subtitles',
  6480. captions: 'captions',
  6481. descriptions: 'descriptions',
  6482. chapters: 'chapters',
  6483. metadata: 'metadata'
  6484. };
  6485. /**
  6486. * All possible `TextTrackMode`s
  6487. *
  6488. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackmode
  6489. * @typedef TextTrack~Mode
  6490. * @enum
  6491. */
  6492. var TextTrackMode = {
  6493. disabled: 'disabled',
  6494. hidden: 'hidden',
  6495. showing: 'showing'
  6496. };
  6497. /**
  6498. * A Track class that contains all of the common functionality for {@link AudioTrack},
  6499. * {@link VideoTrack}, and {@link TextTrack}.
  6500. *
  6501. * > Note: This class should not be used directly
  6502. *
  6503. * @see {@link https://html.spec.whatwg.org/multipage/embedded-content.html}
  6504. * @extends EventTarget
  6505. * @abstract
  6506. */
  6507. var Track = /*#__PURE__*/function (_EventTarget) {
  6508. inheritsLoose(Track, _EventTarget);
  6509. /**
  6510. * Create an instance of this class.
  6511. *
  6512. * @param {Object} [options={}]
  6513. * Object of option names and values
  6514. *
  6515. * @param {string} [options.kind='']
  6516. * A valid kind for the track type you are creating.
  6517. *
  6518. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  6519. * A unique id for this AudioTrack.
  6520. *
  6521. * @param {string} [options.label='']
  6522. * The menu label for this track.
  6523. *
  6524. * @param {string} [options.language='']
  6525. * A valid two character language code.
  6526. *
  6527. * @abstract
  6528. */
  6529. function Track(options) {
  6530. var _this;
  6531. if (options === void 0) {
  6532. options = {};
  6533. }
  6534. _this = _EventTarget.call(this) || this;
  6535. var trackProps = {
  6536. id: options.id || 'vjs_track_' + newGUID(),
  6537. kind: options.kind || '',
  6538. language: options.language || ''
  6539. };
  6540. var label = options.label || '';
  6541. /**
  6542. * @memberof Track
  6543. * @member {string} id
  6544. * The id of this track. Cannot be changed after creation.
  6545. * @instance
  6546. *
  6547. * @readonly
  6548. */
  6549. /**
  6550. * @memberof Track
  6551. * @member {string} kind
  6552. * The kind of track that this is. Cannot be changed after creation.
  6553. * @instance
  6554. *
  6555. * @readonly
  6556. */
  6557. /**
  6558. * @memberof Track
  6559. * @member {string} language
  6560. * The two letter language code for this track. Cannot be changed after
  6561. * creation.
  6562. * @instance
  6563. *
  6564. * @readonly
  6565. */
  6566. var _loop = function _loop(key) {
  6567. Object.defineProperty(assertThisInitialized(_this), key, {
  6568. get: function get() {
  6569. return trackProps[key];
  6570. },
  6571. set: function set() {}
  6572. });
  6573. };
  6574. for (var key in trackProps) {
  6575. _loop(key);
  6576. }
  6577. /**
  6578. * @memberof Track
  6579. * @member {string} label
  6580. * The label of this track. Cannot be changed after creation.
  6581. * @instance
  6582. *
  6583. * @fires Track#labelchange
  6584. */
  6585. Object.defineProperty(assertThisInitialized(_this), 'label', {
  6586. get: function get() {
  6587. return label;
  6588. },
  6589. set: function set(newLabel) {
  6590. if (newLabel !== label) {
  6591. label = newLabel;
  6592. /**
  6593. * An event that fires when label changes on this track.
  6594. *
  6595. * > Note: This is not part of the spec!
  6596. *
  6597. * @event Track#labelchange
  6598. * @type {EventTarget~Event}
  6599. */
  6600. this.trigger('labelchange');
  6601. }
  6602. }
  6603. });
  6604. return _this;
  6605. }
  6606. return Track;
  6607. }(EventTarget);
  6608. /**
  6609. * @file url.js
  6610. * @module url
  6611. */
  6612. /**
  6613. * @typedef {Object} url:URLObject
  6614. *
  6615. * @property {string} protocol
  6616. * The protocol of the url that was parsed.
  6617. *
  6618. * @property {string} hostname
  6619. * The hostname of the url that was parsed.
  6620. *
  6621. * @property {string} port
  6622. * The port of the url that was parsed.
  6623. *
  6624. * @property {string} pathname
  6625. * The pathname of the url that was parsed.
  6626. *
  6627. * @property {string} search
  6628. * The search query of the url that was parsed.
  6629. *
  6630. * @property {string} hash
  6631. * The hash of the url that was parsed.
  6632. *
  6633. * @property {string} host
  6634. * The host of the url that was parsed.
  6635. */
  6636. /**
  6637. * Resolve and parse the elements of a URL.
  6638. *
  6639. * @function
  6640. * @param {String} url
  6641. * The url to parse
  6642. *
  6643. * @return {url:URLObject}
  6644. * An object of url details
  6645. */
  6646. var parseUrl = function parseUrl(url) {
  6647. // This entire method can be replace with URL once we are able to drop IE11
  6648. var props = ['protocol', 'hostname', 'port', 'pathname', 'search', 'hash', 'host']; // add the url to an anchor and let the browser parse the URL
  6649. var a = document.createElement('a');
  6650. a.href = url; // Copy the specific URL properties to a new object
  6651. // This is also needed for IE because the anchor loses its
  6652. // properties when it's removed from the dom
  6653. var details = {};
  6654. for (var i = 0; i < props.length; i++) {
  6655. details[props[i]] = a[props[i]];
  6656. } // IE adds the port to the host property unlike everyone else. If
  6657. // a port identifier is added for standard ports, strip it.
  6658. if (details.protocol === 'http:') {
  6659. details.host = details.host.replace(/:80$/, '');
  6660. }
  6661. if (details.protocol === 'https:') {
  6662. details.host = details.host.replace(/:443$/, '');
  6663. }
  6664. if (!details.protocol) {
  6665. details.protocol = window.location.protocol;
  6666. }
  6667. /* istanbul ignore if */
  6668. if (!details.host) {
  6669. details.host = window.location.host;
  6670. }
  6671. return details;
  6672. };
  6673. /**
  6674. * Get absolute version of relative URL. Used to tell Flash the correct URL.
  6675. *
  6676. * @function
  6677. * @param {string} url
  6678. * URL to make absolute
  6679. *
  6680. * @return {string}
  6681. * Absolute URL
  6682. *
  6683. * @see http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
  6684. */
  6685. var getAbsoluteURL = function getAbsoluteURL(url) {
  6686. // Check if absolute URL
  6687. if (!url.match(/^https?:\/\//)) {
  6688. // Convert to absolute URL. Flash hosted off-site needs an absolute URL.
  6689. // add the url to an anchor and let the browser parse the URL
  6690. var a = document.createElement('a');
  6691. a.href = url;
  6692. url = a.href;
  6693. }
  6694. return url;
  6695. };
  6696. /**
  6697. * Returns the extension of the passed file name. It will return an empty string
  6698. * if passed an invalid path.
  6699. *
  6700. * @function
  6701. * @param {string} path
  6702. * The fileName path like '/path/to/file.mp4'
  6703. *
  6704. * @return {string}
  6705. * The extension in lower case or an empty string if no
  6706. * extension could be found.
  6707. */
  6708. var getFileExtension = function getFileExtension(path) {
  6709. if (typeof path === 'string') {
  6710. var splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$/;
  6711. var pathParts = splitPathRe.exec(path);
  6712. if (pathParts) {
  6713. return pathParts.pop().toLowerCase();
  6714. }
  6715. }
  6716. return '';
  6717. };
  6718. /**
  6719. * Returns whether the url passed is a cross domain request or not.
  6720. *
  6721. * @function
  6722. * @param {string} url
  6723. * The url to check.
  6724. *
  6725. * @param {Object} [winLoc]
  6726. * the domain to check the url against, defaults to window.location
  6727. *
  6728. * @param {string} [winLoc.protocol]
  6729. * The window location protocol defaults to window.location.protocol
  6730. *
  6731. * @param {string} [winLoc.host]
  6732. * The window location host defaults to window.location.host
  6733. *
  6734. * @return {boolean}
  6735. * Whether it is a cross domain request or not.
  6736. */
  6737. var isCrossOrigin = function isCrossOrigin(url, winLoc) {
  6738. if (winLoc === void 0) {
  6739. winLoc = window.location;
  6740. }
  6741. var urlInfo = parseUrl(url); // IE8 protocol relative urls will return ':' for protocol
  6742. var srcProtocol = urlInfo.protocol === ':' ? winLoc.protocol : urlInfo.protocol; // Check if url is for another domain/origin
  6743. // IE8 doesn't know location.origin, so we won't rely on it here
  6744. var crossOrigin = srcProtocol + urlInfo.host !== winLoc.protocol + winLoc.host;
  6745. return crossOrigin;
  6746. };
  6747. var Url = /*#__PURE__*/Object.freeze({
  6748. __proto__: null,
  6749. parseUrl: parseUrl,
  6750. getAbsoluteURL: getAbsoluteURL,
  6751. getFileExtension: getFileExtension,
  6752. isCrossOrigin: isCrossOrigin
  6753. });
  6754. var win;
  6755. if (typeof window !== "undefined") {
  6756. win = window;
  6757. } else if (typeof commonjsGlobal !== "undefined") {
  6758. win = commonjsGlobal;
  6759. } else if (typeof self !== "undefined") {
  6760. win = self;
  6761. } else {
  6762. win = {};
  6763. }
  6764. var window_1 = win;
  6765. var isFunction_1 = isFunction;
  6766. var toString = Object.prototype.toString;
  6767. function isFunction(fn) {
  6768. if (!fn) {
  6769. return false;
  6770. }
  6771. var string = toString.call(fn);
  6772. return string === '[object Function]' || typeof fn === 'function' && string !== '[object RegExp]' || typeof window !== 'undefined' && ( // IE8 and below
  6773. fn === window.setTimeout || fn === window.alert || fn === window.confirm || fn === window.prompt);
  6774. }
  6775. var httpResponseHandler = function httpResponseHandler(callback, decodeResponseBody) {
  6776. if (decodeResponseBody === void 0) {
  6777. decodeResponseBody = false;
  6778. }
  6779. return function (err, response, responseBody) {
  6780. // if the XHR failed, return that error
  6781. if (err) {
  6782. callback(err);
  6783. return;
  6784. } // if the HTTP status code is 4xx or 5xx, the request also failed
  6785. if (response.statusCode >= 400 && response.statusCode <= 599) {
  6786. var cause = responseBody;
  6787. if (decodeResponseBody) {
  6788. if (window_1.TextDecoder) {
  6789. var charset = getCharset(response.headers && response.headers['content-type']);
  6790. try {
  6791. cause = new TextDecoder(charset).decode(responseBody);
  6792. } catch (e) {}
  6793. } else {
  6794. cause = String.fromCharCode.apply(null, new Uint8Array(responseBody));
  6795. }
  6796. }
  6797. callback({
  6798. cause: cause
  6799. });
  6800. return;
  6801. } // otherwise, request succeeded
  6802. callback(null, responseBody);
  6803. };
  6804. };
  6805. function getCharset(contentTypeHeader) {
  6806. if (contentTypeHeader === void 0) {
  6807. contentTypeHeader = '';
  6808. }
  6809. return contentTypeHeader.toLowerCase().split(';').reduce(function (charset, contentType) {
  6810. var _contentType$split = contentType.split('='),
  6811. type = _contentType$split[0],
  6812. value = _contentType$split[1];
  6813. if (type.trim() === 'charset') {
  6814. return value.trim();
  6815. }
  6816. return charset;
  6817. }, 'utf-8');
  6818. }
  6819. var httpHandler = httpResponseHandler;
  6820. createXHR.httpHandler = httpHandler;
  6821. /**
  6822. * @license
  6823. * slighly modified parse-headers 2.0.2 <https://github.com/kesla/parse-headers/>
  6824. * Copyright (c) 2014 David Björklund
  6825. * Available under the MIT license
  6826. * <https://github.com/kesla/parse-headers/blob/master/LICENCE>
  6827. */
  6828. var parseHeaders = function parseHeaders(headers) {
  6829. var result = {};
  6830. if (!headers) {
  6831. return result;
  6832. }
  6833. headers.trim().split('\n').forEach(function (row) {
  6834. var index = row.indexOf(':');
  6835. var key = row.slice(0, index).trim().toLowerCase();
  6836. var value = row.slice(index + 1).trim();
  6837. if (typeof result[key] === 'undefined') {
  6838. result[key] = value;
  6839. } else if (Array.isArray(result[key])) {
  6840. result[key].push(value);
  6841. } else {
  6842. result[key] = [result[key], value];
  6843. }
  6844. });
  6845. return result;
  6846. };
  6847. var lib = createXHR; // Allow use of default import syntax in TypeScript
  6848. var default_1 = createXHR;
  6849. createXHR.XMLHttpRequest = window_1.XMLHttpRequest || noop;
  6850. createXHR.XDomainRequest = "withCredentials" in new createXHR.XMLHttpRequest() ? createXHR.XMLHttpRequest : window_1.XDomainRequest;
  6851. forEachArray(["get", "put", "post", "patch", "head", "delete"], function (method) {
  6852. createXHR[method === "delete" ? "del" : method] = function (uri, options, callback) {
  6853. options = initParams(uri, options, callback);
  6854. options.method = method.toUpperCase();
  6855. return _createXHR(options);
  6856. };
  6857. });
  6858. function forEachArray(array, iterator) {
  6859. for (var i = 0; i < array.length; i++) {
  6860. iterator(array[i]);
  6861. }
  6862. }
  6863. function isEmpty(obj) {
  6864. for (var i in obj) {
  6865. if (obj.hasOwnProperty(i)) return false;
  6866. }
  6867. return true;
  6868. }
  6869. function initParams(uri, options, callback) {
  6870. var params = uri;
  6871. if (isFunction_1(options)) {
  6872. callback = options;
  6873. if (typeof uri === "string") {
  6874. params = {
  6875. uri: uri
  6876. };
  6877. }
  6878. } else {
  6879. params = _extends_1({}, options, {
  6880. uri: uri
  6881. });
  6882. }
  6883. params.callback = callback;
  6884. return params;
  6885. }
  6886. function createXHR(uri, options, callback) {
  6887. options = initParams(uri, options, callback);
  6888. return _createXHR(options);
  6889. }
  6890. function _createXHR(options) {
  6891. if (typeof options.callback === "undefined") {
  6892. throw new Error("callback argument missing");
  6893. }
  6894. var called = false;
  6895. var callback = function cbOnce(err, response, body) {
  6896. if (!called) {
  6897. called = true;
  6898. options.callback(err, response, body);
  6899. }
  6900. };
  6901. function readystatechange() {
  6902. if (xhr.readyState === 4) {
  6903. setTimeout(loadFunc, 0);
  6904. }
  6905. }
  6906. function getBody() {
  6907. // Chrome with requestType=blob throws errors arround when even testing access to responseText
  6908. var body = undefined;
  6909. if (xhr.response) {
  6910. body = xhr.response;
  6911. } else {
  6912. body = xhr.responseText || getXml(xhr);
  6913. }
  6914. if (isJson) {
  6915. try {
  6916. body = JSON.parse(body);
  6917. } catch (e) {}
  6918. }
  6919. return body;
  6920. }
  6921. function errorFunc(evt) {
  6922. clearTimeout(timeoutTimer);
  6923. if (!(evt instanceof Error)) {
  6924. evt = new Error("" + (evt || "Unknown XMLHttpRequest Error"));
  6925. }
  6926. evt.statusCode = 0;
  6927. return callback(evt, failureResponse);
  6928. } // will load the data & process the response in a special response object
  6929. function loadFunc() {
  6930. if (aborted) return;
  6931. var status;
  6932. clearTimeout(timeoutTimer);
  6933. if (options.useXDR && xhr.status === undefined) {
  6934. //IE8 CORS GET successful response doesn't have a status field, but body is fine
  6935. status = 200;
  6936. } else {
  6937. status = xhr.status === 1223 ? 204 : xhr.status;
  6938. }
  6939. var response = failureResponse;
  6940. var err = null;
  6941. if (status !== 0) {
  6942. response = {
  6943. body: getBody(),
  6944. statusCode: status,
  6945. method: method,
  6946. headers: {},
  6947. url: uri,
  6948. rawRequest: xhr
  6949. };
  6950. if (xhr.getAllResponseHeaders) {
  6951. //remember xhr can in fact be XDR for CORS in IE
  6952. response.headers = parseHeaders(xhr.getAllResponseHeaders());
  6953. }
  6954. } else {
  6955. err = new Error("Internal XMLHttpRequest Error");
  6956. }
  6957. return callback(err, response, response.body);
  6958. }
  6959. var xhr = options.xhr || null;
  6960. if (!xhr) {
  6961. if (options.cors || options.useXDR) {
  6962. xhr = new createXHR.XDomainRequest();
  6963. } else {
  6964. xhr = new createXHR.XMLHttpRequest();
  6965. }
  6966. }
  6967. var key;
  6968. var aborted;
  6969. var uri = xhr.url = options.uri || options.url;
  6970. var method = xhr.method = options.method || "GET";
  6971. var body = options.body || options.data;
  6972. var headers = xhr.headers = options.headers || {};
  6973. var sync = !!options.sync;
  6974. var isJson = false;
  6975. var timeoutTimer;
  6976. var failureResponse = {
  6977. body: undefined,
  6978. headers: {},
  6979. statusCode: 0,
  6980. method: method,
  6981. url: uri,
  6982. rawRequest: xhr
  6983. };
  6984. if ("json" in options && options.json !== false) {
  6985. isJson = true;
  6986. headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json"); //Don't override existing accept header declared by user
  6987. if (method !== "GET" && method !== "HEAD") {
  6988. headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json"); //Don't override existing accept header declared by user
  6989. body = JSON.stringify(options.json === true ? body : options.json);
  6990. }
  6991. }
  6992. xhr.onreadystatechange = readystatechange;
  6993. xhr.onload = loadFunc;
  6994. xhr.onerror = errorFunc; // IE9 must have onprogress be set to a unique function.
  6995. xhr.onprogress = function () {// IE must die
  6996. };
  6997. xhr.onabort = function () {
  6998. aborted = true;
  6999. };
  7000. xhr.ontimeout = errorFunc;
  7001. xhr.open(method, uri, !sync, options.username, options.password); //has to be after open
  7002. if (!sync) {
  7003. xhr.withCredentials = !!options.withCredentials;
  7004. } // Cannot set timeout with sync request
  7005. // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly
  7006. // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent
  7007. if (!sync && options.timeout > 0) {
  7008. timeoutTimer = setTimeout(function () {
  7009. if (aborted) return;
  7010. aborted = true; //IE9 may still call readystatechange
  7011. xhr.abort("timeout");
  7012. var e = new Error("XMLHttpRequest timeout");
  7013. e.code = "ETIMEDOUT";
  7014. errorFunc(e);
  7015. }, options.timeout);
  7016. }
  7017. if (xhr.setRequestHeader) {
  7018. for (key in headers) {
  7019. if (headers.hasOwnProperty(key)) {
  7020. xhr.setRequestHeader(key, headers[key]);
  7021. }
  7022. }
  7023. } else if (options.headers && !isEmpty(options.headers)) {
  7024. throw new Error("Headers cannot be set on an XDomainRequest object");
  7025. }
  7026. if ("responseType" in options) {
  7027. xhr.responseType = options.responseType;
  7028. }
  7029. if ("beforeSend" in options && typeof options.beforeSend === "function") {
  7030. options.beforeSend(xhr);
  7031. } // Microsoft Edge browser sends "undefined" when send is called with undefined value.
  7032. // XMLHttpRequest spec says to pass null as body to indicate no body
  7033. // See https://github.com/naugtur/xhr/issues/100.
  7034. xhr.send(body || null);
  7035. return xhr;
  7036. }
  7037. function getXml(xhr) {
  7038. // xhr.responseXML will throw Exception "InvalidStateError" or "DOMException"
  7039. // See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseXML.
  7040. try {
  7041. if (xhr.responseType === "document") {
  7042. return xhr.responseXML;
  7043. }
  7044. var firefoxBugTakenEffect = xhr.responseXML && xhr.responseXML.documentElement.nodeName === "parsererror";
  7045. if (xhr.responseType === "" && !firefoxBugTakenEffect) {
  7046. return xhr.responseXML;
  7047. }
  7048. } catch (e) {}
  7049. return null;
  7050. }
  7051. function noop() {}
  7052. lib["default"] = default_1;
  7053. /**
  7054. * Takes a webvtt file contents and parses it into cues
  7055. *
  7056. * @param {string} srcContent
  7057. * webVTT file contents
  7058. *
  7059. * @param {TextTrack} track
  7060. * TextTrack to add cues to. Cues come from the srcContent.
  7061. *
  7062. * @private
  7063. */
  7064. var parseCues = function parseCues(srcContent, track) {
  7065. var parser = new window.WebVTT.Parser(window, window.vttjs, window.WebVTT.StringDecoder());
  7066. var errors = [];
  7067. parser.oncue = function (cue) {
  7068. track.addCue(cue);
  7069. };
  7070. parser.onparsingerror = function (error) {
  7071. errors.push(error);
  7072. };
  7073. parser.onflush = function () {
  7074. track.trigger({
  7075. type: 'loadeddata',
  7076. target: track
  7077. });
  7078. };
  7079. parser.parse(srcContent);
  7080. if (errors.length > 0) {
  7081. if (window.console && window.console.groupCollapsed) {
  7082. window.console.groupCollapsed("Text Track parsing errors for " + track.src);
  7083. }
  7084. errors.forEach(function (error) {
  7085. return log.error(error);
  7086. });
  7087. if (window.console && window.console.groupEnd) {
  7088. window.console.groupEnd();
  7089. }
  7090. }
  7091. parser.flush();
  7092. };
  7093. /**
  7094. * Load a `TextTrack` from a specified url.
  7095. *
  7096. * @param {string} src
  7097. * Url to load track from.
  7098. *
  7099. * @param {TextTrack} track
  7100. * Track to add cues to. Comes from the content at the end of `url`.
  7101. *
  7102. * @private
  7103. */
  7104. var loadTrack = function loadTrack(src, track) {
  7105. var opts = {
  7106. uri: src
  7107. };
  7108. var crossOrigin = isCrossOrigin(src);
  7109. if (crossOrigin) {
  7110. opts.cors = crossOrigin;
  7111. }
  7112. var withCredentials = track.tech_.crossOrigin() === 'use-credentials';
  7113. if (withCredentials) {
  7114. opts.withCredentials = withCredentials;
  7115. }
  7116. lib(opts, bind(this, function (err, response, responseBody) {
  7117. if (err) {
  7118. return log.error(err, response);
  7119. }
  7120. track.loaded_ = true; // Make sure that vttjs has loaded, otherwise, wait till it finished loading
  7121. // NOTE: this is only used for the alt/video.novtt.js build
  7122. if (typeof window.WebVTT !== 'function') {
  7123. if (track.tech_) {
  7124. // to prevent use before define eslint error, we define loadHandler
  7125. // as a let here
  7126. track.tech_.any(['vttjsloaded', 'vttjserror'], function (event) {
  7127. if (event.type === 'vttjserror') {
  7128. log.error("vttjs failed to load, stopping trying to process " + track.src);
  7129. return;
  7130. }
  7131. return parseCues(responseBody, track);
  7132. });
  7133. }
  7134. } else {
  7135. parseCues(responseBody, track);
  7136. }
  7137. }));
  7138. };
  7139. /**
  7140. * A representation of a single `TextTrack`.
  7141. *
  7142. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrack}
  7143. * @extends Track
  7144. */
  7145. var TextTrack = /*#__PURE__*/function (_Track) {
  7146. inheritsLoose(TextTrack, _Track);
  7147. /**
  7148. * Create an instance of this class.
  7149. *
  7150. * @param {Object} options={}
  7151. * Object of option names and values
  7152. *
  7153. * @param {Tech} options.tech
  7154. * A reference to the tech that owns this TextTrack.
  7155. *
  7156. * @param {TextTrack~Kind} [options.kind='subtitles']
  7157. * A valid text track kind.
  7158. *
  7159. * @param {TextTrack~Mode} [options.mode='disabled']
  7160. * A valid text track mode.
  7161. *
  7162. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7163. * A unique id for this TextTrack.
  7164. *
  7165. * @param {string} [options.label='']
  7166. * The menu label for this track.
  7167. *
  7168. * @param {string} [options.language='']
  7169. * A valid two character language code.
  7170. *
  7171. * @param {string} [options.srclang='']
  7172. * A valid two character language code. An alternative, but deprioritized
  7173. * version of `options.language`
  7174. *
  7175. * @param {string} [options.src]
  7176. * A url to TextTrack cues.
  7177. *
  7178. * @param {boolean} [options.default]
  7179. * If this track should default to on or off.
  7180. */
  7181. function TextTrack(options) {
  7182. var _this;
  7183. if (options === void 0) {
  7184. options = {};
  7185. }
  7186. if (!options.tech) {
  7187. throw new Error('A tech was not provided.');
  7188. }
  7189. var settings = mergeOptions(options, {
  7190. kind: TextTrackKind[options.kind] || 'subtitles',
  7191. language: options.language || options.srclang || ''
  7192. });
  7193. var mode = TextTrackMode[settings.mode] || 'disabled';
  7194. var default_ = settings["default"];
  7195. if (settings.kind === 'metadata' || settings.kind === 'chapters') {
  7196. mode = 'hidden';
  7197. }
  7198. _this = _Track.call(this, settings) || this;
  7199. _this.tech_ = settings.tech;
  7200. _this.cues_ = [];
  7201. _this.activeCues_ = [];
  7202. _this.preload_ = _this.tech_.preloadTextTracks !== false;
  7203. var cues = new TextTrackCueList(_this.cues_);
  7204. var activeCues = new TextTrackCueList(_this.activeCues_);
  7205. var changed = false;
  7206. _this.timeupdateHandler = bind(assertThisInitialized(_this), function (event) {
  7207. if (event === void 0) {
  7208. event = {};
  7209. }
  7210. if (this.tech_.isDisposed()) {
  7211. return;
  7212. }
  7213. if (!this.tech_.isReady_) {
  7214. if (event.type !== 'timeupdate') {
  7215. this.rvf_ = this.tech_.requestVideoFrameCallback(this.timeupdateHandler);
  7216. }
  7217. return;
  7218. } // Accessing this.activeCues for the side-effects of updating itself
  7219. // due to its nature as a getter function. Do not remove or cues will
  7220. // stop updating!
  7221. // Use the setter to prevent deletion from uglify (pure_getters rule)
  7222. this.activeCues = this.activeCues;
  7223. if (changed) {
  7224. this.trigger('cuechange');
  7225. changed = false;
  7226. }
  7227. if (event.type !== 'timeupdate') {
  7228. this.rvf_ = this.tech_.requestVideoFrameCallback(this.timeupdateHandler);
  7229. }
  7230. });
  7231. var disposeHandler = function disposeHandler() {
  7232. _this.stopTracking();
  7233. };
  7234. _this.tech_.one('dispose', disposeHandler);
  7235. if (mode !== 'disabled') {
  7236. _this.startTracking();
  7237. }
  7238. Object.defineProperties(assertThisInitialized(_this), {
  7239. /**
  7240. * @memberof TextTrack
  7241. * @member {boolean} default
  7242. * If this track was set to be on or off by default. Cannot be changed after
  7243. * creation.
  7244. * @instance
  7245. *
  7246. * @readonly
  7247. */
  7248. "default": {
  7249. get: function get() {
  7250. return default_;
  7251. },
  7252. set: function set() {}
  7253. },
  7254. /**
  7255. * @memberof TextTrack
  7256. * @member {string} mode
  7257. * Set the mode of this TextTrack to a valid {@link TextTrack~Mode}. Will
  7258. * not be set if setting to an invalid mode.
  7259. * @instance
  7260. *
  7261. * @fires TextTrack#modechange
  7262. */
  7263. mode: {
  7264. get: function get() {
  7265. return mode;
  7266. },
  7267. set: function set(newMode) {
  7268. if (!TextTrackMode[newMode]) {
  7269. return;
  7270. }
  7271. if (mode === newMode) {
  7272. return;
  7273. }
  7274. mode = newMode;
  7275. if (!this.preload_ && mode !== 'disabled' && this.cues.length === 0) {
  7276. // On-demand load.
  7277. loadTrack(this.src, this);
  7278. }
  7279. this.stopTracking();
  7280. if (mode !== 'disabled') {
  7281. this.startTracking();
  7282. }
  7283. /**
  7284. * An event that fires when mode changes on this track. This allows
  7285. * the TextTrackList that holds this track to act accordingly.
  7286. *
  7287. * > Note: This is not part of the spec!
  7288. *
  7289. * @event TextTrack#modechange
  7290. * @type {EventTarget~Event}
  7291. */
  7292. this.trigger('modechange');
  7293. }
  7294. },
  7295. /**
  7296. * @memberof TextTrack
  7297. * @member {TextTrackCueList} cues
  7298. * The text track cue list for this TextTrack.
  7299. * @instance
  7300. */
  7301. cues: {
  7302. get: function get() {
  7303. if (!this.loaded_) {
  7304. return null;
  7305. }
  7306. return cues;
  7307. },
  7308. set: function set() {}
  7309. },
  7310. /**
  7311. * @memberof TextTrack
  7312. * @member {TextTrackCueList} activeCues
  7313. * The list text track cues that are currently active for this TextTrack.
  7314. * @instance
  7315. */
  7316. activeCues: {
  7317. get: function get() {
  7318. if (!this.loaded_) {
  7319. return null;
  7320. } // nothing to do
  7321. if (this.cues.length === 0) {
  7322. return activeCues;
  7323. }
  7324. var ct = this.tech_.currentTime();
  7325. var active = [];
  7326. for (var i = 0, l = this.cues.length; i < l; i++) {
  7327. var cue = this.cues[i];
  7328. if (cue.startTime <= ct && cue.endTime >= ct) {
  7329. active.push(cue);
  7330. } else if (cue.startTime === cue.endTime && cue.startTime <= ct && cue.startTime + 0.5 >= ct) {
  7331. active.push(cue);
  7332. }
  7333. }
  7334. changed = false;
  7335. if (active.length !== this.activeCues_.length) {
  7336. changed = true;
  7337. } else {
  7338. for (var _i = 0; _i < active.length; _i++) {
  7339. if (this.activeCues_.indexOf(active[_i]) === -1) {
  7340. changed = true;
  7341. }
  7342. }
  7343. }
  7344. this.activeCues_ = active;
  7345. activeCues.setCues_(this.activeCues_);
  7346. return activeCues;
  7347. },
  7348. // /!\ Keep this setter empty (see the timeupdate handler above)
  7349. set: function set() {}
  7350. }
  7351. });
  7352. if (settings.src) {
  7353. _this.src = settings.src;
  7354. if (!_this.preload_) {
  7355. // Tracks will load on-demand.
  7356. // Act like we're loaded for other purposes.
  7357. _this.loaded_ = true;
  7358. }
  7359. if (_this.preload_ || settings.kind !== 'subtitles' && settings.kind !== 'captions') {
  7360. loadTrack(_this.src, assertThisInitialized(_this));
  7361. }
  7362. } else {
  7363. _this.loaded_ = true;
  7364. }
  7365. return _this;
  7366. }
  7367. var _proto = TextTrack.prototype;
  7368. _proto.startTracking = function startTracking() {
  7369. // More precise cues based on requestVideoFrameCallback with a requestAnimationFram fallback
  7370. this.rvf_ = this.tech_.requestVideoFrameCallback(this.timeupdateHandler); // Also listen to timeupdate in case rVFC/rAF stops (window in background, audio in video el)
  7371. this.tech_.on('timeupdate', this.timeupdateHandler);
  7372. };
  7373. _proto.stopTracking = function stopTracking() {
  7374. if (this.rvf_) {
  7375. this.tech_.cancelVideoFrameCallback(this.rvf_);
  7376. this.rvf_ = undefined;
  7377. }
  7378. this.tech_.off('timeupdate', this.timeupdateHandler);
  7379. }
  7380. /**
  7381. * Add a cue to the internal list of cues.
  7382. *
  7383. * @param {TextTrack~Cue} cue
  7384. * The cue to add to our internal list
  7385. */
  7386. ;
  7387. _proto.addCue = function addCue(originalCue) {
  7388. var cue = originalCue;
  7389. if (window.vttjs && !(originalCue instanceof window.vttjs.VTTCue)) {
  7390. cue = new window.vttjs.VTTCue(originalCue.startTime, originalCue.endTime, originalCue.text);
  7391. for (var prop in originalCue) {
  7392. if (!(prop in cue)) {
  7393. cue[prop] = originalCue[prop];
  7394. }
  7395. } // make sure that `id` is copied over
  7396. cue.id = originalCue.id;
  7397. cue.originalCue_ = originalCue;
  7398. }
  7399. var tracks = this.tech_.textTracks();
  7400. for (var i = 0; i < tracks.length; i++) {
  7401. if (tracks[i] !== this) {
  7402. tracks[i].removeCue(cue);
  7403. }
  7404. }
  7405. this.cues_.push(cue);
  7406. this.cues.setCues_(this.cues_);
  7407. }
  7408. /**
  7409. * Remove a cue from our internal list
  7410. *
  7411. * @param {TextTrack~Cue} removeCue
  7412. * The cue to remove from our internal list
  7413. */
  7414. ;
  7415. _proto.removeCue = function removeCue(_removeCue) {
  7416. var i = this.cues_.length;
  7417. while (i--) {
  7418. var cue = this.cues_[i];
  7419. if (cue === _removeCue || cue.originalCue_ && cue.originalCue_ === _removeCue) {
  7420. this.cues_.splice(i, 1);
  7421. this.cues.setCues_(this.cues_);
  7422. break;
  7423. }
  7424. }
  7425. };
  7426. return TextTrack;
  7427. }(Track);
  7428. /**
  7429. * cuechange - One or more cues in the track have become active or stopped being active.
  7430. */
  7431. TextTrack.prototype.allowedEvents_ = {
  7432. cuechange: 'cuechange'
  7433. };
  7434. /**
  7435. * A representation of a single `AudioTrack`. If it is part of an {@link AudioTrackList}
  7436. * only one `AudioTrack` in the list will be enabled at a time.
  7437. *
  7438. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotrack}
  7439. * @extends Track
  7440. */
  7441. var AudioTrack = /*#__PURE__*/function (_Track) {
  7442. inheritsLoose(AudioTrack, _Track);
  7443. /**
  7444. * Create an instance of this class.
  7445. *
  7446. * @param {Object} [options={}]
  7447. * Object of option names and values
  7448. *
  7449. * @param {AudioTrack~Kind} [options.kind='']
  7450. * A valid audio track kind
  7451. *
  7452. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7453. * A unique id for this AudioTrack.
  7454. *
  7455. * @param {string} [options.label='']
  7456. * The menu label for this track.
  7457. *
  7458. * @param {string} [options.language='']
  7459. * A valid two character language code.
  7460. *
  7461. * @param {boolean} [options.enabled]
  7462. * If this track is the one that is currently playing. If this track is part of
  7463. * an {@link AudioTrackList}, only one {@link AudioTrack} will be enabled.
  7464. */
  7465. function AudioTrack(options) {
  7466. var _this;
  7467. if (options === void 0) {
  7468. options = {};
  7469. }
  7470. var settings = mergeOptions(options, {
  7471. kind: AudioTrackKind[options.kind] || ''
  7472. });
  7473. _this = _Track.call(this, settings) || this;
  7474. var enabled = false;
  7475. /**
  7476. * @memberof AudioTrack
  7477. * @member {boolean} enabled
  7478. * If this `AudioTrack` is enabled or not. When setting this will
  7479. * fire {@link AudioTrack#enabledchange} if the state of enabled is changed.
  7480. * @instance
  7481. *
  7482. * @fires VideoTrack#selectedchange
  7483. */
  7484. Object.defineProperty(assertThisInitialized(_this), 'enabled', {
  7485. get: function get() {
  7486. return enabled;
  7487. },
  7488. set: function set(newEnabled) {
  7489. // an invalid or unchanged value
  7490. if (typeof newEnabled !== 'boolean' || newEnabled === enabled) {
  7491. return;
  7492. }
  7493. enabled = newEnabled;
  7494. /**
  7495. * An event that fires when enabled changes on this track. This allows
  7496. * the AudioTrackList that holds this track to act accordingly.
  7497. *
  7498. * > Note: This is not part of the spec! Native tracks will do
  7499. * this internally without an event.
  7500. *
  7501. * @event AudioTrack#enabledchange
  7502. * @type {EventTarget~Event}
  7503. */
  7504. this.trigger('enabledchange');
  7505. }
  7506. }); // if the user sets this track to selected then
  7507. // set selected to that true value otherwise
  7508. // we keep it false
  7509. if (settings.enabled) {
  7510. _this.enabled = settings.enabled;
  7511. }
  7512. _this.loaded_ = true;
  7513. return _this;
  7514. }
  7515. return AudioTrack;
  7516. }(Track);
  7517. /**
  7518. * A representation of a single `VideoTrack`.
  7519. *
  7520. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotrack}
  7521. * @extends Track
  7522. */
  7523. var VideoTrack = /*#__PURE__*/function (_Track) {
  7524. inheritsLoose(VideoTrack, _Track);
  7525. /**
  7526. * Create an instance of this class.
  7527. *
  7528. * @param {Object} [options={}]
  7529. * Object of option names and values
  7530. *
  7531. * @param {string} [options.kind='']
  7532. * A valid {@link VideoTrack~Kind}
  7533. *
  7534. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7535. * A unique id for this AudioTrack.
  7536. *
  7537. * @param {string} [options.label='']
  7538. * The menu label for this track.
  7539. *
  7540. * @param {string} [options.language='']
  7541. * A valid two character language code.
  7542. *
  7543. * @param {boolean} [options.selected]
  7544. * If this track is the one that is currently playing.
  7545. */
  7546. function VideoTrack(options) {
  7547. var _this;
  7548. if (options === void 0) {
  7549. options = {};
  7550. }
  7551. var settings = mergeOptions(options, {
  7552. kind: VideoTrackKind[options.kind] || ''
  7553. });
  7554. _this = _Track.call(this, settings) || this;
  7555. var selected = false;
  7556. /**
  7557. * @memberof VideoTrack
  7558. * @member {boolean} selected
  7559. * If this `VideoTrack` is selected or not. When setting this will
  7560. * fire {@link VideoTrack#selectedchange} if the state of selected changed.
  7561. * @instance
  7562. *
  7563. * @fires VideoTrack#selectedchange
  7564. */
  7565. Object.defineProperty(assertThisInitialized(_this), 'selected', {
  7566. get: function get() {
  7567. return selected;
  7568. },
  7569. set: function set(newSelected) {
  7570. // an invalid or unchanged value
  7571. if (typeof newSelected !== 'boolean' || newSelected === selected) {
  7572. return;
  7573. }
  7574. selected = newSelected;
  7575. /**
  7576. * An event that fires when selected changes on this track. This allows
  7577. * the VideoTrackList that holds this track to act accordingly.
  7578. *
  7579. * > Note: This is not part of the spec! Native tracks will do
  7580. * this internally without an event.
  7581. *
  7582. * @event VideoTrack#selectedchange
  7583. * @type {EventTarget~Event}
  7584. */
  7585. this.trigger('selectedchange');
  7586. }
  7587. }); // if the user sets this track to selected then
  7588. // set selected to that true value otherwise
  7589. // we keep it false
  7590. if (settings.selected) {
  7591. _this.selected = settings.selected;
  7592. }
  7593. return _this;
  7594. }
  7595. return VideoTrack;
  7596. }(Track);
  7597. /**
  7598. * @memberof HTMLTrackElement
  7599. * @typedef {HTMLTrackElement~ReadyState}
  7600. * @enum {number}
  7601. */
  7602. var NONE = 0;
  7603. var LOADING = 1;
  7604. var LOADED = 2;
  7605. var ERROR = 3;
  7606. /**
  7607. * A single track represented in the DOM.
  7608. *
  7609. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#htmltrackelement}
  7610. * @extends EventTarget
  7611. */
  7612. var HTMLTrackElement = /*#__PURE__*/function (_EventTarget) {
  7613. inheritsLoose(HTMLTrackElement, _EventTarget);
  7614. /**
  7615. * Create an instance of this class.
  7616. *
  7617. * @param {Object} options={}
  7618. * Object of option names and values
  7619. *
  7620. * @param {Tech} options.tech
  7621. * A reference to the tech that owns this HTMLTrackElement.
  7622. *
  7623. * @param {TextTrack~Kind} [options.kind='subtitles']
  7624. * A valid text track kind.
  7625. *
  7626. * @param {TextTrack~Mode} [options.mode='disabled']
  7627. * A valid text track mode.
  7628. *
  7629. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7630. * A unique id for this TextTrack.
  7631. *
  7632. * @param {string} [options.label='']
  7633. * The menu label for this track.
  7634. *
  7635. * @param {string} [options.language='']
  7636. * A valid two character language code.
  7637. *
  7638. * @param {string} [options.srclang='']
  7639. * A valid two character language code. An alternative, but deprioritized
  7640. * version of `options.language`
  7641. *
  7642. * @param {string} [options.src]
  7643. * A url to TextTrack cues.
  7644. *
  7645. * @param {boolean} [options.default]
  7646. * If this track should default to on or off.
  7647. */
  7648. function HTMLTrackElement(options) {
  7649. var _this;
  7650. if (options === void 0) {
  7651. options = {};
  7652. }
  7653. _this = _EventTarget.call(this) || this;
  7654. var readyState;
  7655. var track = new TextTrack(options);
  7656. _this.kind = track.kind;
  7657. _this.src = track.src;
  7658. _this.srclang = track.language;
  7659. _this.label = track.label;
  7660. _this["default"] = track["default"];
  7661. Object.defineProperties(assertThisInitialized(_this), {
  7662. /**
  7663. * @memberof HTMLTrackElement
  7664. * @member {HTMLTrackElement~ReadyState} readyState
  7665. * The current ready state of the track element.
  7666. * @instance
  7667. */
  7668. readyState: {
  7669. get: function get() {
  7670. return readyState;
  7671. }
  7672. },
  7673. /**
  7674. * @memberof HTMLTrackElement
  7675. * @member {TextTrack} track
  7676. * The underlying TextTrack object.
  7677. * @instance
  7678. *
  7679. */
  7680. track: {
  7681. get: function get() {
  7682. return track;
  7683. }
  7684. }
  7685. });
  7686. readyState = NONE;
  7687. /**
  7688. * @listens TextTrack#loadeddata
  7689. * @fires HTMLTrackElement#load
  7690. */
  7691. track.addEventListener('loadeddata', function () {
  7692. readyState = LOADED;
  7693. _this.trigger({
  7694. type: 'load',
  7695. target: assertThisInitialized(_this)
  7696. });
  7697. });
  7698. return _this;
  7699. }
  7700. return HTMLTrackElement;
  7701. }(EventTarget);
  7702. HTMLTrackElement.prototype.allowedEvents_ = {
  7703. load: 'load'
  7704. };
  7705. HTMLTrackElement.NONE = NONE;
  7706. HTMLTrackElement.LOADING = LOADING;
  7707. HTMLTrackElement.LOADED = LOADED;
  7708. HTMLTrackElement.ERROR = ERROR;
  7709. /*
  7710. * This file contains all track properties that are used in
  7711. * player.js, tech.js, html5.js and possibly other techs in the future.
  7712. */
  7713. var NORMAL = {
  7714. audio: {
  7715. ListClass: AudioTrackList,
  7716. TrackClass: AudioTrack,
  7717. capitalName: 'Audio'
  7718. },
  7719. video: {
  7720. ListClass: VideoTrackList,
  7721. TrackClass: VideoTrack,
  7722. capitalName: 'Video'
  7723. },
  7724. text: {
  7725. ListClass: TextTrackList,
  7726. TrackClass: TextTrack,
  7727. capitalName: 'Text'
  7728. }
  7729. };
  7730. Object.keys(NORMAL).forEach(function (type) {
  7731. NORMAL[type].getterName = type + "Tracks";
  7732. NORMAL[type].privateName = type + "Tracks_";
  7733. });
  7734. var REMOTE = {
  7735. remoteText: {
  7736. ListClass: TextTrackList,
  7737. TrackClass: TextTrack,
  7738. capitalName: 'RemoteText',
  7739. getterName: 'remoteTextTracks',
  7740. privateName: 'remoteTextTracks_'
  7741. },
  7742. remoteTextEl: {
  7743. ListClass: HtmlTrackElementList,
  7744. TrackClass: HTMLTrackElement,
  7745. capitalName: 'RemoteTextTrackEls',
  7746. getterName: 'remoteTextTrackEls',
  7747. privateName: 'remoteTextTrackEls_'
  7748. }
  7749. };
  7750. var ALL = _extends_1({}, NORMAL, REMOTE);
  7751. REMOTE.names = Object.keys(REMOTE);
  7752. NORMAL.names = Object.keys(NORMAL);
  7753. ALL.names = [].concat(REMOTE.names).concat(NORMAL.names);
  7754. var vtt = {};
  7755. /**
  7756. * An Object containing a structure like: `{src: 'url', type: 'mimetype'}` or string
  7757. * that just contains the src url alone.
  7758. * * `var SourceObject = {src: 'http://ex.com/video.mp4', type: 'video/mp4'};`
  7759. * `var SourceString = 'http://example.com/some-video.mp4';`
  7760. *
  7761. * @typedef {Object|string} Tech~SourceObject
  7762. *
  7763. * @property {string} src
  7764. * The url to the source
  7765. *
  7766. * @property {string} type
  7767. * The mime type of the source
  7768. */
  7769. /**
  7770. * A function used by {@link Tech} to create a new {@link TextTrack}.
  7771. *
  7772. * @private
  7773. *
  7774. * @param {Tech} self
  7775. * An instance of the Tech class.
  7776. *
  7777. * @param {string} kind
  7778. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  7779. *
  7780. * @param {string} [label]
  7781. * Label to identify the text track
  7782. *
  7783. * @param {string} [language]
  7784. * Two letter language abbreviation
  7785. *
  7786. * @param {Object} [options={}]
  7787. * An object with additional text track options
  7788. *
  7789. * @return {TextTrack}
  7790. * The text track that was created.
  7791. */
  7792. function createTrackHelper(self, kind, label, language, options) {
  7793. if (options === void 0) {
  7794. options = {};
  7795. }
  7796. var tracks = self.textTracks();
  7797. options.kind = kind;
  7798. if (label) {
  7799. options.label = label;
  7800. }
  7801. if (language) {
  7802. options.language = language;
  7803. }
  7804. options.tech = self;
  7805. var track = new ALL.text.TrackClass(options);
  7806. tracks.addTrack(track);
  7807. return track;
  7808. }
  7809. /**
  7810. * This is the base class for media playback technology controllers, such as
  7811. * {@link HTML5}
  7812. *
  7813. * @extends Component
  7814. */
  7815. var Tech = /*#__PURE__*/function (_Component) {
  7816. inheritsLoose(Tech, _Component);
  7817. /**
  7818. * Create an instance of this Tech.
  7819. *
  7820. * @param {Object} [options]
  7821. * The key/value store of player options.
  7822. *
  7823. * @param {Component~ReadyCallback} ready
  7824. * Callback function to call when the `HTML5` Tech is ready.
  7825. */
  7826. function Tech(options, ready) {
  7827. var _this;
  7828. if (options === void 0) {
  7829. options = {};
  7830. }
  7831. if (ready === void 0) {
  7832. ready = function ready() {};
  7833. }
  7834. // we don't want the tech to report user activity automatically.
  7835. // This is done manually in addControlsListeners
  7836. options.reportTouchActivity = false;
  7837. _this = _Component.call(this, null, options, ready) || this;
  7838. _this.onDurationChange_ = function (e) {
  7839. return _this.onDurationChange(e);
  7840. };
  7841. _this.trackProgress_ = function (e) {
  7842. return _this.trackProgress(e);
  7843. };
  7844. _this.trackCurrentTime_ = function (e) {
  7845. return _this.trackCurrentTime(e);
  7846. };
  7847. _this.stopTrackingCurrentTime_ = function (e) {
  7848. return _this.stopTrackingCurrentTime(e);
  7849. };
  7850. _this.disposeSourceHandler_ = function (e) {
  7851. return _this.disposeSourceHandler(e);
  7852. };
  7853. _this.queuedHanders_ = new Set(); // keep track of whether the current source has played at all to
  7854. // implement a very limited played()
  7855. _this.hasStarted_ = false;
  7856. _this.on('playing', function () {
  7857. this.hasStarted_ = true;
  7858. });
  7859. _this.on('loadstart', function () {
  7860. this.hasStarted_ = false;
  7861. });
  7862. ALL.names.forEach(function (name) {
  7863. var props = ALL[name];
  7864. if (options && options[props.getterName]) {
  7865. _this[props.privateName] = options[props.getterName];
  7866. }
  7867. }); // Manually track progress in cases where the browser/tech doesn't report it.
  7868. if (!_this.featuresProgressEvents) {
  7869. _this.manualProgressOn();
  7870. } // Manually track timeupdates in cases where the browser/tech doesn't report it.
  7871. if (!_this.featuresTimeupdateEvents) {
  7872. _this.manualTimeUpdatesOn();
  7873. }
  7874. ['Text', 'Audio', 'Video'].forEach(function (track) {
  7875. if (options["native" + track + "Tracks"] === false) {
  7876. _this["featuresNative" + track + "Tracks"] = false;
  7877. }
  7878. });
  7879. if (options.nativeCaptions === false || options.nativeTextTracks === false) {
  7880. _this.featuresNativeTextTracks = false;
  7881. } else if (options.nativeCaptions === true || options.nativeTextTracks === true) {
  7882. _this.featuresNativeTextTracks = true;
  7883. }
  7884. if (!_this.featuresNativeTextTracks) {
  7885. _this.emulateTextTracks();
  7886. }
  7887. _this.preloadTextTracks = options.preloadTextTracks !== false;
  7888. _this.autoRemoteTextTracks_ = new ALL.text.ListClass();
  7889. _this.initTrackListeners(); // Turn on component tap events only if not using native controls
  7890. if (!options.nativeControlsForTouch) {
  7891. _this.emitTapEvents();
  7892. }
  7893. if (_this.constructor) {
  7894. _this.name_ = _this.constructor.name || 'Unknown Tech';
  7895. }
  7896. return _this;
  7897. }
  7898. /**
  7899. * A special function to trigger source set in a way that will allow player
  7900. * to re-trigger if the player or tech are not ready yet.
  7901. *
  7902. * @fires Tech#sourceset
  7903. * @param {string} src The source string at the time of the source changing.
  7904. */
  7905. var _proto = Tech.prototype;
  7906. _proto.triggerSourceset = function triggerSourceset(src) {
  7907. var _this2 = this;
  7908. if (!this.isReady_) {
  7909. // on initial ready we have to trigger source set
  7910. // 1ms after ready so that player can watch for it.
  7911. this.one('ready', function () {
  7912. return _this2.setTimeout(function () {
  7913. return _this2.triggerSourceset(src);
  7914. }, 1);
  7915. });
  7916. }
  7917. /**
  7918. * Fired when the source is set on the tech causing the media element
  7919. * to reload.
  7920. *
  7921. * @see {@link Player#event:sourceset}
  7922. * @event Tech#sourceset
  7923. * @type {EventTarget~Event}
  7924. */
  7925. this.trigger({
  7926. src: src,
  7927. type: 'sourceset'
  7928. });
  7929. }
  7930. /* Fallbacks for unsupported event types
  7931. ================================================================================ */
  7932. /**
  7933. * Polyfill the `progress` event for browsers that don't support it natively.
  7934. *
  7935. * @see {@link Tech#trackProgress}
  7936. */
  7937. ;
  7938. _proto.manualProgressOn = function manualProgressOn() {
  7939. this.on('durationchange', this.onDurationChange_);
  7940. this.manualProgress = true; // Trigger progress watching when a source begins loading
  7941. this.one('ready', this.trackProgress_);
  7942. }
  7943. /**
  7944. * Turn off the polyfill for `progress` events that was created in
  7945. * {@link Tech#manualProgressOn}
  7946. */
  7947. ;
  7948. _proto.manualProgressOff = function manualProgressOff() {
  7949. this.manualProgress = false;
  7950. this.stopTrackingProgress();
  7951. this.off('durationchange', this.onDurationChange_);
  7952. }
  7953. /**
  7954. * This is used to trigger a `progress` event when the buffered percent changes. It
  7955. * sets an interval function that will be called every 500 milliseconds to check if the
  7956. * buffer end percent has changed.
  7957. *
  7958. * > This function is called by {@link Tech#manualProgressOn}
  7959. *
  7960. * @param {EventTarget~Event} event
  7961. * The `ready` event that caused this to run.
  7962. *
  7963. * @listens Tech#ready
  7964. * @fires Tech#progress
  7965. */
  7966. ;
  7967. _proto.trackProgress = function trackProgress(event) {
  7968. this.stopTrackingProgress();
  7969. this.progressInterval = this.setInterval(bind(this, function () {
  7970. // Don't trigger unless buffered amount is greater than last time
  7971. var numBufferedPercent = this.bufferedPercent();
  7972. if (this.bufferedPercent_ !== numBufferedPercent) {
  7973. /**
  7974. * See {@link Player#progress}
  7975. *
  7976. * @event Tech#progress
  7977. * @type {EventTarget~Event}
  7978. */
  7979. this.trigger('progress');
  7980. }
  7981. this.bufferedPercent_ = numBufferedPercent;
  7982. if (numBufferedPercent === 1) {
  7983. this.stopTrackingProgress();
  7984. }
  7985. }), 500);
  7986. }
  7987. /**
  7988. * Update our internal duration on a `durationchange` event by calling
  7989. * {@link Tech#duration}.
  7990. *
  7991. * @param {EventTarget~Event} event
  7992. * The `durationchange` event that caused this to run.
  7993. *
  7994. * @listens Tech#durationchange
  7995. */
  7996. ;
  7997. _proto.onDurationChange = function onDurationChange(event) {
  7998. this.duration_ = this.duration();
  7999. }
  8000. /**
  8001. * Get and create a `TimeRange` object for buffering.
  8002. *
  8003. * @return {TimeRange}
  8004. * The time range object that was created.
  8005. */
  8006. ;
  8007. _proto.buffered = function buffered() {
  8008. return createTimeRanges(0, 0);
  8009. }
  8010. /**
  8011. * Get the percentage of the current video that is currently buffered.
  8012. *
  8013. * @return {number}
  8014. * A number from 0 to 1 that represents the decimal percentage of the
  8015. * video that is buffered.
  8016. *
  8017. */
  8018. ;
  8019. _proto.bufferedPercent = function bufferedPercent$1() {
  8020. return bufferedPercent(this.buffered(), this.duration_);
  8021. }
  8022. /**
  8023. * Turn off the polyfill for `progress` events that was created in
  8024. * {@link Tech#manualProgressOn}
  8025. * Stop manually tracking progress events by clearing the interval that was set in
  8026. * {@link Tech#trackProgress}.
  8027. */
  8028. ;
  8029. _proto.stopTrackingProgress = function stopTrackingProgress() {
  8030. this.clearInterval(this.progressInterval);
  8031. }
  8032. /**
  8033. * Polyfill the `timeupdate` event for browsers that don't support it.
  8034. *
  8035. * @see {@link Tech#trackCurrentTime}
  8036. */
  8037. ;
  8038. _proto.manualTimeUpdatesOn = function manualTimeUpdatesOn() {
  8039. this.manualTimeUpdates = true;
  8040. this.on('play', this.trackCurrentTime_);
  8041. this.on('pause', this.stopTrackingCurrentTime_);
  8042. }
  8043. /**
  8044. * Turn off the polyfill for `timeupdate` events that was created in
  8045. * {@link Tech#manualTimeUpdatesOn}
  8046. */
  8047. ;
  8048. _proto.manualTimeUpdatesOff = function manualTimeUpdatesOff() {
  8049. this.manualTimeUpdates = false;
  8050. this.stopTrackingCurrentTime();
  8051. this.off('play', this.trackCurrentTime_);
  8052. this.off('pause', this.stopTrackingCurrentTime_);
  8053. }
  8054. /**
  8055. * Sets up an interval function to track current time and trigger `timeupdate` every
  8056. * 250 milliseconds.
  8057. *
  8058. * @listens Tech#play
  8059. * @triggers Tech#timeupdate
  8060. */
  8061. ;
  8062. _proto.trackCurrentTime = function trackCurrentTime() {
  8063. if (this.currentTimeInterval) {
  8064. this.stopTrackingCurrentTime();
  8065. }
  8066. this.currentTimeInterval = this.setInterval(function () {
  8067. /**
  8068. * Triggered at an interval of 250ms to indicated that time is passing in the video.
  8069. *
  8070. * @event Tech#timeupdate
  8071. * @type {EventTarget~Event}
  8072. */
  8073. this.trigger({
  8074. type: 'timeupdate',
  8075. target: this,
  8076. manuallyTriggered: true
  8077. }); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
  8078. }, 250);
  8079. }
  8080. /**
  8081. * Stop the interval function created in {@link Tech#trackCurrentTime} so that the
  8082. * `timeupdate` event is no longer triggered.
  8083. *
  8084. * @listens {Tech#pause}
  8085. */
  8086. ;
  8087. _proto.stopTrackingCurrentTime = function stopTrackingCurrentTime() {
  8088. this.clearInterval(this.currentTimeInterval); // #1002 - if the video ends right before the next timeupdate would happen,
  8089. // the progress bar won't make it all the way to the end
  8090. this.trigger({
  8091. type: 'timeupdate',
  8092. target: this,
  8093. manuallyTriggered: true
  8094. });
  8095. }
  8096. /**
  8097. * Turn off all event polyfills, clear the `Tech`s {@link AudioTrackList},
  8098. * {@link VideoTrackList}, and {@link TextTrackList}, and dispose of this Tech.
  8099. *
  8100. * @fires Component#dispose
  8101. */
  8102. ;
  8103. _proto.dispose = function dispose() {
  8104. // clear out all tracks because we can't reuse them between techs
  8105. this.clearTracks(NORMAL.names); // Turn off any manual progress or timeupdate tracking
  8106. if (this.manualProgress) {
  8107. this.manualProgressOff();
  8108. }
  8109. if (this.manualTimeUpdates) {
  8110. this.manualTimeUpdatesOff();
  8111. }
  8112. _Component.prototype.dispose.call(this);
  8113. }
  8114. /**
  8115. * Clear out a single `TrackList` or an array of `TrackLists` given their names.
  8116. *
  8117. * > Note: Techs without source handlers should call this between sources for `video`
  8118. * & `audio` tracks. You don't want to use them between tracks!
  8119. *
  8120. * @param {string[]|string} types
  8121. * TrackList names to clear, valid names are `video`, `audio`, and
  8122. * `text`.
  8123. */
  8124. ;
  8125. _proto.clearTracks = function clearTracks(types) {
  8126. var _this3 = this;
  8127. types = [].concat(types); // clear out all tracks because we can't reuse them between techs
  8128. types.forEach(function (type) {
  8129. var list = _this3[type + "Tracks"]() || [];
  8130. var i = list.length;
  8131. while (i--) {
  8132. var track = list[i];
  8133. if (type === 'text') {
  8134. _this3.removeRemoteTextTrack(track);
  8135. }
  8136. list.removeTrack(track);
  8137. }
  8138. });
  8139. }
  8140. /**
  8141. * Remove any TextTracks added via addRemoteTextTrack that are
  8142. * flagged for automatic garbage collection
  8143. */
  8144. ;
  8145. _proto.cleanupAutoTextTracks = function cleanupAutoTextTracks() {
  8146. var list = this.autoRemoteTextTracks_ || [];
  8147. var i = list.length;
  8148. while (i--) {
  8149. var track = list[i];
  8150. this.removeRemoteTextTrack(track);
  8151. }
  8152. }
  8153. /**
  8154. * Reset the tech, which will removes all sources and reset the internal readyState.
  8155. *
  8156. * @abstract
  8157. */
  8158. ;
  8159. _proto.reset = function reset() {}
  8160. /**
  8161. * Get the value of `crossOrigin` from the tech.
  8162. *
  8163. * @abstract
  8164. *
  8165. * @see {Html5#crossOrigin}
  8166. */
  8167. ;
  8168. _proto.crossOrigin = function crossOrigin() {}
  8169. /**
  8170. * Set the value of `crossOrigin` on the tech.
  8171. *
  8172. * @abstract
  8173. *
  8174. * @param {string} crossOrigin the crossOrigin value
  8175. * @see {Html5#setCrossOrigin}
  8176. */
  8177. ;
  8178. _proto.setCrossOrigin = function setCrossOrigin() {}
  8179. /**
  8180. * Get or set an error on the Tech.
  8181. *
  8182. * @param {MediaError} [err]
  8183. * Error to set on the Tech
  8184. *
  8185. * @return {MediaError|null}
  8186. * The current error object on the tech, or null if there isn't one.
  8187. */
  8188. ;
  8189. _proto.error = function error(err) {
  8190. if (err !== undefined) {
  8191. this.error_ = new MediaError(err);
  8192. this.trigger('error');
  8193. }
  8194. return this.error_;
  8195. }
  8196. /**
  8197. * Returns the `TimeRange`s that have been played through for the current source.
  8198. *
  8199. * > NOTE: This implementation is incomplete. It does not track the played `TimeRange`.
  8200. * It only checks whether the source has played at all or not.
  8201. *
  8202. * @return {TimeRange}
  8203. * - A single time range if this video has played
  8204. * - An empty set of ranges if not.
  8205. */
  8206. ;
  8207. _proto.played = function played() {
  8208. if (this.hasStarted_) {
  8209. return createTimeRanges(0, 0);
  8210. }
  8211. return createTimeRanges();
  8212. }
  8213. /**
  8214. * Start playback
  8215. *
  8216. * @abstract
  8217. *
  8218. * @see {Html5#play}
  8219. */
  8220. ;
  8221. _proto.play = function play() {}
  8222. /**
  8223. * Set whether we are scrubbing or not
  8224. *
  8225. * @abstract
  8226. *
  8227. * @see {Html5#setScrubbing}
  8228. */
  8229. ;
  8230. _proto.setScrubbing = function setScrubbing() {}
  8231. /**
  8232. * Get whether we are scrubbing or not
  8233. *
  8234. * @abstract
  8235. *
  8236. * @see {Html5#scrubbing}
  8237. */
  8238. ;
  8239. _proto.scrubbing = function scrubbing() {}
  8240. /**
  8241. * Causes a manual time update to occur if {@link Tech#manualTimeUpdatesOn} was
  8242. * previously called.
  8243. *
  8244. * @fires Tech#timeupdate
  8245. */
  8246. ;
  8247. _proto.setCurrentTime = function setCurrentTime() {
  8248. // improve the accuracy of manual timeupdates
  8249. if (this.manualTimeUpdates) {
  8250. /**
  8251. * A manual `timeupdate` event.
  8252. *
  8253. * @event Tech#timeupdate
  8254. * @type {EventTarget~Event}
  8255. */
  8256. this.trigger({
  8257. type: 'timeupdate',
  8258. target: this,
  8259. manuallyTriggered: true
  8260. });
  8261. }
  8262. }
  8263. /**
  8264. * Turn on listeners for {@link VideoTrackList}, {@link {AudioTrackList}, and
  8265. * {@link TextTrackList} events.
  8266. *
  8267. * This adds {@link EventTarget~EventListeners} for `addtrack`, and `removetrack`.
  8268. *
  8269. * @fires Tech#audiotrackchange
  8270. * @fires Tech#videotrackchange
  8271. * @fires Tech#texttrackchange
  8272. */
  8273. ;
  8274. _proto.initTrackListeners = function initTrackListeners() {
  8275. var _this4 = this;
  8276. /**
  8277. * Triggered when tracks are added or removed on the Tech {@link AudioTrackList}
  8278. *
  8279. * @event Tech#audiotrackchange
  8280. * @type {EventTarget~Event}
  8281. */
  8282. /**
  8283. * Triggered when tracks are added or removed on the Tech {@link VideoTrackList}
  8284. *
  8285. * @event Tech#videotrackchange
  8286. * @type {EventTarget~Event}
  8287. */
  8288. /**
  8289. * Triggered when tracks are added or removed on the Tech {@link TextTrackList}
  8290. *
  8291. * @event Tech#texttrackchange
  8292. * @type {EventTarget~Event}
  8293. */
  8294. NORMAL.names.forEach(function (name) {
  8295. var props = NORMAL[name];
  8296. var trackListChanges = function trackListChanges() {
  8297. _this4.trigger(name + "trackchange");
  8298. };
  8299. var tracks = _this4[props.getterName]();
  8300. tracks.addEventListener('removetrack', trackListChanges);
  8301. tracks.addEventListener('addtrack', trackListChanges);
  8302. _this4.on('dispose', function () {
  8303. tracks.removeEventListener('removetrack', trackListChanges);
  8304. tracks.removeEventListener('addtrack', trackListChanges);
  8305. });
  8306. });
  8307. }
  8308. /**
  8309. * Emulate TextTracks using vtt.js if necessary
  8310. *
  8311. * @fires Tech#vttjsloaded
  8312. * @fires Tech#vttjserror
  8313. */
  8314. ;
  8315. _proto.addWebVttScript_ = function addWebVttScript_() {
  8316. var _this5 = this;
  8317. if (window.WebVTT) {
  8318. return;
  8319. } // Initially, Tech.el_ is a child of a dummy-div wait until the Component system
  8320. // signals that the Tech is ready at which point Tech.el_ is part of the DOM
  8321. // before inserting the WebVTT script
  8322. if (document.body.contains(this.el())) {
  8323. // load via require if available and vtt.js script location was not passed in
  8324. // as an option. novtt builds will turn the above require call into an empty object
  8325. // which will cause this if check to always fail.
  8326. if (!this.options_['vtt.js'] && isPlain(vtt) && Object.keys(vtt).length > 0) {
  8327. this.trigger('vttjsloaded');
  8328. return;
  8329. } // load vtt.js via the script location option or the cdn of no location was
  8330. // passed in
  8331. var script = document.createElement('script');
  8332. script.src = this.options_['vtt.js'] || 'https://vjs.zencdn.net/vttjs/0.14.1/vtt.min.js';
  8333. script.onload = function () {
  8334. /**
  8335. * Fired when vtt.js is loaded.
  8336. *
  8337. * @event Tech#vttjsloaded
  8338. * @type {EventTarget~Event}
  8339. */
  8340. _this5.trigger('vttjsloaded');
  8341. };
  8342. script.onerror = function () {
  8343. /**
  8344. * Fired when vtt.js was not loaded due to an error
  8345. *
  8346. * @event Tech#vttjsloaded
  8347. * @type {EventTarget~Event}
  8348. */
  8349. _this5.trigger('vttjserror');
  8350. };
  8351. this.on('dispose', function () {
  8352. script.onload = null;
  8353. script.onerror = null;
  8354. }); // but have not loaded yet and we set it to true before the inject so that
  8355. // we don't overwrite the injected window.WebVTT if it loads right away
  8356. window.WebVTT = true;
  8357. this.el().parentNode.appendChild(script);
  8358. } else {
  8359. this.ready(this.addWebVttScript_);
  8360. }
  8361. }
  8362. /**
  8363. * Emulate texttracks
  8364. *
  8365. */
  8366. ;
  8367. _proto.emulateTextTracks = function emulateTextTracks() {
  8368. var _this6 = this;
  8369. var tracks = this.textTracks();
  8370. var remoteTracks = this.remoteTextTracks();
  8371. var handleAddTrack = function handleAddTrack(e) {
  8372. return tracks.addTrack(e.track);
  8373. };
  8374. var handleRemoveTrack = function handleRemoveTrack(e) {
  8375. return tracks.removeTrack(e.track);
  8376. };
  8377. remoteTracks.on('addtrack', handleAddTrack);
  8378. remoteTracks.on('removetrack', handleRemoveTrack);
  8379. this.addWebVttScript_();
  8380. var updateDisplay = function updateDisplay() {
  8381. return _this6.trigger('texttrackchange');
  8382. };
  8383. var textTracksChanges = function textTracksChanges() {
  8384. updateDisplay();
  8385. for (var i = 0; i < tracks.length; i++) {
  8386. var track = tracks[i];
  8387. track.removeEventListener('cuechange', updateDisplay);
  8388. if (track.mode === 'showing') {
  8389. track.addEventListener('cuechange', updateDisplay);
  8390. }
  8391. }
  8392. };
  8393. textTracksChanges();
  8394. tracks.addEventListener('change', textTracksChanges);
  8395. tracks.addEventListener('addtrack', textTracksChanges);
  8396. tracks.addEventListener('removetrack', textTracksChanges);
  8397. this.on('dispose', function () {
  8398. remoteTracks.off('addtrack', handleAddTrack);
  8399. remoteTracks.off('removetrack', handleRemoveTrack);
  8400. tracks.removeEventListener('change', textTracksChanges);
  8401. tracks.removeEventListener('addtrack', textTracksChanges);
  8402. tracks.removeEventListener('removetrack', textTracksChanges);
  8403. for (var i = 0; i < tracks.length; i++) {
  8404. var track = tracks[i];
  8405. track.removeEventListener('cuechange', updateDisplay);
  8406. }
  8407. });
  8408. }
  8409. /**
  8410. * Create and returns a remote {@link TextTrack} object.
  8411. *
  8412. * @param {string} kind
  8413. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  8414. *
  8415. * @param {string} [label]
  8416. * Label to identify the text track
  8417. *
  8418. * @param {string} [language]
  8419. * Two letter language abbreviation
  8420. *
  8421. * @return {TextTrack}
  8422. * The TextTrack that gets created.
  8423. */
  8424. ;
  8425. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  8426. if (!kind) {
  8427. throw new Error('TextTrack kind is required but was not provided');
  8428. }
  8429. return createTrackHelper(this, kind, label, language);
  8430. }
  8431. /**
  8432. * Create an emulated TextTrack for use by addRemoteTextTrack
  8433. *
  8434. * This is intended to be overridden by classes that inherit from
  8435. * Tech in order to create native or custom TextTracks.
  8436. *
  8437. * @param {Object} options
  8438. * The object should contain the options to initialize the TextTrack with.
  8439. *
  8440. * @param {string} [options.kind]
  8441. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  8442. *
  8443. * @param {string} [options.label].
  8444. * Label to identify the text track
  8445. *
  8446. * @param {string} [options.language]
  8447. * Two letter language abbreviation.
  8448. *
  8449. * @return {HTMLTrackElement}
  8450. * The track element that gets created.
  8451. */
  8452. ;
  8453. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  8454. var track = mergeOptions(options, {
  8455. tech: this
  8456. });
  8457. return new REMOTE.remoteTextEl.TrackClass(track);
  8458. }
  8459. /**
  8460. * Creates a remote text track object and returns an html track element.
  8461. *
  8462. * > Note: This can be an emulated {@link HTMLTrackElement} or a native one.
  8463. *
  8464. * @param {Object} options
  8465. * See {@link Tech#createRemoteTextTrack} for more detailed properties.
  8466. *
  8467. * @param {boolean} [manualCleanup=true]
  8468. * - When false: the TextTrack will be automatically removed from the video
  8469. * element whenever the source changes
  8470. * - When True: The TextTrack will have to be cleaned up manually
  8471. *
  8472. * @return {HTMLTrackElement}
  8473. * An Html Track Element.
  8474. *
  8475. * @deprecated The default functionality for this function will be equivalent
  8476. * to "manualCleanup=false" in the future. The manualCleanup parameter will
  8477. * also be removed.
  8478. */
  8479. ;
  8480. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  8481. var _this7 = this;
  8482. if (options === void 0) {
  8483. options = {};
  8484. }
  8485. var htmlTrackElement = this.createRemoteTextTrack(options);
  8486. if (manualCleanup !== true && manualCleanup !== false) {
  8487. // deprecation warning
  8488. log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js');
  8489. manualCleanup = true;
  8490. } // store HTMLTrackElement and TextTrack to remote list
  8491. this.remoteTextTrackEls().addTrackElement_(htmlTrackElement);
  8492. this.remoteTextTracks().addTrack(htmlTrackElement.track);
  8493. if (manualCleanup !== true) {
  8494. // create the TextTrackList if it doesn't exist
  8495. this.ready(function () {
  8496. return _this7.autoRemoteTextTracks_.addTrack(htmlTrackElement.track);
  8497. });
  8498. }
  8499. return htmlTrackElement;
  8500. }
  8501. /**
  8502. * Remove a remote text track from the remote `TextTrackList`.
  8503. *
  8504. * @param {TextTrack} track
  8505. * `TextTrack` to remove from the `TextTrackList`
  8506. */
  8507. ;
  8508. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  8509. var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track); // remove HTMLTrackElement and TextTrack from remote list
  8510. this.remoteTextTrackEls().removeTrackElement_(trackElement);
  8511. this.remoteTextTracks().removeTrack(track);
  8512. this.autoRemoteTextTracks_.removeTrack(track);
  8513. }
  8514. /**
  8515. * Gets available media playback quality metrics as specified by the W3C's Media
  8516. * Playback Quality API.
  8517. *
  8518. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  8519. *
  8520. * @return {Object}
  8521. * An object with supported media playback quality metrics
  8522. *
  8523. * @abstract
  8524. */
  8525. ;
  8526. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  8527. return {};
  8528. }
  8529. /**
  8530. * Attempt to create a floating video window always on top of other windows
  8531. * so that users may continue consuming media while they interact with other
  8532. * content sites, or applications on their device.
  8533. *
  8534. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  8535. *
  8536. * @return {Promise|undefined}
  8537. * A promise with a Picture-in-Picture window if the browser supports
  8538. * Promises (or one was passed in as an option). It returns undefined
  8539. * otherwise.
  8540. *
  8541. * @abstract
  8542. */
  8543. ;
  8544. _proto.requestPictureInPicture = function requestPictureInPicture() {
  8545. var PromiseClass = this.options_.Promise || window.Promise;
  8546. if (PromiseClass) {
  8547. return PromiseClass.reject();
  8548. }
  8549. }
  8550. /**
  8551. * A method to check for the value of the 'disablePictureInPicture' <video> property.
  8552. * Defaults to true, as it should be considered disabled if the tech does not support pip
  8553. *
  8554. * @abstract
  8555. */
  8556. ;
  8557. _proto.disablePictureInPicture = function disablePictureInPicture() {
  8558. return true;
  8559. }
  8560. /**
  8561. * A method to set or unset the 'disablePictureInPicture' <video> property.
  8562. *
  8563. * @abstract
  8564. */
  8565. ;
  8566. _proto.setDisablePictureInPicture = function setDisablePictureInPicture() {}
  8567. /**
  8568. * A fallback implementation of requestVideoFrameCallback using requestAnimationFrame
  8569. *
  8570. * @param {function} cb
  8571. * @return {number} request id
  8572. */
  8573. ;
  8574. _proto.requestVideoFrameCallback = function requestVideoFrameCallback(cb) {
  8575. var _this8 = this;
  8576. var id = newGUID();
  8577. if (!this.isReady_ || this.paused()) {
  8578. this.queuedHanders_.add(id);
  8579. this.one('playing', function () {
  8580. if (_this8.queuedHanders_.has(id)) {
  8581. _this8.queuedHanders_["delete"](id);
  8582. cb();
  8583. }
  8584. });
  8585. } else {
  8586. this.requestNamedAnimationFrame(id, cb);
  8587. }
  8588. return id;
  8589. }
  8590. /**
  8591. * A fallback implementation of cancelVideoFrameCallback
  8592. *
  8593. * @param {number} id id of callback to be cancelled
  8594. */
  8595. ;
  8596. _proto.cancelVideoFrameCallback = function cancelVideoFrameCallback(id) {
  8597. if (this.queuedHanders_.has(id)) {
  8598. this.queuedHanders_["delete"](id);
  8599. } else {
  8600. this.cancelNamedAnimationFrame(id);
  8601. }
  8602. }
  8603. /**
  8604. * A method to set a poster from a `Tech`.
  8605. *
  8606. * @abstract
  8607. */
  8608. ;
  8609. _proto.setPoster = function setPoster() {}
  8610. /**
  8611. * A method to check for the presence of the 'playsinline' <video> attribute.
  8612. *
  8613. * @abstract
  8614. */
  8615. ;
  8616. _proto.playsinline = function playsinline() {}
  8617. /**
  8618. * A method to set or unset the 'playsinline' <video> attribute.
  8619. *
  8620. * @abstract
  8621. */
  8622. ;
  8623. _proto.setPlaysinline = function setPlaysinline() {}
  8624. /**
  8625. * Attempt to force override of native audio tracks.
  8626. *
  8627. * @param {boolean} override - If set to true native audio will be overridden,
  8628. * otherwise native audio will potentially be used.
  8629. *
  8630. * @abstract
  8631. */
  8632. ;
  8633. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks() {}
  8634. /**
  8635. * Attempt to force override of native video tracks.
  8636. *
  8637. * @param {boolean} override - If set to true native video will be overridden,
  8638. * otherwise native video will potentially be used.
  8639. *
  8640. * @abstract
  8641. */
  8642. ;
  8643. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks() {}
  8644. /*
  8645. * Check if the tech can support the given mime-type.
  8646. *
  8647. * The base tech does not support any type, but source handlers might
  8648. * overwrite this.
  8649. *
  8650. * @param {string} type
  8651. * The mimetype to check for support
  8652. *
  8653. * @return {string}
  8654. * 'probably', 'maybe', or empty string
  8655. *
  8656. * @see [Spec]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType}
  8657. *
  8658. * @abstract
  8659. */
  8660. ;
  8661. _proto.canPlayType = function canPlayType() {
  8662. return '';
  8663. }
  8664. /**
  8665. * Check if the type is supported by this tech.
  8666. *
  8667. * The base tech does not support any type, but source handlers might
  8668. * overwrite this.
  8669. *
  8670. * @param {string} type
  8671. * The media type to check
  8672. * @return {string} Returns the native video element's response
  8673. */
  8674. ;
  8675. Tech.canPlayType = function canPlayType() {
  8676. return '';
  8677. }
  8678. /**
  8679. * Check if the tech can support the given source
  8680. *
  8681. * @param {Object} srcObj
  8682. * The source object
  8683. * @param {Object} options
  8684. * The options passed to the tech
  8685. * @return {string} 'probably', 'maybe', or '' (empty string)
  8686. */
  8687. ;
  8688. Tech.canPlaySource = function canPlaySource(srcObj, options) {
  8689. return Tech.canPlayType(srcObj.type);
  8690. }
  8691. /*
  8692. * Return whether the argument is a Tech or not.
  8693. * Can be passed either a Class like `Html5` or a instance like `player.tech_`
  8694. *
  8695. * @param {Object} component
  8696. * The item to check
  8697. *
  8698. * @return {boolean}
  8699. * Whether it is a tech or not
  8700. * - True if it is a tech
  8701. * - False if it is not
  8702. */
  8703. ;
  8704. Tech.isTech = function isTech(component) {
  8705. return component.prototype instanceof Tech || component instanceof Tech || component === Tech;
  8706. }
  8707. /**
  8708. * Registers a `Tech` into a shared list for videojs.
  8709. *
  8710. * @param {string} name
  8711. * Name of the `Tech` to register.
  8712. *
  8713. * @param {Object} tech
  8714. * The `Tech` class to register.
  8715. */
  8716. ;
  8717. Tech.registerTech = function registerTech(name, tech) {
  8718. if (!Tech.techs_) {
  8719. Tech.techs_ = {};
  8720. }
  8721. if (!Tech.isTech(tech)) {
  8722. throw new Error("Tech " + name + " must be a Tech");
  8723. }
  8724. if (!Tech.canPlayType) {
  8725. throw new Error('Techs must have a static canPlayType method on them');
  8726. }
  8727. if (!Tech.canPlaySource) {
  8728. throw new Error('Techs must have a static canPlaySource method on them');
  8729. }
  8730. name = toTitleCase(name);
  8731. Tech.techs_[name] = tech;
  8732. Tech.techs_[toLowerCase(name)] = tech;
  8733. if (name !== 'Tech') {
  8734. // camel case the techName for use in techOrder
  8735. Tech.defaultTechOrder_.push(name);
  8736. }
  8737. return tech;
  8738. }
  8739. /**
  8740. * Get a `Tech` from the shared list by name.
  8741. *
  8742. * @param {string} name
  8743. * `camelCase` or `TitleCase` name of the Tech to get
  8744. *
  8745. * @return {Tech|undefined}
  8746. * The `Tech` or undefined if there was no tech with the name requested.
  8747. */
  8748. ;
  8749. Tech.getTech = function getTech(name) {
  8750. if (!name) {
  8751. return;
  8752. }
  8753. if (Tech.techs_ && Tech.techs_[name]) {
  8754. return Tech.techs_[name];
  8755. }
  8756. name = toTitleCase(name);
  8757. if (window && window.videojs && window.videojs[name]) {
  8758. log.warn("The " + name + " tech was added to the videojs object when it should be registered using videojs.registerTech(name, tech)");
  8759. return window.videojs[name];
  8760. }
  8761. };
  8762. return Tech;
  8763. }(Component);
  8764. /**
  8765. * Get the {@link VideoTrackList}
  8766. *
  8767. * @returns {VideoTrackList}
  8768. * @method Tech.prototype.videoTracks
  8769. */
  8770. /**
  8771. * Get the {@link AudioTrackList}
  8772. *
  8773. * @returns {AudioTrackList}
  8774. * @method Tech.prototype.audioTracks
  8775. */
  8776. /**
  8777. * Get the {@link TextTrackList}
  8778. *
  8779. * @returns {TextTrackList}
  8780. * @method Tech.prototype.textTracks
  8781. */
  8782. /**
  8783. * Get the remote element {@link TextTrackList}
  8784. *
  8785. * @returns {TextTrackList}
  8786. * @method Tech.prototype.remoteTextTracks
  8787. */
  8788. /**
  8789. * Get the remote element {@link HtmlTrackElementList}
  8790. *
  8791. * @returns {HtmlTrackElementList}
  8792. * @method Tech.prototype.remoteTextTrackEls
  8793. */
  8794. ALL.names.forEach(function (name) {
  8795. var props = ALL[name];
  8796. Tech.prototype[props.getterName] = function () {
  8797. this[props.privateName] = this[props.privateName] || new props.ListClass();
  8798. return this[props.privateName];
  8799. };
  8800. });
  8801. /**
  8802. * List of associated text tracks
  8803. *
  8804. * @type {TextTrackList}
  8805. * @private
  8806. * @property Tech#textTracks_
  8807. */
  8808. /**
  8809. * List of associated audio tracks.
  8810. *
  8811. * @type {AudioTrackList}
  8812. * @private
  8813. * @property Tech#audioTracks_
  8814. */
  8815. /**
  8816. * List of associated video tracks.
  8817. *
  8818. * @type {VideoTrackList}
  8819. * @private
  8820. * @property Tech#videoTracks_
  8821. */
  8822. /**
  8823. * Boolean indicating whether the `Tech` supports volume control.
  8824. *
  8825. * @type {boolean}
  8826. * @default
  8827. */
  8828. Tech.prototype.featuresVolumeControl = true;
  8829. /**
  8830. * Boolean indicating whether the `Tech` supports muting volume.
  8831. *
  8832. * @type {bolean}
  8833. * @default
  8834. */
  8835. Tech.prototype.featuresMuteControl = true;
  8836. /**
  8837. * Boolean indicating whether the `Tech` supports fullscreen resize control.
  8838. * Resizing plugins using request fullscreen reloads the plugin
  8839. *
  8840. * @type {boolean}
  8841. * @default
  8842. */
  8843. Tech.prototype.featuresFullscreenResize = false;
  8844. /**
  8845. * Boolean indicating whether the `Tech` supports changing the speed at which the video
  8846. * plays. Examples:
  8847. * - Set player to play 2x (twice) as fast
  8848. * - Set player to play 0.5x (half) as fast
  8849. *
  8850. * @type {boolean}
  8851. * @default
  8852. */
  8853. Tech.prototype.featuresPlaybackRate = false;
  8854. /**
  8855. * Boolean indicating whether the `Tech` supports the `progress` event. This is currently
  8856. * not triggered by video-js-swf. This will be used to determine if
  8857. * {@link Tech#manualProgressOn} should be called.
  8858. *
  8859. * @type {boolean}
  8860. * @default
  8861. */
  8862. Tech.prototype.featuresProgressEvents = false;
  8863. /**
  8864. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  8865. *
  8866. * A tech should set this to `true` and then use {@link Tech#triggerSourceset}
  8867. * to trigger a {@link Tech#event:sourceset} at the earliest time after getting
  8868. * a new source.
  8869. *
  8870. * @type {boolean}
  8871. * @default
  8872. */
  8873. Tech.prototype.featuresSourceset = false;
  8874. /**
  8875. * Boolean indicating whether the `Tech` supports the `timeupdate` event. This is currently
  8876. * not triggered by video-js-swf. This will be used to determine if
  8877. * {@link Tech#manualTimeUpdates} should be called.
  8878. *
  8879. * @type {boolean}
  8880. * @default
  8881. */
  8882. Tech.prototype.featuresTimeupdateEvents = false;
  8883. /**
  8884. * Boolean indicating whether the `Tech` supports the native `TextTrack`s.
  8885. * This will help us integrate with native `TextTrack`s if the browser supports them.
  8886. *
  8887. * @type {boolean}
  8888. * @default
  8889. */
  8890. Tech.prototype.featuresNativeTextTracks = false;
  8891. /**
  8892. * Boolean indicating whether the `Tech` supports `requestVideoFrameCallback`.
  8893. *
  8894. * @type {boolean}
  8895. * @default
  8896. */
  8897. Tech.prototype.featuresVideoFrameCallback = false;
  8898. /**
  8899. * A functional mixin for techs that want to use the Source Handler pattern.
  8900. * Source handlers are scripts for handling specific formats.
  8901. * The source handler pattern is used for adaptive formats (HLS, DASH) that
  8902. * manually load video data and feed it into a Source Buffer (Media Source Extensions)
  8903. * Example: `Tech.withSourceHandlers.call(MyTech);`
  8904. *
  8905. * @param {Tech} _Tech
  8906. * The tech to add source handler functions to.
  8907. *
  8908. * @mixes Tech~SourceHandlerAdditions
  8909. */
  8910. Tech.withSourceHandlers = function (_Tech) {
  8911. /**
  8912. * Register a source handler
  8913. *
  8914. * @param {Function} handler
  8915. * The source handler class
  8916. *
  8917. * @param {number} [index]
  8918. * Register it at the following index
  8919. */
  8920. _Tech.registerSourceHandler = function (handler, index) {
  8921. var handlers = _Tech.sourceHandlers;
  8922. if (!handlers) {
  8923. handlers = _Tech.sourceHandlers = [];
  8924. }
  8925. if (index === undefined) {
  8926. // add to the end of the list
  8927. index = handlers.length;
  8928. }
  8929. handlers.splice(index, 0, handler);
  8930. };
  8931. /**
  8932. * Check if the tech can support the given type. Also checks the
  8933. * Techs sourceHandlers.
  8934. *
  8935. * @param {string} type
  8936. * The mimetype to check.
  8937. *
  8938. * @return {string}
  8939. * 'probably', 'maybe', or '' (empty string)
  8940. */
  8941. _Tech.canPlayType = function (type) {
  8942. var handlers = _Tech.sourceHandlers || [];
  8943. var can;
  8944. for (var i = 0; i < handlers.length; i++) {
  8945. can = handlers[i].canPlayType(type);
  8946. if (can) {
  8947. return can;
  8948. }
  8949. }
  8950. return '';
  8951. };
  8952. /**
  8953. * Returns the first source handler that supports the source.
  8954. *
  8955. * TODO: Answer question: should 'probably' be prioritized over 'maybe'
  8956. *
  8957. * @param {Tech~SourceObject} source
  8958. * The source object
  8959. *
  8960. * @param {Object} options
  8961. * The options passed to the tech
  8962. *
  8963. * @return {SourceHandler|null}
  8964. * The first source handler that supports the source or null if
  8965. * no SourceHandler supports the source
  8966. */
  8967. _Tech.selectSourceHandler = function (source, options) {
  8968. var handlers = _Tech.sourceHandlers || [];
  8969. var can;
  8970. for (var i = 0; i < handlers.length; i++) {
  8971. can = handlers[i].canHandleSource(source, options);
  8972. if (can) {
  8973. return handlers[i];
  8974. }
  8975. }
  8976. return null;
  8977. };
  8978. /**
  8979. * Check if the tech can support the given source.
  8980. *
  8981. * @param {Tech~SourceObject} srcObj
  8982. * The source object
  8983. *
  8984. * @param {Object} options
  8985. * The options passed to the tech
  8986. *
  8987. * @return {string}
  8988. * 'probably', 'maybe', or '' (empty string)
  8989. */
  8990. _Tech.canPlaySource = function (srcObj, options) {
  8991. var sh = _Tech.selectSourceHandler(srcObj, options);
  8992. if (sh) {
  8993. return sh.canHandleSource(srcObj, options);
  8994. }
  8995. return '';
  8996. };
  8997. /**
  8998. * When using a source handler, prefer its implementation of
  8999. * any function normally provided by the tech.
  9000. */
  9001. var deferrable = ['seekable', 'seeking', 'duration'];
  9002. /**
  9003. * A wrapper around {@link Tech#seekable} that will call a `SourceHandler`s seekable
  9004. * function if it exists, with a fallback to the Techs seekable function.
  9005. *
  9006. * @method _Tech.seekable
  9007. */
  9008. /**
  9009. * A wrapper around {@link Tech#duration} that will call a `SourceHandler`s duration
  9010. * function if it exists, otherwise it will fallback to the techs duration function.
  9011. *
  9012. * @method _Tech.duration
  9013. */
  9014. deferrable.forEach(function (fnName) {
  9015. var originalFn = this[fnName];
  9016. if (typeof originalFn !== 'function') {
  9017. return;
  9018. }
  9019. this[fnName] = function () {
  9020. if (this.sourceHandler_ && this.sourceHandler_[fnName]) {
  9021. return this.sourceHandler_[fnName].apply(this.sourceHandler_, arguments);
  9022. }
  9023. return originalFn.apply(this, arguments);
  9024. };
  9025. }, _Tech.prototype);
  9026. /**
  9027. * Create a function for setting the source using a source object
  9028. * and source handlers.
  9029. * Should never be called unless a source handler was found.
  9030. *
  9031. * @param {Tech~SourceObject} source
  9032. * A source object with src and type keys
  9033. */
  9034. _Tech.prototype.setSource = function (source) {
  9035. var sh = _Tech.selectSourceHandler(source, this.options_);
  9036. if (!sh) {
  9037. // Fall back to a native source hander when unsupported sources are
  9038. // deliberately set
  9039. if (_Tech.nativeSourceHandler) {
  9040. sh = _Tech.nativeSourceHandler;
  9041. } else {
  9042. log.error('No source handler found for the current source.');
  9043. }
  9044. } // Dispose any existing source handler
  9045. this.disposeSourceHandler();
  9046. this.off('dispose', this.disposeSourceHandler_);
  9047. if (sh !== _Tech.nativeSourceHandler) {
  9048. this.currentSource_ = source;
  9049. }
  9050. this.sourceHandler_ = sh.handleSource(source, this, this.options_);
  9051. this.one('dispose', this.disposeSourceHandler_);
  9052. };
  9053. /**
  9054. * Clean up any existing SourceHandlers and listeners when the Tech is disposed.
  9055. *
  9056. * @listens Tech#dispose
  9057. */
  9058. _Tech.prototype.disposeSourceHandler = function () {
  9059. // if we have a source and get another one
  9060. // then we are loading something new
  9061. // than clear all of our current tracks
  9062. if (this.currentSource_) {
  9063. this.clearTracks(['audio', 'video']);
  9064. this.currentSource_ = null;
  9065. } // always clean up auto-text tracks
  9066. this.cleanupAutoTextTracks();
  9067. if (this.sourceHandler_) {
  9068. if (this.sourceHandler_.dispose) {
  9069. this.sourceHandler_.dispose();
  9070. }
  9071. this.sourceHandler_ = null;
  9072. }
  9073. };
  9074. }; // The base Tech class needs to be registered as a Component. It is the only
  9075. // Tech that can be registered as a Component.
  9076. Component.registerComponent('Tech', Tech);
  9077. Tech.registerTech('Tech', Tech);
  9078. /**
  9079. * A list of techs that should be added to techOrder on Players
  9080. *
  9081. * @private
  9082. */
  9083. Tech.defaultTechOrder_ = [];
  9084. /**
  9085. * @file middleware.js
  9086. * @module middleware
  9087. */
  9088. var middlewares = {};
  9089. var middlewareInstances = {};
  9090. var TERMINATOR = {};
  9091. /**
  9092. * A middleware object is a plain JavaScript object that has methods that
  9093. * match the {@link Tech} methods found in the lists of allowed
  9094. * {@link module:middleware.allowedGetters|getters},
  9095. * {@link module:middleware.allowedSetters|setters}, and
  9096. * {@link module:middleware.allowedMediators|mediators}.
  9097. *
  9098. * @typedef {Object} MiddlewareObject
  9099. */
  9100. /**
  9101. * A middleware factory function that should return a
  9102. * {@link module:middleware~MiddlewareObject|MiddlewareObject}.
  9103. *
  9104. * This factory will be called for each player when needed, with the player
  9105. * passed in as an argument.
  9106. *
  9107. * @callback MiddlewareFactory
  9108. * @param {Player} player
  9109. * A Video.js player.
  9110. */
  9111. /**
  9112. * Define a middleware that the player should use by way of a factory function
  9113. * that returns a middleware object.
  9114. *
  9115. * @param {string} type
  9116. * The MIME type to match or `"*"` for all MIME types.
  9117. *
  9118. * @param {MiddlewareFactory} middleware
  9119. * A middleware factory function that will be executed for
  9120. * matching types.
  9121. */
  9122. function use(type, middleware) {
  9123. middlewares[type] = middlewares[type] || [];
  9124. middlewares[type].push(middleware);
  9125. }
  9126. /**
  9127. * Asynchronously sets a source using middleware by recursing through any
  9128. * matching middlewares and calling `setSource` on each, passing along the
  9129. * previous returned value each time.
  9130. *
  9131. * @param {Player} player
  9132. * A {@link Player} instance.
  9133. *
  9134. * @param {Tech~SourceObject} src
  9135. * A source object.
  9136. *
  9137. * @param {Function}
  9138. * The next middleware to run.
  9139. */
  9140. function setSource(player, src, next) {
  9141. player.setTimeout(function () {
  9142. return setSourceHelper(src, middlewares[src.type], next, player);
  9143. }, 1);
  9144. }
  9145. /**
  9146. * When the tech is set, passes the tech to each middleware's `setTech` method.
  9147. *
  9148. * @param {Object[]} middleware
  9149. * An array of middleware instances.
  9150. *
  9151. * @param {Tech} tech
  9152. * A Video.js tech.
  9153. */
  9154. function setTech(middleware, tech) {
  9155. middleware.forEach(function (mw) {
  9156. return mw.setTech && mw.setTech(tech);
  9157. });
  9158. }
  9159. /**
  9160. * Calls a getter on the tech first, through each middleware
  9161. * from right to left to the player.
  9162. *
  9163. * @param {Object[]} middleware
  9164. * An array of middleware instances.
  9165. *
  9166. * @param {Tech} tech
  9167. * The current tech.
  9168. *
  9169. * @param {string} method
  9170. * A method name.
  9171. *
  9172. * @return {Mixed}
  9173. * The final value from the tech after middleware has intercepted it.
  9174. */
  9175. function get(middleware, tech, method) {
  9176. return middleware.reduceRight(middlewareIterator(method), tech[method]());
  9177. }
  9178. /**
  9179. * Takes the argument given to the player and calls the setter method on each
  9180. * middleware from left to right to the tech.
  9181. *
  9182. * @param {Object[]} middleware
  9183. * An array of middleware instances.
  9184. *
  9185. * @param {Tech} tech
  9186. * The current tech.
  9187. *
  9188. * @param {string} method
  9189. * A method name.
  9190. *
  9191. * @param {Mixed} arg
  9192. * The value to set on the tech.
  9193. *
  9194. * @return {Mixed}
  9195. * The return value of the `method` of the `tech`.
  9196. */
  9197. function set(middleware, tech, method, arg) {
  9198. return tech[method](middleware.reduce(middlewareIterator(method), arg));
  9199. }
  9200. /**
  9201. * Takes the argument given to the player and calls the `call` version of the
  9202. * method on each middleware from left to right.
  9203. *
  9204. * Then, call the passed in method on the tech and return the result unchanged
  9205. * back to the player, through middleware, this time from right to left.
  9206. *
  9207. * @param {Object[]} middleware
  9208. * An array of middleware instances.
  9209. *
  9210. * @param {Tech} tech
  9211. * The current tech.
  9212. *
  9213. * @param {string} method
  9214. * A method name.
  9215. *
  9216. * @param {Mixed} arg
  9217. * The value to set on the tech.
  9218. *
  9219. * @return {Mixed}
  9220. * The return value of the `method` of the `tech`, regardless of the
  9221. * return values of middlewares.
  9222. */
  9223. function mediate(middleware, tech, method, arg) {
  9224. if (arg === void 0) {
  9225. arg = null;
  9226. }
  9227. var callMethod = 'call' + toTitleCase(method);
  9228. var middlewareValue = middleware.reduce(middlewareIterator(callMethod), arg);
  9229. var terminated = middlewareValue === TERMINATOR; // deprecated. The `null` return value should instead return TERMINATOR to
  9230. // prevent confusion if a techs method actually returns null.
  9231. var returnValue = terminated ? null : tech[method](middlewareValue);
  9232. executeRight(middleware, method, returnValue, terminated);
  9233. return returnValue;
  9234. }
  9235. /**
  9236. * Enumeration of allowed getters where the keys are method names.
  9237. *
  9238. * @type {Object}
  9239. */
  9240. var allowedGetters = {
  9241. buffered: 1,
  9242. currentTime: 1,
  9243. duration: 1,
  9244. muted: 1,
  9245. played: 1,
  9246. paused: 1,
  9247. seekable: 1,
  9248. volume: 1,
  9249. ended: 1
  9250. };
  9251. /**
  9252. * Enumeration of allowed setters where the keys are method names.
  9253. *
  9254. * @type {Object}
  9255. */
  9256. var allowedSetters = {
  9257. setCurrentTime: 1,
  9258. setMuted: 1,
  9259. setVolume: 1
  9260. };
  9261. /**
  9262. * Enumeration of allowed mediators where the keys are method names.
  9263. *
  9264. * @type {Object}
  9265. */
  9266. var allowedMediators = {
  9267. play: 1,
  9268. pause: 1
  9269. };
  9270. function middlewareIterator(method) {
  9271. return function (value, mw) {
  9272. // if the previous middleware terminated, pass along the termination
  9273. if (value === TERMINATOR) {
  9274. return TERMINATOR;
  9275. }
  9276. if (mw[method]) {
  9277. return mw[method](value);
  9278. }
  9279. return value;
  9280. };
  9281. }
  9282. function executeRight(mws, method, value, terminated) {
  9283. for (var i = mws.length - 1; i >= 0; i--) {
  9284. var mw = mws[i];
  9285. if (mw[method]) {
  9286. mw[method](terminated, value);
  9287. }
  9288. }
  9289. }
  9290. /**
  9291. * Clear the middleware cache for a player.
  9292. *
  9293. * @param {Player} player
  9294. * A {@link Player} instance.
  9295. */
  9296. function clearCacheForPlayer(player) {
  9297. middlewareInstances[player.id()] = null;
  9298. }
  9299. /**
  9300. * {
  9301. * [playerId]: [[mwFactory, mwInstance], ...]
  9302. * }
  9303. *
  9304. * @private
  9305. */
  9306. function getOrCreateFactory(player, mwFactory) {
  9307. var mws = middlewareInstances[player.id()];
  9308. var mw = null;
  9309. if (mws === undefined || mws === null) {
  9310. mw = mwFactory(player);
  9311. middlewareInstances[player.id()] = [[mwFactory, mw]];
  9312. return mw;
  9313. }
  9314. for (var i = 0; i < mws.length; i++) {
  9315. var _mws$i = mws[i],
  9316. mwf = _mws$i[0],
  9317. mwi = _mws$i[1];
  9318. if (mwf !== mwFactory) {
  9319. continue;
  9320. }
  9321. mw = mwi;
  9322. }
  9323. if (mw === null) {
  9324. mw = mwFactory(player);
  9325. mws.push([mwFactory, mw]);
  9326. }
  9327. return mw;
  9328. }
  9329. function setSourceHelper(src, middleware, next, player, acc, lastRun) {
  9330. if (src === void 0) {
  9331. src = {};
  9332. }
  9333. if (middleware === void 0) {
  9334. middleware = [];
  9335. }
  9336. if (acc === void 0) {
  9337. acc = [];
  9338. }
  9339. if (lastRun === void 0) {
  9340. lastRun = false;
  9341. }
  9342. var _middleware = middleware,
  9343. mwFactory = _middleware[0],
  9344. mwrest = _middleware.slice(1); // if mwFactory is a string, then we're at a fork in the road
  9345. if (typeof mwFactory === 'string') {
  9346. setSourceHelper(src, middlewares[mwFactory], next, player, acc, lastRun); // if we have an mwFactory, call it with the player to get the mw,
  9347. // then call the mw's setSource method
  9348. } else if (mwFactory) {
  9349. var mw = getOrCreateFactory(player, mwFactory); // if setSource isn't present, implicitly select this middleware
  9350. if (!mw.setSource) {
  9351. acc.push(mw);
  9352. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  9353. }
  9354. mw.setSource(assign({}, src), function (err, _src) {
  9355. // something happened, try the next middleware on the current level
  9356. // make sure to use the old src
  9357. if (err) {
  9358. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  9359. } // we've succeeded, now we need to go deeper
  9360. acc.push(mw); // if it's the same type, continue down the current chain
  9361. // otherwise, we want to go down the new chain
  9362. setSourceHelper(_src, src.type === _src.type ? mwrest : middlewares[_src.type], next, player, acc, lastRun);
  9363. });
  9364. } else if (mwrest.length) {
  9365. setSourceHelper(src, mwrest, next, player, acc, lastRun);
  9366. } else if (lastRun) {
  9367. next(src, acc);
  9368. } else {
  9369. setSourceHelper(src, middlewares['*'], next, player, acc, true);
  9370. }
  9371. }
  9372. /**
  9373. * Mimetypes
  9374. *
  9375. * @see https://www.iana.org/assignments/media-types/media-types.xhtml
  9376. * @typedef Mimetypes~Kind
  9377. * @enum
  9378. */
  9379. var MimetypesKind = {
  9380. opus: 'video/ogg',
  9381. ogv: 'video/ogg',
  9382. mp4: 'video/mp4',
  9383. mov: 'video/mp4',
  9384. m4v: 'video/mp4',
  9385. mkv: 'video/x-matroska',
  9386. m4a: 'audio/mp4',
  9387. mp3: 'audio/mpeg',
  9388. aac: 'audio/aac',
  9389. caf: 'audio/x-caf',
  9390. flac: 'audio/flac',
  9391. oga: 'audio/ogg',
  9392. wav: 'audio/wav',
  9393. m3u8: 'application/x-mpegURL',
  9394. mpd: 'application/dash+xml',
  9395. jpg: 'image/jpeg',
  9396. jpeg: 'image/jpeg',
  9397. gif: 'image/gif',
  9398. png: 'image/png',
  9399. svg: 'image/svg+xml',
  9400. webp: 'image/webp'
  9401. };
  9402. /**
  9403. * Get the mimetype of a given src url if possible
  9404. *
  9405. * @param {string} src
  9406. * The url to the src
  9407. *
  9408. * @return {string}
  9409. * return the mimetype if it was known or empty string otherwise
  9410. */
  9411. var getMimetype = function getMimetype(src) {
  9412. if (src === void 0) {
  9413. src = '';
  9414. }
  9415. var ext = getFileExtension(src);
  9416. var mimetype = MimetypesKind[ext.toLowerCase()];
  9417. return mimetype || '';
  9418. };
  9419. /**
  9420. * Find the mime type of a given source string if possible. Uses the player
  9421. * source cache.
  9422. *
  9423. * @param {Player} player
  9424. * The player object
  9425. *
  9426. * @param {string} src
  9427. * The source string
  9428. *
  9429. * @return {string}
  9430. * The type that was found
  9431. */
  9432. var findMimetype = function findMimetype(player, src) {
  9433. if (!src) {
  9434. return '';
  9435. } // 1. check for the type in the `source` cache
  9436. if (player.cache_.source.src === src && player.cache_.source.type) {
  9437. return player.cache_.source.type;
  9438. } // 2. see if we have this source in our `currentSources` cache
  9439. var matchingSources = player.cache_.sources.filter(function (s) {
  9440. return s.src === src;
  9441. });
  9442. if (matchingSources.length) {
  9443. return matchingSources[0].type;
  9444. } // 3. look for the src url in source elements and use the type there
  9445. var sources = player.$$('source');
  9446. for (var i = 0; i < sources.length; i++) {
  9447. var s = sources[i];
  9448. if (s.type && s.src && s.src === src) {
  9449. return s.type;
  9450. }
  9451. } // 4. finally fallback to our list of mime types based on src url extension
  9452. return getMimetype(src);
  9453. };
  9454. /**
  9455. * @module filter-source
  9456. */
  9457. /**
  9458. * Filter out single bad source objects or multiple source objects in an
  9459. * array. Also flattens nested source object arrays into a 1 dimensional
  9460. * array of source objects.
  9461. *
  9462. * @param {Tech~SourceObject|Tech~SourceObject[]} src
  9463. * The src object to filter
  9464. *
  9465. * @return {Tech~SourceObject[]}
  9466. * An array of sourceobjects containing only valid sources
  9467. *
  9468. * @private
  9469. */
  9470. var filterSource = function filterSource(src) {
  9471. // traverse array
  9472. if (Array.isArray(src)) {
  9473. var newsrc = [];
  9474. src.forEach(function (srcobj) {
  9475. srcobj = filterSource(srcobj);
  9476. if (Array.isArray(srcobj)) {
  9477. newsrc = newsrc.concat(srcobj);
  9478. } else if (isObject(srcobj)) {
  9479. newsrc.push(srcobj);
  9480. }
  9481. });
  9482. src = newsrc;
  9483. } else if (typeof src === 'string' && src.trim()) {
  9484. // convert string into object
  9485. src = [fixSource({
  9486. src: src
  9487. })];
  9488. } else if (isObject(src) && typeof src.src === 'string' && src.src && src.src.trim()) {
  9489. // src is already valid
  9490. src = [fixSource(src)];
  9491. } else {
  9492. // invalid source, turn it into an empty array
  9493. src = [];
  9494. }
  9495. return src;
  9496. };
  9497. /**
  9498. * Checks src mimetype, adding it when possible
  9499. *
  9500. * @param {Tech~SourceObject} src
  9501. * The src object to check
  9502. * @return {Tech~SourceObject}
  9503. * src Object with known type
  9504. */
  9505. function fixSource(src) {
  9506. if (!src.type) {
  9507. var mimetype = getMimetype(src.src);
  9508. if (mimetype) {
  9509. src.type = mimetype;
  9510. }
  9511. }
  9512. return src;
  9513. }
  9514. /**
  9515. * The `MediaLoader` is the `Component` that decides which playback technology to load
  9516. * when a player is initialized.
  9517. *
  9518. * @extends Component
  9519. */
  9520. var MediaLoader = /*#__PURE__*/function (_Component) {
  9521. inheritsLoose(MediaLoader, _Component);
  9522. /**
  9523. * Create an instance of this class.
  9524. *
  9525. * @param {Player} player
  9526. * The `Player` that this class should attach to.
  9527. *
  9528. * @param {Object} [options]
  9529. * The key/value store of player options.
  9530. *
  9531. * @param {Component~ReadyCallback} [ready]
  9532. * The function that is run when this component is ready.
  9533. */
  9534. function MediaLoader(player, options, ready) {
  9535. var _this;
  9536. // MediaLoader has no element
  9537. var options_ = mergeOptions({
  9538. createEl: false
  9539. }, options);
  9540. _this = _Component.call(this, player, options_, ready) || this; // If there are no sources when the player is initialized,
  9541. // load the first supported playback technology.
  9542. if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
  9543. for (var i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
  9544. var techName = toTitleCase(j[i]);
  9545. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  9546. // Remove once that deprecated behavior is removed.
  9547. if (!techName) {
  9548. tech = Component.getComponent(techName);
  9549. } // Check if the browser supports this technology
  9550. if (tech && tech.isSupported()) {
  9551. player.loadTech_(techName);
  9552. break;
  9553. }
  9554. }
  9555. } else {
  9556. // Loop through playback technologies (e.g. HTML5) and check for support.
  9557. // Then load the best source.
  9558. // A few assumptions here:
  9559. // All playback technologies respect preload false.
  9560. player.src(options.playerOptions.sources);
  9561. }
  9562. return _this;
  9563. }
  9564. return MediaLoader;
  9565. }(Component);
  9566. Component.registerComponent('MediaLoader', MediaLoader);
  9567. /**
  9568. * Component which is clickable or keyboard actionable, but is not a
  9569. * native HTML button.
  9570. *
  9571. * @extends Component
  9572. */
  9573. var ClickableComponent = /*#__PURE__*/function (_Component) {
  9574. inheritsLoose(ClickableComponent, _Component);
  9575. /**
  9576. * Creates an instance of this class.
  9577. *
  9578. * @param {Player} player
  9579. * The `Player` that this class should be attached to.
  9580. *
  9581. * @param {Object} [options]
  9582. * The key/value store of component options.
  9583. *
  9584. * @param {function} [options.clickHandler]
  9585. * The function to call when the button is clicked / activated
  9586. *
  9587. * @param {string} [options.controlText]
  9588. * The text to set on the button
  9589. *
  9590. * @param {string} [options.className]
  9591. * A class or space separated list of classes to add the component
  9592. *
  9593. */
  9594. function ClickableComponent(player, options) {
  9595. var _this;
  9596. _this = _Component.call(this, player, options) || this;
  9597. if (_this.options_.controlText) {
  9598. _this.controlText(_this.options_.controlText);
  9599. }
  9600. _this.handleMouseOver_ = function (e) {
  9601. return _this.handleMouseOver(e);
  9602. };
  9603. _this.handleMouseOut_ = function (e) {
  9604. return _this.handleMouseOut(e);
  9605. };
  9606. _this.handleClick_ = function (e) {
  9607. return _this.handleClick(e);
  9608. };
  9609. _this.handleKeyDown_ = function (e) {
  9610. return _this.handleKeyDown(e);
  9611. };
  9612. _this.emitTapEvents();
  9613. _this.enable();
  9614. return _this;
  9615. }
  9616. /**
  9617. * Create the `ClickableComponent`s DOM element.
  9618. *
  9619. * @param {string} [tag=div]
  9620. * The element's node type.
  9621. *
  9622. * @param {Object} [props={}]
  9623. * An object of properties that should be set on the element.
  9624. *
  9625. * @param {Object} [attributes={}]
  9626. * An object of attributes that should be set on the element.
  9627. *
  9628. * @return {Element}
  9629. * The element that gets created.
  9630. */
  9631. var _proto = ClickableComponent.prototype;
  9632. _proto.createEl = function createEl$1(tag, props, attributes) {
  9633. if (tag === void 0) {
  9634. tag = 'div';
  9635. }
  9636. if (props === void 0) {
  9637. props = {};
  9638. }
  9639. if (attributes === void 0) {
  9640. attributes = {};
  9641. }
  9642. props = assign({
  9643. className: this.buildCSSClass(),
  9644. tabIndex: 0
  9645. }, props);
  9646. if (tag === 'button') {
  9647. log.error("Creating a ClickableComponent with an HTML element of " + tag + " is not supported; use a Button instead.");
  9648. } // Add ARIA attributes for clickable element which is not a native HTML button
  9649. attributes = assign({
  9650. role: 'button'
  9651. }, attributes);
  9652. this.tabIndex_ = props.tabIndex;
  9653. var el = createEl(tag, props, attributes);
  9654. el.appendChild(createEl('span', {
  9655. className: 'vjs-icon-placeholder'
  9656. }, {
  9657. 'aria-hidden': true
  9658. }));
  9659. this.createControlTextEl(el);
  9660. return el;
  9661. };
  9662. _proto.dispose = function dispose() {
  9663. // remove controlTextEl_ on dispose
  9664. this.controlTextEl_ = null;
  9665. _Component.prototype.dispose.call(this);
  9666. }
  9667. /**
  9668. * Create a control text element on this `ClickableComponent`
  9669. *
  9670. * @param {Element} [el]
  9671. * Parent element for the control text.
  9672. *
  9673. * @return {Element}
  9674. * The control text element that gets created.
  9675. */
  9676. ;
  9677. _proto.createControlTextEl = function createControlTextEl(el) {
  9678. this.controlTextEl_ = createEl('span', {
  9679. className: 'vjs-control-text'
  9680. }, {
  9681. // let the screen reader user know that the text of the element may change
  9682. 'aria-live': 'polite'
  9683. });
  9684. if (el) {
  9685. el.appendChild(this.controlTextEl_);
  9686. }
  9687. this.controlText(this.controlText_, el);
  9688. return this.controlTextEl_;
  9689. }
  9690. /**
  9691. * Get or set the localize text to use for the controls on the `ClickableComponent`.
  9692. *
  9693. * @param {string} [text]
  9694. * Control text for element.
  9695. *
  9696. * @param {Element} [el=this.el()]
  9697. * Element to set the title on.
  9698. *
  9699. * @return {string}
  9700. * - The control text when getting
  9701. */
  9702. ;
  9703. _proto.controlText = function controlText(text, el) {
  9704. if (el === void 0) {
  9705. el = this.el();
  9706. }
  9707. if (text === undefined) {
  9708. return this.controlText_ || 'Need Text';
  9709. }
  9710. var localizedText = this.localize(text);
  9711. this.controlText_ = text;
  9712. textContent(this.controlTextEl_, localizedText);
  9713. if (!this.nonIconControl && !this.player_.options_.noUITitleAttributes) {
  9714. // Set title attribute if only an icon is shown
  9715. el.setAttribute('title', localizedText);
  9716. }
  9717. }
  9718. /**
  9719. * Builds the default DOM `className`.
  9720. *
  9721. * @return {string}
  9722. * The DOM `className` for this object.
  9723. */
  9724. ;
  9725. _proto.buildCSSClass = function buildCSSClass() {
  9726. return "vjs-control vjs-button " + _Component.prototype.buildCSSClass.call(this);
  9727. }
  9728. /**
  9729. * Enable this `ClickableComponent`
  9730. */
  9731. ;
  9732. _proto.enable = function enable() {
  9733. if (!this.enabled_) {
  9734. this.enabled_ = true;
  9735. this.removeClass('vjs-disabled');
  9736. this.el_.setAttribute('aria-disabled', 'false');
  9737. if (typeof this.tabIndex_ !== 'undefined') {
  9738. this.el_.setAttribute('tabIndex', this.tabIndex_);
  9739. }
  9740. this.on(['tap', 'click'], this.handleClick_);
  9741. this.on('keydown', this.handleKeyDown_);
  9742. }
  9743. }
  9744. /**
  9745. * Disable this `ClickableComponent`
  9746. */
  9747. ;
  9748. _proto.disable = function disable() {
  9749. this.enabled_ = false;
  9750. this.addClass('vjs-disabled');
  9751. this.el_.setAttribute('aria-disabled', 'true');
  9752. if (typeof this.tabIndex_ !== 'undefined') {
  9753. this.el_.removeAttribute('tabIndex');
  9754. }
  9755. this.off('mouseover', this.handleMouseOver_);
  9756. this.off('mouseout', this.handleMouseOut_);
  9757. this.off(['tap', 'click'], this.handleClick_);
  9758. this.off('keydown', this.handleKeyDown_);
  9759. }
  9760. /**
  9761. * Handles language change in ClickableComponent for the player in components
  9762. *
  9763. *
  9764. */
  9765. ;
  9766. _proto.handleLanguagechange = function handleLanguagechange() {
  9767. this.controlText(this.controlText_);
  9768. }
  9769. /**
  9770. * Event handler that is called when a `ClickableComponent` receives a
  9771. * `click` or `tap` event.
  9772. *
  9773. * @param {EventTarget~Event} event
  9774. * The `tap` or `click` event that caused this function to be called.
  9775. *
  9776. * @listens tap
  9777. * @listens click
  9778. * @abstract
  9779. */
  9780. ;
  9781. _proto.handleClick = function handleClick(event) {
  9782. if (this.options_.clickHandler) {
  9783. this.options_.clickHandler.call(this, arguments);
  9784. }
  9785. }
  9786. /**
  9787. * Event handler that is called when a `ClickableComponent` receives a
  9788. * `keydown` event.
  9789. *
  9790. * By default, if the key is Space or Enter, it will trigger a `click` event.
  9791. *
  9792. * @param {EventTarget~Event} event
  9793. * The `keydown` event that caused this function to be called.
  9794. *
  9795. * @listens keydown
  9796. */
  9797. ;
  9798. _proto.handleKeyDown = function handleKeyDown(event) {
  9799. // Support Space or Enter key operation to fire a click event. Also,
  9800. // prevent the event from propagating through the DOM and triggering
  9801. // Player hotkeys.
  9802. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  9803. event.preventDefault();
  9804. event.stopPropagation();
  9805. this.trigger('click');
  9806. } else {
  9807. // Pass keypress handling up for unsupported keys
  9808. _Component.prototype.handleKeyDown.call(this, event);
  9809. }
  9810. };
  9811. return ClickableComponent;
  9812. }(Component);
  9813. Component.registerComponent('ClickableComponent', ClickableComponent);
  9814. /**
  9815. * A `ClickableComponent` that handles showing the poster image for the player.
  9816. *
  9817. * @extends ClickableComponent
  9818. */
  9819. var PosterImage = /*#__PURE__*/function (_ClickableComponent) {
  9820. inheritsLoose(PosterImage, _ClickableComponent);
  9821. /**
  9822. * Create an instance of this class.
  9823. *
  9824. * @param {Player} player
  9825. * The `Player` that this class should attach to.
  9826. *
  9827. * @param {Object} [options]
  9828. * The key/value store of player options.
  9829. */
  9830. function PosterImage(player, options) {
  9831. var _this;
  9832. _this = _ClickableComponent.call(this, player, options) || this;
  9833. _this.update();
  9834. _this.update_ = function (e) {
  9835. return _this.update(e);
  9836. };
  9837. player.on('posterchange', _this.update_);
  9838. return _this;
  9839. }
  9840. /**
  9841. * Clean up and dispose of the `PosterImage`.
  9842. */
  9843. var _proto = PosterImage.prototype;
  9844. _proto.dispose = function dispose() {
  9845. this.player().off('posterchange', this.update_);
  9846. _ClickableComponent.prototype.dispose.call(this);
  9847. }
  9848. /**
  9849. * Create the `PosterImage`s DOM element.
  9850. *
  9851. * @return {Element}
  9852. * The element that gets created.
  9853. */
  9854. ;
  9855. _proto.createEl = function createEl$1() {
  9856. var el = createEl('div', {
  9857. className: 'vjs-poster',
  9858. // Don't want poster to be tabbable.
  9859. tabIndex: -1
  9860. });
  9861. return el;
  9862. }
  9863. /**
  9864. * An {@link EventTarget~EventListener} for {@link Player#posterchange} events.
  9865. *
  9866. * @listens Player#posterchange
  9867. *
  9868. * @param {EventTarget~Event} [event]
  9869. * The `Player#posterchange` event that triggered this function.
  9870. */
  9871. ;
  9872. _proto.update = function update(event) {
  9873. var url = this.player().poster();
  9874. this.setSrc(url); // If there's no poster source we should display:none on this component
  9875. // so it's not still clickable or right-clickable
  9876. if (url) {
  9877. this.show();
  9878. } else {
  9879. this.hide();
  9880. }
  9881. }
  9882. /**
  9883. * Set the source of the `PosterImage` depending on the display method.
  9884. *
  9885. * @param {string} url
  9886. * The URL to the source for the `PosterImage`.
  9887. */
  9888. ;
  9889. _proto.setSrc = function setSrc(url) {
  9890. var backgroundImage = ''; // Any falsy value should stay as an empty string, otherwise
  9891. // this will throw an extra error
  9892. if (url) {
  9893. backgroundImage = "url(\"" + url + "\")";
  9894. }
  9895. this.el_.style.backgroundImage = backgroundImage;
  9896. }
  9897. /**
  9898. * An {@link EventTarget~EventListener} for clicks on the `PosterImage`. See
  9899. * {@link ClickableComponent#handleClick} for instances where this will be triggered.
  9900. *
  9901. * @listens tap
  9902. * @listens click
  9903. * @listens keydown
  9904. *
  9905. * @param {EventTarget~Event} event
  9906. + The `click`, `tap` or `keydown` event that caused this function to be called.
  9907. */
  9908. ;
  9909. _proto.handleClick = function handleClick(event) {
  9910. // We don't want a click to trigger playback when controls are disabled
  9911. if (!this.player_.controls()) {
  9912. return;
  9913. }
  9914. var sourceIsEncrypted = this.player_.usingPlugin('eme') && this.player_.eme.sessions && this.player_.eme.sessions.length > 0;
  9915. if (this.player_.tech(true) && // We've observed a bug in IE and Edge when playing back DRM content where
  9916. // calling .focus() on the video element causes the video to go black,
  9917. // so we avoid it in that specific case
  9918. !((IE_VERSION || IS_EDGE) && sourceIsEncrypted)) {
  9919. this.player_.tech(true).focus();
  9920. }
  9921. if (this.player_.paused()) {
  9922. silencePromise(this.player_.play());
  9923. } else {
  9924. this.player_.pause();
  9925. }
  9926. };
  9927. return PosterImage;
  9928. }(ClickableComponent);
  9929. Component.registerComponent('PosterImage', PosterImage);
  9930. var darkGray = '#222';
  9931. var lightGray = '#ccc';
  9932. var fontMap = {
  9933. monospace: 'monospace',
  9934. sansSerif: 'sans-serif',
  9935. serif: 'serif',
  9936. monospaceSansSerif: '"Andale Mono", "Lucida Console", monospace',
  9937. monospaceSerif: '"Courier New", monospace',
  9938. proportionalSansSerif: 'sans-serif',
  9939. proportionalSerif: 'serif',
  9940. casual: '"Comic Sans MS", Impact, fantasy',
  9941. script: '"Monotype Corsiva", cursive',
  9942. smallcaps: '"Andale Mono", "Lucida Console", monospace, sans-serif'
  9943. };
  9944. /**
  9945. * Construct an rgba color from a given hex color code.
  9946. *
  9947. * @param {number} color
  9948. * Hex number for color, like #f0e or #f604e2.
  9949. *
  9950. * @param {number} opacity
  9951. * Value for opacity, 0.0 - 1.0.
  9952. *
  9953. * @return {string}
  9954. * The rgba color that was created, like 'rgba(255, 0, 0, 0.3)'.
  9955. */
  9956. function constructColor(color, opacity) {
  9957. var hex;
  9958. if (color.length === 4) {
  9959. // color looks like "#f0e"
  9960. hex = color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
  9961. } else if (color.length === 7) {
  9962. // color looks like "#f604e2"
  9963. hex = color.slice(1);
  9964. } else {
  9965. throw new Error('Invalid color code provided, ' + color + '; must be formatted as e.g. #f0e or #f604e2.');
  9966. }
  9967. return 'rgba(' + parseInt(hex.slice(0, 2), 16) + ',' + parseInt(hex.slice(2, 4), 16) + ',' + parseInt(hex.slice(4, 6), 16) + ',' + opacity + ')';
  9968. }
  9969. /**
  9970. * Try to update the style of a DOM element. Some style changes will throw an error,
  9971. * particularly in IE8. Those should be noops.
  9972. *
  9973. * @param {Element} el
  9974. * The DOM element to be styled.
  9975. *
  9976. * @param {string} style
  9977. * The CSS property on the element that should be styled.
  9978. *
  9979. * @param {string} rule
  9980. * The style rule that should be applied to the property.
  9981. *
  9982. * @private
  9983. */
  9984. function tryUpdateStyle(el, style, rule) {
  9985. try {
  9986. el.style[style] = rule;
  9987. } catch (e) {
  9988. // Satisfies linter.
  9989. return;
  9990. }
  9991. }
  9992. /**
  9993. * The component for displaying text track cues.
  9994. *
  9995. * @extends Component
  9996. */
  9997. var TextTrackDisplay = /*#__PURE__*/function (_Component) {
  9998. inheritsLoose(TextTrackDisplay, _Component);
  9999. /**
  10000. * Creates an instance of this class.
  10001. *
  10002. * @param {Player} player
  10003. * The `Player` that this class should be attached to.
  10004. *
  10005. * @param {Object} [options]
  10006. * The key/value store of player options.
  10007. *
  10008. * @param {Component~ReadyCallback} [ready]
  10009. * The function to call when `TextTrackDisplay` is ready.
  10010. */
  10011. function TextTrackDisplay(player, options, ready) {
  10012. var _this;
  10013. _this = _Component.call(this, player, options, ready) || this;
  10014. var updateDisplayHandler = function updateDisplayHandler(e) {
  10015. return _this.updateDisplay(e);
  10016. };
  10017. player.on('loadstart', function (e) {
  10018. return _this.toggleDisplay(e);
  10019. });
  10020. player.on('texttrackchange', updateDisplayHandler);
  10021. player.on('loadedmetadata', function (e) {
  10022. return _this.preselectTrack(e);
  10023. }); // This used to be called during player init, but was causing an error
  10024. // if a track should show by default and the display hadn't loaded yet.
  10025. // Should probably be moved to an external track loader when we support
  10026. // tracks that don't need a display.
  10027. player.ready(bind(assertThisInitialized(_this), function () {
  10028. if (player.tech_ && player.tech_.featuresNativeTextTracks) {
  10029. this.hide();
  10030. return;
  10031. }
  10032. player.on('fullscreenchange', updateDisplayHandler);
  10033. player.on('playerresize', updateDisplayHandler);
  10034. window.addEventListener('orientationchange', updateDisplayHandler);
  10035. player.on('dispose', function () {
  10036. return window.removeEventListener('orientationchange', updateDisplayHandler);
  10037. });
  10038. var tracks = this.options_.playerOptions.tracks || [];
  10039. for (var i = 0; i < tracks.length; i++) {
  10040. this.player_.addRemoteTextTrack(tracks[i], true);
  10041. }
  10042. this.preselectTrack();
  10043. }));
  10044. return _this;
  10045. }
  10046. /**
  10047. * Preselect a track following this precedence:
  10048. * - matches the previously selected {@link TextTrack}'s language and kind
  10049. * - matches the previously selected {@link TextTrack}'s language only
  10050. * - is the first default captions track
  10051. * - is the first default descriptions track
  10052. *
  10053. * @listens Player#loadstart
  10054. */
  10055. var _proto = TextTrackDisplay.prototype;
  10056. _proto.preselectTrack = function preselectTrack() {
  10057. var modes = {
  10058. captions: 1,
  10059. subtitles: 1
  10060. };
  10061. var trackList = this.player_.textTracks();
  10062. var userPref = this.player_.cache_.selectedLanguage;
  10063. var firstDesc;
  10064. var firstCaptions;
  10065. var preferredTrack;
  10066. for (var i = 0; i < trackList.length; i++) {
  10067. var track = trackList[i];
  10068. if (userPref && userPref.enabled && userPref.language && userPref.language === track.language && track.kind in modes) {
  10069. // Always choose the track that matches both language and kind
  10070. if (track.kind === userPref.kind) {
  10071. preferredTrack = track; // or choose the first track that matches language
  10072. } else if (!preferredTrack) {
  10073. preferredTrack = track;
  10074. } // clear everything if offTextTrackMenuItem was clicked
  10075. } else if (userPref && !userPref.enabled) {
  10076. preferredTrack = null;
  10077. firstDesc = null;
  10078. firstCaptions = null;
  10079. } else if (track["default"]) {
  10080. if (track.kind === 'descriptions' && !firstDesc) {
  10081. firstDesc = track;
  10082. } else if (track.kind in modes && !firstCaptions) {
  10083. firstCaptions = track;
  10084. }
  10085. }
  10086. } // The preferredTrack matches the user preference and takes
  10087. // precedence over all the other tracks.
  10088. // So, display the preferredTrack before the first default track
  10089. // and the subtitles/captions track before the descriptions track
  10090. if (preferredTrack) {
  10091. preferredTrack.mode = 'showing';
  10092. } else if (firstCaptions) {
  10093. firstCaptions.mode = 'showing';
  10094. } else if (firstDesc) {
  10095. firstDesc.mode = 'showing';
  10096. }
  10097. }
  10098. /**
  10099. * Turn display of {@link TextTrack}'s from the current state into the other state.
  10100. * There are only two states:
  10101. * - 'shown'
  10102. * - 'hidden'
  10103. *
  10104. * @listens Player#loadstart
  10105. */
  10106. ;
  10107. _proto.toggleDisplay = function toggleDisplay() {
  10108. if (this.player_.tech_ && this.player_.tech_.featuresNativeTextTracks) {
  10109. this.hide();
  10110. } else {
  10111. this.show();
  10112. }
  10113. }
  10114. /**
  10115. * Create the {@link Component}'s DOM element.
  10116. *
  10117. * @return {Element}
  10118. * The element that was created.
  10119. */
  10120. ;
  10121. _proto.createEl = function createEl() {
  10122. return _Component.prototype.createEl.call(this, 'div', {
  10123. className: 'vjs-text-track-display'
  10124. }, {
  10125. 'translate': 'yes',
  10126. 'aria-live': 'off',
  10127. 'aria-atomic': 'true'
  10128. });
  10129. }
  10130. /**
  10131. * Clear all displayed {@link TextTrack}s.
  10132. */
  10133. ;
  10134. _proto.clearDisplay = function clearDisplay() {
  10135. if (typeof window.WebVTT === 'function') {
  10136. window.WebVTT.processCues(window, [], this.el_);
  10137. }
  10138. }
  10139. /**
  10140. * Update the displayed TextTrack when a either a {@link Player#texttrackchange} or
  10141. * a {@link Player#fullscreenchange} is fired.
  10142. *
  10143. * @listens Player#texttrackchange
  10144. * @listens Player#fullscreenchange
  10145. */
  10146. ;
  10147. _proto.updateDisplay = function updateDisplay() {
  10148. var tracks = this.player_.textTracks();
  10149. var allowMultipleShowingTracks = this.options_.allowMultipleShowingTracks;
  10150. this.clearDisplay();
  10151. if (allowMultipleShowingTracks) {
  10152. var showingTracks = [];
  10153. for (var _i = 0; _i < tracks.length; ++_i) {
  10154. var track = tracks[_i];
  10155. if (track.mode !== 'showing') {
  10156. continue;
  10157. }
  10158. showingTracks.push(track);
  10159. }
  10160. this.updateForTrack(showingTracks);
  10161. return;
  10162. } // Track display prioritization model: if multiple tracks are 'showing',
  10163. // display the first 'subtitles' or 'captions' track which is 'showing',
  10164. // otherwise display the first 'descriptions' track which is 'showing'
  10165. var descriptionsTrack = null;
  10166. var captionsSubtitlesTrack = null;
  10167. var i = tracks.length;
  10168. while (i--) {
  10169. var _track = tracks[i];
  10170. if (_track.mode === 'showing') {
  10171. if (_track.kind === 'descriptions') {
  10172. descriptionsTrack = _track;
  10173. } else {
  10174. captionsSubtitlesTrack = _track;
  10175. }
  10176. }
  10177. }
  10178. if (captionsSubtitlesTrack) {
  10179. if (this.getAttribute('aria-live') !== 'off') {
  10180. this.setAttribute('aria-live', 'off');
  10181. }
  10182. this.updateForTrack(captionsSubtitlesTrack);
  10183. } else if (descriptionsTrack) {
  10184. if (this.getAttribute('aria-live') !== 'assertive') {
  10185. this.setAttribute('aria-live', 'assertive');
  10186. }
  10187. this.updateForTrack(descriptionsTrack);
  10188. }
  10189. }
  10190. /**
  10191. * Style {@Link TextTrack} activeCues according to {@Link TextTrackSettings}.
  10192. *
  10193. * @param {TextTrack} track
  10194. * Text track object containing active cues to style.
  10195. */
  10196. ;
  10197. _proto.updateDisplayState = function updateDisplayState(track) {
  10198. var overrides = this.player_.textTrackSettings.getValues();
  10199. var cues = track.activeCues;
  10200. var i = cues.length;
  10201. while (i--) {
  10202. var cue = cues[i];
  10203. if (!cue) {
  10204. continue;
  10205. }
  10206. var cueDiv = cue.displayState;
  10207. if (overrides.color) {
  10208. cueDiv.firstChild.style.color = overrides.color;
  10209. }
  10210. if (overrides.textOpacity) {
  10211. tryUpdateStyle(cueDiv.firstChild, 'color', constructColor(overrides.color || '#fff', overrides.textOpacity));
  10212. }
  10213. if (overrides.backgroundColor) {
  10214. cueDiv.firstChild.style.backgroundColor = overrides.backgroundColor;
  10215. }
  10216. if (overrides.backgroundOpacity) {
  10217. tryUpdateStyle(cueDiv.firstChild, 'backgroundColor', constructColor(overrides.backgroundColor || '#000', overrides.backgroundOpacity));
  10218. }
  10219. if (overrides.windowColor) {
  10220. if (overrides.windowOpacity) {
  10221. tryUpdateStyle(cueDiv, 'backgroundColor', constructColor(overrides.windowColor, overrides.windowOpacity));
  10222. } else {
  10223. cueDiv.style.backgroundColor = overrides.windowColor;
  10224. }
  10225. }
  10226. if (overrides.edgeStyle) {
  10227. if (overrides.edgeStyle === 'dropshadow') {
  10228. cueDiv.firstChild.style.textShadow = "2px 2px 3px " + darkGray + ", 2px 2px 4px " + darkGray + ", 2px 2px 5px " + darkGray;
  10229. } else if (overrides.edgeStyle === 'raised') {
  10230. cueDiv.firstChild.style.textShadow = "1px 1px " + darkGray + ", 2px 2px " + darkGray + ", 3px 3px " + darkGray;
  10231. } else if (overrides.edgeStyle === 'depressed') {
  10232. cueDiv.firstChild.style.textShadow = "1px 1px " + lightGray + ", 0 1px " + lightGray + ", -1px -1px " + darkGray + ", 0 -1px " + darkGray;
  10233. } else if (overrides.edgeStyle === 'uniform') {
  10234. cueDiv.firstChild.style.textShadow = "0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray;
  10235. }
  10236. }
  10237. if (overrides.fontPercent && overrides.fontPercent !== 1) {
  10238. var fontSize = window.parseFloat(cueDiv.style.fontSize);
  10239. cueDiv.style.fontSize = fontSize * overrides.fontPercent + 'px';
  10240. cueDiv.style.height = 'auto';
  10241. cueDiv.style.top = 'auto';
  10242. }
  10243. if (overrides.fontFamily && overrides.fontFamily !== 'default') {
  10244. if (overrides.fontFamily === 'small-caps') {
  10245. cueDiv.firstChild.style.fontVariant = 'small-caps';
  10246. } else {
  10247. cueDiv.firstChild.style.fontFamily = fontMap[overrides.fontFamily];
  10248. }
  10249. }
  10250. }
  10251. }
  10252. /**
  10253. * Add an {@link TextTrack} to to the {@link Tech}s {@link TextTrackList}.
  10254. *
  10255. * @param {TextTrack|TextTrack[]} tracks
  10256. * Text track object or text track array to be added to the list.
  10257. */
  10258. ;
  10259. _proto.updateForTrack = function updateForTrack(tracks) {
  10260. if (!Array.isArray(tracks)) {
  10261. tracks = [tracks];
  10262. }
  10263. if (typeof window.WebVTT !== 'function' || tracks.every(function (track) {
  10264. return !track.activeCues;
  10265. })) {
  10266. return;
  10267. }
  10268. var cues = []; // push all active track cues
  10269. for (var i = 0; i < tracks.length; ++i) {
  10270. var track = tracks[i];
  10271. for (var j = 0; j < track.activeCues.length; ++j) {
  10272. cues.push(track.activeCues[j]);
  10273. }
  10274. } // removes all cues before it processes new ones
  10275. window.WebVTT.processCues(window, cues, this.el_); // add unique class to each language text track & add settings styling if necessary
  10276. for (var _i2 = 0; _i2 < tracks.length; ++_i2) {
  10277. var _track2 = tracks[_i2];
  10278. for (var _j = 0; _j < _track2.activeCues.length; ++_j) {
  10279. var cueEl = _track2.activeCues[_j].displayState;
  10280. addClass(cueEl, 'vjs-text-track-cue');
  10281. addClass(cueEl, 'vjs-text-track-cue-' + (_track2.language ? _track2.language : _i2));
  10282. if (_track2.language) {
  10283. setAttribute(cueEl, 'lang', _track2.language);
  10284. }
  10285. }
  10286. if (this.player_.textTrackSettings) {
  10287. this.updateDisplayState(_track2);
  10288. }
  10289. }
  10290. };
  10291. return TextTrackDisplay;
  10292. }(Component);
  10293. Component.registerComponent('TextTrackDisplay', TextTrackDisplay);
  10294. /**
  10295. * A loading spinner for use during waiting/loading events.
  10296. *
  10297. * @extends Component
  10298. */
  10299. var LoadingSpinner = /*#__PURE__*/function (_Component) {
  10300. inheritsLoose(LoadingSpinner, _Component);
  10301. function LoadingSpinner() {
  10302. return _Component.apply(this, arguments) || this;
  10303. }
  10304. var _proto = LoadingSpinner.prototype;
  10305. /**
  10306. * Create the `LoadingSpinner`s DOM element.
  10307. *
  10308. * @return {Element}
  10309. * The dom element that gets created.
  10310. */
  10311. _proto.createEl = function createEl$1() {
  10312. var isAudio = this.player_.isAudio();
  10313. var playerType = this.localize(isAudio ? 'Audio Player' : 'Video Player');
  10314. var controlText = createEl('span', {
  10315. className: 'vjs-control-text',
  10316. textContent: this.localize('{1} is loading.', [playerType])
  10317. });
  10318. var el = _Component.prototype.createEl.call(this, 'div', {
  10319. className: 'vjs-loading-spinner',
  10320. dir: 'ltr'
  10321. });
  10322. el.appendChild(controlText);
  10323. return el;
  10324. };
  10325. return LoadingSpinner;
  10326. }(Component);
  10327. Component.registerComponent('LoadingSpinner', LoadingSpinner);
  10328. /**
  10329. * Base class for all buttons.
  10330. *
  10331. * @extends ClickableComponent
  10332. */
  10333. var Button = /*#__PURE__*/function (_ClickableComponent) {
  10334. inheritsLoose(Button, _ClickableComponent);
  10335. function Button() {
  10336. return _ClickableComponent.apply(this, arguments) || this;
  10337. }
  10338. var _proto = Button.prototype;
  10339. /**
  10340. * Create the `Button`s DOM element.
  10341. *
  10342. * @param {string} [tag="button"]
  10343. * The element's node type. This argument is IGNORED: no matter what
  10344. * is passed, it will always create a `button` element.
  10345. *
  10346. * @param {Object} [props={}]
  10347. * An object of properties that should be set on the element.
  10348. *
  10349. * @param {Object} [attributes={}]
  10350. * An object of attributes that should be set on the element.
  10351. *
  10352. * @return {Element}
  10353. * The element that gets created.
  10354. */
  10355. _proto.createEl = function createEl$1(tag, props, attributes) {
  10356. if (props === void 0) {
  10357. props = {};
  10358. }
  10359. if (attributes === void 0) {
  10360. attributes = {};
  10361. }
  10362. tag = 'button';
  10363. props = assign({
  10364. className: this.buildCSSClass()
  10365. }, props); // Add attributes for button element
  10366. attributes = assign({
  10367. // Necessary since the default button type is "submit"
  10368. type: 'button'
  10369. }, attributes);
  10370. var el = createEl(tag, props, attributes);
  10371. el.appendChild(createEl('span', {
  10372. className: 'vjs-icon-placeholder'
  10373. }, {
  10374. 'aria-hidden': true
  10375. }));
  10376. this.createControlTextEl(el);
  10377. return el;
  10378. }
  10379. /**
  10380. * Add a child `Component` inside of this `Button`.
  10381. *
  10382. * @param {string|Component} child
  10383. * The name or instance of a child to add.
  10384. *
  10385. * @param {Object} [options={}]
  10386. * The key/value store of options that will get passed to children of
  10387. * the child.
  10388. *
  10389. * @return {Component}
  10390. * The `Component` that gets added as a child. When using a string the
  10391. * `Component` will get created by this process.
  10392. *
  10393. * @deprecated since version 5
  10394. */
  10395. ;
  10396. _proto.addChild = function addChild(child, options) {
  10397. if (options === void 0) {
  10398. options = {};
  10399. }
  10400. var className = this.constructor.name;
  10401. log.warn("Adding an actionable (user controllable) child to a Button (" + className + ") is not supported; use a ClickableComponent instead."); // Avoid the error message generated by ClickableComponent's addChild method
  10402. return Component.prototype.addChild.call(this, child, options);
  10403. }
  10404. /**
  10405. * Enable the `Button` element so that it can be activated or clicked. Use this with
  10406. * {@link Button#disable}.
  10407. */
  10408. ;
  10409. _proto.enable = function enable() {
  10410. _ClickableComponent.prototype.enable.call(this);
  10411. this.el_.removeAttribute('disabled');
  10412. }
  10413. /**
  10414. * Disable the `Button` element so that it cannot be activated or clicked. Use this with
  10415. * {@link Button#enable}.
  10416. */
  10417. ;
  10418. _proto.disable = function disable() {
  10419. _ClickableComponent.prototype.disable.call(this);
  10420. this.el_.setAttribute('disabled', 'disabled');
  10421. }
  10422. /**
  10423. * This gets called when a `Button` has focus and `keydown` is triggered via a key
  10424. * press.
  10425. *
  10426. * @param {EventTarget~Event} event
  10427. * The event that caused this function to get called.
  10428. *
  10429. * @listens keydown
  10430. */
  10431. ;
  10432. _proto.handleKeyDown = function handleKeyDown(event) {
  10433. // Ignore Space or Enter key operation, which is handled by the browser for
  10434. // a button - though not for its super class, ClickableComponent. Also,
  10435. // prevent the event from propagating through the DOM and triggering Player
  10436. // hotkeys. We do not preventDefault here because we _want_ the browser to
  10437. // handle it.
  10438. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  10439. event.stopPropagation();
  10440. return;
  10441. } // Pass keypress handling up for unsupported keys
  10442. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  10443. };
  10444. return Button;
  10445. }(ClickableComponent);
  10446. Component.registerComponent('Button', Button);
  10447. /**
  10448. * The initial play button that shows before the video has played. The hiding of the
  10449. * `BigPlayButton` get done via CSS and `Player` states.
  10450. *
  10451. * @extends Button
  10452. */
  10453. var BigPlayButton = /*#__PURE__*/function (_Button) {
  10454. inheritsLoose(BigPlayButton, _Button);
  10455. function BigPlayButton(player, options) {
  10456. var _this;
  10457. _this = _Button.call(this, player, options) || this;
  10458. _this.mouseused_ = false;
  10459. _this.on('mousedown', function (e) {
  10460. return _this.handleMouseDown(e);
  10461. });
  10462. return _this;
  10463. }
  10464. /**
  10465. * Builds the default DOM `className`.
  10466. *
  10467. * @return {string}
  10468. * The DOM `className` for this object. Always returns 'vjs-big-play-button'.
  10469. */
  10470. var _proto = BigPlayButton.prototype;
  10471. _proto.buildCSSClass = function buildCSSClass() {
  10472. return 'vjs-big-play-button';
  10473. }
  10474. /**
  10475. * This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
  10476. * for more detailed information on what a click can be.
  10477. *
  10478. * @param {EventTarget~Event} event
  10479. * The `keydown`, `tap`, or `click` event that caused this function to be
  10480. * called.
  10481. *
  10482. * @listens tap
  10483. * @listens click
  10484. */
  10485. ;
  10486. _proto.handleClick = function handleClick(event) {
  10487. var playPromise = this.player_.play(); // exit early if clicked via the mouse
  10488. if (this.mouseused_ && event.clientX && event.clientY) {
  10489. var sourceIsEncrypted = this.player_.usingPlugin('eme') && this.player_.eme.sessions && this.player_.eme.sessions.length > 0;
  10490. silencePromise(playPromise);
  10491. if (this.player_.tech(true) && // We've observed a bug in IE and Edge when playing back DRM content where
  10492. // calling .focus() on the video element causes the video to go black,
  10493. // so we avoid it in that specific case
  10494. !((IE_VERSION || IS_EDGE) && sourceIsEncrypted)) {
  10495. this.player_.tech(true).focus();
  10496. }
  10497. return;
  10498. }
  10499. var cb = this.player_.getChild('controlBar');
  10500. var playToggle = cb && cb.getChild('playToggle');
  10501. if (!playToggle) {
  10502. this.player_.tech(true).focus();
  10503. return;
  10504. }
  10505. var playFocus = function playFocus() {
  10506. return playToggle.focus();
  10507. };
  10508. if (isPromise(playPromise)) {
  10509. playPromise.then(playFocus, function () {});
  10510. } else {
  10511. this.setTimeout(playFocus, 1);
  10512. }
  10513. };
  10514. _proto.handleKeyDown = function handleKeyDown(event) {
  10515. this.mouseused_ = false;
  10516. _Button.prototype.handleKeyDown.call(this, event);
  10517. };
  10518. _proto.handleMouseDown = function handleMouseDown(event) {
  10519. this.mouseused_ = true;
  10520. };
  10521. return BigPlayButton;
  10522. }(Button);
  10523. /**
  10524. * The text that should display over the `BigPlayButton`s controls. Added to for localization.
  10525. *
  10526. * @type {string}
  10527. * @private
  10528. */
  10529. BigPlayButton.prototype.controlText_ = 'Play Video';
  10530. Component.registerComponent('BigPlayButton', BigPlayButton);
  10531. /**
  10532. * The `CloseButton` is a `{@link Button}` that fires a `close` event when
  10533. * it gets clicked.
  10534. *
  10535. * @extends Button
  10536. */
  10537. var CloseButton = /*#__PURE__*/function (_Button) {
  10538. inheritsLoose(CloseButton, _Button);
  10539. /**
  10540. * Creates an instance of the this class.
  10541. *
  10542. * @param {Player} player
  10543. * The `Player` that this class should be attached to.
  10544. *
  10545. * @param {Object} [options]
  10546. * The key/value store of player options.
  10547. */
  10548. function CloseButton(player, options) {
  10549. var _this;
  10550. _this = _Button.call(this, player, options) || this;
  10551. _this.controlText(options && options.controlText || _this.localize('Close'));
  10552. return _this;
  10553. }
  10554. /**
  10555. * Builds the default DOM `className`.
  10556. *
  10557. * @return {string}
  10558. * The DOM `className` for this object.
  10559. */
  10560. var _proto = CloseButton.prototype;
  10561. _proto.buildCSSClass = function buildCSSClass() {
  10562. return "vjs-close-button " + _Button.prototype.buildCSSClass.call(this);
  10563. }
  10564. /**
  10565. * This gets called when a `CloseButton` gets clicked. See
  10566. * {@link ClickableComponent#handleClick} for more information on when
  10567. * this will be triggered
  10568. *
  10569. * @param {EventTarget~Event} event
  10570. * The `keydown`, `tap`, or `click` event that caused this function to be
  10571. * called.
  10572. *
  10573. * @listens tap
  10574. * @listens click
  10575. * @fires CloseButton#close
  10576. */
  10577. ;
  10578. _proto.handleClick = function handleClick(event) {
  10579. /**
  10580. * Triggered when the a `CloseButton` is clicked.
  10581. *
  10582. * @event CloseButton#close
  10583. * @type {EventTarget~Event}
  10584. *
  10585. * @property {boolean} [bubbles=false]
  10586. * set to false so that the close event does not
  10587. * bubble up to parents if there is no listener
  10588. */
  10589. this.trigger({
  10590. type: 'close',
  10591. bubbles: false
  10592. });
  10593. }
  10594. /**
  10595. * Event handler that is called when a `CloseButton` receives a
  10596. * `keydown` event.
  10597. *
  10598. * By default, if the key is Esc, it will trigger a `click` event.
  10599. *
  10600. * @param {EventTarget~Event} event
  10601. * The `keydown` event that caused this function to be called.
  10602. *
  10603. * @listens keydown
  10604. */
  10605. ;
  10606. _proto.handleKeyDown = function handleKeyDown(event) {
  10607. // Esc button will trigger `click` event
  10608. if (keycode.isEventKey(event, 'Esc')) {
  10609. event.preventDefault();
  10610. event.stopPropagation();
  10611. this.trigger('click');
  10612. } else {
  10613. // Pass keypress handling up for unsupported keys
  10614. _Button.prototype.handleKeyDown.call(this, event);
  10615. }
  10616. };
  10617. return CloseButton;
  10618. }(Button);
  10619. Component.registerComponent('CloseButton', CloseButton);
  10620. /**
  10621. * Button to toggle between play and pause.
  10622. *
  10623. * @extends Button
  10624. */
  10625. var PlayToggle = /*#__PURE__*/function (_Button) {
  10626. inheritsLoose(PlayToggle, _Button);
  10627. /**
  10628. * Creates an instance of this class.
  10629. *
  10630. * @param {Player} player
  10631. * The `Player` that this class should be attached to.
  10632. *
  10633. * @param {Object} [options={}]
  10634. * The key/value store of player options.
  10635. */
  10636. function PlayToggle(player, options) {
  10637. var _this;
  10638. if (options === void 0) {
  10639. options = {};
  10640. }
  10641. _this = _Button.call(this, player, options) || this; // show or hide replay icon
  10642. options.replay = options.replay === undefined || options.replay;
  10643. _this.on(player, 'play', function (e) {
  10644. return _this.handlePlay(e);
  10645. });
  10646. _this.on(player, 'pause', function (e) {
  10647. return _this.handlePause(e);
  10648. });
  10649. if (options.replay) {
  10650. _this.on(player, 'ended', function (e) {
  10651. return _this.handleEnded(e);
  10652. });
  10653. }
  10654. return _this;
  10655. }
  10656. /**
  10657. * Builds the default DOM `className`.
  10658. *
  10659. * @return {string}
  10660. * The DOM `className` for this object.
  10661. */
  10662. var _proto = PlayToggle.prototype;
  10663. _proto.buildCSSClass = function buildCSSClass() {
  10664. return "vjs-play-control " + _Button.prototype.buildCSSClass.call(this);
  10665. }
  10666. /**
  10667. * This gets called when an `PlayToggle` is "clicked". See
  10668. * {@link ClickableComponent} for more detailed information on what a click can be.
  10669. *
  10670. * @param {EventTarget~Event} [event]
  10671. * The `keydown`, `tap`, or `click` event that caused this function to be
  10672. * called.
  10673. *
  10674. * @listens tap
  10675. * @listens click
  10676. */
  10677. ;
  10678. _proto.handleClick = function handleClick(event) {
  10679. if (this.player_.paused()) {
  10680. silencePromise(this.player_.play());
  10681. } else {
  10682. this.player_.pause();
  10683. }
  10684. }
  10685. /**
  10686. * This gets called once after the video has ended and the user seeks so that
  10687. * we can change the replay button back to a play button.
  10688. *
  10689. * @param {EventTarget~Event} [event]
  10690. * The event that caused this function to run.
  10691. *
  10692. * @listens Player#seeked
  10693. */
  10694. ;
  10695. _proto.handleSeeked = function handleSeeked(event) {
  10696. this.removeClass('vjs-ended');
  10697. if (this.player_.paused()) {
  10698. this.handlePause(event);
  10699. } else {
  10700. this.handlePlay(event);
  10701. }
  10702. }
  10703. /**
  10704. * Add the vjs-playing class to the element so it can change appearance.
  10705. *
  10706. * @param {EventTarget~Event} [event]
  10707. * The event that caused this function to run.
  10708. *
  10709. * @listens Player#play
  10710. */
  10711. ;
  10712. _proto.handlePlay = function handlePlay(event) {
  10713. this.removeClass('vjs-ended');
  10714. this.removeClass('vjs-paused');
  10715. this.addClass('vjs-playing'); // change the button text to "Pause"
  10716. this.controlText('Pause');
  10717. }
  10718. /**
  10719. * Add the vjs-paused class to the element so it can change appearance.
  10720. *
  10721. * @param {EventTarget~Event} [event]
  10722. * The event that caused this function to run.
  10723. *
  10724. * @listens Player#pause
  10725. */
  10726. ;
  10727. _proto.handlePause = function handlePause(event) {
  10728. this.removeClass('vjs-playing');
  10729. this.addClass('vjs-paused'); // change the button text to "Play"
  10730. this.controlText('Play');
  10731. }
  10732. /**
  10733. * Add the vjs-ended class to the element so it can change appearance
  10734. *
  10735. * @param {EventTarget~Event} [event]
  10736. * The event that caused this function to run.
  10737. *
  10738. * @listens Player#ended
  10739. */
  10740. ;
  10741. _proto.handleEnded = function handleEnded(event) {
  10742. var _this2 = this;
  10743. this.removeClass('vjs-playing');
  10744. this.addClass('vjs-ended'); // change the button text to "Replay"
  10745. this.controlText('Replay'); // on the next seek remove the replay button
  10746. this.one(this.player_, 'seeked', function (e) {
  10747. return _this2.handleSeeked(e);
  10748. });
  10749. };
  10750. return PlayToggle;
  10751. }(Button);
  10752. /**
  10753. * The text that should display over the `PlayToggle`s controls. Added for localization.
  10754. *
  10755. * @type {string}
  10756. * @private
  10757. */
  10758. PlayToggle.prototype.controlText_ = 'Play';
  10759. Component.registerComponent('PlayToggle', PlayToggle);
  10760. /**
  10761. * @file format-time.js
  10762. * @module format-time
  10763. */
  10764. /**
  10765. * Format seconds as a time string, H:MM:SS or M:SS. Supplying a guide (in
  10766. * seconds) will force a number of leading zeros to cover the length of the
  10767. * guide.
  10768. *
  10769. * @private
  10770. * @param {number} seconds
  10771. * Number of seconds to be turned into a string
  10772. *
  10773. * @param {number} guide
  10774. * Number (in seconds) to model the string after
  10775. *
  10776. * @return {string}
  10777. * Time formatted as H:MM:SS or M:SS
  10778. */
  10779. var defaultImplementation = function defaultImplementation(seconds, guide) {
  10780. seconds = seconds < 0 ? 0 : seconds;
  10781. var s = Math.floor(seconds % 60);
  10782. var m = Math.floor(seconds / 60 % 60);
  10783. var h = Math.floor(seconds / 3600);
  10784. var gm = Math.floor(guide / 60 % 60);
  10785. var gh = Math.floor(guide / 3600); // handle invalid times
  10786. if (isNaN(seconds) || seconds === Infinity) {
  10787. // '-' is false for all relational operators (e.g. <, >=) so this setting
  10788. // will add the minimum number of fields specified by the guide
  10789. h = m = s = '-';
  10790. } // Check if we need to show hours
  10791. h = h > 0 || gh > 0 ? h + ':' : ''; // If hours are showing, we may need to add a leading zero.
  10792. // Always show at least one digit of minutes.
  10793. m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':'; // Check if leading zero is need for seconds
  10794. s = s < 10 ? '0' + s : s;
  10795. return h + m + s;
  10796. }; // Internal pointer to the current implementation.
  10797. var implementation = defaultImplementation;
  10798. /**
  10799. * Replaces the default formatTime implementation with a custom implementation.
  10800. *
  10801. * @param {Function} customImplementation
  10802. * A function which will be used in place of the default formatTime
  10803. * implementation. Will receive the current time in seconds and the
  10804. * guide (in seconds) as arguments.
  10805. */
  10806. function setFormatTime(customImplementation) {
  10807. implementation = customImplementation;
  10808. }
  10809. /**
  10810. * Resets formatTime to the default implementation.
  10811. */
  10812. function resetFormatTime() {
  10813. implementation = defaultImplementation;
  10814. }
  10815. /**
  10816. * Delegates to either the default time formatting function or a custom
  10817. * function supplied via `setFormatTime`.
  10818. *
  10819. * Formats seconds as a time string (H:MM:SS or M:SS). Supplying a
  10820. * guide (in seconds) will force a number of leading zeros to cover the
  10821. * length of the guide.
  10822. *
  10823. * @static
  10824. * @example formatTime(125, 600) === "02:05"
  10825. * @param {number} seconds
  10826. * Number of seconds to be turned into a string
  10827. *
  10828. * @param {number} guide
  10829. * Number (in seconds) to model the string after
  10830. *
  10831. * @return {string}
  10832. * Time formatted as H:MM:SS or M:SS
  10833. */
  10834. function formatTime(seconds, guide) {
  10835. if (guide === void 0) {
  10836. guide = seconds;
  10837. }
  10838. return implementation(seconds, guide);
  10839. }
  10840. /**
  10841. * Displays time information about the video
  10842. *
  10843. * @extends Component
  10844. */
  10845. var TimeDisplay = /*#__PURE__*/function (_Component) {
  10846. inheritsLoose(TimeDisplay, _Component);
  10847. /**
  10848. * Creates an instance of this class.
  10849. *
  10850. * @param {Player} player
  10851. * The `Player` that this class should be attached to.
  10852. *
  10853. * @param {Object} [options]
  10854. * The key/value store of player options.
  10855. */
  10856. function TimeDisplay(player, options) {
  10857. var _this;
  10858. _this = _Component.call(this, player, options) || this;
  10859. _this.on(player, ['timeupdate', 'ended'], function (e) {
  10860. return _this.updateContent(e);
  10861. });
  10862. _this.updateTextNode_();
  10863. return _this;
  10864. }
  10865. /**
  10866. * Create the `Component`'s DOM element
  10867. *
  10868. * @return {Element}
  10869. * The element that was created.
  10870. */
  10871. var _proto = TimeDisplay.prototype;
  10872. _proto.createEl = function createEl$1() {
  10873. var className = this.buildCSSClass();
  10874. var el = _Component.prototype.createEl.call(this, 'div', {
  10875. className: className + " vjs-time-control vjs-control"
  10876. });
  10877. var span = createEl('span', {
  10878. className: 'vjs-control-text',
  10879. textContent: this.localize(this.labelText_) + "\xA0"
  10880. }, {
  10881. role: 'presentation'
  10882. });
  10883. el.appendChild(span);
  10884. this.contentEl_ = createEl('span', {
  10885. className: className + "-display"
  10886. }, {
  10887. // tell screen readers not to automatically read the time as it changes
  10888. 'aria-live': 'off',
  10889. // span elements have no implicit role, but some screen readers (notably VoiceOver)
  10890. // treat them as a break between items in the DOM when using arrow keys
  10891. // (or left-to-right swipes on iOS) to read contents of a page. Using
  10892. // role='presentation' causes VoiceOver to NOT treat this span as a break.
  10893. 'role': 'presentation'
  10894. });
  10895. el.appendChild(this.contentEl_);
  10896. return el;
  10897. };
  10898. _proto.dispose = function dispose() {
  10899. this.contentEl_ = null;
  10900. this.textNode_ = null;
  10901. _Component.prototype.dispose.call(this);
  10902. }
  10903. /**
  10904. * Updates the time display text node with a new time
  10905. *
  10906. * @param {number} [time=0] the time to update to
  10907. *
  10908. * @private
  10909. */
  10910. ;
  10911. _proto.updateTextNode_ = function updateTextNode_(time) {
  10912. var _this2 = this;
  10913. if (time === void 0) {
  10914. time = 0;
  10915. }
  10916. time = formatTime(time);
  10917. if (this.formattedTime_ === time) {
  10918. return;
  10919. }
  10920. this.formattedTime_ = time;
  10921. this.requestNamedAnimationFrame('TimeDisplay#updateTextNode_', function () {
  10922. if (!_this2.contentEl_) {
  10923. return;
  10924. }
  10925. var oldNode = _this2.textNode_;
  10926. if (oldNode && _this2.contentEl_.firstChild !== oldNode) {
  10927. oldNode = null;
  10928. log.warn('TimeDisplay#updateTextnode_: Prevented replacement of text node element since it was no longer a child of this node. Appending a new node instead.');
  10929. }
  10930. _this2.textNode_ = document.createTextNode(_this2.formattedTime_);
  10931. if (!_this2.textNode_) {
  10932. return;
  10933. }
  10934. if (oldNode) {
  10935. _this2.contentEl_.replaceChild(_this2.textNode_, oldNode);
  10936. } else {
  10937. _this2.contentEl_.appendChild(_this2.textNode_);
  10938. }
  10939. });
  10940. }
  10941. /**
  10942. * To be filled out in the child class, should update the displayed time
  10943. * in accordance with the fact that the current time has changed.
  10944. *
  10945. * @param {EventTarget~Event} [event]
  10946. * The `timeupdate` event that caused this to run.
  10947. *
  10948. * @listens Player#timeupdate
  10949. */
  10950. ;
  10951. _proto.updateContent = function updateContent(event) {};
  10952. return TimeDisplay;
  10953. }(Component);
  10954. /**
  10955. * The text that is added to the `TimeDisplay` for screen reader users.
  10956. *
  10957. * @type {string}
  10958. * @private
  10959. */
  10960. TimeDisplay.prototype.labelText_ = 'Time';
  10961. /**
  10962. * The text that should display over the `TimeDisplay`s controls. Added to for localization.
  10963. *
  10964. * @type {string}
  10965. * @private
  10966. *
  10967. * @deprecated in v7; controlText_ is not used in non-active display Components
  10968. */
  10969. TimeDisplay.prototype.controlText_ = 'Time';
  10970. Component.registerComponent('TimeDisplay', TimeDisplay);
  10971. /**
  10972. * Displays the current time
  10973. *
  10974. * @extends Component
  10975. */
  10976. var CurrentTimeDisplay = /*#__PURE__*/function (_TimeDisplay) {
  10977. inheritsLoose(CurrentTimeDisplay, _TimeDisplay);
  10978. function CurrentTimeDisplay() {
  10979. return _TimeDisplay.apply(this, arguments) || this;
  10980. }
  10981. var _proto = CurrentTimeDisplay.prototype;
  10982. /**
  10983. * Builds the default DOM `className`.
  10984. *
  10985. * @return {string}
  10986. * The DOM `className` for this object.
  10987. */
  10988. _proto.buildCSSClass = function buildCSSClass() {
  10989. return 'vjs-current-time';
  10990. }
  10991. /**
  10992. * Update current time display
  10993. *
  10994. * @param {EventTarget~Event} [event]
  10995. * The `timeupdate` event that caused this function to run.
  10996. *
  10997. * @listens Player#timeupdate
  10998. */
  10999. ;
  11000. _proto.updateContent = function updateContent(event) {
  11001. // Allows for smooth scrubbing, when player can't keep up.
  11002. var time;
  11003. if (this.player_.ended()) {
  11004. time = this.player_.duration();
  11005. } else {
  11006. time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  11007. }
  11008. this.updateTextNode_(time);
  11009. };
  11010. return CurrentTimeDisplay;
  11011. }(TimeDisplay);
  11012. /**
  11013. * The text that is added to the `CurrentTimeDisplay` for screen reader users.
  11014. *
  11015. * @type {string}
  11016. * @private
  11017. */
  11018. CurrentTimeDisplay.prototype.labelText_ = 'Current Time';
  11019. /**
  11020. * The text that should display over the `CurrentTimeDisplay`s controls. Added to for localization.
  11021. *
  11022. * @type {string}
  11023. * @private
  11024. *
  11025. * @deprecated in v7; controlText_ is not used in non-active display Components
  11026. */
  11027. CurrentTimeDisplay.prototype.controlText_ = 'Current Time';
  11028. Component.registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
  11029. /**
  11030. * Displays the duration
  11031. *
  11032. * @extends Component
  11033. */
  11034. var DurationDisplay = /*#__PURE__*/function (_TimeDisplay) {
  11035. inheritsLoose(DurationDisplay, _TimeDisplay);
  11036. /**
  11037. * Creates an instance of this class.
  11038. *
  11039. * @param {Player} player
  11040. * The `Player` that this class should be attached to.
  11041. *
  11042. * @param {Object} [options]
  11043. * The key/value store of player options.
  11044. */
  11045. function DurationDisplay(player, options) {
  11046. var _this;
  11047. _this = _TimeDisplay.call(this, player, options) || this;
  11048. var updateContent = function updateContent(e) {
  11049. return _this.updateContent(e);
  11050. }; // we do not want to/need to throttle duration changes,
  11051. // as they should always display the changed duration as
  11052. // it has changed
  11053. _this.on(player, 'durationchange', updateContent); // Listen to loadstart because the player duration is reset when a new media element is loaded,
  11054. // but the durationchange on the user agent will not fire.
  11055. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  11056. _this.on(player, 'loadstart', updateContent); // Also listen for timeupdate (in the parent) and loadedmetadata because removing those
  11057. // listeners could have broken dependent applications/libraries. These
  11058. // can likely be removed for 7.0.
  11059. _this.on(player, 'loadedmetadata', updateContent);
  11060. return _this;
  11061. }
  11062. /**
  11063. * Builds the default DOM `className`.
  11064. *
  11065. * @return {string}
  11066. * The DOM `className` for this object.
  11067. */
  11068. var _proto = DurationDisplay.prototype;
  11069. _proto.buildCSSClass = function buildCSSClass() {
  11070. return 'vjs-duration';
  11071. }
  11072. /**
  11073. * Update duration time display.
  11074. *
  11075. * @param {EventTarget~Event} [event]
  11076. * The `durationchange`, `timeupdate`, or `loadedmetadata` event that caused
  11077. * this function to be called.
  11078. *
  11079. * @listens Player#durationchange
  11080. * @listens Player#timeupdate
  11081. * @listens Player#loadedmetadata
  11082. */
  11083. ;
  11084. _proto.updateContent = function updateContent(event) {
  11085. var duration = this.player_.duration();
  11086. this.updateTextNode_(duration);
  11087. };
  11088. return DurationDisplay;
  11089. }(TimeDisplay);
  11090. /**
  11091. * The text that is added to the `DurationDisplay` for screen reader users.
  11092. *
  11093. * @type {string}
  11094. * @private
  11095. */
  11096. DurationDisplay.prototype.labelText_ = 'Duration';
  11097. /**
  11098. * The text that should display over the `DurationDisplay`s controls. Added to for localization.
  11099. *
  11100. * @type {string}
  11101. * @private
  11102. *
  11103. * @deprecated in v7; controlText_ is not used in non-active display Components
  11104. */
  11105. DurationDisplay.prototype.controlText_ = 'Duration';
  11106. Component.registerComponent('DurationDisplay', DurationDisplay);
  11107. /**
  11108. * The separator between the current time and duration.
  11109. * Can be hidden if it's not needed in the design.
  11110. *
  11111. * @extends Component
  11112. */
  11113. var TimeDivider = /*#__PURE__*/function (_Component) {
  11114. inheritsLoose(TimeDivider, _Component);
  11115. function TimeDivider() {
  11116. return _Component.apply(this, arguments) || this;
  11117. }
  11118. var _proto = TimeDivider.prototype;
  11119. /**
  11120. * Create the component's DOM element
  11121. *
  11122. * @return {Element}
  11123. * The element that was created.
  11124. */
  11125. _proto.createEl = function createEl() {
  11126. var el = _Component.prototype.createEl.call(this, 'div', {
  11127. className: 'vjs-time-control vjs-time-divider'
  11128. }, {
  11129. // this element and its contents can be hidden from assistive techs since
  11130. // it is made extraneous by the announcement of the control text
  11131. // for the current time and duration displays
  11132. 'aria-hidden': true
  11133. });
  11134. var div = _Component.prototype.createEl.call(this, 'div');
  11135. var span = _Component.prototype.createEl.call(this, 'span', {
  11136. textContent: '/'
  11137. });
  11138. div.appendChild(span);
  11139. el.appendChild(div);
  11140. return el;
  11141. };
  11142. return TimeDivider;
  11143. }(Component);
  11144. Component.registerComponent('TimeDivider', TimeDivider);
  11145. /**
  11146. * Displays the time left in the video
  11147. *
  11148. * @extends Component
  11149. */
  11150. var RemainingTimeDisplay = /*#__PURE__*/function (_TimeDisplay) {
  11151. inheritsLoose(RemainingTimeDisplay, _TimeDisplay);
  11152. /**
  11153. * Creates an instance of this class.
  11154. *
  11155. * @param {Player} player
  11156. * The `Player` that this class should be attached to.
  11157. *
  11158. * @param {Object} [options]
  11159. * The key/value store of player options.
  11160. */
  11161. function RemainingTimeDisplay(player, options) {
  11162. var _this;
  11163. _this = _TimeDisplay.call(this, player, options) || this;
  11164. _this.on(player, 'durationchange', function (e) {
  11165. return _this.updateContent(e);
  11166. });
  11167. return _this;
  11168. }
  11169. /**
  11170. * Builds the default DOM `className`.
  11171. *
  11172. * @return {string}
  11173. * The DOM `className` for this object.
  11174. */
  11175. var _proto = RemainingTimeDisplay.prototype;
  11176. _proto.buildCSSClass = function buildCSSClass() {
  11177. return 'vjs-remaining-time';
  11178. }
  11179. /**
  11180. * Create the `Component`'s DOM element with the "minus" characted prepend to the time
  11181. *
  11182. * @return {Element}
  11183. * The element that was created.
  11184. */
  11185. ;
  11186. _proto.createEl = function createEl$1() {
  11187. var el = _TimeDisplay.prototype.createEl.call(this);
  11188. if (this.options_.displayNegative !== false) {
  11189. el.insertBefore(createEl('span', {}, {
  11190. 'aria-hidden': true
  11191. }, '-'), this.contentEl_);
  11192. }
  11193. return el;
  11194. }
  11195. /**
  11196. * Update remaining time display.
  11197. *
  11198. * @param {EventTarget~Event} [event]
  11199. * The `timeupdate` or `durationchange` event that caused this to run.
  11200. *
  11201. * @listens Player#timeupdate
  11202. * @listens Player#durationchange
  11203. */
  11204. ;
  11205. _proto.updateContent = function updateContent(event) {
  11206. if (typeof this.player_.duration() !== 'number') {
  11207. return;
  11208. }
  11209. var time; // @deprecated We should only use remainingTimeDisplay
  11210. // as of video.js 7
  11211. if (this.player_.ended()) {
  11212. time = 0;
  11213. } else if (this.player_.remainingTimeDisplay) {
  11214. time = this.player_.remainingTimeDisplay();
  11215. } else {
  11216. time = this.player_.remainingTime();
  11217. }
  11218. this.updateTextNode_(time);
  11219. };
  11220. return RemainingTimeDisplay;
  11221. }(TimeDisplay);
  11222. /**
  11223. * The text that is added to the `RemainingTimeDisplay` for screen reader users.
  11224. *
  11225. * @type {string}
  11226. * @private
  11227. */
  11228. RemainingTimeDisplay.prototype.labelText_ = 'Remaining Time';
  11229. /**
  11230. * The text that should display over the `RemainingTimeDisplay`s controls. Added to for localization.
  11231. *
  11232. * @type {string}
  11233. * @private
  11234. *
  11235. * @deprecated in v7; controlText_ is not used in non-active display Components
  11236. */
  11237. RemainingTimeDisplay.prototype.controlText_ = 'Remaining Time';
  11238. Component.registerComponent('RemainingTimeDisplay', RemainingTimeDisplay);
  11239. /**
  11240. * Displays the live indicator when duration is Infinity.
  11241. *
  11242. * @extends Component
  11243. */
  11244. var LiveDisplay = /*#__PURE__*/function (_Component) {
  11245. inheritsLoose(LiveDisplay, _Component);
  11246. /**
  11247. * Creates an instance of this class.
  11248. *
  11249. * @param {Player} player
  11250. * The `Player` that this class should be attached to.
  11251. *
  11252. * @param {Object} [options]
  11253. * The key/value store of player options.
  11254. */
  11255. function LiveDisplay(player, options) {
  11256. var _this;
  11257. _this = _Component.call(this, player, options) || this;
  11258. _this.updateShowing();
  11259. _this.on(_this.player(), 'durationchange', function (e) {
  11260. return _this.updateShowing(e);
  11261. });
  11262. return _this;
  11263. }
  11264. /**
  11265. * Create the `Component`'s DOM element
  11266. *
  11267. * @return {Element}
  11268. * The element that was created.
  11269. */
  11270. var _proto = LiveDisplay.prototype;
  11271. _proto.createEl = function createEl$1() {
  11272. var el = _Component.prototype.createEl.call(this, 'div', {
  11273. className: 'vjs-live-control vjs-control'
  11274. });
  11275. this.contentEl_ = createEl('div', {
  11276. className: 'vjs-live-display'
  11277. }, {
  11278. 'aria-live': 'off'
  11279. });
  11280. this.contentEl_.appendChild(createEl('span', {
  11281. className: 'vjs-control-text',
  11282. textContent: this.localize('Stream Type') + "\xA0"
  11283. }));
  11284. this.contentEl_.appendChild(document.createTextNode(this.localize('LIVE')));
  11285. el.appendChild(this.contentEl_);
  11286. return el;
  11287. };
  11288. _proto.dispose = function dispose() {
  11289. this.contentEl_ = null;
  11290. _Component.prototype.dispose.call(this);
  11291. }
  11292. /**
  11293. * Check the duration to see if the LiveDisplay should be showing or not. Then show/hide
  11294. * it accordingly
  11295. *
  11296. * @param {EventTarget~Event} [event]
  11297. * The {@link Player#durationchange} event that caused this function to run.
  11298. *
  11299. * @listens Player#durationchange
  11300. */
  11301. ;
  11302. _proto.updateShowing = function updateShowing(event) {
  11303. if (this.player().duration() === Infinity) {
  11304. this.show();
  11305. } else {
  11306. this.hide();
  11307. }
  11308. };
  11309. return LiveDisplay;
  11310. }(Component);
  11311. Component.registerComponent('LiveDisplay', LiveDisplay);
  11312. /**
  11313. * Displays the live indicator when duration is Infinity.
  11314. *
  11315. * @extends Component
  11316. */
  11317. var SeekToLive = /*#__PURE__*/function (_Button) {
  11318. inheritsLoose(SeekToLive, _Button);
  11319. /**
  11320. * Creates an instance of this class.
  11321. *
  11322. * @param {Player} player
  11323. * The `Player` that this class should be attached to.
  11324. *
  11325. * @param {Object} [options]
  11326. * The key/value store of player options.
  11327. */
  11328. function SeekToLive(player, options) {
  11329. var _this;
  11330. _this = _Button.call(this, player, options) || this;
  11331. _this.updateLiveEdgeStatus();
  11332. if (_this.player_.liveTracker) {
  11333. _this.updateLiveEdgeStatusHandler_ = function (e) {
  11334. return _this.updateLiveEdgeStatus(e);
  11335. };
  11336. _this.on(_this.player_.liveTracker, 'liveedgechange', _this.updateLiveEdgeStatusHandler_);
  11337. }
  11338. return _this;
  11339. }
  11340. /**
  11341. * Create the `Component`'s DOM element
  11342. *
  11343. * @return {Element}
  11344. * The element that was created.
  11345. */
  11346. var _proto = SeekToLive.prototype;
  11347. _proto.createEl = function createEl$1() {
  11348. var el = _Button.prototype.createEl.call(this, 'button', {
  11349. className: 'vjs-seek-to-live-control vjs-control'
  11350. });
  11351. this.textEl_ = createEl('span', {
  11352. className: 'vjs-seek-to-live-text',
  11353. textContent: this.localize('LIVE')
  11354. }, {
  11355. 'aria-hidden': 'true'
  11356. });
  11357. el.appendChild(this.textEl_);
  11358. return el;
  11359. }
  11360. /**
  11361. * Update the state of this button if we are at the live edge
  11362. * or not
  11363. */
  11364. ;
  11365. _proto.updateLiveEdgeStatus = function updateLiveEdgeStatus() {
  11366. // default to live edge
  11367. if (!this.player_.liveTracker || this.player_.liveTracker.atLiveEdge()) {
  11368. this.setAttribute('aria-disabled', true);
  11369. this.addClass('vjs-at-live-edge');
  11370. this.controlText('Seek to live, currently playing live');
  11371. } else {
  11372. this.setAttribute('aria-disabled', false);
  11373. this.removeClass('vjs-at-live-edge');
  11374. this.controlText('Seek to live, currently behind live');
  11375. }
  11376. }
  11377. /**
  11378. * On click bring us as near to the live point as possible.
  11379. * This requires that we wait for the next `live-seekable-change`
  11380. * event which will happen every segment length seconds.
  11381. */
  11382. ;
  11383. _proto.handleClick = function handleClick() {
  11384. this.player_.liveTracker.seekToLiveEdge();
  11385. }
  11386. /**
  11387. * Dispose of the element and stop tracking
  11388. */
  11389. ;
  11390. _proto.dispose = function dispose() {
  11391. if (this.player_.liveTracker) {
  11392. this.off(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatusHandler_);
  11393. }
  11394. this.textEl_ = null;
  11395. _Button.prototype.dispose.call(this);
  11396. };
  11397. return SeekToLive;
  11398. }(Button);
  11399. SeekToLive.prototype.controlText_ = 'Seek to live, currently playing live';
  11400. Component.registerComponent('SeekToLive', SeekToLive);
  11401. /**
  11402. * Keep a number between a min and a max value
  11403. *
  11404. * @param {number} number
  11405. * The number to clamp
  11406. *
  11407. * @param {number} min
  11408. * The minimum value
  11409. * @param {number} max
  11410. * The maximum value
  11411. *
  11412. * @return {number}
  11413. * the clamped number
  11414. */
  11415. var clamp = function clamp(number, min, max) {
  11416. number = Number(number);
  11417. return Math.min(max, Math.max(min, isNaN(number) ? min : number));
  11418. };
  11419. /**
  11420. * The base functionality for a slider. Can be vertical or horizontal.
  11421. * For instance the volume bar or the seek bar on a video is a slider.
  11422. *
  11423. * @extends Component
  11424. */
  11425. var Slider = /*#__PURE__*/function (_Component) {
  11426. inheritsLoose(Slider, _Component);
  11427. /**
  11428. * Create an instance of this class
  11429. *
  11430. * @param {Player} player
  11431. * The `Player` that this class should be attached to.
  11432. *
  11433. * @param {Object} [options]
  11434. * The key/value store of player options.
  11435. */
  11436. function Slider(player, options) {
  11437. var _this;
  11438. _this = _Component.call(this, player, options) || this;
  11439. _this.handleMouseDown_ = function (e) {
  11440. return _this.handleMouseDown(e);
  11441. };
  11442. _this.handleMouseUp_ = function (e) {
  11443. return _this.handleMouseUp(e);
  11444. };
  11445. _this.handleKeyDown_ = function (e) {
  11446. return _this.handleKeyDown(e);
  11447. };
  11448. _this.handleClick_ = function (e) {
  11449. return _this.handleClick(e);
  11450. };
  11451. _this.handleMouseMove_ = function (e) {
  11452. return _this.handleMouseMove(e);
  11453. };
  11454. _this.update_ = function (e) {
  11455. return _this.update(e);
  11456. }; // Set property names to bar to match with the child Slider class is looking for
  11457. _this.bar = _this.getChild(_this.options_.barName); // Set a horizontal or vertical class on the slider depending on the slider type
  11458. _this.vertical(!!_this.options_.vertical);
  11459. _this.enable();
  11460. return _this;
  11461. }
  11462. /**
  11463. * Are controls are currently enabled for this slider or not.
  11464. *
  11465. * @return {boolean}
  11466. * true if controls are enabled, false otherwise
  11467. */
  11468. var _proto = Slider.prototype;
  11469. _proto.enabled = function enabled() {
  11470. return this.enabled_;
  11471. }
  11472. /**
  11473. * Enable controls for this slider if they are disabled
  11474. */
  11475. ;
  11476. _proto.enable = function enable() {
  11477. if (this.enabled()) {
  11478. return;
  11479. }
  11480. this.on('mousedown', this.handleMouseDown_);
  11481. this.on('touchstart', this.handleMouseDown_);
  11482. this.on('keydown', this.handleKeyDown_);
  11483. this.on('click', this.handleClick_); // TODO: deprecated, controlsvisible does not seem to be fired
  11484. this.on(this.player_, 'controlsvisible', this.update);
  11485. if (this.playerEvent) {
  11486. this.on(this.player_, this.playerEvent, this.update);
  11487. }
  11488. this.removeClass('disabled');
  11489. this.setAttribute('tabindex', 0);
  11490. this.enabled_ = true;
  11491. }
  11492. /**
  11493. * Disable controls for this slider if they are enabled
  11494. */
  11495. ;
  11496. _proto.disable = function disable() {
  11497. if (!this.enabled()) {
  11498. return;
  11499. }
  11500. var doc = this.bar.el_.ownerDocument;
  11501. this.off('mousedown', this.handleMouseDown_);
  11502. this.off('touchstart', this.handleMouseDown_);
  11503. this.off('keydown', this.handleKeyDown_);
  11504. this.off('click', this.handleClick_);
  11505. this.off(this.player_, 'controlsvisible', this.update_);
  11506. this.off(doc, 'mousemove', this.handleMouseMove_);
  11507. this.off(doc, 'mouseup', this.handleMouseUp_);
  11508. this.off(doc, 'touchmove', this.handleMouseMove_);
  11509. this.off(doc, 'touchend', this.handleMouseUp_);
  11510. this.removeAttribute('tabindex');
  11511. this.addClass('disabled');
  11512. if (this.playerEvent) {
  11513. this.off(this.player_, this.playerEvent, this.update);
  11514. }
  11515. this.enabled_ = false;
  11516. }
  11517. /**
  11518. * Create the `Slider`s DOM element.
  11519. *
  11520. * @param {string} type
  11521. * Type of element to create.
  11522. *
  11523. * @param {Object} [props={}]
  11524. * List of properties in Object form.
  11525. *
  11526. * @param {Object} [attributes={}]
  11527. * list of attributes in Object form.
  11528. *
  11529. * @return {Element}
  11530. * The element that gets created.
  11531. */
  11532. ;
  11533. _proto.createEl = function createEl(type, props, attributes) {
  11534. if (props === void 0) {
  11535. props = {};
  11536. }
  11537. if (attributes === void 0) {
  11538. attributes = {};
  11539. }
  11540. // Add the slider element class to all sub classes
  11541. props.className = props.className + ' vjs-slider';
  11542. props = assign({
  11543. tabIndex: 0
  11544. }, props);
  11545. attributes = assign({
  11546. 'role': 'slider',
  11547. 'aria-valuenow': 0,
  11548. 'aria-valuemin': 0,
  11549. 'aria-valuemax': 100,
  11550. 'tabIndex': 0
  11551. }, attributes);
  11552. return _Component.prototype.createEl.call(this, type, props, attributes);
  11553. }
  11554. /**
  11555. * Handle `mousedown` or `touchstart` events on the `Slider`.
  11556. *
  11557. * @param {EventTarget~Event} event
  11558. * `mousedown` or `touchstart` event that triggered this function
  11559. *
  11560. * @listens mousedown
  11561. * @listens touchstart
  11562. * @fires Slider#slideractive
  11563. */
  11564. ;
  11565. _proto.handleMouseDown = function handleMouseDown(event) {
  11566. var doc = this.bar.el_.ownerDocument;
  11567. if (event.type === 'mousedown') {
  11568. event.preventDefault();
  11569. } // Do not call preventDefault() on touchstart in Chrome
  11570. // to avoid console warnings. Use a 'touch-action: none' style
  11571. // instead to prevent unintented scrolling.
  11572. // https://developers.google.com/web/updates/2017/01/scrolling-intervention
  11573. if (event.type === 'touchstart' && !IS_CHROME) {
  11574. event.preventDefault();
  11575. }
  11576. blockTextSelection();
  11577. this.addClass('vjs-sliding');
  11578. /**
  11579. * Triggered when the slider is in an active state
  11580. *
  11581. * @event Slider#slideractive
  11582. * @type {EventTarget~Event}
  11583. */
  11584. this.trigger('slideractive');
  11585. this.on(doc, 'mousemove', this.handleMouseMove_);
  11586. this.on(doc, 'mouseup', this.handleMouseUp_);
  11587. this.on(doc, 'touchmove', this.handleMouseMove_);
  11588. this.on(doc, 'touchend', this.handleMouseUp_);
  11589. this.handleMouseMove(event, true);
  11590. }
  11591. /**
  11592. * Handle the `mousemove`, `touchmove`, and `mousedown` events on this `Slider`.
  11593. * The `mousemove` and `touchmove` events will only only trigger this function during
  11594. * `mousedown` and `touchstart`. This is due to {@link Slider#handleMouseDown} and
  11595. * {@link Slider#handleMouseUp}.
  11596. *
  11597. * @param {EventTarget~Event} event
  11598. * `mousedown`, `mousemove`, `touchstart`, or `touchmove` event that triggered
  11599. * this function
  11600. * @param {boolean} mouseDown this is a flag that should be set to true if `handleMouseMove` is called directly. It allows us to skip things that should not happen if coming from mouse down but should happen on regular mouse move handler. Defaults to false.
  11601. *
  11602. * @listens mousemove
  11603. * @listens touchmove
  11604. */
  11605. ;
  11606. _proto.handleMouseMove = function handleMouseMove(event) {}
  11607. /**
  11608. * Handle `mouseup` or `touchend` events on the `Slider`.
  11609. *
  11610. * @param {EventTarget~Event} event
  11611. * `mouseup` or `touchend` event that triggered this function.
  11612. *
  11613. * @listens touchend
  11614. * @listens mouseup
  11615. * @fires Slider#sliderinactive
  11616. */
  11617. ;
  11618. _proto.handleMouseUp = function handleMouseUp() {
  11619. var doc = this.bar.el_.ownerDocument;
  11620. unblockTextSelection();
  11621. this.removeClass('vjs-sliding');
  11622. /**
  11623. * Triggered when the slider is no longer in an active state.
  11624. *
  11625. * @event Slider#sliderinactive
  11626. * @type {EventTarget~Event}
  11627. */
  11628. this.trigger('sliderinactive');
  11629. this.off(doc, 'mousemove', this.handleMouseMove_);
  11630. this.off(doc, 'mouseup', this.handleMouseUp_);
  11631. this.off(doc, 'touchmove', this.handleMouseMove_);
  11632. this.off(doc, 'touchend', this.handleMouseUp_);
  11633. this.update();
  11634. }
  11635. /**
  11636. * Update the progress bar of the `Slider`.
  11637. *
  11638. * @return {number}
  11639. * The percentage of progress the progress bar represents as a
  11640. * number from 0 to 1.
  11641. */
  11642. ;
  11643. _proto.update = function update() {
  11644. var _this2 = this;
  11645. // In VolumeBar init we have a setTimeout for update that pops and update
  11646. // to the end of the execution stack. The player is destroyed before then
  11647. // update will cause an error
  11648. // If there's no bar...
  11649. if (!this.el_ || !this.bar) {
  11650. return;
  11651. } // clamp progress between 0 and 1
  11652. // and only round to four decimal places, as we round to two below
  11653. var progress = this.getProgress();
  11654. if (progress === this.progress_) {
  11655. return progress;
  11656. }
  11657. this.progress_ = progress;
  11658. this.requestNamedAnimationFrame('Slider#update', function () {
  11659. // Set the new bar width or height
  11660. var sizeKey = _this2.vertical() ? 'height' : 'width'; // Convert to a percentage for css value
  11661. _this2.bar.el().style[sizeKey] = (progress * 100).toFixed(2) + '%';
  11662. });
  11663. return progress;
  11664. }
  11665. /**
  11666. * Get the percentage of the bar that should be filled
  11667. * but clamped and rounded.
  11668. *
  11669. * @return {number}
  11670. * percentage filled that the slider is
  11671. */
  11672. ;
  11673. _proto.getProgress = function getProgress() {
  11674. return Number(clamp(this.getPercent(), 0, 1).toFixed(4));
  11675. }
  11676. /**
  11677. * Calculate distance for slider
  11678. *
  11679. * @param {EventTarget~Event} event
  11680. * The event that caused this function to run.
  11681. *
  11682. * @return {number}
  11683. * The current position of the Slider.
  11684. * - position.x for vertical `Slider`s
  11685. * - position.y for horizontal `Slider`s
  11686. */
  11687. ;
  11688. _proto.calculateDistance = function calculateDistance(event) {
  11689. var position = getPointerPosition(this.el_, event);
  11690. if (this.vertical()) {
  11691. return position.y;
  11692. }
  11693. return position.x;
  11694. }
  11695. /**
  11696. * Handle a `keydown` event on the `Slider`. Watches for left, rigth, up, and down
  11697. * arrow keys. This function will only be called when the slider has focus. See
  11698. * {@link Slider#handleFocus} and {@link Slider#handleBlur}.
  11699. *
  11700. * @param {EventTarget~Event} event
  11701. * the `keydown` event that caused this function to run.
  11702. *
  11703. * @listens keydown
  11704. */
  11705. ;
  11706. _proto.handleKeyDown = function handleKeyDown(event) {
  11707. // Left and Down Arrows
  11708. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  11709. event.preventDefault();
  11710. event.stopPropagation();
  11711. this.stepBack(); // Up and Right Arrows
  11712. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  11713. event.preventDefault();
  11714. event.stopPropagation();
  11715. this.stepForward();
  11716. } else {
  11717. // Pass keydown handling up for unsupported keys
  11718. _Component.prototype.handleKeyDown.call(this, event);
  11719. }
  11720. }
  11721. /**
  11722. * Listener for click events on slider, used to prevent clicks
  11723. * from bubbling up to parent elements like button menus.
  11724. *
  11725. * @param {Object} event
  11726. * Event that caused this object to run
  11727. */
  11728. ;
  11729. _proto.handleClick = function handleClick(event) {
  11730. event.stopPropagation();
  11731. event.preventDefault();
  11732. }
  11733. /**
  11734. * Get/set if slider is horizontal for vertical
  11735. *
  11736. * @param {boolean} [bool]
  11737. * - true if slider is vertical,
  11738. * - false is horizontal
  11739. *
  11740. * @return {boolean}
  11741. * - true if slider is vertical, and getting
  11742. * - false if the slider is horizontal, and getting
  11743. */
  11744. ;
  11745. _proto.vertical = function vertical(bool) {
  11746. if (bool === undefined) {
  11747. return this.vertical_ || false;
  11748. }
  11749. this.vertical_ = !!bool;
  11750. if (this.vertical_) {
  11751. this.addClass('vjs-slider-vertical');
  11752. } else {
  11753. this.addClass('vjs-slider-horizontal');
  11754. }
  11755. };
  11756. return Slider;
  11757. }(Component);
  11758. Component.registerComponent('Slider', Slider);
  11759. var percentify = function percentify(time, end) {
  11760. return clamp(time / end * 100, 0, 100).toFixed(2) + '%';
  11761. };
  11762. /**
  11763. * Shows loading progress
  11764. *
  11765. * @extends Component
  11766. */
  11767. var LoadProgressBar = /*#__PURE__*/function (_Component) {
  11768. inheritsLoose(LoadProgressBar, _Component);
  11769. /**
  11770. * Creates an instance of this class.
  11771. *
  11772. * @param {Player} player
  11773. * The `Player` that this class should be attached to.
  11774. *
  11775. * @param {Object} [options]
  11776. * The key/value store of player options.
  11777. */
  11778. function LoadProgressBar(player, options) {
  11779. var _this;
  11780. _this = _Component.call(this, player, options) || this;
  11781. _this.partEls_ = [];
  11782. _this.on(player, 'progress', function (e) {
  11783. return _this.update(e);
  11784. });
  11785. return _this;
  11786. }
  11787. /**
  11788. * Create the `Component`'s DOM element
  11789. *
  11790. * @return {Element}
  11791. * The element that was created.
  11792. */
  11793. var _proto = LoadProgressBar.prototype;
  11794. _proto.createEl = function createEl$1() {
  11795. var el = _Component.prototype.createEl.call(this, 'div', {
  11796. className: 'vjs-load-progress'
  11797. });
  11798. var wrapper = createEl('span', {
  11799. className: 'vjs-control-text'
  11800. });
  11801. var loadedText = createEl('span', {
  11802. textContent: this.localize('Loaded')
  11803. });
  11804. var separator = document.createTextNode(': ');
  11805. this.percentageEl_ = createEl('span', {
  11806. className: 'vjs-control-text-loaded-percentage',
  11807. textContent: '0%'
  11808. });
  11809. el.appendChild(wrapper);
  11810. wrapper.appendChild(loadedText);
  11811. wrapper.appendChild(separator);
  11812. wrapper.appendChild(this.percentageEl_);
  11813. return el;
  11814. };
  11815. _proto.dispose = function dispose() {
  11816. this.partEls_ = null;
  11817. this.percentageEl_ = null;
  11818. _Component.prototype.dispose.call(this);
  11819. }
  11820. /**
  11821. * Update progress bar
  11822. *
  11823. * @param {EventTarget~Event} [event]
  11824. * The `progress` event that caused this function to run.
  11825. *
  11826. * @listens Player#progress
  11827. */
  11828. ;
  11829. _proto.update = function update(event) {
  11830. var _this2 = this;
  11831. this.requestNamedAnimationFrame('LoadProgressBar#update', function () {
  11832. var liveTracker = _this2.player_.liveTracker;
  11833. var buffered = _this2.player_.buffered();
  11834. var duration = liveTracker && liveTracker.isLive() ? liveTracker.seekableEnd() : _this2.player_.duration();
  11835. var bufferedEnd = _this2.player_.bufferedEnd();
  11836. var children = _this2.partEls_;
  11837. var percent = percentify(bufferedEnd, duration);
  11838. if (_this2.percent_ !== percent) {
  11839. // update the width of the progress bar
  11840. _this2.el_.style.width = percent; // update the control-text
  11841. textContent(_this2.percentageEl_, percent);
  11842. _this2.percent_ = percent;
  11843. } // add child elements to represent the individual buffered time ranges
  11844. for (var i = 0; i < buffered.length; i++) {
  11845. var start = buffered.start(i);
  11846. var end = buffered.end(i);
  11847. var part = children[i];
  11848. if (!part) {
  11849. part = _this2.el_.appendChild(createEl());
  11850. children[i] = part;
  11851. } // only update if changed
  11852. if (part.dataset.start === start && part.dataset.end === end) {
  11853. continue;
  11854. }
  11855. part.dataset.start = start;
  11856. part.dataset.end = end; // set the percent based on the width of the progress bar (bufferedEnd)
  11857. part.style.left = percentify(start, bufferedEnd);
  11858. part.style.width = percentify(end - start, bufferedEnd);
  11859. } // remove unused buffered range elements
  11860. for (var _i = children.length; _i > buffered.length; _i--) {
  11861. _this2.el_.removeChild(children[_i - 1]);
  11862. }
  11863. children.length = buffered.length;
  11864. });
  11865. };
  11866. return LoadProgressBar;
  11867. }(Component);
  11868. Component.registerComponent('LoadProgressBar', LoadProgressBar);
  11869. /**
  11870. * Time tooltips display a time above the progress bar.
  11871. *
  11872. * @extends Component
  11873. */
  11874. var TimeTooltip = /*#__PURE__*/function (_Component) {
  11875. inheritsLoose(TimeTooltip, _Component);
  11876. /**
  11877. * Creates an instance of this class.
  11878. *
  11879. * @param {Player} player
  11880. * The {@link Player} that this class should be attached to.
  11881. *
  11882. * @param {Object} [options]
  11883. * The key/value store of player options.
  11884. */
  11885. function TimeTooltip(player, options) {
  11886. var _this;
  11887. _this = _Component.call(this, player, options) || this;
  11888. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  11889. return _this;
  11890. }
  11891. /**
  11892. * Create the time tooltip DOM element
  11893. *
  11894. * @return {Element}
  11895. * The element that was created.
  11896. */
  11897. var _proto = TimeTooltip.prototype;
  11898. _proto.createEl = function createEl() {
  11899. return _Component.prototype.createEl.call(this, 'div', {
  11900. className: 'vjs-time-tooltip'
  11901. }, {
  11902. 'aria-hidden': 'true'
  11903. });
  11904. }
  11905. /**
  11906. * Updates the position of the time tooltip relative to the `SeekBar`.
  11907. *
  11908. * @param {Object} seekBarRect
  11909. * The `ClientRect` for the {@link SeekBar} element.
  11910. *
  11911. * @param {number} seekBarPoint
  11912. * A number from 0 to 1, representing a horizontal reference point
  11913. * from the left edge of the {@link SeekBar}
  11914. */
  11915. ;
  11916. _proto.update = function update(seekBarRect, seekBarPoint, content) {
  11917. var tooltipRect = findPosition(this.el_);
  11918. var playerRect = getBoundingClientRect(this.player_.el());
  11919. var seekBarPointPx = seekBarRect.width * seekBarPoint; // do nothing if either rect isn't available
  11920. // for example, if the player isn't in the DOM for testing
  11921. if (!playerRect || !tooltipRect) {
  11922. return;
  11923. } // This is the space left of the `seekBarPoint` available within the bounds
  11924. // of the player. We calculate any gap between the left edge of the player
  11925. // and the left edge of the `SeekBar` and add the number of pixels in the
  11926. // `SeekBar` before hitting the `seekBarPoint`
  11927. var spaceLeftOfPoint = seekBarRect.left - playerRect.left + seekBarPointPx; // This is the space right of the `seekBarPoint` available within the bounds
  11928. // of the player. We calculate the number of pixels from the `seekBarPoint`
  11929. // to the right edge of the `SeekBar` and add to that any gap between the
  11930. // right edge of the `SeekBar` and the player.
  11931. var spaceRightOfPoint = seekBarRect.width - seekBarPointPx + (playerRect.right - seekBarRect.right); // This is the number of pixels by which the tooltip will need to be pulled
  11932. // further to the right to center it over the `seekBarPoint`.
  11933. var pullTooltipBy = tooltipRect.width / 2; // Adjust the `pullTooltipBy` distance to the left or right depending on
  11934. // the results of the space calculations above.
  11935. if (spaceLeftOfPoint < pullTooltipBy) {
  11936. pullTooltipBy += pullTooltipBy - spaceLeftOfPoint;
  11937. } else if (spaceRightOfPoint < pullTooltipBy) {
  11938. pullTooltipBy = spaceRightOfPoint;
  11939. } // Due to the imprecision of decimal/ratio based calculations and varying
  11940. // rounding behaviors, there are cases where the spacing adjustment is off
  11941. // by a pixel or two. This adds insurance to these calculations.
  11942. if (pullTooltipBy < 0) {
  11943. pullTooltipBy = 0;
  11944. } else if (pullTooltipBy > tooltipRect.width) {
  11945. pullTooltipBy = tooltipRect.width;
  11946. } // prevent small width fluctuations within 0.4px from
  11947. // changing the value below.
  11948. // This really helps for live to prevent the play
  11949. // progress time tooltip from jittering
  11950. pullTooltipBy = Math.round(pullTooltipBy);
  11951. this.el_.style.right = "-" + pullTooltipBy + "px";
  11952. this.write(content);
  11953. }
  11954. /**
  11955. * Write the time to the tooltip DOM element.
  11956. *
  11957. * @param {string} content
  11958. * The formatted time for the tooltip.
  11959. */
  11960. ;
  11961. _proto.write = function write(content) {
  11962. textContent(this.el_, content);
  11963. }
  11964. /**
  11965. * Updates the position of the time tooltip relative to the `SeekBar`.
  11966. *
  11967. * @param {Object} seekBarRect
  11968. * The `ClientRect` for the {@link SeekBar} element.
  11969. *
  11970. * @param {number} seekBarPoint
  11971. * A number from 0 to 1, representing a horizontal reference point
  11972. * from the left edge of the {@link SeekBar}
  11973. *
  11974. * @param {number} time
  11975. * The time to update the tooltip to, not used during live playback
  11976. *
  11977. * @param {Function} cb
  11978. * A function that will be called during the request animation frame
  11979. * for tooltips that need to do additional animations from the default
  11980. */
  11981. ;
  11982. _proto.updateTime = function updateTime(seekBarRect, seekBarPoint, time, cb) {
  11983. var _this2 = this;
  11984. this.requestNamedAnimationFrame('TimeTooltip#updateTime', function () {
  11985. var content;
  11986. var duration = _this2.player_.duration();
  11987. if (_this2.player_.liveTracker && _this2.player_.liveTracker.isLive()) {
  11988. var liveWindow = _this2.player_.liveTracker.liveWindow();
  11989. var secondsBehind = liveWindow - seekBarPoint * liveWindow;
  11990. content = (secondsBehind < 1 ? '' : '-') + formatTime(secondsBehind, liveWindow);
  11991. } else {
  11992. content = formatTime(time, duration);
  11993. }
  11994. _this2.update(seekBarRect, seekBarPoint, content);
  11995. if (cb) {
  11996. cb();
  11997. }
  11998. });
  11999. };
  12000. return TimeTooltip;
  12001. }(Component);
  12002. Component.registerComponent('TimeTooltip', TimeTooltip);
  12003. /**
  12004. * Used by {@link SeekBar} to display media playback progress as part of the
  12005. * {@link ProgressControl}.
  12006. *
  12007. * @extends Component
  12008. */
  12009. var PlayProgressBar = /*#__PURE__*/function (_Component) {
  12010. inheritsLoose(PlayProgressBar, _Component);
  12011. /**
  12012. * Creates an instance of this class.
  12013. *
  12014. * @param {Player} player
  12015. * The {@link Player} that this class should be attached to.
  12016. *
  12017. * @param {Object} [options]
  12018. * The key/value store of player options.
  12019. */
  12020. function PlayProgressBar(player, options) {
  12021. var _this;
  12022. _this = _Component.call(this, player, options) || this;
  12023. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  12024. return _this;
  12025. }
  12026. /**
  12027. * Create the the DOM element for this class.
  12028. *
  12029. * @return {Element}
  12030. * The element that was created.
  12031. */
  12032. var _proto = PlayProgressBar.prototype;
  12033. _proto.createEl = function createEl() {
  12034. return _Component.prototype.createEl.call(this, 'div', {
  12035. className: 'vjs-play-progress vjs-slider-bar'
  12036. }, {
  12037. 'aria-hidden': 'true'
  12038. });
  12039. }
  12040. /**
  12041. * Enqueues updates to its own DOM as well as the DOM of its
  12042. * {@link TimeTooltip} child.
  12043. *
  12044. * @param {Object} seekBarRect
  12045. * The `ClientRect` for the {@link SeekBar} element.
  12046. *
  12047. * @param {number} seekBarPoint
  12048. * A number from 0 to 1, representing a horizontal reference point
  12049. * from the left edge of the {@link SeekBar}
  12050. */
  12051. ;
  12052. _proto.update = function update(seekBarRect, seekBarPoint) {
  12053. var timeTooltip = this.getChild('timeTooltip');
  12054. if (!timeTooltip) {
  12055. return;
  12056. }
  12057. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  12058. timeTooltip.updateTime(seekBarRect, seekBarPoint, time);
  12059. };
  12060. return PlayProgressBar;
  12061. }(Component);
  12062. /**
  12063. * Default options for {@link PlayProgressBar}.
  12064. *
  12065. * @type {Object}
  12066. * @private
  12067. */
  12068. PlayProgressBar.prototype.options_ = {
  12069. children: []
  12070. }; // Time tooltips should not be added to a player on mobile devices
  12071. if (!IS_IOS && !IS_ANDROID) {
  12072. PlayProgressBar.prototype.options_.children.push('timeTooltip');
  12073. }
  12074. Component.registerComponent('PlayProgressBar', PlayProgressBar);
  12075. /**
  12076. * The {@link MouseTimeDisplay} component tracks mouse movement over the
  12077. * {@link ProgressControl}. It displays an indicator and a {@link TimeTooltip}
  12078. * indicating the time which is represented by a given point in the
  12079. * {@link ProgressControl}.
  12080. *
  12081. * @extends Component
  12082. */
  12083. var MouseTimeDisplay = /*#__PURE__*/function (_Component) {
  12084. inheritsLoose(MouseTimeDisplay, _Component);
  12085. /**
  12086. * Creates an instance of this class.
  12087. *
  12088. * @param {Player} player
  12089. * The {@link Player} that this class should be attached to.
  12090. *
  12091. * @param {Object} [options]
  12092. * The key/value store of player options.
  12093. */
  12094. function MouseTimeDisplay(player, options) {
  12095. var _this;
  12096. _this = _Component.call(this, player, options) || this;
  12097. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  12098. return _this;
  12099. }
  12100. /**
  12101. * Create the DOM element for this class.
  12102. *
  12103. * @return {Element}
  12104. * The element that was created.
  12105. */
  12106. var _proto = MouseTimeDisplay.prototype;
  12107. _proto.createEl = function createEl() {
  12108. return _Component.prototype.createEl.call(this, 'div', {
  12109. className: 'vjs-mouse-display'
  12110. });
  12111. }
  12112. /**
  12113. * Enqueues updates to its own DOM as well as the DOM of its
  12114. * {@link TimeTooltip} child.
  12115. *
  12116. * @param {Object} seekBarRect
  12117. * The `ClientRect` for the {@link SeekBar} element.
  12118. *
  12119. * @param {number} seekBarPoint
  12120. * A number from 0 to 1, representing a horizontal reference point
  12121. * from the left edge of the {@link SeekBar}
  12122. */
  12123. ;
  12124. _proto.update = function update(seekBarRect, seekBarPoint) {
  12125. var _this2 = this;
  12126. var time = seekBarPoint * this.player_.duration();
  12127. this.getChild('timeTooltip').updateTime(seekBarRect, seekBarPoint, time, function () {
  12128. _this2.el_.style.left = seekBarRect.width * seekBarPoint + "px";
  12129. });
  12130. };
  12131. return MouseTimeDisplay;
  12132. }(Component);
  12133. /**
  12134. * Default options for `MouseTimeDisplay`
  12135. *
  12136. * @type {Object}
  12137. * @private
  12138. */
  12139. MouseTimeDisplay.prototype.options_ = {
  12140. children: ['timeTooltip']
  12141. };
  12142. Component.registerComponent('MouseTimeDisplay', MouseTimeDisplay);
  12143. var STEP_SECONDS = 5; // The multiplier of STEP_SECONDS that PgUp/PgDown move the timeline.
  12144. var PAGE_KEY_MULTIPLIER = 12;
  12145. /**
  12146. * Seek bar and container for the progress bars. Uses {@link PlayProgressBar}
  12147. * as its `bar`.
  12148. *
  12149. * @extends Slider
  12150. */
  12151. var SeekBar = /*#__PURE__*/function (_Slider) {
  12152. inheritsLoose(SeekBar, _Slider);
  12153. /**
  12154. * Creates an instance of this class.
  12155. *
  12156. * @param {Player} player
  12157. * The `Player` that this class should be attached to.
  12158. *
  12159. * @param {Object} [options]
  12160. * The key/value store of player options.
  12161. */
  12162. function SeekBar(player, options) {
  12163. var _this;
  12164. _this = _Slider.call(this, player, options) || this;
  12165. _this.setEventHandlers_();
  12166. return _this;
  12167. }
  12168. /**
  12169. * Sets the event handlers
  12170. *
  12171. * @private
  12172. */
  12173. var _proto = SeekBar.prototype;
  12174. _proto.setEventHandlers_ = function setEventHandlers_() {
  12175. var _this2 = this;
  12176. this.update_ = bind(this, this.update);
  12177. this.update = throttle(this.update_, UPDATE_REFRESH_INTERVAL);
  12178. this.on(this.player_, ['ended', 'durationchange', 'timeupdate'], this.update);
  12179. if (this.player_.liveTracker) {
  12180. this.on(this.player_.liveTracker, 'liveedgechange', this.update);
  12181. } // when playing, let's ensure we smoothly update the play progress bar
  12182. // via an interval
  12183. this.updateInterval = null;
  12184. this.enableIntervalHandler_ = function (e) {
  12185. return _this2.enableInterval_(e);
  12186. };
  12187. this.disableIntervalHandler_ = function (e) {
  12188. return _this2.disableInterval_(e);
  12189. };
  12190. this.on(this.player_, ['playing'], this.enableIntervalHandler_);
  12191. this.on(this.player_, ['ended', 'pause', 'waiting'], this.disableIntervalHandler_); // we don't need to update the play progress if the document is hidden,
  12192. // also, this causes the CPU to spike and eventually crash the page on IE11.
  12193. if ('hidden' in document && 'visibilityState' in document) {
  12194. this.on(document, 'visibilitychange', this.toggleVisibility_);
  12195. }
  12196. };
  12197. _proto.toggleVisibility_ = function toggleVisibility_(e) {
  12198. if (document.visibilityState === 'hidden') {
  12199. this.cancelNamedAnimationFrame('SeekBar#update');
  12200. this.cancelNamedAnimationFrame('Slider#update');
  12201. this.disableInterval_(e);
  12202. } else {
  12203. if (!this.player_.ended() && !this.player_.paused()) {
  12204. this.enableInterval_();
  12205. } // we just switched back to the page and someone may be looking, so, update ASAP
  12206. this.update();
  12207. }
  12208. };
  12209. _proto.enableInterval_ = function enableInterval_() {
  12210. if (this.updateInterval) {
  12211. return;
  12212. }
  12213. this.updateInterval = this.setInterval(this.update, UPDATE_REFRESH_INTERVAL);
  12214. };
  12215. _proto.disableInterval_ = function disableInterval_(e) {
  12216. if (this.player_.liveTracker && this.player_.liveTracker.isLive() && e && e.type !== 'ended') {
  12217. return;
  12218. }
  12219. if (!this.updateInterval) {
  12220. return;
  12221. }
  12222. this.clearInterval(this.updateInterval);
  12223. this.updateInterval = null;
  12224. }
  12225. /**
  12226. * Create the `Component`'s DOM element
  12227. *
  12228. * @return {Element}
  12229. * The element that was created.
  12230. */
  12231. ;
  12232. _proto.createEl = function createEl() {
  12233. return _Slider.prototype.createEl.call(this, 'div', {
  12234. className: 'vjs-progress-holder'
  12235. }, {
  12236. 'aria-label': this.localize('Progress Bar')
  12237. });
  12238. }
  12239. /**
  12240. * This function updates the play progress bar and accessibility
  12241. * attributes to whatever is passed in.
  12242. *
  12243. * @param {EventTarget~Event} [event]
  12244. * The `timeupdate` or `ended` event that caused this to run.
  12245. *
  12246. * @listens Player#timeupdate
  12247. *
  12248. * @return {number}
  12249. * The current percent at a number from 0-1
  12250. */
  12251. ;
  12252. _proto.update = function update(event) {
  12253. var _this3 = this;
  12254. // ignore updates while the tab is hidden
  12255. if (document.visibilityState === 'hidden') {
  12256. return;
  12257. }
  12258. var percent = _Slider.prototype.update.call(this);
  12259. this.requestNamedAnimationFrame('SeekBar#update', function () {
  12260. var currentTime = _this3.player_.ended() ? _this3.player_.duration() : _this3.getCurrentTime_();
  12261. var liveTracker = _this3.player_.liveTracker;
  12262. var duration = _this3.player_.duration();
  12263. if (liveTracker && liveTracker.isLive()) {
  12264. duration = _this3.player_.liveTracker.liveCurrentTime();
  12265. }
  12266. if (_this3.percent_ !== percent) {
  12267. // machine readable value of progress bar (percentage complete)
  12268. _this3.el_.setAttribute('aria-valuenow', (percent * 100).toFixed(2));
  12269. _this3.percent_ = percent;
  12270. }
  12271. if (_this3.currentTime_ !== currentTime || _this3.duration_ !== duration) {
  12272. // human readable value of progress bar (time complete)
  12273. _this3.el_.setAttribute('aria-valuetext', _this3.localize('progress bar timing: currentTime={1} duration={2}', [formatTime(currentTime, duration), formatTime(duration, duration)], '{1} of {2}'));
  12274. _this3.currentTime_ = currentTime;
  12275. _this3.duration_ = duration;
  12276. } // update the progress bar time tooltip with the current time
  12277. if (_this3.bar) {
  12278. _this3.bar.update(getBoundingClientRect(_this3.el()), _this3.getProgress());
  12279. }
  12280. });
  12281. return percent;
  12282. }
  12283. /**
  12284. * Prevent liveThreshold from causing seeks to seem like they
  12285. * are not happening from a user perspective.
  12286. *
  12287. * @param {number} ct
  12288. * current time to seek to
  12289. */
  12290. ;
  12291. _proto.userSeek_ = function userSeek_(ct) {
  12292. if (this.player_.liveTracker && this.player_.liveTracker.isLive()) {
  12293. this.player_.liveTracker.nextSeekedFromUser();
  12294. }
  12295. this.player_.currentTime(ct);
  12296. }
  12297. /**
  12298. * Get the value of current time but allows for smooth scrubbing,
  12299. * when player can't keep up.
  12300. *
  12301. * @return {number}
  12302. * The current time value to display
  12303. *
  12304. * @private
  12305. */
  12306. ;
  12307. _proto.getCurrentTime_ = function getCurrentTime_() {
  12308. return this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  12309. }
  12310. /**
  12311. * Get the percentage of media played so far.
  12312. *
  12313. * @return {number}
  12314. * The percentage of media played so far (0 to 1).
  12315. */
  12316. ;
  12317. _proto.getPercent = function getPercent() {
  12318. var currentTime = this.getCurrentTime_();
  12319. var percent;
  12320. var liveTracker = this.player_.liveTracker;
  12321. if (liveTracker && liveTracker.isLive()) {
  12322. percent = (currentTime - liveTracker.seekableStart()) / liveTracker.liveWindow(); // prevent the percent from changing at the live edge
  12323. if (liveTracker.atLiveEdge()) {
  12324. percent = 1;
  12325. }
  12326. } else {
  12327. percent = currentTime / this.player_.duration();
  12328. }
  12329. return percent;
  12330. }
  12331. /**
  12332. * Handle mouse down on seek bar
  12333. *
  12334. * @param {EventTarget~Event} event
  12335. * The `mousedown` event that caused this to run.
  12336. *
  12337. * @listens mousedown
  12338. */
  12339. ;
  12340. _proto.handleMouseDown = function handleMouseDown(event) {
  12341. if (!isSingleLeftClick(event)) {
  12342. return;
  12343. } // Stop event propagation to prevent double fire in progress-control.js
  12344. event.stopPropagation();
  12345. this.videoWasPlaying = !this.player_.paused();
  12346. this.player_.pause();
  12347. _Slider.prototype.handleMouseDown.call(this, event);
  12348. }
  12349. /**
  12350. * Handle mouse move on seek bar
  12351. *
  12352. * @param {EventTarget~Event} event
  12353. * The `mousemove` event that caused this to run.
  12354. * @param {boolean} mouseDown this is a flag that should be set to true if `handleMouseMove` is called directly. It allows us to skip things that should not happen if coming from mouse down but should happen on regular mouse move handler. Defaults to false
  12355. *
  12356. * @listens mousemove
  12357. */
  12358. ;
  12359. _proto.handleMouseMove = function handleMouseMove(event, mouseDown) {
  12360. if (mouseDown === void 0) {
  12361. mouseDown = false;
  12362. }
  12363. if (!isSingleLeftClick(event)) {
  12364. return;
  12365. }
  12366. if (!mouseDown && !this.player_.scrubbing()) {
  12367. this.player_.scrubbing(true);
  12368. }
  12369. var newTime;
  12370. var distance = this.calculateDistance(event);
  12371. var liveTracker = this.player_.liveTracker;
  12372. if (!liveTracker || !liveTracker.isLive()) {
  12373. newTime = distance * this.player_.duration(); // Don't let video end while scrubbing.
  12374. if (newTime === this.player_.duration()) {
  12375. newTime = newTime - 0.1;
  12376. }
  12377. } else {
  12378. if (distance >= 0.99) {
  12379. liveTracker.seekToLiveEdge();
  12380. return;
  12381. }
  12382. var seekableStart = liveTracker.seekableStart();
  12383. var seekableEnd = liveTracker.liveCurrentTime();
  12384. newTime = seekableStart + distance * liveTracker.liveWindow(); // Don't let video end while scrubbing.
  12385. if (newTime >= seekableEnd) {
  12386. newTime = seekableEnd;
  12387. } // Compensate for precision differences so that currentTime is not less
  12388. // than seekable start
  12389. if (newTime <= seekableStart) {
  12390. newTime = seekableStart + 0.1;
  12391. } // On android seekableEnd can be Infinity sometimes,
  12392. // this will cause newTime to be Infinity, which is
  12393. // not a valid currentTime.
  12394. if (newTime === Infinity) {
  12395. return;
  12396. }
  12397. } // Set new time (tell player to seek to new time)
  12398. this.userSeek_(newTime);
  12399. };
  12400. _proto.enable = function enable() {
  12401. _Slider.prototype.enable.call(this);
  12402. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  12403. if (!mouseTimeDisplay) {
  12404. return;
  12405. }
  12406. mouseTimeDisplay.show();
  12407. };
  12408. _proto.disable = function disable() {
  12409. _Slider.prototype.disable.call(this);
  12410. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  12411. if (!mouseTimeDisplay) {
  12412. return;
  12413. }
  12414. mouseTimeDisplay.hide();
  12415. }
  12416. /**
  12417. * Handle mouse up on seek bar
  12418. *
  12419. * @param {EventTarget~Event} event
  12420. * The `mouseup` event that caused this to run.
  12421. *
  12422. * @listens mouseup
  12423. */
  12424. ;
  12425. _proto.handleMouseUp = function handleMouseUp(event) {
  12426. _Slider.prototype.handleMouseUp.call(this, event); // Stop event propagation to prevent double fire in progress-control.js
  12427. if (event) {
  12428. event.stopPropagation();
  12429. }
  12430. this.player_.scrubbing(false);
  12431. /**
  12432. * Trigger timeupdate because we're done seeking and the time has changed.
  12433. * This is particularly useful for if the player is paused to time the time displays.
  12434. *
  12435. * @event Tech#timeupdate
  12436. * @type {EventTarget~Event}
  12437. */
  12438. this.player_.trigger({
  12439. type: 'timeupdate',
  12440. target: this,
  12441. manuallyTriggered: true
  12442. });
  12443. if (this.videoWasPlaying) {
  12444. silencePromise(this.player_.play());
  12445. } else {
  12446. // We're done seeking and the time has changed.
  12447. // If the player is paused, make sure we display the correct time on the seek bar.
  12448. this.update_();
  12449. }
  12450. }
  12451. /**
  12452. * Move more quickly fast forward for keyboard-only users
  12453. */
  12454. ;
  12455. _proto.stepForward = function stepForward() {
  12456. this.userSeek_(this.player_.currentTime() + STEP_SECONDS);
  12457. }
  12458. /**
  12459. * Move more quickly rewind for keyboard-only users
  12460. */
  12461. ;
  12462. _proto.stepBack = function stepBack() {
  12463. this.userSeek_(this.player_.currentTime() - STEP_SECONDS);
  12464. }
  12465. /**
  12466. * Toggles the playback state of the player
  12467. * This gets called when enter or space is used on the seekbar
  12468. *
  12469. * @param {EventTarget~Event} event
  12470. * The `keydown` event that caused this function to be called
  12471. *
  12472. */
  12473. ;
  12474. _proto.handleAction = function handleAction(event) {
  12475. if (this.player_.paused()) {
  12476. this.player_.play();
  12477. } else {
  12478. this.player_.pause();
  12479. }
  12480. }
  12481. /**
  12482. * Called when this SeekBar has focus and a key gets pressed down.
  12483. * Supports the following keys:
  12484. *
  12485. * Space or Enter key fire a click event
  12486. * Home key moves to start of the timeline
  12487. * End key moves to end of the timeline
  12488. * Digit "0" through "9" keys move to 0%, 10% ... 80%, 90% of the timeline
  12489. * PageDown key moves back a larger step than ArrowDown
  12490. * PageUp key moves forward a large step
  12491. *
  12492. * @param {EventTarget~Event} event
  12493. * The `keydown` event that caused this function to be called.
  12494. *
  12495. * @listens keydown
  12496. */
  12497. ;
  12498. _proto.handleKeyDown = function handleKeyDown(event) {
  12499. var liveTracker = this.player_.liveTracker;
  12500. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  12501. event.preventDefault();
  12502. event.stopPropagation();
  12503. this.handleAction(event);
  12504. } else if (keycode.isEventKey(event, 'Home')) {
  12505. event.preventDefault();
  12506. event.stopPropagation();
  12507. this.userSeek_(0);
  12508. } else if (keycode.isEventKey(event, 'End')) {
  12509. event.preventDefault();
  12510. event.stopPropagation();
  12511. if (liveTracker && liveTracker.isLive()) {
  12512. this.userSeek_(liveTracker.liveCurrentTime());
  12513. } else {
  12514. this.userSeek_(this.player_.duration());
  12515. }
  12516. } else if (/^[0-9]$/.test(keycode(event))) {
  12517. event.preventDefault();
  12518. event.stopPropagation();
  12519. var gotoFraction = (keycode.codes[keycode(event)] - keycode.codes['0']) * 10.0 / 100.0;
  12520. if (liveTracker && liveTracker.isLive()) {
  12521. this.userSeek_(liveTracker.seekableStart() + liveTracker.liveWindow() * gotoFraction);
  12522. } else {
  12523. this.userSeek_(this.player_.duration() * gotoFraction);
  12524. }
  12525. } else if (keycode.isEventKey(event, 'PgDn')) {
  12526. event.preventDefault();
  12527. event.stopPropagation();
  12528. this.userSeek_(this.player_.currentTime() - STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  12529. } else if (keycode.isEventKey(event, 'PgUp')) {
  12530. event.preventDefault();
  12531. event.stopPropagation();
  12532. this.userSeek_(this.player_.currentTime() + STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  12533. } else {
  12534. // Pass keydown handling up for unsupported keys
  12535. _Slider.prototype.handleKeyDown.call(this, event);
  12536. }
  12537. };
  12538. _proto.dispose = function dispose() {
  12539. this.disableInterval_();
  12540. this.off(this.player_, ['ended', 'durationchange', 'timeupdate'], this.update);
  12541. if (this.player_.liveTracker) {
  12542. this.off(this.player_.liveTracker, 'liveedgechange', this.update);
  12543. }
  12544. this.off(this.player_, ['playing'], this.enableIntervalHandler_);
  12545. this.off(this.player_, ['ended', 'pause', 'waiting'], this.disableIntervalHandler_); // we don't need to update the play progress if the document is hidden,
  12546. // also, this causes the CPU to spike and eventually crash the page on IE11.
  12547. if ('hidden' in document && 'visibilityState' in document) {
  12548. this.off(document, 'visibilitychange', this.toggleVisibility_);
  12549. }
  12550. _Slider.prototype.dispose.call(this);
  12551. };
  12552. return SeekBar;
  12553. }(Slider);
  12554. /**
  12555. * Default options for the `SeekBar`
  12556. *
  12557. * @type {Object}
  12558. * @private
  12559. */
  12560. SeekBar.prototype.options_ = {
  12561. children: ['loadProgressBar', 'playProgressBar'],
  12562. barName: 'playProgressBar'
  12563. }; // MouseTimeDisplay tooltips should not be added to a player on mobile devices
  12564. if (!IS_IOS && !IS_ANDROID) {
  12565. SeekBar.prototype.options_.children.splice(1, 0, 'mouseTimeDisplay');
  12566. }
  12567. Component.registerComponent('SeekBar', SeekBar);
  12568. /**
  12569. * The Progress Control component contains the seek bar, load progress,
  12570. * and play progress.
  12571. *
  12572. * @extends Component
  12573. */
  12574. var ProgressControl = /*#__PURE__*/function (_Component) {
  12575. inheritsLoose(ProgressControl, _Component);
  12576. /**
  12577. * Creates an instance of this class.
  12578. *
  12579. * @param {Player} player
  12580. * The `Player` that this class should be attached to.
  12581. *
  12582. * @param {Object} [options]
  12583. * The key/value store of player options.
  12584. */
  12585. function ProgressControl(player, options) {
  12586. var _this;
  12587. _this = _Component.call(this, player, options) || this;
  12588. _this.handleMouseMove = throttle(bind(assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  12589. _this.throttledHandleMouseSeek = throttle(bind(assertThisInitialized(_this), _this.handleMouseSeek), UPDATE_REFRESH_INTERVAL);
  12590. _this.handleMouseUpHandler_ = function (e) {
  12591. return _this.handleMouseUp(e);
  12592. };
  12593. _this.handleMouseDownHandler_ = function (e) {
  12594. return _this.handleMouseDown(e);
  12595. };
  12596. _this.enable();
  12597. return _this;
  12598. }
  12599. /**
  12600. * Create the `Component`'s DOM element
  12601. *
  12602. * @return {Element}
  12603. * The element that was created.
  12604. */
  12605. var _proto = ProgressControl.prototype;
  12606. _proto.createEl = function createEl() {
  12607. return _Component.prototype.createEl.call(this, 'div', {
  12608. className: 'vjs-progress-control vjs-control'
  12609. });
  12610. }
  12611. /**
  12612. * When the mouse moves over the `ProgressControl`, the pointer position
  12613. * gets passed down to the `MouseTimeDisplay` component.
  12614. *
  12615. * @param {EventTarget~Event} event
  12616. * The `mousemove` event that caused this function to run.
  12617. *
  12618. * @listen mousemove
  12619. */
  12620. ;
  12621. _proto.handleMouseMove = function handleMouseMove(event) {
  12622. var seekBar = this.getChild('seekBar');
  12623. if (!seekBar) {
  12624. return;
  12625. }
  12626. var playProgressBar = seekBar.getChild('playProgressBar');
  12627. var mouseTimeDisplay = seekBar.getChild('mouseTimeDisplay');
  12628. if (!playProgressBar && !mouseTimeDisplay) {
  12629. return;
  12630. }
  12631. var seekBarEl = seekBar.el();
  12632. var seekBarRect = findPosition(seekBarEl);
  12633. var seekBarPoint = getPointerPosition(seekBarEl, event).x; // The default skin has a gap on either side of the `SeekBar`. This means
  12634. // that it's possible to trigger this behavior outside the boundaries of
  12635. // the `SeekBar`. This ensures we stay within it at all times.
  12636. seekBarPoint = clamp(seekBarPoint, 0, 1);
  12637. if (mouseTimeDisplay) {
  12638. mouseTimeDisplay.update(seekBarRect, seekBarPoint);
  12639. }
  12640. if (playProgressBar) {
  12641. playProgressBar.update(seekBarRect, seekBar.getProgress());
  12642. }
  12643. }
  12644. /**
  12645. * A throttled version of the {@link ProgressControl#handleMouseSeek} listener.
  12646. *
  12647. * @method ProgressControl#throttledHandleMouseSeek
  12648. * @param {EventTarget~Event} event
  12649. * The `mousemove` event that caused this function to run.
  12650. *
  12651. * @listen mousemove
  12652. * @listen touchmove
  12653. */
  12654. /**
  12655. * Handle `mousemove` or `touchmove` events on the `ProgressControl`.
  12656. *
  12657. * @param {EventTarget~Event} event
  12658. * `mousedown` or `touchstart` event that triggered this function
  12659. *
  12660. * @listens mousemove
  12661. * @listens touchmove
  12662. */
  12663. ;
  12664. _proto.handleMouseSeek = function handleMouseSeek(event) {
  12665. var seekBar = this.getChild('seekBar');
  12666. if (seekBar) {
  12667. seekBar.handleMouseMove(event);
  12668. }
  12669. }
  12670. /**
  12671. * Are controls are currently enabled for this progress control.
  12672. *
  12673. * @return {boolean}
  12674. * true if controls are enabled, false otherwise
  12675. */
  12676. ;
  12677. _proto.enabled = function enabled() {
  12678. return this.enabled_;
  12679. }
  12680. /**
  12681. * Disable all controls on the progress control and its children
  12682. */
  12683. ;
  12684. _proto.disable = function disable() {
  12685. this.children().forEach(function (child) {
  12686. return child.disable && child.disable();
  12687. });
  12688. if (!this.enabled()) {
  12689. return;
  12690. }
  12691. this.off(['mousedown', 'touchstart'], this.handleMouseDownHandler_);
  12692. this.off(this.el_, 'mousemove', this.handleMouseMove);
  12693. this.removeListenersAddedOnMousedownAndTouchstart();
  12694. this.addClass('disabled');
  12695. this.enabled_ = false; // Restore normal playback state if controls are disabled while scrubbing
  12696. if (this.player_.scrubbing()) {
  12697. var seekBar = this.getChild('seekBar');
  12698. this.player_.scrubbing(false);
  12699. if (seekBar.videoWasPlaying) {
  12700. silencePromise(this.player_.play());
  12701. }
  12702. }
  12703. }
  12704. /**
  12705. * Enable all controls on the progress control and its children
  12706. */
  12707. ;
  12708. _proto.enable = function enable() {
  12709. this.children().forEach(function (child) {
  12710. return child.enable && child.enable();
  12711. });
  12712. if (this.enabled()) {
  12713. return;
  12714. }
  12715. this.on(['mousedown', 'touchstart'], this.handleMouseDownHandler_);
  12716. this.on(this.el_, 'mousemove', this.handleMouseMove);
  12717. this.removeClass('disabled');
  12718. this.enabled_ = true;
  12719. }
  12720. /**
  12721. * Cleanup listeners after the user finishes interacting with the progress controls
  12722. */
  12723. ;
  12724. _proto.removeListenersAddedOnMousedownAndTouchstart = function removeListenersAddedOnMousedownAndTouchstart() {
  12725. var doc = this.el_.ownerDocument;
  12726. this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
  12727. this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
  12728. this.off(doc, 'mouseup', this.handleMouseUpHandler_);
  12729. this.off(doc, 'touchend', this.handleMouseUpHandler_);
  12730. }
  12731. /**
  12732. * Handle `mousedown` or `touchstart` events on the `ProgressControl`.
  12733. *
  12734. * @param {EventTarget~Event} event
  12735. * `mousedown` or `touchstart` event that triggered this function
  12736. *
  12737. * @listens mousedown
  12738. * @listens touchstart
  12739. */
  12740. ;
  12741. _proto.handleMouseDown = function handleMouseDown(event) {
  12742. var doc = this.el_.ownerDocument;
  12743. var seekBar = this.getChild('seekBar');
  12744. if (seekBar) {
  12745. seekBar.handleMouseDown(event);
  12746. }
  12747. this.on(doc, 'mousemove', this.throttledHandleMouseSeek);
  12748. this.on(doc, 'touchmove', this.throttledHandleMouseSeek);
  12749. this.on(doc, 'mouseup', this.handleMouseUpHandler_);
  12750. this.on(doc, 'touchend', this.handleMouseUpHandler_);
  12751. }
  12752. /**
  12753. * Handle `mouseup` or `touchend` events on the `ProgressControl`.
  12754. *
  12755. * @param {EventTarget~Event} event
  12756. * `mouseup` or `touchend` event that triggered this function.
  12757. *
  12758. * @listens touchend
  12759. * @listens mouseup
  12760. */
  12761. ;
  12762. _proto.handleMouseUp = function handleMouseUp(event) {
  12763. var seekBar = this.getChild('seekBar');
  12764. if (seekBar) {
  12765. seekBar.handleMouseUp(event);
  12766. }
  12767. this.removeListenersAddedOnMousedownAndTouchstart();
  12768. };
  12769. return ProgressControl;
  12770. }(Component);
  12771. /**
  12772. * Default options for `ProgressControl`
  12773. *
  12774. * @type {Object}
  12775. * @private
  12776. */
  12777. ProgressControl.prototype.options_ = {
  12778. children: ['seekBar']
  12779. };
  12780. Component.registerComponent('ProgressControl', ProgressControl);
  12781. /**
  12782. * Toggle Picture-in-Picture mode
  12783. *
  12784. * @extends Button
  12785. */
  12786. var PictureInPictureToggle = /*#__PURE__*/function (_Button) {
  12787. inheritsLoose(PictureInPictureToggle, _Button);
  12788. /**
  12789. * Creates an instance of this class.
  12790. *
  12791. * @param {Player} player
  12792. * The `Player` that this class should be attached to.
  12793. *
  12794. * @param {Object} [options]
  12795. * The key/value store of player options.
  12796. *
  12797. * @listens Player#enterpictureinpicture
  12798. * @listens Player#leavepictureinpicture
  12799. */
  12800. function PictureInPictureToggle(player, options) {
  12801. var _this;
  12802. _this = _Button.call(this, player, options) || this;
  12803. _this.on(player, ['enterpictureinpicture', 'leavepictureinpicture'], function (e) {
  12804. return _this.handlePictureInPictureChange(e);
  12805. });
  12806. _this.on(player, ['disablepictureinpicturechanged', 'loadedmetadata'], function (e) {
  12807. return _this.handlePictureInPictureEnabledChange(e);
  12808. });
  12809. _this.on(player, ['loadedmetadata', 'audioonlymodechange', 'audiopostermodechange'], function () {
  12810. // This audio detection will not detect HLS or DASH audio-only streams because there was no reliable way to detect them at the time
  12811. var isSourceAudio = player.currentType().substring(0, 5) === 'audio';
  12812. if (isSourceAudio || player.audioPosterMode() || player.audioOnlyMode()) {
  12813. if (player.isInPictureInPicture()) {
  12814. player.exitPictureInPicture();
  12815. }
  12816. _this.hide();
  12817. } else {
  12818. _this.show();
  12819. }
  12820. }); // TODO: Deactivate button on player emptied event.
  12821. _this.disable();
  12822. return _this;
  12823. }
  12824. /**
  12825. * Builds the default DOM `className`.
  12826. *
  12827. * @return {string}
  12828. * The DOM `className` for this object.
  12829. */
  12830. var _proto = PictureInPictureToggle.prototype;
  12831. _proto.buildCSSClass = function buildCSSClass() {
  12832. return "vjs-picture-in-picture-control " + _Button.prototype.buildCSSClass.call(this);
  12833. }
  12834. /**
  12835. * Enables or disables button based on document.pictureInPictureEnabled property value
  12836. * or on value returned by player.disablePictureInPicture() method.
  12837. */
  12838. ;
  12839. _proto.handlePictureInPictureEnabledChange = function handlePictureInPictureEnabledChange() {
  12840. if (document.pictureInPictureEnabled && this.player_.disablePictureInPicture() === false) {
  12841. this.enable();
  12842. } else {
  12843. this.disable();
  12844. }
  12845. }
  12846. /**
  12847. * Handles enterpictureinpicture and leavepictureinpicture on the player and change control text accordingly.
  12848. *
  12849. * @param {EventTarget~Event} [event]
  12850. * The {@link Player#enterpictureinpicture} or {@link Player#leavepictureinpicture} event that caused this function to be
  12851. * called.
  12852. *
  12853. * @listens Player#enterpictureinpicture
  12854. * @listens Player#leavepictureinpicture
  12855. */
  12856. ;
  12857. _proto.handlePictureInPictureChange = function handlePictureInPictureChange(event) {
  12858. if (this.player_.isInPictureInPicture()) {
  12859. this.controlText('Exit Picture-in-Picture');
  12860. } else {
  12861. this.controlText('Picture-in-Picture');
  12862. }
  12863. this.handlePictureInPictureEnabledChange();
  12864. }
  12865. /**
  12866. * This gets called when an `PictureInPictureToggle` is "clicked". See
  12867. * {@link ClickableComponent} for more detailed information on what a click can be.
  12868. *
  12869. * @param {EventTarget~Event} [event]
  12870. * The `keydown`, `tap`, or `click` event that caused this function to be
  12871. * called.
  12872. *
  12873. * @listens tap
  12874. * @listens click
  12875. */
  12876. ;
  12877. _proto.handleClick = function handleClick(event) {
  12878. if (!this.player_.isInPictureInPicture()) {
  12879. this.player_.requestPictureInPicture();
  12880. } else {
  12881. this.player_.exitPictureInPicture();
  12882. }
  12883. };
  12884. return PictureInPictureToggle;
  12885. }(Button);
  12886. /**
  12887. * The text that should display over the `PictureInPictureToggle`s controls. Added for localization.
  12888. *
  12889. * @type {string}
  12890. * @private
  12891. */
  12892. PictureInPictureToggle.prototype.controlText_ = 'Picture-in-Picture';
  12893. Component.registerComponent('PictureInPictureToggle', PictureInPictureToggle);
  12894. /**
  12895. * Toggle fullscreen video
  12896. *
  12897. * @extends Button
  12898. */
  12899. var FullscreenToggle = /*#__PURE__*/function (_Button) {
  12900. inheritsLoose(FullscreenToggle, _Button);
  12901. /**
  12902. * Creates an instance of this class.
  12903. *
  12904. * @param {Player} player
  12905. * The `Player` that this class should be attached to.
  12906. *
  12907. * @param {Object} [options]
  12908. * The key/value store of player options.
  12909. */
  12910. function FullscreenToggle(player, options) {
  12911. var _this;
  12912. _this = _Button.call(this, player, options) || this;
  12913. _this.on(player, 'fullscreenchange', function (e) {
  12914. return _this.handleFullscreenChange(e);
  12915. });
  12916. if (document[player.fsApi_.fullscreenEnabled] === false) {
  12917. _this.disable();
  12918. }
  12919. return _this;
  12920. }
  12921. /**
  12922. * Builds the default DOM `className`.
  12923. *
  12924. * @return {string}
  12925. * The DOM `className` for this object.
  12926. */
  12927. var _proto = FullscreenToggle.prototype;
  12928. _proto.buildCSSClass = function buildCSSClass() {
  12929. return "vjs-fullscreen-control " + _Button.prototype.buildCSSClass.call(this);
  12930. }
  12931. /**
  12932. * Handles fullscreenchange on the player and change control text accordingly.
  12933. *
  12934. * @param {EventTarget~Event} [event]
  12935. * The {@link Player#fullscreenchange} event that caused this function to be
  12936. * called.
  12937. *
  12938. * @listens Player#fullscreenchange
  12939. */
  12940. ;
  12941. _proto.handleFullscreenChange = function handleFullscreenChange(event) {
  12942. if (this.player_.isFullscreen()) {
  12943. this.controlText('Non-Fullscreen');
  12944. } else {
  12945. this.controlText('Fullscreen');
  12946. }
  12947. }
  12948. /**
  12949. * This gets called when an `FullscreenToggle` is "clicked". See
  12950. * {@link ClickableComponent} for more detailed information on what a click can be.
  12951. *
  12952. * @param {EventTarget~Event} [event]
  12953. * The `keydown`, `tap`, or `click` event that caused this function to be
  12954. * called.
  12955. *
  12956. * @listens tap
  12957. * @listens click
  12958. */
  12959. ;
  12960. _proto.handleClick = function handleClick(event) {
  12961. if (!this.player_.isFullscreen()) {
  12962. this.player_.requestFullscreen();
  12963. } else {
  12964. this.player_.exitFullscreen();
  12965. }
  12966. };
  12967. return FullscreenToggle;
  12968. }(Button);
  12969. /**
  12970. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  12971. *
  12972. * @type {string}
  12973. * @private
  12974. */
  12975. FullscreenToggle.prototype.controlText_ = 'Fullscreen';
  12976. Component.registerComponent('FullscreenToggle', FullscreenToggle);
  12977. /**
  12978. * Check if volume control is supported and if it isn't hide the
  12979. * `Component` that was passed using the `vjs-hidden` class.
  12980. *
  12981. * @param {Component} self
  12982. * The component that should be hidden if volume is unsupported
  12983. *
  12984. * @param {Player} player
  12985. * A reference to the player
  12986. *
  12987. * @private
  12988. */
  12989. var checkVolumeSupport = function checkVolumeSupport(self, player) {
  12990. // hide volume controls when they're not supported by the current tech
  12991. if (player.tech_ && !player.tech_.featuresVolumeControl) {
  12992. self.addClass('vjs-hidden');
  12993. }
  12994. self.on(player, 'loadstart', function () {
  12995. if (!player.tech_.featuresVolumeControl) {
  12996. self.addClass('vjs-hidden');
  12997. } else {
  12998. self.removeClass('vjs-hidden');
  12999. }
  13000. });
  13001. };
  13002. /**
  13003. * Shows volume level
  13004. *
  13005. * @extends Component
  13006. */
  13007. var VolumeLevel = /*#__PURE__*/function (_Component) {
  13008. inheritsLoose(VolumeLevel, _Component);
  13009. function VolumeLevel() {
  13010. return _Component.apply(this, arguments) || this;
  13011. }
  13012. var _proto = VolumeLevel.prototype;
  13013. /**
  13014. * Create the `Component`'s DOM element
  13015. *
  13016. * @return {Element}
  13017. * The element that was created.
  13018. */
  13019. _proto.createEl = function createEl() {
  13020. var el = _Component.prototype.createEl.call(this, 'div', {
  13021. className: 'vjs-volume-level'
  13022. });
  13023. el.appendChild(_Component.prototype.createEl.call(this, 'span', {
  13024. className: 'vjs-control-text'
  13025. }));
  13026. return el;
  13027. };
  13028. return VolumeLevel;
  13029. }(Component);
  13030. Component.registerComponent('VolumeLevel', VolumeLevel);
  13031. /**
  13032. * Volume level tooltips display a volume above or side by side the volume bar.
  13033. *
  13034. * @extends Component
  13035. */
  13036. var VolumeLevelTooltip = /*#__PURE__*/function (_Component) {
  13037. inheritsLoose(VolumeLevelTooltip, _Component);
  13038. /**
  13039. * Creates an instance of this class.
  13040. *
  13041. * @param {Player} player
  13042. * The {@link Player} that this class should be attached to.
  13043. *
  13044. * @param {Object} [options]
  13045. * The key/value store of player options.
  13046. */
  13047. function VolumeLevelTooltip(player, options) {
  13048. var _this;
  13049. _this = _Component.call(this, player, options) || this;
  13050. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13051. return _this;
  13052. }
  13053. /**
  13054. * Create the volume tooltip DOM element
  13055. *
  13056. * @return {Element}
  13057. * The element that was created.
  13058. */
  13059. var _proto = VolumeLevelTooltip.prototype;
  13060. _proto.createEl = function createEl() {
  13061. return _Component.prototype.createEl.call(this, 'div', {
  13062. className: 'vjs-volume-tooltip'
  13063. }, {
  13064. 'aria-hidden': 'true'
  13065. });
  13066. }
  13067. /**
  13068. * Updates the position of the tooltip relative to the `VolumeBar` and
  13069. * its content text.
  13070. *
  13071. * @param {Object} rangeBarRect
  13072. * The `ClientRect` for the {@link VolumeBar} element.
  13073. *
  13074. * @param {number} rangeBarPoint
  13075. * A number from 0 to 1, representing a horizontal/vertical reference point
  13076. * from the left edge of the {@link VolumeBar}
  13077. *
  13078. * @param {boolean} vertical
  13079. * Referees to the Volume control position
  13080. * in the control bar{@link VolumeControl}
  13081. *
  13082. */
  13083. ;
  13084. _proto.update = function update(rangeBarRect, rangeBarPoint, vertical, content) {
  13085. if (!vertical) {
  13086. var tooltipRect = getBoundingClientRect(this.el_);
  13087. var playerRect = getBoundingClientRect(this.player_.el());
  13088. var volumeBarPointPx = rangeBarRect.width * rangeBarPoint;
  13089. if (!playerRect || !tooltipRect) {
  13090. return;
  13091. }
  13092. var spaceLeftOfPoint = rangeBarRect.left - playerRect.left + volumeBarPointPx;
  13093. var spaceRightOfPoint = rangeBarRect.width - volumeBarPointPx + (playerRect.right - rangeBarRect.right);
  13094. var pullTooltipBy = tooltipRect.width / 2;
  13095. if (spaceLeftOfPoint < pullTooltipBy) {
  13096. pullTooltipBy += pullTooltipBy - spaceLeftOfPoint;
  13097. } else if (spaceRightOfPoint < pullTooltipBy) {
  13098. pullTooltipBy = spaceRightOfPoint;
  13099. }
  13100. if (pullTooltipBy < 0) {
  13101. pullTooltipBy = 0;
  13102. } else if (pullTooltipBy > tooltipRect.width) {
  13103. pullTooltipBy = tooltipRect.width;
  13104. }
  13105. this.el_.style.right = "-" + pullTooltipBy + "px";
  13106. }
  13107. this.write(content + "%");
  13108. }
  13109. /**
  13110. * Write the volume to the tooltip DOM element.
  13111. *
  13112. * @param {string} content
  13113. * The formatted volume for the tooltip.
  13114. */
  13115. ;
  13116. _proto.write = function write(content) {
  13117. textContent(this.el_, content);
  13118. }
  13119. /**
  13120. * Updates the position of the volume tooltip relative to the `VolumeBar`.
  13121. *
  13122. * @param {Object} rangeBarRect
  13123. * The `ClientRect` for the {@link VolumeBar} element.
  13124. *
  13125. * @param {number} rangeBarPoint
  13126. * A number from 0 to 1, representing a horizontal/vertical reference point
  13127. * from the left edge of the {@link VolumeBar}
  13128. *
  13129. * @param {boolean} vertical
  13130. * Referees to the Volume control position
  13131. * in the control bar{@link VolumeControl}
  13132. *
  13133. * @param {number} volume
  13134. * The volume level to update the tooltip to
  13135. *
  13136. * @param {Function} cb
  13137. * A function that will be called during the request animation frame
  13138. * for tooltips that need to do additional animations from the default
  13139. */
  13140. ;
  13141. _proto.updateVolume = function updateVolume(rangeBarRect, rangeBarPoint, vertical, volume, cb) {
  13142. var _this2 = this;
  13143. this.requestNamedAnimationFrame('VolumeLevelTooltip#updateVolume', function () {
  13144. _this2.update(rangeBarRect, rangeBarPoint, vertical, volume.toFixed(0));
  13145. if (cb) {
  13146. cb();
  13147. }
  13148. });
  13149. };
  13150. return VolumeLevelTooltip;
  13151. }(Component);
  13152. Component.registerComponent('VolumeLevelTooltip', VolumeLevelTooltip);
  13153. /**
  13154. * The {@link MouseVolumeLevelDisplay} component tracks mouse movement over the
  13155. * {@link VolumeControl}. It displays an indicator and a {@link VolumeLevelTooltip}
  13156. * indicating the volume level which is represented by a given point in the
  13157. * {@link VolumeBar}.
  13158. *
  13159. * @extends Component
  13160. */
  13161. var MouseVolumeLevelDisplay = /*#__PURE__*/function (_Component) {
  13162. inheritsLoose(MouseVolumeLevelDisplay, _Component);
  13163. /**
  13164. * Creates an instance of this class.
  13165. *
  13166. * @param {Player} player
  13167. * The {@link Player} that this class should be attached to.
  13168. *
  13169. * @param {Object} [options]
  13170. * The key/value store of player options.
  13171. */
  13172. function MouseVolumeLevelDisplay(player, options) {
  13173. var _this;
  13174. _this = _Component.call(this, player, options) || this;
  13175. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13176. return _this;
  13177. }
  13178. /**
  13179. * Create the DOM element for this class.
  13180. *
  13181. * @return {Element}
  13182. * The element that was created.
  13183. */
  13184. var _proto = MouseVolumeLevelDisplay.prototype;
  13185. _proto.createEl = function createEl() {
  13186. return _Component.prototype.createEl.call(this, 'div', {
  13187. className: 'vjs-mouse-display'
  13188. });
  13189. }
  13190. /**
  13191. * Enquires updates to its own DOM as well as the DOM of its
  13192. * {@link VolumeLevelTooltip} child.
  13193. *
  13194. * @param {Object} rangeBarRect
  13195. * The `ClientRect` for the {@link VolumeBar} element.
  13196. *
  13197. * @param {number} rangeBarPoint
  13198. * A number from 0 to 1, representing a horizontal/vertical reference point
  13199. * from the left edge of the {@link VolumeBar}
  13200. *
  13201. * @param {boolean} vertical
  13202. * Referees to the Volume control position
  13203. * in the control bar{@link VolumeControl}
  13204. *
  13205. */
  13206. ;
  13207. _proto.update = function update(rangeBarRect, rangeBarPoint, vertical) {
  13208. var _this2 = this;
  13209. var volume = 100 * rangeBarPoint;
  13210. this.getChild('volumeLevelTooltip').updateVolume(rangeBarRect, rangeBarPoint, vertical, volume, function () {
  13211. if (vertical) {
  13212. _this2.el_.style.bottom = rangeBarRect.height * rangeBarPoint + "px";
  13213. } else {
  13214. _this2.el_.style.left = rangeBarRect.width * rangeBarPoint + "px";
  13215. }
  13216. });
  13217. };
  13218. return MouseVolumeLevelDisplay;
  13219. }(Component);
  13220. /**
  13221. * Default options for `MouseVolumeLevelDisplay`
  13222. *
  13223. * @type {Object}
  13224. * @private
  13225. */
  13226. MouseVolumeLevelDisplay.prototype.options_ = {
  13227. children: ['volumeLevelTooltip']
  13228. };
  13229. Component.registerComponent('MouseVolumeLevelDisplay', MouseVolumeLevelDisplay);
  13230. /**
  13231. * The bar that contains the volume level and can be clicked on to adjust the level
  13232. *
  13233. * @extends Slider
  13234. */
  13235. var VolumeBar = /*#__PURE__*/function (_Slider) {
  13236. inheritsLoose(VolumeBar, _Slider);
  13237. /**
  13238. * Creates an instance of this class.
  13239. *
  13240. * @param {Player} player
  13241. * The `Player` that this class should be attached to.
  13242. *
  13243. * @param {Object} [options]
  13244. * The key/value store of player options.
  13245. */
  13246. function VolumeBar(player, options) {
  13247. var _this;
  13248. _this = _Slider.call(this, player, options) || this;
  13249. _this.on('slideractive', function (e) {
  13250. return _this.updateLastVolume_(e);
  13251. });
  13252. _this.on(player, 'volumechange', function (e) {
  13253. return _this.updateARIAAttributes(e);
  13254. });
  13255. player.ready(function () {
  13256. return _this.updateARIAAttributes();
  13257. });
  13258. return _this;
  13259. }
  13260. /**
  13261. * Create the `Component`'s DOM element
  13262. *
  13263. * @return {Element}
  13264. * The element that was created.
  13265. */
  13266. var _proto = VolumeBar.prototype;
  13267. _proto.createEl = function createEl() {
  13268. return _Slider.prototype.createEl.call(this, 'div', {
  13269. className: 'vjs-volume-bar vjs-slider-bar'
  13270. }, {
  13271. 'aria-label': this.localize('Volume Level'),
  13272. 'aria-live': 'polite'
  13273. });
  13274. }
  13275. /**
  13276. * Handle mouse down on volume bar
  13277. *
  13278. * @param {EventTarget~Event} event
  13279. * The `mousedown` event that caused this to run.
  13280. *
  13281. * @listens mousedown
  13282. */
  13283. ;
  13284. _proto.handleMouseDown = function handleMouseDown(event) {
  13285. if (!isSingleLeftClick(event)) {
  13286. return;
  13287. }
  13288. _Slider.prototype.handleMouseDown.call(this, event);
  13289. }
  13290. /**
  13291. * Handle movement events on the {@link VolumeMenuButton}.
  13292. *
  13293. * @param {EventTarget~Event} event
  13294. * The event that caused this function to run.
  13295. *
  13296. * @listens mousemove
  13297. */
  13298. ;
  13299. _proto.handleMouseMove = function handleMouseMove(event) {
  13300. var mouseVolumeLevelDisplay = this.getChild('mouseVolumeLevelDisplay');
  13301. if (mouseVolumeLevelDisplay) {
  13302. var volumeBarEl = this.el();
  13303. var volumeBarRect = getBoundingClientRect(volumeBarEl);
  13304. var vertical = this.vertical();
  13305. var volumeBarPoint = getPointerPosition(volumeBarEl, event);
  13306. volumeBarPoint = vertical ? volumeBarPoint.y : volumeBarPoint.x; // The default skin has a gap on either side of the `VolumeBar`. This means
  13307. // that it's possible to trigger this behavior outside the boundaries of
  13308. // the `VolumeBar`. This ensures we stay within it at all times.
  13309. volumeBarPoint = clamp(volumeBarPoint, 0, 1);
  13310. mouseVolumeLevelDisplay.update(volumeBarRect, volumeBarPoint, vertical);
  13311. }
  13312. if (!isSingleLeftClick(event)) {
  13313. return;
  13314. }
  13315. this.checkMuted();
  13316. this.player_.volume(this.calculateDistance(event));
  13317. }
  13318. /**
  13319. * If the player is muted unmute it.
  13320. */
  13321. ;
  13322. _proto.checkMuted = function checkMuted() {
  13323. if (this.player_.muted()) {
  13324. this.player_.muted(false);
  13325. }
  13326. }
  13327. /**
  13328. * Get percent of volume level
  13329. *
  13330. * @return {number}
  13331. * Volume level percent as a decimal number.
  13332. */
  13333. ;
  13334. _proto.getPercent = function getPercent() {
  13335. if (this.player_.muted()) {
  13336. return 0;
  13337. }
  13338. return this.player_.volume();
  13339. }
  13340. /**
  13341. * Increase volume level for keyboard users
  13342. */
  13343. ;
  13344. _proto.stepForward = function stepForward() {
  13345. this.checkMuted();
  13346. this.player_.volume(this.player_.volume() + 0.1);
  13347. }
  13348. /**
  13349. * Decrease volume level for keyboard users
  13350. */
  13351. ;
  13352. _proto.stepBack = function stepBack() {
  13353. this.checkMuted();
  13354. this.player_.volume(this.player_.volume() - 0.1);
  13355. }
  13356. /**
  13357. * Update ARIA accessibility attributes
  13358. *
  13359. * @param {EventTarget~Event} [event]
  13360. * The `volumechange` event that caused this function to run.
  13361. *
  13362. * @listens Player#volumechange
  13363. */
  13364. ;
  13365. _proto.updateARIAAttributes = function updateARIAAttributes(event) {
  13366. var ariaValue = this.player_.muted() ? 0 : this.volumeAsPercentage_();
  13367. this.el_.setAttribute('aria-valuenow', ariaValue);
  13368. this.el_.setAttribute('aria-valuetext', ariaValue + '%');
  13369. }
  13370. /**
  13371. * Returns the current value of the player volume as a percentage
  13372. *
  13373. * @private
  13374. */
  13375. ;
  13376. _proto.volumeAsPercentage_ = function volumeAsPercentage_() {
  13377. return Math.round(this.player_.volume() * 100);
  13378. }
  13379. /**
  13380. * When user starts dragging the VolumeBar, store the volume and listen for
  13381. * the end of the drag. When the drag ends, if the volume was set to zero,
  13382. * set lastVolume to the stored volume.
  13383. *
  13384. * @listens slideractive
  13385. * @private
  13386. */
  13387. ;
  13388. _proto.updateLastVolume_ = function updateLastVolume_() {
  13389. var _this2 = this;
  13390. var volumeBeforeDrag = this.player_.volume();
  13391. this.one('sliderinactive', function () {
  13392. if (_this2.player_.volume() === 0) {
  13393. _this2.player_.lastVolume_(volumeBeforeDrag);
  13394. }
  13395. });
  13396. };
  13397. return VolumeBar;
  13398. }(Slider);
  13399. /**
  13400. * Default options for the `VolumeBar`
  13401. *
  13402. * @type {Object}
  13403. * @private
  13404. */
  13405. VolumeBar.prototype.options_ = {
  13406. children: ['volumeLevel'],
  13407. barName: 'volumeLevel'
  13408. }; // MouseVolumeLevelDisplay tooltip should not be added to a player on mobile devices
  13409. if (!IS_IOS && !IS_ANDROID) {
  13410. VolumeBar.prototype.options_.children.splice(0, 0, 'mouseVolumeLevelDisplay');
  13411. }
  13412. /**
  13413. * Call the update event for this Slider when this event happens on the player.
  13414. *
  13415. * @type {string}
  13416. */
  13417. VolumeBar.prototype.playerEvent = 'volumechange';
  13418. Component.registerComponent('VolumeBar', VolumeBar);
  13419. /**
  13420. * The component for controlling the volume level
  13421. *
  13422. * @extends Component
  13423. */
  13424. var VolumeControl = /*#__PURE__*/function (_Component) {
  13425. inheritsLoose(VolumeControl, _Component);
  13426. /**
  13427. * Creates an instance of this class.
  13428. *
  13429. * @param {Player} player
  13430. * The `Player` that this class should be attached to.
  13431. *
  13432. * @param {Object} [options={}]
  13433. * The key/value store of player options.
  13434. */
  13435. function VolumeControl(player, options) {
  13436. var _this;
  13437. if (options === void 0) {
  13438. options = {};
  13439. }
  13440. options.vertical = options.vertical || false; // Pass the vertical option down to the VolumeBar if
  13441. // the VolumeBar is turned on.
  13442. if (typeof options.volumeBar === 'undefined' || isPlain(options.volumeBar)) {
  13443. options.volumeBar = options.volumeBar || {};
  13444. options.volumeBar.vertical = options.vertical;
  13445. }
  13446. _this = _Component.call(this, player, options) || this; // hide this control if volume support is missing
  13447. checkVolumeSupport(assertThisInitialized(_this), player);
  13448. _this.throttledHandleMouseMove = throttle(bind(assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  13449. _this.handleMouseUpHandler_ = function (e) {
  13450. return _this.handleMouseUp(e);
  13451. };
  13452. _this.on('mousedown', function (e) {
  13453. return _this.handleMouseDown(e);
  13454. });
  13455. _this.on('touchstart', function (e) {
  13456. return _this.handleMouseDown(e);
  13457. });
  13458. _this.on('mousemove', function (e) {
  13459. return _this.handleMouseMove(e);
  13460. }); // while the slider is active (the mouse has been pressed down and
  13461. // is dragging) or in focus we do not want to hide the VolumeBar
  13462. _this.on(_this.volumeBar, ['focus', 'slideractive'], function () {
  13463. _this.volumeBar.addClass('vjs-slider-active');
  13464. _this.addClass('vjs-slider-active');
  13465. _this.trigger('slideractive');
  13466. });
  13467. _this.on(_this.volumeBar, ['blur', 'sliderinactive'], function () {
  13468. _this.volumeBar.removeClass('vjs-slider-active');
  13469. _this.removeClass('vjs-slider-active');
  13470. _this.trigger('sliderinactive');
  13471. });
  13472. return _this;
  13473. }
  13474. /**
  13475. * Create the `Component`'s DOM element
  13476. *
  13477. * @return {Element}
  13478. * The element that was created.
  13479. */
  13480. var _proto = VolumeControl.prototype;
  13481. _proto.createEl = function createEl() {
  13482. var orientationClass = 'vjs-volume-horizontal';
  13483. if (this.options_.vertical) {
  13484. orientationClass = 'vjs-volume-vertical';
  13485. }
  13486. return _Component.prototype.createEl.call(this, 'div', {
  13487. className: "vjs-volume-control vjs-control " + orientationClass
  13488. });
  13489. }
  13490. /**
  13491. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  13492. *
  13493. * @param {EventTarget~Event} event
  13494. * `mousedown` or `touchstart` event that triggered this function
  13495. *
  13496. * @listens mousedown
  13497. * @listens touchstart
  13498. */
  13499. ;
  13500. _proto.handleMouseDown = function handleMouseDown(event) {
  13501. var doc = this.el_.ownerDocument;
  13502. this.on(doc, 'mousemove', this.throttledHandleMouseMove);
  13503. this.on(doc, 'touchmove', this.throttledHandleMouseMove);
  13504. this.on(doc, 'mouseup', this.handleMouseUpHandler_);
  13505. this.on(doc, 'touchend', this.handleMouseUpHandler_);
  13506. }
  13507. /**
  13508. * Handle `mouseup` or `touchend` events on the `VolumeControl`.
  13509. *
  13510. * @param {EventTarget~Event} event
  13511. * `mouseup` or `touchend` event that triggered this function.
  13512. *
  13513. * @listens touchend
  13514. * @listens mouseup
  13515. */
  13516. ;
  13517. _proto.handleMouseUp = function handleMouseUp(event) {
  13518. var doc = this.el_.ownerDocument;
  13519. this.off(doc, 'mousemove', this.throttledHandleMouseMove);
  13520. this.off(doc, 'touchmove', this.throttledHandleMouseMove);
  13521. this.off(doc, 'mouseup', this.handleMouseUpHandler_);
  13522. this.off(doc, 'touchend', this.handleMouseUpHandler_);
  13523. }
  13524. /**
  13525. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  13526. *
  13527. * @param {EventTarget~Event} event
  13528. * `mousedown` or `touchstart` event that triggered this function
  13529. *
  13530. * @listens mousedown
  13531. * @listens touchstart
  13532. */
  13533. ;
  13534. _proto.handleMouseMove = function handleMouseMove(event) {
  13535. this.volumeBar.handleMouseMove(event);
  13536. };
  13537. return VolumeControl;
  13538. }(Component);
  13539. /**
  13540. * Default options for the `VolumeControl`
  13541. *
  13542. * @type {Object}
  13543. * @private
  13544. */
  13545. VolumeControl.prototype.options_ = {
  13546. children: ['volumeBar']
  13547. };
  13548. Component.registerComponent('VolumeControl', VolumeControl);
  13549. /**
  13550. * Check if muting volume is supported and if it isn't hide the mute toggle
  13551. * button.
  13552. *
  13553. * @param {Component} self
  13554. * A reference to the mute toggle button
  13555. *
  13556. * @param {Player} player
  13557. * A reference to the player
  13558. *
  13559. * @private
  13560. */
  13561. var checkMuteSupport = function checkMuteSupport(self, player) {
  13562. // hide mute toggle button if it's not supported by the current tech
  13563. if (player.tech_ && !player.tech_.featuresMuteControl) {
  13564. self.addClass('vjs-hidden');
  13565. }
  13566. self.on(player, 'loadstart', function () {
  13567. if (!player.tech_.featuresMuteControl) {
  13568. self.addClass('vjs-hidden');
  13569. } else {
  13570. self.removeClass('vjs-hidden');
  13571. }
  13572. });
  13573. };
  13574. /**
  13575. * A button component for muting the audio.
  13576. *
  13577. * @extends Button
  13578. */
  13579. var MuteToggle = /*#__PURE__*/function (_Button) {
  13580. inheritsLoose(MuteToggle, _Button);
  13581. /**
  13582. * Creates an instance of this class.
  13583. *
  13584. * @param {Player} player
  13585. * The `Player` that this class should be attached to.
  13586. *
  13587. * @param {Object} [options]
  13588. * The key/value store of player options.
  13589. */
  13590. function MuteToggle(player, options) {
  13591. var _this;
  13592. _this = _Button.call(this, player, options) || this; // hide this control if volume support is missing
  13593. checkMuteSupport(assertThisInitialized(_this), player);
  13594. _this.on(player, ['loadstart', 'volumechange'], function (e) {
  13595. return _this.update(e);
  13596. });
  13597. return _this;
  13598. }
  13599. /**
  13600. * Builds the default DOM `className`.
  13601. *
  13602. * @return {string}
  13603. * The DOM `className` for this object.
  13604. */
  13605. var _proto = MuteToggle.prototype;
  13606. _proto.buildCSSClass = function buildCSSClass() {
  13607. return "vjs-mute-control " + _Button.prototype.buildCSSClass.call(this);
  13608. }
  13609. /**
  13610. * This gets called when an `MuteToggle` is "clicked". See
  13611. * {@link ClickableComponent} for more detailed information on what a click can be.
  13612. *
  13613. * @param {EventTarget~Event} [event]
  13614. * The `keydown`, `tap`, or `click` event that caused this function to be
  13615. * called.
  13616. *
  13617. * @listens tap
  13618. * @listens click
  13619. */
  13620. ;
  13621. _proto.handleClick = function handleClick(event) {
  13622. var vol = this.player_.volume();
  13623. var lastVolume = this.player_.lastVolume_();
  13624. if (vol === 0) {
  13625. var volumeToSet = lastVolume < 0.1 ? 0.1 : lastVolume;
  13626. this.player_.volume(volumeToSet);
  13627. this.player_.muted(false);
  13628. } else {
  13629. this.player_.muted(this.player_.muted() ? false : true);
  13630. }
  13631. }
  13632. /**
  13633. * Update the `MuteToggle` button based on the state of `volume` and `muted`
  13634. * on the player.
  13635. *
  13636. * @param {EventTarget~Event} [event]
  13637. * The {@link Player#loadstart} event if this function was called
  13638. * through an event.
  13639. *
  13640. * @listens Player#loadstart
  13641. * @listens Player#volumechange
  13642. */
  13643. ;
  13644. _proto.update = function update(event) {
  13645. this.updateIcon_();
  13646. this.updateControlText_();
  13647. }
  13648. /**
  13649. * Update the appearance of the `MuteToggle` icon.
  13650. *
  13651. * Possible states (given `level` variable below):
  13652. * - 0: crossed out
  13653. * - 1: zero bars of volume
  13654. * - 2: one bar of volume
  13655. * - 3: two bars of volume
  13656. *
  13657. * @private
  13658. */
  13659. ;
  13660. _proto.updateIcon_ = function updateIcon_() {
  13661. var vol = this.player_.volume();
  13662. var level = 3; // in iOS when a player is loaded with muted attribute
  13663. // and volume is changed with a native mute button
  13664. // we want to make sure muted state is updated
  13665. if (IS_IOS && this.player_.tech_ && this.player_.tech_.el_) {
  13666. this.player_.muted(this.player_.tech_.el_.muted);
  13667. }
  13668. if (vol === 0 || this.player_.muted()) {
  13669. level = 0;
  13670. } else if (vol < 0.33) {
  13671. level = 1;
  13672. } else if (vol < 0.67) {
  13673. level = 2;
  13674. } // TODO improve muted icon classes
  13675. for (var i = 0; i < 4; i++) {
  13676. removeClass(this.el_, "vjs-vol-" + i);
  13677. }
  13678. addClass(this.el_, "vjs-vol-" + level);
  13679. }
  13680. /**
  13681. * If `muted` has changed on the player, update the control text
  13682. * (`title` attribute on `vjs-mute-control` element and content of
  13683. * `vjs-control-text` element).
  13684. *
  13685. * @private
  13686. */
  13687. ;
  13688. _proto.updateControlText_ = function updateControlText_() {
  13689. var soundOff = this.player_.muted() || this.player_.volume() === 0;
  13690. var text = soundOff ? 'Unmute' : 'Mute';
  13691. if (this.controlText() !== text) {
  13692. this.controlText(text);
  13693. }
  13694. };
  13695. return MuteToggle;
  13696. }(Button);
  13697. /**
  13698. * The text that should display over the `MuteToggle`s controls. Added for localization.
  13699. *
  13700. * @type {string}
  13701. * @private
  13702. */
  13703. MuteToggle.prototype.controlText_ = 'Mute';
  13704. Component.registerComponent('MuteToggle', MuteToggle);
  13705. /**
  13706. * A Component to contain the MuteToggle and VolumeControl so that
  13707. * they can work together.
  13708. *
  13709. * @extends Component
  13710. */
  13711. var VolumePanel = /*#__PURE__*/function (_Component) {
  13712. inheritsLoose(VolumePanel, _Component);
  13713. /**
  13714. * Creates an instance of this class.
  13715. *
  13716. * @param {Player} player
  13717. * The `Player` that this class should be attached to.
  13718. *
  13719. * @param {Object} [options={}]
  13720. * The key/value store of player options.
  13721. */
  13722. function VolumePanel(player, options) {
  13723. var _this;
  13724. if (options === void 0) {
  13725. options = {};
  13726. }
  13727. if (typeof options.inline !== 'undefined') {
  13728. options.inline = options.inline;
  13729. } else {
  13730. options.inline = true;
  13731. } // pass the inline option down to the VolumeControl as vertical if
  13732. // the VolumeControl is on.
  13733. if (typeof options.volumeControl === 'undefined' || isPlain(options.volumeControl)) {
  13734. options.volumeControl = options.volumeControl || {};
  13735. options.volumeControl.vertical = !options.inline;
  13736. }
  13737. _this = _Component.call(this, player, options) || this; // this handler is used by mouse handler methods below
  13738. _this.handleKeyPressHandler_ = function (e) {
  13739. return _this.handleKeyPress(e);
  13740. };
  13741. _this.on(player, ['loadstart'], function (e) {
  13742. return _this.volumePanelState_(e);
  13743. });
  13744. _this.on(_this.muteToggle, 'keyup', function (e) {
  13745. return _this.handleKeyPress(e);
  13746. });
  13747. _this.on(_this.volumeControl, 'keyup', function (e) {
  13748. return _this.handleVolumeControlKeyUp(e);
  13749. });
  13750. _this.on('keydown', function (e) {
  13751. return _this.handleKeyPress(e);
  13752. });
  13753. _this.on('mouseover', function (e) {
  13754. return _this.handleMouseOver(e);
  13755. });
  13756. _this.on('mouseout', function (e) {
  13757. return _this.handleMouseOut(e);
  13758. }); // while the slider is active (the mouse has been pressed down and
  13759. // is dragging) we do not want to hide the VolumeBar
  13760. _this.on(_this.volumeControl, ['slideractive'], _this.sliderActive_);
  13761. _this.on(_this.volumeControl, ['sliderinactive'], _this.sliderInactive_);
  13762. return _this;
  13763. }
  13764. /**
  13765. * Add vjs-slider-active class to the VolumePanel
  13766. *
  13767. * @listens VolumeControl#slideractive
  13768. * @private
  13769. */
  13770. var _proto = VolumePanel.prototype;
  13771. _proto.sliderActive_ = function sliderActive_() {
  13772. this.addClass('vjs-slider-active');
  13773. }
  13774. /**
  13775. * Removes vjs-slider-active class to the VolumePanel
  13776. *
  13777. * @listens VolumeControl#sliderinactive
  13778. * @private
  13779. */
  13780. ;
  13781. _proto.sliderInactive_ = function sliderInactive_() {
  13782. this.removeClass('vjs-slider-active');
  13783. }
  13784. /**
  13785. * Adds vjs-hidden or vjs-mute-toggle-only to the VolumePanel
  13786. * depending on MuteToggle and VolumeControl state
  13787. *
  13788. * @listens Player#loadstart
  13789. * @private
  13790. */
  13791. ;
  13792. _proto.volumePanelState_ = function volumePanelState_() {
  13793. // hide volume panel if neither volume control or mute toggle
  13794. // are displayed
  13795. if (this.volumeControl.hasClass('vjs-hidden') && this.muteToggle.hasClass('vjs-hidden')) {
  13796. this.addClass('vjs-hidden');
  13797. } // if only mute toggle is visible we don't want
  13798. // volume panel expanding when hovered or active
  13799. if (this.volumeControl.hasClass('vjs-hidden') && !this.muteToggle.hasClass('vjs-hidden')) {
  13800. this.addClass('vjs-mute-toggle-only');
  13801. }
  13802. }
  13803. /**
  13804. * Create the `Component`'s DOM element
  13805. *
  13806. * @return {Element}
  13807. * The element that was created.
  13808. */
  13809. ;
  13810. _proto.createEl = function createEl() {
  13811. var orientationClass = 'vjs-volume-panel-horizontal';
  13812. if (!this.options_.inline) {
  13813. orientationClass = 'vjs-volume-panel-vertical';
  13814. }
  13815. return _Component.prototype.createEl.call(this, 'div', {
  13816. className: "vjs-volume-panel vjs-control " + orientationClass
  13817. });
  13818. }
  13819. /**
  13820. * Dispose of the `volume-panel` and all child components.
  13821. */
  13822. ;
  13823. _proto.dispose = function dispose() {
  13824. this.handleMouseOut();
  13825. _Component.prototype.dispose.call(this);
  13826. }
  13827. /**
  13828. * Handles `keyup` events on the `VolumeControl`, looking for ESC, which closes
  13829. * the volume panel and sets focus on `MuteToggle`.
  13830. *
  13831. * @param {EventTarget~Event} event
  13832. * The `keyup` event that caused this function to be called.
  13833. *
  13834. * @listens keyup
  13835. */
  13836. ;
  13837. _proto.handleVolumeControlKeyUp = function handleVolumeControlKeyUp(event) {
  13838. if (keycode.isEventKey(event, 'Esc')) {
  13839. this.muteToggle.focus();
  13840. }
  13841. }
  13842. /**
  13843. * This gets called when a `VolumePanel` gains hover via a `mouseover` event.
  13844. * Turns on listening for `mouseover` event. When they happen it
  13845. * calls `this.handleMouseOver`.
  13846. *
  13847. * @param {EventTarget~Event} event
  13848. * The `mouseover` event that caused this function to be called.
  13849. *
  13850. * @listens mouseover
  13851. */
  13852. ;
  13853. _proto.handleMouseOver = function handleMouseOver(event) {
  13854. this.addClass('vjs-hover');
  13855. on(document, 'keyup', this.handleKeyPressHandler_);
  13856. }
  13857. /**
  13858. * This gets called when a `VolumePanel` gains hover via a `mouseout` event.
  13859. * Turns on listening for `mouseout` event. When they happen it
  13860. * calls `this.handleMouseOut`.
  13861. *
  13862. * @param {EventTarget~Event} event
  13863. * The `mouseout` event that caused this function to be called.
  13864. *
  13865. * @listens mouseout
  13866. */
  13867. ;
  13868. _proto.handleMouseOut = function handleMouseOut(event) {
  13869. this.removeClass('vjs-hover');
  13870. off(document, 'keyup', this.handleKeyPressHandler_);
  13871. }
  13872. /**
  13873. * Handles `keyup` event on the document or `keydown` event on the `VolumePanel`,
  13874. * looking for ESC, which hides the `VolumeControl`.
  13875. *
  13876. * @param {EventTarget~Event} event
  13877. * The keypress that triggered this event.
  13878. *
  13879. * @listens keydown | keyup
  13880. */
  13881. ;
  13882. _proto.handleKeyPress = function handleKeyPress(event) {
  13883. if (keycode.isEventKey(event, 'Esc')) {
  13884. this.handleMouseOut();
  13885. }
  13886. };
  13887. return VolumePanel;
  13888. }(Component);
  13889. /**
  13890. * Default options for the `VolumeControl`
  13891. *
  13892. * @type {Object}
  13893. * @private
  13894. */
  13895. VolumePanel.prototype.options_ = {
  13896. children: ['muteToggle', 'volumeControl']
  13897. };
  13898. Component.registerComponent('VolumePanel', VolumePanel);
  13899. /**
  13900. * The Menu component is used to build popup menus, including subtitle and
  13901. * captions selection menus.
  13902. *
  13903. * @extends Component
  13904. */
  13905. var Menu = /*#__PURE__*/function (_Component) {
  13906. inheritsLoose(Menu, _Component);
  13907. /**
  13908. * Create an instance of this class.
  13909. *
  13910. * @param {Player} player
  13911. * the player that this component should attach to
  13912. *
  13913. * @param {Object} [options]
  13914. * Object of option names and values
  13915. *
  13916. */
  13917. function Menu(player, options) {
  13918. var _this;
  13919. _this = _Component.call(this, player, options) || this;
  13920. if (options) {
  13921. _this.menuButton_ = options.menuButton;
  13922. }
  13923. _this.focusedChild_ = -1;
  13924. _this.on('keydown', function (e) {
  13925. return _this.handleKeyDown(e);
  13926. }); // All the menu item instances share the same blur handler provided by the menu container.
  13927. _this.boundHandleBlur_ = function (e) {
  13928. return _this.handleBlur(e);
  13929. };
  13930. _this.boundHandleTapClick_ = function (e) {
  13931. return _this.handleTapClick(e);
  13932. };
  13933. return _this;
  13934. }
  13935. /**
  13936. * Add event listeners to the {@link MenuItem}.
  13937. *
  13938. * @param {Object} component
  13939. * The instance of the `MenuItem` to add listeners to.
  13940. *
  13941. */
  13942. var _proto = Menu.prototype;
  13943. _proto.addEventListenerForItem = function addEventListenerForItem(component) {
  13944. if (!(component instanceof Component)) {
  13945. return;
  13946. }
  13947. this.on(component, 'blur', this.boundHandleBlur_);
  13948. this.on(component, ['tap', 'click'], this.boundHandleTapClick_);
  13949. }
  13950. /**
  13951. * Remove event listeners from the {@link MenuItem}.
  13952. *
  13953. * @param {Object} component
  13954. * The instance of the `MenuItem` to remove listeners.
  13955. *
  13956. */
  13957. ;
  13958. _proto.removeEventListenerForItem = function removeEventListenerForItem(component) {
  13959. if (!(component instanceof Component)) {
  13960. return;
  13961. }
  13962. this.off(component, 'blur', this.boundHandleBlur_);
  13963. this.off(component, ['tap', 'click'], this.boundHandleTapClick_);
  13964. }
  13965. /**
  13966. * This method will be called indirectly when the component has been added
  13967. * before the component adds to the new menu instance by `addItem`.
  13968. * In this case, the original menu instance will remove the component
  13969. * by calling `removeChild`.
  13970. *
  13971. * @param {Object} component
  13972. * The instance of the `MenuItem`
  13973. */
  13974. ;
  13975. _proto.removeChild = function removeChild(component) {
  13976. if (typeof component === 'string') {
  13977. component = this.getChild(component);
  13978. }
  13979. this.removeEventListenerForItem(component);
  13980. _Component.prototype.removeChild.call(this, component);
  13981. }
  13982. /**
  13983. * Add a {@link MenuItem} to the menu.
  13984. *
  13985. * @param {Object|string} component
  13986. * The name or instance of the `MenuItem` to add.
  13987. *
  13988. */
  13989. ;
  13990. _proto.addItem = function addItem(component) {
  13991. var childComponent = this.addChild(component);
  13992. if (childComponent) {
  13993. this.addEventListenerForItem(childComponent);
  13994. }
  13995. }
  13996. /**
  13997. * Create the `Menu`s DOM element.
  13998. *
  13999. * @return {Element}
  14000. * the element that was created
  14001. */
  14002. ;
  14003. _proto.createEl = function createEl$1() {
  14004. var contentElType = this.options_.contentElType || 'ul';
  14005. this.contentEl_ = createEl(contentElType, {
  14006. className: 'vjs-menu-content'
  14007. });
  14008. this.contentEl_.setAttribute('role', 'menu');
  14009. var el = _Component.prototype.createEl.call(this, 'div', {
  14010. append: this.contentEl_,
  14011. className: 'vjs-menu'
  14012. });
  14013. el.appendChild(this.contentEl_); // Prevent clicks from bubbling up. Needed for Menu Buttons,
  14014. // where a click on the parent is significant
  14015. on(el, 'click', function (event) {
  14016. event.preventDefault();
  14017. event.stopImmediatePropagation();
  14018. });
  14019. return el;
  14020. };
  14021. _proto.dispose = function dispose() {
  14022. this.contentEl_ = null;
  14023. this.boundHandleBlur_ = null;
  14024. this.boundHandleTapClick_ = null;
  14025. _Component.prototype.dispose.call(this);
  14026. }
  14027. /**
  14028. * Called when a `MenuItem` loses focus.
  14029. *
  14030. * @param {EventTarget~Event} event
  14031. * The `blur` event that caused this function to be called.
  14032. *
  14033. * @listens blur
  14034. */
  14035. ;
  14036. _proto.handleBlur = function handleBlur(event) {
  14037. var relatedTarget = event.relatedTarget || document.activeElement; // Close menu popup when a user clicks outside the menu
  14038. if (!this.children().some(function (element) {
  14039. return element.el() === relatedTarget;
  14040. })) {
  14041. var btn = this.menuButton_;
  14042. if (btn && btn.buttonPressed_ && relatedTarget !== btn.el().firstChild) {
  14043. btn.unpressButton();
  14044. }
  14045. }
  14046. }
  14047. /**
  14048. * Called when a `MenuItem` gets clicked or tapped.
  14049. *
  14050. * @param {EventTarget~Event} event
  14051. * The `click` or `tap` event that caused this function to be called.
  14052. *
  14053. * @listens click,tap
  14054. */
  14055. ;
  14056. _proto.handleTapClick = function handleTapClick(event) {
  14057. // Unpress the associated MenuButton, and move focus back to it
  14058. if (this.menuButton_) {
  14059. this.menuButton_.unpressButton();
  14060. var childComponents = this.children();
  14061. if (!Array.isArray(childComponents)) {
  14062. return;
  14063. }
  14064. var foundComponent = childComponents.filter(function (component) {
  14065. return component.el() === event.target;
  14066. })[0];
  14067. if (!foundComponent) {
  14068. return;
  14069. } // don't focus menu button if item is a caption settings item
  14070. // because focus will move elsewhere
  14071. if (foundComponent.name() !== 'CaptionSettingsMenuItem') {
  14072. this.menuButton_.focus();
  14073. }
  14074. }
  14075. }
  14076. /**
  14077. * Handle a `keydown` event on this menu. This listener is added in the constructor.
  14078. *
  14079. * @param {EventTarget~Event} event
  14080. * A `keydown` event that happened on the menu.
  14081. *
  14082. * @listens keydown
  14083. */
  14084. ;
  14085. _proto.handleKeyDown = function handleKeyDown(event) {
  14086. // Left and Down Arrows
  14087. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  14088. event.preventDefault();
  14089. event.stopPropagation();
  14090. this.stepForward(); // Up and Right Arrows
  14091. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  14092. event.preventDefault();
  14093. event.stopPropagation();
  14094. this.stepBack();
  14095. }
  14096. }
  14097. /**
  14098. * Move to next (lower) menu item for keyboard users.
  14099. */
  14100. ;
  14101. _proto.stepForward = function stepForward() {
  14102. var stepChild = 0;
  14103. if (this.focusedChild_ !== undefined) {
  14104. stepChild = this.focusedChild_ + 1;
  14105. }
  14106. this.focus(stepChild);
  14107. }
  14108. /**
  14109. * Move to previous (higher) menu item for keyboard users.
  14110. */
  14111. ;
  14112. _proto.stepBack = function stepBack() {
  14113. var stepChild = 0;
  14114. if (this.focusedChild_ !== undefined) {
  14115. stepChild = this.focusedChild_ - 1;
  14116. }
  14117. this.focus(stepChild);
  14118. }
  14119. /**
  14120. * Set focus on a {@link MenuItem} in the `Menu`.
  14121. *
  14122. * @param {Object|string} [item=0]
  14123. * Index of child item set focus on.
  14124. */
  14125. ;
  14126. _proto.focus = function focus(item) {
  14127. if (item === void 0) {
  14128. item = 0;
  14129. }
  14130. var children = this.children().slice();
  14131. var haveTitle = children.length && children[0].hasClass('vjs-menu-title');
  14132. if (haveTitle) {
  14133. children.shift();
  14134. }
  14135. if (children.length > 0) {
  14136. if (item < 0) {
  14137. item = 0;
  14138. } else if (item >= children.length) {
  14139. item = children.length - 1;
  14140. }
  14141. this.focusedChild_ = item;
  14142. children[item].el_.focus();
  14143. }
  14144. };
  14145. return Menu;
  14146. }(Component);
  14147. Component.registerComponent('Menu', Menu);
  14148. /**
  14149. * A `MenuButton` class for any popup {@link Menu}.
  14150. *
  14151. * @extends Component
  14152. */
  14153. var MenuButton = /*#__PURE__*/function (_Component) {
  14154. inheritsLoose(MenuButton, _Component);
  14155. /**
  14156. * Creates an instance of this class.
  14157. *
  14158. * @param {Player} player
  14159. * The `Player` that this class should be attached to.
  14160. *
  14161. * @param {Object} [options={}]
  14162. * The key/value store of player options.
  14163. */
  14164. function MenuButton(player, options) {
  14165. var _this;
  14166. if (options === void 0) {
  14167. options = {};
  14168. }
  14169. _this = _Component.call(this, player, options) || this;
  14170. _this.menuButton_ = new Button(player, options);
  14171. _this.menuButton_.controlText(_this.controlText_);
  14172. _this.menuButton_.el_.setAttribute('aria-haspopup', 'true'); // Add buildCSSClass values to the button, not the wrapper
  14173. var buttonClass = Button.prototype.buildCSSClass();
  14174. _this.menuButton_.el_.className = _this.buildCSSClass() + ' ' + buttonClass;
  14175. _this.menuButton_.removeClass('vjs-control');
  14176. _this.addChild(_this.menuButton_);
  14177. _this.update();
  14178. _this.enabled_ = true;
  14179. var handleClick = function handleClick(e) {
  14180. return _this.handleClick(e);
  14181. };
  14182. _this.handleMenuKeyUp_ = function (e) {
  14183. return _this.handleMenuKeyUp(e);
  14184. };
  14185. _this.on(_this.menuButton_, 'tap', handleClick);
  14186. _this.on(_this.menuButton_, 'click', handleClick);
  14187. _this.on(_this.menuButton_, 'keydown', function (e) {
  14188. return _this.handleKeyDown(e);
  14189. });
  14190. _this.on(_this.menuButton_, 'mouseenter', function () {
  14191. _this.addClass('vjs-hover');
  14192. _this.menu.show();
  14193. on(document, 'keyup', _this.handleMenuKeyUp_);
  14194. });
  14195. _this.on('mouseleave', function (e) {
  14196. return _this.handleMouseLeave(e);
  14197. });
  14198. _this.on('keydown', function (e) {
  14199. return _this.handleSubmenuKeyDown(e);
  14200. });
  14201. return _this;
  14202. }
  14203. /**
  14204. * Update the menu based on the current state of its items.
  14205. */
  14206. var _proto = MenuButton.prototype;
  14207. _proto.update = function update() {
  14208. var menu = this.createMenu();
  14209. if (this.menu) {
  14210. this.menu.dispose();
  14211. this.removeChild(this.menu);
  14212. }
  14213. this.menu = menu;
  14214. this.addChild(menu);
  14215. /**
  14216. * Track the state of the menu button
  14217. *
  14218. * @type {Boolean}
  14219. * @private
  14220. */
  14221. this.buttonPressed_ = false;
  14222. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  14223. if (this.items && this.items.length <= this.hideThreshold_) {
  14224. this.hide();
  14225. this.menu.contentEl_.removeAttribute('role');
  14226. } else {
  14227. this.show();
  14228. this.menu.contentEl_.setAttribute('role', 'menu');
  14229. }
  14230. }
  14231. /**
  14232. * Create the menu and add all items to it.
  14233. *
  14234. * @return {Menu}
  14235. * The constructed menu
  14236. */
  14237. ;
  14238. _proto.createMenu = function createMenu() {
  14239. var menu = new Menu(this.player_, {
  14240. menuButton: this
  14241. });
  14242. /**
  14243. * Hide the menu if the number of items is less than or equal to this threshold. This defaults
  14244. * to 0 and whenever we add items which can be hidden to the menu we'll increment it. We list
  14245. * it here because every time we run `createMenu` we need to reset the value.
  14246. *
  14247. * @protected
  14248. * @type {Number}
  14249. */
  14250. this.hideThreshold_ = 0; // Add a title list item to the top
  14251. if (this.options_.title) {
  14252. var titleEl = createEl('li', {
  14253. className: 'vjs-menu-title',
  14254. textContent: toTitleCase(this.options_.title),
  14255. tabIndex: -1
  14256. });
  14257. var titleComponent = new Component(this.player_, {
  14258. el: titleEl
  14259. });
  14260. menu.addItem(titleComponent);
  14261. }
  14262. this.items = this.createItems();
  14263. if (this.items) {
  14264. // Add menu items to the menu
  14265. for (var i = 0; i < this.items.length; i++) {
  14266. menu.addItem(this.items[i]);
  14267. }
  14268. }
  14269. return menu;
  14270. }
  14271. /**
  14272. * Create the list of menu items. Specific to each subclass.
  14273. *
  14274. * @abstract
  14275. */
  14276. ;
  14277. _proto.createItems = function createItems() {}
  14278. /**
  14279. * Create the `MenuButtons`s DOM element.
  14280. *
  14281. * @return {Element}
  14282. * The element that gets created.
  14283. */
  14284. ;
  14285. _proto.createEl = function createEl() {
  14286. return _Component.prototype.createEl.call(this, 'div', {
  14287. className: this.buildWrapperCSSClass()
  14288. }, {});
  14289. }
  14290. /**
  14291. * Allow sub components to stack CSS class names for the wrapper element
  14292. *
  14293. * @return {string}
  14294. * The constructed wrapper DOM `className`
  14295. */
  14296. ;
  14297. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  14298. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  14299. if (this.options_.inline === true) {
  14300. menuButtonClass += '-inline';
  14301. } else {
  14302. menuButtonClass += '-popup';
  14303. } // TODO: Fix the CSS so that this isn't necessary
  14304. var buttonClass = Button.prototype.buildCSSClass();
  14305. return "vjs-menu-button " + menuButtonClass + " " + buttonClass + " " + _Component.prototype.buildCSSClass.call(this);
  14306. }
  14307. /**
  14308. * Builds the default DOM `className`.
  14309. *
  14310. * @return {string}
  14311. * The DOM `className` for this object.
  14312. */
  14313. ;
  14314. _proto.buildCSSClass = function buildCSSClass() {
  14315. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  14316. if (this.options_.inline === true) {
  14317. menuButtonClass += '-inline';
  14318. } else {
  14319. menuButtonClass += '-popup';
  14320. }
  14321. return "vjs-menu-button " + menuButtonClass + " " + _Component.prototype.buildCSSClass.call(this);
  14322. }
  14323. /**
  14324. * Get or set the localized control text that will be used for accessibility.
  14325. *
  14326. * > NOTE: This will come from the internal `menuButton_` element.
  14327. *
  14328. * @param {string} [text]
  14329. * Control text for element.
  14330. *
  14331. * @param {Element} [el=this.menuButton_.el()]
  14332. * Element to set the title on.
  14333. *
  14334. * @return {string}
  14335. * - The control text when getting
  14336. */
  14337. ;
  14338. _proto.controlText = function controlText(text, el) {
  14339. if (el === void 0) {
  14340. el = this.menuButton_.el();
  14341. }
  14342. return this.menuButton_.controlText(text, el);
  14343. }
  14344. /**
  14345. * Dispose of the `menu-button` and all child components.
  14346. */
  14347. ;
  14348. _proto.dispose = function dispose() {
  14349. this.handleMouseLeave();
  14350. _Component.prototype.dispose.call(this);
  14351. }
  14352. /**
  14353. * Handle a click on a `MenuButton`.
  14354. * See {@link ClickableComponent#handleClick} for instances where this is called.
  14355. *
  14356. * @param {EventTarget~Event} event
  14357. * The `keydown`, `tap`, or `click` event that caused this function to be
  14358. * called.
  14359. *
  14360. * @listens tap
  14361. * @listens click
  14362. */
  14363. ;
  14364. _proto.handleClick = function handleClick(event) {
  14365. if (this.buttonPressed_) {
  14366. this.unpressButton();
  14367. } else {
  14368. this.pressButton();
  14369. }
  14370. }
  14371. /**
  14372. * Handle `mouseleave` for `MenuButton`.
  14373. *
  14374. * @param {EventTarget~Event} event
  14375. * The `mouseleave` event that caused this function to be called.
  14376. *
  14377. * @listens mouseleave
  14378. */
  14379. ;
  14380. _proto.handleMouseLeave = function handleMouseLeave(event) {
  14381. this.removeClass('vjs-hover');
  14382. off(document, 'keyup', this.handleMenuKeyUp_);
  14383. }
  14384. /**
  14385. * Set the focus to the actual button, not to this element
  14386. */
  14387. ;
  14388. _proto.focus = function focus() {
  14389. this.menuButton_.focus();
  14390. }
  14391. /**
  14392. * Remove the focus from the actual button, not this element
  14393. */
  14394. ;
  14395. _proto.blur = function blur() {
  14396. this.menuButton_.blur();
  14397. }
  14398. /**
  14399. * Handle tab, escape, down arrow, and up arrow keys for `MenuButton`. See
  14400. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  14401. *
  14402. * @param {EventTarget~Event} event
  14403. * The `keydown` event that caused this function to be called.
  14404. *
  14405. * @listens keydown
  14406. */
  14407. ;
  14408. _proto.handleKeyDown = function handleKeyDown(event) {
  14409. // Escape or Tab unpress the 'button'
  14410. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  14411. if (this.buttonPressed_) {
  14412. this.unpressButton();
  14413. } // Don't preventDefault for Tab key - we still want to lose focus
  14414. if (!keycode.isEventKey(event, 'Tab')) {
  14415. event.preventDefault(); // Set focus back to the menu button's button
  14416. this.menuButton_.focus();
  14417. } // Up Arrow or Down Arrow also 'press' the button to open the menu
  14418. } else if (keycode.isEventKey(event, 'Up') || keycode.isEventKey(event, 'Down')) {
  14419. if (!this.buttonPressed_) {
  14420. event.preventDefault();
  14421. this.pressButton();
  14422. }
  14423. }
  14424. }
  14425. /**
  14426. * Handle a `keyup` event on a `MenuButton`. The listener for this is added in
  14427. * the constructor.
  14428. *
  14429. * @param {EventTarget~Event} event
  14430. * Key press event
  14431. *
  14432. * @listens keyup
  14433. */
  14434. ;
  14435. _proto.handleMenuKeyUp = function handleMenuKeyUp(event) {
  14436. // Escape hides popup menu
  14437. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  14438. this.removeClass('vjs-hover');
  14439. }
  14440. }
  14441. /**
  14442. * This method name now delegates to `handleSubmenuKeyDown`. This means
  14443. * anyone calling `handleSubmenuKeyPress` will not see their method calls
  14444. * stop working.
  14445. *
  14446. * @param {EventTarget~Event} event
  14447. * The event that caused this function to be called.
  14448. */
  14449. ;
  14450. _proto.handleSubmenuKeyPress = function handleSubmenuKeyPress(event) {
  14451. this.handleSubmenuKeyDown(event);
  14452. }
  14453. /**
  14454. * Handle a `keydown` event on a sub-menu. The listener for this is added in
  14455. * the constructor.
  14456. *
  14457. * @param {EventTarget~Event} event
  14458. * Key press event
  14459. *
  14460. * @listens keydown
  14461. */
  14462. ;
  14463. _proto.handleSubmenuKeyDown = function handleSubmenuKeyDown(event) {
  14464. // Escape or Tab unpress the 'button'
  14465. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  14466. if (this.buttonPressed_) {
  14467. this.unpressButton();
  14468. } // Don't preventDefault for Tab key - we still want to lose focus
  14469. if (!keycode.isEventKey(event, 'Tab')) {
  14470. event.preventDefault(); // Set focus back to the menu button's button
  14471. this.menuButton_.focus();
  14472. }
  14473. }
  14474. }
  14475. /**
  14476. * Put the current `MenuButton` into a pressed state.
  14477. */
  14478. ;
  14479. _proto.pressButton = function pressButton() {
  14480. if (this.enabled_) {
  14481. this.buttonPressed_ = true;
  14482. this.menu.show();
  14483. this.menu.lockShowing();
  14484. this.menuButton_.el_.setAttribute('aria-expanded', 'true'); // set the focus into the submenu, except on iOS where it is resulting in
  14485. // undesired scrolling behavior when the player is in an iframe
  14486. if (IS_IOS && isInFrame()) {
  14487. // Return early so that the menu isn't focused
  14488. return;
  14489. }
  14490. this.menu.focus();
  14491. }
  14492. }
  14493. /**
  14494. * Take the current `MenuButton` out of a pressed state.
  14495. */
  14496. ;
  14497. _proto.unpressButton = function unpressButton() {
  14498. if (this.enabled_) {
  14499. this.buttonPressed_ = false;
  14500. this.menu.unlockShowing();
  14501. this.menu.hide();
  14502. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  14503. }
  14504. }
  14505. /**
  14506. * Disable the `MenuButton`. Don't allow it to be clicked.
  14507. */
  14508. ;
  14509. _proto.disable = function disable() {
  14510. this.unpressButton();
  14511. this.enabled_ = false;
  14512. this.addClass('vjs-disabled');
  14513. this.menuButton_.disable();
  14514. }
  14515. /**
  14516. * Enable the `MenuButton`. Allow it to be clicked.
  14517. */
  14518. ;
  14519. _proto.enable = function enable() {
  14520. this.enabled_ = true;
  14521. this.removeClass('vjs-disabled');
  14522. this.menuButton_.enable();
  14523. };
  14524. return MenuButton;
  14525. }(Component);
  14526. Component.registerComponent('MenuButton', MenuButton);
  14527. /**
  14528. * The base class for buttons that toggle specific track types (e.g. subtitles).
  14529. *
  14530. * @extends MenuButton
  14531. */
  14532. var TrackButton = /*#__PURE__*/function (_MenuButton) {
  14533. inheritsLoose(TrackButton, _MenuButton);
  14534. /**
  14535. * Creates an instance of this class.
  14536. *
  14537. * @param {Player} player
  14538. * The `Player` that this class should be attached to.
  14539. *
  14540. * @param {Object} [options]
  14541. * The key/value store of player options.
  14542. */
  14543. function TrackButton(player, options) {
  14544. var _this;
  14545. var tracks = options.tracks;
  14546. _this = _MenuButton.call(this, player, options) || this;
  14547. if (_this.items.length <= 1) {
  14548. _this.hide();
  14549. }
  14550. if (!tracks) {
  14551. return assertThisInitialized(_this);
  14552. }
  14553. var updateHandler = bind(assertThisInitialized(_this), _this.update);
  14554. tracks.addEventListener('removetrack', updateHandler);
  14555. tracks.addEventListener('addtrack', updateHandler);
  14556. tracks.addEventListener('labelchange', updateHandler);
  14557. _this.player_.on('ready', updateHandler);
  14558. _this.player_.on('dispose', function () {
  14559. tracks.removeEventListener('removetrack', updateHandler);
  14560. tracks.removeEventListener('addtrack', updateHandler);
  14561. tracks.removeEventListener('labelchange', updateHandler);
  14562. });
  14563. return _this;
  14564. }
  14565. return TrackButton;
  14566. }(MenuButton);
  14567. Component.registerComponent('TrackButton', TrackButton);
  14568. /**
  14569. * @file menu-keys.js
  14570. */
  14571. /**
  14572. * All keys used for operation of a menu (`MenuButton`, `Menu`, and `MenuItem`)
  14573. * Note that 'Enter' and 'Space' are not included here (otherwise they would
  14574. * prevent the `MenuButton` and `MenuItem` from being keyboard-clickable)
  14575. * @typedef MenuKeys
  14576. * @array
  14577. */
  14578. var MenuKeys = ['Tab', 'Esc', 'Up', 'Down', 'Right', 'Left'];
  14579. /**
  14580. * The component for a menu item. `<li>`
  14581. *
  14582. * @extends ClickableComponent
  14583. */
  14584. var MenuItem = /*#__PURE__*/function (_ClickableComponent) {
  14585. inheritsLoose(MenuItem, _ClickableComponent);
  14586. /**
  14587. * Creates an instance of the this class.
  14588. *
  14589. * @param {Player} player
  14590. * The `Player` that this class should be attached to.
  14591. *
  14592. * @param {Object} [options={}]
  14593. * The key/value store of player options.
  14594. *
  14595. */
  14596. function MenuItem(player, options) {
  14597. var _this;
  14598. _this = _ClickableComponent.call(this, player, options) || this;
  14599. _this.selectable = options.selectable;
  14600. _this.isSelected_ = options.selected || false;
  14601. _this.multiSelectable = options.multiSelectable;
  14602. _this.selected(_this.isSelected_);
  14603. if (_this.selectable) {
  14604. if (_this.multiSelectable) {
  14605. _this.el_.setAttribute('role', 'menuitemcheckbox');
  14606. } else {
  14607. _this.el_.setAttribute('role', 'menuitemradio');
  14608. }
  14609. } else {
  14610. _this.el_.setAttribute('role', 'menuitem');
  14611. }
  14612. return _this;
  14613. }
  14614. /**
  14615. * Create the `MenuItem's DOM element
  14616. *
  14617. * @param {string} [type=li]
  14618. * Element's node type, not actually used, always set to `li`.
  14619. *
  14620. * @param {Object} [props={}]
  14621. * An object of properties that should be set on the element
  14622. *
  14623. * @param {Object} [attrs={}]
  14624. * An object of attributes that should be set on the element
  14625. *
  14626. * @return {Element}
  14627. * The element that gets created.
  14628. */
  14629. var _proto = MenuItem.prototype;
  14630. _proto.createEl = function createEl$1(type, props, attrs) {
  14631. // The control is textual, not just an icon
  14632. this.nonIconControl = true;
  14633. var el = _ClickableComponent.prototype.createEl.call(this, 'li', assign({
  14634. className: 'vjs-menu-item',
  14635. tabIndex: -1
  14636. }, props), attrs); // swap icon with menu item text.
  14637. el.replaceChild(createEl('span', {
  14638. className: 'vjs-menu-item-text',
  14639. textContent: this.localize(this.options_.label)
  14640. }), el.querySelector('.vjs-icon-placeholder'));
  14641. return el;
  14642. }
  14643. /**
  14644. * Ignore keys which are used by the menu, but pass any other ones up. See
  14645. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  14646. *
  14647. * @param {EventTarget~Event} event
  14648. * The `keydown` event that caused this function to be called.
  14649. *
  14650. * @listens keydown
  14651. */
  14652. ;
  14653. _proto.handleKeyDown = function handleKeyDown(event) {
  14654. if (!MenuKeys.some(function (key) {
  14655. return keycode.isEventKey(event, key);
  14656. })) {
  14657. // Pass keydown handling up for unused keys
  14658. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  14659. }
  14660. }
  14661. /**
  14662. * Any click on a `MenuItem` puts it into the selected state.
  14663. * See {@link ClickableComponent#handleClick} for instances where this is called.
  14664. *
  14665. * @param {EventTarget~Event} event
  14666. * The `keydown`, `tap`, or `click` event that caused this function to be
  14667. * called.
  14668. *
  14669. * @listens tap
  14670. * @listens click
  14671. */
  14672. ;
  14673. _proto.handleClick = function handleClick(event) {
  14674. this.selected(true);
  14675. }
  14676. /**
  14677. * Set the state for this menu item as selected or not.
  14678. *
  14679. * @param {boolean} selected
  14680. * if the menu item is selected or not
  14681. */
  14682. ;
  14683. _proto.selected = function selected(_selected) {
  14684. if (this.selectable) {
  14685. if (_selected) {
  14686. this.addClass('vjs-selected');
  14687. this.el_.setAttribute('aria-checked', 'true'); // aria-checked isn't fully supported by browsers/screen readers,
  14688. // so indicate selected state to screen reader in the control text.
  14689. this.controlText(', selected');
  14690. this.isSelected_ = true;
  14691. } else {
  14692. this.removeClass('vjs-selected');
  14693. this.el_.setAttribute('aria-checked', 'false'); // Indicate un-selected state to screen reader
  14694. this.controlText('');
  14695. this.isSelected_ = false;
  14696. }
  14697. }
  14698. };
  14699. return MenuItem;
  14700. }(ClickableComponent);
  14701. Component.registerComponent('MenuItem', MenuItem);
  14702. /**
  14703. * The specific menu item type for selecting a language within a text track kind
  14704. *
  14705. * @extends MenuItem
  14706. */
  14707. var TextTrackMenuItem = /*#__PURE__*/function (_MenuItem) {
  14708. inheritsLoose(TextTrackMenuItem, _MenuItem);
  14709. /**
  14710. * Creates an instance of this class.
  14711. *
  14712. * @param {Player} player
  14713. * The `Player` that this class should be attached to.
  14714. *
  14715. * @param {Object} [options]
  14716. * The key/value store of player options.
  14717. */
  14718. function TextTrackMenuItem(player, options) {
  14719. var _this;
  14720. var track = options.track;
  14721. var tracks = player.textTracks(); // Modify options for parent MenuItem class's init.
  14722. options.label = track.label || track.language || 'Unknown';
  14723. options.selected = track.mode === 'showing';
  14724. _this = _MenuItem.call(this, player, options) || this;
  14725. _this.track = track; // Determine the relevant kind(s) of tracks for this component and filter
  14726. // out empty kinds.
  14727. _this.kinds = (options.kinds || [options.kind || _this.track.kind]).filter(Boolean);
  14728. var changeHandler = function changeHandler() {
  14729. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  14730. args[_key] = arguments[_key];
  14731. }
  14732. _this.handleTracksChange.apply(assertThisInitialized(_this), args);
  14733. };
  14734. var selectedLanguageChangeHandler = function selectedLanguageChangeHandler() {
  14735. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  14736. args[_key2] = arguments[_key2];
  14737. }
  14738. _this.handleSelectedLanguageChange.apply(assertThisInitialized(_this), args);
  14739. };
  14740. player.on(['loadstart', 'texttrackchange'], changeHandler);
  14741. tracks.addEventListener('change', changeHandler);
  14742. tracks.addEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  14743. _this.on('dispose', function () {
  14744. player.off(['loadstart', 'texttrackchange'], changeHandler);
  14745. tracks.removeEventListener('change', changeHandler);
  14746. tracks.removeEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  14747. }); // iOS7 doesn't dispatch change events to TextTrackLists when an
  14748. // associated track's mode changes. Without something like
  14749. // Object.observe() (also not present on iOS7), it's not
  14750. // possible to detect changes to the mode attribute and polyfill
  14751. // the change event. As a poor substitute, we manually dispatch
  14752. // change events whenever the controls modify the mode.
  14753. if (tracks.onchange === undefined) {
  14754. var event;
  14755. _this.on(['tap', 'click'], function () {
  14756. if (typeof window.Event !== 'object') {
  14757. // Android 2.3 throws an Illegal Constructor error for window.Event
  14758. try {
  14759. event = new window.Event('change');
  14760. } catch (err) {// continue regardless of error
  14761. }
  14762. }
  14763. if (!event) {
  14764. event = document.createEvent('Event');
  14765. event.initEvent('change', true, true);
  14766. }
  14767. tracks.dispatchEvent(event);
  14768. });
  14769. } // set the default state based on current tracks
  14770. _this.handleTracksChange();
  14771. return _this;
  14772. }
  14773. /**
  14774. * This gets called when an `TextTrackMenuItem` is "clicked". See
  14775. * {@link ClickableComponent} for more detailed information on what a click can be.
  14776. *
  14777. * @param {EventTarget~Event} event
  14778. * The `keydown`, `tap`, or `click` event that caused this function to be
  14779. * called.
  14780. *
  14781. * @listens tap
  14782. * @listens click
  14783. */
  14784. var _proto = TextTrackMenuItem.prototype;
  14785. _proto.handleClick = function handleClick(event) {
  14786. var referenceTrack = this.track;
  14787. var tracks = this.player_.textTracks();
  14788. _MenuItem.prototype.handleClick.call(this, event);
  14789. if (!tracks) {
  14790. return;
  14791. }
  14792. for (var i = 0; i < tracks.length; i++) {
  14793. var track = tracks[i]; // If the track from the text tracks list is not of the right kind,
  14794. // skip it. We do not want to affect tracks of incompatible kind(s).
  14795. if (this.kinds.indexOf(track.kind) === -1) {
  14796. continue;
  14797. } // If this text track is the component's track and it is not showing,
  14798. // set it to showing.
  14799. if (track === referenceTrack) {
  14800. if (track.mode !== 'showing') {
  14801. track.mode = 'showing';
  14802. } // If this text track is not the component's track and it is not
  14803. // disabled, set it to disabled.
  14804. } else if (track.mode !== 'disabled') {
  14805. track.mode = 'disabled';
  14806. }
  14807. }
  14808. }
  14809. /**
  14810. * Handle text track list change
  14811. *
  14812. * @param {EventTarget~Event} event
  14813. * The `change` event that caused this function to be called.
  14814. *
  14815. * @listens TextTrackList#change
  14816. */
  14817. ;
  14818. _proto.handleTracksChange = function handleTracksChange(event) {
  14819. var shouldBeSelected = this.track.mode === 'showing'; // Prevent redundant selected() calls because they may cause
  14820. // screen readers to read the appended control text unnecessarily
  14821. if (shouldBeSelected !== this.isSelected_) {
  14822. this.selected(shouldBeSelected);
  14823. }
  14824. };
  14825. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  14826. if (this.track.mode === 'showing') {
  14827. var selectedLanguage = this.player_.cache_.selectedLanguage; // Don't replace the kind of track across the same language
  14828. if (selectedLanguage && selectedLanguage.enabled && selectedLanguage.language === this.track.language && selectedLanguage.kind !== this.track.kind) {
  14829. return;
  14830. }
  14831. this.player_.cache_.selectedLanguage = {
  14832. enabled: true,
  14833. language: this.track.language,
  14834. kind: this.track.kind
  14835. };
  14836. }
  14837. };
  14838. _proto.dispose = function dispose() {
  14839. // remove reference to track object on dispose
  14840. this.track = null;
  14841. _MenuItem.prototype.dispose.call(this);
  14842. };
  14843. return TextTrackMenuItem;
  14844. }(MenuItem);
  14845. Component.registerComponent('TextTrackMenuItem', TextTrackMenuItem);
  14846. /**
  14847. * A special menu item for turning of a specific type of text track
  14848. *
  14849. * @extends TextTrackMenuItem
  14850. */
  14851. var OffTextTrackMenuItem = /*#__PURE__*/function (_TextTrackMenuItem) {
  14852. inheritsLoose(OffTextTrackMenuItem, _TextTrackMenuItem);
  14853. /**
  14854. * Creates an instance of this class.
  14855. *
  14856. * @param {Player} player
  14857. * The `Player` that this class should be attached to.
  14858. *
  14859. * @param {Object} [options]
  14860. * The key/value store of player options.
  14861. */
  14862. function OffTextTrackMenuItem(player, options) {
  14863. // Create pseudo track info
  14864. // Requires options['kind']
  14865. options.track = {
  14866. player: player,
  14867. // it is no longer necessary to store `kind` or `kinds` on the track itself
  14868. // since they are now stored in the `kinds` property of all instances of
  14869. // TextTrackMenuItem, but this will remain for backwards compatibility
  14870. kind: options.kind,
  14871. kinds: options.kinds,
  14872. "default": false,
  14873. mode: 'disabled'
  14874. };
  14875. if (!options.kinds) {
  14876. options.kinds = [options.kind];
  14877. }
  14878. if (options.label) {
  14879. options.track.label = options.label;
  14880. } else {
  14881. options.track.label = options.kinds.join(' and ') + ' off';
  14882. } // MenuItem is selectable
  14883. options.selectable = true; // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  14884. options.multiSelectable = false;
  14885. return _TextTrackMenuItem.call(this, player, options) || this;
  14886. }
  14887. /**
  14888. * Handle text track change
  14889. *
  14890. * @param {EventTarget~Event} event
  14891. * The event that caused this function to run
  14892. */
  14893. var _proto = OffTextTrackMenuItem.prototype;
  14894. _proto.handleTracksChange = function handleTracksChange(event) {
  14895. var tracks = this.player().textTracks();
  14896. var shouldBeSelected = true;
  14897. for (var i = 0, l = tracks.length; i < l; i++) {
  14898. var track = tracks[i];
  14899. if (this.options_.kinds.indexOf(track.kind) > -1 && track.mode === 'showing') {
  14900. shouldBeSelected = false;
  14901. break;
  14902. }
  14903. } // Prevent redundant selected() calls because they may cause
  14904. // screen readers to read the appended control text unnecessarily
  14905. if (shouldBeSelected !== this.isSelected_) {
  14906. this.selected(shouldBeSelected);
  14907. }
  14908. };
  14909. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  14910. var tracks = this.player().textTracks();
  14911. var allHidden = true;
  14912. for (var i = 0, l = tracks.length; i < l; i++) {
  14913. var track = tracks[i];
  14914. if (['captions', 'descriptions', 'subtitles'].indexOf(track.kind) > -1 && track.mode === 'showing') {
  14915. allHidden = false;
  14916. break;
  14917. }
  14918. }
  14919. if (allHidden) {
  14920. this.player_.cache_.selectedLanguage = {
  14921. enabled: false
  14922. };
  14923. }
  14924. };
  14925. return OffTextTrackMenuItem;
  14926. }(TextTrackMenuItem);
  14927. Component.registerComponent('OffTextTrackMenuItem', OffTextTrackMenuItem);
  14928. /**
  14929. * The base class for buttons that toggle specific text track types (e.g. subtitles)
  14930. *
  14931. * @extends MenuButton
  14932. */
  14933. var TextTrackButton = /*#__PURE__*/function (_TrackButton) {
  14934. inheritsLoose(TextTrackButton, _TrackButton);
  14935. /**
  14936. * Creates an instance of this class.
  14937. *
  14938. * @param {Player} player
  14939. * The `Player` that this class should be attached to.
  14940. *
  14941. * @param {Object} [options={}]
  14942. * The key/value store of player options.
  14943. */
  14944. function TextTrackButton(player, options) {
  14945. if (options === void 0) {
  14946. options = {};
  14947. }
  14948. options.tracks = player.textTracks();
  14949. return _TrackButton.call(this, player, options) || this;
  14950. }
  14951. /**
  14952. * Create a menu item for each text track
  14953. *
  14954. * @param {TextTrackMenuItem[]} [items=[]]
  14955. * Existing array of items to use during creation
  14956. *
  14957. * @return {TextTrackMenuItem[]}
  14958. * Array of menu items that were created
  14959. */
  14960. var _proto = TextTrackButton.prototype;
  14961. _proto.createItems = function createItems(items, TrackMenuItem) {
  14962. if (items === void 0) {
  14963. items = [];
  14964. }
  14965. if (TrackMenuItem === void 0) {
  14966. TrackMenuItem = TextTrackMenuItem;
  14967. }
  14968. // Label is an override for the [track] off label
  14969. // USed to localise captions/subtitles
  14970. var label;
  14971. if (this.label_) {
  14972. label = this.label_ + " off";
  14973. } // Add an OFF menu item to turn all tracks off
  14974. items.push(new OffTextTrackMenuItem(this.player_, {
  14975. kinds: this.kinds_,
  14976. kind: this.kind_,
  14977. label: label
  14978. }));
  14979. this.hideThreshold_ += 1;
  14980. var tracks = this.player_.textTracks();
  14981. if (!Array.isArray(this.kinds_)) {
  14982. this.kinds_ = [this.kind_];
  14983. }
  14984. for (var i = 0; i < tracks.length; i++) {
  14985. var track = tracks[i]; // only add tracks that are of an appropriate kind and have a label
  14986. if (this.kinds_.indexOf(track.kind) > -1) {
  14987. var item = new TrackMenuItem(this.player_, {
  14988. track: track,
  14989. kinds: this.kinds_,
  14990. kind: this.kind_,
  14991. // MenuItem is selectable
  14992. selectable: true,
  14993. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  14994. multiSelectable: false
  14995. });
  14996. item.addClass("vjs-" + track.kind + "-menu-item");
  14997. items.push(item);
  14998. }
  14999. }
  15000. return items;
  15001. };
  15002. return TextTrackButton;
  15003. }(TrackButton);
  15004. Component.registerComponent('TextTrackButton', TextTrackButton);
  15005. /**
  15006. * The chapter track menu item
  15007. *
  15008. * @extends MenuItem
  15009. */
  15010. var ChaptersTrackMenuItem = /*#__PURE__*/function (_MenuItem) {
  15011. inheritsLoose(ChaptersTrackMenuItem, _MenuItem);
  15012. /**
  15013. * Creates an instance of this class.
  15014. *
  15015. * @param {Player} player
  15016. * The `Player` that this class should be attached to.
  15017. *
  15018. * @param {Object} [options]
  15019. * The key/value store of player options.
  15020. */
  15021. function ChaptersTrackMenuItem(player, options) {
  15022. var _this;
  15023. var track = options.track;
  15024. var cue = options.cue;
  15025. var currentTime = player.currentTime(); // Modify options for parent MenuItem class's init.
  15026. options.selectable = true;
  15027. options.multiSelectable = false;
  15028. options.label = cue.text;
  15029. options.selected = cue.startTime <= currentTime && currentTime < cue.endTime;
  15030. _this = _MenuItem.call(this, player, options) || this;
  15031. _this.track = track;
  15032. _this.cue = cue;
  15033. return _this;
  15034. }
  15035. /**
  15036. * This gets called when an `ChaptersTrackMenuItem` is "clicked". See
  15037. * {@link ClickableComponent} for more detailed information on what a click can be.
  15038. *
  15039. * @param {EventTarget~Event} [event]
  15040. * The `keydown`, `tap`, or `click` event that caused this function to be
  15041. * called.
  15042. *
  15043. * @listens tap
  15044. * @listens click
  15045. */
  15046. var _proto = ChaptersTrackMenuItem.prototype;
  15047. _proto.handleClick = function handleClick(event) {
  15048. _MenuItem.prototype.handleClick.call(this);
  15049. this.player_.currentTime(this.cue.startTime);
  15050. };
  15051. return ChaptersTrackMenuItem;
  15052. }(MenuItem);
  15053. Component.registerComponent('ChaptersTrackMenuItem', ChaptersTrackMenuItem);
  15054. /**
  15055. * The button component for toggling and selecting chapters
  15056. * Chapters act much differently than other text tracks
  15057. * Cues are navigation vs. other tracks of alternative languages
  15058. *
  15059. * @extends TextTrackButton
  15060. */
  15061. var ChaptersButton = /*#__PURE__*/function (_TextTrackButton) {
  15062. inheritsLoose(ChaptersButton, _TextTrackButton);
  15063. /**
  15064. * Creates an instance of this class.
  15065. *
  15066. * @param {Player} player
  15067. * The `Player` that this class should be attached to.
  15068. *
  15069. * @param {Object} [options]
  15070. * The key/value store of player options.
  15071. *
  15072. * @param {Component~ReadyCallback} [ready]
  15073. * The function to call when this function is ready.
  15074. */
  15075. function ChaptersButton(player, options, ready) {
  15076. var _this;
  15077. _this = _TextTrackButton.call(this, player, options, ready) || this;
  15078. _this.selectCurrentItem_ = function () {
  15079. _this.items.forEach(function (item) {
  15080. item.selected(_this.track_.activeCues[0] === item.cue);
  15081. });
  15082. };
  15083. return _this;
  15084. }
  15085. /**
  15086. * Builds the default DOM `className`.
  15087. *
  15088. * @return {string}
  15089. * The DOM `className` for this object.
  15090. */
  15091. var _proto = ChaptersButton.prototype;
  15092. _proto.buildCSSClass = function buildCSSClass() {
  15093. return "vjs-chapters-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15094. };
  15095. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15096. return "vjs-chapters-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15097. }
  15098. /**
  15099. * Update the menu based on the current state of its items.
  15100. *
  15101. * @param {EventTarget~Event} [event]
  15102. * An event that triggered this function to run.
  15103. *
  15104. * @listens TextTrackList#addtrack
  15105. * @listens TextTrackList#removetrack
  15106. * @listens TextTrackList#change
  15107. */
  15108. ;
  15109. _proto.update = function update(event) {
  15110. if (event && event.track && event.track.kind !== 'chapters') {
  15111. return;
  15112. }
  15113. var track = this.findChaptersTrack();
  15114. if (track !== this.track_) {
  15115. this.setTrack(track);
  15116. _TextTrackButton.prototype.update.call(this);
  15117. } else if (!this.items || track && track.cues && track.cues.length !== this.items.length) {
  15118. // Update the menu initially or if the number of cues has changed since set
  15119. _TextTrackButton.prototype.update.call(this);
  15120. }
  15121. }
  15122. /**
  15123. * Set the currently selected track for the chapters button.
  15124. *
  15125. * @param {TextTrack} track
  15126. * The new track to select. Nothing will change if this is the currently selected
  15127. * track.
  15128. */
  15129. ;
  15130. _proto.setTrack = function setTrack(track) {
  15131. if (this.track_ === track) {
  15132. return;
  15133. }
  15134. if (!this.updateHandler_) {
  15135. this.updateHandler_ = this.update.bind(this);
  15136. } // here this.track_ refers to the old track instance
  15137. if (this.track_) {
  15138. var remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  15139. if (remoteTextTrackEl) {
  15140. remoteTextTrackEl.removeEventListener('load', this.updateHandler_);
  15141. }
  15142. this.track_.removeEventListener('cuechange', this.selectCurrentItem_);
  15143. this.track_ = null;
  15144. }
  15145. this.track_ = track; // here this.track_ refers to the new track instance
  15146. if (this.track_) {
  15147. this.track_.mode = 'hidden';
  15148. var _remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  15149. if (_remoteTextTrackEl) {
  15150. _remoteTextTrackEl.addEventListener('load', this.updateHandler_);
  15151. }
  15152. this.track_.addEventListener('cuechange', this.selectCurrentItem_);
  15153. }
  15154. }
  15155. /**
  15156. * Find the track object that is currently in use by this ChaptersButton
  15157. *
  15158. * @return {TextTrack|undefined}
  15159. * The current track or undefined if none was found.
  15160. */
  15161. ;
  15162. _proto.findChaptersTrack = function findChaptersTrack() {
  15163. var tracks = this.player_.textTracks() || [];
  15164. for (var i = tracks.length - 1; i >= 0; i--) {
  15165. // We will always choose the last track as our chaptersTrack
  15166. var track = tracks[i];
  15167. if (track.kind === this.kind_) {
  15168. return track;
  15169. }
  15170. }
  15171. }
  15172. /**
  15173. * Get the caption for the ChaptersButton based on the track label. This will also
  15174. * use the current tracks localized kind as a fallback if a label does not exist.
  15175. *
  15176. * @return {string}
  15177. * The tracks current label or the localized track kind.
  15178. */
  15179. ;
  15180. _proto.getMenuCaption = function getMenuCaption() {
  15181. if (this.track_ && this.track_.label) {
  15182. return this.track_.label;
  15183. }
  15184. return this.localize(toTitleCase(this.kind_));
  15185. }
  15186. /**
  15187. * Create menu from chapter track
  15188. *
  15189. * @return {Menu}
  15190. * New menu for the chapter buttons
  15191. */
  15192. ;
  15193. _proto.createMenu = function createMenu() {
  15194. this.options_.title = this.getMenuCaption();
  15195. return _TextTrackButton.prototype.createMenu.call(this);
  15196. }
  15197. /**
  15198. * Create a menu item for each text track
  15199. *
  15200. * @return {TextTrackMenuItem[]}
  15201. * Array of menu items
  15202. */
  15203. ;
  15204. _proto.createItems = function createItems() {
  15205. var items = [];
  15206. if (!this.track_) {
  15207. return items;
  15208. }
  15209. var cues = this.track_.cues;
  15210. if (!cues) {
  15211. return items;
  15212. }
  15213. for (var i = 0, l = cues.length; i < l; i++) {
  15214. var cue = cues[i];
  15215. var mi = new ChaptersTrackMenuItem(this.player_, {
  15216. track: this.track_,
  15217. cue: cue
  15218. });
  15219. items.push(mi);
  15220. }
  15221. return items;
  15222. };
  15223. return ChaptersButton;
  15224. }(TextTrackButton);
  15225. /**
  15226. * `kind` of TextTrack to look for to associate it with this menu.
  15227. *
  15228. * @type {string}
  15229. * @private
  15230. */
  15231. ChaptersButton.prototype.kind_ = 'chapters';
  15232. /**
  15233. * The text that should display over the `ChaptersButton`s controls. Added for localization.
  15234. *
  15235. * @type {string}
  15236. * @private
  15237. */
  15238. ChaptersButton.prototype.controlText_ = 'Chapters';
  15239. Component.registerComponent('ChaptersButton', ChaptersButton);
  15240. /**
  15241. * The button component for toggling and selecting descriptions
  15242. *
  15243. * @extends TextTrackButton
  15244. */
  15245. var DescriptionsButton = /*#__PURE__*/function (_TextTrackButton) {
  15246. inheritsLoose(DescriptionsButton, _TextTrackButton);
  15247. /**
  15248. * Creates an instance of this class.
  15249. *
  15250. * @param {Player} player
  15251. * The `Player` that this class should be attached to.
  15252. *
  15253. * @param {Object} [options]
  15254. * The key/value store of player options.
  15255. *
  15256. * @param {Component~ReadyCallback} [ready]
  15257. * The function to call when this component is ready.
  15258. */
  15259. function DescriptionsButton(player, options, ready) {
  15260. var _this;
  15261. _this = _TextTrackButton.call(this, player, options, ready) || this;
  15262. var tracks = player.textTracks();
  15263. var changeHandler = bind(assertThisInitialized(_this), _this.handleTracksChange);
  15264. tracks.addEventListener('change', changeHandler);
  15265. _this.on('dispose', function () {
  15266. tracks.removeEventListener('change', changeHandler);
  15267. });
  15268. return _this;
  15269. }
  15270. /**
  15271. * Handle text track change
  15272. *
  15273. * @param {EventTarget~Event} event
  15274. * The event that caused this function to run
  15275. *
  15276. * @listens TextTrackList#change
  15277. */
  15278. var _proto = DescriptionsButton.prototype;
  15279. _proto.handleTracksChange = function handleTracksChange(event) {
  15280. var tracks = this.player().textTracks();
  15281. var disabled = false; // Check whether a track of a different kind is showing
  15282. for (var i = 0, l = tracks.length; i < l; i++) {
  15283. var track = tracks[i];
  15284. if (track.kind !== this.kind_ && track.mode === 'showing') {
  15285. disabled = true;
  15286. break;
  15287. }
  15288. } // If another track is showing, disable this menu button
  15289. if (disabled) {
  15290. this.disable();
  15291. } else {
  15292. this.enable();
  15293. }
  15294. }
  15295. /**
  15296. * Builds the default DOM `className`.
  15297. *
  15298. * @return {string}
  15299. * The DOM `className` for this object.
  15300. */
  15301. ;
  15302. _proto.buildCSSClass = function buildCSSClass() {
  15303. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15304. };
  15305. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15306. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15307. };
  15308. return DescriptionsButton;
  15309. }(TextTrackButton);
  15310. /**
  15311. * `kind` of TextTrack to look for to associate it with this menu.
  15312. *
  15313. * @type {string}
  15314. * @private
  15315. */
  15316. DescriptionsButton.prototype.kind_ = 'descriptions';
  15317. /**
  15318. * The text that should display over the `DescriptionsButton`s controls. Added for localization.
  15319. *
  15320. * @type {string}
  15321. * @private
  15322. */
  15323. DescriptionsButton.prototype.controlText_ = 'Descriptions';
  15324. Component.registerComponent('DescriptionsButton', DescriptionsButton);
  15325. /**
  15326. * The button component for toggling and selecting subtitles
  15327. *
  15328. * @extends TextTrackButton
  15329. */
  15330. var SubtitlesButton = /*#__PURE__*/function (_TextTrackButton) {
  15331. inheritsLoose(SubtitlesButton, _TextTrackButton);
  15332. /**
  15333. * Creates an instance of this class.
  15334. *
  15335. * @param {Player} player
  15336. * The `Player` that this class should be attached to.
  15337. *
  15338. * @param {Object} [options]
  15339. * The key/value store of player options.
  15340. *
  15341. * @param {Component~ReadyCallback} [ready]
  15342. * The function to call when this component is ready.
  15343. */
  15344. function SubtitlesButton(player, options, ready) {
  15345. return _TextTrackButton.call(this, player, options, ready) || this;
  15346. }
  15347. /**
  15348. * Builds the default DOM `className`.
  15349. *
  15350. * @return {string}
  15351. * The DOM `className` for this object.
  15352. */
  15353. var _proto = SubtitlesButton.prototype;
  15354. _proto.buildCSSClass = function buildCSSClass() {
  15355. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15356. };
  15357. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15358. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15359. };
  15360. return SubtitlesButton;
  15361. }(TextTrackButton);
  15362. /**
  15363. * `kind` of TextTrack to look for to associate it with this menu.
  15364. *
  15365. * @type {string}
  15366. * @private
  15367. */
  15368. SubtitlesButton.prototype.kind_ = 'subtitles';
  15369. /**
  15370. * The text that should display over the `SubtitlesButton`s controls. Added for localization.
  15371. *
  15372. * @type {string}
  15373. * @private
  15374. */
  15375. SubtitlesButton.prototype.controlText_ = 'Subtitles';
  15376. Component.registerComponent('SubtitlesButton', SubtitlesButton);
  15377. /**
  15378. * The menu item for caption track settings menu
  15379. *
  15380. * @extends TextTrackMenuItem
  15381. */
  15382. var CaptionSettingsMenuItem = /*#__PURE__*/function (_TextTrackMenuItem) {
  15383. inheritsLoose(CaptionSettingsMenuItem, _TextTrackMenuItem);
  15384. /**
  15385. * Creates an instance of this class.
  15386. *
  15387. * @param {Player} player
  15388. * The `Player` that this class should be attached to.
  15389. *
  15390. * @param {Object} [options]
  15391. * The key/value store of player options.
  15392. */
  15393. function CaptionSettingsMenuItem(player, options) {
  15394. var _this;
  15395. options.track = {
  15396. player: player,
  15397. kind: options.kind,
  15398. label: options.kind + ' settings',
  15399. selectable: false,
  15400. "default": false,
  15401. mode: 'disabled'
  15402. }; // CaptionSettingsMenuItem has no concept of 'selected'
  15403. options.selectable = false;
  15404. options.name = 'CaptionSettingsMenuItem';
  15405. _this = _TextTrackMenuItem.call(this, player, options) || this;
  15406. _this.addClass('vjs-texttrack-settings');
  15407. _this.controlText(', opens ' + options.kind + ' settings dialog');
  15408. return _this;
  15409. }
  15410. /**
  15411. * This gets called when an `CaptionSettingsMenuItem` is "clicked". See
  15412. * {@link ClickableComponent} for more detailed information on what a click can be.
  15413. *
  15414. * @param {EventTarget~Event} [event]
  15415. * The `keydown`, `tap`, or `click` event that caused this function to be
  15416. * called.
  15417. *
  15418. * @listens tap
  15419. * @listens click
  15420. */
  15421. var _proto = CaptionSettingsMenuItem.prototype;
  15422. _proto.handleClick = function handleClick(event) {
  15423. this.player().getChild('textTrackSettings').open();
  15424. };
  15425. return CaptionSettingsMenuItem;
  15426. }(TextTrackMenuItem);
  15427. Component.registerComponent('CaptionSettingsMenuItem', CaptionSettingsMenuItem);
  15428. /**
  15429. * The button component for toggling and selecting captions
  15430. *
  15431. * @extends TextTrackButton
  15432. */
  15433. var CaptionsButton = /*#__PURE__*/function (_TextTrackButton) {
  15434. inheritsLoose(CaptionsButton, _TextTrackButton);
  15435. /**
  15436. * Creates an instance of this class.
  15437. *
  15438. * @param {Player} player
  15439. * The `Player` that this class should be attached to.
  15440. *
  15441. * @param {Object} [options]
  15442. * The key/value store of player options.
  15443. *
  15444. * @param {Component~ReadyCallback} [ready]
  15445. * The function to call when this component is ready.
  15446. */
  15447. function CaptionsButton(player, options, ready) {
  15448. return _TextTrackButton.call(this, player, options, ready) || this;
  15449. }
  15450. /**
  15451. * Builds the default DOM `className`.
  15452. *
  15453. * @return {string}
  15454. * The DOM `className` for this object.
  15455. */
  15456. var _proto = CaptionsButton.prototype;
  15457. _proto.buildCSSClass = function buildCSSClass() {
  15458. return "vjs-captions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15459. };
  15460. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15461. return "vjs-captions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15462. }
  15463. /**
  15464. * Create caption menu items
  15465. *
  15466. * @return {CaptionSettingsMenuItem[]}
  15467. * The array of current menu items.
  15468. */
  15469. ;
  15470. _proto.createItems = function createItems() {
  15471. var items = [];
  15472. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  15473. items.push(new CaptionSettingsMenuItem(this.player_, {
  15474. kind: this.kind_
  15475. }));
  15476. this.hideThreshold_ += 1;
  15477. }
  15478. return _TextTrackButton.prototype.createItems.call(this, items);
  15479. };
  15480. return CaptionsButton;
  15481. }(TextTrackButton);
  15482. /**
  15483. * `kind` of TextTrack to look for to associate it with this menu.
  15484. *
  15485. * @type {string}
  15486. * @private
  15487. */
  15488. CaptionsButton.prototype.kind_ = 'captions';
  15489. /**
  15490. * The text that should display over the `CaptionsButton`s controls. Added for localization.
  15491. *
  15492. * @type {string}
  15493. * @private
  15494. */
  15495. CaptionsButton.prototype.controlText_ = 'Captions';
  15496. Component.registerComponent('CaptionsButton', CaptionsButton);
  15497. /**
  15498. * SubsCapsMenuItem has an [cc] icon to distinguish captions from subtitles
  15499. * in the SubsCapsMenu.
  15500. *
  15501. * @extends TextTrackMenuItem
  15502. */
  15503. var SubsCapsMenuItem = /*#__PURE__*/function (_TextTrackMenuItem) {
  15504. inheritsLoose(SubsCapsMenuItem, _TextTrackMenuItem);
  15505. function SubsCapsMenuItem() {
  15506. return _TextTrackMenuItem.apply(this, arguments) || this;
  15507. }
  15508. var _proto = SubsCapsMenuItem.prototype;
  15509. _proto.createEl = function createEl$1(type, props, attrs) {
  15510. var el = _TextTrackMenuItem.prototype.createEl.call(this, type, props, attrs);
  15511. var parentSpan = el.querySelector('.vjs-menu-item-text');
  15512. if (this.options_.track.kind === 'captions') {
  15513. parentSpan.appendChild(createEl('span', {
  15514. className: 'vjs-icon-placeholder'
  15515. }, {
  15516. 'aria-hidden': true
  15517. }));
  15518. parentSpan.appendChild(createEl('span', {
  15519. className: 'vjs-control-text',
  15520. // space added as the text will visually flow with the
  15521. // label
  15522. textContent: " " + this.localize('Captions')
  15523. }));
  15524. }
  15525. return el;
  15526. };
  15527. return SubsCapsMenuItem;
  15528. }(TextTrackMenuItem);
  15529. Component.registerComponent('SubsCapsMenuItem', SubsCapsMenuItem);
  15530. /**
  15531. * The button component for toggling and selecting captions and/or subtitles
  15532. *
  15533. * @extends TextTrackButton
  15534. */
  15535. var SubsCapsButton = /*#__PURE__*/function (_TextTrackButton) {
  15536. inheritsLoose(SubsCapsButton, _TextTrackButton);
  15537. function SubsCapsButton(player, options) {
  15538. var _this;
  15539. if (options === void 0) {
  15540. options = {};
  15541. }
  15542. _this = _TextTrackButton.call(this, player, options) || this; // Although North America uses "captions" in most cases for
  15543. // "captions and subtitles" other locales use "subtitles"
  15544. _this.label_ = 'subtitles';
  15545. if (['en', 'en-us', 'en-ca', 'fr-ca'].indexOf(_this.player_.language_) > -1) {
  15546. _this.label_ = 'captions';
  15547. }
  15548. _this.menuButton_.controlText(toTitleCase(_this.label_));
  15549. return _this;
  15550. }
  15551. /**
  15552. * Builds the default DOM `className`.
  15553. *
  15554. * @return {string}
  15555. * The DOM `className` for this object.
  15556. */
  15557. var _proto = SubsCapsButton.prototype;
  15558. _proto.buildCSSClass = function buildCSSClass() {
  15559. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15560. };
  15561. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15562. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15563. }
  15564. /**
  15565. * Create caption/subtitles menu items
  15566. *
  15567. * @return {CaptionSettingsMenuItem[]}
  15568. * The array of current menu items.
  15569. */
  15570. ;
  15571. _proto.createItems = function createItems() {
  15572. var items = [];
  15573. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  15574. items.push(new CaptionSettingsMenuItem(this.player_, {
  15575. kind: this.label_
  15576. }));
  15577. this.hideThreshold_ += 1;
  15578. }
  15579. items = _TextTrackButton.prototype.createItems.call(this, items, SubsCapsMenuItem);
  15580. return items;
  15581. };
  15582. return SubsCapsButton;
  15583. }(TextTrackButton);
  15584. /**
  15585. * `kind`s of TextTrack to look for to associate it with this menu.
  15586. *
  15587. * @type {array}
  15588. * @private
  15589. */
  15590. SubsCapsButton.prototype.kinds_ = ['captions', 'subtitles'];
  15591. /**
  15592. * The text that should display over the `SubsCapsButton`s controls.
  15593. *
  15594. *
  15595. * @type {string}
  15596. * @private
  15597. */
  15598. SubsCapsButton.prototype.controlText_ = 'Subtitles';
  15599. Component.registerComponent('SubsCapsButton', SubsCapsButton);
  15600. /**
  15601. * An {@link AudioTrack} {@link MenuItem}
  15602. *
  15603. * @extends MenuItem
  15604. */
  15605. var AudioTrackMenuItem = /*#__PURE__*/function (_MenuItem) {
  15606. inheritsLoose(AudioTrackMenuItem, _MenuItem);
  15607. /**
  15608. * Creates an instance of this class.
  15609. *
  15610. * @param {Player} player
  15611. * The `Player` that this class should be attached to.
  15612. *
  15613. * @param {Object} [options]
  15614. * The key/value store of player options.
  15615. */
  15616. function AudioTrackMenuItem(player, options) {
  15617. var _this;
  15618. var track = options.track;
  15619. var tracks = player.audioTracks(); // Modify options for parent MenuItem class's init.
  15620. options.label = track.label || track.language || 'Unknown';
  15621. options.selected = track.enabled;
  15622. _this = _MenuItem.call(this, player, options) || this;
  15623. _this.track = track;
  15624. _this.addClass("vjs-" + track.kind + "-menu-item");
  15625. var changeHandler = function changeHandler() {
  15626. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  15627. args[_key] = arguments[_key];
  15628. }
  15629. _this.handleTracksChange.apply(assertThisInitialized(_this), args);
  15630. };
  15631. tracks.addEventListener('change', changeHandler);
  15632. _this.on('dispose', function () {
  15633. tracks.removeEventListener('change', changeHandler);
  15634. });
  15635. return _this;
  15636. }
  15637. var _proto = AudioTrackMenuItem.prototype;
  15638. _proto.createEl = function createEl$1(type, props, attrs) {
  15639. var el = _MenuItem.prototype.createEl.call(this, type, props, attrs);
  15640. var parentSpan = el.querySelector('.vjs-menu-item-text');
  15641. if (this.options_.track.kind === 'main-desc') {
  15642. parentSpan.appendChild(createEl('span', {
  15643. className: 'vjs-icon-placeholder'
  15644. }, {
  15645. 'aria-hidden': true
  15646. }));
  15647. parentSpan.appendChild(createEl('span', {
  15648. className: 'vjs-control-text',
  15649. textContent: ' ' + this.localize('Descriptions')
  15650. }));
  15651. }
  15652. return el;
  15653. }
  15654. /**
  15655. * This gets called when an `AudioTrackMenuItem is "clicked". See {@link ClickableComponent}
  15656. * for more detailed information on what a click can be.
  15657. *
  15658. * @param {EventTarget~Event} [event]
  15659. * The `keydown`, `tap`, or `click` event that caused this function to be
  15660. * called.
  15661. *
  15662. * @listens tap
  15663. * @listens click
  15664. */
  15665. ;
  15666. _proto.handleClick = function handleClick(event) {
  15667. _MenuItem.prototype.handleClick.call(this, event); // the audio track list will automatically toggle other tracks
  15668. // off for us.
  15669. this.track.enabled = true; // when native audio tracks are used, we want to make sure that other tracks are turned off
  15670. if (this.player_.tech_.featuresNativeAudioTracks) {
  15671. var tracks = this.player_.audioTracks();
  15672. for (var i = 0; i < tracks.length; i++) {
  15673. var track = tracks[i]; // skip the current track since we enabled it above
  15674. if (track === this.track) {
  15675. continue;
  15676. }
  15677. track.enabled = track === this.track;
  15678. }
  15679. }
  15680. }
  15681. /**
  15682. * Handle any {@link AudioTrack} change.
  15683. *
  15684. * @param {EventTarget~Event} [event]
  15685. * The {@link AudioTrackList#change} event that caused this to run.
  15686. *
  15687. * @listens AudioTrackList#change
  15688. */
  15689. ;
  15690. _proto.handleTracksChange = function handleTracksChange(event) {
  15691. this.selected(this.track.enabled);
  15692. };
  15693. return AudioTrackMenuItem;
  15694. }(MenuItem);
  15695. Component.registerComponent('AudioTrackMenuItem', AudioTrackMenuItem);
  15696. /**
  15697. * The base class for buttons that toggle specific {@link AudioTrack} types.
  15698. *
  15699. * @extends TrackButton
  15700. */
  15701. var AudioTrackButton = /*#__PURE__*/function (_TrackButton) {
  15702. inheritsLoose(AudioTrackButton, _TrackButton);
  15703. /**
  15704. * Creates an instance of this class.
  15705. *
  15706. * @param {Player} player
  15707. * The `Player` that this class should be attached to.
  15708. *
  15709. * @param {Object} [options={}]
  15710. * The key/value store of player options.
  15711. */
  15712. function AudioTrackButton(player, options) {
  15713. if (options === void 0) {
  15714. options = {};
  15715. }
  15716. options.tracks = player.audioTracks();
  15717. return _TrackButton.call(this, player, options) || this;
  15718. }
  15719. /**
  15720. * Builds the default DOM `className`.
  15721. *
  15722. * @return {string}
  15723. * The DOM `className` for this object.
  15724. */
  15725. var _proto = AudioTrackButton.prototype;
  15726. _proto.buildCSSClass = function buildCSSClass() {
  15727. return "vjs-audio-button " + _TrackButton.prototype.buildCSSClass.call(this);
  15728. };
  15729. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15730. return "vjs-audio-button " + _TrackButton.prototype.buildWrapperCSSClass.call(this);
  15731. }
  15732. /**
  15733. * Create a menu item for each audio track
  15734. *
  15735. * @param {AudioTrackMenuItem[]} [items=[]]
  15736. * An array of existing menu items to use.
  15737. *
  15738. * @return {AudioTrackMenuItem[]}
  15739. * An array of menu items
  15740. */
  15741. ;
  15742. _proto.createItems = function createItems(items) {
  15743. if (items === void 0) {
  15744. items = [];
  15745. }
  15746. // if there's only one audio track, there no point in showing it
  15747. this.hideThreshold_ = 1;
  15748. var tracks = this.player_.audioTracks();
  15749. for (var i = 0; i < tracks.length; i++) {
  15750. var track = tracks[i];
  15751. items.push(new AudioTrackMenuItem(this.player_, {
  15752. track: track,
  15753. // MenuItem is selectable
  15754. selectable: true,
  15755. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  15756. multiSelectable: false
  15757. }));
  15758. }
  15759. return items;
  15760. };
  15761. return AudioTrackButton;
  15762. }(TrackButton);
  15763. /**
  15764. * The text that should display over the `AudioTrackButton`s controls. Added for localization.
  15765. *
  15766. * @type {string}
  15767. * @private
  15768. */
  15769. AudioTrackButton.prototype.controlText_ = 'Audio Track';
  15770. Component.registerComponent('AudioTrackButton', AudioTrackButton);
  15771. /**
  15772. * The specific menu item type for selecting a playback rate.
  15773. *
  15774. * @extends MenuItem
  15775. */
  15776. var PlaybackRateMenuItem = /*#__PURE__*/function (_MenuItem) {
  15777. inheritsLoose(PlaybackRateMenuItem, _MenuItem);
  15778. /**
  15779. * Creates an instance of this class.
  15780. *
  15781. * @param {Player} player
  15782. * The `Player` that this class should be attached to.
  15783. *
  15784. * @param {Object} [options]
  15785. * The key/value store of player options.
  15786. */
  15787. function PlaybackRateMenuItem(player, options) {
  15788. var _this;
  15789. var label = options.rate;
  15790. var rate = parseFloat(label, 10); // Modify options for parent MenuItem class's init.
  15791. options.label = label;
  15792. options.selected = rate === player.playbackRate();
  15793. options.selectable = true;
  15794. options.multiSelectable = false;
  15795. _this = _MenuItem.call(this, player, options) || this;
  15796. _this.label = label;
  15797. _this.rate = rate;
  15798. _this.on(player, 'ratechange', function (e) {
  15799. return _this.update(e);
  15800. });
  15801. return _this;
  15802. }
  15803. /**
  15804. * This gets called when an `PlaybackRateMenuItem` is "clicked". See
  15805. * {@link ClickableComponent} for more detailed information on what a click can be.
  15806. *
  15807. * @param {EventTarget~Event} [event]
  15808. * The `keydown`, `tap`, or `click` event that caused this function to be
  15809. * called.
  15810. *
  15811. * @listens tap
  15812. * @listens click
  15813. */
  15814. var _proto = PlaybackRateMenuItem.prototype;
  15815. _proto.handleClick = function handleClick(event) {
  15816. _MenuItem.prototype.handleClick.call(this);
  15817. this.player().playbackRate(this.rate);
  15818. }
  15819. /**
  15820. * Update the PlaybackRateMenuItem when the playbackrate changes.
  15821. *
  15822. * @param {EventTarget~Event} [event]
  15823. * The `ratechange` event that caused this function to run.
  15824. *
  15825. * @listens Player#ratechange
  15826. */
  15827. ;
  15828. _proto.update = function update(event) {
  15829. this.selected(this.player().playbackRate() === this.rate);
  15830. };
  15831. return PlaybackRateMenuItem;
  15832. }(MenuItem);
  15833. /**
  15834. * The text that should display over the `PlaybackRateMenuItem`s controls. Added for localization.
  15835. *
  15836. * @type {string}
  15837. * @private
  15838. */
  15839. PlaybackRateMenuItem.prototype.contentElType = 'button';
  15840. Component.registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem);
  15841. /**
  15842. * The component for controlling the playback rate.
  15843. *
  15844. * @extends MenuButton
  15845. */
  15846. var PlaybackRateMenuButton = /*#__PURE__*/function (_MenuButton) {
  15847. inheritsLoose(PlaybackRateMenuButton, _MenuButton);
  15848. /**
  15849. * Creates an instance of this class.
  15850. *
  15851. * @param {Player} player
  15852. * The `Player` that this class should be attached to.
  15853. *
  15854. * @param {Object} [options]
  15855. * The key/value store of player options.
  15856. */
  15857. function PlaybackRateMenuButton(player, options) {
  15858. var _this;
  15859. _this = _MenuButton.call(this, player, options) || this;
  15860. _this.menuButton_.el_.setAttribute('aria-describedby', _this.labelElId_);
  15861. _this.updateVisibility();
  15862. _this.updateLabel();
  15863. _this.on(player, 'loadstart', function (e) {
  15864. return _this.updateVisibility(e);
  15865. });
  15866. _this.on(player, 'ratechange', function (e) {
  15867. return _this.updateLabel(e);
  15868. });
  15869. _this.on(player, 'playbackrateschange', function (e) {
  15870. return _this.handlePlaybackRateschange(e);
  15871. });
  15872. return _this;
  15873. }
  15874. /**
  15875. * Create the `Component`'s DOM element
  15876. *
  15877. * @return {Element}
  15878. * The element that was created.
  15879. */
  15880. var _proto = PlaybackRateMenuButton.prototype;
  15881. _proto.createEl = function createEl$1() {
  15882. var el = _MenuButton.prototype.createEl.call(this);
  15883. this.labelElId_ = 'vjs-playback-rate-value-label-' + this.id_;
  15884. this.labelEl_ = createEl('div', {
  15885. className: 'vjs-playback-rate-value',
  15886. id: this.labelElId_,
  15887. textContent: '1x'
  15888. });
  15889. el.appendChild(this.labelEl_);
  15890. return el;
  15891. };
  15892. _proto.dispose = function dispose() {
  15893. this.labelEl_ = null;
  15894. _MenuButton.prototype.dispose.call(this);
  15895. }
  15896. /**
  15897. * Builds the default DOM `className`.
  15898. *
  15899. * @return {string}
  15900. * The DOM `className` for this object.
  15901. */
  15902. ;
  15903. _proto.buildCSSClass = function buildCSSClass() {
  15904. return "vjs-playback-rate " + _MenuButton.prototype.buildCSSClass.call(this);
  15905. };
  15906. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15907. return "vjs-playback-rate " + _MenuButton.prototype.buildWrapperCSSClass.call(this);
  15908. }
  15909. /**
  15910. * Create the list of menu items. Specific to each subclass.
  15911. *
  15912. */
  15913. ;
  15914. _proto.createItems = function createItems() {
  15915. var rates = this.playbackRates();
  15916. var items = [];
  15917. for (var i = rates.length - 1; i >= 0; i--) {
  15918. items.push(new PlaybackRateMenuItem(this.player(), {
  15919. rate: rates[i] + 'x'
  15920. }));
  15921. }
  15922. return items;
  15923. }
  15924. /**
  15925. * Updates ARIA accessibility attributes
  15926. */
  15927. ;
  15928. _proto.updateARIAAttributes = function updateARIAAttributes() {
  15929. // Current playback rate
  15930. this.el().setAttribute('aria-valuenow', this.player().playbackRate());
  15931. }
  15932. /**
  15933. * This gets called when an `PlaybackRateMenuButton` is "clicked". See
  15934. * {@link ClickableComponent} for more detailed information on what a click can be.
  15935. *
  15936. * @param {EventTarget~Event} [event]
  15937. * The `keydown`, `tap`, or `click` event that caused this function to be
  15938. * called.
  15939. *
  15940. * @listens tap
  15941. * @listens click
  15942. */
  15943. ;
  15944. _proto.handleClick = function handleClick(event) {
  15945. // select next rate option
  15946. var currentRate = this.player().playbackRate();
  15947. var rates = this.playbackRates();
  15948. var currentIndex = rates.indexOf(currentRate); // this get the next rate and it will select first one if the last one currently selected
  15949. var newIndex = (currentIndex + 1) % rates.length;
  15950. this.player().playbackRate(rates[newIndex]);
  15951. }
  15952. /**
  15953. * On playbackrateschange, update the menu to account for the new items.
  15954. *
  15955. * @listens Player#playbackrateschange
  15956. */
  15957. ;
  15958. _proto.handlePlaybackRateschange = function handlePlaybackRateschange(event) {
  15959. this.update();
  15960. }
  15961. /**
  15962. * Get possible playback rates
  15963. *
  15964. * @return {Array}
  15965. * All possible playback rates
  15966. */
  15967. ;
  15968. _proto.playbackRates = function playbackRates() {
  15969. var player = this.player();
  15970. return player.playbackRates && player.playbackRates() || [];
  15971. }
  15972. /**
  15973. * Get whether playback rates is supported by the tech
  15974. * and an array of playback rates exists
  15975. *
  15976. * @return {boolean}
  15977. * Whether changing playback rate is supported
  15978. */
  15979. ;
  15980. _proto.playbackRateSupported = function playbackRateSupported() {
  15981. return this.player().tech_ && this.player().tech_.featuresPlaybackRate && this.playbackRates() && this.playbackRates().length > 0;
  15982. }
  15983. /**
  15984. * Hide playback rate controls when they're no playback rate options to select
  15985. *
  15986. * @param {EventTarget~Event} [event]
  15987. * The event that caused this function to run.
  15988. *
  15989. * @listens Player#loadstart
  15990. */
  15991. ;
  15992. _proto.updateVisibility = function updateVisibility(event) {
  15993. if (this.playbackRateSupported()) {
  15994. this.removeClass('vjs-hidden');
  15995. } else {
  15996. this.addClass('vjs-hidden');
  15997. }
  15998. }
  15999. /**
  16000. * Update button label when rate changed
  16001. *
  16002. * @param {EventTarget~Event} [event]
  16003. * The event that caused this function to run.
  16004. *
  16005. * @listens Player#ratechange
  16006. */
  16007. ;
  16008. _proto.updateLabel = function updateLabel(event) {
  16009. if (this.playbackRateSupported()) {
  16010. this.labelEl_.textContent = this.player().playbackRate() + 'x';
  16011. }
  16012. };
  16013. return PlaybackRateMenuButton;
  16014. }(MenuButton);
  16015. /**
  16016. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  16017. *
  16018. * @type {string}
  16019. * @private
  16020. */
  16021. PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
  16022. Component.registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
  16023. /**
  16024. * Just an empty spacer element that can be used as an append point for plugins, etc.
  16025. * Also can be used to create space between elements when necessary.
  16026. *
  16027. * @extends Component
  16028. */
  16029. var Spacer = /*#__PURE__*/function (_Component) {
  16030. inheritsLoose(Spacer, _Component);
  16031. function Spacer() {
  16032. return _Component.apply(this, arguments) || this;
  16033. }
  16034. var _proto = Spacer.prototype;
  16035. /**
  16036. * Builds the default DOM `className`.
  16037. *
  16038. * @return {string}
  16039. * The DOM `className` for this object.
  16040. */
  16041. _proto.buildCSSClass = function buildCSSClass() {
  16042. return "vjs-spacer " + _Component.prototype.buildCSSClass.call(this);
  16043. }
  16044. /**
  16045. * Create the `Component`'s DOM element
  16046. *
  16047. * @return {Element}
  16048. * The element that was created.
  16049. */
  16050. ;
  16051. _proto.createEl = function createEl(tag, props, attributes) {
  16052. if (tag === void 0) {
  16053. tag = 'div';
  16054. }
  16055. if (props === void 0) {
  16056. props = {};
  16057. }
  16058. if (attributes === void 0) {
  16059. attributes = {};
  16060. }
  16061. if (!props.className) {
  16062. props.className = this.buildCSSClass();
  16063. }
  16064. return _Component.prototype.createEl.call(this, tag, props, attributes);
  16065. };
  16066. return Spacer;
  16067. }(Component);
  16068. Component.registerComponent('Spacer', Spacer);
  16069. /**
  16070. * Spacer specifically meant to be used as an insertion point for new plugins, etc.
  16071. *
  16072. * @extends Spacer
  16073. */
  16074. var CustomControlSpacer = /*#__PURE__*/function (_Spacer) {
  16075. inheritsLoose(CustomControlSpacer, _Spacer);
  16076. function CustomControlSpacer() {
  16077. return _Spacer.apply(this, arguments) || this;
  16078. }
  16079. var _proto = CustomControlSpacer.prototype;
  16080. /**
  16081. * Builds the default DOM `className`.
  16082. *
  16083. * @return {string}
  16084. * The DOM `className` for this object.
  16085. */
  16086. _proto.buildCSSClass = function buildCSSClass() {
  16087. return "vjs-custom-control-spacer " + _Spacer.prototype.buildCSSClass.call(this);
  16088. }
  16089. /**
  16090. * Create the `Component`'s DOM element
  16091. *
  16092. * @return {Element}
  16093. * The element that was created.
  16094. */
  16095. ;
  16096. _proto.createEl = function createEl() {
  16097. return _Spacer.prototype.createEl.call(this, 'div', {
  16098. className: this.buildCSSClass(),
  16099. // No-flex/table-cell mode requires there be some content
  16100. // in the cell to fill the remaining space of the table.
  16101. textContent: "\xA0"
  16102. });
  16103. };
  16104. return CustomControlSpacer;
  16105. }(Spacer);
  16106. Component.registerComponent('CustomControlSpacer', CustomControlSpacer);
  16107. /**
  16108. * Container of main controls.
  16109. *
  16110. * @extends Component
  16111. */
  16112. var ControlBar = /*#__PURE__*/function (_Component) {
  16113. inheritsLoose(ControlBar, _Component);
  16114. function ControlBar() {
  16115. return _Component.apply(this, arguments) || this;
  16116. }
  16117. var _proto = ControlBar.prototype;
  16118. /**
  16119. * Create the `Component`'s DOM element
  16120. *
  16121. * @return {Element}
  16122. * The element that was created.
  16123. */
  16124. _proto.createEl = function createEl() {
  16125. return _Component.prototype.createEl.call(this, 'div', {
  16126. className: 'vjs-control-bar',
  16127. dir: 'ltr'
  16128. });
  16129. };
  16130. return ControlBar;
  16131. }(Component);
  16132. /**
  16133. * Default options for `ControlBar`
  16134. *
  16135. * @type {Object}
  16136. * @private
  16137. */
  16138. ControlBar.prototype.options_ = {
  16139. children: ['playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'seekToLive', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'descriptionsButton', 'subsCapsButton', 'audioTrackButton', 'fullscreenToggle']
  16140. };
  16141. if ('exitPictureInPicture' in document) {
  16142. ControlBar.prototype.options_.children.splice(ControlBar.prototype.options_.children.length - 1, 0, 'pictureInPictureToggle');
  16143. }
  16144. Component.registerComponent('ControlBar', ControlBar);
  16145. /**
  16146. * A display that indicates an error has occurred. This means that the video
  16147. * is unplayable.
  16148. *
  16149. * @extends ModalDialog
  16150. */
  16151. var ErrorDisplay = /*#__PURE__*/function (_ModalDialog) {
  16152. inheritsLoose(ErrorDisplay, _ModalDialog);
  16153. /**
  16154. * Creates an instance of this class.
  16155. *
  16156. * @param {Player} player
  16157. * The `Player` that this class should be attached to.
  16158. *
  16159. * @param {Object} [options]
  16160. * The key/value store of player options.
  16161. */
  16162. function ErrorDisplay(player, options) {
  16163. var _this;
  16164. _this = _ModalDialog.call(this, player, options) || this;
  16165. _this.on(player, 'error', function (e) {
  16166. return _this.open(e);
  16167. });
  16168. return _this;
  16169. }
  16170. /**
  16171. * Builds the default DOM `className`.
  16172. *
  16173. * @return {string}
  16174. * The DOM `className` for this object.
  16175. *
  16176. * @deprecated Since version 5.
  16177. */
  16178. var _proto = ErrorDisplay.prototype;
  16179. _proto.buildCSSClass = function buildCSSClass() {
  16180. return "vjs-error-display " + _ModalDialog.prototype.buildCSSClass.call(this);
  16181. }
  16182. /**
  16183. * Gets the localized error message based on the `Player`s error.
  16184. *
  16185. * @return {string}
  16186. * The `Player`s error message localized or an empty string.
  16187. */
  16188. ;
  16189. _proto.content = function content() {
  16190. var error = this.player().error();
  16191. return error ? this.localize(error.message) : '';
  16192. };
  16193. return ErrorDisplay;
  16194. }(ModalDialog);
  16195. /**
  16196. * The default options for an `ErrorDisplay`.
  16197. *
  16198. * @private
  16199. */
  16200. ErrorDisplay.prototype.options_ = _extends_1({}, ModalDialog.prototype.options_, {
  16201. pauseOnOpen: false,
  16202. fillAlways: true,
  16203. temporary: false,
  16204. uncloseable: true
  16205. });
  16206. Component.registerComponent('ErrorDisplay', ErrorDisplay);
  16207. var LOCAL_STORAGE_KEY = 'vjs-text-track-settings';
  16208. var COLOR_BLACK = ['#000', 'Black'];
  16209. var COLOR_BLUE = ['#00F', 'Blue'];
  16210. var COLOR_CYAN = ['#0FF', 'Cyan'];
  16211. var COLOR_GREEN = ['#0F0', 'Green'];
  16212. var COLOR_MAGENTA = ['#F0F', 'Magenta'];
  16213. var COLOR_RED = ['#F00', 'Red'];
  16214. var COLOR_WHITE = ['#FFF', 'White'];
  16215. var COLOR_YELLOW = ['#FF0', 'Yellow'];
  16216. var OPACITY_OPAQUE = ['1', 'Opaque'];
  16217. var OPACITY_SEMI = ['0.5', 'Semi-Transparent'];
  16218. var OPACITY_TRANS = ['0', 'Transparent']; // Configuration for the various <select> elements in the DOM of this component.
  16219. //
  16220. // Possible keys include:
  16221. //
  16222. // `default`:
  16223. // The default option index. Only needs to be provided if not zero.
  16224. // `parser`:
  16225. // A function which is used to parse the value from the selected option in
  16226. // a customized way.
  16227. // `selector`:
  16228. // The selector used to find the associated <select> element.
  16229. var selectConfigs = {
  16230. backgroundColor: {
  16231. selector: '.vjs-bg-color > select',
  16232. id: 'captions-background-color-%s',
  16233. label: 'Color',
  16234. options: [COLOR_BLACK, COLOR_WHITE, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  16235. },
  16236. backgroundOpacity: {
  16237. selector: '.vjs-bg-opacity > select',
  16238. id: 'captions-background-opacity-%s',
  16239. label: 'Transparency',
  16240. options: [OPACITY_OPAQUE, OPACITY_SEMI, OPACITY_TRANS]
  16241. },
  16242. color: {
  16243. selector: '.vjs-fg-color > select',
  16244. id: 'captions-foreground-color-%s',
  16245. label: 'Color',
  16246. options: [COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  16247. },
  16248. edgeStyle: {
  16249. selector: '.vjs-edge-style > select',
  16250. id: '%s',
  16251. label: 'Text Edge Style',
  16252. options: [['none', 'None'], ['raised', 'Raised'], ['depressed', 'Depressed'], ['uniform', 'Uniform'], ['dropshadow', 'Dropshadow']]
  16253. },
  16254. fontFamily: {
  16255. selector: '.vjs-font-family > select',
  16256. id: 'captions-font-family-%s',
  16257. label: 'Font Family',
  16258. options: [['proportionalSansSerif', 'Proportional Sans-Serif'], ['monospaceSansSerif', 'Monospace Sans-Serif'], ['proportionalSerif', 'Proportional Serif'], ['monospaceSerif', 'Monospace Serif'], ['casual', 'Casual'], ['script', 'Script'], ['small-caps', 'Small Caps']]
  16259. },
  16260. fontPercent: {
  16261. selector: '.vjs-font-percent > select',
  16262. id: 'captions-font-size-%s',
  16263. label: 'Font Size',
  16264. options: [['0.50', '50%'], ['0.75', '75%'], ['1.00', '100%'], ['1.25', '125%'], ['1.50', '150%'], ['1.75', '175%'], ['2.00', '200%'], ['3.00', '300%'], ['4.00', '400%']],
  16265. "default": 2,
  16266. parser: function parser(v) {
  16267. return v === '1.00' ? null : Number(v);
  16268. }
  16269. },
  16270. textOpacity: {
  16271. selector: '.vjs-text-opacity > select',
  16272. id: 'captions-foreground-opacity-%s',
  16273. label: 'Transparency',
  16274. options: [OPACITY_OPAQUE, OPACITY_SEMI]
  16275. },
  16276. // Options for this object are defined below.
  16277. windowColor: {
  16278. selector: '.vjs-window-color > select',
  16279. id: 'captions-window-color-%s',
  16280. label: 'Color'
  16281. },
  16282. // Options for this object are defined below.
  16283. windowOpacity: {
  16284. selector: '.vjs-window-opacity > select',
  16285. id: 'captions-window-opacity-%s',
  16286. label: 'Transparency',
  16287. options: [OPACITY_TRANS, OPACITY_SEMI, OPACITY_OPAQUE]
  16288. }
  16289. };
  16290. selectConfigs.windowColor.options = selectConfigs.backgroundColor.options;
  16291. /**
  16292. * Get the actual value of an option.
  16293. *
  16294. * @param {string} value
  16295. * The value to get
  16296. *
  16297. * @param {Function} [parser]
  16298. * Optional function to adjust the value.
  16299. *
  16300. * @return {Mixed}
  16301. * - Will be `undefined` if no value exists
  16302. * - Will be `undefined` if the given value is "none".
  16303. * - Will be the actual value otherwise.
  16304. *
  16305. * @private
  16306. */
  16307. function parseOptionValue(value, parser) {
  16308. if (parser) {
  16309. value = parser(value);
  16310. }
  16311. if (value && value !== 'none') {
  16312. return value;
  16313. }
  16314. }
  16315. /**
  16316. * Gets the value of the selected <option> element within a <select> element.
  16317. *
  16318. * @param {Element} el
  16319. * the element to look in
  16320. *
  16321. * @param {Function} [parser]
  16322. * Optional function to adjust the value.
  16323. *
  16324. * @return {Mixed}
  16325. * - Will be `undefined` if no value exists
  16326. * - Will be `undefined` if the given value is "none".
  16327. * - Will be the actual value otherwise.
  16328. *
  16329. * @private
  16330. */
  16331. function getSelectedOptionValue(el, parser) {
  16332. var value = el.options[el.options.selectedIndex].value;
  16333. return parseOptionValue(value, parser);
  16334. }
  16335. /**
  16336. * Sets the selected <option> element within a <select> element based on a
  16337. * given value.
  16338. *
  16339. * @param {Element} el
  16340. * The element to look in.
  16341. *
  16342. * @param {string} value
  16343. * the property to look on.
  16344. *
  16345. * @param {Function} [parser]
  16346. * Optional function to adjust the value before comparing.
  16347. *
  16348. * @private
  16349. */
  16350. function setSelectedOption(el, value, parser) {
  16351. if (!value) {
  16352. return;
  16353. }
  16354. for (var i = 0; i < el.options.length; i++) {
  16355. if (parseOptionValue(el.options[i].value, parser) === value) {
  16356. el.selectedIndex = i;
  16357. break;
  16358. }
  16359. }
  16360. }
  16361. /**
  16362. * Manipulate Text Tracks settings.
  16363. *
  16364. * @extends ModalDialog
  16365. */
  16366. var TextTrackSettings = /*#__PURE__*/function (_ModalDialog) {
  16367. inheritsLoose(TextTrackSettings, _ModalDialog);
  16368. /**
  16369. * Creates an instance of this class.
  16370. *
  16371. * @param {Player} player
  16372. * The `Player` that this class should be attached to.
  16373. *
  16374. * @param {Object} [options]
  16375. * The key/value store of player options.
  16376. */
  16377. function TextTrackSettings(player, options) {
  16378. var _this;
  16379. options.temporary = false;
  16380. _this = _ModalDialog.call(this, player, options) || this;
  16381. _this.updateDisplay = _this.updateDisplay.bind(assertThisInitialized(_this)); // fill the modal and pretend we have opened it
  16382. _this.fill();
  16383. _this.hasBeenOpened_ = _this.hasBeenFilled_ = true;
  16384. _this.endDialog = createEl('p', {
  16385. className: 'vjs-control-text',
  16386. textContent: _this.localize('End of dialog window.')
  16387. });
  16388. _this.el().appendChild(_this.endDialog);
  16389. _this.setDefaults(); // Grab `persistTextTrackSettings` from the player options if not passed in child options
  16390. if (options.persistTextTrackSettings === undefined) {
  16391. _this.options_.persistTextTrackSettings = _this.options_.playerOptions.persistTextTrackSettings;
  16392. }
  16393. _this.on(_this.$('.vjs-done-button'), 'click', function () {
  16394. _this.saveSettings();
  16395. _this.close();
  16396. });
  16397. _this.on(_this.$('.vjs-default-button'), 'click', function () {
  16398. _this.setDefaults();
  16399. _this.updateDisplay();
  16400. });
  16401. each(selectConfigs, function (config) {
  16402. _this.on(_this.$(config.selector), 'change', _this.updateDisplay);
  16403. });
  16404. if (_this.options_.persistTextTrackSettings) {
  16405. _this.restoreSettings();
  16406. }
  16407. return _this;
  16408. }
  16409. var _proto = TextTrackSettings.prototype;
  16410. _proto.dispose = function dispose() {
  16411. this.endDialog = null;
  16412. _ModalDialog.prototype.dispose.call(this);
  16413. }
  16414. /**
  16415. * Create a <select> element with configured options.
  16416. *
  16417. * @param {string} key
  16418. * Configuration key to use during creation.
  16419. *
  16420. * @return {string}
  16421. * An HTML string.
  16422. *
  16423. * @private
  16424. */
  16425. ;
  16426. _proto.createElSelect_ = function createElSelect_(key, legendId, type) {
  16427. var _this2 = this;
  16428. if (legendId === void 0) {
  16429. legendId = '';
  16430. }
  16431. if (type === void 0) {
  16432. type = 'label';
  16433. }
  16434. var config = selectConfigs[key];
  16435. var id = config.id.replace('%s', this.id_);
  16436. var selectLabelledbyIds = [legendId, id].join(' ').trim();
  16437. return ["<" + type + " id=\"" + id + "\" class=\"" + (type === 'label' ? 'vjs-label' : '') + "\">", this.localize(config.label), "</" + type + ">", "<select aria-labelledby=\"" + selectLabelledbyIds + "\">"].concat(config.options.map(function (o) {
  16438. var optionId = id + '-' + o[1].replace(/\W+/g, '');
  16439. return ["<option id=\"" + optionId + "\" value=\"" + o[0] + "\" ", "aria-labelledby=\"" + selectLabelledbyIds + " " + optionId + "\">", _this2.localize(o[1]), '</option>'].join('');
  16440. })).concat('</select>').join('');
  16441. }
  16442. /**
  16443. * Create foreground color element for the component
  16444. *
  16445. * @return {string}
  16446. * An HTML string.
  16447. *
  16448. * @private
  16449. */
  16450. ;
  16451. _proto.createElFgColor_ = function createElFgColor_() {
  16452. var legendId = "captions-text-legend-" + this.id_;
  16453. return ['<fieldset class="vjs-fg-color vjs-track-setting">', "<legend id=\"" + legendId + "\">", this.localize('Text'), '</legend>', this.createElSelect_('color', legendId), '<span class="vjs-text-opacity vjs-opacity">', this.createElSelect_('textOpacity', legendId), '</span>', '</fieldset>'].join('');
  16454. }
  16455. /**
  16456. * Create background color element for the component
  16457. *
  16458. * @return {string}
  16459. * An HTML string.
  16460. *
  16461. * @private
  16462. */
  16463. ;
  16464. _proto.createElBgColor_ = function createElBgColor_() {
  16465. var legendId = "captions-background-" + this.id_;
  16466. return ['<fieldset class="vjs-bg-color vjs-track-setting">', "<legend id=\"" + legendId + "\">", this.localize('Background'), '</legend>', this.createElSelect_('backgroundColor', legendId), '<span class="vjs-bg-opacity vjs-opacity">', this.createElSelect_('backgroundOpacity', legendId), '</span>', '</fieldset>'].join('');
  16467. }
  16468. /**
  16469. * Create window color element for the component
  16470. *
  16471. * @return {string}
  16472. * An HTML string.
  16473. *
  16474. * @private
  16475. */
  16476. ;
  16477. _proto.createElWinColor_ = function createElWinColor_() {
  16478. var legendId = "captions-window-" + this.id_;
  16479. return ['<fieldset class="vjs-window-color vjs-track-setting">', "<legend id=\"" + legendId + "\">", this.localize('Window'), '</legend>', this.createElSelect_('windowColor', legendId), '<span class="vjs-window-opacity vjs-opacity">', this.createElSelect_('windowOpacity', legendId), '</span>', '</fieldset>'].join('');
  16480. }
  16481. /**
  16482. * Create color elements for the component
  16483. *
  16484. * @return {Element}
  16485. * The element that was created
  16486. *
  16487. * @private
  16488. */
  16489. ;
  16490. _proto.createElColors_ = function createElColors_() {
  16491. return createEl('div', {
  16492. className: 'vjs-track-settings-colors',
  16493. innerHTML: [this.createElFgColor_(), this.createElBgColor_(), this.createElWinColor_()].join('')
  16494. });
  16495. }
  16496. /**
  16497. * Create font elements for the component
  16498. *
  16499. * @return {Element}
  16500. * The element that was created.
  16501. *
  16502. * @private
  16503. */
  16504. ;
  16505. _proto.createElFont_ = function createElFont_() {
  16506. return createEl('div', {
  16507. className: 'vjs-track-settings-font',
  16508. innerHTML: ['<fieldset class="vjs-font-percent vjs-track-setting">', this.createElSelect_('fontPercent', '', 'legend'), '</fieldset>', '<fieldset class="vjs-edge-style vjs-track-setting">', this.createElSelect_('edgeStyle', '', 'legend'), '</fieldset>', '<fieldset class="vjs-font-family vjs-track-setting">', this.createElSelect_('fontFamily', '', 'legend'), '</fieldset>'].join('')
  16509. });
  16510. }
  16511. /**
  16512. * Create controls for the component
  16513. *
  16514. * @return {Element}
  16515. * The element that was created.
  16516. *
  16517. * @private
  16518. */
  16519. ;
  16520. _proto.createElControls_ = function createElControls_() {
  16521. var defaultsDescription = this.localize('restore all settings to the default values');
  16522. return createEl('div', {
  16523. className: 'vjs-track-settings-controls',
  16524. innerHTML: ["<button type=\"button\" class=\"vjs-default-button\" title=\"" + defaultsDescription + "\">", this.localize('Reset'), "<span class=\"vjs-control-text\"> " + defaultsDescription + "</span>", '</button>', "<button type=\"button\" class=\"vjs-done-button\">" + this.localize('Done') + "</button>"].join('')
  16525. });
  16526. };
  16527. _proto.content = function content() {
  16528. return [this.createElColors_(), this.createElFont_(), this.createElControls_()];
  16529. };
  16530. _proto.label = function label() {
  16531. return this.localize('Caption Settings Dialog');
  16532. };
  16533. _proto.description = function description() {
  16534. return this.localize('Beginning of dialog window. Escape will cancel and close the window.');
  16535. };
  16536. _proto.buildCSSClass = function buildCSSClass() {
  16537. return _ModalDialog.prototype.buildCSSClass.call(this) + ' vjs-text-track-settings';
  16538. }
  16539. /**
  16540. * Gets an object of text track settings (or null).
  16541. *
  16542. * @return {Object}
  16543. * An object with config values parsed from the DOM or localStorage.
  16544. */
  16545. ;
  16546. _proto.getValues = function getValues() {
  16547. var _this3 = this;
  16548. return reduce(selectConfigs, function (accum, config, key) {
  16549. var value = getSelectedOptionValue(_this3.$(config.selector), config.parser);
  16550. if (value !== undefined) {
  16551. accum[key] = value;
  16552. }
  16553. return accum;
  16554. }, {});
  16555. }
  16556. /**
  16557. * Sets text track settings from an object of values.
  16558. *
  16559. * @param {Object} values
  16560. * An object with config values parsed from the DOM or localStorage.
  16561. */
  16562. ;
  16563. _proto.setValues = function setValues(values) {
  16564. var _this4 = this;
  16565. each(selectConfigs, function (config, key) {
  16566. setSelectedOption(_this4.$(config.selector), values[key], config.parser);
  16567. });
  16568. }
  16569. /**
  16570. * Sets all `<select>` elements to their default values.
  16571. */
  16572. ;
  16573. _proto.setDefaults = function setDefaults() {
  16574. var _this5 = this;
  16575. each(selectConfigs, function (config) {
  16576. var index = config.hasOwnProperty('default') ? config["default"] : 0;
  16577. _this5.$(config.selector).selectedIndex = index;
  16578. });
  16579. }
  16580. /**
  16581. * Restore texttrack settings from localStorage
  16582. */
  16583. ;
  16584. _proto.restoreSettings = function restoreSettings() {
  16585. var values;
  16586. try {
  16587. values = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY));
  16588. } catch (err) {
  16589. log.warn(err);
  16590. }
  16591. if (values) {
  16592. this.setValues(values);
  16593. }
  16594. }
  16595. /**
  16596. * Save text track settings to localStorage
  16597. */
  16598. ;
  16599. _proto.saveSettings = function saveSettings() {
  16600. if (!this.options_.persistTextTrackSettings) {
  16601. return;
  16602. }
  16603. var values = this.getValues();
  16604. try {
  16605. if (Object.keys(values).length) {
  16606. window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(values));
  16607. } else {
  16608. window.localStorage.removeItem(LOCAL_STORAGE_KEY);
  16609. }
  16610. } catch (err) {
  16611. log.warn(err);
  16612. }
  16613. }
  16614. /**
  16615. * Update display of text track settings
  16616. */
  16617. ;
  16618. _proto.updateDisplay = function updateDisplay() {
  16619. var ttDisplay = this.player_.getChild('textTrackDisplay');
  16620. if (ttDisplay) {
  16621. ttDisplay.updateDisplay();
  16622. }
  16623. }
  16624. /**
  16625. * conditionally blur the element and refocus the captions button
  16626. *
  16627. * @private
  16628. */
  16629. ;
  16630. _proto.conditionalBlur_ = function conditionalBlur_() {
  16631. this.previouslyActiveEl_ = null;
  16632. var cb = this.player_.controlBar;
  16633. var subsCapsBtn = cb && cb.subsCapsButton;
  16634. var ccBtn = cb && cb.captionsButton;
  16635. if (subsCapsBtn) {
  16636. subsCapsBtn.focus();
  16637. } else if (ccBtn) {
  16638. ccBtn.focus();
  16639. }
  16640. };
  16641. return TextTrackSettings;
  16642. }(ModalDialog);
  16643. Component.registerComponent('TextTrackSettings', TextTrackSettings);
  16644. /**
  16645. * A Resize Manager. It is in charge of triggering `playerresize` on the player in the right conditions.
  16646. *
  16647. * It'll either create an iframe and use a debounced resize handler on it or use the new {@link https://wicg.github.io/ResizeObserver/|ResizeObserver}.
  16648. *
  16649. * If the ResizeObserver is available natively, it will be used. A polyfill can be passed in as an option.
  16650. * If a `playerresize` event is not needed, the ResizeManager component can be removed from the player, see the example below.
  16651. * @example <caption>How to disable the resize manager</caption>
  16652. * const player = videojs('#vid', {
  16653. * resizeManager: false
  16654. * });
  16655. *
  16656. * @see {@link https://wicg.github.io/ResizeObserver/|ResizeObserver specification}
  16657. *
  16658. * @extends Component
  16659. */
  16660. var ResizeManager = /*#__PURE__*/function (_Component) {
  16661. inheritsLoose(ResizeManager, _Component);
  16662. /**
  16663. * Create the ResizeManager.
  16664. *
  16665. * @param {Object} player
  16666. * The `Player` that this class should be attached to.
  16667. *
  16668. * @param {Object} [options]
  16669. * The key/value store of ResizeManager options.
  16670. *
  16671. * @param {Object} [options.ResizeObserver]
  16672. * A polyfill for ResizeObserver can be passed in here.
  16673. * If this is set to null it will ignore the native ResizeObserver and fall back to the iframe fallback.
  16674. */
  16675. function ResizeManager(player, options) {
  16676. var _this;
  16677. var RESIZE_OBSERVER_AVAILABLE = options.ResizeObserver || window.ResizeObserver; // if `null` was passed, we want to disable the ResizeObserver
  16678. if (options.ResizeObserver === null) {
  16679. RESIZE_OBSERVER_AVAILABLE = false;
  16680. } // Only create an element when ResizeObserver isn't available
  16681. var options_ = mergeOptions({
  16682. createEl: !RESIZE_OBSERVER_AVAILABLE,
  16683. reportTouchActivity: false
  16684. }, options);
  16685. _this = _Component.call(this, player, options_) || this;
  16686. _this.ResizeObserver = options.ResizeObserver || window.ResizeObserver;
  16687. _this.loadListener_ = null;
  16688. _this.resizeObserver_ = null;
  16689. _this.debouncedHandler_ = debounce(function () {
  16690. _this.resizeHandler();
  16691. }, 100, false, assertThisInitialized(_this));
  16692. if (RESIZE_OBSERVER_AVAILABLE) {
  16693. _this.resizeObserver_ = new _this.ResizeObserver(_this.debouncedHandler_);
  16694. _this.resizeObserver_.observe(player.el());
  16695. } else {
  16696. _this.loadListener_ = function () {
  16697. if (!_this.el_ || !_this.el_.contentWindow) {
  16698. return;
  16699. }
  16700. var debouncedHandler_ = _this.debouncedHandler_;
  16701. var unloadListener_ = _this.unloadListener_ = function () {
  16702. off(this, 'resize', debouncedHandler_);
  16703. off(this, 'unload', unloadListener_);
  16704. unloadListener_ = null;
  16705. }; // safari and edge can unload the iframe before resizemanager dispose
  16706. // we have to dispose of event handlers correctly before that happens
  16707. on(_this.el_.contentWindow, 'unload', unloadListener_);
  16708. on(_this.el_.contentWindow, 'resize', debouncedHandler_);
  16709. };
  16710. _this.one('load', _this.loadListener_);
  16711. }
  16712. return _this;
  16713. }
  16714. var _proto = ResizeManager.prototype;
  16715. _proto.createEl = function createEl() {
  16716. return _Component.prototype.createEl.call(this, 'iframe', {
  16717. className: 'vjs-resize-manager',
  16718. tabIndex: -1,
  16719. title: this.localize('No content')
  16720. }, {
  16721. 'aria-hidden': 'true'
  16722. });
  16723. }
  16724. /**
  16725. * Called when a resize is triggered on the iframe or a resize is observed via the ResizeObserver
  16726. *
  16727. * @fires Player#playerresize
  16728. */
  16729. ;
  16730. _proto.resizeHandler = function resizeHandler() {
  16731. /**
  16732. * Called when the player size has changed
  16733. *
  16734. * @event Player#playerresize
  16735. * @type {EventTarget~Event}
  16736. */
  16737. // make sure player is still around to trigger
  16738. // prevents this from causing an error after dispose
  16739. if (!this.player_ || !this.player_.trigger) {
  16740. return;
  16741. }
  16742. this.player_.trigger('playerresize');
  16743. };
  16744. _proto.dispose = function dispose() {
  16745. if (this.debouncedHandler_) {
  16746. this.debouncedHandler_.cancel();
  16747. }
  16748. if (this.resizeObserver_) {
  16749. if (this.player_.el()) {
  16750. this.resizeObserver_.unobserve(this.player_.el());
  16751. }
  16752. this.resizeObserver_.disconnect();
  16753. }
  16754. if (this.loadListener_) {
  16755. this.off('load', this.loadListener_);
  16756. }
  16757. if (this.el_ && this.el_.contentWindow && this.unloadListener_) {
  16758. this.unloadListener_.call(this.el_.contentWindow);
  16759. }
  16760. this.ResizeObserver = null;
  16761. this.resizeObserver = null;
  16762. this.debouncedHandler_ = null;
  16763. this.loadListener_ = null;
  16764. _Component.prototype.dispose.call(this);
  16765. };
  16766. return ResizeManager;
  16767. }(Component);
  16768. Component.registerComponent('ResizeManager', ResizeManager);
  16769. var defaults = {
  16770. trackingThreshold: 20,
  16771. liveTolerance: 15
  16772. };
  16773. /*
  16774. track when we are at the live edge, and other helpers for live playback */
  16775. /**
  16776. * A class for checking live current time and determining when the player
  16777. * is at or behind the live edge.
  16778. */
  16779. var LiveTracker = /*#__PURE__*/function (_Component) {
  16780. inheritsLoose(LiveTracker, _Component);
  16781. /**
  16782. * Creates an instance of this class.
  16783. *
  16784. * @param {Player} player
  16785. * The `Player` that this class should be attached to.
  16786. *
  16787. * @param {Object} [options]
  16788. * The key/value store of player options.
  16789. *
  16790. * @param {number} [options.trackingThreshold=20]
  16791. * Number of seconds of live window (seekableEnd - seekableStart) that
  16792. * media needs to have before the liveui will be shown.
  16793. *
  16794. * @param {number} [options.liveTolerance=15]
  16795. * Number of seconds behind live that we have to be
  16796. * before we will be considered non-live. Note that this will only
  16797. * be used when playing at the live edge. This allows large seekable end
  16798. * changes to not effect wether we are live or not.
  16799. */
  16800. function LiveTracker(player, options) {
  16801. var _this;
  16802. // LiveTracker does not need an element
  16803. var options_ = mergeOptions(defaults, options, {
  16804. createEl: false
  16805. });
  16806. _this = _Component.call(this, player, options_) || this;
  16807. _this.handleVisibilityChange_ = function (e) {
  16808. return _this.handleVisibilityChange(e);
  16809. };
  16810. _this.trackLiveHandler_ = function () {
  16811. return _this.trackLive_();
  16812. };
  16813. _this.handlePlay_ = function (e) {
  16814. return _this.handlePlay(e);
  16815. };
  16816. _this.handleFirstTimeupdate_ = function (e) {
  16817. return _this.handleFirstTimeupdate(e);
  16818. };
  16819. _this.handleSeeked_ = function (e) {
  16820. return _this.handleSeeked(e);
  16821. };
  16822. _this.seekToLiveEdge_ = function (e) {
  16823. return _this.seekToLiveEdge(e);
  16824. };
  16825. _this.reset_();
  16826. _this.on(_this.player_, 'durationchange', function (e) {
  16827. return _this.handleDurationchange(e);
  16828. }); // we should try to toggle tracking on canplay as native playback engines, like Safari
  16829. // may not have the proper values for things like seekableEnd until then
  16830. _this.on(_this.player_, 'canplay', function () {
  16831. return _this.toggleTracking();
  16832. }); // we don't need to track live playback if the document is hidden,
  16833. // also, tracking when the document is hidden can
  16834. // cause the CPU to spike and eventually crash the page on IE11.
  16835. if (IE_VERSION && 'hidden' in document && 'visibilityState' in document) {
  16836. _this.on(document, 'visibilitychange', _this.handleVisibilityChange_);
  16837. }
  16838. return _this;
  16839. }
  16840. /**
  16841. * toggle tracking based on document visiblility
  16842. */
  16843. var _proto = LiveTracker.prototype;
  16844. _proto.handleVisibilityChange = function handleVisibilityChange() {
  16845. if (this.player_.duration() !== Infinity) {
  16846. return;
  16847. }
  16848. if (document.hidden) {
  16849. this.stopTracking();
  16850. } else {
  16851. this.startTracking();
  16852. }
  16853. }
  16854. /**
  16855. * all the functionality for tracking when seek end changes
  16856. * and for tracking how far past seek end we should be
  16857. */
  16858. ;
  16859. _proto.trackLive_ = function trackLive_() {
  16860. var seekable = this.player_.seekable(); // skip undefined seekable
  16861. if (!seekable || !seekable.length) {
  16862. return;
  16863. }
  16864. var newTime = Number(window.performance.now().toFixed(4));
  16865. var deltaTime = this.lastTime_ === -1 ? 0 : (newTime - this.lastTime_) / 1000;
  16866. this.lastTime_ = newTime;
  16867. this.pastSeekEnd_ = this.pastSeekEnd() + deltaTime;
  16868. var liveCurrentTime = this.liveCurrentTime();
  16869. var currentTime = this.player_.currentTime(); // we are behind live if any are true
  16870. // 1. the player is paused
  16871. // 2. the user seeked to a location 2 seconds away from live
  16872. // 3. the difference between live and current time is greater
  16873. // liveTolerance which defaults to 15s
  16874. var isBehind = this.player_.paused() || this.seekedBehindLive_ || Math.abs(liveCurrentTime - currentTime) > this.options_.liveTolerance; // we cannot be behind if
  16875. // 1. until we have not seen a timeupdate yet
  16876. // 2. liveCurrentTime is Infinity, which happens on Android and Native Safari
  16877. if (!this.timeupdateSeen_ || liveCurrentTime === Infinity) {
  16878. isBehind = false;
  16879. }
  16880. if (isBehind !== this.behindLiveEdge_) {
  16881. this.behindLiveEdge_ = isBehind;
  16882. this.trigger('liveedgechange');
  16883. }
  16884. }
  16885. /**
  16886. * handle a durationchange event on the player
  16887. * and start/stop tracking accordingly.
  16888. */
  16889. ;
  16890. _proto.handleDurationchange = function handleDurationchange() {
  16891. this.toggleTracking();
  16892. }
  16893. /**
  16894. * start/stop tracking
  16895. */
  16896. ;
  16897. _proto.toggleTracking = function toggleTracking() {
  16898. if (this.player_.duration() === Infinity && this.liveWindow() >= this.options_.trackingThreshold) {
  16899. if (this.player_.options_.liveui) {
  16900. this.player_.addClass('vjs-liveui');
  16901. }
  16902. this.startTracking();
  16903. } else {
  16904. this.player_.removeClass('vjs-liveui');
  16905. this.stopTracking();
  16906. }
  16907. }
  16908. /**
  16909. * start tracking live playback
  16910. */
  16911. ;
  16912. _proto.startTracking = function startTracking() {
  16913. if (this.isTracking()) {
  16914. return;
  16915. } // If we haven't seen a timeupdate, we need to check whether playback
  16916. // began before this component started tracking. This can happen commonly
  16917. // when using autoplay.
  16918. if (!this.timeupdateSeen_) {
  16919. this.timeupdateSeen_ = this.player_.hasStarted();
  16920. }
  16921. this.trackingInterval_ = this.setInterval(this.trackLiveHandler_, UPDATE_REFRESH_INTERVAL);
  16922. this.trackLive_();
  16923. this.on(this.player_, ['play', 'pause'], this.trackLiveHandler_);
  16924. if (!this.timeupdateSeen_) {
  16925. this.one(this.player_, 'play', this.handlePlay_);
  16926. this.one(this.player_, 'timeupdate', this.handleFirstTimeupdate_);
  16927. } else {
  16928. this.on(this.player_, 'seeked', this.handleSeeked_);
  16929. }
  16930. }
  16931. /**
  16932. * handle the first timeupdate on the player if it wasn't already playing
  16933. * when live tracker started tracking.
  16934. */
  16935. ;
  16936. _proto.handleFirstTimeupdate = function handleFirstTimeupdate() {
  16937. this.timeupdateSeen_ = true;
  16938. this.on(this.player_, 'seeked', this.handleSeeked_);
  16939. }
  16940. /**
  16941. * Keep track of what time a seek starts, and listen for seeked
  16942. * to find where a seek ends.
  16943. */
  16944. ;
  16945. _proto.handleSeeked = function handleSeeked() {
  16946. var timeDiff = Math.abs(this.liveCurrentTime() - this.player_.currentTime());
  16947. this.seekedBehindLive_ = this.nextSeekedFromUser_ && timeDiff > 2;
  16948. this.nextSeekedFromUser_ = false;
  16949. this.trackLive_();
  16950. }
  16951. /**
  16952. * handle the first play on the player, and make sure that we seek
  16953. * right to the live edge.
  16954. */
  16955. ;
  16956. _proto.handlePlay = function handlePlay() {
  16957. this.one(this.player_, 'timeupdate', this.seekToLiveEdge_);
  16958. }
  16959. /**
  16960. * Stop tracking, and set all internal variables to
  16961. * their initial value.
  16962. */
  16963. ;
  16964. _proto.reset_ = function reset_() {
  16965. this.lastTime_ = -1;
  16966. this.pastSeekEnd_ = 0;
  16967. this.lastSeekEnd_ = -1;
  16968. this.behindLiveEdge_ = true;
  16969. this.timeupdateSeen_ = false;
  16970. this.seekedBehindLive_ = false;
  16971. this.nextSeekedFromUser_ = false;
  16972. this.clearInterval(this.trackingInterval_);
  16973. this.trackingInterval_ = null;
  16974. this.off(this.player_, ['play', 'pause'], this.trackLiveHandler_);
  16975. this.off(this.player_, 'seeked', this.handleSeeked_);
  16976. this.off(this.player_, 'play', this.handlePlay_);
  16977. this.off(this.player_, 'timeupdate', this.handleFirstTimeupdate_);
  16978. this.off(this.player_, 'timeupdate', this.seekToLiveEdge_);
  16979. }
  16980. /**
  16981. * The next seeked event is from the user. Meaning that any seek
  16982. * > 2s behind live will be considered behind live for real and
  16983. * liveTolerance will be ignored.
  16984. */
  16985. ;
  16986. _proto.nextSeekedFromUser = function nextSeekedFromUser() {
  16987. this.nextSeekedFromUser_ = true;
  16988. }
  16989. /**
  16990. * stop tracking live playback
  16991. */
  16992. ;
  16993. _proto.stopTracking = function stopTracking() {
  16994. if (!this.isTracking()) {
  16995. return;
  16996. }
  16997. this.reset_();
  16998. this.trigger('liveedgechange');
  16999. }
  17000. /**
  17001. * A helper to get the player seekable end
  17002. * so that we don't have to null check everywhere
  17003. *
  17004. * @return {number}
  17005. * The furthest seekable end or Infinity.
  17006. */
  17007. ;
  17008. _proto.seekableEnd = function seekableEnd() {
  17009. var seekable = this.player_.seekable();
  17010. var seekableEnds = [];
  17011. var i = seekable ? seekable.length : 0;
  17012. while (i--) {
  17013. seekableEnds.push(seekable.end(i));
  17014. } // grab the furthest seekable end after sorting, or if there are none
  17015. // default to Infinity
  17016. return seekableEnds.length ? seekableEnds.sort()[seekableEnds.length - 1] : Infinity;
  17017. }
  17018. /**
  17019. * A helper to get the player seekable start
  17020. * so that we don't have to null check everywhere
  17021. *
  17022. * @return {number}
  17023. * The earliest seekable start or 0.
  17024. */
  17025. ;
  17026. _proto.seekableStart = function seekableStart() {
  17027. var seekable = this.player_.seekable();
  17028. var seekableStarts = [];
  17029. var i = seekable ? seekable.length : 0;
  17030. while (i--) {
  17031. seekableStarts.push(seekable.start(i));
  17032. } // grab the first seekable start after sorting, or if there are none
  17033. // default to 0
  17034. return seekableStarts.length ? seekableStarts.sort()[0] : 0;
  17035. }
  17036. /**
  17037. * Get the live time window aka
  17038. * the amount of time between seekable start and
  17039. * live current time.
  17040. *
  17041. * @return {number}
  17042. * The amount of seconds that are seekable in
  17043. * the live video.
  17044. */
  17045. ;
  17046. _proto.liveWindow = function liveWindow() {
  17047. var liveCurrentTime = this.liveCurrentTime(); // if liveCurrenTime is Infinity then we don't have a liveWindow at all
  17048. if (liveCurrentTime === Infinity) {
  17049. return 0;
  17050. }
  17051. return liveCurrentTime - this.seekableStart();
  17052. }
  17053. /**
  17054. * Determines if the player is live, only checks if this component
  17055. * is tracking live playback or not
  17056. *
  17057. * @return {boolean}
  17058. * Wether liveTracker is tracking
  17059. */
  17060. ;
  17061. _proto.isLive = function isLive() {
  17062. return this.isTracking();
  17063. }
  17064. /**
  17065. * Determines if currentTime is at the live edge and won't fall behind
  17066. * on each seekableendchange
  17067. *
  17068. * @return {boolean}
  17069. * Wether playback is at the live edge
  17070. */
  17071. ;
  17072. _proto.atLiveEdge = function atLiveEdge() {
  17073. return !this.behindLiveEdge();
  17074. }
  17075. /**
  17076. * get what we expect the live current time to be
  17077. *
  17078. * @return {number}
  17079. * The expected live current time
  17080. */
  17081. ;
  17082. _proto.liveCurrentTime = function liveCurrentTime() {
  17083. return this.pastSeekEnd() + this.seekableEnd();
  17084. }
  17085. /**
  17086. * The number of seconds that have occured after seekable end
  17087. * changed. This will be reset to 0 once seekable end changes.
  17088. *
  17089. * @return {number}
  17090. * Seconds past the current seekable end
  17091. */
  17092. ;
  17093. _proto.pastSeekEnd = function pastSeekEnd() {
  17094. var seekableEnd = this.seekableEnd();
  17095. if (this.lastSeekEnd_ !== -1 && seekableEnd !== this.lastSeekEnd_) {
  17096. this.pastSeekEnd_ = 0;
  17097. }
  17098. this.lastSeekEnd_ = seekableEnd;
  17099. return this.pastSeekEnd_;
  17100. }
  17101. /**
  17102. * If we are currently behind the live edge, aka currentTime will be
  17103. * behind on a seekableendchange
  17104. *
  17105. * @return {boolean}
  17106. * If we are behind the live edge
  17107. */
  17108. ;
  17109. _proto.behindLiveEdge = function behindLiveEdge() {
  17110. return this.behindLiveEdge_;
  17111. }
  17112. /**
  17113. * Wether live tracker is currently tracking or not.
  17114. */
  17115. ;
  17116. _proto.isTracking = function isTracking() {
  17117. return typeof this.trackingInterval_ === 'number';
  17118. }
  17119. /**
  17120. * Seek to the live edge if we are behind the live edge
  17121. */
  17122. ;
  17123. _proto.seekToLiveEdge = function seekToLiveEdge() {
  17124. this.seekedBehindLive_ = false;
  17125. if (this.atLiveEdge()) {
  17126. return;
  17127. }
  17128. this.nextSeekedFromUser_ = false;
  17129. this.player_.currentTime(this.liveCurrentTime());
  17130. }
  17131. /**
  17132. * Dispose of liveTracker
  17133. */
  17134. ;
  17135. _proto.dispose = function dispose() {
  17136. this.off(document, 'visibilitychange', this.handleVisibilityChange_);
  17137. this.stopTracking();
  17138. _Component.prototype.dispose.call(this);
  17139. };
  17140. return LiveTracker;
  17141. }(Component);
  17142. Component.registerComponent('LiveTracker', LiveTracker);
  17143. /**
  17144. * This function is used to fire a sourceset when there is something
  17145. * similar to `mediaEl.load()` being called. It will try to find the source via
  17146. * the `src` attribute and then the `<source>` elements. It will then fire `sourceset`
  17147. * with the source that was found or empty string if we cannot know. If it cannot
  17148. * find a source then `sourceset` will not be fired.
  17149. *
  17150. * @param {Html5} tech
  17151. * The tech object that sourceset was setup on
  17152. *
  17153. * @return {boolean}
  17154. * returns false if the sourceset was not fired and true otherwise.
  17155. */
  17156. var sourcesetLoad = function sourcesetLoad(tech) {
  17157. var el = tech.el(); // if `el.src` is set, that source will be loaded.
  17158. if (el.hasAttribute('src')) {
  17159. tech.triggerSourceset(el.src);
  17160. return true;
  17161. }
  17162. /**
  17163. * Since there isn't a src property on the media element, source elements will be used for
  17164. * implementing the source selection algorithm. This happens asynchronously and
  17165. * for most cases were there is more than one source we cannot tell what source will
  17166. * be loaded, without re-implementing the source selection algorithm. At this time we are not
  17167. * going to do that. There are three special cases that we do handle here though:
  17168. *
  17169. * 1. If there are no sources, do not fire `sourceset`.
  17170. * 2. If there is only one `<source>` with a `src` property/attribute that is our `src`
  17171. * 3. If there is more than one `<source>` but all of them have the same `src` url.
  17172. * That will be our src.
  17173. */
  17174. var sources = tech.$$('source');
  17175. var srcUrls = [];
  17176. var src = ''; // if there are no sources, do not fire sourceset
  17177. if (!sources.length) {
  17178. return false;
  17179. } // only count valid/non-duplicate source elements
  17180. for (var i = 0; i < sources.length; i++) {
  17181. var url = sources[i].src;
  17182. if (url && srcUrls.indexOf(url) === -1) {
  17183. srcUrls.push(url);
  17184. }
  17185. } // there were no valid sources
  17186. if (!srcUrls.length) {
  17187. return false;
  17188. } // there is only one valid source element url
  17189. // use that
  17190. if (srcUrls.length === 1) {
  17191. src = srcUrls[0];
  17192. }
  17193. tech.triggerSourceset(src);
  17194. return true;
  17195. };
  17196. /**
  17197. * our implementation of an `innerHTML` descriptor for browsers
  17198. * that do not have one.
  17199. */
  17200. var innerHTMLDescriptorPolyfill = Object.defineProperty({}, 'innerHTML', {
  17201. get: function get() {
  17202. return this.cloneNode(true).innerHTML;
  17203. },
  17204. set: function set(v) {
  17205. // make a dummy node to use innerHTML on
  17206. var dummy = document.createElement(this.nodeName.toLowerCase()); // set innerHTML to the value provided
  17207. dummy.innerHTML = v; // make a document fragment to hold the nodes from dummy
  17208. var docFrag = document.createDocumentFragment(); // copy all of the nodes created by the innerHTML on dummy
  17209. // to the document fragment
  17210. while (dummy.childNodes.length) {
  17211. docFrag.appendChild(dummy.childNodes[0]);
  17212. } // remove content
  17213. this.innerText = ''; // now we add all of that html in one by appending the
  17214. // document fragment. This is how innerHTML does it.
  17215. window.Element.prototype.appendChild.call(this, docFrag); // then return the result that innerHTML's setter would
  17216. return this.innerHTML;
  17217. }
  17218. });
  17219. /**
  17220. * Get a property descriptor given a list of priorities and the
  17221. * property to get.
  17222. */
  17223. var getDescriptor = function getDescriptor(priority, prop) {
  17224. var descriptor = {};
  17225. for (var i = 0; i < priority.length; i++) {
  17226. descriptor = Object.getOwnPropertyDescriptor(priority[i], prop);
  17227. if (descriptor && descriptor.set && descriptor.get) {
  17228. break;
  17229. }
  17230. }
  17231. descriptor.enumerable = true;
  17232. descriptor.configurable = true;
  17233. return descriptor;
  17234. };
  17235. var getInnerHTMLDescriptor = function getInnerHTMLDescriptor(tech) {
  17236. return getDescriptor([tech.el(), window.HTMLMediaElement.prototype, window.Element.prototype, innerHTMLDescriptorPolyfill], 'innerHTML');
  17237. };
  17238. /**
  17239. * Patches browser internal functions so that we can tell synchronously
  17240. * if a `<source>` was appended to the media element. For some reason this
  17241. * causes a `sourceset` if the the media element is ready and has no source.
  17242. * This happens when:
  17243. * - The page has just loaded and the media element does not have a source.
  17244. * - The media element was emptied of all sources, then `load()` was called.
  17245. *
  17246. * It does this by patching the following functions/properties when they are supported:
  17247. *
  17248. * - `append()` - can be used to add a `<source>` element to the media element
  17249. * - `appendChild()` - can be used to add a `<source>` element to the media element
  17250. * - `insertAdjacentHTML()` - can be used to add a `<source>` element to the media element
  17251. * - `innerHTML` - can be used to add a `<source>` element to the media element
  17252. *
  17253. * @param {Html5} tech
  17254. * The tech object that sourceset is being setup on.
  17255. */
  17256. var firstSourceWatch = function firstSourceWatch(tech) {
  17257. var el = tech.el(); // make sure firstSourceWatch isn't setup twice.
  17258. if (el.resetSourceWatch_) {
  17259. return;
  17260. }
  17261. var old = {};
  17262. var innerDescriptor = getInnerHTMLDescriptor(tech);
  17263. var appendWrapper = function appendWrapper(appendFn) {
  17264. return function () {
  17265. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  17266. args[_key] = arguments[_key];
  17267. }
  17268. var retval = appendFn.apply(el, args);
  17269. sourcesetLoad(tech);
  17270. return retval;
  17271. };
  17272. };
  17273. ['append', 'appendChild', 'insertAdjacentHTML'].forEach(function (k) {
  17274. if (!el[k]) {
  17275. return;
  17276. } // store the old function
  17277. old[k] = el[k]; // call the old function with a sourceset if a source
  17278. // was loaded
  17279. el[k] = appendWrapper(old[k]);
  17280. });
  17281. Object.defineProperty(el, 'innerHTML', mergeOptions(innerDescriptor, {
  17282. set: appendWrapper(innerDescriptor.set)
  17283. }));
  17284. el.resetSourceWatch_ = function () {
  17285. el.resetSourceWatch_ = null;
  17286. Object.keys(old).forEach(function (k) {
  17287. el[k] = old[k];
  17288. });
  17289. Object.defineProperty(el, 'innerHTML', innerDescriptor);
  17290. }; // on the first sourceset, we need to revert our changes
  17291. tech.one('sourceset', el.resetSourceWatch_);
  17292. };
  17293. /**
  17294. * our implementation of a `src` descriptor for browsers
  17295. * that do not have one.
  17296. */
  17297. var srcDescriptorPolyfill = Object.defineProperty({}, 'src', {
  17298. get: function get() {
  17299. if (this.hasAttribute('src')) {
  17300. return getAbsoluteURL(window.Element.prototype.getAttribute.call(this, 'src'));
  17301. }
  17302. return '';
  17303. },
  17304. set: function set(v) {
  17305. window.Element.prototype.setAttribute.call(this, 'src', v);
  17306. return v;
  17307. }
  17308. });
  17309. var getSrcDescriptor = function getSrcDescriptor(tech) {
  17310. return getDescriptor([tech.el(), window.HTMLMediaElement.prototype, srcDescriptorPolyfill], 'src');
  17311. };
  17312. /**
  17313. * setup `sourceset` handling on the `Html5` tech. This function
  17314. * patches the following element properties/functions:
  17315. *
  17316. * - `src` - to determine when `src` is set
  17317. * - `setAttribute()` - to determine when `src` is set
  17318. * - `load()` - this re-triggers the source selection algorithm, and can
  17319. * cause a sourceset.
  17320. *
  17321. * If there is no source when we are adding `sourceset` support or during a `load()`
  17322. * we also patch the functions listed in `firstSourceWatch`.
  17323. *
  17324. * @param {Html5} tech
  17325. * The tech to patch
  17326. */
  17327. var setupSourceset = function setupSourceset(tech) {
  17328. if (!tech.featuresSourceset) {
  17329. return;
  17330. }
  17331. var el = tech.el(); // make sure sourceset isn't setup twice.
  17332. if (el.resetSourceset_) {
  17333. return;
  17334. }
  17335. var srcDescriptor = getSrcDescriptor(tech);
  17336. var oldSetAttribute = el.setAttribute;
  17337. var oldLoad = el.load;
  17338. Object.defineProperty(el, 'src', mergeOptions(srcDescriptor, {
  17339. set: function set(v) {
  17340. var retval = srcDescriptor.set.call(el, v); // we use the getter here to get the actual value set on src
  17341. tech.triggerSourceset(el.src);
  17342. return retval;
  17343. }
  17344. }));
  17345. el.setAttribute = function (n, v) {
  17346. var retval = oldSetAttribute.call(el, n, v);
  17347. if (/src/i.test(n)) {
  17348. tech.triggerSourceset(el.src);
  17349. }
  17350. return retval;
  17351. };
  17352. el.load = function () {
  17353. var retval = oldLoad.call(el); // if load was called, but there was no source to fire
  17354. // sourceset on. We have to watch for a source append
  17355. // as that can trigger a `sourceset` when the media element
  17356. // has no source
  17357. if (!sourcesetLoad(tech)) {
  17358. tech.triggerSourceset('');
  17359. firstSourceWatch(tech);
  17360. }
  17361. return retval;
  17362. };
  17363. if (el.currentSrc) {
  17364. tech.triggerSourceset(el.currentSrc);
  17365. } else if (!sourcesetLoad(tech)) {
  17366. firstSourceWatch(tech);
  17367. }
  17368. el.resetSourceset_ = function () {
  17369. el.resetSourceset_ = null;
  17370. el.load = oldLoad;
  17371. el.setAttribute = oldSetAttribute;
  17372. Object.defineProperty(el, 'src', srcDescriptor);
  17373. if (el.resetSourceWatch_) {
  17374. el.resetSourceWatch_();
  17375. }
  17376. };
  17377. };
  17378. /**
  17379. * Object.defineProperty but "lazy", which means that the value is only set after
  17380. * it retrieved the first time, rather than being set right away.
  17381. *
  17382. * @param {Object} obj the object to set the property on
  17383. * @param {string} key the key for the property to set
  17384. * @param {Function} getValue the function used to get the value when it is needed.
  17385. * @param {boolean} setter wether a setter shoould be allowed or not
  17386. */
  17387. var defineLazyProperty = function defineLazyProperty(obj, key, getValue, setter) {
  17388. if (setter === void 0) {
  17389. setter = true;
  17390. }
  17391. var set = function set(value) {
  17392. return Object.defineProperty(obj, key, {
  17393. value: value,
  17394. enumerable: true,
  17395. writable: true
  17396. });
  17397. };
  17398. var options = {
  17399. configurable: true,
  17400. enumerable: true,
  17401. get: function get() {
  17402. var value = getValue();
  17403. set(value);
  17404. return value;
  17405. }
  17406. };
  17407. if (setter) {
  17408. options.set = set;
  17409. }
  17410. return Object.defineProperty(obj, key, options);
  17411. };
  17412. /**
  17413. * HTML5 Media Controller - Wrapper for HTML5 Media API
  17414. *
  17415. * @mixes Tech~SourceHandlerAdditions
  17416. * @extends Tech
  17417. */
  17418. var Html5 = /*#__PURE__*/function (_Tech) {
  17419. inheritsLoose(Html5, _Tech);
  17420. /**
  17421. * Create an instance of this Tech.
  17422. *
  17423. * @param {Object} [options]
  17424. * The key/value store of player options.
  17425. *
  17426. * @param {Component~ReadyCallback} ready
  17427. * Callback function to call when the `HTML5` Tech is ready.
  17428. */
  17429. function Html5(options, ready) {
  17430. var _this;
  17431. _this = _Tech.call(this, options, ready) || this;
  17432. var source = options.source;
  17433. var crossoriginTracks = false;
  17434. _this.featuresVideoFrameCallback = _this.featuresVideoFrameCallback && _this.el_.tagName === 'VIDEO'; // Set the source if one is provided
  17435. // 1) Check if the source is new (if not, we want to keep the original so playback isn't interrupted)
  17436. // 2) Check to see if the network state of the tag was failed at init, and if so, reset the source
  17437. // anyway so the error gets fired.
  17438. if (source && (_this.el_.currentSrc !== source.src || options.tag && options.tag.initNetworkState_ === 3)) {
  17439. _this.setSource(source);
  17440. } else {
  17441. _this.handleLateInit_(_this.el_);
  17442. } // setup sourceset after late sourceset/init
  17443. if (options.enableSourceset) {
  17444. _this.setupSourcesetHandling_();
  17445. }
  17446. _this.isScrubbing_ = false;
  17447. if (_this.el_.hasChildNodes()) {
  17448. var nodes = _this.el_.childNodes;
  17449. var nodesLength = nodes.length;
  17450. var removeNodes = [];
  17451. while (nodesLength--) {
  17452. var node = nodes[nodesLength];
  17453. var nodeName = node.nodeName.toLowerCase();
  17454. if (nodeName === 'track') {
  17455. if (!_this.featuresNativeTextTracks) {
  17456. // Empty video tag tracks so the built-in player doesn't use them also.
  17457. // This may not be fast enough to stop HTML5 browsers from reading the tags
  17458. // so we'll need to turn off any default tracks if we're manually doing
  17459. // captions and subtitles. videoElement.textTracks
  17460. removeNodes.push(node);
  17461. } else {
  17462. // store HTMLTrackElement and TextTrack to remote list
  17463. _this.remoteTextTrackEls().addTrackElement_(node);
  17464. _this.remoteTextTracks().addTrack(node.track);
  17465. _this.textTracks().addTrack(node.track);
  17466. if (!crossoriginTracks && !_this.el_.hasAttribute('crossorigin') && isCrossOrigin(node.src)) {
  17467. crossoriginTracks = true;
  17468. }
  17469. }
  17470. }
  17471. }
  17472. for (var i = 0; i < removeNodes.length; i++) {
  17473. _this.el_.removeChild(removeNodes[i]);
  17474. }
  17475. }
  17476. _this.proxyNativeTracks_();
  17477. if (_this.featuresNativeTextTracks && crossoriginTracks) {
  17478. log.warn('Text Tracks are being loaded from another origin but the crossorigin attribute isn\'t used.\n' + 'This may prevent text tracks from loading.');
  17479. } // prevent iOS Safari from disabling metadata text tracks during native playback
  17480. _this.restoreMetadataTracksInIOSNativePlayer_(); // Determine if native controls should be used
  17481. // Our goal should be to get the custom controls on mobile solid everywhere
  17482. // so we can remove this all together. Right now this will block custom
  17483. // controls on touch enabled laptops like the Chrome Pixel
  17484. if ((TOUCH_ENABLED || IS_IPHONE || IS_NATIVE_ANDROID) && options.nativeControlsForTouch === true) {
  17485. _this.setControls(true);
  17486. } // on iOS, we want to proxy `webkitbeginfullscreen` and `webkitendfullscreen`
  17487. // into a `fullscreenchange` event
  17488. _this.proxyWebkitFullscreen_();
  17489. _this.triggerReady();
  17490. return _this;
  17491. }
  17492. /**
  17493. * Dispose of `HTML5` media element and remove all tracks.
  17494. */
  17495. var _proto = Html5.prototype;
  17496. _proto.dispose = function dispose() {
  17497. if (this.el_ && this.el_.resetSourceset_) {
  17498. this.el_.resetSourceset_();
  17499. }
  17500. Html5.disposeMediaElement(this.el_);
  17501. this.options_ = null; // tech will handle clearing of the emulated track list
  17502. _Tech.prototype.dispose.call(this);
  17503. }
  17504. /**
  17505. * Modify the media element so that we can detect when
  17506. * the source is changed. Fires `sourceset` just after the source has changed
  17507. */
  17508. ;
  17509. _proto.setupSourcesetHandling_ = function setupSourcesetHandling_() {
  17510. setupSourceset(this);
  17511. }
  17512. /**
  17513. * When a captions track is enabled in the iOS Safari native player, all other
  17514. * tracks are disabled (including metadata tracks), which nulls all of their
  17515. * associated cue points. This will restore metadata tracks to their pre-fullscreen
  17516. * state in those cases so that cue points are not needlessly lost.
  17517. *
  17518. * @private
  17519. */
  17520. ;
  17521. _proto.restoreMetadataTracksInIOSNativePlayer_ = function restoreMetadataTracksInIOSNativePlayer_() {
  17522. var textTracks = this.textTracks();
  17523. var metadataTracksPreFullscreenState; // captures a snapshot of every metadata track's current state
  17524. var takeMetadataTrackSnapshot = function takeMetadataTrackSnapshot() {
  17525. metadataTracksPreFullscreenState = [];
  17526. for (var i = 0; i < textTracks.length; i++) {
  17527. var track = textTracks[i];
  17528. if (track.kind === 'metadata') {
  17529. metadataTracksPreFullscreenState.push({
  17530. track: track,
  17531. storedMode: track.mode
  17532. });
  17533. }
  17534. }
  17535. }; // snapshot each metadata track's initial state, and update the snapshot
  17536. // each time there is a track 'change' event
  17537. takeMetadataTrackSnapshot();
  17538. textTracks.addEventListener('change', takeMetadataTrackSnapshot);
  17539. this.on('dispose', function () {
  17540. return textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  17541. });
  17542. var restoreTrackMode = function restoreTrackMode() {
  17543. for (var i = 0; i < metadataTracksPreFullscreenState.length; i++) {
  17544. var storedTrack = metadataTracksPreFullscreenState[i];
  17545. if (storedTrack.track.mode === 'disabled' && storedTrack.track.mode !== storedTrack.storedMode) {
  17546. storedTrack.track.mode = storedTrack.storedMode;
  17547. }
  17548. } // we only want this handler to be executed on the first 'change' event
  17549. textTracks.removeEventListener('change', restoreTrackMode);
  17550. }; // when we enter fullscreen playback, stop updating the snapshot and
  17551. // restore all track modes to their pre-fullscreen state
  17552. this.on('webkitbeginfullscreen', function () {
  17553. textTracks.removeEventListener('change', takeMetadataTrackSnapshot); // remove the listener before adding it just in case it wasn't previously removed
  17554. textTracks.removeEventListener('change', restoreTrackMode);
  17555. textTracks.addEventListener('change', restoreTrackMode);
  17556. }); // start updating the snapshot again after leaving fullscreen
  17557. this.on('webkitendfullscreen', function () {
  17558. // remove the listener before adding it just in case it wasn't previously removed
  17559. textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  17560. textTracks.addEventListener('change', takeMetadataTrackSnapshot); // remove the restoreTrackMode handler in case it wasn't triggered during fullscreen playback
  17561. textTracks.removeEventListener('change', restoreTrackMode);
  17562. });
  17563. }
  17564. /**
  17565. * Attempt to force override of tracks for the given type
  17566. *
  17567. * @param {string} type - Track type to override, possible values include 'Audio',
  17568. * 'Video', and 'Text'.
  17569. * @param {boolean} override - If set to true native audio/video will be overridden,
  17570. * otherwise native audio/video will potentially be used.
  17571. * @private
  17572. */
  17573. ;
  17574. _proto.overrideNative_ = function overrideNative_(type, override) {
  17575. var _this2 = this;
  17576. // If there is no behavioral change don't add/remove listeners
  17577. if (override !== this["featuresNative" + type + "Tracks"]) {
  17578. return;
  17579. }
  17580. var lowerCaseType = type.toLowerCase();
  17581. if (this[lowerCaseType + "TracksListeners_"]) {
  17582. Object.keys(this[lowerCaseType + "TracksListeners_"]).forEach(function (eventName) {
  17583. var elTracks = _this2.el()[lowerCaseType + "Tracks"];
  17584. elTracks.removeEventListener(eventName, _this2[lowerCaseType + "TracksListeners_"][eventName]);
  17585. });
  17586. }
  17587. this["featuresNative" + type + "Tracks"] = !override;
  17588. this[lowerCaseType + "TracksListeners_"] = null;
  17589. this.proxyNativeTracksForType_(lowerCaseType);
  17590. }
  17591. /**
  17592. * Attempt to force override of native audio tracks.
  17593. *
  17594. * @param {boolean} override - If set to true native audio will be overridden,
  17595. * otherwise native audio will potentially be used.
  17596. */
  17597. ;
  17598. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks(override) {
  17599. this.overrideNative_('Audio', override);
  17600. }
  17601. /**
  17602. * Attempt to force override of native video tracks.
  17603. *
  17604. * @param {boolean} override - If set to true native video will be overridden,
  17605. * otherwise native video will potentially be used.
  17606. */
  17607. ;
  17608. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks(override) {
  17609. this.overrideNative_('Video', override);
  17610. }
  17611. /**
  17612. * Proxy native track list events for the given type to our track
  17613. * lists if the browser we are playing in supports that type of track list.
  17614. *
  17615. * @param {string} name - Track type; values include 'audio', 'video', and 'text'
  17616. * @private
  17617. */
  17618. ;
  17619. _proto.proxyNativeTracksForType_ = function proxyNativeTracksForType_(name) {
  17620. var _this3 = this;
  17621. var props = NORMAL[name];
  17622. var elTracks = this.el()[props.getterName];
  17623. var techTracks = this[props.getterName]();
  17624. if (!this["featuresNative" + props.capitalName + "Tracks"] || !elTracks || !elTracks.addEventListener) {
  17625. return;
  17626. }
  17627. var listeners = {
  17628. change: function change(e) {
  17629. var event = {
  17630. type: 'change',
  17631. target: techTracks,
  17632. currentTarget: techTracks,
  17633. srcElement: techTracks
  17634. };
  17635. techTracks.trigger(event); // if we are a text track change event, we should also notify the
  17636. // remote text track list. This can potentially cause a false positive
  17637. // if we were to get a change event on a non-remote track and
  17638. // we triggered the event on the remote text track list which doesn't
  17639. // contain that track. However, best practices mean looping through the
  17640. // list of tracks and searching for the appropriate mode value, so,
  17641. // this shouldn't pose an issue
  17642. if (name === 'text') {
  17643. _this3[REMOTE.remoteText.getterName]().trigger(event);
  17644. }
  17645. },
  17646. addtrack: function addtrack(e) {
  17647. techTracks.addTrack(e.track);
  17648. },
  17649. removetrack: function removetrack(e) {
  17650. techTracks.removeTrack(e.track);
  17651. }
  17652. };
  17653. var removeOldTracks = function removeOldTracks() {
  17654. var removeTracks = [];
  17655. for (var i = 0; i < techTracks.length; i++) {
  17656. var found = false;
  17657. for (var j = 0; j < elTracks.length; j++) {
  17658. if (elTracks[j] === techTracks[i]) {
  17659. found = true;
  17660. break;
  17661. }
  17662. }
  17663. if (!found) {
  17664. removeTracks.push(techTracks[i]);
  17665. }
  17666. }
  17667. while (removeTracks.length) {
  17668. techTracks.removeTrack(removeTracks.shift());
  17669. }
  17670. };
  17671. this[props.getterName + 'Listeners_'] = listeners;
  17672. Object.keys(listeners).forEach(function (eventName) {
  17673. var listener = listeners[eventName];
  17674. elTracks.addEventListener(eventName, listener);
  17675. _this3.on('dispose', function (e) {
  17676. return elTracks.removeEventListener(eventName, listener);
  17677. });
  17678. }); // Remove (native) tracks that are not used anymore
  17679. this.on('loadstart', removeOldTracks);
  17680. this.on('dispose', function (e) {
  17681. return _this3.off('loadstart', removeOldTracks);
  17682. });
  17683. }
  17684. /**
  17685. * Proxy all native track list events to our track lists if the browser we are playing
  17686. * in supports that type of track list.
  17687. *
  17688. * @private
  17689. */
  17690. ;
  17691. _proto.proxyNativeTracks_ = function proxyNativeTracks_() {
  17692. var _this4 = this;
  17693. NORMAL.names.forEach(function (name) {
  17694. _this4.proxyNativeTracksForType_(name);
  17695. });
  17696. }
  17697. /**
  17698. * Create the `Html5` Tech's DOM element.
  17699. *
  17700. * @return {Element}
  17701. * The element that gets created.
  17702. */
  17703. ;
  17704. _proto.createEl = function createEl() {
  17705. var el = this.options_.tag; // Check if this browser supports moving the element into the box.
  17706. // On the iPhone video will break if you move the element,
  17707. // So we have to create a brand new element.
  17708. // If we ingested the player div, we do not need to move the media element.
  17709. if (!el || !(this.options_.playerElIngest || this.movingMediaElementInDOM)) {
  17710. // If the original tag is still there, clone and remove it.
  17711. if (el) {
  17712. var clone = el.cloneNode(true);
  17713. if (el.parentNode) {
  17714. el.parentNode.insertBefore(clone, el);
  17715. }
  17716. Html5.disposeMediaElement(el);
  17717. el = clone;
  17718. } else {
  17719. el = document.createElement('video'); // determine if native controls should be used
  17720. var tagAttributes = this.options_.tag && getAttributes(this.options_.tag);
  17721. var attributes = mergeOptions({}, tagAttributes);
  17722. if (!TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
  17723. delete attributes.controls;
  17724. }
  17725. setAttributes(el, assign(attributes, {
  17726. id: this.options_.techId,
  17727. "class": 'vjs-tech'
  17728. }));
  17729. }
  17730. el.playerId = this.options_.playerId;
  17731. }
  17732. if (typeof this.options_.preload !== 'undefined') {
  17733. setAttribute(el, 'preload', this.options_.preload);
  17734. }
  17735. if (this.options_.disablePictureInPicture !== undefined) {
  17736. el.disablePictureInPicture = this.options_.disablePictureInPicture;
  17737. } // Update specific tag settings, in case they were overridden
  17738. // `autoplay` has to be *last* so that `muted` and `playsinline` are present
  17739. // when iOS/Safari or other browsers attempt to autoplay.
  17740. var settingsAttrs = ['loop', 'muted', 'playsinline', 'autoplay'];
  17741. for (var i = 0; i < settingsAttrs.length; i++) {
  17742. var attr = settingsAttrs[i];
  17743. var value = this.options_[attr];
  17744. if (typeof value !== 'undefined') {
  17745. if (value) {
  17746. setAttribute(el, attr, attr);
  17747. } else {
  17748. removeAttribute(el, attr);
  17749. }
  17750. el[attr] = value;
  17751. }
  17752. }
  17753. return el;
  17754. }
  17755. /**
  17756. * This will be triggered if the loadstart event has already fired, before videojs was
  17757. * ready. Two known examples of when this can happen are:
  17758. * 1. If we're loading the playback object after it has started loading
  17759. * 2. The media is already playing the (often with autoplay on) then
  17760. *
  17761. * This function will fire another loadstart so that videojs can catchup.
  17762. *
  17763. * @fires Tech#loadstart
  17764. *
  17765. * @return {undefined}
  17766. * returns nothing.
  17767. */
  17768. ;
  17769. _proto.handleLateInit_ = function handleLateInit_(el) {
  17770. if (el.networkState === 0 || el.networkState === 3) {
  17771. // The video element hasn't started loading the source yet
  17772. // or didn't find a source
  17773. return;
  17774. }
  17775. if (el.readyState === 0) {
  17776. // NetworkState is set synchronously BUT loadstart is fired at the
  17777. // end of the current stack, usually before setInterval(fn, 0).
  17778. // So at this point we know loadstart may have already fired or is
  17779. // about to fire, and either way the player hasn't seen it yet.
  17780. // We don't want to fire loadstart prematurely here and cause a
  17781. // double loadstart so we'll wait and see if it happens between now
  17782. // and the next loop, and fire it if not.
  17783. // HOWEVER, we also want to make sure it fires before loadedmetadata
  17784. // which could also happen between now and the next loop, so we'll
  17785. // watch for that also.
  17786. var loadstartFired = false;
  17787. var setLoadstartFired = function setLoadstartFired() {
  17788. loadstartFired = true;
  17789. };
  17790. this.on('loadstart', setLoadstartFired);
  17791. var triggerLoadstart = function triggerLoadstart() {
  17792. // We did miss the original loadstart. Make sure the player
  17793. // sees loadstart before loadedmetadata
  17794. if (!loadstartFired) {
  17795. this.trigger('loadstart');
  17796. }
  17797. };
  17798. this.on('loadedmetadata', triggerLoadstart);
  17799. this.ready(function () {
  17800. this.off('loadstart', setLoadstartFired);
  17801. this.off('loadedmetadata', triggerLoadstart);
  17802. if (!loadstartFired) {
  17803. // We did miss the original native loadstart. Fire it now.
  17804. this.trigger('loadstart');
  17805. }
  17806. });
  17807. return;
  17808. } // From here on we know that loadstart already fired and we missed it.
  17809. // The other readyState events aren't as much of a problem if we double
  17810. // them, so not going to go to as much trouble as loadstart to prevent
  17811. // that unless we find reason to.
  17812. var eventsToTrigger = ['loadstart']; // loadedmetadata: newly equal to HAVE_METADATA (1) or greater
  17813. eventsToTrigger.push('loadedmetadata'); // loadeddata: newly increased to HAVE_CURRENT_DATA (2) or greater
  17814. if (el.readyState >= 2) {
  17815. eventsToTrigger.push('loadeddata');
  17816. } // canplay: newly increased to HAVE_FUTURE_DATA (3) or greater
  17817. if (el.readyState >= 3) {
  17818. eventsToTrigger.push('canplay');
  17819. } // canplaythrough: newly equal to HAVE_ENOUGH_DATA (4)
  17820. if (el.readyState >= 4) {
  17821. eventsToTrigger.push('canplaythrough');
  17822. } // We still need to give the player time to add event listeners
  17823. this.ready(function () {
  17824. eventsToTrigger.forEach(function (type) {
  17825. this.trigger(type);
  17826. }, this);
  17827. });
  17828. }
  17829. /**
  17830. * Set whether we are scrubbing or not.
  17831. * This is used to decide whether we should use `fastSeek` or not.
  17832. * `fastSeek` is used to provide trick play on Safari browsers.
  17833. *
  17834. * @param {boolean} isScrubbing
  17835. * - true for we are currently scrubbing
  17836. * - false for we are no longer scrubbing
  17837. */
  17838. ;
  17839. _proto.setScrubbing = function setScrubbing(isScrubbing) {
  17840. this.isScrubbing_ = isScrubbing;
  17841. }
  17842. /**
  17843. * Get whether we are scrubbing or not.
  17844. *
  17845. * @return {boolean} isScrubbing
  17846. * - true for we are currently scrubbing
  17847. * - false for we are no longer scrubbing
  17848. */
  17849. ;
  17850. _proto.scrubbing = function scrubbing() {
  17851. return this.isScrubbing_;
  17852. }
  17853. /**
  17854. * Set current time for the `HTML5` tech.
  17855. *
  17856. * @param {number} seconds
  17857. * Set the current time of the media to this.
  17858. */
  17859. ;
  17860. _proto.setCurrentTime = function setCurrentTime(seconds) {
  17861. try {
  17862. if (this.isScrubbing_ && this.el_.fastSeek && IS_ANY_SAFARI) {
  17863. this.el_.fastSeek(seconds);
  17864. } else {
  17865. this.el_.currentTime = seconds;
  17866. }
  17867. } catch (e) {
  17868. log(e, 'Video is not ready. (Video.js)'); // this.warning(VideoJS.warnings.videoNotReady);
  17869. }
  17870. }
  17871. /**
  17872. * Get the current duration of the HTML5 media element.
  17873. *
  17874. * @return {number}
  17875. * The duration of the media or 0 if there is no duration.
  17876. */
  17877. ;
  17878. _proto.duration = function duration() {
  17879. var _this5 = this;
  17880. // Android Chrome will report duration as Infinity for VOD HLS until after
  17881. // playback has started, which triggers the live display erroneously.
  17882. // Return NaN if playback has not started and trigger a durationupdate once
  17883. // the duration can be reliably known.
  17884. if (this.el_.duration === Infinity && IS_ANDROID && IS_CHROME && this.el_.currentTime === 0) {
  17885. // Wait for the first `timeupdate` with currentTime > 0 - there may be
  17886. // several with 0
  17887. var checkProgress = function checkProgress() {
  17888. if (_this5.el_.currentTime > 0) {
  17889. // Trigger durationchange for genuinely live video
  17890. if (_this5.el_.duration === Infinity) {
  17891. _this5.trigger('durationchange');
  17892. }
  17893. _this5.off('timeupdate', checkProgress);
  17894. }
  17895. };
  17896. this.on('timeupdate', checkProgress);
  17897. return NaN;
  17898. }
  17899. return this.el_.duration || NaN;
  17900. }
  17901. /**
  17902. * Get the current width of the HTML5 media element.
  17903. *
  17904. * @return {number}
  17905. * The width of the HTML5 media element.
  17906. */
  17907. ;
  17908. _proto.width = function width() {
  17909. return this.el_.offsetWidth;
  17910. }
  17911. /**
  17912. * Get the current height of the HTML5 media element.
  17913. *
  17914. * @return {number}
  17915. * The height of the HTML5 media element.
  17916. */
  17917. ;
  17918. _proto.height = function height() {
  17919. return this.el_.offsetHeight;
  17920. }
  17921. /**
  17922. * Proxy iOS `webkitbeginfullscreen` and `webkitendfullscreen` into
  17923. * `fullscreenchange` event.
  17924. *
  17925. * @private
  17926. * @fires fullscreenchange
  17927. * @listens webkitendfullscreen
  17928. * @listens webkitbeginfullscreen
  17929. * @listens webkitbeginfullscreen
  17930. */
  17931. ;
  17932. _proto.proxyWebkitFullscreen_ = function proxyWebkitFullscreen_() {
  17933. var _this6 = this;
  17934. if (!('webkitDisplayingFullscreen' in this.el_)) {
  17935. return;
  17936. }
  17937. var endFn = function endFn() {
  17938. this.trigger('fullscreenchange', {
  17939. isFullscreen: false
  17940. }); // Safari will sometimes set contols on the videoelement when existing fullscreen.
  17941. if (this.el_.controls && !this.options_.nativeControlsForTouch && this.controls()) {
  17942. this.el_.controls = false;
  17943. }
  17944. };
  17945. var beginFn = function beginFn() {
  17946. if ('webkitPresentationMode' in this.el_ && this.el_.webkitPresentationMode !== 'picture-in-picture') {
  17947. this.one('webkitendfullscreen', endFn);
  17948. this.trigger('fullscreenchange', {
  17949. isFullscreen: true,
  17950. // set a flag in case another tech triggers fullscreenchange
  17951. nativeIOSFullscreen: true
  17952. });
  17953. }
  17954. };
  17955. this.on('webkitbeginfullscreen', beginFn);
  17956. this.on('dispose', function () {
  17957. _this6.off('webkitbeginfullscreen', beginFn);
  17958. _this6.off('webkitendfullscreen', endFn);
  17959. });
  17960. }
  17961. /**
  17962. * Check if fullscreen is supported on the current playback device.
  17963. *
  17964. * @return {boolean}
  17965. * - True if fullscreen is supported.
  17966. * - False if fullscreen is not supported.
  17967. */
  17968. ;
  17969. _proto.supportsFullScreen = function supportsFullScreen() {
  17970. if (typeof this.el_.webkitEnterFullScreen === 'function') {
  17971. var userAgent = window.navigator && window.navigator.userAgent || ''; // Seems to be broken in Chromium/Chrome && Safari in Leopard
  17972. if (/Android/.test(userAgent) || !/Chrome|Mac OS X 10.5/.test(userAgent)) {
  17973. return true;
  17974. }
  17975. }
  17976. return false;
  17977. }
  17978. /**
  17979. * Request that the `HTML5` Tech enter fullscreen.
  17980. */
  17981. ;
  17982. _proto.enterFullScreen = function enterFullScreen() {
  17983. var video = this.el_;
  17984. if (video.paused && video.networkState <= video.HAVE_METADATA) {
  17985. // attempt to prime the video element for programmatic access
  17986. // this isn't necessary on the desktop but shouldn't hurt
  17987. silencePromise(this.el_.play()); // playing and pausing synchronously during the transition to fullscreen
  17988. // can get iOS ~6.1 devices into a play/pause loop
  17989. this.setTimeout(function () {
  17990. video.pause();
  17991. try {
  17992. video.webkitEnterFullScreen();
  17993. } catch (e) {
  17994. this.trigger('fullscreenerror', e);
  17995. }
  17996. }, 0);
  17997. } else {
  17998. try {
  17999. video.webkitEnterFullScreen();
  18000. } catch (e) {
  18001. this.trigger('fullscreenerror', e);
  18002. }
  18003. }
  18004. }
  18005. /**
  18006. * Request that the `HTML5` Tech exit fullscreen.
  18007. */
  18008. ;
  18009. _proto.exitFullScreen = function exitFullScreen() {
  18010. if (!this.el_.webkitDisplayingFullscreen) {
  18011. this.trigger('fullscreenerror', new Error('The video is not fullscreen'));
  18012. return;
  18013. }
  18014. this.el_.webkitExitFullScreen();
  18015. }
  18016. /**
  18017. * Create a floating video window always on top of other windows so that users may
  18018. * continue consuming media while they interact with other content sites, or
  18019. * applications on their device.
  18020. *
  18021. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  18022. *
  18023. * @return {Promise}
  18024. * A promise with a Picture-in-Picture window.
  18025. */
  18026. ;
  18027. _proto.requestPictureInPicture = function requestPictureInPicture() {
  18028. return this.el_.requestPictureInPicture();
  18029. }
  18030. /**
  18031. * Native requestVideoFrameCallback if supported by browser/tech, or fallback
  18032. * Don't use rVCF on Safari when DRM is playing, as it doesn't fire
  18033. * Needs to be checked later than the constructor
  18034. * This will be a false positive for clear sources loaded after a Fairplay source
  18035. *
  18036. * @param {function} cb function to call
  18037. * @return {number} id of request
  18038. */
  18039. ;
  18040. _proto.requestVideoFrameCallback = function requestVideoFrameCallback(cb) {
  18041. if (this.featuresVideoFrameCallback && !this.el_.webkitKeys) {
  18042. return this.el_.requestVideoFrameCallback(cb);
  18043. }
  18044. return _Tech.prototype.requestVideoFrameCallback.call(this, cb);
  18045. }
  18046. /**
  18047. * Native or fallback requestVideoFrameCallback
  18048. *
  18049. * @param {number} id request id to cancel
  18050. */
  18051. ;
  18052. _proto.cancelVideoFrameCallback = function cancelVideoFrameCallback(id) {
  18053. if (this.featuresVideoFrameCallback && !this.el_.webkitKeys) {
  18054. this.el_.cancelVideoFrameCallback(id);
  18055. } else {
  18056. _Tech.prototype.cancelVideoFrameCallback.call(this, id);
  18057. }
  18058. }
  18059. /**
  18060. * A getter/setter for the `Html5` Tech's source object.
  18061. * > Note: Please use {@link Html5#setSource}
  18062. *
  18063. * @param {Tech~SourceObject} [src]
  18064. * The source object you want to set on the `HTML5` techs element.
  18065. *
  18066. * @return {Tech~SourceObject|undefined}
  18067. * - The current source object when a source is not passed in.
  18068. * - undefined when setting
  18069. *
  18070. * @deprecated Since version 5.
  18071. */
  18072. ;
  18073. _proto.src = function src(_src) {
  18074. if (_src === undefined) {
  18075. return this.el_.src;
  18076. } // Setting src through `src` instead of `setSrc` will be deprecated
  18077. this.setSrc(_src);
  18078. }
  18079. /**
  18080. * Reset the tech by removing all sources and then calling
  18081. * {@link Html5.resetMediaElement}.
  18082. */
  18083. ;
  18084. _proto.reset = function reset() {
  18085. Html5.resetMediaElement(this.el_);
  18086. }
  18087. /**
  18088. * Get the current source on the `HTML5` Tech. Falls back to returning the source from
  18089. * the HTML5 media element.
  18090. *
  18091. * @return {Tech~SourceObject}
  18092. * The current source object from the HTML5 tech. With a fallback to the
  18093. * elements source.
  18094. */
  18095. ;
  18096. _proto.currentSrc = function currentSrc() {
  18097. if (this.currentSource_) {
  18098. return this.currentSource_.src;
  18099. }
  18100. return this.el_.currentSrc;
  18101. }
  18102. /**
  18103. * Set controls attribute for the HTML5 media Element.
  18104. *
  18105. * @param {string} val
  18106. * Value to set the controls attribute to
  18107. */
  18108. ;
  18109. _proto.setControls = function setControls(val) {
  18110. this.el_.controls = !!val;
  18111. }
  18112. /**
  18113. * Create and returns a remote {@link TextTrack} object.
  18114. *
  18115. * @param {string} kind
  18116. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  18117. *
  18118. * @param {string} [label]
  18119. * Label to identify the text track
  18120. *
  18121. * @param {string} [language]
  18122. * Two letter language abbreviation
  18123. *
  18124. * @return {TextTrack}
  18125. * The TextTrack that gets created.
  18126. */
  18127. ;
  18128. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  18129. if (!this.featuresNativeTextTracks) {
  18130. return _Tech.prototype.addTextTrack.call(this, kind, label, language);
  18131. }
  18132. return this.el_.addTextTrack(kind, label, language);
  18133. }
  18134. /**
  18135. * Creates either native TextTrack or an emulated TextTrack depending
  18136. * on the value of `featuresNativeTextTracks`
  18137. *
  18138. * @param {Object} options
  18139. * The object should contain the options to initialize the TextTrack with.
  18140. *
  18141. * @param {string} [options.kind]
  18142. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  18143. *
  18144. * @param {string} [options.label]
  18145. * Label to identify the text track
  18146. *
  18147. * @param {string} [options.language]
  18148. * Two letter language abbreviation.
  18149. *
  18150. * @param {boolean} [options.default]
  18151. * Default this track to on.
  18152. *
  18153. * @param {string} [options.id]
  18154. * The internal id to assign this track.
  18155. *
  18156. * @param {string} [options.src]
  18157. * A source url for the track.
  18158. *
  18159. * @return {HTMLTrackElement}
  18160. * The track element that gets created.
  18161. */
  18162. ;
  18163. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  18164. if (!this.featuresNativeTextTracks) {
  18165. return _Tech.prototype.createRemoteTextTrack.call(this, options);
  18166. }
  18167. var htmlTrackElement = document.createElement('track');
  18168. if (options.kind) {
  18169. htmlTrackElement.kind = options.kind;
  18170. }
  18171. if (options.label) {
  18172. htmlTrackElement.label = options.label;
  18173. }
  18174. if (options.language || options.srclang) {
  18175. htmlTrackElement.srclang = options.language || options.srclang;
  18176. }
  18177. if (options["default"]) {
  18178. htmlTrackElement["default"] = options["default"];
  18179. }
  18180. if (options.id) {
  18181. htmlTrackElement.id = options.id;
  18182. }
  18183. if (options.src) {
  18184. htmlTrackElement.src = options.src;
  18185. }
  18186. return htmlTrackElement;
  18187. }
  18188. /**
  18189. * Creates a remote text track object and returns an html track element.
  18190. *
  18191. * @param {Object} options The object should contain values for
  18192. * kind, language, label, and src (location of the WebVTT file)
  18193. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  18194. * automatically removed from the video element whenever the source changes
  18195. * @return {HTMLTrackElement} An Html Track Element.
  18196. * This can be an emulated {@link HTMLTrackElement} or a native one.
  18197. * @deprecated The default value of the "manualCleanup" parameter will default
  18198. * to "false" in upcoming versions of Video.js
  18199. */
  18200. ;
  18201. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  18202. var htmlTrackElement = _Tech.prototype.addRemoteTextTrack.call(this, options, manualCleanup);
  18203. if (this.featuresNativeTextTracks) {
  18204. this.el().appendChild(htmlTrackElement);
  18205. }
  18206. return htmlTrackElement;
  18207. }
  18208. /**
  18209. * Remove remote `TextTrack` from `TextTrackList` object
  18210. *
  18211. * @param {TextTrack} track
  18212. * `TextTrack` object to remove
  18213. */
  18214. ;
  18215. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  18216. _Tech.prototype.removeRemoteTextTrack.call(this, track);
  18217. if (this.featuresNativeTextTracks) {
  18218. var tracks = this.$$('track');
  18219. var i = tracks.length;
  18220. while (i--) {
  18221. if (track === tracks[i] || track === tracks[i].track) {
  18222. this.el().removeChild(tracks[i]);
  18223. }
  18224. }
  18225. }
  18226. }
  18227. /**
  18228. * Gets available media playback quality metrics as specified by the W3C's Media
  18229. * Playback Quality API.
  18230. *
  18231. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  18232. *
  18233. * @return {Object}
  18234. * An object with supported media playback quality metrics
  18235. */
  18236. ;
  18237. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  18238. if (typeof this.el().getVideoPlaybackQuality === 'function') {
  18239. return this.el().getVideoPlaybackQuality();
  18240. }
  18241. var videoPlaybackQuality = {};
  18242. if (typeof this.el().webkitDroppedFrameCount !== 'undefined' && typeof this.el().webkitDecodedFrameCount !== 'undefined') {
  18243. videoPlaybackQuality.droppedVideoFrames = this.el().webkitDroppedFrameCount;
  18244. videoPlaybackQuality.totalVideoFrames = this.el().webkitDecodedFrameCount;
  18245. }
  18246. if (window.performance && typeof window.performance.now === 'function') {
  18247. videoPlaybackQuality.creationTime = window.performance.now();
  18248. } else if (window.performance && window.performance.timing && typeof window.performance.timing.navigationStart === 'number') {
  18249. videoPlaybackQuality.creationTime = window.Date.now() - window.performance.timing.navigationStart;
  18250. }
  18251. return videoPlaybackQuality;
  18252. };
  18253. return Html5;
  18254. }(Tech);
  18255. /* HTML5 Support Testing ---------------------------------------------------- */
  18256. /**
  18257. * Element for testing browser HTML5 media capabilities
  18258. *
  18259. * @type {Element}
  18260. * @constant
  18261. * @private
  18262. */
  18263. defineLazyProperty(Html5, 'TEST_VID', function () {
  18264. if (!isReal()) {
  18265. return;
  18266. }
  18267. var video = document.createElement('video');
  18268. var track = document.createElement('track');
  18269. track.kind = 'captions';
  18270. track.srclang = 'en';
  18271. track.label = 'English';
  18272. video.appendChild(track);
  18273. return video;
  18274. });
  18275. /**
  18276. * Check if HTML5 media is supported by this browser/device.
  18277. *
  18278. * @return {boolean}
  18279. * - True if HTML5 media is supported.
  18280. * - False if HTML5 media is not supported.
  18281. */
  18282. Html5.isSupported = function () {
  18283. // IE with no Media Player is a LIAR! (#984)
  18284. try {
  18285. Html5.TEST_VID.volume = 0.5;
  18286. } catch (e) {
  18287. return false;
  18288. }
  18289. return !!(Html5.TEST_VID && Html5.TEST_VID.canPlayType);
  18290. };
  18291. /**
  18292. * Check if the tech can support the given type
  18293. *
  18294. * @param {string} type
  18295. * The mimetype to check
  18296. * @return {string} 'probably', 'maybe', or '' (empty string)
  18297. */
  18298. Html5.canPlayType = function (type) {
  18299. return Html5.TEST_VID.canPlayType(type);
  18300. };
  18301. /**
  18302. * Check if the tech can support the given source
  18303. *
  18304. * @param {Object} srcObj
  18305. * The source object
  18306. * @param {Object} options
  18307. * The options passed to the tech
  18308. * @return {string} 'probably', 'maybe', or '' (empty string)
  18309. */
  18310. Html5.canPlaySource = function (srcObj, options) {
  18311. return Html5.canPlayType(srcObj.type);
  18312. };
  18313. /**
  18314. * Check if the volume can be changed in this browser/device.
  18315. * Volume cannot be changed in a lot of mobile devices.
  18316. * Specifically, it can't be changed from 1 on iOS.
  18317. *
  18318. * @return {boolean}
  18319. * - True if volume can be controlled
  18320. * - False otherwise
  18321. */
  18322. Html5.canControlVolume = function () {
  18323. // IE will error if Windows Media Player not installed #3315
  18324. try {
  18325. var volume = Html5.TEST_VID.volume;
  18326. Html5.TEST_VID.volume = volume / 2 + 0.1;
  18327. var canControl = volume !== Html5.TEST_VID.volume; // With the introduction of iOS 15, there are cases where the volume is read as
  18328. // changed but reverts back to its original state at the start of the next tick.
  18329. // To determine whether volume can be controlled on iOS,
  18330. // a timeout is set and the volume is checked asynchronously.
  18331. // Since `features` doesn't currently work asynchronously, the value is manually set.
  18332. if (canControl && IS_IOS) {
  18333. window.setTimeout(function () {
  18334. if (Html5 && Html5.prototype) {
  18335. Html5.prototype.featuresVolumeControl = volume !== Html5.TEST_VID.volume;
  18336. }
  18337. }); // default iOS to false, which will be updated in the timeout above.
  18338. return false;
  18339. }
  18340. return canControl;
  18341. } catch (e) {
  18342. return false;
  18343. }
  18344. };
  18345. /**
  18346. * Check if the volume can be muted in this browser/device.
  18347. * Some devices, e.g. iOS, don't allow changing volume
  18348. * but permits muting/unmuting.
  18349. *
  18350. * @return {bolean}
  18351. * - True if volume can be muted
  18352. * - False otherwise
  18353. */
  18354. Html5.canMuteVolume = function () {
  18355. try {
  18356. var muted = Html5.TEST_VID.muted; // in some versions of iOS muted property doesn't always
  18357. // work, so we want to set both property and attribute
  18358. Html5.TEST_VID.muted = !muted;
  18359. if (Html5.TEST_VID.muted) {
  18360. setAttribute(Html5.TEST_VID, 'muted', 'muted');
  18361. } else {
  18362. removeAttribute(Html5.TEST_VID, 'muted', 'muted');
  18363. }
  18364. return muted !== Html5.TEST_VID.muted;
  18365. } catch (e) {
  18366. return false;
  18367. }
  18368. };
  18369. /**
  18370. * Check if the playback rate can be changed in this browser/device.
  18371. *
  18372. * @return {boolean}
  18373. * - True if playback rate can be controlled
  18374. * - False otherwise
  18375. */
  18376. Html5.canControlPlaybackRate = function () {
  18377. // Playback rate API is implemented in Android Chrome, but doesn't do anything
  18378. // https://github.com/videojs/video.js/issues/3180
  18379. if (IS_ANDROID && IS_CHROME && CHROME_VERSION < 58) {
  18380. return false;
  18381. } // IE will error if Windows Media Player not installed #3315
  18382. try {
  18383. var playbackRate = Html5.TEST_VID.playbackRate;
  18384. Html5.TEST_VID.playbackRate = playbackRate / 2 + 0.1;
  18385. return playbackRate !== Html5.TEST_VID.playbackRate;
  18386. } catch (e) {
  18387. return false;
  18388. }
  18389. };
  18390. /**
  18391. * Check if we can override a video/audio elements attributes, with
  18392. * Object.defineProperty.
  18393. *
  18394. * @return {boolean}
  18395. * - True if builtin attributes can be overridden
  18396. * - False otherwise
  18397. */
  18398. Html5.canOverrideAttributes = function () {
  18399. // if we cannot overwrite the src/innerHTML property, there is no support
  18400. // iOS 7 safari for instance cannot do this.
  18401. try {
  18402. var noop = function noop() {};
  18403. Object.defineProperty(document.createElement('video'), 'src', {
  18404. get: noop,
  18405. set: noop
  18406. });
  18407. Object.defineProperty(document.createElement('audio'), 'src', {
  18408. get: noop,
  18409. set: noop
  18410. });
  18411. Object.defineProperty(document.createElement('video'), 'innerHTML', {
  18412. get: noop,
  18413. set: noop
  18414. });
  18415. Object.defineProperty(document.createElement('audio'), 'innerHTML', {
  18416. get: noop,
  18417. set: noop
  18418. });
  18419. } catch (e) {
  18420. return false;
  18421. }
  18422. return true;
  18423. };
  18424. /**
  18425. * Check to see if native `TextTrack`s are supported by this browser/device.
  18426. *
  18427. * @return {boolean}
  18428. * - True if native `TextTrack`s are supported.
  18429. * - False otherwise
  18430. */
  18431. Html5.supportsNativeTextTracks = function () {
  18432. return IS_ANY_SAFARI || IS_IOS && IS_CHROME;
  18433. };
  18434. /**
  18435. * Check to see if native `VideoTrack`s are supported by this browser/device
  18436. *
  18437. * @return {boolean}
  18438. * - True if native `VideoTrack`s are supported.
  18439. * - False otherwise
  18440. */
  18441. Html5.supportsNativeVideoTracks = function () {
  18442. return !!(Html5.TEST_VID && Html5.TEST_VID.videoTracks);
  18443. };
  18444. /**
  18445. * Check to see if native `AudioTrack`s are supported by this browser/device
  18446. *
  18447. * @return {boolean}
  18448. * - True if native `AudioTrack`s are supported.
  18449. * - False otherwise
  18450. */
  18451. Html5.supportsNativeAudioTracks = function () {
  18452. return !!(Html5.TEST_VID && Html5.TEST_VID.audioTracks);
  18453. };
  18454. /**
  18455. * An array of events available on the Html5 tech.
  18456. *
  18457. * @private
  18458. * @type {Array}
  18459. */
  18460. Html5.Events = ['loadstart', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'loadedmetadata', 'loadeddata', 'canplay', 'canplaythrough', 'playing', 'waiting', 'seeking', 'seeked', 'ended', 'durationchange', 'timeupdate', 'progress', 'play', 'pause', 'ratechange', 'resize', 'volumechange'];
  18461. /**
  18462. * Boolean indicating whether the `Tech` supports volume control.
  18463. *
  18464. * @type {boolean}
  18465. * @default {@link Html5.canControlVolume}
  18466. */
  18467. /**
  18468. * Boolean indicating whether the `Tech` supports muting volume.
  18469. *
  18470. * @type {bolean}
  18471. * @default {@link Html5.canMuteVolume}
  18472. */
  18473. /**
  18474. * Boolean indicating whether the `Tech` supports changing the speed at which the media
  18475. * plays. Examples:
  18476. * - Set player to play 2x (twice) as fast
  18477. * - Set player to play 0.5x (half) as fast
  18478. *
  18479. * @type {boolean}
  18480. * @default {@link Html5.canControlPlaybackRate}
  18481. */
  18482. /**
  18483. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  18484. *
  18485. * @type {boolean}
  18486. * @default
  18487. */
  18488. /**
  18489. * Boolean indicating whether the `HTML5` tech currently supports native `TextTrack`s.
  18490. *
  18491. * @type {boolean}
  18492. * @default {@link Html5.supportsNativeTextTracks}
  18493. */
  18494. /**
  18495. * Boolean indicating whether the `HTML5` tech currently supports native `VideoTrack`s.
  18496. *
  18497. * @type {boolean}
  18498. * @default {@link Html5.supportsNativeVideoTracks}
  18499. */
  18500. /**
  18501. * Boolean indicating whether the `HTML5` tech currently supports native `AudioTrack`s.
  18502. *
  18503. * @type {boolean}
  18504. * @default {@link Html5.supportsNativeAudioTracks}
  18505. */
  18506. [['featuresMuteControl', 'canMuteVolume'], ['featuresPlaybackRate', 'canControlPlaybackRate'], ['featuresSourceset', 'canOverrideAttributes'], ['featuresNativeTextTracks', 'supportsNativeTextTracks'], ['featuresNativeVideoTracks', 'supportsNativeVideoTracks'], ['featuresNativeAudioTracks', 'supportsNativeAudioTracks']].forEach(function (_ref) {
  18507. var key = _ref[0],
  18508. fn = _ref[1];
  18509. defineLazyProperty(Html5.prototype, key, function () {
  18510. return Html5[fn]();
  18511. }, true);
  18512. });
  18513. Html5.prototype.featuresVolumeControl = Html5.canControlVolume();
  18514. /**
  18515. * Boolean indicating whether the `HTML5` tech currently supports the media element
  18516. * moving in the DOM. iOS breaks if you move the media element, so this is set this to
  18517. * false there. Everywhere else this should be true.
  18518. *
  18519. * @type {boolean}
  18520. * @default
  18521. */
  18522. Html5.prototype.movingMediaElementInDOM = !IS_IOS; // TODO: Previous comment: No longer appears to be used. Can probably be removed.
  18523. // Is this true?
  18524. /**
  18525. * Boolean indicating whether the `HTML5` tech currently supports automatic media resize
  18526. * when going into fullscreen.
  18527. *
  18528. * @type {boolean}
  18529. * @default
  18530. */
  18531. Html5.prototype.featuresFullscreenResize = true;
  18532. /**
  18533. * Boolean indicating whether the `HTML5` tech currently supports the progress event.
  18534. * If this is false, manual `progress` events will be triggered instead.
  18535. *
  18536. * @type {boolean}
  18537. * @default
  18538. */
  18539. Html5.prototype.featuresProgressEvents = true;
  18540. /**
  18541. * Boolean indicating whether the `HTML5` tech currently supports the timeupdate event.
  18542. * If this is false, manual `timeupdate` events will be triggered instead.
  18543. *
  18544. * @default
  18545. */
  18546. Html5.prototype.featuresTimeupdateEvents = true;
  18547. /**
  18548. * Whether the HTML5 el supports `requestVideoFrameCallback`
  18549. *
  18550. * @type {boolean}
  18551. */
  18552. Html5.prototype.featuresVideoFrameCallback = !!(Html5.TEST_VID && Html5.TEST_VID.requestVideoFrameCallback); // HTML5 Feature detection and Device Fixes --------------------------------- //
  18553. var canPlayType;
  18554. Html5.patchCanPlayType = function () {
  18555. // Android 4.0 and above can play HLS to some extent but it reports being unable to do so
  18556. // Firefox and Chrome report correctly
  18557. if (ANDROID_VERSION >= 4.0 && !IS_FIREFOX && !IS_CHROME) {
  18558. canPlayType = Html5.TEST_VID && Html5.TEST_VID.constructor.prototype.canPlayType;
  18559. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  18560. var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
  18561. if (type && mpegurlRE.test(type)) {
  18562. return 'maybe';
  18563. }
  18564. return canPlayType.call(this, type);
  18565. };
  18566. }
  18567. };
  18568. Html5.unpatchCanPlayType = function () {
  18569. var r = Html5.TEST_VID.constructor.prototype.canPlayType;
  18570. if (canPlayType) {
  18571. Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
  18572. }
  18573. return r;
  18574. }; // by default, patch the media element
  18575. Html5.patchCanPlayType();
  18576. Html5.disposeMediaElement = function (el) {
  18577. if (!el) {
  18578. return;
  18579. }
  18580. if (el.parentNode) {
  18581. el.parentNode.removeChild(el);
  18582. } // remove any child track or source nodes to prevent their loading
  18583. while (el.hasChildNodes()) {
  18584. el.removeChild(el.firstChild);
  18585. } // remove any src reference. not setting `src=''` because that causes a warning
  18586. // in firefox
  18587. el.removeAttribute('src'); // force the media element to update its loading state by calling load()
  18588. // however IE on Windows 7N has a bug that throws an error so need a try/catch (#793)
  18589. if (typeof el.load === 'function') {
  18590. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  18591. (function () {
  18592. try {
  18593. el.load();
  18594. } catch (e) {// not supported
  18595. }
  18596. })();
  18597. }
  18598. };
  18599. Html5.resetMediaElement = function (el) {
  18600. if (!el) {
  18601. return;
  18602. }
  18603. var sources = el.querySelectorAll('source');
  18604. var i = sources.length;
  18605. while (i--) {
  18606. el.removeChild(sources[i]);
  18607. } // remove any src reference.
  18608. // not setting `src=''` because that throws an error
  18609. el.removeAttribute('src');
  18610. if (typeof el.load === 'function') {
  18611. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  18612. (function () {
  18613. try {
  18614. el.load();
  18615. } catch (e) {// satisfy linter
  18616. }
  18617. })();
  18618. }
  18619. };
  18620. /* Native HTML5 element property wrapping ----------------------------------- */
  18621. // Wrap native boolean attributes with getters that check both property and attribute
  18622. // The list is as followed:
  18623. // muted, defaultMuted, autoplay, controls, loop, playsinline
  18624. [
  18625. /**
  18626. * Get the value of `muted` from the media element. `muted` indicates
  18627. * that the volume for the media should be set to silent. This does not actually change
  18628. * the `volume` attribute.
  18629. *
  18630. * @method Html5#muted
  18631. * @return {boolean}
  18632. * - True if the value of `volume` should be ignored and the audio set to silent.
  18633. * - False if the value of `volume` should be used.
  18634. *
  18635. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  18636. */
  18637. 'muted',
  18638. /**
  18639. * Get the value of `defaultMuted` from the media element. `defaultMuted` indicates
  18640. * whether the media should start muted or not. Only changes the default state of the
  18641. * media. `muted` and `defaultMuted` can have different values. {@link Html5#muted} indicates the
  18642. * current state.
  18643. *
  18644. * @method Html5#defaultMuted
  18645. * @return {boolean}
  18646. * - The value of `defaultMuted` from the media element.
  18647. * - True indicates that the media should start muted.
  18648. * - False indicates that the media should not start muted
  18649. *
  18650. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  18651. */
  18652. 'defaultMuted',
  18653. /**
  18654. * Get the value of `autoplay` from the media element. `autoplay` indicates
  18655. * that the media should start to play as soon as the page is ready.
  18656. *
  18657. * @method Html5#autoplay
  18658. * @return {boolean}
  18659. * - The value of `autoplay` from the media element.
  18660. * - True indicates that the media should start as soon as the page loads.
  18661. * - False indicates that the media should not start as soon as the page loads.
  18662. *
  18663. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  18664. */
  18665. 'autoplay',
  18666. /**
  18667. * Get the value of `controls` from the media element. `controls` indicates
  18668. * whether the native media controls should be shown or hidden.
  18669. *
  18670. * @method Html5#controls
  18671. * @return {boolean}
  18672. * - The value of `controls` from the media element.
  18673. * - True indicates that native controls should be showing.
  18674. * - False indicates that native controls should be hidden.
  18675. *
  18676. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-controls}
  18677. */
  18678. 'controls',
  18679. /**
  18680. * Get the value of `loop` from the media element. `loop` indicates
  18681. * that the media should return to the start of the media and continue playing once
  18682. * it reaches the end.
  18683. *
  18684. * @method Html5#loop
  18685. * @return {boolean}
  18686. * - The value of `loop` from the media element.
  18687. * - True indicates that playback should seek back to start once
  18688. * the end of a media is reached.
  18689. * - False indicates that playback should not loop back to the start when the
  18690. * end of the media is reached.
  18691. *
  18692. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  18693. */
  18694. 'loop',
  18695. /**
  18696. * Get the value of `playsinline` from the media element. `playsinline` indicates
  18697. * to the browser that non-fullscreen playback is preferred when fullscreen
  18698. * playback is the native default, such as in iOS Safari.
  18699. *
  18700. * @method Html5#playsinline
  18701. * @return {boolean}
  18702. * - The value of `playsinline` from the media element.
  18703. * - True indicates that the media should play inline.
  18704. * - False indicates that the media should not play inline.
  18705. *
  18706. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  18707. */
  18708. 'playsinline'].forEach(function (prop) {
  18709. Html5.prototype[prop] = function () {
  18710. return this.el_[prop] || this.el_.hasAttribute(prop);
  18711. };
  18712. }); // Wrap native boolean attributes with setters that set both property and attribute
  18713. // The list is as followed:
  18714. // setMuted, setDefaultMuted, setAutoplay, setLoop, setPlaysinline
  18715. // setControls is special-cased above
  18716. [
  18717. /**
  18718. * Set the value of `muted` on the media element. `muted` indicates that the current
  18719. * audio level should be silent.
  18720. *
  18721. * @method Html5#setMuted
  18722. * @param {boolean} muted
  18723. * - True if the audio should be set to silent
  18724. * - False otherwise
  18725. *
  18726. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  18727. */
  18728. 'muted',
  18729. /**
  18730. * Set the value of `defaultMuted` on the media element. `defaultMuted` indicates that the current
  18731. * audio level should be silent, but will only effect the muted level on initial playback..
  18732. *
  18733. * @method Html5.prototype.setDefaultMuted
  18734. * @param {boolean} defaultMuted
  18735. * - True if the audio should be set to silent
  18736. * - False otherwise
  18737. *
  18738. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  18739. */
  18740. 'defaultMuted',
  18741. /**
  18742. * Set the value of `autoplay` on the media element. `autoplay` indicates
  18743. * that the media should start to play as soon as the page is ready.
  18744. *
  18745. * @method Html5#setAutoplay
  18746. * @param {boolean} autoplay
  18747. * - True indicates that the media should start as soon as the page loads.
  18748. * - False indicates that the media should not start as soon as the page loads.
  18749. *
  18750. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  18751. */
  18752. 'autoplay',
  18753. /**
  18754. * Set the value of `loop` on the media element. `loop` indicates
  18755. * that the media should return to the start of the media and continue playing once
  18756. * it reaches the end.
  18757. *
  18758. * @method Html5#setLoop
  18759. * @param {boolean} loop
  18760. * - True indicates that playback should seek back to start once
  18761. * the end of a media is reached.
  18762. * - False indicates that playback should not loop back to the start when the
  18763. * end of the media is reached.
  18764. *
  18765. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  18766. */
  18767. 'loop',
  18768. /**
  18769. * Set the value of `playsinline` from the media element. `playsinline` indicates
  18770. * to the browser that non-fullscreen playback is preferred when fullscreen
  18771. * playback is the native default, such as in iOS Safari.
  18772. *
  18773. * @method Html5#setPlaysinline
  18774. * @param {boolean} playsinline
  18775. * - True indicates that the media should play inline.
  18776. * - False indicates that the media should not play inline.
  18777. *
  18778. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  18779. */
  18780. 'playsinline'].forEach(function (prop) {
  18781. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  18782. this.el_[prop] = v;
  18783. if (v) {
  18784. this.el_.setAttribute(prop, prop);
  18785. } else {
  18786. this.el_.removeAttribute(prop);
  18787. }
  18788. };
  18789. }); // Wrap native properties with a getter
  18790. // The list is as followed
  18791. // paused, currentTime, buffered, volume, poster, preload, error, seeking
  18792. // seekable, ended, playbackRate, defaultPlaybackRate, disablePictureInPicture
  18793. // played, networkState, readyState, videoWidth, videoHeight, crossOrigin
  18794. [
  18795. /**
  18796. * Get the value of `paused` from the media element. `paused` indicates whether the media element
  18797. * is currently paused or not.
  18798. *
  18799. * @method Html5#paused
  18800. * @return {boolean}
  18801. * The value of `paused` from the media element.
  18802. *
  18803. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-paused}
  18804. */
  18805. 'paused',
  18806. /**
  18807. * Get the value of `currentTime` from the media element. `currentTime` indicates
  18808. * the current second that the media is at in playback.
  18809. *
  18810. * @method Html5#currentTime
  18811. * @return {number}
  18812. * The value of `currentTime` from the media element.
  18813. *
  18814. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-currenttime}
  18815. */
  18816. 'currentTime',
  18817. /**
  18818. * Get the value of `buffered` from the media element. `buffered` is a `TimeRange`
  18819. * object that represents the parts of the media that are already downloaded and
  18820. * available for playback.
  18821. *
  18822. * @method Html5#buffered
  18823. * @return {TimeRange}
  18824. * The value of `buffered` from the media element.
  18825. *
  18826. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-buffered}
  18827. */
  18828. 'buffered',
  18829. /**
  18830. * Get the value of `volume` from the media element. `volume` indicates
  18831. * the current playback volume of audio for a media. `volume` will be a value from 0
  18832. * (silent) to 1 (loudest and default).
  18833. *
  18834. * @method Html5#volume
  18835. * @return {number}
  18836. * The value of `volume` from the media element. Value will be between 0-1.
  18837. *
  18838. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  18839. */
  18840. 'volume',
  18841. /**
  18842. * Get the value of `poster` from the media element. `poster` indicates
  18843. * that the url of an image file that can/will be shown when no media data is available.
  18844. *
  18845. * @method Html5#poster
  18846. * @return {string}
  18847. * The value of `poster` from the media element. Value will be a url to an
  18848. * image.
  18849. *
  18850. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster}
  18851. */
  18852. 'poster',
  18853. /**
  18854. * Get the value of `preload` from the media element. `preload` indicates
  18855. * what should download before the media is interacted with. It can have the following
  18856. * values:
  18857. * - none: nothing should be downloaded
  18858. * - metadata: poster and the first few frames of the media may be downloaded to get
  18859. * media dimensions and other metadata
  18860. * - auto: allow the media and metadata for the media to be downloaded before
  18861. * interaction
  18862. *
  18863. * @method Html5#preload
  18864. * @return {string}
  18865. * The value of `preload` from the media element. Will be 'none', 'metadata',
  18866. * or 'auto'.
  18867. *
  18868. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  18869. */
  18870. 'preload',
  18871. /**
  18872. * Get the value of the `error` from the media element. `error` indicates any
  18873. * MediaError that may have occurred during playback. If error returns null there is no
  18874. * current error.
  18875. *
  18876. * @method Html5#error
  18877. * @return {MediaError|null}
  18878. * The value of `error` from the media element. Will be `MediaError` if there
  18879. * is a current error and null otherwise.
  18880. *
  18881. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-error}
  18882. */
  18883. 'error',
  18884. /**
  18885. * Get the value of `seeking` from the media element. `seeking` indicates whether the
  18886. * media is currently seeking to a new position or not.
  18887. *
  18888. * @method Html5#seeking
  18889. * @return {boolean}
  18890. * - The value of `seeking` from the media element.
  18891. * - True indicates that the media is currently seeking to a new position.
  18892. * - False indicates that the media is not seeking to a new position at this time.
  18893. *
  18894. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seeking}
  18895. */
  18896. 'seeking',
  18897. /**
  18898. * Get the value of `seekable` from the media element. `seekable` returns a
  18899. * `TimeRange` object indicating ranges of time that can currently be `seeked` to.
  18900. *
  18901. * @method Html5#seekable
  18902. * @return {TimeRange}
  18903. * The value of `seekable` from the media element. A `TimeRange` object
  18904. * indicating the current ranges of time that can be seeked to.
  18905. *
  18906. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seekable}
  18907. */
  18908. 'seekable',
  18909. /**
  18910. * Get the value of `ended` from the media element. `ended` indicates whether
  18911. * the media has reached the end or not.
  18912. *
  18913. * @method Html5#ended
  18914. * @return {boolean}
  18915. * - The value of `ended` from the media element.
  18916. * - True indicates that the media has ended.
  18917. * - False indicates that the media has not ended.
  18918. *
  18919. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
  18920. */
  18921. 'ended',
  18922. /**
  18923. * Get the value of `playbackRate` from the media element. `playbackRate` indicates
  18924. * the rate at which the media is currently playing back. Examples:
  18925. * - if playbackRate is set to 2, media will play twice as fast.
  18926. * - if playbackRate is set to 0.5, media will play half as fast.
  18927. *
  18928. * @method Html5#playbackRate
  18929. * @return {number}
  18930. * The value of `playbackRate` from the media element. A number indicating
  18931. * the current playback speed of the media, where 1 is normal speed.
  18932. *
  18933. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  18934. */
  18935. 'playbackRate',
  18936. /**
  18937. * Get the value of `defaultPlaybackRate` from the media element. `defaultPlaybackRate` indicates
  18938. * the rate at which the media is currently playing back. This value will not indicate the current
  18939. * `playbackRate` after playback has started, use {@link Html5#playbackRate} for that.
  18940. *
  18941. * Examples:
  18942. * - if defaultPlaybackRate is set to 2, media will play twice as fast.
  18943. * - if defaultPlaybackRate is set to 0.5, media will play half as fast.
  18944. *
  18945. * @method Html5.prototype.defaultPlaybackRate
  18946. * @return {number}
  18947. * The value of `defaultPlaybackRate` from the media element. A number indicating
  18948. * the current playback speed of the media, where 1 is normal speed.
  18949. *
  18950. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  18951. */
  18952. 'defaultPlaybackRate',
  18953. /**
  18954. * Get the value of 'disablePictureInPicture' from the video element.
  18955. *
  18956. * @method Html5#disablePictureInPicture
  18957. * @return {boolean} value
  18958. * - The value of `disablePictureInPicture` from the video element.
  18959. * - True indicates that the video can't be played in Picture-In-Picture mode
  18960. * - False indicates that the video can be played in Picture-In-Picture mode
  18961. *
  18962. * @see [Spec]{@link https://w3c.github.io/picture-in-picture/#disable-pip}
  18963. */
  18964. 'disablePictureInPicture',
  18965. /**
  18966. * Get the value of `played` from the media element. `played` returns a `TimeRange`
  18967. * object representing points in the media timeline that have been played.
  18968. *
  18969. * @method Html5#played
  18970. * @return {TimeRange}
  18971. * The value of `played` from the media element. A `TimeRange` object indicating
  18972. * the ranges of time that have been played.
  18973. *
  18974. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-played}
  18975. */
  18976. 'played',
  18977. /**
  18978. * Get the value of `networkState` from the media element. `networkState` indicates
  18979. * the current network state. It returns an enumeration from the following list:
  18980. * - 0: NETWORK_EMPTY
  18981. * - 1: NETWORK_IDLE
  18982. * - 2: NETWORK_LOADING
  18983. * - 3: NETWORK_NO_SOURCE
  18984. *
  18985. * @method Html5#networkState
  18986. * @return {number}
  18987. * The value of `networkState` from the media element. This will be a number
  18988. * from the list in the description.
  18989. *
  18990. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-networkstate}
  18991. */
  18992. 'networkState',
  18993. /**
  18994. * Get the value of `readyState` from the media element. `readyState` indicates
  18995. * the current state of the media element. It returns an enumeration from the
  18996. * following list:
  18997. * - 0: HAVE_NOTHING
  18998. * - 1: HAVE_METADATA
  18999. * - 2: HAVE_CURRENT_DATA
  19000. * - 3: HAVE_FUTURE_DATA
  19001. * - 4: HAVE_ENOUGH_DATA
  19002. *
  19003. * @method Html5#readyState
  19004. * @return {number}
  19005. * The value of `readyState` from the media element. This will be a number
  19006. * from the list in the description.
  19007. *
  19008. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#ready-states}
  19009. */
  19010. 'readyState',
  19011. /**
  19012. * Get the value of `videoWidth` from the video element. `videoWidth` indicates
  19013. * the current width of the video in css pixels.
  19014. *
  19015. * @method Html5#videoWidth
  19016. * @return {number}
  19017. * The value of `videoWidth` from the video element. This will be a number
  19018. * in css pixels.
  19019. *
  19020. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  19021. */
  19022. 'videoWidth',
  19023. /**
  19024. * Get the value of `videoHeight` from the video element. `videoHeight` indicates
  19025. * the current height of the video in css pixels.
  19026. *
  19027. * @method Html5#videoHeight
  19028. * @return {number}
  19029. * The value of `videoHeight` from the video element. This will be a number
  19030. * in css pixels.
  19031. *
  19032. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  19033. */
  19034. 'videoHeight',
  19035. /**
  19036. * Get the value of `crossOrigin` from the media element. `crossOrigin` indicates
  19037. * to the browser that should sent the cookies along with the requests for the
  19038. * different assets/playlists
  19039. *
  19040. * @method Html5#crossOrigin
  19041. * @return {string}
  19042. * - anonymous indicates that the media should not sent cookies.
  19043. * - use-credentials indicates that the media should sent cookies along the requests.
  19044. *
  19045. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-media-crossorigin}
  19046. */
  19047. 'crossOrigin'].forEach(function (prop) {
  19048. Html5.prototype[prop] = function () {
  19049. return this.el_[prop];
  19050. };
  19051. }); // Wrap native properties with a setter in this format:
  19052. // set + toTitleCase(name)
  19053. // The list is as follows:
  19054. // setVolume, setSrc, setPoster, setPreload, setPlaybackRate, setDefaultPlaybackRate,
  19055. // setDisablePictureInPicture, setCrossOrigin
  19056. [
  19057. /**
  19058. * Set the value of `volume` on the media element. `volume` indicates the current
  19059. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  19060. * so on.
  19061. *
  19062. * @method Html5#setVolume
  19063. * @param {number} percentAsDecimal
  19064. * The volume percent as a decimal. Valid range is from 0-1.
  19065. *
  19066. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  19067. */
  19068. 'volume',
  19069. /**
  19070. * Set the value of `src` on the media element. `src` indicates the current
  19071. * {@link Tech~SourceObject} for the media.
  19072. *
  19073. * @method Html5#setSrc
  19074. * @param {Tech~SourceObject} src
  19075. * The source object to set as the current source.
  19076. *
  19077. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-src}
  19078. */
  19079. 'src',
  19080. /**
  19081. * Set the value of `poster` on the media element. `poster` is the url to
  19082. * an image file that can/will be shown when no media data is available.
  19083. *
  19084. * @method Html5#setPoster
  19085. * @param {string} poster
  19086. * The url to an image that should be used as the `poster` for the media
  19087. * element.
  19088. *
  19089. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-poster}
  19090. */
  19091. 'poster',
  19092. /**
  19093. * Set the value of `preload` on the media element. `preload` indicates
  19094. * what should download before the media is interacted with. It can have the following
  19095. * values:
  19096. * - none: nothing should be downloaded
  19097. * - metadata: poster and the first few frames of the media may be downloaded to get
  19098. * media dimensions and other metadata
  19099. * - auto: allow the media and metadata for the media to be downloaded before
  19100. * interaction
  19101. *
  19102. * @method Html5#setPreload
  19103. * @param {string} preload
  19104. * The value of `preload` to set on the media element. Must be 'none', 'metadata',
  19105. * or 'auto'.
  19106. *
  19107. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  19108. */
  19109. 'preload',
  19110. /**
  19111. * Set the value of `playbackRate` on the media element. `playbackRate` indicates
  19112. * the rate at which the media should play back. Examples:
  19113. * - if playbackRate is set to 2, media will play twice as fast.
  19114. * - if playbackRate is set to 0.5, media will play half as fast.
  19115. *
  19116. * @method Html5#setPlaybackRate
  19117. * @return {number}
  19118. * The value of `playbackRate` from the media element. A number indicating
  19119. * the current playback speed of the media, where 1 is normal speed.
  19120. *
  19121. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  19122. */
  19123. 'playbackRate',
  19124. /**
  19125. * Set the value of `defaultPlaybackRate` on the media element. `defaultPlaybackRate` indicates
  19126. * the rate at which the media should play back upon initial startup. Changing this value
  19127. * after a video has started will do nothing. Instead you should used {@link Html5#setPlaybackRate}.
  19128. *
  19129. * Example Values:
  19130. * - if playbackRate is set to 2, media will play twice as fast.
  19131. * - if playbackRate is set to 0.5, media will play half as fast.
  19132. *
  19133. * @method Html5.prototype.setDefaultPlaybackRate
  19134. * @return {number}
  19135. * The value of `defaultPlaybackRate` from the media element. A number indicating
  19136. * the current playback speed of the media, where 1 is normal speed.
  19137. *
  19138. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultplaybackrate}
  19139. */
  19140. 'defaultPlaybackRate',
  19141. /**
  19142. * Prevents the browser from suggesting a Picture-in-Picture context menu
  19143. * or to request Picture-in-Picture automatically in some cases.
  19144. *
  19145. * @method Html5#setDisablePictureInPicture
  19146. * @param {boolean} value
  19147. * The true value will disable Picture-in-Picture mode.
  19148. *
  19149. * @see [Spec]{@link https://w3c.github.io/picture-in-picture/#disable-pip}
  19150. */
  19151. 'disablePictureInPicture',
  19152. /**
  19153. * Set the value of `crossOrigin` from the media element. `crossOrigin` indicates
  19154. * to the browser that should sent the cookies along with the requests for the
  19155. * different assets/playlists
  19156. *
  19157. * @method Html5#setCrossOrigin
  19158. * @param {string} crossOrigin
  19159. * - anonymous indicates that the media should not sent cookies.
  19160. * - use-credentials indicates that the media should sent cookies along the requests.
  19161. *
  19162. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-media-crossorigin}
  19163. */
  19164. 'crossOrigin'].forEach(function (prop) {
  19165. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  19166. this.el_[prop] = v;
  19167. };
  19168. }); // wrap native functions with a function
  19169. // The list is as follows:
  19170. // pause, load, play
  19171. [
  19172. /**
  19173. * A wrapper around the media elements `pause` function. This will call the `HTML5`
  19174. * media elements `pause` function.
  19175. *
  19176. * @method Html5#pause
  19177. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-pause}
  19178. */
  19179. 'pause',
  19180. /**
  19181. * A wrapper around the media elements `load` function. This will call the `HTML5`s
  19182. * media element `load` function.
  19183. *
  19184. * @method Html5#load
  19185. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-load}
  19186. */
  19187. 'load',
  19188. /**
  19189. * A wrapper around the media elements `play` function. This will call the `HTML5`s
  19190. * media element `play` function.
  19191. *
  19192. * @method Html5#play
  19193. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-play}
  19194. */
  19195. 'play'].forEach(function (prop) {
  19196. Html5.prototype[prop] = function () {
  19197. return this.el_[prop]();
  19198. };
  19199. });
  19200. Tech.withSourceHandlers(Html5);
  19201. /**
  19202. * Native source handler for Html5, simply passes the source to the media element.
  19203. *
  19204. * @property {Tech~SourceObject} source
  19205. * The source object
  19206. *
  19207. * @property {Html5} tech
  19208. * The instance of the HTML5 tech.
  19209. */
  19210. Html5.nativeSourceHandler = {};
  19211. /**
  19212. * Check if the media element can play the given mime type.
  19213. *
  19214. * @param {string} type
  19215. * The mimetype to check
  19216. *
  19217. * @return {string}
  19218. * 'probably', 'maybe', or '' (empty string)
  19219. */
  19220. Html5.nativeSourceHandler.canPlayType = function (type) {
  19221. // IE without MediaPlayer throws an error (#519)
  19222. try {
  19223. return Html5.TEST_VID.canPlayType(type);
  19224. } catch (e) {
  19225. return '';
  19226. }
  19227. };
  19228. /**
  19229. * Check if the media element can handle a source natively.
  19230. *
  19231. * @param {Tech~SourceObject} source
  19232. * The source object
  19233. *
  19234. * @param {Object} [options]
  19235. * Options to be passed to the tech.
  19236. *
  19237. * @return {string}
  19238. * 'probably', 'maybe', or '' (empty string).
  19239. */
  19240. Html5.nativeSourceHandler.canHandleSource = function (source, options) {
  19241. // If a type was provided we should rely on that
  19242. if (source.type) {
  19243. return Html5.nativeSourceHandler.canPlayType(source.type); // If no type, fall back to checking 'video/[EXTENSION]'
  19244. } else if (source.src) {
  19245. var ext = getFileExtension(source.src);
  19246. return Html5.nativeSourceHandler.canPlayType("video/" + ext);
  19247. }
  19248. return '';
  19249. };
  19250. /**
  19251. * Pass the source to the native media element.
  19252. *
  19253. * @param {Tech~SourceObject} source
  19254. * The source object
  19255. *
  19256. * @param {Html5} tech
  19257. * The instance of the Html5 tech
  19258. *
  19259. * @param {Object} [options]
  19260. * The options to pass to the source
  19261. */
  19262. Html5.nativeSourceHandler.handleSource = function (source, tech, options) {
  19263. tech.setSrc(source.src);
  19264. };
  19265. /**
  19266. * A noop for the native dispose function, as cleanup is not needed.
  19267. */
  19268. Html5.nativeSourceHandler.dispose = function () {}; // Register the native source handler
  19269. Html5.registerSourceHandler(Html5.nativeSourceHandler);
  19270. Tech.registerTech('Html5', Html5);
  19271. // on the player when they happen
  19272. var TECH_EVENTS_RETRIGGER = [
  19273. /**
  19274. * Fired while the user agent is downloading media data.
  19275. *
  19276. * @event Player#progress
  19277. * @type {EventTarget~Event}
  19278. */
  19279. /**
  19280. * Retrigger the `progress` event that was triggered by the {@link Tech}.
  19281. *
  19282. * @private
  19283. * @method Player#handleTechProgress_
  19284. * @fires Player#progress
  19285. * @listens Tech#progress
  19286. */
  19287. 'progress',
  19288. /**
  19289. * Fires when the loading of an audio/video is aborted.
  19290. *
  19291. * @event Player#abort
  19292. * @type {EventTarget~Event}
  19293. */
  19294. /**
  19295. * Retrigger the `abort` event that was triggered by the {@link Tech}.
  19296. *
  19297. * @private
  19298. * @method Player#handleTechAbort_
  19299. * @fires Player#abort
  19300. * @listens Tech#abort
  19301. */
  19302. 'abort',
  19303. /**
  19304. * Fires when the browser is intentionally not getting media data.
  19305. *
  19306. * @event Player#suspend
  19307. * @type {EventTarget~Event}
  19308. */
  19309. /**
  19310. * Retrigger the `suspend` event that was triggered by the {@link Tech}.
  19311. *
  19312. * @private
  19313. * @method Player#handleTechSuspend_
  19314. * @fires Player#suspend
  19315. * @listens Tech#suspend
  19316. */
  19317. 'suspend',
  19318. /**
  19319. * Fires when the current playlist is empty.
  19320. *
  19321. * @event Player#emptied
  19322. * @type {EventTarget~Event}
  19323. */
  19324. /**
  19325. * Retrigger the `emptied` event that was triggered by the {@link Tech}.
  19326. *
  19327. * @private
  19328. * @method Player#handleTechEmptied_
  19329. * @fires Player#emptied
  19330. * @listens Tech#emptied
  19331. */
  19332. 'emptied',
  19333. /**
  19334. * Fires when the browser is trying to get media data, but data is not available.
  19335. *
  19336. * @event Player#stalled
  19337. * @type {EventTarget~Event}
  19338. */
  19339. /**
  19340. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  19341. *
  19342. * @private
  19343. * @method Player#handleTechStalled_
  19344. * @fires Player#stalled
  19345. * @listens Tech#stalled
  19346. */
  19347. 'stalled',
  19348. /**
  19349. * Fires when the browser has loaded meta data for the audio/video.
  19350. *
  19351. * @event Player#loadedmetadata
  19352. * @type {EventTarget~Event}
  19353. */
  19354. /**
  19355. * Retrigger the `loadedmetadata` event that was triggered by the {@link Tech}.
  19356. *
  19357. * @private
  19358. * @method Player#handleTechLoadedmetadata_
  19359. * @fires Player#loadedmetadata
  19360. * @listens Tech#loadedmetadata
  19361. */
  19362. 'loadedmetadata',
  19363. /**
  19364. * Fires when the browser has loaded the current frame of the audio/video.
  19365. *
  19366. * @event Player#loadeddata
  19367. * @type {event}
  19368. */
  19369. /**
  19370. * Retrigger the `loadeddata` event that was triggered by the {@link Tech}.
  19371. *
  19372. * @private
  19373. * @method Player#handleTechLoaddeddata_
  19374. * @fires Player#loadeddata
  19375. * @listens Tech#loadeddata
  19376. */
  19377. 'loadeddata',
  19378. /**
  19379. * Fires when the current playback position has changed.
  19380. *
  19381. * @event Player#timeupdate
  19382. * @type {event}
  19383. */
  19384. /**
  19385. * Retrigger the `timeupdate` event that was triggered by the {@link Tech}.
  19386. *
  19387. * @private
  19388. * @method Player#handleTechTimeUpdate_
  19389. * @fires Player#timeupdate
  19390. * @listens Tech#timeupdate
  19391. */
  19392. 'timeupdate',
  19393. /**
  19394. * Fires when the video's intrinsic dimensions change
  19395. *
  19396. * @event Player#resize
  19397. * @type {event}
  19398. */
  19399. /**
  19400. * Retrigger the `resize` event that was triggered by the {@link Tech}.
  19401. *
  19402. * @private
  19403. * @method Player#handleTechResize_
  19404. * @fires Player#resize
  19405. * @listens Tech#resize
  19406. */
  19407. 'resize',
  19408. /**
  19409. * Fires when the volume has been changed
  19410. *
  19411. * @event Player#volumechange
  19412. * @type {event}
  19413. */
  19414. /**
  19415. * Retrigger the `volumechange` event that was triggered by the {@link Tech}.
  19416. *
  19417. * @private
  19418. * @method Player#handleTechVolumechange_
  19419. * @fires Player#volumechange
  19420. * @listens Tech#volumechange
  19421. */
  19422. 'volumechange',
  19423. /**
  19424. * Fires when the text track has been changed
  19425. *
  19426. * @event Player#texttrackchange
  19427. * @type {event}
  19428. */
  19429. /**
  19430. * Retrigger the `texttrackchange` event that was triggered by the {@link Tech}.
  19431. *
  19432. * @private
  19433. * @method Player#handleTechTexttrackchange_
  19434. * @fires Player#texttrackchange
  19435. * @listens Tech#texttrackchange
  19436. */
  19437. 'texttrackchange']; // events to queue when playback rate is zero
  19438. // this is a hash for the sole purpose of mapping non-camel-cased event names
  19439. // to camel-cased function names
  19440. var TECH_EVENTS_QUEUE = {
  19441. canplay: 'CanPlay',
  19442. canplaythrough: 'CanPlayThrough',
  19443. playing: 'Playing',
  19444. seeked: 'Seeked'
  19445. };
  19446. var BREAKPOINT_ORDER = ['tiny', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'huge'];
  19447. var BREAKPOINT_CLASSES = {}; // grep: vjs-layout-tiny
  19448. // grep: vjs-layout-x-small
  19449. // grep: vjs-layout-small
  19450. // grep: vjs-layout-medium
  19451. // grep: vjs-layout-large
  19452. // grep: vjs-layout-x-large
  19453. // grep: vjs-layout-huge
  19454. BREAKPOINT_ORDER.forEach(function (k) {
  19455. var v = k.charAt(0) === 'x' ? "x-" + k.substring(1) : k;
  19456. BREAKPOINT_CLASSES[k] = "vjs-layout-" + v;
  19457. });
  19458. var DEFAULT_BREAKPOINTS = {
  19459. tiny: 210,
  19460. xsmall: 320,
  19461. small: 425,
  19462. medium: 768,
  19463. large: 1440,
  19464. xlarge: 2560,
  19465. huge: Infinity
  19466. };
  19467. /**
  19468. * An instance of the `Player` class is created when any of the Video.js setup methods
  19469. * are used to initialize a video.
  19470. *
  19471. * After an instance has been created it can be accessed globally in two ways:
  19472. * 1. By calling `videojs('example_video_1');`
  19473. * 2. By using it directly via `videojs.players.example_video_1;`
  19474. *
  19475. * @extends Component
  19476. */
  19477. var Player = /*#__PURE__*/function (_Component) {
  19478. inheritsLoose(Player, _Component);
  19479. /**
  19480. * Create an instance of this class.
  19481. *
  19482. * @param {Element} tag
  19483. * The original video DOM element used for configuring options.
  19484. *
  19485. * @param {Object} [options]
  19486. * Object of option names and values.
  19487. *
  19488. * @param {Component~ReadyCallback} [ready]
  19489. * Ready callback function.
  19490. */
  19491. function Player(tag, options, ready) {
  19492. var _this;
  19493. // Make sure tag ID exists
  19494. tag.id = tag.id || options.id || "vjs_video_" + newGUID(); // Set Options
  19495. // The options argument overrides options set in the video tag
  19496. // which overrides globally set options.
  19497. // This latter part coincides with the load order
  19498. // (tag must exist before Player)
  19499. options = assign(Player.getTagSettings(tag), options); // Delay the initialization of children because we need to set up
  19500. // player properties first, and can't use `this` before `super()`
  19501. options.initChildren = false; // Same with creating the element
  19502. options.createEl = false; // don't auto mixin the evented mixin
  19503. options.evented = false; // we don't want the player to report touch activity on itself
  19504. // see enableTouchActivity in Component
  19505. options.reportTouchActivity = false; // If language is not set, get the closest lang attribute
  19506. if (!options.language) {
  19507. if (typeof tag.closest === 'function') {
  19508. var closest = tag.closest('[lang]');
  19509. if (closest && closest.getAttribute) {
  19510. options.language = closest.getAttribute('lang');
  19511. }
  19512. } else {
  19513. var element = tag;
  19514. while (element && element.nodeType === 1) {
  19515. if (getAttributes(element).hasOwnProperty('lang')) {
  19516. options.language = element.getAttribute('lang');
  19517. break;
  19518. }
  19519. element = element.parentNode;
  19520. }
  19521. }
  19522. } // Run base component initializing with new options
  19523. _this = _Component.call(this, null, options, ready) || this; // Create bound methods for document listeners.
  19524. _this.boundDocumentFullscreenChange_ = function (e) {
  19525. return _this.documentFullscreenChange_(e);
  19526. };
  19527. _this.boundFullWindowOnEscKey_ = function (e) {
  19528. return _this.fullWindowOnEscKey(e);
  19529. };
  19530. _this.boundUpdateStyleEl_ = function (e) {
  19531. return _this.updateStyleEl_(e);
  19532. };
  19533. _this.boundApplyInitTime_ = function (e) {
  19534. return _this.applyInitTime_(e);
  19535. };
  19536. _this.boundUpdateCurrentBreakpoint_ = function (e) {
  19537. return _this.updateCurrentBreakpoint_(e);
  19538. };
  19539. _this.boundHandleTechClick_ = function (e) {
  19540. return _this.handleTechClick_(e);
  19541. };
  19542. _this.boundHandleTechDoubleClick_ = function (e) {
  19543. return _this.handleTechDoubleClick_(e);
  19544. };
  19545. _this.boundHandleTechTouchStart_ = function (e) {
  19546. return _this.handleTechTouchStart_(e);
  19547. };
  19548. _this.boundHandleTechTouchMove_ = function (e) {
  19549. return _this.handleTechTouchMove_(e);
  19550. };
  19551. _this.boundHandleTechTouchEnd_ = function (e) {
  19552. return _this.handleTechTouchEnd_(e);
  19553. };
  19554. _this.boundHandleTechTap_ = function (e) {
  19555. return _this.handleTechTap_(e);
  19556. }; // default isFullscreen_ to false
  19557. _this.isFullscreen_ = false; // create logger
  19558. _this.log = createLogger(_this.id_); // Hold our own reference to fullscreen api so it can be mocked in tests
  19559. _this.fsApi_ = FullscreenApi; // Tracks when a tech changes the poster
  19560. _this.isPosterFromTech_ = false; // Holds callback info that gets queued when playback rate is zero
  19561. // and a seek is happening
  19562. _this.queuedCallbacks_ = []; // Turn off API access because we're loading a new tech that might load asynchronously
  19563. _this.isReady_ = false; // Init state hasStarted_
  19564. _this.hasStarted_ = false; // Init state userActive_
  19565. _this.userActive_ = false; // Init debugEnabled_
  19566. _this.debugEnabled_ = false; // Init state audioOnlyMode_
  19567. _this.audioOnlyMode_ = false; // Init state audioPosterMode_
  19568. _this.audioPosterMode_ = false; // Init state audioOnlyCache_
  19569. _this.audioOnlyCache_ = {
  19570. playerHeight: null,
  19571. hiddenChildren: []
  19572. }; // if the global option object was accidentally blown away by
  19573. // someone, bail early with an informative error
  19574. if (!_this.options_ || !_this.options_.techOrder || !_this.options_.techOrder.length) {
  19575. throw new Error('No techOrder specified. Did you overwrite ' + 'videojs.options instead of just changing the ' + 'properties you want to override?');
  19576. } // Store the original tag used to set options
  19577. _this.tag = tag; // Store the tag attributes used to restore html5 element
  19578. _this.tagAttributes = tag && getAttributes(tag); // Update current language
  19579. _this.language(_this.options_.language); // Update Supported Languages
  19580. if (options.languages) {
  19581. // Normalise player option languages to lowercase
  19582. var languagesToLower = {};
  19583. Object.getOwnPropertyNames(options.languages).forEach(function (name) {
  19584. languagesToLower[name.toLowerCase()] = options.languages[name];
  19585. });
  19586. _this.languages_ = languagesToLower;
  19587. } else {
  19588. _this.languages_ = Player.prototype.options_.languages;
  19589. }
  19590. _this.resetCache_(); // Set poster
  19591. _this.poster_ = options.poster || ''; // Set controls
  19592. _this.controls_ = !!options.controls; // Original tag settings stored in options
  19593. // now remove immediately so native controls don't flash.
  19594. // May be turned back on by HTML5 tech if nativeControlsForTouch is true
  19595. tag.controls = false;
  19596. tag.removeAttribute('controls');
  19597. _this.changingSrc_ = false;
  19598. _this.playCallbacks_ = [];
  19599. _this.playTerminatedQueue_ = []; // the attribute overrides the option
  19600. if (tag.hasAttribute('autoplay')) {
  19601. _this.autoplay(true);
  19602. } else {
  19603. // otherwise use the setter to validate and
  19604. // set the correct value.
  19605. _this.autoplay(_this.options_.autoplay);
  19606. } // check plugins
  19607. if (options.plugins) {
  19608. Object.keys(options.plugins).forEach(function (name) {
  19609. if (typeof _this[name] !== 'function') {
  19610. throw new Error("plugin \"" + name + "\" does not exist");
  19611. }
  19612. });
  19613. }
  19614. /*
  19615. * Store the internal state of scrubbing
  19616. *
  19617. * @private
  19618. * @return {Boolean} True if the user is scrubbing
  19619. */
  19620. _this.scrubbing_ = false;
  19621. _this.el_ = _this.createEl(); // Make this an evented object and use `el_` as its event bus.
  19622. evented(assertThisInitialized(_this), {
  19623. eventBusKey: 'el_'
  19624. }); // listen to document and player fullscreenchange handlers so we receive those events
  19625. // before a user can receive them so we can update isFullscreen appropriately.
  19626. // make sure that we listen to fullscreenchange events before everything else to make sure that
  19627. // our isFullscreen method is updated properly for internal components as well as external.
  19628. if (_this.fsApi_.requestFullscreen) {
  19629. on(document, _this.fsApi_.fullscreenchange, _this.boundDocumentFullscreenChange_);
  19630. _this.on(_this.fsApi_.fullscreenchange, _this.boundDocumentFullscreenChange_);
  19631. }
  19632. if (_this.fluid_) {
  19633. _this.on(['playerreset', 'resize'], _this.boundUpdateStyleEl_);
  19634. } // We also want to pass the original player options to each component and plugin
  19635. // as well so they don't need to reach back into the player for options later.
  19636. // We also need to do another copy of this.options_ so we don't end up with
  19637. // an infinite loop.
  19638. var playerOptionsCopy = mergeOptions(_this.options_); // Load plugins
  19639. if (options.plugins) {
  19640. Object.keys(options.plugins).forEach(function (name) {
  19641. _this[name](options.plugins[name]);
  19642. });
  19643. } // Enable debug mode to fire debugon event for all plugins.
  19644. if (options.debug) {
  19645. _this.debug(true);
  19646. }
  19647. _this.options_.playerOptions = playerOptionsCopy;
  19648. _this.middleware_ = [];
  19649. _this.playbackRates(options.playbackRates);
  19650. _this.initChildren(); // Set isAudio based on whether or not an audio tag was used
  19651. _this.isAudio(tag.nodeName.toLowerCase() === 'audio'); // Update controls className. Can't do this when the controls are initially
  19652. // set because the element doesn't exist yet.
  19653. if (_this.controls()) {
  19654. _this.addClass('vjs-controls-enabled');
  19655. } else {
  19656. _this.addClass('vjs-controls-disabled');
  19657. } // Set ARIA label and region role depending on player type
  19658. _this.el_.setAttribute('role', 'region');
  19659. if (_this.isAudio()) {
  19660. _this.el_.setAttribute('aria-label', _this.localize('Audio Player'));
  19661. } else {
  19662. _this.el_.setAttribute('aria-label', _this.localize('Video Player'));
  19663. }
  19664. if (_this.isAudio()) {
  19665. _this.addClass('vjs-audio');
  19666. }
  19667. if (_this.flexNotSupported_()) {
  19668. _this.addClass('vjs-no-flex');
  19669. } // TODO: Make this smarter. Toggle user state between touching/mousing
  19670. // using events, since devices can have both touch and mouse events.
  19671. // TODO: Make this check be performed again when the window switches between monitors
  19672. // (See https://github.com/videojs/video.js/issues/5683)
  19673. if (TOUCH_ENABLED) {
  19674. _this.addClass('vjs-touch-enabled');
  19675. } // iOS Safari has broken hover handling
  19676. if (!IS_IOS) {
  19677. _this.addClass('vjs-workinghover');
  19678. } // Make player easily findable by ID
  19679. Player.players[_this.id_] = assertThisInitialized(_this); // Add a major version class to aid css in plugins
  19680. var majorVersion = version.split('.')[0];
  19681. _this.addClass("vjs-v" + majorVersion); // When the player is first initialized, trigger activity so components
  19682. // like the control bar show themselves if needed
  19683. _this.userActive(true);
  19684. _this.reportUserActivity();
  19685. _this.one('play', function (e) {
  19686. return _this.listenForUserActivity_(e);
  19687. });
  19688. _this.on('stageclick', function (e) {
  19689. return _this.handleStageClick_(e);
  19690. });
  19691. _this.on('keydown', function (e) {
  19692. return _this.handleKeyDown(e);
  19693. });
  19694. _this.on('languagechange', function (e) {
  19695. return _this.handleLanguagechange(e);
  19696. });
  19697. _this.breakpoints(_this.options_.breakpoints);
  19698. _this.responsive(_this.options_.responsive); // Calling both the audio mode methods after the player is fully
  19699. // setup to be able to listen to the events triggered by them
  19700. _this.on('ready', function () {
  19701. // Calling the audioPosterMode method first so that
  19702. // the audioOnlyMode can take precedence when both options are set to true
  19703. _this.audioPosterMode(_this.options_.audioPosterMode);
  19704. _this.audioOnlyMode(_this.options_.audioOnlyMode);
  19705. });
  19706. return _this;
  19707. }
  19708. /**
  19709. * Destroys the video player and does any necessary cleanup.
  19710. *
  19711. * This is especially helpful if you are dynamically adding and removing videos
  19712. * to/from the DOM.
  19713. *
  19714. * @fires Player#dispose
  19715. */
  19716. var _proto = Player.prototype;
  19717. _proto.dispose = function dispose() {
  19718. var _this2 = this;
  19719. /**
  19720. * Called when the player is being disposed of.
  19721. *
  19722. * @event Player#dispose
  19723. * @type {EventTarget~Event}
  19724. */
  19725. this.trigger('dispose'); // prevent dispose from being called twice
  19726. this.off('dispose'); // Make sure all player-specific document listeners are unbound. This is
  19727. off(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_);
  19728. off(document, 'keydown', this.boundFullWindowOnEscKey_);
  19729. if (this.styleEl_ && this.styleEl_.parentNode) {
  19730. this.styleEl_.parentNode.removeChild(this.styleEl_);
  19731. this.styleEl_ = null;
  19732. } // Kill reference to this player
  19733. Player.players[this.id_] = null;
  19734. if (this.tag && this.tag.player) {
  19735. this.tag.player = null;
  19736. }
  19737. if (this.el_ && this.el_.player) {
  19738. this.el_.player = null;
  19739. }
  19740. if (this.tech_) {
  19741. this.tech_.dispose();
  19742. this.isPosterFromTech_ = false;
  19743. this.poster_ = '';
  19744. }
  19745. if (this.playerElIngest_) {
  19746. this.playerElIngest_ = null;
  19747. }
  19748. if (this.tag) {
  19749. this.tag = null;
  19750. }
  19751. clearCacheForPlayer(this); // remove all event handlers for track lists
  19752. // all tracks and track listeners are removed on
  19753. // tech dispose
  19754. ALL.names.forEach(function (name) {
  19755. var props = ALL[name];
  19756. var list = _this2[props.getterName](); // if it is not a native list
  19757. // we have to manually remove event listeners
  19758. if (list && list.off) {
  19759. list.off();
  19760. }
  19761. }); // the actual .el_ is removed here, or replaced if
  19762. _Component.prototype.dispose.call(this, {
  19763. restoreEl: this.options_.restoreEl
  19764. });
  19765. }
  19766. /**
  19767. * Create the `Player`'s DOM element.
  19768. *
  19769. * @return {Element}
  19770. * The DOM element that gets created.
  19771. */
  19772. ;
  19773. _proto.createEl = function createEl() {
  19774. var tag = this.tag;
  19775. var el;
  19776. var playerElIngest = this.playerElIngest_ = tag.parentNode && tag.parentNode.hasAttribute && tag.parentNode.hasAttribute('data-vjs-player');
  19777. var divEmbed = this.tag.tagName.toLowerCase() === 'video-js';
  19778. if (playerElIngest) {
  19779. el = this.el_ = tag.parentNode;
  19780. } else if (!divEmbed) {
  19781. el = this.el_ = _Component.prototype.createEl.call(this, 'div');
  19782. } // Copy over all the attributes from the tag, including ID and class
  19783. // ID will now reference player box, not the video tag
  19784. var attrs = getAttributes(tag);
  19785. if (divEmbed) {
  19786. el = this.el_ = tag;
  19787. tag = this.tag = document.createElement('video');
  19788. while (el.children.length) {
  19789. tag.appendChild(el.firstChild);
  19790. }
  19791. if (!hasClass(el, 'video-js')) {
  19792. addClass(el, 'video-js');
  19793. }
  19794. el.appendChild(tag);
  19795. playerElIngest = this.playerElIngest_ = el; // move properties over from our custom `video-js` element
  19796. // to our new `video` element. This will move things like
  19797. // `src` or `controls` that were set via js before the player
  19798. // was initialized.
  19799. Object.keys(el).forEach(function (k) {
  19800. try {
  19801. tag[k] = el[k];
  19802. } catch (e) {// we got a a property like outerHTML which we can't actually copy, ignore it
  19803. }
  19804. });
  19805. } // set tabindex to -1 to remove the video element from the focus order
  19806. tag.setAttribute('tabindex', '-1');
  19807. attrs.tabindex = '-1'; // Workaround for #4583 (JAWS+IE doesn't announce BPB or play button), and
  19808. // for the same issue with Chrome (on Windows) with JAWS.
  19809. // See https://github.com/FreedomScientific/VFO-standards-support/issues/78
  19810. // Note that we can't detect if JAWS is being used, but this ARIA attribute
  19811. // doesn't change behavior of IE11 or Chrome if JAWS is not being used
  19812. if (IE_VERSION || IS_CHROME && IS_WINDOWS) {
  19813. tag.setAttribute('role', 'application');
  19814. attrs.role = 'application';
  19815. } // Remove width/height attrs from tag so CSS can make it 100% width/height
  19816. tag.removeAttribute('width');
  19817. tag.removeAttribute('height');
  19818. if ('width' in attrs) {
  19819. delete attrs.width;
  19820. }
  19821. if ('height' in attrs) {
  19822. delete attrs.height;
  19823. }
  19824. Object.getOwnPropertyNames(attrs).forEach(function (attr) {
  19825. // don't copy over the class attribute to the player element when we're in a div embed
  19826. // the class is already set up properly in the divEmbed case
  19827. // and we want to make sure that the `video-js` class doesn't get lost
  19828. if (!(divEmbed && attr === 'class')) {
  19829. el.setAttribute(attr, attrs[attr]);
  19830. }
  19831. if (divEmbed) {
  19832. tag.setAttribute(attr, attrs[attr]);
  19833. }
  19834. }); // Update tag id/class for use as HTML5 playback tech
  19835. // Might think we should do this after embedding in container so .vjs-tech class
  19836. // doesn't flash 100% width/height, but class only applies with .video-js parent
  19837. tag.playerId = tag.id;
  19838. tag.id += '_html5_api';
  19839. tag.className = 'vjs-tech'; // Make player findable on elements
  19840. tag.player = el.player = this; // Default state of video is paused
  19841. this.addClass('vjs-paused'); // Add a style element in the player that we'll use to set the width/height
  19842. // of the player in a way that's still overrideable by CSS, just like the
  19843. // video element
  19844. if (window.VIDEOJS_NO_DYNAMIC_STYLE !== true) {
  19845. this.styleEl_ = createStyleElement('vjs-styles-dimensions');
  19846. var defaultsStyleEl = $('.vjs-styles-defaults');
  19847. var head = $('head');
  19848. head.insertBefore(this.styleEl_, defaultsStyleEl ? defaultsStyleEl.nextSibling : head.firstChild);
  19849. }
  19850. this.fill_ = false;
  19851. this.fluid_ = false; // Pass in the width/height/aspectRatio options which will update the style el
  19852. this.width(this.options_.width);
  19853. this.height(this.options_.height);
  19854. this.fill(this.options_.fill);
  19855. this.fluid(this.options_.fluid);
  19856. this.aspectRatio(this.options_.aspectRatio); // support both crossOrigin and crossorigin to reduce confusion and issues around the name
  19857. this.crossOrigin(this.options_.crossOrigin || this.options_.crossorigin); // Hide any links within the video/audio tag,
  19858. // because IE doesn't hide them completely from screen readers.
  19859. var links = tag.getElementsByTagName('a');
  19860. for (var i = 0; i < links.length; i++) {
  19861. var linkEl = links.item(i);
  19862. addClass(linkEl, 'vjs-hidden');
  19863. linkEl.setAttribute('hidden', 'hidden');
  19864. } // insertElFirst seems to cause the networkState to flicker from 3 to 2, so
  19865. // keep track of the original for later so we can know if the source originally failed
  19866. tag.initNetworkState_ = tag.networkState; // Wrap video tag in div (el/box) container
  19867. if (tag.parentNode && !playerElIngest) {
  19868. tag.parentNode.insertBefore(el, tag);
  19869. } // insert the tag as the first child of the player element
  19870. // then manually add it to the children array so that this.addChild
  19871. // will work properly for other components
  19872. //
  19873. // Breaks iPhone, fixed in HTML5 setup.
  19874. prependTo(tag, el);
  19875. this.children_.unshift(tag); // Set lang attr on player to ensure CSS :lang() in consistent with player
  19876. // if it's been set to something different to the doc
  19877. this.el_.setAttribute('lang', this.language_);
  19878. this.el_.setAttribute('translate', 'no');
  19879. this.el_ = el;
  19880. return el;
  19881. }
  19882. /**
  19883. * Get or set the `Player`'s crossOrigin option. For the HTML5 player, this
  19884. * sets the `crossOrigin` property on the `<video>` tag to control the CORS
  19885. * behavior.
  19886. *
  19887. * @see [Video Element Attributes]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin}
  19888. *
  19889. * @param {string} [value]
  19890. * The value to set the `Player`'s crossOrigin to. If an argument is
  19891. * given, must be one of `anonymous` or `use-credentials`.
  19892. *
  19893. * @return {string|undefined}
  19894. * - The current crossOrigin value of the `Player` when getting.
  19895. * - undefined when setting
  19896. */
  19897. ;
  19898. _proto.crossOrigin = function crossOrigin(value) {
  19899. if (!value) {
  19900. return this.techGet_('crossOrigin');
  19901. }
  19902. if (value !== 'anonymous' && value !== 'use-credentials') {
  19903. log.warn("crossOrigin must be \"anonymous\" or \"use-credentials\", given \"" + value + "\"");
  19904. return;
  19905. }
  19906. this.techCall_('setCrossOrigin', value);
  19907. return;
  19908. }
  19909. /**
  19910. * A getter/setter for the `Player`'s width. Returns the player's configured value.
  19911. * To get the current width use `currentWidth()`.
  19912. *
  19913. * @param {number} [value]
  19914. * The value to set the `Player`'s width to.
  19915. *
  19916. * @return {number}
  19917. * The current width of the `Player` when getting.
  19918. */
  19919. ;
  19920. _proto.width = function width(value) {
  19921. return this.dimension('width', value);
  19922. }
  19923. /**
  19924. * A getter/setter for the `Player`'s height. Returns the player's configured value.
  19925. * To get the current height use `currentheight()`.
  19926. *
  19927. * @param {number} [value]
  19928. * The value to set the `Player`'s heigth to.
  19929. *
  19930. * @return {number}
  19931. * The current height of the `Player` when getting.
  19932. */
  19933. ;
  19934. _proto.height = function height(value) {
  19935. return this.dimension('height', value);
  19936. }
  19937. /**
  19938. * A getter/setter for the `Player`'s width & height.
  19939. *
  19940. * @param {string} dimension
  19941. * This string can be:
  19942. * - 'width'
  19943. * - 'height'
  19944. *
  19945. * @param {number} [value]
  19946. * Value for dimension specified in the first argument.
  19947. *
  19948. * @return {number}
  19949. * The dimension arguments value when getting (width/height).
  19950. */
  19951. ;
  19952. _proto.dimension = function dimension(_dimension, value) {
  19953. var privDimension = _dimension + '_';
  19954. if (value === undefined) {
  19955. return this[privDimension] || 0;
  19956. }
  19957. if (value === '' || value === 'auto') {
  19958. // If an empty string is given, reset the dimension to be automatic
  19959. this[privDimension] = undefined;
  19960. this.updateStyleEl_();
  19961. return;
  19962. }
  19963. var parsedVal = parseFloat(value);
  19964. if (isNaN(parsedVal)) {
  19965. log.error("Improper value \"" + value + "\" supplied for for " + _dimension);
  19966. return;
  19967. }
  19968. this[privDimension] = parsedVal;
  19969. this.updateStyleEl_();
  19970. }
  19971. /**
  19972. * A getter/setter/toggler for the vjs-fluid `className` on the `Player`.
  19973. *
  19974. * Turning this on will turn off fill mode.
  19975. *
  19976. * @param {boolean} [bool]
  19977. * - A value of true adds the class.
  19978. * - A value of false removes the class.
  19979. * - No value will be a getter.
  19980. *
  19981. * @return {boolean|undefined}
  19982. * - The value of fluid when getting.
  19983. * - `undefined` when setting.
  19984. */
  19985. ;
  19986. _proto.fluid = function fluid(bool) {
  19987. var _this3 = this;
  19988. if (bool === undefined) {
  19989. return !!this.fluid_;
  19990. }
  19991. this.fluid_ = !!bool;
  19992. if (isEvented(this)) {
  19993. this.off(['playerreset', 'resize'], this.boundUpdateStyleEl_);
  19994. }
  19995. if (bool) {
  19996. this.addClass('vjs-fluid');
  19997. this.fill(false);
  19998. addEventedCallback(this, function () {
  19999. _this3.on(['playerreset', 'resize'], _this3.boundUpdateStyleEl_);
  20000. });
  20001. } else {
  20002. this.removeClass('vjs-fluid');
  20003. }
  20004. this.updateStyleEl_();
  20005. }
  20006. /**
  20007. * A getter/setter/toggler for the vjs-fill `className` on the `Player`.
  20008. *
  20009. * Turning this on will turn off fluid mode.
  20010. *
  20011. * @param {boolean} [bool]
  20012. * - A value of true adds the class.
  20013. * - A value of false removes the class.
  20014. * - No value will be a getter.
  20015. *
  20016. * @return {boolean|undefined}
  20017. * - The value of fluid when getting.
  20018. * - `undefined` when setting.
  20019. */
  20020. ;
  20021. _proto.fill = function fill(bool) {
  20022. if (bool === undefined) {
  20023. return !!this.fill_;
  20024. }
  20025. this.fill_ = !!bool;
  20026. if (bool) {
  20027. this.addClass('vjs-fill');
  20028. this.fluid(false);
  20029. } else {
  20030. this.removeClass('vjs-fill');
  20031. }
  20032. }
  20033. /**
  20034. * Get/Set the aspect ratio
  20035. *
  20036. * @param {string} [ratio]
  20037. * Aspect ratio for player
  20038. *
  20039. * @return {string|undefined}
  20040. * returns the current aspect ratio when getting
  20041. */
  20042. /**
  20043. * A getter/setter for the `Player`'s aspect ratio.
  20044. *
  20045. * @param {string} [ratio]
  20046. * The value to set the `Player`'s aspect ratio to.
  20047. *
  20048. * @return {string|undefined}
  20049. * - The current aspect ratio of the `Player` when getting.
  20050. * - undefined when setting
  20051. */
  20052. ;
  20053. _proto.aspectRatio = function aspectRatio(ratio) {
  20054. if (ratio === undefined) {
  20055. return this.aspectRatio_;
  20056. } // Check for width:height format
  20057. if (!/^\d+\:\d+$/.test(ratio)) {
  20058. throw new Error('Improper value supplied for aspect ratio. The format should be width:height, for example 16:9.');
  20059. }
  20060. this.aspectRatio_ = ratio; // We're assuming if you set an aspect ratio you want fluid mode,
  20061. // because in fixed mode you could calculate width and height yourself.
  20062. this.fluid(true);
  20063. this.updateStyleEl_();
  20064. }
  20065. /**
  20066. * Update styles of the `Player` element (height, width and aspect ratio).
  20067. *
  20068. * @private
  20069. * @listens Tech#loadedmetadata
  20070. */
  20071. ;
  20072. _proto.updateStyleEl_ = function updateStyleEl_() {
  20073. if (window.VIDEOJS_NO_DYNAMIC_STYLE === true) {
  20074. var _width = typeof this.width_ === 'number' ? this.width_ : this.options_.width;
  20075. var _height = typeof this.height_ === 'number' ? this.height_ : this.options_.height;
  20076. var techEl = this.tech_ && this.tech_.el();
  20077. if (techEl) {
  20078. if (_width >= 0) {
  20079. techEl.width = _width;
  20080. }
  20081. if (_height >= 0) {
  20082. techEl.height = _height;
  20083. }
  20084. }
  20085. return;
  20086. }
  20087. var width;
  20088. var height;
  20089. var aspectRatio;
  20090. var idClass; // The aspect ratio is either used directly or to calculate width and height.
  20091. if (this.aspectRatio_ !== undefined && this.aspectRatio_ !== 'auto') {
  20092. // Use any aspectRatio that's been specifically set
  20093. aspectRatio = this.aspectRatio_;
  20094. } else if (this.videoWidth() > 0) {
  20095. // Otherwise try to get the aspect ratio from the video metadata
  20096. aspectRatio = this.videoWidth() + ':' + this.videoHeight();
  20097. } else {
  20098. // Or use a default. The video element's is 2:1, but 16:9 is more common.
  20099. aspectRatio = '16:9';
  20100. } // Get the ratio as a decimal we can use to calculate dimensions
  20101. var ratioParts = aspectRatio.split(':');
  20102. var ratioMultiplier = ratioParts[1] / ratioParts[0];
  20103. if (this.width_ !== undefined) {
  20104. // Use any width that's been specifically set
  20105. width = this.width_;
  20106. } else if (this.height_ !== undefined) {
  20107. // Or calulate the width from the aspect ratio if a height has been set
  20108. width = this.height_ / ratioMultiplier;
  20109. } else {
  20110. // Or use the video's metadata, or use the video el's default of 300
  20111. width = this.videoWidth() || 300;
  20112. }
  20113. if (this.height_ !== undefined) {
  20114. // Use any height that's been specifically set
  20115. height = this.height_;
  20116. } else {
  20117. // Otherwise calculate the height from the ratio and the width
  20118. height = width * ratioMultiplier;
  20119. } // Ensure the CSS class is valid by starting with an alpha character
  20120. if (/^[^a-zA-Z]/.test(this.id())) {
  20121. idClass = 'dimensions-' + this.id();
  20122. } else {
  20123. idClass = this.id() + '-dimensions';
  20124. } // Ensure the right class is still on the player for the style element
  20125. this.addClass(idClass);
  20126. setTextContent(this.styleEl_, "\n ." + idClass + " {\n width: " + width + "px;\n height: " + height + "px;\n }\n\n ." + idClass + ".vjs-fluid:not(.vjs-audio-only-mode) {\n padding-top: " + ratioMultiplier * 100 + "%;\n }\n ");
  20127. }
  20128. /**
  20129. * Load/Create an instance of playback {@link Tech} including element
  20130. * and API methods. Then append the `Tech` element in `Player` as a child.
  20131. *
  20132. * @param {string} techName
  20133. * name of the playback technology
  20134. *
  20135. * @param {string} source
  20136. * video source
  20137. *
  20138. * @private
  20139. */
  20140. ;
  20141. _proto.loadTech_ = function loadTech_(techName, source) {
  20142. var _this4 = this;
  20143. // Pause and remove current playback technology
  20144. if (this.tech_) {
  20145. this.unloadTech_();
  20146. }
  20147. var titleTechName = toTitleCase(techName);
  20148. var camelTechName = techName.charAt(0).toLowerCase() + techName.slice(1); // get rid of the HTML5 video tag as soon as we are using another tech
  20149. if (titleTechName !== 'Html5' && this.tag) {
  20150. Tech.getTech('Html5').disposeMediaElement(this.tag);
  20151. this.tag.player = null;
  20152. this.tag = null;
  20153. }
  20154. this.techName_ = titleTechName; // Turn off API access because we're loading a new tech that might load asynchronously
  20155. this.isReady_ = false;
  20156. var autoplay = this.autoplay(); // if autoplay is a string (or `true` with normalizeAutoplay: true) we pass false to the tech
  20157. // because the player is going to handle autoplay on `loadstart`
  20158. if (typeof this.autoplay() === 'string' || this.autoplay() === true && this.options_.normalizeAutoplay) {
  20159. autoplay = false;
  20160. } // Grab tech-specific options from player options and add source and parent element to use.
  20161. var techOptions = {
  20162. source: source,
  20163. autoplay: autoplay,
  20164. 'nativeControlsForTouch': this.options_.nativeControlsForTouch,
  20165. 'playerId': this.id(),
  20166. 'techId': this.id() + "_" + camelTechName + "_api",
  20167. 'playsinline': this.options_.playsinline,
  20168. 'preload': this.options_.preload,
  20169. 'loop': this.options_.loop,
  20170. 'disablePictureInPicture': this.options_.disablePictureInPicture,
  20171. 'muted': this.options_.muted,
  20172. 'poster': this.poster(),
  20173. 'language': this.language(),
  20174. 'playerElIngest': this.playerElIngest_ || false,
  20175. 'vtt.js': this.options_['vtt.js'],
  20176. 'canOverridePoster': !!this.options_.techCanOverridePoster,
  20177. 'enableSourceset': this.options_.enableSourceset,
  20178. 'Promise': this.options_.Promise
  20179. };
  20180. ALL.names.forEach(function (name) {
  20181. var props = ALL[name];
  20182. techOptions[props.getterName] = _this4[props.privateName];
  20183. });
  20184. assign(techOptions, this.options_[titleTechName]);
  20185. assign(techOptions, this.options_[camelTechName]);
  20186. assign(techOptions, this.options_[techName.toLowerCase()]);
  20187. if (this.tag) {
  20188. techOptions.tag = this.tag;
  20189. }
  20190. if (source && source.src === this.cache_.src && this.cache_.currentTime > 0) {
  20191. techOptions.startTime = this.cache_.currentTime;
  20192. } // Initialize tech instance
  20193. var TechClass = Tech.getTech(techName);
  20194. if (!TechClass) {
  20195. throw new Error("No Tech named '" + titleTechName + "' exists! '" + titleTechName + "' should be registered using videojs.registerTech()'");
  20196. }
  20197. this.tech_ = new TechClass(techOptions); // player.triggerReady is always async, so don't need this to be async
  20198. this.tech_.ready(bind(this, this.handleTechReady_), true);
  20199. textTrackConverter.jsonToTextTracks(this.textTracksJson_ || [], this.tech_); // Listen to all HTML5-defined events and trigger them on the player
  20200. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  20201. _this4.on(_this4.tech_, event, function (e) {
  20202. return _this4["handleTech" + toTitleCase(event) + "_"](e);
  20203. });
  20204. });
  20205. Object.keys(TECH_EVENTS_QUEUE).forEach(function (event) {
  20206. _this4.on(_this4.tech_, event, function (eventObj) {
  20207. if (_this4.tech_.playbackRate() === 0 && _this4.tech_.seeking()) {
  20208. _this4.queuedCallbacks_.push({
  20209. callback: _this4["handleTech" + TECH_EVENTS_QUEUE[event] + "_"].bind(_this4),
  20210. event: eventObj
  20211. });
  20212. return;
  20213. }
  20214. _this4["handleTech" + TECH_EVENTS_QUEUE[event] + "_"](eventObj);
  20215. });
  20216. });
  20217. this.on(this.tech_, 'loadstart', function (e) {
  20218. return _this4.handleTechLoadStart_(e);
  20219. });
  20220. this.on(this.tech_, 'sourceset', function (e) {
  20221. return _this4.handleTechSourceset_(e);
  20222. });
  20223. this.on(this.tech_, 'waiting', function (e) {
  20224. return _this4.handleTechWaiting_(e);
  20225. });
  20226. this.on(this.tech_, 'ended', function (e) {
  20227. return _this4.handleTechEnded_(e);
  20228. });
  20229. this.on(this.tech_, 'seeking', function (e) {
  20230. return _this4.handleTechSeeking_(e);
  20231. });
  20232. this.on(this.tech_, 'play', function (e) {
  20233. return _this4.handleTechPlay_(e);
  20234. });
  20235. this.on(this.tech_, 'firstplay', function (e) {
  20236. return _this4.handleTechFirstPlay_(e);
  20237. });
  20238. this.on(this.tech_, 'pause', function (e) {
  20239. return _this4.handleTechPause_(e);
  20240. });
  20241. this.on(this.tech_, 'durationchange', function (e) {
  20242. return _this4.handleTechDurationChange_(e);
  20243. });
  20244. this.on(this.tech_, 'fullscreenchange', function (e, data) {
  20245. return _this4.handleTechFullscreenChange_(e, data);
  20246. });
  20247. this.on(this.tech_, 'fullscreenerror', function (e, err) {
  20248. return _this4.handleTechFullscreenError_(e, err);
  20249. });
  20250. this.on(this.tech_, 'enterpictureinpicture', function (e) {
  20251. return _this4.handleTechEnterPictureInPicture_(e);
  20252. });
  20253. this.on(this.tech_, 'leavepictureinpicture', function (e) {
  20254. return _this4.handleTechLeavePictureInPicture_(e);
  20255. });
  20256. this.on(this.tech_, 'error', function (e) {
  20257. return _this4.handleTechError_(e);
  20258. });
  20259. this.on(this.tech_, 'posterchange', function (e) {
  20260. return _this4.handleTechPosterChange_(e);
  20261. });
  20262. this.on(this.tech_, 'textdata', function (e) {
  20263. return _this4.handleTechTextData_(e);
  20264. });
  20265. this.on(this.tech_, 'ratechange', function (e) {
  20266. return _this4.handleTechRateChange_(e);
  20267. });
  20268. this.on(this.tech_, 'loadedmetadata', this.boundUpdateStyleEl_);
  20269. this.usingNativeControls(this.techGet_('controls'));
  20270. if (this.controls() && !this.usingNativeControls()) {
  20271. this.addTechControlsListeners_();
  20272. } // Add the tech element in the DOM if it was not already there
  20273. // Make sure to not insert the original video element if using Html5
  20274. if (this.tech_.el().parentNode !== this.el() && (titleTechName !== 'Html5' || !this.tag)) {
  20275. prependTo(this.tech_.el(), this.el());
  20276. } // Get rid of the original video tag reference after the first tech is loaded
  20277. if (this.tag) {
  20278. this.tag.player = null;
  20279. this.tag = null;
  20280. }
  20281. }
  20282. /**
  20283. * Unload and dispose of the current playback {@link Tech}.
  20284. *
  20285. * @private
  20286. */
  20287. ;
  20288. _proto.unloadTech_ = function unloadTech_() {
  20289. var _this5 = this;
  20290. // Save the current text tracks so that we can reuse the same text tracks with the next tech
  20291. ALL.names.forEach(function (name) {
  20292. var props = ALL[name];
  20293. _this5[props.privateName] = _this5[props.getterName]();
  20294. });
  20295. this.textTracksJson_ = textTrackConverter.textTracksToJson(this.tech_);
  20296. this.isReady_ = false;
  20297. this.tech_.dispose();
  20298. this.tech_ = false;
  20299. if (this.isPosterFromTech_) {
  20300. this.poster_ = '';
  20301. this.trigger('posterchange');
  20302. }
  20303. this.isPosterFromTech_ = false;
  20304. }
  20305. /**
  20306. * Return a reference to the current {@link Tech}.
  20307. * It will print a warning by default about the danger of using the tech directly
  20308. * but any argument that is passed in will silence the warning.
  20309. *
  20310. * @param {*} [safety]
  20311. * Anything passed in to silence the warning
  20312. *
  20313. * @return {Tech}
  20314. * The Tech
  20315. */
  20316. ;
  20317. _proto.tech = function tech(safety) {
  20318. if (safety === undefined) {
  20319. log.warn('Using the tech directly can be dangerous. I hope you know what you\'re doing.\n' + 'See https://github.com/videojs/video.js/issues/2617 for more info.\n');
  20320. }
  20321. return this.tech_;
  20322. }
  20323. /**
  20324. * Set up click and touch listeners for the playback element
  20325. *
  20326. * - On desktops: a click on the video itself will toggle playback
  20327. * - On mobile devices: a click on the video toggles controls
  20328. * which is done by toggling the user state between active and
  20329. * inactive
  20330. * - A tap can signal that a user has become active or has become inactive
  20331. * e.g. a quick tap on an iPhone movie should reveal the controls. Another
  20332. * quick tap should hide them again (signaling the user is in an inactive
  20333. * viewing state)
  20334. * - In addition to this, we still want the user to be considered inactive after
  20335. * a few seconds of inactivity.
  20336. *
  20337. * > Note: the only part of iOS interaction we can't mimic with this setup
  20338. * is a touch and hold on the video element counting as activity in order to
  20339. * keep the controls showing, but that shouldn't be an issue. A touch and hold
  20340. * on any controls will still keep the user active
  20341. *
  20342. * @private
  20343. */
  20344. ;
  20345. _proto.addTechControlsListeners_ = function addTechControlsListeners_() {
  20346. // Make sure to remove all the previous listeners in case we are called multiple times.
  20347. this.removeTechControlsListeners_();
  20348. this.on(this.tech_, 'click', this.boundHandleTechClick_);
  20349. this.on(this.tech_, 'dblclick', this.boundHandleTechDoubleClick_); // If the controls were hidden we don't want that to change without a tap event
  20350. // so we'll check if the controls were already showing before reporting user
  20351. // activity
  20352. this.on(this.tech_, 'touchstart', this.boundHandleTechTouchStart_);
  20353. this.on(this.tech_, 'touchmove', this.boundHandleTechTouchMove_);
  20354. this.on(this.tech_, 'touchend', this.boundHandleTechTouchEnd_); // The tap listener needs to come after the touchend listener because the tap
  20355. // listener cancels out any reportedUserActivity when setting userActive(false)
  20356. this.on(this.tech_, 'tap', this.boundHandleTechTap_);
  20357. }
  20358. /**
  20359. * Remove the listeners used for click and tap controls. This is needed for
  20360. * toggling to controls disabled, where a tap/touch should do nothing.
  20361. *
  20362. * @private
  20363. */
  20364. ;
  20365. _proto.removeTechControlsListeners_ = function removeTechControlsListeners_() {
  20366. // We don't want to just use `this.off()` because there might be other needed
  20367. // listeners added by techs that extend this.
  20368. this.off(this.tech_, 'tap', this.boundHandleTechTap_);
  20369. this.off(this.tech_, 'touchstart', this.boundHandleTechTouchStart_);
  20370. this.off(this.tech_, 'touchmove', this.boundHandleTechTouchMove_);
  20371. this.off(this.tech_, 'touchend', this.boundHandleTechTouchEnd_);
  20372. this.off(this.tech_, 'click', this.boundHandleTechClick_);
  20373. this.off(this.tech_, 'dblclick', this.boundHandleTechDoubleClick_);
  20374. }
  20375. /**
  20376. * Player waits for the tech to be ready
  20377. *
  20378. * @private
  20379. */
  20380. ;
  20381. _proto.handleTechReady_ = function handleTechReady_() {
  20382. this.triggerReady(); // Keep the same volume as before
  20383. if (this.cache_.volume) {
  20384. this.techCall_('setVolume', this.cache_.volume);
  20385. } // Look if the tech found a higher resolution poster while loading
  20386. this.handleTechPosterChange_(); // Update the duration if available
  20387. this.handleTechDurationChange_();
  20388. }
  20389. /**
  20390. * Retrigger the `loadstart` event that was triggered by the {@link Tech}. This
  20391. * function will also trigger {@link Player#firstplay} if it is the first loadstart
  20392. * for a video.
  20393. *
  20394. * @fires Player#loadstart
  20395. * @fires Player#firstplay
  20396. * @listens Tech#loadstart
  20397. * @private
  20398. */
  20399. ;
  20400. _proto.handleTechLoadStart_ = function handleTechLoadStart_() {
  20401. // TODO: Update to use `emptied` event instead. See #1277.
  20402. this.removeClass('vjs-ended');
  20403. this.removeClass('vjs-seeking'); // reset the error state
  20404. this.error(null); // Update the duration
  20405. this.handleTechDurationChange_(); // If it's already playing we want to trigger a firstplay event now.
  20406. // The firstplay event relies on both the play and loadstart events
  20407. // which can happen in any order for a new source
  20408. if (!this.paused()) {
  20409. /**
  20410. * Fired when the user agent begins looking for media data
  20411. *
  20412. * @event Player#loadstart
  20413. * @type {EventTarget~Event}
  20414. */
  20415. this.trigger('loadstart');
  20416. this.trigger('firstplay');
  20417. } else {
  20418. // reset the hasStarted state
  20419. this.hasStarted(false);
  20420. this.trigger('loadstart');
  20421. } // autoplay happens after loadstart for the browser,
  20422. // so we mimic that behavior
  20423. this.manualAutoplay_(this.autoplay() === true && this.options_.normalizeAutoplay ? 'play' : this.autoplay());
  20424. }
  20425. /**
  20426. * Handle autoplay string values, rather than the typical boolean
  20427. * values that should be handled by the tech. Note that this is not
  20428. * part of any specification. Valid values and what they do can be
  20429. * found on the autoplay getter at Player#autoplay()
  20430. */
  20431. ;
  20432. _proto.manualAutoplay_ = function manualAutoplay_(type) {
  20433. var _this6 = this;
  20434. if (!this.tech_ || typeof type !== 'string') {
  20435. return;
  20436. } // Save original muted() value, set muted to true, and attempt to play().
  20437. // On promise rejection, restore muted from saved value
  20438. var resolveMuted = function resolveMuted() {
  20439. var previouslyMuted = _this6.muted();
  20440. _this6.muted(true);
  20441. var restoreMuted = function restoreMuted() {
  20442. _this6.muted(previouslyMuted);
  20443. }; // restore muted on play terminatation
  20444. _this6.playTerminatedQueue_.push(restoreMuted);
  20445. var mutedPromise = _this6.play();
  20446. if (!isPromise(mutedPromise)) {
  20447. return;
  20448. }
  20449. return mutedPromise["catch"](function (err) {
  20450. restoreMuted();
  20451. throw new Error("Rejection at manualAutoplay. Restoring muted value. " + (err ? err : ''));
  20452. });
  20453. };
  20454. var promise; // if muted defaults to true
  20455. // the only thing we can do is call play
  20456. if (type === 'any' && !this.muted()) {
  20457. promise = this.play();
  20458. if (isPromise(promise)) {
  20459. promise = promise["catch"](resolveMuted);
  20460. }
  20461. } else if (type === 'muted' && !this.muted()) {
  20462. promise = resolveMuted();
  20463. } else {
  20464. promise = this.play();
  20465. }
  20466. if (!isPromise(promise)) {
  20467. return;
  20468. }
  20469. return promise.then(function () {
  20470. _this6.trigger({
  20471. type: 'autoplay-success',
  20472. autoplay: type
  20473. });
  20474. })["catch"](function () {
  20475. _this6.trigger({
  20476. type: 'autoplay-failure',
  20477. autoplay: type
  20478. });
  20479. });
  20480. }
  20481. /**
  20482. * Update the internal source caches so that we return the correct source from
  20483. * `src()`, `currentSource()`, and `currentSources()`.
  20484. *
  20485. * > Note: `currentSources` will not be updated if the source that is passed in exists
  20486. * in the current `currentSources` cache.
  20487. *
  20488. *
  20489. * @param {Tech~SourceObject} srcObj
  20490. * A string or object source to update our caches to.
  20491. */
  20492. ;
  20493. _proto.updateSourceCaches_ = function updateSourceCaches_(srcObj) {
  20494. if (srcObj === void 0) {
  20495. srcObj = '';
  20496. }
  20497. var src = srcObj;
  20498. var type = '';
  20499. if (typeof src !== 'string') {
  20500. src = srcObj.src;
  20501. type = srcObj.type;
  20502. } // make sure all the caches are set to default values
  20503. // to prevent null checking
  20504. this.cache_.source = this.cache_.source || {};
  20505. this.cache_.sources = this.cache_.sources || []; // try to get the type of the src that was passed in
  20506. if (src && !type) {
  20507. type = findMimetype(this, src);
  20508. } // update `currentSource` cache always
  20509. this.cache_.source = mergeOptions({}, srcObj, {
  20510. src: src,
  20511. type: type
  20512. });
  20513. var matchingSources = this.cache_.sources.filter(function (s) {
  20514. return s.src && s.src === src;
  20515. });
  20516. var sourceElSources = [];
  20517. var sourceEls = this.$$('source');
  20518. var matchingSourceEls = [];
  20519. for (var i = 0; i < sourceEls.length; i++) {
  20520. var sourceObj = getAttributes(sourceEls[i]);
  20521. sourceElSources.push(sourceObj);
  20522. if (sourceObj.src && sourceObj.src === src) {
  20523. matchingSourceEls.push(sourceObj.src);
  20524. }
  20525. } // if we have matching source els but not matching sources
  20526. // the current source cache is not up to date
  20527. if (matchingSourceEls.length && !matchingSources.length) {
  20528. this.cache_.sources = sourceElSources; // if we don't have matching source or source els set the
  20529. // sources cache to the `currentSource` cache
  20530. } else if (!matchingSources.length) {
  20531. this.cache_.sources = [this.cache_.source];
  20532. } // update the tech `src` cache
  20533. this.cache_.src = src;
  20534. }
  20535. /**
  20536. * *EXPERIMENTAL* Fired when the source is set or changed on the {@link Tech}
  20537. * causing the media element to reload.
  20538. *
  20539. * It will fire for the initial source and each subsequent source.
  20540. * This event is a custom event from Video.js and is triggered by the {@link Tech}.
  20541. *
  20542. * The event object for this event contains a `src` property that will contain the source
  20543. * that was available when the event was triggered. This is generally only necessary if Video.js
  20544. * is switching techs while the source was being changed.
  20545. *
  20546. * It is also fired when `load` is called on the player (or media element)
  20547. * because the {@link https://html.spec.whatwg.org/multipage/media.html#dom-media-load|specification for `load`}
  20548. * says that the resource selection algorithm needs to be aborted and restarted.
  20549. * In this case, it is very likely that the `src` property will be set to the
  20550. * empty string `""` to indicate we do not know what the source will be but
  20551. * that it is changing.
  20552. *
  20553. * *This event is currently still experimental and may change in minor releases.*
  20554. * __To use this, pass `enableSourceset` option to the player.__
  20555. *
  20556. * @event Player#sourceset
  20557. * @type {EventTarget~Event}
  20558. * @prop {string} src
  20559. * The source url available when the `sourceset` was triggered.
  20560. * It will be an empty string if we cannot know what the source is
  20561. * but know that the source will change.
  20562. */
  20563. /**
  20564. * Retrigger the `sourceset` event that was triggered by the {@link Tech}.
  20565. *
  20566. * @fires Player#sourceset
  20567. * @listens Tech#sourceset
  20568. * @private
  20569. */
  20570. ;
  20571. _proto.handleTechSourceset_ = function handleTechSourceset_(event) {
  20572. var _this7 = this;
  20573. // only update the source cache when the source
  20574. // was not updated using the player api
  20575. if (!this.changingSrc_) {
  20576. var updateSourceCaches = function updateSourceCaches(src) {
  20577. return _this7.updateSourceCaches_(src);
  20578. };
  20579. var playerSrc = this.currentSource().src;
  20580. var eventSrc = event.src; // if we have a playerSrc that is not a blob, and a tech src that is a blob
  20581. if (playerSrc && !/^blob:/.test(playerSrc) && /^blob:/.test(eventSrc)) {
  20582. // if both the tech source and the player source were updated we assume
  20583. // something like @videojs/http-streaming did the sourceset and skip updating the source cache.
  20584. if (!this.lastSource_ || this.lastSource_.tech !== eventSrc && this.lastSource_.player !== playerSrc) {
  20585. updateSourceCaches = function updateSourceCaches() {};
  20586. }
  20587. } // update the source to the initial source right away
  20588. // in some cases this will be empty string
  20589. updateSourceCaches(eventSrc); // if the `sourceset` `src` was an empty string
  20590. // wait for a `loadstart` to update the cache to `currentSrc`.
  20591. // If a sourceset happens before a `loadstart`, we reset the state
  20592. if (!event.src) {
  20593. this.tech_.any(['sourceset', 'loadstart'], function (e) {
  20594. // if a sourceset happens before a `loadstart` there
  20595. // is nothing to do as this `handleTechSourceset_`
  20596. // will be called again and this will be handled there.
  20597. if (e.type === 'sourceset') {
  20598. return;
  20599. }
  20600. var techSrc = _this7.techGet('currentSrc');
  20601. _this7.lastSource_.tech = techSrc;
  20602. _this7.updateSourceCaches_(techSrc);
  20603. });
  20604. }
  20605. }
  20606. this.lastSource_ = {
  20607. player: this.currentSource().src,
  20608. tech: event.src
  20609. };
  20610. this.trigger({
  20611. src: event.src,
  20612. type: 'sourceset'
  20613. });
  20614. }
  20615. /**
  20616. * Add/remove the vjs-has-started class
  20617. *
  20618. * @fires Player#firstplay
  20619. *
  20620. * @param {boolean} request
  20621. * - true: adds the class
  20622. * - false: remove the class
  20623. *
  20624. * @return {boolean}
  20625. * the boolean value of hasStarted_
  20626. */
  20627. ;
  20628. _proto.hasStarted = function hasStarted(request) {
  20629. if (request === undefined) {
  20630. // act as getter, if we have no request to change
  20631. return this.hasStarted_;
  20632. }
  20633. if (request === this.hasStarted_) {
  20634. return;
  20635. }
  20636. this.hasStarted_ = request;
  20637. if (this.hasStarted_) {
  20638. this.addClass('vjs-has-started');
  20639. this.trigger('firstplay');
  20640. } else {
  20641. this.removeClass('vjs-has-started');
  20642. }
  20643. }
  20644. /**
  20645. * Fired whenever the media begins or resumes playback
  20646. *
  20647. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play}
  20648. * @fires Player#play
  20649. * @listens Tech#play
  20650. * @private
  20651. */
  20652. ;
  20653. _proto.handleTechPlay_ = function handleTechPlay_() {
  20654. this.removeClass('vjs-ended');
  20655. this.removeClass('vjs-paused');
  20656. this.addClass('vjs-playing'); // hide the poster when the user hits play
  20657. this.hasStarted(true);
  20658. /**
  20659. * Triggered whenever an {@link Tech#play} event happens. Indicates that
  20660. * playback has started or resumed.
  20661. *
  20662. * @event Player#play
  20663. * @type {EventTarget~Event}
  20664. */
  20665. this.trigger('play');
  20666. }
  20667. /**
  20668. * Retrigger the `ratechange` event that was triggered by the {@link Tech}.
  20669. *
  20670. * If there were any events queued while the playback rate was zero, fire
  20671. * those events now.
  20672. *
  20673. * @private
  20674. * @method Player#handleTechRateChange_
  20675. * @fires Player#ratechange
  20676. * @listens Tech#ratechange
  20677. */
  20678. ;
  20679. _proto.handleTechRateChange_ = function handleTechRateChange_() {
  20680. if (this.tech_.playbackRate() > 0 && this.cache_.lastPlaybackRate === 0) {
  20681. this.queuedCallbacks_.forEach(function (queued) {
  20682. return queued.callback(queued.event);
  20683. });
  20684. this.queuedCallbacks_ = [];
  20685. }
  20686. this.cache_.lastPlaybackRate = this.tech_.playbackRate();
  20687. /**
  20688. * Fires when the playing speed of the audio/video is changed
  20689. *
  20690. * @event Player#ratechange
  20691. * @type {event}
  20692. */
  20693. this.trigger('ratechange');
  20694. }
  20695. /**
  20696. * Retrigger the `waiting` event that was triggered by the {@link Tech}.
  20697. *
  20698. * @fires Player#waiting
  20699. * @listens Tech#waiting
  20700. * @private
  20701. */
  20702. ;
  20703. _proto.handleTechWaiting_ = function handleTechWaiting_() {
  20704. var _this8 = this;
  20705. this.addClass('vjs-waiting');
  20706. /**
  20707. * A readyState change on the DOM element has caused playback to stop.
  20708. *
  20709. * @event Player#waiting
  20710. * @type {EventTarget~Event}
  20711. */
  20712. this.trigger('waiting'); // Browsers may emit a timeupdate event after a waiting event. In order to prevent
  20713. // premature removal of the waiting class, wait for the time to change.
  20714. var timeWhenWaiting = this.currentTime();
  20715. var timeUpdateListener = function timeUpdateListener() {
  20716. if (timeWhenWaiting !== _this8.currentTime()) {
  20717. _this8.removeClass('vjs-waiting');
  20718. _this8.off('timeupdate', timeUpdateListener);
  20719. }
  20720. };
  20721. this.on('timeupdate', timeUpdateListener);
  20722. }
  20723. /**
  20724. * Retrigger the `canplay` event that was triggered by the {@link Tech}.
  20725. * > Note: This is not consistent between browsers. See #1351
  20726. *
  20727. * @fires Player#canplay
  20728. * @listens Tech#canplay
  20729. * @private
  20730. */
  20731. ;
  20732. _proto.handleTechCanPlay_ = function handleTechCanPlay_() {
  20733. this.removeClass('vjs-waiting');
  20734. /**
  20735. * The media has a readyState of HAVE_FUTURE_DATA or greater.
  20736. *
  20737. * @event Player#canplay
  20738. * @type {EventTarget~Event}
  20739. */
  20740. this.trigger('canplay');
  20741. }
  20742. /**
  20743. * Retrigger the `canplaythrough` event that was triggered by the {@link Tech}.
  20744. *
  20745. * @fires Player#canplaythrough
  20746. * @listens Tech#canplaythrough
  20747. * @private
  20748. */
  20749. ;
  20750. _proto.handleTechCanPlayThrough_ = function handleTechCanPlayThrough_() {
  20751. this.removeClass('vjs-waiting');
  20752. /**
  20753. * The media has a readyState of HAVE_ENOUGH_DATA or greater. This means that the
  20754. * entire media file can be played without buffering.
  20755. *
  20756. * @event Player#canplaythrough
  20757. * @type {EventTarget~Event}
  20758. */
  20759. this.trigger('canplaythrough');
  20760. }
  20761. /**
  20762. * Retrigger the `playing` event that was triggered by the {@link Tech}.
  20763. *
  20764. * @fires Player#playing
  20765. * @listens Tech#playing
  20766. * @private
  20767. */
  20768. ;
  20769. _proto.handleTechPlaying_ = function handleTechPlaying_() {
  20770. this.removeClass('vjs-waiting');
  20771. /**
  20772. * The media is no longer blocked from playback, and has started playing.
  20773. *
  20774. * @event Player#playing
  20775. * @type {EventTarget~Event}
  20776. */
  20777. this.trigger('playing');
  20778. }
  20779. /**
  20780. * Retrigger the `seeking` event that was triggered by the {@link Tech}.
  20781. *
  20782. * @fires Player#seeking
  20783. * @listens Tech#seeking
  20784. * @private
  20785. */
  20786. ;
  20787. _proto.handleTechSeeking_ = function handleTechSeeking_() {
  20788. this.addClass('vjs-seeking');
  20789. /**
  20790. * Fired whenever the player is jumping to a new time
  20791. *
  20792. * @event Player#seeking
  20793. * @type {EventTarget~Event}
  20794. */
  20795. this.trigger('seeking');
  20796. }
  20797. /**
  20798. * Retrigger the `seeked` event that was triggered by the {@link Tech}.
  20799. *
  20800. * @fires Player#seeked
  20801. * @listens Tech#seeked
  20802. * @private
  20803. */
  20804. ;
  20805. _proto.handleTechSeeked_ = function handleTechSeeked_() {
  20806. this.removeClass('vjs-seeking');
  20807. this.removeClass('vjs-ended');
  20808. /**
  20809. * Fired when the player has finished jumping to a new time
  20810. *
  20811. * @event Player#seeked
  20812. * @type {EventTarget~Event}
  20813. */
  20814. this.trigger('seeked');
  20815. }
  20816. /**
  20817. * Retrigger the `firstplay` event that was triggered by the {@link Tech}.
  20818. *
  20819. * @fires Player#firstplay
  20820. * @listens Tech#firstplay
  20821. * @deprecated As of 6.0 firstplay event is deprecated.
  20822. * As of 6.0 passing the `starttime` option to the player and the firstplay event are deprecated.
  20823. * @private
  20824. */
  20825. ;
  20826. _proto.handleTechFirstPlay_ = function handleTechFirstPlay_() {
  20827. // If the first starttime attribute is specified
  20828. // then we will start at the given offset in seconds
  20829. if (this.options_.starttime) {
  20830. log.warn('Passing the `starttime` option to the player will be deprecated in 6.0');
  20831. this.currentTime(this.options_.starttime);
  20832. }
  20833. this.addClass('vjs-has-started');
  20834. /**
  20835. * Fired the first time a video is played. Not part of the HLS spec, and this is
  20836. * probably not the best implementation yet, so use sparingly. If you don't have a
  20837. * reason to prevent playback, use `myPlayer.one('play');` instead.
  20838. *
  20839. * @event Player#firstplay
  20840. * @deprecated As of 6.0 firstplay event is deprecated.
  20841. * @type {EventTarget~Event}
  20842. */
  20843. this.trigger('firstplay');
  20844. }
  20845. /**
  20846. * Retrigger the `pause` event that was triggered by the {@link Tech}.
  20847. *
  20848. * @fires Player#pause
  20849. * @listens Tech#pause
  20850. * @private
  20851. */
  20852. ;
  20853. _proto.handleTechPause_ = function handleTechPause_() {
  20854. this.removeClass('vjs-playing');
  20855. this.addClass('vjs-paused');
  20856. /**
  20857. * Fired whenever the media has been paused
  20858. *
  20859. * @event Player#pause
  20860. * @type {EventTarget~Event}
  20861. */
  20862. this.trigger('pause');
  20863. }
  20864. /**
  20865. * Retrigger the `ended` event that was triggered by the {@link Tech}.
  20866. *
  20867. * @fires Player#ended
  20868. * @listens Tech#ended
  20869. * @private
  20870. */
  20871. ;
  20872. _proto.handleTechEnded_ = function handleTechEnded_() {
  20873. this.addClass('vjs-ended');
  20874. this.removeClass('vjs-waiting');
  20875. if (this.options_.loop) {
  20876. this.currentTime(0);
  20877. this.play();
  20878. } else if (!this.paused()) {
  20879. this.pause();
  20880. }
  20881. /**
  20882. * Fired when the end of the media resource is reached (currentTime == duration)
  20883. *
  20884. * @event Player#ended
  20885. * @type {EventTarget~Event}
  20886. */
  20887. this.trigger('ended');
  20888. }
  20889. /**
  20890. * Fired when the duration of the media resource is first known or changed
  20891. *
  20892. * @listens Tech#durationchange
  20893. * @private
  20894. */
  20895. ;
  20896. _proto.handleTechDurationChange_ = function handleTechDurationChange_() {
  20897. this.duration(this.techGet_('duration'));
  20898. }
  20899. /**
  20900. * Handle a click on the media element to play/pause
  20901. *
  20902. * @param {EventTarget~Event} event
  20903. * the event that caused this function to trigger
  20904. *
  20905. * @listens Tech#click
  20906. * @private
  20907. */
  20908. ;
  20909. _proto.handleTechClick_ = function handleTechClick_(event) {
  20910. // When controls are disabled a click should not toggle playback because
  20911. // the click is considered a control
  20912. if (!this.controls_) {
  20913. return;
  20914. }
  20915. if (this.options_ === undefined || this.options_.userActions === undefined || this.options_.userActions.click === undefined || this.options_.userActions.click !== false) {
  20916. if (this.options_ !== undefined && this.options_.userActions !== undefined && typeof this.options_.userActions.click === 'function') {
  20917. this.options_.userActions.click.call(this, event);
  20918. } else if (this.paused()) {
  20919. silencePromise(this.play());
  20920. } else {
  20921. this.pause();
  20922. }
  20923. }
  20924. }
  20925. /**
  20926. * Handle a double-click on the media element to enter/exit fullscreen
  20927. *
  20928. * @param {EventTarget~Event} event
  20929. * the event that caused this function to trigger
  20930. *
  20931. * @listens Tech#dblclick
  20932. * @private
  20933. */
  20934. ;
  20935. _proto.handleTechDoubleClick_ = function handleTechDoubleClick_(event) {
  20936. if (!this.controls_) {
  20937. return;
  20938. } // we do not want to toggle fullscreen state
  20939. // when double-clicking inside a control bar or a modal
  20940. var inAllowedEls = Array.prototype.some.call(this.$$('.vjs-control-bar, .vjs-modal-dialog'), function (el) {
  20941. return el.contains(event.target);
  20942. });
  20943. if (!inAllowedEls) {
  20944. /*
  20945. * options.userActions.doubleClick
  20946. *
  20947. * If `undefined` or `true`, double-click toggles fullscreen if controls are present
  20948. * Set to `false` to disable double-click handling
  20949. * Set to a function to substitute an external double-click handler
  20950. */
  20951. if (this.options_ === undefined || this.options_.userActions === undefined || this.options_.userActions.doubleClick === undefined || this.options_.userActions.doubleClick !== false) {
  20952. if (this.options_ !== undefined && this.options_.userActions !== undefined && typeof this.options_.userActions.doubleClick === 'function') {
  20953. this.options_.userActions.doubleClick.call(this, event);
  20954. } else if (this.isFullscreen()) {
  20955. this.exitFullscreen();
  20956. } else {
  20957. this.requestFullscreen();
  20958. }
  20959. }
  20960. }
  20961. }
  20962. /**
  20963. * Handle a tap on the media element. It will toggle the user
  20964. * activity state, which hides and shows the controls.
  20965. *
  20966. * @listens Tech#tap
  20967. * @private
  20968. */
  20969. ;
  20970. _proto.handleTechTap_ = function handleTechTap_() {
  20971. this.userActive(!this.userActive());
  20972. }
  20973. /**
  20974. * Handle touch to start
  20975. *
  20976. * @listens Tech#touchstart
  20977. * @private
  20978. */
  20979. ;
  20980. _proto.handleTechTouchStart_ = function handleTechTouchStart_() {
  20981. this.userWasActive = this.userActive();
  20982. }
  20983. /**
  20984. * Handle touch to move
  20985. *
  20986. * @listens Tech#touchmove
  20987. * @private
  20988. */
  20989. ;
  20990. _proto.handleTechTouchMove_ = function handleTechTouchMove_() {
  20991. if (this.userWasActive) {
  20992. this.reportUserActivity();
  20993. }
  20994. }
  20995. /**
  20996. * Handle touch to end
  20997. *
  20998. * @param {EventTarget~Event} event
  20999. * the touchend event that triggered
  21000. * this function
  21001. *
  21002. * @listens Tech#touchend
  21003. * @private
  21004. */
  21005. ;
  21006. _proto.handleTechTouchEnd_ = function handleTechTouchEnd_(event) {
  21007. // Stop the mouse events from also happening
  21008. if (event.cancelable) {
  21009. event.preventDefault();
  21010. }
  21011. }
  21012. /**
  21013. * native click events on the SWF aren't triggered on IE11, Win8.1RT
  21014. * use stageclick events triggered from inside the SWF instead
  21015. *
  21016. * @private
  21017. * @listens stageclick
  21018. */
  21019. ;
  21020. _proto.handleStageClick_ = function handleStageClick_() {
  21021. this.reportUserActivity();
  21022. }
  21023. /**
  21024. * @private
  21025. */
  21026. ;
  21027. _proto.toggleFullscreenClass_ = function toggleFullscreenClass_() {
  21028. if (this.isFullscreen()) {
  21029. this.addClass('vjs-fullscreen');
  21030. } else {
  21031. this.removeClass('vjs-fullscreen');
  21032. }
  21033. }
  21034. /**
  21035. * when the document fschange event triggers it calls this
  21036. */
  21037. ;
  21038. _proto.documentFullscreenChange_ = function documentFullscreenChange_(e) {
  21039. var targetPlayer = e.target.player; // if another player was fullscreen
  21040. // do a null check for targetPlayer because older firefox's would put document as e.target
  21041. if (targetPlayer && targetPlayer !== this) {
  21042. return;
  21043. }
  21044. var el = this.el();
  21045. var isFs = document[this.fsApi_.fullscreenElement] === el;
  21046. if (!isFs && el.matches) {
  21047. isFs = el.matches(':' + this.fsApi_.fullscreen);
  21048. } else if (!isFs && el.msMatchesSelector) {
  21049. isFs = el.msMatchesSelector(':' + this.fsApi_.fullscreen);
  21050. }
  21051. this.isFullscreen(isFs);
  21052. }
  21053. /**
  21054. * Handle Tech Fullscreen Change
  21055. *
  21056. * @param {EventTarget~Event} event
  21057. * the fullscreenchange event that triggered this function
  21058. *
  21059. * @param {Object} data
  21060. * the data that was sent with the event
  21061. *
  21062. * @private
  21063. * @listens Tech#fullscreenchange
  21064. * @fires Player#fullscreenchange
  21065. */
  21066. ;
  21067. _proto.handleTechFullscreenChange_ = function handleTechFullscreenChange_(event, data) {
  21068. var _this9 = this;
  21069. if (data) {
  21070. if (data.nativeIOSFullscreen) {
  21071. this.addClass('vjs-ios-native-fs');
  21072. this.tech_.one('webkitendfullscreen', function () {
  21073. _this9.removeClass('vjs-ios-native-fs');
  21074. });
  21075. }
  21076. this.isFullscreen(data.isFullscreen);
  21077. }
  21078. };
  21079. _proto.handleTechFullscreenError_ = function handleTechFullscreenError_(event, err) {
  21080. this.trigger('fullscreenerror', err);
  21081. }
  21082. /**
  21083. * @private
  21084. */
  21085. ;
  21086. _proto.togglePictureInPictureClass_ = function togglePictureInPictureClass_() {
  21087. if (this.isInPictureInPicture()) {
  21088. this.addClass('vjs-picture-in-picture');
  21089. } else {
  21090. this.removeClass('vjs-picture-in-picture');
  21091. }
  21092. }
  21093. /**
  21094. * Handle Tech Enter Picture-in-Picture.
  21095. *
  21096. * @param {EventTarget~Event} event
  21097. * the enterpictureinpicture event that triggered this function
  21098. *
  21099. * @private
  21100. * @listens Tech#enterpictureinpicture
  21101. */
  21102. ;
  21103. _proto.handleTechEnterPictureInPicture_ = function handleTechEnterPictureInPicture_(event) {
  21104. this.isInPictureInPicture(true);
  21105. }
  21106. /**
  21107. * Handle Tech Leave Picture-in-Picture.
  21108. *
  21109. * @param {EventTarget~Event} event
  21110. * the leavepictureinpicture event that triggered this function
  21111. *
  21112. * @private
  21113. * @listens Tech#leavepictureinpicture
  21114. */
  21115. ;
  21116. _proto.handleTechLeavePictureInPicture_ = function handleTechLeavePictureInPicture_(event) {
  21117. this.isInPictureInPicture(false);
  21118. }
  21119. /**
  21120. * Fires when an error occurred during the loading of an audio/video.
  21121. *
  21122. * @private
  21123. * @listens Tech#error
  21124. */
  21125. ;
  21126. _proto.handleTechError_ = function handleTechError_() {
  21127. var error = this.tech_.error();
  21128. this.error(error);
  21129. }
  21130. /**
  21131. * Retrigger the `textdata` event that was triggered by the {@link Tech}.
  21132. *
  21133. * @fires Player#textdata
  21134. * @listens Tech#textdata
  21135. * @private
  21136. */
  21137. ;
  21138. _proto.handleTechTextData_ = function handleTechTextData_() {
  21139. var data = null;
  21140. if (arguments.length > 1) {
  21141. data = arguments[1];
  21142. }
  21143. /**
  21144. * Fires when we get a textdata event from tech
  21145. *
  21146. * @event Player#textdata
  21147. * @type {EventTarget~Event}
  21148. */
  21149. this.trigger('textdata', data);
  21150. }
  21151. /**
  21152. * Get object for cached values.
  21153. *
  21154. * @return {Object}
  21155. * get the current object cache
  21156. */
  21157. ;
  21158. _proto.getCache = function getCache() {
  21159. return this.cache_;
  21160. }
  21161. /**
  21162. * Resets the internal cache object.
  21163. *
  21164. * Using this function outside the player constructor or reset method may
  21165. * have unintended side-effects.
  21166. *
  21167. * @private
  21168. */
  21169. ;
  21170. _proto.resetCache_ = function resetCache_() {
  21171. this.cache_ = {
  21172. // Right now, the currentTime is not _really_ cached because it is always
  21173. // retrieved from the tech (see: currentTime). However, for completeness,
  21174. // we set it to zero here to ensure that if we do start actually caching
  21175. // it, we reset it along with everything else.
  21176. currentTime: 0,
  21177. initTime: 0,
  21178. inactivityTimeout: this.options_.inactivityTimeout,
  21179. duration: NaN,
  21180. lastVolume: 1,
  21181. lastPlaybackRate: this.defaultPlaybackRate(),
  21182. media: null,
  21183. src: '',
  21184. source: {},
  21185. sources: [],
  21186. playbackRates: [],
  21187. volume: 1
  21188. };
  21189. }
  21190. /**
  21191. * Pass values to the playback tech
  21192. *
  21193. * @param {string} [method]
  21194. * the method to call
  21195. *
  21196. * @param {Object} arg
  21197. * the argument to pass
  21198. *
  21199. * @private
  21200. */
  21201. ;
  21202. _proto.techCall_ = function techCall_(method, arg) {
  21203. // If it's not ready yet, call method when it is
  21204. this.ready(function () {
  21205. if (method in allowedSetters) {
  21206. return set(this.middleware_, this.tech_, method, arg);
  21207. } else if (method in allowedMediators) {
  21208. return mediate(this.middleware_, this.tech_, method, arg);
  21209. }
  21210. try {
  21211. if (this.tech_) {
  21212. this.tech_[method](arg);
  21213. }
  21214. } catch (e) {
  21215. log(e);
  21216. throw e;
  21217. }
  21218. }, true);
  21219. }
  21220. /**
  21221. * Get calls can't wait for the tech, and sometimes don't need to.
  21222. *
  21223. * @param {string} method
  21224. * Tech method
  21225. *
  21226. * @return {Function|undefined}
  21227. * the method or undefined
  21228. *
  21229. * @private
  21230. */
  21231. ;
  21232. _proto.techGet_ = function techGet_(method) {
  21233. if (!this.tech_ || !this.tech_.isReady_) {
  21234. return;
  21235. }
  21236. if (method in allowedGetters) {
  21237. return get(this.middleware_, this.tech_, method);
  21238. } else if (method in allowedMediators) {
  21239. return mediate(this.middleware_, this.tech_, method);
  21240. } // Flash likes to die and reload when you hide or reposition it.
  21241. // In these cases the object methods go away and we get errors.
  21242. // TODO: Is this needed for techs other than Flash?
  21243. // When that happens we'll catch the errors and inform tech that it's not ready any more.
  21244. try {
  21245. return this.tech_[method]();
  21246. } catch (e) {
  21247. // When building additional tech libs, an expected method may not be defined yet
  21248. if (this.tech_[method] === undefined) {
  21249. log("Video.js: " + method + " method not defined for " + this.techName_ + " playback technology.", e);
  21250. throw e;
  21251. } // When a method isn't available on the object it throws a TypeError
  21252. if (e.name === 'TypeError') {
  21253. log("Video.js: " + method + " unavailable on " + this.techName_ + " playback technology element.", e);
  21254. this.tech_.isReady_ = false;
  21255. throw e;
  21256. } // If error unknown, just log and throw
  21257. log(e);
  21258. throw e;
  21259. }
  21260. }
  21261. /**
  21262. * Attempt to begin playback at the first opportunity.
  21263. *
  21264. * @return {Promise|undefined}
  21265. * Returns a promise if the browser supports Promises (or one
  21266. * was passed in as an option). This promise will be resolved on
  21267. * the return value of play. If this is undefined it will fulfill the
  21268. * promise chain otherwise the promise chain will be fulfilled when
  21269. * the promise from play is fulfilled.
  21270. */
  21271. ;
  21272. _proto.play = function play() {
  21273. var _this10 = this;
  21274. var PromiseClass = this.options_.Promise || window.Promise;
  21275. if (PromiseClass) {
  21276. return new PromiseClass(function (resolve) {
  21277. _this10.play_(resolve);
  21278. });
  21279. }
  21280. return this.play_();
  21281. }
  21282. /**
  21283. * The actual logic for play, takes a callback that will be resolved on the
  21284. * return value of play. This allows us to resolve to the play promise if there
  21285. * is one on modern browsers.
  21286. *
  21287. * @private
  21288. * @param {Function} [callback]
  21289. * The callback that should be called when the techs play is actually called
  21290. */
  21291. ;
  21292. _proto.play_ = function play_(callback) {
  21293. var _this11 = this;
  21294. if (callback === void 0) {
  21295. callback = silencePromise;
  21296. }
  21297. this.playCallbacks_.push(callback);
  21298. var isSrcReady = Boolean(!this.changingSrc_ && (this.src() || this.currentSrc()));
  21299. var isSafariOrIOS = Boolean(IS_ANY_SAFARI || IS_IOS); // treat calls to play_ somewhat like the `one` event function
  21300. if (this.waitToPlay_) {
  21301. this.off(['ready', 'loadstart'], this.waitToPlay_);
  21302. this.waitToPlay_ = null;
  21303. } // if the player/tech is not ready or the src itself is not ready
  21304. // queue up a call to play on `ready` or `loadstart`
  21305. if (!this.isReady_ || !isSrcReady) {
  21306. this.waitToPlay_ = function (e) {
  21307. _this11.play_();
  21308. };
  21309. this.one(['ready', 'loadstart'], this.waitToPlay_); // if we are in Safari, there is a high chance that loadstart will trigger after the gesture timeperiod
  21310. // in that case, we need to prime the video element by calling load so it'll be ready in time
  21311. if (!isSrcReady && isSafariOrIOS) {
  21312. this.load();
  21313. }
  21314. return;
  21315. } // If the player/tech is ready and we have a source, we can attempt playback.
  21316. var val = this.techGet_('play'); // For native playback, reset the progress bar if we get a play call from a replay.
  21317. var isNativeReplay = isSafariOrIOS && this.hasClass('vjs-ended');
  21318. if (isNativeReplay) {
  21319. this.resetProgressBar_();
  21320. } // play was terminated if the returned value is null
  21321. if (val === null) {
  21322. this.runPlayTerminatedQueue_();
  21323. } else {
  21324. this.runPlayCallbacks_(val);
  21325. }
  21326. }
  21327. /**
  21328. * These functions will be run when if play is terminated. If play
  21329. * runPlayCallbacks_ is run these function will not be run. This allows us
  21330. * to differenciate between a terminated play and an actual call to play.
  21331. */
  21332. ;
  21333. _proto.runPlayTerminatedQueue_ = function runPlayTerminatedQueue_() {
  21334. var queue = this.playTerminatedQueue_.slice(0);
  21335. this.playTerminatedQueue_ = [];
  21336. queue.forEach(function (q) {
  21337. q();
  21338. });
  21339. }
  21340. /**
  21341. * When a callback to play is delayed we have to run these
  21342. * callbacks when play is actually called on the tech. This function
  21343. * runs the callbacks that were delayed and accepts the return value
  21344. * from the tech.
  21345. *
  21346. * @param {undefined|Promise} val
  21347. * The return value from the tech.
  21348. */
  21349. ;
  21350. _proto.runPlayCallbacks_ = function runPlayCallbacks_(val) {
  21351. var callbacks = this.playCallbacks_.slice(0);
  21352. this.playCallbacks_ = []; // clear play terminatedQueue since we finished a real play
  21353. this.playTerminatedQueue_ = [];
  21354. callbacks.forEach(function (cb) {
  21355. cb(val);
  21356. });
  21357. }
  21358. /**
  21359. * Pause the video playback
  21360. *
  21361. * @return {Player}
  21362. * A reference to the player object this function was called on
  21363. */
  21364. ;
  21365. _proto.pause = function pause() {
  21366. this.techCall_('pause');
  21367. }
  21368. /**
  21369. * Check if the player is paused or has yet to play
  21370. *
  21371. * @return {boolean}
  21372. * - false: if the media is currently playing
  21373. * - true: if media is not currently playing
  21374. */
  21375. ;
  21376. _proto.paused = function paused() {
  21377. // The initial state of paused should be true (in Safari it's actually false)
  21378. return this.techGet_('paused') === false ? false : true;
  21379. }
  21380. /**
  21381. * Get a TimeRange object representing the current ranges of time that the user
  21382. * has played.
  21383. *
  21384. * @return {TimeRange}
  21385. * A time range object that represents all the increments of time that have
  21386. * been played.
  21387. */
  21388. ;
  21389. _proto.played = function played() {
  21390. return this.techGet_('played') || createTimeRanges(0, 0);
  21391. }
  21392. /**
  21393. * Returns whether or not the user is "scrubbing". Scrubbing is
  21394. * when the user has clicked the progress bar handle and is
  21395. * dragging it along the progress bar.
  21396. *
  21397. * @param {boolean} [isScrubbing]
  21398. * whether the user is or is not scrubbing
  21399. *
  21400. * @return {boolean}
  21401. * The value of scrubbing when getting
  21402. */
  21403. ;
  21404. _proto.scrubbing = function scrubbing(isScrubbing) {
  21405. if (typeof isScrubbing === 'undefined') {
  21406. return this.scrubbing_;
  21407. }
  21408. this.scrubbing_ = !!isScrubbing;
  21409. this.techCall_('setScrubbing', this.scrubbing_);
  21410. if (isScrubbing) {
  21411. this.addClass('vjs-scrubbing');
  21412. } else {
  21413. this.removeClass('vjs-scrubbing');
  21414. }
  21415. }
  21416. /**
  21417. * Get or set the current time (in seconds)
  21418. *
  21419. * @param {number|string} [seconds]
  21420. * The time to seek to in seconds
  21421. *
  21422. * @return {number}
  21423. * - the current time in seconds when getting
  21424. */
  21425. ;
  21426. _proto.currentTime = function currentTime(seconds) {
  21427. if (typeof seconds !== 'undefined') {
  21428. if (seconds < 0) {
  21429. seconds = 0;
  21430. }
  21431. if (!this.isReady_ || this.changingSrc_ || !this.tech_ || !this.tech_.isReady_) {
  21432. this.cache_.initTime = seconds;
  21433. this.off('canplay', this.boundApplyInitTime_);
  21434. this.one('canplay', this.boundApplyInitTime_);
  21435. return;
  21436. }
  21437. this.techCall_('setCurrentTime', seconds);
  21438. this.cache_.initTime = 0;
  21439. return;
  21440. } // cache last currentTime and return. default to 0 seconds
  21441. //
  21442. // Caching the currentTime is meant to prevent a massive amount of reads on the tech's
  21443. // currentTime when scrubbing, but may not provide much performance benefit afterall.
  21444. // Should be tested. Also something has to read the actual current time or the cache will
  21445. // never get updated.
  21446. this.cache_.currentTime = this.techGet_('currentTime') || 0;
  21447. return this.cache_.currentTime;
  21448. }
  21449. /**
  21450. * Apply the value of initTime stored in cache as currentTime.
  21451. *
  21452. * @private
  21453. */
  21454. ;
  21455. _proto.applyInitTime_ = function applyInitTime_() {
  21456. this.currentTime(this.cache_.initTime);
  21457. }
  21458. /**
  21459. * Normally gets the length in time of the video in seconds;
  21460. * in all but the rarest use cases an argument will NOT be passed to the method
  21461. *
  21462. * > **NOTE**: The video must have started loading before the duration can be
  21463. * known, and depending on preload behaviour may not be known until the video starts
  21464. * playing.
  21465. *
  21466. * @fires Player#durationchange
  21467. *
  21468. * @param {number} [seconds]
  21469. * The duration of the video to set in seconds
  21470. *
  21471. * @return {number}
  21472. * - The duration of the video in seconds when getting
  21473. */
  21474. ;
  21475. _proto.duration = function duration(seconds) {
  21476. if (seconds === undefined) {
  21477. // return NaN if the duration is not known
  21478. return this.cache_.duration !== undefined ? this.cache_.duration : NaN;
  21479. }
  21480. seconds = parseFloat(seconds); // Standardize on Infinity for signaling video is live
  21481. if (seconds < 0) {
  21482. seconds = Infinity;
  21483. }
  21484. if (seconds !== this.cache_.duration) {
  21485. // Cache the last set value for optimized scrubbing (esp. Flash)
  21486. // TODO: Required for techs other than Flash?
  21487. this.cache_.duration = seconds;
  21488. if (seconds === Infinity) {
  21489. this.addClass('vjs-live');
  21490. } else {
  21491. this.removeClass('vjs-live');
  21492. }
  21493. if (!isNaN(seconds)) {
  21494. // Do not fire durationchange unless the duration value is known.
  21495. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  21496. /**
  21497. * @event Player#durationchange
  21498. * @type {EventTarget~Event}
  21499. */
  21500. this.trigger('durationchange');
  21501. }
  21502. }
  21503. }
  21504. /**
  21505. * Calculates how much time is left in the video. Not part
  21506. * of the native video API.
  21507. *
  21508. * @return {number}
  21509. * The time remaining in seconds
  21510. */
  21511. ;
  21512. _proto.remainingTime = function remainingTime() {
  21513. return this.duration() - this.currentTime();
  21514. }
  21515. /**
  21516. * A remaining time function that is intented to be used when
  21517. * the time is to be displayed directly to the user.
  21518. *
  21519. * @return {number}
  21520. * The rounded time remaining in seconds
  21521. */
  21522. ;
  21523. _proto.remainingTimeDisplay = function remainingTimeDisplay() {
  21524. return Math.floor(this.duration()) - Math.floor(this.currentTime());
  21525. } //
  21526. // Kind of like an array of portions of the video that have been downloaded.
  21527. /**
  21528. * Get a TimeRange object with an array of the times of the video
  21529. * that have been downloaded. If you just want the percent of the
  21530. * video that's been downloaded, use bufferedPercent.
  21531. *
  21532. * @see [Buffered Spec]{@link http://dev.w3.org/html5/spec/video.html#dom-media-buffered}
  21533. *
  21534. * @return {TimeRange}
  21535. * A mock TimeRange object (following HTML spec)
  21536. */
  21537. ;
  21538. _proto.buffered = function buffered() {
  21539. var buffered = this.techGet_('buffered');
  21540. if (!buffered || !buffered.length) {
  21541. buffered = createTimeRanges(0, 0);
  21542. }
  21543. return buffered;
  21544. }
  21545. /**
  21546. * Get the percent (as a decimal) of the video that's been downloaded.
  21547. * This method is not a part of the native HTML video API.
  21548. *
  21549. * @return {number}
  21550. * A decimal between 0 and 1 representing the percent
  21551. * that is buffered 0 being 0% and 1 being 100%
  21552. */
  21553. ;
  21554. _proto.bufferedPercent = function bufferedPercent$1() {
  21555. return bufferedPercent(this.buffered(), this.duration());
  21556. }
  21557. /**
  21558. * Get the ending time of the last buffered time range
  21559. * This is used in the progress bar to encapsulate all time ranges.
  21560. *
  21561. * @return {number}
  21562. * The end of the last buffered time range
  21563. */
  21564. ;
  21565. _proto.bufferedEnd = function bufferedEnd() {
  21566. var buffered = this.buffered();
  21567. var duration = this.duration();
  21568. var end = buffered.end(buffered.length - 1);
  21569. if (end > duration) {
  21570. end = duration;
  21571. }
  21572. return end;
  21573. }
  21574. /**
  21575. * Get or set the current volume of the media
  21576. *
  21577. * @param {number} [percentAsDecimal]
  21578. * The new volume as a decimal percent:
  21579. * - 0 is muted/0%/off
  21580. * - 1.0 is 100%/full
  21581. * - 0.5 is half volume or 50%
  21582. *
  21583. * @return {number}
  21584. * The current volume as a percent when getting
  21585. */
  21586. ;
  21587. _proto.volume = function volume(percentAsDecimal) {
  21588. var vol;
  21589. if (percentAsDecimal !== undefined) {
  21590. // Force value to between 0 and 1
  21591. vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal)));
  21592. this.cache_.volume = vol;
  21593. this.techCall_('setVolume', vol);
  21594. if (vol > 0) {
  21595. this.lastVolume_(vol);
  21596. }
  21597. return;
  21598. } // Default to 1 when returning current volume.
  21599. vol = parseFloat(this.techGet_('volume'));
  21600. return isNaN(vol) ? 1 : vol;
  21601. }
  21602. /**
  21603. * Get the current muted state, or turn mute on or off
  21604. *
  21605. * @param {boolean} [muted]
  21606. * - true to mute
  21607. * - false to unmute
  21608. *
  21609. * @return {boolean}
  21610. * - true if mute is on and getting
  21611. * - false if mute is off and getting
  21612. */
  21613. ;
  21614. _proto.muted = function muted(_muted) {
  21615. if (_muted !== undefined) {
  21616. this.techCall_('setMuted', _muted);
  21617. return;
  21618. }
  21619. return this.techGet_('muted') || false;
  21620. }
  21621. /**
  21622. * Get the current defaultMuted state, or turn defaultMuted on or off. defaultMuted
  21623. * indicates the state of muted on initial playback.
  21624. *
  21625. * ```js
  21626. * var myPlayer = videojs('some-player-id');
  21627. *
  21628. * myPlayer.src("http://www.example.com/path/to/video.mp4");
  21629. *
  21630. * // get, should be false
  21631. * console.log(myPlayer.defaultMuted());
  21632. * // set to true
  21633. * myPlayer.defaultMuted(true);
  21634. * // get should be true
  21635. * console.log(myPlayer.defaultMuted());
  21636. * ```
  21637. *
  21638. * @param {boolean} [defaultMuted]
  21639. * - true to mute
  21640. * - false to unmute
  21641. *
  21642. * @return {boolean|Player}
  21643. * - true if defaultMuted is on and getting
  21644. * - false if defaultMuted is off and getting
  21645. * - A reference to the current player when setting
  21646. */
  21647. ;
  21648. _proto.defaultMuted = function defaultMuted(_defaultMuted) {
  21649. if (_defaultMuted !== undefined) {
  21650. return this.techCall_('setDefaultMuted', _defaultMuted);
  21651. }
  21652. return this.techGet_('defaultMuted') || false;
  21653. }
  21654. /**
  21655. * Get the last volume, or set it
  21656. *
  21657. * @param {number} [percentAsDecimal]
  21658. * The new last volume as a decimal percent:
  21659. * - 0 is muted/0%/off
  21660. * - 1.0 is 100%/full
  21661. * - 0.5 is half volume or 50%
  21662. *
  21663. * @return {number}
  21664. * the current value of lastVolume as a percent when getting
  21665. *
  21666. * @private
  21667. */
  21668. ;
  21669. _proto.lastVolume_ = function lastVolume_(percentAsDecimal) {
  21670. if (percentAsDecimal !== undefined && percentAsDecimal !== 0) {
  21671. this.cache_.lastVolume = percentAsDecimal;
  21672. return;
  21673. }
  21674. return this.cache_.lastVolume;
  21675. }
  21676. /**
  21677. * Check if current tech can support native fullscreen
  21678. * (e.g. with built in controls like iOS)
  21679. *
  21680. * @return {boolean}
  21681. * if native fullscreen is supported
  21682. */
  21683. ;
  21684. _proto.supportsFullScreen = function supportsFullScreen() {
  21685. return this.techGet_('supportsFullScreen') || false;
  21686. }
  21687. /**
  21688. * Check if the player is in fullscreen mode or tell the player that it
  21689. * is or is not in fullscreen mode.
  21690. *
  21691. * > NOTE: As of the latest HTML5 spec, isFullscreen is no longer an official
  21692. * property and instead document.fullscreenElement is used. But isFullscreen is
  21693. * still a valuable property for internal player workings.
  21694. *
  21695. * @param {boolean} [isFS]
  21696. * Set the players current fullscreen state
  21697. *
  21698. * @return {boolean}
  21699. * - true if fullscreen is on and getting
  21700. * - false if fullscreen is off and getting
  21701. */
  21702. ;
  21703. _proto.isFullscreen = function isFullscreen(isFS) {
  21704. if (isFS !== undefined) {
  21705. var oldValue = this.isFullscreen_;
  21706. this.isFullscreen_ = Boolean(isFS); // if we changed fullscreen state and we're in prefixed mode, trigger fullscreenchange
  21707. // this is the only place where we trigger fullscreenchange events for older browsers
  21708. // fullWindow mode is treated as a prefixed event and will get a fullscreenchange event as well
  21709. if (this.isFullscreen_ !== oldValue && this.fsApi_.prefixed) {
  21710. /**
  21711. * @event Player#fullscreenchange
  21712. * @type {EventTarget~Event}
  21713. */
  21714. this.trigger('fullscreenchange');
  21715. }
  21716. this.toggleFullscreenClass_();
  21717. return;
  21718. }
  21719. return this.isFullscreen_;
  21720. }
  21721. /**
  21722. * Increase the size of the video to full screen
  21723. * In some browsers, full screen is not supported natively, so it enters
  21724. * "full window mode", where the video fills the browser window.
  21725. * In browsers and devices that support native full screen, sometimes the
  21726. * browser's default controls will be shown, and not the Video.js custom skin.
  21727. * This includes most mobile devices (iOS, Android) and older versions of
  21728. * Safari.
  21729. *
  21730. * @param {Object} [fullscreenOptions]
  21731. * Override the player fullscreen options
  21732. *
  21733. * @fires Player#fullscreenchange
  21734. */
  21735. ;
  21736. _proto.requestFullscreen = function requestFullscreen(fullscreenOptions) {
  21737. var PromiseClass = this.options_.Promise || window.Promise;
  21738. if (PromiseClass) {
  21739. var self = this;
  21740. return new PromiseClass(function (resolve, reject) {
  21741. function offHandler() {
  21742. self.off('fullscreenerror', errorHandler);
  21743. self.off('fullscreenchange', changeHandler);
  21744. }
  21745. function changeHandler() {
  21746. offHandler();
  21747. resolve();
  21748. }
  21749. function errorHandler(e, err) {
  21750. offHandler();
  21751. reject(err);
  21752. }
  21753. self.one('fullscreenchange', changeHandler);
  21754. self.one('fullscreenerror', errorHandler);
  21755. var promise = self.requestFullscreenHelper_(fullscreenOptions);
  21756. if (promise) {
  21757. promise.then(offHandler, offHandler);
  21758. promise.then(resolve, reject);
  21759. }
  21760. });
  21761. }
  21762. return this.requestFullscreenHelper_();
  21763. };
  21764. _proto.requestFullscreenHelper_ = function requestFullscreenHelper_(fullscreenOptions) {
  21765. var _this12 = this;
  21766. var fsOptions; // Only pass fullscreen options to requestFullscreen in spec-compliant browsers.
  21767. // Use defaults or player configured option unless passed directly to this method.
  21768. if (!this.fsApi_.prefixed) {
  21769. fsOptions = this.options_.fullscreen && this.options_.fullscreen.options || {};
  21770. if (fullscreenOptions !== undefined) {
  21771. fsOptions = fullscreenOptions;
  21772. }
  21773. } // This method works as follows:
  21774. // 1. if a fullscreen api is available, use it
  21775. // 1. call requestFullscreen with potential options
  21776. // 2. if we got a promise from above, use it to update isFullscreen()
  21777. // 2. otherwise, if the tech supports fullscreen, call `enterFullScreen` on it.
  21778. // This is particularly used for iPhone, older iPads, and non-safari browser on iOS.
  21779. // 3. otherwise, use "fullWindow" mode
  21780. if (this.fsApi_.requestFullscreen) {
  21781. var promise = this.el_[this.fsApi_.requestFullscreen](fsOptions);
  21782. if (promise) {
  21783. promise.then(function () {
  21784. return _this12.isFullscreen(true);
  21785. }, function () {
  21786. return _this12.isFullscreen(false);
  21787. });
  21788. }
  21789. return promise;
  21790. } else if (this.tech_.supportsFullScreen() && !this.options_.preferFullWindow === true) {
  21791. // we can't take the video.js controls fullscreen but we can go fullscreen
  21792. // with native controls
  21793. this.techCall_('enterFullScreen');
  21794. } else {
  21795. // fullscreen isn't supported so we'll just stretch the video element to
  21796. // fill the viewport
  21797. this.enterFullWindow();
  21798. }
  21799. }
  21800. /**
  21801. * Return the video to its normal size after having been in full screen mode
  21802. *
  21803. * @fires Player#fullscreenchange
  21804. */
  21805. ;
  21806. _proto.exitFullscreen = function exitFullscreen() {
  21807. var PromiseClass = this.options_.Promise || window.Promise;
  21808. if (PromiseClass) {
  21809. var self = this;
  21810. return new PromiseClass(function (resolve, reject) {
  21811. function offHandler() {
  21812. self.off('fullscreenerror', errorHandler);
  21813. self.off('fullscreenchange', changeHandler);
  21814. }
  21815. function changeHandler() {
  21816. offHandler();
  21817. resolve();
  21818. }
  21819. function errorHandler(e, err) {
  21820. offHandler();
  21821. reject(err);
  21822. }
  21823. self.one('fullscreenchange', changeHandler);
  21824. self.one('fullscreenerror', errorHandler);
  21825. var promise = self.exitFullscreenHelper_();
  21826. if (promise) {
  21827. promise.then(offHandler, offHandler); // map the promise to our resolve/reject methods
  21828. promise.then(resolve, reject);
  21829. }
  21830. });
  21831. }
  21832. return this.exitFullscreenHelper_();
  21833. };
  21834. _proto.exitFullscreenHelper_ = function exitFullscreenHelper_() {
  21835. var _this13 = this;
  21836. if (this.fsApi_.requestFullscreen) {
  21837. var promise = document[this.fsApi_.exitFullscreen]();
  21838. if (promise) {
  21839. // we're splitting the promise here, so, we want to catch the
  21840. // potential error so that this chain doesn't have unhandled errors
  21841. silencePromise(promise.then(function () {
  21842. return _this13.isFullscreen(false);
  21843. }));
  21844. }
  21845. return promise;
  21846. } else if (this.tech_.supportsFullScreen() && !this.options_.preferFullWindow === true) {
  21847. this.techCall_('exitFullScreen');
  21848. } else {
  21849. this.exitFullWindow();
  21850. }
  21851. }
  21852. /**
  21853. * When fullscreen isn't supported we can stretch the
  21854. * video container to as wide as the browser will let us.
  21855. *
  21856. * @fires Player#enterFullWindow
  21857. */
  21858. ;
  21859. _proto.enterFullWindow = function enterFullWindow() {
  21860. this.isFullscreen(true);
  21861. this.isFullWindow = true; // Storing original doc overflow value to return to when fullscreen is off
  21862. this.docOrigOverflow = document.documentElement.style.overflow; // Add listener for esc key to exit fullscreen
  21863. on(document, 'keydown', this.boundFullWindowOnEscKey_); // Hide any scroll bars
  21864. document.documentElement.style.overflow = 'hidden'; // Apply fullscreen styles
  21865. addClass(document.body, 'vjs-full-window');
  21866. /**
  21867. * @event Player#enterFullWindow
  21868. * @type {EventTarget~Event}
  21869. */
  21870. this.trigger('enterFullWindow');
  21871. }
  21872. /**
  21873. * Check for call to either exit full window or
  21874. * full screen on ESC key
  21875. *
  21876. * @param {string} event
  21877. * Event to check for key press
  21878. */
  21879. ;
  21880. _proto.fullWindowOnEscKey = function fullWindowOnEscKey(event) {
  21881. if (keycode.isEventKey(event, 'Esc')) {
  21882. if (this.isFullscreen() === true) {
  21883. if (!this.isFullWindow) {
  21884. this.exitFullscreen();
  21885. } else {
  21886. this.exitFullWindow();
  21887. }
  21888. }
  21889. }
  21890. }
  21891. /**
  21892. * Exit full window
  21893. *
  21894. * @fires Player#exitFullWindow
  21895. */
  21896. ;
  21897. _proto.exitFullWindow = function exitFullWindow() {
  21898. this.isFullscreen(false);
  21899. this.isFullWindow = false;
  21900. off(document, 'keydown', this.boundFullWindowOnEscKey_); // Unhide scroll bars.
  21901. document.documentElement.style.overflow = this.docOrigOverflow; // Remove fullscreen styles
  21902. removeClass(document.body, 'vjs-full-window'); // Resize the box, controller, and poster to original sizes
  21903. // this.positionAll();
  21904. /**
  21905. * @event Player#exitFullWindow
  21906. * @type {EventTarget~Event}
  21907. */
  21908. this.trigger('exitFullWindow');
  21909. }
  21910. /**
  21911. * Disable Picture-in-Picture mode.
  21912. *
  21913. * @param {boolean} value
  21914. * - true will disable Picture-in-Picture mode
  21915. * - false will enable Picture-in-Picture mode
  21916. */
  21917. ;
  21918. _proto.disablePictureInPicture = function disablePictureInPicture(value) {
  21919. if (value === undefined) {
  21920. return this.techGet_('disablePictureInPicture');
  21921. }
  21922. this.techCall_('setDisablePictureInPicture', value);
  21923. this.options_.disablePictureInPicture = value;
  21924. this.trigger('disablepictureinpicturechanged');
  21925. }
  21926. /**
  21927. * Check if the player is in Picture-in-Picture mode or tell the player that it
  21928. * is or is not in Picture-in-Picture mode.
  21929. *
  21930. * @param {boolean} [isPiP]
  21931. * Set the players current Picture-in-Picture state
  21932. *
  21933. * @return {boolean}
  21934. * - true if Picture-in-Picture is on and getting
  21935. * - false if Picture-in-Picture is off and getting
  21936. */
  21937. ;
  21938. _proto.isInPictureInPicture = function isInPictureInPicture(isPiP) {
  21939. if (isPiP !== undefined) {
  21940. this.isInPictureInPicture_ = !!isPiP;
  21941. this.togglePictureInPictureClass_();
  21942. return;
  21943. }
  21944. return !!this.isInPictureInPicture_;
  21945. }
  21946. /**
  21947. * Create a floating video window always on top of other windows so that users may
  21948. * continue consuming media while they interact with other content sites, or
  21949. * applications on their device.
  21950. *
  21951. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  21952. *
  21953. * @fires Player#enterpictureinpicture
  21954. *
  21955. * @return {Promise}
  21956. * A promise with a Picture-in-Picture window.
  21957. */
  21958. ;
  21959. _proto.requestPictureInPicture = function requestPictureInPicture() {
  21960. if ('pictureInPictureEnabled' in document && this.disablePictureInPicture() === false) {
  21961. /**
  21962. * This event fires when the player enters picture in picture mode
  21963. *
  21964. * @event Player#enterpictureinpicture
  21965. * @type {EventTarget~Event}
  21966. */
  21967. return this.techGet_('requestPictureInPicture');
  21968. }
  21969. }
  21970. /**
  21971. * Exit Picture-in-Picture mode.
  21972. *
  21973. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  21974. *
  21975. * @fires Player#leavepictureinpicture
  21976. *
  21977. * @return {Promise}
  21978. * A promise.
  21979. */
  21980. ;
  21981. _proto.exitPictureInPicture = function exitPictureInPicture() {
  21982. if ('pictureInPictureEnabled' in document) {
  21983. /**
  21984. * This event fires when the player leaves picture in picture mode
  21985. *
  21986. * @event Player#leavepictureinpicture
  21987. * @type {EventTarget~Event}
  21988. */
  21989. return document.exitPictureInPicture();
  21990. }
  21991. }
  21992. /**
  21993. * Called when this Player has focus and a key gets pressed down, or when
  21994. * any Component of this player receives a key press that it doesn't handle.
  21995. * This allows player-wide hotkeys (either as defined below, or optionally
  21996. * by an external function).
  21997. *
  21998. * @param {EventTarget~Event} event
  21999. * The `keydown` event that caused this function to be called.
  22000. *
  22001. * @listens keydown
  22002. */
  22003. ;
  22004. _proto.handleKeyDown = function handleKeyDown(event) {
  22005. var userActions = this.options_.userActions; // Bail out if hotkeys are not configured.
  22006. if (!userActions || !userActions.hotkeys) {
  22007. return;
  22008. } // Function that determines whether or not to exclude an element from
  22009. // hotkeys handling.
  22010. var excludeElement = function excludeElement(el) {
  22011. var tagName = el.tagName.toLowerCase(); // The first and easiest test is for `contenteditable` elements.
  22012. if (el.isContentEditable) {
  22013. return true;
  22014. } // Inputs matching these types will still trigger hotkey handling as
  22015. // they are not text inputs.
  22016. var allowedInputTypes = ['button', 'checkbox', 'hidden', 'radio', 'reset', 'submit'];
  22017. if (tagName === 'input') {
  22018. return allowedInputTypes.indexOf(el.type) === -1;
  22019. } // The final test is by tag name. These tags will be excluded entirely.
  22020. var excludedTags = ['textarea'];
  22021. return excludedTags.indexOf(tagName) !== -1;
  22022. }; // Bail out if the user is focused on an interactive form element.
  22023. if (excludeElement(this.el_.ownerDocument.activeElement)) {
  22024. return;
  22025. }
  22026. if (typeof userActions.hotkeys === 'function') {
  22027. userActions.hotkeys.call(this, event);
  22028. } else {
  22029. this.handleHotkeys(event);
  22030. }
  22031. }
  22032. /**
  22033. * Called when this Player receives a hotkey keydown event.
  22034. * Supported player-wide hotkeys are:
  22035. *
  22036. * f - toggle fullscreen
  22037. * m - toggle mute
  22038. * k or Space - toggle play/pause
  22039. *
  22040. * @param {EventTarget~Event} event
  22041. * The `keydown` event that caused this function to be called.
  22042. */
  22043. ;
  22044. _proto.handleHotkeys = function handleHotkeys(event) {
  22045. var hotkeys = this.options_.userActions ? this.options_.userActions.hotkeys : {}; // set fullscreenKey, muteKey, playPauseKey from `hotkeys`, use defaults if not set
  22046. var _hotkeys$fullscreenKe = hotkeys.fullscreenKey,
  22047. fullscreenKey = _hotkeys$fullscreenKe === void 0 ? function (keydownEvent) {
  22048. return keycode.isEventKey(keydownEvent, 'f');
  22049. } : _hotkeys$fullscreenKe,
  22050. _hotkeys$muteKey = hotkeys.muteKey,
  22051. muteKey = _hotkeys$muteKey === void 0 ? function (keydownEvent) {
  22052. return keycode.isEventKey(keydownEvent, 'm');
  22053. } : _hotkeys$muteKey,
  22054. _hotkeys$playPauseKey = hotkeys.playPauseKey,
  22055. playPauseKey = _hotkeys$playPauseKey === void 0 ? function (keydownEvent) {
  22056. return keycode.isEventKey(keydownEvent, 'k') || keycode.isEventKey(keydownEvent, 'Space');
  22057. } : _hotkeys$playPauseKey;
  22058. if (fullscreenKey.call(this, event)) {
  22059. event.preventDefault();
  22060. event.stopPropagation();
  22061. var FSToggle = Component.getComponent('FullscreenToggle');
  22062. if (document[this.fsApi_.fullscreenEnabled] !== false) {
  22063. FSToggle.prototype.handleClick.call(this, event);
  22064. }
  22065. } else if (muteKey.call(this, event)) {
  22066. event.preventDefault();
  22067. event.stopPropagation();
  22068. var MuteToggle = Component.getComponent('MuteToggle');
  22069. MuteToggle.prototype.handleClick.call(this, event);
  22070. } else if (playPauseKey.call(this, event)) {
  22071. event.preventDefault();
  22072. event.stopPropagation();
  22073. var PlayToggle = Component.getComponent('PlayToggle');
  22074. PlayToggle.prototype.handleClick.call(this, event);
  22075. }
  22076. }
  22077. /**
  22078. * Check whether the player can play a given mimetype
  22079. *
  22080. * @see https://www.w3.org/TR/2011/WD-html5-20110113/video.html#dom-navigator-canplaytype
  22081. *
  22082. * @param {string} type
  22083. * The mimetype to check
  22084. *
  22085. * @return {string}
  22086. * 'probably', 'maybe', or '' (empty string)
  22087. */
  22088. ;
  22089. _proto.canPlayType = function canPlayType(type) {
  22090. var can; // Loop through each playback technology in the options order
  22091. for (var i = 0, j = this.options_.techOrder; i < j.length; i++) {
  22092. var techName = j[i];
  22093. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  22094. // Remove once that deprecated behavior is removed.
  22095. if (!tech) {
  22096. tech = Component.getComponent(techName);
  22097. } // Check if the current tech is defined before continuing
  22098. if (!tech) {
  22099. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  22100. continue;
  22101. } // Check if the browser supports this technology
  22102. if (tech.isSupported()) {
  22103. can = tech.canPlayType(type);
  22104. if (can) {
  22105. return can;
  22106. }
  22107. }
  22108. }
  22109. return '';
  22110. }
  22111. /**
  22112. * Select source based on tech-order or source-order
  22113. * Uses source-order selection if `options.sourceOrder` is truthy. Otherwise,
  22114. * defaults to tech-order selection
  22115. *
  22116. * @param {Array} sources
  22117. * The sources for a media asset
  22118. *
  22119. * @return {Object|boolean}
  22120. * Object of source and tech order or false
  22121. */
  22122. ;
  22123. _proto.selectSource = function selectSource(sources) {
  22124. var _this14 = this;
  22125. // Get only the techs specified in `techOrder` that exist and are supported by the
  22126. // current platform
  22127. var techs = this.options_.techOrder.map(function (techName) {
  22128. return [techName, Tech.getTech(techName)];
  22129. }).filter(function (_ref) {
  22130. var techName = _ref[0],
  22131. tech = _ref[1];
  22132. // Check if the current tech is defined before continuing
  22133. if (tech) {
  22134. // Check if the browser supports this technology
  22135. return tech.isSupported();
  22136. }
  22137. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  22138. return false;
  22139. }); // Iterate over each `innerArray` element once per `outerArray` element and execute
  22140. // `tester` with both. If `tester` returns a non-falsy value, exit early and return
  22141. // that value.
  22142. var findFirstPassingTechSourcePair = function findFirstPassingTechSourcePair(outerArray, innerArray, tester) {
  22143. var found;
  22144. outerArray.some(function (outerChoice) {
  22145. return innerArray.some(function (innerChoice) {
  22146. found = tester(outerChoice, innerChoice);
  22147. if (found) {
  22148. return true;
  22149. }
  22150. });
  22151. });
  22152. return found;
  22153. };
  22154. var foundSourceAndTech;
  22155. var flip = function flip(fn) {
  22156. return function (a, b) {
  22157. return fn(b, a);
  22158. };
  22159. };
  22160. var finder = function finder(_ref2, source) {
  22161. var techName = _ref2[0],
  22162. tech = _ref2[1];
  22163. if (tech.canPlaySource(source, _this14.options_[techName.toLowerCase()])) {
  22164. return {
  22165. source: source,
  22166. tech: techName
  22167. };
  22168. }
  22169. }; // Depending on the truthiness of `options.sourceOrder`, we swap the order of techs and sources
  22170. // to select from them based on their priority.
  22171. if (this.options_.sourceOrder) {
  22172. // Source-first ordering
  22173. foundSourceAndTech = findFirstPassingTechSourcePair(sources, techs, flip(finder));
  22174. } else {
  22175. // Tech-first ordering
  22176. foundSourceAndTech = findFirstPassingTechSourcePair(techs, sources, finder);
  22177. }
  22178. return foundSourceAndTech || false;
  22179. }
  22180. /**
  22181. * Executes source setting and getting logic
  22182. *
  22183. * @param {Tech~SourceObject|Tech~SourceObject[]|string} [source]
  22184. * A SourceObject, an array of SourceObjects, or a string referencing
  22185. * a URL to a media source. It is _highly recommended_ that an object
  22186. * or array of objects is used here, so that source selection
  22187. * algorithms can take the `type` into account.
  22188. *
  22189. * If not provided, this method acts as a getter.
  22190. * @param {boolean} isRetry
  22191. * Indicates whether this is being called internally as a result of a retry
  22192. *
  22193. * @return {string|undefined}
  22194. * If the `source` argument is missing, returns the current source
  22195. * URL. Otherwise, returns nothing/undefined.
  22196. */
  22197. ;
  22198. _proto.handleSrc_ = function handleSrc_(source, isRetry) {
  22199. var _this15 = this;
  22200. // getter usage
  22201. if (typeof source === 'undefined') {
  22202. return this.cache_.src || '';
  22203. } // Reset retry behavior for new source
  22204. if (this.resetRetryOnError_) {
  22205. this.resetRetryOnError_();
  22206. } // filter out invalid sources and turn our source into
  22207. // an array of source objects
  22208. var sources = filterSource(source); // if a source was passed in then it is invalid because
  22209. // it was filtered to a zero length Array. So we have to
  22210. // show an error
  22211. if (!sources.length) {
  22212. this.setTimeout(function () {
  22213. this.error({
  22214. code: 4,
  22215. message: this.options_.notSupportedMessage
  22216. });
  22217. }, 0);
  22218. return;
  22219. } // initial sources
  22220. this.changingSrc_ = true; // Only update the cached source list if we are not retrying a new source after error,
  22221. // since in that case we want to include the failed source(s) in the cache
  22222. if (!isRetry) {
  22223. this.cache_.sources = sources;
  22224. }
  22225. this.updateSourceCaches_(sources[0]); // middlewareSource is the source after it has been changed by middleware
  22226. setSource(this, sources[0], function (middlewareSource, mws) {
  22227. _this15.middleware_ = mws; // since sourceSet is async we have to update the cache again after we select a source since
  22228. // the source that is selected could be out of order from the cache update above this callback.
  22229. if (!isRetry) {
  22230. _this15.cache_.sources = sources;
  22231. }
  22232. _this15.updateSourceCaches_(middlewareSource);
  22233. var err = _this15.src_(middlewareSource);
  22234. if (err) {
  22235. if (sources.length > 1) {
  22236. return _this15.handleSrc_(sources.slice(1));
  22237. }
  22238. _this15.changingSrc_ = false; // We need to wrap this in a timeout to give folks a chance to add error event handlers
  22239. _this15.setTimeout(function () {
  22240. this.error({
  22241. code: 4,
  22242. message: this.options_.notSupportedMessage
  22243. });
  22244. }, 0); // we could not find an appropriate tech, but let's still notify the delegate that this is it
  22245. // this needs a better comment about why this is needed
  22246. _this15.triggerReady();
  22247. return;
  22248. }
  22249. setTech(mws, _this15.tech_);
  22250. }); // Try another available source if this one fails before playback.
  22251. if (this.options_.retryOnError && sources.length > 1) {
  22252. var retry = function retry() {
  22253. // Remove the error modal
  22254. _this15.error(null);
  22255. _this15.handleSrc_(sources.slice(1), true);
  22256. };
  22257. var stopListeningForErrors = function stopListeningForErrors() {
  22258. _this15.off('error', retry);
  22259. };
  22260. this.one('error', retry);
  22261. this.one('playing', stopListeningForErrors);
  22262. this.resetRetryOnError_ = function () {
  22263. _this15.off('error', retry);
  22264. _this15.off('playing', stopListeningForErrors);
  22265. };
  22266. }
  22267. }
  22268. /**
  22269. * Get or set the video source.
  22270. *
  22271. * @param {Tech~SourceObject|Tech~SourceObject[]|string} [source]
  22272. * A SourceObject, an array of SourceObjects, or a string referencing
  22273. * a URL to a media source. It is _highly recommended_ that an object
  22274. * or array of objects is used here, so that source selection
  22275. * algorithms can take the `type` into account.
  22276. *
  22277. * If not provided, this method acts as a getter.
  22278. *
  22279. * @return {string|undefined}
  22280. * If the `source` argument is missing, returns the current source
  22281. * URL. Otherwise, returns nothing/undefined.
  22282. */
  22283. ;
  22284. _proto.src = function src(source) {
  22285. return this.handleSrc_(source, false);
  22286. }
  22287. /**
  22288. * Set the source object on the tech, returns a boolean that indicates whether
  22289. * there is a tech that can play the source or not
  22290. *
  22291. * @param {Tech~SourceObject} source
  22292. * The source object to set on the Tech
  22293. *
  22294. * @return {boolean}
  22295. * - True if there is no Tech to playback this source
  22296. * - False otherwise
  22297. *
  22298. * @private
  22299. */
  22300. ;
  22301. _proto.src_ = function src_(source) {
  22302. var _this16 = this;
  22303. var sourceTech = this.selectSource([source]);
  22304. if (!sourceTech) {
  22305. return true;
  22306. }
  22307. if (!titleCaseEquals(sourceTech.tech, this.techName_)) {
  22308. this.changingSrc_ = true; // load this technology with the chosen source
  22309. this.loadTech_(sourceTech.tech, sourceTech.source);
  22310. this.tech_.ready(function () {
  22311. _this16.changingSrc_ = false;
  22312. });
  22313. return false;
  22314. } // wait until the tech is ready to set the source
  22315. // and set it synchronously if possible (#2326)
  22316. this.ready(function () {
  22317. // The setSource tech method was added with source handlers
  22318. // so older techs won't support it
  22319. // We need to check the direct prototype for the case where subclasses
  22320. // of the tech do not support source handlers
  22321. if (this.tech_.constructor.prototype.hasOwnProperty('setSource')) {
  22322. this.techCall_('setSource', source);
  22323. } else {
  22324. this.techCall_('src', source.src);
  22325. }
  22326. this.changingSrc_ = false;
  22327. }, true);
  22328. return false;
  22329. }
  22330. /**
  22331. * Begin loading the src data.
  22332. */
  22333. ;
  22334. _proto.load = function load() {
  22335. this.techCall_('load');
  22336. }
  22337. /**
  22338. * Reset the player. Loads the first tech in the techOrder,
  22339. * removes all the text tracks in the existing `tech`,
  22340. * and calls `reset` on the `tech`.
  22341. */
  22342. ;
  22343. _proto.reset = function reset() {
  22344. var _this17 = this;
  22345. var PromiseClass = this.options_.Promise || window.Promise;
  22346. if (this.paused() || !PromiseClass) {
  22347. this.doReset_();
  22348. } else {
  22349. var playPromise = this.play();
  22350. silencePromise(playPromise.then(function () {
  22351. return _this17.doReset_();
  22352. }));
  22353. }
  22354. };
  22355. _proto.doReset_ = function doReset_() {
  22356. if (this.tech_) {
  22357. this.tech_.clearTracks('text');
  22358. }
  22359. this.resetCache_();
  22360. this.poster('');
  22361. this.loadTech_(this.options_.techOrder[0], null);
  22362. this.techCall_('reset');
  22363. this.resetControlBarUI_();
  22364. if (isEvented(this)) {
  22365. this.trigger('playerreset');
  22366. }
  22367. }
  22368. /**
  22369. * Reset Control Bar's UI by calling sub-methods that reset
  22370. * all of Control Bar's components
  22371. */
  22372. ;
  22373. _proto.resetControlBarUI_ = function resetControlBarUI_() {
  22374. this.resetProgressBar_();
  22375. this.resetPlaybackRate_();
  22376. this.resetVolumeBar_();
  22377. }
  22378. /**
  22379. * Reset tech's progress so progress bar is reset in the UI
  22380. */
  22381. ;
  22382. _proto.resetProgressBar_ = function resetProgressBar_() {
  22383. this.currentTime(0);
  22384. var _ref3 = this.controlBar || {},
  22385. durationDisplay = _ref3.durationDisplay,
  22386. remainingTimeDisplay = _ref3.remainingTimeDisplay;
  22387. if (durationDisplay) {
  22388. durationDisplay.updateContent();
  22389. }
  22390. if (remainingTimeDisplay) {
  22391. remainingTimeDisplay.updateContent();
  22392. }
  22393. }
  22394. /**
  22395. * Reset Playback ratio
  22396. */
  22397. ;
  22398. _proto.resetPlaybackRate_ = function resetPlaybackRate_() {
  22399. this.playbackRate(this.defaultPlaybackRate());
  22400. this.handleTechRateChange_();
  22401. }
  22402. /**
  22403. * Reset Volume bar
  22404. */
  22405. ;
  22406. _proto.resetVolumeBar_ = function resetVolumeBar_() {
  22407. this.volume(1.0);
  22408. this.trigger('volumechange');
  22409. }
  22410. /**
  22411. * Returns all of the current source objects.
  22412. *
  22413. * @return {Tech~SourceObject[]}
  22414. * The current source objects
  22415. */
  22416. ;
  22417. _proto.currentSources = function currentSources() {
  22418. var source = this.currentSource();
  22419. var sources = []; // assume `{}` or `{ src }`
  22420. if (Object.keys(source).length !== 0) {
  22421. sources.push(source);
  22422. }
  22423. return this.cache_.sources || sources;
  22424. }
  22425. /**
  22426. * Returns the current source object.
  22427. *
  22428. * @return {Tech~SourceObject}
  22429. * The current source object
  22430. */
  22431. ;
  22432. _proto.currentSource = function currentSource() {
  22433. return this.cache_.source || {};
  22434. }
  22435. /**
  22436. * Returns the fully qualified URL of the current source value e.g. http://mysite.com/video.mp4
  22437. * Can be used in conjunction with `currentType` to assist in rebuilding the current source object.
  22438. *
  22439. * @return {string}
  22440. * The current source
  22441. */
  22442. ;
  22443. _proto.currentSrc = function currentSrc() {
  22444. return this.currentSource() && this.currentSource().src || '';
  22445. }
  22446. /**
  22447. * Get the current source type e.g. video/mp4
  22448. * This can allow you rebuild the current source object so that you could load the same
  22449. * source and tech later
  22450. *
  22451. * @return {string}
  22452. * The source MIME type
  22453. */
  22454. ;
  22455. _proto.currentType = function currentType() {
  22456. return this.currentSource() && this.currentSource().type || '';
  22457. }
  22458. /**
  22459. * Get or set the preload attribute
  22460. *
  22461. * @param {boolean} [value]
  22462. * - true means that we should preload
  22463. * - false means that we should not preload
  22464. *
  22465. * @return {string}
  22466. * The preload attribute value when getting
  22467. */
  22468. ;
  22469. _proto.preload = function preload(value) {
  22470. if (value !== undefined) {
  22471. this.techCall_('setPreload', value);
  22472. this.options_.preload = value;
  22473. return;
  22474. }
  22475. return this.techGet_('preload');
  22476. }
  22477. /**
  22478. * Get or set the autoplay option. When this is a boolean it will
  22479. * modify the attribute on the tech. When this is a string the attribute on
  22480. * the tech will be removed and `Player` will handle autoplay on loadstarts.
  22481. *
  22482. * @param {boolean|string} [value]
  22483. * - true: autoplay using the browser behavior
  22484. * - false: do not autoplay
  22485. * - 'play': call play() on every loadstart
  22486. * - 'muted': call muted() then play() on every loadstart
  22487. * - 'any': call play() on every loadstart. if that fails call muted() then play().
  22488. * - *: values other than those listed here will be set `autoplay` to true
  22489. *
  22490. * @return {boolean|string}
  22491. * The current value of autoplay when getting
  22492. */
  22493. ;
  22494. _proto.autoplay = function autoplay(value) {
  22495. // getter usage
  22496. if (value === undefined) {
  22497. return this.options_.autoplay || false;
  22498. }
  22499. var techAutoplay; // if the value is a valid string set it to that, or normalize `true` to 'play', if need be
  22500. if (typeof value === 'string' && /(any|play|muted)/.test(value) || value === true && this.options_.normalizeAutoplay) {
  22501. this.options_.autoplay = value;
  22502. this.manualAutoplay_(typeof value === 'string' ? value : 'play');
  22503. techAutoplay = false; // any falsy value sets autoplay to false in the browser,
  22504. // lets do the same
  22505. } else if (!value) {
  22506. this.options_.autoplay = false; // any other value (ie truthy) sets autoplay to true
  22507. } else {
  22508. this.options_.autoplay = true;
  22509. }
  22510. techAutoplay = typeof techAutoplay === 'undefined' ? this.options_.autoplay : techAutoplay; // if we don't have a tech then we do not queue up
  22511. // a setAutoplay call on tech ready. We do this because the
  22512. // autoplay option will be passed in the constructor and we
  22513. // do not need to set it twice
  22514. if (this.tech_) {
  22515. this.techCall_('setAutoplay', techAutoplay);
  22516. }
  22517. }
  22518. /**
  22519. * Set or unset the playsinline attribute.
  22520. * Playsinline tells the browser that non-fullscreen playback is preferred.
  22521. *
  22522. * @param {boolean} [value]
  22523. * - true means that we should try to play inline by default
  22524. * - false means that we should use the browser's default playback mode,
  22525. * which in most cases is inline. iOS Safari is a notable exception
  22526. * and plays fullscreen by default.
  22527. *
  22528. * @return {string|Player}
  22529. * - the current value of playsinline
  22530. * - the player when setting
  22531. *
  22532. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  22533. */
  22534. ;
  22535. _proto.playsinline = function playsinline(value) {
  22536. if (value !== undefined) {
  22537. this.techCall_('setPlaysinline', value);
  22538. this.options_.playsinline = value;
  22539. return this;
  22540. }
  22541. return this.techGet_('playsinline');
  22542. }
  22543. /**
  22544. * Get or set the loop attribute on the video element.
  22545. *
  22546. * @param {boolean} [value]
  22547. * - true means that we should loop the video
  22548. * - false means that we should not loop the video
  22549. *
  22550. * @return {boolean}
  22551. * The current value of loop when getting
  22552. */
  22553. ;
  22554. _proto.loop = function loop(value) {
  22555. if (value !== undefined) {
  22556. this.techCall_('setLoop', value);
  22557. this.options_.loop = value;
  22558. return;
  22559. }
  22560. return this.techGet_('loop');
  22561. }
  22562. /**
  22563. * Get or set the poster image source url
  22564. *
  22565. * @fires Player#posterchange
  22566. *
  22567. * @param {string} [src]
  22568. * Poster image source URL
  22569. *
  22570. * @return {string}
  22571. * The current value of poster when getting
  22572. */
  22573. ;
  22574. _proto.poster = function poster(src) {
  22575. if (src === undefined) {
  22576. return this.poster_;
  22577. } // The correct way to remove a poster is to set as an empty string
  22578. // other falsey values will throw errors
  22579. if (!src) {
  22580. src = '';
  22581. }
  22582. if (src === this.poster_) {
  22583. return;
  22584. } // update the internal poster variable
  22585. this.poster_ = src; // update the tech's poster
  22586. this.techCall_('setPoster', src);
  22587. this.isPosterFromTech_ = false; // alert components that the poster has been set
  22588. /**
  22589. * This event fires when the poster image is changed on the player.
  22590. *
  22591. * @event Player#posterchange
  22592. * @type {EventTarget~Event}
  22593. */
  22594. this.trigger('posterchange');
  22595. }
  22596. /**
  22597. * Some techs (e.g. YouTube) can provide a poster source in an
  22598. * asynchronous way. We want the poster component to use this
  22599. * poster source so that it covers up the tech's controls.
  22600. * (YouTube's play button). However we only want to use this
  22601. * source if the player user hasn't set a poster through
  22602. * the normal APIs.
  22603. *
  22604. * @fires Player#posterchange
  22605. * @listens Tech#posterchange
  22606. * @private
  22607. */
  22608. ;
  22609. _proto.handleTechPosterChange_ = function handleTechPosterChange_() {
  22610. if ((!this.poster_ || this.options_.techCanOverridePoster) && this.tech_ && this.tech_.poster) {
  22611. var newPoster = this.tech_.poster() || '';
  22612. if (newPoster !== this.poster_) {
  22613. this.poster_ = newPoster;
  22614. this.isPosterFromTech_ = true; // Let components know the poster has changed
  22615. this.trigger('posterchange');
  22616. }
  22617. }
  22618. }
  22619. /**
  22620. * Get or set whether or not the controls are showing.
  22621. *
  22622. * @fires Player#controlsenabled
  22623. *
  22624. * @param {boolean} [bool]
  22625. * - true to turn controls on
  22626. * - false to turn controls off
  22627. *
  22628. * @return {boolean}
  22629. * The current value of controls when getting
  22630. */
  22631. ;
  22632. _proto.controls = function controls(bool) {
  22633. if (bool === undefined) {
  22634. return !!this.controls_;
  22635. }
  22636. bool = !!bool; // Don't trigger a change event unless it actually changed
  22637. if (this.controls_ === bool) {
  22638. return;
  22639. }
  22640. this.controls_ = bool;
  22641. if (this.usingNativeControls()) {
  22642. this.techCall_('setControls', bool);
  22643. }
  22644. if (this.controls_) {
  22645. this.removeClass('vjs-controls-disabled');
  22646. this.addClass('vjs-controls-enabled');
  22647. /**
  22648. * @event Player#controlsenabled
  22649. * @type {EventTarget~Event}
  22650. */
  22651. this.trigger('controlsenabled');
  22652. if (!this.usingNativeControls()) {
  22653. this.addTechControlsListeners_();
  22654. }
  22655. } else {
  22656. this.removeClass('vjs-controls-enabled');
  22657. this.addClass('vjs-controls-disabled');
  22658. /**
  22659. * @event Player#controlsdisabled
  22660. * @type {EventTarget~Event}
  22661. */
  22662. this.trigger('controlsdisabled');
  22663. if (!this.usingNativeControls()) {
  22664. this.removeTechControlsListeners_();
  22665. }
  22666. }
  22667. }
  22668. /**
  22669. * Toggle native controls on/off. Native controls are the controls built into
  22670. * devices (e.g. default iPhone controls) or other techs
  22671. * (e.g. Vimeo Controls)
  22672. * **This should only be set by the current tech, because only the tech knows
  22673. * if it can support native controls**
  22674. *
  22675. * @fires Player#usingnativecontrols
  22676. * @fires Player#usingcustomcontrols
  22677. *
  22678. * @param {boolean} [bool]
  22679. * - true to turn native controls on
  22680. * - false to turn native controls off
  22681. *
  22682. * @return {boolean}
  22683. * The current value of native controls when getting
  22684. */
  22685. ;
  22686. _proto.usingNativeControls = function usingNativeControls(bool) {
  22687. if (bool === undefined) {
  22688. return !!this.usingNativeControls_;
  22689. }
  22690. bool = !!bool; // Don't trigger a change event unless it actually changed
  22691. if (this.usingNativeControls_ === bool) {
  22692. return;
  22693. }
  22694. this.usingNativeControls_ = bool;
  22695. if (this.usingNativeControls_) {
  22696. this.addClass('vjs-using-native-controls');
  22697. /**
  22698. * player is using the native device controls
  22699. *
  22700. * @event Player#usingnativecontrols
  22701. * @type {EventTarget~Event}
  22702. */
  22703. this.trigger('usingnativecontrols');
  22704. } else {
  22705. this.removeClass('vjs-using-native-controls');
  22706. /**
  22707. * player is using the custom HTML controls
  22708. *
  22709. * @event Player#usingcustomcontrols
  22710. * @type {EventTarget~Event}
  22711. */
  22712. this.trigger('usingcustomcontrols');
  22713. }
  22714. }
  22715. /**
  22716. * Set or get the current MediaError
  22717. *
  22718. * @fires Player#error
  22719. *
  22720. * @param {MediaError|string|number} [err]
  22721. * A MediaError or a string/number to be turned
  22722. * into a MediaError
  22723. *
  22724. * @return {MediaError|null}
  22725. * The current MediaError when getting (or null)
  22726. */
  22727. ;
  22728. _proto.error = function error(err) {
  22729. var _this18 = this;
  22730. if (err === undefined) {
  22731. return this.error_ || null;
  22732. } // allow hooks to modify error object
  22733. hooks('beforeerror').forEach(function (hookFunction) {
  22734. var newErr = hookFunction(_this18, err);
  22735. if (!(isObject(newErr) && !Array.isArray(newErr) || typeof newErr === 'string' || typeof newErr === 'number' || newErr === null)) {
  22736. _this18.log.error('please return a value that MediaError expects in beforeerror hooks');
  22737. return;
  22738. }
  22739. err = newErr;
  22740. }); // Suppress the first error message for no compatible source until
  22741. // user interaction
  22742. if (this.options_.suppressNotSupportedError && err && err.code === 4) {
  22743. var triggerSuppressedError = function triggerSuppressedError() {
  22744. this.error(err);
  22745. };
  22746. this.options_.suppressNotSupportedError = false;
  22747. this.any(['click', 'touchstart'], triggerSuppressedError);
  22748. this.one('loadstart', function () {
  22749. this.off(['click', 'touchstart'], triggerSuppressedError);
  22750. });
  22751. return;
  22752. } // restoring to default
  22753. if (err === null) {
  22754. this.error_ = err;
  22755. this.removeClass('vjs-error');
  22756. if (this.errorDisplay) {
  22757. this.errorDisplay.close();
  22758. }
  22759. return;
  22760. }
  22761. this.error_ = new MediaError(err); // add the vjs-error classname to the player
  22762. this.addClass('vjs-error'); // log the name of the error type and any message
  22763. // IE11 logs "[object object]" and required you to expand message to see error object
  22764. log.error("(CODE:" + this.error_.code + " " + MediaError.errorTypes[this.error_.code] + ")", this.error_.message, this.error_);
  22765. /**
  22766. * @event Player#error
  22767. * @type {EventTarget~Event}
  22768. */
  22769. this.trigger('error'); // notify hooks of the per player error
  22770. hooks('error').forEach(function (hookFunction) {
  22771. return hookFunction(_this18, _this18.error_);
  22772. });
  22773. return;
  22774. }
  22775. /**
  22776. * Report user activity
  22777. *
  22778. * @param {Object} event
  22779. * Event object
  22780. */
  22781. ;
  22782. _proto.reportUserActivity = function reportUserActivity(event) {
  22783. this.userActivity_ = true;
  22784. }
  22785. /**
  22786. * Get/set if user is active
  22787. *
  22788. * @fires Player#useractive
  22789. * @fires Player#userinactive
  22790. *
  22791. * @param {boolean} [bool]
  22792. * - true if the user is active
  22793. * - false if the user is inactive
  22794. *
  22795. * @return {boolean}
  22796. * The current value of userActive when getting
  22797. */
  22798. ;
  22799. _proto.userActive = function userActive(bool) {
  22800. if (bool === undefined) {
  22801. return this.userActive_;
  22802. }
  22803. bool = !!bool;
  22804. if (bool === this.userActive_) {
  22805. return;
  22806. }
  22807. this.userActive_ = bool;
  22808. if (this.userActive_) {
  22809. this.userActivity_ = true;
  22810. this.removeClass('vjs-user-inactive');
  22811. this.addClass('vjs-user-active');
  22812. /**
  22813. * @event Player#useractive
  22814. * @type {EventTarget~Event}
  22815. */
  22816. this.trigger('useractive');
  22817. return;
  22818. } // Chrome/Safari/IE have bugs where when you change the cursor it can
  22819. // trigger a mousemove event. This causes an issue when you're hiding
  22820. // the cursor when the user is inactive, and a mousemove signals user
  22821. // activity. Making it impossible to go into inactive mode. Specifically
  22822. // this happens in fullscreen when we really need to hide the cursor.
  22823. //
  22824. // When this gets resolved in ALL browsers it can be removed
  22825. // https://code.google.com/p/chromium/issues/detail?id=103041
  22826. if (this.tech_) {
  22827. this.tech_.one('mousemove', function (e) {
  22828. e.stopPropagation();
  22829. e.preventDefault();
  22830. });
  22831. }
  22832. this.userActivity_ = false;
  22833. this.removeClass('vjs-user-active');
  22834. this.addClass('vjs-user-inactive');
  22835. /**
  22836. * @event Player#userinactive
  22837. * @type {EventTarget~Event}
  22838. */
  22839. this.trigger('userinactive');
  22840. }
  22841. /**
  22842. * Listen for user activity based on timeout value
  22843. *
  22844. * @private
  22845. */
  22846. ;
  22847. _proto.listenForUserActivity_ = function listenForUserActivity_() {
  22848. var mouseInProgress;
  22849. var lastMoveX;
  22850. var lastMoveY;
  22851. var handleActivity = bind(this, this.reportUserActivity);
  22852. var handleMouseMove = function handleMouseMove(e) {
  22853. // #1068 - Prevent mousemove spamming
  22854. // Chrome Bug: https://code.google.com/p/chromium/issues/detail?id=366970
  22855. if (e.screenX !== lastMoveX || e.screenY !== lastMoveY) {
  22856. lastMoveX = e.screenX;
  22857. lastMoveY = e.screenY;
  22858. handleActivity();
  22859. }
  22860. };
  22861. var handleMouseDown = function handleMouseDown() {
  22862. handleActivity(); // For as long as the they are touching the device or have their mouse down,
  22863. // we consider them active even if they're not moving their finger or mouse.
  22864. // So we want to continue to update that they are active
  22865. this.clearInterval(mouseInProgress); // Setting userActivity=true now and setting the interval to the same time
  22866. // as the activityCheck interval (250) should ensure we never miss the
  22867. // next activityCheck
  22868. mouseInProgress = this.setInterval(handleActivity, 250);
  22869. };
  22870. var handleMouseUpAndMouseLeave = function handleMouseUpAndMouseLeave(event) {
  22871. handleActivity(); // Stop the interval that maintains activity if the mouse/touch is down
  22872. this.clearInterval(mouseInProgress);
  22873. }; // Any mouse movement will be considered user activity
  22874. this.on('mousedown', handleMouseDown);
  22875. this.on('mousemove', handleMouseMove);
  22876. this.on('mouseup', handleMouseUpAndMouseLeave);
  22877. this.on('mouseleave', handleMouseUpAndMouseLeave);
  22878. var controlBar = this.getChild('controlBar'); // Fixes bug on Android & iOS where when tapping progressBar (when control bar is displayed)
  22879. // controlBar would no longer be hidden by default timeout.
  22880. if (controlBar && !IS_IOS && !IS_ANDROID) {
  22881. controlBar.on('mouseenter', function (event) {
  22882. if (this.player().options_.inactivityTimeout !== 0) {
  22883. this.player().cache_.inactivityTimeout = this.player().options_.inactivityTimeout;
  22884. }
  22885. this.player().options_.inactivityTimeout = 0;
  22886. });
  22887. controlBar.on('mouseleave', function (event) {
  22888. this.player().options_.inactivityTimeout = this.player().cache_.inactivityTimeout;
  22889. });
  22890. } // Listen for keyboard navigation
  22891. // Shouldn't need to use inProgress interval because of key repeat
  22892. this.on('keydown', handleActivity);
  22893. this.on('keyup', handleActivity); // Run an interval every 250 milliseconds instead of stuffing everything into
  22894. // the mousemove/touchmove function itself, to prevent performance degradation.
  22895. // `this.reportUserActivity` simply sets this.userActivity_ to true, which
  22896. // then gets picked up by this loop
  22897. // http://ejohn.org/blog/learning-from-twitter/
  22898. var inactivityTimeout;
  22899. this.setInterval(function () {
  22900. // Check to see if mouse/touch activity has happened
  22901. if (!this.userActivity_) {
  22902. return;
  22903. } // Reset the activity tracker
  22904. this.userActivity_ = false; // If the user state was inactive, set the state to active
  22905. this.userActive(true); // Clear any existing inactivity timeout to start the timer over
  22906. this.clearTimeout(inactivityTimeout);
  22907. var timeout = this.options_.inactivityTimeout;
  22908. if (timeout <= 0) {
  22909. return;
  22910. } // In <timeout> milliseconds, if no more activity has occurred the
  22911. // user will be considered inactive
  22912. inactivityTimeout = this.setTimeout(function () {
  22913. // Protect against the case where the inactivityTimeout can trigger just
  22914. // before the next user activity is picked up by the activity check loop
  22915. // causing a flicker
  22916. if (!this.userActivity_) {
  22917. this.userActive(false);
  22918. }
  22919. }, timeout);
  22920. }, 250);
  22921. }
  22922. /**
  22923. * Gets or sets the current playback rate. A playback rate of
  22924. * 1.0 represents normal speed and 0.5 would indicate half-speed
  22925. * playback, for instance.
  22926. *
  22927. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-playbackrate
  22928. *
  22929. * @param {number} [rate]
  22930. * New playback rate to set.
  22931. *
  22932. * @return {number}
  22933. * The current playback rate when getting or 1.0
  22934. */
  22935. ;
  22936. _proto.playbackRate = function playbackRate(rate) {
  22937. if (rate !== undefined) {
  22938. // NOTE: this.cache_.lastPlaybackRate is set from the tech handler
  22939. // that is registered above
  22940. this.techCall_('setPlaybackRate', rate);
  22941. return;
  22942. }
  22943. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  22944. return this.cache_.lastPlaybackRate || this.techGet_('playbackRate');
  22945. }
  22946. return 1.0;
  22947. }
  22948. /**
  22949. * Gets or sets the current default playback rate. A default playback rate of
  22950. * 1.0 represents normal speed and 0.5 would indicate half-speed playback, for instance.
  22951. * defaultPlaybackRate will only represent what the initial playbackRate of a video was, not
  22952. * not the current playbackRate.
  22953. *
  22954. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-defaultplaybackrate
  22955. *
  22956. * @param {number} [rate]
  22957. * New default playback rate to set.
  22958. *
  22959. * @return {number|Player}
  22960. * - The default playback rate when getting or 1.0
  22961. * - the player when setting
  22962. */
  22963. ;
  22964. _proto.defaultPlaybackRate = function defaultPlaybackRate(rate) {
  22965. if (rate !== undefined) {
  22966. return this.techCall_('setDefaultPlaybackRate', rate);
  22967. }
  22968. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  22969. return this.techGet_('defaultPlaybackRate');
  22970. }
  22971. return 1.0;
  22972. }
  22973. /**
  22974. * Gets or sets the audio flag
  22975. *
  22976. * @param {boolean} bool
  22977. * - true signals that this is an audio player
  22978. * - false signals that this is not an audio player
  22979. *
  22980. * @return {boolean}
  22981. * The current value of isAudio when getting
  22982. */
  22983. ;
  22984. _proto.isAudio = function isAudio(bool) {
  22985. if (bool !== undefined) {
  22986. this.isAudio_ = !!bool;
  22987. return;
  22988. }
  22989. return !!this.isAudio_;
  22990. };
  22991. _proto.enableAudioOnlyUI_ = function enableAudioOnlyUI_() {
  22992. var _this19 = this;
  22993. // Update styling immediately to show the control bar so we can get its height
  22994. this.addClass('vjs-audio-only-mode');
  22995. var playerChildren = this.children();
  22996. var controlBar = this.getChild('ControlBar');
  22997. var controlBarHeight = controlBar && controlBar.currentHeight(); // Hide all player components except the control bar. Control bar components
  22998. // needed only for video are hidden with CSS
  22999. playerChildren.forEach(function (child) {
  23000. if (child === controlBar) {
  23001. return;
  23002. }
  23003. if (child.el_ && !child.hasClass('vjs-hidden')) {
  23004. child.hide();
  23005. _this19.audioOnlyCache_.hiddenChildren.push(child);
  23006. }
  23007. });
  23008. this.audioOnlyCache_.playerHeight = this.currentHeight(); // Set the player height the same as the control bar
  23009. this.height(controlBarHeight);
  23010. this.trigger('audioonlymodechange');
  23011. };
  23012. _proto.disableAudioOnlyUI_ = function disableAudioOnlyUI_() {
  23013. this.removeClass('vjs-audio-only-mode'); // Show player components that were previously hidden
  23014. this.audioOnlyCache_.hiddenChildren.forEach(function (child) {
  23015. return child.show();
  23016. }); // Reset player height
  23017. this.height(this.audioOnlyCache_.playerHeight);
  23018. this.trigger('audioonlymodechange');
  23019. }
  23020. /**
  23021. * Get the current audioOnlyMode state or set audioOnlyMode to true or false.
  23022. *
  23023. * Setting this to `true` will hide all player components except the control bar,
  23024. * as well as control bar components needed only for video.
  23025. *
  23026. * @param {boolean} [value]
  23027. * The value to set audioOnlyMode to.
  23028. *
  23029. * @return {Promise|boolean}
  23030. * A Promise is returned when setting the state, and a boolean when getting
  23031. * the present state
  23032. */
  23033. ;
  23034. _proto.audioOnlyMode = function audioOnlyMode(value) {
  23035. var _this20 = this;
  23036. if (typeof value !== 'boolean' || value === this.audioOnlyMode_) {
  23037. return this.audioOnlyMode_;
  23038. }
  23039. this.audioOnlyMode_ = value;
  23040. var PromiseClass = this.options_.Promise || window.Promise;
  23041. if (PromiseClass) {
  23042. // Enable Audio Only Mode
  23043. if (value) {
  23044. var exitPromises = []; // Fullscreen and PiP are not supported in audioOnlyMode, so exit if we need to.
  23045. if (this.isInPictureInPicture()) {
  23046. exitPromises.push(this.exitPictureInPicture());
  23047. }
  23048. if (this.isFullscreen()) {
  23049. exitPromises.push(this.exitFullscreen());
  23050. }
  23051. if (this.audioPosterMode()) {
  23052. exitPromises.push(this.audioPosterMode(false));
  23053. }
  23054. return PromiseClass.all(exitPromises).then(function () {
  23055. return _this20.enableAudioOnlyUI_();
  23056. });
  23057. } // Disable Audio Only Mode
  23058. return PromiseClass.resolve().then(function () {
  23059. return _this20.disableAudioOnlyUI_();
  23060. });
  23061. }
  23062. if (value) {
  23063. if (this.isInPictureInPicture()) {
  23064. this.exitPictureInPicture();
  23065. }
  23066. if (this.isFullscreen()) {
  23067. this.exitFullscreen();
  23068. }
  23069. this.enableAudioOnlyUI_();
  23070. } else {
  23071. this.disableAudioOnlyUI_();
  23072. }
  23073. };
  23074. _proto.enablePosterModeUI_ = function enablePosterModeUI_() {
  23075. // Hide the video element and show the poster image to enable posterModeUI
  23076. var tech = this.tech_ && this.tech_;
  23077. tech.hide();
  23078. this.addClass('vjs-audio-poster-mode');
  23079. this.trigger('audiopostermodechange');
  23080. };
  23081. _proto.disablePosterModeUI_ = function disablePosterModeUI_() {
  23082. // Show the video element and hide the poster image to disable posterModeUI
  23083. var tech = this.tech_ && this.tech_;
  23084. tech.show();
  23085. this.removeClass('vjs-audio-poster-mode');
  23086. this.trigger('audiopostermodechange');
  23087. }
  23088. /**
  23089. * Get the current audioPosterMode state or set audioPosterMode to true or false
  23090. *
  23091. * @param {boolean} [value]
  23092. * The value to set audioPosterMode to.
  23093. *
  23094. * @return {Promise|boolean}
  23095. * A Promise is returned when setting the state, and a boolean when getting
  23096. * the present state
  23097. */
  23098. ;
  23099. _proto.audioPosterMode = function audioPosterMode(value) {
  23100. var _this21 = this;
  23101. if (typeof value !== 'boolean' || value === this.audioPosterMode_) {
  23102. return this.audioPosterMode_;
  23103. }
  23104. this.audioPosterMode_ = value;
  23105. var PromiseClass = this.options_.Promise || window.Promise;
  23106. if (PromiseClass) {
  23107. if (value) {
  23108. if (this.audioOnlyMode()) {
  23109. var audioOnlyModePromise = this.audioOnlyMode(false);
  23110. return audioOnlyModePromise.then(function () {
  23111. // enable audio poster mode after audio only mode is disabled
  23112. _this21.enablePosterModeUI_();
  23113. });
  23114. }
  23115. return PromiseClass.resolve().then(function () {
  23116. // enable audio poster mode
  23117. _this21.enablePosterModeUI_();
  23118. });
  23119. }
  23120. return PromiseClass.resolve().then(function () {
  23121. // disable audio poster mode
  23122. _this21.disablePosterModeUI_();
  23123. });
  23124. }
  23125. if (value) {
  23126. if (this.audioOnlyMode()) {
  23127. this.audioOnlyMode(false);
  23128. }
  23129. this.enablePosterModeUI_();
  23130. return;
  23131. }
  23132. this.disablePosterModeUI_();
  23133. }
  23134. /**
  23135. * A helper method for adding a {@link TextTrack} to our
  23136. * {@link TextTrackList}.
  23137. *
  23138. * In addition to the W3C settings we allow adding additional info through options.
  23139. *
  23140. * @see http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-addtexttrack
  23141. *
  23142. * @param {string} [kind]
  23143. * the kind of TextTrack you are adding
  23144. *
  23145. * @param {string} [label]
  23146. * the label to give the TextTrack label
  23147. *
  23148. * @param {string} [language]
  23149. * the language to set on the TextTrack
  23150. *
  23151. * @return {TextTrack|undefined}
  23152. * the TextTrack that was added or undefined
  23153. * if there is no tech
  23154. */
  23155. ;
  23156. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  23157. if (this.tech_) {
  23158. return this.tech_.addTextTrack(kind, label, language);
  23159. }
  23160. }
  23161. /**
  23162. * Create a remote {@link TextTrack} and an {@link HTMLTrackElement}.
  23163. * When manualCleanup is set to false, the track will be automatically removed
  23164. * on source changes.
  23165. *
  23166. * @param {Object} options
  23167. * Options to pass to {@link HTMLTrackElement} during creation. See
  23168. * {@link HTMLTrackElement} for object properties that you should use.
  23169. *
  23170. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  23171. * removed on a source change
  23172. *
  23173. * @return {HtmlTrackElement}
  23174. * the HTMLTrackElement that was created and added
  23175. * to the HtmlTrackElementList and the remote
  23176. * TextTrackList
  23177. *
  23178. * @deprecated The default value of the "manualCleanup" parameter will default
  23179. * to "false" in upcoming versions of Video.js
  23180. */
  23181. ;
  23182. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  23183. if (this.tech_) {
  23184. return this.tech_.addRemoteTextTrack(options, manualCleanup);
  23185. }
  23186. }
  23187. /**
  23188. * Remove a remote {@link TextTrack} from the respective
  23189. * {@link TextTrackList} and {@link HtmlTrackElementList}.
  23190. *
  23191. * @param {Object} track
  23192. * Remote {@link TextTrack} to remove
  23193. *
  23194. * @return {undefined}
  23195. * does not return anything
  23196. */
  23197. ;
  23198. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(obj) {
  23199. if (obj === void 0) {
  23200. obj = {};
  23201. }
  23202. var _obj = obj,
  23203. track = _obj.track;
  23204. if (!track) {
  23205. track = obj;
  23206. } // destructure the input into an object with a track argument, defaulting to arguments[0]
  23207. // default the whole argument to an empty object if nothing was passed in
  23208. if (this.tech_) {
  23209. return this.tech_.removeRemoteTextTrack(track);
  23210. }
  23211. }
  23212. /**
  23213. * Gets available media playback quality metrics as specified by the W3C's Media
  23214. * Playback Quality API.
  23215. *
  23216. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  23217. *
  23218. * @return {Object|undefined}
  23219. * An object with supported media playback quality metrics or undefined if there
  23220. * is no tech or the tech does not support it.
  23221. */
  23222. ;
  23223. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  23224. return this.techGet_('getVideoPlaybackQuality');
  23225. }
  23226. /**
  23227. * Get video width
  23228. *
  23229. * @return {number}
  23230. * current video width
  23231. */
  23232. ;
  23233. _proto.videoWidth = function videoWidth() {
  23234. return this.tech_ && this.tech_.videoWidth && this.tech_.videoWidth() || 0;
  23235. }
  23236. /**
  23237. * Get video height
  23238. *
  23239. * @return {number}
  23240. * current video height
  23241. */
  23242. ;
  23243. _proto.videoHeight = function videoHeight() {
  23244. return this.tech_ && this.tech_.videoHeight && this.tech_.videoHeight() || 0;
  23245. }
  23246. /**
  23247. * The player's language code.
  23248. *
  23249. * Changing the language will trigger
  23250. * [languagechange]{@link Player#event:languagechange}
  23251. * which Components can use to update control text.
  23252. * ClickableComponent will update its control text by default on
  23253. * [languagechange]{@link Player#event:languagechange}.
  23254. *
  23255. * @fires Player#languagechange
  23256. *
  23257. * @param {string} [code]
  23258. * the language code to set the player to
  23259. *
  23260. * @return {string}
  23261. * The current language code when getting
  23262. */
  23263. ;
  23264. _proto.language = function language(code) {
  23265. if (code === undefined) {
  23266. return this.language_;
  23267. }
  23268. if (this.language_ !== String(code).toLowerCase()) {
  23269. this.language_ = String(code).toLowerCase(); // during first init, it's possible some things won't be evented
  23270. if (isEvented(this)) {
  23271. /**
  23272. * fires when the player language change
  23273. *
  23274. * @event Player#languagechange
  23275. * @type {EventTarget~Event}
  23276. */
  23277. this.trigger('languagechange');
  23278. }
  23279. }
  23280. }
  23281. /**
  23282. * Get the player's language dictionary
  23283. * Merge every time, because a newly added plugin might call videojs.addLanguage() at any time
  23284. * Languages specified directly in the player options have precedence
  23285. *
  23286. * @return {Array}
  23287. * An array of of supported languages
  23288. */
  23289. ;
  23290. _proto.languages = function languages() {
  23291. return mergeOptions(Player.prototype.options_.languages, this.languages_);
  23292. }
  23293. /**
  23294. * returns a JavaScript object reperesenting the current track
  23295. * information. **DOES not return it as JSON**
  23296. *
  23297. * @return {Object}
  23298. * Object representing the current of track info
  23299. */
  23300. ;
  23301. _proto.toJSON = function toJSON() {
  23302. var options = mergeOptions(this.options_);
  23303. var tracks = options.tracks;
  23304. options.tracks = [];
  23305. for (var i = 0; i < tracks.length; i++) {
  23306. var track = tracks[i]; // deep merge tracks and null out player so no circular references
  23307. track = mergeOptions(track);
  23308. track.player = undefined;
  23309. options.tracks[i] = track;
  23310. }
  23311. return options;
  23312. }
  23313. /**
  23314. * Creates a simple modal dialog (an instance of the {@link ModalDialog}
  23315. * component) that immediately overlays the player with arbitrary
  23316. * content and removes itself when closed.
  23317. *
  23318. * @param {string|Function|Element|Array|null} content
  23319. * Same as {@link ModalDialog#content}'s param of the same name.
  23320. * The most straight-forward usage is to provide a string or DOM
  23321. * element.
  23322. *
  23323. * @param {Object} [options]
  23324. * Extra options which will be passed on to the {@link ModalDialog}.
  23325. *
  23326. * @return {ModalDialog}
  23327. * the {@link ModalDialog} that was created
  23328. */
  23329. ;
  23330. _proto.createModal = function createModal(content, options) {
  23331. var _this22 = this;
  23332. options = options || {};
  23333. options.content = content || '';
  23334. var modal = new ModalDialog(this, options);
  23335. this.addChild(modal);
  23336. modal.on('dispose', function () {
  23337. _this22.removeChild(modal);
  23338. });
  23339. modal.open();
  23340. return modal;
  23341. }
  23342. /**
  23343. * Change breakpoint classes when the player resizes.
  23344. *
  23345. * @private
  23346. */
  23347. ;
  23348. _proto.updateCurrentBreakpoint_ = function updateCurrentBreakpoint_() {
  23349. if (!this.responsive()) {
  23350. return;
  23351. }
  23352. var currentBreakpoint = this.currentBreakpoint();
  23353. var currentWidth = this.currentWidth();
  23354. for (var i = 0; i < BREAKPOINT_ORDER.length; i++) {
  23355. var candidateBreakpoint = BREAKPOINT_ORDER[i];
  23356. var maxWidth = this.breakpoints_[candidateBreakpoint];
  23357. if (currentWidth <= maxWidth) {
  23358. // The current breakpoint did not change, nothing to do.
  23359. if (currentBreakpoint === candidateBreakpoint) {
  23360. return;
  23361. } // Only remove a class if there is a current breakpoint.
  23362. if (currentBreakpoint) {
  23363. this.removeClass(BREAKPOINT_CLASSES[currentBreakpoint]);
  23364. }
  23365. this.addClass(BREAKPOINT_CLASSES[candidateBreakpoint]);
  23366. this.breakpoint_ = candidateBreakpoint;
  23367. break;
  23368. }
  23369. }
  23370. }
  23371. /**
  23372. * Removes the current breakpoint.
  23373. *
  23374. * @private
  23375. */
  23376. ;
  23377. _proto.removeCurrentBreakpoint_ = function removeCurrentBreakpoint_() {
  23378. var className = this.currentBreakpointClass();
  23379. this.breakpoint_ = '';
  23380. if (className) {
  23381. this.removeClass(className);
  23382. }
  23383. }
  23384. /**
  23385. * Get or set breakpoints on the player.
  23386. *
  23387. * Calling this method with an object or `true` will remove any previous
  23388. * custom breakpoints and start from the defaults again.
  23389. *
  23390. * @param {Object|boolean} [breakpoints]
  23391. * If an object is given, it can be used to provide custom
  23392. * breakpoints. If `true` is given, will set default breakpoints.
  23393. * If this argument is not given, will simply return the current
  23394. * breakpoints.
  23395. *
  23396. * @param {number} [breakpoints.tiny]
  23397. * The maximum width for the "vjs-layout-tiny" class.
  23398. *
  23399. * @param {number} [breakpoints.xsmall]
  23400. * The maximum width for the "vjs-layout-x-small" class.
  23401. *
  23402. * @param {number} [breakpoints.small]
  23403. * The maximum width for the "vjs-layout-small" class.
  23404. *
  23405. * @param {number} [breakpoints.medium]
  23406. * The maximum width for the "vjs-layout-medium" class.
  23407. *
  23408. * @param {number} [breakpoints.large]
  23409. * The maximum width for the "vjs-layout-large" class.
  23410. *
  23411. * @param {number} [breakpoints.xlarge]
  23412. * The maximum width for the "vjs-layout-x-large" class.
  23413. *
  23414. * @param {number} [breakpoints.huge]
  23415. * The maximum width for the "vjs-layout-huge" class.
  23416. *
  23417. * @return {Object}
  23418. * An object mapping breakpoint names to maximum width values.
  23419. */
  23420. ;
  23421. _proto.breakpoints = function breakpoints(_breakpoints) {
  23422. // Used as a getter.
  23423. if (_breakpoints === undefined) {
  23424. return assign(this.breakpoints_);
  23425. }
  23426. this.breakpoint_ = '';
  23427. this.breakpoints_ = assign({}, DEFAULT_BREAKPOINTS, _breakpoints); // When breakpoint definitions change, we need to update the currently
  23428. // selected breakpoint.
  23429. this.updateCurrentBreakpoint_(); // Clone the breakpoints before returning.
  23430. return assign(this.breakpoints_);
  23431. }
  23432. /**
  23433. * Get or set a flag indicating whether or not this player should adjust
  23434. * its UI based on its dimensions.
  23435. *
  23436. * @param {boolean} value
  23437. * Should be `true` if the player should adjust its UI based on its
  23438. * dimensions; otherwise, should be `false`.
  23439. *
  23440. * @return {boolean}
  23441. * Will be `true` if this player should adjust its UI based on its
  23442. * dimensions; otherwise, will be `false`.
  23443. */
  23444. ;
  23445. _proto.responsive = function responsive(value) {
  23446. // Used as a getter.
  23447. if (value === undefined) {
  23448. return this.responsive_;
  23449. }
  23450. value = Boolean(value);
  23451. var current = this.responsive_; // Nothing changed.
  23452. if (value === current) {
  23453. return;
  23454. } // The value actually changed, set it.
  23455. this.responsive_ = value; // Start listening for breakpoints and set the initial breakpoint if the
  23456. // player is now responsive.
  23457. if (value) {
  23458. this.on('playerresize', this.boundUpdateCurrentBreakpoint_);
  23459. this.updateCurrentBreakpoint_(); // Stop listening for breakpoints if the player is no longer responsive.
  23460. } else {
  23461. this.off('playerresize', this.boundUpdateCurrentBreakpoint_);
  23462. this.removeCurrentBreakpoint_();
  23463. }
  23464. return value;
  23465. }
  23466. /**
  23467. * Get current breakpoint name, if any.
  23468. *
  23469. * @return {string}
  23470. * If there is currently a breakpoint set, returns a the key from the
  23471. * breakpoints object matching it. Otherwise, returns an empty string.
  23472. */
  23473. ;
  23474. _proto.currentBreakpoint = function currentBreakpoint() {
  23475. return this.breakpoint_;
  23476. }
  23477. /**
  23478. * Get the current breakpoint class name.
  23479. *
  23480. * @return {string}
  23481. * The matching class name (e.g. `"vjs-layout-tiny"` or
  23482. * `"vjs-layout-large"`) for the current breakpoint. Empty string if
  23483. * there is no current breakpoint.
  23484. */
  23485. ;
  23486. _proto.currentBreakpointClass = function currentBreakpointClass() {
  23487. return BREAKPOINT_CLASSES[this.breakpoint_] || '';
  23488. }
  23489. /**
  23490. * An object that describes a single piece of media.
  23491. *
  23492. * Properties that are not part of this type description will be retained; so,
  23493. * this can be viewed as a generic metadata storage mechanism as well.
  23494. *
  23495. * @see {@link https://wicg.github.io/mediasession/#the-mediametadata-interface}
  23496. * @typedef {Object} Player~MediaObject
  23497. *
  23498. * @property {string} [album]
  23499. * Unused, except if this object is passed to the `MediaSession`
  23500. * API.
  23501. *
  23502. * @property {string} [artist]
  23503. * Unused, except if this object is passed to the `MediaSession`
  23504. * API.
  23505. *
  23506. * @property {Object[]} [artwork]
  23507. * Unused, except if this object is passed to the `MediaSession`
  23508. * API. If not specified, will be populated via the `poster`, if
  23509. * available.
  23510. *
  23511. * @property {string} [poster]
  23512. * URL to an image that will display before playback.
  23513. *
  23514. * @property {Tech~SourceObject|Tech~SourceObject[]|string} [src]
  23515. * A single source object, an array of source objects, or a string
  23516. * referencing a URL to a media source. It is _highly recommended_
  23517. * that an object or array of objects is used here, so that source
  23518. * selection algorithms can take the `type` into account.
  23519. *
  23520. * @property {string} [title]
  23521. * Unused, except if this object is passed to the `MediaSession`
  23522. * API.
  23523. *
  23524. * @property {Object[]} [textTracks]
  23525. * An array of objects to be used to create text tracks, following
  23526. * the {@link https://www.w3.org/TR/html50/embedded-content-0.html#the-track-element|native track element format}.
  23527. * For ease of removal, these will be created as "remote" text
  23528. * tracks and set to automatically clean up on source changes.
  23529. *
  23530. * These objects may have properties like `src`, `kind`, `label`,
  23531. * and `language`, see {@link Tech#createRemoteTextTrack}.
  23532. */
  23533. /**
  23534. * Populate the player using a {@link Player~MediaObject|MediaObject}.
  23535. *
  23536. * @param {Player~MediaObject} media
  23537. * A media object.
  23538. *
  23539. * @param {Function} ready
  23540. * A callback to be called when the player is ready.
  23541. */
  23542. ;
  23543. _proto.loadMedia = function loadMedia(media, ready) {
  23544. var _this23 = this;
  23545. if (!media || typeof media !== 'object') {
  23546. return;
  23547. }
  23548. this.reset(); // Clone the media object so it cannot be mutated from outside.
  23549. this.cache_.media = mergeOptions(media);
  23550. var _this$cache_$media = this.cache_.media,
  23551. artwork = _this$cache_$media.artwork,
  23552. poster = _this$cache_$media.poster,
  23553. src = _this$cache_$media.src,
  23554. textTracks = _this$cache_$media.textTracks; // If `artwork` is not given, create it using `poster`.
  23555. if (!artwork && poster) {
  23556. this.cache_.media.artwork = [{
  23557. src: poster,
  23558. type: getMimetype(poster)
  23559. }];
  23560. }
  23561. if (src) {
  23562. this.src(src);
  23563. }
  23564. if (poster) {
  23565. this.poster(poster);
  23566. }
  23567. if (Array.isArray(textTracks)) {
  23568. textTracks.forEach(function (tt) {
  23569. return _this23.addRemoteTextTrack(tt, false);
  23570. });
  23571. }
  23572. this.ready(ready);
  23573. }
  23574. /**
  23575. * Get a clone of the current {@link Player~MediaObject} for this player.
  23576. *
  23577. * If the `loadMedia` method has not been used, will attempt to return a
  23578. * {@link Player~MediaObject} based on the current state of the player.
  23579. *
  23580. * @return {Player~MediaObject}
  23581. */
  23582. ;
  23583. _proto.getMedia = function getMedia() {
  23584. if (!this.cache_.media) {
  23585. var poster = this.poster();
  23586. var src = this.currentSources();
  23587. var textTracks = Array.prototype.map.call(this.remoteTextTracks(), function (tt) {
  23588. return {
  23589. kind: tt.kind,
  23590. label: tt.label,
  23591. language: tt.language,
  23592. src: tt.src
  23593. };
  23594. });
  23595. var media = {
  23596. src: src,
  23597. textTracks: textTracks
  23598. };
  23599. if (poster) {
  23600. media.poster = poster;
  23601. media.artwork = [{
  23602. src: media.poster,
  23603. type: getMimetype(media.poster)
  23604. }];
  23605. }
  23606. return media;
  23607. }
  23608. return mergeOptions(this.cache_.media);
  23609. }
  23610. /**
  23611. * Gets tag settings
  23612. *
  23613. * @param {Element} tag
  23614. * The player tag
  23615. *
  23616. * @return {Object}
  23617. * An object containing all of the settings
  23618. * for a player tag
  23619. */
  23620. ;
  23621. Player.getTagSettings = function getTagSettings(tag) {
  23622. var baseOptions = {
  23623. sources: [],
  23624. tracks: []
  23625. };
  23626. var tagOptions = getAttributes(tag);
  23627. var dataSetup = tagOptions['data-setup'];
  23628. if (hasClass(tag, 'vjs-fill')) {
  23629. tagOptions.fill = true;
  23630. }
  23631. if (hasClass(tag, 'vjs-fluid')) {
  23632. tagOptions.fluid = true;
  23633. } // Check if data-setup attr exists.
  23634. if (dataSetup !== null) {
  23635. // Parse options JSON
  23636. // If empty string, make it a parsable json object.
  23637. var _safeParseTuple = tuple(dataSetup || '{}'),
  23638. err = _safeParseTuple[0],
  23639. data = _safeParseTuple[1];
  23640. if (err) {
  23641. log.error(err);
  23642. }
  23643. assign(tagOptions, data);
  23644. }
  23645. assign(baseOptions, tagOptions); // Get tag children settings
  23646. if (tag.hasChildNodes()) {
  23647. var children = tag.childNodes;
  23648. for (var i = 0, j = children.length; i < j; i++) {
  23649. var child = children[i]; // Change case needed: http://ejohn.org/blog/nodename-case-sensitivity/
  23650. var childName = child.nodeName.toLowerCase();
  23651. if (childName === 'source') {
  23652. baseOptions.sources.push(getAttributes(child));
  23653. } else if (childName === 'track') {
  23654. baseOptions.tracks.push(getAttributes(child));
  23655. }
  23656. }
  23657. }
  23658. return baseOptions;
  23659. }
  23660. /**
  23661. * Determine whether or not flexbox is supported
  23662. *
  23663. * @return {boolean}
  23664. * - true if flexbox is supported
  23665. * - false if flexbox is not supported
  23666. */
  23667. ;
  23668. _proto.flexNotSupported_ = function flexNotSupported_() {
  23669. var elem = document.createElement('i'); // Note: We don't actually use flexBasis (or flexOrder), but it's one of the more
  23670. // common flex features that we can rely on when checking for flex support.
  23671. return !('flexBasis' in elem.style || 'webkitFlexBasis' in elem.style || 'mozFlexBasis' in elem.style || 'msFlexBasis' in elem.style || // IE10-specific (2012 flex spec), available for completeness
  23672. 'msFlexOrder' in elem.style);
  23673. }
  23674. /**
  23675. * Set debug mode to enable/disable logs at info level.
  23676. *
  23677. * @param {boolean} enabled
  23678. * @fires Player#debugon
  23679. * @fires Player#debugoff
  23680. */
  23681. ;
  23682. _proto.debug = function debug(enabled) {
  23683. if (enabled === undefined) {
  23684. return this.debugEnabled_;
  23685. }
  23686. if (enabled) {
  23687. this.trigger('debugon');
  23688. this.previousLogLevel_ = this.log.level;
  23689. this.log.level('debug');
  23690. this.debugEnabled_ = true;
  23691. } else {
  23692. this.trigger('debugoff');
  23693. this.log.level(this.previousLogLevel_);
  23694. this.previousLogLevel_ = undefined;
  23695. this.debugEnabled_ = false;
  23696. }
  23697. }
  23698. /**
  23699. * Set or get current playback rates.
  23700. * Takes an array and updates the playback rates menu with the new items.
  23701. * Pass in an empty array to hide the menu.
  23702. * Values other than arrays are ignored.
  23703. *
  23704. * @fires Player#playbackrateschange
  23705. * @param {number[]} newRates
  23706. * The new rates that the playback rates menu should update to.
  23707. * An empty array will hide the menu
  23708. * @return {number[]} When used as a getter will return the current playback rates
  23709. */
  23710. ;
  23711. _proto.playbackRates = function playbackRates(newRates) {
  23712. if (newRates === undefined) {
  23713. return this.cache_.playbackRates;
  23714. } // ignore any value that isn't an array
  23715. if (!Array.isArray(newRates)) {
  23716. return;
  23717. } // ignore any arrays that don't only contain numbers
  23718. if (!newRates.every(function (rate) {
  23719. return typeof rate === 'number';
  23720. })) {
  23721. return;
  23722. }
  23723. this.cache_.playbackRates = newRates;
  23724. /**
  23725. * fires when the playback rates in a player are changed
  23726. *
  23727. * @event Player#playbackrateschange
  23728. * @type {EventTarget~Event}
  23729. */
  23730. this.trigger('playbackrateschange');
  23731. };
  23732. return Player;
  23733. }(Component);
  23734. /**
  23735. * Get the {@link VideoTrackList}
  23736. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist
  23737. *
  23738. * @return {VideoTrackList}
  23739. * the current video track list
  23740. *
  23741. * @method Player.prototype.videoTracks
  23742. */
  23743. /**
  23744. * Get the {@link AudioTrackList}
  23745. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist
  23746. *
  23747. * @return {AudioTrackList}
  23748. * the current audio track list
  23749. *
  23750. * @method Player.prototype.audioTracks
  23751. */
  23752. /**
  23753. * Get the {@link TextTrackList}
  23754. *
  23755. * @link http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-texttracks
  23756. *
  23757. * @return {TextTrackList}
  23758. * the current text track list
  23759. *
  23760. * @method Player.prototype.textTracks
  23761. */
  23762. /**
  23763. * Get the remote {@link TextTrackList}
  23764. *
  23765. * @return {TextTrackList}
  23766. * The current remote text track list
  23767. *
  23768. * @method Player.prototype.remoteTextTracks
  23769. */
  23770. /**
  23771. * Get the remote {@link HtmlTrackElementList} tracks.
  23772. *
  23773. * @return {HtmlTrackElementList}
  23774. * The current remote text track element list
  23775. *
  23776. * @method Player.prototype.remoteTextTrackEls
  23777. */
  23778. ALL.names.forEach(function (name) {
  23779. var props = ALL[name];
  23780. Player.prototype[props.getterName] = function () {
  23781. if (this.tech_) {
  23782. return this.tech_[props.getterName]();
  23783. } // if we have not yet loadTech_, we create {video,audio,text}Tracks_
  23784. // these will be passed to the tech during loading
  23785. this[props.privateName] = this[props.privateName] || new props.ListClass();
  23786. return this[props.privateName];
  23787. };
  23788. });
  23789. /**
  23790. * Get or set the `Player`'s crossorigin option. For the HTML5 player, this
  23791. * sets the `crossOrigin` property on the `<video>` tag to control the CORS
  23792. * behavior.
  23793. *
  23794. * @see [Video Element Attributes]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin}
  23795. *
  23796. * @param {string} [value]
  23797. * The value to set the `Player`'s crossorigin to. If an argument is
  23798. * given, must be one of `anonymous` or `use-credentials`.
  23799. *
  23800. * @return {string|undefined}
  23801. * - The current crossorigin value of the `Player` when getting.
  23802. * - undefined when setting
  23803. */
  23804. Player.prototype.crossorigin = Player.prototype.crossOrigin;
  23805. /**
  23806. * Global enumeration of players.
  23807. *
  23808. * The keys are the player IDs and the values are either the {@link Player}
  23809. * instance or `null` for disposed players.
  23810. *
  23811. * @type {Object}
  23812. */
  23813. Player.players = {};
  23814. var navigator = window.navigator;
  23815. /*
  23816. * Player instance options, surfaced using options
  23817. * options = Player.prototype.options_
  23818. * Make changes in options, not here.
  23819. *
  23820. * @type {Object}
  23821. * @private
  23822. */
  23823. Player.prototype.options_ = {
  23824. // Default order of fallback technology
  23825. techOrder: Tech.defaultTechOrder_,
  23826. html5: {},
  23827. // default inactivity timeout
  23828. inactivityTimeout: 2000,
  23829. // default playback rates
  23830. playbackRates: [],
  23831. // Add playback rate selection by adding rates
  23832. // 'playbackRates': [0.5, 1, 1.5, 2],
  23833. liveui: false,
  23834. // Included control sets
  23835. children: ['mediaLoader', 'posterImage', 'textTrackDisplay', 'loadingSpinner', 'bigPlayButton', 'liveTracker', 'controlBar', 'errorDisplay', 'textTrackSettings', 'resizeManager'],
  23836. language: navigator && (navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language) || 'en',
  23837. // locales and their language translations
  23838. languages: {},
  23839. // Default message to show when a video cannot be played.
  23840. notSupportedMessage: 'No compatible source was found for this media.',
  23841. normalizeAutoplay: false,
  23842. fullscreen: {
  23843. options: {
  23844. navigationUI: 'hide'
  23845. }
  23846. },
  23847. breakpoints: {},
  23848. responsive: false,
  23849. audioOnlyMode: false,
  23850. audioPosterMode: false
  23851. };
  23852. [
  23853. /**
  23854. * Returns whether or not the player is in the "ended" state.
  23855. *
  23856. * @return {Boolean} True if the player is in the ended state, false if not.
  23857. * @method Player#ended
  23858. */
  23859. 'ended',
  23860. /**
  23861. * Returns whether or not the player is in the "seeking" state.
  23862. *
  23863. * @return {Boolean} True if the player is in the seeking state, false if not.
  23864. * @method Player#seeking
  23865. */
  23866. 'seeking',
  23867. /**
  23868. * Returns the TimeRanges of the media that are currently available
  23869. * for seeking to.
  23870. *
  23871. * @return {TimeRanges} the seekable intervals of the media timeline
  23872. * @method Player#seekable
  23873. */
  23874. 'seekable',
  23875. /**
  23876. * Returns the current state of network activity for the element, from
  23877. * the codes in the list below.
  23878. * - NETWORK_EMPTY (numeric value 0)
  23879. * The element has not yet been initialised. All attributes are in
  23880. * their initial states.
  23881. * - NETWORK_IDLE (numeric value 1)
  23882. * The element's resource selection algorithm is active and has
  23883. * selected a resource, but it is not actually using the network at
  23884. * this time.
  23885. * - NETWORK_LOADING (numeric value 2)
  23886. * The user agent is actively trying to download data.
  23887. * - NETWORK_NO_SOURCE (numeric value 3)
  23888. * The element's resource selection algorithm is active, but it has
  23889. * not yet found a resource to use.
  23890. *
  23891. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
  23892. * @return {number} the current network activity state
  23893. * @method Player#networkState
  23894. */
  23895. 'networkState',
  23896. /**
  23897. * Returns a value that expresses the current state of the element
  23898. * with respect to rendering the current playback position, from the
  23899. * codes in the list below.
  23900. * - HAVE_NOTHING (numeric value 0)
  23901. * No information regarding the media resource is available.
  23902. * - HAVE_METADATA (numeric value 1)
  23903. * Enough of the resource has been obtained that the duration of the
  23904. * resource is available.
  23905. * - HAVE_CURRENT_DATA (numeric value 2)
  23906. * Data for the immediate current playback position is available.
  23907. * - HAVE_FUTURE_DATA (numeric value 3)
  23908. * Data for the immediate current playback position is available, as
  23909. * well as enough data for the user agent to advance the current
  23910. * playback position in the direction of playback.
  23911. * - HAVE_ENOUGH_DATA (numeric value 4)
  23912. * The user agent estimates that enough data is available for
  23913. * playback to proceed uninterrupted.
  23914. *
  23915. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
  23916. * @return {number} the current playback rendering state
  23917. * @method Player#readyState
  23918. */
  23919. 'readyState'].forEach(function (fn) {
  23920. Player.prototype[fn] = function () {
  23921. return this.techGet_(fn);
  23922. };
  23923. });
  23924. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  23925. Player.prototype["handleTech" + toTitleCase(event) + "_"] = function () {
  23926. return this.trigger(event);
  23927. };
  23928. });
  23929. /**
  23930. * Fired when the player has initial duration and dimension information
  23931. *
  23932. * @event Player#loadedmetadata
  23933. * @type {EventTarget~Event}
  23934. */
  23935. /**
  23936. * Fired when the player has downloaded data at the current playback position
  23937. *
  23938. * @event Player#loadeddata
  23939. * @type {EventTarget~Event}
  23940. */
  23941. /**
  23942. * Fired when the current playback position has changed *
  23943. * During playback this is fired every 15-250 milliseconds, depending on the
  23944. * playback technology in use.
  23945. *
  23946. * @event Player#timeupdate
  23947. * @type {EventTarget~Event}
  23948. */
  23949. /**
  23950. * Fired when the volume changes
  23951. *
  23952. * @event Player#volumechange
  23953. * @type {EventTarget~Event}
  23954. */
  23955. /**
  23956. * Reports whether or not a player has a plugin available.
  23957. *
  23958. * This does not report whether or not the plugin has ever been initialized
  23959. * on this player. For that, [usingPlugin]{@link Player#usingPlugin}.
  23960. *
  23961. * @method Player#hasPlugin
  23962. * @param {string} name
  23963. * The name of a plugin.
  23964. *
  23965. * @return {boolean}
  23966. * Whether or not this player has the requested plugin available.
  23967. */
  23968. /**
  23969. * Reports whether or not a player is using a plugin by name.
  23970. *
  23971. * For basic plugins, this only reports whether the plugin has _ever_ been
  23972. * initialized on this player.
  23973. *
  23974. * @method Player#usingPlugin
  23975. * @param {string} name
  23976. * The name of a plugin.
  23977. *
  23978. * @return {boolean}
  23979. * Whether or not this player is using the requested plugin.
  23980. */
  23981. Component.registerComponent('Player', Player);
  23982. var setPrototypeOf = createCommonjsModule(function (module) {
  23983. function _setPrototypeOf(o, p) {
  23984. module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  23985. o.__proto__ = p;
  23986. return o;
  23987. };
  23988. return _setPrototypeOf(o, p);
  23989. }
  23990. module.exports = _setPrototypeOf;
  23991. });
  23992. function _isNativeReflectConstruct() {
  23993. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  23994. if (Reflect.construct.sham) return false;
  23995. if (typeof Proxy === "function") return true;
  23996. try {
  23997. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  23998. return true;
  23999. } catch (e) {
  24000. return false;
  24001. }
  24002. }
  24003. var isNativeReflectConstruct = _isNativeReflectConstruct;
  24004. var construct = createCommonjsModule(function (module) {
  24005. function _construct(Parent, args, Class) {
  24006. if (isNativeReflectConstruct()) {
  24007. module.exports = _construct = Reflect.construct;
  24008. } else {
  24009. module.exports = _construct = function _construct(Parent, args, Class) {
  24010. var a = [null];
  24011. a.push.apply(a, args);
  24012. var Constructor = Function.bind.apply(Parent, a);
  24013. var instance = new Constructor();
  24014. if (Class) setPrototypeOf(instance, Class.prototype);
  24015. return instance;
  24016. };
  24017. }
  24018. return _construct.apply(null, arguments);
  24019. }
  24020. module.exports = _construct;
  24021. });
  24022. /**
  24023. * The base plugin name.
  24024. *
  24025. * @private
  24026. * @constant
  24027. * @type {string}
  24028. */
  24029. var BASE_PLUGIN_NAME = 'plugin';
  24030. /**
  24031. * The key on which a player's active plugins cache is stored.
  24032. *
  24033. * @private
  24034. * @constant
  24035. * @type {string}
  24036. */
  24037. var PLUGIN_CACHE_KEY = 'activePlugins_';
  24038. /**
  24039. * Stores registered plugins in a private space.
  24040. *
  24041. * @private
  24042. * @type {Object}
  24043. */
  24044. var pluginStorage = {};
  24045. /**
  24046. * Reports whether or not a plugin has been registered.
  24047. *
  24048. * @private
  24049. * @param {string} name
  24050. * The name of a plugin.
  24051. *
  24052. * @return {boolean}
  24053. * Whether or not the plugin has been registered.
  24054. */
  24055. var pluginExists = function pluginExists(name) {
  24056. return pluginStorage.hasOwnProperty(name);
  24057. };
  24058. /**
  24059. * Get a single registered plugin by name.
  24060. *
  24061. * @private
  24062. * @param {string} name
  24063. * The name of a plugin.
  24064. *
  24065. * @return {Function|undefined}
  24066. * The plugin (or undefined).
  24067. */
  24068. var getPlugin = function getPlugin(name) {
  24069. return pluginExists(name) ? pluginStorage[name] : undefined;
  24070. };
  24071. /**
  24072. * Marks a plugin as "active" on a player.
  24073. *
  24074. * Also, ensures that the player has an object for tracking active plugins.
  24075. *
  24076. * @private
  24077. * @param {Player} player
  24078. * A Video.js player instance.
  24079. *
  24080. * @param {string} name
  24081. * The name of a plugin.
  24082. */
  24083. var markPluginAsActive = function markPluginAsActive(player, name) {
  24084. player[PLUGIN_CACHE_KEY] = player[PLUGIN_CACHE_KEY] || {};
  24085. player[PLUGIN_CACHE_KEY][name] = true;
  24086. };
  24087. /**
  24088. * Triggers a pair of plugin setup events.
  24089. *
  24090. * @private
  24091. * @param {Player} player
  24092. * A Video.js player instance.
  24093. *
  24094. * @param {Plugin~PluginEventHash} hash
  24095. * A plugin event hash.
  24096. *
  24097. * @param {boolean} [before]
  24098. * If true, prefixes the event name with "before". In other words,
  24099. * use this to trigger "beforepluginsetup" instead of "pluginsetup".
  24100. */
  24101. var triggerSetupEvent = function triggerSetupEvent(player, hash, before) {
  24102. var eventName = (before ? 'before' : '') + 'pluginsetup';
  24103. player.trigger(eventName, hash);
  24104. player.trigger(eventName + ':' + hash.name, hash);
  24105. };
  24106. /**
  24107. * Takes a basic plugin function and returns a wrapper function which marks
  24108. * on the player that the plugin has been activated.
  24109. *
  24110. * @private
  24111. * @param {string} name
  24112. * The name of the plugin.
  24113. *
  24114. * @param {Function} plugin
  24115. * The basic plugin.
  24116. *
  24117. * @return {Function}
  24118. * A wrapper function for the given plugin.
  24119. */
  24120. var createBasicPlugin = function createBasicPlugin(name, plugin) {
  24121. var basicPluginWrapper = function basicPluginWrapper() {
  24122. // We trigger the "beforepluginsetup" and "pluginsetup" events on the player
  24123. // regardless, but we want the hash to be consistent with the hash provided
  24124. // for advanced plugins.
  24125. //
  24126. // The only potentially counter-intuitive thing here is the `instance` in
  24127. // the "pluginsetup" event is the value returned by the `plugin` function.
  24128. triggerSetupEvent(this, {
  24129. name: name,
  24130. plugin: plugin,
  24131. instance: null
  24132. }, true);
  24133. var instance = plugin.apply(this, arguments);
  24134. markPluginAsActive(this, name);
  24135. triggerSetupEvent(this, {
  24136. name: name,
  24137. plugin: plugin,
  24138. instance: instance
  24139. });
  24140. return instance;
  24141. };
  24142. Object.keys(plugin).forEach(function (prop) {
  24143. basicPluginWrapper[prop] = plugin[prop];
  24144. });
  24145. return basicPluginWrapper;
  24146. };
  24147. /**
  24148. * Takes a plugin sub-class and returns a factory function for generating
  24149. * instances of it.
  24150. *
  24151. * This factory function will replace itself with an instance of the requested
  24152. * sub-class of Plugin.
  24153. *
  24154. * @private
  24155. * @param {string} name
  24156. * The name of the plugin.
  24157. *
  24158. * @param {Plugin} PluginSubClass
  24159. * The advanced plugin.
  24160. *
  24161. * @return {Function}
  24162. */
  24163. var createPluginFactory = function createPluginFactory(name, PluginSubClass) {
  24164. // Add a `name` property to the plugin prototype so that each plugin can
  24165. // refer to itself by name.
  24166. PluginSubClass.prototype.name = name;
  24167. return function () {
  24168. triggerSetupEvent(this, {
  24169. name: name,
  24170. plugin: PluginSubClass,
  24171. instance: null
  24172. }, true);
  24173. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  24174. args[_key] = arguments[_key];
  24175. }
  24176. var instance = construct(PluginSubClass, [this].concat(args)); // The plugin is replaced by a function that returns the current instance.
  24177. this[name] = function () {
  24178. return instance;
  24179. };
  24180. triggerSetupEvent(this, instance.getEventHash());
  24181. return instance;
  24182. };
  24183. };
  24184. /**
  24185. * Parent class for all advanced plugins.
  24186. *
  24187. * @mixes module:evented~EventedMixin
  24188. * @mixes module:stateful~StatefulMixin
  24189. * @fires Player#beforepluginsetup
  24190. * @fires Player#beforepluginsetup:$name
  24191. * @fires Player#pluginsetup
  24192. * @fires Player#pluginsetup:$name
  24193. * @listens Player#dispose
  24194. * @throws {Error}
  24195. * If attempting to instantiate the base {@link Plugin} class
  24196. * directly instead of via a sub-class.
  24197. */
  24198. var Plugin = /*#__PURE__*/function () {
  24199. /**
  24200. * Creates an instance of this class.
  24201. *
  24202. * Sub-classes should call `super` to ensure plugins are properly initialized.
  24203. *
  24204. * @param {Player} player
  24205. * A Video.js player instance.
  24206. */
  24207. function Plugin(player) {
  24208. if (this.constructor === Plugin) {
  24209. throw new Error('Plugin must be sub-classed; not directly instantiated.');
  24210. }
  24211. this.player = player;
  24212. if (!this.log) {
  24213. this.log = this.player.log.createLogger(this.name);
  24214. } // Make this object evented, but remove the added `trigger` method so we
  24215. // use the prototype version instead.
  24216. evented(this);
  24217. delete this.trigger;
  24218. stateful(this, this.constructor.defaultState);
  24219. markPluginAsActive(player, this.name); // Auto-bind the dispose method so we can use it as a listener and unbind
  24220. // it later easily.
  24221. this.dispose = this.dispose.bind(this); // If the player is disposed, dispose the plugin.
  24222. player.on('dispose', this.dispose);
  24223. }
  24224. /**
  24225. * Get the version of the plugin that was set on <pluginName>.VERSION
  24226. */
  24227. var _proto = Plugin.prototype;
  24228. _proto.version = function version() {
  24229. return this.constructor.VERSION;
  24230. }
  24231. /**
  24232. * Each event triggered by plugins includes a hash of additional data with
  24233. * conventional properties.
  24234. *
  24235. * This returns that object or mutates an existing hash.
  24236. *
  24237. * @param {Object} [hash={}]
  24238. * An object to be used as event an event hash.
  24239. *
  24240. * @return {Plugin~PluginEventHash}
  24241. * An event hash object with provided properties mixed-in.
  24242. */
  24243. ;
  24244. _proto.getEventHash = function getEventHash(hash) {
  24245. if (hash === void 0) {
  24246. hash = {};
  24247. }
  24248. hash.name = this.name;
  24249. hash.plugin = this.constructor;
  24250. hash.instance = this;
  24251. return hash;
  24252. }
  24253. /**
  24254. * Triggers an event on the plugin object and overrides
  24255. * {@link module:evented~EventedMixin.trigger|EventedMixin.trigger}.
  24256. *
  24257. * @param {string|Object} event
  24258. * An event type or an object with a type property.
  24259. *
  24260. * @param {Object} [hash={}]
  24261. * Additional data hash to merge with a
  24262. * {@link Plugin~PluginEventHash|PluginEventHash}.
  24263. *
  24264. * @return {boolean}
  24265. * Whether or not default was prevented.
  24266. */
  24267. ;
  24268. _proto.trigger = function trigger$1(event, hash) {
  24269. if (hash === void 0) {
  24270. hash = {};
  24271. }
  24272. return trigger(this.eventBusEl_, event, this.getEventHash(hash));
  24273. }
  24274. /**
  24275. * Handles "statechanged" events on the plugin. No-op by default, override by
  24276. * subclassing.
  24277. *
  24278. * @abstract
  24279. * @param {Event} e
  24280. * An event object provided by a "statechanged" event.
  24281. *
  24282. * @param {Object} e.changes
  24283. * An object describing changes that occurred with the "statechanged"
  24284. * event.
  24285. */
  24286. ;
  24287. _proto.handleStateChanged = function handleStateChanged(e) {}
  24288. /**
  24289. * Disposes a plugin.
  24290. *
  24291. * Subclasses can override this if they want, but for the sake of safety,
  24292. * it's probably best to subscribe the "dispose" event.
  24293. *
  24294. * @fires Plugin#dispose
  24295. */
  24296. ;
  24297. _proto.dispose = function dispose() {
  24298. var name = this.name,
  24299. player = this.player;
  24300. /**
  24301. * Signals that a advanced plugin is about to be disposed.
  24302. *
  24303. * @event Plugin#dispose
  24304. * @type {EventTarget~Event}
  24305. */
  24306. this.trigger('dispose');
  24307. this.off();
  24308. player.off('dispose', this.dispose); // Eliminate any possible sources of leaking memory by clearing up
  24309. // references between the player and the plugin instance and nulling out
  24310. // the plugin's state and replacing methods with a function that throws.
  24311. player[PLUGIN_CACHE_KEY][name] = false;
  24312. this.player = this.state = null; // Finally, replace the plugin name on the player with a new factory
  24313. // function, so that the plugin is ready to be set up again.
  24314. player[name] = createPluginFactory(name, pluginStorage[name]);
  24315. }
  24316. /**
  24317. * Determines if a plugin is a basic plugin (i.e. not a sub-class of `Plugin`).
  24318. *
  24319. * @param {string|Function} plugin
  24320. * If a string, matches the name of a plugin. If a function, will be
  24321. * tested directly.
  24322. *
  24323. * @return {boolean}
  24324. * Whether or not a plugin is a basic plugin.
  24325. */
  24326. ;
  24327. Plugin.isBasic = function isBasic(plugin) {
  24328. var p = typeof plugin === 'string' ? getPlugin(plugin) : plugin;
  24329. return typeof p === 'function' && !Plugin.prototype.isPrototypeOf(p.prototype);
  24330. }
  24331. /**
  24332. * Register a Video.js plugin.
  24333. *
  24334. * @param {string} name
  24335. * The name of the plugin to be registered. Must be a string and
  24336. * must not match an existing plugin or a method on the `Player`
  24337. * prototype.
  24338. *
  24339. * @param {Function} plugin
  24340. * A sub-class of `Plugin` or a function for basic plugins.
  24341. *
  24342. * @return {Function}
  24343. * For advanced plugins, a factory function for that plugin. For
  24344. * basic plugins, a wrapper function that initializes the plugin.
  24345. */
  24346. ;
  24347. Plugin.registerPlugin = function registerPlugin(name, plugin) {
  24348. if (typeof name !== 'string') {
  24349. throw new Error("Illegal plugin name, \"" + name + "\", must be a string, was " + typeof name + ".");
  24350. }
  24351. if (pluginExists(name)) {
  24352. log.warn("A plugin named \"" + name + "\" already exists. You may want to avoid re-registering plugins!");
  24353. } else if (Player.prototype.hasOwnProperty(name)) {
  24354. throw new Error("Illegal plugin name, \"" + name + "\", cannot share a name with an existing player method!");
  24355. }
  24356. if (typeof plugin !== 'function') {
  24357. throw new Error("Illegal plugin for \"" + name + "\", must be a function, was " + typeof plugin + ".");
  24358. }
  24359. pluginStorage[name] = plugin; // Add a player prototype method for all sub-classed plugins (but not for
  24360. // the base Plugin class).
  24361. if (name !== BASE_PLUGIN_NAME) {
  24362. if (Plugin.isBasic(plugin)) {
  24363. Player.prototype[name] = createBasicPlugin(name, plugin);
  24364. } else {
  24365. Player.prototype[name] = createPluginFactory(name, plugin);
  24366. }
  24367. }
  24368. return plugin;
  24369. }
  24370. /**
  24371. * De-register a Video.js plugin.
  24372. *
  24373. * @param {string} name
  24374. * The name of the plugin to be de-registered. Must be a string that
  24375. * matches an existing plugin.
  24376. *
  24377. * @throws {Error}
  24378. * If an attempt is made to de-register the base plugin.
  24379. */
  24380. ;
  24381. Plugin.deregisterPlugin = function deregisterPlugin(name) {
  24382. if (name === BASE_PLUGIN_NAME) {
  24383. throw new Error('Cannot de-register base plugin.');
  24384. }
  24385. if (pluginExists(name)) {
  24386. delete pluginStorage[name];
  24387. delete Player.prototype[name];
  24388. }
  24389. }
  24390. /**
  24391. * Gets an object containing multiple Video.js plugins.
  24392. *
  24393. * @param {Array} [names]
  24394. * If provided, should be an array of plugin names. Defaults to _all_
  24395. * plugin names.
  24396. *
  24397. * @return {Object|undefined}
  24398. * An object containing plugin(s) associated with their name(s) or
  24399. * `undefined` if no matching plugins exist).
  24400. */
  24401. ;
  24402. Plugin.getPlugins = function getPlugins(names) {
  24403. if (names === void 0) {
  24404. names = Object.keys(pluginStorage);
  24405. }
  24406. var result;
  24407. names.forEach(function (name) {
  24408. var plugin = getPlugin(name);
  24409. if (plugin) {
  24410. result = result || {};
  24411. result[name] = plugin;
  24412. }
  24413. });
  24414. return result;
  24415. }
  24416. /**
  24417. * Gets a plugin's version, if available
  24418. *
  24419. * @param {string} name
  24420. * The name of a plugin.
  24421. *
  24422. * @return {string}
  24423. * The plugin's version or an empty string.
  24424. */
  24425. ;
  24426. Plugin.getPluginVersion = function getPluginVersion(name) {
  24427. var plugin = getPlugin(name);
  24428. return plugin && plugin.VERSION || '';
  24429. };
  24430. return Plugin;
  24431. }();
  24432. /**
  24433. * Gets a plugin by name if it exists.
  24434. *
  24435. * @static
  24436. * @method getPlugin
  24437. * @memberOf Plugin
  24438. * @param {string} name
  24439. * The name of a plugin.
  24440. *
  24441. * @returns {Function|undefined}
  24442. * The plugin (or `undefined`).
  24443. */
  24444. Plugin.getPlugin = getPlugin;
  24445. /**
  24446. * The name of the base plugin class as it is registered.
  24447. *
  24448. * @type {string}
  24449. */
  24450. Plugin.BASE_PLUGIN_NAME = BASE_PLUGIN_NAME;
  24451. Plugin.registerPlugin(BASE_PLUGIN_NAME, Plugin);
  24452. /**
  24453. * Documented in player.js
  24454. *
  24455. * @ignore
  24456. */
  24457. Player.prototype.usingPlugin = function (name) {
  24458. return !!this[PLUGIN_CACHE_KEY] && this[PLUGIN_CACHE_KEY][name] === true;
  24459. };
  24460. /**
  24461. * Documented in player.js
  24462. *
  24463. * @ignore
  24464. */
  24465. Player.prototype.hasPlugin = function (name) {
  24466. return !!pluginExists(name);
  24467. };
  24468. /**
  24469. * Signals that a plugin is about to be set up on a player.
  24470. *
  24471. * @event Player#beforepluginsetup
  24472. * @type {Plugin~PluginEventHash}
  24473. */
  24474. /**
  24475. * Signals that a plugin is about to be set up on a player - by name. The name
  24476. * is the name of the plugin.
  24477. *
  24478. * @event Player#beforepluginsetup:$name
  24479. * @type {Plugin~PluginEventHash}
  24480. */
  24481. /**
  24482. * Signals that a plugin has just been set up on a player.
  24483. *
  24484. * @event Player#pluginsetup
  24485. * @type {Plugin~PluginEventHash}
  24486. */
  24487. /**
  24488. * Signals that a plugin has just been set up on a player - by name. The name
  24489. * is the name of the plugin.
  24490. *
  24491. * @event Player#pluginsetup:$name
  24492. * @type {Plugin~PluginEventHash}
  24493. */
  24494. /**
  24495. * @typedef {Object} Plugin~PluginEventHash
  24496. *
  24497. * @property {string} instance
  24498. * For basic plugins, the return value of the plugin function. For
  24499. * advanced plugins, the plugin instance on which the event is fired.
  24500. *
  24501. * @property {string} name
  24502. * The name of the plugin.
  24503. *
  24504. * @property {string} plugin
  24505. * For basic plugins, the plugin function. For advanced plugins, the
  24506. * plugin class/constructor.
  24507. */
  24508. function _inherits(subClass, superClass) {
  24509. if (typeof superClass !== "function" && superClass !== null) {
  24510. throw new TypeError("Super expression must either be null or a function");
  24511. }
  24512. subClass.prototype = Object.create(superClass && superClass.prototype, {
  24513. constructor: {
  24514. value: subClass,
  24515. writable: true,
  24516. configurable: true
  24517. }
  24518. });
  24519. if (superClass) setPrototypeOf(subClass, superClass);
  24520. }
  24521. var inherits = _inherits;
  24522. /**
  24523. * @file extend.js
  24524. * @module extend
  24525. */
  24526. var hasLogged = false;
  24527. /**
  24528. * Used to subclass an existing class by emulating ES subclassing using the
  24529. * `extends` keyword.
  24530. *
  24531. * @function
  24532. * @deprecated
  24533. * @example
  24534. * var MyComponent = videojs.extend(videojs.getComponent('Component'), {
  24535. * myCustomMethod: function() {
  24536. * // Do things in my method.
  24537. * }
  24538. * });
  24539. *
  24540. * @param {Function} superClass
  24541. * The class to inherit from
  24542. *
  24543. * @param {Object} [subClassMethods={}]
  24544. * Methods of the new class
  24545. *
  24546. * @return {Function}
  24547. * The new class with subClassMethods that inherited superClass.
  24548. */
  24549. var extend = function extend(superClass, subClassMethods) {
  24550. if (subClassMethods === void 0) {
  24551. subClassMethods = {};
  24552. }
  24553. // Log a warning the first time extend is called to note that it is deprecated
  24554. // It was previously deprecated in our documentation (guides, specifically),
  24555. // but was never formally deprecated in code.
  24556. if (!hasLogged) {
  24557. log.warn('videojs.extend is deprecated as of Video.js 7.22.0 and will be removed in Video.js 8.0.0');
  24558. hasLogged = true;
  24559. }
  24560. var subClass = function subClass() {
  24561. superClass.apply(this, arguments);
  24562. };
  24563. var methods = {};
  24564. if (typeof subClassMethods === 'object') {
  24565. if (subClassMethods.constructor !== Object.prototype.constructor) {
  24566. subClass = subClassMethods.constructor;
  24567. }
  24568. methods = subClassMethods;
  24569. } else if (typeof subClassMethods === 'function') {
  24570. subClass = subClassMethods;
  24571. }
  24572. inherits(subClass, superClass); // this is needed for backward-compatibility and node compatibility.
  24573. if (superClass) {
  24574. subClass.super_ = superClass;
  24575. } // Extend subObj's prototype with functions and other properties from props
  24576. for (var name in methods) {
  24577. if (methods.hasOwnProperty(name)) {
  24578. subClass.prototype[name] = methods[name];
  24579. }
  24580. }
  24581. return subClass;
  24582. };
  24583. /**
  24584. * @file video.js
  24585. * @module videojs
  24586. */
  24587. /**
  24588. * Normalize an `id` value by trimming off a leading `#`
  24589. *
  24590. * @private
  24591. * @param {string} id
  24592. * A string, maybe with a leading `#`.
  24593. *
  24594. * @return {string}
  24595. * The string, without any leading `#`.
  24596. */
  24597. var normalizeId = function normalizeId(id) {
  24598. return id.indexOf('#') === 0 ? id.slice(1) : id;
  24599. };
  24600. /**
  24601. * The `videojs()` function doubles as the main function for users to create a
  24602. * {@link Player} instance as well as the main library namespace.
  24603. *
  24604. * It can also be used as a getter for a pre-existing {@link Player} instance.
  24605. * However, we _strongly_ recommend using `videojs.getPlayer()` for this
  24606. * purpose because it avoids any potential for unintended initialization.
  24607. *
  24608. * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149)
  24609. * of our JSDoc template, we cannot properly document this as both a function
  24610. * and a namespace, so its function signature is documented here.
  24611. *
  24612. * #### Arguments
  24613. * ##### id
  24614. * string|Element, **required**
  24615. *
  24616. * Video element or video element ID.
  24617. *
  24618. * ##### options
  24619. * Object, optional
  24620. *
  24621. * Options object for providing settings.
  24622. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  24623. *
  24624. * ##### ready
  24625. * {@link Component~ReadyCallback}, optional
  24626. *
  24627. * A function to be called when the {@link Player} and {@link Tech} are ready.
  24628. *
  24629. * #### Return Value
  24630. *
  24631. * The `videojs()` function returns a {@link Player} instance.
  24632. *
  24633. * @namespace
  24634. *
  24635. * @borrows AudioTrack as AudioTrack
  24636. * @borrows Component.getComponent as getComponent
  24637. * @borrows module:computed-style~computedStyle as computedStyle
  24638. * @borrows module:events.on as on
  24639. * @borrows module:events.one as one
  24640. * @borrows module:events.off as off
  24641. * @borrows module:events.trigger as trigger
  24642. * @borrows EventTarget as EventTarget
  24643. * @borrows module:extend~extend as extend
  24644. * @borrows module:fn.bind as bind
  24645. * @borrows module:format-time.formatTime as formatTime
  24646. * @borrows module:format-time.resetFormatTime as resetFormatTime
  24647. * @borrows module:format-time.setFormatTime as setFormatTime
  24648. * @borrows module:merge-options.mergeOptions as mergeOptions
  24649. * @borrows module:middleware.use as use
  24650. * @borrows Player.players as players
  24651. * @borrows Plugin.registerPlugin as registerPlugin
  24652. * @borrows Plugin.deregisterPlugin as deregisterPlugin
  24653. * @borrows Plugin.getPlugins as getPlugins
  24654. * @borrows Plugin.getPlugin as getPlugin
  24655. * @borrows Plugin.getPluginVersion as getPluginVersion
  24656. * @borrows Tech.getTech as getTech
  24657. * @borrows Tech.registerTech as registerTech
  24658. * @borrows TextTrack as TextTrack
  24659. * @borrows module:time-ranges.createTimeRanges as createTimeRange
  24660. * @borrows module:time-ranges.createTimeRanges as createTimeRanges
  24661. * @borrows module:url.isCrossOrigin as isCrossOrigin
  24662. * @borrows module:url.parseUrl as parseUrl
  24663. * @borrows VideoTrack as VideoTrack
  24664. *
  24665. * @param {string|Element} id
  24666. * Video element or video element ID.
  24667. *
  24668. * @param {Object} [options]
  24669. * Options object for providing settings.
  24670. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  24671. *
  24672. * @param {Component~ReadyCallback} [ready]
  24673. * A function to be called when the {@link Player} and {@link Tech} are
  24674. * ready.
  24675. *
  24676. * @return {Player}
  24677. * The `videojs()` function returns a {@link Player|Player} instance.
  24678. */
  24679. function videojs(id, options, ready) {
  24680. var player = videojs.getPlayer(id);
  24681. if (player) {
  24682. if (options) {
  24683. log.warn("Player \"" + id + "\" is already initialised. Options will not be applied.");
  24684. }
  24685. if (ready) {
  24686. player.ready(ready);
  24687. }
  24688. return player;
  24689. }
  24690. var el = typeof id === 'string' ? $('#' + normalizeId(id)) : id;
  24691. if (!isEl(el)) {
  24692. throw new TypeError('The element or ID supplied is not valid. (videojs)');
  24693. } // document.body.contains(el) will only check if el is contained within that one document.
  24694. // This causes problems for elements in iframes.
  24695. // Instead, use the element's ownerDocument instead of the global document.
  24696. // This will make sure that the element is indeed in the dom of that document.
  24697. // Additionally, check that the document in question has a default view.
  24698. // If the document is no longer attached to the dom, the defaultView of the document will be null.
  24699. if (!el.ownerDocument.defaultView || !el.ownerDocument.body.contains(el)) {
  24700. log.warn('The element supplied is not included in the DOM');
  24701. }
  24702. options = options || {}; // Store a copy of the el before modification, if it is to be restored in destroy()
  24703. // If div ingest, store the parent div
  24704. if (options.restoreEl === true) {
  24705. options.restoreEl = (el.parentNode && el.parentNode.hasAttribute('data-vjs-player') ? el.parentNode : el).cloneNode(true);
  24706. }
  24707. hooks('beforesetup').forEach(function (hookFunction) {
  24708. var opts = hookFunction(el, mergeOptions(options));
  24709. if (!isObject(opts) || Array.isArray(opts)) {
  24710. log.error('please return an object in beforesetup hooks');
  24711. return;
  24712. }
  24713. options = mergeOptions(options, opts);
  24714. }); // We get the current "Player" component here in case an integration has
  24715. // replaced it with a custom player.
  24716. var PlayerComponent = Component.getComponent('Player');
  24717. player = new PlayerComponent(el, options, ready);
  24718. hooks('setup').forEach(function (hookFunction) {
  24719. return hookFunction(player);
  24720. });
  24721. return player;
  24722. }
  24723. videojs.hooks_ = hooks_;
  24724. videojs.hooks = hooks;
  24725. videojs.hook = hook;
  24726. videojs.hookOnce = hookOnce;
  24727. videojs.removeHook = removeHook; // Add default styles
  24728. if (window.VIDEOJS_NO_DYNAMIC_STYLE !== true && isReal()) {
  24729. var style = $('.vjs-styles-defaults');
  24730. if (!style) {
  24731. style = createStyleElement('vjs-styles-defaults');
  24732. var head = $('head');
  24733. if (head) {
  24734. head.insertBefore(style, head.firstChild);
  24735. }
  24736. setTextContent(style, "\n .video-js {\n width: 300px;\n height: 150px;\n }\n\n .vjs-fluid:not(.vjs-audio-only-mode) {\n padding-top: 56.25%\n }\n ");
  24737. }
  24738. } // Run Auto-load players
  24739. // You have to wait at least once in case this script is loaded after your
  24740. // video in the DOM (weird behavior only with minified version)
  24741. autoSetupTimeout(1, videojs);
  24742. /**
  24743. * Current Video.js version. Follows [semantic versioning](https://semver.org/).
  24744. *
  24745. * @type {string}
  24746. */
  24747. videojs.VERSION = version;
  24748. /**
  24749. * The global options object. These are the settings that take effect
  24750. * if no overrides are specified when the player is created.
  24751. *
  24752. * @type {Object}
  24753. */
  24754. videojs.options = Player.prototype.options_;
  24755. /**
  24756. * Get an object with the currently created players, keyed by player ID
  24757. *
  24758. * @return {Object}
  24759. * The created players
  24760. */
  24761. videojs.getPlayers = function () {
  24762. return Player.players;
  24763. };
  24764. /**
  24765. * Get a single player based on an ID or DOM element.
  24766. *
  24767. * This is useful if you want to check if an element or ID has an associated
  24768. * Video.js player, but not create one if it doesn't.
  24769. *
  24770. * @param {string|Element} id
  24771. * An HTML element - `<video>`, `<audio>`, or `<video-js>` -
  24772. * or a string matching the `id` of such an element.
  24773. *
  24774. * @return {Player|undefined}
  24775. * A player instance or `undefined` if there is no player instance
  24776. * matching the argument.
  24777. */
  24778. videojs.getPlayer = function (id) {
  24779. var players = Player.players;
  24780. var tag;
  24781. if (typeof id === 'string') {
  24782. var nId = normalizeId(id);
  24783. var player = players[nId];
  24784. if (player) {
  24785. return player;
  24786. }
  24787. tag = $('#' + nId);
  24788. } else {
  24789. tag = id;
  24790. }
  24791. if (isEl(tag)) {
  24792. var _tag = tag,
  24793. _player = _tag.player,
  24794. playerId = _tag.playerId; // Element may have a `player` property referring to an already created
  24795. // player instance. If so, return that.
  24796. if (_player || players[playerId]) {
  24797. return _player || players[playerId];
  24798. }
  24799. }
  24800. };
  24801. /**
  24802. * Returns an array of all current players.
  24803. *
  24804. * @return {Array}
  24805. * An array of all players. The array will be in the order that
  24806. * `Object.keys` provides, which could potentially vary between
  24807. * JavaScript engines.
  24808. *
  24809. */
  24810. videojs.getAllPlayers = function () {
  24811. return (// Disposed players leave a key with a `null` value, so we need to make sure
  24812. // we filter those out.
  24813. Object.keys(Player.players).map(function (k) {
  24814. return Player.players[k];
  24815. }).filter(Boolean)
  24816. );
  24817. };
  24818. videojs.players = Player.players;
  24819. videojs.getComponent = Component.getComponent;
  24820. /**
  24821. * Register a component so it can referred to by name. Used when adding to other
  24822. * components, either through addChild `component.addChild('myComponent')` or through
  24823. * default children options `{ children: ['myComponent'] }`.
  24824. *
  24825. * > NOTE: You could also just initialize the component before adding.
  24826. * `component.addChild(new MyComponent());`
  24827. *
  24828. * @param {string} name
  24829. * The class name of the component
  24830. *
  24831. * @param {Component} comp
  24832. * The component class
  24833. *
  24834. * @return {Component}
  24835. * The newly registered component
  24836. */
  24837. videojs.registerComponent = function (name, comp) {
  24838. if (Tech.isTech(comp)) {
  24839. log.warn("The " + name + " tech was registered as a component. It should instead be registered using videojs.registerTech(name, tech)");
  24840. }
  24841. Component.registerComponent.call(Component, name, comp);
  24842. };
  24843. videojs.getTech = Tech.getTech;
  24844. videojs.registerTech = Tech.registerTech;
  24845. videojs.use = use;
  24846. /**
  24847. * An object that can be returned by a middleware to signify
  24848. * that the middleware is being terminated.
  24849. *
  24850. * @type {object}
  24851. * @property {object} middleware.TERMINATOR
  24852. */
  24853. Object.defineProperty(videojs, 'middleware', {
  24854. value: {},
  24855. writeable: false,
  24856. enumerable: true
  24857. });
  24858. Object.defineProperty(videojs.middleware, 'TERMINATOR', {
  24859. value: TERMINATOR,
  24860. writeable: false,
  24861. enumerable: true
  24862. });
  24863. /**
  24864. * A reference to the {@link module:browser|browser utility module} as an object.
  24865. *
  24866. * @type {Object}
  24867. * @see {@link module:browser|browser}
  24868. */
  24869. videojs.browser = browser;
  24870. /**
  24871. * Use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED} instead; only
  24872. * included for backward-compatibility with 4.x.
  24873. *
  24874. * @deprecated Since version 5.0, use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED instead.
  24875. * @type {boolean}
  24876. */
  24877. videojs.TOUCH_ENABLED = TOUCH_ENABLED;
  24878. videojs.extend = extend;
  24879. videojs.mergeOptions = mergeOptions;
  24880. videojs.bind = bind;
  24881. videojs.registerPlugin = Plugin.registerPlugin;
  24882. videojs.deregisterPlugin = Plugin.deregisterPlugin;
  24883. /**
  24884. * Deprecated method to register a plugin with Video.js
  24885. *
  24886. * @deprecated videojs.plugin() is deprecated; use videojs.registerPlugin() instead
  24887. *
  24888. * @param {string} name
  24889. * The plugin name
  24890. *
  24891. * @param {Plugin|Function} plugin
  24892. * The plugin sub-class or function
  24893. */
  24894. videojs.plugin = function (name, plugin) {
  24895. log.warn('videojs.plugin() is deprecated; use videojs.registerPlugin() instead');
  24896. return Plugin.registerPlugin(name, plugin);
  24897. };
  24898. videojs.getPlugins = Plugin.getPlugins;
  24899. videojs.getPlugin = Plugin.getPlugin;
  24900. videojs.getPluginVersion = Plugin.getPluginVersion;
  24901. /**
  24902. * Adding languages so that they're available to all players.
  24903. * Example: `videojs.addLanguage('es', { 'Hello': 'Hola' });`
  24904. *
  24905. * @param {string} code
  24906. * The language code or dictionary property
  24907. *
  24908. * @param {Object} data
  24909. * The data values to be translated
  24910. *
  24911. * @return {Object}
  24912. * The resulting language dictionary object
  24913. */
  24914. videojs.addLanguage = function (code, data) {
  24915. var _mergeOptions;
  24916. code = ('' + code).toLowerCase();
  24917. videojs.options.languages = mergeOptions(videojs.options.languages, (_mergeOptions = {}, _mergeOptions[code] = data, _mergeOptions));
  24918. return videojs.options.languages[code];
  24919. };
  24920. /**
  24921. * A reference to the {@link module:log|log utility module} as an object.
  24922. *
  24923. * @type {Function}
  24924. * @see {@link module:log|log}
  24925. */
  24926. videojs.log = log;
  24927. videojs.createLogger = createLogger;
  24928. videojs.createTimeRange = videojs.createTimeRanges = createTimeRanges;
  24929. videojs.formatTime = formatTime;
  24930. videojs.setFormatTime = setFormatTime;
  24931. videojs.resetFormatTime = resetFormatTime;
  24932. videojs.parseUrl = parseUrl;
  24933. videojs.isCrossOrigin = isCrossOrigin;
  24934. videojs.EventTarget = EventTarget;
  24935. videojs.on = on;
  24936. videojs.one = one;
  24937. videojs.off = off;
  24938. videojs.trigger = trigger;
  24939. /**
  24940. * A cross-browser XMLHttpRequest wrapper.
  24941. *
  24942. * @function
  24943. * @param {Object} options
  24944. * Settings for the request.
  24945. *
  24946. * @return {XMLHttpRequest|XDomainRequest}
  24947. * The request object.
  24948. *
  24949. * @see https://github.com/Raynos/xhr
  24950. */
  24951. videojs.xhr = lib;
  24952. videojs.TextTrack = TextTrack;
  24953. videojs.AudioTrack = AudioTrack;
  24954. videojs.VideoTrack = VideoTrack;
  24955. ['isEl', 'isTextNode', 'createEl', 'hasClass', 'addClass', 'removeClass', 'toggleClass', 'setAttributes', 'getAttributes', 'emptyEl', 'appendContent', 'insertContent'].forEach(function (k) {
  24956. videojs[k] = function () {
  24957. log.warn("videojs." + k + "() is deprecated; use videojs.dom." + k + "() instead");
  24958. return Dom[k].apply(null, arguments);
  24959. };
  24960. });
  24961. videojs.computedStyle = computedStyle;
  24962. /**
  24963. * A reference to the {@link module:dom|DOM utility module} as an object.
  24964. *
  24965. * @type {Object}
  24966. * @see {@link module:dom|dom}
  24967. */
  24968. videojs.dom = Dom;
  24969. /**
  24970. * A reference to the {@link module:url|URL utility module} as an object.
  24971. *
  24972. * @type {Object}
  24973. * @see {@link module:url|url}
  24974. */
  24975. videojs.url = Url;
  24976. videojs.defineLazyProperty = defineLazyProperty; // Adding less ambiguous text for fullscreen button.
  24977. // In a major update this could become the default text and key.
  24978. videojs.addLanguage('en', {
  24979. 'Non-Fullscreen': 'Exit Fullscreen'
  24980. });
  24981. return videojs;
  24982. })));