index.js 601 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740
  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$o(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$p(); 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$p() { 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$o(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$5(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$5(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$5(o, minLen) {
  947. if (!o) return;
  948. if (typeof o === "string") return _arrayLikeToArray$5(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$5(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$5(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$1 = 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$n(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$o(); 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$o() { 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$n(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$1.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$1.warn("request ".concat(t, " retry, left retry count"), u), g()) : (logger$1.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 = /*#__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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$n() {
  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$n()) {
  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$m(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); }; }
  1945. 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; } }
  1946. var XverseError = /*#__PURE__*/function (_Error) {
  1947. _inherits(XverseError, _Error);
  1948. var _super = _createSuper$m(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$l(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); }; }
  1979. 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; } }
  1980. var TimeoutError = /*#__PURE__*/function (_XverseError) {
  1981. _inherits(TimeoutError, _XverseError);
  1982. var _super = _createSuper$l(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. var XAvatarLoader = /*#__PURE__*/function () {
  1990. function XAvatarLoader() {
  1991. _classCallCheck(this, XAvatarLoader);
  1992. E(this, "containers", new Map());
  1993. E(this, "meshes", new Map());
  1994. E(this, "animations", new Map());
  1995. E(this, "aniPath", new Map());
  1996. E(this, "binPath", new Map());
  1997. E(this, "texPath", new Map());
  1998. E(this, "matPath", new Map());
  1999. E(this, "mshPath", new Map());
  2000. E(this, "rootPath", new Map());
  2001. E(this, "meshTexList", new Map());
  2002. E(this, "_enableIdb", !0);
  2003. E(this, "_mappings", new Map());
  2004. E(this, "_sharedTex", new Map());
  2005. E(this, "avaliableAnimation", new Map());
  2006. E(this, "enableShareTexture", !0);
  2007. E(this, "enableShareAnimation", !0);
  2008. E(this, "fillEmptyLod", !0);
  2009. var e = new BABYLON.GLTFFileLoader();
  2010. BABYLON.SceneLoader.RegisterPlugin(e), e.preprocessUrlAsync = function (t) {
  2011. var r = avatarLoader._mappings.get(t);
  2012. return r ? Promise.resolve(r) : Promise.resolve(t);
  2013. };
  2014. }
  2015. _createClass(XAvatarLoader, [{
  2016. key: "getParsedUrl",
  2017. value: function getParsedUrl(e, t, r) {
  2018. var _this = this;
  2019. return new Promise(function (o, a) {
  2020. if (!r || r.indexOf(".zip") === -1) return o(r);
  2021. var s = _this.rootPath.get(r);
  2022. if (s) return o(s);
  2023. {
  2024. var l = ".zip",
  2025. u = r.replace(l, "") + COMPONENT_LIST_PREFIX;
  2026. e.urlTransformer(u, !0).then(function (c) {
  2027. if (!c) return a("Loading Failed");
  2028. new Response(c).json().then(function (h) {
  2029. var _, g, m, v, y, b, T;
  2030. var f = r.replace(l, ""),
  2031. d = f + ((_ = h == null ? void 0 : h.components) == null ? void 0 : _.url.replace("./", ""));
  2032. if (_this.rootPath.set(r, d), h.components ? (h.components.url && _this.mshPath.set(t, f + "/" + ((g = h == null ? void 0 : h.components) == null ? void 0 : g.url.replace("./", ""))), h.components.url_lod2 && _this.mshPath.set(t + "_" + avatarSetting.lod[1].level, f + "/" + ((m = h == null ? void 0 : h.components) == null ? void 0 : m.url_lod2.replace("./", ""))), h.components.url_lod4 && _this.mshPath.set(t + "_" + avatarSetting.lod[2].level, f + "/" + ((v = h == null ? void 0 : h.components) == null ? void 0 : v.url_lod4.replace("./", "")))) : (h.meshes.url && _this.mshPath.set(t, f + "/" + ((y = h == null ? void 0 : h.meshes) == null ? void 0 : y.url.replace("./", ""))), h.meshes.url_lod2 && _this.mshPath.set(t + "_" + avatarSetting.lod[1].level, f + "/" + ((b = h == null ? void 0 : h.meshes) == null ? void 0 : b.url_lod2.replace("./", ""))), h.meshes.url_lod4 && _this.mshPath.set(t + "_" + avatarSetting.lod[2].level, f + "/" + ((T = h == null ? void 0 : h.meshes) == null ? void 0 : T.url_lod4.replace("./", "")))), h.materials && h.materials.forEach(function (C) {
  2033. var A = f + "/" + C.url;
  2034. _this.matPath.set(C.name, A);
  2035. }), h.bin) {
  2036. var C = f + "/" + h.bin.url;
  2037. _this.binPath.set(t, C);
  2038. var A = f + "/" + h.bin.url_lod2;
  2039. _this.binPath.set(t + "_" + avatarSetting.lod[1].level, A);
  2040. var S = f + "/" + h.bin.url_lod4;
  2041. _this.binPath.set(t + "_" + avatarSetting.lod[2].level, S);
  2042. }
  2043. return h.textures && h.textures.forEach(function (C) {
  2044. var A = f + "/" + C.url;
  2045. _this.texPath.set(C.url, A);
  2046. var S = _this.meshTexList.get(h.components.url);
  2047. C.type === "png" && (S ? S.find(function (P) {
  2048. return P === C.name;
  2049. }) || S.push(C.url) : _this.meshTexList.set(t, [C.name]));
  2050. }), o(d);
  2051. }).catch(function (h) {
  2052. logger$1.error("[Engine] parse json file error,".concat(h));
  2053. });
  2054. }).catch(function (c) {
  2055. logger$1.error("[Engine] ulrtransform error, cannot find resource in db,".concat(c));
  2056. });
  2057. }
  2058. });
  2059. }
  2060. }, {
  2061. key: "parse",
  2062. value: function () {
  2063. var _parse = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  2064. var _this2 = this;
  2065. var r;
  2066. return regenerator.wrap(function _callee$(_context) {
  2067. while (1) {
  2068. switch (_context.prev = _context.next) {
  2069. case 0:
  2070. r = [];
  2071. t.forEach(function (n) {
  2072. _this2._setAnimationList(n.id, n.animations), r.push(_this2.getParsedUrl(e, n.id, n.url)), n.components.forEach(function (o) {
  2073. o.units.forEach(function (a) {
  2074. r.push(_this2.getParsedUrl(e, a.name, a.url));
  2075. });
  2076. });
  2077. });
  2078. _context.next = 4;
  2079. return Promise.all(r);
  2080. case 4:
  2081. case "end":
  2082. return _context.stop();
  2083. }
  2084. }
  2085. }, _callee);
  2086. }));
  2087. function parse(_x, _x2) {
  2088. return _parse.apply(this, arguments);
  2089. }
  2090. return parse;
  2091. }()
  2092. }, {
  2093. key: "_setAnimationList",
  2094. value: function _setAnimationList(e, t) {
  2095. var _this3 = this;
  2096. t ? t.forEach(function (r) {
  2097. _this3.aniPath.set(e + "_" + r.name, r.url);
  2098. }) : logger$1.error("[Engine] no animation list exist, please check config for details");
  2099. }
  2100. }, {
  2101. key: "disposeContainer",
  2102. value: function disposeContainer() {
  2103. var _this4 = this;
  2104. this.containers.forEach(function (e, t) {
  2105. e.xReferenceCount < 1 && (_this4.enableShareTexture && e.textures.length > 0 && e.textures[0].xReferenceCount != null && (e.textures[0].xReferenceCount--, e.textures = []), e.dispose(), _this4.containers.delete(t));
  2106. }), this._sharedTex.forEach(function (e, t) {
  2107. e.xReferenceCount == 0 && (e.dispose(), _this4._sharedTex.delete(t));
  2108. });
  2109. }
  2110. }, {
  2111. key: "enableIdb",
  2112. set: function set(e) {
  2113. this._enableIdb = e;
  2114. }
  2115. }, {
  2116. key: "getGlbPath",
  2117. value: function getGlbPath(e) {
  2118. return this.aniPath.get(e + ".glb");
  2119. }
  2120. }, {
  2121. key: "getGltfPath",
  2122. value: function getGltfPath(e) {
  2123. return this.mshPath.get(e + ".gltf");
  2124. }
  2125. }, {
  2126. key: "getPngUrl",
  2127. value: function getPngUrl(e) {
  2128. return this.texPath.get(e + ".png");
  2129. }
  2130. }, {
  2131. key: "getMeshUrl",
  2132. value: function getMeshUrl(e) {
  2133. return this.mshPath.get(e);
  2134. }
  2135. }, {
  2136. key: "_getSourceKey",
  2137. value: function _getSourceKey(e, t) {
  2138. return t && avatarSetting.lod[t] ? e + avatarSetting.lod[t].fileName.split(".")[0] : e;
  2139. }
  2140. }, {
  2141. key: "_getAnimPath",
  2142. value: function _getAnimPath(e, t) {
  2143. var r = this.aniPath.get(t + "_animations_" + t.split("_")[1]);
  2144. return r || (r = this.aniPath.get(t + "_" + e)), r;
  2145. }
  2146. }, {
  2147. key: "load",
  2148. value: function load(e, t, r, n) {
  2149. var _this5 = this;
  2150. return new Promise(function (o, a) {
  2151. _this5.loadGlb(e, t, r).then(function (s) {
  2152. return s ? o(s) : a("[Engine] container load failed");
  2153. }).catch(function () {
  2154. return a("[Engine] container load failed");
  2155. });
  2156. });
  2157. }
  2158. }, {
  2159. key: "_searchAnimation",
  2160. value: function _searchAnimation(e, t) {
  2161. var r;
  2162. return this.containers.forEach(function (n, o) {
  2163. var a = t.split("_")[0];
  2164. o.indexOf(a) != -1 && o.indexOf(e) != -1 && (r = n);
  2165. }), r;
  2166. }
  2167. }, {
  2168. key: "loadAnimRes",
  2169. value: function loadAnimRes(e, t, r) {
  2170. var _this6 = this;
  2171. return new Promise(function (n, o) {
  2172. var a = _this6._getAnimPath(t, r),
  2173. s = getAnimationKey(t, r);
  2174. if (a && _this6.containers.get(a)) return n(_this6.containers.get(a));
  2175. if (a) _this6._loadGlbFromBlob(e, s, a).then(function (l) {
  2176. return l.animationGroups.length == 0 ? (_this6.containers.delete(s), l.dispose(), Promise.reject("container does not contains animation data")) : n(l);
  2177. });else return o("no such url");
  2178. });
  2179. }
  2180. }, {
  2181. key: "loadGlb",
  2182. value: function loadGlb(e, t, r) {
  2183. var n = this.getMeshUrl(this._getSourceKey(t, r));
  2184. return !n && this.fillEmptyLod && (r = 0, n = this.getMeshUrl(this._getSourceKey(t, r))), n && this.containers.get(n) ? Promise.resolve(this.containers.get(n)) : n ? this._enableIdb ? Promise.resolve(this._loadGlbFromBlob(e, this._getSourceKey(t, r), n)) : Promise.resolve(this._loadGlbFromUrl(e, this._getSourceKey(t, r), n)) : Promise.reject("no such url");
  2185. }
  2186. }, {
  2187. key: "loadGltf",
  2188. value: function loadGltf(e, t, r, n) {
  2189. var o = this._getSourceKey(t, r || 0);
  2190. var a = this.getGltfPath(o);
  2191. return !a && this.fillEmptyLod && (a = this.getGltfPath(t)), a && this.containers.get(a) ? Promise.resolve(this.containers.get(a)) : this._enableIdb ? this._loadGltfFromBlob(e, t, r, n) : a ? this._loadGltfFromUrl(e, t, a.replace(t + ".gltf", "")) : Promise.reject();
  2192. }
  2193. }, {
  2194. key: "loadSubsequence",
  2195. value: function loadSubsequence() {}
  2196. }, {
  2197. key: "loadVAT",
  2198. value: function loadVAT() {}
  2199. }, {
  2200. key: "getResourceName",
  2201. value: function getResourceName(e) {
  2202. return this.meshTexList.get(e);
  2203. }
  2204. }, {
  2205. key: "_loadGltfFromUrl",
  2206. value: function _loadGltfFromUrl(e, t, r) {
  2207. return BABYLON.SceneLoader.LoadAssetContainerAsync(r, t + ".gltf", e.Scene, null, ".gltf");
  2208. }
  2209. }, {
  2210. key: "_loadGlbFromBlob",
  2211. value: function _loadGlbFromBlob(e, t, r) {
  2212. var _this7 = this;
  2213. return new Promise(function (n, o) {
  2214. e.urlTransformer(r).then(function (a) {
  2215. BABYLON.SceneLoader.LoadAssetContainerAsync("", a, e.Scene, null, ".glb").then(function (s) {
  2216. if (s) {
  2217. if (_this7.enableShareTexture && s.textures.length > 0) {
  2218. var l = t.indexOf("_lod") != -1 ? t.slice(0, -5) : t,
  2219. u = _this7._sharedTex.get(l);
  2220. u ? (s.meshes[1].material._albedoTexture = u, s.textures.forEach(function (c) {
  2221. c.dispose();
  2222. }), s.textures = [u], u.xReferenceCount++) : (_this7._sharedTex.set(l, s.textures[0]), s.textures[0].xReferenceCount = 1);
  2223. }
  2224. return s.addAllToScene(), s.xReferenceCount = 0, s.meshes.forEach(function (l) {
  2225. l.setEnabled(!1);
  2226. }), _this7.containers.set(r, s), n(s);
  2227. } else o("glb file load failed");
  2228. });
  2229. });
  2230. });
  2231. }
  2232. }, {
  2233. key: "_loadGlbFromUrl",
  2234. value: function _loadGlbFromUrl(e, t, r) {
  2235. var _this8 = this;
  2236. return new Promise(function (n, o) {
  2237. BABYLON.SceneLoader.LoadAssetContainerAsync("", r, e.Scene, null, ".glb").then(function (a) {
  2238. if (a) {
  2239. if (a.addAllToScene(), a.meshes.forEach(function (s) {
  2240. s.setEnabled(!1);
  2241. }), _this8.enableShareTexture && a.textures.length > 0) {
  2242. var s = t.indexOf("_lod") != -1 ? t.slice(0, -5) : t,
  2243. l = _this8._sharedTex.get(s);
  2244. l ? (a.meshes[1].material._albedoTexture = l, a.textures.forEach(function (u) {
  2245. u.dispose();
  2246. }), a.textures = [l], l.xReferenceCount++) : (_this8._sharedTex.set(s, a.textures[0]), a.textures[0].xReferenceCount = 1);
  2247. }
  2248. return a.xReferenceCount = 0, _this8.containers.set(r, a), n(a);
  2249. } else o("glb file load failed");
  2250. });
  2251. });
  2252. }
  2253. }, {
  2254. key: "_loadGltfFromBlob",
  2255. value: function _loadGltfFromBlob(e, t, r, n) {
  2256. var _this9 = this;
  2257. return new Promise(function (o, a) {
  2258. var s = [];
  2259. var l = _this9._getSourceKey(t, r),
  2260. u = _this9.getGltfPath(l);
  2261. if (!u && _this9.fillEmptyLod && (r = 0, l = _this9._getSourceKey(t, r), u = _this9.getGltfPath(l)), !u) return a("[Engine] gltf path incorrect ".concat(l, ",cancel."));
  2262. var c = _this9.mshPath.get(l + ".gltf");
  2263. if (!c) return a("cannot find asset mshPath");
  2264. var h = _this9.binPath.get(l + ".bin");
  2265. if (!h) return a("cannot find asset binPath");
  2266. if (!n) {
  2267. var _ = _this9.meshTexList.get(t);
  2268. if (!_ || _.length == 0) return a("cannot find texture");
  2269. n = _[0];
  2270. }
  2271. var f = _this9.texPath.get(n + ".png");
  2272. if (!f) return a();
  2273. var d = _this9.texPath.get(n + "-astc.ktx");
  2274. if (!d) return a();
  2275. s.push(_this9._blobMapping(e, c)), s.push(_this9._blobMapping(e, h)), s.push(_this9._blobMapping(e, f)), s.push(_this9._blobMapping(e, d)), Promise.all(s).then(function () {
  2276. var _ = u.replace(l + ".gltf", "");
  2277. BABYLON.SceneLoader.LoadAssetContainerAsync(_, l + ".gltf", e.Scene, null, ".gltf").then(function (g) {
  2278. var v;
  2279. _this9.containers.set(u, g), g.addAllToScene(), g.meshes.forEach(function (y) {
  2280. y.setEnabled(!1);
  2281. });
  2282. var m = _this9._sharedTex.get(t);
  2283. m ? ((v = g.meshes[1].material._albedoTexture) == null || v.dispose(), g.meshes[1].material._albedoTexture = m) : _this9._sharedTex.set(t, g.meshes[1].material._albedoTexture), o(g);
  2284. });
  2285. });
  2286. });
  2287. }
  2288. }, {
  2289. key: "_blobMapping",
  2290. value: function _blobMapping(e, t) {
  2291. var _this10 = this;
  2292. return new Promise(function (r, n) {
  2293. e.urlTransformer(t).then(function (o) {
  2294. return o ? (_this10._mappings.set(t, o), r(t)) : n("[Engine] url urlTransformer parse error ".concat(t));
  2295. });
  2296. });
  2297. }
  2298. }]);
  2299. return XAvatarLoader;
  2300. }();
  2301. var avatarLoader = new XAvatarLoader();
  2302. function _createSuper$k(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$k(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  2303. function _isNativeReflectConstruct$k() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  2304. var XverseAvatarManager = /*#__PURE__*/function (_EventEmitter) {
  2305. _inherits(XverseAvatarManager, _EventEmitter);
  2306. var _super = _createSuper$k(XverseAvatarManager);
  2307. function XverseAvatarManager(e) {
  2308. var _this;
  2309. _classCallCheck(this, XverseAvatarManager);
  2310. _this = _super.call(this);
  2311. _this.xAvatarManager = null;
  2312. _this.avatars = new Map();
  2313. _this.syncAvatarsLength = 0;
  2314. _this._room = e;
  2315. _this._usersStatistics();
  2316. _this.broadcast = _this.setupBroadcast();
  2317. e.on("skinChanged", function () {
  2318. _this.avatars.forEach(function (t) {
  2319. t.disconnected && _this.removeAvatar(t.userId, !0);
  2320. });
  2321. });
  2322. return _this;
  2323. }
  2324. _createClass(XverseAvatarManager, [{
  2325. key: "setupBroadcast",
  2326. value: function setupBroadcast() {
  2327. var _this2 = this;
  2328. return new Broadcast$1(this._room, /*#__PURE__*/function () {
  2329. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  2330. var t, r, n, o, a, _r$loop, s, l;
  2331. return regenerator.wrap(function _callee$(_context) {
  2332. while (1) {
  2333. switch (_context.prev = _context.next) {
  2334. case 0:
  2335. t = e.broadcastType, r = e.info;
  2336. if (!(t !== CoreBroadcastType.PlayAnimation)) {
  2337. _context.next = 3;
  2338. break;
  2339. }
  2340. return _context.abrupt("return");
  2341. case 3:
  2342. 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);
  2343. _context.t0 = l && !l.isSelf;
  2344. if (!_context.t0) {
  2345. _context.next = 10;
  2346. break;
  2347. }
  2348. l.emit("animationStart", {
  2349. animationName: o,
  2350. extra: decodeURIComponent(a)
  2351. });
  2352. _context.next = 9;
  2353. return l == null ? void 0 : l._playAnimation(o, s);
  2354. case 9:
  2355. l.emit("animationEnd", {
  2356. animationName: o,
  2357. extra: decodeURIComponent(a)
  2358. });
  2359. case 10:
  2360. case "end":
  2361. return _context.stop();
  2362. }
  2363. }
  2364. }, _callee);
  2365. }));
  2366. return function (_x) {
  2367. return _ref.apply(this, arguments);
  2368. };
  2369. }());
  2370. }
  2371. }, {
  2372. key: "hideAll",
  2373. value: function hideAll() {
  2374. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2375. this.xAvatarManager.hideAll(e);
  2376. }
  2377. }, {
  2378. key: "showAll",
  2379. value: function showAll() {
  2380. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2381. this.xAvatarManager.showAll(e);
  2382. }
  2383. }, {
  2384. key: "init",
  2385. value: function () {
  2386. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  2387. var e, t;
  2388. return regenerator.wrap(function _callee2$(_context2) {
  2389. while (1) {
  2390. switch (_context2.prev = _context2.next) {
  2391. case 0:
  2392. this.xAvatarManager = this._room.sceneManager.avatarComponent;
  2393. _context2.prev = 1;
  2394. _context2.next = 4;
  2395. return this._room.modelManager.getApplicationConfig();
  2396. case 4:
  2397. e = _context2.sent;
  2398. t = e.avatars;
  2399. if (!t) {
  2400. _context2.next = 10;
  2401. break;
  2402. }
  2403. _context2.next = 9;
  2404. return avatarLoader.parse(this._room.sceneManager, t);
  2405. case 9:
  2406. return _context2.abrupt("return");
  2407. case 10:
  2408. return _context2.abrupt("return", Promise.reject("cannot find avatar config list"));
  2409. case 13:
  2410. _context2.prev = 13;
  2411. _context2.t0 = _context2["catch"](1);
  2412. return _context2.abrupt("return", (logger$1.error(_context2.t0), Promise.reject("avatar mananger init error!")));
  2413. case 16:
  2414. case "end":
  2415. return _context2.stop();
  2416. }
  2417. }
  2418. }, _callee2, this, [[1, 13]]);
  2419. }));
  2420. function init() {
  2421. return _init.apply(this, arguments);
  2422. }
  2423. return init;
  2424. }()
  2425. }, {
  2426. key: "handleAvatar",
  2427. value: function () {
  2428. var _handleAvatar2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  2429. var _this3 = this;
  2430. var r, t, n, o, _n, a;
  2431. return regenerator.wrap(function _callee3$(_context3) {
  2432. while (1) {
  2433. switch (_context3.prev = _context3.next) {
  2434. case 0:
  2435. if (!(this._room.viewMode === "simple" || !this._room.joined || !e.newUserStates)) {
  2436. _context3.next = 2;
  2437. break;
  2438. }
  2439. return _context3.abrupt("return");
  2440. case 2:
  2441. t = e.newUserStates;
  2442. if (((r = this._room._userAvatar) == null ? void 0 : r.isMoving) && this._room._userAvatar.motionType === MotionType.Run) {
  2443. n = t.filter(function (a) {
  2444. return a.userId === _this3._room.userId;
  2445. }), o = t.filter(function (a) {
  2446. return a.userId !== _this3._room.userId;
  2447. }).slice(0, 2);
  2448. t = n.concat(o);
  2449. }
  2450. if (e.getStateType === GetStateTypes.Event) {
  2451. this.syncAvatarsLength = (t || []).length;
  2452. _n = this._room.avatars.filter(function (s) {
  2453. return s.group == AvatarGroup.User;
  2454. });
  2455. _n.filter(function (s) {
  2456. return !(t != null && t.find(function (l) {
  2457. return l.userId == s.userId;
  2458. }));
  2459. }).forEach(function (s) {
  2460. _this3.removeAvatar(s.userId);
  2461. });
  2462. a = t.filter(function (s) {
  2463. return !_n.find(function (l) {
  2464. return l.userId == s.userId;
  2465. });
  2466. });
  2467. this._handleAvatar(a);
  2468. }
  2469. this._handleAvatar(t);
  2470. case 6:
  2471. case "end":
  2472. return _context3.stop();
  2473. }
  2474. }
  2475. }, _callee3, this);
  2476. }));
  2477. function handleAvatar(_x2) {
  2478. return _handleAvatar2.apply(this, arguments);
  2479. }
  2480. return handleAvatar;
  2481. }()
  2482. }, {
  2483. key: "_handleAvatar",
  2484. value: function () {
  2485. var _handleAvatar3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  2486. var _this4 = this;
  2487. return regenerator.wrap(function _callee4$(_context4) {
  2488. while (1) {
  2489. switch (_context4.prev = _context4.next) {
  2490. case 0:
  2491. e == null || e.forEach(function (t) {
  2492. var n, o, a, s, l, u, c, h, f;
  2493. var r = _this4._room.userId === t.userId;
  2494. if (((n = t.event) == null ? void 0 : n.type) === SyncEventType.ET_RemoveVisitor) {
  2495. var d = (a = (o = t.event) == null ? void 0 : o.removeVisitorEvent) == null ? void 0 : a.removeVisitorEvent,
  2496. _ = JSON.parse(safeDecodeURIComponent(((l = (s = t.event) == null ? void 0 : s.removeVisitorEvent) == null ? void 0 : l.extraInfo) || "")),
  2497. g = _.code,
  2498. m = _.msg;
  2499. d === RemoveVisitorType.RVT_ChangeToObserver ? _this4._room.audienceViewModeHook() : d === RemoveVisitorType.RVT_MoveOutOfTheRoom && _this4._room.leave(), _this4._room.emit("visitorStatusChanged", {
  2500. code: g,
  2501. msg: m
  2502. });
  2503. }
  2504. if (t.event && [SyncEventType.Appear, SyncEventType.Reset].includes(t.event.type) || !t.event) {
  2505. var _d = _this4.avatars.get(t.userId);
  2506. if (t.playerState.avatarId && (_d == null ? void 0 : _d.avatarId) !== t.playerState.avatarId && (_d = void 0, _this4.removeAvatar(t.userId)), _d) {
  2507. 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) {
  2508. var _2 = safeParseComponents(t.playerState.avatarComponents);
  2509. _d._changeComponents({
  2510. avatarComponents: _2,
  2511. mode: ChangeComponentsMode.Preview
  2512. });
  2513. }
  2514. } else {
  2515. var _t$playerState$player = t.playerState.player,
  2516. _3 = _t$playerState$player.position,
  2517. _g = _t$playerState$player.angle,
  2518. _m = t.playerState.avatarId,
  2519. v = t.playerState.prioritySync,
  2520. y = safelyJsonParse(t.playerState.extra);
  2521. if (!_m) return;
  2522. var b = safeParseComponents(t.playerState.avatarComponents),
  2523. T = safeDecodeURIComponent(t.playerState.nickName),
  2524. C = _this4.calculatePriority(t.userId, y);
  2525. _this4.addAvatar({
  2526. userId: t.userId,
  2527. isHost: t.playerState.isHost,
  2528. nickname: T,
  2529. avatarPosition: _3,
  2530. avatarRotation: _g,
  2531. avatarScale: t.playerState.avatarSize,
  2532. avatarId: _m,
  2533. avatarComponents: t.playerState.person === Person.First ? [] : b,
  2534. priority: C,
  2535. group: AvatarGroup.User,
  2536. prioritySync: v,
  2537. extraInfo: y
  2538. }).then(function () {
  2539. var A;
  2540. (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$1.info("userAvatarLoaded"));
  2541. }).catch(function (A) {
  2542. r && (_this4.xAvatarManager.setMainAvatar(t.userId), _this4._room.emit("userAvatarFailed", {
  2543. error: A
  2544. }), logger$1.error("userAvatarFailed", A));
  2545. });
  2546. }
  2547. }
  2548. 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) {
  2549. (h = t == null ? void 0 : t.event) != null && h.id && _this4._room.actionsHandler.confirmEvent(t.event.id);
  2550. var _d2 = _this4.avatars.get(t.userId);
  2551. _d2 && _d2.withModel && !_d2.isLoading && _this4.updateAvatarPositionAndRotation(t);
  2552. }
  2553. if (!r && ((f = t.event) == null ? void 0 : f.type) === SyncEventType.Rotate) {
  2554. var _d3 = _this4.avatars.get(t.userId);
  2555. _d3.statusSyncQueue.append({
  2556. type: QueueType.Rotate,
  2557. action: function action() {
  2558. return _d3.statusSync(t);
  2559. }
  2560. });
  2561. }
  2562. });
  2563. case 1:
  2564. case "end":
  2565. return _context4.stop();
  2566. }
  2567. }
  2568. }, _callee4);
  2569. }));
  2570. function _handleAvatar(_x3) {
  2571. return _handleAvatar3.apply(this, arguments);
  2572. }
  2573. return _handleAvatar;
  2574. }()
  2575. }, {
  2576. key: "calculatePriority",
  2577. value: function calculatePriority(e, t) {
  2578. var n;
  2579. return e === this._room.userId ? EAvatarRelationRank.Self : (n = this._room.options.firends) != null && n.includes(e) ? EAvatarRelationRank.Friend : EAvatarRelationRank.Stranger;
  2580. }
  2581. }, {
  2582. key: "updateAvatarPositionAndRotation",
  2583. value: function updateAvatarPositionAndRotation(e) {
  2584. var t, r;
  2585. if ((t = e == null ? void 0 : e.playerState) != null && t.player) {
  2586. var _e$playerState$player = e.playerState.player,
  2587. n = _e$playerState$player.position,
  2588. o = _e$playerState$player.angle;
  2589. var a = this.avatars.get(e.userId);
  2590. if (!a) return;
  2591. 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({
  2592. type: QueueType.Move,
  2593. action: function action() {
  2594. return a.statusSync(e);
  2595. }
  2596. }), e.renderInfo && a.isSelf) {
  2597. var _e$renderInfo = e.renderInfo,
  2598. s = _e$renderInfo.isMoving,
  2599. l = _e$renderInfo.isRotating;
  2600. this._updateAvatarMovingStatus({
  2601. id: e.userId,
  2602. isMoving: !!s,
  2603. isRotating: !!l
  2604. });
  2605. }
  2606. }
  2607. }
  2608. }, {
  2609. key: "addAvatar",
  2610. value: function () {
  2611. var _addAvatar = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e) {
  2612. 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;
  2613. return regenerator.wrap(function _callee5$(_context5) {
  2614. while (1) {
  2615. switch (_context5.prev = _context5.next) {
  2616. case 0:
  2617. 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;
  2618. g = this.avatars.get(t);
  2619. if (!g) {
  2620. _context5.next = 4;
  2621. break;
  2622. }
  2623. return _context5.abrupt("return", Promise.resolve(g));
  2624. case 4:
  2625. if (!(g = new xe.subAvatar({
  2626. userId: t,
  2627. isHost: r,
  2628. isSelf: _,
  2629. room: this._room,
  2630. avatarComponents: l,
  2631. avatarId: o,
  2632. nickname: s,
  2633. group: c
  2634. }), this.avatars.set(t, g), !g.withModel)) {
  2635. _context5.next = 6;
  2636. break;
  2637. }
  2638. return _context5.abrupt("return", (g.isLoading = !1, g.avatarLoadedHook(), this._room.emit("avatarChanged", {
  2639. avatars: this._room.avatars
  2640. }), g));
  2641. case 6:
  2642. _context5.next = 8;
  2643. return this._room.modelManager.getAvatarModelList();
  2644. case 8:
  2645. v = _context5.sent.find(function (b) {
  2646. return b.id === o;
  2647. });
  2648. y = Date.now();
  2649. if (v) {
  2650. _context5.next = 12;
  2651. break;
  2652. }
  2653. return _context5.abrupt("return", (this._room.emit("avatarChanged", {
  2654. avatars: this._room.avatars
  2655. }), this.avatars.delete(t), Promise.reject("no such avatar model with id: ".concat(o))));
  2656. case 12:
  2657. _context5.prev = 12;
  2658. _context5.next = 15;
  2659. return avatarComponentsModify(v, l);
  2660. case 15:
  2661. b = _context5.sent;
  2662. b = b.filter(function (A) {
  2663. return A.type != "pendant";
  2664. });
  2665. _context5.next = 19;
  2666. return avatarComponentsParser(v, b);
  2667. case 19:
  2668. T = _context5.sent;
  2669. _context5.next = 22;
  2670. return this.xAvatarManager.loadAvatar({
  2671. id: t,
  2672. avatarType: o,
  2673. priority: u,
  2674. avatarManager: this.xAvatarManager,
  2675. assets: T,
  2676. status: {
  2677. avatarPosition: n,
  2678. avatarRotation: a,
  2679. avatarScale: h
  2680. }
  2681. })._timeout(8e3, new TimeoutError$1("loadAvatar timeout(8s)"));
  2682. case 22:
  2683. C = _context5.sent;
  2684. 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", {
  2685. avatars: this._room.avatars
  2686. }), s && g._setNickname(s), t === this._room.userId && (logger$1.infoAndReportMeasurement({
  2687. metric: "avatarLoadDuration",
  2688. startTime: y,
  2689. group: "costs"
  2690. }), logger$1.infoAndReportMeasurement({
  2691. metric: "avatarLoadAt",
  2692. startTime: this._room._startTime,
  2693. group: "costs"
  2694. })), g));
  2695. case 26:
  2696. _context5.prev = 26;
  2697. _context5.t0 = _context5["catch"](12);
  2698. return _context5.abrupt("return", (g.isLoading = !1, this._room.emit("avatarChanged", {
  2699. avatars: this._room.avatars
  2700. }), logger$1.error(_context5.t0), Promise.reject(_context5.t0)));
  2701. case 29:
  2702. case "end":
  2703. return _context5.stop();
  2704. }
  2705. }
  2706. }, _callee5, this, [[12, 26]]);
  2707. }));
  2708. function addAvatar(_x4) {
  2709. return _addAvatar.apply(this, arguments);
  2710. }
  2711. return addAvatar;
  2712. }()
  2713. }, {
  2714. key: "removeAvatar",
  2715. value: function removeAvatar(e) {
  2716. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
  2717. var r = this.avatars.get(e);
  2718. if (!!r) {
  2719. if (r.removeWhenDisconnected || t) {
  2720. r.xAvatar && this.xAvatarManager.deleteAvatar(r.xAvatar), this.avatars.delete(e), this._room.emit("avatarChanged", {
  2721. avatars: this._room.avatars
  2722. });
  2723. return;
  2724. }
  2725. r.setConnectionStatus(!0);
  2726. }
  2727. }
  2728. }, {
  2729. key: "clearOtherUsers",
  2730. value: function clearOtherUsers() {
  2731. var _this5 = this;
  2732. this.avatars.forEach(function (e) {
  2733. !e.isSelf && e.group === AvatarGroup.User && _this5.removeAvatar(e.userId);
  2734. });
  2735. }
  2736. }, {
  2737. key: "_updateAvatarMovingStatus",
  2738. value: function () {
  2739. var _updateAvatarMovingStatus2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  2740. var t, r, n, o, a, _a;
  2741. return regenerator.wrap(function _callee6$(_context6) {
  2742. while (1) {
  2743. switch (_context6.prev = _context6.next) {
  2744. case 0:
  2745. t = e.id, r = e.isMoving, n = e.isRotating, o = this.avatars.get(t);
  2746. if (!!o) {
  2747. if (o.isRotating !== n) {
  2748. o.isRotating = n;
  2749. a = "Idle";
  2750. n && (a = "Walking", o.motionType === MotionType.Run && (a = "Running")), o._playAnimation(a, !0, !0), logger$1.infoAndReportMeasurement({
  2751. startTime: Date.now(),
  2752. value: 0,
  2753. metric: n ? "userAvatarStartRotating" : "userAvatarStopRotating",
  2754. extra: {
  2755. motionType: o.motionType,
  2756. moveToExtra: this._room.moveToExtra
  2757. }
  2758. });
  2759. }
  2760. if (o.isMoving !== r) {
  2761. o.isMoving = r;
  2762. _a = "Idle";
  2763. r && (_a = "Walking", o.motionType === MotionType.Run && (_a = "Running")), r ? (o.avatarStartMovingHook(), o.emit("startMoving", {
  2764. target: o,
  2765. extra: this._room.moveToExtra
  2766. })) : (o.avatarStopMovingHook(), o.emit("stopMoving", {
  2767. target: o,
  2768. extra: this._room.moveToExtra
  2769. })), o._playAnimation(_a, !0, !0), logger$1.infoAndReportMeasurement({
  2770. startTime: Date.now(),
  2771. value: 0,
  2772. metric: r ? "userAvatarStartMoving" : "userAvatarStopMoving",
  2773. extra: {
  2774. motionType: o.motionType,
  2775. moveToExtra: this._room.moveToExtra
  2776. }
  2777. });
  2778. }
  2779. }
  2780. case 2:
  2781. case "end":
  2782. return _context6.stop();
  2783. }
  2784. }
  2785. }, _callee6, this);
  2786. }));
  2787. function _updateAvatarMovingStatus(_x5) {
  2788. return _updateAvatarMovingStatus2.apply(this, arguments);
  2789. }
  2790. return _updateAvatarMovingStatus;
  2791. }()
  2792. }, {
  2793. key: "_usersStatistics",
  2794. value: function _usersStatistics() {
  2795. var _this6 = this;
  2796. this.on("userAvatarLoaded", function () {
  2797. window.setInterval(function () {
  2798. var e = _this6._room.avatars.filter(function (r) {
  2799. return r.group === AvatarGroup.User;
  2800. }).length || 0,
  2801. t = _this6._room.avatars.filter(function (r) {
  2802. return r.group === AvatarGroup.User && r.isRender;
  2803. }).length || 0;
  2804. _this6._room.stats.assign({
  2805. userNum: e,
  2806. syncUserNum: _this6.syncAvatarsLength,
  2807. renderedUserNum: t
  2808. });
  2809. }, 3e3);
  2810. });
  2811. }
  2812. }]);
  2813. return XverseAvatarManager;
  2814. }(EventEmitter);
  2815. var PathManager = /*#__PURE__*/function () {
  2816. function PathManager() {
  2817. _classCallCheck(this, PathManager);
  2818. this.currentArea = '';
  2819. this.currentPathName = '';
  2820. this.currentAttitude = '';
  2821. this.speed = 0;
  2822. }
  2823. _createClass(PathManager, [{
  2824. key: "getSpeed",
  2825. value: function getSpeed(e) {
  2826. var t = {
  2827. guangchang: {
  2828. [MotionType.Walk]: 17,
  2829. [MotionType.Run]: 51
  2830. },
  2831. tower: {
  2832. [MotionType.Walk]: 12.5,
  2833. [MotionType.Run]: 25
  2834. },
  2835. zhiboting: {
  2836. [MotionType.Walk]: 12.5,
  2837. [MotionType.Run]: 25
  2838. },
  2839. youxiting: {
  2840. [MotionType.Walk]: 12.5,
  2841. [MotionType.Run]: 25
  2842. },
  2843. diqing: {
  2844. [MotionType.Walk]: 12.5,
  2845. [MotionType.Run]: 25
  2846. }
  2847. },
  2848. r = t[this.currentArea] || t.guangchang;
  2849. return this.speed = r[e] * 30, this.speed;
  2850. }
  2851. }]);
  2852. return PathManager;
  2853. }();
  2854. var CameraStates = {
  2855. Normal: 0,
  2856. ItemView: 1,
  2857. CGView: 2,
  2858. PathView: 3
  2859. };
  2860. var Person$1 = {
  2861. Third: 0,
  2862. First: 1
  2863. };
  2864. var EImageQuality = {
  2865. low: 0,
  2866. mid: 1,
  2867. high: 2
  2868. };
  2869. var Actions = {
  2870. Clicking: 1,
  2871. PlayCG: 6,
  2872. Back: 7,
  2873. ChangeRoom: 8,
  2874. ChangeSkin: 13,
  2875. Joystick: 15,
  2876. Transfer: 18,
  2877. GetOnVehicle: 22,
  2878. GetOffVehicle: 23,
  2879. StopMoving: 34,
  2880. UnaryActionLine: 1e3,
  2881. Init: 1001,
  2882. Exit: 1002,
  2883. SetIFrameInfo: 1003,
  2884. GetNeighborPoints: 1004,
  2885. ReserveSeat: 1005,
  2886. GetReserveStatus: 1006,
  2887. ChangeNickname: 1007,
  2888. ChangeBitRateInfo: 1008,
  2889. Echo: 1009,
  2890. SetPlayerState: 1010,
  2891. TurnTo: 1011,
  2892. TurnToFace: 1012,
  2893. RotateTo: 1013,
  2894. Rotation: 1014,
  2895. CameraTurnTo: 1015,
  2896. ConfirmEvent: 1016,
  2897. Broadcast: 1017,
  2898. NotifyActionLine: 2e4,
  2899. AudienceChangeToVisitor: 1020,
  2900. VisitorChangeToAudience: 1021,
  2901. RemoveVisitor: 1022,
  2902. GetUserWithAvatar: 1023
  2903. };
  2904. 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); }; }
  2905. 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; } }
  2906. var Camera = /*#__PURE__*/function (_EventEmitter) {
  2907. _inherits(Camera, _EventEmitter);
  2908. var _super = _createSuper$j(Camera);
  2909. function Camera(e) {
  2910. var _this;
  2911. _classCallCheck(this, Camera);
  2912. _this = _super.call(this);
  2913. _this.initialFov = 0;
  2914. _this._state = CameraStates.Normal;
  2915. _this._person = Person$1.Third;
  2916. _this._cameraFollowing = !0;
  2917. _this._room = e;
  2918. return _this;
  2919. }
  2920. _createClass(Camera, [{
  2921. key: "checkPointOnLeftOrRight",
  2922. value: function checkPointOnLeftOrRight(e) {
  2923. var t = ue4Position2Xverse(e);
  2924. if (!t || this.checkPointInView(e)) return;
  2925. var o = this._room.scene.activeCamera;
  2926. if (!o) return;
  2927. var a = [o.target.x, o.target.y, o.target.z],
  2928. s = [o.position.x, o.position.y, o.position.z],
  2929. l = t.x,
  2930. u = t.y,
  2931. c = t.z,
  2932. h = calNormVector(s, a),
  2933. f = calNormVector(s, [l, u, c]);
  2934. return vectorCrossMulti(h, f) < 0 ? Direction.Right : Direction.Left;
  2935. }
  2936. }, {
  2937. key: "checkPointInView",
  2938. value: function checkPointInView(e, t, r) {
  2939. var n = ue4Position2Xverse({
  2940. x: e,
  2941. y: t,
  2942. z: r
  2943. });
  2944. if (!n) return !1;
  2945. for (var o = 0; o < 6; o++) {
  2946. if (this._room.scene.frustumPlanes[o].dotCoordinate(n) < 0) return !1;
  2947. }
  2948. return !0;
  2949. }
  2950. }, {
  2951. key: "person",
  2952. get: function get() {
  2953. return this._person;
  2954. }
  2955. }, {
  2956. key: "state",
  2957. get: function get() {
  2958. return this._state;
  2959. }
  2960. }, {
  2961. key: "pose",
  2962. get: function get() {
  2963. return this._room.currentClickingState.camera;
  2964. }
  2965. }, {
  2966. key: "cameraFollowing",
  2967. get: function get() {
  2968. return this._cameraFollowing;
  2969. },
  2970. set: function set(e) {
  2971. logger$1.info("cameraFollowing setter", e), this.setCameraFollowing({
  2972. isFollowHost: e
  2973. });
  2974. }
  2975. }, {
  2976. key: "setCameraFollowing",
  2977. value: function setCameraFollowing(_ref) {
  2978. _ref.isFollowHost;
  2979. }
  2980. }, {
  2981. key: "handleRenderInfo",
  2982. value: function handleRenderInfo(e) {
  2983. var t = e.renderInfo.cameraStateType,
  2984. r = this._room.sceneManager;
  2985. if (t !== this._state && (this._state = t, logger$1.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", {
  2986. state: t
  2987. })), this._room.isHost) return;
  2988. var n = e.playerState.isFollowHost;
  2989. !!n !== this._cameraFollowing && (this._cameraFollowing = !!n, this.emit("cameraFollowingChanged", {
  2990. cameraFollowing: !!n
  2991. }));
  2992. }
  2993. }, {
  2994. key: "setCameraState",
  2995. value: function setCameraState(_ref2) {
  2996. var e = _ref2.state;
  2997. if (this._state === e) {
  2998. logger$1.warn("You are already in ".concat(CameraStates[e], " camera state"));
  2999. return;
  3000. }
  3001. e === CameraStates.Normal || this._state === CameraStates.ItemView && logger$1.warn("CloseUp camera state can only be triggerd by room internally");
  3002. }
  3003. }, {
  3004. key: "turnToFace",
  3005. value: function turnToFace(_ref3) {
  3006. var _ref3$extra = _ref3.extra,
  3007. e = _ref3$extra === void 0 ? "" : _ref3$extra,
  3008. _ref3$offset = _ref3.offset,
  3009. t = _ref3$offset === void 0 ? 0 : _ref3$offset;
  3010. var r = {
  3011. action_type: Actions.TurnToFace,
  3012. turn_to_face_action: {
  3013. offset: t
  3014. }
  3015. };
  3016. return this.emit("viewChanged", {
  3017. extra: e
  3018. }), this._room.actionsHandler.sendData({
  3019. data: r
  3020. });
  3021. }
  3022. }, {
  3023. key: "isInDefaultView",
  3024. value: function isInDefaultView() {
  3025. if (!this._room.isHost) {
  3026. logger$1.warn("It is recommended to call the function on the host side");
  3027. return;
  3028. }
  3029. if (!this._room._currentClickingState) return logger$1.error("CurrentState should not be empty"), !1;
  3030. var _this$_room$_currentC = this._room._currentClickingState,
  3031. e = _this$_room$_currentC.camera,
  3032. t = _this$_room$_currentC.player;
  3033. return Math.abs(t.angle.yaw - 180 - e.angle.yaw) % 360 <= 4;
  3034. }
  3035. }, {
  3036. key: "screenShot",
  3037. value: function () {
  3038. var _screenShot = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_ref4) {
  3039. var e, _ref4$autoSave, t, r, n, o;
  3040. return regenerator.wrap(function _callee$(_context) {
  3041. while (1) {
  3042. switch (_context.prev = _context.next) {
  3043. case 0:
  3044. e = _ref4.name, _ref4$autoSave = _ref4.autoSave, t = _ref4$autoSave === void 0 ? !1 : _ref4$autoSave;
  3045. r = this._room.scene.getEngine(), n = this._room.scene.activeCamera;
  3046. _context.prev = 2;
  3047. this._room.sceneManager.setImageQuality(EImageQuality.high);
  3048. _context.next = 6;
  3049. return CreateScreenshotAsync(r, n, {
  3050. precision: 1
  3051. });
  3052. case 6:
  3053. o = _context.sent;
  3054. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), t === !0 && downloadFileByBase64(o, e), Promise.resolve(o)));
  3055. case 10:
  3056. _context.prev = 10;
  3057. _context.t0 = _context["catch"](2);
  3058. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), Promise.reject(_context.t0)));
  3059. case 13:
  3060. case "end":
  3061. return _context.stop();
  3062. }
  3063. }
  3064. }, _callee, this, [[2, 10]]);
  3065. }));
  3066. function screenShot(_x) {
  3067. return _screenShot.apply(this, arguments);
  3068. }
  3069. return screenShot;
  3070. }()
  3071. }, {
  3072. key: "changeToFirstPerson",
  3073. value: function changeToFirstPerson(e, t, r) {
  3074. var _this2 = this;
  3075. var n = e.camera,
  3076. o = e.player,
  3077. a = e.attitude,
  3078. s = e.areaName,
  3079. l = e.pathName;
  3080. return this._room.actionsHandler.requestPanorama({
  3081. camera: n,
  3082. player: o,
  3083. attitude: a,
  3084. areaName: s,
  3085. pathName: l
  3086. }, t, r).then(function () {
  3087. _this2._room.networkController.rtcp.workers.changePanoMode(!0);
  3088. var _ref5 = o || {},
  3089. u = _ref5.position,
  3090. c = _ref5.angle;
  3091. _this2._room.sceneManager.cameraComponent.changeToFirstPersonView({
  3092. position: u,
  3093. rotation: c
  3094. });
  3095. });
  3096. }
  3097. }, {
  3098. key: "setPerson",
  3099. value: function setPerson(e) {
  3100. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  3101. camera: this._room._currentClickingState.camera,
  3102. player: this._room._currentClickingState.player
  3103. };
  3104. var r = Date.now();
  3105. return this._setPerson(e, t).then(function (n) {
  3106. return logger$1.infoAndReportMeasurement({
  3107. tag: Person$1[e],
  3108. startTime: r,
  3109. metric: "setPerson"
  3110. }), n;
  3111. }).catch(function (n) {
  3112. return logger$1.infoAndReportMeasurement({
  3113. tag: Person$1[e],
  3114. startTime: r,
  3115. metric: "setPerson",
  3116. error: n
  3117. }), Promise.reject(n);
  3118. });
  3119. }
  3120. }, {
  3121. key: "_setPerson",
  3122. value: function _setPerson(e) {
  3123. var _this3 = this;
  3124. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  3125. camera: this._room._currentClickingState.camera,
  3126. player: this._room._currentClickingState.player
  3127. };
  3128. 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({
  3129. camera: t.camera,
  3130. player: t.player,
  3131. tag: "setPerson"
  3132. }).then(function () {
  3133. var o, a;
  3134. _this3._person = e, (o = _this3._room._userAvatar) == null || o.hide();
  3135. var _ref6 = ((a = _this3._room.currentClickingState) == null ? void 0 : a.camera) || {},
  3136. r = _ref6.position,
  3137. n = _ref6.angle;
  3138. !r || !n || _this3._room.sceneManager.cameraComponent.changeToFirstPersonView({
  3139. position: r,
  3140. rotation: n
  3141. });
  3142. }) : this._room.panorama.exit({
  3143. camera: t.camera,
  3144. player: t.player
  3145. }).then(function () {
  3146. var r, n;
  3147. _this3._person = e, (r = _this3._room._userAvatar) != null && r.xAvatar && ((n = _this3._room._userAvatar) == null || n.xAvatar.show());
  3148. });
  3149. }
  3150. }, {
  3151. key: "setCameraPose",
  3152. value: function setCameraPose(e) {
  3153. this._room.sceneManager.cameraComponent.setCameraPose({
  3154. position: e.position,
  3155. rotation: e.angle
  3156. });
  3157. }
  3158. }, {
  3159. key: "setMainCameraRotationLimit",
  3160. value: function setMainCameraRotationLimit(e) {
  3161. var t = e.limitAxis,
  3162. r = e.limitRotation;
  3163. this._room.sceneManager.cameraComponent.setMainCameraRotationLimit(t, r);
  3164. }
  3165. }]);
  3166. return Camera;
  3167. }(EventEmitter);
  3168. 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); }; }
  3169. 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; } }
  3170. var numberFormat = new Intl.NumberFormat(window.navigator.language, {
  3171. maximumFractionDigits: 0
  3172. });
  3173. var Stats = /*#__PURE__*/function (_EventEmitter) {
  3174. _inherits(Stats, _EventEmitter);
  3175. var _super = _createSuper$i(Stats);
  3176. function Stats(e) {
  3177. var _this;
  3178. _classCallCheck(this, Stats);
  3179. _this = _super.call(this);
  3180. _this._netInterval = null;
  3181. _this._disabled = !1;
  3182. _this._show = !1;
  3183. _this._aggregatedStats = {};
  3184. _this._displayElement = null;
  3185. _this._extraStats = {};
  3186. _this._networkSamples = [];
  3187. _this.externalStats = null;
  3188. _this.constructedTime = null;
  3189. _this.room = e, _this.constructedTime = Date.now(), _this._interval = window.setInterval(function () {
  3190. var t, r, n;
  3191. _this._disabled || _this.onStats((n = (r = (t = e.networkController) == null ? void 0 : t.rtcp) == null ? void 0 : r.workers) == null ? void 0 : n.uploadDataToServer());
  3192. }, 1e3), _this._netInterval = window.setInterval(function () {
  3193. _this.getIsWeakNet();
  3194. }, NET_INTERVAL * 1e3);
  3195. return _this;
  3196. }
  3197. _createClass(Stats, [{
  3198. key: "isShow",
  3199. get: function get() {
  3200. return this._show;
  3201. }
  3202. }, {
  3203. key: "assign",
  3204. value: function assign(e) {
  3205. Object.assign(this._extraStats, e), ((e == null ? void 0 : e.hb) || (e == null ? void 0 : e.rtt)) && this.startStatsNetSamples();
  3206. }
  3207. }, {
  3208. key: "appendExternalStats",
  3209. value: function appendExternalStats(e) {
  3210. var _this2 = this;
  3211. var t = {};
  3212. if (!e || typeof e != "object") {
  3213. console.warn("appendExternalStats should be plain object");
  3214. return;
  3215. }
  3216. Object.keys(e).forEach(function (r) {
  3217. Object.prototype.hasOwnProperty.call(_this2._aggregatedStats, r) ? console.warn("".concat(r, " is duplicate with internal stats")) : t[r] = e[r];
  3218. }), !(Object.keys(t).length > 10) && (this.externalStats = t);
  3219. }
  3220. }, {
  3221. key: "getRtt",
  3222. value: function getRtt() {
  3223. var e = this._extraStats.rtt;
  3224. return typeof e != "number" ? 0 : e > 999 ? 999 : e;
  3225. }
  3226. }, {
  3227. key: "enable",
  3228. value: function enable() {
  3229. this._disabled = !1;
  3230. }
  3231. }, {
  3232. key: "disable",
  3233. value: function disable() {
  3234. this._disabled = !0;
  3235. }
  3236. }, {
  3237. key: "disableNet",
  3238. value: function disableNet() {
  3239. this._netInterval && window.clearInterval(this._netInterval);
  3240. }
  3241. }, {
  3242. key: "show",
  3243. value: function show() {
  3244. this._show = !0, this._render();
  3245. }
  3246. }, {
  3247. key: "hide",
  3248. value: function hide() {
  3249. this._show = !1, this._displayElement && document.body.removeChild(this._displayElement), this._displayElement = null;
  3250. }
  3251. }, {
  3252. key: "getIsWeakNet",
  3253. value: function getIsWeakNet() {
  3254. var _this3 = this;
  3255. var e = !1;
  3256. var t = this._networkSamples.length - 1;
  3257. if (t < 0) return;
  3258. var r = this._networkSamples[t].time,
  3259. n = this._networkSamples[0].time,
  3260. o = r - n,
  3261. a = 1e3 * (DURATION - 2);
  3262. if (o < a) return;
  3263. var s = this._networkSamples.map(function (g) {
  3264. return _this3.isNetDelay(g, "rtt");
  3265. }),
  3266. l = this._networkSamples.map(function (g) {
  3267. return _this3.isNetDelay(g, "hb");
  3268. }),
  3269. u = s.reduce(function (g, m) {
  3270. return g + m;
  3271. }, 0),
  3272. c = l.reduce(function (g, m) {
  3273. return g + m;
  3274. }, 0),
  3275. h = Math.floor(u / this._networkSamples.length) * 100,
  3276. f = Math.floor(c / this._networkSamples.length) * 100,
  3277. d = 70;
  3278. (h >= d || f >= d) && (e = !0);
  3279. var _ = this.room.viewMode === "observer" || this.room.viewMode === "serverless";
  3280. e && !_ && (logger$1.infoAndReportMeasurement({
  3281. metric: "weakNetwork",
  3282. startTime: Date.now(),
  3283. extra: {
  3284. msg: this._networkSamples.slice(20),
  3285. netDelayRTTValues: u,
  3286. netDelayHBValues: c
  3287. }
  3288. }), this.emit("weakNetwork"));
  3289. }
  3290. }, {
  3291. key: "startStatsNetSamples",
  3292. value: function startStatsNetSamples() {
  3293. var _this$_extraStats = this._extraStats,
  3294. e = _this$_extraStats.rtt,
  3295. t = _this$_extraStats.hb;
  3296. if (e || t) {
  3297. var r = {
  3298. rtt: e,
  3299. hb: t,
  3300. time: new Date().getTime()
  3301. };
  3302. this._networkSamples.push(r);
  3303. var n = this._networkSamples.length - 1;
  3304. if (n < 0) return;
  3305. var o = this._networkSamples[n].time,
  3306. a = 1e3 * DURATION;
  3307. this._networkSamples = this._networkSamples.filter(function (s) {
  3308. return s.time > o - a;
  3309. });
  3310. }
  3311. }
  3312. }, {
  3313. key: "isNetDelay",
  3314. value: function isNetDelay(e, t) {
  3315. return t === "rtt" ? e.rtt > RTT_MAX_VALUE ? 1 : 0 : t === "hb" && e.hb > HB_MAX_VALUE ? 1 : 0;
  3316. }
  3317. }, {
  3318. key: "getPreciesTimer",
  3319. value: function getPreciesTimer(e, t) {
  3320. var r = t * 1e3,
  3321. n = new Date().getTime();
  3322. var o = 0;
  3323. o++;
  3324. var a = new Date().getTime() - (n + o * 1e3),
  3325. s = r - a,
  3326. l = setTimeout(function () {
  3327. clearTimeout(l), e();
  3328. }, s);
  3329. }
  3330. }, {
  3331. key: "_render",
  3332. value: function _render() {
  3333. var c, h, f, d, _, g, m, v, y, b, T, C, A, S, P, R, M, x, I, w;
  3334. if (!this._aggregatedStats) return;
  3335. 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));
  3336. var e = [],
  3337. t = Date.now() - this.constructedTime,
  3338. r = Math.floor(t / 1e3 % 60),
  3339. n = Math.floor(t / (1e3 * 60) % 60),
  3340. o = Math.floor(t / (1e3 * 60 * 60) % 24),
  3341. a = o < 10 ? "0" + o.toString() : o.toString(),
  3342. s = n < 10 ? "0" + n : n,
  3343. l = r < 10 ? "0" + r : r;
  3344. e.push({
  3345. key: new Date(Math.floor(this._aggregatedStats.timestamp || 0)).toLocaleString("en-GB"),
  3346. value: a + ":" + s + ":" + l
  3347. }), e.push({
  3348. key: "rtt: " + this._extraStats.rtt + " hb: " + this._extraStats.hb,
  3349. value: "FPS: " + this._extraStats.fps + " avatar: " + ((c = this.room._userAvatar) == null ? void 0 : c.state)
  3350. }), e.push({
  3351. key: "SDK: " + Xverse$1.SUB_PACKAGE_VERSION,
  3352. value: "ENGINE:" + VERSION$1 + " uid:" + this._extraStats.userId
  3353. }), e.push({
  3354. key: "\u540C\u6B65/\u6709\u6548/\u663E\u793A\u73A9\u5BB6",
  3355. value: "".concat(this._extraStats.syncUserNum || 0, "/").concat(this._extraStats.userNum || 0, "/").concat(this._extraStats.renderedUserNum || 0)
  3356. }), e.push({
  3357. key: "media/meta bitrate(kbps)",
  3358. value: numberFormat.format(this._aggregatedStats.mediaBitrate || 0) + "/" + numberFormat.format(this._aggregatedStats.metaBitrate || 0)
  3359. }), e.push({
  3360. key: ":----------------Decoding---------------",
  3361. value: ""
  3362. }), e.push({
  3363. key: "-max/avg decodeTime(ms)",
  3364. value: numberFormat.format(this._aggregatedStats.decodeTimeMaxFrame || 0) + "/" + numberFormat.format(this._aggregatedStats.decodeTimePerFrame || 0)
  3365. }), e.push({
  3366. key: "-frmAwait/Lost/Drop",
  3367. 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
  3368. }), e.push({
  3369. key: ":----------------FrameLoop-------------",
  3370. value: ""
  3371. }), e.push({
  3372. key: "interval(max/avg/>40)",
  3373. 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
  3374. }), e.push({
  3375. key: "systemStuck",
  3376. value: this._extraStats.systemStuckCnt
  3377. }), e.push({
  3378. key: "--update",
  3379. value: (this._aggregatedStats.maxGraphicTime.toFixed(1) || 0) + "/" + (((d = this._aggregatedStats.averageGraphicTime) == null ? void 0 : d.toFixed(0)) || 0)
  3380. }), e.push({
  3381. key: "--timeout",
  3382. value: (((_ = this._extraStats.maxTimeoutTime) == null ? void 0 : _.toFixed(1)) || 0) + "/" + ((g = this._extraStats.avgTimeoutTime) == null ? void 0 : g.toFixed(0)) || 0
  3383. }), e.push({
  3384. key: "--render",
  3385. value: (((m = this._extraStats.maxRenderFrameTime) == null ? void 0 : m.toFixed(1)) || 0) + "/" + (((v = this._extraStats.renderFrameTime) == null ? void 0 : v.toFixed(0)) || 0)
  3386. }), e.push({
  3387. key: "---anim/regBR/clip(avg ms)",
  3388. value: (this._extraStats.animationTime.toFixed(2) || 0) + " / " + (this._extraStats.registerBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.meshSelectTime.toFixed(2) || 0)
  3389. }), e.push({
  3390. key: "---anim/regBR/clip(max ms)",
  3391. value: (this._extraStats.maxAnimationTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxMeshSelectTime.toFixed(2) || 0)
  3392. }), e.push({
  3393. key: "---rTR/drC/regAF(avg ms)",
  3394. value: (this._extraStats.renderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.drawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.registerAfterRenderTime.toFixed(2) || 0)
  3395. }), e.push({
  3396. key: "---rTR/drC/regAF(max ms)",
  3397. value: (this._extraStats.maxRenderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxDrawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterAfterRenderTime.toFixed(2) || 0)
  3398. }), e.push({
  3399. key: "--tri/drC/pati/bones/anim(Num)",
  3400. 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)
  3401. }), e.push({
  3402. key: "--rootN/mesh/geo/tex/mat(Num)",
  3403. 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)
  3404. }), e.push({
  3405. key: "--registerBF/AF(Num)",
  3406. value: (this._extraStats.registerBeforeCount.toFixed(0) || 0) + " / " + (this._extraStats.registerAfterCount.toFixed(0) || 0)
  3407. }), e.push({
  3408. key: ":----------------Rotation-------------------",
  3409. value: ""
  3410. }), e.push({
  3411. key: "Total(ms/miss)",
  3412. value: (((y = this._aggregatedStats.avgOverallTime) == null ? void 0 : y.toFixed(2)) || 0) + "/" + (this._aggregatedStats.responseMissPs + this._aggregatedStats.processMissPs + this._aggregatedStats.displayMissPs)
  3413. }), e.push({
  3414. key: "--rotateRsp",
  3415. value: (((b = this._aggregatedStats.avgResponseTime) == null ? void 0 : b.toFixed(1)) || 0) + "/" + this._aggregatedStats.responseMissPs
  3416. }), e.push({
  3417. key: "--rotateProc",
  3418. value: (((T = this._aggregatedStats.avgProcessTime) == null ? void 0 : T.toFixed(1)) || 0) + "/" + this._aggregatedStats.processMissPs
  3419. }), e.push({
  3420. key: "--rotateShow",
  3421. value: (((C = this._aggregatedStats.avgDisplayTime) == null ? void 0 : C.toFixed(1)) || 0) + "/" + this._aggregatedStats.displayMissPs
  3422. }), ((A = this.room._userAvatar) == null ? void 0 : A.state) == "moving", e.push({
  3423. key: ":----------------Move----------------------",
  3424. value: ""
  3425. }), e.push({
  3426. key: "-startDelay",
  3427. 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)
  3428. }), (((S = this.room._userAvatar) == null ? void 0 : S.state) == "moving" || this._aggregatedStats.moveEvent == "GetOnAirship" || this._aggregatedStats.moveEvent == "GetOnVehicle") && e.push({
  3429. key: "-srvInterFrm(max/avg)",
  3430. value: (this._aggregatedStats.maxServerDiff || 0) + "/" + (this._aggregatedStats.avgServerDiff.toFixed(1) || 0)
  3431. }), e.push({
  3432. key: "-interFrameDelay",
  3433. value: "(max/avg/jank)"
  3434. }), e.push({
  3435. key: "--toDisplay",
  3436. 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)
  3437. }), e.push({
  3438. key: "--received",
  3439. 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)
  3440. }), e.push({
  3441. key: "--decoded",
  3442. 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)
  3443. }), e.push({
  3444. key: ":----------------DevInfo-----------------",
  3445. value: ""
  3446. }), e.push({
  3447. key: "sd",
  3448. value: (this._aggregatedStats.sdMoveResponseLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveProcessLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveDisplayLongTime.toFixed(1) || 0)
  3449. }), e.push({
  3450. key: "----hardwareInfo",
  3451. value: this._extraStats.hardwareInfo
  3452. });
  3453. var u = "";
  3454. for (var _i = 0, _e = e; _i < _e.length; _i++) {
  3455. var O = _e[_i];
  3456. u += "<div><span>".concat(O.key, "</span>: <span>").concat(O.value, "</span> </div>");
  3457. }
  3458. this._displayElement.innerHTML = u;
  3459. }
  3460. }, {
  3461. key: "onStats",
  3462. value: function onStats(e) {
  3463. var _this4 = this;
  3464. var n;
  3465. if (!e) return;
  3466. var t = {},
  3467. r = this;
  3468. 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) {
  3469. t[o] = _this4.externalStats[o];
  3470. }), r._aggregatedStats = t, this.emit("stats", {
  3471. stats: t
  3472. });
  3473. }
  3474. }]);
  3475. return Stats;
  3476. }(EventEmitter);
  3477. 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); }; }
  3478. 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; } }
  3479. var EventsManager = /*#__PURE__*/function (_EventEmitter) {
  3480. _inherits(EventsManager, _EventEmitter);
  3481. var _super = _createSuper$h(EventsManager);
  3482. function EventsManager() {
  3483. var _this;
  3484. _classCallCheck(this, EventsManager);
  3485. _this = _super.apply(this, arguments);
  3486. E(_assertThisInitialized(_this), "events", new Map());
  3487. E(_assertThisInitialized(_this), "specialEvents", new Map());
  3488. return _this;
  3489. }
  3490. _createClass(EventsManager, [{
  3491. key: "remove",
  3492. value: function remove(e, t, r, n) {
  3493. if (this.specialEvents.has(e) && !n && t === Codes$1.Success) return;
  3494. this.events.get(e) && (this.emit(e, {
  3495. code: t,
  3496. data: r
  3497. }), this.events.delete(e), this.specialEvents.delete(e));
  3498. }
  3499. }, {
  3500. key: "track",
  3501. value: function () {
  3502. var _track = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  3503. var _this2 = this;
  3504. var r, _ref, n, _ref$noReport, o, a, s, l, u, c;
  3505. return regenerator.wrap(function _callee$(_context) {
  3506. while (1) {
  3507. switch (_context.prev = _context.next) {
  3508. case 0:
  3509. r = e.traceId;
  3510. this.emitTraceIdToDecoder(e);
  3511. _ref = t || {}, n = _ref.sampleRate, _ref$noReport = _ref.noReport, o = _ref$noReport === void 0 ? !1 : _ref$noReport, a = _ref.special;
  3512. if (!(n && Math.random() > n)) {
  3513. _context.next = 5;
  3514. break;
  3515. }
  3516. return _context.abrupt("return", Promise.resolve());
  3517. case 5:
  3518. s = Actions[e.event] + "Action", l = e.tag;
  3519. this.events.set(r, !0), a && this.specialEvents.set(r, !0);
  3520. u = Date.now();
  3521. c = null;
  3522. return _context.abrupt("return", new Promise(function (h, f) {
  3523. if (o) return _this2.off(r), _this2.events.delete(r), h(void 0);
  3524. _this2.on(r, function (_ref2) {
  3525. var _ = _ref2.code,
  3526. g = _ref2.data,
  3527. m = _ref2.msg;
  3528. if (_ === Codes$1.Success) h(g), _this2.off(r), logger$1.infoAndReportMeasurement({
  3529. metric: s,
  3530. tag: l,
  3531. extra: e.extra,
  3532. startTime: u,
  3533. traceId: r
  3534. });else {
  3535. if (_ === Codes$1.ActionMaybeDelay) return;
  3536. if (_ === Codes$1.DoActionBlocked && e.event === Actions.Rotation) {
  3537. logger$1.debug(s + " response code: " + _);
  3538. return;
  3539. }
  3540. var v = getErrorByCode(_),
  3541. y = new v(m);
  3542. _this2.off(r), f(y), _this2.emit("actionResponseError", {
  3543. error: y,
  3544. event: e,
  3545. tag: l
  3546. }), logger$1.infoAndReportMeasurement({
  3547. metric: s,
  3548. tag: l,
  3549. extra: e.extra,
  3550. error: y,
  3551. startTime: u,
  3552. traceId: r
  3553. });
  3554. }
  3555. });
  3556. var d = e.timeout || 2e3;
  3557. c = window.setTimeout(function () {
  3558. if (c && clearTimeout(c), !_this2.events.get(r)) return;
  3559. var _ = new ActionResponseTimeoutError("".concat(s, " timeout in ").concat(d, "ms"));
  3560. _this2.emit("actionResponseTimeout", {
  3561. error: _,
  3562. event: e,
  3563. tag: l
  3564. }), f(_), _this2.events.delete(r), _this2.off(r), logger$1.infoAndReportMeasurement({
  3565. metric: s,
  3566. tag: l,
  3567. extra: e.extra,
  3568. error: _,
  3569. startTime: u,
  3570. traceId: r
  3571. });
  3572. }, d);
  3573. }));
  3574. case 10:
  3575. case "end":
  3576. return _context.stop();
  3577. }
  3578. }
  3579. }, _callee, this);
  3580. }));
  3581. function track(_x, _x2) {
  3582. return _track.apply(this, arguments);
  3583. }
  3584. return track;
  3585. }()
  3586. }, {
  3587. key: "emitTraceIdToDecoder",
  3588. value: function emitTraceIdToDecoder(e) {
  3589. if (e.event === Actions.Rotation || e.event === Actions.Clicking || e.event === Actions.GetOnVehicle || e.event === Actions.GetOffVehicle) {
  3590. var t = {
  3591. [Actions.Rotation]: "Rotation",
  3592. [Actions.GetOnVehicle]: "GetOnVehicle",
  3593. [Actions.GetOffVehicle]: "GetOffVehicle",
  3594. [Actions.Clicking]: "MoveTo"
  3595. };
  3596. this.emit("traceId", {
  3597. traceId: e.traceId,
  3598. timestamp: Date.now(),
  3599. event: t[e.event]
  3600. });
  3601. }
  3602. }
  3603. }]);
  3604. return EventsManager;
  3605. }(EventEmitter);
  3606. var eventsManager = new EventsManager();
  3607. var QueueActions = [Actions.Transfer, Actions.ChangeSkin, Actions.GetOnVehicle, Actions.GetOffVehicle];
  3608. var ActionsHandler = /*#__PURE__*/function () {
  3609. function ActionsHandler(e) {
  3610. _classCallCheck(this, ActionsHandler);
  3611. this.currentActiveAction = null;
  3612. this.room = e;
  3613. }
  3614. _createClass(ActionsHandler, [{
  3615. key: "avatarComponentsSync",
  3616. value: function () {
  3617. var _avatarComponentsSync = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  3618. var t;
  3619. return regenerator.wrap(function _callee$(_context) {
  3620. while (1) {
  3621. switch (_context.prev = _context.next) {
  3622. case 0:
  3623. t = {
  3624. action_type: Actions.SetPlayerState,
  3625. set_player_state_action: {
  3626. player_state: {
  3627. avatar_components: JSON.stringify(e)
  3628. }
  3629. }
  3630. };
  3631. this.sendData({
  3632. data: t
  3633. });
  3634. case 2:
  3635. case "end":
  3636. return _context.stop();
  3637. }
  3638. }
  3639. }, _callee, this);
  3640. }));
  3641. function avatarComponentsSync(_x) {
  3642. return _avatarComponentsSync.apply(this, arguments);
  3643. }
  3644. return avatarComponentsSync;
  3645. }()
  3646. }, {
  3647. key: "sendData",
  3648. value: function () {
  3649. var _sendData = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  3650. var _this = this;
  3651. var t, _e$sampleRate, r, _e$timeout, n, o, a, s;
  3652. return regenerator.wrap(function _callee2$(_context2) {
  3653. while (1) {
  3654. switch (_context2.prev = _context2.next) {
  3655. case 0:
  3656. _context2.next = 2;
  3657. return this.beforeSend(e);
  3658. case 2:
  3659. t = util.uuid();
  3660. if (!(this.room.networkController.sendRtcData(le(oe({}, e.data), {
  3661. trace_id: t,
  3662. user_id: this.room.options.userId
  3663. })), e.track === !1)) {
  3664. _context2.next = 5;
  3665. break;
  3666. }
  3667. return _context2.abrupt("return", Promise.resolve(null));
  3668. case 5:
  3669. _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;
  3670. return _context2.abrupt("return", eventsManager.track({
  3671. timeout: n,
  3672. traceId: t,
  3673. event: a.action_type,
  3674. tag: o,
  3675. extra: a
  3676. }, {
  3677. special: s,
  3678. sampleRate: r,
  3679. noReport: this.room.viewMode === "serverless" || this.room.options.viewMode === "serverless"
  3680. }).finally(function () {
  3681. QueueActions.includes(e.data.action_type) && (_this.currentActiveAction = void 0);
  3682. }));
  3683. case 7:
  3684. case "end":
  3685. return _context2.stop();
  3686. }
  3687. }
  3688. }, _callee2, this);
  3689. }));
  3690. function sendData(_x2) {
  3691. return _sendData.apply(this, arguments);
  3692. }
  3693. return sendData;
  3694. }()
  3695. }, {
  3696. key: "beforeSend",
  3697. value: function () {
  3698. var _beforeSend = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  3699. var o, t, r;
  3700. return regenerator.wrap(function _callee3$(_context3) {
  3701. while (1) {
  3702. switch (_context3.prev = _context3.next) {
  3703. case 0:
  3704. t = (o = this.room._userAvatar) == null ? void 0 : o.isMoving, r = e.data.action_type;
  3705. if (!QueueActions.includes(r)) {
  3706. _context3.next = 5;
  3707. break;
  3708. }
  3709. if (!this.currentActiveAction) {
  3710. _context3.next = 4;
  3711. break;
  3712. }
  3713. return _context3.abrupt("return", (logger$1.error("".concat(Actions[this.currentActiveAction], " still pending, reject ").concat(Actions[r])), Promise.reject(new FrequencyLimitError("".concat(Actions[r], " action request frequency limit")))));
  3714. case 4:
  3715. this.currentActiveAction = r;
  3716. case 5:
  3717. if (!(t && QueueActions.includes(e.data.action_type))) {
  3718. _context3.next = 14;
  3719. break;
  3720. }
  3721. _context3.prev = 6;
  3722. _context3.next = 9;
  3723. return this.stopMoving();
  3724. case 9:
  3725. _context3.next = 14;
  3726. break;
  3727. case 11:
  3728. _context3.prev = 11;
  3729. _context3.t0 = _context3["catch"](6);
  3730. this.currentActiveAction = void 0, logger$1.error("before action stopMoving failed", _context3.t0);
  3731. case 14:
  3732. case "end":
  3733. return _context3.stop();
  3734. }
  3735. }
  3736. }, _callee3, this, [[6, 11]]);
  3737. }));
  3738. function beforeSend(_x3) {
  3739. return _beforeSend.apply(this, arguments);
  3740. }
  3741. return beforeSend;
  3742. }()
  3743. }, {
  3744. key: "moveTo",
  3745. value: function () {
  3746. var _moveTo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  3747. var t, _e$extra, r, n, o;
  3748. return regenerator.wrap(function _callee4$(_context4) {
  3749. while (1) {
  3750. switch (_context4.prev = _context4.next) {
  3751. case 0:
  3752. t = e.point, _e$extra = e.extra, r = _e$extra === void 0 ? "" : _e$extra, n = e.motionType, o = {
  3753. action_type: Actions.Clicking,
  3754. clicking_action: {
  3755. clicking_point: t,
  3756. clicking_type: ClickType.IgnoreView,
  3757. extra: encodeURIComponent(r),
  3758. attitude: n
  3759. },
  3760. clicking_state: this.room._currentClickingState
  3761. };
  3762. return _context4.abrupt("return", this.sendData({
  3763. data: o
  3764. }));
  3765. case 2:
  3766. case "end":
  3767. return _context4.stop();
  3768. }
  3769. }
  3770. }, _callee4, this);
  3771. }));
  3772. function moveTo(_x4) {
  3773. return _moveTo.apply(this, arguments);
  3774. }
  3775. return moveTo;
  3776. }()
  3777. }, {
  3778. key: "transfer",
  3779. value: function transfer(e) {
  3780. var _this2 = this;
  3781. var t = e.renderType,
  3782. r = e.player,
  3783. n = e.camera,
  3784. o = e.areaName,
  3785. a = e.attitude,
  3786. s = e.pathName,
  3787. l = e.person,
  3788. u = e.noMedia,
  3789. c = e.timeout,
  3790. h = e.tag,
  3791. f = e.special,
  3792. d = {
  3793. data: {
  3794. action_type: Actions.Transfer,
  3795. transfer_action: {
  3796. render_type: t,
  3797. player: r,
  3798. camera: n,
  3799. areaName: o,
  3800. attitude: a,
  3801. pathName: s,
  3802. person: {
  3803. type: l
  3804. },
  3805. noMedia: u,
  3806. tiles: [0, 1, 2, 4]
  3807. }
  3808. },
  3809. special: f,
  3810. timeout: c || 4e3,
  3811. tag: h
  3812. };
  3813. return this.sendData(d).then(function (_) {
  3814. return typeof l != "undefined" && _this2.room.updateCurrentNetworkOptions({
  3815. person: l,
  3816. rotationRenderType: t
  3817. }), _;
  3818. });
  3819. }
  3820. }, {
  3821. key: "changeRotationRenderType",
  3822. value: function changeRotationRenderType(e) {
  3823. var t = e.renderType,
  3824. r = e.player,
  3825. n = e.camera,
  3826. o = e.areaName,
  3827. a = e.attitude,
  3828. s = e.pathName;
  3829. return this.transfer({
  3830. renderType: t,
  3831. player: r,
  3832. camera: n,
  3833. areaName: o,
  3834. attitude: a,
  3835. pathName: s,
  3836. tag: "changeToRotationVideo"
  3837. });
  3838. }
  3839. }, {
  3840. key: "requestPanorama",
  3841. value: function requestPanorama(e, t, r) {
  3842. var n = e.camera,
  3843. o = e.player,
  3844. a = e.areaName,
  3845. s = e.attitude,
  3846. l = e.pathName,
  3847. u = e.tag;
  3848. return this.transfer({
  3849. renderType: RenderType.ClientRotationPano,
  3850. player: o,
  3851. camera: n,
  3852. person: Person.First,
  3853. areaName: a,
  3854. attitude: s,
  3855. pathName: l,
  3856. noMedia: t,
  3857. timeout: r,
  3858. tag: u || "requestPanorama",
  3859. special: !t
  3860. });
  3861. }
  3862. }, {
  3863. key: "setMotionType",
  3864. value: function setMotionType(e) {
  3865. return this.transfer({
  3866. attitude: e,
  3867. tag: "setMotionType"
  3868. });
  3869. }
  3870. }, {
  3871. key: "setNickName",
  3872. value: function setNickName(e) {
  3873. var t = {
  3874. action_type: Actions.ChangeNickname,
  3875. change_nickname_action: {
  3876. nickname: e
  3877. }
  3878. };
  3879. return this.sendData({
  3880. data: t
  3881. });
  3882. }
  3883. }, {
  3884. key: "getReserveSeat",
  3885. value: function getReserveSeat(_ref) {
  3886. var e = _ref.routeId,
  3887. t = _ref.name;
  3888. var r = {
  3889. action_type: Actions.ReserveSeat,
  3890. reserve_seat_action: {
  3891. route_id: e,
  3892. name: t
  3893. }
  3894. };
  3895. return this.sendData({
  3896. data: r
  3897. });
  3898. }
  3899. }, {
  3900. key: "getReserveStatus",
  3901. value: function getReserveStatus(_ref2) {
  3902. var e = _ref2.routeId,
  3903. t = _ref2.name,
  3904. r = _ref2.need_detail;
  3905. var n = {
  3906. action_type: Actions.GetReserveStatus,
  3907. get_reserve_status_action: {
  3908. route_id: e,
  3909. name: t,
  3910. need_detail: r
  3911. }
  3912. };
  3913. return this.sendData({
  3914. data: n,
  3915. timeout: 2e3
  3916. }).then(function (o) {
  3917. return o.reserveDetail;
  3918. });
  3919. }
  3920. }, {
  3921. key: "stopMoving",
  3922. value: function stopMoving() {
  3923. var e = {
  3924. action_type: Actions.StopMoving,
  3925. stop_move_action: {}
  3926. };
  3927. return this.sendData({
  3928. data: e
  3929. });
  3930. }
  3931. }, {
  3932. key: "getOnVehicle",
  3933. value: function getOnVehicle(_ref3) {
  3934. var e = _ref3.routeId,
  3935. t = _ref3.name,
  3936. r = _ref3.camera;
  3937. var n = {
  3938. action_type: Actions.GetOnVehicle,
  3939. get_on_vehicle_action: {
  3940. route_id: e,
  3941. name: t,
  3942. camera: r
  3943. }
  3944. };
  3945. return this.sendData({
  3946. data: n
  3947. });
  3948. }
  3949. }, {
  3950. key: "getOffVehicle",
  3951. value: function getOffVehicle(_ref4) {
  3952. var e = _ref4.renderType,
  3953. t = _ref4.player,
  3954. r = _ref4.camera;
  3955. var n = {
  3956. action_type: Actions.GetOffVehicle,
  3957. get_off_vehicle_action: {
  3958. render_type: e,
  3959. player: t,
  3960. camera: r
  3961. }
  3962. };
  3963. return this.sendData({
  3964. data: n
  3965. });
  3966. }
  3967. }, {
  3968. key: "confirmEvent",
  3969. value: function confirmEvent(e) {
  3970. var t = {
  3971. action_type: Actions.ConfirmEvent,
  3972. confirm_event_action: {
  3973. id: e
  3974. }
  3975. };
  3976. return this.sendData({
  3977. data: t,
  3978. track: !1
  3979. });
  3980. }
  3981. }, {
  3982. key: "echo",
  3983. value: function echo(e) {
  3984. var t = {
  3985. action_type: Actions.Echo,
  3986. echo_msg: {
  3987. echoMsg: e
  3988. }
  3989. };
  3990. return this.sendData({
  3991. data: t,
  3992. track: !1
  3993. });
  3994. }
  3995. }, {
  3996. key: "changeSkin",
  3997. value: function () {
  3998. var _changeSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  3999. var _this3 = this;
  4000. var t, r, n, _e$landingType, o, a, s, l, u, c, h, f, d, _, _e$roomTypeId, g, m, y, v;
  4001. return regenerator.wrap(function _callee6$(_context6) {
  4002. while (1) {
  4003. switch (_context6.prev = _context6.next) {
  4004. case 0:
  4005. 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) {
  4006. return y.id === r;
  4007. })[0];
  4008. if (m) {
  4009. _context6.next = 4;
  4010. break;
  4011. }
  4012. y = "skin ".concat(r, " is invalid");
  4013. return _context6.abrupt("return", (logger$1.error(y), Promise.reject(new ParamError(y))));
  4014. case 4:
  4015. v = {
  4016. action_type: Actions.ChangeSkin,
  4017. change_skin_action: {
  4018. skinID: r,
  4019. mode: n === ChangeMode.Preview ? ChangeMode.Preview : ChangeMode.Confirm,
  4020. skin_data_version: r + m.versionId,
  4021. landing_type: o,
  4022. landing_point: a,
  4023. landing_camera: s,
  4024. render_wrapper: {
  4025. render_type: l
  4026. },
  4027. areaName: u,
  4028. attitude: c,
  4029. noMedia: d,
  4030. person: f,
  4031. pathName: h,
  4032. roomTypeId: g
  4033. }
  4034. };
  4035. return _context6.abrupt("return", this.sendData({
  4036. data: v,
  4037. timeout: _ || 6e3,
  4038. special: t
  4039. }).then( /*#__PURE__*/function () {
  4040. var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(y) {
  4041. var b, _ref6, T;
  4042. return regenerator.wrap(function _callee5$(_context5) {
  4043. while (1) {
  4044. switch (_context5.prev = _context5.next) {
  4045. case 0:
  4046. if (!(l === RenderType.ClientRotationPano && y)) {
  4047. _context5.next = 8;
  4048. break;
  4049. }
  4050. _context5.next = 3;
  4051. return _this3.room.modelManager.findRoute(r, h);
  4052. case 3:
  4053. b = _context5.sent;
  4054. _ref6 = util.getRandomItem(b.birthPointList) || {};
  4055. T = _ref6.camera;
  4056. _context5.next = 8;
  4057. return _this3.room.panorama.handleReceivePanorama(y, T);
  4058. case 8:
  4059. return _context5.abrupt("return", _this3.handleChangeSkin(e));
  4060. case 9:
  4061. case "end":
  4062. return _context5.stop();
  4063. }
  4064. }
  4065. }, _callee5);
  4066. }));
  4067. return function (_x6) {
  4068. return _ref5.apply(this, arguments);
  4069. };
  4070. }()).catch(function (y) {
  4071. return d ? _this3.handleChangeSkin(e) : Promise.reject(y);
  4072. }));
  4073. case 6:
  4074. case "end":
  4075. return _context6.stop();
  4076. }
  4077. }
  4078. }, _callee6, this);
  4079. }));
  4080. function changeSkin(_x5) {
  4081. return _changeSkin.apply(this, arguments);
  4082. }
  4083. return changeSkin;
  4084. }()
  4085. }, {
  4086. key: "handleChangeSkin",
  4087. value: function handleChangeSkin(e) {
  4088. var _this4 = this;
  4089. var t = e.skinId,
  4090. r = e.mode,
  4091. n = e.renderType,
  4092. o = e.areaName,
  4093. a = e.attitude,
  4094. s = e.pathName;
  4095. return this.room.sceneManager.staticmeshComponent.getCgMesh().show(), this.room.sceneManager.cameraComponent.switchToCgCamera(), this.room.engineProxy._updateSkinAssets(t).then(function () {
  4096. _this4.room.sceneManager.staticmeshComponent.getCgMesh().hide(), _this4.room.sceneManager.cameraComponent.switchToMainCamera(), _this4.room.pathManager.currentArea = o, logger$1.info("changeSkin _updateSkinAssets susccss"), _this4.room.updateCurrentNetworkOptions({
  4097. pathName: s,
  4098. attitude: a,
  4099. areaName: o
  4100. }), _this4.room.skinChangedHook(), _this4.room.emit("skinChanged", {
  4101. skin: {
  4102. id: t
  4103. },
  4104. mode: r
  4105. }), n === RenderType.ClientRotationPano && _this4.room.sceneManager.cameraComponent.allowMainCameraController();
  4106. });
  4107. }
  4108. }, {
  4109. key: "rotate",
  4110. value: function rotate(_ref7) {
  4111. var e = _ref7.pitch,
  4112. t = _ref7.yaw;
  4113. var n;
  4114. if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode)) return;
  4115. var r = {
  4116. action_type: Actions.Rotation,
  4117. rotation_action: {
  4118. vertical_move: e,
  4119. horizontal_move: -t
  4120. }
  4121. };
  4122. this.sendData({
  4123. data: r,
  4124. sampleRate: .02
  4125. });
  4126. }
  4127. }, {
  4128. key: "turnTo",
  4129. value: function turnTo(e) {
  4130. var _ref8 = e || {},
  4131. t = _ref8.point,
  4132. _ref8$timeout = _ref8.timeout,
  4133. r = _ref8$timeout === void 0 ? 2e3 : _ref8$timeout,
  4134. _ref8$offset = _ref8.offset,
  4135. n = _ref8$offset === void 0 ? 8 : _ref8$offset,
  4136. o = {
  4137. action_type: Actions.TurnTo,
  4138. turn_to_action: {
  4139. turn_to_point: t,
  4140. offset: n
  4141. }
  4142. };
  4143. return this.sendData({
  4144. data: o,
  4145. timeout: r
  4146. });
  4147. }
  4148. }, {
  4149. key: "rotateTo",
  4150. value: function rotateTo(e) {
  4151. var _ref9 = e || {},
  4152. t = _ref9.point,
  4153. _ref9$offset = _ref9.offset,
  4154. r = _ref9$offset === void 0 ? 0 : _ref9$offset,
  4155. _ref9$speed = _ref9.speed,
  4156. n = _ref9$speed === void 0 ? 3 : _ref9$speed,
  4157. o = {
  4158. action_type: Actions.RotateTo,
  4159. rotate_to_action: {
  4160. rotate_to_point: t,
  4161. offset: r,
  4162. speed: n
  4163. }
  4164. };
  4165. return this.sendData({
  4166. data: o
  4167. });
  4168. }
  4169. }, {
  4170. key: "broadcast",
  4171. value: function broadcast(e) {
  4172. var t = e.data,
  4173. _e$msgType = e.msgType,
  4174. r = _e$msgType === void 0 ? MessageHandleType.MHT_FollowListMulticast : _e$msgType,
  4175. n = e.targetUserIds;
  4176. if (r === MessageHandleType.MHT_CustomTargetSync && !Array.isArray(n)) return Promise.reject(new ParamError("param targetUserIds is required when msgType is ".concat(MessageHandleType[r])));
  4177. var o = {
  4178. action_type: Actions.Broadcast,
  4179. broadcast_action: {
  4180. data: JSON.stringify(t),
  4181. user_id: this.room.options.userId,
  4182. msgType: r
  4183. }
  4184. };
  4185. return Array.isArray(n) && r === MessageHandleType.MHT_CustomTargetSync && (o.broadcast_action.target_user_ids = n), this.room.actionsHandler.sendData({
  4186. data: o,
  4187. tag: t.broadcastType
  4188. });
  4189. }
  4190. }, {
  4191. key: "getNeighborPoints",
  4192. value: function getNeighborPoints(e) {
  4193. var t = e.point,
  4194. _e$containSelf = e.containSelf,
  4195. r = _e$containSelf === void 0 ? !1 : _e$containSelf,
  4196. _e$searchRange = e.searchRange,
  4197. n = _e$searchRange === void 0 ? 500 : _e$searchRange,
  4198. o = {
  4199. action_type: Actions.GetNeighborPoints,
  4200. get_neighbor_points_action: {
  4201. point: t,
  4202. level: 1,
  4203. containSelf: r,
  4204. searchRange: n
  4205. }
  4206. };
  4207. return this.sendData({
  4208. data: o
  4209. }).then(function (a) {
  4210. return a.nps;
  4211. });
  4212. }
  4213. }, {
  4214. key: "playCG",
  4215. value: function playCG(e) {
  4216. var t = {
  4217. action_type: Actions.PlayCG,
  4218. play_cg_action: {
  4219. cg_name: e
  4220. }
  4221. };
  4222. return this.sendData({
  4223. data: t
  4224. });
  4225. }
  4226. }, {
  4227. key: "audienceToVisitor",
  4228. value: function audienceToVisitor(e) {
  4229. var t = e.avatarId,
  4230. r = e.avatarComponents,
  4231. n = e.player,
  4232. o = e.camera,
  4233. a = {
  4234. action_type: Actions.AudienceChangeToVisitor,
  4235. audienceChangeToVisitorAction: {
  4236. avatarID: t,
  4237. avatarComponents: r,
  4238. player: n,
  4239. camera: o
  4240. }
  4241. };
  4242. return logger$1.debug("send data: audience to visitor"), this.sendData({
  4243. data: a
  4244. });
  4245. }
  4246. }, {
  4247. key: "visitorToAudience",
  4248. value: function visitorToAudience(e) {
  4249. var t = e.renderType,
  4250. r = e.player,
  4251. n = e.camera,
  4252. o = e.areaName,
  4253. a = e.attitude,
  4254. s = e.pathName,
  4255. l = e.person,
  4256. u = e.noMedia,
  4257. c = {
  4258. action_type: Actions.VisitorChangeToAudience,
  4259. visitorChangeToAudienceAction: {
  4260. transferAction: {
  4261. render_type: t,
  4262. player: r,
  4263. camera: n,
  4264. areaName: o,
  4265. attitude: a,
  4266. pathName: s,
  4267. person: {
  4268. type: l
  4269. },
  4270. noMedia: u,
  4271. tiles: [0, 1, 2, 4]
  4272. }
  4273. }
  4274. };
  4275. return logger$1.debug("send data: visitor to audience"), this.sendData({
  4276. data: c
  4277. });
  4278. }
  4279. }, {
  4280. key: "removeVisitor",
  4281. value: function removeVisitor(e) {
  4282. var t = e.removeType,
  4283. r = e.userIDList,
  4284. _e$extraInfo = e.extraInfo,
  4285. n = _e$extraInfo === void 0 ? "" : _e$extraInfo,
  4286. o = {
  4287. action_type: Actions.RemoveVisitor,
  4288. removeVisitorAction: {
  4289. removeVisitorEvent: t,
  4290. userIDList: r,
  4291. extraInfo: encodeURIComponent(n)
  4292. }
  4293. };
  4294. return logger$1.debug("send data: remove visitor"), this.sendData({
  4295. data: o
  4296. });
  4297. }
  4298. }, {
  4299. key: "getUserWithAvatar",
  4300. value: function getUserWithAvatar(e, t) {
  4301. var r = {
  4302. action_type: Actions.GetUserWithAvatar,
  4303. getUserWithAvatarAction: {
  4304. userType: e,
  4305. roomID: t
  4306. }
  4307. };
  4308. return logger$1.debug("send data: get user with avatar"), this.sendData({
  4309. data: r
  4310. }).then(function (n) {
  4311. return n.userWithAvatarList;
  4312. });
  4313. }
  4314. }, {
  4315. key: "joystick",
  4316. value: function joystick(e) {
  4317. var t = e.degree,
  4318. _e$level = e.level,
  4319. r = _e$level === void 0 ? 1 : _e$level,
  4320. n = util.uuid();
  4321. var o = -t + 90 + 360;
  4322. o >= 360 && (o -= 360);
  4323. var a = {
  4324. action_type: Actions.Joystick,
  4325. dir_action: {
  4326. move_angle: o,
  4327. speed_level: r
  4328. },
  4329. trace_id: n,
  4330. user_id: this.room.options.userId,
  4331. packet_id: n
  4332. };
  4333. return this.sendData({
  4334. data: a,
  4335. track: !1
  4336. });
  4337. }
  4338. }]);
  4339. return ActionsHandler;
  4340. }();
  4341. var ECurrentShaderMode = {
  4342. default: 0,
  4343. video: 1,
  4344. pano: 2
  4345. };
  4346. var Signal = /*#__PURE__*/function () {
  4347. function Signal(e) {
  4348. _classCallCheck(this, Signal);
  4349. this.signalHandleActived = !0;
  4350. this.isUpdatedYUV = !0;
  4351. this._room = e;
  4352. }
  4353. _createClass(Signal, [{
  4354. key: "handleSignal",
  4355. value: function handleSignal(e) {
  4356. var _this = this;
  4357. var a, s, l;
  4358. if (!this.signalHandleActived) return;
  4359. var t = e.signal,
  4360. r = e.alreadyUpdateYUV;
  4361. if (this.handleActionResponses(t), this._room.handleSignalHook(t), !r) {
  4362. var u = (a = t.newUserStates) == null ? void 0 : a.find(function (c) {
  4363. return c.userId === _this._room.userId;
  4364. });
  4365. if ((u == null ? void 0 : u.renderInfo) && ((s = this._room._userAvatar) == null ? void 0 : s.isMoving)) {
  4366. logger$1.debug("stream stoped, make avatar to stop");
  4367. var _u$renderInfo = u.renderInfo,
  4368. c = _u$renderInfo.isMoving,
  4369. h = _u$renderInfo.isRotating;
  4370. this._room.avatarManager._updateAvatarMovingStatus({
  4371. id: u.userId,
  4372. isMoving: !!c,
  4373. isRotating: !!h
  4374. });
  4375. }
  4376. return;
  4377. }
  4378. this.isUpdatedYUV = r;
  4379. var n = t;
  4380. if (!t) {
  4381. logger$1.warn("metadata signal is empty");
  4382. return;
  4383. }
  4384. if (n.code === Codes.RepeatLogin) {
  4385. this._room.handleRepetLogin();
  4386. return;
  4387. }
  4388. n.code !== void 0 && n.code !== Codes.Success && n.code !== Codes.ActionMaybeDelay && n.code !== Codes.DoActionBlocked && n.code !== Codes.GetOnVehicle && (logger$1.error("signal errcode: ", n), this._room.emit("error", n));
  4389. var o = (l = n.newUserStates) == null ? void 0 : l.find(function (u) {
  4390. return u.userId === _this._room.userId;
  4391. });
  4392. if (n.broadcastAction) try {
  4393. var _u = JSON.parse(n.broadcastAction.data);
  4394. Broadcast.handlers.forEach(function (c) {
  4395. return c(_u);
  4396. });
  4397. } catch (u) {
  4398. logger$1.error(u);
  4399. }
  4400. if (n.newUserStates && n.newUserStates.length > 0 && this._room.avatarManager.handleAvatar(n), o != null && o.playerState) {
  4401. this._room._currentClickingState = o.playerState;
  4402. var _o$playerState = o.playerState,
  4403. _u2 = _o$playerState.pathName,
  4404. _c = _o$playerState.attitude,
  4405. _h = _o$playerState.areaName,
  4406. f = _o$playerState.skinId;
  4407. if (_u2 && (this._room.pathManager.currentPathName = _u2, this._room.updateCurrentState({
  4408. pathName: _u2
  4409. })), f && this.udpateSkinInfo(f), _h && this._room.updateCurrentState({
  4410. areaName: _h
  4411. }), _c) {
  4412. var d = this._room.skin.routeList.find(function (g) {
  4413. return g.areaName === _this._room.currentState.areaName;
  4414. }),
  4415. _ = ((d == null ? void 0 : d.step) || 7.5) * 30;
  4416. this._room.updateCurrentState({
  4417. speed: _,
  4418. attitude: _c
  4419. }), this._room.pathManager.currentAttitude = _c, this._room._userAvatar && (this._room._userAvatar.motionType = _c);
  4420. }
  4421. this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano && !this._room.isPano && o.playerState.camera && this._room.camera.setCameraPose(o.playerState.camera);
  4422. }
  4423. if (o != null && o.renderInfo && this._room.camera.handleRenderInfo(o), n.actionType !== void 0) {
  4424. var _u3 = n.actionType,
  4425. _c2 = n.code,
  4426. _h2 = n.echoMsg,
  4427. _f = n.traceId;
  4428. _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);
  4429. }
  4430. }
  4431. }, {
  4432. key: "handleActionResponses",
  4433. value: function handleActionResponses(e) {
  4434. var _this2 = this;
  4435. !(e != null && e.actionResponses) || e.actionResponses.length === 0 || e.actionResponses.forEach(function (t) {
  4436. if (t.actionType == null) return;
  4437. var r = t.pointType,
  4438. n = t.extra,
  4439. o = t.actionType,
  4440. a = t.traceId,
  4441. s = t.code,
  4442. l = t.msg;
  4443. 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));
  4444. });
  4445. }
  4446. }, {
  4447. key: "udpateSkinInfo",
  4448. value: function () {
  4449. var _udpateSkinInfo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  4450. var t;
  4451. return regenerator.wrap(function _callee$(_context) {
  4452. while (1) {
  4453. switch (_context.prev = _context.next) {
  4454. case 0:
  4455. this._room.updateCurrentState({
  4456. skinId: e
  4457. });
  4458. _context.next = 3;
  4459. return this._room.skinList.find(function (r) {
  4460. return r.id === e;
  4461. });
  4462. case 3:
  4463. t = _context.sent;
  4464. t && this._room.updateCurrentState({
  4465. skin: t
  4466. });
  4467. case 5:
  4468. case "end":
  4469. return _context.stop();
  4470. }
  4471. }
  4472. }, _callee, this);
  4473. }));
  4474. function udpateSkinInfo(_x) {
  4475. return _udpateSkinInfo.apply(this, arguments);
  4476. }
  4477. return udpateSkinInfo;
  4478. }()
  4479. }]);
  4480. return Signal;
  4481. }();
  4482. 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); }; }
  4483. 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; } }
  4484. var XverseEffectManager = /*#__PURE__*/function (_EventEmitter) {
  4485. _inherits(XverseEffectManager, _EventEmitter);
  4486. var _super = _createSuper$g(XverseEffectManager);
  4487. function XverseEffectManager(e) {
  4488. var _this;
  4489. _classCallCheck(this, XverseEffectManager);
  4490. _this = _super.call(this);
  4491. E(_assertThisInitialized(_this), "effects", new Map());
  4492. E(_assertThisInitialized(_this), "room");
  4493. _this.room = e;
  4494. return _this;
  4495. }
  4496. _createClass(XverseEffectManager, [{
  4497. key: "addEffect",
  4498. value: function () {
  4499. var _addEffect = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  4500. var o, t, r, _e$type, n, a;
  4501. return regenerator.wrap(function _callee$(_context) {
  4502. while (1) {
  4503. switch (_context.prev = _context.next) {
  4504. case 0:
  4505. t = e.jsonPath, r = e.id, _e$type = e.type, n = _e$type === void 0 ? IEffectType.SubSequence : _e$type;
  4506. _context.prev = 1;
  4507. this.effects.get(r) && ((o = this.effects.get(r)) == null || o.dispose());
  4508. a = new Ae.subEffect({
  4509. id: r,
  4510. jsonPath: t,
  4511. type: n,
  4512. room: this.room
  4513. });
  4514. this.effects.set(r, a);
  4515. _context.next = 7;
  4516. return a.init();
  4517. case 7:
  4518. return _context.abrupt("return", a);
  4519. case 10:
  4520. _context.prev = 10;
  4521. _context.t0 = _context["catch"](1);
  4522. return _context.abrupt("return", (this.effects.delete(r), logger$1.error(_context.t0), Promise.reject(_context.t0)));
  4523. case 13:
  4524. case "end":
  4525. return _context.stop();
  4526. }
  4527. }
  4528. }, _callee, this, [[1, 10]]);
  4529. }));
  4530. function addEffect(_x) {
  4531. return _addEffect.apply(this, arguments);
  4532. }
  4533. return addEffect;
  4534. }()
  4535. }, {
  4536. key: "clearEffects",
  4537. value: function clearEffects() {
  4538. var _this2 = this;
  4539. this.effects.forEach(function (e) {
  4540. e.dispose(), _this2.effects.delete(e.id);
  4541. });
  4542. }
  4543. }, {
  4544. key: "removeEffect",
  4545. value: function removeEffect(e) {
  4546. var t = this.effects.get(e);
  4547. t == null || t.dispose(), t && this.effects.delete(t.id);
  4548. }
  4549. }]);
  4550. return XverseEffectManager;
  4551. }(EventEmitter);
  4552. 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); }; }
  4553. 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; } }
  4554. var ParamError$1 = /*#__PURE__*/function (_XverseError) {
  4555. _inherits(ParamError, _XverseError);
  4556. var _super = _createSuper$f(ParamError);
  4557. function ParamError(e) {
  4558. _classCallCheck(this, ParamError);
  4559. return _super.call(this, 1001, e || "\u53C2\u6570\u9519\u8BEF");
  4560. }
  4561. return _createClass(ParamError);
  4562. }(XverseError);
  4563. var MotionType$1 = {
  4564. Walk: 'walk',
  4565. Run: 'run',
  4566. Fly: 'fly'
  4567. };
  4568. var Heartbeat = /*#__PURE__*/function () {
  4569. function Heartbeat(e) {
  4570. var _this = this;
  4571. _classCallCheck(this, Heartbeat);
  4572. E(this, "_interval", null);
  4573. E(this, "ping", function () {
  4574. var e = Date.now().toString();
  4575. _this.handler.ping(e);
  4576. });
  4577. this.handler = e;
  4578. }
  4579. _createClass(Heartbeat, [{
  4580. key: "ping",
  4581. value: function ping() {
  4582. var e = Date.now().toString();
  4583. this.handler.ping(e);
  4584. }
  4585. }, {
  4586. key: "start",
  4587. value: function start() {
  4588. this.stop(), logger$1.debug("Setting ping interval to ".concat(PING_INTERVAL_MS, "ms")), this._interval = window.setInterval(this.ping, PING_INTERVAL_MS);
  4589. }
  4590. }, {
  4591. key: "stop",
  4592. value: function stop() {
  4593. logger$1.debug("stop heartbeat"), this._interval && window.clearInterval(this._interval);
  4594. }
  4595. }, {
  4596. key: "pong",
  4597. value: function pong(e, t) {
  4598. !e || typeof e == "string" && this.handler.pong(Date.now() - Number(e), t);
  4599. }
  4600. }]);
  4601. return Heartbeat;
  4602. }();
  4603. var Timeout$1 = /*#__PURE__*/function () {
  4604. function Timeout(e, t) {
  4605. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !0;
  4606. _classCallCheck(this, Timeout);
  4607. this._timeout = null;
  4608. this._fn = e, this._delay = t, r && this.start();
  4609. }
  4610. _createClass(Timeout, [{
  4611. key: "delay",
  4612. get: function get() {
  4613. return this._delay;
  4614. }
  4615. }, {
  4616. key: "isSet",
  4617. get: function get() {
  4618. return !!this._timeout;
  4619. }
  4620. }, {
  4621. key: "setDelay",
  4622. value: function setDelay(e) {
  4623. this._delay = e;
  4624. }
  4625. }, {
  4626. key: "start",
  4627. value: function start() {
  4628. var _this = this;
  4629. this.isSet || (this._timeout = window.setTimeout(function () {
  4630. var e = _this._fn;
  4631. _this.clear(), e();
  4632. }, this._delay));
  4633. }
  4634. }, {
  4635. key: "clear",
  4636. value: function clear() {
  4637. window.clearTimeout(this._timeout), this._timeout = void 0;
  4638. }
  4639. }, {
  4640. key: "reset",
  4641. value: function reset() {
  4642. this.clear(), this.start();
  4643. }
  4644. }]);
  4645. return Timeout;
  4646. }();
  4647. 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); }; }
  4648. 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; } }
  4649. var InitNetworkTimeoutError = /*#__PURE__*/function (_XverseError) {
  4650. _inherits(InitNetworkTimeoutError, _XverseError);
  4651. var _super = _createSuper$e(InitNetworkTimeoutError);
  4652. function InitNetworkTimeoutError(e) {
  4653. _classCallCheck(this, InitNetworkTimeoutError);
  4654. return _super.call(this, 1007, e || "\u7F51\u7EDC\u521D\u59CB\u5316\u8D85\u65F6");
  4655. }
  4656. return _createClass(InitNetworkTimeoutError);
  4657. }(XverseError);
  4658. 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); }; }
  4659. 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; } }
  4660. var Socket = /*#__PURE__*/function (_EventEmitter) {
  4661. _inherits(Socket, _EventEmitter);
  4662. var _super = _createSuper$d(Socket);
  4663. function Socket(e) {
  4664. var _this;
  4665. _classCallCheck(this, Socket);
  4666. _this = _super.call(this);
  4667. E(_assertThisInitialized(_this), "_ws");
  4668. E(_assertThisInitialized(_this), "_openTimer");
  4669. E(_assertThisInitialized(_this), "connected", !1);
  4670. E(_assertThisInitialized(_this), "_hasTimeout", !1);
  4671. E(_assertThisInitialized(_this), "heartbeat");
  4672. E(_assertThisInitialized(_this), "latency", function (e, t) {
  4673. return _this.send({
  4674. id: "checkLatency",
  4675. data: JSON.stringify(e),
  4676. packet_id: t
  4677. });
  4678. });
  4679. E(_assertThisInitialized(_this), "send", function (e) {
  4680. if (_this.wsNoReady()) return;
  4681. var t = JSON.stringify(e);
  4682. e.id !== "heartbeat" && logger$1.info("send ws frame", t), _this._ws.send(t);
  4683. });
  4684. E(_assertThisInitialized(_this), "startGame", function () {
  4685. var _this$network$room$cu = _this.network.room.currentNetworkOptions,
  4686. e = _this$network$room$cu.roomId,
  4687. t = _this$network$room$cu.userId,
  4688. r = _this$network$room$cu.avatarId,
  4689. n = _this$network$room$cu.skinId,
  4690. o = _this$network$room$cu.role,
  4691. a = _this$network$room$cu.avatarComponents,
  4692. s = _this$network$room$cu.versionId,
  4693. l = _this$network$room$cu.rotationRenderType,
  4694. u = _this$network$room$cu.isAllSync,
  4695. c = _this$network$room$cu.nickname,
  4696. h = _this$network$room$cu.avatarScale,
  4697. f = _this$network$room$cu.appId,
  4698. d = _this$network$room$cu.camera,
  4699. _ = _this$network$room$cu.player,
  4700. g = _this$network$room$cu.firends,
  4701. m = _this$network$room$cu.syncByEvent,
  4702. v = _this$network$room$cu.areaName,
  4703. y = _this$network$room$cu.attitude,
  4704. b = _this$network$room$cu.pathName,
  4705. T = _this$network$room$cu.person,
  4706. _this$network$room$cu2 = _this$network$room$cu.roomTypeId,
  4707. C = _this$network$room$cu2 === void 0 ? "" : _this$network$room$cu2,
  4708. A = _this$network$room$cu.syncToOthers,
  4709. S = _this$network$room$cu.hasAvatar,
  4710. P = _this$network$room$cu.prioritySync,
  4711. _this$network$room$cu3 = _this$network$room$cu.extra,
  4712. R = _this$network$room$cu3 === void 0 ? {} : _this$network$room$cu3,
  4713. M = _this$network$room$cu.removeWhenDisconnected;
  4714. R.removeWhenDisconnected = M;
  4715. var x = {
  4716. id: "start",
  4717. room_id: e,
  4718. user_id: t,
  4719. trace_id: util.uuid(),
  4720. data: JSON.stringify({
  4721. avatar_components: JSON.stringify(a),
  4722. avatar_id: r,
  4723. skin_id: n,
  4724. is_host: o ? o == "host" : !0,
  4725. skin_data_version: n !== void 0 && s !== void 0 ? n + s : void 0,
  4726. rotation_render_type: l,
  4727. is_all_sync: u,
  4728. nick_name: encodeURIComponent(c || ""),
  4729. app_id: f,
  4730. camera: d,
  4731. player: _,
  4732. person: T,
  4733. firends: JSON.stringify(g),
  4734. sync_by_event: m,
  4735. area_name: v,
  4736. path_name: b,
  4737. attitude: y,
  4738. room_type_id: C,
  4739. syncToOthers: A,
  4740. hasAvatar: S,
  4741. avatarSize: h,
  4742. prioritySync: P,
  4743. extra: JSON.stringify(R)
  4744. })
  4745. };
  4746. _this.send(x), logger$1.warn("startGame", le(oe({}, x), {
  4747. data: JSON.parse(x.data)
  4748. }));
  4749. });
  4750. _this.network = e, _this.heartbeat = new Heartbeat({
  4751. ping: function ping(t) {
  4752. var r;
  4753. if (!_this.connected) {
  4754. _this.heartbeat.stop(), (r = e.room.stats) == null || r.assign({
  4755. rtt: 0
  4756. });
  4757. return;
  4758. }
  4759. _this.send({
  4760. id: "heartbeat",
  4761. data: t
  4762. });
  4763. },
  4764. pong(t) {
  4765. var r;
  4766. (r = e.room.stats) == null || r.assign({
  4767. rtt: t
  4768. });
  4769. }
  4770. });
  4771. return _this;
  4772. }
  4773. _createClass(Socket, [{
  4774. key: "connection",
  4775. get: function get() {
  4776. return this._ws;
  4777. }
  4778. }, {
  4779. key: "start",
  4780. value: function start() {
  4781. var _this2 = this;
  4782. this._hasTimeout = !1;
  4783. var e = this.getAddress();
  4784. logger$1.info("connecting to ".concat(e));
  4785. var t = Date.now();
  4786. this._ws = new WebSocket(e), this._openTimer = new Timeout$1(function () {
  4787. var r = "Failed to open websocket in ".concat(DEFAULT_OPEN_TIMEOUT_MS, " ms");
  4788. _this2._hasTimeout = !0, _this2.emit("socketClosed", new InitNetworkTimeoutError(r));
  4789. }, DEFAULT_OPEN_TIMEOUT_MS), this._ws.onopen = function () {
  4790. var r;
  4791. (r = _this2._openTimer) == null || r.clear(), _this2.connected = !0, _this2.heartbeat.start(), _this2.network.room.currentNetworkOptions.reconnect || (logger$1.infoAndReportMeasurement({
  4792. metric: "wsOpenedAt",
  4793. group: "joinRoom",
  4794. startTime: _this2.network.room._startTime
  4795. }), logger$1.infoAndReportMeasurement({
  4796. metric: "wsOpenedCost",
  4797. group: "joinRoom",
  4798. startTime: t
  4799. }));
  4800. }, this.handleWSEvent();
  4801. }
  4802. }, {
  4803. key: "getAddress",
  4804. value: function getAddress() {
  4805. var _this$network$room$cu4 = this.network.room.currentNetworkOptions,
  4806. e = _this$network$room$cu4.wsServerUrl,
  4807. t = _this$network$room$cu4.reconnect,
  4808. r = _this$network$room$cu4.sessionId,
  4809. n = _this$network$room$cu4.token,
  4810. o = _this$network$room$cu4.roomId,
  4811. a = _this$network$room$cu4.userId,
  4812. s = _this$network$room$cu4.pageSession,
  4813. l = this.network.room.skinId;
  4814. var u = e;
  4815. t && (u = u + "?reconnect=true&lastSessionID=".concat(r));
  4816. var c = "userId=".concat(a, "&roomId=").concat(o, "&pageSession=").concat(s) + (this.network.room.isHost ? "&skinId=".concat(l) : "") + (n ? "&token=".concat(n) : "");
  4817. return u = u.indexOf("?") > -1 ? u + "&" + c : u + "?" + c, u;
  4818. }
  4819. }, {
  4820. key: "handleWSEvent",
  4821. value: function handleWSEvent() {
  4822. var _this3 = this;
  4823. var e = this._ws;
  4824. e.addEventListener("error", function (t) {
  4825. _this3.connected = !1, logger$1.error("webscoket error", t), _this3.emit("socketClosed", new InternalError("connect to address error: " + _this3.network.room.currentNetworkOptions.wsServerUrl));
  4826. }), e.addEventListener("close", function (t) {
  4827. _this3.connected = !1, _this3._onClose(t);
  4828. }), e.addEventListener("message", function (t) {
  4829. if (!t || _this3._hasTimeout || !_this3.connected) return;
  4830. var r = null;
  4831. try {
  4832. r = JSON.parse(t.data);
  4833. } catch (o) {
  4834. logger$1.error(o);
  4835. return;
  4836. }
  4837. if (!r) return;
  4838. var n = r.id;
  4839. if (!!n) switch (n !== "heartbeat" && logger$1.info("receive ws frame: ".concat(t.data)), n) {
  4840. case "fail":
  4841. break;
  4842. case "init":
  4843. try {
  4844. var o = r.data.slice(-37, -1);
  4845. reporter$1.updateBody({
  4846. serverSession: o
  4847. });
  4848. } catch (o) {
  4849. console.error(o);
  4850. }
  4851. _this3.network.rtcp.start();
  4852. break;
  4853. case "heartbeat":
  4854. _this3.heartbeat.pong(r.data);
  4855. break;
  4856. case "offer":
  4857. _this3.network.rtcp.setRemoteDescription(r.data, _this3.network.stream.el);
  4858. break;
  4859. case "ice_candidate":
  4860. _this3.network.rtcp.addCandidate(r.data);
  4861. break;
  4862. case "start":
  4863. _this3.emit("gameRoomAvailable", r);
  4864. break;
  4865. case "error":
  4866. try {
  4867. var _JSON$parse = JSON.parse(r.data),
  4868. _o = _JSON$parse.Code,
  4869. a = _JSON$parse.Msg;
  4870. if (_o) {
  4871. if (_o == 3003) return _this3.emit("socketClosed", new TokenExpiredError());
  4872. if (authenticationErrorCodes.indexOf(_o) > -1) return _this3.emit("socketClosed", new AuthenticationError("\u9274\u6743\u9519\u8BEF:" + a));
  4873. {
  4874. var s = getErrorByCode(_o);
  4875. _this3.emit("socketClosed", new s(a));
  4876. }
  4877. }
  4878. } catch (o) {
  4879. logger$1.error(o), _this3.emit("socketClosed", new InternalError(r.data));
  4880. }
  4881. break;
  4882. case "checkLatency":
  4883. {
  4884. var _o2 = r.packet_id,
  4885. _a = r.data.split(",");
  4886. _this3.onLatencyCheck({
  4887. packetId: _o2,
  4888. addresses: _a
  4889. });
  4890. break;
  4891. }
  4892. default:
  4893. logger$1.warn("unkown ws message type", n, r);
  4894. }
  4895. });
  4896. }
  4897. }, {
  4898. key: "onLatencyCheck",
  4899. value: function onLatencyCheck(e) {
  4900. var _this4 = this;
  4901. var t = _toConsumableArray(new Set(e.addresses || []));
  4902. Promise.all(t.map(function (r) {
  4903. return {
  4904. [r]: 9999
  4905. };
  4906. })).then(function (r) {
  4907. var n = Object.assign.apply(Object, [{}].concat(_toConsumableArray(r)));
  4908. _this4.latency(n, e.packetId);
  4909. });
  4910. }
  4911. }, {
  4912. key: "wsNoReady",
  4913. value: function wsNoReady() {
  4914. return this._ws.readyState == WebSocket.CLOSED || this._ws.readyState == WebSocket.CLOSING || this._ws.readyState == WebSocket.CONNECTING;
  4915. }
  4916. }, {
  4917. key: "prepareReconnect",
  4918. value: function prepareReconnect() {
  4919. this._close({
  4920. code: WS_CLOSE_RECONNECT,
  4921. reason: "reconnect"
  4922. });
  4923. }
  4924. }, {
  4925. key: "_onClose",
  4926. value: function _onClose(_ref) {
  4927. var e = _ref.code,
  4928. t = _ref.reason;
  4929. this._openTimer && this._openTimer.clear(), logger$1.warn("ws closed: ".concat(e, " ") + t), [WS_CLOSE_RECONNECT, WS_CLOSE_NORMAL].includes(e) || this.emit("socketClosed", new InternalError("Websocket error"));
  4930. }
  4931. }, {
  4932. key: "_close",
  4933. value: function _close(_ref2) {
  4934. var e = _ref2.code,
  4935. t = _ref2.reason;
  4936. var r;
  4937. (r = this._ws) == null || r.close(e, t);
  4938. }
  4939. }, {
  4940. key: "quit",
  4941. value: function quit() {
  4942. this._close({
  4943. code: WS_CLOSE_NORMAL,
  4944. reason: "quit"
  4945. });
  4946. }
  4947. }]);
  4948. return Socket;
  4949. }(EventEmitter);
  4950. function add(i, e) {
  4951. return e == -1 && (e = 0), i + e;
  4952. }
  4953. function max(i, e) {
  4954. return Math.max(i, e);
  4955. }
  4956. function count_sd(i, e) {
  4957. function t(r, n) {
  4958. var o = 0;
  4959. return n == -1 ? o = 0 : o = (n - e) * (n - e), r + o;
  4960. }
  4961. return Math.sqrt(i.reduce(t, 0) / i.reduce(count_valid, 0)) || 0;
  4962. }
  4963. function count_valid(i, e) {
  4964. var t = 0;
  4965. return e != -1 && (t = 1), i + t;
  4966. }
  4967. function count_less(i, e) {
  4968. function t(r, n) {
  4969. var o = 0;
  4970. return n != -1 && n < e && (o = 1), r + o;
  4971. }
  4972. return i.reduce(t, 0);
  4973. }
  4974. var CircularArray = /*#__PURE__*/function () {
  4975. function CircularArray(e, t, r) {
  4976. _classCallCheck(this, CircularArray);
  4977. 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);
  4978. }
  4979. _createClass(CircularArray, [{
  4980. key: "add",
  4981. value: function add(e) {
  4982. 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);
  4983. }
  4984. }, {
  4985. key: "computeAvg",
  4986. value: function computeAvg(e) {
  4987. return e.reduce(add, 0) / e.reduce(count_valid, 0) || 0;
  4988. }
  4989. }, {
  4990. key: "computeMax",
  4991. value: function computeMax(e) {
  4992. return e.reduce(max, 0) || 0;
  4993. }
  4994. }, {
  4995. key: "computeThreshPercent",
  4996. value: function computeThreshPercent(e) {
  4997. if (this.countLess) {
  4998. var t = count_less(e, this.lessThreshes[0]) || 0,
  4999. r = count_less(e, this.lessThreshes[1]) || 0,
  5000. n = count_less(e, this.lessThreshes[2]) || 0,
  5001. o = count_less(e, this.lessThreshes[3]) || 0,
  5002. a = e.reduce(count_valid, 0);
  5003. return [t, r, n, o, a];
  5004. } else return [0, 0, 0, 0, 0];
  5005. }
  5006. }, {
  5007. key: "getAvg",
  5008. value: function getAvg() {
  5009. var e = this.sum / this.count || 0,
  5010. t = this.computeAvg(this.circularData) || 0;
  5011. return Math.abs(e - t) > .01 && console.error("avg value mismatch: ", e, t), this.computeAvg(this.circularData) || 0;
  5012. }
  5013. }, {
  5014. key: "getMax",
  5015. value: function getMax() {
  5016. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  5017. var t = this.computeMax(this.circularData) || 0;
  5018. return e && Math.abs(t - this.max) > .01 && console.error("max value mismatch: ", this.max, t), this.computeMax(this.circularData) || 0;
  5019. }
  5020. }, {
  5021. key: "getStandardDeviation",
  5022. value: function getStandardDeviation() {
  5023. return count_sd(this.circularData, this.getAvg());
  5024. }
  5025. }, {
  5026. key: "getThreshPercent",
  5027. value: function getThreshPercent() {
  5028. return this.computeThreshPercent(this.circularData);
  5029. }
  5030. }, {
  5031. key: "getIncomingMax",
  5032. value: function getIncomingMax() {
  5033. return this.computeMax(this.incomingData) || 0;
  5034. }
  5035. }, {
  5036. key: "getIncomingAvg",
  5037. value: function getIncomingAvg() {
  5038. return this.computeAvg(this.incomingData) || 0;
  5039. }
  5040. }, {
  5041. key: "getIncomingStandardDeviation",
  5042. value: function getIncomingStandardDeviation() {
  5043. return count_sd(this.incomingData, this.getIncomingAvg());
  5044. }
  5045. }, {
  5046. key: "getIncomingThreshPercent",
  5047. value: function getIncomingThreshPercent() {
  5048. return this.computeThreshPercent(this.incomingData);
  5049. }
  5050. }, {
  5051. key: "clearFastComputeItem",
  5052. value: function clearFastComputeItem() {
  5053. 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;
  5054. }
  5055. }, {
  5056. key: "clearIncoming",
  5057. value: function clearIncoming() {
  5058. for (; this.incomingData.length > 0;) {
  5059. this.incomingData.pop();
  5060. }
  5061. }
  5062. }, {
  5063. key: "clear",
  5064. value: function clear() {
  5065. this.circularData.fill(-1), this.circularPtr = 0, this.clearFastComputeItem(), this.clearIncoming();
  5066. }
  5067. }]);
  5068. return CircularArray;
  5069. }();
  5070. function _createForOfIteratorHelper$4(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$4(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; } } }; }
  5071. function _unsupportedIterableToArray$4(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$4(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$4(o, minLen); }
  5072. function _arrayLikeToArray$4(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; }
  5073. var defaultLogger = {
  5074. info: console.log,
  5075. debug: console.log,
  5076. error: console.error,
  5077. infoAndReportMeasurement: function infoAndReportMeasurement() {}
  5078. };
  5079. var FRAME_COMPOSE_LENGTH = 5;
  5080. var Workers = /*#__PURE__*/function () {
  5081. function Workers(e, t) {
  5082. var _this = this;
  5083. _classCallCheck(this, Workers);
  5084. 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 = {
  5085. x: 0,
  5086. y: 0,
  5087. z: 0,
  5088. tiles: []
  5089. }, 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 () {
  5090. return DECODER_VERSION;
  5091. }, this.downloadBlob = function (r, n, o) {
  5092. var a = new Blob([r], {
  5093. type: o
  5094. }),
  5095. s = window.URL.createObjectURL(a);
  5096. _this.downloadURL(s, n), setTimeout(function () {
  5097. return window.URL.revokeObjectURL(s);
  5098. }, 1e3);
  5099. }, this.downloadURL = function (r, n) {
  5100. var o = document.createElement("a");
  5101. o.href = r, o.download = n, document.body.appendChild(o), o.style.display = "none", o.click(), o.remove();
  5102. }, this.Stringify = function (r) {
  5103. var n = "";
  5104. for (var a = 0; a < r.length / 8192; a++) {
  5105. n += String.fromCharCode.apply(null, r.slice(a * 8192, (a + 1) * 8192));
  5106. }
  5107. return n;
  5108. }, this._rtcp = e;
  5109. }
  5110. _createClass(Workers, [{
  5111. key: "registerLogger",
  5112. value: function registerLogger(e) {//defaultLogger = e
  5113. }
  5114. }, {
  5115. key: "registerFunction",
  5116. value: function registerFunction(e, t) {
  5117. this.functionMap.set(e, t);
  5118. }
  5119. }, {
  5120. key: "hasFrmCntInCache",
  5121. value: function hasFrmCntInCache(e) {
  5122. var t = -1;
  5123. for (var r = 0; r < this.cacheFrameComposes.length; r++) {
  5124. this.cacheFrameComposes[r].frameCnt == e && (t = r);
  5125. }
  5126. return t;
  5127. }
  5128. }, {
  5129. key: "requestPanoramaTest",
  5130. value: function requestPanoramaTest(e, t, r, n, o) {
  5131. var a = o,
  5132. s = {
  5133. action_type: 16,
  5134. change_rotation_render_type_action: {
  5135. render_type: 5,
  5136. player: {
  5137. position: {
  5138. x: 0,
  5139. y: 0,
  5140. z: 0
  5141. },
  5142. angle: {
  5143. yaw: 0,
  5144. pitch: 0,
  5145. roll: 0
  5146. }
  5147. },
  5148. camera: {
  5149. position: {
  5150. x: e,
  5151. y: t,
  5152. z: r
  5153. },
  5154. angle: {
  5155. yaw: 0,
  5156. pitch: 0,
  5157. roll: 0
  5158. }
  5159. },
  5160. client_pano_titles_bitmap: n
  5161. },
  5162. trace_id: a,
  5163. user_id: this.userId_test,
  5164. packet_id: a
  5165. };
  5166. defaultLogger.debug("send data: ", s), this._rtcp.sendData(s);
  5167. }
  5168. }, {
  5169. key: "onRotateInPanoMode",
  5170. value: function onRotateInPanoMode(e) {
  5171. var t = e.traceId,
  5172. r = {};
  5173. r.width = 1280, r.height = 720, r.horz_fov = 92, r.angle = {
  5174. yaw: 100,
  5175. pitch: 30
  5176. };
  5177. var n = new ArrayBuffer(8),
  5178. o = new DataView(n);
  5179. getTilesInView(r, n);
  5180. var a = n.slice(0);
  5181. this.PendingMasks.unshift({
  5182. buffer: a,
  5183. angle: r.angle
  5184. }), MaskSetToOne(18, this.PanoView), operateForDataView(o, this.PanoView, o, function (s, l) {
  5185. return s ^ s & l;
  5186. }), 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);
  5187. }
  5188. }, {
  5189. key: "processMetaWithTraceId",
  5190. value: function processMetaWithTraceId(e) {
  5191. var _iterator = _createForOfIteratorHelper$4(e.traceIds),
  5192. _step;
  5193. try {
  5194. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  5195. var t = _step.value;
  5196. if (this.traceIdMap.has(t)) {
  5197. var r = this.traceIdMap.get(t);
  5198. r != null && (r.receiveTime = Date.now(), r.status = 1);
  5199. }
  5200. if (t == this.PendingMovingTraceId) {
  5201. 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());
  5202. var _r = Date.now();
  5203. this.lastMoveResponseTime = _r, this.lastMoveProcessTime = _r, this.lastMoveDisplayTime = _r, this.frameServerCircular.clear(), this.frameClientCircular.clear();
  5204. }
  5205. }
  5206. } catch (err) {
  5207. _iterator.e(err);
  5208. } finally {
  5209. _iterator.f();
  5210. }
  5211. }
  5212. }, {
  5213. key: "onTraceId",
  5214. value: function onTraceId(e) {
  5215. var _this2 = this;
  5216. var r = e.traceId,
  5217. n = e.timestamp,
  5218. o = e.event;
  5219. if (o === "Rotation") {
  5220. var a = {
  5221. traceId: r,
  5222. pts: 0,
  5223. startTime: n,
  5224. receiveTime: 0,
  5225. readyTime: 0,
  5226. displayTime: 0,
  5227. status: 0
  5228. };
  5229. this.traceIdMap.set(r, a);
  5230. var s = setTimeout(function () {
  5231. if (s && clearTimeout(s), _this2.traceIdMap.has(r)) {
  5232. var l = _this2.traceIdMap.get(r);
  5233. switch (l == null ? void 0 : l.status) {
  5234. case 0:
  5235. {
  5236. _this2.responseMiss += 1;
  5237. break;
  5238. }
  5239. case 1:
  5240. {
  5241. _this2.processMiss += 1;
  5242. var u = l.receiveTime - l.startTime;
  5243. _this2.responseTimeArray.push(u);
  5244. break;
  5245. }
  5246. case 2:
  5247. {
  5248. _this2.displayMiss += 1;
  5249. var _u = l.receiveTime - l.startTime,
  5250. c = l.readyTime - l.receiveTime;
  5251. _this2.responseTimeArray.push(_u), _this2.processTimeArray.push(c);
  5252. break;
  5253. }
  5254. case 3:
  5255. defaultLogger.debug("status is 3");
  5256. }
  5257. }
  5258. }, 1e3);
  5259. } 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();
  5260. }
  5261. }, {
  5262. key: "executeFunction",
  5263. value: function executeFunction(e, t) {
  5264. if (this.functionMap.has(e)) {
  5265. var r = this.functionMap.get(e);
  5266. r != null && r(t);
  5267. }
  5268. }
  5269. }, {
  5270. key: "UpdateStats",
  5271. value: function UpdateStats(e) {
  5272. var _this3 = this;
  5273. var t;
  5274. (t = this._rtcp.connection) == null || t.getStats(null).then(function (r) {
  5275. r.forEach(function (n) {
  5276. n.type == "data-channel" && (_this3.rtcMessageReceived = n.messagesReceived - n.messagesSent, _this3.rtcBytesReceived = n.bytesReceived);
  5277. });
  5278. }), 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;
  5279. }
  5280. }, {
  5281. key: "ReceiveDecodeMessage",
  5282. value: function ReceiveDecodeMessage(e) {
  5283. var n;
  5284. if (!this.firstYUVReceived) {
  5285. this.firstYUVDecoded = e.data.yuv_ts;
  5286. var o = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  5287. defaultLogger.infoAndReportMeasurement({
  5288. metric: "firstYUVDecodedAt",
  5289. value: o,
  5290. group: "joinRoom"
  5291. }), this.firstRender = Date.now();
  5292. var a = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  5293. defaultLogger.infoAndReportMeasurement({
  5294. metric: "firstRenderAt",
  5295. value: a,
  5296. group: "joinRoom"
  5297. }), this.firstYUVReceived = !0, this.lastRenderTs = Date.now();
  5298. }
  5299. !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", {
  5300. stream: this.cachedStreams[this.setPtr],
  5301. width: this.cachedResolution[this.setPtr].width,
  5302. height: this.cachedResolution[this.setPtr].height,
  5303. pts: this.cachedPtss[this.setPtr]
  5304. }), this.executeFunction("signal", {
  5305. signal: this.cachedMetas[this.setPtr],
  5306. pts: this.cachedPtss[this.setPtr],
  5307. alreadyUpdateYUV: !0
  5308. })) : this.updateDropFrame += 1, this.decoderWorker.postMessage({
  5309. t: 2,
  5310. frameCnt: this.cachedPtss[this.setPtr],
  5311. buffer: this.cachedStreams[this.setPtr]
  5312. }, [this.cachedStreams[this.setPtr].buffer])), this.getPtr = (this.getPtr + 1) % this.cachedLength);
  5313. var t = e.data.metadata;
  5314. if ((n = t == null ? void 0 : t.traceIds) != null && n.length) {
  5315. var _iterator2 = _createForOfIteratorHelper$4(t.traceIds),
  5316. _step2;
  5317. try {
  5318. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  5319. var _o = _step2.value;
  5320. if (this.traceIdMap.has(_o)) {
  5321. var _a = this.traceIdMap.get(_o);
  5322. _a != null && (_a.readyTime = Date.now(), _a.status = 2);
  5323. }
  5324. }
  5325. } catch (err) {
  5326. _iterator2.e(err);
  5327. } finally {
  5328. _iterator2.f();
  5329. }
  5330. }
  5331. if (e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs), this.userId_test = this.rtcp.network.room.userId, this.inMovingMode) {
  5332. var _o2 = Date.now(),
  5333. _a2 = _o2 - this.lastMoveProcessTime;
  5334. this.moveProcessCircular.add(_a2), this.lastMoveProcessTime = _o2;
  5335. }
  5336. var r = this.setPtr;
  5337. 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] = {
  5338. width: e.data.width,
  5339. height: e.data.height
  5340. }, this.setPtr = (this.setPtr + 1) % this.cachedLength;
  5341. }
  5342. }, {
  5343. key: "SendCacheFrameInfo",
  5344. value: function SendCacheFrameInfo(e) {
  5345. var _this4 = this;
  5346. var h, f, d, _, g, m, v;
  5347. var t = e.data.cachedKey,
  5348. r = e.data.metadata,
  5349. n = t,
  5350. o = r,
  5351. a = (d = (f = (h = o.newUserStates) == null ? void 0 : h.find(function (y) {
  5352. return y.userId === _this4.rtcp.network.room.userId;
  5353. })) == null ? void 0 : f.playerState) == null ? void 0 : d.roomTypeId,
  5354. s = this.rtcp.network.room.skinId,
  5355. l = (v = (m = (g = (_ = o.newUserStates) == null ? void 0 : _.find(function (y) {
  5356. return y.userId === _this4._rtcp.network.room.userId;
  5357. })) == null ? void 0 : g.playerState) == null ? void 0 : m.player) == null ? void 0 : v.position,
  5358. u = {
  5359. MsgType: 1,
  5360. FrameCacheMsg: {
  5361. FrameIndex: n,
  5362. RoomTypeId: a,
  5363. SkinID: s,
  5364. Position: l
  5365. }
  5366. };
  5367. var c = "";
  5368. try {
  5369. c = JSON.stringify(u);
  5370. } catch (y) {
  5371. defaultLogger.error(y);
  5372. return;
  5373. }
  5374. }
  5375. }, {
  5376. key: "ReceivePanoramaDecodeMessage",
  5377. value: function ReceivePanoramaDecodeMessage(e) {
  5378. defaultLogger.info("Receive Panorama Image in Workers.ts"), MaskSetToOne(e.data.tileId, this.PanoView);
  5379. var t = 0,
  5380. r;
  5381. var n = this.PendingMasks.length;
  5382. for (t = 0; t < n; t++) {
  5383. var o = this.PendingMasks[t].buffer,
  5384. a = new DataView(o),
  5385. s = new ArrayBuffer(8),
  5386. l = new DataView(s);
  5387. if (operateForDataView(this.PanoView, a, l, function (u, c) {
  5388. return c ^ u & c;
  5389. }), IsAll0(l)) {
  5390. r = this.PendingMasks[t].angle;
  5391. break;
  5392. }
  5393. }
  5394. for (var _o3 = t; _o3 < n; _o3++) {
  5395. this.PendingMasks.pop();
  5396. }
  5397. this.executeFunction("panorama", {
  5398. data: e.data.data,
  5399. tileId: e.data.tileId,
  5400. pos: {
  5401. x: e.data.x,
  5402. y: e.data.y,
  5403. z: e.data.z
  5404. },
  5405. uuid: e.data.uuid,
  5406. finished: !0,
  5407. matchAngle: r
  5408. });
  5409. }
  5410. }, {
  5411. key: "enable_decoder_queue_logging",
  5412. value: function enable_decoder_queue_logging() {
  5413. this.decoderWorker.postMessage({
  5414. t: 100,
  5415. status: !0
  5416. });
  5417. }
  5418. }, {
  5419. key: "disable_decoder_queue_logging",
  5420. value: function disable_decoder_queue_logging() {
  5421. this.decoderWorker.postMessage({
  5422. t: 100,
  5423. status: !1
  5424. });
  5425. }
  5426. }, {
  5427. key: "init",
  5428. value: function () {
  5429. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  5430. var r,
  5431. n,
  5432. t;
  5433. return regenerator.wrap(function _callee$(_context) {
  5434. while (1) {
  5435. switch (_context.prev = _context.next) {
  5436. case 0:
  5437. for (r = 0; r < FRAME_COMPOSE_LENGTH; r++) {
  5438. n = {
  5439. buffer: new Uint8Array(2621440),
  5440. size: 0,
  5441. startReceiveTime: 0,
  5442. serverTime: 0,
  5443. frameCnt: -1
  5444. };
  5445. this.cacheFrameComposes.push(n);
  5446. }
  5447. t = new Blob([decoder], {
  5448. type: "application/javascript"
  5449. });
  5450. return _context.abrupt("return", (this.decoderWorker = new Worker(URL.createObjectURL(t)), this.decoderWorker.postMessage({
  5451. t: 9,
  5452. url: WASM_URLS[WASM_Version],
  5453. jitterLength: DECODER_PASSIVE_JITTER
  5454. })));
  5455. case 5:
  5456. case "end":
  5457. return _context.stop();
  5458. }
  5459. }
  5460. }, _callee, this);
  5461. }));
  5462. function init() {
  5463. return _init.apply(this, arguments);
  5464. }
  5465. return init;
  5466. }()
  5467. }, {
  5468. key: "UpdateYUV",
  5469. value: function UpdateYUV() {
  5470. var t, r;
  5471. var e = this.getPtr;
  5472. if (this.cachedMetas[e] != null && !this.cachedRender[e]) {
  5473. var n = Date.now();
  5474. if (this.firstUpdateYUV) {
  5475. var h = ((t = this.cachedStreams[e]) == null ? void 0 : t.byteLength) || 0;
  5476. defaultLogger.infoAndReportMeasurement({
  5477. metric: "firstUpdateStreamLength",
  5478. value: h,
  5479. group: "joinRoom"
  5480. }), this.firstUpdateYUV = !1;
  5481. }
  5482. this.cachedStreams[e] != null && this.executeFunction("stream", {
  5483. stream: this.cachedStreams[e],
  5484. width: this.cachedResolution[e].width,
  5485. height: this.cachedResolution[e].height,
  5486. pts: this.cachedPtss[e]
  5487. });
  5488. var o = Date.now();
  5489. this.cachedStreams[e] != null && this.decoderWorker.postMessage({
  5490. t: 2,
  5491. frameCnt: this.cachedPtss[e],
  5492. buffer: this.cachedStreams[e]
  5493. }, [this.cachedStreams[e].buffer]);
  5494. var a = Date.now(),
  5495. s = o - n,
  5496. l = a - o;
  5497. (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;
  5498. var u = o - n;
  5499. this.updateYUVCircular.add(u);
  5500. var c = this.cachedMetas[e];
  5501. if ((r = c == null ? void 0 : c.traceIds) != null && r.length) {
  5502. var _iterator3 = _createForOfIteratorHelper$4(c.traceIds),
  5503. _step3;
  5504. try {
  5505. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  5506. var _h = _step3.value;
  5507. if (this.traceIdMap.has(_h)) {
  5508. var f = this.traceIdMap.get(_h);
  5509. if (f != null) {
  5510. f.displayTime = Date.now(), f.status = 3;
  5511. var d = f.receiveTime - f.startTime,
  5512. _ = f.readyTime - f.receiveTime,
  5513. g = f.displayTime - f.readyTime,
  5514. m = f.displayTime - f.startTime;
  5515. this.responseTimeArray.push(d), this.processTimeArray.push(_), this.displayTimeArray.push(g), this.overallTimeArray.push(m), this.traceIdMap.delete(_h);
  5516. }
  5517. }
  5518. }
  5519. } catch (err) {
  5520. _iterator3.e(err);
  5521. } finally {
  5522. _iterator3.f();
  5523. }
  5524. }
  5525. if (this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs), this.inMovingMode) {
  5526. var _h2 = Date.now(),
  5527. _f = _h2 - this.lastMoveDisplayTime;
  5528. this.moveDisplayCircular.add(_f), this.lastMoveDisplayTime = _h2;
  5529. }
  5530. this.executeFunction("signal", {
  5531. signal: this.cachedMetas[e],
  5532. pts: this.cachedPtss[e],
  5533. alreadyUpdateYUV: !0
  5534. }), this.cachedRender[e] = !0, this.getPtr = (this.getPtr + 1) % this.cachedLength;
  5535. }
  5536. }
  5537. }, {
  5538. key: "unmarshalPano",
  5539. value: function unmarshalPano(e) {
  5540. var t = new DataView(e);
  5541. if (t.getUint32(0) != 1723558763) return !1;
  5542. console.log("Receive Pano Message"), t.getUint16(4);
  5543. var n = t.getUint16(6),
  5544. o = t.getUint32(8),
  5545. a = t.getUint32(12) - (1 << 30) * 2,
  5546. s = t.getUint32(16) - (1 << 30) * 2,
  5547. l = t.getUint32(20) - (1 << 30) * 2,
  5548. u = t.getUint32(24),
  5549. c = new Uint8Array(e).subarray(28, 64),
  5550. h = String.fromCharCode.apply(null, c),
  5551. f = t.getUint32(64),
  5552. d = e.byteLength - n;
  5553. if (d == u) {
  5554. var g = {
  5555. data: new Uint8Array(e).subarray(n),
  5556. mediaLen: u,
  5557. tileId: o,
  5558. uuid: h,
  5559. x: a,
  5560. y: s,
  5561. z: l
  5562. };
  5563. this.decoderWorker.postMessage({
  5564. t: 8,
  5565. data: g
  5566. });
  5567. } else {
  5568. var _ = new Uint8Array(e, n, d);
  5569. if (this.cachePanoTileID == o) {
  5570. if (this.panoCacheBuffer.set(_, f), this.panoCacheSize += d, this.panoCacheSize === u) {
  5571. var m = {
  5572. data: new Uint8Array(this.panoCacheBuffer).slice(0, u),
  5573. mediaLen: u,
  5574. tileId: o,
  5575. uuid: h,
  5576. x: a,
  5577. y: s,
  5578. z: l
  5579. };
  5580. this.decoderWorker.postMessage({
  5581. t: 8,
  5582. data: m
  5583. }), this.panoCacheSize = 0;
  5584. }
  5585. } else this.panoCacheBuffer.set(_, f), this.panoCacheSize = d, this.cachePanoTileID = o;
  5586. }
  5587. return !0;
  5588. }
  5589. }, {
  5590. key: "clearMoveArray",
  5591. value: function clearMoveArray() {
  5592. 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 = "";
  5593. }
  5594. }, {
  5595. key: "getIsMoving",
  5596. value: function getIsMoving(e) {
  5597. var t;
  5598. if (typeof e.newUserStates != "undefined") for (var r = 0; r < e.newUserStates.length; r++) {
  5599. var n = e.newUserStates[r];
  5600. if (n.userId == this.rtcp.network.room.userId) {
  5601. t = n.renderInfo.isMoving;
  5602. break;
  5603. }
  5604. }
  5605. return t;
  5606. }
  5607. }, {
  5608. key: "isHeartBeatPacket",
  5609. value: function isHeartBeatPacket(e, t) {
  5610. return new DataView(e).getUint32(0) == 2009889916;
  5611. }
  5612. }, {
  5613. key: "resetSendTimeDiff",
  5614. value: function resetSendTimeDiff() {
  5615. this.prevSenderTs = 0, this.serverSendTimeArray.clear();
  5616. }
  5617. }, {
  5618. key: "calcSendTimeDiff",
  5619. value: function calcSendTimeDiff(e) {
  5620. if (this.prevSenderTs == -1) {
  5621. this.prevSenderTs = e;
  5622. return;
  5623. }
  5624. var t = e - this.prevSenderTs;
  5625. this.serverSendTimeArray.add(t), this.prevSenderTs = e;
  5626. }
  5627. }, {
  5628. key: "unmarshalStream",
  5629. value: function unmarshalStream(e) {
  5630. var _this6 = this;
  5631. var T, C, A, S, P, R, M, x, I, w;
  5632. var t = new DataView(e);
  5633. if (t.getUint32(0) != 1437227610) return !1;
  5634. t.getUint16(4);
  5635. var n = t.getUint16(6),
  5636. o = t.getUint16(8),
  5637. a = o,
  5638. s = t.getUint16(10);
  5639. var l = !1;
  5640. s == 1 && (l = !0);
  5641. var u = t.getUint32(12),
  5642. c = t.getUint32(16),
  5643. h = t.getUint32(20),
  5644. f = t.getUint16(24),
  5645. d = t.getUint16(26),
  5646. _ = t.getUint32(28),
  5647. g = t.getUint32(n - 4),
  5648. m = u + c,
  5649. v = e.byteLength - n,
  5650. y = new Uint8Array(e, n, v);
  5651. this.calcSendTimeDiff(h);
  5652. var b;
  5653. if (this.inPanoMode && (c > 0 || f)) return defaultLogger.error("Stream Protocal Violation: receive illegal stream in Pano mode"), !0;
  5654. if (v === m) {
  5655. this.receivedMedia++;
  5656. var O = new Uint8Array(e).subarray(n);
  5657. h - this.lastServerTS > 60 ? this.serverFrameSlow++ : h - this.lastServerTS < 16 && this.serverFrameFast++;
  5658. var D = Date.now();
  5659. D - this.lastClientTS > 60 ? this.clientFrameSlow++ : D - this.lastClientTS < 16 && this.clientFrameFast++;
  5660. var F = c === 0,
  5661. V = h - this.lastServerTS;
  5662. 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;
  5663. var N = O.subarray(0, u),
  5664. L = Date.now(),
  5665. k = JSON.parse(this.Stringify(N)),
  5666. U = Date.now();
  5667. 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));
  5668. var z = this.getIsMoving(k);
  5669. if (this.inMovingMode && z == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof z != "undefined" && (this.lastIsMoving = z), this.inMovingMode) {
  5670. var G = Date.now(),
  5671. W = G - this.lastMoveResponseTime;
  5672. this.moveResponseCircular.add(W), this.lastMoveResponseTime = G;
  5673. }
  5674. (f || d) && (b = (P = (S = (A = (C = k.newUserStates) == null ? void 0 : C.find(function (G) {
  5675. return G.userId === _this6._rtcp.network.room.userId;
  5676. })) == null ? void 0 : A.playerState) == null ? void 0 : S.player) == null ? void 0 : P.position);
  5677. var H = {
  5678. t: 0,
  5679. data: O,
  5680. mediaLen: c,
  5681. metaLen: u,
  5682. metadata: k,
  5683. frameCnt: a,
  5684. server_ts: h,
  5685. isIDR: l,
  5686. cacheRequest: d,
  5687. cached: f,
  5688. cachedKey: _,
  5689. position: b
  5690. };
  5691. if (this.inPanoMode) return this.executeFunction("signal", {
  5692. signal: k,
  5693. pts: -1,
  5694. alreadyUpdateYUV: !0
  5695. }), !0;
  5696. if (this.decoderWorker.postMessage(H, [O.buffer]), !this.firstMediaReceived) {
  5697. this.firstMediaArraval = Date.now();
  5698. var _G = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5699. defaultLogger.infoAndReportMeasurement({
  5700. metric: "firstMediaArravalAt",
  5701. value: _G,
  5702. group: "joinRoom"
  5703. }), this.firstMediaReceived = !0;
  5704. }
  5705. } else {
  5706. var _O = this.hasFrmCntInCache(a);
  5707. if (_O != -1) {
  5708. if (this.cacheFrameComposes[_O].buffer.set(y, g), this.cacheFrameComposes[_O].size += v, this.cacheFrameComposes[_O].size === m) {
  5709. var _D = new Uint8Array(this.cacheFrameComposes[_O].buffer).slice(0, m);
  5710. 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++;
  5711. var _F = Date.now();
  5712. _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;
  5713. var _V = _D.subarray(0, u),
  5714. _N = Date.now(),
  5715. _L = JSON.parse(this.Stringify(_V)),
  5716. _k = Date.now();
  5717. 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);
  5718. var _U = this.getIsMoving(_L);
  5719. if (this.inMovingMode && _U == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof _U != "undefined" && (this.lastIsMoving = _U), this.inMovingMode) {
  5720. var _H = Date.now(),
  5721. _G2 = _H - this.lastMoveResponseTime;
  5722. this.moveResponseCircular.add(_G2), this.lastMoveResponseTime = _H;
  5723. }
  5724. (f || d) && (b = (w = (I = (x = (M = _L.newUserStates) == null ? void 0 : M.find(function (H) {
  5725. return H.userId === _this6._rtcp.network.room.userId;
  5726. })) == null ? void 0 : x.playerState) == null ? void 0 : I.player) == null ? void 0 : w.position);
  5727. var _z = {
  5728. t: 0,
  5729. data: _D,
  5730. mediaLen: c,
  5731. metaLen: u,
  5732. metadata: _L,
  5733. frameCnt: a,
  5734. server_ts: h,
  5735. isIDR: l,
  5736. cacheRequest: d,
  5737. cached: f,
  5738. cachedKey: _,
  5739. position: b
  5740. };
  5741. if (this.inPanoMode) return this.executeFunction("signal", {
  5742. signal: _L,
  5743. pts: -1,
  5744. alreadyUpdateYUV: !0
  5745. }), !0;
  5746. if (this.decoderWorker.postMessage(_z, [_D.buffer]), !this.firstMediaReceived) {
  5747. this.firstMediaArraval = Date.now();
  5748. var _H2 = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5749. defaultLogger.infoAndReportMeasurement({
  5750. metric: "firstMediaArravalAt",
  5751. value: _H2,
  5752. group: "joinRoom"
  5753. }), this.firstMediaReceived = !0;
  5754. }
  5755. } else this.cacheFrameComposes[_O].size > m && defaultLogger.debug("I frame exceed, cache size is ", this.cacheSize, ", total size is ", m);
  5756. } else if (_O == -1) {
  5757. var _D2 = this.hasFrmCntInCache(-1);
  5758. if (_D2 == -1) {
  5759. var _F2 = Date.now() + 1e18,
  5760. _V2 = -1;
  5761. for (var _N2 = 0; _N2 < this.cacheFrameComposes.length; _N2++) {
  5762. this.cacheFrameComposes[_N2].serverTime < _F2 && (_F2 = this.cacheFrameComposes[_N2].serverTime, _V2 = _N2);
  5763. }
  5764. _D2 = _V2;
  5765. }
  5766. 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;
  5767. }
  5768. }
  5769. return !0;
  5770. }
  5771. }, {
  5772. key: "reset",
  5773. value: function reset() {
  5774. defaultLogger.debug("Worker reset is called"), this.cacheFrameCnt = 0, this.receivedMedia = 0, this.reconnectSignal = !0, this.decoderWorker.postMessage({
  5775. t: 4
  5776. });
  5777. }
  5778. }, {
  5779. key: "dataHandleOff",
  5780. value: function dataHandleOff(e) {
  5781. defaultLogger.debug("hhh");
  5782. }
  5783. }, {
  5784. key: "dataHandle",
  5785. value: function dataHandle(e) {
  5786. this.saveframe && (this.decoderWorker.postMessage({
  5787. t: 6
  5788. }), this.saveframe = !1), this.SaveMediaStream && (this.decoderWorker.postMessage({
  5789. t: 7
  5790. }), this.SaveMediaStream = !1);
  5791. var t = new Uint8Array(e);
  5792. if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0) return;
  5793. if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
  5794. this.reconnectSignal && (this.executeFunction("reconnectedFrame", {}), this.reconnectSignal = !1);
  5795. return;
  5796. }
  5797. if (t.length > 20 && this.unmarshalPano(t.buffer) == !0) return;
  5798. this.noWasmBytesReceived += e.byteLength;
  5799. var r = JSON.parse(this.Stringify(t));
  5800. this.executeFunction("signal", {
  5801. signal: r,
  5802. pts: -1,
  5803. alreadyUpdateYUV: !0
  5804. });
  5805. }
  5806. }, {
  5807. key: "changePanoMode",
  5808. value: function changePanoMode(e) {
  5809. this.inPanoMode = e;
  5810. }
  5811. }, {
  5812. key: "uploadDataToServer",
  5813. value: function uploadDataToServer() {
  5814. this.DynamicPanoTest == !0 && (this.onRotateInPanoMode({
  5815. traceId: "b2e1a296-6438-4371-8a31-687beb724ebe"
  5816. }), this.DynamicPanoTest = !1);
  5817. function e(ie, ee) {
  5818. return ee == -1 && (ee = 0), ie + ee;
  5819. }
  5820. function t(ie, ee) {
  5821. return Math.max(ie, ee);
  5822. }
  5823. var r = this.responseTimeArray.reduce(e, 0) / this.responseTimeArray.length || 0,
  5824. n = this.processTimeArray.reduce(e, 0) / this.processTimeArray.length || 0,
  5825. o = this.displayTimeArray.reduce(e, 0) / this.displayTimeArray.length || 0,
  5826. a = this.overallTimeArray.reduce(e, 0) / this.overallTimeArray.length || 0,
  5827. s = this.overallTimeArray.length;
  5828. this.responseTimeArray = [], this.processTimeArray = [], this.displayTimeArray = [], this.overallTimeArray = [];
  5829. var l = this.moveResponseCircular.getThreshPercent(),
  5830. u = l[0],
  5831. c = l[1],
  5832. h = l[2],
  5833. f = l[3],
  5834. d = l[4],
  5835. _ = d - f,
  5836. g = 1 - c / d || 0,
  5837. m = [u, c - u, h - c, f - h, _],
  5838. v = this.moveProcessCircular.getThreshPercent(),
  5839. y = v[0],
  5840. b = v[1],
  5841. T = v[2],
  5842. C = v[3],
  5843. A = v[4],
  5844. S = A - C,
  5845. P = 1 - b / A || 0,
  5846. R = [y, b - y, T - b, C - T, S],
  5847. M = this.moveDisplayCircular.getThreshPercent(),
  5848. x = M[0],
  5849. I = M[1],
  5850. w = M[2],
  5851. O = M[3],
  5852. D = M[4],
  5853. F = D - O,
  5854. V = 1 - I / D || 0,
  5855. N = [x, I - x, w - I, O - w, F],
  5856. L = x,
  5857. k = I - x,
  5858. U = w - I,
  5859. z = O - w,
  5860. H = F,
  5861. G = this.moveResponseCircular.getAvg(),
  5862. W = this.moveProcessCircular.getAvg(),
  5863. j = this.moveDisplayCircular.getAvg(),
  5864. B = this.moveResponseCircular.getMax(),
  5865. X = this.moveProcessCircular.getMax(),
  5866. $ = this.moveDisplayCircular.getMax(),
  5867. Y = this.moveResponseCircular.getStandardDeviation(),
  5868. K = this.moveProcessCircular.getStandardDeviation(),
  5869. Z = this.moveDisplayCircular.getStandardDeviation();
  5870. 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();
  5871. var q = this.frameServerCircular.getAvg(),
  5872. J = this.frameServerCircular.getMax();
  5873. this.frameClientCircular.getAvg(), this.frameClientCircular.getMax();
  5874. var Q = this.metaParseAraay.reduce(e, 0) / this.metaParseAraay.length || 0,
  5875. te = this.metaParseAraay.reduce(t, 0);
  5876. this.metaParseAraay = [];
  5877. var re = {
  5878. mediaBytesReceived: this.mediaBytesReceived,
  5879. metaBytesReceived: this.metaBytesReceived,
  5880. packetsLost: this.packetsLost,
  5881. timestamp: Date.now(),
  5882. frameHeight: 1280,
  5883. frameWidth: 720,
  5884. framesReceived: this.receivedMedia,
  5885. framesReceivedWorker: this.receivedMedia_worker,
  5886. framesDecoded: this.receivedYUV,
  5887. framesEmited: this.receivedEmit,
  5888. decodeTimePerFrame: this.decodeTimePerFrame,
  5889. decodeTimeMaxFrame: this.decodeTimeMaxFrame,
  5890. packetsDrop: this.packetsDrop,
  5891. framesAwait: this.framesAwait,
  5892. firstMediaArraval: this.firstMediaArraval,
  5893. firstYUVDecoded: this.firstYUVDecoded,
  5894. firstRender: this.firstRender,
  5895. returnFrames: this.returnFrames,
  5896. sendOutBuffer: this.sendOutBuffer,
  5897. maxGraphicTime: this.updateYUVCircular.getMax(),
  5898. averageGraphicTime: this.updateYUVCircular.getAvg(),
  5899. jankTimes: this.JankTimes,
  5900. bigJankTimes: this.bigJankTimes,
  5901. decodeJankTimes: this.DecodeJankTimes,
  5902. bigDecodeJankTimes: this.bigDecodeJankTimes,
  5903. serverFrameSlow: this.serverFrameSlow,
  5904. serverFrameFast: this.serverFrameFast,
  5905. clientFrameSlow: this.clientFrameSlow,
  5906. clientFrameFast: this.clientFrameFast,
  5907. rtcMessageReceived: this.rtcMessageReceived,
  5908. rtcBytesReceived: this.rtcBytesReceived - this.noWasmBytesReceived,
  5909. receiveIframes: this.receiveIframes,
  5910. decodeIframes: this.decodeIframes,
  5911. avgResponseTime: r,
  5912. avgProcessTime: n,
  5913. avgDisplayTime: o,
  5914. avgOverallTime: a,
  5915. overallTimeCount: s,
  5916. responseMiss: this.responseMiss,
  5917. processMiss: this.processMiss,
  5918. displayMiss: this.displayMiss,
  5919. updateDropFrame: this.updateDropFrame,
  5920. moveEvent: this.moveEvent,
  5921. avgResponseMoveDiff: this.moveEvent == "MoveTo" ? G : 0,
  5922. avgProcessMoveDiff: this.moveEvent == "MoveTo" ? W : 0,
  5923. avgDisplayMoveDiff: this.moveEvent == "MoveTo" ? j : 0,
  5924. maxResponseMoveDiff: this.moveEvent == "MoveTo" ? B : 0,
  5925. maxProcessMoveDiff: this.moveEvent == "MoveTo" ? X : 0,
  5926. maxDisplayMoveDiff: this.moveEvent == "MoveTo" ? $ : 0,
  5927. moveResponseJank: this.moveEvent == "MoveTo" ? g : 0,
  5928. moveProcessJank: this.moveEvent == "MoveTo" ? P : 0,
  5929. moveDisplayJank: this.moveEvent == "MoveTo" ? V : 0,
  5930. moveResponseCounts: this.moveEvent == "MoveTo" ? m.toString() : "0,0,0,0,0",
  5931. moveProcessCounts: this.moveEvent == "MoveTo" ? R.toString() : "0,0,0,0,0",
  5932. moveDisplayCounts: this.moveEvent == "MoveTo" ? N.toString() : "0,0,0,0,0",
  5933. MoveDisplayCountGood: this.moveEvent == "MoveTo" ? L.toString() : "0",
  5934. MoveDisplayCountWell: this.moveEvent == "MoveTo" ? k.toString() : "0",
  5935. MoveDisplayCountFair: this.moveEvent == "MoveTo" ? U.toString() : "0",
  5936. MoveDisplayCountBad: this.moveEvent == "MoveTo" ? z.toString() : "0",
  5937. MoveDisplayCountRest: this.moveEvent == "MoveTo" ? H.toString() : "0",
  5938. moveResponseDelay: this.moveEvent == "MoveTo" ? this.MoveResponseDelay : 0,
  5939. moveProcessDelay: this.moveEvent == "MoveTo" ? this.MoveProcessDelay : 0,
  5940. moveDisplayDelay: this.moveEvent == "MoveTo" ? this.MoveDisplayDelay : 0,
  5941. sdMoveResponseLongTime: Y,
  5942. sdMoveProcessLongTime: K,
  5943. sdMoveDisplayLongTime: Z,
  5944. avgResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? G : 0,
  5945. avgProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? W : 0,
  5946. avgDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? j : 0,
  5947. maxResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? B : 0,
  5948. maxProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? X : 0,
  5949. maxDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? $ : 0,
  5950. flyResponseJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? g : 0,
  5951. flyProcessJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? P : 0,
  5952. flyDisplayJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? V : 0,
  5953. flyResponseCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? m.toString() : "0,0,0,0,0",
  5954. flyProcessCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? R.toString() : "0,0,0,0,0",
  5955. flyDisplayCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? N.toString() : "0,0,0,0,0",
  5956. flyResponseDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveResponseDelay : 0,
  5957. flyProcessDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveProcessDelay : 0,
  5958. flyDisplayDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveDisplayDelay : 0,
  5959. avgMetaParseTime: Q,
  5960. maxMetaParseTime: te,
  5961. avgServerDiff: q,
  5962. maxServerDiff: J,
  5963. streamType: WASM_Version
  5964. };
  5965. return this.lastReturnFrames = this.returnFrames, this.lastReceivedEmit = this.receivedEmit, re;
  5966. }
  5967. }]);
  5968. return Workers;
  5969. }();
  5970. 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); }; }
  5971. 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; } }
  5972. var Rtcp = /*#__PURE__*/function (_EventEmitter) {
  5973. _inherits(Rtcp, _EventEmitter);
  5974. var _super = _createSuper$c(Rtcp);
  5975. function Rtcp(e) {
  5976. var _this;
  5977. _classCallCheck(this, Rtcp);
  5978. _this = _super.call(this);
  5979. E(_assertThisInitialized(_this), "connection", null);
  5980. E(_assertThisInitialized(_this), "inputChannel", null);
  5981. E(_assertThisInitialized(_this), "mediaStream");
  5982. E(_assertThisInitialized(_this), "socket");
  5983. E(_assertThisInitialized(_this), "connected", !1);
  5984. E(_assertThisInitialized(_this), "candidates", []);
  5985. E(_assertThisInitialized(_this), "isAnswered", !1);
  5986. E(_assertThisInitialized(_this), "isFlushing", !1);
  5987. E(_assertThisInitialized(_this), "inputReady", !1);
  5988. E(_assertThisInitialized(_this), "workers");
  5989. E(_assertThisInitialized(_this), "actived", !0);
  5990. E(_assertThisInitialized(_this), "heartbeat");
  5991. E(_assertThisInitialized(_this), "onIcecandidate", function (e) {
  5992. if (e.candidate != null) {
  5993. var t = JSON.stringify(e.candidate);
  5994. logger$1.debug("Got ice candidate: ".concat(t)), _this.network.socket.send({
  5995. id: "ice_candidate",
  5996. data: btoa(t)
  5997. });
  5998. }
  5999. });
  6000. E(_assertThisInitialized(_this), "onIcecandidateerror", function (e) {
  6001. logger$1.error("onicecandidateerror", e.errorCode, e.errorText, e);
  6002. });
  6003. E(_assertThisInitialized(_this), "onIceStateChange", function (e) {
  6004. switch (e.target.iceGatheringState) {
  6005. case "gathering":
  6006. logger$1.info("ice gathering");
  6007. break;
  6008. case "complete":
  6009. logger$1.info("Ice gathering completed");
  6010. }
  6011. });
  6012. E(_assertThisInitialized(_this), "onIceConnectionStateChange", function () {
  6013. if (!!_this.connection) switch (logger$1.info("iceConnectionState: ".concat(_this.connection.iceConnectionState)), _this.connection.iceConnectionState) {
  6014. case "connected":
  6015. {
  6016. _this.connected = !0;
  6017. break;
  6018. }
  6019. case "disconnected":
  6020. {
  6021. _this.connected = !1, _this.emit("rtcDisconnected");
  6022. break;
  6023. }
  6024. case "failed":
  6025. {
  6026. _this.emit("rtcDisconnected"), _this.connected = !1;
  6027. break;
  6028. }
  6029. }
  6030. });
  6031. E(_assertThisInitialized(_this), "setRemoteDescription", /*#__PURE__*/function () {
  6032. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  6033. var a, s, l, r, n, o, u;
  6034. return regenerator.wrap(function _callee$(_context) {
  6035. while (1) {
  6036. switch (_context.prev = _context.next) {
  6037. case 0:
  6038. if (_this.connection) {
  6039. _context.next = 2;
  6040. break;
  6041. }
  6042. return _context.abrupt("return");
  6043. case 2:
  6044. r = JSON.parse(atob(e)), n = new RTCSessionDescription(r);
  6045. _context.next = 5;
  6046. return _this.connection.setRemoteDescription(n);
  6047. case 5:
  6048. _context.next = 7;
  6049. return _this.connection.createAnswer();
  6050. case 7:
  6051. o = _context.sent;
  6052. 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) {
  6053. u = o.sdp.lastIndexOf("a=mid:1");
  6054. o.sdp = o.sdp.slice(0, u) + "a=mid:2" + o.sdp.slice(u + 7);
  6055. }
  6056. _context.prev = 9;
  6057. _context.next = 12;
  6058. return _this.connection.setLocalDescription(o);
  6059. case 12:
  6060. _context.next = 17;
  6061. break;
  6062. case 14:
  6063. _context.prev = 14;
  6064. _context.t0 = _context["catch"](9);
  6065. logger$1.error("error", _context.t0);
  6066. case 17:
  6067. _this.isAnswered = !0, _this.network.rtcp.flushCandidate(), _this.network.socket.send({
  6068. id: "answer",
  6069. data: btoa(JSON.stringify(o))
  6070. }), t.srcObject = _this.mediaStream;
  6071. case 18:
  6072. case "end":
  6073. return _context.stop();
  6074. }
  6075. }
  6076. }, _callee, null, [[9, 14]]);
  6077. }));
  6078. return function (_x, _x2) {
  6079. return _ref.apply(this, arguments);
  6080. };
  6081. }());
  6082. E(_assertThisInitialized(_this), "flushCandidate", function () {
  6083. _this.isFlushing || !_this.isAnswered || (_this.isFlushing = !0, _this.candidates.forEach(function (e) {
  6084. var t = atob(e),
  6085. r = JSON.parse(t);
  6086. if (/172\./.test(r.candidate)) return;
  6087. var n = new RTCIceCandidate(r);
  6088. _this.connection && _this.connection.addIceCandidate(n).then(function () {}, function (o) {
  6089. logger$1.info("add candidate failed", o);
  6090. });
  6091. }), _this.isFlushing = !1);
  6092. });
  6093. E(_assertThisInitialized(_this), "input", function (e) {
  6094. var t;
  6095. !_this.actived || !_this.inputChannel || _this.inputChannel.readyState === "open" && ((t = _this.inputChannel) == null || t.send(e));
  6096. });
  6097. _this.network = e, _this.workers = new Workers(_assertThisInitialized(_this), logger$1), _this.workers.registerLogger(logger$1), _this.workers.registerFunction("data", function (t) {
  6098. _this.emit("data", t);
  6099. }), _this.heartbeat = new Heartbeat({
  6100. ping: function ping(t) {
  6101. e.room.actionsHandler.echo(t);
  6102. },
  6103. pong(t, r) {
  6104. var n;
  6105. r && t > 500 && logger$1.warn("high hb value ".concat(t, ", traceId:") + r), (n = e.room.stats) == null || n.assign({
  6106. hb: t
  6107. });
  6108. }
  6109. });
  6110. return _this;
  6111. }
  6112. _createClass(Rtcp, [{
  6113. key: "start",
  6114. value: function start() {
  6115. var _this2 = this;
  6116. this.connection = new RTCPeerConnection();
  6117. var e = Date.now();
  6118. this.connection.ondatachannel = function (t) {
  6119. logger$1.info("ondatachannel: ".concat(t.channel.label));
  6120. _this2.inputChannel = t.channel;
  6121. _this2.inputChannel.onopen = function () {
  6122. var r;
  6123. logger$1.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$1.infoAndReportMeasurement({
  6124. metric: "datachannelOpenedAt",
  6125. startTime: _this2.network.room._startTime,
  6126. group: "joinRoom"
  6127. }), logger$1.infoAndReportMeasurement({
  6128. metric: "datachannelOpenedCost",
  6129. startTime: e,
  6130. group: "joinRoom"
  6131. }));
  6132. console.log('this.inputChannel', _this2.inputChannel);
  6133. }, _this2.inputChannel.onclose = function () {
  6134. var r;
  6135. return logger$1.info("The input channel has closed, id:", (r = _this2.inputChannel) == null ? void 0 : r.id);
  6136. }, _this2.inputChannel.onmessage = function (r) {
  6137. // console.log('this.workers',this.workers)
  6138. //console.log('inputChannel',r.data)
  6139. _this2.workers.dataHandle(r.data);
  6140. };
  6141. }, this.connection.oniceconnectionstatechange = this.onIceConnectionStateChange, this.connection.onicegatheringstatechange = this.onIceStateChange, this.connection.onicecandidate = this.onIcecandidate, this.connection.onicecandidateerror = this.onIcecandidateerror, this.network.socket.send({
  6142. id: "init_webrtc",
  6143. data: JSON.stringify({
  6144. is_mobile: !0
  6145. })
  6146. });
  6147. }
  6148. }, {
  6149. key: "addCandidate",
  6150. value: function addCandidate(e) {
  6151. e === "" ? this.network.rtcp.flushCandidate() : this.candidates.push(e);
  6152. }
  6153. }, {
  6154. key: "disconnect",
  6155. value: function disconnect() {
  6156. var e, t, r;
  6157. this.heartbeat.stop(), logger$1.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;
  6158. }
  6159. }, {
  6160. key: "sendStringData",
  6161. value: function sendStringData(e) {
  6162. console.log('e', e);
  6163. this.input(e);
  6164. }
  6165. }, {
  6166. key: "sendData",
  6167. value: function sendData(e) {
  6168. var t = "";
  6169. try {
  6170. t = JSON.stringify(e);
  6171. } catch (r) {
  6172. logger$1.error(r);
  6173. return;
  6174. }
  6175. this.input(t);
  6176. }
  6177. }]);
  6178. return Rtcp;
  6179. }(EventEmitter);
  6180. var NetworkMonitor = /*#__PURE__*/function () {
  6181. function NetworkMonitor(e) {
  6182. _classCallCheck(this, NetworkMonitor);
  6183. this._listener = e;
  6184. }
  6185. _createClass(NetworkMonitor, [{
  6186. key: "isOnline",
  6187. get: function get() {
  6188. var e = window.navigator;
  6189. return typeof e.onLine == "boolean" ? e.onLine : !0;
  6190. }
  6191. }, {
  6192. key: "start",
  6193. value: function start() {
  6194. window.addEventListener("online", this._listener), window.addEventListener("offline", this._listener);
  6195. }
  6196. }, {
  6197. key: "stop",
  6198. value: function stop() {
  6199. window.removeEventListener("online", this._listener), window.removeEventListener("offline", this._listener);
  6200. }
  6201. }]);
  6202. return NetworkMonitor;
  6203. }();
  6204. var Stream = /*#__PURE__*/function () {
  6205. function Stream(e) {
  6206. _classCallCheck(this, Stream);
  6207. this.el = null;
  6208. this._streamPlayTimer = null;
  6209. if (!e) {
  6210. this.el = this.createVideoElement();
  6211. return;
  6212. }
  6213. this.el = e;
  6214. }
  6215. _createClass(Stream, [{
  6216. key: "play",
  6217. value: function play() {
  6218. var _this = this;
  6219. return new Promise(function (e, t) {
  6220. _this._streamPlayTimer = new Timeout(function () {
  6221. t(new InternalError("Stream play timeout"));
  6222. }, 5e3), _this.el && _this.el.play().then(function () {
  6223. var r;
  6224. e(), logger$1.info("Media can autoplay"), (r = _this._streamPlayTimer) == null || r.clear();
  6225. }).catch(function (r) {
  6226. var n;
  6227. logger$1.error("Media Failed to autoplay"), logger$1.error(r), t(new InternalError("Media Failed to autoplay")), (n = _this._streamPlayTimer) == null || n.clear();
  6228. });
  6229. });
  6230. }
  6231. }, {
  6232. key: "createVideoElement",
  6233. value: function createVideoElement() {
  6234. var e = document.createElement("video");
  6235. 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;
  6236. }
  6237. }]);
  6238. return Stream;
  6239. }();
  6240. 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); }; }
  6241. 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; } }
  6242. var InternalError$1 = /*#__PURE__*/function (_XverseError) {
  6243. _inherits(InternalError, _XverseError);
  6244. var _super = _createSuper$b(InternalError);
  6245. function InternalError(e) {
  6246. _classCallCheck(this, InternalError);
  6247. return _super.call(this, 1002, e || "\u5185\u90E8\u9519\u8BEF");
  6248. }
  6249. return _createClass(InternalError);
  6250. }(XverseError);
  6251. 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); }; }
  6252. 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; } }
  6253. 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 ";
  6254. var NetworkController = /*#__PURE__*/function (_EventEmitter) {
  6255. _inherits(NetworkController, _EventEmitter);
  6256. var _super = _createSuper$a(NetworkController);
  6257. function NetworkController(e) {
  6258. var _this;
  6259. _classCallCheck(this, NetworkController);
  6260. _this = _super.call(this);
  6261. _this.socket = null;
  6262. _this.rtcp = null;
  6263. _this.stream = null;
  6264. _this._state = 'connecting';
  6265. _this._networkMonitor = null;
  6266. _this.blockedActions = [];
  6267. _this.reconnectCount = 0;
  6268. _this.room = e, _this.socket = new Socket(_assertThisInitialized(_this));
  6269. _this.rtcp = new Rtcp(_assertThisInitialized(_this));
  6270. _this.stream = new Stream();
  6271. _this._networkMonitor = new NetworkMonitor(function () {
  6272. logger$1.info("network changed, online:", _this._networkMonitor.isOnline), _this._state === "disconnected" && _this._networkMonitor.isOnline && (logger$1.info("network back to online, try to reconnect"), _this.reconnect());
  6273. });
  6274. _this.checkNetworkQuality(_this.room.currentNetworkOptions.wsServerUrl);
  6275. _this._networkMonitor.start();
  6276. new VisibilityChangeHandler().subscribe(function (r) {
  6277. var n, o;
  6278. r ? ((o = _this.room.stats) == null || o.disable(), logger$1.infoAndReportMeasurement({
  6279. metric: "pageHide",
  6280. startTime: Date.now()
  6281. })) : ((n = _this.room.stats) == null || n.enable(), logger$1.infoAndReportMeasurement({
  6282. metric: "pageShow",
  6283. startTime: Date.now(),
  6284. extra: {
  6285. state: _this._state
  6286. }
  6287. }), _this._state === "disconnected" && _this.reconnect());
  6288. });
  6289. return _this;
  6290. }
  6291. _createClass(NetworkController, [{
  6292. key: "startGame",
  6293. value: function startGame() {
  6294. var _this2 = this;
  6295. return new Promise(function (e, t) {
  6296. if (!_this2.rtcp.connected) return t(new InternalError$1("Game cannot load. Please refresh"));
  6297. if (!_this2.rtcp.inputReady) return t(new InternalError$1("Game is not ready yet. Please wait"));
  6298. _this2.socket.on("gameRoomAvailable", function (r) {
  6299. _this2.setState("connected"), e(r), _this2.rtcp.heartbeat.start();
  6300. }), _this2.socket.on("socketClosed", function (r) {
  6301. t(r);
  6302. }), _this2.socket.startGame();
  6303. });
  6304. }
  6305. }, {
  6306. key: "addBlockedActions",
  6307. value: function addBlockedActions(e) {
  6308. var _this$blockedActions;
  6309. (_this$blockedActions = this.blockedActions).push.apply(_this$blockedActions, _toConsumableArray(e));
  6310. }
  6311. }, {
  6312. key: "removeBlockedActions",
  6313. value: function removeBlockedActions(e) {
  6314. if (!e) {
  6315. this.blockedActions = [];
  6316. return;
  6317. }
  6318. var t = this.blockedActions.indexOf(e);
  6319. this.blockedActions.splice(t, 1);
  6320. }
  6321. }, {
  6322. key: "setState",
  6323. value: function setState(e) {
  6324. this._state !== e && (logger$1.info("Set network state to ", e), this._state = e);
  6325. }
  6326. }, {
  6327. key: "connectAndStart",
  6328. value: function () {
  6329. var _connectAndStart = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  6330. return regenerator.wrap(function _callee$(_context) {
  6331. while (1) {
  6332. switch (_context.prev = _context.next) {
  6333. case 0:
  6334. return _context.abrupt("return", this.connect(e).then(this.startGame));
  6335. case 1:
  6336. case "end":
  6337. return _context.stop();
  6338. }
  6339. }
  6340. }, _callee, this);
  6341. }));
  6342. function connectAndStart(_x) {
  6343. return _connectAndStart.apply(this, arguments);
  6344. }
  6345. return connectAndStart;
  6346. }()
  6347. }, {
  6348. key: "connect",
  6349. value: function () {
  6350. var _connect = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  6351. var _this3 = this;
  6352. var e,
  6353. _args2 = arguments;
  6354. return regenerator.wrap(function _callee2$(_context2) {
  6355. while (1) {
  6356. switch (_context2.prev = _context2.next) {
  6357. case 0:
  6358. e = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : !1;
  6359. this.room.updateCurrentNetworkOptions({
  6360. reconnect: e
  6361. });
  6362. return _context2.abrupt("return", new Promise(function (t, r) {
  6363. _this3.rtcp.on("rtcConnected", function () {
  6364. _this3.setState("connected"), t();
  6365. }), _this3.rtcp.on("rtcDisconnected", function () {
  6366. logger$1.info("rtc disconnected"), _this3._state === "connecting" ? (_this3.setState("disconnected"), r(new InternalError$1("rtc connect failed"))) : (_this3.setState("disconnected"), logger$1.info("rtc disconnected, start to reconnect"), _this3.reconnect());
  6367. }), _this3.socket.on("socketQuit", function () {
  6368. logger$1.info("socket quit success"), _this3.setState("closed");
  6369. }), _this3.socket.on("socketClosed", function (n) {
  6370. _this3._state === "connecting" && (_this3.setState("disconnected"), r(n)), r(n);
  6371. }), _this3.socket.start();
  6372. }));
  6373. case 3:
  6374. case "end":
  6375. return _context2.stop();
  6376. }
  6377. }
  6378. }, _callee2, this);
  6379. }));
  6380. function connect() {
  6381. return _connect.apply(this, arguments);
  6382. }
  6383. return connect;
  6384. }()
  6385. }, {
  6386. key: "reconnect",
  6387. value: function reconnect() {
  6388. var _this4 = this;
  6389. if (this.room.viewMode === "observer") return;
  6390. var e = Date.now();
  6391. if (this.reconnectCount++, this.reconnectCount > MAX_RECONNECT_COUNT) {
  6392. logger$1.error("reconnect failed, reached max reconnect count", MAX_RECONNECT_COUNT), this.reconnectCount = 0, this.emit("stateChanged", {
  6393. state: "disconnected"
  6394. });
  6395. return;
  6396. }
  6397. return logger$1.info("start reconnect, count:", this.reconnectCount), this._reconnect().then(function () {
  6398. logger$1.infoAndReportMeasurement({
  6399. startTime: e,
  6400. metric: "reconnect"
  6401. });
  6402. }).catch(function (t) {
  6403. if (logger$1.infoAndReportMeasurement({
  6404. startTime: e,
  6405. metric: "reconnect",
  6406. error: t
  6407. }), t.code === Codes.RepeatLogin) {
  6408. _this4.room.handleRepetLogin();
  6409. return;
  6410. }
  6411. var r = 1e3;
  6412. logger$1.info("reconnect failed, wait " + r + " ms for next reconnect"), setTimeout(function () {
  6413. _this4.reconnect();
  6414. }, r);
  6415. });
  6416. }
  6417. }, {
  6418. key: "_reconnect",
  6419. value: function _reconnect() {
  6420. var _this5 = this;
  6421. return this._state === "closed" ? (logger$1.warn("connection closed already"), Promise.reject()) : this._state === "connecting" ? (logger$1.warn("connection is already in connecting state"), Promise.reject()) : this._state !== "disconnected" ? Promise.reject() : (this.prepareReconnect(), this._state = "connecting", this.emit("stateChanged", {
  6422. state: "reconnecting",
  6423. count: this.reconnectCount
  6424. }), this.socket.off("gameRoomAvailable"), this.socket.off("socketClosed"), this.rtcp.off("rtcDisconnected"), this.rtcp.off("rtcConnected"), this.connectAndStart(!0).then(function (_ref) {
  6425. var e = _ref.session_id;
  6426. _this5.room.updateCurrentNetworkOptions({
  6427. sessionId: e
  6428. }), reporter.updateBody({
  6429. serverSession: e
  6430. }), logger$1.info("reconnect success"), _this5.setState("connected"), _this5.reconnectCount = 0, _this5.emit("stateChanged", {
  6431. state: "reconnected"
  6432. });
  6433. }));
  6434. }
  6435. }, {
  6436. key: "prepareReconnect",
  6437. value: function prepareReconnect() {
  6438. this.rtcp.disconnect(), this.socket.prepareReconnect(), this.prepareReconnectOptions();
  6439. }
  6440. }, {
  6441. key: "prepareReconnectOptions",
  6442. value: function prepareReconnectOptions() {
  6443. var _ref2 = this.room.currentClickingState || {},
  6444. e = _ref2.camera,
  6445. t = _ref2.player;
  6446. e && t && this.room.updateCurrentNetworkOptions({
  6447. camera: e,
  6448. player: t
  6449. });
  6450. }
  6451. }, {
  6452. key: "sendRtcData",
  6453. value: function sendRtcData(e) {
  6454. if (this.blockedActions.includes(e.action_type)) {
  6455. logger$1.info("action: ".concat(Actions[e.action_type], " was blocked"));
  6456. return;
  6457. }
  6458. this.rtcp.sendData(e);
  6459. }
  6460. }, {
  6461. key: "sendSocketData",
  6462. value: function sendSocketData(e) {
  6463. logger$1.debug("ws send ->", e), this.socket.send(e);
  6464. }
  6465. }, {
  6466. key: "quit",
  6467. value: function quit() {
  6468. var e = util.uuid(),
  6469. t = {
  6470. action_type: Actions.Exit,
  6471. trace_id: e,
  6472. exit_action: {},
  6473. user_id: this.room.options.userId,
  6474. packet_id: e
  6475. };
  6476. this.setState("closed"), this.socket.quit(), this.sendRtcData(t);
  6477. }
  6478. }, {
  6479. key: "checkNetworkQuality",
  6480. value: function checkNetworkQuality(i) {
  6481. var worker = null;
  6482. if (!i) return;
  6483. var e = Date.now();
  6484. if (this.pingOthers("https://www.baidu.com", function (t, r) {
  6485. logger$1.infoAndReportMeasurement({
  6486. metric: "baiduRtt",
  6487. group: "http",
  6488. value: r,
  6489. startTime: e
  6490. });
  6491. }), !worker) {
  6492. var t = new Blob([workerSourceCode], {
  6493. type: "application/javascript"
  6494. });
  6495. worker = new Worker(URL.createObjectURL(t)), worker.onmessage = function (r) {
  6496. logger$1.infoAndReportMeasurement({
  6497. metric: "workerRtt",
  6498. group: "http",
  6499. startTime: e,
  6500. value: r.data
  6501. });
  6502. };
  6503. }
  6504. }
  6505. }, {
  6506. key: "pingOthers",
  6507. value: function pingOthers(i, e) {
  6508. var t = !1;
  6509. var r = new Image();
  6510. r.onload = o, r.onerror = a;
  6511. var n = Date.now();
  6512. function o(l) {
  6513. t = !0, s();
  6514. }
  6515. function a(l) {}
  6516. function s() {
  6517. var l = Date.now() - n;
  6518. if (typeof e == "function") return t ? e(null, l) : (console.error("error loading resource"), e("error", l));
  6519. }
  6520. r.src = i + "/favicon.ico?" + +new Date();
  6521. }
  6522. }]);
  6523. return NetworkController;
  6524. }(EventEmitter);
  6525. 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); }; }
  6526. 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; } }
  6527. var InitConfigTimeoutError = /*#__PURE__*/function (_XverseError) {
  6528. _inherits(InitConfigTimeoutError, _XverseError);
  6529. var _super = _createSuper$9(InitConfigTimeoutError);
  6530. function InitConfigTimeoutError(e) {
  6531. _classCallCheck(this, InitConfigTimeoutError);
  6532. return _super.call(this, 1009, e || "\u914D\u7F6E\u521D\u59CB\u5316\u8D85\u65F6");
  6533. }
  6534. return _createClass(InitConfigTimeoutError);
  6535. }(XverseError);
  6536. 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); }; }
  6537. 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; } }
  6538. var InitDecoderTimeoutError = /*#__PURE__*/function (_XverseError) {
  6539. _inherits(InitDecoderTimeoutError, _XverseError);
  6540. var _super = _createSuper$8(InitDecoderTimeoutError);
  6541. function InitDecoderTimeoutError(e) {
  6542. _classCallCheck(this, InitDecoderTimeoutError);
  6543. return _super.call(this, 1008, e || "Decoder \u521D\u59CB\u5316\u8D85\u65F6");
  6544. }
  6545. return _createClass(InitDecoderTimeoutError);
  6546. }(XverseError);
  6547. 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); }; }
  6548. 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; } }
  6549. var InitEngineError = /*#__PURE__*/function (_XverseError) {
  6550. _inherits(InitEngineError, _XverseError);
  6551. var _super = _createSuper$7(InitEngineError);
  6552. function InitEngineError(e) {
  6553. _classCallCheck(this, InitEngineError);
  6554. return _super.call(this, 1011, e || "\u5F15\u64CE\u521D\u59CB\u5316\u9519\u8BEF");
  6555. }
  6556. return _createClass(InitEngineError);
  6557. }(XverseError);
  6558. var AssetTypeName = {
  6559. Config: 'CONFIG',
  6560. Model: 'MODEL',
  6561. Vedio: 'VEDIO',
  6562. Media: 'MEDIA',
  6563. Effects: 'EFFECTS',
  6564. Gift: 'GIFT',
  6565. Textures: 'TEXTURES'
  6566. };
  6567. var AssetClassName = {
  6568. Effects: '\u7279\u6548',
  6569. Tv: 'TV',
  6570. Lpm: '\u7C97\u6A21',
  6571. Reward: '\u571F\u8C6A\u699C',
  6572. Env: '\u73AF\u5883\u5149',
  6573. Gbq: '\u544A\u767D\u5899',
  6574. BreathPoint: '\u547C\u5438\u70B9',
  6575. Gifts: '\u9001\u793C',
  6576. Panorama: '\u5168\u666F\u56FE',
  6577. GiftBubble: '\u9001\u793C\u6C14\u6CE1',
  6578. SayBubble: '\u804A\u5929\u6C14\u6CE1'
  6579. };
  6580. var LoggerLevels$1 = {
  6581. Debug: 1,
  6582. Info: 2,
  6583. Warn: 3,
  6584. Error: 4,
  6585. Off: 5
  6586. };
  6587. var EShaderMode = {
  6588. default: 0,
  6589. video: 1,
  6590. videoAndPano: 2
  6591. };
  6592. var EFitMode = {
  6593. fill: 'fill',
  6594. contain: 'contain',
  6595. cover: 'cover'
  6596. };
  6597. var BaseTable = /*#__PURE__*/function () {
  6598. function BaseTable(e, t) {
  6599. _classCallCheck(this, BaseTable);
  6600. this.db = null;
  6601. this.isCreatingTable = !1;
  6602. this.hasCleared = !1;
  6603. this.dbName = e, this.dbVersion = t;
  6604. }
  6605. _createClass(BaseTable, [{
  6606. key: "clearDataBase",
  6607. value: function () {
  6608. var _clearDataBase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  6609. var _this = this;
  6610. return regenerator.wrap(function _callee$(_context) {
  6611. while (1) {
  6612. switch (_context.prev = _context.next) {
  6613. case 0:
  6614. return _context.abrupt("return", this.hasCleared || (e && (this.hasCleared = !0), !window.indexedDB.databases) ? Promise.resolve() : new Promise(function (t, r) {
  6615. var n = window.indexedDB.deleteDatabase(_this.dbName);
  6616. n.onsuccess = function () {
  6617. t();
  6618. }, n.onerror = r;
  6619. }));
  6620. case 1:
  6621. case "end":
  6622. return _context.stop();
  6623. }
  6624. }
  6625. }, _callee, this);
  6626. }));
  6627. function clearDataBase(_x) {
  6628. return _clearDataBase.apply(this, arguments);
  6629. }
  6630. return clearDataBase;
  6631. }()
  6632. }, {
  6633. key: "tableName",
  6634. value: function tableName() {
  6635. throw new Error("Derived class have to override 'tableName', and set a proper table name!");
  6636. }
  6637. }, {
  6638. key: "keyPath",
  6639. value: function keyPath() {
  6640. throw new Error("Derived class have to override 'keyPath', and set a proper index name!");
  6641. }
  6642. }, {
  6643. key: "index",
  6644. value: function index() {
  6645. throw new Error("Derived class have to override 'index', and set a proper index name!");
  6646. }
  6647. }, {
  6648. key: "checkAndOpenDatabase",
  6649. value: function () {
  6650. var _checkAndOpenDatabase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  6651. var _this2 = this;
  6652. return regenerator.wrap(function _callee2$(_context2) {
  6653. while (1) {
  6654. switch (_context2.prev = _context2.next) {
  6655. case 0:
  6656. return _context2.abrupt("return", this.db ? Promise.resolve(this.db) : new Promise(function (e, t) {
  6657. var n = setTimeout(function () {
  6658. logger$1.info("wait db to open for", 200), _this2.db ? e(_this2.db) : e(_this2.checkAndOpenDatabase()), clearTimeout(n);
  6659. }, 200);
  6660. _this2.openDatabase(_this2.dbName, _this2.dbVersion || 1, function () {
  6661. _this2.db && !_this2.isCreatingTable && e(_this2.db), logger$1.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable)), clearTimeout(n);
  6662. }, function () {
  6663. t(new Error("Failed to open database!")), clearTimeout(n);
  6664. }, function () {
  6665. _this2.db && e(_this2.db), clearTimeout(n), logger$1.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable));
  6666. });
  6667. }));
  6668. case 1:
  6669. case "end":
  6670. return _context2.stop();
  6671. }
  6672. }
  6673. }, _callee2, this);
  6674. }));
  6675. function checkAndOpenDatabase() {
  6676. return _checkAndOpenDatabase.apply(this, arguments);
  6677. }
  6678. return checkAndOpenDatabase;
  6679. }()
  6680. }, {
  6681. key: "openDatabase",
  6682. value: function openDatabase(e, t, r, n, o) {
  6683. var _this3 = this;
  6684. if (this.isCreatingTable) return;
  6685. this.isCreatingTable = !0, logger$1.info(e, t);
  6686. var a = window.indexedDB.open(e, t),
  6687. s = this.tableName();
  6688. a.onsuccess = function (l) {
  6689. _this3.db = a.result, logger$1.info("IndexedDb ".concat(e, " is opened.")), _this3.db.objectStoreNames.contains(s) && (_this3.isCreatingTable = !1), r && r(l);
  6690. }, a.onerror = function (l) {
  6691. var u;
  6692. logger$1.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);
  6693. }, a.onupgradeneeded = function (l) {
  6694. var u = l.target.result,
  6695. c = _this3.index();
  6696. logger$1.info("Creating table ".concat(s, "."));
  6697. var h = u.objectStoreNames.contains(s);
  6698. if (h) h = u.transaction([s], "readwrite").objectStore(s);else {
  6699. var f = _this3.keyPath();
  6700. h = u.createObjectStore(s, {
  6701. keyPath: f
  6702. });
  6703. }
  6704. c.map(function (f) {
  6705. h.createIndex(f, f, {
  6706. unique: !1
  6707. });
  6708. }), _this3.isCreatingTable = !1, logger$1.info("Table ".concat(s, " opened")), o && o(l);
  6709. };
  6710. }
  6711. }, {
  6712. key: "add",
  6713. value: function () {
  6714. var _add = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  6715. var t, o;
  6716. return regenerator.wrap(function _callee3$(_context3) {
  6717. while (1) {
  6718. switch (_context3.prev = _context3.next) {
  6719. case 0:
  6720. t = this.tableName();
  6721. _context3.next = 3;
  6722. return this.checkAndOpenDatabase();
  6723. case 3:
  6724. o = _context3.sent.transaction([t], "readwrite").objectStore(t).add(e);
  6725. return _context3.abrupt("return", new Promise(function (a, s) {
  6726. o.onsuccess = function (l) {
  6727. a(l);
  6728. }, o.onerror = function (l) {
  6729. var u;
  6730. logger$1.error((u = l.srcElement) == null ? void 0 : u.error), s(l);
  6731. };
  6732. }));
  6733. case 5:
  6734. case "end":
  6735. return _context3.stop();
  6736. }
  6737. }
  6738. }, _callee3, this);
  6739. }));
  6740. function add(_x2) {
  6741. return _add.apply(this, arguments);
  6742. }
  6743. return add;
  6744. }()
  6745. }, {
  6746. key: "put",
  6747. value: function () {
  6748. var _put = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  6749. var t, o;
  6750. return regenerator.wrap(function _callee4$(_context4) {
  6751. while (1) {
  6752. switch (_context4.prev = _context4.next) {
  6753. case 0:
  6754. t = this.tableName();
  6755. _context4.next = 3;
  6756. return this.checkAndOpenDatabase();
  6757. case 3:
  6758. o = _context4.sent.transaction([t], "readwrite").objectStore(t).put(e);
  6759. return _context4.abrupt("return", new Promise(function (a, s) {
  6760. o.onsuccess = function (l) {
  6761. a(l);
  6762. }, o.onerror = function (l) {
  6763. var u;
  6764. logger$1.error("db put error", (u = l.srcElement) == null ? void 0 : u.error), s(l);
  6765. };
  6766. }));
  6767. case 5:
  6768. case "end":
  6769. return _context4.stop();
  6770. }
  6771. }
  6772. }, _callee4, this);
  6773. }));
  6774. function put(_x3) {
  6775. return _put.apply(this, arguments);
  6776. }
  6777. return put;
  6778. }()
  6779. }, {
  6780. key: "delete",
  6781. value: function _delete(e, t, r) {
  6782. var n = this.tableName();
  6783. this.checkAndOpenDatabase().then(function (o) {
  6784. var s = o.transaction([n], "readwrite").objectStore(n).delete(e);
  6785. s.onsuccess = t, s.onerror = r;
  6786. });
  6787. }
  6788. }, {
  6789. key: "update",
  6790. value: function update() {
  6791. this.checkAndOpenDatabase().then(function (e) {});
  6792. }
  6793. }, {
  6794. key: "getAllKeys",
  6795. value: function () {
  6796. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  6797. var e, t;
  6798. return regenerator.wrap(function _callee5$(_context5) {
  6799. while (1) {
  6800. switch (_context5.prev = _context5.next) {
  6801. case 0:
  6802. e = this.tableName();
  6803. _context5.next = 3;
  6804. return this.checkAndOpenDatabase();
  6805. case 3:
  6806. t = _context5.sent;
  6807. return _context5.abrupt("return", new Promise(function (r, n) {
  6808. var a = t.transaction([e], "readonly").objectStore(e).getAllKeys();
  6809. a.onsuccess = function (s) {
  6810. r(s.target.result);
  6811. }, a.onerror = function (s) {
  6812. logger$1.error("db getAllKeys error", s), n(s);
  6813. };
  6814. }));
  6815. case 5:
  6816. case "end":
  6817. return _context5.stop();
  6818. }
  6819. }
  6820. }, _callee5, this);
  6821. }));
  6822. function getAllKeys() {
  6823. return _getAllKeys.apply(this, arguments);
  6824. }
  6825. return getAllKeys;
  6826. }()
  6827. }, {
  6828. key: "query",
  6829. value: function () {
  6830. var _query = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t) {
  6831. var r, n;
  6832. return regenerator.wrap(function _callee6$(_context6) {
  6833. while (1) {
  6834. switch (_context6.prev = _context6.next) {
  6835. case 0:
  6836. r = this.tableName();
  6837. _context6.next = 3;
  6838. return this.checkAndOpenDatabase();
  6839. case 3:
  6840. n = _context6.sent;
  6841. return _context6.abrupt("return", new Promise(function (o, a) {
  6842. var u = n.transaction([r], "readonly").objectStore(r).index(e).get(t);
  6843. u.onsuccess = function (c) {
  6844. var f;
  6845. var h = (f = c == null ? void 0 : c.target) == null ? void 0 : f.result;
  6846. o && o(h);
  6847. }, u.onerror = function (c) {
  6848. logger$1.error("db query error", c), a(c);
  6849. };
  6850. }));
  6851. case 5:
  6852. case "end":
  6853. return _context6.stop();
  6854. }
  6855. }
  6856. }, _callee6, this);
  6857. }));
  6858. function query(_x4, _x5) {
  6859. return _query.apply(this, arguments);
  6860. }
  6861. return query;
  6862. }()
  6863. }, {
  6864. key: "sleep",
  6865. value: function () {
  6866. var _sleep = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  6867. return regenerator.wrap(function _callee7$(_context7) {
  6868. while (1) {
  6869. switch (_context7.prev = _context7.next) {
  6870. case 0:
  6871. return _context7.abrupt("return", new Promise(function (t) {
  6872. setTimeout(function () {
  6873. t("");
  6874. }, e);
  6875. }));
  6876. case 1:
  6877. case "end":
  6878. return _context7.stop();
  6879. }
  6880. }
  6881. }, _callee7);
  6882. }));
  6883. function sleep(_x6) {
  6884. return _sleep.apply(this, arguments);
  6885. }
  6886. return sleep;
  6887. }()
  6888. }]);
  6889. return BaseTable;
  6890. }();
  6891. 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); }; }
  6892. 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; } }
  6893. var ModelTable = /*#__PURE__*/function (_BaseTable) {
  6894. _inherits(ModelTable, _BaseTable);
  6895. var _super = _createSuper$6(ModelTable);
  6896. function ModelTable() {
  6897. _classCallCheck(this, ModelTable);
  6898. return _super.call(this, "XverseDatabase", 1);
  6899. }
  6900. _createClass(ModelTable, [{
  6901. key: "tableName",
  6902. value: function tableName() {
  6903. return "models";
  6904. }
  6905. }, {
  6906. key: "index",
  6907. value: function index() {
  6908. return ["url"];
  6909. }
  6910. }, {
  6911. key: "keyPath",
  6912. value: function keyPath() {
  6913. return "url";
  6914. }
  6915. }]);
  6916. return ModelTable;
  6917. }(BaseTable);
  6918. var modelTable = new ModelTable();
  6919. 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); }; }
  6920. 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; } }
  6921. var isIndexedDbSupported = function isIndexedDbSupported() {
  6922. return (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB) !== void 0;
  6923. };
  6924. var dataURItoBlob = function dataURItoBlob(i) {
  6925. var e;
  6926. i.split(",")[0].indexOf("base64") >= 0 ? e = atob(i.split(",")[1]) : e = unescape(i.split(",")[1]);
  6927. var t = i.split(",")[0].split(":")[1].split(";")[0],
  6928. r = new Uint8Array(e.length);
  6929. for (var o = 0; o < e.length; o++) {
  6930. r[o] = e.charCodeAt(o);
  6931. }
  6932. return new Blob([r], {
  6933. type: t
  6934. });
  6935. };
  6936. var Http = /*#__PURE__*/function (_EventEmitter) {
  6937. _inherits(Http, _EventEmitter);
  6938. var _super = _createSuper$5(Http);
  6939. function Http() {
  6940. _classCallCheck(this, Http);
  6941. return _super.apply(this, arguments);
  6942. }
  6943. _createClass(Http, [{
  6944. key: "get",
  6945. value: function () {
  6946. var _get = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(_ref) {
  6947. var e, _ref$useIndexedDb, t, _ref$timeout, r, n, _ref$isOutPutObjectUR, o, a, s, l;
  6948. return regenerator.wrap(function _callee2$(_context2) {
  6949. while (1) {
  6950. switch (_context2.prev = _context2.next) {
  6951. case 0:
  6952. 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;
  6953. if (!(Xverse.NO_CACHE !== void 0 && (t = !Xverse.NO_CACHE), t)) {
  6954. _context2.next = 25;
  6955. break;
  6956. }
  6957. if (!isIndexedDbSupported()) {
  6958. _context2.next = 22;
  6959. break;
  6960. }
  6961. window.performance.now();
  6962. a = null;
  6963. _context2.prev = 5;
  6964. _context2.next = 8;
  6965. return modelTable.query("url", e);
  6966. case 8:
  6967. a = _context2.sent;
  6968. _context2.next = 14;
  6969. break;
  6970. case 11:
  6971. _context2.prev = 11;
  6972. _context2.t0 = _context2["catch"](5);
  6973. return _context2.abrupt("return", (logger$1.debug(_context2.t0), logger$1.warn("cache query error", e), Promise.resolve(e)));
  6974. case 14:
  6975. if (!(a && a.model)) {
  6976. _context2.next = 19;
  6977. break;
  6978. }
  6979. s = dataURItoBlob(a.model), l = Promise.resolve(o ? URL.createObjectURL(s) : s);
  6980. return _context2.abrupt("return", (window.performance.now(), l));
  6981. case 19:
  6982. return _context2.abrupt("return", this.request({
  6983. url: e,
  6984. timeout: r,
  6985. contentType: "blob",
  6986. key: n
  6987. }).then( /*#__PURE__*/function () {
  6988. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(s) {
  6989. var l;
  6990. return regenerator.wrap(function _callee$(_context) {
  6991. while (1) {
  6992. switch (_context.prev = _context.next) {
  6993. case 0:
  6994. _context.next = 2;
  6995. return blobToDataURI(s.response);
  6996. case 2:
  6997. l = _context.sent;
  6998. _context.prev = 3;
  6999. _context.next = 6;
  7000. return modelTable.put({
  7001. url: e,
  7002. model: l
  7003. });
  7004. case 6:
  7005. _context.next = 11;
  7006. break;
  7007. case 8:
  7008. _context.prev = 8;
  7009. _context.t0 = _context["catch"](3);
  7010. logger$1.warn("unable to add data to indexedDB", _context.t0);
  7011. case 11:
  7012. return _context.abrupt("return", Promise.resolve(o ? URL.createObjectURL(s.response) : s.response));
  7013. case 12:
  7014. case "end":
  7015. return _context.stop();
  7016. }
  7017. }
  7018. }, _callee, null, [[3, 8]]);
  7019. }));
  7020. return function (_x2) {
  7021. return _ref2.apply(this, arguments);
  7022. };
  7023. }()));
  7024. case 20:
  7025. _context2.next = 23;
  7026. break;
  7027. case 22:
  7028. return _context2.abrupt("return", this.request({
  7029. url: e,
  7030. timeout: r,
  7031. contentType: "blob",
  7032. key: n
  7033. }).then(function (a) {
  7034. var s = a.response;
  7035. return Promise.resolve(o ? URL.createObjectURL(s) : s);
  7036. }).catch(function (a) {
  7037. return Promise.reject(a);
  7038. }));
  7039. case 23:
  7040. _context2.next = 26;
  7041. break;
  7042. case 25:
  7043. return _context2.abrupt("return", this.request({
  7044. url: e,
  7045. timeout: r,
  7046. key: n
  7047. }).then(function (a) {
  7048. return a.getResponseHeader("content-type") === "application/json" ? Promise.resolve(JSON.parse(a.responseText)) : Promise.resolve(a.responseText);
  7049. }));
  7050. case 26:
  7051. case "end":
  7052. return _context2.stop();
  7053. }
  7054. }
  7055. }, _callee2, this, [[5, 11]]);
  7056. }));
  7057. function get(_x) {
  7058. return _get.apply(this, arguments);
  7059. }
  7060. return get;
  7061. }()
  7062. }, {
  7063. key: "request",
  7064. value: function request(e) {
  7065. var _this = this;
  7066. var _e$timeout = e.timeout,
  7067. t = _e$timeout === void 0 ? 3e4 : _e$timeout,
  7068. r = e.contentType;
  7069. e.key;
  7070. var o = e.onRequestStart,
  7071. a = e.url;
  7072. return new Promise(function (s, l) {
  7073. window.performance.now();
  7074. var u = new XMLHttpRequest();
  7075. r && (u.responseType = r), u.timeout = t, u.addEventListener("readystatechange", function () {
  7076. if (u.readyState == 4) {
  7077. if (u.status == 200) return window.performance.now(), _this.emit("loadend", {
  7078. message: "request ".concat(a, " load success")
  7079. }), s(u);
  7080. {
  7081. var c = "Unable to load the request ".concat(a);
  7082. return _this.emit("error", {
  7083. message: c
  7084. }), logger$1.error(c), l(c);
  7085. }
  7086. }
  7087. }), o && o(u), u.open("GET", a), u.send();
  7088. });
  7089. }
  7090. }]);
  7091. return Http;
  7092. }(EventEmitter); // const http = new Http();
  7093. var Logger1 = /*#__PURE__*/function () {
  7094. function Logger1(e) {
  7095. _classCallCheck(this, Logger1);
  7096. E(this, "module");
  7097. this.module = e;
  7098. }
  7099. _createClass(Logger1, [{
  7100. key: "debug",
  7101. value: function debug() {
  7102. var _Logger1$instance;
  7103. return (_Logger1$instance = Logger1.instance).debug.apply(_Logger1$instance, arguments);
  7104. }
  7105. }, {
  7106. key: "info",
  7107. value: function info() {
  7108. var _Logger1$instance2;
  7109. return (_Logger1$instance2 = Logger1.instance).info.apply(_Logger1$instance2, arguments);
  7110. }
  7111. }, {
  7112. key: "warn",
  7113. value: function warn() {
  7114. var _Logger1$instance3;
  7115. return (_Logger1$instance3 = Logger1.instance).warn.apply(_Logger1$instance3, arguments);
  7116. }
  7117. }, {
  7118. key: "error",
  7119. value: function error() {
  7120. var _Logger1$instance4;
  7121. return (_Logger1$instance4 = Logger1.instance).error.apply(_Logger1$instance4, arguments);
  7122. }
  7123. }], [{
  7124. key: "setLogger",
  7125. value: function setLogger(e) {
  7126. Logger1.instance = e;
  7127. }
  7128. }]);
  7129. return Logger1;
  7130. }();
  7131. var XCameraComponent = /*#__PURE__*/function () {
  7132. function XCameraComponent(e, t, r) {
  7133. var _this = this;
  7134. _classCallCheck(this, XCameraComponent);
  7135. E(this, "maincameraRotLimitObserver", null);
  7136. E(this, "mainCamera");
  7137. E(this, "cgCamera");
  7138. E(this, "saveCameraPose");
  7139. E(this, "_cameraPose");
  7140. E(this, "scene");
  7141. E(this, "canvas");
  7142. E(this, "yuvInfo");
  7143. E(this, "forceKeepVertical", !1);
  7144. E(this, "initCamera", function (e) {
  7145. var _e$maxZ = e.maxZ,
  7146. t = _e$maxZ === void 0 ? 1e4 : _e$maxZ,
  7147. _e$minZ = e.minZ,
  7148. r = _e$minZ === void 0 ? .1 : _e$minZ,
  7149. _e$angularSensibility = e.angularSensibility,
  7150. n = _e$angularSensibility === void 0 ? 2e3 : _e$angularSensibility;
  7151. _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);
  7152. });
  7153. E(this, "cameraFovChange", function (e) {
  7154. _this.yuvInfo = e;
  7155. var t = e.width,
  7156. r = e.height,
  7157. n = _this.canvas.width,
  7158. o = _this.canvas.height,
  7159. a = e.fov;
  7160. if (_this.forceKeepVertical == !0) {
  7161. var s = t / (2 * Math.tan(Math.PI * a / 360)),
  7162. l = 2 * Math.atan(r / (2 * s));
  7163. _this.mainCamera.fov = l, _this.cgCamera.fov = l, _this.mainCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED, _this.cgCamera.fovMode = BABYLON.Camera.FOVMODE_VERTICAL_FIXED;
  7164. } 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) {
  7165. var _s = o,
  7166. _l = n,
  7167. u = _s * t / r / (2 * Math.tan(a * Math.PI / 360)),
  7168. c = 2 * Math.atan(_l / (2 * u));
  7169. _this.mainCamera.fov = c, _this.cgCamera.fov = c;
  7170. } else _this.mainCamera.fov = Math.PI * a / 180, _this.cgCamera.fov = Math.PI * a / 180;
  7171. });
  7172. E(this, "setCameraPose", function (e) {
  7173. var n;
  7174. var t = ue4Position2Xverse(e.position);
  7175. var r = null;
  7176. e.rotation != null && (r = ue4Rotation2Xverse(e.rotation)), _this._cameraPose = {
  7177. position: t
  7178. }, r != null && (_this._cameraPose.rotation = r), _this.scene.activeCamera === _this.mainCamera && !((n = _this.mainCamera) != null && n.isDisposed()) && _this._setCamPositionRotation(_this.mainCamera, _this._cameraPose);
  7179. });
  7180. E(this, "_setCamPositionRotation", function (e, t) {
  7181. var r, n;
  7182. t.position && (e.position = (r = t.position) == null ? void 0 : r.clone()), t.rotation && (e.rotation = (n = t.rotation) == null ? void 0 : n.clone());
  7183. });
  7184. E(this, "switchCamera", function (e) {
  7185. var t;
  7186. (t = _this.scene.activeCamera) == null || t.detachControl(_this.canvas), _this.scene.activeCamera = e;
  7187. });
  7188. E(this, "reCalXYZRot", function (e, t) {
  7189. return e = e % (2 * Math.PI), Math.abs(t - e) >= Math.PI && (e = e - 2 * Math.PI), e;
  7190. });
  7191. E(this, "_moveCam", function (e, t, r, n, o, a, s, l) {
  7192. var u = function u(v, y, b) {
  7193. 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);
  7194. },
  7195. c = function c(v, y, b) {
  7196. 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);
  7197. },
  7198. h = new Animation("myAnimation1", "position", s, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);
  7199. var f = [],
  7200. d = t,
  7201. _ = r;
  7202. for (var v = 0; v < a; ++v) {
  7203. f.push({
  7204. frame: v,
  7205. value: c(d, _, v / a)
  7206. });
  7207. }
  7208. f.push({
  7209. frame: f.length,
  7210. value: c(d, _, 1)
  7211. }), h.setKeys(f);
  7212. var g = new Animation("myAnimation2", "rotation", s, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);
  7213. f = [], d = n, _ = o;
  7214. for (var _v = 0; _v < a; ++_v) {
  7215. f.push({
  7216. frame: _v,
  7217. value: u(d, _, _v / a)
  7218. });
  7219. }
  7220. f.push({
  7221. frame: f.length,
  7222. value: u(d, _, 1)
  7223. }), g.setKeys(f), e.animations.push(g), e.animations.push(h);
  7224. var m = _this.scene.beginAnimation(e, 0, a, !1);
  7225. m.onAnimationEnd = function () {
  7226. l(), m.stop(), m.animationStarted = !1;
  7227. };
  7228. });
  7229. this.scene = t, this.canvas = e, this.yuvInfo = r.yuvInfo, r.forceKeepVertical != null && (this.forceKeepVertical = r.forceKeepVertical), this.initCamera(r.cameraParam);
  7230. }
  7231. _createClass(XCameraComponent, [{
  7232. key: "MainCamera",
  7233. get: function get() {
  7234. return this.mainCamera;
  7235. }
  7236. }, {
  7237. key: "CgCamera",
  7238. get: function get() {
  7239. return this.cgCamera;
  7240. }
  7241. }, {
  7242. key: "getCameraHorizonFov",
  7243. value: function getCameraHorizonFov() {
  7244. return this.mainCamera.fovMode == BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED ? this.mainCamera.fov : Math.PI * this.yuvInfo.fov / 180;
  7245. }
  7246. }, {
  7247. key: "changeMainCameraRotationDamping",
  7248. value: function changeMainCameraRotationDamping() {
  7249. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2e3;
  7250. this.mainCamera.angularSensibility = e;
  7251. }
  7252. }, {
  7253. key: "removeMainCameraRotationLimit",
  7254. value: function removeMainCameraRotationLimit() {
  7255. this.maincameraRotLimitObserver != null && this.mainCamera.onAfterCheckInputsObservable.remove(this.maincameraRotLimitObserver);
  7256. }
  7257. }, {
  7258. key: "setMainCameraInfo",
  7259. value: function setMainCameraInfo(e) {
  7260. var _e$maxZ2 = e.maxZ,
  7261. t = _e$maxZ2 === void 0 ? 1e4 : _e$maxZ2,
  7262. _e$minZ2 = e.minZ,
  7263. r = _e$minZ2 === void 0 ? .1 : _e$minZ2,
  7264. _e$angularSensibility2 = e.angularSensibility,
  7265. n = _e$angularSensibility2 === void 0 ? 2e3 : _e$angularSensibility2;
  7266. this.mainCamera.maxZ = t, this.mainCamera.minZ = r, this.mainCamera.angularSensibility = n;
  7267. }
  7268. }, {
  7269. key: "getMainCameraInfo",
  7270. value: function getMainCameraInfo() {
  7271. return {
  7272. maxZ: this.mainCamera.maxZ,
  7273. minZ: this.mainCamera.minZ,
  7274. angularSensibility: this.mainCamera.angularSensibility
  7275. };
  7276. }
  7277. }, {
  7278. key: "_limitAngle",
  7279. value: function _limitAngle(e, t) {
  7280. 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;
  7281. }
  7282. }, {
  7283. key: "setMainCameraRotationLimit",
  7284. value: function setMainCameraRotationLimit(e, t) {
  7285. var _this2 = this;
  7286. this.maincameraRotLimitObserver != null && this.removeMainCameraRotationLimit();
  7287. var r = this.mainCamera,
  7288. n = e.yaw,
  7289. o = e.pitch,
  7290. a = e.roll,
  7291. s = t.yaw,
  7292. l = t.pitch,
  7293. u = t.roll;
  7294. if (s < 0 || l < 0 || u < 0) throw new Error("\u76F8\u673A\u65CB\u8F6C\u9650\u5236\u53EA\u80FD\u8BBE\u7F6E\u4E3A\u5927\u4E8E0");
  7295. var c = [o - l, o + l],
  7296. h = [n - s, n + s],
  7297. f = [a - u, a + u];
  7298. this.maincameraRotLimitObserver = r.onAfterCheckInputsObservable.add(function () {
  7299. var _xverseRotation2Ue = xverseRotation2Ue4(r.rotation),
  7300. d = _xverseRotation2Ue.pitch,
  7301. _ = _xverseRotation2Ue.yaw,
  7302. g = _xverseRotation2Ue.roll;
  7303. d = _this2._limitAngle(d, c), _ = _this2._limitAngle(_, h), g = _this2._limitAngle(g, f), r.rotation = ue4Rotation2Xverse({
  7304. pitch: d,
  7305. yaw: _,
  7306. roll: g
  7307. });
  7308. });
  7309. }
  7310. }, {
  7311. key: "setMainCameraRotationLimitByAnchor",
  7312. value: function setMainCameraRotationLimitByAnchor(e, t, r) {
  7313. this.maincameraRotLimitObserver != null && this.removeMainCameraRotationLimit();
  7314. var n = this.mainCamera,
  7315. o = ue4Rotation2Xverse_mesh(t),
  7316. a = ue4Rotation2Xverse_mesh(r);
  7317. a != null && o != null && e.mesh != null && (this.maincameraRotLimitObserver = n.onAfterCheckInputsObservable.add(function () {
  7318. var s = e.mesh.rotation;
  7319. 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));
  7320. }));
  7321. }
  7322. }, {
  7323. key: "getCameraPose",
  7324. value: function getCameraPose() {
  7325. var e = xversePosition2Ue4({
  7326. x: this.mainCamera.position.x,
  7327. y: this.mainCamera.position.y,
  7328. z: this.mainCamera.position.z
  7329. }),
  7330. t = xverseRotation2Ue4({
  7331. x: this.mainCamera.rotation.x,
  7332. y: this.mainCamera.rotation.y,
  7333. z: this.mainCamera.rotation.z
  7334. });
  7335. return {
  7336. position: e,
  7337. rotation: t
  7338. };
  7339. }
  7340. }, {
  7341. key: "changeCameraFov",
  7342. value: function changeCameraFov(e, t) {
  7343. this.mainCamera.fov = e, t != null && (this.mainCamera.fovMode = t == 0 ? BABYLON.Camera.FOVMODE_HORIZONTAL_FIXED : BABYLON.Camera.FOVMODE_VERTICAL_FIXED);
  7344. }
  7345. }, {
  7346. key: "controlCameraRotation",
  7347. value: function controlCameraRotation(e, t) {
  7348. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : .5;
  7349. var n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : .5;
  7350. var o = {
  7351. pitch: n * t * 180,
  7352. yaw: r * e * 180,
  7353. roll: 0
  7354. };
  7355. this.addRot(o);
  7356. }
  7357. }, {
  7358. key: "addRot",
  7359. value: function addRot(e) {
  7360. var t = this.mainCamera,
  7361. r = ue4Rotation2Xverse_mesh(e);
  7362. r != null && t.rotation.addInPlace(r);
  7363. }
  7364. }, {
  7365. key: "getCameraFov",
  7366. value: function getCameraFov() {
  7367. return this.mainCamera.fov;
  7368. }
  7369. }, {
  7370. key: "allowMainCameraController",
  7371. value: function allowMainCameraController() {
  7372. this.mainCamera.attachControl(this.canvas, !0);
  7373. }
  7374. }, {
  7375. key: "detachMainCameraController",
  7376. value: function detachMainCameraController() {
  7377. this.mainCamera.detachControl(this.canvas);
  7378. }
  7379. }, {
  7380. key: "forceChangeSavedCameraPose",
  7381. value: function forceChangeSavedCameraPose(e) {
  7382. this.saveCameraPose != null && (e.position != null && (this.saveCameraPose.position = ue4Position2Xverse(e.position)), e.rotation != null && (this.saveCameraPose.rotation = ue4Rotation2Xverse(e.rotation)));
  7383. }
  7384. }, {
  7385. key: "changeToFirstPersonView",
  7386. value: function changeToFirstPersonView(e) {
  7387. this.saveCameraPose = {
  7388. position: this.mainCamera.position.clone(),
  7389. rotation: this.mainCamera.rotation.clone()
  7390. }, this.mainCamera.attachControl(this.canvas, !0), e.position != null && (this.mainCamera.position = ue4Position2Xverse(e.position)), e.rotation != null && (this.mainCamera.rotation = ue4Rotation2Xverse(e.rotation));
  7391. }
  7392. }, {
  7393. key: "changeToThirdPersonView",
  7394. value: function changeToThirdPersonView() {
  7395. 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));
  7396. }
  7397. }, {
  7398. key: "switchToMainCamera",
  7399. value: function switchToMainCamera() {
  7400. this.switchCamera(this.mainCamera);
  7401. }
  7402. }, {
  7403. key: "switchToCgCamera",
  7404. value: function switchToCgCamera() {
  7405. this.switchCamera(this.cgCamera);
  7406. }
  7407. }, {
  7408. key: "moveMainCamera",
  7409. value: function moveMainCamera(e, t, r, n, o) {
  7410. this._moveCam(this.mainCamera, this.mainCamera.position, e, this.mainCamera.rotation, t, r, n, o);
  7411. }
  7412. }]);
  7413. return XCameraComponent;
  7414. }();
  7415. var EMeshType = {
  7416. XAvatar: 'XAvatar',
  7417. XStaticMesh: 'XStaticMesh',
  7418. XBreathPoint: 'breathpoint',
  7419. Decal: 'decal',
  7420. Cgplane: 'cgplane',
  7421. Tv: 'tv',
  7422. XSubSequence: 'XSubSequence',
  7423. XBillboard: 'XBillboard'
  7424. };
  7425. var XStaticMesh = /*#__PURE__*/function () {
  7426. function XStaticMesh(_ref) {
  7427. var _this = this;
  7428. var e = _ref.id,
  7429. t = _ref.mesh,
  7430. _ref$group = _ref.group,
  7431. r = _ref$group === void 0 ? "default" : _ref$group,
  7432. _ref$lod = _ref.lod,
  7433. n = _ref$lod === void 0 ? 0 : _ref$lod,
  7434. _ref$xtype = _ref.xtype,
  7435. o = _ref$xtype === void 0 ? EMeshType.XStaticMesh : _ref$xtype,
  7436. _ref$skinInfo = _ref.skinInfo,
  7437. a = _ref$skinInfo === void 0 ? "default" : _ref$skinInfo,
  7438. _ref$url = _ref.url,
  7439. s = _ref$url === void 0 ? "" : _ref$url;
  7440. _classCallCheck(this, XStaticMesh);
  7441. E(this, "_mesh");
  7442. E(this, "_id", "-1");
  7443. E(this, "_group");
  7444. E(this, "_lod");
  7445. E(this, "_isMoving", !1);
  7446. E(this, "_isRotating", !1);
  7447. E(this, "_isVisible", !0);
  7448. E(this, "_skinInfo");
  7449. E(this, "setVisibility", function (e, t) {
  7450. Array.isArray(e) ? e.forEach(function (r) {
  7451. _this.setVisibility(r, t);
  7452. }) : e.isAnInstance || (e.visibility = t);
  7453. });
  7454. E(this, "setPickable", function (e, t) {
  7455. Array.isArray(e) ? e.forEach(function (r) {
  7456. _this.setPickable(r, t);
  7457. }) : ("isPickable" in e && (e.isPickable = t), e.setEnabled(t));
  7458. });
  7459. E(this, "hide", function () {
  7460. var e;
  7461. _this._isVisible = !1, _this.mesh && _this.setVisibility(_this.mesh, 0), _this.mesh && _this.setPickable(_this.mesh, !1), (e = _this.mesh) == null || e.getChildMeshes().forEach(function (t) {
  7462. _this.setVisibility(t, 0), _this.setPickable(t, !1);
  7463. });
  7464. });
  7465. E(this, "show", function () {
  7466. var e;
  7467. _this._isVisible = !0, _this.mesh && _this.setVisibility(_this.mesh, 1), _this.mesh && _this.setPickable(_this.mesh, !0), (e = _this.mesh) == null || e.getChildMeshes().forEach(function (t) {
  7468. _this.setVisibility(t, 1), _this.setPickable(t, !0);
  7469. });
  7470. });
  7471. E(this, "attachToAvatar", function (e) {
  7472. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  7473. x: 0,
  7474. y: .5,
  7475. z: 0
  7476. };
  7477. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
  7478. yaw: 0,
  7479. pitch: 0,
  7480. roll: 0
  7481. };
  7482. var n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
  7483. x: .35,
  7484. y: .35,
  7485. z: .35
  7486. };
  7487. var o = ue4Scaling2Xverse(n),
  7488. a = ue4Rotation2Xverse(r),
  7489. s = ue4Position2Xverse(t),
  7490. l = _this._mesh;
  7491. e && l ? (e.setParent(l), e.position = s, e.rotation = a, e.scaling = o) : logger$1.error("[Engine] avatar or attachment not found!");
  7492. });
  7493. E(this, "detachFromAvatar", function (e) {
  7494. _this._mesh && e ? _this._mesh.removeChild(e) : logger$1.error("[Engine] avatar not found!");
  7495. });
  7496. this._id = e, this._mesh = t, this._group = r, this._lod = n, this._skinInfo = a, this.unallowMove(), this._mesh.xtype = o, this._mesh.xid = e, this._mesh.xgroup = this._group, this._mesh.xlod = this._lod, this._mesh.xskinInfo = this._skinInfo, this._mesh.xurl = s;
  7497. }
  7498. _createClass(XStaticMesh, [{
  7499. key: "mesh",
  7500. get: function get() {
  7501. return this._mesh;
  7502. }
  7503. }, {
  7504. key: "position",
  7505. get: function get() {
  7506. var o;
  7507. if (!this._mesh) return null;
  7508. var _ref2 = (o = this._mesh) == null ? void 0 : o.position,
  7509. e = _ref2.x,
  7510. t = _ref2.y,
  7511. r = _ref2.z;
  7512. return xversePosition2Ue4({
  7513. x: e,
  7514. y: t,
  7515. z: r
  7516. });
  7517. }
  7518. }, {
  7519. key: "id",
  7520. get: function get() {
  7521. return this._id;
  7522. }
  7523. }, {
  7524. key: "group",
  7525. get: function get() {
  7526. return this._group;
  7527. }
  7528. }, {
  7529. key: "isMoving",
  7530. get: function get() {
  7531. return this._isMoving;
  7532. }
  7533. }, {
  7534. key: "isVisible",
  7535. get: function get() {
  7536. return this._isVisible;
  7537. }
  7538. }, {
  7539. key: "isRotating",
  7540. get: function get() {
  7541. return this._isRotating;
  7542. }
  7543. }, {
  7544. key: "skinInfo",
  7545. get: function get() {
  7546. return this._skinInfo;
  7547. }
  7548. }, {
  7549. key: "allowMove",
  7550. value: function allowMove() {
  7551. this._mesh != null && (this._mesh.getChildMeshes().forEach(function (e) {
  7552. e.unfreezeWorldMatrix();
  7553. }), this._mesh.unfreezeWorldMatrix());
  7554. }
  7555. }, {
  7556. key: "unallowMove",
  7557. value: function unallowMove() {
  7558. this._mesh != null && (this._mesh.getChildMeshes().forEach(function (e) {
  7559. e.freezeWorldMatrix();
  7560. }), this._mesh.freezeWorldMatrix());
  7561. }
  7562. }, {
  7563. key: "getID",
  7564. value: function getID() {
  7565. return this._id;
  7566. }
  7567. }, {
  7568. key: "setPosition",
  7569. value: function setPosition(e) {
  7570. if (this._mesh) {
  7571. var t = ue4Position2Xverse(e);
  7572. this._mesh.position = t;
  7573. } else logger$1.error("[Engine] no root for positioning");
  7574. }
  7575. }, {
  7576. key: "setRotation",
  7577. value: function setRotation(e) {
  7578. var t = ue4Rotation2Xverse_mesh(e);
  7579. this._mesh ? this._mesh.rotation = t : logger$1.error("[Engine] no root for rotating");
  7580. }
  7581. }, {
  7582. key: "setScale",
  7583. value: function setScale(e) {
  7584. this._mesh ? this._mesh.scaling = new BABYLON.Vector3(e, e, -e) : logger$1.error("[Engine] no root for scaling");
  7585. }
  7586. }, {
  7587. key: "disableAvatar",
  7588. value: function disableAvatar() {
  7589. var e;
  7590. (e = this._mesh) == null || e.setEnabled(!1);
  7591. }
  7592. }, {
  7593. key: "enableAvatar",
  7594. value: function enableAvatar() {
  7595. var e;
  7596. (e = this._mesh) == null || e.setEnabled(!0);
  7597. }
  7598. }, {
  7599. key: "togglePickable",
  7600. value: function togglePickable(e) {
  7601. var t;
  7602. (t = this.mesh) == null || t.getChildMeshes().forEach(function (r) {
  7603. "instances" in r && "isPickable" in r && (r.isPickable = e);
  7604. }), this.mesh != null && "isPickable" in this.mesh && (this.mesh.isPickable = e);
  7605. }
  7606. }, {
  7607. key: "setMaterial",
  7608. value: function setMaterial(e) {
  7609. var t;
  7610. (t = this.mesh) == null || t.getChildMeshes().forEach(function (r) {
  7611. "instances" in r && "material" in r && (r.material = e);
  7612. }), this.mesh != null && "material" in this.mesh && (this.mesh.material = e);
  7613. }
  7614. }, {
  7615. key: "dispose",
  7616. value: function dispose() {
  7617. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !1;
  7618. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
  7619. !this.mesh.isDisposed() && this.mesh.dispose(e, t);
  7620. }
  7621. }]);
  7622. return XStaticMesh;
  7623. }();
  7624. 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); }; }
  7625. 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; } }
  7626. var XLowpolyModelError = /*#__PURE__*/function (_XverseError) {
  7627. _inherits(XLowpolyModelError, _XverseError);
  7628. var _super = _createSuper$4(XLowpolyModelError);
  7629. function XLowpolyModelError(e) {
  7630. _classCallCheck(this, XLowpolyModelError);
  7631. return _super.call(this, 5204, e || "[Engine] \u4F20\u5165\u6A21\u578Burl\u9519\u8BEF");
  7632. }
  7633. return _createClass(XLowpolyModelError);
  7634. }(XverseError);
  7635. var XStaticMeshFromOneGltf = /*#__PURE__*/function () {
  7636. function XStaticMeshFromOneGltf(e, t) {
  7637. var _this = this;
  7638. _classCallCheck(this, XStaticMeshFromOneGltf);
  7639. E(this, "_scene");
  7640. E(this, "_url");
  7641. E(this, "_group");
  7642. E(this, "_pickable");
  7643. E(this, "_meshes");
  7644. E(this, "_id");
  7645. E(this, "_lod");
  7646. E(this, "_groupUuid");
  7647. E(this, "_isInScene");
  7648. E(this, "_skinInfo");
  7649. E(this, "loadMesh", function (e, t) {
  7650. var r = _this._meshes.length,
  7651. n = t ? 1 : 0,
  7652. o = _this._url;
  7653. return BABYLON.SceneLoader.LoadAssetContainerAsync("", o, _this._scene, function () {
  7654. _this._scene.blockMaterialDirtyMechanism = !0;
  7655. }, ".glb").then(function (a) {
  7656. for (var s = a.materials.length - 1; s >= 0; --s) {
  7657. a.materials[s].dispose();
  7658. }
  7659. _this._scene.blockMaterialDirtyMechanism = !0;
  7660. for (var _s = 0; _s < a.meshes.length; ++_s) {
  7661. var l = a.meshes[_s];
  7662. if ("instances" in l) {
  7663. "visibility" in l && (l.visibility = 0), "isPickable" in l && (l.isPickable = _this._pickable), e != null && (l.material = e), "hasVertexAlpha" in l && (l.hasVertexAlpha = !1);
  7664. var u = new XStaticMesh({
  7665. id: _this._groupUuid + "-" + Math.random().toString(36).substr(2, 5),
  7666. mesh: l,
  7667. lod: _this._lod,
  7668. group: _this._group,
  7669. url: _this._url,
  7670. xtype: EMeshType.XStaticMesh,
  7671. skinInfo: _this._skinInfo
  7672. });
  7673. _this._meshes.push(u);
  7674. }
  7675. _this._scene.addMesh(l);
  7676. }
  7677. return !0;
  7678. }).then(function () {
  7679. _this._isInScene = !0;
  7680. for (var a = r; a < _this._meshes.length; ++a) {
  7681. _this._meshes[a].mesh.visibility = n;
  7682. }
  7683. return Promise.resolve(!0);
  7684. }).catch(function (a) {
  7685. logger$1.error("[Engine] input gltf mesh uri error! " + a), Promise.reject(new XLowpolyModelError("[Engine] input gltf mesh uri error! " + a));
  7686. });
  7687. });
  7688. this._meshes = [], this._scene = e, this._url = t.url, t.group != null ? this._group = t.group : this._group = "default", t.pick != null ? this._pickable = t.pick : this._pickable = !1, t.id != null ? this._id = t.id : this._id = "default", t.lod != null ? this._lod = t.lod : this._lod = -1, t.skinInfo != null ? this._skinInfo = t.skinInfo : this._skinInfo = "default", this._groupUuid = util.uuid(), this._isInScene = !1;
  7689. }
  7690. _createClass(XStaticMeshFromOneGltf, [{
  7691. key: "isinscene",
  7692. get: function get() {
  7693. return this._isInScene;
  7694. }
  7695. }, {
  7696. key: "groupUuid",
  7697. get: function get() {
  7698. return this._groupUuid;
  7699. }
  7700. }, {
  7701. key: "skinInfo",
  7702. get: function get() {
  7703. return this._skinInfo;
  7704. }
  7705. }, {
  7706. key: "group",
  7707. get: function get() {
  7708. return this._group;
  7709. }
  7710. }, {
  7711. key: "meshes",
  7712. get: function get() {
  7713. return this._meshes;
  7714. }
  7715. }, {
  7716. key: "url",
  7717. get: function get() {
  7718. return this._url;
  7719. }
  7720. }, {
  7721. key: "id",
  7722. get: function get() {
  7723. return this._id;
  7724. }
  7725. }, {
  7726. key: "lod",
  7727. get: function get() {
  7728. return this._lod;
  7729. }
  7730. }, {
  7731. key: "removeFromScene",
  7732. value: function removeFromScene() {
  7733. if (this._isInScene) {
  7734. this._isInScene = !1;
  7735. for (var e = 0, t = this._meshes.length; e < t; ++e) {
  7736. this._meshes[e].mesh != null && this._scene.removeMesh(this._meshes[e].mesh);
  7737. }
  7738. }
  7739. }
  7740. }, {
  7741. key: "addToScene",
  7742. value: function addToScene() {
  7743. if (this._isInScene == !1) {
  7744. this._isInScene = !0;
  7745. for (var e = 0, t = this._meshes.length; e < t; ++e) {
  7746. this._meshes[e].mesh != null && this._scene.addMesh(this._meshes[e].mesh);
  7747. }
  7748. }
  7749. }
  7750. }, {
  7751. key: "toggleVisibility",
  7752. value: function toggleVisibility(e) {
  7753. var t = e ? 1 : 0;
  7754. for (var r = 0, n = this._meshes.length; r < n; ++r) {
  7755. "visibility" in this._meshes[r].mesh && (this._meshes[r].mesh.visibility = t);
  7756. }
  7757. }
  7758. }, {
  7759. key: "togglePickable",
  7760. value: function togglePickable(e) {
  7761. for (var t = 0, r = this._meshes.length; t < r; ++t) {
  7762. "isPickable" in this._meshes[t].mesh && (this._meshes[t].mesh.isPickable = e);
  7763. }
  7764. }
  7765. }, {
  7766. key: "setMaterial",
  7767. value: function setMaterial(e) {
  7768. for (var t = 0, r = this._meshes.length; t < r; ++t) {
  7769. "material" in this._meshes[t].mesh && (this._meshes[t].mesh.material = e);
  7770. }
  7771. }
  7772. }, {
  7773. key: "dispose",
  7774. value: function dispose() {
  7775. for (var e = 0, t = this._meshes.length; e < t; ++e) {
  7776. this._meshes[e].mesh.dispose(!1, !1);
  7777. }
  7778. }
  7779. }]);
  7780. return XStaticMeshFromOneGltf;
  7781. }();
  7782. var XStaticMeshComponent = /*#__PURE__*/function () {
  7783. function XStaticMeshComponent(e) {
  7784. var _this = this;
  7785. _classCallCheck(this, XStaticMeshComponent);
  7786. E(this, "scene");
  7787. E(this, "_staticmeshes");
  7788. E(this, "_lowModel_group");
  7789. E(this, "_CgPlane");
  7790. E(this, "_rootDir");
  7791. E(this, "_abosoluteUrl");
  7792. E(this, "_partMeshSkinInfo");
  7793. E(this, "_meshInfoJson");
  7794. E(this, "_orijson");
  7795. E(this, "_notUsedRegionLists");
  7796. E(this, "_meshInfoKeys");
  7797. E(this, "_currentUpdateRegionCount");
  7798. E(this, "_currentMeshUsedLod");
  7799. E(this, "_currentPartGroup");
  7800. E(this, "_allowRegionUpdate");
  7801. E(this, "_allowRegionForceLod");
  7802. E(this, "_forceLod");
  7803. E(this, "_scenemanager");
  7804. E(this, "regionIdInCamera");
  7805. E(this, "regionIdInCameraConst");
  7806. E(this, "_cameraInRegionId");
  7807. E(this, "_meshVis");
  7808. E(this, "_doMeshVisChangeNumber");
  7809. E(this, "_meshVisTypeName");
  7810. E(this, "_visCheckDurationFrameNumber");
  7811. E(this, "_regionLodRule");
  7812. E(this, "reg_staticmesh_partupdate", function () {
  7813. if (_this._allowRegionUpdate && (_this.scene.getFrameId(), _this._meshUpdateFrame()), _this._allowRegionForceLod) {
  7814. _this.scene.getFrameId() % 2 == 0 && _this.setOneRegionLod(_this._meshInfoKeys[_this._currentUpdateRegionCount % _this._meshInfoKeys.length].toString(), _this._forceLod);
  7815. var t = !0;
  7816. var r = Array.from(_this._currentMeshUsedLod.keys());
  7817. if (r.length > 0) {
  7818. for (var n = 0; n < r.length; ++n) {
  7819. _this._currentMeshUsedLod.get(r[n]) != _this._forceLod && (t = !1);
  7820. }
  7821. t && (_this._allowRegionForceLod = !1);
  7822. }
  7823. }
  7824. });
  7825. E(this, "setMeshInfo", function (e) {
  7826. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
  7827. _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 () {
  7828. _this.startMeshUpdate();
  7829. }));
  7830. });
  7831. E(this, "_meshUpdateFrame", function () {
  7832. {
  7833. var _e = _this._meshInfoKeys[_this._currentUpdateRegionCount % _this._meshInfoKeys.length];
  7834. var t = !0;
  7835. var r = 3;
  7836. if (_this._scenemanager != null && _this._scenemanager.cameraComponent != null) {
  7837. var n = _this._getMainPlayerPosition();
  7838. if (n != null) {
  7839. if (_this._cameraInRegionId >= 0) {
  7840. var a = _this.getRegionIdWhichIncludeCamera(n);
  7841. (_this._cameraInRegionId != a || _this.regionIdInCamera.length == 0) && (_this._cameraInRegionId = a, _this.regionIdInCamera = _this._getNeighborId(_this._cameraInRegionId.toString()), _this.regionIdInCameraConst = _this.regionIdInCamera.slice());
  7842. var s = _this.regionIdInCamera.pop();
  7843. for (; s != null;) {
  7844. if (_this._notUsedRegionLists.indexOf(s) >= 0) s = _this.regionIdInCamera.pop();else break;
  7845. }
  7846. s != null && (_e = s.toString());
  7847. } else _this._cameraInRegionId = _this.getRegionIdWhichIncludeCamera(n);
  7848. if (_this._currentMeshUsedLod.size == 0 || _this._notUsedRegionLists.indexOf(parseInt(_e)) >= 0) {
  7849. _e = _this._cameraInRegionId.toString();
  7850. var _a = _this._getNeighborId(_e);
  7851. for (; _a.length == 0 && (_e = _this.getNearestRegionIdWithCamera(n).toString()), _this._notUsedRegionLists.indexOf(parseInt(_e)) >= 0;) {
  7852. _e = _a.pop().toString();
  7853. }
  7854. }
  7855. var o = _this._meshInfoJson[_this._cameraInRegionId.toString()].lod;
  7856. 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];
  7857. }
  7858. }
  7859. _this.setOneRegionLod(_e, r, t), _this.updateRegionNotInLocalNeighbor(), _this.cleanRootNodes();
  7860. }
  7861. });
  7862. E(this, "updateRegionNotInLocalNeighbor", function () {
  7863. Array.from(_this._currentMeshUsedLod.keys()).forEach(function (t) {
  7864. _this.regionIdInCameraConst.indexOf(parseInt(t)) < 0 && _this.setOneRegionLod(t, -1);
  7865. });
  7866. });
  7867. E(this, "cleanRootNodes", function () {
  7868. if (_this.scene.getFrameId() % 3 == 0) {
  7869. var _e2 = [];
  7870. _this.scene.rootNodes.forEach(function (t) {
  7871. (t.getClassName() == "TransformNode" && t.getChildren().length == 0 || t.getClassName() == "Mesh" && t.name == "__root__" && t.getChildren().length == 0) && _e2.push(t);
  7872. }), _e2.forEach(function (t) {
  7873. t.dispose();
  7874. });
  7875. }
  7876. });
  7877. E(this, "setOneRegionLod", function (e, t) {
  7878. _this._currentUpdateRegionCount++;
  7879. var n = _this._calHashCode(_this._rootDir),
  7880. o = "region_" + n + "_" + e;
  7881. if (t < 0) {
  7882. _this._currentMeshUsedLod.has(e) && (_this._currentMeshUsedLod.delete(e), _this._currentPartGroup.delete(o), _this.deleteMeshesByCustomProperty("group", "region_" + n + "_" + e));
  7883. return;
  7884. }
  7885. var a = _this._rootDir + e + "_lod" + t + "_xverse.glb",
  7886. s = _this._currentMeshUsedLod.get(e);
  7887. _this._currentPartGroup.add(o), s != null ? s != t && (_this._currentMeshUsedLod.set(e, t), _this._scenemanager.addNewLowPolyMesh({
  7888. url: a,
  7889. group: "region_" + n + "_" + e,
  7890. pick: !0,
  7891. lod: t,
  7892. skinInfo: _this._partMeshSkinInfo
  7893. }, [{
  7894. group: "region_" + n + "_" + e,
  7895. mode: 0
  7896. }])) : (_this._currentMeshUsedLod.set(e, t), _this._scenemanager.addNewLowPolyMesh({
  7897. url: a,
  7898. group: "region_" + n + "_" + e,
  7899. pick: !0,
  7900. lod: t,
  7901. skinInfo: _this._partMeshSkinInfo
  7902. }));
  7903. });
  7904. E(this, "checkPointInView", function (_ref) {
  7905. var e = _ref.x,
  7906. t = _ref.y,
  7907. r = _ref.z;
  7908. var n = ue4Position2Xverse({
  7909. x: e,
  7910. y: t,
  7911. z: r
  7912. });
  7913. if (!n) return !1;
  7914. for (var o = 0; o < 6; o++) {
  7915. if (_this.scene.frustumPlanes[o].dotCoordinate(n) < 0) return !1;
  7916. }
  7917. return !0;
  7918. });
  7919. E(this, "addNewLowPolyMesh", function (e, t, r) {
  7920. if (!e.url.endsWith("glb") && !e.url.startsWith("blob:")) return e.url.endsWith("zip") ? (_this.setMeshInfo(e.url, e.skinInfo), Promise.resolve(!0)) : (logger$1.error("[Engine] input model path is error! ", e.url), Promise.reject(new XLowpolyModelError("[Engine] input model path is error! " + e.url)));
  7921. {
  7922. var n = e.url;
  7923. return new Promise(function (o, a) {
  7924. return _this._scenemanager.urlTransformer(e.url).then(function (s) {
  7925. e.url = s;
  7926. var l = new XStaticMeshFromOneGltf(_this.scene, e),
  7927. u = Date.now();
  7928. return new Promise(function (c, h) {
  7929. l.loadMesh(r, !0).then(function (f) {
  7930. var d = Date.now();
  7931. if (_this._scenemanager.engineRunTimeStats.timeArray_loadStaticMesh.add(d - u), f == !0) {
  7932. var _ = _this.getLowModelType(e);
  7933. var g = 0;
  7934. 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) {
  7935. var m = [];
  7936. for (var v = 0; v < t.length; ++v) {
  7937. m.push(t[v].group), _this.updateLowModelGroup(t[v], _, g);
  7938. }
  7939. }
  7940. _this._scenemanager.engineRunTimeStats.timeArray_updateStaticMesh.add(Date.now() - d), c(!0);
  7941. } else h(new XLowpolyModelError("[Engine] after lowmodel error!"));
  7942. }).catch(function (f) {
  7943. logger$1.error("[Engine] load Mesh [" + n + "] error! " + f), h(new XLowpolyModelError("[Engine] load Mesh [".concat(n, "] error! ").concat(f)));
  7944. });
  7945. });
  7946. }).then(function (s) {
  7947. s == !0 ? (logger$1.info("[Engine] load Mesh [".concat(n, "] successfully.")), o(!0)) : a(!1);
  7948. }).catch(function (s) {
  7949. logger$1.error("[Engine] addNewLowPolyMesh [" + n + "] error! " + s), a(new XLowpolyModelError("[Engine] addNewLowPolyMesh [".concat(n, "] error! ").concat(s)));
  7950. });
  7951. });
  7952. }
  7953. });
  7954. E(this, "toggleLowModelVisibility", function (e) {
  7955. var t = e.vis,
  7956. _e$groupName = e.groupName,
  7957. r = _e$groupName === void 0 ? "" : _e$groupName,
  7958. _e$skinInfo = e.skinInfo,
  7959. n = _e$skinInfo === void 0 ? "" : _e$skinInfo;
  7960. _this._meshVis = t, _this._meshVisTypeName = {
  7961. groupName: r,
  7962. skinInfo: n
  7963. }, _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;
  7964. });
  7965. E(this, "reg_staticmesh_visibility", function () {
  7966. if (_this._doMeshVisChangeNumber >= 0) if (_this._doMeshVisChangeNumber < _this._visCheckDurationFrameNumber) {
  7967. if (_this._doMeshVisChangeNumber = _this._doMeshVisChangeNumber + 1, _this._meshVisTypeName.groupName == Te.ALL_MESHES) _this._lowModel_group.forEach(function (e, t) {
  7968. for (var r = 0, n = e.length; r < n; ++r) {
  7969. e[r].toggleVisibility(_this._meshVis);
  7970. }
  7971. });else {
  7972. if (_this._lowModel_group.has(_this._meshVisTypeName.groupName)) for (var _e3 = 0; _e3 < _this._lowModel_group.get(_this._meshVisTypeName.groupName).length; ++_e3) {
  7973. _this._lowModel_group.get(_this._meshVisTypeName.groupName)[_e3].toggleVisibility(_this._meshVis);
  7974. }
  7975. if (_this._meshVisTypeName.skinInfo != "") for (var _e4 = 0; _e4 < _this._staticmeshes.length; ++_e4) {
  7976. _this._staticmeshes[_e4].skinInfo == _this._meshVisTypeName.skinInfo && _this._staticmeshes[_e4].toggleVisibility(_this._meshVis);
  7977. }
  7978. }
  7979. } else _this._meshVis = !0, _this._meshVisTypeName = {
  7980. groupName: "",
  7981. skinInfo: ""
  7982. }, _this._doMeshVisChangeNumber = -1;
  7983. });
  7984. E(this, "_getMeshesByCustomProperty", function (e, t) {
  7985. var r = [];
  7986. return _this._staticmeshes.forEach(function (n) {
  7987. n[e] != null && n[e] == t && (r = r.concat(n.meshes));
  7988. }), r;
  7989. });
  7990. 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 = {
  7991. groupName: "",
  7992. skinInfo: ""
  7993. }, this._doMeshVisChangeNumber = -1, this._visCheckDurationFrameNumber = -1, this._regionLodRule = [0, 1, 3, 3, -1], this.initCgLowModel(), this._regionPartLoop();
  7994. }
  7995. _createClass(XStaticMeshComponent, [{
  7996. key: "cameraInRegionId",
  7997. get: function get() {
  7998. return this._cameraInRegionId;
  7999. }
  8000. }, {
  8001. key: "setRegionLodRule",
  8002. value: function setRegionLodRule(e) {
  8003. return e.length != 5 ? !1 : (e.forEach(function (t) {}), this._regionLodRule = e, !0);
  8004. }
  8005. }, {
  8006. key: "lowModel_group",
  8007. get: function get() {
  8008. return this._lowModel_group;
  8009. }
  8010. }, {
  8011. key: "_regionPartLoop",
  8012. value: function _regionPartLoop() {
  8013. this.scene.registerBeforeRender(this.reg_staticmesh_partupdate), this.scene.registerAfterRender(this.reg_staticmesh_visibility);
  8014. }
  8015. }, {
  8016. key: "_globalSearchCameraInWhichRegion",
  8017. value: function _globalSearchCameraInWhichRegion(e, t) {
  8018. var r = -1;
  8019. for (var n = 0; n < t.length; ++n) {
  8020. var o = this._meshInfoJson[t[n].toString()].boundingbox,
  8021. a = o[0],
  8022. s = o[1];
  8023. 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]) {
  8024. r = parseInt(t[n].toString());
  8025. break;
  8026. }
  8027. }
  8028. return r;
  8029. }
  8030. }, {
  8031. key: "getRegionIdByPosition",
  8032. value: function getRegionIdByPosition(e) {
  8033. return this.getRegionIdWhichIncludeCamera(e);
  8034. }
  8035. }, {
  8036. key: "getRegionIdWhichIncludeCamera",
  8037. value: function getRegionIdWhichIncludeCamera(e) {
  8038. var t = -1;
  8039. if (this._allowRegionUpdate == !1) return t;
  8040. 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) {
  8041. var r = 1e7;
  8042. for (var n = 0; n < this._meshInfoKeys.length; ++n) {
  8043. var o = this._meshInfoJson[this._meshInfoKeys[n]].center,
  8044. a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
  8045. r > a && (r = a, t = parseInt(this._meshInfoKeys[n]));
  8046. }
  8047. }
  8048. return t;
  8049. }
  8050. }, {
  8051. key: "getNearestRegionIdWithCamera",
  8052. value: function getNearestRegionIdWithCamera(e) {
  8053. var t = 1,
  8054. r = 1e7;
  8055. for (var n = 0; n < this._meshInfoKeys.length; ++n) {
  8056. if (this._notUsedRegionLists.indexOf(parseInt(this._meshInfoKeys[n])) >= 0) continue;
  8057. var o = this._meshInfoJson[this._meshInfoKeys[n]].center,
  8058. a = Math.abs(e.x - o[0]) + Math.abs(e.y - o[1]);
  8059. r > a && (r = a, t = parseInt(this._meshInfoKeys[n]));
  8060. }
  8061. return t;
  8062. }
  8063. }, {
  8064. key: "_getNeighborId",
  8065. value: function _getNeighborId(e) {
  8066. var t = this._meshInfoJson[e].lod;
  8067. var r = [];
  8068. var n = Object.keys(t);
  8069. for (var o = n.length - 1; o >= 0; --o) {
  8070. r = r.concat(t[n[o]]);
  8071. }
  8072. return r.push(parseInt(e)), r;
  8073. }
  8074. }, {
  8075. key: "_getMainPlayerPosition",
  8076. value: function _getMainPlayerPosition() {
  8077. var e = this._scenemanager.cameraComponent.getCameraPose().position,
  8078. t = this._scenemanager.avatarComponent.getMainAvatar();
  8079. if (t != null && t != null) {
  8080. var r = t.position;
  8081. if (r != null) return r;
  8082. }
  8083. return e;
  8084. }
  8085. }, {
  8086. key: "_calHashCode",
  8087. value: function _calHashCode(e) {
  8088. return hashCode(e) + "_" + this._partMeshSkinInfo;
  8089. }
  8090. }, {
  8091. key: "forceAllRegionLod",
  8092. value: function forceAllRegionLod() {
  8093. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3;
  8094. e < 0 && (e = 0), e > 3 && (e = 3), this.stopMeshUpdate(), this._allowRegionForceLod = !0, this._forceLod = e;
  8095. }
  8096. }, {
  8097. key: "deleteLastRegionMesh",
  8098. value: function deleteLastRegionMesh() {
  8099. if (this._rootDir != "") {
  8100. var e = this._calHashCode(this._rootDir);
  8101. 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);
  8102. }
  8103. }
  8104. }, {
  8105. key: "startMeshUpdate",
  8106. value: function startMeshUpdate() {
  8107. this._allowRegionUpdate == !1 && this._meshInfoJson != null && this._abosoluteUrl != "" && this._meshInfoKeys.length > 0 && (this._allowRegionUpdate = !0);
  8108. }
  8109. }, {
  8110. key: "stopMeshUpdate",
  8111. value: function stopMeshUpdate() {
  8112. this._allowRegionUpdate = !1;
  8113. }
  8114. }, {
  8115. key: "parseJson",
  8116. value: function parseJson(e) {
  8117. var _this2 = this;
  8118. return new Promise(function (t, r) {
  8119. return _this2._scenemanager.urlTransformer(e).then(function (n) {
  8120. var o = new XMLHttpRequest();
  8121. o.open("get", n), o.send(null), o.onload = function () {
  8122. if (o.status == 200) {
  8123. var a = JSON.parse(o.responseText);
  8124. _this2._orijson = a, _this2._meshInfoJson = _this2._orijson.usedRegion, _this2._notUsedRegionLists = _this2._orijson.notUsedRegion, _this2._meshInfoKeys = Object.keys(_this2._meshInfoJson), logger$1.info("[Engine] parse zip mesh info successful"), t();
  8125. }
  8126. }, o.onerror = function () {
  8127. logger$1.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)));
  8128. };
  8129. }).catch(function (n) {
  8130. logger$1.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)));
  8131. });
  8132. });
  8133. }
  8134. }, {
  8135. key: "initCgLowModel",
  8136. value: function initCgLowModel() {
  8137. var e = BABYLON.MeshBuilder.CreatePlane("CgPlane", {
  8138. size: 400
  8139. });
  8140. e.position = new BABYLON.Vector3(0, 1010, 0), e.rotation = new BABYLON.Vector3(3 * Math.PI / 2, 0, 0), this._CgPlane = new XStaticMesh({
  8141. id: "CgPlane",
  8142. mesh: e,
  8143. xtype: EMeshType.Cgplane
  8144. }), this._CgPlane.hide();
  8145. }
  8146. }, {
  8147. key: "getLowModelType",
  8148. value: function getLowModelType(e) {
  8149. var t = "";
  8150. return e.group != null ? t = e.group : t = "default", t;
  8151. }
  8152. }, {
  8153. key: "lowmodelGroupMapAddValue",
  8154. value: function lowmodelGroupMapAddValue(e, t) {
  8155. var r = this._lowModel_group.get(e);
  8156. r != null ? (r.push(t), this._lowModel_group.set(e, r)) : this._lowModel_group.set(e, [t]);
  8157. }
  8158. }, {
  8159. key: "updateLowModelGroup",
  8160. value: function updateLowModelGroup(e, t, r) {
  8161. var n = r;
  8162. 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);
  8163. }
  8164. }, {
  8165. key: "toggleVisibleLowModelGroup",
  8166. value: function toggleVisibleLowModelGroup(e, t) {
  8167. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
  8168. if (this._lowModel_group.has(t)) {
  8169. var n = this._lowModel_group.get(t);
  8170. var o = n.length;
  8171. r >= 0 && o >= r && (o = r);
  8172. for (var a = 0; a < o; ++a) {
  8173. n[a].toggleVisibility(e);
  8174. }
  8175. }
  8176. }
  8177. }, {
  8178. key: "deleteLowModelGroup",
  8179. value: function deleteLowModelGroup(e) {
  8180. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
  8181. if (this._lowModel_group.has(e)) {
  8182. var o = this._lowModel_group.get(e);
  8183. var a = o.length;
  8184. t >= 0 && a >= t && (a = t);
  8185. for (var s = 0; s < a; ++s) {
  8186. o[s].dispose();
  8187. }
  8188. t >= 0 ? this._lowModel_group.set(e, this._lowModel_group.get(e).slice(a)) : this._lowModel_group.delete(e);
  8189. }
  8190. var r = this._lowModel_group.get(e),
  8191. n = [];
  8192. r != null && r.length > 0 ? this._staticmeshes.forEach(function (o) {
  8193. if (o.group != e) n.push(o);else for (var _a2 = 0; _a2 < r.length; ++_a2) {
  8194. o.groupUuid == r[_a2].groupUuid && n.push(o);
  8195. }
  8196. }) : this._staticmeshes.forEach(function (o) {
  8197. o.group != e && n.push(o);
  8198. }), this._staticmeshes = n;
  8199. }
  8200. }, {
  8201. key: "deleteMeshesByGroup",
  8202. value: function deleteMeshesByGroup(e) {
  8203. this.deleteLowModelGroup(e);
  8204. }
  8205. }, {
  8206. key: "deleteMeshesById",
  8207. value: function deleteMeshesById(e) {
  8208. this.deleteMeshesByCustomProperty("id", e);
  8209. }
  8210. }, {
  8211. key: "deleteMeshesByLoD",
  8212. value: function deleteMeshesByLoD(e) {
  8213. this.deleteMeshesByCustomProperty("lod", e);
  8214. }
  8215. }, {
  8216. key: "deleteMeshesBySkinInfo",
  8217. value: function deleteMeshesBySkinInfo(e) {
  8218. this.deleteMeshesByCustomProperty("skinInfo", e);
  8219. }
  8220. }, {
  8221. key: "removeMeshesFromSceneByGroup",
  8222. value: function removeMeshesFromSceneByGroup(e) {
  8223. this.removeMeshesFromSceneByCustomProperty("group", e);
  8224. }
  8225. }, {
  8226. key: "removeMeshesFromSceneById",
  8227. value: function removeMeshesFromSceneById(e) {
  8228. this.removeMeshesFromSceneByCustomProperty("id", e);
  8229. }
  8230. }, {
  8231. key: "addMeshesToSceneByGroup",
  8232. value: function addMeshesToSceneByGroup(e) {
  8233. this.addMeshesToSceneByCustomProperty("group", e);
  8234. }
  8235. }, {
  8236. key: "addMeshesToSceneById",
  8237. value: function addMeshesToSceneById(e) {
  8238. this.addMeshesToSceneByCustomProperty("id", e);
  8239. }
  8240. }, {
  8241. key: "removeMeshesFromSceneByCustomProperty",
  8242. value: function removeMeshesFromSceneByCustomProperty(e, t) {
  8243. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
  8244. this._staticmeshes.forEach(function (n) {
  8245. n.isinscene && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.removeFromScene() : n[e] != t || n.removeFromScene());
  8246. });
  8247. }
  8248. }, {
  8249. key: "addMeshesToSceneByCustomProperty",
  8250. value: function addMeshesToSceneByCustomProperty(e, t) {
  8251. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
  8252. this._staticmeshes.forEach(function (n) {
  8253. n.isinscene == !1 && n[e] != null && (r ? n[e].indexOf(t) < 0 || n.addToScene() : n[e] != t || n.addToScene());
  8254. });
  8255. }
  8256. }, {
  8257. key: "deleteMeshesByCustomProperty",
  8258. value: function deleteMeshesByCustomProperty(e, t) {
  8259. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
  8260. var n = [];
  8261. this._staticmeshes.forEach(function (a) {
  8262. a[e] != null && (r ? a[e].indexOf(t) < 0 ? n.push(a) : a.dispose() : a[e] != t ? n.push(a) : a.dispose());
  8263. }), this._staticmeshes = n;
  8264. var o = Array.from(this._lowModel_group.keys());
  8265. for (var a = 0; a < o.length; ++a) {
  8266. var s = o[a],
  8267. l = this._lowModel_group.get(s);
  8268. if (l != null) {
  8269. var u = [];
  8270. for (var c = 0; c < l.length; ++c) {
  8271. l[c][e] != null && (r ? l[c][e].indexOf(t) < 0 && u.push(l[c]) : l[c][e] != t && u.push(l[c]));
  8272. }
  8273. u.length > 0 ? this._lowModel_group.set(s, u) : this._lowModel_group.delete(s);
  8274. }
  8275. }
  8276. }
  8277. }, {
  8278. key: "getMeshes",
  8279. value: function getMeshes() {
  8280. var e = [];
  8281. for (var t = 0; t < this._staticmeshes.length; ++t) {
  8282. e = e.concat(this._staticmeshes[t].meshes);
  8283. }
  8284. return e;
  8285. }
  8286. }, {
  8287. key: "getCgMesh",
  8288. value: function getCgMesh() {
  8289. return this._CgPlane;
  8290. }
  8291. }, {
  8292. key: "getMeshesByGroup",
  8293. value: function getMeshesByGroup() {
  8294. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
  8295. var t = this._lowModel_group.get(e);
  8296. if (t != null) {
  8297. var r = [];
  8298. for (var n = 0; n < t.length; ++n) {
  8299. r = r.concat(t[n].meshes);
  8300. }
  8301. return r;
  8302. } else return null;
  8303. }
  8304. }, {
  8305. key: "getMeshesByGroup2",
  8306. value: function getMeshesByGroup2() {
  8307. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "default";
  8308. return this._getMeshesByCustomProperty("group", e);
  8309. }
  8310. }]);
  8311. return XStaticMeshComponent;
  8312. }();
  8313. var XVideoRawYUV = /*#__PURE__*/function () {
  8314. function XVideoRawYUV(e, t) {
  8315. var _this = this;
  8316. _classCallCheck(this, XVideoRawYUV);
  8317. E(this, "scene");
  8318. E(this, "_videoRawYUVTexture");
  8319. E(this, "videosResOriArray");
  8320. E(this, "_currentVideoId");
  8321. this.scene = e, this._videoRawYUVTexture = [], this.videosResOriArray = t, this._currentVideoId = -1;
  8322. for (var r = 0; r < t.length; ++r) {
  8323. (function (n) {
  8324. var o = BABYLON.RawTexture.CreateLuminanceTexture(null, t[n].width, t[n].height * 1.5, _this.scene, !1, !0);
  8325. o.name = "videoTex_" + t[n].width + "_" + t[n].height, _this._videoRawYUVTexture.push(o);
  8326. })(r);
  8327. }
  8328. }
  8329. _createClass(XVideoRawYUV, [{
  8330. key: "inRange",
  8331. value: function inRange(e) {
  8332. return e >= 0 && e < this._videoRawYUVTexture.length;
  8333. }
  8334. }, {
  8335. key: "getVideoYUVTex",
  8336. value: function getVideoYUVTex(e) {
  8337. return this.inRange(e) ? this._videoRawYUVTexture[e] : null;
  8338. }
  8339. }, {
  8340. key: "findId",
  8341. value: function findId(e, t) {
  8342. var r = 0;
  8343. for (var n = 0; n < this.videosResOriArray.length; ++n) {
  8344. if (this.videosResOriArray[n].width == e && this.videosResOriArray[n].height == t) {
  8345. r = n;
  8346. break;
  8347. }
  8348. }
  8349. return r;
  8350. }
  8351. }, {
  8352. key: "getCurrentVideoTexId",
  8353. value: function getCurrentVideoTexId() {
  8354. return this._currentVideoId;
  8355. }
  8356. }, {
  8357. key: "setCurrentVideoTexId",
  8358. value: function setCurrentVideoTexId(e) {
  8359. this._currentVideoId = e;
  8360. }
  8361. }]);
  8362. return XVideoRawYUV;
  8363. }();
  8364. var XMaterialComponent = /*#__PURE__*/function () {
  8365. function XMaterialComponent(e, t) {
  8366. var _this = this;
  8367. _classCallCheck(this, XMaterialComponent);
  8368. E(this, "scene");
  8369. E(this, "engine");
  8370. E(this, "yuvInfo");
  8371. E(this, "shaderMode");
  8372. E(this, "_panoInfo");
  8373. E(this, "_dynamic_size");
  8374. E(this, "_dynamic_babylonpose");
  8375. E(this, "_dynamic_textures");
  8376. E(this, "_dynamic_shaders");
  8377. E(this, "_scenemanager");
  8378. E(this, "_videoTexture");
  8379. E(this, "_videoElement");
  8380. E(this, "_lowModelShader");
  8381. E(this, "_defaultShader");
  8382. E(this, "_inputYUV420", !0);
  8383. E(this, "_inputPanoYUV420", !0);
  8384. E(this, "_videoRawYUVTexArray");
  8385. E(this, "_isUpdateYUV", !0);
  8386. E(this, "initMaterial", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  8387. return regenerator.wrap(function _callee$(_context) {
  8388. while (1) {
  8389. switch (_context.prev = _context.next) {
  8390. case 0:
  8391. return _context.abrupt("return", new Promise(function (e, t) {
  8392. _this._initDefaultShader(), _this.shaderMode == 2 ? _this.initDynamicData(_this._panoInfo.dynamicRange, _this._panoInfo.width, _this._panoInfo.height).then(function () {
  8393. _this._initPureVideoShader(), _this._prepareRender(_this.yuvInfo);
  8394. }) : _this.shaderMode == 1 ? (_this._initPureVideoShader(), _this._prepareRender(_this.yuvInfo)) : _this.shaderMode == 0, e(!0);
  8395. }));
  8396. case 1:
  8397. case "end":
  8398. return _context.stop();
  8399. }
  8400. }
  8401. }, _callee);
  8402. })));
  8403. E(this, "_initPureVideoContent", function (e) {
  8404. _this._inputYUV420 ? _this._videoRawYUVTexArray.getVideoYUVTex(0) != null && (_this._lowModelShader.setTexture("texture_video", _this._videoRawYUVTexArray.getVideoYUVTex(0)), _this._lowModelShader.setFloat("isYUV", 1), BABYLON.Texture.WhenAllReady([_this._videoRawYUVTexArray.getVideoYUVTex(0)], function () {
  8405. _this._changePureVideoLowModelShaderCanvasSize(e);
  8406. })) : (_this._videoElement = e.videoElement, _this._videoTexture || (_this._videoTexture = new VideoTexture("InterVideoTexture", _this._videoElement, _this.scene, !0, !1)), BABYLON.Texture.WhenAllReady([_this._videoTexture], function () {
  8407. _this._changePureVideoLowModelShaderCanvasSize({
  8408. width: _this._videoElement.height,
  8409. height: _this._videoElement.width,
  8410. fov: e.fov
  8411. });
  8412. }), _this._lowModelShader.setTexture("texture_video", _this._videoTexture), _this._lowModelShader.setFloat("isYUV", 0));
  8413. });
  8414. E(this, "_changePureVideoLowModelShaderCanvasSize", function (e) {
  8415. var a;
  8416. var t = e.fov || 50,
  8417. r = e.width || 720,
  8418. n = e.height || 1280,
  8419. o = r / (2 * Math.tan(Math.PI * t / 360));
  8420. (a = _this._lowModelShader) == null || a.setVector3("focal_width_height", new BABYLON.Vector3(o, r, n));
  8421. });
  8422. E(this, "updateRawYUVData", function (e, t, r) {
  8423. var n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
  8424. var o, a;
  8425. if (n == -1 && (n = _this.yuvInfo.fov), _this._isUpdateYUV == !0) {
  8426. var s = {
  8427. width: t,
  8428. height: r,
  8429. fov: n
  8430. },
  8431. l = _this._videoRawYUVTexArray.findId(t, r),
  8432. u = _this._videoRawYUVTexArray.getCurrentVideoTexId();
  8433. (u < 0 || l != u || n != _this.yuvInfo.fov) && (_this.yuvInfo.width = t, _this.yuvInfo.height = r, _this.yuvInfo.fov = n, _this._videoRawYUVTexArray.setCurrentVideoTexId(l), _this._changeVideoRes(l), _this._changePureVideoLowModelShaderCanvasSize(s), _this._scenemanager.cameraComponent.cameraFovChange(s), _this._scenemanager.yuvInfo = s), (o = _this._videoRawYUVTexArray.getVideoYUVTex(l)) == null || o.update(e), (a = _this._videoRawYUVTexArray.getVideoYUVTex(l)) == null || a.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  8434. }
  8435. });
  8436. E(this, "_changeVideoRes", function (e) {
  8437. _this._lowModelShader.setTexture("texture_video", _this._videoRawYUVTexArray.getVideoYUVTex(e));
  8438. });
  8439. E(this, "initDynamicData", function (e, t, r) {
  8440. return new Promise(function (n, o) {
  8441. _this.setDynamicSize(e).then(function (a) {
  8442. if (a) {
  8443. for (var s = 0; s < e; ++s) {
  8444. (function (l) {
  8445. _this.initDynamicTexture(l, t, r), _this.initDynamicShaders(l).then(function () {
  8446. _this._updatePanoShaderInput(l);
  8447. });
  8448. })(s);
  8449. }
  8450. n(!0);
  8451. } else o(new XMaterialError("[Engine] DynamicRoomSize (".concat(e, ") is too small")));
  8452. });
  8453. }).catch(function (n) {
  8454. return logger$1.error("[Engine] ".concat(n));
  8455. });
  8456. });
  8457. E(this, "_initDefaultShader", function () {
  8458. _this._defaultShader == null && (_this._defaultShader = new BABYLON.GridMaterial("GridShader", _this.scene), _this._defaultShader.gridRatio = 50, _this._defaultShader.lineColor = new BABYLON.Color3(0, 0, .5), _this._defaultShader.majorUnitFrequency = 1, _this._defaultShader.mainColor = new BABYLON.Color3(.6, .6, .6), _this._defaultShader.backFaceCulling = !1);
  8459. });
  8460. E(this, "_initPureVideoShader", function () {
  8461. if (_this._lowModelShader == null) {
  8462. var _e = new BABYLON.ShaderMaterial("PureVideoShader", _this.scene, {
  8463. vertexSource: pureVideoVertex,
  8464. fragmentSource: pureVideoFragment
  8465. }, {
  8466. attributes: ["uv", "position", "world0", "world1", "world2", "world3"],
  8467. uniforms: ["view", "projection", "worldViewProjection", "world"],
  8468. defines: ["#define SHADOWFULLFLOAT"]
  8469. });
  8470. _e.setTexture("shadowSampler", null), _e.setMatrix("lightSpaceMatrix", null), _e.setFloat("haveShadowLight", 0), _e.setTexture("texture_video", null), _e.setFloat("isYUV", _this._inputYUV420 ? 1 : 0), _e.setFloat("fireworkLight", 0), _e.setVector3("fireworkLightPosition", new BABYLON.Vector3(0, 0, 0)), _e.setVector3("focal_width_height", new BABYLON.Vector3(772.022491, 720, 1280)), _e.backFaceCulling = !1, _this._lowModelShader = _e;
  8471. }
  8472. });
  8473. E(this, "setDynamicSize", function (e) {
  8474. return new Promise(function (t, r) {
  8475. e >= 1 && e <= 100 ? (_this._dynamic_size = e, t(!0)) : (_this._dynamic_size = 1, t(!1));
  8476. });
  8477. });
  8478. E(this, "_isInDynamicRange", function (e) {
  8479. return e < _this._dynamic_size && e >= 0;
  8480. });
  8481. E(this, "initDynamicTexture", function (e, t, r) {
  8482. _this._isInDynamicRange(e) && (_this._dynamic_textures[e] != null && (_this._dynamic_textures[e].dispose(), _this._dynamic_textures[e] = null), _this._dynamic_textures[e] = new BABYLON.RawTexture(null, t, r * 1.5, BABYLON.Engine.TEXTUREFORMAT_LUMINANCE, _this.scene, !1, !0, BABYLON.Texture.NEAREST_SAMPLINGMODE, BABYLON.Engine.TEXTURETYPE_UNSIGNED_BYTE), _this._dynamic_textures[e].name = "Pano_Dynamic_" + e + "_" + Date.now());
  8483. });
  8484. E(this, "initDynamicShaders", function (e) {
  8485. return logger$1.info("[Engine] Material init dynamic shader."), new Promise(function (t, r) {
  8486. _this._dynamic_shaders[e] != null && _this._dynamic_shaders[e].dispose();
  8487. var n = new BABYLON.ShaderMaterial("Pano_Shader_" + e, _this.scene, {
  8488. vertexSource: panoVertex,
  8489. fragmentSource: panoFragment
  8490. }, {
  8491. attributes: ["uv", "position", "world0", "world1", "world2", "world3"],
  8492. uniforms: ["view", "projection", "worldViewProjection", "world"],
  8493. defines: ["#define SHADOWFULLFLOAT"]
  8494. });
  8495. n.setTexture("texture_pano", null), n.setVector3("centre_pose", new BABYLON.Vector3(0, 0, 0)), n.setFloat("isYUV", _this._inputPanoYUV420 ? 1 : 0), n.setTexture("shadowSampler", null), n.setMatrix("lightSpaceMatrix", null), n.setFloat("haveShadowLight", 0), n.setFloat("fireworkLight", 0), n.setVector3("fireworkLightPosition", new BABYLON.Vector3(0, 0, 0)), n.backFaceCulling = !1, _this._dynamic_shaders[e] = n, t(!0);
  8496. });
  8497. });
  8498. this._scenemanager = e, this.scene = e.Scene, this.engine = this.scene.getEngine(), this.shaderMode = 1, this._dynamic_textures = [], this._dynamic_shaders = [], this._dynamic_babylonpose = [], this._videoRawYUVTexArray = new XVideoRawYUV(this.scene, t.videoResOriArray), this.shaderMode = t.shaderMode, t.yuvInfo != null && (this.yuvInfo = t.yuvInfo), t.panoInfo != null && this.setPanoInfo(t.panoInfo);
  8499. }
  8500. _createClass(XMaterialComponent, [{
  8501. key: "stopYUVUpdate",
  8502. value: function stopYUVUpdate() {
  8503. this._isUpdateYUV = !1;
  8504. }
  8505. }, {
  8506. key: "allowYUVUpdate",
  8507. value: function allowYUVUpdate() {
  8508. this._isUpdateYUV = !0;
  8509. }
  8510. }, {
  8511. key: "setPanoInfo",
  8512. value: function setPanoInfo(e) {
  8513. this._panoInfo = e;
  8514. }
  8515. }, {
  8516. key: "_prepareRender",
  8517. value: function _prepareRender(e) {
  8518. e && (this._initPureVideoContent(e), this._updatePureVideoShaderInput());
  8519. }
  8520. }, {
  8521. key: "getPureVideoShader",
  8522. value: function getPureVideoShader() {
  8523. return this._lowModelShader;
  8524. }
  8525. }, {
  8526. key: "getDefaultShader",
  8527. value: function getDefaultShader() {
  8528. return this._defaultShader;
  8529. }
  8530. }, {
  8531. key: "updatePanoPartYUV",
  8532. value: function updatePanoPartYUV(e, t, r) {
  8533. var n = t.subarray(0, r.width * r.height),
  8534. o = t.subarray(r.width * r.height, r.width * r.height * 1.25),
  8535. a = t.subarray(r.width * r.height * 1.25),
  8536. s = this._panoInfo.width,
  8537. l = this._panoInfo.height;
  8538. if (this._dynamic_textures[e] != null) {
  8539. var u = this._dynamic_textures[e].getInternalTexture();
  8540. if (u != null && u != null) {
  8541. var c = this.engine._getTextureTarget(u);
  8542. this.engine._bindTextureDirectly(c, u, !0), this.engine.updateTextureData(u, n, r.startX, l * 1.5 - r.startY - r.height, r.width, r.height), this.engine.updateTextureData(u, o, r.startX * .5, (l - r.startY - r.height) * .5, r.width * .5 - 1, r.height * .5 - 1), this.engine.updateTextureData(u, a, r.startX * .5 + s * .5, (l - r.startY - r.height) * .5, r.width * .5, r.height * .5), this.engine._bindTextureDirectly(c, null);
  8543. }
  8544. }
  8545. }
  8546. }, {
  8547. key: "changePanoImg",
  8548. value: function changePanoImg(e, t) {
  8549. var _this2 = this;
  8550. if (logger$1.info("[Engine] changePanoImg, id=".concat(e, ", pose=").concat(t.pose.position.x, ",").concat(t.pose.position.y, ",").concat(t.pose.position.z)), !this._isInDynamicRange(e)) return logger$1.error("[Engine] ".concat(e, " is bigger than dynamic size set in PanoInfo")), Promise.reject(new XMaterialError("[Engine] ".concat(e, " is bigger than dynamic size set in PanoInfo")));
  8551. var r = ue4Position2Xverse(t.pose.position);
  8552. return r && (this._dynamic_babylonpose[e] = {
  8553. position: r
  8554. }), new Promise(function (n, o) {
  8555. try {
  8556. typeof t.data == "string" ? (_this2.setPanoYUV420(!1), _this2._dynamic_textures[e].updateURL(t.data, null, function () {
  8557. _this2._dynamic_textures[e].updateSamplingMode(BABYLON.Texture.NEAREST_SAMPLINGMODE);
  8558. })) : (_this2.isPanoYUV420() == !1 && _this2.initDynamicTexture(e, _this2._panoInfo.width, _this2._panoInfo.height), _this2.setPanoYUV420(!0), _this2._dynamic_textures[e].update(t.data), _this2._dynamic_textures[e].updateSamplingMode(BABYLON.Texture.NEAREST_SAMPLINGMODE)), n(_this2);
  8559. } catch (a) {
  8560. o(new XMaterialError("[Engine] ChangePanoImg Error! ".concat(a)));
  8561. }
  8562. }).then(function (n) {
  8563. return t.fov != null && _this2._scenemanager.cameraComponent.changeCameraFov(t.fov * Math.PI / 180), _this2._dynamic_shaders[e].setFloat("isYUV", _this2._inputPanoYUV420 ? 1 : 0), _this2._dynamic_shaders[e].setTexture("texture_pano", _this2._dynamic_textures[e]), _this2._dynamic_shaders[e].setVector3("centre_pose", _this2._dynamic_babylonpose[e].position), !0;
  8564. });
  8565. }
  8566. }, {
  8567. key: "setYUV420",
  8568. value: function setYUV420(e) {
  8569. this._inputYUV420 = e;
  8570. }
  8571. }, {
  8572. key: "isYUV420",
  8573. value: function isYUV420() {
  8574. return this._inputYUV420;
  8575. }
  8576. }, {
  8577. key: "setPanoYUV420",
  8578. value: function setPanoYUV420(e) {
  8579. this._inputPanoYUV420 = e;
  8580. }
  8581. }, {
  8582. key: "isPanoYUV420",
  8583. value: function isPanoYUV420() {
  8584. return this._inputPanoYUV420;
  8585. }
  8586. }, {
  8587. key: "getDynamicShader",
  8588. value: function getDynamicShader(e) {
  8589. return this._dynamic_shaders[e];
  8590. }
  8591. }, {
  8592. key: "_updatePureVideoShaderInput",
  8593. value: function _updatePureVideoShaderInput() {
  8594. var _this3 = this;
  8595. var e, t, r, n, o, a, s, l, u, c;
  8596. if (this.scene.getLightByName("AvatarLight") ? ((e = this._lowModelShader) == null || e.setFloat("haveShadowLight", 1), (n = this._lowModelShader) == null || n.setTexture("shadowSampler", (r = (t = this.scene.getLightByName("AvatarLight")) == null ? void 0 : t.getShadowGenerator()) == null ? void 0 : r.getShadowMapForRendering()), (s = this._lowModelShader) == null || s.setMatrix("lightSpaceMatrix", (a = (o = this.scene.getLightByName("AvatarLight")) == null ? void 0 : o.getShadowGenerator()) == null ? void 0 : a.getTransformMatrix())) : ((l = this._lowModelShader) == null || l.setTexture("shadowSampler", this._videoTexture), (u = this._lowModelShader) == null || u.setMatrix("lightSpaceMatrix", new Matrix()), (c = this._lowModelShader) == null || c.setFloat("haveShadowLight", 0)), this.scene.getLightByName("fireworkLight")) this.scene.registerBeforeRender(function () {
  8597. var h;
  8598. _this3._lowModelShader.setFloat("fireworkLight", _this3.scene.getLightByName("fireworkLight").getScaledIntensity()), _this3._lowModelShader.setVector3("fireworkLightPosition", (h = _this3.scene.getLightByName("fireworkLight")) == null ? void 0 : h.position);
  8599. });else {
  8600. var h = new BABYLON.PointLight("fireworkLight", new BABYLON.Vector3(0, 0, 0), this.scene);
  8601. h.intensity = 0;
  8602. }
  8603. }
  8604. }, {
  8605. key: "_updatePanoShaderInput",
  8606. value: function _updatePanoShaderInput(e) {
  8607. var _this4 = this;
  8608. var t, r, n, o, a, s, l, u, c, h;
  8609. if (this._isInDynamicRange(e)) if (this.scene.getLightByName("AvatarLight") ? ((t = this._dynamic_shaders[e]) == null || t.setFloat("haveShadowLight", 1), (o = this._dynamic_shaders[e]) == null || o.setTexture("shadowSampler", (n = (r = this.scene.getLightByName("AvatarLight")) == null ? void 0 : r.getShadowGenerator()) == null ? void 0 : n.getShadowMapForRendering()), (l = this._dynamic_shaders[e]) == null || l.setMatrix("lightSpaceMatrix", (s = (a = this.scene.getLightByName("AvatarLight")) == null ? void 0 : a.getShadowGenerator()) == null ? void 0 : s.getTransformMatrix())) : ((u = this._dynamic_shaders[e]) == null || u.setTexture("shadowSampler", null), (c = this._dynamic_shaders[e]) == null || c.setMatrix("lightSpaceMatrix", new Matrix()), (h = this._dynamic_shaders[e]) == null || h.setFloat("haveShadowLight", 0)), this.scene.getLightByName("fireworkLight")) this.scene.registerBeforeRender(function () {
  8610. var f;
  8611. _this4._dynamic_shaders[e].setFloat("fireworkLight", _this4.scene.getLightByName("fireworkLight").getScaledIntensity()), _this4._dynamic_shaders[e].setVector3("fireworkLightPosition", (f = _this4.scene.getLightByName("fireworkLight")) == null ? void 0 : f.position);
  8612. });else {
  8613. var f = new BABYLON.PointLight("fireworkLight", new BABYLON.Vector3(0, 0, 0), this.scene);
  8614. f.intensity = 0;
  8615. }
  8616. }
  8617. }]);
  8618. return XMaterialComponent;
  8619. }();
  8620. var XStats = /*#__PURE__*/function () {
  8621. function XStats(e) {
  8622. _classCallCheck(this, XStats);
  8623. E(this, "scene");
  8624. E(this, "sceneInstrumentation");
  8625. E(this, "engineInstrumentation");
  8626. E(this, "caps");
  8627. E(this, "engine");
  8628. E(this, "_canvas");
  8629. E(this, "_osversion");
  8630. E(this, "_scenemanager");
  8631. this._scenemanager = e, this.scene = e.Scene, this._canvas = e.canvas, this.initSceneInstrument();
  8632. }
  8633. _createClass(XStats, [{
  8634. key: "initSceneInstrument",
  8635. value: function initSceneInstrument() {
  8636. this.sceneInstrumentation = new BABYLON.SceneInstrumentation(this.scene), this.sceneInstrumentation.captureCameraRenderTime = !0, this.sceneInstrumentation.captureActiveMeshesEvaluationTime = !0, this.sceneInstrumentation.captureRenderTargetsRenderTime = !0, this.sceneInstrumentation.captureFrameTime = !0, this.sceneInstrumentation.captureRenderTime = !0, this.sceneInstrumentation.captureInterFrameTime = !0, this.sceneInstrumentation.captureParticlesRenderTime = !0, this.sceneInstrumentation.captureSpritesRenderTime = !0, this.sceneInstrumentation.capturePhysicsTime = !0, this.sceneInstrumentation.captureAnimationsTime = !0, this.engineInstrumentation = new BABYLON.EngineInstrumentation(this.scene.getEngine()), this.caps = this.scene.getEngine().getCaps(), this.engine = this.scene.getEngine(), this._osversion = this.osVersion();
  8637. }
  8638. }, {
  8639. key: "getFrameTimeCounter",
  8640. value: function getFrameTimeCounter() {
  8641. return this.sceneInstrumentation.frameTimeCounter.current;
  8642. }
  8643. }, {
  8644. key: "getInterFrameTimeCounter",
  8645. value: function getInterFrameTimeCounter() {
  8646. return this.sceneInstrumentation.interFrameTimeCounter.current;
  8647. }
  8648. }, {
  8649. key: "getActiveMeshEvaluationTime",
  8650. value: function getActiveMeshEvaluationTime() {
  8651. return this.sceneInstrumentation.activeMeshesEvaluationTimeCounter.current;
  8652. }
  8653. }, {
  8654. key: "getDrawCall",
  8655. value: function getDrawCall() {
  8656. return this.sceneInstrumentation.drawCallsCounter.current;
  8657. }
  8658. }, {
  8659. key: "getDrawCallTime",
  8660. value: function getDrawCallTime() {
  8661. return this.sceneInstrumentation.renderTimeCounter.current;
  8662. }
  8663. }, {
  8664. key: "getAnimationTime",
  8665. value: function getAnimationTime() {
  8666. return this.sceneInstrumentation.animationsTimeCounter.current;
  8667. }
  8668. }, {
  8669. key: "getActiveMesh",
  8670. value: function getActiveMesh() {
  8671. return this.scene.getActiveMeshes().length;
  8672. }
  8673. }, {
  8674. key: "getActiveFaces",
  8675. value: function getActiveFaces() {
  8676. return Math.round(this.scene.getActiveIndices() / 3);
  8677. }
  8678. }, {
  8679. key: "getActiveBones",
  8680. value: function getActiveBones() {
  8681. return this.scene.getActiveBones();
  8682. }
  8683. }, {
  8684. key: "getActiveAnimation",
  8685. value: function getActiveAnimation() {
  8686. return this.scene._activeAnimatables.length;
  8687. }
  8688. }, {
  8689. key: "getActiveParticles",
  8690. value: function getActiveParticles() {
  8691. return this.scene.getActiveParticles();
  8692. }
  8693. }, {
  8694. key: "getTotalMaterials",
  8695. value: function getTotalMaterials() {
  8696. return this.scene.materials.length;
  8697. }
  8698. }, {
  8699. key: "getTotalTextures",
  8700. value: function getTotalTextures() {
  8701. return this.scene.textures.length;
  8702. }
  8703. }, {
  8704. key: "getTotalGeometries",
  8705. value: function getTotalGeometries() {
  8706. return this.scene.geometries.length;
  8707. }
  8708. }, {
  8709. key: "getTotalMeshes",
  8710. value: function getTotalMeshes() {
  8711. return this.scene.meshes.length;
  8712. }
  8713. }, {
  8714. key: "getCameraRenderTime",
  8715. value: function getCameraRenderTime() {
  8716. return this.sceneInstrumentation.cameraRenderTimeCounter.current;
  8717. }
  8718. }, {
  8719. key: "getTotalRootNodes",
  8720. value: function getTotalRootNodes() {
  8721. return this.scene.rootNodes.length;
  8722. }
  8723. }, {
  8724. key: "getRenderTargetRenderTime",
  8725. value: function getRenderTargetRenderTime() {
  8726. var e = this.getDrawCallTime(),
  8727. t = this.getActiveMeshEvaluationTime(),
  8728. r = this.getCameraRenderTime() - (t + e);
  8729. return this.getRTT1Time() + r;
  8730. }
  8731. }, {
  8732. key: "getRegisterBeforeRenderTime",
  8733. value: function getRegisterBeforeRenderTime() {
  8734. return this.sceneInstrumentation.registerBeforeTimeCounter.current;
  8735. }
  8736. }, {
  8737. key: "getRegisterAfterRenderTime",
  8738. value: function getRegisterAfterRenderTime() {
  8739. return this.sceneInstrumentation.registerAfterTimeCounter.current;
  8740. }
  8741. }, {
  8742. key: "getRTT1Time",
  8743. value: function getRTT1Time() {
  8744. return this.sceneInstrumentation.getRTT1TimeCounter.current;
  8745. }
  8746. }, {
  8747. key: "getRegisterBeforeRenderObserverLength",
  8748. value: function getRegisterBeforeRenderObserverLength() {
  8749. return this.scene.onBeforeRenderObservable.observers.length;
  8750. }
  8751. }, {
  8752. key: "getRegisterAfterRenderObserverLength",
  8753. value: function getRegisterAfterRenderObserverLength() {
  8754. return this.scene.onAfterRenderObservable.observers.length;
  8755. }
  8756. }, {
  8757. key: "getTotalMeshByType",
  8758. value: function getTotalMeshByType() {
  8759. var e = new Map();
  8760. return this.scene.meshes.forEach(function (t) {
  8761. e.has(t.xtype) ? e.set(t.xtype, e.get(t.xtype) + 1) : e.set(t.xtype, 1);
  8762. }), e;
  8763. }
  8764. }, {
  8765. key: "getHardwareRenderInfo",
  8766. value: function getHardwareRenderInfo() {
  8767. return {
  8768. maxTexturesUnits: this.caps.maxTexturesImageUnits,
  8769. maxVertexTextureImageUnits: this.caps.maxVertexTextureImageUnits,
  8770. maxCombinedTexturesImageUnits: this.caps.maxCombinedTexturesImageUnits,
  8771. maxTextureSize: this.caps.maxTextureSize,
  8772. maxSamples: this.caps.maxSamples,
  8773. maxCubemapTextureSize: this.caps.maxCubemapTextureSize,
  8774. maxRenderTextureSize: this.caps.maxRenderTextureSize,
  8775. maxVertexAttribs: this.caps.maxVertexAttribs,
  8776. maxVaryingVectors: this.caps.maxVaryingVectors,
  8777. maxVertexUniformVectors: this.caps.maxVertexUniformVectors,
  8778. maxFragmentUniformVectors: this.caps.maxFragmentUniformVectors,
  8779. standardDerivatives: this.caps.standardDerivatives,
  8780. supportTextureCompress: {
  8781. s3tc: this.caps.s3tc !== void 0,
  8782. s3tc_srgb: this.caps.s3tc_srgb !== void 0,
  8783. pvrtc: this.caps.pvrtc !== void 0,
  8784. etc1: this.caps.etc1 !== void 0,
  8785. etc2: this.caps.etc2 !== void 0,
  8786. astc: this.caps.astc !== void 0,
  8787. bptc: this.caps.bptc !== void 0
  8788. },
  8789. textureFloat: this.caps.textureFloat,
  8790. vertexArrayObject: this.caps.vertexArrayObject,
  8791. textureAnisotropicFilterExtension: this.caps.textureAnisotropicFilterExtension !== void 0,
  8792. maxAnisotropy: this.caps.maxAnisotropy,
  8793. instancedArrays: this.caps.instancedArrays,
  8794. uintIndices: this.caps.uintIndices,
  8795. highPrecisionShaders: this.caps.highPrecisionShaderSupported,
  8796. fragmentDepth: this.caps.fragmentDepthSupported,
  8797. textureFloatLinearFiltering: this.caps.textureFloatLinearFiltering,
  8798. renderToTextureFloat: this.caps.textureFloatRender,
  8799. textureHalfFloat: this.caps.textureHalfFloat,
  8800. textureHalfFloatLinearFiltering: this.caps.textureHalfFloatLinearFiltering,
  8801. textureHalfFloatRender: this.caps.textureHalfFloatRender,
  8802. textureLOD: this.caps.textureLOD,
  8803. drawBuffersExtension: this.caps.drawBuffersExtension,
  8804. depthTextureExtension: this.caps.depthTextureExtension,
  8805. colorBufferFloat: this.caps.colorBufferFloat,
  8806. supportTimerQuery: this.caps.timerQuery !== void 0,
  8807. canUseTimestampForTimerQuery: this.caps.canUseTimestampForTimerQuery,
  8808. supportOcclusionQuery: this.caps.supportOcclusionQuery,
  8809. multiview: this.caps.multiview,
  8810. oculusMultiview: this.caps.oculusMultiview,
  8811. maxMSAASamples: this.caps.maxMSAASamples,
  8812. blendMinMax: this.caps.blendMinMax,
  8813. canUseGLInstanceID: this.caps.canUseGLInstanceID,
  8814. canUseGLVertexID: this.caps.canUseGLVertexID,
  8815. supportComputeShaders: this.caps.supportComputeShaders,
  8816. supportSRGBBuffers: this.caps.supportSRGBBuffers,
  8817. supportStencil: this.engine.isStencilEnable
  8818. };
  8819. }
  8820. }, {
  8821. key: "getSystemInfo",
  8822. value: function getSystemInfo() {
  8823. return {
  8824. resolution: "real: " + this.engine.getRenderWidth() + "x" + this.engine.getRenderHeight() + " cavs: " + this._canvas.clientWidth + "x" + this._canvas.clientHeight,
  8825. hardwareScalingLevel: this.engine.getHardwareScalingLevel().toFixed(2).toString() + "_" + this._scenemanager.initEngineScaleNumber.toFixed(2).toString(),
  8826. driver: this.engine.getGlInfo().renderer,
  8827. vender: this.engine.getGlInfo().vendor,
  8828. version: this.engine.getGlInfo().version,
  8829. os: this._osversion
  8830. };
  8831. }
  8832. }, {
  8833. key: "getFps",
  8834. value: function getFps() {
  8835. var e = this.sceneInstrumentation.frameTimeCounter.lastSecAverage,
  8836. t = this.sceneInstrumentation.interFrameTimeCounter.lastSecAverage;
  8837. return 1e3 / (e + t);
  8838. }
  8839. }, {
  8840. key: "osVersion",
  8841. value: function osVersion() {
  8842. var e = window.navigator.userAgent;
  8843. var t;
  8844. return /iphone|ipad|ipod/gi.test(e) ? t = e.match(/OS (\d+)_(\d+)_?(\d+)?/) : /android/gi.test(e) && (t = e.match(/Android (\d+)/)), t != null && t.length > 0 ? t[0] : null;
  8845. }
  8846. }]);
  8847. return XStats;
  8848. }();
  8849. function _arrayWithHoles(arr) {
  8850. if (Array.isArray(arr)) return arr;
  8851. }
  8852. function _iterableToArrayLimit(arr, i) {
  8853. var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
  8854. if (_i == null) return;
  8855. var _arr = [];
  8856. var _n = true;
  8857. var _d = false;
  8858. var _s, _e;
  8859. try {
  8860. for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
  8861. _arr.push(_s.value);
  8862. if (i && _arr.length === i) break;
  8863. }
  8864. } catch (err) {
  8865. _d = true;
  8866. _e = err;
  8867. } finally {
  8868. try {
  8869. if (!_n && _i["return"] != null) _i["return"]();
  8870. } finally {
  8871. if (_d) throw _e;
  8872. }
  8873. }
  8874. return _arr;
  8875. }
  8876. function _nonIterableRest() {
  8877. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  8878. }
  8879. function _slicedToArray(arr, i) {
  8880. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$5(arr, i) || _nonIterableRest();
  8881. }
  8882. function _createForOfIteratorHelper$3(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$3(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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  8883. function _unsupportedIterableToArray$3(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$3(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$3(o, minLen); }
  8884. function _arrayLikeToArray$3(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; }
  8885. var XBreathPointManager = /*#__PURE__*/function () {
  8886. function XBreathPointManager(e) {
  8887. var _this = this;
  8888. _classCallCheck(this, XBreathPointManager);
  8889. E(this, "_scene");
  8890. E(this, "materialMap", new Map());
  8891. E(this, "breathPoints", new Map());
  8892. E(this, "_sceneManager");
  8893. E(this, "_allIds", new Set());
  8894. E(this, "_loopBPKeys", []);
  8895. E(this, "addBreathPoint", /*#__PURE__*/function () {
  8896. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  8897. var t, r, n, _e$spriteSheet, o, _e$spriteWidthNumber, a, _e$spriteHeightNumber, s, l, _e$rotation, u, _e$size, c, _e$width, h, _e$height, f, _e$fps, d, _e$billboardMode, _, _e$forceLeaveGround, g, _e$type, m, _e$lifeTime, v, _e$backfaceculling, y, _e$maxVisibleRegion, b, _e$skinInfo, T, I, C, _I, _I2, A, _I3, S, P, R, M, x;
  8898. return regenerator.wrap(function _callee$(_context) {
  8899. while (1) {
  8900. switch (_context.prev = _context.next) {
  8901. case 0:
  8902. t = [{
  8903. url: "https://static.xverse.cn/qqktv/texture.png"
  8904. }];
  8905. if (!(t.length <= 0)) {
  8906. _context.next = 4;
  8907. break;
  8908. }
  8909. logger$1.warn("[Engine] BreathPoint get texture list error: textureList.length <= 0"), new XBreathPointError("[Engine] BreathPoint get texture list error!");
  8910. return _context.abrupt("return");
  8911. case 4:
  8912. r = t[0], n = e.id, _e$spriteSheet = e.spriteSheet, o = _e$spriteSheet === void 0 ? r.url : _e$spriteSheet, _e$spriteWidthNumber = e.spriteWidthNumber, a = _e$spriteWidthNumber === void 0 ? 20 : _e$spriteWidthNumber, _e$spriteHeightNumber = e.spriteHeightNumber, s = _e$spriteHeightNumber === void 0 ? 1 : _e$spriteHeightNumber, l = e.position, _e$rotation = e.rotation, u = _e$rotation === void 0 ? {
  8913. pitch: -90,
  8914. yaw: 270,
  8915. roll: 0
  8916. } : _e$rotation, _e$size = e.size, c = _e$size === void 0 ? .6 : _e$size, _e$width = e.width, h = _e$width === void 0 ? -1 : _e$width, _e$height = e.height, f = _e$height === void 0 ? -1 : _e$height, _e$fps = e.fps, d = _e$fps === void 0 ? 30 : _e$fps, _e$billboardMode = e.billboardMode, _ = _e$billboardMode === void 0 ? !1 : _e$billboardMode, _e$forceLeaveGround = e.forceLeaveGround, g = _e$forceLeaveGround === void 0 ? !1 : _e$forceLeaveGround, _e$type = e.type, m = _e$type === void 0 ? "default" : _e$type, _e$lifeTime = e.lifeTime, v = _e$lifeTime === void 0 ? -1 : _e$lifeTime, _e$backfaceculling = e.backfaceculling, y = _e$backfaceculling === void 0 ? !0 : _e$backfaceculling, _e$maxVisibleRegion = e.maxVisibleRegion, b = _e$maxVisibleRegion === void 0 ? -1 : _e$maxVisibleRegion, _e$skinInfo = e.skinInfo, T = _e$skinInfo === void 0 ? "default" : _e$skinInfo;
  8917. if (!_this.breathPoints.get(n)) {
  8918. _context.next = 8;
  8919. break;
  8920. }
  8921. logger$1.warn("[Engine] Cannot add breathPoint with an existing id: [" + n + "]"), new XBreathPointError("[Engine] Cannot add breathPoint with an existing id: [" + n + "]");
  8922. return _context.abrupt("return");
  8923. case 8:
  8924. if (g) {
  8925. I = _this.castRay(new BABYLON.Vector3(l.x, l.y, l.z)) * scaleFromUE4toXverse;
  8926. I != 0 ? l.z = l.z - I + 1 : l.z = l.z + 1;
  8927. }
  8928. if (_this.materialMap.get(m)) {
  8929. _I = _this.materialMap.get(m);
  8930. _I.count = _I.count + 1, C = _I.mat;
  8931. } else {
  8932. _I2 = new Texture(o, _this._scene, !0, !0, Texture.BILINEAR_SAMPLINGMODE, null, function () {
  8933. logger$1.error("[Engine] Breathpoint create texture error."), new XBreathPointError("[Engine] Breathpoint create texture error.");
  8934. }, null, !0);
  8935. _I2.name = "TexBreathPoint_" + n, C = new StandardMaterial("MaterialBreathPoint_".concat(n), _this._scene), C.alpha = 1, C.emissiveTexture = _I2, C.backFaceCulling = y, C.diffuseTexture = _I2, C.diffuseTexture.hasAlpha = !0, C.useAlphaFromDiffuseTexture = !0, _this.materialMap.set(m, {
  8936. mat: C,
  8937. count: 1,
  8938. lastRenderTime: Date.now(),
  8939. fps: d,
  8940. spriteWidthNumber: a,
  8941. spriteHeightNumber: s,
  8942. spriteSheet: o,
  8943. texture: _I2
  8944. });
  8945. }
  8946. A = new Array(6);
  8947. for (_I3 = 0; _I3 < 6; _I3++) {
  8948. A[_I3] = new Vector4(0, 0, 0, 0);
  8949. }
  8950. A[0] = new Vector4(0, 0, 1 / a, 1 / s), A[1] = new Vector4(0, 0, 1 / a, 1 / s);
  8951. S = {};
  8952. h > 0 && f > 0 ? S = {
  8953. width: h,
  8954. height: f,
  8955. depth: .01,
  8956. faceUV: A
  8957. } : S = {
  8958. size: c,
  8959. depth: .01,
  8960. faceUV: A
  8961. };
  8962. P = BABYLON.MeshBuilder.CreateBox(n, S, _this._scene);
  8963. P.material = C;
  8964. R = new XStaticMesh({
  8965. id: n,
  8966. mesh: P,
  8967. xtype: EMeshType.XBreathPoint,
  8968. skinInfo: T
  8969. });
  8970. M = u;
  8971. _ && (P.billboardMode = Mesh.BILLBOARDMODE_ALL, R.allowMove(), M = {
  8972. pitch: 0,
  8973. yaw: 270,
  8974. roll: 0
  8975. });
  8976. x = new BreathPoint({
  8977. type: m,
  8978. mesh: R,
  8979. id: n,
  8980. position: l,
  8981. rotation: M,
  8982. mat: C,
  8983. maxVisibleRegion: b,
  8984. scene: _this._scene,
  8985. skinInfo: T
  8986. });
  8987. _this.breathPoints.set(n, x), _this._allIds.add(n), v > 0 && setTimeout(function () {
  8988. _this.clearBreathPoints(n);
  8989. }, v * 1e3);
  8990. case 22:
  8991. case "end":
  8992. return _context.stop();
  8993. }
  8994. }
  8995. }, _callee);
  8996. }));
  8997. return function (_x) {
  8998. return _ref.apply(this, arguments);
  8999. };
  9000. }());
  9001. E(this, "reg_breathpoint_update", function () {
  9002. var e = new Date().getTime();
  9003. if (_this.materialMap != null) {
  9004. var _iterator = _createForOfIteratorHelper$3(_this.materialMap),
  9005. _step;
  9006. try {
  9007. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  9008. var _step$value = _slicedToArray(_step.value, 2),
  9009. t = _step$value[0],
  9010. r = _step$value[1];
  9011. e - r.lastRenderTime > 1e3 / r.fps && (r.lastRenderTime = e, Math.abs(r.mat.diffuseTexture.uOffset - (1 - 1 / r.spriteWidthNumber)) < 1e-6 ? (r.mat.diffuseTexture.uOffset = 0, Math.abs(r.mat.diffuseTexture.vOffset - (1 - 1 / r.spriteHeightNumber)) < 1e-6 ? r.mat.diffuseTexture.vOffset = 0 : r.mat.diffuseTexture.vOffset += 1 / r.spriteHeightNumber) : r.mat.diffuseTexture.uOffset += 1 / r.spriteWidthNumber);
  9012. }
  9013. } catch (err) {
  9014. _iterator.e(err);
  9015. } finally {
  9016. _iterator.f();
  9017. }
  9018. }
  9019. });
  9020. E(this, "reg_breathpoint_autovisible", function () {
  9021. if (_this._scene.getFrameId() % 2 == 0) if (_this._loopBPKeys.length == 0) _this._loopBPKeys = Array.from(_this._allIds);else {
  9022. var _e = _this._getMainPlayerPosition();
  9023. for (var t = 0; t < 5 && _this._loopBPKeys.length > 0; ++t) {
  9024. var r = _this._loopBPKeys.pop();
  9025. if (r != null) {
  9026. var n = _this.getBreathPoint(r);
  9027. if (n != null && n.maxvisibleregion >= 0 && n.mesh.visibility == 1) {
  9028. var o = n.mesh.position;
  9029. calcDistance3DVector(_e, o) >= n.maxvisibleregion ? n == null || n.removeFromScene() : n == null || n.addToScene();
  9030. }
  9031. }
  9032. }
  9033. }
  9034. });
  9035. this._sceneManager = e, this._scene = e.Scene, this._scene.registerBeforeRender(this.reg_breathpoint_update), this._scene.registerBeforeRender(this.reg_breathpoint_autovisible);
  9036. }
  9037. _createClass(XBreathPointManager, [{
  9038. key: "setAllBreathPointVisibility",
  9039. value: function setAllBreathPointVisibility(e) {
  9040. var _iterator2 = _createForOfIteratorHelper$3(this.breathPoints.entries()),
  9041. _step2;
  9042. try {
  9043. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  9044. var _step2$value = _slicedToArray(_step2.value, 2),
  9045. t = _step2$value[0],
  9046. r = _step2$value[1];
  9047. r.toggleVisibility(e);
  9048. }
  9049. } catch (err) {
  9050. _iterator2.e(err);
  9051. } finally {
  9052. _iterator2.f();
  9053. }
  9054. }
  9055. }, {
  9056. key: "toggleBPVisibilityBySkinInfo",
  9057. value: function toggleBPVisibilityBySkinInfo(e, t) {
  9058. var _iterator3 = _createForOfIteratorHelper$3(this.breathPoints.entries()),
  9059. _step3;
  9060. try {
  9061. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  9062. var _step3$value = _slicedToArray(_step3.value, 2),
  9063. r = _step3$value[0],
  9064. n = _step3$value[1];
  9065. n.skinInfo == e && n.toggleVisibility(t);
  9066. }
  9067. } catch (err) {
  9068. _iterator3.e(err);
  9069. } finally {
  9070. _iterator3.f();
  9071. }
  9072. }
  9073. }, {
  9074. key: "toggleBPVisibilityById",
  9075. value: function toggleBPVisibilityById(e, t) {
  9076. var r = this.getBreathPoint(e);
  9077. r != null && r.toggleVisibility(t);
  9078. }
  9079. }, {
  9080. key: "getBreathPointBySkinInfo",
  9081. value: function getBreathPointBySkinInfo(e) {
  9082. var t = [];
  9083. var _iterator4 = _createForOfIteratorHelper$3(this.breathPoints.entries()),
  9084. _step4;
  9085. try {
  9086. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  9087. var _step4$value = _slicedToArray(_step4.value, 2),
  9088. r = _step4$value[0],
  9089. n = _step4$value[1];
  9090. n.skinInfo == e && t.push(n);
  9091. }
  9092. } catch (err) {
  9093. _iterator4.e(err);
  9094. } finally {
  9095. _iterator4.f();
  9096. }
  9097. return t;
  9098. }
  9099. }, {
  9100. key: "getAllBreathPoint",
  9101. value: function getAllBreathPoint() {
  9102. return this.breathPoints;
  9103. }
  9104. }, {
  9105. key: "getBreathPoint",
  9106. value: function getBreathPoint(e) {
  9107. return this.breathPoints.get(e);
  9108. }
  9109. }, {
  9110. key: "delete",
  9111. value: function _delete(e) {
  9112. var t = this.breathPoints.get(e);
  9113. if (t != null) {
  9114. t.dispose(), this._allIds.delete(e);
  9115. var r = this.materialMap.get(t._type);
  9116. r != null && (r.count = r.count - 1, r.count <= 0 && (r.count = 0, r.texture.dispose(), r.mat.dispose(!0, !0), this.materialMap.delete(t._type))), this.breathPoints.delete(e);
  9117. }
  9118. }
  9119. }, {
  9120. key: "castRay",
  9121. value: function castRay(e) {
  9122. var s;
  9123. e = ue4Position2Xverse({
  9124. x: e.x,
  9125. y: e.y,
  9126. z: e.z
  9127. });
  9128. var t = new BABYLON.Vector3(0, -1, 0),
  9129. r = new Ray(e, t, length),
  9130. n = [],
  9131. o = (s = this._sceneManager) == null ? void 0 : s.getGround({
  9132. x: e.x,
  9133. y: e.y,
  9134. z: e.z
  9135. });
  9136. var a = r.intersectsMeshes(o);
  9137. if (a.length > 0) {
  9138. var l = a[0];
  9139. if (l && l.pickedMesh) {
  9140. var u = l.distance;
  9141. t.y = 1;
  9142. var c = r.intersectsMeshes(n);
  9143. var h = 1e8;
  9144. if (c.length > 0) {
  9145. var f = c[0];
  9146. return f && f.pickedMesh && (h = -f.distance), h == 1e8 ? u : Math.abs(h) < Math.abs(u) ? h : u;
  9147. }
  9148. }
  9149. } else if (t.y = 1, a = r.intersectsMeshes(n), a.length > 0) {
  9150. var _l = a[0];
  9151. if (_l && _l.pickedMesh) return _l.distance;
  9152. }
  9153. return 0;
  9154. }
  9155. }, {
  9156. key: "changePickable",
  9157. value: function changePickable(e) {
  9158. var _iterator5 = _createForOfIteratorHelper$3(this.breathPoints.entries()),
  9159. _step5;
  9160. try {
  9161. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  9162. var _step5$value = _slicedToArray(_step5.value, 2),
  9163. t = _step5$value[0],
  9164. r = _step5$value[1];
  9165. r.changePickable(e);
  9166. }
  9167. } catch (err) {
  9168. _iterator5.e(err);
  9169. } finally {
  9170. _iterator5.f();
  9171. }
  9172. }
  9173. }, {
  9174. key: "clearBreathPoints",
  9175. value: function clearBreathPoints(e) {
  9176. logger$1.info("[Engine] clearBreathPoints: ".concat(e));
  9177. var _iterator6 = _createForOfIteratorHelper$3(this.breathPoints.entries()),
  9178. _step6;
  9179. try {
  9180. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  9181. var _step6$value = _slicedToArray(_step6.value, 2),
  9182. t = _step6$value[0],
  9183. r = _step6$value[1];
  9184. (r._type == e || r._id == e) && this.delete(r._id);
  9185. }
  9186. } catch (err) {
  9187. _iterator6.e(err);
  9188. } finally {
  9189. _iterator6.f();
  9190. }
  9191. }
  9192. }, {
  9193. key: "clearBreathPointsBySkinInfo",
  9194. value: function clearBreathPointsBySkinInfo(e) {
  9195. logger$1.info("[Engine] clearBreathPointsBySkinInfo: ".concat(e));
  9196. var _iterator7 = _createForOfIteratorHelper$3(this.breathPoints.entries()),
  9197. _step7;
  9198. try {
  9199. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  9200. var _step7$value = _slicedToArray(_step7.value, 2),
  9201. t = _step7$value[0],
  9202. r = _step7$value[1];
  9203. r.skinInfo == e && this.delete(r._id);
  9204. }
  9205. } catch (err) {
  9206. _iterator7.e(err);
  9207. } finally {
  9208. _iterator7.f();
  9209. }
  9210. }
  9211. }, {
  9212. key: "clearAllBreathPoints",
  9213. value: function clearAllBreathPoints() {
  9214. logger$1.info("[Engine] ClearAllBreathPoints");
  9215. var _iterator8 = _createForOfIteratorHelper$3(this.breathPoints.entries()),
  9216. _step8;
  9217. try {
  9218. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  9219. var _step8$value = _slicedToArray(_step8.value, 2),
  9220. e = _step8$value[0],
  9221. t = _step8$value[1];
  9222. this.delete(t._id);
  9223. }
  9224. } catch (err) {
  9225. _iterator8.e(err);
  9226. } finally {
  9227. _iterator8.f();
  9228. }
  9229. }
  9230. }, {
  9231. key: "_getMainPlayerPosition",
  9232. value: function _getMainPlayerPosition() {
  9233. var r;
  9234. var e = this._sceneManager.cameraComponent.MainCamera.position,
  9235. t = this._sceneManager.avatarComponent.getMainAvatar();
  9236. if (t != null && t != null) {
  9237. var n = (r = t == null ? void 0 : t.rootNode) == null ? void 0 : r.position;
  9238. if (n != null) return n;
  9239. }
  9240. return e;
  9241. }
  9242. }, {
  9243. key: "changeBreathPointPose",
  9244. value: function changeBreathPointPose(e, t, r) {
  9245. var n = new BABYLON.Vector3(e.position.x, e.position.y, e.position.z);
  9246. if (this.breathPoints.get(r) != null) {
  9247. logger$1.info("[Engine] changeBreathPointPose, id:".concat(r));
  9248. var o = this.breathPoints.get(r),
  9249. a = o.mesh.position;
  9250. var s = a.subtract(n);
  9251. s = BABYLON.Vector3.Normalize(s);
  9252. var l = BABYLON.Vector3.Distance(a, n),
  9253. u = new Ray(n, s, l),
  9254. c = this._scene.multiPickWithRay(u);
  9255. if (c) {
  9256. for (var h = 0; h < c.length; h++) {
  9257. if (c[h].pickedMesh != null && t.mesh.name.indexOf(c[h].pickedMesh.name) >= 0) {
  9258. var f = c[h].pickedPoint;
  9259. o.mesh.position = n.add(f.subtract(n).scale(.99)), this.breathPoints.set(r, o);
  9260. }
  9261. }
  9262. }
  9263. } else logger$1.warn("[Engine] changeBreathPointPose, id:".concat(r, " is not existing!"));
  9264. }
  9265. }]);
  9266. return XBreathPointManager;
  9267. }();
  9268. function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(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; } } }; }
  9269. function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(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$2(o, minLen); }
  9270. function _arrayLikeToArray$2(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; }
  9271. var XDecalManager = /*#__PURE__*/function () {
  9272. function XDecalManager(e) {
  9273. _classCallCheck(this, XDecalManager);
  9274. E(this, "scene");
  9275. E(this, "_decal");
  9276. E(this, "_mat");
  9277. E(this, "_sharedMat");
  9278. E(this, "_scenemanager");
  9279. this._decal = new Map(), this._mat = new Map(), this._sharedMat = new Map(), this._scenemanager = e, this.scene = e.Scene;
  9280. }
  9281. _createClass(XDecalManager, [{
  9282. key: "decals",
  9283. get: function get() {
  9284. return Array.from(this._decal.values());
  9285. }
  9286. }, {
  9287. key: "getMesh",
  9288. value: function getMesh() {
  9289. return this._decal;
  9290. }
  9291. }, {
  9292. key: "addDecal",
  9293. value: function () {
  9294. var _addDecal = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  9295. var _this = this;
  9296. var t, r, _e$skinInfo, n;
  9297. return regenerator.wrap(function _callee$(_context) {
  9298. while (1) {
  9299. switch (_context.prev = _context.next) {
  9300. case 0:
  9301. t = e.id, r = e.meshPath, _e$skinInfo = e.skinInfo, n = _e$skinInfo === void 0 ? "default" : _e$skinInfo;
  9302. return _context.abrupt("return", this._decal.get(t) ? (logger.warn("[Engine] Cannot add decal with an existing id: [".concat(t, "], meshPath: ").concat(r, ", skinInfo:").concat(n)), Promise.resolve(!0)) : (logger.info("[Engine] addDecal wiht id:[".concat(t, "], meshPath: ").concat(r, ", skinInfo:").concat(n)), new Promise(function (o, a) {
  9303. return _this._scenemanager.urlTransformer(r).then(function (s) {
  9304. return new Promise(function (l, u) {
  9305. if (_this._decal.get(t)) l(!0);else {
  9306. var c = new XDecal({
  9307. id: t,
  9308. scene: _this.scene,
  9309. meshPath: s,
  9310. skinInfo: n
  9311. });
  9312. _this._decal.set(t, c), c.loadModel().then(function () {
  9313. l(!0);
  9314. }).catch(function (h) {
  9315. logger.error("[Engine] addDecal Error! id: [".concat(t, "], meshpath:").concat(r, ", skin: ").concat(n, ". ").concat(h)), u(new XDecalError("[Engine] addDecal Error! id: [".concat(t, "], meshpath:").concat(r, ", skin: ").concat(n, ". ").concat(h)));
  9316. });
  9317. }
  9318. });
  9319. }).then(function (s) {
  9320. s == !0 ? o(!0) : a(!1);
  9321. }).catch(function (s) {
  9322. logger.error("[Engine] Add Decal error! id: [".concat(t, "], meshpath:").concat(r, ", skin:").concat(n, ". ").concat(s)), a(new XDecalError("[Engine] addDecal error! id: [".concat(t, "], meshpath:").concat(r, ", skin:").concat(n, ". ").concat(s)));
  9323. });
  9324. })));
  9325. case 2:
  9326. case "end":
  9327. return _context.stop();
  9328. }
  9329. }
  9330. }, _callee, this);
  9331. }));
  9332. function addDecal(_x) {
  9333. return _addDecal.apply(this, arguments);
  9334. }
  9335. return addDecal;
  9336. }()
  9337. }, {
  9338. key: "setDecalTexture",
  9339. value: function setDecalTexture(e) {
  9340. var _this2 = this;
  9341. var t = e.id,
  9342. r = e.buffer,
  9343. _e$isDynamic = e.isDynamic,
  9344. n = _e$isDynamic === void 0 ? !1 : _e$isDynamic,
  9345. _e$width = e.width,
  9346. o = _e$width === void 0 ? 1100 : _e$width,
  9347. _e$height = e.height,
  9348. a = _e$height === void 0 ? 25 : _e$height,
  9349. _e$slots = e.slots,
  9350. s = _e$slots === void 0 ? 1 : _e$slots,
  9351. _e$visibleSlots = e.visibleSlots,
  9352. l = _e$visibleSlots === void 0 ? 1 : _e$visibleSlots,
  9353. u = !0;
  9354. return logger.info("[Engine] setDecalTexture wiht id:[".concat(t, "]")), new Promise(function (c, h) {
  9355. var f = _this2._decal.get(t);
  9356. if (f != null) {
  9357. if (_this2._mat.get(t) != null) _this2.changeDecalTexture({
  9358. id: t,
  9359. buffer: r,
  9360. isUrl: u,
  9361. isDynamic: n,
  9362. width: o,
  9363. height: a,
  9364. slots: s,
  9365. visibleSlots: l
  9366. }), c(!0);else {
  9367. var d = new XDecalMaterial(t, _this2.scene);
  9368. d.setTexture(r, u, n, o, a, s, l).then(function () {
  9369. f.setMat(d.getMat()), _this2._decal.set(t, f), _this2._mat.set(t, d), c(!0);
  9370. }).catch(function (_) {
  9371. logger.error("[Engine] setDecalTexture Error! " + _), h(new XDecalTextureError("[Engine] decal set texture error! ".concat(_)));
  9372. });
  9373. }
  9374. } else logger.error("[Engine] Error! decal id: [" + t + "] is not find!"), h(new XDecalTextureError("[Engine] decal id: [".concat(t, "] is not find!")));
  9375. });
  9376. }
  9377. }, {
  9378. key: "shareDecal",
  9379. value: function () {
  9380. var _shareDecal = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  9381. var _this3 = this;
  9382. var t, r, n, _e$skinInfo2, o;
  9383. return regenerator.wrap(function _callee2$(_context2) {
  9384. while (1) {
  9385. switch (_context2.prev = _context2.next) {
  9386. case 0:
  9387. t = e.idTar, r = e.meshPath, n = e.idSrc, _e$skinInfo2 = e.skinInfo, o = _e$skinInfo2 === void 0 ? "default" : _e$skinInfo2;
  9388. return _context2.abrupt("return", this._decal.has(n) && !this._decal.has(t) && this._mat.has(n) && !this._mat.has(t) ? (logger.info("[Engine] shareDecal wiht idTar:[".concat(t, "], idSrc:[").concat(n, "], skinInfo: ").concat(o, ", meshPath: ").concat(r)), new Promise(function (a, s) {
  9389. return _this3._scenemanager.urlTransformer(r).then(function (l) {
  9390. var u = new XDecal({
  9391. id: t,
  9392. scene: _this3.scene,
  9393. meshPath: l,
  9394. skinInfo: o
  9395. }),
  9396. c = _this3._mat.get(n);
  9397. c != null && (u.setMat(c.getMat()), u.sourceMatId = n, _this3._decal.set(t, u), _this3.addSharedMatCount(n)), a(!0);
  9398. }).catch(function (l) {
  9399. s(new XDecalError("[Engine] decal shareDecal error! ".concat(l)));
  9400. });
  9401. })) : (logger.error("[Engine] shareDecal Error. idSrc: [".concat(n, "] not exist! or idTar: [").concat(t, "] exists!")), Promise.reject("[Engine] shareDecal Error. idSrc: [".concat(n, "] not exist! or idTar: [").concat(t, "] exists!"))));
  9402. case 2:
  9403. case "end":
  9404. return _context2.stop();
  9405. }
  9406. }
  9407. }, _callee2, this);
  9408. }));
  9409. function shareDecal(_x2) {
  9410. return _shareDecal.apply(this, arguments);
  9411. }
  9412. return shareDecal;
  9413. }()
  9414. }, {
  9415. key: "changeDecalModel",
  9416. value: function () {
  9417. var _changeDecalModel = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  9418. var _this4 = this;
  9419. var t, r, n;
  9420. return regenerator.wrap(function _callee3$(_context3) {
  9421. while (1) {
  9422. switch (_context3.prev = _context3.next) {
  9423. case 0:
  9424. t = e.id, r = e.meshPath, n = this._decal.get(t);
  9425. return _context3.abrupt("return", new Promise(function (o, a) {
  9426. return n != null ? (logger.info("[Engine] changeDecalModel id:".concat(t)), n.changeModel(r).then(function () {
  9427. _this4._decal.set(t, n), o(!0);
  9428. })) : (logger.warn("[Engine] changeDecalModel id:".concat(t, " is not exist")), a("[Engine] changeDecalModel id:".concat(t, " is not exist")));
  9429. }));
  9430. case 2:
  9431. case "end":
  9432. return _context3.stop();
  9433. }
  9434. }
  9435. }, _callee3, this);
  9436. }));
  9437. function changeDecalModel(_x3) {
  9438. return _changeDecalModel.apply(this, arguments);
  9439. }
  9440. return changeDecalModel;
  9441. }()
  9442. }, {
  9443. key: "changeDecalTexture",
  9444. value: function changeDecalTexture(e) {
  9445. var t = e.id,
  9446. r = e.buffer,
  9447. _e$isUrl = e.isUrl,
  9448. n = _e$isUrl === void 0 ? !1 : _e$isUrl,
  9449. _e$isDynamic2 = e.isDynamic,
  9450. o = _e$isDynamic2 === void 0 ? !1 : _e$isDynamic2,
  9451. _e$width2 = e.width,
  9452. a = _e$width2 === void 0 ? 1110 : _e$width2,
  9453. _e$height2 = e.height,
  9454. s = _e$height2 === void 0 ? 25 : _e$height2,
  9455. _e$slots2 = e.slots,
  9456. l = _e$slots2 === void 0 ? 1 : _e$slots2,
  9457. _e$visibleSlots2 = e.visibleSlots,
  9458. u = _e$visibleSlots2 === void 0 ? 1 : _e$visibleSlots2,
  9459. c = this._mat.get(t);
  9460. c != null && this._decal.has(t) ? (c.changeTexture(r, n, o, a, s, l, u), this._mat.set(t, c)) : logger.error("[Engine] changeDecalTexture Error. id:".concat(t, " is not exist"));
  9461. }
  9462. }, {
  9463. key: "deleteDecal",
  9464. value: function deleteDecal(e) {
  9465. var t, r;
  9466. if (this._decal.has(e)) {
  9467. var n = this._decal.get(e);
  9468. n != null && n.cleanMesh(), this._sharedMat.get(e) != null ? this.minusSharedMatCount(e) : this._mat.get(e) != null ? ((t = this._mat.get(e)) == null || t.cleanTexture(), this._mat.delete(e)) : ((r = n.sourceMatId) == null ? void 0 : r.length) > 0 && this.minusSharedMatCount(n.sourceMatId), this._decal.delete(e);
  9469. }
  9470. }
  9471. }, {
  9472. key: "deleteDecalBySkinInfo",
  9473. value: function deleteDecalBySkinInfo(e) {
  9474. var _iterator = _createForOfIteratorHelper$2(this._decal.entries()),
  9475. _step;
  9476. try {
  9477. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  9478. var _step$value = _slicedToArray(_step.value, 2),
  9479. t = _step$value[0],
  9480. r = _step$value[1];
  9481. r.skinInfo == e && this.deleteDecal(t);
  9482. }
  9483. } catch (err) {
  9484. _iterator.e(err);
  9485. } finally {
  9486. _iterator.f();
  9487. }
  9488. }
  9489. }, {
  9490. key: "addSharedMatCount",
  9491. value: function addSharedMatCount(e) {
  9492. var t = this._sharedMat.get(e);
  9493. t != null ? this._sharedMat.set(e, t + 1) : this._sharedMat.set(e, 1);
  9494. }
  9495. }, {
  9496. key: "minusSharedMatCount",
  9497. value: function minusSharedMatCount(e) {
  9498. var r;
  9499. var t = this._sharedMat.get(e);
  9500. t != null && (this._sharedMat.set(e, t - 1), t == 0 && (this._sharedMat.delete(e), (r = this._mat.get(e)) == null || r.cleanTexture(), this._mat.delete(e)));
  9501. }
  9502. }, {
  9503. key: "toggle",
  9504. value: function toggle(e, t) {
  9505. var r = this._decal.get(e);
  9506. r == null || r.toggle(t);
  9507. }
  9508. }, {
  9509. key: "toggleDecalBySkinInfo",
  9510. value: function toggleDecalBySkinInfo(e, t) {
  9511. var _iterator2 = _createForOfIteratorHelper$2(this._decal.entries()),
  9512. _step2;
  9513. try {
  9514. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  9515. var _step2$value = _slicedToArray(_step2.value, 2),
  9516. r = _step2$value[0],
  9517. n = _step2$value[1];
  9518. n.skinInfo == e && n.toggle(t);
  9519. }
  9520. } catch (err) {
  9521. _iterator2.e(err);
  9522. } finally {
  9523. _iterator2.f();
  9524. }
  9525. }
  9526. }, {
  9527. key: "updateTexAsWords",
  9528. value: function updateTexAsWords(e, t) {
  9529. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  9530. var _r$clearArea = r.clearArea,
  9531. n = _r$clearArea === void 0 ? !0 : _r$clearArea,
  9532. _r$w = r.w,
  9533. o = _r$w === void 0 ? 480 : _r$w,
  9534. _r$h = r.h,
  9535. a = _r$h === void 0 ? 480 : _r$h,
  9536. _r$y = r.y,
  9537. s = _r$y === void 0 ? a / 2 : _r$y,
  9538. _r$fontsize = r.fontsize,
  9539. l = _r$fontsize === void 0 ? 70 : _r$fontsize,
  9540. _r$slots = r.slots,
  9541. u = _r$slots === void 0 ? 1 : _r$slots,
  9542. _r$visibleSlots = r.visibleSlots,
  9543. c = _r$visibleSlots === void 0 ? 1 : _r$visibleSlots,
  9544. _r$font = r.font,
  9545. h = _r$font === void 0 ? "black-body" : _r$font,
  9546. _r$color = r.color,
  9547. f = _r$color === void 0 ? "white" : _r$color,
  9548. _r$fontweight = r.fontweight,
  9549. d = _r$fontweight === void 0 ? 100 : _r$fontweight;
  9550. var _r$x = r.x,
  9551. _ = _r$x === void 0 ? o / 2 : _r$x;
  9552. var g = this._mat.get(e);
  9553. if (g) {
  9554. _ == -1 && (_ = (g.getUOffset() + c / u) % 1 * o * u);
  9555. var v = g.getMat().diffuseTexture,
  9556. y = v.getContext();
  9557. n && y.clearRect(_ - o / 2, s - a / 2, o, a), y.textAlign = "center", y.textBaseline = "middle", v.drawText(t, _, s, d + " " + l + "px " + h, f, "transparent", !0), v.hasAlpha = !0, v.update();
  9558. }
  9559. }
  9560. }, {
  9561. key: "updateTexAsImg",
  9562. value: function () {
  9563. var _updateTexAsImg = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e, t) {
  9564. var _this5 = this;
  9565. var r,
  9566. _r$clearArea2,
  9567. n,
  9568. _r$w2,
  9569. o,
  9570. _r$h2,
  9571. a,
  9572. _r$x2,
  9573. s,
  9574. _r$y2,
  9575. l,
  9576. _r$clearW,
  9577. u,
  9578. _r$clearH,
  9579. c,
  9580. _args4 = arguments;
  9581. return regenerator.wrap(function _callee4$(_context4) {
  9582. while (1) {
  9583. switch (_context4.prev = _context4.next) {
  9584. case 0:
  9585. r = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
  9586. _r$clearArea2 = r.clearArea, n = _r$clearArea2 === void 0 ? !0 : _r$clearArea2, _r$w2 = r.w, o = _r$w2 === void 0 ? 480 : _r$w2, _r$h2 = r.h, a = _r$h2 === void 0 ? 480 : _r$h2, _r$x2 = r.x, s = _r$x2 === void 0 ? o / 2 : _r$x2, _r$y2 = r.y, l = _r$y2 === void 0 ? a / 2 : _r$y2, _r$clearW = r.clearW, u = _r$clearW === void 0 ? o : _r$clearW, _r$clearH = r.clearH, c = _r$clearH === void 0 ? a : _r$clearH;
  9587. return _context4.abrupt("return", t == null || t == null || t == "" ? (logger.error("[Engine] updateTexAsImg Error. id: [".concat(e, "], newBuffer is Null or \"\"!")), Promise.reject(new XDecalError("[Engine] updateTexAsImg Error. id: [".concat(e, "], newBuffer is Null or \"\"!")))) : new Promise(function (h, f) {
  9588. return _this5._scenemanager.urlTransformer(t).then(function (d) {
  9589. return new Promise(function (_, g) {
  9590. var m = _this5._mat.get(e);
  9591. if (m) {
  9592. var y = m.getMat().diffuseTexture;
  9593. if (typeof t == "string") {
  9594. var b = new Image();
  9595. b.crossOrigin = "anonymous", b.src = d, b.onload = function () {
  9596. var T = y.getContext();
  9597. n && T.clearRect(s - u / 2, l - c / 2, u, c), T.drawImage(b, s - o / 2, l - a / 2, o, a), y.update(), _(!0);
  9598. }, b.onerror = function () {
  9599. logger.error("[Engine] updateTexAsImg Error.newImg load error. id: [".concat(e, "], decalMat is Null or undefined!")), g(new XDecalError("[Engine] updateTexAsImg Error. id: [".concat(e, "], decalMat is Null or undefined!")));
  9600. };
  9601. } else logger.error("[Engine] updateTexAsImg Error. id: [".concat(e, "], Buffer is not string!")), g(new XDecalError("[Engine] updateTexAsImg Error. id: [".concat(e, "], Buffer is not string!")));
  9602. } else logger.error("[Engine] updateTexAsImg Error. id: [".concat(e, "], decalMat is Null or undefined!")), g(new XDecalError("[Engine] updateTexAsImg Error. id: [".concat(e, "], decalMat is Null or undefined!")));
  9603. }).then(function (_) {
  9604. _ == !0 ? h(!0) : (logger.error("[Engine] updateTexAsImg Error. id: [".concat(e, "] !")), f(new XDecalError("[Engine] updateTexAsImg error! id: [".concat(e, "]"))));
  9605. }).catch(function (_) {
  9606. logger.error("[Engine] updateTexAsImg Error. id: [".concat(e, "]. ").concat(_));
  9607. });
  9608. });
  9609. }));
  9610. case 3:
  9611. case "end":
  9612. return _context4.stop();
  9613. }
  9614. }
  9615. }, _callee4);
  9616. }));
  9617. function updateTexAsImg(_x4, _x5) {
  9618. return _updateTexAsImg.apply(this, arguments);
  9619. }
  9620. return updateTexAsImg;
  9621. }()
  9622. }, {
  9623. key: "startAnime",
  9624. value: function startAnime(e, t) {
  9625. logger.info("[Engine] Decal Start Anime. [".concat(e, "]"));
  9626. var _t$speed = t.speed,
  9627. r = _t$speed === void 0 ? .001 : _t$speed,
  9628. n = t.callback,
  9629. o = this._mat.get(e);
  9630. o ? (o.do_animation(r), n && o.uOffsetObserverable.add(n)) : (logger.error("[Engine] startAnime Error. id: [".concat(e, "] is not exist!")), new XDecalError("[Engine] startAnime Error. id: [".concat(e, "] is not exist!")));
  9631. }
  9632. }]);
  9633. return XDecalManager;
  9634. }();
  9635. var PoolObject = /*#__PURE__*/function () {
  9636. function PoolObject(e, t, r) {
  9637. var n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !0;
  9638. _classCallCheck(this, PoolObject);
  9639. E(this, "data");
  9640. E(this, "nextFree");
  9641. E(this, "previousFree");
  9642. E(this, "free");
  9643. this.data = e, this.nextFree = t, this.previousFree = r, this.free = n;
  9644. }
  9645. _createClass(PoolObject, [{
  9646. key: "dispose",
  9647. value: function dispose() {
  9648. this.data && this.data instanceof Mesh && this.data.dispose(!0, !0), this.previousFree = null, this.nextFree = null, this.data = null;
  9649. }
  9650. }]);
  9651. return PoolObject;
  9652. }();
  9653. var Pool = /*#__PURE__*/function () {
  9654. function Pool(e, t, r, n) {
  9655. _classCallCheck(this, Pool);
  9656. this.lastFree = null;
  9657. this.nextFree = null;
  9658. this._pool = [], this.objCreator = e, this.objReseter = t;
  9659. for (var _len = arguments.length, o = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++) {
  9660. o[_key - 4] = arguments[_key];
  9661. }
  9662. for (var a = 0; a < n; a++) {
  9663. this.addNewObject(this.newPoolObject.apply(this, o));
  9664. }
  9665. this.capacity = r;
  9666. }
  9667. _createClass(Pool, [{
  9668. key: "addNewObject",
  9669. value: function addNewObject(e) {
  9670. return this._pool.push(e), this.release(e), e;
  9671. }
  9672. }, {
  9673. key: "release",
  9674. value: function release(e) {
  9675. e.free = !0, e.nextFree = null, e.previousFree = this.lastFree, this.lastFree ? this.lastFree.nextFree = e : this.nextFree = e, this.lastFree = e, this.objReseter(e);
  9676. }
  9677. }, {
  9678. key: "getFree",
  9679. value: function getFree() {
  9680. var t = this.nextFree ? this.nextFree : this.addNewObject(this.newPoolObject.apply(this, arguments));
  9681. return t.free = !1, this.nextFree = t.nextFree, this.nextFree || (this.lastFree = null), t;
  9682. }
  9683. }, {
  9684. key: "newPoolObject",
  9685. value: function newPoolObject() {
  9686. var t = this.objCreator.apply(this, arguments);
  9687. return new PoolObject(t, this.nextFree, this.lastFree);
  9688. }
  9689. }, {
  9690. key: "releaseAll",
  9691. value: function releaseAll() {
  9692. var _this = this;
  9693. this._pool.forEach(function (e) {
  9694. return _this.release(e);
  9695. });
  9696. }
  9697. }, {
  9698. key: "clean",
  9699. value: function clean() {
  9700. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  9701. var r = this.nextFree;
  9702. if (!r) return;
  9703. var n = 0;
  9704. for (; r;) {
  9705. n += 1, r = r.nextFree;
  9706. }
  9707. var o = !1;
  9708. if (n > e && this._pool.length > this.capacity && (o = !0), o) for (r = this.nextFree; r;) {
  9709. r.free = !1, this.nextFree = r.nextFree;
  9710. var a = this._pool.indexOf(r);
  9711. this._pool.splice(a, 1), this.nextFree || (this.lastFree = null), r == null || r.dispose(), r = this.nextFree;
  9712. }
  9713. }
  9714. }]);
  9715. return Pool;
  9716. }();
  9717. var BillboardStatus = {
  9718. SHOW: 1,
  9719. HIDE: 0,
  9720. DISPOSE: -1
  9721. };
  9722. 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; } } }; }
  9723. 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); }
  9724. 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; }
  9725. var XAvatarManager = /*#__PURE__*/function () {
  9726. function XAvatarManager(e) {
  9727. var _this = this;
  9728. _classCallCheck(this, XAvatarManager);
  9729. this.characterMap = new Map();
  9730. this.curAnimList = [];
  9731. this.extraComps = new Map();
  9732. this._mainUser = null;
  9733. this._lodSettings = null;
  9734. this.maxBillBoardDist = 0;
  9735. this.maxAvatarNum = 0;
  9736. this.currentLODUsers = [];
  9737. this.bboxMeshPool = null;
  9738. this._distLevels = [];
  9739. this._maxLODUsers = [];
  9740. this._cullingDistance = 0;
  9741. this._maxDistRange = null;
  9742. this._delayTime = 100;
  9743. this._queueLength = -1;
  9744. this._queue = [];
  9745. this._processList = [];
  9746. this._process = null;
  9747. this._updateLoopObserver = null;
  9748. this._avatarInDistance = [];
  9749. this._renderedAvatar = [];
  9750. this._enableNickname = !0;
  9751. this._tickObserver = null;
  9752. this._tickInterval = null;
  9753. this._defaultAnims = null;
  9754. this._tickDispose = 0;
  9755. this._disposeTime = 100;
  9756. this.avatarLoader = avatarLoader;
  9757. this._scene = e.mainScene;
  9758. this._sceneManager = e;
  9759. this.initAvatarMap();
  9760. this._initSettings();
  9761. this._maxDistRange = this._distLevels[this._distLevels.length - 1], this.bboxMeshPool = new Pool(this.createBboxAsset, this.resetBboxAsset, 0, this.maxAvatarNum, this._sceneManager.Scene, 0, 0, 0), this._tickInterval = 250;
  9762. var t = 0;
  9763. this._tickObserver = this._scene.onAfterRenderObservable.add(function () {
  9764. t += 1, t == _this._tickInterval && (_this.tick(), t = 0);
  9765. });
  9766. }
  9767. _createClass(XAvatarManager, [{
  9768. key: "tick",
  9769. value: function tick() {
  9770. this.bboxMeshPool.clean(0);
  9771. }
  9772. }, {
  9773. key: "createBboxAsset",
  9774. value: function createBboxAsset(e, t, r, n) {
  9775. return BABYLON.MeshBuilder.CreateBox("avatarBbox", {
  9776. width: t,
  9777. height: r,
  9778. depth: n
  9779. }, e);
  9780. }
  9781. }, {
  9782. key: "resetBboxAsset",
  9783. value: function resetBboxAsset(e) {
  9784. var t = e.data;
  9785. return t.setEnabled(!1), t.isPickable = !1, e;
  9786. }
  9787. }, {
  9788. key: "_initSettings",
  9789. value: function _initSettings() {
  9790. this._defaultAnims = avatarSetting.defaultIdle, this._lodSettings = avatarSetting.lod, this._distLevels = avatarSetting.lod.map(function (e) {
  9791. return e.dist;
  9792. }), this._maxLODUsers = avatarSetting.lod.map(function (e) {
  9793. return e.quota;
  9794. }), this.currentLODUsers = new Array(this._distLevels.length).fill(0), this.maxAvatarNum = avatarSetting.maxAvatarNum, this.maxBillBoardDist = avatarSetting.maxBillBoardDist, this._cullingDistance = avatarSetting.cullingDistance;
  9795. }
  9796. }, {
  9797. key: "maxRenderNum",
  9798. value: function maxRenderNum() {
  9799. var e = 0;
  9800. return this._maxLODUsers.forEach(function (t) {
  9801. e += t;
  9802. }), e;
  9803. }
  9804. }, {
  9805. key: "curRenderNum",
  9806. value: function curRenderNum() {
  9807. var e = 0;
  9808. return this.currentLODUsers.forEach(function (t) {
  9809. e += t;
  9810. }), e;
  9811. }
  9812. }, {
  9813. key: "setLoDLevels",
  9814. value: function setLoDLevels(e) {
  9815. this._distLevels = e;
  9816. }
  9817. }, {
  9818. key: "cullingDistance",
  9819. get: function get() {
  9820. return this._cullingDistance;
  9821. },
  9822. set: function set(e) {
  9823. this._cullingDistance = e;
  9824. }
  9825. }, {
  9826. key: "getLoDLevels",
  9827. value: function getLoDLevels() {
  9828. return this._distLevels;
  9829. }
  9830. }, {
  9831. key: "setLodUserLimits",
  9832. value: function setLodUserLimits(e, t) {
  9833. this._maxLODUsers.length > e && (this._maxLODUsers[e] = t);
  9834. }
  9835. }, {
  9836. key: "setLodDist",
  9837. value: function setLodDist(e, t) {
  9838. this._distLevels[e] = t;
  9839. }
  9840. }, {
  9841. key: "setMaxDistRange",
  9842. value: function setMaxDistRange(e) {
  9843. this._maxDistRange = e, this._distLevels[this._distLevels.length - 1] = e;
  9844. }
  9845. }, {
  9846. key: "scene",
  9847. get: function get() {
  9848. return this._scene;
  9849. }
  9850. }, {
  9851. key: "setMainAvatar",
  9852. value: function setMainAvatar(e) {
  9853. var t;
  9854. this._mainUser = (t = this.characterMap.get(0)) == null ? void 0 : t.get(e);
  9855. }
  9856. }, {
  9857. key: "getMainAvatar",
  9858. value: function getMainAvatar() {
  9859. return this._mainUser;
  9860. }
  9861. }, {
  9862. key: "enableAllNickname",
  9863. value: function enableAllNickname(e) {
  9864. var _this2 = this;
  9865. return this.characterMap.forEach(function (t, r) {
  9866. r != 0 && t.forEach(function (n, o) {
  9867. _this2._updateBillboardStatus(n, e ? BillboardStatus.SHOW : BillboardStatus.HIDE);
  9868. });
  9869. }), this._enableNickname = e;
  9870. }
  9871. }, {
  9872. key: "getAvatarById",
  9873. value: function getAvatarById(e) {
  9874. var t;
  9875. return this.characterMap.forEach(function (r, n) {
  9876. r.get(e) && (t = r.get(e));
  9877. }), t;
  9878. }
  9879. }, {
  9880. key: "getAvatarNums",
  9881. value: function getAvatarNums() {
  9882. var e = 0;
  9883. return this.characterMap.forEach(function (t, r) {
  9884. e += t.size;
  9885. }), e;
  9886. }
  9887. }, {
  9888. key: "registerAvatar",
  9889. value: function registerAvatar(e) {
  9890. this.characterMap.get(e.priority).set(e.id, e);
  9891. }
  9892. }, {
  9893. key: "unregisterAvatar",
  9894. value: function unregisterAvatar(e) {
  9895. this.characterMap.get(e.priority).delete(e.id);
  9896. }
  9897. }, {
  9898. key: "initAvatarMap",
  9899. value: function initAvatarMap() {
  9900. this.characterMap.set(0, new Map()), this.characterMap.set(1, new Map()), this.characterMap.set(2, new Map()), this.characterMap.set(3, new Map()), this.characterMap.set(4, new Map()), this.characterMap.set(5, new Map());
  9901. }
  9902. }, {
  9903. key: "loadAvatar",
  9904. value: function loadAvatar(_ref) {
  9905. var _this3 = this;
  9906. var e = _ref.id,
  9907. t = _ref.avatarType,
  9908. r = _ref.priority,
  9909. n = _ref.avatarManager,
  9910. o = _ref.assets,
  9911. a = _ref.status;
  9912. return new Promise(function (s, l) {
  9913. if (_this3.getAvatarById(e)) return l(new DuplicateAvatarIDError("[Engine] cannot init avatar with the same id = ".concat(e)));
  9914. if (_this3.getAvatarNums() > _this3.maxAvatarNum) return l(new ExceedMaxAvatarNumError("[Engine] \u8D85\u51FA\u6700\u5927\u89D2\u8272\u9650\u5236 ".concat(_this3.maxAvatarNum)));
  9915. var u = new XAvatar({
  9916. id: e,
  9917. avatarType: t,
  9918. priority: r,
  9919. avatarManager: n,
  9920. assets: o,
  9921. status: a
  9922. });
  9923. if (_this3.registerAvatar(u), r == 0) _this3.setMainAvatar(u.id), _this3.addAvatarToScene(u, 0).then(function (c) {
  9924. return logger$1.debug("[Engine] avatar ".concat(u.id, " has been added to scene")), c ? (_this3._updateBillboardStatus(c, BillboardStatus.SHOW), setTimeout(function () {
  9925. _this3.launchProcessLoadingLoop();
  9926. }, _this3._delayTime), s(c)) : (u.removeAvatarFromScene(), l(new AvatarAssetLoadingError()));
  9927. }).catch(function (c) {
  9928. return u.removeAvatarFromScene(), l(new AvatarAssetLoadingError(c));
  9929. });else return s(u);
  9930. });
  9931. }
  9932. }, {
  9933. key: "deleteAvatar",
  9934. value: function deleteAvatar(e) {
  9935. return e.isRender ? (e.removeAvatarFromScene(), this.currentLODUsers[e.distLevel]--) : e.bbComponent.disposeBillBoard(e), this._processList = this._processList.filter(function (t) {
  9936. return t.id !== e.id;
  9937. }), this.unregisterAvatar(e), e.rootNode && (e.rootNode.dispose(), e.rootNode = void 0), e.bbComponent.bbox && e.bbComponent.bbox.dispose(), e.removeObserver(), e;
  9938. }
  9939. }, {
  9940. key: "_checkLODLevel",
  9941. value: function _checkLODLevel(e) {
  9942. if (e < this._distLevels[0]) return 0;
  9943. for (var t = 1; t < this._distLevels.length; ++t) {
  9944. if (e >= this._distLevels[t - 1] && e < this._distLevels[t]) return t;
  9945. }
  9946. return this._distLevels.length - 1;
  9947. }
  9948. }, {
  9949. key: "sceneManager",
  9950. get: function get() {
  9951. return this._sceneManager;
  9952. }
  9953. }, {
  9954. key: "launchProcessLoadingLoop",
  9955. value: function launchProcessLoadingLoop() {
  9956. this._updateAvatarStatus();
  9957. }
  9958. }, {
  9959. key: "stopProcessLoadingLoop",
  9960. value: function stopProcessLoadingLoop() {
  9961. var e;
  9962. this._updateLoopObserver && ((e = this._scene) == null || e.onBeforeRenderObservable.remove(this._updateLoopObserver));
  9963. }
  9964. }, {
  9965. key: "_distToMain",
  9966. value: function _distToMain(e) {
  9967. var n;
  9968. var t = (n = this._mainUser) == null ? void 0 : n.position,
  9969. r = e.position;
  9970. if (r && t) {
  9971. var o = this.sceneManager.cameraComponent.MainCamera.getFrontPosition(1).subtract(this.sceneManager.cameraComponent.MainCamera.position).normalize(),
  9972. a = e.rootNode.position.subtract(this.sceneManager.cameraComponent.MainCamera.position).normalize();
  9973. var s = 1;
  9974. if (o && a) {
  9975. var l = a.multiply(o);
  9976. s = Math.acos(l.x + l.y + l.z) < this.sceneManager.cameraComponent.MainCamera.fov / 2 ? 1 : 1e11;
  9977. }
  9978. return calcDistance3D(t, r) * s;
  9979. } else return logger$1.warn("user position or camera position is not correct!"), 1e11;
  9980. }
  9981. }, {
  9982. key: "_distToCamera",
  9983. value: function _distToCamera(e) {
  9984. var n;
  9985. var t = (n = this._sceneManager) == null ? void 0 : n.cameraComponent.getCameraPose().position,
  9986. r = e.position;
  9987. return r && t ? calcDistance3D(t, r) : (logger$1.warn("user position or camera position is not correct!"), 1e11);
  9988. }
  9989. }, {
  9990. key: "showAll",
  9991. value: function showAll(e) {
  9992. this.characterMap.forEach(function (t, r) {
  9993. e && r == 0 && t.forEach(function (n, o) {
  9994. n.show();
  9995. }), r != 0 && t.forEach(function (n, o) {
  9996. n.show();
  9997. });
  9998. });
  9999. }
  10000. }, {
  10001. key: "hideAll",
  10002. value: function hideAll(e) {
  10003. this.characterMap.forEach(function (t, r) {
  10004. e && r == 0 && t.forEach(function (n, o) {
  10005. n.hide();
  10006. }), r != 0 && t.forEach(function (n, o) {
  10007. n.hide();
  10008. });
  10009. });
  10010. }
  10011. }, {
  10012. key: "_assemblyAvatar",
  10013. value: function _assemblyAvatar(e, t) {
  10014. var _this4 = this;
  10015. var n, o;
  10016. var r = e.get(avatarSetting.body);
  10017. if (r && !t.attachBody(r)) {
  10018. t.isInLoadingList = !1, e.clear();
  10019. return;
  10020. }
  10021. var _iterator = _createForOfIteratorHelper$1(e),
  10022. _step;
  10023. try {
  10024. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  10025. var a = _step.value;
  10026. if (a[0] != avatarSetting.body && a[0] != avatarSetting.animations && !t.attachDecoration(a[1])) {
  10027. t.isInLoadingList = !1, t.removeAvatarFromScene(), e.clear();
  10028. return;
  10029. }
  10030. }
  10031. } catch (err) {
  10032. _iterator.e(err);
  10033. } finally {
  10034. _iterator.f();
  10035. }
  10036. t.isRender = !0, (n = t.controller) == null || n.playAnimation(t.controller.onPlay, t.controller.loop), (o = t.controller) == null || o.onPlayObservable.addOnce(function () {
  10037. var a, s;
  10038. if (!_this4.getAvatarById(t.id)) {
  10039. t.isInLoadingList = !1, t.removeAvatarFromScene(), _this4.currentLODUsers[t.distLevel]--;
  10040. return;
  10041. }
  10042. if (_this4.getAvatarById(t.id).rootNode.getChildMeshes().length < e.size) {
  10043. logger$1.error("this avatar does not have complete components, render failed. current list ".concat((a = _this4.getAvatarById(t.id)) == null ? void 0 : a.clothesList, ",avatar: ").concat(t.id, ",").concat(t.nickName)), t.isInLoadingList = !1, t.removeAvatarFromScene(), _this4.currentLODUsers[t.distLevel]--;
  10044. return;
  10045. }
  10046. t.setIsPickable(!0), t.isInLoadingList = !1, t.setAvatarVisible(!0), (s = _this4._sceneManager) == null || s.lightComponent.setShadow(t), t.getBbox(), t.nameBoard && t.nickName.length > 0 && t.setNickName(t.nickName, t.nameBoard.DEFAULT_CONFIGS), t.bubble && t.words.length > 0 && t.say(t.words, t.bubble.DEFAULT_CONFIGS), logger$1.debug("[Engine] avatar ".concat(t.id, " has been added to scene, current number of users : ").concat(_this4.currentLODUsers));
  10047. });
  10048. }
  10049. }, {
  10050. key: "_disposeUnusedAssets",
  10051. value: function _disposeUnusedAssets() {
  10052. this._tickDispose++, this._tickDispose > this._disposeTime && (avatarLoader.disposeContainer(), this._tickDispose = 0);
  10053. }
  10054. }, {
  10055. key: "_addResourcesToList",
  10056. value: function _addResourcesToList(e, t) {
  10057. var _this5 = this;
  10058. return e.clothesList.forEach(function (r) {
  10059. r.lod = t, _this5._queue.push(r);
  10060. }), this._queue.push({
  10061. type: avatarSetting.animations,
  10062. id: this._defaultAnims
  10063. }), this._queue.push({
  10064. type: avatarSetting.body,
  10065. id: e.avatarType,
  10066. lod: t
  10067. }), !0;
  10068. }
  10069. }, {
  10070. key: "_updateBillboardStatus",
  10071. value: function _updateBillboardStatus(e, t) {
  10072. e.bbComponent.updateBillboardStatus(e, t);
  10073. }
  10074. }, {
  10075. key: "_processLayer",
  10076. value: function _processLayer(e) {
  10077. var _this6 = this;
  10078. var t = this.characterMap.get(e),
  10079. r = [];
  10080. for (t == null || t.forEach(function (n) {
  10081. n.distToCam = _this6._distToCamera(n);
  10082. var o = n.distToCam < _this6._cullingDistance;
  10083. if (n.isRender && (!n.isHide && o ? n._hide_culling() : n._show_culling()), n.priority != 0) {
  10084. n.distance = _this6._distToMain(n);
  10085. var _a = BillboardStatus.SHOW;
  10086. n.distance < _this6._maxDistRange && (o ? _a = BillboardStatus.HIDE : n._show_culling(), _this6._updateBillboardStatus(n, _a)), n.isHide || (n.isInLoadingList ? _this6.currentLODUsers[n.distLevel]++ : r.push(n));
  10087. }
  10088. }), r.sort(function (n, o) {
  10089. return o.distance - n.distance;
  10090. }); r.length > 0 && this.curRenderNum() < this.maxRenderNum();) {
  10091. var n = r.pop();
  10092. var o = this._checkLODLevel(n.distance),
  10093. a = !1;
  10094. for (var s = 0; s < this._maxLODUsers.length; ++s) {
  10095. if (this.currentLODUsers[s] < this._maxLODUsers[s]) {
  10096. o = s, a = !0;
  10097. break;
  10098. }
  10099. }
  10100. if (!a || n.distance > this._maxDistRange) {
  10101. if (n.isRender) {
  10102. n._removeAvatarFromScene();
  10103. var _s = BillboardStatus.HIDE;
  10104. n.distance < this._maxDistRange && (_s = BillboardStatus.SHOW), this._updateBillboardStatus(n, _s);
  10105. }
  10106. break;
  10107. }
  10108. o != n.distLevel ? (n.isRender && (n.pendingLod = !0), n.distLevel = o, this._processList.push(n), n.isInLoadingList = !0) : n.isRender || (this._processList.push(n), n.isInLoadingList = !0), this.currentLODUsers[o]++;
  10109. }
  10110. return this.curRenderNum() >= this.maxRenderNum() && r.forEach(function (n) {
  10111. if (n.isRender) {
  10112. n._removeAvatarFromScene();
  10113. var _o = BillboardStatus.HIDE;
  10114. n.distance < _this6._maxDistRange && (_o = BillboardStatus.SHOW), _this6._updateBillboardStatus(n, _o);
  10115. }
  10116. }), this.curRenderNum() < this.maxRenderNum();
  10117. }
  10118. }, {
  10119. key: "_updateAvatar",
  10120. value: function _updateAvatar() {
  10121. var _this7 = this;
  10122. this.currentLODUsers = [0, 0, 0];
  10123. var e = [5, 4, 3, 2, 1, 0];
  10124. for (; e.length > 0;) {
  10125. var t = e.pop();
  10126. if (!this._processLayer(t)) {
  10127. e.forEach(function (n) {
  10128. var o;
  10129. (o = _this7.characterMap.get(n)) == null || o.forEach(function (a) {
  10130. a.distance = _this7._distToMain(a);
  10131. var s = BillboardStatus.HIDE;
  10132. a.distToCam < _this7._maxDistRange && (s = BillboardStatus.SHOW, a.isRender && a._removeAvatarFromScene()), _this7._updateBillboardStatus(a, s);
  10133. });
  10134. });
  10135. break;
  10136. }
  10137. }
  10138. }
  10139. }, {
  10140. key: "_updateAvatarStatus",
  10141. value: function _updateAvatarStatus() {
  10142. var _this8 = this;
  10143. var e = new Map();
  10144. this._updateLoopObserver = this.scene.onBeforeRenderObservable.add(function () {
  10145. var t;
  10146. if (_this8._disposeUnusedAssets(), !(_this8.getAvatarNums() <= 0)) {
  10147. if (!_this8._process && _this8._processList.length == 0 && _this8._updateAvatar(), !_this8._process && _this8._processList.length > 0) {
  10148. var r = _this8._processList.shift();
  10149. r != _this8._process && !r.isCulling ? _this8._addResourcesToList(r, r.distLevel) ? (_this8._process = r, _this8._queueLength = _this8._queue.length) : (_this8._process = void 0, _this8._queue = [], r.isInLoadingList = !1) : r.isInLoadingList = !1;
  10150. }
  10151. if (e.size === _this8._queueLength && _this8._process) {
  10152. _this8._process.pendingLod && (_this8._process.pendingLod = !1, _this8._process._removeAvatarFromScene());
  10153. var _r = Date.now();
  10154. _this8._assemblyAvatar(e, _this8._process), (t = _this8._sceneManager) == null || t.engineRunTimeStats.timeArray_addAvatarToScene.add(Date.now() - _r), _this8._updateBillboardStatus(_this8._process, BillboardStatus.SHOW), e.clear(), _this8._queue = [], _this8._process.isInLoadingList = !1, _this8._process = void 0, _this8._disposeUnusedAssets();
  10155. }
  10156. _this8._loadResByList(e);
  10157. }
  10158. });
  10159. }
  10160. }, {
  10161. key: "_loadResByList",
  10162. value: function _loadResByList(e) {
  10163. var _this9 = this;
  10164. var t = 0;
  10165. var r = 5;
  10166. if (!this._process) {
  10167. e.clear();
  10168. return;
  10169. }
  10170. var _loop = function _loop() {
  10171. var n = Date.now(),
  10172. o = _this9._queue.pop();
  10173. setTimeout(function () {
  10174. o ? o.type === avatarSetting.body ? _this9.loadBody(o.type, o.id, o.lod).then(function (a) {
  10175. a && e.set(avatarSetting.body, a), t += Date.now() - n;
  10176. }).catch(function (a) {
  10177. _this9._process && (_this9._process.isHide = !0, _this9.currentLODUsers[_this9._process.distLevel]--, e.clear(), _this9._queue = [], _this9._process.isInLoadingList = !1, _this9._process = void 0, t += 100), logger$1.warn("[Engine] body ".concat(o.id, " uri error, type ").concat(o.type, ", avatar has been hided") + a);
  10178. }) : o.type === avatarSetting.animations ? _this9.loadAnimation(_this9._process.avatarType, o.id).then(function (a) {
  10179. a && e.set(avatarSetting.animations, a), t += Date.now() - n;
  10180. }).catch(function (a) {
  10181. _this9._process && (_this9._process.isHide = !0, _this9.currentLODUsers[_this9._process.distLevel]--, e.clear(), _this9._queue = [], _this9._process.isInLoadingList = !1, _this9._process = void 0, t += 100), logger$1.warn("animation ".concat(o.id, " uri error, type ").concat(o.type, ", avatar has been hided") + a);
  10182. }) : _this9.loadDecoration(o.type, o.id, o.lod).then(function (a) {
  10183. a && e.set(a.type, a), t += Date.now() - n;
  10184. }).catch(function (a) {
  10185. _this9._process && (_this9._process.isHide = !0, _this9.currentLODUsers[_this9._process.distLevel]--, e.clear(), _this9._queue = [], _this9._process.isInLoadingList = !1, _this9._process = void 0, t += 100), logger$1.warn("component ".concat(o.id, " uri error, type ").concat(o.type, ", avatar has been hided") + a);
  10186. }) : t += 100;
  10187. }, 0);
  10188. };
  10189. for (; t < r && this._queue.length > 0;) {
  10190. _loop();
  10191. }
  10192. }
  10193. }, {
  10194. key: "_validateContainer",
  10195. value: function _validateContainer(e) {
  10196. return !e.meshes || e.meshes.length <= 1 ? (logger$1.warn("import container has no valid meshes"), !1) : !e.skeletons || e.skeletons.length == 0 ? (logger$1.warn("import container has no valid skeletons"), !1) : !0;
  10197. }
  10198. }, {
  10199. key: "_getAssetContainer",
  10200. value: function _getAssetContainer(e, t) {
  10201. var _this10 = this;
  10202. return new Promise(function (r, n) {
  10203. var o = _this10._getSourceKey(e, t || 0),
  10204. a = avatarLoader.containers.get(o);
  10205. if (a) return r(a);
  10206. avatarLoader.load(_this10.sceneManager, e, t).then(function (s) {
  10207. return s ? _this10._validateContainer(s) ? (avatarLoader.containers.set(o, s), r(s)) : n(new ContainerLoadingFailedError("[Engine] :: cannot load body type ".concat(e, "."))) : n(new ContainerLoadingFailedError("[Engine] container load failed cannot load body type ".concat(e, ".")));
  10208. }).catch(function (s) {
  10209. return n(new ContainerLoadingFailedError("[Engine] ".concat(s, " :: cannot load body type ").concat(e, ".")));
  10210. });
  10211. });
  10212. }
  10213. }, {
  10214. key: "_clipContainerRes",
  10215. value: function _clipContainerRes(e) {
  10216. e.transformNodes.forEach(function (t) {
  10217. t.dispose();
  10218. }), e.transformNodes = [], e.skeletons.forEach(function (t) {
  10219. t.dispose();
  10220. }), e.skeletons = [];
  10221. }
  10222. }, {
  10223. key: "loadBody",
  10224. value: function loadBody(e, t, r) {
  10225. var _this11 = this;
  10226. return new Promise(function (n, o) {
  10227. return avatarLoader.load(_this11.sceneManager, t, r).then(function (a) {
  10228. if (a) {
  10229. var s = a.instantiateModelsToScene();
  10230. a.xReferenceCount++;
  10231. var l = {
  10232. isRender: !1,
  10233. uId: Math.random(),
  10234. root: s.rootNodes[0],
  10235. skeletonType: e,
  10236. name: t,
  10237. animations: s.animationGroups,
  10238. skeleton: s.skeletons[0],
  10239. lod: r
  10240. };
  10241. return s.rootNodes[0]._parentContainer = a, s.rootNodes[0].setEnabled(!1), n(l);
  10242. } else return o(new ContainerLoadingFailedError("[Engine] container failed instanciates failed"));
  10243. }).catch(function () {
  10244. return o(new ContainerLoadingFailedError("[Engine] body type ".concat(e, " instanciates failed")));
  10245. });
  10246. });
  10247. }
  10248. }, {
  10249. key: "updateAnimationLists",
  10250. value: function updateAnimationLists(e, t) {
  10251. return new Promise(function (r, n) {
  10252. return avatarLoader.avaliableAnimation.set(t, e), r();
  10253. });
  10254. }
  10255. }, {
  10256. key: "loadAnimation",
  10257. value: function loadAnimation(e, t) {
  10258. var _this12 = this;
  10259. return new Promise(function (r, n) {
  10260. return avatarLoader.loadAnimRes(_this12.sceneManager, t, e).then(function (o) {
  10261. if (o) {
  10262. var a;
  10263. var s = _this12.avatarLoader.animations;
  10264. return o.animationGroups.forEach(function (l) {
  10265. l.stop(), l.name === t && (a = l, a.pContainer = o), s.set(getAnimationKey(l.name, e), l);
  10266. }), _this12._clipContainerRes(o), o.xReferenceCount++, r(a);
  10267. } else return n(new ContainerLoadingFailedError("[Engine] container failed instanciates failed"));
  10268. });
  10269. });
  10270. }
  10271. }, {
  10272. key: "loadDecoration",
  10273. value: function loadDecoration(e, t, r) {
  10274. var _this13 = this;
  10275. return new Promise(function (n, o) {
  10276. return avatarLoader.load(_this13.sceneManager, t, r).then(function (a) {
  10277. if (a) {
  10278. _this13._clipContainerRes(a);
  10279. var s = a.meshes[1].clone(a.meshes[1].name, null);
  10280. if (!s) {
  10281. logger$1.warn("[Engine] decoration does not exist!"), n(null);
  10282. return;
  10283. }
  10284. var l = {
  10285. isRender: !1,
  10286. uId: Math.random(),
  10287. root: s,
  10288. type: e,
  10289. name: t,
  10290. isSelected: !1,
  10291. lod: r
  10292. };
  10293. if (a.xReferenceCount++, s._parentContainer = a, a.meshes.length > 1) for (var u = 2; u < a.meshes.length; u++) {
  10294. s.addChild(a.meshes[u].clone(a.meshes[u].name, null));
  10295. }
  10296. s.setEnabled(!1), l.isSelected = !0, n(l);
  10297. } else return o(new ContainerLoadingFailedError("[Engine] container failed, instanciates failed."));
  10298. }).catch(function () {
  10299. return o(new ContainerLoadingFailedError("[Engine] body type ".concat(e, " instanciates failed.")));
  10300. });
  10301. });
  10302. }
  10303. }, {
  10304. key: "_getSourceKey",
  10305. value: function _getSourceKey(e, t) {
  10306. return t && avatarSetting.lod[t] ? e + avatarSetting.lod[t].fileName.split(".")[0] : e;
  10307. }
  10308. }, {
  10309. key: "addAvatarToScene",
  10310. value: function addAvatarToScene(e, t) {
  10311. var _this14 = this;
  10312. var r = Date.now();
  10313. return new Promise(function (n, o) {
  10314. _this14.loadBody(e.avatarType, e.avatarType, t).then(function (a) {
  10315. var s;
  10316. if (!a) return e.isInLoadingList = !1, o(new ContainerLoadingFailedError("[Engine] avatar ".concat(e.id, " instanciates failed")));
  10317. if (e.attachBody(a), a.animations.length > 0) return a.animations.forEach(function (l) {
  10318. l.stop();
  10319. }), e.setAnimations(a.animations), (s = e.controller) == null || s.playAnimation(e.controller.onPlay, !0), e.isRender = !0, e.isInLoadingList = !1, e.setAvatarVisible(!0), n(e);
  10320. _this14.loadAnimation(e.avatarType, _this14._defaultAnims).then(function (l) {
  10321. if (!l) return e.removeAvatarFromScene(), e.isInLoadingList = !1, o(new AvatarAnimationError());
  10322. var u = [];
  10323. e.clothesList.length > 0 && e.clothesList.forEach(function (c) {
  10324. u.push(_this14.loadDecoration(c.type, c.id, t));
  10325. }), Promise.all(u).then(function (c) {
  10326. var d, _, g, m;
  10327. c.forEach(function (v) {
  10328. if (v && !v.isRender) e.attachDecoration(v);else return e.isInLoadingList = !1, e.removeAvatarFromScene(), o(new AvatarAssetLoadingError());
  10329. }), e.isRender = !0, (d = e.controller) == null || d.playAnimation(e.controller.onPlay, e.controller.loop), e.setAvatarVisible(!0);
  10330. var h = avatarLoader.mshPath.get("meshes/ygb.glb"),
  10331. f = avatarLoader.matPath.get(avatarResources.ygb.mesh);
  10332. h && f ? _this14.loadExtra(f, h).then(function (v) {
  10333. var y;
  10334. e.isRender = !0, e.isInLoadingList = !1, e.distLevel = t, (y = _this14._sceneManager) == null || y.engineRunTimeStats.timeArray_addAvatarToScene.add(Date.now() - r), n(e);
  10335. }) : (e.isRender = !0, e.isInLoadingList = !1, e.distLevel = t, (_ = _this14._sceneManager) == null || _.engineRunTimeStats.timeArray_addAvatarToScene.add(Date.now() - r), n(e)), (g = _this14._sceneManager) == null || g.lightComponent.setShadow(e), e.isInLoadingList = !1, e.distLevel = t, (m = _this14._sceneManager) == null || m.engineRunTimeStats.timeArray_addAvatarToScene.add(Date.now() - r), n(e);
  10336. }).catch(function () {
  10337. return o(new AvatarAssetLoadingError("[Engine] avatar ".concat(e.id, " instanciates failed.")));
  10338. });
  10339. }).catch(function () {
  10340. return o(new AvatarAssetLoadingError("[Engine] avatar ".concat(e.id, " instanciates failed.")));
  10341. });
  10342. }).catch(function () {
  10343. return o(new AvatarAssetLoadingError("[Engine] avatar ".concat(e.id, " instanciates failed.")));
  10344. });
  10345. });
  10346. }
  10347. }, {
  10348. key: "loadExtra",
  10349. value: function loadExtra(e, t) {
  10350. var _this15 = this;
  10351. var r = avatarResources.ygb.name;
  10352. return new Promise(function (n, o) {
  10353. var a;
  10354. (a = _this15.sceneManager) == null || a.urlTransformer(e).then(function (s) {
  10355. BABYLON.SceneLoader.LoadAssetContainerAsync("", s, _this15.scene, null, avatarSetting.fileType).then(function (l) {
  10356. var c;
  10357. _this15.extraComps.set(r, l.meshes[0]);
  10358. var u = new NodeMaterial("material_".concat(r), _this15._scene, {
  10359. emitComments: !1
  10360. });
  10361. (c = _this15.sceneManager) == null || c.urlTransformer(t).then(function (h) {
  10362. u.loadAsync(h).then(function () {
  10363. l.meshes[2].material.dispose(!0, !0), u.build(!1), l.meshes[2].material = u, n(l.meshes[2]);
  10364. });
  10365. });
  10366. });
  10367. });
  10368. });
  10369. }
  10370. }, {
  10371. key: "getAvatarList",
  10372. value: function getAvatarList() {
  10373. var e = [];
  10374. return this.characterMap.forEach(function (t, r) {
  10375. t.forEach(function (n, o) {
  10376. e.push(n);
  10377. });
  10378. }), e;
  10379. }
  10380. }, {
  10381. key: "_debug_avatar",
  10382. value: function _debug_avatar() {
  10383. var t, r;
  10384. console.error("===>currentLODUsers", this.currentLODUsers), console.error("===>maxLODUsers", this._maxLODUsers), console.error("===>Loddist", this.getLoDLevels()), console.error("===> main character loc", (r = (t = this._mainUser) == null ? void 0 : t.rootNode) == null ? void 0 : r.position);
  10385. var e = 0;
  10386. this.getAvatarList().forEach(function (n) {
  10387. n.isRender && (console.error("avatar id : ".concat(n.id, ",lod ").concat(n.distLevel, ",is Hide ").concat(n.isHide, ", distance ").concat(n.distance, ", is pending ").concat(n.isInLoadingList)), e++);
  10388. }), console.error("========= avatar num", e), console.error("loop:", this._updateLoopObserver ? "on" : "false", "=> process", this._process, "===> comp", this._processList), console.error("===>maxLODUsers", this._maxLODUsers);
  10389. }
  10390. }]);
  10391. return XAvatarManager;
  10392. }();
  10393. var texRootDir = "https://app-asset-1258211750.file.myqcloud.com/1/textures/";
  10394. var XBillboardManager = /*#__PURE__*/function () {
  10395. function XBillboardManager(e) {
  10396. var _this = this;
  10397. _classCallCheck(this, XBillboardManager);
  10398. E(this, "billboardMap", new Map());
  10399. E(this, "sceneManager");
  10400. E(this, "billboardPool");
  10401. E(this, "userBackGroundBlob", new Array());
  10402. E(this, "npcBackGroundBlob", new Array());
  10403. E(this, "tickObserver");
  10404. E(this, "tickInterval");
  10405. E(this, "_updateLoopObserver");
  10406. this.sceneManager = e, this.billboardPool = new Pool(this.createBillboardAsset, this.resetBillboardAsset, 0, 60, this.sceneManager.Scene, !1), this.tickInterval = 250;
  10407. var t = 0;
  10408. this.tickObserver = this.sceneManager.Scene.onAfterRenderObservable.add(function () {
  10409. t += 1, t == _this.tickInterval && (_this.tick(), t = 0);
  10410. }), this.launchBillboardStatusLoop();
  10411. }
  10412. _createClass(XBillboardManager, [{
  10413. key: "tick",
  10414. value: function tick() {
  10415. this.billboardPool.clean(0, this.sceneManager.Scene, !1);
  10416. }
  10417. }, {
  10418. key: "createBillboardAsset",
  10419. value: function createBillboardAsset(e) {
  10420. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
  10421. var r = BABYLON.MeshBuilder.CreatePlane("billboard-", {
  10422. height: .001,
  10423. width: .001,
  10424. sideOrientation: BABYLON.Mesh.DOUBLESIDE
  10425. }, e);
  10426. r.isPickable = !0, r.setEnabled(!1);
  10427. var n = new BABYLON.DynamicTexture("billboard-tex-", {
  10428. width: .001 + 1,
  10429. height: .001 + 1
  10430. }, e, t, BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  10431. n.hasAlpha = !0;
  10432. var o = new BABYLON.StandardMaterial("billboard-mat-", e);
  10433. return o.diffuseTexture = n, o.emissiveColor = new BABYLON.Color3(.95, .95, .95), o.useAlphaFromDiffuseTexture = !0, r.material = o, r.billboardMode = BABYLON.Mesh.BILLBOARDMODE_Y, r.position.y = 0, r;
  10434. }
  10435. }, {
  10436. key: "resetBillboardAsset",
  10437. value: function resetBillboardAsset(e) {
  10438. var t = e.data;
  10439. return t.setEnabled(!1), t.isPickable = !1, e;
  10440. }
  10441. }, {
  10442. key: "loadBackGroundTexToIDB",
  10443. value: function () {
  10444. var _loadBackGroundTexToIDB = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  10445. var _this2 = this;
  10446. return regenerator.wrap(function _callee$(_context) {
  10447. while (1) {
  10448. switch (_context.prev = _context.next) {
  10449. case 0:
  10450. XBillboardManager.userBubbleUrls.forEach(function (r) {
  10451. _this2.sceneManager.urlTransformer(r).then(function (n) {
  10452. _this2.userBackGroundBlob.push(n);
  10453. });
  10454. }), XBillboardManager.npcBubbleUrls.forEach(function (r) {
  10455. _this2.sceneManager.urlTransformer(r).then(function (n) {
  10456. _this2.npcBackGroundBlob.push(n);
  10457. });
  10458. });
  10459. case 1:
  10460. case "end":
  10461. return _context.stop();
  10462. }
  10463. }
  10464. }, _callee);
  10465. }));
  10466. function loadBackGroundTexToIDB() {
  10467. return _loadBackGroundTexToIDB.apply(this, arguments);
  10468. }
  10469. return loadBackGroundTexToIDB;
  10470. }()
  10471. }, {
  10472. key: "addBillboardToMap",
  10473. value: function addBillboardToMap(e, t) {
  10474. this.billboardMap.set(e, t);
  10475. }
  10476. }, {
  10477. key: "addBillboard",
  10478. value: function addBillboard(e, t, r) {
  10479. var n = this.getBillboard(e);
  10480. return n || (n = new XBillboard(this, t, r), this.addBillboardToMap(e, n)), n;
  10481. }
  10482. }, {
  10483. key: "generateStaticBillboard",
  10484. value: function generateStaticBillboard(e, _ref) {
  10485. var _ref$id = _ref.id,
  10486. t = _ref$id === void 0 ? "billboard" : _ref$id,
  10487. r = _ref.isUser,
  10488. n = _ref.background,
  10489. _ref$font = _ref.font,
  10490. o = _ref$font === void 0 ? "Arial" : _ref$font,
  10491. _ref$fontsize = _ref.fontsize,
  10492. a = _ref$fontsize === void 0 ? 40 : _ref$fontsize,
  10493. _ref$fontcolor = _ref.fontcolor,
  10494. s = _ref$fontcolor === void 0 ? "#ffffff" : _ref$fontcolor,
  10495. _ref$fontstyle = _ref.fontstyle,
  10496. l = _ref$fontstyle === void 0 ? "600" : _ref$fontstyle,
  10497. _ref$linesize = _ref.linesize,
  10498. u = _ref$linesize === void 0 ? 16 : _ref$linesize,
  10499. c = _ref.linelimit,
  10500. _ref$scale = _ref.scale,
  10501. h = _ref$scale === void 0 ? 1 : _ref$scale,
  10502. _ref$width = _ref.width,
  10503. f = _ref$width === void 0 ? .01 : _ref$width,
  10504. _ref$height = _ref.height,
  10505. d = _ref$height === void 0 ? .01 : _ref$height,
  10506. _ref$position = _ref.position,
  10507. _ = _ref$position === void 0 ? {
  10508. x: 0,
  10509. y: 0,
  10510. z: 0
  10511. } : _ref$position;
  10512. var g = this.addBillboard(t, !1, !0);
  10513. g.getMesh() == null && g.init(t, f, d);
  10514. var m;
  10515. r != null && (m = r ? XBillboardManager.userBubbleUrls : XBillboardManager.npcBubbleUrls), g && g.getMesh() && (g.DEFAULT_CONFIGS = {
  10516. id: t,
  10517. isUser: r,
  10518. background: n,
  10519. font: o,
  10520. fontsize: a,
  10521. fontcolor: s,
  10522. fontstyle: l,
  10523. linesize: u,
  10524. linelimit: c,
  10525. scale: h,
  10526. width: f,
  10527. height: d,
  10528. position: _
  10529. }, g.drawBillboard({
  10530. imageList: n || m
  10531. }, {
  10532. texts: e,
  10533. font: o,
  10534. fontsize: a,
  10535. fontcolor: s,
  10536. fontstyle: l,
  10537. linesize: u,
  10538. linelimit: c
  10539. }, {
  10540. position: _,
  10541. scale: h
  10542. }), t && g.setId(t), g.setStatus(BillboardStatus.SHOW));
  10543. }
  10544. }, {
  10545. key: "getBillboard",
  10546. value: function getBillboard(e) {
  10547. return this.billboardMap.get(e);
  10548. }
  10549. }, {
  10550. key: "toggle",
  10551. value: function toggle(e, t) {
  10552. var r;
  10553. (r = this.getBillboard(e)) == null || r.setStatus(t ? BillboardStatus.SHOW : BillboardStatus.HIDE);
  10554. }
  10555. }, {
  10556. key: "removeBillboard",
  10557. value: function removeBillboard(e) {
  10558. var t = this.getBillboard(e);
  10559. t && (t.setStatus(BillboardStatus.DISPOSE), this.billboardMap.delete(e));
  10560. }
  10561. }, {
  10562. key: "launchBillboardStatusLoop",
  10563. value: function launchBillboardStatusLoop() {
  10564. var _this3 = this;
  10565. this._updateLoopObserver = this.sceneManager.Scene.onBeforeRenderObservable.add(function () {
  10566. _this3.billboardMap.size <= 0 || _this3.billboardMap.forEach(function (e) {
  10567. e.stageChanged && (e.status == BillboardStatus.SHOW ? e.show() : e.status == BillboardStatus.HIDE ? e.hide() : (e.hide(), e.dispose()), e.stageChanged = !1);
  10568. });
  10569. });
  10570. }
  10571. }]);
  10572. return XBillboardManager;
  10573. }();
  10574. E(XBillboardManager, "alphaWidthMap", new Map()), E(XBillboardManager, "userBubbleUrls", [texRootDir + "bubble01.png", texRootDir + "bubble02.png", texRootDir + "bubble03.png"]), E(XBillboardManager, "npcBubbleUrls", [texRootDir + "bubble01_npc.png", texRootDir + "bubble02_npc.png", texRootDir + "bubble03_npc.png"]);
  10575. var XLightManager = /*#__PURE__*/function () {
  10576. function XLightManager(e) {
  10577. _classCallCheck(this, XLightManager);
  10578. E(this, "_scene");
  10579. E(this, "_envTexture");
  10580. E(this, "_shadowLight");
  10581. E(this, "_shadowGenerator");
  10582. E(this, "_avatarShadowMeshMap");
  10583. E(this, "_cullingShadowObservers");
  10584. E(this, "sceneManager");
  10585. this.sceneManager = e, this._scene = this.sceneManager.Scene, this._envTexture = null, this.shadowLean = .1;
  10586. var t = new BABYLON.Vector3(this.shadowLean, -1, 0),
  10587. r = 1024;
  10588. this._shadowLight = new BABYLON.DirectionalLight("AvatarLight", t, this._scene), this._shadowLight.shadowMaxZ = 5e3, this._shadowLight.intensity = 0, this.attachLightToCamera(this._shadowLight), this._shadowGenerator = new BABYLON.ShadowGenerator(r, this._shadowLight, !0), this._avatarShadowMeshMap = new Map(), this._cullingShadowObservers = new Map();
  10589. }
  10590. _createClass(XLightManager, [{
  10591. key: "shadowLean",
  10592. set: function set(e) {
  10593. e = Math.min(e, 1), e = Math.max(e, -1), this._shadowLight && (this._shadowLight.direction = new BABYLON.Vector3(e, -1, 0));
  10594. }
  10595. }, {
  10596. key: "setIBL",
  10597. value: function setIBL(e) {
  10598. var _this = this;
  10599. return new Promise(function (t, r) {
  10600. _this.sceneManager.urlTransformer(e).then(function (n) {
  10601. var o;
  10602. if (n == ((o = _this._envTexture) == null ? void 0 : o.url)) return t("env set success");
  10603. _this._envTexture != null && _this.disposeIBL(), _this._envTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(n, _this._scene, ".env"), _this._scene.environmentTexture = _this._envTexture, _this._envTexture.onLoadObservable.addOnce(function () {
  10604. t("env set success"), logger$1.info("env set success");
  10605. });
  10606. }).catch(function () {
  10607. r("env set fail");
  10608. });
  10609. });
  10610. }
  10611. }, {
  10612. key: "disposeIBL",
  10613. value: function disposeIBL() {
  10614. this._envTexture == null ? logger$1.info("env not exist") : (this._envTexture.dispose(), this._envTexture = null, this._scene.environmentTexture = null, logger$1.info("env dispose success"));
  10615. }
  10616. }, {
  10617. key: "removeShadow",
  10618. value: function removeShadow(e) {
  10619. var t;
  10620. if (this._avatarShadowMeshMap.has(e)) {
  10621. this._avatarShadowMeshMap.delete(e), this._cullingShadowObservers.get(e) && (this._scene.onBeforeRenderObservable.remove(this._cullingShadowObservers.get(e)), this._cullingShadowObservers.delete(e));
  10622. var r = e.rootNode;
  10623. r && ((t = this._shadowGenerator) == null || t.removeShadowCaster(r));
  10624. } else return;
  10625. }
  10626. }, {
  10627. key: "setShadow",
  10628. value: function setShadow(e) {
  10629. if (this._avatarShadowMeshMap.has(e)) return;
  10630. e.rootNode && this._avatarShadowMeshMap.set(e, e.rootNode.getChildMeshes());
  10631. var t = 20,
  10632. r = 10,
  10633. n = this.cullingShadow(t, r, e);
  10634. this._cullingShadowObservers.set(e, n);
  10635. }
  10636. }, {
  10637. key: "cullingShadow",
  10638. value: function cullingShadow(e, t, r) {
  10639. var _this2 = this;
  10640. var n = 0;
  10641. var o = function o() {
  10642. var s, l;
  10643. if (n == t) {
  10644. var u = _this2._avatarShadowMeshMap.get(r),
  10645. c = (s = r.rootNode) == null ? void 0 : s.getChildMeshes(),
  10646. h = _this2._scene.activeCamera;
  10647. u == null || u.forEach(function (f) {
  10648. var d;
  10649. (d = _this2._shadowGenerator) == null || d.removeShadowCaster(f, !1);
  10650. }), c == null || c.forEach(function (f) {
  10651. var d;
  10652. (d = _this2._shadowGenerator) == null || d.addShadowCaster(f, !1);
  10653. }), h && r.rootNode && ((l = r.rootNode.position) == null ? void 0 : l.subtract(h.position).length()) > e && (c == null || c.forEach(function (f) {
  10654. var d;
  10655. (d = _this2._shadowGenerator) == null || d.removeShadowCaster(f, !1);
  10656. })), c && _this2._avatarShadowMeshMap.set(r, c), n = 0;
  10657. } else n += 1;
  10658. };
  10659. return this._scene.onBeforeRenderObservable.add(o);
  10660. }
  10661. }, {
  10662. key: "attachLightToCamera",
  10663. value: function attachLightToCamera(e) {
  10664. var _this3 = this;
  10665. var t = e,
  10666. r = 15,
  10667. n = function n() {
  10668. var o = _this3._scene.activeCamera;
  10669. if (o) {
  10670. var a = t.direction,
  10671. s = new BABYLON.Vector3(r * a.x, r * a.y, r * a.z),
  10672. l = o.position;
  10673. t.position = l.subtract(s);
  10674. }
  10675. };
  10676. return t && this._scene.registerBeforeRender(n), n;
  10677. }
  10678. }]);
  10679. return XLightManager;
  10680. }();
  10681. var RunTimeArray = /*#__PURE__*/function () {
  10682. function RunTimeArray() {
  10683. _classCallCheck(this, RunTimeArray);
  10684. E(this, "circularData");
  10685. this.circularData = [];
  10686. }
  10687. _createClass(RunTimeArray, [{
  10688. key: "add",
  10689. value: function add(e) {
  10690. this.circularData.length > 1e3 && this.circularData.shift(), this.circularData.push(e);
  10691. }
  10692. }, {
  10693. key: "getAvg",
  10694. value: function getAvg() {
  10695. var e = 0;
  10696. for (var t = 0; t < this.circularData.length; t++) {
  10697. e += this.circularData[t];
  10698. }
  10699. return {
  10700. sum: e,
  10701. avg: e / this.circularData.length || 0
  10702. };
  10703. }
  10704. }, {
  10705. key: "getMax",
  10706. value: function getMax() {
  10707. var e = 0;
  10708. for (var t = 0; t < this.circularData.length; t++) {
  10709. e < this.circularData[t] && (e = this.circularData[t]);
  10710. }
  10711. return e || 0;
  10712. }
  10713. }, {
  10714. key: "clear",
  10715. value: function clear() {
  10716. this.circularData = [];
  10717. }
  10718. }, {
  10719. key: "getStat",
  10720. value: function getStat() {
  10721. var e = this.getAvg(),
  10722. t = {
  10723. sum: e.sum,
  10724. avg: e.avg,
  10725. max: this.getMax()
  10726. };
  10727. return this.clear(), t;
  10728. }
  10729. }]);
  10730. return RunTimeArray;
  10731. }();
  10732. var XEngineRunTimeStats = /*#__PURE__*/_createClass(function XEngineRunTimeStats() {
  10733. _classCallCheck(this, XEngineRunTimeStats);
  10734. E(this, "timeArray_loadStaticMesh", new RunTimeArray());
  10735. E(this, "timeArray_updateStaticMesh", new RunTimeArray());
  10736. E(this, "timeArray_addAvatarToScene", new RunTimeArray());
  10737. });
  10738. 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; } } }; }
  10739. 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); }
  10740. 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; }
  10741. var getAlphaWidthMap = function getAlphaWidthMap(i, e) {
  10742. var t = new BABYLON.DynamicTexture("test", 3, e),
  10743. r = new Map();
  10744. for (var n = 32; n < 127; n++) {
  10745. var o = String.fromCodePoint(n),
  10746. a = 2 + "px " + i;
  10747. t.drawText(o, null, null, a, "#000000", "#ffffff", !0);
  10748. var s = t.getContext();
  10749. s.font = a;
  10750. var l = s.measureText(o).width;
  10751. r.set(n, l);
  10752. }
  10753. return t.dispose(), r;
  10754. };
  10755. var XSceneManager = /*#__PURE__*/function () {
  10756. function XSceneManager(e, t) {
  10757. var _this = this;
  10758. _classCallCheck(this, XSceneManager);
  10759. E(this, "scene");
  10760. E(this, "engine");
  10761. E(this, "canvas");
  10762. E(this, "gl");
  10763. E(this, "_yuvInfo");
  10764. E(this, "cameraParam");
  10765. E(this, "shaderMode");
  10766. E(this, "panoInfo");
  10767. E(this, "_initEngineScaleNumber");
  10768. E(this, "_forceKeepVertical", !1);
  10769. E(this, "_currentShader");
  10770. E(this, "_currentPanoId");
  10771. E(this, "_renderStatusCheckCount", 0);
  10772. E(this, "_renderStatusNotChecktCount", 0);
  10773. E(this, "_nonlinearCanvasResize", !1);
  10774. E(this, "_bChangeEngineSize", !0);
  10775. E(this, "_cameraManager");
  10776. E(this, "_lowpolyManager");
  10777. E(this, "_materialManager");
  10778. E(this, "_statisticManager");
  10779. E(this, "_breathPointManager");
  10780. E(this, "_skytv");
  10781. E(this, "_mv", []);
  10782. E(this, "_decalManager");
  10783. E(this, "_lightManager");
  10784. E(this, "_avatarManager");
  10785. E(this, "urlTransformer");
  10786. E(this, "_billboardManager");
  10787. E(this, "_backgroundImg");
  10788. E(this, "engineRunTimeStats");
  10789. E(this, "uploadHardwareSystemInfo", function () {
  10790. var e = _this.statisticComponent.getHardwareRenderInfo(),
  10791. t = _this.statisticComponent.getSystemInfo(),
  10792. r = {
  10793. driver: t.driver,
  10794. vender: t.vender,
  10795. webgl: t.version,
  10796. os: t.os
  10797. };
  10798. logger$1.warn(JSON.stringify(e)), logger$1.warn(JSON.stringify(r));
  10799. });
  10800. E(this, "addNewLowPolyMesh", /*#__PURE__*/function () {
  10801. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  10802. return regenerator.wrap(function _callee$(_context) {
  10803. while (1) {
  10804. switch (_context.prev = _context.next) {
  10805. case 0:
  10806. _context.t0 = _this._currentShader == null;
  10807. if (!_context.t0) {
  10808. _context.next = 4;
  10809. break;
  10810. }
  10811. _context.next = 4;
  10812. return _this.initSceneManager();
  10813. case 4:
  10814. return _context.abrupt("return", _this._lowpolyManager.addNewLowPolyMesh(e, t, _this._currentShader));
  10815. case 5:
  10816. case "end":
  10817. return _context.stop();
  10818. }
  10819. }
  10820. }, _callee);
  10821. }));
  10822. return function (_x, _x2) {
  10823. return _ref.apply(this, arguments);
  10824. };
  10825. }());
  10826. E(this, "initSceneManager", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  10827. return regenerator.wrap(function _callee2$(_context2) {
  10828. while (1) {
  10829. switch (_context2.prev = _context2.next) {
  10830. case 0:
  10831. _context2.next = 2;
  10832. return _this._materialManager.initMaterial();
  10833. case 2:
  10834. return _context2.abrupt("return", _this.applyShader());
  10835. case 3:
  10836. case "end":
  10837. return _context2.stop();
  10838. }
  10839. }
  10840. }, _callee2);
  10841. })));
  10842. E(this, "registerAfterRender", function () {
  10843. var e;
  10844. if (_this._forceKeepVertical) {
  10845. var _t = _this.canvas.width,
  10846. _r = _this.canvas.height;
  10847. var _n = 0,
  10848. _o = [[0, 0, 0, 0], [0, 0, 0, 0]];
  10849. 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) {
  10850. _this.gl.enable(_this.gl.SCISSOR_TEST);
  10851. for (var a = 0; a < _o.length; ++a) {
  10852. _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);
  10853. }
  10854. _this.gl.disable(_this.gl.SCISSOR_TEST);
  10855. }
  10856. }
  10857. });
  10858. E(this, "resetRender", function () {
  10859. _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));
  10860. });
  10861. var r = /iphone|ipad/gi.test(window.navigator.userAgent) || t.disableWebGL2,
  10862. n = new BABYLON.Engine(e, !0, {
  10863. preserveDrawingBuffer: !0,
  10864. stencil: !0,
  10865. disableWebGL2Support: r
  10866. }, !0),
  10867. o = new BABYLON.Scene(n);
  10868. 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) {
  10869. return Promise.resolve(s);
  10870. }, t.logger && Logger1.setLogger(t.logger), this.gl = e.getContext("webgl2", {
  10871. preserveDrawingBuffer: !0
  10872. }) || e.getContext("webgl", {
  10873. preserveDrawingBuffer: !0
  10874. }) || e.getContext("experimental-webgl", {
  10875. preserveDrawingBuffer: !0
  10876. }), 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 = {
  10877. width: t.videoResOriArray[0].width,
  10878. height: t.videoResOriArray[0].height,
  10879. fov: 50
  10880. }, t.cameraParam != null && (this.cameraParam = t.cameraParam), t.nonlinearCanvasResize != null && (this._nonlinearCanvasResize = t.nonlinearCanvasResize), this._cameraManager = new XCameraComponent(this.canvas, this.scene, {
  10881. cameraParam: this.cameraParam,
  10882. yuvInfo: this._yuvInfo,
  10883. forceKeepVertical: this._forceKeepVertical
  10884. }), this._lowpolyManager = new XStaticMeshComponent(this), this._materialManager = new XMaterialComponent(this, {
  10885. videoResOriArray: t.videoResOriArray,
  10886. yuvInfo: this._yuvInfo,
  10887. panoInfo: this.panoInfo,
  10888. shaderMode: this.shaderMode
  10889. }), 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 () {
  10890. _this._nonlinearCanvasResize && _this._bChangeEngineSize && (_this.setEngineSize(_this._yuvInfo), _this._bChangeEngineSize = !1);
  10891. }), this.scene.registerAfterRender(function () {
  10892. _this._nonlinearCanvasResize || _this.registerAfterRender();
  10893. }), window.addEventListener("resize", function () {
  10894. _this._nonlinearCanvasResize ? _this._bChangeEngineSize = !0 : _this.engine.resize();
  10895. }), XBillboardManager.alphaWidthMap = getAlphaWidthMap("Arial", this.scene), this.uploadHardwareSystemInfo();
  10896. }
  10897. _createClass(XSceneManager, [{
  10898. key: "yuvInfo",
  10899. get: function get() {
  10900. return this.getCurrentShaderMode() == 1 ? this._yuvInfo : {
  10901. width: -1,
  10902. height: -1,
  10903. fov: -1
  10904. };
  10905. },
  10906. set: function set(e) {
  10907. this.getCurrentShaderMode() == 1 && (this._yuvInfo = e, this._cameraManager.cameraFovChange(e));
  10908. }
  10909. }, {
  10910. key: "mainScene",
  10911. get: function get() {
  10912. return this.scene;
  10913. }
  10914. }, {
  10915. key: "cameraComponent",
  10916. get: function get() {
  10917. return this._cameraManager;
  10918. }
  10919. }, {
  10920. key: "staticmeshComponent",
  10921. get: function get() {
  10922. return this._lowpolyManager;
  10923. }
  10924. }, {
  10925. key: "materialComponent",
  10926. get: function get() {
  10927. return this._materialManager;
  10928. }
  10929. }, {
  10930. key: "statisticComponent",
  10931. get: function get() {
  10932. return this._statisticManager;
  10933. }
  10934. }, {
  10935. key: "avatarComponent",
  10936. get: function get() {
  10937. return this._avatarManager;
  10938. }
  10939. }, {
  10940. key: "lightComponent",
  10941. get: function get() {
  10942. return this._lightManager;
  10943. }
  10944. }, {
  10945. key: "Engine",
  10946. get: function get() {
  10947. return this.engine;
  10948. }
  10949. }, {
  10950. key: "Scene",
  10951. get: function get() {
  10952. return this.scene;
  10953. }
  10954. }, {
  10955. key: "billboardComponent",
  10956. get: function get() {
  10957. return this._billboardManager;
  10958. }
  10959. }, {
  10960. key: "breathPointComponent",
  10961. get: function get() {
  10962. return this._breathPointManager;
  10963. }
  10964. }, {
  10965. key: "skytvComponent",
  10966. get: function get() {
  10967. return this._skytv;
  10968. }
  10969. }, {
  10970. key: "mvComponent",
  10971. get: function get() {
  10972. return this._mv;
  10973. }
  10974. }, {
  10975. key: "decalComponent",
  10976. get: function get() {
  10977. return this._decalManager;
  10978. }
  10979. }, {
  10980. key: "currentShader",
  10981. get: function get() {
  10982. return this._currentShader;
  10983. }
  10984. }, {
  10985. key: "initEngineScaleNumber",
  10986. get: function get() {
  10987. return this._initEngineScaleNumber;
  10988. }
  10989. }, {
  10990. key: "setImageQuality",
  10991. value: function setImageQuality(e) {
  10992. e == 0 ? (this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 1.8), logger$1.info("[Engine] change image quality to low, [" + this._initEngineScaleNumber * 1.8 + "]")) : e == 1 ? (this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 1.5), logger$1.info("[Engine] change image quality to mid, [" + this._initEngineScaleNumber * 1.5 + "]")) : e == 2 && (this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * 1), logger$1.info("[Engine] change image quality to high, [" + this._initEngineScaleNumber * 1 + "]"));
  10993. }
  10994. }, {
  10995. key: "setNonlinearCanvasResize",
  10996. value: function setNonlinearCanvasResize(e) {
  10997. this._nonlinearCanvasResize = e, this._bChangeEngineSize = e, e || this.engine.resize();
  10998. }
  10999. }, {
  11000. key: "setBackgroundColor",
  11001. value: function setBackgroundColor(e) {
  11002. this.scene.clearColor = new Color4(e.r, e.g, e.b, e.a);
  11003. }
  11004. }, {
  11005. key: "setBackgroundImg",
  11006. value: function setBackgroundImg(e) {
  11007. var _this2 = this;
  11008. return this._backgroundImg != null && this._backgroundImg.url == e ? Promise.resolve(!0) : new Promise(function (t, r) {
  11009. _this2.urlTransformer(e).then(function (n) {
  11010. _this2._backgroundImg == null ? _this2._backgroundImg = {
  11011. layer: new Layer("tex_background_" + Date.now(), n, _this2.Scene, !0),
  11012. url: e
  11013. } : _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);
  11014. }).catch(function (n) {
  11015. logger$1.error("[Engine] set background image Error: ".concat(n)), r("[Engine] set background image Error: ".concat(n));
  11016. });
  11017. });
  11018. }
  11019. }, {
  11020. key: "cleanTheWholeScene",
  11021. value: function cleanTheWholeScene() {
  11022. var _this3 = this;
  11023. var e = this.scene.getFrameId();
  11024. this.scene.onBeforeRenderObservable.clear(), this.scene.onAfterRenderObservable.clear(), this.scene.clearCachedVertexData(), this.scene.cleanCachedTextureBuffer(), this.scene.registerBeforeRender(function () {
  11025. _this3.scene.getFrameId() - e > 5 && _this3.scene.dispose();
  11026. });
  11027. }
  11028. }, {
  11029. key: "getAreaAvatar",
  11030. value: function getAreaAvatar(e, t) {
  11031. var r = [];
  11032. return this._avatarManager.getAvatarList().forEach(function (n) {
  11033. var o = e,
  11034. a = n.position;
  11035. a && o && calcDistance3D(o, a) < t && r.push(n.id);
  11036. }), r;
  11037. }
  11038. }, {
  11039. key: "setEngineSize",
  11040. value: function setEngineSize(e) {
  11041. var t = e.width,
  11042. r = e.height,
  11043. n = this.canvas.width;
  11044. this.canvas.height, this.engine.setSize(Math.round(n), Math.round(n * (r / t)));
  11045. }
  11046. }, {
  11047. key: "getCurrentShaderMode",
  11048. value: function getCurrentShaderMode() {
  11049. return this._currentShader === this._materialManager.getDefaultShader() ? 0 : this._currentShader === this._materialManager.getPureVideoShader() ? 1 : 2;
  11050. }
  11051. }, {
  11052. key: "addSkyTV",
  11053. value: function addSkyTV(e, t) {
  11054. return this._skytv = new XTelevision(this.scene, e, this, t), this._skytv;
  11055. }
  11056. }, {
  11057. key: "addMv",
  11058. value: function addMv(e, t) {
  11059. this._mv.push(new XTelevision(this.scene, e, this, t));
  11060. }
  11061. }, {
  11062. key: "addMeshInfo",
  11063. value: function addMeshInfo(e) {
  11064. this._lowpolyManager.setMeshInfo(e);
  11065. }
  11066. }, {
  11067. key: "applyShader",
  11068. value: function applyShader() {
  11069. var _this4 = this;
  11070. return new Promise(function (e, t) {
  11071. _this4.shaderMode == EShaderMode.videoAndPano || _this4.shaderMode == EShaderMode.video ? _this4.changeVideoShaderForLowModel() : _this4.shaderMode == EShaderMode.default && _this4.changeDefaultShaderForLowModel(), e(!0);
  11072. });
  11073. }
  11074. }, {
  11075. key: "changeHardwareScaling",
  11076. value: function changeHardwareScaling(e) {
  11077. e < 1 ? e = 1 : e > 2.5 && (e = 2.5), this._bChangeEngineSize = !0, this.engine.setHardwareScalingLevel(this._initEngineScaleNumber * e);
  11078. }
  11079. }, {
  11080. key: "getCurrentUsedPanoId",
  11081. value: function getCurrentUsedPanoId() {
  11082. return this._currentPanoId;
  11083. }
  11084. }, {
  11085. key: "render",
  11086. value: function render() {
  11087. try {
  11088. this.scene.render();
  11089. } catch (e) {
  11090. throw logger$1.error("[Engine] Render Error: ".concat(e)), e;
  11091. }
  11092. }
  11093. }, {
  11094. key: "isReadyToRender",
  11095. value: function isReadyToRender(e) {
  11096. var _e$checkMesh = e.checkMesh,
  11097. t = _e$checkMesh === void 0 ? !0 : _e$checkMesh,
  11098. _e$checkEffect = e.checkEffect,
  11099. r = _e$checkEffect === void 0 ? !1 : _e$checkEffect,
  11100. _e$checkPostProgress = e.checkPostProgress,
  11101. n = _e$checkPostProgress === void 0 ? !1 : _e$checkPostProgress,
  11102. _e$checkParticle = e.checkParticle,
  11103. o = _e$checkParticle === void 0 ? !1 : _e$checkParticle,
  11104. _e$checkAnimation = e.checkAnimation,
  11105. a = _e$checkAnimation === void 0 ? !1 : _e$checkAnimation;
  11106. e.materialNameWhiteLists;
  11107. if (this.scene._isDisposed) return logger$1.error("[Engine] this.scene._isDisposed== false "), !1;
  11108. var l;
  11109. var u = this.scene.getEngine();
  11110. if (r && !u.areAllEffectsReady()) return logger$1.error("[Engine] engine.areAllEffectsReady == false"), !1;
  11111. if (a && this.scene._pendingData.length > 0) return logger$1.error("[Engine] scene._pendingData.length > 0 && animation error"), !1;
  11112. if (t) {
  11113. for (l = 0; l < this.scene.meshes.length; l++) {
  11114. var c = this.scene.meshes[l];
  11115. 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;
  11116. if (!c.isReady(!0)) return logger$1.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;
  11117. var h = c.hasThinInstances || c.getClassName() === "InstancedMesh" || c.getClassName() === "InstancedLinesMesh" || u.getCaps().instancedArrays && c.instances.length > 0;
  11118. var _iterator = _createForOfIteratorHelper(this.scene._isReadyForMeshStage),
  11119. _step;
  11120. try {
  11121. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  11122. var f = _step.value;
  11123. if (!f.action(c, h)) return logger$1.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;
  11124. }
  11125. } catch (err) {
  11126. _iterator.e(err);
  11127. } finally {
  11128. _iterator.f();
  11129. }
  11130. }
  11131. for (l = 0; l < this.scene.geometries.length; l++) {
  11132. if (this.scene.geometries[l].delayLoadState === 2) return logger$1.error("[Engine] geometry.delayLoadState === 2"), !1;
  11133. }
  11134. }
  11135. if (n) {
  11136. if (this.scene.activeCameras && this.scene.activeCameras.length > 0) {
  11137. var _iterator2 = _createForOfIteratorHelper(this.scene.activeCameras),
  11138. _step2;
  11139. try {
  11140. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  11141. var _c = _step2.value;
  11142. if (!_c.isReady(!0)) return logger$1.error("[Engine] camera not ready === false, ", _c.name), !1;
  11143. }
  11144. } catch (err) {
  11145. _iterator2.e(err);
  11146. } finally {
  11147. _iterator2.f();
  11148. }
  11149. } else if (this.scene.activeCamera && !this.scene.activeCamera.isReady(!0)) return logger$1.error("[Engine] activeCamera ready === false, ", this.scene.activeCamera.name), !1;
  11150. }
  11151. if (o) {
  11152. var _iterator3 = _createForOfIteratorHelper(this.scene.particleSystems),
  11153. _step3;
  11154. try {
  11155. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  11156. var _c2 = _step3.value;
  11157. if (!_c2.isReady()) return logger$1.error("[Engine] particleSystem ready === false, ", _c2.name), !1;
  11158. }
  11159. } catch (err) {
  11160. _iterator3.e(err);
  11161. } finally {
  11162. _iterator3.f();
  11163. }
  11164. }
  11165. return !0;
  11166. }
  11167. }, {
  11168. key: "changePanoShaderForLowModel",
  11169. value: function changePanoShaderForLowModel(e) {
  11170. var _this5 = this;
  11171. return logger$1.info("[Engine] changePanoShaderForLowModel: ".concat(e)), this._materialManager.allowYUVUpdate(), new Promise(function (t, r) {
  11172. _this5._materialManager._isInDynamicRange(e) == !1 && r(!1), _this5._currentPanoId = e, _this5._currentShader = _this5._materialManager.getDynamicShader(e), _this5.changeShaderForLowModel().then(function () {
  11173. t(!0);
  11174. });
  11175. });
  11176. }
  11177. }, {
  11178. key: "changeVideoShaderForLowModel",
  11179. value: function changeVideoShaderForLowModel() {
  11180. return logger$1.info("[Engine] changeVideoShaderForLowModel"), this._currentShader = this._materialManager.getPureVideoShader(), this._materialManager.allowYUVUpdate(), this.changeShaderForLowModel();
  11181. }
  11182. }, {
  11183. key: "changeDefaultShaderForLowModel",
  11184. value: function changeDefaultShaderForLowModel() {
  11185. return logger$1.info("[Engine] changeDefaultShaderForLowModel"), this._currentShader = this._materialManager.getDefaultShader(), this._materialManager.stopYUVUpdate(), this.changeShaderForLowModel();
  11186. }
  11187. }, {
  11188. key: "changeShaderForLowModel",
  11189. value: function changeShaderForLowModel() {
  11190. var _this6 = this;
  11191. return new Promise(function (e, t) {
  11192. _this6._lowpolyManager.getMeshes().forEach(function (r) {
  11193. r.setMaterial(_this6._currentShader);
  11194. }), _this6._lowpolyManager.getCgMesh().mesh.material = _this6._currentShader, e(!0);
  11195. });
  11196. }
  11197. }, {
  11198. key: "setIBL",
  11199. value: function setIBL(e) {
  11200. this._lightManager.setIBL(e);
  11201. }
  11202. }, {
  11203. key: "postprocessing",
  11204. value: function postprocessing() {
  11205. var e = new BABYLON.DefaultRenderingPipeline("default", !0, this.scene);
  11206. e.imageProcessingEnabled = !1, e.bloomEnabled = !0, e.bloomThreshold = 1, e.bloomWeight = 1, e.bloomKernel = 64, e.bloomScale = .1;
  11207. }
  11208. }, {
  11209. key: "getGround",
  11210. value: function getGround(e) {
  11211. var t = this._lowpolyManager.getMeshes(),
  11212. r = [];
  11213. return t.forEach(function (n) {
  11214. n.mesh.name.indexOf("SM_Stage") >= 0 && r.push(n.mesh);
  11215. }), this.Scene.meshes.forEach(function (n) {
  11216. n.name.split("_")[0] === "ground" && r.push(n);
  11217. }), r;
  11218. }
  11219. }]);
  11220. return XSceneManager;
  11221. }();
  11222. 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); }; }
  11223. 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; } }
  11224. var InitEngineTimeoutError = /*#__PURE__*/function (_XverseError) {
  11225. _inherits(InitEngineTimeoutError, _XverseError);
  11226. var _super = _createSuper$3(InitEngineTimeoutError);
  11227. function InitEngineTimeoutError(e) {
  11228. _classCallCheck(this, InitEngineTimeoutError);
  11229. return _super.call(this, 1010, e || "\u5F15\u64CE\u521D\u59CB\u5316\u8D85\u65F6");
  11230. }
  11231. return _createClass(InitEngineTimeoutError);
  11232. }(XverseError);
  11233. var http = new Http();
  11234. var urlMap = new Map(),
  11235. urlTransformer = /*#__PURE__*/function () {
  11236. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(i) {
  11237. var e,
  11238. _args2 = arguments;
  11239. return regenerator.wrap(function _callee2$(_context2) {
  11240. while (1) {
  11241. switch (_context2.prev = _context2.next) {
  11242. case 0:
  11243. e = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : !1;
  11244. return _context2.abrupt("return", typeof i != "string" ? (console.warn("url transformer error", i), i) : i.startsWith("blob:") ? i : e ? http.get({
  11245. url: i,
  11246. useIndexedDb: !0,
  11247. key: "url",
  11248. isOutPutObjectURL: !1
  11249. }) : urlMap.has(i) ? urlMap.get(i) : http.get({
  11250. url: i,
  11251. useIndexedDb: !0,
  11252. key: "url"
  11253. }).then(function (t) {
  11254. return urlMap.set(i, t), t;
  11255. }));
  11256. case 2:
  11257. case "end":
  11258. return _context2.stop();
  11259. }
  11260. }
  11261. }, _callee2);
  11262. }));
  11263. return function urlTransformer(_x2) {
  11264. return _ref2.apply(this, arguments);
  11265. };
  11266. }();
  11267. var sceneManager;
  11268. function getSceneManager(i, e) {
  11269. return sceneManager || (sceneManager = new XSceneManager(i, e)), sceneManager;
  11270. }
  11271. var EngineProxy = /*#__PURE__*/function () {
  11272. function EngineProxy(e) {
  11273. var _this = this;
  11274. _classCallCheck(this, EngineProxy);
  11275. E(this, "_tvs", []);
  11276. E(this, "isRenderFirstFrame", !1);
  11277. E(this, "_idleTime", 0);
  11278. E(this, "renderTimer");
  11279. E(this, "lightManager");
  11280. E(this, "_checkSceneNotReadyCount", 0);
  11281. E(this, "_checkSceneDurationFrameNum", 0);
  11282. E(this, "_checkSceneFrameCount", 0);
  11283. E(this, "timeoutCircularArray", new CircularArray(120, !1, []));
  11284. E(this, "frameCircularArray", new CircularArray(120, !1, []));
  11285. E(this, "interFrameCircularArray", new CircularArray(120, !1, []));
  11286. E(this, "drawCallCntCircularArray", new CircularArray(120, !1, []));
  11287. E(this, "activeFacesCircularArray", new CircularArray(120, !1, []));
  11288. E(this, "renderTimeCircularArray", new CircularArray(120, !1, []));
  11289. E(this, "drawCallTimeCircularArray", new CircularArray(120, !1, []));
  11290. E(this, "animationCircularArray", new CircularArray(120, !1, []));
  11291. E(this, "meshSelectCircularArray", new CircularArray(120, !1, []));
  11292. E(this, "renderTargetCircularArray", new CircularArray(120, !1, []));
  11293. E(this, "regBeforeRenderCircularArray", new CircularArray(120, !1, []));
  11294. E(this, "regAfterRenderCircularArray", new CircularArray(120, !1, []));
  11295. E(this, "renderCnt", 0);
  11296. E(this, "renderErrorCount", 0);
  11297. E(this, "engineSloppyCnt", 0);
  11298. E(this, "systemStuckCnt", 0);
  11299. E(this, "frameRenderNumber", 0);
  11300. E(this, "_setFPS", function (e) {
  11301. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 25;
  11302. logger$1.info("Set fps to", t);
  11303. var r = t > 60 ? 60 : t < 24 ? 24 : t;
  11304. e.Engine.stopRenderLoop();
  11305. var n = 1e3 / r;
  11306. var o = Date.now(),
  11307. a = Date.now(),
  11308. s = n,
  11309. l = 1;
  11310. var u = function u() {
  11311. var T;
  11312. var c = Date.now(),
  11313. h = c - o,
  11314. f = c - a;
  11315. a = c, _this.frameCircularArray.add(f), h - s > n && (_this.systemStuckCnt += 1);
  11316. var d = h / s;
  11317. l = .9 * l + .1 * d;
  11318. var _ = Date.now();
  11319. var g = 0,
  11320. m = 0;
  11321. if (_this.room.isUpdatedRawYUVData || _this.room.isPano) {
  11322. if (_this.isRenderFirstFrame = !0, _this._checkSceneDurationFrameNum > 0) _this._checkSceneFrameCount++, _this.room.sceneManager.isReadyToRender({}) && _this._checkSceneDurationFrameNum--, _this._checkSceneFrameCount > EngineProxy._CHECK_DURATION && (_this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION, _this._checkSceneFrameCount = 0, _this._checkSceneNotReadyCount++, (_this._checkSceneNotReadyCount == 1 || _this._checkSceneNotReadyCount % 100 == 0) && logger$1.error("[SDK] Scene not ready, skip render. loop: ".concat(_this._checkSceneNotReadyCount)), _this._checkSceneNotReadyCount > 10 && (logger$1.error("[SDK] Scene not ready, reload later"), _this.room.proxyEvents("renderError", {
  11323. error: new Error("[SDK] Scene not ready, skip render and reload.")
  11324. })), _this.room.stats.assign({
  11325. renderErrorCount: _this._checkSceneNotReadyCount
  11326. }), logger$1.infoAndReportMeasurement({
  11327. value: 0,
  11328. startTime: Date.now(),
  11329. metric: "renderError",
  11330. error: new Error("[SDK] Scene not ready, skip render and reload."),
  11331. reportOptions: {
  11332. sampleRate: .1
  11333. }
  11334. }));else try {
  11335. e.render();
  11336. } catch (C) {
  11337. _this.renderErrorCount++, _this.renderErrorCount > 10 && _this.room.proxyEvents("renderError", {
  11338. error: C
  11339. }), _this.room.stats.assign({
  11340. renderErrorCount: _this.renderErrorCount
  11341. }), logger$1.infoAndReportMeasurement({
  11342. value: 0,
  11343. startTime: Date.now(),
  11344. metric: "renderError",
  11345. error: C,
  11346. reportOptions: {
  11347. sampleRate: .1
  11348. }
  11349. });
  11350. }
  11351. g = Date.now() - _, _this.frameRenderNumber < 1e3 && _this.frameRenderNumber++, _this.room.networkController.rtcp.workers.UpdateYUV(), m = Date.now() - _ - g;
  11352. }
  11353. _this.isRenderFirstFrame || _this.room.networkController.rtcp.workers.UpdateYUV();
  11354. var y = Date.now() - _;
  11355. o = c + y, s = Math.min(Math.max((n - y) / l, 5), 200), y > n && (s = 10, _this.engineSloppyCnt += 1), _this._idleTime = s;
  11356. var b = s;
  11357. 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) {
  11358. var C = _this.frameCircularArray.getAvg(),
  11359. A = _this.timeoutCircularArray.getAvg(),
  11360. S = _this.frameCircularArray.getMax(),
  11361. P = _this.timeoutCircularArray.getMax();
  11362. (T = _this.room.stats) == null || T.assign({
  11363. avgFrameTime: C,
  11364. avgTimeoutTime: A,
  11365. maxFrameTime: S,
  11366. maxTimeoutTime: P,
  11367. systemStuckCnt: _this.systemStuckCnt
  11368. });
  11369. }
  11370. _this.renderTimer = window.setTimeout(u, s);
  11371. };
  11372. _this.renderTimer = window.setTimeout(u, n / l);
  11373. });
  11374. E(this, "updateStats", function () {
  11375. var e;
  11376. (e = _this.room.stats) == null || e.assign({
  11377. renderFrameTime: _this.renderTimeCircularArray.getAvg(),
  11378. maxRenderFrameTime: _this.renderTimeCircularArray.getMax(),
  11379. interFrameTime: _this.interFrameCircularArray.getAvg(),
  11380. animationTime: _this.animationCircularArray.getAvg(),
  11381. meshSelectTime: _this.meshSelectCircularArray.getAvg(),
  11382. drawcallTime: _this.drawCallTimeCircularArray.getAvg(),
  11383. idleTime: _this._idleTime,
  11384. registerBeforeRenderTime: _this.regBeforeRenderCircularArray.getAvg(),
  11385. registerAfterRenderTime: _this.regAfterRenderCircularArray.getAvg(),
  11386. renderTargetRenderTime: _this.renderTargetCircularArray.getAvg(),
  11387. fps: (1e3 / (_this.renderTimeCircularArray.getAvg() + _this.interFrameCircularArray.getAvg())).toFixed(2),
  11388. drawcall: _this.drawCallCntCircularArray.getAvg(),
  11389. engineSloppyCnt: _this.engineSloppyCnt,
  11390. maxInterFrameTime: _this.interFrameCircularArray.getMax(),
  11391. maxDrawcallTime: _this.drawCallTimeCircularArray.getMax(),
  11392. maxMeshSelectTime: _this.meshSelectCircularArray.getMax(),
  11393. maxAnimationTime: _this.animationCircularArray.getMax(),
  11394. maxRegisterBeforeRenderTime: _this.regBeforeRenderCircularArray.getMax(),
  11395. maxRegisterAfterRenderTime: _this.regAfterRenderCircularArray.getMax(),
  11396. maxRenderTargetRenderTime: _this.renderTargetCircularArray.getMax(),
  11397. avgFrameTime: _this.frameCircularArray.getAvg(),
  11398. avgTimeoutTime: _this.timeoutCircularArray.getAvg(),
  11399. maxFrameTime: _this.frameCircularArray.getMax(),
  11400. maxTimeoutTime: _this.timeoutCircularArray.getMax()
  11401. });
  11402. });
  11403. this.room = e;
  11404. }
  11405. _createClass(EngineProxy, [{
  11406. key: "initEngine",
  11407. value: function () {
  11408. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  11409. var t, r, n, o, a;
  11410. return regenerator.wrap(function _callee3$(_context3) {
  11411. while (1) {
  11412. switch (_context3.prev = _context3.next) {
  11413. case 0:
  11414. _context3.next = 2;
  11415. return this.updateBillboard();
  11416. case 2:
  11417. logger$1.info("engine version:", VERSION$1);
  11418. t = logger$1;
  11419. t.setLevel(LoggerLevels$1.Warn);
  11420. r = {
  11421. videoResOriArray: [{
  11422. width: 720,
  11423. height: 1280
  11424. }, {
  11425. width: 1280,
  11426. height: 720
  11427. }, {
  11428. width: 480,
  11429. height: 654
  11430. }, {
  11431. width: 654,
  11432. height: 480
  11433. }, {
  11434. width: 1920,
  11435. height: 1080
  11436. }, {
  11437. width: 1080,
  11438. height: 1920
  11439. }, {
  11440. width: 414,
  11441. height: 896
  11442. }],
  11443. forceKeepVertical: this.room.options.objectFit !== "cover",
  11444. panoInfo: {
  11445. dynamicRange: 1,
  11446. width: 4096,
  11447. height: 2048
  11448. },
  11449. shaderMode: EShaderMode.videoAndPano,
  11450. yuvInfo: {
  11451. width: 1280,
  11452. height: 720,
  11453. fov: e.fov || DEFAULT_MAIN_CAMERA_FOV
  11454. },
  11455. cameraParam: {
  11456. maxZ: 1e4
  11457. },
  11458. urlTransformer,
  11459. logger: t,
  11460. disableWebGL2: this.room.options.disableWebGL2 || !1
  11461. }, n = this.room.options.resolution;
  11462. n && (r.videoResOriArray.some(function (l) {
  11463. return l.width === n.width && l.height === n.height;
  11464. }) || r.videoResOriArray.push(n));
  11465. o = this.room.sceneManager = getSceneManager(this.room.canvas, r);
  11466. this.room.setPictureQualityLevel(this.room.options.pictureQualityLevel || "high");
  11467. this.room.sceneManager.staticmeshComponent.setRegionLodRule([2, 2, -1, -1, -1]);
  11468. this.room.scene = o.Scene;
  11469. this.room.breathPointManager = o.breathPointComponent;
  11470. this.lightManager = o.lightComponent;
  11471. this.registerStats();
  11472. this.setEnv(e);
  11473. _context3.next = 17;
  11474. return this.room.avatarManager.init();
  11475. case 17:
  11476. a = this._createAssetList(e);
  11477. _context3.next = 20;
  11478. return this.loadAssets(a, "");
  11479. case 20:
  11480. this._setFPS(o);
  11481. case 21:
  11482. case "end":
  11483. return _context3.stop();
  11484. }
  11485. }
  11486. }, _callee3, this);
  11487. }));
  11488. function initEngine(_x3) {
  11489. return _initEngine.apply(this, arguments);
  11490. }
  11491. return initEngine;
  11492. }()
  11493. }, {
  11494. key: "pause",
  11495. value: function pause() {
  11496. clearTimeout(this.renderTimer), logger$1.info("Invoke room.pause to pause render");
  11497. var e = {
  11498. roomId: this.room.id,
  11499. effects: [],
  11500. lowPolyModels: [],
  11501. breathPointsConfig: [],
  11502. skinId: this.room.skinId
  11503. };
  11504. return this.loadAssets(e, this.room.skinId);
  11505. }
  11506. }, {
  11507. key: "resume",
  11508. value: function () {
  11509. var _resume = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  11510. var e;
  11511. return regenerator.wrap(function _callee4$(_context4) {
  11512. while (1) {
  11513. switch (_context4.prev = _context4.next) {
  11514. case 0:
  11515. this._setFPS(this.room.sceneManager), this.room.sceneManager.cameraComponent.cameraFovChange(this.room.sceneManager.yuvInfo), logger$1.info("Invoke room.resume to render");
  11516. e = this._createAssetList(this.room.skin);
  11517. _context4.next = 4;
  11518. return this.loadAssets(e, "");
  11519. case 4:
  11520. case "end":
  11521. return _context4.stop();
  11522. }
  11523. }
  11524. }, _callee4, this);
  11525. }));
  11526. function resume() {
  11527. return _resume.apply(this, arguments);
  11528. }
  11529. return resume;
  11530. }()
  11531. }, {
  11532. key: "setEnv",
  11533. value: function setEnv(e) {
  11534. var r;
  11535. this.lightManager || (this.lightManager = this.room.sceneManager.lightComponent), e = e || this.room.skin;
  11536. var t = ModelManager.findModel(e.models, AssetTypeName.Config, AssetClassName.Env);
  11537. return t ? (r = this.lightManager) == null ? void 0 : r.setIBL(t.modelUrl) : (logger$1.error("env file not found"), Promise.resolve());
  11538. }
  11539. }, {
  11540. key: "_parseModelsAndLoad",
  11541. value: function () {
  11542. var _parseModelsAndLoad2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e, t, r) {
  11543. var n, o, a, u, c, h, _c, s, l, _u, _c2, _h;
  11544. return regenerator.wrap(function _callee5$(_context5) {
  11545. while (1) {
  11546. switch (_context5.prev = _context5.next) {
  11547. case 0:
  11548. logger$1.info("Invoke _parseModelsAndLoad start", t);
  11549. n = ["airship", "balloon", "default", "ground_feiting", "ground_reqiqiu"], o = new Map();
  11550. r == null && (r = "xxxx");
  11551. a = !0;
  11552. u = 0;
  11553. case 5:
  11554. if (!(u < e.length)) {
  11555. _context5.next = 20;
  11556. break;
  11557. }
  11558. a = !0;
  11559. c = 0;
  11560. case 8:
  11561. if (!(c < n.length)) {
  11562. _context5.next = 16;
  11563. break;
  11564. }
  11565. if (!(e[u].modelUrl.toLowerCase().indexOf(n[c]) >= 0)) {
  11566. _context5.next = 13;
  11567. break;
  11568. }
  11569. h = o.get(n[c]);
  11570. h ? (h.push(e[u]), o.set(n[c], h)) : o.set(n[c], [e[u]]), a = !1;
  11571. return _context5.abrupt("break", 16);
  11572. case 13:
  11573. ++c;
  11574. _context5.next = 8;
  11575. break;
  11576. case 16:
  11577. if (a) {
  11578. _c = o.get("default");
  11579. _c ? (_c.push(e[u]), o.set("default", _c)) : o.set("default", [e[u]]);
  11580. }
  11581. case 17:
  11582. ++u;
  11583. _context5.next = 5;
  11584. break;
  11585. case 20:
  11586. s = o.get(t) || [];
  11587. if (!(this.room.viewMode === "simple" && (s = s.filter(function (u) {
  11588. return !u.modelUrl.endsWith("zip");
  11589. })), !s)) {
  11590. _context5.next = 23;
  11591. break;
  11592. }
  11593. return _context5.abrupt("return", Promise.reject("no invalid scene model with group name: ".concat(t)));
  11594. case 23:
  11595. l = [];
  11596. for (_u = 0; _u < s.length; ++_u) {
  11597. _c2 = s[_u];
  11598. if (_c2.modelUrl.toLowerCase().endsWith("zip")) _c2.modelUrl.toLowerCase().endsWith("zip") && l.push(this.room.sceneManager.addNewLowPolyMesh({
  11599. url: _c2.modelUrl,
  11600. skinInfo: r
  11601. }));else {
  11602. _h = t;
  11603. l.push(this.room.sceneManager.addNewLowPolyMesh({
  11604. url: _c2.modelUrl,
  11605. group: _h,
  11606. pick: !0,
  11607. skinInfo: r
  11608. }));
  11609. }
  11610. }
  11611. return _context5.abrupt("return", Promise.all(l));
  11612. case 26:
  11613. case "end":
  11614. return _context5.stop();
  11615. }
  11616. }
  11617. }, _callee5, this);
  11618. }));
  11619. function _parseModelsAndLoad(_x4, _x5, _x6) {
  11620. return _parseModelsAndLoad2.apply(this, arguments);
  11621. }
  11622. return _parseModelsAndLoad;
  11623. }()
  11624. }, {
  11625. key: "_deleteAssetsLowpolyModel",
  11626. value: function () {
  11627. var _deleteAssetsLowpolyModel2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  11628. var t;
  11629. return regenerator.wrap(function _callee6$(_context6) {
  11630. while (1) {
  11631. switch (_context6.prev = _context6.next) {
  11632. case 0:
  11633. this.room.sceneManager.staticmeshComponent.deleteMeshesBySkinInfo(e), this.room.sceneManager.breathPointComponent.clearBreathPointsBySkinInfo(e), this.room.sceneManager.decalComponent.deleteDecalBySkinInfo(e);
  11634. t = [];
  11635. this.room.sceneManager.Scene.meshes.forEach(function (r) {
  11636. r.xskinInfo == e && t.push(r);
  11637. }), t.forEach(function (r) {
  11638. r.dispose(!1, !1);
  11639. });
  11640. case 3:
  11641. case "end":
  11642. return _context6.stop();
  11643. }
  11644. }
  11645. }, _callee6, this);
  11646. }));
  11647. function _deleteAssetsLowpolyModel(_x7) {
  11648. return _deleteAssetsLowpolyModel2.apply(this, arguments);
  11649. }
  11650. return _deleteAssetsLowpolyModel;
  11651. }()
  11652. }, {
  11653. key: "loadLandAssets",
  11654. value: function () {
  11655. var _loadLandAssets = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7() {
  11656. var _this2 = this;
  11657. var e;
  11658. return regenerator.wrap(function _callee7$(_context7) {
  11659. while (1) {
  11660. switch (_context7.prev = _context7.next) {
  11661. case 0:
  11662. e = this._createAssetList(this.room.skin);
  11663. return _context7.abrupt("return", this.loadAssets(e, this.room.skinId).catch(function () {
  11664. return _this2.loadAssets(e, _this2.room.skinId);
  11665. }));
  11666. case 2:
  11667. case "end":
  11668. return _context7.stop();
  11669. }
  11670. }
  11671. }, _callee7, this);
  11672. }));
  11673. function loadLandAssets() {
  11674. return _loadLandAssets.apply(this, arguments);
  11675. }
  11676. return loadLandAssets;
  11677. }()
  11678. }, {
  11679. key: "loadAssets",
  11680. value: function () {
  11681. var _loadAssets2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8(e) {
  11682. var t,
  11683. r,
  11684. n,
  11685. _args8 = arguments;
  11686. return regenerator.wrap(function _callee8$(_context8) {
  11687. while (1) {
  11688. switch (_context8.prev = _context8.next) {
  11689. case 0:
  11690. t = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : "";
  11691. r = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : 8e3;
  11692. n = Date.now();
  11693. return _context8.abrupt("return", this._loadAssets(e, t)._timeout(r, new InitEngineTimeoutError("loadAssets timeout(".concat(r, "ms)"))).then(function (o) {
  11694. return logger$1.infoAndReportMeasurement({
  11695. tag: "loadAssets",
  11696. startTime: n,
  11697. metric: "loadAssets"
  11698. }), o;
  11699. }).catch(function (o) {
  11700. return logger$1.infoAndReportMeasurement({
  11701. tag: "loadAssets",
  11702. startTime: n,
  11703. metric: "loadAssets",
  11704. error: o
  11705. }), Promise.reject(o);
  11706. }));
  11707. case 4:
  11708. case "end":
  11709. return _context8.stop();
  11710. }
  11711. }
  11712. }, _callee8, this);
  11713. }));
  11714. function loadAssets(_x8) {
  11715. return _loadAssets2.apply(this, arguments);
  11716. }
  11717. return loadAssets;
  11718. }()
  11719. }, {
  11720. key: "_loadAssets",
  11721. value: function () {
  11722. var _loadAssets3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(e) {
  11723. var t,
  11724. r,
  11725. _args9 = arguments;
  11726. return regenerator.wrap(function _callee9$(_context9) {
  11727. while (1) {
  11728. switch (_context9.prev = _context9.next) {
  11729. case 0:
  11730. t = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : "";
  11731. _context9.prev = 1;
  11732. r = [];
  11733. r.push(this._loadAssetsLowpolyModel(e, t));
  11734. _context9.next = 6;
  11735. return Promise.all(r);
  11736. case 6:
  11737. _context9.next = 8;
  11738. return this.setEnv();
  11739. case 8:
  11740. this._checkSceneDurationFrameNum = EngineProxy._CHECK_DURATION;
  11741. this._checkSceneNotReadyCount = 0;
  11742. this._checkSceneFrameCount = 0;
  11743. this.updateAnimationList();
  11744. this.room.loadAssetsHook();
  11745. _context9.next = 18;
  11746. break;
  11747. case 15:
  11748. _context9.prev = 15;
  11749. _context9.t0 = _context9["catch"](1);
  11750. return _context9.abrupt("return", Promise.reject(_context9.t0));
  11751. case 18:
  11752. case "end":
  11753. return _context9.stop();
  11754. }
  11755. }
  11756. }, _callee9, this, [[1, 15]]);
  11757. }));
  11758. function _loadAssets(_x9) {
  11759. return _loadAssets3.apply(this, arguments);
  11760. }
  11761. return _loadAssets;
  11762. }()
  11763. }, {
  11764. key: "updateAnimationList",
  11765. value: function updateAnimationList() {
  11766. var _this3 = this;
  11767. if (this.room.avatarManager && this.room.avatarManager.xAvatarManager) {
  11768. var e = this.room.skin.animationList;
  11769. if (!e) return;
  11770. e.forEach(function (t) {
  11771. _this3.room.avatarManager.xAvatarManager.updateAnimationLists(t.animations, t.avatarId);
  11772. });
  11773. }
  11774. }
  11775. }, {
  11776. key: "_loadAssetsLowpolyModel",
  11777. value: function () {
  11778. var _loadAssetsLowpolyModel2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  11779. var _this4 = this;
  11780. var t,
  11781. r,
  11782. n,
  11783. o,
  11784. a,
  11785. s,
  11786. u,
  11787. c,
  11788. h,
  11789. _args11 = arguments;
  11790. return regenerator.wrap(function _callee11$(_context11) {
  11791. while (1) {
  11792. switch (_context11.prev = _context11.next) {
  11793. case 0:
  11794. t = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : "";
  11795. r = [], n = [], o = [];
  11796. e.lowPolyModels.forEach(function (f) {
  11797. f.group === "TV" ? n.push({
  11798. id: "",
  11799. name: "",
  11800. thumbnailUrl: "",
  11801. typeName: AssetTypeName.Model,
  11802. className: AssetClassName.Tv,
  11803. modelUrl: f.url
  11804. }) : f.group === "\u544A\u767D\u5899" ? o.push({
  11805. id: "",
  11806. name: "",
  11807. thumbnailUrl: "",
  11808. typeName: AssetTypeName.Model,
  11809. className: AssetClassName.Lpm,
  11810. modelUrl: f.url
  11811. }) : r.push({
  11812. id: "",
  11813. name: "",
  11814. thumbnailUrl: "",
  11815. typeName: AssetTypeName.Model,
  11816. className: AssetClassName.Lpm,
  11817. modelUrl: f.url
  11818. });
  11819. }), t != "" && t != null && this._deleteAssetsLowpolyModel(t);
  11820. a = e.skinId;
  11821. logger$1.info("====> from ", t, " to ", a), this._tvs.forEach(function (f) {
  11822. return f.clean();
  11823. }), this._tvs = [];
  11824. s = EFitMode.cover;
  11825. a == "10048" && (s = EFitMode.contain), Array.isArray(n) && n.forEach(function (f, d) {
  11826. _this4._tvs.push(new TV("squareTv" + d, f.modelUrl, _this4.room, {
  11827. fitMode: s
  11828. }));
  11829. }), e.breathPointsConfig.forEach( /*#__PURE__*/function () {
  11830. var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(f) {
  11831. var d;
  11832. return regenerator.wrap(function _callee10$(_context10) {
  11833. while (1) {
  11834. switch (_context10.prev = _context10.next) {
  11835. case 0:
  11836. _context10.prev = 0;
  11837. _context10.next = 3;
  11838. return urlTransformer(f.imageUrl);
  11839. case 3:
  11840. d = _context10.sent;
  11841. _context10.next = 9;
  11842. break;
  11843. case 6:
  11844. _context10.prev = 6;
  11845. _context10.t0 = _context10["catch"](0);
  11846. d = f.imageUrl, logger$1.error("urlTransformer error", _context10.t0);
  11847. case 9:
  11848. _this4.room.breathPointManager.addBreathPoint({
  11849. id: f.id,
  11850. position: f.position,
  11851. spriteSheet: d,
  11852. rotation: f.rotation || {
  11853. pitch: 0,
  11854. yaw: 270,
  11855. roll: 0
  11856. },
  11857. billboardMode: !0,
  11858. type: f.type || "no_type",
  11859. spriteWidthNumber: f.spriteWidthNum || 1,
  11860. spriteHeightNumber: f.spriteHeightNum || 1,
  11861. maxVisibleRegion: f.maxVisibleRegion || 150,
  11862. width: f.width,
  11863. height: f.height,
  11864. skinInfo: f.skinId
  11865. });
  11866. case 10:
  11867. case "end":
  11868. return _context10.stop();
  11869. }
  11870. }
  11871. }, _callee10, null, [[0, 6]]);
  11872. }));
  11873. return function (_x11) {
  11874. return _ref3.apply(this, arguments);
  11875. };
  11876. }()), o.forEach(function (f) {
  11877. _this4.room.sceneManager.decalComponent.addDecal({
  11878. id: f.id || "gbq",
  11879. meshPath: f.modelUrl,
  11880. skinInfo: a
  11881. });
  11882. });
  11883. u = this.room.sceneManager.staticmeshComponent.lowModel_group, c = Array.from(u.keys()).filter(function (f) {
  11884. return !f.startsWith("region_");
  11885. }), h = ["airship", "balloon", "ground_feiting", "ground_reqiqiu", "default"];
  11886. return _context11.abrupt("return", new Promise(function (f, d) {
  11887. Promise.all(h.map(function (_) {
  11888. return _this4._parseModelsAndLoad(r, _, a);
  11889. })).then(function () {
  11890. var _ = !1;
  11891. r.forEach(function (v) {
  11892. v.modelUrl.endsWith("zip") && (_ = !0);
  11893. }), _ == !1 && _this4.room.sceneManager.staticmeshComponent.deleteLastRegionMesh(), _this4.room.sceneManager.staticmeshComponent.lowModel_group;
  11894. var g = Array.from(u.keys()).filter(function (v) {
  11895. return !v.startsWith("region_");
  11896. }),
  11897. m = c.filter(function (v) {
  11898. return g.indexOf(v) < 0;
  11899. });
  11900. m.length > 0 && m.forEach(function (v) {
  11901. _this4.room.sceneManager.staticmeshComponent.deleteMeshesByGroup(v);
  11902. }), f(!0);
  11903. }).catch(function (_) {
  11904. d(_);
  11905. });
  11906. }));
  11907. case 9:
  11908. case "end":
  11909. return _context11.stop();
  11910. }
  11911. }
  11912. }, _callee11, this);
  11913. }));
  11914. function _loadAssetsLowpolyModel(_x10) {
  11915. return _loadAssetsLowpolyModel2.apply(this, arguments);
  11916. }
  11917. return _loadAssetsLowpolyModel;
  11918. }()
  11919. }, {
  11920. key: "_updateSkinAssets",
  11921. value: function () {
  11922. var _updateSkinAssets2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee12(e) {
  11923. var t, r, n;
  11924. return regenerator.wrap(function _callee12$(_context12) {
  11925. while (1) {
  11926. switch (_context12.prev = _context12.next) {
  11927. case 0:
  11928. t = this.room.lastSkinId;
  11929. _context12.next = 3;
  11930. return this.room.getSkin(e);
  11931. case 3:
  11932. r = _context12.sent;
  11933. n = this._createAssetList(r);
  11934. _context12.prev = 5;
  11935. _context12.next = 8;
  11936. return this.loadAssets(n, t);
  11937. case 8:
  11938. this.room.updateCurrentState({
  11939. versionId: r.versionId,
  11940. skinId: r.id,
  11941. skin: r
  11942. });
  11943. _context12.next = 16;
  11944. break;
  11945. case 11:
  11946. _context12.prev = 11;
  11947. _context12.t0 = _context12["catch"](5);
  11948. _context12.next = 15;
  11949. return this.loadAssets(n, t);
  11950. case 15:
  11951. this.room.updateCurrentState({
  11952. versionId: r.versionId,
  11953. skinId: r.id,
  11954. skin: r
  11955. });
  11956. case 16:
  11957. this.setEnv(r);
  11958. case 17:
  11959. case "end":
  11960. return _context12.stop();
  11961. }
  11962. }
  11963. }, _callee12, this, [[5, 11]]);
  11964. }));
  11965. function _updateSkinAssets(_x12) {
  11966. return _updateSkinAssets2.apply(this, arguments);
  11967. }
  11968. return _updateSkinAssets;
  11969. }()
  11970. }, {
  11971. key: "_createAssetList",
  11972. value: function _createAssetList(e) {
  11973. var t = [],
  11974. r = [],
  11975. n = [];
  11976. var o = e.models;
  11977. var a = this.room.modelManager.config.preload;
  11978. return this.room.viewMode === "simple" ? a && (o = a.baseUrls.map(function (l) {
  11979. return l.modelUrl = l.url, l;
  11980. })) : this.room.viewMode, ModelManager.findModels(o, AssetTypeName.Effects, AssetClassName.Effects).forEach(function (l) {
  11981. t.push({
  11982. url: l.modelUrl,
  11983. group: l.className,
  11984. name: l.name
  11985. });
  11986. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Lpm).forEach(function (l) {
  11987. r.push({
  11988. url: l.modelUrl,
  11989. group: l.className
  11990. });
  11991. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Gbq).forEach(function (l) {
  11992. r.push({
  11993. url: l.modelUrl,
  11994. group: l.className
  11995. });
  11996. }), ModelManager.findModels(o, AssetTypeName.Model, AssetClassName.Tv).forEach(function (l) {
  11997. r.push({
  11998. url: l.modelUrl,
  11999. group: l.className
  12000. });
  12001. }), [].forEach(function (l) {
  12002. l.skinId == e.id && n.push(l);
  12003. }), {
  12004. roomId: this.room.id,
  12005. effects: t,
  12006. lowPolyModels: r,
  12007. breathPointsConfig: n,
  12008. skinId: e.id
  12009. };
  12010. }
  12011. }, {
  12012. key: "registerStats",
  12013. value: function registerStats() {
  12014. var _this5 = this;
  12015. var e = this.room.sceneManager;
  12016. this.room.scene.registerAfterRender(function () {
  12017. var I;
  12018. var t = e.statisticComponent.getInterFrameTimeCounter(),
  12019. r = e.statisticComponent.getDrawCall(),
  12020. n = e.statisticComponent.getActiveFaces(),
  12021. o = e.statisticComponent.getFrameTimeCounter(),
  12022. a = e.statisticComponent.getDrawCallTime(),
  12023. s = e.statisticComponent.getAnimationTime(),
  12024. l = e.statisticComponent.getActiveMeshEvaluationTime(),
  12025. u = e.statisticComponent.getRenderTargetRenderTime(),
  12026. c = e.statisticComponent.getRegisterBeforeRenderTime(),
  12027. h = e.statisticComponent.getRegisterAfterRenderTime(),
  12028. f = e.statisticComponent.getActiveParticles(),
  12029. d = e.statisticComponent.getActiveBones(),
  12030. _ = e.Scene._activeAnimatables.length,
  12031. g = e.statisticComponent.getTotalRootNodes(),
  12032. m = e.Scene.geometries.length,
  12033. v = e.Scene.onBeforeRenderObservable.observers.length,
  12034. y = e.Scene.onAfterRenderObservable.observers.length,
  12035. b = e.statisticComponent.getTotalMeshes(),
  12036. T = e.statisticComponent.getTotalTextures(),
  12037. C = e.statisticComponent.getTotalMaterials(),
  12038. A = e.statisticComponent.getSystemInfo(),
  12039. S = A.resolution,
  12040. P = A.driver;
  12041. A.vender;
  12042. var R = A.version,
  12043. M = A.hardwareScalingLevel,
  12044. x = S + "_" + P + "_" + R + "_" + M;
  12045. _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({
  12046. renderFrameTime: _this5.renderTimeCircularArray.getAvg(),
  12047. maxRenderFrameTime: _this5.renderTimeCircularArray.getMax(),
  12048. interFrameTime: _this5.interFrameCircularArray.getAvg(),
  12049. animationTime: _this5.animationCircularArray.getAvg(),
  12050. meshSelectTime: _this5.meshSelectCircularArray.getAvg(),
  12051. drawcallTime: _this5.drawCallTimeCircularArray.getAvg(),
  12052. idleTime: _this5._idleTime,
  12053. registerBeforeRenderTime: _this5.regBeforeRenderCircularArray.getAvg(),
  12054. registerAfterRenderTime: _this5.regAfterRenderCircularArray.getAvg(),
  12055. renderTargetRenderTime: _this5.renderTargetCircularArray.getAvg(),
  12056. fps: (1e3 / (_this5.renderTimeCircularArray.getAvg() + _this5.interFrameCircularArray.getAvg())).toFixed(2),
  12057. drawcall: _this5.drawCallCntCircularArray.getAvg(),
  12058. triangle: n.toString(),
  12059. engineSloppyCnt: _this5.engineSloppyCnt,
  12060. maxInterFrameTime: _this5.interFrameCircularArray.getMax(),
  12061. maxDrawcallTime: _this5.drawCallTimeCircularArray.getMax(),
  12062. maxMeshSelectTime: _this5.meshSelectCircularArray.getMax(),
  12063. maxAnimationTime: _this5.animationCircularArray.getMax(),
  12064. maxRegisterBeforeRenderTime: _this5.regBeforeRenderCircularArray.getMax(),
  12065. maxRegisterAfterRenderTime: _this5.regAfterRenderCircularArray.getMax(),
  12066. maxRenderTargetRenderTime: _this5.renderTargetCircularArray.getMax(),
  12067. activeParticles: f,
  12068. activeBones: d,
  12069. activeAnimation: _,
  12070. totalMeshes: b,
  12071. totalRootNodes: g,
  12072. totalGeometries: m,
  12073. totalTextures: T,
  12074. totalMaterials: C,
  12075. registerBeforeCount: v,
  12076. registerAfterCount: y,
  12077. hardwareInfo: x
  12078. }));
  12079. });
  12080. }
  12081. }, {
  12082. key: "updateBillboard",
  12083. value: function () {
  12084. var _updateBillboard = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee13() {
  12085. var e, r, n, o, a, s;
  12086. return regenerator.wrap(function _callee13$(_context13) {
  12087. while (1) {
  12088. switch (_context13.prev = _context13.next) {
  12089. case 0:
  12090. e = this.room.options.skinId;
  12091. _context13.next = 3;
  12092. return this.room.modelManager.findAssetList(e);
  12093. case 3:
  12094. r = _context13.sent.filter(function (a) {
  12095. return a.typeName === AssetTypeName.Textures && a.className === AssetClassName.SayBubble;
  12096. });
  12097. n = ["bubble01", "bubble02", "bubble03"];
  12098. o = ["bubble01_npc", "bubble02_npc", "bubble03_npc"];
  12099. if (r.length) {
  12100. a = r.filter(function (l) {
  12101. return n.includes(l.name);
  12102. }).map(function (l) {
  12103. return l.url;
  12104. }), s = r.filter(function (l) {
  12105. return o.includes(l.name);
  12106. }).map(function (l) {
  12107. return l.url;
  12108. });
  12109. a.length && (XBillboardManager.userBubbleUrls = a), s.length && (XBillboardManager.npcBubbleUrls = s);
  12110. }
  12111. case 7:
  12112. case "end":
  12113. return _context13.stop();
  12114. }
  12115. }
  12116. }, _callee13, this);
  12117. }));
  12118. function updateBillboard() {
  12119. return _updateBillboard.apply(this, arguments);
  12120. }
  12121. return updateBillboard;
  12122. }()
  12123. }]);
  12124. return EngineProxy;
  12125. }();
  12126. 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); }; }
  12127. 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; } }
  12128. var LongPressMesh = [EMeshType.XAvatar];
  12129. var StaticMeshEvent = /*#__PURE__*/function (_EventEmitter) {
  12130. _inherits(StaticMeshEvent, _EventEmitter);
  12131. var _super = _createSuper$2(StaticMeshEvent);
  12132. function StaticMeshEvent(e) {
  12133. var _this;
  12134. _classCallCheck(this, StaticMeshEvent);
  12135. _this = _super.call(this);
  12136. E(_assertThisInitialized(_this), "scene");
  12137. E(_assertThisInitialized(_this), "_staringPointerTime", -1);
  12138. E(_assertThisInitialized(_this), "_pickedMeshID", "0");
  12139. E(_assertThisInitialized(_this), "_pointerDownTime", -1);
  12140. E(_assertThisInitialized(_this), "_currentPickPoint");
  12141. E(_assertThisInitialized(_this), "_longPressDelay", 500);
  12142. E(_assertThisInitialized(_this), "_pointerTapDelay", 200);
  12143. E(_assertThisInitialized(_this), "_pickedMeshType");
  12144. E(_assertThisInitialized(_this), "registerEvent", function () {
  12145. _this.scene.onPrePointerObservable.add(_this.onDown, BABYLON.PointerEventTypes.POINTERDOWN), _this.scene.onPrePointerObservable.add(_this.onUp, BABYLON.PointerEventTypes.POINTERUP), _this.scene.onPrePointerObservable.add(_this.onDoubleTap, BABYLON.PointerEventTypes.POINTERDOUBLETAP), _this.scene.onDispose = function () {
  12146. _this.scene.onPrePointerObservable.removeCallback(_this.onUp), _this.scene.onPrePointerObservable.removeCallback(_this.onDown), _this.scene.onPrePointerObservable.removeCallback(_this.onDoubleTap);
  12147. };
  12148. });
  12149. E(_assertThisInitialized(_this), "onUp", function () {
  12150. if (Date.now() - _this._pointerDownTime < _this._pointerTapDelay && !_this.scene._inputManager._isPointerSwiping()) {
  12151. _this.scene._inputManager._totalPointersPressed = 0;
  12152. var _e = _this._currentPickPoint;
  12153. _e != null && LongPressMesh.indexOf(_e.type) == -1 && _this.scene._inputManager._totalPointersPressed == 0 && _this.emit("pointTap", _e), _e != null && LongPressMesh.indexOf(_e.type) != -1 && (_e = _this.onPointerTap(function (t) {
  12154. return t.isPickable && LongPressMesh.indexOf(t.xtype) == -1;
  12155. }), _e != null && _this.emit("pointTap", _e));
  12156. }
  12157. });
  12158. E(_assertThisInitialized(_this), "onDown", function () {
  12159. var e = _this.onPointerTap(function (t) {
  12160. return t.isPickable;
  12161. });
  12162. _this._currentPickPoint = e, _this._pointerDownTime = Date.now(), e != null && LongPressMesh.indexOf(e.type) != -1 && (_this._staringPointerTime = Date.now(), _this._pickedMeshID = e.id, _this._pickedMeshType = e.type, window.setTimeout(function () {
  12163. e = _this.onPointerTap(function (t) {
  12164. return t.isPickable && t.xtype == _this._pickedMeshType && t.xid == _this._pickedMeshID;
  12165. }), e !== null && Date.now() - _this._staringPointerTime > _this._longPressDelay && !_this.scene._inputManager._isPointerSwiping() && _this.scene._inputManager._totalPointersPressed !== 0 && (_this._staringPointerTime = 0, _this.emit("longPress", e));
  12166. }, _this._longPressDelay));
  12167. });
  12168. E(_assertThisInitialized(_this), "onDoubleTap", function () {
  12169. var e = _this.onPointerTap(void 0);
  12170. e != null && _this.emit("pointDoubleTap", e);
  12171. });
  12172. _this.manager = e, _this.scene = e.Scene, _this.registerEvent(), _this._currentPickPoint = null, _this._pickedMeshType = null;
  12173. return _this;
  12174. }
  12175. _createClass(StaticMeshEvent, [{
  12176. key: "onPointerTap",
  12177. value: function onPointerTap(e) {
  12178. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
  12179. var n, o;
  12180. var r = new BABYLON.PickingInfo();
  12181. if (t) {
  12182. var a = this.scene.multiPick(this.scene.pointerX, this.scene.pointerY, e, void 0, void 0);
  12183. a && a.length > 1 ? r = a[1] : a && (r = a[0]);
  12184. } else r = this.scene.pick(this.scene.pointerX, this.scene.pointerY, e, !1, null);
  12185. if (r.hit) {
  12186. var _a = (n = r == null ? void 0 : r.pickedPoint) == null ? void 0 : n.asArray();
  12187. if (_a) {
  12188. var _a2 = _slicedToArray(_a, 3),
  12189. s = _a2[0],
  12190. l = _a2[1],
  12191. u = _a2[2],
  12192. c = xversePosition2Ue4({
  12193. x: s,
  12194. y: l,
  12195. z: u
  12196. });
  12197. return {
  12198. name: (o = r.pickedMesh) == null ? void 0 : o.name,
  12199. type: r.pickedMesh.xtype,
  12200. id: r.pickedMesh.xid,
  12201. point: c
  12202. };
  12203. }
  12204. }
  12205. return null;
  12206. }
  12207. }]);
  12208. return StaticMeshEvent;
  12209. }(EventEmitter);
  12210. var RotationEvent = /*#__PURE__*/function () {
  12211. function RotationEvent(e) {
  12212. var _this = this;
  12213. _classCallCheck(this, RotationEvent);
  12214. E(this, "touchStartX");
  12215. E(this, "touchStartY");
  12216. E(this, "handelResize");
  12217. E(this, "_room");
  12218. E(this, "_canvas");
  12219. E(this, "handleTouchStart", function (e) {
  12220. var t = e.touches[0];
  12221. _this.touchStartX = t.pageX, _this.touchStartY = t.pageY, _this._room.emit("touchStart", {
  12222. event: e
  12223. });
  12224. });
  12225. E(this, "handleMouseDown", function (e) {
  12226. _this.touchStartX = e.pageX, _this.touchStartY = e.pageY;
  12227. });
  12228. E(this, "handleMouseMove", function (e) {
  12229. if (!_this.touchStartX || !_this.touchStartY) return;
  12230. var t = e.pageX,
  12231. r = e.pageY,
  12232. n = t - _this.touchStartX,
  12233. o = r - _this.touchStartY,
  12234. a = _this._room.options.canvas.offsetHeight,
  12235. s = _this._room.options.canvas.offsetWidth;
  12236. var l = 2 * o / a,
  12237. u = 2 * n / s;
  12238. l > 1 && (l = 1), u > 1 && (u = 1), _this._room.actionsHandler.rotate({
  12239. pitch: l,
  12240. yaw: u
  12241. }), _this.touchStartX = t, _this.touchStartY = r;
  12242. });
  12243. E(this, "handleMouseUp", function () {
  12244. _this.touchStartX = void 0, _this.touchStartY = void 0;
  12245. });
  12246. E(this, "handleTouchMove", function (e) {
  12247. if (!_this.touchStartX || !_this.touchStartY) return;
  12248. var t = e.touches[0],
  12249. r = t.pageX,
  12250. n = t.pageY,
  12251. o = r - _this.touchStartX,
  12252. a = n - _this.touchStartY,
  12253. s = _this._room.options.canvas.offsetHeight,
  12254. l = _this._room.options.canvas.offsetWidth;
  12255. var u = 2 * a / s,
  12256. c = 2 * o / l;
  12257. u > 1 && (u = 1), c > 1 && (c = 1), _this._room.actionsHandler.rotate({
  12258. pitch: u,
  12259. yaw: c
  12260. }), _this.touchStartX = r, _this.touchStartY = n, _this._room.emit("touchMove", {
  12261. pitch: u,
  12262. yaw: c,
  12263. event: e
  12264. });
  12265. });
  12266. E(this, "handleTouchEnd", function (e) {
  12267. _this._room.emit("touchEnd", {
  12268. event: e
  12269. });
  12270. });
  12271. this._room = e, this._canvas = e.canvas, this.handelResize = this.reiszeChange();
  12272. }
  12273. _createClass(RotationEvent, [{
  12274. key: "init",
  12275. value: function init() {
  12276. this._canvas.addEventListener("touchstart", this.handleTouchStart), this._canvas.addEventListener("touchmove", this.handleTouchMove), this._canvas.addEventListener("touchend", this.handleTouchEnd), this._room.scene.preventDefaultOnPointerDown = !1, this._room.scene.preventDefaultOnPointerUp = !1, this._canvas.addEventListener("mousedown", this.handleMouseDown), this._canvas.addEventListener("mousemove", this.handleMouseMove), this._canvas.addEventListener("mouseup", this.handleMouseUp);
  12277. }
  12278. }, {
  12279. key: "clear",
  12280. value: function clear() {
  12281. this._canvas.removeEventListener("touchstart", this.handleTouchStart), this._canvas.removeEventListener("touchmove", this.handleTouchMove), this._canvas.removeEventListener("touchend", this.handleTouchEnd), this._canvas.removeEventListener("mousedown", this.handleMouseDown), this._canvas.removeEventListener("mousemove", this.handleMouseMove), this._canvas.removeEventListener("mouseup", this.handleMouseUp);
  12282. }
  12283. }, {
  12284. key: "reiszeChange",
  12285. value: function reiszeChange() {
  12286. window.addEventListener("resize", function () {});
  12287. }
  12288. }]);
  12289. return RotationEvent;
  12290. }();
  12291. var EventsController = /*#__PURE__*/function () {
  12292. function EventsController(e) {
  12293. var _this = this;
  12294. _classCallCheck(this, EventsController);
  12295. E(this, "staticmeshEvent");
  12296. E(this, "rotationEvent");
  12297. E(this, "resize", function () {
  12298. _this.room.sceneManager.cameraComponent.cameraFovChange(_this.room.sceneManager.yuvInfo);
  12299. });
  12300. E(this, "clickEvent", function (e) {
  12301. var t = e.point,
  12302. r = e.name,
  12303. n = e.type,
  12304. o = e.id;
  12305. logger$1.debug("pointEvent", e), _this.room.proxyEvents("pointTap", {
  12306. point: t,
  12307. meshName: r,
  12308. type: n,
  12309. id: o
  12310. }), _this.room.proxyEvents("_coreClick", e);
  12311. });
  12312. E(this, "longPressEvent", function (e) {
  12313. _this.room.proxyEvents("_corePress", e);
  12314. });
  12315. E(this, "handleActionResponseTimeout", function (_ref) {
  12316. var e = _ref.error,
  12317. t = _ref.event;
  12318. _this.room.proxyEvents("actionResponseTimeout", {
  12319. error: e,
  12320. event: t
  12321. });
  12322. });
  12323. E(this, "handleNetworkStateChange", function (e) {
  12324. var t = e.state,
  12325. r = e.count;
  12326. t == "reconnecting" ? _this.room.proxyEvents("reconnecting", {
  12327. count: r || 1
  12328. }) : t === "reconnected" ? (_this.room.networkController.rtcp.workers.reset(), _this.room.proxyEvents("reconnected"), _this.room.afterReconnected()) : t === "disconnected" && _this.room.proxyEvents("disconnected");
  12329. });
  12330. this.room = e, this.staticmeshEvent = new StaticMeshEvent(this.room.sceneManager), this.rotationEvent = new RotationEvent(e);
  12331. }
  12332. _createClass(EventsController, [{
  12333. key: "bindEvents",
  12334. value: function bindEvents() {
  12335. window.addEventListener("orientationchange" in window ? "orientationchange" : "resize", this.resize), this.staticmeshEvent.on("pointTap", this.clickEvent), this.staticmeshEvent.on("longPress", this.longPressEvent), this.rotationEvent.init(), eventsManager.on("actionResponseTimeout", this.handleActionResponseTimeout), this.room.networkController.on("stateChanged", this.handleNetworkStateChange);
  12336. }
  12337. }, {
  12338. key: "clearEvents",
  12339. value: function clearEvents() {
  12340. window.removeEventListener("orientationchange" in window ? "orientationchange" : "resize", this.resize), this.staticmeshEvent.off("pointTap", this.clickEvent), this.staticmeshEvent.off("longPress", this.longPressEvent), eventsManager.off("actionResponseTimeout", this.handleActionResponseTimeout), this.room.networkController.off("stateChanged", this.handleNetworkStateChange), this.rotationEvent.clear();
  12341. }
  12342. }]);
  12343. return EventsController;
  12344. }();
  12345. var Panorama = /*#__PURE__*/function () {
  12346. function Panorama(e) {
  12347. var _this = this;
  12348. _classCallCheck(this, Panorama);
  12349. E(this, "_actived", !1);
  12350. E(this, "handleReceivePanorama", /*#__PURE__*/function () {
  12351. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  12352. var r, n, _this$room$currentSta, o, a, s, _ref2, l;
  12353. return regenerator.wrap(function _callee$(_context) {
  12354. while (1) {
  12355. switch (_context.prev = _context.next) {
  12356. case 0:
  12357. logger$1.warn("handle panorama", e.uuid, e.pos, e.finished);
  12358. r = {
  12359. data: e.data,
  12360. pose: {
  12361. position: e.pos
  12362. }
  12363. }, n = _this.room.sceneManager;
  12364. _this.room.networkController.rtcp.workers.changePanoMode(!0);
  12365. _context.next = 5;
  12366. return n.materialComponent.changePanoImg(0, r);
  12367. case 5:
  12368. if (!e.finished) {
  12369. _context.next = 23;
  12370. break;
  12371. }
  12372. _context.next = 8;
  12373. return n.changePanoShaderForLowModel(0);
  12374. case 8:
  12375. _this.room.isPano = !0;
  12376. _this._actived = !0;
  12377. if (!t) {
  12378. _context.next = 14;
  12379. break;
  12380. }
  12381. _this.room.sceneManager.cameraComponent.changeToFirstPersonView({
  12382. position: t.position,
  12383. rotation: t.angle
  12384. });
  12385. _context.next = 23;
  12386. break;
  12387. case 14:
  12388. _this$room$currentSta = _this.room.currentState, o = _this$room$currentSta.skinId, a = _this$room$currentSta.pathName;
  12389. if (!(!o || !a)) {
  12390. _context.next = 17;
  12391. break;
  12392. }
  12393. return _context.abrupt("return");
  12394. case 17:
  12395. _context.next = 19;
  12396. return _this.room.modelManager.findRoute(o, a);
  12397. case 19:
  12398. s = _context.sent;
  12399. _ref2 = util.getRandomItem(s.birthPointList) || {};
  12400. l = _ref2.camera;
  12401. l && _this.room.sceneManager.cameraComponent.changeToFirstPersonView(le(oe({}, l), {
  12402. rotation: l.angle
  12403. }));
  12404. case 23:
  12405. case "end":
  12406. return _context.stop();
  12407. }
  12408. }
  12409. }, _callee);
  12410. }));
  12411. return function (_x, _x2) {
  12412. return _ref.apply(this, arguments);
  12413. };
  12414. }());
  12415. this.room = e;
  12416. }
  12417. _createClass(Panorama, [{
  12418. key: "actived",
  12419. get: function get() {
  12420. return this._actived;
  12421. }
  12422. }, {
  12423. key: "bindListener",
  12424. value: function bindListener(e) {
  12425. var _this2 = this;
  12426. this.room.networkController.rtcp.workers.registerFunction("panorama", function (r) {
  12427. logger$1.warn("receive panorama", r.uuid, r.pos), r.uuid && eventsManager.remove(r.uuid, Codes.Success, r, !0), _this2.room.isFirstDataUsed || (_this2.room.isFirstDataUsed = !0, _this2.handleReceivePanorama(r, _this2.room.options.camera).then(e));
  12428. });
  12429. }
  12430. }, {
  12431. key: "access",
  12432. value: function access(e, t, r) {
  12433. var _this3 = this;
  12434. var n = e.camera,
  12435. o = e.player,
  12436. a = e.attitude,
  12437. s = e.areaName,
  12438. l = e.pathName,
  12439. u = e.tag;
  12440. return this.room.actionsHandler.requestPanorama({
  12441. camera: n,
  12442. player: o,
  12443. attitude: a,
  12444. areaName: s,
  12445. pathName: l,
  12446. tag: u
  12447. }, t, r).then(function (c) {
  12448. return _this3.handleReceivePanorama(c, o);
  12449. });
  12450. }
  12451. }, {
  12452. key: "exit",
  12453. value: function exit(e) {
  12454. var _this4 = this;
  12455. var t = e.camera,
  12456. r = e.player,
  12457. n = e.attitude,
  12458. o = e.areaName,
  12459. a = e.pathName;
  12460. return this.room.networkController.rtcp.workers.changePanoMode(!1), this.room.actionsHandler.changeRotationRenderType({
  12461. renderType: RenderType.RotationVideo,
  12462. player: r,
  12463. camera: t,
  12464. attitude: n,
  12465. areaName: o,
  12466. pathName: a
  12467. }).then(function () {
  12468. return _this4.handleExitPanorama();
  12469. }).catch(function (s) {
  12470. return _this4.room.networkController.rtcp.workers.changePanoMode(!0), Promise.reject(s);
  12471. });
  12472. }
  12473. }, {
  12474. key: "handleExitPanorama",
  12475. value: function handleExitPanorama() {
  12476. var e, t, r, n, o, a;
  12477. this.room.isPano = !1, this._actived = !1, (n = (e = this.room.sceneManager) == null ? void 0 : e.cameraComponent) == null || n.forceChangeSavedCameraPose({
  12478. position: (t = this.room._currentClickingState) == null ? void 0 : t.camera.position,
  12479. rotation: (r = this.room._currentClickingState) == null ? void 0 : r.camera.angle
  12480. }), this.room.sceneManager.changeVideoShaderForLowModel(), (a = (o = this.room.sceneManager) == null ? void 0 : o.cameraComponent) == null || a.changeToThirdPersonView();
  12481. }
  12482. }]);
  12483. return Panorama;
  12484. }();
  12485. 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); }; }
  12486. 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; } }
  12487. var Xverse_Room = /*#__PURE__*/function (_EventEmitter) {
  12488. _inherits(Xverse_Room, _EventEmitter);
  12489. var _super = _createSuper$1(Xverse_Room);
  12490. function Xverse_Room(e) {
  12491. var _this;
  12492. _classCallCheck(this, Xverse_Room);
  12493. _this = _super.call(this);
  12494. E(_assertThisInitialized(_this), "disableAutoTurn", !1);
  12495. E(_assertThisInitialized(_this), "options");
  12496. E(_assertThisInitialized(_this), "_currentNetworkOptions");
  12497. E(_assertThisInitialized(_this), "lastSkinId");
  12498. E(_assertThisInitialized(_this), "debug");
  12499. E(_assertThisInitialized(_this), "isFirstDataUsed", !1);
  12500. E(_assertThisInitialized(_this), "userId", null);
  12501. E(_assertThisInitialized(_this), "pathManager", new PathManager());
  12502. E(_assertThisInitialized(_this), "networkController");
  12503. E(_assertThisInitialized(_this), "_startTime", Date.now());
  12504. E(_assertThisInitialized(_this), "canvas");
  12505. E(_assertThisInitialized(_this), "modelManager");
  12506. E(_assertThisInitialized(_this), "eventsController");
  12507. E(_assertThisInitialized(_this), "panorama");
  12508. E(_assertThisInitialized(_this), "engineProxy");
  12509. E(_assertThisInitialized(_this), "_id");
  12510. E(_assertThisInitialized(_this), "skinList", []);
  12511. E(_assertThisInitialized(_this), "isHost", !1);
  12512. E(_assertThisInitialized(_this), "avatarManager", new XverseAvatarManager(_assertThisInitialized(_this)));
  12513. E(_assertThisInitialized(_this), "effectManager", new XverseEffectManager(_assertThisInitialized(_this)));
  12514. E(_assertThisInitialized(_this), "sceneManager");
  12515. E(_assertThisInitialized(_this), "scene");
  12516. E(_assertThisInitialized(_this), "breathPointManager");
  12517. E(_assertThisInitialized(_this), "_currentState");
  12518. E(_assertThisInitialized(_this), "joined", !1);
  12519. E(_assertThisInitialized(_this), "disableRotate", !1);
  12520. E(_assertThisInitialized(_this), "isPano", !1);
  12521. E(_assertThisInitialized(_this), "movingByClick", !0);
  12522. E(_assertThisInitialized(_this), "camera", new Camera(_assertThisInitialized(_this)));
  12523. E(_assertThisInitialized(_this), "stats", new Stats(_assertThisInitialized(_this)));
  12524. E(_assertThisInitialized(_this), "isUpdatedRawYUVData", !1);
  12525. E(_assertThisInitialized(_this), "actionsHandler", new ActionsHandler(_assertThisInitialized(_this)));
  12526. E(_assertThisInitialized(_this), "_currentClickingState", null);
  12527. E(_assertThisInitialized(_this), "signal", new Signal(_assertThisInitialized(_this)));
  12528. E(_assertThisInitialized(_this), "firstFrameTimestamp");
  12529. E(_assertThisInitialized(_this), "receiveRtcData", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  12530. var e, t, r, n;
  12531. return regenerator.wrap(function _callee$(_context) {
  12532. while (1) {
  12533. switch (_context.prev = _context.next) {
  12534. case 0:
  12535. logger$1.info("Invoke receiveRtcData");
  12536. e = !1, t = !1, r = !1, n = !1;
  12537. return _context.abrupt("return", _this.viewMode === "serverless" ? (logger$1.warn("set view mode to serverless"), _this.setViewMode("observer").then(function () {
  12538. return _assertThisInitialized(_this);
  12539. }, function () {
  12540. return _assertThisInitialized(_this);
  12541. })) : new Promise(function (o) {
  12542. var a = _this.networkController.rtcp.workers;
  12543. a.registerFunction("signal", function (s) {
  12544. _this.signal.handleSignal(s);
  12545. }), a.registerFunction("stream", function (s) {
  12546. var l;
  12547. if (_this.emit("streamTimestamp", {
  12548. timestamp: Date.now()
  12549. }), t || (t = !0, logger$1.info("Invoke stream event")), s.stream) {
  12550. r || (r = !0, logger$1.info("Invoke updateRawYUVData")), _this.isUpdatedRawYUVData = !1;
  12551. var u = (l = _this._currentState.skin) == null ? void 0 : l.fov;
  12552. _this.sceneManager.materialComponent.updateRawYUVData(s.stream, s.width, s.height, u), _this.isUpdatedRawYUVData = !0;
  12553. }
  12554. e || (logger$1.info("Invoke isAfterRenderRegistered"), e = !0, _this.scene.registerAfterRender(function () {
  12555. _this.engineProxy.frameRenderNumber >= 2 && (n || (n = !0, logger$1.info("Invoke registerAfterRender")), _this.isFirstDataUsed || (logger$1.info("Invoke isStreamAvailable"), _this.isFirstDataUsed = !0, _this.firstFrameTimestamp = Date.now(), o(_assertThisInitialized(_this)), _this.afterJoinRoom()));
  12556. }));
  12557. }), _this.panorama.bindListener(function () {
  12558. o(_assertThisInitialized(_this)), _this.afterJoinRoom();
  12559. }), a.registerFunction("reconnectedFrame", function () {}), logger$1.info("Invoke decoderWorker.postMessage"), a.decoderWorker.postMessage({
  12560. t: 5
  12561. });
  12562. }));
  12563. case 3:
  12564. case "end":
  12565. return _context.stop();
  12566. }
  12567. }
  12568. }, _callee);
  12569. })));
  12570. E(_assertThisInitialized(_this), "moveToExtra", "");
  12571. _this.options = e, _this.options.wsServerUrl || (_this.options.wsServerUrl = SERVER_URLS.DEV), _this.modelManager = ModelManager.getInstance(e.appId, e.releaseId), _this.updateReporter();
  12572. var n = e;
  12573. n.canvas;
  12574. var r = Oe(n, ["canvas"]);
  12575. logger$1.infoAndReportMeasurement({
  12576. metric: "startJoinRoomAt",
  12577. startTime: Date.now(),
  12578. group: "joinRoom",
  12579. extra: r,
  12580. value: 0
  12581. });
  12582. return _this;
  12583. }
  12584. _createClass(Xverse_Room, [{
  12585. key: "currentNetworkOptions",
  12586. get: function get() {
  12587. return this._currentNetworkOptions;
  12588. }
  12589. }, {
  12590. key: "viewMode",
  12591. get: function get() {
  12592. var e;
  12593. return ((e = this._currentState) == null ? void 0 : e.viewMode) || "full";
  12594. }
  12595. }, {
  12596. key: "id",
  12597. get: function get() {
  12598. return this._id;
  12599. }
  12600. }, {
  12601. key: "skinId",
  12602. get: function get() {
  12603. return this._currentState.skinId;
  12604. }
  12605. }, {
  12606. key: "skin",
  12607. get: function get() {
  12608. return this._currentState.skin;
  12609. }
  12610. }, {
  12611. key: "sessionId",
  12612. get: function get() {
  12613. return this.currentNetworkOptions.sessionId;
  12614. }
  12615. }, {
  12616. key: "pictureQualityLevel",
  12617. get: function get() {
  12618. return this.currentState.pictureQualityLevel;
  12619. }
  12620. }, {
  12621. key: "avatars",
  12622. get: function get() {
  12623. return Array.from(this.avatarManager.avatars.values());
  12624. }
  12625. }, {
  12626. key: "currentState",
  12627. get: function get() {
  12628. var e;
  12629. return le(oe({}, this._currentState), {
  12630. state: (e = this.networkController) == null ? void 0 : e._state
  12631. });
  12632. }
  12633. }, {
  12634. key: "_userAvatar",
  12635. get: function get() {
  12636. var _this2 = this;
  12637. return this.avatars.find(function (e) {
  12638. return e.userId === _this2.userId;
  12639. });
  12640. }
  12641. }, {
  12642. key: "tvs",
  12643. get: function get() {
  12644. return this.engineProxy._tvs;
  12645. }
  12646. }, {
  12647. key: "tv",
  12648. get: function get() {
  12649. return this.tvs[0];
  12650. }
  12651. }, {
  12652. key: "currentClickingState",
  12653. get: function get() {
  12654. return this._currentClickingState;
  12655. }
  12656. }, {
  12657. key: "afterJoinRoomHook",
  12658. value: function afterJoinRoomHook() {}
  12659. }, {
  12660. key: "beforeJoinRoomResolveHook",
  12661. value: function beforeJoinRoomResolveHook() {}
  12662. }, {
  12663. key: "afterReconnectedHook",
  12664. value: function afterReconnectedHook() {}
  12665. }, {
  12666. key: "handleSignalHook",
  12667. value: function handleSignalHook(e) {}
  12668. }, {
  12669. key: "skinChangedHook",
  12670. value: function skinChangedHook() {}
  12671. }, {
  12672. key: "beforeStartGameHook",
  12673. value: function () {
  12674. var _beforeStartGameHook = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  12675. return regenerator.wrap(function _callee2$(_context2) {
  12676. while (1) {
  12677. switch (_context2.prev = _context2.next) {
  12678. case 0:
  12679. case "end":
  12680. return _context2.stop();
  12681. }
  12682. }
  12683. }, _callee2);
  12684. }));
  12685. function beforeStartGameHook(_x) {
  12686. return _beforeStartGameHook.apply(this, arguments);
  12687. }
  12688. return beforeStartGameHook;
  12689. }()
  12690. }, {
  12691. key: "loadAssetsHook",
  12692. value: function loadAssetsHook() {}
  12693. }, {
  12694. key: "afterUserAvatarLoadedHook",
  12695. value: function afterUserAvatarLoadedHook() {}
  12696. }, {
  12697. key: "audienceViewModeHook",
  12698. value: function audienceViewModeHook() {}
  12699. }, {
  12700. key: "setViewModeToObserver",
  12701. value: function setViewModeToObserver() {}
  12702. }, {
  12703. key: "handleVehicleHook",
  12704. value: function handleVehicleHook(e) {}
  12705. }, {
  12706. key: "updateReporter",
  12707. value: function updateReporter() {
  12708. var _this$options = this.options,
  12709. e = _this$options.avatarId,
  12710. t = _this$options.skinId,
  12711. r = _this$options.userId,
  12712. n = _this$options.roomId,
  12713. o = _this$options.role,
  12714. a = _this$options.appId,
  12715. s = _this$options.wsServerUrl;
  12716. reporter$1.updateHeader({
  12717. userId: r
  12718. }), reporter$1.updateBody({
  12719. roomId: n,
  12720. role: o,
  12721. skinId: t,
  12722. avatarId: e,
  12723. appId: a,
  12724. wsServerUrl: s
  12725. });
  12726. }
  12727. }, {
  12728. key: "initRoom",
  12729. value: function () {
  12730. var _initRoom2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  12731. var _this$options$timeout, e;
  12732. return regenerator.wrap(function _callee3$(_context3) {
  12733. while (1) {
  12734. switch (_context3.prev = _context3.next) {
  12735. case 0:
  12736. _this$options$timeout = this.options.timeout, e = _this$options$timeout === void 0 ? DEFAULT_JOINROOM_TIMEOUT : _this$options$timeout;
  12737. if (!util.isSupported()) {
  12738. _context3.next = 5;
  12739. break;
  12740. }
  12741. return _context3.abrupt("return", this._initRoom()._timeout(e, new TimeoutError("initRoom timeout")));
  12742. case 5:
  12743. return _context3.abrupt("return", Promise.reject(new UnsupportedError()));
  12744. case 6:
  12745. case "end":
  12746. return _context3.stop();
  12747. }
  12748. }
  12749. }, _callee3, this);
  12750. }));
  12751. function initRoom() {
  12752. return _initRoom2.apply(this, arguments);
  12753. }
  12754. return initRoom;
  12755. }()
  12756. }, {
  12757. key: "_initRoom",
  12758. value: function () {
  12759. var _initRoom3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  12760. 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;
  12761. return regenerator.wrap(function _callee4$(_context4) {
  12762. while (1) {
  12763. switch (_context4.prev = _context4.next) {
  12764. case 0:
  12765. e = this.validateOptions(this.options);
  12766. if (!e) {
  12767. _context4.next = 3;
  12768. break;
  12769. }
  12770. return _context4.abrupt("return", (logger$1.error("initRoom param error", e), Promise.reject(e)));
  12771. case 3:
  12772. _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;
  12773. this.setCurrentNetworkOptions({
  12774. avatarId: r,
  12775. skinId: n,
  12776. roomId: R,
  12777. userId: o,
  12778. wsServerUrl: a,
  12779. role: s,
  12780. token: l,
  12781. pageSession: u,
  12782. rotationRenderType: c,
  12783. isAllSync: h,
  12784. appId: f,
  12785. camera: d,
  12786. player: _,
  12787. avatarComponents: g,
  12788. nickname: m,
  12789. avatarScale: v,
  12790. firends: y,
  12791. syncByEvent: b,
  12792. areaName: T,
  12793. attitude: C,
  12794. pathName: A,
  12795. person: P,
  12796. roomTypeId: M,
  12797. hasAvatar: x,
  12798. syncToOthers: I,
  12799. prioritySync: w,
  12800. extra: D,
  12801. removeWhenDisconnected: O
  12802. });
  12803. this.userId = o;
  12804. this.canvas = t;
  12805. T && (this.pathManager.currentArea = T);
  12806. this.networkController = new NetworkController(this);
  12807. this.setCurrentState({
  12808. areaName: T,
  12809. pathName: A,
  12810. attitude: C,
  12811. speed: 0,
  12812. viewMode: S,
  12813. state: this.networkController._state,
  12814. skinId: n
  12815. });
  12816. _context4.prev = 10;
  12817. _context4.next = 13;
  12818. return Promise.all([this.initNetwork(), this.initConfig(), this.initWasm()]);
  12819. case 13:
  12820. logger$1.info("network config wasm all ready, start to create game");
  12821. _context4.next = 16;
  12822. return this.requestCreateRoom({
  12823. skinId: n
  12824. });
  12825. case 16:
  12826. F = _context4.sent;
  12827. V = F.routeList.find(function (L) {
  12828. return L.areaName === T;
  12829. });
  12830. N = ((V == null ? void 0 : V.step) || 7.5) * 30;
  12831. this.updateCurrentState({
  12832. skin: F,
  12833. skinId: F.id,
  12834. versionId: F.versionId,
  12835. speed: N
  12836. });
  12837. _context4.next = 22;
  12838. return this.initEngine(F);
  12839. case 22:
  12840. _context4.next = 27;
  12841. break;
  12842. case 24:
  12843. _context4.prev = 24;
  12844. _context4.t0 = _context4["catch"](10);
  12845. return _context4.abrupt("return", Promise.reject(_context4.t0));
  12846. case 27:
  12847. return _context4.abrupt("return", (this.beforeJoinRoomResolve(), this.receiveRtcData()));
  12848. case 28:
  12849. case "end":
  12850. return _context4.stop();
  12851. }
  12852. }
  12853. }, _callee4, this, [[10, 24]]);
  12854. }));
  12855. function _initRoom() {
  12856. return _initRoom3.apply(this, arguments);
  12857. }
  12858. return _initRoom;
  12859. }()
  12860. }, {
  12861. key: "beforeJoinRoomResolve",
  12862. value: function beforeJoinRoomResolve() {
  12863. this.setupStats(), this.eventsController = new EventsController(this), this.eventsController.bindEvents(), this.panorama = new Panorama(this), this.beforeJoinRoomResolveHook();
  12864. }
  12865. }, {
  12866. key: "afterJoinRoom",
  12867. value: function afterJoinRoom() {
  12868. this.joined = !0, this.viewMode === "observer" && this.setViewModeToObserver(), logger$1.infoAndReportMeasurement({
  12869. tag: this.viewMode,
  12870. value: this.firstFrameTimestamp - this._startTime,
  12871. startTime: Date.now(),
  12872. metric: "joinRoom"
  12873. }), this.camera.initialFov = this.sceneManager.cameraComponent.getCameraFov(), this.stats.on("stats", function (_ref2) {
  12874. var e = _ref2.stats;
  12875. reporter$1.report("stats", oe({}, e));
  12876. }), this.debug = new Debug(this), this.afterJoinRoomHook();
  12877. }
  12878. }, {
  12879. key: "afterReconnected",
  12880. value: function afterReconnected() {
  12881. this.avatarManager.clearOtherUsers(), this.afterReconnectedHook();
  12882. }
  12883. }, {
  12884. key: "leave",
  12885. value: function leave() {
  12886. var e, t;
  12887. return logger$1.info("Invoke room.leave"), (e = this.eventsController) == null || e.clearEvents(), (t = this.networkController) == null || t.quit(), this;
  12888. }
  12889. }, {
  12890. key: "validateOptions",
  12891. value: function validateOptions(e) {
  12892. var _ref3 = e || {},
  12893. t = _ref3.canvas,
  12894. r = _ref3.avatarId,
  12895. n = _ref3.skinId,
  12896. o = _ref3.userId,
  12897. a = _ref3.role;
  12898. _ref3.roomId;
  12899. var l = _ref3.token,
  12900. u = _ref3.appId;
  12901. _ref3.avatarComponents;
  12902. var h = [];
  12903. t instanceof HTMLCanvasElement || h.push(new ParamError$1("`canvas` must be instanceof of HTMLCanvasElement"));
  12904. (!o || typeof o != "string") && h.push(new ParamError$1("`userId` must be string"));
  12905. (!l || typeof l != "string") && h.push(new ParamError$1("`token` must be string"));
  12906. (!u || typeof u != "string") && h.push(new ParamError$1("`appId` must be string"));
  12907. a == "audience" || (!r || !n) && h.push(new ParamError$1("`avatarId` and `skinId` is required when create room"));
  12908. return h[0];
  12909. }
  12910. }, {
  12911. key: "initNetwork",
  12912. value: function () {
  12913. var _initNetwork = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  12914. var e;
  12915. return regenerator.wrap(function _callee5$(_context5) {
  12916. while (1) {
  12917. switch (_context5.prev = _context5.next) {
  12918. case 0:
  12919. if (!(this.viewMode === "serverless")) {
  12920. _context5.next = 2;
  12921. break;
  12922. }
  12923. return _context5.abrupt("return", Promise.resolve());
  12924. case 2:
  12925. e = Date.now();
  12926. _context5.prev = 3;
  12927. _context5.next = 6;
  12928. return this.networkController.connect()._timeout(8e3, new InitNetworkTimeoutError());
  12929. case 6:
  12930. logger$1.infoAndReportMeasurement({
  12931. metric: "networkInitAt",
  12932. startTime: this._startTime,
  12933. group: "joinRoom"
  12934. });
  12935. logger$1.infoAndReportMeasurement({
  12936. metric: "networkInitCost",
  12937. startTime: e,
  12938. group: "joinRoom"
  12939. });
  12940. _context5.next = 13;
  12941. break;
  12942. case 10:
  12943. _context5.prev = 10;
  12944. _context5.t0 = _context5["catch"](3);
  12945. throw logger$1.infoAndReportMeasurement({
  12946. metric: "networkInitAt",
  12947. startTime: e,
  12948. group: "joinRoom",
  12949. error: _context5.t0
  12950. }), _context5.t0;
  12951. case 13:
  12952. case "end":
  12953. return _context5.stop();
  12954. }
  12955. }
  12956. }, _callee5, this, [[3, 10]]);
  12957. }));
  12958. function initNetwork() {
  12959. return _initNetwork.apply(this, arguments);
  12960. }
  12961. return initNetwork;
  12962. }()
  12963. }, {
  12964. key: "initConfig",
  12965. value: function () {
  12966. var _initConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  12967. var e;
  12968. return regenerator.wrap(function _callee6$(_context6) {
  12969. while (1) {
  12970. switch (_context6.prev = _context6.next) {
  12971. case 0:
  12972. e = Date.now();
  12973. _context6.prev = 1;
  12974. _context6.next = 4;
  12975. return this.modelManager.getApplicationConfig()._timeout(8e3, new InitConfigTimeoutError());
  12976. case 4:
  12977. logger$1.infoAndReportMeasurement({
  12978. metric: "configInitAt",
  12979. startTime: this._startTime,
  12980. group: "joinRoom"
  12981. });
  12982. logger$1.infoAndReportMeasurement({
  12983. metric: "configInitCost",
  12984. startTime: e,
  12985. group: "joinRoom"
  12986. });
  12987. _context6.next = 11;
  12988. break;
  12989. case 8:
  12990. _context6.prev = 8;
  12991. _context6.t0 = _context6["catch"](1);
  12992. throw logger$1.infoAndReportMeasurement({
  12993. metric: "configInitAt",
  12994. startTime: e,
  12995. group: "joinRoom",
  12996. error: _context6.t0
  12997. }), _context6.t0;
  12998. case 11:
  12999. case "end":
  13000. return _context6.stop();
  13001. }
  13002. }
  13003. }, _callee6, this, [[1, 8]]);
  13004. }));
  13005. function initConfig() {
  13006. return _initConfig.apply(this, arguments);
  13007. }
  13008. return initConfig;
  13009. }()
  13010. }, {
  13011. key: "initEngine",
  13012. value: function () {
  13013. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  13014. var t, n;
  13015. return regenerator.wrap(function _callee7$(_context7) {
  13016. while (1) {
  13017. switch (_context7.prev = _context7.next) {
  13018. case 0:
  13019. t = Date.now();
  13020. _context7.prev = 1;
  13021. this.engineProxy = new EngineProxy(this);
  13022. _context7.next = 5;
  13023. return this.engineProxy.initEngine(e);
  13024. case 5:
  13025. logger$1.infoAndReportMeasurement({
  13026. metric: "webglInitAt",
  13027. startTime: this._startTime,
  13028. group: "joinRoom"
  13029. });
  13030. logger$1.infoAndReportMeasurement({
  13031. metric: "webglInitCost",
  13032. startTime: t,
  13033. group: "joinRoom"
  13034. });
  13035. return _context7.abrupt("return");
  13036. case 10:
  13037. _context7.prev = 10;
  13038. _context7.t0 = _context7["catch"](1);
  13039. n = _context7.t0;
  13040. return _context7.abrupt("return", (_context7.t0.code !== Codes.InitEngineTimeout && (n = new InitEngineError()), logger$1.error(_context7.t0), logger$1.infoAndReportMeasurement({
  13041. metric: "webglInitAt",
  13042. startTime: t,
  13043. group: "joinRoom",
  13044. error: n
  13045. }), Promise.reject(n)));
  13046. case 14:
  13047. case "end":
  13048. return _context7.stop();
  13049. }
  13050. }
  13051. }, _callee7, this, [[1, 10]]);
  13052. }));
  13053. function initEngine(_x2) {
  13054. return _initEngine.apply(this, arguments);
  13055. }
  13056. return initEngine;
  13057. }()
  13058. }, {
  13059. key: "initWasm",
  13060. value: function () {
  13061. var _initWasm = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  13062. var _this3 = this;
  13063. var e;
  13064. return regenerator.wrap(function _callee8$(_context8) {
  13065. while (1) {
  13066. switch (_context8.prev = _context8.next) {
  13067. case 0:
  13068. if (!(this.viewMode === "serverless")) {
  13069. _context8.next = 2;
  13070. break;
  13071. }
  13072. return _context8.abrupt("return", Promise.resolve());
  13073. case 2:
  13074. e = Date.now();
  13075. _context8.prev = 3;
  13076. _context8.next = 6;
  13077. return this.networkController.rtcp.workers.init(this.options.resolution)._timeout(8e3, new InitDecoderTimeoutError());
  13078. case 6:
  13079. this.networkController.rtcp.workers.registerFunction("error", function (t) {
  13080. logger$1.error("decode error", t);
  13081. var r = t.code,
  13082. n = t.message;
  13083. _this3.emit("error", {
  13084. code: r,
  13085. msg: n
  13086. });
  13087. });
  13088. logger$1.infoAndReportMeasurement({
  13089. metric: "wasmInitAt",
  13090. group: "joinRoom",
  13091. startTime: this._startTime
  13092. });
  13093. logger$1.infoAndReportMeasurement({
  13094. metric: "wasmInitCost",
  13095. group: "joinRoom",
  13096. startTime: e
  13097. });
  13098. eventsManager.on("traceId", function (t) {
  13099. _this3.networkController.rtcp.workers.onTraceId(t);
  13100. });
  13101. _context8.next = 15;
  13102. break;
  13103. case 12:
  13104. _context8.prev = 12;
  13105. _context8.t0 = _context8["catch"](3);
  13106. throw logger$1.infoAndReportMeasurement({
  13107. metric: "wasmInitAt",
  13108. group: "joinRoom",
  13109. startTime: e,
  13110. error: _context8.t0
  13111. }), _context8.t0;
  13112. case 15:
  13113. case "end":
  13114. return _context8.stop();
  13115. }
  13116. }
  13117. }, _callee8, this, [[3, 12]]);
  13118. }));
  13119. function initWasm() {
  13120. return _initWasm.apply(this, arguments);
  13121. }
  13122. return initWasm;
  13123. }()
  13124. }, {
  13125. key: "requestCreateRoom",
  13126. value: function () {
  13127. var _requestCreateRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(_ref4) {
  13128. var e, t, r, _ref5, n, o, _yield$this$networkCo, _r, _n, _o, a, s;
  13129. return regenerator.wrap(function _callee9$(_context9) {
  13130. while (1) {
  13131. switch (_context9.prev = _context9.next) {
  13132. case 0:
  13133. e = _ref4.skinId;
  13134. if (!e) {
  13135. _context9.next = 11;
  13136. break;
  13137. }
  13138. _context9.next = 4;
  13139. return this.getSkin(e);
  13140. case 4:
  13141. t = _context9.sent;
  13142. _context9.next = 7;
  13143. return this.modelManager.findRoute(e, this.options.pathName);
  13144. case 7:
  13145. r = _context9.sent;
  13146. this.updateCurrentNetworkOptions({
  13147. areaName: r.areaName,
  13148. attitude: r.attitude,
  13149. versionId: t.versionId
  13150. });
  13151. _ref5 = util.getRandomItem(r.birthPointList) || this.options, n = _ref5.camera, o = _ref5.player;
  13152. this.options.camera || this.updateCurrentNetworkOptions({
  13153. camera: n
  13154. }), this.options.player || this.updateCurrentNetworkOptions({
  13155. player: o
  13156. });
  13157. case 11:
  13158. if (!(this.viewMode === "serverless")) {
  13159. _context9.next = 13;
  13160. break;
  13161. }
  13162. return _context9.abrupt("return", t);
  13163. case 13:
  13164. _context9.prev = 13;
  13165. _context9.next = 16;
  13166. return this.beforeStartGameHook(this.options);
  13167. case 16:
  13168. _context9.next = 18;
  13169. return this.networkController.startGame();
  13170. case 18:
  13171. _yield$this$networkCo = _context9.sent;
  13172. _r = _yield$this$networkCo.room_id;
  13173. _n = _yield$this$networkCo.data;
  13174. _o = _yield$this$networkCo.session_id;
  13175. this._id = _r;
  13176. a = JSON.parse(_n);
  13177. this.isHost = a.IsHost, e = a.SkinID || e;
  13178. _context9.next = 27;
  13179. return this.getSkin(e);
  13180. case 27:
  13181. s = _context9.sent;
  13182. return _context9.abrupt("return", (this.updateCurrentNetworkOptions({
  13183. roomId: _r,
  13184. sessionId: _o
  13185. }), reporter$1.updateBody({
  13186. roomId: _r,
  13187. skinId: e,
  13188. serverSession: _o
  13189. }), s));
  13190. case 31:
  13191. _context9.prev = 31;
  13192. _context9.t0 = _context9["catch"](13);
  13193. throw logger$1.error("Request create room error", _context9.t0), _context9.t0;
  13194. case 34:
  13195. case "end":
  13196. return _context9.stop();
  13197. }
  13198. }
  13199. }, _callee9, this, [[13, 31]]);
  13200. }));
  13201. function requestCreateRoom(_x3) {
  13202. return _requestCreateRoom.apply(this, arguments);
  13203. }
  13204. return requestCreateRoom;
  13205. }()
  13206. }, {
  13207. key: "pause",
  13208. value: function pause() {
  13209. return this.engineProxy.pause();
  13210. }
  13211. }, {
  13212. key: "resume",
  13213. value: function resume() {
  13214. return this.engineProxy.resume();
  13215. }
  13216. }, {
  13217. key: "reconnect",
  13218. value: function reconnect() {
  13219. this.networkController.reconnect();
  13220. }
  13221. }, {
  13222. key: "setViewMode",
  13223. value: function () {
  13224. var _setViewMode = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(e) {
  13225. return regenerator.wrap(function _callee10$(_context10) {
  13226. while (1) {
  13227. switch (_context10.prev = _context10.next) {
  13228. case 0:
  13229. case "end":
  13230. return _context10.stop();
  13231. }
  13232. }
  13233. }, _callee10);
  13234. }));
  13235. function setViewMode(_x4) {
  13236. return _setViewMode.apply(this, arguments);
  13237. }
  13238. return setViewMode;
  13239. }()
  13240. }, {
  13241. key: "handleRepetLogin",
  13242. value: function handleRepetLogin() {
  13243. logger$1.warn("receive " + Codes.RepeatLogin + " for repeat login"), this.emit("repeatLogin"), reporter$1.disable(), this.networkController.quit();
  13244. }
  13245. }, {
  13246. key: "setPictureQualityLevel",
  13247. value: function setPictureQualityLevel(e) {
  13248. var t = {
  13249. high: EImageQuality.high,
  13250. low: EImageQuality.low,
  13251. average: EImageQuality.mid
  13252. };
  13253. return this.updateCurrentState({
  13254. pictureQualityLevel: e
  13255. }), this.sceneManager.setImageQuality(t[e]);
  13256. }
  13257. }, {
  13258. key: "getSkin",
  13259. value: function () {
  13260. var _getSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  13261. var t, n;
  13262. return regenerator.wrap(function _callee11$(_context11) {
  13263. while (1) {
  13264. switch (_context11.prev = _context11.next) {
  13265. case 0:
  13266. t = null;
  13267. _context11.next = 3;
  13268. return this.modelManager.getSkinsList();
  13269. case 3:
  13270. t = (this.skinList = _context11.sent).find(function (n) {
  13271. return n.id === e || n.id === e;
  13272. });
  13273. if (!t) {
  13274. _context11.next = 6;
  13275. break;
  13276. }
  13277. return _context11.abrupt("return", t);
  13278. case 6:
  13279. n = "skin is invalid: skinId: ".concat(e);
  13280. return _context11.abrupt("return", Promise.reject(new ParamError$1(n)));
  13281. case 8:
  13282. case "end":
  13283. return _context11.stop();
  13284. }
  13285. }
  13286. }, _callee11, this);
  13287. }));
  13288. function getSkin(_x5) {
  13289. return _getSkin.apply(this, arguments);
  13290. }
  13291. return getSkin;
  13292. }()
  13293. }, {
  13294. key: "setupStats",
  13295. value: function setupStats() {
  13296. this.stats.assign({
  13297. roomId: this.id,
  13298. userId: this.userId
  13299. }), setInterval(this.engineProxy.updateStats, 1e3);
  13300. }
  13301. }, {
  13302. key: "proxyEvents",
  13303. value: function proxyEvents(e, t) {
  13304. this.emit(e, t);
  13305. }
  13306. }, {
  13307. key: "setCurrentNetworkOptions",
  13308. value: function setCurrentNetworkOptions(e) {
  13309. this._currentNetworkOptions = e;
  13310. }
  13311. }, {
  13312. key: "updateCurrentNetworkOptions",
  13313. value: function updateCurrentNetworkOptions(e) {
  13314. Object.assign(this._currentNetworkOptions, e), Object.assign(this.options, e);
  13315. }
  13316. }, {
  13317. key: "setCurrentState",
  13318. value: function setCurrentState(e) {
  13319. this._currentState = e;
  13320. }
  13321. }, {
  13322. key: "updateCurrentState",
  13323. value: function updateCurrentState(e) {
  13324. e.skinId && (this.lastSkinId = this.currentState.skinId, this.updateCurrentNetworkOptions({
  13325. skinId: e.skinId
  13326. })), e.versionId && this.updateCurrentNetworkOptions({
  13327. versionId: e.versionId
  13328. }), Object.assign(this._currentState, e);
  13329. }
  13330. }]);
  13331. return Xverse_Room;
  13332. }(EventEmitter);
  13333. 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); }; }
  13334. 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; } }
  13335. var XverseRoom = /*#__PURE__*/function (_Xverse_Room) {
  13336. _inherits(XverseRoom, _Xverse_Room);
  13337. var _super = _createSuper(XverseRoom);
  13338. function XverseRoom(e) {
  13339. var _this;
  13340. _classCallCheck(this, XverseRoom);
  13341. _this = _super.call(this, e);
  13342. _this.joyStick = new JoyStick(_assertThisInitialized(_this));
  13343. return _this;
  13344. }
  13345. _createClass(XverseRoom, [{
  13346. key: "afterJoinRoomHook",
  13347. value: function afterJoinRoomHook() {
  13348. this.joyStick.init({});
  13349. }
  13350. }]);
  13351. return XverseRoom;
  13352. }(Xverse_Room);
  13353. var Preload = /*#__PURE__*/function () {
  13354. function Preload(e) {
  13355. _classCallCheck(this, Preload);
  13356. this.config = null;
  13357. this.allKeys = [];
  13358. this.oldResourcesDeleted = !1;
  13359. this.requests = {
  13360. simple: {
  13361. stopped: !0,
  13362. requests: {}
  13363. },
  13364. observer: {
  13365. stopped: !0,
  13366. requests: {}
  13367. },
  13368. full: {
  13369. stopped: !0,
  13370. requests: {}
  13371. }
  13372. };
  13373. this.modelManager = e, this.init(e.appId);
  13374. }
  13375. _createClass(Preload, [{
  13376. key: "init",
  13377. value: function init(e) {
  13378. reporter$1.updateBody({
  13379. appId: e
  13380. });
  13381. }
  13382. }, {
  13383. key: "getConfig",
  13384. value: function () {
  13385. var _getConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  13386. var _yield$this$modelMana, t;
  13387. return regenerator.wrap(function _callee$(_context) {
  13388. while (1) {
  13389. switch (_context.prev = _context.next) {
  13390. case 0:
  13391. if (!this.config) {
  13392. _context.next = 2;
  13393. break;
  13394. }
  13395. return _context.abrupt("return", this.config);
  13396. case 2:
  13397. _context.next = 4;
  13398. return this.modelManager.requestConfig();
  13399. case 4:
  13400. _yield$this$modelMana = _context.sent;
  13401. t = _yield$this$modelMana.preload;
  13402. return _context.abrupt("return", t ? (this.config = t, Promise.resolve(t)) : Promise.reject("no preload config"));
  13403. case 7:
  13404. case "end":
  13405. return _context.stop();
  13406. }
  13407. }
  13408. }, _callee, this);
  13409. }));
  13410. function getConfig(_x) {
  13411. return _getConfig.apply(this, arguments);
  13412. }
  13413. return getConfig;
  13414. }()
  13415. }, {
  13416. key: "getAllKeys",
  13417. value: function () {
  13418. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  13419. var e, t;
  13420. return regenerator.wrap(function _callee2$(_context2) {
  13421. while (1) {
  13422. switch (_context2.prev = _context2.next) {
  13423. case 0:
  13424. if (!this.allKeys.length) {
  13425. _context2.next = 2;
  13426. break;
  13427. }
  13428. return _context2.abrupt("return", this.allKeys);
  13429. case 2:
  13430. _context2.prev = 2;
  13431. _context2.next = 5;
  13432. return modelTable.getAllKeys();
  13433. case 5:
  13434. e = _context2.sent;
  13435. this.allKeys = e;
  13436. return _context2.abrupt("return", e);
  13437. case 10:
  13438. _context2.prev = 10;
  13439. _context2.t0 = _context2["catch"](2);
  13440. t = "preload getAllKeys error";
  13441. return _context2.abrupt("return", (logger$1.error(t), Promise.reject(t)));
  13442. case 14:
  13443. case "end":
  13444. return _context2.stop();
  13445. }
  13446. }
  13447. }, _callee2, this, [[2, 10]]);
  13448. }));
  13449. function getAllKeys() {
  13450. return _getAllKeys.apply(this, arguments);
  13451. }
  13452. return getAllKeys;
  13453. }()
  13454. }, {
  13455. key: "stop",
  13456. value: function stop(e) {
  13457. e === "serverless" && (e = "observer"), this.requests[e].stopped = !0;
  13458. var t = this.requests[e].requests;
  13459. Object.keys(t).forEach(function (r) {
  13460. http1.canceler.removePending(r), delete t[r];
  13461. });
  13462. }
  13463. }, {
  13464. key: "clearPreload",
  13465. value: function clearPreload(e) {
  13466. this.requests[e].stopped = !1, this.allKeys = [];
  13467. }
  13468. }, {
  13469. key: "start",
  13470. value: function () {
  13471. var _start = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e, t, r) {
  13472. var n, o, a, s, l, u, h, f, _s;
  13473. return regenerator.wrap(function _callee3$(_context3) {
  13474. while (1) {
  13475. switch (_context3.prev = _context3.next) {
  13476. case 0:
  13477. n = Date.now(), o = 0;
  13478. _context3.prev = 1;
  13479. if (!(e === "serverless" && (e = "observer"), !this.requests[e])) {
  13480. _context3.next = 4;
  13481. break;
  13482. }
  13483. return _context3.abrupt("return", Promise.reject(new ParamError("invalid stage name: " + e)));
  13484. case 4:
  13485. this.clearPreload(e);
  13486. _context3.next = 7;
  13487. return this.getConfig(e);
  13488. case 7:
  13489. a = _context3.sent;
  13490. _context3.next = 10;
  13491. return this.getAllKeys();
  13492. case 10:
  13493. s = _context3.sent;
  13494. _context3.prev = 11;
  13495. _context3.next = 14;
  13496. return this.deleteOldResources(a.assetUrls.map(function (d) {
  13497. return d.url;
  13498. }), s);
  13499. case 14:
  13500. _context3.next = 19;
  13501. break;
  13502. case 16:
  13503. _context3.prev = 16;
  13504. _context3.t0 = _context3["catch"](11);
  13505. logger$1.error(_context3.t0);
  13506. case 19:
  13507. l = a.baseUrls, u = a.assetUrls;
  13508. _context3.t1 = e;
  13509. _context3.next = _context3.t1 === "simple" ? 23 : _context3.t1 === "observer" ? 25 : _context3.t1 === "full" ? 27 : 29;
  13510. break;
  13511. case 23:
  13512. h = l;
  13513. return _context3.abrupt("break", 30);
  13514. case 25:
  13515. h = u;
  13516. return _context3.abrupt("break", 30);
  13517. case 27:
  13518. h = u;
  13519. return _context3.abrupt("break", 30);
  13520. case 29:
  13521. h = u;
  13522. case 30:
  13523. f = h.filter(function (d) {
  13524. return !s.includes(d.url);
  13525. });
  13526. r && isFunction(r) && (f = f.filter(r));
  13527. o = f.length;
  13528. logger$1.debug("keysNeedToPreload", f);
  13529. f.length || t && t(h.length, h.length);
  13530. n = Date.now();
  13531. _context3.next = 38;
  13532. return this._preload(e, f, t);
  13533. case 38:
  13534. logger$1.infoAndReportMeasurement({
  13535. tag: e,
  13536. startTime: n,
  13537. metric: "assetsPreload",
  13538. extra: {
  13539. total: o
  13540. }
  13541. });
  13542. return _context3.abrupt("return");
  13543. case 42:
  13544. _context3.prev = 42;
  13545. _context3.t2 = _context3["catch"](1);
  13546. _s = _context3.t2;
  13547. return _context3.abrupt("return", ((this.requests[e].stopped || axios.isCancel(_context3.t2)) && (_s = new PreloadCanceledError()), logger$1.infoAndReportMeasurement({
  13548. tag: e,
  13549. startTime: n,
  13550. metric: "assetsPreload",
  13551. extra: {
  13552. total: o
  13553. },
  13554. error: _s,
  13555. reportOptions: {
  13556. immediate: !0
  13557. }
  13558. }), Promise.reject(_s)));
  13559. case 46:
  13560. case "end":
  13561. return _context3.stop();
  13562. }
  13563. }
  13564. }, _callee3, this, [[1, 42], [11, 16]]);
  13565. }));
  13566. function start(_x2, _x3, _x4) {
  13567. return _start.apply(this, arguments);
  13568. }
  13569. return start;
  13570. }()
  13571. }, {
  13572. key: "deleteOldResources",
  13573. value: function deleteOldResources(e, t) {
  13574. if (!this.oldResourcesDeleted) this.oldResourcesDeleted = !0;else return Promise.resolve();
  13575. var r = t.filter(function (n) {
  13576. return !e.includes(n);
  13577. });
  13578. return logger$1.debug("keysNeedToDelete", r), logger$1.warn("keysNeedToDelete", r.length), Promise.all(r.map(function (n) {
  13579. return modelTable.delete(n);
  13580. }));
  13581. }
  13582. }, {
  13583. key: "_preload",
  13584. value: function () {
  13585. var _preload2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t, r) {
  13586. var _this = this;
  13587. var n, o, a;
  13588. return regenerator.wrap(function _callee6$(_context6) {
  13589. while (1) {
  13590. switch (_context6.prev = _context6.next) {
  13591. case 0:
  13592. n = t.length;
  13593. if (n) {
  13594. _context6.next = 3;
  13595. break;
  13596. }
  13597. return _context6.abrupt("return", Promise.resolve());
  13598. case 3:
  13599. o = 0;
  13600. a = window.setInterval(function () {
  13601. r && r(o, n), o >= n && window.clearInterval(a);
  13602. }, 1e3);
  13603. return _context6.abrupt("return", util.mapLimit(t, 10, /*#__PURE__*/function () {
  13604. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(s) {
  13605. var l, u;
  13606. return regenerator.wrap(function _callee5$(_context5) {
  13607. while (1) {
  13608. switch (_context5.prev = _context5.next) {
  13609. case 0:
  13610. l = s.size, u = s.url;
  13611. return _context5.abrupt("return", _this.requests[e].stopped ? Promise.reject(new PreloadCanceledError()) : http1.get({
  13612. url: u,
  13613. timeout: Preload.getTimeoutBySize(l),
  13614. responseType: "blob",
  13615. retry: 2,
  13616. beforeRequest: function beforeRequest() {
  13617. _this.requests[e].requests[u] = !0;
  13618. }
  13619. }).then( /*#__PURE__*/function () {
  13620. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(c) {
  13621. var h, f;
  13622. return regenerator.wrap(function _callee4$(_context4) {
  13623. while (1) {
  13624. switch (_context4.prev = _context4.next) {
  13625. case 0:
  13626. h = c.data;
  13627. if (h instanceof Blob) {
  13628. _context4.next = 3;
  13629. break;
  13630. }
  13631. return _context4.abrupt("return", (logger$1.error("request blob failed, type:", typeof h, u), Promise.reject("request blob failed " + u)));
  13632. case 3:
  13633. _context4.next = 5;
  13634. return blobToDataURI(h);
  13635. case 5:
  13636. f = _context4.sent;
  13637. _context4.prev = 6;
  13638. _context4.next = 9;
  13639. return modelTable.put({
  13640. url: u,
  13641. model: f
  13642. });
  13643. case 9:
  13644. return _context4.abrupt("return");
  13645. case 12:
  13646. _context4.prev = 12;
  13647. _context4.t0 = _context4["catch"](6);
  13648. return _context4.abrupt("return", (logger$1.error("unable to add data to indexedDB", _context4.t0), Promise.reject(new InternalError("preload db error"))));
  13649. case 15:
  13650. case "end":
  13651. return _context4.stop();
  13652. }
  13653. }
  13654. }, _callee4, null, [[6, 12]]);
  13655. }));
  13656. return function (_x9) {
  13657. return _ref2.apply(this, arguments);
  13658. };
  13659. }()).then(function () {
  13660. o++, delete _this.requests[e].requests[u];
  13661. }, function (c) {
  13662. return delete _this.requests[e].requests[u], window.clearInterval(a), Promise.reject(c);
  13663. }));
  13664. case 2:
  13665. case "end":
  13666. return _context5.stop();
  13667. }
  13668. }
  13669. }, _callee5);
  13670. }));
  13671. return function (_x8) {
  13672. return _ref.apply(this, arguments);
  13673. };
  13674. }()));
  13675. case 6:
  13676. case "end":
  13677. return _context6.stop();
  13678. }
  13679. }
  13680. }, _callee6);
  13681. }));
  13682. function _preload(_x5, _x6, _x7) {
  13683. return _preload2.apply(this, arguments);
  13684. }
  13685. return _preload;
  13686. }()
  13687. }], [{
  13688. key: "getTimeoutBySize",
  13689. value: function getTimeoutBySize(e) {
  13690. return e ? e < 500 * 1e3 ? 30 * 1e3 : e < 1e3 * 1e3 ? 60 * 1e3 : 100 * 1e3 : 100 * 1e3;
  13691. }
  13692. }]);
  13693. return Preload;
  13694. }();
  13695. var RenderType$1 = {
  13696. PathVideo: 0,
  13697. RotationVideo: 1,
  13698. RotationImage: 2,
  13699. PanoramaImage: 3,
  13700. CGVideo: 4,
  13701. ClientRotationPano: 5,
  13702. CloudRotationPano: 6
  13703. };
  13704. var Xverse = /*#__PURE__*/function () {
  13705. function Xverse(e) {
  13706. _classCallCheck(this, Xverse);
  13707. e || (e = {});
  13708. var _e = e,
  13709. t = _e.onLog,
  13710. r = _e.env,
  13711. n = _e.appId,
  13712. o = _e.releaseId,
  13713. a = _e.subPackageVersion;
  13714. this.NO_CACHE = !1, this.env = r || "PROD", this.SUB_PACKAGE_VERSION = a, this.debug && logger$1.setLevel(LoggerLevels.Debug);
  13715. var s = this.pageSession = util.uuid();
  13716. reporter$1.updateHeader({
  13717. pageSession: s
  13718. });
  13719. reporter$1.updateReportUrl(REPORT_URL[this.env]);
  13720. a && reporter$1.updateBody({
  13721. sdkVersion: a
  13722. });
  13723. logger$1.infoAndReportMeasurement({
  13724. metric: "sdkInit",
  13725. startTime: Date.now(),
  13726. extra: {
  13727. version: a,
  13728. enviroment: r,
  13729. pageSession: s
  13730. }
  13731. });
  13732. logger$1.debug("debug mode:", this.debug);
  13733. reporter$1.on("report", function (l) {
  13734. t && t(l);
  13735. });
  13736. if (n) {
  13737. this.appId = n, this.releaseId = o;
  13738. var l = ModelManager.getInstance(n, o);
  13739. this.preload = new Preload(l);
  13740. }
  13741. }
  13742. _createClass(Xverse, [{
  13743. key: "isSupported",
  13744. get: function get() {
  13745. return isSupported();
  13746. }
  13747. }, {
  13748. key: "disableLogUpload",
  13749. value: function disableLogUpload() {
  13750. reporter$1.disable(), logger$1.debug("logger upload has been disabled");
  13751. }
  13752. }, {
  13753. key: "getSkinList",
  13754. value: function () {
  13755. var _getSkinList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  13756. return regenerator.wrap(function _callee$(_context) {
  13757. while (1) {
  13758. switch (_context.prev = _context.next) {
  13759. case 0:
  13760. return _context.abrupt("return", []);
  13761. case 1:
  13762. case "end":
  13763. return _context.stop();
  13764. }
  13765. }
  13766. }, _callee);
  13767. }));
  13768. function getSkinList() {
  13769. return _getSkinList.apply(this, arguments);
  13770. }
  13771. return getSkinList;
  13772. }()
  13773. }, {
  13774. key: "getAvatarList",
  13775. value: function () {
  13776. var _getAvatarList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  13777. return regenerator.wrap(function _callee2$(_context2) {
  13778. while (1) {
  13779. switch (_context2.prev = _context2.next) {
  13780. case 0:
  13781. return _context2.abrupt("return", []);
  13782. case 1:
  13783. case "end":
  13784. return _context2.stop();
  13785. }
  13786. }
  13787. }, _callee2);
  13788. }));
  13789. function getAvatarList() {
  13790. return _getAvatarList.apply(this, arguments);
  13791. }
  13792. return getAvatarList;
  13793. }()
  13794. }, {
  13795. key: "getGiftList",
  13796. value: function () {
  13797. var _getGiftList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  13798. return regenerator.wrap(function _callee3$(_context3) {
  13799. while (1) {
  13800. switch (_context3.prev = _context3.next) {
  13801. case 0:
  13802. return _context3.abrupt("return", [{
  13803. id: "hack "
  13804. }]);
  13805. case 1:
  13806. case "end":
  13807. return _context3.stop();
  13808. }
  13809. }
  13810. }, _callee3);
  13811. }));
  13812. function getGiftList() {
  13813. return _getGiftList.apply(this, arguments);
  13814. }
  13815. return getGiftList;
  13816. }()
  13817. }, {
  13818. key: "joinRoom",
  13819. value: function () {
  13820. var _joinRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  13821. var t, r, n, o;
  13822. return regenerator.wrap(function _callee4$(_context4) {
  13823. while (1) {
  13824. switch (_context4.prev = _context4.next) {
  13825. case 0:
  13826. t = e.pathName || "thirdwalk", r = e.rotationRenderType || RenderType$1.RotationVideo, n = e.person || Person$1.Third, o = new XverseRoom(le(oe({}, e), {
  13827. appId: e.appId || this.appId,
  13828. releaseId: e.releaseId || this.releaseId,
  13829. pageSession: this.pageSession,
  13830. isAllSync: !0,
  13831. rotationRenderType: r,
  13832. syncByEvent: !0,
  13833. pathName: t,
  13834. person: n,
  13835. role: e.role || "audience"
  13836. }));
  13837. return _context4.abrupt("return", o.initRoom().then(function () {
  13838. return o;
  13839. }));
  13840. case 2:
  13841. case "end":
  13842. return _context4.stop();
  13843. }
  13844. }
  13845. }, _callee4, this);
  13846. }));
  13847. function joinRoom(_x) {
  13848. return _joinRoom.apply(this, arguments);
  13849. }
  13850. return joinRoom;
  13851. }()
  13852. }]);
  13853. return Xverse;
  13854. }();
  13855. var xverse = new Xverse({
  13856. env: "DEV",
  13857. appId: "10016",
  13858. releaseId: '2203120033_29769e'
  13859. });
  13860. var l = /*#__PURE__*/function () {
  13861. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  13862. var R;
  13863. return regenerator.wrap(function _callee$(_context) {
  13864. while (1) {
  13865. switch (_context.prev = _context.next) {
  13866. case 0:
  13867. _context.prev = 0;
  13868. _context.next = 3;
  13869. return (R = xverse.preload) == null ? void 0 : R.start('full', function (M, x) {
  13870. });
  13871. case 3:
  13872. _context.next = 12;
  13873. break;
  13874. case 5:
  13875. _context.prev = 5;
  13876. _context.t0 = _context["catch"](0);
  13877. if (!(console.error(_context.t0), _context.t0.code === Codes.PreloadCanceled)) {
  13878. _context.next = 10;
  13879. break;
  13880. }
  13881. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88");
  13882. return _context.abrupt("return");
  13883. case 10:
  13884. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5");
  13885. return _context.abrupt("return");
  13886. case 12:
  13887. _context.prev = 12;
  13888. _context.next = 15;
  13889. return xverse.joinRoom({
  13890. canvas: document.getElementById('canvas'),
  13891. skinId: '10092',
  13892. avatarId: 'KGe_Boy',
  13893. roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
  13894. userId: '1f7acca1db9d5',
  13895. wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
  13896. appId: "10016",
  13897. token: " ",
  13898. nickname: '1f7acca1db9d5',
  13899. firends: ["user1"],
  13900. viewMode: "full",
  13901. resolution: {
  13902. width: 1728,
  13903. height: 720
  13904. },
  13905. pathName: 'thirdwalk',
  13906. objectFit: null,
  13907. hasAvatar: !0,
  13908. syncToOthers: !0
  13909. });
  13910. case 15:
  13911. room = _context.sent;
  13912. debugger;
  13913. u();
  13914. c();
  13915. window.room = room;
  13916. e(!1);
  13917. _context.next = 28;
  13918. break;
  13919. case 23:
  13920. _context.prev = 23;
  13921. _context.t1 = _context["catch"](12);
  13922. console.error(_context.t1);
  13923. alert(_context.t1);
  13924. return _context.abrupt("return");
  13925. case 28:
  13926. case "end":
  13927. return _context.stop();
  13928. }
  13929. }
  13930. }, _callee, null, [[0, 5], [12, 23]]);
  13931. }));
  13932. return function l() {
  13933. return _ref.apply(this, arguments);
  13934. };
  13935. }();
  13936. var u = function u() {
  13937. room.on("_coreClick", function (_ref2) {
  13938. var f = _ref2.point;
  13939. room._userAvatar.moveTo({
  13940. point: f
  13941. });
  13942. });
  13943. };
  13944. var c = function c() {
  13945. room.on("repeatLogin", function () {
  13946. toast("\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55", {
  13947. duration: 1e4
  13948. });
  13949. }), room.on("reconnecting", function (_ref3) {
  13950. var f = _ref3.count;
  13951. toast("\u5C1D\u8BD5\u7B2C".concat(f, "\u6B21\u91CD\u8FDE"));
  13952. }), room.on("reconnected", function () {
  13953. toast("\u91CD\u8FDE\u6210\u529F");
  13954. }), room.on("disconnected", function () {
  13955. var f = toast("\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5", {
  13956. duration: 1e5,
  13957. onClick() {
  13958. f.hideToast(), room.reconnect();
  13959. }
  13960. });
  13961. });
  13962. };
  13963. l();
  13964. }));
  13965. //# sourceMappingURL=index.js.map