index.js 443 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818
  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. objectParseFloat(i) {
  775. var e = {};
  776. return i && Object.keys(i).forEach(function (t) {
  777. e[t] = parseFloat(i[t]);
  778. }), e;
  779. },
  780. getRandomItem(i) {
  781. i.length === 0 ? null : i[Math.floor(Math.random() * i.length)];
  782. }
  783. };
  784. function _setPrototypeOf(o, p) {
  785. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  786. o.__proto__ = p;
  787. return o;
  788. };
  789. return _setPrototypeOf(o, p);
  790. }
  791. function _inherits(subClass, superClass) {
  792. if (typeof superClass !== "function" && superClass !== null) {
  793. throw new TypeError("Super expression must either be null or a function");
  794. }
  795. subClass.prototype = Object.create(superClass && superClass.prototype, {
  796. constructor: {
  797. value: subClass,
  798. writable: true,
  799. configurable: true
  800. }
  801. });
  802. Object.defineProperty(subClass, "prototype", {
  803. writable: false
  804. });
  805. if (superClass) _setPrototypeOf(subClass, superClass);
  806. }
  807. function _typeof(obj) {
  808. "@babel/helpers - typeof";
  809. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  810. return typeof obj;
  811. } : function (obj) {
  812. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  813. }, _typeof(obj);
  814. }
  815. function _assertThisInitialized(self) {
  816. if (self === void 0) {
  817. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  818. }
  819. return self;
  820. }
  821. function _possibleConstructorReturn(self, call) {
  822. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  823. return call;
  824. } else if (call !== void 0) {
  825. throw new TypeError("Derived constructors may only return object or undefined");
  826. }
  827. return _assertThisInitialized(self);
  828. }
  829. function _getPrototypeOf(o) {
  830. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  831. return o.__proto__ || Object.getPrototypeOf(o);
  832. };
  833. return _getPrototypeOf(o);
  834. }
  835. function _createSuper$l(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$m(); 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); }; }
  836. function _isNativeReflectConstruct$m() { 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; } }
  837. var Reporter = /*#__PURE__*/function (_EventEmitter) {
  838. _inherits(Reporter, _EventEmitter);
  839. var _super = _createSuper$l(Reporter);
  840. function Reporter() {
  841. var _this;
  842. _classCallCheck(this, Reporter);
  843. _this = _super.call(this);
  844. _this._header = {};
  845. _this._body = {};
  846. _this._queue = [];
  847. _this._disabled = !1;
  848. _this._interval = null;
  849. _this._reportUrl = null;
  850. _this.isDocumentLoaded = function () {
  851. return document.readyState === "complete";
  852. };
  853. _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 () {
  854. _this._flushReport();
  855. }, 10 * 1e3);
  856. return _this;
  857. }
  858. _createClass(Reporter, [{
  859. key: "disable",
  860. value: function disable() {
  861. this._disabled = !0, this._interval && window.clearInterval(this._interval);
  862. }
  863. }, {
  864. key: "updateHeader",
  865. value: function updateHeader(e) {
  866. Object.assign(this._header, e);
  867. }
  868. }, {
  869. key: "updateBody",
  870. value: function updateBody(e) {
  871. Object.assign(this._body, e);
  872. }
  873. }, {
  874. key: "updateReportUrl",
  875. value: function updateReportUrl(e) {
  876. this._reportUrl = e;
  877. }
  878. }, {
  879. key: "report",
  880. value: function report(e, t, r) {
  881. var _this2 = this;
  882. if (this._disabled) return;
  883. r || (r = {});
  884. var _r = r,
  885. n = _r.immediate,
  886. o = _r.sampleRate;
  887. if (o && o > Math.random()) return;
  888. this.updateBody({
  889. logTime: util.getFormattedDate(new Date()),
  890. logTimestamp: Date.now()
  891. });
  892. var a = function a(s) {
  893. var l = oe(le(oe({}, _this2._body), {
  894. type: e
  895. }), s);
  896. _this2._queue.push(l), e === "measurement" && _this2.emit("report", s);
  897. };
  898. Array.isArray(t) ? t.forEach(function (s) {
  899. return a(s);
  900. }) : a(t), (n || this._queue.length >= REPORT_NUM_PER_REQUEST) && this._flushReport();
  901. }
  902. }, {
  903. key: "_flushReport",
  904. value: function _flushReport() {
  905. if (this._disabled || !this._queue.length || !this.isDocumentLoaded()) return;
  906. var e = {
  907. header: this._header,
  908. body: this._queue.splice(0, REPORT_NUM_PER_REQUEST)
  909. };
  910. this._post(e);
  911. }
  912. }, {
  913. key: "_post",
  914. value: function _post(e) {
  915. var t = this._reportUrl || REPORT_URL.DEV;
  916. return new Promise(function (r, n) {
  917. var o = new XMLHttpRequest();
  918. o.open("POST", t), o.setRequestHeader("Content-Type", "application/json");
  919. try {
  920. o.send(JSON.stringify(e));
  921. } catch (a) {
  922. console.error(a);
  923. }
  924. o.addEventListener("readystatechange", function () {
  925. if (o.readyState == 4) return o.status == 200 ? r(o) : n("Unable to send log");
  926. });
  927. });
  928. }
  929. }]);
  930. return Reporter;
  931. }(EventEmitter);
  932. var reporter$1 = new Reporter();
  933. function _arrayLikeToArray$2(arr, len) {
  934. if (len == null || len > arr.length) len = arr.length;
  935. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  936. arr2[i] = arr[i];
  937. }
  938. return arr2;
  939. }
  940. function _arrayWithoutHoles(arr) {
  941. if (Array.isArray(arr)) return _arrayLikeToArray$2(arr);
  942. }
  943. function _iterableToArray(iter) {
  944. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  945. }
  946. function _unsupportedIterableToArray$2(o, minLen) {
  947. if (!o) return;
  948. if (typeof o === "string") return _arrayLikeToArray$2(o, minLen);
  949. var n = Object.prototype.toString.call(o).slice(8, -1);
  950. if (n === "Object" && o.constructor) n = o.constructor.name;
  951. if (n === "Map" || n === "Set") return Array.from(o);
  952. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen);
  953. }
  954. function _nonIterableSpread() {
  955. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  956. }
  957. function _toConsumableArray(arr) {
  958. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$2(arr) || _nonIterableSpread();
  959. }
  960. var Codes = {
  961. Success: 0,
  962. Param: 1001,
  963. Internal: 1002,
  964. Timeout: 1003,
  965. Authentication: 1004,
  966. TokenExpired: 1005,
  967. Unsupported: 1006,
  968. InitNetworkTimeout: 1007,
  969. InitDecoderTimeout: 1008,
  970. InitConfigTimeout: 1009,
  971. InitEngineTimeout: 1010,
  972. InitEngine: 1011,
  973. ActionBlocked: 1012,
  974. PreloadCanceled: 1013,
  975. FrequencyLimit: 1014,
  976. UsersUpperLimit: 2e3,
  977. RoomsUpperLimit: 2001,
  978. ServerParam: 2002,
  979. LackOfToken: 2003,
  980. LoginFailed: 2004,
  981. VerifyServiceDown: 2005,
  982. CreateSessionFailed: 2006,
  983. RtcConnection: 2008,
  984. DoActionFailed: 2009,
  985. StateSyncFailed: 2010,
  986. BroadcastFailed: 2011,
  987. DataAbnormal: 2012,
  988. GetOnVehicle: 2015,
  989. RepeatLogin: 2017,
  990. RoomDoseNotExist: 2018,
  991. TicketExpire: 2019,
  992. ServerRateLimit: 2020,
  993. DoActionBlocked: 2333,
  994. ActionMaybeDelay: 2334,
  995. ActionResponseTimeout: 2999
  996. };
  997. var Logger = /*#__PURE__*/function () {
  998. function Logger(e) {
  999. _classCallCheck(this, Logger);
  1000. this.level = 3;
  1001. this.module = e;
  1002. }
  1003. _createClass(Logger, [{
  1004. key: "setLevel",
  1005. value: function setLevel(e) {
  1006. this.level = e;
  1007. }
  1008. }, {
  1009. key: "atleast",
  1010. value: function atleast(e) {
  1011. return e >= this.level && e >= this.level;
  1012. }
  1013. }, {
  1014. key: "print",
  1015. value: function print(e, t) {
  1016. for (var _len = arguments.length, r = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  1017. r[_key - 2] = arguments[_key];
  1018. }
  1019. if (this.atleast(t)) {
  1020. var _console$n;
  1021. var n = e == "debug" ? "info" : e,
  1022. o = this.prefix(e);
  1023. (_console$n = console[n]).call.apply(_console$n, [null, o].concat(r));
  1024. }
  1025. if (e !== "debug" && e !== "info") {
  1026. var _n = r.map(function (o) {
  1027. if (o instanceof Object) try {
  1028. return JSON.stringify(o);
  1029. } catch (_unused) {
  1030. return o;
  1031. } else return o;
  1032. }).join(",");
  1033. reporter$1.report("log", {
  1034. message: _n,
  1035. level: e,
  1036. module: this.module
  1037. });
  1038. }
  1039. }
  1040. }, {
  1041. key: "debug",
  1042. value: function debug() {
  1043. for (var _len2 = arguments.length, e = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  1044. e[_key2] = arguments[_key2];
  1045. }
  1046. return this.print.apply(this, ["debug", 1].concat(e));
  1047. }
  1048. }, {
  1049. key: "info",
  1050. value: function info() {
  1051. for (var _len3 = arguments.length, e = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  1052. e[_key3] = arguments[_key3];
  1053. }
  1054. return this.print.apply(this, ["info", 2].concat(e));
  1055. }
  1056. }, {
  1057. key: "infoAndReportLog",
  1058. value: function infoAndReportLog(e) {
  1059. for (var _len4 = arguments.length, t = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
  1060. t[_key4 - 1] = arguments[_key4];
  1061. }
  1062. var r = e.reportOptions;
  1063. delete e.reportOptions, reporter$1.report("log", e, r), t.length || (t = [e.message]), this.debug.apply(this, _toConsumableArray(t));
  1064. }
  1065. }, {
  1066. key: "infoAndReportMeasurement",
  1067. value: function infoAndReportMeasurement(e) {
  1068. for (var _len5 = arguments.length, t = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
  1069. t[_key5 - 1] = arguments[_key5];
  1070. }
  1071. var n;
  1072. var r = e.reportOptions;
  1073. if (e.startTime) {
  1074. var o = Date.now();
  1075. e.value === void 0 && (e.endTime = o), e.value === void 0 && (e.value = o - e.startTime);
  1076. }
  1077. 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) {
  1078. this.error.apply(this, _toConsumableArray(t));
  1079. return;
  1080. }
  1081. this.warn.apply(this, _toConsumableArray(t));
  1082. }
  1083. }, {
  1084. key: "warn",
  1085. value: function warn() {
  1086. for (var _len6 = arguments.length, e = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  1087. e[_key6] = arguments[_key6];
  1088. }
  1089. return this.print.apply(this, ["warn", 3].concat(e));
  1090. }
  1091. }, {
  1092. key: "error",
  1093. value: function error() {
  1094. for (var _len7 = arguments.length, e = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
  1095. e[_key7] = arguments[_key7];
  1096. }
  1097. return this.print.apply(this, ["error", 4].concat(e));
  1098. }
  1099. }, {
  1100. key: "prefix",
  1101. value: function prefix(e) {
  1102. return "[".concat(this.module, "][").concat(e, "] ").concat(util.getFormattedDate(new Date()), ":");
  1103. }
  1104. }], [{
  1105. key: "setLevel",
  1106. value: function setLevel(e) {
  1107. this.level = e;
  1108. }
  1109. }]);
  1110. return Logger;
  1111. }();
  1112. var logger = new Logger();
  1113. var AxiosCanceler = /*#__PURE__*/function () {
  1114. function AxiosCanceler() {
  1115. _classCallCheck(this, AxiosCanceler);
  1116. this.pendingMap = new Map();
  1117. }
  1118. _createClass(AxiosCanceler, [{
  1119. key: "addPending",
  1120. value: function addPending(e) {
  1121. var _this = this;
  1122. return new axios.CancelToken(function (t) {
  1123. _this.pendingMap.has(e) || _this.pendingMap.set(e, t);
  1124. });
  1125. }
  1126. }, {
  1127. key: "removeAllPending",
  1128. value: function removeAllPending() {
  1129. this.pendingMap.forEach(function (e) {
  1130. e && isFunction(e) && e();
  1131. }), this.pendingMap.clear();
  1132. }
  1133. }, {
  1134. key: "removePending",
  1135. value: function removePending(e) {
  1136. if (this.pendingMap.has(e)) {
  1137. var t = this.pendingMap.get(e);
  1138. t && t(e), this.pendingMap.delete(e);
  1139. }
  1140. }
  1141. }, {
  1142. key: "removeCancelToken",
  1143. value: function removeCancelToken(e) {
  1144. this.pendingMap.has(e) && this.pendingMap.delete(e);
  1145. }
  1146. }, {
  1147. key: "reset",
  1148. value: function reset() {
  1149. this.pendingMap = new Map();
  1150. }
  1151. }]);
  1152. return AxiosCanceler;
  1153. }();
  1154. 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); }; }
  1155. 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; } }
  1156. var Http1 = /*#__PURE__*/function (_EventEmitter) {
  1157. _inherits(Http1, _EventEmitter);
  1158. var _super = _createSuper$k(Http1);
  1159. function Http1() {
  1160. var _this;
  1161. _classCallCheck(this, Http1);
  1162. _this = _super.call(this);
  1163. _this.instatnce = axios.create(), _this.canceler = new AxiosCanceler();
  1164. return _this;
  1165. }
  1166. _createClass(Http1, [{
  1167. key: "requestConstant",
  1168. value: function requestConstant() {
  1169. return {
  1170. x_nounce: this.randomString(),
  1171. x_timestamp: new Date().getTime(),
  1172. x_os: "web"
  1173. };
  1174. }
  1175. }, {
  1176. key: "requestParams",
  1177. value: function requestParams(e) {
  1178. return oe({}, e.params);
  1179. }
  1180. }, {
  1181. key: "get",
  1182. value: function get(e) {
  1183. return this.request(le(oe({}, e), {
  1184. method: "GET"
  1185. }));
  1186. }
  1187. }, {
  1188. key: "post",
  1189. value: function post(e) {
  1190. return this.request(le(oe({}, e), {
  1191. method: "POST"
  1192. }));
  1193. }
  1194. }, {
  1195. key: "request",
  1196. value: function request(e) {
  1197. var _this2 = this;
  1198. var t = e.url,
  1199. _e$timeout = e.timeout,
  1200. r = _e$timeout === void 0 ? 1e4 : _e$timeout,
  1201. n = e.method,
  1202. o = e.key,
  1203. a = e.beforeRequest,
  1204. s = e.responseType,
  1205. l = e.data;
  1206. var _e$retry = e.retry,
  1207. u = _e$retry === void 0 ? 0 : _e$retry;
  1208. var c = this.patchUrl(t),
  1209. h = this.canceler.addPending(t);
  1210. a && isFunction(a) && a(e);
  1211. var f = this.requestParams(e);
  1212. var d = {
  1213. url: c,
  1214. method: n,
  1215. timeout: r,
  1216. cancelToken: h,
  1217. responseType: s,
  1218. params: f
  1219. };
  1220. n === "POST" && (d = oe({
  1221. data: l
  1222. }, d));
  1223. var _ = Date.now(),
  1224. g = function g() {
  1225. return _this2.instatnce.request(d).then(function (m) {
  1226. return o && logger.infoAndReportMeasurement({
  1227. metric: "http",
  1228. startTime: _,
  1229. extra: t,
  1230. group: "http",
  1231. tag: o
  1232. }), _this2.canceler.removeCancelToken(t), m;
  1233. }).catch(function (m) {
  1234. var v = axios.isCancel(m);
  1235. return u > 0 && !v ? (u--, logger.warn("request ".concat(t, " retry, left retry count"), u), g()) : (logger.infoAndReportMeasurement({
  1236. metric: "http",
  1237. startTime: _,
  1238. error: m,
  1239. extra: {
  1240. url: t,
  1241. isCanceled: v
  1242. },
  1243. tag: o,
  1244. group: "http"
  1245. }), _this2.canceler.removeCancelToken(t), Promise.reject(m));
  1246. });
  1247. };
  1248. return g();
  1249. }
  1250. }, {
  1251. key: "patchUrl",
  1252. value: function patchUrl(e) {
  1253. return e;
  1254. }
  1255. }, {
  1256. key: "randomString",
  1257. value: function randomString() {
  1258. var e = "";
  1259. var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
  1260. r = t.length;
  1261. for (var n = 0; n < 8; n++) {
  1262. e += t.charAt(Math.floor(Math.random() * r));
  1263. }
  1264. return e;
  1265. }
  1266. }]);
  1267. return Http1;
  1268. }(EventEmitter);
  1269. var http1 = new Http1();
  1270. var ModelManager$1 = /*#__PURE__*/function () {
  1271. function ModelManager(e, t) {
  1272. _classCallCheck(this, ModelManager);
  1273. this.avatarModelList = [];
  1274. this.skinList = [];
  1275. this.applicationConfig = null;
  1276. this.config = null;
  1277. this.appId = e, this.releaseId = t;
  1278. }
  1279. _createClass(ModelManager, [{
  1280. key: "findSkinConfig",
  1281. value: function () {
  1282. var _findSkinConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  1283. var t, n;
  1284. return regenerator.wrap(function _callee$(_context) {
  1285. while (1) {
  1286. switch (_context.prev = _context.next) {
  1287. case 0:
  1288. t = null;
  1289. _context.next = 3;
  1290. return this.getSkinsList();
  1291. case 3:
  1292. t = (this.skinList = _context.sent).find(function (n) {
  1293. return n.id === e;
  1294. });
  1295. if (!t) {
  1296. _context.next = 6;
  1297. break;
  1298. }
  1299. return _context.abrupt("return", t);
  1300. case 6:
  1301. n = "skin is invalid: skinId: ".concat(e);
  1302. return _context.abrupt("return", Promise.reject(new ParamError(n)));
  1303. case 8:
  1304. case "end":
  1305. return _context.stop();
  1306. }
  1307. }
  1308. }, _callee, this);
  1309. }));
  1310. function findSkinConfig(_x) {
  1311. return _findSkinConfig.apply(this, arguments);
  1312. }
  1313. return findSkinConfig;
  1314. }()
  1315. }, {
  1316. key: "findRoute",
  1317. value: function () {
  1318. var _findRoute = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e, t) {
  1319. var n, o;
  1320. return regenerator.wrap(function _callee2$(_context2) {
  1321. while (1) {
  1322. switch (_context2.prev = _context2.next) {
  1323. case 0:
  1324. _context2.next = 2;
  1325. return this.findSkinConfig(e);
  1326. case 2:
  1327. n = _context2.sent.routeList.find(function (o) {
  1328. return o.pathName === t;
  1329. });
  1330. if (n) {
  1331. _context2.next = 6;
  1332. break;
  1333. }
  1334. o = "find path failed: skinId: ".concat(e, ", pathName: ").concat(t);
  1335. return _context2.abrupt("return", Promise.reject(new ParamError(o)));
  1336. case 6:
  1337. return _context2.abrupt("return", (logger.debug("find route success", n), n));
  1338. case 7:
  1339. case "end":
  1340. return _context2.stop();
  1341. }
  1342. }
  1343. }, _callee2, this);
  1344. }));
  1345. function findRoute(_x2, _x3) {
  1346. return _findRoute.apply(this, arguments);
  1347. }
  1348. return findRoute;
  1349. }()
  1350. }, {
  1351. key: "findAssetList",
  1352. value: function () {
  1353. var _findAssetList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  1354. var r, n;
  1355. return regenerator.wrap(function _callee3$(_context3) {
  1356. while (1) {
  1357. switch (_context3.prev = _context3.next) {
  1358. case 0:
  1359. _context3.next = 2;
  1360. return this.findSkinConfig(e);
  1361. case 2:
  1362. r = _context3.sent.assetList;
  1363. if (r) {
  1364. _context3.next = 6;
  1365. break;
  1366. }
  1367. n = "find path failed: skinId: ".concat(e);
  1368. return _context3.abrupt("return", Promise.reject(new ParamError(n)));
  1369. case 6:
  1370. return _context3.abrupt("return", (logger.debug("find route success", r), r));
  1371. case 7:
  1372. case "end":
  1373. return _context3.stop();
  1374. }
  1375. }
  1376. }, _callee3, this);
  1377. }));
  1378. function findAssetList(_x4) {
  1379. return _findAssetList.apply(this, arguments);
  1380. }
  1381. return findAssetList;
  1382. }()
  1383. }, {
  1384. key: "findAsset",
  1385. value: function () {
  1386. var _findAsset = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e, t) {
  1387. var r,
  1388. n,
  1389. o,
  1390. a,
  1391. _args4 = arguments;
  1392. return regenerator.wrap(function _callee4$(_context4) {
  1393. while (1) {
  1394. switch (_context4.prev = _context4.next) {
  1395. case 0:
  1396. r = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : "id";
  1397. _context4.next = 3;
  1398. return this.findSkinConfig(e);
  1399. case 3:
  1400. n = _context4.sent;
  1401. if (!Array.isArray(t)) {
  1402. _context4.next = 6;
  1403. break;
  1404. }
  1405. return _context4.abrupt("return", t.map(function (a) {
  1406. return n.models.find(function (s) {
  1407. return s[r] === a;
  1408. });
  1409. }).filter(Boolean));
  1410. case 6:
  1411. o = n.models.find(function (a) {
  1412. return a[r] === t;
  1413. });
  1414. if (o) {
  1415. _context4.next = 10;
  1416. break;
  1417. }
  1418. a = "find asset failed: skinId: ".concat(e, ", keyValue: ").concat(t);
  1419. return _context4.abrupt("return", Promise.reject(new ParamError(a)));
  1420. case 10:
  1421. return _context4.abrupt("return", (logger.debug("find asset success", o), o));
  1422. case 11:
  1423. case "end":
  1424. return _context4.stop();
  1425. }
  1426. }
  1427. }, _callee4, this);
  1428. }));
  1429. function findAsset(_x5, _x6) {
  1430. return _findAsset.apply(this, arguments);
  1431. }
  1432. return findAsset;
  1433. }()
  1434. }, {
  1435. key: "findPoint",
  1436. value: function () {
  1437. var _findPoint = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e, t) {
  1438. var n, o;
  1439. return regenerator.wrap(function _callee5$(_context5) {
  1440. while (1) {
  1441. switch (_context5.prev = _context5.next) {
  1442. case 0:
  1443. _context5.next = 2;
  1444. return this.findSkinConfig(e);
  1445. case 2:
  1446. n = _context5.sent.pointList.find(function (o) {
  1447. return o.id === t;
  1448. });
  1449. if (n) {
  1450. _context5.next = 6;
  1451. break;
  1452. }
  1453. o = "find point failed: skinId: ".concat(e, ", id: ").concat(t);
  1454. return _context5.abrupt("return", Promise.reject(new ParamError(o)));
  1455. case 6:
  1456. return _context5.abrupt("return", (logger.debug("find point success", n), n));
  1457. case 7:
  1458. case "end":
  1459. return _context5.stop();
  1460. }
  1461. }
  1462. }, _callee5, this);
  1463. }));
  1464. function findPoint(_x7, _x8) {
  1465. return _findPoint.apply(this, arguments);
  1466. }
  1467. return findPoint;
  1468. }()
  1469. }, {
  1470. key: "requestConfig",
  1471. value: function () {
  1472. var _requestConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  1473. var t, r, _ref, n, o;
  1474. return regenerator.wrap(function _callee6$(_context6) {
  1475. while (1) {
  1476. switch (_context6.prev = _context6.next) {
  1477. case 0:
  1478. if (!this.config) {
  1479. _context6.next = 2;
  1480. break;
  1481. }
  1482. return _context6.abrupt("return", this.config);
  1483. case 2:
  1484. // let e = `https://static.xverse.cn/console/config/${this.appId}/config.json`;
  1485. // this.releaseId && (e = `https://static.xverse.cn/console/config/${this.appId}/${this.releaseId}/config.json`);
  1486. // const t = Xverse.USE_TME_CDN ? "https://static.xverse.cn/tmeland/config/tme_config.json" : e;
  1487. t = './assets/config.json';
  1488. _context6.prev = 3;
  1489. _context6.next = 6;
  1490. return http1.get({
  1491. url: "".concat(t, "?t=").concat(Date.now()),
  1492. key: "config",
  1493. timeout: 6e3,
  1494. retry: 2
  1495. });
  1496. case 6:
  1497. r = _context6.sent;
  1498. _ref = r.data.data || {}, n = _ref.config, o = _ref.preload;
  1499. if (n) {
  1500. _context6.next = 10;
  1501. break;
  1502. }
  1503. throw new Error("config data parse error" + r.data);
  1504. case 10:
  1505. return _context6.abrupt("return", (this.config = {
  1506. config: n,
  1507. preload: o
  1508. }, logger.debug("get config success", this.config), this.config));
  1509. case 13:
  1510. _context6.prev = 13;
  1511. _context6.t0 = _context6["catch"](3);
  1512. return _context6.abrupt("return", Promise.reject(_context6.t0));
  1513. case 16:
  1514. case "end":
  1515. return _context6.stop();
  1516. }
  1517. }
  1518. }, _callee6, this, [[3, 13]]);
  1519. }));
  1520. function requestConfig() {
  1521. return _requestConfig.apply(this, arguments);
  1522. }
  1523. return requestConfig;
  1524. }()
  1525. }, {
  1526. key: "getApplicationConfig",
  1527. value: function () {
  1528. var _getApplicationConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7() {
  1529. var e;
  1530. return regenerator.wrap(function _callee7$(_context7) {
  1531. while (1) {
  1532. switch (_context7.prev = _context7.next) {
  1533. case 0:
  1534. if (!this.applicationConfig) {
  1535. _context7.next = 2;
  1536. break;
  1537. }
  1538. return _context7.abrupt("return", this.applicationConfig);
  1539. case 2:
  1540. _context7.prev = 2;
  1541. _context7.next = 5;
  1542. return this.requestConfig();
  1543. case 5:
  1544. e = _context7.sent;
  1545. return _context7.abrupt("return", (this.applicationConfig = e.config, this.applicationConfig));
  1546. case 9:
  1547. _context7.prev = 9;
  1548. _context7.t0 = _context7["catch"](2);
  1549. return _context7.abrupt("return", Promise.reject(_context7.t0));
  1550. case 12:
  1551. case "end":
  1552. return _context7.stop();
  1553. }
  1554. }
  1555. }, _callee7, this, [[2, 9]]);
  1556. }));
  1557. function getApplicationConfig() {
  1558. return _getApplicationConfig.apply(this, arguments);
  1559. }
  1560. return getApplicationConfig;
  1561. }()
  1562. }, {
  1563. key: "getAvatarModelList",
  1564. value: function () {
  1565. var _getAvatarModelList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  1566. var _yield$this$getApplic, e;
  1567. return regenerator.wrap(function _callee8$(_context8) {
  1568. while (1) {
  1569. switch (_context8.prev = _context8.next) {
  1570. case 0:
  1571. if (!this.avatarModelList.length) {
  1572. _context8.next = 2;
  1573. break;
  1574. }
  1575. return _context8.abrupt("return", this.avatarModelList);
  1576. case 2:
  1577. _context8.prev = 2;
  1578. _context8.next = 5;
  1579. return this.getApplicationConfig();
  1580. case 5:
  1581. _yield$this$getApplic = _context8.sent;
  1582. e = _yield$this$getApplic.avatars;
  1583. return _context8.abrupt("return", (this.avatarModelList = e.map(function (t) {
  1584. return {
  1585. name: t.name,
  1586. id: t.id,
  1587. modelUrl: t.url,
  1588. gender: t.gender,
  1589. components: t.components
  1590. };
  1591. }), this.avatarModelList));
  1592. case 10:
  1593. _context8.prev = 10;
  1594. _context8.t0 = _context8["catch"](2);
  1595. return _context8.abrupt("return", (logger.error(_context8.t0), []));
  1596. case 13:
  1597. case "end":
  1598. return _context8.stop();
  1599. }
  1600. }
  1601. }, _callee8, this, [[2, 10]]);
  1602. }));
  1603. function getAvatarModelList() {
  1604. return _getAvatarModelList.apply(this, arguments);
  1605. }
  1606. return getAvatarModelList;
  1607. }()
  1608. }, {
  1609. key: "getSkinsList",
  1610. value: function () {
  1611. var _getSkinsList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9() {
  1612. var _yield$this$getApplic2, e;
  1613. return regenerator.wrap(function _callee9$(_context9) {
  1614. while (1) {
  1615. switch (_context9.prev = _context9.next) {
  1616. case 0:
  1617. if (!this.skinList.length) {
  1618. _context9.next = 2;
  1619. break;
  1620. }
  1621. return _context9.abrupt("return", this.skinList);
  1622. case 2:
  1623. _context9.prev = 2;
  1624. _context9.next = 5;
  1625. return this.getApplicationConfig();
  1626. case 5:
  1627. _yield$this$getApplic2 = _context9.sent;
  1628. e = _yield$this$getApplic2.skins;
  1629. return _context9.abrupt("return", (this.skinList = e.map(function (t) {
  1630. var r;
  1631. return {
  1632. name: t.name,
  1633. dataVersion: t.id + t.versionId,
  1634. id: t.id,
  1635. fov: parseInt(t.fov || 90),
  1636. models: t.assetList.map(function (n) {
  1637. var o = n.assetId,
  1638. a = n.url,
  1639. s = n.thumbnailUrl,
  1640. l = n.typeName,
  1641. u = n.className;
  1642. return {
  1643. id: o,
  1644. modelUrl: a,
  1645. name: n.name,
  1646. thumbnailUrl: s,
  1647. typeName: l,
  1648. className: u === "\u4F4E\u6A21" ? "\u7C97\u6A21" : u
  1649. };
  1650. }),
  1651. routeList: (r = t.routeList) == null ? void 0 : r.map(function (n) {
  1652. var o = n.areaName,
  1653. a = n.attitude,
  1654. s = n.id,
  1655. l = n.pathName,
  1656. u = n.step,
  1657. c = n.birthPointList;
  1658. return {
  1659. areaName: o,
  1660. attitude: a,
  1661. id: s,
  1662. pathName: l,
  1663. step: u,
  1664. birthPointList: c.map(function (h) {
  1665. return {
  1666. camera: h.camera && {
  1667. position: util.objectParseFloat(h.camera.position),
  1668. angle: util.objectParseFloat(h.camera.rotation)
  1669. },
  1670. player: h.player && {
  1671. position: util.objectParseFloat(h.player.position),
  1672. angle: util.objectParseFloat(h.player.rotation)
  1673. }
  1674. };
  1675. })
  1676. };
  1677. }),
  1678. pointList: t.pointList.map(function (n) {
  1679. return le(oe({}, n), {
  1680. position: util.objectParseFloat(n.position),
  1681. rotation: util.objectParseFloat(n.rotation)
  1682. });
  1683. }),
  1684. versionId: t.versionId,
  1685. isEnable: t.isEnable,
  1686. assetList: t.assetList,
  1687. visibleRules: t.visibleRules,
  1688. animationList: t.animationList
  1689. };
  1690. }), this.skinList));
  1691. case 10:
  1692. _context9.prev = 10;
  1693. _context9.t0 = _context9["catch"](2);
  1694. return _context9.abrupt("return", (logger.error(_context9.t0), []));
  1695. case 13:
  1696. case "end":
  1697. return _context9.stop();
  1698. }
  1699. }
  1700. }, _callee9, this, [[2, 10]]);
  1701. }));
  1702. function getSkinsList() {
  1703. return _getSkinsList.apply(this, arguments);
  1704. }
  1705. return getSkinsList;
  1706. }()
  1707. }, {
  1708. key: "getBreathPointTextrueList",
  1709. value: function () {
  1710. var _getBreathPointTextrueList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10() {
  1711. return regenerator.wrap(function _callee10$(_context10) {
  1712. while (1) {
  1713. switch (_context10.prev = _context10.next) {
  1714. case 0:
  1715. return _context10.abrupt("return", [{
  1716. url: TEXTURE_URL
  1717. }]);
  1718. case 1:
  1719. case "end":
  1720. return _context10.stop();
  1721. }
  1722. }
  1723. }, _callee10);
  1724. }));
  1725. function getBreathPointTextrueList() {
  1726. return _getBreathPointTextrueList.apply(this, arguments);
  1727. }
  1728. return getBreathPointTextrueList;
  1729. }()
  1730. }], [{
  1731. key: "getInstance",
  1732. value: function getInstance(e, t) {
  1733. //getInstance(e, t) {
  1734. return this.instance || (this.instance = new ModelManager(e, t)), this.instance;
  1735. }
  1736. }, {
  1737. key: "findModels",
  1738. value: function findModels(e, t, r) {
  1739. //findModels(e, t, r) {
  1740. return e.filter(function (o) {
  1741. return o.typeName === t && o.className === r;
  1742. });
  1743. }
  1744. }, {
  1745. key: "findModel",
  1746. value: function findModel(e, t, r) {
  1747. //findModel(e, t, r) {
  1748. var n = e.filter(function (o) {
  1749. return o.typeName === t && o.className === r;
  1750. })[0];
  1751. return n || null;
  1752. }
  1753. }]);
  1754. return ModelManager;
  1755. }();
  1756. // export { modelManager };
  1757. var JoyStick = /*#__PURE__*/function () {
  1758. function JoyStick(e) {
  1759. _classCallCheck(this, JoyStick);
  1760. this._zone = document.createElement("div");
  1761. this._joystick = null;
  1762. this._room = e;
  1763. }
  1764. _createClass(JoyStick, [{
  1765. key: "init",
  1766. value: function init(e) {
  1767. var _this = this;
  1768. var _e$interval = e.interval,
  1769. t = _e$interval === void 0 ? 33 : _e$interval,
  1770. _e$triggerDistance = e.triggerDistance,
  1771. r = _e$triggerDistance === void 0 ? 25 : _e$triggerDistance,
  1772. _e$style = e.style,
  1773. n = _e$style === void 0 ? {
  1774. left: 0,
  1775. bottom: 0
  1776. } : _e$style,
  1777. o = function o(u, c) {
  1778. _this._room.actionsHandler.joystick({
  1779. degree: Math.floor(u),
  1780. level: Math.floor(c / 5)
  1781. });
  1782. },
  1783. a = this._zone;
  1784. 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({
  1785. zone: a,
  1786. mode: "static",
  1787. position: {
  1788. left: "50%",
  1789. top: "50%"
  1790. },
  1791. color: "white"
  1792. });
  1793. var s, l;
  1794. return this._joystick.on("move", function (u, c) {
  1795. s = c;
  1796. }), this._joystick.on("start", function () {
  1797. l = window.setInterval(function () {
  1798. s && s.distance > r && o && o(s.angle.degree, s.distance);
  1799. }, t);
  1800. }), this._joystick.on("end", function () {
  1801. l && window.clearInterval(l), l = void 0;
  1802. }), this._joystick;
  1803. }
  1804. }, {
  1805. key: "show",
  1806. value: function show() {
  1807. if (!this._joystick) throw new Error("joystick is not created");
  1808. this._zone.style.display = "block";
  1809. }
  1810. }, {
  1811. key: "hide",
  1812. value: function hide() {
  1813. if (!this._joystick) throw new Error("joystick is not created");
  1814. this._zone.style.display = "none";
  1815. }
  1816. }]);
  1817. return JoyStick;
  1818. }();
  1819. var CoreBroadcastType = {
  1820. PlayAnimation: 'PlayAnimation'
  1821. };
  1822. var AvatarGroup = {
  1823. Npc: 'npc',
  1824. User: 'user'
  1825. };
  1826. var MessageHandleType$1 = {
  1827. MHT_Undefined: 0,
  1828. MHT_RoomMulticast: 1,
  1829. MHT_FollowListMulticast: 2,
  1830. MHT_CustomTargetSync: 3
  1831. };
  1832. var Broadcast$1 = /*#__PURE__*/function () {
  1833. function Broadcast(e, t) {
  1834. _classCallCheck(this, Broadcast);
  1835. this.room = e;
  1836. this.handlers = [];
  1837. this.init(t);
  1838. }
  1839. _createClass(Broadcast, [{
  1840. key: "init",
  1841. value: function init(t) {
  1842. this.handlers.push(t);
  1843. }
  1844. }, {
  1845. key: "handleBroadcast",
  1846. value: function () {
  1847. var _handleBroadcast = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  1848. return regenerator.wrap(function _callee$(_context) {
  1849. while (1) {
  1850. switch (_context.prev = _context.next) {
  1851. case 0:
  1852. _context.prev = 1;
  1853. JSON.parse(e.broadcastAction.data);
  1854. _context.next = 9;
  1855. break;
  1856. case 5:
  1857. _context.prev = 5;
  1858. _context.t0 = _context["catch"](1);
  1859. logger.error(_context.t0);
  1860. return _context.abrupt("return");
  1861. case 9:
  1862. case "end":
  1863. return _context.stop();
  1864. }
  1865. }
  1866. }, _callee, null, [[1, 5]]);
  1867. }));
  1868. function handleBroadcast(_x) {
  1869. return _handleBroadcast.apply(this, arguments);
  1870. }
  1871. return handleBroadcast;
  1872. }()
  1873. }, {
  1874. key: "broadcast",
  1875. value: function broadcast(e) {
  1876. var t = e.data,
  1877. _e$msgType = e.msgType,
  1878. r = _e$msgType === void 0 ? MessageHandleType$1.MHT_FollowListMulticast : _e$msgType,
  1879. n = e.targetUserIds;
  1880. return this.room.actionsHandler.broadcast({
  1881. data: t,
  1882. msgType: r,
  1883. targetUserIds: n
  1884. });
  1885. }
  1886. }]);
  1887. return Broadcast;
  1888. }();
  1889. function _isNativeFunction(fn) {
  1890. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  1891. }
  1892. function _isNativeReflectConstruct$k() {
  1893. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1894. if (Reflect.construct.sham) return false;
  1895. if (typeof Proxy === "function") return true;
  1896. try {
  1897. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  1898. return true;
  1899. } catch (e) {
  1900. return false;
  1901. }
  1902. }
  1903. function _construct(Parent, args, Class) {
  1904. if (_isNativeReflectConstruct$k()) {
  1905. _construct = Reflect.construct;
  1906. } else {
  1907. _construct = function _construct(Parent, args, Class) {
  1908. var a = [null];
  1909. a.push.apply(a, args);
  1910. var Constructor = Function.bind.apply(Parent, a);
  1911. var instance = new Constructor();
  1912. if (Class) _setPrototypeOf(instance, Class.prototype);
  1913. return instance;
  1914. };
  1915. }
  1916. return _construct.apply(null, arguments);
  1917. }
  1918. function _wrapNativeSuper(Class) {
  1919. var _cache = typeof Map === "function" ? new Map() : undefined;
  1920. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1921. if (Class === null || !_isNativeFunction(Class)) return Class;
  1922. if (typeof Class !== "function") {
  1923. throw new TypeError("Super expression must either be null or a function");
  1924. }
  1925. if (typeof _cache !== "undefined") {
  1926. if (_cache.has(Class)) return _cache.get(Class);
  1927. _cache.set(Class, Wrapper);
  1928. }
  1929. function Wrapper() {
  1930. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1931. }
  1932. Wrapper.prototype = Object.create(Class.prototype, {
  1933. constructor: {
  1934. value: Wrapper,
  1935. enumerable: false,
  1936. writable: true,
  1937. configurable: true
  1938. }
  1939. });
  1940. return _setPrototypeOf(Wrapper, Class);
  1941. };
  1942. return _wrapNativeSuper(Class);
  1943. }
  1944. function _createSuper$j(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$j(); 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); }; }
  1945. function _isNativeReflectConstruct$j() { 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; } }
  1946. var XverseError = /*#__PURE__*/function (_Error) {
  1947. _inherits(XverseError, _Error);
  1948. var _super = _createSuper$j(XverseError);
  1949. function XverseError(e, t) {
  1950. var _this;
  1951. _classCallCheck(this, XverseError);
  1952. _this = _super.call(this, t);
  1953. _this.code = e;
  1954. return _this;
  1955. }
  1956. _createClass(XverseError, [{
  1957. key: "toJSON",
  1958. value: function toJSON() {
  1959. return {
  1960. code: this.code,
  1961. message: this.message
  1962. };
  1963. }
  1964. }, {
  1965. key: "toString",
  1966. value: function toString() {
  1967. if (Object(this) !== this) throw new TypeError();
  1968. var t = this.name;
  1969. t = t === void 0 ? "Error" : String(t);
  1970. var r = this.message;
  1971. r = r === void 0 ? "" : String(r);
  1972. var n = this.code;
  1973. return r = n === void 0 ? r : n + "," + r, t === "" ? r : r === "" ? t : t + ": " + r;
  1974. }
  1975. }]);
  1976. return XverseError;
  1977. }( /*#__PURE__*/_wrapNativeSuper(Error));
  1978. 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); }; }
  1979. 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; } }
  1980. var TimeoutError = /*#__PURE__*/function (_XverseError) {
  1981. _inherits(TimeoutError, _XverseError);
  1982. var _super = _createSuper$i(TimeoutError);
  1983. function TimeoutError(e) {
  1984. _classCallCheck(this, TimeoutError);
  1985. return _super.call(this, 1003, e || "\u8D85\u65F6");
  1986. }
  1987. return _createClass(TimeoutError);
  1988. }(XverseError);
  1989. 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); }; }
  1990. 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; } }
  1991. var XverseAvatarManager = /*#__PURE__*/function (_EventEmitter) {
  1992. _inherits(XverseAvatarManager, _EventEmitter);
  1993. var _super = _createSuper$h(XverseAvatarManager);
  1994. function XverseAvatarManager(e) {
  1995. var _this;
  1996. _classCallCheck(this, XverseAvatarManager);
  1997. _this = _super.call(this);
  1998. _this.xAvatarManager = null;
  1999. _this.avatars = new Map();
  2000. _this.syncAvatarsLength = 0;
  2001. _this._room = e;
  2002. _this._usersStatistics();
  2003. _this.broadcast = _this.setupBroadcast();
  2004. e.on("skinChanged", function () {
  2005. _this.avatars.forEach(function (t) {
  2006. t.disconnected && _this.removeAvatar(t.userId, !0);
  2007. });
  2008. });
  2009. return _this;
  2010. }
  2011. _createClass(XverseAvatarManager, [{
  2012. key: "setupBroadcast",
  2013. value: function setupBroadcast() {
  2014. var _this2 = this;
  2015. return new Broadcast$1(this._room, /*#__PURE__*/function () {
  2016. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  2017. var t, r, n, o, a, _r$loop, s, l;
  2018. return regenerator.wrap(function _callee$(_context) {
  2019. while (1) {
  2020. switch (_context.prev = _context.next) {
  2021. case 0:
  2022. t = e.broadcastType, r = e.info;
  2023. if (!(t !== CoreBroadcastType.PlayAnimation)) {
  2024. _context.next = 3;
  2025. break;
  2026. }
  2027. return _context.abrupt("return");
  2028. case 3:
  2029. 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);
  2030. _context.t0 = l && !l.isSelf;
  2031. if (!_context.t0) {
  2032. _context.next = 10;
  2033. break;
  2034. }
  2035. l.emit("animationStart", {
  2036. animationName: o,
  2037. extra: decodeURIComponent(a)
  2038. });
  2039. _context.next = 9;
  2040. return l == null ? void 0 : l._playAnimation(o, s);
  2041. case 9:
  2042. l.emit("animationEnd", {
  2043. animationName: o,
  2044. extra: decodeURIComponent(a)
  2045. });
  2046. case 10:
  2047. case "end":
  2048. return _context.stop();
  2049. }
  2050. }
  2051. }, _callee);
  2052. }));
  2053. return function (_x) {
  2054. return _ref.apply(this, arguments);
  2055. };
  2056. }());
  2057. }
  2058. }, {
  2059. key: "hideAll",
  2060. value: function hideAll() {
  2061. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2062. this.xAvatarManager.hideAll(e);
  2063. }
  2064. }, {
  2065. key: "showAll",
  2066. value: function showAll() {
  2067. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2068. this.xAvatarManager.showAll(e);
  2069. }
  2070. }, {
  2071. key: "init",
  2072. value: function () {
  2073. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  2074. var e, t;
  2075. return regenerator.wrap(function _callee2$(_context2) {
  2076. while (1) {
  2077. switch (_context2.prev = _context2.next) {
  2078. case 0:
  2079. this.xAvatarManager = this._room.sceneManager.avatarComponent;
  2080. _context2.prev = 1;
  2081. _context2.next = 4;
  2082. return this._room.modelManager.getApplicationConfig();
  2083. case 4:
  2084. e = _context2.sent;
  2085. t = e.avatars;
  2086. if (!t) {
  2087. _context2.next = 10;
  2088. break;
  2089. }
  2090. _context2.next = 9;
  2091. return avatarLoader.parse(this._room.sceneManager, t);
  2092. case 9:
  2093. return _context2.abrupt("return");
  2094. case 10:
  2095. return _context2.abrupt("return", Promise.reject("cannot find avatar config list"));
  2096. case 13:
  2097. _context2.prev = 13;
  2098. _context2.t0 = _context2["catch"](1);
  2099. return _context2.abrupt("return", (logger.error(_context2.t0), Promise.reject("avatar mananger init error!")));
  2100. case 16:
  2101. case "end":
  2102. return _context2.stop();
  2103. }
  2104. }
  2105. }, _callee2, this, [[1, 13]]);
  2106. }));
  2107. function init() {
  2108. return _init.apply(this, arguments);
  2109. }
  2110. return init;
  2111. }()
  2112. }, {
  2113. key: "handleAvatar",
  2114. value: function () {
  2115. var _handleAvatar2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  2116. var _this3 = this;
  2117. var r, t, n, o, _n, a;
  2118. return regenerator.wrap(function _callee3$(_context3) {
  2119. while (1) {
  2120. switch (_context3.prev = _context3.next) {
  2121. case 0:
  2122. if (!(this._room.viewMode === "simple" || !this._room.joined || !e.newUserStates)) {
  2123. _context3.next = 2;
  2124. break;
  2125. }
  2126. return _context3.abrupt("return");
  2127. case 2:
  2128. t = e.newUserStates;
  2129. if (((r = this._room._userAvatar) == null ? void 0 : r.isMoving) && this._room._userAvatar.motionType === MotionType.Run) {
  2130. n = t.filter(function (a) {
  2131. return a.userId === _this3._room.userId;
  2132. }), o = t.filter(function (a) {
  2133. return a.userId !== _this3._room.userId;
  2134. }).slice(0, 2);
  2135. t = n.concat(o);
  2136. }
  2137. if (e.getStateType === GetStateTypes.Event) {
  2138. this.syncAvatarsLength = (t || []).length;
  2139. _n = this._room.avatars.filter(function (s) {
  2140. return s.group == AvatarGroup.User;
  2141. });
  2142. _n.filter(function (s) {
  2143. return !(t != null && t.find(function (l) {
  2144. return l.userId == s.userId;
  2145. }));
  2146. }).forEach(function (s) {
  2147. _this3.removeAvatar(s.userId);
  2148. });
  2149. a = t.filter(function (s) {
  2150. return !_n.find(function (l) {
  2151. return l.userId == s.userId;
  2152. });
  2153. });
  2154. this._handleAvatar(a);
  2155. }
  2156. this._handleAvatar(t);
  2157. case 6:
  2158. case "end":
  2159. return _context3.stop();
  2160. }
  2161. }
  2162. }, _callee3, this);
  2163. }));
  2164. function handleAvatar(_x2) {
  2165. return _handleAvatar2.apply(this, arguments);
  2166. }
  2167. return handleAvatar;
  2168. }()
  2169. }, {
  2170. key: "_handleAvatar",
  2171. value: function () {
  2172. var _handleAvatar3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  2173. var _this4 = this;
  2174. return regenerator.wrap(function _callee4$(_context4) {
  2175. while (1) {
  2176. switch (_context4.prev = _context4.next) {
  2177. case 0:
  2178. e == null || e.forEach(function (t) {
  2179. var n, o, a, s, l, u, c, h, f;
  2180. var r = _this4._room.userId === t.userId;
  2181. if (((n = t.event) == null ? void 0 : n.type) === SyncEventType.ET_RemoveVisitor) {
  2182. var d = (a = (o = t.event) == null ? void 0 : o.removeVisitorEvent) == null ? void 0 : a.removeVisitorEvent,
  2183. _ = JSON.parse(safeDecodeURIComponent(((l = (s = t.event) == null ? void 0 : s.removeVisitorEvent) == null ? void 0 : l.extraInfo) || "")),
  2184. g = _.code,
  2185. m = _.msg;
  2186. d === RemoveVisitorType.RVT_ChangeToObserver ? _this4._room.audienceViewModeHook() : d === RemoveVisitorType.RVT_MoveOutOfTheRoom && _this4._room.leave(), _this4._room.emit("visitorStatusChanged", {
  2187. code: g,
  2188. msg: m
  2189. });
  2190. }
  2191. if (t.event && [SyncEventType.Appear, SyncEventType.Reset].includes(t.event.type) || !t.event) {
  2192. var _d = _this4.avatars.get(t.userId);
  2193. if (t.playerState.avatarId && (_d == null ? void 0 : _d.avatarId) !== t.playerState.avatarId && (_d = void 0, _this4.removeAvatar(t.userId)), _d) {
  2194. 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) {
  2195. var _2 = safeParseComponents(t.playerState.avatarComponents);
  2196. _d._changeComponents({
  2197. avatarComponents: _2,
  2198. mode: ChangeComponentsMode.Preview
  2199. });
  2200. }
  2201. } else {
  2202. var _t$playerState$player = t.playerState.player,
  2203. _3 = _t$playerState$player.position,
  2204. _g = _t$playerState$player.angle,
  2205. _m = t.playerState.avatarId,
  2206. v = t.playerState.prioritySync,
  2207. y = safelyJsonParse(t.playerState.extra);
  2208. if (!_m) return;
  2209. var b = safeParseComponents(t.playerState.avatarComponents),
  2210. T = safeDecodeURIComponent(t.playerState.nickName),
  2211. C = _this4.calculatePriority(t.userId, y);
  2212. _this4.addAvatar({
  2213. userId: t.userId,
  2214. isHost: t.playerState.isHost,
  2215. nickname: T,
  2216. avatarPosition: _3,
  2217. avatarRotation: _g,
  2218. avatarScale: t.playerState.avatarSize,
  2219. avatarId: _m,
  2220. avatarComponents: t.playerState.person === Person.First ? [] : b,
  2221. priority: C,
  2222. group: AvatarGroup.User,
  2223. prioritySync: v,
  2224. extraInfo: y
  2225. }).then(function () {
  2226. var A;
  2227. (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"));
  2228. }).catch(function (A) {
  2229. r && (_this4.xAvatarManager.setMainAvatar(t.userId), _this4._room.emit("userAvatarFailed", {
  2230. error: A
  2231. }), logger.error("userAvatarFailed", A));
  2232. });
  2233. }
  2234. }
  2235. 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) {
  2236. (h = t == null ? void 0 : t.event) != null && h.id && _this4._room.actionsHandler.confirmEvent(t.event.id);
  2237. var _d2 = _this4.avatars.get(t.userId);
  2238. _d2 && _d2.withModel && !_d2.isLoading && _this4.updateAvatarPositionAndRotation(t);
  2239. }
  2240. if (!r && ((f = t.event) == null ? void 0 : f.type) === SyncEventType.Rotate) {
  2241. var _d3 = _this4.avatars.get(t.userId);
  2242. _d3.statusSyncQueue.append({
  2243. type: QueueType.Rotate,
  2244. action: function action() {
  2245. return _d3.statusSync(t);
  2246. }
  2247. });
  2248. }
  2249. });
  2250. case 1:
  2251. case "end":
  2252. return _context4.stop();
  2253. }
  2254. }
  2255. }, _callee4);
  2256. }));
  2257. function _handleAvatar(_x3) {
  2258. return _handleAvatar3.apply(this, arguments);
  2259. }
  2260. return _handleAvatar;
  2261. }()
  2262. }, {
  2263. key: "calculatePriority",
  2264. value: function calculatePriority(e, t) {
  2265. var n;
  2266. return e === this._room.userId ? EAvatarRelationRank.Self : (n = this._room.options.firends) != null && n.includes(e) ? EAvatarRelationRank.Friend : EAvatarRelationRank.Stranger;
  2267. }
  2268. }, {
  2269. key: "updateAvatarPositionAndRotation",
  2270. value: function updateAvatarPositionAndRotation(e) {
  2271. var t, r;
  2272. if ((t = e == null ? void 0 : e.playerState) != null && t.player) {
  2273. var _e$playerState$player = e.playerState.player,
  2274. n = _e$playerState$player.position,
  2275. o = _e$playerState$player.angle;
  2276. var a = this.avatars.get(e.userId);
  2277. if (!a) return;
  2278. 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({
  2279. type: QueueType.Move,
  2280. action: function action() {
  2281. return a.statusSync(e);
  2282. }
  2283. }), e.renderInfo && a.isSelf) {
  2284. var _e$renderInfo = e.renderInfo,
  2285. s = _e$renderInfo.isMoving,
  2286. l = _e$renderInfo.isRotating;
  2287. this._updateAvatarMovingStatus({
  2288. id: e.userId,
  2289. isMoving: !!s,
  2290. isRotating: !!l
  2291. });
  2292. }
  2293. }
  2294. }
  2295. }, {
  2296. key: "addAvatar",
  2297. value: function () {
  2298. var _addAvatar = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e) {
  2299. 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;
  2300. return regenerator.wrap(function _callee5$(_context5) {
  2301. while (1) {
  2302. switch (_context5.prev = _context5.next) {
  2303. case 0:
  2304. 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;
  2305. g = this.avatars.get(t);
  2306. if (!g) {
  2307. _context5.next = 4;
  2308. break;
  2309. }
  2310. return _context5.abrupt("return", Promise.resolve(g));
  2311. case 4:
  2312. if (!(g = new xe.subAvatar({
  2313. userId: t,
  2314. isHost: r,
  2315. isSelf: _,
  2316. room: this._room,
  2317. avatarComponents: l,
  2318. avatarId: o,
  2319. nickname: s,
  2320. group: c
  2321. }), this.avatars.set(t, g), !g.withModel)) {
  2322. _context5.next = 6;
  2323. break;
  2324. }
  2325. return _context5.abrupt("return", (g.isLoading = !1, g.avatarLoadedHook(), this._room.emit("avatarChanged", {
  2326. avatars: this._room.avatars
  2327. }), g));
  2328. case 6:
  2329. _context5.next = 8;
  2330. return this._room.modelManager.getAvatarModelList();
  2331. case 8:
  2332. v = _context5.sent.find(function (b) {
  2333. return b.id === o;
  2334. });
  2335. y = Date.now();
  2336. if (v) {
  2337. _context5.next = 12;
  2338. break;
  2339. }
  2340. return _context5.abrupt("return", (this._room.emit("avatarChanged", {
  2341. avatars: this._room.avatars
  2342. }), this.avatars.delete(t), Promise.reject("no such avatar model with id: ".concat(o))));
  2343. case 12:
  2344. _context5.prev = 12;
  2345. _context5.next = 15;
  2346. return avatarComponentsModify(v, l);
  2347. case 15:
  2348. b = _context5.sent;
  2349. b = b.filter(function (A) {
  2350. return A.type != "pendant";
  2351. });
  2352. _context5.next = 19;
  2353. return avatarComponentsParser(v, b);
  2354. case 19:
  2355. T = _context5.sent;
  2356. _context5.next = 22;
  2357. return this.xAvatarManager.loadAvatar({
  2358. id: t,
  2359. avatarType: o,
  2360. priority: u,
  2361. avatarManager: this.xAvatarManager,
  2362. assets: T,
  2363. status: {
  2364. avatarPosition: n,
  2365. avatarRotation: a,
  2366. avatarScale: h
  2367. }
  2368. })._timeout(8e3, new TimeoutError$1("loadAvatar timeout(8s)"));
  2369. case 22:
  2370. C = _context5.sent;
  2371. 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", {
  2372. avatars: this._room.avatars
  2373. }), s && g._setNickname(s), t === this._room.userId && (logger.infoAndReportMeasurement({
  2374. metric: "avatarLoadDuration",
  2375. startTime: y,
  2376. group: "costs"
  2377. }), logger.infoAndReportMeasurement({
  2378. metric: "avatarLoadAt",
  2379. startTime: this._room._startTime,
  2380. group: "costs"
  2381. })), g));
  2382. case 26:
  2383. _context5.prev = 26;
  2384. _context5.t0 = _context5["catch"](12);
  2385. return _context5.abrupt("return", (g.isLoading = !1, this._room.emit("avatarChanged", {
  2386. avatars: this._room.avatars
  2387. }), logger.error(_context5.t0), Promise.reject(_context5.t0)));
  2388. case 29:
  2389. case "end":
  2390. return _context5.stop();
  2391. }
  2392. }
  2393. }, _callee5, this, [[12, 26]]);
  2394. }));
  2395. function addAvatar(_x4) {
  2396. return _addAvatar.apply(this, arguments);
  2397. }
  2398. return addAvatar;
  2399. }()
  2400. }, {
  2401. key: "removeAvatar",
  2402. value: function removeAvatar(e) {
  2403. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
  2404. var r = this.avatars.get(e);
  2405. if (!!r) {
  2406. if (r.removeWhenDisconnected || t) {
  2407. r.xAvatar && this.xAvatarManager.deleteAvatar(r.xAvatar), this.avatars.delete(e), this._room.emit("avatarChanged", {
  2408. avatars: this._room.avatars
  2409. });
  2410. return;
  2411. }
  2412. r.setConnectionStatus(!0);
  2413. }
  2414. }
  2415. }, {
  2416. key: "clearOtherUsers",
  2417. value: function clearOtherUsers() {
  2418. var _this5 = this;
  2419. this.avatars.forEach(function (e) {
  2420. !e.isSelf && e.group === AvatarGroup.User && _this5.removeAvatar(e.userId);
  2421. });
  2422. }
  2423. }, {
  2424. key: "_updateAvatarMovingStatus",
  2425. value: function () {
  2426. var _updateAvatarMovingStatus2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  2427. var t, r, n, o, a, _a;
  2428. return regenerator.wrap(function _callee6$(_context6) {
  2429. while (1) {
  2430. switch (_context6.prev = _context6.next) {
  2431. case 0:
  2432. t = e.id, r = e.isMoving, n = e.isRotating, o = this.avatars.get(t);
  2433. if (!!o) {
  2434. if (o.isRotating !== n) {
  2435. o.isRotating = n;
  2436. a = "Idle";
  2437. n && (a = "Walking", o.motionType === MotionType.Run && (a = "Running")), o._playAnimation(a, !0, !0), logger.infoAndReportMeasurement({
  2438. startTime: Date.now(),
  2439. value: 0,
  2440. metric: n ? "userAvatarStartRotating" : "userAvatarStopRotating",
  2441. extra: {
  2442. motionType: o.motionType,
  2443. moveToExtra: this._room.moveToExtra
  2444. }
  2445. });
  2446. }
  2447. if (o.isMoving !== r) {
  2448. o.isMoving = r;
  2449. _a = "Idle";
  2450. r && (_a = "Walking", o.motionType === MotionType.Run && (_a = "Running")), r ? (o.avatarStartMovingHook(), o.emit("startMoving", {
  2451. target: o,
  2452. extra: this._room.moveToExtra
  2453. })) : (o.avatarStopMovingHook(), o.emit("stopMoving", {
  2454. target: o,
  2455. extra: this._room.moveToExtra
  2456. })), o._playAnimation(_a, !0, !0), logger.infoAndReportMeasurement({
  2457. startTime: Date.now(),
  2458. value: 0,
  2459. metric: r ? "userAvatarStartMoving" : "userAvatarStopMoving",
  2460. extra: {
  2461. motionType: o.motionType,
  2462. moveToExtra: this._room.moveToExtra
  2463. }
  2464. });
  2465. }
  2466. }
  2467. case 2:
  2468. case "end":
  2469. return _context6.stop();
  2470. }
  2471. }
  2472. }, _callee6, this);
  2473. }));
  2474. function _updateAvatarMovingStatus(_x5) {
  2475. return _updateAvatarMovingStatus2.apply(this, arguments);
  2476. }
  2477. return _updateAvatarMovingStatus;
  2478. }()
  2479. }, {
  2480. key: "_usersStatistics",
  2481. value: function _usersStatistics() {
  2482. var _this6 = this;
  2483. this.on("userAvatarLoaded", function () {
  2484. window.setInterval(function () {
  2485. var e = _this6._room.avatars.filter(function (r) {
  2486. return r.group === AvatarGroup.User;
  2487. }).length || 0,
  2488. t = _this6._room.avatars.filter(function (r) {
  2489. return r.group === AvatarGroup.User && r.isRender;
  2490. }).length || 0;
  2491. _this6._room.stats.assign({
  2492. userNum: e,
  2493. syncUserNum: _this6.syncAvatarsLength,
  2494. renderedUserNum: t
  2495. });
  2496. }, 3e3);
  2497. });
  2498. }
  2499. }]);
  2500. return XverseAvatarManager;
  2501. }(EventEmitter);
  2502. var PathManager = /*#__PURE__*/function () {
  2503. function PathManager() {
  2504. _classCallCheck(this, PathManager);
  2505. this.currentArea = '';
  2506. this.currentPathName = '';
  2507. this.currentAttitude = '';
  2508. this.speed = 0;
  2509. }
  2510. _createClass(PathManager, [{
  2511. key: "getSpeed",
  2512. value: function getSpeed(e) {
  2513. var t = {
  2514. guangchang: {
  2515. [MotionType.Walk]: 17,
  2516. [MotionType.Run]: 51
  2517. },
  2518. tower: {
  2519. [MotionType.Walk]: 12.5,
  2520. [MotionType.Run]: 25
  2521. },
  2522. zhiboting: {
  2523. [MotionType.Walk]: 12.5,
  2524. [MotionType.Run]: 25
  2525. },
  2526. youxiting: {
  2527. [MotionType.Walk]: 12.5,
  2528. [MotionType.Run]: 25
  2529. },
  2530. diqing: {
  2531. [MotionType.Walk]: 12.5,
  2532. [MotionType.Run]: 25
  2533. }
  2534. },
  2535. r = t[this.currentArea] || t.guangchang;
  2536. return this.speed = r[e] * 30, this.speed;
  2537. }
  2538. }]);
  2539. return PathManager;
  2540. }();
  2541. var CameraStates = {
  2542. Normal: 0,
  2543. ItemView: 1,
  2544. CGView: 2,
  2545. PathView: 3
  2546. };
  2547. var Person$1 = {
  2548. Third: 0,
  2549. First: 1
  2550. };
  2551. var EImageQuality = {
  2552. low: 0,
  2553. mid: 1,
  2554. high: 2
  2555. };
  2556. 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); }; }
  2557. 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; } }
  2558. var Camera = /*#__PURE__*/function (_EventEmitter) {
  2559. _inherits(Camera, _EventEmitter);
  2560. var _super = _createSuper$g(Camera);
  2561. function Camera(e) {
  2562. var _this;
  2563. _classCallCheck(this, Camera);
  2564. _this = _super.call(this);
  2565. _this.initialFov = 0;
  2566. _this._state = CameraStates.Normal;
  2567. _this._person = Person$1.Third;
  2568. _this._cameraFollowing = !0;
  2569. _this._room = e;
  2570. return _this;
  2571. }
  2572. _createClass(Camera, [{
  2573. key: "checkPointOnLeftOrRight",
  2574. value: function checkPointOnLeftOrRight(e) {
  2575. var t = ue4Position2Xverse(e);
  2576. if (!t || this.checkPointInView(e)) return;
  2577. var o = this._room.scene.activeCamera;
  2578. if (!o) return;
  2579. var a = [o.target.x, o.target.y, o.target.z],
  2580. s = [o.position.x, o.position.y, o.position.z],
  2581. l = t.x,
  2582. u = t.y,
  2583. c = t.z,
  2584. h = calNormVector(s, a),
  2585. f = calNormVector(s, [l, u, c]);
  2586. return vectorCrossMulti(h, f) < 0 ? Direction.Right : Direction.Left;
  2587. }
  2588. }, {
  2589. key: "checkPointInView",
  2590. value: function checkPointInView(e, t, r) {
  2591. var n = ue4Position2Xverse({
  2592. x: e,
  2593. y: t,
  2594. z: r
  2595. });
  2596. if (!n) return !1;
  2597. for (var o = 0; o < 6; o++) {
  2598. if (this._room.scene.frustumPlanes[o].dotCoordinate(n) < 0) return !1;
  2599. }
  2600. return !0;
  2601. }
  2602. }, {
  2603. key: "person",
  2604. get: function get() {
  2605. return this._person;
  2606. }
  2607. }, {
  2608. key: "state",
  2609. get: function get() {
  2610. return this._state;
  2611. }
  2612. }, {
  2613. key: "pose",
  2614. get: function get() {
  2615. return this._room.currentClickingState.camera;
  2616. }
  2617. }, {
  2618. key: "cameraFollowing",
  2619. get: function get() {
  2620. return this._cameraFollowing;
  2621. },
  2622. set: function set(e) {
  2623. logger.info("cameraFollowing setter", e), this.setCameraFollowing({
  2624. isFollowHost: e
  2625. });
  2626. }
  2627. }, {
  2628. key: "setCameraFollowing",
  2629. value: function setCameraFollowing(_ref) {
  2630. _ref.isFollowHost;
  2631. }
  2632. }, {
  2633. key: "handleRenderInfo",
  2634. value: function handleRenderInfo(e) {
  2635. var t = e.renderInfo.cameraStateType,
  2636. r = this._room.sceneManager;
  2637. 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", {
  2638. state: t
  2639. })), this._room.isHost) return;
  2640. var n = e.playerState.isFollowHost;
  2641. !!n !== this._cameraFollowing && (this._cameraFollowing = !!n, this.emit("cameraFollowingChanged", {
  2642. cameraFollowing: !!n
  2643. }));
  2644. }
  2645. }, {
  2646. key: "setCameraState",
  2647. value: function setCameraState(_ref2) {
  2648. var e = _ref2.state;
  2649. if (this._state === e) {
  2650. logger.warn("You are already in ".concat(CameraStates[e], " camera state"));
  2651. return;
  2652. }
  2653. e === CameraStates.Normal || this._state === CameraStates.ItemView && logger.warn("CloseUp camera state can only be triggerd by room internally");
  2654. }
  2655. }, {
  2656. key: "turnToFace",
  2657. value: function turnToFace(_ref3) {
  2658. var _ref3$extra = _ref3.extra,
  2659. e = _ref3$extra === void 0 ? "" : _ref3$extra,
  2660. _ref3$offset = _ref3.offset,
  2661. t = _ref3$offset === void 0 ? 0 : _ref3$offset;
  2662. var r = {
  2663. action_type: Actions.TurnToFace,
  2664. turn_to_face_action: {
  2665. offset: t
  2666. }
  2667. };
  2668. return this.emit("viewChanged", {
  2669. extra: e
  2670. }), this._room.actionsHandler.sendData({
  2671. data: r
  2672. });
  2673. }
  2674. }, {
  2675. key: "isInDefaultView",
  2676. value: function isInDefaultView() {
  2677. if (!this._room.isHost) {
  2678. logger.warn("It is recommended to call the function on the host side");
  2679. return;
  2680. }
  2681. if (!this._room._currentClickingState) return logger.error("CurrentState should not be empty"), !1;
  2682. var _this$_room$_currentC = this._room._currentClickingState,
  2683. e = _this$_room$_currentC.camera,
  2684. t = _this$_room$_currentC.player;
  2685. return Math.abs(t.angle.yaw - 180 - e.angle.yaw) % 360 <= 4;
  2686. }
  2687. }, {
  2688. key: "screenShot",
  2689. value: function () {
  2690. var _screenShot = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_ref4) {
  2691. var e, _ref4$autoSave, t, r, n, o;
  2692. return regenerator.wrap(function _callee$(_context) {
  2693. while (1) {
  2694. switch (_context.prev = _context.next) {
  2695. case 0:
  2696. e = _ref4.name, _ref4$autoSave = _ref4.autoSave, t = _ref4$autoSave === void 0 ? !1 : _ref4$autoSave;
  2697. r = this._room.scene.getEngine(), n = this._room.scene.activeCamera;
  2698. _context.prev = 2;
  2699. this._room.sceneManager.setImageQuality(EImageQuality.high);
  2700. _context.next = 6;
  2701. return CreateScreenshotAsync(r, n, {
  2702. precision: 1
  2703. });
  2704. case 6:
  2705. o = _context.sent;
  2706. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), t === !0 && downloadFileByBase64(o, e), Promise.resolve(o)));
  2707. case 10:
  2708. _context.prev = 10;
  2709. _context.t0 = _context["catch"](2);
  2710. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), Promise.reject(_context.t0)));
  2711. case 13:
  2712. case "end":
  2713. return _context.stop();
  2714. }
  2715. }
  2716. }, _callee, this, [[2, 10]]);
  2717. }));
  2718. function screenShot(_x) {
  2719. return _screenShot.apply(this, arguments);
  2720. }
  2721. return screenShot;
  2722. }()
  2723. }, {
  2724. key: "changeToFirstPerson",
  2725. value: function changeToFirstPerson(e, t, r) {
  2726. var _this2 = this;
  2727. var n = e.camera,
  2728. o = e.player,
  2729. a = e.attitude,
  2730. s = e.areaName,
  2731. l = e.pathName;
  2732. return this._room.actionsHandler.requestPanorama({
  2733. camera: n,
  2734. player: o,
  2735. attitude: a,
  2736. areaName: s,
  2737. pathName: l
  2738. }, t, r).then(function () {
  2739. _this2._room.networkController.rtcp.workers.changePanoMode(!0);
  2740. var _ref5 = o || {},
  2741. u = _ref5.position,
  2742. c = _ref5.angle;
  2743. _this2._room.sceneManager.cameraComponent.changeToFirstPersonView({
  2744. position: u,
  2745. rotation: c
  2746. });
  2747. });
  2748. }
  2749. }, {
  2750. key: "setPerson",
  2751. value: function setPerson(e) {
  2752. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  2753. camera: this._room._currentClickingState.camera,
  2754. player: this._room._currentClickingState.player
  2755. };
  2756. var r = Date.now();
  2757. return this._setPerson(e, t).then(function (n) {
  2758. return logger.infoAndReportMeasurement({
  2759. tag: Person$1[e],
  2760. startTime: r,
  2761. metric: "setPerson"
  2762. }), n;
  2763. }).catch(function (n) {
  2764. return logger.infoAndReportMeasurement({
  2765. tag: Person$1[e],
  2766. startTime: r,
  2767. metric: "setPerson",
  2768. error: n
  2769. }), Promise.reject(n);
  2770. });
  2771. }
  2772. }, {
  2773. key: "_setPerson",
  2774. value: function _setPerson(e) {
  2775. var _this3 = this;
  2776. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  2777. camera: this._room._currentClickingState.camera,
  2778. player: this._room._currentClickingState.player
  2779. };
  2780. 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({
  2781. camera: t.camera,
  2782. player: t.player,
  2783. tag: "setPerson"
  2784. }).then(function () {
  2785. var o, a;
  2786. _this3._person = e, (o = _this3._room._userAvatar) == null || o.hide();
  2787. var _ref6 = ((a = _this3._room.currentClickingState) == null ? void 0 : a.camera) || {},
  2788. r = _ref6.position,
  2789. n = _ref6.angle;
  2790. !r || !n || _this3._room.sceneManager.cameraComponent.changeToFirstPersonView({
  2791. position: r,
  2792. rotation: n
  2793. });
  2794. }) : this._room.panorama.exit({
  2795. camera: t.camera,
  2796. player: t.player
  2797. }).then(function () {
  2798. var r, n;
  2799. _this3._person = e, (r = _this3._room._userAvatar) != null && r.xAvatar && ((n = _this3._room._userAvatar) == null || n.xAvatar.show());
  2800. });
  2801. }
  2802. }, {
  2803. key: "setCameraPose",
  2804. value: function setCameraPose(e) {
  2805. this._room.sceneManager.cameraComponent.setCameraPose({
  2806. position: e.position,
  2807. rotation: e.angle
  2808. });
  2809. }
  2810. }, {
  2811. key: "setMainCameraRotationLimit",
  2812. value: function setMainCameraRotationLimit(e) {
  2813. var t = e.limitAxis,
  2814. r = e.limitRotation;
  2815. this._room.sceneManager.cameraComponent.setMainCameraRotationLimit(t, r);
  2816. }
  2817. }]);
  2818. return Camera;
  2819. }(EventEmitter);
  2820. 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); }; }
  2821. 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; } }
  2822. var numberFormat = new Intl.NumberFormat(window.navigator.language, {
  2823. maximumFractionDigits: 0
  2824. });
  2825. var Stats = /*#__PURE__*/function (_EventEmitter) {
  2826. _inherits(Stats, _EventEmitter);
  2827. var _super = _createSuper$f(Stats);
  2828. function Stats(e) {
  2829. var _this;
  2830. _classCallCheck(this, Stats);
  2831. _this = _super.call(this);
  2832. _this._netInterval = null;
  2833. _this._disabled = !1;
  2834. _this._show = !1;
  2835. _this._aggregatedStats = {};
  2836. _this._displayElement = null;
  2837. _this._extraStats = {};
  2838. _this._networkSamples = [];
  2839. _this.externalStats = null;
  2840. _this.constructedTime = null;
  2841. _this.room = e, _this.constructedTime = Date.now(), _this._interval = window.setInterval(function () {
  2842. var t, r, n;
  2843. _this._disabled || _this.onStats((n = (r = (t = e.networkController) == null ? void 0 : t.rtcp) == null ? void 0 : r.workers) == null ? void 0 : n.uploadDataToServer());
  2844. }, 1e3), _this._netInterval = window.setInterval(function () {
  2845. _this.getIsWeakNet();
  2846. }, NET_INTERVAL * 1e3);
  2847. return _this;
  2848. }
  2849. _createClass(Stats, [{
  2850. key: "isShow",
  2851. get: function get() {
  2852. return this._show;
  2853. }
  2854. }, {
  2855. key: "assign",
  2856. value: function assign(e) {
  2857. Object.assign(this._extraStats, e), ((e == null ? void 0 : e.hb) || (e == null ? void 0 : e.rtt)) && this.startStatsNetSamples();
  2858. }
  2859. }, {
  2860. key: "appendExternalStats",
  2861. value: function appendExternalStats(e) {
  2862. var _this2 = this;
  2863. var t = {};
  2864. if (!e || typeof e != "object") {
  2865. console.warn("appendExternalStats should be plain object");
  2866. return;
  2867. }
  2868. Object.keys(e).forEach(function (r) {
  2869. Object.prototype.hasOwnProperty.call(_this2._aggregatedStats, r) ? console.warn("".concat(r, " is duplicate with internal stats")) : t[r] = e[r];
  2870. }), !(Object.keys(t).length > 10) && (this.externalStats = t);
  2871. }
  2872. }, {
  2873. key: "getRtt",
  2874. value: function getRtt() {
  2875. var e = this._extraStats.rtt;
  2876. return typeof e != "number" ? 0 : e > 999 ? 999 : e;
  2877. }
  2878. }, {
  2879. key: "enable",
  2880. value: function enable() {
  2881. this._disabled = !1;
  2882. }
  2883. }, {
  2884. key: "disable",
  2885. value: function disable() {
  2886. this._disabled = !0;
  2887. }
  2888. }, {
  2889. key: "disableNet",
  2890. value: function disableNet() {
  2891. this._netInterval && window.clearInterval(this._netInterval);
  2892. }
  2893. }, {
  2894. key: "show",
  2895. value: function show() {
  2896. this._show = !0, this._render();
  2897. }
  2898. }, {
  2899. key: "hide",
  2900. value: function hide() {
  2901. this._show = !1, this._displayElement && document.body.removeChild(this._displayElement), this._displayElement = null;
  2902. }
  2903. }, {
  2904. key: "getIsWeakNet",
  2905. value: function getIsWeakNet() {
  2906. var _this3 = this;
  2907. var e = !1;
  2908. var t = this._networkSamples.length - 1;
  2909. if (t < 0) return;
  2910. var r = this._networkSamples[t].time,
  2911. n = this._networkSamples[0].time,
  2912. o = r - n,
  2913. a = 1e3 * (DURATION - 2);
  2914. if (o < a) return;
  2915. var s = this._networkSamples.map(function (g) {
  2916. return _this3.isNetDelay(g, "rtt");
  2917. }),
  2918. l = this._networkSamples.map(function (g) {
  2919. return _this3.isNetDelay(g, "hb");
  2920. }),
  2921. u = s.reduce(function (g, m) {
  2922. return g + m;
  2923. }, 0),
  2924. c = l.reduce(function (g, m) {
  2925. return g + m;
  2926. }, 0),
  2927. h = Math.floor(u / this._networkSamples.length) * 100,
  2928. f = Math.floor(c / this._networkSamples.length) * 100,
  2929. d = 70;
  2930. (h >= d || f >= d) && (e = !0);
  2931. var _ = this.room.viewMode === "observer" || this.room.viewMode === "serverless";
  2932. e && !_ && (logger.infoAndReportMeasurement({
  2933. metric: "weakNetwork",
  2934. startTime: Date.now(),
  2935. extra: {
  2936. msg: this._networkSamples.slice(20),
  2937. netDelayRTTValues: u,
  2938. netDelayHBValues: c
  2939. }
  2940. }), this.emit("weakNetwork"));
  2941. }
  2942. }, {
  2943. key: "startStatsNetSamples",
  2944. value: function startStatsNetSamples() {
  2945. var _this$_extraStats = this._extraStats,
  2946. e = _this$_extraStats.rtt,
  2947. t = _this$_extraStats.hb;
  2948. if (e || t) {
  2949. var r = {
  2950. rtt: e,
  2951. hb: t,
  2952. time: new Date().getTime()
  2953. };
  2954. this._networkSamples.push(r);
  2955. var n = this._networkSamples.length - 1;
  2956. if (n < 0) return;
  2957. var o = this._networkSamples[n].time,
  2958. a = 1e3 * DURATION;
  2959. this._networkSamples = this._networkSamples.filter(function (s) {
  2960. return s.time > o - a;
  2961. });
  2962. }
  2963. }
  2964. }, {
  2965. key: "isNetDelay",
  2966. value: function isNetDelay(e, t) {
  2967. return t === "rtt" ? e.rtt > RTT_MAX_VALUE ? 1 : 0 : t === "hb" && e.hb > HB_MAX_VALUE ? 1 : 0;
  2968. }
  2969. }, {
  2970. key: "getPreciesTimer",
  2971. value: function getPreciesTimer(e, t) {
  2972. var r = t * 1e3,
  2973. n = new Date().getTime();
  2974. var o = 0;
  2975. o++;
  2976. var a = new Date().getTime() - (n + o * 1e3),
  2977. s = r - a,
  2978. l = setTimeout(function () {
  2979. clearTimeout(l), e();
  2980. }, s);
  2981. }
  2982. }, {
  2983. key: "_render",
  2984. value: function _render() {
  2985. var c, h, f, d, _, g, m, v, y, b, T, C, A, S, P, R, M, x, I, w;
  2986. if (!this._aggregatedStats) return;
  2987. 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));
  2988. var e = [],
  2989. t = Date.now() - this.constructedTime,
  2990. r = Math.floor(t / 1e3 % 60),
  2991. n = Math.floor(t / (1e3 * 60) % 60),
  2992. o = Math.floor(t / (1e3 * 60 * 60) % 24),
  2993. a = o < 10 ? "0" + o.toString() : o.toString(),
  2994. s = n < 10 ? "0" + n : n,
  2995. l = r < 10 ? "0" + r : r;
  2996. e.push({
  2997. key: new Date(Math.floor(this._aggregatedStats.timestamp || 0)).toLocaleString("en-GB"),
  2998. value: a + ":" + s + ":" + l
  2999. }), e.push({
  3000. key: "rtt: " + this._extraStats.rtt + " hb: " + this._extraStats.hb,
  3001. value: "FPS: " + this._extraStats.fps + " avatar: " + ((c = this.room._userAvatar) == null ? void 0 : c.state)
  3002. }), e.push({
  3003. key: "SDK: " + Xverse$1.SUB_PACKAGE_VERSION,
  3004. value: "ENGINE:" + VERSION$1 + " uid:" + this._extraStats.userId
  3005. }), e.push({
  3006. key: "\u540C\u6B65/\u6709\u6548/\u663E\u793A\u73A9\u5BB6",
  3007. value: "".concat(this._extraStats.syncUserNum || 0, "/").concat(this._extraStats.userNum || 0, "/").concat(this._extraStats.renderedUserNum || 0)
  3008. }), e.push({
  3009. key: "media/meta bitrate(kbps)",
  3010. value: numberFormat.format(this._aggregatedStats.mediaBitrate || 0) + "/" + numberFormat.format(this._aggregatedStats.metaBitrate || 0)
  3011. }), e.push({
  3012. key: ":----------------Decoding---------------",
  3013. value: ""
  3014. }), e.push({
  3015. key: "-max/avg decodeTime(ms)",
  3016. value: numberFormat.format(this._aggregatedStats.decodeTimeMaxFrame || 0) + "/" + numberFormat.format(this._aggregatedStats.decodeTimePerFrame || 0)
  3017. }), e.push({
  3018. key: "-frmAwait/Lost/Drop",
  3019. 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
  3020. }), e.push({
  3021. key: ":----------------FrameLoop-------------",
  3022. value: ""
  3023. }), e.push({
  3024. key: "interval(max/avg/>40)",
  3025. 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
  3026. }), e.push({
  3027. key: "systemStuck",
  3028. value: this._extraStats.systemStuckCnt
  3029. }), e.push({
  3030. key: "--update",
  3031. value: (this._aggregatedStats.maxGraphicTime.toFixed(1) || 0) + "/" + (((d = this._aggregatedStats.averageGraphicTime) == null ? void 0 : d.toFixed(0)) || 0)
  3032. }), e.push({
  3033. key: "--timeout",
  3034. value: (((_ = this._extraStats.maxTimeoutTime) == null ? void 0 : _.toFixed(1)) || 0) + "/" + ((g = this._extraStats.avgTimeoutTime) == null ? void 0 : g.toFixed(0)) || 0
  3035. }), e.push({
  3036. key: "--render",
  3037. value: (((m = this._extraStats.maxRenderFrameTime) == null ? void 0 : m.toFixed(1)) || 0) + "/" + (((v = this._extraStats.renderFrameTime) == null ? void 0 : v.toFixed(0)) || 0)
  3038. }), e.push({
  3039. key: "---anim/regBR/clip(avg ms)",
  3040. value: (this._extraStats.animationTime.toFixed(2) || 0) + " / " + (this._extraStats.registerBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.meshSelectTime.toFixed(2) || 0)
  3041. }), e.push({
  3042. key: "---anim/regBR/clip(max ms)",
  3043. value: (this._extraStats.maxAnimationTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxMeshSelectTime.toFixed(2) || 0)
  3044. }), e.push({
  3045. key: "---rTR/drC/regAF(avg ms)",
  3046. value: (this._extraStats.renderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.drawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.registerAfterRenderTime.toFixed(2) || 0)
  3047. }), e.push({
  3048. key: "---rTR/drC/regAF(max ms)",
  3049. value: (this._extraStats.maxRenderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxDrawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterAfterRenderTime.toFixed(2) || 0)
  3050. }), e.push({
  3051. key: "--tri/drC/pati/bones/anim(Num)",
  3052. 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)
  3053. }), e.push({
  3054. key: "--rootN/mesh/geo/tex/mat(Num)",
  3055. 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)
  3056. }), e.push({
  3057. key: "--registerBF/AF(Num)",
  3058. value: (this._extraStats.registerBeforeCount.toFixed(0) || 0) + " / " + (this._extraStats.registerAfterCount.toFixed(0) || 0)
  3059. }), e.push({
  3060. key: ":----------------Rotation-------------------",
  3061. value: ""
  3062. }), e.push({
  3063. key: "Total(ms/miss)",
  3064. value: (((y = this._aggregatedStats.avgOverallTime) == null ? void 0 : y.toFixed(2)) || 0) + "/" + (this._aggregatedStats.responseMissPs + this._aggregatedStats.processMissPs + this._aggregatedStats.displayMissPs)
  3065. }), e.push({
  3066. key: "--rotateRsp",
  3067. value: (((b = this._aggregatedStats.avgResponseTime) == null ? void 0 : b.toFixed(1)) || 0) + "/" + this._aggregatedStats.responseMissPs
  3068. }), e.push({
  3069. key: "--rotateProc",
  3070. value: (((T = this._aggregatedStats.avgProcessTime) == null ? void 0 : T.toFixed(1)) || 0) + "/" + this._aggregatedStats.processMissPs
  3071. }), e.push({
  3072. key: "--rotateShow",
  3073. value: (((C = this._aggregatedStats.avgDisplayTime) == null ? void 0 : C.toFixed(1)) || 0) + "/" + this._aggregatedStats.displayMissPs
  3074. }), ((A = this.room._userAvatar) == null ? void 0 : A.state) == "moving", e.push({
  3075. key: ":----------------Move----------------------",
  3076. value: ""
  3077. }), e.push({
  3078. key: "-startDelay",
  3079. 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)
  3080. }), (((S = this.room._userAvatar) == null ? void 0 : S.state) == "moving" || this._aggregatedStats.moveEvent == "GetOnAirship" || this._aggregatedStats.moveEvent == "GetOnVehicle") && e.push({
  3081. key: "-srvInterFrm(max/avg)",
  3082. value: (this._aggregatedStats.maxServerDiff || 0) + "/" + (this._aggregatedStats.avgServerDiff.toFixed(1) || 0)
  3083. }), e.push({
  3084. key: "-interFrameDelay",
  3085. value: "(max/avg/jank)"
  3086. }), e.push({
  3087. key: "--toDisplay",
  3088. 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)
  3089. }), e.push({
  3090. key: "--received",
  3091. 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)
  3092. }), e.push({
  3093. key: "--decoded",
  3094. 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)
  3095. }), e.push({
  3096. key: ":----------------DevInfo-----------------",
  3097. value: ""
  3098. }), e.push({
  3099. key: "sd",
  3100. value: (this._aggregatedStats.sdMoveResponseLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveProcessLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveDisplayLongTime.toFixed(1) || 0)
  3101. }), e.push({
  3102. key: "----hardwareInfo",
  3103. value: this._extraStats.hardwareInfo
  3104. });
  3105. var u = "";
  3106. for (var _i = 0, _e = e; _i < _e.length; _i++) {
  3107. var O = _e[_i];
  3108. u += "<div><span>".concat(O.key, "</span>: <span>").concat(O.value, "</span> </div>");
  3109. }
  3110. this._displayElement.innerHTML = u;
  3111. }
  3112. }, {
  3113. key: "onStats",
  3114. value: function onStats(e) {
  3115. var _this4 = this;
  3116. var n;
  3117. if (!e) return;
  3118. var t = {},
  3119. r = this;
  3120. 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) {
  3121. t[o] = _this4.externalStats[o];
  3122. }), r._aggregatedStats = t, this.emit("stats", {
  3123. stats: t
  3124. });
  3125. }
  3126. }]);
  3127. return Stats;
  3128. }(EventEmitter);
  3129. var Actions$1 = {
  3130. Clicking: 1,
  3131. PlayCG: 6,
  3132. Back: 7,
  3133. ChangeRoom: 8,
  3134. ChangeSkin: 13,
  3135. Joystick: 15,
  3136. Transfer: 18,
  3137. GetOnVehicle: 22,
  3138. GetOffVehicle: 23,
  3139. StopMoving: 34,
  3140. UnaryActionLine: 1e3,
  3141. Init: 1001,
  3142. Exit: 1002,
  3143. SetIFrameInfo: 1003,
  3144. GetNeighborPoints: 1004,
  3145. ReserveSeat: 1005,
  3146. GetReserveStatus: 1006,
  3147. ChangeNickname: 1007,
  3148. ChangeBitRateInfo: 1008,
  3149. Echo: 1009,
  3150. SetPlayerState: 1010,
  3151. TurnTo: 1011,
  3152. TurnToFace: 1012,
  3153. RotateTo: 1013,
  3154. Rotation: 1014,
  3155. CameraTurnTo: 1015,
  3156. ConfirmEvent: 1016,
  3157. Broadcast: 1017,
  3158. NotifyActionLine: 2e4,
  3159. AudienceChangeToVisitor: 1020,
  3160. VisitorChangeToAudience: 1021,
  3161. RemoveVisitor: 1022,
  3162. GetUserWithAvatar: 1023
  3163. };
  3164. 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); }; }
  3165. 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; } }
  3166. var EventsManager = /*#__PURE__*/function (_EventEmitter) {
  3167. _inherits(EventsManager, _EventEmitter);
  3168. var _super = _createSuper$e(EventsManager);
  3169. function EventsManager() {
  3170. var _this;
  3171. _classCallCheck(this, EventsManager);
  3172. _this = _super.apply(this, arguments);
  3173. E(_assertThisInitialized(_this), "events", new Map());
  3174. E(_assertThisInitialized(_this), "specialEvents", new Map());
  3175. return _this;
  3176. }
  3177. _createClass(EventsManager, [{
  3178. key: "remove",
  3179. value: function remove(e, t, r, n) {
  3180. if (this.specialEvents.has(e) && !n && t === Codes$1.Success) return;
  3181. this.events.get(e) && (this.emit(e, {
  3182. code: t,
  3183. data: r
  3184. }), this.events.delete(e), this.specialEvents.delete(e));
  3185. }
  3186. }, {
  3187. key: "track",
  3188. value: function () {
  3189. var _track = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  3190. var _this2 = this;
  3191. var r, _ref, n, _ref$noReport, o, a, s, l, u, c;
  3192. return regenerator.wrap(function _callee$(_context) {
  3193. while (1) {
  3194. switch (_context.prev = _context.next) {
  3195. case 0:
  3196. r = e.traceId;
  3197. this.emitTraceIdToDecoder(e);
  3198. _ref = t || {}, n = _ref.sampleRate, _ref$noReport = _ref.noReport, o = _ref$noReport === void 0 ? !1 : _ref$noReport, a = _ref.special;
  3199. if (!(n && Math.random() > n)) {
  3200. _context.next = 5;
  3201. break;
  3202. }
  3203. return _context.abrupt("return", Promise.resolve());
  3204. case 5:
  3205. s = Actions[e.event] + "Action", l = e.tag;
  3206. this.events.set(r, !0), a && this.specialEvents.set(r, !0);
  3207. u = Date.now();
  3208. c = null;
  3209. return _context.abrupt("return", new Promise(function (h, f) {
  3210. if (o) return _this2.off(r), _this2.events.delete(r), h(void 0);
  3211. _this2.on(r, function (_ref2) {
  3212. var _ = _ref2.code,
  3213. g = _ref2.data,
  3214. m = _ref2.msg;
  3215. if (_ === Codes$1.Success) h(g), _this2.off(r), logger.infoAndReportMeasurement({
  3216. metric: s,
  3217. tag: l,
  3218. extra: e.extra,
  3219. startTime: u,
  3220. traceId: r
  3221. });else {
  3222. if (_ === Codes$1.ActionMaybeDelay) return;
  3223. if (_ === Codes$1.DoActionBlocked && e.event === Actions.Rotation) {
  3224. logger.debug(s + " response code: " + _);
  3225. return;
  3226. }
  3227. var v = getErrorByCode(_),
  3228. y = new v(m);
  3229. _this2.off(r), f(y), _this2.emit("actionResponseError", {
  3230. error: y,
  3231. event: e,
  3232. tag: l
  3233. }), logger.infoAndReportMeasurement({
  3234. metric: s,
  3235. tag: l,
  3236. extra: e.extra,
  3237. error: y,
  3238. startTime: u,
  3239. traceId: r
  3240. });
  3241. }
  3242. });
  3243. var d = e.timeout || 2e3;
  3244. c = window.setTimeout(function () {
  3245. if (c && clearTimeout(c), !_this2.events.get(r)) return;
  3246. var _ = new ActionResponseTimeoutError("".concat(s, " timeout in ").concat(d, "ms"));
  3247. _this2.emit("actionResponseTimeout", {
  3248. error: _,
  3249. event: e,
  3250. tag: l
  3251. }), f(_), _this2.events.delete(r), _this2.off(r), logger.infoAndReportMeasurement({
  3252. metric: s,
  3253. tag: l,
  3254. extra: e.extra,
  3255. error: _,
  3256. startTime: u,
  3257. traceId: r
  3258. });
  3259. }, d);
  3260. }));
  3261. case 10:
  3262. case "end":
  3263. return _context.stop();
  3264. }
  3265. }
  3266. }, _callee, this);
  3267. }));
  3268. function track(_x, _x2) {
  3269. return _track.apply(this, arguments);
  3270. }
  3271. return track;
  3272. }()
  3273. }, {
  3274. key: "emitTraceIdToDecoder",
  3275. value: function emitTraceIdToDecoder(e) {
  3276. if (e.event === Actions.Rotation || e.event === Actions.Clicking || e.event === Actions.GetOnVehicle || e.event === Actions.GetOffVehicle) {
  3277. var t = {
  3278. [Actions.Rotation]: "Rotation",
  3279. [Actions.GetOnVehicle]: "GetOnVehicle",
  3280. [Actions.GetOffVehicle]: "GetOffVehicle",
  3281. [Actions.Clicking]: "MoveTo"
  3282. };
  3283. this.emit("traceId", {
  3284. traceId: e.traceId,
  3285. timestamp: Date.now(),
  3286. event: t[e.event]
  3287. });
  3288. }
  3289. }
  3290. }]);
  3291. return EventsManager;
  3292. }(EventEmitter);
  3293. var eventsManager = new EventsManager();
  3294. var QueueActions = [Actions$1.Transfer, Actions$1.ChangeSkin, Actions$1.GetOnVehicle, Actions$1.GetOffVehicle];
  3295. var ActionsHandler = /*#__PURE__*/function () {
  3296. function ActionsHandler(e) {
  3297. _classCallCheck(this, ActionsHandler);
  3298. this.currentActiveAction = null;
  3299. this.room = e;
  3300. }
  3301. _createClass(ActionsHandler, [{
  3302. key: "avatarComponentsSync",
  3303. value: function () {
  3304. var _avatarComponentsSync = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  3305. var t;
  3306. return regenerator.wrap(function _callee$(_context) {
  3307. while (1) {
  3308. switch (_context.prev = _context.next) {
  3309. case 0:
  3310. t = {
  3311. action_type: Actions$1.SetPlayerState,
  3312. set_player_state_action: {
  3313. player_state: {
  3314. avatar_components: JSON.stringify(e)
  3315. }
  3316. }
  3317. };
  3318. this.sendData({
  3319. data: t
  3320. });
  3321. case 2:
  3322. case "end":
  3323. return _context.stop();
  3324. }
  3325. }
  3326. }, _callee, this);
  3327. }));
  3328. function avatarComponentsSync(_x) {
  3329. return _avatarComponentsSync.apply(this, arguments);
  3330. }
  3331. return avatarComponentsSync;
  3332. }()
  3333. }, {
  3334. key: "sendData",
  3335. value: function () {
  3336. var _sendData = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  3337. var _this = this;
  3338. var t, _e$sampleRate, r, _e$timeout, n, o, a, s;
  3339. return regenerator.wrap(function _callee2$(_context2) {
  3340. while (1) {
  3341. switch (_context2.prev = _context2.next) {
  3342. case 0:
  3343. _context2.next = 2;
  3344. return this.beforeSend(e);
  3345. case 2:
  3346. t = util.uuid();
  3347. if (!(this.room.networkController.sendRtcData(le(oe({}, e.data), {
  3348. trace_id: t,
  3349. user_id: this.room.options.userId
  3350. })), e.track === !1)) {
  3351. _context2.next = 5;
  3352. break;
  3353. }
  3354. return _context2.abrupt("return", Promise.resolve(null));
  3355. case 5:
  3356. _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;
  3357. return _context2.abrupt("return", eventsManager.track({
  3358. timeout: n,
  3359. traceId: t,
  3360. event: a.action_type,
  3361. tag: o,
  3362. extra: a
  3363. }, {
  3364. special: s,
  3365. sampleRate: r,
  3366. noReport: this.room.viewMode === "serverless" || this.room.options.viewMode === "serverless"
  3367. }).finally(function () {
  3368. QueueActions.includes(e.data.action_type) && (_this.currentActiveAction = void 0);
  3369. }));
  3370. case 7:
  3371. case "end":
  3372. return _context2.stop();
  3373. }
  3374. }
  3375. }, _callee2, this);
  3376. }));
  3377. function sendData(_x2) {
  3378. return _sendData.apply(this, arguments);
  3379. }
  3380. return sendData;
  3381. }()
  3382. }, {
  3383. key: "beforeSend",
  3384. value: function () {
  3385. var _beforeSend = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  3386. var o, t, r;
  3387. return regenerator.wrap(function _callee3$(_context3) {
  3388. while (1) {
  3389. switch (_context3.prev = _context3.next) {
  3390. case 0:
  3391. t = (o = this.room._userAvatar) == null ? void 0 : o.isMoving, r = e.data.action_type;
  3392. if (!QueueActions.includes(r)) {
  3393. _context3.next = 5;
  3394. break;
  3395. }
  3396. if (!this.currentActiveAction) {
  3397. _context3.next = 4;
  3398. break;
  3399. }
  3400. 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")))));
  3401. case 4:
  3402. this.currentActiveAction = r;
  3403. case 5:
  3404. if (!(t && QueueActions.includes(e.data.action_type))) {
  3405. _context3.next = 14;
  3406. break;
  3407. }
  3408. _context3.prev = 6;
  3409. _context3.next = 9;
  3410. return this.stopMoving();
  3411. case 9:
  3412. _context3.next = 14;
  3413. break;
  3414. case 11:
  3415. _context3.prev = 11;
  3416. _context3.t0 = _context3["catch"](6);
  3417. this.currentActiveAction = void 0, logger.error("before action stopMoving failed", _context3.t0);
  3418. case 14:
  3419. case "end":
  3420. return _context3.stop();
  3421. }
  3422. }
  3423. }, _callee3, this, [[6, 11]]);
  3424. }));
  3425. function beforeSend(_x3) {
  3426. return _beforeSend.apply(this, arguments);
  3427. }
  3428. return beforeSend;
  3429. }()
  3430. }, {
  3431. key: "moveTo",
  3432. value: function () {
  3433. var _moveTo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  3434. var t, _e$extra, r, n, o;
  3435. return regenerator.wrap(function _callee4$(_context4) {
  3436. while (1) {
  3437. switch (_context4.prev = _context4.next) {
  3438. case 0:
  3439. t = e.point, _e$extra = e.extra, r = _e$extra === void 0 ? "" : _e$extra, n = e.motionType, o = {
  3440. action_type: Actions$1.Clicking,
  3441. clicking_action: {
  3442. clicking_point: t,
  3443. clicking_type: ClickType.IgnoreView,
  3444. extra: encodeURIComponent(r),
  3445. attitude: n
  3446. },
  3447. clicking_state: this.room._currentClickingState
  3448. };
  3449. return _context4.abrupt("return", this.sendData({
  3450. data: o
  3451. }));
  3452. case 2:
  3453. case "end":
  3454. return _context4.stop();
  3455. }
  3456. }
  3457. }, _callee4, this);
  3458. }));
  3459. function moveTo(_x4) {
  3460. return _moveTo.apply(this, arguments);
  3461. }
  3462. return moveTo;
  3463. }()
  3464. }, {
  3465. key: "transfer",
  3466. value: function transfer(e) {
  3467. var _this2 = this;
  3468. var t = e.renderType,
  3469. r = e.player,
  3470. n = e.camera,
  3471. o = e.areaName,
  3472. a = e.attitude,
  3473. s = e.pathName,
  3474. l = e.person,
  3475. u = e.noMedia,
  3476. c = e.timeout,
  3477. h = e.tag,
  3478. f = e.special,
  3479. d = {
  3480. data: {
  3481. action_type: Actions$1.Transfer,
  3482. transfer_action: {
  3483. render_type: t,
  3484. player: r,
  3485. camera: n,
  3486. areaName: o,
  3487. attitude: a,
  3488. pathName: s,
  3489. person: {
  3490. type: l
  3491. },
  3492. noMedia: u,
  3493. tiles: [0, 1, 2, 4]
  3494. }
  3495. },
  3496. special: f,
  3497. timeout: c || 4e3,
  3498. tag: h
  3499. };
  3500. return this.sendData(d).then(function (_) {
  3501. return typeof l != "undefined" && _this2.room.updateCurrentNetworkOptions({
  3502. person: l,
  3503. rotationRenderType: t
  3504. }), _;
  3505. });
  3506. }
  3507. }, {
  3508. key: "changeRotationRenderType",
  3509. value: function changeRotationRenderType(e) {
  3510. var t = e.renderType,
  3511. r = e.player,
  3512. n = e.camera,
  3513. o = e.areaName,
  3514. a = e.attitude,
  3515. s = e.pathName;
  3516. return this.transfer({
  3517. renderType: t,
  3518. player: r,
  3519. camera: n,
  3520. areaName: o,
  3521. attitude: a,
  3522. pathName: s,
  3523. tag: "changeToRotationVideo"
  3524. });
  3525. }
  3526. }, {
  3527. key: "requestPanorama",
  3528. value: function requestPanorama(e, t, r) {
  3529. var n = e.camera,
  3530. o = e.player,
  3531. a = e.areaName,
  3532. s = e.attitude,
  3533. l = e.pathName,
  3534. u = e.tag;
  3535. return this.transfer({
  3536. renderType: RenderType.ClientRotationPano,
  3537. player: o,
  3538. camera: n,
  3539. person: Person.First,
  3540. areaName: a,
  3541. attitude: s,
  3542. pathName: l,
  3543. noMedia: t,
  3544. timeout: r,
  3545. tag: u || "requestPanorama",
  3546. special: !t
  3547. });
  3548. }
  3549. }, {
  3550. key: "setMotionType",
  3551. value: function setMotionType(e) {
  3552. return this.transfer({
  3553. attitude: e,
  3554. tag: "setMotionType"
  3555. });
  3556. }
  3557. }, {
  3558. key: "setNickName",
  3559. value: function setNickName(e) {
  3560. var t = {
  3561. action_type: Actions$1.ChangeNickname,
  3562. change_nickname_action: {
  3563. nickname: e
  3564. }
  3565. };
  3566. return this.sendData({
  3567. data: t
  3568. });
  3569. }
  3570. }, {
  3571. key: "getReserveSeat",
  3572. value: function getReserveSeat(_ref) {
  3573. var e = _ref.routeId,
  3574. t = _ref.name;
  3575. var r = {
  3576. action_type: Actions$1.ReserveSeat,
  3577. reserve_seat_action: {
  3578. route_id: e,
  3579. name: t
  3580. }
  3581. };
  3582. return this.sendData({
  3583. data: r
  3584. });
  3585. }
  3586. }, {
  3587. key: "getReserveStatus",
  3588. value: function getReserveStatus(_ref2) {
  3589. var e = _ref2.routeId,
  3590. t = _ref2.name,
  3591. r = _ref2.need_detail;
  3592. var n = {
  3593. action_type: Actions$1.GetReserveStatus,
  3594. get_reserve_status_action: {
  3595. route_id: e,
  3596. name: t,
  3597. need_detail: r
  3598. }
  3599. };
  3600. return this.sendData({
  3601. data: n,
  3602. timeout: 2e3
  3603. }).then(function (o) {
  3604. return o.reserveDetail;
  3605. });
  3606. }
  3607. }, {
  3608. key: "stopMoving",
  3609. value: function stopMoving() {
  3610. var e = {
  3611. action_type: Actions$1.StopMoving,
  3612. stop_move_action: {}
  3613. };
  3614. return this.sendData({
  3615. data: e
  3616. });
  3617. }
  3618. }, {
  3619. key: "getOnVehicle",
  3620. value: function getOnVehicle(_ref3) {
  3621. var e = _ref3.routeId,
  3622. t = _ref3.name,
  3623. r = _ref3.camera;
  3624. var n = {
  3625. action_type: Actions$1.GetOnVehicle,
  3626. get_on_vehicle_action: {
  3627. route_id: e,
  3628. name: t,
  3629. camera: r
  3630. }
  3631. };
  3632. return this.sendData({
  3633. data: n
  3634. });
  3635. }
  3636. }, {
  3637. key: "getOffVehicle",
  3638. value: function getOffVehicle(_ref4) {
  3639. var e = _ref4.renderType,
  3640. t = _ref4.player,
  3641. r = _ref4.camera;
  3642. var n = {
  3643. action_type: Actions$1.GetOffVehicle,
  3644. get_off_vehicle_action: {
  3645. render_type: e,
  3646. player: t,
  3647. camera: r
  3648. }
  3649. };
  3650. return this.sendData({
  3651. data: n
  3652. });
  3653. }
  3654. }, {
  3655. key: "confirmEvent",
  3656. value: function confirmEvent(e) {
  3657. var t = {
  3658. action_type: Actions$1.ConfirmEvent,
  3659. confirm_event_action: {
  3660. id: e
  3661. }
  3662. };
  3663. return this.sendData({
  3664. data: t,
  3665. track: !1
  3666. });
  3667. }
  3668. }, {
  3669. key: "echo",
  3670. value: function echo(e) {
  3671. var t = {
  3672. action_type: Actions$1.Echo,
  3673. echo_msg: {
  3674. echoMsg: e
  3675. }
  3676. };
  3677. return this.sendData({
  3678. data: t,
  3679. track: !1
  3680. });
  3681. }
  3682. }, {
  3683. key: "changeSkin",
  3684. value: function () {
  3685. var _changeSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  3686. var _this3 = this;
  3687. var t, r, n, _e$landingType, o, a, s, l, u, c, h, f, d, _, _e$roomTypeId, g, m, y, v;
  3688. return regenerator.wrap(function _callee6$(_context6) {
  3689. while (1) {
  3690. switch (_context6.prev = _context6.next) {
  3691. case 0:
  3692. 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) {
  3693. return y.id === r;
  3694. })[0];
  3695. if (m) {
  3696. _context6.next = 4;
  3697. break;
  3698. }
  3699. y = "skin ".concat(r, " is invalid");
  3700. return _context6.abrupt("return", (logger.error(y), Promise.reject(new ParamError(y))));
  3701. case 4:
  3702. v = {
  3703. action_type: Actions$1.ChangeSkin,
  3704. change_skin_action: {
  3705. skinID: r,
  3706. mode: n === ChangeMode.Preview ? ChangeMode.Preview : ChangeMode.Confirm,
  3707. skin_data_version: r + m.versionId,
  3708. landing_type: o,
  3709. landing_point: a,
  3710. landing_camera: s,
  3711. render_wrapper: {
  3712. render_type: l
  3713. },
  3714. areaName: u,
  3715. attitude: c,
  3716. noMedia: d,
  3717. person: f,
  3718. pathName: h,
  3719. roomTypeId: g
  3720. }
  3721. };
  3722. return _context6.abrupt("return", this.sendData({
  3723. data: v,
  3724. timeout: _ || 6e3,
  3725. special: t
  3726. }).then( /*#__PURE__*/function () {
  3727. var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(y) {
  3728. var b, _ref6, T;
  3729. return regenerator.wrap(function _callee5$(_context5) {
  3730. while (1) {
  3731. switch (_context5.prev = _context5.next) {
  3732. case 0:
  3733. if (!(l === RenderType.ClientRotationPano && y)) {
  3734. _context5.next = 8;
  3735. break;
  3736. }
  3737. _context5.next = 3;
  3738. return _this3.room.modelManager.findRoute(r, h);
  3739. case 3:
  3740. b = _context5.sent;
  3741. _ref6 = util.getRandomItem(b.birthPointList) || {};
  3742. T = _ref6.camera;
  3743. _context5.next = 8;
  3744. return _this3.room.panorama.handleReceivePanorama(y, T);
  3745. case 8:
  3746. return _context5.abrupt("return", _this3.handleChangeSkin(e));
  3747. case 9:
  3748. case "end":
  3749. return _context5.stop();
  3750. }
  3751. }
  3752. }, _callee5);
  3753. }));
  3754. return function (_x6) {
  3755. return _ref5.apply(this, arguments);
  3756. };
  3757. }()).catch(function (y) {
  3758. return d ? _this3.handleChangeSkin(e) : Promise.reject(y);
  3759. }));
  3760. case 6:
  3761. case "end":
  3762. return _context6.stop();
  3763. }
  3764. }
  3765. }, _callee6, this);
  3766. }));
  3767. function changeSkin(_x5) {
  3768. return _changeSkin.apply(this, arguments);
  3769. }
  3770. return changeSkin;
  3771. }()
  3772. }, {
  3773. key: "handleChangeSkin",
  3774. value: function handleChangeSkin(e) {
  3775. var _this4 = this;
  3776. var t = e.skinId,
  3777. r = e.mode,
  3778. n = e.renderType,
  3779. o = e.areaName,
  3780. a = e.attitude,
  3781. s = e.pathName;
  3782. return this.room.sceneManager.staticmeshComponent.getCgMesh().show(), this.room.sceneManager.cameraComponent.switchToCgCamera(), this.room.engineProxy._updateSkinAssets(t).then(function () {
  3783. _this4.room.sceneManager.staticmeshComponent.getCgMesh().hide(), _this4.room.sceneManager.cameraComponent.switchToMainCamera(), _this4.room.pathManager.currentArea = o, logger.info("changeSkin _updateSkinAssets susccss"), _this4.room.updateCurrentNetworkOptions({
  3784. pathName: s,
  3785. attitude: a,
  3786. areaName: o
  3787. }), _this4.room.skinChangedHook(), _this4.room.emit("skinChanged", {
  3788. skin: {
  3789. id: t
  3790. },
  3791. mode: r
  3792. }), n === RenderType.ClientRotationPano && _this4.room.sceneManager.cameraComponent.allowMainCameraController();
  3793. });
  3794. }
  3795. }, {
  3796. key: "rotate",
  3797. value: function rotate(_ref7) {
  3798. var e = _ref7.pitch,
  3799. t = _ref7.yaw;
  3800. var n;
  3801. if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode)) return;
  3802. var r = {
  3803. action_type: Actions$1.Rotation,
  3804. rotation_action: {
  3805. vertical_move: e,
  3806. horizontal_move: -t
  3807. }
  3808. };
  3809. this.sendData({
  3810. data: r,
  3811. sampleRate: .02
  3812. });
  3813. }
  3814. }, {
  3815. key: "turnTo",
  3816. value: function turnTo(e) {
  3817. var _ref8 = e || {},
  3818. t = _ref8.point,
  3819. _ref8$timeout = _ref8.timeout,
  3820. r = _ref8$timeout === void 0 ? 2e3 : _ref8$timeout,
  3821. _ref8$offset = _ref8.offset,
  3822. n = _ref8$offset === void 0 ? 8 : _ref8$offset,
  3823. o = {
  3824. action_type: Actions$1.TurnTo,
  3825. turn_to_action: {
  3826. turn_to_point: t,
  3827. offset: n
  3828. }
  3829. };
  3830. return this.sendData({
  3831. data: o,
  3832. timeout: r
  3833. });
  3834. }
  3835. }, {
  3836. key: "rotateTo",
  3837. value: function rotateTo(e) {
  3838. var _ref9 = e || {},
  3839. t = _ref9.point,
  3840. _ref9$offset = _ref9.offset,
  3841. r = _ref9$offset === void 0 ? 0 : _ref9$offset,
  3842. _ref9$speed = _ref9.speed,
  3843. n = _ref9$speed === void 0 ? 3 : _ref9$speed,
  3844. o = {
  3845. action_type: Actions$1.RotateTo,
  3846. rotate_to_action: {
  3847. rotate_to_point: t,
  3848. offset: r,
  3849. speed: n
  3850. }
  3851. };
  3852. return this.sendData({
  3853. data: o
  3854. });
  3855. }
  3856. }, {
  3857. key: "broadcast",
  3858. value: function broadcast(e) {
  3859. var t = e.data,
  3860. _e$msgType = e.msgType,
  3861. r = _e$msgType === void 0 ? MessageHandleType.MHT_FollowListMulticast : _e$msgType,
  3862. n = e.targetUserIds;
  3863. if (r === MessageHandleType.MHT_CustomTargetSync && !Array.isArray(n)) return Promise.reject(new ParamError("param targetUserIds is required when msgType is ".concat(MessageHandleType[r])));
  3864. var o = {
  3865. action_type: Actions$1.Broadcast,
  3866. broadcast_action: {
  3867. data: JSON.stringify(t),
  3868. user_id: this.room.options.userId,
  3869. msgType: r
  3870. }
  3871. };
  3872. return Array.isArray(n) && r === MessageHandleType.MHT_CustomTargetSync && (o.broadcast_action.target_user_ids = n), this.room.actionsHandler.sendData({
  3873. data: o,
  3874. tag: t.broadcastType
  3875. });
  3876. }
  3877. }, {
  3878. key: "getNeighborPoints",
  3879. value: function getNeighborPoints(e) {
  3880. var t = e.point,
  3881. _e$containSelf = e.containSelf,
  3882. r = _e$containSelf === void 0 ? !1 : _e$containSelf,
  3883. _e$searchRange = e.searchRange,
  3884. n = _e$searchRange === void 0 ? 500 : _e$searchRange,
  3885. o = {
  3886. action_type: Actions$1.GetNeighborPoints,
  3887. get_neighbor_points_action: {
  3888. point: t,
  3889. level: 1,
  3890. containSelf: r,
  3891. searchRange: n
  3892. }
  3893. };
  3894. return this.sendData({
  3895. data: o
  3896. }).then(function (a) {
  3897. return a.nps;
  3898. });
  3899. }
  3900. }, {
  3901. key: "playCG",
  3902. value: function playCG(e) {
  3903. var t = {
  3904. action_type: Actions$1.PlayCG,
  3905. play_cg_action: {
  3906. cg_name: e
  3907. }
  3908. };
  3909. return this.sendData({
  3910. data: t
  3911. });
  3912. }
  3913. }, {
  3914. key: "audienceToVisitor",
  3915. value: function audienceToVisitor(e) {
  3916. var t = e.avatarId,
  3917. r = e.avatarComponents,
  3918. n = e.player,
  3919. o = e.camera,
  3920. a = {
  3921. action_type: Actions$1.AudienceChangeToVisitor,
  3922. audienceChangeToVisitorAction: {
  3923. avatarID: t,
  3924. avatarComponents: r,
  3925. player: n,
  3926. camera: o
  3927. }
  3928. };
  3929. return logger.debug("send data: audience to visitor"), this.sendData({
  3930. data: a
  3931. });
  3932. }
  3933. }, {
  3934. key: "visitorToAudience",
  3935. value: function visitorToAudience(e) {
  3936. var t = e.renderType,
  3937. r = e.player,
  3938. n = e.camera,
  3939. o = e.areaName,
  3940. a = e.attitude,
  3941. s = e.pathName,
  3942. l = e.person,
  3943. u = e.noMedia,
  3944. c = {
  3945. action_type: Actions$1.VisitorChangeToAudience,
  3946. visitorChangeToAudienceAction: {
  3947. transferAction: {
  3948. render_type: t,
  3949. player: r,
  3950. camera: n,
  3951. areaName: o,
  3952. attitude: a,
  3953. pathName: s,
  3954. person: {
  3955. type: l
  3956. },
  3957. noMedia: u,
  3958. tiles: [0, 1, 2, 4]
  3959. }
  3960. }
  3961. };
  3962. return logger.debug("send data: visitor to audience"), this.sendData({
  3963. data: c
  3964. });
  3965. }
  3966. }, {
  3967. key: "removeVisitor",
  3968. value: function removeVisitor(e) {
  3969. var t = e.removeType,
  3970. r = e.userIDList,
  3971. _e$extraInfo = e.extraInfo,
  3972. n = _e$extraInfo === void 0 ? "" : _e$extraInfo,
  3973. o = {
  3974. action_type: Actions$1.RemoveVisitor,
  3975. removeVisitorAction: {
  3976. removeVisitorEvent: t,
  3977. userIDList: r,
  3978. extraInfo: encodeURIComponent(n)
  3979. }
  3980. };
  3981. return logger.debug("send data: remove visitor"), this.sendData({
  3982. data: o
  3983. });
  3984. }
  3985. }, {
  3986. key: "getUserWithAvatar",
  3987. value: function getUserWithAvatar(e, t) {
  3988. var r = {
  3989. action_type: Actions$1.GetUserWithAvatar,
  3990. getUserWithAvatarAction: {
  3991. userType: e,
  3992. roomID: t
  3993. }
  3994. };
  3995. return logger.debug("send data: get user with avatar"), this.sendData({
  3996. data: r
  3997. }).then(function (n) {
  3998. return n.userWithAvatarList;
  3999. });
  4000. }
  4001. }, {
  4002. key: "joystick",
  4003. value: function joystick(e) {
  4004. var t = e.degree,
  4005. _e$level = e.level,
  4006. r = _e$level === void 0 ? 1 : _e$level,
  4007. n = util.uuid();
  4008. var o = -t + 90 + 360;
  4009. o >= 360 && (o -= 360);
  4010. var a = {
  4011. action_type: Actions$1.Joystick,
  4012. dir_action: {
  4013. move_angle: o,
  4014. speed_level: r
  4015. },
  4016. trace_id: n,
  4017. user_id: this.room.options.userId,
  4018. packet_id: n
  4019. };
  4020. return this.sendData({
  4021. data: a,
  4022. track: !1
  4023. });
  4024. }
  4025. }]);
  4026. return ActionsHandler;
  4027. }();
  4028. var ECurrentShaderMode = {
  4029. default: 0,
  4030. video: 1,
  4031. pano: 2
  4032. };
  4033. var Signal = /*#__PURE__*/function () {
  4034. function Signal(e) {
  4035. _classCallCheck(this, Signal);
  4036. this.signalHandleActived = !0;
  4037. this.isUpdatedYUV = !0;
  4038. this._room = e;
  4039. }
  4040. _createClass(Signal, [{
  4041. key: "handleSignal",
  4042. value: function handleSignal(e) {
  4043. var _this = this;
  4044. var a, s, l;
  4045. if (!this.signalHandleActived) return;
  4046. var t = e.signal,
  4047. r = e.alreadyUpdateYUV;
  4048. if (this.handleActionResponses(t), this._room.handleSignalHook(t), !r) {
  4049. var u = (a = t.newUserStates) == null ? void 0 : a.find(function (c) {
  4050. return c.userId === _this._room.userId;
  4051. });
  4052. if ((u == null ? void 0 : u.renderInfo) && ((s = this._room._userAvatar) == null ? void 0 : s.isMoving)) {
  4053. logger.debug("stream stoped, make avatar to stop");
  4054. var _u$renderInfo = u.renderInfo,
  4055. c = _u$renderInfo.isMoving,
  4056. h = _u$renderInfo.isRotating;
  4057. this._room.avatarManager._updateAvatarMovingStatus({
  4058. id: u.userId,
  4059. isMoving: !!c,
  4060. isRotating: !!h
  4061. });
  4062. }
  4063. return;
  4064. }
  4065. this.isUpdatedYUV = r;
  4066. var n = t;
  4067. if (!t) {
  4068. logger.warn("metadata signal is empty");
  4069. return;
  4070. }
  4071. if (n.code === Codes.RepeatLogin) {
  4072. this._room.handleRepetLogin();
  4073. return;
  4074. }
  4075. 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));
  4076. var o = (l = n.newUserStates) == null ? void 0 : l.find(function (u) {
  4077. return u.userId === _this._room.userId;
  4078. });
  4079. if (n.broadcastAction) try {
  4080. var _u = JSON.parse(n.broadcastAction.data);
  4081. Broadcast.handlers.forEach(function (c) {
  4082. return c(_u);
  4083. });
  4084. } catch (u) {
  4085. logger.error(u);
  4086. }
  4087. if (n.newUserStates && n.newUserStates.length > 0 && this._room.avatarManager.handleAvatar(n), o != null && o.playerState) {
  4088. this._room._currentClickingState = o.playerState;
  4089. var _o$playerState = o.playerState,
  4090. _u2 = _o$playerState.pathName,
  4091. _c = _o$playerState.attitude,
  4092. _h = _o$playerState.areaName,
  4093. f = _o$playerState.skinId;
  4094. if (_u2 && (this._room.pathManager.currentPathName = _u2, this._room.updateCurrentState({
  4095. pathName: _u2
  4096. })), f && this.udpateSkinInfo(f), _h && this._room.updateCurrentState({
  4097. areaName: _h
  4098. }), _c) {
  4099. var d = this._room.skin.routeList.find(function (g) {
  4100. return g.areaName === _this._room.currentState.areaName;
  4101. }),
  4102. _ = ((d == null ? void 0 : d.step) || 7.5) * 30;
  4103. this._room.updateCurrentState({
  4104. speed: _,
  4105. attitude: _c
  4106. }), this._room.pathManager.currentAttitude = _c, this._room._userAvatar && (this._room._userAvatar.motionType = _c);
  4107. }
  4108. this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano && !this._room.isPano && o.playerState.camera && this._room.camera.setCameraPose(o.playerState.camera);
  4109. }
  4110. if (o != null && o.renderInfo && this._room.camera.handleRenderInfo(o), n.actionType !== void 0) {
  4111. var _u3 = n.actionType,
  4112. _c2 = n.code,
  4113. _h2 = n.echoMsg,
  4114. _f = n.traceId;
  4115. _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);
  4116. }
  4117. }
  4118. }, {
  4119. key: "handleActionResponses",
  4120. value: function handleActionResponses(e) {
  4121. var _this2 = this;
  4122. !(e != null && e.actionResponses) || e.actionResponses.length === 0 || e.actionResponses.forEach(function (t) {
  4123. if (t.actionType == null) return;
  4124. var r = t.pointType,
  4125. n = t.extra,
  4126. o = t.actionType,
  4127. a = t.traceId,
  4128. s = t.code,
  4129. l = t.msg;
  4130. 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));
  4131. });
  4132. }
  4133. }, {
  4134. key: "udpateSkinInfo",
  4135. value: function () {
  4136. var _udpateSkinInfo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  4137. var t;
  4138. return regenerator.wrap(function _callee$(_context) {
  4139. while (1) {
  4140. switch (_context.prev = _context.next) {
  4141. case 0:
  4142. this._room.updateCurrentState({
  4143. skinId: e
  4144. });
  4145. _context.next = 3;
  4146. return this._room.skinList.find(function (r) {
  4147. return r.id === e;
  4148. });
  4149. case 3:
  4150. t = _context.sent;
  4151. t && this._room.updateCurrentState({
  4152. skin: t
  4153. });
  4154. case 5:
  4155. case "end":
  4156. return _context.stop();
  4157. }
  4158. }
  4159. }, _callee, this);
  4160. }));
  4161. function udpateSkinInfo(_x) {
  4162. return _udpateSkinInfo.apply(this, arguments);
  4163. }
  4164. return udpateSkinInfo;
  4165. }()
  4166. }]);
  4167. return Signal;
  4168. }();
  4169. 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); }; }
  4170. 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; } }
  4171. var XverseEffectManager = /*#__PURE__*/function (_EventEmitter) {
  4172. _inherits(XverseEffectManager, _EventEmitter);
  4173. var _super = _createSuper$d(XverseEffectManager);
  4174. function XverseEffectManager(e) {
  4175. var _this;
  4176. _classCallCheck(this, XverseEffectManager);
  4177. _this = _super.call(this);
  4178. E(_assertThisInitialized(_this), "effects", new Map());
  4179. E(_assertThisInitialized(_this), "room");
  4180. _this.room = e;
  4181. return _this;
  4182. }
  4183. _createClass(XverseEffectManager, [{
  4184. key: "addEffect",
  4185. value: function () {
  4186. var _addEffect = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  4187. var o, t, r, _e$type, n, a;
  4188. return regenerator.wrap(function _callee$(_context) {
  4189. while (1) {
  4190. switch (_context.prev = _context.next) {
  4191. case 0:
  4192. t = e.jsonPath, r = e.id, _e$type = e.type, n = _e$type === void 0 ? IEffectType.SubSequence : _e$type;
  4193. _context.prev = 1;
  4194. this.effects.get(r) && ((o = this.effects.get(r)) == null || o.dispose());
  4195. a = new Ae.subEffect({
  4196. id: r,
  4197. jsonPath: t,
  4198. type: n,
  4199. room: this.room
  4200. });
  4201. this.effects.set(r, a);
  4202. _context.next = 7;
  4203. return a.init();
  4204. case 7:
  4205. return _context.abrupt("return", a);
  4206. case 10:
  4207. _context.prev = 10;
  4208. _context.t0 = _context["catch"](1);
  4209. return _context.abrupt("return", (this.effects.delete(r), logger.error(_context.t0), Promise.reject(_context.t0)));
  4210. case 13:
  4211. case "end":
  4212. return _context.stop();
  4213. }
  4214. }
  4215. }, _callee, this, [[1, 10]]);
  4216. }));
  4217. function addEffect(_x) {
  4218. return _addEffect.apply(this, arguments);
  4219. }
  4220. return addEffect;
  4221. }()
  4222. }, {
  4223. key: "clearEffects",
  4224. value: function clearEffects() {
  4225. var _this2 = this;
  4226. this.effects.forEach(function (e) {
  4227. e.dispose(), _this2.effects.delete(e.id);
  4228. });
  4229. }
  4230. }, {
  4231. key: "removeEffect",
  4232. value: function removeEffect(e) {
  4233. var t = this.effects.get(e);
  4234. t == null || t.dispose(), t && this.effects.delete(t.id);
  4235. }
  4236. }]);
  4237. return XverseEffectManager;
  4238. }(EventEmitter);
  4239. 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); }; }
  4240. 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; } }
  4241. var ParamError$1 = /*#__PURE__*/function (_XverseError) {
  4242. _inherits(ParamError, _XverseError);
  4243. var _super = _createSuper$c(ParamError);
  4244. function ParamError(e) {
  4245. _classCallCheck(this, ParamError);
  4246. return _super.call(this, 1001, e || "\u53C2\u6570\u9519\u8BEF");
  4247. }
  4248. return _createClass(ParamError);
  4249. }(XverseError);
  4250. var MotionType$1 = {
  4251. Walk: 'walk',
  4252. Run: 'run',
  4253. Fly: 'fly'
  4254. };
  4255. var Heartbeat = /*#__PURE__*/function () {
  4256. function Heartbeat(e) {
  4257. var _this = this;
  4258. _classCallCheck(this, Heartbeat);
  4259. E(this, "_interval", null);
  4260. E(this, "ping", function () {
  4261. var e = Date.now().toString();
  4262. _this.handler.ping(e);
  4263. });
  4264. this.handler = e;
  4265. }
  4266. _createClass(Heartbeat, [{
  4267. key: "ping",
  4268. value: function ping() {
  4269. var e = Date.now().toString();
  4270. this.handler.ping(e);
  4271. }
  4272. }, {
  4273. key: "start",
  4274. value: function start() {
  4275. this.stop(), logger.debug("Setting ping interval to ".concat(PING_INTERVAL_MS, "ms")), this._interval = window.setInterval(this.ping, PING_INTERVAL_MS);
  4276. }
  4277. }, {
  4278. key: "stop",
  4279. value: function stop() {
  4280. logger.debug("stop heartbeat"), this._interval && window.clearInterval(this._interval);
  4281. }
  4282. }, {
  4283. key: "pong",
  4284. value: function pong(e, t) {
  4285. !e || typeof e == "string" && this.handler.pong(Date.now() - Number(e), t);
  4286. }
  4287. }]);
  4288. return Heartbeat;
  4289. }();
  4290. var Timeout$1 = /*#__PURE__*/function () {
  4291. function Timeout(e, t) {
  4292. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !0;
  4293. _classCallCheck(this, Timeout);
  4294. this._timeout = null;
  4295. this._fn = e, this._delay = t, r && this.start();
  4296. }
  4297. _createClass(Timeout, [{
  4298. key: "delay",
  4299. get: function get() {
  4300. return this._delay;
  4301. }
  4302. }, {
  4303. key: "isSet",
  4304. get: function get() {
  4305. return !!this._timeout;
  4306. }
  4307. }, {
  4308. key: "setDelay",
  4309. value: function setDelay(e) {
  4310. this._delay = e;
  4311. }
  4312. }, {
  4313. key: "start",
  4314. value: function start() {
  4315. var _this = this;
  4316. this.isSet || (this._timeout = window.setTimeout(function () {
  4317. var e = _this._fn;
  4318. _this.clear(), e();
  4319. }, this._delay));
  4320. }
  4321. }, {
  4322. key: "clear",
  4323. value: function clear() {
  4324. window.clearTimeout(this._timeout), this._timeout = void 0;
  4325. }
  4326. }, {
  4327. key: "reset",
  4328. value: function reset() {
  4329. this.clear(), this.start();
  4330. }
  4331. }]);
  4332. return Timeout;
  4333. }();
  4334. 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); }; }
  4335. 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; } }
  4336. var InitNetworkTimeoutError = /*#__PURE__*/function (_XverseError) {
  4337. _inherits(InitNetworkTimeoutError, _XverseError);
  4338. var _super = _createSuper$b(InitNetworkTimeoutError);
  4339. function InitNetworkTimeoutError(e) {
  4340. _classCallCheck(this, InitNetworkTimeoutError);
  4341. return _super.call(this, 1007, e || "\u7F51\u7EDC\u521D\u59CB\u5316\u8D85\u65F6");
  4342. }
  4343. return _createClass(InitNetworkTimeoutError);
  4344. }(XverseError);
  4345. 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); }; }
  4346. 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; } }
  4347. var Socket = /*#__PURE__*/function (_EventEmitter) {
  4348. _inherits(Socket, _EventEmitter);
  4349. var _super = _createSuper$a(Socket);
  4350. function Socket(e) {
  4351. var _this;
  4352. _classCallCheck(this, Socket);
  4353. _this = _super.call(this);
  4354. E(_assertThisInitialized(_this), "_ws");
  4355. E(_assertThisInitialized(_this), "_openTimer");
  4356. E(_assertThisInitialized(_this), "connected", !1);
  4357. E(_assertThisInitialized(_this), "_hasTimeout", !1);
  4358. E(_assertThisInitialized(_this), "heartbeat");
  4359. E(_assertThisInitialized(_this), "latency", function (e, t) {
  4360. return _this.send({
  4361. id: "checkLatency",
  4362. data: JSON.stringify(e),
  4363. packet_id: t
  4364. });
  4365. });
  4366. E(_assertThisInitialized(_this), "send", function (e) {
  4367. if (_this.wsNoReady()) return;
  4368. var t = JSON.stringify(e);
  4369. e.id !== "heartbeat" && logger.info("send ws frame", t), _this._ws.send(t);
  4370. });
  4371. E(_assertThisInitialized(_this), "startGame", function () {
  4372. var _this$network$room$cu = _this.network.room.currentNetworkOptions,
  4373. e = _this$network$room$cu.roomId,
  4374. t = _this$network$room$cu.userId,
  4375. r = _this$network$room$cu.avatarId,
  4376. n = _this$network$room$cu.skinId,
  4377. o = _this$network$room$cu.role,
  4378. a = _this$network$room$cu.avatarComponents,
  4379. s = _this$network$room$cu.versionId,
  4380. l = _this$network$room$cu.rotationRenderType,
  4381. u = _this$network$room$cu.isAllSync,
  4382. c = _this$network$room$cu.nickname,
  4383. h = _this$network$room$cu.avatarScale,
  4384. f = _this$network$room$cu.appId,
  4385. d = _this$network$room$cu.camera,
  4386. _ = _this$network$room$cu.player,
  4387. g = _this$network$room$cu.firends,
  4388. m = _this$network$room$cu.syncByEvent,
  4389. v = _this$network$room$cu.areaName,
  4390. y = _this$network$room$cu.attitude,
  4391. b = _this$network$room$cu.pathName,
  4392. T = _this$network$room$cu.person,
  4393. _this$network$room$cu2 = _this$network$room$cu.roomTypeId,
  4394. C = _this$network$room$cu2 === void 0 ? "" : _this$network$room$cu2,
  4395. A = _this$network$room$cu.syncToOthers,
  4396. S = _this$network$room$cu.hasAvatar,
  4397. P = _this$network$room$cu.prioritySync,
  4398. _this$network$room$cu3 = _this$network$room$cu.extra,
  4399. R = _this$network$room$cu3 === void 0 ? {} : _this$network$room$cu3,
  4400. M = _this$network$room$cu.removeWhenDisconnected;
  4401. R.removeWhenDisconnected = M;
  4402. var x = {
  4403. id: "start",
  4404. room_id: e,
  4405. user_id: t,
  4406. trace_id: util.uuid(),
  4407. data: JSON.stringify({
  4408. avatar_components: JSON.stringify(a),
  4409. avatar_id: r,
  4410. skin_id: n,
  4411. is_host: o ? o == "host" : !0,
  4412. skin_data_version: n !== void 0 && s !== void 0 ? n + s : void 0,
  4413. rotation_render_type: l,
  4414. is_all_sync: u,
  4415. nick_name: encodeURIComponent(c || ""),
  4416. app_id: f,
  4417. camera: d,
  4418. player: _,
  4419. person: T,
  4420. firends: JSON.stringify(g),
  4421. sync_by_event: m,
  4422. area_name: v,
  4423. path_name: b,
  4424. attitude: y,
  4425. room_type_id: C,
  4426. syncToOthers: A,
  4427. hasAvatar: S,
  4428. avatarSize: h,
  4429. prioritySync: P,
  4430. extra: JSON.stringify(R)
  4431. })
  4432. };
  4433. _this.send(x), logger.warn("startGame", le(oe({}, x), {
  4434. data: JSON.parse(x.data)
  4435. }));
  4436. });
  4437. _this.network = e, _this.heartbeat = new Heartbeat({
  4438. ping: function ping(t) {
  4439. var r;
  4440. if (!_this.connected) {
  4441. _this.heartbeat.stop(), (r = e.room.stats) == null || r.assign({
  4442. rtt: 0
  4443. });
  4444. return;
  4445. }
  4446. _this.send({
  4447. id: "heartbeat",
  4448. data: t
  4449. });
  4450. },
  4451. pong(t) {
  4452. var r;
  4453. (r = e.room.stats) == null || r.assign({
  4454. rtt: t
  4455. });
  4456. }
  4457. });
  4458. return _this;
  4459. }
  4460. _createClass(Socket, [{
  4461. key: "connection",
  4462. get: function get() {
  4463. return this._ws;
  4464. }
  4465. }, {
  4466. key: "start",
  4467. value: function start() {
  4468. var _this2 = this;
  4469. this._hasTimeout = !1;
  4470. var e = this.getAddress();
  4471. logger.info("connecting to ".concat(e));
  4472. var t = Date.now();
  4473. this._ws = new WebSocket(e), this._openTimer = new Timeout$1(function () {
  4474. var r = "Failed to open websocket in ".concat(DEFAULT_OPEN_TIMEOUT_MS, " ms");
  4475. _this2._hasTimeout = !0, _this2.emit("socketClosed", new InitNetworkTimeoutError(r));
  4476. }, DEFAULT_OPEN_TIMEOUT_MS), this._ws.onopen = function () {
  4477. var r;
  4478. (r = _this2._openTimer) == null || r.clear(), _this2.connected = !0, _this2.heartbeat.start(), _this2.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
  4479. metric: "wsOpenedAt",
  4480. group: "joinRoom",
  4481. startTime: _this2.network.room._startTime
  4482. }), logger.infoAndReportMeasurement({
  4483. metric: "wsOpenedCost",
  4484. group: "joinRoom",
  4485. startTime: t
  4486. }));
  4487. }, this.handleWSEvent();
  4488. }
  4489. }, {
  4490. key: "getAddress",
  4491. value: function getAddress() {
  4492. var _this$network$room$cu4 = this.network.room.currentNetworkOptions,
  4493. e = _this$network$room$cu4.wsServerUrl,
  4494. t = _this$network$room$cu4.reconnect,
  4495. r = _this$network$room$cu4.sessionId,
  4496. n = _this$network$room$cu4.token,
  4497. o = _this$network$room$cu4.roomId,
  4498. a = _this$network$room$cu4.userId,
  4499. s = _this$network$room$cu4.pageSession,
  4500. l = this.network.room.skinId;
  4501. var u = e;
  4502. t && (u = u + "?reconnect=true&lastSessionID=".concat(r));
  4503. var c = "userId=".concat(a, "&roomId=").concat(o, "&pageSession=").concat(s) + (this.network.room.isHost ? "&skinId=".concat(l) : "") + (n ? "&token=".concat(n) : "");
  4504. return u = u.indexOf("?") > -1 ? u + "&" + c : u + "?" + c, u;
  4505. }
  4506. }, {
  4507. key: "handleWSEvent",
  4508. value: function handleWSEvent() {
  4509. var _this3 = this;
  4510. var e = this._ws;
  4511. e.addEventListener("error", function (t) {
  4512. _this3.connected = !1, logger.error("webscoket error", t), _this3.emit("socketClosed", new InternalError("connect to address error: " + _this3.network.room.currentNetworkOptions.wsServerUrl));
  4513. }), e.addEventListener("close", function (t) {
  4514. _this3.connected = !1, _this3._onClose(t);
  4515. }), e.addEventListener("message", function (t) {
  4516. if (!t || _this3._hasTimeout || !_this3.connected) return;
  4517. var r = null;
  4518. try {
  4519. r = JSON.parse(t.data);
  4520. } catch (o) {
  4521. logger.error(o);
  4522. return;
  4523. }
  4524. if (!r) return;
  4525. var n = r.id;
  4526. if (!!n) switch (n !== "heartbeat" && logger.info("receive ws frame: ".concat(t.data)), n) {
  4527. case "fail":
  4528. break;
  4529. case "init":
  4530. try {
  4531. var o = r.data.slice(-37, -1);
  4532. reporter$1.updateBody({
  4533. serverSession: o
  4534. });
  4535. } catch (o) {
  4536. console.error(o);
  4537. }
  4538. _this3.network.rtcp.start();
  4539. break;
  4540. case "heartbeat":
  4541. _this3.heartbeat.pong(r.data);
  4542. break;
  4543. case "offer":
  4544. _this3.network.rtcp.setRemoteDescription(r.data, _this3.network.stream.el);
  4545. break;
  4546. case "ice_candidate":
  4547. _this3.network.rtcp.addCandidate(r.data);
  4548. break;
  4549. case "start":
  4550. _this3.emit("gameRoomAvailable", r);
  4551. break;
  4552. case "error":
  4553. try {
  4554. var _JSON$parse = JSON.parse(r.data),
  4555. _o = _JSON$parse.Code,
  4556. a = _JSON$parse.Msg;
  4557. if (_o) {
  4558. if (_o == 3003) return _this3.emit("socketClosed", new TokenExpiredError());
  4559. if (authenticationErrorCodes.indexOf(_o) > -1) return _this3.emit("socketClosed", new AuthenticationError("\u9274\u6743\u9519\u8BEF:" + a));
  4560. {
  4561. var s = getErrorByCode(_o);
  4562. _this3.emit("socketClosed", new s(a));
  4563. }
  4564. }
  4565. } catch (o) {
  4566. logger.error(o), _this3.emit("socketClosed", new InternalError(r.data));
  4567. }
  4568. break;
  4569. case "checkLatency":
  4570. {
  4571. var _o2 = r.packet_id,
  4572. _a = r.data.split(",");
  4573. _this3.onLatencyCheck({
  4574. packetId: _o2,
  4575. addresses: _a
  4576. });
  4577. break;
  4578. }
  4579. default:
  4580. logger.warn("unkown ws message type", n, r);
  4581. }
  4582. });
  4583. }
  4584. }, {
  4585. key: "onLatencyCheck",
  4586. value: function onLatencyCheck(e) {
  4587. var _this4 = this;
  4588. var t = _toConsumableArray(new Set(e.addresses || []));
  4589. Promise.all(t.map(function (r) {
  4590. return {
  4591. [r]: 9999
  4592. };
  4593. })).then(function (r) {
  4594. var n = Object.assign.apply(Object, [{}].concat(_toConsumableArray(r)));
  4595. _this4.latency(n, e.packetId);
  4596. });
  4597. }
  4598. }, {
  4599. key: "wsNoReady",
  4600. value: function wsNoReady() {
  4601. return this._ws.readyState == WebSocket.CLOSED || this._ws.readyState == WebSocket.CLOSING || this._ws.readyState == WebSocket.CONNECTING;
  4602. }
  4603. }, {
  4604. key: "prepareReconnect",
  4605. value: function prepareReconnect() {
  4606. this._close({
  4607. code: WS_CLOSE_RECONNECT,
  4608. reason: "reconnect"
  4609. });
  4610. }
  4611. }, {
  4612. key: "_onClose",
  4613. value: function _onClose(_ref) {
  4614. var e = _ref.code,
  4615. t = _ref.reason;
  4616. 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"));
  4617. }
  4618. }, {
  4619. key: "_close",
  4620. value: function _close(_ref2) {
  4621. var e = _ref2.code,
  4622. t = _ref2.reason;
  4623. var r;
  4624. (r = this._ws) == null || r.close(e, t);
  4625. }
  4626. }, {
  4627. key: "quit",
  4628. value: function quit() {
  4629. this._close({
  4630. code: WS_CLOSE_NORMAL,
  4631. reason: "quit"
  4632. });
  4633. }
  4634. }]);
  4635. return Socket;
  4636. }(EventEmitter);
  4637. function add(i, e) {
  4638. return e == -1 && (e = 0), i + e;
  4639. }
  4640. function max(i, e) {
  4641. return Math.max(i, e);
  4642. }
  4643. function count_sd(i, e) {
  4644. function t(r, n) {
  4645. var o = 0;
  4646. return n == -1 ? o = 0 : o = (n - e) * (n - e), r + o;
  4647. }
  4648. return Math.sqrt(i.reduce(t, 0) / i.reduce(count_valid, 0)) || 0;
  4649. }
  4650. function count_valid(i, e) {
  4651. var t = 0;
  4652. return e != -1 && (t = 1), i + t;
  4653. }
  4654. function count_less(i, e) {
  4655. function t(r, n) {
  4656. var o = 0;
  4657. return n != -1 && n < e && (o = 1), r + o;
  4658. }
  4659. return i.reduce(t, 0);
  4660. }
  4661. var CircularArray = /*#__PURE__*/function () {
  4662. function CircularArray(e, t, r) {
  4663. _classCallCheck(this, CircularArray);
  4664. 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);
  4665. }
  4666. _createClass(CircularArray, [{
  4667. key: "add",
  4668. value: function add(e) {
  4669. 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);
  4670. }
  4671. }, {
  4672. key: "computeAvg",
  4673. value: function computeAvg(e) {
  4674. return e.reduce(add, 0) / e.reduce(count_valid, 0) || 0;
  4675. }
  4676. }, {
  4677. key: "computeMax",
  4678. value: function computeMax(e) {
  4679. return e.reduce(max, 0) || 0;
  4680. }
  4681. }, {
  4682. key: "computeThreshPercent",
  4683. value: function computeThreshPercent(e) {
  4684. if (this.countLess) {
  4685. var t = count_less(e, this.lessThreshes[0]) || 0,
  4686. r = count_less(e, this.lessThreshes[1]) || 0,
  4687. n = count_less(e, this.lessThreshes[2]) || 0,
  4688. o = count_less(e, this.lessThreshes[3]) || 0,
  4689. a = e.reduce(count_valid, 0);
  4690. return [t, r, n, o, a];
  4691. } else return [0, 0, 0, 0, 0];
  4692. }
  4693. }, {
  4694. key: "getAvg",
  4695. value: function getAvg() {
  4696. var e = this.sum / this.count || 0,
  4697. t = this.computeAvg(this.circularData) || 0;
  4698. return Math.abs(e - t) > .01 && console.error("avg value mismatch: ", e, t), this.computeAvg(this.circularData) || 0;
  4699. }
  4700. }, {
  4701. key: "getMax",
  4702. value: function getMax() {
  4703. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  4704. var t = this.computeMax(this.circularData) || 0;
  4705. return e && Math.abs(t - this.max) > .01 && console.error("max value mismatch: ", this.max, t), this.computeMax(this.circularData) || 0;
  4706. }
  4707. }, {
  4708. key: "getStandardDeviation",
  4709. value: function getStandardDeviation() {
  4710. return count_sd(this.circularData, this.getAvg());
  4711. }
  4712. }, {
  4713. key: "getThreshPercent",
  4714. value: function getThreshPercent() {
  4715. return this.computeThreshPercent(this.circularData);
  4716. }
  4717. }, {
  4718. key: "getIncomingMax",
  4719. value: function getIncomingMax() {
  4720. return this.computeMax(this.incomingData) || 0;
  4721. }
  4722. }, {
  4723. key: "getIncomingAvg",
  4724. value: function getIncomingAvg() {
  4725. return this.computeAvg(this.incomingData) || 0;
  4726. }
  4727. }, {
  4728. key: "getIncomingStandardDeviation",
  4729. value: function getIncomingStandardDeviation() {
  4730. return count_sd(this.incomingData, this.getIncomingAvg());
  4731. }
  4732. }, {
  4733. key: "getIncomingThreshPercent",
  4734. value: function getIncomingThreshPercent() {
  4735. return this.computeThreshPercent(this.incomingData);
  4736. }
  4737. }, {
  4738. key: "clearFastComputeItem",
  4739. value: function clearFastComputeItem() {
  4740. 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;
  4741. }
  4742. }, {
  4743. key: "clearIncoming",
  4744. value: function clearIncoming() {
  4745. for (; this.incomingData.length > 0;) {
  4746. this.incomingData.pop();
  4747. }
  4748. }
  4749. }, {
  4750. key: "clear",
  4751. value: function clear() {
  4752. this.circularData.fill(-1), this.circularPtr = 0, this.clearFastComputeItem(), this.clearIncoming();
  4753. }
  4754. }]);
  4755. return CircularArray;
  4756. }();
  4757. function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(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; } } }; }
  4758. function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(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$1(o, minLen); }
  4759. function _arrayLikeToArray$1(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; }
  4760. var defaultLogger = {
  4761. info: console.log,
  4762. debug: console.log,
  4763. error: console.error,
  4764. infoAndReportMeasurement: function infoAndReportMeasurement() {}
  4765. };
  4766. var FRAME_COMPOSE_LENGTH = 5;
  4767. var Workers = /*#__PURE__*/function () {
  4768. function Workers(e, t) {
  4769. var _this = this;
  4770. _classCallCheck(this, Workers);
  4771. 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(120, !1, []), this.inPanoMode = !1, this.PanoStatus = {
  4772. x: 0,
  4773. y: 0,
  4774. z: 0,
  4775. tiles: []
  4776. }, 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(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(120, !0, [STUCK_STAGE_GOOD, STUCK_STAGE_WELL, STUCK_STAGE_FAIR, STUCK_STAGE_BAD]), this.moveProcessCircular = new CircularArray(120, !0, [STUCK_STAGE_GOOD, STUCK_STAGE_WELL, STUCK_STAGE_FAIR, STUCK_STAGE_BAD]), this.moveDisplayCircular = new CircularArray(120, !0, [STUCK_STAGE_GOOD, STUCK_STAGE_WELL, STUCK_STAGE_FAIR, STUCK_STAGE_BAD]), this.moveStartPts = -1, this.frameServerCircular = new CircularArray(120, !1, []), this.srvMetaIntervalCircular = new CircularArray(120, !1, []), this.srvMediaIntervalCircular = new CircularArray(120, !1, []), this.srvHBMetaIntervalCircular = new CircularArray(120, !1, []), this.srvHBMetaIntervalSrvSentCircular = new CircularArray(120, !1, []), this.frameClientCircular = new CircularArray(120, !1, []), this.firstUpdateYUV = !0, this.functionMap = new Map(), this.WASM_VERSION = "WASM-1.1", this.frameHistory = [], this.getVersion = function () {
  4777. return DECODER_VERSION;
  4778. }, this.downloadBlob = function (r, n, o) {
  4779. var a = new Blob([r], {
  4780. type: o
  4781. }),
  4782. s = window.URL.createObjectURL(a);
  4783. _this.downloadURL(s, n), setTimeout(function () {
  4784. return window.URL.revokeObjectURL(s);
  4785. }, 1e3);
  4786. }, this.downloadURL = function (r, n) {
  4787. var o = document.createElement("a");
  4788. o.href = r, o.download = n, document.body.appendChild(o), o.style.display = "none", o.click(), o.remove();
  4789. }, this.Stringify = function (r) {
  4790. var n = "";
  4791. for (var a = 0; a < r.length / 8192; a++) {
  4792. n += String.fromCharCode.apply(null, r.slice(a * 8192, (a + 1) * 8192));
  4793. }
  4794. return n;
  4795. }, this._rtcp = e;
  4796. }
  4797. _createClass(Workers, [{
  4798. key: "registerLogger",
  4799. value: function registerLogger(e) {//defaultLogger = e
  4800. }
  4801. }, {
  4802. key: "registerFunction",
  4803. value: function registerFunction(e, t) {
  4804. this.functionMap.set(e, t);
  4805. }
  4806. }, {
  4807. key: "hasFrmCntInCache",
  4808. value: function hasFrmCntInCache(e) {
  4809. var t = -1;
  4810. for (var r = 0; r < this.cacheFrameComposes.length; r++) {
  4811. this.cacheFrameComposes[r].frameCnt == e && (t = r);
  4812. }
  4813. return t;
  4814. }
  4815. }, {
  4816. key: "requestPanoramaTest",
  4817. value: function requestPanoramaTest(e, t, r, n, o) {
  4818. var a = o,
  4819. s = {
  4820. action_type: 16,
  4821. change_rotation_render_type_action: {
  4822. render_type: 5,
  4823. player: {
  4824. position: {
  4825. x: 0,
  4826. y: 0,
  4827. z: 0
  4828. },
  4829. angle: {
  4830. yaw: 0,
  4831. pitch: 0,
  4832. roll: 0
  4833. }
  4834. },
  4835. camera: {
  4836. position: {
  4837. x: e,
  4838. y: t,
  4839. z: r
  4840. },
  4841. angle: {
  4842. yaw: 0,
  4843. pitch: 0,
  4844. roll: 0
  4845. }
  4846. },
  4847. client_pano_titles_bitmap: n
  4848. },
  4849. trace_id: a,
  4850. user_id: this.userId_test,
  4851. packet_id: a
  4852. };
  4853. defaultLogger.debug("send data: ", s), this._rtcp.sendData(s);
  4854. }
  4855. }, {
  4856. key: "onRotateInPanoMode",
  4857. value: function onRotateInPanoMode(e) {
  4858. var t = e.traceId,
  4859. r = {};
  4860. r.width = 1280, r.height = 720, r.horz_fov = 92, r.angle = {
  4861. yaw: 100,
  4862. pitch: 30
  4863. };
  4864. var n = new ArrayBuffer(8),
  4865. o = new DataView(n);
  4866. getTilesInView(r, n);
  4867. var a = n.slice(0);
  4868. this.PendingMasks.unshift({
  4869. buffer: a,
  4870. angle: r.angle
  4871. }), MaskSetToOne(18, this.PanoView), operateForDataView(o, this.PanoView, o, function (s, l) {
  4872. return s ^ s & l;
  4873. }), 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);
  4874. }
  4875. }, {
  4876. key: "processMetaWithTraceId",
  4877. value: function processMetaWithTraceId(e) {
  4878. var _iterator = _createForOfIteratorHelper$1(e.traceIds),
  4879. _step;
  4880. try {
  4881. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  4882. var t = _step.value;
  4883. if (this.traceIdMap.has(t)) {
  4884. var r = this.traceIdMap.get(t);
  4885. r != null && (r.receiveTime = Date.now(), r.status = 1);
  4886. }
  4887. if (t == this.PendingMovingTraceId) {
  4888. 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());
  4889. var _r = Date.now();
  4890. this.lastMoveResponseTime = _r, this.lastMoveProcessTime = _r, this.lastMoveDisplayTime = _r, this.frameServerCircular.clear(), this.frameClientCircular.clear();
  4891. }
  4892. }
  4893. } catch (err) {
  4894. _iterator.e(err);
  4895. } finally {
  4896. _iterator.f();
  4897. }
  4898. }
  4899. }, {
  4900. key: "onTraceId",
  4901. value: function onTraceId(e) {
  4902. var _this2 = this;
  4903. var r = e.traceId,
  4904. n = e.timestamp,
  4905. o = e.event;
  4906. if (o === "Rotation") {
  4907. var a = {
  4908. traceId: r,
  4909. pts: 0,
  4910. startTime: n,
  4911. receiveTime: 0,
  4912. readyTime: 0,
  4913. displayTime: 0,
  4914. status: 0
  4915. };
  4916. this.traceIdMap.set(r, a);
  4917. var s = setTimeout(function () {
  4918. if (s && clearTimeout(s), _this2.traceIdMap.has(r)) {
  4919. var l = _this2.traceIdMap.get(r);
  4920. switch (l == null ? void 0 : l.status) {
  4921. case 0:
  4922. {
  4923. _this2.responseMiss += 1;
  4924. break;
  4925. }
  4926. case 1:
  4927. {
  4928. _this2.processMiss += 1;
  4929. var u = l.receiveTime - l.startTime;
  4930. _this2.responseTimeArray.push(u);
  4931. break;
  4932. }
  4933. case 2:
  4934. {
  4935. _this2.displayMiss += 1;
  4936. var _u = l.receiveTime - l.startTime,
  4937. c = l.readyTime - l.receiveTime;
  4938. _this2.responseTimeArray.push(_u), _this2.processTimeArray.push(c);
  4939. break;
  4940. }
  4941. case 3:
  4942. defaultLogger.debug("status is 3");
  4943. }
  4944. }
  4945. }, 1e3);
  4946. } 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();
  4947. }
  4948. }, {
  4949. key: "executeFunction",
  4950. value: function executeFunction(e, t) {
  4951. if (this.functionMap.has(e)) {
  4952. var r = this.functionMap.get(e);
  4953. r != null && r(t);
  4954. }
  4955. }
  4956. }, {
  4957. key: "UpdateStats",
  4958. value: function UpdateStats(e) {
  4959. var _this3 = this;
  4960. var t;
  4961. (t = this._rtcp.connection) == null || t.getStats(null).then(function (r) {
  4962. r.forEach(function (n) {
  4963. n.type == "data-channel" && (_this3.rtcMessageReceived = n.messagesReceived - n.messagesSent, _this3.rtcBytesReceived = n.bytesReceived);
  4964. });
  4965. }), 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;
  4966. }
  4967. }, {
  4968. key: "ReceiveDecodeMessage",
  4969. value: function ReceiveDecodeMessage(e) {
  4970. var n;
  4971. if (!this.firstYUVReceived) {
  4972. this.firstYUVDecoded = e.data.yuv_ts;
  4973. var o = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  4974. defaultLogger.infoAndReportMeasurement({
  4975. metric: "firstYUVDecodedAt",
  4976. value: o,
  4977. group: "joinRoom"
  4978. }), this.firstRender = Date.now();
  4979. var a = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  4980. defaultLogger.infoAndReportMeasurement({
  4981. metric: "firstRenderAt",
  4982. value: a,
  4983. group: "joinRoom"
  4984. }), this.firstYUVReceived = !0, this.lastRenderTs = Date.now();
  4985. }
  4986. !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", {
  4987. stream: this.cachedStreams[this.setPtr],
  4988. width: this.cachedResolution[this.setPtr].width,
  4989. height: this.cachedResolution[this.setPtr].height,
  4990. pts: this.cachedPtss[this.setPtr]
  4991. }), this.executeFunction("signal", {
  4992. signal: this.cachedMetas[this.setPtr],
  4993. pts: this.cachedPtss[this.setPtr],
  4994. alreadyUpdateYUV: !0
  4995. })) : this.updateDropFrame += 1, this.decoderWorker.postMessage({
  4996. t: 2,
  4997. frameCnt: this.cachedPtss[this.setPtr],
  4998. buffer: this.cachedStreams[this.setPtr]
  4999. }, [this.cachedStreams[this.setPtr].buffer])), this.getPtr = (this.getPtr + 1) % this.cachedLength);
  5000. var t = e.data.metadata;
  5001. if ((n = t == null ? void 0 : t.traceIds) != null && n.length) {
  5002. var _iterator2 = _createForOfIteratorHelper$1(t.traceIds),
  5003. _step2;
  5004. try {
  5005. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  5006. var _o = _step2.value;
  5007. if (this.traceIdMap.has(_o)) {
  5008. var _a = this.traceIdMap.get(_o);
  5009. _a != null && (_a.readyTime = Date.now(), _a.status = 2);
  5010. }
  5011. }
  5012. } catch (err) {
  5013. _iterator2.e(err);
  5014. } finally {
  5015. _iterator2.f();
  5016. }
  5017. }
  5018. if (e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs), this.userId_test = this.rtcp.network.room.userId, this.inMovingMode) {
  5019. var _o2 = Date.now(),
  5020. _a2 = _o2 - this.lastMoveProcessTime;
  5021. this.moveProcessCircular.add(_a2), this.lastMoveProcessTime = _o2;
  5022. }
  5023. var r = this.setPtr;
  5024. 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] = {
  5025. width: e.data.width,
  5026. height: e.data.height
  5027. }, this.setPtr = (this.setPtr + 1) % this.cachedLength;
  5028. }
  5029. }, {
  5030. key: "SendCacheFrameInfo",
  5031. value: function SendCacheFrameInfo(e) {
  5032. var _this4 = this;
  5033. var h, f, d, _, g, m, v;
  5034. var t = e.data.cachedKey,
  5035. r = e.data.metadata,
  5036. n = t,
  5037. o = r,
  5038. a = (d = (f = (h = o.newUserStates) == null ? void 0 : h.find(function (y) {
  5039. return y.userId === _this4.rtcp.network.room.userId;
  5040. })) == null ? void 0 : f.playerState) == null ? void 0 : d.roomTypeId,
  5041. s = this.rtcp.network.room.skinId,
  5042. l = (v = (m = (g = (_ = o.newUserStates) == null ? void 0 : _.find(function (y) {
  5043. return y.userId === _this4._rtcp.network.room.userId;
  5044. })) == null ? void 0 : g.playerState) == null ? void 0 : m.player) == null ? void 0 : v.position,
  5045. u = {
  5046. MsgType: 1,
  5047. FrameCacheMsg: {
  5048. FrameIndex: n,
  5049. RoomTypeId: a,
  5050. SkinID: s,
  5051. Position: l
  5052. }
  5053. };
  5054. var c = "";
  5055. try {
  5056. c = JSON.stringify(u);
  5057. } catch (y) {
  5058. defaultLogger.error(y);
  5059. return;
  5060. }
  5061. }
  5062. }, {
  5063. key: "ReceivePanoramaDecodeMessage",
  5064. value: function ReceivePanoramaDecodeMessage(e) {
  5065. defaultLogger.info("Receive Panorama Image in Workers.ts"), MaskSetToOne(e.data.tileId, this.PanoView);
  5066. var t = 0,
  5067. r;
  5068. var n = this.PendingMasks.length;
  5069. for (t = 0; t < n; t++) {
  5070. var o = this.PendingMasks[t].buffer,
  5071. a = new DataView(o),
  5072. s = new ArrayBuffer(8),
  5073. l = new DataView(s);
  5074. if (operateForDataView(this.PanoView, a, l, function (u, c) {
  5075. return c ^ u & c;
  5076. }), IsAll0(l)) {
  5077. r = this.PendingMasks[t].angle;
  5078. break;
  5079. }
  5080. }
  5081. for (var _o3 = t; _o3 < n; _o3++) {
  5082. this.PendingMasks.pop();
  5083. }
  5084. this.executeFunction("panorama", {
  5085. data: e.data.data,
  5086. tileId: e.data.tileId,
  5087. pos: {
  5088. x: e.data.x,
  5089. y: e.data.y,
  5090. z: e.data.z
  5091. },
  5092. uuid: e.data.uuid,
  5093. finished: !0,
  5094. matchAngle: r
  5095. });
  5096. }
  5097. }, {
  5098. key: "enable_decoder_queue_logging",
  5099. value: function enable_decoder_queue_logging() {
  5100. this.decoderWorker.postMessage({
  5101. t: 100,
  5102. status: !0
  5103. });
  5104. }
  5105. }, {
  5106. key: "disable_decoder_queue_logging",
  5107. value: function disable_decoder_queue_logging() {
  5108. this.decoderWorker.postMessage({
  5109. t: 100,
  5110. status: !1
  5111. });
  5112. }
  5113. }, {
  5114. key: "init",
  5115. value: function () {
  5116. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  5117. var r,
  5118. n,
  5119. t;
  5120. return regenerator.wrap(function _callee$(_context) {
  5121. while (1) {
  5122. switch (_context.prev = _context.next) {
  5123. case 0:
  5124. for (r = 0; r < FRAME_COMPOSE_LENGTH; r++) {
  5125. n = {
  5126. buffer: new Uint8Array(2621440),
  5127. size: 0,
  5128. startReceiveTime: 0,
  5129. serverTime: 0,
  5130. frameCnt: -1
  5131. };
  5132. this.cacheFrameComposes.push(n);
  5133. }
  5134. t = new Blob([decoder], {
  5135. type: "application/javascript"
  5136. });
  5137. return _context.abrupt("return", (this.decoderWorker = new Worker(URL.createObjectURL(t)), this.decoderWorker.postMessage({
  5138. t: 9,
  5139. url: WASM_URLS[WASM_Version],
  5140. jitterLength: DECODER_PASSIVE_JITTER
  5141. })));
  5142. case 5:
  5143. case "end":
  5144. return _context.stop();
  5145. }
  5146. }
  5147. }, _callee, this);
  5148. }));
  5149. function init() {
  5150. return _init.apply(this, arguments);
  5151. }
  5152. return init;
  5153. }()
  5154. }, {
  5155. key: "UpdateYUV",
  5156. value: function UpdateYUV() {
  5157. var t, r;
  5158. var e = this.getPtr;
  5159. if (this.cachedMetas[e] != null && !this.cachedRender[e]) {
  5160. var n = Date.now();
  5161. if (this.firstUpdateYUV) {
  5162. var h = ((t = this.cachedStreams[e]) == null ? void 0 : t.byteLength) || 0;
  5163. defaultLogger.infoAndReportMeasurement({
  5164. metric: "firstUpdateStreamLength",
  5165. value: h,
  5166. group: "joinRoom"
  5167. }), this.firstUpdateYUV = !1;
  5168. }
  5169. this.cachedStreams[e] != null && this.executeFunction("stream", {
  5170. stream: this.cachedStreams[e],
  5171. width: this.cachedResolution[e].width,
  5172. height: this.cachedResolution[e].height,
  5173. pts: this.cachedPtss[e]
  5174. });
  5175. var o = Date.now();
  5176. this.cachedStreams[e] != null && this.decoderWorker.postMessage({
  5177. t: 2,
  5178. frameCnt: this.cachedPtss[e],
  5179. buffer: this.cachedStreams[e]
  5180. }, [this.cachedStreams[e].buffer]);
  5181. var a = Date.now(),
  5182. s = o - n,
  5183. l = a - o;
  5184. (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;
  5185. var u = o - n;
  5186. this.updateYUVCircular.add(u);
  5187. var c = this.cachedMetas[e];
  5188. if ((r = c == null ? void 0 : c.traceIds) != null && r.length) {
  5189. var _iterator3 = _createForOfIteratorHelper$1(c.traceIds),
  5190. _step3;
  5191. try {
  5192. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  5193. var _h = _step3.value;
  5194. if (this.traceIdMap.has(_h)) {
  5195. var f = this.traceIdMap.get(_h);
  5196. if (f != null) {
  5197. f.displayTime = Date.now(), f.status = 3;
  5198. var d = f.receiveTime - f.startTime,
  5199. _ = f.readyTime - f.receiveTime,
  5200. g = f.displayTime - f.readyTime,
  5201. m = f.displayTime - f.startTime;
  5202. this.responseTimeArray.push(d), this.processTimeArray.push(_), this.displayTimeArray.push(g), this.overallTimeArray.push(m), this.traceIdMap.delete(_h);
  5203. }
  5204. }
  5205. }
  5206. } catch (err) {
  5207. _iterator3.e(err);
  5208. } finally {
  5209. _iterator3.f();
  5210. }
  5211. }
  5212. if (this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs), this.inMovingMode) {
  5213. var _h2 = Date.now(),
  5214. _f = _h2 - this.lastMoveDisplayTime;
  5215. this.moveDisplayCircular.add(_f), this.lastMoveDisplayTime = _h2;
  5216. }
  5217. this.executeFunction("signal", {
  5218. signal: this.cachedMetas[e],
  5219. pts: this.cachedPtss[e],
  5220. alreadyUpdateYUV: !0
  5221. }), this.cachedRender[e] = !0, this.getPtr = (this.getPtr + 1) % this.cachedLength;
  5222. }
  5223. }
  5224. }, {
  5225. key: "unmarshalPano",
  5226. value: function unmarshalPano(e) {
  5227. var t = new DataView(e);
  5228. if (t.getUint32(0) != 1723558763) return !1;
  5229. console.log("Receive Pano Message"), t.getUint16(4);
  5230. var n = t.getUint16(6),
  5231. o = t.getUint32(8),
  5232. a = t.getUint32(12) - (1 << 30) * 2,
  5233. s = t.getUint32(16) - (1 << 30) * 2,
  5234. l = t.getUint32(20) - (1 << 30) * 2,
  5235. u = t.getUint32(24),
  5236. c = new Uint8Array(e).subarray(28, 64),
  5237. h = String.fromCharCode.apply(null, c),
  5238. f = t.getUint32(64),
  5239. d = e.byteLength - n;
  5240. if (d == u) {
  5241. var g = {
  5242. data: new Uint8Array(e).subarray(n),
  5243. mediaLen: u,
  5244. tileId: o,
  5245. uuid: h,
  5246. x: a,
  5247. y: s,
  5248. z: l
  5249. };
  5250. this.decoderWorker.postMessage({
  5251. t: 8,
  5252. data: g
  5253. });
  5254. } else {
  5255. var _ = new Uint8Array(e, n, d);
  5256. if (this.cachePanoTileID == o) {
  5257. if (this.panoCacheBuffer.set(_, f), this.panoCacheSize += d, this.panoCacheSize === u) {
  5258. var m = {
  5259. data: new Uint8Array(this.panoCacheBuffer).slice(0, u),
  5260. mediaLen: u,
  5261. tileId: o,
  5262. uuid: h,
  5263. x: a,
  5264. y: s,
  5265. z: l
  5266. };
  5267. this.decoderWorker.postMessage({
  5268. t: 8,
  5269. data: m
  5270. }), this.panoCacheSize = 0;
  5271. }
  5272. } else this.panoCacheBuffer.set(_, f), this.panoCacheSize = d, this.cachePanoTileID = o;
  5273. }
  5274. return !0;
  5275. }
  5276. }, {
  5277. key: "clearMoveArray",
  5278. value: function clearMoveArray() {
  5279. 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 = "";
  5280. }
  5281. }, {
  5282. key: "getIsMoving",
  5283. value: function getIsMoving(e) {
  5284. var t;
  5285. if (typeof e.newUserStates != "undefined") for (var r = 0; r < e.newUserStates.length; r++) {
  5286. var n = e.newUserStates[r];
  5287. if (n.userId == this.rtcp.network.room.userId) {
  5288. t = n.renderInfo.isMoving;
  5289. break;
  5290. }
  5291. }
  5292. return t;
  5293. }
  5294. }, {
  5295. key: "isHeartBeatPacket",
  5296. value: function isHeartBeatPacket(e, t) {
  5297. return new DataView(e).getUint32(0) == 2009889916;
  5298. }
  5299. }, {
  5300. key: "resetSendTimeDiff",
  5301. value: function resetSendTimeDiff() {
  5302. this.prevSenderTs = 0, this.serverSendTimeArray.clear();
  5303. }
  5304. }, {
  5305. key: "calcSendTimeDiff",
  5306. value: function calcSendTimeDiff(e) {
  5307. if (this.prevSenderTs == -1) {
  5308. this.prevSenderTs = e;
  5309. return;
  5310. }
  5311. var t = e - this.prevSenderTs;
  5312. this.serverSendTimeArray.add(t), this.prevSenderTs = e;
  5313. }
  5314. }, {
  5315. key: "unmarshalStream",
  5316. value: function unmarshalStream(e) {
  5317. var _this6 = this;
  5318. var T, C, A, S, P, R, M, x, I, w;
  5319. var t = new DataView(e);
  5320. if (t.getUint32(0) != 1437227610) return !1;
  5321. t.getUint16(4);
  5322. var n = t.getUint16(6),
  5323. o = t.getUint16(8),
  5324. a = o,
  5325. s = t.getUint16(10);
  5326. var l = !1;
  5327. s == 1 && (l = !0);
  5328. var u = t.getUint32(12),
  5329. c = t.getUint32(16),
  5330. h = t.getUint32(20),
  5331. f = t.getUint16(24),
  5332. d = t.getUint16(26),
  5333. _ = t.getUint32(28),
  5334. g = t.getUint32(n - 4),
  5335. m = u + c,
  5336. v = e.byteLength - n,
  5337. y = new Uint8Array(e, n, v);
  5338. this.calcSendTimeDiff(h);
  5339. var b;
  5340. if (this.inPanoMode && (c > 0 || f)) return defaultLogger.error("Stream Protocal Violation: receive illegal stream in Pano mode"), !0;
  5341. if (v === m) {
  5342. this.receivedMedia++;
  5343. var O = new Uint8Array(e).subarray(n);
  5344. h - this.lastServerTS > 60 ? this.serverFrameSlow++ : h - this.lastServerTS < 16 && this.serverFrameFast++;
  5345. var D = Date.now();
  5346. D - this.lastClientTS > 60 ? this.clientFrameSlow++ : D - this.lastClientTS < 16 && this.clientFrameFast++;
  5347. var F = c === 0,
  5348. V = h - this.lastServerTS;
  5349. 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;
  5350. var N = O.subarray(0, u),
  5351. L = Date.now(),
  5352. k = JSON.parse(this.Stringify(N)),
  5353. U = Date.now();
  5354. 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));
  5355. var z = this.getIsMoving(k);
  5356. if (this.inMovingMode && z == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof z != "undefined" && (this.lastIsMoving = z), this.inMovingMode) {
  5357. var G = Date.now(),
  5358. W = G - this.lastMoveResponseTime;
  5359. this.moveResponseCircular.add(W), this.lastMoveResponseTime = G;
  5360. }
  5361. (f || d) && (b = (P = (S = (A = (C = k.newUserStates) == null ? void 0 : C.find(function (G) {
  5362. return G.userId === _this6._rtcp.network.room.userId;
  5363. })) == null ? void 0 : A.playerState) == null ? void 0 : S.player) == null ? void 0 : P.position);
  5364. var H = {
  5365. t: 0,
  5366. data: O,
  5367. mediaLen: c,
  5368. metaLen: u,
  5369. metadata: k,
  5370. frameCnt: a,
  5371. server_ts: h,
  5372. isIDR: l,
  5373. cacheRequest: d,
  5374. cached: f,
  5375. cachedKey: _,
  5376. position: b
  5377. };
  5378. if (this.inPanoMode) return this.executeFunction("signal", {
  5379. signal: k,
  5380. pts: -1,
  5381. alreadyUpdateYUV: !0
  5382. }), !0;
  5383. if (this.decoderWorker.postMessage(H, [O.buffer]), !this.firstMediaReceived) {
  5384. this.firstMediaArraval = Date.now();
  5385. var _G = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5386. defaultLogger.infoAndReportMeasurement({
  5387. metric: "firstMediaArravalAt",
  5388. value: _G,
  5389. group: "joinRoom"
  5390. }), this.firstMediaReceived = !0;
  5391. }
  5392. } else {
  5393. var _O = this.hasFrmCntInCache(a);
  5394. if (_O != -1) {
  5395. if (this.cacheFrameComposes[_O].buffer.set(y, g), this.cacheFrameComposes[_O].size += v, this.cacheFrameComposes[_O].size === m) {
  5396. var _D = new Uint8Array(this.cacheFrameComposes[_O].buffer).slice(0, m);
  5397. 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++;
  5398. var _F = Date.now();
  5399. _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;
  5400. var _V = _D.subarray(0, u),
  5401. _N = Date.now(),
  5402. _L = JSON.parse(this.Stringify(_V)),
  5403. _k = Date.now();
  5404. 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);
  5405. var _U = this.getIsMoving(_L);
  5406. if (this.inMovingMode && _U == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof _U != "undefined" && (this.lastIsMoving = _U), this.inMovingMode) {
  5407. var _H = Date.now(),
  5408. _G2 = _H - this.lastMoveResponseTime;
  5409. this.moveResponseCircular.add(_G2), this.lastMoveResponseTime = _H;
  5410. }
  5411. (f || d) && (b = (w = (I = (x = (M = _L.newUserStates) == null ? void 0 : M.find(function (H) {
  5412. return H.userId === _this6._rtcp.network.room.userId;
  5413. })) == null ? void 0 : x.playerState) == null ? void 0 : I.player) == null ? void 0 : w.position);
  5414. var _z = {
  5415. t: 0,
  5416. data: _D,
  5417. mediaLen: c,
  5418. metaLen: u,
  5419. metadata: _L,
  5420. frameCnt: a,
  5421. server_ts: h,
  5422. isIDR: l,
  5423. cacheRequest: d,
  5424. cached: f,
  5425. cachedKey: _,
  5426. position: b
  5427. };
  5428. if (this.inPanoMode) return this.executeFunction("signal", {
  5429. signal: _L,
  5430. pts: -1,
  5431. alreadyUpdateYUV: !0
  5432. }), !0;
  5433. if (this.decoderWorker.postMessage(_z, [_D.buffer]), !this.firstMediaReceived) {
  5434. this.firstMediaArraval = Date.now();
  5435. var _H2 = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5436. defaultLogger.infoAndReportMeasurement({
  5437. metric: "firstMediaArravalAt",
  5438. value: _H2,
  5439. group: "joinRoom"
  5440. }), this.firstMediaReceived = !0;
  5441. }
  5442. } else this.cacheFrameComposes[_O].size > m && defaultLogger.debug("I frame exceed, cache size is ", this.cacheSize, ", total size is ", m);
  5443. } else if (_O == -1) {
  5444. var _D2 = this.hasFrmCntInCache(-1);
  5445. if (_D2 == -1) {
  5446. var _F2 = Date.now() + 1e18,
  5447. _V2 = -1;
  5448. for (var _N2 = 0; _N2 < this.cacheFrameComposes.length; _N2++) {
  5449. this.cacheFrameComposes[_N2].serverTime < _F2 && (_F2 = this.cacheFrameComposes[_N2].serverTime, _V2 = _N2);
  5450. }
  5451. _D2 = _V2;
  5452. }
  5453. 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;
  5454. }
  5455. }
  5456. return !0;
  5457. }
  5458. }, {
  5459. key: "reset",
  5460. value: function reset() {
  5461. defaultLogger.debug("Worker reset is called"), this.cacheFrameCnt = 0, this.receivedMedia = 0, this.reconnectSignal = !0, this.decoderWorker.postMessage({
  5462. t: 4
  5463. });
  5464. }
  5465. }, {
  5466. key: "dataHandleOff",
  5467. value: function dataHandleOff(e) {
  5468. defaultLogger.debug("hhh");
  5469. }
  5470. }, {
  5471. key: "dataHandle",
  5472. value: function dataHandle(e) {
  5473. this.saveframe && (this.decoderWorker.postMessage({
  5474. t: 6
  5475. }), this.saveframe = !1), this.SaveMediaStream && (this.decoderWorker.postMessage({
  5476. t: 7
  5477. }), this.SaveMediaStream = !1);
  5478. var t = new Uint8Array(e);
  5479. if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0) return;
  5480. if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
  5481. this.reconnectSignal && (this.executeFunction("reconnectedFrame", {}), this.reconnectSignal = !1);
  5482. return;
  5483. }
  5484. if (t.length > 20 && this.unmarshalPano(t.buffer) == !0) return;
  5485. this.noWasmBytesReceived += e.byteLength;
  5486. var r = JSON.parse(this.Stringify(t));
  5487. this.executeFunction("signal", {
  5488. signal: r,
  5489. pts: -1,
  5490. alreadyUpdateYUV: !0
  5491. });
  5492. }
  5493. }, {
  5494. key: "changePanoMode",
  5495. value: function changePanoMode(e) {
  5496. this.inPanoMode = e;
  5497. }
  5498. }, {
  5499. key: "uploadDataToServer",
  5500. value: function uploadDataToServer() {
  5501. this.DynamicPanoTest == !0 && (this.onRotateInPanoMode({
  5502. traceId: "b2e1a296-6438-4371-8a31-687beb724ebe"
  5503. }), this.DynamicPanoTest = !1);
  5504. function e(ie, ee) {
  5505. return ee == -1 && (ee = 0), ie + ee;
  5506. }
  5507. function t(ie, ee) {
  5508. return Math.max(ie, ee);
  5509. }
  5510. var r = this.responseTimeArray.reduce(e, 0) / this.responseTimeArray.length || 0,
  5511. n = this.processTimeArray.reduce(e, 0) / this.processTimeArray.length || 0,
  5512. o = this.displayTimeArray.reduce(e, 0) / this.displayTimeArray.length || 0,
  5513. a = this.overallTimeArray.reduce(e, 0) / this.overallTimeArray.length || 0,
  5514. s = this.overallTimeArray.length;
  5515. this.responseTimeArray = [], this.processTimeArray = [], this.displayTimeArray = [], this.overallTimeArray = [];
  5516. var l = this.moveResponseCircular.getThreshPercent(),
  5517. u = l[0],
  5518. c = l[1],
  5519. h = l[2],
  5520. f = l[3],
  5521. d = l[4],
  5522. _ = d - f,
  5523. g = 1 - c / d || 0,
  5524. m = [u, c - u, h - c, f - h, _],
  5525. v = this.moveProcessCircular.getThreshPercent(),
  5526. y = v[0],
  5527. b = v[1],
  5528. T = v[2],
  5529. C = v[3],
  5530. A = v[4],
  5531. S = A - C,
  5532. P = 1 - b / A || 0,
  5533. R = [y, b - y, T - b, C - T, S],
  5534. M = this.moveDisplayCircular.getThreshPercent(),
  5535. x = M[0],
  5536. I = M[1],
  5537. w = M[2],
  5538. O = M[3],
  5539. D = M[4],
  5540. F = D - O,
  5541. V = 1 - I / D || 0,
  5542. N = [x, I - x, w - I, O - w, F],
  5543. L = x,
  5544. k = I - x,
  5545. U = w - I,
  5546. z = O - w,
  5547. H = F,
  5548. G = this.moveResponseCircular.getAvg(),
  5549. W = this.moveProcessCircular.getAvg(),
  5550. j = this.moveDisplayCircular.getAvg(),
  5551. B = this.moveResponseCircular.getMax(),
  5552. X = this.moveProcessCircular.getMax(),
  5553. $ = this.moveDisplayCircular.getMax(),
  5554. Y = this.moveResponseCircular.getStandardDeviation(),
  5555. K = this.moveProcessCircular.getStandardDeviation(),
  5556. Z = this.moveDisplayCircular.getStandardDeviation();
  5557. 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();
  5558. var q = this.frameServerCircular.getAvg(),
  5559. J = this.frameServerCircular.getMax();
  5560. this.frameClientCircular.getAvg(), this.frameClientCircular.getMax();
  5561. var Q = this.metaParseAraay.reduce(e, 0) / this.metaParseAraay.length || 0,
  5562. te = this.metaParseAraay.reduce(t, 0);
  5563. this.metaParseAraay = [];
  5564. var re = {
  5565. mediaBytesReceived: this.mediaBytesReceived,
  5566. metaBytesReceived: this.metaBytesReceived,
  5567. packetsLost: this.packetsLost,
  5568. timestamp: Date.now(),
  5569. frameHeight: 1280,
  5570. frameWidth: 720,
  5571. framesReceived: this.receivedMedia,
  5572. framesReceivedWorker: this.receivedMedia_worker,
  5573. framesDecoded: this.receivedYUV,
  5574. framesEmited: this.receivedEmit,
  5575. decodeTimePerFrame: this.decodeTimePerFrame,
  5576. decodeTimeMaxFrame: this.decodeTimeMaxFrame,
  5577. packetsDrop: this.packetsDrop,
  5578. framesAwait: this.framesAwait,
  5579. firstMediaArraval: this.firstMediaArraval,
  5580. firstYUVDecoded: this.firstYUVDecoded,
  5581. firstRender: this.firstRender,
  5582. returnFrames: this.returnFrames,
  5583. sendOutBuffer: this.sendOutBuffer,
  5584. maxGraphicTime: this.updateYUVCircular.getMax(),
  5585. averageGraphicTime: this.updateYUVCircular.getAvg(),
  5586. jankTimes: this.JankTimes,
  5587. bigJankTimes: this.bigJankTimes,
  5588. decodeJankTimes: this.DecodeJankTimes,
  5589. bigDecodeJankTimes: this.bigDecodeJankTimes,
  5590. serverFrameSlow: this.serverFrameSlow,
  5591. serverFrameFast: this.serverFrameFast,
  5592. clientFrameSlow: this.clientFrameSlow,
  5593. clientFrameFast: this.clientFrameFast,
  5594. rtcMessageReceived: this.rtcMessageReceived,
  5595. rtcBytesReceived: this.rtcBytesReceived - this.noWasmBytesReceived,
  5596. receiveIframes: this.receiveIframes,
  5597. decodeIframes: this.decodeIframes,
  5598. avgResponseTime: r,
  5599. avgProcessTime: n,
  5600. avgDisplayTime: o,
  5601. avgOverallTime: a,
  5602. overallTimeCount: s,
  5603. responseMiss: this.responseMiss,
  5604. processMiss: this.processMiss,
  5605. displayMiss: this.displayMiss,
  5606. updateDropFrame: this.updateDropFrame,
  5607. moveEvent: this.moveEvent,
  5608. avgResponseMoveDiff: this.moveEvent == "MoveTo" ? G : 0,
  5609. avgProcessMoveDiff: this.moveEvent == "MoveTo" ? W : 0,
  5610. avgDisplayMoveDiff: this.moveEvent == "MoveTo" ? j : 0,
  5611. maxResponseMoveDiff: this.moveEvent == "MoveTo" ? B : 0,
  5612. maxProcessMoveDiff: this.moveEvent == "MoveTo" ? X : 0,
  5613. maxDisplayMoveDiff: this.moveEvent == "MoveTo" ? $ : 0,
  5614. moveResponseJank: this.moveEvent == "MoveTo" ? g : 0,
  5615. moveProcessJank: this.moveEvent == "MoveTo" ? P : 0,
  5616. moveDisplayJank: this.moveEvent == "MoveTo" ? V : 0,
  5617. moveResponseCounts: this.moveEvent == "MoveTo" ? m.toString() : "0,0,0,0,0",
  5618. moveProcessCounts: this.moveEvent == "MoveTo" ? R.toString() : "0,0,0,0,0",
  5619. moveDisplayCounts: this.moveEvent == "MoveTo" ? N.toString() : "0,0,0,0,0",
  5620. MoveDisplayCountGood: this.moveEvent == "MoveTo" ? L.toString() : "0",
  5621. MoveDisplayCountWell: this.moveEvent == "MoveTo" ? k.toString() : "0",
  5622. MoveDisplayCountFair: this.moveEvent == "MoveTo" ? U.toString() : "0",
  5623. MoveDisplayCountBad: this.moveEvent == "MoveTo" ? z.toString() : "0",
  5624. MoveDisplayCountRest: this.moveEvent == "MoveTo" ? H.toString() : "0",
  5625. moveResponseDelay: this.moveEvent == "MoveTo" ? this.MoveResponseDelay : 0,
  5626. moveProcessDelay: this.moveEvent == "MoveTo" ? this.MoveProcessDelay : 0,
  5627. moveDisplayDelay: this.moveEvent == "MoveTo" ? this.MoveDisplayDelay : 0,
  5628. sdMoveResponseLongTime: Y,
  5629. sdMoveProcessLongTime: K,
  5630. sdMoveDisplayLongTime: Z,
  5631. avgResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? G : 0,
  5632. avgProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? W : 0,
  5633. avgDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? j : 0,
  5634. maxResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? B : 0,
  5635. maxProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? X : 0,
  5636. maxDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? $ : 0,
  5637. flyResponseJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? g : 0,
  5638. flyProcessJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? P : 0,
  5639. flyDisplayJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? V : 0,
  5640. flyResponseCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? m.toString() : "0,0,0,0,0",
  5641. flyProcessCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? R.toString() : "0,0,0,0,0",
  5642. flyDisplayCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? N.toString() : "0,0,0,0,0",
  5643. flyResponseDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveResponseDelay : 0,
  5644. flyProcessDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveProcessDelay : 0,
  5645. flyDisplayDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveDisplayDelay : 0,
  5646. avgMetaParseTime: Q,
  5647. maxMetaParseTime: te,
  5648. avgServerDiff: q,
  5649. maxServerDiff: J,
  5650. streamType: WASM_Version
  5651. };
  5652. return this.lastReturnFrames = this.returnFrames, this.lastReceivedEmit = this.receivedEmit, re;
  5653. }
  5654. }]);
  5655. return Workers;
  5656. }();
  5657. 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); }; }
  5658. 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; } }
  5659. var Rtcp = /*#__PURE__*/function (_EventEmitter) {
  5660. _inherits(Rtcp, _EventEmitter);
  5661. var _super = _createSuper$9(Rtcp);
  5662. function Rtcp(e) {
  5663. var _this;
  5664. _classCallCheck(this, Rtcp);
  5665. _this = _super.call(this);
  5666. E(_assertThisInitialized(_this), "connection", null);
  5667. E(_assertThisInitialized(_this), "inputChannel", null);
  5668. E(_assertThisInitialized(_this), "mediaStream");
  5669. E(_assertThisInitialized(_this), "socket");
  5670. E(_assertThisInitialized(_this), "connected", !1);
  5671. E(_assertThisInitialized(_this), "candidates", []);
  5672. E(_assertThisInitialized(_this), "isAnswered", !1);
  5673. E(_assertThisInitialized(_this), "isFlushing", !1);
  5674. E(_assertThisInitialized(_this), "inputReady", !1);
  5675. E(_assertThisInitialized(_this), "workers");
  5676. E(_assertThisInitialized(_this), "actived", !0);
  5677. E(_assertThisInitialized(_this), "heartbeat");
  5678. E(_assertThisInitialized(_this), "onIcecandidate", function (e) {
  5679. if (e.candidate != null) {
  5680. var t = JSON.stringify(e.candidate);
  5681. logger.debug("Got ice candidate: ".concat(t)), _this.network.socket.send({
  5682. id: "ice_candidate",
  5683. data: btoa(t)
  5684. });
  5685. }
  5686. });
  5687. E(_assertThisInitialized(_this), "onIcecandidateerror", function (e) {
  5688. logger.error("onicecandidateerror", e.errorCode, e.errorText, e);
  5689. });
  5690. E(_assertThisInitialized(_this), "onIceStateChange", function (e) {
  5691. switch (e.target.iceGatheringState) {
  5692. case "gathering":
  5693. logger.info("ice gathering");
  5694. break;
  5695. case "complete":
  5696. logger.info("Ice gathering completed");
  5697. }
  5698. });
  5699. E(_assertThisInitialized(_this), "onIceConnectionStateChange", function () {
  5700. if (!!_this.connection) switch (logger.info("iceConnectionState: ".concat(_this.connection.iceConnectionState)), _this.connection.iceConnectionState) {
  5701. case "connected":
  5702. {
  5703. _this.connected = !0;
  5704. break;
  5705. }
  5706. case "disconnected":
  5707. {
  5708. _this.connected = !1, _this.emit("rtcDisconnected");
  5709. break;
  5710. }
  5711. case "failed":
  5712. {
  5713. _this.emit("rtcDisconnected"), _this.connected = !1;
  5714. break;
  5715. }
  5716. }
  5717. });
  5718. E(_assertThisInitialized(_this), "setRemoteDescription", /*#__PURE__*/function () {
  5719. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  5720. var a, s, l, r, n, o, u;
  5721. return regenerator.wrap(function _callee$(_context) {
  5722. while (1) {
  5723. switch (_context.prev = _context.next) {
  5724. case 0:
  5725. if (_this.connection) {
  5726. _context.next = 2;
  5727. break;
  5728. }
  5729. return _context.abrupt("return");
  5730. case 2:
  5731. r = JSON.parse(atob(e)), n = new RTCSessionDescription(r);
  5732. _context.next = 5;
  5733. return _this.connection.setRemoteDescription(n);
  5734. case 5:
  5735. _context.next = 7;
  5736. return _this.connection.createAnswer();
  5737. case 7:
  5738. o = _context.sent;
  5739. 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) {
  5740. u = o.sdp.lastIndexOf("a=mid:1");
  5741. o.sdp = o.sdp.slice(0, u) + "a=mid:2" + o.sdp.slice(u + 7);
  5742. }
  5743. _context.prev = 9;
  5744. _context.next = 12;
  5745. return _this.connection.setLocalDescription(o);
  5746. case 12:
  5747. _context.next = 17;
  5748. break;
  5749. case 14:
  5750. _context.prev = 14;
  5751. _context.t0 = _context["catch"](9);
  5752. logger.error("error", _context.t0);
  5753. case 17:
  5754. _this.isAnswered = !0, _this.network.rtcp.flushCandidate(), _this.network.socket.send({
  5755. id: "answer",
  5756. data: btoa(JSON.stringify(o))
  5757. }), t.srcObject = _this.mediaStream;
  5758. case 18:
  5759. case "end":
  5760. return _context.stop();
  5761. }
  5762. }
  5763. }, _callee, null, [[9, 14]]);
  5764. }));
  5765. return function (_x, _x2) {
  5766. return _ref.apply(this, arguments);
  5767. };
  5768. }());
  5769. E(_assertThisInitialized(_this), "flushCandidate", function () {
  5770. _this.isFlushing || !_this.isAnswered || (_this.isFlushing = !0, _this.candidates.forEach(function (e) {
  5771. var t = atob(e),
  5772. r = JSON.parse(t);
  5773. if (/172\./.test(r.candidate)) return;
  5774. var n = new RTCIceCandidate(r);
  5775. _this.connection && _this.connection.addIceCandidate(n).then(function () {}, function (o) {
  5776. logger.info("add candidate failed", o);
  5777. });
  5778. }), _this.isFlushing = !1);
  5779. });
  5780. E(_assertThisInitialized(_this), "input", function (e) {
  5781. var t;
  5782. !_this.actived || !_this.inputChannel || _this.inputChannel.readyState === "open" && ((t = _this.inputChannel) == null || t.send(e));
  5783. });
  5784. _this.network = e, _this.workers = new Workers(_assertThisInitialized(_this), logger), _this.workers.registerLogger(logger), _this.workers.registerFunction("data", function (t) {
  5785. _this.emit("data", t);
  5786. }), _this.heartbeat = new Heartbeat({
  5787. ping: function ping(t) {
  5788. e.room.actionsHandler.echo(t);
  5789. },
  5790. pong(t, r) {
  5791. var n;
  5792. r && t > 500 && logger.warn("high hb value ".concat(t, ", traceId:") + r), (n = e.room.stats) == null || n.assign({
  5793. hb: t
  5794. });
  5795. }
  5796. });
  5797. return _this;
  5798. }
  5799. _createClass(Rtcp, [{
  5800. key: "start",
  5801. value: function start() {
  5802. var _this2 = this;
  5803. this.connection = new RTCPeerConnection();
  5804. var e = Date.now();
  5805. this.connection.ondatachannel = function (t) {
  5806. logger.info("ondatachannel: ".concat(t.channel.label));
  5807. _this2.inputChannel = t.channel;
  5808. _this2.inputChannel.onopen = function () {
  5809. var r;
  5810. 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({
  5811. metric: "datachannelOpenedAt",
  5812. startTime: _this2.network.room._startTime,
  5813. group: "joinRoom"
  5814. }), logger.infoAndReportMeasurement({
  5815. metric: "datachannelOpenedCost",
  5816. startTime: e,
  5817. group: "joinRoom"
  5818. }));
  5819. console.log('this.inputChannel', _this2.inputChannel);
  5820. }, _this2.inputChannel.onclose = function () {
  5821. var r;
  5822. return logger.info("The input channel has closed, id:", (r = _this2.inputChannel) == null ? void 0 : r.id);
  5823. }, _this2.inputChannel.onmessage = function (r) {
  5824. // console.log('this.workers',this.workers)
  5825. console.log('inputChannel', r.data);
  5826. _this2.workers.dataHandle(r.data);
  5827. };
  5828. }, this.connection.oniceconnectionstatechange = this.onIceConnectionStateChange, this.connection.onicegatheringstatechange = this.onIceStateChange, this.connection.onicecandidate = this.onIcecandidate, this.connection.onicecandidateerror = this.onIcecandidateerror, this.network.socket.send({
  5829. id: "init_webrtc",
  5830. data: JSON.stringify({
  5831. is_mobile: !0
  5832. })
  5833. });
  5834. }
  5835. }, {
  5836. key: "addCandidate",
  5837. value: function addCandidate(e) {
  5838. e === "" ? this.network.rtcp.flushCandidate() : this.candidates.push(e);
  5839. }
  5840. }, {
  5841. key: "disconnect",
  5842. value: function disconnect() {
  5843. var e, t, r;
  5844. 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;
  5845. }
  5846. }, {
  5847. key: "sendStringData",
  5848. value: function sendStringData(e) {
  5849. console.log('e', e);
  5850. this.input(e);
  5851. }
  5852. }, {
  5853. key: "sendData",
  5854. value: function sendData(e) {
  5855. var t = "";
  5856. try {
  5857. t = JSON.stringify(e);
  5858. } catch (r) {
  5859. logger.error(r);
  5860. return;
  5861. }
  5862. this.input(t);
  5863. }
  5864. }]);
  5865. return Rtcp;
  5866. }(EventEmitter);
  5867. var NetworkMonitor = /*#__PURE__*/function () {
  5868. function NetworkMonitor(e) {
  5869. _classCallCheck(this, NetworkMonitor);
  5870. this._listener = e;
  5871. }
  5872. _createClass(NetworkMonitor, [{
  5873. key: "isOnline",
  5874. get: function get() {
  5875. var e = window.navigator;
  5876. return typeof e.onLine == "boolean" ? e.onLine : !0;
  5877. }
  5878. }, {
  5879. key: "start",
  5880. value: function start() {
  5881. window.addEventListener("online", this._listener), window.addEventListener("offline", this._listener);
  5882. }
  5883. }, {
  5884. key: "stop",
  5885. value: function stop() {
  5886. window.removeEventListener("online", this._listener), window.removeEventListener("offline", this._listener);
  5887. }
  5888. }]);
  5889. return NetworkMonitor;
  5890. }();
  5891. var Stream = /*#__PURE__*/function () {
  5892. function Stream(e) {
  5893. _classCallCheck(this, Stream);
  5894. this.el = null;
  5895. this._streamPlayTimer = null;
  5896. if (!e) {
  5897. this.el = this.createVideoElement();
  5898. return;
  5899. }
  5900. this.el = e;
  5901. }
  5902. _createClass(Stream, [{
  5903. key: "play",
  5904. value: function play() {
  5905. var _this = this;
  5906. return new Promise(function (e, t) {
  5907. _this._streamPlayTimer = new Timeout(function () {
  5908. t(new InternalError("Stream play timeout"));
  5909. }, 5e3), _this.el && _this.el.play().then(function () {
  5910. var r;
  5911. e(), logger.info("Media can autoplay"), (r = _this._streamPlayTimer) == null || r.clear();
  5912. }).catch(function (r) {
  5913. var n;
  5914. logger.error("Media Failed to autoplay"), logger.error(r), t(new InternalError("Media Failed to autoplay")), (n = _this._streamPlayTimer) == null || n.clear();
  5915. });
  5916. });
  5917. }
  5918. }, {
  5919. key: "createVideoElement",
  5920. value: function createVideoElement() {
  5921. var e = document.createElement("video");
  5922. 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;
  5923. }
  5924. }]);
  5925. return Stream;
  5926. }();
  5927. 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); }; }
  5928. 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; } }
  5929. var InternalError$1 = /*#__PURE__*/function (_XverseError) {
  5930. _inherits(InternalError, _XverseError);
  5931. var _super = _createSuper$8(InternalError);
  5932. function InternalError(e) {
  5933. _classCallCheck(this, InternalError);
  5934. return _super.call(this, 1002, e || "\u5185\u90E8\u9519\u8BEF");
  5935. }
  5936. return _createClass(InternalError);
  5937. }(XverseError);
  5938. 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); }; }
  5939. 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; } }
  5940. 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 ";
  5941. var NetworkController = /*#__PURE__*/function (_EventEmitter) {
  5942. _inherits(NetworkController, _EventEmitter);
  5943. var _super = _createSuper$7(NetworkController);
  5944. function NetworkController(e) {
  5945. var _this;
  5946. _classCallCheck(this, NetworkController);
  5947. _this = _super.call(this);
  5948. _this.socket = null;
  5949. _this.rtcp = null;
  5950. _this.stream = null;
  5951. _this._state = 'connecting';
  5952. _this._networkMonitor = null;
  5953. _this.blockedActions = [];
  5954. _this.reconnectCount = 0;
  5955. _this.room = e, _this.socket = new Socket(_assertThisInitialized(_this));
  5956. _this.rtcp = new Rtcp(_assertThisInitialized(_this));
  5957. _this.stream = new Stream();
  5958. _this._networkMonitor = new NetworkMonitor(function () {
  5959. 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());
  5960. });
  5961. _this.checkNetworkQuality(_this.room.currentNetworkOptions.wsServerUrl);
  5962. _this._networkMonitor.start();
  5963. new VisibilityChangeHandler().subscribe(function (r) {
  5964. var n, o;
  5965. r ? ((o = _this.room.stats) == null || o.disable(), logger.infoAndReportMeasurement({
  5966. metric: "pageHide",
  5967. startTime: Date.now()
  5968. })) : ((n = _this.room.stats) == null || n.enable(), logger.infoAndReportMeasurement({
  5969. metric: "pageShow",
  5970. startTime: Date.now(),
  5971. extra: {
  5972. state: _this._state
  5973. }
  5974. }), _this._state === "disconnected" && _this.reconnect());
  5975. });
  5976. return _this;
  5977. }
  5978. _createClass(NetworkController, [{
  5979. key: "startGame",
  5980. value: function startGame() {
  5981. var _this2 = this;
  5982. return new Promise(function (e, t) {
  5983. if (!_this2.rtcp.connected) return t(new InternalError$1("Game cannot load. Please refresh"));
  5984. if (!_this2.rtcp.inputReady) return t(new InternalError$1("Game is not ready yet. Please wait"));
  5985. _this2.socket.on("gameRoomAvailable", function (r) {
  5986. _this2.setState("connected"), e(r), _this2.rtcp.heartbeat.start();
  5987. }), _this2.socket.on("socketClosed", function (r) {
  5988. t(r);
  5989. }), _this2.socket.startGame();
  5990. });
  5991. }
  5992. }, {
  5993. key: "addBlockedActions",
  5994. value: function addBlockedActions(e) {
  5995. var _this$blockedActions;
  5996. (_this$blockedActions = this.blockedActions).push.apply(_this$blockedActions, _toConsumableArray(e));
  5997. }
  5998. }, {
  5999. key: "removeBlockedActions",
  6000. value: function removeBlockedActions(e) {
  6001. if (!e) {
  6002. this.blockedActions = [];
  6003. return;
  6004. }
  6005. var t = this.blockedActions.indexOf(e);
  6006. this.blockedActions.splice(t, 1);
  6007. }
  6008. }, {
  6009. key: "setState",
  6010. value: function setState(e) {
  6011. this._state !== e && (logger.info("Set network state to ", e), this._state = e);
  6012. }
  6013. }, {
  6014. key: "connectAndStart",
  6015. value: function () {
  6016. var _connectAndStart = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  6017. return regenerator.wrap(function _callee$(_context) {
  6018. while (1) {
  6019. switch (_context.prev = _context.next) {
  6020. case 0:
  6021. return _context.abrupt("return", this.connect(e).then(this.startGame));
  6022. case 1:
  6023. case "end":
  6024. return _context.stop();
  6025. }
  6026. }
  6027. }, _callee, this);
  6028. }));
  6029. function connectAndStart(_x) {
  6030. return _connectAndStart.apply(this, arguments);
  6031. }
  6032. return connectAndStart;
  6033. }()
  6034. }, {
  6035. key: "connect",
  6036. value: function () {
  6037. var _connect = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  6038. var _this3 = this;
  6039. var e,
  6040. _args2 = arguments;
  6041. return regenerator.wrap(function _callee2$(_context2) {
  6042. while (1) {
  6043. switch (_context2.prev = _context2.next) {
  6044. case 0:
  6045. e = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : !1;
  6046. this.room.updateCurrentNetworkOptions({
  6047. reconnect: e
  6048. });
  6049. return _context2.abrupt("return", new Promise(function (t, r) {
  6050. _this3.rtcp.on("rtcConnected", function () {
  6051. _this3.setState("connected"), t();
  6052. }), _this3.rtcp.on("rtcDisconnected", function () {
  6053. 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());
  6054. }), _this3.socket.on("socketQuit", function () {
  6055. logger.info("socket quit success"), _this3.setState("closed");
  6056. }), _this3.socket.on("socketClosed", function (n) {
  6057. _this3._state === "connecting" && (_this3.setState("disconnected"), r(n)), r(n);
  6058. }), _this3.socket.start();
  6059. }));
  6060. case 3:
  6061. case "end":
  6062. return _context2.stop();
  6063. }
  6064. }
  6065. }, _callee2, this);
  6066. }));
  6067. function connect() {
  6068. return _connect.apply(this, arguments);
  6069. }
  6070. return connect;
  6071. }()
  6072. }, {
  6073. key: "reconnect",
  6074. value: function reconnect() {
  6075. var _this4 = this;
  6076. if (this.room.viewMode === "observer") return;
  6077. var e = Date.now();
  6078. if (this.reconnectCount++, this.reconnectCount > MAX_RECONNECT_COUNT) {
  6079. logger.error("reconnect failed, reached max reconnect count", MAX_RECONNECT_COUNT), this.reconnectCount = 0, this.emit("stateChanged", {
  6080. state: "disconnected"
  6081. });
  6082. return;
  6083. }
  6084. return logger.info("start reconnect, count:", this.reconnectCount), this._reconnect().then(function () {
  6085. logger.infoAndReportMeasurement({
  6086. startTime: e,
  6087. metric: "reconnect"
  6088. });
  6089. }).catch(function (t) {
  6090. if (logger.infoAndReportMeasurement({
  6091. startTime: e,
  6092. metric: "reconnect",
  6093. error: t
  6094. }), t.code === Codes.RepeatLogin) {
  6095. _this4.room.handleRepetLogin();
  6096. return;
  6097. }
  6098. var r = 1e3;
  6099. logger.info("reconnect failed, wait " + r + " ms for next reconnect"), setTimeout(function () {
  6100. _this4.reconnect();
  6101. }, r);
  6102. });
  6103. }
  6104. }, {
  6105. key: "_reconnect",
  6106. value: function _reconnect() {
  6107. var _this5 = this;
  6108. 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", {
  6109. state: "reconnecting",
  6110. count: this.reconnectCount
  6111. }), this.socket.off("gameRoomAvailable"), this.socket.off("socketClosed"), this.rtcp.off("rtcDisconnected"), this.rtcp.off("rtcConnected"), this.connectAndStart(!0).then(function (_ref) {
  6112. var e = _ref.session_id;
  6113. _this5.room.updateCurrentNetworkOptions({
  6114. sessionId: e
  6115. }), reporter.updateBody({
  6116. serverSession: e
  6117. }), logger.info("reconnect success"), _this5.setState("connected"), _this5.reconnectCount = 0, _this5.emit("stateChanged", {
  6118. state: "reconnected"
  6119. });
  6120. }));
  6121. }
  6122. }, {
  6123. key: "prepareReconnect",
  6124. value: function prepareReconnect() {
  6125. this.rtcp.disconnect(), this.socket.prepareReconnect(), this.prepareReconnectOptions();
  6126. }
  6127. }, {
  6128. key: "prepareReconnectOptions",
  6129. value: function prepareReconnectOptions() {
  6130. var _ref2 = this.room.currentClickingState || {},
  6131. e = _ref2.camera,
  6132. t = _ref2.player;
  6133. e && t && this.room.updateCurrentNetworkOptions({
  6134. camera: e,
  6135. player: t
  6136. });
  6137. }
  6138. }, {
  6139. key: "sendRtcData",
  6140. value: function sendRtcData(e) {
  6141. if (this.blockedActions.includes(e.action_type)) {
  6142. logger.info("action: ".concat(Actions[e.action_type], " was blocked"));
  6143. return;
  6144. }
  6145. this.rtcp.sendData(e);
  6146. }
  6147. }, {
  6148. key: "sendSocketData",
  6149. value: function sendSocketData(e) {
  6150. logger.debug("ws send ->", e), this.socket.send(e);
  6151. }
  6152. }, {
  6153. key: "quit",
  6154. value: function quit() {
  6155. var e = util.uuid(),
  6156. t = {
  6157. action_type: Actions.Exit,
  6158. trace_id: e,
  6159. exit_action: {},
  6160. user_id: this.room.options.userId,
  6161. packet_id: e
  6162. };
  6163. this.setState("closed"), this.socket.quit(), this.sendRtcData(t);
  6164. }
  6165. }, {
  6166. key: "checkNetworkQuality",
  6167. value: function checkNetworkQuality(i) {
  6168. var worker = null;
  6169. if (!i) return;
  6170. var e = Date.now();
  6171. if (this.pingOthers("https://www.baidu.com", function (t, r) {
  6172. logger.infoAndReportMeasurement({
  6173. metric: "baiduRtt",
  6174. group: "http",
  6175. value: r,
  6176. startTime: e
  6177. });
  6178. }), !worker) {
  6179. var t = new Blob([workerSourceCode], {
  6180. type: "application/javascript"
  6181. });
  6182. worker = new Worker(URL.createObjectURL(t)), worker.onmessage = function (r) {
  6183. logger.infoAndReportMeasurement({
  6184. metric: "workerRtt",
  6185. group: "http",
  6186. startTime: e,
  6187. value: r.data
  6188. });
  6189. };
  6190. }
  6191. }
  6192. }, {
  6193. key: "pingOthers",
  6194. value: function pingOthers(i, e) {
  6195. var t = !1;
  6196. var r = new Image();
  6197. r.onload = o, r.onerror = a;
  6198. var n = Date.now();
  6199. function o(l) {
  6200. t = !0, s();
  6201. }
  6202. function a(l) {}
  6203. function s() {
  6204. var l = Date.now() - n;
  6205. if (typeof e == "function") return t ? e(null, l) : (console.error("error loading resource"), e("error", l));
  6206. }
  6207. r.src = i + "/favicon.ico?" + +new Date();
  6208. }
  6209. }]);
  6210. return NetworkController;
  6211. }(EventEmitter);
  6212. 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); }; }
  6213. 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; } }
  6214. var InitConfigTimeoutError = /*#__PURE__*/function (_XverseError) {
  6215. _inherits(InitConfigTimeoutError, _XverseError);
  6216. var _super = _createSuper$6(InitConfigTimeoutError);
  6217. function InitConfigTimeoutError(e) {
  6218. _classCallCheck(this, InitConfigTimeoutError);
  6219. return _super.call(this, 1009, e || "\u914D\u7F6E\u521D\u59CB\u5316\u8D85\u65F6");
  6220. }
  6221. return _createClass(InitConfigTimeoutError);
  6222. }(XverseError);
  6223. 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); }; }
  6224. 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; } }
  6225. var InitDecoderTimeoutError = /*#__PURE__*/function (_XverseError) {
  6226. _inherits(InitDecoderTimeoutError, _XverseError);
  6227. var _super = _createSuper$5(InitDecoderTimeoutError);
  6228. function InitDecoderTimeoutError(e) {
  6229. _classCallCheck(this, InitDecoderTimeoutError);
  6230. return _super.call(this, 1008, e || "Decoder \u521D\u59CB\u5316\u8D85\u65F6");
  6231. }
  6232. return _createClass(InitDecoderTimeoutError);
  6233. }(XverseError);
  6234. 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); }; }
  6235. 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; } }
  6236. var InitEngineError = /*#__PURE__*/function (_XverseError) {
  6237. _inherits(InitEngineError, _XverseError);
  6238. var _super = _createSuper$4(InitEngineError);
  6239. function InitEngineError(e) {
  6240. _classCallCheck(this, InitEngineError);
  6241. return _super.call(this, 1011, e || "\u5F15\u64CE\u521D\u59CB\u5316\u9519\u8BEF");
  6242. }
  6243. return _createClass(InitEngineError);
  6244. }(XverseError);
  6245. var AssetTypeName = {
  6246. Config: 'CONFIG',
  6247. Model: 'MODEL',
  6248. Vedio: 'VEDIO',
  6249. Media: 'MEDIA',
  6250. Effects: 'EFFECTS',
  6251. Gift: 'GIFT',
  6252. Textures: 'TEXTURES'
  6253. };
  6254. var AssetClassName = {
  6255. Effects: '\u7279\u6548',
  6256. Tv: 'TV',
  6257. Lpm: '\u7C97\u6A21',
  6258. Reward: '\u571F\u8C6A\u699C',
  6259. Env: '\u73AF\u5883\u5149',
  6260. Gbq: '\u544A\u767D\u5899',
  6261. BreathPoint: '\u547C\u5438\u70B9',
  6262. Gifts: '\u9001\u793C',
  6263. Panorama: '\u5168\u666F\u56FE',
  6264. GiftBubble: '\u9001\u793C\u6C14\u6CE1',
  6265. SayBubble: '\u804A\u5929\u6C14\u6CE1'
  6266. };
  6267. var LoggerLevels$1 = {
  6268. Debug: 1,
  6269. Info: 2,
  6270. Warn: 3,
  6271. Error: 4,
  6272. Off: 5
  6273. };
  6274. var EShaderMode$1 = {
  6275. default: 0,
  6276. video: 1,
  6277. videoAndPano: 2
  6278. };
  6279. var BaseTable = /*#__PURE__*/function () {
  6280. function BaseTable(e, t) {
  6281. _classCallCheck(this, BaseTable);
  6282. this.db = null;
  6283. this.isCreatingTable = !1;
  6284. this.hasCleared = !1;
  6285. this.dbName = e, this.dbVersion = t;
  6286. }
  6287. _createClass(BaseTable, [{
  6288. key: "clearDataBase",
  6289. value: function () {
  6290. var _clearDataBase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  6291. var _this = this;
  6292. return regenerator.wrap(function _callee$(_context) {
  6293. while (1) {
  6294. switch (_context.prev = _context.next) {
  6295. case 0:
  6296. return _context.abrupt("return", this.hasCleared || (e && (this.hasCleared = !0), !window.indexedDB.databases) ? Promise.resolve() : new Promise(function (t, r) {
  6297. var n = window.indexedDB.deleteDatabase(_this.dbName);
  6298. n.onsuccess = function () {
  6299. t();
  6300. }, n.onerror = r;
  6301. }));
  6302. case 1:
  6303. case "end":
  6304. return _context.stop();
  6305. }
  6306. }
  6307. }, _callee, this);
  6308. }));
  6309. function clearDataBase(_x) {
  6310. return _clearDataBase.apply(this, arguments);
  6311. }
  6312. return clearDataBase;
  6313. }()
  6314. }, {
  6315. key: "tableName",
  6316. value: function tableName() {
  6317. throw new Error("Derived class have to override 'tableName', and set a proper table name!");
  6318. }
  6319. }, {
  6320. key: "keyPath",
  6321. value: function keyPath() {
  6322. throw new Error("Derived class have to override 'keyPath', and set a proper index name!");
  6323. }
  6324. }, {
  6325. key: "index",
  6326. value: function index() {
  6327. throw new Error("Derived class have to override 'index', and set a proper index name!");
  6328. }
  6329. }, {
  6330. key: "checkAndOpenDatabase",
  6331. value: function () {
  6332. var _checkAndOpenDatabase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  6333. var _this2 = this;
  6334. return regenerator.wrap(function _callee2$(_context2) {
  6335. while (1) {
  6336. switch (_context2.prev = _context2.next) {
  6337. case 0:
  6338. return _context2.abrupt("return", this.db ? Promise.resolve(this.db) : new Promise(function (e, t) {
  6339. var n = setTimeout(function () {
  6340. logger.info("wait db to open for", 200), _this2.db ? e(_this2.db) : e(_this2.checkAndOpenDatabase()), clearTimeout(n);
  6341. }, 200);
  6342. _this2.openDatabase(_this2.dbName, _this2.dbVersion || 1, function () {
  6343. _this2.db && !_this2.isCreatingTable && e(_this2.db), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable)), clearTimeout(n);
  6344. }, function () {
  6345. t(new Error("Failed to open database!")), clearTimeout(n);
  6346. }, function () {
  6347. _this2.db && e(_this2.db), clearTimeout(n), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable));
  6348. });
  6349. }));
  6350. case 1:
  6351. case "end":
  6352. return _context2.stop();
  6353. }
  6354. }
  6355. }, _callee2, this);
  6356. }));
  6357. function checkAndOpenDatabase() {
  6358. return _checkAndOpenDatabase.apply(this, arguments);
  6359. }
  6360. return checkAndOpenDatabase;
  6361. }()
  6362. }, {
  6363. key: "openDatabase",
  6364. value: function openDatabase(e, t, r, n, o) {
  6365. var _this3 = this;
  6366. if (this.isCreatingTable) return;
  6367. this.isCreatingTable = !0, logger.info(e, t);
  6368. var a = window.indexedDB.open(e, t),
  6369. s = this.tableName();
  6370. a.onsuccess = function (l) {
  6371. _this3.db = a.result, logger.info("IndexedDb ".concat(e, " is opened.")), _this3.db.objectStoreNames.contains(s) && (_this3.isCreatingTable = !1), r && r(l);
  6372. }, a.onerror = function (l) {
  6373. var u;
  6374. 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);
  6375. }, a.onupgradeneeded = function (l) {
  6376. var u = l.target.result,
  6377. c = _this3.index();
  6378. logger.info("Creating table ".concat(s, "."));
  6379. var h = u.objectStoreNames.contains(s);
  6380. if (h) h = u.transaction([s], "readwrite").objectStore(s);else {
  6381. var f = _this3.keyPath();
  6382. h = u.createObjectStore(s, {
  6383. keyPath: f
  6384. });
  6385. }
  6386. c.map(function (f) {
  6387. h.createIndex(f, f, {
  6388. unique: !1
  6389. });
  6390. }), _this3.isCreatingTable = !1, logger.info("Table ".concat(s, " opened")), o && o(l);
  6391. };
  6392. }
  6393. }, {
  6394. key: "add",
  6395. value: function () {
  6396. var _add = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  6397. var t, o;
  6398. return regenerator.wrap(function _callee3$(_context3) {
  6399. while (1) {
  6400. switch (_context3.prev = _context3.next) {
  6401. case 0:
  6402. t = this.tableName();
  6403. _context3.next = 3;
  6404. return this.checkAndOpenDatabase();
  6405. case 3:
  6406. o = _context3.sent.transaction([t], "readwrite").objectStore(t).add(e);
  6407. return _context3.abrupt("return", new Promise(function (a, s) {
  6408. o.onsuccess = function (l) {
  6409. a(l);
  6410. }, o.onerror = function (l) {
  6411. var u;
  6412. logger.error((u = l.srcElement) == null ? void 0 : u.error), s(l);
  6413. };
  6414. }));
  6415. case 5:
  6416. case "end":
  6417. return _context3.stop();
  6418. }
  6419. }
  6420. }, _callee3, this);
  6421. }));
  6422. function add(_x2) {
  6423. return _add.apply(this, arguments);
  6424. }
  6425. return add;
  6426. }()
  6427. }, {
  6428. key: "put",
  6429. value: function () {
  6430. var _put = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  6431. var t, o;
  6432. return regenerator.wrap(function _callee4$(_context4) {
  6433. while (1) {
  6434. switch (_context4.prev = _context4.next) {
  6435. case 0:
  6436. t = this.tableName();
  6437. _context4.next = 3;
  6438. return this.checkAndOpenDatabase();
  6439. case 3:
  6440. o = _context4.sent.transaction([t], "readwrite").objectStore(t).put(e);
  6441. return _context4.abrupt("return", new Promise(function (a, s) {
  6442. o.onsuccess = function (l) {
  6443. a(l);
  6444. }, o.onerror = function (l) {
  6445. var u;
  6446. logger.error("db put error", (u = l.srcElement) == null ? void 0 : u.error), s(l);
  6447. };
  6448. }));
  6449. case 5:
  6450. case "end":
  6451. return _context4.stop();
  6452. }
  6453. }
  6454. }, _callee4, this);
  6455. }));
  6456. function put(_x3) {
  6457. return _put.apply(this, arguments);
  6458. }
  6459. return put;
  6460. }()
  6461. }, {
  6462. key: "delete",
  6463. value: function _delete(e, t, r) {
  6464. var n = this.tableName();
  6465. this.checkAndOpenDatabase().then(function (o) {
  6466. var s = o.transaction([n], "readwrite").objectStore(n).delete(e);
  6467. s.onsuccess = t, s.onerror = r;
  6468. });
  6469. }
  6470. }, {
  6471. key: "update",
  6472. value: function update() {
  6473. this.checkAndOpenDatabase().then(function (e) {});
  6474. }
  6475. }, {
  6476. key: "getAllKeys",
  6477. value: function () {
  6478. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  6479. var e, t;
  6480. return regenerator.wrap(function _callee5$(_context5) {
  6481. while (1) {
  6482. switch (_context5.prev = _context5.next) {
  6483. case 0:
  6484. e = this.tableName();
  6485. _context5.next = 3;
  6486. return this.checkAndOpenDatabase();
  6487. case 3:
  6488. t = _context5.sent;
  6489. return _context5.abrupt("return", new Promise(function (r, n) {
  6490. var a = t.transaction([e], "readonly").objectStore(e).getAllKeys();
  6491. a.onsuccess = function (s) {
  6492. r(s.target.result);
  6493. }, a.onerror = function (s) {
  6494. logger.error("db getAllKeys error", s), n(s);
  6495. };
  6496. }));
  6497. case 5:
  6498. case "end":
  6499. return _context5.stop();
  6500. }
  6501. }
  6502. }, _callee5, this);
  6503. }));
  6504. function getAllKeys() {
  6505. return _getAllKeys.apply(this, arguments);
  6506. }
  6507. return getAllKeys;
  6508. }()
  6509. }, {
  6510. key: "query",
  6511. value: function () {
  6512. var _query = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t) {
  6513. var r, n;
  6514. return regenerator.wrap(function _callee6$(_context6) {
  6515. while (1) {
  6516. switch (_context6.prev = _context6.next) {
  6517. case 0:
  6518. r = this.tableName();
  6519. _context6.next = 3;
  6520. return this.checkAndOpenDatabase();
  6521. case 3:
  6522. n = _context6.sent;
  6523. return _context6.abrupt("return", new Promise(function (o, a) {
  6524. var u = n.transaction([r], "readonly").objectStore(r).index(e).get(t);
  6525. u.onsuccess = function (c) {
  6526. var f;
  6527. var h = (f = c == null ? void 0 : c.target) == null ? void 0 : f.result;
  6528. o && o(h);
  6529. }, u.onerror = function (c) {
  6530. logger.error("db query error", c), a(c);
  6531. };
  6532. }));
  6533. case 5:
  6534. case "end":
  6535. return _context6.stop();
  6536. }
  6537. }
  6538. }, _callee6, this);
  6539. }));
  6540. function query(_x4, _x5) {
  6541. return _query.apply(this, arguments);
  6542. }
  6543. return query;
  6544. }()
  6545. }, {
  6546. key: "sleep",
  6547. value: function () {
  6548. var _sleep = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  6549. return regenerator.wrap(function _callee7$(_context7) {
  6550. while (1) {
  6551. switch (_context7.prev = _context7.next) {
  6552. case 0:
  6553. return _context7.abrupt("return", new Promise(function (t) {
  6554. setTimeout(function () {
  6555. t("");
  6556. }, e);
  6557. }));
  6558. case 1:
  6559. case "end":
  6560. return _context7.stop();
  6561. }
  6562. }
  6563. }, _callee7);
  6564. }));
  6565. function sleep(_x6) {
  6566. return _sleep.apply(this, arguments);
  6567. }
  6568. return sleep;
  6569. }()
  6570. }]);
  6571. return BaseTable;
  6572. }();
  6573. 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); }; }
  6574. 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; } }
  6575. var ModelTable = /*#__PURE__*/function (_BaseTable) {
  6576. _inherits(ModelTable, _BaseTable);
  6577. var _super = _createSuper$3(ModelTable);
  6578. function ModelTable() {
  6579. _classCallCheck(this, ModelTable);
  6580. return _super.call(this, "XverseDatabase", 1);
  6581. }
  6582. _createClass(ModelTable, [{
  6583. key: "tableName",
  6584. value: function tableName() {
  6585. return "models";
  6586. }
  6587. }, {
  6588. key: "index",
  6589. value: function index() {
  6590. return ["url"];
  6591. }
  6592. }, {
  6593. key: "keyPath",
  6594. value: function keyPath() {
  6595. return "url";
  6596. }
  6597. }]);
  6598. return ModelTable;
  6599. }(BaseTable);
  6600. var modelTable = new ModelTable();
  6601. 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); }; }
  6602. 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; } }
  6603. var Http = /*#__PURE__*/function (_EventEmitter) {
  6604. _inherits(Http, _EventEmitter);
  6605. var _super = _createSuper$2(Http);
  6606. function Http() {
  6607. _classCallCheck(this, Http);
  6608. return _super.apply(this, arguments);
  6609. }
  6610. _createClass(Http, [{
  6611. key: "get",
  6612. value: function () {
  6613. var _get = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(_ref) {
  6614. var e, _ref$useIndexedDb, t, _ref$timeout, r, n, _ref$isOutPutObjectUR, o, a, s, l;
  6615. return regenerator.wrap(function _callee2$(_context2) {
  6616. while (1) {
  6617. switch (_context2.prev = _context2.next) {
  6618. case 0:
  6619. e = _ref.url, _ref$useIndexedDb = _ref.useIndexedDb, t = _ref$useIndexedDb === void 0 ? !1 : _ref$useIndexedDb, _ref$timeout = _ref.timeout, r = _ref$timeout === void 0 ? 15e3 : _ref$timeout, n = _ref.key, _ref$isOutPutObjectUR = _ref.isOutPutObjectURL, o = _ref$isOutPutObjectUR === void 0 ? !0 : _ref$isOutPutObjectUR;
  6620. if (!(Xverse.NO_CACHE !== void 0 && (t = !Xverse.NO_CACHE), t)) {
  6621. _context2.next = 25;
  6622. break;
  6623. }
  6624. if (!isIndexedDbSupported()) {
  6625. _context2.next = 22;
  6626. break;
  6627. }
  6628. window.performance.now();
  6629. a = null;
  6630. _context2.prev = 5;
  6631. _context2.next = 8;
  6632. return modelTable.query("url", e);
  6633. case 8:
  6634. a = _context2.sent;
  6635. _context2.next = 14;
  6636. break;
  6637. case 11:
  6638. _context2.prev = 11;
  6639. _context2.t0 = _context2["catch"](5);
  6640. return _context2.abrupt("return", (logger.debug(_context2.t0), logger.warn("cache query error", e), Promise.resolve(e)));
  6641. case 14:
  6642. if (!(a && a.model)) {
  6643. _context2.next = 19;
  6644. break;
  6645. }
  6646. s = dataURItoBlob(a.model), l = Promise.resolve(o ? URL.createObjectURL(s) : s);
  6647. return _context2.abrupt("return", (window.performance.now(), l));
  6648. case 19:
  6649. return _context2.abrupt("return", this.request({
  6650. url: e,
  6651. timeout: r,
  6652. contentType: "blob",
  6653. key: n
  6654. }).then( /*#__PURE__*/function () {
  6655. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(s) {
  6656. var l;
  6657. return regenerator.wrap(function _callee$(_context) {
  6658. while (1) {
  6659. switch (_context.prev = _context.next) {
  6660. case 0:
  6661. _context.next = 2;
  6662. return blobToDataURI(s.response);
  6663. case 2:
  6664. l = _context.sent;
  6665. _context.prev = 3;
  6666. _context.next = 6;
  6667. return modelTable.put({
  6668. url: e,
  6669. model: l
  6670. });
  6671. case 6:
  6672. _context.next = 11;
  6673. break;
  6674. case 8:
  6675. _context.prev = 8;
  6676. _context.t0 = _context["catch"](3);
  6677. logger.warn("unable to add data to indexedDB", _context.t0);
  6678. case 11:
  6679. return _context.abrupt("return", Promise.resolve(o ? URL.createObjectURL(s.response) : s.response));
  6680. case 12:
  6681. case "end":
  6682. return _context.stop();
  6683. }
  6684. }
  6685. }, _callee, null, [[3, 8]]);
  6686. }));
  6687. return function (_x2) {
  6688. return _ref2.apply(this, arguments);
  6689. };
  6690. }()));
  6691. case 20:
  6692. _context2.next = 23;
  6693. break;
  6694. case 22:
  6695. return _context2.abrupt("return", this.request({
  6696. url: e,
  6697. timeout: r,
  6698. contentType: "blob",
  6699. key: n
  6700. }).then(function (a) {
  6701. var s = a.response;
  6702. return Promise.resolve(o ? URL.createObjectURL(s) : s);
  6703. }).catch(function (a) {
  6704. return Promise.reject(a);
  6705. }));
  6706. case 23:
  6707. _context2.next = 26;
  6708. break;
  6709. case 25:
  6710. return _context2.abrupt("return", this.request({
  6711. url: e,
  6712. timeout: r,
  6713. key: n
  6714. }).then(function (a) {
  6715. return a.getResponseHeader("content-type") === "application/json" ? Promise.resolve(JSON.parse(a.responseText)) : Promise.resolve(a.responseText);
  6716. }));
  6717. case 26:
  6718. case "end":
  6719. return _context2.stop();
  6720. }
  6721. }
  6722. }, _callee2, this, [[5, 11]]);
  6723. }));
  6724. function get(_x) {
  6725. return _get.apply(this, arguments);
  6726. }
  6727. return get;
  6728. }()
  6729. }, {
  6730. key: "request",
  6731. value: function request(e) {
  6732. var _this = this;
  6733. var _e$timeout = e.timeout,
  6734. t = _e$timeout === void 0 ? 3e4 : _e$timeout,
  6735. r = e.contentType;
  6736. e.key;
  6737. var o = e.onRequestStart,
  6738. a = e.url;
  6739. return new Promise(function (s, l) {
  6740. window.performance.now();
  6741. var u = new XMLHttpRequest();
  6742. r && (u.responseType = r), u.timeout = t, u.addEventListener("readystatechange", function () {
  6743. if (u.readyState == 4) {
  6744. if (u.status == 200) return window.performance.now(), _this.emit("loadend", {
  6745. message: "request ".concat(a, " load success")
  6746. }), s(u);
  6747. {
  6748. var c = "Unable to load the request ".concat(a);
  6749. return _this.emit("error", {
  6750. message: c
  6751. }), logger.error(c), l(c);
  6752. }
  6753. }
  6754. }), o && o(u), u.open("GET", a), u.send();
  6755. });
  6756. }
  6757. }]);
  6758. return Http;
  6759. }(EventEmitter); // const http = new Http();
  6760. var Logger1 = /*#__PURE__*/function () {
  6761. function Logger1(e) {
  6762. _classCallCheck(this, Logger1);
  6763. E(this, "module");
  6764. this.module = e;
  6765. }
  6766. _createClass(Logger1, [{
  6767. key: "debug",
  6768. value: function debug() {
  6769. var _Logger1$instance;
  6770. return (_Logger1$instance = Logger1.instance).debug.apply(_Logger1$instance, arguments);
  6771. }
  6772. }, {
  6773. key: "info",
  6774. value: function info() {
  6775. var _Logger1$instance2;
  6776. return (_Logger1$instance2 = Logger1.instance).info.apply(_Logger1$instance2, arguments);
  6777. }
  6778. }, {
  6779. key: "warn",
  6780. value: function warn() {
  6781. var _Logger1$instance3;
  6782. return (_Logger1$instance3 = Logger1.instance).warn.apply(_Logger1$instance3, arguments);
  6783. }
  6784. }, {
  6785. key: "error",
  6786. value: function error() {
  6787. var _Logger1$instance4;
  6788. return (_Logger1$instance4 = Logger1.instance).error.apply(_Logger1$instance4, arguments);
  6789. }
  6790. }], [{
  6791. key: "setLogger",
  6792. value: function setLogger(e) {
  6793. Logger1.instance = e;
  6794. }
  6795. }]);
  6796. return Logger1;
  6797. }();
  6798. var XCameraComponent = /*#__PURE__*/function () {
  6799. function XCameraComponent(e, t, r) {
  6800. var _this = this;
  6801. _classCallCheck(this, XCameraComponent);
  6802. E(this, "maincameraRotLimitObserver", null);
  6803. E(this, "mainCamera");
  6804. E(this, "cgCamera");
  6805. E(this, "saveCameraPose");
  6806. E(this, "_cameraPose");
  6807. E(this, "scene");
  6808. E(this, "canvas");
  6809. E(this, "yuvInfo");
  6810. E(this, "forceKeepVertical", !1);
  6811. E(this, "initCamera", function (e) {
  6812. var _e$maxZ = e.maxZ,
  6813. t = _e$maxZ === void 0 ? 1e4 : _e$maxZ,
  6814. _e$minZ = e.minZ,
  6815. r = _e$minZ === void 0 ? .1 : _e$minZ,
  6816. _e$angularSensibility = e.angularSensibility,
  6817. n = _e$angularSensibility === void 0 ? 2e3 : _e$angularSensibility;
  6818. _this.mainCamera = new BABYLON.FreeCamera("camera_main", new BABYLON.Vector3(0, 1e3, 0), _this.scene), _this.mainCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA, _this.mainCamera.speed = .1, _this.mainCamera.angularSensibility = n, _this.mainCamera.setTarget(new BABYLON.Vector3(0, 1010, 0)), _this.mainCamera.minZ = r, _this.mainCamera.fov = Math.PI * _this.yuvInfo.fov / 180, _this.mainCamera.maxZ = t, _this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED, _this.cgCamera = new BABYLON.FreeCamera("camera_temp", new BABYLON.Vector3(0, 1e3, 0), _this.scene), _this.cgCamera.mode = BABYLON.Camera.PERSPECTIVE_CAMERA, _this.cgCamera.speed = .1, _this.cgCamera.setTarget(new BABYLON.Vector3(0, 1010, 0)), _this.cgCamera.maxZ = t, _this.cgCamera.minZ = r, _this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED, _this.cameraFovChange(_this.yuvInfo);
  6819. });
  6820. E(this, "cameraFovChange", function (e) {
  6821. _this.yuvInfo = e;
  6822. var t = e.width,
  6823. r = e.height,
  6824. n = _this.canvas.width,
  6825. o = _this.canvas.height,
  6826. a = e.fov;
  6827. if (_this.forceKeepVertical == !0) {
  6828. var s = t / (2 * Math.tan(Math.PI * a / 360)),
  6829. l = 2 * Math.atan(r / (2 * s));
  6830. _this.mainCamera.fov = l, _this.cgCamera.fov = l, _this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED, _this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED;
  6831. } else if (_this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED, _this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED, n / o < t / r && _this.mainCamera.fov) {
  6832. var _s = o,
  6833. _l = n,
  6834. u = _s * t / r / (2 * Math.tan(a * Math.PI / 360)),
  6835. c = 2 * Math.atan(_l / (2 * u));
  6836. _this.mainCamera.fov = c, _this.cgCamera.fov = c;
  6837. } else _this.mainCamera.fov = Math.PI * a / 180, _this.cgCamera.fov = Math.PI * a / 180;
  6838. });
  6839. E(this, "setCameraPose", function (e) {
  6840. var n;
  6841. var t = ue4Position2Xverse(e.position);
  6842. var r = null;
  6843. e.rotation != null && (r = ue4Rotation2Xverse(e.rotation)), _this._cameraPose = {
  6844. position: t
  6845. }, r != null && (_this._cameraPose.rotation = r), _this.scene.activeCamera === _this.mainCamera && !((n = _this.mainCamera) != null && n.isDisposed()) && _this._setCamPositionRotation(_this.mainCamera, _this._cameraPose);
  6846. });
  6847. E(this, "_setCamPositionRotation", function (e, t) {
  6848. var r, n;
  6849. t.position && (e.position = (r = t.position) == null ? void 0 : r.clone()), t.rotation && (e.rotation = (n = t.rotation) == null ? void 0 : n.clone());
  6850. });
  6851. E(this, "switchCamera", function (e) {
  6852. var t;
  6853. (t = _this.scene.activeCamera) == null || t.detachControl(_this.canvas), _this.scene.activeCamera = e;
  6854. });
  6855. E(this, "reCalXYZRot", function (e, t) {
  6856. return e = e % (2 * Math.PI), Math.abs(t - e) >= Math.PI && (e = e - 2 * Math.PI), e;
  6857. });
  6858. E(this, "_moveCam", function (e, t, r, n, o, a, s, l) {
  6859. var u = function u(v, y, b) {
  6860. return v.x = _this.reCalXYZRot(v.x, y.x), v.y = _this.reCalXYZRot(v.y, y.y), v.z = _this.reCalXYZRot(v.z, y.z), new BABYLON.Vector3((y.x - v.x) * b + v.x, (y.y - v.y) * b + v.y, (y.z - v.z) * b + v.z);
  6861. },
  6862. c = function c(v, y, b) {
  6863. return new BABYLON.Vector3((y.x - v.x) * b + v.x, (y.y - v.y) * b + v.y, (y.z - v.z) * b + v.z);
  6864. },
  6865. h = new Animation("myAnimation1", "position", s, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);
  6866. var f = [],
  6867. d = t,
  6868. _ = r;
  6869. for (var v = 0; v < a; ++v) {
  6870. f.push({
  6871. frame: v,
  6872. value: c(d, _, v / a)
  6873. });
  6874. }
  6875. f.push({
  6876. frame: f.length,
  6877. value: c(d, _, 1)
  6878. }), h.setKeys(f);
  6879. var g = new Animation("myAnimation2", "rotation", s, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);
  6880. f = [], d = n, _ = o;
  6881. for (var _v = 0; _v < a; ++_v) {
  6882. f.push({
  6883. frame: _v,
  6884. value: u(d, _, _v / a)
  6885. });
  6886. }
  6887. f.push({
  6888. frame: f.length,
  6889. value: u(d, _, 1)
  6890. }), g.setKeys(f), e.animations.push(g), e.animations.push(h);
  6891. var m = _this.scene.beginAnimation(e, 0, a, !1);
  6892. m.onAnimationEnd = function () {
  6893. l(), m.stop(), m.animationStarted = !1;
  6894. };
  6895. });
  6896. this.scene = t, this.canvas = e, this.yuvInfo = r.yuvInfo, r.forceKeepVertical != null && (this.forceKeepVertical = r.forceKeepVertical), this.initCamera(r.cameraParam);
  6897. }
  6898. _createClass(XCameraComponent, [{
  6899. key: "MainCamera",
  6900. get: function get() {
  6901. return this.mainCamera;
  6902. }
  6903. }, {
  6904. key: "CgCamera",
  6905. get: function get() {
  6906. return this.cgCamera;
  6907. }
  6908. }, {
  6909. key: "getCameraHorizonFov",
  6910. value: function getCameraHorizonFov() {
  6911. return this.mainCamera.fovMode == BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED ? this.mainCamera.fov : Math.PI * this.yuvInfo.fov / 180;
  6912. }
  6913. }, {
  6914. key: "changeMainCameraRotationDamping",
  6915. value: function changeMainCameraRotationDamping() {
  6916. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2e3;
  6917. this.mainCamera.angularSensibility = e;
  6918. }
  6919. }, {
  6920. key: "removeMainCameraRotationLimit",
  6921. value: function removeMainCameraRotationLimit() {
  6922. this.maincameraRotLimitObserver != null && this.mainCamera.onAfterCheckInputsObservable.remove(this.maincameraRotLimitObserver);
  6923. }
  6924. }, {
  6925. key: "setMainCameraInfo",
  6926. value: function setMainCameraInfo(e) {
  6927. var _e$maxZ2 = e.maxZ,
  6928. t = _e$maxZ2 === void 0 ? 1e4 : _e$maxZ2,
  6929. _e$minZ2 = e.minZ,
  6930. r = _e$minZ2 === void 0 ? .1 : _e$minZ2,
  6931. _e$angularSensibility2 = e.angularSensibility,
  6932. n = _e$angularSensibility2 === void 0 ? 2e3 : _e$angularSensibility2;
  6933. this.mainCamera.maxZ = t, this.mainCamera.minZ = r, this.mainCamera.angularSensibility = n;
  6934. }
  6935. }, {
  6936. key: "getMainCameraInfo",
  6937. value: function getMainCameraInfo() {
  6938. return {
  6939. maxZ: this.mainCamera.maxZ,
  6940. minZ: this.mainCamera.minZ,
  6941. angularSensibility: this.mainCamera.angularSensibility
  6942. };
  6943. }
  6944. }, {
  6945. key: "_limitAngle",
  6946. value: function _limitAngle(e, t) {
  6947. return Math.abs(Math.abs(t[0] - t[1]) - 360) < 1e-6 || (e = (e % 360 + 360) % 360, t[0] = (t[0] % 360 + 360) % 360, t[1] = (t[1] % 360 + 360) % 360, t[0] > t[1] ? e > t[1] && e < t[0] && (Math.abs(e - t[0]) < Math.abs(e - t[1]) ? e = t[0] : e = t[1]) : e < t[0] ? e = t[0] : e > t[1] && (e = t[1])), e;
  6948. }
  6949. }, {
  6950. key: "setMainCameraRotationLimit",
  6951. value: function setMainCameraRotationLimit(e, t) {
  6952. var _this2 = this;
  6953. this.maincameraRotLimitObserver != null && this.removeMainCameraRotationLimit();
  6954. var r = this.mainCamera,
  6955. n = e.yaw,
  6956. o = e.pitch,
  6957. a = e.roll,
  6958. s = t.yaw,
  6959. l = t.pitch,
  6960. u = t.roll;
  6961. if (s < 0 || l < 0 || u < 0) throw new Error("\u76F8\u673A\u65CB\u8F6C\u9650\u5236\u53EA\u80FD\u8BBE\u7F6E\u4E3A\u5927\u4E8E0");
  6962. var c = [o - l, o + l],
  6963. h = [n - s, n + s],
  6964. f = [a - u, a + u];
  6965. this.maincameraRotLimitObserver = r.onAfterCheckInputsObservable.add(function () {
  6966. var _xverseRotation2Ue = xverseRotation2Ue4(r.rotation),
  6967. d = _xverseRotation2Ue.pitch,
  6968. _ = _xverseRotation2Ue.yaw,
  6969. g = _xverseRotation2Ue.roll;
  6970. d = _this2._limitAngle(d, c), _ = _this2._limitAngle(_, h), g = _this2._limitAngle(g, f), r.rotation = ue4Rotation2Xverse({
  6971. pitch: d,
  6972. yaw: _,
  6973. roll: g
  6974. });
  6975. });
  6976. }
  6977. }, {
  6978. key: "setMainCameraRotationLimitByAnchor",
  6979. value: function setMainCameraRotationLimitByAnchor(e, t, r) {
  6980. this.maincameraRotLimitObserver != null && this.removeMainCameraRotationLimit();
  6981. var n = this.mainCamera,
  6982. o = ue4Rotation2Xverse_mesh(t),
  6983. a = ue4Rotation2Xverse_mesh(r);
  6984. a != null && o != null && e.mesh != null && (this.maincameraRotLimitObserver = n.onAfterCheckInputsObservable.add(function () {
  6985. var s = e.mesh.rotation;
  6986. r.yaw > 0 && (n.rotation.y <= s.y - a.y + o.y ? n.rotation.y = s.y - a.y + o.y : n.rotation.y >= s.y + a.y + o.y && (n.rotation.y = s.y + a.y + o.y)), r.pitch > 0 && (n.rotation.x <= s.x - a.x + o.x ? n.rotation.x = s.x - a.x + o.x : n.rotation.x >= s.x + a.x + o.x && (n.rotation.x = s.x + a.x + o.x)), r.roll > 0 && (n.rotation.z <= s.z - a.z + o.z ? n.rotation.z = s.z - a.z + o.z : n.rotation.z >= s.z + a.z + o.z && (n.rotation.z = s.z + a.z + o.z));
  6987. }));
  6988. }
  6989. }, {
  6990. key: "getCameraPose",
  6991. value: function getCameraPose() {
  6992. var e = xversePosition2Ue4({
  6993. x: this.mainCamera.position.x,
  6994. y: this.mainCamera.position.y,
  6995. z: this.mainCamera.position.z
  6996. }),
  6997. t = xverseRotation2Ue4({
  6998. x: this.mainCamera.rotation.x,
  6999. y: this.mainCamera.rotation.y,
  7000. z: this.mainCamera.rotation.z
  7001. });
  7002. return {
  7003. position: e,
  7004. rotation: t
  7005. };
  7006. }
  7007. }, {
  7008. key: "changeCameraFov",
  7009. value: function changeCameraFov(e, t) {
  7010. this.mainCamera.fov = e, t != null && (this.mainCamera.fovMode = t == 0 ? BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED : BABYLON.Camera.FOVMODE_VERTICAL_FIXED);
  7011. }
  7012. }, {
  7013. key: "controlCameraRotation",
  7014. value: function controlCameraRotation(e, t) {
  7015. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .5;
  7016. var n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : .5;
  7017. var o = {
  7018. pitch: n * t * 180,
  7019. yaw: r * e * 180,
  7020. roll: 0
  7021. };
  7022. this.addRot(o);
  7023. }
  7024. }, {
  7025. key: "addRot",
  7026. value: function addRot(e) {
  7027. var t = this.mainCamera,
  7028. r = ue4Rotation2Xverse_mesh(e);
  7029. r != null && t.rotation.addInPlace(r);
  7030. }
  7031. }, {
  7032. key: "getCameraFov",
  7033. value: function getCameraFov() {
  7034. return this.mainCamera.fov;
  7035. }
  7036. }, {
  7037. key: "allowMainCameraController",
  7038. value: function allowMainCameraController() {
  7039. this.mainCamera.attachControl(this.canvas, !0);
  7040. }
  7041. }, {
  7042. key: "detachMainCameraController",
  7043. value: function detachMainCameraController() {
  7044. this.mainCamera.detachControl(this.canvas);
  7045. }
  7046. }, {
  7047. key: "forceChangeSavedCameraPose",
  7048. value: function forceChangeSavedCameraPose(e) {
  7049. this.saveCameraPose != null && (e.position != null && (this.saveCameraPose.position = ue4Position2Xverse(e.position)), e.rotation != null && (this.saveCameraPose.rotation = ue4Rotation2Xverse(e.rotation)));
  7050. }
  7051. }, {
  7052. key: "changeToFirstPersonView",
  7053. value: function changeToFirstPersonView(e) {
  7054. this.saveCameraPose = {
  7055. position: this.mainCamera.position.clone(),
  7056. rotation: this.mainCamera.rotation.clone()
  7057. }, this.mainCamera.attachControl(this.canvas, !0), e.position != null && (this.mainCamera.position = ue4Position2Xverse(e.position)), e.rotation != null && (this.mainCamera.rotation = ue4Rotation2Xverse(e.rotation));
  7058. }
  7059. }, {
  7060. key: "changeToThirdPersonView",
  7061. value: function changeToThirdPersonView() {
  7062. this.saveCameraPose != null && this.mainCamera != null && (this.mainCamera.position = this.saveCameraPose.position.clone(), this.mainCamera.rotation = this.saveCameraPose.rotation.clone(), this.mainCamera.detachControl(this.canvas));
  7063. }
  7064. }, {
  7065. key: "switchToMainCamera",
  7066. value: function switchToMainCamera() {
  7067. this.switchCamera(this.mainCamera);
  7068. }
  7069. }, {
  7070. key: "switchToCgCamera",
  7071. value: function switchToCgCamera() {
  7072. this.switchCamera(this.cgCamera);
  7073. }
  7074. }, {
  7075. key: "moveMainCamera",
  7076. value: function moveMainCamera(e, t, r, n, o) {
  7077. this._moveCam(this.mainCamera, this.mainCamera.position, e, this.mainCamera.rotation, t, r, n, o);
  7078. }
  7079. }]);
  7080. return XCameraComponent;
  7081. }();
  7082. var XStaticMeshComponent = /*#__PURE__*/function () {
  7083. function XStaticMeshComponent(e) {
  7084. var _this = this;
  7085. _classCallCheck(this, XStaticMeshComponent);
  7086. E(this, "scene");
  7087. E(this, "_staticmeshes");
  7088. E(this, "_lowModel_group");
  7089. E(this, "_CgPlane");
  7090. E(this, "_rootDir");
  7091. E(this, "_abosoluteUrl");
  7092. E(this, "_partMeshSkinInfo");
  7093. E(this, "_meshInfoJson");
  7094. E(this, "_orijson");
  7095. E(this, "_notUsedRegionLists");
  7096. E(this, "_meshInfoKeys");
  7097. E(this, "_currentUpdateRegionCount");
  7098. E(this, "_currentMeshUsedLod");
  7099. E(this, "_currentPartGroup");
  7100. E(this, "_allowRegionUpdate");
  7101. E(this, "_allowRegionForceLod");
  7102. E(this, "_forceLod");
  7103. E(this, "_scenemanager");
  7104. E(this, "regionIdInCamera");
  7105. E(this, "regionIdInCameraConst");
  7106. E(this, "_cameraInRegionId");
  7107. E(this, "_meshVis");
  7108. E(this, "_doMeshVisChangeNumber");
  7109. E(this, "_meshVisTypeName");
  7110. E(this, "_visCheckDurationFrameNumber");
  7111. E(this, "_regionLodRule");
  7112. E(this, "reg_staticmesh_partupdate", function () {
  7113. if (_this._allowRegionUpdate && (_this.scene.getFrameId(), _this._meshUpdateFrame()), _this._allowRegionForceLod) {
  7114. _this.scene.getFrameId() % 2 == 0 && _this.setOneRegionLod(_this._meshInfoKeys[_this._currentUpdateRegionCount % _this._meshInfoKeys.length].toString(), _this._forceLod);
  7115. var t = !0;
  7116. var r = Array.from(_this._currentMeshUsedLod.keys());
  7117. if (r.length > 0) {
  7118. for (var n = 0; n < r.length; ++n) {
  7119. _this._currentMeshUsedLod.get(r[n]) != _this._forceLod && (t = !1);
  7120. }
  7121. t && (_this._allowRegionForceLod = !1);
  7122. }
  7123. }
  7124. });
  7125. E(this, "setMeshInfo", function (e) {
  7126. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
  7127. _this._abosoluteUrl != e && (_this._abosoluteUrl.length > 0 && _this.deleteLastRegionMesh(), _this._partMeshSkinInfo = t, _this._abosoluteUrl = e, _this._rootDir = _this._abosoluteUrl.slice(0, -4) + "/", _this.parseJson(_this._rootDir + "meshInfo.json").then(function () {
  7128. _this.startMeshUpdate();
  7129. }));
  7130. });
  7131. E(this, "_meshUpdateFrame", function () {
  7132. {
  7133. var _e = _this._meshInfoKeys[_this._currentUpdateRegionCount % _this._meshInfoKeys.length];
  7134. var t = !0;
  7135. var r = 3;
  7136. if (_this._scenemanager != null && _this._scenemanager.cameraComponent != null) {
  7137. var n = _this._getMainPlayerPosition();
  7138. if (n != null) {
  7139. if (_this._cameraInRegionId >= 0) {
  7140. var a = _this.getRegionIdWhichIncludeCamera(n);
  7141. (_this._cameraInRegionId != a || _this.regionIdInCamera.length == 0) && (_this._cameraInRegionId = a, _this.regionIdInCamera = _this._getNeighborId(_this._cameraInRegionId.toString()), _this.regionIdInCameraConst = _this.regionIdInCamera.slice());
  7142. var s = _this.regionIdInCamera.pop();
  7143. for (; s != null;) {
  7144. if (_this._notUsedRegionLists.indexOf(s) >= 0) s = _this.regionIdInCamera.pop();else break;
  7145. }
  7146. s != null && (_e = s.toString());
  7147. } else _this._cameraInRegionId = _this.getRegionIdWhichIncludeCamera(n);
  7148. if (_this._currentMeshUsedLod.size == 0 || _this._notUsedRegionLists.indexOf(parseInt(_e)) >= 0) {
  7149. _e = _this._cameraInRegionId.toString();
  7150. var _a = _this._getNeighborId(_e);
  7151. for (; _a.length == 0 && (_e = _this.getNearestRegionIdWithCamera(n).toString()), _this._notUsedRegionLists.indexOf(parseInt(_e)) >= 0;) {
  7152. _e = _a.pop().toString();
  7153. }
  7154. }
  7155. var o = _this._meshInfoJson[_this._cameraInRegionId.toString()].lod;
  7156. r = 3, _this._cameraInRegionId.toString() == _e ? r = _this._regionLodRule[0] : o[0].indexOf(parseInt(_e)) >= 0 ? r = _this._regionLodRule[1] : o[1].indexOf(parseInt(_e)) >= 0 ? r = _this._regionLodRule[2] : o[2].indexOf(parseInt(_e)) >= 0 ? r = _this._regionLodRule[3] : r = _this._regionLodRule[4];
  7157. }
  7158. }
  7159. _this.setOneRegionLod(_e, r, t), _this.updateRegionNotInLocalNeighbor(), _this.cleanRootNodes();
  7160. }
  7161. });
  7162. E(this, "updateRegionNotInLocalNeighbor", function () {
  7163. Array.from(_this._currentMeshUsedLod.keys()).forEach(function (t) {
  7164. _this.regionIdInCameraConst.indexOf(parseInt(t)) < 0 && _this.setOneRegionLod(t, -1);
  7165. });
  7166. });
  7167. E(this, "cleanRootNodes", function () {
  7168. if (_this.scene.getFrameId() % 3 == 0) {
  7169. var _e2 = [];
  7170. _this.scene.rootNodes.forEach(function (t) {
  7171. (t.getClassName() == "TransformNode" && t.getChildren().length == 0 || t.getClassName() == "Mesh" && t.name == "__root__" && t.getChildren().length == 0) && _e2.push(t);
  7172. }), _e2.forEach(function (t) {
  7173. t.dispose();
  7174. });
  7175. }
  7176. });
  7177. E(this, "setOneRegionLod", function (e, t) {
  7178. _this._currentUpdateRegionCount++;
  7179. var n = _this._calHashCode(_this._rootDir),
  7180. o = "region_" + n + "_" + e;
  7181. if (t < 0) {
  7182. _this._currentMeshUsedLod.has(e) && (_this._currentMeshUsedLod.delete(e), _this._currentPartGroup.delete(o), _this.deleteMeshesByCustomProperty("group", "region_" + n + "_" + e));
  7183. return;
  7184. }
  7185. var a = _this._rootDir + e + "_lod" + t + "_xverse.glb",
  7186. s = _this._currentMeshUsedLod.get(e);
  7187. _this._currentPartGroup.add(o), s != null ? s != t && (_this._currentMeshUsedLod.set(e, t), _this._scenemanager.addNewLowPolyMesh({
  7188. url: a,
  7189. group: "region_" + n + "_" + e,
  7190. pick: !0,
  7191. lod: t,
  7192. skinInfo: _this._partMeshSkinInfo
  7193. }, [{
  7194. group: "region_" + n + "_" + e,
  7195. mode: 0
  7196. }])) : (_this._currentMeshUsedLod.set(e, t), _this._scenemanager.addNewLowPolyMesh({
  7197. url: a,
  7198. group: "region_" + n + "_" + e,
  7199. pick: !0,
  7200. lod: t,
  7201. skinInfo: _this._partMeshSkinInfo
  7202. }));
  7203. });
  7204. E(this, "checkPointInView", function (_ref) {
  7205. var e = _ref.x,
  7206. t = _ref.y,
  7207. r = _ref.z;
  7208. var n = ue4Position2Xverse({
  7209. x: e,
  7210. y: t,
  7211. z: r
  7212. });
  7213. if (!n) return !1;
  7214. for (var o = 0; o < 6; o++) {
  7215. if (_this.scene.frustumPlanes[o].dotCoordinate(n) < 0) return !1;
  7216. }
  7217. return !0;
  7218. });
  7219. E(this, "addNewLowPolyMesh", function (e, t, r) {
  7220. if (!e.url.endsWith("glb") && !e.url.startsWith("blob:")) return e.url.endsWith("zip") ? (_this.setMeshInfo(e.url, e.skinInfo), Promise.resolve(!0)) : (logger.error("[Engine] input model path is error! ", e.url), Promise.reject(new XLowpolyModelError("[Engine] input model path is error! " + e.url)));
  7221. {
  7222. var n = e.url;
  7223. return new Promise(function (o, a) {
  7224. return _this._scenemanager.urlTransformer(e.url).then(function (s) {
  7225. e.url = s;
  7226. var l = new XStaticMeshFromOneGltf(_this.scene, e),
  7227. u = Date.now();
  7228. return new Promise(function (c, h) {
  7229. l.loadMesh(r, !0).then(function (f) {
  7230. var d = Date.now();
  7231. if (_this._scenemanager.engineRunTimeStats.timeArray_loadStaticMesh.add(d - u), f == !0) {
  7232. var _ = _this.getLowModelType(e);
  7233. var g = 0;
  7234. if (_this._lowModel_group.has(_) && (g = _this._lowModel_group.get(_).length), r != null && _this._scenemanager.currentShader != null && _this._scenemanager.currentShader.name != r.name && l.setMaterial(_this._scenemanager.currentShader), _this._allowRegionUpdate == !1 && _.startsWith("region_")) l.dispose();else if (_this._staticmeshes.push(l), _this.lowmodelGroupMapAddValue(_, l), t != null && t.length > 0) {
  7235. var m = [];
  7236. for (var v = 0; v < t.length; ++v) {
  7237. m.push(t[v].group), _this.updateLowModelGroup(t[v], _, g);
  7238. }
  7239. }
  7240. _this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - d), c(!0);
  7241. } else h(new XLowpolyModelError("[Engine] after lowmodel error!"));
  7242. }).catch(function (f) {
  7243. logger.error("[Engine] load Mesh [" + n + "] error! " + f), h(new XLowpolyModelError("[Engine] load Mesh [".concat(n, "] error! ").concat(f)));
  7244. });
  7245. });
  7246. }).then(function (s) {
  7247. s == !0 ? (logger.info("[Engine] load Mesh [".concat(n, "] successfully.")), o(!0)) : a(!1);
  7248. }).catch(function (s) {
  7249. logger.error("[Engine] addNewLowPolyMesh [" + n + "] error! " + s), a(new XLowpolyModelError("[Engine] addNewLowPolyMesh [".concat(n, "] error! ").concat(s)));
  7250. });
  7251. });
  7252. }
  7253. });
  7254. E(this, "toggleLowModelVisibility", function (e) {
  7255. var t = e.vis,
  7256. _e$groupName = e.groupName,
  7257. r = _e$groupName === void 0 ? "" : _e$groupName,
  7258. _e$skinInfo = e.skinInfo,
  7259. n = _e$skinInfo === void 0 ? "" : _e$skinInfo;
  7260. _this._meshVis = t, _this._meshVisTypeName = {
  7261. groupName: r,
  7262. skinInfo: n
  7263. }, _this._doMeshVisChangeNumber = 0, r == Te.ALL_MESHES || _this._currentPartGroup.has(r) == !0 || _this._partMeshSkinInfo == n ? t == !1 ? (_this._visCheckDurationFrameNumber = 100, _this.stopMeshUpdate()) : (_this._visCheckDurationFrameNumber = 1, _this.startMeshUpdate()) : _this._visCheckDurationFrameNumber = 1;
  7264. });
  7265. E(this, "reg_staticmesh_visibility", function () {
  7266. if (_this._doMeshVisChangeNumber >= 0) if (_this._doMeshVisChangeNumber < _this._visCheckDurationFrameNumber) {
  7267. if (_this._doMeshVisChangeNumber = _this._doMeshVisChangeNumber + 1, _this._meshVisTypeName.groupName == Te.ALL_MESHES) _this._lowModel_group.forEach(function (e, t) {
  7268. for (var r = 0, n = e.length; r < n; ++r) {
  7269. e[r].toggleVisibility(_this._meshVis);
  7270. }
  7271. });else {
  7272. if (_this._lowModel_group.has(_this._meshVisTypeName.groupName)) for (var _e3 = 0; _e3 < _this._lowModel_group.get(_this._meshVisTypeName.groupName).length; ++_e3) {
  7273. _this._lowModel_group.get(_this._meshVisTypeName.groupName)[_e3].toggleVisibility(_this._meshVis);
  7274. }
  7275. if (_this._meshVisTypeName.skinInfo != "") for (var _e4 = 0; _e4 < _this._staticmeshes.length; ++_e4) {
  7276. _this._staticmeshes[_e4].skinInfo == _this._meshVisTypeName.skinInfo && _this._staticmeshes[_e4].toggleVisibility(_this._meshVis);
  7277. }
  7278. }
  7279. } else _this._meshVis = !0, _this._meshVisTypeName = {
  7280. groupName: "",
  7281. skinInfo: ""
  7282. }, _this._doMeshVisChangeNumber = -1;
  7283. });
  7284. E(this, "_getMeshesByCustomProperty", function (e, t) {
  7285. var r = [];
  7286. return _this._staticmeshes.forEach(function (n) {
  7287. n[e] != null && n[e] == t && (r = r.concat(n.meshes));
  7288. }), r;
  7289. });
  7290. this._lowModel_group = new Map(), this._staticmeshes = [], this._meshInfoJson = null, this._meshInfoKeys = [], this._currentUpdateRegionCount = 0, this._abosoluteUrl = "", this._partMeshSkinInfo = "", this._forceLod = 3, this._allowRegionUpdate = !1, this._allowRegionForceLod = !1, this._currentMeshUsedLod = new Map(), this._currentPartGroup = new Set(), this._scenemanager = e, this.scene = e.Scene, this.regionIdInCamera = [], this.regionIdInCameraConst = [], this._cameraInRegionId = -1, this._rootDir = "", this._meshVis = !0, this._meshVisTypeName = {
  7291. groupName: "",
  7292. skinInfo: ""
  7293. }, this._doMeshVisChangeNumber = -1, this._visCheckDurationFrameNumber = -1, this._regionLodRule = [0, 1, 3, 3, -1], this.initCgLowModel(), this._regionPartLoop();
  7294. }
  7295. _createClass(XStaticMeshComponent, [{
  7296. key: "cameraInRegionId",
  7297. get: function get() {
  7298. return this._cameraInRegionId;
  7299. }
  7300. }, {
  7301. key: "setRegionLodRule",
  7302. value: function setRegionLodRule(e) {
  7303. return e.length != 5 ? !1 : (e.forEach(function (t) {}), this._regionLodRule = e, !0);
  7304. }
  7305. }, {
  7306. key: "lowModel_group",
  7307. get: function get() {
  7308. return this._lowModel_group;
  7309. }
  7310. }, {
  7311. key: "_regionPartLoop",
  7312. value: function _regionPartLoop() {
  7313. this.scene.registerBeforeRender(this.reg_staticmesh_partupdate), this.scene.registerAfterRender(this.reg_staticmesh_visibility);
  7314. }
  7315. }, {
  7316. key: "_globalSearchCameraInWhichRegion",
  7317. value: function _globalSearchCameraInWhichRegion(e, t) {
  7318. var r = -1;
  7319. for (var n = 0; n < t.length; ++n) {
  7320. var o = this._meshInfoJson[t[n].toString()].boundingbox,
  7321. a = o[0],
  7322. s = o[1];
  7323. if (e.x >= a[0] && e.x <= s[0] && e.y >= a[1] && e.y <= s[1] && e.z >= a[2] && e.z <= s[2] || e.x >= s[0] && e.x <= a[0] && e.y >= s[1] && e.y <= a[1] && e.z >= s[2] && e.z <= a[2]) {
  7324. r = parseInt(t[n].toString());
  7325. break;
  7326. }
  7327. }
  7328. return r;
  7329. }
  7330. }, {
  7331. key: "getRegionIdByPosition",
  7332. value: function getRegionIdByPosition(e) {
  7333. return this.getRegionIdWhichIncludeCamera(e);
  7334. }
  7335. }, {
  7336. key: "getRegionIdWhichIncludeCamera",
  7337. value: function getRegionIdWhichIncludeCamera(e) {
  7338. var t = -1;
  7339. if (this._allowRegionUpdate == !1) return t;
  7340. if (this._cameraInRegionId == -1 ? t = this._globalSearchCameraInWhichRegion(e, this._meshInfoKeys) : (t = this._globalSearchCameraInWhichRegion(e, this.regionIdInCameraConst), t == -1 && (t = this._globalSearchCameraInWhichRegion(e, this._meshInfoKeys))), t == -1) {
  7341. var r = 1e7;
  7342. for (var n = 0; n < this._meshInfoKeys.length; ++n) {
  7343. var o = this._meshInfoJson[this._meshInfoKeys[n]].center,
  7344. a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
  7345. r > a && (r = a, t = parseInt(this._meshInfoKeys[n]));
  7346. }
  7347. }
  7348. return t;
  7349. }
  7350. }, {
  7351. key: "getNearestRegionIdWithCamera",
  7352. value: function getNearestRegionIdWithCamera(e) {
  7353. var t = 1,
  7354. r = 1e7;
  7355. for (var n = 0; n < this._meshInfoKeys.length; ++n) {
  7356. if (this._notUsedRegionLists.indexOf(parseInt(this._meshInfoKeys[n])) >= 0) continue;
  7357. var o = this._meshInfoJson[this._meshInfoKeys[n]].center,
  7358. a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
  7359. r > a && (r = a, t = parseInt(this._meshInfoKeys[n]));
  7360. }
  7361. return t;
  7362. }
  7363. }, {
  7364. key: "_getNeighborId",
  7365. value: function _getNeighborId(e) {
  7366. var t = this._meshInfoJson[e].lod;
  7367. var r = [];
  7368. var n = Object.keys(t);
  7369. for (var o = n.length - 1; o >= 0; --o) {
  7370. r = r.concat(t[n[o]]);
  7371. }
  7372. return r.push(parseInt(e)), r;
  7373. }
  7374. }, {
  7375. key: "_getMainPlayerPosition",
  7376. value: function _getMainPlayerPosition() {
  7377. var e = this._scenemanager.cameraComponent.getCameraPose().position,
  7378. t = this._scenemanager.avatarComponent.getMainAvatar();
  7379. if (t != null && t != null) {
  7380. var r = t.position;
  7381. if (r != null) return r;
  7382. }
  7383. return e;
  7384. }
  7385. }, {
  7386. key: "_calHashCode",
  7387. value: function _calHashCode(e) {
  7388. return hashCode(e) + "_" + this._partMeshSkinInfo;
  7389. }
  7390. }, {
  7391. key: "forceAllRegionLod",
  7392. value: function forceAllRegionLod() {
  7393. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3;
  7394. e < 0 && (e = 0), e > 3 && (e = 3), this.stopMeshUpdate(), this._allowRegionForceLod = !0, this._forceLod = e;
  7395. }
  7396. }, {
  7397. key: "deleteLastRegionMesh",
  7398. value: function deleteLastRegionMesh() {
  7399. if (this._rootDir != "") {
  7400. var e = this._calHashCode(this._rootDir);
  7401. this._currentMeshUsedLod.clear(), this._currentPartGroup.clear(), this._meshInfoJson = null, this._meshInfoKeys = [], this._currentUpdateRegionCount = 0, this._orijson = null, this._notUsedRegionLists = [], this._partMeshSkinInfo = "", this._abosoluteUrl = "", this.stopMeshUpdate(), this.deleteMeshesByCustomProperty("group", "region_" + e, !0);
  7402. }
  7403. }
  7404. }, {
  7405. key: "startMeshUpdate",
  7406. value: function startMeshUpdate() {
  7407. this._allowRegionUpdate == !1 && this._meshInfoJson != null && this._abosoluteUrl != "" && this._meshInfoKeys.length > 0 && (this._allowRegionUpdate = !0);
  7408. }
  7409. }, {
  7410. key: "stopMeshUpdate",
  7411. value: function stopMeshUpdate() {
  7412. this._allowRegionUpdate = !1;
  7413. }
  7414. }, {
  7415. key: "parseJson",
  7416. value: function parseJson(e) {
  7417. var _this2 = this;
  7418. return new Promise(function (t, r) {
  7419. return _this2._scenemanager.urlTransformer(e).then(function (n) {
  7420. var o = new XMLHttpRequest();
  7421. o.open("get", n), o.send(null), o.onload = function () {
  7422. if (o.status == 200) {
  7423. var a = JSON.parse(o.responseText);
  7424. _this2._orijson = a, _this2._meshInfoJson = _this2._orijson.usedRegion, _this2._notUsedRegionLists = _this2._orijson.notUsedRegion, _this2._meshInfoKeys = Object.keys(_this2._meshInfoJson), logger.info("[Engine] parse zip mesh info successful"), t();
  7425. }
  7426. }, o.onerror = function () {
  7427. logger.error("[Engine] load zip mesh info json error, (provided by blob): ".concat(n)), r(new XLowpolyJsonError("[Engine] load zip mesh info json error, (provided by blob): ".concat(n)));
  7428. };
  7429. }).catch(function (n) {
  7430. logger.error("[Engine] load zip mesh info json error: ".concat(n, ", link:").concat(e)), r(new XLowpolyJsonError("[Engine] load zip mesh info json error: ".concat(n, ", link: ").concat(e)));
  7431. });
  7432. });
  7433. }
  7434. }, {
  7435. key: "initCgLowModel",
  7436. value: function initCgLowModel() {
  7437. var e = BABYLON.MeshBuilder.CreatePlane("CgPlane", {
  7438. size: 400
  7439. });
  7440. e.position = new Vector3(0, 1010, 0), e.rotation = new Vector3(3 * Math.PI / 2, 0, 0), this._CgPlane = new XStaticMesh({
  7441. id: "CgPlane",
  7442. mesh: e,
  7443. xtype: EMeshType.Cgplane
  7444. }), this._CgPlane.hide();
  7445. }
  7446. }, {
  7447. key: "getLowModelType",
  7448. value: function getLowModelType(e) {
  7449. var t = "";
  7450. return e.group != null ? t = e.group : t = "default", t;
  7451. }
  7452. }, {
  7453. key: "lowmodelGroupMapAddValue",
  7454. value: function lowmodelGroupMapAddValue(e, t) {
  7455. var r = this._lowModel_group.get(e);
  7456. r != null ? (r.push(t), this._lowModel_group.set(e, r)) : this._lowModel_group.set(e, [t]);
  7457. }
  7458. }, {
  7459. key: "updateLowModelGroup",
  7460. value: function updateLowModelGroup(e, t, r) {
  7461. var n = r;
  7462. e.group == t || (n = -1), e.mode == 0 ? this.deleteLowModelGroup(e.group, n) : e.mode == 1 ? this.toggleVisibleLowModelGroup(!1, e.group, n) : e.mode == 2 && this.toggleVisibleLowModelGroup(!0, e.group, n);
  7463. }
  7464. }, {
  7465. key: "toggleVisibleLowModelGroup",
  7466. value: function toggleVisibleLowModelGroup(e, t) {
  7467. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
  7468. if (this._lowModel_group.has(t)) {
  7469. var n = this._lowModel_group.get(t);
  7470. var o = n.length;
  7471. r >= 0 && o >= r && (o = r);
  7472. for (var a = 0; a < o; ++a) {
  7473. n[a].toggleVisibility(e);
  7474. }
  7475. }
  7476. }
  7477. }, {
  7478. key: "deleteLowModelGroup",
  7479. value: function deleteLowModelGroup(e) {
  7480. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
  7481. if (this._lowModel_group.has(e)) {
  7482. var o = this._lowModel_group.get(e);
  7483. var a = o.length;
  7484. t >= 0 && a >= t && (a = t);
  7485. for (var s = 0; s < a; ++s) {
  7486. o[s].dispose();
  7487. }
  7488. t >= 0 ? this._lowModel_group.set(e, this._lowModel_group.get(e).slice(a)) : this._lowModel_group.delete(e);
  7489. }
  7490. var r = this._lowModel_group.get(e),
  7491. n = [];
  7492. r != null && r.length > 0 ? this._staticmeshes.forEach(function (o) {
  7493. if (o.group != e) n.push(o);else for (var _a2 = 0; _a2 < r.length; ++_a2) {
  7494. o.groupUuid == r[_a2].groupUuid && n.push(o);
  7495. }
  7496. }) : this._staticmeshes.forEach(function (o) {
  7497. o.group != e && n.push(o);
  7498. }), this._staticmeshes = n;
  7499. }
  7500. }, {
  7501. key: "deleteMeshesByGroup",
  7502. value: function deleteMeshesByGroup(e) {
  7503. this.deleteLowModelGroup(e);
  7504. }
  7505. }, {
  7506. key: "deleteMeshesById",
  7507. value: function deleteMeshesById(e) {
  7508. this.deleteMeshesByCustomProperty("id", e);
  7509. }
  7510. }, {
  7511. key: "deleteMeshesByLoD",
  7512. value: function deleteMeshesByLoD(e) {
  7513. this.deleteMeshesByCustomProperty("lod", e);
  7514. }
  7515. }, {
  7516. key: "deleteMeshesBySkinInfo",
  7517. value: function deleteMeshesBySkinInfo(e) {
  7518. this.deleteMeshesByCustomProperty("skinInfo", e);
  7519. }
  7520. }, {
  7521. key: "removeMeshesFromSceneByGroup",
  7522. value: function removeMeshesFromSceneByGroup(e) {
  7523. this.removeMeshesFromSceneByCustomProperty("group", e);
  7524. }
  7525. }, {
  7526. key: "removeMeshesFromSceneById",
  7527. value: function removeMeshesFromSceneById(e) {
  7528. this.removeMeshesFromSceneByCustomProperty("id", e);
  7529. }
  7530. }, {
  7531. key: "addMeshesToSceneByGroup",
  7532. value: function addMeshesToSceneByGroup(e) {
  7533. this.addMeshesToSceneByCustomProperty("group", e);
  7534. }
  7535. }, {
  7536. key: "addMeshesToSceneById",
  7537. value: function addMeshesToSceneById(e) {
  7538. this.addMeshesToSceneByCustomProperty("id", e);
  7539. }
  7540. }, {
  7541. key: "removeMeshesFromSceneByCustomProperty",
  7542. value: function removeMeshesFromSceneByCustomProperty(e, t) {
  7543. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
  7544. this._staticmeshes.forEach(function (n) {
  7545. n.isinscene && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.removeFromScene() : n[e] != t || n.removeFromScene());
  7546. });
  7547. }
  7548. }, {
  7549. key: "addMeshesToSceneByCustomProperty",
  7550. value: function addMeshesToSceneByCustomProperty(e, t) {
  7551. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
  7552. this._staticmeshes.forEach(function (n) {
  7553. n.isinscene == !1 && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.addToScene() : n[e] != t || n.addToScene());
  7554. });
  7555. }
  7556. }, {
  7557. key: "deleteMeshesByCustomProperty",
  7558. value: function deleteMeshesByCustomProperty(e, t) {
  7559. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
  7560. var n = [];
  7561. this._staticmeshes.forEach(function (a) {
  7562. a[e] != null && (r ? a[e].indexOf(t) < 0 ? n.push(a) : a.dispose() : a[e] != t ? n.push(a) : a.dispose());
  7563. }), this._staticmeshes = n;
  7564. var o = Array.from(this._lowModel_group.keys());
  7565. for (var a = 0; a < o.length; ++a) {
  7566. var s = o[a],
  7567. l = this._lowModel_group.get(s);
  7568. if (l != null) {
  7569. var u = [];
  7570. for (var c = 0; c < l.length; ++c) {
  7571. l[c][e] != null && (r ? l[c][e].indexOf(t) < 0 && u.push(l[c]) : l[c][e] != t && u.push(l[c]));
  7572. }
  7573. u.length > 0 ? this._lowModel_group.set(s, u) : this._lowModel_group.delete(s);
  7574. }
  7575. }
  7576. }
  7577. }, {
  7578. key: "getMeshes",
  7579. value: function getMeshes() {
  7580. var e = [];
  7581. for (var t = 0; t < this._staticmeshes.length; ++t) {
  7582. e = e.concat(this._staticmeshes[t].meshes);
  7583. }
  7584. return e;
  7585. }
  7586. }, {
  7587. key: "getCgMesh",
  7588. value: function getCgMesh() {
  7589. return this._CgPlane;
  7590. }
  7591. }, {
  7592. key: "getMeshesByGroup",
  7593. value: function getMeshesByGroup() {
  7594. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
  7595. var t = this._lowModel_group.get(e);
  7596. if (t != null) {
  7597. var r = [];
  7598. for (var n = 0; n < t.length; ++n) {
  7599. r = r.concat(t[n].meshes);
  7600. }
  7601. return r;
  7602. } else return null;
  7603. }
  7604. }, {
  7605. key: "getMeshesByGroup2",
  7606. value: function getMeshesByGroup2() {
  7607. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
  7608. return this._getMeshesByCustomProperty("group", e);
  7609. }
  7610. }]);
  7611. return XStaticMeshComponent;
  7612. }();
  7613. 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; } } }; }
  7614. 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); }
  7615. 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; }
  7616. var XSceneManager = /*#__PURE__*/function () {
  7617. function XSceneManager(e, t) {
  7618. var _this = this;
  7619. _classCallCheck(this, XSceneManager);
  7620. E(this, "scene");
  7621. E(this, "engine");
  7622. E(this, "canvas");
  7623. E(this, "gl");
  7624. E(this, "_yuvInfo");
  7625. E(this, "cameraParam");
  7626. E(this, "shaderMode");
  7627. E(this, "panoInfo");
  7628. E(this, "_initEngineScaleNumber");
  7629. E(this, "_forceKeepVertical", !1);
  7630. E(this, "_currentShader");
  7631. E(this, "_currentPanoId");
  7632. E(this, "_renderStatusCheckCount", 0);
  7633. E(this, "_renderStatusNotChecktCount", 0);
  7634. E(this, "_nonlinearCanvasResize", !1);
  7635. E(this, "_bChangeEngineSize", !0);
  7636. E(this, "_cameraManager");
  7637. E(this, "_lowpolyManager");
  7638. E(this, "_materialManager");
  7639. E(this, "_statisticManager");
  7640. E(this, "_breathPointManager");
  7641. E(this, "_skytv");
  7642. E(this, "_mv", []);
  7643. E(this, "_decalManager");
  7644. E(this, "_lightManager");
  7645. E(this, "_avatarManager");
  7646. E(this, "urlTransformer");
  7647. E(this, "_billboardManager");
  7648. E(this, "_backgroundImg");
  7649. E(this, "engineRunTimeStats");
  7650. E(this, "uploadHardwareSystemInfo", function () {
  7651. var e = _this.statisticComponent.getHardwareRenderInfo(),
  7652. t = _this.statisticComponent.getSystemInfo(),
  7653. r = {
  7654. driver: t.driver,
  7655. vender: t.vender,
  7656. webgl: t.version,
  7657. os: t.os
  7658. };
  7659. logger.warn(JSON.stringify(e)), logger.warn(JSON.stringify(r));
  7660. });
  7661. E(this, "addNewLowPolyMesh", /*#__PURE__*/function () {
  7662. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  7663. return regenerator.wrap(function _callee$(_context) {
  7664. while (1) {
  7665. switch (_context.prev = _context.next) {
  7666. case 0:
  7667. _context.t0 = _this._currentShader == null;
  7668. if (!_context.t0) {
  7669. _context.next = 4;
  7670. break;
  7671. }
  7672. _context.next = 4;
  7673. return _this.initSceneManager();
  7674. case 4:
  7675. return _context.abrupt("return", _this._lowpolyManager.addNewLowPolyMesh(e, t, _this._currentShader));
  7676. case 5:
  7677. case "end":
  7678. return _context.stop();
  7679. }
  7680. }
  7681. }, _callee);
  7682. }));
  7683. return function (_x, _x2) {
  7684. return _ref.apply(this, arguments);
  7685. };
  7686. }());
  7687. E(this, "initSceneManager", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  7688. return regenerator.wrap(function _callee2$(_context2) {
  7689. while (1) {
  7690. switch (_context2.prev = _context2.next) {
  7691. case 0:
  7692. _context2.next = 2;
  7693. return _this._materialManager.initMaterial();
  7694. case 2:
  7695. return _context2.abrupt("return", _this.applyShader());
  7696. case 3:
  7697. case "end":
  7698. return _context2.stop();
  7699. }
  7700. }
  7701. }, _callee2);
  7702. })));
  7703. E(this, "registerAfterRender", function () {
  7704. var e;
  7705. if (_this._forceKeepVertical) {
  7706. var _t = _this.canvas.width,
  7707. _r = _this.canvas.height;
  7708. var _n = 0,
  7709. _o = [[0, 0, 0, 0], [0, 0, 0, 0]];
  7710. if (((e = _this._cameraManager.MainCamera) == null ? void 0 : e.fovMode) === BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED ? (_n = Math.ceil((_r - _this._yuvInfo.height * _t / _this._yuvInfo.width) / 2), _o = [[0, 0, _t, _n], [0, _r - _n, _t, _n]]) : (_n = Math.ceil((_t - _this._yuvInfo.width * _r / _this._yuvInfo.height) / 2), _o = [[0, 0, _n, _r], [_t - _n, 0, _n, _r]]), _n > 0) {
  7711. _this.gl.enable(_this.gl.SCISSOR_TEST);
  7712. for (var a = 0; a < _o.length; ++a) {
  7713. _this.gl.scissor(_o[a][0], _o[a][1], _o[a][2], _o[a][3]), _this.gl.clearColor(0, 0, 0, 1), _this.gl.clear(_this.gl.COLOR_BUFFER_BIT);
  7714. }
  7715. _this.gl.disable(_this.gl.SCISSOR_TEST);
  7716. }
  7717. }
  7718. });
  7719. E(this, "resetRender", function () {
  7720. _this.scene.environmentTexture && (_this.scene.environmentTexture._texture ? _this.lightComponent.setIBL(_this.scene.environmentTexture._texture.url) : _this.scene.environmentTexture.url && _this.lightComponent.setIBL(_this.scene.environmentTexture.url));
  7721. });
  7722. var r = /iphone|ipad/gi.test(window.navigator.userAgent) || t.disableWebGL2,
  7723. n = new BABYLON.Engine(e, !0, {
  7724. preserveDrawingBuffer: !0,
  7725. stencil: !0,
  7726. disableWebGL2Support: r
  7727. }, !0),
  7728. o = new BABYLON.Scene(n);
  7729. this.scene = o, this.engine = n, this.canvas = e, this.scene.clearColor = new BABYLON.Color4(.7, .7, .7, 1), this.engine.getCaps().parallelShaderCompile = void 0, this._initEngineScaleNumber = this.engine.getHardwareScalingLevel(), this.engine.enableOfflineSupport = !1, this.engine.doNotHandleContextLost = !0, this.scene.clearCachedVertexData(), this.scene.cleanCachedTextureBuffer(), this.urlTransformer = t.urlTransformer || function (s) {
  7730. return Promise.resolve(s);
  7731. }, t.logger && Logger1.setLogger(t.logger), this.gl = e.getContext("webgl2", {
  7732. preserveDrawingBuffer: !0
  7733. }) || e.getContext("webgl", {
  7734. preserveDrawingBuffer: !0
  7735. }) || e.getContext("experimental-webgl", {
  7736. preserveDrawingBuffer: !0
  7737. }), this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT, 1), this._currentPanoId = 0, t.forceKeepVertical != null && (this._forceKeepVertical = t.forceKeepVertical), t.panoInfo != null && (this.panoInfo = t.panoInfo), t.shaderMode != null && (this.shaderMode = t.shaderMode), t.yuvInfo != null ? this._yuvInfo = t.yuvInfo : this._yuvInfo = {
  7738. width: t.videoResOriArray[0].width,
  7739. height: t.videoResOriArray[0].height,
  7740. fov: 50
  7741. }, t.cameraParam != null && (this.cameraParam = t.cameraParam), t.nonlinearCanvasResize != null && (this._nonlinearCanvasResize = t.nonlinearCanvasResize), this._cameraManager = new XCameraComponent(this.canvas, this.scene, {
  7742. cameraParam: this.cameraParam,
  7743. yuvInfo: this._yuvInfo,
  7744. forceKeepVertical: this._forceKeepVertical
  7745. }), this._lowpolyManager = new XStaticMeshComponent(this), this._materialManager = new XMaterialComponent(this, {
  7746. videoResOriArray: t.videoResOriArray,
  7747. yuvInfo: this._yuvInfo,
  7748. panoInfo: this.panoInfo,
  7749. shaderMode: this.shaderMode
  7750. }), this._statisticManager = new XStats(this), this._breathPointManager = new XBreathPointManager(this), this._decalManager = new XDecalManager(this), this._avatarManager = new XAvatarManager(this), this._billboardManager = new XBillboardManager(this), this.billboardComponent.loadBackGroundTexToIDB(), this._lightManager = new XLightManager(this), this.postprocessing(), this.initSceneManager(), this.engineRunTimeStats = new XEngineRunTimeStats(), /iphone/gi.test(window.navigator.userAgent) && window.devicePixelRatio && window.devicePixelRatio === 3 && window.screen.width === 375 && window.screen.height === 812 ? this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 2) : this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 1.8), this.scene.registerBeforeRender(function () {
  7751. _this._nonlinearCanvasResize && _this._bChangeEngineSize && (_this.setEngineSize(_this._yuvInfo), _this._bChangeEngineSize = !1);
  7752. }), this.scene.registerAfterRender(function () {
  7753. _this._nonlinearCanvasResize || _this.registerAfterRender();
  7754. }), window.addEventListener("resize", function () {
  7755. _this._nonlinearCanvasResize ? _this._bChangeEngineSize = !0 : _this.engine.resize();
  7756. }), XBillboardManager.alphaWidthMap = getAlphaWidthMap("Arial", this.scene), this.uploadHardwareSystemInfo();
  7757. }
  7758. _createClass(XSceneManager, [{
  7759. key: "yuvInfo",
  7760. get: function get() {
  7761. return this.getCurrentShaderMode() == 1 ? this._yuvInfo : {
  7762. width: -1,
  7763. height: -1,
  7764. fov: -1
  7765. };
  7766. },
  7767. set: function set(e) {
  7768. this.getCurrentShaderMode() == 1 && (this._yuvInfo = e, this._cameraManager.cameraFovChange(e));
  7769. }
  7770. }, {
  7771. key: "mainScene",
  7772. get: function get() {
  7773. return this.scene;
  7774. }
  7775. }, {
  7776. key: "cameraComponent",
  7777. get: function get() {
  7778. return this._cameraManager;
  7779. }
  7780. }, {
  7781. key: "staticmeshComponent",
  7782. get: function get() {
  7783. return this._lowpolyManager;
  7784. }
  7785. }, {
  7786. key: "materialComponent",
  7787. get: function get() {
  7788. return this._materialManager;
  7789. }
  7790. }, {
  7791. key: "statisticComponent",
  7792. get: function get() {
  7793. return this._statisticManager;
  7794. }
  7795. }, {
  7796. key: "avatarComponent",
  7797. get: function get() {
  7798. return this._avatarManager;
  7799. }
  7800. }, {
  7801. key: "lightComponent",
  7802. get: function get() {
  7803. return this._lightManager;
  7804. }
  7805. }, {
  7806. key: "Engine",
  7807. get: function get() {
  7808. return this.engine;
  7809. }
  7810. }, {
  7811. key: "Scene",
  7812. get: function get() {
  7813. return this.scene;
  7814. }
  7815. }, {
  7816. key: "billboardComponent",
  7817. get: function get() {
  7818. return this._billboardManager;
  7819. }
  7820. }, {
  7821. key: "breathPointComponent",
  7822. get: function get() {
  7823. return this._breathPointManager;
  7824. }
  7825. }, {
  7826. key: "skytvComponent",
  7827. get: function get() {
  7828. return this._skytv;
  7829. }
  7830. }, {
  7831. key: "mvComponent",
  7832. get: function get() {
  7833. return this._mv;
  7834. }
  7835. }, {
  7836. key: "decalComponent",
  7837. get: function get() {
  7838. return this._decalManager;
  7839. }
  7840. }, {
  7841. key: "currentShader",
  7842. get: function get() {
  7843. return this._currentShader;
  7844. }
  7845. }, {
  7846. key: "initEngineScaleNumber",
  7847. get: function get() {
  7848. return this._initEngineScaleNumber;
  7849. }
  7850. }, {
  7851. key: "setImageQuality",
  7852. value: function setImageQuality(e) {
  7853. e == 0 ? (this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 1.8), logger.info("[Engine] change image quality to low, [" + this._initEngineScaleNumber * 1.8 + "]")) : e == 1 ? (this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 1.5), logger.info("[Engine] change image quality to mid, [" + this._initEngineScaleNumber * 1.5 + "]")) : e == 2 && (this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 1), logger.info("[Engine] change image quality to high, [" + this._initEngineScaleNumber * 1 + "]"));
  7854. }
  7855. }, {
  7856. key: "setNonlinearCanvasResize",
  7857. value: function setNonlinearCanvasResize(e) {
  7858. this._nonlinearCanvasResize = e, this._bChangeEngineSize = e, e || this.engine.resize();
  7859. }
  7860. }, {
  7861. key: "setBackgroundColor",
  7862. value: function setBackgroundColor(e) {
  7863. this.scene.clearColor = new Color4(e.r, e.g, e.b, e.a);
  7864. }
  7865. }, {
  7866. key: "setBackgroundImg",
  7867. value: function setBackgroundImg(e) {
  7868. var _this2 = this;
  7869. return this._backgroundImg != null && this._backgroundImg.url == e ? Promise.resolve(!0) : new Promise(function (t, r) {
  7870. _this2.urlTransformer(e).then(function (n) {
  7871. _this2._backgroundImg == null ? _this2._backgroundImg = {
  7872. layer: new Layer("tex_background_" + Date.now(), n, _this2.Scene, !0),
  7873. url: e
  7874. } : _this2._backgroundImg.url != e && _this2._backgroundImg.layer != null && _this2._backgroundImg.layer.texture != null && (_this2._backgroundImg.layer.texture.updateURL(n), _this2._backgroundImg.layer.name = "tex_background_" + Date.now(), _this2._backgroundImg.url = e), t(!0);
  7875. }).catch(function (n) {
  7876. logger.error("[Engine] set background image Error: ".concat(n)), r("[Engine] set background image Error: ".concat(n));
  7877. });
  7878. });
  7879. }
  7880. }, {
  7881. key: "cleanTheWholeScene",
  7882. value: function cleanTheWholeScene() {
  7883. var _this3 = this;
  7884. var e = this.scene.getFrameId();
  7885. this.scene.onBeforeRenderObservable.clear(), this.scene.onAfterRenderObservable.clear(), this.scene.clearCachedVertexData(), this.scene.cleanCachedTextureBuffer(), this.scene.registerBeforeRender(function () {
  7886. _this3.scene.getFrameId() - e > 5 && _this3.scene.dispose();
  7887. });
  7888. }
  7889. }, {
  7890. key: "getAreaAvatar",
  7891. value: function getAreaAvatar(e, t) {
  7892. var r = [];
  7893. return this._avatarManager.getAvatarList().forEach(function (n) {
  7894. var o = e,
  7895. a = n.position;
  7896. a && o && calcDistance3D(o, a) < t && r.push(n.id);
  7897. }), r;
  7898. }
  7899. }, {
  7900. key: "setEngineSize",
  7901. value: function setEngineSize(e) {
  7902. var t = e.width,
  7903. r = e.height,
  7904. n = this.canvas.width;
  7905. this.canvas.height, this.engine.setSize(Math.round(n), Math.round(n * (r / t)));
  7906. }
  7907. }, {
  7908. key: "getCurrentShaderMode",
  7909. value: function getCurrentShaderMode() {
  7910. return this._currentShader === this._materialManager.getDefaultShader() ? 0 : this._currentShader === this._materialManager.getPureVideoShader() ? 1 : 2;
  7911. }
  7912. }, {
  7913. key: "addSkyTV",
  7914. value: function addSkyTV(e, t) {
  7915. return this._skytv = new XTelevision(this.scene, e, this, t), this._skytv;
  7916. }
  7917. }, {
  7918. key: "addMv",
  7919. value: function addMv(e, t) {
  7920. this._mv.push(new XTelevision(this.scene, e, this, t));
  7921. }
  7922. }, {
  7923. key: "addMeshInfo",
  7924. value: function addMeshInfo(e) {
  7925. this._lowpolyManager.setMeshInfo(e);
  7926. }
  7927. }, {
  7928. key: "applyShader",
  7929. value: function applyShader() {
  7930. var _this4 = this;
  7931. return new Promise(function (e, t) {
  7932. _this4.shaderMode == EShaderMode.videoAndPano || _this4.shaderMode == EShaderMode.video ? _this4.changeVideoShaderForLowModel() : _this4.shaderMode == EShaderMode.default && _this4.changeDefaultShaderForLowModel(), e(!0);
  7933. });
  7934. }
  7935. }, {
  7936. key: "changeHardwareScaling",
  7937. value: function changeHardwareScaling(e) {
  7938. e < 1 ? e = 1 : e > 2.5 && (e = 2.5), this._bChangeEngineSize = !0, this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * e);
  7939. }
  7940. }, {
  7941. key: "getCurrentUsedPanoId",
  7942. value: function getCurrentUsedPanoId() {
  7943. return this._currentPanoId;
  7944. }
  7945. }, {
  7946. key: "render",
  7947. value: function render() {
  7948. try {
  7949. this.scene.render();
  7950. } catch (e) {
  7951. throw logger.error("[Engine] Render Error: ".concat(e)), e;
  7952. }
  7953. }
  7954. }, {
  7955. key: "isReadyToRender",
  7956. value: function isReadyToRender(e) {
  7957. var _e$checkMesh = e.checkMesh,
  7958. t = _e$checkMesh === void 0 ? !0 : _e$checkMesh,
  7959. _e$checkEffect = e.checkEffect,
  7960. r = _e$checkEffect === void 0 ? !1 : _e$checkEffect,
  7961. _e$checkPostProgress = e.checkPostProgress,
  7962. n = _e$checkPostProgress === void 0 ? !1 : _e$checkPostProgress,
  7963. _e$checkParticle = e.checkParticle,
  7964. o = _e$checkParticle === void 0 ? !1 : _e$checkParticle,
  7965. _e$checkAnimation = e.checkAnimation,
  7966. a = _e$checkAnimation === void 0 ? !1 : _e$checkAnimation;
  7967. e.materialNameWhiteLists;
  7968. if (this.scene._isDisposed) return logger.error("[Engine] this.scene._isDisposed== false "), !1;
  7969. var l;
  7970. var u = this.scene.getEngine();
  7971. if (r && !u.areAllEffectsReady()) return logger.error("[Engine] engine.areAllEffectsReady == false"), !1;
  7972. if (a && this.scene._pendingData.length > 0) return logger.error("[Engine] scene._pendingData.length > 0 && animation error"), !1;
  7973. if (t) {
  7974. for (l = 0; l < this.scene.meshes.length; l++) {
  7975. var c = this.scene.meshes[l];
  7976. if (!c.isEnabled() || !c.subMeshes || c.subMeshes.length === 0 || c != null && c.material != null && !(c.material.name.startsWith("Pure") || c.material.name.startsWith("Pano"))) continue;
  7977. if (!c.isReady(!0)) return logger.error("[Engine] scene. mesh isReady == false, mesh name:".concat(c.name, ", mesh xtype: ").concat(c == null ? void 0 : c.xtype, ", mesh xgroup: ").concat(c == null ? void 0 : c.xgroup, ", mesh xskinInfo: ").concat(c == null ? void 0 : c.xskinInfo)), !1;
  7978. var h = c.hasThinInstances || c.getClassName() === "InstancedMesh" || c.getClassName() === "InstancedLinesMesh" || u.getCaps().instancedArrays && c.instances.length > 0;
  7979. var _iterator = _createForOfIteratorHelper(this.scene._isReadyForMeshStage),
  7980. _step;
  7981. try {
  7982. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  7983. var f = _step.value;
  7984. if (!f.action(c, h)) return logger.error("[Engine] scene._isReadyForMeshStage == false, mesh name:".concat(c.name, ", mesh xtype: ").concat(c == null ? void 0 : c.xtype, ", mesh xgroup: ").concat(c == null ? void 0 : c.xgroup, ", mesh xskinInfo: ").concat(c == null ? void 0 : c.xskinInfo)), !1;
  7985. }
  7986. } catch (err) {
  7987. _iterator.e(err);
  7988. } finally {
  7989. _iterator.f();
  7990. }
  7991. }
  7992. for (l = 0; l < this.scene.geometries.length; l++) {
  7993. if (this.scene.geometries[l].delayLoadState === 2) return logger.error("[Engine] geometry.delayLoadState === 2"), !1;
  7994. }
  7995. }
  7996. if (n) {
  7997. if (this.scene.activeCameras && this.scene.activeCameras.length > 0) {
  7998. var _iterator2 = _createForOfIteratorHelper(this.scene.activeCameras),
  7999. _step2;
  8000. try {
  8001. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  8002. var _c = _step2.value;
  8003. if (!_c.isReady(!0)) return logger.error("[Engine] camera not ready === false, ", _c.name), !1;
  8004. }
  8005. } catch (err) {
  8006. _iterator2.e(err);
  8007. } finally {
  8008. _iterator2.f();
  8009. }
  8010. } else if (this.scene.activeCamera && !this.scene.activeCamera.isReady(!0)) return logger.error("[Engine] activeCamera ready === false, ", this.scene.activeCamera.name), !1;
  8011. }
  8012. if (o) {
  8013. var _iterator3 = _createForOfIteratorHelper(this.scene.particleSystems),
  8014. _step3;
  8015. try {
  8016. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  8017. var _c2 = _step3.value;
  8018. if (!_c2.isReady()) return logger.error("[Engine] particleSystem ready === false, ", _c2.name), !1;
  8019. }
  8020. } catch (err) {
  8021. _iterator3.e(err);
  8022. } finally {
  8023. _iterator3.f();
  8024. }
  8025. }
  8026. return !0;
  8027. }
  8028. }, {
  8029. key: "changePanoShaderForLowModel",
  8030. value: function changePanoShaderForLowModel(e) {
  8031. var _this5 = this;
  8032. return logger.info("[Engine] changePanoShaderForLowModel: ".concat(e)), this._materialManager.allowYUVUpdate(), new Promise(function (t, r) {
  8033. _this5._materialManager._isInDynamicRange(e) == !1 && r(!1), _this5._currentPanoId = e, _this5._currentShader = _this5._materialManager.getDynamicShader(e), _this5.changeShaderForLowModel().then(function () {
  8034. t(!0);
  8035. });
  8036. });
  8037. }
  8038. }, {
  8039. key: "changeVideoShaderForLowModel",
  8040. value: function changeVideoShaderForLowModel() {
  8041. return logger.info("[Engine] changeVideoShaderForLowModel"), this._currentShader = this._materialManager.getPureVideoShader(), this._materialManager.allowYUVUpdate(), this.changeShaderForLowModel();
  8042. }
  8043. }, {
  8044. key: "changeDefaultShaderForLowModel",
  8045. value: function changeDefaultShaderForLowModel() {
  8046. return logger.info("[Engine] changeDefaultShaderForLowModel"), this._currentShader = this._materialManager.getDefaultShader(), this._materialManager.stopYUVUpdate(), this.changeShaderForLowModel();
  8047. }
  8048. }, {
  8049. key: "changeShaderForLowModel",
  8050. value: function changeShaderForLowModel() {
  8051. var _this6 = this;
  8052. return new Promise(function (e, t) {
  8053. _this6._lowpolyManager.getMeshes().forEach(function (r) {
  8054. r.setMaterial(_this6._currentShader);
  8055. }), _this6._lowpolyManager.getCgMesh().mesh.material = _this6._currentShader, e(!0);
  8056. });
  8057. }
  8058. }, {
  8059. key: "setIBL",
  8060. value: function setIBL(e) {
  8061. this._lightManager.setIBL(e);
  8062. }
  8063. }, {
  8064. key: "postprocessing",
  8065. value: function postprocessing() {
  8066. var e = new DefaultRenderingPipeline("default", !0, this.scene);
  8067. e.imageProcessingEnabled = !1, e.bloomEnabled = !0, e.bloomThreshold = 1, e.bloomWeight = 1, e.bloomKernel = 64, e.bloomScale = .1;
  8068. }
  8069. }, {
  8070. key: "getGround",
  8071. value: function getGround(e) {
  8072. var t = this._lowpolyManager.getMeshes(),
  8073. r = [];
  8074. return t.forEach(function (n) {
  8075. n.mesh.name.indexOf("SM_Stage") >= 0 && r.push(n.mesh);
  8076. }), this.Scene.meshes.forEach(function (n) {
  8077. n.name.split("_")[0] === "ground" && r.push(n);
  8078. }), r;
  8079. }
  8080. }]);
  8081. return XSceneManager;
  8082. }();
  8083. var http = new Http(),
  8084. urlMap = new Map(),
  8085. urlTransformer = /*#__PURE__*/function () {
  8086. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(i) {
  8087. var e,
  8088. _args2 = arguments;
  8089. return regenerator.wrap(function _callee2$(_context2) {
  8090. while (1) {
  8091. switch (_context2.prev = _context2.next) {
  8092. case 0:
  8093. e = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : !1;
  8094. return _context2.abrupt("return", typeof i != "string" ? (console.warn("url transformer error", i), i) : i.startsWith("blob:") ? i : e ? http.get({
  8095. url: i,
  8096. useIndexedDb: !0,
  8097. key: "url",
  8098. isOutPutObjectURL: !1
  8099. }) : urlMap.has(i) ? urlMap.get(i) : http.get({
  8100. url: i,
  8101. useIndexedDb: !0,
  8102. key: "url"
  8103. }).then(function (t) {
  8104. return urlMap.set(i, t), t;
  8105. }));
  8106. case 2:
  8107. case "end":
  8108. return _context2.stop();
  8109. }
  8110. }
  8111. }, _callee2);
  8112. }));
  8113. return function urlTransformer(_x2) {
  8114. return _ref2.apply(this, arguments);
  8115. };
  8116. }();
  8117. var sceneManager;
  8118. function getSceneManager(i, e) {
  8119. return sceneManager || (sceneManager = new XSceneManager(i, e)), sceneManager;
  8120. }
  8121. var EngineProxy = /*#__PURE__*/function () {
  8122. function EngineProxy(e) {
  8123. var _this = this;
  8124. _classCallCheck(this, EngineProxy);
  8125. E(this, "_tvs", []);
  8126. E(this, "isRenderFirstFrame", !1);
  8127. E(this, "_idleTime", 0);
  8128. E(this, "renderTimer");
  8129. E(this, "lightManager");
  8130. E(this, "_checkSceneNotReadyCount", 0);
  8131. E(this, "_checkSceneDurationFrameNum", 0);
  8132. E(this, "_checkSceneFrameCount", 0);
  8133. E(this, "timeoutCircularArray", new CircularArray(120, !1, []));
  8134. E(this, "frameCircularArray", new CircularArray(120, !1, []));
  8135. E(this, "interFrameCircularArray", new CircularArray(120, !1, []));
  8136. E(this, "drawCallCntCircularArray", new CircularArray(120, !1, []));
  8137. E(this, "activeFacesCircularArray", new CircularArray(120, !1, []));
  8138. E(this, "renderTimeCircularArray", new CircularArray(120, !1, []));
  8139. E(this, "drawCallTimeCircularArray", new CircularArray(120, !1, []));
  8140. E(this, "animationCircularArray", new CircularArray(120, !1, []));
  8141. E(this, "meshSelectCircularArray", new CircularArray(120, !1, []));
  8142. E(this, "renderTargetCircularArray", new CircularArray(120, !1, []));
  8143. E(this, "regBeforeRenderCircularArray", new CircularArray(120, !1, []));
  8144. E(this, "regAfterRenderCircularArray", new CircularArray(120, !1, []));
  8145. E(this, "renderCnt", 0);
  8146. E(this, "renderErrorCount", 0);
  8147. E(this, "engineSloppyCnt", 0);
  8148. E(this, "systemStuckCnt", 0);
  8149. E(this, "frameRenderNumber", 0);
  8150. E(this, "_setFPS", function (e) {
  8151. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 25;
  8152. logger.info("Set fps to", t);
  8153. var r = t > 60 ? 60 : t < 24 ? 24 : t;
  8154. e.Engine.stopRenderLoop();
  8155. var n = 1e3 / r;
  8156. var o = Date.now(),
  8157. a = Date.now(),
  8158. s = n,
  8159. l = 1;
  8160. var u = function u() {
  8161. var T;
  8162. var c = Date.now(),
  8163. h = c - o,
  8164. f = c - a;
  8165. a = c, _this.frameCircularArray.add(f), h - s > n && (_this.systemStuckCnt += 1);
  8166. var d = h / s;
  8167. l = .9 * l + .1 * d;
  8168. var _ = Date.now();
  8169. var g = 0,
  8170. m = 0;
  8171. if (_this.room.isUpdatedRawYUVData || _this.room.isPano) {
  8172. 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) && logger.error("[SDK] Scene not ready, skip render. loop: ".concat(_this._checkSceneNotReadyCount)), _this._checkSceneNotReadyCount > 10 && (logger.error("[SDK] Scene not ready, reload later"), _this.room.proxyEvents("renderError", {
  8173. error: new Error("[SDK] Scene not ready, skip render and reload.")
  8174. })), _this.room.stats.assign({
  8175. renderErrorCount: _this._checkSceneNotReadyCount
  8176. }), logger.infoAndReportMeasurement({
  8177. value: 0,
  8178. startTime: Date.now(),
  8179. metric: "renderError",
  8180. error: new Error("[SDK] Scene not ready, skip render and reload."),
  8181. reportOptions: {
  8182. sampleRate: .1
  8183. }
  8184. }));else try {
  8185. e.render();
  8186. } catch (C) {
  8187. _this.renderErrorCount++, _this.renderErrorCount > 10 && _this.room.proxyEvents("renderError", {
  8188. error: C
  8189. }), _this.room.stats.assign({
  8190. renderErrorCount: _this.renderErrorCount
  8191. }), logger.infoAndReportMeasurement({
  8192. value: 0,
  8193. startTime: Date.now(),
  8194. metric: "renderError",
  8195. error: C,
  8196. reportOptions: {
  8197. sampleRate: .1
  8198. }
  8199. });
  8200. }
  8201. g = Date.now() - _, _this.frameRenderNumber < 1e3 && _this.frameRenderNumber++, _this.room.networkController.rtcp.workers.UpdateYUV(), m = Date.now() - _ - g;
  8202. }
  8203. _this.isRenderFirstFrame || _this.room.networkController.rtcp.workers.UpdateYUV();
  8204. var y = Date.now() - _;
  8205. o = c + y, s = Math.min(Math.max((n - y) / l, 5), 200), y > n && (s = 10, _this.engineSloppyCnt += 1), _this._idleTime = s;
  8206. var b = s;
  8207. 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) {
  8208. var C = _this.frameCircularArray.getAvg(),
  8209. A = _this.timeoutCircularArray.getAvg(),
  8210. S = _this.frameCircularArray.getMax(),
  8211. P = _this.timeoutCircularArray.getMax();
  8212. (T = _this.room.stats) == null || T.assign({
  8213. avgFrameTime: C,
  8214. avgTimeoutTime: A,
  8215. maxFrameTime: S,
  8216. maxTimeoutTime: P,
  8217. systemStuckCnt: _this.systemStuckCnt
  8218. });
  8219. }
  8220. _this.renderTimer = window.setTimeout(u, s);
  8221. };
  8222. _this.renderTimer = window.setTimeout(u, n / l);
  8223. });
  8224. E(this, "updateStats", function () {
  8225. var e;
  8226. (e = _this.room.stats) == null || e.assign({
  8227. renderFrameTime: _this.renderTimeCircularArray.getAvg(),
  8228. maxRenderFrameTime: _this.renderTimeCircularArray.getMax(),
  8229. interFrameTime: _this.interFrameCircularArray.getAvg(),
  8230. animationTime: _this.animationCircularArray.getAvg(),
  8231. meshSelectTime: _this.meshSelectCircularArray.getAvg(),
  8232. drawcallTime: _this.drawCallTimeCircularArray.getAvg(),
  8233. idleTime: _this._idleTime,
  8234. registerBeforeRenderTime: _this.regBeforeRenderCircularArray.getAvg(),
  8235. registerAfterRenderTime: _this.regAfterRenderCircularArray.getAvg(),
  8236. renderTargetRenderTime: _this.renderTargetCircularArray.getAvg(),
  8237. fps: (1e3 / (_this.renderTimeCircularArray.getAvg() + _this.interFrameCircularArray.getAvg())).toFixed(2),
  8238. drawcall: _this.drawCallCntCircularArray.getAvg(),
  8239. engineSloppyCnt: _this.engineSloppyCnt,
  8240. maxInterFrameTime: _this.interFrameCircularArray.getMax(),
  8241. maxDrawcallTime: _this.drawCallTimeCircularArray.getMax(),
  8242. maxMeshSelectTime: _this.meshSelectCircularArray.getMax(),
  8243. maxAnimationTime: _this.animationCircularArray.getMax(),
  8244. maxRegisterBeforeRenderTime: _this.regBeforeRenderCircularArray.getMax(),
  8245. maxRegisterAfterRenderTime: _this.regAfterRenderCircularArray.getMax(),
  8246. maxRenderTargetRenderTime: _this.renderTargetCircularArray.getMax(),
  8247. avgFrameTime: _this.frameCircularArray.getAvg(),
  8248. avgTimeoutTime: _this.timeoutCircularArray.getAvg(),
  8249. maxFrameTime: _this.frameCircularArray.getMax(),
  8250. maxTimeoutTime: _this.timeoutCircularArray.getMax()
  8251. });
  8252. });
  8253. this.room = e;
  8254. }
  8255. _createClass(EngineProxy, [{
  8256. key: "initEngine",
  8257. value: function () {
  8258. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  8259. var t, r, n, o, a;
  8260. return regenerator.wrap(function _callee3$(_context3) {
  8261. while (1) {
  8262. switch (_context3.prev = _context3.next) {
  8263. case 0:
  8264. _context3.next = 2;
  8265. return this.updateBillboard();
  8266. case 2:
  8267. logger.info("engine version:", VERSION$1);
  8268. t = logger;
  8269. t.setLevel(LoggerLevels$1.Warn);
  8270. r = {
  8271. videoResOriArray: [{
  8272. width: 720,
  8273. height: 1280
  8274. }, {
  8275. width: 1280,
  8276. height: 720
  8277. }, {
  8278. width: 480,
  8279. height: 654
  8280. }, {
  8281. width: 654,
  8282. height: 480
  8283. }, {
  8284. width: 1920,
  8285. height: 1080
  8286. }, {
  8287. width: 1080,
  8288. height: 1920
  8289. }, {
  8290. width: 414,
  8291. height: 896
  8292. }],
  8293. forceKeepVertical: this.room.options.objectFit !== "cover",
  8294. panoInfo: {
  8295. dynamicRange: 1,
  8296. width: 4096,
  8297. height: 2048
  8298. },
  8299. shaderMode: EShaderMode$1.videoAndPano,
  8300. yuvInfo: {
  8301. width: 1280,
  8302. height: 720,
  8303. fov: e.fov || DEFAULT_MAIN_CAMERA_FOV
  8304. },
  8305. cameraParam: {
  8306. maxZ: 1e4
  8307. },
  8308. urlTransformer,
  8309. logger: t,
  8310. disableWebGL2: this.room.options.disableWebGL2 || !1
  8311. }, n = this.room.options.resolution;
  8312. n && (r.videoResOriArray.some(function (l) {
  8313. return l.width === n.width && l.height === n.height;
  8314. }) || r.videoResOriArray.push(n));
  8315. o = this.room.sceneManager = getSceneManager(this.room.canvas, r);
  8316. this.room.setPictureQualityLevel(this.room.options.pictureQualityLevel || "high");
  8317. this.room.sceneManager.staticmeshComponent.setRegionLodRule([2, 2, -1, -1, -1]);
  8318. this.room.scene = o.Scene;
  8319. this.room.breathPointManager = o.breathPointComponent;
  8320. this.lightManager = o.lightComponent;
  8321. this.registerStats();
  8322. this.setEnv(e);
  8323. _context3.next = 17;
  8324. return this.room.avatarManager.init();
  8325. case 17:
  8326. a = this._createAssetList(e);
  8327. _context3.next = 20;
  8328. return this.loadAssets(a, "");
  8329. case 20:
  8330. this._setFPS(o);
  8331. case 21:
  8332. case "end":
  8333. return _context3.stop();
  8334. }
  8335. }
  8336. }, _callee3, this);
  8337. }));
  8338. function initEngine(_x3) {
  8339. return _initEngine.apply(this, arguments);
  8340. }
  8341. return initEngine;
  8342. }()
  8343. }, {
  8344. key: "pause",
  8345. value: function pause() {
  8346. clearTimeout(this.renderTimer), logger.info("Invoke room.pause to pause render");
  8347. var e = {
  8348. roomId: this.room.id,
  8349. effects: [],
  8350. lowPolyModels: [],
  8351. breathPointsConfig: [],
  8352. skinId: this.room.skinId
  8353. };
  8354. return this.loadAssets(e, this.room.skinId);
  8355. }
  8356. }, {
  8357. key: "resume",
  8358. value: function () {
  8359. var _resume = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  8360. var e;
  8361. return regenerator.wrap(function _callee4$(_context4) {
  8362. while (1) {
  8363. switch (_context4.prev = _context4.next) {
  8364. case 0:
  8365. this._setFPS(this.room.sceneManager), this.room.sceneManager.cameraComponent.cameraFovChange(this.room.sceneManager.yuvInfo), logger.info("Invoke room.resume to render");
  8366. e = this._createAssetList(this.room.skin);
  8367. _context4.next = 4;
  8368. return this.loadAssets(e, "");
  8369. case 4:
  8370. case "end":
  8371. return _context4.stop();
  8372. }
  8373. }
  8374. }, _callee4, this);
  8375. }));
  8376. function resume() {
  8377. return _resume.apply(this, arguments);
  8378. }
  8379. return resume;
  8380. }()
  8381. }, {
  8382. key: "setEnv",
  8383. value: function setEnv(e) {
  8384. var r;
  8385. this.lightManager || (this.lightManager = this.room.sceneManager.lightComponent), e = e || this.room.skin;
  8386. var t = ModelManager.findModel(e.models, AssetTypeName.Config, AssetClassName.Env);
  8387. return t ? (r = this.lightManager) == null ? void 0 : r.setIBL(t.modelUrl) : (logger.error("env file not found"), Promise.resolve());
  8388. }
  8389. }, {
  8390. key: "_parseModelsAndLoad",
  8391. value: function () {
  8392. var _parseModelsAndLoad2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e, t, r) {
  8393. var n, o, a, u, c, h, _c, s, l, _u, _c2, _h;
  8394. return regenerator.wrap(function _callee5$(_context5) {
  8395. while (1) {
  8396. switch (_context5.prev = _context5.next) {
  8397. case 0:
  8398. logger.info("Invoke _parseModelsAndLoad start", t);
  8399. n = ["airship", "balloon", "default", "ground_feiting", "ground_reqiqiu"], o = new Map();
  8400. r == null && (r = "xxxx");
  8401. a = !0;
  8402. u = 0;
  8403. case 5:
  8404. if (!(u < e.length)) {
  8405. _context5.next = 20;
  8406. break;
  8407. }
  8408. a = !0;
  8409. c = 0;
  8410. case 8:
  8411. if (!(c < n.length)) {
  8412. _context5.next = 16;
  8413. break;
  8414. }
  8415. if (!(e[u].modelUrl.toLowerCase().indexOf(n[c]) >= 0)) {
  8416. _context5.next = 13;
  8417. break;
  8418. }
  8419. h = o.get(n[c]);
  8420. h ? (h.push(e[u]), o.set(n[c], h)) : o.set(n[c], [e[u]]), a = !1;
  8421. return _context5.abrupt("break", 16);
  8422. case 13:
  8423. ++c;
  8424. _context5.next = 8;
  8425. break;
  8426. case 16:
  8427. if (a) {
  8428. _c = o.get("default");
  8429. _c ? (_c.push(e[u]), o.set("default", _c)) : o.set("default", [e[u]]);
  8430. }
  8431. case 17:
  8432. ++u;
  8433. _context5.next = 5;
  8434. break;
  8435. case 20:
  8436. s = o.get(t) || [];
  8437. if (!(this.room.viewMode === "simple" && (s = s.filter(function (u) {
  8438. return !u.modelUrl.endsWith("zip");
  8439. })), !s)) {
  8440. _context5.next = 23;
  8441. break;
  8442. }
  8443. return _context5.abrupt("return", Promise.reject("no invalid scene model with group name: ".concat(t)));
  8444. case 23:
  8445. l = [];
  8446. for (_u = 0; _u < s.length; ++_u) {
  8447. _c2 = s[_u];
  8448. if (_c2.modelUrl.toLowerCase().endsWith("zip")) _c2.modelUrl.toLowerCase().endsWith("zip") && l.push(this.room.sceneManager.addNewLowPolyMesh({
  8449. url: _c2.modelUrl,
  8450. skinInfo: r
  8451. }));else {
  8452. _h = t;
  8453. l.push(this.room.sceneManager.addNewLowPolyMesh({
  8454. url: _c2.modelUrl,
  8455. group: _h,
  8456. pick: !0,
  8457. skinInfo: r
  8458. }));
  8459. }
  8460. }
  8461. return _context5.abrupt("return", Promise.all(l));
  8462. case 26:
  8463. case "end":
  8464. return _context5.stop();
  8465. }
  8466. }
  8467. }, _callee5, this);
  8468. }));
  8469. function _parseModelsAndLoad(_x4, _x5, _x6) {
  8470. return _parseModelsAndLoad2.apply(this, arguments);
  8471. }
  8472. return _parseModelsAndLoad;
  8473. }()
  8474. }, {
  8475. key: "_deleteAssetsLowpolyModel",
  8476. value: function () {
  8477. var _deleteAssetsLowpolyModel2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  8478. var t;
  8479. return regenerator.wrap(function _callee6$(_context6) {
  8480. while (1) {
  8481. switch (_context6.prev = _context6.next) {
  8482. case 0:
  8483. this.room.sceneManager.staticmeshComponent.deleteMeshesBySkinInfo(e), this.room.sceneManager.breathPointComponent.clearBreathPointsBySkinInfo(e), this.room.sceneManager.decalComponent.deleteDecalBySkinInfo(e);
  8484. t = [];
  8485. this.room.sceneManager.Scene.meshes.forEach(function (r) {
  8486. r.xskinInfo == e && t.push(r);
  8487. }), t.forEach(function (r) {
  8488. r.dispose(!1, !1);
  8489. });
  8490. case 3:
  8491. case "end":
  8492. return _context6.stop();
  8493. }
  8494. }
  8495. }, _callee6, this);
  8496. }));
  8497. function _deleteAssetsLowpolyModel(_x7) {
  8498. return _deleteAssetsLowpolyModel2.apply(this, arguments);
  8499. }
  8500. return _deleteAssetsLowpolyModel;
  8501. }()
  8502. }, {
  8503. key: "loadLandAssets",
  8504. value: function () {
  8505. var _loadLandAssets = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7() {
  8506. var _this2 = this;
  8507. var e;
  8508. return regenerator.wrap(function _callee7$(_context7) {
  8509. while (1) {
  8510. switch (_context7.prev = _context7.next) {
  8511. case 0:
  8512. e = this._createAssetList(this.room.skin);
  8513. return _context7.abrupt("return", this.loadAssets(e, this.room.skinId).catch(function () {
  8514. return _this2.loadAssets(e, _this2.room.skinId);
  8515. }));
  8516. case 2:
  8517. case "end":
  8518. return _context7.stop();
  8519. }
  8520. }
  8521. }, _callee7, this);
  8522. }));
  8523. function loadLandAssets() {
  8524. return _loadLandAssets.apply(this, arguments);
  8525. }
  8526. return loadLandAssets;
  8527. }()
  8528. }, {
  8529. key: "loadAssets",
  8530. value: function () {
  8531. var _loadAssets2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8(e) {
  8532. var t,
  8533. r,
  8534. n,
  8535. _args8 = arguments;
  8536. return regenerator.wrap(function _callee8$(_context8) {
  8537. while (1) {
  8538. switch (_context8.prev = _context8.next) {
  8539. case 0:
  8540. t = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : "";
  8541. r = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : 8e3;
  8542. n = Date.now();
  8543. return _context8.abrupt("return", this._loadAssets(e, t)._timeout(r, new InitEngineTimeoutError("loadAssets timeout(".concat(r, "ms)"))).then(function (o) {
  8544. return logger.infoAndReportMeasurement({
  8545. tag: "loadAssets",
  8546. startTime: n,
  8547. metric: "loadAssets"
  8548. }), o;
  8549. }).catch(function (o) {
  8550. return logger.infoAndReportMeasurement({
  8551. tag: "loadAssets",
  8552. startTime: n,
  8553. metric: "loadAssets",
  8554. error: o
  8555. }), Promise.reject(o);
  8556. }));
  8557. case 4:
  8558. case "end":
  8559. return _context8.stop();
  8560. }
  8561. }
  8562. }, _callee8, this);
  8563. }));
  8564. function loadAssets(_x8) {
  8565. return _loadAssets2.apply(this, arguments);
  8566. }
  8567. return loadAssets;
  8568. }()
  8569. }, {
  8570. key: "_loadAssets",
  8571. value: function () {
  8572. var _loadAssets3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(e) {
  8573. var t,
  8574. r,
  8575. _args9 = arguments;
  8576. return regenerator.wrap(function _callee9$(_context9) {
  8577. while (1) {
  8578. switch (_context9.prev = _context9.next) {
  8579. case 0:
  8580. t = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : "";
  8581. _context9.prev = 1;
  8582. r = [];
  8583. r.push(this._loadAssetsLowpolyModel(e, t));
  8584. _context9.next = 6;
  8585. return Promise.all(r);
  8586. case 6:
  8587. _context9.next = 8;
  8588. return this.setEnv();
  8589. case 8:
  8590. this._checkSceneDurationFrameNum = ye._CHECK_DURATION;
  8591. this._checkSceneNotReadyCount = 0;
  8592. this._checkSceneFrameCount = 0;
  8593. this.updateAnimationList();
  8594. this.room.loadAssetsHook();
  8595. _context9.next = 18;
  8596. break;
  8597. case 15:
  8598. _context9.prev = 15;
  8599. _context9.t0 = _context9["catch"](1);
  8600. return _context9.abrupt("return", Promise.reject(_context9.t0));
  8601. case 18:
  8602. case "end":
  8603. return _context9.stop();
  8604. }
  8605. }
  8606. }, _callee9, this, [[1, 15]]);
  8607. }));
  8608. function _loadAssets(_x9) {
  8609. return _loadAssets3.apply(this, arguments);
  8610. }
  8611. return _loadAssets;
  8612. }()
  8613. }, {
  8614. key: "updateAnimationList",
  8615. value: function updateAnimationList() {
  8616. var _this3 = this;
  8617. if (this.room.avatarManager && this.room.avatarManager.xAvatarManager) {
  8618. var e = this.room.skin.animationList;
  8619. if (!e) return;
  8620. e.forEach(function (t) {
  8621. _this3.room.avatarManager.xAvatarManager.updateAnimationLists(t.animations, t.avatarId);
  8622. });
  8623. }
  8624. }
  8625. }, {
  8626. key: "_loadAssetsLowpolyModel",
  8627. value: function () {
  8628. var _loadAssetsLowpolyModel2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  8629. var _this4 = this;
  8630. var t,
  8631. r,
  8632. n,
  8633. o,
  8634. a,
  8635. s,
  8636. u,
  8637. c,
  8638. h,
  8639. _args11 = arguments;
  8640. return regenerator.wrap(function _callee11$(_context11) {
  8641. while (1) {
  8642. switch (_context11.prev = _context11.next) {
  8643. case 0:
  8644. t = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : "";
  8645. r = [], n = [], o = [];
  8646. e.lowPolyModels.forEach(function (f) {
  8647. f.group === "TV" ? n.push({
  8648. id: "",
  8649. name: "",
  8650. thumbnailUrl: "",
  8651. typeName: AssetTypeName.Model,
  8652. className: AssetClassName.Tv,
  8653. modelUrl: f.url
  8654. }) : f.group === "\u544A\u767D\u5899" ? o.push({
  8655. id: "",
  8656. name: "",
  8657. thumbnailUrl: "",
  8658. typeName: AssetTypeName.Model,
  8659. className: AssetClassName.Lpm,
  8660. modelUrl: f.url
  8661. }) : r.push({
  8662. id: "",
  8663. name: "",
  8664. thumbnailUrl: "",
  8665. typeName: AssetTypeName.Model,
  8666. className: AssetClassName.Lpm,
  8667. modelUrl: f.url
  8668. });
  8669. }), t != "" && t != null && this._deleteAssetsLowpolyModel(t);
  8670. a = e.skinId;
  8671. logger.info("====> from ", t, " to ", a), this._tvs.forEach(function (f) {
  8672. return f.clean();
  8673. }), this._tvs = [];
  8674. s = EFitMode.cover;
  8675. a == "10048" && (s = EFitMode.contain), Array.isArray(n) && n.forEach(function (f, d) {
  8676. _this4._tvs.push(new TV("squareTv" + d, f.modelUrl, _this4.room, {
  8677. fitMode: s
  8678. }));
  8679. }), e.breathPointsConfig.forEach( /*#__PURE__*/function () {
  8680. var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(f) {
  8681. var d;
  8682. return regenerator.wrap(function _callee10$(_context10) {
  8683. while (1) {
  8684. switch (_context10.prev = _context10.next) {
  8685. case 0:
  8686. _context10.prev = 0;
  8687. _context10.next = 3;
  8688. return urlTransformer(f.imageUrl);
  8689. case 3:
  8690. d = _context10.sent;
  8691. _context10.next = 9;
  8692. break;
  8693. case 6:
  8694. _context10.prev = 6;
  8695. _context10.t0 = _context10["catch"](0);
  8696. d = f.imageUrl, logger.error("urlTransformer error", _context10.t0);
  8697. case 9:
  8698. _this4.room.breathPointManager.addBreathPoint({
  8699. id: f.id,
  8700. position: f.position,
  8701. spriteSheet: d,
  8702. rotation: f.rotation || {
  8703. pitch: 0,
  8704. yaw: 270,
  8705. roll: 0
  8706. },
  8707. billboardMode: !0,
  8708. type: f.type || "no_type",
  8709. spriteWidthNumber: f.spriteWidthNum || 1,
  8710. spriteHeightNumber: f.spriteHeightNum || 1,
  8711. maxVisibleRegion: f.maxVisibleRegion || 150,
  8712. width: f.width,
  8713. height: f.height,
  8714. skinInfo: f.skinId
  8715. });
  8716. case 10:
  8717. case "end":
  8718. return _context10.stop();
  8719. }
  8720. }
  8721. }, _callee10, null, [[0, 6]]);
  8722. }));
  8723. return function (_x11) {
  8724. return _ref3.apply(this, arguments);
  8725. };
  8726. }()), o.forEach(function (f) {
  8727. _this4.room.sceneManager.decalComponent.addDecal({
  8728. id: f.id || "gbq",
  8729. meshPath: f.modelUrl,
  8730. skinInfo: a
  8731. });
  8732. });
  8733. u = this.room.sceneManager.staticmeshComponent.lowModel_group, c = Array.from(u.keys()).filter(function (f) {
  8734. return !f.startsWith("region_");
  8735. }), h = ["airship", "balloon", "ground_feiting", "ground_reqiqiu", "default"];
  8736. return _context11.abrupt("return", new Promise(function (f, d) {
  8737. Promise.all(h.map(function (_) {
  8738. return _this4._parseModelsAndLoad(r, _, a);
  8739. })).then(function () {
  8740. var _ = !1;
  8741. r.forEach(function (v) {
  8742. v.modelUrl.endsWith("zip") && (_ = !0);
  8743. }), _ == !1 && _this4.room.sceneManager.staticmeshComponent.deleteLastRegionMesh(), _this4.room.sceneManager.staticmeshComponent.lowModel_group;
  8744. var g = Array.from(u.keys()).filter(function (v) {
  8745. return !v.startsWith("region_");
  8746. }),
  8747. m = c.filter(function (v) {
  8748. return g.indexOf(v) < 0;
  8749. });
  8750. m.length > 0 && m.forEach(function (v) {
  8751. _this4.room.sceneManager.staticmeshComponent.deleteMeshesByGroup(v);
  8752. }), f(!0);
  8753. }).catch(function (_) {
  8754. d(_);
  8755. });
  8756. }));
  8757. case 9:
  8758. case "end":
  8759. return _context11.stop();
  8760. }
  8761. }
  8762. }, _callee11, this);
  8763. }));
  8764. function _loadAssetsLowpolyModel(_x10) {
  8765. return _loadAssetsLowpolyModel2.apply(this, arguments);
  8766. }
  8767. return _loadAssetsLowpolyModel;
  8768. }()
  8769. }, {
  8770. key: "_updateSkinAssets",
  8771. value: function () {
  8772. var _updateSkinAssets2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee12(e) {
  8773. var t, r, n;
  8774. return regenerator.wrap(function _callee12$(_context12) {
  8775. while (1) {
  8776. switch (_context12.prev = _context12.next) {
  8777. case 0:
  8778. t = this.room.lastSkinId;
  8779. _context12.next = 3;
  8780. return this.room.getSkin(e);
  8781. case 3:
  8782. r = _context12.sent;
  8783. n = this._createAssetList(r);
  8784. _context12.prev = 5;
  8785. _context12.next = 8;
  8786. return this.loadAssets(n, t);
  8787. case 8:
  8788. this.room.updateCurrentState({
  8789. versionId: r.versionId,
  8790. skinId: r.id,
  8791. skin: r
  8792. });
  8793. _context12.next = 16;
  8794. break;
  8795. case 11:
  8796. _context12.prev = 11;
  8797. _context12.t0 = _context12["catch"](5);
  8798. _context12.next = 15;
  8799. return this.loadAssets(n, t);
  8800. case 15:
  8801. this.room.updateCurrentState({
  8802. versionId: r.versionId,
  8803. skinId: r.id,
  8804. skin: r
  8805. });
  8806. case 16:
  8807. this.setEnv(r);
  8808. case 17:
  8809. case "end":
  8810. return _context12.stop();
  8811. }
  8812. }
  8813. }, _callee12, this, [[5, 11]]);
  8814. }));
  8815. function _updateSkinAssets(_x12) {
  8816. return _updateSkinAssets2.apply(this, arguments);
  8817. }
  8818. return _updateSkinAssets;
  8819. }()
  8820. }, {
  8821. key: "_createAssetList",
  8822. value: function _createAssetList(e) {
  8823. var t = [],
  8824. r = [],
  8825. n = [];
  8826. var o = e.models;
  8827. var a = this.room.modelManager.config.preload;
  8828. return this.room.viewMode === "simple" ? a && (o = a.baseUrls.map(function (l) {
  8829. return l.modelUrl = l.url, l;
  8830. })) : this.room.viewMode, ModelManager.findModels(o, AssetTypeName.Effects, AssetClassName.Effects).forEach(function (l) {
  8831. t.push({
  8832. url: l.modelUrl,
  8833. group: l.className,
  8834. name: l.name
  8835. });
  8836. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Lpm).forEach(function (l) {
  8837. r.push({
  8838. url: l.modelUrl,
  8839. group: l.className
  8840. });
  8841. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Gbq).forEach(function (l) {
  8842. r.push({
  8843. url: l.modelUrl,
  8844. group: l.className
  8845. });
  8846. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Tv).forEach(function (l) {
  8847. r.push({
  8848. url: l.modelUrl,
  8849. group: l.className
  8850. });
  8851. }), [].forEach(function (l) {
  8852. l.skinId == e.id && n.push(l);
  8853. }), {
  8854. roomId: this.room.id,
  8855. effects: t,
  8856. lowPolyModels: r,
  8857. breathPointsConfig: n,
  8858. skinId: e.id
  8859. };
  8860. }
  8861. }, {
  8862. key: "registerStats",
  8863. value: function registerStats() {
  8864. var _this5 = this;
  8865. var e = this.room.sceneManager;
  8866. this.room.scene.registerAfterRender(function () {
  8867. var I;
  8868. var t = e.statisticComponent.getInterFrameTimeCounter(),
  8869. r = e.statisticComponent.getDrawCall(),
  8870. n = e.statisticComponent.getActiveFaces(),
  8871. o = e.statisticComponent.getFrameTimeCounter(),
  8872. a = e.statisticComponent.getDrawCallTime(),
  8873. s = e.statisticComponent.getAnimationTime(),
  8874. l = e.statisticComponent.getActiveMeshEvaluationTime(),
  8875. u = e.statisticComponent.getRenderTargetRenderTime(),
  8876. c = e.statisticComponent.getRegisterBeforeRenderTime(),
  8877. h = e.statisticComponent.getRegisterAfterRenderTime(),
  8878. f = e.statisticComponent.getActiveParticles(),
  8879. d = e.statisticComponent.getActiveBones(),
  8880. _ = e.Scene._activeAnimatables.length,
  8881. g = e.statisticComponent.getTotalRootNodes(),
  8882. m = e.Scene.geometries.length,
  8883. v = e.Scene.onBeforeRenderObservable.observers.length,
  8884. y = e.Scene.onAfterRenderObservable.observers.length,
  8885. b = e.statisticComponent.getTotalMeshes(),
  8886. T = e.statisticComponent.getTotalTextures(),
  8887. C = e.statisticComponent.getTotalMaterials(),
  8888. A = e.statisticComponent.getSystemInfo(),
  8889. S = A.resolution,
  8890. P = A.driver;
  8891. A.vender;
  8892. var R = A.version,
  8893. M = A.hardwareScalingLevel,
  8894. x = S + "_" + P + "_" + R + "_" + M;
  8895. _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({
  8896. renderFrameTime: _this5.renderTimeCircularArray.getAvg(),
  8897. maxRenderFrameTime: _this5.renderTimeCircularArray.getMax(),
  8898. interFrameTime: _this5.interFrameCircularArray.getAvg(),
  8899. animationTime: _this5.animationCircularArray.getAvg(),
  8900. meshSelectTime: _this5.meshSelectCircularArray.getAvg(),
  8901. drawcallTime: _this5.drawCallTimeCircularArray.getAvg(),
  8902. idleTime: _this5._idleTime,
  8903. registerBeforeRenderTime: _this5.regBeforeRenderCircularArray.getAvg(),
  8904. registerAfterRenderTime: _this5.regAfterRenderCircularArray.getAvg(),
  8905. renderTargetRenderTime: _this5.renderTargetCircularArray.getAvg(),
  8906. fps: (1e3 / (_this5.renderTimeCircularArray.getAvg() + _this5.interFrameCircularArray.getAvg())).toFixed(2),
  8907. drawcall: _this5.drawCallCntCircularArray.getAvg(),
  8908. triangle: n.toString(),
  8909. engineSloppyCnt: _this5.engineSloppyCnt,
  8910. maxInterFrameTime: _this5.interFrameCircularArray.getMax(),
  8911. maxDrawcallTime: _this5.drawCallTimeCircularArray.getMax(),
  8912. maxMeshSelectTime: _this5.meshSelectCircularArray.getMax(),
  8913. maxAnimationTime: _this5.animationCircularArray.getMax(),
  8914. maxRegisterBeforeRenderTime: _this5.regBeforeRenderCircularArray.getMax(),
  8915. maxRegisterAfterRenderTime: _this5.regAfterRenderCircularArray.getMax(),
  8916. maxRenderTargetRenderTime: _this5.renderTargetCircularArray.getMax(),
  8917. activeParticles: f,
  8918. activeBones: d,
  8919. activeAnimation: _,
  8920. totalMeshes: b,
  8921. totalRootNodes: g,
  8922. totalGeometries: m,
  8923. totalTextures: T,
  8924. totalMaterials: C,
  8925. registerBeforeCount: v,
  8926. registerAfterCount: y,
  8927. hardwareInfo: x
  8928. }));
  8929. });
  8930. }
  8931. }, {
  8932. key: "updateBillboard",
  8933. value: function () {
  8934. var _updateBillboard = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee13() {
  8935. var e, r, n, o, a, s;
  8936. return regenerator.wrap(function _callee13$(_context13) {
  8937. while (1) {
  8938. switch (_context13.prev = _context13.next) {
  8939. case 0:
  8940. e = this.room.options.skinId;
  8941. _context13.next = 3;
  8942. return this.room.modelManager.findAssetList(e);
  8943. case 3:
  8944. r = _context13.sent.filter(function (a) {
  8945. return a.typeName === AssetTypeName.Textures && a.className === AssetClassName.SayBubble;
  8946. });
  8947. n = ["bubble01", "bubble02", "bubble03"];
  8948. o = ["bubble01_npc", "bubble02_npc", "bubble03_npc"];
  8949. if (r.length) {
  8950. a = r.filter(function (l) {
  8951. return n.includes(l.name);
  8952. }).map(function (l) {
  8953. return l.url;
  8954. }), s = r.filter(function (l) {
  8955. return o.includes(l.name);
  8956. }).map(function (l) {
  8957. return l.url;
  8958. });
  8959. a.length && (XBillboardManager.userBubbleUrls = a), s.length && (XBillboardManager.npcBubbleUrls = s);
  8960. }
  8961. case 7:
  8962. case "end":
  8963. return _context13.stop();
  8964. }
  8965. }
  8966. }, _callee13, this);
  8967. }));
  8968. function updateBillboard() {
  8969. return _updateBillboard.apply(this, arguments);
  8970. }
  8971. return updateBillboard;
  8972. }()
  8973. }]);
  8974. return EngineProxy;
  8975. }();
  8976. 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); }; }
  8977. 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; } }
  8978. var Xverse_Room = /*#__PURE__*/function (_EventEmitter) {
  8979. _inherits(Xverse_Room, _EventEmitter);
  8980. var _super = _createSuper$1(Xverse_Room);
  8981. function Xverse_Room(e) {
  8982. var _this;
  8983. _classCallCheck(this, Xverse_Room);
  8984. _this = _super.call(this);
  8985. E(_assertThisInitialized(_this), "disableAutoTurn", !1);
  8986. E(_assertThisInitialized(_this), "options");
  8987. E(_assertThisInitialized(_this), "_currentNetworkOptions");
  8988. E(_assertThisInitialized(_this), "lastSkinId");
  8989. E(_assertThisInitialized(_this), "debug");
  8990. E(_assertThisInitialized(_this), "isFirstDataUsed", !1);
  8991. E(_assertThisInitialized(_this), "userId", null);
  8992. E(_assertThisInitialized(_this), "pathManager", new PathManager());
  8993. E(_assertThisInitialized(_this), "networkController");
  8994. E(_assertThisInitialized(_this), "_startTime", Date.now());
  8995. E(_assertThisInitialized(_this), "canvas");
  8996. E(_assertThisInitialized(_this), "modelManager");
  8997. E(_assertThisInitialized(_this), "eventsController");
  8998. E(_assertThisInitialized(_this), "panorama");
  8999. E(_assertThisInitialized(_this), "engineProxy");
  9000. E(_assertThisInitialized(_this), "_id");
  9001. E(_assertThisInitialized(_this), "skinList", []);
  9002. E(_assertThisInitialized(_this), "isHost", !1);
  9003. E(_assertThisInitialized(_this), "avatarManager", new XverseAvatarManager(_assertThisInitialized(_this)));
  9004. E(_assertThisInitialized(_this), "effectManager", new XverseEffectManager(_assertThisInitialized(_this)));
  9005. E(_assertThisInitialized(_this), "sceneManager");
  9006. E(_assertThisInitialized(_this), "scene");
  9007. E(_assertThisInitialized(_this), "breathPointManager");
  9008. E(_assertThisInitialized(_this), "_currentState");
  9009. E(_assertThisInitialized(_this), "joined", !1);
  9010. E(_assertThisInitialized(_this), "disableRotate", !1);
  9011. E(_assertThisInitialized(_this), "isPano", !1);
  9012. E(_assertThisInitialized(_this), "movingByClick", !0);
  9013. E(_assertThisInitialized(_this), "camera", new Camera(_assertThisInitialized(_this)));
  9014. E(_assertThisInitialized(_this), "stats", new Stats(_assertThisInitialized(_this)));
  9015. E(_assertThisInitialized(_this), "isUpdatedRawYUVData", !1);
  9016. E(_assertThisInitialized(_this), "actionsHandler", new ActionsHandler(_assertThisInitialized(_this)));
  9017. E(_assertThisInitialized(_this), "_currentClickingState", null);
  9018. E(_assertThisInitialized(_this), "signal", new Signal(_assertThisInitialized(_this)));
  9019. E(_assertThisInitialized(_this), "firstFrameTimestamp");
  9020. E(_assertThisInitialized(_this), "receiveRtcData", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  9021. var e, t, r, n;
  9022. return regenerator.wrap(function _callee$(_context) {
  9023. while (1) {
  9024. switch (_context.prev = _context.next) {
  9025. case 0:
  9026. logger.info("Invoke receiveRtcData");
  9027. e = !1, t = !1, r = !1, n = !1;
  9028. return _context.abrupt("return", _this.viewMode === "serverless" ? (logger.warn("set view mode to serverless"), _this.setViewMode("observer").then(function () {
  9029. return _assertThisInitialized(_this);
  9030. }, function () {
  9031. return _assertThisInitialized(_this);
  9032. })) : new Promise(function (o) {
  9033. var a = _this.networkController.rtcp.workers;
  9034. a.registerFunction("signal", function (s) {
  9035. _this.signal.handleSignal(s);
  9036. }), a.registerFunction("stream", function (s) {
  9037. var l;
  9038. if (_this.emit("streamTimestamp", {
  9039. timestamp: Date.now()
  9040. }), t || (t = !0, logger.info("Invoke stream event")), s.stream) {
  9041. r || (r = !0, logger.info("Invoke updateRawYUVData")), _this.isUpdatedRawYUVData = !1;
  9042. var u = (l = _this._currentState.skin) == null ? void 0 : l.fov;
  9043. _this.sceneManager.materialComponent.updateRawYUVData(s.stream, s.width, s.height, u), _this.isUpdatedRawYUVData = !0;
  9044. }
  9045. e || (logger.info("Invoke isAfterRenderRegistered"), e = !0, _this.scene.registerAfterRender(function () {
  9046. _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()));
  9047. }));
  9048. }), _this.panorama.bindListener(function () {
  9049. o(_assertThisInitialized(_this)), _this.afterJoinRoom();
  9050. }), a.registerFunction("reconnectedFrame", function () {}), logger.info("Invoke decoderWorker.postMessage"), a.decoderWorker.postMessage({
  9051. t: 5
  9052. });
  9053. }));
  9054. case 3:
  9055. case "end":
  9056. return _context.stop();
  9057. }
  9058. }
  9059. }, _callee);
  9060. })));
  9061. E(_assertThisInitialized(_this), "moveToExtra", "");
  9062. _this.options = e, _this.options.wsServerUrl || (_this.options.wsServerUrl = SERVER_URLS.DEV), _this.modelManager = ModelManager$1.getInstance(e.appId, e.releaseId), _this.updateReporter();
  9063. var n = e;
  9064. n.canvas;
  9065. var r = Oe(n, ["canvas"]);
  9066. logger.infoAndReportMeasurement({
  9067. metric: "startJoinRoomAt",
  9068. startTime: Date.now(),
  9069. group: "joinRoom",
  9070. extra: r,
  9071. value: 0
  9072. });
  9073. return _this;
  9074. }
  9075. _createClass(Xverse_Room, [{
  9076. key: "currentNetworkOptions",
  9077. get: function get() {
  9078. return this._currentNetworkOptions;
  9079. }
  9080. }, {
  9081. key: "viewMode",
  9082. get: function get() {
  9083. var e;
  9084. return ((e = this._currentState) == null ? void 0 : e.viewMode) || "full";
  9085. }
  9086. }, {
  9087. key: "id",
  9088. get: function get() {
  9089. return this._id;
  9090. }
  9091. }, {
  9092. key: "skinId",
  9093. get: function get() {
  9094. return this._currentState.skinId;
  9095. }
  9096. }, {
  9097. key: "skin",
  9098. get: function get() {
  9099. return this._currentState.skin;
  9100. }
  9101. }, {
  9102. key: "sessionId",
  9103. get: function get() {
  9104. return this.currentNetworkOptions.sessionId;
  9105. }
  9106. }, {
  9107. key: "pictureQualityLevel",
  9108. get: function get() {
  9109. return this.currentState.pictureQualityLevel;
  9110. }
  9111. }, {
  9112. key: "avatars",
  9113. get: function get() {
  9114. return Array.from(this.avatarManager.avatars.values());
  9115. }
  9116. }, {
  9117. key: "currentState",
  9118. get: function get() {
  9119. var e;
  9120. return le(oe({}, this._currentState), {
  9121. state: (e = this.networkController) == null ? void 0 : e._state
  9122. });
  9123. }
  9124. }, {
  9125. key: "_userAvatar",
  9126. get: function get() {
  9127. var _this2 = this;
  9128. return this.avatars.find(function (e) {
  9129. return e.userId === _this2.userId;
  9130. });
  9131. }
  9132. }, {
  9133. key: "tvs",
  9134. get: function get() {
  9135. return this.engineProxy._tvs;
  9136. }
  9137. }, {
  9138. key: "tv",
  9139. get: function get() {
  9140. return this.tvs[0];
  9141. }
  9142. }, {
  9143. key: "currentClickingState",
  9144. get: function get() {
  9145. return this._currentClickingState;
  9146. }
  9147. }, {
  9148. key: "afterJoinRoomHook",
  9149. value: function afterJoinRoomHook() {}
  9150. }, {
  9151. key: "beforeJoinRoomResolveHook",
  9152. value: function beforeJoinRoomResolveHook() {}
  9153. }, {
  9154. key: "afterReconnectedHook",
  9155. value: function afterReconnectedHook() {}
  9156. }, {
  9157. key: "handleSignalHook",
  9158. value: function handleSignalHook(e) {}
  9159. }, {
  9160. key: "skinChangedHook",
  9161. value: function skinChangedHook() {}
  9162. }, {
  9163. key: "beforeStartGameHook",
  9164. value: function () {
  9165. var _beforeStartGameHook = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  9166. return regenerator.wrap(function _callee2$(_context2) {
  9167. while (1) {
  9168. switch (_context2.prev = _context2.next) {
  9169. case 0:
  9170. case "end":
  9171. return _context2.stop();
  9172. }
  9173. }
  9174. }, _callee2);
  9175. }));
  9176. function beforeStartGameHook(_x) {
  9177. return _beforeStartGameHook.apply(this, arguments);
  9178. }
  9179. return beforeStartGameHook;
  9180. }()
  9181. }, {
  9182. key: "loadAssetsHook",
  9183. value: function loadAssetsHook() {}
  9184. }, {
  9185. key: "afterUserAvatarLoadedHook",
  9186. value: function afterUserAvatarLoadedHook() {}
  9187. }, {
  9188. key: "audienceViewModeHook",
  9189. value: function audienceViewModeHook() {}
  9190. }, {
  9191. key: "setViewModeToObserver",
  9192. value: function setViewModeToObserver() {}
  9193. }, {
  9194. key: "handleVehicleHook",
  9195. value: function handleVehicleHook(e) {}
  9196. }, {
  9197. key: "updateReporter",
  9198. value: function updateReporter() {
  9199. var _this$options = this.options,
  9200. e = _this$options.avatarId,
  9201. t = _this$options.skinId,
  9202. r = _this$options.userId,
  9203. n = _this$options.roomId,
  9204. o = _this$options.role,
  9205. a = _this$options.appId,
  9206. s = _this$options.wsServerUrl;
  9207. reporter$1.updateHeader({
  9208. userId: r
  9209. }), reporter$1.updateBody({
  9210. roomId: n,
  9211. role: o,
  9212. skinId: t,
  9213. avatarId: e,
  9214. appId: a,
  9215. wsServerUrl: s
  9216. });
  9217. }
  9218. }, {
  9219. key: "initRoom",
  9220. value: function () {
  9221. var _initRoom2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  9222. var _this$options$timeout, e;
  9223. return regenerator.wrap(function _callee3$(_context3) {
  9224. while (1) {
  9225. switch (_context3.prev = _context3.next) {
  9226. case 0:
  9227. _this$options$timeout = this.options.timeout, e = _this$options$timeout === void 0 ? DEFAULT_JOINROOM_TIMEOUT : _this$options$timeout;
  9228. if (!util.isSupported()) {
  9229. _context3.next = 5;
  9230. break;
  9231. }
  9232. return _context3.abrupt("return", this._initRoom()._timeout(e, new TimeoutError("initRoom timeout")));
  9233. case 5:
  9234. return _context3.abrupt("return", Promise.reject(new UnsupportedError()));
  9235. case 6:
  9236. case "end":
  9237. return _context3.stop();
  9238. }
  9239. }
  9240. }, _callee3, this);
  9241. }));
  9242. function initRoom() {
  9243. return _initRoom2.apply(this, arguments);
  9244. }
  9245. return initRoom;
  9246. }()
  9247. }, {
  9248. key: "_initRoom",
  9249. value: function () {
  9250. var _initRoom3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  9251. 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;
  9252. return regenerator.wrap(function _callee4$(_context4) {
  9253. while (1) {
  9254. switch (_context4.prev = _context4.next) {
  9255. case 0:
  9256. e = this.validateOptions(this.options);
  9257. if (!e) {
  9258. _context4.next = 3;
  9259. break;
  9260. }
  9261. return _context4.abrupt("return", (logger.error("initRoom param error", e), Promise.reject(e)));
  9262. case 3:
  9263. _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;
  9264. this.setCurrentNetworkOptions({
  9265. avatarId: r,
  9266. skinId: n,
  9267. roomId: R,
  9268. userId: o,
  9269. wsServerUrl: a,
  9270. role: s,
  9271. token: l,
  9272. pageSession: u,
  9273. rotationRenderType: c,
  9274. isAllSync: h,
  9275. appId: f,
  9276. camera: d,
  9277. player: _,
  9278. avatarComponents: g,
  9279. nickname: m,
  9280. avatarScale: v,
  9281. firends: y,
  9282. syncByEvent: b,
  9283. areaName: T,
  9284. attitude: C,
  9285. pathName: A,
  9286. person: P,
  9287. roomTypeId: M,
  9288. hasAvatar: x,
  9289. syncToOthers: I,
  9290. prioritySync: w,
  9291. extra: D,
  9292. removeWhenDisconnected: O
  9293. });
  9294. this.userId = o;
  9295. this.canvas = t;
  9296. T && (this.pathManager.currentArea = T);
  9297. this.networkController = new NetworkController(this);
  9298. this.setCurrentState({
  9299. areaName: T,
  9300. pathName: A,
  9301. attitude: C,
  9302. speed: 0,
  9303. viewMode: S,
  9304. state: this.networkController._state,
  9305. skinId: n
  9306. });
  9307. _context4.prev = 10;
  9308. _context4.next = 13;
  9309. return Promise.all([this.initNetwork(), this.initConfig(), this.initWasm()]);
  9310. case 13:
  9311. logger.info("network config wasm all ready, start to create game");
  9312. _context4.next = 16;
  9313. return this.requestCreateRoom({
  9314. skinId: n
  9315. });
  9316. case 16:
  9317. F = _context4.sent;
  9318. V = F.routeList.find(function (L) {
  9319. return L.areaName === T;
  9320. });
  9321. N = ((V == null ? void 0 : V.step) || 7.5) * 30;
  9322. this.updateCurrentState({
  9323. skin: F,
  9324. skinId: F.id,
  9325. versionId: F.versionId,
  9326. speed: N
  9327. });
  9328. _context4.next = 22;
  9329. return this.initEngine(F);
  9330. case 22:
  9331. _context4.next = 27;
  9332. break;
  9333. case 24:
  9334. _context4.prev = 24;
  9335. _context4.t0 = _context4["catch"](10);
  9336. return _context4.abrupt("return", Promise.reject(_context4.t0));
  9337. case 27:
  9338. return _context4.abrupt("return", (this.beforeJoinRoomResolve(), this.receiveRtcData()));
  9339. case 28:
  9340. case "end":
  9341. return _context4.stop();
  9342. }
  9343. }
  9344. }, _callee4, this, [[10, 24]]);
  9345. }));
  9346. function _initRoom() {
  9347. return _initRoom3.apply(this, arguments);
  9348. }
  9349. return _initRoom;
  9350. }()
  9351. }, {
  9352. key: "beforeJoinRoomResolve",
  9353. value: function beforeJoinRoomResolve() {
  9354. this.setupStats(), this.eventsController = new EventsController(this), this.eventsController.bindEvents(), this.panorama = new Panorama(this), this.beforeJoinRoomResolveHook();
  9355. }
  9356. }, {
  9357. key: "afterJoinRoom",
  9358. value: function afterJoinRoom() {
  9359. this.joined = !0, this.viewMode === "observer" && this.setViewModeToObserver(), logger.infoAndReportMeasurement({
  9360. tag: this.viewMode,
  9361. value: this.firstFrameTimestamp - this._startTime,
  9362. startTime: Date.now(),
  9363. metric: "joinRoom"
  9364. }), this.camera.initialFov = this.sceneManager.cameraComponent.getCameraFov(), this.stats.on("stats", function (_ref2) {
  9365. var e = _ref2.stats;
  9366. reporter$1.report("stats", oe({}, e));
  9367. }), this.debug = new Debug(this), this.afterJoinRoomHook();
  9368. }
  9369. }, {
  9370. key: "afterReconnected",
  9371. value: function afterReconnected() {
  9372. this.avatarManager.clearOtherUsers(), this.afterReconnectedHook();
  9373. }
  9374. }, {
  9375. key: "leave",
  9376. value: function leave() {
  9377. var e, t;
  9378. return logger.info("Invoke room.leave"), (e = this.eventsController) == null || e.clearEvents(), (t = this.networkController) == null || t.quit(), this;
  9379. }
  9380. }, {
  9381. key: "validateOptions",
  9382. value: function validateOptions(e) {
  9383. var _ref3 = e || {},
  9384. t = _ref3.canvas,
  9385. r = _ref3.avatarId,
  9386. n = _ref3.skinId,
  9387. o = _ref3.userId,
  9388. a = _ref3.role;
  9389. _ref3.roomId;
  9390. var l = _ref3.token,
  9391. u = _ref3.appId;
  9392. _ref3.avatarComponents;
  9393. var h = [];
  9394. t instanceof HTMLCanvasElement || h.push(new ParamError$1("`canvas` must be instanceof of HTMLCanvasElement"));
  9395. (!o || typeof o != "string") && h.push(new ParamError$1("`userId` must be string"));
  9396. (!l || typeof l != "string") && h.push(new ParamError$1("`token` must be string"));
  9397. (!u || typeof u != "string") && h.push(new ParamError$1("`appId` must be string"));
  9398. a == "audience" || (!r || !n) && h.push(new ParamError$1("`avatarId` and `skinId` is required when create room"));
  9399. return h[0];
  9400. }
  9401. }, {
  9402. key: "initNetwork",
  9403. value: function () {
  9404. var _initNetwork = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  9405. var e;
  9406. return regenerator.wrap(function _callee5$(_context5) {
  9407. while (1) {
  9408. switch (_context5.prev = _context5.next) {
  9409. case 0:
  9410. if (!(this.viewMode === "serverless")) {
  9411. _context5.next = 2;
  9412. break;
  9413. }
  9414. return _context5.abrupt("return", Promise.resolve());
  9415. case 2:
  9416. e = Date.now();
  9417. _context5.prev = 3;
  9418. _context5.next = 6;
  9419. return this.networkController.connect()._timeout(8e3, new InitNetworkTimeoutError());
  9420. case 6:
  9421. logger.infoAndReportMeasurement({
  9422. metric: "networkInitAt",
  9423. startTime: this._startTime,
  9424. group: "joinRoom"
  9425. });
  9426. logger.infoAndReportMeasurement({
  9427. metric: "networkInitCost",
  9428. startTime: e,
  9429. group: "joinRoom"
  9430. });
  9431. _context5.next = 13;
  9432. break;
  9433. case 10:
  9434. _context5.prev = 10;
  9435. _context5.t0 = _context5["catch"](3);
  9436. throw logger.infoAndReportMeasurement({
  9437. metric: "networkInitAt",
  9438. startTime: e,
  9439. group: "joinRoom",
  9440. error: _context5.t0
  9441. }), _context5.t0;
  9442. case 13:
  9443. case "end":
  9444. return _context5.stop();
  9445. }
  9446. }
  9447. }, _callee5, this, [[3, 10]]);
  9448. }));
  9449. function initNetwork() {
  9450. return _initNetwork.apply(this, arguments);
  9451. }
  9452. return initNetwork;
  9453. }()
  9454. }, {
  9455. key: "initConfig",
  9456. value: function () {
  9457. var _initConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  9458. var e;
  9459. return regenerator.wrap(function _callee6$(_context6) {
  9460. while (1) {
  9461. switch (_context6.prev = _context6.next) {
  9462. case 0:
  9463. e = Date.now();
  9464. _context6.prev = 1;
  9465. _context6.next = 4;
  9466. return this.modelManager.getApplicationConfig()._timeout(8e3, new InitConfigTimeoutError());
  9467. case 4:
  9468. logger.infoAndReportMeasurement({
  9469. metric: "configInitAt",
  9470. startTime: this._startTime,
  9471. group: "joinRoom"
  9472. });
  9473. logger.infoAndReportMeasurement({
  9474. metric: "configInitCost",
  9475. startTime: e,
  9476. group: "joinRoom"
  9477. });
  9478. _context6.next = 11;
  9479. break;
  9480. case 8:
  9481. _context6.prev = 8;
  9482. _context6.t0 = _context6["catch"](1);
  9483. throw logger.infoAndReportMeasurement({
  9484. metric: "configInitAt",
  9485. startTime: e,
  9486. group: "joinRoom",
  9487. error: _context6.t0
  9488. }), _context6.t0;
  9489. case 11:
  9490. case "end":
  9491. return _context6.stop();
  9492. }
  9493. }
  9494. }, _callee6, this, [[1, 8]]);
  9495. }));
  9496. function initConfig() {
  9497. return _initConfig.apply(this, arguments);
  9498. }
  9499. return initConfig;
  9500. }()
  9501. }, {
  9502. key: "initEngine",
  9503. value: function () {
  9504. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  9505. var t, n;
  9506. return regenerator.wrap(function _callee7$(_context7) {
  9507. while (1) {
  9508. switch (_context7.prev = _context7.next) {
  9509. case 0:
  9510. t = Date.now();
  9511. _context7.prev = 1;
  9512. this.engineProxy = new EngineProxy(this);
  9513. _context7.next = 5;
  9514. return this.engineProxy.initEngine(e);
  9515. case 5:
  9516. logger.infoAndReportMeasurement({
  9517. metric: "webglInitAt",
  9518. startTime: this._startTime,
  9519. group: "joinRoom"
  9520. });
  9521. logger.infoAndReportMeasurement({
  9522. metric: "webglInitCost",
  9523. startTime: t,
  9524. group: "joinRoom"
  9525. });
  9526. return _context7.abrupt("return");
  9527. case 10:
  9528. _context7.prev = 10;
  9529. _context7.t0 = _context7["catch"](1);
  9530. n = _context7.t0;
  9531. return _context7.abrupt("return", (_context7.t0.code !== Codes.InitEngineTimeout && (n = new InitEngineError()), logger.error(_context7.t0), logger.infoAndReportMeasurement({
  9532. metric: "webglInitAt",
  9533. startTime: t,
  9534. group: "joinRoom",
  9535. error: n
  9536. }), Promise.reject(n)));
  9537. case 14:
  9538. case "end":
  9539. return _context7.stop();
  9540. }
  9541. }
  9542. }, _callee7, this, [[1, 10]]);
  9543. }));
  9544. function initEngine(_x2) {
  9545. return _initEngine.apply(this, arguments);
  9546. }
  9547. return initEngine;
  9548. }()
  9549. }, {
  9550. key: "initWasm",
  9551. value: function () {
  9552. var _initWasm = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  9553. var _this3 = this;
  9554. var e;
  9555. return regenerator.wrap(function _callee8$(_context8) {
  9556. while (1) {
  9557. switch (_context8.prev = _context8.next) {
  9558. case 0:
  9559. if (!(this.viewMode === "serverless")) {
  9560. _context8.next = 2;
  9561. break;
  9562. }
  9563. return _context8.abrupt("return", Promise.resolve());
  9564. case 2:
  9565. e = Date.now();
  9566. _context8.prev = 3;
  9567. _context8.next = 6;
  9568. return this.networkController.rtcp.workers.init(this.options.resolution)._timeout(8e3, new InitDecoderTimeoutError());
  9569. case 6:
  9570. this.networkController.rtcp.workers.registerFunction("error", function (t) {
  9571. logger.error("decode error", t);
  9572. var r = t.code,
  9573. n = t.message;
  9574. _this3.emit("error", {
  9575. code: r,
  9576. msg: n
  9577. });
  9578. });
  9579. logger.infoAndReportMeasurement({
  9580. metric: "wasmInitAt",
  9581. group: "joinRoom",
  9582. startTime: this._startTime
  9583. });
  9584. logger.infoAndReportMeasurement({
  9585. metric: "wasmInitCost",
  9586. group: "joinRoom",
  9587. startTime: e
  9588. });
  9589. eventsManager.on("traceId", function (t) {
  9590. _this3.networkController.rtcp.workers.onTraceId(t);
  9591. });
  9592. _context8.next = 15;
  9593. break;
  9594. case 12:
  9595. _context8.prev = 12;
  9596. _context8.t0 = _context8["catch"](3);
  9597. throw logger.infoAndReportMeasurement({
  9598. metric: "wasmInitAt",
  9599. group: "joinRoom",
  9600. startTime: e,
  9601. error: _context8.t0
  9602. }), _context8.t0;
  9603. case 15:
  9604. case "end":
  9605. return _context8.stop();
  9606. }
  9607. }
  9608. }, _callee8, this, [[3, 12]]);
  9609. }));
  9610. function initWasm() {
  9611. return _initWasm.apply(this, arguments);
  9612. }
  9613. return initWasm;
  9614. }()
  9615. }, {
  9616. key: "requestCreateRoom",
  9617. value: function () {
  9618. var _requestCreateRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(_ref4) {
  9619. var e, t, r, _ref5, n, o, _yield$this$networkCo, _r, _n, _o, a, s;
  9620. return regenerator.wrap(function _callee9$(_context9) {
  9621. while (1) {
  9622. switch (_context9.prev = _context9.next) {
  9623. case 0:
  9624. e = _ref4.skinId;
  9625. if (!e) {
  9626. _context9.next = 11;
  9627. break;
  9628. }
  9629. _context9.next = 4;
  9630. return this.getSkin(e);
  9631. case 4:
  9632. t = _context9.sent;
  9633. _context9.next = 7;
  9634. return this.modelManager.findRoute(e, this.options.pathName);
  9635. case 7:
  9636. r = _context9.sent;
  9637. this.updateCurrentNetworkOptions({
  9638. areaName: r.areaName,
  9639. attitude: r.attitude,
  9640. versionId: t.versionId
  9641. });
  9642. _ref5 = util.getRandomItem(r.birthPointList) || this.options, n = _ref5.camera, o = _ref5.player;
  9643. this.options.camera || this.updateCurrentNetworkOptions({
  9644. camera: n
  9645. }), this.options.player || this.updateCurrentNetworkOptions({
  9646. player: o
  9647. });
  9648. case 11:
  9649. if (!(this.viewMode === "serverless")) {
  9650. _context9.next = 13;
  9651. break;
  9652. }
  9653. return _context9.abrupt("return", t);
  9654. case 13:
  9655. _context9.prev = 13;
  9656. _context9.next = 16;
  9657. return this.beforeStartGameHook(this.options);
  9658. case 16:
  9659. _context9.next = 18;
  9660. return this.networkController.startGame();
  9661. case 18:
  9662. _yield$this$networkCo = _context9.sent;
  9663. _r = _yield$this$networkCo.room_id;
  9664. _n = _yield$this$networkCo.data;
  9665. _o = _yield$this$networkCo.session_id;
  9666. this._id = _r;
  9667. a = JSON.parse(_n);
  9668. this.isHost = a.IsHost, e = a.SkinID || e;
  9669. _context9.next = 27;
  9670. return this.getSkin(e);
  9671. case 27:
  9672. s = _context9.sent;
  9673. return _context9.abrupt("return", (this.updateCurrentNetworkOptions({
  9674. roomId: _r,
  9675. sessionId: _o
  9676. }), reporter$1.updateBody({
  9677. roomId: _r,
  9678. skinId: e,
  9679. serverSession: _o
  9680. }), s));
  9681. case 31:
  9682. _context9.prev = 31;
  9683. _context9.t0 = _context9["catch"](13);
  9684. throw logger.error("Request create room error", _context9.t0), _context9.t0;
  9685. case 34:
  9686. case "end":
  9687. return _context9.stop();
  9688. }
  9689. }
  9690. }, _callee9, this, [[13, 31]]);
  9691. }));
  9692. function requestCreateRoom(_x3) {
  9693. return _requestCreateRoom.apply(this, arguments);
  9694. }
  9695. return requestCreateRoom;
  9696. }()
  9697. }, {
  9698. key: "pause",
  9699. value: function pause() {
  9700. return this.engineProxy.pause();
  9701. }
  9702. }, {
  9703. key: "resume",
  9704. value: function resume() {
  9705. return this.engineProxy.resume();
  9706. }
  9707. }, {
  9708. key: "reconnect",
  9709. value: function reconnect() {
  9710. this.networkController.reconnect();
  9711. }
  9712. }, {
  9713. key: "setViewMode",
  9714. value: function () {
  9715. var _setViewMode = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(e) {
  9716. return regenerator.wrap(function _callee10$(_context10) {
  9717. while (1) {
  9718. switch (_context10.prev = _context10.next) {
  9719. case 0:
  9720. case "end":
  9721. return _context10.stop();
  9722. }
  9723. }
  9724. }, _callee10);
  9725. }));
  9726. function setViewMode(_x4) {
  9727. return _setViewMode.apply(this, arguments);
  9728. }
  9729. return setViewMode;
  9730. }()
  9731. }, {
  9732. key: "handleRepetLogin",
  9733. value: function handleRepetLogin() {
  9734. logger.warn("receive " + Codes.RepeatLogin + " for repeat login"), this.emit("repeatLogin"), reporter$1.disable(), this.networkController.quit();
  9735. }
  9736. }, {
  9737. key: "setPictureQualityLevel",
  9738. value: function setPictureQualityLevel(e) {
  9739. var t = {
  9740. high: EImageQuality.high,
  9741. low: EImageQuality.low,
  9742. average: EImageQuality.mid
  9743. };
  9744. return this.updateCurrentState({
  9745. pictureQualityLevel: e
  9746. }), this.sceneManager.setImageQuality(t[e]);
  9747. }
  9748. }, {
  9749. key: "getSkin",
  9750. value: function () {
  9751. var _getSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  9752. var t, n;
  9753. return regenerator.wrap(function _callee11$(_context11) {
  9754. while (1) {
  9755. switch (_context11.prev = _context11.next) {
  9756. case 0:
  9757. t = null;
  9758. _context11.next = 3;
  9759. return this.modelManager.getSkinsList();
  9760. case 3:
  9761. t = (this.skinList = _context11.sent).find(function (n) {
  9762. return n.id === e || n.id === e;
  9763. });
  9764. if (!t) {
  9765. _context11.next = 6;
  9766. break;
  9767. }
  9768. return _context11.abrupt("return", t);
  9769. case 6:
  9770. n = "skin is invalid: skinId: ".concat(e);
  9771. return _context11.abrupt("return", Promise.reject(new ParamError$1(n)));
  9772. case 8:
  9773. case "end":
  9774. return _context11.stop();
  9775. }
  9776. }
  9777. }, _callee11, this);
  9778. }));
  9779. function getSkin(_x5) {
  9780. return _getSkin.apply(this, arguments);
  9781. }
  9782. return getSkin;
  9783. }()
  9784. }, {
  9785. key: "setupStats",
  9786. value: function setupStats() {
  9787. this.stats.assign({
  9788. roomId: this.id,
  9789. userId: this.userId
  9790. }), setInterval(this.engineProxy.updateStats, 1e3);
  9791. }
  9792. }, {
  9793. key: "proxyEvents",
  9794. value: function proxyEvents(e, t) {
  9795. this.emit(e, t);
  9796. }
  9797. }, {
  9798. key: "setCurrentNetworkOptions",
  9799. value: function setCurrentNetworkOptions(e) {
  9800. this._currentNetworkOptions = e;
  9801. }
  9802. }, {
  9803. key: "updateCurrentNetworkOptions",
  9804. value: function updateCurrentNetworkOptions(e) {
  9805. Object.assign(this._currentNetworkOptions, e), Object.assign(this.options, e);
  9806. }
  9807. }, {
  9808. key: "setCurrentState",
  9809. value: function setCurrentState(e) {
  9810. this._currentState = e;
  9811. }
  9812. }, {
  9813. key: "updateCurrentState",
  9814. value: function updateCurrentState(e) {
  9815. e.skinId && (this.lastSkinId = this.currentState.skinId, this.updateCurrentNetworkOptions({
  9816. skinId: e.skinId
  9817. })), e.versionId && this.updateCurrentNetworkOptions({
  9818. versionId: e.versionId
  9819. }), Object.assign(this._currentState, e);
  9820. }
  9821. }]);
  9822. return Xverse_Room;
  9823. }(EventEmitter);
  9824. 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); }; }
  9825. 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; } }
  9826. var XverseRoom = /*#__PURE__*/function (_Xverse_Room) {
  9827. _inherits(XverseRoom, _Xverse_Room);
  9828. var _super = _createSuper(XverseRoom);
  9829. function XverseRoom(e) {
  9830. var _this;
  9831. _classCallCheck(this, XverseRoom);
  9832. _this = _super.call(this, e);
  9833. _this.joyStick = new JoyStick(_assertThisInitialized(_this));
  9834. return _this;
  9835. }
  9836. _createClass(XverseRoom, [{
  9837. key: "afterJoinRoomHook",
  9838. value: function afterJoinRoomHook() {
  9839. this.joyStick.init({});
  9840. }
  9841. }]);
  9842. return XverseRoom;
  9843. }(Xverse_Room);
  9844. var Preload = /*#__PURE__*/function () {
  9845. function Preload(e) {
  9846. _classCallCheck(this, Preload);
  9847. this.config = null;
  9848. this.allKeys = [];
  9849. this.oldResourcesDeleted = !1;
  9850. this.requests = {
  9851. simple: {
  9852. stopped: !0,
  9853. requests: {}
  9854. },
  9855. observer: {
  9856. stopped: !0,
  9857. requests: {}
  9858. },
  9859. full: {
  9860. stopped: !0,
  9861. requests: {}
  9862. }
  9863. };
  9864. this.modelManager = e, this.init(e.appId);
  9865. }
  9866. _createClass(Preload, [{
  9867. key: "init",
  9868. value: function init(e) {
  9869. reporter$1.updateBody({
  9870. appId: e
  9871. });
  9872. }
  9873. }, {
  9874. key: "getConfig",
  9875. value: function () {
  9876. var _getConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  9877. var _yield$this$modelMana, t;
  9878. return regenerator.wrap(function _callee$(_context) {
  9879. while (1) {
  9880. switch (_context.prev = _context.next) {
  9881. case 0:
  9882. if (!this.config) {
  9883. _context.next = 2;
  9884. break;
  9885. }
  9886. return _context.abrupt("return", this.config);
  9887. case 2:
  9888. _context.next = 4;
  9889. return this.modelManager.requestConfig();
  9890. case 4:
  9891. _yield$this$modelMana = _context.sent;
  9892. t = _yield$this$modelMana.preload;
  9893. return _context.abrupt("return", t ? (this.config = t, Promise.resolve(t)) : Promise.reject("no preload config"));
  9894. case 7:
  9895. case "end":
  9896. return _context.stop();
  9897. }
  9898. }
  9899. }, _callee, this);
  9900. }));
  9901. function getConfig(_x) {
  9902. return _getConfig.apply(this, arguments);
  9903. }
  9904. return getConfig;
  9905. }()
  9906. }, {
  9907. key: "getAllKeys",
  9908. value: function () {
  9909. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  9910. var e, t;
  9911. return regenerator.wrap(function _callee2$(_context2) {
  9912. while (1) {
  9913. switch (_context2.prev = _context2.next) {
  9914. case 0:
  9915. if (!this.allKeys.length) {
  9916. _context2.next = 2;
  9917. break;
  9918. }
  9919. return _context2.abrupt("return", this.allKeys);
  9920. case 2:
  9921. _context2.prev = 2;
  9922. _context2.next = 5;
  9923. return modelTable.getAllKeys();
  9924. case 5:
  9925. e = _context2.sent;
  9926. this.allKeys = e;
  9927. return _context2.abrupt("return", e);
  9928. case 10:
  9929. _context2.prev = 10;
  9930. _context2.t0 = _context2["catch"](2);
  9931. t = "preload getAllKeys error";
  9932. return _context2.abrupt("return", (logger.error(t), Promise.reject(t)));
  9933. case 14:
  9934. case "end":
  9935. return _context2.stop();
  9936. }
  9937. }
  9938. }, _callee2, this, [[2, 10]]);
  9939. }));
  9940. function getAllKeys() {
  9941. return _getAllKeys.apply(this, arguments);
  9942. }
  9943. return getAllKeys;
  9944. }()
  9945. }, {
  9946. key: "stop",
  9947. value: function stop(e) {
  9948. e === "serverless" && (e = "observer"), this.requests[e].stopped = !0;
  9949. var t = this.requests[e].requests;
  9950. Object.keys(t).forEach(function (r) {
  9951. http1.canceler.removePending(r), delete t[r];
  9952. });
  9953. }
  9954. }, {
  9955. key: "clearPreload",
  9956. value: function clearPreload(e) {
  9957. this.requests[e].stopped = !1, this.allKeys = [];
  9958. }
  9959. }, {
  9960. key: "start",
  9961. value: function () {
  9962. var _start = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e, t, r) {
  9963. var n, o, a, s, l, u, h, f, _s;
  9964. return regenerator.wrap(function _callee3$(_context3) {
  9965. while (1) {
  9966. switch (_context3.prev = _context3.next) {
  9967. case 0:
  9968. n = Date.now(), o = 0;
  9969. _context3.prev = 1;
  9970. if (!(e === "serverless" && (e = "observer"), !this.requests[e])) {
  9971. _context3.next = 4;
  9972. break;
  9973. }
  9974. return _context3.abrupt("return", Promise.reject(new ParamError("invalid stage name: " + e)));
  9975. case 4:
  9976. this.clearPreload(e);
  9977. _context3.next = 7;
  9978. return this.getConfig(e);
  9979. case 7:
  9980. a = _context3.sent;
  9981. _context3.next = 10;
  9982. return this.getAllKeys();
  9983. case 10:
  9984. s = _context3.sent;
  9985. _context3.prev = 11;
  9986. _context3.next = 14;
  9987. return this.deleteOldResources(a.assetUrls.map(function (d) {
  9988. return d.url;
  9989. }), s);
  9990. case 14:
  9991. _context3.next = 19;
  9992. break;
  9993. case 16:
  9994. _context3.prev = 16;
  9995. _context3.t0 = _context3["catch"](11);
  9996. logger.error(_context3.t0);
  9997. case 19:
  9998. l = a.baseUrls, u = a.assetUrls;
  9999. _context3.t1 = e;
  10000. _context3.next = _context3.t1 === "simple" ? 23 : _context3.t1 === "observer" ? 25 : _context3.t1 === "full" ? 27 : 29;
  10001. break;
  10002. case 23:
  10003. h = l;
  10004. return _context3.abrupt("break", 30);
  10005. case 25:
  10006. h = u;
  10007. return _context3.abrupt("break", 30);
  10008. case 27:
  10009. h = u;
  10010. return _context3.abrupt("break", 30);
  10011. case 29:
  10012. h = u;
  10013. case 30:
  10014. f = h.filter(function (d) {
  10015. return !s.includes(d.url);
  10016. });
  10017. r && isFunction(r) && (f = f.filter(r));
  10018. o = f.length;
  10019. logger.debug("keysNeedToPreload", f);
  10020. f.length || t && t(h.length, h.length);
  10021. n = Date.now();
  10022. _context3.next = 38;
  10023. return this._preload(e, f, t);
  10024. case 38:
  10025. logger.infoAndReportMeasurement({
  10026. tag: e,
  10027. startTime: n,
  10028. metric: "assetsPreload",
  10029. extra: {
  10030. total: o
  10031. }
  10032. });
  10033. return _context3.abrupt("return");
  10034. case 42:
  10035. _context3.prev = 42;
  10036. _context3.t2 = _context3["catch"](1);
  10037. _s = _context3.t2;
  10038. return _context3.abrupt("return", ((this.requests[e].stopped || axios.isCancel(_context3.t2)) && (_s = new PreloadCanceledError()), logger.infoAndReportMeasurement({
  10039. tag: e,
  10040. startTime: n,
  10041. metric: "assetsPreload",
  10042. extra: {
  10043. total: o
  10044. },
  10045. error: _s,
  10046. reportOptions: {
  10047. immediate: !0
  10048. }
  10049. }), Promise.reject(_s)));
  10050. case 46:
  10051. case "end":
  10052. return _context3.stop();
  10053. }
  10054. }
  10055. }, _callee3, this, [[1, 42], [11, 16]]);
  10056. }));
  10057. function start(_x2, _x3, _x4) {
  10058. return _start.apply(this, arguments);
  10059. }
  10060. return start;
  10061. }()
  10062. }, {
  10063. key: "deleteOldResources",
  10064. value: function deleteOldResources(e, t) {
  10065. if (!this.oldResourcesDeleted) this.oldResourcesDeleted = !0;else return Promise.resolve();
  10066. var r = t.filter(function (n) {
  10067. return !e.includes(n);
  10068. });
  10069. return logger.debug("keysNeedToDelete", r), logger.warn("keysNeedToDelete", r.length), Promise.all(r.map(function (n) {
  10070. return modelTable.delete(n);
  10071. }));
  10072. }
  10073. }, {
  10074. key: "_preload",
  10075. value: function () {
  10076. var _preload2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t, r) {
  10077. var _this = this;
  10078. var n, o, a;
  10079. return regenerator.wrap(function _callee6$(_context6) {
  10080. while (1) {
  10081. switch (_context6.prev = _context6.next) {
  10082. case 0:
  10083. n = t.length;
  10084. if (n) {
  10085. _context6.next = 3;
  10086. break;
  10087. }
  10088. return _context6.abrupt("return", Promise.resolve());
  10089. case 3:
  10090. o = 0;
  10091. a = window.setInterval(function () {
  10092. r && r(o, n), o >= n && window.clearInterval(a);
  10093. }, 1e3);
  10094. return _context6.abrupt("return", util.mapLimit(t, 10, /*#__PURE__*/function () {
  10095. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(s) {
  10096. var l, u;
  10097. return regenerator.wrap(function _callee5$(_context5) {
  10098. while (1) {
  10099. switch (_context5.prev = _context5.next) {
  10100. case 0:
  10101. l = s.size, u = s.url;
  10102. return _context5.abrupt("return", _this.requests[e].stopped ? Promise.reject(new PreloadCanceledError()) : http1.get({
  10103. url: u,
  10104. timeout: Preload.getTimeoutBySize(l),
  10105. responseType: "blob",
  10106. retry: 2,
  10107. beforeRequest: function beforeRequest() {
  10108. _this.requests[e].requests[u] = !0;
  10109. }
  10110. }).then( /*#__PURE__*/function () {
  10111. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(c) {
  10112. var h, f;
  10113. return regenerator.wrap(function _callee4$(_context4) {
  10114. while (1) {
  10115. switch (_context4.prev = _context4.next) {
  10116. case 0:
  10117. h = c.data;
  10118. if (h instanceof Blob) {
  10119. _context4.next = 3;
  10120. break;
  10121. }
  10122. return _context4.abrupt("return", (logger.error("request blob failed, type:", typeof h, u), Promise.reject("request blob failed " + u)));
  10123. case 3:
  10124. _context4.next = 5;
  10125. return blobToDataURI(h);
  10126. case 5:
  10127. f = _context4.sent;
  10128. _context4.prev = 6;
  10129. _context4.next = 9;
  10130. return modelTable.put({
  10131. url: u,
  10132. model: f
  10133. });
  10134. case 9:
  10135. return _context4.abrupt("return");
  10136. case 12:
  10137. _context4.prev = 12;
  10138. _context4.t0 = _context4["catch"](6);
  10139. return _context4.abrupt("return", (logger.error("unable to add data to indexedDB", _context4.t0), Promise.reject(new InternalError("preload db error"))));
  10140. case 15:
  10141. case "end":
  10142. return _context4.stop();
  10143. }
  10144. }
  10145. }, _callee4, null, [[6, 12]]);
  10146. }));
  10147. return function (_x9) {
  10148. return _ref2.apply(this, arguments);
  10149. };
  10150. }()).then(function () {
  10151. o++, delete _this.requests[e].requests[u];
  10152. }, function (c) {
  10153. return delete _this.requests[e].requests[u], window.clearInterval(a), Promise.reject(c);
  10154. }));
  10155. case 2:
  10156. case "end":
  10157. return _context5.stop();
  10158. }
  10159. }
  10160. }, _callee5);
  10161. }));
  10162. return function (_x8) {
  10163. return _ref.apply(this, arguments);
  10164. };
  10165. }()));
  10166. case 6:
  10167. case "end":
  10168. return _context6.stop();
  10169. }
  10170. }
  10171. }, _callee6);
  10172. }));
  10173. function _preload(_x5, _x6, _x7) {
  10174. return _preload2.apply(this, arguments);
  10175. }
  10176. return _preload;
  10177. }()
  10178. }], [{
  10179. key: "getTimeoutBySize",
  10180. value: function getTimeoutBySize(e) {
  10181. return e ? e < 500 * 1e3 ? 30 * 1e3 : e < 1e3 * 1e3 ? 60 * 1e3 : 100 * 1e3 : 100 * 1e3;
  10182. }
  10183. }]);
  10184. return Preload;
  10185. }();
  10186. var RenderType$1 = {
  10187. PathVideo: 0,
  10188. RotationVideo: 1,
  10189. RotationImage: 2,
  10190. PanoramaImage: 3,
  10191. CGVideo: 4,
  10192. ClientRotationPano: 5,
  10193. CloudRotationPano: 6
  10194. };
  10195. var Xverse = /*#__PURE__*/function () {
  10196. function Xverse(e) {
  10197. _classCallCheck(this, Xverse);
  10198. e || (e = {});
  10199. var _e = e,
  10200. t = _e.onLog,
  10201. r = _e.env,
  10202. n = _e.appId,
  10203. o = _e.releaseId,
  10204. a = _e.subPackageVersion;
  10205. this.NO_CACHE = !1, this.env = r || "PROD", this.SUB_PACKAGE_VERSION = a, this.debug && logger.setLevel(LoggerLevels.Debug);
  10206. var s = this.pageSession = util.uuid();
  10207. reporter$1.updateHeader({
  10208. pageSession: s
  10209. });
  10210. reporter$1.updateReportUrl(REPORT_URL[this.env]);
  10211. a && reporter$1.updateBody({
  10212. sdkVersion: a
  10213. });
  10214. logger.infoAndReportMeasurement({
  10215. metric: "sdkInit",
  10216. startTime: Date.now(),
  10217. extra: {
  10218. version: a,
  10219. enviroment: r,
  10220. pageSession: s
  10221. }
  10222. });
  10223. logger.debug("debug mode:", this.debug);
  10224. reporter$1.on("report", function (l) {
  10225. t && t(l);
  10226. });
  10227. if (n) {
  10228. this.appId = n, this.releaseId = o;
  10229. var l = ModelManager$1.getInstance(n, o);
  10230. this.preload = new Preload(l);
  10231. }
  10232. }
  10233. _createClass(Xverse, [{
  10234. key: "isSupported",
  10235. get: function get() {
  10236. return isSupported();
  10237. }
  10238. }, {
  10239. key: "disableLogUpload",
  10240. value: function disableLogUpload() {
  10241. reporter$1.disable(), logger.debug("logger upload has been disabled");
  10242. }
  10243. }, {
  10244. key: "getSkinList",
  10245. value: function () {
  10246. var _getSkinList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  10247. return regenerator.wrap(function _callee$(_context) {
  10248. while (1) {
  10249. switch (_context.prev = _context.next) {
  10250. case 0:
  10251. return _context.abrupt("return", []);
  10252. case 1:
  10253. case "end":
  10254. return _context.stop();
  10255. }
  10256. }
  10257. }, _callee);
  10258. }));
  10259. function getSkinList() {
  10260. return _getSkinList.apply(this, arguments);
  10261. }
  10262. return getSkinList;
  10263. }()
  10264. }, {
  10265. key: "getAvatarList",
  10266. value: function () {
  10267. var _getAvatarList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  10268. return regenerator.wrap(function _callee2$(_context2) {
  10269. while (1) {
  10270. switch (_context2.prev = _context2.next) {
  10271. case 0:
  10272. return _context2.abrupt("return", []);
  10273. case 1:
  10274. case "end":
  10275. return _context2.stop();
  10276. }
  10277. }
  10278. }, _callee2);
  10279. }));
  10280. function getAvatarList() {
  10281. return _getAvatarList.apply(this, arguments);
  10282. }
  10283. return getAvatarList;
  10284. }()
  10285. }, {
  10286. key: "getGiftList",
  10287. value: function () {
  10288. var _getGiftList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  10289. return regenerator.wrap(function _callee3$(_context3) {
  10290. while (1) {
  10291. switch (_context3.prev = _context3.next) {
  10292. case 0:
  10293. return _context3.abrupt("return", [{
  10294. id: "hack "
  10295. }]);
  10296. case 1:
  10297. case "end":
  10298. return _context3.stop();
  10299. }
  10300. }
  10301. }, _callee3);
  10302. }));
  10303. function getGiftList() {
  10304. return _getGiftList.apply(this, arguments);
  10305. }
  10306. return getGiftList;
  10307. }()
  10308. }, {
  10309. key: "joinRoom",
  10310. value: function () {
  10311. var _joinRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  10312. var t, r, n, o;
  10313. return regenerator.wrap(function _callee4$(_context4) {
  10314. while (1) {
  10315. switch (_context4.prev = _context4.next) {
  10316. case 0:
  10317. t = e.pathName || "thirdwalk", r = e.rotationRenderType || RenderType$1.RotationVideo, n = e.person || Person$1.Third, o = new XverseRoom(le(oe({}, e), {
  10318. appId: e.appId || this.appId,
  10319. releaseId: e.releaseId || this.releaseId,
  10320. pageSession: this.pageSession,
  10321. isAllSync: !0,
  10322. rotationRenderType: r,
  10323. syncByEvent: !0,
  10324. pathName: t,
  10325. person: n,
  10326. role: e.role || "audience"
  10327. }));
  10328. return _context4.abrupt("return", o.initRoom().then(function () {
  10329. return o;
  10330. }));
  10331. case 2:
  10332. case "end":
  10333. return _context4.stop();
  10334. }
  10335. }
  10336. }, _callee4, this);
  10337. }));
  10338. function joinRoom(_x) {
  10339. return _joinRoom.apply(this, arguments);
  10340. }
  10341. return joinRoom;
  10342. }()
  10343. }]);
  10344. return Xverse;
  10345. }();
  10346. var xverse = new Xverse({
  10347. env: "DEV",
  10348. appId: "10016",
  10349. releaseId: '2203120033_29769e'
  10350. });
  10351. var l = /*#__PURE__*/function () {
  10352. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  10353. var R;
  10354. return regenerator.wrap(function _callee$(_context) {
  10355. while (1) {
  10356. switch (_context.prev = _context.next) {
  10357. case 0:
  10358. _context.prev = 0;
  10359. _context.next = 3;
  10360. return (R = xverse.preload) == null ? void 0 : R.start('full', function (M, x) {
  10361. });
  10362. case 3:
  10363. _context.next = 12;
  10364. break;
  10365. case 5:
  10366. _context.prev = 5;
  10367. _context.t0 = _context["catch"](0);
  10368. if (!(console.error(_context.t0), _context.t0.code === Codes.PreloadCanceled)) {
  10369. _context.next = 10;
  10370. break;
  10371. }
  10372. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88");
  10373. return _context.abrupt("return");
  10374. case 10:
  10375. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5");
  10376. return _context.abrupt("return");
  10377. case 12:
  10378. _context.prev = 12;
  10379. _context.next = 15;
  10380. return xverse.joinRoom({
  10381. canvas: document.getElementById('canvas'),
  10382. skinId: '10092',
  10383. avatarId: 'KGe_Boy',
  10384. roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
  10385. userId: '1f7acca1db9d5',
  10386. wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
  10387. appId: "10016",
  10388. token: " ",
  10389. nickname: '1f7acca1db9d5',
  10390. firends: ["user1"],
  10391. viewMode: "full",
  10392. resolution: {
  10393. width: 1728,
  10394. height: 720
  10395. },
  10396. pathName: 'thirdwalk',
  10397. objectFit: null,
  10398. hasAvatar: !0,
  10399. syncToOthers: !0
  10400. });
  10401. case 15:
  10402. room = _context.sent;
  10403. debugger;
  10404. u();
  10405. c();
  10406. window.room = room;
  10407. e(!1);
  10408. _context.next = 28;
  10409. break;
  10410. case 23:
  10411. _context.prev = 23;
  10412. _context.t1 = _context["catch"](12);
  10413. console.error(_context.t1);
  10414. alert(_context.t1);
  10415. return _context.abrupt("return");
  10416. case 28:
  10417. case "end":
  10418. return _context.stop();
  10419. }
  10420. }
  10421. }, _callee, null, [[0, 5], [12, 23]]);
  10422. }));
  10423. return function l() {
  10424. return _ref.apply(this, arguments);
  10425. };
  10426. }();
  10427. var u = function u() {
  10428. room.on("_coreClick", function (_ref2) {
  10429. var f = _ref2.point;
  10430. room._userAvatar.moveTo({
  10431. point: f
  10432. });
  10433. });
  10434. };
  10435. var c = function c() {
  10436. room.on("repeatLogin", function () {
  10437. toast("\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55", {
  10438. duration: 1e4
  10439. });
  10440. }), room.on("reconnecting", function (_ref3) {
  10441. var f = _ref3.count;
  10442. toast("\u5C1D\u8BD5\u7B2C".concat(f, "\u6B21\u91CD\u8FDE"));
  10443. }), room.on("reconnected", function () {
  10444. toast("\u91CD\u8FDE\u6210\u529F");
  10445. }), room.on("disconnected", function () {
  10446. var f = toast("\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5", {
  10447. duration: 1e5,
  10448. onClick() {
  10449. f.hideToast(), room.reconnect();
  10450. }
  10451. });
  10452. });
  10453. };
  10454. l();
  10455. }));
  10456. //# sourceMappingURL=index.js.map