index.js 584 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331
  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$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); }; }
  836. 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; } }
  837. var Reporter = /*#__PURE__*/function (_EventEmitter) {
  838. _inherits(Reporter, _EventEmitter);
  839. var _super = _createSuper$n(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$m(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$n(); 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$n() { 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$m(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$m() {
  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$m()) {
  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$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); }; }
  1945. 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; } }
  1946. var XverseError = /*#__PURE__*/function (_Error) {
  1947. _inherits(XverseError, _Error);
  1948. var _super = _createSuper$l(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$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); }; }
  1979. 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; } }
  1980. var TimeoutError = /*#__PURE__*/function (_XverseError) {
  1981. _inherits(TimeoutError, _XverseError);
  1982. var _super = _createSuper$k(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$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); }; }
  2303. 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; } }
  2304. var XverseAvatarManager = /*#__PURE__*/function (_EventEmitter) {
  2305. _inherits(XverseAvatarManager, _EventEmitter);
  2306. var _super = _createSuper$j(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. 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); }; }
  2870. 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; } }
  2871. var Camera = /*#__PURE__*/function (_EventEmitter) {
  2872. _inherits(Camera, _EventEmitter);
  2873. var _super = _createSuper$i(Camera);
  2874. function Camera(e) {
  2875. var _this;
  2876. _classCallCheck(this, Camera);
  2877. _this = _super.call(this);
  2878. _this.initialFov = 0;
  2879. _this._state = CameraStates.Normal;
  2880. _this._person = Person$1.Third;
  2881. _this._cameraFollowing = !0;
  2882. _this._room = e;
  2883. return _this;
  2884. }
  2885. _createClass(Camera, [{
  2886. key: "checkPointOnLeftOrRight",
  2887. value: function checkPointOnLeftOrRight(e) {
  2888. var t = ue4Position2Xverse(e);
  2889. if (!t || this.checkPointInView(e)) return;
  2890. var o = this._room.scene.activeCamera;
  2891. if (!o) return;
  2892. var a = [o.target.x, o.target.y, o.target.z],
  2893. s = [o.position.x, o.position.y, o.position.z],
  2894. l = t.x,
  2895. u = t.y,
  2896. c = t.z,
  2897. h = calNormVector(s, a),
  2898. f = calNormVector(s, [l, u, c]);
  2899. return vectorCrossMulti(h, f) < 0 ? Direction.Right : Direction.Left;
  2900. }
  2901. }, {
  2902. key: "checkPointInView",
  2903. value: function checkPointInView(e, t, r) {
  2904. var n = ue4Position2Xverse({
  2905. x: e,
  2906. y: t,
  2907. z: r
  2908. });
  2909. if (!n) return !1;
  2910. for (var o = 0; o < 6; o++) {
  2911. if (this._room.scene.frustumPlanes[o].dotCoordinate(n) < 0) return !1;
  2912. }
  2913. return !0;
  2914. }
  2915. }, {
  2916. key: "person",
  2917. get: function get() {
  2918. return this._person;
  2919. }
  2920. }, {
  2921. key: "state",
  2922. get: function get() {
  2923. return this._state;
  2924. }
  2925. }, {
  2926. key: "pose",
  2927. get: function get() {
  2928. return this._room.currentClickingState.camera;
  2929. }
  2930. }, {
  2931. key: "cameraFollowing",
  2932. get: function get() {
  2933. return this._cameraFollowing;
  2934. },
  2935. set: function set(e) {
  2936. logger$1.info("cameraFollowing setter", e), this.setCameraFollowing({
  2937. isFollowHost: e
  2938. });
  2939. }
  2940. }, {
  2941. key: "setCameraFollowing",
  2942. value: function setCameraFollowing(_ref) {
  2943. _ref.isFollowHost;
  2944. }
  2945. }, {
  2946. key: "handleRenderInfo",
  2947. value: function handleRenderInfo(e) {
  2948. var t = e.renderInfo.cameraStateType,
  2949. r = this._room.sceneManager;
  2950. 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", {
  2951. state: t
  2952. })), this._room.isHost) return;
  2953. var n = e.playerState.isFollowHost;
  2954. !!n !== this._cameraFollowing && (this._cameraFollowing = !!n, this.emit("cameraFollowingChanged", {
  2955. cameraFollowing: !!n
  2956. }));
  2957. }
  2958. }, {
  2959. key: "setCameraState",
  2960. value: function setCameraState(_ref2) {
  2961. var e = _ref2.state;
  2962. if (this._state === e) {
  2963. logger$1.warn("You are already in ".concat(CameraStates[e], " camera state"));
  2964. return;
  2965. }
  2966. e === CameraStates.Normal || this._state === CameraStates.ItemView && logger$1.warn("CloseUp camera state can only be triggerd by room internally");
  2967. }
  2968. }, {
  2969. key: "turnToFace",
  2970. value: function turnToFace(_ref3) {
  2971. var _ref3$extra = _ref3.extra,
  2972. e = _ref3$extra === void 0 ? "" : _ref3$extra,
  2973. _ref3$offset = _ref3.offset,
  2974. t = _ref3$offset === void 0 ? 0 : _ref3$offset;
  2975. var r = {
  2976. action_type: Actions.TurnToFace,
  2977. turn_to_face_action: {
  2978. offset: t
  2979. }
  2980. };
  2981. return this.emit("viewChanged", {
  2982. extra: e
  2983. }), this._room.actionsHandler.sendData({
  2984. data: r
  2985. });
  2986. }
  2987. }, {
  2988. key: "isInDefaultView",
  2989. value: function isInDefaultView() {
  2990. if (!this._room.isHost) {
  2991. logger$1.warn("It is recommended to call the function on the host side");
  2992. return;
  2993. }
  2994. if (!this._room._currentClickingState) return logger$1.error("CurrentState should not be empty"), !1;
  2995. var _this$_room$_currentC = this._room._currentClickingState,
  2996. e = _this$_room$_currentC.camera,
  2997. t = _this$_room$_currentC.player;
  2998. return Math.abs(t.angle.yaw - 180 - e.angle.yaw) % 360 <= 4;
  2999. }
  3000. }, {
  3001. key: "screenShot",
  3002. value: function () {
  3003. var _screenShot = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_ref4) {
  3004. var e, _ref4$autoSave, t, r, n, o;
  3005. return regenerator.wrap(function _callee$(_context) {
  3006. while (1) {
  3007. switch (_context.prev = _context.next) {
  3008. case 0:
  3009. e = _ref4.name, _ref4$autoSave = _ref4.autoSave, t = _ref4$autoSave === void 0 ? !1 : _ref4$autoSave;
  3010. r = this._room.scene.getEngine(), n = this._room.scene.activeCamera;
  3011. _context.prev = 2;
  3012. this._room.sceneManager.setImageQuality(EImageQuality.high);
  3013. _context.next = 6;
  3014. return CreateScreenshotAsync(r, n, {
  3015. precision: 1
  3016. });
  3017. case 6:
  3018. o = _context.sent;
  3019. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), t === !0 && downloadFileByBase64(o, e), Promise.resolve(o)));
  3020. case 10:
  3021. _context.prev = 10;
  3022. _context.t0 = _context["catch"](2);
  3023. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), Promise.reject(_context.t0)));
  3024. case 13:
  3025. case "end":
  3026. return _context.stop();
  3027. }
  3028. }
  3029. }, _callee, this, [[2, 10]]);
  3030. }));
  3031. function screenShot(_x) {
  3032. return _screenShot.apply(this, arguments);
  3033. }
  3034. return screenShot;
  3035. }()
  3036. }, {
  3037. key: "changeToFirstPerson",
  3038. value: function changeToFirstPerson(e, t, r) {
  3039. var _this2 = this;
  3040. var n = e.camera,
  3041. o = e.player,
  3042. a = e.attitude,
  3043. s = e.areaName,
  3044. l = e.pathName;
  3045. return this._room.actionsHandler.requestPanorama({
  3046. camera: n,
  3047. player: o,
  3048. attitude: a,
  3049. areaName: s,
  3050. pathName: l
  3051. }, t, r).then(function () {
  3052. _this2._room.networkController.rtcp.workers.changePanoMode(!0);
  3053. var _ref5 = o || {},
  3054. u = _ref5.position,
  3055. c = _ref5.angle;
  3056. _this2._room.sceneManager.cameraComponent.changeToFirstPersonView({
  3057. position: u,
  3058. rotation: c
  3059. });
  3060. });
  3061. }
  3062. }, {
  3063. key: "setPerson",
  3064. value: function setPerson(e) {
  3065. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  3066. camera: this._room._currentClickingState.camera,
  3067. player: this._room._currentClickingState.player
  3068. };
  3069. var r = Date.now();
  3070. return this._setPerson(e, t).then(function (n) {
  3071. return logger$1.infoAndReportMeasurement({
  3072. tag: Person$1[e],
  3073. startTime: r,
  3074. metric: "setPerson"
  3075. }), n;
  3076. }).catch(function (n) {
  3077. return logger$1.infoAndReportMeasurement({
  3078. tag: Person$1[e],
  3079. startTime: r,
  3080. metric: "setPerson",
  3081. error: n
  3082. }), Promise.reject(n);
  3083. });
  3084. }
  3085. }, {
  3086. key: "_setPerson",
  3087. value: function _setPerson(e) {
  3088. var _this3 = this;
  3089. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  3090. camera: this._room._currentClickingState.camera,
  3091. player: this._room._currentClickingState.player
  3092. };
  3093. 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({
  3094. camera: t.camera,
  3095. player: t.player,
  3096. tag: "setPerson"
  3097. }).then(function () {
  3098. var o, a;
  3099. _this3._person = e, (o = _this3._room._userAvatar) == null || o.hide();
  3100. var _ref6 = ((a = _this3._room.currentClickingState) == null ? void 0 : a.camera) || {},
  3101. r = _ref6.position,
  3102. n = _ref6.angle;
  3103. !r || !n || _this3._room.sceneManager.cameraComponent.changeToFirstPersonView({
  3104. position: r,
  3105. rotation: n
  3106. });
  3107. }) : this._room.panorama.exit({
  3108. camera: t.camera,
  3109. player: t.player
  3110. }).then(function () {
  3111. var r, n;
  3112. _this3._person = e, (r = _this3._room._userAvatar) != null && r.xAvatar && ((n = _this3._room._userAvatar) == null || n.xAvatar.show());
  3113. });
  3114. }
  3115. }, {
  3116. key: "setCameraPose",
  3117. value: function setCameraPose(e) {
  3118. this._room.sceneManager.cameraComponent.setCameraPose({
  3119. position: e.position,
  3120. rotation: e.angle
  3121. });
  3122. }
  3123. }, {
  3124. key: "setMainCameraRotationLimit",
  3125. value: function setMainCameraRotationLimit(e) {
  3126. var t = e.limitAxis,
  3127. r = e.limitRotation;
  3128. this._room.sceneManager.cameraComponent.setMainCameraRotationLimit(t, r);
  3129. }
  3130. }]);
  3131. return Camera;
  3132. }(EventEmitter);
  3133. 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); }; }
  3134. 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; } }
  3135. var numberFormat = new Intl.NumberFormat(window.navigator.language, {
  3136. maximumFractionDigits: 0
  3137. });
  3138. var Stats = /*#__PURE__*/function (_EventEmitter) {
  3139. _inherits(Stats, _EventEmitter);
  3140. var _super = _createSuper$h(Stats);
  3141. function Stats(e) {
  3142. var _this;
  3143. _classCallCheck(this, Stats);
  3144. _this = _super.call(this);
  3145. _this._netInterval = null;
  3146. _this._disabled = !1;
  3147. _this._show = !1;
  3148. _this._aggregatedStats = {};
  3149. _this._displayElement = null;
  3150. _this._extraStats = {};
  3151. _this._networkSamples = [];
  3152. _this.externalStats = null;
  3153. _this.constructedTime = null;
  3154. _this.room = e, _this.constructedTime = Date.now(), _this._interval = window.setInterval(function () {
  3155. var t, r, n;
  3156. _this._disabled || _this.onStats((n = (r = (t = e.networkController) == null ? void 0 : t.rtcp) == null ? void 0 : r.workers) == null ? void 0 : n.uploadDataToServer());
  3157. }, 1e3), _this._netInterval = window.setInterval(function () {
  3158. _this.getIsWeakNet();
  3159. }, NET_INTERVAL * 1e3);
  3160. return _this;
  3161. }
  3162. _createClass(Stats, [{
  3163. key: "isShow",
  3164. get: function get() {
  3165. return this._show;
  3166. }
  3167. }, {
  3168. key: "assign",
  3169. value: function assign(e) {
  3170. Object.assign(this._extraStats, e), ((e == null ? void 0 : e.hb) || (e == null ? void 0 : e.rtt)) && this.startStatsNetSamples();
  3171. }
  3172. }, {
  3173. key: "appendExternalStats",
  3174. value: function appendExternalStats(e) {
  3175. var _this2 = this;
  3176. var t = {};
  3177. if (!e || typeof e != "object") {
  3178. console.warn("appendExternalStats should be plain object");
  3179. return;
  3180. }
  3181. Object.keys(e).forEach(function (r) {
  3182. Object.prototype.hasOwnProperty.call(_this2._aggregatedStats, r) ? console.warn("".concat(r, " is duplicate with internal stats")) : t[r] = e[r];
  3183. }), !(Object.keys(t).length > 10) && (this.externalStats = t);
  3184. }
  3185. }, {
  3186. key: "getRtt",
  3187. value: function getRtt() {
  3188. var e = this._extraStats.rtt;
  3189. return typeof e != "number" ? 0 : e > 999 ? 999 : e;
  3190. }
  3191. }, {
  3192. key: "enable",
  3193. value: function enable() {
  3194. this._disabled = !1;
  3195. }
  3196. }, {
  3197. key: "disable",
  3198. value: function disable() {
  3199. this._disabled = !0;
  3200. }
  3201. }, {
  3202. key: "disableNet",
  3203. value: function disableNet() {
  3204. this._netInterval && window.clearInterval(this._netInterval);
  3205. }
  3206. }, {
  3207. key: "show",
  3208. value: function show() {
  3209. this._show = !0, this._render();
  3210. }
  3211. }, {
  3212. key: "hide",
  3213. value: function hide() {
  3214. this._show = !1, this._displayElement && document.body.removeChild(this._displayElement), this._displayElement = null;
  3215. }
  3216. }, {
  3217. key: "getIsWeakNet",
  3218. value: function getIsWeakNet() {
  3219. var _this3 = this;
  3220. var e = !1;
  3221. var t = this._networkSamples.length - 1;
  3222. if (t < 0) return;
  3223. var r = this._networkSamples[t].time,
  3224. n = this._networkSamples[0].time,
  3225. o = r - n,
  3226. a = 1e3 * (DURATION - 2);
  3227. if (o < a) return;
  3228. var s = this._networkSamples.map(function (g) {
  3229. return _this3.isNetDelay(g, "rtt");
  3230. }),
  3231. l = this._networkSamples.map(function (g) {
  3232. return _this3.isNetDelay(g, "hb");
  3233. }),
  3234. u = s.reduce(function (g, m) {
  3235. return g + m;
  3236. }, 0),
  3237. c = l.reduce(function (g, m) {
  3238. return g + m;
  3239. }, 0),
  3240. h = Math.floor(u / this._networkSamples.length) * 100,
  3241. f = Math.floor(c / this._networkSamples.length) * 100,
  3242. d = 70;
  3243. (h >= d || f >= d) && (e = !0);
  3244. var _ = this.room.viewMode === "observer" || this.room.viewMode === "serverless";
  3245. e && !_ && (logger$1.infoAndReportMeasurement({
  3246. metric: "weakNetwork",
  3247. startTime: Date.now(),
  3248. extra: {
  3249. msg: this._networkSamples.slice(20),
  3250. netDelayRTTValues: u,
  3251. netDelayHBValues: c
  3252. }
  3253. }), this.emit("weakNetwork"));
  3254. }
  3255. }, {
  3256. key: "startStatsNetSamples",
  3257. value: function startStatsNetSamples() {
  3258. var _this$_extraStats = this._extraStats,
  3259. e = _this$_extraStats.rtt,
  3260. t = _this$_extraStats.hb;
  3261. if (e || t) {
  3262. var r = {
  3263. rtt: e,
  3264. hb: t,
  3265. time: new Date().getTime()
  3266. };
  3267. this._networkSamples.push(r);
  3268. var n = this._networkSamples.length - 1;
  3269. if (n < 0) return;
  3270. var o = this._networkSamples[n].time,
  3271. a = 1e3 * DURATION;
  3272. this._networkSamples = this._networkSamples.filter(function (s) {
  3273. return s.time > o - a;
  3274. });
  3275. }
  3276. }
  3277. }, {
  3278. key: "isNetDelay",
  3279. value: function isNetDelay(e, t) {
  3280. return t === "rtt" ? e.rtt > RTT_MAX_VALUE ? 1 : 0 : t === "hb" && e.hb > HB_MAX_VALUE ? 1 : 0;
  3281. }
  3282. }, {
  3283. key: "getPreciesTimer",
  3284. value: function getPreciesTimer(e, t) {
  3285. var r = t * 1e3,
  3286. n = new Date().getTime();
  3287. var o = 0;
  3288. o++;
  3289. var a = new Date().getTime() - (n + o * 1e3),
  3290. s = r - a,
  3291. l = setTimeout(function () {
  3292. clearTimeout(l), e();
  3293. }, s);
  3294. }
  3295. }, {
  3296. key: "_render",
  3297. value: function _render() {
  3298. var c, h, f, d, _, g, m, v, y, b, T, C, A, S, P, R, M, x, I, w;
  3299. if (!this._aggregatedStats) return;
  3300. 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));
  3301. var e = [],
  3302. t = Date.now() - this.constructedTime,
  3303. r = Math.floor(t / 1e3 % 60),
  3304. n = Math.floor(t / (1e3 * 60) % 60),
  3305. o = Math.floor(t / (1e3 * 60 * 60) % 24),
  3306. a = o < 10 ? "0" + o.toString() : o.toString(),
  3307. s = n < 10 ? "0" + n : n,
  3308. l = r < 10 ? "0" + r : r;
  3309. e.push({
  3310. key: new Date(Math.floor(this._aggregatedStats.timestamp || 0)).toLocaleString("en-GB"),
  3311. value: a + ":" + s + ":" + l
  3312. }), e.push({
  3313. key: "rtt: " + this._extraStats.rtt + " hb: " + this._extraStats.hb,
  3314. value: "FPS: " + this._extraStats.fps + " avatar: " + ((c = this.room._userAvatar) == null ? void 0 : c.state)
  3315. }), e.push({
  3316. key: "SDK: " + Xverse$1.SUB_PACKAGE_VERSION,
  3317. value: "ENGINE:" + VERSION$1 + " uid:" + this._extraStats.userId
  3318. }), e.push({
  3319. key: "\u540C\u6B65/\u6709\u6548/\u663E\u793A\u73A9\u5BB6",
  3320. value: "".concat(this._extraStats.syncUserNum || 0, "/").concat(this._extraStats.userNum || 0, "/").concat(this._extraStats.renderedUserNum || 0)
  3321. }), e.push({
  3322. key: "media/meta bitrate(kbps)",
  3323. value: numberFormat.format(this._aggregatedStats.mediaBitrate || 0) + "/" + numberFormat.format(this._aggregatedStats.metaBitrate || 0)
  3324. }), e.push({
  3325. key: ":----------------Decoding---------------",
  3326. value: ""
  3327. }), e.push({
  3328. key: "-max/avg decodeTime(ms)",
  3329. value: numberFormat.format(this._aggregatedStats.decodeTimeMaxFrame || 0) + "/" + numberFormat.format(this._aggregatedStats.decodeTimePerFrame || 0)
  3330. }), e.push({
  3331. key: "-frmAwait/Lost/Drop",
  3332. 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
  3333. }), e.push({
  3334. key: ":----------------FrameLoop-------------",
  3335. value: ""
  3336. }), e.push({
  3337. key: "interval(max/avg/>40)",
  3338. 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
  3339. }), e.push({
  3340. key: "systemStuck",
  3341. value: this._extraStats.systemStuckCnt
  3342. }), e.push({
  3343. key: "--update",
  3344. value: (this._aggregatedStats.maxGraphicTime.toFixed(1) || 0) + "/" + (((d = this._aggregatedStats.averageGraphicTime) == null ? void 0 : d.toFixed(0)) || 0)
  3345. }), e.push({
  3346. key: "--timeout",
  3347. value: (((_ = this._extraStats.maxTimeoutTime) == null ? void 0 : _.toFixed(1)) || 0) + "/" + ((g = this._extraStats.avgTimeoutTime) == null ? void 0 : g.toFixed(0)) || 0
  3348. }), e.push({
  3349. key: "--render",
  3350. value: (((m = this._extraStats.maxRenderFrameTime) == null ? void 0 : m.toFixed(1)) || 0) + "/" + (((v = this._extraStats.renderFrameTime) == null ? void 0 : v.toFixed(0)) || 0)
  3351. }), e.push({
  3352. key: "---anim/regBR/clip(avg ms)",
  3353. value: (this._extraStats.animationTime.toFixed(2) || 0) + " / " + (this._extraStats.registerBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.meshSelectTime.toFixed(2) || 0)
  3354. }), e.push({
  3355. key: "---anim/regBR/clip(max ms)",
  3356. value: (this._extraStats.maxAnimationTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxMeshSelectTime.toFixed(2) || 0)
  3357. }), e.push({
  3358. key: "---rTR/drC/regAF(avg ms)",
  3359. value: (this._extraStats.renderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.drawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.registerAfterRenderTime.toFixed(2) || 0)
  3360. }), e.push({
  3361. key: "---rTR/drC/regAF(max ms)",
  3362. value: (this._extraStats.maxRenderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxDrawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterAfterRenderTime.toFixed(2) || 0)
  3363. }), e.push({
  3364. key: "--tri/drC/pati/bones/anim(Num)",
  3365. 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)
  3366. }), e.push({
  3367. key: "--rootN/mesh/geo/tex/mat(Num)",
  3368. 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)
  3369. }), e.push({
  3370. key: "--registerBF/AF(Num)",
  3371. value: (this._extraStats.registerBeforeCount.toFixed(0) || 0) + " / " + (this._extraStats.registerAfterCount.toFixed(0) || 0)
  3372. }), e.push({
  3373. key: ":----------------Rotation-------------------",
  3374. value: ""
  3375. }), e.push({
  3376. key: "Total(ms/miss)",
  3377. value: (((y = this._aggregatedStats.avgOverallTime) == null ? void 0 : y.toFixed(2)) || 0) + "/" + (this._aggregatedStats.responseMissPs + this._aggregatedStats.processMissPs + this._aggregatedStats.displayMissPs)
  3378. }), e.push({
  3379. key: "--rotateRsp",
  3380. value: (((b = this._aggregatedStats.avgResponseTime) == null ? void 0 : b.toFixed(1)) || 0) + "/" + this._aggregatedStats.responseMissPs
  3381. }), e.push({
  3382. key: "--rotateProc",
  3383. value: (((T = this._aggregatedStats.avgProcessTime) == null ? void 0 : T.toFixed(1)) || 0) + "/" + this._aggregatedStats.processMissPs
  3384. }), e.push({
  3385. key: "--rotateShow",
  3386. value: (((C = this._aggregatedStats.avgDisplayTime) == null ? void 0 : C.toFixed(1)) || 0) + "/" + this._aggregatedStats.displayMissPs
  3387. }), ((A = this.room._userAvatar) == null ? void 0 : A.state) == "moving", e.push({
  3388. key: ":----------------Move----------------------",
  3389. value: ""
  3390. }), e.push({
  3391. key: "-startDelay",
  3392. 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)
  3393. }), (((S = this.room._userAvatar) == null ? void 0 : S.state) == "moving" || this._aggregatedStats.moveEvent == "GetOnAirship" || this._aggregatedStats.moveEvent == "GetOnVehicle") && e.push({
  3394. key: "-srvInterFrm(max/avg)",
  3395. value: (this._aggregatedStats.maxServerDiff || 0) + "/" + (this._aggregatedStats.avgServerDiff.toFixed(1) || 0)
  3396. }), e.push({
  3397. key: "-interFrameDelay",
  3398. value: "(max/avg/jank)"
  3399. }), e.push({
  3400. key: "--toDisplay",
  3401. 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)
  3402. }), e.push({
  3403. key: "--received",
  3404. 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)
  3405. }), e.push({
  3406. key: "--decoded",
  3407. 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)
  3408. }), e.push({
  3409. key: ":----------------DevInfo-----------------",
  3410. value: ""
  3411. }), e.push({
  3412. key: "sd",
  3413. value: (this._aggregatedStats.sdMoveResponseLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveProcessLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveDisplayLongTime.toFixed(1) || 0)
  3414. }), e.push({
  3415. key: "----hardwareInfo",
  3416. value: this._extraStats.hardwareInfo
  3417. });
  3418. var u = "";
  3419. for (var _i = 0, _e = e; _i < _e.length; _i++) {
  3420. var O = _e[_i];
  3421. u += "<div><span>".concat(O.key, "</span>: <span>").concat(O.value, "</span> </div>");
  3422. }
  3423. this._displayElement.innerHTML = u;
  3424. }
  3425. }, {
  3426. key: "onStats",
  3427. value: function onStats(e) {
  3428. var _this4 = this;
  3429. var n;
  3430. if (!e) return;
  3431. var t = {},
  3432. r = this;
  3433. 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) {
  3434. t[o] = _this4.externalStats[o];
  3435. }), r._aggregatedStats = t, this.emit("stats", {
  3436. stats: t
  3437. });
  3438. }
  3439. }]);
  3440. return Stats;
  3441. }(EventEmitter);
  3442. var Actions$1 = {
  3443. Clicking: 1,
  3444. PlayCG: 6,
  3445. Back: 7,
  3446. ChangeRoom: 8,
  3447. ChangeSkin: 13,
  3448. Joystick: 15,
  3449. Transfer: 18,
  3450. GetOnVehicle: 22,
  3451. GetOffVehicle: 23,
  3452. StopMoving: 34,
  3453. UnaryActionLine: 1e3,
  3454. Init: 1001,
  3455. Exit: 1002,
  3456. SetIFrameInfo: 1003,
  3457. GetNeighborPoints: 1004,
  3458. ReserveSeat: 1005,
  3459. GetReserveStatus: 1006,
  3460. ChangeNickname: 1007,
  3461. ChangeBitRateInfo: 1008,
  3462. Echo: 1009,
  3463. SetPlayerState: 1010,
  3464. TurnTo: 1011,
  3465. TurnToFace: 1012,
  3466. RotateTo: 1013,
  3467. Rotation: 1014,
  3468. CameraTurnTo: 1015,
  3469. ConfirmEvent: 1016,
  3470. Broadcast: 1017,
  3471. NotifyActionLine: 2e4,
  3472. AudienceChangeToVisitor: 1020,
  3473. VisitorChangeToAudience: 1021,
  3474. RemoveVisitor: 1022,
  3475. GetUserWithAvatar: 1023
  3476. };
  3477. 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); }; }
  3478. 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; } }
  3479. var EventsManager = /*#__PURE__*/function (_EventEmitter) {
  3480. _inherits(EventsManager, _EventEmitter);
  3481. var _super = _createSuper$g(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$1.Transfer, Actions$1.ChangeSkin, Actions$1.GetOnVehicle, Actions$1.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$1.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$1[this.currentActiveAction], " still pending, reject ").concat(Actions$1[r])), Promise.reject(new FrequencyLimitError("".concat(Actions$1[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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$1.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$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); }; }
  4483. 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; } }
  4484. var XverseEffectManager = /*#__PURE__*/function (_EventEmitter) {
  4485. _inherits(XverseEffectManager, _EventEmitter);
  4486. var _super = _createSuper$f(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$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); }; }
  4553. 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; } }
  4554. var ParamError$1 = /*#__PURE__*/function (_XverseError) {
  4555. _inherits(ParamError, _XverseError);
  4556. var _super = _createSuper$e(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$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); }; }
  4648. 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; } }
  4649. var InitNetworkTimeoutError = /*#__PURE__*/function (_XverseError) {
  4650. _inherits(InitNetworkTimeoutError, _XverseError);
  4651. var _super = _createSuper$d(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$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); }; }
  4659. 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; } }
  4660. var Socket = /*#__PURE__*/function (_EventEmitter) {
  4661. _inherits(Socket, _EventEmitter);
  4662. var _super = _createSuper$c(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$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); }; }
  5971. 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; } }
  5972. var Rtcp = /*#__PURE__*/function (_EventEmitter) {
  5973. _inherits(Rtcp, _EventEmitter);
  5974. var _super = _createSuper$b(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$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); }; }
  6241. 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; } }
  6242. var InternalError$1 = /*#__PURE__*/function (_XverseError) {
  6243. _inherits(InternalError, _XverseError);
  6244. var _super = _createSuper$a(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$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); }; }
  6252. 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; } }
  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$9(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$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); }; }
  6526. 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; } }
  6527. var InitConfigTimeoutError = /*#__PURE__*/function (_XverseError) {
  6528. _inherits(InitConfigTimeoutError, _XverseError);
  6529. var _super = _createSuper$8(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$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); }; }
  6537. 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; } }
  6538. var InitDecoderTimeoutError = /*#__PURE__*/function (_XverseError) {
  6539. _inherits(InitDecoderTimeoutError, _XverseError);
  6540. var _super = _createSuper$7(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$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); }; }
  6548. 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; } }
  6549. var InitEngineError = /*#__PURE__*/function (_XverseError) {
  6550. _inherits(InitEngineError, _XverseError);
  6551. var _super = _createSuper$6(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$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); }; }
  6892. 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; } }
  6893. var ModelTable = /*#__PURE__*/function (_BaseTable) {
  6894. _inherits(ModelTable, _BaseTable);
  6895. var _super = _createSuper$5(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$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); }; }
  6920. 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; } }
  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$4(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$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); }; }
  7625. 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; } }
  7626. var XLowpolyModelError = /*#__PURE__*/function (_XverseError) {
  7627. _inherits(XLowpolyModelError, _XverseError);
  7628. var _super = _createSuper$3(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 = 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$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); }; }
  11223. 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; } }
  11224. var InitEngineTimeoutError = /*#__PURE__*/function (_XverseError) {
  11225. _inherits(InitEngineTimeoutError, _XverseError);
  11226. var _super = _createSuper$2(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 > ye._CHECK_DURATION && (_this._checkSceneDurationFrameNum = ye._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 = ye._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$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); }; }
  12127. 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; } }
  12128. var Xverse_Room = /*#__PURE__*/function (_EventEmitter) {
  12129. _inherits(Xverse_Room, _EventEmitter);
  12130. var _super = _createSuper$1(Xverse_Room);
  12131. function Xverse_Room(e) {
  12132. var _this;
  12133. _classCallCheck(this, Xverse_Room);
  12134. _this = _super.call(this);
  12135. E(_assertThisInitialized(_this), "disableAutoTurn", !1);
  12136. E(_assertThisInitialized(_this), "options");
  12137. E(_assertThisInitialized(_this), "_currentNetworkOptions");
  12138. E(_assertThisInitialized(_this), "lastSkinId");
  12139. E(_assertThisInitialized(_this), "debug");
  12140. E(_assertThisInitialized(_this), "isFirstDataUsed", !1);
  12141. E(_assertThisInitialized(_this), "userId", null);
  12142. E(_assertThisInitialized(_this), "pathManager", new PathManager());
  12143. E(_assertThisInitialized(_this), "networkController");
  12144. E(_assertThisInitialized(_this), "_startTime", Date.now());
  12145. E(_assertThisInitialized(_this), "canvas");
  12146. E(_assertThisInitialized(_this), "modelManager");
  12147. E(_assertThisInitialized(_this), "eventsController");
  12148. E(_assertThisInitialized(_this), "panorama");
  12149. E(_assertThisInitialized(_this), "engineProxy");
  12150. E(_assertThisInitialized(_this), "_id");
  12151. E(_assertThisInitialized(_this), "skinList", []);
  12152. E(_assertThisInitialized(_this), "isHost", !1);
  12153. E(_assertThisInitialized(_this), "avatarManager", new XverseAvatarManager(_assertThisInitialized(_this)));
  12154. E(_assertThisInitialized(_this), "effectManager", new XverseEffectManager(_assertThisInitialized(_this)));
  12155. E(_assertThisInitialized(_this), "sceneManager");
  12156. E(_assertThisInitialized(_this), "scene");
  12157. E(_assertThisInitialized(_this), "breathPointManager");
  12158. E(_assertThisInitialized(_this), "_currentState");
  12159. E(_assertThisInitialized(_this), "joined", !1);
  12160. E(_assertThisInitialized(_this), "disableRotate", !1);
  12161. E(_assertThisInitialized(_this), "isPano", !1);
  12162. E(_assertThisInitialized(_this), "movingByClick", !0);
  12163. E(_assertThisInitialized(_this), "camera", new Camera(_assertThisInitialized(_this)));
  12164. E(_assertThisInitialized(_this), "stats", new Stats(_assertThisInitialized(_this)));
  12165. E(_assertThisInitialized(_this), "isUpdatedRawYUVData", !1);
  12166. E(_assertThisInitialized(_this), "actionsHandler", new ActionsHandler(_assertThisInitialized(_this)));
  12167. E(_assertThisInitialized(_this), "_currentClickingState", null);
  12168. E(_assertThisInitialized(_this), "signal", new Signal(_assertThisInitialized(_this)));
  12169. E(_assertThisInitialized(_this), "firstFrameTimestamp");
  12170. E(_assertThisInitialized(_this), "receiveRtcData", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  12171. var e, t, r, n;
  12172. return regenerator.wrap(function _callee$(_context) {
  12173. while (1) {
  12174. switch (_context.prev = _context.next) {
  12175. case 0:
  12176. logger$1.info("Invoke receiveRtcData");
  12177. e = !1, t = !1, r = !1, n = !1;
  12178. return _context.abrupt("return", _this.viewMode === "serverless" ? (logger$1.warn("set view mode to serverless"), _this.setViewMode("observer").then(function () {
  12179. return _assertThisInitialized(_this);
  12180. }, function () {
  12181. return _assertThisInitialized(_this);
  12182. })) : new Promise(function (o) {
  12183. var a = _this.networkController.rtcp.workers;
  12184. a.registerFunction("signal", function (s) {
  12185. _this.signal.handleSignal(s);
  12186. }), a.registerFunction("stream", function (s) {
  12187. var l;
  12188. if (_this.emit("streamTimestamp", {
  12189. timestamp: Date.now()
  12190. }), t || (t = !0, logger$1.info("Invoke stream event")), s.stream) {
  12191. r || (r = !0, logger$1.info("Invoke updateRawYUVData")), _this.isUpdatedRawYUVData = !1;
  12192. var u = (l = _this._currentState.skin) == null ? void 0 : l.fov;
  12193. _this.sceneManager.materialComponent.updateRawYUVData(s.stream, s.width, s.height, u), _this.isUpdatedRawYUVData = !0;
  12194. }
  12195. e || (logger$1.info("Invoke isAfterRenderRegistered"), e = !0, _this.scene.registerAfterRender(function () {
  12196. _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()));
  12197. }));
  12198. }), _this.panorama.bindListener(function () {
  12199. o(_assertThisInitialized(_this)), _this.afterJoinRoom();
  12200. }), a.registerFunction("reconnectedFrame", function () {}), logger$1.info("Invoke decoderWorker.postMessage"), a.decoderWorker.postMessage({
  12201. t: 5
  12202. });
  12203. }));
  12204. case 3:
  12205. case "end":
  12206. return _context.stop();
  12207. }
  12208. }
  12209. }, _callee);
  12210. })));
  12211. E(_assertThisInitialized(_this), "moveToExtra", "");
  12212. _this.options = e, _this.options.wsServerUrl || (_this.options.wsServerUrl = SERVER_URLS.DEV), _this.modelManager = ModelManager.getInstance(e.appId, e.releaseId), _this.updateReporter();
  12213. var n = e;
  12214. n.canvas;
  12215. var r = Oe(n, ["canvas"]);
  12216. logger$1.infoAndReportMeasurement({
  12217. metric: "startJoinRoomAt",
  12218. startTime: Date.now(),
  12219. group: "joinRoom",
  12220. extra: r,
  12221. value: 0
  12222. });
  12223. return _this;
  12224. }
  12225. _createClass(Xverse_Room, [{
  12226. key: "currentNetworkOptions",
  12227. get: function get() {
  12228. return this._currentNetworkOptions;
  12229. }
  12230. }, {
  12231. key: "viewMode",
  12232. get: function get() {
  12233. var e;
  12234. return ((e = this._currentState) == null ? void 0 : e.viewMode) || "full";
  12235. }
  12236. }, {
  12237. key: "id",
  12238. get: function get() {
  12239. return this._id;
  12240. }
  12241. }, {
  12242. key: "skinId",
  12243. get: function get() {
  12244. return this._currentState.skinId;
  12245. }
  12246. }, {
  12247. key: "skin",
  12248. get: function get() {
  12249. return this._currentState.skin;
  12250. }
  12251. }, {
  12252. key: "sessionId",
  12253. get: function get() {
  12254. return this.currentNetworkOptions.sessionId;
  12255. }
  12256. }, {
  12257. key: "pictureQualityLevel",
  12258. get: function get() {
  12259. return this.currentState.pictureQualityLevel;
  12260. }
  12261. }, {
  12262. key: "avatars",
  12263. get: function get() {
  12264. return Array.from(this.avatarManager.avatars.values());
  12265. }
  12266. }, {
  12267. key: "currentState",
  12268. get: function get() {
  12269. var e;
  12270. return le(oe({}, this._currentState), {
  12271. state: (e = this.networkController) == null ? void 0 : e._state
  12272. });
  12273. }
  12274. }, {
  12275. key: "_userAvatar",
  12276. get: function get() {
  12277. var _this2 = this;
  12278. return this.avatars.find(function (e) {
  12279. return e.userId === _this2.userId;
  12280. });
  12281. }
  12282. }, {
  12283. key: "tvs",
  12284. get: function get() {
  12285. return this.engineProxy._tvs;
  12286. }
  12287. }, {
  12288. key: "tv",
  12289. get: function get() {
  12290. return this.tvs[0];
  12291. }
  12292. }, {
  12293. key: "currentClickingState",
  12294. get: function get() {
  12295. return this._currentClickingState;
  12296. }
  12297. }, {
  12298. key: "afterJoinRoomHook",
  12299. value: function afterJoinRoomHook() {}
  12300. }, {
  12301. key: "beforeJoinRoomResolveHook",
  12302. value: function beforeJoinRoomResolveHook() {}
  12303. }, {
  12304. key: "afterReconnectedHook",
  12305. value: function afterReconnectedHook() {}
  12306. }, {
  12307. key: "handleSignalHook",
  12308. value: function handleSignalHook(e) {}
  12309. }, {
  12310. key: "skinChangedHook",
  12311. value: function skinChangedHook() {}
  12312. }, {
  12313. key: "beforeStartGameHook",
  12314. value: function () {
  12315. var _beforeStartGameHook = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  12316. return regenerator.wrap(function _callee2$(_context2) {
  12317. while (1) {
  12318. switch (_context2.prev = _context2.next) {
  12319. case 0:
  12320. case "end":
  12321. return _context2.stop();
  12322. }
  12323. }
  12324. }, _callee2);
  12325. }));
  12326. function beforeStartGameHook(_x) {
  12327. return _beforeStartGameHook.apply(this, arguments);
  12328. }
  12329. return beforeStartGameHook;
  12330. }()
  12331. }, {
  12332. key: "loadAssetsHook",
  12333. value: function loadAssetsHook() {}
  12334. }, {
  12335. key: "afterUserAvatarLoadedHook",
  12336. value: function afterUserAvatarLoadedHook() {}
  12337. }, {
  12338. key: "audienceViewModeHook",
  12339. value: function audienceViewModeHook() {}
  12340. }, {
  12341. key: "setViewModeToObserver",
  12342. value: function setViewModeToObserver() {}
  12343. }, {
  12344. key: "handleVehicleHook",
  12345. value: function handleVehicleHook(e) {}
  12346. }, {
  12347. key: "updateReporter",
  12348. value: function updateReporter() {
  12349. var _this$options = this.options,
  12350. e = _this$options.avatarId,
  12351. t = _this$options.skinId,
  12352. r = _this$options.userId,
  12353. n = _this$options.roomId,
  12354. o = _this$options.role,
  12355. a = _this$options.appId,
  12356. s = _this$options.wsServerUrl;
  12357. reporter$1.updateHeader({
  12358. userId: r
  12359. }), reporter$1.updateBody({
  12360. roomId: n,
  12361. role: o,
  12362. skinId: t,
  12363. avatarId: e,
  12364. appId: a,
  12365. wsServerUrl: s
  12366. });
  12367. }
  12368. }, {
  12369. key: "initRoom",
  12370. value: function () {
  12371. var _initRoom2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  12372. var _this$options$timeout, e;
  12373. return regenerator.wrap(function _callee3$(_context3) {
  12374. while (1) {
  12375. switch (_context3.prev = _context3.next) {
  12376. case 0:
  12377. _this$options$timeout = this.options.timeout, e = _this$options$timeout === void 0 ? DEFAULT_JOINROOM_TIMEOUT : _this$options$timeout;
  12378. if (!util.isSupported()) {
  12379. _context3.next = 5;
  12380. break;
  12381. }
  12382. return _context3.abrupt("return", this._initRoom()._timeout(e, new TimeoutError("initRoom timeout")));
  12383. case 5:
  12384. return _context3.abrupt("return", Promise.reject(new UnsupportedError()));
  12385. case 6:
  12386. case "end":
  12387. return _context3.stop();
  12388. }
  12389. }
  12390. }, _callee3, this);
  12391. }));
  12392. function initRoom() {
  12393. return _initRoom2.apply(this, arguments);
  12394. }
  12395. return initRoom;
  12396. }()
  12397. }, {
  12398. key: "_initRoom",
  12399. value: function () {
  12400. var _initRoom3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  12401. 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;
  12402. return regenerator.wrap(function _callee4$(_context4) {
  12403. while (1) {
  12404. switch (_context4.prev = _context4.next) {
  12405. case 0:
  12406. e = this.validateOptions(this.options);
  12407. if (!e) {
  12408. _context4.next = 3;
  12409. break;
  12410. }
  12411. return _context4.abrupt("return", (logger$1.error("initRoom param error", e), Promise.reject(e)));
  12412. case 3:
  12413. _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;
  12414. this.setCurrentNetworkOptions({
  12415. avatarId: r,
  12416. skinId: n,
  12417. roomId: R,
  12418. userId: o,
  12419. wsServerUrl: a,
  12420. role: s,
  12421. token: l,
  12422. pageSession: u,
  12423. rotationRenderType: c,
  12424. isAllSync: h,
  12425. appId: f,
  12426. camera: d,
  12427. player: _,
  12428. avatarComponents: g,
  12429. nickname: m,
  12430. avatarScale: v,
  12431. firends: y,
  12432. syncByEvent: b,
  12433. areaName: T,
  12434. attitude: C,
  12435. pathName: A,
  12436. person: P,
  12437. roomTypeId: M,
  12438. hasAvatar: x,
  12439. syncToOthers: I,
  12440. prioritySync: w,
  12441. extra: D,
  12442. removeWhenDisconnected: O
  12443. });
  12444. this.userId = o;
  12445. this.canvas = t;
  12446. T && (this.pathManager.currentArea = T);
  12447. this.networkController = new NetworkController(this);
  12448. this.setCurrentState({
  12449. areaName: T,
  12450. pathName: A,
  12451. attitude: C,
  12452. speed: 0,
  12453. viewMode: S,
  12454. state: this.networkController._state,
  12455. skinId: n
  12456. });
  12457. _context4.prev = 10;
  12458. _context4.next = 13;
  12459. return Promise.all([this.initNetwork(), this.initConfig(), this.initWasm()]);
  12460. case 13:
  12461. logger$1.info("network config wasm all ready, start to create game");
  12462. _context4.next = 16;
  12463. return this.requestCreateRoom({
  12464. skinId: n
  12465. });
  12466. case 16:
  12467. F = _context4.sent;
  12468. V = F.routeList.find(function (L) {
  12469. return L.areaName === T;
  12470. });
  12471. N = ((V == null ? void 0 : V.step) || 7.5) * 30;
  12472. this.updateCurrentState({
  12473. skin: F,
  12474. skinId: F.id,
  12475. versionId: F.versionId,
  12476. speed: N
  12477. });
  12478. _context4.next = 22;
  12479. return this.initEngine(F);
  12480. case 22:
  12481. _context4.next = 27;
  12482. break;
  12483. case 24:
  12484. _context4.prev = 24;
  12485. _context4.t0 = _context4["catch"](10);
  12486. return _context4.abrupt("return", Promise.reject(_context4.t0));
  12487. case 27:
  12488. return _context4.abrupt("return", (this.beforeJoinRoomResolve(), this.receiveRtcData()));
  12489. case 28:
  12490. case "end":
  12491. return _context4.stop();
  12492. }
  12493. }
  12494. }, _callee4, this, [[10, 24]]);
  12495. }));
  12496. function _initRoom() {
  12497. return _initRoom3.apply(this, arguments);
  12498. }
  12499. return _initRoom;
  12500. }()
  12501. }, {
  12502. key: "beforeJoinRoomResolve",
  12503. value: function beforeJoinRoomResolve() {
  12504. this.setupStats(), this.eventsController = new EventsController(this), this.eventsController.bindEvents(), this.panorama = new Panorama(this), this.beforeJoinRoomResolveHook();
  12505. }
  12506. }, {
  12507. key: "afterJoinRoom",
  12508. value: function afterJoinRoom() {
  12509. this.joined = !0, this.viewMode === "observer" && this.setViewModeToObserver(), logger$1.infoAndReportMeasurement({
  12510. tag: this.viewMode,
  12511. value: this.firstFrameTimestamp - this._startTime,
  12512. startTime: Date.now(),
  12513. metric: "joinRoom"
  12514. }), this.camera.initialFov = this.sceneManager.cameraComponent.getCameraFov(), this.stats.on("stats", function (_ref2) {
  12515. var e = _ref2.stats;
  12516. reporter$1.report("stats", oe({}, e));
  12517. }), this.debug = new Debug(this), this.afterJoinRoomHook();
  12518. }
  12519. }, {
  12520. key: "afterReconnected",
  12521. value: function afterReconnected() {
  12522. this.avatarManager.clearOtherUsers(), this.afterReconnectedHook();
  12523. }
  12524. }, {
  12525. key: "leave",
  12526. value: function leave() {
  12527. var e, t;
  12528. return logger$1.info("Invoke room.leave"), (e = this.eventsController) == null || e.clearEvents(), (t = this.networkController) == null || t.quit(), this;
  12529. }
  12530. }, {
  12531. key: "validateOptions",
  12532. value: function validateOptions(e) {
  12533. var _ref3 = e || {},
  12534. t = _ref3.canvas,
  12535. r = _ref3.avatarId,
  12536. n = _ref3.skinId,
  12537. o = _ref3.userId,
  12538. a = _ref3.role;
  12539. _ref3.roomId;
  12540. var l = _ref3.token,
  12541. u = _ref3.appId;
  12542. _ref3.avatarComponents;
  12543. var h = [];
  12544. t instanceof HTMLCanvasElement || h.push(new ParamError$1("`canvas` must be instanceof of HTMLCanvasElement"));
  12545. (!o || typeof o != "string") && h.push(new ParamError$1("`userId` must be string"));
  12546. (!l || typeof l != "string") && h.push(new ParamError$1("`token` must be string"));
  12547. (!u || typeof u != "string") && h.push(new ParamError$1("`appId` must be string"));
  12548. a == "audience" || (!r || !n) && h.push(new ParamError$1("`avatarId` and `skinId` is required when create room"));
  12549. return h[0];
  12550. }
  12551. }, {
  12552. key: "initNetwork",
  12553. value: function () {
  12554. var _initNetwork = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  12555. var e;
  12556. return regenerator.wrap(function _callee5$(_context5) {
  12557. while (1) {
  12558. switch (_context5.prev = _context5.next) {
  12559. case 0:
  12560. if (!(this.viewMode === "serverless")) {
  12561. _context5.next = 2;
  12562. break;
  12563. }
  12564. return _context5.abrupt("return", Promise.resolve());
  12565. case 2:
  12566. e = Date.now();
  12567. _context5.prev = 3;
  12568. _context5.next = 6;
  12569. return this.networkController.connect()._timeout(8e3, new InitNetworkTimeoutError());
  12570. case 6:
  12571. logger$1.infoAndReportMeasurement({
  12572. metric: "networkInitAt",
  12573. startTime: this._startTime,
  12574. group: "joinRoom"
  12575. });
  12576. logger$1.infoAndReportMeasurement({
  12577. metric: "networkInitCost",
  12578. startTime: e,
  12579. group: "joinRoom"
  12580. });
  12581. _context5.next = 13;
  12582. break;
  12583. case 10:
  12584. _context5.prev = 10;
  12585. _context5.t0 = _context5["catch"](3);
  12586. throw logger$1.infoAndReportMeasurement({
  12587. metric: "networkInitAt",
  12588. startTime: e,
  12589. group: "joinRoom",
  12590. error: _context5.t0
  12591. }), _context5.t0;
  12592. case 13:
  12593. case "end":
  12594. return _context5.stop();
  12595. }
  12596. }
  12597. }, _callee5, this, [[3, 10]]);
  12598. }));
  12599. function initNetwork() {
  12600. return _initNetwork.apply(this, arguments);
  12601. }
  12602. return initNetwork;
  12603. }()
  12604. }, {
  12605. key: "initConfig",
  12606. value: function () {
  12607. var _initConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  12608. var e;
  12609. return regenerator.wrap(function _callee6$(_context6) {
  12610. while (1) {
  12611. switch (_context6.prev = _context6.next) {
  12612. case 0:
  12613. e = Date.now();
  12614. _context6.prev = 1;
  12615. _context6.next = 4;
  12616. return this.modelManager.getApplicationConfig()._timeout(8e3, new InitConfigTimeoutError());
  12617. case 4:
  12618. logger$1.infoAndReportMeasurement({
  12619. metric: "configInitAt",
  12620. startTime: this._startTime,
  12621. group: "joinRoom"
  12622. });
  12623. logger$1.infoAndReportMeasurement({
  12624. metric: "configInitCost",
  12625. startTime: e,
  12626. group: "joinRoom"
  12627. });
  12628. _context6.next = 11;
  12629. break;
  12630. case 8:
  12631. _context6.prev = 8;
  12632. _context6.t0 = _context6["catch"](1);
  12633. throw logger$1.infoAndReportMeasurement({
  12634. metric: "configInitAt",
  12635. startTime: e,
  12636. group: "joinRoom",
  12637. error: _context6.t0
  12638. }), _context6.t0;
  12639. case 11:
  12640. case "end":
  12641. return _context6.stop();
  12642. }
  12643. }
  12644. }, _callee6, this, [[1, 8]]);
  12645. }));
  12646. function initConfig() {
  12647. return _initConfig.apply(this, arguments);
  12648. }
  12649. return initConfig;
  12650. }()
  12651. }, {
  12652. key: "initEngine",
  12653. value: function () {
  12654. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  12655. var t, n;
  12656. return regenerator.wrap(function _callee7$(_context7) {
  12657. while (1) {
  12658. switch (_context7.prev = _context7.next) {
  12659. case 0:
  12660. t = Date.now();
  12661. _context7.prev = 1;
  12662. this.engineProxy = new EngineProxy(this);
  12663. _context7.next = 5;
  12664. return this.engineProxy.initEngine(e);
  12665. case 5:
  12666. logger$1.infoAndReportMeasurement({
  12667. metric: "webglInitAt",
  12668. startTime: this._startTime,
  12669. group: "joinRoom"
  12670. });
  12671. logger$1.infoAndReportMeasurement({
  12672. metric: "webglInitCost",
  12673. startTime: t,
  12674. group: "joinRoom"
  12675. });
  12676. return _context7.abrupt("return");
  12677. case 10:
  12678. _context7.prev = 10;
  12679. _context7.t0 = _context7["catch"](1);
  12680. n = _context7.t0;
  12681. return _context7.abrupt("return", (_context7.t0.code !== Codes.InitEngineTimeout && (n = new InitEngineError()), logger$1.error(_context7.t0), logger$1.infoAndReportMeasurement({
  12682. metric: "webglInitAt",
  12683. startTime: t,
  12684. group: "joinRoom",
  12685. error: n
  12686. }), Promise.reject(n)));
  12687. case 14:
  12688. case "end":
  12689. return _context7.stop();
  12690. }
  12691. }
  12692. }, _callee7, this, [[1, 10]]);
  12693. }));
  12694. function initEngine(_x2) {
  12695. return _initEngine.apply(this, arguments);
  12696. }
  12697. return initEngine;
  12698. }()
  12699. }, {
  12700. key: "initWasm",
  12701. value: function () {
  12702. var _initWasm = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  12703. var _this3 = this;
  12704. var e;
  12705. return regenerator.wrap(function _callee8$(_context8) {
  12706. while (1) {
  12707. switch (_context8.prev = _context8.next) {
  12708. case 0:
  12709. if (!(this.viewMode === "serverless")) {
  12710. _context8.next = 2;
  12711. break;
  12712. }
  12713. return _context8.abrupt("return", Promise.resolve());
  12714. case 2:
  12715. e = Date.now();
  12716. _context8.prev = 3;
  12717. _context8.next = 6;
  12718. return this.networkController.rtcp.workers.init(this.options.resolution)._timeout(8e3, new InitDecoderTimeoutError());
  12719. case 6:
  12720. this.networkController.rtcp.workers.registerFunction("error", function (t) {
  12721. logger$1.error("decode error", t);
  12722. var r = t.code,
  12723. n = t.message;
  12724. _this3.emit("error", {
  12725. code: r,
  12726. msg: n
  12727. });
  12728. });
  12729. logger$1.infoAndReportMeasurement({
  12730. metric: "wasmInitAt",
  12731. group: "joinRoom",
  12732. startTime: this._startTime
  12733. });
  12734. logger$1.infoAndReportMeasurement({
  12735. metric: "wasmInitCost",
  12736. group: "joinRoom",
  12737. startTime: e
  12738. });
  12739. eventsManager.on("traceId", function (t) {
  12740. _this3.networkController.rtcp.workers.onTraceId(t);
  12741. });
  12742. _context8.next = 15;
  12743. break;
  12744. case 12:
  12745. _context8.prev = 12;
  12746. _context8.t0 = _context8["catch"](3);
  12747. throw logger$1.infoAndReportMeasurement({
  12748. metric: "wasmInitAt",
  12749. group: "joinRoom",
  12750. startTime: e,
  12751. error: _context8.t0
  12752. }), _context8.t0;
  12753. case 15:
  12754. case "end":
  12755. return _context8.stop();
  12756. }
  12757. }
  12758. }, _callee8, this, [[3, 12]]);
  12759. }));
  12760. function initWasm() {
  12761. return _initWasm.apply(this, arguments);
  12762. }
  12763. return initWasm;
  12764. }()
  12765. }, {
  12766. key: "requestCreateRoom",
  12767. value: function () {
  12768. var _requestCreateRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(_ref4) {
  12769. var e, t, r, _ref5, n, o, _yield$this$networkCo, _r, _n, _o, a, s;
  12770. return regenerator.wrap(function _callee9$(_context9) {
  12771. while (1) {
  12772. switch (_context9.prev = _context9.next) {
  12773. case 0:
  12774. e = _ref4.skinId;
  12775. if (!e) {
  12776. _context9.next = 11;
  12777. break;
  12778. }
  12779. _context9.next = 4;
  12780. return this.getSkin(e);
  12781. case 4:
  12782. t = _context9.sent;
  12783. _context9.next = 7;
  12784. return this.modelManager.findRoute(e, this.options.pathName);
  12785. case 7:
  12786. r = _context9.sent;
  12787. this.updateCurrentNetworkOptions({
  12788. areaName: r.areaName,
  12789. attitude: r.attitude,
  12790. versionId: t.versionId
  12791. });
  12792. _ref5 = util.getRandomItem(r.birthPointList) || this.options, n = _ref5.camera, o = _ref5.player;
  12793. this.options.camera || this.updateCurrentNetworkOptions({
  12794. camera: n
  12795. }), this.options.player || this.updateCurrentNetworkOptions({
  12796. player: o
  12797. });
  12798. case 11:
  12799. if (!(this.viewMode === "serverless")) {
  12800. _context9.next = 13;
  12801. break;
  12802. }
  12803. return _context9.abrupt("return", t);
  12804. case 13:
  12805. _context9.prev = 13;
  12806. _context9.next = 16;
  12807. return this.beforeStartGameHook(this.options);
  12808. case 16:
  12809. _context9.next = 18;
  12810. return this.networkController.startGame();
  12811. case 18:
  12812. _yield$this$networkCo = _context9.sent;
  12813. _r = _yield$this$networkCo.room_id;
  12814. _n = _yield$this$networkCo.data;
  12815. _o = _yield$this$networkCo.session_id;
  12816. this._id = _r;
  12817. a = JSON.parse(_n);
  12818. this.isHost = a.IsHost, e = a.SkinID || e;
  12819. _context9.next = 27;
  12820. return this.getSkin(e);
  12821. case 27:
  12822. s = _context9.sent;
  12823. return _context9.abrupt("return", (this.updateCurrentNetworkOptions({
  12824. roomId: _r,
  12825. sessionId: _o
  12826. }), reporter$1.updateBody({
  12827. roomId: _r,
  12828. skinId: e,
  12829. serverSession: _o
  12830. }), s));
  12831. case 31:
  12832. _context9.prev = 31;
  12833. _context9.t0 = _context9["catch"](13);
  12834. throw logger$1.error("Request create room error", _context9.t0), _context9.t0;
  12835. case 34:
  12836. case "end":
  12837. return _context9.stop();
  12838. }
  12839. }
  12840. }, _callee9, this, [[13, 31]]);
  12841. }));
  12842. function requestCreateRoom(_x3) {
  12843. return _requestCreateRoom.apply(this, arguments);
  12844. }
  12845. return requestCreateRoom;
  12846. }()
  12847. }, {
  12848. key: "pause",
  12849. value: function pause() {
  12850. return this.engineProxy.pause();
  12851. }
  12852. }, {
  12853. key: "resume",
  12854. value: function resume() {
  12855. return this.engineProxy.resume();
  12856. }
  12857. }, {
  12858. key: "reconnect",
  12859. value: function reconnect() {
  12860. this.networkController.reconnect();
  12861. }
  12862. }, {
  12863. key: "setViewMode",
  12864. value: function () {
  12865. var _setViewMode = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(e) {
  12866. return regenerator.wrap(function _callee10$(_context10) {
  12867. while (1) {
  12868. switch (_context10.prev = _context10.next) {
  12869. case 0:
  12870. case "end":
  12871. return _context10.stop();
  12872. }
  12873. }
  12874. }, _callee10);
  12875. }));
  12876. function setViewMode(_x4) {
  12877. return _setViewMode.apply(this, arguments);
  12878. }
  12879. return setViewMode;
  12880. }()
  12881. }, {
  12882. key: "handleRepetLogin",
  12883. value: function handleRepetLogin() {
  12884. logger$1.warn("receive " + Codes.RepeatLogin + " for repeat login"), this.emit("repeatLogin"), reporter$1.disable(), this.networkController.quit();
  12885. }
  12886. }, {
  12887. key: "setPictureQualityLevel",
  12888. value: function setPictureQualityLevel(e) {
  12889. var t = {
  12890. high: EImageQuality.high,
  12891. low: EImageQuality.low,
  12892. average: EImageQuality.mid
  12893. };
  12894. return this.updateCurrentState({
  12895. pictureQualityLevel: e
  12896. }), this.sceneManager.setImageQuality(t[e]);
  12897. }
  12898. }, {
  12899. key: "getSkin",
  12900. value: function () {
  12901. var _getSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  12902. var t, n;
  12903. return regenerator.wrap(function _callee11$(_context11) {
  12904. while (1) {
  12905. switch (_context11.prev = _context11.next) {
  12906. case 0:
  12907. t = null;
  12908. _context11.next = 3;
  12909. return this.modelManager.getSkinsList();
  12910. case 3:
  12911. t = (this.skinList = _context11.sent).find(function (n) {
  12912. return n.id === e || n.id === e;
  12913. });
  12914. if (!t) {
  12915. _context11.next = 6;
  12916. break;
  12917. }
  12918. return _context11.abrupt("return", t);
  12919. case 6:
  12920. n = "skin is invalid: skinId: ".concat(e);
  12921. return _context11.abrupt("return", Promise.reject(new ParamError$1(n)));
  12922. case 8:
  12923. case "end":
  12924. return _context11.stop();
  12925. }
  12926. }
  12927. }, _callee11, this);
  12928. }));
  12929. function getSkin(_x5) {
  12930. return _getSkin.apply(this, arguments);
  12931. }
  12932. return getSkin;
  12933. }()
  12934. }, {
  12935. key: "setupStats",
  12936. value: function setupStats() {
  12937. this.stats.assign({
  12938. roomId: this.id,
  12939. userId: this.userId
  12940. }), setInterval(this.engineProxy.updateStats, 1e3);
  12941. }
  12942. }, {
  12943. key: "proxyEvents",
  12944. value: function proxyEvents(e, t) {
  12945. this.emit(e, t);
  12946. }
  12947. }, {
  12948. key: "setCurrentNetworkOptions",
  12949. value: function setCurrentNetworkOptions(e) {
  12950. this._currentNetworkOptions = e;
  12951. }
  12952. }, {
  12953. key: "updateCurrentNetworkOptions",
  12954. value: function updateCurrentNetworkOptions(e) {
  12955. Object.assign(this._currentNetworkOptions, e), Object.assign(this.options, e);
  12956. }
  12957. }, {
  12958. key: "setCurrentState",
  12959. value: function setCurrentState(e) {
  12960. this._currentState = e;
  12961. }
  12962. }, {
  12963. key: "updateCurrentState",
  12964. value: function updateCurrentState(e) {
  12965. e.skinId && (this.lastSkinId = this.currentState.skinId, this.updateCurrentNetworkOptions({
  12966. skinId: e.skinId
  12967. })), e.versionId && this.updateCurrentNetworkOptions({
  12968. versionId: e.versionId
  12969. }), Object.assign(this._currentState, e);
  12970. }
  12971. }]);
  12972. return Xverse_Room;
  12973. }(EventEmitter);
  12974. 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); }; }
  12975. 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; } }
  12976. var XverseRoom = /*#__PURE__*/function (_Xverse_Room) {
  12977. _inherits(XverseRoom, _Xverse_Room);
  12978. var _super = _createSuper(XverseRoom);
  12979. function XverseRoom(e) {
  12980. var _this;
  12981. _classCallCheck(this, XverseRoom);
  12982. _this = _super.call(this, e);
  12983. _this.joyStick = new JoyStick(_assertThisInitialized(_this));
  12984. return _this;
  12985. }
  12986. _createClass(XverseRoom, [{
  12987. key: "afterJoinRoomHook",
  12988. value: function afterJoinRoomHook() {
  12989. this.joyStick.init({});
  12990. }
  12991. }]);
  12992. return XverseRoom;
  12993. }(Xverse_Room);
  12994. var Preload = /*#__PURE__*/function () {
  12995. function Preload(e) {
  12996. _classCallCheck(this, Preload);
  12997. this.config = null;
  12998. this.allKeys = [];
  12999. this.oldResourcesDeleted = !1;
  13000. this.requests = {
  13001. simple: {
  13002. stopped: !0,
  13003. requests: {}
  13004. },
  13005. observer: {
  13006. stopped: !0,
  13007. requests: {}
  13008. },
  13009. full: {
  13010. stopped: !0,
  13011. requests: {}
  13012. }
  13013. };
  13014. this.modelManager = e, this.init(e.appId);
  13015. }
  13016. _createClass(Preload, [{
  13017. key: "init",
  13018. value: function init(e) {
  13019. reporter$1.updateBody({
  13020. appId: e
  13021. });
  13022. }
  13023. }, {
  13024. key: "getConfig",
  13025. value: function () {
  13026. var _getConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  13027. var _yield$this$modelMana, t;
  13028. return regenerator.wrap(function _callee$(_context) {
  13029. while (1) {
  13030. switch (_context.prev = _context.next) {
  13031. case 0:
  13032. if (!this.config) {
  13033. _context.next = 2;
  13034. break;
  13035. }
  13036. return _context.abrupt("return", this.config);
  13037. case 2:
  13038. _context.next = 4;
  13039. return this.modelManager.requestConfig();
  13040. case 4:
  13041. _yield$this$modelMana = _context.sent;
  13042. t = _yield$this$modelMana.preload;
  13043. return _context.abrupt("return", t ? (this.config = t, Promise.resolve(t)) : Promise.reject("no preload config"));
  13044. case 7:
  13045. case "end":
  13046. return _context.stop();
  13047. }
  13048. }
  13049. }, _callee, this);
  13050. }));
  13051. function getConfig(_x) {
  13052. return _getConfig.apply(this, arguments);
  13053. }
  13054. return getConfig;
  13055. }()
  13056. }, {
  13057. key: "getAllKeys",
  13058. value: function () {
  13059. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  13060. var e, t;
  13061. return regenerator.wrap(function _callee2$(_context2) {
  13062. while (1) {
  13063. switch (_context2.prev = _context2.next) {
  13064. case 0:
  13065. if (!this.allKeys.length) {
  13066. _context2.next = 2;
  13067. break;
  13068. }
  13069. return _context2.abrupt("return", this.allKeys);
  13070. case 2:
  13071. _context2.prev = 2;
  13072. _context2.next = 5;
  13073. return modelTable.getAllKeys();
  13074. case 5:
  13075. e = _context2.sent;
  13076. this.allKeys = e;
  13077. return _context2.abrupt("return", e);
  13078. case 10:
  13079. _context2.prev = 10;
  13080. _context2.t0 = _context2["catch"](2);
  13081. t = "preload getAllKeys error";
  13082. return _context2.abrupt("return", (logger$1.error(t), Promise.reject(t)));
  13083. case 14:
  13084. case "end":
  13085. return _context2.stop();
  13086. }
  13087. }
  13088. }, _callee2, this, [[2, 10]]);
  13089. }));
  13090. function getAllKeys() {
  13091. return _getAllKeys.apply(this, arguments);
  13092. }
  13093. return getAllKeys;
  13094. }()
  13095. }, {
  13096. key: "stop",
  13097. value: function stop(e) {
  13098. e === "serverless" && (e = "observer"), this.requests[e].stopped = !0;
  13099. var t = this.requests[e].requests;
  13100. Object.keys(t).forEach(function (r) {
  13101. http1.canceler.removePending(r), delete t[r];
  13102. });
  13103. }
  13104. }, {
  13105. key: "clearPreload",
  13106. value: function clearPreload(e) {
  13107. this.requests[e].stopped = !1, this.allKeys = [];
  13108. }
  13109. }, {
  13110. key: "start",
  13111. value: function () {
  13112. var _start = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e, t, r) {
  13113. var n, o, a, s, l, u, h, f, _s;
  13114. return regenerator.wrap(function _callee3$(_context3) {
  13115. while (1) {
  13116. switch (_context3.prev = _context3.next) {
  13117. case 0:
  13118. n = Date.now(), o = 0;
  13119. _context3.prev = 1;
  13120. if (!(e === "serverless" && (e = "observer"), !this.requests[e])) {
  13121. _context3.next = 4;
  13122. break;
  13123. }
  13124. return _context3.abrupt("return", Promise.reject(new ParamError("invalid stage name: " + e)));
  13125. case 4:
  13126. this.clearPreload(e);
  13127. _context3.next = 7;
  13128. return this.getConfig(e);
  13129. case 7:
  13130. a = _context3.sent;
  13131. _context3.next = 10;
  13132. return this.getAllKeys();
  13133. case 10:
  13134. s = _context3.sent;
  13135. _context3.prev = 11;
  13136. _context3.next = 14;
  13137. return this.deleteOldResources(a.assetUrls.map(function (d) {
  13138. return d.url;
  13139. }), s);
  13140. case 14:
  13141. _context3.next = 19;
  13142. break;
  13143. case 16:
  13144. _context3.prev = 16;
  13145. _context3.t0 = _context3["catch"](11);
  13146. logger$1.error(_context3.t0);
  13147. case 19:
  13148. l = a.baseUrls, u = a.assetUrls;
  13149. _context3.t1 = e;
  13150. _context3.next = _context3.t1 === "simple" ? 23 : _context3.t1 === "observer" ? 25 : _context3.t1 === "full" ? 27 : 29;
  13151. break;
  13152. case 23:
  13153. h = l;
  13154. return _context3.abrupt("break", 30);
  13155. case 25:
  13156. h = u;
  13157. return _context3.abrupt("break", 30);
  13158. case 27:
  13159. h = u;
  13160. return _context3.abrupt("break", 30);
  13161. case 29:
  13162. h = u;
  13163. case 30:
  13164. f = h.filter(function (d) {
  13165. return !s.includes(d.url);
  13166. });
  13167. r && isFunction(r) && (f = f.filter(r));
  13168. o = f.length;
  13169. logger$1.debug("keysNeedToPreload", f);
  13170. f.length || t && t(h.length, h.length);
  13171. n = Date.now();
  13172. _context3.next = 38;
  13173. return this._preload(e, f, t);
  13174. case 38:
  13175. logger$1.infoAndReportMeasurement({
  13176. tag: e,
  13177. startTime: n,
  13178. metric: "assetsPreload",
  13179. extra: {
  13180. total: o
  13181. }
  13182. });
  13183. return _context3.abrupt("return");
  13184. case 42:
  13185. _context3.prev = 42;
  13186. _context3.t2 = _context3["catch"](1);
  13187. _s = _context3.t2;
  13188. return _context3.abrupt("return", ((this.requests[e].stopped || axios.isCancel(_context3.t2)) && (_s = new PreloadCanceledError()), logger$1.infoAndReportMeasurement({
  13189. tag: e,
  13190. startTime: n,
  13191. metric: "assetsPreload",
  13192. extra: {
  13193. total: o
  13194. },
  13195. error: _s,
  13196. reportOptions: {
  13197. immediate: !0
  13198. }
  13199. }), Promise.reject(_s)));
  13200. case 46:
  13201. case "end":
  13202. return _context3.stop();
  13203. }
  13204. }
  13205. }, _callee3, this, [[1, 42], [11, 16]]);
  13206. }));
  13207. function start(_x2, _x3, _x4) {
  13208. return _start.apply(this, arguments);
  13209. }
  13210. return start;
  13211. }()
  13212. }, {
  13213. key: "deleteOldResources",
  13214. value: function deleteOldResources(e, t) {
  13215. if (!this.oldResourcesDeleted) this.oldResourcesDeleted = !0;else return Promise.resolve();
  13216. var r = t.filter(function (n) {
  13217. return !e.includes(n);
  13218. });
  13219. return logger$1.debug("keysNeedToDelete", r), logger$1.warn("keysNeedToDelete", r.length), Promise.all(r.map(function (n) {
  13220. return modelTable.delete(n);
  13221. }));
  13222. }
  13223. }, {
  13224. key: "_preload",
  13225. value: function () {
  13226. var _preload2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t, r) {
  13227. var _this = this;
  13228. var n, o, a;
  13229. return regenerator.wrap(function _callee6$(_context6) {
  13230. while (1) {
  13231. switch (_context6.prev = _context6.next) {
  13232. case 0:
  13233. n = t.length;
  13234. if (n) {
  13235. _context6.next = 3;
  13236. break;
  13237. }
  13238. return _context6.abrupt("return", Promise.resolve());
  13239. case 3:
  13240. o = 0;
  13241. a = window.setInterval(function () {
  13242. r && r(o, n), o >= n && window.clearInterval(a);
  13243. }, 1e3);
  13244. return _context6.abrupt("return", util.mapLimit(t, 10, /*#__PURE__*/function () {
  13245. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(s) {
  13246. var l, u;
  13247. return regenerator.wrap(function _callee5$(_context5) {
  13248. while (1) {
  13249. switch (_context5.prev = _context5.next) {
  13250. case 0:
  13251. l = s.size, u = s.url;
  13252. return _context5.abrupt("return", _this.requests[e].stopped ? Promise.reject(new PreloadCanceledError()) : http1.get({
  13253. url: u,
  13254. timeout: Preload.getTimeoutBySize(l),
  13255. responseType: "blob",
  13256. retry: 2,
  13257. beforeRequest: function beforeRequest() {
  13258. _this.requests[e].requests[u] = !0;
  13259. }
  13260. }).then( /*#__PURE__*/function () {
  13261. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(c) {
  13262. var h, f;
  13263. return regenerator.wrap(function _callee4$(_context4) {
  13264. while (1) {
  13265. switch (_context4.prev = _context4.next) {
  13266. case 0:
  13267. h = c.data;
  13268. if (h instanceof Blob) {
  13269. _context4.next = 3;
  13270. break;
  13271. }
  13272. return _context4.abrupt("return", (logger$1.error("request blob failed, type:", typeof h, u), Promise.reject("request blob failed " + u)));
  13273. case 3:
  13274. _context4.next = 5;
  13275. return blobToDataURI(h);
  13276. case 5:
  13277. f = _context4.sent;
  13278. _context4.prev = 6;
  13279. _context4.next = 9;
  13280. return modelTable.put({
  13281. url: u,
  13282. model: f
  13283. });
  13284. case 9:
  13285. return _context4.abrupt("return");
  13286. case 12:
  13287. _context4.prev = 12;
  13288. _context4.t0 = _context4["catch"](6);
  13289. return _context4.abrupt("return", (logger$1.error("unable to add data to indexedDB", _context4.t0), Promise.reject(new InternalError("preload db error"))));
  13290. case 15:
  13291. case "end":
  13292. return _context4.stop();
  13293. }
  13294. }
  13295. }, _callee4, null, [[6, 12]]);
  13296. }));
  13297. return function (_x9) {
  13298. return _ref2.apply(this, arguments);
  13299. };
  13300. }()).then(function () {
  13301. o++, delete _this.requests[e].requests[u];
  13302. }, function (c) {
  13303. return delete _this.requests[e].requests[u], window.clearInterval(a), Promise.reject(c);
  13304. }));
  13305. case 2:
  13306. case "end":
  13307. return _context5.stop();
  13308. }
  13309. }
  13310. }, _callee5);
  13311. }));
  13312. return function (_x8) {
  13313. return _ref.apply(this, arguments);
  13314. };
  13315. }()));
  13316. case 6:
  13317. case "end":
  13318. return _context6.stop();
  13319. }
  13320. }
  13321. }, _callee6);
  13322. }));
  13323. function _preload(_x5, _x6, _x7) {
  13324. return _preload2.apply(this, arguments);
  13325. }
  13326. return _preload;
  13327. }()
  13328. }], [{
  13329. key: "getTimeoutBySize",
  13330. value: function getTimeoutBySize(e) {
  13331. return e ? e < 500 * 1e3 ? 30 * 1e3 : e < 1e3 * 1e3 ? 60 * 1e3 : 100 * 1e3 : 100 * 1e3;
  13332. }
  13333. }]);
  13334. return Preload;
  13335. }();
  13336. var RenderType$1 = {
  13337. PathVideo: 0,
  13338. RotationVideo: 1,
  13339. RotationImage: 2,
  13340. PanoramaImage: 3,
  13341. CGVideo: 4,
  13342. ClientRotationPano: 5,
  13343. CloudRotationPano: 6
  13344. };
  13345. var Xverse = /*#__PURE__*/function () {
  13346. function Xverse(e) {
  13347. _classCallCheck(this, Xverse);
  13348. e || (e = {});
  13349. var _e = e,
  13350. t = _e.onLog,
  13351. r = _e.env,
  13352. n = _e.appId,
  13353. o = _e.releaseId,
  13354. a = _e.subPackageVersion;
  13355. this.NO_CACHE = !1, this.env = r || "PROD", this.SUB_PACKAGE_VERSION = a, this.debug && logger$1.setLevel(LoggerLevels.Debug);
  13356. var s = this.pageSession = util.uuid();
  13357. reporter$1.updateHeader({
  13358. pageSession: s
  13359. });
  13360. reporter$1.updateReportUrl(REPORT_URL[this.env]);
  13361. a && reporter$1.updateBody({
  13362. sdkVersion: a
  13363. });
  13364. logger$1.infoAndReportMeasurement({
  13365. metric: "sdkInit",
  13366. startTime: Date.now(),
  13367. extra: {
  13368. version: a,
  13369. enviroment: r,
  13370. pageSession: s
  13371. }
  13372. });
  13373. logger$1.debug("debug mode:", this.debug);
  13374. reporter$1.on("report", function (l) {
  13375. t && t(l);
  13376. });
  13377. if (n) {
  13378. this.appId = n, this.releaseId = o;
  13379. var l = ModelManager.getInstance(n, o);
  13380. this.preload = new Preload(l);
  13381. }
  13382. }
  13383. _createClass(Xverse, [{
  13384. key: "isSupported",
  13385. get: function get() {
  13386. return isSupported();
  13387. }
  13388. }, {
  13389. key: "disableLogUpload",
  13390. value: function disableLogUpload() {
  13391. reporter$1.disable(), logger$1.debug("logger upload has been disabled");
  13392. }
  13393. }, {
  13394. key: "getSkinList",
  13395. value: function () {
  13396. var _getSkinList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  13397. return regenerator.wrap(function _callee$(_context) {
  13398. while (1) {
  13399. switch (_context.prev = _context.next) {
  13400. case 0:
  13401. return _context.abrupt("return", []);
  13402. case 1:
  13403. case "end":
  13404. return _context.stop();
  13405. }
  13406. }
  13407. }, _callee);
  13408. }));
  13409. function getSkinList() {
  13410. return _getSkinList.apply(this, arguments);
  13411. }
  13412. return getSkinList;
  13413. }()
  13414. }, {
  13415. key: "getAvatarList",
  13416. value: function () {
  13417. var _getAvatarList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  13418. return regenerator.wrap(function _callee2$(_context2) {
  13419. while (1) {
  13420. switch (_context2.prev = _context2.next) {
  13421. case 0:
  13422. return _context2.abrupt("return", []);
  13423. case 1:
  13424. case "end":
  13425. return _context2.stop();
  13426. }
  13427. }
  13428. }, _callee2);
  13429. }));
  13430. function getAvatarList() {
  13431. return _getAvatarList.apply(this, arguments);
  13432. }
  13433. return getAvatarList;
  13434. }()
  13435. }, {
  13436. key: "getGiftList",
  13437. value: function () {
  13438. var _getGiftList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  13439. return regenerator.wrap(function _callee3$(_context3) {
  13440. while (1) {
  13441. switch (_context3.prev = _context3.next) {
  13442. case 0:
  13443. return _context3.abrupt("return", [{
  13444. id: "hack "
  13445. }]);
  13446. case 1:
  13447. case "end":
  13448. return _context3.stop();
  13449. }
  13450. }
  13451. }, _callee3);
  13452. }));
  13453. function getGiftList() {
  13454. return _getGiftList.apply(this, arguments);
  13455. }
  13456. return getGiftList;
  13457. }()
  13458. }, {
  13459. key: "joinRoom",
  13460. value: function () {
  13461. var _joinRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  13462. var t, r, n, o;
  13463. return regenerator.wrap(function _callee4$(_context4) {
  13464. while (1) {
  13465. switch (_context4.prev = _context4.next) {
  13466. case 0:
  13467. t = e.pathName || "thirdwalk", r = e.rotationRenderType || RenderType$1.RotationVideo, n = e.person || Person$1.Third, o = new XverseRoom(le(oe({}, e), {
  13468. appId: e.appId || this.appId,
  13469. releaseId: e.releaseId || this.releaseId,
  13470. pageSession: this.pageSession,
  13471. isAllSync: !0,
  13472. rotationRenderType: r,
  13473. syncByEvent: !0,
  13474. pathName: t,
  13475. person: n,
  13476. role: e.role || "audience"
  13477. }));
  13478. return _context4.abrupt("return", o.initRoom().then(function () {
  13479. return o;
  13480. }));
  13481. case 2:
  13482. case "end":
  13483. return _context4.stop();
  13484. }
  13485. }
  13486. }, _callee4, this);
  13487. }));
  13488. function joinRoom(_x) {
  13489. return _joinRoom.apply(this, arguments);
  13490. }
  13491. return joinRoom;
  13492. }()
  13493. }]);
  13494. return Xverse;
  13495. }();
  13496. var xverse = new Xverse({
  13497. env: "DEV",
  13498. appId: "10016",
  13499. releaseId: '2203120033_29769e'
  13500. });
  13501. var l = /*#__PURE__*/function () {
  13502. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  13503. var R;
  13504. return regenerator.wrap(function _callee$(_context) {
  13505. while (1) {
  13506. switch (_context.prev = _context.next) {
  13507. case 0:
  13508. _context.prev = 0;
  13509. _context.next = 3;
  13510. return (R = xverse.preload) == null ? void 0 : R.start('full', function (M, x) {
  13511. });
  13512. case 3:
  13513. _context.next = 12;
  13514. break;
  13515. case 5:
  13516. _context.prev = 5;
  13517. _context.t0 = _context["catch"](0);
  13518. if (!(console.error(_context.t0), _context.t0.code === Codes.PreloadCanceled)) {
  13519. _context.next = 10;
  13520. break;
  13521. }
  13522. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88");
  13523. return _context.abrupt("return");
  13524. case 10:
  13525. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5");
  13526. return _context.abrupt("return");
  13527. case 12:
  13528. _context.prev = 12;
  13529. _context.next = 15;
  13530. return xverse.joinRoom({
  13531. canvas: document.getElementById('canvas'),
  13532. skinId: '10092',
  13533. avatarId: 'KGe_Boy',
  13534. roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
  13535. userId: '1f7acca1db9d5',
  13536. wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
  13537. appId: "10016",
  13538. token: " ",
  13539. nickname: '1f7acca1db9d5',
  13540. firends: ["user1"],
  13541. viewMode: "full",
  13542. resolution: {
  13543. width: 1728,
  13544. height: 720
  13545. },
  13546. pathName: 'thirdwalk',
  13547. objectFit: null,
  13548. hasAvatar: !0,
  13549. syncToOthers: !0
  13550. });
  13551. case 15:
  13552. room = _context.sent;
  13553. debugger;
  13554. u();
  13555. c();
  13556. window.room = room;
  13557. e(!1);
  13558. _context.next = 28;
  13559. break;
  13560. case 23:
  13561. _context.prev = 23;
  13562. _context.t1 = _context["catch"](12);
  13563. console.error(_context.t1);
  13564. alert(_context.t1);
  13565. return _context.abrupt("return");
  13566. case 28:
  13567. case "end":
  13568. return _context.stop();
  13569. }
  13570. }
  13571. }, _callee, null, [[0, 5], [12, 23]]);
  13572. }));
  13573. return function l() {
  13574. return _ref.apply(this, arguments);
  13575. };
  13576. }();
  13577. var u = function u() {
  13578. room.on("_coreClick", function (_ref2) {
  13579. var f = _ref2.point;
  13580. room._userAvatar.moveTo({
  13581. point: f
  13582. });
  13583. });
  13584. };
  13585. var c = function c() {
  13586. room.on("repeatLogin", function () {
  13587. toast("\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55", {
  13588. duration: 1e4
  13589. });
  13590. }), room.on("reconnecting", function (_ref3) {
  13591. var f = _ref3.count;
  13592. toast("\u5C1D\u8BD5\u7B2C".concat(f, "\u6B21\u91CD\u8FDE"));
  13593. }), room.on("reconnected", function () {
  13594. toast("\u91CD\u8FDE\u6210\u529F");
  13595. }), room.on("disconnected", function () {
  13596. var f = toast("\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5", {
  13597. duration: 1e5,
  13598. onClick() {
  13599. f.hideToast(), room.reconnect();
  13600. }
  13601. });
  13602. });
  13603. };
  13604. l();
  13605. }));
  13606. //# sourceMappingURL=index.js.map