video.core.js 912 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232
  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 minDoc = {};
  7755. var topLevel = typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : typeof window !== 'undefined' ? window : {};
  7756. var doccy;
  7757. if (typeof document !== 'undefined') {
  7758. doccy = document;
  7759. } else {
  7760. doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];
  7761. if (!doccy) {
  7762. doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
  7763. }
  7764. }
  7765. var document_1 = doccy;
  7766. /**
  7767. * Copyright 2013 vtt.js Contributors
  7768. *
  7769. * Licensed under the Apache License, Version 2.0 (the "License");
  7770. * you may not use this file except in compliance with the License.
  7771. * You may obtain a copy of the License at
  7772. *
  7773. * http://www.apache.org/licenses/LICENSE-2.0
  7774. *
  7775. * Unless required by applicable law or agreed to in writing, software
  7776. * distributed under the License is distributed on an "AS IS" BASIS,
  7777. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7778. * See the License for the specific language governing permissions and
  7779. * limitations under the License.
  7780. */
  7781. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  7782. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  7783. var _objCreate = Object.create || function () {
  7784. function F() {}
  7785. return function (o) {
  7786. if (arguments.length !== 1) {
  7787. throw new Error('Object.create shim only accepts one parameter.');
  7788. }
  7789. F.prototype = o;
  7790. return new F();
  7791. };
  7792. }(); // Creates a new ParserError object from an errorData object. The errorData
  7793. // object should have default code and message properties. The default message
  7794. // property can be overriden by passing in a message parameter.
  7795. // See ParsingError.Errors below for acceptable errors.
  7796. function ParsingError(errorData, message) {
  7797. this.name = "ParsingError";
  7798. this.code = errorData.code;
  7799. this.message = message || errorData.message;
  7800. }
  7801. ParsingError.prototype = _objCreate(Error.prototype);
  7802. ParsingError.prototype.constructor = ParsingError; // ParsingError metadata for acceptable ParsingErrors.
  7803. ParsingError.Errors = {
  7804. BadSignature: {
  7805. code: 0,
  7806. message: "Malformed WebVTT signature."
  7807. },
  7808. BadTimeStamp: {
  7809. code: 1,
  7810. message: "Malformed time stamp."
  7811. }
  7812. }; // Try to parse input as a time stamp.
  7813. function parseTimeStamp(input) {
  7814. function computeSeconds(h, m, s, f) {
  7815. return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;
  7816. }
  7817. var m = input.match(/^(\d+):(\d{1,2})(:\d{1,2})?\.(\d{3})/);
  7818. if (!m) {
  7819. return null;
  7820. }
  7821. if (m[3]) {
  7822. // Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
  7823. return computeSeconds(m[1], m[2], m[3].replace(":", ""), m[4]);
  7824. } else if (m[1] > 59) {
  7825. // Timestamp takes the form of [hours]:[minutes].[milliseconds]
  7826. // First position is hours as it's over 59.
  7827. return computeSeconds(m[1], m[2], 0, m[4]);
  7828. } else {
  7829. // Timestamp takes the form of [minutes]:[seconds].[milliseconds]
  7830. return computeSeconds(0, m[1], m[2], m[4]);
  7831. }
  7832. } // A settings object holds key/value pairs and will ignore anything but the first
  7833. // assignment to a specific key.
  7834. function Settings() {
  7835. this.values = _objCreate(null);
  7836. }
  7837. Settings.prototype = {
  7838. // Only accept the first assignment to any key.
  7839. set: function set(k, v) {
  7840. if (!this.get(k) && v !== "") {
  7841. this.values[k] = v;
  7842. }
  7843. },
  7844. // Return the value for a key, or a default value.
  7845. // If 'defaultKey' is passed then 'dflt' is assumed to be an object with
  7846. // a number of possible default values as properties where 'defaultKey' is
  7847. // the key of the property that will be chosen; otherwise it's assumed to be
  7848. // a single value.
  7849. get: function get(k, dflt, defaultKey) {
  7850. if (defaultKey) {
  7851. return this.has(k) ? this.values[k] : dflt[defaultKey];
  7852. }
  7853. return this.has(k) ? this.values[k] : dflt;
  7854. },
  7855. // Check whether we have a value for a key.
  7856. has: function has(k) {
  7857. return k in this.values;
  7858. },
  7859. // Accept a setting if its one of the given alternatives.
  7860. alt: function alt(k, v, a) {
  7861. for (var n = 0; n < a.length; ++n) {
  7862. if (v === a[n]) {
  7863. this.set(k, v);
  7864. break;
  7865. }
  7866. }
  7867. },
  7868. // Accept a setting if its a valid (signed) integer.
  7869. integer: function integer(k, v) {
  7870. if (/^-?\d+$/.test(v)) {
  7871. // integer
  7872. this.set(k, parseInt(v, 10));
  7873. }
  7874. },
  7875. // Accept a setting if its a valid percentage.
  7876. percent: function percent(k, v) {
  7877. if (v.match(/^([\d]{1,3})(\.[\d]*)?%$/)) {
  7878. v = parseFloat(v);
  7879. if (v >= 0 && v <= 100) {
  7880. this.set(k, v);
  7881. return true;
  7882. }
  7883. }
  7884. return false;
  7885. }
  7886. }; // Helper function to parse input into groups separated by 'groupDelim', and
  7887. // interprete each group as a key/value pair separated by 'keyValueDelim'.
  7888. function parseOptions(input, callback, keyValueDelim, groupDelim) {
  7889. var groups = groupDelim ? input.split(groupDelim) : [input];
  7890. for (var i in groups) {
  7891. if (typeof groups[i] !== "string") {
  7892. continue;
  7893. }
  7894. var kv = groups[i].split(keyValueDelim);
  7895. if (kv.length !== 2) {
  7896. continue;
  7897. }
  7898. var k = kv[0].trim();
  7899. var v = kv[1].trim();
  7900. callback(k, v);
  7901. }
  7902. }
  7903. function parseCue(input, cue, regionList) {
  7904. // Remember the original input if we need to throw an error.
  7905. var oInput = input; // 4.1 WebVTT timestamp
  7906. function consumeTimeStamp() {
  7907. var ts = parseTimeStamp(input);
  7908. if (ts === null) {
  7909. throw new ParsingError(ParsingError.Errors.BadTimeStamp, "Malformed timestamp: " + oInput);
  7910. } // Remove time stamp from input.
  7911. input = input.replace(/^[^\sa-zA-Z-]+/, "");
  7912. return ts;
  7913. } // 4.4.2 WebVTT cue settings
  7914. function consumeCueSettings(input, cue) {
  7915. var settings = new Settings();
  7916. parseOptions(input, function (k, v) {
  7917. switch (k) {
  7918. case "region":
  7919. // Find the last region we parsed with the same region id.
  7920. for (var i = regionList.length - 1; i >= 0; i--) {
  7921. if (regionList[i].id === v) {
  7922. settings.set(k, regionList[i].region);
  7923. break;
  7924. }
  7925. }
  7926. break;
  7927. case "vertical":
  7928. settings.alt(k, v, ["rl", "lr"]);
  7929. break;
  7930. case "line":
  7931. var vals = v.split(","),
  7932. vals0 = vals[0];
  7933. settings.integer(k, vals0);
  7934. settings.percent(k, vals0) ? settings.set("snapToLines", false) : null;
  7935. settings.alt(k, vals0, ["auto"]);
  7936. if (vals.length === 2) {
  7937. settings.alt("lineAlign", vals[1], ["start", "center", "end"]);
  7938. }
  7939. break;
  7940. case "position":
  7941. vals = v.split(",");
  7942. settings.percent(k, vals[0]);
  7943. if (vals.length === 2) {
  7944. settings.alt("positionAlign", vals[1], ["start", "center", "end"]);
  7945. }
  7946. break;
  7947. case "size":
  7948. settings.percent(k, v);
  7949. break;
  7950. case "align":
  7951. settings.alt(k, v, ["start", "center", "end", "left", "right"]);
  7952. break;
  7953. }
  7954. }, /:/, /\s/); // Apply default values for any missing fields.
  7955. cue.region = settings.get("region", null);
  7956. cue.vertical = settings.get("vertical", "");
  7957. try {
  7958. cue.line = settings.get("line", "auto");
  7959. } catch (e) {}
  7960. cue.lineAlign = settings.get("lineAlign", "start");
  7961. cue.snapToLines = settings.get("snapToLines", true);
  7962. cue.size = settings.get("size", 100); // Safari still uses the old middle value and won't accept center
  7963. try {
  7964. cue.align = settings.get("align", "center");
  7965. } catch (e) {
  7966. cue.align = settings.get("align", "middle");
  7967. }
  7968. try {
  7969. cue.position = settings.get("position", "auto");
  7970. } catch (e) {
  7971. cue.position = settings.get("position", {
  7972. start: 0,
  7973. left: 0,
  7974. center: 50,
  7975. middle: 50,
  7976. end: 100,
  7977. right: 100
  7978. }, cue.align);
  7979. }
  7980. cue.positionAlign = settings.get("positionAlign", {
  7981. start: "start",
  7982. left: "start",
  7983. center: "center",
  7984. middle: "center",
  7985. end: "end",
  7986. right: "end"
  7987. }, cue.align);
  7988. }
  7989. function skipWhitespace() {
  7990. input = input.replace(/^\s+/, "");
  7991. } // 4.1 WebVTT cue timings.
  7992. skipWhitespace();
  7993. cue.startTime = consumeTimeStamp(); // (1) collect cue start time
  7994. skipWhitespace();
  7995. if (input.substr(0, 3) !== "-->") {
  7996. // (3) next characters must match "-->"
  7997. throw new ParsingError(ParsingError.Errors.BadTimeStamp, "Malformed time stamp (time stamps must be separated by '-->'): " + oInput);
  7998. }
  7999. input = input.substr(3);
  8000. skipWhitespace();
  8001. cue.endTime = consumeTimeStamp(); // (5) collect cue end time
  8002. // 4.1 WebVTT cue settings list.
  8003. skipWhitespace();
  8004. consumeCueSettings(input, cue);
  8005. } // When evaluating this file as part of a Webpack bundle for server
  8006. // side rendering, `document` is an empty object.
  8007. var TEXTAREA_ELEMENT = document_1.createElement && document_1.createElement("textarea");
  8008. var TAG_NAME = {
  8009. c: "span",
  8010. i: "i",
  8011. b: "b",
  8012. u: "u",
  8013. ruby: "ruby",
  8014. rt: "rt",
  8015. v: "span",
  8016. lang: "span"
  8017. }; // 5.1 default text color
  8018. // 5.2 default text background color is equivalent to text color with bg_ prefix
  8019. var DEFAULT_COLOR_CLASS = {
  8020. white: 'rgba(255,255,255,1)',
  8021. lime: 'rgba(0,255,0,1)',
  8022. cyan: 'rgba(0,255,255,1)',
  8023. red: 'rgba(255,0,0,1)',
  8024. yellow: 'rgba(255,255,0,1)',
  8025. magenta: 'rgba(255,0,255,1)',
  8026. blue: 'rgba(0,0,255,1)',
  8027. black: 'rgba(0,0,0,1)'
  8028. };
  8029. var TAG_ANNOTATION = {
  8030. v: "title",
  8031. lang: "lang"
  8032. };
  8033. var NEEDS_PARENT = {
  8034. rt: "ruby"
  8035. }; // Parse content into a document fragment.
  8036. function parseContent(window, input) {
  8037. function nextToken() {
  8038. // Check for end-of-string.
  8039. if (!input) {
  8040. return null;
  8041. } // Consume 'n' characters from the input.
  8042. function consume(result) {
  8043. input = input.substr(result.length);
  8044. return result;
  8045. }
  8046. var m = input.match(/^([^<]*)(<[^>]*>?)?/); // If there is some text before the next tag, return it, otherwise return
  8047. // the tag.
  8048. return consume(m[1] ? m[1] : m[2]);
  8049. }
  8050. function unescape(s) {
  8051. TEXTAREA_ELEMENT.innerHTML = s;
  8052. s = TEXTAREA_ELEMENT.textContent;
  8053. TEXTAREA_ELEMENT.textContent = "";
  8054. return s;
  8055. }
  8056. function shouldAdd(current, element) {
  8057. return !NEEDS_PARENT[element.localName] || NEEDS_PARENT[element.localName] === current.localName;
  8058. } // Create an element for this tag.
  8059. function createElement(type, annotation) {
  8060. var tagName = TAG_NAME[type];
  8061. if (!tagName) {
  8062. return null;
  8063. }
  8064. var element = window.document.createElement(tagName);
  8065. var name = TAG_ANNOTATION[type];
  8066. if (name && annotation) {
  8067. element[name] = annotation.trim();
  8068. }
  8069. return element;
  8070. }
  8071. var rootDiv = window.document.createElement("div"),
  8072. current = rootDiv,
  8073. t,
  8074. tagStack = [];
  8075. while ((t = nextToken()) !== null) {
  8076. if (t[0] === '<') {
  8077. if (t[1] === "/") {
  8078. // If the closing tag matches, move back up to the parent node.
  8079. if (tagStack.length && tagStack[tagStack.length - 1] === t.substr(2).replace(">", "")) {
  8080. tagStack.pop();
  8081. current = current.parentNode;
  8082. } // Otherwise just ignore the end tag.
  8083. continue;
  8084. }
  8085. var ts = parseTimeStamp(t.substr(1, t.length - 2));
  8086. var node;
  8087. if (ts) {
  8088. // Timestamps are lead nodes as well.
  8089. node = window.document.createProcessingInstruction("timestamp", ts);
  8090. current.appendChild(node);
  8091. continue;
  8092. }
  8093. var m = t.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/); // If we can't parse the tag, skip to the next tag.
  8094. if (!m) {
  8095. continue;
  8096. } // Try to construct an element, and ignore the tag if we couldn't.
  8097. node = createElement(m[1], m[3]);
  8098. if (!node) {
  8099. continue;
  8100. } // Determine if the tag should be added based on the context of where it
  8101. // is placed in the cuetext.
  8102. if (!shouldAdd(current, node)) {
  8103. continue;
  8104. } // Set the class list (as a list of classes, separated by space).
  8105. if (m[2]) {
  8106. var classes = m[2].split('.');
  8107. classes.forEach(function (cl) {
  8108. var bgColor = /^bg_/.test(cl); // slice out `bg_` if it's a background color
  8109. var colorName = bgColor ? cl.slice(3) : cl;
  8110. if (DEFAULT_COLOR_CLASS.hasOwnProperty(colorName)) {
  8111. var propName = bgColor ? 'background-color' : 'color';
  8112. var propValue = DEFAULT_COLOR_CLASS[colorName];
  8113. node.style[propName] = propValue;
  8114. }
  8115. });
  8116. node.className = classes.join(' ');
  8117. } // Append the node to the current node, and enter the scope of the new
  8118. // node.
  8119. tagStack.push(m[1]);
  8120. current.appendChild(node);
  8121. current = node;
  8122. continue;
  8123. } // Text nodes are leaf nodes.
  8124. current.appendChild(window.document.createTextNode(unescape(t)));
  8125. }
  8126. return rootDiv;
  8127. } // This is a list of all the Unicode characters that have a strong
  8128. // right-to-left category. What this means is that these characters are
  8129. // written right-to-left for sure. It was generated by pulling all the strong
  8130. // right-to-left characters out of the Unicode data table. That table can
  8131. // found at: http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
  8132. var strongRTLRanges = [[0x5be, 0x5be], [0x5c0, 0x5c0], [0x5c3, 0x5c3], [0x5c6, 0x5c6], [0x5d0, 0x5ea], [0x5f0, 0x5f4], [0x608, 0x608], [0x60b, 0x60b], [0x60d, 0x60d], [0x61b, 0x61b], [0x61e, 0x64a], [0x66d, 0x66f], [0x671, 0x6d5], [0x6e5, 0x6e6], [0x6ee, 0x6ef], [0x6fa, 0x70d], [0x70f, 0x710], [0x712, 0x72f], [0x74d, 0x7a5], [0x7b1, 0x7b1], [0x7c0, 0x7ea], [0x7f4, 0x7f5], [0x7fa, 0x7fa], [0x800, 0x815], [0x81a, 0x81a], [0x824, 0x824], [0x828, 0x828], [0x830, 0x83e], [0x840, 0x858], [0x85e, 0x85e], [0x8a0, 0x8a0], [0x8a2, 0x8ac], [0x200f, 0x200f], [0xfb1d, 0xfb1d], [0xfb1f, 0xfb28], [0xfb2a, 0xfb36], [0xfb38, 0xfb3c], [0xfb3e, 0xfb3e], [0xfb40, 0xfb41], [0xfb43, 0xfb44], [0xfb46, 0xfbc1], [0xfbd3, 0xfd3d], [0xfd50, 0xfd8f], [0xfd92, 0xfdc7], [0xfdf0, 0xfdfc], [0xfe70, 0xfe74], [0xfe76, 0xfefc], [0x10800, 0x10805], [0x10808, 0x10808], [0x1080a, 0x10835], [0x10837, 0x10838], [0x1083c, 0x1083c], [0x1083f, 0x10855], [0x10857, 0x1085f], [0x10900, 0x1091b], [0x10920, 0x10939], [0x1093f, 0x1093f], [0x10980, 0x109b7], [0x109be, 0x109bf], [0x10a00, 0x10a00], [0x10a10, 0x10a13], [0x10a15, 0x10a17], [0x10a19, 0x10a33], [0x10a40, 0x10a47], [0x10a50, 0x10a58], [0x10a60, 0x10a7f], [0x10b00, 0x10b35], [0x10b40, 0x10b55], [0x10b58, 0x10b72], [0x10b78, 0x10b7f], [0x10c00, 0x10c48], [0x1ee00, 0x1ee03], [0x1ee05, 0x1ee1f], [0x1ee21, 0x1ee22], [0x1ee24, 0x1ee24], [0x1ee27, 0x1ee27], [0x1ee29, 0x1ee32], [0x1ee34, 0x1ee37], [0x1ee39, 0x1ee39], [0x1ee3b, 0x1ee3b], [0x1ee42, 0x1ee42], [0x1ee47, 0x1ee47], [0x1ee49, 0x1ee49], [0x1ee4b, 0x1ee4b], [0x1ee4d, 0x1ee4f], [0x1ee51, 0x1ee52], [0x1ee54, 0x1ee54], [0x1ee57, 0x1ee57], [0x1ee59, 0x1ee59], [0x1ee5b, 0x1ee5b], [0x1ee5d, 0x1ee5d], [0x1ee5f, 0x1ee5f], [0x1ee61, 0x1ee62], [0x1ee64, 0x1ee64], [0x1ee67, 0x1ee6a], [0x1ee6c, 0x1ee72], [0x1ee74, 0x1ee77], [0x1ee79, 0x1ee7c], [0x1ee7e, 0x1ee7e], [0x1ee80, 0x1ee89], [0x1ee8b, 0x1ee9b], [0x1eea1, 0x1eea3], [0x1eea5, 0x1eea9], [0x1eeab, 0x1eebb], [0x10fffd, 0x10fffd]];
  8133. function isStrongRTLChar(charCode) {
  8134. for (var i = 0; i < strongRTLRanges.length; i++) {
  8135. var currentRange = strongRTLRanges[i];
  8136. if (charCode >= currentRange[0] && charCode <= currentRange[1]) {
  8137. return true;
  8138. }
  8139. }
  8140. return false;
  8141. }
  8142. function determineBidi(cueDiv) {
  8143. var nodeStack = [],
  8144. text = "",
  8145. charCode;
  8146. if (!cueDiv || !cueDiv.childNodes) {
  8147. return "ltr";
  8148. }
  8149. function pushNodes(nodeStack, node) {
  8150. for (var i = node.childNodes.length - 1; i >= 0; i--) {
  8151. nodeStack.push(node.childNodes[i]);
  8152. }
  8153. }
  8154. function nextTextNode(nodeStack) {
  8155. if (!nodeStack || !nodeStack.length) {
  8156. return null;
  8157. }
  8158. var node = nodeStack.pop(),
  8159. text = node.textContent || node.innerText;
  8160. if (text) {
  8161. // TODO: This should match all unicode type B characters (paragraph
  8162. // separator characters). See issue #115.
  8163. var m = text.match(/^.*(\n|\r)/);
  8164. if (m) {
  8165. nodeStack.length = 0;
  8166. return m[0];
  8167. }
  8168. return text;
  8169. }
  8170. if (node.tagName === "ruby") {
  8171. return nextTextNode(nodeStack);
  8172. }
  8173. if (node.childNodes) {
  8174. pushNodes(nodeStack, node);
  8175. return nextTextNode(nodeStack);
  8176. }
  8177. }
  8178. pushNodes(nodeStack, cueDiv);
  8179. while (text = nextTextNode(nodeStack)) {
  8180. for (var i = 0; i < text.length; i++) {
  8181. charCode = text.charCodeAt(i);
  8182. if (isStrongRTLChar(charCode)) {
  8183. return "rtl";
  8184. }
  8185. }
  8186. }
  8187. return "ltr";
  8188. }
  8189. function computeLinePos(cue) {
  8190. if (typeof cue.line === "number" && (cue.snapToLines || cue.line >= 0 && cue.line <= 100)) {
  8191. return cue.line;
  8192. }
  8193. if (!cue.track || !cue.track.textTrackList || !cue.track.textTrackList.mediaElement) {
  8194. return -1;
  8195. }
  8196. var track = cue.track,
  8197. trackList = track.textTrackList,
  8198. count = 0;
  8199. for (var i = 0; i < trackList.length && trackList[i] !== track; i++) {
  8200. if (trackList[i].mode === "showing") {
  8201. count++;
  8202. }
  8203. }
  8204. return ++count * -1;
  8205. }
  8206. function StyleBox() {} // Apply styles to a div. If there is no div passed then it defaults to the
  8207. // div on 'this'.
  8208. StyleBox.prototype.applyStyles = function (styles, div) {
  8209. div = div || this.div;
  8210. for (var prop in styles) {
  8211. if (styles.hasOwnProperty(prop)) {
  8212. div.style[prop] = styles[prop];
  8213. }
  8214. }
  8215. };
  8216. StyleBox.prototype.formatStyle = function (val, unit) {
  8217. return val === 0 ? 0 : val + unit;
  8218. }; // Constructs the computed display state of the cue (a div). Places the div
  8219. // into the overlay which should be a block level element (usually a div).
  8220. function CueStyleBox(window, cue, styleOptions) {
  8221. StyleBox.call(this);
  8222. this.cue = cue; // Parse our cue's text into a DOM tree rooted at 'cueDiv'. This div will
  8223. // have inline positioning and will function as the cue background box.
  8224. this.cueDiv = parseContent(window, cue.text);
  8225. var styles = {
  8226. color: "rgba(255, 255, 255, 1)",
  8227. backgroundColor: "rgba(0, 0, 0, 0.8)",
  8228. position: "relative",
  8229. left: 0,
  8230. right: 0,
  8231. top: 0,
  8232. bottom: 0,
  8233. display: "inline",
  8234. writingMode: cue.vertical === "" ? "horizontal-tb" : cue.vertical === "lr" ? "vertical-lr" : "vertical-rl",
  8235. unicodeBidi: "plaintext"
  8236. };
  8237. this.applyStyles(styles, this.cueDiv); // Create an absolutely positioned div that will be used to position the cue
  8238. // div. Note, all WebVTT cue-setting alignments are equivalent to the CSS
  8239. // mirrors of them except middle instead of center on Safari.
  8240. this.div = window.document.createElement("div");
  8241. styles = {
  8242. direction: determineBidi(this.cueDiv),
  8243. writingMode: cue.vertical === "" ? "horizontal-tb" : cue.vertical === "lr" ? "vertical-lr" : "vertical-rl",
  8244. unicodeBidi: "plaintext",
  8245. textAlign: cue.align === "middle" ? "center" : cue.align,
  8246. font: styleOptions.font,
  8247. whiteSpace: "pre-line",
  8248. position: "absolute"
  8249. };
  8250. this.applyStyles(styles);
  8251. this.div.appendChild(this.cueDiv); // Calculate the distance from the reference edge of the viewport to the text
  8252. // position of the cue box. The reference edge will be resolved later when
  8253. // the box orientation styles are applied.
  8254. var textPos = 0;
  8255. switch (cue.positionAlign) {
  8256. case "start":
  8257. textPos = cue.position;
  8258. break;
  8259. case "center":
  8260. textPos = cue.position - cue.size / 2;
  8261. break;
  8262. case "end":
  8263. textPos = cue.position - cue.size;
  8264. break;
  8265. } // Horizontal box orientation; textPos is the distance from the left edge of the
  8266. // area to the left edge of the box and cue.size is the distance extending to
  8267. // the right from there.
  8268. if (cue.vertical === "") {
  8269. this.applyStyles({
  8270. left: this.formatStyle(textPos, "%"),
  8271. width: this.formatStyle(cue.size, "%")
  8272. }); // Vertical box orientation; textPos is the distance from the top edge of the
  8273. // area to the top edge of the box and cue.size is the height extending
  8274. // downwards from there.
  8275. } else {
  8276. this.applyStyles({
  8277. top: this.formatStyle(textPos, "%"),
  8278. height: this.formatStyle(cue.size, "%")
  8279. });
  8280. }
  8281. this.move = function (box) {
  8282. this.applyStyles({
  8283. top: this.formatStyle(box.top, "px"),
  8284. bottom: this.formatStyle(box.bottom, "px"),
  8285. left: this.formatStyle(box.left, "px"),
  8286. right: this.formatStyle(box.right, "px"),
  8287. height: this.formatStyle(box.height, "px"),
  8288. width: this.formatStyle(box.width, "px")
  8289. });
  8290. };
  8291. }
  8292. CueStyleBox.prototype = _objCreate(StyleBox.prototype);
  8293. CueStyleBox.prototype.constructor = CueStyleBox; // Represents the co-ordinates of an Element in a way that we can easily
  8294. // compute things with such as if it overlaps or intersects with another Element.
  8295. // Can initialize it with either a StyleBox or another BoxPosition.
  8296. function BoxPosition(obj) {
  8297. // Either a BoxPosition was passed in and we need to copy it, or a StyleBox
  8298. // was passed in and we need to copy the results of 'getBoundingClientRect'
  8299. // as the object returned is readonly. All co-ordinate values are in reference
  8300. // to the viewport origin (top left).
  8301. var lh, height, width, top;
  8302. if (obj.div) {
  8303. height = obj.div.offsetHeight;
  8304. width = obj.div.offsetWidth;
  8305. top = obj.div.offsetTop;
  8306. var rects = (rects = obj.div.childNodes) && (rects = rects[0]) && rects.getClientRects && rects.getClientRects();
  8307. obj = obj.div.getBoundingClientRect(); // In certain cases the outter div will be slightly larger then the sum of
  8308. // the inner div's lines. This could be due to bold text, etc, on some platforms.
  8309. // In this case we should get the average line height and use that. This will
  8310. // result in the desired behaviour.
  8311. lh = rects ? Math.max(rects[0] && rects[0].height || 0, obj.height / rects.length) : 0;
  8312. }
  8313. this.left = obj.left;
  8314. this.right = obj.right;
  8315. this.top = obj.top || top;
  8316. this.height = obj.height || height;
  8317. this.bottom = obj.bottom || top + (obj.height || height);
  8318. this.width = obj.width || width;
  8319. this.lineHeight = lh !== undefined ? lh : obj.lineHeight;
  8320. } // Move the box along a particular axis. Optionally pass in an amount to move
  8321. // the box. If no amount is passed then the default is the line height of the
  8322. // box.
  8323. BoxPosition.prototype.move = function (axis, toMove) {
  8324. toMove = toMove !== undefined ? toMove : this.lineHeight;
  8325. switch (axis) {
  8326. case "+x":
  8327. this.left += toMove;
  8328. this.right += toMove;
  8329. break;
  8330. case "-x":
  8331. this.left -= toMove;
  8332. this.right -= toMove;
  8333. break;
  8334. case "+y":
  8335. this.top += toMove;
  8336. this.bottom += toMove;
  8337. break;
  8338. case "-y":
  8339. this.top -= toMove;
  8340. this.bottom -= toMove;
  8341. break;
  8342. }
  8343. }; // Check if this box overlaps another box, b2.
  8344. BoxPosition.prototype.overlaps = function (b2) {
  8345. return this.left < b2.right && this.right > b2.left && this.top < b2.bottom && this.bottom > b2.top;
  8346. }; // Check if this box overlaps any other boxes in boxes.
  8347. BoxPosition.prototype.overlapsAny = function (boxes) {
  8348. for (var i = 0; i < boxes.length; i++) {
  8349. if (this.overlaps(boxes[i])) {
  8350. return true;
  8351. }
  8352. }
  8353. return false;
  8354. }; // Check if this box is within another box.
  8355. BoxPosition.prototype.within = function (container) {
  8356. return this.top >= container.top && this.bottom <= container.bottom && this.left >= container.left && this.right <= container.right;
  8357. }; // Check if this box is entirely within the container or it is overlapping
  8358. // on the edge opposite of the axis direction passed. For example, if "+x" is
  8359. // passed and the box is overlapping on the left edge of the container, then
  8360. // return true.
  8361. BoxPosition.prototype.overlapsOppositeAxis = function (container, axis) {
  8362. switch (axis) {
  8363. case "+x":
  8364. return this.left < container.left;
  8365. case "-x":
  8366. return this.right > container.right;
  8367. case "+y":
  8368. return this.top < container.top;
  8369. case "-y":
  8370. return this.bottom > container.bottom;
  8371. }
  8372. }; // Find the percentage of the area that this box is overlapping with another
  8373. // box.
  8374. BoxPosition.prototype.intersectPercentage = function (b2) {
  8375. var x = Math.max(0, Math.min(this.right, b2.right) - Math.max(this.left, b2.left)),
  8376. y = Math.max(0, Math.min(this.bottom, b2.bottom) - Math.max(this.top, b2.top)),
  8377. intersectArea = x * y;
  8378. return intersectArea / (this.height * this.width);
  8379. }; // Convert the positions from this box to CSS compatible positions using
  8380. // the reference container's positions. This has to be done because this
  8381. // box's positions are in reference to the viewport origin, whereas, CSS
  8382. // values are in referecne to their respective edges.
  8383. BoxPosition.prototype.toCSSCompatValues = function (reference) {
  8384. return {
  8385. top: this.top - reference.top,
  8386. bottom: reference.bottom - this.bottom,
  8387. left: this.left - reference.left,
  8388. right: reference.right - this.right,
  8389. height: this.height,
  8390. width: this.width
  8391. };
  8392. }; // Get an object that represents the box's position without anything extra.
  8393. // Can pass a StyleBox, HTMLElement, or another BoxPositon.
  8394. BoxPosition.getSimpleBoxPosition = function (obj) {
  8395. var height = obj.div ? obj.div.offsetHeight : obj.tagName ? obj.offsetHeight : 0;
  8396. var width = obj.div ? obj.div.offsetWidth : obj.tagName ? obj.offsetWidth : 0;
  8397. var top = obj.div ? obj.div.offsetTop : obj.tagName ? obj.offsetTop : 0;
  8398. obj = obj.div ? obj.div.getBoundingClientRect() : obj.tagName ? obj.getBoundingClientRect() : obj;
  8399. var ret = {
  8400. left: obj.left,
  8401. right: obj.right,
  8402. top: obj.top || top,
  8403. height: obj.height || height,
  8404. bottom: obj.bottom || top + (obj.height || height),
  8405. width: obj.width || width
  8406. };
  8407. return ret;
  8408. }; // Move a StyleBox to its specified, or next best, position. The containerBox
  8409. // is the box that contains the StyleBox, such as a div. boxPositions are
  8410. // a list of other boxes that the styleBox can't overlap with.
  8411. function moveBoxToLinePosition(window, styleBox, containerBox, boxPositions) {
  8412. // Find the best position for a cue box, b, on the video. The axis parameter
  8413. // is a list of axis, the order of which, it will move the box along. For example:
  8414. // Passing ["+x", "-x"] will move the box first along the x axis in the positive
  8415. // direction. If it doesn't find a good position for it there it will then move
  8416. // it along the x axis in the negative direction.
  8417. function findBestPosition(b, axis) {
  8418. var bestPosition,
  8419. specifiedPosition = new BoxPosition(b),
  8420. percentage = 1; // Highest possible so the first thing we get is better.
  8421. for (var i = 0; i < axis.length; i++) {
  8422. while (b.overlapsOppositeAxis(containerBox, axis[i]) || b.within(containerBox) && b.overlapsAny(boxPositions)) {
  8423. b.move(axis[i]);
  8424. } // We found a spot where we aren't overlapping anything. This is our
  8425. // best position.
  8426. if (b.within(containerBox)) {
  8427. return b;
  8428. }
  8429. var p = b.intersectPercentage(containerBox); // If we're outside the container box less then we were on our last try
  8430. // then remember this position as the best position.
  8431. if (percentage > p) {
  8432. bestPosition = new BoxPosition(b);
  8433. percentage = p;
  8434. } // Reset the box position to the specified position.
  8435. b = new BoxPosition(specifiedPosition);
  8436. }
  8437. return bestPosition || specifiedPosition;
  8438. }
  8439. var boxPosition = new BoxPosition(styleBox),
  8440. cue = styleBox.cue,
  8441. linePos = computeLinePos(cue),
  8442. axis = []; // If we have a line number to align the cue to.
  8443. if (cue.snapToLines) {
  8444. var size;
  8445. switch (cue.vertical) {
  8446. case "":
  8447. axis = ["+y", "-y"];
  8448. size = "height";
  8449. break;
  8450. case "rl":
  8451. axis = ["+x", "-x"];
  8452. size = "width";
  8453. break;
  8454. case "lr":
  8455. axis = ["-x", "+x"];
  8456. size = "width";
  8457. break;
  8458. }
  8459. var step = boxPosition.lineHeight,
  8460. position = step * Math.round(linePos),
  8461. maxPosition = containerBox[size] + step,
  8462. initialAxis = axis[0]; // If the specified intial position is greater then the max position then
  8463. // clamp the box to the amount of steps it would take for the box to
  8464. // reach the max position.
  8465. if (Math.abs(position) > maxPosition) {
  8466. position = position < 0 ? -1 : 1;
  8467. position *= Math.ceil(maxPosition / step) * step;
  8468. } // If computed line position returns negative then line numbers are
  8469. // relative to the bottom of the video instead of the top. Therefore, we
  8470. // need to increase our initial position by the length or width of the
  8471. // video, depending on the writing direction, and reverse our axis directions.
  8472. if (linePos < 0) {
  8473. position += cue.vertical === "" ? containerBox.height : containerBox.width;
  8474. axis = axis.reverse();
  8475. } // Move the box to the specified position. This may not be its best
  8476. // position.
  8477. boxPosition.move(initialAxis, position);
  8478. } else {
  8479. // If we have a percentage line value for the cue.
  8480. var calculatedPercentage = boxPosition.lineHeight / containerBox.height * 100;
  8481. switch (cue.lineAlign) {
  8482. case "center":
  8483. linePos -= calculatedPercentage / 2;
  8484. break;
  8485. case "end":
  8486. linePos -= calculatedPercentage;
  8487. break;
  8488. } // Apply initial line position to the cue box.
  8489. switch (cue.vertical) {
  8490. case "":
  8491. styleBox.applyStyles({
  8492. top: styleBox.formatStyle(linePos, "%")
  8493. });
  8494. break;
  8495. case "rl":
  8496. styleBox.applyStyles({
  8497. left: styleBox.formatStyle(linePos, "%")
  8498. });
  8499. break;
  8500. case "lr":
  8501. styleBox.applyStyles({
  8502. right: styleBox.formatStyle(linePos, "%")
  8503. });
  8504. break;
  8505. }
  8506. axis = ["+y", "-x", "+x", "-y"]; // Get the box position again after we've applied the specified positioning
  8507. // to it.
  8508. boxPosition = new BoxPosition(styleBox);
  8509. }
  8510. var bestPosition = findBestPosition(boxPosition, axis);
  8511. styleBox.move(bestPosition.toCSSCompatValues(containerBox));
  8512. }
  8513. function WebVTT$1() {// Nothing
  8514. } // Helper to allow strings to be decoded instead of the default binary utf8 data.
  8515. WebVTT$1.StringDecoder = function () {
  8516. return {
  8517. decode: function decode(data) {
  8518. if (!data) {
  8519. return "";
  8520. }
  8521. if (typeof data !== "string") {
  8522. throw new Error("Error - expected string data.");
  8523. }
  8524. return decodeURIComponent(encodeURIComponent(data));
  8525. }
  8526. };
  8527. };
  8528. WebVTT$1.convertCueToDOMTree = function (window, cuetext) {
  8529. if (!window || !cuetext) {
  8530. return null;
  8531. }
  8532. return parseContent(window, cuetext);
  8533. };
  8534. var FONT_SIZE_PERCENT = 0.05;
  8535. var FONT_STYLE = "sans-serif";
  8536. var CUE_BACKGROUND_PADDING = "1.5%"; // Runs the processing model over the cues and regions passed to it.
  8537. // @param overlay A block level element (usually a div) that the computed cues
  8538. // and regions will be placed into.
  8539. WebVTT$1.processCues = function (window, cues, overlay) {
  8540. if (!window || !cues || !overlay) {
  8541. return null;
  8542. } // Remove all previous children.
  8543. while (overlay.firstChild) {
  8544. overlay.removeChild(overlay.firstChild);
  8545. }
  8546. var paddedOverlay = window.document.createElement("div");
  8547. paddedOverlay.style.position = "absolute";
  8548. paddedOverlay.style.left = "0";
  8549. paddedOverlay.style.right = "0";
  8550. paddedOverlay.style.top = "0";
  8551. paddedOverlay.style.bottom = "0";
  8552. paddedOverlay.style.margin = CUE_BACKGROUND_PADDING;
  8553. overlay.appendChild(paddedOverlay); // Determine if we need to compute the display states of the cues. This could
  8554. // be the case if a cue's state has been changed since the last computation or
  8555. // if it has not been computed yet.
  8556. function shouldCompute(cues) {
  8557. for (var i = 0; i < cues.length; i++) {
  8558. if (cues[i].hasBeenReset || !cues[i].displayState) {
  8559. return true;
  8560. }
  8561. }
  8562. return false;
  8563. } // We don't need to recompute the cues' display states. Just reuse them.
  8564. if (!shouldCompute(cues)) {
  8565. for (var i = 0; i < cues.length; i++) {
  8566. paddedOverlay.appendChild(cues[i].displayState);
  8567. }
  8568. return;
  8569. }
  8570. var boxPositions = [],
  8571. containerBox = BoxPosition.getSimpleBoxPosition(paddedOverlay),
  8572. fontSize = Math.round(containerBox.height * FONT_SIZE_PERCENT * 100) / 100;
  8573. var styleOptions = {
  8574. font: fontSize + "px " + FONT_STYLE
  8575. };
  8576. (function () {
  8577. var styleBox, cue;
  8578. for (var i = 0; i < cues.length; i++) {
  8579. cue = cues[i]; // Compute the intial position and styles of the cue div.
  8580. styleBox = new CueStyleBox(window, cue, styleOptions);
  8581. paddedOverlay.appendChild(styleBox.div); // Move the cue div to it's correct line position.
  8582. moveBoxToLinePosition(window, styleBox, containerBox, boxPositions); // Remember the computed div so that we don't have to recompute it later
  8583. // if we don't have too.
  8584. cue.displayState = styleBox.div;
  8585. boxPositions.push(BoxPosition.getSimpleBoxPosition(styleBox));
  8586. }
  8587. })();
  8588. };
  8589. WebVTT$1.Parser = function (window, vttjs, decoder) {
  8590. if (!decoder) {
  8591. decoder = vttjs;
  8592. vttjs = {};
  8593. }
  8594. if (!vttjs) {
  8595. vttjs = {};
  8596. }
  8597. this.window = window;
  8598. this.vttjs = vttjs;
  8599. this.state = "INITIAL";
  8600. this.buffer = "";
  8601. this.decoder = decoder || new TextDecoder("utf8");
  8602. this.regionList = [];
  8603. };
  8604. WebVTT$1.Parser.prototype = {
  8605. // If the error is a ParsingError then report it to the consumer if
  8606. // possible. If it's not a ParsingError then throw it like normal.
  8607. reportOrThrowError: function reportOrThrowError(e) {
  8608. if (e instanceof ParsingError) {
  8609. this.onparsingerror && this.onparsingerror(e);
  8610. } else {
  8611. throw e;
  8612. }
  8613. },
  8614. parse: function parse(data) {
  8615. var self = this; // If there is no data then we won't decode it, but will just try to parse
  8616. // whatever is in buffer already. This may occur in circumstances, for
  8617. // example when flush() is called.
  8618. if (data) {
  8619. // Try to decode the data that we received.
  8620. self.buffer += self.decoder.decode(data, {
  8621. stream: true
  8622. });
  8623. }
  8624. function collectNextLine() {
  8625. var buffer = self.buffer;
  8626. var pos = 0;
  8627. while (pos < buffer.length && buffer[pos] !== '\r' && buffer[pos] !== '\n') {
  8628. ++pos;
  8629. }
  8630. var line = buffer.substr(0, pos); // Advance the buffer early in case we fail below.
  8631. if (buffer[pos] === '\r') {
  8632. ++pos;
  8633. }
  8634. if (buffer[pos] === '\n') {
  8635. ++pos;
  8636. }
  8637. self.buffer = buffer.substr(pos);
  8638. return line;
  8639. } // 3.4 WebVTT region and WebVTT region settings syntax
  8640. function parseRegion(input) {
  8641. var settings = new Settings();
  8642. parseOptions(input, function (k, v) {
  8643. switch (k) {
  8644. case "id":
  8645. settings.set(k, v);
  8646. break;
  8647. case "width":
  8648. settings.percent(k, v);
  8649. break;
  8650. case "lines":
  8651. settings.integer(k, v);
  8652. break;
  8653. case "regionanchor":
  8654. case "viewportanchor":
  8655. var xy = v.split(',');
  8656. if (xy.length !== 2) {
  8657. break;
  8658. } // We have to make sure both x and y parse, so use a temporary
  8659. // settings object here.
  8660. var anchor = new Settings();
  8661. anchor.percent("x", xy[0]);
  8662. anchor.percent("y", xy[1]);
  8663. if (!anchor.has("x") || !anchor.has("y")) {
  8664. break;
  8665. }
  8666. settings.set(k + "X", anchor.get("x"));
  8667. settings.set(k + "Y", anchor.get("y"));
  8668. break;
  8669. case "scroll":
  8670. settings.alt(k, v, ["up"]);
  8671. break;
  8672. }
  8673. }, /=/, /\s/); // Create the region, using default values for any values that were not
  8674. // specified.
  8675. if (settings.has("id")) {
  8676. var region = new (self.vttjs.VTTRegion || self.window.VTTRegion)();
  8677. region.width = settings.get("width", 100);
  8678. region.lines = settings.get("lines", 3);
  8679. region.regionAnchorX = settings.get("regionanchorX", 0);
  8680. region.regionAnchorY = settings.get("regionanchorY", 100);
  8681. region.viewportAnchorX = settings.get("viewportanchorX", 0);
  8682. region.viewportAnchorY = settings.get("viewportanchorY", 100);
  8683. region.scroll = settings.get("scroll", ""); // Register the region.
  8684. self.onregion && self.onregion(region); // Remember the VTTRegion for later in case we parse any VTTCues that
  8685. // reference it.
  8686. self.regionList.push({
  8687. id: settings.get("id"),
  8688. region: region
  8689. });
  8690. }
  8691. } // draft-pantos-http-live-streaming-20
  8692. // https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5
  8693. // 3.5 WebVTT
  8694. function parseTimestampMap(input) {
  8695. var settings = new Settings();
  8696. parseOptions(input, function (k, v) {
  8697. switch (k) {
  8698. case "MPEGT":
  8699. settings.integer(k + 'S', v);
  8700. break;
  8701. case "LOCA":
  8702. settings.set(k + 'L', parseTimeStamp(v));
  8703. break;
  8704. }
  8705. }, /[^\d]:/, /,/);
  8706. self.ontimestampmap && self.ontimestampmap({
  8707. "MPEGTS": settings.get("MPEGTS"),
  8708. "LOCAL": settings.get("LOCAL")
  8709. });
  8710. } // 3.2 WebVTT metadata header syntax
  8711. function parseHeader(input) {
  8712. if (input.match(/X-TIMESTAMP-MAP/)) {
  8713. // This line contains HLS X-TIMESTAMP-MAP metadata
  8714. parseOptions(input, function (k, v) {
  8715. switch (k) {
  8716. case "X-TIMESTAMP-MAP":
  8717. parseTimestampMap(v);
  8718. break;
  8719. }
  8720. }, /=/);
  8721. } else {
  8722. parseOptions(input, function (k, v) {
  8723. switch (k) {
  8724. case "Region":
  8725. // 3.3 WebVTT region metadata header syntax
  8726. parseRegion(v);
  8727. break;
  8728. }
  8729. }, /:/);
  8730. }
  8731. } // 5.1 WebVTT file parsing.
  8732. try {
  8733. var line;
  8734. if (self.state === "INITIAL") {
  8735. // We can't start parsing until we have the first line.
  8736. if (!/\r\n|\n/.test(self.buffer)) {
  8737. return this;
  8738. }
  8739. line = collectNextLine();
  8740. var m = line.match(/^WEBVTT([ \t].*)?$/);
  8741. if (!m || !m[0]) {
  8742. throw new ParsingError(ParsingError.Errors.BadSignature);
  8743. }
  8744. self.state = "HEADER";
  8745. }
  8746. var alreadyCollectedLine = false;
  8747. while (self.buffer) {
  8748. // We can't parse a line until we have the full line.
  8749. if (!/\r\n|\n/.test(self.buffer)) {
  8750. return this;
  8751. }
  8752. if (!alreadyCollectedLine) {
  8753. line = collectNextLine();
  8754. } else {
  8755. alreadyCollectedLine = false;
  8756. }
  8757. switch (self.state) {
  8758. case "HEADER":
  8759. // 13-18 - Allow a header (metadata) under the WEBVTT line.
  8760. if (/:/.test(line)) {
  8761. parseHeader(line);
  8762. } else if (!line) {
  8763. // An empty line terminates the header and starts the body (cues).
  8764. self.state = "ID";
  8765. }
  8766. continue;
  8767. case "NOTE":
  8768. // Ignore NOTE blocks.
  8769. if (!line) {
  8770. self.state = "ID";
  8771. }
  8772. continue;
  8773. case "ID":
  8774. // Check for the start of NOTE blocks.
  8775. if (/^NOTE($|[ \t])/.test(line)) {
  8776. self.state = "NOTE";
  8777. break;
  8778. } // 19-29 - Allow any number of line terminators, then initialize new cue values.
  8779. if (!line) {
  8780. continue;
  8781. }
  8782. self.cue = new (self.vttjs.VTTCue || self.window.VTTCue)(0, 0, ""); // Safari still uses the old middle value and won't accept center
  8783. try {
  8784. self.cue.align = "center";
  8785. } catch (e) {
  8786. self.cue.align = "middle";
  8787. }
  8788. self.state = "CUE"; // 30-39 - Check if self line contains an optional identifier or timing data.
  8789. if (line.indexOf("-->") === -1) {
  8790. self.cue.id = line;
  8791. continue;
  8792. }
  8793. // Process line as start of a cue.
  8794. /*falls through*/
  8795. case "CUE":
  8796. // 40 - Collect cue timings and settings.
  8797. try {
  8798. parseCue(line, self.cue, self.regionList);
  8799. } catch (e) {
  8800. self.reportOrThrowError(e); // In case of an error ignore rest of the cue.
  8801. self.cue = null;
  8802. self.state = "BADCUE";
  8803. continue;
  8804. }
  8805. self.state = "CUETEXT";
  8806. continue;
  8807. case "CUETEXT":
  8808. var hasSubstring = line.indexOf("-->") !== -1; // 34 - If we have an empty line then report the cue.
  8809. // 35 - If we have the special substring '-->' then report the cue,
  8810. // but do not collect the line as we need to process the current
  8811. // one as a new cue.
  8812. if (!line || hasSubstring && (alreadyCollectedLine = true)) {
  8813. // We are done parsing self cue.
  8814. self.oncue && self.oncue(self.cue);
  8815. self.cue = null;
  8816. self.state = "ID";
  8817. continue;
  8818. }
  8819. if (self.cue.text) {
  8820. self.cue.text += "\n";
  8821. }
  8822. self.cue.text += line.replace(/\u2028/g, '\n').replace(/u2029/g, '\n');
  8823. continue;
  8824. case "BADCUE":
  8825. // BADCUE
  8826. // 54-62 - Collect and discard the remaining cue.
  8827. if (!line) {
  8828. self.state = "ID";
  8829. }
  8830. continue;
  8831. }
  8832. }
  8833. } catch (e) {
  8834. self.reportOrThrowError(e); // If we are currently parsing a cue, report what we have.
  8835. if (self.state === "CUETEXT" && self.cue && self.oncue) {
  8836. self.oncue(self.cue);
  8837. }
  8838. self.cue = null; // Enter BADWEBVTT state if header was not parsed correctly otherwise
  8839. // another exception occurred so enter BADCUE state.
  8840. self.state = self.state === "INITIAL" ? "BADWEBVTT" : "BADCUE";
  8841. }
  8842. return this;
  8843. },
  8844. flush: function flush() {
  8845. var self = this;
  8846. try {
  8847. // Finish decoding the stream.
  8848. self.buffer += self.decoder.decode(); // Synthesize the end of the current cue or region.
  8849. if (self.cue || self.state === "HEADER") {
  8850. self.buffer += "\n\n";
  8851. self.parse();
  8852. } // If we've flushed, parsed, and we're still on the INITIAL state then
  8853. // that means we don't have enough of the stream to parse the first
  8854. // line.
  8855. if (self.state === "INITIAL") {
  8856. throw new ParsingError(ParsingError.Errors.BadSignature);
  8857. }
  8858. } catch (e) {
  8859. self.reportOrThrowError(e);
  8860. }
  8861. self.onflush && self.onflush();
  8862. return this;
  8863. }
  8864. };
  8865. var vtt = WebVTT$1;
  8866. /**
  8867. * Copyright 2013 vtt.js Contributors
  8868. *
  8869. * Licensed under the Apache License, Version 2.0 (the "License");
  8870. * you may not use this file except in compliance with the License.
  8871. * You may obtain a copy of the License at
  8872. *
  8873. * http://www.apache.org/licenses/LICENSE-2.0
  8874. *
  8875. * Unless required by applicable law or agreed to in writing, software
  8876. * distributed under the License is distributed on an "AS IS" BASIS,
  8877. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8878. * See the License for the specific language governing permissions and
  8879. * limitations under the License.
  8880. */
  8881. var autoKeyword = "auto";
  8882. var directionSetting = {
  8883. "": 1,
  8884. "lr": 1,
  8885. "rl": 1
  8886. };
  8887. var alignSetting = {
  8888. "start": 1,
  8889. "center": 1,
  8890. "end": 1,
  8891. "left": 1,
  8892. "right": 1,
  8893. "auto": 1,
  8894. "line-left": 1,
  8895. "line-right": 1
  8896. };
  8897. function findDirectionSetting(value) {
  8898. if (typeof value !== "string") {
  8899. return false;
  8900. }
  8901. var dir = directionSetting[value.toLowerCase()];
  8902. return dir ? value.toLowerCase() : false;
  8903. }
  8904. function findAlignSetting(value) {
  8905. if (typeof value !== "string") {
  8906. return false;
  8907. }
  8908. var align = alignSetting[value.toLowerCase()];
  8909. return align ? value.toLowerCase() : false;
  8910. }
  8911. function VTTCue(startTime, endTime, text) {
  8912. /**
  8913. * Shim implementation specific properties. These properties are not in
  8914. * the spec.
  8915. */
  8916. // Lets us know when the VTTCue's data has changed in such a way that we need
  8917. // to recompute its display state. This lets us compute its display state
  8918. // lazily.
  8919. this.hasBeenReset = false;
  8920. /**
  8921. * VTTCue and TextTrackCue properties
  8922. * http://dev.w3.org/html5/webvtt/#vttcue-interface
  8923. */
  8924. var _id = "";
  8925. var _pauseOnExit = false;
  8926. var _startTime = startTime;
  8927. var _endTime = endTime;
  8928. var _text = text;
  8929. var _region = null;
  8930. var _vertical = "";
  8931. var _snapToLines = true;
  8932. var _line = "auto";
  8933. var _lineAlign = "start";
  8934. var _position = "auto";
  8935. var _positionAlign = "auto";
  8936. var _size = 100;
  8937. var _align = "center";
  8938. Object.defineProperties(this, {
  8939. "id": {
  8940. enumerable: true,
  8941. get: function get() {
  8942. return _id;
  8943. },
  8944. set: function set(value) {
  8945. _id = "" + value;
  8946. }
  8947. },
  8948. "pauseOnExit": {
  8949. enumerable: true,
  8950. get: function get() {
  8951. return _pauseOnExit;
  8952. },
  8953. set: function set(value) {
  8954. _pauseOnExit = !!value;
  8955. }
  8956. },
  8957. "startTime": {
  8958. enumerable: true,
  8959. get: function get() {
  8960. return _startTime;
  8961. },
  8962. set: function set(value) {
  8963. if (typeof value !== "number") {
  8964. throw new TypeError("Start time must be set to a number.");
  8965. }
  8966. _startTime = value;
  8967. this.hasBeenReset = true;
  8968. }
  8969. },
  8970. "endTime": {
  8971. enumerable: true,
  8972. get: function get() {
  8973. return _endTime;
  8974. },
  8975. set: function set(value) {
  8976. if (typeof value !== "number") {
  8977. throw new TypeError("End time must be set to a number.");
  8978. }
  8979. _endTime = value;
  8980. this.hasBeenReset = true;
  8981. }
  8982. },
  8983. "text": {
  8984. enumerable: true,
  8985. get: function get() {
  8986. return _text;
  8987. },
  8988. set: function set(value) {
  8989. _text = "" + value;
  8990. this.hasBeenReset = true;
  8991. }
  8992. },
  8993. "region": {
  8994. enumerable: true,
  8995. get: function get() {
  8996. return _region;
  8997. },
  8998. set: function set(value) {
  8999. _region = value;
  9000. this.hasBeenReset = true;
  9001. }
  9002. },
  9003. "vertical": {
  9004. enumerable: true,
  9005. get: function get() {
  9006. return _vertical;
  9007. },
  9008. set: function set(value) {
  9009. var setting = findDirectionSetting(value); // Have to check for false because the setting an be an empty string.
  9010. if (setting === false) {
  9011. throw new SyntaxError("Vertical: an invalid or illegal direction string was specified.");
  9012. }
  9013. _vertical = setting;
  9014. this.hasBeenReset = true;
  9015. }
  9016. },
  9017. "snapToLines": {
  9018. enumerable: true,
  9019. get: function get() {
  9020. return _snapToLines;
  9021. },
  9022. set: function set(value) {
  9023. _snapToLines = !!value;
  9024. this.hasBeenReset = true;
  9025. }
  9026. },
  9027. "line": {
  9028. enumerable: true,
  9029. get: function get() {
  9030. return _line;
  9031. },
  9032. set: function set(value) {
  9033. if (typeof value !== "number" && value !== autoKeyword) {
  9034. throw new SyntaxError("Line: an invalid number or illegal string was specified.");
  9035. }
  9036. _line = value;
  9037. this.hasBeenReset = true;
  9038. }
  9039. },
  9040. "lineAlign": {
  9041. enumerable: true,
  9042. get: function get() {
  9043. return _lineAlign;
  9044. },
  9045. set: function set(value) {
  9046. var setting = findAlignSetting(value);
  9047. if (!setting) {
  9048. console.warn("lineAlign: an invalid or illegal string was specified.");
  9049. } else {
  9050. _lineAlign = setting;
  9051. this.hasBeenReset = true;
  9052. }
  9053. }
  9054. },
  9055. "position": {
  9056. enumerable: true,
  9057. get: function get() {
  9058. return _position;
  9059. },
  9060. set: function set(value) {
  9061. if (value < 0 || value > 100) {
  9062. throw new Error("Position must be between 0 and 100.");
  9063. }
  9064. _position = value;
  9065. this.hasBeenReset = true;
  9066. }
  9067. },
  9068. "positionAlign": {
  9069. enumerable: true,
  9070. get: function get() {
  9071. return _positionAlign;
  9072. },
  9073. set: function set(value) {
  9074. var setting = findAlignSetting(value);
  9075. if (!setting) {
  9076. console.warn("positionAlign: an invalid or illegal string was specified.");
  9077. } else {
  9078. _positionAlign = setting;
  9079. this.hasBeenReset = true;
  9080. }
  9081. }
  9082. },
  9083. "size": {
  9084. enumerable: true,
  9085. get: function get() {
  9086. return _size;
  9087. },
  9088. set: function set(value) {
  9089. if (value < 0 || value > 100) {
  9090. throw new Error("Size must be between 0 and 100.");
  9091. }
  9092. _size = value;
  9093. this.hasBeenReset = true;
  9094. }
  9095. },
  9096. "align": {
  9097. enumerable: true,
  9098. get: function get() {
  9099. return _align;
  9100. },
  9101. set: function set(value) {
  9102. var setting = findAlignSetting(value);
  9103. if (!setting) {
  9104. throw new SyntaxError("align: an invalid or illegal alignment string was specified.");
  9105. }
  9106. _align = setting;
  9107. this.hasBeenReset = true;
  9108. }
  9109. }
  9110. });
  9111. /**
  9112. * Other <track> spec defined properties
  9113. */
  9114. // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#text-track-cue-display-state
  9115. this.displayState = undefined;
  9116. }
  9117. /**
  9118. * VTTCue methods
  9119. */
  9120. VTTCue.prototype.getCueAsHTML = function () {
  9121. // Assume WebVTT.convertCueToDOMTree is on the global.
  9122. return WebVTT.convertCueToDOMTree(window, this.text);
  9123. };
  9124. var vttcue = VTTCue;
  9125. /**
  9126. * Copyright 2013 vtt.js Contributors
  9127. *
  9128. * Licensed under the Apache License, Version 2.0 (the "License");
  9129. * you may not use this file except in compliance with the License.
  9130. * You may obtain a copy of the License at
  9131. *
  9132. * http://www.apache.org/licenses/LICENSE-2.0
  9133. *
  9134. * Unless required by applicable law or agreed to in writing, software
  9135. * distributed under the License is distributed on an "AS IS" BASIS,
  9136. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9137. * See the License for the specific language governing permissions and
  9138. * limitations under the License.
  9139. */
  9140. var scrollSetting = {
  9141. "": true,
  9142. "up": true
  9143. };
  9144. function findScrollSetting(value) {
  9145. if (typeof value !== "string") {
  9146. return false;
  9147. }
  9148. var scroll = scrollSetting[value.toLowerCase()];
  9149. return scroll ? value.toLowerCase() : false;
  9150. }
  9151. function isValidPercentValue(value) {
  9152. return typeof value === "number" && value >= 0 && value <= 100;
  9153. } // VTTRegion shim http://dev.w3.org/html5/webvtt/#vttregion-interface
  9154. function VTTRegion() {
  9155. var _width = 100;
  9156. var _lines = 3;
  9157. var _regionAnchorX = 0;
  9158. var _regionAnchorY = 100;
  9159. var _viewportAnchorX = 0;
  9160. var _viewportAnchorY = 100;
  9161. var _scroll = "";
  9162. Object.defineProperties(this, {
  9163. "width": {
  9164. enumerable: true,
  9165. get: function get() {
  9166. return _width;
  9167. },
  9168. set: function set(value) {
  9169. if (!isValidPercentValue(value)) {
  9170. throw new Error("Width must be between 0 and 100.");
  9171. }
  9172. _width = value;
  9173. }
  9174. },
  9175. "lines": {
  9176. enumerable: true,
  9177. get: function get() {
  9178. return _lines;
  9179. },
  9180. set: function set(value) {
  9181. if (typeof value !== "number") {
  9182. throw new TypeError("Lines must be set to a number.");
  9183. }
  9184. _lines = value;
  9185. }
  9186. },
  9187. "regionAnchorY": {
  9188. enumerable: true,
  9189. get: function get() {
  9190. return _regionAnchorY;
  9191. },
  9192. set: function set(value) {
  9193. if (!isValidPercentValue(value)) {
  9194. throw new Error("RegionAnchorX must be between 0 and 100.");
  9195. }
  9196. _regionAnchorY = value;
  9197. }
  9198. },
  9199. "regionAnchorX": {
  9200. enumerable: true,
  9201. get: function get() {
  9202. return _regionAnchorX;
  9203. },
  9204. set: function set(value) {
  9205. if (!isValidPercentValue(value)) {
  9206. throw new Error("RegionAnchorY must be between 0 and 100.");
  9207. }
  9208. _regionAnchorX = value;
  9209. }
  9210. },
  9211. "viewportAnchorY": {
  9212. enumerable: true,
  9213. get: function get() {
  9214. return _viewportAnchorY;
  9215. },
  9216. set: function set(value) {
  9217. if (!isValidPercentValue(value)) {
  9218. throw new Error("ViewportAnchorY must be between 0 and 100.");
  9219. }
  9220. _viewportAnchorY = value;
  9221. }
  9222. },
  9223. "viewportAnchorX": {
  9224. enumerable: true,
  9225. get: function get() {
  9226. return _viewportAnchorX;
  9227. },
  9228. set: function set(value) {
  9229. if (!isValidPercentValue(value)) {
  9230. throw new Error("ViewportAnchorX must be between 0 and 100.");
  9231. }
  9232. _viewportAnchorX = value;
  9233. }
  9234. },
  9235. "scroll": {
  9236. enumerable: true,
  9237. get: function get() {
  9238. return _scroll;
  9239. },
  9240. set: function set(value) {
  9241. var setting = findScrollSetting(value); // Have to check for false as an empty string is a legal value.
  9242. if (setting === false) {
  9243. console.warn("Scroll: an invalid or illegal string was specified.");
  9244. } else {
  9245. _scroll = setting;
  9246. }
  9247. }
  9248. }
  9249. });
  9250. }
  9251. var vttregion = VTTRegion;
  9252. var browserIndex = createCommonjsModule(function (module) {
  9253. /**
  9254. * Copyright 2013 vtt.js Contributors
  9255. *
  9256. * Licensed under the Apache License, Version 2.0 (the "License");
  9257. * you may not use this file except in compliance with the License.
  9258. * You may obtain a copy of the License at
  9259. *
  9260. * http://www.apache.org/licenses/LICENSE-2.0
  9261. *
  9262. * Unless required by applicable law or agreed to in writing, software
  9263. * distributed under the License is distributed on an "AS IS" BASIS,
  9264. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9265. * See the License for the specific language governing permissions and
  9266. * limitations under the License.
  9267. */
  9268. // Default exports for Node. Export the extended versions of VTTCue and
  9269. // VTTRegion in Node since we likely want the capability to convert back and
  9270. // forth between JSON. If we don't then it's not that big of a deal since we're
  9271. // off browser.
  9272. var vttjs = module.exports = {
  9273. WebVTT: vtt,
  9274. VTTCue: vttcue,
  9275. VTTRegion: vttregion
  9276. };
  9277. window_1.vttjs = vttjs;
  9278. window_1.WebVTT = vttjs.WebVTT;
  9279. var cueShim = vttjs.VTTCue;
  9280. var regionShim = vttjs.VTTRegion;
  9281. var nativeVTTCue = window_1.VTTCue;
  9282. var nativeVTTRegion = window_1.VTTRegion;
  9283. vttjs.shim = function () {
  9284. window_1.VTTCue = cueShim;
  9285. window_1.VTTRegion = regionShim;
  9286. };
  9287. vttjs.restore = function () {
  9288. window_1.VTTCue = nativeVTTCue;
  9289. window_1.VTTRegion = nativeVTTRegion;
  9290. };
  9291. if (!window_1.VTTCue) {
  9292. vttjs.shim();
  9293. }
  9294. });
  9295. browserIndex.WebVTT;
  9296. browserIndex.VTTCue;
  9297. browserIndex.VTTRegion;
  9298. /**
  9299. * An Object containing a structure like: `{src: 'url', type: 'mimetype'}` or string
  9300. * that just contains the src url alone.
  9301. * * `var SourceObject = {src: 'http://ex.com/video.mp4', type: 'video/mp4'};`
  9302. * `var SourceString = 'http://example.com/some-video.mp4';`
  9303. *
  9304. * @typedef {Object|string} Tech~SourceObject
  9305. *
  9306. * @property {string} src
  9307. * The url to the source
  9308. *
  9309. * @property {string} type
  9310. * The mime type of the source
  9311. */
  9312. /**
  9313. * A function used by {@link Tech} to create a new {@link TextTrack}.
  9314. *
  9315. * @private
  9316. *
  9317. * @param {Tech} self
  9318. * An instance of the Tech class.
  9319. *
  9320. * @param {string} kind
  9321. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  9322. *
  9323. * @param {string} [label]
  9324. * Label to identify the text track
  9325. *
  9326. * @param {string} [language]
  9327. * Two letter language abbreviation
  9328. *
  9329. * @param {Object} [options={}]
  9330. * An object with additional text track options
  9331. *
  9332. * @return {TextTrack}
  9333. * The text track that was created.
  9334. */
  9335. function createTrackHelper(self, kind, label, language, options) {
  9336. if (options === void 0) {
  9337. options = {};
  9338. }
  9339. var tracks = self.textTracks();
  9340. options.kind = kind;
  9341. if (label) {
  9342. options.label = label;
  9343. }
  9344. if (language) {
  9345. options.language = language;
  9346. }
  9347. options.tech = self;
  9348. var track = new ALL.text.TrackClass(options);
  9349. tracks.addTrack(track);
  9350. return track;
  9351. }
  9352. /**
  9353. * This is the base class for media playback technology controllers, such as
  9354. * {@link HTML5}
  9355. *
  9356. * @extends Component
  9357. */
  9358. var Tech = /*#__PURE__*/function (_Component) {
  9359. inheritsLoose(Tech, _Component);
  9360. /**
  9361. * Create an instance of this Tech.
  9362. *
  9363. * @param {Object} [options]
  9364. * The key/value store of player options.
  9365. *
  9366. * @param {Component~ReadyCallback} ready
  9367. * Callback function to call when the `HTML5` Tech is ready.
  9368. */
  9369. function Tech(options, ready) {
  9370. var _this;
  9371. if (options === void 0) {
  9372. options = {};
  9373. }
  9374. if (ready === void 0) {
  9375. ready = function ready() {};
  9376. }
  9377. // we don't want the tech to report user activity automatically.
  9378. // This is done manually in addControlsListeners
  9379. options.reportTouchActivity = false;
  9380. _this = _Component.call(this, null, options, ready) || this;
  9381. _this.onDurationChange_ = function (e) {
  9382. return _this.onDurationChange(e);
  9383. };
  9384. _this.trackProgress_ = function (e) {
  9385. return _this.trackProgress(e);
  9386. };
  9387. _this.trackCurrentTime_ = function (e) {
  9388. return _this.trackCurrentTime(e);
  9389. };
  9390. _this.stopTrackingCurrentTime_ = function (e) {
  9391. return _this.stopTrackingCurrentTime(e);
  9392. };
  9393. _this.disposeSourceHandler_ = function (e) {
  9394. return _this.disposeSourceHandler(e);
  9395. };
  9396. _this.queuedHanders_ = new Set(); // keep track of whether the current source has played at all to
  9397. // implement a very limited played()
  9398. _this.hasStarted_ = false;
  9399. _this.on('playing', function () {
  9400. this.hasStarted_ = true;
  9401. });
  9402. _this.on('loadstart', function () {
  9403. this.hasStarted_ = false;
  9404. });
  9405. ALL.names.forEach(function (name) {
  9406. var props = ALL[name];
  9407. if (options && options[props.getterName]) {
  9408. _this[props.privateName] = options[props.getterName];
  9409. }
  9410. }); // Manually track progress in cases where the browser/tech doesn't report it.
  9411. if (!_this.featuresProgressEvents) {
  9412. _this.manualProgressOn();
  9413. } // Manually track timeupdates in cases where the browser/tech doesn't report it.
  9414. if (!_this.featuresTimeupdateEvents) {
  9415. _this.manualTimeUpdatesOn();
  9416. }
  9417. ['Text', 'Audio', 'Video'].forEach(function (track) {
  9418. if (options["native" + track + "Tracks"] === false) {
  9419. _this["featuresNative" + track + "Tracks"] = false;
  9420. }
  9421. });
  9422. if (options.nativeCaptions === false || options.nativeTextTracks === false) {
  9423. _this.featuresNativeTextTracks = false;
  9424. } else if (options.nativeCaptions === true || options.nativeTextTracks === true) {
  9425. _this.featuresNativeTextTracks = true;
  9426. }
  9427. if (!_this.featuresNativeTextTracks) {
  9428. _this.emulateTextTracks();
  9429. }
  9430. _this.preloadTextTracks = options.preloadTextTracks !== false;
  9431. _this.autoRemoteTextTracks_ = new ALL.text.ListClass();
  9432. _this.initTrackListeners(); // Turn on component tap events only if not using native controls
  9433. if (!options.nativeControlsForTouch) {
  9434. _this.emitTapEvents();
  9435. }
  9436. if (_this.constructor) {
  9437. _this.name_ = _this.constructor.name || 'Unknown Tech';
  9438. }
  9439. return _this;
  9440. }
  9441. /**
  9442. * A special function to trigger source set in a way that will allow player
  9443. * to re-trigger if the player or tech are not ready yet.
  9444. *
  9445. * @fires Tech#sourceset
  9446. * @param {string} src The source string at the time of the source changing.
  9447. */
  9448. var _proto = Tech.prototype;
  9449. _proto.triggerSourceset = function triggerSourceset(src) {
  9450. var _this2 = this;
  9451. if (!this.isReady_) {
  9452. // on initial ready we have to trigger source set
  9453. // 1ms after ready so that player can watch for it.
  9454. this.one('ready', function () {
  9455. return _this2.setTimeout(function () {
  9456. return _this2.triggerSourceset(src);
  9457. }, 1);
  9458. });
  9459. }
  9460. /**
  9461. * Fired when the source is set on the tech causing the media element
  9462. * to reload.
  9463. *
  9464. * @see {@link Player#event:sourceset}
  9465. * @event Tech#sourceset
  9466. * @type {EventTarget~Event}
  9467. */
  9468. this.trigger({
  9469. src: src,
  9470. type: 'sourceset'
  9471. });
  9472. }
  9473. /* Fallbacks for unsupported event types
  9474. ================================================================================ */
  9475. /**
  9476. * Polyfill the `progress` event for browsers that don't support it natively.
  9477. *
  9478. * @see {@link Tech#trackProgress}
  9479. */
  9480. ;
  9481. _proto.manualProgressOn = function manualProgressOn() {
  9482. this.on('durationchange', this.onDurationChange_);
  9483. this.manualProgress = true; // Trigger progress watching when a source begins loading
  9484. this.one('ready', this.trackProgress_);
  9485. }
  9486. /**
  9487. * Turn off the polyfill for `progress` events that was created in
  9488. * {@link Tech#manualProgressOn}
  9489. */
  9490. ;
  9491. _proto.manualProgressOff = function manualProgressOff() {
  9492. this.manualProgress = false;
  9493. this.stopTrackingProgress();
  9494. this.off('durationchange', this.onDurationChange_);
  9495. }
  9496. /**
  9497. * This is used to trigger a `progress` event when the buffered percent changes. It
  9498. * sets an interval function that will be called every 500 milliseconds to check if the
  9499. * buffer end percent has changed.
  9500. *
  9501. * > This function is called by {@link Tech#manualProgressOn}
  9502. *
  9503. * @param {EventTarget~Event} event
  9504. * The `ready` event that caused this to run.
  9505. *
  9506. * @listens Tech#ready
  9507. * @fires Tech#progress
  9508. */
  9509. ;
  9510. _proto.trackProgress = function trackProgress(event) {
  9511. this.stopTrackingProgress();
  9512. this.progressInterval = this.setInterval(bind(this, function () {
  9513. // Don't trigger unless buffered amount is greater than last time
  9514. var numBufferedPercent = this.bufferedPercent();
  9515. if (this.bufferedPercent_ !== numBufferedPercent) {
  9516. /**
  9517. * See {@link Player#progress}
  9518. *
  9519. * @event Tech#progress
  9520. * @type {EventTarget~Event}
  9521. */
  9522. this.trigger('progress');
  9523. }
  9524. this.bufferedPercent_ = numBufferedPercent;
  9525. if (numBufferedPercent === 1) {
  9526. this.stopTrackingProgress();
  9527. }
  9528. }), 500);
  9529. }
  9530. /**
  9531. * Update our internal duration on a `durationchange` event by calling
  9532. * {@link Tech#duration}.
  9533. *
  9534. * @param {EventTarget~Event} event
  9535. * The `durationchange` event that caused this to run.
  9536. *
  9537. * @listens Tech#durationchange
  9538. */
  9539. ;
  9540. _proto.onDurationChange = function onDurationChange(event) {
  9541. this.duration_ = this.duration();
  9542. }
  9543. /**
  9544. * Get and create a `TimeRange` object for buffering.
  9545. *
  9546. * @return {TimeRange}
  9547. * The time range object that was created.
  9548. */
  9549. ;
  9550. _proto.buffered = function buffered() {
  9551. return createTimeRanges(0, 0);
  9552. }
  9553. /**
  9554. * Get the percentage of the current video that is currently buffered.
  9555. *
  9556. * @return {number}
  9557. * A number from 0 to 1 that represents the decimal percentage of the
  9558. * video that is buffered.
  9559. *
  9560. */
  9561. ;
  9562. _proto.bufferedPercent = function bufferedPercent$1() {
  9563. return bufferedPercent(this.buffered(), this.duration_);
  9564. }
  9565. /**
  9566. * Turn off the polyfill for `progress` events that was created in
  9567. * {@link Tech#manualProgressOn}
  9568. * Stop manually tracking progress events by clearing the interval that was set in
  9569. * {@link Tech#trackProgress}.
  9570. */
  9571. ;
  9572. _proto.stopTrackingProgress = function stopTrackingProgress() {
  9573. this.clearInterval(this.progressInterval);
  9574. }
  9575. /**
  9576. * Polyfill the `timeupdate` event for browsers that don't support it.
  9577. *
  9578. * @see {@link Tech#trackCurrentTime}
  9579. */
  9580. ;
  9581. _proto.manualTimeUpdatesOn = function manualTimeUpdatesOn() {
  9582. this.manualTimeUpdates = true;
  9583. this.on('play', this.trackCurrentTime_);
  9584. this.on('pause', this.stopTrackingCurrentTime_);
  9585. }
  9586. /**
  9587. * Turn off the polyfill for `timeupdate` events that was created in
  9588. * {@link Tech#manualTimeUpdatesOn}
  9589. */
  9590. ;
  9591. _proto.manualTimeUpdatesOff = function manualTimeUpdatesOff() {
  9592. this.manualTimeUpdates = false;
  9593. this.stopTrackingCurrentTime();
  9594. this.off('play', this.trackCurrentTime_);
  9595. this.off('pause', this.stopTrackingCurrentTime_);
  9596. }
  9597. /**
  9598. * Sets up an interval function to track current time and trigger `timeupdate` every
  9599. * 250 milliseconds.
  9600. *
  9601. * @listens Tech#play
  9602. * @triggers Tech#timeupdate
  9603. */
  9604. ;
  9605. _proto.trackCurrentTime = function trackCurrentTime() {
  9606. if (this.currentTimeInterval) {
  9607. this.stopTrackingCurrentTime();
  9608. }
  9609. this.currentTimeInterval = this.setInterval(function () {
  9610. /**
  9611. * Triggered at an interval of 250ms to indicated that time is passing in the video.
  9612. *
  9613. * @event Tech#timeupdate
  9614. * @type {EventTarget~Event}
  9615. */
  9616. this.trigger({
  9617. type: 'timeupdate',
  9618. target: this,
  9619. manuallyTriggered: true
  9620. }); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
  9621. }, 250);
  9622. }
  9623. /**
  9624. * Stop the interval function created in {@link Tech#trackCurrentTime} so that the
  9625. * `timeupdate` event is no longer triggered.
  9626. *
  9627. * @listens {Tech#pause}
  9628. */
  9629. ;
  9630. _proto.stopTrackingCurrentTime = function stopTrackingCurrentTime() {
  9631. this.clearInterval(this.currentTimeInterval); // #1002 - if the video ends right before the next timeupdate would happen,
  9632. // the progress bar won't make it all the way to the end
  9633. this.trigger({
  9634. type: 'timeupdate',
  9635. target: this,
  9636. manuallyTriggered: true
  9637. });
  9638. }
  9639. /**
  9640. * Turn off all event polyfills, clear the `Tech`s {@link AudioTrackList},
  9641. * {@link VideoTrackList}, and {@link TextTrackList}, and dispose of this Tech.
  9642. *
  9643. * @fires Component#dispose
  9644. */
  9645. ;
  9646. _proto.dispose = function dispose() {
  9647. // clear out all tracks because we can't reuse them between techs
  9648. this.clearTracks(NORMAL.names); // Turn off any manual progress or timeupdate tracking
  9649. if (this.manualProgress) {
  9650. this.manualProgressOff();
  9651. }
  9652. if (this.manualTimeUpdates) {
  9653. this.manualTimeUpdatesOff();
  9654. }
  9655. _Component.prototype.dispose.call(this);
  9656. }
  9657. /**
  9658. * Clear out a single `TrackList` or an array of `TrackLists` given their names.
  9659. *
  9660. * > Note: Techs without source handlers should call this between sources for `video`
  9661. * & `audio` tracks. You don't want to use them between tracks!
  9662. *
  9663. * @param {string[]|string} types
  9664. * TrackList names to clear, valid names are `video`, `audio`, and
  9665. * `text`.
  9666. */
  9667. ;
  9668. _proto.clearTracks = function clearTracks(types) {
  9669. var _this3 = this;
  9670. types = [].concat(types); // clear out all tracks because we can't reuse them between techs
  9671. types.forEach(function (type) {
  9672. var list = _this3[type + "Tracks"]() || [];
  9673. var i = list.length;
  9674. while (i--) {
  9675. var track = list[i];
  9676. if (type === 'text') {
  9677. _this3.removeRemoteTextTrack(track);
  9678. }
  9679. list.removeTrack(track);
  9680. }
  9681. });
  9682. }
  9683. /**
  9684. * Remove any TextTracks added via addRemoteTextTrack that are
  9685. * flagged for automatic garbage collection
  9686. */
  9687. ;
  9688. _proto.cleanupAutoTextTracks = function cleanupAutoTextTracks() {
  9689. var list = this.autoRemoteTextTracks_ || [];
  9690. var i = list.length;
  9691. while (i--) {
  9692. var track = list[i];
  9693. this.removeRemoteTextTrack(track);
  9694. }
  9695. }
  9696. /**
  9697. * Reset the tech, which will removes all sources and reset the internal readyState.
  9698. *
  9699. * @abstract
  9700. */
  9701. ;
  9702. _proto.reset = function reset() {}
  9703. /**
  9704. * Get the value of `crossOrigin` from the tech.
  9705. *
  9706. * @abstract
  9707. *
  9708. * @see {Html5#crossOrigin}
  9709. */
  9710. ;
  9711. _proto.crossOrigin = function crossOrigin() {}
  9712. /**
  9713. * Set the value of `crossOrigin` on the tech.
  9714. *
  9715. * @abstract
  9716. *
  9717. * @param {string} crossOrigin the crossOrigin value
  9718. * @see {Html5#setCrossOrigin}
  9719. */
  9720. ;
  9721. _proto.setCrossOrigin = function setCrossOrigin() {}
  9722. /**
  9723. * Get or set an error on the Tech.
  9724. *
  9725. * @param {MediaError} [err]
  9726. * Error to set on the Tech
  9727. *
  9728. * @return {MediaError|null}
  9729. * The current error object on the tech, or null if there isn't one.
  9730. */
  9731. ;
  9732. _proto.error = function error(err) {
  9733. if (err !== undefined) {
  9734. this.error_ = new MediaError(err);
  9735. this.trigger('error');
  9736. }
  9737. return this.error_;
  9738. }
  9739. /**
  9740. * Returns the `TimeRange`s that have been played through for the current source.
  9741. *
  9742. * > NOTE: This implementation is incomplete. It does not track the played `TimeRange`.
  9743. * It only checks whether the source has played at all or not.
  9744. *
  9745. * @return {TimeRange}
  9746. * - A single time range if this video has played
  9747. * - An empty set of ranges if not.
  9748. */
  9749. ;
  9750. _proto.played = function played() {
  9751. if (this.hasStarted_) {
  9752. return createTimeRanges(0, 0);
  9753. }
  9754. return createTimeRanges();
  9755. }
  9756. /**
  9757. * Start playback
  9758. *
  9759. * @abstract
  9760. *
  9761. * @see {Html5#play}
  9762. */
  9763. ;
  9764. _proto.play = function play() {}
  9765. /**
  9766. * Set whether we are scrubbing or not
  9767. *
  9768. * @abstract
  9769. *
  9770. * @see {Html5#setScrubbing}
  9771. */
  9772. ;
  9773. _proto.setScrubbing = function setScrubbing() {}
  9774. /**
  9775. * Get whether we are scrubbing or not
  9776. *
  9777. * @abstract
  9778. *
  9779. * @see {Html5#scrubbing}
  9780. */
  9781. ;
  9782. _proto.scrubbing = function scrubbing() {}
  9783. /**
  9784. * Causes a manual time update to occur if {@link Tech#manualTimeUpdatesOn} was
  9785. * previously called.
  9786. *
  9787. * @fires Tech#timeupdate
  9788. */
  9789. ;
  9790. _proto.setCurrentTime = function setCurrentTime() {
  9791. // improve the accuracy of manual timeupdates
  9792. if (this.manualTimeUpdates) {
  9793. /**
  9794. * A manual `timeupdate` event.
  9795. *
  9796. * @event Tech#timeupdate
  9797. * @type {EventTarget~Event}
  9798. */
  9799. this.trigger({
  9800. type: 'timeupdate',
  9801. target: this,
  9802. manuallyTriggered: true
  9803. });
  9804. }
  9805. }
  9806. /**
  9807. * Turn on listeners for {@link VideoTrackList}, {@link {AudioTrackList}, and
  9808. * {@link TextTrackList} events.
  9809. *
  9810. * This adds {@link EventTarget~EventListeners} for `addtrack`, and `removetrack`.
  9811. *
  9812. * @fires Tech#audiotrackchange
  9813. * @fires Tech#videotrackchange
  9814. * @fires Tech#texttrackchange
  9815. */
  9816. ;
  9817. _proto.initTrackListeners = function initTrackListeners() {
  9818. var _this4 = this;
  9819. /**
  9820. * Triggered when tracks are added or removed on the Tech {@link AudioTrackList}
  9821. *
  9822. * @event Tech#audiotrackchange
  9823. * @type {EventTarget~Event}
  9824. */
  9825. /**
  9826. * Triggered when tracks are added or removed on the Tech {@link VideoTrackList}
  9827. *
  9828. * @event Tech#videotrackchange
  9829. * @type {EventTarget~Event}
  9830. */
  9831. /**
  9832. * Triggered when tracks are added or removed on the Tech {@link TextTrackList}
  9833. *
  9834. * @event Tech#texttrackchange
  9835. * @type {EventTarget~Event}
  9836. */
  9837. NORMAL.names.forEach(function (name) {
  9838. var props = NORMAL[name];
  9839. var trackListChanges = function trackListChanges() {
  9840. _this4.trigger(name + "trackchange");
  9841. };
  9842. var tracks = _this4[props.getterName]();
  9843. tracks.addEventListener('removetrack', trackListChanges);
  9844. tracks.addEventListener('addtrack', trackListChanges);
  9845. _this4.on('dispose', function () {
  9846. tracks.removeEventListener('removetrack', trackListChanges);
  9847. tracks.removeEventListener('addtrack', trackListChanges);
  9848. });
  9849. });
  9850. }
  9851. /**
  9852. * Emulate TextTracks using vtt.js if necessary
  9853. *
  9854. * @fires Tech#vttjsloaded
  9855. * @fires Tech#vttjserror
  9856. */
  9857. ;
  9858. _proto.addWebVttScript_ = function addWebVttScript_() {
  9859. var _this5 = this;
  9860. if (window.WebVTT) {
  9861. return;
  9862. } // Initially, Tech.el_ is a child of a dummy-div wait until the Component system
  9863. // signals that the Tech is ready at which point Tech.el_ is part of the DOM
  9864. // before inserting the WebVTT script
  9865. if (document.body.contains(this.el())) {
  9866. // load via require if available and vtt.js script location was not passed in
  9867. // as an option. novtt builds will turn the above require call into an empty object
  9868. // which will cause this if check to always fail.
  9869. if (!this.options_['vtt.js'] && isPlain(browserIndex) && Object.keys(browserIndex).length > 0) {
  9870. this.trigger('vttjsloaded');
  9871. return;
  9872. } // load vtt.js via the script location option or the cdn of no location was
  9873. // passed in
  9874. var script = document.createElement('script');
  9875. script.src = this.options_['vtt.js'] || 'https://vjs.zencdn.net/vttjs/0.14.1/vtt.min.js';
  9876. script.onload = function () {
  9877. /**
  9878. * Fired when vtt.js is loaded.
  9879. *
  9880. * @event Tech#vttjsloaded
  9881. * @type {EventTarget~Event}
  9882. */
  9883. _this5.trigger('vttjsloaded');
  9884. };
  9885. script.onerror = function () {
  9886. /**
  9887. * Fired when vtt.js was not loaded due to an error
  9888. *
  9889. * @event Tech#vttjsloaded
  9890. * @type {EventTarget~Event}
  9891. */
  9892. _this5.trigger('vttjserror');
  9893. };
  9894. this.on('dispose', function () {
  9895. script.onload = null;
  9896. script.onerror = null;
  9897. }); // but have not loaded yet and we set it to true before the inject so that
  9898. // we don't overwrite the injected window.WebVTT if it loads right away
  9899. window.WebVTT = true;
  9900. this.el().parentNode.appendChild(script);
  9901. } else {
  9902. this.ready(this.addWebVttScript_);
  9903. }
  9904. }
  9905. /**
  9906. * Emulate texttracks
  9907. *
  9908. */
  9909. ;
  9910. _proto.emulateTextTracks = function emulateTextTracks() {
  9911. var _this6 = this;
  9912. var tracks = this.textTracks();
  9913. var remoteTracks = this.remoteTextTracks();
  9914. var handleAddTrack = function handleAddTrack(e) {
  9915. return tracks.addTrack(e.track);
  9916. };
  9917. var handleRemoveTrack = function handleRemoveTrack(e) {
  9918. return tracks.removeTrack(e.track);
  9919. };
  9920. remoteTracks.on('addtrack', handleAddTrack);
  9921. remoteTracks.on('removetrack', handleRemoveTrack);
  9922. this.addWebVttScript_();
  9923. var updateDisplay = function updateDisplay() {
  9924. return _this6.trigger('texttrackchange');
  9925. };
  9926. var textTracksChanges = function textTracksChanges() {
  9927. updateDisplay();
  9928. for (var i = 0; i < tracks.length; i++) {
  9929. var track = tracks[i];
  9930. track.removeEventListener('cuechange', updateDisplay);
  9931. if (track.mode === 'showing') {
  9932. track.addEventListener('cuechange', updateDisplay);
  9933. }
  9934. }
  9935. };
  9936. textTracksChanges();
  9937. tracks.addEventListener('change', textTracksChanges);
  9938. tracks.addEventListener('addtrack', textTracksChanges);
  9939. tracks.addEventListener('removetrack', textTracksChanges);
  9940. this.on('dispose', function () {
  9941. remoteTracks.off('addtrack', handleAddTrack);
  9942. remoteTracks.off('removetrack', handleRemoveTrack);
  9943. tracks.removeEventListener('change', textTracksChanges);
  9944. tracks.removeEventListener('addtrack', textTracksChanges);
  9945. tracks.removeEventListener('removetrack', textTracksChanges);
  9946. for (var i = 0; i < tracks.length; i++) {
  9947. var track = tracks[i];
  9948. track.removeEventListener('cuechange', updateDisplay);
  9949. }
  9950. });
  9951. }
  9952. /**
  9953. * Create and returns a remote {@link TextTrack} object.
  9954. *
  9955. * @param {string} kind
  9956. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  9957. *
  9958. * @param {string} [label]
  9959. * Label to identify the text track
  9960. *
  9961. * @param {string} [language]
  9962. * Two letter language abbreviation
  9963. *
  9964. * @return {TextTrack}
  9965. * The TextTrack that gets created.
  9966. */
  9967. ;
  9968. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  9969. if (!kind) {
  9970. throw new Error('TextTrack kind is required but was not provided');
  9971. }
  9972. return createTrackHelper(this, kind, label, language);
  9973. }
  9974. /**
  9975. * Create an emulated TextTrack for use by addRemoteTextTrack
  9976. *
  9977. * This is intended to be overridden by classes that inherit from
  9978. * Tech in order to create native or custom TextTracks.
  9979. *
  9980. * @param {Object} options
  9981. * The object should contain the options to initialize the TextTrack with.
  9982. *
  9983. * @param {string} [options.kind]
  9984. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  9985. *
  9986. * @param {string} [options.label].
  9987. * Label to identify the text track
  9988. *
  9989. * @param {string} [options.language]
  9990. * Two letter language abbreviation.
  9991. *
  9992. * @return {HTMLTrackElement}
  9993. * The track element that gets created.
  9994. */
  9995. ;
  9996. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  9997. var track = mergeOptions(options, {
  9998. tech: this
  9999. });
  10000. return new REMOTE.remoteTextEl.TrackClass(track);
  10001. }
  10002. /**
  10003. * Creates a remote text track object and returns an html track element.
  10004. *
  10005. * > Note: This can be an emulated {@link HTMLTrackElement} or a native one.
  10006. *
  10007. * @param {Object} options
  10008. * See {@link Tech#createRemoteTextTrack} for more detailed properties.
  10009. *
  10010. * @param {boolean} [manualCleanup=true]
  10011. * - When false: the TextTrack will be automatically removed from the video
  10012. * element whenever the source changes
  10013. * - When True: The TextTrack will have to be cleaned up manually
  10014. *
  10015. * @return {HTMLTrackElement}
  10016. * An Html Track Element.
  10017. *
  10018. * @deprecated The default functionality for this function will be equivalent
  10019. * to "manualCleanup=false" in the future. The manualCleanup parameter will
  10020. * also be removed.
  10021. */
  10022. ;
  10023. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  10024. var _this7 = this;
  10025. if (options === void 0) {
  10026. options = {};
  10027. }
  10028. var htmlTrackElement = this.createRemoteTextTrack(options);
  10029. if (manualCleanup !== true && manualCleanup !== false) {
  10030. // deprecation warning
  10031. log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js');
  10032. manualCleanup = true;
  10033. } // store HTMLTrackElement and TextTrack to remote list
  10034. this.remoteTextTrackEls().addTrackElement_(htmlTrackElement);
  10035. this.remoteTextTracks().addTrack(htmlTrackElement.track);
  10036. if (manualCleanup !== true) {
  10037. // create the TextTrackList if it doesn't exist
  10038. this.ready(function () {
  10039. return _this7.autoRemoteTextTracks_.addTrack(htmlTrackElement.track);
  10040. });
  10041. }
  10042. return htmlTrackElement;
  10043. }
  10044. /**
  10045. * Remove a remote text track from the remote `TextTrackList`.
  10046. *
  10047. * @param {TextTrack} track
  10048. * `TextTrack` to remove from the `TextTrackList`
  10049. */
  10050. ;
  10051. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  10052. var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track); // remove HTMLTrackElement and TextTrack from remote list
  10053. this.remoteTextTrackEls().removeTrackElement_(trackElement);
  10054. this.remoteTextTracks().removeTrack(track);
  10055. this.autoRemoteTextTracks_.removeTrack(track);
  10056. }
  10057. /**
  10058. * Gets available media playback quality metrics as specified by the W3C's Media
  10059. * Playback Quality API.
  10060. *
  10061. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  10062. *
  10063. * @return {Object}
  10064. * An object with supported media playback quality metrics
  10065. *
  10066. * @abstract
  10067. */
  10068. ;
  10069. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  10070. return {};
  10071. }
  10072. /**
  10073. * Attempt to create a floating video window always on top of other windows
  10074. * so that users may continue consuming media while they interact with other
  10075. * content sites, or applications on their device.
  10076. *
  10077. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  10078. *
  10079. * @return {Promise|undefined}
  10080. * A promise with a Picture-in-Picture window if the browser supports
  10081. * Promises (or one was passed in as an option). It returns undefined
  10082. * otherwise.
  10083. *
  10084. * @abstract
  10085. */
  10086. ;
  10087. _proto.requestPictureInPicture = function requestPictureInPicture() {
  10088. var PromiseClass = this.options_.Promise || window.Promise;
  10089. if (PromiseClass) {
  10090. return PromiseClass.reject();
  10091. }
  10092. }
  10093. /**
  10094. * A method to check for the value of the 'disablePictureInPicture' <video> property.
  10095. * Defaults to true, as it should be considered disabled if the tech does not support pip
  10096. *
  10097. * @abstract
  10098. */
  10099. ;
  10100. _proto.disablePictureInPicture = function disablePictureInPicture() {
  10101. return true;
  10102. }
  10103. /**
  10104. * A method to set or unset the 'disablePictureInPicture' <video> property.
  10105. *
  10106. * @abstract
  10107. */
  10108. ;
  10109. _proto.setDisablePictureInPicture = function setDisablePictureInPicture() {}
  10110. /**
  10111. * A fallback implementation of requestVideoFrameCallback using requestAnimationFrame
  10112. *
  10113. * @param {function} cb
  10114. * @return {number} request id
  10115. */
  10116. ;
  10117. _proto.requestVideoFrameCallback = function requestVideoFrameCallback(cb) {
  10118. var _this8 = this;
  10119. var id = newGUID();
  10120. if (!this.isReady_ || this.paused()) {
  10121. this.queuedHanders_.add(id);
  10122. this.one('playing', function () {
  10123. if (_this8.queuedHanders_.has(id)) {
  10124. _this8.queuedHanders_["delete"](id);
  10125. cb();
  10126. }
  10127. });
  10128. } else {
  10129. this.requestNamedAnimationFrame(id, cb);
  10130. }
  10131. return id;
  10132. }
  10133. /**
  10134. * A fallback implementation of cancelVideoFrameCallback
  10135. *
  10136. * @param {number} id id of callback to be cancelled
  10137. */
  10138. ;
  10139. _proto.cancelVideoFrameCallback = function cancelVideoFrameCallback(id) {
  10140. if (this.queuedHanders_.has(id)) {
  10141. this.queuedHanders_["delete"](id);
  10142. } else {
  10143. this.cancelNamedAnimationFrame(id);
  10144. }
  10145. }
  10146. /**
  10147. * A method to set a poster from a `Tech`.
  10148. *
  10149. * @abstract
  10150. */
  10151. ;
  10152. _proto.setPoster = function setPoster() {}
  10153. /**
  10154. * A method to check for the presence of the 'playsinline' <video> attribute.
  10155. *
  10156. * @abstract
  10157. */
  10158. ;
  10159. _proto.playsinline = function playsinline() {}
  10160. /**
  10161. * A method to set or unset the 'playsinline' <video> attribute.
  10162. *
  10163. * @abstract
  10164. */
  10165. ;
  10166. _proto.setPlaysinline = function setPlaysinline() {}
  10167. /**
  10168. * Attempt to force override of native audio tracks.
  10169. *
  10170. * @param {boolean} override - If set to true native audio will be overridden,
  10171. * otherwise native audio will potentially be used.
  10172. *
  10173. * @abstract
  10174. */
  10175. ;
  10176. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks() {}
  10177. /**
  10178. * Attempt to force override of native video tracks.
  10179. *
  10180. * @param {boolean} override - If set to true native video will be overridden,
  10181. * otherwise native video will potentially be used.
  10182. *
  10183. * @abstract
  10184. */
  10185. ;
  10186. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks() {}
  10187. /*
  10188. * Check if the tech can support the given mime-type.
  10189. *
  10190. * The base tech does not support any type, but source handlers might
  10191. * overwrite this.
  10192. *
  10193. * @param {string} type
  10194. * The mimetype to check for support
  10195. *
  10196. * @return {string}
  10197. * 'probably', 'maybe', or empty string
  10198. *
  10199. * @see [Spec]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType}
  10200. *
  10201. * @abstract
  10202. */
  10203. ;
  10204. _proto.canPlayType = function canPlayType() {
  10205. return '';
  10206. }
  10207. /**
  10208. * Check if the type is supported by this tech.
  10209. *
  10210. * The base tech does not support any type, but source handlers might
  10211. * overwrite this.
  10212. *
  10213. * @param {string} type
  10214. * The media type to check
  10215. * @return {string} Returns the native video element's response
  10216. */
  10217. ;
  10218. Tech.canPlayType = function canPlayType() {
  10219. return '';
  10220. }
  10221. /**
  10222. * Check if the tech can support the given source
  10223. *
  10224. * @param {Object} srcObj
  10225. * The source object
  10226. * @param {Object} options
  10227. * The options passed to the tech
  10228. * @return {string} 'probably', 'maybe', or '' (empty string)
  10229. */
  10230. ;
  10231. Tech.canPlaySource = function canPlaySource(srcObj, options) {
  10232. return Tech.canPlayType(srcObj.type);
  10233. }
  10234. /*
  10235. * Return whether the argument is a Tech or not.
  10236. * Can be passed either a Class like `Html5` or a instance like `player.tech_`
  10237. *
  10238. * @param {Object} component
  10239. * The item to check
  10240. *
  10241. * @return {boolean}
  10242. * Whether it is a tech or not
  10243. * - True if it is a tech
  10244. * - False if it is not
  10245. */
  10246. ;
  10247. Tech.isTech = function isTech(component) {
  10248. return component.prototype instanceof Tech || component instanceof Tech || component === Tech;
  10249. }
  10250. /**
  10251. * Registers a `Tech` into a shared list for videojs.
  10252. *
  10253. * @param {string} name
  10254. * Name of the `Tech` to register.
  10255. *
  10256. * @param {Object} tech
  10257. * The `Tech` class to register.
  10258. */
  10259. ;
  10260. Tech.registerTech = function registerTech(name, tech) {
  10261. if (!Tech.techs_) {
  10262. Tech.techs_ = {};
  10263. }
  10264. if (!Tech.isTech(tech)) {
  10265. throw new Error("Tech " + name + " must be a Tech");
  10266. }
  10267. if (!Tech.canPlayType) {
  10268. throw new Error('Techs must have a static canPlayType method on them');
  10269. }
  10270. if (!Tech.canPlaySource) {
  10271. throw new Error('Techs must have a static canPlaySource method on them');
  10272. }
  10273. name = toTitleCase(name);
  10274. Tech.techs_[name] = tech;
  10275. Tech.techs_[toLowerCase(name)] = tech;
  10276. if (name !== 'Tech') {
  10277. // camel case the techName for use in techOrder
  10278. Tech.defaultTechOrder_.push(name);
  10279. }
  10280. return tech;
  10281. }
  10282. /**
  10283. * Get a `Tech` from the shared list by name.
  10284. *
  10285. * @param {string} name
  10286. * `camelCase` or `TitleCase` name of the Tech to get
  10287. *
  10288. * @return {Tech|undefined}
  10289. * The `Tech` or undefined if there was no tech with the name requested.
  10290. */
  10291. ;
  10292. Tech.getTech = function getTech(name) {
  10293. if (!name) {
  10294. return;
  10295. }
  10296. if (Tech.techs_ && Tech.techs_[name]) {
  10297. return Tech.techs_[name];
  10298. }
  10299. name = toTitleCase(name);
  10300. if (window && window.videojs && window.videojs[name]) {
  10301. log.warn("The " + name + " tech was added to the videojs object when it should be registered using videojs.registerTech(name, tech)");
  10302. return window.videojs[name];
  10303. }
  10304. };
  10305. return Tech;
  10306. }(Component);
  10307. /**
  10308. * Get the {@link VideoTrackList}
  10309. *
  10310. * @returns {VideoTrackList}
  10311. * @method Tech.prototype.videoTracks
  10312. */
  10313. /**
  10314. * Get the {@link AudioTrackList}
  10315. *
  10316. * @returns {AudioTrackList}
  10317. * @method Tech.prototype.audioTracks
  10318. */
  10319. /**
  10320. * Get the {@link TextTrackList}
  10321. *
  10322. * @returns {TextTrackList}
  10323. * @method Tech.prototype.textTracks
  10324. */
  10325. /**
  10326. * Get the remote element {@link TextTrackList}
  10327. *
  10328. * @returns {TextTrackList}
  10329. * @method Tech.prototype.remoteTextTracks
  10330. */
  10331. /**
  10332. * Get the remote element {@link HtmlTrackElementList}
  10333. *
  10334. * @returns {HtmlTrackElementList}
  10335. * @method Tech.prototype.remoteTextTrackEls
  10336. */
  10337. ALL.names.forEach(function (name) {
  10338. var props = ALL[name];
  10339. Tech.prototype[props.getterName] = function () {
  10340. this[props.privateName] = this[props.privateName] || new props.ListClass();
  10341. return this[props.privateName];
  10342. };
  10343. });
  10344. /**
  10345. * List of associated text tracks
  10346. *
  10347. * @type {TextTrackList}
  10348. * @private
  10349. * @property Tech#textTracks_
  10350. */
  10351. /**
  10352. * List of associated audio tracks.
  10353. *
  10354. * @type {AudioTrackList}
  10355. * @private
  10356. * @property Tech#audioTracks_
  10357. */
  10358. /**
  10359. * List of associated video tracks.
  10360. *
  10361. * @type {VideoTrackList}
  10362. * @private
  10363. * @property Tech#videoTracks_
  10364. */
  10365. /**
  10366. * Boolean indicating whether the `Tech` supports volume control.
  10367. *
  10368. * @type {boolean}
  10369. * @default
  10370. */
  10371. Tech.prototype.featuresVolumeControl = true;
  10372. /**
  10373. * Boolean indicating whether the `Tech` supports muting volume.
  10374. *
  10375. * @type {bolean}
  10376. * @default
  10377. */
  10378. Tech.prototype.featuresMuteControl = true;
  10379. /**
  10380. * Boolean indicating whether the `Tech` supports fullscreen resize control.
  10381. * Resizing plugins using request fullscreen reloads the plugin
  10382. *
  10383. * @type {boolean}
  10384. * @default
  10385. */
  10386. Tech.prototype.featuresFullscreenResize = false;
  10387. /**
  10388. * Boolean indicating whether the `Tech` supports changing the speed at which the video
  10389. * plays. Examples:
  10390. * - Set player to play 2x (twice) as fast
  10391. * - Set player to play 0.5x (half) as fast
  10392. *
  10393. * @type {boolean}
  10394. * @default
  10395. */
  10396. Tech.prototype.featuresPlaybackRate = false;
  10397. /**
  10398. * Boolean indicating whether the `Tech` supports the `progress` event. This is currently
  10399. * not triggered by video-js-swf. This will be used to determine if
  10400. * {@link Tech#manualProgressOn} should be called.
  10401. *
  10402. * @type {boolean}
  10403. * @default
  10404. */
  10405. Tech.prototype.featuresProgressEvents = false;
  10406. /**
  10407. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  10408. *
  10409. * A tech should set this to `true` and then use {@link Tech#triggerSourceset}
  10410. * to trigger a {@link Tech#event:sourceset} at the earliest time after getting
  10411. * a new source.
  10412. *
  10413. * @type {boolean}
  10414. * @default
  10415. */
  10416. Tech.prototype.featuresSourceset = false;
  10417. /**
  10418. * Boolean indicating whether the `Tech` supports the `timeupdate` event. This is currently
  10419. * not triggered by video-js-swf. This will be used to determine if
  10420. * {@link Tech#manualTimeUpdates} should be called.
  10421. *
  10422. * @type {boolean}
  10423. * @default
  10424. */
  10425. Tech.prototype.featuresTimeupdateEvents = false;
  10426. /**
  10427. * Boolean indicating whether the `Tech` supports the native `TextTrack`s.
  10428. * This will help us integrate with native `TextTrack`s if the browser supports them.
  10429. *
  10430. * @type {boolean}
  10431. * @default
  10432. */
  10433. Tech.prototype.featuresNativeTextTracks = false;
  10434. /**
  10435. * Boolean indicating whether the `Tech` supports `requestVideoFrameCallback`.
  10436. *
  10437. * @type {boolean}
  10438. * @default
  10439. */
  10440. Tech.prototype.featuresVideoFrameCallback = false;
  10441. /**
  10442. * A functional mixin for techs that want to use the Source Handler pattern.
  10443. * Source handlers are scripts for handling specific formats.
  10444. * The source handler pattern is used for adaptive formats (HLS, DASH) that
  10445. * manually load video data and feed it into a Source Buffer (Media Source Extensions)
  10446. * Example: `Tech.withSourceHandlers.call(MyTech);`
  10447. *
  10448. * @param {Tech} _Tech
  10449. * The tech to add source handler functions to.
  10450. *
  10451. * @mixes Tech~SourceHandlerAdditions
  10452. */
  10453. Tech.withSourceHandlers = function (_Tech) {
  10454. /**
  10455. * Register a source handler
  10456. *
  10457. * @param {Function} handler
  10458. * The source handler class
  10459. *
  10460. * @param {number} [index]
  10461. * Register it at the following index
  10462. */
  10463. _Tech.registerSourceHandler = function (handler, index) {
  10464. var handlers = _Tech.sourceHandlers;
  10465. if (!handlers) {
  10466. handlers = _Tech.sourceHandlers = [];
  10467. }
  10468. if (index === undefined) {
  10469. // add to the end of the list
  10470. index = handlers.length;
  10471. }
  10472. handlers.splice(index, 0, handler);
  10473. };
  10474. /**
  10475. * Check if the tech can support the given type. Also checks the
  10476. * Techs sourceHandlers.
  10477. *
  10478. * @param {string} type
  10479. * The mimetype to check.
  10480. *
  10481. * @return {string}
  10482. * 'probably', 'maybe', or '' (empty string)
  10483. */
  10484. _Tech.canPlayType = function (type) {
  10485. var handlers = _Tech.sourceHandlers || [];
  10486. var can;
  10487. for (var i = 0; i < handlers.length; i++) {
  10488. can = handlers[i].canPlayType(type);
  10489. if (can) {
  10490. return can;
  10491. }
  10492. }
  10493. return '';
  10494. };
  10495. /**
  10496. * Returns the first source handler that supports the source.
  10497. *
  10498. * TODO: Answer question: should 'probably' be prioritized over 'maybe'
  10499. *
  10500. * @param {Tech~SourceObject} source
  10501. * The source object
  10502. *
  10503. * @param {Object} options
  10504. * The options passed to the tech
  10505. *
  10506. * @return {SourceHandler|null}
  10507. * The first source handler that supports the source or null if
  10508. * no SourceHandler supports the source
  10509. */
  10510. _Tech.selectSourceHandler = function (source, options) {
  10511. var handlers = _Tech.sourceHandlers || [];
  10512. var can;
  10513. for (var i = 0; i < handlers.length; i++) {
  10514. can = handlers[i].canHandleSource(source, options);
  10515. if (can) {
  10516. return handlers[i];
  10517. }
  10518. }
  10519. return null;
  10520. };
  10521. /**
  10522. * Check if the tech can support the given source.
  10523. *
  10524. * @param {Tech~SourceObject} srcObj
  10525. * The source object
  10526. *
  10527. * @param {Object} options
  10528. * The options passed to the tech
  10529. *
  10530. * @return {string}
  10531. * 'probably', 'maybe', or '' (empty string)
  10532. */
  10533. _Tech.canPlaySource = function (srcObj, options) {
  10534. var sh = _Tech.selectSourceHandler(srcObj, options);
  10535. if (sh) {
  10536. return sh.canHandleSource(srcObj, options);
  10537. }
  10538. return '';
  10539. };
  10540. /**
  10541. * When using a source handler, prefer its implementation of
  10542. * any function normally provided by the tech.
  10543. */
  10544. var deferrable = ['seekable', 'seeking', 'duration'];
  10545. /**
  10546. * A wrapper around {@link Tech#seekable} that will call a `SourceHandler`s seekable
  10547. * function if it exists, with a fallback to the Techs seekable function.
  10548. *
  10549. * @method _Tech.seekable
  10550. */
  10551. /**
  10552. * A wrapper around {@link Tech#duration} that will call a `SourceHandler`s duration
  10553. * function if it exists, otherwise it will fallback to the techs duration function.
  10554. *
  10555. * @method _Tech.duration
  10556. */
  10557. deferrable.forEach(function (fnName) {
  10558. var originalFn = this[fnName];
  10559. if (typeof originalFn !== 'function') {
  10560. return;
  10561. }
  10562. this[fnName] = function () {
  10563. if (this.sourceHandler_ && this.sourceHandler_[fnName]) {
  10564. return this.sourceHandler_[fnName].apply(this.sourceHandler_, arguments);
  10565. }
  10566. return originalFn.apply(this, arguments);
  10567. };
  10568. }, _Tech.prototype);
  10569. /**
  10570. * Create a function for setting the source using a source object
  10571. * and source handlers.
  10572. * Should never be called unless a source handler was found.
  10573. *
  10574. * @param {Tech~SourceObject} source
  10575. * A source object with src and type keys
  10576. */
  10577. _Tech.prototype.setSource = function (source) {
  10578. var sh = _Tech.selectSourceHandler(source, this.options_);
  10579. if (!sh) {
  10580. // Fall back to a native source hander when unsupported sources are
  10581. // deliberately set
  10582. if (_Tech.nativeSourceHandler) {
  10583. sh = _Tech.nativeSourceHandler;
  10584. } else {
  10585. log.error('No source handler found for the current source.');
  10586. }
  10587. } // Dispose any existing source handler
  10588. this.disposeSourceHandler();
  10589. this.off('dispose', this.disposeSourceHandler_);
  10590. if (sh !== _Tech.nativeSourceHandler) {
  10591. this.currentSource_ = source;
  10592. }
  10593. this.sourceHandler_ = sh.handleSource(source, this, this.options_);
  10594. this.one('dispose', this.disposeSourceHandler_);
  10595. };
  10596. /**
  10597. * Clean up any existing SourceHandlers and listeners when the Tech is disposed.
  10598. *
  10599. * @listens Tech#dispose
  10600. */
  10601. _Tech.prototype.disposeSourceHandler = function () {
  10602. // if we have a source and get another one
  10603. // then we are loading something new
  10604. // than clear all of our current tracks
  10605. if (this.currentSource_) {
  10606. this.clearTracks(['audio', 'video']);
  10607. this.currentSource_ = null;
  10608. } // always clean up auto-text tracks
  10609. this.cleanupAutoTextTracks();
  10610. if (this.sourceHandler_) {
  10611. if (this.sourceHandler_.dispose) {
  10612. this.sourceHandler_.dispose();
  10613. }
  10614. this.sourceHandler_ = null;
  10615. }
  10616. };
  10617. }; // The base Tech class needs to be registered as a Component. It is the only
  10618. // Tech that can be registered as a Component.
  10619. Component.registerComponent('Tech', Tech);
  10620. Tech.registerTech('Tech', Tech);
  10621. /**
  10622. * A list of techs that should be added to techOrder on Players
  10623. *
  10624. * @private
  10625. */
  10626. Tech.defaultTechOrder_ = [];
  10627. /**
  10628. * @file middleware.js
  10629. * @module middleware
  10630. */
  10631. var middlewares = {};
  10632. var middlewareInstances = {};
  10633. var TERMINATOR = {};
  10634. /**
  10635. * A middleware object is a plain JavaScript object that has methods that
  10636. * match the {@link Tech} methods found in the lists of allowed
  10637. * {@link module:middleware.allowedGetters|getters},
  10638. * {@link module:middleware.allowedSetters|setters}, and
  10639. * {@link module:middleware.allowedMediators|mediators}.
  10640. *
  10641. * @typedef {Object} MiddlewareObject
  10642. */
  10643. /**
  10644. * A middleware factory function that should return a
  10645. * {@link module:middleware~MiddlewareObject|MiddlewareObject}.
  10646. *
  10647. * This factory will be called for each player when needed, with the player
  10648. * passed in as an argument.
  10649. *
  10650. * @callback MiddlewareFactory
  10651. * @param {Player} player
  10652. * A Video.js player.
  10653. */
  10654. /**
  10655. * Define a middleware that the player should use by way of a factory function
  10656. * that returns a middleware object.
  10657. *
  10658. * @param {string} type
  10659. * The MIME type to match or `"*"` for all MIME types.
  10660. *
  10661. * @param {MiddlewareFactory} middleware
  10662. * A middleware factory function that will be executed for
  10663. * matching types.
  10664. */
  10665. function use(type, middleware) {
  10666. middlewares[type] = middlewares[type] || [];
  10667. middlewares[type].push(middleware);
  10668. }
  10669. /**
  10670. * Asynchronously sets a source using middleware by recursing through any
  10671. * matching middlewares and calling `setSource` on each, passing along the
  10672. * previous returned value each time.
  10673. *
  10674. * @param {Player} player
  10675. * A {@link Player} instance.
  10676. *
  10677. * @param {Tech~SourceObject} src
  10678. * A source object.
  10679. *
  10680. * @param {Function}
  10681. * The next middleware to run.
  10682. */
  10683. function setSource(player, src, next) {
  10684. player.setTimeout(function () {
  10685. return setSourceHelper(src, middlewares[src.type], next, player);
  10686. }, 1);
  10687. }
  10688. /**
  10689. * When the tech is set, passes the tech to each middleware's `setTech` method.
  10690. *
  10691. * @param {Object[]} middleware
  10692. * An array of middleware instances.
  10693. *
  10694. * @param {Tech} tech
  10695. * A Video.js tech.
  10696. */
  10697. function setTech(middleware, tech) {
  10698. middleware.forEach(function (mw) {
  10699. return mw.setTech && mw.setTech(tech);
  10700. });
  10701. }
  10702. /**
  10703. * Calls a getter on the tech first, through each middleware
  10704. * from right to left to the player.
  10705. *
  10706. * @param {Object[]} middleware
  10707. * An array of middleware instances.
  10708. *
  10709. * @param {Tech} tech
  10710. * The current tech.
  10711. *
  10712. * @param {string} method
  10713. * A method name.
  10714. *
  10715. * @return {Mixed}
  10716. * The final value from the tech after middleware has intercepted it.
  10717. */
  10718. function get(middleware, tech, method) {
  10719. return middleware.reduceRight(middlewareIterator(method), tech[method]());
  10720. }
  10721. /**
  10722. * Takes the argument given to the player and calls the setter method on each
  10723. * middleware from left to right to the tech.
  10724. *
  10725. * @param {Object[]} middleware
  10726. * An array of middleware instances.
  10727. *
  10728. * @param {Tech} tech
  10729. * The current tech.
  10730. *
  10731. * @param {string} method
  10732. * A method name.
  10733. *
  10734. * @param {Mixed} arg
  10735. * The value to set on the tech.
  10736. *
  10737. * @return {Mixed}
  10738. * The return value of the `method` of the `tech`.
  10739. */
  10740. function set(middleware, tech, method, arg) {
  10741. return tech[method](middleware.reduce(middlewareIterator(method), arg));
  10742. }
  10743. /**
  10744. * Takes the argument given to the player and calls the `call` version of the
  10745. * method on each middleware from left to right.
  10746. *
  10747. * Then, call the passed in method on the tech and return the result unchanged
  10748. * back to the player, through middleware, this time from right to left.
  10749. *
  10750. * @param {Object[]} middleware
  10751. * An array of middleware instances.
  10752. *
  10753. * @param {Tech} tech
  10754. * The current tech.
  10755. *
  10756. * @param {string} method
  10757. * A method name.
  10758. *
  10759. * @param {Mixed} arg
  10760. * The value to set on the tech.
  10761. *
  10762. * @return {Mixed}
  10763. * The return value of the `method` of the `tech`, regardless of the
  10764. * return values of middlewares.
  10765. */
  10766. function mediate(middleware, tech, method, arg) {
  10767. if (arg === void 0) {
  10768. arg = null;
  10769. }
  10770. var callMethod = 'call' + toTitleCase(method);
  10771. var middlewareValue = middleware.reduce(middlewareIterator(callMethod), arg);
  10772. var terminated = middlewareValue === TERMINATOR; // deprecated. The `null` return value should instead return TERMINATOR to
  10773. // prevent confusion if a techs method actually returns null.
  10774. var returnValue = terminated ? null : tech[method](middlewareValue);
  10775. executeRight(middleware, method, returnValue, terminated);
  10776. return returnValue;
  10777. }
  10778. /**
  10779. * Enumeration of allowed getters where the keys are method names.
  10780. *
  10781. * @type {Object}
  10782. */
  10783. var allowedGetters = {
  10784. buffered: 1,
  10785. currentTime: 1,
  10786. duration: 1,
  10787. muted: 1,
  10788. played: 1,
  10789. paused: 1,
  10790. seekable: 1,
  10791. volume: 1,
  10792. ended: 1
  10793. };
  10794. /**
  10795. * Enumeration of allowed setters where the keys are method names.
  10796. *
  10797. * @type {Object}
  10798. */
  10799. var allowedSetters = {
  10800. setCurrentTime: 1,
  10801. setMuted: 1,
  10802. setVolume: 1
  10803. };
  10804. /**
  10805. * Enumeration of allowed mediators where the keys are method names.
  10806. *
  10807. * @type {Object}
  10808. */
  10809. var allowedMediators = {
  10810. play: 1,
  10811. pause: 1
  10812. };
  10813. function middlewareIterator(method) {
  10814. return function (value, mw) {
  10815. // if the previous middleware terminated, pass along the termination
  10816. if (value === TERMINATOR) {
  10817. return TERMINATOR;
  10818. }
  10819. if (mw[method]) {
  10820. return mw[method](value);
  10821. }
  10822. return value;
  10823. };
  10824. }
  10825. function executeRight(mws, method, value, terminated) {
  10826. for (var i = mws.length - 1; i >= 0; i--) {
  10827. var mw = mws[i];
  10828. if (mw[method]) {
  10829. mw[method](terminated, value);
  10830. }
  10831. }
  10832. }
  10833. /**
  10834. * Clear the middleware cache for a player.
  10835. *
  10836. * @param {Player} player
  10837. * A {@link Player} instance.
  10838. */
  10839. function clearCacheForPlayer(player) {
  10840. middlewareInstances[player.id()] = null;
  10841. }
  10842. /**
  10843. * {
  10844. * [playerId]: [[mwFactory, mwInstance], ...]
  10845. * }
  10846. *
  10847. * @private
  10848. */
  10849. function getOrCreateFactory(player, mwFactory) {
  10850. var mws = middlewareInstances[player.id()];
  10851. var mw = null;
  10852. if (mws === undefined || mws === null) {
  10853. mw = mwFactory(player);
  10854. middlewareInstances[player.id()] = [[mwFactory, mw]];
  10855. return mw;
  10856. }
  10857. for (var i = 0; i < mws.length; i++) {
  10858. var _mws$i = mws[i],
  10859. mwf = _mws$i[0],
  10860. mwi = _mws$i[1];
  10861. if (mwf !== mwFactory) {
  10862. continue;
  10863. }
  10864. mw = mwi;
  10865. }
  10866. if (mw === null) {
  10867. mw = mwFactory(player);
  10868. mws.push([mwFactory, mw]);
  10869. }
  10870. return mw;
  10871. }
  10872. function setSourceHelper(src, middleware, next, player, acc, lastRun) {
  10873. if (src === void 0) {
  10874. src = {};
  10875. }
  10876. if (middleware === void 0) {
  10877. middleware = [];
  10878. }
  10879. if (acc === void 0) {
  10880. acc = [];
  10881. }
  10882. if (lastRun === void 0) {
  10883. lastRun = false;
  10884. }
  10885. var _middleware = middleware,
  10886. mwFactory = _middleware[0],
  10887. mwrest = _middleware.slice(1); // if mwFactory is a string, then we're at a fork in the road
  10888. if (typeof mwFactory === 'string') {
  10889. setSourceHelper(src, middlewares[mwFactory], next, player, acc, lastRun); // if we have an mwFactory, call it with the player to get the mw,
  10890. // then call the mw's setSource method
  10891. } else if (mwFactory) {
  10892. var mw = getOrCreateFactory(player, mwFactory); // if setSource isn't present, implicitly select this middleware
  10893. if (!mw.setSource) {
  10894. acc.push(mw);
  10895. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  10896. }
  10897. mw.setSource(assign({}, src), function (err, _src) {
  10898. // something happened, try the next middleware on the current level
  10899. // make sure to use the old src
  10900. if (err) {
  10901. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  10902. } // we've succeeded, now we need to go deeper
  10903. acc.push(mw); // if it's the same type, continue down the current chain
  10904. // otherwise, we want to go down the new chain
  10905. setSourceHelper(_src, src.type === _src.type ? mwrest : middlewares[_src.type], next, player, acc, lastRun);
  10906. });
  10907. } else if (mwrest.length) {
  10908. setSourceHelper(src, mwrest, next, player, acc, lastRun);
  10909. } else if (lastRun) {
  10910. next(src, acc);
  10911. } else {
  10912. setSourceHelper(src, middlewares['*'], next, player, acc, true);
  10913. }
  10914. }
  10915. /**
  10916. * Mimetypes
  10917. *
  10918. * @see https://www.iana.org/assignments/media-types/media-types.xhtml
  10919. * @typedef Mimetypes~Kind
  10920. * @enum
  10921. */
  10922. var MimetypesKind = {
  10923. opus: 'video/ogg',
  10924. ogv: 'video/ogg',
  10925. mp4: 'video/mp4',
  10926. mov: 'video/mp4',
  10927. m4v: 'video/mp4',
  10928. mkv: 'video/x-matroska',
  10929. m4a: 'audio/mp4',
  10930. mp3: 'audio/mpeg',
  10931. aac: 'audio/aac',
  10932. caf: 'audio/x-caf',
  10933. flac: 'audio/flac',
  10934. oga: 'audio/ogg',
  10935. wav: 'audio/wav',
  10936. m3u8: 'application/x-mpegURL',
  10937. mpd: 'application/dash+xml',
  10938. jpg: 'image/jpeg',
  10939. jpeg: 'image/jpeg',
  10940. gif: 'image/gif',
  10941. png: 'image/png',
  10942. svg: 'image/svg+xml',
  10943. webp: 'image/webp'
  10944. };
  10945. /**
  10946. * Get the mimetype of a given src url if possible
  10947. *
  10948. * @param {string} src
  10949. * The url to the src
  10950. *
  10951. * @return {string}
  10952. * return the mimetype if it was known or empty string otherwise
  10953. */
  10954. var getMimetype = function getMimetype(src) {
  10955. if (src === void 0) {
  10956. src = '';
  10957. }
  10958. var ext = getFileExtension(src);
  10959. var mimetype = MimetypesKind[ext.toLowerCase()];
  10960. return mimetype || '';
  10961. };
  10962. /**
  10963. * Find the mime type of a given source string if possible. Uses the player
  10964. * source cache.
  10965. *
  10966. * @param {Player} player
  10967. * The player object
  10968. *
  10969. * @param {string} src
  10970. * The source string
  10971. *
  10972. * @return {string}
  10973. * The type that was found
  10974. */
  10975. var findMimetype = function findMimetype(player, src) {
  10976. if (!src) {
  10977. return '';
  10978. } // 1. check for the type in the `source` cache
  10979. if (player.cache_.source.src === src && player.cache_.source.type) {
  10980. return player.cache_.source.type;
  10981. } // 2. see if we have this source in our `currentSources` cache
  10982. var matchingSources = player.cache_.sources.filter(function (s) {
  10983. return s.src === src;
  10984. });
  10985. if (matchingSources.length) {
  10986. return matchingSources[0].type;
  10987. } // 3. look for the src url in source elements and use the type there
  10988. var sources = player.$$('source');
  10989. for (var i = 0; i < sources.length; i++) {
  10990. var s = sources[i];
  10991. if (s.type && s.src && s.src === src) {
  10992. return s.type;
  10993. }
  10994. } // 4. finally fallback to our list of mime types based on src url extension
  10995. return getMimetype(src);
  10996. };
  10997. /**
  10998. * @module filter-source
  10999. */
  11000. /**
  11001. * Filter out single bad source objects or multiple source objects in an
  11002. * array. Also flattens nested source object arrays into a 1 dimensional
  11003. * array of source objects.
  11004. *
  11005. * @param {Tech~SourceObject|Tech~SourceObject[]} src
  11006. * The src object to filter
  11007. *
  11008. * @return {Tech~SourceObject[]}
  11009. * An array of sourceobjects containing only valid sources
  11010. *
  11011. * @private
  11012. */
  11013. var filterSource = function filterSource(src) {
  11014. // traverse array
  11015. if (Array.isArray(src)) {
  11016. var newsrc = [];
  11017. src.forEach(function (srcobj) {
  11018. srcobj = filterSource(srcobj);
  11019. if (Array.isArray(srcobj)) {
  11020. newsrc = newsrc.concat(srcobj);
  11021. } else if (isObject(srcobj)) {
  11022. newsrc.push(srcobj);
  11023. }
  11024. });
  11025. src = newsrc;
  11026. } else if (typeof src === 'string' && src.trim()) {
  11027. // convert string into object
  11028. src = [fixSource({
  11029. src: src
  11030. })];
  11031. } else if (isObject(src) && typeof src.src === 'string' && src.src && src.src.trim()) {
  11032. // src is already valid
  11033. src = [fixSource(src)];
  11034. } else {
  11035. // invalid source, turn it into an empty array
  11036. src = [];
  11037. }
  11038. return src;
  11039. };
  11040. /**
  11041. * Checks src mimetype, adding it when possible
  11042. *
  11043. * @param {Tech~SourceObject} src
  11044. * The src object to check
  11045. * @return {Tech~SourceObject}
  11046. * src Object with known type
  11047. */
  11048. function fixSource(src) {
  11049. if (!src.type) {
  11050. var mimetype = getMimetype(src.src);
  11051. if (mimetype) {
  11052. src.type = mimetype;
  11053. }
  11054. }
  11055. return src;
  11056. }
  11057. /**
  11058. * The `MediaLoader` is the `Component` that decides which playback technology to load
  11059. * when a player is initialized.
  11060. *
  11061. * @extends Component
  11062. */
  11063. var MediaLoader = /*#__PURE__*/function (_Component) {
  11064. inheritsLoose(MediaLoader, _Component);
  11065. /**
  11066. * Create an instance of this class.
  11067. *
  11068. * @param {Player} player
  11069. * The `Player` that this class should attach to.
  11070. *
  11071. * @param {Object} [options]
  11072. * The key/value store of player options.
  11073. *
  11074. * @param {Component~ReadyCallback} [ready]
  11075. * The function that is run when this component is ready.
  11076. */
  11077. function MediaLoader(player, options, ready) {
  11078. var _this;
  11079. // MediaLoader has no element
  11080. var options_ = mergeOptions({
  11081. createEl: false
  11082. }, options);
  11083. _this = _Component.call(this, player, options_, ready) || this; // If there are no sources when the player is initialized,
  11084. // load the first supported playback technology.
  11085. if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
  11086. for (var i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
  11087. var techName = toTitleCase(j[i]);
  11088. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  11089. // Remove once that deprecated behavior is removed.
  11090. if (!techName) {
  11091. tech = Component.getComponent(techName);
  11092. } // Check if the browser supports this technology
  11093. if (tech && tech.isSupported()) {
  11094. player.loadTech_(techName);
  11095. break;
  11096. }
  11097. }
  11098. } else {
  11099. // Loop through playback technologies (e.g. HTML5) and check for support.
  11100. // Then load the best source.
  11101. // A few assumptions here:
  11102. // All playback technologies respect preload false.
  11103. player.src(options.playerOptions.sources);
  11104. }
  11105. return _this;
  11106. }
  11107. return MediaLoader;
  11108. }(Component);
  11109. Component.registerComponent('MediaLoader', MediaLoader);
  11110. /**
  11111. * Component which is clickable or keyboard actionable, but is not a
  11112. * native HTML button.
  11113. *
  11114. * @extends Component
  11115. */
  11116. var ClickableComponent = /*#__PURE__*/function (_Component) {
  11117. inheritsLoose(ClickableComponent, _Component);
  11118. /**
  11119. * Creates an instance of this class.
  11120. *
  11121. * @param {Player} player
  11122. * The `Player` that this class should be attached to.
  11123. *
  11124. * @param {Object} [options]
  11125. * The key/value store of component options.
  11126. *
  11127. * @param {function} [options.clickHandler]
  11128. * The function to call when the button is clicked / activated
  11129. *
  11130. * @param {string} [options.controlText]
  11131. * The text to set on the button
  11132. *
  11133. * @param {string} [options.className]
  11134. * A class or space separated list of classes to add the component
  11135. *
  11136. */
  11137. function ClickableComponent(player, options) {
  11138. var _this;
  11139. _this = _Component.call(this, player, options) || this;
  11140. if (_this.options_.controlText) {
  11141. _this.controlText(_this.options_.controlText);
  11142. }
  11143. _this.handleMouseOver_ = function (e) {
  11144. return _this.handleMouseOver(e);
  11145. };
  11146. _this.handleMouseOut_ = function (e) {
  11147. return _this.handleMouseOut(e);
  11148. };
  11149. _this.handleClick_ = function (e) {
  11150. return _this.handleClick(e);
  11151. };
  11152. _this.handleKeyDown_ = function (e) {
  11153. return _this.handleKeyDown(e);
  11154. };
  11155. _this.emitTapEvents();
  11156. _this.enable();
  11157. return _this;
  11158. }
  11159. /**
  11160. * Create the `ClickableComponent`s DOM element.
  11161. *
  11162. * @param {string} [tag=div]
  11163. * The element's node type.
  11164. *
  11165. * @param {Object} [props={}]
  11166. * An object of properties that should be set on the element.
  11167. *
  11168. * @param {Object} [attributes={}]
  11169. * An object of attributes that should be set on the element.
  11170. *
  11171. * @return {Element}
  11172. * The element that gets created.
  11173. */
  11174. var _proto = ClickableComponent.prototype;
  11175. _proto.createEl = function createEl$1(tag, props, attributes) {
  11176. if (tag === void 0) {
  11177. tag = 'div';
  11178. }
  11179. if (props === void 0) {
  11180. props = {};
  11181. }
  11182. if (attributes === void 0) {
  11183. attributes = {};
  11184. }
  11185. props = assign({
  11186. className: this.buildCSSClass(),
  11187. tabIndex: 0
  11188. }, props);
  11189. if (tag === 'button') {
  11190. log.error("Creating a ClickableComponent with an HTML element of " + tag + " is not supported; use a Button instead.");
  11191. } // Add ARIA attributes for clickable element which is not a native HTML button
  11192. attributes = assign({
  11193. role: 'button'
  11194. }, attributes);
  11195. this.tabIndex_ = props.tabIndex;
  11196. var el = createEl(tag, props, attributes);
  11197. el.appendChild(createEl('span', {
  11198. className: 'vjs-icon-placeholder'
  11199. }, {
  11200. 'aria-hidden': true
  11201. }));
  11202. this.createControlTextEl(el);
  11203. return el;
  11204. };
  11205. _proto.dispose = function dispose() {
  11206. // remove controlTextEl_ on dispose
  11207. this.controlTextEl_ = null;
  11208. _Component.prototype.dispose.call(this);
  11209. }
  11210. /**
  11211. * Create a control text element on this `ClickableComponent`
  11212. *
  11213. * @param {Element} [el]
  11214. * Parent element for the control text.
  11215. *
  11216. * @return {Element}
  11217. * The control text element that gets created.
  11218. */
  11219. ;
  11220. _proto.createControlTextEl = function createControlTextEl(el) {
  11221. this.controlTextEl_ = createEl('span', {
  11222. className: 'vjs-control-text'
  11223. }, {
  11224. // let the screen reader user know that the text of the element may change
  11225. 'aria-live': 'polite'
  11226. });
  11227. if (el) {
  11228. el.appendChild(this.controlTextEl_);
  11229. }
  11230. this.controlText(this.controlText_, el);
  11231. return this.controlTextEl_;
  11232. }
  11233. /**
  11234. * Get or set the localize text to use for the controls on the `ClickableComponent`.
  11235. *
  11236. * @param {string} [text]
  11237. * Control text for element.
  11238. *
  11239. * @param {Element} [el=this.el()]
  11240. * Element to set the title on.
  11241. *
  11242. * @return {string}
  11243. * - The control text when getting
  11244. */
  11245. ;
  11246. _proto.controlText = function controlText(text, el) {
  11247. if (el === void 0) {
  11248. el = this.el();
  11249. }
  11250. if (text === undefined) {
  11251. return this.controlText_ || 'Need Text';
  11252. }
  11253. var localizedText = this.localize(text);
  11254. this.controlText_ = text;
  11255. textContent(this.controlTextEl_, localizedText);
  11256. if (!this.nonIconControl && !this.player_.options_.noUITitleAttributes) {
  11257. // Set title attribute if only an icon is shown
  11258. el.setAttribute('title', localizedText);
  11259. }
  11260. }
  11261. /**
  11262. * Builds the default DOM `className`.
  11263. *
  11264. * @return {string}
  11265. * The DOM `className` for this object.
  11266. */
  11267. ;
  11268. _proto.buildCSSClass = function buildCSSClass() {
  11269. return "vjs-control vjs-button " + _Component.prototype.buildCSSClass.call(this);
  11270. }
  11271. /**
  11272. * Enable this `ClickableComponent`
  11273. */
  11274. ;
  11275. _proto.enable = function enable() {
  11276. if (!this.enabled_) {
  11277. this.enabled_ = true;
  11278. this.removeClass('vjs-disabled');
  11279. this.el_.setAttribute('aria-disabled', 'false');
  11280. if (typeof this.tabIndex_ !== 'undefined') {
  11281. this.el_.setAttribute('tabIndex', this.tabIndex_);
  11282. }
  11283. this.on(['tap', 'click'], this.handleClick_);
  11284. this.on('keydown', this.handleKeyDown_);
  11285. }
  11286. }
  11287. /**
  11288. * Disable this `ClickableComponent`
  11289. */
  11290. ;
  11291. _proto.disable = function disable() {
  11292. this.enabled_ = false;
  11293. this.addClass('vjs-disabled');
  11294. this.el_.setAttribute('aria-disabled', 'true');
  11295. if (typeof this.tabIndex_ !== 'undefined') {
  11296. this.el_.removeAttribute('tabIndex');
  11297. }
  11298. this.off('mouseover', this.handleMouseOver_);
  11299. this.off('mouseout', this.handleMouseOut_);
  11300. this.off(['tap', 'click'], this.handleClick_);
  11301. this.off('keydown', this.handleKeyDown_);
  11302. }
  11303. /**
  11304. * Handles language change in ClickableComponent for the player in components
  11305. *
  11306. *
  11307. */
  11308. ;
  11309. _proto.handleLanguagechange = function handleLanguagechange() {
  11310. this.controlText(this.controlText_);
  11311. }
  11312. /**
  11313. * Event handler that is called when a `ClickableComponent` receives a
  11314. * `click` or `tap` event.
  11315. *
  11316. * @param {EventTarget~Event} event
  11317. * The `tap` or `click` event that caused this function to be called.
  11318. *
  11319. * @listens tap
  11320. * @listens click
  11321. * @abstract
  11322. */
  11323. ;
  11324. _proto.handleClick = function handleClick(event) {
  11325. if (this.options_.clickHandler) {
  11326. this.options_.clickHandler.call(this, arguments);
  11327. }
  11328. }
  11329. /**
  11330. * Event handler that is called when a `ClickableComponent` receives a
  11331. * `keydown` event.
  11332. *
  11333. * By default, if the key is Space or Enter, it will trigger a `click` event.
  11334. *
  11335. * @param {EventTarget~Event} event
  11336. * The `keydown` event that caused this function to be called.
  11337. *
  11338. * @listens keydown
  11339. */
  11340. ;
  11341. _proto.handleKeyDown = function handleKeyDown(event) {
  11342. // Support Space or Enter key operation to fire a click event. Also,
  11343. // prevent the event from propagating through the DOM and triggering
  11344. // Player hotkeys.
  11345. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  11346. event.preventDefault();
  11347. event.stopPropagation();
  11348. this.trigger('click');
  11349. } else {
  11350. // Pass keypress handling up for unsupported keys
  11351. _Component.prototype.handleKeyDown.call(this, event);
  11352. }
  11353. };
  11354. return ClickableComponent;
  11355. }(Component);
  11356. Component.registerComponent('ClickableComponent', ClickableComponent);
  11357. /**
  11358. * A `ClickableComponent` that handles showing the poster image for the player.
  11359. *
  11360. * @extends ClickableComponent
  11361. */
  11362. var PosterImage = /*#__PURE__*/function (_ClickableComponent) {
  11363. inheritsLoose(PosterImage, _ClickableComponent);
  11364. /**
  11365. * Create an instance of this class.
  11366. *
  11367. * @param {Player} player
  11368. * The `Player` that this class should attach to.
  11369. *
  11370. * @param {Object} [options]
  11371. * The key/value store of player options.
  11372. */
  11373. function PosterImage(player, options) {
  11374. var _this;
  11375. _this = _ClickableComponent.call(this, player, options) || this;
  11376. _this.update();
  11377. _this.update_ = function (e) {
  11378. return _this.update(e);
  11379. };
  11380. player.on('posterchange', _this.update_);
  11381. return _this;
  11382. }
  11383. /**
  11384. * Clean up and dispose of the `PosterImage`.
  11385. */
  11386. var _proto = PosterImage.prototype;
  11387. _proto.dispose = function dispose() {
  11388. this.player().off('posterchange', this.update_);
  11389. _ClickableComponent.prototype.dispose.call(this);
  11390. }
  11391. /**
  11392. * Create the `PosterImage`s DOM element.
  11393. *
  11394. * @return {Element}
  11395. * The element that gets created.
  11396. */
  11397. ;
  11398. _proto.createEl = function createEl$1() {
  11399. var el = createEl('div', {
  11400. className: 'vjs-poster',
  11401. // Don't want poster to be tabbable.
  11402. tabIndex: -1
  11403. });
  11404. return el;
  11405. }
  11406. /**
  11407. * An {@link EventTarget~EventListener} for {@link Player#posterchange} events.
  11408. *
  11409. * @listens Player#posterchange
  11410. *
  11411. * @param {EventTarget~Event} [event]
  11412. * The `Player#posterchange` event that triggered this function.
  11413. */
  11414. ;
  11415. _proto.update = function update(event) {
  11416. var url = this.player().poster();
  11417. this.setSrc(url); // If there's no poster source we should display:none on this component
  11418. // so it's not still clickable or right-clickable
  11419. if (url) {
  11420. this.show();
  11421. } else {
  11422. this.hide();
  11423. }
  11424. }
  11425. /**
  11426. * Set the source of the `PosterImage` depending on the display method.
  11427. *
  11428. * @param {string} url
  11429. * The URL to the source for the `PosterImage`.
  11430. */
  11431. ;
  11432. _proto.setSrc = function setSrc(url) {
  11433. var backgroundImage = ''; // Any falsy value should stay as an empty string, otherwise
  11434. // this will throw an extra error
  11435. if (url) {
  11436. backgroundImage = "url(\"" + url + "\")";
  11437. }
  11438. this.el_.style.backgroundImage = backgroundImage;
  11439. }
  11440. /**
  11441. * An {@link EventTarget~EventListener} for clicks on the `PosterImage`. See
  11442. * {@link ClickableComponent#handleClick} for instances where this will be triggered.
  11443. *
  11444. * @listens tap
  11445. * @listens click
  11446. * @listens keydown
  11447. *
  11448. * @param {EventTarget~Event} event
  11449. + The `click`, `tap` or `keydown` event that caused this function to be called.
  11450. */
  11451. ;
  11452. _proto.handleClick = function handleClick(event) {
  11453. // We don't want a click to trigger playback when controls are disabled
  11454. if (!this.player_.controls()) {
  11455. return;
  11456. }
  11457. var sourceIsEncrypted = this.player_.usingPlugin('eme') && this.player_.eme.sessions && this.player_.eme.sessions.length > 0;
  11458. if (this.player_.tech(true) && // We've observed a bug in IE and Edge when playing back DRM content where
  11459. // calling .focus() on the video element causes the video to go black,
  11460. // so we avoid it in that specific case
  11461. !((IE_VERSION || IS_EDGE) && sourceIsEncrypted)) {
  11462. this.player_.tech(true).focus();
  11463. }
  11464. if (this.player_.paused()) {
  11465. silencePromise(this.player_.play());
  11466. } else {
  11467. this.player_.pause();
  11468. }
  11469. };
  11470. return PosterImage;
  11471. }(ClickableComponent);
  11472. Component.registerComponent('PosterImage', PosterImage);
  11473. var darkGray = '#222';
  11474. var lightGray = '#ccc';
  11475. var fontMap = {
  11476. monospace: 'monospace',
  11477. sansSerif: 'sans-serif',
  11478. serif: 'serif',
  11479. monospaceSansSerif: '"Andale Mono", "Lucida Console", monospace',
  11480. monospaceSerif: '"Courier New", monospace',
  11481. proportionalSansSerif: 'sans-serif',
  11482. proportionalSerif: 'serif',
  11483. casual: '"Comic Sans MS", Impact, fantasy',
  11484. script: '"Monotype Corsiva", cursive',
  11485. smallcaps: '"Andale Mono", "Lucida Console", monospace, sans-serif'
  11486. };
  11487. /**
  11488. * Construct an rgba color from a given hex color code.
  11489. *
  11490. * @param {number} color
  11491. * Hex number for color, like #f0e or #f604e2.
  11492. *
  11493. * @param {number} opacity
  11494. * Value for opacity, 0.0 - 1.0.
  11495. *
  11496. * @return {string}
  11497. * The rgba color that was created, like 'rgba(255, 0, 0, 0.3)'.
  11498. */
  11499. function constructColor(color, opacity) {
  11500. var hex;
  11501. if (color.length === 4) {
  11502. // color looks like "#f0e"
  11503. hex = color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
  11504. } else if (color.length === 7) {
  11505. // color looks like "#f604e2"
  11506. hex = color.slice(1);
  11507. } else {
  11508. throw new Error('Invalid color code provided, ' + color + '; must be formatted as e.g. #f0e or #f604e2.');
  11509. }
  11510. return 'rgba(' + parseInt(hex.slice(0, 2), 16) + ',' + parseInt(hex.slice(2, 4), 16) + ',' + parseInt(hex.slice(4, 6), 16) + ',' + opacity + ')';
  11511. }
  11512. /**
  11513. * Try to update the style of a DOM element. Some style changes will throw an error,
  11514. * particularly in IE8. Those should be noops.
  11515. *
  11516. * @param {Element} el
  11517. * The DOM element to be styled.
  11518. *
  11519. * @param {string} style
  11520. * The CSS property on the element that should be styled.
  11521. *
  11522. * @param {string} rule
  11523. * The style rule that should be applied to the property.
  11524. *
  11525. * @private
  11526. */
  11527. function tryUpdateStyle(el, style, rule) {
  11528. try {
  11529. el.style[style] = rule;
  11530. } catch (e) {
  11531. // Satisfies linter.
  11532. return;
  11533. }
  11534. }
  11535. /**
  11536. * The component for displaying text track cues.
  11537. *
  11538. * @extends Component
  11539. */
  11540. var TextTrackDisplay = /*#__PURE__*/function (_Component) {
  11541. inheritsLoose(TextTrackDisplay, _Component);
  11542. /**
  11543. * Creates an instance of this class.
  11544. *
  11545. * @param {Player} player
  11546. * The `Player` that this class should be attached to.
  11547. *
  11548. * @param {Object} [options]
  11549. * The key/value store of player options.
  11550. *
  11551. * @param {Component~ReadyCallback} [ready]
  11552. * The function to call when `TextTrackDisplay` is ready.
  11553. */
  11554. function TextTrackDisplay(player, options, ready) {
  11555. var _this;
  11556. _this = _Component.call(this, player, options, ready) || this;
  11557. var updateDisplayHandler = function updateDisplayHandler(e) {
  11558. return _this.updateDisplay(e);
  11559. };
  11560. player.on('loadstart', function (e) {
  11561. return _this.toggleDisplay(e);
  11562. });
  11563. player.on('texttrackchange', updateDisplayHandler);
  11564. player.on('loadedmetadata', function (e) {
  11565. return _this.preselectTrack(e);
  11566. }); // This used to be called during player init, but was causing an error
  11567. // if a track should show by default and the display hadn't loaded yet.
  11568. // Should probably be moved to an external track loader when we support
  11569. // tracks that don't need a display.
  11570. player.ready(bind(assertThisInitialized(_this), function () {
  11571. if (player.tech_ && player.tech_.featuresNativeTextTracks) {
  11572. this.hide();
  11573. return;
  11574. }
  11575. player.on('fullscreenchange', updateDisplayHandler);
  11576. player.on('playerresize', updateDisplayHandler);
  11577. window.addEventListener('orientationchange', updateDisplayHandler);
  11578. player.on('dispose', function () {
  11579. return window.removeEventListener('orientationchange', updateDisplayHandler);
  11580. });
  11581. var tracks = this.options_.playerOptions.tracks || [];
  11582. for (var i = 0; i < tracks.length; i++) {
  11583. this.player_.addRemoteTextTrack(tracks[i], true);
  11584. }
  11585. this.preselectTrack();
  11586. }));
  11587. return _this;
  11588. }
  11589. /**
  11590. * Preselect a track following this precedence:
  11591. * - matches the previously selected {@link TextTrack}'s language and kind
  11592. * - matches the previously selected {@link TextTrack}'s language only
  11593. * - is the first default captions track
  11594. * - is the first default descriptions track
  11595. *
  11596. * @listens Player#loadstart
  11597. */
  11598. var _proto = TextTrackDisplay.prototype;
  11599. _proto.preselectTrack = function preselectTrack() {
  11600. var modes = {
  11601. captions: 1,
  11602. subtitles: 1
  11603. };
  11604. var trackList = this.player_.textTracks();
  11605. var userPref = this.player_.cache_.selectedLanguage;
  11606. var firstDesc;
  11607. var firstCaptions;
  11608. var preferredTrack;
  11609. for (var i = 0; i < trackList.length; i++) {
  11610. var track = trackList[i];
  11611. if (userPref && userPref.enabled && userPref.language && userPref.language === track.language && track.kind in modes) {
  11612. // Always choose the track that matches both language and kind
  11613. if (track.kind === userPref.kind) {
  11614. preferredTrack = track; // or choose the first track that matches language
  11615. } else if (!preferredTrack) {
  11616. preferredTrack = track;
  11617. } // clear everything if offTextTrackMenuItem was clicked
  11618. } else if (userPref && !userPref.enabled) {
  11619. preferredTrack = null;
  11620. firstDesc = null;
  11621. firstCaptions = null;
  11622. } else if (track["default"]) {
  11623. if (track.kind === 'descriptions' && !firstDesc) {
  11624. firstDesc = track;
  11625. } else if (track.kind in modes && !firstCaptions) {
  11626. firstCaptions = track;
  11627. }
  11628. }
  11629. } // The preferredTrack matches the user preference and takes
  11630. // precedence over all the other tracks.
  11631. // So, display the preferredTrack before the first default track
  11632. // and the subtitles/captions track before the descriptions track
  11633. if (preferredTrack) {
  11634. preferredTrack.mode = 'showing';
  11635. } else if (firstCaptions) {
  11636. firstCaptions.mode = 'showing';
  11637. } else if (firstDesc) {
  11638. firstDesc.mode = 'showing';
  11639. }
  11640. }
  11641. /**
  11642. * Turn display of {@link TextTrack}'s from the current state into the other state.
  11643. * There are only two states:
  11644. * - 'shown'
  11645. * - 'hidden'
  11646. *
  11647. * @listens Player#loadstart
  11648. */
  11649. ;
  11650. _proto.toggleDisplay = function toggleDisplay() {
  11651. if (this.player_.tech_ && this.player_.tech_.featuresNativeTextTracks) {
  11652. this.hide();
  11653. } else {
  11654. this.show();
  11655. }
  11656. }
  11657. /**
  11658. * Create the {@link Component}'s DOM element.
  11659. *
  11660. * @return {Element}
  11661. * The element that was created.
  11662. */
  11663. ;
  11664. _proto.createEl = function createEl() {
  11665. return _Component.prototype.createEl.call(this, 'div', {
  11666. className: 'vjs-text-track-display'
  11667. }, {
  11668. 'translate': 'yes',
  11669. 'aria-live': 'off',
  11670. 'aria-atomic': 'true'
  11671. });
  11672. }
  11673. /**
  11674. * Clear all displayed {@link TextTrack}s.
  11675. */
  11676. ;
  11677. _proto.clearDisplay = function clearDisplay() {
  11678. if (typeof window.WebVTT === 'function') {
  11679. window.WebVTT.processCues(window, [], this.el_);
  11680. }
  11681. }
  11682. /**
  11683. * Update the displayed TextTrack when a either a {@link Player#texttrackchange} or
  11684. * a {@link Player#fullscreenchange} is fired.
  11685. *
  11686. * @listens Player#texttrackchange
  11687. * @listens Player#fullscreenchange
  11688. */
  11689. ;
  11690. _proto.updateDisplay = function updateDisplay() {
  11691. var tracks = this.player_.textTracks();
  11692. var allowMultipleShowingTracks = this.options_.allowMultipleShowingTracks;
  11693. this.clearDisplay();
  11694. if (allowMultipleShowingTracks) {
  11695. var showingTracks = [];
  11696. for (var _i = 0; _i < tracks.length; ++_i) {
  11697. var track = tracks[_i];
  11698. if (track.mode !== 'showing') {
  11699. continue;
  11700. }
  11701. showingTracks.push(track);
  11702. }
  11703. this.updateForTrack(showingTracks);
  11704. return;
  11705. } // Track display prioritization model: if multiple tracks are 'showing',
  11706. // display the first 'subtitles' or 'captions' track which is 'showing',
  11707. // otherwise display the first 'descriptions' track which is 'showing'
  11708. var descriptionsTrack = null;
  11709. var captionsSubtitlesTrack = null;
  11710. var i = tracks.length;
  11711. while (i--) {
  11712. var _track = tracks[i];
  11713. if (_track.mode === 'showing') {
  11714. if (_track.kind === 'descriptions') {
  11715. descriptionsTrack = _track;
  11716. } else {
  11717. captionsSubtitlesTrack = _track;
  11718. }
  11719. }
  11720. }
  11721. if (captionsSubtitlesTrack) {
  11722. if (this.getAttribute('aria-live') !== 'off') {
  11723. this.setAttribute('aria-live', 'off');
  11724. }
  11725. this.updateForTrack(captionsSubtitlesTrack);
  11726. } else if (descriptionsTrack) {
  11727. if (this.getAttribute('aria-live') !== 'assertive') {
  11728. this.setAttribute('aria-live', 'assertive');
  11729. }
  11730. this.updateForTrack(descriptionsTrack);
  11731. }
  11732. }
  11733. /**
  11734. * Style {@Link TextTrack} activeCues according to {@Link TextTrackSettings}.
  11735. *
  11736. * @param {TextTrack} track
  11737. * Text track object containing active cues to style.
  11738. */
  11739. ;
  11740. _proto.updateDisplayState = function updateDisplayState(track) {
  11741. var overrides = this.player_.textTrackSettings.getValues();
  11742. var cues = track.activeCues;
  11743. var i = cues.length;
  11744. while (i--) {
  11745. var cue = cues[i];
  11746. if (!cue) {
  11747. continue;
  11748. }
  11749. var cueDiv = cue.displayState;
  11750. if (overrides.color) {
  11751. cueDiv.firstChild.style.color = overrides.color;
  11752. }
  11753. if (overrides.textOpacity) {
  11754. tryUpdateStyle(cueDiv.firstChild, 'color', constructColor(overrides.color || '#fff', overrides.textOpacity));
  11755. }
  11756. if (overrides.backgroundColor) {
  11757. cueDiv.firstChild.style.backgroundColor = overrides.backgroundColor;
  11758. }
  11759. if (overrides.backgroundOpacity) {
  11760. tryUpdateStyle(cueDiv.firstChild, 'backgroundColor', constructColor(overrides.backgroundColor || '#000', overrides.backgroundOpacity));
  11761. }
  11762. if (overrides.windowColor) {
  11763. if (overrides.windowOpacity) {
  11764. tryUpdateStyle(cueDiv, 'backgroundColor', constructColor(overrides.windowColor, overrides.windowOpacity));
  11765. } else {
  11766. cueDiv.style.backgroundColor = overrides.windowColor;
  11767. }
  11768. }
  11769. if (overrides.edgeStyle) {
  11770. if (overrides.edgeStyle === 'dropshadow') {
  11771. cueDiv.firstChild.style.textShadow = "2px 2px 3px " + darkGray + ", 2px 2px 4px " + darkGray + ", 2px 2px 5px " + darkGray;
  11772. } else if (overrides.edgeStyle === 'raised') {
  11773. cueDiv.firstChild.style.textShadow = "1px 1px " + darkGray + ", 2px 2px " + darkGray + ", 3px 3px " + darkGray;
  11774. } else if (overrides.edgeStyle === 'depressed') {
  11775. cueDiv.firstChild.style.textShadow = "1px 1px " + lightGray + ", 0 1px " + lightGray + ", -1px -1px " + darkGray + ", 0 -1px " + darkGray;
  11776. } else if (overrides.edgeStyle === 'uniform') {
  11777. cueDiv.firstChild.style.textShadow = "0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray;
  11778. }
  11779. }
  11780. if (overrides.fontPercent && overrides.fontPercent !== 1) {
  11781. var fontSize = window.parseFloat(cueDiv.style.fontSize);
  11782. cueDiv.style.fontSize = fontSize * overrides.fontPercent + 'px';
  11783. cueDiv.style.height = 'auto';
  11784. cueDiv.style.top = 'auto';
  11785. }
  11786. if (overrides.fontFamily && overrides.fontFamily !== 'default') {
  11787. if (overrides.fontFamily === 'small-caps') {
  11788. cueDiv.firstChild.style.fontVariant = 'small-caps';
  11789. } else {
  11790. cueDiv.firstChild.style.fontFamily = fontMap[overrides.fontFamily];
  11791. }
  11792. }
  11793. }
  11794. }
  11795. /**
  11796. * Add an {@link TextTrack} to to the {@link Tech}s {@link TextTrackList}.
  11797. *
  11798. * @param {TextTrack|TextTrack[]} tracks
  11799. * Text track object or text track array to be added to the list.
  11800. */
  11801. ;
  11802. _proto.updateForTrack = function updateForTrack(tracks) {
  11803. if (!Array.isArray(tracks)) {
  11804. tracks = [tracks];
  11805. }
  11806. if (typeof window.WebVTT !== 'function' || tracks.every(function (track) {
  11807. return !track.activeCues;
  11808. })) {
  11809. return;
  11810. }
  11811. var cues = []; // push all active track cues
  11812. for (var i = 0; i < tracks.length; ++i) {
  11813. var track = tracks[i];
  11814. for (var j = 0; j < track.activeCues.length; ++j) {
  11815. cues.push(track.activeCues[j]);
  11816. }
  11817. } // removes all cues before it processes new ones
  11818. window.WebVTT.processCues(window, cues, this.el_); // add unique class to each language text track & add settings styling if necessary
  11819. for (var _i2 = 0; _i2 < tracks.length; ++_i2) {
  11820. var _track2 = tracks[_i2];
  11821. for (var _j = 0; _j < _track2.activeCues.length; ++_j) {
  11822. var cueEl = _track2.activeCues[_j].displayState;
  11823. addClass(cueEl, 'vjs-text-track-cue');
  11824. addClass(cueEl, 'vjs-text-track-cue-' + (_track2.language ? _track2.language : _i2));
  11825. if (_track2.language) {
  11826. setAttribute(cueEl, 'lang', _track2.language);
  11827. }
  11828. }
  11829. if (this.player_.textTrackSettings) {
  11830. this.updateDisplayState(_track2);
  11831. }
  11832. }
  11833. };
  11834. return TextTrackDisplay;
  11835. }(Component);
  11836. Component.registerComponent('TextTrackDisplay', TextTrackDisplay);
  11837. /**
  11838. * A loading spinner for use during waiting/loading events.
  11839. *
  11840. * @extends Component
  11841. */
  11842. var LoadingSpinner = /*#__PURE__*/function (_Component) {
  11843. inheritsLoose(LoadingSpinner, _Component);
  11844. function LoadingSpinner() {
  11845. return _Component.apply(this, arguments) || this;
  11846. }
  11847. var _proto = LoadingSpinner.prototype;
  11848. /**
  11849. * Create the `LoadingSpinner`s DOM element.
  11850. *
  11851. * @return {Element}
  11852. * The dom element that gets created.
  11853. */
  11854. _proto.createEl = function createEl$1() {
  11855. var isAudio = this.player_.isAudio();
  11856. var playerType = this.localize(isAudio ? 'Audio Player' : 'Video Player');
  11857. var controlText = createEl('span', {
  11858. className: 'vjs-control-text',
  11859. textContent: this.localize('{1} is loading.', [playerType])
  11860. });
  11861. var el = _Component.prototype.createEl.call(this, 'div', {
  11862. className: 'vjs-loading-spinner',
  11863. dir: 'ltr'
  11864. });
  11865. el.appendChild(controlText);
  11866. return el;
  11867. };
  11868. return LoadingSpinner;
  11869. }(Component);
  11870. Component.registerComponent('LoadingSpinner', LoadingSpinner);
  11871. /**
  11872. * Base class for all buttons.
  11873. *
  11874. * @extends ClickableComponent
  11875. */
  11876. var Button = /*#__PURE__*/function (_ClickableComponent) {
  11877. inheritsLoose(Button, _ClickableComponent);
  11878. function Button() {
  11879. return _ClickableComponent.apply(this, arguments) || this;
  11880. }
  11881. var _proto = Button.prototype;
  11882. /**
  11883. * Create the `Button`s DOM element.
  11884. *
  11885. * @param {string} [tag="button"]
  11886. * The element's node type. This argument is IGNORED: no matter what
  11887. * is passed, it will always create a `button` element.
  11888. *
  11889. * @param {Object} [props={}]
  11890. * An object of properties that should be set on the element.
  11891. *
  11892. * @param {Object} [attributes={}]
  11893. * An object of attributes that should be set on the element.
  11894. *
  11895. * @return {Element}
  11896. * The element that gets created.
  11897. */
  11898. _proto.createEl = function createEl$1(tag, props, attributes) {
  11899. if (props === void 0) {
  11900. props = {};
  11901. }
  11902. if (attributes === void 0) {
  11903. attributes = {};
  11904. }
  11905. tag = 'button';
  11906. props = assign({
  11907. className: this.buildCSSClass()
  11908. }, props); // Add attributes for button element
  11909. attributes = assign({
  11910. // Necessary since the default button type is "submit"
  11911. type: 'button'
  11912. }, attributes);
  11913. var el = createEl(tag, props, attributes);
  11914. el.appendChild(createEl('span', {
  11915. className: 'vjs-icon-placeholder'
  11916. }, {
  11917. 'aria-hidden': true
  11918. }));
  11919. this.createControlTextEl(el);
  11920. return el;
  11921. }
  11922. /**
  11923. * Add a child `Component` inside of this `Button`.
  11924. *
  11925. * @param {string|Component} child
  11926. * The name or instance of a child to add.
  11927. *
  11928. * @param {Object} [options={}]
  11929. * The key/value store of options that will get passed to children of
  11930. * the child.
  11931. *
  11932. * @return {Component}
  11933. * The `Component` that gets added as a child. When using a string the
  11934. * `Component` will get created by this process.
  11935. *
  11936. * @deprecated since version 5
  11937. */
  11938. ;
  11939. _proto.addChild = function addChild(child, options) {
  11940. if (options === void 0) {
  11941. options = {};
  11942. }
  11943. var className = this.constructor.name;
  11944. 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
  11945. return Component.prototype.addChild.call(this, child, options);
  11946. }
  11947. /**
  11948. * Enable the `Button` element so that it can be activated or clicked. Use this with
  11949. * {@link Button#disable}.
  11950. */
  11951. ;
  11952. _proto.enable = function enable() {
  11953. _ClickableComponent.prototype.enable.call(this);
  11954. this.el_.removeAttribute('disabled');
  11955. }
  11956. /**
  11957. * Disable the `Button` element so that it cannot be activated or clicked. Use this with
  11958. * {@link Button#enable}.
  11959. */
  11960. ;
  11961. _proto.disable = function disable() {
  11962. _ClickableComponent.prototype.disable.call(this);
  11963. this.el_.setAttribute('disabled', 'disabled');
  11964. }
  11965. /**
  11966. * This gets called when a `Button` has focus and `keydown` is triggered via a key
  11967. * press.
  11968. *
  11969. * @param {EventTarget~Event} event
  11970. * The event that caused this function to get called.
  11971. *
  11972. * @listens keydown
  11973. */
  11974. ;
  11975. _proto.handleKeyDown = function handleKeyDown(event) {
  11976. // Ignore Space or Enter key operation, which is handled by the browser for
  11977. // a button - though not for its super class, ClickableComponent. Also,
  11978. // prevent the event from propagating through the DOM and triggering Player
  11979. // hotkeys. We do not preventDefault here because we _want_ the browser to
  11980. // handle it.
  11981. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  11982. event.stopPropagation();
  11983. return;
  11984. } // Pass keypress handling up for unsupported keys
  11985. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  11986. };
  11987. return Button;
  11988. }(ClickableComponent);
  11989. Component.registerComponent('Button', Button);
  11990. /**
  11991. * The initial play button that shows before the video has played. The hiding of the
  11992. * `BigPlayButton` get done via CSS and `Player` states.
  11993. *
  11994. * @extends Button
  11995. */
  11996. var BigPlayButton = /*#__PURE__*/function (_Button) {
  11997. inheritsLoose(BigPlayButton, _Button);
  11998. function BigPlayButton(player, options) {
  11999. var _this;
  12000. _this = _Button.call(this, player, options) || this;
  12001. _this.mouseused_ = false;
  12002. _this.on('mousedown', function (e) {
  12003. return _this.handleMouseDown(e);
  12004. });
  12005. return _this;
  12006. }
  12007. /**
  12008. * Builds the default DOM `className`.
  12009. *
  12010. * @return {string}
  12011. * The DOM `className` for this object. Always returns 'vjs-big-play-button'.
  12012. */
  12013. var _proto = BigPlayButton.prototype;
  12014. _proto.buildCSSClass = function buildCSSClass() {
  12015. return 'vjs-big-play-button';
  12016. }
  12017. /**
  12018. * This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
  12019. * for more detailed information on what a click can be.
  12020. *
  12021. * @param {EventTarget~Event} event
  12022. * The `keydown`, `tap`, or `click` event that caused this function to be
  12023. * called.
  12024. *
  12025. * @listens tap
  12026. * @listens click
  12027. */
  12028. ;
  12029. _proto.handleClick = function handleClick(event) {
  12030. var playPromise = this.player_.play(); // exit early if clicked via the mouse
  12031. if (this.mouseused_ && event.clientX && event.clientY) {
  12032. var sourceIsEncrypted = this.player_.usingPlugin('eme') && this.player_.eme.sessions && this.player_.eme.sessions.length > 0;
  12033. silencePromise(playPromise);
  12034. if (this.player_.tech(true) && // We've observed a bug in IE and Edge when playing back DRM content where
  12035. // calling .focus() on the video element causes the video to go black,
  12036. // so we avoid it in that specific case
  12037. !((IE_VERSION || IS_EDGE) && sourceIsEncrypted)) {
  12038. this.player_.tech(true).focus();
  12039. }
  12040. return;
  12041. }
  12042. var cb = this.player_.getChild('controlBar');
  12043. var playToggle = cb && cb.getChild('playToggle');
  12044. if (!playToggle) {
  12045. this.player_.tech(true).focus();
  12046. return;
  12047. }
  12048. var playFocus = function playFocus() {
  12049. return playToggle.focus();
  12050. };
  12051. if (isPromise(playPromise)) {
  12052. playPromise.then(playFocus, function () {});
  12053. } else {
  12054. this.setTimeout(playFocus, 1);
  12055. }
  12056. };
  12057. _proto.handleKeyDown = function handleKeyDown(event) {
  12058. this.mouseused_ = false;
  12059. _Button.prototype.handleKeyDown.call(this, event);
  12060. };
  12061. _proto.handleMouseDown = function handleMouseDown(event) {
  12062. this.mouseused_ = true;
  12063. };
  12064. return BigPlayButton;
  12065. }(Button);
  12066. /**
  12067. * The text that should display over the `BigPlayButton`s controls. Added to for localization.
  12068. *
  12069. * @type {string}
  12070. * @private
  12071. */
  12072. BigPlayButton.prototype.controlText_ = 'Play Video';
  12073. Component.registerComponent('BigPlayButton', BigPlayButton);
  12074. /**
  12075. * The `CloseButton` is a `{@link Button}` that fires a `close` event when
  12076. * it gets clicked.
  12077. *
  12078. * @extends Button
  12079. */
  12080. var CloseButton = /*#__PURE__*/function (_Button) {
  12081. inheritsLoose(CloseButton, _Button);
  12082. /**
  12083. * Creates an instance of the this class.
  12084. *
  12085. * @param {Player} player
  12086. * The `Player` that this class should be attached to.
  12087. *
  12088. * @param {Object} [options]
  12089. * The key/value store of player options.
  12090. */
  12091. function CloseButton(player, options) {
  12092. var _this;
  12093. _this = _Button.call(this, player, options) || this;
  12094. _this.controlText(options && options.controlText || _this.localize('Close'));
  12095. return _this;
  12096. }
  12097. /**
  12098. * Builds the default DOM `className`.
  12099. *
  12100. * @return {string}
  12101. * The DOM `className` for this object.
  12102. */
  12103. var _proto = CloseButton.prototype;
  12104. _proto.buildCSSClass = function buildCSSClass() {
  12105. return "vjs-close-button " + _Button.prototype.buildCSSClass.call(this);
  12106. }
  12107. /**
  12108. * This gets called when a `CloseButton` gets clicked. See
  12109. * {@link ClickableComponent#handleClick} for more information on when
  12110. * this will be triggered
  12111. *
  12112. * @param {EventTarget~Event} event
  12113. * The `keydown`, `tap`, or `click` event that caused this function to be
  12114. * called.
  12115. *
  12116. * @listens tap
  12117. * @listens click
  12118. * @fires CloseButton#close
  12119. */
  12120. ;
  12121. _proto.handleClick = function handleClick(event) {
  12122. /**
  12123. * Triggered when the a `CloseButton` is clicked.
  12124. *
  12125. * @event CloseButton#close
  12126. * @type {EventTarget~Event}
  12127. *
  12128. * @property {boolean} [bubbles=false]
  12129. * set to false so that the close event does not
  12130. * bubble up to parents if there is no listener
  12131. */
  12132. this.trigger({
  12133. type: 'close',
  12134. bubbles: false
  12135. });
  12136. }
  12137. /**
  12138. * Event handler that is called when a `CloseButton` receives a
  12139. * `keydown` event.
  12140. *
  12141. * By default, if the key is Esc, it will trigger a `click` event.
  12142. *
  12143. * @param {EventTarget~Event} event
  12144. * The `keydown` event that caused this function to be called.
  12145. *
  12146. * @listens keydown
  12147. */
  12148. ;
  12149. _proto.handleKeyDown = function handleKeyDown(event) {
  12150. // Esc button will trigger `click` event
  12151. if (keycode.isEventKey(event, 'Esc')) {
  12152. event.preventDefault();
  12153. event.stopPropagation();
  12154. this.trigger('click');
  12155. } else {
  12156. // Pass keypress handling up for unsupported keys
  12157. _Button.prototype.handleKeyDown.call(this, event);
  12158. }
  12159. };
  12160. return CloseButton;
  12161. }(Button);
  12162. Component.registerComponent('CloseButton', CloseButton);
  12163. /**
  12164. * Button to toggle between play and pause.
  12165. *
  12166. * @extends Button
  12167. */
  12168. var PlayToggle = /*#__PURE__*/function (_Button) {
  12169. inheritsLoose(PlayToggle, _Button);
  12170. /**
  12171. * Creates an instance of this class.
  12172. *
  12173. * @param {Player} player
  12174. * The `Player` that this class should be attached to.
  12175. *
  12176. * @param {Object} [options={}]
  12177. * The key/value store of player options.
  12178. */
  12179. function PlayToggle(player, options) {
  12180. var _this;
  12181. if (options === void 0) {
  12182. options = {};
  12183. }
  12184. _this = _Button.call(this, player, options) || this; // show or hide replay icon
  12185. options.replay = options.replay === undefined || options.replay;
  12186. _this.on(player, 'play', function (e) {
  12187. return _this.handlePlay(e);
  12188. });
  12189. _this.on(player, 'pause', function (e) {
  12190. return _this.handlePause(e);
  12191. });
  12192. if (options.replay) {
  12193. _this.on(player, 'ended', function (e) {
  12194. return _this.handleEnded(e);
  12195. });
  12196. }
  12197. return _this;
  12198. }
  12199. /**
  12200. * Builds the default DOM `className`.
  12201. *
  12202. * @return {string}
  12203. * The DOM `className` for this object.
  12204. */
  12205. var _proto = PlayToggle.prototype;
  12206. _proto.buildCSSClass = function buildCSSClass() {
  12207. return "vjs-play-control " + _Button.prototype.buildCSSClass.call(this);
  12208. }
  12209. /**
  12210. * This gets called when an `PlayToggle` is "clicked". See
  12211. * {@link ClickableComponent} for more detailed information on what a click can be.
  12212. *
  12213. * @param {EventTarget~Event} [event]
  12214. * The `keydown`, `tap`, or `click` event that caused this function to be
  12215. * called.
  12216. *
  12217. * @listens tap
  12218. * @listens click
  12219. */
  12220. ;
  12221. _proto.handleClick = function handleClick(event) {
  12222. if (this.player_.paused()) {
  12223. silencePromise(this.player_.play());
  12224. } else {
  12225. this.player_.pause();
  12226. }
  12227. }
  12228. /**
  12229. * This gets called once after the video has ended and the user seeks so that
  12230. * we can change the replay button back to a play button.
  12231. *
  12232. * @param {EventTarget~Event} [event]
  12233. * The event that caused this function to run.
  12234. *
  12235. * @listens Player#seeked
  12236. */
  12237. ;
  12238. _proto.handleSeeked = function handleSeeked(event) {
  12239. this.removeClass('vjs-ended');
  12240. if (this.player_.paused()) {
  12241. this.handlePause(event);
  12242. } else {
  12243. this.handlePlay(event);
  12244. }
  12245. }
  12246. /**
  12247. * Add the vjs-playing class to the element so it can change appearance.
  12248. *
  12249. * @param {EventTarget~Event} [event]
  12250. * The event that caused this function to run.
  12251. *
  12252. * @listens Player#play
  12253. */
  12254. ;
  12255. _proto.handlePlay = function handlePlay(event) {
  12256. this.removeClass('vjs-ended');
  12257. this.removeClass('vjs-paused');
  12258. this.addClass('vjs-playing'); // change the button text to "Pause"
  12259. this.controlText('Pause');
  12260. }
  12261. /**
  12262. * Add the vjs-paused class to the element so it can change appearance.
  12263. *
  12264. * @param {EventTarget~Event} [event]
  12265. * The event that caused this function to run.
  12266. *
  12267. * @listens Player#pause
  12268. */
  12269. ;
  12270. _proto.handlePause = function handlePause(event) {
  12271. this.removeClass('vjs-playing');
  12272. this.addClass('vjs-paused'); // change the button text to "Play"
  12273. this.controlText('Play');
  12274. }
  12275. /**
  12276. * Add the vjs-ended class to the element so it can change appearance
  12277. *
  12278. * @param {EventTarget~Event} [event]
  12279. * The event that caused this function to run.
  12280. *
  12281. * @listens Player#ended
  12282. */
  12283. ;
  12284. _proto.handleEnded = function handleEnded(event) {
  12285. var _this2 = this;
  12286. this.removeClass('vjs-playing');
  12287. this.addClass('vjs-ended'); // change the button text to "Replay"
  12288. this.controlText('Replay'); // on the next seek remove the replay button
  12289. this.one(this.player_, 'seeked', function (e) {
  12290. return _this2.handleSeeked(e);
  12291. });
  12292. };
  12293. return PlayToggle;
  12294. }(Button);
  12295. /**
  12296. * The text that should display over the `PlayToggle`s controls. Added for localization.
  12297. *
  12298. * @type {string}
  12299. * @private
  12300. */
  12301. PlayToggle.prototype.controlText_ = 'Play';
  12302. Component.registerComponent('PlayToggle', PlayToggle);
  12303. /**
  12304. * @file format-time.js
  12305. * @module format-time
  12306. */
  12307. /**
  12308. * Format seconds as a time string, H:MM:SS or M:SS. Supplying a guide (in
  12309. * seconds) will force a number of leading zeros to cover the length of the
  12310. * guide.
  12311. *
  12312. * @private
  12313. * @param {number} seconds
  12314. * Number of seconds to be turned into a string
  12315. *
  12316. * @param {number} guide
  12317. * Number (in seconds) to model the string after
  12318. *
  12319. * @return {string}
  12320. * Time formatted as H:MM:SS or M:SS
  12321. */
  12322. var defaultImplementation = function defaultImplementation(seconds, guide) {
  12323. seconds = seconds < 0 ? 0 : seconds;
  12324. var s = Math.floor(seconds % 60);
  12325. var m = Math.floor(seconds / 60 % 60);
  12326. var h = Math.floor(seconds / 3600);
  12327. var gm = Math.floor(guide / 60 % 60);
  12328. var gh = Math.floor(guide / 3600); // handle invalid times
  12329. if (isNaN(seconds) || seconds === Infinity) {
  12330. // '-' is false for all relational operators (e.g. <, >=) so this setting
  12331. // will add the minimum number of fields specified by the guide
  12332. h = m = s = '-';
  12333. } // Check if we need to show hours
  12334. h = h > 0 || gh > 0 ? h + ':' : ''; // If hours are showing, we may need to add a leading zero.
  12335. // Always show at least one digit of minutes.
  12336. m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':'; // Check if leading zero is need for seconds
  12337. s = s < 10 ? '0' + s : s;
  12338. return h + m + s;
  12339. }; // Internal pointer to the current implementation.
  12340. var implementation = defaultImplementation;
  12341. /**
  12342. * Replaces the default formatTime implementation with a custom implementation.
  12343. *
  12344. * @param {Function} customImplementation
  12345. * A function which will be used in place of the default formatTime
  12346. * implementation. Will receive the current time in seconds and the
  12347. * guide (in seconds) as arguments.
  12348. */
  12349. function setFormatTime(customImplementation) {
  12350. implementation = customImplementation;
  12351. }
  12352. /**
  12353. * Resets formatTime to the default implementation.
  12354. */
  12355. function resetFormatTime() {
  12356. implementation = defaultImplementation;
  12357. }
  12358. /**
  12359. * Delegates to either the default time formatting function or a custom
  12360. * function supplied via `setFormatTime`.
  12361. *
  12362. * Formats seconds as a time string (H:MM:SS or M:SS). Supplying a
  12363. * guide (in seconds) will force a number of leading zeros to cover the
  12364. * length of the guide.
  12365. *
  12366. * @static
  12367. * @example formatTime(125, 600) === "02:05"
  12368. * @param {number} seconds
  12369. * Number of seconds to be turned into a string
  12370. *
  12371. * @param {number} guide
  12372. * Number (in seconds) to model the string after
  12373. *
  12374. * @return {string}
  12375. * Time formatted as H:MM:SS or M:SS
  12376. */
  12377. function formatTime(seconds, guide) {
  12378. if (guide === void 0) {
  12379. guide = seconds;
  12380. }
  12381. return implementation(seconds, guide);
  12382. }
  12383. /**
  12384. * Displays time information about the video
  12385. *
  12386. * @extends Component
  12387. */
  12388. var TimeDisplay = /*#__PURE__*/function (_Component) {
  12389. inheritsLoose(TimeDisplay, _Component);
  12390. /**
  12391. * Creates an instance of this class.
  12392. *
  12393. * @param {Player} player
  12394. * The `Player` that this class should be attached to.
  12395. *
  12396. * @param {Object} [options]
  12397. * The key/value store of player options.
  12398. */
  12399. function TimeDisplay(player, options) {
  12400. var _this;
  12401. _this = _Component.call(this, player, options) || this;
  12402. _this.on(player, ['timeupdate', 'ended'], function (e) {
  12403. return _this.updateContent(e);
  12404. });
  12405. _this.updateTextNode_();
  12406. return _this;
  12407. }
  12408. /**
  12409. * Create the `Component`'s DOM element
  12410. *
  12411. * @return {Element}
  12412. * The element that was created.
  12413. */
  12414. var _proto = TimeDisplay.prototype;
  12415. _proto.createEl = function createEl$1() {
  12416. var className = this.buildCSSClass();
  12417. var el = _Component.prototype.createEl.call(this, 'div', {
  12418. className: className + " vjs-time-control vjs-control"
  12419. });
  12420. var span = createEl('span', {
  12421. className: 'vjs-control-text',
  12422. textContent: this.localize(this.labelText_) + "\xA0"
  12423. }, {
  12424. role: 'presentation'
  12425. });
  12426. el.appendChild(span);
  12427. this.contentEl_ = createEl('span', {
  12428. className: className + "-display"
  12429. }, {
  12430. // tell screen readers not to automatically read the time as it changes
  12431. 'aria-live': 'off',
  12432. // span elements have no implicit role, but some screen readers (notably VoiceOver)
  12433. // treat them as a break between items in the DOM when using arrow keys
  12434. // (or left-to-right swipes on iOS) to read contents of a page. Using
  12435. // role='presentation' causes VoiceOver to NOT treat this span as a break.
  12436. 'role': 'presentation'
  12437. });
  12438. el.appendChild(this.contentEl_);
  12439. return el;
  12440. };
  12441. _proto.dispose = function dispose() {
  12442. this.contentEl_ = null;
  12443. this.textNode_ = null;
  12444. _Component.prototype.dispose.call(this);
  12445. }
  12446. /**
  12447. * Updates the time display text node with a new time
  12448. *
  12449. * @param {number} [time=0] the time to update to
  12450. *
  12451. * @private
  12452. */
  12453. ;
  12454. _proto.updateTextNode_ = function updateTextNode_(time) {
  12455. var _this2 = this;
  12456. if (time === void 0) {
  12457. time = 0;
  12458. }
  12459. time = formatTime(time);
  12460. if (this.formattedTime_ === time) {
  12461. return;
  12462. }
  12463. this.formattedTime_ = time;
  12464. this.requestNamedAnimationFrame('TimeDisplay#updateTextNode_', function () {
  12465. if (!_this2.contentEl_) {
  12466. return;
  12467. }
  12468. var oldNode = _this2.textNode_;
  12469. if (oldNode && _this2.contentEl_.firstChild !== oldNode) {
  12470. oldNode = null;
  12471. 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.');
  12472. }
  12473. _this2.textNode_ = document.createTextNode(_this2.formattedTime_);
  12474. if (!_this2.textNode_) {
  12475. return;
  12476. }
  12477. if (oldNode) {
  12478. _this2.contentEl_.replaceChild(_this2.textNode_, oldNode);
  12479. } else {
  12480. _this2.contentEl_.appendChild(_this2.textNode_);
  12481. }
  12482. });
  12483. }
  12484. /**
  12485. * To be filled out in the child class, should update the displayed time
  12486. * in accordance with the fact that the current time has changed.
  12487. *
  12488. * @param {EventTarget~Event} [event]
  12489. * The `timeupdate` event that caused this to run.
  12490. *
  12491. * @listens Player#timeupdate
  12492. */
  12493. ;
  12494. _proto.updateContent = function updateContent(event) {};
  12495. return TimeDisplay;
  12496. }(Component);
  12497. /**
  12498. * The text that is added to the `TimeDisplay` for screen reader users.
  12499. *
  12500. * @type {string}
  12501. * @private
  12502. */
  12503. TimeDisplay.prototype.labelText_ = 'Time';
  12504. /**
  12505. * The text that should display over the `TimeDisplay`s controls. Added to for localization.
  12506. *
  12507. * @type {string}
  12508. * @private
  12509. *
  12510. * @deprecated in v7; controlText_ is not used in non-active display Components
  12511. */
  12512. TimeDisplay.prototype.controlText_ = 'Time';
  12513. Component.registerComponent('TimeDisplay', TimeDisplay);
  12514. /**
  12515. * Displays the current time
  12516. *
  12517. * @extends Component
  12518. */
  12519. var CurrentTimeDisplay = /*#__PURE__*/function (_TimeDisplay) {
  12520. inheritsLoose(CurrentTimeDisplay, _TimeDisplay);
  12521. function CurrentTimeDisplay() {
  12522. return _TimeDisplay.apply(this, arguments) || this;
  12523. }
  12524. var _proto = CurrentTimeDisplay.prototype;
  12525. /**
  12526. * Builds the default DOM `className`.
  12527. *
  12528. * @return {string}
  12529. * The DOM `className` for this object.
  12530. */
  12531. _proto.buildCSSClass = function buildCSSClass() {
  12532. return 'vjs-current-time';
  12533. }
  12534. /**
  12535. * Update current time display
  12536. *
  12537. * @param {EventTarget~Event} [event]
  12538. * The `timeupdate` event that caused this function to run.
  12539. *
  12540. * @listens Player#timeupdate
  12541. */
  12542. ;
  12543. _proto.updateContent = function updateContent(event) {
  12544. // Allows for smooth scrubbing, when player can't keep up.
  12545. var time;
  12546. if (this.player_.ended()) {
  12547. time = this.player_.duration();
  12548. } else {
  12549. time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  12550. }
  12551. this.updateTextNode_(time);
  12552. };
  12553. return CurrentTimeDisplay;
  12554. }(TimeDisplay);
  12555. /**
  12556. * The text that is added to the `CurrentTimeDisplay` for screen reader users.
  12557. *
  12558. * @type {string}
  12559. * @private
  12560. */
  12561. CurrentTimeDisplay.prototype.labelText_ = 'Current Time';
  12562. /**
  12563. * The text that should display over the `CurrentTimeDisplay`s controls. Added to for localization.
  12564. *
  12565. * @type {string}
  12566. * @private
  12567. *
  12568. * @deprecated in v7; controlText_ is not used in non-active display Components
  12569. */
  12570. CurrentTimeDisplay.prototype.controlText_ = 'Current Time';
  12571. Component.registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
  12572. /**
  12573. * Displays the duration
  12574. *
  12575. * @extends Component
  12576. */
  12577. var DurationDisplay = /*#__PURE__*/function (_TimeDisplay) {
  12578. inheritsLoose(DurationDisplay, _TimeDisplay);
  12579. /**
  12580. * Creates an instance of this class.
  12581. *
  12582. * @param {Player} player
  12583. * The `Player` that this class should be attached to.
  12584. *
  12585. * @param {Object} [options]
  12586. * The key/value store of player options.
  12587. */
  12588. function DurationDisplay(player, options) {
  12589. var _this;
  12590. _this = _TimeDisplay.call(this, player, options) || this;
  12591. var updateContent = function updateContent(e) {
  12592. return _this.updateContent(e);
  12593. }; // we do not want to/need to throttle duration changes,
  12594. // as they should always display the changed duration as
  12595. // it has changed
  12596. _this.on(player, 'durationchange', updateContent); // Listen to loadstart because the player duration is reset when a new media element is loaded,
  12597. // but the durationchange on the user agent will not fire.
  12598. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  12599. _this.on(player, 'loadstart', updateContent); // Also listen for timeupdate (in the parent) and loadedmetadata because removing those
  12600. // listeners could have broken dependent applications/libraries. These
  12601. // can likely be removed for 7.0.
  12602. _this.on(player, 'loadedmetadata', updateContent);
  12603. return _this;
  12604. }
  12605. /**
  12606. * Builds the default DOM `className`.
  12607. *
  12608. * @return {string}
  12609. * The DOM `className` for this object.
  12610. */
  12611. var _proto = DurationDisplay.prototype;
  12612. _proto.buildCSSClass = function buildCSSClass() {
  12613. return 'vjs-duration';
  12614. }
  12615. /**
  12616. * Update duration time display.
  12617. *
  12618. * @param {EventTarget~Event} [event]
  12619. * The `durationchange`, `timeupdate`, or `loadedmetadata` event that caused
  12620. * this function to be called.
  12621. *
  12622. * @listens Player#durationchange
  12623. * @listens Player#timeupdate
  12624. * @listens Player#loadedmetadata
  12625. */
  12626. ;
  12627. _proto.updateContent = function updateContent(event) {
  12628. var duration = this.player_.duration();
  12629. this.updateTextNode_(duration);
  12630. };
  12631. return DurationDisplay;
  12632. }(TimeDisplay);
  12633. /**
  12634. * The text that is added to the `DurationDisplay` for screen reader users.
  12635. *
  12636. * @type {string}
  12637. * @private
  12638. */
  12639. DurationDisplay.prototype.labelText_ = 'Duration';
  12640. /**
  12641. * The text that should display over the `DurationDisplay`s controls. Added to for localization.
  12642. *
  12643. * @type {string}
  12644. * @private
  12645. *
  12646. * @deprecated in v7; controlText_ is not used in non-active display Components
  12647. */
  12648. DurationDisplay.prototype.controlText_ = 'Duration';
  12649. Component.registerComponent('DurationDisplay', DurationDisplay);
  12650. /**
  12651. * The separator between the current time and duration.
  12652. * Can be hidden if it's not needed in the design.
  12653. *
  12654. * @extends Component
  12655. */
  12656. var TimeDivider = /*#__PURE__*/function (_Component) {
  12657. inheritsLoose(TimeDivider, _Component);
  12658. function TimeDivider() {
  12659. return _Component.apply(this, arguments) || this;
  12660. }
  12661. var _proto = TimeDivider.prototype;
  12662. /**
  12663. * Create the component's DOM element
  12664. *
  12665. * @return {Element}
  12666. * The element that was created.
  12667. */
  12668. _proto.createEl = function createEl() {
  12669. var el = _Component.prototype.createEl.call(this, 'div', {
  12670. className: 'vjs-time-control vjs-time-divider'
  12671. }, {
  12672. // this element and its contents can be hidden from assistive techs since
  12673. // it is made extraneous by the announcement of the control text
  12674. // for the current time and duration displays
  12675. 'aria-hidden': true
  12676. });
  12677. var div = _Component.prototype.createEl.call(this, 'div');
  12678. var span = _Component.prototype.createEl.call(this, 'span', {
  12679. textContent: '/'
  12680. });
  12681. div.appendChild(span);
  12682. el.appendChild(div);
  12683. return el;
  12684. };
  12685. return TimeDivider;
  12686. }(Component);
  12687. Component.registerComponent('TimeDivider', TimeDivider);
  12688. /**
  12689. * Displays the time left in the video
  12690. *
  12691. * @extends Component
  12692. */
  12693. var RemainingTimeDisplay = /*#__PURE__*/function (_TimeDisplay) {
  12694. inheritsLoose(RemainingTimeDisplay, _TimeDisplay);
  12695. /**
  12696. * Creates an instance of this class.
  12697. *
  12698. * @param {Player} player
  12699. * The `Player` that this class should be attached to.
  12700. *
  12701. * @param {Object} [options]
  12702. * The key/value store of player options.
  12703. */
  12704. function RemainingTimeDisplay(player, options) {
  12705. var _this;
  12706. _this = _TimeDisplay.call(this, player, options) || this;
  12707. _this.on(player, 'durationchange', function (e) {
  12708. return _this.updateContent(e);
  12709. });
  12710. return _this;
  12711. }
  12712. /**
  12713. * Builds the default DOM `className`.
  12714. *
  12715. * @return {string}
  12716. * The DOM `className` for this object.
  12717. */
  12718. var _proto = RemainingTimeDisplay.prototype;
  12719. _proto.buildCSSClass = function buildCSSClass() {
  12720. return 'vjs-remaining-time';
  12721. }
  12722. /**
  12723. * Create the `Component`'s DOM element with the "minus" characted prepend to the time
  12724. *
  12725. * @return {Element}
  12726. * The element that was created.
  12727. */
  12728. ;
  12729. _proto.createEl = function createEl$1() {
  12730. var el = _TimeDisplay.prototype.createEl.call(this);
  12731. if (this.options_.displayNegative !== false) {
  12732. el.insertBefore(createEl('span', {}, {
  12733. 'aria-hidden': true
  12734. }, '-'), this.contentEl_);
  12735. }
  12736. return el;
  12737. }
  12738. /**
  12739. * Update remaining time display.
  12740. *
  12741. * @param {EventTarget~Event} [event]
  12742. * The `timeupdate` or `durationchange` event that caused this to run.
  12743. *
  12744. * @listens Player#timeupdate
  12745. * @listens Player#durationchange
  12746. */
  12747. ;
  12748. _proto.updateContent = function updateContent(event) {
  12749. if (typeof this.player_.duration() !== 'number') {
  12750. return;
  12751. }
  12752. var time; // @deprecated We should only use remainingTimeDisplay
  12753. // as of video.js 7
  12754. if (this.player_.ended()) {
  12755. time = 0;
  12756. } else if (this.player_.remainingTimeDisplay) {
  12757. time = this.player_.remainingTimeDisplay();
  12758. } else {
  12759. time = this.player_.remainingTime();
  12760. }
  12761. this.updateTextNode_(time);
  12762. };
  12763. return RemainingTimeDisplay;
  12764. }(TimeDisplay);
  12765. /**
  12766. * The text that is added to the `RemainingTimeDisplay` for screen reader users.
  12767. *
  12768. * @type {string}
  12769. * @private
  12770. */
  12771. RemainingTimeDisplay.prototype.labelText_ = 'Remaining Time';
  12772. /**
  12773. * The text that should display over the `RemainingTimeDisplay`s controls. Added to for localization.
  12774. *
  12775. * @type {string}
  12776. * @private
  12777. *
  12778. * @deprecated in v7; controlText_ is not used in non-active display Components
  12779. */
  12780. RemainingTimeDisplay.prototype.controlText_ = 'Remaining Time';
  12781. Component.registerComponent('RemainingTimeDisplay', RemainingTimeDisplay);
  12782. /**
  12783. * Displays the live indicator when duration is Infinity.
  12784. *
  12785. * @extends Component
  12786. */
  12787. var LiveDisplay = /*#__PURE__*/function (_Component) {
  12788. inheritsLoose(LiveDisplay, _Component);
  12789. /**
  12790. * Creates an instance of this class.
  12791. *
  12792. * @param {Player} player
  12793. * The `Player` that this class should be attached to.
  12794. *
  12795. * @param {Object} [options]
  12796. * The key/value store of player options.
  12797. */
  12798. function LiveDisplay(player, options) {
  12799. var _this;
  12800. _this = _Component.call(this, player, options) || this;
  12801. _this.updateShowing();
  12802. _this.on(_this.player(), 'durationchange', function (e) {
  12803. return _this.updateShowing(e);
  12804. });
  12805. return _this;
  12806. }
  12807. /**
  12808. * Create the `Component`'s DOM element
  12809. *
  12810. * @return {Element}
  12811. * The element that was created.
  12812. */
  12813. var _proto = LiveDisplay.prototype;
  12814. _proto.createEl = function createEl$1() {
  12815. var el = _Component.prototype.createEl.call(this, 'div', {
  12816. className: 'vjs-live-control vjs-control'
  12817. });
  12818. this.contentEl_ = createEl('div', {
  12819. className: 'vjs-live-display'
  12820. }, {
  12821. 'aria-live': 'off'
  12822. });
  12823. this.contentEl_.appendChild(createEl('span', {
  12824. className: 'vjs-control-text',
  12825. textContent: this.localize('Stream Type') + "\xA0"
  12826. }));
  12827. this.contentEl_.appendChild(document.createTextNode(this.localize('LIVE')));
  12828. el.appendChild(this.contentEl_);
  12829. return el;
  12830. };
  12831. _proto.dispose = function dispose() {
  12832. this.contentEl_ = null;
  12833. _Component.prototype.dispose.call(this);
  12834. }
  12835. /**
  12836. * Check the duration to see if the LiveDisplay should be showing or not. Then show/hide
  12837. * it accordingly
  12838. *
  12839. * @param {EventTarget~Event} [event]
  12840. * The {@link Player#durationchange} event that caused this function to run.
  12841. *
  12842. * @listens Player#durationchange
  12843. */
  12844. ;
  12845. _proto.updateShowing = function updateShowing(event) {
  12846. if (this.player().duration() === Infinity) {
  12847. this.show();
  12848. } else {
  12849. this.hide();
  12850. }
  12851. };
  12852. return LiveDisplay;
  12853. }(Component);
  12854. Component.registerComponent('LiveDisplay', LiveDisplay);
  12855. /**
  12856. * Displays the live indicator when duration is Infinity.
  12857. *
  12858. * @extends Component
  12859. */
  12860. var SeekToLive = /*#__PURE__*/function (_Button) {
  12861. inheritsLoose(SeekToLive, _Button);
  12862. /**
  12863. * Creates an instance of this class.
  12864. *
  12865. * @param {Player} player
  12866. * The `Player` that this class should be attached to.
  12867. *
  12868. * @param {Object} [options]
  12869. * The key/value store of player options.
  12870. */
  12871. function SeekToLive(player, options) {
  12872. var _this;
  12873. _this = _Button.call(this, player, options) || this;
  12874. _this.updateLiveEdgeStatus();
  12875. if (_this.player_.liveTracker) {
  12876. _this.updateLiveEdgeStatusHandler_ = function (e) {
  12877. return _this.updateLiveEdgeStatus(e);
  12878. };
  12879. _this.on(_this.player_.liveTracker, 'liveedgechange', _this.updateLiveEdgeStatusHandler_);
  12880. }
  12881. return _this;
  12882. }
  12883. /**
  12884. * Create the `Component`'s DOM element
  12885. *
  12886. * @return {Element}
  12887. * The element that was created.
  12888. */
  12889. var _proto = SeekToLive.prototype;
  12890. _proto.createEl = function createEl$1() {
  12891. var el = _Button.prototype.createEl.call(this, 'button', {
  12892. className: 'vjs-seek-to-live-control vjs-control'
  12893. });
  12894. this.textEl_ = createEl('span', {
  12895. className: 'vjs-seek-to-live-text',
  12896. textContent: this.localize('LIVE')
  12897. }, {
  12898. 'aria-hidden': 'true'
  12899. });
  12900. el.appendChild(this.textEl_);
  12901. return el;
  12902. }
  12903. /**
  12904. * Update the state of this button if we are at the live edge
  12905. * or not
  12906. */
  12907. ;
  12908. _proto.updateLiveEdgeStatus = function updateLiveEdgeStatus() {
  12909. // default to live edge
  12910. if (!this.player_.liveTracker || this.player_.liveTracker.atLiveEdge()) {
  12911. this.setAttribute('aria-disabled', true);
  12912. this.addClass('vjs-at-live-edge');
  12913. this.controlText('Seek to live, currently playing live');
  12914. } else {
  12915. this.setAttribute('aria-disabled', false);
  12916. this.removeClass('vjs-at-live-edge');
  12917. this.controlText('Seek to live, currently behind live');
  12918. }
  12919. }
  12920. /**
  12921. * On click bring us as near to the live point as possible.
  12922. * This requires that we wait for the next `live-seekable-change`
  12923. * event which will happen every segment length seconds.
  12924. */
  12925. ;
  12926. _proto.handleClick = function handleClick() {
  12927. this.player_.liveTracker.seekToLiveEdge();
  12928. }
  12929. /**
  12930. * Dispose of the element and stop tracking
  12931. */
  12932. ;
  12933. _proto.dispose = function dispose() {
  12934. if (this.player_.liveTracker) {
  12935. this.off(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatusHandler_);
  12936. }
  12937. this.textEl_ = null;
  12938. _Button.prototype.dispose.call(this);
  12939. };
  12940. return SeekToLive;
  12941. }(Button);
  12942. SeekToLive.prototype.controlText_ = 'Seek to live, currently playing live';
  12943. Component.registerComponent('SeekToLive', SeekToLive);
  12944. /**
  12945. * Keep a number between a min and a max value
  12946. *
  12947. * @param {number} number
  12948. * The number to clamp
  12949. *
  12950. * @param {number} min
  12951. * The minimum value
  12952. * @param {number} max
  12953. * The maximum value
  12954. *
  12955. * @return {number}
  12956. * the clamped number
  12957. */
  12958. var clamp = function clamp(number, min, max) {
  12959. number = Number(number);
  12960. return Math.min(max, Math.max(min, isNaN(number) ? min : number));
  12961. };
  12962. /**
  12963. * The base functionality for a slider. Can be vertical or horizontal.
  12964. * For instance the volume bar or the seek bar on a video is a slider.
  12965. *
  12966. * @extends Component
  12967. */
  12968. var Slider = /*#__PURE__*/function (_Component) {
  12969. inheritsLoose(Slider, _Component);
  12970. /**
  12971. * Create an instance of this class
  12972. *
  12973. * @param {Player} player
  12974. * The `Player` that this class should be attached to.
  12975. *
  12976. * @param {Object} [options]
  12977. * The key/value store of player options.
  12978. */
  12979. function Slider(player, options) {
  12980. var _this;
  12981. _this = _Component.call(this, player, options) || this;
  12982. _this.handleMouseDown_ = function (e) {
  12983. return _this.handleMouseDown(e);
  12984. };
  12985. _this.handleMouseUp_ = function (e) {
  12986. return _this.handleMouseUp(e);
  12987. };
  12988. _this.handleKeyDown_ = function (e) {
  12989. return _this.handleKeyDown(e);
  12990. };
  12991. _this.handleClick_ = function (e) {
  12992. return _this.handleClick(e);
  12993. };
  12994. _this.handleMouseMove_ = function (e) {
  12995. return _this.handleMouseMove(e);
  12996. };
  12997. _this.update_ = function (e) {
  12998. return _this.update(e);
  12999. }; // Set property names to bar to match with the child Slider class is looking for
  13000. _this.bar = _this.getChild(_this.options_.barName); // Set a horizontal or vertical class on the slider depending on the slider type
  13001. _this.vertical(!!_this.options_.vertical);
  13002. _this.enable();
  13003. return _this;
  13004. }
  13005. /**
  13006. * Are controls are currently enabled for this slider or not.
  13007. *
  13008. * @return {boolean}
  13009. * true if controls are enabled, false otherwise
  13010. */
  13011. var _proto = Slider.prototype;
  13012. _proto.enabled = function enabled() {
  13013. return this.enabled_;
  13014. }
  13015. /**
  13016. * Enable controls for this slider if they are disabled
  13017. */
  13018. ;
  13019. _proto.enable = function enable() {
  13020. if (this.enabled()) {
  13021. return;
  13022. }
  13023. this.on('mousedown', this.handleMouseDown_);
  13024. this.on('touchstart', this.handleMouseDown_);
  13025. this.on('keydown', this.handleKeyDown_);
  13026. this.on('click', this.handleClick_); // TODO: deprecated, controlsvisible does not seem to be fired
  13027. this.on(this.player_, 'controlsvisible', this.update);
  13028. if (this.playerEvent) {
  13029. this.on(this.player_, this.playerEvent, this.update);
  13030. }
  13031. this.removeClass('disabled');
  13032. this.setAttribute('tabindex', 0);
  13033. this.enabled_ = true;
  13034. }
  13035. /**
  13036. * Disable controls for this slider if they are enabled
  13037. */
  13038. ;
  13039. _proto.disable = function disable() {
  13040. if (!this.enabled()) {
  13041. return;
  13042. }
  13043. var doc = this.bar.el_.ownerDocument;
  13044. this.off('mousedown', this.handleMouseDown_);
  13045. this.off('touchstart', this.handleMouseDown_);
  13046. this.off('keydown', this.handleKeyDown_);
  13047. this.off('click', this.handleClick_);
  13048. this.off(this.player_, 'controlsvisible', this.update_);
  13049. this.off(doc, 'mousemove', this.handleMouseMove_);
  13050. this.off(doc, 'mouseup', this.handleMouseUp_);
  13051. this.off(doc, 'touchmove', this.handleMouseMove_);
  13052. this.off(doc, 'touchend', this.handleMouseUp_);
  13053. this.removeAttribute('tabindex');
  13054. this.addClass('disabled');
  13055. if (this.playerEvent) {
  13056. this.off(this.player_, this.playerEvent, this.update);
  13057. }
  13058. this.enabled_ = false;
  13059. }
  13060. /**
  13061. * Create the `Slider`s DOM element.
  13062. *
  13063. * @param {string} type
  13064. * Type of element to create.
  13065. *
  13066. * @param {Object} [props={}]
  13067. * List of properties in Object form.
  13068. *
  13069. * @param {Object} [attributes={}]
  13070. * list of attributes in Object form.
  13071. *
  13072. * @return {Element}
  13073. * The element that gets created.
  13074. */
  13075. ;
  13076. _proto.createEl = function createEl(type, props, attributes) {
  13077. if (props === void 0) {
  13078. props = {};
  13079. }
  13080. if (attributes === void 0) {
  13081. attributes = {};
  13082. }
  13083. // Add the slider element class to all sub classes
  13084. props.className = props.className + ' vjs-slider';
  13085. props = assign({
  13086. tabIndex: 0
  13087. }, props);
  13088. attributes = assign({
  13089. 'role': 'slider',
  13090. 'aria-valuenow': 0,
  13091. 'aria-valuemin': 0,
  13092. 'aria-valuemax': 100,
  13093. 'tabIndex': 0
  13094. }, attributes);
  13095. return _Component.prototype.createEl.call(this, type, props, attributes);
  13096. }
  13097. /**
  13098. * Handle `mousedown` or `touchstart` events on the `Slider`.
  13099. *
  13100. * @param {EventTarget~Event} event
  13101. * `mousedown` or `touchstart` event that triggered this function
  13102. *
  13103. * @listens mousedown
  13104. * @listens touchstart
  13105. * @fires Slider#slideractive
  13106. */
  13107. ;
  13108. _proto.handleMouseDown = function handleMouseDown(event) {
  13109. var doc = this.bar.el_.ownerDocument;
  13110. if (event.type === 'mousedown') {
  13111. event.preventDefault();
  13112. } // Do not call preventDefault() on touchstart in Chrome
  13113. // to avoid console warnings. Use a 'touch-action: none' style
  13114. // instead to prevent unintented scrolling.
  13115. // https://developers.google.com/web/updates/2017/01/scrolling-intervention
  13116. if (event.type === 'touchstart' && !IS_CHROME) {
  13117. event.preventDefault();
  13118. }
  13119. blockTextSelection();
  13120. this.addClass('vjs-sliding');
  13121. /**
  13122. * Triggered when the slider is in an active state
  13123. *
  13124. * @event Slider#slideractive
  13125. * @type {EventTarget~Event}
  13126. */
  13127. this.trigger('slideractive');
  13128. this.on(doc, 'mousemove', this.handleMouseMove_);
  13129. this.on(doc, 'mouseup', this.handleMouseUp_);
  13130. this.on(doc, 'touchmove', this.handleMouseMove_);
  13131. this.on(doc, 'touchend', this.handleMouseUp_);
  13132. this.handleMouseMove(event, true);
  13133. }
  13134. /**
  13135. * Handle the `mousemove`, `touchmove`, and `mousedown` events on this `Slider`.
  13136. * The `mousemove` and `touchmove` events will only only trigger this function during
  13137. * `mousedown` and `touchstart`. This is due to {@link Slider#handleMouseDown} and
  13138. * {@link Slider#handleMouseUp}.
  13139. *
  13140. * @param {EventTarget~Event} event
  13141. * `mousedown`, `mousemove`, `touchstart`, or `touchmove` event that triggered
  13142. * this function
  13143. * @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.
  13144. *
  13145. * @listens mousemove
  13146. * @listens touchmove
  13147. */
  13148. ;
  13149. _proto.handleMouseMove = function handleMouseMove(event) {}
  13150. /**
  13151. * Handle `mouseup` or `touchend` events on the `Slider`.
  13152. *
  13153. * @param {EventTarget~Event} event
  13154. * `mouseup` or `touchend` event that triggered this function.
  13155. *
  13156. * @listens touchend
  13157. * @listens mouseup
  13158. * @fires Slider#sliderinactive
  13159. */
  13160. ;
  13161. _proto.handleMouseUp = function handleMouseUp() {
  13162. var doc = this.bar.el_.ownerDocument;
  13163. unblockTextSelection();
  13164. this.removeClass('vjs-sliding');
  13165. /**
  13166. * Triggered when the slider is no longer in an active state.
  13167. *
  13168. * @event Slider#sliderinactive
  13169. * @type {EventTarget~Event}
  13170. */
  13171. this.trigger('sliderinactive');
  13172. this.off(doc, 'mousemove', this.handleMouseMove_);
  13173. this.off(doc, 'mouseup', this.handleMouseUp_);
  13174. this.off(doc, 'touchmove', this.handleMouseMove_);
  13175. this.off(doc, 'touchend', this.handleMouseUp_);
  13176. this.update();
  13177. }
  13178. /**
  13179. * Update the progress bar of the `Slider`.
  13180. *
  13181. * @return {number}
  13182. * The percentage of progress the progress bar represents as a
  13183. * number from 0 to 1.
  13184. */
  13185. ;
  13186. _proto.update = function update() {
  13187. var _this2 = this;
  13188. // In VolumeBar init we have a setTimeout for update that pops and update
  13189. // to the end of the execution stack. The player is destroyed before then
  13190. // update will cause an error
  13191. // If there's no bar...
  13192. if (!this.el_ || !this.bar) {
  13193. return;
  13194. } // clamp progress between 0 and 1
  13195. // and only round to four decimal places, as we round to two below
  13196. var progress = this.getProgress();
  13197. if (progress === this.progress_) {
  13198. return progress;
  13199. }
  13200. this.progress_ = progress;
  13201. this.requestNamedAnimationFrame('Slider#update', function () {
  13202. // Set the new bar width or height
  13203. var sizeKey = _this2.vertical() ? 'height' : 'width'; // Convert to a percentage for css value
  13204. _this2.bar.el().style[sizeKey] = (progress * 100).toFixed(2) + '%';
  13205. });
  13206. return progress;
  13207. }
  13208. /**
  13209. * Get the percentage of the bar that should be filled
  13210. * but clamped and rounded.
  13211. *
  13212. * @return {number}
  13213. * percentage filled that the slider is
  13214. */
  13215. ;
  13216. _proto.getProgress = function getProgress() {
  13217. return Number(clamp(this.getPercent(), 0, 1).toFixed(4));
  13218. }
  13219. /**
  13220. * Calculate distance for slider
  13221. *
  13222. * @param {EventTarget~Event} event
  13223. * The event that caused this function to run.
  13224. *
  13225. * @return {number}
  13226. * The current position of the Slider.
  13227. * - position.x for vertical `Slider`s
  13228. * - position.y for horizontal `Slider`s
  13229. */
  13230. ;
  13231. _proto.calculateDistance = function calculateDistance(event) {
  13232. var position = getPointerPosition(this.el_, event);
  13233. if (this.vertical()) {
  13234. return position.y;
  13235. }
  13236. return position.x;
  13237. }
  13238. /**
  13239. * Handle a `keydown` event on the `Slider`. Watches for left, rigth, up, and down
  13240. * arrow keys. This function will only be called when the slider has focus. See
  13241. * {@link Slider#handleFocus} and {@link Slider#handleBlur}.
  13242. *
  13243. * @param {EventTarget~Event} event
  13244. * the `keydown` event that caused this function to run.
  13245. *
  13246. * @listens keydown
  13247. */
  13248. ;
  13249. _proto.handleKeyDown = function handleKeyDown(event) {
  13250. // Left and Down Arrows
  13251. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  13252. event.preventDefault();
  13253. event.stopPropagation();
  13254. this.stepBack(); // Up and Right Arrows
  13255. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  13256. event.preventDefault();
  13257. event.stopPropagation();
  13258. this.stepForward();
  13259. } else {
  13260. // Pass keydown handling up for unsupported keys
  13261. _Component.prototype.handleKeyDown.call(this, event);
  13262. }
  13263. }
  13264. /**
  13265. * Listener for click events on slider, used to prevent clicks
  13266. * from bubbling up to parent elements like button menus.
  13267. *
  13268. * @param {Object} event
  13269. * Event that caused this object to run
  13270. */
  13271. ;
  13272. _proto.handleClick = function handleClick(event) {
  13273. event.stopPropagation();
  13274. event.preventDefault();
  13275. }
  13276. /**
  13277. * Get/set if slider is horizontal for vertical
  13278. *
  13279. * @param {boolean} [bool]
  13280. * - true if slider is vertical,
  13281. * - false is horizontal
  13282. *
  13283. * @return {boolean}
  13284. * - true if slider is vertical, and getting
  13285. * - false if the slider is horizontal, and getting
  13286. */
  13287. ;
  13288. _proto.vertical = function vertical(bool) {
  13289. if (bool === undefined) {
  13290. return this.vertical_ || false;
  13291. }
  13292. this.vertical_ = !!bool;
  13293. if (this.vertical_) {
  13294. this.addClass('vjs-slider-vertical');
  13295. } else {
  13296. this.addClass('vjs-slider-horizontal');
  13297. }
  13298. };
  13299. return Slider;
  13300. }(Component);
  13301. Component.registerComponent('Slider', Slider);
  13302. var percentify = function percentify(time, end) {
  13303. return clamp(time / end * 100, 0, 100).toFixed(2) + '%';
  13304. };
  13305. /**
  13306. * Shows loading progress
  13307. *
  13308. * @extends Component
  13309. */
  13310. var LoadProgressBar = /*#__PURE__*/function (_Component) {
  13311. inheritsLoose(LoadProgressBar, _Component);
  13312. /**
  13313. * Creates an instance of this class.
  13314. *
  13315. * @param {Player} player
  13316. * The `Player` that this class should be attached to.
  13317. *
  13318. * @param {Object} [options]
  13319. * The key/value store of player options.
  13320. */
  13321. function LoadProgressBar(player, options) {
  13322. var _this;
  13323. _this = _Component.call(this, player, options) || this;
  13324. _this.partEls_ = [];
  13325. _this.on(player, 'progress', function (e) {
  13326. return _this.update(e);
  13327. });
  13328. return _this;
  13329. }
  13330. /**
  13331. * Create the `Component`'s DOM element
  13332. *
  13333. * @return {Element}
  13334. * The element that was created.
  13335. */
  13336. var _proto = LoadProgressBar.prototype;
  13337. _proto.createEl = function createEl$1() {
  13338. var el = _Component.prototype.createEl.call(this, 'div', {
  13339. className: 'vjs-load-progress'
  13340. });
  13341. var wrapper = createEl('span', {
  13342. className: 'vjs-control-text'
  13343. });
  13344. var loadedText = createEl('span', {
  13345. textContent: this.localize('Loaded')
  13346. });
  13347. var separator = document.createTextNode(': ');
  13348. this.percentageEl_ = createEl('span', {
  13349. className: 'vjs-control-text-loaded-percentage',
  13350. textContent: '0%'
  13351. });
  13352. el.appendChild(wrapper);
  13353. wrapper.appendChild(loadedText);
  13354. wrapper.appendChild(separator);
  13355. wrapper.appendChild(this.percentageEl_);
  13356. return el;
  13357. };
  13358. _proto.dispose = function dispose() {
  13359. this.partEls_ = null;
  13360. this.percentageEl_ = null;
  13361. _Component.prototype.dispose.call(this);
  13362. }
  13363. /**
  13364. * Update progress bar
  13365. *
  13366. * @param {EventTarget~Event} [event]
  13367. * The `progress` event that caused this function to run.
  13368. *
  13369. * @listens Player#progress
  13370. */
  13371. ;
  13372. _proto.update = function update(event) {
  13373. var _this2 = this;
  13374. this.requestNamedAnimationFrame('LoadProgressBar#update', function () {
  13375. var liveTracker = _this2.player_.liveTracker;
  13376. var buffered = _this2.player_.buffered();
  13377. var duration = liveTracker && liveTracker.isLive() ? liveTracker.seekableEnd() : _this2.player_.duration();
  13378. var bufferedEnd = _this2.player_.bufferedEnd();
  13379. var children = _this2.partEls_;
  13380. var percent = percentify(bufferedEnd, duration);
  13381. if (_this2.percent_ !== percent) {
  13382. // update the width of the progress bar
  13383. _this2.el_.style.width = percent; // update the control-text
  13384. textContent(_this2.percentageEl_, percent);
  13385. _this2.percent_ = percent;
  13386. } // add child elements to represent the individual buffered time ranges
  13387. for (var i = 0; i < buffered.length; i++) {
  13388. var start = buffered.start(i);
  13389. var end = buffered.end(i);
  13390. var part = children[i];
  13391. if (!part) {
  13392. part = _this2.el_.appendChild(createEl());
  13393. children[i] = part;
  13394. } // only update if changed
  13395. if (part.dataset.start === start && part.dataset.end === end) {
  13396. continue;
  13397. }
  13398. part.dataset.start = start;
  13399. part.dataset.end = end; // set the percent based on the width of the progress bar (bufferedEnd)
  13400. part.style.left = percentify(start, bufferedEnd);
  13401. part.style.width = percentify(end - start, bufferedEnd);
  13402. } // remove unused buffered range elements
  13403. for (var _i = children.length; _i > buffered.length; _i--) {
  13404. _this2.el_.removeChild(children[_i - 1]);
  13405. }
  13406. children.length = buffered.length;
  13407. });
  13408. };
  13409. return LoadProgressBar;
  13410. }(Component);
  13411. Component.registerComponent('LoadProgressBar', LoadProgressBar);
  13412. /**
  13413. * Time tooltips display a time above the progress bar.
  13414. *
  13415. * @extends Component
  13416. */
  13417. var TimeTooltip = /*#__PURE__*/function (_Component) {
  13418. inheritsLoose(TimeTooltip, _Component);
  13419. /**
  13420. * Creates an instance of this class.
  13421. *
  13422. * @param {Player} player
  13423. * The {@link Player} that this class should be attached to.
  13424. *
  13425. * @param {Object} [options]
  13426. * The key/value store of player options.
  13427. */
  13428. function TimeTooltip(player, options) {
  13429. var _this;
  13430. _this = _Component.call(this, player, options) || this;
  13431. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13432. return _this;
  13433. }
  13434. /**
  13435. * Create the time tooltip DOM element
  13436. *
  13437. * @return {Element}
  13438. * The element that was created.
  13439. */
  13440. var _proto = TimeTooltip.prototype;
  13441. _proto.createEl = function createEl() {
  13442. return _Component.prototype.createEl.call(this, 'div', {
  13443. className: 'vjs-time-tooltip'
  13444. }, {
  13445. 'aria-hidden': 'true'
  13446. });
  13447. }
  13448. /**
  13449. * Updates the position of the time tooltip relative to the `SeekBar`.
  13450. *
  13451. * @param {Object} seekBarRect
  13452. * The `ClientRect` for the {@link SeekBar} element.
  13453. *
  13454. * @param {number} seekBarPoint
  13455. * A number from 0 to 1, representing a horizontal reference point
  13456. * from the left edge of the {@link SeekBar}
  13457. */
  13458. ;
  13459. _proto.update = function update(seekBarRect, seekBarPoint, content) {
  13460. var tooltipRect = findPosition(this.el_);
  13461. var playerRect = getBoundingClientRect(this.player_.el());
  13462. var seekBarPointPx = seekBarRect.width * seekBarPoint; // do nothing if either rect isn't available
  13463. // for example, if the player isn't in the DOM for testing
  13464. if (!playerRect || !tooltipRect) {
  13465. return;
  13466. } // This is the space left of the `seekBarPoint` available within the bounds
  13467. // of the player. We calculate any gap between the left edge of the player
  13468. // and the left edge of the `SeekBar` and add the number of pixels in the
  13469. // `SeekBar` before hitting the `seekBarPoint`
  13470. var spaceLeftOfPoint = seekBarRect.left - playerRect.left + seekBarPointPx; // This is the space right of the `seekBarPoint` available within the bounds
  13471. // of the player. We calculate the number of pixels from the `seekBarPoint`
  13472. // to the right edge of the `SeekBar` and add to that any gap between the
  13473. // right edge of the `SeekBar` and the player.
  13474. var spaceRightOfPoint = seekBarRect.width - seekBarPointPx + (playerRect.right - seekBarRect.right); // This is the number of pixels by which the tooltip will need to be pulled
  13475. // further to the right to center it over the `seekBarPoint`.
  13476. var pullTooltipBy = tooltipRect.width / 2; // Adjust the `pullTooltipBy` distance to the left or right depending on
  13477. // the results of the space calculations above.
  13478. if (spaceLeftOfPoint < pullTooltipBy) {
  13479. pullTooltipBy += pullTooltipBy - spaceLeftOfPoint;
  13480. } else if (spaceRightOfPoint < pullTooltipBy) {
  13481. pullTooltipBy = spaceRightOfPoint;
  13482. } // Due to the imprecision of decimal/ratio based calculations and varying
  13483. // rounding behaviors, there are cases where the spacing adjustment is off
  13484. // by a pixel or two. This adds insurance to these calculations.
  13485. if (pullTooltipBy < 0) {
  13486. pullTooltipBy = 0;
  13487. } else if (pullTooltipBy > tooltipRect.width) {
  13488. pullTooltipBy = tooltipRect.width;
  13489. } // prevent small width fluctuations within 0.4px from
  13490. // changing the value below.
  13491. // This really helps for live to prevent the play
  13492. // progress time tooltip from jittering
  13493. pullTooltipBy = Math.round(pullTooltipBy);
  13494. this.el_.style.right = "-" + pullTooltipBy + "px";
  13495. this.write(content);
  13496. }
  13497. /**
  13498. * Write the time to the tooltip DOM element.
  13499. *
  13500. * @param {string} content
  13501. * The formatted time for the tooltip.
  13502. */
  13503. ;
  13504. _proto.write = function write(content) {
  13505. textContent(this.el_, content);
  13506. }
  13507. /**
  13508. * Updates the position of the time tooltip relative to the `SeekBar`.
  13509. *
  13510. * @param {Object} seekBarRect
  13511. * The `ClientRect` for the {@link SeekBar} element.
  13512. *
  13513. * @param {number} seekBarPoint
  13514. * A number from 0 to 1, representing a horizontal reference point
  13515. * from the left edge of the {@link SeekBar}
  13516. *
  13517. * @param {number} time
  13518. * The time to update the tooltip to, not used during live playback
  13519. *
  13520. * @param {Function} cb
  13521. * A function that will be called during the request animation frame
  13522. * for tooltips that need to do additional animations from the default
  13523. */
  13524. ;
  13525. _proto.updateTime = function updateTime(seekBarRect, seekBarPoint, time, cb) {
  13526. var _this2 = this;
  13527. this.requestNamedAnimationFrame('TimeTooltip#updateTime', function () {
  13528. var content;
  13529. var duration = _this2.player_.duration();
  13530. if (_this2.player_.liveTracker && _this2.player_.liveTracker.isLive()) {
  13531. var liveWindow = _this2.player_.liveTracker.liveWindow();
  13532. var secondsBehind = liveWindow - seekBarPoint * liveWindow;
  13533. content = (secondsBehind < 1 ? '' : '-') + formatTime(secondsBehind, liveWindow);
  13534. } else {
  13535. content = formatTime(time, duration);
  13536. }
  13537. _this2.update(seekBarRect, seekBarPoint, content);
  13538. if (cb) {
  13539. cb();
  13540. }
  13541. });
  13542. };
  13543. return TimeTooltip;
  13544. }(Component);
  13545. Component.registerComponent('TimeTooltip', TimeTooltip);
  13546. /**
  13547. * Used by {@link SeekBar} to display media playback progress as part of the
  13548. * {@link ProgressControl}.
  13549. *
  13550. * @extends Component
  13551. */
  13552. var PlayProgressBar = /*#__PURE__*/function (_Component) {
  13553. inheritsLoose(PlayProgressBar, _Component);
  13554. /**
  13555. * Creates an instance of this class.
  13556. *
  13557. * @param {Player} player
  13558. * The {@link Player} that this class should be attached to.
  13559. *
  13560. * @param {Object} [options]
  13561. * The key/value store of player options.
  13562. */
  13563. function PlayProgressBar(player, options) {
  13564. var _this;
  13565. _this = _Component.call(this, player, options) || this;
  13566. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13567. return _this;
  13568. }
  13569. /**
  13570. * Create the the DOM element for this class.
  13571. *
  13572. * @return {Element}
  13573. * The element that was created.
  13574. */
  13575. var _proto = PlayProgressBar.prototype;
  13576. _proto.createEl = function createEl() {
  13577. return _Component.prototype.createEl.call(this, 'div', {
  13578. className: 'vjs-play-progress vjs-slider-bar'
  13579. }, {
  13580. 'aria-hidden': 'true'
  13581. });
  13582. }
  13583. /**
  13584. * Enqueues updates to its own DOM as well as the DOM of its
  13585. * {@link TimeTooltip} child.
  13586. *
  13587. * @param {Object} seekBarRect
  13588. * The `ClientRect` for the {@link SeekBar} element.
  13589. *
  13590. * @param {number} seekBarPoint
  13591. * A number from 0 to 1, representing a horizontal reference point
  13592. * from the left edge of the {@link SeekBar}
  13593. */
  13594. ;
  13595. _proto.update = function update(seekBarRect, seekBarPoint) {
  13596. var timeTooltip = this.getChild('timeTooltip');
  13597. if (!timeTooltip) {
  13598. return;
  13599. }
  13600. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  13601. timeTooltip.updateTime(seekBarRect, seekBarPoint, time);
  13602. };
  13603. return PlayProgressBar;
  13604. }(Component);
  13605. /**
  13606. * Default options for {@link PlayProgressBar}.
  13607. *
  13608. * @type {Object}
  13609. * @private
  13610. */
  13611. PlayProgressBar.prototype.options_ = {
  13612. children: []
  13613. }; // Time tooltips should not be added to a player on mobile devices
  13614. if (!IS_IOS && !IS_ANDROID) {
  13615. PlayProgressBar.prototype.options_.children.push('timeTooltip');
  13616. }
  13617. Component.registerComponent('PlayProgressBar', PlayProgressBar);
  13618. /**
  13619. * The {@link MouseTimeDisplay} component tracks mouse movement over the
  13620. * {@link ProgressControl}. It displays an indicator and a {@link TimeTooltip}
  13621. * indicating the time which is represented by a given point in the
  13622. * {@link ProgressControl}.
  13623. *
  13624. * @extends Component
  13625. */
  13626. var MouseTimeDisplay = /*#__PURE__*/function (_Component) {
  13627. inheritsLoose(MouseTimeDisplay, _Component);
  13628. /**
  13629. * Creates an instance of this class.
  13630. *
  13631. * @param {Player} player
  13632. * The {@link Player} that this class should be attached to.
  13633. *
  13634. * @param {Object} [options]
  13635. * The key/value store of player options.
  13636. */
  13637. function MouseTimeDisplay(player, options) {
  13638. var _this;
  13639. _this = _Component.call(this, player, options) || this;
  13640. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13641. return _this;
  13642. }
  13643. /**
  13644. * Create the DOM element for this class.
  13645. *
  13646. * @return {Element}
  13647. * The element that was created.
  13648. */
  13649. var _proto = MouseTimeDisplay.prototype;
  13650. _proto.createEl = function createEl() {
  13651. return _Component.prototype.createEl.call(this, 'div', {
  13652. className: 'vjs-mouse-display'
  13653. });
  13654. }
  13655. /**
  13656. * Enqueues updates to its own DOM as well as the DOM of its
  13657. * {@link TimeTooltip} child.
  13658. *
  13659. * @param {Object} seekBarRect
  13660. * The `ClientRect` for the {@link SeekBar} element.
  13661. *
  13662. * @param {number} seekBarPoint
  13663. * A number from 0 to 1, representing a horizontal reference point
  13664. * from the left edge of the {@link SeekBar}
  13665. */
  13666. ;
  13667. _proto.update = function update(seekBarRect, seekBarPoint) {
  13668. var _this2 = this;
  13669. var time = seekBarPoint * this.player_.duration();
  13670. this.getChild('timeTooltip').updateTime(seekBarRect, seekBarPoint, time, function () {
  13671. _this2.el_.style.left = seekBarRect.width * seekBarPoint + "px";
  13672. });
  13673. };
  13674. return MouseTimeDisplay;
  13675. }(Component);
  13676. /**
  13677. * Default options for `MouseTimeDisplay`
  13678. *
  13679. * @type {Object}
  13680. * @private
  13681. */
  13682. MouseTimeDisplay.prototype.options_ = {
  13683. children: ['timeTooltip']
  13684. };
  13685. Component.registerComponent('MouseTimeDisplay', MouseTimeDisplay);
  13686. var STEP_SECONDS = 5; // The multiplier of STEP_SECONDS that PgUp/PgDown move the timeline.
  13687. var PAGE_KEY_MULTIPLIER = 12;
  13688. /**
  13689. * Seek bar and container for the progress bars. Uses {@link PlayProgressBar}
  13690. * as its `bar`.
  13691. *
  13692. * @extends Slider
  13693. */
  13694. var SeekBar = /*#__PURE__*/function (_Slider) {
  13695. inheritsLoose(SeekBar, _Slider);
  13696. /**
  13697. * Creates an instance of this class.
  13698. *
  13699. * @param {Player} player
  13700. * The `Player` that this class should be attached to.
  13701. *
  13702. * @param {Object} [options]
  13703. * The key/value store of player options.
  13704. */
  13705. function SeekBar(player, options) {
  13706. var _this;
  13707. _this = _Slider.call(this, player, options) || this;
  13708. _this.setEventHandlers_();
  13709. return _this;
  13710. }
  13711. /**
  13712. * Sets the event handlers
  13713. *
  13714. * @private
  13715. */
  13716. var _proto = SeekBar.prototype;
  13717. _proto.setEventHandlers_ = function setEventHandlers_() {
  13718. var _this2 = this;
  13719. this.update_ = bind(this, this.update);
  13720. this.update = throttle(this.update_, UPDATE_REFRESH_INTERVAL);
  13721. this.on(this.player_, ['ended', 'durationchange', 'timeupdate'], this.update);
  13722. if (this.player_.liveTracker) {
  13723. this.on(this.player_.liveTracker, 'liveedgechange', this.update);
  13724. } // when playing, let's ensure we smoothly update the play progress bar
  13725. // via an interval
  13726. this.updateInterval = null;
  13727. this.enableIntervalHandler_ = function (e) {
  13728. return _this2.enableInterval_(e);
  13729. };
  13730. this.disableIntervalHandler_ = function (e) {
  13731. return _this2.disableInterval_(e);
  13732. };
  13733. this.on(this.player_, ['playing'], this.enableIntervalHandler_);
  13734. this.on(this.player_, ['ended', 'pause', 'waiting'], this.disableIntervalHandler_); // we don't need to update the play progress if the document is hidden,
  13735. // also, this causes the CPU to spike and eventually crash the page on IE11.
  13736. if ('hidden' in document && 'visibilityState' in document) {
  13737. this.on(document, 'visibilitychange', this.toggleVisibility_);
  13738. }
  13739. };
  13740. _proto.toggleVisibility_ = function toggleVisibility_(e) {
  13741. if (document.visibilityState === 'hidden') {
  13742. this.cancelNamedAnimationFrame('SeekBar#update');
  13743. this.cancelNamedAnimationFrame('Slider#update');
  13744. this.disableInterval_(e);
  13745. } else {
  13746. if (!this.player_.ended() && !this.player_.paused()) {
  13747. this.enableInterval_();
  13748. } // we just switched back to the page and someone may be looking, so, update ASAP
  13749. this.update();
  13750. }
  13751. };
  13752. _proto.enableInterval_ = function enableInterval_() {
  13753. if (this.updateInterval) {
  13754. return;
  13755. }
  13756. this.updateInterval = this.setInterval(this.update, UPDATE_REFRESH_INTERVAL);
  13757. };
  13758. _proto.disableInterval_ = function disableInterval_(e) {
  13759. if (this.player_.liveTracker && this.player_.liveTracker.isLive() && e && e.type !== 'ended') {
  13760. return;
  13761. }
  13762. if (!this.updateInterval) {
  13763. return;
  13764. }
  13765. this.clearInterval(this.updateInterval);
  13766. this.updateInterval = null;
  13767. }
  13768. /**
  13769. * Create the `Component`'s DOM element
  13770. *
  13771. * @return {Element}
  13772. * The element that was created.
  13773. */
  13774. ;
  13775. _proto.createEl = function createEl() {
  13776. return _Slider.prototype.createEl.call(this, 'div', {
  13777. className: 'vjs-progress-holder'
  13778. }, {
  13779. 'aria-label': this.localize('Progress Bar')
  13780. });
  13781. }
  13782. /**
  13783. * This function updates the play progress bar and accessibility
  13784. * attributes to whatever is passed in.
  13785. *
  13786. * @param {EventTarget~Event} [event]
  13787. * The `timeupdate` or `ended` event that caused this to run.
  13788. *
  13789. * @listens Player#timeupdate
  13790. *
  13791. * @return {number}
  13792. * The current percent at a number from 0-1
  13793. */
  13794. ;
  13795. _proto.update = function update(event) {
  13796. var _this3 = this;
  13797. // ignore updates while the tab is hidden
  13798. if (document.visibilityState === 'hidden') {
  13799. return;
  13800. }
  13801. var percent = _Slider.prototype.update.call(this);
  13802. this.requestNamedAnimationFrame('SeekBar#update', function () {
  13803. var currentTime = _this3.player_.ended() ? _this3.player_.duration() : _this3.getCurrentTime_();
  13804. var liveTracker = _this3.player_.liveTracker;
  13805. var duration = _this3.player_.duration();
  13806. if (liveTracker && liveTracker.isLive()) {
  13807. duration = _this3.player_.liveTracker.liveCurrentTime();
  13808. }
  13809. if (_this3.percent_ !== percent) {
  13810. // machine readable value of progress bar (percentage complete)
  13811. _this3.el_.setAttribute('aria-valuenow', (percent * 100).toFixed(2));
  13812. _this3.percent_ = percent;
  13813. }
  13814. if (_this3.currentTime_ !== currentTime || _this3.duration_ !== duration) {
  13815. // human readable value of progress bar (time complete)
  13816. _this3.el_.setAttribute('aria-valuetext', _this3.localize('progress bar timing: currentTime={1} duration={2}', [formatTime(currentTime, duration), formatTime(duration, duration)], '{1} of {2}'));
  13817. _this3.currentTime_ = currentTime;
  13818. _this3.duration_ = duration;
  13819. } // update the progress bar time tooltip with the current time
  13820. if (_this3.bar) {
  13821. _this3.bar.update(getBoundingClientRect(_this3.el()), _this3.getProgress());
  13822. }
  13823. });
  13824. return percent;
  13825. }
  13826. /**
  13827. * Prevent liveThreshold from causing seeks to seem like they
  13828. * are not happening from a user perspective.
  13829. *
  13830. * @param {number} ct
  13831. * current time to seek to
  13832. */
  13833. ;
  13834. _proto.userSeek_ = function userSeek_(ct) {
  13835. if (this.player_.liveTracker && this.player_.liveTracker.isLive()) {
  13836. this.player_.liveTracker.nextSeekedFromUser();
  13837. }
  13838. this.player_.currentTime(ct);
  13839. }
  13840. /**
  13841. * Get the value of current time but allows for smooth scrubbing,
  13842. * when player can't keep up.
  13843. *
  13844. * @return {number}
  13845. * The current time value to display
  13846. *
  13847. * @private
  13848. */
  13849. ;
  13850. _proto.getCurrentTime_ = function getCurrentTime_() {
  13851. return this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  13852. }
  13853. /**
  13854. * Get the percentage of media played so far.
  13855. *
  13856. * @return {number}
  13857. * The percentage of media played so far (0 to 1).
  13858. */
  13859. ;
  13860. _proto.getPercent = function getPercent() {
  13861. var currentTime = this.getCurrentTime_();
  13862. var percent;
  13863. var liveTracker = this.player_.liveTracker;
  13864. if (liveTracker && liveTracker.isLive()) {
  13865. percent = (currentTime - liveTracker.seekableStart()) / liveTracker.liveWindow(); // prevent the percent from changing at the live edge
  13866. if (liveTracker.atLiveEdge()) {
  13867. percent = 1;
  13868. }
  13869. } else {
  13870. percent = currentTime / this.player_.duration();
  13871. }
  13872. return percent;
  13873. }
  13874. /**
  13875. * Handle mouse down on seek bar
  13876. *
  13877. * @param {EventTarget~Event} event
  13878. * The `mousedown` event that caused this to run.
  13879. *
  13880. * @listens mousedown
  13881. */
  13882. ;
  13883. _proto.handleMouseDown = function handleMouseDown(event) {
  13884. if (!isSingleLeftClick(event)) {
  13885. return;
  13886. } // Stop event propagation to prevent double fire in progress-control.js
  13887. event.stopPropagation();
  13888. this.videoWasPlaying = !this.player_.paused();
  13889. this.player_.pause();
  13890. _Slider.prototype.handleMouseDown.call(this, event);
  13891. }
  13892. /**
  13893. * Handle mouse move on seek bar
  13894. *
  13895. * @param {EventTarget~Event} event
  13896. * The `mousemove` event that caused this to run.
  13897. * @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
  13898. *
  13899. * @listens mousemove
  13900. */
  13901. ;
  13902. _proto.handleMouseMove = function handleMouseMove(event, mouseDown) {
  13903. if (mouseDown === void 0) {
  13904. mouseDown = false;
  13905. }
  13906. if (!isSingleLeftClick(event)) {
  13907. return;
  13908. }
  13909. if (!mouseDown && !this.player_.scrubbing()) {
  13910. this.player_.scrubbing(true);
  13911. }
  13912. var newTime;
  13913. var distance = this.calculateDistance(event);
  13914. var liveTracker = this.player_.liveTracker;
  13915. if (!liveTracker || !liveTracker.isLive()) {
  13916. newTime = distance * this.player_.duration(); // Don't let video end while scrubbing.
  13917. if (newTime === this.player_.duration()) {
  13918. newTime = newTime - 0.1;
  13919. }
  13920. } else {
  13921. if (distance >= 0.99) {
  13922. liveTracker.seekToLiveEdge();
  13923. return;
  13924. }
  13925. var seekableStart = liveTracker.seekableStart();
  13926. var seekableEnd = liveTracker.liveCurrentTime();
  13927. newTime = seekableStart + distance * liveTracker.liveWindow(); // Don't let video end while scrubbing.
  13928. if (newTime >= seekableEnd) {
  13929. newTime = seekableEnd;
  13930. } // Compensate for precision differences so that currentTime is not less
  13931. // than seekable start
  13932. if (newTime <= seekableStart) {
  13933. newTime = seekableStart + 0.1;
  13934. } // On android seekableEnd can be Infinity sometimes,
  13935. // this will cause newTime to be Infinity, which is
  13936. // not a valid currentTime.
  13937. if (newTime === Infinity) {
  13938. return;
  13939. }
  13940. } // Set new time (tell player to seek to new time)
  13941. this.userSeek_(newTime);
  13942. };
  13943. _proto.enable = function enable() {
  13944. _Slider.prototype.enable.call(this);
  13945. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  13946. if (!mouseTimeDisplay) {
  13947. return;
  13948. }
  13949. mouseTimeDisplay.show();
  13950. };
  13951. _proto.disable = function disable() {
  13952. _Slider.prototype.disable.call(this);
  13953. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  13954. if (!mouseTimeDisplay) {
  13955. return;
  13956. }
  13957. mouseTimeDisplay.hide();
  13958. }
  13959. /**
  13960. * Handle mouse up on seek bar
  13961. *
  13962. * @param {EventTarget~Event} event
  13963. * The `mouseup` event that caused this to run.
  13964. *
  13965. * @listens mouseup
  13966. */
  13967. ;
  13968. _proto.handleMouseUp = function handleMouseUp(event) {
  13969. _Slider.prototype.handleMouseUp.call(this, event); // Stop event propagation to prevent double fire in progress-control.js
  13970. if (event) {
  13971. event.stopPropagation();
  13972. }
  13973. this.player_.scrubbing(false);
  13974. /**
  13975. * Trigger timeupdate because we're done seeking and the time has changed.
  13976. * This is particularly useful for if the player is paused to time the time displays.
  13977. *
  13978. * @event Tech#timeupdate
  13979. * @type {EventTarget~Event}
  13980. */
  13981. this.player_.trigger({
  13982. type: 'timeupdate',
  13983. target: this,
  13984. manuallyTriggered: true
  13985. });
  13986. if (this.videoWasPlaying) {
  13987. silencePromise(this.player_.play());
  13988. } else {
  13989. // We're done seeking and the time has changed.
  13990. // If the player is paused, make sure we display the correct time on the seek bar.
  13991. this.update_();
  13992. }
  13993. }
  13994. /**
  13995. * Move more quickly fast forward for keyboard-only users
  13996. */
  13997. ;
  13998. _proto.stepForward = function stepForward() {
  13999. this.userSeek_(this.player_.currentTime() + STEP_SECONDS);
  14000. }
  14001. /**
  14002. * Move more quickly rewind for keyboard-only users
  14003. */
  14004. ;
  14005. _proto.stepBack = function stepBack() {
  14006. this.userSeek_(this.player_.currentTime() - STEP_SECONDS);
  14007. }
  14008. /**
  14009. * Toggles the playback state of the player
  14010. * This gets called when enter or space is used on the seekbar
  14011. *
  14012. * @param {EventTarget~Event} event
  14013. * The `keydown` event that caused this function to be called
  14014. *
  14015. */
  14016. ;
  14017. _proto.handleAction = function handleAction(event) {
  14018. if (this.player_.paused()) {
  14019. this.player_.play();
  14020. } else {
  14021. this.player_.pause();
  14022. }
  14023. }
  14024. /**
  14025. * Called when this SeekBar has focus and a key gets pressed down.
  14026. * Supports the following keys:
  14027. *
  14028. * Space or Enter key fire a click event
  14029. * Home key moves to start of the timeline
  14030. * End key moves to end of the timeline
  14031. * Digit "0" through "9" keys move to 0%, 10% ... 80%, 90% of the timeline
  14032. * PageDown key moves back a larger step than ArrowDown
  14033. * PageUp key moves forward a large step
  14034. *
  14035. * @param {EventTarget~Event} event
  14036. * The `keydown` event that caused this function to be called.
  14037. *
  14038. * @listens keydown
  14039. */
  14040. ;
  14041. _proto.handleKeyDown = function handleKeyDown(event) {
  14042. var liveTracker = this.player_.liveTracker;
  14043. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  14044. event.preventDefault();
  14045. event.stopPropagation();
  14046. this.handleAction(event);
  14047. } else if (keycode.isEventKey(event, 'Home')) {
  14048. event.preventDefault();
  14049. event.stopPropagation();
  14050. this.userSeek_(0);
  14051. } else if (keycode.isEventKey(event, 'End')) {
  14052. event.preventDefault();
  14053. event.stopPropagation();
  14054. if (liveTracker && liveTracker.isLive()) {
  14055. this.userSeek_(liveTracker.liveCurrentTime());
  14056. } else {
  14057. this.userSeek_(this.player_.duration());
  14058. }
  14059. } else if (/^[0-9]$/.test(keycode(event))) {
  14060. event.preventDefault();
  14061. event.stopPropagation();
  14062. var gotoFraction = (keycode.codes[keycode(event)] - keycode.codes['0']) * 10.0 / 100.0;
  14063. if (liveTracker && liveTracker.isLive()) {
  14064. this.userSeek_(liveTracker.seekableStart() + liveTracker.liveWindow() * gotoFraction);
  14065. } else {
  14066. this.userSeek_(this.player_.duration() * gotoFraction);
  14067. }
  14068. } else if (keycode.isEventKey(event, 'PgDn')) {
  14069. event.preventDefault();
  14070. event.stopPropagation();
  14071. this.userSeek_(this.player_.currentTime() - STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  14072. } else if (keycode.isEventKey(event, 'PgUp')) {
  14073. event.preventDefault();
  14074. event.stopPropagation();
  14075. this.userSeek_(this.player_.currentTime() + STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  14076. } else {
  14077. // Pass keydown handling up for unsupported keys
  14078. _Slider.prototype.handleKeyDown.call(this, event);
  14079. }
  14080. };
  14081. _proto.dispose = function dispose() {
  14082. this.disableInterval_();
  14083. this.off(this.player_, ['ended', 'durationchange', 'timeupdate'], this.update);
  14084. if (this.player_.liveTracker) {
  14085. this.off(this.player_.liveTracker, 'liveedgechange', this.update);
  14086. }
  14087. this.off(this.player_, ['playing'], this.enableIntervalHandler_);
  14088. this.off(this.player_, ['ended', 'pause', 'waiting'], this.disableIntervalHandler_); // we don't need to update the play progress if the document is hidden,
  14089. // also, this causes the CPU to spike and eventually crash the page on IE11.
  14090. if ('hidden' in document && 'visibilityState' in document) {
  14091. this.off(document, 'visibilitychange', this.toggleVisibility_);
  14092. }
  14093. _Slider.prototype.dispose.call(this);
  14094. };
  14095. return SeekBar;
  14096. }(Slider);
  14097. /**
  14098. * Default options for the `SeekBar`
  14099. *
  14100. * @type {Object}
  14101. * @private
  14102. */
  14103. SeekBar.prototype.options_ = {
  14104. children: ['loadProgressBar', 'playProgressBar'],
  14105. barName: 'playProgressBar'
  14106. }; // MouseTimeDisplay tooltips should not be added to a player on mobile devices
  14107. if (!IS_IOS && !IS_ANDROID) {
  14108. SeekBar.prototype.options_.children.splice(1, 0, 'mouseTimeDisplay');
  14109. }
  14110. Component.registerComponent('SeekBar', SeekBar);
  14111. /**
  14112. * The Progress Control component contains the seek bar, load progress,
  14113. * and play progress.
  14114. *
  14115. * @extends Component
  14116. */
  14117. var ProgressControl = /*#__PURE__*/function (_Component) {
  14118. inheritsLoose(ProgressControl, _Component);
  14119. /**
  14120. * Creates an instance of this class.
  14121. *
  14122. * @param {Player} player
  14123. * The `Player` that this class should be attached to.
  14124. *
  14125. * @param {Object} [options]
  14126. * The key/value store of player options.
  14127. */
  14128. function ProgressControl(player, options) {
  14129. var _this;
  14130. _this = _Component.call(this, player, options) || this;
  14131. _this.handleMouseMove = throttle(bind(assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  14132. _this.throttledHandleMouseSeek = throttle(bind(assertThisInitialized(_this), _this.handleMouseSeek), UPDATE_REFRESH_INTERVAL);
  14133. _this.handleMouseUpHandler_ = function (e) {
  14134. return _this.handleMouseUp(e);
  14135. };
  14136. _this.handleMouseDownHandler_ = function (e) {
  14137. return _this.handleMouseDown(e);
  14138. };
  14139. _this.enable();
  14140. return _this;
  14141. }
  14142. /**
  14143. * Create the `Component`'s DOM element
  14144. *
  14145. * @return {Element}
  14146. * The element that was created.
  14147. */
  14148. var _proto = ProgressControl.prototype;
  14149. _proto.createEl = function createEl() {
  14150. return _Component.prototype.createEl.call(this, 'div', {
  14151. className: 'vjs-progress-control vjs-control'
  14152. });
  14153. }
  14154. /**
  14155. * When the mouse moves over the `ProgressControl`, the pointer position
  14156. * gets passed down to the `MouseTimeDisplay` component.
  14157. *
  14158. * @param {EventTarget~Event} event
  14159. * The `mousemove` event that caused this function to run.
  14160. *
  14161. * @listen mousemove
  14162. */
  14163. ;
  14164. _proto.handleMouseMove = function handleMouseMove(event) {
  14165. var seekBar = this.getChild('seekBar');
  14166. if (!seekBar) {
  14167. return;
  14168. }
  14169. var playProgressBar = seekBar.getChild('playProgressBar');
  14170. var mouseTimeDisplay = seekBar.getChild('mouseTimeDisplay');
  14171. if (!playProgressBar && !mouseTimeDisplay) {
  14172. return;
  14173. }
  14174. var seekBarEl = seekBar.el();
  14175. var seekBarRect = findPosition(seekBarEl);
  14176. var seekBarPoint = getPointerPosition(seekBarEl, event).x; // The default skin has a gap on either side of the `SeekBar`. This means
  14177. // that it's possible to trigger this behavior outside the boundaries of
  14178. // the `SeekBar`. This ensures we stay within it at all times.
  14179. seekBarPoint = clamp(seekBarPoint, 0, 1);
  14180. if (mouseTimeDisplay) {
  14181. mouseTimeDisplay.update(seekBarRect, seekBarPoint);
  14182. }
  14183. if (playProgressBar) {
  14184. playProgressBar.update(seekBarRect, seekBar.getProgress());
  14185. }
  14186. }
  14187. /**
  14188. * A throttled version of the {@link ProgressControl#handleMouseSeek} listener.
  14189. *
  14190. * @method ProgressControl#throttledHandleMouseSeek
  14191. * @param {EventTarget~Event} event
  14192. * The `mousemove` event that caused this function to run.
  14193. *
  14194. * @listen mousemove
  14195. * @listen touchmove
  14196. */
  14197. /**
  14198. * Handle `mousemove` or `touchmove` events on the `ProgressControl`.
  14199. *
  14200. * @param {EventTarget~Event} event
  14201. * `mousedown` or `touchstart` event that triggered this function
  14202. *
  14203. * @listens mousemove
  14204. * @listens touchmove
  14205. */
  14206. ;
  14207. _proto.handleMouseSeek = function handleMouseSeek(event) {
  14208. var seekBar = this.getChild('seekBar');
  14209. if (seekBar) {
  14210. seekBar.handleMouseMove(event);
  14211. }
  14212. }
  14213. /**
  14214. * Are controls are currently enabled for this progress control.
  14215. *
  14216. * @return {boolean}
  14217. * true if controls are enabled, false otherwise
  14218. */
  14219. ;
  14220. _proto.enabled = function enabled() {
  14221. return this.enabled_;
  14222. }
  14223. /**
  14224. * Disable all controls on the progress control and its children
  14225. */
  14226. ;
  14227. _proto.disable = function disable() {
  14228. this.children().forEach(function (child) {
  14229. return child.disable && child.disable();
  14230. });
  14231. if (!this.enabled()) {
  14232. return;
  14233. }
  14234. this.off(['mousedown', 'touchstart'], this.handleMouseDownHandler_);
  14235. this.off(this.el_, 'mousemove', this.handleMouseMove);
  14236. this.removeListenersAddedOnMousedownAndTouchstart();
  14237. this.addClass('disabled');
  14238. this.enabled_ = false; // Restore normal playback state if controls are disabled while scrubbing
  14239. if (this.player_.scrubbing()) {
  14240. var seekBar = this.getChild('seekBar');
  14241. this.player_.scrubbing(false);
  14242. if (seekBar.videoWasPlaying) {
  14243. silencePromise(this.player_.play());
  14244. }
  14245. }
  14246. }
  14247. /**
  14248. * Enable all controls on the progress control and its children
  14249. */
  14250. ;
  14251. _proto.enable = function enable() {
  14252. this.children().forEach(function (child) {
  14253. return child.enable && child.enable();
  14254. });
  14255. if (this.enabled()) {
  14256. return;
  14257. }
  14258. this.on(['mousedown', 'touchstart'], this.handleMouseDownHandler_);
  14259. this.on(this.el_, 'mousemove', this.handleMouseMove);
  14260. this.removeClass('disabled');
  14261. this.enabled_ = true;
  14262. }
  14263. /**
  14264. * Cleanup listeners after the user finishes interacting with the progress controls
  14265. */
  14266. ;
  14267. _proto.removeListenersAddedOnMousedownAndTouchstart = function removeListenersAddedOnMousedownAndTouchstart() {
  14268. var doc = this.el_.ownerDocument;
  14269. this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
  14270. this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
  14271. this.off(doc, 'mouseup', this.handleMouseUpHandler_);
  14272. this.off(doc, 'touchend', this.handleMouseUpHandler_);
  14273. }
  14274. /**
  14275. * Handle `mousedown` or `touchstart` events on the `ProgressControl`.
  14276. *
  14277. * @param {EventTarget~Event} event
  14278. * `mousedown` or `touchstart` event that triggered this function
  14279. *
  14280. * @listens mousedown
  14281. * @listens touchstart
  14282. */
  14283. ;
  14284. _proto.handleMouseDown = function handleMouseDown(event) {
  14285. var doc = this.el_.ownerDocument;
  14286. var seekBar = this.getChild('seekBar');
  14287. if (seekBar) {
  14288. seekBar.handleMouseDown(event);
  14289. }
  14290. this.on(doc, 'mousemove', this.throttledHandleMouseSeek);
  14291. this.on(doc, 'touchmove', this.throttledHandleMouseSeek);
  14292. this.on(doc, 'mouseup', this.handleMouseUpHandler_);
  14293. this.on(doc, 'touchend', this.handleMouseUpHandler_);
  14294. }
  14295. /**
  14296. * Handle `mouseup` or `touchend` events on the `ProgressControl`.
  14297. *
  14298. * @param {EventTarget~Event} event
  14299. * `mouseup` or `touchend` event that triggered this function.
  14300. *
  14301. * @listens touchend
  14302. * @listens mouseup
  14303. */
  14304. ;
  14305. _proto.handleMouseUp = function handleMouseUp(event) {
  14306. var seekBar = this.getChild('seekBar');
  14307. if (seekBar) {
  14308. seekBar.handleMouseUp(event);
  14309. }
  14310. this.removeListenersAddedOnMousedownAndTouchstart();
  14311. };
  14312. return ProgressControl;
  14313. }(Component);
  14314. /**
  14315. * Default options for `ProgressControl`
  14316. *
  14317. * @type {Object}
  14318. * @private
  14319. */
  14320. ProgressControl.prototype.options_ = {
  14321. children: ['seekBar']
  14322. };
  14323. Component.registerComponent('ProgressControl', ProgressControl);
  14324. /**
  14325. * Toggle Picture-in-Picture mode
  14326. *
  14327. * @extends Button
  14328. */
  14329. var PictureInPictureToggle = /*#__PURE__*/function (_Button) {
  14330. inheritsLoose(PictureInPictureToggle, _Button);
  14331. /**
  14332. * Creates an instance of this class.
  14333. *
  14334. * @param {Player} player
  14335. * The `Player` that this class should be attached to.
  14336. *
  14337. * @param {Object} [options]
  14338. * The key/value store of player options.
  14339. *
  14340. * @listens Player#enterpictureinpicture
  14341. * @listens Player#leavepictureinpicture
  14342. */
  14343. function PictureInPictureToggle(player, options) {
  14344. var _this;
  14345. _this = _Button.call(this, player, options) || this;
  14346. _this.on(player, ['enterpictureinpicture', 'leavepictureinpicture'], function (e) {
  14347. return _this.handlePictureInPictureChange(e);
  14348. });
  14349. _this.on(player, ['disablepictureinpicturechanged', 'loadedmetadata'], function (e) {
  14350. return _this.handlePictureInPictureEnabledChange(e);
  14351. });
  14352. _this.on(player, ['loadedmetadata', 'audioonlymodechange', 'audiopostermodechange'], function () {
  14353. // This audio detection will not detect HLS or DASH audio-only streams because there was no reliable way to detect them at the time
  14354. var isSourceAudio = player.currentType().substring(0, 5) === 'audio';
  14355. if (isSourceAudio || player.audioPosterMode() || player.audioOnlyMode()) {
  14356. if (player.isInPictureInPicture()) {
  14357. player.exitPictureInPicture();
  14358. }
  14359. _this.hide();
  14360. } else {
  14361. _this.show();
  14362. }
  14363. }); // TODO: Deactivate button on player emptied event.
  14364. _this.disable();
  14365. return _this;
  14366. }
  14367. /**
  14368. * Builds the default DOM `className`.
  14369. *
  14370. * @return {string}
  14371. * The DOM `className` for this object.
  14372. */
  14373. var _proto = PictureInPictureToggle.prototype;
  14374. _proto.buildCSSClass = function buildCSSClass() {
  14375. return "vjs-picture-in-picture-control " + _Button.prototype.buildCSSClass.call(this);
  14376. }
  14377. /**
  14378. * Enables or disables button based on document.pictureInPictureEnabled property value
  14379. * or on value returned by player.disablePictureInPicture() method.
  14380. */
  14381. ;
  14382. _proto.handlePictureInPictureEnabledChange = function handlePictureInPictureEnabledChange() {
  14383. if (document.pictureInPictureEnabled && this.player_.disablePictureInPicture() === false) {
  14384. this.enable();
  14385. } else {
  14386. this.disable();
  14387. }
  14388. }
  14389. /**
  14390. * Handles enterpictureinpicture and leavepictureinpicture on the player and change control text accordingly.
  14391. *
  14392. * @param {EventTarget~Event} [event]
  14393. * The {@link Player#enterpictureinpicture} or {@link Player#leavepictureinpicture} event that caused this function to be
  14394. * called.
  14395. *
  14396. * @listens Player#enterpictureinpicture
  14397. * @listens Player#leavepictureinpicture
  14398. */
  14399. ;
  14400. _proto.handlePictureInPictureChange = function handlePictureInPictureChange(event) {
  14401. if (this.player_.isInPictureInPicture()) {
  14402. this.controlText('Exit Picture-in-Picture');
  14403. } else {
  14404. this.controlText('Picture-in-Picture');
  14405. }
  14406. this.handlePictureInPictureEnabledChange();
  14407. }
  14408. /**
  14409. * This gets called when an `PictureInPictureToggle` is "clicked". See
  14410. * {@link ClickableComponent} for more detailed information on what a click can be.
  14411. *
  14412. * @param {EventTarget~Event} [event]
  14413. * The `keydown`, `tap`, or `click` event that caused this function to be
  14414. * called.
  14415. *
  14416. * @listens tap
  14417. * @listens click
  14418. */
  14419. ;
  14420. _proto.handleClick = function handleClick(event) {
  14421. if (!this.player_.isInPictureInPicture()) {
  14422. this.player_.requestPictureInPicture();
  14423. } else {
  14424. this.player_.exitPictureInPicture();
  14425. }
  14426. };
  14427. return PictureInPictureToggle;
  14428. }(Button);
  14429. /**
  14430. * The text that should display over the `PictureInPictureToggle`s controls. Added for localization.
  14431. *
  14432. * @type {string}
  14433. * @private
  14434. */
  14435. PictureInPictureToggle.prototype.controlText_ = 'Picture-in-Picture';
  14436. Component.registerComponent('PictureInPictureToggle', PictureInPictureToggle);
  14437. /**
  14438. * Toggle fullscreen video
  14439. *
  14440. * @extends Button
  14441. */
  14442. var FullscreenToggle = /*#__PURE__*/function (_Button) {
  14443. inheritsLoose(FullscreenToggle, _Button);
  14444. /**
  14445. * Creates an instance of this class.
  14446. *
  14447. * @param {Player} player
  14448. * The `Player` that this class should be attached to.
  14449. *
  14450. * @param {Object} [options]
  14451. * The key/value store of player options.
  14452. */
  14453. function FullscreenToggle(player, options) {
  14454. var _this;
  14455. _this = _Button.call(this, player, options) || this;
  14456. _this.on(player, 'fullscreenchange', function (e) {
  14457. return _this.handleFullscreenChange(e);
  14458. });
  14459. if (document[player.fsApi_.fullscreenEnabled] === false) {
  14460. _this.disable();
  14461. }
  14462. return _this;
  14463. }
  14464. /**
  14465. * Builds the default DOM `className`.
  14466. *
  14467. * @return {string}
  14468. * The DOM `className` for this object.
  14469. */
  14470. var _proto = FullscreenToggle.prototype;
  14471. _proto.buildCSSClass = function buildCSSClass() {
  14472. return "vjs-fullscreen-control " + _Button.prototype.buildCSSClass.call(this);
  14473. }
  14474. /**
  14475. * Handles fullscreenchange on the player and change control text accordingly.
  14476. *
  14477. * @param {EventTarget~Event} [event]
  14478. * The {@link Player#fullscreenchange} event that caused this function to be
  14479. * called.
  14480. *
  14481. * @listens Player#fullscreenchange
  14482. */
  14483. ;
  14484. _proto.handleFullscreenChange = function handleFullscreenChange(event) {
  14485. if (this.player_.isFullscreen()) {
  14486. this.controlText('Non-Fullscreen');
  14487. } else {
  14488. this.controlText('Fullscreen');
  14489. }
  14490. }
  14491. /**
  14492. * This gets called when an `FullscreenToggle` is "clicked". See
  14493. * {@link ClickableComponent} for more detailed information on what a click can be.
  14494. *
  14495. * @param {EventTarget~Event} [event]
  14496. * The `keydown`, `tap`, or `click` event that caused this function to be
  14497. * called.
  14498. *
  14499. * @listens tap
  14500. * @listens click
  14501. */
  14502. ;
  14503. _proto.handleClick = function handleClick(event) {
  14504. if (!this.player_.isFullscreen()) {
  14505. this.player_.requestFullscreen();
  14506. } else {
  14507. this.player_.exitFullscreen();
  14508. }
  14509. };
  14510. return FullscreenToggle;
  14511. }(Button);
  14512. /**
  14513. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  14514. *
  14515. * @type {string}
  14516. * @private
  14517. */
  14518. FullscreenToggle.prototype.controlText_ = 'Fullscreen';
  14519. Component.registerComponent('FullscreenToggle', FullscreenToggle);
  14520. /**
  14521. * Check if volume control is supported and if it isn't hide the
  14522. * `Component` that was passed using the `vjs-hidden` class.
  14523. *
  14524. * @param {Component} self
  14525. * The component that should be hidden if volume is unsupported
  14526. *
  14527. * @param {Player} player
  14528. * A reference to the player
  14529. *
  14530. * @private
  14531. */
  14532. var checkVolumeSupport = function checkVolumeSupport(self, player) {
  14533. // hide volume controls when they're not supported by the current tech
  14534. if (player.tech_ && !player.tech_.featuresVolumeControl) {
  14535. self.addClass('vjs-hidden');
  14536. }
  14537. self.on(player, 'loadstart', function () {
  14538. if (!player.tech_.featuresVolumeControl) {
  14539. self.addClass('vjs-hidden');
  14540. } else {
  14541. self.removeClass('vjs-hidden');
  14542. }
  14543. });
  14544. };
  14545. /**
  14546. * Shows volume level
  14547. *
  14548. * @extends Component
  14549. */
  14550. var VolumeLevel = /*#__PURE__*/function (_Component) {
  14551. inheritsLoose(VolumeLevel, _Component);
  14552. function VolumeLevel() {
  14553. return _Component.apply(this, arguments) || this;
  14554. }
  14555. var _proto = VolumeLevel.prototype;
  14556. /**
  14557. * Create the `Component`'s DOM element
  14558. *
  14559. * @return {Element}
  14560. * The element that was created.
  14561. */
  14562. _proto.createEl = function createEl() {
  14563. var el = _Component.prototype.createEl.call(this, 'div', {
  14564. className: 'vjs-volume-level'
  14565. });
  14566. el.appendChild(_Component.prototype.createEl.call(this, 'span', {
  14567. className: 'vjs-control-text'
  14568. }));
  14569. return el;
  14570. };
  14571. return VolumeLevel;
  14572. }(Component);
  14573. Component.registerComponent('VolumeLevel', VolumeLevel);
  14574. /**
  14575. * Volume level tooltips display a volume above or side by side the volume bar.
  14576. *
  14577. * @extends Component
  14578. */
  14579. var VolumeLevelTooltip = /*#__PURE__*/function (_Component) {
  14580. inheritsLoose(VolumeLevelTooltip, _Component);
  14581. /**
  14582. * Creates an instance of this class.
  14583. *
  14584. * @param {Player} player
  14585. * The {@link Player} that this class should be attached to.
  14586. *
  14587. * @param {Object} [options]
  14588. * The key/value store of player options.
  14589. */
  14590. function VolumeLevelTooltip(player, options) {
  14591. var _this;
  14592. _this = _Component.call(this, player, options) || this;
  14593. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  14594. return _this;
  14595. }
  14596. /**
  14597. * Create the volume tooltip DOM element
  14598. *
  14599. * @return {Element}
  14600. * The element that was created.
  14601. */
  14602. var _proto = VolumeLevelTooltip.prototype;
  14603. _proto.createEl = function createEl() {
  14604. return _Component.prototype.createEl.call(this, 'div', {
  14605. className: 'vjs-volume-tooltip'
  14606. }, {
  14607. 'aria-hidden': 'true'
  14608. });
  14609. }
  14610. /**
  14611. * Updates the position of the tooltip relative to the `VolumeBar` and
  14612. * its content text.
  14613. *
  14614. * @param {Object} rangeBarRect
  14615. * The `ClientRect` for the {@link VolumeBar} element.
  14616. *
  14617. * @param {number} rangeBarPoint
  14618. * A number from 0 to 1, representing a horizontal/vertical reference point
  14619. * from the left edge of the {@link VolumeBar}
  14620. *
  14621. * @param {boolean} vertical
  14622. * Referees to the Volume control position
  14623. * in the control bar{@link VolumeControl}
  14624. *
  14625. */
  14626. ;
  14627. _proto.update = function update(rangeBarRect, rangeBarPoint, vertical, content) {
  14628. if (!vertical) {
  14629. var tooltipRect = getBoundingClientRect(this.el_);
  14630. var playerRect = getBoundingClientRect(this.player_.el());
  14631. var volumeBarPointPx = rangeBarRect.width * rangeBarPoint;
  14632. if (!playerRect || !tooltipRect) {
  14633. return;
  14634. }
  14635. var spaceLeftOfPoint = rangeBarRect.left - playerRect.left + volumeBarPointPx;
  14636. var spaceRightOfPoint = rangeBarRect.width - volumeBarPointPx + (playerRect.right - rangeBarRect.right);
  14637. var pullTooltipBy = tooltipRect.width / 2;
  14638. if (spaceLeftOfPoint < pullTooltipBy) {
  14639. pullTooltipBy += pullTooltipBy - spaceLeftOfPoint;
  14640. } else if (spaceRightOfPoint < pullTooltipBy) {
  14641. pullTooltipBy = spaceRightOfPoint;
  14642. }
  14643. if (pullTooltipBy < 0) {
  14644. pullTooltipBy = 0;
  14645. } else if (pullTooltipBy > tooltipRect.width) {
  14646. pullTooltipBy = tooltipRect.width;
  14647. }
  14648. this.el_.style.right = "-" + pullTooltipBy + "px";
  14649. }
  14650. this.write(content + "%");
  14651. }
  14652. /**
  14653. * Write the volume to the tooltip DOM element.
  14654. *
  14655. * @param {string} content
  14656. * The formatted volume for the tooltip.
  14657. */
  14658. ;
  14659. _proto.write = function write(content) {
  14660. textContent(this.el_, content);
  14661. }
  14662. /**
  14663. * Updates the position of the volume tooltip relative to the `VolumeBar`.
  14664. *
  14665. * @param {Object} rangeBarRect
  14666. * The `ClientRect` for the {@link VolumeBar} element.
  14667. *
  14668. * @param {number} rangeBarPoint
  14669. * A number from 0 to 1, representing a horizontal/vertical reference point
  14670. * from the left edge of the {@link VolumeBar}
  14671. *
  14672. * @param {boolean} vertical
  14673. * Referees to the Volume control position
  14674. * in the control bar{@link VolumeControl}
  14675. *
  14676. * @param {number} volume
  14677. * The volume level to update the tooltip to
  14678. *
  14679. * @param {Function} cb
  14680. * A function that will be called during the request animation frame
  14681. * for tooltips that need to do additional animations from the default
  14682. */
  14683. ;
  14684. _proto.updateVolume = function updateVolume(rangeBarRect, rangeBarPoint, vertical, volume, cb) {
  14685. var _this2 = this;
  14686. this.requestNamedAnimationFrame('VolumeLevelTooltip#updateVolume', function () {
  14687. _this2.update(rangeBarRect, rangeBarPoint, vertical, volume.toFixed(0));
  14688. if (cb) {
  14689. cb();
  14690. }
  14691. });
  14692. };
  14693. return VolumeLevelTooltip;
  14694. }(Component);
  14695. Component.registerComponent('VolumeLevelTooltip', VolumeLevelTooltip);
  14696. /**
  14697. * The {@link MouseVolumeLevelDisplay} component tracks mouse movement over the
  14698. * {@link VolumeControl}. It displays an indicator and a {@link VolumeLevelTooltip}
  14699. * indicating the volume level which is represented by a given point in the
  14700. * {@link VolumeBar}.
  14701. *
  14702. * @extends Component
  14703. */
  14704. var MouseVolumeLevelDisplay = /*#__PURE__*/function (_Component) {
  14705. inheritsLoose(MouseVolumeLevelDisplay, _Component);
  14706. /**
  14707. * Creates an instance of this class.
  14708. *
  14709. * @param {Player} player
  14710. * The {@link Player} that this class should be attached to.
  14711. *
  14712. * @param {Object} [options]
  14713. * The key/value store of player options.
  14714. */
  14715. function MouseVolumeLevelDisplay(player, options) {
  14716. var _this;
  14717. _this = _Component.call(this, player, options) || this;
  14718. _this.update = throttle(bind(assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  14719. return _this;
  14720. }
  14721. /**
  14722. * Create the DOM element for this class.
  14723. *
  14724. * @return {Element}
  14725. * The element that was created.
  14726. */
  14727. var _proto = MouseVolumeLevelDisplay.prototype;
  14728. _proto.createEl = function createEl() {
  14729. return _Component.prototype.createEl.call(this, 'div', {
  14730. className: 'vjs-mouse-display'
  14731. });
  14732. }
  14733. /**
  14734. * Enquires updates to its own DOM as well as the DOM of its
  14735. * {@link VolumeLevelTooltip} child.
  14736. *
  14737. * @param {Object} rangeBarRect
  14738. * The `ClientRect` for the {@link VolumeBar} element.
  14739. *
  14740. * @param {number} rangeBarPoint
  14741. * A number from 0 to 1, representing a horizontal/vertical reference point
  14742. * from the left edge of the {@link VolumeBar}
  14743. *
  14744. * @param {boolean} vertical
  14745. * Referees to the Volume control position
  14746. * in the control bar{@link VolumeControl}
  14747. *
  14748. */
  14749. ;
  14750. _proto.update = function update(rangeBarRect, rangeBarPoint, vertical) {
  14751. var _this2 = this;
  14752. var volume = 100 * rangeBarPoint;
  14753. this.getChild('volumeLevelTooltip').updateVolume(rangeBarRect, rangeBarPoint, vertical, volume, function () {
  14754. if (vertical) {
  14755. _this2.el_.style.bottom = rangeBarRect.height * rangeBarPoint + "px";
  14756. } else {
  14757. _this2.el_.style.left = rangeBarRect.width * rangeBarPoint + "px";
  14758. }
  14759. });
  14760. };
  14761. return MouseVolumeLevelDisplay;
  14762. }(Component);
  14763. /**
  14764. * Default options for `MouseVolumeLevelDisplay`
  14765. *
  14766. * @type {Object}
  14767. * @private
  14768. */
  14769. MouseVolumeLevelDisplay.prototype.options_ = {
  14770. children: ['volumeLevelTooltip']
  14771. };
  14772. Component.registerComponent('MouseVolumeLevelDisplay', MouseVolumeLevelDisplay);
  14773. /**
  14774. * The bar that contains the volume level and can be clicked on to adjust the level
  14775. *
  14776. * @extends Slider
  14777. */
  14778. var VolumeBar = /*#__PURE__*/function (_Slider) {
  14779. inheritsLoose(VolumeBar, _Slider);
  14780. /**
  14781. * Creates an instance of this class.
  14782. *
  14783. * @param {Player} player
  14784. * The `Player` that this class should be attached to.
  14785. *
  14786. * @param {Object} [options]
  14787. * The key/value store of player options.
  14788. */
  14789. function VolumeBar(player, options) {
  14790. var _this;
  14791. _this = _Slider.call(this, player, options) || this;
  14792. _this.on('slideractive', function (e) {
  14793. return _this.updateLastVolume_(e);
  14794. });
  14795. _this.on(player, 'volumechange', function (e) {
  14796. return _this.updateARIAAttributes(e);
  14797. });
  14798. player.ready(function () {
  14799. return _this.updateARIAAttributes();
  14800. });
  14801. return _this;
  14802. }
  14803. /**
  14804. * Create the `Component`'s DOM element
  14805. *
  14806. * @return {Element}
  14807. * The element that was created.
  14808. */
  14809. var _proto = VolumeBar.prototype;
  14810. _proto.createEl = function createEl() {
  14811. return _Slider.prototype.createEl.call(this, 'div', {
  14812. className: 'vjs-volume-bar vjs-slider-bar'
  14813. }, {
  14814. 'aria-label': this.localize('Volume Level'),
  14815. 'aria-live': 'polite'
  14816. });
  14817. }
  14818. /**
  14819. * Handle mouse down on volume bar
  14820. *
  14821. * @param {EventTarget~Event} event
  14822. * The `mousedown` event that caused this to run.
  14823. *
  14824. * @listens mousedown
  14825. */
  14826. ;
  14827. _proto.handleMouseDown = function handleMouseDown(event) {
  14828. if (!isSingleLeftClick(event)) {
  14829. return;
  14830. }
  14831. _Slider.prototype.handleMouseDown.call(this, event);
  14832. }
  14833. /**
  14834. * Handle movement events on the {@link VolumeMenuButton}.
  14835. *
  14836. * @param {EventTarget~Event} event
  14837. * The event that caused this function to run.
  14838. *
  14839. * @listens mousemove
  14840. */
  14841. ;
  14842. _proto.handleMouseMove = function handleMouseMove(event) {
  14843. var mouseVolumeLevelDisplay = this.getChild('mouseVolumeLevelDisplay');
  14844. if (mouseVolumeLevelDisplay) {
  14845. var volumeBarEl = this.el();
  14846. var volumeBarRect = getBoundingClientRect(volumeBarEl);
  14847. var vertical = this.vertical();
  14848. var volumeBarPoint = getPointerPosition(volumeBarEl, event);
  14849. volumeBarPoint = vertical ? volumeBarPoint.y : volumeBarPoint.x; // The default skin has a gap on either side of the `VolumeBar`. This means
  14850. // that it's possible to trigger this behavior outside the boundaries of
  14851. // the `VolumeBar`. This ensures we stay within it at all times.
  14852. volumeBarPoint = clamp(volumeBarPoint, 0, 1);
  14853. mouseVolumeLevelDisplay.update(volumeBarRect, volumeBarPoint, vertical);
  14854. }
  14855. if (!isSingleLeftClick(event)) {
  14856. return;
  14857. }
  14858. this.checkMuted();
  14859. this.player_.volume(this.calculateDistance(event));
  14860. }
  14861. /**
  14862. * If the player is muted unmute it.
  14863. */
  14864. ;
  14865. _proto.checkMuted = function checkMuted() {
  14866. if (this.player_.muted()) {
  14867. this.player_.muted(false);
  14868. }
  14869. }
  14870. /**
  14871. * Get percent of volume level
  14872. *
  14873. * @return {number}
  14874. * Volume level percent as a decimal number.
  14875. */
  14876. ;
  14877. _proto.getPercent = function getPercent() {
  14878. if (this.player_.muted()) {
  14879. return 0;
  14880. }
  14881. return this.player_.volume();
  14882. }
  14883. /**
  14884. * Increase volume level for keyboard users
  14885. */
  14886. ;
  14887. _proto.stepForward = function stepForward() {
  14888. this.checkMuted();
  14889. this.player_.volume(this.player_.volume() + 0.1);
  14890. }
  14891. /**
  14892. * Decrease volume level for keyboard users
  14893. */
  14894. ;
  14895. _proto.stepBack = function stepBack() {
  14896. this.checkMuted();
  14897. this.player_.volume(this.player_.volume() - 0.1);
  14898. }
  14899. /**
  14900. * Update ARIA accessibility attributes
  14901. *
  14902. * @param {EventTarget~Event} [event]
  14903. * The `volumechange` event that caused this function to run.
  14904. *
  14905. * @listens Player#volumechange
  14906. */
  14907. ;
  14908. _proto.updateARIAAttributes = function updateARIAAttributes(event) {
  14909. var ariaValue = this.player_.muted() ? 0 : this.volumeAsPercentage_();
  14910. this.el_.setAttribute('aria-valuenow', ariaValue);
  14911. this.el_.setAttribute('aria-valuetext', ariaValue + '%');
  14912. }
  14913. /**
  14914. * Returns the current value of the player volume as a percentage
  14915. *
  14916. * @private
  14917. */
  14918. ;
  14919. _proto.volumeAsPercentage_ = function volumeAsPercentage_() {
  14920. return Math.round(this.player_.volume() * 100);
  14921. }
  14922. /**
  14923. * When user starts dragging the VolumeBar, store the volume and listen for
  14924. * the end of the drag. When the drag ends, if the volume was set to zero,
  14925. * set lastVolume to the stored volume.
  14926. *
  14927. * @listens slideractive
  14928. * @private
  14929. */
  14930. ;
  14931. _proto.updateLastVolume_ = function updateLastVolume_() {
  14932. var _this2 = this;
  14933. var volumeBeforeDrag = this.player_.volume();
  14934. this.one('sliderinactive', function () {
  14935. if (_this2.player_.volume() === 0) {
  14936. _this2.player_.lastVolume_(volumeBeforeDrag);
  14937. }
  14938. });
  14939. };
  14940. return VolumeBar;
  14941. }(Slider);
  14942. /**
  14943. * Default options for the `VolumeBar`
  14944. *
  14945. * @type {Object}
  14946. * @private
  14947. */
  14948. VolumeBar.prototype.options_ = {
  14949. children: ['volumeLevel'],
  14950. barName: 'volumeLevel'
  14951. }; // MouseVolumeLevelDisplay tooltip should not be added to a player on mobile devices
  14952. if (!IS_IOS && !IS_ANDROID) {
  14953. VolumeBar.prototype.options_.children.splice(0, 0, 'mouseVolumeLevelDisplay');
  14954. }
  14955. /**
  14956. * Call the update event for this Slider when this event happens on the player.
  14957. *
  14958. * @type {string}
  14959. */
  14960. VolumeBar.prototype.playerEvent = 'volumechange';
  14961. Component.registerComponent('VolumeBar', VolumeBar);
  14962. /**
  14963. * The component for controlling the volume level
  14964. *
  14965. * @extends Component
  14966. */
  14967. var VolumeControl = /*#__PURE__*/function (_Component) {
  14968. inheritsLoose(VolumeControl, _Component);
  14969. /**
  14970. * Creates an instance of this class.
  14971. *
  14972. * @param {Player} player
  14973. * The `Player` that this class should be attached to.
  14974. *
  14975. * @param {Object} [options={}]
  14976. * The key/value store of player options.
  14977. */
  14978. function VolumeControl(player, options) {
  14979. var _this;
  14980. if (options === void 0) {
  14981. options = {};
  14982. }
  14983. options.vertical = options.vertical || false; // Pass the vertical option down to the VolumeBar if
  14984. // the VolumeBar is turned on.
  14985. if (typeof options.volumeBar === 'undefined' || isPlain(options.volumeBar)) {
  14986. options.volumeBar = options.volumeBar || {};
  14987. options.volumeBar.vertical = options.vertical;
  14988. }
  14989. _this = _Component.call(this, player, options) || this; // hide this control if volume support is missing
  14990. checkVolumeSupport(assertThisInitialized(_this), player);
  14991. _this.throttledHandleMouseMove = throttle(bind(assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  14992. _this.handleMouseUpHandler_ = function (e) {
  14993. return _this.handleMouseUp(e);
  14994. };
  14995. _this.on('mousedown', function (e) {
  14996. return _this.handleMouseDown(e);
  14997. });
  14998. _this.on('touchstart', function (e) {
  14999. return _this.handleMouseDown(e);
  15000. });
  15001. _this.on('mousemove', function (e) {
  15002. return _this.handleMouseMove(e);
  15003. }); // while the slider is active (the mouse has been pressed down and
  15004. // is dragging) or in focus we do not want to hide the VolumeBar
  15005. _this.on(_this.volumeBar, ['focus', 'slideractive'], function () {
  15006. _this.volumeBar.addClass('vjs-slider-active');
  15007. _this.addClass('vjs-slider-active');
  15008. _this.trigger('slideractive');
  15009. });
  15010. _this.on(_this.volumeBar, ['blur', 'sliderinactive'], function () {
  15011. _this.volumeBar.removeClass('vjs-slider-active');
  15012. _this.removeClass('vjs-slider-active');
  15013. _this.trigger('sliderinactive');
  15014. });
  15015. return _this;
  15016. }
  15017. /**
  15018. * Create the `Component`'s DOM element
  15019. *
  15020. * @return {Element}
  15021. * The element that was created.
  15022. */
  15023. var _proto = VolumeControl.prototype;
  15024. _proto.createEl = function createEl() {
  15025. var orientationClass = 'vjs-volume-horizontal';
  15026. if (this.options_.vertical) {
  15027. orientationClass = 'vjs-volume-vertical';
  15028. }
  15029. return _Component.prototype.createEl.call(this, 'div', {
  15030. className: "vjs-volume-control vjs-control " + orientationClass
  15031. });
  15032. }
  15033. /**
  15034. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  15035. *
  15036. * @param {EventTarget~Event} event
  15037. * `mousedown` or `touchstart` event that triggered this function
  15038. *
  15039. * @listens mousedown
  15040. * @listens touchstart
  15041. */
  15042. ;
  15043. _proto.handleMouseDown = function handleMouseDown(event) {
  15044. var doc = this.el_.ownerDocument;
  15045. this.on(doc, 'mousemove', this.throttledHandleMouseMove);
  15046. this.on(doc, 'touchmove', this.throttledHandleMouseMove);
  15047. this.on(doc, 'mouseup', this.handleMouseUpHandler_);
  15048. this.on(doc, 'touchend', this.handleMouseUpHandler_);
  15049. }
  15050. /**
  15051. * Handle `mouseup` or `touchend` events on the `VolumeControl`.
  15052. *
  15053. * @param {EventTarget~Event} event
  15054. * `mouseup` or `touchend` event that triggered this function.
  15055. *
  15056. * @listens touchend
  15057. * @listens mouseup
  15058. */
  15059. ;
  15060. _proto.handleMouseUp = function handleMouseUp(event) {
  15061. var doc = this.el_.ownerDocument;
  15062. this.off(doc, 'mousemove', this.throttledHandleMouseMove);
  15063. this.off(doc, 'touchmove', this.throttledHandleMouseMove);
  15064. this.off(doc, 'mouseup', this.handleMouseUpHandler_);
  15065. this.off(doc, 'touchend', this.handleMouseUpHandler_);
  15066. }
  15067. /**
  15068. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  15069. *
  15070. * @param {EventTarget~Event} event
  15071. * `mousedown` or `touchstart` event that triggered this function
  15072. *
  15073. * @listens mousedown
  15074. * @listens touchstart
  15075. */
  15076. ;
  15077. _proto.handleMouseMove = function handleMouseMove(event) {
  15078. this.volumeBar.handleMouseMove(event);
  15079. };
  15080. return VolumeControl;
  15081. }(Component);
  15082. /**
  15083. * Default options for the `VolumeControl`
  15084. *
  15085. * @type {Object}
  15086. * @private
  15087. */
  15088. VolumeControl.prototype.options_ = {
  15089. children: ['volumeBar']
  15090. };
  15091. Component.registerComponent('VolumeControl', VolumeControl);
  15092. /**
  15093. * Check if muting volume is supported and if it isn't hide the mute toggle
  15094. * button.
  15095. *
  15096. * @param {Component} self
  15097. * A reference to the mute toggle button
  15098. *
  15099. * @param {Player} player
  15100. * A reference to the player
  15101. *
  15102. * @private
  15103. */
  15104. var checkMuteSupport = function checkMuteSupport(self, player) {
  15105. // hide mute toggle button if it's not supported by the current tech
  15106. if (player.tech_ && !player.tech_.featuresMuteControl) {
  15107. self.addClass('vjs-hidden');
  15108. }
  15109. self.on(player, 'loadstart', function () {
  15110. if (!player.tech_.featuresMuteControl) {
  15111. self.addClass('vjs-hidden');
  15112. } else {
  15113. self.removeClass('vjs-hidden');
  15114. }
  15115. });
  15116. };
  15117. /**
  15118. * A button component for muting the audio.
  15119. *
  15120. * @extends Button
  15121. */
  15122. var MuteToggle = /*#__PURE__*/function (_Button) {
  15123. inheritsLoose(MuteToggle, _Button);
  15124. /**
  15125. * Creates an instance of this class.
  15126. *
  15127. * @param {Player} player
  15128. * The `Player` that this class should be attached to.
  15129. *
  15130. * @param {Object} [options]
  15131. * The key/value store of player options.
  15132. */
  15133. function MuteToggle(player, options) {
  15134. var _this;
  15135. _this = _Button.call(this, player, options) || this; // hide this control if volume support is missing
  15136. checkMuteSupport(assertThisInitialized(_this), player);
  15137. _this.on(player, ['loadstart', 'volumechange'], function (e) {
  15138. return _this.update(e);
  15139. });
  15140. return _this;
  15141. }
  15142. /**
  15143. * Builds the default DOM `className`.
  15144. *
  15145. * @return {string}
  15146. * The DOM `className` for this object.
  15147. */
  15148. var _proto = MuteToggle.prototype;
  15149. _proto.buildCSSClass = function buildCSSClass() {
  15150. return "vjs-mute-control " + _Button.prototype.buildCSSClass.call(this);
  15151. }
  15152. /**
  15153. * This gets called when an `MuteToggle` is "clicked". See
  15154. * {@link ClickableComponent} for more detailed information on what a click can be.
  15155. *
  15156. * @param {EventTarget~Event} [event]
  15157. * The `keydown`, `tap`, or `click` event that caused this function to be
  15158. * called.
  15159. *
  15160. * @listens tap
  15161. * @listens click
  15162. */
  15163. ;
  15164. _proto.handleClick = function handleClick(event) {
  15165. var vol = this.player_.volume();
  15166. var lastVolume = this.player_.lastVolume_();
  15167. if (vol === 0) {
  15168. var volumeToSet = lastVolume < 0.1 ? 0.1 : lastVolume;
  15169. this.player_.volume(volumeToSet);
  15170. this.player_.muted(false);
  15171. } else {
  15172. this.player_.muted(this.player_.muted() ? false : true);
  15173. }
  15174. }
  15175. /**
  15176. * Update the `MuteToggle` button based on the state of `volume` and `muted`
  15177. * on the player.
  15178. *
  15179. * @param {EventTarget~Event} [event]
  15180. * The {@link Player#loadstart} event if this function was called
  15181. * through an event.
  15182. *
  15183. * @listens Player#loadstart
  15184. * @listens Player#volumechange
  15185. */
  15186. ;
  15187. _proto.update = function update(event) {
  15188. this.updateIcon_();
  15189. this.updateControlText_();
  15190. }
  15191. /**
  15192. * Update the appearance of the `MuteToggle` icon.
  15193. *
  15194. * Possible states (given `level` variable below):
  15195. * - 0: crossed out
  15196. * - 1: zero bars of volume
  15197. * - 2: one bar of volume
  15198. * - 3: two bars of volume
  15199. *
  15200. * @private
  15201. */
  15202. ;
  15203. _proto.updateIcon_ = function updateIcon_() {
  15204. var vol = this.player_.volume();
  15205. var level = 3; // in iOS when a player is loaded with muted attribute
  15206. // and volume is changed with a native mute button
  15207. // we want to make sure muted state is updated
  15208. if (IS_IOS && this.player_.tech_ && this.player_.tech_.el_) {
  15209. this.player_.muted(this.player_.tech_.el_.muted);
  15210. }
  15211. if (vol === 0 || this.player_.muted()) {
  15212. level = 0;
  15213. } else if (vol < 0.33) {
  15214. level = 1;
  15215. } else if (vol < 0.67) {
  15216. level = 2;
  15217. } // TODO improve muted icon classes
  15218. for (var i = 0; i < 4; i++) {
  15219. removeClass(this.el_, "vjs-vol-" + i);
  15220. }
  15221. addClass(this.el_, "vjs-vol-" + level);
  15222. }
  15223. /**
  15224. * If `muted` has changed on the player, update the control text
  15225. * (`title` attribute on `vjs-mute-control` element and content of
  15226. * `vjs-control-text` element).
  15227. *
  15228. * @private
  15229. */
  15230. ;
  15231. _proto.updateControlText_ = function updateControlText_() {
  15232. var soundOff = this.player_.muted() || this.player_.volume() === 0;
  15233. var text = soundOff ? 'Unmute' : 'Mute';
  15234. if (this.controlText() !== text) {
  15235. this.controlText(text);
  15236. }
  15237. };
  15238. return MuteToggle;
  15239. }(Button);
  15240. /**
  15241. * The text that should display over the `MuteToggle`s controls. Added for localization.
  15242. *
  15243. * @type {string}
  15244. * @private
  15245. */
  15246. MuteToggle.prototype.controlText_ = 'Mute';
  15247. Component.registerComponent('MuteToggle', MuteToggle);
  15248. /**
  15249. * A Component to contain the MuteToggle and VolumeControl so that
  15250. * they can work together.
  15251. *
  15252. * @extends Component
  15253. */
  15254. var VolumePanel = /*#__PURE__*/function (_Component) {
  15255. inheritsLoose(VolumePanel, _Component);
  15256. /**
  15257. * Creates an instance of this class.
  15258. *
  15259. * @param {Player} player
  15260. * The `Player` that this class should be attached to.
  15261. *
  15262. * @param {Object} [options={}]
  15263. * The key/value store of player options.
  15264. */
  15265. function VolumePanel(player, options) {
  15266. var _this;
  15267. if (options === void 0) {
  15268. options = {};
  15269. }
  15270. if (typeof options.inline !== 'undefined') {
  15271. options.inline = options.inline;
  15272. } else {
  15273. options.inline = true;
  15274. } // pass the inline option down to the VolumeControl as vertical if
  15275. // the VolumeControl is on.
  15276. if (typeof options.volumeControl === 'undefined' || isPlain(options.volumeControl)) {
  15277. options.volumeControl = options.volumeControl || {};
  15278. options.volumeControl.vertical = !options.inline;
  15279. }
  15280. _this = _Component.call(this, player, options) || this; // this handler is used by mouse handler methods below
  15281. _this.handleKeyPressHandler_ = function (e) {
  15282. return _this.handleKeyPress(e);
  15283. };
  15284. _this.on(player, ['loadstart'], function (e) {
  15285. return _this.volumePanelState_(e);
  15286. });
  15287. _this.on(_this.muteToggle, 'keyup', function (e) {
  15288. return _this.handleKeyPress(e);
  15289. });
  15290. _this.on(_this.volumeControl, 'keyup', function (e) {
  15291. return _this.handleVolumeControlKeyUp(e);
  15292. });
  15293. _this.on('keydown', function (e) {
  15294. return _this.handleKeyPress(e);
  15295. });
  15296. _this.on('mouseover', function (e) {
  15297. return _this.handleMouseOver(e);
  15298. });
  15299. _this.on('mouseout', function (e) {
  15300. return _this.handleMouseOut(e);
  15301. }); // while the slider is active (the mouse has been pressed down and
  15302. // is dragging) we do not want to hide the VolumeBar
  15303. _this.on(_this.volumeControl, ['slideractive'], _this.sliderActive_);
  15304. _this.on(_this.volumeControl, ['sliderinactive'], _this.sliderInactive_);
  15305. return _this;
  15306. }
  15307. /**
  15308. * Add vjs-slider-active class to the VolumePanel
  15309. *
  15310. * @listens VolumeControl#slideractive
  15311. * @private
  15312. */
  15313. var _proto = VolumePanel.prototype;
  15314. _proto.sliderActive_ = function sliderActive_() {
  15315. this.addClass('vjs-slider-active');
  15316. }
  15317. /**
  15318. * Removes vjs-slider-active class to the VolumePanel
  15319. *
  15320. * @listens VolumeControl#sliderinactive
  15321. * @private
  15322. */
  15323. ;
  15324. _proto.sliderInactive_ = function sliderInactive_() {
  15325. this.removeClass('vjs-slider-active');
  15326. }
  15327. /**
  15328. * Adds vjs-hidden or vjs-mute-toggle-only to the VolumePanel
  15329. * depending on MuteToggle and VolumeControl state
  15330. *
  15331. * @listens Player#loadstart
  15332. * @private
  15333. */
  15334. ;
  15335. _proto.volumePanelState_ = function volumePanelState_() {
  15336. // hide volume panel if neither volume control or mute toggle
  15337. // are displayed
  15338. if (this.volumeControl.hasClass('vjs-hidden') && this.muteToggle.hasClass('vjs-hidden')) {
  15339. this.addClass('vjs-hidden');
  15340. } // if only mute toggle is visible we don't want
  15341. // volume panel expanding when hovered or active
  15342. if (this.volumeControl.hasClass('vjs-hidden') && !this.muteToggle.hasClass('vjs-hidden')) {
  15343. this.addClass('vjs-mute-toggle-only');
  15344. }
  15345. }
  15346. /**
  15347. * Create the `Component`'s DOM element
  15348. *
  15349. * @return {Element}
  15350. * The element that was created.
  15351. */
  15352. ;
  15353. _proto.createEl = function createEl() {
  15354. var orientationClass = 'vjs-volume-panel-horizontal';
  15355. if (!this.options_.inline) {
  15356. orientationClass = 'vjs-volume-panel-vertical';
  15357. }
  15358. return _Component.prototype.createEl.call(this, 'div', {
  15359. className: "vjs-volume-panel vjs-control " + orientationClass
  15360. });
  15361. }
  15362. /**
  15363. * Dispose of the `volume-panel` and all child components.
  15364. */
  15365. ;
  15366. _proto.dispose = function dispose() {
  15367. this.handleMouseOut();
  15368. _Component.prototype.dispose.call(this);
  15369. }
  15370. /**
  15371. * Handles `keyup` events on the `VolumeControl`, looking for ESC, which closes
  15372. * the volume panel and sets focus on `MuteToggle`.
  15373. *
  15374. * @param {EventTarget~Event} event
  15375. * The `keyup` event that caused this function to be called.
  15376. *
  15377. * @listens keyup
  15378. */
  15379. ;
  15380. _proto.handleVolumeControlKeyUp = function handleVolumeControlKeyUp(event) {
  15381. if (keycode.isEventKey(event, 'Esc')) {
  15382. this.muteToggle.focus();
  15383. }
  15384. }
  15385. /**
  15386. * This gets called when a `VolumePanel` gains hover via a `mouseover` event.
  15387. * Turns on listening for `mouseover` event. When they happen it
  15388. * calls `this.handleMouseOver`.
  15389. *
  15390. * @param {EventTarget~Event} event
  15391. * The `mouseover` event that caused this function to be called.
  15392. *
  15393. * @listens mouseover
  15394. */
  15395. ;
  15396. _proto.handleMouseOver = function handleMouseOver(event) {
  15397. this.addClass('vjs-hover');
  15398. on(document, 'keyup', this.handleKeyPressHandler_);
  15399. }
  15400. /**
  15401. * This gets called when a `VolumePanel` gains hover via a `mouseout` event.
  15402. * Turns on listening for `mouseout` event. When they happen it
  15403. * calls `this.handleMouseOut`.
  15404. *
  15405. * @param {EventTarget~Event} event
  15406. * The `mouseout` event that caused this function to be called.
  15407. *
  15408. * @listens mouseout
  15409. */
  15410. ;
  15411. _proto.handleMouseOut = function handleMouseOut(event) {
  15412. this.removeClass('vjs-hover');
  15413. off(document, 'keyup', this.handleKeyPressHandler_);
  15414. }
  15415. /**
  15416. * Handles `keyup` event on the document or `keydown` event on the `VolumePanel`,
  15417. * looking for ESC, which hides the `VolumeControl`.
  15418. *
  15419. * @param {EventTarget~Event} event
  15420. * The keypress that triggered this event.
  15421. *
  15422. * @listens keydown | keyup
  15423. */
  15424. ;
  15425. _proto.handleKeyPress = function handleKeyPress(event) {
  15426. if (keycode.isEventKey(event, 'Esc')) {
  15427. this.handleMouseOut();
  15428. }
  15429. };
  15430. return VolumePanel;
  15431. }(Component);
  15432. /**
  15433. * Default options for the `VolumeControl`
  15434. *
  15435. * @type {Object}
  15436. * @private
  15437. */
  15438. VolumePanel.prototype.options_ = {
  15439. children: ['muteToggle', 'volumeControl']
  15440. };
  15441. Component.registerComponent('VolumePanel', VolumePanel);
  15442. /**
  15443. * The Menu component is used to build popup menus, including subtitle and
  15444. * captions selection menus.
  15445. *
  15446. * @extends Component
  15447. */
  15448. var Menu = /*#__PURE__*/function (_Component) {
  15449. inheritsLoose(Menu, _Component);
  15450. /**
  15451. * Create an instance of this class.
  15452. *
  15453. * @param {Player} player
  15454. * the player that this component should attach to
  15455. *
  15456. * @param {Object} [options]
  15457. * Object of option names and values
  15458. *
  15459. */
  15460. function Menu(player, options) {
  15461. var _this;
  15462. _this = _Component.call(this, player, options) || this;
  15463. if (options) {
  15464. _this.menuButton_ = options.menuButton;
  15465. }
  15466. _this.focusedChild_ = -1;
  15467. _this.on('keydown', function (e) {
  15468. return _this.handleKeyDown(e);
  15469. }); // All the menu item instances share the same blur handler provided by the menu container.
  15470. _this.boundHandleBlur_ = function (e) {
  15471. return _this.handleBlur(e);
  15472. };
  15473. _this.boundHandleTapClick_ = function (e) {
  15474. return _this.handleTapClick(e);
  15475. };
  15476. return _this;
  15477. }
  15478. /**
  15479. * Add event listeners to the {@link MenuItem}.
  15480. *
  15481. * @param {Object} component
  15482. * The instance of the `MenuItem` to add listeners to.
  15483. *
  15484. */
  15485. var _proto = Menu.prototype;
  15486. _proto.addEventListenerForItem = function addEventListenerForItem(component) {
  15487. if (!(component instanceof Component)) {
  15488. return;
  15489. }
  15490. this.on(component, 'blur', this.boundHandleBlur_);
  15491. this.on(component, ['tap', 'click'], this.boundHandleTapClick_);
  15492. }
  15493. /**
  15494. * Remove event listeners from the {@link MenuItem}.
  15495. *
  15496. * @param {Object} component
  15497. * The instance of the `MenuItem` to remove listeners.
  15498. *
  15499. */
  15500. ;
  15501. _proto.removeEventListenerForItem = function removeEventListenerForItem(component) {
  15502. if (!(component instanceof Component)) {
  15503. return;
  15504. }
  15505. this.off(component, 'blur', this.boundHandleBlur_);
  15506. this.off(component, ['tap', 'click'], this.boundHandleTapClick_);
  15507. }
  15508. /**
  15509. * This method will be called indirectly when the component has been added
  15510. * before the component adds to the new menu instance by `addItem`.
  15511. * In this case, the original menu instance will remove the component
  15512. * by calling `removeChild`.
  15513. *
  15514. * @param {Object} component
  15515. * The instance of the `MenuItem`
  15516. */
  15517. ;
  15518. _proto.removeChild = function removeChild(component) {
  15519. if (typeof component === 'string') {
  15520. component = this.getChild(component);
  15521. }
  15522. this.removeEventListenerForItem(component);
  15523. _Component.prototype.removeChild.call(this, component);
  15524. }
  15525. /**
  15526. * Add a {@link MenuItem} to the menu.
  15527. *
  15528. * @param {Object|string} component
  15529. * The name or instance of the `MenuItem` to add.
  15530. *
  15531. */
  15532. ;
  15533. _proto.addItem = function addItem(component) {
  15534. var childComponent = this.addChild(component);
  15535. if (childComponent) {
  15536. this.addEventListenerForItem(childComponent);
  15537. }
  15538. }
  15539. /**
  15540. * Create the `Menu`s DOM element.
  15541. *
  15542. * @return {Element}
  15543. * the element that was created
  15544. */
  15545. ;
  15546. _proto.createEl = function createEl$1() {
  15547. var contentElType = this.options_.contentElType || 'ul';
  15548. this.contentEl_ = createEl(contentElType, {
  15549. className: 'vjs-menu-content'
  15550. });
  15551. this.contentEl_.setAttribute('role', 'menu');
  15552. var el = _Component.prototype.createEl.call(this, 'div', {
  15553. append: this.contentEl_,
  15554. className: 'vjs-menu'
  15555. });
  15556. el.appendChild(this.contentEl_); // Prevent clicks from bubbling up. Needed for Menu Buttons,
  15557. // where a click on the parent is significant
  15558. on(el, 'click', function (event) {
  15559. event.preventDefault();
  15560. event.stopImmediatePropagation();
  15561. });
  15562. return el;
  15563. };
  15564. _proto.dispose = function dispose() {
  15565. this.contentEl_ = null;
  15566. this.boundHandleBlur_ = null;
  15567. this.boundHandleTapClick_ = null;
  15568. _Component.prototype.dispose.call(this);
  15569. }
  15570. /**
  15571. * Called when a `MenuItem` loses focus.
  15572. *
  15573. * @param {EventTarget~Event} event
  15574. * The `blur` event that caused this function to be called.
  15575. *
  15576. * @listens blur
  15577. */
  15578. ;
  15579. _proto.handleBlur = function handleBlur(event) {
  15580. var relatedTarget = event.relatedTarget || document.activeElement; // Close menu popup when a user clicks outside the menu
  15581. if (!this.children().some(function (element) {
  15582. return element.el() === relatedTarget;
  15583. })) {
  15584. var btn = this.menuButton_;
  15585. if (btn && btn.buttonPressed_ && relatedTarget !== btn.el().firstChild) {
  15586. btn.unpressButton();
  15587. }
  15588. }
  15589. }
  15590. /**
  15591. * Called when a `MenuItem` gets clicked or tapped.
  15592. *
  15593. * @param {EventTarget~Event} event
  15594. * The `click` or `tap` event that caused this function to be called.
  15595. *
  15596. * @listens click,tap
  15597. */
  15598. ;
  15599. _proto.handleTapClick = function handleTapClick(event) {
  15600. // Unpress the associated MenuButton, and move focus back to it
  15601. if (this.menuButton_) {
  15602. this.menuButton_.unpressButton();
  15603. var childComponents = this.children();
  15604. if (!Array.isArray(childComponents)) {
  15605. return;
  15606. }
  15607. var foundComponent = childComponents.filter(function (component) {
  15608. return component.el() === event.target;
  15609. })[0];
  15610. if (!foundComponent) {
  15611. return;
  15612. } // don't focus menu button if item is a caption settings item
  15613. // because focus will move elsewhere
  15614. if (foundComponent.name() !== 'CaptionSettingsMenuItem') {
  15615. this.menuButton_.focus();
  15616. }
  15617. }
  15618. }
  15619. /**
  15620. * Handle a `keydown` event on this menu. This listener is added in the constructor.
  15621. *
  15622. * @param {EventTarget~Event} event
  15623. * A `keydown` event that happened on the menu.
  15624. *
  15625. * @listens keydown
  15626. */
  15627. ;
  15628. _proto.handleKeyDown = function handleKeyDown(event) {
  15629. // Left and Down Arrows
  15630. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  15631. event.preventDefault();
  15632. event.stopPropagation();
  15633. this.stepForward(); // Up and Right Arrows
  15634. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  15635. event.preventDefault();
  15636. event.stopPropagation();
  15637. this.stepBack();
  15638. }
  15639. }
  15640. /**
  15641. * Move to next (lower) menu item for keyboard users.
  15642. */
  15643. ;
  15644. _proto.stepForward = function stepForward() {
  15645. var stepChild = 0;
  15646. if (this.focusedChild_ !== undefined) {
  15647. stepChild = this.focusedChild_ + 1;
  15648. }
  15649. this.focus(stepChild);
  15650. }
  15651. /**
  15652. * Move to previous (higher) menu item for keyboard users.
  15653. */
  15654. ;
  15655. _proto.stepBack = function stepBack() {
  15656. var stepChild = 0;
  15657. if (this.focusedChild_ !== undefined) {
  15658. stepChild = this.focusedChild_ - 1;
  15659. }
  15660. this.focus(stepChild);
  15661. }
  15662. /**
  15663. * Set focus on a {@link MenuItem} in the `Menu`.
  15664. *
  15665. * @param {Object|string} [item=0]
  15666. * Index of child item set focus on.
  15667. */
  15668. ;
  15669. _proto.focus = function focus(item) {
  15670. if (item === void 0) {
  15671. item = 0;
  15672. }
  15673. var children = this.children().slice();
  15674. var haveTitle = children.length && children[0].hasClass('vjs-menu-title');
  15675. if (haveTitle) {
  15676. children.shift();
  15677. }
  15678. if (children.length > 0) {
  15679. if (item < 0) {
  15680. item = 0;
  15681. } else if (item >= children.length) {
  15682. item = children.length - 1;
  15683. }
  15684. this.focusedChild_ = item;
  15685. children[item].el_.focus();
  15686. }
  15687. };
  15688. return Menu;
  15689. }(Component);
  15690. Component.registerComponent('Menu', Menu);
  15691. /**
  15692. * A `MenuButton` class for any popup {@link Menu}.
  15693. *
  15694. * @extends Component
  15695. */
  15696. var MenuButton = /*#__PURE__*/function (_Component) {
  15697. inheritsLoose(MenuButton, _Component);
  15698. /**
  15699. * Creates an instance of this class.
  15700. *
  15701. * @param {Player} player
  15702. * The `Player` that this class should be attached to.
  15703. *
  15704. * @param {Object} [options={}]
  15705. * The key/value store of player options.
  15706. */
  15707. function MenuButton(player, options) {
  15708. var _this;
  15709. if (options === void 0) {
  15710. options = {};
  15711. }
  15712. _this = _Component.call(this, player, options) || this;
  15713. _this.menuButton_ = new Button(player, options);
  15714. _this.menuButton_.controlText(_this.controlText_);
  15715. _this.menuButton_.el_.setAttribute('aria-haspopup', 'true'); // Add buildCSSClass values to the button, not the wrapper
  15716. var buttonClass = Button.prototype.buildCSSClass();
  15717. _this.menuButton_.el_.className = _this.buildCSSClass() + ' ' + buttonClass;
  15718. _this.menuButton_.removeClass('vjs-control');
  15719. _this.addChild(_this.menuButton_);
  15720. _this.update();
  15721. _this.enabled_ = true;
  15722. var handleClick = function handleClick(e) {
  15723. return _this.handleClick(e);
  15724. };
  15725. _this.handleMenuKeyUp_ = function (e) {
  15726. return _this.handleMenuKeyUp(e);
  15727. };
  15728. _this.on(_this.menuButton_, 'tap', handleClick);
  15729. _this.on(_this.menuButton_, 'click', handleClick);
  15730. _this.on(_this.menuButton_, 'keydown', function (e) {
  15731. return _this.handleKeyDown(e);
  15732. });
  15733. _this.on(_this.menuButton_, 'mouseenter', function () {
  15734. _this.addClass('vjs-hover');
  15735. _this.menu.show();
  15736. on(document, 'keyup', _this.handleMenuKeyUp_);
  15737. });
  15738. _this.on('mouseleave', function (e) {
  15739. return _this.handleMouseLeave(e);
  15740. });
  15741. _this.on('keydown', function (e) {
  15742. return _this.handleSubmenuKeyDown(e);
  15743. });
  15744. return _this;
  15745. }
  15746. /**
  15747. * Update the menu based on the current state of its items.
  15748. */
  15749. var _proto = MenuButton.prototype;
  15750. _proto.update = function update() {
  15751. var menu = this.createMenu();
  15752. if (this.menu) {
  15753. this.menu.dispose();
  15754. this.removeChild(this.menu);
  15755. }
  15756. this.menu = menu;
  15757. this.addChild(menu);
  15758. /**
  15759. * Track the state of the menu button
  15760. *
  15761. * @type {Boolean}
  15762. * @private
  15763. */
  15764. this.buttonPressed_ = false;
  15765. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  15766. if (this.items && this.items.length <= this.hideThreshold_) {
  15767. this.hide();
  15768. this.menu.contentEl_.removeAttribute('role');
  15769. } else {
  15770. this.show();
  15771. this.menu.contentEl_.setAttribute('role', 'menu');
  15772. }
  15773. }
  15774. /**
  15775. * Create the menu and add all items to it.
  15776. *
  15777. * @return {Menu}
  15778. * The constructed menu
  15779. */
  15780. ;
  15781. _proto.createMenu = function createMenu() {
  15782. var menu = new Menu(this.player_, {
  15783. menuButton: this
  15784. });
  15785. /**
  15786. * Hide the menu if the number of items is less than or equal to this threshold. This defaults
  15787. * to 0 and whenever we add items which can be hidden to the menu we'll increment it. We list
  15788. * it here because every time we run `createMenu` we need to reset the value.
  15789. *
  15790. * @protected
  15791. * @type {Number}
  15792. */
  15793. this.hideThreshold_ = 0; // Add a title list item to the top
  15794. if (this.options_.title) {
  15795. var titleEl = createEl('li', {
  15796. className: 'vjs-menu-title',
  15797. textContent: toTitleCase(this.options_.title),
  15798. tabIndex: -1
  15799. });
  15800. var titleComponent = new Component(this.player_, {
  15801. el: titleEl
  15802. });
  15803. menu.addItem(titleComponent);
  15804. }
  15805. this.items = this.createItems();
  15806. if (this.items) {
  15807. // Add menu items to the menu
  15808. for (var i = 0; i < this.items.length; i++) {
  15809. menu.addItem(this.items[i]);
  15810. }
  15811. }
  15812. return menu;
  15813. }
  15814. /**
  15815. * Create the list of menu items. Specific to each subclass.
  15816. *
  15817. * @abstract
  15818. */
  15819. ;
  15820. _proto.createItems = function createItems() {}
  15821. /**
  15822. * Create the `MenuButtons`s DOM element.
  15823. *
  15824. * @return {Element}
  15825. * The element that gets created.
  15826. */
  15827. ;
  15828. _proto.createEl = function createEl() {
  15829. return _Component.prototype.createEl.call(this, 'div', {
  15830. className: this.buildWrapperCSSClass()
  15831. }, {});
  15832. }
  15833. /**
  15834. * Allow sub components to stack CSS class names for the wrapper element
  15835. *
  15836. * @return {string}
  15837. * The constructed wrapper DOM `className`
  15838. */
  15839. ;
  15840. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15841. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  15842. if (this.options_.inline === true) {
  15843. menuButtonClass += '-inline';
  15844. } else {
  15845. menuButtonClass += '-popup';
  15846. } // TODO: Fix the CSS so that this isn't necessary
  15847. var buttonClass = Button.prototype.buildCSSClass();
  15848. return "vjs-menu-button " + menuButtonClass + " " + buttonClass + " " + _Component.prototype.buildCSSClass.call(this);
  15849. }
  15850. /**
  15851. * Builds the default DOM `className`.
  15852. *
  15853. * @return {string}
  15854. * The DOM `className` for this object.
  15855. */
  15856. ;
  15857. _proto.buildCSSClass = function buildCSSClass() {
  15858. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  15859. if (this.options_.inline === true) {
  15860. menuButtonClass += '-inline';
  15861. } else {
  15862. menuButtonClass += '-popup';
  15863. }
  15864. return "vjs-menu-button " + menuButtonClass + " " + _Component.prototype.buildCSSClass.call(this);
  15865. }
  15866. /**
  15867. * Get or set the localized control text that will be used for accessibility.
  15868. *
  15869. * > NOTE: This will come from the internal `menuButton_` element.
  15870. *
  15871. * @param {string} [text]
  15872. * Control text for element.
  15873. *
  15874. * @param {Element} [el=this.menuButton_.el()]
  15875. * Element to set the title on.
  15876. *
  15877. * @return {string}
  15878. * - The control text when getting
  15879. */
  15880. ;
  15881. _proto.controlText = function controlText(text, el) {
  15882. if (el === void 0) {
  15883. el = this.menuButton_.el();
  15884. }
  15885. return this.menuButton_.controlText(text, el);
  15886. }
  15887. /**
  15888. * Dispose of the `menu-button` and all child components.
  15889. */
  15890. ;
  15891. _proto.dispose = function dispose() {
  15892. this.handleMouseLeave();
  15893. _Component.prototype.dispose.call(this);
  15894. }
  15895. /**
  15896. * Handle a click on a `MenuButton`.
  15897. * See {@link ClickableComponent#handleClick} for instances where this is called.
  15898. *
  15899. * @param {EventTarget~Event} event
  15900. * The `keydown`, `tap`, or `click` event that caused this function to be
  15901. * called.
  15902. *
  15903. * @listens tap
  15904. * @listens click
  15905. */
  15906. ;
  15907. _proto.handleClick = function handleClick(event) {
  15908. if (this.buttonPressed_) {
  15909. this.unpressButton();
  15910. } else {
  15911. this.pressButton();
  15912. }
  15913. }
  15914. /**
  15915. * Handle `mouseleave` for `MenuButton`.
  15916. *
  15917. * @param {EventTarget~Event} event
  15918. * The `mouseleave` event that caused this function to be called.
  15919. *
  15920. * @listens mouseleave
  15921. */
  15922. ;
  15923. _proto.handleMouseLeave = function handleMouseLeave(event) {
  15924. this.removeClass('vjs-hover');
  15925. off(document, 'keyup', this.handleMenuKeyUp_);
  15926. }
  15927. /**
  15928. * Set the focus to the actual button, not to this element
  15929. */
  15930. ;
  15931. _proto.focus = function focus() {
  15932. this.menuButton_.focus();
  15933. }
  15934. /**
  15935. * Remove the focus from the actual button, not this element
  15936. */
  15937. ;
  15938. _proto.blur = function blur() {
  15939. this.menuButton_.blur();
  15940. }
  15941. /**
  15942. * Handle tab, escape, down arrow, and up arrow keys for `MenuButton`. See
  15943. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  15944. *
  15945. * @param {EventTarget~Event} event
  15946. * The `keydown` event that caused this function to be called.
  15947. *
  15948. * @listens keydown
  15949. */
  15950. ;
  15951. _proto.handleKeyDown = function handleKeyDown(event) {
  15952. // Escape or Tab unpress the 'button'
  15953. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  15954. if (this.buttonPressed_) {
  15955. this.unpressButton();
  15956. } // Don't preventDefault for Tab key - we still want to lose focus
  15957. if (!keycode.isEventKey(event, 'Tab')) {
  15958. event.preventDefault(); // Set focus back to the menu button's button
  15959. this.menuButton_.focus();
  15960. } // Up Arrow or Down Arrow also 'press' the button to open the menu
  15961. } else if (keycode.isEventKey(event, 'Up') || keycode.isEventKey(event, 'Down')) {
  15962. if (!this.buttonPressed_) {
  15963. event.preventDefault();
  15964. this.pressButton();
  15965. }
  15966. }
  15967. }
  15968. /**
  15969. * Handle a `keyup` event on a `MenuButton`. The listener for this is added in
  15970. * the constructor.
  15971. *
  15972. * @param {EventTarget~Event} event
  15973. * Key press event
  15974. *
  15975. * @listens keyup
  15976. */
  15977. ;
  15978. _proto.handleMenuKeyUp = function handleMenuKeyUp(event) {
  15979. // Escape hides popup menu
  15980. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  15981. this.removeClass('vjs-hover');
  15982. }
  15983. }
  15984. /**
  15985. * This method name now delegates to `handleSubmenuKeyDown`. This means
  15986. * anyone calling `handleSubmenuKeyPress` will not see their method calls
  15987. * stop working.
  15988. *
  15989. * @param {EventTarget~Event} event
  15990. * The event that caused this function to be called.
  15991. */
  15992. ;
  15993. _proto.handleSubmenuKeyPress = function handleSubmenuKeyPress(event) {
  15994. this.handleSubmenuKeyDown(event);
  15995. }
  15996. /**
  15997. * Handle a `keydown` event on a sub-menu. The listener for this is added in
  15998. * the constructor.
  15999. *
  16000. * @param {EventTarget~Event} event
  16001. * Key press event
  16002. *
  16003. * @listens keydown
  16004. */
  16005. ;
  16006. _proto.handleSubmenuKeyDown = function handleSubmenuKeyDown(event) {
  16007. // Escape or Tab unpress the 'button'
  16008. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  16009. if (this.buttonPressed_) {
  16010. this.unpressButton();
  16011. } // Don't preventDefault for Tab key - we still want to lose focus
  16012. if (!keycode.isEventKey(event, 'Tab')) {
  16013. event.preventDefault(); // Set focus back to the menu button's button
  16014. this.menuButton_.focus();
  16015. }
  16016. }
  16017. }
  16018. /**
  16019. * Put the current `MenuButton` into a pressed state.
  16020. */
  16021. ;
  16022. _proto.pressButton = function pressButton() {
  16023. if (this.enabled_) {
  16024. this.buttonPressed_ = true;
  16025. this.menu.show();
  16026. this.menu.lockShowing();
  16027. this.menuButton_.el_.setAttribute('aria-expanded', 'true'); // set the focus into the submenu, except on iOS where it is resulting in
  16028. // undesired scrolling behavior when the player is in an iframe
  16029. if (IS_IOS && isInFrame()) {
  16030. // Return early so that the menu isn't focused
  16031. return;
  16032. }
  16033. this.menu.focus();
  16034. }
  16035. }
  16036. /**
  16037. * Take the current `MenuButton` out of a pressed state.
  16038. */
  16039. ;
  16040. _proto.unpressButton = function unpressButton() {
  16041. if (this.enabled_) {
  16042. this.buttonPressed_ = false;
  16043. this.menu.unlockShowing();
  16044. this.menu.hide();
  16045. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  16046. }
  16047. }
  16048. /**
  16049. * Disable the `MenuButton`. Don't allow it to be clicked.
  16050. */
  16051. ;
  16052. _proto.disable = function disable() {
  16053. this.unpressButton();
  16054. this.enabled_ = false;
  16055. this.addClass('vjs-disabled');
  16056. this.menuButton_.disable();
  16057. }
  16058. /**
  16059. * Enable the `MenuButton`. Allow it to be clicked.
  16060. */
  16061. ;
  16062. _proto.enable = function enable() {
  16063. this.enabled_ = true;
  16064. this.removeClass('vjs-disabled');
  16065. this.menuButton_.enable();
  16066. };
  16067. return MenuButton;
  16068. }(Component);
  16069. Component.registerComponent('MenuButton', MenuButton);
  16070. /**
  16071. * The base class for buttons that toggle specific track types (e.g. subtitles).
  16072. *
  16073. * @extends MenuButton
  16074. */
  16075. var TrackButton = /*#__PURE__*/function (_MenuButton) {
  16076. inheritsLoose(TrackButton, _MenuButton);
  16077. /**
  16078. * Creates an instance of this class.
  16079. *
  16080. * @param {Player} player
  16081. * The `Player` that this class should be attached to.
  16082. *
  16083. * @param {Object} [options]
  16084. * The key/value store of player options.
  16085. */
  16086. function TrackButton(player, options) {
  16087. var _this;
  16088. var tracks = options.tracks;
  16089. _this = _MenuButton.call(this, player, options) || this;
  16090. if (_this.items.length <= 1) {
  16091. _this.hide();
  16092. }
  16093. if (!tracks) {
  16094. return assertThisInitialized(_this);
  16095. }
  16096. var updateHandler = bind(assertThisInitialized(_this), _this.update);
  16097. tracks.addEventListener('removetrack', updateHandler);
  16098. tracks.addEventListener('addtrack', updateHandler);
  16099. tracks.addEventListener('labelchange', updateHandler);
  16100. _this.player_.on('ready', updateHandler);
  16101. _this.player_.on('dispose', function () {
  16102. tracks.removeEventListener('removetrack', updateHandler);
  16103. tracks.removeEventListener('addtrack', updateHandler);
  16104. tracks.removeEventListener('labelchange', updateHandler);
  16105. });
  16106. return _this;
  16107. }
  16108. return TrackButton;
  16109. }(MenuButton);
  16110. Component.registerComponent('TrackButton', TrackButton);
  16111. /**
  16112. * @file menu-keys.js
  16113. */
  16114. /**
  16115. * All keys used for operation of a menu (`MenuButton`, `Menu`, and `MenuItem`)
  16116. * Note that 'Enter' and 'Space' are not included here (otherwise they would
  16117. * prevent the `MenuButton` and `MenuItem` from being keyboard-clickable)
  16118. * @typedef MenuKeys
  16119. * @array
  16120. */
  16121. var MenuKeys = ['Tab', 'Esc', 'Up', 'Down', 'Right', 'Left'];
  16122. /**
  16123. * The component for a menu item. `<li>`
  16124. *
  16125. * @extends ClickableComponent
  16126. */
  16127. var MenuItem = /*#__PURE__*/function (_ClickableComponent) {
  16128. inheritsLoose(MenuItem, _ClickableComponent);
  16129. /**
  16130. * Creates an instance of the this class.
  16131. *
  16132. * @param {Player} player
  16133. * The `Player` that this class should be attached to.
  16134. *
  16135. * @param {Object} [options={}]
  16136. * The key/value store of player options.
  16137. *
  16138. */
  16139. function MenuItem(player, options) {
  16140. var _this;
  16141. _this = _ClickableComponent.call(this, player, options) || this;
  16142. _this.selectable = options.selectable;
  16143. _this.isSelected_ = options.selected || false;
  16144. _this.multiSelectable = options.multiSelectable;
  16145. _this.selected(_this.isSelected_);
  16146. if (_this.selectable) {
  16147. if (_this.multiSelectable) {
  16148. _this.el_.setAttribute('role', 'menuitemcheckbox');
  16149. } else {
  16150. _this.el_.setAttribute('role', 'menuitemradio');
  16151. }
  16152. } else {
  16153. _this.el_.setAttribute('role', 'menuitem');
  16154. }
  16155. return _this;
  16156. }
  16157. /**
  16158. * Create the `MenuItem's DOM element
  16159. *
  16160. * @param {string} [type=li]
  16161. * Element's node type, not actually used, always set to `li`.
  16162. *
  16163. * @param {Object} [props={}]
  16164. * An object of properties that should be set on the element
  16165. *
  16166. * @param {Object} [attrs={}]
  16167. * An object of attributes that should be set on the element
  16168. *
  16169. * @return {Element}
  16170. * The element that gets created.
  16171. */
  16172. var _proto = MenuItem.prototype;
  16173. _proto.createEl = function createEl$1(type, props, attrs) {
  16174. // The control is textual, not just an icon
  16175. this.nonIconControl = true;
  16176. var el = _ClickableComponent.prototype.createEl.call(this, 'li', assign({
  16177. className: 'vjs-menu-item',
  16178. tabIndex: -1
  16179. }, props), attrs); // swap icon with menu item text.
  16180. el.replaceChild(createEl('span', {
  16181. className: 'vjs-menu-item-text',
  16182. textContent: this.localize(this.options_.label)
  16183. }), el.querySelector('.vjs-icon-placeholder'));
  16184. return el;
  16185. }
  16186. /**
  16187. * Ignore keys which are used by the menu, but pass any other ones up. See
  16188. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  16189. *
  16190. * @param {EventTarget~Event} event
  16191. * The `keydown` event that caused this function to be called.
  16192. *
  16193. * @listens keydown
  16194. */
  16195. ;
  16196. _proto.handleKeyDown = function handleKeyDown(event) {
  16197. if (!MenuKeys.some(function (key) {
  16198. return keycode.isEventKey(event, key);
  16199. })) {
  16200. // Pass keydown handling up for unused keys
  16201. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  16202. }
  16203. }
  16204. /**
  16205. * Any click on a `MenuItem` puts it into the selected state.
  16206. * See {@link ClickableComponent#handleClick} for instances where this is called.
  16207. *
  16208. * @param {EventTarget~Event} event
  16209. * The `keydown`, `tap`, or `click` event that caused this function to be
  16210. * called.
  16211. *
  16212. * @listens tap
  16213. * @listens click
  16214. */
  16215. ;
  16216. _proto.handleClick = function handleClick(event) {
  16217. this.selected(true);
  16218. }
  16219. /**
  16220. * Set the state for this menu item as selected or not.
  16221. *
  16222. * @param {boolean} selected
  16223. * if the menu item is selected or not
  16224. */
  16225. ;
  16226. _proto.selected = function selected(_selected) {
  16227. if (this.selectable) {
  16228. if (_selected) {
  16229. this.addClass('vjs-selected');
  16230. this.el_.setAttribute('aria-checked', 'true'); // aria-checked isn't fully supported by browsers/screen readers,
  16231. // so indicate selected state to screen reader in the control text.
  16232. this.controlText(', selected');
  16233. this.isSelected_ = true;
  16234. } else {
  16235. this.removeClass('vjs-selected');
  16236. this.el_.setAttribute('aria-checked', 'false'); // Indicate un-selected state to screen reader
  16237. this.controlText('');
  16238. this.isSelected_ = false;
  16239. }
  16240. }
  16241. };
  16242. return MenuItem;
  16243. }(ClickableComponent);
  16244. Component.registerComponent('MenuItem', MenuItem);
  16245. /**
  16246. * The specific menu item type for selecting a language within a text track kind
  16247. *
  16248. * @extends MenuItem
  16249. */
  16250. var TextTrackMenuItem = /*#__PURE__*/function (_MenuItem) {
  16251. inheritsLoose(TextTrackMenuItem, _MenuItem);
  16252. /**
  16253. * Creates an instance of this class.
  16254. *
  16255. * @param {Player} player
  16256. * The `Player` that this class should be attached to.
  16257. *
  16258. * @param {Object} [options]
  16259. * The key/value store of player options.
  16260. */
  16261. function TextTrackMenuItem(player, options) {
  16262. var _this;
  16263. var track = options.track;
  16264. var tracks = player.textTracks(); // Modify options for parent MenuItem class's init.
  16265. options.label = track.label || track.language || 'Unknown';
  16266. options.selected = track.mode === 'showing';
  16267. _this = _MenuItem.call(this, player, options) || this;
  16268. _this.track = track; // Determine the relevant kind(s) of tracks for this component and filter
  16269. // out empty kinds.
  16270. _this.kinds = (options.kinds || [options.kind || _this.track.kind]).filter(Boolean);
  16271. var changeHandler = function changeHandler() {
  16272. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  16273. args[_key] = arguments[_key];
  16274. }
  16275. _this.handleTracksChange.apply(assertThisInitialized(_this), args);
  16276. };
  16277. var selectedLanguageChangeHandler = function selectedLanguageChangeHandler() {
  16278. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  16279. args[_key2] = arguments[_key2];
  16280. }
  16281. _this.handleSelectedLanguageChange.apply(assertThisInitialized(_this), args);
  16282. };
  16283. player.on(['loadstart', 'texttrackchange'], changeHandler);
  16284. tracks.addEventListener('change', changeHandler);
  16285. tracks.addEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  16286. _this.on('dispose', function () {
  16287. player.off(['loadstart', 'texttrackchange'], changeHandler);
  16288. tracks.removeEventListener('change', changeHandler);
  16289. tracks.removeEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  16290. }); // iOS7 doesn't dispatch change events to TextTrackLists when an
  16291. // associated track's mode changes. Without something like
  16292. // Object.observe() (also not present on iOS7), it's not
  16293. // possible to detect changes to the mode attribute and polyfill
  16294. // the change event. As a poor substitute, we manually dispatch
  16295. // change events whenever the controls modify the mode.
  16296. if (tracks.onchange === undefined) {
  16297. var event;
  16298. _this.on(['tap', 'click'], function () {
  16299. if (typeof window.Event !== 'object') {
  16300. // Android 2.3 throws an Illegal Constructor error for window.Event
  16301. try {
  16302. event = new window.Event('change');
  16303. } catch (err) {// continue regardless of error
  16304. }
  16305. }
  16306. if (!event) {
  16307. event = document.createEvent('Event');
  16308. event.initEvent('change', true, true);
  16309. }
  16310. tracks.dispatchEvent(event);
  16311. });
  16312. } // set the default state based on current tracks
  16313. _this.handleTracksChange();
  16314. return _this;
  16315. }
  16316. /**
  16317. * This gets called when an `TextTrackMenuItem` is "clicked". See
  16318. * {@link ClickableComponent} for more detailed information on what a click can be.
  16319. *
  16320. * @param {EventTarget~Event} event
  16321. * The `keydown`, `tap`, or `click` event that caused this function to be
  16322. * called.
  16323. *
  16324. * @listens tap
  16325. * @listens click
  16326. */
  16327. var _proto = TextTrackMenuItem.prototype;
  16328. _proto.handleClick = function handleClick(event) {
  16329. var referenceTrack = this.track;
  16330. var tracks = this.player_.textTracks();
  16331. _MenuItem.prototype.handleClick.call(this, event);
  16332. if (!tracks) {
  16333. return;
  16334. }
  16335. for (var i = 0; i < tracks.length; i++) {
  16336. var track = tracks[i]; // If the track from the text tracks list is not of the right kind,
  16337. // skip it. We do not want to affect tracks of incompatible kind(s).
  16338. if (this.kinds.indexOf(track.kind) === -1) {
  16339. continue;
  16340. } // If this text track is the component's track and it is not showing,
  16341. // set it to showing.
  16342. if (track === referenceTrack) {
  16343. if (track.mode !== 'showing') {
  16344. track.mode = 'showing';
  16345. } // If this text track is not the component's track and it is not
  16346. // disabled, set it to disabled.
  16347. } else if (track.mode !== 'disabled') {
  16348. track.mode = 'disabled';
  16349. }
  16350. }
  16351. }
  16352. /**
  16353. * Handle text track list change
  16354. *
  16355. * @param {EventTarget~Event} event
  16356. * The `change` event that caused this function to be called.
  16357. *
  16358. * @listens TextTrackList#change
  16359. */
  16360. ;
  16361. _proto.handleTracksChange = function handleTracksChange(event) {
  16362. var shouldBeSelected = this.track.mode === 'showing'; // Prevent redundant selected() calls because they may cause
  16363. // screen readers to read the appended control text unnecessarily
  16364. if (shouldBeSelected !== this.isSelected_) {
  16365. this.selected(shouldBeSelected);
  16366. }
  16367. };
  16368. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  16369. if (this.track.mode === 'showing') {
  16370. var selectedLanguage = this.player_.cache_.selectedLanguage; // Don't replace the kind of track across the same language
  16371. if (selectedLanguage && selectedLanguage.enabled && selectedLanguage.language === this.track.language && selectedLanguage.kind !== this.track.kind) {
  16372. return;
  16373. }
  16374. this.player_.cache_.selectedLanguage = {
  16375. enabled: true,
  16376. language: this.track.language,
  16377. kind: this.track.kind
  16378. };
  16379. }
  16380. };
  16381. _proto.dispose = function dispose() {
  16382. // remove reference to track object on dispose
  16383. this.track = null;
  16384. _MenuItem.prototype.dispose.call(this);
  16385. };
  16386. return TextTrackMenuItem;
  16387. }(MenuItem);
  16388. Component.registerComponent('TextTrackMenuItem', TextTrackMenuItem);
  16389. /**
  16390. * A special menu item for turning of a specific type of text track
  16391. *
  16392. * @extends TextTrackMenuItem
  16393. */
  16394. var OffTextTrackMenuItem = /*#__PURE__*/function (_TextTrackMenuItem) {
  16395. inheritsLoose(OffTextTrackMenuItem, _TextTrackMenuItem);
  16396. /**
  16397. * Creates an instance of this class.
  16398. *
  16399. * @param {Player} player
  16400. * The `Player` that this class should be attached to.
  16401. *
  16402. * @param {Object} [options]
  16403. * The key/value store of player options.
  16404. */
  16405. function OffTextTrackMenuItem(player, options) {
  16406. // Create pseudo track info
  16407. // Requires options['kind']
  16408. options.track = {
  16409. player: player,
  16410. // it is no longer necessary to store `kind` or `kinds` on the track itself
  16411. // since they are now stored in the `kinds` property of all instances of
  16412. // TextTrackMenuItem, but this will remain for backwards compatibility
  16413. kind: options.kind,
  16414. kinds: options.kinds,
  16415. "default": false,
  16416. mode: 'disabled'
  16417. };
  16418. if (!options.kinds) {
  16419. options.kinds = [options.kind];
  16420. }
  16421. if (options.label) {
  16422. options.track.label = options.label;
  16423. } else {
  16424. options.track.label = options.kinds.join(' and ') + ' off';
  16425. } // MenuItem is selectable
  16426. options.selectable = true; // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  16427. options.multiSelectable = false;
  16428. return _TextTrackMenuItem.call(this, player, options) || this;
  16429. }
  16430. /**
  16431. * Handle text track change
  16432. *
  16433. * @param {EventTarget~Event} event
  16434. * The event that caused this function to run
  16435. */
  16436. var _proto = OffTextTrackMenuItem.prototype;
  16437. _proto.handleTracksChange = function handleTracksChange(event) {
  16438. var tracks = this.player().textTracks();
  16439. var shouldBeSelected = true;
  16440. for (var i = 0, l = tracks.length; i < l; i++) {
  16441. var track = tracks[i];
  16442. if (this.options_.kinds.indexOf(track.kind) > -1 && track.mode === 'showing') {
  16443. shouldBeSelected = false;
  16444. break;
  16445. }
  16446. } // Prevent redundant selected() calls because they may cause
  16447. // screen readers to read the appended control text unnecessarily
  16448. if (shouldBeSelected !== this.isSelected_) {
  16449. this.selected(shouldBeSelected);
  16450. }
  16451. };
  16452. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  16453. var tracks = this.player().textTracks();
  16454. var allHidden = true;
  16455. for (var i = 0, l = tracks.length; i < l; i++) {
  16456. var track = tracks[i];
  16457. if (['captions', 'descriptions', 'subtitles'].indexOf(track.kind) > -1 && track.mode === 'showing') {
  16458. allHidden = false;
  16459. break;
  16460. }
  16461. }
  16462. if (allHidden) {
  16463. this.player_.cache_.selectedLanguage = {
  16464. enabled: false
  16465. };
  16466. }
  16467. };
  16468. return OffTextTrackMenuItem;
  16469. }(TextTrackMenuItem);
  16470. Component.registerComponent('OffTextTrackMenuItem', OffTextTrackMenuItem);
  16471. /**
  16472. * The base class for buttons that toggle specific text track types (e.g. subtitles)
  16473. *
  16474. * @extends MenuButton
  16475. */
  16476. var TextTrackButton = /*#__PURE__*/function (_TrackButton) {
  16477. inheritsLoose(TextTrackButton, _TrackButton);
  16478. /**
  16479. * Creates an instance of this class.
  16480. *
  16481. * @param {Player} player
  16482. * The `Player` that this class should be attached to.
  16483. *
  16484. * @param {Object} [options={}]
  16485. * The key/value store of player options.
  16486. */
  16487. function TextTrackButton(player, options) {
  16488. if (options === void 0) {
  16489. options = {};
  16490. }
  16491. options.tracks = player.textTracks();
  16492. return _TrackButton.call(this, player, options) || this;
  16493. }
  16494. /**
  16495. * Create a menu item for each text track
  16496. *
  16497. * @param {TextTrackMenuItem[]} [items=[]]
  16498. * Existing array of items to use during creation
  16499. *
  16500. * @return {TextTrackMenuItem[]}
  16501. * Array of menu items that were created
  16502. */
  16503. var _proto = TextTrackButton.prototype;
  16504. _proto.createItems = function createItems(items, TrackMenuItem) {
  16505. if (items === void 0) {
  16506. items = [];
  16507. }
  16508. if (TrackMenuItem === void 0) {
  16509. TrackMenuItem = TextTrackMenuItem;
  16510. }
  16511. // Label is an override for the [track] off label
  16512. // USed to localise captions/subtitles
  16513. var label;
  16514. if (this.label_) {
  16515. label = this.label_ + " off";
  16516. } // Add an OFF menu item to turn all tracks off
  16517. items.push(new OffTextTrackMenuItem(this.player_, {
  16518. kinds: this.kinds_,
  16519. kind: this.kind_,
  16520. label: label
  16521. }));
  16522. this.hideThreshold_ += 1;
  16523. var tracks = this.player_.textTracks();
  16524. if (!Array.isArray(this.kinds_)) {
  16525. this.kinds_ = [this.kind_];
  16526. }
  16527. for (var i = 0; i < tracks.length; i++) {
  16528. var track = tracks[i]; // only add tracks that are of an appropriate kind and have a label
  16529. if (this.kinds_.indexOf(track.kind) > -1) {
  16530. var item = new TrackMenuItem(this.player_, {
  16531. track: track,
  16532. kinds: this.kinds_,
  16533. kind: this.kind_,
  16534. // MenuItem is selectable
  16535. selectable: true,
  16536. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  16537. multiSelectable: false
  16538. });
  16539. item.addClass("vjs-" + track.kind + "-menu-item");
  16540. items.push(item);
  16541. }
  16542. }
  16543. return items;
  16544. };
  16545. return TextTrackButton;
  16546. }(TrackButton);
  16547. Component.registerComponent('TextTrackButton', TextTrackButton);
  16548. /**
  16549. * The chapter track menu item
  16550. *
  16551. * @extends MenuItem
  16552. */
  16553. var ChaptersTrackMenuItem = /*#__PURE__*/function (_MenuItem) {
  16554. inheritsLoose(ChaptersTrackMenuItem, _MenuItem);
  16555. /**
  16556. * Creates an instance of this class.
  16557. *
  16558. * @param {Player} player
  16559. * The `Player` that this class should be attached to.
  16560. *
  16561. * @param {Object} [options]
  16562. * The key/value store of player options.
  16563. */
  16564. function ChaptersTrackMenuItem(player, options) {
  16565. var _this;
  16566. var track = options.track;
  16567. var cue = options.cue;
  16568. var currentTime = player.currentTime(); // Modify options for parent MenuItem class's init.
  16569. options.selectable = true;
  16570. options.multiSelectable = false;
  16571. options.label = cue.text;
  16572. options.selected = cue.startTime <= currentTime && currentTime < cue.endTime;
  16573. _this = _MenuItem.call(this, player, options) || this;
  16574. _this.track = track;
  16575. _this.cue = cue;
  16576. return _this;
  16577. }
  16578. /**
  16579. * This gets called when an `ChaptersTrackMenuItem` is "clicked". See
  16580. * {@link ClickableComponent} for more detailed information on what a click can be.
  16581. *
  16582. * @param {EventTarget~Event} [event]
  16583. * The `keydown`, `tap`, or `click` event that caused this function to be
  16584. * called.
  16585. *
  16586. * @listens tap
  16587. * @listens click
  16588. */
  16589. var _proto = ChaptersTrackMenuItem.prototype;
  16590. _proto.handleClick = function handleClick(event) {
  16591. _MenuItem.prototype.handleClick.call(this);
  16592. this.player_.currentTime(this.cue.startTime);
  16593. };
  16594. return ChaptersTrackMenuItem;
  16595. }(MenuItem);
  16596. Component.registerComponent('ChaptersTrackMenuItem', ChaptersTrackMenuItem);
  16597. /**
  16598. * The button component for toggling and selecting chapters
  16599. * Chapters act much differently than other text tracks
  16600. * Cues are navigation vs. other tracks of alternative languages
  16601. *
  16602. * @extends TextTrackButton
  16603. */
  16604. var ChaptersButton = /*#__PURE__*/function (_TextTrackButton) {
  16605. inheritsLoose(ChaptersButton, _TextTrackButton);
  16606. /**
  16607. * Creates an instance of this class.
  16608. *
  16609. * @param {Player} player
  16610. * The `Player` that this class should be attached to.
  16611. *
  16612. * @param {Object} [options]
  16613. * The key/value store of player options.
  16614. *
  16615. * @param {Component~ReadyCallback} [ready]
  16616. * The function to call when this function is ready.
  16617. */
  16618. function ChaptersButton(player, options, ready) {
  16619. var _this;
  16620. _this = _TextTrackButton.call(this, player, options, ready) || this;
  16621. _this.selectCurrentItem_ = function () {
  16622. _this.items.forEach(function (item) {
  16623. item.selected(_this.track_.activeCues[0] === item.cue);
  16624. });
  16625. };
  16626. return _this;
  16627. }
  16628. /**
  16629. * Builds the default DOM `className`.
  16630. *
  16631. * @return {string}
  16632. * The DOM `className` for this object.
  16633. */
  16634. var _proto = ChaptersButton.prototype;
  16635. _proto.buildCSSClass = function buildCSSClass() {
  16636. return "vjs-chapters-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16637. };
  16638. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16639. return "vjs-chapters-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16640. }
  16641. /**
  16642. * Update the menu based on the current state of its items.
  16643. *
  16644. * @param {EventTarget~Event} [event]
  16645. * An event that triggered this function to run.
  16646. *
  16647. * @listens TextTrackList#addtrack
  16648. * @listens TextTrackList#removetrack
  16649. * @listens TextTrackList#change
  16650. */
  16651. ;
  16652. _proto.update = function update(event) {
  16653. if (event && event.track && event.track.kind !== 'chapters') {
  16654. return;
  16655. }
  16656. var track = this.findChaptersTrack();
  16657. if (track !== this.track_) {
  16658. this.setTrack(track);
  16659. _TextTrackButton.prototype.update.call(this);
  16660. } else if (!this.items || track && track.cues && track.cues.length !== this.items.length) {
  16661. // Update the menu initially or if the number of cues has changed since set
  16662. _TextTrackButton.prototype.update.call(this);
  16663. }
  16664. }
  16665. /**
  16666. * Set the currently selected track for the chapters button.
  16667. *
  16668. * @param {TextTrack} track
  16669. * The new track to select. Nothing will change if this is the currently selected
  16670. * track.
  16671. */
  16672. ;
  16673. _proto.setTrack = function setTrack(track) {
  16674. if (this.track_ === track) {
  16675. return;
  16676. }
  16677. if (!this.updateHandler_) {
  16678. this.updateHandler_ = this.update.bind(this);
  16679. } // here this.track_ refers to the old track instance
  16680. if (this.track_) {
  16681. var remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  16682. if (remoteTextTrackEl) {
  16683. remoteTextTrackEl.removeEventListener('load', this.updateHandler_);
  16684. }
  16685. this.track_.removeEventListener('cuechange', this.selectCurrentItem_);
  16686. this.track_ = null;
  16687. }
  16688. this.track_ = track; // here this.track_ refers to the new track instance
  16689. if (this.track_) {
  16690. this.track_.mode = 'hidden';
  16691. var _remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  16692. if (_remoteTextTrackEl) {
  16693. _remoteTextTrackEl.addEventListener('load', this.updateHandler_);
  16694. }
  16695. this.track_.addEventListener('cuechange', this.selectCurrentItem_);
  16696. }
  16697. }
  16698. /**
  16699. * Find the track object that is currently in use by this ChaptersButton
  16700. *
  16701. * @return {TextTrack|undefined}
  16702. * The current track or undefined if none was found.
  16703. */
  16704. ;
  16705. _proto.findChaptersTrack = function findChaptersTrack() {
  16706. var tracks = this.player_.textTracks() || [];
  16707. for (var i = tracks.length - 1; i >= 0; i--) {
  16708. // We will always choose the last track as our chaptersTrack
  16709. var track = tracks[i];
  16710. if (track.kind === this.kind_) {
  16711. return track;
  16712. }
  16713. }
  16714. }
  16715. /**
  16716. * Get the caption for the ChaptersButton based on the track label. This will also
  16717. * use the current tracks localized kind as a fallback if a label does not exist.
  16718. *
  16719. * @return {string}
  16720. * The tracks current label or the localized track kind.
  16721. */
  16722. ;
  16723. _proto.getMenuCaption = function getMenuCaption() {
  16724. if (this.track_ && this.track_.label) {
  16725. return this.track_.label;
  16726. }
  16727. return this.localize(toTitleCase(this.kind_));
  16728. }
  16729. /**
  16730. * Create menu from chapter track
  16731. *
  16732. * @return {Menu}
  16733. * New menu for the chapter buttons
  16734. */
  16735. ;
  16736. _proto.createMenu = function createMenu() {
  16737. this.options_.title = this.getMenuCaption();
  16738. return _TextTrackButton.prototype.createMenu.call(this);
  16739. }
  16740. /**
  16741. * Create a menu item for each text track
  16742. *
  16743. * @return {TextTrackMenuItem[]}
  16744. * Array of menu items
  16745. */
  16746. ;
  16747. _proto.createItems = function createItems() {
  16748. var items = [];
  16749. if (!this.track_) {
  16750. return items;
  16751. }
  16752. var cues = this.track_.cues;
  16753. if (!cues) {
  16754. return items;
  16755. }
  16756. for (var i = 0, l = cues.length; i < l; i++) {
  16757. var cue = cues[i];
  16758. var mi = new ChaptersTrackMenuItem(this.player_, {
  16759. track: this.track_,
  16760. cue: cue
  16761. });
  16762. items.push(mi);
  16763. }
  16764. return items;
  16765. };
  16766. return ChaptersButton;
  16767. }(TextTrackButton);
  16768. /**
  16769. * `kind` of TextTrack to look for to associate it with this menu.
  16770. *
  16771. * @type {string}
  16772. * @private
  16773. */
  16774. ChaptersButton.prototype.kind_ = 'chapters';
  16775. /**
  16776. * The text that should display over the `ChaptersButton`s controls. Added for localization.
  16777. *
  16778. * @type {string}
  16779. * @private
  16780. */
  16781. ChaptersButton.prototype.controlText_ = 'Chapters';
  16782. Component.registerComponent('ChaptersButton', ChaptersButton);
  16783. /**
  16784. * The button component for toggling and selecting descriptions
  16785. *
  16786. * @extends TextTrackButton
  16787. */
  16788. var DescriptionsButton = /*#__PURE__*/function (_TextTrackButton) {
  16789. inheritsLoose(DescriptionsButton, _TextTrackButton);
  16790. /**
  16791. * Creates an instance of this class.
  16792. *
  16793. * @param {Player} player
  16794. * The `Player` that this class should be attached to.
  16795. *
  16796. * @param {Object} [options]
  16797. * The key/value store of player options.
  16798. *
  16799. * @param {Component~ReadyCallback} [ready]
  16800. * The function to call when this component is ready.
  16801. */
  16802. function DescriptionsButton(player, options, ready) {
  16803. var _this;
  16804. _this = _TextTrackButton.call(this, player, options, ready) || this;
  16805. var tracks = player.textTracks();
  16806. var changeHandler = bind(assertThisInitialized(_this), _this.handleTracksChange);
  16807. tracks.addEventListener('change', changeHandler);
  16808. _this.on('dispose', function () {
  16809. tracks.removeEventListener('change', changeHandler);
  16810. });
  16811. return _this;
  16812. }
  16813. /**
  16814. * Handle text track change
  16815. *
  16816. * @param {EventTarget~Event} event
  16817. * The event that caused this function to run
  16818. *
  16819. * @listens TextTrackList#change
  16820. */
  16821. var _proto = DescriptionsButton.prototype;
  16822. _proto.handleTracksChange = function handleTracksChange(event) {
  16823. var tracks = this.player().textTracks();
  16824. var disabled = false; // Check whether a track of a different kind is showing
  16825. for (var i = 0, l = tracks.length; i < l; i++) {
  16826. var track = tracks[i];
  16827. if (track.kind !== this.kind_ && track.mode === 'showing') {
  16828. disabled = true;
  16829. break;
  16830. }
  16831. } // If another track is showing, disable this menu button
  16832. if (disabled) {
  16833. this.disable();
  16834. } else {
  16835. this.enable();
  16836. }
  16837. }
  16838. /**
  16839. * Builds the default DOM `className`.
  16840. *
  16841. * @return {string}
  16842. * The DOM `className` for this object.
  16843. */
  16844. ;
  16845. _proto.buildCSSClass = function buildCSSClass() {
  16846. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16847. };
  16848. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16849. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16850. };
  16851. return DescriptionsButton;
  16852. }(TextTrackButton);
  16853. /**
  16854. * `kind` of TextTrack to look for to associate it with this menu.
  16855. *
  16856. * @type {string}
  16857. * @private
  16858. */
  16859. DescriptionsButton.prototype.kind_ = 'descriptions';
  16860. /**
  16861. * The text that should display over the `DescriptionsButton`s controls. Added for localization.
  16862. *
  16863. * @type {string}
  16864. * @private
  16865. */
  16866. DescriptionsButton.prototype.controlText_ = 'Descriptions';
  16867. Component.registerComponent('DescriptionsButton', DescriptionsButton);
  16868. /**
  16869. * The button component for toggling and selecting subtitles
  16870. *
  16871. * @extends TextTrackButton
  16872. */
  16873. var SubtitlesButton = /*#__PURE__*/function (_TextTrackButton) {
  16874. inheritsLoose(SubtitlesButton, _TextTrackButton);
  16875. /**
  16876. * Creates an instance of this class.
  16877. *
  16878. * @param {Player} player
  16879. * The `Player` that this class should be attached to.
  16880. *
  16881. * @param {Object} [options]
  16882. * The key/value store of player options.
  16883. *
  16884. * @param {Component~ReadyCallback} [ready]
  16885. * The function to call when this component is ready.
  16886. */
  16887. function SubtitlesButton(player, options, ready) {
  16888. return _TextTrackButton.call(this, player, options, ready) || this;
  16889. }
  16890. /**
  16891. * Builds the default DOM `className`.
  16892. *
  16893. * @return {string}
  16894. * The DOM `className` for this object.
  16895. */
  16896. var _proto = SubtitlesButton.prototype;
  16897. _proto.buildCSSClass = function buildCSSClass() {
  16898. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16899. };
  16900. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16901. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16902. };
  16903. return SubtitlesButton;
  16904. }(TextTrackButton);
  16905. /**
  16906. * `kind` of TextTrack to look for to associate it with this menu.
  16907. *
  16908. * @type {string}
  16909. * @private
  16910. */
  16911. SubtitlesButton.prototype.kind_ = 'subtitles';
  16912. /**
  16913. * The text that should display over the `SubtitlesButton`s controls. Added for localization.
  16914. *
  16915. * @type {string}
  16916. * @private
  16917. */
  16918. SubtitlesButton.prototype.controlText_ = 'Subtitles';
  16919. Component.registerComponent('SubtitlesButton', SubtitlesButton);
  16920. /**
  16921. * The menu item for caption track settings menu
  16922. *
  16923. * @extends TextTrackMenuItem
  16924. */
  16925. var CaptionSettingsMenuItem = /*#__PURE__*/function (_TextTrackMenuItem) {
  16926. inheritsLoose(CaptionSettingsMenuItem, _TextTrackMenuItem);
  16927. /**
  16928. * Creates an instance of this class.
  16929. *
  16930. * @param {Player} player
  16931. * The `Player` that this class should be attached to.
  16932. *
  16933. * @param {Object} [options]
  16934. * The key/value store of player options.
  16935. */
  16936. function CaptionSettingsMenuItem(player, options) {
  16937. var _this;
  16938. options.track = {
  16939. player: player,
  16940. kind: options.kind,
  16941. label: options.kind + ' settings',
  16942. selectable: false,
  16943. "default": false,
  16944. mode: 'disabled'
  16945. }; // CaptionSettingsMenuItem has no concept of 'selected'
  16946. options.selectable = false;
  16947. options.name = 'CaptionSettingsMenuItem';
  16948. _this = _TextTrackMenuItem.call(this, player, options) || this;
  16949. _this.addClass('vjs-texttrack-settings');
  16950. _this.controlText(', opens ' + options.kind + ' settings dialog');
  16951. return _this;
  16952. }
  16953. /**
  16954. * This gets called when an `CaptionSettingsMenuItem` is "clicked". See
  16955. * {@link ClickableComponent} for more detailed information on what a click can be.
  16956. *
  16957. * @param {EventTarget~Event} [event]
  16958. * The `keydown`, `tap`, or `click` event that caused this function to be
  16959. * called.
  16960. *
  16961. * @listens tap
  16962. * @listens click
  16963. */
  16964. var _proto = CaptionSettingsMenuItem.prototype;
  16965. _proto.handleClick = function handleClick(event) {
  16966. this.player().getChild('textTrackSettings').open();
  16967. };
  16968. return CaptionSettingsMenuItem;
  16969. }(TextTrackMenuItem);
  16970. Component.registerComponent('CaptionSettingsMenuItem', CaptionSettingsMenuItem);
  16971. /**
  16972. * The button component for toggling and selecting captions
  16973. *
  16974. * @extends TextTrackButton
  16975. */
  16976. var CaptionsButton = /*#__PURE__*/function (_TextTrackButton) {
  16977. inheritsLoose(CaptionsButton, _TextTrackButton);
  16978. /**
  16979. * Creates an instance of this class.
  16980. *
  16981. * @param {Player} player
  16982. * The `Player` that this class should be attached to.
  16983. *
  16984. * @param {Object} [options]
  16985. * The key/value store of player options.
  16986. *
  16987. * @param {Component~ReadyCallback} [ready]
  16988. * The function to call when this component is ready.
  16989. */
  16990. function CaptionsButton(player, options, ready) {
  16991. return _TextTrackButton.call(this, player, options, ready) || this;
  16992. }
  16993. /**
  16994. * Builds the default DOM `className`.
  16995. *
  16996. * @return {string}
  16997. * The DOM `className` for this object.
  16998. */
  16999. var _proto = CaptionsButton.prototype;
  17000. _proto.buildCSSClass = function buildCSSClass() {
  17001. return "vjs-captions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  17002. };
  17003. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  17004. return "vjs-captions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  17005. }
  17006. /**
  17007. * Create caption menu items
  17008. *
  17009. * @return {CaptionSettingsMenuItem[]}
  17010. * The array of current menu items.
  17011. */
  17012. ;
  17013. _proto.createItems = function createItems() {
  17014. var items = [];
  17015. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  17016. items.push(new CaptionSettingsMenuItem(this.player_, {
  17017. kind: this.kind_
  17018. }));
  17019. this.hideThreshold_ += 1;
  17020. }
  17021. return _TextTrackButton.prototype.createItems.call(this, items);
  17022. };
  17023. return CaptionsButton;
  17024. }(TextTrackButton);
  17025. /**
  17026. * `kind` of TextTrack to look for to associate it with this menu.
  17027. *
  17028. * @type {string}
  17029. * @private
  17030. */
  17031. CaptionsButton.prototype.kind_ = 'captions';
  17032. /**
  17033. * The text that should display over the `CaptionsButton`s controls. Added for localization.
  17034. *
  17035. * @type {string}
  17036. * @private
  17037. */
  17038. CaptionsButton.prototype.controlText_ = 'Captions';
  17039. Component.registerComponent('CaptionsButton', CaptionsButton);
  17040. /**
  17041. * SubsCapsMenuItem has an [cc] icon to distinguish captions from subtitles
  17042. * in the SubsCapsMenu.
  17043. *
  17044. * @extends TextTrackMenuItem
  17045. */
  17046. var SubsCapsMenuItem = /*#__PURE__*/function (_TextTrackMenuItem) {
  17047. inheritsLoose(SubsCapsMenuItem, _TextTrackMenuItem);
  17048. function SubsCapsMenuItem() {
  17049. return _TextTrackMenuItem.apply(this, arguments) || this;
  17050. }
  17051. var _proto = SubsCapsMenuItem.prototype;
  17052. _proto.createEl = function createEl$1(type, props, attrs) {
  17053. var el = _TextTrackMenuItem.prototype.createEl.call(this, type, props, attrs);
  17054. var parentSpan = el.querySelector('.vjs-menu-item-text');
  17055. if (this.options_.track.kind === 'captions') {
  17056. parentSpan.appendChild(createEl('span', {
  17057. className: 'vjs-icon-placeholder'
  17058. }, {
  17059. 'aria-hidden': true
  17060. }));
  17061. parentSpan.appendChild(createEl('span', {
  17062. className: 'vjs-control-text',
  17063. // space added as the text will visually flow with the
  17064. // label
  17065. textContent: " " + this.localize('Captions')
  17066. }));
  17067. }
  17068. return el;
  17069. };
  17070. return SubsCapsMenuItem;
  17071. }(TextTrackMenuItem);
  17072. Component.registerComponent('SubsCapsMenuItem', SubsCapsMenuItem);
  17073. /**
  17074. * The button component for toggling and selecting captions and/or subtitles
  17075. *
  17076. * @extends TextTrackButton
  17077. */
  17078. var SubsCapsButton = /*#__PURE__*/function (_TextTrackButton) {
  17079. inheritsLoose(SubsCapsButton, _TextTrackButton);
  17080. function SubsCapsButton(player, options) {
  17081. var _this;
  17082. if (options === void 0) {
  17083. options = {};
  17084. }
  17085. _this = _TextTrackButton.call(this, player, options) || this; // Although North America uses "captions" in most cases for
  17086. // "captions and subtitles" other locales use "subtitles"
  17087. _this.label_ = 'subtitles';
  17088. if (['en', 'en-us', 'en-ca', 'fr-ca'].indexOf(_this.player_.language_) > -1) {
  17089. _this.label_ = 'captions';
  17090. }
  17091. _this.menuButton_.controlText(toTitleCase(_this.label_));
  17092. return _this;
  17093. }
  17094. /**
  17095. * Builds the default DOM `className`.
  17096. *
  17097. * @return {string}
  17098. * The DOM `className` for this object.
  17099. */
  17100. var _proto = SubsCapsButton.prototype;
  17101. _proto.buildCSSClass = function buildCSSClass() {
  17102. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  17103. };
  17104. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  17105. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  17106. }
  17107. /**
  17108. * Create caption/subtitles menu items
  17109. *
  17110. * @return {CaptionSettingsMenuItem[]}
  17111. * The array of current menu items.
  17112. */
  17113. ;
  17114. _proto.createItems = function createItems() {
  17115. var items = [];
  17116. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  17117. items.push(new CaptionSettingsMenuItem(this.player_, {
  17118. kind: this.label_
  17119. }));
  17120. this.hideThreshold_ += 1;
  17121. }
  17122. items = _TextTrackButton.prototype.createItems.call(this, items, SubsCapsMenuItem);
  17123. return items;
  17124. };
  17125. return SubsCapsButton;
  17126. }(TextTrackButton);
  17127. /**
  17128. * `kind`s of TextTrack to look for to associate it with this menu.
  17129. *
  17130. * @type {array}
  17131. * @private
  17132. */
  17133. SubsCapsButton.prototype.kinds_ = ['captions', 'subtitles'];
  17134. /**
  17135. * The text that should display over the `SubsCapsButton`s controls.
  17136. *
  17137. *
  17138. * @type {string}
  17139. * @private
  17140. */
  17141. SubsCapsButton.prototype.controlText_ = 'Subtitles';
  17142. Component.registerComponent('SubsCapsButton', SubsCapsButton);
  17143. /**
  17144. * An {@link AudioTrack} {@link MenuItem}
  17145. *
  17146. * @extends MenuItem
  17147. */
  17148. var AudioTrackMenuItem = /*#__PURE__*/function (_MenuItem) {
  17149. inheritsLoose(AudioTrackMenuItem, _MenuItem);
  17150. /**
  17151. * Creates an instance of this class.
  17152. *
  17153. * @param {Player} player
  17154. * The `Player` that this class should be attached to.
  17155. *
  17156. * @param {Object} [options]
  17157. * The key/value store of player options.
  17158. */
  17159. function AudioTrackMenuItem(player, options) {
  17160. var _this;
  17161. var track = options.track;
  17162. var tracks = player.audioTracks(); // Modify options for parent MenuItem class's init.
  17163. options.label = track.label || track.language || 'Unknown';
  17164. options.selected = track.enabled;
  17165. _this = _MenuItem.call(this, player, options) || this;
  17166. _this.track = track;
  17167. _this.addClass("vjs-" + track.kind + "-menu-item");
  17168. var changeHandler = function changeHandler() {
  17169. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  17170. args[_key] = arguments[_key];
  17171. }
  17172. _this.handleTracksChange.apply(assertThisInitialized(_this), args);
  17173. };
  17174. tracks.addEventListener('change', changeHandler);
  17175. _this.on('dispose', function () {
  17176. tracks.removeEventListener('change', changeHandler);
  17177. });
  17178. return _this;
  17179. }
  17180. var _proto = AudioTrackMenuItem.prototype;
  17181. _proto.createEl = function createEl$1(type, props, attrs) {
  17182. var el = _MenuItem.prototype.createEl.call(this, type, props, attrs);
  17183. var parentSpan = el.querySelector('.vjs-menu-item-text');
  17184. if (this.options_.track.kind === 'main-desc') {
  17185. parentSpan.appendChild(createEl('span', {
  17186. className: 'vjs-icon-placeholder'
  17187. }, {
  17188. 'aria-hidden': true
  17189. }));
  17190. parentSpan.appendChild(createEl('span', {
  17191. className: 'vjs-control-text',
  17192. textContent: ' ' + this.localize('Descriptions')
  17193. }));
  17194. }
  17195. return el;
  17196. }
  17197. /**
  17198. * This gets called when an `AudioTrackMenuItem is "clicked". See {@link ClickableComponent}
  17199. * for more detailed information on what a click can be.
  17200. *
  17201. * @param {EventTarget~Event} [event]
  17202. * The `keydown`, `tap`, or `click` event that caused this function to be
  17203. * called.
  17204. *
  17205. * @listens tap
  17206. * @listens click
  17207. */
  17208. ;
  17209. _proto.handleClick = function handleClick(event) {
  17210. _MenuItem.prototype.handleClick.call(this, event); // the audio track list will automatically toggle other tracks
  17211. // off for us.
  17212. this.track.enabled = true; // when native audio tracks are used, we want to make sure that other tracks are turned off
  17213. if (this.player_.tech_.featuresNativeAudioTracks) {
  17214. var tracks = this.player_.audioTracks();
  17215. for (var i = 0; i < tracks.length; i++) {
  17216. var track = tracks[i]; // skip the current track since we enabled it above
  17217. if (track === this.track) {
  17218. continue;
  17219. }
  17220. track.enabled = track === this.track;
  17221. }
  17222. }
  17223. }
  17224. /**
  17225. * Handle any {@link AudioTrack} change.
  17226. *
  17227. * @param {EventTarget~Event} [event]
  17228. * The {@link AudioTrackList#change} event that caused this to run.
  17229. *
  17230. * @listens AudioTrackList#change
  17231. */
  17232. ;
  17233. _proto.handleTracksChange = function handleTracksChange(event) {
  17234. this.selected(this.track.enabled);
  17235. };
  17236. return AudioTrackMenuItem;
  17237. }(MenuItem);
  17238. Component.registerComponent('AudioTrackMenuItem', AudioTrackMenuItem);
  17239. /**
  17240. * The base class for buttons that toggle specific {@link AudioTrack} types.
  17241. *
  17242. * @extends TrackButton
  17243. */
  17244. var AudioTrackButton = /*#__PURE__*/function (_TrackButton) {
  17245. inheritsLoose(AudioTrackButton, _TrackButton);
  17246. /**
  17247. * Creates an instance of this class.
  17248. *
  17249. * @param {Player} player
  17250. * The `Player` that this class should be attached to.
  17251. *
  17252. * @param {Object} [options={}]
  17253. * The key/value store of player options.
  17254. */
  17255. function AudioTrackButton(player, options) {
  17256. if (options === void 0) {
  17257. options = {};
  17258. }
  17259. options.tracks = player.audioTracks();
  17260. return _TrackButton.call(this, player, options) || this;
  17261. }
  17262. /**
  17263. * Builds the default DOM `className`.
  17264. *
  17265. * @return {string}
  17266. * The DOM `className` for this object.
  17267. */
  17268. var _proto = AudioTrackButton.prototype;
  17269. _proto.buildCSSClass = function buildCSSClass() {
  17270. return "vjs-audio-button " + _TrackButton.prototype.buildCSSClass.call(this);
  17271. };
  17272. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  17273. return "vjs-audio-button " + _TrackButton.prototype.buildWrapperCSSClass.call(this);
  17274. }
  17275. /**
  17276. * Create a menu item for each audio track
  17277. *
  17278. * @param {AudioTrackMenuItem[]} [items=[]]
  17279. * An array of existing menu items to use.
  17280. *
  17281. * @return {AudioTrackMenuItem[]}
  17282. * An array of menu items
  17283. */
  17284. ;
  17285. _proto.createItems = function createItems(items) {
  17286. if (items === void 0) {
  17287. items = [];
  17288. }
  17289. // if there's only one audio track, there no point in showing it
  17290. this.hideThreshold_ = 1;
  17291. var tracks = this.player_.audioTracks();
  17292. for (var i = 0; i < tracks.length; i++) {
  17293. var track = tracks[i];
  17294. items.push(new AudioTrackMenuItem(this.player_, {
  17295. track: track,
  17296. // MenuItem is selectable
  17297. selectable: true,
  17298. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  17299. multiSelectable: false
  17300. }));
  17301. }
  17302. return items;
  17303. };
  17304. return AudioTrackButton;
  17305. }(TrackButton);
  17306. /**
  17307. * The text that should display over the `AudioTrackButton`s controls. Added for localization.
  17308. *
  17309. * @type {string}
  17310. * @private
  17311. */
  17312. AudioTrackButton.prototype.controlText_ = 'Audio Track';
  17313. Component.registerComponent('AudioTrackButton', AudioTrackButton);
  17314. /**
  17315. * The specific menu item type for selecting a playback rate.
  17316. *
  17317. * @extends MenuItem
  17318. */
  17319. var PlaybackRateMenuItem = /*#__PURE__*/function (_MenuItem) {
  17320. inheritsLoose(PlaybackRateMenuItem, _MenuItem);
  17321. /**
  17322. * Creates an instance of this class.
  17323. *
  17324. * @param {Player} player
  17325. * The `Player` that this class should be attached to.
  17326. *
  17327. * @param {Object} [options]
  17328. * The key/value store of player options.
  17329. */
  17330. function PlaybackRateMenuItem(player, options) {
  17331. var _this;
  17332. var label = options.rate;
  17333. var rate = parseFloat(label, 10); // Modify options for parent MenuItem class's init.
  17334. options.label = label;
  17335. options.selected = rate === player.playbackRate();
  17336. options.selectable = true;
  17337. options.multiSelectable = false;
  17338. _this = _MenuItem.call(this, player, options) || this;
  17339. _this.label = label;
  17340. _this.rate = rate;
  17341. _this.on(player, 'ratechange', function (e) {
  17342. return _this.update(e);
  17343. });
  17344. return _this;
  17345. }
  17346. /**
  17347. * This gets called when an `PlaybackRateMenuItem` is "clicked". See
  17348. * {@link ClickableComponent} for more detailed information on what a click can be.
  17349. *
  17350. * @param {EventTarget~Event} [event]
  17351. * The `keydown`, `tap`, or `click` event that caused this function to be
  17352. * called.
  17353. *
  17354. * @listens tap
  17355. * @listens click
  17356. */
  17357. var _proto = PlaybackRateMenuItem.prototype;
  17358. _proto.handleClick = function handleClick(event) {
  17359. _MenuItem.prototype.handleClick.call(this);
  17360. this.player().playbackRate(this.rate);
  17361. }
  17362. /**
  17363. * Update the PlaybackRateMenuItem when the playbackrate changes.
  17364. *
  17365. * @param {EventTarget~Event} [event]
  17366. * The `ratechange` event that caused this function to run.
  17367. *
  17368. * @listens Player#ratechange
  17369. */
  17370. ;
  17371. _proto.update = function update(event) {
  17372. this.selected(this.player().playbackRate() === this.rate);
  17373. };
  17374. return PlaybackRateMenuItem;
  17375. }(MenuItem);
  17376. /**
  17377. * The text that should display over the `PlaybackRateMenuItem`s controls. Added for localization.
  17378. *
  17379. * @type {string}
  17380. * @private
  17381. */
  17382. PlaybackRateMenuItem.prototype.contentElType = 'button';
  17383. Component.registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem);
  17384. /**
  17385. * The component for controlling the playback rate.
  17386. *
  17387. * @extends MenuButton
  17388. */
  17389. var PlaybackRateMenuButton = /*#__PURE__*/function (_MenuButton) {
  17390. inheritsLoose(PlaybackRateMenuButton, _MenuButton);
  17391. /**
  17392. * Creates an instance of this class.
  17393. *
  17394. * @param {Player} player
  17395. * The `Player` that this class should be attached to.
  17396. *
  17397. * @param {Object} [options]
  17398. * The key/value store of player options.
  17399. */
  17400. function PlaybackRateMenuButton(player, options) {
  17401. var _this;
  17402. _this = _MenuButton.call(this, player, options) || this;
  17403. _this.menuButton_.el_.setAttribute('aria-describedby', _this.labelElId_);
  17404. _this.updateVisibility();
  17405. _this.updateLabel();
  17406. _this.on(player, 'loadstart', function (e) {
  17407. return _this.updateVisibility(e);
  17408. });
  17409. _this.on(player, 'ratechange', function (e) {
  17410. return _this.updateLabel(e);
  17411. });
  17412. _this.on(player, 'playbackrateschange', function (e) {
  17413. return _this.handlePlaybackRateschange(e);
  17414. });
  17415. return _this;
  17416. }
  17417. /**
  17418. * Create the `Component`'s DOM element
  17419. *
  17420. * @return {Element}
  17421. * The element that was created.
  17422. */
  17423. var _proto = PlaybackRateMenuButton.prototype;
  17424. _proto.createEl = function createEl$1() {
  17425. var el = _MenuButton.prototype.createEl.call(this);
  17426. this.labelElId_ = 'vjs-playback-rate-value-label-' + this.id_;
  17427. this.labelEl_ = createEl('div', {
  17428. className: 'vjs-playback-rate-value',
  17429. id: this.labelElId_,
  17430. textContent: '1x'
  17431. });
  17432. el.appendChild(this.labelEl_);
  17433. return el;
  17434. };
  17435. _proto.dispose = function dispose() {
  17436. this.labelEl_ = null;
  17437. _MenuButton.prototype.dispose.call(this);
  17438. }
  17439. /**
  17440. * Builds the default DOM `className`.
  17441. *
  17442. * @return {string}
  17443. * The DOM `className` for this object.
  17444. */
  17445. ;
  17446. _proto.buildCSSClass = function buildCSSClass() {
  17447. return "vjs-playback-rate " + _MenuButton.prototype.buildCSSClass.call(this);
  17448. };
  17449. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  17450. return "vjs-playback-rate " + _MenuButton.prototype.buildWrapperCSSClass.call(this);
  17451. }
  17452. /**
  17453. * Create the list of menu items. Specific to each subclass.
  17454. *
  17455. */
  17456. ;
  17457. _proto.createItems = function createItems() {
  17458. var rates = this.playbackRates();
  17459. var items = [];
  17460. for (var i = rates.length - 1; i >= 0; i--) {
  17461. items.push(new PlaybackRateMenuItem(this.player(), {
  17462. rate: rates[i] + 'x'
  17463. }));
  17464. }
  17465. return items;
  17466. }
  17467. /**
  17468. * Updates ARIA accessibility attributes
  17469. */
  17470. ;
  17471. _proto.updateARIAAttributes = function updateARIAAttributes() {
  17472. // Current playback rate
  17473. this.el().setAttribute('aria-valuenow', this.player().playbackRate());
  17474. }
  17475. /**
  17476. * This gets called when an `PlaybackRateMenuButton` is "clicked". See
  17477. * {@link ClickableComponent} for more detailed information on what a click can be.
  17478. *
  17479. * @param {EventTarget~Event} [event]
  17480. * The `keydown`, `tap`, or `click` event that caused this function to be
  17481. * called.
  17482. *
  17483. * @listens tap
  17484. * @listens click
  17485. */
  17486. ;
  17487. _proto.handleClick = function handleClick(event) {
  17488. // select next rate option
  17489. var currentRate = this.player().playbackRate();
  17490. var rates = this.playbackRates();
  17491. var currentIndex = rates.indexOf(currentRate); // this get the next rate and it will select first one if the last one currently selected
  17492. var newIndex = (currentIndex + 1) % rates.length;
  17493. this.player().playbackRate(rates[newIndex]);
  17494. }
  17495. /**
  17496. * On playbackrateschange, update the menu to account for the new items.
  17497. *
  17498. * @listens Player#playbackrateschange
  17499. */
  17500. ;
  17501. _proto.handlePlaybackRateschange = function handlePlaybackRateschange(event) {
  17502. this.update();
  17503. }
  17504. /**
  17505. * Get possible playback rates
  17506. *
  17507. * @return {Array}
  17508. * All possible playback rates
  17509. */
  17510. ;
  17511. _proto.playbackRates = function playbackRates() {
  17512. var player = this.player();
  17513. return player.playbackRates && player.playbackRates() || [];
  17514. }
  17515. /**
  17516. * Get whether playback rates is supported by the tech
  17517. * and an array of playback rates exists
  17518. *
  17519. * @return {boolean}
  17520. * Whether changing playback rate is supported
  17521. */
  17522. ;
  17523. _proto.playbackRateSupported = function playbackRateSupported() {
  17524. return this.player().tech_ && this.player().tech_.featuresPlaybackRate && this.playbackRates() && this.playbackRates().length > 0;
  17525. }
  17526. /**
  17527. * Hide playback rate controls when they're no playback rate options to select
  17528. *
  17529. * @param {EventTarget~Event} [event]
  17530. * The event that caused this function to run.
  17531. *
  17532. * @listens Player#loadstart
  17533. */
  17534. ;
  17535. _proto.updateVisibility = function updateVisibility(event) {
  17536. if (this.playbackRateSupported()) {
  17537. this.removeClass('vjs-hidden');
  17538. } else {
  17539. this.addClass('vjs-hidden');
  17540. }
  17541. }
  17542. /**
  17543. * Update button label when rate changed
  17544. *
  17545. * @param {EventTarget~Event} [event]
  17546. * The event that caused this function to run.
  17547. *
  17548. * @listens Player#ratechange
  17549. */
  17550. ;
  17551. _proto.updateLabel = function updateLabel(event) {
  17552. if (this.playbackRateSupported()) {
  17553. this.labelEl_.textContent = this.player().playbackRate() + 'x';
  17554. }
  17555. };
  17556. return PlaybackRateMenuButton;
  17557. }(MenuButton);
  17558. /**
  17559. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  17560. *
  17561. * @type {string}
  17562. * @private
  17563. */
  17564. PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
  17565. Component.registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
  17566. /**
  17567. * Just an empty spacer element that can be used as an append point for plugins, etc.
  17568. * Also can be used to create space between elements when necessary.
  17569. *
  17570. * @extends Component
  17571. */
  17572. var Spacer = /*#__PURE__*/function (_Component) {
  17573. inheritsLoose(Spacer, _Component);
  17574. function Spacer() {
  17575. return _Component.apply(this, arguments) || this;
  17576. }
  17577. var _proto = Spacer.prototype;
  17578. /**
  17579. * Builds the default DOM `className`.
  17580. *
  17581. * @return {string}
  17582. * The DOM `className` for this object.
  17583. */
  17584. _proto.buildCSSClass = function buildCSSClass() {
  17585. return "vjs-spacer " + _Component.prototype.buildCSSClass.call(this);
  17586. }
  17587. /**
  17588. * Create the `Component`'s DOM element
  17589. *
  17590. * @return {Element}
  17591. * The element that was created.
  17592. */
  17593. ;
  17594. _proto.createEl = function createEl(tag, props, attributes) {
  17595. if (tag === void 0) {
  17596. tag = 'div';
  17597. }
  17598. if (props === void 0) {
  17599. props = {};
  17600. }
  17601. if (attributes === void 0) {
  17602. attributes = {};
  17603. }
  17604. if (!props.className) {
  17605. props.className = this.buildCSSClass();
  17606. }
  17607. return _Component.prototype.createEl.call(this, tag, props, attributes);
  17608. };
  17609. return Spacer;
  17610. }(Component);
  17611. Component.registerComponent('Spacer', Spacer);
  17612. /**
  17613. * Spacer specifically meant to be used as an insertion point for new plugins, etc.
  17614. *
  17615. * @extends Spacer
  17616. */
  17617. var CustomControlSpacer = /*#__PURE__*/function (_Spacer) {
  17618. inheritsLoose(CustomControlSpacer, _Spacer);
  17619. function CustomControlSpacer() {
  17620. return _Spacer.apply(this, arguments) || this;
  17621. }
  17622. var _proto = CustomControlSpacer.prototype;
  17623. /**
  17624. * Builds the default DOM `className`.
  17625. *
  17626. * @return {string}
  17627. * The DOM `className` for this object.
  17628. */
  17629. _proto.buildCSSClass = function buildCSSClass() {
  17630. return "vjs-custom-control-spacer " + _Spacer.prototype.buildCSSClass.call(this);
  17631. }
  17632. /**
  17633. * Create the `Component`'s DOM element
  17634. *
  17635. * @return {Element}
  17636. * The element that was created.
  17637. */
  17638. ;
  17639. _proto.createEl = function createEl() {
  17640. return _Spacer.prototype.createEl.call(this, 'div', {
  17641. className: this.buildCSSClass(),
  17642. // No-flex/table-cell mode requires there be some content
  17643. // in the cell to fill the remaining space of the table.
  17644. textContent: "\xA0"
  17645. });
  17646. };
  17647. return CustomControlSpacer;
  17648. }(Spacer);
  17649. Component.registerComponent('CustomControlSpacer', CustomControlSpacer);
  17650. /**
  17651. * Container of main controls.
  17652. *
  17653. * @extends Component
  17654. */
  17655. var ControlBar = /*#__PURE__*/function (_Component) {
  17656. inheritsLoose(ControlBar, _Component);
  17657. function ControlBar() {
  17658. return _Component.apply(this, arguments) || this;
  17659. }
  17660. var _proto = ControlBar.prototype;
  17661. /**
  17662. * Create the `Component`'s DOM element
  17663. *
  17664. * @return {Element}
  17665. * The element that was created.
  17666. */
  17667. _proto.createEl = function createEl() {
  17668. return _Component.prototype.createEl.call(this, 'div', {
  17669. className: 'vjs-control-bar',
  17670. dir: 'ltr'
  17671. });
  17672. };
  17673. return ControlBar;
  17674. }(Component);
  17675. /**
  17676. * Default options for `ControlBar`
  17677. *
  17678. * @type {Object}
  17679. * @private
  17680. */
  17681. ControlBar.prototype.options_ = {
  17682. children: ['playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'seekToLive', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'descriptionsButton', 'subsCapsButton', 'audioTrackButton', 'fullscreenToggle']
  17683. };
  17684. if ('exitPictureInPicture' in document) {
  17685. ControlBar.prototype.options_.children.splice(ControlBar.prototype.options_.children.length - 1, 0, 'pictureInPictureToggle');
  17686. }
  17687. Component.registerComponent('ControlBar', ControlBar);
  17688. /**
  17689. * A display that indicates an error has occurred. This means that the video
  17690. * is unplayable.
  17691. *
  17692. * @extends ModalDialog
  17693. */
  17694. var ErrorDisplay = /*#__PURE__*/function (_ModalDialog) {
  17695. inheritsLoose(ErrorDisplay, _ModalDialog);
  17696. /**
  17697. * Creates an instance of this class.
  17698. *
  17699. * @param {Player} player
  17700. * The `Player` that this class should be attached to.
  17701. *
  17702. * @param {Object} [options]
  17703. * The key/value store of player options.
  17704. */
  17705. function ErrorDisplay(player, options) {
  17706. var _this;
  17707. _this = _ModalDialog.call(this, player, options) || this;
  17708. _this.on(player, 'error', function (e) {
  17709. return _this.open(e);
  17710. });
  17711. return _this;
  17712. }
  17713. /**
  17714. * Builds the default DOM `className`.
  17715. *
  17716. * @return {string}
  17717. * The DOM `className` for this object.
  17718. *
  17719. * @deprecated Since version 5.
  17720. */
  17721. var _proto = ErrorDisplay.prototype;
  17722. _proto.buildCSSClass = function buildCSSClass() {
  17723. return "vjs-error-display " + _ModalDialog.prototype.buildCSSClass.call(this);
  17724. }
  17725. /**
  17726. * Gets the localized error message based on the `Player`s error.
  17727. *
  17728. * @return {string}
  17729. * The `Player`s error message localized or an empty string.
  17730. */
  17731. ;
  17732. _proto.content = function content() {
  17733. var error = this.player().error();
  17734. return error ? this.localize(error.message) : '';
  17735. };
  17736. return ErrorDisplay;
  17737. }(ModalDialog);
  17738. /**
  17739. * The default options for an `ErrorDisplay`.
  17740. *
  17741. * @private
  17742. */
  17743. ErrorDisplay.prototype.options_ = _extends_1({}, ModalDialog.prototype.options_, {
  17744. pauseOnOpen: false,
  17745. fillAlways: true,
  17746. temporary: false,
  17747. uncloseable: true
  17748. });
  17749. Component.registerComponent('ErrorDisplay', ErrorDisplay);
  17750. var LOCAL_STORAGE_KEY = 'vjs-text-track-settings';
  17751. var COLOR_BLACK = ['#000', 'Black'];
  17752. var COLOR_BLUE = ['#00F', 'Blue'];
  17753. var COLOR_CYAN = ['#0FF', 'Cyan'];
  17754. var COLOR_GREEN = ['#0F0', 'Green'];
  17755. var COLOR_MAGENTA = ['#F0F', 'Magenta'];
  17756. var COLOR_RED = ['#F00', 'Red'];
  17757. var COLOR_WHITE = ['#FFF', 'White'];
  17758. var COLOR_YELLOW = ['#FF0', 'Yellow'];
  17759. var OPACITY_OPAQUE = ['1', 'Opaque'];
  17760. var OPACITY_SEMI = ['0.5', 'Semi-Transparent'];
  17761. var OPACITY_TRANS = ['0', 'Transparent']; // Configuration for the various <select> elements in the DOM of this component.
  17762. //
  17763. // Possible keys include:
  17764. //
  17765. // `default`:
  17766. // The default option index. Only needs to be provided if not zero.
  17767. // `parser`:
  17768. // A function which is used to parse the value from the selected option in
  17769. // a customized way.
  17770. // `selector`:
  17771. // The selector used to find the associated <select> element.
  17772. var selectConfigs = {
  17773. backgroundColor: {
  17774. selector: '.vjs-bg-color > select',
  17775. id: 'captions-background-color-%s',
  17776. label: 'Color',
  17777. options: [COLOR_BLACK, COLOR_WHITE, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  17778. },
  17779. backgroundOpacity: {
  17780. selector: '.vjs-bg-opacity > select',
  17781. id: 'captions-background-opacity-%s',
  17782. label: 'Transparency',
  17783. options: [OPACITY_OPAQUE, OPACITY_SEMI, OPACITY_TRANS]
  17784. },
  17785. color: {
  17786. selector: '.vjs-fg-color > select',
  17787. id: 'captions-foreground-color-%s',
  17788. label: 'Color',
  17789. options: [COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  17790. },
  17791. edgeStyle: {
  17792. selector: '.vjs-edge-style > select',
  17793. id: '%s',
  17794. label: 'Text Edge Style',
  17795. options: [['none', 'None'], ['raised', 'Raised'], ['depressed', 'Depressed'], ['uniform', 'Uniform'], ['dropshadow', 'Dropshadow']]
  17796. },
  17797. fontFamily: {
  17798. selector: '.vjs-font-family > select',
  17799. id: 'captions-font-family-%s',
  17800. label: 'Font Family',
  17801. options: [['proportionalSansSerif', 'Proportional Sans-Serif'], ['monospaceSansSerif', 'Monospace Sans-Serif'], ['proportionalSerif', 'Proportional Serif'], ['monospaceSerif', 'Monospace Serif'], ['casual', 'Casual'], ['script', 'Script'], ['small-caps', 'Small Caps']]
  17802. },
  17803. fontPercent: {
  17804. selector: '.vjs-font-percent > select',
  17805. id: 'captions-font-size-%s',
  17806. label: 'Font Size',
  17807. 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%']],
  17808. "default": 2,
  17809. parser: function parser(v) {
  17810. return v === '1.00' ? null : Number(v);
  17811. }
  17812. },
  17813. textOpacity: {
  17814. selector: '.vjs-text-opacity > select',
  17815. id: 'captions-foreground-opacity-%s',
  17816. label: 'Transparency',
  17817. options: [OPACITY_OPAQUE, OPACITY_SEMI]
  17818. },
  17819. // Options for this object are defined below.
  17820. windowColor: {
  17821. selector: '.vjs-window-color > select',
  17822. id: 'captions-window-color-%s',
  17823. label: 'Color'
  17824. },
  17825. // Options for this object are defined below.
  17826. windowOpacity: {
  17827. selector: '.vjs-window-opacity > select',
  17828. id: 'captions-window-opacity-%s',
  17829. label: 'Transparency',
  17830. options: [OPACITY_TRANS, OPACITY_SEMI, OPACITY_OPAQUE]
  17831. }
  17832. };
  17833. selectConfigs.windowColor.options = selectConfigs.backgroundColor.options;
  17834. /**
  17835. * Get the actual value of an option.
  17836. *
  17837. * @param {string} value
  17838. * The value to get
  17839. *
  17840. * @param {Function} [parser]
  17841. * Optional function to adjust the value.
  17842. *
  17843. * @return {Mixed}
  17844. * - Will be `undefined` if no value exists
  17845. * - Will be `undefined` if the given value is "none".
  17846. * - Will be the actual value otherwise.
  17847. *
  17848. * @private
  17849. */
  17850. function parseOptionValue(value, parser) {
  17851. if (parser) {
  17852. value = parser(value);
  17853. }
  17854. if (value && value !== 'none') {
  17855. return value;
  17856. }
  17857. }
  17858. /**
  17859. * Gets the value of the selected <option> element within a <select> element.
  17860. *
  17861. * @param {Element} el
  17862. * the element to look in
  17863. *
  17864. * @param {Function} [parser]
  17865. * Optional function to adjust the value.
  17866. *
  17867. * @return {Mixed}
  17868. * - Will be `undefined` if no value exists
  17869. * - Will be `undefined` if the given value is "none".
  17870. * - Will be the actual value otherwise.
  17871. *
  17872. * @private
  17873. */
  17874. function getSelectedOptionValue(el, parser) {
  17875. var value = el.options[el.options.selectedIndex].value;
  17876. return parseOptionValue(value, parser);
  17877. }
  17878. /**
  17879. * Sets the selected <option> element within a <select> element based on a
  17880. * given value.
  17881. *
  17882. * @param {Element} el
  17883. * The element to look in.
  17884. *
  17885. * @param {string} value
  17886. * the property to look on.
  17887. *
  17888. * @param {Function} [parser]
  17889. * Optional function to adjust the value before comparing.
  17890. *
  17891. * @private
  17892. */
  17893. function setSelectedOption(el, value, parser) {
  17894. if (!value) {
  17895. return;
  17896. }
  17897. for (var i = 0; i < el.options.length; i++) {
  17898. if (parseOptionValue(el.options[i].value, parser) === value) {
  17899. el.selectedIndex = i;
  17900. break;
  17901. }
  17902. }
  17903. }
  17904. /**
  17905. * Manipulate Text Tracks settings.
  17906. *
  17907. * @extends ModalDialog
  17908. */
  17909. var TextTrackSettings = /*#__PURE__*/function (_ModalDialog) {
  17910. inheritsLoose(TextTrackSettings, _ModalDialog);
  17911. /**
  17912. * Creates an instance of this class.
  17913. *
  17914. * @param {Player} player
  17915. * The `Player` that this class should be attached to.
  17916. *
  17917. * @param {Object} [options]
  17918. * The key/value store of player options.
  17919. */
  17920. function TextTrackSettings(player, options) {
  17921. var _this;
  17922. options.temporary = false;
  17923. _this = _ModalDialog.call(this, player, options) || this;
  17924. _this.updateDisplay = _this.updateDisplay.bind(assertThisInitialized(_this)); // fill the modal and pretend we have opened it
  17925. _this.fill();
  17926. _this.hasBeenOpened_ = _this.hasBeenFilled_ = true;
  17927. _this.endDialog = createEl('p', {
  17928. className: 'vjs-control-text',
  17929. textContent: _this.localize('End of dialog window.')
  17930. });
  17931. _this.el().appendChild(_this.endDialog);
  17932. _this.setDefaults(); // Grab `persistTextTrackSettings` from the player options if not passed in child options
  17933. if (options.persistTextTrackSettings === undefined) {
  17934. _this.options_.persistTextTrackSettings = _this.options_.playerOptions.persistTextTrackSettings;
  17935. }
  17936. _this.on(_this.$('.vjs-done-button'), 'click', function () {
  17937. _this.saveSettings();
  17938. _this.close();
  17939. });
  17940. _this.on(_this.$('.vjs-default-button'), 'click', function () {
  17941. _this.setDefaults();
  17942. _this.updateDisplay();
  17943. });
  17944. each(selectConfigs, function (config) {
  17945. _this.on(_this.$(config.selector), 'change', _this.updateDisplay);
  17946. });
  17947. if (_this.options_.persistTextTrackSettings) {
  17948. _this.restoreSettings();
  17949. }
  17950. return _this;
  17951. }
  17952. var _proto = TextTrackSettings.prototype;
  17953. _proto.dispose = function dispose() {
  17954. this.endDialog = null;
  17955. _ModalDialog.prototype.dispose.call(this);
  17956. }
  17957. /**
  17958. * Create a <select> element with configured options.
  17959. *
  17960. * @param {string} key
  17961. * Configuration key to use during creation.
  17962. *
  17963. * @return {string}
  17964. * An HTML string.
  17965. *
  17966. * @private
  17967. */
  17968. ;
  17969. _proto.createElSelect_ = function createElSelect_(key, legendId, type) {
  17970. var _this2 = this;
  17971. if (legendId === void 0) {
  17972. legendId = '';
  17973. }
  17974. if (type === void 0) {
  17975. type = 'label';
  17976. }
  17977. var config = selectConfigs[key];
  17978. var id = config.id.replace('%s', this.id_);
  17979. var selectLabelledbyIds = [legendId, id].join(' ').trim();
  17980. return ["<" + type + " id=\"" + id + "\" class=\"" + (type === 'label' ? 'vjs-label' : '') + "\">", this.localize(config.label), "</" + type + ">", "<select aria-labelledby=\"" + selectLabelledbyIds + "\">"].concat(config.options.map(function (o) {
  17981. var optionId = id + '-' + o[1].replace(/\W+/g, '');
  17982. return ["<option id=\"" + optionId + "\" value=\"" + o[0] + "\" ", "aria-labelledby=\"" + selectLabelledbyIds + " " + optionId + "\">", _this2.localize(o[1]), '</option>'].join('');
  17983. })).concat('</select>').join('');
  17984. }
  17985. /**
  17986. * Create foreground color element for the component
  17987. *
  17988. * @return {string}
  17989. * An HTML string.
  17990. *
  17991. * @private
  17992. */
  17993. ;
  17994. _proto.createElFgColor_ = function createElFgColor_() {
  17995. var legendId = "captions-text-legend-" + this.id_;
  17996. 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('');
  17997. }
  17998. /**
  17999. * Create background color element for the component
  18000. *
  18001. * @return {string}
  18002. * An HTML string.
  18003. *
  18004. * @private
  18005. */
  18006. ;
  18007. _proto.createElBgColor_ = function createElBgColor_() {
  18008. var legendId = "captions-background-" + this.id_;
  18009. 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('');
  18010. }
  18011. /**
  18012. * Create window color element for the component
  18013. *
  18014. * @return {string}
  18015. * An HTML string.
  18016. *
  18017. * @private
  18018. */
  18019. ;
  18020. _proto.createElWinColor_ = function createElWinColor_() {
  18021. var legendId = "captions-window-" + this.id_;
  18022. 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('');
  18023. }
  18024. /**
  18025. * Create color elements for the component
  18026. *
  18027. * @return {Element}
  18028. * The element that was created
  18029. *
  18030. * @private
  18031. */
  18032. ;
  18033. _proto.createElColors_ = function createElColors_() {
  18034. return createEl('div', {
  18035. className: 'vjs-track-settings-colors',
  18036. innerHTML: [this.createElFgColor_(), this.createElBgColor_(), this.createElWinColor_()].join('')
  18037. });
  18038. }
  18039. /**
  18040. * Create font elements for the component
  18041. *
  18042. * @return {Element}
  18043. * The element that was created.
  18044. *
  18045. * @private
  18046. */
  18047. ;
  18048. _proto.createElFont_ = function createElFont_() {
  18049. return createEl('div', {
  18050. className: 'vjs-track-settings-font',
  18051. 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('')
  18052. });
  18053. }
  18054. /**
  18055. * Create controls for the component
  18056. *
  18057. * @return {Element}
  18058. * The element that was created.
  18059. *
  18060. * @private
  18061. */
  18062. ;
  18063. _proto.createElControls_ = function createElControls_() {
  18064. var defaultsDescription = this.localize('restore all settings to the default values');
  18065. return createEl('div', {
  18066. className: 'vjs-track-settings-controls',
  18067. 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('')
  18068. });
  18069. };
  18070. _proto.content = function content() {
  18071. return [this.createElColors_(), this.createElFont_(), this.createElControls_()];
  18072. };
  18073. _proto.label = function label() {
  18074. return this.localize('Caption Settings Dialog');
  18075. };
  18076. _proto.description = function description() {
  18077. return this.localize('Beginning of dialog window. Escape will cancel and close the window.');
  18078. };
  18079. _proto.buildCSSClass = function buildCSSClass() {
  18080. return _ModalDialog.prototype.buildCSSClass.call(this) + ' vjs-text-track-settings';
  18081. }
  18082. /**
  18083. * Gets an object of text track settings (or null).
  18084. *
  18085. * @return {Object}
  18086. * An object with config values parsed from the DOM or localStorage.
  18087. */
  18088. ;
  18089. _proto.getValues = function getValues() {
  18090. var _this3 = this;
  18091. return reduce(selectConfigs, function (accum, config, key) {
  18092. var value = getSelectedOptionValue(_this3.$(config.selector), config.parser);
  18093. if (value !== undefined) {
  18094. accum[key] = value;
  18095. }
  18096. return accum;
  18097. }, {});
  18098. }
  18099. /**
  18100. * Sets text track settings from an object of values.
  18101. *
  18102. * @param {Object} values
  18103. * An object with config values parsed from the DOM or localStorage.
  18104. */
  18105. ;
  18106. _proto.setValues = function setValues(values) {
  18107. var _this4 = this;
  18108. each(selectConfigs, function (config, key) {
  18109. setSelectedOption(_this4.$(config.selector), values[key], config.parser);
  18110. });
  18111. }
  18112. /**
  18113. * Sets all `<select>` elements to their default values.
  18114. */
  18115. ;
  18116. _proto.setDefaults = function setDefaults() {
  18117. var _this5 = this;
  18118. each(selectConfigs, function (config) {
  18119. var index = config.hasOwnProperty('default') ? config["default"] : 0;
  18120. _this5.$(config.selector).selectedIndex = index;
  18121. });
  18122. }
  18123. /**
  18124. * Restore texttrack settings from localStorage
  18125. */
  18126. ;
  18127. _proto.restoreSettings = function restoreSettings() {
  18128. var values;
  18129. try {
  18130. values = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY));
  18131. } catch (err) {
  18132. log.warn(err);
  18133. }
  18134. if (values) {
  18135. this.setValues(values);
  18136. }
  18137. }
  18138. /**
  18139. * Save text track settings to localStorage
  18140. */
  18141. ;
  18142. _proto.saveSettings = function saveSettings() {
  18143. if (!this.options_.persistTextTrackSettings) {
  18144. return;
  18145. }
  18146. var values = this.getValues();
  18147. try {
  18148. if (Object.keys(values).length) {
  18149. window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(values));
  18150. } else {
  18151. window.localStorage.removeItem(LOCAL_STORAGE_KEY);
  18152. }
  18153. } catch (err) {
  18154. log.warn(err);
  18155. }
  18156. }
  18157. /**
  18158. * Update display of text track settings
  18159. */
  18160. ;
  18161. _proto.updateDisplay = function updateDisplay() {
  18162. var ttDisplay = this.player_.getChild('textTrackDisplay');
  18163. if (ttDisplay) {
  18164. ttDisplay.updateDisplay();
  18165. }
  18166. }
  18167. /**
  18168. * conditionally blur the element and refocus the captions button
  18169. *
  18170. * @private
  18171. */
  18172. ;
  18173. _proto.conditionalBlur_ = function conditionalBlur_() {
  18174. this.previouslyActiveEl_ = null;
  18175. var cb = this.player_.controlBar;
  18176. var subsCapsBtn = cb && cb.subsCapsButton;
  18177. var ccBtn = cb && cb.captionsButton;
  18178. if (subsCapsBtn) {
  18179. subsCapsBtn.focus();
  18180. } else if (ccBtn) {
  18181. ccBtn.focus();
  18182. }
  18183. };
  18184. return TextTrackSettings;
  18185. }(ModalDialog);
  18186. Component.registerComponent('TextTrackSettings', TextTrackSettings);
  18187. /**
  18188. * A Resize Manager. It is in charge of triggering `playerresize` on the player in the right conditions.
  18189. *
  18190. * 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}.
  18191. *
  18192. * If the ResizeObserver is available natively, it will be used. A polyfill can be passed in as an option.
  18193. * If a `playerresize` event is not needed, the ResizeManager component can be removed from the player, see the example below.
  18194. * @example <caption>How to disable the resize manager</caption>
  18195. * const player = videojs('#vid', {
  18196. * resizeManager: false
  18197. * });
  18198. *
  18199. * @see {@link https://wicg.github.io/ResizeObserver/|ResizeObserver specification}
  18200. *
  18201. * @extends Component
  18202. */
  18203. var ResizeManager = /*#__PURE__*/function (_Component) {
  18204. inheritsLoose(ResizeManager, _Component);
  18205. /**
  18206. * Create the ResizeManager.
  18207. *
  18208. * @param {Object} player
  18209. * The `Player` that this class should be attached to.
  18210. *
  18211. * @param {Object} [options]
  18212. * The key/value store of ResizeManager options.
  18213. *
  18214. * @param {Object} [options.ResizeObserver]
  18215. * A polyfill for ResizeObserver can be passed in here.
  18216. * If this is set to null it will ignore the native ResizeObserver and fall back to the iframe fallback.
  18217. */
  18218. function ResizeManager(player, options) {
  18219. var _this;
  18220. var RESIZE_OBSERVER_AVAILABLE = options.ResizeObserver || window.ResizeObserver; // if `null` was passed, we want to disable the ResizeObserver
  18221. if (options.ResizeObserver === null) {
  18222. RESIZE_OBSERVER_AVAILABLE = false;
  18223. } // Only create an element when ResizeObserver isn't available
  18224. var options_ = mergeOptions({
  18225. createEl: !RESIZE_OBSERVER_AVAILABLE,
  18226. reportTouchActivity: false
  18227. }, options);
  18228. _this = _Component.call(this, player, options_) || this;
  18229. _this.ResizeObserver = options.ResizeObserver || window.ResizeObserver;
  18230. _this.loadListener_ = null;
  18231. _this.resizeObserver_ = null;
  18232. _this.debouncedHandler_ = debounce(function () {
  18233. _this.resizeHandler();
  18234. }, 100, false, assertThisInitialized(_this));
  18235. if (RESIZE_OBSERVER_AVAILABLE) {
  18236. _this.resizeObserver_ = new _this.ResizeObserver(_this.debouncedHandler_);
  18237. _this.resizeObserver_.observe(player.el());
  18238. } else {
  18239. _this.loadListener_ = function () {
  18240. if (!_this.el_ || !_this.el_.contentWindow) {
  18241. return;
  18242. }
  18243. var debouncedHandler_ = _this.debouncedHandler_;
  18244. var unloadListener_ = _this.unloadListener_ = function () {
  18245. off(this, 'resize', debouncedHandler_);
  18246. off(this, 'unload', unloadListener_);
  18247. unloadListener_ = null;
  18248. }; // safari and edge can unload the iframe before resizemanager dispose
  18249. // we have to dispose of event handlers correctly before that happens
  18250. on(_this.el_.contentWindow, 'unload', unloadListener_);
  18251. on(_this.el_.contentWindow, 'resize', debouncedHandler_);
  18252. };
  18253. _this.one('load', _this.loadListener_);
  18254. }
  18255. return _this;
  18256. }
  18257. var _proto = ResizeManager.prototype;
  18258. _proto.createEl = function createEl() {
  18259. return _Component.prototype.createEl.call(this, 'iframe', {
  18260. className: 'vjs-resize-manager',
  18261. tabIndex: -1,
  18262. title: this.localize('No content')
  18263. }, {
  18264. 'aria-hidden': 'true'
  18265. });
  18266. }
  18267. /**
  18268. * Called when a resize is triggered on the iframe or a resize is observed via the ResizeObserver
  18269. *
  18270. * @fires Player#playerresize
  18271. */
  18272. ;
  18273. _proto.resizeHandler = function resizeHandler() {
  18274. /**
  18275. * Called when the player size has changed
  18276. *
  18277. * @event Player#playerresize
  18278. * @type {EventTarget~Event}
  18279. */
  18280. // make sure player is still around to trigger
  18281. // prevents this from causing an error after dispose
  18282. if (!this.player_ || !this.player_.trigger) {
  18283. return;
  18284. }
  18285. this.player_.trigger('playerresize');
  18286. };
  18287. _proto.dispose = function dispose() {
  18288. if (this.debouncedHandler_) {
  18289. this.debouncedHandler_.cancel();
  18290. }
  18291. if (this.resizeObserver_) {
  18292. if (this.player_.el()) {
  18293. this.resizeObserver_.unobserve(this.player_.el());
  18294. }
  18295. this.resizeObserver_.disconnect();
  18296. }
  18297. if (this.loadListener_) {
  18298. this.off('load', this.loadListener_);
  18299. }
  18300. if (this.el_ && this.el_.contentWindow && this.unloadListener_) {
  18301. this.unloadListener_.call(this.el_.contentWindow);
  18302. }
  18303. this.ResizeObserver = null;
  18304. this.resizeObserver = null;
  18305. this.debouncedHandler_ = null;
  18306. this.loadListener_ = null;
  18307. _Component.prototype.dispose.call(this);
  18308. };
  18309. return ResizeManager;
  18310. }(Component);
  18311. Component.registerComponent('ResizeManager', ResizeManager);
  18312. var defaults = {
  18313. trackingThreshold: 20,
  18314. liveTolerance: 15
  18315. };
  18316. /*
  18317. track when we are at the live edge, and other helpers for live playback */
  18318. /**
  18319. * A class for checking live current time and determining when the player
  18320. * is at or behind the live edge.
  18321. */
  18322. var LiveTracker = /*#__PURE__*/function (_Component) {
  18323. inheritsLoose(LiveTracker, _Component);
  18324. /**
  18325. * Creates an instance of this class.
  18326. *
  18327. * @param {Player} player
  18328. * The `Player` that this class should be attached to.
  18329. *
  18330. * @param {Object} [options]
  18331. * The key/value store of player options.
  18332. *
  18333. * @param {number} [options.trackingThreshold=20]
  18334. * Number of seconds of live window (seekableEnd - seekableStart) that
  18335. * media needs to have before the liveui will be shown.
  18336. *
  18337. * @param {number} [options.liveTolerance=15]
  18338. * Number of seconds behind live that we have to be
  18339. * before we will be considered non-live. Note that this will only
  18340. * be used when playing at the live edge. This allows large seekable end
  18341. * changes to not effect wether we are live or not.
  18342. */
  18343. function LiveTracker(player, options) {
  18344. var _this;
  18345. // LiveTracker does not need an element
  18346. var options_ = mergeOptions(defaults, options, {
  18347. createEl: false
  18348. });
  18349. _this = _Component.call(this, player, options_) || this;
  18350. _this.handleVisibilityChange_ = function (e) {
  18351. return _this.handleVisibilityChange(e);
  18352. };
  18353. _this.trackLiveHandler_ = function () {
  18354. return _this.trackLive_();
  18355. };
  18356. _this.handlePlay_ = function (e) {
  18357. return _this.handlePlay(e);
  18358. };
  18359. _this.handleFirstTimeupdate_ = function (e) {
  18360. return _this.handleFirstTimeupdate(e);
  18361. };
  18362. _this.handleSeeked_ = function (e) {
  18363. return _this.handleSeeked(e);
  18364. };
  18365. _this.seekToLiveEdge_ = function (e) {
  18366. return _this.seekToLiveEdge(e);
  18367. };
  18368. _this.reset_();
  18369. _this.on(_this.player_, 'durationchange', function (e) {
  18370. return _this.handleDurationchange(e);
  18371. }); // we should try to toggle tracking on canplay as native playback engines, like Safari
  18372. // may not have the proper values for things like seekableEnd until then
  18373. _this.on(_this.player_, 'canplay', function () {
  18374. return _this.toggleTracking();
  18375. }); // we don't need to track live playback if the document is hidden,
  18376. // also, tracking when the document is hidden can
  18377. // cause the CPU to spike and eventually crash the page on IE11.
  18378. if (IE_VERSION && 'hidden' in document && 'visibilityState' in document) {
  18379. _this.on(document, 'visibilitychange', _this.handleVisibilityChange_);
  18380. }
  18381. return _this;
  18382. }
  18383. /**
  18384. * toggle tracking based on document visiblility
  18385. */
  18386. var _proto = LiveTracker.prototype;
  18387. _proto.handleVisibilityChange = function handleVisibilityChange() {
  18388. if (this.player_.duration() !== Infinity) {
  18389. return;
  18390. }
  18391. if (document.hidden) {
  18392. this.stopTracking();
  18393. } else {
  18394. this.startTracking();
  18395. }
  18396. }
  18397. /**
  18398. * all the functionality for tracking when seek end changes
  18399. * and for tracking how far past seek end we should be
  18400. */
  18401. ;
  18402. _proto.trackLive_ = function trackLive_() {
  18403. var seekable = this.player_.seekable(); // skip undefined seekable
  18404. if (!seekable || !seekable.length) {
  18405. return;
  18406. }
  18407. var newTime = Number(window.performance.now().toFixed(4));
  18408. var deltaTime = this.lastTime_ === -1 ? 0 : (newTime - this.lastTime_) / 1000;
  18409. this.lastTime_ = newTime;
  18410. this.pastSeekEnd_ = this.pastSeekEnd() + deltaTime;
  18411. var liveCurrentTime = this.liveCurrentTime();
  18412. var currentTime = this.player_.currentTime(); // we are behind live if any are true
  18413. // 1. the player is paused
  18414. // 2. the user seeked to a location 2 seconds away from live
  18415. // 3. the difference between live and current time is greater
  18416. // liveTolerance which defaults to 15s
  18417. var isBehind = this.player_.paused() || this.seekedBehindLive_ || Math.abs(liveCurrentTime - currentTime) > this.options_.liveTolerance; // we cannot be behind if
  18418. // 1. until we have not seen a timeupdate yet
  18419. // 2. liveCurrentTime is Infinity, which happens on Android and Native Safari
  18420. if (!this.timeupdateSeen_ || liveCurrentTime === Infinity) {
  18421. isBehind = false;
  18422. }
  18423. if (isBehind !== this.behindLiveEdge_) {
  18424. this.behindLiveEdge_ = isBehind;
  18425. this.trigger('liveedgechange');
  18426. }
  18427. }
  18428. /**
  18429. * handle a durationchange event on the player
  18430. * and start/stop tracking accordingly.
  18431. */
  18432. ;
  18433. _proto.handleDurationchange = function handleDurationchange() {
  18434. this.toggleTracking();
  18435. }
  18436. /**
  18437. * start/stop tracking
  18438. */
  18439. ;
  18440. _proto.toggleTracking = function toggleTracking() {
  18441. if (this.player_.duration() === Infinity && this.liveWindow() >= this.options_.trackingThreshold) {
  18442. if (this.player_.options_.liveui) {
  18443. this.player_.addClass('vjs-liveui');
  18444. }
  18445. this.startTracking();
  18446. } else {
  18447. this.player_.removeClass('vjs-liveui');
  18448. this.stopTracking();
  18449. }
  18450. }
  18451. /**
  18452. * start tracking live playback
  18453. */
  18454. ;
  18455. _proto.startTracking = function startTracking() {
  18456. if (this.isTracking()) {
  18457. return;
  18458. } // If we haven't seen a timeupdate, we need to check whether playback
  18459. // began before this component started tracking. This can happen commonly
  18460. // when using autoplay.
  18461. if (!this.timeupdateSeen_) {
  18462. this.timeupdateSeen_ = this.player_.hasStarted();
  18463. }
  18464. this.trackingInterval_ = this.setInterval(this.trackLiveHandler_, UPDATE_REFRESH_INTERVAL);
  18465. this.trackLive_();
  18466. this.on(this.player_, ['play', 'pause'], this.trackLiveHandler_);
  18467. if (!this.timeupdateSeen_) {
  18468. this.one(this.player_, 'play', this.handlePlay_);
  18469. this.one(this.player_, 'timeupdate', this.handleFirstTimeupdate_);
  18470. } else {
  18471. this.on(this.player_, 'seeked', this.handleSeeked_);
  18472. }
  18473. }
  18474. /**
  18475. * handle the first timeupdate on the player if it wasn't already playing
  18476. * when live tracker started tracking.
  18477. */
  18478. ;
  18479. _proto.handleFirstTimeupdate = function handleFirstTimeupdate() {
  18480. this.timeupdateSeen_ = true;
  18481. this.on(this.player_, 'seeked', this.handleSeeked_);
  18482. }
  18483. /**
  18484. * Keep track of what time a seek starts, and listen for seeked
  18485. * to find where a seek ends.
  18486. */
  18487. ;
  18488. _proto.handleSeeked = function handleSeeked() {
  18489. var timeDiff = Math.abs(this.liveCurrentTime() - this.player_.currentTime());
  18490. this.seekedBehindLive_ = this.nextSeekedFromUser_ && timeDiff > 2;
  18491. this.nextSeekedFromUser_ = false;
  18492. this.trackLive_();
  18493. }
  18494. /**
  18495. * handle the first play on the player, and make sure that we seek
  18496. * right to the live edge.
  18497. */
  18498. ;
  18499. _proto.handlePlay = function handlePlay() {
  18500. this.one(this.player_, 'timeupdate', this.seekToLiveEdge_);
  18501. }
  18502. /**
  18503. * Stop tracking, and set all internal variables to
  18504. * their initial value.
  18505. */
  18506. ;
  18507. _proto.reset_ = function reset_() {
  18508. this.lastTime_ = -1;
  18509. this.pastSeekEnd_ = 0;
  18510. this.lastSeekEnd_ = -1;
  18511. this.behindLiveEdge_ = true;
  18512. this.timeupdateSeen_ = false;
  18513. this.seekedBehindLive_ = false;
  18514. this.nextSeekedFromUser_ = false;
  18515. this.clearInterval(this.trackingInterval_);
  18516. this.trackingInterval_ = null;
  18517. this.off(this.player_, ['play', 'pause'], this.trackLiveHandler_);
  18518. this.off(this.player_, 'seeked', this.handleSeeked_);
  18519. this.off(this.player_, 'play', this.handlePlay_);
  18520. this.off(this.player_, 'timeupdate', this.handleFirstTimeupdate_);
  18521. this.off(this.player_, 'timeupdate', this.seekToLiveEdge_);
  18522. }
  18523. /**
  18524. * The next seeked event is from the user. Meaning that any seek
  18525. * > 2s behind live will be considered behind live for real and
  18526. * liveTolerance will be ignored.
  18527. */
  18528. ;
  18529. _proto.nextSeekedFromUser = function nextSeekedFromUser() {
  18530. this.nextSeekedFromUser_ = true;
  18531. }
  18532. /**
  18533. * stop tracking live playback
  18534. */
  18535. ;
  18536. _proto.stopTracking = function stopTracking() {
  18537. if (!this.isTracking()) {
  18538. return;
  18539. }
  18540. this.reset_();
  18541. this.trigger('liveedgechange');
  18542. }
  18543. /**
  18544. * A helper to get the player seekable end
  18545. * so that we don't have to null check everywhere
  18546. *
  18547. * @return {number}
  18548. * The furthest seekable end or Infinity.
  18549. */
  18550. ;
  18551. _proto.seekableEnd = function seekableEnd() {
  18552. var seekable = this.player_.seekable();
  18553. var seekableEnds = [];
  18554. var i = seekable ? seekable.length : 0;
  18555. while (i--) {
  18556. seekableEnds.push(seekable.end(i));
  18557. } // grab the furthest seekable end after sorting, or if there are none
  18558. // default to Infinity
  18559. return seekableEnds.length ? seekableEnds.sort()[seekableEnds.length - 1] : Infinity;
  18560. }
  18561. /**
  18562. * A helper to get the player seekable start
  18563. * so that we don't have to null check everywhere
  18564. *
  18565. * @return {number}
  18566. * The earliest seekable start or 0.
  18567. */
  18568. ;
  18569. _proto.seekableStart = function seekableStart() {
  18570. var seekable = this.player_.seekable();
  18571. var seekableStarts = [];
  18572. var i = seekable ? seekable.length : 0;
  18573. while (i--) {
  18574. seekableStarts.push(seekable.start(i));
  18575. } // grab the first seekable start after sorting, or if there are none
  18576. // default to 0
  18577. return seekableStarts.length ? seekableStarts.sort()[0] : 0;
  18578. }
  18579. /**
  18580. * Get the live time window aka
  18581. * the amount of time between seekable start and
  18582. * live current time.
  18583. *
  18584. * @return {number}
  18585. * The amount of seconds that are seekable in
  18586. * the live video.
  18587. */
  18588. ;
  18589. _proto.liveWindow = function liveWindow() {
  18590. var liveCurrentTime = this.liveCurrentTime(); // if liveCurrenTime is Infinity then we don't have a liveWindow at all
  18591. if (liveCurrentTime === Infinity) {
  18592. return 0;
  18593. }
  18594. return liveCurrentTime - this.seekableStart();
  18595. }
  18596. /**
  18597. * Determines if the player is live, only checks if this component
  18598. * is tracking live playback or not
  18599. *
  18600. * @return {boolean}
  18601. * Wether liveTracker is tracking
  18602. */
  18603. ;
  18604. _proto.isLive = function isLive() {
  18605. return this.isTracking();
  18606. }
  18607. /**
  18608. * Determines if currentTime is at the live edge and won't fall behind
  18609. * on each seekableendchange
  18610. *
  18611. * @return {boolean}
  18612. * Wether playback is at the live edge
  18613. */
  18614. ;
  18615. _proto.atLiveEdge = function atLiveEdge() {
  18616. return !this.behindLiveEdge();
  18617. }
  18618. /**
  18619. * get what we expect the live current time to be
  18620. *
  18621. * @return {number}
  18622. * The expected live current time
  18623. */
  18624. ;
  18625. _proto.liveCurrentTime = function liveCurrentTime() {
  18626. return this.pastSeekEnd() + this.seekableEnd();
  18627. }
  18628. /**
  18629. * The number of seconds that have occured after seekable end
  18630. * changed. This will be reset to 0 once seekable end changes.
  18631. *
  18632. * @return {number}
  18633. * Seconds past the current seekable end
  18634. */
  18635. ;
  18636. _proto.pastSeekEnd = function pastSeekEnd() {
  18637. var seekableEnd = this.seekableEnd();
  18638. if (this.lastSeekEnd_ !== -1 && seekableEnd !== this.lastSeekEnd_) {
  18639. this.pastSeekEnd_ = 0;
  18640. }
  18641. this.lastSeekEnd_ = seekableEnd;
  18642. return this.pastSeekEnd_;
  18643. }
  18644. /**
  18645. * If we are currently behind the live edge, aka currentTime will be
  18646. * behind on a seekableendchange
  18647. *
  18648. * @return {boolean}
  18649. * If we are behind the live edge
  18650. */
  18651. ;
  18652. _proto.behindLiveEdge = function behindLiveEdge() {
  18653. return this.behindLiveEdge_;
  18654. }
  18655. /**
  18656. * Wether live tracker is currently tracking or not.
  18657. */
  18658. ;
  18659. _proto.isTracking = function isTracking() {
  18660. return typeof this.trackingInterval_ === 'number';
  18661. }
  18662. /**
  18663. * Seek to the live edge if we are behind the live edge
  18664. */
  18665. ;
  18666. _proto.seekToLiveEdge = function seekToLiveEdge() {
  18667. this.seekedBehindLive_ = false;
  18668. if (this.atLiveEdge()) {
  18669. return;
  18670. }
  18671. this.nextSeekedFromUser_ = false;
  18672. this.player_.currentTime(this.liveCurrentTime());
  18673. }
  18674. /**
  18675. * Dispose of liveTracker
  18676. */
  18677. ;
  18678. _proto.dispose = function dispose() {
  18679. this.off(document, 'visibilitychange', this.handleVisibilityChange_);
  18680. this.stopTracking();
  18681. _Component.prototype.dispose.call(this);
  18682. };
  18683. return LiveTracker;
  18684. }(Component);
  18685. Component.registerComponent('LiveTracker', LiveTracker);
  18686. /**
  18687. * This function is used to fire a sourceset when there is something
  18688. * similar to `mediaEl.load()` being called. It will try to find the source via
  18689. * the `src` attribute and then the `<source>` elements. It will then fire `sourceset`
  18690. * with the source that was found or empty string if we cannot know. If it cannot
  18691. * find a source then `sourceset` will not be fired.
  18692. *
  18693. * @param {Html5} tech
  18694. * The tech object that sourceset was setup on
  18695. *
  18696. * @return {boolean}
  18697. * returns false if the sourceset was not fired and true otherwise.
  18698. */
  18699. var sourcesetLoad = function sourcesetLoad(tech) {
  18700. var el = tech.el(); // if `el.src` is set, that source will be loaded.
  18701. if (el.hasAttribute('src')) {
  18702. tech.triggerSourceset(el.src);
  18703. return true;
  18704. }
  18705. /**
  18706. * Since there isn't a src property on the media element, source elements will be used for
  18707. * implementing the source selection algorithm. This happens asynchronously and
  18708. * for most cases were there is more than one source we cannot tell what source will
  18709. * be loaded, without re-implementing the source selection algorithm. At this time we are not
  18710. * going to do that. There are three special cases that we do handle here though:
  18711. *
  18712. * 1. If there are no sources, do not fire `sourceset`.
  18713. * 2. If there is only one `<source>` with a `src` property/attribute that is our `src`
  18714. * 3. If there is more than one `<source>` but all of them have the same `src` url.
  18715. * That will be our src.
  18716. */
  18717. var sources = tech.$$('source');
  18718. var srcUrls = [];
  18719. var src = ''; // if there are no sources, do not fire sourceset
  18720. if (!sources.length) {
  18721. return false;
  18722. } // only count valid/non-duplicate source elements
  18723. for (var i = 0; i < sources.length; i++) {
  18724. var url = sources[i].src;
  18725. if (url && srcUrls.indexOf(url) === -1) {
  18726. srcUrls.push(url);
  18727. }
  18728. } // there were no valid sources
  18729. if (!srcUrls.length) {
  18730. return false;
  18731. } // there is only one valid source element url
  18732. // use that
  18733. if (srcUrls.length === 1) {
  18734. src = srcUrls[0];
  18735. }
  18736. tech.triggerSourceset(src);
  18737. return true;
  18738. };
  18739. /**
  18740. * our implementation of an `innerHTML` descriptor for browsers
  18741. * that do not have one.
  18742. */
  18743. var innerHTMLDescriptorPolyfill = Object.defineProperty({}, 'innerHTML', {
  18744. get: function get() {
  18745. return this.cloneNode(true).innerHTML;
  18746. },
  18747. set: function set(v) {
  18748. // make a dummy node to use innerHTML on
  18749. var dummy = document.createElement(this.nodeName.toLowerCase()); // set innerHTML to the value provided
  18750. dummy.innerHTML = v; // make a document fragment to hold the nodes from dummy
  18751. var docFrag = document.createDocumentFragment(); // copy all of the nodes created by the innerHTML on dummy
  18752. // to the document fragment
  18753. while (dummy.childNodes.length) {
  18754. docFrag.appendChild(dummy.childNodes[0]);
  18755. } // remove content
  18756. this.innerText = ''; // now we add all of that html in one by appending the
  18757. // document fragment. This is how innerHTML does it.
  18758. window.Element.prototype.appendChild.call(this, docFrag); // then return the result that innerHTML's setter would
  18759. return this.innerHTML;
  18760. }
  18761. });
  18762. /**
  18763. * Get a property descriptor given a list of priorities and the
  18764. * property to get.
  18765. */
  18766. var getDescriptor = function getDescriptor(priority, prop) {
  18767. var descriptor = {};
  18768. for (var i = 0; i < priority.length; i++) {
  18769. descriptor = Object.getOwnPropertyDescriptor(priority[i], prop);
  18770. if (descriptor && descriptor.set && descriptor.get) {
  18771. break;
  18772. }
  18773. }
  18774. descriptor.enumerable = true;
  18775. descriptor.configurable = true;
  18776. return descriptor;
  18777. };
  18778. var getInnerHTMLDescriptor = function getInnerHTMLDescriptor(tech) {
  18779. return getDescriptor([tech.el(), window.HTMLMediaElement.prototype, window.Element.prototype, innerHTMLDescriptorPolyfill], 'innerHTML');
  18780. };
  18781. /**
  18782. * Patches browser internal functions so that we can tell synchronously
  18783. * if a `<source>` was appended to the media element. For some reason this
  18784. * causes a `sourceset` if the the media element is ready and has no source.
  18785. * This happens when:
  18786. * - The page has just loaded and the media element does not have a source.
  18787. * - The media element was emptied of all sources, then `load()` was called.
  18788. *
  18789. * It does this by patching the following functions/properties when they are supported:
  18790. *
  18791. * - `append()` - can be used to add a `<source>` element to the media element
  18792. * - `appendChild()` - can be used to add a `<source>` element to the media element
  18793. * - `insertAdjacentHTML()` - can be used to add a `<source>` element to the media element
  18794. * - `innerHTML` - can be used to add a `<source>` element to the media element
  18795. *
  18796. * @param {Html5} tech
  18797. * The tech object that sourceset is being setup on.
  18798. */
  18799. var firstSourceWatch = function firstSourceWatch(tech) {
  18800. var el = tech.el(); // make sure firstSourceWatch isn't setup twice.
  18801. if (el.resetSourceWatch_) {
  18802. return;
  18803. }
  18804. var old = {};
  18805. var innerDescriptor = getInnerHTMLDescriptor(tech);
  18806. var appendWrapper = function appendWrapper(appendFn) {
  18807. return function () {
  18808. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  18809. args[_key] = arguments[_key];
  18810. }
  18811. var retval = appendFn.apply(el, args);
  18812. sourcesetLoad(tech);
  18813. return retval;
  18814. };
  18815. };
  18816. ['append', 'appendChild', 'insertAdjacentHTML'].forEach(function (k) {
  18817. if (!el[k]) {
  18818. return;
  18819. } // store the old function
  18820. old[k] = el[k]; // call the old function with a sourceset if a source
  18821. // was loaded
  18822. el[k] = appendWrapper(old[k]);
  18823. });
  18824. Object.defineProperty(el, 'innerHTML', mergeOptions(innerDescriptor, {
  18825. set: appendWrapper(innerDescriptor.set)
  18826. }));
  18827. el.resetSourceWatch_ = function () {
  18828. el.resetSourceWatch_ = null;
  18829. Object.keys(old).forEach(function (k) {
  18830. el[k] = old[k];
  18831. });
  18832. Object.defineProperty(el, 'innerHTML', innerDescriptor);
  18833. }; // on the first sourceset, we need to revert our changes
  18834. tech.one('sourceset', el.resetSourceWatch_);
  18835. };
  18836. /**
  18837. * our implementation of a `src` descriptor for browsers
  18838. * that do not have one.
  18839. */
  18840. var srcDescriptorPolyfill = Object.defineProperty({}, 'src', {
  18841. get: function get() {
  18842. if (this.hasAttribute('src')) {
  18843. return getAbsoluteURL(window.Element.prototype.getAttribute.call(this, 'src'));
  18844. }
  18845. return '';
  18846. },
  18847. set: function set(v) {
  18848. window.Element.prototype.setAttribute.call(this, 'src', v);
  18849. return v;
  18850. }
  18851. });
  18852. var getSrcDescriptor = function getSrcDescriptor(tech) {
  18853. return getDescriptor([tech.el(), window.HTMLMediaElement.prototype, srcDescriptorPolyfill], 'src');
  18854. };
  18855. /**
  18856. * setup `sourceset` handling on the `Html5` tech. This function
  18857. * patches the following element properties/functions:
  18858. *
  18859. * - `src` - to determine when `src` is set
  18860. * - `setAttribute()` - to determine when `src` is set
  18861. * - `load()` - this re-triggers the source selection algorithm, and can
  18862. * cause a sourceset.
  18863. *
  18864. * If there is no source when we are adding `sourceset` support or during a `load()`
  18865. * we also patch the functions listed in `firstSourceWatch`.
  18866. *
  18867. * @param {Html5} tech
  18868. * The tech to patch
  18869. */
  18870. var setupSourceset = function setupSourceset(tech) {
  18871. if (!tech.featuresSourceset) {
  18872. return;
  18873. }
  18874. var el = tech.el(); // make sure sourceset isn't setup twice.
  18875. if (el.resetSourceset_) {
  18876. return;
  18877. }
  18878. var srcDescriptor = getSrcDescriptor(tech);
  18879. var oldSetAttribute = el.setAttribute;
  18880. var oldLoad = el.load;
  18881. Object.defineProperty(el, 'src', mergeOptions(srcDescriptor, {
  18882. set: function set(v) {
  18883. var retval = srcDescriptor.set.call(el, v); // we use the getter here to get the actual value set on src
  18884. tech.triggerSourceset(el.src);
  18885. return retval;
  18886. }
  18887. }));
  18888. el.setAttribute = function (n, v) {
  18889. var retval = oldSetAttribute.call(el, n, v);
  18890. if (/src/i.test(n)) {
  18891. tech.triggerSourceset(el.src);
  18892. }
  18893. return retval;
  18894. };
  18895. el.load = function () {
  18896. var retval = oldLoad.call(el); // if load was called, but there was no source to fire
  18897. // sourceset on. We have to watch for a source append
  18898. // as that can trigger a `sourceset` when the media element
  18899. // has no source
  18900. if (!sourcesetLoad(tech)) {
  18901. tech.triggerSourceset('');
  18902. firstSourceWatch(tech);
  18903. }
  18904. return retval;
  18905. };
  18906. if (el.currentSrc) {
  18907. tech.triggerSourceset(el.currentSrc);
  18908. } else if (!sourcesetLoad(tech)) {
  18909. firstSourceWatch(tech);
  18910. }
  18911. el.resetSourceset_ = function () {
  18912. el.resetSourceset_ = null;
  18913. el.load = oldLoad;
  18914. el.setAttribute = oldSetAttribute;
  18915. Object.defineProperty(el, 'src', srcDescriptor);
  18916. if (el.resetSourceWatch_) {
  18917. el.resetSourceWatch_();
  18918. }
  18919. };
  18920. };
  18921. /**
  18922. * Object.defineProperty but "lazy", which means that the value is only set after
  18923. * it retrieved the first time, rather than being set right away.
  18924. *
  18925. * @param {Object} obj the object to set the property on
  18926. * @param {string} key the key for the property to set
  18927. * @param {Function} getValue the function used to get the value when it is needed.
  18928. * @param {boolean} setter wether a setter shoould be allowed or not
  18929. */
  18930. var defineLazyProperty = function defineLazyProperty(obj, key, getValue, setter) {
  18931. if (setter === void 0) {
  18932. setter = true;
  18933. }
  18934. var set = function set(value) {
  18935. return Object.defineProperty(obj, key, {
  18936. value: value,
  18937. enumerable: true,
  18938. writable: true
  18939. });
  18940. };
  18941. var options = {
  18942. configurable: true,
  18943. enumerable: true,
  18944. get: function get() {
  18945. var value = getValue();
  18946. set(value);
  18947. return value;
  18948. }
  18949. };
  18950. if (setter) {
  18951. options.set = set;
  18952. }
  18953. return Object.defineProperty(obj, key, options);
  18954. };
  18955. /**
  18956. * HTML5 Media Controller - Wrapper for HTML5 Media API
  18957. *
  18958. * @mixes Tech~SourceHandlerAdditions
  18959. * @extends Tech
  18960. */
  18961. var Html5 = /*#__PURE__*/function (_Tech) {
  18962. inheritsLoose(Html5, _Tech);
  18963. /**
  18964. * Create an instance of this Tech.
  18965. *
  18966. * @param {Object} [options]
  18967. * The key/value store of player options.
  18968. *
  18969. * @param {Component~ReadyCallback} ready
  18970. * Callback function to call when the `HTML5` Tech is ready.
  18971. */
  18972. function Html5(options, ready) {
  18973. var _this;
  18974. _this = _Tech.call(this, options, ready) || this;
  18975. var source = options.source;
  18976. var crossoriginTracks = false;
  18977. _this.featuresVideoFrameCallback = _this.featuresVideoFrameCallback && _this.el_.tagName === 'VIDEO'; // Set the source if one is provided
  18978. // 1) Check if the source is new (if not, we want to keep the original so playback isn't interrupted)
  18979. // 2) Check to see if the network state of the tag was failed at init, and if so, reset the source
  18980. // anyway so the error gets fired.
  18981. if (source && (_this.el_.currentSrc !== source.src || options.tag && options.tag.initNetworkState_ === 3)) {
  18982. _this.setSource(source);
  18983. } else {
  18984. _this.handleLateInit_(_this.el_);
  18985. } // setup sourceset after late sourceset/init
  18986. if (options.enableSourceset) {
  18987. _this.setupSourcesetHandling_();
  18988. }
  18989. _this.isScrubbing_ = false;
  18990. if (_this.el_.hasChildNodes()) {
  18991. var nodes = _this.el_.childNodes;
  18992. var nodesLength = nodes.length;
  18993. var removeNodes = [];
  18994. while (nodesLength--) {
  18995. var node = nodes[nodesLength];
  18996. var nodeName = node.nodeName.toLowerCase();
  18997. if (nodeName === 'track') {
  18998. if (!_this.featuresNativeTextTracks) {
  18999. // Empty video tag tracks so the built-in player doesn't use them also.
  19000. // This may not be fast enough to stop HTML5 browsers from reading the tags
  19001. // so we'll need to turn off any default tracks if we're manually doing
  19002. // captions and subtitles. videoElement.textTracks
  19003. removeNodes.push(node);
  19004. } else {
  19005. // store HTMLTrackElement and TextTrack to remote list
  19006. _this.remoteTextTrackEls().addTrackElement_(node);
  19007. _this.remoteTextTracks().addTrack(node.track);
  19008. _this.textTracks().addTrack(node.track);
  19009. if (!crossoriginTracks && !_this.el_.hasAttribute('crossorigin') && isCrossOrigin(node.src)) {
  19010. crossoriginTracks = true;
  19011. }
  19012. }
  19013. }
  19014. }
  19015. for (var i = 0; i < removeNodes.length; i++) {
  19016. _this.el_.removeChild(removeNodes[i]);
  19017. }
  19018. }
  19019. _this.proxyNativeTracks_();
  19020. if (_this.featuresNativeTextTracks && crossoriginTracks) {
  19021. 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.');
  19022. } // prevent iOS Safari from disabling metadata text tracks during native playback
  19023. _this.restoreMetadataTracksInIOSNativePlayer_(); // Determine if native controls should be used
  19024. // Our goal should be to get the custom controls on mobile solid everywhere
  19025. // so we can remove this all together. Right now this will block custom
  19026. // controls on touch enabled laptops like the Chrome Pixel
  19027. if ((TOUCH_ENABLED || IS_IPHONE || IS_NATIVE_ANDROID) && options.nativeControlsForTouch === true) {
  19028. _this.setControls(true);
  19029. } // on iOS, we want to proxy `webkitbeginfullscreen` and `webkitendfullscreen`
  19030. // into a `fullscreenchange` event
  19031. _this.proxyWebkitFullscreen_();
  19032. _this.triggerReady();
  19033. return _this;
  19034. }
  19035. /**
  19036. * Dispose of `HTML5` media element and remove all tracks.
  19037. */
  19038. var _proto = Html5.prototype;
  19039. _proto.dispose = function dispose() {
  19040. if (this.el_ && this.el_.resetSourceset_) {
  19041. this.el_.resetSourceset_();
  19042. }
  19043. Html5.disposeMediaElement(this.el_);
  19044. this.options_ = null; // tech will handle clearing of the emulated track list
  19045. _Tech.prototype.dispose.call(this);
  19046. }
  19047. /**
  19048. * Modify the media element so that we can detect when
  19049. * the source is changed. Fires `sourceset` just after the source has changed
  19050. */
  19051. ;
  19052. _proto.setupSourcesetHandling_ = function setupSourcesetHandling_() {
  19053. setupSourceset(this);
  19054. }
  19055. /**
  19056. * When a captions track is enabled in the iOS Safari native player, all other
  19057. * tracks are disabled (including metadata tracks), which nulls all of their
  19058. * associated cue points. This will restore metadata tracks to their pre-fullscreen
  19059. * state in those cases so that cue points are not needlessly lost.
  19060. *
  19061. * @private
  19062. */
  19063. ;
  19064. _proto.restoreMetadataTracksInIOSNativePlayer_ = function restoreMetadataTracksInIOSNativePlayer_() {
  19065. var textTracks = this.textTracks();
  19066. var metadataTracksPreFullscreenState; // captures a snapshot of every metadata track's current state
  19067. var takeMetadataTrackSnapshot = function takeMetadataTrackSnapshot() {
  19068. metadataTracksPreFullscreenState = [];
  19069. for (var i = 0; i < textTracks.length; i++) {
  19070. var track = textTracks[i];
  19071. if (track.kind === 'metadata') {
  19072. metadataTracksPreFullscreenState.push({
  19073. track: track,
  19074. storedMode: track.mode
  19075. });
  19076. }
  19077. }
  19078. }; // snapshot each metadata track's initial state, and update the snapshot
  19079. // each time there is a track 'change' event
  19080. takeMetadataTrackSnapshot();
  19081. textTracks.addEventListener('change', takeMetadataTrackSnapshot);
  19082. this.on('dispose', function () {
  19083. return textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  19084. });
  19085. var restoreTrackMode = function restoreTrackMode() {
  19086. for (var i = 0; i < metadataTracksPreFullscreenState.length; i++) {
  19087. var storedTrack = metadataTracksPreFullscreenState[i];
  19088. if (storedTrack.track.mode === 'disabled' && storedTrack.track.mode !== storedTrack.storedMode) {
  19089. storedTrack.track.mode = storedTrack.storedMode;
  19090. }
  19091. } // we only want this handler to be executed on the first 'change' event
  19092. textTracks.removeEventListener('change', restoreTrackMode);
  19093. }; // when we enter fullscreen playback, stop updating the snapshot and
  19094. // restore all track modes to their pre-fullscreen state
  19095. this.on('webkitbeginfullscreen', function () {
  19096. textTracks.removeEventListener('change', takeMetadataTrackSnapshot); // remove the listener before adding it just in case it wasn't previously removed
  19097. textTracks.removeEventListener('change', restoreTrackMode);
  19098. textTracks.addEventListener('change', restoreTrackMode);
  19099. }); // start updating the snapshot again after leaving fullscreen
  19100. this.on('webkitendfullscreen', function () {
  19101. // remove the listener before adding it just in case it wasn't previously removed
  19102. textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  19103. textTracks.addEventListener('change', takeMetadataTrackSnapshot); // remove the restoreTrackMode handler in case it wasn't triggered during fullscreen playback
  19104. textTracks.removeEventListener('change', restoreTrackMode);
  19105. });
  19106. }
  19107. /**
  19108. * Attempt to force override of tracks for the given type
  19109. *
  19110. * @param {string} type - Track type to override, possible values include 'Audio',
  19111. * 'Video', and 'Text'.
  19112. * @param {boolean} override - If set to true native audio/video will be overridden,
  19113. * otherwise native audio/video will potentially be used.
  19114. * @private
  19115. */
  19116. ;
  19117. _proto.overrideNative_ = function overrideNative_(type, override) {
  19118. var _this2 = this;
  19119. // If there is no behavioral change don't add/remove listeners
  19120. if (override !== this["featuresNative" + type + "Tracks"]) {
  19121. return;
  19122. }
  19123. var lowerCaseType = type.toLowerCase();
  19124. if (this[lowerCaseType + "TracksListeners_"]) {
  19125. Object.keys(this[lowerCaseType + "TracksListeners_"]).forEach(function (eventName) {
  19126. var elTracks = _this2.el()[lowerCaseType + "Tracks"];
  19127. elTracks.removeEventListener(eventName, _this2[lowerCaseType + "TracksListeners_"][eventName]);
  19128. });
  19129. }
  19130. this["featuresNative" + type + "Tracks"] = !override;
  19131. this[lowerCaseType + "TracksListeners_"] = null;
  19132. this.proxyNativeTracksForType_(lowerCaseType);
  19133. }
  19134. /**
  19135. * Attempt to force override of native audio tracks.
  19136. *
  19137. * @param {boolean} override - If set to true native audio will be overridden,
  19138. * otherwise native audio will potentially be used.
  19139. */
  19140. ;
  19141. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks(override) {
  19142. this.overrideNative_('Audio', override);
  19143. }
  19144. /**
  19145. * Attempt to force override of native video tracks.
  19146. *
  19147. * @param {boolean} override - If set to true native video will be overridden,
  19148. * otherwise native video will potentially be used.
  19149. */
  19150. ;
  19151. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks(override) {
  19152. this.overrideNative_('Video', override);
  19153. }
  19154. /**
  19155. * Proxy native track list events for the given type to our track
  19156. * lists if the browser we are playing in supports that type of track list.
  19157. *
  19158. * @param {string} name - Track type; values include 'audio', 'video', and 'text'
  19159. * @private
  19160. */
  19161. ;
  19162. _proto.proxyNativeTracksForType_ = function proxyNativeTracksForType_(name) {
  19163. var _this3 = this;
  19164. var props = NORMAL[name];
  19165. var elTracks = this.el()[props.getterName];
  19166. var techTracks = this[props.getterName]();
  19167. if (!this["featuresNative" + props.capitalName + "Tracks"] || !elTracks || !elTracks.addEventListener) {
  19168. return;
  19169. }
  19170. var listeners = {
  19171. change: function change(e) {
  19172. var event = {
  19173. type: 'change',
  19174. target: techTracks,
  19175. currentTarget: techTracks,
  19176. srcElement: techTracks
  19177. };
  19178. techTracks.trigger(event); // if we are a text track change event, we should also notify the
  19179. // remote text track list. This can potentially cause a false positive
  19180. // if we were to get a change event on a non-remote track and
  19181. // we triggered the event on the remote text track list which doesn't
  19182. // contain that track. However, best practices mean looping through the
  19183. // list of tracks and searching for the appropriate mode value, so,
  19184. // this shouldn't pose an issue
  19185. if (name === 'text') {
  19186. _this3[REMOTE.remoteText.getterName]().trigger(event);
  19187. }
  19188. },
  19189. addtrack: function addtrack(e) {
  19190. techTracks.addTrack(e.track);
  19191. },
  19192. removetrack: function removetrack(e) {
  19193. techTracks.removeTrack(e.track);
  19194. }
  19195. };
  19196. var removeOldTracks = function removeOldTracks() {
  19197. var removeTracks = [];
  19198. for (var i = 0; i < techTracks.length; i++) {
  19199. var found = false;
  19200. for (var j = 0; j < elTracks.length; j++) {
  19201. if (elTracks[j] === techTracks[i]) {
  19202. found = true;
  19203. break;
  19204. }
  19205. }
  19206. if (!found) {
  19207. removeTracks.push(techTracks[i]);
  19208. }
  19209. }
  19210. while (removeTracks.length) {
  19211. techTracks.removeTrack(removeTracks.shift());
  19212. }
  19213. };
  19214. this[props.getterName + 'Listeners_'] = listeners;
  19215. Object.keys(listeners).forEach(function (eventName) {
  19216. var listener = listeners[eventName];
  19217. elTracks.addEventListener(eventName, listener);
  19218. _this3.on('dispose', function (e) {
  19219. return elTracks.removeEventListener(eventName, listener);
  19220. });
  19221. }); // Remove (native) tracks that are not used anymore
  19222. this.on('loadstart', removeOldTracks);
  19223. this.on('dispose', function (e) {
  19224. return _this3.off('loadstart', removeOldTracks);
  19225. });
  19226. }
  19227. /**
  19228. * Proxy all native track list events to our track lists if the browser we are playing
  19229. * in supports that type of track list.
  19230. *
  19231. * @private
  19232. */
  19233. ;
  19234. _proto.proxyNativeTracks_ = function proxyNativeTracks_() {
  19235. var _this4 = this;
  19236. NORMAL.names.forEach(function (name) {
  19237. _this4.proxyNativeTracksForType_(name);
  19238. });
  19239. }
  19240. /**
  19241. * Create the `Html5` Tech's DOM element.
  19242. *
  19243. * @return {Element}
  19244. * The element that gets created.
  19245. */
  19246. ;
  19247. _proto.createEl = function createEl() {
  19248. var el = this.options_.tag; // Check if this browser supports moving the element into the box.
  19249. // On the iPhone video will break if you move the element,
  19250. // So we have to create a brand new element.
  19251. // If we ingested the player div, we do not need to move the media element.
  19252. if (!el || !(this.options_.playerElIngest || this.movingMediaElementInDOM)) {
  19253. // If the original tag is still there, clone and remove it.
  19254. if (el) {
  19255. var clone = el.cloneNode(true);
  19256. if (el.parentNode) {
  19257. el.parentNode.insertBefore(clone, el);
  19258. }
  19259. Html5.disposeMediaElement(el);
  19260. el = clone;
  19261. } else {
  19262. el = document.createElement('video'); // determine if native controls should be used
  19263. var tagAttributes = this.options_.tag && getAttributes(this.options_.tag);
  19264. var attributes = mergeOptions({}, tagAttributes);
  19265. if (!TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
  19266. delete attributes.controls;
  19267. }
  19268. setAttributes(el, assign(attributes, {
  19269. id: this.options_.techId,
  19270. "class": 'vjs-tech'
  19271. }));
  19272. }
  19273. el.playerId = this.options_.playerId;
  19274. }
  19275. if (typeof this.options_.preload !== 'undefined') {
  19276. setAttribute(el, 'preload', this.options_.preload);
  19277. }
  19278. if (this.options_.disablePictureInPicture !== undefined) {
  19279. el.disablePictureInPicture = this.options_.disablePictureInPicture;
  19280. } // Update specific tag settings, in case they were overridden
  19281. // `autoplay` has to be *last* so that `muted` and `playsinline` are present
  19282. // when iOS/Safari or other browsers attempt to autoplay.
  19283. var settingsAttrs = ['loop', 'muted', 'playsinline', 'autoplay'];
  19284. for (var i = 0; i < settingsAttrs.length; i++) {
  19285. var attr = settingsAttrs[i];
  19286. var value = this.options_[attr];
  19287. if (typeof value !== 'undefined') {
  19288. if (value) {
  19289. setAttribute(el, attr, attr);
  19290. } else {
  19291. removeAttribute(el, attr);
  19292. }
  19293. el[attr] = value;
  19294. }
  19295. }
  19296. return el;
  19297. }
  19298. /**
  19299. * This will be triggered if the loadstart event has already fired, before videojs was
  19300. * ready. Two known examples of when this can happen are:
  19301. * 1. If we're loading the playback object after it has started loading
  19302. * 2. The media is already playing the (often with autoplay on) then
  19303. *
  19304. * This function will fire another loadstart so that videojs can catchup.
  19305. *
  19306. * @fires Tech#loadstart
  19307. *
  19308. * @return {undefined}
  19309. * returns nothing.
  19310. */
  19311. ;
  19312. _proto.handleLateInit_ = function handleLateInit_(el) {
  19313. if (el.networkState === 0 || el.networkState === 3) {
  19314. // The video element hasn't started loading the source yet
  19315. // or didn't find a source
  19316. return;
  19317. }
  19318. if (el.readyState === 0) {
  19319. // NetworkState is set synchronously BUT loadstart is fired at the
  19320. // end of the current stack, usually before setInterval(fn, 0).
  19321. // So at this point we know loadstart may have already fired or is
  19322. // about to fire, and either way the player hasn't seen it yet.
  19323. // We don't want to fire loadstart prematurely here and cause a
  19324. // double loadstart so we'll wait and see if it happens between now
  19325. // and the next loop, and fire it if not.
  19326. // HOWEVER, we also want to make sure it fires before loadedmetadata
  19327. // which could also happen between now and the next loop, so we'll
  19328. // watch for that also.
  19329. var loadstartFired = false;
  19330. var setLoadstartFired = function setLoadstartFired() {
  19331. loadstartFired = true;
  19332. };
  19333. this.on('loadstart', setLoadstartFired);
  19334. var triggerLoadstart = function triggerLoadstart() {
  19335. // We did miss the original loadstart. Make sure the player
  19336. // sees loadstart before loadedmetadata
  19337. if (!loadstartFired) {
  19338. this.trigger('loadstart');
  19339. }
  19340. };
  19341. this.on('loadedmetadata', triggerLoadstart);
  19342. this.ready(function () {
  19343. this.off('loadstart', setLoadstartFired);
  19344. this.off('loadedmetadata', triggerLoadstart);
  19345. if (!loadstartFired) {
  19346. // We did miss the original native loadstart. Fire it now.
  19347. this.trigger('loadstart');
  19348. }
  19349. });
  19350. return;
  19351. } // From here on we know that loadstart already fired and we missed it.
  19352. // The other readyState events aren't as much of a problem if we double
  19353. // them, so not going to go to as much trouble as loadstart to prevent
  19354. // that unless we find reason to.
  19355. var eventsToTrigger = ['loadstart']; // loadedmetadata: newly equal to HAVE_METADATA (1) or greater
  19356. eventsToTrigger.push('loadedmetadata'); // loadeddata: newly increased to HAVE_CURRENT_DATA (2) or greater
  19357. if (el.readyState >= 2) {
  19358. eventsToTrigger.push('loadeddata');
  19359. } // canplay: newly increased to HAVE_FUTURE_DATA (3) or greater
  19360. if (el.readyState >= 3) {
  19361. eventsToTrigger.push('canplay');
  19362. } // canplaythrough: newly equal to HAVE_ENOUGH_DATA (4)
  19363. if (el.readyState >= 4) {
  19364. eventsToTrigger.push('canplaythrough');
  19365. } // We still need to give the player time to add event listeners
  19366. this.ready(function () {
  19367. eventsToTrigger.forEach(function (type) {
  19368. this.trigger(type);
  19369. }, this);
  19370. });
  19371. }
  19372. /**
  19373. * Set whether we are scrubbing or not.
  19374. * This is used to decide whether we should use `fastSeek` or not.
  19375. * `fastSeek` is used to provide trick play on Safari browsers.
  19376. *
  19377. * @param {boolean} isScrubbing
  19378. * - true for we are currently scrubbing
  19379. * - false for we are no longer scrubbing
  19380. */
  19381. ;
  19382. _proto.setScrubbing = function setScrubbing(isScrubbing) {
  19383. this.isScrubbing_ = isScrubbing;
  19384. }
  19385. /**
  19386. * Get whether we are scrubbing or not.
  19387. *
  19388. * @return {boolean} isScrubbing
  19389. * - true for we are currently scrubbing
  19390. * - false for we are no longer scrubbing
  19391. */
  19392. ;
  19393. _proto.scrubbing = function scrubbing() {
  19394. return this.isScrubbing_;
  19395. }
  19396. /**
  19397. * Set current time for the `HTML5` tech.
  19398. *
  19399. * @param {number} seconds
  19400. * Set the current time of the media to this.
  19401. */
  19402. ;
  19403. _proto.setCurrentTime = function setCurrentTime(seconds) {
  19404. try {
  19405. if (this.isScrubbing_ && this.el_.fastSeek && IS_ANY_SAFARI) {
  19406. this.el_.fastSeek(seconds);
  19407. } else {
  19408. this.el_.currentTime = seconds;
  19409. }
  19410. } catch (e) {
  19411. log(e, 'Video is not ready. (Video.js)'); // this.warning(VideoJS.warnings.videoNotReady);
  19412. }
  19413. }
  19414. /**
  19415. * Get the current duration of the HTML5 media element.
  19416. *
  19417. * @return {number}
  19418. * The duration of the media or 0 if there is no duration.
  19419. */
  19420. ;
  19421. _proto.duration = function duration() {
  19422. var _this5 = this;
  19423. // Android Chrome will report duration as Infinity for VOD HLS until after
  19424. // playback has started, which triggers the live display erroneously.
  19425. // Return NaN if playback has not started and trigger a durationupdate once
  19426. // the duration can be reliably known.
  19427. if (this.el_.duration === Infinity && IS_ANDROID && IS_CHROME && this.el_.currentTime === 0) {
  19428. // Wait for the first `timeupdate` with currentTime > 0 - there may be
  19429. // several with 0
  19430. var checkProgress = function checkProgress() {
  19431. if (_this5.el_.currentTime > 0) {
  19432. // Trigger durationchange for genuinely live video
  19433. if (_this5.el_.duration === Infinity) {
  19434. _this5.trigger('durationchange');
  19435. }
  19436. _this5.off('timeupdate', checkProgress);
  19437. }
  19438. };
  19439. this.on('timeupdate', checkProgress);
  19440. return NaN;
  19441. }
  19442. return this.el_.duration || NaN;
  19443. }
  19444. /**
  19445. * Get the current width of the HTML5 media element.
  19446. *
  19447. * @return {number}
  19448. * The width of the HTML5 media element.
  19449. */
  19450. ;
  19451. _proto.width = function width() {
  19452. return this.el_.offsetWidth;
  19453. }
  19454. /**
  19455. * Get the current height of the HTML5 media element.
  19456. *
  19457. * @return {number}
  19458. * The height of the HTML5 media element.
  19459. */
  19460. ;
  19461. _proto.height = function height() {
  19462. return this.el_.offsetHeight;
  19463. }
  19464. /**
  19465. * Proxy iOS `webkitbeginfullscreen` and `webkitendfullscreen` into
  19466. * `fullscreenchange` event.
  19467. *
  19468. * @private
  19469. * @fires fullscreenchange
  19470. * @listens webkitendfullscreen
  19471. * @listens webkitbeginfullscreen
  19472. * @listens webkitbeginfullscreen
  19473. */
  19474. ;
  19475. _proto.proxyWebkitFullscreen_ = function proxyWebkitFullscreen_() {
  19476. var _this6 = this;
  19477. if (!('webkitDisplayingFullscreen' in this.el_)) {
  19478. return;
  19479. }
  19480. var endFn = function endFn() {
  19481. this.trigger('fullscreenchange', {
  19482. isFullscreen: false
  19483. }); // Safari will sometimes set contols on the videoelement when existing fullscreen.
  19484. if (this.el_.controls && !this.options_.nativeControlsForTouch && this.controls()) {
  19485. this.el_.controls = false;
  19486. }
  19487. };
  19488. var beginFn = function beginFn() {
  19489. if ('webkitPresentationMode' in this.el_ && this.el_.webkitPresentationMode !== 'picture-in-picture') {
  19490. this.one('webkitendfullscreen', endFn);
  19491. this.trigger('fullscreenchange', {
  19492. isFullscreen: true,
  19493. // set a flag in case another tech triggers fullscreenchange
  19494. nativeIOSFullscreen: true
  19495. });
  19496. }
  19497. };
  19498. this.on('webkitbeginfullscreen', beginFn);
  19499. this.on('dispose', function () {
  19500. _this6.off('webkitbeginfullscreen', beginFn);
  19501. _this6.off('webkitendfullscreen', endFn);
  19502. });
  19503. }
  19504. /**
  19505. * Check if fullscreen is supported on the current playback device.
  19506. *
  19507. * @return {boolean}
  19508. * - True if fullscreen is supported.
  19509. * - False if fullscreen is not supported.
  19510. */
  19511. ;
  19512. _proto.supportsFullScreen = function supportsFullScreen() {
  19513. if (typeof this.el_.webkitEnterFullScreen === 'function') {
  19514. var userAgent = window.navigator && window.navigator.userAgent || ''; // Seems to be broken in Chromium/Chrome && Safari in Leopard
  19515. if (/Android/.test(userAgent) || !/Chrome|Mac OS X 10.5/.test(userAgent)) {
  19516. return true;
  19517. }
  19518. }
  19519. return false;
  19520. }
  19521. /**
  19522. * Request that the `HTML5` Tech enter fullscreen.
  19523. */
  19524. ;
  19525. _proto.enterFullScreen = function enterFullScreen() {
  19526. var video = this.el_;
  19527. if (video.paused && video.networkState <= video.HAVE_METADATA) {
  19528. // attempt to prime the video element for programmatic access
  19529. // this isn't necessary on the desktop but shouldn't hurt
  19530. silencePromise(this.el_.play()); // playing and pausing synchronously during the transition to fullscreen
  19531. // can get iOS ~6.1 devices into a play/pause loop
  19532. this.setTimeout(function () {
  19533. video.pause();
  19534. try {
  19535. video.webkitEnterFullScreen();
  19536. } catch (e) {
  19537. this.trigger('fullscreenerror', e);
  19538. }
  19539. }, 0);
  19540. } else {
  19541. try {
  19542. video.webkitEnterFullScreen();
  19543. } catch (e) {
  19544. this.trigger('fullscreenerror', e);
  19545. }
  19546. }
  19547. }
  19548. /**
  19549. * Request that the `HTML5` Tech exit fullscreen.
  19550. */
  19551. ;
  19552. _proto.exitFullScreen = function exitFullScreen() {
  19553. if (!this.el_.webkitDisplayingFullscreen) {
  19554. this.trigger('fullscreenerror', new Error('The video is not fullscreen'));
  19555. return;
  19556. }
  19557. this.el_.webkitExitFullScreen();
  19558. }
  19559. /**
  19560. * Create a floating video window always on top of other windows so that users may
  19561. * continue consuming media while they interact with other content sites, or
  19562. * applications on their device.
  19563. *
  19564. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  19565. *
  19566. * @return {Promise}
  19567. * A promise with a Picture-in-Picture window.
  19568. */
  19569. ;
  19570. _proto.requestPictureInPicture = function requestPictureInPicture() {
  19571. return this.el_.requestPictureInPicture();
  19572. }
  19573. /**
  19574. * Native requestVideoFrameCallback if supported by browser/tech, or fallback
  19575. * Don't use rVCF on Safari when DRM is playing, as it doesn't fire
  19576. * Needs to be checked later than the constructor
  19577. * This will be a false positive for clear sources loaded after a Fairplay source
  19578. *
  19579. * @param {function} cb function to call
  19580. * @return {number} id of request
  19581. */
  19582. ;
  19583. _proto.requestVideoFrameCallback = function requestVideoFrameCallback(cb) {
  19584. if (this.featuresVideoFrameCallback && !this.el_.webkitKeys) {
  19585. return this.el_.requestVideoFrameCallback(cb);
  19586. }
  19587. return _Tech.prototype.requestVideoFrameCallback.call(this, cb);
  19588. }
  19589. /**
  19590. * Native or fallback requestVideoFrameCallback
  19591. *
  19592. * @param {number} id request id to cancel
  19593. */
  19594. ;
  19595. _proto.cancelVideoFrameCallback = function cancelVideoFrameCallback(id) {
  19596. if (this.featuresVideoFrameCallback && !this.el_.webkitKeys) {
  19597. this.el_.cancelVideoFrameCallback(id);
  19598. } else {
  19599. _Tech.prototype.cancelVideoFrameCallback.call(this, id);
  19600. }
  19601. }
  19602. /**
  19603. * A getter/setter for the `Html5` Tech's source object.
  19604. * > Note: Please use {@link Html5#setSource}
  19605. *
  19606. * @param {Tech~SourceObject} [src]
  19607. * The source object you want to set on the `HTML5` techs element.
  19608. *
  19609. * @return {Tech~SourceObject|undefined}
  19610. * - The current source object when a source is not passed in.
  19611. * - undefined when setting
  19612. *
  19613. * @deprecated Since version 5.
  19614. */
  19615. ;
  19616. _proto.src = function src(_src) {
  19617. if (_src === undefined) {
  19618. return this.el_.src;
  19619. } // Setting src through `src` instead of `setSrc` will be deprecated
  19620. this.setSrc(_src);
  19621. }
  19622. /**
  19623. * Reset the tech by removing all sources and then calling
  19624. * {@link Html5.resetMediaElement}.
  19625. */
  19626. ;
  19627. _proto.reset = function reset() {
  19628. Html5.resetMediaElement(this.el_);
  19629. }
  19630. /**
  19631. * Get the current source on the `HTML5` Tech. Falls back to returning the source from
  19632. * the HTML5 media element.
  19633. *
  19634. * @return {Tech~SourceObject}
  19635. * The current source object from the HTML5 tech. With a fallback to the
  19636. * elements source.
  19637. */
  19638. ;
  19639. _proto.currentSrc = function currentSrc() {
  19640. if (this.currentSource_) {
  19641. return this.currentSource_.src;
  19642. }
  19643. return this.el_.currentSrc;
  19644. }
  19645. /**
  19646. * Set controls attribute for the HTML5 media Element.
  19647. *
  19648. * @param {string} val
  19649. * Value to set the controls attribute to
  19650. */
  19651. ;
  19652. _proto.setControls = function setControls(val) {
  19653. this.el_.controls = !!val;
  19654. }
  19655. /**
  19656. * Create and returns a remote {@link TextTrack} object.
  19657. *
  19658. * @param {string} kind
  19659. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  19660. *
  19661. * @param {string} [label]
  19662. * Label to identify the text track
  19663. *
  19664. * @param {string} [language]
  19665. * Two letter language abbreviation
  19666. *
  19667. * @return {TextTrack}
  19668. * The TextTrack that gets created.
  19669. */
  19670. ;
  19671. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  19672. if (!this.featuresNativeTextTracks) {
  19673. return _Tech.prototype.addTextTrack.call(this, kind, label, language);
  19674. }
  19675. return this.el_.addTextTrack(kind, label, language);
  19676. }
  19677. /**
  19678. * Creates either native TextTrack or an emulated TextTrack depending
  19679. * on the value of `featuresNativeTextTracks`
  19680. *
  19681. * @param {Object} options
  19682. * The object should contain the options to initialize the TextTrack with.
  19683. *
  19684. * @param {string} [options.kind]
  19685. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  19686. *
  19687. * @param {string} [options.label]
  19688. * Label to identify the text track
  19689. *
  19690. * @param {string} [options.language]
  19691. * Two letter language abbreviation.
  19692. *
  19693. * @param {boolean} [options.default]
  19694. * Default this track to on.
  19695. *
  19696. * @param {string} [options.id]
  19697. * The internal id to assign this track.
  19698. *
  19699. * @param {string} [options.src]
  19700. * A source url for the track.
  19701. *
  19702. * @return {HTMLTrackElement}
  19703. * The track element that gets created.
  19704. */
  19705. ;
  19706. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  19707. if (!this.featuresNativeTextTracks) {
  19708. return _Tech.prototype.createRemoteTextTrack.call(this, options);
  19709. }
  19710. var htmlTrackElement = document.createElement('track');
  19711. if (options.kind) {
  19712. htmlTrackElement.kind = options.kind;
  19713. }
  19714. if (options.label) {
  19715. htmlTrackElement.label = options.label;
  19716. }
  19717. if (options.language || options.srclang) {
  19718. htmlTrackElement.srclang = options.language || options.srclang;
  19719. }
  19720. if (options["default"]) {
  19721. htmlTrackElement["default"] = options["default"];
  19722. }
  19723. if (options.id) {
  19724. htmlTrackElement.id = options.id;
  19725. }
  19726. if (options.src) {
  19727. htmlTrackElement.src = options.src;
  19728. }
  19729. return htmlTrackElement;
  19730. }
  19731. /**
  19732. * Creates a remote text track object and returns an html track element.
  19733. *
  19734. * @param {Object} options The object should contain values for
  19735. * kind, language, label, and src (location of the WebVTT file)
  19736. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  19737. * automatically removed from the video element whenever the source changes
  19738. * @return {HTMLTrackElement} An Html Track Element.
  19739. * This can be an emulated {@link HTMLTrackElement} or a native one.
  19740. * @deprecated The default value of the "manualCleanup" parameter will default
  19741. * to "false" in upcoming versions of Video.js
  19742. */
  19743. ;
  19744. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  19745. var htmlTrackElement = _Tech.prototype.addRemoteTextTrack.call(this, options, manualCleanup);
  19746. if (this.featuresNativeTextTracks) {
  19747. this.el().appendChild(htmlTrackElement);
  19748. }
  19749. return htmlTrackElement;
  19750. }
  19751. /**
  19752. * Remove remote `TextTrack` from `TextTrackList` object
  19753. *
  19754. * @param {TextTrack} track
  19755. * `TextTrack` object to remove
  19756. */
  19757. ;
  19758. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  19759. _Tech.prototype.removeRemoteTextTrack.call(this, track);
  19760. if (this.featuresNativeTextTracks) {
  19761. var tracks = this.$$('track');
  19762. var i = tracks.length;
  19763. while (i--) {
  19764. if (track === tracks[i] || track === tracks[i].track) {
  19765. this.el().removeChild(tracks[i]);
  19766. }
  19767. }
  19768. }
  19769. }
  19770. /**
  19771. * Gets available media playback quality metrics as specified by the W3C's Media
  19772. * Playback Quality API.
  19773. *
  19774. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  19775. *
  19776. * @return {Object}
  19777. * An object with supported media playback quality metrics
  19778. */
  19779. ;
  19780. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  19781. if (typeof this.el().getVideoPlaybackQuality === 'function') {
  19782. return this.el().getVideoPlaybackQuality();
  19783. }
  19784. var videoPlaybackQuality = {};
  19785. if (typeof this.el().webkitDroppedFrameCount !== 'undefined' && typeof this.el().webkitDecodedFrameCount !== 'undefined') {
  19786. videoPlaybackQuality.droppedVideoFrames = this.el().webkitDroppedFrameCount;
  19787. videoPlaybackQuality.totalVideoFrames = this.el().webkitDecodedFrameCount;
  19788. }
  19789. if (window.performance && typeof window.performance.now === 'function') {
  19790. videoPlaybackQuality.creationTime = window.performance.now();
  19791. } else if (window.performance && window.performance.timing && typeof window.performance.timing.navigationStart === 'number') {
  19792. videoPlaybackQuality.creationTime = window.Date.now() - window.performance.timing.navigationStart;
  19793. }
  19794. return videoPlaybackQuality;
  19795. };
  19796. return Html5;
  19797. }(Tech);
  19798. /* HTML5 Support Testing ---------------------------------------------------- */
  19799. /**
  19800. * Element for testing browser HTML5 media capabilities
  19801. *
  19802. * @type {Element}
  19803. * @constant
  19804. * @private
  19805. */
  19806. defineLazyProperty(Html5, 'TEST_VID', function () {
  19807. if (!isReal()) {
  19808. return;
  19809. }
  19810. var video = document.createElement('video');
  19811. var track = document.createElement('track');
  19812. track.kind = 'captions';
  19813. track.srclang = 'en';
  19814. track.label = 'English';
  19815. video.appendChild(track);
  19816. return video;
  19817. });
  19818. /**
  19819. * Check if HTML5 media is supported by this browser/device.
  19820. *
  19821. * @return {boolean}
  19822. * - True if HTML5 media is supported.
  19823. * - False if HTML5 media is not supported.
  19824. */
  19825. Html5.isSupported = function () {
  19826. // IE with no Media Player is a LIAR! (#984)
  19827. try {
  19828. Html5.TEST_VID.volume = 0.5;
  19829. } catch (e) {
  19830. return false;
  19831. }
  19832. return !!(Html5.TEST_VID && Html5.TEST_VID.canPlayType);
  19833. };
  19834. /**
  19835. * Check if the tech can support the given type
  19836. *
  19837. * @param {string} type
  19838. * The mimetype to check
  19839. * @return {string} 'probably', 'maybe', or '' (empty string)
  19840. */
  19841. Html5.canPlayType = function (type) {
  19842. return Html5.TEST_VID.canPlayType(type);
  19843. };
  19844. /**
  19845. * Check if the tech can support the given source
  19846. *
  19847. * @param {Object} srcObj
  19848. * The source object
  19849. * @param {Object} options
  19850. * The options passed to the tech
  19851. * @return {string} 'probably', 'maybe', or '' (empty string)
  19852. */
  19853. Html5.canPlaySource = function (srcObj, options) {
  19854. return Html5.canPlayType(srcObj.type);
  19855. };
  19856. /**
  19857. * Check if the volume can be changed in this browser/device.
  19858. * Volume cannot be changed in a lot of mobile devices.
  19859. * Specifically, it can't be changed from 1 on iOS.
  19860. *
  19861. * @return {boolean}
  19862. * - True if volume can be controlled
  19863. * - False otherwise
  19864. */
  19865. Html5.canControlVolume = function () {
  19866. // IE will error if Windows Media Player not installed #3315
  19867. try {
  19868. var volume = Html5.TEST_VID.volume;
  19869. Html5.TEST_VID.volume = volume / 2 + 0.1;
  19870. var canControl = volume !== Html5.TEST_VID.volume; // With the introduction of iOS 15, there are cases where the volume is read as
  19871. // changed but reverts back to its original state at the start of the next tick.
  19872. // To determine whether volume can be controlled on iOS,
  19873. // a timeout is set and the volume is checked asynchronously.
  19874. // Since `features` doesn't currently work asynchronously, the value is manually set.
  19875. if (canControl && IS_IOS) {
  19876. window.setTimeout(function () {
  19877. if (Html5 && Html5.prototype) {
  19878. Html5.prototype.featuresVolumeControl = volume !== Html5.TEST_VID.volume;
  19879. }
  19880. }); // default iOS to false, which will be updated in the timeout above.
  19881. return false;
  19882. }
  19883. return canControl;
  19884. } catch (e) {
  19885. return false;
  19886. }
  19887. };
  19888. /**
  19889. * Check if the volume can be muted in this browser/device.
  19890. * Some devices, e.g. iOS, don't allow changing volume
  19891. * but permits muting/unmuting.
  19892. *
  19893. * @return {bolean}
  19894. * - True if volume can be muted
  19895. * - False otherwise
  19896. */
  19897. Html5.canMuteVolume = function () {
  19898. try {
  19899. var muted = Html5.TEST_VID.muted; // in some versions of iOS muted property doesn't always
  19900. // work, so we want to set both property and attribute
  19901. Html5.TEST_VID.muted = !muted;
  19902. if (Html5.TEST_VID.muted) {
  19903. setAttribute(Html5.TEST_VID, 'muted', 'muted');
  19904. } else {
  19905. removeAttribute(Html5.TEST_VID, 'muted', 'muted');
  19906. }
  19907. return muted !== Html5.TEST_VID.muted;
  19908. } catch (e) {
  19909. return false;
  19910. }
  19911. };
  19912. /**
  19913. * Check if the playback rate can be changed in this browser/device.
  19914. *
  19915. * @return {boolean}
  19916. * - True if playback rate can be controlled
  19917. * - False otherwise
  19918. */
  19919. Html5.canControlPlaybackRate = function () {
  19920. // Playback rate API is implemented in Android Chrome, but doesn't do anything
  19921. // https://github.com/videojs/video.js/issues/3180
  19922. if (IS_ANDROID && IS_CHROME && CHROME_VERSION < 58) {
  19923. return false;
  19924. } // IE will error if Windows Media Player not installed #3315
  19925. try {
  19926. var playbackRate = Html5.TEST_VID.playbackRate;
  19927. Html5.TEST_VID.playbackRate = playbackRate / 2 + 0.1;
  19928. return playbackRate !== Html5.TEST_VID.playbackRate;
  19929. } catch (e) {
  19930. return false;
  19931. }
  19932. };
  19933. /**
  19934. * Check if we can override a video/audio elements attributes, with
  19935. * Object.defineProperty.
  19936. *
  19937. * @return {boolean}
  19938. * - True if builtin attributes can be overridden
  19939. * - False otherwise
  19940. */
  19941. Html5.canOverrideAttributes = function () {
  19942. // if we cannot overwrite the src/innerHTML property, there is no support
  19943. // iOS 7 safari for instance cannot do this.
  19944. try {
  19945. var noop = function noop() {};
  19946. Object.defineProperty(document.createElement('video'), 'src', {
  19947. get: noop,
  19948. set: noop
  19949. });
  19950. Object.defineProperty(document.createElement('audio'), 'src', {
  19951. get: noop,
  19952. set: noop
  19953. });
  19954. Object.defineProperty(document.createElement('video'), 'innerHTML', {
  19955. get: noop,
  19956. set: noop
  19957. });
  19958. Object.defineProperty(document.createElement('audio'), 'innerHTML', {
  19959. get: noop,
  19960. set: noop
  19961. });
  19962. } catch (e) {
  19963. return false;
  19964. }
  19965. return true;
  19966. };
  19967. /**
  19968. * Check to see if native `TextTrack`s are supported by this browser/device.
  19969. *
  19970. * @return {boolean}
  19971. * - True if native `TextTrack`s are supported.
  19972. * - False otherwise
  19973. */
  19974. Html5.supportsNativeTextTracks = function () {
  19975. return IS_ANY_SAFARI || IS_IOS && IS_CHROME;
  19976. };
  19977. /**
  19978. * Check to see if native `VideoTrack`s are supported by this browser/device
  19979. *
  19980. * @return {boolean}
  19981. * - True if native `VideoTrack`s are supported.
  19982. * - False otherwise
  19983. */
  19984. Html5.supportsNativeVideoTracks = function () {
  19985. return !!(Html5.TEST_VID && Html5.TEST_VID.videoTracks);
  19986. };
  19987. /**
  19988. * Check to see if native `AudioTrack`s are supported by this browser/device
  19989. *
  19990. * @return {boolean}
  19991. * - True if native `AudioTrack`s are supported.
  19992. * - False otherwise
  19993. */
  19994. Html5.supportsNativeAudioTracks = function () {
  19995. return !!(Html5.TEST_VID && Html5.TEST_VID.audioTracks);
  19996. };
  19997. /**
  19998. * An array of events available on the Html5 tech.
  19999. *
  20000. * @private
  20001. * @type {Array}
  20002. */
  20003. 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'];
  20004. /**
  20005. * Boolean indicating whether the `Tech` supports volume control.
  20006. *
  20007. * @type {boolean}
  20008. * @default {@link Html5.canControlVolume}
  20009. */
  20010. /**
  20011. * Boolean indicating whether the `Tech` supports muting volume.
  20012. *
  20013. * @type {bolean}
  20014. * @default {@link Html5.canMuteVolume}
  20015. */
  20016. /**
  20017. * Boolean indicating whether the `Tech` supports changing the speed at which the media
  20018. * plays. Examples:
  20019. * - Set player to play 2x (twice) as fast
  20020. * - Set player to play 0.5x (half) as fast
  20021. *
  20022. * @type {boolean}
  20023. * @default {@link Html5.canControlPlaybackRate}
  20024. */
  20025. /**
  20026. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  20027. *
  20028. * @type {boolean}
  20029. * @default
  20030. */
  20031. /**
  20032. * Boolean indicating whether the `HTML5` tech currently supports native `TextTrack`s.
  20033. *
  20034. * @type {boolean}
  20035. * @default {@link Html5.supportsNativeTextTracks}
  20036. */
  20037. /**
  20038. * Boolean indicating whether the `HTML5` tech currently supports native `VideoTrack`s.
  20039. *
  20040. * @type {boolean}
  20041. * @default {@link Html5.supportsNativeVideoTracks}
  20042. */
  20043. /**
  20044. * Boolean indicating whether the `HTML5` tech currently supports native `AudioTrack`s.
  20045. *
  20046. * @type {boolean}
  20047. * @default {@link Html5.supportsNativeAudioTracks}
  20048. */
  20049. [['featuresMuteControl', 'canMuteVolume'], ['featuresPlaybackRate', 'canControlPlaybackRate'], ['featuresSourceset', 'canOverrideAttributes'], ['featuresNativeTextTracks', 'supportsNativeTextTracks'], ['featuresNativeVideoTracks', 'supportsNativeVideoTracks'], ['featuresNativeAudioTracks', 'supportsNativeAudioTracks']].forEach(function (_ref) {
  20050. var key = _ref[0],
  20051. fn = _ref[1];
  20052. defineLazyProperty(Html5.prototype, key, function () {
  20053. return Html5[fn]();
  20054. }, true);
  20055. });
  20056. Html5.prototype.featuresVolumeControl = Html5.canControlVolume();
  20057. /**
  20058. * Boolean indicating whether the `HTML5` tech currently supports the media element
  20059. * moving in the DOM. iOS breaks if you move the media element, so this is set this to
  20060. * false there. Everywhere else this should be true.
  20061. *
  20062. * @type {boolean}
  20063. * @default
  20064. */
  20065. Html5.prototype.movingMediaElementInDOM = !IS_IOS; // TODO: Previous comment: No longer appears to be used. Can probably be removed.
  20066. // Is this true?
  20067. /**
  20068. * Boolean indicating whether the `HTML5` tech currently supports automatic media resize
  20069. * when going into fullscreen.
  20070. *
  20071. * @type {boolean}
  20072. * @default
  20073. */
  20074. Html5.prototype.featuresFullscreenResize = true;
  20075. /**
  20076. * Boolean indicating whether the `HTML5` tech currently supports the progress event.
  20077. * If this is false, manual `progress` events will be triggered instead.
  20078. *
  20079. * @type {boolean}
  20080. * @default
  20081. */
  20082. Html5.prototype.featuresProgressEvents = true;
  20083. /**
  20084. * Boolean indicating whether the `HTML5` tech currently supports the timeupdate event.
  20085. * If this is false, manual `timeupdate` events will be triggered instead.
  20086. *
  20087. * @default
  20088. */
  20089. Html5.prototype.featuresTimeupdateEvents = true;
  20090. /**
  20091. * Whether the HTML5 el supports `requestVideoFrameCallback`
  20092. *
  20093. * @type {boolean}
  20094. */
  20095. Html5.prototype.featuresVideoFrameCallback = !!(Html5.TEST_VID && Html5.TEST_VID.requestVideoFrameCallback); // HTML5 Feature detection and Device Fixes --------------------------------- //
  20096. var canPlayType;
  20097. Html5.patchCanPlayType = function () {
  20098. // Android 4.0 and above can play HLS to some extent but it reports being unable to do so
  20099. // Firefox and Chrome report correctly
  20100. if (ANDROID_VERSION >= 4.0 && !IS_FIREFOX && !IS_CHROME) {
  20101. canPlayType = Html5.TEST_VID && Html5.TEST_VID.constructor.prototype.canPlayType;
  20102. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  20103. var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
  20104. if (type && mpegurlRE.test(type)) {
  20105. return 'maybe';
  20106. }
  20107. return canPlayType.call(this, type);
  20108. };
  20109. }
  20110. };
  20111. Html5.unpatchCanPlayType = function () {
  20112. var r = Html5.TEST_VID.constructor.prototype.canPlayType;
  20113. if (canPlayType) {
  20114. Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
  20115. }
  20116. return r;
  20117. }; // by default, patch the media element
  20118. Html5.patchCanPlayType();
  20119. Html5.disposeMediaElement = function (el) {
  20120. if (!el) {
  20121. return;
  20122. }
  20123. if (el.parentNode) {
  20124. el.parentNode.removeChild(el);
  20125. } // remove any child track or source nodes to prevent their loading
  20126. while (el.hasChildNodes()) {
  20127. el.removeChild(el.firstChild);
  20128. } // remove any src reference. not setting `src=''` because that causes a warning
  20129. // in firefox
  20130. el.removeAttribute('src'); // force the media element to update its loading state by calling load()
  20131. // however IE on Windows 7N has a bug that throws an error so need a try/catch (#793)
  20132. if (typeof el.load === 'function') {
  20133. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  20134. (function () {
  20135. try {
  20136. el.load();
  20137. } catch (e) {// not supported
  20138. }
  20139. })();
  20140. }
  20141. };
  20142. Html5.resetMediaElement = function (el) {
  20143. if (!el) {
  20144. return;
  20145. }
  20146. var sources = el.querySelectorAll('source');
  20147. var i = sources.length;
  20148. while (i--) {
  20149. el.removeChild(sources[i]);
  20150. } // remove any src reference.
  20151. // not setting `src=''` because that throws an error
  20152. el.removeAttribute('src');
  20153. if (typeof el.load === 'function') {
  20154. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  20155. (function () {
  20156. try {
  20157. el.load();
  20158. } catch (e) {// satisfy linter
  20159. }
  20160. })();
  20161. }
  20162. };
  20163. /* Native HTML5 element property wrapping ----------------------------------- */
  20164. // Wrap native boolean attributes with getters that check both property and attribute
  20165. // The list is as followed:
  20166. // muted, defaultMuted, autoplay, controls, loop, playsinline
  20167. [
  20168. /**
  20169. * Get the value of `muted` from the media element. `muted` indicates
  20170. * that the volume for the media should be set to silent. This does not actually change
  20171. * the `volume` attribute.
  20172. *
  20173. * @method Html5#muted
  20174. * @return {boolean}
  20175. * - True if the value of `volume` should be ignored and the audio set to silent.
  20176. * - False if the value of `volume` should be used.
  20177. *
  20178. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  20179. */
  20180. 'muted',
  20181. /**
  20182. * Get the value of `defaultMuted` from the media element. `defaultMuted` indicates
  20183. * whether the media should start muted or not. Only changes the default state of the
  20184. * media. `muted` and `defaultMuted` can have different values. {@link Html5#muted} indicates the
  20185. * current state.
  20186. *
  20187. * @method Html5#defaultMuted
  20188. * @return {boolean}
  20189. * - The value of `defaultMuted` from the media element.
  20190. * - True indicates that the media should start muted.
  20191. * - False indicates that the media should not start muted
  20192. *
  20193. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  20194. */
  20195. 'defaultMuted',
  20196. /**
  20197. * Get the value of `autoplay` from the media element. `autoplay` indicates
  20198. * that the media should start to play as soon as the page is ready.
  20199. *
  20200. * @method Html5#autoplay
  20201. * @return {boolean}
  20202. * - The value of `autoplay` from the media element.
  20203. * - True indicates that the media should start as soon as the page loads.
  20204. * - False indicates that the media should not start as soon as the page loads.
  20205. *
  20206. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  20207. */
  20208. 'autoplay',
  20209. /**
  20210. * Get the value of `controls` from the media element. `controls` indicates
  20211. * whether the native media controls should be shown or hidden.
  20212. *
  20213. * @method Html5#controls
  20214. * @return {boolean}
  20215. * - The value of `controls` from the media element.
  20216. * - True indicates that native controls should be showing.
  20217. * - False indicates that native controls should be hidden.
  20218. *
  20219. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-controls}
  20220. */
  20221. 'controls',
  20222. /**
  20223. * Get the value of `loop` from the media element. `loop` indicates
  20224. * that the media should return to the start of the media and continue playing once
  20225. * it reaches the end.
  20226. *
  20227. * @method Html5#loop
  20228. * @return {boolean}
  20229. * - The value of `loop` from the media element.
  20230. * - True indicates that playback should seek back to start once
  20231. * the end of a media is reached.
  20232. * - False indicates that playback should not loop back to the start when the
  20233. * end of the media is reached.
  20234. *
  20235. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  20236. */
  20237. 'loop',
  20238. /**
  20239. * Get the value of `playsinline` from the media element. `playsinline` indicates
  20240. * to the browser that non-fullscreen playback is preferred when fullscreen
  20241. * playback is the native default, such as in iOS Safari.
  20242. *
  20243. * @method Html5#playsinline
  20244. * @return {boolean}
  20245. * - The value of `playsinline` from the media element.
  20246. * - True indicates that the media should play inline.
  20247. * - False indicates that the media should not play inline.
  20248. *
  20249. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  20250. */
  20251. 'playsinline'].forEach(function (prop) {
  20252. Html5.prototype[prop] = function () {
  20253. return this.el_[prop] || this.el_.hasAttribute(prop);
  20254. };
  20255. }); // Wrap native boolean attributes with setters that set both property and attribute
  20256. // The list is as followed:
  20257. // setMuted, setDefaultMuted, setAutoplay, setLoop, setPlaysinline
  20258. // setControls is special-cased above
  20259. [
  20260. /**
  20261. * Set the value of `muted` on the media element. `muted` indicates that the current
  20262. * audio level should be silent.
  20263. *
  20264. * @method Html5#setMuted
  20265. * @param {boolean} muted
  20266. * - True if the audio should be set to silent
  20267. * - False otherwise
  20268. *
  20269. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  20270. */
  20271. 'muted',
  20272. /**
  20273. * Set the value of `defaultMuted` on the media element. `defaultMuted` indicates that the current
  20274. * audio level should be silent, but will only effect the muted level on initial playback..
  20275. *
  20276. * @method Html5.prototype.setDefaultMuted
  20277. * @param {boolean} defaultMuted
  20278. * - True if the audio should be set to silent
  20279. * - False otherwise
  20280. *
  20281. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  20282. */
  20283. 'defaultMuted',
  20284. /**
  20285. * Set the value of `autoplay` on the media element. `autoplay` indicates
  20286. * that the media should start to play as soon as the page is ready.
  20287. *
  20288. * @method Html5#setAutoplay
  20289. * @param {boolean} autoplay
  20290. * - True indicates that the media should start as soon as the page loads.
  20291. * - False indicates that the media should not start as soon as the page loads.
  20292. *
  20293. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  20294. */
  20295. 'autoplay',
  20296. /**
  20297. * Set the value of `loop` on the media element. `loop` indicates
  20298. * that the media should return to the start of the media and continue playing once
  20299. * it reaches the end.
  20300. *
  20301. * @method Html5#setLoop
  20302. * @param {boolean} loop
  20303. * - True indicates that playback should seek back to start once
  20304. * the end of a media is reached.
  20305. * - False indicates that playback should not loop back to the start when the
  20306. * end of the media is reached.
  20307. *
  20308. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  20309. */
  20310. 'loop',
  20311. /**
  20312. * Set the value of `playsinline` from the media element. `playsinline` indicates
  20313. * to the browser that non-fullscreen playback is preferred when fullscreen
  20314. * playback is the native default, such as in iOS Safari.
  20315. *
  20316. * @method Html5#setPlaysinline
  20317. * @param {boolean} playsinline
  20318. * - True indicates that the media should play inline.
  20319. * - False indicates that the media should not play inline.
  20320. *
  20321. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  20322. */
  20323. 'playsinline'].forEach(function (prop) {
  20324. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  20325. this.el_[prop] = v;
  20326. if (v) {
  20327. this.el_.setAttribute(prop, prop);
  20328. } else {
  20329. this.el_.removeAttribute(prop);
  20330. }
  20331. };
  20332. }); // Wrap native properties with a getter
  20333. // The list is as followed
  20334. // paused, currentTime, buffered, volume, poster, preload, error, seeking
  20335. // seekable, ended, playbackRate, defaultPlaybackRate, disablePictureInPicture
  20336. // played, networkState, readyState, videoWidth, videoHeight, crossOrigin
  20337. [
  20338. /**
  20339. * Get the value of `paused` from the media element. `paused` indicates whether the media element
  20340. * is currently paused or not.
  20341. *
  20342. * @method Html5#paused
  20343. * @return {boolean}
  20344. * The value of `paused` from the media element.
  20345. *
  20346. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-paused}
  20347. */
  20348. 'paused',
  20349. /**
  20350. * Get the value of `currentTime` from the media element. `currentTime` indicates
  20351. * the current second that the media is at in playback.
  20352. *
  20353. * @method Html5#currentTime
  20354. * @return {number}
  20355. * The value of `currentTime` from the media element.
  20356. *
  20357. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-currenttime}
  20358. */
  20359. 'currentTime',
  20360. /**
  20361. * Get the value of `buffered` from the media element. `buffered` is a `TimeRange`
  20362. * object that represents the parts of the media that are already downloaded and
  20363. * available for playback.
  20364. *
  20365. * @method Html5#buffered
  20366. * @return {TimeRange}
  20367. * The value of `buffered` from the media element.
  20368. *
  20369. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-buffered}
  20370. */
  20371. 'buffered',
  20372. /**
  20373. * Get the value of `volume` from the media element. `volume` indicates
  20374. * the current playback volume of audio for a media. `volume` will be a value from 0
  20375. * (silent) to 1 (loudest and default).
  20376. *
  20377. * @method Html5#volume
  20378. * @return {number}
  20379. * The value of `volume` from the media element. Value will be between 0-1.
  20380. *
  20381. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  20382. */
  20383. 'volume',
  20384. /**
  20385. * Get the value of `poster` from the media element. `poster` indicates
  20386. * that the url of an image file that can/will be shown when no media data is available.
  20387. *
  20388. * @method Html5#poster
  20389. * @return {string}
  20390. * The value of `poster` from the media element. Value will be a url to an
  20391. * image.
  20392. *
  20393. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster}
  20394. */
  20395. 'poster',
  20396. /**
  20397. * Get the value of `preload` from the media element. `preload` indicates
  20398. * what should download before the media is interacted with. It can have the following
  20399. * values:
  20400. * - none: nothing should be downloaded
  20401. * - metadata: poster and the first few frames of the media may be downloaded to get
  20402. * media dimensions and other metadata
  20403. * - auto: allow the media and metadata for the media to be downloaded before
  20404. * interaction
  20405. *
  20406. * @method Html5#preload
  20407. * @return {string}
  20408. * The value of `preload` from the media element. Will be 'none', 'metadata',
  20409. * or 'auto'.
  20410. *
  20411. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  20412. */
  20413. 'preload',
  20414. /**
  20415. * Get the value of the `error` from the media element. `error` indicates any
  20416. * MediaError that may have occurred during playback. If error returns null there is no
  20417. * current error.
  20418. *
  20419. * @method Html5#error
  20420. * @return {MediaError|null}
  20421. * The value of `error` from the media element. Will be `MediaError` if there
  20422. * is a current error and null otherwise.
  20423. *
  20424. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-error}
  20425. */
  20426. 'error',
  20427. /**
  20428. * Get the value of `seeking` from the media element. `seeking` indicates whether the
  20429. * media is currently seeking to a new position or not.
  20430. *
  20431. * @method Html5#seeking
  20432. * @return {boolean}
  20433. * - The value of `seeking` from the media element.
  20434. * - True indicates that the media is currently seeking to a new position.
  20435. * - False indicates that the media is not seeking to a new position at this time.
  20436. *
  20437. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seeking}
  20438. */
  20439. 'seeking',
  20440. /**
  20441. * Get the value of `seekable` from the media element. `seekable` returns a
  20442. * `TimeRange` object indicating ranges of time that can currently be `seeked` to.
  20443. *
  20444. * @method Html5#seekable
  20445. * @return {TimeRange}
  20446. * The value of `seekable` from the media element. A `TimeRange` object
  20447. * indicating the current ranges of time that can be seeked to.
  20448. *
  20449. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seekable}
  20450. */
  20451. 'seekable',
  20452. /**
  20453. * Get the value of `ended` from the media element. `ended` indicates whether
  20454. * the media has reached the end or not.
  20455. *
  20456. * @method Html5#ended
  20457. * @return {boolean}
  20458. * - The value of `ended` from the media element.
  20459. * - True indicates that the media has ended.
  20460. * - False indicates that the media has not ended.
  20461. *
  20462. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
  20463. */
  20464. 'ended',
  20465. /**
  20466. * Get the value of `playbackRate` from the media element. `playbackRate` indicates
  20467. * the rate at which the media is currently playing back. Examples:
  20468. * - if playbackRate is set to 2, media will play twice as fast.
  20469. * - if playbackRate is set to 0.5, media will play half as fast.
  20470. *
  20471. * @method Html5#playbackRate
  20472. * @return {number}
  20473. * The value of `playbackRate` from the media element. A number indicating
  20474. * the current playback speed of the media, where 1 is normal speed.
  20475. *
  20476. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  20477. */
  20478. 'playbackRate',
  20479. /**
  20480. * Get the value of `defaultPlaybackRate` from the media element. `defaultPlaybackRate` indicates
  20481. * the rate at which the media is currently playing back. This value will not indicate the current
  20482. * `playbackRate` after playback has started, use {@link Html5#playbackRate} for that.
  20483. *
  20484. * Examples:
  20485. * - if defaultPlaybackRate is set to 2, media will play twice as fast.
  20486. * - if defaultPlaybackRate is set to 0.5, media will play half as fast.
  20487. *
  20488. * @method Html5.prototype.defaultPlaybackRate
  20489. * @return {number}
  20490. * The value of `defaultPlaybackRate` from the media element. A number indicating
  20491. * the current playback speed of the media, where 1 is normal speed.
  20492. *
  20493. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  20494. */
  20495. 'defaultPlaybackRate',
  20496. /**
  20497. * Get the value of 'disablePictureInPicture' from the video element.
  20498. *
  20499. * @method Html5#disablePictureInPicture
  20500. * @return {boolean} value
  20501. * - The value of `disablePictureInPicture` from the video element.
  20502. * - True indicates that the video can't be played in Picture-In-Picture mode
  20503. * - False indicates that the video can be played in Picture-In-Picture mode
  20504. *
  20505. * @see [Spec]{@link https://w3c.github.io/picture-in-picture/#disable-pip}
  20506. */
  20507. 'disablePictureInPicture',
  20508. /**
  20509. * Get the value of `played` from the media element. `played` returns a `TimeRange`
  20510. * object representing points in the media timeline that have been played.
  20511. *
  20512. * @method Html5#played
  20513. * @return {TimeRange}
  20514. * The value of `played` from the media element. A `TimeRange` object indicating
  20515. * the ranges of time that have been played.
  20516. *
  20517. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-played}
  20518. */
  20519. 'played',
  20520. /**
  20521. * Get the value of `networkState` from the media element. `networkState` indicates
  20522. * the current network state. It returns an enumeration from the following list:
  20523. * - 0: NETWORK_EMPTY
  20524. * - 1: NETWORK_IDLE
  20525. * - 2: NETWORK_LOADING
  20526. * - 3: NETWORK_NO_SOURCE
  20527. *
  20528. * @method Html5#networkState
  20529. * @return {number}
  20530. * The value of `networkState` from the media element. This will be a number
  20531. * from the list in the description.
  20532. *
  20533. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-networkstate}
  20534. */
  20535. 'networkState',
  20536. /**
  20537. * Get the value of `readyState` from the media element. `readyState` indicates
  20538. * the current state of the media element. It returns an enumeration from the
  20539. * following list:
  20540. * - 0: HAVE_NOTHING
  20541. * - 1: HAVE_METADATA
  20542. * - 2: HAVE_CURRENT_DATA
  20543. * - 3: HAVE_FUTURE_DATA
  20544. * - 4: HAVE_ENOUGH_DATA
  20545. *
  20546. * @method Html5#readyState
  20547. * @return {number}
  20548. * The value of `readyState` from the media element. This will be a number
  20549. * from the list in the description.
  20550. *
  20551. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#ready-states}
  20552. */
  20553. 'readyState',
  20554. /**
  20555. * Get the value of `videoWidth` from the video element. `videoWidth` indicates
  20556. * the current width of the video in css pixels.
  20557. *
  20558. * @method Html5#videoWidth
  20559. * @return {number}
  20560. * The value of `videoWidth` from the video element. This will be a number
  20561. * in css pixels.
  20562. *
  20563. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  20564. */
  20565. 'videoWidth',
  20566. /**
  20567. * Get the value of `videoHeight` from the video element. `videoHeight` indicates
  20568. * the current height of the video in css pixels.
  20569. *
  20570. * @method Html5#videoHeight
  20571. * @return {number}
  20572. * The value of `videoHeight` from the video element. This will be a number
  20573. * in css pixels.
  20574. *
  20575. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  20576. */
  20577. 'videoHeight',
  20578. /**
  20579. * Get the value of `crossOrigin` from the media element. `crossOrigin` indicates
  20580. * to the browser that should sent the cookies along with the requests for the
  20581. * different assets/playlists
  20582. *
  20583. * @method Html5#crossOrigin
  20584. * @return {string}
  20585. * - anonymous indicates that the media should not sent cookies.
  20586. * - use-credentials indicates that the media should sent cookies along the requests.
  20587. *
  20588. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-media-crossorigin}
  20589. */
  20590. 'crossOrigin'].forEach(function (prop) {
  20591. Html5.prototype[prop] = function () {
  20592. return this.el_[prop];
  20593. };
  20594. }); // Wrap native properties with a setter in this format:
  20595. // set + toTitleCase(name)
  20596. // The list is as follows:
  20597. // setVolume, setSrc, setPoster, setPreload, setPlaybackRate, setDefaultPlaybackRate,
  20598. // setDisablePictureInPicture, setCrossOrigin
  20599. [
  20600. /**
  20601. * Set the value of `volume` on the media element. `volume` indicates the current
  20602. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  20603. * so on.
  20604. *
  20605. * @method Html5#setVolume
  20606. * @param {number} percentAsDecimal
  20607. * The volume percent as a decimal. Valid range is from 0-1.
  20608. *
  20609. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  20610. */
  20611. 'volume',
  20612. /**
  20613. * Set the value of `src` on the media element. `src` indicates the current
  20614. * {@link Tech~SourceObject} for the media.
  20615. *
  20616. * @method Html5#setSrc
  20617. * @param {Tech~SourceObject} src
  20618. * The source object to set as the current source.
  20619. *
  20620. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-src}
  20621. */
  20622. 'src',
  20623. /**
  20624. * Set the value of `poster` on the media element. `poster` is the url to
  20625. * an image file that can/will be shown when no media data is available.
  20626. *
  20627. * @method Html5#setPoster
  20628. * @param {string} poster
  20629. * The url to an image that should be used as the `poster` for the media
  20630. * element.
  20631. *
  20632. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-poster}
  20633. */
  20634. 'poster',
  20635. /**
  20636. * Set the value of `preload` on the media element. `preload` indicates
  20637. * what should download before the media is interacted with. It can have the following
  20638. * values:
  20639. * - none: nothing should be downloaded
  20640. * - metadata: poster and the first few frames of the media may be downloaded to get
  20641. * media dimensions and other metadata
  20642. * - auto: allow the media and metadata for the media to be downloaded before
  20643. * interaction
  20644. *
  20645. * @method Html5#setPreload
  20646. * @param {string} preload
  20647. * The value of `preload` to set on the media element. Must be 'none', 'metadata',
  20648. * or 'auto'.
  20649. *
  20650. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  20651. */
  20652. 'preload',
  20653. /**
  20654. * Set the value of `playbackRate` on the media element. `playbackRate` indicates
  20655. * the rate at which the media should play back. Examples:
  20656. * - if playbackRate is set to 2, media will play twice as fast.
  20657. * - if playbackRate is set to 0.5, media will play half as fast.
  20658. *
  20659. * @method Html5#setPlaybackRate
  20660. * @return {number}
  20661. * The value of `playbackRate` from the media element. A number indicating
  20662. * the current playback speed of the media, where 1 is normal speed.
  20663. *
  20664. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  20665. */
  20666. 'playbackRate',
  20667. /**
  20668. * Set the value of `defaultPlaybackRate` on the media element. `defaultPlaybackRate` indicates
  20669. * the rate at which the media should play back upon initial startup. Changing this value
  20670. * after a video has started will do nothing. Instead you should used {@link Html5#setPlaybackRate}.
  20671. *
  20672. * Example Values:
  20673. * - if playbackRate is set to 2, media will play twice as fast.
  20674. * - if playbackRate is set to 0.5, media will play half as fast.
  20675. *
  20676. * @method Html5.prototype.setDefaultPlaybackRate
  20677. * @return {number}
  20678. * The value of `defaultPlaybackRate` from the media element. A number indicating
  20679. * the current playback speed of the media, where 1 is normal speed.
  20680. *
  20681. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultplaybackrate}
  20682. */
  20683. 'defaultPlaybackRate',
  20684. /**
  20685. * Prevents the browser from suggesting a Picture-in-Picture context menu
  20686. * or to request Picture-in-Picture automatically in some cases.
  20687. *
  20688. * @method Html5#setDisablePictureInPicture
  20689. * @param {boolean} value
  20690. * The true value will disable Picture-in-Picture mode.
  20691. *
  20692. * @see [Spec]{@link https://w3c.github.io/picture-in-picture/#disable-pip}
  20693. */
  20694. 'disablePictureInPicture',
  20695. /**
  20696. * Set the value of `crossOrigin` from the media element. `crossOrigin` indicates
  20697. * to the browser that should sent the cookies along with the requests for the
  20698. * different assets/playlists
  20699. *
  20700. * @method Html5#setCrossOrigin
  20701. * @param {string} crossOrigin
  20702. * - anonymous indicates that the media should not sent cookies.
  20703. * - use-credentials indicates that the media should sent cookies along the requests.
  20704. *
  20705. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-media-crossorigin}
  20706. */
  20707. 'crossOrigin'].forEach(function (prop) {
  20708. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  20709. this.el_[prop] = v;
  20710. };
  20711. }); // wrap native functions with a function
  20712. // The list is as follows:
  20713. // pause, load, play
  20714. [
  20715. /**
  20716. * A wrapper around the media elements `pause` function. This will call the `HTML5`
  20717. * media elements `pause` function.
  20718. *
  20719. * @method Html5#pause
  20720. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-pause}
  20721. */
  20722. 'pause',
  20723. /**
  20724. * A wrapper around the media elements `load` function. This will call the `HTML5`s
  20725. * media element `load` function.
  20726. *
  20727. * @method Html5#load
  20728. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-load}
  20729. */
  20730. 'load',
  20731. /**
  20732. * A wrapper around the media elements `play` function. This will call the `HTML5`s
  20733. * media element `play` function.
  20734. *
  20735. * @method Html5#play
  20736. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-play}
  20737. */
  20738. 'play'].forEach(function (prop) {
  20739. Html5.prototype[prop] = function () {
  20740. return this.el_[prop]();
  20741. };
  20742. });
  20743. Tech.withSourceHandlers(Html5);
  20744. /**
  20745. * Native source handler for Html5, simply passes the source to the media element.
  20746. *
  20747. * @property {Tech~SourceObject} source
  20748. * The source object
  20749. *
  20750. * @property {Html5} tech
  20751. * The instance of the HTML5 tech.
  20752. */
  20753. Html5.nativeSourceHandler = {};
  20754. /**
  20755. * Check if the media element can play the given mime type.
  20756. *
  20757. * @param {string} type
  20758. * The mimetype to check
  20759. *
  20760. * @return {string}
  20761. * 'probably', 'maybe', or '' (empty string)
  20762. */
  20763. Html5.nativeSourceHandler.canPlayType = function (type) {
  20764. // IE without MediaPlayer throws an error (#519)
  20765. try {
  20766. return Html5.TEST_VID.canPlayType(type);
  20767. } catch (e) {
  20768. return '';
  20769. }
  20770. };
  20771. /**
  20772. * Check if the media element can handle a source natively.
  20773. *
  20774. * @param {Tech~SourceObject} source
  20775. * The source object
  20776. *
  20777. * @param {Object} [options]
  20778. * Options to be passed to the tech.
  20779. *
  20780. * @return {string}
  20781. * 'probably', 'maybe', or '' (empty string).
  20782. */
  20783. Html5.nativeSourceHandler.canHandleSource = function (source, options) {
  20784. // If a type was provided we should rely on that
  20785. if (source.type) {
  20786. return Html5.nativeSourceHandler.canPlayType(source.type); // If no type, fall back to checking 'video/[EXTENSION]'
  20787. } else if (source.src) {
  20788. var ext = getFileExtension(source.src);
  20789. return Html5.nativeSourceHandler.canPlayType("video/" + ext);
  20790. }
  20791. return '';
  20792. };
  20793. /**
  20794. * Pass the source to the native media element.
  20795. *
  20796. * @param {Tech~SourceObject} source
  20797. * The source object
  20798. *
  20799. * @param {Html5} tech
  20800. * The instance of the Html5 tech
  20801. *
  20802. * @param {Object} [options]
  20803. * The options to pass to the source
  20804. */
  20805. Html5.nativeSourceHandler.handleSource = function (source, tech, options) {
  20806. tech.setSrc(source.src);
  20807. };
  20808. /**
  20809. * A noop for the native dispose function, as cleanup is not needed.
  20810. */
  20811. Html5.nativeSourceHandler.dispose = function () {}; // Register the native source handler
  20812. Html5.registerSourceHandler(Html5.nativeSourceHandler);
  20813. Tech.registerTech('Html5', Html5);
  20814. // on the player when they happen
  20815. var TECH_EVENTS_RETRIGGER = [
  20816. /**
  20817. * Fired while the user agent is downloading media data.
  20818. *
  20819. * @event Player#progress
  20820. * @type {EventTarget~Event}
  20821. */
  20822. /**
  20823. * Retrigger the `progress` event that was triggered by the {@link Tech}.
  20824. *
  20825. * @private
  20826. * @method Player#handleTechProgress_
  20827. * @fires Player#progress
  20828. * @listens Tech#progress
  20829. */
  20830. 'progress',
  20831. /**
  20832. * Fires when the loading of an audio/video is aborted.
  20833. *
  20834. * @event Player#abort
  20835. * @type {EventTarget~Event}
  20836. */
  20837. /**
  20838. * Retrigger the `abort` event that was triggered by the {@link Tech}.
  20839. *
  20840. * @private
  20841. * @method Player#handleTechAbort_
  20842. * @fires Player#abort
  20843. * @listens Tech#abort
  20844. */
  20845. 'abort',
  20846. /**
  20847. * Fires when the browser is intentionally not getting media data.
  20848. *
  20849. * @event Player#suspend
  20850. * @type {EventTarget~Event}
  20851. */
  20852. /**
  20853. * Retrigger the `suspend` event that was triggered by the {@link Tech}.
  20854. *
  20855. * @private
  20856. * @method Player#handleTechSuspend_
  20857. * @fires Player#suspend
  20858. * @listens Tech#suspend
  20859. */
  20860. 'suspend',
  20861. /**
  20862. * Fires when the current playlist is empty.
  20863. *
  20864. * @event Player#emptied
  20865. * @type {EventTarget~Event}
  20866. */
  20867. /**
  20868. * Retrigger the `emptied` event that was triggered by the {@link Tech}.
  20869. *
  20870. * @private
  20871. * @method Player#handleTechEmptied_
  20872. * @fires Player#emptied
  20873. * @listens Tech#emptied
  20874. */
  20875. 'emptied',
  20876. /**
  20877. * Fires when the browser is trying to get media data, but data is not available.
  20878. *
  20879. * @event Player#stalled
  20880. * @type {EventTarget~Event}
  20881. */
  20882. /**
  20883. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  20884. *
  20885. * @private
  20886. * @method Player#handleTechStalled_
  20887. * @fires Player#stalled
  20888. * @listens Tech#stalled
  20889. */
  20890. 'stalled',
  20891. /**
  20892. * Fires when the browser has loaded meta data for the audio/video.
  20893. *
  20894. * @event Player#loadedmetadata
  20895. * @type {EventTarget~Event}
  20896. */
  20897. /**
  20898. * Retrigger the `loadedmetadata` event that was triggered by the {@link Tech}.
  20899. *
  20900. * @private
  20901. * @method Player#handleTechLoadedmetadata_
  20902. * @fires Player#loadedmetadata
  20903. * @listens Tech#loadedmetadata
  20904. */
  20905. 'loadedmetadata',
  20906. /**
  20907. * Fires when the browser has loaded the current frame of the audio/video.
  20908. *
  20909. * @event Player#loadeddata
  20910. * @type {event}
  20911. */
  20912. /**
  20913. * Retrigger the `loadeddata` event that was triggered by the {@link Tech}.
  20914. *
  20915. * @private
  20916. * @method Player#handleTechLoaddeddata_
  20917. * @fires Player#loadeddata
  20918. * @listens Tech#loadeddata
  20919. */
  20920. 'loadeddata',
  20921. /**
  20922. * Fires when the current playback position has changed.
  20923. *
  20924. * @event Player#timeupdate
  20925. * @type {event}
  20926. */
  20927. /**
  20928. * Retrigger the `timeupdate` event that was triggered by the {@link Tech}.
  20929. *
  20930. * @private
  20931. * @method Player#handleTechTimeUpdate_
  20932. * @fires Player#timeupdate
  20933. * @listens Tech#timeupdate
  20934. */
  20935. 'timeupdate',
  20936. /**
  20937. * Fires when the video's intrinsic dimensions change
  20938. *
  20939. * @event Player#resize
  20940. * @type {event}
  20941. */
  20942. /**
  20943. * Retrigger the `resize` event that was triggered by the {@link Tech}.
  20944. *
  20945. * @private
  20946. * @method Player#handleTechResize_
  20947. * @fires Player#resize
  20948. * @listens Tech#resize
  20949. */
  20950. 'resize',
  20951. /**
  20952. * Fires when the volume has been changed
  20953. *
  20954. * @event Player#volumechange
  20955. * @type {event}
  20956. */
  20957. /**
  20958. * Retrigger the `volumechange` event that was triggered by the {@link Tech}.
  20959. *
  20960. * @private
  20961. * @method Player#handleTechVolumechange_
  20962. * @fires Player#volumechange
  20963. * @listens Tech#volumechange
  20964. */
  20965. 'volumechange',
  20966. /**
  20967. * Fires when the text track has been changed
  20968. *
  20969. * @event Player#texttrackchange
  20970. * @type {event}
  20971. */
  20972. /**
  20973. * Retrigger the `texttrackchange` event that was triggered by the {@link Tech}.
  20974. *
  20975. * @private
  20976. * @method Player#handleTechTexttrackchange_
  20977. * @fires Player#texttrackchange
  20978. * @listens Tech#texttrackchange
  20979. */
  20980. 'texttrackchange']; // events to queue when playback rate is zero
  20981. // this is a hash for the sole purpose of mapping non-camel-cased event names
  20982. // to camel-cased function names
  20983. var TECH_EVENTS_QUEUE = {
  20984. canplay: 'CanPlay',
  20985. canplaythrough: 'CanPlayThrough',
  20986. playing: 'Playing',
  20987. seeked: 'Seeked'
  20988. };
  20989. var BREAKPOINT_ORDER = ['tiny', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'huge'];
  20990. var BREAKPOINT_CLASSES = {}; // grep: vjs-layout-tiny
  20991. // grep: vjs-layout-x-small
  20992. // grep: vjs-layout-small
  20993. // grep: vjs-layout-medium
  20994. // grep: vjs-layout-large
  20995. // grep: vjs-layout-x-large
  20996. // grep: vjs-layout-huge
  20997. BREAKPOINT_ORDER.forEach(function (k) {
  20998. var v = k.charAt(0) === 'x' ? "x-" + k.substring(1) : k;
  20999. BREAKPOINT_CLASSES[k] = "vjs-layout-" + v;
  21000. });
  21001. var DEFAULT_BREAKPOINTS = {
  21002. tiny: 210,
  21003. xsmall: 320,
  21004. small: 425,
  21005. medium: 768,
  21006. large: 1440,
  21007. xlarge: 2560,
  21008. huge: Infinity
  21009. };
  21010. /**
  21011. * An instance of the `Player` class is created when any of the Video.js setup methods
  21012. * are used to initialize a video.
  21013. *
  21014. * After an instance has been created it can be accessed globally in two ways:
  21015. * 1. By calling `videojs('example_video_1');`
  21016. * 2. By using it directly via `videojs.players.example_video_1;`
  21017. *
  21018. * @extends Component
  21019. */
  21020. var Player = /*#__PURE__*/function (_Component) {
  21021. inheritsLoose(Player, _Component);
  21022. /**
  21023. * Create an instance of this class.
  21024. *
  21025. * @param {Element} tag
  21026. * The original video DOM element used for configuring options.
  21027. *
  21028. * @param {Object} [options]
  21029. * Object of option names and values.
  21030. *
  21031. * @param {Component~ReadyCallback} [ready]
  21032. * Ready callback function.
  21033. */
  21034. function Player(tag, options, ready) {
  21035. var _this;
  21036. // Make sure tag ID exists
  21037. tag.id = tag.id || options.id || "vjs_video_" + newGUID(); // Set Options
  21038. // The options argument overrides options set in the video tag
  21039. // which overrides globally set options.
  21040. // This latter part coincides with the load order
  21041. // (tag must exist before Player)
  21042. options = assign(Player.getTagSettings(tag), options); // Delay the initialization of children because we need to set up
  21043. // player properties first, and can't use `this` before `super()`
  21044. options.initChildren = false; // Same with creating the element
  21045. options.createEl = false; // don't auto mixin the evented mixin
  21046. options.evented = false; // we don't want the player to report touch activity on itself
  21047. // see enableTouchActivity in Component
  21048. options.reportTouchActivity = false; // If language is not set, get the closest lang attribute
  21049. if (!options.language) {
  21050. if (typeof tag.closest === 'function') {
  21051. var closest = tag.closest('[lang]');
  21052. if (closest && closest.getAttribute) {
  21053. options.language = closest.getAttribute('lang');
  21054. }
  21055. } else {
  21056. var element = tag;
  21057. while (element && element.nodeType === 1) {
  21058. if (getAttributes(element).hasOwnProperty('lang')) {
  21059. options.language = element.getAttribute('lang');
  21060. break;
  21061. }
  21062. element = element.parentNode;
  21063. }
  21064. }
  21065. } // Run base component initializing with new options
  21066. _this = _Component.call(this, null, options, ready) || this; // Create bound methods for document listeners.
  21067. _this.boundDocumentFullscreenChange_ = function (e) {
  21068. return _this.documentFullscreenChange_(e);
  21069. };
  21070. _this.boundFullWindowOnEscKey_ = function (e) {
  21071. return _this.fullWindowOnEscKey(e);
  21072. };
  21073. _this.boundUpdateStyleEl_ = function (e) {
  21074. return _this.updateStyleEl_(e);
  21075. };
  21076. _this.boundApplyInitTime_ = function (e) {
  21077. return _this.applyInitTime_(e);
  21078. };
  21079. _this.boundUpdateCurrentBreakpoint_ = function (e) {
  21080. return _this.updateCurrentBreakpoint_(e);
  21081. };
  21082. _this.boundHandleTechClick_ = function (e) {
  21083. return _this.handleTechClick_(e);
  21084. };
  21085. _this.boundHandleTechDoubleClick_ = function (e) {
  21086. return _this.handleTechDoubleClick_(e);
  21087. };
  21088. _this.boundHandleTechTouchStart_ = function (e) {
  21089. return _this.handleTechTouchStart_(e);
  21090. };
  21091. _this.boundHandleTechTouchMove_ = function (e) {
  21092. return _this.handleTechTouchMove_(e);
  21093. };
  21094. _this.boundHandleTechTouchEnd_ = function (e) {
  21095. return _this.handleTechTouchEnd_(e);
  21096. };
  21097. _this.boundHandleTechTap_ = function (e) {
  21098. return _this.handleTechTap_(e);
  21099. }; // default isFullscreen_ to false
  21100. _this.isFullscreen_ = false; // create logger
  21101. _this.log = createLogger(_this.id_); // Hold our own reference to fullscreen api so it can be mocked in tests
  21102. _this.fsApi_ = FullscreenApi; // Tracks when a tech changes the poster
  21103. _this.isPosterFromTech_ = false; // Holds callback info that gets queued when playback rate is zero
  21104. // and a seek is happening
  21105. _this.queuedCallbacks_ = []; // Turn off API access because we're loading a new tech that might load asynchronously
  21106. _this.isReady_ = false; // Init state hasStarted_
  21107. _this.hasStarted_ = false; // Init state userActive_
  21108. _this.userActive_ = false; // Init debugEnabled_
  21109. _this.debugEnabled_ = false; // Init state audioOnlyMode_
  21110. _this.audioOnlyMode_ = false; // Init state audioPosterMode_
  21111. _this.audioPosterMode_ = false; // Init state audioOnlyCache_
  21112. _this.audioOnlyCache_ = {
  21113. playerHeight: null,
  21114. hiddenChildren: []
  21115. }; // if the global option object was accidentally blown away by
  21116. // someone, bail early with an informative error
  21117. if (!_this.options_ || !_this.options_.techOrder || !_this.options_.techOrder.length) {
  21118. throw new Error('No techOrder specified. Did you overwrite ' + 'videojs.options instead of just changing the ' + 'properties you want to override?');
  21119. } // Store the original tag used to set options
  21120. _this.tag = tag; // Store the tag attributes used to restore html5 element
  21121. _this.tagAttributes = tag && getAttributes(tag); // Update current language
  21122. _this.language(_this.options_.language); // Update Supported Languages
  21123. if (options.languages) {
  21124. // Normalise player option languages to lowercase
  21125. var languagesToLower = {};
  21126. Object.getOwnPropertyNames(options.languages).forEach(function (name) {
  21127. languagesToLower[name.toLowerCase()] = options.languages[name];
  21128. });
  21129. _this.languages_ = languagesToLower;
  21130. } else {
  21131. _this.languages_ = Player.prototype.options_.languages;
  21132. }
  21133. _this.resetCache_(); // Set poster
  21134. _this.poster_ = options.poster || ''; // Set controls
  21135. _this.controls_ = !!options.controls; // Original tag settings stored in options
  21136. // now remove immediately so native controls don't flash.
  21137. // May be turned back on by HTML5 tech if nativeControlsForTouch is true
  21138. tag.controls = false;
  21139. tag.removeAttribute('controls');
  21140. _this.changingSrc_ = false;
  21141. _this.playCallbacks_ = [];
  21142. _this.playTerminatedQueue_ = []; // the attribute overrides the option
  21143. if (tag.hasAttribute('autoplay')) {
  21144. _this.autoplay(true);
  21145. } else {
  21146. // otherwise use the setter to validate and
  21147. // set the correct value.
  21148. _this.autoplay(_this.options_.autoplay);
  21149. } // check plugins
  21150. if (options.plugins) {
  21151. Object.keys(options.plugins).forEach(function (name) {
  21152. if (typeof _this[name] !== 'function') {
  21153. throw new Error("plugin \"" + name + "\" does not exist");
  21154. }
  21155. });
  21156. }
  21157. /*
  21158. * Store the internal state of scrubbing
  21159. *
  21160. * @private
  21161. * @return {Boolean} True if the user is scrubbing
  21162. */
  21163. _this.scrubbing_ = false;
  21164. _this.el_ = _this.createEl(); // Make this an evented object and use `el_` as its event bus.
  21165. evented(assertThisInitialized(_this), {
  21166. eventBusKey: 'el_'
  21167. }); // listen to document and player fullscreenchange handlers so we receive those events
  21168. // before a user can receive them so we can update isFullscreen appropriately.
  21169. // make sure that we listen to fullscreenchange events before everything else to make sure that
  21170. // our isFullscreen method is updated properly for internal components as well as external.
  21171. if (_this.fsApi_.requestFullscreen) {
  21172. on(document, _this.fsApi_.fullscreenchange, _this.boundDocumentFullscreenChange_);
  21173. _this.on(_this.fsApi_.fullscreenchange, _this.boundDocumentFullscreenChange_);
  21174. }
  21175. if (_this.fluid_) {
  21176. _this.on(['playerreset', 'resize'], _this.boundUpdateStyleEl_);
  21177. } // We also want to pass the original player options to each component and plugin
  21178. // as well so they don't need to reach back into the player for options later.
  21179. // We also need to do another copy of this.options_ so we don't end up with
  21180. // an infinite loop.
  21181. var playerOptionsCopy = mergeOptions(_this.options_); // Load plugins
  21182. if (options.plugins) {
  21183. Object.keys(options.plugins).forEach(function (name) {
  21184. _this[name](options.plugins[name]);
  21185. });
  21186. } // Enable debug mode to fire debugon event for all plugins.
  21187. if (options.debug) {
  21188. _this.debug(true);
  21189. }
  21190. _this.options_.playerOptions = playerOptionsCopy;
  21191. _this.middleware_ = [];
  21192. _this.playbackRates(options.playbackRates);
  21193. _this.initChildren(); // Set isAudio based on whether or not an audio tag was used
  21194. _this.isAudio(tag.nodeName.toLowerCase() === 'audio'); // Update controls className. Can't do this when the controls are initially
  21195. // set because the element doesn't exist yet.
  21196. if (_this.controls()) {
  21197. _this.addClass('vjs-controls-enabled');
  21198. } else {
  21199. _this.addClass('vjs-controls-disabled');
  21200. } // Set ARIA label and region role depending on player type
  21201. _this.el_.setAttribute('role', 'region');
  21202. if (_this.isAudio()) {
  21203. _this.el_.setAttribute('aria-label', _this.localize('Audio Player'));
  21204. } else {
  21205. _this.el_.setAttribute('aria-label', _this.localize('Video Player'));
  21206. }
  21207. if (_this.isAudio()) {
  21208. _this.addClass('vjs-audio');
  21209. }
  21210. if (_this.flexNotSupported_()) {
  21211. _this.addClass('vjs-no-flex');
  21212. } // TODO: Make this smarter. Toggle user state between touching/mousing
  21213. // using events, since devices can have both touch and mouse events.
  21214. // TODO: Make this check be performed again when the window switches between monitors
  21215. // (See https://github.com/videojs/video.js/issues/5683)
  21216. if (TOUCH_ENABLED) {
  21217. _this.addClass('vjs-touch-enabled');
  21218. } // iOS Safari has broken hover handling
  21219. if (!IS_IOS) {
  21220. _this.addClass('vjs-workinghover');
  21221. } // Make player easily findable by ID
  21222. Player.players[_this.id_] = assertThisInitialized(_this); // Add a major version class to aid css in plugins
  21223. var majorVersion = version.split('.')[0];
  21224. _this.addClass("vjs-v" + majorVersion); // When the player is first initialized, trigger activity so components
  21225. // like the control bar show themselves if needed
  21226. _this.userActive(true);
  21227. _this.reportUserActivity();
  21228. _this.one('play', function (e) {
  21229. return _this.listenForUserActivity_(e);
  21230. });
  21231. _this.on('stageclick', function (e) {
  21232. return _this.handleStageClick_(e);
  21233. });
  21234. _this.on('keydown', function (e) {
  21235. return _this.handleKeyDown(e);
  21236. });
  21237. _this.on('languagechange', function (e) {
  21238. return _this.handleLanguagechange(e);
  21239. });
  21240. _this.breakpoints(_this.options_.breakpoints);
  21241. _this.responsive(_this.options_.responsive); // Calling both the audio mode methods after the player is fully
  21242. // setup to be able to listen to the events triggered by them
  21243. _this.on('ready', function () {
  21244. // Calling the audioPosterMode method first so that
  21245. // the audioOnlyMode can take precedence when both options are set to true
  21246. _this.audioPosterMode(_this.options_.audioPosterMode);
  21247. _this.audioOnlyMode(_this.options_.audioOnlyMode);
  21248. });
  21249. return _this;
  21250. }
  21251. /**
  21252. * Destroys the video player and does any necessary cleanup.
  21253. *
  21254. * This is especially helpful if you are dynamically adding and removing videos
  21255. * to/from the DOM.
  21256. *
  21257. * @fires Player#dispose
  21258. */
  21259. var _proto = Player.prototype;
  21260. _proto.dispose = function dispose() {
  21261. var _this2 = this;
  21262. /**
  21263. * Called when the player is being disposed of.
  21264. *
  21265. * @event Player#dispose
  21266. * @type {EventTarget~Event}
  21267. */
  21268. this.trigger('dispose'); // prevent dispose from being called twice
  21269. this.off('dispose'); // Make sure all player-specific document listeners are unbound. This is
  21270. off(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_);
  21271. off(document, 'keydown', this.boundFullWindowOnEscKey_);
  21272. if (this.styleEl_ && this.styleEl_.parentNode) {
  21273. this.styleEl_.parentNode.removeChild(this.styleEl_);
  21274. this.styleEl_ = null;
  21275. } // Kill reference to this player
  21276. Player.players[this.id_] = null;
  21277. if (this.tag && this.tag.player) {
  21278. this.tag.player = null;
  21279. }
  21280. if (this.el_ && this.el_.player) {
  21281. this.el_.player = null;
  21282. }
  21283. if (this.tech_) {
  21284. this.tech_.dispose();
  21285. this.isPosterFromTech_ = false;
  21286. this.poster_ = '';
  21287. }
  21288. if (this.playerElIngest_) {
  21289. this.playerElIngest_ = null;
  21290. }
  21291. if (this.tag) {
  21292. this.tag = null;
  21293. }
  21294. clearCacheForPlayer(this); // remove all event handlers for track lists
  21295. // all tracks and track listeners are removed on
  21296. // tech dispose
  21297. ALL.names.forEach(function (name) {
  21298. var props = ALL[name];
  21299. var list = _this2[props.getterName](); // if it is not a native list
  21300. // we have to manually remove event listeners
  21301. if (list && list.off) {
  21302. list.off();
  21303. }
  21304. }); // the actual .el_ is removed here, or replaced if
  21305. _Component.prototype.dispose.call(this, {
  21306. restoreEl: this.options_.restoreEl
  21307. });
  21308. }
  21309. /**
  21310. * Create the `Player`'s DOM element.
  21311. *
  21312. * @return {Element}
  21313. * The DOM element that gets created.
  21314. */
  21315. ;
  21316. _proto.createEl = function createEl() {
  21317. var tag = this.tag;
  21318. var el;
  21319. var playerElIngest = this.playerElIngest_ = tag.parentNode && tag.parentNode.hasAttribute && tag.parentNode.hasAttribute('data-vjs-player');
  21320. var divEmbed = this.tag.tagName.toLowerCase() === 'video-js';
  21321. if (playerElIngest) {
  21322. el = this.el_ = tag.parentNode;
  21323. } else if (!divEmbed) {
  21324. el = this.el_ = _Component.prototype.createEl.call(this, 'div');
  21325. } // Copy over all the attributes from the tag, including ID and class
  21326. // ID will now reference player box, not the video tag
  21327. var attrs = getAttributes(tag);
  21328. if (divEmbed) {
  21329. el = this.el_ = tag;
  21330. tag = this.tag = document.createElement('video');
  21331. while (el.children.length) {
  21332. tag.appendChild(el.firstChild);
  21333. }
  21334. if (!hasClass(el, 'video-js')) {
  21335. addClass(el, 'video-js');
  21336. }
  21337. el.appendChild(tag);
  21338. playerElIngest = this.playerElIngest_ = el; // move properties over from our custom `video-js` element
  21339. // to our new `video` element. This will move things like
  21340. // `src` or `controls` that were set via js before the player
  21341. // was initialized.
  21342. Object.keys(el).forEach(function (k) {
  21343. try {
  21344. tag[k] = el[k];
  21345. } catch (e) {// we got a a property like outerHTML which we can't actually copy, ignore it
  21346. }
  21347. });
  21348. } // set tabindex to -1 to remove the video element from the focus order
  21349. tag.setAttribute('tabindex', '-1');
  21350. attrs.tabindex = '-1'; // Workaround for #4583 (JAWS+IE doesn't announce BPB or play button), and
  21351. // for the same issue with Chrome (on Windows) with JAWS.
  21352. // See https://github.com/FreedomScientific/VFO-standards-support/issues/78
  21353. // Note that we can't detect if JAWS is being used, but this ARIA attribute
  21354. // doesn't change behavior of IE11 or Chrome if JAWS is not being used
  21355. if (IE_VERSION || IS_CHROME && IS_WINDOWS) {
  21356. tag.setAttribute('role', 'application');
  21357. attrs.role = 'application';
  21358. } // Remove width/height attrs from tag so CSS can make it 100% width/height
  21359. tag.removeAttribute('width');
  21360. tag.removeAttribute('height');
  21361. if ('width' in attrs) {
  21362. delete attrs.width;
  21363. }
  21364. if ('height' in attrs) {
  21365. delete attrs.height;
  21366. }
  21367. Object.getOwnPropertyNames(attrs).forEach(function (attr) {
  21368. // don't copy over the class attribute to the player element when we're in a div embed
  21369. // the class is already set up properly in the divEmbed case
  21370. // and we want to make sure that the `video-js` class doesn't get lost
  21371. if (!(divEmbed && attr === 'class')) {
  21372. el.setAttribute(attr, attrs[attr]);
  21373. }
  21374. if (divEmbed) {
  21375. tag.setAttribute(attr, attrs[attr]);
  21376. }
  21377. }); // Update tag id/class for use as HTML5 playback tech
  21378. // Might think we should do this after embedding in container so .vjs-tech class
  21379. // doesn't flash 100% width/height, but class only applies with .video-js parent
  21380. tag.playerId = tag.id;
  21381. tag.id += '_html5_api';
  21382. tag.className = 'vjs-tech'; // Make player findable on elements
  21383. tag.player = el.player = this; // Default state of video is paused
  21384. this.addClass('vjs-paused'); // Add a style element in the player that we'll use to set the width/height
  21385. // of the player in a way that's still overrideable by CSS, just like the
  21386. // video element
  21387. if (window.VIDEOJS_NO_DYNAMIC_STYLE !== true) {
  21388. this.styleEl_ = createStyleElement('vjs-styles-dimensions');
  21389. var defaultsStyleEl = $('.vjs-styles-defaults');
  21390. var head = $('head');
  21391. head.insertBefore(this.styleEl_, defaultsStyleEl ? defaultsStyleEl.nextSibling : head.firstChild);
  21392. }
  21393. this.fill_ = false;
  21394. this.fluid_ = false; // Pass in the width/height/aspectRatio options which will update the style el
  21395. this.width(this.options_.width);
  21396. this.height(this.options_.height);
  21397. this.fill(this.options_.fill);
  21398. this.fluid(this.options_.fluid);
  21399. this.aspectRatio(this.options_.aspectRatio); // support both crossOrigin and crossorigin to reduce confusion and issues around the name
  21400. this.crossOrigin(this.options_.crossOrigin || this.options_.crossorigin); // Hide any links within the video/audio tag,
  21401. // because IE doesn't hide them completely from screen readers.
  21402. var links = tag.getElementsByTagName('a');
  21403. for (var i = 0; i < links.length; i++) {
  21404. var linkEl = links.item(i);
  21405. addClass(linkEl, 'vjs-hidden');
  21406. linkEl.setAttribute('hidden', 'hidden');
  21407. } // insertElFirst seems to cause the networkState to flicker from 3 to 2, so
  21408. // keep track of the original for later so we can know if the source originally failed
  21409. tag.initNetworkState_ = tag.networkState; // Wrap video tag in div (el/box) container
  21410. if (tag.parentNode && !playerElIngest) {
  21411. tag.parentNode.insertBefore(el, tag);
  21412. } // insert the tag as the first child of the player element
  21413. // then manually add it to the children array so that this.addChild
  21414. // will work properly for other components
  21415. //
  21416. // Breaks iPhone, fixed in HTML5 setup.
  21417. prependTo(tag, el);
  21418. this.children_.unshift(tag); // Set lang attr on player to ensure CSS :lang() in consistent with player
  21419. // if it's been set to something different to the doc
  21420. this.el_.setAttribute('lang', this.language_);
  21421. this.el_.setAttribute('translate', 'no');
  21422. this.el_ = el;
  21423. return el;
  21424. }
  21425. /**
  21426. * Get or set the `Player`'s crossOrigin option. For the HTML5 player, this
  21427. * sets the `crossOrigin` property on the `<video>` tag to control the CORS
  21428. * behavior.
  21429. *
  21430. * @see [Video Element Attributes]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin}
  21431. *
  21432. * @param {string} [value]
  21433. * The value to set the `Player`'s crossOrigin to. If an argument is
  21434. * given, must be one of `anonymous` or `use-credentials`.
  21435. *
  21436. * @return {string|undefined}
  21437. * - The current crossOrigin value of the `Player` when getting.
  21438. * - undefined when setting
  21439. */
  21440. ;
  21441. _proto.crossOrigin = function crossOrigin(value) {
  21442. if (!value) {
  21443. return this.techGet_('crossOrigin');
  21444. }
  21445. if (value !== 'anonymous' && value !== 'use-credentials') {
  21446. log.warn("crossOrigin must be \"anonymous\" or \"use-credentials\", given \"" + value + "\"");
  21447. return;
  21448. }
  21449. this.techCall_('setCrossOrigin', value);
  21450. return;
  21451. }
  21452. /**
  21453. * A getter/setter for the `Player`'s width. Returns the player's configured value.
  21454. * To get the current width use `currentWidth()`.
  21455. *
  21456. * @param {number} [value]
  21457. * The value to set the `Player`'s width to.
  21458. *
  21459. * @return {number}
  21460. * The current width of the `Player` when getting.
  21461. */
  21462. ;
  21463. _proto.width = function width(value) {
  21464. return this.dimension('width', value);
  21465. }
  21466. /**
  21467. * A getter/setter for the `Player`'s height. Returns the player's configured value.
  21468. * To get the current height use `currentheight()`.
  21469. *
  21470. * @param {number} [value]
  21471. * The value to set the `Player`'s heigth to.
  21472. *
  21473. * @return {number}
  21474. * The current height of the `Player` when getting.
  21475. */
  21476. ;
  21477. _proto.height = function height(value) {
  21478. return this.dimension('height', value);
  21479. }
  21480. /**
  21481. * A getter/setter for the `Player`'s width & height.
  21482. *
  21483. * @param {string} dimension
  21484. * This string can be:
  21485. * - 'width'
  21486. * - 'height'
  21487. *
  21488. * @param {number} [value]
  21489. * Value for dimension specified in the first argument.
  21490. *
  21491. * @return {number}
  21492. * The dimension arguments value when getting (width/height).
  21493. */
  21494. ;
  21495. _proto.dimension = function dimension(_dimension, value) {
  21496. var privDimension = _dimension + '_';
  21497. if (value === undefined) {
  21498. return this[privDimension] || 0;
  21499. }
  21500. if (value === '' || value === 'auto') {
  21501. // If an empty string is given, reset the dimension to be automatic
  21502. this[privDimension] = undefined;
  21503. this.updateStyleEl_();
  21504. return;
  21505. }
  21506. var parsedVal = parseFloat(value);
  21507. if (isNaN(parsedVal)) {
  21508. log.error("Improper value \"" + value + "\" supplied for for " + _dimension);
  21509. return;
  21510. }
  21511. this[privDimension] = parsedVal;
  21512. this.updateStyleEl_();
  21513. }
  21514. /**
  21515. * A getter/setter/toggler for the vjs-fluid `className` on the `Player`.
  21516. *
  21517. * Turning this on will turn off fill mode.
  21518. *
  21519. * @param {boolean} [bool]
  21520. * - A value of true adds the class.
  21521. * - A value of false removes the class.
  21522. * - No value will be a getter.
  21523. *
  21524. * @return {boolean|undefined}
  21525. * - The value of fluid when getting.
  21526. * - `undefined` when setting.
  21527. */
  21528. ;
  21529. _proto.fluid = function fluid(bool) {
  21530. var _this3 = this;
  21531. if (bool === undefined) {
  21532. return !!this.fluid_;
  21533. }
  21534. this.fluid_ = !!bool;
  21535. if (isEvented(this)) {
  21536. this.off(['playerreset', 'resize'], this.boundUpdateStyleEl_);
  21537. }
  21538. if (bool) {
  21539. this.addClass('vjs-fluid');
  21540. this.fill(false);
  21541. addEventedCallback(this, function () {
  21542. _this3.on(['playerreset', 'resize'], _this3.boundUpdateStyleEl_);
  21543. });
  21544. } else {
  21545. this.removeClass('vjs-fluid');
  21546. }
  21547. this.updateStyleEl_();
  21548. }
  21549. /**
  21550. * A getter/setter/toggler for the vjs-fill `className` on the `Player`.
  21551. *
  21552. * Turning this on will turn off fluid mode.
  21553. *
  21554. * @param {boolean} [bool]
  21555. * - A value of true adds the class.
  21556. * - A value of false removes the class.
  21557. * - No value will be a getter.
  21558. *
  21559. * @return {boolean|undefined}
  21560. * - The value of fluid when getting.
  21561. * - `undefined` when setting.
  21562. */
  21563. ;
  21564. _proto.fill = function fill(bool) {
  21565. if (bool === undefined) {
  21566. return !!this.fill_;
  21567. }
  21568. this.fill_ = !!bool;
  21569. if (bool) {
  21570. this.addClass('vjs-fill');
  21571. this.fluid(false);
  21572. } else {
  21573. this.removeClass('vjs-fill');
  21574. }
  21575. }
  21576. /**
  21577. * Get/Set the aspect ratio
  21578. *
  21579. * @param {string} [ratio]
  21580. * Aspect ratio for player
  21581. *
  21582. * @return {string|undefined}
  21583. * returns the current aspect ratio when getting
  21584. */
  21585. /**
  21586. * A getter/setter for the `Player`'s aspect ratio.
  21587. *
  21588. * @param {string} [ratio]
  21589. * The value to set the `Player`'s aspect ratio to.
  21590. *
  21591. * @return {string|undefined}
  21592. * - The current aspect ratio of the `Player` when getting.
  21593. * - undefined when setting
  21594. */
  21595. ;
  21596. _proto.aspectRatio = function aspectRatio(ratio) {
  21597. if (ratio === undefined) {
  21598. return this.aspectRatio_;
  21599. } // Check for width:height format
  21600. if (!/^\d+\:\d+$/.test(ratio)) {
  21601. throw new Error('Improper value supplied for aspect ratio. The format should be width:height, for example 16:9.');
  21602. }
  21603. this.aspectRatio_ = ratio; // We're assuming if you set an aspect ratio you want fluid mode,
  21604. // because in fixed mode you could calculate width and height yourself.
  21605. this.fluid(true);
  21606. this.updateStyleEl_();
  21607. }
  21608. /**
  21609. * Update styles of the `Player` element (height, width and aspect ratio).
  21610. *
  21611. * @private
  21612. * @listens Tech#loadedmetadata
  21613. */
  21614. ;
  21615. _proto.updateStyleEl_ = function updateStyleEl_() {
  21616. if (window.VIDEOJS_NO_DYNAMIC_STYLE === true) {
  21617. var _width = typeof this.width_ === 'number' ? this.width_ : this.options_.width;
  21618. var _height = typeof this.height_ === 'number' ? this.height_ : this.options_.height;
  21619. var techEl = this.tech_ && this.tech_.el();
  21620. if (techEl) {
  21621. if (_width >= 0) {
  21622. techEl.width = _width;
  21623. }
  21624. if (_height >= 0) {
  21625. techEl.height = _height;
  21626. }
  21627. }
  21628. return;
  21629. }
  21630. var width;
  21631. var height;
  21632. var aspectRatio;
  21633. var idClass; // The aspect ratio is either used directly or to calculate width and height.
  21634. if (this.aspectRatio_ !== undefined && this.aspectRatio_ !== 'auto') {
  21635. // Use any aspectRatio that's been specifically set
  21636. aspectRatio = this.aspectRatio_;
  21637. } else if (this.videoWidth() > 0) {
  21638. // Otherwise try to get the aspect ratio from the video metadata
  21639. aspectRatio = this.videoWidth() + ':' + this.videoHeight();
  21640. } else {
  21641. // Or use a default. The video element's is 2:1, but 16:9 is more common.
  21642. aspectRatio = '16:9';
  21643. } // Get the ratio as a decimal we can use to calculate dimensions
  21644. var ratioParts = aspectRatio.split(':');
  21645. var ratioMultiplier = ratioParts[1] / ratioParts[0];
  21646. if (this.width_ !== undefined) {
  21647. // Use any width that's been specifically set
  21648. width = this.width_;
  21649. } else if (this.height_ !== undefined) {
  21650. // Or calulate the width from the aspect ratio if a height has been set
  21651. width = this.height_ / ratioMultiplier;
  21652. } else {
  21653. // Or use the video's metadata, or use the video el's default of 300
  21654. width = this.videoWidth() || 300;
  21655. }
  21656. if (this.height_ !== undefined) {
  21657. // Use any height that's been specifically set
  21658. height = this.height_;
  21659. } else {
  21660. // Otherwise calculate the height from the ratio and the width
  21661. height = width * ratioMultiplier;
  21662. } // Ensure the CSS class is valid by starting with an alpha character
  21663. if (/^[^a-zA-Z]/.test(this.id())) {
  21664. idClass = 'dimensions-' + this.id();
  21665. } else {
  21666. idClass = this.id() + '-dimensions';
  21667. } // Ensure the right class is still on the player for the style element
  21668. this.addClass(idClass);
  21669. 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 ");
  21670. }
  21671. /**
  21672. * Load/Create an instance of playback {@link Tech} including element
  21673. * and API methods. Then append the `Tech` element in `Player` as a child.
  21674. *
  21675. * @param {string} techName
  21676. * name of the playback technology
  21677. *
  21678. * @param {string} source
  21679. * video source
  21680. *
  21681. * @private
  21682. */
  21683. ;
  21684. _proto.loadTech_ = function loadTech_(techName, source) {
  21685. var _this4 = this;
  21686. // Pause and remove current playback technology
  21687. if (this.tech_) {
  21688. this.unloadTech_();
  21689. }
  21690. var titleTechName = toTitleCase(techName);
  21691. var camelTechName = techName.charAt(0).toLowerCase() + techName.slice(1); // get rid of the HTML5 video tag as soon as we are using another tech
  21692. if (titleTechName !== 'Html5' && this.tag) {
  21693. Tech.getTech('Html5').disposeMediaElement(this.tag);
  21694. this.tag.player = null;
  21695. this.tag = null;
  21696. }
  21697. this.techName_ = titleTechName; // Turn off API access because we're loading a new tech that might load asynchronously
  21698. this.isReady_ = false;
  21699. var autoplay = this.autoplay(); // if autoplay is a string (or `true` with normalizeAutoplay: true) we pass false to the tech
  21700. // because the player is going to handle autoplay on `loadstart`
  21701. if (typeof this.autoplay() === 'string' || this.autoplay() === true && this.options_.normalizeAutoplay) {
  21702. autoplay = false;
  21703. } // Grab tech-specific options from player options and add source and parent element to use.
  21704. var techOptions = {
  21705. source: source,
  21706. autoplay: autoplay,
  21707. 'nativeControlsForTouch': this.options_.nativeControlsForTouch,
  21708. 'playerId': this.id(),
  21709. 'techId': this.id() + "_" + camelTechName + "_api",
  21710. 'playsinline': this.options_.playsinline,
  21711. 'preload': this.options_.preload,
  21712. 'loop': this.options_.loop,
  21713. 'disablePictureInPicture': this.options_.disablePictureInPicture,
  21714. 'muted': this.options_.muted,
  21715. 'poster': this.poster(),
  21716. 'language': this.language(),
  21717. 'playerElIngest': this.playerElIngest_ || false,
  21718. 'vtt.js': this.options_['vtt.js'],
  21719. 'canOverridePoster': !!this.options_.techCanOverridePoster,
  21720. 'enableSourceset': this.options_.enableSourceset,
  21721. 'Promise': this.options_.Promise
  21722. };
  21723. ALL.names.forEach(function (name) {
  21724. var props = ALL[name];
  21725. techOptions[props.getterName] = _this4[props.privateName];
  21726. });
  21727. assign(techOptions, this.options_[titleTechName]);
  21728. assign(techOptions, this.options_[camelTechName]);
  21729. assign(techOptions, this.options_[techName.toLowerCase()]);
  21730. if (this.tag) {
  21731. techOptions.tag = this.tag;
  21732. }
  21733. if (source && source.src === this.cache_.src && this.cache_.currentTime > 0) {
  21734. techOptions.startTime = this.cache_.currentTime;
  21735. } // Initialize tech instance
  21736. var TechClass = Tech.getTech(techName);
  21737. if (!TechClass) {
  21738. throw new Error("No Tech named '" + titleTechName + "' exists! '" + titleTechName + "' should be registered using videojs.registerTech()'");
  21739. }
  21740. this.tech_ = new TechClass(techOptions); // player.triggerReady is always async, so don't need this to be async
  21741. this.tech_.ready(bind(this, this.handleTechReady_), true);
  21742. textTrackConverter.jsonToTextTracks(this.textTracksJson_ || [], this.tech_); // Listen to all HTML5-defined events and trigger them on the player
  21743. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  21744. _this4.on(_this4.tech_, event, function (e) {
  21745. return _this4["handleTech" + toTitleCase(event) + "_"](e);
  21746. });
  21747. });
  21748. Object.keys(TECH_EVENTS_QUEUE).forEach(function (event) {
  21749. _this4.on(_this4.tech_, event, function (eventObj) {
  21750. if (_this4.tech_.playbackRate() === 0 && _this4.tech_.seeking()) {
  21751. _this4.queuedCallbacks_.push({
  21752. callback: _this4["handleTech" + TECH_EVENTS_QUEUE[event] + "_"].bind(_this4),
  21753. event: eventObj
  21754. });
  21755. return;
  21756. }
  21757. _this4["handleTech" + TECH_EVENTS_QUEUE[event] + "_"](eventObj);
  21758. });
  21759. });
  21760. this.on(this.tech_, 'loadstart', function (e) {
  21761. return _this4.handleTechLoadStart_(e);
  21762. });
  21763. this.on(this.tech_, 'sourceset', function (e) {
  21764. return _this4.handleTechSourceset_(e);
  21765. });
  21766. this.on(this.tech_, 'waiting', function (e) {
  21767. return _this4.handleTechWaiting_(e);
  21768. });
  21769. this.on(this.tech_, 'ended', function (e) {
  21770. return _this4.handleTechEnded_(e);
  21771. });
  21772. this.on(this.tech_, 'seeking', function (e) {
  21773. return _this4.handleTechSeeking_(e);
  21774. });
  21775. this.on(this.tech_, 'play', function (e) {
  21776. return _this4.handleTechPlay_(e);
  21777. });
  21778. this.on(this.tech_, 'firstplay', function (e) {
  21779. return _this4.handleTechFirstPlay_(e);
  21780. });
  21781. this.on(this.tech_, 'pause', function (e) {
  21782. return _this4.handleTechPause_(e);
  21783. });
  21784. this.on(this.tech_, 'durationchange', function (e) {
  21785. return _this4.handleTechDurationChange_(e);
  21786. });
  21787. this.on(this.tech_, 'fullscreenchange', function (e, data) {
  21788. return _this4.handleTechFullscreenChange_(e, data);
  21789. });
  21790. this.on(this.tech_, 'fullscreenerror', function (e, err) {
  21791. return _this4.handleTechFullscreenError_(e, err);
  21792. });
  21793. this.on(this.tech_, 'enterpictureinpicture', function (e) {
  21794. return _this4.handleTechEnterPictureInPicture_(e);
  21795. });
  21796. this.on(this.tech_, 'leavepictureinpicture', function (e) {
  21797. return _this4.handleTechLeavePictureInPicture_(e);
  21798. });
  21799. this.on(this.tech_, 'error', function (e) {
  21800. return _this4.handleTechError_(e);
  21801. });
  21802. this.on(this.tech_, 'posterchange', function (e) {
  21803. return _this4.handleTechPosterChange_(e);
  21804. });
  21805. this.on(this.tech_, 'textdata', function (e) {
  21806. return _this4.handleTechTextData_(e);
  21807. });
  21808. this.on(this.tech_, 'ratechange', function (e) {
  21809. return _this4.handleTechRateChange_(e);
  21810. });
  21811. this.on(this.tech_, 'loadedmetadata', this.boundUpdateStyleEl_);
  21812. this.usingNativeControls(this.techGet_('controls'));
  21813. if (this.controls() && !this.usingNativeControls()) {
  21814. this.addTechControlsListeners_();
  21815. } // Add the tech element in the DOM if it was not already there
  21816. // Make sure to not insert the original video element if using Html5
  21817. if (this.tech_.el().parentNode !== this.el() && (titleTechName !== 'Html5' || !this.tag)) {
  21818. prependTo(this.tech_.el(), this.el());
  21819. } // Get rid of the original video tag reference after the first tech is loaded
  21820. if (this.tag) {
  21821. this.tag.player = null;
  21822. this.tag = null;
  21823. }
  21824. }
  21825. /**
  21826. * Unload and dispose of the current playback {@link Tech}.
  21827. *
  21828. * @private
  21829. */
  21830. ;
  21831. _proto.unloadTech_ = function unloadTech_() {
  21832. var _this5 = this;
  21833. // Save the current text tracks so that we can reuse the same text tracks with the next tech
  21834. ALL.names.forEach(function (name) {
  21835. var props = ALL[name];
  21836. _this5[props.privateName] = _this5[props.getterName]();
  21837. });
  21838. this.textTracksJson_ = textTrackConverter.textTracksToJson(this.tech_);
  21839. this.isReady_ = false;
  21840. this.tech_.dispose();
  21841. this.tech_ = false;
  21842. if (this.isPosterFromTech_) {
  21843. this.poster_ = '';
  21844. this.trigger('posterchange');
  21845. }
  21846. this.isPosterFromTech_ = false;
  21847. }
  21848. /**
  21849. * Return a reference to the current {@link Tech}.
  21850. * It will print a warning by default about the danger of using the tech directly
  21851. * but any argument that is passed in will silence the warning.
  21852. *
  21853. * @param {*} [safety]
  21854. * Anything passed in to silence the warning
  21855. *
  21856. * @return {Tech}
  21857. * The Tech
  21858. */
  21859. ;
  21860. _proto.tech = function tech(safety) {
  21861. if (safety === undefined) {
  21862. 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');
  21863. }
  21864. return this.tech_;
  21865. }
  21866. /**
  21867. * Set up click and touch listeners for the playback element
  21868. *
  21869. * - On desktops: a click on the video itself will toggle playback
  21870. * - On mobile devices: a click on the video toggles controls
  21871. * which is done by toggling the user state between active and
  21872. * inactive
  21873. * - A tap can signal that a user has become active or has become inactive
  21874. * e.g. a quick tap on an iPhone movie should reveal the controls. Another
  21875. * quick tap should hide them again (signaling the user is in an inactive
  21876. * viewing state)
  21877. * - In addition to this, we still want the user to be considered inactive after
  21878. * a few seconds of inactivity.
  21879. *
  21880. * > Note: the only part of iOS interaction we can't mimic with this setup
  21881. * is a touch and hold on the video element counting as activity in order to
  21882. * keep the controls showing, but that shouldn't be an issue. A touch and hold
  21883. * on any controls will still keep the user active
  21884. *
  21885. * @private
  21886. */
  21887. ;
  21888. _proto.addTechControlsListeners_ = function addTechControlsListeners_() {
  21889. // Make sure to remove all the previous listeners in case we are called multiple times.
  21890. this.removeTechControlsListeners_();
  21891. this.on(this.tech_, 'click', this.boundHandleTechClick_);
  21892. this.on(this.tech_, 'dblclick', this.boundHandleTechDoubleClick_); // If the controls were hidden we don't want that to change without a tap event
  21893. // so we'll check if the controls were already showing before reporting user
  21894. // activity
  21895. this.on(this.tech_, 'touchstart', this.boundHandleTechTouchStart_);
  21896. this.on(this.tech_, 'touchmove', this.boundHandleTechTouchMove_);
  21897. this.on(this.tech_, 'touchend', this.boundHandleTechTouchEnd_); // The tap listener needs to come after the touchend listener because the tap
  21898. // listener cancels out any reportedUserActivity when setting userActive(false)
  21899. this.on(this.tech_, 'tap', this.boundHandleTechTap_);
  21900. }
  21901. /**
  21902. * Remove the listeners used for click and tap controls. This is needed for
  21903. * toggling to controls disabled, where a tap/touch should do nothing.
  21904. *
  21905. * @private
  21906. */
  21907. ;
  21908. _proto.removeTechControlsListeners_ = function removeTechControlsListeners_() {
  21909. // We don't want to just use `this.off()` because there might be other needed
  21910. // listeners added by techs that extend this.
  21911. this.off(this.tech_, 'tap', this.boundHandleTechTap_);
  21912. this.off(this.tech_, 'touchstart', this.boundHandleTechTouchStart_);
  21913. this.off(this.tech_, 'touchmove', this.boundHandleTechTouchMove_);
  21914. this.off(this.tech_, 'touchend', this.boundHandleTechTouchEnd_);
  21915. this.off(this.tech_, 'click', this.boundHandleTechClick_);
  21916. this.off(this.tech_, 'dblclick', this.boundHandleTechDoubleClick_);
  21917. }
  21918. /**
  21919. * Player waits for the tech to be ready
  21920. *
  21921. * @private
  21922. */
  21923. ;
  21924. _proto.handleTechReady_ = function handleTechReady_() {
  21925. this.triggerReady(); // Keep the same volume as before
  21926. if (this.cache_.volume) {
  21927. this.techCall_('setVolume', this.cache_.volume);
  21928. } // Look if the tech found a higher resolution poster while loading
  21929. this.handleTechPosterChange_(); // Update the duration if available
  21930. this.handleTechDurationChange_();
  21931. }
  21932. /**
  21933. * Retrigger the `loadstart` event that was triggered by the {@link Tech}. This
  21934. * function will also trigger {@link Player#firstplay} if it is the first loadstart
  21935. * for a video.
  21936. *
  21937. * @fires Player#loadstart
  21938. * @fires Player#firstplay
  21939. * @listens Tech#loadstart
  21940. * @private
  21941. */
  21942. ;
  21943. _proto.handleTechLoadStart_ = function handleTechLoadStart_() {
  21944. // TODO: Update to use `emptied` event instead. See #1277.
  21945. this.removeClass('vjs-ended');
  21946. this.removeClass('vjs-seeking'); // reset the error state
  21947. this.error(null); // Update the duration
  21948. this.handleTechDurationChange_(); // If it's already playing we want to trigger a firstplay event now.
  21949. // The firstplay event relies on both the play and loadstart events
  21950. // which can happen in any order for a new source
  21951. if (!this.paused()) {
  21952. /**
  21953. * Fired when the user agent begins looking for media data
  21954. *
  21955. * @event Player#loadstart
  21956. * @type {EventTarget~Event}
  21957. */
  21958. this.trigger('loadstart');
  21959. this.trigger('firstplay');
  21960. } else {
  21961. // reset the hasStarted state
  21962. this.hasStarted(false);
  21963. this.trigger('loadstart');
  21964. } // autoplay happens after loadstart for the browser,
  21965. // so we mimic that behavior
  21966. this.manualAutoplay_(this.autoplay() === true && this.options_.normalizeAutoplay ? 'play' : this.autoplay());
  21967. }
  21968. /**
  21969. * Handle autoplay string values, rather than the typical boolean
  21970. * values that should be handled by the tech. Note that this is not
  21971. * part of any specification. Valid values and what they do can be
  21972. * found on the autoplay getter at Player#autoplay()
  21973. */
  21974. ;
  21975. _proto.manualAutoplay_ = function manualAutoplay_(type) {
  21976. var _this6 = this;
  21977. if (!this.tech_ || typeof type !== 'string') {
  21978. return;
  21979. } // Save original muted() value, set muted to true, and attempt to play().
  21980. // On promise rejection, restore muted from saved value
  21981. var resolveMuted = function resolveMuted() {
  21982. var previouslyMuted = _this6.muted();
  21983. _this6.muted(true);
  21984. var restoreMuted = function restoreMuted() {
  21985. _this6.muted(previouslyMuted);
  21986. }; // restore muted on play terminatation
  21987. _this6.playTerminatedQueue_.push(restoreMuted);
  21988. var mutedPromise = _this6.play();
  21989. if (!isPromise(mutedPromise)) {
  21990. return;
  21991. }
  21992. return mutedPromise["catch"](function (err) {
  21993. restoreMuted();
  21994. throw new Error("Rejection at manualAutoplay. Restoring muted value. " + (err ? err : ''));
  21995. });
  21996. };
  21997. var promise; // if muted defaults to true
  21998. // the only thing we can do is call play
  21999. if (type === 'any' && !this.muted()) {
  22000. promise = this.play();
  22001. if (isPromise(promise)) {
  22002. promise = promise["catch"](resolveMuted);
  22003. }
  22004. } else if (type === 'muted' && !this.muted()) {
  22005. promise = resolveMuted();
  22006. } else {
  22007. promise = this.play();
  22008. }
  22009. if (!isPromise(promise)) {
  22010. return;
  22011. }
  22012. return promise.then(function () {
  22013. _this6.trigger({
  22014. type: 'autoplay-success',
  22015. autoplay: type
  22016. });
  22017. })["catch"](function () {
  22018. _this6.trigger({
  22019. type: 'autoplay-failure',
  22020. autoplay: type
  22021. });
  22022. });
  22023. }
  22024. /**
  22025. * Update the internal source caches so that we return the correct source from
  22026. * `src()`, `currentSource()`, and `currentSources()`.
  22027. *
  22028. * > Note: `currentSources` will not be updated if the source that is passed in exists
  22029. * in the current `currentSources` cache.
  22030. *
  22031. *
  22032. * @param {Tech~SourceObject} srcObj
  22033. * A string or object source to update our caches to.
  22034. */
  22035. ;
  22036. _proto.updateSourceCaches_ = function updateSourceCaches_(srcObj) {
  22037. if (srcObj === void 0) {
  22038. srcObj = '';
  22039. }
  22040. var src = srcObj;
  22041. var type = '';
  22042. if (typeof src !== 'string') {
  22043. src = srcObj.src;
  22044. type = srcObj.type;
  22045. } // make sure all the caches are set to default values
  22046. // to prevent null checking
  22047. this.cache_.source = this.cache_.source || {};
  22048. this.cache_.sources = this.cache_.sources || []; // try to get the type of the src that was passed in
  22049. if (src && !type) {
  22050. type = findMimetype(this, src);
  22051. } // update `currentSource` cache always
  22052. this.cache_.source = mergeOptions({}, srcObj, {
  22053. src: src,
  22054. type: type
  22055. });
  22056. var matchingSources = this.cache_.sources.filter(function (s) {
  22057. return s.src && s.src === src;
  22058. });
  22059. var sourceElSources = [];
  22060. var sourceEls = this.$$('source');
  22061. var matchingSourceEls = [];
  22062. for (var i = 0; i < sourceEls.length; i++) {
  22063. var sourceObj = getAttributes(sourceEls[i]);
  22064. sourceElSources.push(sourceObj);
  22065. if (sourceObj.src && sourceObj.src === src) {
  22066. matchingSourceEls.push(sourceObj.src);
  22067. }
  22068. } // if we have matching source els but not matching sources
  22069. // the current source cache is not up to date
  22070. if (matchingSourceEls.length && !matchingSources.length) {
  22071. this.cache_.sources = sourceElSources; // if we don't have matching source or source els set the
  22072. // sources cache to the `currentSource` cache
  22073. } else if (!matchingSources.length) {
  22074. this.cache_.sources = [this.cache_.source];
  22075. } // update the tech `src` cache
  22076. this.cache_.src = src;
  22077. }
  22078. /**
  22079. * *EXPERIMENTAL* Fired when the source is set or changed on the {@link Tech}
  22080. * causing the media element to reload.
  22081. *
  22082. * It will fire for the initial source and each subsequent source.
  22083. * This event is a custom event from Video.js and is triggered by the {@link Tech}.
  22084. *
  22085. * The event object for this event contains a `src` property that will contain the source
  22086. * that was available when the event was triggered. This is generally only necessary if Video.js
  22087. * is switching techs while the source was being changed.
  22088. *
  22089. * It is also fired when `load` is called on the player (or media element)
  22090. * because the {@link https://html.spec.whatwg.org/multipage/media.html#dom-media-load|specification for `load`}
  22091. * says that the resource selection algorithm needs to be aborted and restarted.
  22092. * In this case, it is very likely that the `src` property will be set to the
  22093. * empty string `""` to indicate we do not know what the source will be but
  22094. * that it is changing.
  22095. *
  22096. * *This event is currently still experimental and may change in minor releases.*
  22097. * __To use this, pass `enableSourceset` option to the player.__
  22098. *
  22099. * @event Player#sourceset
  22100. * @type {EventTarget~Event}
  22101. * @prop {string} src
  22102. * The source url available when the `sourceset` was triggered.
  22103. * It will be an empty string if we cannot know what the source is
  22104. * but know that the source will change.
  22105. */
  22106. /**
  22107. * Retrigger the `sourceset` event that was triggered by the {@link Tech}.
  22108. *
  22109. * @fires Player#sourceset
  22110. * @listens Tech#sourceset
  22111. * @private
  22112. */
  22113. ;
  22114. _proto.handleTechSourceset_ = function handleTechSourceset_(event) {
  22115. var _this7 = this;
  22116. // only update the source cache when the source
  22117. // was not updated using the player api
  22118. if (!this.changingSrc_) {
  22119. var updateSourceCaches = function updateSourceCaches(src) {
  22120. return _this7.updateSourceCaches_(src);
  22121. };
  22122. var playerSrc = this.currentSource().src;
  22123. var eventSrc = event.src; // if we have a playerSrc that is not a blob, and a tech src that is a blob
  22124. if (playerSrc && !/^blob:/.test(playerSrc) && /^blob:/.test(eventSrc)) {
  22125. // if both the tech source and the player source were updated we assume
  22126. // something like @videojs/http-streaming did the sourceset and skip updating the source cache.
  22127. if (!this.lastSource_ || this.lastSource_.tech !== eventSrc && this.lastSource_.player !== playerSrc) {
  22128. updateSourceCaches = function updateSourceCaches() {};
  22129. }
  22130. } // update the source to the initial source right away
  22131. // in some cases this will be empty string
  22132. updateSourceCaches(eventSrc); // if the `sourceset` `src` was an empty string
  22133. // wait for a `loadstart` to update the cache to `currentSrc`.
  22134. // If a sourceset happens before a `loadstart`, we reset the state
  22135. if (!event.src) {
  22136. this.tech_.any(['sourceset', 'loadstart'], function (e) {
  22137. // if a sourceset happens before a `loadstart` there
  22138. // is nothing to do as this `handleTechSourceset_`
  22139. // will be called again and this will be handled there.
  22140. if (e.type === 'sourceset') {
  22141. return;
  22142. }
  22143. var techSrc = _this7.techGet('currentSrc');
  22144. _this7.lastSource_.tech = techSrc;
  22145. _this7.updateSourceCaches_(techSrc);
  22146. });
  22147. }
  22148. }
  22149. this.lastSource_ = {
  22150. player: this.currentSource().src,
  22151. tech: event.src
  22152. };
  22153. this.trigger({
  22154. src: event.src,
  22155. type: 'sourceset'
  22156. });
  22157. }
  22158. /**
  22159. * Add/remove the vjs-has-started class
  22160. *
  22161. * @fires Player#firstplay
  22162. *
  22163. * @param {boolean} request
  22164. * - true: adds the class
  22165. * - false: remove the class
  22166. *
  22167. * @return {boolean}
  22168. * the boolean value of hasStarted_
  22169. */
  22170. ;
  22171. _proto.hasStarted = function hasStarted(request) {
  22172. if (request === undefined) {
  22173. // act as getter, if we have no request to change
  22174. return this.hasStarted_;
  22175. }
  22176. if (request === this.hasStarted_) {
  22177. return;
  22178. }
  22179. this.hasStarted_ = request;
  22180. if (this.hasStarted_) {
  22181. this.addClass('vjs-has-started');
  22182. this.trigger('firstplay');
  22183. } else {
  22184. this.removeClass('vjs-has-started');
  22185. }
  22186. }
  22187. /**
  22188. * Fired whenever the media begins or resumes playback
  22189. *
  22190. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play}
  22191. * @fires Player#play
  22192. * @listens Tech#play
  22193. * @private
  22194. */
  22195. ;
  22196. _proto.handleTechPlay_ = function handleTechPlay_() {
  22197. this.removeClass('vjs-ended');
  22198. this.removeClass('vjs-paused');
  22199. this.addClass('vjs-playing'); // hide the poster when the user hits play
  22200. this.hasStarted(true);
  22201. /**
  22202. * Triggered whenever an {@link Tech#play} event happens. Indicates that
  22203. * playback has started or resumed.
  22204. *
  22205. * @event Player#play
  22206. * @type {EventTarget~Event}
  22207. */
  22208. this.trigger('play');
  22209. }
  22210. /**
  22211. * Retrigger the `ratechange` event that was triggered by the {@link Tech}.
  22212. *
  22213. * If there were any events queued while the playback rate was zero, fire
  22214. * those events now.
  22215. *
  22216. * @private
  22217. * @method Player#handleTechRateChange_
  22218. * @fires Player#ratechange
  22219. * @listens Tech#ratechange
  22220. */
  22221. ;
  22222. _proto.handleTechRateChange_ = function handleTechRateChange_() {
  22223. if (this.tech_.playbackRate() > 0 && this.cache_.lastPlaybackRate === 0) {
  22224. this.queuedCallbacks_.forEach(function (queued) {
  22225. return queued.callback(queued.event);
  22226. });
  22227. this.queuedCallbacks_ = [];
  22228. }
  22229. this.cache_.lastPlaybackRate = this.tech_.playbackRate();
  22230. /**
  22231. * Fires when the playing speed of the audio/video is changed
  22232. *
  22233. * @event Player#ratechange
  22234. * @type {event}
  22235. */
  22236. this.trigger('ratechange');
  22237. }
  22238. /**
  22239. * Retrigger the `waiting` event that was triggered by the {@link Tech}.
  22240. *
  22241. * @fires Player#waiting
  22242. * @listens Tech#waiting
  22243. * @private
  22244. */
  22245. ;
  22246. _proto.handleTechWaiting_ = function handleTechWaiting_() {
  22247. var _this8 = this;
  22248. this.addClass('vjs-waiting');
  22249. /**
  22250. * A readyState change on the DOM element has caused playback to stop.
  22251. *
  22252. * @event Player#waiting
  22253. * @type {EventTarget~Event}
  22254. */
  22255. this.trigger('waiting'); // Browsers may emit a timeupdate event after a waiting event. In order to prevent
  22256. // premature removal of the waiting class, wait for the time to change.
  22257. var timeWhenWaiting = this.currentTime();
  22258. var timeUpdateListener = function timeUpdateListener() {
  22259. if (timeWhenWaiting !== _this8.currentTime()) {
  22260. _this8.removeClass('vjs-waiting');
  22261. _this8.off('timeupdate', timeUpdateListener);
  22262. }
  22263. };
  22264. this.on('timeupdate', timeUpdateListener);
  22265. }
  22266. /**
  22267. * Retrigger the `canplay` event that was triggered by the {@link Tech}.
  22268. * > Note: This is not consistent between browsers. See #1351
  22269. *
  22270. * @fires Player#canplay
  22271. * @listens Tech#canplay
  22272. * @private
  22273. */
  22274. ;
  22275. _proto.handleTechCanPlay_ = function handleTechCanPlay_() {
  22276. this.removeClass('vjs-waiting');
  22277. /**
  22278. * The media has a readyState of HAVE_FUTURE_DATA or greater.
  22279. *
  22280. * @event Player#canplay
  22281. * @type {EventTarget~Event}
  22282. */
  22283. this.trigger('canplay');
  22284. }
  22285. /**
  22286. * Retrigger the `canplaythrough` event that was triggered by the {@link Tech}.
  22287. *
  22288. * @fires Player#canplaythrough
  22289. * @listens Tech#canplaythrough
  22290. * @private
  22291. */
  22292. ;
  22293. _proto.handleTechCanPlayThrough_ = function handleTechCanPlayThrough_() {
  22294. this.removeClass('vjs-waiting');
  22295. /**
  22296. * The media has a readyState of HAVE_ENOUGH_DATA or greater. This means that the
  22297. * entire media file can be played without buffering.
  22298. *
  22299. * @event Player#canplaythrough
  22300. * @type {EventTarget~Event}
  22301. */
  22302. this.trigger('canplaythrough');
  22303. }
  22304. /**
  22305. * Retrigger the `playing` event that was triggered by the {@link Tech}.
  22306. *
  22307. * @fires Player#playing
  22308. * @listens Tech#playing
  22309. * @private
  22310. */
  22311. ;
  22312. _proto.handleTechPlaying_ = function handleTechPlaying_() {
  22313. this.removeClass('vjs-waiting');
  22314. /**
  22315. * The media is no longer blocked from playback, and has started playing.
  22316. *
  22317. * @event Player#playing
  22318. * @type {EventTarget~Event}
  22319. */
  22320. this.trigger('playing');
  22321. }
  22322. /**
  22323. * Retrigger the `seeking` event that was triggered by the {@link Tech}.
  22324. *
  22325. * @fires Player#seeking
  22326. * @listens Tech#seeking
  22327. * @private
  22328. */
  22329. ;
  22330. _proto.handleTechSeeking_ = function handleTechSeeking_() {
  22331. this.addClass('vjs-seeking');
  22332. /**
  22333. * Fired whenever the player is jumping to a new time
  22334. *
  22335. * @event Player#seeking
  22336. * @type {EventTarget~Event}
  22337. */
  22338. this.trigger('seeking');
  22339. }
  22340. /**
  22341. * Retrigger the `seeked` event that was triggered by the {@link Tech}.
  22342. *
  22343. * @fires Player#seeked
  22344. * @listens Tech#seeked
  22345. * @private
  22346. */
  22347. ;
  22348. _proto.handleTechSeeked_ = function handleTechSeeked_() {
  22349. this.removeClass('vjs-seeking');
  22350. this.removeClass('vjs-ended');
  22351. /**
  22352. * Fired when the player has finished jumping to a new time
  22353. *
  22354. * @event Player#seeked
  22355. * @type {EventTarget~Event}
  22356. */
  22357. this.trigger('seeked');
  22358. }
  22359. /**
  22360. * Retrigger the `firstplay` event that was triggered by the {@link Tech}.
  22361. *
  22362. * @fires Player#firstplay
  22363. * @listens Tech#firstplay
  22364. * @deprecated As of 6.0 firstplay event is deprecated.
  22365. * As of 6.0 passing the `starttime` option to the player and the firstplay event are deprecated.
  22366. * @private
  22367. */
  22368. ;
  22369. _proto.handleTechFirstPlay_ = function handleTechFirstPlay_() {
  22370. // If the first starttime attribute is specified
  22371. // then we will start at the given offset in seconds
  22372. if (this.options_.starttime) {
  22373. log.warn('Passing the `starttime` option to the player will be deprecated in 6.0');
  22374. this.currentTime(this.options_.starttime);
  22375. }
  22376. this.addClass('vjs-has-started');
  22377. /**
  22378. * Fired the first time a video is played. Not part of the HLS spec, and this is
  22379. * probably not the best implementation yet, so use sparingly. If you don't have a
  22380. * reason to prevent playback, use `myPlayer.one('play');` instead.
  22381. *
  22382. * @event Player#firstplay
  22383. * @deprecated As of 6.0 firstplay event is deprecated.
  22384. * @type {EventTarget~Event}
  22385. */
  22386. this.trigger('firstplay');
  22387. }
  22388. /**
  22389. * Retrigger the `pause` event that was triggered by the {@link Tech}.
  22390. *
  22391. * @fires Player#pause
  22392. * @listens Tech#pause
  22393. * @private
  22394. */
  22395. ;
  22396. _proto.handleTechPause_ = function handleTechPause_() {
  22397. this.removeClass('vjs-playing');
  22398. this.addClass('vjs-paused');
  22399. /**
  22400. * Fired whenever the media has been paused
  22401. *
  22402. * @event Player#pause
  22403. * @type {EventTarget~Event}
  22404. */
  22405. this.trigger('pause');
  22406. }
  22407. /**
  22408. * Retrigger the `ended` event that was triggered by the {@link Tech}.
  22409. *
  22410. * @fires Player#ended
  22411. * @listens Tech#ended
  22412. * @private
  22413. */
  22414. ;
  22415. _proto.handleTechEnded_ = function handleTechEnded_() {
  22416. this.addClass('vjs-ended');
  22417. this.removeClass('vjs-waiting');
  22418. if (this.options_.loop) {
  22419. this.currentTime(0);
  22420. this.play();
  22421. } else if (!this.paused()) {
  22422. this.pause();
  22423. }
  22424. /**
  22425. * Fired when the end of the media resource is reached (currentTime == duration)
  22426. *
  22427. * @event Player#ended
  22428. * @type {EventTarget~Event}
  22429. */
  22430. this.trigger('ended');
  22431. }
  22432. /**
  22433. * Fired when the duration of the media resource is first known or changed
  22434. *
  22435. * @listens Tech#durationchange
  22436. * @private
  22437. */
  22438. ;
  22439. _proto.handleTechDurationChange_ = function handleTechDurationChange_() {
  22440. this.duration(this.techGet_('duration'));
  22441. }
  22442. /**
  22443. * Handle a click on the media element to play/pause
  22444. *
  22445. * @param {EventTarget~Event} event
  22446. * the event that caused this function to trigger
  22447. *
  22448. * @listens Tech#click
  22449. * @private
  22450. */
  22451. ;
  22452. _proto.handleTechClick_ = function handleTechClick_(event) {
  22453. // When controls are disabled a click should not toggle playback because
  22454. // the click is considered a control
  22455. if (!this.controls_) {
  22456. return;
  22457. }
  22458. if (this.options_ === undefined || this.options_.userActions === undefined || this.options_.userActions.click === undefined || this.options_.userActions.click !== false) {
  22459. if (this.options_ !== undefined && this.options_.userActions !== undefined && typeof this.options_.userActions.click === 'function') {
  22460. this.options_.userActions.click.call(this, event);
  22461. } else if (this.paused()) {
  22462. silencePromise(this.play());
  22463. } else {
  22464. this.pause();
  22465. }
  22466. }
  22467. }
  22468. /**
  22469. * Handle a double-click on the media element to enter/exit fullscreen
  22470. *
  22471. * @param {EventTarget~Event} event
  22472. * the event that caused this function to trigger
  22473. *
  22474. * @listens Tech#dblclick
  22475. * @private
  22476. */
  22477. ;
  22478. _proto.handleTechDoubleClick_ = function handleTechDoubleClick_(event) {
  22479. if (!this.controls_) {
  22480. return;
  22481. } // we do not want to toggle fullscreen state
  22482. // when double-clicking inside a control bar or a modal
  22483. var inAllowedEls = Array.prototype.some.call(this.$$('.vjs-control-bar, .vjs-modal-dialog'), function (el) {
  22484. return el.contains(event.target);
  22485. });
  22486. if (!inAllowedEls) {
  22487. /*
  22488. * options.userActions.doubleClick
  22489. *
  22490. * If `undefined` or `true`, double-click toggles fullscreen if controls are present
  22491. * Set to `false` to disable double-click handling
  22492. * Set to a function to substitute an external double-click handler
  22493. */
  22494. if (this.options_ === undefined || this.options_.userActions === undefined || this.options_.userActions.doubleClick === undefined || this.options_.userActions.doubleClick !== false) {
  22495. if (this.options_ !== undefined && this.options_.userActions !== undefined && typeof this.options_.userActions.doubleClick === 'function') {
  22496. this.options_.userActions.doubleClick.call(this, event);
  22497. } else if (this.isFullscreen()) {
  22498. this.exitFullscreen();
  22499. } else {
  22500. this.requestFullscreen();
  22501. }
  22502. }
  22503. }
  22504. }
  22505. /**
  22506. * Handle a tap on the media element. It will toggle the user
  22507. * activity state, which hides and shows the controls.
  22508. *
  22509. * @listens Tech#tap
  22510. * @private
  22511. */
  22512. ;
  22513. _proto.handleTechTap_ = function handleTechTap_() {
  22514. this.userActive(!this.userActive());
  22515. }
  22516. /**
  22517. * Handle touch to start
  22518. *
  22519. * @listens Tech#touchstart
  22520. * @private
  22521. */
  22522. ;
  22523. _proto.handleTechTouchStart_ = function handleTechTouchStart_() {
  22524. this.userWasActive = this.userActive();
  22525. }
  22526. /**
  22527. * Handle touch to move
  22528. *
  22529. * @listens Tech#touchmove
  22530. * @private
  22531. */
  22532. ;
  22533. _proto.handleTechTouchMove_ = function handleTechTouchMove_() {
  22534. if (this.userWasActive) {
  22535. this.reportUserActivity();
  22536. }
  22537. }
  22538. /**
  22539. * Handle touch to end
  22540. *
  22541. * @param {EventTarget~Event} event
  22542. * the touchend event that triggered
  22543. * this function
  22544. *
  22545. * @listens Tech#touchend
  22546. * @private
  22547. */
  22548. ;
  22549. _proto.handleTechTouchEnd_ = function handleTechTouchEnd_(event) {
  22550. // Stop the mouse events from also happening
  22551. if (event.cancelable) {
  22552. event.preventDefault();
  22553. }
  22554. }
  22555. /**
  22556. * native click events on the SWF aren't triggered on IE11, Win8.1RT
  22557. * use stageclick events triggered from inside the SWF instead
  22558. *
  22559. * @private
  22560. * @listens stageclick
  22561. */
  22562. ;
  22563. _proto.handleStageClick_ = function handleStageClick_() {
  22564. this.reportUserActivity();
  22565. }
  22566. /**
  22567. * @private
  22568. */
  22569. ;
  22570. _proto.toggleFullscreenClass_ = function toggleFullscreenClass_() {
  22571. if (this.isFullscreen()) {
  22572. this.addClass('vjs-fullscreen');
  22573. } else {
  22574. this.removeClass('vjs-fullscreen');
  22575. }
  22576. }
  22577. /**
  22578. * when the document fschange event triggers it calls this
  22579. */
  22580. ;
  22581. _proto.documentFullscreenChange_ = function documentFullscreenChange_(e) {
  22582. var targetPlayer = e.target.player; // if another player was fullscreen
  22583. // do a null check for targetPlayer because older firefox's would put document as e.target
  22584. if (targetPlayer && targetPlayer !== this) {
  22585. return;
  22586. }
  22587. var el = this.el();
  22588. var isFs = document[this.fsApi_.fullscreenElement] === el;
  22589. if (!isFs && el.matches) {
  22590. isFs = el.matches(':' + this.fsApi_.fullscreen);
  22591. } else if (!isFs && el.msMatchesSelector) {
  22592. isFs = el.msMatchesSelector(':' + this.fsApi_.fullscreen);
  22593. }
  22594. this.isFullscreen(isFs);
  22595. }
  22596. /**
  22597. * Handle Tech Fullscreen Change
  22598. *
  22599. * @param {EventTarget~Event} event
  22600. * the fullscreenchange event that triggered this function
  22601. *
  22602. * @param {Object} data
  22603. * the data that was sent with the event
  22604. *
  22605. * @private
  22606. * @listens Tech#fullscreenchange
  22607. * @fires Player#fullscreenchange
  22608. */
  22609. ;
  22610. _proto.handleTechFullscreenChange_ = function handleTechFullscreenChange_(event, data) {
  22611. var _this9 = this;
  22612. if (data) {
  22613. if (data.nativeIOSFullscreen) {
  22614. this.addClass('vjs-ios-native-fs');
  22615. this.tech_.one('webkitendfullscreen', function () {
  22616. _this9.removeClass('vjs-ios-native-fs');
  22617. });
  22618. }
  22619. this.isFullscreen(data.isFullscreen);
  22620. }
  22621. };
  22622. _proto.handleTechFullscreenError_ = function handleTechFullscreenError_(event, err) {
  22623. this.trigger('fullscreenerror', err);
  22624. }
  22625. /**
  22626. * @private
  22627. */
  22628. ;
  22629. _proto.togglePictureInPictureClass_ = function togglePictureInPictureClass_() {
  22630. if (this.isInPictureInPicture()) {
  22631. this.addClass('vjs-picture-in-picture');
  22632. } else {
  22633. this.removeClass('vjs-picture-in-picture');
  22634. }
  22635. }
  22636. /**
  22637. * Handle Tech Enter Picture-in-Picture.
  22638. *
  22639. * @param {EventTarget~Event} event
  22640. * the enterpictureinpicture event that triggered this function
  22641. *
  22642. * @private
  22643. * @listens Tech#enterpictureinpicture
  22644. */
  22645. ;
  22646. _proto.handleTechEnterPictureInPicture_ = function handleTechEnterPictureInPicture_(event) {
  22647. this.isInPictureInPicture(true);
  22648. }
  22649. /**
  22650. * Handle Tech Leave Picture-in-Picture.
  22651. *
  22652. * @param {EventTarget~Event} event
  22653. * the leavepictureinpicture event that triggered this function
  22654. *
  22655. * @private
  22656. * @listens Tech#leavepictureinpicture
  22657. */
  22658. ;
  22659. _proto.handleTechLeavePictureInPicture_ = function handleTechLeavePictureInPicture_(event) {
  22660. this.isInPictureInPicture(false);
  22661. }
  22662. /**
  22663. * Fires when an error occurred during the loading of an audio/video.
  22664. *
  22665. * @private
  22666. * @listens Tech#error
  22667. */
  22668. ;
  22669. _proto.handleTechError_ = function handleTechError_() {
  22670. var error = this.tech_.error();
  22671. this.error(error);
  22672. }
  22673. /**
  22674. * Retrigger the `textdata` event that was triggered by the {@link Tech}.
  22675. *
  22676. * @fires Player#textdata
  22677. * @listens Tech#textdata
  22678. * @private
  22679. */
  22680. ;
  22681. _proto.handleTechTextData_ = function handleTechTextData_() {
  22682. var data = null;
  22683. if (arguments.length > 1) {
  22684. data = arguments[1];
  22685. }
  22686. /**
  22687. * Fires when we get a textdata event from tech
  22688. *
  22689. * @event Player#textdata
  22690. * @type {EventTarget~Event}
  22691. */
  22692. this.trigger('textdata', data);
  22693. }
  22694. /**
  22695. * Get object for cached values.
  22696. *
  22697. * @return {Object}
  22698. * get the current object cache
  22699. */
  22700. ;
  22701. _proto.getCache = function getCache() {
  22702. return this.cache_;
  22703. }
  22704. /**
  22705. * Resets the internal cache object.
  22706. *
  22707. * Using this function outside the player constructor or reset method may
  22708. * have unintended side-effects.
  22709. *
  22710. * @private
  22711. */
  22712. ;
  22713. _proto.resetCache_ = function resetCache_() {
  22714. this.cache_ = {
  22715. // Right now, the currentTime is not _really_ cached because it is always
  22716. // retrieved from the tech (see: currentTime). However, for completeness,
  22717. // we set it to zero here to ensure that if we do start actually caching
  22718. // it, we reset it along with everything else.
  22719. currentTime: 0,
  22720. initTime: 0,
  22721. inactivityTimeout: this.options_.inactivityTimeout,
  22722. duration: NaN,
  22723. lastVolume: 1,
  22724. lastPlaybackRate: this.defaultPlaybackRate(),
  22725. media: null,
  22726. src: '',
  22727. source: {},
  22728. sources: [],
  22729. playbackRates: [],
  22730. volume: 1
  22731. };
  22732. }
  22733. /**
  22734. * Pass values to the playback tech
  22735. *
  22736. * @param {string} [method]
  22737. * the method to call
  22738. *
  22739. * @param {Object} arg
  22740. * the argument to pass
  22741. *
  22742. * @private
  22743. */
  22744. ;
  22745. _proto.techCall_ = function techCall_(method, arg) {
  22746. // If it's not ready yet, call method when it is
  22747. this.ready(function () {
  22748. if (method in allowedSetters) {
  22749. return set(this.middleware_, this.tech_, method, arg);
  22750. } else if (method in allowedMediators) {
  22751. return mediate(this.middleware_, this.tech_, method, arg);
  22752. }
  22753. try {
  22754. if (this.tech_) {
  22755. this.tech_[method](arg);
  22756. }
  22757. } catch (e) {
  22758. log(e);
  22759. throw e;
  22760. }
  22761. }, true);
  22762. }
  22763. /**
  22764. * Get calls can't wait for the tech, and sometimes don't need to.
  22765. *
  22766. * @param {string} method
  22767. * Tech method
  22768. *
  22769. * @return {Function|undefined}
  22770. * the method or undefined
  22771. *
  22772. * @private
  22773. */
  22774. ;
  22775. _proto.techGet_ = function techGet_(method) {
  22776. if (!this.tech_ || !this.tech_.isReady_) {
  22777. return;
  22778. }
  22779. if (method in allowedGetters) {
  22780. return get(this.middleware_, this.tech_, method);
  22781. } else if (method in allowedMediators) {
  22782. return mediate(this.middleware_, this.tech_, method);
  22783. } // Flash likes to die and reload when you hide or reposition it.
  22784. // In these cases the object methods go away and we get errors.
  22785. // TODO: Is this needed for techs other than Flash?
  22786. // When that happens we'll catch the errors and inform tech that it's not ready any more.
  22787. try {
  22788. return this.tech_[method]();
  22789. } catch (e) {
  22790. // When building additional tech libs, an expected method may not be defined yet
  22791. if (this.tech_[method] === undefined) {
  22792. log("Video.js: " + method + " method not defined for " + this.techName_ + " playback technology.", e);
  22793. throw e;
  22794. } // When a method isn't available on the object it throws a TypeError
  22795. if (e.name === 'TypeError') {
  22796. log("Video.js: " + method + " unavailable on " + this.techName_ + " playback technology element.", e);
  22797. this.tech_.isReady_ = false;
  22798. throw e;
  22799. } // If error unknown, just log and throw
  22800. log(e);
  22801. throw e;
  22802. }
  22803. }
  22804. /**
  22805. * Attempt to begin playback at the first opportunity.
  22806. *
  22807. * @return {Promise|undefined}
  22808. * Returns a promise if the browser supports Promises (or one
  22809. * was passed in as an option). This promise will be resolved on
  22810. * the return value of play. If this is undefined it will fulfill the
  22811. * promise chain otherwise the promise chain will be fulfilled when
  22812. * the promise from play is fulfilled.
  22813. */
  22814. ;
  22815. _proto.play = function play() {
  22816. var _this10 = this;
  22817. var PromiseClass = this.options_.Promise || window.Promise;
  22818. if (PromiseClass) {
  22819. return new PromiseClass(function (resolve) {
  22820. _this10.play_(resolve);
  22821. });
  22822. }
  22823. return this.play_();
  22824. }
  22825. /**
  22826. * The actual logic for play, takes a callback that will be resolved on the
  22827. * return value of play. This allows us to resolve to the play promise if there
  22828. * is one on modern browsers.
  22829. *
  22830. * @private
  22831. * @param {Function} [callback]
  22832. * The callback that should be called when the techs play is actually called
  22833. */
  22834. ;
  22835. _proto.play_ = function play_(callback) {
  22836. var _this11 = this;
  22837. if (callback === void 0) {
  22838. callback = silencePromise;
  22839. }
  22840. this.playCallbacks_.push(callback);
  22841. var isSrcReady = Boolean(!this.changingSrc_ && (this.src() || this.currentSrc()));
  22842. var isSafariOrIOS = Boolean(IS_ANY_SAFARI || IS_IOS); // treat calls to play_ somewhat like the `one` event function
  22843. if (this.waitToPlay_) {
  22844. this.off(['ready', 'loadstart'], this.waitToPlay_);
  22845. this.waitToPlay_ = null;
  22846. } // if the player/tech is not ready or the src itself is not ready
  22847. // queue up a call to play on `ready` or `loadstart`
  22848. if (!this.isReady_ || !isSrcReady) {
  22849. this.waitToPlay_ = function (e) {
  22850. _this11.play_();
  22851. };
  22852. this.one(['ready', 'loadstart'], this.waitToPlay_); // if we are in Safari, there is a high chance that loadstart will trigger after the gesture timeperiod
  22853. // in that case, we need to prime the video element by calling load so it'll be ready in time
  22854. if (!isSrcReady && isSafariOrIOS) {
  22855. this.load();
  22856. }
  22857. return;
  22858. } // If the player/tech is ready and we have a source, we can attempt playback.
  22859. var val = this.techGet_('play'); // For native playback, reset the progress bar if we get a play call from a replay.
  22860. var isNativeReplay = isSafariOrIOS && this.hasClass('vjs-ended');
  22861. if (isNativeReplay) {
  22862. this.resetProgressBar_();
  22863. } // play was terminated if the returned value is null
  22864. if (val === null) {
  22865. this.runPlayTerminatedQueue_();
  22866. } else {
  22867. this.runPlayCallbacks_(val);
  22868. }
  22869. }
  22870. /**
  22871. * These functions will be run when if play is terminated. If play
  22872. * runPlayCallbacks_ is run these function will not be run. This allows us
  22873. * to differenciate between a terminated play and an actual call to play.
  22874. */
  22875. ;
  22876. _proto.runPlayTerminatedQueue_ = function runPlayTerminatedQueue_() {
  22877. var queue = this.playTerminatedQueue_.slice(0);
  22878. this.playTerminatedQueue_ = [];
  22879. queue.forEach(function (q) {
  22880. q();
  22881. });
  22882. }
  22883. /**
  22884. * When a callback to play is delayed we have to run these
  22885. * callbacks when play is actually called on the tech. This function
  22886. * runs the callbacks that were delayed and accepts the return value
  22887. * from the tech.
  22888. *
  22889. * @param {undefined|Promise} val
  22890. * The return value from the tech.
  22891. */
  22892. ;
  22893. _proto.runPlayCallbacks_ = function runPlayCallbacks_(val) {
  22894. var callbacks = this.playCallbacks_.slice(0);
  22895. this.playCallbacks_ = []; // clear play terminatedQueue since we finished a real play
  22896. this.playTerminatedQueue_ = [];
  22897. callbacks.forEach(function (cb) {
  22898. cb(val);
  22899. });
  22900. }
  22901. /**
  22902. * Pause the video playback
  22903. *
  22904. * @return {Player}
  22905. * A reference to the player object this function was called on
  22906. */
  22907. ;
  22908. _proto.pause = function pause() {
  22909. this.techCall_('pause');
  22910. }
  22911. /**
  22912. * Check if the player is paused or has yet to play
  22913. *
  22914. * @return {boolean}
  22915. * - false: if the media is currently playing
  22916. * - true: if media is not currently playing
  22917. */
  22918. ;
  22919. _proto.paused = function paused() {
  22920. // The initial state of paused should be true (in Safari it's actually false)
  22921. return this.techGet_('paused') === false ? false : true;
  22922. }
  22923. /**
  22924. * Get a TimeRange object representing the current ranges of time that the user
  22925. * has played.
  22926. *
  22927. * @return {TimeRange}
  22928. * A time range object that represents all the increments of time that have
  22929. * been played.
  22930. */
  22931. ;
  22932. _proto.played = function played() {
  22933. return this.techGet_('played') || createTimeRanges(0, 0);
  22934. }
  22935. /**
  22936. * Returns whether or not the user is "scrubbing". Scrubbing is
  22937. * when the user has clicked the progress bar handle and is
  22938. * dragging it along the progress bar.
  22939. *
  22940. * @param {boolean} [isScrubbing]
  22941. * whether the user is or is not scrubbing
  22942. *
  22943. * @return {boolean}
  22944. * The value of scrubbing when getting
  22945. */
  22946. ;
  22947. _proto.scrubbing = function scrubbing(isScrubbing) {
  22948. if (typeof isScrubbing === 'undefined') {
  22949. return this.scrubbing_;
  22950. }
  22951. this.scrubbing_ = !!isScrubbing;
  22952. this.techCall_('setScrubbing', this.scrubbing_);
  22953. if (isScrubbing) {
  22954. this.addClass('vjs-scrubbing');
  22955. } else {
  22956. this.removeClass('vjs-scrubbing');
  22957. }
  22958. }
  22959. /**
  22960. * Get or set the current time (in seconds)
  22961. *
  22962. * @param {number|string} [seconds]
  22963. * The time to seek to in seconds
  22964. *
  22965. * @return {number}
  22966. * - the current time in seconds when getting
  22967. */
  22968. ;
  22969. _proto.currentTime = function currentTime(seconds) {
  22970. if (typeof seconds !== 'undefined') {
  22971. if (seconds < 0) {
  22972. seconds = 0;
  22973. }
  22974. if (!this.isReady_ || this.changingSrc_ || !this.tech_ || !this.tech_.isReady_) {
  22975. this.cache_.initTime = seconds;
  22976. this.off('canplay', this.boundApplyInitTime_);
  22977. this.one('canplay', this.boundApplyInitTime_);
  22978. return;
  22979. }
  22980. this.techCall_('setCurrentTime', seconds);
  22981. this.cache_.initTime = 0;
  22982. return;
  22983. } // cache last currentTime and return. default to 0 seconds
  22984. //
  22985. // Caching the currentTime is meant to prevent a massive amount of reads on the tech's
  22986. // currentTime when scrubbing, but may not provide much performance benefit afterall.
  22987. // Should be tested. Also something has to read the actual current time or the cache will
  22988. // never get updated.
  22989. this.cache_.currentTime = this.techGet_('currentTime') || 0;
  22990. return this.cache_.currentTime;
  22991. }
  22992. /**
  22993. * Apply the value of initTime stored in cache as currentTime.
  22994. *
  22995. * @private
  22996. */
  22997. ;
  22998. _proto.applyInitTime_ = function applyInitTime_() {
  22999. this.currentTime(this.cache_.initTime);
  23000. }
  23001. /**
  23002. * Normally gets the length in time of the video in seconds;
  23003. * in all but the rarest use cases an argument will NOT be passed to the method
  23004. *
  23005. * > **NOTE**: The video must have started loading before the duration can be
  23006. * known, and depending on preload behaviour may not be known until the video starts
  23007. * playing.
  23008. *
  23009. * @fires Player#durationchange
  23010. *
  23011. * @param {number} [seconds]
  23012. * The duration of the video to set in seconds
  23013. *
  23014. * @return {number}
  23015. * - The duration of the video in seconds when getting
  23016. */
  23017. ;
  23018. _proto.duration = function duration(seconds) {
  23019. if (seconds === undefined) {
  23020. // return NaN if the duration is not known
  23021. return this.cache_.duration !== undefined ? this.cache_.duration : NaN;
  23022. }
  23023. seconds = parseFloat(seconds); // Standardize on Infinity for signaling video is live
  23024. if (seconds < 0) {
  23025. seconds = Infinity;
  23026. }
  23027. if (seconds !== this.cache_.duration) {
  23028. // Cache the last set value for optimized scrubbing (esp. Flash)
  23029. // TODO: Required for techs other than Flash?
  23030. this.cache_.duration = seconds;
  23031. if (seconds === Infinity) {
  23032. this.addClass('vjs-live');
  23033. } else {
  23034. this.removeClass('vjs-live');
  23035. }
  23036. if (!isNaN(seconds)) {
  23037. // Do not fire durationchange unless the duration value is known.
  23038. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  23039. /**
  23040. * @event Player#durationchange
  23041. * @type {EventTarget~Event}
  23042. */
  23043. this.trigger('durationchange');
  23044. }
  23045. }
  23046. }
  23047. /**
  23048. * Calculates how much time is left in the video. Not part
  23049. * of the native video API.
  23050. *
  23051. * @return {number}
  23052. * The time remaining in seconds
  23053. */
  23054. ;
  23055. _proto.remainingTime = function remainingTime() {
  23056. return this.duration() - this.currentTime();
  23057. }
  23058. /**
  23059. * A remaining time function that is intented to be used when
  23060. * the time is to be displayed directly to the user.
  23061. *
  23062. * @return {number}
  23063. * The rounded time remaining in seconds
  23064. */
  23065. ;
  23066. _proto.remainingTimeDisplay = function remainingTimeDisplay() {
  23067. return Math.floor(this.duration()) - Math.floor(this.currentTime());
  23068. } //
  23069. // Kind of like an array of portions of the video that have been downloaded.
  23070. /**
  23071. * Get a TimeRange object with an array of the times of the video
  23072. * that have been downloaded. If you just want the percent of the
  23073. * video that's been downloaded, use bufferedPercent.
  23074. *
  23075. * @see [Buffered Spec]{@link http://dev.w3.org/html5/spec/video.html#dom-media-buffered}
  23076. *
  23077. * @return {TimeRange}
  23078. * A mock TimeRange object (following HTML spec)
  23079. */
  23080. ;
  23081. _proto.buffered = function buffered() {
  23082. var buffered = this.techGet_('buffered');
  23083. if (!buffered || !buffered.length) {
  23084. buffered = createTimeRanges(0, 0);
  23085. }
  23086. return buffered;
  23087. }
  23088. /**
  23089. * Get the percent (as a decimal) of the video that's been downloaded.
  23090. * This method is not a part of the native HTML video API.
  23091. *
  23092. * @return {number}
  23093. * A decimal between 0 and 1 representing the percent
  23094. * that is buffered 0 being 0% and 1 being 100%
  23095. */
  23096. ;
  23097. _proto.bufferedPercent = function bufferedPercent$1() {
  23098. return bufferedPercent(this.buffered(), this.duration());
  23099. }
  23100. /**
  23101. * Get the ending time of the last buffered time range
  23102. * This is used in the progress bar to encapsulate all time ranges.
  23103. *
  23104. * @return {number}
  23105. * The end of the last buffered time range
  23106. */
  23107. ;
  23108. _proto.bufferedEnd = function bufferedEnd() {
  23109. var buffered = this.buffered();
  23110. var duration = this.duration();
  23111. var end = buffered.end(buffered.length - 1);
  23112. if (end > duration) {
  23113. end = duration;
  23114. }
  23115. return end;
  23116. }
  23117. /**
  23118. * Get or set the current volume of the media
  23119. *
  23120. * @param {number} [percentAsDecimal]
  23121. * The new volume as a decimal percent:
  23122. * - 0 is muted/0%/off
  23123. * - 1.0 is 100%/full
  23124. * - 0.5 is half volume or 50%
  23125. *
  23126. * @return {number}
  23127. * The current volume as a percent when getting
  23128. */
  23129. ;
  23130. _proto.volume = function volume(percentAsDecimal) {
  23131. var vol;
  23132. if (percentAsDecimal !== undefined) {
  23133. // Force value to between 0 and 1
  23134. vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal)));
  23135. this.cache_.volume = vol;
  23136. this.techCall_('setVolume', vol);
  23137. if (vol > 0) {
  23138. this.lastVolume_(vol);
  23139. }
  23140. return;
  23141. } // Default to 1 when returning current volume.
  23142. vol = parseFloat(this.techGet_('volume'));
  23143. return isNaN(vol) ? 1 : vol;
  23144. }
  23145. /**
  23146. * Get the current muted state, or turn mute on or off
  23147. *
  23148. * @param {boolean} [muted]
  23149. * - true to mute
  23150. * - false to unmute
  23151. *
  23152. * @return {boolean}
  23153. * - true if mute is on and getting
  23154. * - false if mute is off and getting
  23155. */
  23156. ;
  23157. _proto.muted = function muted(_muted) {
  23158. if (_muted !== undefined) {
  23159. this.techCall_('setMuted', _muted);
  23160. return;
  23161. }
  23162. return this.techGet_('muted') || false;
  23163. }
  23164. /**
  23165. * Get the current defaultMuted state, or turn defaultMuted on or off. defaultMuted
  23166. * indicates the state of muted on initial playback.
  23167. *
  23168. * ```js
  23169. * var myPlayer = videojs('some-player-id');
  23170. *
  23171. * myPlayer.src("http://www.example.com/path/to/video.mp4");
  23172. *
  23173. * // get, should be false
  23174. * console.log(myPlayer.defaultMuted());
  23175. * // set to true
  23176. * myPlayer.defaultMuted(true);
  23177. * // get should be true
  23178. * console.log(myPlayer.defaultMuted());
  23179. * ```
  23180. *
  23181. * @param {boolean} [defaultMuted]
  23182. * - true to mute
  23183. * - false to unmute
  23184. *
  23185. * @return {boolean|Player}
  23186. * - true if defaultMuted is on and getting
  23187. * - false if defaultMuted is off and getting
  23188. * - A reference to the current player when setting
  23189. */
  23190. ;
  23191. _proto.defaultMuted = function defaultMuted(_defaultMuted) {
  23192. if (_defaultMuted !== undefined) {
  23193. return this.techCall_('setDefaultMuted', _defaultMuted);
  23194. }
  23195. return this.techGet_('defaultMuted') || false;
  23196. }
  23197. /**
  23198. * Get the last volume, or set it
  23199. *
  23200. * @param {number} [percentAsDecimal]
  23201. * The new last volume as a decimal percent:
  23202. * - 0 is muted/0%/off
  23203. * - 1.0 is 100%/full
  23204. * - 0.5 is half volume or 50%
  23205. *
  23206. * @return {number}
  23207. * the current value of lastVolume as a percent when getting
  23208. *
  23209. * @private
  23210. */
  23211. ;
  23212. _proto.lastVolume_ = function lastVolume_(percentAsDecimal) {
  23213. if (percentAsDecimal !== undefined && percentAsDecimal !== 0) {
  23214. this.cache_.lastVolume = percentAsDecimal;
  23215. return;
  23216. }
  23217. return this.cache_.lastVolume;
  23218. }
  23219. /**
  23220. * Check if current tech can support native fullscreen
  23221. * (e.g. with built in controls like iOS)
  23222. *
  23223. * @return {boolean}
  23224. * if native fullscreen is supported
  23225. */
  23226. ;
  23227. _proto.supportsFullScreen = function supportsFullScreen() {
  23228. return this.techGet_('supportsFullScreen') || false;
  23229. }
  23230. /**
  23231. * Check if the player is in fullscreen mode or tell the player that it
  23232. * is or is not in fullscreen mode.
  23233. *
  23234. * > NOTE: As of the latest HTML5 spec, isFullscreen is no longer an official
  23235. * property and instead document.fullscreenElement is used. But isFullscreen is
  23236. * still a valuable property for internal player workings.
  23237. *
  23238. * @param {boolean} [isFS]
  23239. * Set the players current fullscreen state
  23240. *
  23241. * @return {boolean}
  23242. * - true if fullscreen is on and getting
  23243. * - false if fullscreen is off and getting
  23244. */
  23245. ;
  23246. _proto.isFullscreen = function isFullscreen(isFS) {
  23247. if (isFS !== undefined) {
  23248. var oldValue = this.isFullscreen_;
  23249. this.isFullscreen_ = Boolean(isFS); // if we changed fullscreen state and we're in prefixed mode, trigger fullscreenchange
  23250. // this is the only place where we trigger fullscreenchange events for older browsers
  23251. // fullWindow mode is treated as a prefixed event and will get a fullscreenchange event as well
  23252. if (this.isFullscreen_ !== oldValue && this.fsApi_.prefixed) {
  23253. /**
  23254. * @event Player#fullscreenchange
  23255. * @type {EventTarget~Event}
  23256. */
  23257. this.trigger('fullscreenchange');
  23258. }
  23259. this.toggleFullscreenClass_();
  23260. return;
  23261. }
  23262. return this.isFullscreen_;
  23263. }
  23264. /**
  23265. * Increase the size of the video to full screen
  23266. * In some browsers, full screen is not supported natively, so it enters
  23267. * "full window mode", where the video fills the browser window.
  23268. * In browsers and devices that support native full screen, sometimes the
  23269. * browser's default controls will be shown, and not the Video.js custom skin.
  23270. * This includes most mobile devices (iOS, Android) and older versions of
  23271. * Safari.
  23272. *
  23273. * @param {Object} [fullscreenOptions]
  23274. * Override the player fullscreen options
  23275. *
  23276. * @fires Player#fullscreenchange
  23277. */
  23278. ;
  23279. _proto.requestFullscreen = function requestFullscreen(fullscreenOptions) {
  23280. var PromiseClass = this.options_.Promise || window.Promise;
  23281. if (PromiseClass) {
  23282. var self = this;
  23283. return new PromiseClass(function (resolve, reject) {
  23284. function offHandler() {
  23285. self.off('fullscreenerror', errorHandler);
  23286. self.off('fullscreenchange', changeHandler);
  23287. }
  23288. function changeHandler() {
  23289. offHandler();
  23290. resolve();
  23291. }
  23292. function errorHandler(e, err) {
  23293. offHandler();
  23294. reject(err);
  23295. }
  23296. self.one('fullscreenchange', changeHandler);
  23297. self.one('fullscreenerror', errorHandler);
  23298. var promise = self.requestFullscreenHelper_(fullscreenOptions);
  23299. if (promise) {
  23300. promise.then(offHandler, offHandler);
  23301. promise.then(resolve, reject);
  23302. }
  23303. });
  23304. }
  23305. return this.requestFullscreenHelper_();
  23306. };
  23307. _proto.requestFullscreenHelper_ = function requestFullscreenHelper_(fullscreenOptions) {
  23308. var _this12 = this;
  23309. var fsOptions; // Only pass fullscreen options to requestFullscreen in spec-compliant browsers.
  23310. // Use defaults or player configured option unless passed directly to this method.
  23311. if (!this.fsApi_.prefixed) {
  23312. fsOptions = this.options_.fullscreen && this.options_.fullscreen.options || {};
  23313. if (fullscreenOptions !== undefined) {
  23314. fsOptions = fullscreenOptions;
  23315. }
  23316. } // This method works as follows:
  23317. // 1. if a fullscreen api is available, use it
  23318. // 1. call requestFullscreen with potential options
  23319. // 2. if we got a promise from above, use it to update isFullscreen()
  23320. // 2. otherwise, if the tech supports fullscreen, call `enterFullScreen` on it.
  23321. // This is particularly used for iPhone, older iPads, and non-safari browser on iOS.
  23322. // 3. otherwise, use "fullWindow" mode
  23323. if (this.fsApi_.requestFullscreen) {
  23324. var promise = this.el_[this.fsApi_.requestFullscreen](fsOptions);
  23325. if (promise) {
  23326. promise.then(function () {
  23327. return _this12.isFullscreen(true);
  23328. }, function () {
  23329. return _this12.isFullscreen(false);
  23330. });
  23331. }
  23332. return promise;
  23333. } else if (this.tech_.supportsFullScreen() && !this.options_.preferFullWindow === true) {
  23334. // we can't take the video.js controls fullscreen but we can go fullscreen
  23335. // with native controls
  23336. this.techCall_('enterFullScreen');
  23337. } else {
  23338. // fullscreen isn't supported so we'll just stretch the video element to
  23339. // fill the viewport
  23340. this.enterFullWindow();
  23341. }
  23342. }
  23343. /**
  23344. * Return the video to its normal size after having been in full screen mode
  23345. *
  23346. * @fires Player#fullscreenchange
  23347. */
  23348. ;
  23349. _proto.exitFullscreen = function exitFullscreen() {
  23350. var PromiseClass = this.options_.Promise || window.Promise;
  23351. if (PromiseClass) {
  23352. var self = this;
  23353. return new PromiseClass(function (resolve, reject) {
  23354. function offHandler() {
  23355. self.off('fullscreenerror', errorHandler);
  23356. self.off('fullscreenchange', changeHandler);
  23357. }
  23358. function changeHandler() {
  23359. offHandler();
  23360. resolve();
  23361. }
  23362. function errorHandler(e, err) {
  23363. offHandler();
  23364. reject(err);
  23365. }
  23366. self.one('fullscreenchange', changeHandler);
  23367. self.one('fullscreenerror', errorHandler);
  23368. var promise = self.exitFullscreenHelper_();
  23369. if (promise) {
  23370. promise.then(offHandler, offHandler); // map the promise to our resolve/reject methods
  23371. promise.then(resolve, reject);
  23372. }
  23373. });
  23374. }
  23375. return this.exitFullscreenHelper_();
  23376. };
  23377. _proto.exitFullscreenHelper_ = function exitFullscreenHelper_() {
  23378. var _this13 = this;
  23379. if (this.fsApi_.requestFullscreen) {
  23380. var promise = document[this.fsApi_.exitFullscreen]();
  23381. if (promise) {
  23382. // we're splitting the promise here, so, we want to catch the
  23383. // potential error so that this chain doesn't have unhandled errors
  23384. silencePromise(promise.then(function () {
  23385. return _this13.isFullscreen(false);
  23386. }));
  23387. }
  23388. return promise;
  23389. } else if (this.tech_.supportsFullScreen() && !this.options_.preferFullWindow === true) {
  23390. this.techCall_('exitFullScreen');
  23391. } else {
  23392. this.exitFullWindow();
  23393. }
  23394. }
  23395. /**
  23396. * When fullscreen isn't supported we can stretch the
  23397. * video container to as wide as the browser will let us.
  23398. *
  23399. * @fires Player#enterFullWindow
  23400. */
  23401. ;
  23402. _proto.enterFullWindow = function enterFullWindow() {
  23403. this.isFullscreen(true);
  23404. this.isFullWindow = true; // Storing original doc overflow value to return to when fullscreen is off
  23405. this.docOrigOverflow = document.documentElement.style.overflow; // Add listener for esc key to exit fullscreen
  23406. on(document, 'keydown', this.boundFullWindowOnEscKey_); // Hide any scroll bars
  23407. document.documentElement.style.overflow = 'hidden'; // Apply fullscreen styles
  23408. addClass(document.body, 'vjs-full-window');
  23409. /**
  23410. * @event Player#enterFullWindow
  23411. * @type {EventTarget~Event}
  23412. */
  23413. this.trigger('enterFullWindow');
  23414. }
  23415. /**
  23416. * Check for call to either exit full window or
  23417. * full screen on ESC key
  23418. *
  23419. * @param {string} event
  23420. * Event to check for key press
  23421. */
  23422. ;
  23423. _proto.fullWindowOnEscKey = function fullWindowOnEscKey(event) {
  23424. if (keycode.isEventKey(event, 'Esc')) {
  23425. if (this.isFullscreen() === true) {
  23426. if (!this.isFullWindow) {
  23427. this.exitFullscreen();
  23428. } else {
  23429. this.exitFullWindow();
  23430. }
  23431. }
  23432. }
  23433. }
  23434. /**
  23435. * Exit full window
  23436. *
  23437. * @fires Player#exitFullWindow
  23438. */
  23439. ;
  23440. _proto.exitFullWindow = function exitFullWindow() {
  23441. this.isFullscreen(false);
  23442. this.isFullWindow = false;
  23443. off(document, 'keydown', this.boundFullWindowOnEscKey_); // Unhide scroll bars.
  23444. document.documentElement.style.overflow = this.docOrigOverflow; // Remove fullscreen styles
  23445. removeClass(document.body, 'vjs-full-window'); // Resize the box, controller, and poster to original sizes
  23446. // this.positionAll();
  23447. /**
  23448. * @event Player#exitFullWindow
  23449. * @type {EventTarget~Event}
  23450. */
  23451. this.trigger('exitFullWindow');
  23452. }
  23453. /**
  23454. * Disable Picture-in-Picture mode.
  23455. *
  23456. * @param {boolean} value
  23457. * - true will disable Picture-in-Picture mode
  23458. * - false will enable Picture-in-Picture mode
  23459. */
  23460. ;
  23461. _proto.disablePictureInPicture = function disablePictureInPicture(value) {
  23462. if (value === undefined) {
  23463. return this.techGet_('disablePictureInPicture');
  23464. }
  23465. this.techCall_('setDisablePictureInPicture', value);
  23466. this.options_.disablePictureInPicture = value;
  23467. this.trigger('disablepictureinpicturechanged');
  23468. }
  23469. /**
  23470. * Check if the player is in Picture-in-Picture mode or tell the player that it
  23471. * is or is not in Picture-in-Picture mode.
  23472. *
  23473. * @param {boolean} [isPiP]
  23474. * Set the players current Picture-in-Picture state
  23475. *
  23476. * @return {boolean}
  23477. * - true if Picture-in-Picture is on and getting
  23478. * - false if Picture-in-Picture is off and getting
  23479. */
  23480. ;
  23481. _proto.isInPictureInPicture = function isInPictureInPicture(isPiP) {
  23482. if (isPiP !== undefined) {
  23483. this.isInPictureInPicture_ = !!isPiP;
  23484. this.togglePictureInPictureClass_();
  23485. return;
  23486. }
  23487. return !!this.isInPictureInPicture_;
  23488. }
  23489. /**
  23490. * Create a floating video window always on top of other windows so that users may
  23491. * continue consuming media while they interact with other content sites, or
  23492. * applications on their device.
  23493. *
  23494. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  23495. *
  23496. * @fires Player#enterpictureinpicture
  23497. *
  23498. * @return {Promise}
  23499. * A promise with a Picture-in-Picture window.
  23500. */
  23501. ;
  23502. _proto.requestPictureInPicture = function requestPictureInPicture() {
  23503. if ('pictureInPictureEnabled' in document && this.disablePictureInPicture() === false) {
  23504. /**
  23505. * This event fires when the player enters picture in picture mode
  23506. *
  23507. * @event Player#enterpictureinpicture
  23508. * @type {EventTarget~Event}
  23509. */
  23510. return this.techGet_('requestPictureInPicture');
  23511. }
  23512. }
  23513. /**
  23514. * Exit Picture-in-Picture mode.
  23515. *
  23516. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  23517. *
  23518. * @fires Player#leavepictureinpicture
  23519. *
  23520. * @return {Promise}
  23521. * A promise.
  23522. */
  23523. ;
  23524. _proto.exitPictureInPicture = function exitPictureInPicture() {
  23525. if ('pictureInPictureEnabled' in document) {
  23526. /**
  23527. * This event fires when the player leaves picture in picture mode
  23528. *
  23529. * @event Player#leavepictureinpicture
  23530. * @type {EventTarget~Event}
  23531. */
  23532. return document.exitPictureInPicture();
  23533. }
  23534. }
  23535. /**
  23536. * Called when this Player has focus and a key gets pressed down, or when
  23537. * any Component of this player receives a key press that it doesn't handle.
  23538. * This allows player-wide hotkeys (either as defined below, or optionally
  23539. * by an external function).
  23540. *
  23541. * @param {EventTarget~Event} event
  23542. * The `keydown` event that caused this function to be called.
  23543. *
  23544. * @listens keydown
  23545. */
  23546. ;
  23547. _proto.handleKeyDown = function handleKeyDown(event) {
  23548. var userActions = this.options_.userActions; // Bail out if hotkeys are not configured.
  23549. if (!userActions || !userActions.hotkeys) {
  23550. return;
  23551. } // Function that determines whether or not to exclude an element from
  23552. // hotkeys handling.
  23553. var excludeElement = function excludeElement(el) {
  23554. var tagName = el.tagName.toLowerCase(); // The first and easiest test is for `contenteditable` elements.
  23555. if (el.isContentEditable) {
  23556. return true;
  23557. } // Inputs matching these types will still trigger hotkey handling as
  23558. // they are not text inputs.
  23559. var allowedInputTypes = ['button', 'checkbox', 'hidden', 'radio', 'reset', 'submit'];
  23560. if (tagName === 'input') {
  23561. return allowedInputTypes.indexOf(el.type) === -1;
  23562. } // The final test is by tag name. These tags will be excluded entirely.
  23563. var excludedTags = ['textarea'];
  23564. return excludedTags.indexOf(tagName) !== -1;
  23565. }; // Bail out if the user is focused on an interactive form element.
  23566. if (excludeElement(this.el_.ownerDocument.activeElement)) {
  23567. return;
  23568. }
  23569. if (typeof userActions.hotkeys === 'function') {
  23570. userActions.hotkeys.call(this, event);
  23571. } else {
  23572. this.handleHotkeys(event);
  23573. }
  23574. }
  23575. /**
  23576. * Called when this Player receives a hotkey keydown event.
  23577. * Supported player-wide hotkeys are:
  23578. *
  23579. * f - toggle fullscreen
  23580. * m - toggle mute
  23581. * k or Space - toggle play/pause
  23582. *
  23583. * @param {EventTarget~Event} event
  23584. * The `keydown` event that caused this function to be called.
  23585. */
  23586. ;
  23587. _proto.handleHotkeys = function handleHotkeys(event) {
  23588. var hotkeys = this.options_.userActions ? this.options_.userActions.hotkeys : {}; // set fullscreenKey, muteKey, playPauseKey from `hotkeys`, use defaults if not set
  23589. var _hotkeys$fullscreenKe = hotkeys.fullscreenKey,
  23590. fullscreenKey = _hotkeys$fullscreenKe === void 0 ? function (keydownEvent) {
  23591. return keycode.isEventKey(keydownEvent, 'f');
  23592. } : _hotkeys$fullscreenKe,
  23593. _hotkeys$muteKey = hotkeys.muteKey,
  23594. muteKey = _hotkeys$muteKey === void 0 ? function (keydownEvent) {
  23595. return keycode.isEventKey(keydownEvent, 'm');
  23596. } : _hotkeys$muteKey,
  23597. _hotkeys$playPauseKey = hotkeys.playPauseKey,
  23598. playPauseKey = _hotkeys$playPauseKey === void 0 ? function (keydownEvent) {
  23599. return keycode.isEventKey(keydownEvent, 'k') || keycode.isEventKey(keydownEvent, 'Space');
  23600. } : _hotkeys$playPauseKey;
  23601. if (fullscreenKey.call(this, event)) {
  23602. event.preventDefault();
  23603. event.stopPropagation();
  23604. var FSToggle = Component.getComponent('FullscreenToggle');
  23605. if (document[this.fsApi_.fullscreenEnabled] !== false) {
  23606. FSToggle.prototype.handleClick.call(this, event);
  23607. }
  23608. } else if (muteKey.call(this, event)) {
  23609. event.preventDefault();
  23610. event.stopPropagation();
  23611. var MuteToggle = Component.getComponent('MuteToggle');
  23612. MuteToggle.prototype.handleClick.call(this, event);
  23613. } else if (playPauseKey.call(this, event)) {
  23614. event.preventDefault();
  23615. event.stopPropagation();
  23616. var PlayToggle = Component.getComponent('PlayToggle');
  23617. PlayToggle.prototype.handleClick.call(this, event);
  23618. }
  23619. }
  23620. /**
  23621. * Check whether the player can play a given mimetype
  23622. *
  23623. * @see https://www.w3.org/TR/2011/WD-html5-20110113/video.html#dom-navigator-canplaytype
  23624. *
  23625. * @param {string} type
  23626. * The mimetype to check
  23627. *
  23628. * @return {string}
  23629. * 'probably', 'maybe', or '' (empty string)
  23630. */
  23631. ;
  23632. _proto.canPlayType = function canPlayType(type) {
  23633. var can; // Loop through each playback technology in the options order
  23634. for (var i = 0, j = this.options_.techOrder; i < j.length; i++) {
  23635. var techName = j[i];
  23636. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  23637. // Remove once that deprecated behavior is removed.
  23638. if (!tech) {
  23639. tech = Component.getComponent(techName);
  23640. } // Check if the current tech is defined before continuing
  23641. if (!tech) {
  23642. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  23643. continue;
  23644. } // Check if the browser supports this technology
  23645. if (tech.isSupported()) {
  23646. can = tech.canPlayType(type);
  23647. if (can) {
  23648. return can;
  23649. }
  23650. }
  23651. }
  23652. return '';
  23653. }
  23654. /**
  23655. * Select source based on tech-order or source-order
  23656. * Uses source-order selection if `options.sourceOrder` is truthy. Otherwise,
  23657. * defaults to tech-order selection
  23658. *
  23659. * @param {Array} sources
  23660. * The sources for a media asset
  23661. *
  23662. * @return {Object|boolean}
  23663. * Object of source and tech order or false
  23664. */
  23665. ;
  23666. _proto.selectSource = function selectSource(sources) {
  23667. var _this14 = this;
  23668. // Get only the techs specified in `techOrder` that exist and are supported by the
  23669. // current platform
  23670. var techs = this.options_.techOrder.map(function (techName) {
  23671. return [techName, Tech.getTech(techName)];
  23672. }).filter(function (_ref) {
  23673. var techName = _ref[0],
  23674. tech = _ref[1];
  23675. // Check if the current tech is defined before continuing
  23676. if (tech) {
  23677. // Check if the browser supports this technology
  23678. return tech.isSupported();
  23679. }
  23680. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  23681. return false;
  23682. }); // Iterate over each `innerArray` element once per `outerArray` element and execute
  23683. // `tester` with both. If `tester` returns a non-falsy value, exit early and return
  23684. // that value.
  23685. var findFirstPassingTechSourcePair = function findFirstPassingTechSourcePair(outerArray, innerArray, tester) {
  23686. var found;
  23687. outerArray.some(function (outerChoice) {
  23688. return innerArray.some(function (innerChoice) {
  23689. found = tester(outerChoice, innerChoice);
  23690. if (found) {
  23691. return true;
  23692. }
  23693. });
  23694. });
  23695. return found;
  23696. };
  23697. var foundSourceAndTech;
  23698. var flip = function flip(fn) {
  23699. return function (a, b) {
  23700. return fn(b, a);
  23701. };
  23702. };
  23703. var finder = function finder(_ref2, source) {
  23704. var techName = _ref2[0],
  23705. tech = _ref2[1];
  23706. if (tech.canPlaySource(source, _this14.options_[techName.toLowerCase()])) {
  23707. return {
  23708. source: source,
  23709. tech: techName
  23710. };
  23711. }
  23712. }; // Depending on the truthiness of `options.sourceOrder`, we swap the order of techs and sources
  23713. // to select from them based on their priority.
  23714. if (this.options_.sourceOrder) {
  23715. // Source-first ordering
  23716. foundSourceAndTech = findFirstPassingTechSourcePair(sources, techs, flip(finder));
  23717. } else {
  23718. // Tech-first ordering
  23719. foundSourceAndTech = findFirstPassingTechSourcePair(techs, sources, finder);
  23720. }
  23721. return foundSourceAndTech || false;
  23722. }
  23723. /**
  23724. * Executes source setting and getting logic
  23725. *
  23726. * @param {Tech~SourceObject|Tech~SourceObject[]|string} [source]
  23727. * A SourceObject, an array of SourceObjects, or a string referencing
  23728. * a URL to a media source. It is _highly recommended_ that an object
  23729. * or array of objects is used here, so that source selection
  23730. * algorithms can take the `type` into account.
  23731. *
  23732. * If not provided, this method acts as a getter.
  23733. * @param {boolean} isRetry
  23734. * Indicates whether this is being called internally as a result of a retry
  23735. *
  23736. * @return {string|undefined}
  23737. * If the `source` argument is missing, returns the current source
  23738. * URL. Otherwise, returns nothing/undefined.
  23739. */
  23740. ;
  23741. _proto.handleSrc_ = function handleSrc_(source, isRetry) {
  23742. var _this15 = this;
  23743. // getter usage
  23744. if (typeof source === 'undefined') {
  23745. return this.cache_.src || '';
  23746. } // Reset retry behavior for new source
  23747. if (this.resetRetryOnError_) {
  23748. this.resetRetryOnError_();
  23749. } // filter out invalid sources and turn our source into
  23750. // an array of source objects
  23751. var sources = filterSource(source); // if a source was passed in then it is invalid because
  23752. // it was filtered to a zero length Array. So we have to
  23753. // show an error
  23754. if (!sources.length) {
  23755. this.setTimeout(function () {
  23756. this.error({
  23757. code: 4,
  23758. message: this.options_.notSupportedMessage
  23759. });
  23760. }, 0);
  23761. return;
  23762. } // initial sources
  23763. this.changingSrc_ = true; // Only update the cached source list if we are not retrying a new source after error,
  23764. // since in that case we want to include the failed source(s) in the cache
  23765. if (!isRetry) {
  23766. this.cache_.sources = sources;
  23767. }
  23768. this.updateSourceCaches_(sources[0]); // middlewareSource is the source after it has been changed by middleware
  23769. setSource(this, sources[0], function (middlewareSource, mws) {
  23770. _this15.middleware_ = mws; // since sourceSet is async we have to update the cache again after we select a source since
  23771. // the source that is selected could be out of order from the cache update above this callback.
  23772. if (!isRetry) {
  23773. _this15.cache_.sources = sources;
  23774. }
  23775. _this15.updateSourceCaches_(middlewareSource);
  23776. var err = _this15.src_(middlewareSource);
  23777. if (err) {
  23778. if (sources.length > 1) {
  23779. return _this15.handleSrc_(sources.slice(1));
  23780. }
  23781. _this15.changingSrc_ = false; // We need to wrap this in a timeout to give folks a chance to add error event handlers
  23782. _this15.setTimeout(function () {
  23783. this.error({
  23784. code: 4,
  23785. message: this.options_.notSupportedMessage
  23786. });
  23787. }, 0); // we could not find an appropriate tech, but let's still notify the delegate that this is it
  23788. // this needs a better comment about why this is needed
  23789. _this15.triggerReady();
  23790. return;
  23791. }
  23792. setTech(mws, _this15.tech_);
  23793. }); // Try another available source if this one fails before playback.
  23794. if (this.options_.retryOnError && sources.length > 1) {
  23795. var retry = function retry() {
  23796. // Remove the error modal
  23797. _this15.error(null);
  23798. _this15.handleSrc_(sources.slice(1), true);
  23799. };
  23800. var stopListeningForErrors = function stopListeningForErrors() {
  23801. _this15.off('error', retry);
  23802. };
  23803. this.one('error', retry);
  23804. this.one('playing', stopListeningForErrors);
  23805. this.resetRetryOnError_ = function () {
  23806. _this15.off('error', retry);
  23807. _this15.off('playing', stopListeningForErrors);
  23808. };
  23809. }
  23810. }
  23811. /**
  23812. * Get or set the video source.
  23813. *
  23814. * @param {Tech~SourceObject|Tech~SourceObject[]|string} [source]
  23815. * A SourceObject, an array of SourceObjects, or a string referencing
  23816. * a URL to a media source. It is _highly recommended_ that an object
  23817. * or array of objects is used here, so that source selection
  23818. * algorithms can take the `type` into account.
  23819. *
  23820. * If not provided, this method acts as a getter.
  23821. *
  23822. * @return {string|undefined}
  23823. * If the `source` argument is missing, returns the current source
  23824. * URL. Otherwise, returns nothing/undefined.
  23825. */
  23826. ;
  23827. _proto.src = function src(source) {
  23828. return this.handleSrc_(source, false);
  23829. }
  23830. /**
  23831. * Set the source object on the tech, returns a boolean that indicates whether
  23832. * there is a tech that can play the source or not
  23833. *
  23834. * @param {Tech~SourceObject} source
  23835. * The source object to set on the Tech
  23836. *
  23837. * @return {boolean}
  23838. * - True if there is no Tech to playback this source
  23839. * - False otherwise
  23840. *
  23841. * @private
  23842. */
  23843. ;
  23844. _proto.src_ = function src_(source) {
  23845. var _this16 = this;
  23846. var sourceTech = this.selectSource([source]);
  23847. if (!sourceTech) {
  23848. return true;
  23849. }
  23850. if (!titleCaseEquals(sourceTech.tech, this.techName_)) {
  23851. this.changingSrc_ = true; // load this technology with the chosen source
  23852. this.loadTech_(sourceTech.tech, sourceTech.source);
  23853. this.tech_.ready(function () {
  23854. _this16.changingSrc_ = false;
  23855. });
  23856. return false;
  23857. } // wait until the tech is ready to set the source
  23858. // and set it synchronously if possible (#2326)
  23859. this.ready(function () {
  23860. // The setSource tech method was added with source handlers
  23861. // so older techs won't support it
  23862. // We need to check the direct prototype for the case where subclasses
  23863. // of the tech do not support source handlers
  23864. if (this.tech_.constructor.prototype.hasOwnProperty('setSource')) {
  23865. this.techCall_('setSource', source);
  23866. } else {
  23867. this.techCall_('src', source.src);
  23868. }
  23869. this.changingSrc_ = false;
  23870. }, true);
  23871. return false;
  23872. }
  23873. /**
  23874. * Begin loading the src data.
  23875. */
  23876. ;
  23877. _proto.load = function load() {
  23878. this.techCall_('load');
  23879. }
  23880. /**
  23881. * Reset the player. Loads the first tech in the techOrder,
  23882. * removes all the text tracks in the existing `tech`,
  23883. * and calls `reset` on the `tech`.
  23884. */
  23885. ;
  23886. _proto.reset = function reset() {
  23887. var _this17 = this;
  23888. var PromiseClass = this.options_.Promise || window.Promise;
  23889. if (this.paused() || !PromiseClass) {
  23890. this.doReset_();
  23891. } else {
  23892. var playPromise = this.play();
  23893. silencePromise(playPromise.then(function () {
  23894. return _this17.doReset_();
  23895. }));
  23896. }
  23897. };
  23898. _proto.doReset_ = function doReset_() {
  23899. if (this.tech_) {
  23900. this.tech_.clearTracks('text');
  23901. }
  23902. this.resetCache_();
  23903. this.poster('');
  23904. this.loadTech_(this.options_.techOrder[0], null);
  23905. this.techCall_('reset');
  23906. this.resetControlBarUI_();
  23907. if (isEvented(this)) {
  23908. this.trigger('playerreset');
  23909. }
  23910. }
  23911. /**
  23912. * Reset Control Bar's UI by calling sub-methods that reset
  23913. * all of Control Bar's components
  23914. */
  23915. ;
  23916. _proto.resetControlBarUI_ = function resetControlBarUI_() {
  23917. this.resetProgressBar_();
  23918. this.resetPlaybackRate_();
  23919. this.resetVolumeBar_();
  23920. }
  23921. /**
  23922. * Reset tech's progress so progress bar is reset in the UI
  23923. */
  23924. ;
  23925. _proto.resetProgressBar_ = function resetProgressBar_() {
  23926. this.currentTime(0);
  23927. var _ref3 = this.controlBar || {},
  23928. durationDisplay = _ref3.durationDisplay,
  23929. remainingTimeDisplay = _ref3.remainingTimeDisplay;
  23930. if (durationDisplay) {
  23931. durationDisplay.updateContent();
  23932. }
  23933. if (remainingTimeDisplay) {
  23934. remainingTimeDisplay.updateContent();
  23935. }
  23936. }
  23937. /**
  23938. * Reset Playback ratio
  23939. */
  23940. ;
  23941. _proto.resetPlaybackRate_ = function resetPlaybackRate_() {
  23942. this.playbackRate(this.defaultPlaybackRate());
  23943. this.handleTechRateChange_();
  23944. }
  23945. /**
  23946. * Reset Volume bar
  23947. */
  23948. ;
  23949. _proto.resetVolumeBar_ = function resetVolumeBar_() {
  23950. this.volume(1.0);
  23951. this.trigger('volumechange');
  23952. }
  23953. /**
  23954. * Returns all of the current source objects.
  23955. *
  23956. * @return {Tech~SourceObject[]}
  23957. * The current source objects
  23958. */
  23959. ;
  23960. _proto.currentSources = function currentSources() {
  23961. var source = this.currentSource();
  23962. var sources = []; // assume `{}` or `{ src }`
  23963. if (Object.keys(source).length !== 0) {
  23964. sources.push(source);
  23965. }
  23966. return this.cache_.sources || sources;
  23967. }
  23968. /**
  23969. * Returns the current source object.
  23970. *
  23971. * @return {Tech~SourceObject}
  23972. * The current source object
  23973. */
  23974. ;
  23975. _proto.currentSource = function currentSource() {
  23976. return this.cache_.source || {};
  23977. }
  23978. /**
  23979. * Returns the fully qualified URL of the current source value e.g. http://mysite.com/video.mp4
  23980. * Can be used in conjunction with `currentType` to assist in rebuilding the current source object.
  23981. *
  23982. * @return {string}
  23983. * The current source
  23984. */
  23985. ;
  23986. _proto.currentSrc = function currentSrc() {
  23987. return this.currentSource() && this.currentSource().src || '';
  23988. }
  23989. /**
  23990. * Get the current source type e.g. video/mp4
  23991. * This can allow you rebuild the current source object so that you could load the same
  23992. * source and tech later
  23993. *
  23994. * @return {string}
  23995. * The source MIME type
  23996. */
  23997. ;
  23998. _proto.currentType = function currentType() {
  23999. return this.currentSource() && this.currentSource().type || '';
  24000. }
  24001. /**
  24002. * Get or set the preload attribute
  24003. *
  24004. * @param {boolean} [value]
  24005. * - true means that we should preload
  24006. * - false means that we should not preload
  24007. *
  24008. * @return {string}
  24009. * The preload attribute value when getting
  24010. */
  24011. ;
  24012. _proto.preload = function preload(value) {
  24013. if (value !== undefined) {
  24014. this.techCall_('setPreload', value);
  24015. this.options_.preload = value;
  24016. return;
  24017. }
  24018. return this.techGet_('preload');
  24019. }
  24020. /**
  24021. * Get or set the autoplay option. When this is a boolean it will
  24022. * modify the attribute on the tech. When this is a string the attribute on
  24023. * the tech will be removed and `Player` will handle autoplay on loadstarts.
  24024. *
  24025. * @param {boolean|string} [value]
  24026. * - true: autoplay using the browser behavior
  24027. * - false: do not autoplay
  24028. * - 'play': call play() on every loadstart
  24029. * - 'muted': call muted() then play() on every loadstart
  24030. * - 'any': call play() on every loadstart. if that fails call muted() then play().
  24031. * - *: values other than those listed here will be set `autoplay` to true
  24032. *
  24033. * @return {boolean|string}
  24034. * The current value of autoplay when getting
  24035. */
  24036. ;
  24037. _proto.autoplay = function autoplay(value) {
  24038. // getter usage
  24039. if (value === undefined) {
  24040. return this.options_.autoplay || false;
  24041. }
  24042. var techAutoplay; // if the value is a valid string set it to that, or normalize `true` to 'play', if need be
  24043. if (typeof value === 'string' && /(any|play|muted)/.test(value) || value === true && this.options_.normalizeAutoplay) {
  24044. this.options_.autoplay = value;
  24045. this.manualAutoplay_(typeof value === 'string' ? value : 'play');
  24046. techAutoplay = false; // any falsy value sets autoplay to false in the browser,
  24047. // lets do the same
  24048. } else if (!value) {
  24049. this.options_.autoplay = false; // any other value (ie truthy) sets autoplay to true
  24050. } else {
  24051. this.options_.autoplay = true;
  24052. }
  24053. techAutoplay = typeof techAutoplay === 'undefined' ? this.options_.autoplay : techAutoplay; // if we don't have a tech then we do not queue up
  24054. // a setAutoplay call on tech ready. We do this because the
  24055. // autoplay option will be passed in the constructor and we
  24056. // do not need to set it twice
  24057. if (this.tech_) {
  24058. this.techCall_('setAutoplay', techAutoplay);
  24059. }
  24060. }
  24061. /**
  24062. * Set or unset the playsinline attribute.
  24063. * Playsinline tells the browser that non-fullscreen playback is preferred.
  24064. *
  24065. * @param {boolean} [value]
  24066. * - true means that we should try to play inline by default
  24067. * - false means that we should use the browser's default playback mode,
  24068. * which in most cases is inline. iOS Safari is a notable exception
  24069. * and plays fullscreen by default.
  24070. *
  24071. * @return {string|Player}
  24072. * - the current value of playsinline
  24073. * - the player when setting
  24074. *
  24075. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  24076. */
  24077. ;
  24078. _proto.playsinline = function playsinline(value) {
  24079. if (value !== undefined) {
  24080. this.techCall_('setPlaysinline', value);
  24081. this.options_.playsinline = value;
  24082. return this;
  24083. }
  24084. return this.techGet_('playsinline');
  24085. }
  24086. /**
  24087. * Get or set the loop attribute on the video element.
  24088. *
  24089. * @param {boolean} [value]
  24090. * - true means that we should loop the video
  24091. * - false means that we should not loop the video
  24092. *
  24093. * @return {boolean}
  24094. * The current value of loop when getting
  24095. */
  24096. ;
  24097. _proto.loop = function loop(value) {
  24098. if (value !== undefined) {
  24099. this.techCall_('setLoop', value);
  24100. this.options_.loop = value;
  24101. return;
  24102. }
  24103. return this.techGet_('loop');
  24104. }
  24105. /**
  24106. * Get or set the poster image source url
  24107. *
  24108. * @fires Player#posterchange
  24109. *
  24110. * @param {string} [src]
  24111. * Poster image source URL
  24112. *
  24113. * @return {string}
  24114. * The current value of poster when getting
  24115. */
  24116. ;
  24117. _proto.poster = function poster(src) {
  24118. if (src === undefined) {
  24119. return this.poster_;
  24120. } // The correct way to remove a poster is to set as an empty string
  24121. // other falsey values will throw errors
  24122. if (!src) {
  24123. src = '';
  24124. }
  24125. if (src === this.poster_) {
  24126. return;
  24127. } // update the internal poster variable
  24128. this.poster_ = src; // update the tech's poster
  24129. this.techCall_('setPoster', src);
  24130. this.isPosterFromTech_ = false; // alert components that the poster has been set
  24131. /**
  24132. * This event fires when the poster image is changed on the player.
  24133. *
  24134. * @event Player#posterchange
  24135. * @type {EventTarget~Event}
  24136. */
  24137. this.trigger('posterchange');
  24138. }
  24139. /**
  24140. * Some techs (e.g. YouTube) can provide a poster source in an
  24141. * asynchronous way. We want the poster component to use this
  24142. * poster source so that it covers up the tech's controls.
  24143. * (YouTube's play button). However we only want to use this
  24144. * source if the player user hasn't set a poster through
  24145. * the normal APIs.
  24146. *
  24147. * @fires Player#posterchange
  24148. * @listens Tech#posterchange
  24149. * @private
  24150. */
  24151. ;
  24152. _proto.handleTechPosterChange_ = function handleTechPosterChange_() {
  24153. if ((!this.poster_ || this.options_.techCanOverridePoster) && this.tech_ && this.tech_.poster) {
  24154. var newPoster = this.tech_.poster() || '';
  24155. if (newPoster !== this.poster_) {
  24156. this.poster_ = newPoster;
  24157. this.isPosterFromTech_ = true; // Let components know the poster has changed
  24158. this.trigger('posterchange');
  24159. }
  24160. }
  24161. }
  24162. /**
  24163. * Get or set whether or not the controls are showing.
  24164. *
  24165. * @fires Player#controlsenabled
  24166. *
  24167. * @param {boolean} [bool]
  24168. * - true to turn controls on
  24169. * - false to turn controls off
  24170. *
  24171. * @return {boolean}
  24172. * The current value of controls when getting
  24173. */
  24174. ;
  24175. _proto.controls = function controls(bool) {
  24176. if (bool === undefined) {
  24177. return !!this.controls_;
  24178. }
  24179. bool = !!bool; // Don't trigger a change event unless it actually changed
  24180. if (this.controls_ === bool) {
  24181. return;
  24182. }
  24183. this.controls_ = bool;
  24184. if (this.usingNativeControls()) {
  24185. this.techCall_('setControls', bool);
  24186. }
  24187. if (this.controls_) {
  24188. this.removeClass('vjs-controls-disabled');
  24189. this.addClass('vjs-controls-enabled');
  24190. /**
  24191. * @event Player#controlsenabled
  24192. * @type {EventTarget~Event}
  24193. */
  24194. this.trigger('controlsenabled');
  24195. if (!this.usingNativeControls()) {
  24196. this.addTechControlsListeners_();
  24197. }
  24198. } else {
  24199. this.removeClass('vjs-controls-enabled');
  24200. this.addClass('vjs-controls-disabled');
  24201. /**
  24202. * @event Player#controlsdisabled
  24203. * @type {EventTarget~Event}
  24204. */
  24205. this.trigger('controlsdisabled');
  24206. if (!this.usingNativeControls()) {
  24207. this.removeTechControlsListeners_();
  24208. }
  24209. }
  24210. }
  24211. /**
  24212. * Toggle native controls on/off. Native controls are the controls built into
  24213. * devices (e.g. default iPhone controls) or other techs
  24214. * (e.g. Vimeo Controls)
  24215. * **This should only be set by the current tech, because only the tech knows
  24216. * if it can support native controls**
  24217. *
  24218. * @fires Player#usingnativecontrols
  24219. * @fires Player#usingcustomcontrols
  24220. *
  24221. * @param {boolean} [bool]
  24222. * - true to turn native controls on
  24223. * - false to turn native controls off
  24224. *
  24225. * @return {boolean}
  24226. * The current value of native controls when getting
  24227. */
  24228. ;
  24229. _proto.usingNativeControls = function usingNativeControls(bool) {
  24230. if (bool === undefined) {
  24231. return !!this.usingNativeControls_;
  24232. }
  24233. bool = !!bool; // Don't trigger a change event unless it actually changed
  24234. if (this.usingNativeControls_ === bool) {
  24235. return;
  24236. }
  24237. this.usingNativeControls_ = bool;
  24238. if (this.usingNativeControls_) {
  24239. this.addClass('vjs-using-native-controls');
  24240. /**
  24241. * player is using the native device controls
  24242. *
  24243. * @event Player#usingnativecontrols
  24244. * @type {EventTarget~Event}
  24245. */
  24246. this.trigger('usingnativecontrols');
  24247. } else {
  24248. this.removeClass('vjs-using-native-controls');
  24249. /**
  24250. * player is using the custom HTML controls
  24251. *
  24252. * @event Player#usingcustomcontrols
  24253. * @type {EventTarget~Event}
  24254. */
  24255. this.trigger('usingcustomcontrols');
  24256. }
  24257. }
  24258. /**
  24259. * Set or get the current MediaError
  24260. *
  24261. * @fires Player#error
  24262. *
  24263. * @param {MediaError|string|number} [err]
  24264. * A MediaError or a string/number to be turned
  24265. * into a MediaError
  24266. *
  24267. * @return {MediaError|null}
  24268. * The current MediaError when getting (or null)
  24269. */
  24270. ;
  24271. _proto.error = function error(err) {
  24272. var _this18 = this;
  24273. if (err === undefined) {
  24274. return this.error_ || null;
  24275. } // allow hooks to modify error object
  24276. hooks('beforeerror').forEach(function (hookFunction) {
  24277. var newErr = hookFunction(_this18, err);
  24278. if (!(isObject(newErr) && !Array.isArray(newErr) || typeof newErr === 'string' || typeof newErr === 'number' || newErr === null)) {
  24279. _this18.log.error('please return a value that MediaError expects in beforeerror hooks');
  24280. return;
  24281. }
  24282. err = newErr;
  24283. }); // Suppress the first error message for no compatible source until
  24284. // user interaction
  24285. if (this.options_.suppressNotSupportedError && err && err.code === 4) {
  24286. var triggerSuppressedError = function triggerSuppressedError() {
  24287. this.error(err);
  24288. };
  24289. this.options_.suppressNotSupportedError = false;
  24290. this.any(['click', 'touchstart'], triggerSuppressedError);
  24291. this.one('loadstart', function () {
  24292. this.off(['click', 'touchstart'], triggerSuppressedError);
  24293. });
  24294. return;
  24295. } // restoring to default
  24296. if (err === null) {
  24297. this.error_ = err;
  24298. this.removeClass('vjs-error');
  24299. if (this.errorDisplay) {
  24300. this.errorDisplay.close();
  24301. }
  24302. return;
  24303. }
  24304. this.error_ = new MediaError(err); // add the vjs-error classname to the player
  24305. this.addClass('vjs-error'); // log the name of the error type and any message
  24306. // IE11 logs "[object object]" and required you to expand message to see error object
  24307. log.error("(CODE:" + this.error_.code + " " + MediaError.errorTypes[this.error_.code] + ")", this.error_.message, this.error_);
  24308. /**
  24309. * @event Player#error
  24310. * @type {EventTarget~Event}
  24311. */
  24312. this.trigger('error'); // notify hooks of the per player error
  24313. hooks('error').forEach(function (hookFunction) {
  24314. return hookFunction(_this18, _this18.error_);
  24315. });
  24316. return;
  24317. }
  24318. /**
  24319. * Report user activity
  24320. *
  24321. * @param {Object} event
  24322. * Event object
  24323. */
  24324. ;
  24325. _proto.reportUserActivity = function reportUserActivity(event) {
  24326. this.userActivity_ = true;
  24327. }
  24328. /**
  24329. * Get/set if user is active
  24330. *
  24331. * @fires Player#useractive
  24332. * @fires Player#userinactive
  24333. *
  24334. * @param {boolean} [bool]
  24335. * - true if the user is active
  24336. * - false if the user is inactive
  24337. *
  24338. * @return {boolean}
  24339. * The current value of userActive when getting
  24340. */
  24341. ;
  24342. _proto.userActive = function userActive(bool) {
  24343. if (bool === undefined) {
  24344. return this.userActive_;
  24345. }
  24346. bool = !!bool;
  24347. if (bool === this.userActive_) {
  24348. return;
  24349. }
  24350. this.userActive_ = bool;
  24351. if (this.userActive_) {
  24352. this.userActivity_ = true;
  24353. this.removeClass('vjs-user-inactive');
  24354. this.addClass('vjs-user-active');
  24355. /**
  24356. * @event Player#useractive
  24357. * @type {EventTarget~Event}
  24358. */
  24359. this.trigger('useractive');
  24360. return;
  24361. } // Chrome/Safari/IE have bugs where when you change the cursor it can
  24362. // trigger a mousemove event. This causes an issue when you're hiding
  24363. // the cursor when the user is inactive, and a mousemove signals user
  24364. // activity. Making it impossible to go into inactive mode. Specifically
  24365. // this happens in fullscreen when we really need to hide the cursor.
  24366. //
  24367. // When this gets resolved in ALL browsers it can be removed
  24368. // https://code.google.com/p/chromium/issues/detail?id=103041
  24369. if (this.tech_) {
  24370. this.tech_.one('mousemove', function (e) {
  24371. e.stopPropagation();
  24372. e.preventDefault();
  24373. });
  24374. }
  24375. this.userActivity_ = false;
  24376. this.removeClass('vjs-user-active');
  24377. this.addClass('vjs-user-inactive');
  24378. /**
  24379. * @event Player#userinactive
  24380. * @type {EventTarget~Event}
  24381. */
  24382. this.trigger('userinactive');
  24383. }
  24384. /**
  24385. * Listen for user activity based on timeout value
  24386. *
  24387. * @private
  24388. */
  24389. ;
  24390. _proto.listenForUserActivity_ = function listenForUserActivity_() {
  24391. var mouseInProgress;
  24392. var lastMoveX;
  24393. var lastMoveY;
  24394. var handleActivity = bind(this, this.reportUserActivity);
  24395. var handleMouseMove = function handleMouseMove(e) {
  24396. // #1068 - Prevent mousemove spamming
  24397. // Chrome Bug: https://code.google.com/p/chromium/issues/detail?id=366970
  24398. if (e.screenX !== lastMoveX || e.screenY !== lastMoveY) {
  24399. lastMoveX = e.screenX;
  24400. lastMoveY = e.screenY;
  24401. handleActivity();
  24402. }
  24403. };
  24404. var handleMouseDown = function handleMouseDown() {
  24405. handleActivity(); // For as long as the they are touching the device or have their mouse down,
  24406. // we consider them active even if they're not moving their finger or mouse.
  24407. // So we want to continue to update that they are active
  24408. this.clearInterval(mouseInProgress); // Setting userActivity=true now and setting the interval to the same time
  24409. // as the activityCheck interval (250) should ensure we never miss the
  24410. // next activityCheck
  24411. mouseInProgress = this.setInterval(handleActivity, 250);
  24412. };
  24413. var handleMouseUpAndMouseLeave = function handleMouseUpAndMouseLeave(event) {
  24414. handleActivity(); // Stop the interval that maintains activity if the mouse/touch is down
  24415. this.clearInterval(mouseInProgress);
  24416. }; // Any mouse movement will be considered user activity
  24417. this.on('mousedown', handleMouseDown);
  24418. this.on('mousemove', handleMouseMove);
  24419. this.on('mouseup', handleMouseUpAndMouseLeave);
  24420. this.on('mouseleave', handleMouseUpAndMouseLeave);
  24421. var controlBar = this.getChild('controlBar'); // Fixes bug on Android & iOS where when tapping progressBar (when control bar is displayed)
  24422. // controlBar would no longer be hidden by default timeout.
  24423. if (controlBar && !IS_IOS && !IS_ANDROID) {
  24424. controlBar.on('mouseenter', function (event) {
  24425. if (this.player().options_.inactivityTimeout !== 0) {
  24426. this.player().cache_.inactivityTimeout = this.player().options_.inactivityTimeout;
  24427. }
  24428. this.player().options_.inactivityTimeout = 0;
  24429. });
  24430. controlBar.on('mouseleave', function (event) {
  24431. this.player().options_.inactivityTimeout = this.player().cache_.inactivityTimeout;
  24432. });
  24433. } // Listen for keyboard navigation
  24434. // Shouldn't need to use inProgress interval because of key repeat
  24435. this.on('keydown', handleActivity);
  24436. this.on('keyup', handleActivity); // Run an interval every 250 milliseconds instead of stuffing everything into
  24437. // the mousemove/touchmove function itself, to prevent performance degradation.
  24438. // `this.reportUserActivity` simply sets this.userActivity_ to true, which
  24439. // then gets picked up by this loop
  24440. // http://ejohn.org/blog/learning-from-twitter/
  24441. var inactivityTimeout;
  24442. this.setInterval(function () {
  24443. // Check to see if mouse/touch activity has happened
  24444. if (!this.userActivity_) {
  24445. return;
  24446. } // Reset the activity tracker
  24447. this.userActivity_ = false; // If the user state was inactive, set the state to active
  24448. this.userActive(true); // Clear any existing inactivity timeout to start the timer over
  24449. this.clearTimeout(inactivityTimeout);
  24450. var timeout = this.options_.inactivityTimeout;
  24451. if (timeout <= 0) {
  24452. return;
  24453. } // In <timeout> milliseconds, if no more activity has occurred the
  24454. // user will be considered inactive
  24455. inactivityTimeout = this.setTimeout(function () {
  24456. // Protect against the case where the inactivityTimeout can trigger just
  24457. // before the next user activity is picked up by the activity check loop
  24458. // causing a flicker
  24459. if (!this.userActivity_) {
  24460. this.userActive(false);
  24461. }
  24462. }, timeout);
  24463. }, 250);
  24464. }
  24465. /**
  24466. * Gets or sets the current playback rate. A playback rate of
  24467. * 1.0 represents normal speed and 0.5 would indicate half-speed
  24468. * playback, for instance.
  24469. *
  24470. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-playbackrate
  24471. *
  24472. * @param {number} [rate]
  24473. * New playback rate to set.
  24474. *
  24475. * @return {number}
  24476. * The current playback rate when getting or 1.0
  24477. */
  24478. ;
  24479. _proto.playbackRate = function playbackRate(rate) {
  24480. if (rate !== undefined) {
  24481. // NOTE: this.cache_.lastPlaybackRate is set from the tech handler
  24482. // that is registered above
  24483. this.techCall_('setPlaybackRate', rate);
  24484. return;
  24485. }
  24486. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  24487. return this.cache_.lastPlaybackRate || this.techGet_('playbackRate');
  24488. }
  24489. return 1.0;
  24490. }
  24491. /**
  24492. * Gets or sets the current default playback rate. A default playback rate of
  24493. * 1.0 represents normal speed and 0.5 would indicate half-speed playback, for instance.
  24494. * defaultPlaybackRate will only represent what the initial playbackRate of a video was, not
  24495. * not the current playbackRate.
  24496. *
  24497. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-defaultplaybackrate
  24498. *
  24499. * @param {number} [rate]
  24500. * New default playback rate to set.
  24501. *
  24502. * @return {number|Player}
  24503. * - The default playback rate when getting or 1.0
  24504. * - the player when setting
  24505. */
  24506. ;
  24507. _proto.defaultPlaybackRate = function defaultPlaybackRate(rate) {
  24508. if (rate !== undefined) {
  24509. return this.techCall_('setDefaultPlaybackRate', rate);
  24510. }
  24511. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  24512. return this.techGet_('defaultPlaybackRate');
  24513. }
  24514. return 1.0;
  24515. }
  24516. /**
  24517. * Gets or sets the audio flag
  24518. *
  24519. * @param {boolean} bool
  24520. * - true signals that this is an audio player
  24521. * - false signals that this is not an audio player
  24522. *
  24523. * @return {boolean}
  24524. * The current value of isAudio when getting
  24525. */
  24526. ;
  24527. _proto.isAudio = function isAudio(bool) {
  24528. if (bool !== undefined) {
  24529. this.isAudio_ = !!bool;
  24530. return;
  24531. }
  24532. return !!this.isAudio_;
  24533. };
  24534. _proto.enableAudioOnlyUI_ = function enableAudioOnlyUI_() {
  24535. var _this19 = this;
  24536. // Update styling immediately to show the control bar so we can get its height
  24537. this.addClass('vjs-audio-only-mode');
  24538. var playerChildren = this.children();
  24539. var controlBar = this.getChild('ControlBar');
  24540. var controlBarHeight = controlBar && controlBar.currentHeight(); // Hide all player components except the control bar. Control bar components
  24541. // needed only for video are hidden with CSS
  24542. playerChildren.forEach(function (child) {
  24543. if (child === controlBar) {
  24544. return;
  24545. }
  24546. if (child.el_ && !child.hasClass('vjs-hidden')) {
  24547. child.hide();
  24548. _this19.audioOnlyCache_.hiddenChildren.push(child);
  24549. }
  24550. });
  24551. this.audioOnlyCache_.playerHeight = this.currentHeight(); // Set the player height the same as the control bar
  24552. this.height(controlBarHeight);
  24553. this.trigger('audioonlymodechange');
  24554. };
  24555. _proto.disableAudioOnlyUI_ = function disableAudioOnlyUI_() {
  24556. this.removeClass('vjs-audio-only-mode'); // Show player components that were previously hidden
  24557. this.audioOnlyCache_.hiddenChildren.forEach(function (child) {
  24558. return child.show();
  24559. }); // Reset player height
  24560. this.height(this.audioOnlyCache_.playerHeight);
  24561. this.trigger('audioonlymodechange');
  24562. }
  24563. /**
  24564. * Get the current audioOnlyMode state or set audioOnlyMode to true or false.
  24565. *
  24566. * Setting this to `true` will hide all player components except the control bar,
  24567. * as well as control bar components needed only for video.
  24568. *
  24569. * @param {boolean} [value]
  24570. * The value to set audioOnlyMode to.
  24571. *
  24572. * @return {Promise|boolean}
  24573. * A Promise is returned when setting the state, and a boolean when getting
  24574. * the present state
  24575. */
  24576. ;
  24577. _proto.audioOnlyMode = function audioOnlyMode(value) {
  24578. var _this20 = this;
  24579. if (typeof value !== 'boolean' || value === this.audioOnlyMode_) {
  24580. return this.audioOnlyMode_;
  24581. }
  24582. this.audioOnlyMode_ = value;
  24583. var PromiseClass = this.options_.Promise || window.Promise;
  24584. if (PromiseClass) {
  24585. // Enable Audio Only Mode
  24586. if (value) {
  24587. var exitPromises = []; // Fullscreen and PiP are not supported in audioOnlyMode, so exit if we need to.
  24588. if (this.isInPictureInPicture()) {
  24589. exitPromises.push(this.exitPictureInPicture());
  24590. }
  24591. if (this.isFullscreen()) {
  24592. exitPromises.push(this.exitFullscreen());
  24593. }
  24594. if (this.audioPosterMode()) {
  24595. exitPromises.push(this.audioPosterMode(false));
  24596. }
  24597. return PromiseClass.all(exitPromises).then(function () {
  24598. return _this20.enableAudioOnlyUI_();
  24599. });
  24600. } // Disable Audio Only Mode
  24601. return PromiseClass.resolve().then(function () {
  24602. return _this20.disableAudioOnlyUI_();
  24603. });
  24604. }
  24605. if (value) {
  24606. if (this.isInPictureInPicture()) {
  24607. this.exitPictureInPicture();
  24608. }
  24609. if (this.isFullscreen()) {
  24610. this.exitFullscreen();
  24611. }
  24612. this.enableAudioOnlyUI_();
  24613. } else {
  24614. this.disableAudioOnlyUI_();
  24615. }
  24616. };
  24617. _proto.enablePosterModeUI_ = function enablePosterModeUI_() {
  24618. // Hide the video element and show the poster image to enable posterModeUI
  24619. var tech = this.tech_ && this.tech_;
  24620. tech.hide();
  24621. this.addClass('vjs-audio-poster-mode');
  24622. this.trigger('audiopostermodechange');
  24623. };
  24624. _proto.disablePosterModeUI_ = function disablePosterModeUI_() {
  24625. // Show the video element and hide the poster image to disable posterModeUI
  24626. var tech = this.tech_ && this.tech_;
  24627. tech.show();
  24628. this.removeClass('vjs-audio-poster-mode');
  24629. this.trigger('audiopostermodechange');
  24630. }
  24631. /**
  24632. * Get the current audioPosterMode state or set audioPosterMode to true or false
  24633. *
  24634. * @param {boolean} [value]
  24635. * The value to set audioPosterMode to.
  24636. *
  24637. * @return {Promise|boolean}
  24638. * A Promise is returned when setting the state, and a boolean when getting
  24639. * the present state
  24640. */
  24641. ;
  24642. _proto.audioPosterMode = function audioPosterMode(value) {
  24643. var _this21 = this;
  24644. if (typeof value !== 'boolean' || value === this.audioPosterMode_) {
  24645. return this.audioPosterMode_;
  24646. }
  24647. this.audioPosterMode_ = value;
  24648. var PromiseClass = this.options_.Promise || window.Promise;
  24649. if (PromiseClass) {
  24650. if (value) {
  24651. if (this.audioOnlyMode()) {
  24652. var audioOnlyModePromise = this.audioOnlyMode(false);
  24653. return audioOnlyModePromise.then(function () {
  24654. // enable audio poster mode after audio only mode is disabled
  24655. _this21.enablePosterModeUI_();
  24656. });
  24657. }
  24658. return PromiseClass.resolve().then(function () {
  24659. // enable audio poster mode
  24660. _this21.enablePosterModeUI_();
  24661. });
  24662. }
  24663. return PromiseClass.resolve().then(function () {
  24664. // disable audio poster mode
  24665. _this21.disablePosterModeUI_();
  24666. });
  24667. }
  24668. if (value) {
  24669. if (this.audioOnlyMode()) {
  24670. this.audioOnlyMode(false);
  24671. }
  24672. this.enablePosterModeUI_();
  24673. return;
  24674. }
  24675. this.disablePosterModeUI_();
  24676. }
  24677. /**
  24678. * A helper method for adding a {@link TextTrack} to our
  24679. * {@link TextTrackList}.
  24680. *
  24681. * In addition to the W3C settings we allow adding additional info through options.
  24682. *
  24683. * @see http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-addtexttrack
  24684. *
  24685. * @param {string} [kind]
  24686. * the kind of TextTrack you are adding
  24687. *
  24688. * @param {string} [label]
  24689. * the label to give the TextTrack label
  24690. *
  24691. * @param {string} [language]
  24692. * the language to set on the TextTrack
  24693. *
  24694. * @return {TextTrack|undefined}
  24695. * the TextTrack that was added or undefined
  24696. * if there is no tech
  24697. */
  24698. ;
  24699. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  24700. if (this.tech_) {
  24701. return this.tech_.addTextTrack(kind, label, language);
  24702. }
  24703. }
  24704. /**
  24705. * Create a remote {@link TextTrack} and an {@link HTMLTrackElement}.
  24706. * When manualCleanup is set to false, the track will be automatically removed
  24707. * on source changes.
  24708. *
  24709. * @param {Object} options
  24710. * Options to pass to {@link HTMLTrackElement} during creation. See
  24711. * {@link HTMLTrackElement} for object properties that you should use.
  24712. *
  24713. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  24714. * removed on a source change
  24715. *
  24716. * @return {HtmlTrackElement}
  24717. * the HTMLTrackElement that was created and added
  24718. * to the HtmlTrackElementList and the remote
  24719. * TextTrackList
  24720. *
  24721. * @deprecated The default value of the "manualCleanup" parameter will default
  24722. * to "false" in upcoming versions of Video.js
  24723. */
  24724. ;
  24725. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  24726. if (this.tech_) {
  24727. return this.tech_.addRemoteTextTrack(options, manualCleanup);
  24728. }
  24729. }
  24730. /**
  24731. * Remove a remote {@link TextTrack} from the respective
  24732. * {@link TextTrackList} and {@link HtmlTrackElementList}.
  24733. *
  24734. * @param {Object} track
  24735. * Remote {@link TextTrack} to remove
  24736. *
  24737. * @return {undefined}
  24738. * does not return anything
  24739. */
  24740. ;
  24741. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(obj) {
  24742. if (obj === void 0) {
  24743. obj = {};
  24744. }
  24745. var _obj = obj,
  24746. track = _obj.track;
  24747. if (!track) {
  24748. track = obj;
  24749. } // destructure the input into an object with a track argument, defaulting to arguments[0]
  24750. // default the whole argument to an empty object if nothing was passed in
  24751. if (this.tech_) {
  24752. return this.tech_.removeRemoteTextTrack(track);
  24753. }
  24754. }
  24755. /**
  24756. * Gets available media playback quality metrics as specified by the W3C's Media
  24757. * Playback Quality API.
  24758. *
  24759. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  24760. *
  24761. * @return {Object|undefined}
  24762. * An object with supported media playback quality metrics or undefined if there
  24763. * is no tech or the tech does not support it.
  24764. */
  24765. ;
  24766. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  24767. return this.techGet_('getVideoPlaybackQuality');
  24768. }
  24769. /**
  24770. * Get video width
  24771. *
  24772. * @return {number}
  24773. * current video width
  24774. */
  24775. ;
  24776. _proto.videoWidth = function videoWidth() {
  24777. return this.tech_ && this.tech_.videoWidth && this.tech_.videoWidth() || 0;
  24778. }
  24779. /**
  24780. * Get video height
  24781. *
  24782. * @return {number}
  24783. * current video height
  24784. */
  24785. ;
  24786. _proto.videoHeight = function videoHeight() {
  24787. return this.tech_ && this.tech_.videoHeight && this.tech_.videoHeight() || 0;
  24788. }
  24789. /**
  24790. * The player's language code.
  24791. *
  24792. * Changing the language will trigger
  24793. * [languagechange]{@link Player#event:languagechange}
  24794. * which Components can use to update control text.
  24795. * ClickableComponent will update its control text by default on
  24796. * [languagechange]{@link Player#event:languagechange}.
  24797. *
  24798. * @fires Player#languagechange
  24799. *
  24800. * @param {string} [code]
  24801. * the language code to set the player to
  24802. *
  24803. * @return {string}
  24804. * The current language code when getting
  24805. */
  24806. ;
  24807. _proto.language = function language(code) {
  24808. if (code === undefined) {
  24809. return this.language_;
  24810. }
  24811. if (this.language_ !== String(code).toLowerCase()) {
  24812. this.language_ = String(code).toLowerCase(); // during first init, it's possible some things won't be evented
  24813. if (isEvented(this)) {
  24814. /**
  24815. * fires when the player language change
  24816. *
  24817. * @event Player#languagechange
  24818. * @type {EventTarget~Event}
  24819. */
  24820. this.trigger('languagechange');
  24821. }
  24822. }
  24823. }
  24824. /**
  24825. * Get the player's language dictionary
  24826. * Merge every time, because a newly added plugin might call videojs.addLanguage() at any time
  24827. * Languages specified directly in the player options have precedence
  24828. *
  24829. * @return {Array}
  24830. * An array of of supported languages
  24831. */
  24832. ;
  24833. _proto.languages = function languages() {
  24834. return mergeOptions(Player.prototype.options_.languages, this.languages_);
  24835. }
  24836. /**
  24837. * returns a JavaScript object reperesenting the current track
  24838. * information. **DOES not return it as JSON**
  24839. *
  24840. * @return {Object}
  24841. * Object representing the current of track info
  24842. */
  24843. ;
  24844. _proto.toJSON = function toJSON() {
  24845. var options = mergeOptions(this.options_);
  24846. var tracks = options.tracks;
  24847. options.tracks = [];
  24848. for (var i = 0; i < tracks.length; i++) {
  24849. var track = tracks[i]; // deep merge tracks and null out player so no circular references
  24850. track = mergeOptions(track);
  24851. track.player = undefined;
  24852. options.tracks[i] = track;
  24853. }
  24854. return options;
  24855. }
  24856. /**
  24857. * Creates a simple modal dialog (an instance of the {@link ModalDialog}
  24858. * component) that immediately overlays the player with arbitrary
  24859. * content and removes itself when closed.
  24860. *
  24861. * @param {string|Function|Element|Array|null} content
  24862. * Same as {@link ModalDialog#content}'s param of the same name.
  24863. * The most straight-forward usage is to provide a string or DOM
  24864. * element.
  24865. *
  24866. * @param {Object} [options]
  24867. * Extra options which will be passed on to the {@link ModalDialog}.
  24868. *
  24869. * @return {ModalDialog}
  24870. * the {@link ModalDialog} that was created
  24871. */
  24872. ;
  24873. _proto.createModal = function createModal(content, options) {
  24874. var _this22 = this;
  24875. options = options || {};
  24876. options.content = content || '';
  24877. var modal = new ModalDialog(this, options);
  24878. this.addChild(modal);
  24879. modal.on('dispose', function () {
  24880. _this22.removeChild(modal);
  24881. });
  24882. modal.open();
  24883. return modal;
  24884. }
  24885. /**
  24886. * Change breakpoint classes when the player resizes.
  24887. *
  24888. * @private
  24889. */
  24890. ;
  24891. _proto.updateCurrentBreakpoint_ = function updateCurrentBreakpoint_() {
  24892. if (!this.responsive()) {
  24893. return;
  24894. }
  24895. var currentBreakpoint = this.currentBreakpoint();
  24896. var currentWidth = this.currentWidth();
  24897. for (var i = 0; i < BREAKPOINT_ORDER.length; i++) {
  24898. var candidateBreakpoint = BREAKPOINT_ORDER[i];
  24899. var maxWidth = this.breakpoints_[candidateBreakpoint];
  24900. if (currentWidth <= maxWidth) {
  24901. // The current breakpoint did not change, nothing to do.
  24902. if (currentBreakpoint === candidateBreakpoint) {
  24903. return;
  24904. } // Only remove a class if there is a current breakpoint.
  24905. if (currentBreakpoint) {
  24906. this.removeClass(BREAKPOINT_CLASSES[currentBreakpoint]);
  24907. }
  24908. this.addClass(BREAKPOINT_CLASSES[candidateBreakpoint]);
  24909. this.breakpoint_ = candidateBreakpoint;
  24910. break;
  24911. }
  24912. }
  24913. }
  24914. /**
  24915. * Removes the current breakpoint.
  24916. *
  24917. * @private
  24918. */
  24919. ;
  24920. _proto.removeCurrentBreakpoint_ = function removeCurrentBreakpoint_() {
  24921. var className = this.currentBreakpointClass();
  24922. this.breakpoint_ = '';
  24923. if (className) {
  24924. this.removeClass(className);
  24925. }
  24926. }
  24927. /**
  24928. * Get or set breakpoints on the player.
  24929. *
  24930. * Calling this method with an object or `true` will remove any previous
  24931. * custom breakpoints and start from the defaults again.
  24932. *
  24933. * @param {Object|boolean} [breakpoints]
  24934. * If an object is given, it can be used to provide custom
  24935. * breakpoints. If `true` is given, will set default breakpoints.
  24936. * If this argument is not given, will simply return the current
  24937. * breakpoints.
  24938. *
  24939. * @param {number} [breakpoints.tiny]
  24940. * The maximum width for the "vjs-layout-tiny" class.
  24941. *
  24942. * @param {number} [breakpoints.xsmall]
  24943. * The maximum width for the "vjs-layout-x-small" class.
  24944. *
  24945. * @param {number} [breakpoints.small]
  24946. * The maximum width for the "vjs-layout-small" class.
  24947. *
  24948. * @param {number} [breakpoints.medium]
  24949. * The maximum width for the "vjs-layout-medium" class.
  24950. *
  24951. * @param {number} [breakpoints.large]
  24952. * The maximum width for the "vjs-layout-large" class.
  24953. *
  24954. * @param {number} [breakpoints.xlarge]
  24955. * The maximum width for the "vjs-layout-x-large" class.
  24956. *
  24957. * @param {number} [breakpoints.huge]
  24958. * The maximum width for the "vjs-layout-huge" class.
  24959. *
  24960. * @return {Object}
  24961. * An object mapping breakpoint names to maximum width values.
  24962. */
  24963. ;
  24964. _proto.breakpoints = function breakpoints(_breakpoints) {
  24965. // Used as a getter.
  24966. if (_breakpoints === undefined) {
  24967. return assign(this.breakpoints_);
  24968. }
  24969. this.breakpoint_ = '';
  24970. this.breakpoints_ = assign({}, DEFAULT_BREAKPOINTS, _breakpoints); // When breakpoint definitions change, we need to update the currently
  24971. // selected breakpoint.
  24972. this.updateCurrentBreakpoint_(); // Clone the breakpoints before returning.
  24973. return assign(this.breakpoints_);
  24974. }
  24975. /**
  24976. * Get or set a flag indicating whether or not this player should adjust
  24977. * its UI based on its dimensions.
  24978. *
  24979. * @param {boolean} value
  24980. * Should be `true` if the player should adjust its UI based on its
  24981. * dimensions; otherwise, should be `false`.
  24982. *
  24983. * @return {boolean}
  24984. * Will be `true` if this player should adjust its UI based on its
  24985. * dimensions; otherwise, will be `false`.
  24986. */
  24987. ;
  24988. _proto.responsive = function responsive(value) {
  24989. // Used as a getter.
  24990. if (value === undefined) {
  24991. return this.responsive_;
  24992. }
  24993. value = Boolean(value);
  24994. var current = this.responsive_; // Nothing changed.
  24995. if (value === current) {
  24996. return;
  24997. } // The value actually changed, set it.
  24998. this.responsive_ = value; // Start listening for breakpoints and set the initial breakpoint if the
  24999. // player is now responsive.
  25000. if (value) {
  25001. this.on('playerresize', this.boundUpdateCurrentBreakpoint_);
  25002. this.updateCurrentBreakpoint_(); // Stop listening for breakpoints if the player is no longer responsive.
  25003. } else {
  25004. this.off('playerresize', this.boundUpdateCurrentBreakpoint_);
  25005. this.removeCurrentBreakpoint_();
  25006. }
  25007. return value;
  25008. }
  25009. /**
  25010. * Get current breakpoint name, if any.
  25011. *
  25012. * @return {string}
  25013. * If there is currently a breakpoint set, returns a the key from the
  25014. * breakpoints object matching it. Otherwise, returns an empty string.
  25015. */
  25016. ;
  25017. _proto.currentBreakpoint = function currentBreakpoint() {
  25018. return this.breakpoint_;
  25019. }
  25020. /**
  25021. * Get the current breakpoint class name.
  25022. *
  25023. * @return {string}
  25024. * The matching class name (e.g. `"vjs-layout-tiny"` or
  25025. * `"vjs-layout-large"`) for the current breakpoint. Empty string if
  25026. * there is no current breakpoint.
  25027. */
  25028. ;
  25029. _proto.currentBreakpointClass = function currentBreakpointClass() {
  25030. return BREAKPOINT_CLASSES[this.breakpoint_] || '';
  25031. }
  25032. /**
  25033. * An object that describes a single piece of media.
  25034. *
  25035. * Properties that are not part of this type description will be retained; so,
  25036. * this can be viewed as a generic metadata storage mechanism as well.
  25037. *
  25038. * @see {@link https://wicg.github.io/mediasession/#the-mediametadata-interface}
  25039. * @typedef {Object} Player~MediaObject
  25040. *
  25041. * @property {string} [album]
  25042. * Unused, except if this object is passed to the `MediaSession`
  25043. * API.
  25044. *
  25045. * @property {string} [artist]
  25046. * Unused, except if this object is passed to the `MediaSession`
  25047. * API.
  25048. *
  25049. * @property {Object[]} [artwork]
  25050. * Unused, except if this object is passed to the `MediaSession`
  25051. * API. If not specified, will be populated via the `poster`, if
  25052. * available.
  25053. *
  25054. * @property {string} [poster]
  25055. * URL to an image that will display before playback.
  25056. *
  25057. * @property {Tech~SourceObject|Tech~SourceObject[]|string} [src]
  25058. * A single source object, an array of source objects, or a string
  25059. * referencing a URL to a media source. It is _highly recommended_
  25060. * that an object or array of objects is used here, so that source
  25061. * selection algorithms can take the `type` into account.
  25062. *
  25063. * @property {string} [title]
  25064. * Unused, except if this object is passed to the `MediaSession`
  25065. * API.
  25066. *
  25067. * @property {Object[]} [textTracks]
  25068. * An array of objects to be used to create text tracks, following
  25069. * the {@link https://www.w3.org/TR/html50/embedded-content-0.html#the-track-element|native track element format}.
  25070. * For ease of removal, these will be created as "remote" text
  25071. * tracks and set to automatically clean up on source changes.
  25072. *
  25073. * These objects may have properties like `src`, `kind`, `label`,
  25074. * and `language`, see {@link Tech#createRemoteTextTrack}.
  25075. */
  25076. /**
  25077. * Populate the player using a {@link Player~MediaObject|MediaObject}.
  25078. *
  25079. * @param {Player~MediaObject} media
  25080. * A media object.
  25081. *
  25082. * @param {Function} ready
  25083. * A callback to be called when the player is ready.
  25084. */
  25085. ;
  25086. _proto.loadMedia = function loadMedia(media, ready) {
  25087. var _this23 = this;
  25088. if (!media || typeof media !== 'object') {
  25089. return;
  25090. }
  25091. this.reset(); // Clone the media object so it cannot be mutated from outside.
  25092. this.cache_.media = mergeOptions(media);
  25093. var _this$cache_$media = this.cache_.media,
  25094. artwork = _this$cache_$media.artwork,
  25095. poster = _this$cache_$media.poster,
  25096. src = _this$cache_$media.src,
  25097. textTracks = _this$cache_$media.textTracks; // If `artwork` is not given, create it using `poster`.
  25098. if (!artwork && poster) {
  25099. this.cache_.media.artwork = [{
  25100. src: poster,
  25101. type: getMimetype(poster)
  25102. }];
  25103. }
  25104. if (src) {
  25105. this.src(src);
  25106. }
  25107. if (poster) {
  25108. this.poster(poster);
  25109. }
  25110. if (Array.isArray(textTracks)) {
  25111. textTracks.forEach(function (tt) {
  25112. return _this23.addRemoteTextTrack(tt, false);
  25113. });
  25114. }
  25115. this.ready(ready);
  25116. }
  25117. /**
  25118. * Get a clone of the current {@link Player~MediaObject} for this player.
  25119. *
  25120. * If the `loadMedia` method has not been used, will attempt to return a
  25121. * {@link Player~MediaObject} based on the current state of the player.
  25122. *
  25123. * @return {Player~MediaObject}
  25124. */
  25125. ;
  25126. _proto.getMedia = function getMedia() {
  25127. if (!this.cache_.media) {
  25128. var poster = this.poster();
  25129. var src = this.currentSources();
  25130. var textTracks = Array.prototype.map.call(this.remoteTextTracks(), function (tt) {
  25131. return {
  25132. kind: tt.kind,
  25133. label: tt.label,
  25134. language: tt.language,
  25135. src: tt.src
  25136. };
  25137. });
  25138. var media = {
  25139. src: src,
  25140. textTracks: textTracks
  25141. };
  25142. if (poster) {
  25143. media.poster = poster;
  25144. media.artwork = [{
  25145. src: media.poster,
  25146. type: getMimetype(media.poster)
  25147. }];
  25148. }
  25149. return media;
  25150. }
  25151. return mergeOptions(this.cache_.media);
  25152. }
  25153. /**
  25154. * Gets tag settings
  25155. *
  25156. * @param {Element} tag
  25157. * The player tag
  25158. *
  25159. * @return {Object}
  25160. * An object containing all of the settings
  25161. * for a player tag
  25162. */
  25163. ;
  25164. Player.getTagSettings = function getTagSettings(tag) {
  25165. var baseOptions = {
  25166. sources: [],
  25167. tracks: []
  25168. };
  25169. var tagOptions = getAttributes(tag);
  25170. var dataSetup = tagOptions['data-setup'];
  25171. if (hasClass(tag, 'vjs-fill')) {
  25172. tagOptions.fill = true;
  25173. }
  25174. if (hasClass(tag, 'vjs-fluid')) {
  25175. tagOptions.fluid = true;
  25176. } // Check if data-setup attr exists.
  25177. if (dataSetup !== null) {
  25178. // Parse options JSON
  25179. // If empty string, make it a parsable json object.
  25180. var _safeParseTuple = tuple(dataSetup || '{}'),
  25181. err = _safeParseTuple[0],
  25182. data = _safeParseTuple[1];
  25183. if (err) {
  25184. log.error(err);
  25185. }
  25186. assign(tagOptions, data);
  25187. }
  25188. assign(baseOptions, tagOptions); // Get tag children settings
  25189. if (tag.hasChildNodes()) {
  25190. var children = tag.childNodes;
  25191. for (var i = 0, j = children.length; i < j; i++) {
  25192. var child = children[i]; // Change case needed: http://ejohn.org/blog/nodename-case-sensitivity/
  25193. var childName = child.nodeName.toLowerCase();
  25194. if (childName === 'source') {
  25195. baseOptions.sources.push(getAttributes(child));
  25196. } else if (childName === 'track') {
  25197. baseOptions.tracks.push(getAttributes(child));
  25198. }
  25199. }
  25200. }
  25201. return baseOptions;
  25202. }
  25203. /**
  25204. * Determine whether or not flexbox is supported
  25205. *
  25206. * @return {boolean}
  25207. * - true if flexbox is supported
  25208. * - false if flexbox is not supported
  25209. */
  25210. ;
  25211. _proto.flexNotSupported_ = function flexNotSupported_() {
  25212. var elem = document.createElement('i'); // Note: We don't actually use flexBasis (or flexOrder), but it's one of the more
  25213. // common flex features that we can rely on when checking for flex support.
  25214. 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
  25215. 'msFlexOrder' in elem.style);
  25216. }
  25217. /**
  25218. * Set debug mode to enable/disable logs at info level.
  25219. *
  25220. * @param {boolean} enabled
  25221. * @fires Player#debugon
  25222. * @fires Player#debugoff
  25223. */
  25224. ;
  25225. _proto.debug = function debug(enabled) {
  25226. if (enabled === undefined) {
  25227. return this.debugEnabled_;
  25228. }
  25229. if (enabled) {
  25230. this.trigger('debugon');
  25231. this.previousLogLevel_ = this.log.level;
  25232. this.log.level('debug');
  25233. this.debugEnabled_ = true;
  25234. } else {
  25235. this.trigger('debugoff');
  25236. this.log.level(this.previousLogLevel_);
  25237. this.previousLogLevel_ = undefined;
  25238. this.debugEnabled_ = false;
  25239. }
  25240. }
  25241. /**
  25242. * Set or get current playback rates.
  25243. * Takes an array and updates the playback rates menu with the new items.
  25244. * Pass in an empty array to hide the menu.
  25245. * Values other than arrays are ignored.
  25246. *
  25247. * @fires Player#playbackrateschange
  25248. * @param {number[]} newRates
  25249. * The new rates that the playback rates menu should update to.
  25250. * An empty array will hide the menu
  25251. * @return {number[]} When used as a getter will return the current playback rates
  25252. */
  25253. ;
  25254. _proto.playbackRates = function playbackRates(newRates) {
  25255. if (newRates === undefined) {
  25256. return this.cache_.playbackRates;
  25257. } // ignore any value that isn't an array
  25258. if (!Array.isArray(newRates)) {
  25259. return;
  25260. } // ignore any arrays that don't only contain numbers
  25261. if (!newRates.every(function (rate) {
  25262. return typeof rate === 'number';
  25263. })) {
  25264. return;
  25265. }
  25266. this.cache_.playbackRates = newRates;
  25267. /**
  25268. * fires when the playback rates in a player are changed
  25269. *
  25270. * @event Player#playbackrateschange
  25271. * @type {EventTarget~Event}
  25272. */
  25273. this.trigger('playbackrateschange');
  25274. };
  25275. return Player;
  25276. }(Component);
  25277. /**
  25278. * Get the {@link VideoTrackList}
  25279. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist
  25280. *
  25281. * @return {VideoTrackList}
  25282. * the current video track list
  25283. *
  25284. * @method Player.prototype.videoTracks
  25285. */
  25286. /**
  25287. * Get the {@link AudioTrackList}
  25288. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist
  25289. *
  25290. * @return {AudioTrackList}
  25291. * the current audio track list
  25292. *
  25293. * @method Player.prototype.audioTracks
  25294. */
  25295. /**
  25296. * Get the {@link TextTrackList}
  25297. *
  25298. * @link http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-texttracks
  25299. *
  25300. * @return {TextTrackList}
  25301. * the current text track list
  25302. *
  25303. * @method Player.prototype.textTracks
  25304. */
  25305. /**
  25306. * Get the remote {@link TextTrackList}
  25307. *
  25308. * @return {TextTrackList}
  25309. * The current remote text track list
  25310. *
  25311. * @method Player.prototype.remoteTextTracks
  25312. */
  25313. /**
  25314. * Get the remote {@link HtmlTrackElementList} tracks.
  25315. *
  25316. * @return {HtmlTrackElementList}
  25317. * The current remote text track element list
  25318. *
  25319. * @method Player.prototype.remoteTextTrackEls
  25320. */
  25321. ALL.names.forEach(function (name) {
  25322. var props = ALL[name];
  25323. Player.prototype[props.getterName] = function () {
  25324. if (this.tech_) {
  25325. return this.tech_[props.getterName]();
  25326. } // if we have not yet loadTech_, we create {video,audio,text}Tracks_
  25327. // these will be passed to the tech during loading
  25328. this[props.privateName] = this[props.privateName] || new props.ListClass();
  25329. return this[props.privateName];
  25330. };
  25331. });
  25332. /**
  25333. * Get or set the `Player`'s crossorigin option. For the HTML5 player, this
  25334. * sets the `crossOrigin` property on the `<video>` tag to control the CORS
  25335. * behavior.
  25336. *
  25337. * @see [Video Element Attributes]{@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-crossorigin}
  25338. *
  25339. * @param {string} [value]
  25340. * The value to set the `Player`'s crossorigin to. If an argument is
  25341. * given, must be one of `anonymous` or `use-credentials`.
  25342. *
  25343. * @return {string|undefined}
  25344. * - The current crossorigin value of the `Player` when getting.
  25345. * - undefined when setting
  25346. */
  25347. Player.prototype.crossorigin = Player.prototype.crossOrigin;
  25348. /**
  25349. * Global enumeration of players.
  25350. *
  25351. * The keys are the player IDs and the values are either the {@link Player}
  25352. * instance or `null` for disposed players.
  25353. *
  25354. * @type {Object}
  25355. */
  25356. Player.players = {};
  25357. var navigator = window.navigator;
  25358. /*
  25359. * Player instance options, surfaced using options
  25360. * options = Player.prototype.options_
  25361. * Make changes in options, not here.
  25362. *
  25363. * @type {Object}
  25364. * @private
  25365. */
  25366. Player.prototype.options_ = {
  25367. // Default order of fallback technology
  25368. techOrder: Tech.defaultTechOrder_,
  25369. html5: {},
  25370. // default inactivity timeout
  25371. inactivityTimeout: 2000,
  25372. // default playback rates
  25373. playbackRates: [],
  25374. // Add playback rate selection by adding rates
  25375. // 'playbackRates': [0.5, 1, 1.5, 2],
  25376. liveui: false,
  25377. // Included control sets
  25378. children: ['mediaLoader', 'posterImage', 'textTrackDisplay', 'loadingSpinner', 'bigPlayButton', 'liveTracker', 'controlBar', 'errorDisplay', 'textTrackSettings', 'resizeManager'],
  25379. language: navigator && (navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language) || 'en',
  25380. // locales and their language translations
  25381. languages: {},
  25382. // Default message to show when a video cannot be played.
  25383. notSupportedMessage: 'No compatible source was found for this media.',
  25384. normalizeAutoplay: false,
  25385. fullscreen: {
  25386. options: {
  25387. navigationUI: 'hide'
  25388. }
  25389. },
  25390. breakpoints: {},
  25391. responsive: false,
  25392. audioOnlyMode: false,
  25393. audioPosterMode: false
  25394. };
  25395. [
  25396. /**
  25397. * Returns whether or not the player is in the "ended" state.
  25398. *
  25399. * @return {Boolean} True if the player is in the ended state, false if not.
  25400. * @method Player#ended
  25401. */
  25402. 'ended',
  25403. /**
  25404. * Returns whether or not the player is in the "seeking" state.
  25405. *
  25406. * @return {Boolean} True if the player is in the seeking state, false if not.
  25407. * @method Player#seeking
  25408. */
  25409. 'seeking',
  25410. /**
  25411. * Returns the TimeRanges of the media that are currently available
  25412. * for seeking to.
  25413. *
  25414. * @return {TimeRanges} the seekable intervals of the media timeline
  25415. * @method Player#seekable
  25416. */
  25417. 'seekable',
  25418. /**
  25419. * Returns the current state of network activity for the element, from
  25420. * the codes in the list below.
  25421. * - NETWORK_EMPTY (numeric value 0)
  25422. * The element has not yet been initialised. All attributes are in
  25423. * their initial states.
  25424. * - NETWORK_IDLE (numeric value 1)
  25425. * The element's resource selection algorithm is active and has
  25426. * selected a resource, but it is not actually using the network at
  25427. * this time.
  25428. * - NETWORK_LOADING (numeric value 2)
  25429. * The user agent is actively trying to download data.
  25430. * - NETWORK_NO_SOURCE (numeric value 3)
  25431. * The element's resource selection algorithm is active, but it has
  25432. * not yet found a resource to use.
  25433. *
  25434. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
  25435. * @return {number} the current network activity state
  25436. * @method Player#networkState
  25437. */
  25438. 'networkState',
  25439. /**
  25440. * Returns a value that expresses the current state of the element
  25441. * with respect to rendering the current playback position, from the
  25442. * codes in the list below.
  25443. * - HAVE_NOTHING (numeric value 0)
  25444. * No information regarding the media resource is available.
  25445. * - HAVE_METADATA (numeric value 1)
  25446. * Enough of the resource has been obtained that the duration of the
  25447. * resource is available.
  25448. * - HAVE_CURRENT_DATA (numeric value 2)
  25449. * Data for the immediate current playback position is available.
  25450. * - HAVE_FUTURE_DATA (numeric value 3)
  25451. * Data for the immediate current playback position is available, as
  25452. * well as enough data for the user agent to advance the current
  25453. * playback position in the direction of playback.
  25454. * - HAVE_ENOUGH_DATA (numeric value 4)
  25455. * The user agent estimates that enough data is available for
  25456. * playback to proceed uninterrupted.
  25457. *
  25458. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
  25459. * @return {number} the current playback rendering state
  25460. * @method Player#readyState
  25461. */
  25462. 'readyState'].forEach(function (fn) {
  25463. Player.prototype[fn] = function () {
  25464. return this.techGet_(fn);
  25465. };
  25466. });
  25467. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  25468. Player.prototype["handleTech" + toTitleCase(event) + "_"] = function () {
  25469. return this.trigger(event);
  25470. };
  25471. });
  25472. /**
  25473. * Fired when the player has initial duration and dimension information
  25474. *
  25475. * @event Player#loadedmetadata
  25476. * @type {EventTarget~Event}
  25477. */
  25478. /**
  25479. * Fired when the player has downloaded data at the current playback position
  25480. *
  25481. * @event Player#loadeddata
  25482. * @type {EventTarget~Event}
  25483. */
  25484. /**
  25485. * Fired when the current playback position has changed *
  25486. * During playback this is fired every 15-250 milliseconds, depending on the
  25487. * playback technology in use.
  25488. *
  25489. * @event Player#timeupdate
  25490. * @type {EventTarget~Event}
  25491. */
  25492. /**
  25493. * Fired when the volume changes
  25494. *
  25495. * @event Player#volumechange
  25496. * @type {EventTarget~Event}
  25497. */
  25498. /**
  25499. * Reports whether or not a player has a plugin available.
  25500. *
  25501. * This does not report whether or not the plugin has ever been initialized
  25502. * on this player. For that, [usingPlugin]{@link Player#usingPlugin}.
  25503. *
  25504. * @method Player#hasPlugin
  25505. * @param {string} name
  25506. * The name of a plugin.
  25507. *
  25508. * @return {boolean}
  25509. * Whether or not this player has the requested plugin available.
  25510. */
  25511. /**
  25512. * Reports whether or not a player is using a plugin by name.
  25513. *
  25514. * For basic plugins, this only reports whether the plugin has _ever_ been
  25515. * initialized on this player.
  25516. *
  25517. * @method Player#usingPlugin
  25518. * @param {string} name
  25519. * The name of a plugin.
  25520. *
  25521. * @return {boolean}
  25522. * Whether or not this player is using the requested plugin.
  25523. */
  25524. Component.registerComponent('Player', Player);
  25525. var setPrototypeOf = createCommonjsModule(function (module) {
  25526. function _setPrototypeOf(o, p) {
  25527. module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  25528. o.__proto__ = p;
  25529. return o;
  25530. };
  25531. return _setPrototypeOf(o, p);
  25532. }
  25533. module.exports = _setPrototypeOf;
  25534. });
  25535. function _isNativeReflectConstruct() {
  25536. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  25537. if (Reflect.construct.sham) return false;
  25538. if (typeof Proxy === "function") return true;
  25539. try {
  25540. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  25541. return true;
  25542. } catch (e) {
  25543. return false;
  25544. }
  25545. }
  25546. var isNativeReflectConstruct = _isNativeReflectConstruct;
  25547. var construct = createCommonjsModule(function (module) {
  25548. function _construct(Parent, args, Class) {
  25549. if (isNativeReflectConstruct()) {
  25550. module.exports = _construct = Reflect.construct;
  25551. } else {
  25552. module.exports = _construct = function _construct(Parent, args, Class) {
  25553. var a = [null];
  25554. a.push.apply(a, args);
  25555. var Constructor = Function.bind.apply(Parent, a);
  25556. var instance = new Constructor();
  25557. if (Class) setPrototypeOf(instance, Class.prototype);
  25558. return instance;
  25559. };
  25560. }
  25561. return _construct.apply(null, arguments);
  25562. }
  25563. module.exports = _construct;
  25564. });
  25565. /**
  25566. * The base plugin name.
  25567. *
  25568. * @private
  25569. * @constant
  25570. * @type {string}
  25571. */
  25572. var BASE_PLUGIN_NAME = 'plugin';
  25573. /**
  25574. * The key on which a player's active plugins cache is stored.
  25575. *
  25576. * @private
  25577. * @constant
  25578. * @type {string}
  25579. */
  25580. var PLUGIN_CACHE_KEY = 'activePlugins_';
  25581. /**
  25582. * Stores registered plugins in a private space.
  25583. *
  25584. * @private
  25585. * @type {Object}
  25586. */
  25587. var pluginStorage = {};
  25588. /**
  25589. * Reports whether or not a plugin has been registered.
  25590. *
  25591. * @private
  25592. * @param {string} name
  25593. * The name of a plugin.
  25594. *
  25595. * @return {boolean}
  25596. * Whether or not the plugin has been registered.
  25597. */
  25598. var pluginExists = function pluginExists(name) {
  25599. return pluginStorage.hasOwnProperty(name);
  25600. };
  25601. /**
  25602. * Get a single registered plugin by name.
  25603. *
  25604. * @private
  25605. * @param {string} name
  25606. * The name of a plugin.
  25607. *
  25608. * @return {Function|undefined}
  25609. * The plugin (or undefined).
  25610. */
  25611. var getPlugin = function getPlugin(name) {
  25612. return pluginExists(name) ? pluginStorage[name] : undefined;
  25613. };
  25614. /**
  25615. * Marks a plugin as "active" on a player.
  25616. *
  25617. * Also, ensures that the player has an object for tracking active plugins.
  25618. *
  25619. * @private
  25620. * @param {Player} player
  25621. * A Video.js player instance.
  25622. *
  25623. * @param {string} name
  25624. * The name of a plugin.
  25625. */
  25626. var markPluginAsActive = function markPluginAsActive(player, name) {
  25627. player[PLUGIN_CACHE_KEY] = player[PLUGIN_CACHE_KEY] || {};
  25628. player[PLUGIN_CACHE_KEY][name] = true;
  25629. };
  25630. /**
  25631. * Triggers a pair of plugin setup events.
  25632. *
  25633. * @private
  25634. * @param {Player} player
  25635. * A Video.js player instance.
  25636. *
  25637. * @param {Plugin~PluginEventHash} hash
  25638. * A plugin event hash.
  25639. *
  25640. * @param {boolean} [before]
  25641. * If true, prefixes the event name with "before". In other words,
  25642. * use this to trigger "beforepluginsetup" instead of "pluginsetup".
  25643. */
  25644. var triggerSetupEvent = function triggerSetupEvent(player, hash, before) {
  25645. var eventName = (before ? 'before' : '') + 'pluginsetup';
  25646. player.trigger(eventName, hash);
  25647. player.trigger(eventName + ':' + hash.name, hash);
  25648. };
  25649. /**
  25650. * Takes a basic plugin function and returns a wrapper function which marks
  25651. * on the player that the plugin has been activated.
  25652. *
  25653. * @private
  25654. * @param {string} name
  25655. * The name of the plugin.
  25656. *
  25657. * @param {Function} plugin
  25658. * The basic plugin.
  25659. *
  25660. * @return {Function}
  25661. * A wrapper function for the given plugin.
  25662. */
  25663. var createBasicPlugin = function createBasicPlugin(name, plugin) {
  25664. var basicPluginWrapper = function basicPluginWrapper() {
  25665. // We trigger the "beforepluginsetup" and "pluginsetup" events on the player
  25666. // regardless, but we want the hash to be consistent with the hash provided
  25667. // for advanced plugins.
  25668. //
  25669. // The only potentially counter-intuitive thing here is the `instance` in
  25670. // the "pluginsetup" event is the value returned by the `plugin` function.
  25671. triggerSetupEvent(this, {
  25672. name: name,
  25673. plugin: plugin,
  25674. instance: null
  25675. }, true);
  25676. var instance = plugin.apply(this, arguments);
  25677. markPluginAsActive(this, name);
  25678. triggerSetupEvent(this, {
  25679. name: name,
  25680. plugin: plugin,
  25681. instance: instance
  25682. });
  25683. return instance;
  25684. };
  25685. Object.keys(plugin).forEach(function (prop) {
  25686. basicPluginWrapper[prop] = plugin[prop];
  25687. });
  25688. return basicPluginWrapper;
  25689. };
  25690. /**
  25691. * Takes a plugin sub-class and returns a factory function for generating
  25692. * instances of it.
  25693. *
  25694. * This factory function will replace itself with an instance of the requested
  25695. * sub-class of Plugin.
  25696. *
  25697. * @private
  25698. * @param {string} name
  25699. * The name of the plugin.
  25700. *
  25701. * @param {Plugin} PluginSubClass
  25702. * The advanced plugin.
  25703. *
  25704. * @return {Function}
  25705. */
  25706. var createPluginFactory = function createPluginFactory(name, PluginSubClass) {
  25707. // Add a `name` property to the plugin prototype so that each plugin can
  25708. // refer to itself by name.
  25709. PluginSubClass.prototype.name = name;
  25710. return function () {
  25711. triggerSetupEvent(this, {
  25712. name: name,
  25713. plugin: PluginSubClass,
  25714. instance: null
  25715. }, true);
  25716. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  25717. args[_key] = arguments[_key];
  25718. }
  25719. var instance = construct(PluginSubClass, [this].concat(args)); // The plugin is replaced by a function that returns the current instance.
  25720. this[name] = function () {
  25721. return instance;
  25722. };
  25723. triggerSetupEvent(this, instance.getEventHash());
  25724. return instance;
  25725. };
  25726. };
  25727. /**
  25728. * Parent class for all advanced plugins.
  25729. *
  25730. * @mixes module:evented~EventedMixin
  25731. * @mixes module:stateful~StatefulMixin
  25732. * @fires Player#beforepluginsetup
  25733. * @fires Player#beforepluginsetup:$name
  25734. * @fires Player#pluginsetup
  25735. * @fires Player#pluginsetup:$name
  25736. * @listens Player#dispose
  25737. * @throws {Error}
  25738. * If attempting to instantiate the base {@link Plugin} class
  25739. * directly instead of via a sub-class.
  25740. */
  25741. var Plugin = /*#__PURE__*/function () {
  25742. /**
  25743. * Creates an instance of this class.
  25744. *
  25745. * Sub-classes should call `super` to ensure plugins are properly initialized.
  25746. *
  25747. * @param {Player} player
  25748. * A Video.js player instance.
  25749. */
  25750. function Plugin(player) {
  25751. if (this.constructor === Plugin) {
  25752. throw new Error('Plugin must be sub-classed; not directly instantiated.');
  25753. }
  25754. this.player = player;
  25755. if (!this.log) {
  25756. this.log = this.player.log.createLogger(this.name);
  25757. } // Make this object evented, but remove the added `trigger` method so we
  25758. // use the prototype version instead.
  25759. evented(this);
  25760. delete this.trigger;
  25761. stateful(this, this.constructor.defaultState);
  25762. markPluginAsActive(player, this.name); // Auto-bind the dispose method so we can use it as a listener and unbind
  25763. // it later easily.
  25764. this.dispose = this.dispose.bind(this); // If the player is disposed, dispose the plugin.
  25765. player.on('dispose', this.dispose);
  25766. }
  25767. /**
  25768. * Get the version of the plugin that was set on <pluginName>.VERSION
  25769. */
  25770. var _proto = Plugin.prototype;
  25771. _proto.version = function version() {
  25772. return this.constructor.VERSION;
  25773. }
  25774. /**
  25775. * Each event triggered by plugins includes a hash of additional data with
  25776. * conventional properties.
  25777. *
  25778. * This returns that object or mutates an existing hash.
  25779. *
  25780. * @param {Object} [hash={}]
  25781. * An object to be used as event an event hash.
  25782. *
  25783. * @return {Plugin~PluginEventHash}
  25784. * An event hash object with provided properties mixed-in.
  25785. */
  25786. ;
  25787. _proto.getEventHash = function getEventHash(hash) {
  25788. if (hash === void 0) {
  25789. hash = {};
  25790. }
  25791. hash.name = this.name;
  25792. hash.plugin = this.constructor;
  25793. hash.instance = this;
  25794. return hash;
  25795. }
  25796. /**
  25797. * Triggers an event on the plugin object and overrides
  25798. * {@link module:evented~EventedMixin.trigger|EventedMixin.trigger}.
  25799. *
  25800. * @param {string|Object} event
  25801. * An event type or an object with a type property.
  25802. *
  25803. * @param {Object} [hash={}]
  25804. * Additional data hash to merge with a
  25805. * {@link Plugin~PluginEventHash|PluginEventHash}.
  25806. *
  25807. * @return {boolean}
  25808. * Whether or not default was prevented.
  25809. */
  25810. ;
  25811. _proto.trigger = function trigger$1(event, hash) {
  25812. if (hash === void 0) {
  25813. hash = {};
  25814. }
  25815. return trigger(this.eventBusEl_, event, this.getEventHash(hash));
  25816. }
  25817. /**
  25818. * Handles "statechanged" events on the plugin. No-op by default, override by
  25819. * subclassing.
  25820. *
  25821. * @abstract
  25822. * @param {Event} e
  25823. * An event object provided by a "statechanged" event.
  25824. *
  25825. * @param {Object} e.changes
  25826. * An object describing changes that occurred with the "statechanged"
  25827. * event.
  25828. */
  25829. ;
  25830. _proto.handleStateChanged = function handleStateChanged(e) {}
  25831. /**
  25832. * Disposes a plugin.
  25833. *
  25834. * Subclasses can override this if they want, but for the sake of safety,
  25835. * it's probably best to subscribe the "dispose" event.
  25836. *
  25837. * @fires Plugin#dispose
  25838. */
  25839. ;
  25840. _proto.dispose = function dispose() {
  25841. var name = this.name,
  25842. player = this.player;
  25843. /**
  25844. * Signals that a advanced plugin is about to be disposed.
  25845. *
  25846. * @event Plugin#dispose
  25847. * @type {EventTarget~Event}
  25848. */
  25849. this.trigger('dispose');
  25850. this.off();
  25851. player.off('dispose', this.dispose); // Eliminate any possible sources of leaking memory by clearing up
  25852. // references between the player and the plugin instance and nulling out
  25853. // the plugin's state and replacing methods with a function that throws.
  25854. player[PLUGIN_CACHE_KEY][name] = false;
  25855. this.player = this.state = null; // Finally, replace the plugin name on the player with a new factory
  25856. // function, so that the plugin is ready to be set up again.
  25857. player[name] = createPluginFactory(name, pluginStorage[name]);
  25858. }
  25859. /**
  25860. * Determines if a plugin is a basic plugin (i.e. not a sub-class of `Plugin`).
  25861. *
  25862. * @param {string|Function} plugin
  25863. * If a string, matches the name of a plugin. If a function, will be
  25864. * tested directly.
  25865. *
  25866. * @return {boolean}
  25867. * Whether or not a plugin is a basic plugin.
  25868. */
  25869. ;
  25870. Plugin.isBasic = function isBasic(plugin) {
  25871. var p = typeof plugin === 'string' ? getPlugin(plugin) : plugin;
  25872. return typeof p === 'function' && !Plugin.prototype.isPrototypeOf(p.prototype);
  25873. }
  25874. /**
  25875. * Register a Video.js plugin.
  25876. *
  25877. * @param {string} name
  25878. * The name of the plugin to be registered. Must be a string and
  25879. * must not match an existing plugin or a method on the `Player`
  25880. * prototype.
  25881. *
  25882. * @param {Function} plugin
  25883. * A sub-class of `Plugin` or a function for basic plugins.
  25884. *
  25885. * @return {Function}
  25886. * For advanced plugins, a factory function for that plugin. For
  25887. * basic plugins, a wrapper function that initializes the plugin.
  25888. */
  25889. ;
  25890. Plugin.registerPlugin = function registerPlugin(name, plugin) {
  25891. if (typeof name !== 'string') {
  25892. throw new Error("Illegal plugin name, \"" + name + "\", must be a string, was " + typeof name + ".");
  25893. }
  25894. if (pluginExists(name)) {
  25895. log.warn("A plugin named \"" + name + "\" already exists. You may want to avoid re-registering plugins!");
  25896. } else if (Player.prototype.hasOwnProperty(name)) {
  25897. throw new Error("Illegal plugin name, \"" + name + "\", cannot share a name with an existing player method!");
  25898. }
  25899. if (typeof plugin !== 'function') {
  25900. throw new Error("Illegal plugin for \"" + name + "\", must be a function, was " + typeof plugin + ".");
  25901. }
  25902. pluginStorage[name] = plugin; // Add a player prototype method for all sub-classed plugins (but not for
  25903. // the base Plugin class).
  25904. if (name !== BASE_PLUGIN_NAME) {
  25905. if (Plugin.isBasic(plugin)) {
  25906. Player.prototype[name] = createBasicPlugin(name, plugin);
  25907. } else {
  25908. Player.prototype[name] = createPluginFactory(name, plugin);
  25909. }
  25910. }
  25911. return plugin;
  25912. }
  25913. /**
  25914. * De-register a Video.js plugin.
  25915. *
  25916. * @param {string} name
  25917. * The name of the plugin to be de-registered. Must be a string that
  25918. * matches an existing plugin.
  25919. *
  25920. * @throws {Error}
  25921. * If an attempt is made to de-register the base plugin.
  25922. */
  25923. ;
  25924. Plugin.deregisterPlugin = function deregisterPlugin(name) {
  25925. if (name === BASE_PLUGIN_NAME) {
  25926. throw new Error('Cannot de-register base plugin.');
  25927. }
  25928. if (pluginExists(name)) {
  25929. delete pluginStorage[name];
  25930. delete Player.prototype[name];
  25931. }
  25932. }
  25933. /**
  25934. * Gets an object containing multiple Video.js plugins.
  25935. *
  25936. * @param {Array} [names]
  25937. * If provided, should be an array of plugin names. Defaults to _all_
  25938. * plugin names.
  25939. *
  25940. * @return {Object|undefined}
  25941. * An object containing plugin(s) associated with their name(s) or
  25942. * `undefined` if no matching plugins exist).
  25943. */
  25944. ;
  25945. Plugin.getPlugins = function getPlugins(names) {
  25946. if (names === void 0) {
  25947. names = Object.keys(pluginStorage);
  25948. }
  25949. var result;
  25950. names.forEach(function (name) {
  25951. var plugin = getPlugin(name);
  25952. if (plugin) {
  25953. result = result || {};
  25954. result[name] = plugin;
  25955. }
  25956. });
  25957. return result;
  25958. }
  25959. /**
  25960. * Gets a plugin's version, if available
  25961. *
  25962. * @param {string} name
  25963. * The name of a plugin.
  25964. *
  25965. * @return {string}
  25966. * The plugin's version or an empty string.
  25967. */
  25968. ;
  25969. Plugin.getPluginVersion = function getPluginVersion(name) {
  25970. var plugin = getPlugin(name);
  25971. return plugin && plugin.VERSION || '';
  25972. };
  25973. return Plugin;
  25974. }();
  25975. /**
  25976. * Gets a plugin by name if it exists.
  25977. *
  25978. * @static
  25979. * @method getPlugin
  25980. * @memberOf Plugin
  25981. * @param {string} name
  25982. * The name of a plugin.
  25983. *
  25984. * @returns {Function|undefined}
  25985. * The plugin (or `undefined`).
  25986. */
  25987. Plugin.getPlugin = getPlugin;
  25988. /**
  25989. * The name of the base plugin class as it is registered.
  25990. *
  25991. * @type {string}
  25992. */
  25993. Plugin.BASE_PLUGIN_NAME = BASE_PLUGIN_NAME;
  25994. Plugin.registerPlugin(BASE_PLUGIN_NAME, Plugin);
  25995. /**
  25996. * Documented in player.js
  25997. *
  25998. * @ignore
  25999. */
  26000. Player.prototype.usingPlugin = function (name) {
  26001. return !!this[PLUGIN_CACHE_KEY] && this[PLUGIN_CACHE_KEY][name] === true;
  26002. };
  26003. /**
  26004. * Documented in player.js
  26005. *
  26006. * @ignore
  26007. */
  26008. Player.prototype.hasPlugin = function (name) {
  26009. return !!pluginExists(name);
  26010. };
  26011. /**
  26012. * Signals that a plugin is about to be set up on a player.
  26013. *
  26014. * @event Player#beforepluginsetup
  26015. * @type {Plugin~PluginEventHash}
  26016. */
  26017. /**
  26018. * Signals that a plugin is about to be set up on a player - by name. The name
  26019. * is the name of the plugin.
  26020. *
  26021. * @event Player#beforepluginsetup:$name
  26022. * @type {Plugin~PluginEventHash}
  26023. */
  26024. /**
  26025. * Signals that a plugin has just been set up on a player.
  26026. *
  26027. * @event Player#pluginsetup
  26028. * @type {Plugin~PluginEventHash}
  26029. */
  26030. /**
  26031. * Signals that a plugin has just been set up on a player - by name. The name
  26032. * is the name of the plugin.
  26033. *
  26034. * @event Player#pluginsetup:$name
  26035. * @type {Plugin~PluginEventHash}
  26036. */
  26037. /**
  26038. * @typedef {Object} Plugin~PluginEventHash
  26039. *
  26040. * @property {string} instance
  26041. * For basic plugins, the return value of the plugin function. For
  26042. * advanced plugins, the plugin instance on which the event is fired.
  26043. *
  26044. * @property {string} name
  26045. * The name of the plugin.
  26046. *
  26047. * @property {string} plugin
  26048. * For basic plugins, the plugin function. For advanced plugins, the
  26049. * plugin class/constructor.
  26050. */
  26051. function _inherits(subClass, superClass) {
  26052. if (typeof superClass !== "function" && superClass !== null) {
  26053. throw new TypeError("Super expression must either be null or a function");
  26054. }
  26055. subClass.prototype = Object.create(superClass && superClass.prototype, {
  26056. constructor: {
  26057. value: subClass,
  26058. writable: true,
  26059. configurable: true
  26060. }
  26061. });
  26062. if (superClass) setPrototypeOf(subClass, superClass);
  26063. }
  26064. var inherits = _inherits;
  26065. /**
  26066. * @file extend.js
  26067. * @module extend
  26068. */
  26069. var hasLogged = false;
  26070. /**
  26071. * Used to subclass an existing class by emulating ES subclassing using the
  26072. * `extends` keyword.
  26073. *
  26074. * @function
  26075. * @deprecated
  26076. * @example
  26077. * var MyComponent = videojs.extend(videojs.getComponent('Component'), {
  26078. * myCustomMethod: function() {
  26079. * // Do things in my method.
  26080. * }
  26081. * });
  26082. *
  26083. * @param {Function} superClass
  26084. * The class to inherit from
  26085. *
  26086. * @param {Object} [subClassMethods={}]
  26087. * Methods of the new class
  26088. *
  26089. * @return {Function}
  26090. * The new class with subClassMethods that inherited superClass.
  26091. */
  26092. var extend = function extend(superClass, subClassMethods) {
  26093. if (subClassMethods === void 0) {
  26094. subClassMethods = {};
  26095. }
  26096. // Log a warning the first time extend is called to note that it is deprecated
  26097. // It was previously deprecated in our documentation (guides, specifically),
  26098. // but was never formally deprecated in code.
  26099. if (!hasLogged) {
  26100. log.warn('videojs.extend is deprecated as of Video.js 7.22.0 and will be removed in Video.js 8.0.0');
  26101. hasLogged = true;
  26102. }
  26103. var subClass = function subClass() {
  26104. superClass.apply(this, arguments);
  26105. };
  26106. var methods = {};
  26107. if (typeof subClassMethods === 'object') {
  26108. if (subClassMethods.constructor !== Object.prototype.constructor) {
  26109. subClass = subClassMethods.constructor;
  26110. }
  26111. methods = subClassMethods;
  26112. } else if (typeof subClassMethods === 'function') {
  26113. subClass = subClassMethods;
  26114. }
  26115. inherits(subClass, superClass); // this is needed for backward-compatibility and node compatibility.
  26116. if (superClass) {
  26117. subClass.super_ = superClass;
  26118. } // Extend subObj's prototype with functions and other properties from props
  26119. for (var name in methods) {
  26120. if (methods.hasOwnProperty(name)) {
  26121. subClass.prototype[name] = methods[name];
  26122. }
  26123. }
  26124. return subClass;
  26125. };
  26126. /**
  26127. * @file video.js
  26128. * @module videojs
  26129. */
  26130. /**
  26131. * Normalize an `id` value by trimming off a leading `#`
  26132. *
  26133. * @private
  26134. * @param {string} id
  26135. * A string, maybe with a leading `#`.
  26136. *
  26137. * @return {string}
  26138. * The string, without any leading `#`.
  26139. */
  26140. var normalizeId = function normalizeId(id) {
  26141. return id.indexOf('#') === 0 ? id.slice(1) : id;
  26142. };
  26143. /**
  26144. * The `videojs()` function doubles as the main function for users to create a
  26145. * {@link Player} instance as well as the main library namespace.
  26146. *
  26147. * It can also be used as a getter for a pre-existing {@link Player} instance.
  26148. * However, we _strongly_ recommend using `videojs.getPlayer()` for this
  26149. * purpose because it avoids any potential for unintended initialization.
  26150. *
  26151. * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149)
  26152. * of our JSDoc template, we cannot properly document this as both a function
  26153. * and a namespace, so its function signature is documented here.
  26154. *
  26155. * #### Arguments
  26156. * ##### id
  26157. * string|Element, **required**
  26158. *
  26159. * Video element or video element ID.
  26160. *
  26161. * ##### options
  26162. * Object, optional
  26163. *
  26164. * Options object for providing settings.
  26165. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  26166. *
  26167. * ##### ready
  26168. * {@link Component~ReadyCallback}, optional
  26169. *
  26170. * A function to be called when the {@link Player} and {@link Tech} are ready.
  26171. *
  26172. * #### Return Value
  26173. *
  26174. * The `videojs()` function returns a {@link Player} instance.
  26175. *
  26176. * @namespace
  26177. *
  26178. * @borrows AudioTrack as AudioTrack
  26179. * @borrows Component.getComponent as getComponent
  26180. * @borrows module:computed-style~computedStyle as computedStyle
  26181. * @borrows module:events.on as on
  26182. * @borrows module:events.one as one
  26183. * @borrows module:events.off as off
  26184. * @borrows module:events.trigger as trigger
  26185. * @borrows EventTarget as EventTarget
  26186. * @borrows module:extend~extend as extend
  26187. * @borrows module:fn.bind as bind
  26188. * @borrows module:format-time.formatTime as formatTime
  26189. * @borrows module:format-time.resetFormatTime as resetFormatTime
  26190. * @borrows module:format-time.setFormatTime as setFormatTime
  26191. * @borrows module:merge-options.mergeOptions as mergeOptions
  26192. * @borrows module:middleware.use as use
  26193. * @borrows Player.players as players
  26194. * @borrows Plugin.registerPlugin as registerPlugin
  26195. * @borrows Plugin.deregisterPlugin as deregisterPlugin
  26196. * @borrows Plugin.getPlugins as getPlugins
  26197. * @borrows Plugin.getPlugin as getPlugin
  26198. * @borrows Plugin.getPluginVersion as getPluginVersion
  26199. * @borrows Tech.getTech as getTech
  26200. * @borrows Tech.registerTech as registerTech
  26201. * @borrows TextTrack as TextTrack
  26202. * @borrows module:time-ranges.createTimeRanges as createTimeRange
  26203. * @borrows module:time-ranges.createTimeRanges as createTimeRanges
  26204. * @borrows module:url.isCrossOrigin as isCrossOrigin
  26205. * @borrows module:url.parseUrl as parseUrl
  26206. * @borrows VideoTrack as VideoTrack
  26207. *
  26208. * @param {string|Element} id
  26209. * Video element or video element ID.
  26210. *
  26211. * @param {Object} [options]
  26212. * Options object for providing settings.
  26213. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  26214. *
  26215. * @param {Component~ReadyCallback} [ready]
  26216. * A function to be called when the {@link Player} and {@link Tech} are
  26217. * ready.
  26218. *
  26219. * @return {Player}
  26220. * The `videojs()` function returns a {@link Player|Player} instance.
  26221. */
  26222. function videojs(id, options, ready) {
  26223. var player = videojs.getPlayer(id);
  26224. if (player) {
  26225. if (options) {
  26226. log.warn("Player \"" + id + "\" is already initialised. Options will not be applied.");
  26227. }
  26228. if (ready) {
  26229. player.ready(ready);
  26230. }
  26231. return player;
  26232. }
  26233. var el = typeof id === 'string' ? $('#' + normalizeId(id)) : id;
  26234. if (!isEl(el)) {
  26235. throw new TypeError('The element or ID supplied is not valid. (videojs)');
  26236. } // document.body.contains(el) will only check if el is contained within that one document.
  26237. // This causes problems for elements in iframes.
  26238. // Instead, use the element's ownerDocument instead of the global document.
  26239. // This will make sure that the element is indeed in the dom of that document.
  26240. // Additionally, check that the document in question has a default view.
  26241. // If the document is no longer attached to the dom, the defaultView of the document will be null.
  26242. if (!el.ownerDocument.defaultView || !el.ownerDocument.body.contains(el)) {
  26243. log.warn('The element supplied is not included in the DOM');
  26244. }
  26245. options = options || {}; // Store a copy of the el before modification, if it is to be restored in destroy()
  26246. // If div ingest, store the parent div
  26247. if (options.restoreEl === true) {
  26248. options.restoreEl = (el.parentNode && el.parentNode.hasAttribute('data-vjs-player') ? el.parentNode : el).cloneNode(true);
  26249. }
  26250. hooks('beforesetup').forEach(function (hookFunction) {
  26251. var opts = hookFunction(el, mergeOptions(options));
  26252. if (!isObject(opts) || Array.isArray(opts)) {
  26253. log.error('please return an object in beforesetup hooks');
  26254. return;
  26255. }
  26256. options = mergeOptions(options, opts);
  26257. }); // We get the current "Player" component here in case an integration has
  26258. // replaced it with a custom player.
  26259. var PlayerComponent = Component.getComponent('Player');
  26260. player = new PlayerComponent(el, options, ready);
  26261. hooks('setup').forEach(function (hookFunction) {
  26262. return hookFunction(player);
  26263. });
  26264. return player;
  26265. }
  26266. videojs.hooks_ = hooks_;
  26267. videojs.hooks = hooks;
  26268. videojs.hook = hook;
  26269. videojs.hookOnce = hookOnce;
  26270. videojs.removeHook = removeHook; // Add default styles
  26271. if (window.VIDEOJS_NO_DYNAMIC_STYLE !== true && isReal()) {
  26272. var style = $('.vjs-styles-defaults');
  26273. if (!style) {
  26274. style = createStyleElement('vjs-styles-defaults');
  26275. var head = $('head');
  26276. if (head) {
  26277. head.insertBefore(style, head.firstChild);
  26278. }
  26279. 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 ");
  26280. }
  26281. } // Run Auto-load players
  26282. // You have to wait at least once in case this script is loaded after your
  26283. // video in the DOM (weird behavior only with minified version)
  26284. autoSetupTimeout(1, videojs);
  26285. /**
  26286. * Current Video.js version. Follows [semantic versioning](https://semver.org/).
  26287. *
  26288. * @type {string}
  26289. */
  26290. videojs.VERSION = version;
  26291. /**
  26292. * The global options object. These are the settings that take effect
  26293. * if no overrides are specified when the player is created.
  26294. *
  26295. * @type {Object}
  26296. */
  26297. videojs.options = Player.prototype.options_;
  26298. /**
  26299. * Get an object with the currently created players, keyed by player ID
  26300. *
  26301. * @return {Object}
  26302. * The created players
  26303. */
  26304. videojs.getPlayers = function () {
  26305. return Player.players;
  26306. };
  26307. /**
  26308. * Get a single player based on an ID or DOM element.
  26309. *
  26310. * This is useful if you want to check if an element or ID has an associated
  26311. * Video.js player, but not create one if it doesn't.
  26312. *
  26313. * @param {string|Element} id
  26314. * An HTML element - `<video>`, `<audio>`, or `<video-js>` -
  26315. * or a string matching the `id` of such an element.
  26316. *
  26317. * @return {Player|undefined}
  26318. * A player instance or `undefined` if there is no player instance
  26319. * matching the argument.
  26320. */
  26321. videojs.getPlayer = function (id) {
  26322. var players = Player.players;
  26323. var tag;
  26324. if (typeof id === 'string') {
  26325. var nId = normalizeId(id);
  26326. var player = players[nId];
  26327. if (player) {
  26328. return player;
  26329. }
  26330. tag = $('#' + nId);
  26331. } else {
  26332. tag = id;
  26333. }
  26334. if (isEl(tag)) {
  26335. var _tag = tag,
  26336. _player = _tag.player,
  26337. playerId = _tag.playerId; // Element may have a `player` property referring to an already created
  26338. // player instance. If so, return that.
  26339. if (_player || players[playerId]) {
  26340. return _player || players[playerId];
  26341. }
  26342. }
  26343. };
  26344. /**
  26345. * Returns an array of all current players.
  26346. *
  26347. * @return {Array}
  26348. * An array of all players. The array will be in the order that
  26349. * `Object.keys` provides, which could potentially vary between
  26350. * JavaScript engines.
  26351. *
  26352. */
  26353. videojs.getAllPlayers = function () {
  26354. return (// Disposed players leave a key with a `null` value, so we need to make sure
  26355. // we filter those out.
  26356. Object.keys(Player.players).map(function (k) {
  26357. return Player.players[k];
  26358. }).filter(Boolean)
  26359. );
  26360. };
  26361. videojs.players = Player.players;
  26362. videojs.getComponent = Component.getComponent;
  26363. /**
  26364. * Register a component so it can referred to by name. Used when adding to other
  26365. * components, either through addChild `component.addChild('myComponent')` or through
  26366. * default children options `{ children: ['myComponent'] }`.
  26367. *
  26368. * > NOTE: You could also just initialize the component before adding.
  26369. * `component.addChild(new MyComponent());`
  26370. *
  26371. * @param {string} name
  26372. * The class name of the component
  26373. *
  26374. * @param {Component} comp
  26375. * The component class
  26376. *
  26377. * @return {Component}
  26378. * The newly registered component
  26379. */
  26380. videojs.registerComponent = function (name, comp) {
  26381. if (Tech.isTech(comp)) {
  26382. log.warn("The " + name + " tech was registered as a component. It should instead be registered using videojs.registerTech(name, tech)");
  26383. }
  26384. Component.registerComponent.call(Component, name, comp);
  26385. };
  26386. videojs.getTech = Tech.getTech;
  26387. videojs.registerTech = Tech.registerTech;
  26388. videojs.use = use;
  26389. /**
  26390. * An object that can be returned by a middleware to signify
  26391. * that the middleware is being terminated.
  26392. *
  26393. * @type {object}
  26394. * @property {object} middleware.TERMINATOR
  26395. */
  26396. Object.defineProperty(videojs, 'middleware', {
  26397. value: {},
  26398. writeable: false,
  26399. enumerable: true
  26400. });
  26401. Object.defineProperty(videojs.middleware, 'TERMINATOR', {
  26402. value: TERMINATOR,
  26403. writeable: false,
  26404. enumerable: true
  26405. });
  26406. /**
  26407. * A reference to the {@link module:browser|browser utility module} as an object.
  26408. *
  26409. * @type {Object}
  26410. * @see {@link module:browser|browser}
  26411. */
  26412. videojs.browser = browser;
  26413. /**
  26414. * Use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED} instead; only
  26415. * included for backward-compatibility with 4.x.
  26416. *
  26417. * @deprecated Since version 5.0, use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED instead.
  26418. * @type {boolean}
  26419. */
  26420. videojs.TOUCH_ENABLED = TOUCH_ENABLED;
  26421. videojs.extend = extend;
  26422. videojs.mergeOptions = mergeOptions;
  26423. videojs.bind = bind;
  26424. videojs.registerPlugin = Plugin.registerPlugin;
  26425. videojs.deregisterPlugin = Plugin.deregisterPlugin;
  26426. /**
  26427. * Deprecated method to register a plugin with Video.js
  26428. *
  26429. * @deprecated videojs.plugin() is deprecated; use videojs.registerPlugin() instead
  26430. *
  26431. * @param {string} name
  26432. * The plugin name
  26433. *
  26434. * @param {Plugin|Function} plugin
  26435. * The plugin sub-class or function
  26436. */
  26437. videojs.plugin = function (name, plugin) {
  26438. log.warn('videojs.plugin() is deprecated; use videojs.registerPlugin() instead');
  26439. return Plugin.registerPlugin(name, plugin);
  26440. };
  26441. videojs.getPlugins = Plugin.getPlugins;
  26442. videojs.getPlugin = Plugin.getPlugin;
  26443. videojs.getPluginVersion = Plugin.getPluginVersion;
  26444. /**
  26445. * Adding languages so that they're available to all players.
  26446. * Example: `videojs.addLanguage('es', { 'Hello': 'Hola' });`
  26447. *
  26448. * @param {string} code
  26449. * The language code or dictionary property
  26450. *
  26451. * @param {Object} data
  26452. * The data values to be translated
  26453. *
  26454. * @return {Object}
  26455. * The resulting language dictionary object
  26456. */
  26457. videojs.addLanguage = function (code, data) {
  26458. var _mergeOptions;
  26459. code = ('' + code).toLowerCase();
  26460. videojs.options.languages = mergeOptions(videojs.options.languages, (_mergeOptions = {}, _mergeOptions[code] = data, _mergeOptions));
  26461. return videojs.options.languages[code];
  26462. };
  26463. /**
  26464. * A reference to the {@link module:log|log utility module} as an object.
  26465. *
  26466. * @type {Function}
  26467. * @see {@link module:log|log}
  26468. */
  26469. videojs.log = log;
  26470. videojs.createLogger = createLogger;
  26471. videojs.createTimeRange = videojs.createTimeRanges = createTimeRanges;
  26472. videojs.formatTime = formatTime;
  26473. videojs.setFormatTime = setFormatTime;
  26474. videojs.resetFormatTime = resetFormatTime;
  26475. videojs.parseUrl = parseUrl;
  26476. videojs.isCrossOrigin = isCrossOrigin;
  26477. videojs.EventTarget = EventTarget;
  26478. videojs.on = on;
  26479. videojs.one = one;
  26480. videojs.off = off;
  26481. videojs.trigger = trigger;
  26482. /**
  26483. * A cross-browser XMLHttpRequest wrapper.
  26484. *
  26485. * @function
  26486. * @param {Object} options
  26487. * Settings for the request.
  26488. *
  26489. * @return {XMLHttpRequest|XDomainRequest}
  26490. * The request object.
  26491. *
  26492. * @see https://github.com/Raynos/xhr
  26493. */
  26494. videojs.xhr = lib;
  26495. videojs.TextTrack = TextTrack;
  26496. videojs.AudioTrack = AudioTrack;
  26497. videojs.VideoTrack = VideoTrack;
  26498. ['isEl', 'isTextNode', 'createEl', 'hasClass', 'addClass', 'removeClass', 'toggleClass', 'setAttributes', 'getAttributes', 'emptyEl', 'appendContent', 'insertContent'].forEach(function (k) {
  26499. videojs[k] = function () {
  26500. log.warn("videojs." + k + "() is deprecated; use videojs.dom." + k + "() instead");
  26501. return Dom[k].apply(null, arguments);
  26502. };
  26503. });
  26504. videojs.computedStyle = computedStyle;
  26505. /**
  26506. * A reference to the {@link module:dom|DOM utility module} as an object.
  26507. *
  26508. * @type {Object}
  26509. * @see {@link module:dom|dom}
  26510. */
  26511. videojs.dom = Dom;
  26512. /**
  26513. * A reference to the {@link module:url|URL utility module} as an object.
  26514. *
  26515. * @type {Object}
  26516. * @see {@link module:url|url}
  26517. */
  26518. videojs.url = Url;
  26519. videojs.defineLazyProperty = defineLazyProperty; // Adding less ambiguous text for fullscreen button.
  26520. // In a major update this could become the default text and key.
  26521. videojs.addLanguage('en', {
  26522. 'Non-Fullscreen': 'Exit Fullscreen'
  26523. });
  26524. return videojs;
  26525. })));