index.js 372 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077
  1. /**
  2. * Name: Metaverse
  3. * Date: 2022/4/11
  4. * Author: https://www.4dkankan.com
  5. * Copyright © 2022 4DAGE Co., Ltd. All rights reserved.
  6. * Licensed under the GLP license
  7. */
  8. (function (factory) {
  9. typeof define === 'function' && define.amd ? define(factory) :
  10. factory();
  11. })((function () { 'use strict';
  12. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  13. try {
  14. var info = gen[key](arg);
  15. var value = info.value;
  16. } catch (error) {
  17. reject(error);
  18. return;
  19. }
  20. if (info.done) {
  21. resolve(value);
  22. } else {
  23. Promise.resolve(value).then(_next, _throw);
  24. }
  25. }
  26. function _asyncToGenerator(fn) {
  27. return function () {
  28. var self = this,
  29. args = arguments;
  30. return new Promise(function (resolve, reject) {
  31. var gen = fn.apply(self, args);
  32. function _next(value) {
  33. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  34. }
  35. function _throw(err) {
  36. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  37. }
  38. _next(undefined);
  39. });
  40. };
  41. }
  42. function createCommonjsModule(fn) {
  43. var module = { exports: {} };
  44. return fn(module, module.exports), module.exports;
  45. }
  46. /**
  47. * Copyright (c) 2014-present, Facebook, Inc.
  48. *
  49. * This source code is licensed under the MIT license found in the
  50. * LICENSE file in the root directory of this source tree.
  51. */
  52. var runtime_1 = createCommonjsModule(function (module) {
  53. var runtime = (function (exports) {
  54. var Op = Object.prototype;
  55. var hasOwn = Op.hasOwnProperty;
  56. var undefined$1; // More compressible than void 0.
  57. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  58. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  59. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  60. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  61. function define(obj, key, value) {
  62. Object.defineProperty(obj, key, {
  63. value: value,
  64. enumerable: true,
  65. configurable: true,
  66. writable: true
  67. });
  68. return obj[key];
  69. }
  70. try {
  71. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  72. define({}, "");
  73. } catch (err) {
  74. define = function(obj, key, value) {
  75. return obj[key] = value;
  76. };
  77. }
  78. function wrap(innerFn, outerFn, self, tryLocsList) {
  79. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  80. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  81. var generator = Object.create(protoGenerator.prototype);
  82. var context = new Context(tryLocsList || []);
  83. // The ._invoke method unifies the implementations of the .next,
  84. // .throw, and .return methods.
  85. generator._invoke = makeInvokeMethod(innerFn, self, context);
  86. return generator;
  87. }
  88. exports.wrap = wrap;
  89. // Try/catch helper to minimize deoptimizations. Returns a completion
  90. // record like context.tryEntries[i].completion. This interface could
  91. // have been (and was previously) designed to take a closure to be
  92. // invoked without arguments, but in all the cases we care about we
  93. // already have an existing method we want to call, so there's no need
  94. // to create a new function object. We can even get away with assuming
  95. // the method takes exactly one argument, since that happens to be true
  96. // in every case, so we don't have to touch the arguments object. The
  97. // only additional allocation required is the completion record, which
  98. // has a stable shape and so hopefully should be cheap to allocate.
  99. function tryCatch(fn, obj, arg) {
  100. try {
  101. return { type: "normal", arg: fn.call(obj, arg) };
  102. } catch (err) {
  103. return { type: "throw", arg: err };
  104. }
  105. }
  106. var GenStateSuspendedStart = "suspendedStart";
  107. var GenStateSuspendedYield = "suspendedYield";
  108. var GenStateExecuting = "executing";
  109. var GenStateCompleted = "completed";
  110. // Returning this object from the innerFn has the same effect as
  111. // breaking out of the dispatch switch statement.
  112. var ContinueSentinel = {};
  113. // Dummy constructor functions that we use as the .constructor and
  114. // .constructor.prototype properties for functions that return Generator
  115. // objects. For full spec compliance, you may wish to configure your
  116. // minifier not to mangle the names of these two functions.
  117. function Generator() {}
  118. function GeneratorFunction() {}
  119. function GeneratorFunctionPrototype() {}
  120. // This is a polyfill for %IteratorPrototype% for environments that
  121. // don't natively support it.
  122. var IteratorPrototype = {};
  123. define(IteratorPrototype, iteratorSymbol, function () {
  124. return this;
  125. });
  126. var getProto = Object.getPrototypeOf;
  127. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  128. if (NativeIteratorPrototype &&
  129. NativeIteratorPrototype !== Op &&
  130. hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  131. // This environment has a native %IteratorPrototype%; use it instead
  132. // of the polyfill.
  133. IteratorPrototype = NativeIteratorPrototype;
  134. }
  135. var Gp = GeneratorFunctionPrototype.prototype =
  136. Generator.prototype = Object.create(IteratorPrototype);
  137. GeneratorFunction.prototype = GeneratorFunctionPrototype;
  138. define(Gp, "constructor", GeneratorFunctionPrototype);
  139. define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
  140. GeneratorFunction.displayName = define(
  141. GeneratorFunctionPrototype,
  142. toStringTagSymbol,
  143. "GeneratorFunction"
  144. );
  145. // Helper for defining the .next, .throw, and .return methods of the
  146. // Iterator interface in terms of a single ._invoke method.
  147. function defineIteratorMethods(prototype) {
  148. ["next", "throw", "return"].forEach(function(method) {
  149. define(prototype, method, function(arg) {
  150. return this._invoke(method, arg);
  151. });
  152. });
  153. }
  154. exports.isGeneratorFunction = function(genFun) {
  155. var ctor = typeof genFun === "function" && genFun.constructor;
  156. return ctor
  157. ? ctor === GeneratorFunction ||
  158. // For the native GeneratorFunction constructor, the best we can
  159. // do is to check its .name property.
  160. (ctor.displayName || ctor.name) === "GeneratorFunction"
  161. : false;
  162. };
  163. exports.mark = function(genFun) {
  164. if (Object.setPrototypeOf) {
  165. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  166. } else {
  167. genFun.__proto__ = GeneratorFunctionPrototype;
  168. define(genFun, toStringTagSymbol, "GeneratorFunction");
  169. }
  170. genFun.prototype = Object.create(Gp);
  171. return genFun;
  172. };
  173. // Within the body of any async function, `await x` is transformed to
  174. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  175. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  176. // meant to be awaited.
  177. exports.awrap = function(arg) {
  178. return { __await: arg };
  179. };
  180. function AsyncIterator(generator, PromiseImpl) {
  181. function invoke(method, arg, resolve, reject) {
  182. var record = tryCatch(generator[method], generator, arg);
  183. if (record.type === "throw") {
  184. reject(record.arg);
  185. } else {
  186. var result = record.arg;
  187. var value = result.value;
  188. if (value &&
  189. typeof value === "object" &&
  190. hasOwn.call(value, "__await")) {
  191. return PromiseImpl.resolve(value.__await).then(function(value) {
  192. invoke("next", value, resolve, reject);
  193. }, function(err) {
  194. invoke("throw", err, resolve, reject);
  195. });
  196. }
  197. return PromiseImpl.resolve(value).then(function(unwrapped) {
  198. // When a yielded Promise is resolved, its final value becomes
  199. // the .value of the Promise<{value,done}> result for the
  200. // current iteration.
  201. result.value = unwrapped;
  202. resolve(result);
  203. }, function(error) {
  204. // If a rejected Promise was yielded, throw the rejection back
  205. // into the async generator function so it can be handled there.
  206. return invoke("throw", error, resolve, reject);
  207. });
  208. }
  209. }
  210. var previousPromise;
  211. function enqueue(method, arg) {
  212. function callInvokeWithMethodAndArg() {
  213. return new PromiseImpl(function(resolve, reject) {
  214. invoke(method, arg, resolve, reject);
  215. });
  216. }
  217. return previousPromise =
  218. // If enqueue has been called before, then we want to wait until
  219. // all previous Promises have been resolved before calling invoke,
  220. // so that results are always delivered in the correct order. If
  221. // enqueue has not been called before, then it is important to
  222. // call invoke immediately, without waiting on a callback to fire,
  223. // so that the async generator function has the opportunity to do
  224. // any necessary setup in a predictable way. This predictability
  225. // is why the Promise constructor synchronously invokes its
  226. // executor callback, and why async functions synchronously
  227. // execute code before the first await. Since we implement simple
  228. // async functions in terms of async generators, it is especially
  229. // important to get this right, even though it requires care.
  230. previousPromise ? previousPromise.then(
  231. callInvokeWithMethodAndArg,
  232. // Avoid propagating failures to Promises returned by later
  233. // invocations of the iterator.
  234. callInvokeWithMethodAndArg
  235. ) : callInvokeWithMethodAndArg();
  236. }
  237. // Define the unified helper method that is used to implement .next,
  238. // .throw, and .return (see defineIteratorMethods).
  239. this._invoke = enqueue;
  240. }
  241. defineIteratorMethods(AsyncIterator.prototype);
  242. define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  243. return this;
  244. });
  245. exports.AsyncIterator = AsyncIterator;
  246. // Note that simple async functions are implemented on top of
  247. // AsyncIterator objects; they just return a Promise for the value of
  248. // the final result produced by the iterator.
  249. exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  250. if (PromiseImpl === void 0) PromiseImpl = Promise;
  251. var iter = new AsyncIterator(
  252. wrap(innerFn, outerFn, self, tryLocsList),
  253. PromiseImpl
  254. );
  255. return exports.isGeneratorFunction(outerFn)
  256. ? iter // If outerFn is a generator, return the full iterator.
  257. : iter.next().then(function(result) {
  258. return result.done ? result.value : iter.next();
  259. });
  260. };
  261. function makeInvokeMethod(innerFn, self, context) {
  262. var state = GenStateSuspendedStart;
  263. return function invoke(method, arg) {
  264. if (state === GenStateExecuting) {
  265. throw new Error("Generator is already running");
  266. }
  267. if (state === GenStateCompleted) {
  268. if (method === "throw") {
  269. throw arg;
  270. }
  271. // Be forgiving, per 25.3.3.3.3 of the spec:
  272. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  273. return doneResult();
  274. }
  275. context.method = method;
  276. context.arg = arg;
  277. while (true) {
  278. var delegate = context.delegate;
  279. if (delegate) {
  280. var delegateResult = maybeInvokeDelegate(delegate, context);
  281. if (delegateResult) {
  282. if (delegateResult === ContinueSentinel) continue;
  283. return delegateResult;
  284. }
  285. }
  286. if (context.method === "next") {
  287. // Setting context._sent for legacy support of Babel's
  288. // function.sent implementation.
  289. context.sent = context._sent = context.arg;
  290. } else if (context.method === "throw") {
  291. if (state === GenStateSuspendedStart) {
  292. state = GenStateCompleted;
  293. throw context.arg;
  294. }
  295. context.dispatchException(context.arg);
  296. } else if (context.method === "return") {
  297. context.abrupt("return", context.arg);
  298. }
  299. state = GenStateExecuting;
  300. var record = tryCatch(innerFn, self, context);
  301. if (record.type === "normal") {
  302. // If an exception is thrown from innerFn, we leave state ===
  303. // GenStateExecuting and loop back for another invocation.
  304. state = context.done
  305. ? GenStateCompleted
  306. : GenStateSuspendedYield;
  307. if (record.arg === ContinueSentinel) {
  308. continue;
  309. }
  310. return {
  311. value: record.arg,
  312. done: context.done
  313. };
  314. } else if (record.type === "throw") {
  315. state = GenStateCompleted;
  316. // Dispatch the exception by looping back around to the
  317. // context.dispatchException(context.arg) call above.
  318. context.method = "throw";
  319. context.arg = record.arg;
  320. }
  321. }
  322. };
  323. }
  324. // Call delegate.iterator[context.method](context.arg) and handle the
  325. // result, either by returning a { value, done } result from the
  326. // delegate iterator, or by modifying context.method and context.arg,
  327. // setting context.delegate to null, and returning the ContinueSentinel.
  328. function maybeInvokeDelegate(delegate, context) {
  329. var method = delegate.iterator[context.method];
  330. if (method === undefined$1) {
  331. // A .throw or .return when the delegate iterator has no .throw
  332. // method always terminates the yield* loop.
  333. context.delegate = null;
  334. if (context.method === "throw") {
  335. // Note: ["return"] must be used for ES3 parsing compatibility.
  336. if (delegate.iterator["return"]) {
  337. // If the delegate iterator has a return method, give it a
  338. // chance to clean up.
  339. context.method = "return";
  340. context.arg = undefined$1;
  341. maybeInvokeDelegate(delegate, context);
  342. if (context.method === "throw") {
  343. // If maybeInvokeDelegate(context) changed context.method from
  344. // "return" to "throw", let that override the TypeError below.
  345. return ContinueSentinel;
  346. }
  347. }
  348. context.method = "throw";
  349. context.arg = new TypeError(
  350. "The iterator does not provide a 'throw' method");
  351. }
  352. return ContinueSentinel;
  353. }
  354. var record = tryCatch(method, delegate.iterator, context.arg);
  355. if (record.type === "throw") {
  356. context.method = "throw";
  357. context.arg = record.arg;
  358. context.delegate = null;
  359. return ContinueSentinel;
  360. }
  361. var info = record.arg;
  362. if (! info) {
  363. context.method = "throw";
  364. context.arg = new TypeError("iterator result is not an object");
  365. context.delegate = null;
  366. return ContinueSentinel;
  367. }
  368. if (info.done) {
  369. // Assign the result of the finished delegate to the temporary
  370. // variable specified by delegate.resultName (see delegateYield).
  371. context[delegate.resultName] = info.value;
  372. // Resume execution at the desired location (see delegateYield).
  373. context.next = delegate.nextLoc;
  374. // If context.method was "throw" but the delegate handled the
  375. // exception, let the outer generator proceed normally. If
  376. // context.method was "next", forget context.arg since it has been
  377. // "consumed" by the delegate iterator. If context.method was
  378. // "return", allow the original .return call to continue in the
  379. // outer generator.
  380. if (context.method !== "return") {
  381. context.method = "next";
  382. context.arg = undefined$1;
  383. }
  384. } else {
  385. // Re-yield the result returned by the delegate method.
  386. return info;
  387. }
  388. // The delegate iterator is finished, so forget it and continue with
  389. // the outer generator.
  390. context.delegate = null;
  391. return ContinueSentinel;
  392. }
  393. // Define Generator.prototype.{next,throw,return} in terms of the
  394. // unified ._invoke helper method.
  395. defineIteratorMethods(Gp);
  396. define(Gp, toStringTagSymbol, "Generator");
  397. // A Generator should always return itself as the iterator object when the
  398. // @@iterator function is called on it. Some browsers' implementations of the
  399. // iterator prototype chain incorrectly implement this, causing the Generator
  400. // object to not be returned from this call. This ensures that doesn't happen.
  401. // See https://github.com/facebook/regenerator/issues/274 for more details.
  402. define(Gp, iteratorSymbol, function() {
  403. return this;
  404. });
  405. define(Gp, "toString", function() {
  406. return "[object Generator]";
  407. });
  408. function pushTryEntry(locs) {
  409. var entry = { tryLoc: locs[0] };
  410. if (1 in locs) {
  411. entry.catchLoc = locs[1];
  412. }
  413. if (2 in locs) {
  414. entry.finallyLoc = locs[2];
  415. entry.afterLoc = locs[3];
  416. }
  417. this.tryEntries.push(entry);
  418. }
  419. function resetTryEntry(entry) {
  420. var record = entry.completion || {};
  421. record.type = "normal";
  422. delete record.arg;
  423. entry.completion = record;
  424. }
  425. function Context(tryLocsList) {
  426. // The root entry object (effectively a try statement without a catch
  427. // or a finally block) gives us a place to store values thrown from
  428. // locations where there is no enclosing try statement.
  429. this.tryEntries = [{ tryLoc: "root" }];
  430. tryLocsList.forEach(pushTryEntry, this);
  431. this.reset(true);
  432. }
  433. exports.keys = function(object) {
  434. var keys = [];
  435. for (var key in object) {
  436. keys.push(key);
  437. }
  438. keys.reverse();
  439. // Rather than returning an object with a next method, we keep
  440. // things simple and return the next function itself.
  441. return function next() {
  442. while (keys.length) {
  443. var key = keys.pop();
  444. if (key in object) {
  445. next.value = key;
  446. next.done = false;
  447. return next;
  448. }
  449. }
  450. // To avoid creating an additional object, we just hang the .value
  451. // and .done properties off the next function object itself. This
  452. // also ensures that the minifier will not anonymize the function.
  453. next.done = true;
  454. return next;
  455. };
  456. };
  457. function values(iterable) {
  458. if (iterable) {
  459. var iteratorMethod = iterable[iteratorSymbol];
  460. if (iteratorMethod) {
  461. return iteratorMethod.call(iterable);
  462. }
  463. if (typeof iterable.next === "function") {
  464. return iterable;
  465. }
  466. if (!isNaN(iterable.length)) {
  467. var i = -1, next = function next() {
  468. while (++i < iterable.length) {
  469. if (hasOwn.call(iterable, i)) {
  470. next.value = iterable[i];
  471. next.done = false;
  472. return next;
  473. }
  474. }
  475. next.value = undefined$1;
  476. next.done = true;
  477. return next;
  478. };
  479. return next.next = next;
  480. }
  481. }
  482. // Return an iterator with no values.
  483. return { next: doneResult };
  484. }
  485. exports.values = values;
  486. function doneResult() {
  487. return { value: undefined$1, done: true };
  488. }
  489. Context.prototype = {
  490. constructor: Context,
  491. reset: function(skipTempReset) {
  492. this.prev = 0;
  493. this.next = 0;
  494. // Resetting context._sent for legacy support of Babel's
  495. // function.sent implementation.
  496. this.sent = this._sent = undefined$1;
  497. this.done = false;
  498. this.delegate = null;
  499. this.method = "next";
  500. this.arg = undefined$1;
  501. this.tryEntries.forEach(resetTryEntry);
  502. if (!skipTempReset) {
  503. for (var name in this) {
  504. // Not sure about the optimal order of these conditions:
  505. if (name.charAt(0) === "t" &&
  506. hasOwn.call(this, name) &&
  507. !isNaN(+name.slice(1))) {
  508. this[name] = undefined$1;
  509. }
  510. }
  511. }
  512. },
  513. stop: function() {
  514. this.done = true;
  515. var rootEntry = this.tryEntries[0];
  516. var rootRecord = rootEntry.completion;
  517. if (rootRecord.type === "throw") {
  518. throw rootRecord.arg;
  519. }
  520. return this.rval;
  521. },
  522. dispatchException: function(exception) {
  523. if (this.done) {
  524. throw exception;
  525. }
  526. var context = this;
  527. function handle(loc, caught) {
  528. record.type = "throw";
  529. record.arg = exception;
  530. context.next = loc;
  531. if (caught) {
  532. // If the dispatched exception was caught by a catch block,
  533. // then let that catch block handle the exception normally.
  534. context.method = "next";
  535. context.arg = undefined$1;
  536. }
  537. return !! caught;
  538. }
  539. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  540. var entry = this.tryEntries[i];
  541. var record = entry.completion;
  542. if (entry.tryLoc === "root") {
  543. // Exception thrown outside of any try block that could handle
  544. // it, so set the completion value of the entire function to
  545. // throw the exception.
  546. return handle("end");
  547. }
  548. if (entry.tryLoc <= this.prev) {
  549. var hasCatch = hasOwn.call(entry, "catchLoc");
  550. var hasFinally = hasOwn.call(entry, "finallyLoc");
  551. if (hasCatch && hasFinally) {
  552. if (this.prev < entry.catchLoc) {
  553. return handle(entry.catchLoc, true);
  554. } else if (this.prev < entry.finallyLoc) {
  555. return handle(entry.finallyLoc);
  556. }
  557. } else if (hasCatch) {
  558. if (this.prev < entry.catchLoc) {
  559. return handle(entry.catchLoc, true);
  560. }
  561. } else if (hasFinally) {
  562. if (this.prev < entry.finallyLoc) {
  563. return handle(entry.finallyLoc);
  564. }
  565. } else {
  566. throw new Error("try statement without catch or finally");
  567. }
  568. }
  569. }
  570. },
  571. abrupt: function(type, arg) {
  572. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  573. var entry = this.tryEntries[i];
  574. if (entry.tryLoc <= this.prev &&
  575. hasOwn.call(entry, "finallyLoc") &&
  576. this.prev < entry.finallyLoc) {
  577. var finallyEntry = entry;
  578. break;
  579. }
  580. }
  581. if (finallyEntry &&
  582. (type === "break" ||
  583. type === "continue") &&
  584. finallyEntry.tryLoc <= arg &&
  585. arg <= finallyEntry.finallyLoc) {
  586. // Ignore the finally entry if control is not jumping to a
  587. // location outside the try/catch block.
  588. finallyEntry = null;
  589. }
  590. var record = finallyEntry ? finallyEntry.completion : {};
  591. record.type = type;
  592. record.arg = arg;
  593. if (finallyEntry) {
  594. this.method = "next";
  595. this.next = finallyEntry.finallyLoc;
  596. return ContinueSentinel;
  597. }
  598. return this.complete(record);
  599. },
  600. complete: function(record, afterLoc) {
  601. if (record.type === "throw") {
  602. throw record.arg;
  603. }
  604. if (record.type === "break" ||
  605. record.type === "continue") {
  606. this.next = record.arg;
  607. } else if (record.type === "return") {
  608. this.rval = this.arg = record.arg;
  609. this.method = "return";
  610. this.next = "end";
  611. } else if (record.type === "normal" && afterLoc) {
  612. this.next = afterLoc;
  613. }
  614. return ContinueSentinel;
  615. },
  616. finish: function(finallyLoc) {
  617. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  618. var entry = this.tryEntries[i];
  619. if (entry.finallyLoc === finallyLoc) {
  620. this.complete(entry.completion, entry.afterLoc);
  621. resetTryEntry(entry);
  622. return ContinueSentinel;
  623. }
  624. }
  625. },
  626. "catch": function(tryLoc) {
  627. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  628. var entry = this.tryEntries[i];
  629. if (entry.tryLoc === tryLoc) {
  630. var record = entry.completion;
  631. if (record.type === "throw") {
  632. var thrown = record.arg;
  633. resetTryEntry(entry);
  634. }
  635. return thrown;
  636. }
  637. }
  638. // The context.catch method must only be called with a location
  639. // argument that corresponds to a known catch block.
  640. throw new Error("illegal catch attempt");
  641. },
  642. delegateYield: function(iterable, resultName, nextLoc) {
  643. this.delegate = {
  644. iterator: values(iterable),
  645. resultName: resultName,
  646. nextLoc: nextLoc
  647. };
  648. if (this.method === "next") {
  649. // Deliberately forget the last sent value so that we don't
  650. // accidentally pass it on to the delegate.
  651. this.arg = undefined$1;
  652. }
  653. return ContinueSentinel;
  654. }
  655. };
  656. // Regardless of whether this script is executing as a CommonJS module
  657. // or not, return the runtime object so that we can declare the variable
  658. // regeneratorRuntime in the outer scope, which allows this module to be
  659. // injected easily by `bin/regenerator --include-runtime script.js`.
  660. return exports;
  661. }(
  662. // If this script is executing as a CommonJS module, use module.exports
  663. // as the regeneratorRuntime namespace. Otherwise create a new empty
  664. // object. Either way, the resulting object will be used to initialize
  665. // the regeneratorRuntime variable at the top of this file.
  666. module.exports
  667. ));
  668. try {
  669. regeneratorRuntime = runtime;
  670. } catch (accidentalStrictMode) {
  671. // This module should not be running in strict mode, so the above
  672. // assignment should always work unless something is misconfigured. Just
  673. // in case runtime.js accidentally runs in strict mode, in modern engines
  674. // we can explicitly access globalThis. In older engines we can escape
  675. // strict mode using a global Function call. This could conceivably fail
  676. // if a Content Security Policy forbids using Function, but in that case
  677. // the proper solution is to fix the accidental strict mode problem. If
  678. // you've misconfigured your bundler to force strict mode and applied a
  679. // CSP to forbid Function, and you're not willing to fix either of those
  680. // problems, please detail your unique predicament in a GitHub issue.
  681. if (typeof globalThis === "object") {
  682. globalThis.regeneratorRuntime = runtime;
  683. } else {
  684. Function("r", "regeneratorRuntime = r")(runtime);
  685. }
  686. }
  687. });
  688. var regenerator = runtime_1;
  689. function _classCallCheck(instance, Constructor) {
  690. if (!(instance instanceof Constructor)) {
  691. throw new TypeError("Cannot call a class as a function");
  692. }
  693. }
  694. function _defineProperties(target, props) {
  695. for (var i = 0; i < props.length; i++) {
  696. var descriptor = props[i];
  697. descriptor.enumerable = descriptor.enumerable || false;
  698. descriptor.configurable = true;
  699. if ("value" in descriptor) descriptor.writable = true;
  700. Object.defineProperty(target, descriptor.key, descriptor);
  701. }
  702. }
  703. function _createClass(Constructor, protoProps, staticProps) {
  704. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  705. if (staticProps) _defineProperties(Constructor, staticProps);
  706. Object.defineProperty(Constructor, "prototype", {
  707. writable: false
  708. });
  709. return Constructor;
  710. }
  711. var util = {
  712. uuid() {
  713. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (i) {
  714. var e = Math.random() * 16 | 0;
  715. return (i === "x" ? e : e & 3 | 8).toString(16);
  716. });
  717. },
  718. getFormattedDate(i) {
  719. var e = i.getMonth() + 1,
  720. t = i.getDate(),
  721. r = i.getHours(),
  722. n = i.getMinutes(),
  723. o = i.getSeconds(),
  724. a = i.getMilliseconds(),
  725. s = (e < 10 ? "0" : "") + e,
  726. l = (t < 10 ? "0" : "") + t,
  727. u = (r < 10 ? "0" : "") + r,
  728. c = (n < 10 ? "0" : "") + n,
  729. h = (o < 10 ? "0" : "") + o;
  730. return i.getFullYear() + "-" + s + "-" + l + " " + u + ":" + c + ":" + h + "." + a;
  731. },
  732. createInstance(i) {
  733. var e = new Axios(i),
  734. t = bind(Axios.prototype.request, e);
  735. return utils.extend(t, Axios.prototype, e), utils.extend(t, e), t.create = function (n) {
  736. return createInstance(mergeConfig(i, n));
  737. }, t;
  738. },
  739. mapLimit(i, e, t) {
  740. return new Promise(function (r, n) {
  741. var o = i.length;
  742. var a = e - 1,
  743. s = 0;
  744. var l = function l(u) {
  745. u.forEach(function (c) {
  746. t(c).then(function () {
  747. if (s++, s === o) {
  748. r();
  749. return;
  750. }
  751. a++;
  752. var h = i[a];
  753. h && l([h]);
  754. }, function (h) {
  755. n(h);
  756. });
  757. });
  758. };
  759. l(i.slice(0, e));
  760. });
  761. },
  762. isWebAssemblySupported() {
  763. try {
  764. if (typeof WebAssembly == "object" && typeof WebAssembly.instantiate == "function") {
  765. var i = new WebAssembly.Module(Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0));
  766. if (i instanceof WebAssembly.Module) return new WebAssembly.Instance(i) instanceof WebAssembly.Instance;
  767. }
  768. } catch (_unused) {}
  769. return console.log("wasm is not supported"), !1;
  770. },
  771. isSupported() {
  772. return typeof RTCPeerConnection == "function" && this.isWebAssemblySupported();
  773. }
  774. };
  775. function _setPrototypeOf(o, p) {
  776. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  777. o.__proto__ = p;
  778. return o;
  779. };
  780. return _setPrototypeOf(o, p);
  781. }
  782. function _inherits(subClass, superClass) {
  783. if (typeof superClass !== "function" && superClass !== null) {
  784. throw new TypeError("Super expression must either be null or a function");
  785. }
  786. subClass.prototype = Object.create(superClass && superClass.prototype, {
  787. constructor: {
  788. value: subClass,
  789. writable: true,
  790. configurable: true
  791. }
  792. });
  793. Object.defineProperty(subClass, "prototype", {
  794. writable: false
  795. });
  796. if (superClass) _setPrototypeOf(subClass, superClass);
  797. }
  798. function _typeof(obj) {
  799. "@babel/helpers - typeof";
  800. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  801. return typeof obj;
  802. } : function (obj) {
  803. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  804. }, _typeof(obj);
  805. }
  806. function _assertThisInitialized(self) {
  807. if (self === void 0) {
  808. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  809. }
  810. return self;
  811. }
  812. function _possibleConstructorReturn(self, call) {
  813. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  814. return call;
  815. } else if (call !== void 0) {
  816. throw new TypeError("Derived constructors may only return object or undefined");
  817. }
  818. return _assertThisInitialized(self);
  819. }
  820. function _getPrototypeOf(o) {
  821. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  822. return o.__proto__ || Object.getPrototypeOf(o);
  823. };
  824. return _getPrototypeOf(o);
  825. }
  826. function _createSuper$k(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$l(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  827. function _isNativeReflectConstruct$l() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  828. var Reporter = /*#__PURE__*/function (_EventEmitter) {
  829. _inherits(Reporter, _EventEmitter);
  830. var _super = _createSuper$k(Reporter);
  831. function Reporter() {
  832. var _this;
  833. _classCallCheck(this, Reporter);
  834. _this = _super.call(this);
  835. _this._header = {};
  836. _this._body = {};
  837. _this._queue = [];
  838. _this._disabled = !1;
  839. _this._interval = null;
  840. _this._reportUrl = null;
  841. _this.isDocumentLoaded = function () {
  842. return document.readyState === "complete";
  843. };
  844. _this._header.logModuleId = REPORT_MODULE_TYPE, _this._header.url = location.href, _this._header.enviroment = ENV, _this._header.networkType = window.navigator.connection ? window.navigator.connection.type : "unknown", _this._interval = window.setInterval(function () {
  845. _this._flushReport();
  846. }, 10 * 1e3);
  847. return _this;
  848. }
  849. _createClass(Reporter, [{
  850. key: "disable",
  851. value: function disable() {
  852. this._disabled = !0, this._interval && window.clearInterval(this._interval);
  853. }
  854. }, {
  855. key: "updateHeader",
  856. value: function updateHeader(e) {
  857. Object.assign(this._header, e);
  858. }
  859. }, {
  860. key: "updateBody",
  861. value: function updateBody(e) {
  862. Object.assign(this._body, e);
  863. }
  864. }, {
  865. key: "updateReportUrl",
  866. value: function updateReportUrl(e) {
  867. this._reportUrl = e;
  868. }
  869. }, {
  870. key: "report",
  871. value: function report(e, t, r) {
  872. var _this2 = this;
  873. if (this._disabled) return;
  874. r || (r = {});
  875. var _r = r,
  876. n = _r.immediate,
  877. o = _r.sampleRate;
  878. if (o && o > Math.random()) return;
  879. this.updateBody({
  880. logTime: util.getFormattedDate(new Date()),
  881. logTimestamp: Date.now()
  882. });
  883. var a = function a(s) {
  884. var l = oe(le(oe({}, _this2._body), {
  885. type: e
  886. }), s);
  887. _this2._queue.push(l), e === "measurement" && _this2.emit("report", s);
  888. };
  889. Array.isArray(t) ? t.forEach(function (s) {
  890. return a(s);
  891. }) : a(t), (n || this._queue.length >= REPORT_NUM_PER_REQUEST) && this._flushReport();
  892. }
  893. }, {
  894. key: "_flushReport",
  895. value: function _flushReport() {
  896. if (this._disabled || !this._queue.length || !this.isDocumentLoaded()) return;
  897. var e = {
  898. header: this._header,
  899. body: this._queue.splice(0, REPORT_NUM_PER_REQUEST)
  900. };
  901. this._post(e);
  902. }
  903. }, {
  904. key: "_post",
  905. value: function _post(e) {
  906. var t = this._reportUrl || REPORT_URL.DEV;
  907. return new Promise(function (r, n) {
  908. var o = new XMLHttpRequest();
  909. o.open("POST", t), o.setRequestHeader("Content-Type", "application/json");
  910. try {
  911. o.send(JSON.stringify(e));
  912. } catch (a) {
  913. console.error(a);
  914. }
  915. o.addEventListener("readystatechange", function () {
  916. if (o.readyState == 4) return o.status == 200 ? r(o) : n("Unable to send log");
  917. });
  918. });
  919. }
  920. }]);
  921. return Reporter;
  922. }(EventEmitter);
  923. var reporter$1 = new Reporter();
  924. function _arrayLikeToArray$1(arr, len) {
  925. if (len == null || len > arr.length) len = arr.length;
  926. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  927. arr2[i] = arr[i];
  928. }
  929. return arr2;
  930. }
  931. function _arrayWithoutHoles(arr) {
  932. if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
  933. }
  934. function _iterableToArray(iter) {
  935. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  936. }
  937. function _unsupportedIterableToArray$1(o, minLen) {
  938. if (!o) return;
  939. if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
  940. var n = Object.prototype.toString.call(o).slice(8, -1);
  941. if (n === "Object" && o.constructor) n = o.constructor.name;
  942. if (n === "Map" || n === "Set") return Array.from(o);
  943. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
  944. }
  945. function _nonIterableSpread() {
  946. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  947. }
  948. function _toConsumableArray(arr) {
  949. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
  950. }
  951. var Codes = {
  952. Success: 0,
  953. Param: 1001,
  954. Internal: 1002,
  955. Timeout: 1003,
  956. Authentication: 1004,
  957. TokenExpired: 1005,
  958. Unsupported: 1006,
  959. InitNetworkTimeout: 1007,
  960. InitDecoderTimeout: 1008,
  961. InitConfigTimeout: 1009,
  962. InitEngineTimeout: 1010,
  963. InitEngine: 1011,
  964. ActionBlocked: 1012,
  965. PreloadCanceled: 1013,
  966. FrequencyLimit: 1014,
  967. UsersUpperLimit: 2e3,
  968. RoomsUpperLimit: 2001,
  969. ServerParam: 2002,
  970. LackOfToken: 2003,
  971. LoginFailed: 2004,
  972. VerifyServiceDown: 2005,
  973. CreateSessionFailed: 2006,
  974. RtcConnection: 2008,
  975. DoActionFailed: 2009,
  976. StateSyncFailed: 2010,
  977. BroadcastFailed: 2011,
  978. DataAbnormal: 2012,
  979. GetOnVehicle: 2015,
  980. RepeatLogin: 2017,
  981. RoomDoseNotExist: 2018,
  982. TicketExpire: 2019,
  983. ServerRateLimit: 2020,
  984. DoActionBlocked: 2333,
  985. ActionMaybeDelay: 2334,
  986. ActionResponseTimeout: 2999
  987. };
  988. var Logger$1 = /*#__PURE__*/function () {
  989. function Logger(e) {
  990. _classCallCheck(this, Logger);
  991. this.level = 3;
  992. this.module = e;
  993. }
  994. _createClass(Logger, [{
  995. key: "setLevel",
  996. value: function setLevel(e) {
  997. this.level = e;
  998. }
  999. }, {
  1000. key: "atleast",
  1001. value: function atleast(e) {
  1002. return e >= this.level && e >= this.level;
  1003. }
  1004. }, {
  1005. key: "print",
  1006. value: function print(e, t) {
  1007. for (var _len = arguments.length, r = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  1008. r[_key - 2] = arguments[_key];
  1009. }
  1010. if (this.atleast(t)) {
  1011. var _console$n;
  1012. var n = e == "debug" ? "info" : e,
  1013. o = this.prefix(e);
  1014. (_console$n = console[n]).call.apply(_console$n, [null, o].concat(r));
  1015. }
  1016. if (e !== "debug" && e !== "info") {
  1017. var _n = r.map(function (o) {
  1018. if (o instanceof Object) try {
  1019. return JSON.stringify(o);
  1020. } catch (_unused) {
  1021. return o;
  1022. } else return o;
  1023. }).join(",");
  1024. reporter$1.report("log", {
  1025. message: _n,
  1026. level: e,
  1027. module: this.module
  1028. });
  1029. }
  1030. }
  1031. }, {
  1032. key: "debug",
  1033. value: function debug() {
  1034. for (var _len2 = arguments.length, e = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  1035. e[_key2] = arguments[_key2];
  1036. }
  1037. return this.print.apply(this, ["debug", 1].concat(e));
  1038. }
  1039. }, {
  1040. key: "info",
  1041. value: function info() {
  1042. for (var _len3 = arguments.length, e = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  1043. e[_key3] = arguments[_key3];
  1044. }
  1045. return this.print.apply(this, ["info", 2].concat(e));
  1046. }
  1047. }, {
  1048. key: "infoAndReportLog",
  1049. value: function infoAndReportLog(e) {
  1050. for (var _len4 = arguments.length, t = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
  1051. t[_key4 - 1] = arguments[_key4];
  1052. }
  1053. var r = e.reportOptions;
  1054. delete e.reportOptions, reporter$1.report("log", e, r), t.length || (t = [e.message]), this.debug.apply(this, _toConsumableArray(t));
  1055. }
  1056. }, {
  1057. key: "infoAndReportMeasurement",
  1058. value: function infoAndReportMeasurement(e) {
  1059. for (var _len5 = arguments.length, t = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
  1060. t[_key5 - 1] = arguments[_key5];
  1061. }
  1062. var n;
  1063. var r = e.reportOptions;
  1064. if (e.startTime) {
  1065. var o = Date.now();
  1066. e.value === void 0 && (e.endTime = o), e.value === void 0 && (e.value = o - e.startTime);
  1067. }
  1068. if (e.error ? e.code = ((n = e.error) == null ? void 0 : n.code) || Codes.Internal : e.code = Codes.Success, reporter$1.report("measurement", e, r), t.length || (t = [e]), e.level === 4 || e.error) {
  1069. this.error.apply(this, _toConsumableArray(t));
  1070. return;
  1071. }
  1072. this.warn.apply(this, _toConsumableArray(t));
  1073. }
  1074. }, {
  1075. key: "warn",
  1076. value: function warn() {
  1077. for (var _len6 = arguments.length, e = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  1078. e[_key6] = arguments[_key6];
  1079. }
  1080. return this.print.apply(this, ["warn", 3].concat(e));
  1081. }
  1082. }, {
  1083. key: "error",
  1084. value: function error() {
  1085. for (var _len7 = arguments.length, e = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
  1086. e[_key7] = arguments[_key7];
  1087. }
  1088. return this.print.apply(this, ["error", 4].concat(e));
  1089. }
  1090. }, {
  1091. key: "prefix",
  1092. value: function prefix(e) {
  1093. return "[".concat(this.module, "][").concat(e, "] ").concat(util.getFormattedDate(new Date()), ":");
  1094. }
  1095. }], [{
  1096. key: "setLevel",
  1097. value: function setLevel(e) {
  1098. this.level = e;
  1099. }
  1100. }]);
  1101. return Logger;
  1102. }();
  1103. var logger = new Logger$1();
  1104. var AxiosCanceler = /*#__PURE__*/function () {
  1105. function AxiosCanceler() {
  1106. _classCallCheck(this, AxiosCanceler);
  1107. this.pendingMap = new Map();
  1108. }
  1109. _createClass(AxiosCanceler, [{
  1110. key: "addPending",
  1111. value: function addPending(e) {
  1112. var _this = this;
  1113. return new axios.CancelToken(function (t) {
  1114. _this.pendingMap.has(e) || _this.pendingMap.set(e, t);
  1115. });
  1116. }
  1117. }, {
  1118. key: "removeAllPending",
  1119. value: function removeAllPending() {
  1120. this.pendingMap.forEach(function (e) {
  1121. e && isFunction(e) && e();
  1122. }), this.pendingMap.clear();
  1123. }
  1124. }, {
  1125. key: "removePending",
  1126. value: function removePending(e) {
  1127. if (this.pendingMap.has(e)) {
  1128. var t = this.pendingMap.get(e);
  1129. t && t(e), this.pendingMap.delete(e);
  1130. }
  1131. }
  1132. }, {
  1133. key: "removeCancelToken",
  1134. value: function removeCancelToken(e) {
  1135. this.pendingMap.has(e) && this.pendingMap.delete(e);
  1136. }
  1137. }, {
  1138. key: "reset",
  1139. value: function reset() {
  1140. this.pendingMap = new Map();
  1141. }
  1142. }]);
  1143. return AxiosCanceler;
  1144. }();
  1145. function _createSuper$j(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$k(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1146. function _isNativeReflectConstruct$k() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1147. var Http1 = /*#__PURE__*/function (_EventEmitter) {
  1148. _inherits(Http1, _EventEmitter);
  1149. var _super = _createSuper$j(Http1);
  1150. function Http1() {
  1151. var _this;
  1152. _classCallCheck(this, Http1);
  1153. _this = _super.call(this);
  1154. _this.instatnce = axios.create(), _this.canceler = new AxiosCanceler();
  1155. return _this;
  1156. }
  1157. _createClass(Http1, [{
  1158. key: "requestConstant",
  1159. value: function requestConstant() {
  1160. return {
  1161. x_nounce: this.randomString(),
  1162. x_timestamp: new Date().getTime(),
  1163. x_os: "web"
  1164. };
  1165. }
  1166. }, {
  1167. key: "requestParams",
  1168. value: function requestParams(e) {
  1169. return oe({}, e.params);
  1170. }
  1171. }, {
  1172. key: "get",
  1173. value: function get(e) {
  1174. return this.request(le(oe({}, e), {
  1175. method: "GET"
  1176. }));
  1177. }
  1178. }, {
  1179. key: "post",
  1180. value: function post(e) {
  1181. return this.request(le(oe({}, e), {
  1182. method: "POST"
  1183. }));
  1184. }
  1185. }, {
  1186. key: "request",
  1187. value: function request(e) {
  1188. var _this2 = this;
  1189. var t = e.url,
  1190. _e$timeout = e.timeout,
  1191. r = _e$timeout === void 0 ? 1e4 : _e$timeout,
  1192. n = e.method,
  1193. o = e.key,
  1194. a = e.beforeRequest,
  1195. s = e.responseType,
  1196. l = e.data;
  1197. var _e$retry = e.retry,
  1198. u = _e$retry === void 0 ? 0 : _e$retry;
  1199. var c = this.patchUrl(t),
  1200. h = this.canceler.addPending(t);
  1201. a && isFunction(a) && a(e);
  1202. var f = this.requestParams(e);
  1203. var d = {
  1204. url: c,
  1205. method: n,
  1206. timeout: r,
  1207. cancelToken: h,
  1208. responseType: s,
  1209. params: f
  1210. };
  1211. n === "POST" && (d = oe({
  1212. data: l
  1213. }, d));
  1214. var _ = Date.now(),
  1215. g = function g() {
  1216. return _this2.instatnce.request(d).then(function (m) {
  1217. return o && logger.infoAndReportMeasurement({
  1218. metric: "http",
  1219. startTime: _,
  1220. extra: t,
  1221. group: "http",
  1222. tag: o
  1223. }), _this2.canceler.removeCancelToken(t), m;
  1224. }).catch(function (m) {
  1225. var v = axios.isCancel(m);
  1226. return u > 0 && !v ? (u--, logger.warn("request ".concat(t, " retry, left retry count"), u), g()) : (logger.infoAndReportMeasurement({
  1227. metric: "http",
  1228. startTime: _,
  1229. error: m,
  1230. extra: {
  1231. url: t,
  1232. isCanceled: v
  1233. },
  1234. tag: o,
  1235. group: "http"
  1236. }), _this2.canceler.removeCancelToken(t), Promise.reject(m));
  1237. });
  1238. };
  1239. return g();
  1240. }
  1241. }, {
  1242. key: "patchUrl",
  1243. value: function patchUrl(e) {
  1244. return e;
  1245. }
  1246. }, {
  1247. key: "randomString",
  1248. value: function randomString() {
  1249. var e = "";
  1250. var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
  1251. r = t.length;
  1252. for (var n = 0; n < 8; n++) {
  1253. e += t.charAt(Math.floor(Math.random() * r));
  1254. }
  1255. return e;
  1256. }
  1257. }]);
  1258. return Http1;
  1259. }(EventEmitter);
  1260. var http1 = new Http1();
  1261. function _isNativeFunction(fn) {
  1262. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  1263. }
  1264. function _isNativeReflectConstruct$j() {
  1265. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1266. if (Reflect.construct.sham) return false;
  1267. if (typeof Proxy === "function") return true;
  1268. try {
  1269. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  1270. return true;
  1271. } catch (e) {
  1272. return false;
  1273. }
  1274. }
  1275. function _construct(Parent, args, Class) {
  1276. if (_isNativeReflectConstruct$j()) {
  1277. _construct = Reflect.construct;
  1278. } else {
  1279. _construct = function _construct(Parent, args, Class) {
  1280. var a = [null];
  1281. a.push.apply(a, args);
  1282. var Constructor = Function.bind.apply(Parent, a);
  1283. var instance = new Constructor();
  1284. if (Class) _setPrototypeOf(instance, Class.prototype);
  1285. return instance;
  1286. };
  1287. }
  1288. return _construct.apply(null, arguments);
  1289. }
  1290. function _wrapNativeSuper(Class) {
  1291. var _cache = typeof Map === "function" ? new Map() : undefined;
  1292. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1293. if (Class === null || !_isNativeFunction(Class)) return Class;
  1294. if (typeof Class !== "function") {
  1295. throw new TypeError("Super expression must either be null or a function");
  1296. }
  1297. if (typeof _cache !== "undefined") {
  1298. if (_cache.has(Class)) return _cache.get(Class);
  1299. _cache.set(Class, Wrapper);
  1300. }
  1301. function Wrapper() {
  1302. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1303. }
  1304. Wrapper.prototype = Object.create(Class.prototype, {
  1305. constructor: {
  1306. value: Wrapper,
  1307. enumerable: false,
  1308. writable: true,
  1309. configurable: true
  1310. }
  1311. });
  1312. return _setPrototypeOf(Wrapper, Class);
  1313. };
  1314. return _wrapNativeSuper(Class);
  1315. }
  1316. function _createSuper$i(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$i(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1317. function _isNativeReflectConstruct$i() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1318. var XverseError = /*#__PURE__*/function (_Error) {
  1319. _inherits(XverseError, _Error);
  1320. var _super = _createSuper$i(XverseError);
  1321. function XverseError(e, t) {
  1322. var _this;
  1323. _classCallCheck(this, XverseError);
  1324. _this = _super.call(this, t);
  1325. _this.code = e;
  1326. return _this;
  1327. }
  1328. _createClass(XverseError, [{
  1329. key: "toJSON",
  1330. value: function toJSON() {
  1331. return {
  1332. code: this.code,
  1333. message: this.message
  1334. };
  1335. }
  1336. }, {
  1337. key: "toString",
  1338. value: function toString() {
  1339. if (Object(this) !== this) throw new TypeError();
  1340. var t = this.name;
  1341. t = t === void 0 ? "Error" : String(t);
  1342. var r = this.message;
  1343. r = r === void 0 ? "" : String(r);
  1344. var n = this.code;
  1345. return r = n === void 0 ? r : n + "," + r, t === "" ? r : r === "" ? t : t + ": " + r;
  1346. }
  1347. }]);
  1348. return XverseError;
  1349. }( /*#__PURE__*/_wrapNativeSuper(Error));
  1350. function _createSuper$h(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$h(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1351. function _isNativeReflectConstruct$h() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1352. var ParamError$1 = /*#__PURE__*/function (_XverseError) {
  1353. _inherits(ParamError, _XverseError);
  1354. var _super = _createSuper$h(ParamError);
  1355. function ParamError(e) {
  1356. _classCallCheck(this, ParamError);
  1357. return _super.call(this, 1001, e || "\u53C2\u6570\u9519\u8BEF");
  1358. }
  1359. return _createClass(ParamError);
  1360. }(XverseError);
  1361. var ModelManager$1 = /*#__PURE__*/function () {
  1362. function ModelManager(e, t) {
  1363. _classCallCheck(this, ModelManager);
  1364. this.avatarModelList = [];
  1365. this.skinList = [];
  1366. this.applicationConfig = null;
  1367. this.config = null;
  1368. this.appId = e, this.releaseId = t;
  1369. }
  1370. _createClass(ModelManager, [{
  1371. key: "findSkinConfig",
  1372. value: function () {
  1373. var _findSkinConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  1374. var t, n;
  1375. return regenerator.wrap(function _callee$(_context) {
  1376. while (1) {
  1377. switch (_context.prev = _context.next) {
  1378. case 0:
  1379. t = null;
  1380. _context.next = 3;
  1381. return this.getSkinsList();
  1382. case 3:
  1383. t = (this.skinList = _context.sent).find(function (n) {
  1384. return n.id === e;
  1385. });
  1386. if (!t) {
  1387. _context.next = 6;
  1388. break;
  1389. }
  1390. return _context.abrupt("return", t);
  1391. case 6:
  1392. n = "skin is invalid: skinId: ".concat(e);
  1393. return _context.abrupt("return", Promise.reject(new ParamError$1(n)));
  1394. case 8:
  1395. case "end":
  1396. return _context.stop();
  1397. }
  1398. }
  1399. }, _callee, this);
  1400. }));
  1401. function findSkinConfig(_x) {
  1402. return _findSkinConfig.apply(this, arguments);
  1403. }
  1404. return findSkinConfig;
  1405. }()
  1406. }, {
  1407. key: "findRoute",
  1408. value: function () {
  1409. var _findRoute = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e, t) {
  1410. var n, o;
  1411. return regenerator.wrap(function _callee2$(_context2) {
  1412. while (1) {
  1413. switch (_context2.prev = _context2.next) {
  1414. case 0:
  1415. _context2.next = 2;
  1416. return this.findSkinConfig(e);
  1417. case 2:
  1418. n = _context2.sent.routeList.find(function (o) {
  1419. return o.pathName === t;
  1420. });
  1421. if (n) {
  1422. _context2.next = 6;
  1423. break;
  1424. }
  1425. o = "find path failed: skinId: ".concat(e, ", pathName: ").concat(t);
  1426. return _context2.abrupt("return", Promise.reject(new ParamError$1(o)));
  1427. case 6:
  1428. return _context2.abrupt("return", (logger.debug("find route success", n), n));
  1429. case 7:
  1430. case "end":
  1431. return _context2.stop();
  1432. }
  1433. }
  1434. }, _callee2, this);
  1435. }));
  1436. function findRoute(_x2, _x3) {
  1437. return _findRoute.apply(this, arguments);
  1438. }
  1439. return findRoute;
  1440. }()
  1441. }, {
  1442. key: "findAssetList",
  1443. value: function () {
  1444. var _findAssetList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  1445. var r, n;
  1446. return regenerator.wrap(function _callee3$(_context3) {
  1447. while (1) {
  1448. switch (_context3.prev = _context3.next) {
  1449. case 0:
  1450. _context3.next = 2;
  1451. return this.findSkinConfig(e);
  1452. case 2:
  1453. r = _context3.sent.assetList;
  1454. if (r) {
  1455. _context3.next = 6;
  1456. break;
  1457. }
  1458. n = "find path failed: skinId: ".concat(e);
  1459. return _context3.abrupt("return", Promise.reject(new ParamError$1(n)));
  1460. case 6:
  1461. return _context3.abrupt("return", (logger.debug("find route success", r), r));
  1462. case 7:
  1463. case "end":
  1464. return _context3.stop();
  1465. }
  1466. }
  1467. }, _callee3, this);
  1468. }));
  1469. function findAssetList(_x4) {
  1470. return _findAssetList.apply(this, arguments);
  1471. }
  1472. return findAssetList;
  1473. }()
  1474. }, {
  1475. key: "findAsset",
  1476. value: function () {
  1477. var _findAsset = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e, t) {
  1478. var r,
  1479. n,
  1480. o,
  1481. a,
  1482. _args4 = arguments;
  1483. return regenerator.wrap(function _callee4$(_context4) {
  1484. while (1) {
  1485. switch (_context4.prev = _context4.next) {
  1486. case 0:
  1487. r = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : "id";
  1488. _context4.next = 3;
  1489. return this.findSkinConfig(e);
  1490. case 3:
  1491. n = _context4.sent;
  1492. if (!Array.isArray(t)) {
  1493. _context4.next = 6;
  1494. break;
  1495. }
  1496. return _context4.abrupt("return", t.map(function (a) {
  1497. return n.models.find(function (s) {
  1498. return s[r] === a;
  1499. });
  1500. }).filter(Boolean));
  1501. case 6:
  1502. o = n.models.find(function (a) {
  1503. return a[r] === t;
  1504. });
  1505. if (o) {
  1506. _context4.next = 10;
  1507. break;
  1508. }
  1509. a = "find asset failed: skinId: ".concat(e, ", keyValue: ").concat(t);
  1510. return _context4.abrupt("return", Promise.reject(new ParamError$1(a)));
  1511. case 10:
  1512. return _context4.abrupt("return", (logger.debug("find asset success", o), o));
  1513. case 11:
  1514. case "end":
  1515. return _context4.stop();
  1516. }
  1517. }
  1518. }, _callee4, this);
  1519. }));
  1520. function findAsset(_x5, _x6) {
  1521. return _findAsset.apply(this, arguments);
  1522. }
  1523. return findAsset;
  1524. }()
  1525. }, {
  1526. key: "findPoint",
  1527. value: function () {
  1528. var _findPoint = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e, t) {
  1529. var n, o;
  1530. return regenerator.wrap(function _callee5$(_context5) {
  1531. while (1) {
  1532. switch (_context5.prev = _context5.next) {
  1533. case 0:
  1534. _context5.next = 2;
  1535. return this.findSkinConfig(e);
  1536. case 2:
  1537. n = _context5.sent.pointList.find(function (o) {
  1538. return o.id === t;
  1539. });
  1540. if (n) {
  1541. _context5.next = 6;
  1542. break;
  1543. }
  1544. o = "find point failed: skinId: ".concat(e, ", id: ").concat(t);
  1545. return _context5.abrupt("return", Promise.reject(new ParamError$1(o)));
  1546. case 6:
  1547. return _context5.abrupt("return", (logger.debug("find point success", n), n));
  1548. case 7:
  1549. case "end":
  1550. return _context5.stop();
  1551. }
  1552. }
  1553. }, _callee5, this);
  1554. }));
  1555. function findPoint(_x7, _x8) {
  1556. return _findPoint.apply(this, arguments);
  1557. }
  1558. return findPoint;
  1559. }()
  1560. }, {
  1561. key: "requestConfig",
  1562. value: function () {
  1563. var _requestConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  1564. var t, r, _ref, n, o;
  1565. return regenerator.wrap(function _callee6$(_context6) {
  1566. while (1) {
  1567. switch (_context6.prev = _context6.next) {
  1568. case 0:
  1569. if (!this.config) {
  1570. _context6.next = 2;
  1571. break;
  1572. }
  1573. return _context6.abrupt("return", this.config);
  1574. case 2:
  1575. // let e = `https://static.xverse.cn/console/config/${this.appId}/config.json`;
  1576. // this.releaseId && (e = `https://static.xverse.cn/console/config/${this.appId}/${this.releaseId}/config.json`);
  1577. // const t = Xverse.USE_TME_CDN ? "https://static.xverse.cn/tmeland/config/tme_config.json" : e;
  1578. t = './assets/config.json';
  1579. _context6.prev = 3;
  1580. _context6.next = 6;
  1581. return http1.get({
  1582. url: "".concat(t, "?t=").concat(Date.now()),
  1583. key: "config",
  1584. timeout: 6e3,
  1585. retry: 2
  1586. });
  1587. case 6:
  1588. r = _context6.sent;
  1589. _ref = r.data.data || {}, n = _ref.config, o = _ref.preload;
  1590. if (n) {
  1591. _context6.next = 10;
  1592. break;
  1593. }
  1594. throw new Error("config data parse error" + r.data);
  1595. case 10:
  1596. return _context6.abrupt("return", (this.config = {
  1597. config: n,
  1598. preload: o
  1599. }, logger.debug("get config success", this.config), this.config));
  1600. case 13:
  1601. _context6.prev = 13;
  1602. _context6.t0 = _context6["catch"](3);
  1603. return _context6.abrupt("return", Promise.reject(_context6.t0));
  1604. case 16:
  1605. case "end":
  1606. return _context6.stop();
  1607. }
  1608. }
  1609. }, _callee6, this, [[3, 13]]);
  1610. }));
  1611. function requestConfig() {
  1612. return _requestConfig.apply(this, arguments);
  1613. }
  1614. return requestConfig;
  1615. }()
  1616. }, {
  1617. key: "getApplicationConfig",
  1618. value: function () {
  1619. var _getApplicationConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7() {
  1620. var e;
  1621. return regenerator.wrap(function _callee7$(_context7) {
  1622. while (1) {
  1623. switch (_context7.prev = _context7.next) {
  1624. case 0:
  1625. if (!this.applicationConfig) {
  1626. _context7.next = 2;
  1627. break;
  1628. }
  1629. return _context7.abrupt("return", this.applicationConfig);
  1630. case 2:
  1631. _context7.prev = 2;
  1632. _context7.next = 5;
  1633. return this.requestConfig();
  1634. case 5:
  1635. e = _context7.sent;
  1636. return _context7.abrupt("return", (this.applicationConfig = e.config, this.applicationConfig));
  1637. case 9:
  1638. _context7.prev = 9;
  1639. _context7.t0 = _context7["catch"](2);
  1640. return _context7.abrupt("return", Promise.reject(_context7.t0));
  1641. case 12:
  1642. case "end":
  1643. return _context7.stop();
  1644. }
  1645. }
  1646. }, _callee7, this, [[2, 9]]);
  1647. }));
  1648. function getApplicationConfig() {
  1649. return _getApplicationConfig.apply(this, arguments);
  1650. }
  1651. return getApplicationConfig;
  1652. }()
  1653. }, {
  1654. key: "getAvatarModelList",
  1655. value: function () {
  1656. var _getAvatarModelList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  1657. var _yield$this$getApplic, e;
  1658. return regenerator.wrap(function _callee8$(_context8) {
  1659. while (1) {
  1660. switch (_context8.prev = _context8.next) {
  1661. case 0:
  1662. if (!this.avatarModelList.length) {
  1663. _context8.next = 2;
  1664. break;
  1665. }
  1666. return _context8.abrupt("return", this.avatarModelList);
  1667. case 2:
  1668. _context8.prev = 2;
  1669. _context8.next = 5;
  1670. return this.getApplicationConfig();
  1671. case 5:
  1672. _yield$this$getApplic = _context8.sent;
  1673. e = _yield$this$getApplic.avatars;
  1674. return _context8.abrupt("return", (this.avatarModelList = e.map(function (t) {
  1675. return {
  1676. name: t.name,
  1677. id: t.id,
  1678. modelUrl: t.url,
  1679. gender: t.gender,
  1680. components: t.components
  1681. };
  1682. }), this.avatarModelList));
  1683. case 10:
  1684. _context8.prev = 10;
  1685. _context8.t0 = _context8["catch"](2);
  1686. return _context8.abrupt("return", (logger.error(_context8.t0), []));
  1687. case 13:
  1688. case "end":
  1689. return _context8.stop();
  1690. }
  1691. }
  1692. }, _callee8, this, [[2, 10]]);
  1693. }));
  1694. function getAvatarModelList() {
  1695. return _getAvatarModelList.apply(this, arguments);
  1696. }
  1697. return getAvatarModelList;
  1698. }()
  1699. }, {
  1700. key: "getSkinsList",
  1701. value: function () {
  1702. var _getSkinsList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9() {
  1703. var _yield$this$getApplic2, e;
  1704. return regenerator.wrap(function _callee9$(_context9) {
  1705. while (1) {
  1706. switch (_context9.prev = _context9.next) {
  1707. case 0:
  1708. if (!this.skinList.length) {
  1709. _context9.next = 2;
  1710. break;
  1711. }
  1712. return _context9.abrupt("return", this.skinList);
  1713. case 2:
  1714. _context9.prev = 2;
  1715. _context9.next = 5;
  1716. return this.getApplicationConfig();
  1717. case 5:
  1718. _yield$this$getApplic2 = _context9.sent;
  1719. e = _yield$this$getApplic2.skins;
  1720. return _context9.abrupt("return", (this.skinList = e.map(function (t) {
  1721. var r;
  1722. return {
  1723. name: t.name,
  1724. dataVersion: t.id + t.versionId,
  1725. id: t.id,
  1726. fov: parseInt(t.fov || 90),
  1727. models: t.assetList.map(function (n) {
  1728. var o = n.assetId,
  1729. a = n.url,
  1730. s = n.thumbnailUrl,
  1731. l = n.typeName,
  1732. u = n.className;
  1733. return {
  1734. id: o,
  1735. modelUrl: a,
  1736. name: n.name,
  1737. thumbnailUrl: s,
  1738. typeName: l,
  1739. className: u === "\u4F4E\u6A21" ? "\u7C97\u6A21" : u
  1740. };
  1741. }),
  1742. routeList: (r = t.routeList) == null ? void 0 : r.map(function (n) {
  1743. var o = n.areaName,
  1744. a = n.attitude,
  1745. s = n.id,
  1746. l = n.pathName,
  1747. u = n.step,
  1748. c = n.birthPointList;
  1749. return {
  1750. areaName: o,
  1751. attitude: a,
  1752. id: s,
  1753. pathName: l,
  1754. step: u,
  1755. birthPointList: c.map(function (h) {
  1756. return {
  1757. camera: h.camera && {
  1758. position: objectParseFloat(h.camera.position),
  1759. angle: objectParseFloat(h.camera.rotation)
  1760. },
  1761. player: h.player && {
  1762. position: objectParseFloat(h.player.position),
  1763. angle: objectParseFloat(h.player.rotation)
  1764. }
  1765. };
  1766. })
  1767. };
  1768. }),
  1769. pointList: t.pointList.map(function (n) {
  1770. return le(oe({}, n), {
  1771. position: objectParseFloat(n.position),
  1772. rotation: objectParseFloat(n.rotation)
  1773. });
  1774. }),
  1775. versionId: t.versionId,
  1776. isEnable: t.isEnable,
  1777. assetList: t.assetList,
  1778. visibleRules: t.visibleRules,
  1779. animationList: t.animationList
  1780. };
  1781. }), this.skinList));
  1782. case 10:
  1783. _context9.prev = 10;
  1784. _context9.t0 = _context9["catch"](2);
  1785. return _context9.abrupt("return", (logger.error(_context9.t0), []));
  1786. case 13:
  1787. case "end":
  1788. return _context9.stop();
  1789. }
  1790. }
  1791. }, _callee9, this, [[2, 10]]);
  1792. }));
  1793. function getSkinsList() {
  1794. return _getSkinsList.apply(this, arguments);
  1795. }
  1796. return getSkinsList;
  1797. }()
  1798. }, {
  1799. key: "getBreathPointTextrueList",
  1800. value: function () {
  1801. var _getBreathPointTextrueList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10() {
  1802. return regenerator.wrap(function _callee10$(_context10) {
  1803. while (1) {
  1804. switch (_context10.prev = _context10.next) {
  1805. case 0:
  1806. return _context10.abrupt("return", [{
  1807. url: TEXTURE_URL
  1808. }]);
  1809. case 1:
  1810. case "end":
  1811. return _context10.stop();
  1812. }
  1813. }
  1814. }, _callee10);
  1815. }));
  1816. function getBreathPointTextrueList() {
  1817. return _getBreathPointTextrueList.apply(this, arguments);
  1818. }
  1819. return getBreathPointTextrueList;
  1820. }()
  1821. }], [{
  1822. key: "getInstance",
  1823. value: function getInstance(e, t) {
  1824. //getInstance(e, t) {
  1825. return this.instance || (this.instance = new ModelManager(e, t)), this.instance;
  1826. }
  1827. }, {
  1828. key: "findModels",
  1829. value: function findModels(e, t, r) {
  1830. //findModels(e, t, r) {
  1831. return e.filter(function (o) {
  1832. return o.typeName === t && o.className === r;
  1833. });
  1834. }
  1835. }, {
  1836. key: "findModel",
  1837. value: function findModel(e, t, r) {
  1838. //findModel(e, t, r) {
  1839. var n = e.filter(function (o) {
  1840. return o.typeName === t && o.className === r;
  1841. })[0];
  1842. return n || null;
  1843. }
  1844. }]);
  1845. return ModelManager;
  1846. }();
  1847. // export { modelManager };
  1848. var JoyStick = /*#__PURE__*/function () {
  1849. function JoyStick(e) {
  1850. _classCallCheck(this, JoyStick);
  1851. this._zone = document.createElement("div");
  1852. this._joystick = null;
  1853. this._room = e;
  1854. }
  1855. _createClass(JoyStick, [{
  1856. key: "init",
  1857. value: function init(e) {
  1858. var _this = this;
  1859. var _e$interval = e.interval,
  1860. t = _e$interval === void 0 ? 33 : _e$interval,
  1861. _e$triggerDistance = e.triggerDistance,
  1862. r = _e$triggerDistance === void 0 ? 25 : _e$triggerDistance,
  1863. _e$style = e.style,
  1864. n = _e$style === void 0 ? {
  1865. left: 0,
  1866. bottom: 0
  1867. } : _e$style,
  1868. o = function o(u, c) {
  1869. _this._room.actionsHandler.joystick({
  1870. degree: Math.floor(u),
  1871. level: Math.floor(c / 5)
  1872. });
  1873. },
  1874. a = this._zone;
  1875. document.body.appendChild(a), a.style.position = "absolute", a.style.width = "200px", a.style.height = "200px", a.style.left = String(n.left), a.style.bottom = String(n.bottom), a.style.zIndex = "999", a.style.userSelect = "none", a.style.webkitUserSelect = "none", this._joystick = nipplejs.create({
  1876. zone: a,
  1877. mode: "static",
  1878. position: {
  1879. left: "50%",
  1880. top: "50%"
  1881. },
  1882. color: "white"
  1883. });
  1884. var s, l;
  1885. return this._joystick.on("move", function (u, c) {
  1886. s = c;
  1887. }), this._joystick.on("start", function () {
  1888. l = window.setInterval(function () {
  1889. s && s.distance > r && o && o(s.angle.degree, s.distance);
  1890. }, t);
  1891. }), this._joystick.on("end", function () {
  1892. l && window.clearInterval(l), l = void 0;
  1893. }), this._joystick;
  1894. }
  1895. }, {
  1896. key: "show",
  1897. value: function show() {
  1898. if (!this._joystick) throw new Error("joystick is not created");
  1899. this._zone.style.display = "block";
  1900. }
  1901. }, {
  1902. key: "hide",
  1903. value: function hide() {
  1904. if (!this._joystick) throw new Error("joystick is not created");
  1905. this._zone.style.display = "none";
  1906. }
  1907. }]);
  1908. return JoyStick;
  1909. }();
  1910. var CoreBroadcastType = {
  1911. PlayAnimation: 'PlayAnimation'
  1912. };
  1913. var AvatarGroup = {
  1914. Npc: 'npc',
  1915. User: 'user'
  1916. };
  1917. var MessageHandleType$1 = {
  1918. MHT_Undefined: 0,
  1919. MHT_RoomMulticast: 1,
  1920. MHT_FollowListMulticast: 2,
  1921. MHT_CustomTargetSync: 3
  1922. };
  1923. var Broadcast$1 = /*#__PURE__*/function () {
  1924. function Broadcast(e, t) {
  1925. _classCallCheck(this, Broadcast);
  1926. this.room = e;
  1927. this.handlers = [];
  1928. this.init(t);
  1929. }
  1930. _createClass(Broadcast, [{
  1931. key: "init",
  1932. value: function init(t) {
  1933. this.handlers.push(t);
  1934. }
  1935. }, {
  1936. key: "handleBroadcast",
  1937. value: function () {
  1938. var _handleBroadcast = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  1939. return regenerator.wrap(function _callee$(_context) {
  1940. while (1) {
  1941. switch (_context.prev = _context.next) {
  1942. case 0:
  1943. _context.prev = 1;
  1944. JSON.parse(e.broadcastAction.data);
  1945. _context.next = 9;
  1946. break;
  1947. case 5:
  1948. _context.prev = 5;
  1949. _context.t0 = _context["catch"](1);
  1950. logger.error(_context.t0);
  1951. return _context.abrupt("return");
  1952. case 9:
  1953. case "end":
  1954. return _context.stop();
  1955. }
  1956. }
  1957. }, _callee, null, [[1, 5]]);
  1958. }));
  1959. function handleBroadcast(_x) {
  1960. return _handleBroadcast.apply(this, arguments);
  1961. }
  1962. return handleBroadcast;
  1963. }()
  1964. }, {
  1965. key: "broadcast",
  1966. value: function broadcast(e) {
  1967. var t = e.data,
  1968. _e$msgType = e.msgType,
  1969. r = _e$msgType === void 0 ? MessageHandleType$1.MHT_FollowListMulticast : _e$msgType,
  1970. n = e.targetUserIds;
  1971. return this.room.actionsHandler.broadcast({
  1972. data: t,
  1973. msgType: r,
  1974. targetUserIds: n
  1975. });
  1976. }
  1977. }]);
  1978. return Broadcast;
  1979. }();
  1980. function _createSuper$g(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$g(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1981. function _isNativeReflectConstruct$g() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1982. var TimeoutError = /*#__PURE__*/function (_XverseError) {
  1983. _inherits(TimeoutError, _XverseError);
  1984. var _super = _createSuper$g(TimeoutError);
  1985. function TimeoutError(e) {
  1986. _classCallCheck(this, TimeoutError);
  1987. return _super.call(this, 1003, e || "\u8D85\u65F6");
  1988. }
  1989. return _createClass(TimeoutError);
  1990. }(XverseError);
  1991. function _createSuper$f(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$f(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1992. function _isNativeReflectConstruct$f() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1993. var XverseAvatarManager = /*#__PURE__*/function (_EventEmitter) {
  1994. _inherits(XverseAvatarManager, _EventEmitter);
  1995. var _super = _createSuper$f(XverseAvatarManager);
  1996. function XverseAvatarManager(e) {
  1997. var _this;
  1998. _classCallCheck(this, XverseAvatarManager);
  1999. _this = _super.call(this);
  2000. _this.xAvatarManager = null;
  2001. _this.avatars = new Map();
  2002. _this.syncAvatarsLength = 0;
  2003. _this._room = e;
  2004. _this._usersStatistics();
  2005. _this.broadcast = _this.setupBroadcast();
  2006. e.on("skinChanged", function () {
  2007. _this.avatars.forEach(function (t) {
  2008. t.disconnected && _this.removeAvatar(t.userId, !0);
  2009. });
  2010. });
  2011. return _this;
  2012. }
  2013. _createClass(XverseAvatarManager, [{
  2014. key: "setupBroadcast",
  2015. value: function setupBroadcast() {
  2016. var _this2 = this;
  2017. return new Broadcast$1(this._room, /*#__PURE__*/function () {
  2018. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  2019. var t, r, n, o, a, _r$loop, s, l;
  2020. return regenerator.wrap(function _callee$(_context) {
  2021. while (1) {
  2022. switch (_context.prev = _context.next) {
  2023. case 0:
  2024. t = e.broadcastType, r = e.info;
  2025. if (!(t !== CoreBroadcastType.PlayAnimation)) {
  2026. _context.next = 3;
  2027. break;
  2028. }
  2029. return _context.abrupt("return");
  2030. case 3:
  2031. n = r.userId, o = r.animation, a = r.extra, _r$loop = r.loop, s = _r$loop === void 0 ? !1 : _r$loop, l = _this2.avatars.get(n);
  2032. _context.t0 = l && !l.isSelf;
  2033. if (!_context.t0) {
  2034. _context.next = 10;
  2035. break;
  2036. }
  2037. l.emit("animationStart", {
  2038. animationName: o,
  2039. extra: decodeURIComponent(a)
  2040. });
  2041. _context.next = 9;
  2042. return l == null ? void 0 : l._playAnimation(o, s);
  2043. case 9:
  2044. l.emit("animationEnd", {
  2045. animationName: o,
  2046. extra: decodeURIComponent(a)
  2047. });
  2048. case 10:
  2049. case "end":
  2050. return _context.stop();
  2051. }
  2052. }
  2053. }, _callee);
  2054. }));
  2055. return function (_x) {
  2056. return _ref.apply(this, arguments);
  2057. };
  2058. }());
  2059. }
  2060. }, {
  2061. key: "hideAll",
  2062. value: function hideAll() {
  2063. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2064. this.xAvatarManager.hideAll(e);
  2065. }
  2066. }, {
  2067. key: "showAll",
  2068. value: function showAll() {
  2069. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2070. this.xAvatarManager.showAll(e);
  2071. }
  2072. }, {
  2073. key: "init",
  2074. value: function () {
  2075. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  2076. var e, t;
  2077. return regenerator.wrap(function _callee2$(_context2) {
  2078. while (1) {
  2079. switch (_context2.prev = _context2.next) {
  2080. case 0:
  2081. this.xAvatarManager = this._room.sceneManager.avatarComponent;
  2082. _context2.prev = 1;
  2083. _context2.next = 4;
  2084. return this._room.modelManager.getApplicationConfig();
  2085. case 4:
  2086. e = _context2.sent;
  2087. t = e.avatars;
  2088. if (!t) {
  2089. _context2.next = 10;
  2090. break;
  2091. }
  2092. _context2.next = 9;
  2093. return avatarLoader.parse(this._room.sceneManager, t);
  2094. case 9:
  2095. return _context2.abrupt("return");
  2096. case 10:
  2097. return _context2.abrupt("return", Promise.reject("cannot find avatar config list"));
  2098. case 13:
  2099. _context2.prev = 13;
  2100. _context2.t0 = _context2["catch"](1);
  2101. return _context2.abrupt("return", (logger.error(_context2.t0), Promise.reject("avatar mananger init error!")));
  2102. case 16:
  2103. case "end":
  2104. return _context2.stop();
  2105. }
  2106. }
  2107. }, _callee2, this, [[1, 13]]);
  2108. }));
  2109. function init() {
  2110. return _init.apply(this, arguments);
  2111. }
  2112. return init;
  2113. }()
  2114. }, {
  2115. key: "handleAvatar",
  2116. value: function () {
  2117. var _handleAvatar2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  2118. var _this3 = this;
  2119. var r, t, n, o, _n, a;
  2120. return regenerator.wrap(function _callee3$(_context3) {
  2121. while (1) {
  2122. switch (_context3.prev = _context3.next) {
  2123. case 0:
  2124. if (!(this._room.viewMode === "simple" || !this._room.joined || !e.newUserStates)) {
  2125. _context3.next = 2;
  2126. break;
  2127. }
  2128. return _context3.abrupt("return");
  2129. case 2:
  2130. t = e.newUserStates;
  2131. if (((r = this._room._userAvatar) == null ? void 0 : r.isMoving) && this._room._userAvatar.motionType === MotionType.Run) {
  2132. n = t.filter(function (a) {
  2133. return a.userId === _this3._room.userId;
  2134. }), o = t.filter(function (a) {
  2135. return a.userId !== _this3._room.userId;
  2136. }).slice(0, 2);
  2137. t = n.concat(o);
  2138. }
  2139. if (e.getStateType === GetStateTypes.Event) {
  2140. this.syncAvatarsLength = (t || []).length;
  2141. _n = this._room.avatars.filter(function (s) {
  2142. return s.group == AvatarGroup.User;
  2143. });
  2144. _n.filter(function (s) {
  2145. return !(t != null && t.find(function (l) {
  2146. return l.userId == s.userId;
  2147. }));
  2148. }).forEach(function (s) {
  2149. _this3.removeAvatar(s.userId);
  2150. });
  2151. a = t.filter(function (s) {
  2152. return !_n.find(function (l) {
  2153. return l.userId == s.userId;
  2154. });
  2155. });
  2156. this._handleAvatar(a);
  2157. }
  2158. this._handleAvatar(t);
  2159. case 6:
  2160. case "end":
  2161. return _context3.stop();
  2162. }
  2163. }
  2164. }, _callee3, this);
  2165. }));
  2166. function handleAvatar(_x2) {
  2167. return _handleAvatar2.apply(this, arguments);
  2168. }
  2169. return handleAvatar;
  2170. }()
  2171. }, {
  2172. key: "_handleAvatar",
  2173. value: function () {
  2174. var _handleAvatar3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  2175. var _this4 = this;
  2176. return regenerator.wrap(function _callee4$(_context4) {
  2177. while (1) {
  2178. switch (_context4.prev = _context4.next) {
  2179. case 0:
  2180. e == null || e.forEach(function (t) {
  2181. var n, o, a, s, l, u, c, h, f;
  2182. var r = _this4._room.userId === t.userId;
  2183. if (((n = t.event) == null ? void 0 : n.type) === SyncEventType.ET_RemoveVisitor) {
  2184. var d = (a = (o = t.event) == null ? void 0 : o.removeVisitorEvent) == null ? void 0 : a.removeVisitorEvent,
  2185. _ = JSON.parse(safeDecodeURIComponent(((l = (s = t.event) == null ? void 0 : s.removeVisitorEvent) == null ? void 0 : l.extraInfo) || "")),
  2186. g = _.code,
  2187. m = _.msg;
  2188. d === RemoveVisitorType.RVT_ChangeToObserver ? _this4._room.audienceViewModeHook() : d === RemoveVisitorType.RVT_MoveOutOfTheRoom && _this4._room.leave(), _this4._room.emit("visitorStatusChanged", {
  2189. code: g,
  2190. msg: m
  2191. });
  2192. }
  2193. if (t.event && [SyncEventType.Appear, SyncEventType.Reset].includes(t.event.type) || !t.event) {
  2194. var _d = _this4.avatars.get(t.userId);
  2195. if (t.playerState.avatarId && (_d == null ? void 0 : _d.avatarId) !== t.playerState.avatarId && (_d = void 0, _this4.removeAvatar(t.userId)), _d) {
  2196. if (_d.disconnected && _d.setConnectionStatus(!1), (u = t.event) != null && u.id && _this4._room.actionsHandler.confirmEvent(t.event.id), t.playerState.nickName && (_d == null || _d._setNickname(t.playerState.nickName)), t.playerState.avatarComponents && !_d.isSelf && _d.xAvatar) {
  2197. var _2 = safeParseComponents(t.playerState.avatarComponents);
  2198. _d._changeComponents({
  2199. avatarComponents: _2,
  2200. mode: ChangeComponentsMode.Preview
  2201. });
  2202. }
  2203. } else {
  2204. var _t$playerState$player = t.playerState.player,
  2205. _3 = _t$playerState$player.position,
  2206. _g = _t$playerState$player.angle,
  2207. _m = t.playerState.avatarId,
  2208. v = t.playerState.prioritySync,
  2209. y = safelyJsonParse(t.playerState.extra);
  2210. if (!_m) return;
  2211. var b = safeParseComponents(t.playerState.avatarComponents),
  2212. T = safeDecodeURIComponent(t.playerState.nickName),
  2213. C = _this4.calculatePriority(t.userId, y);
  2214. _this4.addAvatar({
  2215. userId: t.userId,
  2216. isHost: t.playerState.isHost,
  2217. nickname: T,
  2218. avatarPosition: _3,
  2219. avatarRotation: _g,
  2220. avatarScale: t.playerState.avatarSize,
  2221. avatarId: _m,
  2222. avatarComponents: t.playerState.person === Person.First ? [] : b,
  2223. priority: C,
  2224. group: AvatarGroup.User,
  2225. prioritySync: v,
  2226. extraInfo: y
  2227. }).then(function () {
  2228. var A;
  2229. (A = t.event) != null && A.id && _this4._room.actionsHandler.confirmEvent(t.event.id), _this4.updateAvatarPositionAndRotation(t), r && (_this4.xAvatarManager.setMainAvatar(t.userId), _this4._room.emit("userAvatarLoaded"), logger.info("userAvatarLoaded"));
  2230. }).catch(function (A) {
  2231. r && (_this4.xAvatarManager.setMainAvatar(t.userId), _this4._room.emit("userAvatarFailed", {
  2232. error: A
  2233. }), logger.error("userAvatarFailed", A));
  2234. });
  2235. }
  2236. }
  2237. if (t.event && SyncEventType.Disappear === t.event.type && ((c = t == null ? void 0 : t.event) != null && c.id && _this4._room.actionsHandler.confirmEvent(t.event.id), _this4.removeAvatar(t.userId)), t.event && [SyncEventType.Move, SyncEventType.ChangeRenderInfo].includes(t.event.type) || !t.event) {
  2238. (h = t == null ? void 0 : t.event) != null && h.id && _this4._room.actionsHandler.confirmEvent(t.event.id);
  2239. var _d2 = _this4.avatars.get(t.userId);
  2240. _d2 && _d2.withModel && !_d2.isLoading && _this4.updateAvatarPositionAndRotation(t);
  2241. }
  2242. if (!r && ((f = t.event) == null ? void 0 : f.type) === SyncEventType.Rotate) {
  2243. var _d3 = _this4.avatars.get(t.userId);
  2244. _d3.statusSyncQueue.append({
  2245. type: QueueType.Rotate,
  2246. action: function action() {
  2247. return _d3.statusSync(t);
  2248. }
  2249. });
  2250. }
  2251. });
  2252. case 1:
  2253. case "end":
  2254. return _context4.stop();
  2255. }
  2256. }
  2257. }, _callee4);
  2258. }));
  2259. function _handleAvatar(_x3) {
  2260. return _handleAvatar3.apply(this, arguments);
  2261. }
  2262. return _handleAvatar;
  2263. }()
  2264. }, {
  2265. key: "calculatePriority",
  2266. value: function calculatePriority(e, t) {
  2267. var n;
  2268. return e === this._room.userId ? EAvatarRelationRank.Self : (n = this._room.options.firends) != null && n.includes(e) ? EAvatarRelationRank.Friend : EAvatarRelationRank.Stranger;
  2269. }
  2270. }, {
  2271. key: "updateAvatarPositionAndRotation",
  2272. value: function updateAvatarPositionAndRotation(e) {
  2273. var t, r;
  2274. if ((t = e == null ? void 0 : e.playerState) != null && t.player) {
  2275. var _e$playerState$player = e.playerState.player,
  2276. n = _e$playerState$player.position,
  2277. o = _e$playerState$player.angle;
  2278. var a = this.avatars.get(e.userId);
  2279. if (!a) return;
  2280. if (n = positionPrecisionProtect(n), o = rotationPrecisionProtect(o), a.isSelf && !this._room.networkController.rtcp.workers.inPanoMode && (a.setPosition(n), a.setRotation(o)), e.event && (((r = e.event) == null ? void 0 : r.points.length) || 0) > 1 && !a.isSelf && a.statusSyncQueue.append({
  2281. type: QueueType.Move,
  2282. action: function action() {
  2283. return a.statusSync(e);
  2284. }
  2285. }), e.renderInfo && a.isSelf) {
  2286. var _e$renderInfo = e.renderInfo,
  2287. s = _e$renderInfo.isMoving,
  2288. l = _e$renderInfo.isRotating;
  2289. this._updateAvatarMovingStatus({
  2290. id: e.userId,
  2291. isMoving: !!s,
  2292. isRotating: !!l
  2293. });
  2294. }
  2295. }
  2296. }
  2297. }, {
  2298. key: "addAvatar",
  2299. value: function () {
  2300. var _addAvatar = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e) {
  2301. var t, r, n, o, a, s, _e$avatarComponents, l, u, _e$group, c, _e$avatarScale, h, f, d, _, g, v, y, b, T, C;
  2302. return regenerator.wrap(function _callee5$(_context5) {
  2303. while (1) {
  2304. switch (_context5.prev = _context5.next) {
  2305. case 0:
  2306. t = e.userId, r = e.isHost, n = e.avatarPosition, o = e.avatarId, a = e.avatarRotation, s = e.nickname, _e$avatarComponents = e.avatarComponents, l = _e$avatarComponents === void 0 ? [] : _e$avatarComponents, u = e.priority, _e$group = e.group, c = _e$group === void 0 ? AvatarGroup.Npc : _e$group, _e$avatarScale = e.avatarScale, h = _e$avatarScale === void 0 ? DEFAULT_AVATAR_SCALE : _e$avatarScale, f = e.extraInfo, d = e.prioritySync, _ = t === this._room.userId;
  2307. g = this.avatars.get(t);
  2308. if (!g) {
  2309. _context5.next = 4;
  2310. break;
  2311. }
  2312. return _context5.abrupt("return", Promise.resolve(g));
  2313. case 4:
  2314. if (!(g = new xe.subAvatar({
  2315. userId: t,
  2316. isHost: r,
  2317. isSelf: _,
  2318. room: this._room,
  2319. avatarComponents: l,
  2320. avatarId: o,
  2321. nickname: s,
  2322. group: c
  2323. }), this.avatars.set(t, g), !g.withModel)) {
  2324. _context5.next = 6;
  2325. break;
  2326. }
  2327. return _context5.abrupt("return", (g.isLoading = !1, g.avatarLoadedHook(), this._room.emit("avatarChanged", {
  2328. avatars: this._room.avatars
  2329. }), g));
  2330. case 6:
  2331. _context5.next = 8;
  2332. return this._room.modelManager.getAvatarModelList();
  2333. case 8:
  2334. v = _context5.sent.find(function (b) {
  2335. return b.id === o;
  2336. });
  2337. y = Date.now();
  2338. if (v) {
  2339. _context5.next = 12;
  2340. break;
  2341. }
  2342. return _context5.abrupt("return", (this._room.emit("avatarChanged", {
  2343. avatars: this._room.avatars
  2344. }), this.avatars.delete(t), Promise.reject("no such avatar model with id: ".concat(o))));
  2345. case 12:
  2346. _context5.prev = 12;
  2347. _context5.next = 15;
  2348. return avatarComponentsModify(v, l);
  2349. case 15:
  2350. b = _context5.sent;
  2351. b = b.filter(function (A) {
  2352. return A.type != "pendant";
  2353. });
  2354. _context5.next = 19;
  2355. return avatarComponentsParser(v, b);
  2356. case 19:
  2357. T = _context5.sent;
  2358. _context5.next = 22;
  2359. return this.xAvatarManager.loadAvatar({
  2360. id: t,
  2361. avatarType: o,
  2362. priority: u,
  2363. avatarManager: this.xAvatarManager,
  2364. assets: T,
  2365. status: {
  2366. avatarPosition: n,
  2367. avatarRotation: a,
  2368. avatarScale: h
  2369. }
  2370. })._timeout(8e3, new TimeoutError$1("loadAvatar timeout(8s)"));
  2371. case 22:
  2372. C = _context5.sent;
  2373. return _context5.abrupt("return", (C.setPickBoxScale(t === this._room.userId ? 0 : 1), g.xAvatar = C, g.setScale(h), g.extraInfo = f, g.priority = u, g.isLoading = !1, g.prioritySync = !!d, g._playAnimation("Idle", !0, !0), g.avatarLoadedHook(), this._room.emit("avatarChanged", {
  2374. avatars: this._room.avatars
  2375. }), s && g._setNickname(s), t === this._room.userId && (logger.infoAndReportMeasurement({
  2376. metric: "avatarLoadDuration",
  2377. startTime: y,
  2378. group: "costs"
  2379. }), logger.infoAndReportMeasurement({
  2380. metric: "avatarLoadAt",
  2381. startTime: this._room._startTime,
  2382. group: "costs"
  2383. })), g));
  2384. case 26:
  2385. _context5.prev = 26;
  2386. _context5.t0 = _context5["catch"](12);
  2387. return _context5.abrupt("return", (g.isLoading = !1, this._room.emit("avatarChanged", {
  2388. avatars: this._room.avatars
  2389. }), logger.error(_context5.t0), Promise.reject(_context5.t0)));
  2390. case 29:
  2391. case "end":
  2392. return _context5.stop();
  2393. }
  2394. }
  2395. }, _callee5, this, [[12, 26]]);
  2396. }));
  2397. function addAvatar(_x4) {
  2398. return _addAvatar.apply(this, arguments);
  2399. }
  2400. return addAvatar;
  2401. }()
  2402. }, {
  2403. key: "removeAvatar",
  2404. value: function removeAvatar(e) {
  2405. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
  2406. var r = this.avatars.get(e);
  2407. if (!!r) {
  2408. if (r.removeWhenDisconnected || t) {
  2409. r.xAvatar && this.xAvatarManager.deleteAvatar(r.xAvatar), this.avatars.delete(e), this._room.emit("avatarChanged", {
  2410. avatars: this._room.avatars
  2411. });
  2412. return;
  2413. }
  2414. r.setConnectionStatus(!0);
  2415. }
  2416. }
  2417. }, {
  2418. key: "clearOtherUsers",
  2419. value: function clearOtherUsers() {
  2420. var _this5 = this;
  2421. this.avatars.forEach(function (e) {
  2422. !e.isSelf && e.group === AvatarGroup.User && _this5.removeAvatar(e.userId);
  2423. });
  2424. }
  2425. }, {
  2426. key: "_updateAvatarMovingStatus",
  2427. value: function () {
  2428. var _updateAvatarMovingStatus2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  2429. var t, r, n, o, a, _a;
  2430. return regenerator.wrap(function _callee6$(_context6) {
  2431. while (1) {
  2432. switch (_context6.prev = _context6.next) {
  2433. case 0:
  2434. t = e.id, r = e.isMoving, n = e.isRotating, o = this.avatars.get(t);
  2435. if (!!o) {
  2436. if (o.isRotating !== n) {
  2437. o.isRotating = n;
  2438. a = "Idle";
  2439. n && (a = "Walking", o.motionType === MotionType.Run && (a = "Running")), o._playAnimation(a, !0, !0), logger.infoAndReportMeasurement({
  2440. startTime: Date.now(),
  2441. value: 0,
  2442. metric: n ? "userAvatarStartRotating" : "userAvatarStopRotating",
  2443. extra: {
  2444. motionType: o.motionType,
  2445. moveToExtra: this._room.moveToExtra
  2446. }
  2447. });
  2448. }
  2449. if (o.isMoving !== r) {
  2450. o.isMoving = r;
  2451. _a = "Idle";
  2452. r && (_a = "Walking", o.motionType === MotionType.Run && (_a = "Running")), r ? (o.avatarStartMovingHook(), o.emit("startMoving", {
  2453. target: o,
  2454. extra: this._room.moveToExtra
  2455. })) : (o.avatarStopMovingHook(), o.emit("stopMoving", {
  2456. target: o,
  2457. extra: this._room.moveToExtra
  2458. })), o._playAnimation(_a, !0, !0), logger.infoAndReportMeasurement({
  2459. startTime: Date.now(),
  2460. value: 0,
  2461. metric: r ? "userAvatarStartMoving" : "userAvatarStopMoving",
  2462. extra: {
  2463. motionType: o.motionType,
  2464. moveToExtra: this._room.moveToExtra
  2465. }
  2466. });
  2467. }
  2468. }
  2469. case 2:
  2470. case "end":
  2471. return _context6.stop();
  2472. }
  2473. }
  2474. }, _callee6, this);
  2475. }));
  2476. function _updateAvatarMovingStatus(_x5) {
  2477. return _updateAvatarMovingStatus2.apply(this, arguments);
  2478. }
  2479. return _updateAvatarMovingStatus;
  2480. }()
  2481. }, {
  2482. key: "_usersStatistics",
  2483. value: function _usersStatistics() {
  2484. var _this6 = this;
  2485. this.on("userAvatarLoaded", function () {
  2486. window.setInterval(function () {
  2487. var e = _this6._room.avatars.filter(function (r) {
  2488. return r.group === AvatarGroup.User;
  2489. }).length || 0,
  2490. t = _this6._room.avatars.filter(function (r) {
  2491. return r.group === AvatarGroup.User && r.isRender;
  2492. }).length || 0;
  2493. _this6._room.stats.assign({
  2494. userNum: e,
  2495. syncUserNum: _this6.syncAvatarsLength,
  2496. renderedUserNum: t
  2497. });
  2498. }, 3e3);
  2499. });
  2500. }
  2501. }]);
  2502. return XverseAvatarManager;
  2503. }(EventEmitter);
  2504. var PathManager = /*#__PURE__*/function () {
  2505. function PathManager() {
  2506. _classCallCheck(this, PathManager);
  2507. this.currentArea = '';
  2508. this.currentPathName = '';
  2509. this.currentAttitude = '';
  2510. this.speed = 0;
  2511. }
  2512. _createClass(PathManager, [{
  2513. key: "getSpeed",
  2514. value: function getSpeed(e) {
  2515. var t = {
  2516. guangchang: {
  2517. [MotionType.Walk]: 17,
  2518. [MotionType.Run]: 51
  2519. },
  2520. tower: {
  2521. [MotionType.Walk]: 12.5,
  2522. [MotionType.Run]: 25
  2523. },
  2524. zhiboting: {
  2525. [MotionType.Walk]: 12.5,
  2526. [MotionType.Run]: 25
  2527. },
  2528. youxiting: {
  2529. [MotionType.Walk]: 12.5,
  2530. [MotionType.Run]: 25
  2531. },
  2532. diqing: {
  2533. [MotionType.Walk]: 12.5,
  2534. [MotionType.Run]: 25
  2535. }
  2536. },
  2537. r = t[this.currentArea] || t.guangchang;
  2538. return this.speed = r[e] * 30, this.speed;
  2539. }
  2540. }]);
  2541. return PathManager;
  2542. }();
  2543. var CameraStates = {
  2544. Normal: 0,
  2545. ItemView: 1,
  2546. CGView: 2,
  2547. PathView: 3
  2548. };
  2549. var Person$1 = {
  2550. Third: 0,
  2551. First: 1
  2552. };
  2553. function _createSuper$e(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$e(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  2554. function _isNativeReflectConstruct$e() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  2555. var Camera = /*#__PURE__*/function (_EventEmitter) {
  2556. _inherits(Camera, _EventEmitter);
  2557. var _super = _createSuper$e(Camera);
  2558. function Camera(e) {
  2559. var _this;
  2560. _classCallCheck(this, Camera);
  2561. _this = _super.call(this);
  2562. _this.initialFov = 0;
  2563. _this._state = CameraStates.Normal;
  2564. _this._person = Person$1.Third;
  2565. _this._cameraFollowing = !0;
  2566. _this._room = e;
  2567. return _this;
  2568. }
  2569. _createClass(Camera, [{
  2570. key: "checkPointOnLeftOrRight",
  2571. value: function checkPointOnLeftOrRight(e) {
  2572. var t = ue4Position2Xverse(e);
  2573. if (!t || this.checkPointInView(e)) return;
  2574. var o = this._room.scene.activeCamera;
  2575. if (!o) return;
  2576. var a = [o.target.x, o.target.y, o.target.z],
  2577. s = [o.position.x, o.position.y, o.position.z],
  2578. l = t.x,
  2579. u = t.y,
  2580. c = t.z,
  2581. h = calNormVector(s, a),
  2582. f = calNormVector(s, [l, u, c]);
  2583. return vectorCrossMulti(h, f) < 0 ? Direction.Right : Direction.Left;
  2584. }
  2585. }, {
  2586. key: "checkPointInView",
  2587. value: function checkPointInView(e, t, r) {
  2588. var n = ue4Position2Xverse({
  2589. x: e,
  2590. y: t,
  2591. z: r
  2592. });
  2593. if (!n) return !1;
  2594. for (var o = 0; o < 6; o++) {
  2595. if (this._room.scene.frustumPlanes[o].dotCoordinate(n) < 0) return !1;
  2596. }
  2597. return !0;
  2598. }
  2599. }, {
  2600. key: "person",
  2601. get: function get() {
  2602. return this._person;
  2603. }
  2604. }, {
  2605. key: "state",
  2606. get: function get() {
  2607. return this._state;
  2608. }
  2609. }, {
  2610. key: "pose",
  2611. get: function get() {
  2612. return this._room.currentClickingState.camera;
  2613. }
  2614. }, {
  2615. key: "cameraFollowing",
  2616. get: function get() {
  2617. return this._cameraFollowing;
  2618. },
  2619. set: function set(e) {
  2620. logger.info("cameraFollowing setter", e), this.setCameraFollowing({
  2621. isFollowHost: e
  2622. });
  2623. }
  2624. }, {
  2625. key: "setCameraFollowing",
  2626. value: function setCameraFollowing(_ref) {
  2627. _ref.isFollowHost;
  2628. }
  2629. }, {
  2630. key: "handleRenderInfo",
  2631. value: function handleRenderInfo(e) {
  2632. var t = e.renderInfo.cameraStateType,
  2633. r = this._room.sceneManager;
  2634. if (t !== this._state && (this._state = t, logger.debug("camera._state changed to", CameraStates[t]), t === CameraStates.CGView ? (r.cameraComponent.switchToCgCamera(), r.staticmeshComponent.getCgMesh().show()) : (r.cameraComponent.switchToMainCamera(), r.staticmeshComponent.getCgMesh().hide()), this.emit("stateChanged", {
  2635. state: t
  2636. })), this._room.isHost) return;
  2637. var n = e.playerState.isFollowHost;
  2638. !!n !== this._cameraFollowing && (this._cameraFollowing = !!n, this.emit("cameraFollowingChanged", {
  2639. cameraFollowing: !!n
  2640. }));
  2641. }
  2642. }, {
  2643. key: "setCameraState",
  2644. value: function setCameraState(_ref2) {
  2645. var e = _ref2.state;
  2646. if (this._state === e) {
  2647. logger.warn("You are already in ".concat(CameraStates[e], " camera state"));
  2648. return;
  2649. }
  2650. e === CameraStates.Normal || this._state === CameraStates.ItemView && logger.warn("CloseUp camera state can only be triggerd by room internally");
  2651. }
  2652. }, {
  2653. key: "turnToFace",
  2654. value: function turnToFace(_ref3) {
  2655. var _ref3$extra = _ref3.extra,
  2656. e = _ref3$extra === void 0 ? "" : _ref3$extra,
  2657. _ref3$offset = _ref3.offset,
  2658. t = _ref3$offset === void 0 ? 0 : _ref3$offset;
  2659. var r = {
  2660. action_type: Actions.TurnToFace,
  2661. turn_to_face_action: {
  2662. offset: t
  2663. }
  2664. };
  2665. return this.emit("viewChanged", {
  2666. extra: e
  2667. }), this._room.actionsHandler.sendData({
  2668. data: r
  2669. });
  2670. }
  2671. }, {
  2672. key: "isInDefaultView",
  2673. value: function isInDefaultView() {
  2674. if (!this._room.isHost) {
  2675. logger.warn("It is recommended to call the function on the host side");
  2676. return;
  2677. }
  2678. if (!this._room._currentClickingState) return logger.error("CurrentState should not be empty"), !1;
  2679. var _this$_room$_currentC = this._room._currentClickingState,
  2680. e = _this$_room$_currentC.camera,
  2681. t = _this$_room$_currentC.player;
  2682. return Math.abs(t.angle.yaw - 180 - e.angle.yaw) % 360 <= 4;
  2683. }
  2684. }, {
  2685. key: "screenShot",
  2686. value: function () {
  2687. var _screenShot = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_ref4) {
  2688. var e, _ref4$autoSave, t, r, n, o;
  2689. return regenerator.wrap(function _callee$(_context) {
  2690. while (1) {
  2691. switch (_context.prev = _context.next) {
  2692. case 0:
  2693. e = _ref4.name, _ref4$autoSave = _ref4.autoSave, t = _ref4$autoSave === void 0 ? !1 : _ref4$autoSave;
  2694. r = this._room.scene.getEngine(), n = this._room.scene.activeCamera;
  2695. _context.prev = 2;
  2696. this._room.sceneManager.setImageQuality(EImageQuality.high);
  2697. _context.next = 6;
  2698. return CreateScreenshotAsync(r, n, {
  2699. precision: 1
  2700. });
  2701. case 6:
  2702. o = _context.sent;
  2703. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), t === !0 && downloadFileByBase64(o, e), Promise.resolve(o)));
  2704. case 10:
  2705. _context.prev = 10;
  2706. _context.t0 = _context["catch"](2);
  2707. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), Promise.reject(_context.t0)));
  2708. case 13:
  2709. case "end":
  2710. return _context.stop();
  2711. }
  2712. }
  2713. }, _callee, this, [[2, 10]]);
  2714. }));
  2715. function screenShot(_x) {
  2716. return _screenShot.apply(this, arguments);
  2717. }
  2718. return screenShot;
  2719. }()
  2720. }, {
  2721. key: "changeToFirstPerson",
  2722. value: function changeToFirstPerson(e, t, r) {
  2723. var _this2 = this;
  2724. var n = e.camera,
  2725. o = e.player,
  2726. a = e.attitude,
  2727. s = e.areaName,
  2728. l = e.pathName;
  2729. return this._room.actionsHandler.requestPanorama({
  2730. camera: n,
  2731. player: o,
  2732. attitude: a,
  2733. areaName: s,
  2734. pathName: l
  2735. }, t, r).then(function () {
  2736. _this2._room.networkController.rtcp.workers.changePanoMode(!0);
  2737. var _ref5 = o || {},
  2738. u = _ref5.position,
  2739. c = _ref5.angle;
  2740. _this2._room.sceneManager.cameraComponent.changeToFirstPersonView({
  2741. position: u,
  2742. rotation: c
  2743. });
  2744. });
  2745. }
  2746. }, {
  2747. key: "setPerson",
  2748. value: function setPerson(e) {
  2749. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  2750. camera: this._room._currentClickingState.camera,
  2751. player: this._room._currentClickingState.player
  2752. };
  2753. var r = Date.now();
  2754. return this._setPerson(e, t).then(function (n) {
  2755. return logger.infoAndReportMeasurement({
  2756. tag: Person$1[e],
  2757. startTime: r,
  2758. metric: "setPerson"
  2759. }), n;
  2760. }).catch(function (n) {
  2761. return logger.infoAndReportMeasurement({
  2762. tag: Person$1[e],
  2763. startTime: r,
  2764. metric: "setPerson",
  2765. error: n
  2766. }), Promise.reject(n);
  2767. });
  2768. }
  2769. }, {
  2770. key: "_setPerson",
  2771. value: function _setPerson(e) {
  2772. var _this3 = this;
  2773. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  2774. camera: this._room._currentClickingState.camera,
  2775. player: this._room._currentClickingState.player
  2776. };
  2777. return e !== Person$1.First && e !== Person$1.Third ? Promise.reject("invalid person " + e) : !t.camera || !t.player ? Promise.reject(new ParamError("wrong camera or player")) : e === Person$1.First ? this._room.panorama.access({
  2778. camera: t.camera,
  2779. player: t.player,
  2780. tag: "setPerson"
  2781. }).then(function () {
  2782. var o, a;
  2783. _this3._person = e, (o = _this3._room._userAvatar) == null || o.hide();
  2784. var _ref6 = ((a = _this3._room.currentClickingState) == null ? void 0 : a.camera) || {},
  2785. r = _ref6.position,
  2786. n = _ref6.angle;
  2787. !r || !n || _this3._room.sceneManager.cameraComponent.changeToFirstPersonView({
  2788. position: r,
  2789. rotation: n
  2790. });
  2791. }) : this._room.panorama.exit({
  2792. camera: t.camera,
  2793. player: t.player
  2794. }).then(function () {
  2795. var r, n;
  2796. _this3._person = e, (r = _this3._room._userAvatar) != null && r.xAvatar && ((n = _this3._room._userAvatar) == null || n.xAvatar.show());
  2797. });
  2798. }
  2799. }, {
  2800. key: "setCameraPose",
  2801. value: function setCameraPose(e) {
  2802. this._room.sceneManager.cameraComponent.setCameraPose({
  2803. position: e.position,
  2804. rotation: e.angle
  2805. });
  2806. }
  2807. }, {
  2808. key: "setMainCameraRotationLimit",
  2809. value: function setMainCameraRotationLimit(e) {
  2810. var t = e.limitAxis,
  2811. r = e.limitRotation;
  2812. this._room.sceneManager.cameraComponent.setMainCameraRotationLimit(t, r);
  2813. }
  2814. }]);
  2815. return Camera;
  2816. }(EventEmitter);
  2817. function _createSuper$d(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$d(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  2818. function _isNativeReflectConstruct$d() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  2819. var numberFormat = new Intl.NumberFormat(window.navigator.language, {
  2820. maximumFractionDigits: 0
  2821. });
  2822. var Stats = /*#__PURE__*/function (_EventEmitter) {
  2823. _inherits(Stats, _EventEmitter);
  2824. var _super = _createSuper$d(Stats);
  2825. function Stats(e) {
  2826. var _this;
  2827. _classCallCheck(this, Stats);
  2828. _this = _super.call(this);
  2829. _this._netInterval = null;
  2830. _this._disabled = !1;
  2831. _this._show = !1;
  2832. _this._aggregatedStats = {};
  2833. _this._displayElement = null;
  2834. _this._extraStats = {};
  2835. _this._networkSamples = [];
  2836. _this.externalStats = null;
  2837. _this.constructedTime = null;
  2838. _this.room = e, _this.constructedTime = Date.now(), _this._interval = window.setInterval(function () {
  2839. var t, r, n;
  2840. _this._disabled || _this.onStats((n = (r = (t = e.networkController) == null ? void 0 : t.rtcp) == null ? void 0 : r.workers) == null ? void 0 : n.uploadDataToServer());
  2841. }, 1e3), _this._netInterval = window.setInterval(function () {
  2842. _this.getIsWeakNet();
  2843. }, NET_INTERVAL * 1e3);
  2844. return _this;
  2845. }
  2846. _createClass(Stats, [{
  2847. key: "isShow",
  2848. get: function get() {
  2849. return this._show;
  2850. }
  2851. }, {
  2852. key: "assign",
  2853. value: function assign(e) {
  2854. Object.assign(this._extraStats, e), ((e == null ? void 0 : e.hb) || (e == null ? void 0 : e.rtt)) && this.startStatsNetSamples();
  2855. }
  2856. }, {
  2857. key: "appendExternalStats",
  2858. value: function appendExternalStats(e) {
  2859. var _this2 = this;
  2860. var t = {};
  2861. if (!e || typeof e != "object") {
  2862. console.warn("appendExternalStats should be plain object");
  2863. return;
  2864. }
  2865. Object.keys(e).forEach(function (r) {
  2866. Object.prototype.hasOwnProperty.call(_this2._aggregatedStats, r) ? console.warn("".concat(r, " is duplicate with internal stats")) : t[r] = e[r];
  2867. }), !(Object.keys(t).length > 10) && (this.externalStats = t);
  2868. }
  2869. }, {
  2870. key: "getRtt",
  2871. value: function getRtt() {
  2872. var e = this._extraStats.rtt;
  2873. return typeof e != "number" ? 0 : e > 999 ? 999 : e;
  2874. }
  2875. }, {
  2876. key: "enable",
  2877. value: function enable() {
  2878. this._disabled = !1;
  2879. }
  2880. }, {
  2881. key: "disable",
  2882. value: function disable() {
  2883. this._disabled = !0;
  2884. }
  2885. }, {
  2886. key: "disableNet",
  2887. value: function disableNet() {
  2888. this._netInterval && window.clearInterval(this._netInterval);
  2889. }
  2890. }, {
  2891. key: "show",
  2892. value: function show() {
  2893. this._show = !0, this._render();
  2894. }
  2895. }, {
  2896. key: "hide",
  2897. value: function hide() {
  2898. this._show = !1, this._displayElement && document.body.removeChild(this._displayElement), this._displayElement = null;
  2899. }
  2900. }, {
  2901. key: "getIsWeakNet",
  2902. value: function getIsWeakNet() {
  2903. var _this3 = this;
  2904. var e = !1;
  2905. var t = this._networkSamples.length - 1;
  2906. if (t < 0) return;
  2907. var r = this._networkSamples[t].time,
  2908. n = this._networkSamples[0].time,
  2909. o = r - n,
  2910. a = 1e3 * (DURATION - 2);
  2911. if (o < a) return;
  2912. var s = this._networkSamples.map(function (g) {
  2913. return _this3.isNetDelay(g, "rtt");
  2914. }),
  2915. l = this._networkSamples.map(function (g) {
  2916. return _this3.isNetDelay(g, "hb");
  2917. }),
  2918. u = s.reduce(function (g, m) {
  2919. return g + m;
  2920. }, 0),
  2921. c = l.reduce(function (g, m) {
  2922. return g + m;
  2923. }, 0),
  2924. h = Math.floor(u / this._networkSamples.length) * 100,
  2925. f = Math.floor(c / this._networkSamples.length) * 100,
  2926. d = 70;
  2927. (h >= d || f >= d) && (e = !0);
  2928. var _ = this.room.viewMode === "observer" || this.room.viewMode === "serverless";
  2929. e && !_ && (logger.infoAndReportMeasurement({
  2930. metric: "weakNetwork",
  2931. startTime: Date.now(),
  2932. extra: {
  2933. msg: this._networkSamples.slice(20),
  2934. netDelayRTTValues: u,
  2935. netDelayHBValues: c
  2936. }
  2937. }), this.emit("weakNetwork"));
  2938. }
  2939. }, {
  2940. key: "startStatsNetSamples",
  2941. value: function startStatsNetSamples() {
  2942. var _this$_extraStats = this._extraStats,
  2943. e = _this$_extraStats.rtt,
  2944. t = _this$_extraStats.hb;
  2945. if (e || t) {
  2946. var r = {
  2947. rtt: e,
  2948. hb: t,
  2949. time: new Date().getTime()
  2950. };
  2951. this._networkSamples.push(r);
  2952. var n = this._networkSamples.length - 1;
  2953. if (n < 0) return;
  2954. var o = this._networkSamples[n].time,
  2955. a = 1e3 * DURATION;
  2956. this._networkSamples = this._networkSamples.filter(function (s) {
  2957. return s.time > o - a;
  2958. });
  2959. }
  2960. }
  2961. }, {
  2962. key: "isNetDelay",
  2963. value: function isNetDelay(e, t) {
  2964. return t === "rtt" ? e.rtt > RTT_MAX_VALUE ? 1 : 0 : t === "hb" && e.hb > HB_MAX_VALUE ? 1 : 0;
  2965. }
  2966. }, {
  2967. key: "getPreciesTimer",
  2968. value: function getPreciesTimer(e, t) {
  2969. var r = t * 1e3,
  2970. n = new Date().getTime();
  2971. var o = 0;
  2972. o++;
  2973. var a = new Date().getTime() - (n + o * 1e3),
  2974. s = r - a,
  2975. l = setTimeout(function () {
  2976. clearTimeout(l), e();
  2977. }, s);
  2978. }
  2979. }, {
  2980. key: "_render",
  2981. value: function _render() {
  2982. var c, h, f, d, _, g, m, v, y, b, T, C, A, S, P, R, M, x, I, w;
  2983. if (!this._aggregatedStats) return;
  2984. this._displayElement || (this._displayElement = document.createElement("div"), this._displayElement.style.position = "absolute", this._displayElement.style.top = "10px", this._displayElement.style.left = "200px", this._displayElement.style.width = "200px", this._displayElement.style.backgroundColor = "rgba(0,0,0,.5)", this._displayElement.style.color = "white", this._displayElement.style.textAlign = "left", this._displayElement.style.fontSize = "8px", this._displayElement.style.lineHeight = "10px", document.body.appendChild(this._displayElement));
  2985. var e = [],
  2986. t = Date.now() - this.constructedTime,
  2987. r = Math.floor(t / 1e3 % 60),
  2988. n = Math.floor(t / (1e3 * 60) % 60),
  2989. o = Math.floor(t / (1e3 * 60 * 60) % 24),
  2990. a = o < 10 ? "0" + o.toString() : o.toString(),
  2991. s = n < 10 ? "0" + n : n,
  2992. l = r < 10 ? "0" + r : r;
  2993. e.push({
  2994. key: new Date(Math.floor(this._aggregatedStats.timestamp || 0)).toLocaleString("en-GB"),
  2995. value: a + ":" + s + ":" + l
  2996. }), e.push({
  2997. key: "rtt: " + this._extraStats.rtt + " hb: " + this._extraStats.hb,
  2998. value: "FPS: " + this._extraStats.fps + " avatar: " + ((c = this.room._userAvatar) == null ? void 0 : c.state)
  2999. }), e.push({
  3000. key: "SDK: " + Xverse$1.SUB_PACKAGE_VERSION,
  3001. value: "ENGINE:" + VERSION$1 + " uid:" + this._extraStats.userId
  3002. }), e.push({
  3003. key: "\u540C\u6B65/\u6709\u6548/\u663E\u793A\u73A9\u5BB6",
  3004. value: "".concat(this._extraStats.syncUserNum || 0, "/").concat(this._extraStats.userNum || 0, "/").concat(this._extraStats.renderedUserNum || 0)
  3005. }), e.push({
  3006. key: "media/meta bitrate(kbps)",
  3007. value: numberFormat.format(this._aggregatedStats.mediaBitrate || 0) + "/" + numberFormat.format(this._aggregatedStats.metaBitrate || 0)
  3008. }), e.push({
  3009. key: ":----------------Decoding---------------",
  3010. value: ""
  3011. }), e.push({
  3012. key: "-max/avg decodeTime(ms)",
  3013. value: numberFormat.format(this._aggregatedStats.decodeTimeMaxFrame || 0) + "/" + numberFormat.format(this._aggregatedStats.decodeTimePerFrame || 0)
  3014. }), e.push({
  3015. key: "-frmAwait/Lost/Drop",
  3016. value: numberFormat.format(this._aggregatedStats.framesAwait || 0) + "/" + numberFormat.format(this._aggregatedStats.packetsLost || 0) + "/" + numberFormat.format(this._aggregatedStats.packetsDrop || 0) + "/" + numberFormat.format(this._aggregatedStats.updateDropFrame) || 0
  3017. }), e.push({
  3018. key: ":----------------FrameLoop-------------",
  3019. value: ""
  3020. }), e.push({
  3021. key: "interval(max/avg/>40)",
  3022. value: (((h = this._extraStats.maxFrameTime) == null ? void 0 : h.toFixed(1)) || 0) + "/" + (((f = this._extraStats.avgFrameTime) == null ? void 0 : f.toFixed(0)) || 0) + "/" + this._extraStats.engineSloppyCnt
  3023. }), e.push({
  3024. key: "systemStuck",
  3025. value: this._extraStats.systemStuckCnt
  3026. }), e.push({
  3027. key: "--update",
  3028. value: (this._aggregatedStats.maxGraphicTime.toFixed(1) || 0) + "/" + (((d = this._aggregatedStats.averageGraphicTime) == null ? void 0 : d.toFixed(0)) || 0)
  3029. }), e.push({
  3030. key: "--timeout",
  3031. value: (((_ = this._extraStats.maxTimeoutTime) == null ? void 0 : _.toFixed(1)) || 0) + "/" + ((g = this._extraStats.avgTimeoutTime) == null ? void 0 : g.toFixed(0)) || 0
  3032. }), e.push({
  3033. key: "--render",
  3034. value: (((m = this._extraStats.maxRenderFrameTime) == null ? void 0 : m.toFixed(1)) || 0) + "/" + (((v = this._extraStats.renderFrameTime) == null ? void 0 : v.toFixed(0)) || 0)
  3035. }), e.push({
  3036. key: "---anim/regBR/clip(avg ms)",
  3037. value: (this._extraStats.animationTime.toFixed(2) || 0) + " / " + (this._extraStats.registerBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.meshSelectTime.toFixed(2) || 0)
  3038. }), e.push({
  3039. key: "---anim/regBR/clip(max ms)",
  3040. value: (this._extraStats.maxAnimationTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxMeshSelectTime.toFixed(2) || 0)
  3041. }), e.push({
  3042. key: "---rTR/drC/regAF(avg ms)",
  3043. value: (this._extraStats.renderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.drawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.registerAfterRenderTime.toFixed(2) || 0)
  3044. }), e.push({
  3045. key: "---rTR/drC/regAF(max ms)",
  3046. value: (this._extraStats.maxRenderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxDrawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterAfterRenderTime.toFixed(2) || 0)
  3047. }), e.push({
  3048. key: "--tri/drC/pati/bones/anim(Num)",
  3049. value: (this._extraStats.triangle || 0) + " / " + (this._extraStats.drawcall.toFixed(0) || 0) + " / " + (this._extraStats.activeParticles.toFixed(0) || 0) + " / " + (this._extraStats.activeBones.toFixed(0) || 0) + " / " + (this._extraStats.activeAnimation.toFixed(0) || 0)
  3050. }), e.push({
  3051. key: "--rootN/mesh/geo/tex/mat(Num)",
  3052. value: (this._extraStats.totalRootNodes.toFixed(0) || 0) + " / " + (this._extraStats.totalMeshes.toFixed(0) || 0) + " / " + (this._extraStats.totalGeometries.toFixed(0) || 0) + " / " + (this._extraStats.totalTextures.toFixed(0) || 0) + " / " + (this._extraStats.totalMaterials.toFixed(0) || 0)
  3053. }), e.push({
  3054. key: "--registerBF/AF(Num)",
  3055. value: (this._extraStats.registerBeforeCount.toFixed(0) || 0) + " / " + (this._extraStats.registerAfterCount.toFixed(0) || 0)
  3056. }), e.push({
  3057. key: ":----------------Rotation-------------------",
  3058. value: ""
  3059. }), e.push({
  3060. key: "Total(ms/miss)",
  3061. value: (((y = this._aggregatedStats.avgOverallTime) == null ? void 0 : y.toFixed(2)) || 0) + "/" + (this._aggregatedStats.responseMissPs + this._aggregatedStats.processMissPs + this._aggregatedStats.displayMissPs)
  3062. }), e.push({
  3063. key: "--rotateRsp",
  3064. value: (((b = this._aggregatedStats.avgResponseTime) == null ? void 0 : b.toFixed(1)) || 0) + "/" + this._aggregatedStats.responseMissPs
  3065. }), e.push({
  3066. key: "--rotateProc",
  3067. value: (((T = this._aggregatedStats.avgProcessTime) == null ? void 0 : T.toFixed(1)) || 0) + "/" + this._aggregatedStats.processMissPs
  3068. }), e.push({
  3069. key: "--rotateShow",
  3070. value: (((C = this._aggregatedStats.avgDisplayTime) == null ? void 0 : C.toFixed(1)) || 0) + "/" + this._aggregatedStats.displayMissPs
  3071. }), ((A = this.room._userAvatar) == null ? void 0 : A.state) == "moving", e.push({
  3072. key: ":----------------Move----------------------",
  3073. value: ""
  3074. }), e.push({
  3075. key: "-startDelay",
  3076. value: (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.moveResponseDelay || 0 : this._aggregatedStats.flyResponseDelay || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.moveProcessDelay || 0 : this._aggregatedStats.flyProcessDelay || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.moveDisplayDelay || 0 : this._aggregatedStats.flyDisplayDelay || 0)
  3077. }), (((S = this.room._userAvatar) == null ? void 0 : S.state) == "moving" || this._aggregatedStats.moveEvent == "GetOnAirship" || this._aggregatedStats.moveEvent == "GetOnVehicle") && e.push({
  3078. key: "-srvInterFrm(max/avg)",
  3079. value: (this._aggregatedStats.maxServerDiff || 0) + "/" + (this._aggregatedStats.avgServerDiff.toFixed(1) || 0)
  3080. }), e.push({
  3081. key: "-interFrameDelay",
  3082. value: "(max/avg/jank)"
  3083. }), e.push({
  3084. key: "--toDisplay",
  3085. value: (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.maxDisplayMoveDiff || 0 : this._aggregatedStats.maxDisplayFlyDiff || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.avgDisplayMoveDiff.toFixed(1) || 0 : this._aggregatedStats.avgDisplayFlyDiff.toFixed(1) || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? ((P = this._aggregatedStats.moveDisplayJank) == null ? void 0 : P.toFixed(3)) || 0 : ((R = this._aggregatedStats.flyDisplayJank) == null ? void 0 : R.toFixed(3)) || 0)
  3086. }), e.push({
  3087. key: "--received",
  3088. value: (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.maxResponseMoveDiff || 0 : this._aggregatedStats.maxResponseFlyDiff || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.avgResponseMoveDiff.toFixed(1) || 0 : this._aggregatedStats.avgResponseFlyDiff.toFixed(1) || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? ((M = this._aggregatedStats.moveResponseJank) == null ? void 0 : M.toFixed(3)) || 0 : ((x = this._aggregatedStats.flyResponseJank) == null ? void 0 : x.toFixed(3)) || 0)
  3089. }), e.push({
  3090. key: "--decoded",
  3091. value: (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.maxProcessMoveDiff || 0 : this._aggregatedStats.maxProcessFlyDiff || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? this._aggregatedStats.avgProcessMoveDiff.toFixed(1) || 0 : this._aggregatedStats.avgProcessFlyDiff.toFixed(1) || 0) + "/" + (this._aggregatedStats.moveEvent == "MoveTo" ? ((I = this._aggregatedStats.moveProcessJank) == null ? void 0 : I.toFixed(3)) || 0 : ((w = this._aggregatedStats.flyProcessJank) == null ? void 0 : w.toFixed(3)) || 0)
  3092. }), e.push({
  3093. key: ":----------------DevInfo-----------------",
  3094. value: ""
  3095. }), e.push({
  3096. key: "sd",
  3097. value: (this._aggregatedStats.sdMoveResponseLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveProcessLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveDisplayLongTime.toFixed(1) || 0)
  3098. }), e.push({
  3099. key: "----hardwareInfo",
  3100. value: this._extraStats.hardwareInfo
  3101. });
  3102. var u = "";
  3103. for (var _i = 0, _e = e; _i < _e.length; _i++) {
  3104. var O = _e[_i];
  3105. u += "<div><span>".concat(O.key, "</span>: <span>").concat(O.value, "</span> </div>");
  3106. }
  3107. this._displayElement.innerHTML = u;
  3108. }
  3109. }, {
  3110. key: "onStats",
  3111. value: function onStats(e) {
  3112. var _this4 = this;
  3113. var n;
  3114. if (!e) return;
  3115. var t = {},
  3116. r = this;
  3117. r._aggregatedStats || (r._aggregatedStats = {}), t.timestamp = e.timestamp, t.mediaBytesReceived = e.mediaBytesReceived, t.metaBytesReceived = e.metaBytesReceived, t.packetsLost = e.packetsLost, t.frameHeight = e.frameHeight, t.frameWidth = e.frameWidth, t.framesReceivedUI = e.framesReceived, t.framesReceived = e.framesReceivedWorker, t.framesDecoded = e.framesDecoded, t.framesEmited = e.framesEmited, t.decodeTimePerFrame = e.decodeTimePerFrame, t.decodeTimeMaxFrame = e.decodeTimeMaxFrame, t.packetsDrop = e.packetsDrop, t.framesAwait = e.framesAwait, t.updateDropFrame = e.updateDropFrame, t.firstMediaArraval = e.firstMediaArraval, t.firstYUVDecoded = e.firstYUVDecoded, t.firstRender = e.firstRender, t.returnFrames = e.returnFrames, t.sendOutBuffer = e.sendOutBuffer, t.averageGraphicTime = e.averageGraphicTime, t.maxGraphicTime = e.maxGraphicTime, t.jankTimes = e.jankTimes, t.bigJankTimes = e.bigJankTimes, t.decodeJankTimes = e.decodeJankTimes, t.bigDecodeJankTimes = e.bigDecodeJankTimes, t.serverFrameFast = e.serverFrameFast, t.serverFrameSlow = e.serverFrameSlow, t.clientFrameFast = e.clientFrameFast, t.clientFrameSlow = e.clientFrameSlow, t.rtcMessageReceived = e.rtcMessageReceived, t.rtcBytesReceived = e.rtcBytesReceived, t.receiveIframes = e.receiveIframes, t.decodeIframes = e.decodeIframes, t.avgResponseTime = e.avgResponseTime, t.avgProcessTime = e.avgProcessTime, t.avgDisplayTime = e.avgDisplayTime, t.avgOverallTime = e.avgOverallTime, t.overallTimeCount = e.overallTimeCount, t.responseMiss = e.responseMiss, t.processMiss = e.processMiss, t.displayMiss = e.displayMiss, t.avgResponseMoveDiff = e.avgResponseMoveDiff, t.avgProcessMoveDiff = e.avgProcessMoveDiff, t.avgDisplayMoveDiff = e.avgDisplayMoveDiff, t.maxResponseMoveDiff = e.maxResponseMoveDiff, t.maxProcessMoveDiff = e.maxProcessMoveDiff, t.maxDisplayMoveDiff = e.maxDisplayMoveDiff, t.moveResponseDelay = e.moveResponseDelay, t.moveProcessDelay = e.moveProcessDelay, t.moveDisplayDelay = e.moveDisplayDelay, t.moveResponseJank = e.moveResponseJank, t.moveProcessJank = e.moveProcessJank, t.moveDisplayJank = e.moveDisplayJank, t.avgMetaParseTime = e.avgMetaParseTime, t.maxMetaParseTime = e.maxMetaParseTime, t.moveResponseCounts = e.moveResponseCounts, t.moveProcessCounts = e.moveProcessCounts, t.moveDisplayCounts = e.moveDisplayCounts, t.MoveDisplayCountGood = e.MoveDisplayCountGood, t.MoveDisplayCountWell = e.MoveDisplayCountWell, t.MoveDisplayCountFair = e.MoveDisplayCountFair, t.MoveDisplayCountBad = e.MoveDisplayCountBad, t.MoveDisplayCountRest = e.MoveDisplayCountRest, t.avgServerDiff = e.avgServerDiff, t.maxServerDiff = e.maxServerDiff, t.avgResponseFlyDiff = e.avgResponseFlyDiff, t.avgProcessFlyDiff = e.avgProcessFlyDiff, t.avgDisplayFlyDiff = e.avgDisplayFlyDiff, t.maxResponseFlyDiff = e.maxResponseFlyDiff, t.maxProcessFlyDiff = e.maxProcessFlyDiff, t.maxDisplayFlyDiff = e.maxDisplayFlyDiff, t.flyResponseCounts = e.flyResponseCounts, t.flyProcessCounts = e.flyProcessCounts, t.flyDisplayCounts = e.flyDisplayCounts, t.flyResponseJank = e.flyResponseJank, t.flyProcessJank = e.flyProcessJank, t.flyDisplayJank = e.flyDisplayJank, t.flyResponseDelay = e.flyResponseDelay, t.flyProcessDelay = e.flyProcessDelay, t.flyDisplayDelay = e.flyDisplayDelay, t.moveEvent = e.moveEvent, t.sdMoveResponseLongTime = e.sdMoveResponseLongTime, t.sdMoveProcessLongTime = e.sdMoveProcessLongTime, t.sdMoveDisplayLongTime = e.sdMoveDisplayLongTime, r._aggregatedStats && r._aggregatedStats.timestamp && (t.mediaBitrate = 8 * (t.mediaBytesReceived - r._aggregatedStats.mediaBytesReceived) / 1e3, t.mediaBitrate = Math.round(t.mediaBitrate || 0), t.metaBitrate = 8 * (t.metaBytesReceived - r._aggregatedStats.metaBytesReceived) / 1e3, t.metaBitrate = Math.round(t.metaBitrate || 0), t.rtcMessagePs = t.rtcMessageReceived - r._aggregatedStats.rtcMessageReceived, t.rtcBitrate = 8 * (t.rtcBytesReceived - r._aggregatedStats.rtcBytesReceived) / 1e3, t.rtcBitrate = Math.round(t.rtcBitrate || 0), t.framesEmitedPs = t.framesEmited - r._aggregatedStats.framesEmited, t.framesEmitedPs = Math.round(t.framesEmitedPs || 0), t.framesReceivedPs = t.framesReceived - r._aggregatedStats.framesReceived, t.framesReceivedPs = Math.round(t.framesReceivedPs || 0), t.framesDecodedPs = t.framesDecoded - r._aggregatedStats.framesDecoded, t.framesDecodedPs = Math.round(t.framesDecodedPs || 0), t.returnFramesPs = t.returnFrames - r._aggregatedStats.returnFrames, t.returnFramesPs = Math.round(t.returnFramesPs || 0), t.responseMissPs = t.responseMiss - r._aggregatedStats.responseMiss, t.processMissPs = t.processMiss - r._aggregatedStats.processMiss, t.displayMissPs = t.displayMiss - r._aggregatedStats.displayMiss, t.returnFrames = e.returnFrames), this._show && this._render(), t.registerBeforeRenderTime = this._extraStats.registerBeforeRenderTime, t.registerAfterRenderTime = this._extraStats.registerAfterRenderTime, t.renderTargetRenderTime = this._extraStats.renderTargetRenderTime, t.renderFrameTime = this._extraStats.renderFrameTime, t.maxRenderFrameTime = this._extraStats.maxRenderFrameTime, t.interFrameTime = this._extraStats.interFrameTime, t.animationTime = this._extraStats.animationTime, t.meshSelectTime = this._extraStats.meshSelectTime, t.drawcall = this._extraStats.drawcall, t.drawcallTime = this._extraStats.drawcallTime, t.triangle = this._extraStats.triangle, t.registerAfterCount = this._extraStats.registerAfterCount, t.registerBeforeCount = this._extraStats.registerBeforeCount, t.fps = this._extraStats.fps, t.rtt = this._extraStats.rtt, t.hb = this._extraStats.hb, t.avgFrameTime = this._extraStats.avgFrameTime, t.avgTimeoutTime = this._extraStats.avgTimeoutTime, t.engineSloppyCnt = this._extraStats.engineSloppyCnt, t.systemStuckCnt = this._extraStats.systemStuckCnt, t.avatarState = (n = this.room._userAvatar) == null ? void 0 : n.state, t.maxFrameTime = this._extraStats.maxFrameTime, t.maxTimeoutTime = this._extraStats.maxTimeoutTime, t.activeParticles = this._extraStats.activeParticles, t.activeBones = this._extraStats.activeBones, t.activeAnimation = this._extraStats.activeAnimation, t.totalRootNodes = this._extraStats.totalRootNodes, t.totalGeometries = this._extraStats.totalGeometries, t.totalMeshes = this._extraStats.totalMeshes, t.totalTextures = this._extraStats.totalTextures, t.totalMaterials = this._extraStats.totalMaterials, t.hardwareInfo = this._extraStats.hardwareInfo, t.maxInterFrameTime = this._extraStats.maxInterFrameTime, t.maxDrawcallTime = this._extraStats.maxDrawcallTime, t.maxMeshSelectTime = this._extraStats.maxMeshSelectTime, t.maxAnimationTime = this._extraStats.maxAnimationTime, t.maxRegisterBeforeRenderTime = this._extraStats.maxRegisterBeforeRenderTime, t.maxRegisterAfterRenderTime = this._extraStats.maxRegisterAfterRenderTime, t.maxRenderTargetRenderTime = this._extraStats.maxRenderTargetRenderTime, this.externalStats && Object.keys(this.externalStats || {}).forEach(function (o) {
  3118. t[o] = _this4.externalStats[o];
  3119. }), r._aggregatedStats = t, this.emit("stats", {
  3120. stats: t
  3121. });
  3122. }
  3123. }]);
  3124. return Stats;
  3125. }(EventEmitter);
  3126. var Actions$1 = {
  3127. Clicking: 1,
  3128. PlayCG: 6,
  3129. Back: 7,
  3130. ChangeRoom: 8,
  3131. ChangeSkin: 13,
  3132. Joystick: 15,
  3133. Transfer: 18,
  3134. GetOnVehicle: 22,
  3135. GetOffVehicle: 23,
  3136. StopMoving: 34,
  3137. UnaryActionLine: 1e3,
  3138. Init: 1001,
  3139. Exit: 1002,
  3140. SetIFrameInfo: 1003,
  3141. GetNeighborPoints: 1004,
  3142. ReserveSeat: 1005,
  3143. GetReserveStatus: 1006,
  3144. ChangeNickname: 1007,
  3145. ChangeBitRateInfo: 1008,
  3146. Echo: 1009,
  3147. SetPlayerState: 1010,
  3148. TurnTo: 1011,
  3149. TurnToFace: 1012,
  3150. RotateTo: 1013,
  3151. Rotation: 1014,
  3152. CameraTurnTo: 1015,
  3153. ConfirmEvent: 1016,
  3154. Broadcast: 1017,
  3155. NotifyActionLine: 2e4,
  3156. AudienceChangeToVisitor: 1020,
  3157. VisitorChangeToAudience: 1021,
  3158. RemoveVisitor: 1022,
  3159. GetUserWithAvatar: 1023
  3160. };
  3161. function _createSuper$c(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$c(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  3162. function _isNativeReflectConstruct$c() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  3163. var EventsManager = /*#__PURE__*/function (_EventEmitter) {
  3164. _inherits(EventsManager, _EventEmitter);
  3165. var _super = _createSuper$c(EventsManager);
  3166. function EventsManager() {
  3167. var _this;
  3168. _classCallCheck(this, EventsManager);
  3169. _this = _super.apply(this, arguments);
  3170. E(_assertThisInitialized(_this), "events", new Map());
  3171. E(_assertThisInitialized(_this), "specialEvents", new Map());
  3172. return _this;
  3173. }
  3174. _createClass(EventsManager, [{
  3175. key: "remove",
  3176. value: function remove(e, t, r, n) {
  3177. if (this.specialEvents.has(e) && !n && t === Codes$1.Success) return;
  3178. this.events.get(e) && (this.emit(e, {
  3179. code: t,
  3180. data: r
  3181. }), this.events.delete(e), this.specialEvents.delete(e));
  3182. }
  3183. }, {
  3184. key: "track",
  3185. value: function () {
  3186. var _track = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  3187. var _this2 = this;
  3188. var r, _ref, n, _ref$noReport, o, a, s, l, u, c;
  3189. return regenerator.wrap(function _callee$(_context) {
  3190. while (1) {
  3191. switch (_context.prev = _context.next) {
  3192. case 0:
  3193. r = e.traceId;
  3194. this.emitTraceIdToDecoder(e);
  3195. _ref = t || {}, n = _ref.sampleRate, _ref$noReport = _ref.noReport, o = _ref$noReport === void 0 ? !1 : _ref$noReport, a = _ref.special;
  3196. if (!(n && Math.random() > n)) {
  3197. _context.next = 5;
  3198. break;
  3199. }
  3200. return _context.abrupt("return", Promise.resolve());
  3201. case 5:
  3202. s = Actions[e.event] + "Action", l = e.tag;
  3203. this.events.set(r, !0), a && this.specialEvents.set(r, !0);
  3204. u = Date.now();
  3205. c = null;
  3206. return _context.abrupt("return", new Promise(function (h, f) {
  3207. if (o) return _this2.off(r), _this2.events.delete(r), h(void 0);
  3208. _this2.on(r, function (_ref2) {
  3209. var _ = _ref2.code,
  3210. g = _ref2.data,
  3211. m = _ref2.msg;
  3212. if (_ === Codes$1.Success) h(g), _this2.off(r), logger.infoAndReportMeasurement({
  3213. metric: s,
  3214. tag: l,
  3215. extra: e.extra,
  3216. startTime: u,
  3217. traceId: r
  3218. });else {
  3219. if (_ === Codes$1.ActionMaybeDelay) return;
  3220. if (_ === Codes$1.DoActionBlocked && e.event === Actions.Rotation) {
  3221. logger.debug(s + " response code: " + _);
  3222. return;
  3223. }
  3224. var v = getErrorByCode(_),
  3225. y = new v(m);
  3226. _this2.off(r), f(y), _this2.emit("actionResponseError", {
  3227. error: y,
  3228. event: e,
  3229. tag: l
  3230. }), logger.infoAndReportMeasurement({
  3231. metric: s,
  3232. tag: l,
  3233. extra: e.extra,
  3234. error: y,
  3235. startTime: u,
  3236. traceId: r
  3237. });
  3238. }
  3239. });
  3240. var d = e.timeout || 2e3;
  3241. c = window.setTimeout(function () {
  3242. if (c && clearTimeout(c), !_this2.events.get(r)) return;
  3243. var _ = new ActionResponseTimeoutError("".concat(s, " timeout in ").concat(d, "ms"));
  3244. _this2.emit("actionResponseTimeout", {
  3245. error: _,
  3246. event: e,
  3247. tag: l
  3248. }), f(_), _this2.events.delete(r), _this2.off(r), logger.infoAndReportMeasurement({
  3249. metric: s,
  3250. tag: l,
  3251. extra: e.extra,
  3252. error: _,
  3253. startTime: u,
  3254. traceId: r
  3255. });
  3256. }, d);
  3257. }));
  3258. case 10:
  3259. case "end":
  3260. return _context.stop();
  3261. }
  3262. }
  3263. }, _callee, this);
  3264. }));
  3265. function track(_x, _x2) {
  3266. return _track.apply(this, arguments);
  3267. }
  3268. return track;
  3269. }()
  3270. }, {
  3271. key: "emitTraceIdToDecoder",
  3272. value: function emitTraceIdToDecoder(e) {
  3273. if (e.event === Actions.Rotation || e.event === Actions.Clicking || e.event === Actions.GetOnVehicle || e.event === Actions.GetOffVehicle) {
  3274. var t = {
  3275. [Actions.Rotation]: "Rotation",
  3276. [Actions.GetOnVehicle]: "GetOnVehicle",
  3277. [Actions.GetOffVehicle]: "GetOffVehicle",
  3278. [Actions.Clicking]: "MoveTo"
  3279. };
  3280. this.emit("traceId", {
  3281. traceId: e.traceId,
  3282. timestamp: Date.now(),
  3283. event: t[e.event]
  3284. });
  3285. }
  3286. }
  3287. }]);
  3288. return EventsManager;
  3289. }(EventEmitter);
  3290. var eventsManager = new EventsManager();
  3291. var ActionsHandler = /*#__PURE__*/function () {
  3292. function ActionsHandler(e) {
  3293. _classCallCheck(this, ActionsHandler);
  3294. this.currentActiveAction = null;
  3295. this.room = e;
  3296. }
  3297. _createClass(ActionsHandler, [{
  3298. key: "avatarComponentsSync",
  3299. value: function () {
  3300. var _avatarComponentsSync = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  3301. var t;
  3302. return regenerator.wrap(function _callee$(_context) {
  3303. while (1) {
  3304. switch (_context.prev = _context.next) {
  3305. case 0:
  3306. t = {
  3307. action_type: Actions$1.SetPlayerState,
  3308. set_player_state_action: {
  3309. player_state: {
  3310. avatar_components: JSON.stringify(e)
  3311. }
  3312. }
  3313. };
  3314. this.sendData({
  3315. data: t
  3316. });
  3317. case 2:
  3318. case "end":
  3319. return _context.stop();
  3320. }
  3321. }
  3322. }, _callee, this);
  3323. }));
  3324. function avatarComponentsSync(_x) {
  3325. return _avatarComponentsSync.apply(this, arguments);
  3326. }
  3327. return avatarComponentsSync;
  3328. }()
  3329. }, {
  3330. key: "sendData",
  3331. value: function () {
  3332. var _sendData = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  3333. var _this = this;
  3334. var t, _e$sampleRate, r, _e$timeout, n, o, a, s;
  3335. return regenerator.wrap(function _callee2$(_context2) {
  3336. while (1) {
  3337. switch (_context2.prev = _context2.next) {
  3338. case 0:
  3339. _context2.next = 2;
  3340. return this.beforeSend(e);
  3341. case 2:
  3342. t = uuid$1();
  3343. if (!(this.room.networkController.sendRtcData(le(oe({}, e.data), {
  3344. trace_id: t,
  3345. user_id: this.room.options.userId
  3346. })), e.track === !1)) {
  3347. _context2.next = 5;
  3348. break;
  3349. }
  3350. return _context2.abrupt("return", Promise.resolve(null));
  3351. case 5:
  3352. _e$sampleRate = e.sampleRate, r = _e$sampleRate === void 0 ? 1 : _e$sampleRate, _e$timeout = e.timeout, n = _e$timeout === void 0 ? 2e3 : _e$timeout, o = e.tag, a = e.data, s = e.special;
  3353. return _context2.abrupt("return", eventsManager.track({
  3354. timeout: n,
  3355. traceId: t,
  3356. event: a.action_type,
  3357. tag: o,
  3358. extra: a
  3359. }, {
  3360. special: s,
  3361. sampleRate: r,
  3362. noReport: this.room.viewMode === "serverless" || this.room.options.viewMode === "serverless"
  3363. }).finally(function () {
  3364. QueueActions.includes(e.data.action_type) && (_this.currentActiveAction = void 0);
  3365. }));
  3366. case 7:
  3367. case "end":
  3368. return _context2.stop();
  3369. }
  3370. }
  3371. }, _callee2, this);
  3372. }));
  3373. function sendData(_x2) {
  3374. return _sendData.apply(this, arguments);
  3375. }
  3376. return sendData;
  3377. }()
  3378. }, {
  3379. key: "beforeSend",
  3380. value: function () {
  3381. var _beforeSend = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  3382. var o, t, r;
  3383. return regenerator.wrap(function _callee3$(_context3) {
  3384. while (1) {
  3385. switch (_context3.prev = _context3.next) {
  3386. case 0:
  3387. t = (o = this.room._userAvatar) == null ? void 0 : o.isMoving, r = e.data.action_type;
  3388. if (!QueueActions.includes(r)) {
  3389. _context3.next = 5;
  3390. break;
  3391. }
  3392. if (!this.currentActiveAction) {
  3393. _context3.next = 4;
  3394. break;
  3395. }
  3396. return _context3.abrupt("return", (logger.error("".concat(Actions$1[this.currentActiveAction], " still pending, reject ").concat(Actions$1[r])), Promise.reject(new FrequencyLimitError("".concat(Actions$1[r], " action request frequency limit")))));
  3397. case 4:
  3398. this.currentActiveAction = r;
  3399. case 5:
  3400. if (!(t && QueueActions.includes(e.data.action_type))) {
  3401. _context3.next = 14;
  3402. break;
  3403. }
  3404. _context3.prev = 6;
  3405. _context3.next = 9;
  3406. return this.stopMoving();
  3407. case 9:
  3408. _context3.next = 14;
  3409. break;
  3410. case 11:
  3411. _context3.prev = 11;
  3412. _context3.t0 = _context3["catch"](6);
  3413. this.currentActiveAction = void 0, logger.error("before action stopMoving failed", _context3.t0);
  3414. case 14:
  3415. case "end":
  3416. return _context3.stop();
  3417. }
  3418. }
  3419. }, _callee3, this, [[6, 11]]);
  3420. }));
  3421. function beforeSend(_x3) {
  3422. return _beforeSend.apply(this, arguments);
  3423. }
  3424. return beforeSend;
  3425. }()
  3426. }, {
  3427. key: "moveTo",
  3428. value: function () {
  3429. var _moveTo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  3430. var t, _e$extra, r, n, o;
  3431. return regenerator.wrap(function _callee4$(_context4) {
  3432. while (1) {
  3433. switch (_context4.prev = _context4.next) {
  3434. case 0:
  3435. t = e.point, _e$extra = e.extra, r = _e$extra === void 0 ? "" : _e$extra, n = e.motionType, o = {
  3436. action_type: Actions$1.Clicking,
  3437. clicking_action: {
  3438. clicking_point: t,
  3439. clicking_type: ClickType.IgnoreView,
  3440. extra: encodeURIComponent(r),
  3441. attitude: n
  3442. },
  3443. clicking_state: this.room._currentClickingState
  3444. };
  3445. return _context4.abrupt("return", this.sendData({
  3446. data: o
  3447. }));
  3448. case 2:
  3449. case "end":
  3450. return _context4.stop();
  3451. }
  3452. }
  3453. }, _callee4, this);
  3454. }));
  3455. function moveTo(_x4) {
  3456. return _moveTo.apply(this, arguments);
  3457. }
  3458. return moveTo;
  3459. }()
  3460. }, {
  3461. key: "transfer",
  3462. value: function transfer(e) {
  3463. var _this2 = this;
  3464. var t = e.renderType,
  3465. r = e.player,
  3466. n = e.camera,
  3467. o = e.areaName,
  3468. a = e.attitude,
  3469. s = e.pathName,
  3470. l = e.person,
  3471. u = e.noMedia,
  3472. c = e.timeout,
  3473. h = e.tag,
  3474. f = e.special,
  3475. d = {
  3476. data: {
  3477. action_type: Actions$1.Transfer,
  3478. transfer_action: {
  3479. render_type: t,
  3480. player: r,
  3481. camera: n,
  3482. areaName: o,
  3483. attitude: a,
  3484. pathName: s,
  3485. person: {
  3486. type: l
  3487. },
  3488. noMedia: u,
  3489. tiles: [0, 1, 2, 4]
  3490. }
  3491. },
  3492. special: f,
  3493. timeout: c || 4e3,
  3494. tag: h
  3495. };
  3496. return this.sendData(d).then(function (_) {
  3497. return typeof l != "undefined" && _this2.room.updateCurrentNetworkOptions({
  3498. person: l,
  3499. rotationRenderType: t
  3500. }), _;
  3501. });
  3502. }
  3503. }, {
  3504. key: "changeRotationRenderType",
  3505. value: function changeRotationRenderType(e) {
  3506. var t = e.renderType,
  3507. r = e.player,
  3508. n = e.camera,
  3509. o = e.areaName,
  3510. a = e.attitude,
  3511. s = e.pathName;
  3512. return this.transfer({
  3513. renderType: t,
  3514. player: r,
  3515. camera: n,
  3516. areaName: o,
  3517. attitude: a,
  3518. pathName: s,
  3519. tag: "changeToRotationVideo"
  3520. });
  3521. }
  3522. }, {
  3523. key: "requestPanorama",
  3524. value: function requestPanorama(e, t, r) {
  3525. var n = e.camera,
  3526. o = e.player,
  3527. a = e.areaName,
  3528. s = e.attitude,
  3529. l = e.pathName,
  3530. u = e.tag;
  3531. return this.transfer({
  3532. renderType: RenderType.ClientRotationPano,
  3533. player: o,
  3534. camera: n,
  3535. person: Person.First,
  3536. areaName: a,
  3537. attitude: s,
  3538. pathName: l,
  3539. noMedia: t,
  3540. timeout: r,
  3541. tag: u || "requestPanorama",
  3542. special: !t
  3543. });
  3544. }
  3545. }, {
  3546. key: "setMotionType",
  3547. value: function setMotionType(e) {
  3548. return this.transfer({
  3549. attitude: e,
  3550. tag: "setMotionType"
  3551. });
  3552. }
  3553. }, {
  3554. key: "setNickName",
  3555. value: function setNickName(e) {
  3556. var t = {
  3557. action_type: Actions$1.ChangeNickname,
  3558. change_nickname_action: {
  3559. nickname: e
  3560. }
  3561. };
  3562. return this.sendData({
  3563. data: t
  3564. });
  3565. }
  3566. }, {
  3567. key: "getReserveSeat",
  3568. value: function getReserveSeat(_ref) {
  3569. var e = _ref.routeId,
  3570. t = _ref.name;
  3571. var r = {
  3572. action_type: Actions$1.ReserveSeat,
  3573. reserve_seat_action: {
  3574. route_id: e,
  3575. name: t
  3576. }
  3577. };
  3578. return this.sendData({
  3579. data: r
  3580. });
  3581. }
  3582. }, {
  3583. key: "getReserveStatus",
  3584. value: function getReserveStatus(_ref2) {
  3585. var e = _ref2.routeId,
  3586. t = _ref2.name,
  3587. r = _ref2.need_detail;
  3588. var n = {
  3589. action_type: Actions$1.GetReserveStatus,
  3590. get_reserve_status_action: {
  3591. route_id: e,
  3592. name: t,
  3593. need_detail: r
  3594. }
  3595. };
  3596. return this.sendData({
  3597. data: n,
  3598. timeout: 2e3
  3599. }).then(function (o) {
  3600. return o.reserveDetail;
  3601. });
  3602. }
  3603. }, {
  3604. key: "stopMoving",
  3605. value: function stopMoving() {
  3606. var e = {
  3607. action_type: Actions$1.StopMoving,
  3608. stop_move_action: {}
  3609. };
  3610. return this.sendData({
  3611. data: e
  3612. });
  3613. }
  3614. }, {
  3615. key: "getOnVehicle",
  3616. value: function getOnVehicle(_ref3) {
  3617. var e = _ref3.routeId,
  3618. t = _ref3.name,
  3619. r = _ref3.camera;
  3620. var n = {
  3621. action_type: Actions$1.GetOnVehicle,
  3622. get_on_vehicle_action: {
  3623. route_id: e,
  3624. name: t,
  3625. camera: r
  3626. }
  3627. };
  3628. return this.sendData({
  3629. data: n
  3630. });
  3631. }
  3632. }, {
  3633. key: "getOffVehicle",
  3634. value: function getOffVehicle(_ref4) {
  3635. var e = _ref4.renderType,
  3636. t = _ref4.player,
  3637. r = _ref4.camera;
  3638. var n = {
  3639. action_type: Actions$1.GetOffVehicle,
  3640. get_off_vehicle_action: {
  3641. render_type: e,
  3642. player: t,
  3643. camera: r
  3644. }
  3645. };
  3646. return this.sendData({
  3647. data: n
  3648. });
  3649. }
  3650. }, {
  3651. key: "confirmEvent",
  3652. value: function confirmEvent(e) {
  3653. var t = {
  3654. action_type: Actions$1.ConfirmEvent,
  3655. confirm_event_action: {
  3656. id: e
  3657. }
  3658. };
  3659. return this.sendData({
  3660. data: t,
  3661. track: !1
  3662. });
  3663. }
  3664. }, {
  3665. key: "echo",
  3666. value: function echo(e) {
  3667. var t = {
  3668. action_type: Actions$1.Echo,
  3669. echo_msg: {
  3670. echoMsg: e
  3671. }
  3672. };
  3673. return this.sendData({
  3674. data: t,
  3675. track: !1
  3676. });
  3677. }
  3678. }, {
  3679. key: "changeSkin",
  3680. value: function () {
  3681. var _changeSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  3682. var _this3 = this;
  3683. var t, r, n, _e$landingType, o, a, s, l, u, c, h, f, d, _, _e$roomTypeId, g, m, y, v;
  3684. return regenerator.wrap(function _callee6$(_context6) {
  3685. while (1) {
  3686. switch (_context6.prev = _context6.next) {
  3687. case 0:
  3688. t = e.special === void 0 ? e.renderType === RenderType.ClientRotationPano : e.special, r = e.skinId, n = e.mode, _e$landingType = e.landingType, o = _e$landingType === void 0 ? LandingType.Stay : _e$landingType, a = e.landingPoint, s = e.landingCamera, l = e.renderType, u = e.areaName, c = e.attitude, h = e.pathName, f = e.person, d = e.noMedia, _ = e.timeout, _e$roomTypeId = e.roomTypeId, g = _e$roomTypeId === void 0 ? "" : _e$roomTypeId, m = this.room.skinList.filter(function (y) {
  3689. return y.id === r;
  3690. })[0];
  3691. if (m) {
  3692. _context6.next = 4;
  3693. break;
  3694. }
  3695. y = "skin ".concat(r, " is invalid");
  3696. return _context6.abrupt("return", (logger.error(y), Promise.reject(new ParamError(y))));
  3697. case 4:
  3698. v = {
  3699. action_type: Actions$1.ChangeSkin,
  3700. change_skin_action: {
  3701. skinID: r,
  3702. mode: n === ChangeMode.Preview ? ChangeMode.Preview : ChangeMode.Confirm,
  3703. skin_data_version: r + m.versionId,
  3704. landing_type: o,
  3705. landing_point: a,
  3706. landing_camera: s,
  3707. render_wrapper: {
  3708. render_type: l
  3709. },
  3710. areaName: u,
  3711. attitude: c,
  3712. noMedia: d,
  3713. person: f,
  3714. pathName: h,
  3715. roomTypeId: g
  3716. }
  3717. };
  3718. return _context6.abrupt("return", this.sendData({
  3719. data: v,
  3720. timeout: _ || 6e3,
  3721. special: t
  3722. }).then( /*#__PURE__*/function () {
  3723. var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(y) {
  3724. var b, _ref6, T;
  3725. return regenerator.wrap(function _callee5$(_context5) {
  3726. while (1) {
  3727. switch (_context5.prev = _context5.next) {
  3728. case 0:
  3729. if (!(l === RenderType.ClientRotationPano && y)) {
  3730. _context5.next = 8;
  3731. break;
  3732. }
  3733. _context5.next = 3;
  3734. return _this3.room.modelManager.findRoute(r, h);
  3735. case 3:
  3736. b = _context5.sent;
  3737. _ref6 = getRandomItem(b.birthPointList) || {};
  3738. T = _ref6.camera;
  3739. _context5.next = 8;
  3740. return _this3.room.panorama.handleReceivePanorama(y, T);
  3741. case 8:
  3742. return _context5.abrupt("return", _this3.handleChangeSkin(e));
  3743. case 9:
  3744. case "end":
  3745. return _context5.stop();
  3746. }
  3747. }
  3748. }, _callee5);
  3749. }));
  3750. return function (_x6) {
  3751. return _ref5.apply(this, arguments);
  3752. };
  3753. }()).catch(function (y) {
  3754. return d ? _this3.handleChangeSkin(e) : Promise.reject(y);
  3755. }));
  3756. case 6:
  3757. case "end":
  3758. return _context6.stop();
  3759. }
  3760. }
  3761. }, _callee6, this);
  3762. }));
  3763. function changeSkin(_x5) {
  3764. return _changeSkin.apply(this, arguments);
  3765. }
  3766. return changeSkin;
  3767. }()
  3768. }, {
  3769. key: "handleChangeSkin",
  3770. value: function handleChangeSkin(e) {
  3771. var _this4 = this;
  3772. var t = e.skinId,
  3773. r = e.mode,
  3774. n = e.renderType,
  3775. o = e.areaName,
  3776. a = e.attitude,
  3777. s = e.pathName;
  3778. return this.room.sceneManager.staticmeshComponent.getCgMesh().show(), this.room.sceneManager.cameraComponent.switchToCgCamera(), this.room.engineProxy._updateSkinAssets(t).then(function () {
  3779. _this4.room.sceneManager.staticmeshComponent.getCgMesh().hide(), _this4.room.sceneManager.cameraComponent.switchToMainCamera(), _this4.room.pathManager.currentArea = o, logger.info("changeSkin _updateSkinAssets susccss"), _this4.room.updateCurrentNetworkOptions({
  3780. pathName: s,
  3781. attitude: a,
  3782. areaName: o
  3783. }), _this4.room.skinChangedHook(), _this4.room.emit("skinChanged", {
  3784. skin: {
  3785. id: t
  3786. },
  3787. mode: r
  3788. }), n === RenderType.ClientRotationPano && _this4.room.sceneManager.cameraComponent.allowMainCameraController();
  3789. });
  3790. }
  3791. }, {
  3792. key: "rotate",
  3793. value: function rotate(_ref7) {
  3794. var e = _ref7.pitch,
  3795. t = _ref7.yaw;
  3796. var n;
  3797. if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode)) return;
  3798. var r = {
  3799. action_type: Actions$1.Rotation,
  3800. rotation_action: {
  3801. vertical_move: e,
  3802. horizontal_move: -t
  3803. }
  3804. };
  3805. this.sendData({
  3806. data: r,
  3807. sampleRate: .02
  3808. });
  3809. }
  3810. }, {
  3811. key: "turnTo",
  3812. value: function turnTo(e) {
  3813. var _ref8 = e || {},
  3814. t = _ref8.point,
  3815. _ref8$timeout = _ref8.timeout,
  3816. r = _ref8$timeout === void 0 ? 2e3 : _ref8$timeout,
  3817. _ref8$offset = _ref8.offset,
  3818. n = _ref8$offset === void 0 ? 8 : _ref8$offset,
  3819. o = {
  3820. action_type: Actions$1.TurnTo,
  3821. turn_to_action: {
  3822. turn_to_point: t,
  3823. offset: n
  3824. }
  3825. };
  3826. return this.sendData({
  3827. data: o,
  3828. timeout: r
  3829. });
  3830. }
  3831. }, {
  3832. key: "rotateTo",
  3833. value: function rotateTo(e) {
  3834. var _ref9 = e || {},
  3835. t = _ref9.point,
  3836. _ref9$offset = _ref9.offset,
  3837. r = _ref9$offset === void 0 ? 0 : _ref9$offset,
  3838. _ref9$speed = _ref9.speed,
  3839. n = _ref9$speed === void 0 ? 3 : _ref9$speed,
  3840. o = {
  3841. action_type: Actions$1.RotateTo,
  3842. rotate_to_action: {
  3843. rotate_to_point: t,
  3844. offset: r,
  3845. speed: n
  3846. }
  3847. };
  3848. return this.sendData({
  3849. data: o
  3850. });
  3851. }
  3852. }, {
  3853. key: "broadcast",
  3854. value: function broadcast(e) {
  3855. var t = e.data,
  3856. _e$msgType = e.msgType,
  3857. r = _e$msgType === void 0 ? MessageHandleType.MHT_FollowListMulticast : _e$msgType,
  3858. n = e.targetUserIds;
  3859. if (r === MessageHandleType.MHT_CustomTargetSync && !Array.isArray(n)) return Promise.reject(new ParamError("param targetUserIds is required when msgType is ".concat(MessageHandleType[r])));
  3860. var o = {
  3861. action_type: Actions$1.Broadcast,
  3862. broadcast_action: {
  3863. data: JSON.stringify(t),
  3864. user_id: this.room.options.userId,
  3865. msgType: r
  3866. }
  3867. };
  3868. return Array.isArray(n) && r === MessageHandleType.MHT_CustomTargetSync && (o.broadcast_action.target_user_ids = n), this.room.actionsHandler.sendData({
  3869. data: o,
  3870. tag: t.broadcastType
  3871. });
  3872. }
  3873. }, {
  3874. key: "getNeighborPoints",
  3875. value: function getNeighborPoints(e) {
  3876. var t = e.point,
  3877. _e$containSelf = e.containSelf,
  3878. r = _e$containSelf === void 0 ? !1 : _e$containSelf,
  3879. _e$searchRange = e.searchRange,
  3880. n = _e$searchRange === void 0 ? 500 : _e$searchRange,
  3881. o = {
  3882. action_type: Actions$1.GetNeighborPoints,
  3883. get_neighbor_points_action: {
  3884. point: t,
  3885. level: 1,
  3886. containSelf: r,
  3887. searchRange: n
  3888. }
  3889. };
  3890. return this.sendData({
  3891. data: o
  3892. }).then(function (a) {
  3893. return a.nps;
  3894. });
  3895. }
  3896. }, {
  3897. key: "playCG",
  3898. value: function playCG(e) {
  3899. var t = {
  3900. action_type: Actions$1.PlayCG,
  3901. play_cg_action: {
  3902. cg_name: e
  3903. }
  3904. };
  3905. return this.sendData({
  3906. data: t
  3907. });
  3908. }
  3909. }, {
  3910. key: "audienceToVisitor",
  3911. value: function audienceToVisitor(e) {
  3912. var t = e.avatarId,
  3913. r = e.avatarComponents,
  3914. n = e.player,
  3915. o = e.camera,
  3916. a = {
  3917. action_type: Actions$1.AudienceChangeToVisitor,
  3918. audienceChangeToVisitorAction: {
  3919. avatarID: t,
  3920. avatarComponents: r,
  3921. player: n,
  3922. camera: o
  3923. }
  3924. };
  3925. return logger.debug("send data: audience to visitor"), this.sendData({
  3926. data: a
  3927. });
  3928. }
  3929. }, {
  3930. key: "visitorToAudience",
  3931. value: function visitorToAudience(e) {
  3932. var t = e.renderType,
  3933. r = e.player,
  3934. n = e.camera,
  3935. o = e.areaName,
  3936. a = e.attitude,
  3937. s = e.pathName,
  3938. l = e.person,
  3939. u = e.noMedia,
  3940. c = {
  3941. action_type: Actions$1.VisitorChangeToAudience,
  3942. visitorChangeToAudienceAction: {
  3943. transferAction: {
  3944. render_type: t,
  3945. player: r,
  3946. camera: n,
  3947. areaName: o,
  3948. attitude: a,
  3949. pathName: s,
  3950. person: {
  3951. type: l
  3952. },
  3953. noMedia: u,
  3954. tiles: [0, 1, 2, 4]
  3955. }
  3956. }
  3957. };
  3958. return logger.debug("send data: visitor to audience"), this.sendData({
  3959. data: c
  3960. });
  3961. }
  3962. }, {
  3963. key: "removeVisitor",
  3964. value: function removeVisitor(e) {
  3965. var t = e.removeType,
  3966. r = e.userIDList,
  3967. _e$extraInfo = e.extraInfo,
  3968. n = _e$extraInfo === void 0 ? "" : _e$extraInfo,
  3969. o = {
  3970. action_type: Actions$1.RemoveVisitor,
  3971. removeVisitorAction: {
  3972. removeVisitorEvent: t,
  3973. userIDList: r,
  3974. extraInfo: encodeURIComponent(n)
  3975. }
  3976. };
  3977. return logger.debug("send data: remove visitor"), this.sendData({
  3978. data: o
  3979. });
  3980. }
  3981. }, {
  3982. key: "getUserWithAvatar",
  3983. value: function getUserWithAvatar(e, t) {
  3984. var r = {
  3985. action_type: Actions$1.GetUserWithAvatar,
  3986. getUserWithAvatarAction: {
  3987. userType: e,
  3988. roomID: t
  3989. }
  3990. };
  3991. return logger.debug("send data: get user with avatar"), this.sendData({
  3992. data: r
  3993. }).then(function (n) {
  3994. return n.userWithAvatarList;
  3995. });
  3996. }
  3997. }, {
  3998. key: "joystick",
  3999. value: function joystick(e) {
  4000. var t = e.degree,
  4001. _e$level = e.level,
  4002. r = _e$level === void 0 ? 1 : _e$level,
  4003. n = uuid$1();
  4004. var o = -t + 90 + 360;
  4005. o >= 360 && (o -= 360);
  4006. var a = {
  4007. action_type: Actions$1.Joystick,
  4008. dir_action: {
  4009. move_angle: o,
  4010. speed_level: r
  4011. },
  4012. trace_id: n,
  4013. user_id: this.room.options.userId,
  4014. packet_id: n
  4015. };
  4016. return this.sendData({
  4017. data: a,
  4018. track: !1
  4019. });
  4020. }
  4021. }]);
  4022. return ActionsHandler;
  4023. }();
  4024. var Signal = /*#__PURE__*/function () {
  4025. function Signal(e) {
  4026. _classCallCheck(this, Signal);
  4027. this.signalHandleActived = !0;
  4028. this.isUpdatedYUV = !0;
  4029. this._room = e;
  4030. }
  4031. _createClass(Signal, [{
  4032. key: "handleSignal",
  4033. value: function handleSignal(e) {
  4034. var _this = this;
  4035. var a, s, l;
  4036. if (!this.signalHandleActived) return;
  4037. var t = e.signal,
  4038. r = e.alreadyUpdateYUV;
  4039. if (this.handleActionResponses(t), this._room.handleSignalHook(t), !r) {
  4040. var u = (a = t.newUserStates) == null ? void 0 : a.find(function (c) {
  4041. return c.userId === _this._room.userId;
  4042. });
  4043. if ((u == null ? void 0 : u.renderInfo) && ((s = this._room._userAvatar) == null ? void 0 : s.isMoving)) {
  4044. logger.debug("stream stoped, make avatar to stop");
  4045. var _u$renderInfo = u.renderInfo,
  4046. c = _u$renderInfo.isMoving,
  4047. h = _u$renderInfo.isRotating;
  4048. this._room.avatarManager._updateAvatarMovingStatus({
  4049. id: u.userId,
  4050. isMoving: !!c,
  4051. isRotating: !!h
  4052. });
  4053. }
  4054. return;
  4055. }
  4056. this.isUpdatedYUV = r;
  4057. var n = t;
  4058. if (!t) {
  4059. logger.warn("metadata signal is empty");
  4060. return;
  4061. }
  4062. if (n.code === Codes.RepeatLogin) {
  4063. this._room.handleRepetLogin();
  4064. return;
  4065. }
  4066. n.code !== void 0 && n.code !== Codes.Success && n.code !== Codes.ActionMaybeDelay && n.code !== Codes.DoActionBlocked && n.code !== Codes.GetOnVehicle && (logger.error("signal errcode: ", n), this._room.emit("error", n));
  4067. var o = (l = n.newUserStates) == null ? void 0 : l.find(function (u) {
  4068. return u.userId === _this._room.userId;
  4069. });
  4070. if (n.broadcastAction) try {
  4071. var _u = JSON.parse(n.broadcastAction.data);
  4072. Broadcast.handlers.forEach(function (c) {
  4073. return c(_u);
  4074. });
  4075. } catch (u) {
  4076. logger.error(u);
  4077. }
  4078. if (n.newUserStates && n.newUserStates.length > 0 && this._room.avatarManager.handleAvatar(n), o != null && o.playerState) {
  4079. this._room._currentClickingState = o.playerState;
  4080. var _o$playerState = o.playerState,
  4081. _u2 = _o$playerState.pathName,
  4082. _c = _o$playerState.attitude,
  4083. _h = _o$playerState.areaName,
  4084. f = _o$playerState.skinId;
  4085. if (_u2 && (this._room.pathManager.currentPathName = _u2, this._room.updateCurrentState({
  4086. pathName: _u2
  4087. })), f && this.udpateSkinInfo(f), _h && this._room.updateCurrentState({
  4088. areaName: _h
  4089. }), _c) {
  4090. var d = this._room.skin.routeList.find(function (g) {
  4091. return g.areaName === _this._room.currentState.areaName;
  4092. }),
  4093. _ = ((d == null ? void 0 : d.step) || 7.5) * 30;
  4094. this._room.updateCurrentState({
  4095. speed: _,
  4096. attitude: _c
  4097. }), this._room.pathManager.currentAttitude = _c, this._room._userAvatar && (this._room._userAvatar.motionType = _c);
  4098. }
  4099. this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano && !this._room.isPano && o.playerState.camera && this._room.camera.setCameraPose(o.playerState.camera);
  4100. }
  4101. if (o != null && o.renderInfo && this._room.camera.handleRenderInfo(o), n.actionType !== void 0) {
  4102. var _u3 = n.actionType,
  4103. _c2 = n.code,
  4104. _h2 = n.echoMsg,
  4105. _f = n.traceId;
  4106. _u3 === Actions.Echo && _c2 === Codes.Success && this._room.networkController.rtcp.heartbeat.pong(_h2, _f), _c2 !== Codes.Success ? eventsManager.remove(_f, _c2) : [Actions.GetReserveStatus, Actions.Broadcast, Actions.ChangeNickname, Actions.ConfirmEvent, Actions.ReserveSeat, Actions.Rotation, Actions.TurnTo, Actions.RotateTo, Actions.SetPlayerState, Actions.GetNeighborPoints, Actions.TurnToFace, Actions.AudienceChangeToVisitor, Actions.RemoveVisitor, Actions.GetUserWithAvatar].includes(_u3) && eventsManager.remove(_f, _c2, n);
  4107. }
  4108. }
  4109. }, {
  4110. key: "handleActionResponses",
  4111. value: function handleActionResponses(e) {
  4112. var _this2 = this;
  4113. !(e != null && e.actionResponses) || e.actionResponses.length === 0 || e.actionResponses.forEach(function (t) {
  4114. if (t.actionType == null) return;
  4115. var r = t.pointType,
  4116. n = t.extra,
  4117. o = t.actionType,
  4118. a = t.traceId,
  4119. s = t.code,
  4120. l = t.msg;
  4121. o === Actions.GetNeighborPoints ? eventsManager.remove(a, s, t.nps) : o === Actions.GetUserWithAvatar ? eventsManager.remove(a, s, t.userWithAvatarList) : eventsManager.remove(a, s, l), r === PointType.Path && o === Actions.Clicking && (_this2._room.moveToExtra = decodeURIComponent(n));
  4122. });
  4123. }
  4124. }, {
  4125. key: "udpateSkinInfo",
  4126. value: function () {
  4127. var _udpateSkinInfo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  4128. var t;
  4129. return regenerator.wrap(function _callee$(_context) {
  4130. while (1) {
  4131. switch (_context.prev = _context.next) {
  4132. case 0:
  4133. this._room.updateCurrentState({
  4134. skinId: e
  4135. });
  4136. _context.next = 3;
  4137. return this._room.skinList.find(function (r) {
  4138. return r.id === e;
  4139. });
  4140. case 3:
  4141. t = _context.sent;
  4142. t && this._room.updateCurrentState({
  4143. skin: t
  4144. });
  4145. case 5:
  4146. case "end":
  4147. return _context.stop();
  4148. }
  4149. }
  4150. }, _callee, this);
  4151. }));
  4152. function udpateSkinInfo(_x) {
  4153. return _udpateSkinInfo.apply(this, arguments);
  4154. }
  4155. return udpateSkinInfo;
  4156. }()
  4157. }]);
  4158. return Signal;
  4159. }();
  4160. function _createSuper$b(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$b(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  4161. function _isNativeReflectConstruct$b() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  4162. var XverseEffectManager = /*#__PURE__*/function (_EventEmitter) {
  4163. _inherits(XverseEffectManager, _EventEmitter);
  4164. var _super = _createSuper$b(XverseEffectManager);
  4165. function XverseEffectManager(e) {
  4166. var _this;
  4167. _classCallCheck(this, XverseEffectManager);
  4168. _this = _super.call(this);
  4169. E(_assertThisInitialized(_this), "effects", new Map());
  4170. E(_assertThisInitialized(_this), "room");
  4171. _this.room = e;
  4172. return _this;
  4173. }
  4174. _createClass(XverseEffectManager, [{
  4175. key: "addEffect",
  4176. value: function () {
  4177. var _addEffect = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  4178. var o, t, r, _e$type, n, a;
  4179. return regenerator.wrap(function _callee$(_context) {
  4180. while (1) {
  4181. switch (_context.prev = _context.next) {
  4182. case 0:
  4183. t = e.jsonPath, r = e.id, _e$type = e.type, n = _e$type === void 0 ? IEffectType.SubSequence : _e$type;
  4184. _context.prev = 1;
  4185. this.effects.get(r) && ((o = this.effects.get(r)) == null || o.dispose());
  4186. a = new Ae.subEffect({
  4187. id: r,
  4188. jsonPath: t,
  4189. type: n,
  4190. room: this.room
  4191. });
  4192. this.effects.set(r, a);
  4193. _context.next = 7;
  4194. return a.init();
  4195. case 7:
  4196. return _context.abrupt("return", a);
  4197. case 10:
  4198. _context.prev = 10;
  4199. _context.t0 = _context["catch"](1);
  4200. return _context.abrupt("return", (this.effects.delete(r), logger.error(_context.t0), Promise.reject(_context.t0)));
  4201. case 13:
  4202. case "end":
  4203. return _context.stop();
  4204. }
  4205. }
  4206. }, _callee, this, [[1, 10]]);
  4207. }));
  4208. function addEffect(_x) {
  4209. return _addEffect.apply(this, arguments);
  4210. }
  4211. return addEffect;
  4212. }()
  4213. }, {
  4214. key: "clearEffects",
  4215. value: function clearEffects() {
  4216. var _this2 = this;
  4217. this.effects.forEach(function (e) {
  4218. e.dispose(), _this2.effects.delete(e.id);
  4219. });
  4220. }
  4221. }, {
  4222. key: "removeEffect",
  4223. value: function removeEffect(e) {
  4224. var t = this.effects.get(e);
  4225. t == null || t.dispose(), t && this.effects.delete(t.id);
  4226. }
  4227. }]);
  4228. return XverseEffectManager;
  4229. }(EventEmitter);
  4230. var MotionType$1 = {
  4231. Walk: 'walk',
  4232. Run: 'run',
  4233. Fly: 'fly'
  4234. };
  4235. var Heartbeat = /*#__PURE__*/function () {
  4236. function Heartbeat(e) {
  4237. var _this = this;
  4238. _classCallCheck(this, Heartbeat);
  4239. E(this, "_interval", null);
  4240. E(this, "ping", function () {
  4241. var e = Date.now().toString();
  4242. _this.handler.ping(e);
  4243. });
  4244. this.handler = e;
  4245. }
  4246. _createClass(Heartbeat, [{
  4247. key: "ping",
  4248. value: function ping() {
  4249. var e = Date.now().toString();
  4250. this.handler.ping(e);
  4251. }
  4252. }, {
  4253. key: "start",
  4254. value: function start() {
  4255. this.stop(), logger.debug("Setting ping interval to ".concat(PING_INTERVAL_MS, "ms")), this._interval = window.setInterval(this.ping, PING_INTERVAL_MS);
  4256. }
  4257. }, {
  4258. key: "stop",
  4259. value: function stop() {
  4260. logger.debug("stop heartbeat"), this._interval && window.clearInterval(this._interval);
  4261. }
  4262. }, {
  4263. key: "pong",
  4264. value: function pong(e, t) {
  4265. !e || typeof e == "string" && this.handler.pong(Date.now() - Number(e), t);
  4266. }
  4267. }]);
  4268. return Heartbeat;
  4269. }();
  4270. var Timeout$1 = /*#__PURE__*/function () {
  4271. function Timeout(e, t) {
  4272. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !0;
  4273. _classCallCheck(this, Timeout);
  4274. this._timeout = null;
  4275. this._fn = e, this._delay = t, r && this.start();
  4276. }
  4277. _createClass(Timeout, [{
  4278. key: "delay",
  4279. get: function get() {
  4280. return this._delay;
  4281. }
  4282. }, {
  4283. key: "isSet",
  4284. get: function get() {
  4285. return !!this._timeout;
  4286. }
  4287. }, {
  4288. key: "setDelay",
  4289. value: function setDelay(e) {
  4290. this._delay = e;
  4291. }
  4292. }, {
  4293. key: "start",
  4294. value: function start() {
  4295. var _this = this;
  4296. this.isSet || (this._timeout = window.setTimeout(function () {
  4297. var e = _this._fn;
  4298. _this.clear(), e();
  4299. }, this._delay));
  4300. }
  4301. }, {
  4302. key: "clear",
  4303. value: function clear() {
  4304. window.clearTimeout(this._timeout), this._timeout = void 0;
  4305. }
  4306. }, {
  4307. key: "reset",
  4308. value: function reset() {
  4309. this.clear(), this.start();
  4310. }
  4311. }]);
  4312. return Timeout;
  4313. }();
  4314. function _createSuper$a(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$a(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  4315. function _isNativeReflectConstruct$a() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  4316. var InitNetworkTimeoutError = /*#__PURE__*/function (_XverseError) {
  4317. _inherits(InitNetworkTimeoutError, _XverseError);
  4318. var _super = _createSuper$a(InitNetworkTimeoutError);
  4319. function InitNetworkTimeoutError(e) {
  4320. _classCallCheck(this, InitNetworkTimeoutError);
  4321. return _super.call(this, 1007, e || "\u7F51\u7EDC\u521D\u59CB\u5316\u8D85\u65F6");
  4322. }
  4323. return _createClass(InitNetworkTimeoutError);
  4324. }(XverseError);
  4325. function _createSuper$9(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$9(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  4326. function _isNativeReflectConstruct$9() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  4327. var Socket = /*#__PURE__*/function (_EventEmitter) {
  4328. _inherits(Socket, _EventEmitter);
  4329. var _super = _createSuper$9(Socket);
  4330. function Socket(e) {
  4331. var _this;
  4332. _classCallCheck(this, Socket);
  4333. _this = _super.call(this);
  4334. E(_assertThisInitialized(_this), "_ws");
  4335. E(_assertThisInitialized(_this), "_openTimer");
  4336. E(_assertThisInitialized(_this), "connected", !1);
  4337. E(_assertThisInitialized(_this), "_hasTimeout", !1);
  4338. E(_assertThisInitialized(_this), "heartbeat");
  4339. E(_assertThisInitialized(_this), "latency", function (e, t) {
  4340. return _this.send({
  4341. id: "checkLatency",
  4342. data: JSON.stringify(e),
  4343. packet_id: t
  4344. });
  4345. });
  4346. E(_assertThisInitialized(_this), "send", function (e) {
  4347. if (_this.wsNoReady()) return;
  4348. var t = JSON.stringify(e);
  4349. e.id !== "heartbeat" && logger.info("send ws frame", t), _this._ws.send(t);
  4350. });
  4351. E(_assertThisInitialized(_this), "startGame", function () {
  4352. var _this$network$room$cu = _this.network.room.currentNetworkOptions,
  4353. e = _this$network$room$cu.roomId,
  4354. t = _this$network$room$cu.userId,
  4355. r = _this$network$room$cu.avatarId,
  4356. n = _this$network$room$cu.skinId,
  4357. o = _this$network$room$cu.role,
  4358. a = _this$network$room$cu.avatarComponents,
  4359. s = _this$network$room$cu.versionId,
  4360. l = _this$network$room$cu.rotationRenderType,
  4361. u = _this$network$room$cu.isAllSync,
  4362. c = _this$network$room$cu.nickname,
  4363. h = _this$network$room$cu.avatarScale,
  4364. f = _this$network$room$cu.appId,
  4365. d = _this$network$room$cu.camera,
  4366. _ = _this$network$room$cu.player,
  4367. g = _this$network$room$cu.firends,
  4368. m = _this$network$room$cu.syncByEvent,
  4369. v = _this$network$room$cu.areaName,
  4370. y = _this$network$room$cu.attitude,
  4371. b = _this$network$room$cu.pathName,
  4372. T = _this$network$room$cu.person,
  4373. _this$network$room$cu2 = _this$network$room$cu.roomTypeId,
  4374. C = _this$network$room$cu2 === void 0 ? "" : _this$network$room$cu2,
  4375. A = _this$network$room$cu.syncToOthers,
  4376. S = _this$network$room$cu.hasAvatar,
  4377. P = _this$network$room$cu.prioritySync,
  4378. _this$network$room$cu3 = _this$network$room$cu.extra,
  4379. R = _this$network$room$cu3 === void 0 ? {} : _this$network$room$cu3,
  4380. M = _this$network$room$cu.removeWhenDisconnected;
  4381. R.removeWhenDisconnected = M;
  4382. var x = {
  4383. id: "start",
  4384. room_id: e,
  4385. user_id: t,
  4386. trace_id: uuid$1(),
  4387. data: JSON.stringify({
  4388. avatar_components: JSON.stringify(a),
  4389. avatar_id: r,
  4390. skin_id: n,
  4391. is_host: o ? o == "host" : !0,
  4392. skin_data_version: n !== void 0 && s !== void 0 ? n + s : void 0,
  4393. rotation_render_type: l,
  4394. is_all_sync: u,
  4395. nick_name: encodeURIComponent(c || ""),
  4396. app_id: f,
  4397. camera: d,
  4398. player: _,
  4399. person: T,
  4400. firends: JSON.stringify(g),
  4401. sync_by_event: m,
  4402. area_name: v,
  4403. path_name: b,
  4404. attitude: y,
  4405. room_type_id: C,
  4406. syncToOthers: A,
  4407. hasAvatar: S,
  4408. avatarSize: h,
  4409. prioritySync: P,
  4410. extra: JSON.stringify(R)
  4411. })
  4412. };
  4413. _this.send(x), logger.warn("startGame", le(oe({}, x), {
  4414. data: JSON.parse(x.data)
  4415. }));
  4416. });
  4417. _this.network = e, _this.heartbeat = new Heartbeat({
  4418. ping: function ping(t) {
  4419. var r;
  4420. if (!_this.connected) {
  4421. _this.heartbeat.stop(), (r = e.room.stats) == null || r.assign({
  4422. rtt: 0
  4423. });
  4424. return;
  4425. }
  4426. _this.send({
  4427. id: "heartbeat",
  4428. data: t
  4429. });
  4430. },
  4431. pong(t) {
  4432. var r;
  4433. (r = e.room.stats) == null || r.assign({
  4434. rtt: t
  4435. });
  4436. }
  4437. });
  4438. return _this;
  4439. }
  4440. _createClass(Socket, [{
  4441. key: "connection",
  4442. get: function get() {
  4443. return this._ws;
  4444. }
  4445. }, {
  4446. key: "start",
  4447. value: function start() {
  4448. var _this2 = this;
  4449. this._hasTimeout = !1;
  4450. var e = this.getAddress();
  4451. logger.info("connecting to ".concat(e));
  4452. var t = Date.now();
  4453. this._ws = new WebSocket(e), this._openTimer = new Timeout$1(function () {
  4454. var r = "Failed to open websocket in ".concat(DEFAULT_OPEN_TIMEOUT_MS, " ms");
  4455. _this2._hasTimeout = !0, _this2.emit("socketClosed", new InitNetworkTimeoutError(r));
  4456. }, DEFAULT_OPEN_TIMEOUT_MS), this._ws.onopen = function () {
  4457. var r;
  4458. (r = _this2._openTimer) == null || r.clear(), _this2.connected = !0, _this2.heartbeat.start(), _this2.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
  4459. metric: "wsOpenedAt",
  4460. group: "joinRoom",
  4461. startTime: _this2.network.room._startTime
  4462. }), logger.infoAndReportMeasurement({
  4463. metric: "wsOpenedCost",
  4464. group: "joinRoom",
  4465. startTime: t
  4466. }));
  4467. }, this.handleWSEvent();
  4468. }
  4469. }, {
  4470. key: "getAddress",
  4471. value: function getAddress() {
  4472. var _this$network$room$cu4 = this.network.room.currentNetworkOptions,
  4473. e = _this$network$room$cu4.wsServerUrl,
  4474. t = _this$network$room$cu4.reconnect,
  4475. r = _this$network$room$cu4.sessionId,
  4476. n = _this$network$room$cu4.token,
  4477. o = _this$network$room$cu4.roomId,
  4478. a = _this$network$room$cu4.userId,
  4479. s = _this$network$room$cu4.pageSession,
  4480. l = this.network.room.skinId;
  4481. var u = e;
  4482. t && (u = u + "?reconnect=true&lastSessionID=".concat(r));
  4483. var c = "userId=".concat(a, "&roomId=").concat(o, "&pageSession=").concat(s) + (this.network.room.isHost ? "&skinId=".concat(l) : "") + (n ? "&token=".concat(n) : "");
  4484. return u = u.indexOf("?") > -1 ? u + "&" + c : u + "?" + c, u;
  4485. }
  4486. }, {
  4487. key: "handleWSEvent",
  4488. value: function handleWSEvent() {
  4489. var _this3 = this;
  4490. var e = this._ws;
  4491. e.addEventListener("error", function (t) {
  4492. _this3.connected = !1, logger.error("webscoket error", t), _this3.emit("socketClosed", new InternalError("connect to address error: " + _this3.network.room.currentNetworkOptions.wsServerUrl));
  4493. }), e.addEventListener("close", function (t) {
  4494. _this3.connected = !1, _this3._onClose(t);
  4495. }), e.addEventListener("message", function (t) {
  4496. if (!t || _this3._hasTimeout || !_this3.connected) return;
  4497. var r = null;
  4498. try {
  4499. r = JSON.parse(t.data);
  4500. } catch (o) {
  4501. logger.error(o);
  4502. return;
  4503. }
  4504. if (!r) return;
  4505. var n = r.id;
  4506. if (!!n) switch (n !== "heartbeat" && logger.info("receive ws frame: ".concat(t.data)), n) {
  4507. case "fail":
  4508. break;
  4509. case "init":
  4510. try {
  4511. var o = r.data.slice(-37, -1);
  4512. reporter$1.updateBody({
  4513. serverSession: o
  4514. });
  4515. } catch (o) {
  4516. console.error(o);
  4517. }
  4518. _this3.network.rtcp.start();
  4519. break;
  4520. case "heartbeat":
  4521. _this3.heartbeat.pong(r.data);
  4522. break;
  4523. case "offer":
  4524. _this3.network.rtcp.setRemoteDescription(r.data, _this3.network.stream.el);
  4525. break;
  4526. case "ice_candidate":
  4527. _this3.network.rtcp.addCandidate(r.data);
  4528. break;
  4529. case "start":
  4530. _this3.emit("gameRoomAvailable", r);
  4531. break;
  4532. case "error":
  4533. try {
  4534. var _JSON$parse = JSON.parse(r.data),
  4535. _o = _JSON$parse.Code,
  4536. a = _JSON$parse.Msg;
  4537. if (_o) {
  4538. if (_o == 3003) return _this3.emit("socketClosed", new TokenExpiredError());
  4539. if (authenticationErrorCodes.indexOf(_o) > -1) return _this3.emit("socketClosed", new AuthenticationError("\u9274\u6743\u9519\u8BEF:" + a));
  4540. {
  4541. var s = getErrorByCode(_o);
  4542. _this3.emit("socketClosed", new s(a));
  4543. }
  4544. }
  4545. } catch (o) {
  4546. logger.error(o), _this3.emit("socketClosed", new InternalError(r.data));
  4547. }
  4548. break;
  4549. case "checkLatency":
  4550. {
  4551. var _o2 = r.packet_id,
  4552. _a = r.data.split(",");
  4553. _this3.onLatencyCheck({
  4554. packetId: _o2,
  4555. addresses: _a
  4556. });
  4557. break;
  4558. }
  4559. default:
  4560. logger.warn("unkown ws message type", n, r);
  4561. }
  4562. });
  4563. }
  4564. }, {
  4565. key: "onLatencyCheck",
  4566. value: function onLatencyCheck(e) {
  4567. var _this4 = this;
  4568. var t = _toConsumableArray(new Set(e.addresses || []));
  4569. Promise.all(t.map(function (r) {
  4570. return {
  4571. [r]: 9999
  4572. };
  4573. })).then(function (r) {
  4574. var n = Object.assign.apply(Object, [{}].concat(_toConsumableArray(r)));
  4575. _this4.latency(n, e.packetId);
  4576. });
  4577. }
  4578. }, {
  4579. key: "wsNoReady",
  4580. value: function wsNoReady() {
  4581. return this._ws.readyState == WebSocket.CLOSED || this._ws.readyState == WebSocket.CLOSING || this._ws.readyState == WebSocket.CONNECTING;
  4582. }
  4583. }, {
  4584. key: "prepareReconnect",
  4585. value: function prepareReconnect() {
  4586. this._close({
  4587. code: WS_CLOSE_RECONNECT,
  4588. reason: "reconnect"
  4589. });
  4590. }
  4591. }, {
  4592. key: "_onClose",
  4593. value: function _onClose(_ref) {
  4594. var e = _ref.code,
  4595. t = _ref.reason;
  4596. this._openTimer && this._openTimer.clear(), logger.warn("ws closed: ".concat(e, " ") + t), [WS_CLOSE_RECONNECT, WS_CLOSE_NORMAL].includes(e) || this.emit("socketClosed", new InternalError("Websocket error"));
  4597. }
  4598. }, {
  4599. key: "_close",
  4600. value: function _close(_ref2) {
  4601. var e = _ref2.code,
  4602. t = _ref2.reason;
  4603. var r;
  4604. (r = this._ws) == null || r.close(e, t);
  4605. }
  4606. }, {
  4607. key: "quit",
  4608. value: function quit() {
  4609. this._close({
  4610. code: WS_CLOSE_NORMAL,
  4611. reason: "quit"
  4612. });
  4613. }
  4614. }]);
  4615. return Socket;
  4616. }(EventEmitter);
  4617. function add(i, e) {
  4618. return e == -1 && (e = 0), i + e;
  4619. }
  4620. function max(i, e) {
  4621. return Math.max(i, e);
  4622. }
  4623. function count_sd(i, e) {
  4624. function t(r, n) {
  4625. var o = 0;
  4626. return n == -1 ? o = 0 : o = (n - e) * (n - e), r + o;
  4627. }
  4628. return Math.sqrt(i.reduce(t, 0) / i.reduce(count_valid, 0)) || 0;
  4629. }
  4630. function count_valid(i, e) {
  4631. var t = 0;
  4632. return e != -1 && (t = 1), i + t;
  4633. }
  4634. function count_less(i, e) {
  4635. function t(r, n) {
  4636. var o = 0;
  4637. return n != -1 && n < e && (o = 1), r + o;
  4638. }
  4639. return i.reduce(t, 0);
  4640. }
  4641. var CircularArray$1 = /*#__PURE__*/function () {
  4642. function CircularArray(e, t, r) {
  4643. _classCallCheck(this, CircularArray);
  4644. this.sum = 0, this.incomingSum = 0, this.count = 0, this.incomingCount = 0, this.max = 0, this.incomingMax = 0, this.goodLess = 0, this.wellLess = 0, this.fairLess = 0, this.badLess = 0, this.countLess = !1, this.lessThreshes = [], this.incomingData = [], this.circularData = Array(e).fill(-1), this.circularPtr = 0, this.circularLength = e, t && (this.countLess = !0, this.lessThreshes = r);
  4645. }
  4646. _createClass(CircularArray, [{
  4647. key: "add",
  4648. value: function add(e) {
  4649. this.circularData[this.circularPtr] != -1 ? (this.sum -= this.circularData[this.circularPtr], Math.abs(this.circularData[this.circularPtr] - this.max) < .01 && (this.circularData[this.circularPtr] = -1, this.max = this.getMax(!1))) : this.count += 1, this.sum += e, this.incomingSum += e, this.incomingCount += 1, this.max < e && (this.max = e), this.incomingMax < e && (this.incomingMax = e), this.circularData[this.circularPtr] = e, this.circularPtr = (this.circularPtr + 1) % this.circularLength, this.incomingData.push(e), this.incomingData.length > this.circularLength && (this.clearIncoming(), this.incomingCount = 0, this.incomingSum = 0);
  4650. }
  4651. }, {
  4652. key: "computeAvg",
  4653. value: function computeAvg(e) {
  4654. return e.reduce(add, 0) / e.reduce(count_valid, 0) || 0;
  4655. }
  4656. }, {
  4657. key: "computeMax",
  4658. value: function computeMax(e) {
  4659. return e.reduce(max, 0) || 0;
  4660. }
  4661. }, {
  4662. key: "computeThreshPercent",
  4663. value: function computeThreshPercent(e) {
  4664. if (this.countLess) {
  4665. var t = count_less(e, this.lessThreshes[0]) || 0,
  4666. r = count_less(e, this.lessThreshes[1]) || 0,
  4667. n = count_less(e, this.lessThreshes[2]) || 0,
  4668. o = count_less(e, this.lessThreshes[3]) || 0,
  4669. a = e.reduce(count_valid, 0);
  4670. return [t, r, n, o, a];
  4671. } else return [0, 0, 0, 0, 0];
  4672. }
  4673. }, {
  4674. key: "getAvg",
  4675. value: function getAvg() {
  4676. var e = this.sum / this.count || 0,
  4677. t = this.computeAvg(this.circularData) || 0;
  4678. return Math.abs(e - t) > .01 && console.error("avg value mismatch: ", e, t), this.computeAvg(this.circularData) || 0;
  4679. }
  4680. }, {
  4681. key: "getMax",
  4682. value: function getMax() {
  4683. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  4684. var t = this.computeMax(this.circularData) || 0;
  4685. return e && Math.abs(t - this.max) > .01 && console.error("max value mismatch: ", this.max, t), this.computeMax(this.circularData) || 0;
  4686. }
  4687. }, {
  4688. key: "getStandardDeviation",
  4689. value: function getStandardDeviation() {
  4690. return count_sd(this.circularData, this.getAvg());
  4691. }
  4692. }, {
  4693. key: "getThreshPercent",
  4694. value: function getThreshPercent() {
  4695. return this.computeThreshPercent(this.circularData);
  4696. }
  4697. }, {
  4698. key: "getIncomingMax",
  4699. value: function getIncomingMax() {
  4700. return this.computeMax(this.incomingData) || 0;
  4701. }
  4702. }, {
  4703. key: "getIncomingAvg",
  4704. value: function getIncomingAvg() {
  4705. return this.computeAvg(this.incomingData) || 0;
  4706. }
  4707. }, {
  4708. key: "getIncomingStandardDeviation",
  4709. value: function getIncomingStandardDeviation() {
  4710. return count_sd(this.incomingData, this.getIncomingAvg());
  4711. }
  4712. }, {
  4713. key: "getIncomingThreshPercent",
  4714. value: function getIncomingThreshPercent() {
  4715. return this.computeThreshPercent(this.incomingData);
  4716. }
  4717. }, {
  4718. key: "clearFastComputeItem",
  4719. value: function clearFastComputeItem() {
  4720. this.sum = 0, this.incomingSum = 0, this.count = 0, this.incomingCount = 0, this.max = 0, this.incomingMax = 0, this.goodLess = 0, this.wellLess = 0, this.fairLess = 0, this.badLess = 0;
  4721. }
  4722. }, {
  4723. key: "clearIncoming",
  4724. value: function clearIncoming() {
  4725. for (; this.incomingData.length > 0;) {
  4726. this.incomingData.pop();
  4727. }
  4728. }
  4729. }, {
  4730. key: "clear",
  4731. value: function clear() {
  4732. this.circularData.fill(-1), this.circularPtr = 0, this.clearFastComputeItem(), this.clearIncoming();
  4733. }
  4734. }]);
  4735. return CircularArray;
  4736. }();
  4737. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  4738. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  4739. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  4740. var defaultLogger = {
  4741. info: console.log,
  4742. debug: console.log,
  4743. error: console.error,
  4744. infoAndReportMeasurement: function infoAndReportMeasurement() {}
  4745. };
  4746. var FRAME_COMPOSE_LENGTH = 5;
  4747. var Workers = /*#__PURE__*/function () {
  4748. function Workers(e, t) {
  4749. var _this = this;
  4750. _classCallCheck(this, Workers);
  4751. this.rtcp = e, this.cacheSize = 0, this.cacheBuffer = new Uint8Array(262144), this.cacheFrameCnt = 0, this.startReceiveTime = 0, this.cacheFrameComposes = new Array(0), this.cacheSizes = new Array(5).fill(0), this.cacheFrameCnts = new Array(5).fill(-1), this.cacheStartReceiveTimes = new Array(5).fill(0), this.cacheBuffers = [new Uint8Array(262144), new Uint8Array(262144), new Uint8Array(262144), new Uint8Array(262144), new Uint8Array(262144)], this.panoCacheSize = 0, this.panoCacheBuffer = new Uint8Array(2097152), this.cachePanoTileID = 0, this.receivedMedia = 0, this.receivedMedia_worker = 0, this.receivedYUV = 0, this.receivedEmit = 0, this.returnFrames = 0, this.lastReturnFrames = 0, this.lastReceivedEmit = 0, this.mediaBytesReceived = 0, this.metaBytesReceived = 0, this.noWasmBytesReceived = 0, this.rtcBytesReceived = 0, this.rtcMessageReceived = 0, this.packetsDrop = 0, this.framesAwait = 0, this.sendOutBuffer = 0, this.decodeTimePerFrame = 0, this.decodeTimeMaxFrame = 0, this.lastRenderTs = 0, this.JankTimes = 0, this.bigJankTimes = 0, this.DecodeJankTimes = 0, this.bigDecodeJankTimes = 0, this.saveframe = !1, this.SaveMediaStream = !1, this.packetsLost = 0, this.showAllReceivedMetadata = !1, this.firstMediaArraval = 0, this.firstMediaReceived = !1, this.firstYUVDecoded = 0, this.firstRender = 0, this.firstYUVReceived = !1, this.reconnectSignal = !1, this.serverFrameSlow = 0, this.serverFrameFast = 0, this.clientFrameSlow = 0, this.clientFrameFast = 0, this.lastServerTS = 0, this.lastClientTS = 0, this.lastSeq = 0, this.lastIsPureMeta = !1, this.lastHBPacketTs = 0, this.HBPacketInterval = 0, this.lastHBPacketSrvSentTs = 0, this.HBPacketIntervalSrvSent = 0, this.cachedLength = 2, this.cachedStreams = new Array(this.cachedLength), this.cachedMetas = new Array(this.cachedLength), this.cachedPtss = new Array(this.cachedLength), this.cachedRender = Array(this.cachedLength).fill(!1), this.cachedResolution = new Array(this.cachedLength), this.getPtr = 0, this.setPtr = 0, this.receiveIframes = 0, this.decodeIframes = 0, this.prevSenderTs = -1, this.serverSendTimeArray = new CircularArray$1(120, !1, []), this.inPanoMode = !1, this.PanoStatus = {
  4752. x: 0,
  4753. y: 0,
  4754. z: 0,
  4755. tiles: []
  4756. }, this.DynamicPanoTest = !1, this.PanoMask = new ArrayBuffer(8), this.PanoView = new DataView(this.PanoMask), this.userId_test = "", this.PendingMasks = [], this.traceIdMap = new Map(), this.responseTimeArray = [], this.processTimeArray = [], this.displayTimeArray = [], this.overallTimeArray = [], this.responseMiss = 0, this.processMiss = 0, this.displayMiss = 0, this.updateYUVCircular = new CircularArray$1(120, !1, []), this.updateDropFrame = 0, this.metaParseAraay = [], this.responseMoveMiss = 0, this.processMoveMiss = 0, this.displayMoveMiss = 0, this.MovingTraceId = "", this.PendingMovingTraceId = "", this.inMovingMode = !1, this.StartMovingTs = 0, this.PendingStartMovingTs = 0, this.moveEvent = "", this.MoveToFrameCnt = 0, this.lastIsMoving = 0, this.MoveResponseDelay = 0, this.MoveProcessDelay = 0, this.MoveDisplayDelay = 0, this.lastMoveResponseTime = 0, this.lastMoveProcessTime = 0, this.lastMoveDisplayTime = 0, this.moveResponseCircular = new CircularArray$1(120, !0, [STUCK_STAGE_GOOD, STUCK_STAGE_WELL, STUCK_STAGE_FAIR, STUCK_STAGE_BAD]), this.moveProcessCircular = new CircularArray$1(120, !0, [STUCK_STAGE_GOOD, STUCK_STAGE_WELL, STUCK_STAGE_FAIR, STUCK_STAGE_BAD]), this.moveDisplayCircular = new CircularArray$1(120, !0, [STUCK_STAGE_GOOD, STUCK_STAGE_WELL, STUCK_STAGE_FAIR, STUCK_STAGE_BAD]), this.moveStartPts = -1, this.frameServerCircular = new CircularArray$1(120, !1, []), this.srvMetaIntervalCircular = new CircularArray$1(120, !1, []), this.srvMediaIntervalCircular = new CircularArray$1(120, !1, []), this.srvHBMetaIntervalCircular = new CircularArray$1(120, !1, []), this.srvHBMetaIntervalSrvSentCircular = new CircularArray$1(120, !1, []), this.frameClientCircular = new CircularArray$1(120, !1, []), this.firstUpdateYUV = !0, this.functionMap = new Map(), this.WASM_VERSION = "WASM-1.1", this.frameHistory = [], this.getVersion = function () {
  4757. return DECODER_VERSION;
  4758. }, this.downloadBlob = function (r, n, o) {
  4759. var a = new Blob([r], {
  4760. type: o
  4761. }),
  4762. s = window.URL.createObjectURL(a);
  4763. _this.downloadURL(s, n), setTimeout(function () {
  4764. return window.URL.revokeObjectURL(s);
  4765. }, 1e3);
  4766. }, this.downloadURL = function (r, n) {
  4767. var o = document.createElement("a");
  4768. o.href = r, o.download = n, document.body.appendChild(o), o.style.display = "none", o.click(), o.remove();
  4769. }, this.Stringify = function (r) {
  4770. var n = "";
  4771. for (var a = 0; a < r.length / 8192; a++) {
  4772. n += String.fromCharCode.apply(null, r.slice(a * 8192, (a + 1) * 8192));
  4773. }
  4774. return n;
  4775. }, this._rtcp = e;
  4776. }
  4777. _createClass(Workers, [{
  4778. key: "registerLogger",
  4779. value: function registerLogger(e) {//defaultLogger = e
  4780. }
  4781. }, {
  4782. key: "registerFunction",
  4783. value: function registerFunction(e, t) {
  4784. this.functionMap.set(e, t);
  4785. }
  4786. }, {
  4787. key: "hasFrmCntInCache",
  4788. value: function hasFrmCntInCache(e) {
  4789. var t = -1;
  4790. for (var r = 0; r < this.cacheFrameComposes.length; r++) {
  4791. this.cacheFrameComposes[r].frameCnt == e && (t = r);
  4792. }
  4793. return t;
  4794. }
  4795. }, {
  4796. key: "requestPanoramaTest",
  4797. value: function requestPanoramaTest(e, t, r, n, o) {
  4798. var a = o,
  4799. s = {
  4800. action_type: 16,
  4801. change_rotation_render_type_action: {
  4802. render_type: 5,
  4803. player: {
  4804. position: {
  4805. x: 0,
  4806. y: 0,
  4807. z: 0
  4808. },
  4809. angle: {
  4810. yaw: 0,
  4811. pitch: 0,
  4812. roll: 0
  4813. }
  4814. },
  4815. camera: {
  4816. position: {
  4817. x: e,
  4818. y: t,
  4819. z: r
  4820. },
  4821. angle: {
  4822. yaw: 0,
  4823. pitch: 0,
  4824. roll: 0
  4825. }
  4826. },
  4827. client_pano_titles_bitmap: n
  4828. },
  4829. trace_id: a,
  4830. user_id: this.userId_test,
  4831. packet_id: a
  4832. };
  4833. defaultLogger.debug("send data: ", s), this._rtcp.sendData(s);
  4834. }
  4835. }, {
  4836. key: "onRotateInPanoMode",
  4837. value: function onRotateInPanoMode(e) {
  4838. var t = e.traceId,
  4839. r = {};
  4840. r.width = 1280, r.height = 720, r.horz_fov = 92, r.angle = {
  4841. yaw: 100,
  4842. pitch: 30
  4843. };
  4844. var n = new ArrayBuffer(8),
  4845. o = new DataView(n);
  4846. getTilesInView(r, n);
  4847. var a = n.slice(0);
  4848. this.PendingMasks.unshift({
  4849. buffer: a,
  4850. angle: r.angle
  4851. }), MaskSetToOne(18, this.PanoView), operateForDataView(o, this.PanoView, o, function (s, l) {
  4852. return s ^ s & l;
  4853. }), this.requestPanoramaTest(0, 0, 0, [o.getUint8(0), o.getUint8(1), o.getUint8(2), o.getUint8(3), o.getUint8(4), o.getUint8(5), o.getUint8(6), o.getUint8(7)], t);
  4854. }
  4855. }, {
  4856. key: "processMetaWithTraceId",
  4857. value: function processMetaWithTraceId(e) {
  4858. var _iterator = _createForOfIteratorHelper(e.traceIds),
  4859. _step;
  4860. try {
  4861. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  4862. var t = _step.value;
  4863. if (this.traceIdMap.has(t)) {
  4864. var r = this.traceIdMap.get(t);
  4865. r != null && (r.receiveTime = Date.now(), r.status = 1);
  4866. }
  4867. if (t == this.PendingMovingTraceId) {
  4868. this.inMovingMode = !0, this.MovingTraceId = this.PendingMovingTraceId, this.StartMovingTs = this.PendingStartMovingTs, this.PendingMovingTraceId = "", this.PendingStartMovingTs = 0, defaultLogger.info("MoveTo TraceId match", this.StartMovingTs, Date.now());
  4869. var _r = Date.now();
  4870. this.lastMoveResponseTime = _r, this.lastMoveProcessTime = _r, this.lastMoveDisplayTime = _r, this.frameServerCircular.clear(), this.frameClientCircular.clear();
  4871. }
  4872. }
  4873. } catch (err) {
  4874. _iterator.e(err);
  4875. } finally {
  4876. _iterator.f();
  4877. }
  4878. }
  4879. }, {
  4880. key: "onTraceId",
  4881. value: function onTraceId(e) {
  4882. var _this2 = this;
  4883. var r = e.traceId,
  4884. n = e.timestamp,
  4885. o = e.event;
  4886. if (o === "Rotation") {
  4887. var a = {
  4888. traceId: r,
  4889. pts: 0,
  4890. startTime: n,
  4891. receiveTime: 0,
  4892. readyTime: 0,
  4893. displayTime: 0,
  4894. status: 0
  4895. };
  4896. this.traceIdMap.set(r, a);
  4897. var s = setTimeout(function () {
  4898. if (s && clearTimeout(s), _this2.traceIdMap.has(r)) {
  4899. var l = _this2.traceIdMap.get(r);
  4900. switch (l == null ? void 0 : l.status) {
  4901. case 0:
  4902. {
  4903. _this2.responseMiss += 1;
  4904. break;
  4905. }
  4906. case 1:
  4907. {
  4908. _this2.processMiss += 1;
  4909. var u = l.receiveTime - l.startTime;
  4910. _this2.responseTimeArray.push(u);
  4911. break;
  4912. }
  4913. case 2:
  4914. {
  4915. _this2.displayMiss += 1;
  4916. var _u = l.receiveTime - l.startTime,
  4917. c = l.readyTime - l.receiveTime;
  4918. _this2.responseTimeArray.push(_u), _this2.processTimeArray.push(c);
  4919. break;
  4920. }
  4921. case 3:
  4922. defaultLogger.debug("status is 3");
  4923. }
  4924. }
  4925. }, 1e3);
  4926. } else o === "MoveTo" ? (defaultLogger.info("receive moveto traceId ", r, " at timestamp", n), this.PendingMovingTraceId = r, this.PendingStartMovingTs = n, this.moveEvent = o, this.frameServerCircular.clear()) : o === "GetOnAirship" || o === "GetOnVehicle" ? (defaultLogger.info("receive airship traceId ", r, " at timestamp ", n), this.PendingMovingTraceId = r, this.PendingStartMovingTs = n, this.moveEvent = o, this.frameServerCircular.clear()) : (o === "GetOffAirship" || o === "GetOffVehicle") && this.clearMoveArray();
  4927. }
  4928. }, {
  4929. key: "executeFunction",
  4930. value: function executeFunction(e, t) {
  4931. if (this.functionMap.has(e)) {
  4932. var r = this.functionMap.get(e);
  4933. r != null && r(t);
  4934. }
  4935. }
  4936. }, {
  4937. key: "UpdateStats",
  4938. value: function UpdateStats(e) {
  4939. var _this3 = this;
  4940. var t;
  4941. (t = this._rtcp.connection) == null || t.getStats(null).then(function (r) {
  4942. r.forEach(function (n) {
  4943. n.type == "data-channel" && (_this3.rtcMessageReceived = n.messagesReceived - n.messagesSent, _this3.rtcBytesReceived = n.bytesReceived);
  4944. });
  4945. }), this.receivedMedia_worker = e.data.framesReceived, this.receivedYUV = e.data.framesDecoded, this.receivedEmit = e.data.framesRendered, this.mediaBytesReceived = e.data.mediaBytesReceived, this.metaBytesReceived = e.data.metaBytesReceived, this.packetsLost = e.data.packetsLost, this.packetsDrop = e.data.packetsDrop, this.framesAwait = e.data.framesAwait, this.decodeTimePerFrame = e.data.decodeTimePerFrame, this.decodeTimeMaxFrame = e.data.decodeTimeMaxFrame, this.returnFrames = e.data.framesReturned, this.sendOutBuffer = e.data.sendOutBuffer, this.DecodeJankTimes = e.data.JankTimes, this.bigDecodeJankTimes = e.data.bigJankTimes, this.receiveIframes = e.data.receivedIframe, this.decodeIframes = e.data.decodedIframe;
  4946. }
  4947. }, {
  4948. key: "ReceiveDecodeMessage",
  4949. value: function ReceiveDecodeMessage(e) {
  4950. var n;
  4951. if (!this.firstYUVReceived) {
  4952. this.firstYUVDecoded = e.data.yuv_ts;
  4953. var o = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  4954. defaultLogger.infoAndReportMeasurement({
  4955. metric: "firstYUVDecodedAt",
  4956. value: o,
  4957. group: "joinRoom"
  4958. }), this.firstRender = Date.now();
  4959. var a = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  4960. defaultLogger.infoAndReportMeasurement({
  4961. metric: "firstRenderAt",
  4962. value: a,
  4963. group: "joinRoom"
  4964. }), this.firstYUVReceived = !0, this.lastRenderTs = Date.now();
  4965. }
  4966. !this.cachedRender[this.setPtr] && this.cachedMetas[this.setPtr] != null && (this.cachedStreams[this.setPtr] != null && this.cachedStreams[this.setPtr].byteLength != 0 && (e.data.data == null ? (this.executeFunction("stream", {
  4967. stream: this.cachedStreams[this.setPtr],
  4968. width: this.cachedResolution[this.setPtr].width,
  4969. height: this.cachedResolution[this.setPtr].height,
  4970. pts: this.cachedPtss[this.setPtr]
  4971. }), this.executeFunction("signal", {
  4972. signal: this.cachedMetas[this.setPtr],
  4973. pts: this.cachedPtss[this.setPtr],
  4974. alreadyUpdateYUV: !0
  4975. })) : this.updateDropFrame += 1, this.decoderWorker.postMessage({
  4976. t: 2,
  4977. frameCnt: this.cachedPtss[this.setPtr],
  4978. buffer: this.cachedStreams[this.setPtr]
  4979. }, [this.cachedStreams[this.setPtr].buffer])), this.getPtr = (this.getPtr + 1) % this.cachedLength);
  4980. var t = e.data.metadata;
  4981. if ((n = t == null ? void 0 : t.traceIds) != null && n.length) {
  4982. var _iterator2 = _createForOfIteratorHelper(t.traceIds),
  4983. _step2;
  4984. try {
  4985. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  4986. var _o = _step2.value;
  4987. if (this.traceIdMap.has(_o)) {
  4988. var _a = this.traceIdMap.get(_o);
  4989. _a != null && (_a.readyTime = Date.now(), _a.status = 2);
  4990. }
  4991. }
  4992. } catch (err) {
  4993. _iterator2.e(err);
  4994. } finally {
  4995. _iterator2.f();
  4996. }
  4997. }
  4998. if (e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs), this.userId_test = this.rtcp.network.room.userId, this.inMovingMode) {
  4999. var _o2 = Date.now(),
  5000. _a2 = _o2 - this.lastMoveProcessTime;
  5001. this.moveProcessCircular.add(_a2), this.lastMoveProcessTime = _o2;
  5002. }
  5003. var r = this.setPtr;
  5004. this.cachedStreams[r] = e.data.data, this.cachedMetas[r] = e.data.metadata, this.cachedPtss[r] = e.data.pts, this.cachedRender[r] = !1, this.cachedResolution[r] = {
  5005. width: e.data.width,
  5006. height: e.data.height
  5007. }, this.setPtr = (this.setPtr + 1) % this.cachedLength;
  5008. }
  5009. }, {
  5010. key: "SendCacheFrameInfo",
  5011. value: function SendCacheFrameInfo(e) {
  5012. var _this4 = this;
  5013. var h, f, d, _, g, m, v;
  5014. var t = e.data.cachedKey,
  5015. r = e.data.metadata,
  5016. n = t,
  5017. o = r,
  5018. a = (d = (f = (h = o.newUserStates) == null ? void 0 : h.find(function (y) {
  5019. return y.userId === _this4.rtcp.network.room.userId;
  5020. })) == null ? void 0 : f.playerState) == null ? void 0 : d.roomTypeId,
  5021. s = this.rtcp.network.room.skinId,
  5022. l = (v = (m = (g = (_ = o.newUserStates) == null ? void 0 : _.find(function (y) {
  5023. return y.userId === _this4._rtcp.network.room.userId;
  5024. })) == null ? void 0 : g.playerState) == null ? void 0 : m.player) == null ? void 0 : v.position,
  5025. u = {
  5026. MsgType: 1,
  5027. FrameCacheMsg: {
  5028. FrameIndex: n,
  5029. RoomTypeId: a,
  5030. SkinID: s,
  5031. Position: l
  5032. }
  5033. };
  5034. var c = "";
  5035. try {
  5036. c = JSON.stringify(u);
  5037. } catch (y) {
  5038. defaultLogger.error(y);
  5039. return;
  5040. }
  5041. }
  5042. }, {
  5043. key: "ReceivePanoramaDecodeMessage",
  5044. value: function ReceivePanoramaDecodeMessage(e) {
  5045. defaultLogger.info("Receive Panorama Image in Workers.ts"), MaskSetToOne(e.data.tileId, this.PanoView);
  5046. var t = 0,
  5047. r;
  5048. var n = this.PendingMasks.length;
  5049. for (t = 0; t < n; t++) {
  5050. var o = this.PendingMasks[t].buffer,
  5051. a = new DataView(o),
  5052. s = new ArrayBuffer(8),
  5053. l = new DataView(s);
  5054. if (operateForDataView(this.PanoView, a, l, function (u, c) {
  5055. return c ^ u & c;
  5056. }), IsAll0(l)) {
  5057. r = this.PendingMasks[t].angle;
  5058. break;
  5059. }
  5060. }
  5061. for (var _o3 = t; _o3 < n; _o3++) {
  5062. this.PendingMasks.pop();
  5063. }
  5064. this.executeFunction("panorama", {
  5065. data: e.data.data,
  5066. tileId: e.data.tileId,
  5067. pos: {
  5068. x: e.data.x,
  5069. y: e.data.y,
  5070. z: e.data.z
  5071. },
  5072. uuid: e.data.uuid,
  5073. finished: !0,
  5074. matchAngle: r
  5075. });
  5076. }
  5077. }, {
  5078. key: "enable_decoder_queue_logging",
  5079. value: function enable_decoder_queue_logging() {
  5080. this.decoderWorker.postMessage({
  5081. t: 100,
  5082. status: !0
  5083. });
  5084. }
  5085. }, {
  5086. key: "disable_decoder_queue_logging",
  5087. value: function disable_decoder_queue_logging() {
  5088. this.decoderWorker.postMessage({
  5089. t: 100,
  5090. status: !1
  5091. });
  5092. }
  5093. }, {
  5094. key: "init",
  5095. value: function () {
  5096. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  5097. var r,
  5098. n,
  5099. t;
  5100. return regenerator.wrap(function _callee$(_context) {
  5101. while (1) {
  5102. switch (_context.prev = _context.next) {
  5103. case 0:
  5104. for (r = 0; r < FRAME_COMPOSE_LENGTH; r++) {
  5105. n = {
  5106. buffer: new Uint8Array(2621440),
  5107. size: 0,
  5108. startReceiveTime: 0,
  5109. serverTime: 0,
  5110. frameCnt: -1
  5111. };
  5112. this.cacheFrameComposes.push(n);
  5113. }
  5114. t = new Blob([decoder], {
  5115. type: "application/javascript"
  5116. });
  5117. return _context.abrupt("return", (this.decoderWorker = new Worker(URL.createObjectURL(t)), this.decoderWorker.postMessage({
  5118. t: 9,
  5119. url: WASM_URLS[WASM_Version],
  5120. jitterLength: DECODER_PASSIVE_JITTER
  5121. })));
  5122. case 5:
  5123. case "end":
  5124. return _context.stop();
  5125. }
  5126. }
  5127. }, _callee, this);
  5128. }));
  5129. function init() {
  5130. return _init.apply(this, arguments);
  5131. }
  5132. return init;
  5133. }()
  5134. }, {
  5135. key: "UpdateYUV",
  5136. value: function UpdateYUV() {
  5137. var t, r;
  5138. var e = this.getPtr;
  5139. if (this.cachedMetas[e] != null && !this.cachedRender[e]) {
  5140. var n = Date.now();
  5141. if (this.firstUpdateYUV) {
  5142. var h = ((t = this.cachedStreams[e]) == null ? void 0 : t.byteLength) || 0;
  5143. defaultLogger.infoAndReportMeasurement({
  5144. metric: "firstUpdateStreamLength",
  5145. value: h,
  5146. group: "joinRoom"
  5147. }), this.firstUpdateYUV = !1;
  5148. }
  5149. this.cachedStreams[e] != null && this.executeFunction("stream", {
  5150. stream: this.cachedStreams[e],
  5151. width: this.cachedResolution[e].width,
  5152. height: this.cachedResolution[e].height,
  5153. pts: this.cachedPtss[e]
  5154. });
  5155. var o = Date.now();
  5156. this.cachedStreams[e] != null && this.decoderWorker.postMessage({
  5157. t: 2,
  5158. frameCnt: this.cachedPtss[e],
  5159. buffer: this.cachedStreams[e]
  5160. }, [this.cachedStreams[e].buffer]);
  5161. var a = Date.now(),
  5162. s = o - n,
  5163. l = a - o;
  5164. (s > 33 || l > 10) && defaultLogger.debug("[wwwarning] updateYUV takes ", s, " ms, postMessage takes ", l, " ms for index ", this.cachedPtss[e]), o - this.lastRenderTs > 84 && this.JankTimes++, o - this.lastRenderTs > 125 && this.bigJankTimes++, this.lastRenderTs = o;
  5165. var u = o - n;
  5166. this.updateYUVCircular.add(u);
  5167. var c = this.cachedMetas[e];
  5168. if ((r = c == null ? void 0 : c.traceIds) != null && r.length) {
  5169. var _iterator3 = _createForOfIteratorHelper(c.traceIds),
  5170. _step3;
  5171. try {
  5172. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  5173. var _h = _step3.value;
  5174. if (this.traceIdMap.has(_h)) {
  5175. var f = this.traceIdMap.get(_h);
  5176. if (f != null) {
  5177. f.displayTime = Date.now(), f.status = 3;
  5178. var d = f.receiveTime - f.startTime,
  5179. _ = f.readyTime - f.receiveTime,
  5180. g = f.displayTime - f.readyTime,
  5181. m = f.displayTime - f.startTime;
  5182. this.responseTimeArray.push(d), this.processTimeArray.push(_), this.displayTimeArray.push(g), this.overallTimeArray.push(m), this.traceIdMap.delete(_h);
  5183. }
  5184. }
  5185. }
  5186. } catch (err) {
  5187. _iterator3.e(err);
  5188. } finally {
  5189. _iterator3.f();
  5190. }
  5191. }
  5192. if (this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs), this.inMovingMode) {
  5193. var _h2 = Date.now(),
  5194. _f = _h2 - this.lastMoveDisplayTime;
  5195. this.moveDisplayCircular.add(_f), this.lastMoveDisplayTime = _h2;
  5196. }
  5197. this.executeFunction("signal", {
  5198. signal: this.cachedMetas[e],
  5199. pts: this.cachedPtss[e],
  5200. alreadyUpdateYUV: !0
  5201. }), this.cachedRender[e] = !0, this.getPtr = (this.getPtr + 1) % this.cachedLength;
  5202. }
  5203. }
  5204. }, {
  5205. key: "unmarshalPano",
  5206. value: function unmarshalPano(e) {
  5207. var t = new DataView(e);
  5208. if (t.getUint32(0) != 1723558763) return !1;
  5209. console.log("Receive Pano Message"), t.getUint16(4);
  5210. var n = t.getUint16(6),
  5211. o = t.getUint32(8),
  5212. a = t.getUint32(12) - (1 << 30) * 2,
  5213. s = t.getUint32(16) - (1 << 30) * 2,
  5214. l = t.getUint32(20) - (1 << 30) * 2,
  5215. u = t.getUint32(24),
  5216. c = new Uint8Array(e).subarray(28, 64),
  5217. h = String.fromCharCode.apply(null, c),
  5218. f = t.getUint32(64),
  5219. d = e.byteLength - n;
  5220. if (d == u) {
  5221. var g = {
  5222. data: new Uint8Array(e).subarray(n),
  5223. mediaLen: u,
  5224. tileId: o,
  5225. uuid: h,
  5226. x: a,
  5227. y: s,
  5228. z: l
  5229. };
  5230. this.decoderWorker.postMessage({
  5231. t: 8,
  5232. data: g
  5233. });
  5234. } else {
  5235. var _ = new Uint8Array(e, n, d);
  5236. if (this.cachePanoTileID == o) {
  5237. if (this.panoCacheBuffer.set(_, f), this.panoCacheSize += d, this.panoCacheSize === u) {
  5238. var m = {
  5239. data: new Uint8Array(this.panoCacheBuffer).slice(0, u),
  5240. mediaLen: u,
  5241. tileId: o,
  5242. uuid: h,
  5243. x: a,
  5244. y: s,
  5245. z: l
  5246. };
  5247. this.decoderWorker.postMessage({
  5248. t: 8,
  5249. data: m
  5250. }), this.panoCacheSize = 0;
  5251. }
  5252. } else this.panoCacheBuffer.set(_, f), this.panoCacheSize = d, this.cachePanoTileID = o;
  5253. }
  5254. return !0;
  5255. }
  5256. }, {
  5257. key: "clearMoveArray",
  5258. value: function clearMoveArray() {
  5259. this.MovingTraceId = "", this.inMovingMode = !1, this.StartMovingTs = 0, this.MoveToFrameCnt = 0, this.MoveResponseDelay = 0, this.MoveProcessDelay = 0, this.MoveDisplayDelay = 0, this.moveStartPts = -1, this.moveResponseCircular.clear(), this.moveProcessCircular.clear(), this.moveDisplayCircular.clear(), this.moveEvent = "";
  5260. }
  5261. }, {
  5262. key: "getIsMoving",
  5263. value: function getIsMoving(e) {
  5264. var t;
  5265. if (typeof e.newUserStates != "undefined") for (var r = 0; r < e.newUserStates.length; r++) {
  5266. var n = e.newUserStates[r];
  5267. if (n.userId == this.rtcp.network.room.userId) {
  5268. t = n.renderInfo.isMoving;
  5269. break;
  5270. }
  5271. }
  5272. return t;
  5273. }
  5274. }, {
  5275. key: "isHeartBeatPacket",
  5276. value: function isHeartBeatPacket(e, t) {
  5277. return new DataView(e).getUint32(0) == 2009889916;
  5278. }
  5279. }, {
  5280. key: "resetSendTimeDiff",
  5281. value: function resetSendTimeDiff() {
  5282. this.prevSenderTs = 0, this.serverSendTimeArray.clear();
  5283. }
  5284. }, {
  5285. key: "calcSendTimeDiff",
  5286. value: function calcSendTimeDiff(e) {
  5287. if (this.prevSenderTs == -1) {
  5288. this.prevSenderTs = e;
  5289. return;
  5290. }
  5291. var t = e - this.prevSenderTs;
  5292. this.serverSendTimeArray.add(t), this.prevSenderTs = e;
  5293. }
  5294. }, {
  5295. key: "unmarshalStream",
  5296. value: function unmarshalStream(e) {
  5297. var _this6 = this;
  5298. var T, C, A, S, P, R, M, x, I, w;
  5299. var t = new DataView(e);
  5300. if (t.getUint32(0) != 1437227610) return !1;
  5301. t.getUint16(4);
  5302. var n = t.getUint16(6),
  5303. o = t.getUint16(8),
  5304. a = o,
  5305. s = t.getUint16(10);
  5306. var l = !1;
  5307. s == 1 && (l = !0);
  5308. var u = t.getUint32(12),
  5309. c = t.getUint32(16),
  5310. h = t.getUint32(20),
  5311. f = t.getUint16(24),
  5312. d = t.getUint16(26),
  5313. _ = t.getUint32(28),
  5314. g = t.getUint32(n - 4),
  5315. m = u + c,
  5316. v = e.byteLength - n,
  5317. y = new Uint8Array(e, n, v);
  5318. this.calcSendTimeDiff(h);
  5319. var b;
  5320. if (this.inPanoMode && (c > 0 || f)) return defaultLogger.error("Stream Protocal Violation: receive illegal stream in Pano mode"), !0;
  5321. if (v === m) {
  5322. this.receivedMedia++;
  5323. var O = new Uint8Array(e).subarray(n);
  5324. h - this.lastServerTS > 60 ? this.serverFrameSlow++ : h - this.lastServerTS < 16 && this.serverFrameFast++;
  5325. var D = Date.now();
  5326. D - this.lastClientTS > 60 ? this.clientFrameSlow++ : D - this.lastClientTS < 16 && this.clientFrameFast++;
  5327. var F = c === 0,
  5328. V = h - this.lastServerTS;
  5329. this.lastServerTS != 0 && ((o + 65536 - this.lastSeq) % 65536 === 1 && this.lastIsPureMeta == F && (F ? this.srvMetaIntervalCircular.add(V) : this.srvMediaIntervalCircular.add(V)), this.frameServerCircular.add(V), this.frameClientCircular.add(D - this.lastClientTS)), this.lastSeq = o, this.lastIsPureMeta = F, this.lastServerTS = h, this.lastClientTS = D;
  5330. var N = O.subarray(0, u),
  5331. L = Date.now(),
  5332. k = JSON.parse(this.Stringify(N)),
  5333. U = Date.now();
  5334. this.showAllReceivedMetadata && console.log(h, D, k), this.metaParseAraay.push(U - L), (T = k.traceIds) != null && T.length && this.processMetaWithTraceId(k), c != 0 && this.moveStartPts == -1 && this.inMovingMode && (this.moveStartPts = o), this.moveStartPts == o && (this.MoveResponseDelay = Date.now() - this.StartMovingTs, console.log("move response delay: ", o, this.moveStartPts, this.MoveResponseDelay));
  5335. var z = this.getIsMoving(k);
  5336. if (this.inMovingMode && z == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof z != "undefined" && (this.lastIsMoving = z), this.inMovingMode) {
  5337. var G = Date.now(),
  5338. W = G - this.lastMoveResponseTime;
  5339. this.moveResponseCircular.add(W), this.lastMoveResponseTime = G;
  5340. }
  5341. (f || d) && (b = (P = (S = (A = (C = k.newUserStates) == null ? void 0 : C.find(function (G) {
  5342. return G.userId === _this6._rtcp.network.room.userId;
  5343. })) == null ? void 0 : A.playerState) == null ? void 0 : S.player) == null ? void 0 : P.position);
  5344. var H = {
  5345. t: 0,
  5346. data: O,
  5347. mediaLen: c,
  5348. metaLen: u,
  5349. metadata: k,
  5350. frameCnt: a,
  5351. server_ts: h,
  5352. isIDR: l,
  5353. cacheRequest: d,
  5354. cached: f,
  5355. cachedKey: _,
  5356. position: b
  5357. };
  5358. if (this.inPanoMode) return this.executeFunction("signal", {
  5359. signal: k,
  5360. pts: -1,
  5361. alreadyUpdateYUV: !0
  5362. }), !0;
  5363. if (this.decoderWorker.postMessage(H, [O.buffer]), !this.firstMediaReceived) {
  5364. this.firstMediaArraval = Date.now();
  5365. var _G = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5366. defaultLogger.infoAndReportMeasurement({
  5367. metric: "firstMediaArravalAt",
  5368. value: _G,
  5369. group: "joinRoom"
  5370. }), this.firstMediaReceived = !0;
  5371. }
  5372. } else {
  5373. var _O = this.hasFrmCntInCache(a);
  5374. if (_O != -1) {
  5375. if (this.cacheFrameComposes[_O].buffer.set(y, g), this.cacheFrameComposes[_O].size += v, this.cacheFrameComposes[_O].size === m) {
  5376. var _D = new Uint8Array(this.cacheFrameComposes[_O].buffer).slice(0, m);
  5377. this.cacheFrameComposes[_O].frameCnt = -1, this.cacheFrameComposes[_O].size = 0, this.cacheFrameComposes[_O].startReceiveTime = 0, this.cacheFrameComposes[_O].serverTime = 0, this.receivedMedia++, h - this.lastServerTS > 60 ? this.serverFrameSlow++ : h - this.lastServerTS < 16 && this.serverFrameFast++;
  5378. var _F = Date.now();
  5379. _F - this.lastClientTS > 60 ? this.clientFrameSlow++ : _F - this.lastClientTS < 16 && this.clientFrameFast++, this.lastServerTS != 0 && (this.frameServerCircular.add(h - this.lastServerTS), this.frameClientCircular.add(_F - this.lastClientTS)), this.lastServerTS = h, this.lastClientTS = _F;
  5380. var _V = _D.subarray(0, u),
  5381. _N = Date.now(),
  5382. _L = JSON.parse(this.Stringify(_V)),
  5383. _k = Date.now();
  5384. this.showAllReceivedMetadata && console.log(h, _F, _L), this.metaParseAraay.push(_k - _N), (R = _L.traceIds) != null && R.length && this.processMetaWithTraceId(_L), c != 0 && this.moveStartPts == -1 && this.inMovingMode && (this.moveStartPts = o), this.moveStartPts == o && (this.MoveResponseDelay = Date.now() - this.StartMovingTs);
  5385. var _U = this.getIsMoving(_L);
  5386. if (this.inMovingMode && _U == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof _U != "undefined" && (this.lastIsMoving = _U), this.inMovingMode) {
  5387. var _H = Date.now(),
  5388. _G2 = _H - this.lastMoveResponseTime;
  5389. this.moveResponseCircular.add(_G2), this.lastMoveResponseTime = _H;
  5390. }
  5391. (f || d) && (b = (w = (I = (x = (M = _L.newUserStates) == null ? void 0 : M.find(function (H) {
  5392. return H.userId === _this6._rtcp.network.room.userId;
  5393. })) == null ? void 0 : x.playerState) == null ? void 0 : I.player) == null ? void 0 : w.position);
  5394. var _z = {
  5395. t: 0,
  5396. data: _D,
  5397. mediaLen: c,
  5398. metaLen: u,
  5399. metadata: _L,
  5400. frameCnt: a,
  5401. server_ts: h,
  5402. isIDR: l,
  5403. cacheRequest: d,
  5404. cached: f,
  5405. cachedKey: _,
  5406. position: b
  5407. };
  5408. if (this.inPanoMode) return this.executeFunction("signal", {
  5409. signal: _L,
  5410. pts: -1,
  5411. alreadyUpdateYUV: !0
  5412. }), !0;
  5413. if (this.decoderWorker.postMessage(_z, [_D.buffer]), !this.firstMediaReceived) {
  5414. this.firstMediaArraval = Date.now();
  5415. var _H2 = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5416. defaultLogger.infoAndReportMeasurement({
  5417. metric: "firstMediaArravalAt",
  5418. value: _H2,
  5419. group: "joinRoom"
  5420. }), this.firstMediaReceived = !0;
  5421. }
  5422. } else this.cacheFrameComposes[_O].size > m && defaultLogger.debug("I frame exceed, cache size is ", this.cacheSize, ", total size is ", m);
  5423. } else if (_O == -1) {
  5424. var _D2 = this.hasFrmCntInCache(-1);
  5425. if (_D2 == -1) {
  5426. var _F2 = Date.now() + 1e18,
  5427. _V2 = -1;
  5428. for (var _N2 = 0; _N2 < this.cacheFrameComposes.length; _N2++) {
  5429. this.cacheFrameComposes[_N2].serverTime < _F2 && (_F2 = this.cacheFrameComposes[_N2].serverTime, _V2 = _N2);
  5430. }
  5431. _D2 = _V2;
  5432. }
  5433. this.cacheFrameComposes[_D2].buffer.set(y, g), this.cacheFrameComposes[_D2].size = v, this.cacheFrameComposes[_D2].frameCnt = a, this.cacheFrameComposes[_D2].startReceiveTime = Date.now(), this.cacheFrameComposes[_D2].serverTime = h;
  5434. }
  5435. }
  5436. return !0;
  5437. }
  5438. }, {
  5439. key: "reset",
  5440. value: function reset() {
  5441. defaultLogger.debug("Worker reset is called"), this.cacheFrameCnt = 0, this.receivedMedia = 0, this.reconnectSignal = !0, this.decoderWorker.postMessage({
  5442. t: 4
  5443. });
  5444. }
  5445. }, {
  5446. key: "dataHandleOff",
  5447. value: function dataHandleOff(e) {
  5448. defaultLogger.debug("hhh");
  5449. }
  5450. }, {
  5451. key: "dataHandle",
  5452. value: function dataHandle(e) {
  5453. this.saveframe && (this.decoderWorker.postMessage({
  5454. t: 6
  5455. }), this.saveframe = !1), this.SaveMediaStream && (this.decoderWorker.postMessage({
  5456. t: 7
  5457. }), this.SaveMediaStream = !1);
  5458. var t = new Uint8Array(e);
  5459. if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0) return;
  5460. if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
  5461. this.reconnectSignal && (this.executeFunction("reconnectedFrame", {}), this.reconnectSignal = !1);
  5462. return;
  5463. }
  5464. if (t.length > 20 && this.unmarshalPano(t.buffer) == !0) return;
  5465. this.noWasmBytesReceived += e.byteLength;
  5466. var r = JSON.parse(this.Stringify(t));
  5467. this.executeFunction("signal", {
  5468. signal: r,
  5469. pts: -1,
  5470. alreadyUpdateYUV: !0
  5471. });
  5472. }
  5473. }, {
  5474. key: "changePanoMode",
  5475. value: function changePanoMode(e) {
  5476. this.inPanoMode = e;
  5477. }
  5478. }, {
  5479. key: "uploadDataToServer",
  5480. value: function uploadDataToServer() {
  5481. this.DynamicPanoTest == !0 && (this.onRotateInPanoMode({
  5482. traceId: "b2e1a296-6438-4371-8a31-687beb724ebe"
  5483. }), this.DynamicPanoTest = !1);
  5484. function e(ie, ee) {
  5485. return ee == -1 && (ee = 0), ie + ee;
  5486. }
  5487. function t(ie, ee) {
  5488. return Math.max(ie, ee);
  5489. }
  5490. var r = this.responseTimeArray.reduce(e, 0) / this.responseTimeArray.length || 0,
  5491. n = this.processTimeArray.reduce(e, 0) / this.processTimeArray.length || 0,
  5492. o = this.displayTimeArray.reduce(e, 0) / this.displayTimeArray.length || 0,
  5493. a = this.overallTimeArray.reduce(e, 0) / this.overallTimeArray.length || 0,
  5494. s = this.overallTimeArray.length;
  5495. this.responseTimeArray = [], this.processTimeArray = [], this.displayTimeArray = [], this.overallTimeArray = [];
  5496. var l = this.moveResponseCircular.getThreshPercent(),
  5497. u = l[0],
  5498. c = l[1],
  5499. h = l[2],
  5500. f = l[3],
  5501. d = l[4],
  5502. _ = d - f,
  5503. g = 1 - c / d || 0,
  5504. m = [u, c - u, h - c, f - h, _],
  5505. v = this.moveProcessCircular.getThreshPercent(),
  5506. y = v[0],
  5507. b = v[1],
  5508. T = v[2],
  5509. C = v[3],
  5510. A = v[4],
  5511. S = A - C,
  5512. P = 1 - b / A || 0,
  5513. R = [y, b - y, T - b, C - T, S],
  5514. M = this.moveDisplayCircular.getThreshPercent(),
  5515. x = M[0],
  5516. I = M[1],
  5517. w = M[2],
  5518. O = M[3],
  5519. D = M[4],
  5520. F = D - O,
  5521. V = 1 - I / D || 0,
  5522. N = [x, I - x, w - I, O - w, F],
  5523. L = x,
  5524. k = I - x,
  5525. U = w - I,
  5526. z = O - w,
  5527. H = F,
  5528. G = this.moveResponseCircular.getAvg(),
  5529. W = this.moveProcessCircular.getAvg(),
  5530. j = this.moveDisplayCircular.getAvg(),
  5531. B = this.moveResponseCircular.getMax(),
  5532. X = this.moveProcessCircular.getMax(),
  5533. $ = this.moveDisplayCircular.getMax(),
  5534. Y = this.moveResponseCircular.getStandardDeviation(),
  5535. K = this.moveProcessCircular.getStandardDeviation(),
  5536. Z = this.moveDisplayCircular.getStandardDeviation();
  5537. this.moveResponseCircular.getIncomingAvg(), this.moveProcessCircular.getIncomingAvg(), this.moveDisplayCircular.getIncomingAvg(), this.moveResponseCircular.getIncomingMax(), this.moveProcessCircular.getIncomingMax(), this.moveDisplayCircular.getIncomingMax(), this.moveResponseCircular.clearIncoming(), this.moveProcessCircular.clearIncoming(), this.moveDisplayCircular.clearIncoming();
  5538. var q = this.frameServerCircular.getAvg(),
  5539. J = this.frameServerCircular.getMax();
  5540. this.frameClientCircular.getAvg(), this.frameClientCircular.getMax();
  5541. var Q = this.metaParseAraay.reduce(e, 0) / this.metaParseAraay.length || 0,
  5542. te = this.metaParseAraay.reduce(t, 0);
  5543. this.metaParseAraay = [];
  5544. var re = {
  5545. mediaBytesReceived: this.mediaBytesReceived,
  5546. metaBytesReceived: this.metaBytesReceived,
  5547. packetsLost: this.packetsLost,
  5548. timestamp: Date.now(),
  5549. frameHeight: 1280,
  5550. frameWidth: 720,
  5551. framesReceived: this.receivedMedia,
  5552. framesReceivedWorker: this.receivedMedia_worker,
  5553. framesDecoded: this.receivedYUV,
  5554. framesEmited: this.receivedEmit,
  5555. decodeTimePerFrame: this.decodeTimePerFrame,
  5556. decodeTimeMaxFrame: this.decodeTimeMaxFrame,
  5557. packetsDrop: this.packetsDrop,
  5558. framesAwait: this.framesAwait,
  5559. firstMediaArraval: this.firstMediaArraval,
  5560. firstYUVDecoded: this.firstYUVDecoded,
  5561. firstRender: this.firstRender,
  5562. returnFrames: this.returnFrames,
  5563. sendOutBuffer: this.sendOutBuffer,
  5564. maxGraphicTime: this.updateYUVCircular.getMax(),
  5565. averageGraphicTime: this.updateYUVCircular.getAvg(),
  5566. jankTimes: this.JankTimes,
  5567. bigJankTimes: this.bigJankTimes,
  5568. decodeJankTimes: this.DecodeJankTimes,
  5569. bigDecodeJankTimes: this.bigDecodeJankTimes,
  5570. serverFrameSlow: this.serverFrameSlow,
  5571. serverFrameFast: this.serverFrameFast,
  5572. clientFrameSlow: this.clientFrameSlow,
  5573. clientFrameFast: this.clientFrameFast,
  5574. rtcMessageReceived: this.rtcMessageReceived,
  5575. rtcBytesReceived: this.rtcBytesReceived - this.noWasmBytesReceived,
  5576. receiveIframes: this.receiveIframes,
  5577. decodeIframes: this.decodeIframes,
  5578. avgResponseTime: r,
  5579. avgProcessTime: n,
  5580. avgDisplayTime: o,
  5581. avgOverallTime: a,
  5582. overallTimeCount: s,
  5583. responseMiss: this.responseMiss,
  5584. processMiss: this.processMiss,
  5585. displayMiss: this.displayMiss,
  5586. updateDropFrame: this.updateDropFrame,
  5587. moveEvent: this.moveEvent,
  5588. avgResponseMoveDiff: this.moveEvent == "MoveTo" ? G : 0,
  5589. avgProcessMoveDiff: this.moveEvent == "MoveTo" ? W : 0,
  5590. avgDisplayMoveDiff: this.moveEvent == "MoveTo" ? j : 0,
  5591. maxResponseMoveDiff: this.moveEvent == "MoveTo" ? B : 0,
  5592. maxProcessMoveDiff: this.moveEvent == "MoveTo" ? X : 0,
  5593. maxDisplayMoveDiff: this.moveEvent == "MoveTo" ? $ : 0,
  5594. moveResponseJank: this.moveEvent == "MoveTo" ? g : 0,
  5595. moveProcessJank: this.moveEvent == "MoveTo" ? P : 0,
  5596. moveDisplayJank: this.moveEvent == "MoveTo" ? V : 0,
  5597. moveResponseCounts: this.moveEvent == "MoveTo" ? m.toString() : "0,0,0,0,0",
  5598. moveProcessCounts: this.moveEvent == "MoveTo" ? R.toString() : "0,0,0,0,0",
  5599. moveDisplayCounts: this.moveEvent == "MoveTo" ? N.toString() : "0,0,0,0,0",
  5600. MoveDisplayCountGood: this.moveEvent == "MoveTo" ? L.toString() : "0",
  5601. MoveDisplayCountWell: this.moveEvent == "MoveTo" ? k.toString() : "0",
  5602. MoveDisplayCountFair: this.moveEvent == "MoveTo" ? U.toString() : "0",
  5603. MoveDisplayCountBad: this.moveEvent == "MoveTo" ? z.toString() : "0",
  5604. MoveDisplayCountRest: this.moveEvent == "MoveTo" ? H.toString() : "0",
  5605. moveResponseDelay: this.moveEvent == "MoveTo" ? this.MoveResponseDelay : 0,
  5606. moveProcessDelay: this.moveEvent == "MoveTo" ? this.MoveProcessDelay : 0,
  5607. moveDisplayDelay: this.moveEvent == "MoveTo" ? this.MoveDisplayDelay : 0,
  5608. sdMoveResponseLongTime: Y,
  5609. sdMoveProcessLongTime: K,
  5610. sdMoveDisplayLongTime: Z,
  5611. avgResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? G : 0,
  5612. avgProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? W : 0,
  5613. avgDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? j : 0,
  5614. maxResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? B : 0,
  5615. maxProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? X : 0,
  5616. maxDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? $ : 0,
  5617. flyResponseJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? g : 0,
  5618. flyProcessJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? P : 0,
  5619. flyDisplayJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? V : 0,
  5620. flyResponseCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? m.toString() : "0,0,0,0,0",
  5621. flyProcessCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? R.toString() : "0,0,0,0,0",
  5622. flyDisplayCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? N.toString() : "0,0,0,0,0",
  5623. flyResponseDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveResponseDelay : 0,
  5624. flyProcessDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveProcessDelay : 0,
  5625. flyDisplayDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveDisplayDelay : 0,
  5626. avgMetaParseTime: Q,
  5627. maxMetaParseTime: te,
  5628. avgServerDiff: q,
  5629. maxServerDiff: J,
  5630. streamType: WASM_Version
  5631. };
  5632. return this.lastReturnFrames = this.returnFrames, this.lastReceivedEmit = this.receivedEmit, re;
  5633. }
  5634. }]);
  5635. return Workers;
  5636. }();
  5637. function _createSuper$8(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$8(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5638. function _isNativeReflectConstruct$8() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5639. var Rtcp = /*#__PURE__*/function (_EventEmitter) {
  5640. _inherits(Rtcp, _EventEmitter);
  5641. var _super = _createSuper$8(Rtcp);
  5642. function Rtcp(e) {
  5643. var _this;
  5644. _classCallCheck(this, Rtcp);
  5645. _this = _super.call(this);
  5646. E(_assertThisInitialized(_this), "connection", null);
  5647. E(_assertThisInitialized(_this), "inputChannel", null);
  5648. E(_assertThisInitialized(_this), "mediaStream");
  5649. E(_assertThisInitialized(_this), "socket");
  5650. E(_assertThisInitialized(_this), "connected", !1);
  5651. E(_assertThisInitialized(_this), "candidates", []);
  5652. E(_assertThisInitialized(_this), "isAnswered", !1);
  5653. E(_assertThisInitialized(_this), "isFlushing", !1);
  5654. E(_assertThisInitialized(_this), "inputReady", !1);
  5655. E(_assertThisInitialized(_this), "workers");
  5656. E(_assertThisInitialized(_this), "actived", !0);
  5657. E(_assertThisInitialized(_this), "heartbeat");
  5658. E(_assertThisInitialized(_this), "onIcecandidate", function (e) {
  5659. if (e.candidate != null) {
  5660. var t = JSON.stringify(e.candidate);
  5661. logger.debug("Got ice candidate: ".concat(t)), _this.network.socket.send({
  5662. id: "ice_candidate",
  5663. data: btoa(t)
  5664. });
  5665. }
  5666. });
  5667. E(_assertThisInitialized(_this), "onIcecandidateerror", function (e) {
  5668. logger.error("onicecandidateerror", e.errorCode, e.errorText, e);
  5669. });
  5670. E(_assertThisInitialized(_this), "onIceStateChange", function (e) {
  5671. switch (e.target.iceGatheringState) {
  5672. case "gathering":
  5673. logger.info("ice gathering");
  5674. break;
  5675. case "complete":
  5676. logger.info("Ice gathering completed");
  5677. }
  5678. });
  5679. E(_assertThisInitialized(_this), "onIceConnectionStateChange", function () {
  5680. if (!!_this.connection) switch (logger.info("iceConnectionState: ".concat(_this.connection.iceConnectionState)), _this.connection.iceConnectionState) {
  5681. case "connected":
  5682. {
  5683. _this.connected = !0;
  5684. break;
  5685. }
  5686. case "disconnected":
  5687. {
  5688. _this.connected = !1, _this.emit("rtcDisconnected");
  5689. break;
  5690. }
  5691. case "failed":
  5692. {
  5693. _this.emit("rtcDisconnected"), _this.connected = !1;
  5694. break;
  5695. }
  5696. }
  5697. });
  5698. E(_assertThisInitialized(_this), "setRemoteDescription", /*#__PURE__*/function () {
  5699. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  5700. var a, s, l, r, n, o, u;
  5701. return regenerator.wrap(function _callee$(_context) {
  5702. while (1) {
  5703. switch (_context.prev = _context.next) {
  5704. case 0:
  5705. if (_this.connection) {
  5706. _context.next = 2;
  5707. break;
  5708. }
  5709. return _context.abrupt("return");
  5710. case 2:
  5711. r = JSON.parse(atob(e)), n = new RTCSessionDescription(r);
  5712. _context.next = 5;
  5713. return _this.connection.setRemoteDescription(n);
  5714. case 5:
  5715. _context.next = 7;
  5716. return _this.connection.createAnswer();
  5717. case 7:
  5718. o = _context.sent;
  5719. if (o.sdp = (a = o.sdp) == null ? void 0 : a.replace(/(a=fmtp:111 .*)/g, "$1;stereo=1;sprop-stereo=1"), ((l = (s = o.sdp) == null ? void 0 : s.match(/a=mid:1/g)) == null ? void 0 : l.length) == 2) {
  5720. u = o.sdp.lastIndexOf("a=mid:1");
  5721. o.sdp = o.sdp.slice(0, u) + "a=mid:2" + o.sdp.slice(u + 7);
  5722. }
  5723. _context.prev = 9;
  5724. _context.next = 12;
  5725. return _this.connection.setLocalDescription(o);
  5726. case 12:
  5727. _context.next = 17;
  5728. break;
  5729. case 14:
  5730. _context.prev = 14;
  5731. _context.t0 = _context["catch"](9);
  5732. logger.error("error", _context.t0);
  5733. case 17:
  5734. _this.isAnswered = !0, _this.network.rtcp.flushCandidate(), _this.network.socket.send({
  5735. id: "answer",
  5736. data: btoa(JSON.stringify(o))
  5737. }), t.srcObject = _this.mediaStream;
  5738. case 18:
  5739. case "end":
  5740. return _context.stop();
  5741. }
  5742. }
  5743. }, _callee, null, [[9, 14]]);
  5744. }));
  5745. return function (_x, _x2) {
  5746. return _ref.apply(this, arguments);
  5747. };
  5748. }());
  5749. E(_assertThisInitialized(_this), "flushCandidate", function () {
  5750. _this.isFlushing || !_this.isAnswered || (_this.isFlushing = !0, _this.candidates.forEach(function (e) {
  5751. var t = atob(e),
  5752. r = JSON.parse(t);
  5753. if (/172\./.test(r.candidate)) return;
  5754. var n = new RTCIceCandidate(r);
  5755. _this.connection && _this.connection.addIceCandidate(n).then(function () {}, function (o) {
  5756. logger.info("add candidate failed", o);
  5757. });
  5758. }), _this.isFlushing = !1);
  5759. });
  5760. E(_assertThisInitialized(_this), "input", function (e) {
  5761. var t;
  5762. !_this.actived || !_this.inputChannel || _this.inputChannel.readyState === "open" && ((t = _this.inputChannel) == null || t.send(e));
  5763. });
  5764. _this.network = e, _this.workers = new Workers(_assertThisInitialized(_this), logger), _this.workers.registerLogger(logger), _this.workers.registerFunction("data", function (t) {
  5765. _this.emit("data", t);
  5766. }), _this.heartbeat = new Heartbeat({
  5767. ping: function ping(t) {
  5768. e.room.actionsHandler.echo(t);
  5769. },
  5770. pong(t, r) {
  5771. var n;
  5772. r && t > 500 && logger.warn("high hb value ".concat(t, ", traceId:") + r), (n = e.room.stats) == null || n.assign({
  5773. hb: t
  5774. });
  5775. }
  5776. });
  5777. return _this;
  5778. }
  5779. _createClass(Rtcp, [{
  5780. key: "start",
  5781. value: function start() {
  5782. var _this2 = this;
  5783. this.connection = new RTCPeerConnection();
  5784. var e = Date.now();
  5785. this.connection.ondatachannel = function (t) {
  5786. logger.info("ondatachannel: ".concat(t.channel.label));
  5787. _this2.inputChannel = t.channel;
  5788. _this2.inputChannel.onopen = function () {
  5789. var r;
  5790. logger.info("The input channel has opened, id:", (r = _this2.inputChannel) == null ? void 0 : r.id), _this2.inputReady = !0, _this2.emit("rtcConnected"), _this2.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
  5791. metric: "datachannelOpenedAt",
  5792. startTime: _this2.network.room._startTime,
  5793. group: "joinRoom"
  5794. }), logger.infoAndReportMeasurement({
  5795. metric: "datachannelOpenedCost",
  5796. startTime: e,
  5797. group: "joinRoom"
  5798. }));
  5799. console.log('this.inputChannel', _this2.inputChannel);
  5800. }, _this2.inputChannel.onclose = function () {
  5801. var r;
  5802. return logger.info("The input channel has closed, id:", (r = _this2.inputChannel) == null ? void 0 : r.id);
  5803. }, _this2.inputChannel.onmessage = function (r) {
  5804. // console.log('this.workers',this.workers)
  5805. console.log('inputChannel', r.data);
  5806. _this2.workers.dataHandle(r.data);
  5807. };
  5808. }, this.connection.oniceconnectionstatechange = this.onIceConnectionStateChange, this.connection.onicegatheringstatechange = this.onIceStateChange, this.connection.onicecandidate = this.onIcecandidate, this.connection.onicecandidateerror = this.onIcecandidateerror, this.network.socket.send({
  5809. id: "init_webrtc",
  5810. data: JSON.stringify({
  5811. is_mobile: !0
  5812. })
  5813. });
  5814. }
  5815. }, {
  5816. key: "addCandidate",
  5817. value: function addCandidate(e) {
  5818. e === "" ? this.network.rtcp.flushCandidate() : this.candidates.push(e);
  5819. }
  5820. }, {
  5821. key: "disconnect",
  5822. value: function disconnect() {
  5823. var e, t, r;
  5824. this.heartbeat.stop(), logger.info("ready to close datachannel, id", (e = this.inputChannel) == null ? void 0 : e.id), (t = this.inputChannel) == null || t.close(), (r = this.connection) == null || r.close(), this.connection = null, this.inputChannel = null;
  5825. }
  5826. }, {
  5827. key: "sendStringData",
  5828. value: function sendStringData(e) {
  5829. console.log('e', e);
  5830. this.input(e);
  5831. }
  5832. }, {
  5833. key: "sendData",
  5834. value: function sendData(e) {
  5835. var t = "";
  5836. try {
  5837. t = JSON.stringify(e);
  5838. } catch (r) {
  5839. logger.error(r);
  5840. return;
  5841. }
  5842. this.input(t);
  5843. }
  5844. }]);
  5845. return Rtcp;
  5846. }(EventEmitter);
  5847. var NetworkMonitor = /*#__PURE__*/function () {
  5848. function NetworkMonitor(e) {
  5849. _classCallCheck(this, NetworkMonitor);
  5850. this._listener = e;
  5851. }
  5852. _createClass(NetworkMonitor, [{
  5853. key: "isOnline",
  5854. get: function get() {
  5855. var e = window.navigator;
  5856. return typeof e.onLine == "boolean" ? e.onLine : !0;
  5857. }
  5858. }, {
  5859. key: "start",
  5860. value: function start() {
  5861. window.addEventListener("online", this._listener), window.addEventListener("offline", this._listener);
  5862. }
  5863. }, {
  5864. key: "stop",
  5865. value: function stop() {
  5866. window.removeEventListener("online", this._listener), window.removeEventListener("offline", this._listener);
  5867. }
  5868. }]);
  5869. return NetworkMonitor;
  5870. }();
  5871. var Stream = /*#__PURE__*/function () {
  5872. function Stream(e) {
  5873. _classCallCheck(this, Stream);
  5874. this.el = null;
  5875. this._streamPlayTimer = null;
  5876. if (!e) {
  5877. this.el = this.createVideoElement();
  5878. return;
  5879. }
  5880. this.el = e;
  5881. }
  5882. _createClass(Stream, [{
  5883. key: "play",
  5884. value: function play() {
  5885. var _this = this;
  5886. return new Promise(function (e, t) {
  5887. _this._streamPlayTimer = new Timeout(function () {
  5888. t(new InternalError("Stream play timeout"));
  5889. }, 5e3), _this.el && _this.el.play().then(function () {
  5890. var r;
  5891. e(), logger.info("Media can autoplay"), (r = _this._streamPlayTimer) == null || r.clear();
  5892. }).catch(function (r) {
  5893. var n;
  5894. logger.error("Media Failed to autoplay"), logger.error(r), t(new InternalError("Media Failed to autoplay")), (n = _this._streamPlayTimer) == null || n.clear();
  5895. });
  5896. });
  5897. }
  5898. }, {
  5899. key: "createVideoElement",
  5900. value: function createVideoElement() {
  5901. var e = document.createElement("video");
  5902. return e.muted = !0, e.autoplay = !1, e.playsInline = !0, e.setAttribute("autostart", "false"), e.setAttribute("controls", "controls"), e.setAttribute("muted", "true"), e.setAttribute("preload", "auto"), e.setAttribute("hidden", "hidden"), document.body.appendChild(e), e;
  5903. }
  5904. }]);
  5905. return Stream;
  5906. }();
  5907. function _createSuper$7(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$7(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5908. function _isNativeReflectConstruct$7() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5909. var InternalError$1 = /*#__PURE__*/function (_XverseError) {
  5910. _inherits(InternalError, _XverseError);
  5911. var _super = _createSuper$7(InternalError);
  5912. function InternalError(e) {
  5913. _classCallCheck(this, InternalError);
  5914. return _super.call(this, 1002, e || "\u5185\u90E8\u9519\u8BEF");
  5915. }
  5916. return _createClass(InternalError);
  5917. }(XverseError);
  5918. function _createSuper$6(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$6(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5919. function _isNativeReflectConstruct$6() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5920. var workerSourceCode = "onmessage = function (event) {\n const data = event.data\n if (!data) return\n \n if (data.type === 'start') {\n const startTime = Date.now()\n const request = new XMLHttpRequest()\n request.open('GET', data.url)\n try {\n request.send()\n } catch (error) {\n console.error(error)\n }\n request.addEventListener('readystatechange', () => {\n if (request.readyState == 4) {\n if (request.status == 200) {\n postMessage(Date.now() - startTime)\n }\n }\n })\n }\n }\n ";
  5921. var NetworkController = /*#__PURE__*/function (_EventEmitter) {
  5922. _inherits(NetworkController, _EventEmitter);
  5923. var _super = _createSuper$6(NetworkController);
  5924. function NetworkController(e) {
  5925. var _this;
  5926. _classCallCheck(this, NetworkController);
  5927. _this = _super.call(this);
  5928. _this.socket = null;
  5929. _this.rtcp = null;
  5930. _this.stream = null;
  5931. _this._state = 'connecting';
  5932. _this._networkMonitor = null;
  5933. _this.blockedActions = [];
  5934. _this.reconnectCount = 0;
  5935. _this.room = e, _this.socket = new Socket(_assertThisInitialized(_this));
  5936. _this.rtcp = new Rtcp(_assertThisInitialized(_this));
  5937. _this.stream = new Stream();
  5938. _this._networkMonitor = new NetworkMonitor(function () {
  5939. logger.info("network changed, online:", _this._networkMonitor.isOnline), _this._state === "disconnected" && _this._networkMonitor.isOnline && (logger.info("network back to online, try to reconnect"), _this.reconnect());
  5940. });
  5941. _this.checkNetworkQuality(_this.room.currentNetworkOptions.wsServerUrl);
  5942. _this._networkMonitor.start();
  5943. new VisibilityChangeHandler().subscribe(function (r) {
  5944. var n, o;
  5945. r ? ((o = _this.room.stats) == null || o.disable(), logger.infoAndReportMeasurement({
  5946. metric: "pageHide",
  5947. startTime: Date.now()
  5948. })) : ((n = _this.room.stats) == null || n.enable(), logger.infoAndReportMeasurement({
  5949. metric: "pageShow",
  5950. startTime: Date.now(),
  5951. extra: {
  5952. state: _this._state
  5953. }
  5954. }), _this._state === "disconnected" && _this.reconnect());
  5955. });
  5956. return _this;
  5957. }
  5958. _createClass(NetworkController, [{
  5959. key: "startGame",
  5960. value: function startGame() {
  5961. var _this2 = this;
  5962. return new Promise(function (e, t) {
  5963. if (!_this2.rtcp.connected) return t(new InternalError$1("Game cannot load. Please refresh"));
  5964. if (!_this2.rtcp.inputReady) return t(new InternalError$1("Game is not ready yet. Please wait"));
  5965. _this2.socket.on("gameRoomAvailable", function (r) {
  5966. _this2.setState("connected"), e(r), _this2.rtcp.heartbeat.start();
  5967. }), _this2.socket.on("socketClosed", function (r) {
  5968. t(r);
  5969. }), _this2.socket.startGame();
  5970. });
  5971. }
  5972. }, {
  5973. key: "addBlockedActions",
  5974. value: function addBlockedActions(e) {
  5975. var _this$blockedActions;
  5976. (_this$blockedActions = this.blockedActions).push.apply(_this$blockedActions, _toConsumableArray(e));
  5977. }
  5978. }, {
  5979. key: "removeBlockedActions",
  5980. value: function removeBlockedActions(e) {
  5981. if (!e) {
  5982. this.blockedActions = [];
  5983. return;
  5984. }
  5985. var t = this.blockedActions.indexOf(e);
  5986. this.blockedActions.splice(t, 1);
  5987. }
  5988. }, {
  5989. key: "setState",
  5990. value: function setState(e) {
  5991. this._state !== e && (logger.info("Set network state to ", e), this._state = e);
  5992. }
  5993. }, {
  5994. key: "connectAndStart",
  5995. value: function () {
  5996. var _connectAndStart = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  5997. return regenerator.wrap(function _callee$(_context) {
  5998. while (1) {
  5999. switch (_context.prev = _context.next) {
  6000. case 0:
  6001. return _context.abrupt("return", this.connect(e).then(this.startGame));
  6002. case 1:
  6003. case "end":
  6004. return _context.stop();
  6005. }
  6006. }
  6007. }, _callee, this);
  6008. }));
  6009. function connectAndStart(_x) {
  6010. return _connectAndStart.apply(this, arguments);
  6011. }
  6012. return connectAndStart;
  6013. }()
  6014. }, {
  6015. key: "connect",
  6016. value: function () {
  6017. var _connect = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  6018. var _this3 = this;
  6019. var e,
  6020. _args2 = arguments;
  6021. return regenerator.wrap(function _callee2$(_context2) {
  6022. while (1) {
  6023. switch (_context2.prev = _context2.next) {
  6024. case 0:
  6025. e = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : !1;
  6026. this.room.updateCurrentNetworkOptions({
  6027. reconnect: e
  6028. });
  6029. return _context2.abrupt("return", new Promise(function (t, r) {
  6030. _this3.rtcp.on("rtcConnected", function () {
  6031. _this3.setState("connected"), t();
  6032. }), _this3.rtcp.on("rtcDisconnected", function () {
  6033. logger.info("rtc disconnected"), _this3._state === "connecting" ? (_this3.setState("disconnected"), r(new InternalError$1("rtc connect failed"))) : (_this3.setState("disconnected"), logger.info("rtc disconnected, start to reconnect"), _this3.reconnect());
  6034. }), _this3.socket.on("socketQuit", function () {
  6035. logger.info("socket quit success"), _this3.setState("closed");
  6036. }), _this3.socket.on("socketClosed", function (n) {
  6037. _this3._state === "connecting" && (_this3.setState("disconnected"), r(n)), r(n);
  6038. }), _this3.socket.start();
  6039. }));
  6040. case 3:
  6041. case "end":
  6042. return _context2.stop();
  6043. }
  6044. }
  6045. }, _callee2, this);
  6046. }));
  6047. function connect() {
  6048. return _connect.apply(this, arguments);
  6049. }
  6050. return connect;
  6051. }()
  6052. }, {
  6053. key: "reconnect",
  6054. value: function reconnect() {
  6055. var _this4 = this;
  6056. if (this.room.viewMode === "observer") return;
  6057. var e = Date.now();
  6058. if (this.reconnectCount++, this.reconnectCount > MAX_RECONNECT_COUNT) {
  6059. logger.error("reconnect failed, reached max reconnect count", MAX_RECONNECT_COUNT), this.reconnectCount = 0, this.emit("stateChanged", {
  6060. state: "disconnected"
  6061. });
  6062. return;
  6063. }
  6064. return logger.info("start reconnect, count:", this.reconnectCount), this._reconnect().then(function () {
  6065. logger.infoAndReportMeasurement({
  6066. startTime: e,
  6067. metric: "reconnect"
  6068. });
  6069. }).catch(function (t) {
  6070. if (logger.infoAndReportMeasurement({
  6071. startTime: e,
  6072. metric: "reconnect",
  6073. error: t
  6074. }), t.code === Codes.RepeatLogin) {
  6075. _this4.room.handleRepetLogin();
  6076. return;
  6077. }
  6078. var r = 1e3;
  6079. logger.info("reconnect failed, wait " + r + " ms for next reconnect"), setTimeout(function () {
  6080. _this4.reconnect();
  6081. }, r);
  6082. });
  6083. }
  6084. }, {
  6085. key: "_reconnect",
  6086. value: function _reconnect() {
  6087. var _this5 = this;
  6088. return this._state === "closed" ? (logger.warn("connection closed already"), Promise.reject()) : this._state === "connecting" ? (logger.warn("connection is already in connecting state"), Promise.reject()) : this._state !== "disconnected" ? Promise.reject() : (this.prepareReconnect(), this._state = "connecting", this.emit("stateChanged", {
  6089. state: "reconnecting",
  6090. count: this.reconnectCount
  6091. }), this.socket.off("gameRoomAvailable"), this.socket.off("socketClosed"), this.rtcp.off("rtcDisconnected"), this.rtcp.off("rtcConnected"), this.connectAndStart(!0).then(function (_ref) {
  6092. var e = _ref.session_id;
  6093. _this5.room.updateCurrentNetworkOptions({
  6094. sessionId: e
  6095. }), reporter.updateBody({
  6096. serverSession: e
  6097. }), logger.info("reconnect success"), _this5.setState("connected"), _this5.reconnectCount = 0, _this5.emit("stateChanged", {
  6098. state: "reconnected"
  6099. });
  6100. }));
  6101. }
  6102. }, {
  6103. key: "prepareReconnect",
  6104. value: function prepareReconnect() {
  6105. this.rtcp.disconnect(), this.socket.prepareReconnect(), this.prepareReconnectOptions();
  6106. }
  6107. }, {
  6108. key: "prepareReconnectOptions",
  6109. value: function prepareReconnectOptions() {
  6110. var _ref2 = this.room.currentClickingState || {},
  6111. e = _ref2.camera,
  6112. t = _ref2.player;
  6113. e && t && this.room.updateCurrentNetworkOptions({
  6114. camera: e,
  6115. player: t
  6116. });
  6117. }
  6118. }, {
  6119. key: "sendRtcData",
  6120. value: function sendRtcData(e) {
  6121. if (this.blockedActions.includes(e.action_type)) {
  6122. logger.info("action: ".concat(Actions[e.action_type], " was blocked"));
  6123. return;
  6124. }
  6125. this.rtcp.sendData(e);
  6126. }
  6127. }, {
  6128. key: "sendSocketData",
  6129. value: function sendSocketData(e) {
  6130. logger.debug("ws send ->", e), this.socket.send(e);
  6131. }
  6132. }, {
  6133. key: "quit",
  6134. value: function quit() {
  6135. var e = uuid$1(),
  6136. t = {
  6137. action_type: Actions.Exit,
  6138. trace_id: e,
  6139. exit_action: {},
  6140. user_id: this.room.options.userId,
  6141. packet_id: e
  6142. };
  6143. this.setState("closed"), this.socket.quit(), this.sendRtcData(t);
  6144. }
  6145. }, {
  6146. key: "checkNetworkQuality",
  6147. value: function checkNetworkQuality(i) {
  6148. var worker = null;
  6149. if (!i) return;
  6150. var e = Date.now();
  6151. if (this.pingOthers("https://www.baidu.com", function (t, r) {
  6152. logger.infoAndReportMeasurement({
  6153. metric: "baiduRtt",
  6154. group: "http",
  6155. value: r,
  6156. startTime: e
  6157. });
  6158. }), !worker) {
  6159. var t = new Blob([workerSourceCode], {
  6160. type: "application/javascript"
  6161. });
  6162. worker = new Worker(URL.createObjectURL(t)), worker.onmessage = function (r) {
  6163. logger.infoAndReportMeasurement({
  6164. metric: "workerRtt",
  6165. group: "http",
  6166. startTime: e,
  6167. value: r.data
  6168. });
  6169. };
  6170. }
  6171. }
  6172. }, {
  6173. key: "pingOthers",
  6174. value: function pingOthers(i, e) {
  6175. var t = !1;
  6176. var r = new Image();
  6177. r.onload = o, r.onerror = a;
  6178. var n = Date.now();
  6179. function o(l) {
  6180. t = !0, s();
  6181. }
  6182. function a(l) {}
  6183. function s() {
  6184. var l = Date.now() - n;
  6185. if (typeof e == "function") return t ? e(null, l) : (console.error("error loading resource"), e("error", l));
  6186. }
  6187. r.src = i + "/favicon.ico?" + +new Date();
  6188. }
  6189. }]);
  6190. return NetworkController;
  6191. }(EventEmitter);
  6192. function _createSuper$5(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$5(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6193. function _isNativeReflectConstruct$5() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  6194. var InitConfigTimeoutError = /*#__PURE__*/function (_XverseError) {
  6195. _inherits(InitConfigTimeoutError, _XverseError);
  6196. var _super = _createSuper$5(InitConfigTimeoutError);
  6197. function InitConfigTimeoutError(e) {
  6198. _classCallCheck(this, InitConfigTimeoutError);
  6199. return _super.call(this, 1009, e || "\u914D\u7F6E\u521D\u59CB\u5316\u8D85\u65F6");
  6200. }
  6201. return _createClass(InitConfigTimeoutError);
  6202. }(XverseError);
  6203. function _createSuper$4(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$4(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6204. function _isNativeReflectConstruct$4() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  6205. var InitDecoderTimeoutError = /*#__PURE__*/function (_XverseError) {
  6206. _inherits(InitDecoderTimeoutError, _XverseError);
  6207. var _super = _createSuper$4(InitDecoderTimeoutError);
  6208. function InitDecoderTimeoutError(e) {
  6209. _classCallCheck(this, InitDecoderTimeoutError);
  6210. return _super.call(this, 1008, e || "Decoder \u521D\u59CB\u5316\u8D85\u65F6");
  6211. }
  6212. return _createClass(InitDecoderTimeoutError);
  6213. }(XverseError);
  6214. function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6215. function _isNativeReflectConstruct$3() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  6216. var InitEngineError = /*#__PURE__*/function (_XverseError) {
  6217. _inherits(InitEngineError, _XverseError);
  6218. var _super = _createSuper$3(InitEngineError);
  6219. function InitEngineError(e) {
  6220. _classCallCheck(this, InitEngineError);
  6221. return _super.call(this, 1011, e || "\u5F15\u64CE\u521D\u59CB\u5316\u9519\u8BEF");
  6222. }
  6223. return _createClass(InitEngineError);
  6224. }(XverseError);
  6225. var EngineProxy = /*#__PURE__*/function () {
  6226. function EngineProxy(e) {
  6227. var _this = this;
  6228. _classCallCheck(this, EngineProxy);
  6229. E(this, "_tvs", []);
  6230. E(this, "isRenderFirstFrame", !1);
  6231. E(this, "_idleTime", 0);
  6232. E(this, "renderTimer");
  6233. E(this, "lightManager");
  6234. E(this, "_checkSceneNotReadyCount", 0);
  6235. E(this, "_checkSceneDurationFrameNum", 0);
  6236. E(this, "_checkSceneFrameCount", 0);
  6237. E(this, "timeoutCircularArray", new CircularArray(120, !1, []));
  6238. E(this, "frameCircularArray", new CircularArray(120, !1, []));
  6239. E(this, "interFrameCircularArray", new CircularArray(120, !1, []));
  6240. E(this, "drawCallCntCircularArray", new CircularArray(120, !1, []));
  6241. E(this, "activeFacesCircularArray", new CircularArray(120, !1, []));
  6242. E(this, "renderTimeCircularArray", new CircularArray(120, !1, []));
  6243. E(this, "drawCallTimeCircularArray", new CircularArray(120, !1, []));
  6244. E(this, "animationCircularArray", new CircularArray(120, !1, []));
  6245. E(this, "meshSelectCircularArray", new CircularArray(120, !1, []));
  6246. E(this, "renderTargetCircularArray", new CircularArray(120, !1, []));
  6247. E(this, "regBeforeRenderCircularArray", new CircularArray(120, !1, []));
  6248. E(this, "regAfterRenderCircularArray", new CircularArray(120, !1, []));
  6249. E(this, "renderCnt", 0);
  6250. E(this, "renderErrorCount", 0);
  6251. E(this, "engineSloppyCnt", 0);
  6252. E(this, "systemStuckCnt", 0);
  6253. E(this, "frameRenderNumber", 0);
  6254. E(this, "_setFPS", function (e) {
  6255. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 25;
  6256. log$a.info("Set fps to", t);
  6257. var r = t > 60 ? 60 : t < 24 ? 24 : t;
  6258. e.Engine.stopRenderLoop();
  6259. var n = 1e3 / r;
  6260. var o = Date.now(),
  6261. a = Date.now(),
  6262. s = n,
  6263. l = 1;
  6264. var u = function u() {
  6265. var T;
  6266. var c = Date.now(),
  6267. h = c - o,
  6268. f = c - a;
  6269. a = c, _this.frameCircularArray.add(f), h - s > n && (_this.systemStuckCnt += 1);
  6270. var d = h / s;
  6271. l = .9 * l + .1 * d;
  6272. var _ = Date.now();
  6273. var g = 0,
  6274. m = 0;
  6275. if (_this.room.isUpdatedRawYUVData || _this.room.isPano) {
  6276. if (_this.isRenderFirstFrame = !0, _this._checkSceneDurationFrameNum > 0) _this._checkSceneFrameCount++, _this.room.sceneManager.isReadyToRender({}) && _this._checkSceneDurationFrameNum--, _this._checkSceneFrameCount > ye._CHECK_DURATION && (_this._checkSceneDurationFrameNum = ye._CHECK_DURATION, _this._checkSceneFrameCount = 0, _this._checkSceneNotReadyCount++, (_this._checkSceneNotReadyCount == 1 || _this._checkSceneNotReadyCount % 100 == 0) && log$a.error("[SDK] Scene not ready, skip render. loop: ".concat(_this._checkSceneNotReadyCount)), _this._checkSceneNotReadyCount > 10 && (log$a.error("[SDK] Scene not ready, reload later"), _this.room.proxyEvents("renderError", {
  6277. error: new Error("[SDK] Scene not ready, skip render and reload.")
  6278. })), _this.room.stats.assign({
  6279. renderErrorCount: _this._checkSceneNotReadyCount
  6280. }), log$a.infoAndReportMeasurement({
  6281. value: 0,
  6282. startTime: Date.now(),
  6283. metric: "renderError",
  6284. error: new Error("[SDK] Scene not ready, skip render and reload."),
  6285. reportOptions: {
  6286. sampleRate: .1
  6287. }
  6288. }));else try {
  6289. e.render();
  6290. } catch (C) {
  6291. _this.renderErrorCount++, _this.renderErrorCount > 10 && _this.room.proxyEvents("renderError", {
  6292. error: C
  6293. }), _this.room.stats.assign({
  6294. renderErrorCount: _this.renderErrorCount
  6295. }), log$a.infoAndReportMeasurement({
  6296. value: 0,
  6297. startTime: Date.now(),
  6298. metric: "renderError",
  6299. error: C,
  6300. reportOptions: {
  6301. sampleRate: .1
  6302. }
  6303. });
  6304. }
  6305. g = Date.now() - _, _this.frameRenderNumber < 1e3 && _this.frameRenderNumber++, _this.room.networkController.rtcp.workers.UpdateYUV(), m = Date.now() - _ - g;
  6306. }
  6307. _this.isRenderFirstFrame || _this.room.networkController.rtcp.workers.UpdateYUV();
  6308. var y = Date.now() - _;
  6309. o = c + y, s = Math.min(Math.max((n - y) / l, 5), 200), y > n && (s = 10, _this.engineSloppyCnt += 1), _this._idleTime = s;
  6310. var b = s;
  6311. if (s > 150 && console.log("lastGap is ", s, ", ratio is ", l, ", usedTimeMs is ", y, ", cpuRenderTime is ", g, ", cpuUpdateYUVTime is ", m), _this.timeoutCircularArray.add(b), _this.renderCnt % 25 == 0) {
  6312. var C = _this.frameCircularArray.getAvg(),
  6313. A = _this.timeoutCircularArray.getAvg(),
  6314. S = _this.frameCircularArray.getMax(),
  6315. P = _this.timeoutCircularArray.getMax();
  6316. (T = _this.room.stats) == null || T.assign({
  6317. avgFrameTime: C,
  6318. avgTimeoutTime: A,
  6319. maxFrameTime: S,
  6320. maxTimeoutTime: P,
  6321. systemStuckCnt: _this.systemStuckCnt
  6322. });
  6323. }
  6324. _this.renderTimer = window.setTimeout(u, s);
  6325. };
  6326. _this.renderTimer = window.setTimeout(u, n / l);
  6327. });
  6328. E(this, "updateStats", function () {
  6329. var e;
  6330. (e = _this.room.stats) == null || e.assign({
  6331. renderFrameTime: _this.renderTimeCircularArray.getAvg(),
  6332. maxRenderFrameTime: _this.renderTimeCircularArray.getMax(),
  6333. interFrameTime: _this.interFrameCircularArray.getAvg(),
  6334. animationTime: _this.animationCircularArray.getAvg(),
  6335. meshSelectTime: _this.meshSelectCircularArray.getAvg(),
  6336. drawcallTime: _this.drawCallTimeCircularArray.getAvg(),
  6337. idleTime: _this._idleTime,
  6338. registerBeforeRenderTime: _this.regBeforeRenderCircularArray.getAvg(),
  6339. registerAfterRenderTime: _this.regAfterRenderCircularArray.getAvg(),
  6340. renderTargetRenderTime: _this.renderTargetCircularArray.getAvg(),
  6341. fps: (1e3 / (_this.renderTimeCircularArray.getAvg() + _this.interFrameCircularArray.getAvg())).toFixed(2),
  6342. drawcall: _this.drawCallCntCircularArray.getAvg(),
  6343. engineSloppyCnt: _this.engineSloppyCnt,
  6344. maxInterFrameTime: _this.interFrameCircularArray.getMax(),
  6345. maxDrawcallTime: _this.drawCallTimeCircularArray.getMax(),
  6346. maxMeshSelectTime: _this.meshSelectCircularArray.getMax(),
  6347. maxAnimationTime: _this.animationCircularArray.getMax(),
  6348. maxRegisterBeforeRenderTime: _this.regBeforeRenderCircularArray.getMax(),
  6349. maxRegisterAfterRenderTime: _this.regAfterRenderCircularArray.getMax(),
  6350. maxRenderTargetRenderTime: _this.renderTargetCircularArray.getMax(),
  6351. avgFrameTime: _this.frameCircularArray.getAvg(),
  6352. avgTimeoutTime: _this.timeoutCircularArray.getAvg(),
  6353. maxFrameTime: _this.frameCircularArray.getMax(),
  6354. maxTimeoutTime: _this.timeoutCircularArray.getMax()
  6355. });
  6356. });
  6357. this.room = e;
  6358. }
  6359. _createClass(EngineProxy, [{
  6360. key: "initEngine",
  6361. value: function () {
  6362. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  6363. var t, r, n, o, a;
  6364. return regenerator.wrap(function _callee$(_context) {
  6365. while (1) {
  6366. switch (_context.prev = _context.next) {
  6367. case 0:
  6368. _context.next = 2;
  6369. return this.updateBillboard();
  6370. case 2:
  6371. log$a.info("engine version:", VERSION$1);
  6372. t = new Logger("engine");
  6373. t.setLevel(LoggerLevels.Warn);
  6374. r = {
  6375. videoResOriArray: [{
  6376. width: 720,
  6377. height: 1280
  6378. }, {
  6379. width: 1280,
  6380. height: 720
  6381. }, {
  6382. width: 480,
  6383. height: 654
  6384. }, {
  6385. width: 654,
  6386. height: 480
  6387. }, {
  6388. width: 1920,
  6389. height: 1080
  6390. }, {
  6391. width: 1080,
  6392. height: 1920
  6393. }, {
  6394. width: 414,
  6395. height: 896
  6396. }],
  6397. forceKeepVertical: this.room.options.objectFit !== "cover",
  6398. panoInfo: {
  6399. dynamicRange: 1,
  6400. width: 4096,
  6401. height: 2048
  6402. },
  6403. shaderMode: EShaderMode.videoAndPano,
  6404. yuvInfo: {
  6405. width: 1280,
  6406. height: 720,
  6407. fov: e.fov || DEFAULT_MAIN_CAMERA_FOV
  6408. },
  6409. cameraParam: {
  6410. maxZ: 1e4
  6411. },
  6412. urlTransformer,
  6413. logger: t,
  6414. disableWebGL2: this.room.options.disableWebGL2 || !1
  6415. }, n = this.room.options.resolution;
  6416. n && (r.videoResOriArray.some(function (l) {
  6417. return l.width === n.width && l.height === n.height;
  6418. }) || r.videoResOriArray.push(n));
  6419. o = this.room.sceneManager = getSceneManager(this.room.canvas, r);
  6420. this.room.setPictureQualityLevel(this.room.options.pictureQualityLevel || "high");
  6421. this.room.sceneManager.staticmeshComponent.setRegionLodRule([2, 2, -1, -1, -1]);
  6422. this.room.scene = o.Scene;
  6423. this.room.breathPointManager = o.breathPointComponent;
  6424. this.lightManager = o.lightComponent;
  6425. this.registerStats();
  6426. this.setEnv(e);
  6427. _context.next = 17;
  6428. return this.room.avatarManager.init();
  6429. case 17:
  6430. a = this._createAssetList(e);
  6431. _context.next = 20;
  6432. return this.loadAssets(a, "");
  6433. case 20:
  6434. this._setFPS(o);
  6435. case 21:
  6436. case "end":
  6437. return _context.stop();
  6438. }
  6439. }
  6440. }, _callee, this);
  6441. }));
  6442. function initEngine(_x) {
  6443. return _initEngine.apply(this, arguments);
  6444. }
  6445. return initEngine;
  6446. }()
  6447. }, {
  6448. key: "pause",
  6449. value: function pause() {
  6450. clearTimeout(this.renderTimer), log$a.info("Invoke room.pause to pause render");
  6451. var e = {
  6452. roomId: this.room.id,
  6453. effects: [],
  6454. lowPolyModels: [],
  6455. breathPointsConfig: [],
  6456. skinId: this.room.skinId
  6457. };
  6458. return this.loadAssets(e, this.room.skinId);
  6459. }
  6460. }, {
  6461. key: "resume",
  6462. value: function () {
  6463. var _resume = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  6464. var e;
  6465. return regenerator.wrap(function _callee2$(_context2) {
  6466. while (1) {
  6467. switch (_context2.prev = _context2.next) {
  6468. case 0:
  6469. this._setFPS(this.room.sceneManager), this.room.sceneManager.cameraComponent.cameraFovChange(this.room.sceneManager.yuvInfo), log$a.info("Invoke room.resume to render");
  6470. e = this._createAssetList(this.room.skin);
  6471. _context2.next = 4;
  6472. return this.loadAssets(e, "");
  6473. case 4:
  6474. case "end":
  6475. return _context2.stop();
  6476. }
  6477. }
  6478. }, _callee2, this);
  6479. }));
  6480. function resume() {
  6481. return _resume.apply(this, arguments);
  6482. }
  6483. return resume;
  6484. }()
  6485. }, {
  6486. key: "setEnv",
  6487. value: function setEnv(e) {
  6488. var r;
  6489. this.lightManager || (this.lightManager = this.room.sceneManager.lightComponent), e = e || this.room.skin;
  6490. var t = ModelManager.findModel(e.models, AssetTypeName.Config, AssetClassName.Env);
  6491. return t ? (r = this.lightManager) == null ? void 0 : r.setIBL(t.modelUrl) : (log$a.error("env file not found"), Promise.resolve());
  6492. }
  6493. }, {
  6494. key: "_parseModelsAndLoad",
  6495. value: function () {
  6496. var _parseModelsAndLoad2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e, t, r) {
  6497. var n, o, a, u, c, h, _c, s, l, _u, _c2, _h;
  6498. return regenerator.wrap(function _callee3$(_context3) {
  6499. while (1) {
  6500. switch (_context3.prev = _context3.next) {
  6501. case 0:
  6502. log$a.info("Invoke _parseModelsAndLoad start", t);
  6503. n = ["airship", "balloon", "default", "ground_feiting", "ground_reqiqiu"], o = new Map();
  6504. r == null && (r = "xxxx");
  6505. a = !0;
  6506. u = 0;
  6507. case 5:
  6508. if (!(u < e.length)) {
  6509. _context3.next = 20;
  6510. break;
  6511. }
  6512. a = !0;
  6513. c = 0;
  6514. case 8:
  6515. if (!(c < n.length)) {
  6516. _context3.next = 16;
  6517. break;
  6518. }
  6519. if (!(e[u].modelUrl.toLowerCase().indexOf(n[c]) >= 0)) {
  6520. _context3.next = 13;
  6521. break;
  6522. }
  6523. h = o.get(n[c]);
  6524. h ? (h.push(e[u]), o.set(n[c], h)) : o.set(n[c], [e[u]]), a = !1;
  6525. return _context3.abrupt("break", 16);
  6526. case 13:
  6527. ++c;
  6528. _context3.next = 8;
  6529. break;
  6530. case 16:
  6531. if (a) {
  6532. _c = o.get("default");
  6533. _c ? (_c.push(e[u]), o.set("default", _c)) : o.set("default", [e[u]]);
  6534. }
  6535. case 17:
  6536. ++u;
  6537. _context3.next = 5;
  6538. break;
  6539. case 20:
  6540. s = o.get(t) || [];
  6541. if (!(this.room.viewMode === "simple" && (s = s.filter(function (u) {
  6542. return !u.modelUrl.endsWith("zip");
  6543. })), !s)) {
  6544. _context3.next = 23;
  6545. break;
  6546. }
  6547. return _context3.abrupt("return", Promise.reject("no invalid scene model with group name: ".concat(t)));
  6548. case 23:
  6549. l = [];
  6550. for (_u = 0; _u < s.length; ++_u) {
  6551. _c2 = s[_u];
  6552. if (_c2.modelUrl.toLowerCase().endsWith("zip")) _c2.modelUrl.toLowerCase().endsWith("zip") && l.push(this.room.sceneManager.addNewLowPolyMesh({
  6553. url: _c2.modelUrl,
  6554. skinInfo: r
  6555. }));else {
  6556. _h = t;
  6557. l.push(this.room.sceneManager.addNewLowPolyMesh({
  6558. url: _c2.modelUrl,
  6559. group: _h,
  6560. pick: !0,
  6561. skinInfo: r
  6562. }));
  6563. }
  6564. }
  6565. return _context3.abrupt("return", Promise.all(l));
  6566. case 26:
  6567. case "end":
  6568. return _context3.stop();
  6569. }
  6570. }
  6571. }, _callee3, this);
  6572. }));
  6573. function _parseModelsAndLoad(_x2, _x3, _x4) {
  6574. return _parseModelsAndLoad2.apply(this, arguments);
  6575. }
  6576. return _parseModelsAndLoad;
  6577. }()
  6578. }, {
  6579. key: "_deleteAssetsLowpolyModel",
  6580. value: function () {
  6581. var _deleteAssetsLowpolyModel2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  6582. var t;
  6583. return regenerator.wrap(function _callee4$(_context4) {
  6584. while (1) {
  6585. switch (_context4.prev = _context4.next) {
  6586. case 0:
  6587. this.room.sceneManager.staticmeshComponent.deleteMeshesBySkinInfo(e), this.room.sceneManager.breathPointComponent.clearBreathPointsBySkinInfo(e), this.room.sceneManager.decalComponent.deleteDecalBySkinInfo(e);
  6588. t = [];
  6589. this.room.sceneManager.Scene.meshes.forEach(function (r) {
  6590. r.xskinInfo == e && t.push(r);
  6591. }), t.forEach(function (r) {
  6592. r.dispose(!1, !1);
  6593. });
  6594. case 3:
  6595. case "end":
  6596. return _context4.stop();
  6597. }
  6598. }
  6599. }, _callee4, this);
  6600. }));
  6601. function _deleteAssetsLowpolyModel(_x5) {
  6602. return _deleteAssetsLowpolyModel2.apply(this, arguments);
  6603. }
  6604. return _deleteAssetsLowpolyModel;
  6605. }()
  6606. }, {
  6607. key: "loadLandAssets",
  6608. value: function () {
  6609. var _loadLandAssets = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  6610. var _this2 = this;
  6611. var e;
  6612. return regenerator.wrap(function _callee5$(_context5) {
  6613. while (1) {
  6614. switch (_context5.prev = _context5.next) {
  6615. case 0:
  6616. e = this._createAssetList(this.room.skin);
  6617. return _context5.abrupt("return", this.loadAssets(e, this.room.skinId).catch(function () {
  6618. return _this2.loadAssets(e, _this2.room.skinId);
  6619. }));
  6620. case 2:
  6621. case "end":
  6622. return _context5.stop();
  6623. }
  6624. }
  6625. }, _callee5, this);
  6626. }));
  6627. function loadLandAssets() {
  6628. return _loadLandAssets.apply(this, arguments);
  6629. }
  6630. return loadLandAssets;
  6631. }()
  6632. }, {
  6633. key: "loadAssets",
  6634. value: function () {
  6635. var _loadAssets2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  6636. var t,
  6637. r,
  6638. n,
  6639. _args6 = arguments;
  6640. return regenerator.wrap(function _callee6$(_context6) {
  6641. while (1) {
  6642. switch (_context6.prev = _context6.next) {
  6643. case 0:
  6644. t = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : "";
  6645. r = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : 8e3;
  6646. n = Date.now();
  6647. return _context6.abrupt("return", this._loadAssets(e, t)._timeout(r, new InitEngineTimeoutError("loadAssets timeout(".concat(r, "ms)"))).then(function (o) {
  6648. return log$a.infoAndReportMeasurement({
  6649. tag: "loadAssets",
  6650. startTime: n,
  6651. metric: "loadAssets"
  6652. }), o;
  6653. }).catch(function (o) {
  6654. return log$a.infoAndReportMeasurement({
  6655. tag: "loadAssets",
  6656. startTime: n,
  6657. metric: "loadAssets",
  6658. error: o
  6659. }), Promise.reject(o);
  6660. }));
  6661. case 4:
  6662. case "end":
  6663. return _context6.stop();
  6664. }
  6665. }
  6666. }, _callee6, this);
  6667. }));
  6668. function loadAssets(_x6) {
  6669. return _loadAssets2.apply(this, arguments);
  6670. }
  6671. return loadAssets;
  6672. }()
  6673. }, {
  6674. key: "_loadAssets",
  6675. value: function () {
  6676. var _loadAssets3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  6677. var t,
  6678. r,
  6679. _args7 = arguments;
  6680. return regenerator.wrap(function _callee7$(_context7) {
  6681. while (1) {
  6682. switch (_context7.prev = _context7.next) {
  6683. case 0:
  6684. t = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : "";
  6685. _context7.prev = 1;
  6686. r = [];
  6687. r.push(this._loadAssetsLowpolyModel(e, t));
  6688. _context7.next = 6;
  6689. return Promise.all(r);
  6690. case 6:
  6691. _context7.next = 8;
  6692. return this.setEnv();
  6693. case 8:
  6694. this._checkSceneDurationFrameNum = ye._CHECK_DURATION;
  6695. this._checkSceneNotReadyCount = 0;
  6696. this._checkSceneFrameCount = 0;
  6697. this.updateAnimationList();
  6698. this.room.loadAssetsHook();
  6699. _context7.next = 18;
  6700. break;
  6701. case 15:
  6702. _context7.prev = 15;
  6703. _context7.t0 = _context7["catch"](1);
  6704. return _context7.abrupt("return", Promise.reject(_context7.t0));
  6705. case 18:
  6706. case "end":
  6707. return _context7.stop();
  6708. }
  6709. }
  6710. }, _callee7, this, [[1, 15]]);
  6711. }));
  6712. function _loadAssets(_x7) {
  6713. return _loadAssets3.apply(this, arguments);
  6714. }
  6715. return _loadAssets;
  6716. }()
  6717. }, {
  6718. key: "updateAnimationList",
  6719. value: function updateAnimationList() {
  6720. var _this3 = this;
  6721. if (this.room.avatarManager && this.room.avatarManager.xAvatarManager) {
  6722. var e = this.room.skin.animationList;
  6723. if (!e) return;
  6724. e.forEach(function (t) {
  6725. _this3.room.avatarManager.xAvatarManager.updateAnimationLists(t.animations, t.avatarId);
  6726. });
  6727. }
  6728. }
  6729. }, {
  6730. key: "_loadAssetsLowpolyModel",
  6731. value: function () {
  6732. var _loadAssetsLowpolyModel2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(e) {
  6733. var _this4 = this;
  6734. var t,
  6735. r,
  6736. n,
  6737. o,
  6738. a,
  6739. s,
  6740. u,
  6741. c,
  6742. h,
  6743. _args9 = arguments;
  6744. return regenerator.wrap(function _callee9$(_context9) {
  6745. while (1) {
  6746. switch (_context9.prev = _context9.next) {
  6747. case 0:
  6748. t = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : "";
  6749. r = [], n = [], o = [];
  6750. e.lowPolyModels.forEach(function (f) {
  6751. f.group === "TV" ? n.push({
  6752. id: "",
  6753. name: "",
  6754. thumbnailUrl: "",
  6755. typeName: AssetTypeName.Model,
  6756. className: AssetClassName.Tv,
  6757. modelUrl: f.url
  6758. }) : f.group === "\u544A\u767D\u5899" ? o.push({
  6759. id: "",
  6760. name: "",
  6761. thumbnailUrl: "",
  6762. typeName: AssetTypeName.Model,
  6763. className: AssetClassName.Lpm,
  6764. modelUrl: f.url
  6765. }) : r.push({
  6766. id: "",
  6767. name: "",
  6768. thumbnailUrl: "",
  6769. typeName: AssetTypeName.Model,
  6770. className: AssetClassName.Lpm,
  6771. modelUrl: f.url
  6772. });
  6773. }), t != "" && t != null && this._deleteAssetsLowpolyModel(t);
  6774. a = e.skinId;
  6775. log$a.info("====> from ", t, " to ", a), this._tvs.forEach(function (f) {
  6776. return f.clean();
  6777. }), this._tvs = [];
  6778. s = EFitMode.cover;
  6779. a == "10048" && (s = EFitMode.contain), Array.isArray(n) && n.forEach(function (f, d) {
  6780. _this4._tvs.push(new TV("squareTv" + d, f.modelUrl, _this4.room, {
  6781. fitMode: s
  6782. }));
  6783. }), e.breathPointsConfig.forEach( /*#__PURE__*/function () {
  6784. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8(f) {
  6785. var d;
  6786. return regenerator.wrap(function _callee8$(_context8) {
  6787. while (1) {
  6788. switch (_context8.prev = _context8.next) {
  6789. case 0:
  6790. _context8.prev = 0;
  6791. _context8.next = 3;
  6792. return urlTransformer(f.imageUrl);
  6793. case 3:
  6794. d = _context8.sent;
  6795. _context8.next = 9;
  6796. break;
  6797. case 6:
  6798. _context8.prev = 6;
  6799. _context8.t0 = _context8["catch"](0);
  6800. d = f.imageUrl, log$a.error("urlTransformer error", _context8.t0);
  6801. case 9:
  6802. _this4.room.breathPointManager.addBreathPoint({
  6803. id: f.id,
  6804. position: f.position,
  6805. spriteSheet: d,
  6806. rotation: f.rotation || {
  6807. pitch: 0,
  6808. yaw: 270,
  6809. roll: 0
  6810. },
  6811. billboardMode: !0,
  6812. type: f.type || "no_type",
  6813. spriteWidthNumber: f.spriteWidthNum || 1,
  6814. spriteHeightNumber: f.spriteHeightNum || 1,
  6815. maxVisibleRegion: f.maxVisibleRegion || 150,
  6816. width: f.width,
  6817. height: f.height,
  6818. skinInfo: f.skinId
  6819. });
  6820. case 10:
  6821. case "end":
  6822. return _context8.stop();
  6823. }
  6824. }
  6825. }, _callee8, null, [[0, 6]]);
  6826. }));
  6827. return function (_x9) {
  6828. return _ref.apply(this, arguments);
  6829. };
  6830. }()), o.forEach(function (f) {
  6831. _this4.room.sceneManager.decalComponent.addDecal({
  6832. id: f.id || "gbq",
  6833. meshPath: f.modelUrl,
  6834. skinInfo: a
  6835. });
  6836. });
  6837. u = this.room.sceneManager.staticmeshComponent.lowModel_group, c = Array.from(u.keys()).filter(function (f) {
  6838. return !f.startsWith("region_");
  6839. }), h = ["airship", "balloon", "ground_feiting", "ground_reqiqiu", "default"];
  6840. return _context9.abrupt("return", new Promise(function (f, d) {
  6841. Promise.all(h.map(function (_) {
  6842. return _this4._parseModelsAndLoad(r, _, a);
  6843. })).then(function () {
  6844. var _ = !1;
  6845. r.forEach(function (v) {
  6846. v.modelUrl.endsWith("zip") && (_ = !0);
  6847. }), _ == !1 && _this4.room.sceneManager.staticmeshComponent.deleteLastRegionMesh(), _this4.room.sceneManager.staticmeshComponent.lowModel_group;
  6848. var g = Array.from(u.keys()).filter(function (v) {
  6849. return !v.startsWith("region_");
  6850. }),
  6851. m = c.filter(function (v) {
  6852. return g.indexOf(v) < 0;
  6853. });
  6854. m.length > 0 && m.forEach(function (v) {
  6855. _this4.room.sceneManager.staticmeshComponent.deleteMeshesByGroup(v);
  6856. }), f(!0);
  6857. }).catch(function (_) {
  6858. d(_);
  6859. });
  6860. }));
  6861. case 9:
  6862. case "end":
  6863. return _context9.stop();
  6864. }
  6865. }
  6866. }, _callee9, this);
  6867. }));
  6868. function _loadAssetsLowpolyModel(_x8) {
  6869. return _loadAssetsLowpolyModel2.apply(this, arguments);
  6870. }
  6871. return _loadAssetsLowpolyModel;
  6872. }()
  6873. }, {
  6874. key: "_updateSkinAssets",
  6875. value: function () {
  6876. var _updateSkinAssets2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(e) {
  6877. var t, r, n;
  6878. return regenerator.wrap(function _callee10$(_context10) {
  6879. while (1) {
  6880. switch (_context10.prev = _context10.next) {
  6881. case 0:
  6882. t = this.room.lastSkinId;
  6883. _context10.next = 3;
  6884. return this.room.getSkin(e);
  6885. case 3:
  6886. r = _context10.sent;
  6887. n = this._createAssetList(r);
  6888. _context10.prev = 5;
  6889. _context10.next = 8;
  6890. return this.loadAssets(n, t);
  6891. case 8:
  6892. this.room.updateCurrentState({
  6893. versionId: r.versionId,
  6894. skinId: r.id,
  6895. skin: r
  6896. });
  6897. _context10.next = 16;
  6898. break;
  6899. case 11:
  6900. _context10.prev = 11;
  6901. _context10.t0 = _context10["catch"](5);
  6902. _context10.next = 15;
  6903. return this.loadAssets(n, t);
  6904. case 15:
  6905. this.room.updateCurrentState({
  6906. versionId: r.versionId,
  6907. skinId: r.id,
  6908. skin: r
  6909. });
  6910. case 16:
  6911. this.setEnv(r);
  6912. case 17:
  6913. case "end":
  6914. return _context10.stop();
  6915. }
  6916. }
  6917. }, _callee10, this, [[5, 11]]);
  6918. }));
  6919. function _updateSkinAssets(_x10) {
  6920. return _updateSkinAssets2.apply(this, arguments);
  6921. }
  6922. return _updateSkinAssets;
  6923. }()
  6924. }, {
  6925. key: "_createAssetList",
  6926. value: function _createAssetList(e) {
  6927. var t = [],
  6928. r = [],
  6929. n = [];
  6930. var o = e.models;
  6931. var a = this.room.modelManager.config.preload;
  6932. return this.room.viewMode === "simple" ? a && (o = a.baseUrls.map(function (l) {
  6933. return l.modelUrl = l.url, l;
  6934. })) : this.room.viewMode, ModelManager.findModels(o, AssetTypeName.Effects, AssetClassName.Effects).forEach(function (l) {
  6935. t.push({
  6936. url: l.modelUrl,
  6937. group: l.className,
  6938. name: l.name
  6939. });
  6940. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Lpm).forEach(function (l) {
  6941. r.push({
  6942. url: l.modelUrl,
  6943. group: l.className
  6944. });
  6945. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Gbq).forEach(function (l) {
  6946. r.push({
  6947. url: l.modelUrl,
  6948. group: l.className
  6949. });
  6950. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Tv).forEach(function (l) {
  6951. r.push({
  6952. url: l.modelUrl,
  6953. group: l.className
  6954. });
  6955. }), [].forEach(function (l) {
  6956. l.skinId == e.id && n.push(l);
  6957. }), {
  6958. roomId: this.room.id,
  6959. effects: t,
  6960. lowPolyModels: r,
  6961. breathPointsConfig: n,
  6962. skinId: e.id
  6963. };
  6964. }
  6965. }, {
  6966. key: "registerStats",
  6967. value: function registerStats() {
  6968. var _this5 = this;
  6969. var e = this.room.sceneManager;
  6970. this.room.scene.registerAfterRender(function () {
  6971. var I;
  6972. var t = e.statisticComponent.getInterFrameTimeCounter(),
  6973. r = e.statisticComponent.getDrawCall(),
  6974. n = e.statisticComponent.getActiveFaces(),
  6975. o = e.statisticComponent.getFrameTimeCounter(),
  6976. a = e.statisticComponent.getDrawCallTime(),
  6977. s = e.statisticComponent.getAnimationTime(),
  6978. l = e.statisticComponent.getActiveMeshEvaluationTime(),
  6979. u = e.statisticComponent.getRenderTargetRenderTime(),
  6980. c = e.statisticComponent.getRegisterBeforeRenderTime(),
  6981. h = e.statisticComponent.getRegisterAfterRenderTime(),
  6982. f = e.statisticComponent.getActiveParticles(),
  6983. d = e.statisticComponent.getActiveBones(),
  6984. _ = e.Scene._activeAnimatables.length,
  6985. g = e.statisticComponent.getTotalRootNodes(),
  6986. m = e.Scene.geometries.length,
  6987. v = e.Scene.onBeforeRenderObservable.observers.length,
  6988. y = e.Scene.onAfterRenderObservable.observers.length,
  6989. b = e.statisticComponent.getTotalMeshes(),
  6990. T = e.statisticComponent.getTotalTextures(),
  6991. C = e.statisticComponent.getTotalMaterials(),
  6992. A = e.statisticComponent.getSystemInfo(),
  6993. S = A.resolution,
  6994. P = A.driver;
  6995. A.vender;
  6996. var R = A.version,
  6997. M = A.hardwareScalingLevel,
  6998. x = S + "_" + P + "_" + R + "_" + M;
  6999. _this5.interFrameCircularArray.add(t), _this5.renderTimeCircularArray.add(o), _this5.animationCircularArray.add(s), _this5.meshSelectCircularArray.add(l), _this5.drawCallTimeCircularArray.add(a), _this5.regAfterRenderCircularArray.add(h), _this5.regBeforeRenderCircularArray.add(c), _this5.renderTargetCircularArray.add(u), _this5.drawCallCntCircularArray.add(r), _this5.renderCnt += 1, _this5.renderCnt % 25 == 0 && ((I = _this5.room.stats) == null || I.assign({
  7000. renderFrameTime: _this5.renderTimeCircularArray.getAvg(),
  7001. maxRenderFrameTime: _this5.renderTimeCircularArray.getMax(),
  7002. interFrameTime: _this5.interFrameCircularArray.getAvg(),
  7003. animationTime: _this5.animationCircularArray.getAvg(),
  7004. meshSelectTime: _this5.meshSelectCircularArray.getAvg(),
  7005. drawcallTime: _this5.drawCallTimeCircularArray.getAvg(),
  7006. idleTime: _this5._idleTime,
  7007. registerBeforeRenderTime: _this5.regBeforeRenderCircularArray.getAvg(),
  7008. registerAfterRenderTime: _this5.regAfterRenderCircularArray.getAvg(),
  7009. renderTargetRenderTime: _this5.renderTargetCircularArray.getAvg(),
  7010. fps: (1e3 / (_this5.renderTimeCircularArray.getAvg() + _this5.interFrameCircularArray.getAvg())).toFixed(2),
  7011. drawcall: _this5.drawCallCntCircularArray.getAvg(),
  7012. triangle: n.toString(),
  7013. engineSloppyCnt: _this5.engineSloppyCnt,
  7014. maxInterFrameTime: _this5.interFrameCircularArray.getMax(),
  7015. maxDrawcallTime: _this5.drawCallTimeCircularArray.getMax(),
  7016. maxMeshSelectTime: _this5.meshSelectCircularArray.getMax(),
  7017. maxAnimationTime: _this5.animationCircularArray.getMax(),
  7018. maxRegisterBeforeRenderTime: _this5.regBeforeRenderCircularArray.getMax(),
  7019. maxRegisterAfterRenderTime: _this5.regAfterRenderCircularArray.getMax(),
  7020. maxRenderTargetRenderTime: _this5.renderTargetCircularArray.getMax(),
  7021. activeParticles: f,
  7022. activeBones: d,
  7023. activeAnimation: _,
  7024. totalMeshes: b,
  7025. totalRootNodes: g,
  7026. totalGeometries: m,
  7027. totalTextures: T,
  7028. totalMaterials: C,
  7029. registerBeforeCount: v,
  7030. registerAfterCount: y,
  7031. hardwareInfo: x
  7032. }));
  7033. });
  7034. }
  7035. }, {
  7036. key: "updateBillboard",
  7037. value: function () {
  7038. var _updateBillboard = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11() {
  7039. var e, r, n, o, a, s;
  7040. return regenerator.wrap(function _callee11$(_context11) {
  7041. while (1) {
  7042. switch (_context11.prev = _context11.next) {
  7043. case 0:
  7044. e = this.room.options.skinId;
  7045. _context11.next = 3;
  7046. return this.room.modelManager.findAssetList(e);
  7047. case 3:
  7048. r = _context11.sent.filter(function (a) {
  7049. return a.typeName === AssetTypeName.Textures && a.className === AssetClassName.SayBubble;
  7050. });
  7051. n = ["bubble01", "bubble02", "bubble03"];
  7052. o = ["bubble01_npc", "bubble02_npc", "bubble03_npc"];
  7053. if (r.length) {
  7054. a = r.filter(function (l) {
  7055. return n.includes(l.name);
  7056. }).map(function (l) {
  7057. return l.url;
  7058. }), s = r.filter(function (l) {
  7059. return o.includes(l.name);
  7060. }).map(function (l) {
  7061. return l.url;
  7062. });
  7063. a.length && (XBillboardManager.userBubbleUrls = a), s.length && (XBillboardManager.npcBubbleUrls = s);
  7064. }
  7065. case 7:
  7066. case "end":
  7067. return _context11.stop();
  7068. }
  7069. }
  7070. }, _callee11, this);
  7071. }));
  7072. function updateBillboard() {
  7073. return _updateBillboard.apply(this, arguments);
  7074. }
  7075. return updateBillboard;
  7076. }()
  7077. }]);
  7078. return EngineProxy;
  7079. }();
  7080. function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7081. function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  7082. var Xverse_Room = /*#__PURE__*/function (_EventEmitter) {
  7083. _inherits(Xverse_Room, _EventEmitter);
  7084. var _super = _createSuper$2(Xverse_Room);
  7085. function Xverse_Room(e) {
  7086. var _this;
  7087. _classCallCheck(this, Xverse_Room);
  7088. _this = _super.call(this);
  7089. E(_assertThisInitialized(_this), "disableAutoTurn", !1);
  7090. E(_assertThisInitialized(_this), "options");
  7091. E(_assertThisInitialized(_this), "_currentNetworkOptions");
  7092. E(_assertThisInitialized(_this), "lastSkinId");
  7093. E(_assertThisInitialized(_this), "debug");
  7094. E(_assertThisInitialized(_this), "isFirstDataUsed", !1);
  7095. E(_assertThisInitialized(_this), "userId", null);
  7096. E(_assertThisInitialized(_this), "pathManager", new PathManager());
  7097. E(_assertThisInitialized(_this), "networkController");
  7098. E(_assertThisInitialized(_this), "_startTime", Date.now());
  7099. E(_assertThisInitialized(_this), "canvas");
  7100. E(_assertThisInitialized(_this), "modelManager");
  7101. E(_assertThisInitialized(_this), "eventsController");
  7102. E(_assertThisInitialized(_this), "panorama");
  7103. E(_assertThisInitialized(_this), "engineProxy");
  7104. E(_assertThisInitialized(_this), "_id");
  7105. E(_assertThisInitialized(_this), "skinList", []);
  7106. E(_assertThisInitialized(_this), "isHost", !1);
  7107. E(_assertThisInitialized(_this), "avatarManager", new XverseAvatarManager(_assertThisInitialized(_this)));
  7108. E(_assertThisInitialized(_this), "effectManager", new XverseEffectManager(_assertThisInitialized(_this)));
  7109. E(_assertThisInitialized(_this), "sceneManager");
  7110. E(_assertThisInitialized(_this), "scene");
  7111. E(_assertThisInitialized(_this), "breathPointManager");
  7112. E(_assertThisInitialized(_this), "_currentState");
  7113. E(_assertThisInitialized(_this), "joined", !1);
  7114. E(_assertThisInitialized(_this), "disableRotate", !1);
  7115. E(_assertThisInitialized(_this), "isPano", !1);
  7116. E(_assertThisInitialized(_this), "movingByClick", !0);
  7117. E(_assertThisInitialized(_this), "camera", new Camera(_assertThisInitialized(_this)));
  7118. E(_assertThisInitialized(_this), "stats", new Stats(_assertThisInitialized(_this)));
  7119. E(_assertThisInitialized(_this), "isUpdatedRawYUVData", !1);
  7120. E(_assertThisInitialized(_this), "actionsHandler", new ActionsHandler(_assertThisInitialized(_this)));
  7121. E(_assertThisInitialized(_this), "_currentClickingState", null);
  7122. E(_assertThisInitialized(_this), "signal", new Signal(_assertThisInitialized(_this)));
  7123. E(_assertThisInitialized(_this), "firstFrameTimestamp");
  7124. E(_assertThisInitialized(_this), "receiveRtcData", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  7125. var e, t, r, n;
  7126. return regenerator.wrap(function _callee$(_context) {
  7127. while (1) {
  7128. switch (_context.prev = _context.next) {
  7129. case 0:
  7130. logger.info("Invoke receiveRtcData");
  7131. e = !1, t = !1, r = !1, n = !1;
  7132. return _context.abrupt("return", _this.viewMode === "serverless" ? (logger.warn("set view mode to serverless"), _this.setViewMode("observer").then(function () {
  7133. return _assertThisInitialized(_this);
  7134. }, function () {
  7135. return _assertThisInitialized(_this);
  7136. })) : new Promise(function (o) {
  7137. var a = _this.networkController.rtcp.workers;
  7138. a.registerFunction("signal", function (s) {
  7139. _this.signal.handleSignal(s);
  7140. }), a.registerFunction("stream", function (s) {
  7141. var l;
  7142. if (_this.emit("streamTimestamp", {
  7143. timestamp: Date.now()
  7144. }), t || (t = !0, logger.info("Invoke stream event")), s.stream) {
  7145. r || (r = !0, logger.info("Invoke updateRawYUVData")), _this.isUpdatedRawYUVData = !1;
  7146. var u = (l = _this._currentState.skin) == null ? void 0 : l.fov;
  7147. _this.sceneManager.materialComponent.updateRawYUVData(s.stream, s.width, s.height, u), _this.isUpdatedRawYUVData = !0;
  7148. }
  7149. e || (logger.info("Invoke isAfterRenderRegistered"), e = !0, _this.scene.registerAfterRender(function () {
  7150. _this.engineProxy.frameRenderNumber >= 2 && (n || (n = !0, logger.info("Invoke registerAfterRender")), _this.isFirstDataUsed || (logger.info("Invoke isStreamAvailable"), _this.isFirstDataUsed = !0, _this.firstFrameTimestamp = Date.now(), o(_assertThisInitialized(_this)), _this.afterJoinRoom()));
  7151. }));
  7152. }), _this.panorama.bindListener(function () {
  7153. o(_assertThisInitialized(_this)), _this.afterJoinRoom();
  7154. }), a.registerFunction("reconnectedFrame", function () {}), logger.info("Invoke decoderWorker.postMessage"), a.decoderWorker.postMessage({
  7155. t: 5
  7156. });
  7157. }));
  7158. case 3:
  7159. case "end":
  7160. return _context.stop();
  7161. }
  7162. }
  7163. }, _callee);
  7164. })));
  7165. E(_assertThisInitialized(_this), "moveToExtra", "");
  7166. _this.options = e, _this.options.wsServerUrl || (_this.options.wsServerUrl = SERVER_URLS.DEV), _this.modelManager = ModelManager$1.getInstance(e.appId, e.releaseId), _this.updateReporter();
  7167. var n = e;
  7168. n.canvas;
  7169. var r = Oe(n, ["canvas"]);
  7170. logger.infoAndReportMeasurement({
  7171. metric: "startJoinRoomAt",
  7172. startTime: Date.now(),
  7173. group: "joinRoom",
  7174. extra: r,
  7175. value: 0
  7176. });
  7177. return _this;
  7178. }
  7179. _createClass(Xverse_Room, [{
  7180. key: "currentNetworkOptions",
  7181. get: function get() {
  7182. return this._currentNetworkOptions;
  7183. }
  7184. }, {
  7185. key: "viewMode",
  7186. get: function get() {
  7187. var e;
  7188. return ((e = this._currentState) == null ? void 0 : e.viewMode) || "full";
  7189. }
  7190. }, {
  7191. key: "id",
  7192. get: function get() {
  7193. return this._id;
  7194. }
  7195. }, {
  7196. key: "skinId",
  7197. get: function get() {
  7198. return this._currentState.skinId;
  7199. }
  7200. }, {
  7201. key: "skin",
  7202. get: function get() {
  7203. return this._currentState.skin;
  7204. }
  7205. }, {
  7206. key: "sessionId",
  7207. get: function get() {
  7208. return this.currentNetworkOptions.sessionId;
  7209. }
  7210. }, {
  7211. key: "pictureQualityLevel",
  7212. get: function get() {
  7213. return this.currentState.pictureQualityLevel;
  7214. }
  7215. }, {
  7216. key: "avatars",
  7217. get: function get() {
  7218. return Array.from(this.avatarManager.avatars.values());
  7219. }
  7220. }, {
  7221. key: "currentState",
  7222. get: function get() {
  7223. var e;
  7224. return le(oe({}, this._currentState), {
  7225. state: (e = this.networkController) == null ? void 0 : e._state
  7226. });
  7227. }
  7228. }, {
  7229. key: "_userAvatar",
  7230. get: function get() {
  7231. var _this2 = this;
  7232. return this.avatars.find(function (e) {
  7233. return e.userId === _this2.userId;
  7234. });
  7235. }
  7236. }, {
  7237. key: "tvs",
  7238. get: function get() {
  7239. return this.engineProxy._tvs;
  7240. }
  7241. }, {
  7242. key: "tv",
  7243. get: function get() {
  7244. return this.tvs[0];
  7245. }
  7246. }, {
  7247. key: "currentClickingState",
  7248. get: function get() {
  7249. return this._currentClickingState;
  7250. }
  7251. }, {
  7252. key: "afterJoinRoomHook",
  7253. value: function afterJoinRoomHook() {}
  7254. }, {
  7255. key: "beforeJoinRoomResolveHook",
  7256. value: function beforeJoinRoomResolveHook() {}
  7257. }, {
  7258. key: "afterReconnectedHook",
  7259. value: function afterReconnectedHook() {}
  7260. }, {
  7261. key: "handleSignalHook",
  7262. value: function handleSignalHook(e) {}
  7263. }, {
  7264. key: "skinChangedHook",
  7265. value: function skinChangedHook() {}
  7266. }, {
  7267. key: "beforeStartGameHook",
  7268. value: function () {
  7269. var _beforeStartGameHook = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  7270. return regenerator.wrap(function _callee2$(_context2) {
  7271. while (1) {
  7272. switch (_context2.prev = _context2.next) {
  7273. case 0:
  7274. case "end":
  7275. return _context2.stop();
  7276. }
  7277. }
  7278. }, _callee2);
  7279. }));
  7280. function beforeStartGameHook(_x) {
  7281. return _beforeStartGameHook.apply(this, arguments);
  7282. }
  7283. return beforeStartGameHook;
  7284. }()
  7285. }, {
  7286. key: "loadAssetsHook",
  7287. value: function loadAssetsHook() {}
  7288. }, {
  7289. key: "afterUserAvatarLoadedHook",
  7290. value: function afterUserAvatarLoadedHook() {}
  7291. }, {
  7292. key: "audienceViewModeHook",
  7293. value: function audienceViewModeHook() {}
  7294. }, {
  7295. key: "setViewModeToObserver",
  7296. value: function setViewModeToObserver() {}
  7297. }, {
  7298. key: "handleVehicleHook",
  7299. value: function handleVehicleHook(e) {}
  7300. }, {
  7301. key: "updateReporter",
  7302. value: function updateReporter() {
  7303. var _this$options = this.options,
  7304. e = _this$options.avatarId,
  7305. t = _this$options.skinId,
  7306. r = _this$options.userId,
  7307. n = _this$options.roomId,
  7308. o = _this$options.role,
  7309. a = _this$options.appId,
  7310. s = _this$options.wsServerUrl;
  7311. reporter$1.updateHeader({
  7312. userId: r
  7313. }), reporter$1.updateBody({
  7314. roomId: n,
  7315. role: o,
  7316. skinId: t,
  7317. avatarId: e,
  7318. appId: a,
  7319. wsServerUrl: s
  7320. });
  7321. }
  7322. }, {
  7323. key: "initRoom",
  7324. value: function () {
  7325. var _initRoom2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  7326. var _this$options$timeout, e;
  7327. return regenerator.wrap(function _callee3$(_context3) {
  7328. while (1) {
  7329. switch (_context3.prev = _context3.next) {
  7330. case 0:
  7331. _this$options$timeout = this.options.timeout, e = _this$options$timeout === void 0 ? DEFAULT_JOINROOM_TIMEOUT : _this$options$timeout;
  7332. if (!util.isSupported()) {
  7333. _context3.next = 5;
  7334. break;
  7335. }
  7336. return _context3.abrupt("return", this._initRoom()._timeout(e, new TimeoutError("initRoom timeout")));
  7337. case 5:
  7338. return _context3.abrupt("return", Promise.reject(new UnsupportedError()));
  7339. case 6:
  7340. case "end":
  7341. return _context3.stop();
  7342. }
  7343. }
  7344. }, _callee3, this);
  7345. }));
  7346. function initRoom() {
  7347. return _initRoom2.apply(this, arguments);
  7348. }
  7349. return initRoom;
  7350. }()
  7351. }, {
  7352. key: "_initRoom",
  7353. value: function () {
  7354. var _initRoom3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  7355. var e, _this$options2, t, r, n, o, a, s, l, u, c, _this$options2$isAllS, h, f, d, _, g, m, v, _this$options2$firend, y, _this$options2$syncBy, b, T, _this$options2$attitu, C, A, _this$options2$viewMo, S, P, R, M, _this$options2$hasAva, x, _this$options2$syncTo, I, _this$options2$priori, w, _this$options2$remove, O, D, F, V, N;
  7356. return regenerator.wrap(function _callee4$(_context4) {
  7357. while (1) {
  7358. switch (_context4.prev = _context4.next) {
  7359. case 0:
  7360. e = this.validateOptions(this.options);
  7361. if (!e) {
  7362. _context4.next = 3;
  7363. break;
  7364. }
  7365. return _context4.abrupt("return", (logger.error("initRoom param error", e), Promise.reject(e)));
  7366. case 3:
  7367. _this$options2 = this.options, t = _this$options2.canvas, r = _this$options2.avatarId, n = _this$options2.skinId, o = _this$options2.userId, a = _this$options2.wsServerUrl, s = _this$options2.role, l = _this$options2.token, u = _this$options2.pageSession, c = _this$options2.rotationRenderType, _this$options2$isAllS = _this$options2.isAllSync, h = _this$options2$isAllS === void 0 ? !1 : _this$options2$isAllS, f = _this$options2.appId, d = _this$options2.camera, _ = _this$options2.player, g = _this$options2.avatarComponents, m = _this$options2.nickname, v = _this$options2.avatarScale, _this$options2$firend = _this$options2.firends, y = _this$options2$firend === void 0 ? [] : _this$options2$firend, _this$options2$syncBy = _this$options2.syncByEvent, b = _this$options2$syncBy === void 0 ? !1 : _this$options2$syncBy, T = _this$options2.areaName, _this$options2$attitu = _this$options2.attitude, C = _this$options2$attitu === void 0 ? MotionType$1.Walk : _this$options2$attitu, A = _this$options2.pathName, _this$options2$viewMo = _this$options2.viewMode, S = _this$options2$viewMo === void 0 ? "full" : _this$options2$viewMo, P = _this$options2.person, R = _this$options2.roomId, M = _this$options2.roomTypeId, _this$options2$hasAva = _this$options2.hasAvatar, x = _this$options2$hasAva === void 0 ? !1 : _this$options2$hasAva, _this$options2$syncTo = _this$options2.syncToOthers, I = _this$options2$syncTo === void 0 ? !1 : _this$options2$syncTo, _this$options2$priori = _this$options2.prioritySync, w = _this$options2$priori === void 0 ? !1 : _this$options2$priori, _this$options2$remove = _this$options2.removeWhenDisconnected, O = _this$options2$remove === void 0 ? !0 : _this$options2$remove, D = _this$options2.extra;
  7368. this.setCurrentNetworkOptions({
  7369. avatarId: r,
  7370. skinId: n,
  7371. roomId: R,
  7372. userId: o,
  7373. wsServerUrl: a,
  7374. role: s,
  7375. token: l,
  7376. pageSession: u,
  7377. rotationRenderType: c,
  7378. isAllSync: h,
  7379. appId: f,
  7380. camera: d,
  7381. player: _,
  7382. avatarComponents: g,
  7383. nickname: m,
  7384. avatarScale: v,
  7385. firends: y,
  7386. syncByEvent: b,
  7387. areaName: T,
  7388. attitude: C,
  7389. pathName: A,
  7390. person: P,
  7391. roomTypeId: M,
  7392. hasAvatar: x,
  7393. syncToOthers: I,
  7394. prioritySync: w,
  7395. extra: D,
  7396. removeWhenDisconnected: O
  7397. });
  7398. this.userId = o;
  7399. this.canvas = t;
  7400. T && (this.pathManager.currentArea = T);
  7401. this.networkController = new NetworkController(this);
  7402. this.setCurrentState({
  7403. areaName: T,
  7404. pathName: A,
  7405. attitude: C,
  7406. speed: 0,
  7407. viewMode: S,
  7408. state: this.networkController._state,
  7409. skinId: n
  7410. });
  7411. _context4.prev = 10;
  7412. _context4.next = 13;
  7413. return Promise.all([this.initNetwork(), this.initConfig(), this.initWasm()]);
  7414. case 13:
  7415. logger.info("network config wasm all ready, start to create game");
  7416. _context4.next = 16;
  7417. return this.requestCreateRoom({
  7418. skinId: n
  7419. });
  7420. case 16:
  7421. F = _context4.sent;
  7422. V = F.routeList.find(function (L) {
  7423. return L.areaName === T;
  7424. });
  7425. N = ((V == null ? void 0 : V.step) || 7.5) * 30;
  7426. this.updateCurrentState({
  7427. skin: F,
  7428. skinId: F.id,
  7429. versionId: F.versionId,
  7430. speed: N
  7431. });
  7432. _context4.next = 22;
  7433. return this.initEngine(F);
  7434. case 22:
  7435. _context4.next = 27;
  7436. break;
  7437. case 24:
  7438. _context4.prev = 24;
  7439. _context4.t0 = _context4["catch"](10);
  7440. return _context4.abrupt("return", Promise.reject(_context4.t0));
  7441. case 27:
  7442. return _context4.abrupt("return", (this.beforeJoinRoomResolve(), this.receiveRtcData()));
  7443. case 28:
  7444. case "end":
  7445. return _context4.stop();
  7446. }
  7447. }
  7448. }, _callee4, this, [[10, 24]]);
  7449. }));
  7450. function _initRoom() {
  7451. return _initRoom3.apply(this, arguments);
  7452. }
  7453. return _initRoom;
  7454. }()
  7455. }, {
  7456. key: "beforeJoinRoomResolve",
  7457. value: function beforeJoinRoomResolve() {
  7458. this.setupStats(), this.eventsController = new EventsController(this), this.eventsController.bindEvents(), this.panorama = new Panorama(this), this.beforeJoinRoomResolveHook();
  7459. }
  7460. }, {
  7461. key: "afterJoinRoom",
  7462. value: function afterJoinRoom() {
  7463. this.joined = !0, this.viewMode === "observer" && this.setViewModeToObserver(), logger.infoAndReportMeasurement({
  7464. tag: this.viewMode,
  7465. value: this.firstFrameTimestamp - this._startTime,
  7466. startTime: Date.now(),
  7467. metric: "joinRoom"
  7468. }), this.camera.initialFov = this.sceneManager.cameraComponent.getCameraFov(), this.stats.on("stats", function (_ref2) {
  7469. var e = _ref2.stats;
  7470. reporter$1.report("stats", oe({}, e));
  7471. }), this.debug = new Debug(this), this.afterJoinRoomHook();
  7472. }
  7473. }, {
  7474. key: "afterReconnected",
  7475. value: function afterReconnected() {
  7476. this.avatarManager.clearOtherUsers(), this.afterReconnectedHook();
  7477. }
  7478. }, {
  7479. key: "leave",
  7480. value: function leave() {
  7481. var e, t;
  7482. return logger.info("Invoke room.leave"), (e = this.eventsController) == null || e.clearEvents(), (t = this.networkController) == null || t.quit(), this;
  7483. }
  7484. }, {
  7485. key: "validateOptions",
  7486. value: function validateOptions(e) {
  7487. var _ref3 = e || {},
  7488. t = _ref3.canvas,
  7489. r = _ref3.avatarId,
  7490. n = _ref3.skinId,
  7491. o = _ref3.userId,
  7492. a = _ref3.role;
  7493. _ref3.roomId;
  7494. var l = _ref3.token,
  7495. u = _ref3.appId;
  7496. _ref3.avatarComponents;
  7497. var h = [];
  7498. t instanceof HTMLCanvasElement || h.push(new ParamError$1("`canvas` must be instanceof of HTMLCanvasElement"));
  7499. (!o || typeof o != "string") && h.push(new ParamError$1("`userId` must be string"));
  7500. (!l || typeof l != "string") && h.push(new ParamError$1("`token` must be string"));
  7501. (!u || typeof u != "string") && h.push(new ParamError$1("`appId` must be string"));
  7502. a == "audience" || (!r || !n) && h.push(new ParamError$1("`avatarId` and `skinId` is required when create room"));
  7503. return h[0];
  7504. }
  7505. }, {
  7506. key: "initNetwork",
  7507. value: function () {
  7508. var _initNetwork = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  7509. var e;
  7510. return regenerator.wrap(function _callee5$(_context5) {
  7511. while (1) {
  7512. switch (_context5.prev = _context5.next) {
  7513. case 0:
  7514. if (!(this.viewMode === "serverless")) {
  7515. _context5.next = 2;
  7516. break;
  7517. }
  7518. return _context5.abrupt("return", Promise.resolve());
  7519. case 2:
  7520. e = Date.now();
  7521. _context5.prev = 3;
  7522. _context5.next = 6;
  7523. return this.networkController.connect()._timeout(8e3, new InitNetworkTimeoutError());
  7524. case 6:
  7525. logger.infoAndReportMeasurement({
  7526. metric: "networkInitAt",
  7527. startTime: this._startTime,
  7528. group: "joinRoom"
  7529. });
  7530. logger.infoAndReportMeasurement({
  7531. metric: "networkInitCost",
  7532. startTime: e,
  7533. group: "joinRoom"
  7534. });
  7535. _context5.next = 13;
  7536. break;
  7537. case 10:
  7538. _context5.prev = 10;
  7539. _context5.t0 = _context5["catch"](3);
  7540. throw logger.infoAndReportMeasurement({
  7541. metric: "networkInitAt",
  7542. startTime: e,
  7543. group: "joinRoom",
  7544. error: _context5.t0
  7545. }), _context5.t0;
  7546. case 13:
  7547. case "end":
  7548. return _context5.stop();
  7549. }
  7550. }
  7551. }, _callee5, this, [[3, 10]]);
  7552. }));
  7553. function initNetwork() {
  7554. return _initNetwork.apply(this, arguments);
  7555. }
  7556. return initNetwork;
  7557. }()
  7558. }, {
  7559. key: "initConfig",
  7560. value: function () {
  7561. var _initConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  7562. var e;
  7563. return regenerator.wrap(function _callee6$(_context6) {
  7564. while (1) {
  7565. switch (_context6.prev = _context6.next) {
  7566. case 0:
  7567. e = Date.now();
  7568. _context6.prev = 1;
  7569. _context6.next = 4;
  7570. return this.modelManager.getApplicationConfig()._timeout(8e3, new InitConfigTimeoutError());
  7571. case 4:
  7572. logger.infoAndReportMeasurement({
  7573. metric: "configInitAt",
  7574. startTime: this._startTime,
  7575. group: "joinRoom"
  7576. });
  7577. logger.infoAndReportMeasurement({
  7578. metric: "configInitCost",
  7579. startTime: e,
  7580. group: "joinRoom"
  7581. });
  7582. _context6.next = 11;
  7583. break;
  7584. case 8:
  7585. _context6.prev = 8;
  7586. _context6.t0 = _context6["catch"](1);
  7587. throw logger.infoAndReportMeasurement({
  7588. metric: "configInitAt",
  7589. startTime: e,
  7590. group: "joinRoom",
  7591. error: _context6.t0
  7592. }), _context6.t0;
  7593. case 11:
  7594. case "end":
  7595. return _context6.stop();
  7596. }
  7597. }
  7598. }, _callee6, this, [[1, 8]]);
  7599. }));
  7600. function initConfig() {
  7601. return _initConfig.apply(this, arguments);
  7602. }
  7603. return initConfig;
  7604. }()
  7605. }, {
  7606. key: "initEngine",
  7607. value: function () {
  7608. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  7609. var t, n;
  7610. return regenerator.wrap(function _callee7$(_context7) {
  7611. while (1) {
  7612. switch (_context7.prev = _context7.next) {
  7613. case 0:
  7614. t = Date.now();
  7615. _context7.prev = 1;
  7616. this.engineProxy = new EngineProxy(this);
  7617. _context7.next = 5;
  7618. return this.engineProxy.initEngine(e);
  7619. case 5:
  7620. logger.infoAndReportMeasurement({
  7621. metric: "webglInitAt",
  7622. startTime: this._startTime,
  7623. group: "joinRoom"
  7624. });
  7625. logger.infoAndReportMeasurement({
  7626. metric: "webglInitCost",
  7627. startTime: t,
  7628. group: "joinRoom"
  7629. });
  7630. return _context7.abrupt("return");
  7631. case 10:
  7632. _context7.prev = 10;
  7633. _context7.t0 = _context7["catch"](1);
  7634. n = _context7.t0;
  7635. return _context7.abrupt("return", (_context7.t0.code !== Codes.InitEngineTimeout && (n = new InitEngineError()), logger.error(_context7.t0), logger.infoAndReportMeasurement({
  7636. metric: "webglInitAt",
  7637. startTime: t,
  7638. group: "joinRoom",
  7639. error: n
  7640. }), Promise.reject(n)));
  7641. case 14:
  7642. case "end":
  7643. return _context7.stop();
  7644. }
  7645. }
  7646. }, _callee7, this, [[1, 10]]);
  7647. }));
  7648. function initEngine(_x2) {
  7649. return _initEngine.apply(this, arguments);
  7650. }
  7651. return initEngine;
  7652. }()
  7653. }, {
  7654. key: "initWasm",
  7655. value: function () {
  7656. var _initWasm = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  7657. var _this3 = this;
  7658. var e;
  7659. return regenerator.wrap(function _callee8$(_context8) {
  7660. while (1) {
  7661. switch (_context8.prev = _context8.next) {
  7662. case 0:
  7663. if (!(this.viewMode === "serverless")) {
  7664. _context8.next = 2;
  7665. break;
  7666. }
  7667. return _context8.abrupt("return", Promise.resolve());
  7668. case 2:
  7669. e = Date.now();
  7670. _context8.prev = 3;
  7671. _context8.next = 6;
  7672. return this.networkController.rtcp.workers.init(this.options.resolution)._timeout(8e3, new InitDecoderTimeoutError());
  7673. case 6:
  7674. this.networkController.rtcp.workers.registerFunction("error", function (t) {
  7675. logger.error("decode error", t);
  7676. var r = t.code,
  7677. n = t.message;
  7678. _this3.emit("error", {
  7679. code: r,
  7680. msg: n
  7681. });
  7682. });
  7683. logger.infoAndReportMeasurement({
  7684. metric: "wasmInitAt",
  7685. group: "joinRoom",
  7686. startTime: this._startTime
  7687. });
  7688. logger.infoAndReportMeasurement({
  7689. metric: "wasmInitCost",
  7690. group: "joinRoom",
  7691. startTime: e
  7692. });
  7693. eventsManager.on("traceId", function (t) {
  7694. _this3.networkController.rtcp.workers.onTraceId(t);
  7695. });
  7696. _context8.next = 15;
  7697. break;
  7698. case 12:
  7699. _context8.prev = 12;
  7700. _context8.t0 = _context8["catch"](3);
  7701. throw logger.infoAndReportMeasurement({
  7702. metric: "wasmInitAt",
  7703. group: "joinRoom",
  7704. startTime: e,
  7705. error: _context8.t0
  7706. }), _context8.t0;
  7707. case 15:
  7708. case "end":
  7709. return _context8.stop();
  7710. }
  7711. }
  7712. }, _callee8, this, [[3, 12]]);
  7713. }));
  7714. function initWasm() {
  7715. return _initWasm.apply(this, arguments);
  7716. }
  7717. return initWasm;
  7718. }()
  7719. }, {
  7720. key: "requestCreateRoom",
  7721. value: function () {
  7722. var _requestCreateRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(_ref4) {
  7723. var e, t, r, _ref5, n, o, _yield$this$networkCo, _r, _n, _o, a, s;
  7724. return regenerator.wrap(function _callee9$(_context9) {
  7725. while (1) {
  7726. switch (_context9.prev = _context9.next) {
  7727. case 0:
  7728. e = _ref4.skinId;
  7729. if (!e) {
  7730. _context9.next = 11;
  7731. break;
  7732. }
  7733. _context9.next = 4;
  7734. return this.getSkin(e);
  7735. case 4:
  7736. t = _context9.sent;
  7737. _context9.next = 7;
  7738. return this.modelManager.findRoute(e, this.options.pathName);
  7739. case 7:
  7740. r = _context9.sent;
  7741. this.updateCurrentNetworkOptions({
  7742. areaName: r.areaName,
  7743. attitude: r.attitude,
  7744. versionId: t.versionId
  7745. });
  7746. _ref5 = getRandomItem(r.birthPointList) || this.options, n = _ref5.camera, o = _ref5.player;
  7747. this.options.camera || this.updateCurrentNetworkOptions({
  7748. camera: n
  7749. }), this.options.player || this.updateCurrentNetworkOptions({
  7750. player: o
  7751. });
  7752. case 11:
  7753. if (!(this.viewMode === "serverless")) {
  7754. _context9.next = 13;
  7755. break;
  7756. }
  7757. return _context9.abrupt("return", t);
  7758. case 13:
  7759. _context9.prev = 13;
  7760. _context9.next = 16;
  7761. return this.beforeStartGameHook(this.options);
  7762. case 16:
  7763. _context9.next = 18;
  7764. return this.networkController.startGame();
  7765. case 18:
  7766. _yield$this$networkCo = _context9.sent;
  7767. _r = _yield$this$networkCo.room_id;
  7768. _n = _yield$this$networkCo.data;
  7769. _o = _yield$this$networkCo.session_id;
  7770. this._id = _r;
  7771. a = JSON.parse(_n);
  7772. this.isHost = a.IsHost, e = a.SkinID || e;
  7773. _context9.next = 27;
  7774. return this.getSkin(e);
  7775. case 27:
  7776. s = _context9.sent;
  7777. return _context9.abrupt("return", (this.updateCurrentNetworkOptions({
  7778. roomId: _r,
  7779. sessionId: _o
  7780. }), reporter$1.updateBody({
  7781. roomId: _r,
  7782. skinId: e,
  7783. serverSession: _o
  7784. }), s));
  7785. case 31:
  7786. _context9.prev = 31;
  7787. _context9.t0 = _context9["catch"](13);
  7788. throw logger.error("Request create room error", _context9.t0), _context9.t0;
  7789. case 34:
  7790. case "end":
  7791. return _context9.stop();
  7792. }
  7793. }
  7794. }, _callee9, this, [[13, 31]]);
  7795. }));
  7796. function requestCreateRoom(_x3) {
  7797. return _requestCreateRoom.apply(this, arguments);
  7798. }
  7799. return requestCreateRoom;
  7800. }()
  7801. }, {
  7802. key: "pause",
  7803. value: function pause() {
  7804. return this.engineProxy.pause();
  7805. }
  7806. }, {
  7807. key: "resume",
  7808. value: function resume() {
  7809. return this.engineProxy.resume();
  7810. }
  7811. }, {
  7812. key: "reconnect",
  7813. value: function reconnect() {
  7814. this.networkController.reconnect();
  7815. }
  7816. }, {
  7817. key: "setViewMode",
  7818. value: function () {
  7819. var _setViewMode = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(e) {
  7820. return regenerator.wrap(function _callee10$(_context10) {
  7821. while (1) {
  7822. switch (_context10.prev = _context10.next) {
  7823. case 0:
  7824. case "end":
  7825. return _context10.stop();
  7826. }
  7827. }
  7828. }, _callee10);
  7829. }));
  7830. function setViewMode(_x4) {
  7831. return _setViewMode.apply(this, arguments);
  7832. }
  7833. return setViewMode;
  7834. }()
  7835. }, {
  7836. key: "handleRepetLogin",
  7837. value: function handleRepetLogin() {
  7838. logger.warn("receive " + Codes.RepeatLogin + " for repeat login"), this.emit("repeatLogin"), reporter$1.disable(), this.networkController.quit();
  7839. }
  7840. }, {
  7841. key: "setPictureQualityLevel",
  7842. value: function setPictureQualityLevel(e) {
  7843. var t = {
  7844. high: EImageQuality.high,
  7845. low: EImageQuality.low,
  7846. average: EImageQuality.mid
  7847. };
  7848. return this.updateCurrentState({
  7849. pictureQualityLevel: e
  7850. }), this.sceneManager.setImageQuality(t[e]);
  7851. }
  7852. }, {
  7853. key: "getSkin",
  7854. value: function () {
  7855. var _getSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  7856. var t, n;
  7857. return regenerator.wrap(function _callee11$(_context11) {
  7858. while (1) {
  7859. switch (_context11.prev = _context11.next) {
  7860. case 0:
  7861. t = null;
  7862. _context11.next = 3;
  7863. return this.modelManager.getSkinsList();
  7864. case 3:
  7865. t = (this.skinList = _context11.sent).find(function (n) {
  7866. return n.id === e || n.id === e;
  7867. });
  7868. if (!t) {
  7869. _context11.next = 6;
  7870. break;
  7871. }
  7872. return _context11.abrupt("return", t);
  7873. case 6:
  7874. n = "skin is invalid: skinId: ".concat(e);
  7875. return _context11.abrupt("return", Promise.reject(new ParamError$1(n)));
  7876. case 8:
  7877. case "end":
  7878. return _context11.stop();
  7879. }
  7880. }
  7881. }, _callee11, this);
  7882. }));
  7883. function getSkin(_x5) {
  7884. return _getSkin.apply(this, arguments);
  7885. }
  7886. return getSkin;
  7887. }()
  7888. }, {
  7889. key: "setupStats",
  7890. value: function setupStats() {
  7891. this.stats.assign({
  7892. roomId: this.id,
  7893. userId: this.userId
  7894. }), setInterval(this.engineProxy.updateStats, 1e3);
  7895. }
  7896. }, {
  7897. key: "proxyEvents",
  7898. value: function proxyEvents(e, t) {
  7899. this.emit(e, t);
  7900. }
  7901. }, {
  7902. key: "setCurrentNetworkOptions",
  7903. value: function setCurrentNetworkOptions(e) {
  7904. this._currentNetworkOptions = e;
  7905. }
  7906. }, {
  7907. key: "updateCurrentNetworkOptions",
  7908. value: function updateCurrentNetworkOptions(e) {
  7909. Object.assign(this._currentNetworkOptions, e), Object.assign(this.options, e);
  7910. }
  7911. }, {
  7912. key: "setCurrentState",
  7913. value: function setCurrentState(e) {
  7914. this._currentState = e;
  7915. }
  7916. }, {
  7917. key: "updateCurrentState",
  7918. value: function updateCurrentState(e) {
  7919. e.skinId && (this.lastSkinId = this.currentState.skinId, this.updateCurrentNetworkOptions({
  7920. skinId: e.skinId
  7921. })), e.versionId && this.updateCurrentNetworkOptions({
  7922. versionId: e.versionId
  7923. }), Object.assign(this._currentState, e);
  7924. }
  7925. }]);
  7926. return Xverse_Room;
  7927. }(EventEmitter);
  7928. function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  7929. function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  7930. var XverseRoom = /*#__PURE__*/function (_Xverse_Room) {
  7931. _inherits(XverseRoom, _Xverse_Room);
  7932. var _super = _createSuper$1(XverseRoom);
  7933. function XverseRoom(e) {
  7934. var _this;
  7935. _classCallCheck(this, XverseRoom);
  7936. _this = _super.call(this, e);
  7937. _this.joyStick = new JoyStick(_assertThisInitialized(_this));
  7938. return _this;
  7939. }
  7940. _createClass(XverseRoom, [{
  7941. key: "afterJoinRoomHook",
  7942. value: function afterJoinRoomHook() {
  7943. this.joyStick.init({});
  7944. }
  7945. }]);
  7946. return XverseRoom;
  7947. }(Xverse_Room);
  7948. var BaseTable = /*#__PURE__*/function () {
  7949. function BaseTable(e, t) {
  7950. _classCallCheck(this, BaseTable);
  7951. this.db = null;
  7952. this.isCreatingTable = !1;
  7953. this.hasCleared = !1;
  7954. this.dbName = e, this.dbVersion = t;
  7955. }
  7956. _createClass(BaseTable, [{
  7957. key: "clearDataBase",
  7958. value: function () {
  7959. var _clearDataBase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  7960. var _this = this;
  7961. return regenerator.wrap(function _callee$(_context) {
  7962. while (1) {
  7963. switch (_context.prev = _context.next) {
  7964. case 0:
  7965. return _context.abrupt("return", this.hasCleared || (e && (this.hasCleared = !0), !window.indexedDB.databases) ? Promise.resolve() : new Promise(function (t, r) {
  7966. var n = window.indexedDB.deleteDatabase(_this.dbName);
  7967. n.onsuccess = function () {
  7968. t();
  7969. }, n.onerror = r;
  7970. }));
  7971. case 1:
  7972. case "end":
  7973. return _context.stop();
  7974. }
  7975. }
  7976. }, _callee, this);
  7977. }));
  7978. function clearDataBase(_x) {
  7979. return _clearDataBase.apply(this, arguments);
  7980. }
  7981. return clearDataBase;
  7982. }()
  7983. }, {
  7984. key: "tableName",
  7985. value: function tableName() {
  7986. throw new Error("Derived class have to override 'tableName', and set a proper table name!");
  7987. }
  7988. }, {
  7989. key: "keyPath",
  7990. value: function keyPath() {
  7991. throw new Error("Derived class have to override 'keyPath', and set a proper index name!");
  7992. }
  7993. }, {
  7994. key: "index",
  7995. value: function index() {
  7996. throw new Error("Derived class have to override 'index', and set a proper index name!");
  7997. }
  7998. }, {
  7999. key: "checkAndOpenDatabase",
  8000. value: function () {
  8001. var _checkAndOpenDatabase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  8002. var _this2 = this;
  8003. return regenerator.wrap(function _callee2$(_context2) {
  8004. while (1) {
  8005. switch (_context2.prev = _context2.next) {
  8006. case 0:
  8007. return _context2.abrupt("return", this.db ? Promise.resolve(this.db) : new Promise(function (e, t) {
  8008. var n = setTimeout(function () {
  8009. logger.info("wait db to open for", 200), _this2.db ? e(_this2.db) : e(_this2.checkAndOpenDatabase()), clearTimeout(n);
  8010. }, 200);
  8011. _this2.openDatabase(_this2.dbName, _this2.dbVersion || 1, function () {
  8012. _this2.db && !_this2.isCreatingTable && e(_this2.db), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable)), clearTimeout(n);
  8013. }, function () {
  8014. t(new Error("Failed to open database!")), clearTimeout(n);
  8015. }, function () {
  8016. _this2.db && e(_this2.db), clearTimeout(n), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable));
  8017. });
  8018. }));
  8019. case 1:
  8020. case "end":
  8021. return _context2.stop();
  8022. }
  8023. }
  8024. }, _callee2, this);
  8025. }));
  8026. function checkAndOpenDatabase() {
  8027. return _checkAndOpenDatabase.apply(this, arguments);
  8028. }
  8029. return checkAndOpenDatabase;
  8030. }()
  8031. }, {
  8032. key: "openDatabase",
  8033. value: function openDatabase(e, t, r, n, o) {
  8034. var _this3 = this;
  8035. if (this.isCreatingTable) return;
  8036. this.isCreatingTable = !0, logger.info(e, t);
  8037. var a = window.indexedDB.open(e, t),
  8038. s = this.tableName();
  8039. a.onsuccess = function (l) {
  8040. _this3.db = a.result, logger.info("IndexedDb ".concat(e, " is opened.")), _this3.db.objectStoreNames.contains(s) && (_this3.isCreatingTable = !1), r && r(l);
  8041. }, a.onerror = function (l) {
  8042. var u;
  8043. logger.error("Failed to open database", (u = l == null ? void 0 : l.srcElement) == null ? void 0 : u.error), _this3.isCreatingTable = !1, n && n(l), _this3.clearDataBase(!0);
  8044. }, a.onupgradeneeded = function (l) {
  8045. var u = l.target.result,
  8046. c = _this3.index();
  8047. logger.info("Creating table ".concat(s, "."));
  8048. var h = u.objectStoreNames.contains(s);
  8049. if (h) h = u.transaction([s], "readwrite").objectStore(s);else {
  8050. var f = _this3.keyPath();
  8051. h = u.createObjectStore(s, {
  8052. keyPath: f
  8053. });
  8054. }
  8055. c.map(function (f) {
  8056. h.createIndex(f, f, {
  8057. unique: !1
  8058. });
  8059. }), _this3.isCreatingTable = !1, logger.info("Table ".concat(s, " opened")), o && o(l);
  8060. };
  8061. }
  8062. }, {
  8063. key: "add",
  8064. value: function () {
  8065. var _add = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  8066. var t, o;
  8067. return regenerator.wrap(function _callee3$(_context3) {
  8068. while (1) {
  8069. switch (_context3.prev = _context3.next) {
  8070. case 0:
  8071. t = this.tableName();
  8072. _context3.next = 3;
  8073. return this.checkAndOpenDatabase();
  8074. case 3:
  8075. o = _context3.sent.transaction([t], "readwrite").objectStore(t).add(e);
  8076. return _context3.abrupt("return", new Promise(function (a, s) {
  8077. o.onsuccess = function (l) {
  8078. a(l);
  8079. }, o.onerror = function (l) {
  8080. var u;
  8081. logger.error((u = l.srcElement) == null ? void 0 : u.error), s(l);
  8082. };
  8083. }));
  8084. case 5:
  8085. case "end":
  8086. return _context3.stop();
  8087. }
  8088. }
  8089. }, _callee3, this);
  8090. }));
  8091. function add(_x2) {
  8092. return _add.apply(this, arguments);
  8093. }
  8094. return add;
  8095. }()
  8096. }, {
  8097. key: "put",
  8098. value: function () {
  8099. var _put = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  8100. var t, o;
  8101. return regenerator.wrap(function _callee4$(_context4) {
  8102. while (1) {
  8103. switch (_context4.prev = _context4.next) {
  8104. case 0:
  8105. t = this.tableName();
  8106. _context4.next = 3;
  8107. return this.checkAndOpenDatabase();
  8108. case 3:
  8109. o = _context4.sent.transaction([t], "readwrite").objectStore(t).put(e);
  8110. return _context4.abrupt("return", new Promise(function (a, s) {
  8111. o.onsuccess = function (l) {
  8112. a(l);
  8113. }, o.onerror = function (l) {
  8114. var u;
  8115. logger.error("db put error", (u = l.srcElement) == null ? void 0 : u.error), s(l);
  8116. };
  8117. }));
  8118. case 5:
  8119. case "end":
  8120. return _context4.stop();
  8121. }
  8122. }
  8123. }, _callee4, this);
  8124. }));
  8125. function put(_x3) {
  8126. return _put.apply(this, arguments);
  8127. }
  8128. return put;
  8129. }()
  8130. }, {
  8131. key: "delete",
  8132. value: function _delete(e, t, r) {
  8133. var n = this.tableName();
  8134. this.checkAndOpenDatabase().then(function (o) {
  8135. var s = o.transaction([n], "readwrite").objectStore(n).delete(e);
  8136. s.onsuccess = t, s.onerror = r;
  8137. });
  8138. }
  8139. }, {
  8140. key: "update",
  8141. value: function update() {
  8142. this.checkAndOpenDatabase().then(function (e) {});
  8143. }
  8144. }, {
  8145. key: "getAllKeys",
  8146. value: function () {
  8147. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  8148. var e, t;
  8149. return regenerator.wrap(function _callee5$(_context5) {
  8150. while (1) {
  8151. switch (_context5.prev = _context5.next) {
  8152. case 0:
  8153. e = this.tableName();
  8154. _context5.next = 3;
  8155. return this.checkAndOpenDatabase();
  8156. case 3:
  8157. t = _context5.sent;
  8158. return _context5.abrupt("return", new Promise(function (r, n) {
  8159. var a = t.transaction([e], "readonly").objectStore(e).getAllKeys();
  8160. a.onsuccess = function (s) {
  8161. r(s.target.result);
  8162. }, a.onerror = function (s) {
  8163. logger.error("db getAllKeys error", s), n(s);
  8164. };
  8165. }));
  8166. case 5:
  8167. case "end":
  8168. return _context5.stop();
  8169. }
  8170. }
  8171. }, _callee5, this);
  8172. }));
  8173. function getAllKeys() {
  8174. return _getAllKeys.apply(this, arguments);
  8175. }
  8176. return getAllKeys;
  8177. }()
  8178. }, {
  8179. key: "query",
  8180. value: function () {
  8181. var _query = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t) {
  8182. var r, n;
  8183. return regenerator.wrap(function _callee6$(_context6) {
  8184. while (1) {
  8185. switch (_context6.prev = _context6.next) {
  8186. case 0:
  8187. r = this.tableName();
  8188. _context6.next = 3;
  8189. return this.checkAndOpenDatabase();
  8190. case 3:
  8191. n = _context6.sent;
  8192. return _context6.abrupt("return", new Promise(function (o, a) {
  8193. var u = n.transaction([r], "readonly").objectStore(r).index(e).get(t);
  8194. u.onsuccess = function (c) {
  8195. var f;
  8196. var h = (f = c == null ? void 0 : c.target) == null ? void 0 : f.result;
  8197. o && o(h);
  8198. }, u.onerror = function (c) {
  8199. logger.error("db query error", c), a(c);
  8200. };
  8201. }));
  8202. case 5:
  8203. case "end":
  8204. return _context6.stop();
  8205. }
  8206. }
  8207. }, _callee6, this);
  8208. }));
  8209. function query(_x4, _x5) {
  8210. return _query.apply(this, arguments);
  8211. }
  8212. return query;
  8213. }()
  8214. }, {
  8215. key: "sleep",
  8216. value: function () {
  8217. var _sleep = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  8218. return regenerator.wrap(function _callee7$(_context7) {
  8219. while (1) {
  8220. switch (_context7.prev = _context7.next) {
  8221. case 0:
  8222. return _context7.abrupt("return", new Promise(function (t) {
  8223. setTimeout(function () {
  8224. t("");
  8225. }, e);
  8226. }));
  8227. case 1:
  8228. case "end":
  8229. return _context7.stop();
  8230. }
  8231. }
  8232. }, _callee7);
  8233. }));
  8234. function sleep(_x6) {
  8235. return _sleep.apply(this, arguments);
  8236. }
  8237. return sleep;
  8238. }()
  8239. }]);
  8240. return BaseTable;
  8241. }();
  8242. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8243. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  8244. var ModelTable = /*#__PURE__*/function (_BaseTable) {
  8245. _inherits(ModelTable, _BaseTable);
  8246. var _super = _createSuper(ModelTable);
  8247. function ModelTable() {
  8248. _classCallCheck(this, ModelTable);
  8249. return _super.call(this, "XverseDatabase", 1);
  8250. }
  8251. _createClass(ModelTable, [{
  8252. key: "tableName",
  8253. value: function tableName() {
  8254. return "models";
  8255. }
  8256. }, {
  8257. key: "index",
  8258. value: function index() {
  8259. return ["url"];
  8260. }
  8261. }, {
  8262. key: "keyPath",
  8263. value: function keyPath() {
  8264. return "url";
  8265. }
  8266. }]);
  8267. return ModelTable;
  8268. }(BaseTable);
  8269. var modelTable = new ModelTable();
  8270. var Preload = /*#__PURE__*/function () {
  8271. function Preload(e) {
  8272. _classCallCheck(this, Preload);
  8273. this.config = null;
  8274. this.allKeys = [];
  8275. this.oldResourcesDeleted = !1;
  8276. this.requests = {
  8277. simple: {
  8278. stopped: !0,
  8279. requests: {}
  8280. },
  8281. observer: {
  8282. stopped: !0,
  8283. requests: {}
  8284. },
  8285. full: {
  8286. stopped: !0,
  8287. requests: {}
  8288. }
  8289. };
  8290. this.modelManager = e, this.init(e.appId);
  8291. }
  8292. _createClass(Preload, [{
  8293. key: "init",
  8294. value: function init(e) {
  8295. reporter$1.updateBody({
  8296. appId: e
  8297. });
  8298. }
  8299. }, {
  8300. key: "getConfig",
  8301. value: function () {
  8302. var _getConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  8303. var _yield$this$modelMana, t;
  8304. return regenerator.wrap(function _callee$(_context) {
  8305. while (1) {
  8306. switch (_context.prev = _context.next) {
  8307. case 0:
  8308. if (!this.config) {
  8309. _context.next = 2;
  8310. break;
  8311. }
  8312. return _context.abrupt("return", this.config);
  8313. case 2:
  8314. _context.next = 4;
  8315. return this.modelManager.requestConfig();
  8316. case 4:
  8317. _yield$this$modelMana = _context.sent;
  8318. t = _yield$this$modelMana.preload;
  8319. return _context.abrupt("return", t ? (this.config = t, Promise.resolve(t)) : Promise.reject("no preload config"));
  8320. case 7:
  8321. case "end":
  8322. return _context.stop();
  8323. }
  8324. }
  8325. }, _callee, this);
  8326. }));
  8327. function getConfig(_x) {
  8328. return _getConfig.apply(this, arguments);
  8329. }
  8330. return getConfig;
  8331. }()
  8332. }, {
  8333. key: "getAllKeys",
  8334. value: function () {
  8335. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  8336. var e, t;
  8337. return regenerator.wrap(function _callee2$(_context2) {
  8338. while (1) {
  8339. switch (_context2.prev = _context2.next) {
  8340. case 0:
  8341. if (!this.allKeys.length) {
  8342. _context2.next = 2;
  8343. break;
  8344. }
  8345. return _context2.abrupt("return", this.allKeys);
  8346. case 2:
  8347. _context2.prev = 2;
  8348. _context2.next = 5;
  8349. return modelTable.getAllKeys();
  8350. case 5:
  8351. e = _context2.sent;
  8352. this.allKeys = e;
  8353. return _context2.abrupt("return", e);
  8354. case 10:
  8355. _context2.prev = 10;
  8356. _context2.t0 = _context2["catch"](2);
  8357. t = "preload getAllKeys error";
  8358. return _context2.abrupt("return", (logger.error(t), Promise.reject(t)));
  8359. case 14:
  8360. case "end":
  8361. return _context2.stop();
  8362. }
  8363. }
  8364. }, _callee2, this, [[2, 10]]);
  8365. }));
  8366. function getAllKeys() {
  8367. return _getAllKeys.apply(this, arguments);
  8368. }
  8369. return getAllKeys;
  8370. }()
  8371. }, {
  8372. key: "stop",
  8373. value: function stop(e) {
  8374. e === "serverless" && (e = "observer"), this.requests[e].stopped = !0;
  8375. var t = this.requests[e].requests;
  8376. Object.keys(t).forEach(function (r) {
  8377. http1.canceler.removePending(r), delete t[r];
  8378. });
  8379. }
  8380. }, {
  8381. key: "clearPreload",
  8382. value: function clearPreload(e) {
  8383. this.requests[e].stopped = !1, this.allKeys = [];
  8384. }
  8385. }, {
  8386. key: "start",
  8387. value: function () {
  8388. var _start = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e, t, r) {
  8389. var n, o, a, s, l, u, h, f, _s;
  8390. return regenerator.wrap(function _callee3$(_context3) {
  8391. while (1) {
  8392. switch (_context3.prev = _context3.next) {
  8393. case 0:
  8394. n = Date.now(), o = 0;
  8395. _context3.prev = 1;
  8396. if (!(e === "serverless" && (e = "observer"), !this.requests[e])) {
  8397. _context3.next = 4;
  8398. break;
  8399. }
  8400. return _context3.abrupt("return", Promise.reject(new ParamError("invalid stage name: " + e)));
  8401. case 4:
  8402. this.clearPreload(e);
  8403. _context3.next = 7;
  8404. return this.getConfig(e);
  8405. case 7:
  8406. a = _context3.sent;
  8407. _context3.next = 10;
  8408. return this.getAllKeys();
  8409. case 10:
  8410. s = _context3.sent;
  8411. _context3.prev = 11;
  8412. _context3.next = 14;
  8413. return this.deleteOldResources(a.assetUrls.map(function (d) {
  8414. return d.url;
  8415. }), s);
  8416. case 14:
  8417. _context3.next = 19;
  8418. break;
  8419. case 16:
  8420. _context3.prev = 16;
  8421. _context3.t0 = _context3["catch"](11);
  8422. logger.error(_context3.t0);
  8423. case 19:
  8424. l = a.baseUrls, u = a.assetUrls;
  8425. _context3.t1 = e;
  8426. _context3.next = _context3.t1 === "simple" ? 23 : _context3.t1 === "observer" ? 25 : _context3.t1 === "full" ? 27 : 29;
  8427. break;
  8428. case 23:
  8429. h = l;
  8430. return _context3.abrupt("break", 30);
  8431. case 25:
  8432. h = u;
  8433. return _context3.abrupt("break", 30);
  8434. case 27:
  8435. h = u;
  8436. return _context3.abrupt("break", 30);
  8437. case 29:
  8438. h = u;
  8439. case 30:
  8440. f = h.filter(function (d) {
  8441. return !s.includes(d.url);
  8442. });
  8443. r && isFunction(r) && (f = f.filter(r));
  8444. o = f.length;
  8445. logger.debug("keysNeedToPreload", f);
  8446. f.length || t && t(h.length, h.length);
  8447. n = Date.now();
  8448. _context3.next = 38;
  8449. return this._preload(e, f, t);
  8450. case 38:
  8451. logger.infoAndReportMeasurement({
  8452. tag: e,
  8453. startTime: n,
  8454. metric: "assetsPreload",
  8455. extra: {
  8456. total: o
  8457. }
  8458. });
  8459. return _context3.abrupt("return");
  8460. case 42:
  8461. _context3.prev = 42;
  8462. _context3.t2 = _context3["catch"](1);
  8463. _s = _context3.t2;
  8464. return _context3.abrupt("return", ((this.requests[e].stopped || axios.isCancel(_context3.t2)) && (_s = new PreloadCanceledError()), logger.infoAndReportMeasurement({
  8465. tag: e,
  8466. startTime: n,
  8467. metric: "assetsPreload",
  8468. extra: {
  8469. total: o
  8470. },
  8471. error: _s,
  8472. reportOptions: {
  8473. immediate: !0
  8474. }
  8475. }), Promise.reject(_s)));
  8476. case 46:
  8477. case "end":
  8478. return _context3.stop();
  8479. }
  8480. }
  8481. }, _callee3, this, [[1, 42], [11, 16]]);
  8482. }));
  8483. function start(_x2, _x3, _x4) {
  8484. return _start.apply(this, arguments);
  8485. }
  8486. return start;
  8487. }()
  8488. }, {
  8489. key: "deleteOldResources",
  8490. value: function deleteOldResources(e, t) {
  8491. if (!this.oldResourcesDeleted) this.oldResourcesDeleted = !0;else return Promise.resolve();
  8492. var r = t.filter(function (n) {
  8493. return !e.includes(n);
  8494. });
  8495. return logger.debug("keysNeedToDelete", r), logger.warn("keysNeedToDelete", r.length), Promise.all(r.map(function (n) {
  8496. return modelTable.delete(n);
  8497. }));
  8498. }
  8499. }, {
  8500. key: "_preload",
  8501. value: function () {
  8502. var _preload2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t, r) {
  8503. var _this = this;
  8504. var n, o, a;
  8505. return regenerator.wrap(function _callee6$(_context6) {
  8506. while (1) {
  8507. switch (_context6.prev = _context6.next) {
  8508. case 0:
  8509. n = t.length;
  8510. if (n) {
  8511. _context6.next = 3;
  8512. break;
  8513. }
  8514. return _context6.abrupt("return", Promise.resolve());
  8515. case 3:
  8516. o = 0;
  8517. a = window.setInterval(function () {
  8518. r && r(o, n), o >= n && window.clearInterval(a);
  8519. }, 1e3);
  8520. return _context6.abrupt("return", util.mapLimit(t, 10, /*#__PURE__*/function () {
  8521. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(s) {
  8522. var l, u;
  8523. return regenerator.wrap(function _callee5$(_context5) {
  8524. while (1) {
  8525. switch (_context5.prev = _context5.next) {
  8526. case 0:
  8527. l = s.size, u = s.url;
  8528. return _context5.abrupt("return", _this.requests[e].stopped ? Promise.reject(new PreloadCanceledError()) : http1.get({
  8529. url: u,
  8530. timeout: Preload.getTimeoutBySize(l),
  8531. responseType: "blob",
  8532. retry: 2,
  8533. beforeRequest: function beforeRequest() {
  8534. _this.requests[e].requests[u] = !0;
  8535. }
  8536. }).then( /*#__PURE__*/function () {
  8537. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(c) {
  8538. var h, f;
  8539. return regenerator.wrap(function _callee4$(_context4) {
  8540. while (1) {
  8541. switch (_context4.prev = _context4.next) {
  8542. case 0:
  8543. h = c.data;
  8544. if (h instanceof Blob) {
  8545. _context4.next = 3;
  8546. break;
  8547. }
  8548. return _context4.abrupt("return", (logger.error("request blob failed, type:", typeof h, u), Promise.reject("request blob failed " + u)));
  8549. case 3:
  8550. _context4.next = 5;
  8551. return blobToDataURI(h);
  8552. case 5:
  8553. f = _context4.sent;
  8554. _context4.prev = 6;
  8555. _context4.next = 9;
  8556. return modelTable.put({
  8557. url: u,
  8558. model: f
  8559. });
  8560. case 9:
  8561. return _context4.abrupt("return");
  8562. case 12:
  8563. _context4.prev = 12;
  8564. _context4.t0 = _context4["catch"](6);
  8565. return _context4.abrupt("return", (logger.error("unable to add data to indexedDB", _context4.t0), Promise.reject(new InternalError("preload db error"))));
  8566. case 15:
  8567. case "end":
  8568. return _context4.stop();
  8569. }
  8570. }
  8571. }, _callee4, null, [[6, 12]]);
  8572. }));
  8573. return function (_x9) {
  8574. return _ref2.apply(this, arguments);
  8575. };
  8576. }()).then(function () {
  8577. o++, delete _this.requests[e].requests[u];
  8578. }, function (c) {
  8579. return delete _this.requests[e].requests[u], window.clearInterval(a), Promise.reject(c);
  8580. }));
  8581. case 2:
  8582. case "end":
  8583. return _context5.stop();
  8584. }
  8585. }
  8586. }, _callee5);
  8587. }));
  8588. return function (_x8) {
  8589. return _ref.apply(this, arguments);
  8590. };
  8591. }()));
  8592. case 6:
  8593. case "end":
  8594. return _context6.stop();
  8595. }
  8596. }
  8597. }, _callee6);
  8598. }));
  8599. function _preload(_x5, _x6, _x7) {
  8600. return _preload2.apply(this, arguments);
  8601. }
  8602. return _preload;
  8603. }()
  8604. }], [{
  8605. key: "getTimeoutBySize",
  8606. value: function getTimeoutBySize(e) {
  8607. return e ? e < 500 * 1e3 ? 30 * 1e3 : e < 1e3 * 1e3 ? 60 * 1e3 : 100 * 1e3 : 100 * 1e3;
  8608. }
  8609. }]);
  8610. return Preload;
  8611. }();
  8612. var RenderType$1 = {
  8613. PathVideo: 0,
  8614. RotationVideo: 1,
  8615. RotationImage: 2,
  8616. PanoramaImage: 3,
  8617. CGVideo: 4,
  8618. ClientRotationPano: 5,
  8619. CloudRotationPano: 6
  8620. };
  8621. var Xverse = /*#__PURE__*/function () {
  8622. function Xverse(e) {
  8623. _classCallCheck(this, Xverse);
  8624. e || (e = {});
  8625. var _e = e,
  8626. t = _e.onLog,
  8627. r = _e.env,
  8628. n = _e.appId,
  8629. o = _e.releaseId,
  8630. a = _e.subPackageVersion;
  8631. this.NO_CACHE = !1, this.env = r || "PROD", this.SUB_PACKAGE_VERSION = a, this.debug && logger.setLevel(LoggerLevels.Debug);
  8632. var s = this.pageSession = util.uuid();
  8633. reporter$1.updateHeader({
  8634. pageSession: s
  8635. });
  8636. reporter$1.updateReportUrl(REPORT_URL[this.env]);
  8637. a && reporter$1.updateBody({
  8638. sdkVersion: a
  8639. });
  8640. logger.infoAndReportMeasurement({
  8641. metric: "sdkInit",
  8642. startTime: Date.now(),
  8643. extra: {
  8644. version: a,
  8645. enviroment: r,
  8646. pageSession: s
  8647. }
  8648. });
  8649. logger.debug("debug mode:", this.debug);
  8650. reporter$1.on("report", function (l) {
  8651. t && t(l);
  8652. });
  8653. if (n) {
  8654. this.appId = n, this.releaseId = o;
  8655. var l = ModelManager$1.getInstance(n, o);
  8656. this.preload = new Preload(l);
  8657. }
  8658. }
  8659. _createClass(Xverse, [{
  8660. key: "isSupported",
  8661. get: function get() {
  8662. return isSupported();
  8663. }
  8664. }, {
  8665. key: "disableLogUpload",
  8666. value: function disableLogUpload() {
  8667. reporter$1.disable(), logger.debug("logger upload has been disabled");
  8668. }
  8669. }, {
  8670. key: "getSkinList",
  8671. value: function () {
  8672. var _getSkinList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  8673. return regenerator.wrap(function _callee$(_context) {
  8674. while (1) {
  8675. switch (_context.prev = _context.next) {
  8676. case 0:
  8677. return _context.abrupt("return", []);
  8678. case 1:
  8679. case "end":
  8680. return _context.stop();
  8681. }
  8682. }
  8683. }, _callee);
  8684. }));
  8685. function getSkinList() {
  8686. return _getSkinList.apply(this, arguments);
  8687. }
  8688. return getSkinList;
  8689. }()
  8690. }, {
  8691. key: "getAvatarList",
  8692. value: function () {
  8693. var _getAvatarList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  8694. return regenerator.wrap(function _callee2$(_context2) {
  8695. while (1) {
  8696. switch (_context2.prev = _context2.next) {
  8697. case 0:
  8698. return _context2.abrupt("return", []);
  8699. case 1:
  8700. case "end":
  8701. return _context2.stop();
  8702. }
  8703. }
  8704. }, _callee2);
  8705. }));
  8706. function getAvatarList() {
  8707. return _getAvatarList.apply(this, arguments);
  8708. }
  8709. return getAvatarList;
  8710. }()
  8711. }, {
  8712. key: "getGiftList",
  8713. value: function () {
  8714. var _getGiftList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  8715. return regenerator.wrap(function _callee3$(_context3) {
  8716. while (1) {
  8717. switch (_context3.prev = _context3.next) {
  8718. case 0:
  8719. return _context3.abrupt("return", [{
  8720. id: "hack "
  8721. }]);
  8722. case 1:
  8723. case "end":
  8724. return _context3.stop();
  8725. }
  8726. }
  8727. }, _callee3);
  8728. }));
  8729. function getGiftList() {
  8730. return _getGiftList.apply(this, arguments);
  8731. }
  8732. return getGiftList;
  8733. }()
  8734. }, {
  8735. key: "joinRoom",
  8736. value: function () {
  8737. var _joinRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  8738. var t, r, n, o;
  8739. return regenerator.wrap(function _callee4$(_context4) {
  8740. while (1) {
  8741. switch (_context4.prev = _context4.next) {
  8742. case 0:
  8743. t = e.pathName || "thirdwalk", r = e.rotationRenderType || RenderType$1.RotationVideo, n = e.person || Person$1.Third, o = new XverseRoom(le(oe({}, e), {
  8744. appId: e.appId || this.appId,
  8745. releaseId: e.releaseId || this.releaseId,
  8746. pageSession: this.pageSession,
  8747. isAllSync: !0,
  8748. rotationRenderType: r,
  8749. syncByEvent: !0,
  8750. pathName: t,
  8751. person: n,
  8752. role: e.role || "audience"
  8753. }));
  8754. return _context4.abrupt("return", o.initRoom().then(function () {
  8755. return o;
  8756. }));
  8757. case 2:
  8758. case "end":
  8759. return _context4.stop();
  8760. }
  8761. }
  8762. }, _callee4, this);
  8763. }));
  8764. function joinRoom(_x) {
  8765. return _joinRoom.apply(this, arguments);
  8766. }
  8767. return joinRoom;
  8768. }()
  8769. }]);
  8770. return Xverse;
  8771. }();
  8772. var xverse = new Xverse({
  8773. env: "DEV",
  8774. appId: "10016",
  8775. releaseId: '2203120033_29769e'
  8776. });
  8777. var l = /*#__PURE__*/function () {
  8778. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  8779. var R;
  8780. return regenerator.wrap(function _callee$(_context) {
  8781. while (1) {
  8782. switch (_context.prev = _context.next) {
  8783. case 0:
  8784. _context.prev = 0;
  8785. _context.next = 3;
  8786. return (R = xverse.preload) == null ? void 0 : R.start('full', function (M, x) {
  8787. });
  8788. case 3:
  8789. _context.next = 12;
  8790. break;
  8791. case 5:
  8792. _context.prev = 5;
  8793. _context.t0 = _context["catch"](0);
  8794. if (!(console.error(_context.t0), _context.t0.code === Codes.PreloadCanceled)) {
  8795. _context.next = 10;
  8796. break;
  8797. }
  8798. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88");
  8799. return _context.abrupt("return");
  8800. case 10:
  8801. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5");
  8802. return _context.abrupt("return");
  8803. case 12:
  8804. _context.prev = 12;
  8805. _context.next = 15;
  8806. return xverse.joinRoom({
  8807. canvas: document.getElementById('canvas'),
  8808. skinId: '10092',
  8809. avatarId: 'KGe_Boy',
  8810. roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
  8811. userId: '1f7acca1db9d5',
  8812. wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
  8813. appId: "10016",
  8814. token: " ",
  8815. nickname: '1f7acca1db9d5',
  8816. firends: ["user1"],
  8817. viewMode: "full",
  8818. resolution: {
  8819. width: 1728,
  8820. height: 720
  8821. },
  8822. pathName: 'thirdwalk',
  8823. objectFit: null,
  8824. hasAvatar: !0,
  8825. syncToOthers: !0
  8826. });
  8827. case 15:
  8828. room = _context.sent;
  8829. debugger;
  8830. u();
  8831. c();
  8832. window.room = room;
  8833. e(!1);
  8834. _context.next = 28;
  8835. break;
  8836. case 23:
  8837. _context.prev = 23;
  8838. _context.t1 = _context["catch"](12);
  8839. console.error(_context.t1);
  8840. alert(_context.t1);
  8841. return _context.abrupt("return");
  8842. case 28:
  8843. case "end":
  8844. return _context.stop();
  8845. }
  8846. }
  8847. }, _callee, null, [[0, 5], [12, 23]]);
  8848. }));
  8849. return function l() {
  8850. return _ref.apply(this, arguments);
  8851. };
  8852. }();
  8853. var u = function u() {
  8854. room.on("_coreClick", function (_ref2) {
  8855. var f = _ref2.point;
  8856. room._userAvatar.moveTo({
  8857. point: f
  8858. });
  8859. });
  8860. };
  8861. var c = function c() {
  8862. room.on("repeatLogin", function () {
  8863. toast("\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55", {
  8864. duration: 1e4
  8865. });
  8866. }), room.on("reconnecting", function (_ref3) {
  8867. var f = _ref3.count;
  8868. toast("\u5C1D\u8BD5\u7B2C".concat(f, "\u6B21\u91CD\u8FDE"));
  8869. }), room.on("reconnected", function () {
  8870. toast("\u91CD\u8FDE\u6210\u529F");
  8871. }), room.on("disconnected", function () {
  8872. var f = toast("\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5", {
  8873. duration: 1e5,
  8874. onClick() {
  8875. f.hideToast(), room.reconnect();
  8876. }
  8877. });
  8878. });
  8879. };
  8880. l();
  8881. }));
  8882. //# sourceMappingURL=index.js.map