index.js 326 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990
  1. /**
  2. * Name: Metaverse
  3. * Date: 2022/4/11
  4. * Author: https://www.4dkankan.com
  5. * Copyright © 2022 4DAGE Co., Ltd. All rights reserved.
  6. * Licensed under the GLP license
  7. */
  8. (function (factory) {
  9. typeof define === 'function' && define.amd ? define(factory) :
  10. factory();
  11. })((function () { 'use strict';
  12. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  13. try {
  14. var info = gen[key](arg);
  15. var value = info.value;
  16. } catch (error) {
  17. reject(error);
  18. return;
  19. }
  20. if (info.done) {
  21. resolve(value);
  22. } else {
  23. Promise.resolve(value).then(_next, _throw);
  24. }
  25. }
  26. function _asyncToGenerator(fn) {
  27. return function () {
  28. var self = this,
  29. args = arguments;
  30. return new Promise(function (resolve, reject) {
  31. var gen = fn.apply(self, args);
  32. function _next(value) {
  33. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  34. }
  35. function _throw(err) {
  36. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  37. }
  38. _next(undefined);
  39. });
  40. };
  41. }
  42. function createCommonjsModule(fn) {
  43. var module = { exports: {} };
  44. return fn(module, module.exports), module.exports;
  45. }
  46. /**
  47. * Copyright (c) 2014-present, Facebook, Inc.
  48. *
  49. * This source code is licensed under the MIT license found in the
  50. * LICENSE file in the root directory of this source tree.
  51. */
  52. var runtime_1 = createCommonjsModule(function (module) {
  53. var runtime = (function (exports) {
  54. var Op = Object.prototype;
  55. var hasOwn = Op.hasOwnProperty;
  56. var undefined$1; // More compressible than void 0.
  57. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  58. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  59. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  60. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  61. function define(obj, key, value) {
  62. Object.defineProperty(obj, key, {
  63. value: value,
  64. enumerable: true,
  65. configurable: true,
  66. writable: true
  67. });
  68. return obj[key];
  69. }
  70. try {
  71. // IE 8 has a broken Object.defineProperty that only works on DOM objects.
  72. define({}, "");
  73. } catch (err) {
  74. define = function(obj, key, value) {
  75. return obj[key] = value;
  76. };
  77. }
  78. function wrap(innerFn, outerFn, self, tryLocsList) {
  79. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  80. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  81. var generator = Object.create(protoGenerator.prototype);
  82. var context = new Context(tryLocsList || []);
  83. // The ._invoke method unifies the implementations of the .next,
  84. // .throw, and .return methods.
  85. generator._invoke = makeInvokeMethod(innerFn, self, context);
  86. return generator;
  87. }
  88. exports.wrap = wrap;
  89. // Try/catch helper to minimize deoptimizations. Returns a completion
  90. // record like context.tryEntries[i].completion. This interface could
  91. // have been (and was previously) designed to take a closure to be
  92. // invoked without arguments, but in all the cases we care about we
  93. // already have an existing method we want to call, so there's no need
  94. // to create a new function object. We can even get away with assuming
  95. // the method takes exactly one argument, since that happens to be true
  96. // in every case, so we don't have to touch the arguments object. The
  97. // only additional allocation required is the completion record, which
  98. // has a stable shape and so hopefully should be cheap to allocate.
  99. function tryCatch(fn, obj, arg) {
  100. try {
  101. return { type: "normal", arg: fn.call(obj, arg) };
  102. } catch (err) {
  103. return { type: "throw", arg: err };
  104. }
  105. }
  106. var GenStateSuspendedStart = "suspendedStart";
  107. var GenStateSuspendedYield = "suspendedYield";
  108. var GenStateExecuting = "executing";
  109. var GenStateCompleted = "completed";
  110. // Returning this object from the innerFn has the same effect as
  111. // breaking out of the dispatch switch statement.
  112. var ContinueSentinel = {};
  113. // Dummy constructor functions that we use as the .constructor and
  114. // .constructor.prototype properties for functions that return Generator
  115. // objects. For full spec compliance, you may wish to configure your
  116. // minifier not to mangle the names of these two functions.
  117. function Generator() {}
  118. function GeneratorFunction() {}
  119. function GeneratorFunctionPrototype() {}
  120. // This is a polyfill for %IteratorPrototype% for environments that
  121. // don't natively support it.
  122. var IteratorPrototype = {};
  123. define(IteratorPrototype, iteratorSymbol, function () {
  124. return this;
  125. });
  126. var getProto = Object.getPrototypeOf;
  127. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  128. if (NativeIteratorPrototype &&
  129. NativeIteratorPrototype !== Op &&
  130. hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  131. // This environment has a native %IteratorPrototype%; use it instead
  132. // of the polyfill.
  133. IteratorPrototype = NativeIteratorPrototype;
  134. }
  135. var Gp = GeneratorFunctionPrototype.prototype =
  136. Generator.prototype = Object.create(IteratorPrototype);
  137. GeneratorFunction.prototype = GeneratorFunctionPrototype;
  138. define(Gp, "constructor", GeneratorFunctionPrototype);
  139. define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
  140. GeneratorFunction.displayName = define(
  141. GeneratorFunctionPrototype,
  142. toStringTagSymbol,
  143. "GeneratorFunction"
  144. );
  145. // Helper for defining the .next, .throw, and .return methods of the
  146. // Iterator interface in terms of a single ._invoke method.
  147. function defineIteratorMethods(prototype) {
  148. ["next", "throw", "return"].forEach(function(method) {
  149. define(prototype, method, function(arg) {
  150. return this._invoke(method, arg);
  151. });
  152. });
  153. }
  154. exports.isGeneratorFunction = function(genFun) {
  155. var ctor = typeof genFun === "function" && genFun.constructor;
  156. return ctor
  157. ? ctor === GeneratorFunction ||
  158. // For the native GeneratorFunction constructor, the best we can
  159. // do is to check its .name property.
  160. (ctor.displayName || ctor.name) === "GeneratorFunction"
  161. : false;
  162. };
  163. exports.mark = function(genFun) {
  164. if (Object.setPrototypeOf) {
  165. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  166. } else {
  167. genFun.__proto__ = GeneratorFunctionPrototype;
  168. define(genFun, toStringTagSymbol, "GeneratorFunction");
  169. }
  170. genFun.prototype = Object.create(Gp);
  171. return genFun;
  172. };
  173. // Within the body of any async function, `await x` is transformed to
  174. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  175. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  176. // meant to be awaited.
  177. exports.awrap = function(arg) {
  178. return { __await: arg };
  179. };
  180. function AsyncIterator(generator, PromiseImpl) {
  181. function invoke(method, arg, resolve, reject) {
  182. var record = tryCatch(generator[method], generator, arg);
  183. if (record.type === "throw") {
  184. reject(record.arg);
  185. } else {
  186. var result = record.arg;
  187. var value = result.value;
  188. if (value &&
  189. typeof value === "object" &&
  190. hasOwn.call(value, "__await")) {
  191. return PromiseImpl.resolve(value.__await).then(function(value) {
  192. invoke("next", value, resolve, reject);
  193. }, function(err) {
  194. invoke("throw", err, resolve, reject);
  195. });
  196. }
  197. return PromiseImpl.resolve(value).then(function(unwrapped) {
  198. // When a yielded Promise is resolved, its final value becomes
  199. // the .value of the Promise<{value,done}> result for the
  200. // current iteration.
  201. result.value = unwrapped;
  202. resolve(result);
  203. }, function(error) {
  204. // If a rejected Promise was yielded, throw the rejection back
  205. // into the async generator function so it can be handled there.
  206. return invoke("throw", error, resolve, reject);
  207. });
  208. }
  209. }
  210. var previousPromise;
  211. function enqueue(method, arg) {
  212. function callInvokeWithMethodAndArg() {
  213. return new PromiseImpl(function(resolve, reject) {
  214. invoke(method, arg, resolve, reject);
  215. });
  216. }
  217. return previousPromise =
  218. // If enqueue has been called before, then we want to wait until
  219. // all previous Promises have been resolved before calling invoke,
  220. // so that results are always delivered in the correct order. If
  221. // enqueue has not been called before, then it is important to
  222. // call invoke immediately, without waiting on a callback to fire,
  223. // so that the async generator function has the opportunity to do
  224. // any necessary setup in a predictable way. This predictability
  225. // is why the Promise constructor synchronously invokes its
  226. // executor callback, and why async functions synchronously
  227. // execute code before the first await. Since we implement simple
  228. // async functions in terms of async generators, it is especially
  229. // important to get this right, even though it requires care.
  230. previousPromise ? previousPromise.then(
  231. callInvokeWithMethodAndArg,
  232. // Avoid propagating failures to Promises returned by later
  233. // invocations of the iterator.
  234. callInvokeWithMethodAndArg
  235. ) : callInvokeWithMethodAndArg();
  236. }
  237. // Define the unified helper method that is used to implement .next,
  238. // .throw, and .return (see defineIteratorMethods).
  239. this._invoke = enqueue;
  240. }
  241. defineIteratorMethods(AsyncIterator.prototype);
  242. define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  243. return this;
  244. });
  245. exports.AsyncIterator = AsyncIterator;
  246. // Note that simple async functions are implemented on top of
  247. // AsyncIterator objects; they just return a Promise for the value of
  248. // the final result produced by the iterator.
  249. exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  250. if (PromiseImpl === void 0) PromiseImpl = Promise;
  251. var iter = new AsyncIterator(
  252. wrap(innerFn, outerFn, self, tryLocsList),
  253. PromiseImpl
  254. );
  255. return exports.isGeneratorFunction(outerFn)
  256. ? iter // If outerFn is a generator, return the full iterator.
  257. : iter.next().then(function(result) {
  258. return result.done ? result.value : iter.next();
  259. });
  260. };
  261. function makeInvokeMethod(innerFn, self, context) {
  262. var state = GenStateSuspendedStart;
  263. return function invoke(method, arg) {
  264. if (state === GenStateExecuting) {
  265. throw new Error("Generator is already running");
  266. }
  267. if (state === GenStateCompleted) {
  268. if (method === "throw") {
  269. throw arg;
  270. }
  271. // Be forgiving, per 25.3.3.3.3 of the spec:
  272. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  273. return doneResult();
  274. }
  275. context.method = method;
  276. context.arg = arg;
  277. while (true) {
  278. var delegate = context.delegate;
  279. if (delegate) {
  280. var delegateResult = maybeInvokeDelegate(delegate, context);
  281. if (delegateResult) {
  282. if (delegateResult === ContinueSentinel) continue;
  283. return delegateResult;
  284. }
  285. }
  286. if (context.method === "next") {
  287. // Setting context._sent for legacy support of Babel's
  288. // function.sent implementation.
  289. context.sent = context._sent = context.arg;
  290. } else if (context.method === "throw") {
  291. if (state === GenStateSuspendedStart) {
  292. state = GenStateCompleted;
  293. throw context.arg;
  294. }
  295. context.dispatchException(context.arg);
  296. } else if (context.method === "return") {
  297. context.abrupt("return", context.arg);
  298. }
  299. state = GenStateExecuting;
  300. var record = tryCatch(innerFn, self, context);
  301. if (record.type === "normal") {
  302. // If an exception is thrown from innerFn, we leave state ===
  303. // GenStateExecuting and loop back for another invocation.
  304. state = context.done
  305. ? GenStateCompleted
  306. : GenStateSuspendedYield;
  307. if (record.arg === ContinueSentinel) {
  308. continue;
  309. }
  310. return {
  311. value: record.arg,
  312. done: context.done
  313. };
  314. } else if (record.type === "throw") {
  315. state = GenStateCompleted;
  316. // Dispatch the exception by looping back around to the
  317. // context.dispatchException(context.arg) call above.
  318. context.method = "throw";
  319. context.arg = record.arg;
  320. }
  321. }
  322. };
  323. }
  324. // Call delegate.iterator[context.method](context.arg) and handle the
  325. // result, either by returning a { value, done } result from the
  326. // delegate iterator, or by modifying context.method and context.arg,
  327. // setting context.delegate to null, and returning the ContinueSentinel.
  328. function maybeInvokeDelegate(delegate, context) {
  329. var method = delegate.iterator[context.method];
  330. if (method === undefined$1) {
  331. // A .throw or .return when the delegate iterator has no .throw
  332. // method always terminates the yield* loop.
  333. context.delegate = null;
  334. if (context.method === "throw") {
  335. // Note: ["return"] must be used for ES3 parsing compatibility.
  336. if (delegate.iterator["return"]) {
  337. // If the delegate iterator has a return method, give it a
  338. // chance to clean up.
  339. context.method = "return";
  340. context.arg = undefined$1;
  341. maybeInvokeDelegate(delegate, context);
  342. if (context.method === "throw") {
  343. // If maybeInvokeDelegate(context) changed context.method from
  344. // "return" to "throw", let that override the TypeError below.
  345. return ContinueSentinel;
  346. }
  347. }
  348. context.method = "throw";
  349. context.arg = new TypeError(
  350. "The iterator does not provide a 'throw' method");
  351. }
  352. return ContinueSentinel;
  353. }
  354. var record = tryCatch(method, delegate.iterator, context.arg);
  355. if (record.type === "throw") {
  356. context.method = "throw";
  357. context.arg = record.arg;
  358. context.delegate = null;
  359. return ContinueSentinel;
  360. }
  361. var info = record.arg;
  362. if (! info) {
  363. context.method = "throw";
  364. context.arg = new TypeError("iterator result is not an object");
  365. context.delegate = null;
  366. return ContinueSentinel;
  367. }
  368. if (info.done) {
  369. // Assign the result of the finished delegate to the temporary
  370. // variable specified by delegate.resultName (see delegateYield).
  371. context[delegate.resultName] = info.value;
  372. // Resume execution at the desired location (see delegateYield).
  373. context.next = delegate.nextLoc;
  374. // If context.method was "throw" but the delegate handled the
  375. // exception, let the outer generator proceed normally. If
  376. // context.method was "next", forget context.arg since it has been
  377. // "consumed" by the delegate iterator. If context.method was
  378. // "return", allow the original .return call to continue in the
  379. // outer generator.
  380. if (context.method !== "return") {
  381. context.method = "next";
  382. context.arg = undefined$1;
  383. }
  384. } else {
  385. // Re-yield the result returned by the delegate method.
  386. return info;
  387. }
  388. // The delegate iterator is finished, so forget it and continue with
  389. // the outer generator.
  390. context.delegate = null;
  391. return ContinueSentinel;
  392. }
  393. // Define Generator.prototype.{next,throw,return} in terms of the
  394. // unified ._invoke helper method.
  395. defineIteratorMethods(Gp);
  396. define(Gp, toStringTagSymbol, "Generator");
  397. // A Generator should always return itself as the iterator object when the
  398. // @@iterator function is called on it. Some browsers' implementations of the
  399. // iterator prototype chain incorrectly implement this, causing the Generator
  400. // object to not be returned from this call. This ensures that doesn't happen.
  401. // See https://github.com/facebook/regenerator/issues/274 for more details.
  402. define(Gp, iteratorSymbol, function() {
  403. return this;
  404. });
  405. define(Gp, "toString", function() {
  406. return "[object Generator]";
  407. });
  408. function pushTryEntry(locs) {
  409. var entry = { tryLoc: locs[0] };
  410. if (1 in locs) {
  411. entry.catchLoc = locs[1];
  412. }
  413. if (2 in locs) {
  414. entry.finallyLoc = locs[2];
  415. entry.afterLoc = locs[3];
  416. }
  417. this.tryEntries.push(entry);
  418. }
  419. function resetTryEntry(entry) {
  420. var record = entry.completion || {};
  421. record.type = "normal";
  422. delete record.arg;
  423. entry.completion = record;
  424. }
  425. function Context(tryLocsList) {
  426. // The root entry object (effectively a try statement without a catch
  427. // or a finally block) gives us a place to store values thrown from
  428. // locations where there is no enclosing try statement.
  429. this.tryEntries = [{ tryLoc: "root" }];
  430. tryLocsList.forEach(pushTryEntry, this);
  431. this.reset(true);
  432. }
  433. exports.keys = function(object) {
  434. var keys = [];
  435. for (var key in object) {
  436. keys.push(key);
  437. }
  438. keys.reverse();
  439. // Rather than returning an object with a next method, we keep
  440. // things simple and return the next function itself.
  441. return function next() {
  442. while (keys.length) {
  443. var key = keys.pop();
  444. if (key in object) {
  445. next.value = key;
  446. next.done = false;
  447. return next;
  448. }
  449. }
  450. // To avoid creating an additional object, we just hang the .value
  451. // and .done properties off the next function object itself. This
  452. // also ensures that the minifier will not anonymize the function.
  453. next.done = true;
  454. return next;
  455. };
  456. };
  457. function values(iterable) {
  458. if (iterable) {
  459. var iteratorMethod = iterable[iteratorSymbol];
  460. if (iteratorMethod) {
  461. return iteratorMethod.call(iterable);
  462. }
  463. if (typeof iterable.next === "function") {
  464. return iterable;
  465. }
  466. if (!isNaN(iterable.length)) {
  467. var i = -1, next = function next() {
  468. while (++i < iterable.length) {
  469. if (hasOwn.call(iterable, i)) {
  470. next.value = iterable[i];
  471. next.done = false;
  472. return next;
  473. }
  474. }
  475. next.value = undefined$1;
  476. next.done = true;
  477. return next;
  478. };
  479. return next.next = next;
  480. }
  481. }
  482. // Return an iterator with no values.
  483. return { next: doneResult };
  484. }
  485. exports.values = values;
  486. function doneResult() {
  487. return { value: undefined$1, done: true };
  488. }
  489. Context.prototype = {
  490. constructor: Context,
  491. reset: function(skipTempReset) {
  492. this.prev = 0;
  493. this.next = 0;
  494. // Resetting context._sent for legacy support of Babel's
  495. // function.sent implementation.
  496. this.sent = this._sent = undefined$1;
  497. this.done = false;
  498. this.delegate = null;
  499. this.method = "next";
  500. this.arg = undefined$1;
  501. this.tryEntries.forEach(resetTryEntry);
  502. if (!skipTempReset) {
  503. for (var name in this) {
  504. // Not sure about the optimal order of these conditions:
  505. if (name.charAt(0) === "t" &&
  506. hasOwn.call(this, name) &&
  507. !isNaN(+name.slice(1))) {
  508. this[name] = undefined$1;
  509. }
  510. }
  511. }
  512. },
  513. stop: function() {
  514. this.done = true;
  515. var rootEntry = this.tryEntries[0];
  516. var rootRecord = rootEntry.completion;
  517. if (rootRecord.type === "throw") {
  518. throw rootRecord.arg;
  519. }
  520. return this.rval;
  521. },
  522. dispatchException: function(exception) {
  523. if (this.done) {
  524. throw exception;
  525. }
  526. var context = this;
  527. function handle(loc, caught) {
  528. record.type = "throw";
  529. record.arg = exception;
  530. context.next = loc;
  531. if (caught) {
  532. // If the dispatched exception was caught by a catch block,
  533. // then let that catch block handle the exception normally.
  534. context.method = "next";
  535. context.arg = undefined$1;
  536. }
  537. return !! caught;
  538. }
  539. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  540. var entry = this.tryEntries[i];
  541. var record = entry.completion;
  542. if (entry.tryLoc === "root") {
  543. // Exception thrown outside of any try block that could handle
  544. // it, so set the completion value of the entire function to
  545. // throw the exception.
  546. return handle("end");
  547. }
  548. if (entry.tryLoc <= this.prev) {
  549. var hasCatch = hasOwn.call(entry, "catchLoc");
  550. var hasFinally = hasOwn.call(entry, "finallyLoc");
  551. if (hasCatch && hasFinally) {
  552. if (this.prev < entry.catchLoc) {
  553. return handle(entry.catchLoc, true);
  554. } else if (this.prev < entry.finallyLoc) {
  555. return handle(entry.finallyLoc);
  556. }
  557. } else if (hasCatch) {
  558. if (this.prev < entry.catchLoc) {
  559. return handle(entry.catchLoc, true);
  560. }
  561. } else if (hasFinally) {
  562. if (this.prev < entry.finallyLoc) {
  563. return handle(entry.finallyLoc);
  564. }
  565. } else {
  566. throw new Error("try statement without catch or finally");
  567. }
  568. }
  569. }
  570. },
  571. abrupt: function(type, arg) {
  572. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  573. var entry = this.tryEntries[i];
  574. if (entry.tryLoc <= this.prev &&
  575. hasOwn.call(entry, "finallyLoc") &&
  576. this.prev < entry.finallyLoc) {
  577. var finallyEntry = entry;
  578. break;
  579. }
  580. }
  581. if (finallyEntry &&
  582. (type === "break" ||
  583. type === "continue") &&
  584. finallyEntry.tryLoc <= arg &&
  585. arg <= finallyEntry.finallyLoc) {
  586. // Ignore the finally entry if control is not jumping to a
  587. // location outside the try/catch block.
  588. finallyEntry = null;
  589. }
  590. var record = finallyEntry ? finallyEntry.completion : {};
  591. record.type = type;
  592. record.arg = arg;
  593. if (finallyEntry) {
  594. this.method = "next";
  595. this.next = finallyEntry.finallyLoc;
  596. return ContinueSentinel;
  597. }
  598. return this.complete(record);
  599. },
  600. complete: function(record, afterLoc) {
  601. if (record.type === "throw") {
  602. throw record.arg;
  603. }
  604. if (record.type === "break" ||
  605. record.type === "continue") {
  606. this.next = record.arg;
  607. } else if (record.type === "return") {
  608. this.rval = this.arg = record.arg;
  609. this.method = "return";
  610. this.next = "end";
  611. } else if (record.type === "normal" && afterLoc) {
  612. this.next = afterLoc;
  613. }
  614. return ContinueSentinel;
  615. },
  616. finish: function(finallyLoc) {
  617. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  618. var entry = this.tryEntries[i];
  619. if (entry.finallyLoc === finallyLoc) {
  620. this.complete(entry.completion, entry.afterLoc);
  621. resetTryEntry(entry);
  622. return ContinueSentinel;
  623. }
  624. }
  625. },
  626. "catch": function(tryLoc) {
  627. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  628. var entry = this.tryEntries[i];
  629. if (entry.tryLoc === tryLoc) {
  630. var record = entry.completion;
  631. if (record.type === "throw") {
  632. var thrown = record.arg;
  633. resetTryEntry(entry);
  634. }
  635. return thrown;
  636. }
  637. }
  638. // The context.catch method must only be called with a location
  639. // argument that corresponds to a known catch block.
  640. throw new Error("illegal catch attempt");
  641. },
  642. delegateYield: function(iterable, resultName, nextLoc) {
  643. this.delegate = {
  644. iterator: values(iterable),
  645. resultName: resultName,
  646. nextLoc: nextLoc
  647. };
  648. if (this.method === "next") {
  649. // Deliberately forget the last sent value so that we don't
  650. // accidentally pass it on to the delegate.
  651. this.arg = undefined$1;
  652. }
  653. return ContinueSentinel;
  654. }
  655. };
  656. // Regardless of whether this script is executing as a CommonJS module
  657. // or not, return the runtime object so that we can declare the variable
  658. // regeneratorRuntime in the outer scope, which allows this module to be
  659. // injected easily by `bin/regenerator --include-runtime script.js`.
  660. return exports;
  661. }(
  662. // If this script is executing as a CommonJS module, use module.exports
  663. // as the regeneratorRuntime namespace. Otherwise create a new empty
  664. // object. Either way, the resulting object will be used to initialize
  665. // the regeneratorRuntime variable at the top of this file.
  666. module.exports
  667. ));
  668. try {
  669. regeneratorRuntime = runtime;
  670. } catch (accidentalStrictMode) {
  671. // This module should not be running in strict mode, so the above
  672. // assignment should always work unless something is misconfigured. Just
  673. // in case runtime.js accidentally runs in strict mode, in modern engines
  674. // we can explicitly access globalThis. In older engines we can escape
  675. // strict mode using a global Function call. This could conceivably fail
  676. // if a Content Security Policy forbids using Function, but in that case
  677. // the proper solution is to fix the accidental strict mode problem. If
  678. // you've misconfigured your bundler to force strict mode and applied a
  679. // CSP to forbid Function, and you're not willing to fix either of those
  680. // problems, please detail your unique predicament in a GitHub issue.
  681. if (typeof globalThis === "object") {
  682. globalThis.regeneratorRuntime = runtime;
  683. } else {
  684. Function("r", "regeneratorRuntime = r")(runtime);
  685. }
  686. }
  687. });
  688. var regenerator = runtime_1;
  689. function _classCallCheck(instance, Constructor) {
  690. if (!(instance instanceof Constructor)) {
  691. throw new TypeError("Cannot call a class as a function");
  692. }
  693. }
  694. function _defineProperties(target, props) {
  695. for (var i = 0; i < props.length; i++) {
  696. var descriptor = props[i];
  697. descriptor.enumerable = descriptor.enumerable || false;
  698. descriptor.configurable = true;
  699. if ("value" in descriptor) descriptor.writable = true;
  700. Object.defineProperty(target, descriptor.key, descriptor);
  701. }
  702. }
  703. function _createClass(Constructor, protoProps, staticProps) {
  704. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  705. if (staticProps) _defineProperties(Constructor, staticProps);
  706. Object.defineProperty(Constructor, "prototype", {
  707. writable: false
  708. });
  709. return Constructor;
  710. }
  711. var util = {
  712. uuid() {
  713. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (i) {
  714. var e = Math.random() * 16 | 0;
  715. return (i === "x" ? e : e & 3 | 8).toString(16);
  716. });
  717. },
  718. getFormattedDate(i) {
  719. var e = i.getMonth() + 1,
  720. t = i.getDate(),
  721. r = i.getHours(),
  722. n = i.getMinutes(),
  723. o = i.getSeconds(),
  724. a = i.getMilliseconds(),
  725. s = (e < 10 ? "0" : "") + e,
  726. l = (t < 10 ? "0" : "") + t,
  727. u = (r < 10 ? "0" : "") + r,
  728. c = (n < 10 ? "0" : "") + n,
  729. h = (o < 10 ? "0" : "") + o;
  730. return i.getFullYear() + "-" + s + "-" + l + " " + u + ":" + c + ":" + h + "." + a;
  731. },
  732. createInstance(i) {
  733. var e = new Axios(i),
  734. t = bind(Axios.prototype.request, e);
  735. return utils.extend(t, Axios.prototype, e), utils.extend(t, e), t.create = function (n) {
  736. return createInstance(mergeConfig(i, n));
  737. }, t;
  738. },
  739. mapLimit(i, e, t) {
  740. return new Promise(function (r, n) {
  741. var o = i.length;
  742. var a = e - 1,
  743. s = 0;
  744. var l = function l(u) {
  745. u.forEach(function (c) {
  746. t(c).then(function () {
  747. if (s++, s === o) {
  748. r();
  749. return;
  750. }
  751. a++;
  752. var h = i[a];
  753. h && l([h]);
  754. }, function (h) {
  755. n(h);
  756. });
  757. });
  758. };
  759. l(i.slice(0, e));
  760. });
  761. },
  762. isWebAssemblySupported() {
  763. try {
  764. if (typeof WebAssembly == "object" && typeof WebAssembly.instantiate == "function") {
  765. var i = new WebAssembly.Module(Uint8Array.of(0, 97, 115, 109, 1, 0, 0, 0));
  766. if (i instanceof WebAssembly.Module) return new WebAssembly.Instance(i) instanceof WebAssembly.Instance;
  767. }
  768. } catch (_unused) {}
  769. return console.log("wasm is not supported"), !1;
  770. },
  771. isSupported() {
  772. return typeof RTCPeerConnection == "function" && this.isWebAssemblySupported();
  773. }
  774. };
  775. function _setPrototypeOf(o, p) {
  776. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  777. o.__proto__ = p;
  778. return o;
  779. };
  780. return _setPrototypeOf(o, p);
  781. }
  782. function _inherits(subClass, superClass) {
  783. if (typeof superClass !== "function" && superClass !== null) {
  784. throw new TypeError("Super expression must either be null or a function");
  785. }
  786. subClass.prototype = Object.create(superClass && superClass.prototype, {
  787. constructor: {
  788. value: subClass,
  789. writable: true,
  790. configurable: true
  791. }
  792. });
  793. Object.defineProperty(subClass, "prototype", {
  794. writable: false
  795. });
  796. if (superClass) _setPrototypeOf(subClass, superClass);
  797. }
  798. function _typeof(obj) {
  799. "@babel/helpers - typeof";
  800. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  801. return typeof obj;
  802. } : function (obj) {
  803. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  804. }, _typeof(obj);
  805. }
  806. function _assertThisInitialized(self) {
  807. if (self === void 0) {
  808. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  809. }
  810. return self;
  811. }
  812. function _possibleConstructorReturn(self, call) {
  813. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  814. return call;
  815. } else if (call !== void 0) {
  816. throw new TypeError("Derived constructors may only return object or undefined");
  817. }
  818. return _assertThisInitialized(self);
  819. }
  820. function _getPrototypeOf(o) {
  821. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  822. return o.__proto__ || Object.getPrototypeOf(o);
  823. };
  824. return _getPrototypeOf(o);
  825. }
  826. function _createSuper$f(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); }; }
  827. 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; } }
  828. var Reporter = /*#__PURE__*/function (_EventEmitter) {
  829. _inherits(Reporter, _EventEmitter);
  830. var _super = _createSuper$f(Reporter);
  831. function Reporter() {
  832. var _this;
  833. _classCallCheck(this, Reporter);
  834. _this = _super.call(this);
  835. _this._header = {};
  836. _this._body = {};
  837. _this._queue = [];
  838. _this._disabled = !1;
  839. _this._interval = null;
  840. _this._reportUrl = null;
  841. _this.isDocumentLoaded = function () {
  842. return document.readyState === "complete";
  843. };
  844. _this._header.logModuleId = REPORT_MODULE_TYPE, _this._header.url = location.href, _this._header.enviroment = ENV, _this._header.networkType = window.navigator.connection ? window.navigator.connection.type : "unknown", _this._interval = window.setInterval(function () {
  845. _this._flushReport();
  846. }, 10 * 1e3);
  847. return _this;
  848. }
  849. _createClass(Reporter, [{
  850. key: "disable",
  851. value: function disable() {
  852. this._disabled = !0, this._interval && window.clearInterval(this._interval);
  853. }
  854. }, {
  855. key: "updateHeader",
  856. value: function updateHeader(e) {
  857. Object.assign(this._header, e);
  858. }
  859. }, {
  860. key: "updateBody",
  861. value: function updateBody(e) {
  862. Object.assign(this._body, e);
  863. }
  864. }, {
  865. key: "updateReportUrl",
  866. value: function updateReportUrl(e) {
  867. this._reportUrl = e;
  868. }
  869. }, {
  870. key: "report",
  871. value: function report(e, t, r) {
  872. var _this2 = this;
  873. if (this._disabled) return;
  874. r || (r = {});
  875. var _r = r,
  876. n = _r.immediate,
  877. o = _r.sampleRate;
  878. if (o && o > Math.random()) return;
  879. this.updateBody({
  880. logTime: util.getFormattedDate(new Date()),
  881. logTimestamp: Date.now()
  882. });
  883. var a = function a(s) {
  884. var l = oe(le(oe({}, _this2._body), {
  885. type: e
  886. }), s);
  887. _this2._queue.push(l), e === "measurement" && _this2.emit("report", s);
  888. };
  889. Array.isArray(t) ? t.forEach(function (s) {
  890. return a(s);
  891. }) : a(t), (n || this._queue.length >= REPORT_NUM_PER_REQUEST) && this._flushReport();
  892. }
  893. }, {
  894. key: "_flushReport",
  895. value: function _flushReport() {
  896. if (this._disabled || !this._queue.length || !this.isDocumentLoaded()) return;
  897. var e = {
  898. header: this._header,
  899. body: this._queue.splice(0, REPORT_NUM_PER_REQUEST)
  900. };
  901. this._post(e);
  902. }
  903. }, {
  904. key: "_post",
  905. value: function _post(e) {
  906. var t = this._reportUrl || REPORT_URL.DEV;
  907. return new Promise(function (r, n) {
  908. var o = new XMLHttpRequest();
  909. o.open("POST", t), o.setRequestHeader("Content-Type", "application/json");
  910. try {
  911. o.send(JSON.stringify(e));
  912. } catch (a) {
  913. console.error(a);
  914. }
  915. o.addEventListener("readystatechange", function () {
  916. if (o.readyState == 4) return o.status == 200 ? r(o) : n("Unable to send log");
  917. });
  918. });
  919. }
  920. }]);
  921. return Reporter;
  922. }(EventEmitter);
  923. var reporter$1 = new Reporter();
  924. function _arrayLikeToArray$1(arr, len) {
  925. if (len == null || len > arr.length) len = arr.length;
  926. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  927. arr2[i] = arr[i];
  928. }
  929. return arr2;
  930. }
  931. function _arrayWithoutHoles(arr) {
  932. if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
  933. }
  934. function _iterableToArray(iter) {
  935. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  936. }
  937. function _unsupportedIterableToArray$1(o, minLen) {
  938. if (!o) return;
  939. if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
  940. var n = Object.prototype.toString.call(o).slice(8, -1);
  941. if (n === "Object" && o.constructor) n = o.constructor.name;
  942. if (n === "Map" || n === "Set") return Array.from(o);
  943. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
  944. }
  945. function _nonIterableSpread() {
  946. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  947. }
  948. function _toConsumableArray(arr) {
  949. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread();
  950. }
  951. var Codes = {
  952. Success: 0,
  953. Param: 1001,
  954. Internal: 1002,
  955. Timeout: 1003,
  956. Authentication: 1004,
  957. TokenExpired: 1005,
  958. Unsupported: 1006,
  959. InitNetworkTimeout: 1007,
  960. InitDecoderTimeout: 1008,
  961. InitConfigTimeout: 1009,
  962. InitEngineTimeout: 1010,
  963. InitEngine: 1011,
  964. ActionBlocked: 1012,
  965. PreloadCanceled: 1013,
  966. FrequencyLimit: 1014,
  967. UsersUpperLimit: 2e3,
  968. RoomsUpperLimit: 2001,
  969. ServerParam: 2002,
  970. LackOfToken: 2003,
  971. LoginFailed: 2004,
  972. VerifyServiceDown: 2005,
  973. CreateSessionFailed: 2006,
  974. RtcConnection: 2008,
  975. DoActionFailed: 2009,
  976. StateSyncFailed: 2010,
  977. BroadcastFailed: 2011,
  978. DataAbnormal: 2012,
  979. GetOnVehicle: 2015,
  980. RepeatLogin: 2017,
  981. RoomDoseNotExist: 2018,
  982. TicketExpire: 2019,
  983. ServerRateLimit: 2020,
  984. DoActionBlocked: 2333,
  985. ActionMaybeDelay: 2334,
  986. ActionResponseTimeout: 2999
  987. };
  988. var Logger$1 = /*#__PURE__*/function () {
  989. function Logger(e) {
  990. _classCallCheck(this, Logger);
  991. this.level = 3;
  992. this.module = e;
  993. }
  994. _createClass(Logger, [{
  995. key: "setLevel",
  996. value: function setLevel(e) {
  997. this.level = e;
  998. }
  999. }, {
  1000. key: "atleast",
  1001. value: function atleast(e) {
  1002. return e >= this.level && e >= this.level;
  1003. }
  1004. }, {
  1005. key: "print",
  1006. value: function print(e, t) {
  1007. for (var _len = arguments.length, r = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  1008. r[_key - 2] = arguments[_key];
  1009. }
  1010. if (this.atleast(t)) {
  1011. var _console$n;
  1012. var n = e == "debug" ? "info" : e,
  1013. o = this.prefix(e);
  1014. (_console$n = console[n]).call.apply(_console$n, [null, o].concat(r));
  1015. }
  1016. if (e !== "debug" && e !== "info") {
  1017. var _n = r.map(function (o) {
  1018. if (o instanceof Object) try {
  1019. return JSON.stringify(o);
  1020. } catch (_unused) {
  1021. return o;
  1022. } else return o;
  1023. }).join(",");
  1024. reporter$1.report("log", {
  1025. message: _n,
  1026. level: e,
  1027. module: this.module
  1028. });
  1029. }
  1030. }
  1031. }, {
  1032. key: "debug",
  1033. value: function debug() {
  1034. for (var _len2 = arguments.length, e = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  1035. e[_key2] = arguments[_key2];
  1036. }
  1037. return this.print.apply(this, ["debug", 1].concat(e));
  1038. }
  1039. }, {
  1040. key: "info",
  1041. value: function info() {
  1042. for (var _len3 = arguments.length, e = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  1043. e[_key3] = arguments[_key3];
  1044. }
  1045. return this.print.apply(this, ["info", 2].concat(e));
  1046. }
  1047. }, {
  1048. key: "infoAndReportLog",
  1049. value: function infoAndReportLog(e) {
  1050. for (var _len4 = arguments.length, t = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
  1051. t[_key4 - 1] = arguments[_key4];
  1052. }
  1053. var r = e.reportOptions;
  1054. delete e.reportOptions, reporter$1.report("log", e, r), t.length || (t = [e.message]), this.debug.apply(this, _toConsumableArray(t));
  1055. }
  1056. }, {
  1057. key: "infoAndReportMeasurement",
  1058. value: function infoAndReportMeasurement(e) {
  1059. for (var _len5 = arguments.length, t = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
  1060. t[_key5 - 1] = arguments[_key5];
  1061. }
  1062. var n;
  1063. var r = e.reportOptions;
  1064. if (e.startTime) {
  1065. var o = Date.now();
  1066. e.value === void 0 && (e.endTime = o), e.value === void 0 && (e.value = o - e.startTime);
  1067. }
  1068. if (e.error ? e.code = ((n = e.error) == null ? void 0 : n.code) || Codes.Internal : e.code = Codes.Success, reporter$1.report("measurement", e, r), t.length || (t = [e]), e.level === 4 || e.error) {
  1069. this.error.apply(this, _toConsumableArray(t));
  1070. return;
  1071. }
  1072. this.warn.apply(this, _toConsumableArray(t));
  1073. }
  1074. }, {
  1075. key: "warn",
  1076. value: function warn() {
  1077. for (var _len6 = arguments.length, e = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  1078. e[_key6] = arguments[_key6];
  1079. }
  1080. return this.print.apply(this, ["warn", 3].concat(e));
  1081. }
  1082. }, {
  1083. key: "error",
  1084. value: function error() {
  1085. for (var _len7 = arguments.length, e = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
  1086. e[_key7] = arguments[_key7];
  1087. }
  1088. return this.print.apply(this, ["error", 4].concat(e));
  1089. }
  1090. }, {
  1091. key: "prefix",
  1092. value: function prefix(e) {
  1093. return "[".concat(this.module, "][").concat(e, "] ").concat(util.getFormattedDate(new Date()), ":");
  1094. }
  1095. }], [{
  1096. key: "setLevel",
  1097. value: function setLevel(e) {
  1098. this.level = e;
  1099. }
  1100. }]);
  1101. return Logger;
  1102. }();
  1103. var logger = new Logger$1();
  1104. var AxiosCanceler = /*#__PURE__*/function () {
  1105. function AxiosCanceler() {
  1106. _classCallCheck(this, AxiosCanceler);
  1107. this.pendingMap = new Map();
  1108. }
  1109. _createClass(AxiosCanceler, [{
  1110. key: "addPending",
  1111. value: function addPending(e) {
  1112. var _this = this;
  1113. return new axios.CancelToken(function (t) {
  1114. _this.pendingMap.has(e) || _this.pendingMap.set(e, t);
  1115. });
  1116. }
  1117. }, {
  1118. key: "removeAllPending",
  1119. value: function removeAllPending() {
  1120. this.pendingMap.forEach(function (e) {
  1121. e && isFunction(e) && e();
  1122. }), this.pendingMap.clear();
  1123. }
  1124. }, {
  1125. key: "removePending",
  1126. value: function removePending(e) {
  1127. if (this.pendingMap.has(e)) {
  1128. var t = this.pendingMap.get(e);
  1129. t && t(e), this.pendingMap.delete(e);
  1130. }
  1131. }
  1132. }, {
  1133. key: "removeCancelToken",
  1134. value: function removeCancelToken(e) {
  1135. this.pendingMap.has(e) && this.pendingMap.delete(e);
  1136. }
  1137. }, {
  1138. key: "reset",
  1139. value: function reset() {
  1140. this.pendingMap = new Map();
  1141. }
  1142. }]);
  1143. return AxiosCanceler;
  1144. }();
  1145. function _createSuper$e(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); }; }
  1146. 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; } }
  1147. var Http1 = /*#__PURE__*/function (_EventEmitter) {
  1148. _inherits(Http1, _EventEmitter);
  1149. var _super = _createSuper$e(Http1);
  1150. function Http1() {
  1151. var _this;
  1152. _classCallCheck(this, Http1);
  1153. _this = _super.call(this);
  1154. _this.instatnce = axios.create(), _this.canceler = new AxiosCanceler();
  1155. return _this;
  1156. }
  1157. _createClass(Http1, [{
  1158. key: "requestConstant",
  1159. value: function requestConstant() {
  1160. return {
  1161. x_nounce: this.randomString(),
  1162. x_timestamp: new Date().getTime(),
  1163. x_os: "web"
  1164. };
  1165. }
  1166. }, {
  1167. key: "requestParams",
  1168. value: function requestParams(e) {
  1169. return oe({}, e.params);
  1170. }
  1171. }, {
  1172. key: "get",
  1173. value: function get(e) {
  1174. return this.request(le(oe({}, e), {
  1175. method: "GET"
  1176. }));
  1177. }
  1178. }, {
  1179. key: "post",
  1180. value: function post(e) {
  1181. return this.request(le(oe({}, e), {
  1182. method: "POST"
  1183. }));
  1184. }
  1185. }, {
  1186. key: "request",
  1187. value: function request(e) {
  1188. var _this2 = this;
  1189. var t = e.url,
  1190. _e$timeout = e.timeout,
  1191. r = _e$timeout === void 0 ? 1e4 : _e$timeout,
  1192. n = e.method,
  1193. o = e.key,
  1194. a = e.beforeRequest,
  1195. s = e.responseType,
  1196. l = e.data;
  1197. var _e$retry = e.retry,
  1198. u = _e$retry === void 0 ? 0 : _e$retry;
  1199. var c = this.patchUrl(t),
  1200. h = this.canceler.addPending(t);
  1201. a && isFunction(a) && a(e);
  1202. var f = this.requestParams(e);
  1203. var d = {
  1204. url: c,
  1205. method: n,
  1206. timeout: r,
  1207. cancelToken: h,
  1208. responseType: s,
  1209. params: f
  1210. };
  1211. n === "POST" && (d = oe({
  1212. data: l
  1213. }, d));
  1214. var _ = Date.now(),
  1215. g = function g() {
  1216. return _this2.instatnce.request(d).then(function (m) {
  1217. return o && logger.infoAndReportMeasurement({
  1218. metric: "http",
  1219. startTime: _,
  1220. extra: t,
  1221. group: "http",
  1222. tag: o
  1223. }), _this2.canceler.removeCancelToken(t), m;
  1224. }).catch(function (m) {
  1225. var v = axios.isCancel(m);
  1226. return u > 0 && !v ? (u--, logger.warn("request ".concat(t, " retry, left retry count"), u), g()) : (logger.infoAndReportMeasurement({
  1227. metric: "http",
  1228. startTime: _,
  1229. error: m,
  1230. extra: {
  1231. url: t,
  1232. isCanceled: v
  1233. },
  1234. tag: o,
  1235. group: "http"
  1236. }), _this2.canceler.removeCancelToken(t), Promise.reject(m));
  1237. });
  1238. };
  1239. return g();
  1240. }
  1241. }, {
  1242. key: "patchUrl",
  1243. value: function patchUrl(e) {
  1244. return e;
  1245. }
  1246. }, {
  1247. key: "randomString",
  1248. value: function randomString() {
  1249. var e = "";
  1250. var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
  1251. r = t.length;
  1252. for (var n = 0; n < 8; n++) {
  1253. e += t.charAt(Math.floor(Math.random() * r));
  1254. }
  1255. return e;
  1256. }
  1257. }]);
  1258. return Http1;
  1259. }(EventEmitter);
  1260. var http1 = new Http1();
  1261. var ModelManager = /*#__PURE__*/function () {
  1262. function ModelManager(e, t) {
  1263. _classCallCheck(this, ModelManager);
  1264. this.avatarModelList = [];
  1265. this.skinList = [];
  1266. this.applicationConfig = null;
  1267. this.config = null;
  1268. this.appId = e, this.releaseId = t;
  1269. }
  1270. _createClass(ModelManager, [{
  1271. key: "findSkinConfig",
  1272. value: function () {
  1273. var _findSkinConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  1274. var t, n;
  1275. return regenerator.wrap(function _callee$(_context) {
  1276. while (1) {
  1277. switch (_context.prev = _context.next) {
  1278. case 0:
  1279. t = null;
  1280. _context.next = 3;
  1281. return this.getSkinsList();
  1282. case 3:
  1283. t = (this.skinList = _context.sent).find(function (n) {
  1284. return n.id === e;
  1285. });
  1286. if (!t) {
  1287. _context.next = 6;
  1288. break;
  1289. }
  1290. return _context.abrupt("return", t);
  1291. case 6:
  1292. n = "skin is invalid: skinId: ".concat(e);
  1293. return _context.abrupt("return", Promise.reject(new ParamError(n)));
  1294. case 8:
  1295. case "end":
  1296. return _context.stop();
  1297. }
  1298. }
  1299. }, _callee, this);
  1300. }));
  1301. function findSkinConfig(_x) {
  1302. return _findSkinConfig.apply(this, arguments);
  1303. }
  1304. return findSkinConfig;
  1305. }()
  1306. }, {
  1307. key: "findRoute",
  1308. value: function () {
  1309. var _findRoute = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e, t) {
  1310. var n, o;
  1311. return regenerator.wrap(function _callee2$(_context2) {
  1312. while (1) {
  1313. switch (_context2.prev = _context2.next) {
  1314. case 0:
  1315. _context2.next = 2;
  1316. return this.findSkinConfig(e);
  1317. case 2:
  1318. n = _context2.sent.routeList.find(function (o) {
  1319. return o.pathName === t;
  1320. });
  1321. if (n) {
  1322. _context2.next = 6;
  1323. break;
  1324. }
  1325. o = "find path failed: skinId: ".concat(e, ", pathName: ").concat(t);
  1326. return _context2.abrupt("return", Promise.reject(new ParamError(o)));
  1327. case 6:
  1328. return _context2.abrupt("return", (logger.debug("find route success", n), n));
  1329. case 7:
  1330. case "end":
  1331. return _context2.stop();
  1332. }
  1333. }
  1334. }, _callee2, this);
  1335. }));
  1336. function findRoute(_x2, _x3) {
  1337. return _findRoute.apply(this, arguments);
  1338. }
  1339. return findRoute;
  1340. }()
  1341. }, {
  1342. key: "findAssetList",
  1343. value: function () {
  1344. var _findAssetList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  1345. var r, n;
  1346. return regenerator.wrap(function _callee3$(_context3) {
  1347. while (1) {
  1348. switch (_context3.prev = _context3.next) {
  1349. case 0:
  1350. _context3.next = 2;
  1351. return this.findSkinConfig(e);
  1352. case 2:
  1353. r = _context3.sent.assetList;
  1354. if (r) {
  1355. _context3.next = 6;
  1356. break;
  1357. }
  1358. n = "find path failed: skinId: ".concat(e);
  1359. return _context3.abrupt("return", Promise.reject(new ParamError(n)));
  1360. case 6:
  1361. return _context3.abrupt("return", (logger.debug("find route success", r), r));
  1362. case 7:
  1363. case "end":
  1364. return _context3.stop();
  1365. }
  1366. }
  1367. }, _callee3, this);
  1368. }));
  1369. function findAssetList(_x4) {
  1370. return _findAssetList.apply(this, arguments);
  1371. }
  1372. return findAssetList;
  1373. }()
  1374. }, {
  1375. key: "findAsset",
  1376. value: function () {
  1377. var _findAsset = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e, t) {
  1378. var r,
  1379. n,
  1380. o,
  1381. a,
  1382. _args4 = arguments;
  1383. return regenerator.wrap(function _callee4$(_context4) {
  1384. while (1) {
  1385. switch (_context4.prev = _context4.next) {
  1386. case 0:
  1387. r = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : "id";
  1388. _context4.next = 3;
  1389. return this.findSkinConfig(e);
  1390. case 3:
  1391. n = _context4.sent;
  1392. if (!Array.isArray(t)) {
  1393. _context4.next = 6;
  1394. break;
  1395. }
  1396. return _context4.abrupt("return", t.map(function (a) {
  1397. return n.models.find(function (s) {
  1398. return s[r] === a;
  1399. });
  1400. }).filter(Boolean));
  1401. case 6:
  1402. o = n.models.find(function (a) {
  1403. return a[r] === t;
  1404. });
  1405. if (o) {
  1406. _context4.next = 10;
  1407. break;
  1408. }
  1409. a = "find asset failed: skinId: ".concat(e, ", keyValue: ").concat(t);
  1410. return _context4.abrupt("return", Promise.reject(new ParamError(a)));
  1411. case 10:
  1412. return _context4.abrupt("return", (logger.debug("find asset success", o), o));
  1413. case 11:
  1414. case "end":
  1415. return _context4.stop();
  1416. }
  1417. }
  1418. }, _callee4, this);
  1419. }));
  1420. function findAsset(_x5, _x6) {
  1421. return _findAsset.apply(this, arguments);
  1422. }
  1423. return findAsset;
  1424. }()
  1425. }, {
  1426. key: "findPoint",
  1427. value: function () {
  1428. var _findPoint = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e, t) {
  1429. var n, o;
  1430. return regenerator.wrap(function _callee5$(_context5) {
  1431. while (1) {
  1432. switch (_context5.prev = _context5.next) {
  1433. case 0:
  1434. _context5.next = 2;
  1435. return this.findSkinConfig(e);
  1436. case 2:
  1437. n = _context5.sent.pointList.find(function (o) {
  1438. return o.id === t;
  1439. });
  1440. if (n) {
  1441. _context5.next = 6;
  1442. break;
  1443. }
  1444. o = "find point failed: skinId: ".concat(e, ", id: ").concat(t);
  1445. return _context5.abrupt("return", Promise.reject(new ParamError(o)));
  1446. case 6:
  1447. return _context5.abrupt("return", (logger.debug("find point success", n), n));
  1448. case 7:
  1449. case "end":
  1450. return _context5.stop();
  1451. }
  1452. }
  1453. }, _callee5, this);
  1454. }));
  1455. function findPoint(_x7, _x8) {
  1456. return _findPoint.apply(this, arguments);
  1457. }
  1458. return findPoint;
  1459. }()
  1460. }, {
  1461. key: "requestConfig",
  1462. value: function () {
  1463. var _requestConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  1464. var t, r, _ref, n, o;
  1465. return regenerator.wrap(function _callee6$(_context6) {
  1466. while (1) {
  1467. switch (_context6.prev = _context6.next) {
  1468. case 0:
  1469. if (!this.config) {
  1470. _context6.next = 2;
  1471. break;
  1472. }
  1473. return _context6.abrupt("return", this.config);
  1474. case 2:
  1475. // let e = `https://static.xverse.cn/console/config/${this.appId}/config.json`;
  1476. // this.releaseId && (e = `https://static.xverse.cn/console/config/${this.appId}/${this.releaseId}/config.json`);
  1477. // const t = Xverse.USE_TME_CDN ? "https://static.xverse.cn/tmeland/config/tme_config.json" : e;
  1478. t = './assets/config.json';
  1479. _context6.prev = 3;
  1480. _context6.next = 6;
  1481. return http1.get({
  1482. url: "".concat(t, "?t=").concat(Date.now()),
  1483. key: "config",
  1484. timeout: 6e3,
  1485. retry: 2
  1486. });
  1487. case 6:
  1488. r = _context6.sent;
  1489. _ref = r.data.data || {}, n = _ref.config, o = _ref.preload;
  1490. if (n) {
  1491. _context6.next = 10;
  1492. break;
  1493. }
  1494. throw new Error("config data parse error" + r.data);
  1495. case 10:
  1496. return _context6.abrupt("return", (this.config = {
  1497. config: n,
  1498. preload: o
  1499. }, logger.debug("get config success", this.config), this.config));
  1500. case 13:
  1501. _context6.prev = 13;
  1502. _context6.t0 = _context6["catch"](3);
  1503. return _context6.abrupt("return", Promise.reject(_context6.t0));
  1504. case 16:
  1505. case "end":
  1506. return _context6.stop();
  1507. }
  1508. }
  1509. }, _callee6, this, [[3, 13]]);
  1510. }));
  1511. function requestConfig() {
  1512. return _requestConfig.apply(this, arguments);
  1513. }
  1514. return requestConfig;
  1515. }()
  1516. }, {
  1517. key: "getApplicationConfig",
  1518. value: function () {
  1519. var _getApplicationConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7() {
  1520. var e;
  1521. return regenerator.wrap(function _callee7$(_context7) {
  1522. while (1) {
  1523. switch (_context7.prev = _context7.next) {
  1524. case 0:
  1525. if (!this.applicationConfig) {
  1526. _context7.next = 2;
  1527. break;
  1528. }
  1529. return _context7.abrupt("return", this.applicationConfig);
  1530. case 2:
  1531. _context7.prev = 2;
  1532. _context7.next = 5;
  1533. return this.requestConfig();
  1534. case 5:
  1535. e = _context7.sent;
  1536. return _context7.abrupt("return", (this.applicationConfig = e.config, this.applicationConfig));
  1537. case 9:
  1538. _context7.prev = 9;
  1539. _context7.t0 = _context7["catch"](2);
  1540. return _context7.abrupt("return", Promise.reject(_context7.t0));
  1541. case 12:
  1542. case "end":
  1543. return _context7.stop();
  1544. }
  1545. }
  1546. }, _callee7, this, [[2, 9]]);
  1547. }));
  1548. function getApplicationConfig() {
  1549. return _getApplicationConfig.apply(this, arguments);
  1550. }
  1551. return getApplicationConfig;
  1552. }()
  1553. }, {
  1554. key: "getAvatarModelList",
  1555. value: function () {
  1556. var _getAvatarModelList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  1557. var _yield$this$getApplic, e;
  1558. return regenerator.wrap(function _callee8$(_context8) {
  1559. while (1) {
  1560. switch (_context8.prev = _context8.next) {
  1561. case 0:
  1562. if (!this.avatarModelList.length) {
  1563. _context8.next = 2;
  1564. break;
  1565. }
  1566. return _context8.abrupt("return", this.avatarModelList);
  1567. case 2:
  1568. _context8.prev = 2;
  1569. _context8.next = 5;
  1570. return this.getApplicationConfig();
  1571. case 5:
  1572. _yield$this$getApplic = _context8.sent;
  1573. e = _yield$this$getApplic.avatars;
  1574. return _context8.abrupt("return", (this.avatarModelList = e.map(function (t) {
  1575. return {
  1576. name: t.name,
  1577. id: t.id,
  1578. modelUrl: t.url,
  1579. gender: t.gender,
  1580. components: t.components
  1581. };
  1582. }), this.avatarModelList));
  1583. case 10:
  1584. _context8.prev = 10;
  1585. _context8.t0 = _context8["catch"](2);
  1586. return _context8.abrupt("return", (logger.error(_context8.t0), []));
  1587. case 13:
  1588. case "end":
  1589. return _context8.stop();
  1590. }
  1591. }
  1592. }, _callee8, this, [[2, 10]]);
  1593. }));
  1594. function getAvatarModelList() {
  1595. return _getAvatarModelList.apply(this, arguments);
  1596. }
  1597. return getAvatarModelList;
  1598. }()
  1599. }, {
  1600. key: "getSkinsList",
  1601. value: function () {
  1602. var _getSkinsList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9() {
  1603. var _yield$this$getApplic2, e;
  1604. return regenerator.wrap(function _callee9$(_context9) {
  1605. while (1) {
  1606. switch (_context9.prev = _context9.next) {
  1607. case 0:
  1608. if (!this.skinList.length) {
  1609. _context9.next = 2;
  1610. break;
  1611. }
  1612. return _context9.abrupt("return", this.skinList);
  1613. case 2:
  1614. _context9.prev = 2;
  1615. _context9.next = 5;
  1616. return this.getApplicationConfig();
  1617. case 5:
  1618. _yield$this$getApplic2 = _context9.sent;
  1619. e = _yield$this$getApplic2.skins;
  1620. return _context9.abrupt("return", (this.skinList = e.map(function (t) {
  1621. var r;
  1622. return {
  1623. name: t.name,
  1624. dataVersion: t.id + t.versionId,
  1625. id: t.id,
  1626. fov: parseInt(t.fov || 90),
  1627. models: t.assetList.map(function (n) {
  1628. var o = n.assetId,
  1629. a = n.url,
  1630. s = n.thumbnailUrl,
  1631. l = n.typeName,
  1632. u = n.className;
  1633. return {
  1634. id: o,
  1635. modelUrl: a,
  1636. name: n.name,
  1637. thumbnailUrl: s,
  1638. typeName: l,
  1639. className: u === "\u4F4E\u6A21" ? "\u7C97\u6A21" : u
  1640. };
  1641. }),
  1642. routeList: (r = t.routeList) == null ? void 0 : r.map(function (n) {
  1643. var o = n.areaName,
  1644. a = n.attitude,
  1645. s = n.id,
  1646. l = n.pathName,
  1647. u = n.step,
  1648. c = n.birthPointList;
  1649. return {
  1650. areaName: o,
  1651. attitude: a,
  1652. id: s,
  1653. pathName: l,
  1654. step: u,
  1655. birthPointList: c.map(function (h) {
  1656. return {
  1657. camera: h.camera && {
  1658. position: objectParseFloat(h.camera.position),
  1659. angle: objectParseFloat(h.camera.rotation)
  1660. },
  1661. player: h.player && {
  1662. position: objectParseFloat(h.player.position),
  1663. angle: objectParseFloat(h.player.rotation)
  1664. }
  1665. };
  1666. })
  1667. };
  1668. }),
  1669. pointList: t.pointList.map(function (n) {
  1670. return le(oe({}, n), {
  1671. position: objectParseFloat(n.position),
  1672. rotation: objectParseFloat(n.rotation)
  1673. });
  1674. }),
  1675. versionId: t.versionId,
  1676. isEnable: t.isEnable,
  1677. assetList: t.assetList,
  1678. visibleRules: t.visibleRules,
  1679. animationList: t.animationList
  1680. };
  1681. }), this.skinList));
  1682. case 10:
  1683. _context9.prev = 10;
  1684. _context9.t0 = _context9["catch"](2);
  1685. return _context9.abrupt("return", (logger.error(_context9.t0), []));
  1686. case 13:
  1687. case "end":
  1688. return _context9.stop();
  1689. }
  1690. }
  1691. }, _callee9, this, [[2, 10]]);
  1692. }));
  1693. function getSkinsList() {
  1694. return _getSkinsList.apply(this, arguments);
  1695. }
  1696. return getSkinsList;
  1697. }()
  1698. }, {
  1699. key: "getBreathPointTextrueList",
  1700. value: function () {
  1701. var _getBreathPointTextrueList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10() {
  1702. return regenerator.wrap(function _callee10$(_context10) {
  1703. while (1) {
  1704. switch (_context10.prev = _context10.next) {
  1705. case 0:
  1706. return _context10.abrupt("return", [{
  1707. url: TEXTURE_URL
  1708. }]);
  1709. case 1:
  1710. case "end":
  1711. return _context10.stop();
  1712. }
  1713. }
  1714. }, _callee10);
  1715. }));
  1716. function getBreathPointTextrueList() {
  1717. return _getBreathPointTextrueList.apply(this, arguments);
  1718. }
  1719. return getBreathPointTextrueList;
  1720. }()
  1721. }], [{
  1722. key: "getInstance",
  1723. value: function getInstance(e, t) {
  1724. //getInstance(e, t) {
  1725. return this.instance || (this.instance = new ModelManager(e, t)), this.instance;
  1726. }
  1727. }, {
  1728. key: "findModels",
  1729. value: function findModels(e, t, r) {
  1730. //findModels(e, t, r) {
  1731. return e.filter(function (o) {
  1732. return o.typeName === t && o.className === r;
  1733. });
  1734. }
  1735. }, {
  1736. key: "findModel",
  1737. value: function findModel(e, t, r) {
  1738. //findModel(e, t, r) {
  1739. var n = e.filter(function (o) {
  1740. return o.typeName === t && o.className === r;
  1741. })[0];
  1742. return n || null;
  1743. }
  1744. }]);
  1745. return ModelManager;
  1746. }();
  1747. // export { modelManager };
  1748. var JoyStick = /*#__PURE__*/function () {
  1749. function JoyStick(e) {
  1750. _classCallCheck(this, JoyStick);
  1751. this._zone = document.createElement("div");
  1752. this._joystick = null;
  1753. this._room = e;
  1754. }
  1755. _createClass(JoyStick, [{
  1756. key: "init",
  1757. value: function init(e) {
  1758. var _this = this;
  1759. var _e$interval = e.interval,
  1760. t = _e$interval === void 0 ? 33 : _e$interval,
  1761. _e$triggerDistance = e.triggerDistance,
  1762. r = _e$triggerDistance === void 0 ? 25 : _e$triggerDistance,
  1763. _e$style = e.style,
  1764. n = _e$style === void 0 ? {
  1765. left: 0,
  1766. bottom: 0
  1767. } : _e$style,
  1768. o = function o(u, c) {
  1769. _this._room.actionsHandler.joystick({
  1770. degree: Math.floor(u),
  1771. level: Math.floor(c / 5)
  1772. });
  1773. },
  1774. a = this._zone;
  1775. 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({
  1776. zone: a,
  1777. mode: "static",
  1778. position: {
  1779. left: "50%",
  1780. top: "50%"
  1781. },
  1782. color: "white"
  1783. });
  1784. var s, l;
  1785. return this._joystick.on("move", function (u, c) {
  1786. s = c;
  1787. }), this._joystick.on("start", function () {
  1788. l = window.setInterval(function () {
  1789. s && s.distance > r && o && o(s.angle.degree, s.distance);
  1790. }, t);
  1791. }), this._joystick.on("end", function () {
  1792. l && window.clearInterval(l), l = void 0;
  1793. }), this._joystick;
  1794. }
  1795. }, {
  1796. key: "show",
  1797. value: function show() {
  1798. if (!this._joystick) throw new Error("joystick is not created");
  1799. this._zone.style.display = "block";
  1800. }
  1801. }, {
  1802. key: "hide",
  1803. value: function hide() {
  1804. if (!this._joystick) throw new Error("joystick is not created");
  1805. this._zone.style.display = "none";
  1806. }
  1807. }]);
  1808. return JoyStick;
  1809. }();
  1810. var CoreBroadcastType = {
  1811. PlayAnimation: 'PlayAnimation'
  1812. };
  1813. var AvatarGroup = {
  1814. Npc: 'npc',
  1815. User: 'user'
  1816. };
  1817. var MessageHandleType$1 = {
  1818. MHT_Undefined: 0,
  1819. MHT_RoomMulticast: 1,
  1820. MHT_FollowListMulticast: 2,
  1821. MHT_CustomTargetSync: 3
  1822. };
  1823. var Broadcast$1 = /*#__PURE__*/function () {
  1824. function Broadcast(e, t) {
  1825. _classCallCheck(this, Broadcast);
  1826. this.room = e;
  1827. this.handlers = [];
  1828. this.init(t);
  1829. }
  1830. _createClass(Broadcast, [{
  1831. key: "init",
  1832. value: function init(t) {
  1833. this.handlers.push(t);
  1834. }
  1835. }, {
  1836. key: "handleBroadcast",
  1837. value: function () {
  1838. var _handleBroadcast = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  1839. return regenerator.wrap(function _callee$(_context) {
  1840. while (1) {
  1841. switch (_context.prev = _context.next) {
  1842. case 0:
  1843. _context.prev = 1;
  1844. JSON.parse(e.broadcastAction.data);
  1845. _context.next = 9;
  1846. break;
  1847. case 5:
  1848. _context.prev = 5;
  1849. _context.t0 = _context["catch"](1);
  1850. logger.error(_context.t0);
  1851. return _context.abrupt("return");
  1852. case 9:
  1853. case "end":
  1854. return _context.stop();
  1855. }
  1856. }
  1857. }, _callee, null, [[1, 5]]);
  1858. }));
  1859. function handleBroadcast(_x) {
  1860. return _handleBroadcast.apply(this, arguments);
  1861. }
  1862. return handleBroadcast;
  1863. }()
  1864. }, {
  1865. key: "broadcast",
  1866. value: function broadcast(e) {
  1867. var t = e.data,
  1868. _e$msgType = e.msgType,
  1869. r = _e$msgType === void 0 ? MessageHandleType$1.MHT_FollowListMulticast : _e$msgType,
  1870. n = e.targetUserIds;
  1871. return this.room.actionsHandler.broadcast({
  1872. data: t,
  1873. msgType: r,
  1874. targetUserIds: n
  1875. });
  1876. }
  1877. }]);
  1878. return Broadcast;
  1879. }();
  1880. function _isNativeFunction(fn) {
  1881. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  1882. }
  1883. function _isNativeReflectConstruct$e() {
  1884. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1885. if (Reflect.construct.sham) return false;
  1886. if (typeof Proxy === "function") return true;
  1887. try {
  1888. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  1889. return true;
  1890. } catch (e) {
  1891. return false;
  1892. }
  1893. }
  1894. function _construct(Parent, args, Class) {
  1895. if (_isNativeReflectConstruct$e()) {
  1896. _construct = Reflect.construct;
  1897. } else {
  1898. _construct = function _construct(Parent, args, Class) {
  1899. var a = [null];
  1900. a.push.apply(a, args);
  1901. var Constructor = Function.bind.apply(Parent, a);
  1902. var instance = new Constructor();
  1903. if (Class) _setPrototypeOf(instance, Class.prototype);
  1904. return instance;
  1905. };
  1906. }
  1907. return _construct.apply(null, arguments);
  1908. }
  1909. function _wrapNativeSuper(Class) {
  1910. var _cache = typeof Map === "function" ? new Map() : undefined;
  1911. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  1912. if (Class === null || !_isNativeFunction(Class)) return Class;
  1913. if (typeof Class !== "function") {
  1914. throw new TypeError("Super expression must either be null or a function");
  1915. }
  1916. if (typeof _cache !== "undefined") {
  1917. if (_cache.has(Class)) return _cache.get(Class);
  1918. _cache.set(Class, Wrapper);
  1919. }
  1920. function Wrapper() {
  1921. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  1922. }
  1923. Wrapper.prototype = Object.create(Class.prototype, {
  1924. constructor: {
  1925. value: Wrapper,
  1926. enumerable: false,
  1927. writable: true,
  1928. configurable: true
  1929. }
  1930. });
  1931. return _setPrototypeOf(Wrapper, Class);
  1932. };
  1933. return _wrapNativeSuper(Class);
  1934. }
  1935. 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); }; }
  1936. 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; } }
  1937. var XverseError = /*#__PURE__*/function (_Error) {
  1938. _inherits(XverseError, _Error);
  1939. var _super = _createSuper$d(XverseError);
  1940. function XverseError(e, t) {
  1941. var _this;
  1942. _classCallCheck(this, XverseError);
  1943. _this = _super.call(this, t);
  1944. _this.code = e;
  1945. return _this;
  1946. }
  1947. _createClass(XverseError, [{
  1948. key: "toJSON",
  1949. value: function toJSON() {
  1950. return {
  1951. code: this.code,
  1952. message: this.message
  1953. };
  1954. }
  1955. }, {
  1956. key: "toString",
  1957. value: function toString() {
  1958. if (Object(this) !== this) throw new TypeError();
  1959. var t = this.name;
  1960. t = t === void 0 ? "Error" : String(t);
  1961. var r = this.message;
  1962. r = r === void 0 ? "" : String(r);
  1963. var n = this.code;
  1964. return r = n === void 0 ? r : n + "," + r, t === "" ? r : r === "" ? t : t + ": " + r;
  1965. }
  1966. }]);
  1967. return XverseError;
  1968. }( /*#__PURE__*/_wrapNativeSuper(Error));
  1969. 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); }; }
  1970. 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; } }
  1971. var TimeoutError = /*#__PURE__*/function (_XverseError) {
  1972. _inherits(TimeoutError, _XverseError);
  1973. var _super = _createSuper$c(TimeoutError);
  1974. function TimeoutError(e) {
  1975. _classCallCheck(this, TimeoutError);
  1976. return _super.call(this, 1003, e || "\u8D85\u65F6");
  1977. }
  1978. return _createClass(TimeoutError);
  1979. }(XverseError);
  1980. 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); }; }
  1981. 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; } }
  1982. var XverseAvatarManager = /*#__PURE__*/function (_EventEmitter) {
  1983. _inherits(XverseAvatarManager, _EventEmitter);
  1984. var _super = _createSuper$b(XverseAvatarManager);
  1985. function XverseAvatarManager(e) {
  1986. var _this;
  1987. _classCallCheck(this, XverseAvatarManager);
  1988. _this = _super.call(this);
  1989. _this.xAvatarManager = null;
  1990. _this.avatars = new Map();
  1991. _this.syncAvatarsLength = 0;
  1992. _this._room = e;
  1993. _this._usersStatistics();
  1994. _this.broadcast = _this.setupBroadcast();
  1995. e.on("skinChanged", function () {
  1996. _this.avatars.forEach(function (t) {
  1997. t.disconnected && _this.removeAvatar(t.userId, !0);
  1998. });
  1999. });
  2000. return _this;
  2001. }
  2002. _createClass(XverseAvatarManager, [{
  2003. key: "setupBroadcast",
  2004. value: function setupBroadcast() {
  2005. var _this2 = this;
  2006. return new Broadcast$1(this._room, /*#__PURE__*/function () {
  2007. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  2008. var t, r, n, o, a, _r$loop, s, l;
  2009. return regenerator.wrap(function _callee$(_context) {
  2010. while (1) {
  2011. switch (_context.prev = _context.next) {
  2012. case 0:
  2013. t = e.broadcastType, r = e.info;
  2014. if (!(t !== CoreBroadcastType.PlayAnimation)) {
  2015. _context.next = 3;
  2016. break;
  2017. }
  2018. return _context.abrupt("return");
  2019. case 3:
  2020. 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);
  2021. _context.t0 = l && !l.isSelf;
  2022. if (!_context.t0) {
  2023. _context.next = 10;
  2024. break;
  2025. }
  2026. l.emit("animationStart", {
  2027. animationName: o,
  2028. extra: decodeURIComponent(a)
  2029. });
  2030. _context.next = 9;
  2031. return l == null ? void 0 : l._playAnimation(o, s);
  2032. case 9:
  2033. l.emit("animationEnd", {
  2034. animationName: o,
  2035. extra: decodeURIComponent(a)
  2036. });
  2037. case 10:
  2038. case "end":
  2039. return _context.stop();
  2040. }
  2041. }
  2042. }, _callee);
  2043. }));
  2044. return function (_x) {
  2045. return _ref.apply(this, arguments);
  2046. };
  2047. }());
  2048. }
  2049. }, {
  2050. key: "hideAll",
  2051. value: function hideAll() {
  2052. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2053. this.xAvatarManager.hideAll(e);
  2054. }
  2055. }, {
  2056. key: "showAll",
  2057. value: function showAll() {
  2058. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  2059. this.xAvatarManager.showAll(e);
  2060. }
  2061. }, {
  2062. key: "init",
  2063. value: function () {
  2064. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  2065. var e, t;
  2066. return regenerator.wrap(function _callee2$(_context2) {
  2067. while (1) {
  2068. switch (_context2.prev = _context2.next) {
  2069. case 0:
  2070. this.xAvatarManager = this._room.sceneManager.avatarComponent;
  2071. _context2.prev = 1;
  2072. _context2.next = 4;
  2073. return this._room.modelManager.getApplicationConfig();
  2074. case 4:
  2075. e = _context2.sent;
  2076. t = e.avatars;
  2077. if (!t) {
  2078. _context2.next = 10;
  2079. break;
  2080. }
  2081. _context2.next = 9;
  2082. return avatarLoader.parse(this._room.sceneManager, t);
  2083. case 9:
  2084. return _context2.abrupt("return");
  2085. case 10:
  2086. return _context2.abrupt("return", Promise.reject("cannot find avatar config list"));
  2087. case 13:
  2088. _context2.prev = 13;
  2089. _context2.t0 = _context2["catch"](1);
  2090. return _context2.abrupt("return", (logger.error(_context2.t0), Promise.reject("avatar mananger init error!")));
  2091. case 16:
  2092. case "end":
  2093. return _context2.stop();
  2094. }
  2095. }
  2096. }, _callee2, this, [[1, 13]]);
  2097. }));
  2098. function init() {
  2099. return _init.apply(this, arguments);
  2100. }
  2101. return init;
  2102. }()
  2103. }, {
  2104. key: "handleAvatar",
  2105. value: function () {
  2106. var _handleAvatar2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  2107. var _this3 = this;
  2108. var r, t, n, o, _n, a;
  2109. return regenerator.wrap(function _callee3$(_context3) {
  2110. while (1) {
  2111. switch (_context3.prev = _context3.next) {
  2112. case 0:
  2113. if (!(this._room.viewMode === "simple" || !this._room.joined || !e.newUserStates)) {
  2114. _context3.next = 2;
  2115. break;
  2116. }
  2117. return _context3.abrupt("return");
  2118. case 2:
  2119. t = e.newUserStates;
  2120. if (((r = this._room._userAvatar) == null ? void 0 : r.isMoving) && this._room._userAvatar.motionType === MotionType.Run) {
  2121. n = t.filter(function (a) {
  2122. return a.userId === _this3._room.userId;
  2123. }), o = t.filter(function (a) {
  2124. return a.userId !== _this3._room.userId;
  2125. }).slice(0, 2);
  2126. t = n.concat(o);
  2127. }
  2128. if (e.getStateType === GetStateTypes.Event) {
  2129. this.syncAvatarsLength = (t || []).length;
  2130. _n = this._room.avatars.filter(function (s) {
  2131. return s.group == AvatarGroup.User;
  2132. });
  2133. _n.filter(function (s) {
  2134. return !(t != null && t.find(function (l) {
  2135. return l.userId == s.userId;
  2136. }));
  2137. }).forEach(function (s) {
  2138. _this3.removeAvatar(s.userId);
  2139. });
  2140. a = t.filter(function (s) {
  2141. return !_n.find(function (l) {
  2142. return l.userId == s.userId;
  2143. });
  2144. });
  2145. this._handleAvatar(a);
  2146. }
  2147. this._handleAvatar(t);
  2148. case 6:
  2149. case "end":
  2150. return _context3.stop();
  2151. }
  2152. }
  2153. }, _callee3, this);
  2154. }));
  2155. function handleAvatar(_x2) {
  2156. return _handleAvatar2.apply(this, arguments);
  2157. }
  2158. return handleAvatar;
  2159. }()
  2160. }, {
  2161. key: "_handleAvatar",
  2162. value: function () {
  2163. var _handleAvatar3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  2164. var _this4 = this;
  2165. return regenerator.wrap(function _callee4$(_context4) {
  2166. while (1) {
  2167. switch (_context4.prev = _context4.next) {
  2168. case 0:
  2169. e == null || e.forEach(function (t) {
  2170. var n, o, a, s, l, u, c, h, f;
  2171. var r = _this4._room.userId === t.userId;
  2172. if (((n = t.event) == null ? void 0 : n.type) === SyncEventType.ET_RemoveVisitor) {
  2173. var d = (a = (o = t.event) == null ? void 0 : o.removeVisitorEvent) == null ? void 0 : a.removeVisitorEvent,
  2174. _ = JSON.parse(safeDecodeURIComponent(((l = (s = t.event) == null ? void 0 : s.removeVisitorEvent) == null ? void 0 : l.extraInfo) || "")),
  2175. g = _.code,
  2176. m = _.msg;
  2177. d === RemoveVisitorType.RVT_ChangeToObserver ? _this4._room.audienceViewModeHook() : d === RemoveVisitorType.RVT_MoveOutOfTheRoom && _this4._room.leave(), _this4._room.emit("visitorStatusChanged", {
  2178. code: g,
  2179. msg: m
  2180. });
  2181. }
  2182. if (t.event && [SyncEventType.Appear, SyncEventType.Reset].includes(t.event.type) || !t.event) {
  2183. var _d = _this4.avatars.get(t.userId);
  2184. if (t.playerState.avatarId && (_d == null ? void 0 : _d.avatarId) !== t.playerState.avatarId && (_d = void 0, _this4.removeAvatar(t.userId)), _d) {
  2185. 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) {
  2186. var _2 = safeParseComponents(t.playerState.avatarComponents);
  2187. _d._changeComponents({
  2188. avatarComponents: _2,
  2189. mode: ChangeComponentsMode.Preview
  2190. });
  2191. }
  2192. } else {
  2193. var _t$playerState$player = t.playerState.player,
  2194. _3 = _t$playerState$player.position,
  2195. _g = _t$playerState$player.angle,
  2196. _m = t.playerState.avatarId,
  2197. v = t.playerState.prioritySync,
  2198. y = safelyJsonParse(t.playerState.extra);
  2199. if (!_m) return;
  2200. var b = safeParseComponents(t.playerState.avatarComponents),
  2201. T = safeDecodeURIComponent(t.playerState.nickName),
  2202. C = _this4.calculatePriority(t.userId, y);
  2203. _this4.addAvatar({
  2204. userId: t.userId,
  2205. isHost: t.playerState.isHost,
  2206. nickname: T,
  2207. avatarPosition: _3,
  2208. avatarRotation: _g,
  2209. avatarScale: t.playerState.avatarSize,
  2210. avatarId: _m,
  2211. avatarComponents: t.playerState.person === Person.First ? [] : b,
  2212. priority: C,
  2213. group: AvatarGroup.User,
  2214. prioritySync: v,
  2215. extraInfo: y
  2216. }).then(function () {
  2217. var A;
  2218. (A = t.event) != null && A.id && _this4._room.actionsHandler.confirmEvent(t.event.id), _this4.updateAvatarPositionAndRotation(t), r && (_this4.xAvatarManager.setMainAvatar(t.userId), _this4._room.emit("userAvatarLoaded"), logger.info("userAvatarLoaded"));
  2219. }).catch(function (A) {
  2220. r && (_this4.xAvatarManager.setMainAvatar(t.userId), _this4._room.emit("userAvatarFailed", {
  2221. error: A
  2222. }), logger.error("userAvatarFailed", A));
  2223. });
  2224. }
  2225. }
  2226. 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) {
  2227. (h = t == null ? void 0 : t.event) != null && h.id && _this4._room.actionsHandler.confirmEvent(t.event.id);
  2228. var _d2 = _this4.avatars.get(t.userId);
  2229. _d2 && _d2.withModel && !_d2.isLoading && _this4.updateAvatarPositionAndRotation(t);
  2230. }
  2231. if (!r && ((f = t.event) == null ? void 0 : f.type) === SyncEventType.Rotate) {
  2232. var _d3 = _this4.avatars.get(t.userId);
  2233. _d3.statusSyncQueue.append({
  2234. type: QueueType.Rotate,
  2235. action: function action() {
  2236. return _d3.statusSync(t);
  2237. }
  2238. });
  2239. }
  2240. });
  2241. case 1:
  2242. case "end":
  2243. return _context4.stop();
  2244. }
  2245. }
  2246. }, _callee4);
  2247. }));
  2248. function _handleAvatar(_x3) {
  2249. return _handleAvatar3.apply(this, arguments);
  2250. }
  2251. return _handleAvatar;
  2252. }()
  2253. }, {
  2254. key: "calculatePriority",
  2255. value: function calculatePriority(e, t) {
  2256. var n;
  2257. return e === this._room.userId ? EAvatarRelationRank.Self : (n = this._room.options.firends) != null && n.includes(e) ? EAvatarRelationRank.Friend : EAvatarRelationRank.Stranger;
  2258. }
  2259. }, {
  2260. key: "updateAvatarPositionAndRotation",
  2261. value: function updateAvatarPositionAndRotation(e) {
  2262. var t, r;
  2263. if ((t = e == null ? void 0 : e.playerState) != null && t.player) {
  2264. var _e$playerState$player = e.playerState.player,
  2265. n = _e$playerState$player.position,
  2266. o = _e$playerState$player.angle;
  2267. var a = this.avatars.get(e.userId);
  2268. if (!a) return;
  2269. 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({
  2270. type: QueueType.Move,
  2271. action: function action() {
  2272. return a.statusSync(e);
  2273. }
  2274. }), e.renderInfo && a.isSelf) {
  2275. var _e$renderInfo = e.renderInfo,
  2276. s = _e$renderInfo.isMoving,
  2277. l = _e$renderInfo.isRotating;
  2278. this._updateAvatarMovingStatus({
  2279. id: e.userId,
  2280. isMoving: !!s,
  2281. isRotating: !!l
  2282. });
  2283. }
  2284. }
  2285. }
  2286. }, {
  2287. key: "addAvatar",
  2288. value: function () {
  2289. var _addAvatar = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(e) {
  2290. 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;
  2291. return regenerator.wrap(function _callee5$(_context5) {
  2292. while (1) {
  2293. switch (_context5.prev = _context5.next) {
  2294. case 0:
  2295. 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;
  2296. g = this.avatars.get(t);
  2297. if (!g) {
  2298. _context5.next = 4;
  2299. break;
  2300. }
  2301. return _context5.abrupt("return", Promise.resolve(g));
  2302. case 4:
  2303. if (!(g = new xe.subAvatar({
  2304. userId: t,
  2305. isHost: r,
  2306. isSelf: _,
  2307. room: this._room,
  2308. avatarComponents: l,
  2309. avatarId: o,
  2310. nickname: s,
  2311. group: c
  2312. }), this.avatars.set(t, g), !g.withModel)) {
  2313. _context5.next = 6;
  2314. break;
  2315. }
  2316. return _context5.abrupt("return", (g.isLoading = !1, g.avatarLoadedHook(), this._room.emit("avatarChanged", {
  2317. avatars: this._room.avatars
  2318. }), g));
  2319. case 6:
  2320. _context5.next = 8;
  2321. return this._room.modelManager.getAvatarModelList();
  2322. case 8:
  2323. v = _context5.sent.find(function (b) {
  2324. return b.id === o;
  2325. });
  2326. y = Date.now();
  2327. if (v) {
  2328. _context5.next = 12;
  2329. break;
  2330. }
  2331. return _context5.abrupt("return", (this._room.emit("avatarChanged", {
  2332. avatars: this._room.avatars
  2333. }), this.avatars.delete(t), Promise.reject("no such avatar model with id: ".concat(o))));
  2334. case 12:
  2335. _context5.prev = 12;
  2336. _context5.next = 15;
  2337. return avatarComponentsModify(v, l);
  2338. case 15:
  2339. b = _context5.sent;
  2340. b = b.filter(function (A) {
  2341. return A.type != "pendant";
  2342. });
  2343. _context5.next = 19;
  2344. return avatarComponentsParser(v, b);
  2345. case 19:
  2346. T = _context5.sent;
  2347. _context5.next = 22;
  2348. return this.xAvatarManager.loadAvatar({
  2349. id: t,
  2350. avatarType: o,
  2351. priority: u,
  2352. avatarManager: this.xAvatarManager,
  2353. assets: T,
  2354. status: {
  2355. avatarPosition: n,
  2356. avatarRotation: a,
  2357. avatarScale: h
  2358. }
  2359. })._timeout(8e3, new TimeoutError$1("loadAvatar timeout(8s)"));
  2360. case 22:
  2361. C = _context5.sent;
  2362. 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", {
  2363. avatars: this._room.avatars
  2364. }), s && g._setNickname(s), t === this._room.userId && (logger.infoAndReportMeasurement({
  2365. metric: "avatarLoadDuration",
  2366. startTime: y,
  2367. group: "costs"
  2368. }), logger.infoAndReportMeasurement({
  2369. metric: "avatarLoadAt",
  2370. startTime: this._room._startTime,
  2371. group: "costs"
  2372. })), g));
  2373. case 26:
  2374. _context5.prev = 26;
  2375. _context5.t0 = _context5["catch"](12);
  2376. return _context5.abrupt("return", (g.isLoading = !1, this._room.emit("avatarChanged", {
  2377. avatars: this._room.avatars
  2378. }), logger.error(_context5.t0), Promise.reject(_context5.t0)));
  2379. case 29:
  2380. case "end":
  2381. return _context5.stop();
  2382. }
  2383. }
  2384. }, _callee5, this, [[12, 26]]);
  2385. }));
  2386. function addAvatar(_x4) {
  2387. return _addAvatar.apply(this, arguments);
  2388. }
  2389. return addAvatar;
  2390. }()
  2391. }, {
  2392. key: "removeAvatar",
  2393. value: function removeAvatar(e) {
  2394. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
  2395. var r = this.avatars.get(e);
  2396. if (!!r) {
  2397. if (r.removeWhenDisconnected || t) {
  2398. r.xAvatar && this.xAvatarManager.deleteAvatar(r.xAvatar), this.avatars.delete(e), this._room.emit("avatarChanged", {
  2399. avatars: this._room.avatars
  2400. });
  2401. return;
  2402. }
  2403. r.setConnectionStatus(!0);
  2404. }
  2405. }
  2406. }, {
  2407. key: "clearOtherUsers",
  2408. value: function clearOtherUsers() {
  2409. var _this5 = this;
  2410. this.avatars.forEach(function (e) {
  2411. !e.isSelf && e.group === AvatarGroup.User && _this5.removeAvatar(e.userId);
  2412. });
  2413. }
  2414. }, {
  2415. key: "_updateAvatarMovingStatus",
  2416. value: function () {
  2417. var _updateAvatarMovingStatus2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  2418. var t, r, n, o, a, _a;
  2419. return regenerator.wrap(function _callee6$(_context6) {
  2420. while (1) {
  2421. switch (_context6.prev = _context6.next) {
  2422. case 0:
  2423. t = e.id, r = e.isMoving, n = e.isRotating, o = this.avatars.get(t);
  2424. if (!!o) {
  2425. if (o.isRotating !== n) {
  2426. o.isRotating = n;
  2427. a = "Idle";
  2428. n && (a = "Walking", o.motionType === MotionType.Run && (a = "Running")), o._playAnimation(a, !0, !0), logger.infoAndReportMeasurement({
  2429. startTime: Date.now(),
  2430. value: 0,
  2431. metric: n ? "userAvatarStartRotating" : "userAvatarStopRotating",
  2432. extra: {
  2433. motionType: o.motionType,
  2434. moveToExtra: this._room.moveToExtra
  2435. }
  2436. });
  2437. }
  2438. if (o.isMoving !== r) {
  2439. o.isMoving = r;
  2440. _a = "Idle";
  2441. r && (_a = "Walking", o.motionType === MotionType.Run && (_a = "Running")), r ? (o.avatarStartMovingHook(), o.emit("startMoving", {
  2442. target: o,
  2443. extra: this._room.moveToExtra
  2444. })) : (o.avatarStopMovingHook(), o.emit("stopMoving", {
  2445. target: o,
  2446. extra: this._room.moveToExtra
  2447. })), o._playAnimation(_a, !0, !0), logger.infoAndReportMeasurement({
  2448. startTime: Date.now(),
  2449. value: 0,
  2450. metric: r ? "userAvatarStartMoving" : "userAvatarStopMoving",
  2451. extra: {
  2452. motionType: o.motionType,
  2453. moveToExtra: this._room.moveToExtra
  2454. }
  2455. });
  2456. }
  2457. }
  2458. case 2:
  2459. case "end":
  2460. return _context6.stop();
  2461. }
  2462. }
  2463. }, _callee6, this);
  2464. }));
  2465. function _updateAvatarMovingStatus(_x5) {
  2466. return _updateAvatarMovingStatus2.apply(this, arguments);
  2467. }
  2468. return _updateAvatarMovingStatus;
  2469. }()
  2470. }, {
  2471. key: "_usersStatistics",
  2472. value: function _usersStatistics() {
  2473. var _this6 = this;
  2474. this.on("userAvatarLoaded", function () {
  2475. window.setInterval(function () {
  2476. var e = _this6._room.avatars.filter(function (r) {
  2477. return r.group === AvatarGroup.User;
  2478. }).length || 0,
  2479. t = _this6._room.avatars.filter(function (r) {
  2480. return r.group === AvatarGroup.User && r.isRender;
  2481. }).length || 0;
  2482. _this6._room.stats.assign({
  2483. userNum: e,
  2484. syncUserNum: _this6.syncAvatarsLength,
  2485. renderedUserNum: t
  2486. });
  2487. }, 3e3);
  2488. });
  2489. }
  2490. }]);
  2491. return XverseAvatarManager;
  2492. }(EventEmitter);
  2493. var PathManager = /*#__PURE__*/function () {
  2494. function PathManager() {
  2495. _classCallCheck(this, PathManager);
  2496. this.currentArea = '';
  2497. this.currentPathName = '';
  2498. this.currentAttitude = '';
  2499. this.speed = 0;
  2500. }
  2501. _createClass(PathManager, [{
  2502. key: "getSpeed",
  2503. value: function getSpeed(e) {
  2504. var t = {
  2505. guangchang: {
  2506. [MotionType.Walk]: 17,
  2507. [MotionType.Run]: 51
  2508. },
  2509. tower: {
  2510. [MotionType.Walk]: 12.5,
  2511. [MotionType.Run]: 25
  2512. },
  2513. zhiboting: {
  2514. [MotionType.Walk]: 12.5,
  2515. [MotionType.Run]: 25
  2516. },
  2517. youxiting: {
  2518. [MotionType.Walk]: 12.5,
  2519. [MotionType.Run]: 25
  2520. },
  2521. diqing: {
  2522. [MotionType.Walk]: 12.5,
  2523. [MotionType.Run]: 25
  2524. }
  2525. },
  2526. r = t[this.currentArea] || t.guangchang;
  2527. return this.speed = r[e] * 30, this.speed;
  2528. }
  2529. }]);
  2530. return PathManager;
  2531. }();
  2532. var CameraStates = {
  2533. Normal: 0,
  2534. ItemView: 1,
  2535. CGView: 2,
  2536. PathView: 3
  2537. };
  2538. var Person$1 = {
  2539. Third: 0,
  2540. First: 1
  2541. };
  2542. 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); }; }
  2543. 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; } }
  2544. var Camera = /*#__PURE__*/function (_EventEmitter) {
  2545. _inherits(Camera, _EventEmitter);
  2546. var _super = _createSuper$a(Camera);
  2547. function Camera(e) {
  2548. var _this;
  2549. _classCallCheck(this, Camera);
  2550. _this = _super.call(this);
  2551. _this.initialFov = 0;
  2552. _this._state = CameraStates.Normal;
  2553. _this._person = Person$1.Third;
  2554. _this._cameraFollowing = !0;
  2555. _this._room = e;
  2556. return _this;
  2557. }
  2558. _createClass(Camera, [{
  2559. key: "checkPointOnLeftOrRight",
  2560. value: function checkPointOnLeftOrRight(e) {
  2561. var t = ue4Position2Xverse(e);
  2562. if (!t || this.checkPointInView(e)) return;
  2563. var o = this._room.scene.activeCamera;
  2564. if (!o) return;
  2565. var a = [o.target.x, o.target.y, o.target.z],
  2566. s = [o.position.x, o.position.y, o.position.z],
  2567. l = t.x,
  2568. u = t.y,
  2569. c = t.z,
  2570. h = calNormVector(s, a),
  2571. f = calNormVector(s, [l, u, c]);
  2572. return vectorCrossMulti(h, f) < 0 ? Direction.Right : Direction.Left;
  2573. }
  2574. }, {
  2575. key: "checkPointInView",
  2576. value: function checkPointInView(e, t, r) {
  2577. var n = ue4Position2Xverse({
  2578. x: e,
  2579. y: t,
  2580. z: r
  2581. });
  2582. if (!n) return !1;
  2583. for (var o = 0; o < 6; o++) {
  2584. if (this._room.scene.frustumPlanes[o].dotCoordinate(n) < 0) return !1;
  2585. }
  2586. return !0;
  2587. }
  2588. }, {
  2589. key: "person",
  2590. get: function get() {
  2591. return this._person;
  2592. }
  2593. }, {
  2594. key: "state",
  2595. get: function get() {
  2596. return this._state;
  2597. }
  2598. }, {
  2599. key: "pose",
  2600. get: function get() {
  2601. return this._room.currentClickingState.camera;
  2602. }
  2603. }, {
  2604. key: "cameraFollowing",
  2605. get: function get() {
  2606. return this._cameraFollowing;
  2607. },
  2608. set: function set(e) {
  2609. logger.info("cameraFollowing setter", e), this.setCameraFollowing({
  2610. isFollowHost: e
  2611. });
  2612. }
  2613. }, {
  2614. key: "setCameraFollowing",
  2615. value: function setCameraFollowing(_ref) {
  2616. _ref.isFollowHost;
  2617. }
  2618. }, {
  2619. key: "handleRenderInfo",
  2620. value: function handleRenderInfo(e) {
  2621. var t = e.renderInfo.cameraStateType,
  2622. r = this._room.sceneManager;
  2623. if (t !== this._state && (this._state = t, logger.debug("camera._state changed to", CameraStates[t]), t === CameraStates.CGView ? (r.cameraComponent.switchToCgCamera(), r.staticmeshComponent.getCgMesh().show()) : (r.cameraComponent.switchToMainCamera(), r.staticmeshComponent.getCgMesh().hide()), this.emit("stateChanged", {
  2624. state: t
  2625. })), this._room.isHost) return;
  2626. var n = e.playerState.isFollowHost;
  2627. !!n !== this._cameraFollowing && (this._cameraFollowing = !!n, this.emit("cameraFollowingChanged", {
  2628. cameraFollowing: !!n
  2629. }));
  2630. }
  2631. }, {
  2632. key: "setCameraState",
  2633. value: function setCameraState(_ref2) {
  2634. var e = _ref2.state;
  2635. if (this._state === e) {
  2636. logger.warn("You are already in ".concat(CameraStates[e], " camera state"));
  2637. return;
  2638. }
  2639. e === CameraStates.Normal || this._state === CameraStates.ItemView && logger.warn("CloseUp camera state can only be triggerd by room internally");
  2640. }
  2641. }, {
  2642. key: "turnToFace",
  2643. value: function turnToFace(_ref3) {
  2644. var _ref3$extra = _ref3.extra,
  2645. e = _ref3$extra === void 0 ? "" : _ref3$extra,
  2646. _ref3$offset = _ref3.offset,
  2647. t = _ref3$offset === void 0 ? 0 : _ref3$offset;
  2648. var r = {
  2649. action_type: Actions.TurnToFace,
  2650. turn_to_face_action: {
  2651. offset: t
  2652. }
  2653. };
  2654. return this.emit("viewChanged", {
  2655. extra: e
  2656. }), this._room.actionsHandler.sendData({
  2657. data: r
  2658. });
  2659. }
  2660. }, {
  2661. key: "isInDefaultView",
  2662. value: function isInDefaultView() {
  2663. if (!this._room.isHost) {
  2664. logger.warn("It is recommended to call the function on the host side");
  2665. return;
  2666. }
  2667. if (!this._room._currentClickingState) return logger.error("CurrentState should not be empty"), !1;
  2668. var _this$_room$_currentC = this._room._currentClickingState,
  2669. e = _this$_room$_currentC.camera,
  2670. t = _this$_room$_currentC.player;
  2671. return Math.abs(t.angle.yaw - 180 - e.angle.yaw) % 360 <= 4;
  2672. }
  2673. }, {
  2674. key: "screenShot",
  2675. value: function () {
  2676. var _screenShot = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(_ref4) {
  2677. var e, _ref4$autoSave, t, r, n, o;
  2678. return regenerator.wrap(function _callee$(_context) {
  2679. while (1) {
  2680. switch (_context.prev = _context.next) {
  2681. case 0:
  2682. e = _ref4.name, _ref4$autoSave = _ref4.autoSave, t = _ref4$autoSave === void 0 ? !1 : _ref4$autoSave;
  2683. r = this._room.scene.getEngine(), n = this._room.scene.activeCamera;
  2684. _context.prev = 2;
  2685. this._room.sceneManager.setImageQuality(EImageQuality.high);
  2686. _context.next = 6;
  2687. return CreateScreenshotAsync(r, n, {
  2688. precision: 1
  2689. });
  2690. case 6:
  2691. o = _context.sent;
  2692. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), t === !0 && downloadFileByBase64(o, e), Promise.resolve(o)));
  2693. case 10:
  2694. _context.prev = 10;
  2695. _context.t0 = _context["catch"](2);
  2696. return _context.abrupt("return", (this._room.sceneManager.setImageQuality(EImageQuality.low), Promise.reject(_context.t0)));
  2697. case 13:
  2698. case "end":
  2699. return _context.stop();
  2700. }
  2701. }
  2702. }, _callee, this, [[2, 10]]);
  2703. }));
  2704. function screenShot(_x) {
  2705. return _screenShot.apply(this, arguments);
  2706. }
  2707. return screenShot;
  2708. }()
  2709. }, {
  2710. key: "changeToFirstPerson",
  2711. value: function changeToFirstPerson(e, t, r) {
  2712. var _this2 = this;
  2713. var n = e.camera,
  2714. o = e.player,
  2715. a = e.attitude,
  2716. s = e.areaName,
  2717. l = e.pathName;
  2718. return this._room.actionsHandler.requestPanorama({
  2719. camera: n,
  2720. player: o,
  2721. attitude: a,
  2722. areaName: s,
  2723. pathName: l
  2724. }, t, r).then(function () {
  2725. _this2._room.networkController.rtcp.workers.changePanoMode(!0);
  2726. var _ref5 = o || {},
  2727. u = _ref5.position,
  2728. c = _ref5.angle;
  2729. _this2._room.sceneManager.cameraComponent.changeToFirstPersonView({
  2730. position: u,
  2731. rotation: c
  2732. });
  2733. });
  2734. }
  2735. }, {
  2736. key: "setPerson",
  2737. value: function setPerson(e) {
  2738. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  2739. camera: this._room._currentClickingState.camera,
  2740. player: this._room._currentClickingState.player
  2741. };
  2742. var r = Date.now();
  2743. return this._setPerson(e, t).then(function (n) {
  2744. return logger.infoAndReportMeasurement({
  2745. tag: Person$1[e],
  2746. startTime: r,
  2747. metric: "setPerson"
  2748. }), n;
  2749. }).catch(function (n) {
  2750. return logger.infoAndReportMeasurement({
  2751. tag: Person$1[e],
  2752. startTime: r,
  2753. metric: "setPerson",
  2754. error: n
  2755. }), Promise.reject(n);
  2756. });
  2757. }
  2758. }, {
  2759. key: "_setPerson",
  2760. value: function _setPerson(e) {
  2761. var _this3 = this;
  2762. var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  2763. camera: this._room._currentClickingState.camera,
  2764. player: this._room._currentClickingState.player
  2765. };
  2766. 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({
  2767. camera: t.camera,
  2768. player: t.player,
  2769. tag: "setPerson"
  2770. }).then(function () {
  2771. var o, a;
  2772. _this3._person = e, (o = _this3._room._userAvatar) == null || o.hide();
  2773. var _ref6 = ((a = _this3._room.currentClickingState) == null ? void 0 : a.camera) || {},
  2774. r = _ref6.position,
  2775. n = _ref6.angle;
  2776. !r || !n || _this3._room.sceneManager.cameraComponent.changeToFirstPersonView({
  2777. position: r,
  2778. rotation: n
  2779. });
  2780. }) : this._room.panorama.exit({
  2781. camera: t.camera,
  2782. player: t.player
  2783. }).then(function () {
  2784. var r, n;
  2785. _this3._person = e, (r = _this3._room._userAvatar) != null && r.xAvatar && ((n = _this3._room._userAvatar) == null || n.xAvatar.show());
  2786. });
  2787. }
  2788. }, {
  2789. key: "setCameraPose",
  2790. value: function setCameraPose(e) {
  2791. this._room.sceneManager.cameraComponent.setCameraPose({
  2792. position: e.position,
  2793. rotation: e.angle
  2794. });
  2795. }
  2796. }, {
  2797. key: "setMainCameraRotationLimit",
  2798. value: function setMainCameraRotationLimit(e) {
  2799. var t = e.limitAxis,
  2800. r = e.limitRotation;
  2801. this._room.sceneManager.cameraComponent.setMainCameraRotationLimit(t, r);
  2802. }
  2803. }]);
  2804. return Camera;
  2805. }(EventEmitter);
  2806. 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); }; }
  2807. 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; } }
  2808. var numberFormat = new Intl.NumberFormat(window.navigator.language, {
  2809. maximumFractionDigits: 0
  2810. });
  2811. var Stats = /*#__PURE__*/function (_EventEmitter) {
  2812. _inherits(Stats, _EventEmitter);
  2813. var _super = _createSuper$9(Stats);
  2814. function Stats(e) {
  2815. var _this;
  2816. _classCallCheck(this, Stats);
  2817. _this = _super.call(this);
  2818. _this._netInterval = null;
  2819. _this._disabled = !1;
  2820. _this._show = !1;
  2821. _this._aggregatedStats = {};
  2822. _this._displayElement = null;
  2823. _this._extraStats = {};
  2824. _this._networkSamples = [];
  2825. _this.externalStats = null;
  2826. _this.constructedTime = null;
  2827. _this.room = e, _this.constructedTime = Date.now(), _this._interval = window.setInterval(function () {
  2828. var t, r, n;
  2829. _this._disabled || _this.onStats((n = (r = (t = e.networkController) == null ? void 0 : t.rtcp) == null ? void 0 : r.workers) == null ? void 0 : n.uploadDataToServer());
  2830. }, 1e3), _this._netInterval = window.setInterval(function () {
  2831. _this.getIsWeakNet();
  2832. }, NET_INTERVAL * 1e3);
  2833. return _this;
  2834. }
  2835. _createClass(Stats, [{
  2836. key: "isShow",
  2837. get: function get() {
  2838. return this._show;
  2839. }
  2840. }, {
  2841. key: "assign",
  2842. value: function assign(e) {
  2843. Object.assign(this._extraStats, e), ((e == null ? void 0 : e.hb) || (e == null ? void 0 : e.rtt)) && this.startStatsNetSamples();
  2844. }
  2845. }, {
  2846. key: "appendExternalStats",
  2847. value: function appendExternalStats(e) {
  2848. var _this2 = this;
  2849. var t = {};
  2850. if (!e || typeof e != "object") {
  2851. console.warn("appendExternalStats should be plain object");
  2852. return;
  2853. }
  2854. Object.keys(e).forEach(function (r) {
  2855. Object.prototype.hasOwnProperty.call(_this2._aggregatedStats, r) ? console.warn("".concat(r, " is duplicate with internal stats")) : t[r] = e[r];
  2856. }), !(Object.keys(t).length > 10) && (this.externalStats = t);
  2857. }
  2858. }, {
  2859. key: "getRtt",
  2860. value: function getRtt() {
  2861. var e = this._extraStats.rtt;
  2862. return typeof e != "number" ? 0 : e > 999 ? 999 : e;
  2863. }
  2864. }, {
  2865. key: "enable",
  2866. value: function enable() {
  2867. this._disabled = !1;
  2868. }
  2869. }, {
  2870. key: "disable",
  2871. value: function disable() {
  2872. this._disabled = !0;
  2873. }
  2874. }, {
  2875. key: "disableNet",
  2876. value: function disableNet() {
  2877. this._netInterval && window.clearInterval(this._netInterval);
  2878. }
  2879. }, {
  2880. key: "show",
  2881. value: function show() {
  2882. this._show = !0, this._render();
  2883. }
  2884. }, {
  2885. key: "hide",
  2886. value: function hide() {
  2887. this._show = !1, this._displayElement && document.body.removeChild(this._displayElement), this._displayElement = null;
  2888. }
  2889. }, {
  2890. key: "getIsWeakNet",
  2891. value: function getIsWeakNet() {
  2892. var _this3 = this;
  2893. var e = !1;
  2894. var t = this._networkSamples.length - 1;
  2895. if (t < 0) return;
  2896. var r = this._networkSamples[t].time,
  2897. n = this._networkSamples[0].time,
  2898. o = r - n,
  2899. a = 1e3 * (DURATION - 2);
  2900. if (o < a) return;
  2901. var s = this._networkSamples.map(function (g) {
  2902. return _this3.isNetDelay(g, "rtt");
  2903. }),
  2904. l = this._networkSamples.map(function (g) {
  2905. return _this3.isNetDelay(g, "hb");
  2906. }),
  2907. u = s.reduce(function (g, m) {
  2908. return g + m;
  2909. }, 0),
  2910. c = l.reduce(function (g, m) {
  2911. return g + m;
  2912. }, 0),
  2913. h = Math.floor(u / this._networkSamples.length) * 100,
  2914. f = Math.floor(c / this._networkSamples.length) * 100,
  2915. d = 70;
  2916. (h >= d || f >= d) && (e = !0);
  2917. var _ = this.room.viewMode === "observer" || this.room.viewMode === "serverless";
  2918. e && !_ && (logger.infoAndReportMeasurement({
  2919. metric: "weakNetwork",
  2920. startTime: Date.now(),
  2921. extra: {
  2922. msg: this._networkSamples.slice(20),
  2923. netDelayRTTValues: u,
  2924. netDelayHBValues: c
  2925. }
  2926. }), this.emit("weakNetwork"));
  2927. }
  2928. }, {
  2929. key: "startStatsNetSamples",
  2930. value: function startStatsNetSamples() {
  2931. var _this$_extraStats = this._extraStats,
  2932. e = _this$_extraStats.rtt,
  2933. t = _this$_extraStats.hb;
  2934. if (e || t) {
  2935. var r = {
  2936. rtt: e,
  2937. hb: t,
  2938. time: new Date().getTime()
  2939. };
  2940. this._networkSamples.push(r);
  2941. var n = this._networkSamples.length - 1;
  2942. if (n < 0) return;
  2943. var o = this._networkSamples[n].time,
  2944. a = 1e3 * DURATION;
  2945. this._networkSamples = this._networkSamples.filter(function (s) {
  2946. return s.time > o - a;
  2947. });
  2948. }
  2949. }
  2950. }, {
  2951. key: "isNetDelay",
  2952. value: function isNetDelay(e, t) {
  2953. return t === "rtt" ? e.rtt > RTT_MAX_VALUE ? 1 : 0 : t === "hb" && e.hb > HB_MAX_VALUE ? 1 : 0;
  2954. }
  2955. }, {
  2956. key: "getPreciesTimer",
  2957. value: function getPreciesTimer(e, t) {
  2958. var r = t * 1e3,
  2959. n = new Date().getTime();
  2960. var o = 0;
  2961. o++;
  2962. var a = new Date().getTime() - (n + o * 1e3),
  2963. s = r - a,
  2964. l = setTimeout(function () {
  2965. clearTimeout(l), e();
  2966. }, s);
  2967. }
  2968. }, {
  2969. key: "_render",
  2970. value: function _render() {
  2971. var c, h, f, d, _, g, m, v, y, b, T, C, A, S, P, R, M, x, I, w;
  2972. if (!this._aggregatedStats) return;
  2973. 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));
  2974. var e = [],
  2975. t = Date.now() - this.constructedTime,
  2976. r = Math.floor(t / 1e3 % 60),
  2977. n = Math.floor(t / (1e3 * 60) % 60),
  2978. o = Math.floor(t / (1e3 * 60 * 60) % 24),
  2979. a = o < 10 ? "0" + o.toString() : o.toString(),
  2980. s = n < 10 ? "0" + n : n,
  2981. l = r < 10 ? "0" + r : r;
  2982. e.push({
  2983. key: new Date(Math.floor(this._aggregatedStats.timestamp || 0)).toLocaleString("en-GB"),
  2984. value: a + ":" + s + ":" + l
  2985. }), e.push({
  2986. key: "rtt: " + this._extraStats.rtt + " hb: " + this._extraStats.hb,
  2987. value: "FPS: " + this._extraStats.fps + " avatar: " + ((c = this.room._userAvatar) == null ? void 0 : c.state)
  2988. }), e.push({
  2989. key: "SDK: " + Xverse$1.SUB_PACKAGE_VERSION,
  2990. value: "ENGINE:" + VERSION$1 + " uid:" + this._extraStats.userId
  2991. }), e.push({
  2992. key: "\u540C\u6B65/\u6709\u6548/\u663E\u793A\u73A9\u5BB6",
  2993. value: "".concat(this._extraStats.syncUserNum || 0, "/").concat(this._extraStats.userNum || 0, "/").concat(this._extraStats.renderedUserNum || 0)
  2994. }), e.push({
  2995. key: "media/meta bitrate(kbps)",
  2996. value: numberFormat.format(this._aggregatedStats.mediaBitrate || 0) + "/" + numberFormat.format(this._aggregatedStats.metaBitrate || 0)
  2997. }), e.push({
  2998. key: ":----------------Decoding---------------",
  2999. value: ""
  3000. }), e.push({
  3001. key: "-max/avg decodeTime(ms)",
  3002. value: numberFormat.format(this._aggregatedStats.decodeTimeMaxFrame || 0) + "/" + numberFormat.format(this._aggregatedStats.decodeTimePerFrame || 0)
  3003. }), e.push({
  3004. key: "-frmAwait/Lost/Drop",
  3005. 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
  3006. }), e.push({
  3007. key: ":----------------FrameLoop-------------",
  3008. value: ""
  3009. }), e.push({
  3010. key: "interval(max/avg/>40)",
  3011. 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
  3012. }), e.push({
  3013. key: "systemStuck",
  3014. value: this._extraStats.systemStuckCnt
  3015. }), e.push({
  3016. key: "--update",
  3017. value: (this._aggregatedStats.maxGraphicTime.toFixed(1) || 0) + "/" + (((d = this._aggregatedStats.averageGraphicTime) == null ? void 0 : d.toFixed(0)) || 0)
  3018. }), e.push({
  3019. key: "--timeout",
  3020. value: (((_ = this._extraStats.maxTimeoutTime) == null ? void 0 : _.toFixed(1)) || 0) + "/" + ((g = this._extraStats.avgTimeoutTime) == null ? void 0 : g.toFixed(0)) || 0
  3021. }), e.push({
  3022. key: "--render",
  3023. value: (((m = this._extraStats.maxRenderFrameTime) == null ? void 0 : m.toFixed(1)) || 0) + "/" + (((v = this._extraStats.renderFrameTime) == null ? void 0 : v.toFixed(0)) || 0)
  3024. }), e.push({
  3025. key: "---anim/regBR/clip(avg ms)",
  3026. value: (this._extraStats.animationTime.toFixed(2) || 0) + " / " + (this._extraStats.registerBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.meshSelectTime.toFixed(2) || 0)
  3027. }), e.push({
  3028. key: "---anim/regBR/clip(max ms)",
  3029. value: (this._extraStats.maxAnimationTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterBeforeRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxMeshSelectTime.toFixed(2) || 0)
  3030. }), e.push({
  3031. key: "---rTR/drC/regAF(avg ms)",
  3032. value: (this._extraStats.renderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.drawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.registerAfterRenderTime.toFixed(2) || 0)
  3033. }), e.push({
  3034. key: "---rTR/drC/regAF(max ms)",
  3035. value: (this._extraStats.maxRenderTargetRenderTime.toFixed(2) || 0) + " / " + (this._extraStats.maxDrawcallTime.toFixed(2) || 0) + " / " + (this._extraStats.maxRegisterAfterRenderTime.toFixed(2) || 0)
  3036. }), e.push({
  3037. key: "--tri/drC/pati/bones/anim(Num)",
  3038. 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)
  3039. }), e.push({
  3040. key: "--rootN/mesh/geo/tex/mat(Num)",
  3041. 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)
  3042. }), e.push({
  3043. key: "--registerBF/AF(Num)",
  3044. value: (this._extraStats.registerBeforeCount.toFixed(0) || 0) + " / " + (this._extraStats.registerAfterCount.toFixed(0) || 0)
  3045. }), e.push({
  3046. key: ":----------------Rotation-------------------",
  3047. value: ""
  3048. }), e.push({
  3049. key: "Total(ms/miss)",
  3050. value: (((y = this._aggregatedStats.avgOverallTime) == null ? void 0 : y.toFixed(2)) || 0) + "/" + (this._aggregatedStats.responseMissPs + this._aggregatedStats.processMissPs + this._aggregatedStats.displayMissPs)
  3051. }), e.push({
  3052. key: "--rotateRsp",
  3053. value: (((b = this._aggregatedStats.avgResponseTime) == null ? void 0 : b.toFixed(1)) || 0) + "/" + this._aggregatedStats.responseMissPs
  3054. }), e.push({
  3055. key: "--rotateProc",
  3056. value: (((T = this._aggregatedStats.avgProcessTime) == null ? void 0 : T.toFixed(1)) || 0) + "/" + this._aggregatedStats.processMissPs
  3057. }), e.push({
  3058. key: "--rotateShow",
  3059. value: (((C = this._aggregatedStats.avgDisplayTime) == null ? void 0 : C.toFixed(1)) || 0) + "/" + this._aggregatedStats.displayMissPs
  3060. }), ((A = this.room._userAvatar) == null ? void 0 : A.state) == "moving", e.push({
  3061. key: ":----------------Move----------------------",
  3062. value: ""
  3063. }), e.push({
  3064. key: "-startDelay",
  3065. 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)
  3066. }), (((S = this.room._userAvatar) == null ? void 0 : S.state) == "moving" || this._aggregatedStats.moveEvent == "GetOnAirship" || this._aggregatedStats.moveEvent == "GetOnVehicle") && e.push({
  3067. key: "-srvInterFrm(max/avg)",
  3068. value: (this._aggregatedStats.maxServerDiff || 0) + "/" + (this._aggregatedStats.avgServerDiff.toFixed(1) || 0)
  3069. }), e.push({
  3070. key: "-interFrameDelay",
  3071. value: "(max/avg/jank)"
  3072. }), e.push({
  3073. key: "--toDisplay",
  3074. 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)
  3075. }), e.push({
  3076. key: "--received",
  3077. 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)
  3078. }), e.push({
  3079. key: "--decoded",
  3080. 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)
  3081. }), e.push({
  3082. key: ":----------------DevInfo-----------------",
  3083. value: ""
  3084. }), e.push({
  3085. key: "sd",
  3086. value: (this._aggregatedStats.sdMoveResponseLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveProcessLongTime.toFixed(1) || 0) + "/" + (this._aggregatedStats.sdMoveDisplayLongTime.toFixed(1) || 0)
  3087. }), e.push({
  3088. key: "----hardwareInfo",
  3089. value: this._extraStats.hardwareInfo
  3090. });
  3091. var u = "";
  3092. for (var _i = 0, _e = e; _i < _e.length; _i++) {
  3093. var O = _e[_i];
  3094. u += "<div><span>".concat(O.key, "</span>: <span>").concat(O.value, "</span> </div>");
  3095. }
  3096. this._displayElement.innerHTML = u;
  3097. }
  3098. }, {
  3099. key: "onStats",
  3100. value: function onStats(e) {
  3101. var _this4 = this;
  3102. var n;
  3103. if (!e) return;
  3104. var t = {},
  3105. r = this;
  3106. 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) {
  3107. t[o] = _this4.externalStats[o];
  3108. }), r._aggregatedStats = t, this.emit("stats", {
  3109. stats: t
  3110. });
  3111. }
  3112. }]);
  3113. return Stats;
  3114. }(EventEmitter);
  3115. var Actions$1 = {
  3116. Clicking: 1,
  3117. PlayCG: 6,
  3118. Back: 7,
  3119. ChangeRoom: 8,
  3120. ChangeSkin: 13,
  3121. Joystick: 15,
  3122. Transfer: 18,
  3123. GetOnVehicle: 22,
  3124. GetOffVehicle: 23,
  3125. StopMoving: 34,
  3126. UnaryActionLine: 1e3,
  3127. Init: 1001,
  3128. Exit: 1002,
  3129. SetIFrameInfo: 1003,
  3130. GetNeighborPoints: 1004,
  3131. ReserveSeat: 1005,
  3132. GetReserveStatus: 1006,
  3133. ChangeNickname: 1007,
  3134. ChangeBitRateInfo: 1008,
  3135. Echo: 1009,
  3136. SetPlayerState: 1010,
  3137. TurnTo: 1011,
  3138. TurnToFace: 1012,
  3139. RotateTo: 1013,
  3140. Rotation: 1014,
  3141. CameraTurnTo: 1015,
  3142. ConfirmEvent: 1016,
  3143. Broadcast: 1017,
  3144. NotifyActionLine: 2e4,
  3145. AudienceChangeToVisitor: 1020,
  3146. VisitorChangeToAudience: 1021,
  3147. RemoveVisitor: 1022,
  3148. GetUserWithAvatar: 1023
  3149. };
  3150. var ActionsHandler = /*#__PURE__*/function () {
  3151. function ActionsHandler(e) {
  3152. _classCallCheck(this, ActionsHandler);
  3153. this.currentActiveAction = null;
  3154. this.room = e;
  3155. }
  3156. _createClass(ActionsHandler, [{
  3157. key: "avatarComponentsSync",
  3158. value: function () {
  3159. var _avatarComponentsSync = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  3160. var t;
  3161. return regenerator.wrap(function _callee$(_context) {
  3162. while (1) {
  3163. switch (_context.prev = _context.next) {
  3164. case 0:
  3165. t = {
  3166. action_type: Actions$1.SetPlayerState,
  3167. set_player_state_action: {
  3168. player_state: {
  3169. avatar_components: JSON.stringify(e)
  3170. }
  3171. }
  3172. };
  3173. this.sendData({
  3174. data: t
  3175. });
  3176. case 2:
  3177. case "end":
  3178. return _context.stop();
  3179. }
  3180. }
  3181. }, _callee, this);
  3182. }));
  3183. function avatarComponentsSync(_x) {
  3184. return _avatarComponentsSync.apply(this, arguments);
  3185. }
  3186. return avatarComponentsSync;
  3187. }()
  3188. }, {
  3189. key: "sendData",
  3190. value: function () {
  3191. var _sendData = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  3192. var _this = this;
  3193. var t, _e$sampleRate, r, _e$timeout, n, o, a, s;
  3194. return regenerator.wrap(function _callee2$(_context2) {
  3195. while (1) {
  3196. switch (_context2.prev = _context2.next) {
  3197. case 0:
  3198. _context2.next = 2;
  3199. return this.beforeSend(e);
  3200. case 2:
  3201. t = uuid$1();
  3202. if (!(this.room.networkController.sendRtcData(le(oe({}, e.data), {
  3203. trace_id: t,
  3204. user_id: this.room.options.userId
  3205. })), e.track === !1)) {
  3206. _context2.next = 5;
  3207. break;
  3208. }
  3209. return _context2.abrupt("return", Promise.resolve(null));
  3210. case 5:
  3211. _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;
  3212. return _context2.abrupt("return", eventsManager.track({
  3213. timeout: n,
  3214. traceId: t,
  3215. event: a.action_type,
  3216. tag: o,
  3217. extra: a
  3218. }, {
  3219. special: s,
  3220. sampleRate: r,
  3221. noReport: this.room.viewMode === "serverless" || this.room.options.viewMode === "serverless"
  3222. }).finally(function () {
  3223. QueueActions.includes(e.data.action_type) && (_this.currentActiveAction = void 0);
  3224. }));
  3225. case 7:
  3226. case "end":
  3227. return _context2.stop();
  3228. }
  3229. }
  3230. }, _callee2, this);
  3231. }));
  3232. function sendData(_x2) {
  3233. return _sendData.apply(this, arguments);
  3234. }
  3235. return sendData;
  3236. }()
  3237. }, {
  3238. key: "beforeSend",
  3239. value: function () {
  3240. var _beforeSend = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  3241. var o, t, r;
  3242. return regenerator.wrap(function _callee3$(_context3) {
  3243. while (1) {
  3244. switch (_context3.prev = _context3.next) {
  3245. case 0:
  3246. t = (o = this.room._userAvatar) == null ? void 0 : o.isMoving, r = e.data.action_type;
  3247. if (!QueueActions.includes(r)) {
  3248. _context3.next = 5;
  3249. break;
  3250. }
  3251. if (!this.currentActiveAction) {
  3252. _context3.next = 4;
  3253. break;
  3254. }
  3255. return _context3.abrupt("return", (log$p.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")))));
  3256. case 4:
  3257. this.currentActiveAction = r;
  3258. case 5:
  3259. if (!(t && QueueActions.includes(e.data.action_type))) {
  3260. _context3.next = 14;
  3261. break;
  3262. }
  3263. _context3.prev = 6;
  3264. _context3.next = 9;
  3265. return this.stopMoving();
  3266. case 9:
  3267. _context3.next = 14;
  3268. break;
  3269. case 11:
  3270. _context3.prev = 11;
  3271. _context3.t0 = _context3["catch"](6);
  3272. this.currentActiveAction = void 0, log$p.error("before action stopMoving failed", _context3.t0);
  3273. case 14:
  3274. case "end":
  3275. return _context3.stop();
  3276. }
  3277. }
  3278. }, _callee3, this, [[6, 11]]);
  3279. }));
  3280. function beforeSend(_x3) {
  3281. return _beforeSend.apply(this, arguments);
  3282. }
  3283. return beforeSend;
  3284. }()
  3285. }, {
  3286. key: "moveTo",
  3287. value: function () {
  3288. var _moveTo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  3289. var t, _e$extra, r, n, o;
  3290. return regenerator.wrap(function _callee4$(_context4) {
  3291. while (1) {
  3292. switch (_context4.prev = _context4.next) {
  3293. case 0:
  3294. t = e.point, _e$extra = e.extra, r = _e$extra === void 0 ? "" : _e$extra, n = e.motionType, o = {
  3295. action_type: Actions$1.Clicking,
  3296. clicking_action: {
  3297. clicking_point: t,
  3298. clicking_type: ClickType.IgnoreView,
  3299. extra: encodeURIComponent(r),
  3300. attitude: n
  3301. },
  3302. clicking_state: this.room._currentClickingState
  3303. };
  3304. return _context4.abrupt("return", this.sendData({
  3305. data: o
  3306. }));
  3307. case 2:
  3308. case "end":
  3309. return _context4.stop();
  3310. }
  3311. }
  3312. }, _callee4, this);
  3313. }));
  3314. function moveTo(_x4) {
  3315. return _moveTo.apply(this, arguments);
  3316. }
  3317. return moveTo;
  3318. }()
  3319. }, {
  3320. key: "transfer",
  3321. value: function transfer(e) {
  3322. var _this2 = this;
  3323. var t = e.renderType,
  3324. r = e.player,
  3325. n = e.camera,
  3326. o = e.areaName,
  3327. a = e.attitude,
  3328. s = e.pathName,
  3329. l = e.person,
  3330. u = e.noMedia,
  3331. c = e.timeout,
  3332. h = e.tag,
  3333. f = e.special,
  3334. d = {
  3335. data: {
  3336. action_type: Actions$1.Transfer,
  3337. transfer_action: {
  3338. render_type: t,
  3339. player: r,
  3340. camera: n,
  3341. areaName: o,
  3342. attitude: a,
  3343. pathName: s,
  3344. person: {
  3345. type: l
  3346. },
  3347. noMedia: u,
  3348. tiles: [0, 1, 2, 4]
  3349. }
  3350. },
  3351. special: f,
  3352. timeout: c || 4e3,
  3353. tag: h
  3354. };
  3355. return this.sendData(d).then(function (_) {
  3356. return typeof l != "undefined" && _this2.room.updateCurrentNetworkOptions({
  3357. person: l,
  3358. rotationRenderType: t
  3359. }), _;
  3360. });
  3361. }
  3362. }, {
  3363. key: "changeRotationRenderType",
  3364. value: function changeRotationRenderType(e) {
  3365. var t = e.renderType,
  3366. r = e.player,
  3367. n = e.camera,
  3368. o = e.areaName,
  3369. a = e.attitude,
  3370. s = e.pathName;
  3371. return this.transfer({
  3372. renderType: t,
  3373. player: r,
  3374. camera: n,
  3375. areaName: o,
  3376. attitude: a,
  3377. pathName: s,
  3378. tag: "changeToRotationVideo"
  3379. });
  3380. }
  3381. }, {
  3382. key: "requestPanorama",
  3383. value: function requestPanorama(e, t, r) {
  3384. var n = e.camera,
  3385. o = e.player,
  3386. a = e.areaName,
  3387. s = e.attitude,
  3388. l = e.pathName,
  3389. u = e.tag;
  3390. return this.transfer({
  3391. renderType: RenderType.ClientRotationPano,
  3392. player: o,
  3393. camera: n,
  3394. person: Person.First,
  3395. areaName: a,
  3396. attitude: s,
  3397. pathName: l,
  3398. noMedia: t,
  3399. timeout: r,
  3400. tag: u || "requestPanorama",
  3401. special: !t
  3402. });
  3403. }
  3404. }, {
  3405. key: "setMotionType",
  3406. value: function setMotionType(e) {
  3407. return this.transfer({
  3408. attitude: e,
  3409. tag: "setMotionType"
  3410. });
  3411. }
  3412. }, {
  3413. key: "setNickName",
  3414. value: function setNickName(e) {
  3415. var t = {
  3416. action_type: Actions$1.ChangeNickname,
  3417. change_nickname_action: {
  3418. nickname: e
  3419. }
  3420. };
  3421. return this.sendData({
  3422. data: t
  3423. });
  3424. }
  3425. }, {
  3426. key: "getReserveSeat",
  3427. value: function getReserveSeat(_ref) {
  3428. var e = _ref.routeId,
  3429. t = _ref.name;
  3430. var r = {
  3431. action_type: Actions$1.ReserveSeat,
  3432. reserve_seat_action: {
  3433. route_id: e,
  3434. name: t
  3435. }
  3436. };
  3437. return this.sendData({
  3438. data: r
  3439. });
  3440. }
  3441. }, {
  3442. key: "getReserveStatus",
  3443. value: function getReserveStatus(_ref2) {
  3444. var e = _ref2.routeId,
  3445. t = _ref2.name,
  3446. r = _ref2.need_detail;
  3447. var n = {
  3448. action_type: Actions$1.GetReserveStatus,
  3449. get_reserve_status_action: {
  3450. route_id: e,
  3451. name: t,
  3452. need_detail: r
  3453. }
  3454. };
  3455. return this.sendData({
  3456. data: n,
  3457. timeout: 2e3
  3458. }).then(function (o) {
  3459. return o.reserveDetail;
  3460. });
  3461. }
  3462. }, {
  3463. key: "stopMoving",
  3464. value: function stopMoving() {
  3465. var e = {
  3466. action_type: Actions$1.StopMoving,
  3467. stop_move_action: {}
  3468. };
  3469. return this.sendData({
  3470. data: e
  3471. });
  3472. }
  3473. }, {
  3474. key: "getOnVehicle",
  3475. value: function getOnVehicle(_ref3) {
  3476. var e = _ref3.routeId,
  3477. t = _ref3.name,
  3478. r = _ref3.camera;
  3479. var n = {
  3480. action_type: Actions$1.GetOnVehicle,
  3481. get_on_vehicle_action: {
  3482. route_id: e,
  3483. name: t,
  3484. camera: r
  3485. }
  3486. };
  3487. return this.sendData({
  3488. data: n
  3489. });
  3490. }
  3491. }, {
  3492. key: "getOffVehicle",
  3493. value: function getOffVehicle(_ref4) {
  3494. var e = _ref4.renderType,
  3495. t = _ref4.player,
  3496. r = _ref4.camera;
  3497. var n = {
  3498. action_type: Actions$1.GetOffVehicle,
  3499. get_off_vehicle_action: {
  3500. render_type: e,
  3501. player: t,
  3502. camera: r
  3503. }
  3504. };
  3505. return this.sendData({
  3506. data: n
  3507. });
  3508. }
  3509. }, {
  3510. key: "confirmEvent",
  3511. value: function confirmEvent(e) {
  3512. var t = {
  3513. action_type: Actions$1.ConfirmEvent,
  3514. confirm_event_action: {
  3515. id: e
  3516. }
  3517. };
  3518. return this.sendData({
  3519. data: t,
  3520. track: !1
  3521. });
  3522. }
  3523. }, {
  3524. key: "echo",
  3525. value: function echo(e) {
  3526. var t = {
  3527. action_type: Actions$1.Echo,
  3528. echo_msg: {
  3529. echoMsg: e
  3530. }
  3531. };
  3532. return this.sendData({
  3533. data: t,
  3534. track: !1
  3535. });
  3536. }
  3537. }, {
  3538. key: "changeSkin",
  3539. value: function () {
  3540. var _changeSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e) {
  3541. var _this3 = this;
  3542. var t, r, n, _e$landingType, o, a, s, l, u, c, h, f, d, _, _e$roomTypeId, g, m, y, v;
  3543. return regenerator.wrap(function _callee6$(_context6) {
  3544. while (1) {
  3545. switch (_context6.prev = _context6.next) {
  3546. case 0:
  3547. 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) {
  3548. return y.id === r;
  3549. })[0];
  3550. if (m) {
  3551. _context6.next = 4;
  3552. break;
  3553. }
  3554. y = "skin ".concat(r, " is invalid");
  3555. return _context6.abrupt("return", (log$p.error(y), Promise.reject(new ParamError(y))));
  3556. case 4:
  3557. v = {
  3558. action_type: Actions$1.ChangeSkin,
  3559. change_skin_action: {
  3560. skinID: r,
  3561. mode: n === ChangeMode.Preview ? ChangeMode.Preview : ChangeMode.Confirm,
  3562. skin_data_version: r + m.versionId,
  3563. landing_type: o,
  3564. landing_point: a,
  3565. landing_camera: s,
  3566. render_wrapper: {
  3567. render_type: l
  3568. },
  3569. areaName: u,
  3570. attitude: c,
  3571. noMedia: d,
  3572. person: f,
  3573. pathName: h,
  3574. roomTypeId: g
  3575. }
  3576. };
  3577. return _context6.abrupt("return", this.sendData({
  3578. data: v,
  3579. timeout: _ || 6e3,
  3580. special: t
  3581. }).then( /*#__PURE__*/function () {
  3582. var _ref5 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(y) {
  3583. var b, _ref6, T;
  3584. return regenerator.wrap(function _callee5$(_context5) {
  3585. while (1) {
  3586. switch (_context5.prev = _context5.next) {
  3587. case 0:
  3588. if (!(l === RenderType.ClientRotationPano && y)) {
  3589. _context5.next = 8;
  3590. break;
  3591. }
  3592. _context5.next = 3;
  3593. return _this3.room.modelManager.findRoute(r, h);
  3594. case 3:
  3595. b = _context5.sent;
  3596. _ref6 = getRandomItem(b.birthPointList) || {};
  3597. T = _ref6.camera;
  3598. _context5.next = 8;
  3599. return _this3.room.panorama.handleReceivePanorama(y, T);
  3600. case 8:
  3601. return _context5.abrupt("return", _this3.handleChangeSkin(e));
  3602. case 9:
  3603. case "end":
  3604. return _context5.stop();
  3605. }
  3606. }
  3607. }, _callee5);
  3608. }));
  3609. return function (_x6) {
  3610. return _ref5.apply(this, arguments);
  3611. };
  3612. }()).catch(function (y) {
  3613. return d ? _this3.handleChangeSkin(e) : Promise.reject(y);
  3614. }));
  3615. case 6:
  3616. case "end":
  3617. return _context6.stop();
  3618. }
  3619. }
  3620. }, _callee6, this);
  3621. }));
  3622. function changeSkin(_x5) {
  3623. return _changeSkin.apply(this, arguments);
  3624. }
  3625. return changeSkin;
  3626. }()
  3627. }, {
  3628. key: "handleChangeSkin",
  3629. value: function handleChangeSkin(e) {
  3630. var _this4 = this;
  3631. var t = e.skinId,
  3632. r = e.mode,
  3633. n = e.renderType,
  3634. o = e.areaName,
  3635. a = e.attitude,
  3636. s = e.pathName;
  3637. return this.room.sceneManager.staticmeshComponent.getCgMesh().show(), this.room.sceneManager.cameraComponent.switchToCgCamera(), this.room.engineProxy._updateSkinAssets(t).then(function () {
  3638. _this4.room.sceneManager.staticmeshComponent.getCgMesh().hide(), _this4.room.sceneManager.cameraComponent.switchToMainCamera(), _this4.room.pathManager.currentArea = o, log$p.info("changeSkin _updateSkinAssets susccss"), _this4.room.updateCurrentNetworkOptions({
  3639. pathName: s,
  3640. attitude: a,
  3641. areaName: o
  3642. }), _this4.room.skinChangedHook(), _this4.room.emit("skinChanged", {
  3643. skin: {
  3644. id: t
  3645. },
  3646. mode: r
  3647. }), n === RenderType.ClientRotationPano && _this4.room.sceneManager.cameraComponent.allowMainCameraController();
  3648. });
  3649. }
  3650. }, {
  3651. key: "rotate",
  3652. value: function rotate(_ref7) {
  3653. var e = _ref7.pitch,
  3654. t = _ref7.yaw;
  3655. var n;
  3656. if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode)) return;
  3657. var r = {
  3658. action_type: Actions$1.Rotation,
  3659. rotation_action: {
  3660. vertical_move: e,
  3661. horizontal_move: -t
  3662. }
  3663. };
  3664. this.sendData({
  3665. data: r,
  3666. sampleRate: .02
  3667. });
  3668. }
  3669. }, {
  3670. key: "turnTo",
  3671. value: function turnTo(e) {
  3672. var _ref8 = e || {},
  3673. t = _ref8.point,
  3674. _ref8$timeout = _ref8.timeout,
  3675. r = _ref8$timeout === void 0 ? 2e3 : _ref8$timeout,
  3676. _ref8$offset = _ref8.offset,
  3677. n = _ref8$offset === void 0 ? 8 : _ref8$offset,
  3678. o = {
  3679. action_type: Actions$1.TurnTo,
  3680. turn_to_action: {
  3681. turn_to_point: t,
  3682. offset: n
  3683. }
  3684. };
  3685. return this.sendData({
  3686. data: o,
  3687. timeout: r
  3688. });
  3689. }
  3690. }, {
  3691. key: "rotateTo",
  3692. value: function rotateTo(e) {
  3693. var _ref9 = e || {},
  3694. t = _ref9.point,
  3695. _ref9$offset = _ref9.offset,
  3696. r = _ref9$offset === void 0 ? 0 : _ref9$offset,
  3697. _ref9$speed = _ref9.speed,
  3698. n = _ref9$speed === void 0 ? 3 : _ref9$speed,
  3699. o = {
  3700. action_type: Actions$1.RotateTo,
  3701. rotate_to_action: {
  3702. rotate_to_point: t,
  3703. offset: r,
  3704. speed: n
  3705. }
  3706. };
  3707. return this.sendData({
  3708. data: o
  3709. });
  3710. }
  3711. }, {
  3712. key: "broadcast",
  3713. value: function broadcast(e) {
  3714. var t = e.data,
  3715. _e$msgType = e.msgType,
  3716. r = _e$msgType === void 0 ? MessageHandleType.MHT_FollowListMulticast : _e$msgType,
  3717. n = e.targetUserIds;
  3718. if (r === MessageHandleType.MHT_CustomTargetSync && !Array.isArray(n)) return Promise.reject(new ParamError("param targetUserIds is required when msgType is ".concat(MessageHandleType[r])));
  3719. var o = {
  3720. action_type: Actions$1.Broadcast,
  3721. broadcast_action: {
  3722. data: JSON.stringify(t),
  3723. user_id: this.room.options.userId,
  3724. msgType: r
  3725. }
  3726. };
  3727. return Array.isArray(n) && r === MessageHandleType.MHT_CustomTargetSync && (o.broadcast_action.target_user_ids = n), this.room.actionsHandler.sendData({
  3728. data: o,
  3729. tag: t.broadcastType
  3730. });
  3731. }
  3732. }, {
  3733. key: "getNeighborPoints",
  3734. value: function getNeighborPoints(e) {
  3735. var t = e.point,
  3736. _e$containSelf = e.containSelf,
  3737. r = _e$containSelf === void 0 ? !1 : _e$containSelf,
  3738. _e$searchRange = e.searchRange,
  3739. n = _e$searchRange === void 0 ? 500 : _e$searchRange,
  3740. o = {
  3741. action_type: Actions$1.GetNeighborPoints,
  3742. get_neighbor_points_action: {
  3743. point: t,
  3744. level: 1,
  3745. containSelf: r,
  3746. searchRange: n
  3747. }
  3748. };
  3749. return this.sendData({
  3750. data: o
  3751. }).then(function (a) {
  3752. return a.nps;
  3753. });
  3754. }
  3755. }, {
  3756. key: "playCG",
  3757. value: function playCG(e) {
  3758. var t = {
  3759. action_type: Actions$1.PlayCG,
  3760. play_cg_action: {
  3761. cg_name: e
  3762. }
  3763. };
  3764. return this.sendData({
  3765. data: t
  3766. });
  3767. }
  3768. }, {
  3769. key: "audienceToVisitor",
  3770. value: function audienceToVisitor(e) {
  3771. var t = e.avatarId,
  3772. r = e.avatarComponents,
  3773. n = e.player,
  3774. o = e.camera,
  3775. a = {
  3776. action_type: Actions$1.AudienceChangeToVisitor,
  3777. audienceChangeToVisitorAction: {
  3778. avatarID: t,
  3779. avatarComponents: r,
  3780. player: n,
  3781. camera: o
  3782. }
  3783. };
  3784. return log$p.debug("send data: audience to visitor"), this.sendData({
  3785. data: a
  3786. });
  3787. }
  3788. }, {
  3789. key: "visitorToAudience",
  3790. value: function visitorToAudience(e) {
  3791. var t = e.renderType,
  3792. r = e.player,
  3793. n = e.camera,
  3794. o = e.areaName,
  3795. a = e.attitude,
  3796. s = e.pathName,
  3797. l = e.person,
  3798. u = e.noMedia,
  3799. c = {
  3800. action_type: Actions$1.VisitorChangeToAudience,
  3801. visitorChangeToAudienceAction: {
  3802. transferAction: {
  3803. render_type: t,
  3804. player: r,
  3805. camera: n,
  3806. areaName: o,
  3807. attitude: a,
  3808. pathName: s,
  3809. person: {
  3810. type: l
  3811. },
  3812. noMedia: u,
  3813. tiles: [0, 1, 2, 4]
  3814. }
  3815. }
  3816. };
  3817. return log$p.debug("send data: visitor to audience"), this.sendData({
  3818. data: c
  3819. });
  3820. }
  3821. }, {
  3822. key: "removeVisitor",
  3823. value: function removeVisitor(e) {
  3824. var t = e.removeType,
  3825. r = e.userIDList,
  3826. _e$extraInfo = e.extraInfo,
  3827. n = _e$extraInfo === void 0 ? "" : _e$extraInfo,
  3828. o = {
  3829. action_type: Actions$1.RemoveVisitor,
  3830. removeVisitorAction: {
  3831. removeVisitorEvent: t,
  3832. userIDList: r,
  3833. extraInfo: encodeURIComponent(n)
  3834. }
  3835. };
  3836. return log$p.debug("send data: remove visitor"), this.sendData({
  3837. data: o
  3838. });
  3839. }
  3840. }, {
  3841. key: "getUserWithAvatar",
  3842. value: function getUserWithAvatar(e, t) {
  3843. var r = {
  3844. action_type: Actions$1.GetUserWithAvatar,
  3845. getUserWithAvatarAction: {
  3846. userType: e,
  3847. roomID: t
  3848. }
  3849. };
  3850. return log$p.debug("send data: get user with avatar"), this.sendData({
  3851. data: r
  3852. }).then(function (n) {
  3853. return n.userWithAvatarList;
  3854. });
  3855. }
  3856. }, {
  3857. key: "joystick",
  3858. value: function joystick(e) {
  3859. var t = e.degree,
  3860. _e$level = e.level,
  3861. r = _e$level === void 0 ? 1 : _e$level,
  3862. n = uuid$1();
  3863. var o = -t + 90 + 360;
  3864. o >= 360 && (o -= 360);
  3865. var a = {
  3866. action_type: Actions$1.Joystick,
  3867. dir_action: {
  3868. move_angle: o,
  3869. speed_level: r
  3870. },
  3871. trace_id: n,
  3872. user_id: this.room.options.userId,
  3873. packet_id: n
  3874. };
  3875. return this.sendData({
  3876. data: a,
  3877. track: !1
  3878. });
  3879. }
  3880. }]);
  3881. return ActionsHandler;
  3882. }();
  3883. var Signal = /*#__PURE__*/function () {
  3884. function Signal(e) {
  3885. _classCallCheck(this, Signal);
  3886. this.signalHandleActived = !0;
  3887. this.isUpdatedYUV = !0;
  3888. this._room = e;
  3889. }
  3890. _createClass(Signal, [{
  3891. key: "handleSignal",
  3892. value: function handleSignal(e) {
  3893. var _this = this;
  3894. var a, s, l;
  3895. if (!this.signalHandleActived) return;
  3896. var t = e.signal,
  3897. r = e.alreadyUpdateYUV;
  3898. if (this.handleActionResponses(t), this._room.handleSignalHook(t), !r) {
  3899. var u = (a = t.newUserStates) == null ? void 0 : a.find(function (c) {
  3900. return c.userId === _this._room.userId;
  3901. });
  3902. if ((u == null ? void 0 : u.renderInfo) && ((s = this._room._userAvatar) == null ? void 0 : s.isMoving)) {
  3903. logger.debug("stream stoped, make avatar to stop");
  3904. var _u$renderInfo = u.renderInfo,
  3905. c = _u$renderInfo.isMoving,
  3906. h = _u$renderInfo.isRotating;
  3907. this._room.avatarManager._updateAvatarMovingStatus({
  3908. id: u.userId,
  3909. isMoving: !!c,
  3910. isRotating: !!h
  3911. });
  3912. }
  3913. return;
  3914. }
  3915. this.isUpdatedYUV = r;
  3916. var n = t;
  3917. if (!t) {
  3918. logger.warn("metadata signal is empty");
  3919. return;
  3920. }
  3921. if (n.code === Codes.RepeatLogin) {
  3922. this._room.handleRepetLogin();
  3923. return;
  3924. }
  3925. n.code !== void 0 && n.code !== Codes.Success && n.code !== Codes.ActionMaybeDelay && n.code !== Codes.DoActionBlocked && n.code !== Codes.GetOnVehicle && (logger.error("signal errcode: ", n), this._room.emit("error", n));
  3926. var o = (l = n.newUserStates) == null ? void 0 : l.find(function (u) {
  3927. return u.userId === _this._room.userId;
  3928. });
  3929. if (n.broadcastAction) try {
  3930. var _u = JSON.parse(n.broadcastAction.data);
  3931. Broadcast.handlers.forEach(function (c) {
  3932. return c(_u);
  3933. });
  3934. } catch (u) {
  3935. logger.error(u);
  3936. }
  3937. if (n.newUserStates && n.newUserStates.length > 0 && this._room.avatarManager.handleAvatar(n), o != null && o.playerState) {
  3938. this._room._currentClickingState = o.playerState;
  3939. var _o$playerState = o.playerState,
  3940. _u2 = _o$playerState.pathName,
  3941. _c = _o$playerState.attitude,
  3942. _h = _o$playerState.areaName,
  3943. f = _o$playerState.skinId;
  3944. if (_u2 && (this._room.pathManager.currentPathName = _u2, this._room.updateCurrentState({
  3945. pathName: _u2
  3946. })), f && this.udpateSkinInfo(f), _h && this._room.updateCurrentState({
  3947. areaName: _h
  3948. }), _c) {
  3949. var d = this._room.skin.routeList.find(function (g) {
  3950. return g.areaName === _this._room.currentState.areaName;
  3951. }),
  3952. _ = ((d == null ? void 0 : d.step) || 7.5) * 30;
  3953. this._room.updateCurrentState({
  3954. speed: _,
  3955. attitude: _c
  3956. }), this._room.pathManager.currentAttitude = _c, this._room._userAvatar && (this._room._userAvatar.motionType = _c);
  3957. }
  3958. this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano && !this._room.isPano && o.playerState.camera && this._room.camera.setCameraPose(o.playerState.camera);
  3959. }
  3960. if (o != null && o.renderInfo && this._room.camera.handleRenderInfo(o), n.actionType !== void 0) {
  3961. var _u3 = n.actionType,
  3962. _c2 = n.code,
  3963. _h2 = n.echoMsg,
  3964. _f = n.traceId;
  3965. _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);
  3966. }
  3967. }
  3968. }, {
  3969. key: "handleActionResponses",
  3970. value: function handleActionResponses(e) {
  3971. var _this2 = this;
  3972. !(e != null && e.actionResponses) || e.actionResponses.length === 0 || e.actionResponses.forEach(function (t) {
  3973. if (t.actionType == null) return;
  3974. var r = t.pointType,
  3975. n = t.extra,
  3976. o = t.actionType,
  3977. a = t.traceId,
  3978. s = t.code,
  3979. l = t.msg;
  3980. 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));
  3981. });
  3982. }
  3983. }, {
  3984. key: "udpateSkinInfo",
  3985. value: function () {
  3986. var _udpateSkinInfo = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  3987. var t;
  3988. return regenerator.wrap(function _callee$(_context) {
  3989. while (1) {
  3990. switch (_context.prev = _context.next) {
  3991. case 0:
  3992. this._room.updateCurrentState({
  3993. skinId: e
  3994. });
  3995. _context.next = 3;
  3996. return this._room.skinList.find(function (r) {
  3997. return r.id === e;
  3998. });
  3999. case 3:
  4000. t = _context.sent;
  4001. t && this._room.updateCurrentState({
  4002. skin: t
  4003. });
  4004. case 5:
  4005. case "end":
  4006. return _context.stop();
  4007. }
  4008. }
  4009. }, _callee, this);
  4010. }));
  4011. function udpateSkinInfo(_x) {
  4012. return _udpateSkinInfo.apply(this, arguments);
  4013. }
  4014. return udpateSkinInfo;
  4015. }()
  4016. }]);
  4017. return Signal;
  4018. }();
  4019. 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); }; }
  4020. 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; } }
  4021. var ParamError$1 = /*#__PURE__*/function (_XverseError) {
  4022. _inherits(ParamError, _XverseError);
  4023. var _super = _createSuper$8(ParamError);
  4024. function ParamError(e) {
  4025. _classCallCheck(this, ParamError);
  4026. return _super.call(this, 1001, e || "\u53C2\u6570\u9519\u8BEF");
  4027. }
  4028. return _createClass(ParamError);
  4029. }(XverseError);
  4030. var MotionType$1 = {
  4031. Walk: 'walk',
  4032. Run: 'run',
  4033. Fly: 'fly'
  4034. };
  4035. var Heartbeat = /*#__PURE__*/function () {
  4036. function Heartbeat(e) {
  4037. _classCallCheck(this, Heartbeat);
  4038. this._interval = null;
  4039. this.handler = e;
  4040. }
  4041. _createClass(Heartbeat, [{
  4042. key: "ping",
  4043. value: function ping() {
  4044. var e = Date.now().toString();
  4045. this.handler.ping(e);
  4046. }
  4047. }, {
  4048. key: "start",
  4049. value: function start() {
  4050. this.stop(), logger.debug("Setting ping interval to ".concat(PING_INTERVAL_MS, "ms")), this._interval = window.setInterval(this.ping, PING_INTERVAL_MS);
  4051. }
  4052. }, {
  4053. key: "stop",
  4054. value: function stop() {
  4055. logger.debug("stop heartbeat"), this._interval && window.clearInterval(this._interval);
  4056. }
  4057. }, {
  4058. key: "pong",
  4059. value: function pong(e, t) {
  4060. !e || typeof e == "string" && this.handler.pong(Date.now() - Number(e), t);
  4061. }
  4062. }]);
  4063. return Heartbeat;
  4064. }();
  4065. var Timeout$1 = /*#__PURE__*/function () {
  4066. function Timeout(e, t) {
  4067. var r = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !0;
  4068. _classCallCheck(this, Timeout);
  4069. this._timeout = null;
  4070. this._fn = e, this._delay = t, r && this.start();
  4071. }
  4072. _createClass(Timeout, [{
  4073. key: "delay",
  4074. get: function get() {
  4075. return this._delay;
  4076. }
  4077. }, {
  4078. key: "isSet",
  4079. get: function get() {
  4080. return !!this._timeout;
  4081. }
  4082. }, {
  4083. key: "setDelay",
  4084. value: function setDelay(e) {
  4085. this._delay = e;
  4086. }
  4087. }, {
  4088. key: "start",
  4089. value: function start() {
  4090. var _this = this;
  4091. this.isSet || (this._timeout = window.setTimeout(function () {
  4092. var e = _this._fn;
  4093. _this.clear(), e();
  4094. }, this._delay));
  4095. }
  4096. }, {
  4097. key: "clear",
  4098. value: function clear() {
  4099. window.clearTimeout(this._timeout), this._timeout = void 0;
  4100. }
  4101. }, {
  4102. key: "reset",
  4103. value: function reset() {
  4104. this.clear(), this.start();
  4105. }
  4106. }]);
  4107. return Timeout;
  4108. }();
  4109. 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); }; }
  4110. 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; } }
  4111. var InitNetworkTimeoutError = /*#__PURE__*/function (_XverseError) {
  4112. _inherits(InitNetworkTimeoutError, _XverseError);
  4113. var _super = _createSuper$7(InitNetworkTimeoutError);
  4114. function InitNetworkTimeoutError(e) {
  4115. _classCallCheck(this, InitNetworkTimeoutError);
  4116. return _super.call(this, 1007, e || "\u7F51\u7EDC\u521D\u59CB\u5316\u8D85\u65F6");
  4117. }
  4118. return _createClass(InitNetworkTimeoutError);
  4119. }(XverseError);
  4120. 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); }; }
  4121. 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; } }
  4122. var Socket = /*#__PURE__*/function (_EventEmitter) {
  4123. _inherits(Socket, _EventEmitter);
  4124. var _super = _createSuper$6(Socket);
  4125. function Socket(e) {
  4126. var _this;
  4127. _classCallCheck(this, Socket);
  4128. _this = _super.call(this);
  4129. _this._ws = null;
  4130. _this._openTimer = null;
  4131. _this.connected = !1;
  4132. _this._hasTimeout = !1;
  4133. _this.heartbeat = null;
  4134. _this.network = e, _this.heartbeat = new Heartbeat({
  4135. ping: function ping(t) {
  4136. var r;
  4137. if (!_this.connected) {
  4138. _this.heartbeat.stop(), (r = e.room.stats) == null || r.assign({
  4139. rtt: 0
  4140. });
  4141. return;
  4142. }
  4143. _this.send({
  4144. id: "heartbeat",
  4145. data: t
  4146. });
  4147. },
  4148. pong(t) {
  4149. var r;
  4150. (r = e.room.stats) == null || r.assign({
  4151. rtt: t
  4152. });
  4153. }
  4154. });
  4155. return _this;
  4156. }
  4157. _createClass(Socket, [{
  4158. key: "latency",
  4159. value: function latency(e, t) {
  4160. this.send({
  4161. id: "checkLatency",
  4162. data: JSON.stringify(e),
  4163. packet_id: t
  4164. });
  4165. }
  4166. }, {
  4167. key: "send",
  4168. value: function send(e) {
  4169. if (this.wsNoReady()) return;
  4170. var t = JSON.stringify(e);
  4171. e.id !== "heartbeat" && logger.info("send ws frame", t), this._ws.send(t);
  4172. }
  4173. }, {
  4174. key: "startGame",
  4175. value: function startGame() {
  4176. var _this$network$room$cu = this.network.room.currentNetworkOptions,
  4177. e = _this$network$room$cu.roomId,
  4178. t = _this$network$room$cu.userId,
  4179. r = _this$network$room$cu.avatarId,
  4180. n = _this$network$room$cu.skinId,
  4181. o = _this$network$room$cu.role,
  4182. a = _this$network$room$cu.avatarComponents,
  4183. s = _this$network$room$cu.versionId,
  4184. l = _this$network$room$cu.rotationRenderType,
  4185. u = _this$network$room$cu.isAllSync,
  4186. c = _this$network$room$cu.nickname,
  4187. h = _this$network$room$cu.avatarScale,
  4188. f = _this$network$room$cu.appId,
  4189. d = _this$network$room$cu.camera,
  4190. _ = _this$network$room$cu.player,
  4191. g = _this$network$room$cu.firends,
  4192. m = _this$network$room$cu.syncByEvent,
  4193. v = _this$network$room$cu.areaName,
  4194. y = _this$network$room$cu.attitude,
  4195. b = _this$network$room$cu.pathName,
  4196. T = _this$network$room$cu.person,
  4197. _this$network$room$cu2 = _this$network$room$cu.roomTypeId,
  4198. C = _this$network$room$cu2 === void 0 ? "" : _this$network$room$cu2,
  4199. A = _this$network$room$cu.syncToOthers,
  4200. S = _this$network$room$cu.hasAvatar,
  4201. P = _this$network$room$cu.prioritySync,
  4202. _this$network$room$cu3 = _this$network$room$cu.extra,
  4203. R = _this$network$room$cu3 === void 0 ? {} : _this$network$room$cu3,
  4204. M = _this$network$room$cu.removeWhenDisconnected;
  4205. R.removeWhenDisconnected = M;
  4206. var x = {
  4207. id: "start",
  4208. room_id: e,
  4209. user_id: t,
  4210. trace_id: uuid$1(),
  4211. data: JSON.stringify({
  4212. avatar_components: JSON.stringify(a),
  4213. avatar_id: r,
  4214. skin_id: n,
  4215. is_host: o ? o == "host" : !0,
  4216. skin_data_version: n !== void 0 && s !== void 0 ? n + s : void 0,
  4217. rotation_render_type: l,
  4218. is_all_sync: u,
  4219. nick_name: encodeURIComponent(c || ""),
  4220. app_id: f,
  4221. camera: d,
  4222. player: _,
  4223. person: T,
  4224. firends: JSON.stringify(g),
  4225. sync_by_event: m,
  4226. area_name: v,
  4227. path_name: b,
  4228. attitude: y,
  4229. room_type_id: C,
  4230. syncToOthers: A,
  4231. hasAvatar: S,
  4232. avatarSize: h,
  4233. prioritySync: P,
  4234. extra: JSON.stringify(R)
  4235. })
  4236. };
  4237. this.send(x), logger.warn("startGame", le(oe({}, x), {
  4238. data: JSON.parse(x.data)
  4239. }));
  4240. }
  4241. }, {
  4242. key: "connection",
  4243. get: function get() {
  4244. return this._ws;
  4245. }
  4246. }, {
  4247. key: "start",
  4248. value: function start() {
  4249. var _this2 = this;
  4250. this._hasTimeout = !1;
  4251. var e = this.getAddress();
  4252. logger.info("connecting to ".concat(e));
  4253. var t = Date.now();
  4254. this._ws = new WebSocket(e), this._openTimer = new Timeout$1(function () {
  4255. var r = "Failed to open websocket in ".concat(DEFAULT_OPEN_TIMEOUT_MS, " ms");
  4256. _this2._hasTimeout = !0, _this2.emit("socketClosed", new InitNetworkTimeoutError(r));
  4257. }, DEFAULT_OPEN_TIMEOUT_MS), this._ws.onopen = function () {
  4258. var r;
  4259. (r = _this2._openTimer) == null || r.clear(), _this2.connected = !0, _this2.heartbeat.start(), _this2.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
  4260. metric: "wsOpenedAt",
  4261. group: "joinRoom",
  4262. startTime: _this2.network.room._startTime
  4263. }), logger.infoAndReportMeasurement({
  4264. metric: "wsOpenedCost",
  4265. group: "joinRoom",
  4266. startTime: t
  4267. }));
  4268. }, this.handleWSEvent();
  4269. }
  4270. }, {
  4271. key: "getAddress",
  4272. value: function getAddress() {
  4273. var _this$network$room$cu4 = this.network.room.currentNetworkOptions,
  4274. e = _this$network$room$cu4.wsServerUrl,
  4275. t = _this$network$room$cu4.reconnect,
  4276. r = _this$network$room$cu4.sessionId,
  4277. n = _this$network$room$cu4.token,
  4278. o = _this$network$room$cu4.roomId,
  4279. a = _this$network$room$cu4.userId,
  4280. s = _this$network$room$cu4.pageSession,
  4281. l = this.network.room.skinId;
  4282. var u = e;
  4283. t && (u = u + "?reconnect=true&lastSessionID=".concat(r));
  4284. var c = "userId=".concat(a, "&roomId=").concat(o, "&pageSession=").concat(s) + (this.network.room.isHost ? "&skinId=".concat(l) : "") + (n ? "&token=".concat(n) : "");
  4285. return u = u.indexOf("?") > -1 ? u + "&" + c : u + "?" + c, u;
  4286. }
  4287. }, {
  4288. key: "handleWSEvent",
  4289. value: function handleWSEvent() {
  4290. var _this3 = this;
  4291. var e = this._ws;
  4292. e.addEventListener("error", function (t) {
  4293. _this3.connected = !1, logger.error("webscoket error", t), _this3.emit("socketClosed", new InternalError("connect to address error: " + _this3.network.room.currentNetworkOptions.wsServerUrl));
  4294. }), e.addEventListener("close", function (t) {
  4295. _this3.connected = !1, _this3._onClose(t);
  4296. }), e.addEventListener("message", function (t) {
  4297. if (!t || _this3._hasTimeout || !_this3.connected) return;
  4298. var r = null;
  4299. try {
  4300. r = JSON.parse(t.data);
  4301. } catch (o) {
  4302. logger.error(o);
  4303. return;
  4304. }
  4305. if (!r) return;
  4306. var n = r.id;
  4307. if (!!n) switch (n !== "heartbeat" && logger.info("receive ws frame: ".concat(t.data)), n) {
  4308. case "fail":
  4309. break;
  4310. case "init":
  4311. try {
  4312. var o = r.data.slice(-37, -1);
  4313. reporter$1.updateBody({
  4314. serverSession: o
  4315. });
  4316. } catch (o) {
  4317. console.error(o);
  4318. }
  4319. _this3.network.rtcp.start();
  4320. break;
  4321. case "heartbeat":
  4322. _this3.heartbeat.pong(r.data);
  4323. break;
  4324. case "offer":
  4325. _this3.network.rtcp.setRemoteDescription(r.data, _this3.network.stream.el);
  4326. break;
  4327. case "ice_candidate":
  4328. _this3.network.rtcp.addCandidate(r.data);
  4329. break;
  4330. case "start":
  4331. _this3.emit("gameRoomAvailable", r);
  4332. break;
  4333. case "error":
  4334. try {
  4335. var _JSON$parse = JSON.parse(r.data),
  4336. _o = _JSON$parse.Code,
  4337. a = _JSON$parse.Msg;
  4338. if (_o) {
  4339. if (_o == 3003) return _this3.emit("socketClosed", new TokenExpiredError());
  4340. if (authenticationErrorCodes.indexOf(_o) > -1) return _this3.emit("socketClosed", new AuthenticationError("\u9274\u6743\u9519\u8BEF:" + a));
  4341. {
  4342. var s = getErrorByCode(_o);
  4343. _this3.emit("socketClosed", new s(a));
  4344. }
  4345. }
  4346. } catch (o) {
  4347. logger.error(o), _this3.emit("socketClosed", new InternalError(r.data));
  4348. }
  4349. break;
  4350. case "checkLatency":
  4351. {
  4352. var _o2 = r.packet_id,
  4353. _a = r.data.split(",");
  4354. _this3.onLatencyCheck({
  4355. packetId: _o2,
  4356. addresses: _a
  4357. });
  4358. break;
  4359. }
  4360. default:
  4361. logger.warn("unkown ws message type", n, r);
  4362. }
  4363. });
  4364. }
  4365. }, {
  4366. key: "onLatencyCheck",
  4367. value: function onLatencyCheck(e) {
  4368. var _this4 = this;
  4369. var t = _toConsumableArray(new Set(e.addresses || []));
  4370. Promise.all(t.map(function (r) {
  4371. return {
  4372. [r]: 9999
  4373. };
  4374. })).then(function (r) {
  4375. var n = Object.assign.apply(Object, [{}].concat(_toConsumableArray(r)));
  4376. _this4.latency(n, e.packetId);
  4377. });
  4378. }
  4379. }, {
  4380. key: "wsNoReady",
  4381. value: function wsNoReady() {
  4382. return this._ws.readyState == WebSocket.CLOSED || this._ws.readyState == WebSocket.CLOSING || this._ws.readyState == WebSocket.CONNECTING;
  4383. }
  4384. }, {
  4385. key: "prepareReconnect",
  4386. value: function prepareReconnect() {
  4387. this._close({
  4388. code: WS_CLOSE_RECONNECT,
  4389. reason: "reconnect"
  4390. });
  4391. }
  4392. }, {
  4393. key: "_onClose",
  4394. value: function _onClose(_ref) {
  4395. var e = _ref.code,
  4396. t = _ref.reason;
  4397. this._openTimer && this._openTimer.clear(), logger.warn("ws closed: ".concat(e, " ") + t), [WS_CLOSE_RECONNECT, WS_CLOSE_NORMAL].includes(e) || this.emit("socketClosed", new InternalError("Websocket error"));
  4398. }
  4399. }, {
  4400. key: "_close",
  4401. value: function _close(_ref2) {
  4402. var e = _ref2.code,
  4403. t = _ref2.reason;
  4404. var r;
  4405. (r = this._ws) == null || r.close(e, t);
  4406. }
  4407. }, {
  4408. key: "quit",
  4409. value: function quit() {
  4410. this._close({
  4411. code: WS_CLOSE_NORMAL,
  4412. reason: "quit"
  4413. });
  4414. }
  4415. }]);
  4416. return Socket;
  4417. }(EventEmitter);
  4418. function add(i, e) {
  4419. return e == -1 && (e = 0), i + e;
  4420. }
  4421. function max(i, e) {
  4422. return Math.max(i, e);
  4423. }
  4424. function count_sd(i, e) {
  4425. function t(r, n) {
  4426. var o = 0;
  4427. return n == -1 ? o = 0 : o = (n - e) * (n - e), r + o;
  4428. }
  4429. return Math.sqrt(i.reduce(t, 0) / i.reduce(count_valid, 0)) || 0;
  4430. }
  4431. function count_valid(i, e) {
  4432. var t = 0;
  4433. return e != -1 && (t = 1), i + t;
  4434. }
  4435. function count_less(i, e) {
  4436. function t(r, n) {
  4437. var o = 0;
  4438. return n != -1 && n < e && (o = 1), r + o;
  4439. }
  4440. return i.reduce(t, 0);
  4441. }
  4442. var CircularArray = /*#__PURE__*/function () {
  4443. function CircularArray(e, t, r) {
  4444. _classCallCheck(this, CircularArray);
  4445. 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);
  4446. }
  4447. _createClass(CircularArray, [{
  4448. key: "add",
  4449. value: function add(e) {
  4450. 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);
  4451. }
  4452. }, {
  4453. key: "computeAvg",
  4454. value: function computeAvg(e) {
  4455. return e.reduce(add, 0) / e.reduce(count_valid, 0) || 0;
  4456. }
  4457. }, {
  4458. key: "computeMax",
  4459. value: function computeMax(e) {
  4460. return e.reduce(max, 0) || 0;
  4461. }
  4462. }, {
  4463. key: "computeThreshPercent",
  4464. value: function computeThreshPercent(e) {
  4465. if (this.countLess) {
  4466. var t = count_less(e, this.lessThreshes[0]) || 0,
  4467. r = count_less(e, this.lessThreshes[1]) || 0,
  4468. n = count_less(e, this.lessThreshes[2]) || 0,
  4469. o = count_less(e, this.lessThreshes[3]) || 0,
  4470. a = e.reduce(count_valid, 0);
  4471. return [t, r, n, o, a];
  4472. } else return [0, 0, 0, 0, 0];
  4473. }
  4474. }, {
  4475. key: "getAvg",
  4476. value: function getAvg() {
  4477. var e = this.sum / this.count || 0,
  4478. t = this.computeAvg(this.circularData) || 0;
  4479. return Math.abs(e - t) > .01 && console.error("avg value mismatch: ", e, t), this.computeAvg(this.circularData) || 0;
  4480. }
  4481. }, {
  4482. key: "getMax",
  4483. value: function getMax() {
  4484. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !0;
  4485. var t = this.computeMax(this.circularData) || 0;
  4486. return e && Math.abs(t - this.max) > .01 && console.error("max value mismatch: ", this.max, t), this.computeMax(this.circularData) || 0;
  4487. }
  4488. }, {
  4489. key: "getStandardDeviation",
  4490. value: function getStandardDeviation() {
  4491. return count_sd(this.circularData, this.getAvg());
  4492. }
  4493. }, {
  4494. key: "getThreshPercent",
  4495. value: function getThreshPercent() {
  4496. return this.computeThreshPercent(this.circularData);
  4497. }
  4498. }, {
  4499. key: "getIncomingMax",
  4500. value: function getIncomingMax() {
  4501. return this.computeMax(this.incomingData) || 0;
  4502. }
  4503. }, {
  4504. key: "getIncomingAvg",
  4505. value: function getIncomingAvg() {
  4506. return this.computeAvg(this.incomingData) || 0;
  4507. }
  4508. }, {
  4509. key: "getIncomingStandardDeviation",
  4510. value: function getIncomingStandardDeviation() {
  4511. return count_sd(this.incomingData, this.getIncomingAvg());
  4512. }
  4513. }, {
  4514. key: "getIncomingThreshPercent",
  4515. value: function getIncomingThreshPercent() {
  4516. return this.computeThreshPercent(this.incomingData);
  4517. }
  4518. }, {
  4519. key: "clearFastComputeItem",
  4520. value: function clearFastComputeItem() {
  4521. 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;
  4522. }
  4523. }, {
  4524. key: "clearIncoming",
  4525. value: function clearIncoming() {
  4526. for (; this.incomingData.length > 0;) {
  4527. this.incomingData.pop();
  4528. }
  4529. }
  4530. }, {
  4531. key: "clear",
  4532. value: function clear() {
  4533. this.circularData.fill(-1), this.circularPtr = 0, this.clearFastComputeItem(), this.clearIncoming();
  4534. }
  4535. }]);
  4536. return CircularArray;
  4537. }();
  4538. 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; } } }; }
  4539. 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); }
  4540. 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; }
  4541. var defaultLogger = {
  4542. info: console.log,
  4543. debug: console.log,
  4544. error: console.error,
  4545. infoAndReportMeasurement: function infoAndReportMeasurement() {}
  4546. };
  4547. var USER_ID = "987412365",
  4548. PAGE_SESSION = "aaabbbccc",
  4549. SERVER_SESSION = "cccbbbaaa",
  4550. COS_PREFIX = "error-bitstreams-auto-uploaded-from-application/",
  4551. FRAME_COMPOSE_LENGTH = 5;
  4552. var Workers = /*#__PURE__*/function () {
  4553. function Workers(e, t) {
  4554. var _this = this;
  4555. _classCallCheck(this, Workers);
  4556. 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 = {
  4557. x: 0,
  4558. y: 0,
  4559. z: 0,
  4560. tiles: []
  4561. }, 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 () {
  4562. return DECODER_VERSION;
  4563. }, this.downloadBlob = function (r, n, o) {
  4564. var a = new Blob([r], {
  4565. type: o
  4566. }),
  4567. s = window.URL.createObjectURL(a);
  4568. _this.downloadURL(s, n), setTimeout(function () {
  4569. return window.URL.revokeObjectURL(s);
  4570. }, 1e3);
  4571. }, this.downloadURL = function (r, n) {
  4572. var o = document.createElement("a");
  4573. o.href = r, o.download = n, document.body.appendChild(o), o.style.display = "none", o.click(), o.remove();
  4574. }, this.Stringify = function (r) {
  4575. var n = "";
  4576. for (var a = 0; a < r.length / 8192; a++) {
  4577. n += String.fromCharCode.apply(null, r.slice(a * 8192, (a + 1) * 8192));
  4578. }
  4579. return n;
  4580. }, this._rtcp = e;
  4581. }
  4582. _createClass(Workers, [{
  4583. key: "registerLogger",
  4584. value: function registerLogger(e) {//defaultLogger = e
  4585. }
  4586. }, {
  4587. key: "registerFunction",
  4588. value: function registerFunction(e, t) {
  4589. this.functionMap.set(e, t);
  4590. }
  4591. }, {
  4592. key: "hasFrmCntInCache",
  4593. value: function hasFrmCntInCache(e) {
  4594. var t = -1;
  4595. for (var r = 0; r < this.cacheFrameComposes.length; r++) {
  4596. this.cacheFrameComposes[r].frameCnt == e && (t = r);
  4597. }
  4598. return t;
  4599. }
  4600. }, {
  4601. key: "requestPanoramaTest",
  4602. value: function requestPanoramaTest(e, t, r, n, o) {
  4603. var a = o,
  4604. s = {
  4605. action_type: 16,
  4606. change_rotation_render_type_action: {
  4607. render_type: 5,
  4608. player: {
  4609. position: {
  4610. x: 0,
  4611. y: 0,
  4612. z: 0
  4613. },
  4614. angle: {
  4615. yaw: 0,
  4616. pitch: 0,
  4617. roll: 0
  4618. }
  4619. },
  4620. camera: {
  4621. position: {
  4622. x: e,
  4623. y: t,
  4624. z: r
  4625. },
  4626. angle: {
  4627. yaw: 0,
  4628. pitch: 0,
  4629. roll: 0
  4630. }
  4631. },
  4632. client_pano_titles_bitmap: n
  4633. },
  4634. trace_id: a,
  4635. user_id: this.userId_test,
  4636. packet_id: a
  4637. };
  4638. defaultLogger.debug("send data: ", s), this._rtcp.sendData(s);
  4639. }
  4640. }, {
  4641. key: "onRotateInPanoMode",
  4642. value: function onRotateInPanoMode(e) {
  4643. var t = e.traceId,
  4644. r = {};
  4645. r.width = 1280, r.height = 720, r.horz_fov = 92, r.angle = {
  4646. yaw: 100,
  4647. pitch: 30
  4648. };
  4649. var n = new ArrayBuffer(8),
  4650. o = new DataView(n);
  4651. getTilesInView(r, n);
  4652. var a = n.slice(0);
  4653. this.PendingMasks.unshift({
  4654. buffer: a,
  4655. angle: r.angle
  4656. }), MaskSetToOne(18, this.PanoView), operateForDataView(o, this.PanoView, o, function (s, l) {
  4657. return s ^ s & l;
  4658. }), 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);
  4659. }
  4660. }, {
  4661. key: "processMetaWithTraceId",
  4662. value: function processMetaWithTraceId(e) {
  4663. var _iterator = _createForOfIteratorHelper(e.traceIds),
  4664. _step;
  4665. try {
  4666. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  4667. var t = _step.value;
  4668. if (this.traceIdMap.has(t)) {
  4669. var r = this.traceIdMap.get(t);
  4670. r != null && (r.receiveTime = Date.now(), r.status = 1);
  4671. }
  4672. if (t == this.PendingMovingTraceId) {
  4673. 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());
  4674. var _r = Date.now();
  4675. this.lastMoveResponseTime = _r, this.lastMoveProcessTime = _r, this.lastMoveDisplayTime = _r, this.frameServerCircular.clear(), this.frameClientCircular.clear();
  4676. }
  4677. }
  4678. } catch (err) {
  4679. _iterator.e(err);
  4680. } finally {
  4681. _iterator.f();
  4682. }
  4683. }
  4684. }, {
  4685. key: "onTraceId",
  4686. value: function onTraceId(e) {
  4687. var _this2 = this;
  4688. var r = e.traceId,
  4689. n = e.timestamp,
  4690. o = e.event;
  4691. if (o === "Rotation") {
  4692. var a = {
  4693. traceId: r,
  4694. pts: 0,
  4695. startTime: n,
  4696. receiveTime: 0,
  4697. readyTime: 0,
  4698. displayTime: 0,
  4699. status: 0
  4700. };
  4701. this.traceIdMap.set(r, a);
  4702. var s = setTimeout(function () {
  4703. if (s && clearTimeout(s), _this2.traceIdMap.has(r)) {
  4704. var l = _this2.traceIdMap.get(r);
  4705. switch (l == null ? void 0 : l.status) {
  4706. case 0:
  4707. {
  4708. _this2.responseMiss += 1;
  4709. break;
  4710. }
  4711. case 1:
  4712. {
  4713. _this2.processMiss += 1;
  4714. var u = l.receiveTime - l.startTime;
  4715. _this2.responseTimeArray.push(u);
  4716. break;
  4717. }
  4718. case 2:
  4719. {
  4720. _this2.displayMiss += 1;
  4721. var _u = l.receiveTime - l.startTime,
  4722. c = l.readyTime - l.receiveTime;
  4723. _this2.responseTimeArray.push(_u), _this2.processTimeArray.push(c);
  4724. break;
  4725. }
  4726. case 3:
  4727. defaultLogger.debug("status is 3");
  4728. }
  4729. }
  4730. }, 1e3);
  4731. } 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();
  4732. }
  4733. }, {
  4734. key: "executeFunction",
  4735. value: function executeFunction(e, t) {
  4736. if (this.functionMap.has(e)) {
  4737. var r = this.functionMap.get(e);
  4738. r != null && r(t);
  4739. }
  4740. }
  4741. }, {
  4742. key: "UpdateStats",
  4743. value: function UpdateStats(e) {
  4744. var _this3 = this;
  4745. var t;
  4746. (t = this._rtcp.connection) == null || t.getStats(null).then(function (r) {
  4747. r.forEach(function (n) {
  4748. n.type == "data-channel" && (_this3.rtcMessageReceived = n.messagesReceived - n.messagesSent, _this3.rtcBytesReceived = n.bytesReceived);
  4749. });
  4750. }), 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;
  4751. }
  4752. }, {
  4753. key: "ReceiveDecodeMessage",
  4754. value: function ReceiveDecodeMessage(e) {
  4755. var n;
  4756. if (!this.firstYUVReceived) {
  4757. this.firstYUVDecoded = e.data.yuv_ts;
  4758. var o = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  4759. defaultLogger.infoAndReportMeasurement({
  4760. metric: "firstYUVDecodedAt",
  4761. value: o,
  4762. group: "joinRoom"
  4763. }), this.firstRender = Date.now();
  4764. var a = this.firstYUVDecoded - this.rtcp.network.room._startTime;
  4765. defaultLogger.infoAndReportMeasurement({
  4766. metric: "firstRenderAt",
  4767. value: a,
  4768. group: "joinRoom"
  4769. }), this.firstYUVReceived = !0, this.lastRenderTs = Date.now();
  4770. }
  4771. !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", {
  4772. stream: this.cachedStreams[this.setPtr],
  4773. width: this.cachedResolution[this.setPtr].width,
  4774. height: this.cachedResolution[this.setPtr].height,
  4775. pts: this.cachedPtss[this.setPtr]
  4776. }), this.executeFunction("signal", {
  4777. signal: this.cachedMetas[this.setPtr],
  4778. pts: this.cachedPtss[this.setPtr],
  4779. alreadyUpdateYUV: !0
  4780. })) : this.updateDropFrame += 1, this.decoderWorker.postMessage({
  4781. t: 2,
  4782. frameCnt: this.cachedPtss[this.setPtr],
  4783. buffer: this.cachedStreams[this.setPtr]
  4784. }, [this.cachedStreams[this.setPtr].buffer])), this.getPtr = (this.getPtr + 1) % this.cachedLength);
  4785. var t = e.data.metadata;
  4786. if ((n = t == null ? void 0 : t.traceIds) != null && n.length) {
  4787. var _iterator2 = _createForOfIteratorHelper(t.traceIds),
  4788. _step2;
  4789. try {
  4790. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  4791. var _o = _step2.value;
  4792. if (this.traceIdMap.has(_o)) {
  4793. var _a = this.traceIdMap.get(_o);
  4794. _a != null && (_a.readyTime = Date.now(), _a.status = 2);
  4795. }
  4796. }
  4797. } catch (err) {
  4798. _iterator2.e(err);
  4799. } finally {
  4800. _iterator2.f();
  4801. }
  4802. }
  4803. if (e.data.pts == this.moveStartPts && (this.MoveProcessDelay = Date.now() - this.StartMovingTs), this.userId_test = this.rtcp.network.room.userId, this.inMovingMode) {
  4804. var _o2 = Date.now(),
  4805. _a2 = _o2 - this.lastMoveProcessTime;
  4806. this.moveProcessCircular.add(_a2), this.lastMoveProcessTime = _o2;
  4807. }
  4808. var r = this.setPtr;
  4809. 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] = {
  4810. width: e.data.width,
  4811. height: e.data.height
  4812. }, this.setPtr = (this.setPtr + 1) % this.cachedLength;
  4813. }
  4814. }, {
  4815. key: "SendCacheFrameInfo",
  4816. value: function SendCacheFrameInfo(e) {
  4817. var _this4 = this;
  4818. var h, f, d, _, g, m, v;
  4819. var t = e.data.cachedKey,
  4820. r = e.data.metadata,
  4821. n = t,
  4822. o = r,
  4823. a = (d = (f = (h = o.newUserStates) == null ? void 0 : h.find(function (y) {
  4824. return y.userId === _this4.rtcp.network.room.userId;
  4825. })) == null ? void 0 : f.playerState) == null ? void 0 : d.roomTypeId,
  4826. s = this.rtcp.network.room.skinId,
  4827. l = (v = (m = (g = (_ = o.newUserStates) == null ? void 0 : _.find(function (y) {
  4828. return y.userId === _this4._rtcp.network.room.userId;
  4829. })) == null ? void 0 : g.playerState) == null ? void 0 : m.player) == null ? void 0 : v.position,
  4830. u = {
  4831. MsgType: 1,
  4832. FrameCacheMsg: {
  4833. FrameIndex: n,
  4834. RoomTypeId: a,
  4835. SkinID: s,
  4836. Position: l
  4837. }
  4838. };
  4839. var c = "";
  4840. try {
  4841. c = JSON.stringify(u);
  4842. } catch (y) {
  4843. defaultLogger.error(y);
  4844. return;
  4845. }
  4846. }
  4847. }, {
  4848. key: "ReceivePanoramaDecodeMessage",
  4849. value: function ReceivePanoramaDecodeMessage(e) {
  4850. defaultLogger.info("Receive Panorama Image in Workers.ts"), MaskSetToOne(e.data.tileId, this.PanoView);
  4851. var t = 0,
  4852. r;
  4853. var n = this.PendingMasks.length;
  4854. for (t = 0; t < n; t++) {
  4855. var o = this.PendingMasks[t].buffer,
  4856. a = new DataView(o),
  4857. s = new ArrayBuffer(8),
  4858. l = new DataView(s);
  4859. if (operateForDataView(this.PanoView, a, l, function (u, c) {
  4860. return c ^ u & c;
  4861. }), IsAll0(l)) {
  4862. r = this.PendingMasks[t].angle;
  4863. break;
  4864. }
  4865. }
  4866. for (var _o3 = t; _o3 < n; _o3++) {
  4867. this.PendingMasks.pop();
  4868. }
  4869. this.executeFunction("panorama", {
  4870. data: e.data.data,
  4871. tileId: e.data.tileId,
  4872. pos: {
  4873. x: e.data.x,
  4874. y: e.data.y,
  4875. z: e.data.z
  4876. },
  4877. uuid: e.data.uuid,
  4878. finished: !0,
  4879. matchAngle: r
  4880. });
  4881. }
  4882. }, {
  4883. key: "enable_decoder_queue_logging",
  4884. value: function enable_decoder_queue_logging() {
  4885. this.decoderWorker.postMessage({
  4886. t: 100,
  4887. status: !0
  4888. });
  4889. }
  4890. }, {
  4891. key: "disable_decoder_queue_logging",
  4892. value: function disable_decoder_queue_logging() {
  4893. this.decoderWorker.postMessage({
  4894. t: 100,
  4895. status: !1
  4896. });
  4897. }
  4898. }, {
  4899. key: "init",
  4900. value: function () {
  4901. var _init = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  4902. var _this5 = this;
  4903. var e,
  4904. r,
  4905. n,
  4906. t,
  4907. _args = arguments;
  4908. return regenerator.wrap(function _callee$(_context) {
  4909. while (1) {
  4910. switch (_context.prev = _context.next) {
  4911. case 0:
  4912. e = _args.length > 0 && _args[0] !== undefined ? _args[0] : {
  4913. width: 1280,
  4914. height: 720
  4915. };
  4916. for (r = 0; r < FRAME_COMPOSE_LENGTH; r++) {
  4917. n = {
  4918. buffer: new Uint8Array(2621440),
  4919. size: 0,
  4920. startReceiveTime: 0,
  4921. serverTime: 0,
  4922. frameCnt: -1
  4923. };
  4924. this.cacheFrameComposes.push(n);
  4925. }
  4926. t = new Blob([decoder], {
  4927. type: "application/javascript"
  4928. });
  4929. return _context.abrupt("return", (this.decoderWorker = new Worker(URL.createObjectURL(t)), this.decoderWorker.postMessage({
  4930. t: 9,
  4931. url: WASM_URLS[WASM_Version],
  4932. jitterLength: DECODER_PASSIVE_JITTER
  4933. }), this.decoderWorker.postMessage({
  4934. t: 1,
  4935. config: e
  4936. }), new Promise(function (r) {
  4937. _this5.decoderWorker.onmessage = function (n) {
  4938. switch (n.data.t) {
  4939. case 0:
  4940. _this5.ReceiveDecodeMessage(n);
  4941. break;
  4942. case 1:
  4943. _this5.UpdateStats(n);
  4944. break;
  4945. case 2:
  4946. r();
  4947. break;
  4948. case 3:
  4949. _this5.SendCacheFrameInfo(n);
  4950. break;
  4951. case 4:
  4952. {
  4953. var o = new Date().toISOString(),
  4954. a = USER_ID + "-" + PAGE_SESSION + "-" + SERVER_SESSION + "-" + o + ".264";
  4955. uploadStream(COS_PREFIX + a, n.data.fileObj);
  4956. break;
  4957. }
  4958. case 5:
  4959. _this5.executeFunction("signal", {
  4960. signal: n.data.metadata,
  4961. pts: -1,
  4962. alreadyUpdateYUV: !1
  4963. });
  4964. break;
  4965. case 6:
  4966. defaultLogger.infoAndReportMeasurement(n.data), defaultLogger.debug("WASM Ready Cost");
  4967. break;
  4968. case 7:
  4969. _this5.ReceivePanoramaDecodeMessage(n);
  4970. break;
  4971. case 8:
  4972. {
  4973. var _o4 = {
  4974. MstType: 0
  4975. };
  4976. var _a3 = "";
  4977. try {
  4978. _a3 = JSON.stringify(_o4);
  4979. } catch (l) {
  4980. defaultLogger.error(l);
  4981. return;
  4982. }
  4983. var s = "wasm:" + _a3;
  4984. _this5._rtcp.sendStringData(s);
  4985. break;
  4986. }
  4987. case 9:
  4988. {
  4989. defaultLogger.info(n.data.printMsg);
  4990. break;
  4991. }
  4992. case 10:
  4993. {
  4994. defaultLogger.error(n.data.printMsg), _this5.executeFunction("error", {
  4995. code: n.data.code,
  4996. message: n.data.printMsg
  4997. });
  4998. break;
  4999. }
  5000. default:
  5001. defaultLogger.error("Receive unknown message event from decoder"), defaultLogger.debug(n.data);
  5002. break;
  5003. }
  5004. };
  5005. })));
  5006. case 4:
  5007. case "end":
  5008. return _context.stop();
  5009. }
  5010. }
  5011. }, _callee, this);
  5012. }));
  5013. function init() {
  5014. return _init.apply(this, arguments);
  5015. }
  5016. return init;
  5017. }()
  5018. }, {
  5019. key: "UpdateYUV",
  5020. value: function UpdateYUV() {
  5021. var t, r;
  5022. var e = this.getPtr;
  5023. if (this.cachedMetas[e] != null && !this.cachedRender[e]) {
  5024. var n = Date.now();
  5025. if (this.firstUpdateYUV) {
  5026. var h = ((t = this.cachedStreams[e]) == null ? void 0 : t.byteLength) || 0;
  5027. defaultLogger.infoAndReportMeasurement({
  5028. metric: "firstUpdateStreamLength",
  5029. value: h,
  5030. group: "joinRoom"
  5031. }), this.firstUpdateYUV = !1;
  5032. }
  5033. this.cachedStreams[e] != null && this.executeFunction("stream", {
  5034. stream: this.cachedStreams[e],
  5035. width: this.cachedResolution[e].width,
  5036. height: this.cachedResolution[e].height,
  5037. pts: this.cachedPtss[e]
  5038. });
  5039. var o = Date.now();
  5040. this.cachedStreams[e] != null && this.decoderWorker.postMessage({
  5041. t: 2,
  5042. frameCnt: this.cachedPtss[e],
  5043. buffer: this.cachedStreams[e]
  5044. }, [this.cachedStreams[e].buffer]);
  5045. var a = Date.now(),
  5046. s = o - n,
  5047. l = a - o;
  5048. (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;
  5049. var u = o - n;
  5050. this.updateYUVCircular.add(u);
  5051. var c = this.cachedMetas[e];
  5052. if ((r = c == null ? void 0 : c.traceIds) != null && r.length) {
  5053. var _iterator3 = _createForOfIteratorHelper(c.traceIds),
  5054. _step3;
  5055. try {
  5056. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  5057. var _h = _step3.value;
  5058. if (this.traceIdMap.has(_h)) {
  5059. var f = this.traceIdMap.get(_h);
  5060. if (f != null) {
  5061. f.displayTime = Date.now(), f.status = 3;
  5062. var d = f.receiveTime - f.startTime,
  5063. _ = f.readyTime - f.receiveTime,
  5064. g = f.displayTime - f.readyTime,
  5065. m = f.displayTime - f.startTime;
  5066. this.responseTimeArray.push(d), this.processTimeArray.push(_), this.displayTimeArray.push(g), this.overallTimeArray.push(m), this.traceIdMap.delete(_h);
  5067. }
  5068. }
  5069. }
  5070. } catch (err) {
  5071. _iterator3.e(err);
  5072. } finally {
  5073. _iterator3.f();
  5074. }
  5075. }
  5076. if (this.cachedPtss[e] == this.moveStartPts && (this.MoveDisplayDelay = Date.now() - this.StartMovingTs), this.inMovingMode) {
  5077. var _h2 = Date.now(),
  5078. _f = _h2 - this.lastMoveDisplayTime;
  5079. this.moveDisplayCircular.add(_f), this.lastMoveDisplayTime = _h2;
  5080. }
  5081. this.executeFunction("signal", {
  5082. signal: this.cachedMetas[e],
  5083. pts: this.cachedPtss[e],
  5084. alreadyUpdateYUV: !0
  5085. }), this.cachedRender[e] = !0, this.getPtr = (this.getPtr + 1) % this.cachedLength;
  5086. }
  5087. }
  5088. }, {
  5089. key: "unmarshalPano",
  5090. value: function unmarshalPano(e) {
  5091. var t = new DataView(e);
  5092. if (t.getUint32(0) != 1723558763) return !1;
  5093. console.log("Receive Pano Message"), t.getUint16(4);
  5094. var n = t.getUint16(6),
  5095. o = t.getUint32(8),
  5096. a = t.getUint32(12) - (1 << 30) * 2,
  5097. s = t.getUint32(16) - (1 << 30) * 2,
  5098. l = t.getUint32(20) - (1 << 30) * 2,
  5099. u = t.getUint32(24),
  5100. c = new Uint8Array(e).subarray(28, 64),
  5101. h = String.fromCharCode.apply(null, c),
  5102. f = t.getUint32(64),
  5103. d = e.byteLength - n;
  5104. if (d == u) {
  5105. var g = {
  5106. data: new Uint8Array(e).subarray(n),
  5107. mediaLen: u,
  5108. tileId: o,
  5109. uuid: h,
  5110. x: a,
  5111. y: s,
  5112. z: l
  5113. };
  5114. this.decoderWorker.postMessage({
  5115. t: 8,
  5116. data: g
  5117. });
  5118. } else {
  5119. var _ = new Uint8Array(e, n, d);
  5120. if (this.cachePanoTileID == o) {
  5121. if (this.panoCacheBuffer.set(_, f), this.panoCacheSize += d, this.panoCacheSize === u) {
  5122. var m = {
  5123. data: new Uint8Array(this.panoCacheBuffer).slice(0, u),
  5124. mediaLen: u,
  5125. tileId: o,
  5126. uuid: h,
  5127. x: a,
  5128. y: s,
  5129. z: l
  5130. };
  5131. this.decoderWorker.postMessage({
  5132. t: 8,
  5133. data: m
  5134. }), this.panoCacheSize = 0;
  5135. }
  5136. } else this.panoCacheBuffer.set(_, f), this.panoCacheSize = d, this.cachePanoTileID = o;
  5137. }
  5138. return !0;
  5139. }
  5140. }, {
  5141. key: "clearMoveArray",
  5142. value: function clearMoveArray() {
  5143. 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 = "";
  5144. }
  5145. }, {
  5146. key: "getIsMoving",
  5147. value: function getIsMoving(e) {
  5148. var t;
  5149. if (typeof e.newUserStates != "undefined") for (var r = 0; r < e.newUserStates.length; r++) {
  5150. var n = e.newUserStates[r];
  5151. if (n.userId == this.rtcp.network.room.userId) {
  5152. t = n.renderInfo.isMoving;
  5153. break;
  5154. }
  5155. }
  5156. return t;
  5157. }
  5158. }, {
  5159. key: "isHeartBeatPacket",
  5160. value: function isHeartBeatPacket(e, t) {
  5161. return new DataView(e).getUint32(0) == 2009889916;
  5162. }
  5163. }, {
  5164. key: "resetSendTimeDiff",
  5165. value: function resetSendTimeDiff() {
  5166. this.prevSenderTs = 0, this.serverSendTimeArray.clear();
  5167. }
  5168. }, {
  5169. key: "calcSendTimeDiff",
  5170. value: function calcSendTimeDiff(e) {
  5171. if (this.prevSenderTs == -1) {
  5172. this.prevSenderTs = e;
  5173. return;
  5174. }
  5175. var t = e - this.prevSenderTs;
  5176. this.serverSendTimeArray.add(t), this.prevSenderTs = e;
  5177. }
  5178. }, {
  5179. key: "unmarshalStream",
  5180. value: function unmarshalStream(e) {
  5181. var _this6 = this;
  5182. var T, C, A, S, P, R, M, x, I, w;
  5183. var t = new DataView(e);
  5184. if (t.getUint32(0) != 1437227610) return !1;
  5185. t.getUint16(4);
  5186. var n = t.getUint16(6),
  5187. o = t.getUint16(8),
  5188. a = o,
  5189. s = t.getUint16(10);
  5190. var l = !1;
  5191. s == 1 && (l = !0);
  5192. var u = t.getUint32(12),
  5193. c = t.getUint32(16),
  5194. h = t.getUint32(20),
  5195. f = t.getUint16(24),
  5196. d = t.getUint16(26),
  5197. _ = t.getUint32(28),
  5198. g = t.getUint32(n - 4),
  5199. m = u + c,
  5200. v = e.byteLength - n,
  5201. y = new Uint8Array(e, n, v);
  5202. this.calcSendTimeDiff(h);
  5203. var b;
  5204. if (this.inPanoMode && (c > 0 || f)) return defaultLogger.error("Stream Protocal Violation: receive illegal stream in Pano mode"), !0;
  5205. if (v === m) {
  5206. this.receivedMedia++;
  5207. var O = new Uint8Array(e).subarray(n);
  5208. h - this.lastServerTS > 60 ? this.serverFrameSlow++ : h - this.lastServerTS < 16 && this.serverFrameFast++;
  5209. var D = Date.now();
  5210. D - this.lastClientTS > 60 ? this.clientFrameSlow++ : D - this.lastClientTS < 16 && this.clientFrameFast++;
  5211. var F = c === 0,
  5212. V = h - this.lastServerTS;
  5213. 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;
  5214. var N = O.subarray(0, u),
  5215. L = Date.now(),
  5216. k = JSON.parse(this.Stringify(N)),
  5217. U = Date.now();
  5218. 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));
  5219. var z = this.getIsMoving(k);
  5220. if (this.inMovingMode && z == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof z != "undefined" && (this.lastIsMoving = z), this.inMovingMode) {
  5221. var G = Date.now(),
  5222. W = G - this.lastMoveResponseTime;
  5223. this.moveResponseCircular.add(W), this.lastMoveResponseTime = G;
  5224. }
  5225. (f || d) && (b = (P = (S = (A = (C = k.newUserStates) == null ? void 0 : C.find(function (G) {
  5226. return G.userId === _this6._rtcp.network.room.userId;
  5227. })) == null ? void 0 : A.playerState) == null ? void 0 : S.player) == null ? void 0 : P.position);
  5228. var H = {
  5229. t: 0,
  5230. data: O,
  5231. mediaLen: c,
  5232. metaLen: u,
  5233. metadata: k,
  5234. frameCnt: a,
  5235. server_ts: h,
  5236. isIDR: l,
  5237. cacheRequest: d,
  5238. cached: f,
  5239. cachedKey: _,
  5240. position: b
  5241. };
  5242. if (this.inPanoMode) return this.executeFunction("signal", {
  5243. signal: k,
  5244. pts: -1,
  5245. alreadyUpdateYUV: !0
  5246. }), !0;
  5247. if (this.decoderWorker.postMessage(H, [O.buffer]), !this.firstMediaReceived) {
  5248. this.firstMediaArraval = Date.now();
  5249. var _G = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5250. defaultLogger.infoAndReportMeasurement({
  5251. metric: "firstMediaArravalAt",
  5252. value: _G,
  5253. group: "joinRoom"
  5254. }), this.firstMediaReceived = !0;
  5255. }
  5256. } else {
  5257. var _O = this.hasFrmCntInCache(a);
  5258. if (_O != -1) {
  5259. if (this.cacheFrameComposes[_O].buffer.set(y, g), this.cacheFrameComposes[_O].size += v, this.cacheFrameComposes[_O].size === m) {
  5260. var _D = new Uint8Array(this.cacheFrameComposes[_O].buffer).slice(0, m);
  5261. 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++;
  5262. var _F = Date.now();
  5263. _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;
  5264. var _V = _D.subarray(0, u),
  5265. _N = Date.now(),
  5266. _L = JSON.parse(this.Stringify(_V)),
  5267. _k = Date.now();
  5268. 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);
  5269. var _U = this.getIsMoving(_L);
  5270. if (this.inMovingMode && _U == 0 && this.lastIsMoving == 1 && this.clearMoveArray(), typeof _U != "undefined" && (this.lastIsMoving = _U), this.inMovingMode) {
  5271. var _H = Date.now(),
  5272. _G2 = _H - this.lastMoveResponseTime;
  5273. this.moveResponseCircular.add(_G2), this.lastMoveResponseTime = _H;
  5274. }
  5275. (f || d) && (b = (w = (I = (x = (M = _L.newUserStates) == null ? void 0 : M.find(function (H) {
  5276. return H.userId === _this6._rtcp.network.room.userId;
  5277. })) == null ? void 0 : x.playerState) == null ? void 0 : I.player) == null ? void 0 : w.position);
  5278. var _z = {
  5279. t: 0,
  5280. data: _D,
  5281. mediaLen: c,
  5282. metaLen: u,
  5283. metadata: _L,
  5284. frameCnt: a,
  5285. server_ts: h,
  5286. isIDR: l,
  5287. cacheRequest: d,
  5288. cached: f,
  5289. cachedKey: _,
  5290. position: b
  5291. };
  5292. if (this.inPanoMode) return this.executeFunction("signal", {
  5293. signal: _L,
  5294. pts: -1,
  5295. alreadyUpdateYUV: !0
  5296. }), !0;
  5297. if (this.decoderWorker.postMessage(_z, [_D.buffer]), !this.firstMediaReceived) {
  5298. this.firstMediaArraval = Date.now();
  5299. var _H2 = this.firstMediaArraval - this.rtcp.network.room._startTime;
  5300. defaultLogger.infoAndReportMeasurement({
  5301. metric: "firstMediaArravalAt",
  5302. value: _H2,
  5303. group: "joinRoom"
  5304. }), this.firstMediaReceived = !0;
  5305. }
  5306. } else this.cacheFrameComposes[_O].size > m && defaultLogger.debug("I frame exceed, cache size is ", this.cacheSize, ", total size is ", m);
  5307. } else if (_O == -1) {
  5308. var _D2 = this.hasFrmCntInCache(-1);
  5309. if (_D2 == -1) {
  5310. var _F2 = Date.now() + 1e18,
  5311. _V2 = -1;
  5312. for (var _N2 = 0; _N2 < this.cacheFrameComposes.length; _N2++) {
  5313. this.cacheFrameComposes[_N2].serverTime < _F2 && (_F2 = this.cacheFrameComposes[_N2].serverTime, _V2 = _N2);
  5314. }
  5315. _D2 = _V2;
  5316. }
  5317. 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;
  5318. }
  5319. }
  5320. return !0;
  5321. }
  5322. }, {
  5323. key: "reset",
  5324. value: function reset() {
  5325. defaultLogger.debug("Worker reset is called"), this.cacheFrameCnt = 0, this.receivedMedia = 0, this.reconnectSignal = !0, this.decoderWorker.postMessage({
  5326. t: 4
  5327. });
  5328. }
  5329. }, {
  5330. key: "dataHandleOff",
  5331. value: function dataHandleOff(e) {
  5332. defaultLogger.debug("hhh");
  5333. }
  5334. }, {
  5335. key: "dataHandle",
  5336. value: function dataHandle(e) {
  5337. this.saveframe && (this.decoderWorker.postMessage({
  5338. t: 6
  5339. }), this.saveframe = !1), this.SaveMediaStream && (this.decoderWorker.postMessage({
  5340. t: 7
  5341. }), this.SaveMediaStream = !1);
  5342. var t = new Uint8Array(e);
  5343. if (t.length >= 4 && this.isHeartBeatPacket(t.buffer, t.length) == !0) return;
  5344. if (t.length > 36 && this.unmarshalStream(t.buffer) == !0) {
  5345. this.reconnectSignal && (this.executeFunction("reconnectedFrame", {}), this.reconnectSignal = !1);
  5346. return;
  5347. }
  5348. if (t.length > 20 && this.unmarshalPano(t.buffer) == !0) return;
  5349. this.noWasmBytesReceived += e.byteLength;
  5350. var r = JSON.parse(this.Stringify(t));
  5351. this.executeFunction("signal", {
  5352. signal: r,
  5353. pts: -1,
  5354. alreadyUpdateYUV: !0
  5355. });
  5356. }
  5357. }, {
  5358. key: "changePanoMode",
  5359. value: function changePanoMode(e) {
  5360. this.inPanoMode = e;
  5361. }
  5362. }, {
  5363. key: "uploadDataToServer",
  5364. value: function uploadDataToServer() {
  5365. this.DynamicPanoTest == !0 && (this.onRotateInPanoMode({
  5366. traceId: "b2e1a296-6438-4371-8a31-687beb724ebe"
  5367. }), this.DynamicPanoTest = !1);
  5368. function e(ie, ee) {
  5369. return ee == -1 && (ee = 0), ie + ee;
  5370. }
  5371. function t(ie, ee) {
  5372. return Math.max(ie, ee);
  5373. }
  5374. var r = this.responseTimeArray.reduce(e, 0) / this.responseTimeArray.length || 0,
  5375. n = this.processTimeArray.reduce(e, 0) / this.processTimeArray.length || 0,
  5376. o = this.displayTimeArray.reduce(e, 0) / this.displayTimeArray.length || 0,
  5377. a = this.overallTimeArray.reduce(e, 0) / this.overallTimeArray.length || 0,
  5378. s = this.overallTimeArray.length;
  5379. this.responseTimeArray = [], this.processTimeArray = [], this.displayTimeArray = [], this.overallTimeArray = [];
  5380. var l = this.moveResponseCircular.getThreshPercent(),
  5381. u = l[0],
  5382. c = l[1],
  5383. h = l[2],
  5384. f = l[3],
  5385. d = l[4],
  5386. _ = d - f,
  5387. g = 1 - c / d || 0,
  5388. m = [u, c - u, h - c, f - h, _],
  5389. v = this.moveProcessCircular.getThreshPercent(),
  5390. y = v[0],
  5391. b = v[1],
  5392. T = v[2],
  5393. C = v[3],
  5394. A = v[4],
  5395. S = A - C,
  5396. P = 1 - b / A || 0,
  5397. R = [y, b - y, T - b, C - T, S],
  5398. M = this.moveDisplayCircular.getThreshPercent(),
  5399. x = M[0],
  5400. I = M[1],
  5401. w = M[2],
  5402. O = M[3],
  5403. D = M[4],
  5404. F = D - O,
  5405. V = 1 - I / D || 0,
  5406. N = [x, I - x, w - I, O - w, F],
  5407. L = x,
  5408. k = I - x,
  5409. U = w - I,
  5410. z = O - w,
  5411. H = F,
  5412. G = this.moveResponseCircular.getAvg(),
  5413. W = this.moveProcessCircular.getAvg(),
  5414. j = this.moveDisplayCircular.getAvg(),
  5415. B = this.moveResponseCircular.getMax(),
  5416. X = this.moveProcessCircular.getMax(),
  5417. $ = this.moveDisplayCircular.getMax(),
  5418. Y = this.moveResponseCircular.getStandardDeviation(),
  5419. K = this.moveProcessCircular.getStandardDeviation(),
  5420. Z = this.moveDisplayCircular.getStandardDeviation();
  5421. 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();
  5422. var q = this.frameServerCircular.getAvg(),
  5423. J = this.frameServerCircular.getMax();
  5424. this.frameClientCircular.getAvg(), this.frameClientCircular.getMax();
  5425. var Q = this.metaParseAraay.reduce(e, 0) / this.metaParseAraay.length || 0,
  5426. te = this.metaParseAraay.reduce(t, 0);
  5427. this.metaParseAraay = [];
  5428. var re = {
  5429. mediaBytesReceived: this.mediaBytesReceived,
  5430. metaBytesReceived: this.metaBytesReceived,
  5431. packetsLost: this.packetsLost,
  5432. timestamp: Date.now(),
  5433. frameHeight: 1280,
  5434. frameWidth: 720,
  5435. framesReceived: this.receivedMedia,
  5436. framesReceivedWorker: this.receivedMedia_worker,
  5437. framesDecoded: this.receivedYUV,
  5438. framesEmited: this.receivedEmit,
  5439. decodeTimePerFrame: this.decodeTimePerFrame,
  5440. decodeTimeMaxFrame: this.decodeTimeMaxFrame,
  5441. packetsDrop: this.packetsDrop,
  5442. framesAwait: this.framesAwait,
  5443. firstMediaArraval: this.firstMediaArraval,
  5444. firstYUVDecoded: this.firstYUVDecoded,
  5445. firstRender: this.firstRender,
  5446. returnFrames: this.returnFrames,
  5447. sendOutBuffer: this.sendOutBuffer,
  5448. maxGraphicTime: this.updateYUVCircular.getMax(),
  5449. averageGraphicTime: this.updateYUVCircular.getAvg(),
  5450. jankTimes: this.JankTimes,
  5451. bigJankTimes: this.bigJankTimes,
  5452. decodeJankTimes: this.DecodeJankTimes,
  5453. bigDecodeJankTimes: this.bigDecodeJankTimes,
  5454. serverFrameSlow: this.serverFrameSlow,
  5455. serverFrameFast: this.serverFrameFast,
  5456. clientFrameSlow: this.clientFrameSlow,
  5457. clientFrameFast: this.clientFrameFast,
  5458. rtcMessageReceived: this.rtcMessageReceived,
  5459. rtcBytesReceived: this.rtcBytesReceived - this.noWasmBytesReceived,
  5460. receiveIframes: this.receiveIframes,
  5461. decodeIframes: this.decodeIframes,
  5462. avgResponseTime: r,
  5463. avgProcessTime: n,
  5464. avgDisplayTime: o,
  5465. avgOverallTime: a,
  5466. overallTimeCount: s,
  5467. responseMiss: this.responseMiss,
  5468. processMiss: this.processMiss,
  5469. displayMiss: this.displayMiss,
  5470. updateDropFrame: this.updateDropFrame,
  5471. moveEvent: this.moveEvent,
  5472. avgResponseMoveDiff: this.moveEvent == "MoveTo" ? G : 0,
  5473. avgProcessMoveDiff: this.moveEvent == "MoveTo" ? W : 0,
  5474. avgDisplayMoveDiff: this.moveEvent == "MoveTo" ? j : 0,
  5475. maxResponseMoveDiff: this.moveEvent == "MoveTo" ? B : 0,
  5476. maxProcessMoveDiff: this.moveEvent == "MoveTo" ? X : 0,
  5477. maxDisplayMoveDiff: this.moveEvent == "MoveTo" ? $ : 0,
  5478. moveResponseJank: this.moveEvent == "MoveTo" ? g : 0,
  5479. moveProcessJank: this.moveEvent == "MoveTo" ? P : 0,
  5480. moveDisplayJank: this.moveEvent == "MoveTo" ? V : 0,
  5481. moveResponseCounts: this.moveEvent == "MoveTo" ? m.toString() : "0,0,0,0,0",
  5482. moveProcessCounts: this.moveEvent == "MoveTo" ? R.toString() : "0,0,0,0,0",
  5483. moveDisplayCounts: this.moveEvent == "MoveTo" ? N.toString() : "0,0,0,0,0",
  5484. MoveDisplayCountGood: this.moveEvent == "MoveTo" ? L.toString() : "0",
  5485. MoveDisplayCountWell: this.moveEvent == "MoveTo" ? k.toString() : "0",
  5486. MoveDisplayCountFair: this.moveEvent == "MoveTo" ? U.toString() : "0",
  5487. MoveDisplayCountBad: this.moveEvent == "MoveTo" ? z.toString() : "0",
  5488. MoveDisplayCountRest: this.moveEvent == "MoveTo" ? H.toString() : "0",
  5489. moveResponseDelay: this.moveEvent == "MoveTo" ? this.MoveResponseDelay : 0,
  5490. moveProcessDelay: this.moveEvent == "MoveTo" ? this.MoveProcessDelay : 0,
  5491. moveDisplayDelay: this.moveEvent == "MoveTo" ? this.MoveDisplayDelay : 0,
  5492. sdMoveResponseLongTime: Y,
  5493. sdMoveProcessLongTime: K,
  5494. sdMoveDisplayLongTime: Z,
  5495. avgResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? G : 0,
  5496. avgProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? W : 0,
  5497. avgDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? j : 0,
  5498. maxResponseFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? B : 0,
  5499. maxProcessFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? X : 0,
  5500. maxDisplayFlyDiff: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? $ : 0,
  5501. flyResponseJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? g : 0,
  5502. flyProcessJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? P : 0,
  5503. flyDisplayJank: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? V : 0,
  5504. flyResponseCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? m.toString() : "0,0,0,0,0",
  5505. flyProcessCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? R.toString() : "0,0,0,0,0",
  5506. flyDisplayCounts: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? N.toString() : "0,0,0,0,0",
  5507. flyResponseDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveResponseDelay : 0,
  5508. flyProcessDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveProcessDelay : 0,
  5509. flyDisplayDelay: this.moveEvent == "GetOnVehicle" || this.moveEvent == "GetOnAirship" ? this.MoveDisplayDelay : 0,
  5510. avgMetaParseTime: Q,
  5511. maxMetaParseTime: te,
  5512. avgServerDiff: q,
  5513. maxServerDiff: J,
  5514. streamType: WASM_Version
  5515. };
  5516. return this.lastReturnFrames = this.returnFrames, this.lastReceivedEmit = this.receivedEmit, re;
  5517. }
  5518. }]);
  5519. return Workers;
  5520. }();
  5521. 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); }; }
  5522. 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; } }
  5523. var Rtcp = /*#__PURE__*/function (_EventEmitter) {
  5524. _inherits(Rtcp, _EventEmitter);
  5525. var _super = _createSuper$5(Rtcp);
  5526. function Rtcp(network) {
  5527. var _this;
  5528. _classCallCheck(this, Rtcp);
  5529. _this = _super.call(this);
  5530. _this.connection = null;
  5531. _this.inputChannel = null;
  5532. _this.mediaStream = null;
  5533. _this.socket = null;
  5534. _this.connected = !1;
  5535. _this.candidates = [];
  5536. _this.isAnswered = !1;
  5537. _this.isFlushing = !1;
  5538. _this.inputReady = !1;
  5539. _this.workers = null;
  5540. _this.actived = !0;
  5541. _this.heartbeat = null;
  5542. _this.network = network; //this.workers = new Workers(this,new Logger("decode")),
  5543. //this.workers.registerLogger(new Logger("decode")),
  5544. _this.workers = new Workers(_assertThisInitialized(_this));
  5545. _this.workers.registerLogger();
  5546. _this.workers.registerFunction("data", function (t) {
  5547. _this.emit("data", t);
  5548. }), _this.heartbeat = new Heartbeat({
  5549. ping: function ping(t) {
  5550. e.room.actionsHandler.echo(t);
  5551. },
  5552. pong(t, r) {
  5553. var n;
  5554. r && t > 500 && logger.warn("high hb value ".concat(t, ", traceId:") + r), (n = e.room.stats) == null || n.assign({
  5555. hb: t
  5556. });
  5557. }
  5558. }); //解决onIcecandidate 获取不了this
  5559. _this.onIcecandidate = _this.onIcecandidate.bind(_assertThisInitialized(_this));
  5560. _this.onIceStateChange = _this.onIceStateChange.bind(_assertThisInitialized(_this));
  5561. _this.setRemoteDescription = _this.setRemoteDescription.bind(_assertThisInitialized(_this));
  5562. _this.start = _this.start.bind(_assertThisInitialized(_this));
  5563. _this.flushCandidate = _this.flushCandidate.bind(_assertThisInitialized(_this));
  5564. _this.addCandidate = _this.addCandidate.bind(_assertThisInitialized(_this));
  5565. _this.disconnect = _this.disconnect.bind(_assertThisInitialized(_this));
  5566. return _this;
  5567. }
  5568. _createClass(Rtcp, [{
  5569. key: "onIcecandidate",
  5570. value: function onIcecandidate(e) {
  5571. if (e.candidate != null) {
  5572. var t = JSON.stringify(e.candidate);
  5573. logger.debug("Got ice candidate: ".concat(t)), this.network.socket.send({
  5574. id: "ice_candidate",
  5575. data: btoa(t)
  5576. });
  5577. }
  5578. }
  5579. }, {
  5580. key: "onIcecandidateerror",
  5581. value: function onIcecandidateerror(e) {
  5582. logger.error("onicecandidateerror", e.errorCode, e.errorText, e);
  5583. }
  5584. }, {
  5585. key: "onIceStateChange",
  5586. value: function onIceStateChange(e) {
  5587. switch (e.target.iceGatheringState) {
  5588. case "gathering":
  5589. logger.info("ice gathering");
  5590. break;
  5591. case "complete":
  5592. logger.info("Ice gathering completed");
  5593. }
  5594. }
  5595. }, {
  5596. key: "onIceConnectionStateChange",
  5597. value: function onIceConnectionStateChange() {
  5598. if (!!this.connection) switch (logger.info("iceConnectionState: ".concat(this.connection.iceConnectionState)), this.connection.iceConnectionState) {
  5599. case "connected":
  5600. {
  5601. this.connected = !0;
  5602. break;
  5603. }
  5604. case "disconnected":
  5605. {
  5606. this.connected = !1, this.emit("rtcDisconnected");
  5607. break;
  5608. }
  5609. case "failed":
  5610. {
  5611. this.emit("rtcDisconnected"), this.connected = !1;
  5612. break;
  5613. }
  5614. }
  5615. }
  5616. }, {
  5617. key: "setRemoteDescription",
  5618. value: function () {
  5619. var _setRemoteDescription = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  5620. var a, s, l, r, n, o, u;
  5621. return regenerator.wrap(function _callee$(_context) {
  5622. while (1) {
  5623. switch (_context.prev = _context.next) {
  5624. case 0:
  5625. if (this.connection) {
  5626. _context.next = 2;
  5627. break;
  5628. }
  5629. return _context.abrupt("return");
  5630. case 2:
  5631. r = JSON.parse(atob(e)), n = new RTCSessionDescription(r);
  5632. _context.next = 5;
  5633. return this.connection.setRemoteDescription(n);
  5634. case 5:
  5635. _context.next = 7;
  5636. return this.connection.createAnswer();
  5637. case 7:
  5638. o = _context.sent;
  5639. 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) {
  5640. u = o.sdp.lastIndexOf("a=mid:1");
  5641. o.sdp = o.sdp.slice(0, u) + "a=mid:2" + o.sdp.slice(u + 7);
  5642. }
  5643. _context.prev = 9;
  5644. _context.next = 12;
  5645. return this.connection.setLocalDescription(o);
  5646. case 12:
  5647. _context.next = 17;
  5648. break;
  5649. case 14:
  5650. _context.prev = 14;
  5651. _context.t0 = _context["catch"](9);
  5652. logger.error("error", _context.t0);
  5653. case 17:
  5654. this.isAnswered = !0, this.network.rtcp.flushCandidate(), this.network.socket.send({
  5655. id: "answer",
  5656. data: btoa(JSON.stringify(o))
  5657. }), t.srcObject = this.mediaStream;
  5658. case 18:
  5659. case "end":
  5660. return _context.stop();
  5661. }
  5662. }
  5663. }, _callee, this, [[9, 14]]);
  5664. }));
  5665. function setRemoteDescription(_x, _x2) {
  5666. return _setRemoteDescription.apply(this, arguments);
  5667. }
  5668. return setRemoteDescription;
  5669. }()
  5670. }, {
  5671. key: "flushCandidate",
  5672. value: function flushCandidate() {
  5673. var _this2 = this;
  5674. this.isFlushing || !this.isAnswered || (this.isFlushing = !0, this.candidates.forEach(function (e) {
  5675. var t = atob(e),
  5676. r = JSON.parse(t);
  5677. if (/172\./.test(r.candidate)) return;
  5678. var n = new RTCIceCandidate(r);
  5679. _this2.connection && _this2.connection.addIceCandidate(n).then(function () {}, function (o) {
  5680. logger.info("add candidate failed", o);
  5681. });
  5682. }), this.isFlushing = !1);
  5683. }
  5684. }, {
  5685. key: "input",
  5686. value: function input(e) {
  5687. var t;
  5688. !this.actived || !this.inputChannel || this.inputChannel.readyState === "open" && ((t = this.inputChannel) == null || t.send(e));
  5689. }
  5690. }, {
  5691. key: "start",
  5692. value: function start() {
  5693. var _this3 = this;
  5694. this.connection = new RTCPeerConnection();
  5695. var e = Date.now();
  5696. this.connection.ondatachannel = function (t) {
  5697. logger.info("ondatachannel: ".concat(t.channel.label));
  5698. _this3.inputChannel = t.channel;
  5699. _this3.inputChannel.onopen = function () {
  5700. var r;
  5701. logger.info("The input channel has opened, id:", (r = _this3.inputChannel) == null ? void 0 : r.id), _this3.inputReady = !0, _this3.emit("rtcConnected"), _this3.network.room.currentNetworkOptions.reconnect || (logger.infoAndReportMeasurement({
  5702. metric: "datachannelOpenedAt",
  5703. startTime: _this3.network.room._startTime,
  5704. group: "joinRoom"
  5705. }), logger.infoAndReportMeasurement({
  5706. metric: "datachannelOpenedCost",
  5707. startTime: e,
  5708. group: "joinRoom"
  5709. }));
  5710. }, _this3.inputChannel.onclose = function () {
  5711. var r;
  5712. return logger.info("The input channel has closed, id:", (r = _this3.inputChannel) == null ? void 0 : r.id);
  5713. }, _this3.inputChannel.onmessage = function (r) {
  5714. _this3.workers.dataHandle(r.data);
  5715. };
  5716. }, this.connection.oniceconnectionstatechange = this.onIceConnectionStateChange, this.connection.onicegatheringstatechange = this.onIceStateChange, this.connection.onicecandidate = this.onIcecandidate, this.connection.onicecandidateerror = this.onIcecandidateerror, this.network.socket.send({
  5717. id: "init_webrtc",
  5718. data: JSON.stringify({
  5719. is_mobile: !0
  5720. })
  5721. });
  5722. }
  5723. }, {
  5724. key: "addCandidate",
  5725. value: function addCandidate(e) {
  5726. e === "" ? this.network.rtcp.flushCandidate() : this.candidates.push(e);
  5727. }
  5728. }, {
  5729. key: "disconnect",
  5730. value: function disconnect() {
  5731. var e, t, r;
  5732. this.heartbeat.stop(), logger.info("ready to close datachannel, id", (e = this.inputChannel) == null ? void 0 : e.id), (t = this.inputChannel) == null || t.close(), (r = this.connection) == null || r.close(), this.connection = null, this.inputChannel = null;
  5733. }
  5734. }, {
  5735. key: "sendStringData",
  5736. value: function sendStringData(e) {
  5737. console.log('e', e);
  5738. this.input(e);
  5739. }
  5740. }, {
  5741. key: "sendData",
  5742. value: function sendData(e) {
  5743. var t = "";
  5744. try {
  5745. t = JSON.stringify(e);
  5746. } catch (r) {
  5747. logger.error(r);
  5748. return;
  5749. }
  5750. this.input(t);
  5751. }
  5752. }]);
  5753. return Rtcp;
  5754. }(EventEmitter);
  5755. var NetworkMonitor = /*#__PURE__*/function () {
  5756. function NetworkMonitor(e) {
  5757. _classCallCheck(this, NetworkMonitor);
  5758. this._listener = e;
  5759. }
  5760. _createClass(NetworkMonitor, [{
  5761. key: "isOnline",
  5762. get: function get() {
  5763. var e = window.navigator;
  5764. return typeof e.onLine == "boolean" ? e.onLine : !0;
  5765. }
  5766. }, {
  5767. key: "start",
  5768. value: function start() {
  5769. window.addEventListener("online", this._listener), window.addEventListener("offline", this._listener);
  5770. }
  5771. }, {
  5772. key: "stop",
  5773. value: function stop() {
  5774. window.removeEventListener("online", this._listener), window.removeEventListener("offline", this._listener);
  5775. }
  5776. }]);
  5777. return NetworkMonitor;
  5778. }();
  5779. var Stream = /*#__PURE__*/function () {
  5780. function Stream(e) {
  5781. _classCallCheck(this, Stream);
  5782. this.el = null;
  5783. this._streamPlayTimer = null;
  5784. if (!e) {
  5785. this.el = this.createVideoElement();
  5786. return;
  5787. }
  5788. this.el = e;
  5789. }
  5790. _createClass(Stream, [{
  5791. key: "play",
  5792. value: function play() {
  5793. var _this = this;
  5794. return new Promise(function (e, t) {
  5795. _this._streamPlayTimer = new Timeout(function () {
  5796. t(new InternalError("Stream play timeout"));
  5797. }, 5e3), _this.el && _this.el.play().then(function () {
  5798. var r;
  5799. e(), logger.info("Media can autoplay"), (r = _this._streamPlayTimer) == null || r.clear();
  5800. }).catch(function (r) {
  5801. var n;
  5802. logger.error("Media Failed to autoplay"), logger.error(r), t(new InternalError("Media Failed to autoplay")), (n = _this._streamPlayTimer) == null || n.clear();
  5803. });
  5804. });
  5805. }
  5806. }, {
  5807. key: "createVideoElement",
  5808. value: function createVideoElement() {
  5809. var e = document.createElement("video");
  5810. 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;
  5811. }
  5812. }]);
  5813. return Stream;
  5814. }();
  5815. 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); }; }
  5816. 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; } }
  5817. 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 ";
  5818. var NetworkController = /*#__PURE__*/function (_EventEmitter) {
  5819. _inherits(NetworkController, _EventEmitter);
  5820. var _super = _createSuper$4(NetworkController);
  5821. function NetworkController(e) {
  5822. var _this;
  5823. _classCallCheck(this, NetworkController);
  5824. _this = _super.call(this);
  5825. _this.socket = null;
  5826. _this.rtcp = null;
  5827. _this.stream = null;
  5828. _this._state = 'connecting';
  5829. _this._networkMonitor = null;
  5830. _this.blockedActions = [];
  5831. _this.reconnectCount = 0;
  5832. _this.room = e, _this.socket = new Socket(_assertThisInitialized(_this));
  5833. _this.rtcp = new Rtcp(_assertThisInitialized(_this));
  5834. _this.stream = new Stream();
  5835. _this._networkMonitor = new NetworkMonitor(function () {
  5836. logger.info("network changed, online:", _this._networkMonitor.isOnline), _this._state === "disconnected" && _this._networkMonitor.isOnline && (logger.info("network back to online, try to reconnect"), _this.reconnect());
  5837. });
  5838. _this.checkNetworkQuality(_this.room.currentNetworkOptions.wsServerUrl);
  5839. _this._networkMonitor.start();
  5840. new VisibilityChangeHandler().subscribe(function (r) {
  5841. var n, o;
  5842. r ? ((o = _this.room.stats) == null || o.disable(), logger.infoAndReportMeasurement({
  5843. metric: "pageHide",
  5844. startTime: Date.now()
  5845. })) : ((n = _this.room.stats) == null || n.enable(), logger.infoAndReportMeasurement({
  5846. metric: "pageShow",
  5847. startTime: Date.now(),
  5848. extra: {
  5849. state: _this._state
  5850. }
  5851. }), _this._state === "disconnected" && _this.reconnect());
  5852. });
  5853. return _this;
  5854. }
  5855. _createClass(NetworkController, [{
  5856. key: "startGame",
  5857. value: function startGame() {
  5858. var _this2 = this;
  5859. debugger;
  5860. return new Promise(function (e, t) {
  5861. if (!_this2.rtcp.connected) return t(new InternalError("Game cannot load. Please refresh"));
  5862. if (!_this2.rtcp.inputReady) return t(new InternalError("Game is not ready yet. Please wait"));
  5863. _this2.socket.on("gameRoomAvailable", function (r) {
  5864. _this2.setState("connected"), e(r), _this2.rtcp.heartbeat.start();
  5865. }), _this2.socket.on("socketClosed", function (r) {
  5866. t(r);
  5867. }), _this2.socket.startGame();
  5868. });
  5869. }
  5870. }, {
  5871. key: "addBlockedActions",
  5872. value: function addBlockedActions(e) {
  5873. var _this$blockedActions;
  5874. (_this$blockedActions = this.blockedActions).push.apply(_this$blockedActions, _toConsumableArray(e));
  5875. }
  5876. }, {
  5877. key: "removeBlockedActions",
  5878. value: function removeBlockedActions(e) {
  5879. if (!e) {
  5880. this.blockedActions = [];
  5881. return;
  5882. }
  5883. var t = this.blockedActions.indexOf(e);
  5884. this.blockedActions.splice(t, 1);
  5885. }
  5886. }, {
  5887. key: "setState",
  5888. value: function setState(e) {
  5889. this._state !== e && (logger.info("Set network state to ", e), this._state = e);
  5890. }
  5891. }, {
  5892. key: "connectAndStart",
  5893. value: function () {
  5894. var _connectAndStart = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  5895. return regenerator.wrap(function _callee$(_context) {
  5896. while (1) {
  5897. switch (_context.prev = _context.next) {
  5898. case 0:
  5899. return _context.abrupt("return", this.connect(e).then(this.startGame));
  5900. case 1:
  5901. case "end":
  5902. return _context.stop();
  5903. }
  5904. }
  5905. }, _callee, this);
  5906. }));
  5907. function connectAndStart(_x) {
  5908. return _connectAndStart.apply(this, arguments);
  5909. }
  5910. return connectAndStart;
  5911. }()
  5912. }, {
  5913. key: "connect",
  5914. value: function () {
  5915. var _connect = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  5916. var _this3 = this;
  5917. var e,
  5918. _args2 = arguments;
  5919. return regenerator.wrap(function _callee2$(_context2) {
  5920. while (1) {
  5921. switch (_context2.prev = _context2.next) {
  5922. case 0:
  5923. e = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : !1;
  5924. this.room.updateCurrentNetworkOptions({
  5925. reconnect: e
  5926. });
  5927. return _context2.abrupt("return", new Promise(function (t, r) {
  5928. _this3.rtcp.on("rtcConnected", function () {
  5929. debugger;
  5930. _this3.setState("connected"), t();
  5931. }), _this3.rtcp.on("rtcDisconnected", function () {
  5932. logger.info("rtc disconnected"), _this3._state === "connecting" ? (_this3.setState("disconnected"), r(new InternalError("rtc connect failed"))) : (_this3.setState("disconnected"), logger.info("rtc disconnected, start to reconnect"), _this3.reconnect());
  5933. }), _this3.socket.on("socketQuit", function () {
  5934. logger.info("socket quit success"), _this3.setState("closed");
  5935. }), _this3.socket.on("socketClosed", function (n) {
  5936. _this3._state === "connecting" && (_this3.setState("disconnected"), r(n)), r(n);
  5937. }), _this3.socket.start();
  5938. }));
  5939. case 3:
  5940. case "end":
  5941. return _context2.stop();
  5942. }
  5943. }
  5944. }, _callee2, this);
  5945. }));
  5946. function connect() {
  5947. return _connect.apply(this, arguments);
  5948. }
  5949. return connect;
  5950. }()
  5951. }, {
  5952. key: "reconnect",
  5953. value: function reconnect() {
  5954. var _this4 = this;
  5955. if (this.room.viewMode === "observer") return;
  5956. var e = Date.now();
  5957. if (this.reconnectCount++, this.reconnectCount > MAX_RECONNECT_COUNT) {
  5958. logger.error("reconnect failed, reached max reconnect count", MAX_RECONNECT_COUNT), this.reconnectCount = 0, this.emit("stateChanged", {
  5959. state: "disconnected"
  5960. });
  5961. return;
  5962. }
  5963. return logger.info("start reconnect, count:", this.reconnectCount), this._reconnect().then(function () {
  5964. logger.infoAndReportMeasurement({
  5965. startTime: e,
  5966. metric: "reconnect"
  5967. });
  5968. }).catch(function (t) {
  5969. if (logger.infoAndReportMeasurement({
  5970. startTime: e,
  5971. metric: "reconnect",
  5972. error: t
  5973. }), t.code === Codes.RepeatLogin) {
  5974. _this4.room.handleRepetLogin();
  5975. return;
  5976. }
  5977. var r = 1e3;
  5978. logger.info("reconnect failed, wait " + r + " ms for next reconnect"), setTimeout(function () {
  5979. _this4.reconnect();
  5980. }, r);
  5981. });
  5982. }
  5983. }, {
  5984. key: "_reconnect",
  5985. value: function _reconnect() {
  5986. var _this5 = this;
  5987. return this._state === "closed" ? (logger.warn("connection closed already"), Promise.reject()) : this._state === "connecting" ? (logger.warn("connection is already in connecting state"), Promise.reject()) : this._state !== "disconnected" ? Promise.reject() : (this.prepareReconnect(), this._state = "connecting", this.emit("stateChanged", {
  5988. state: "reconnecting",
  5989. count: this.reconnectCount
  5990. }), this.socket.off("gameRoomAvailable"), this.socket.off("socketClosed"), this.rtcp.off("rtcDisconnected"), this.rtcp.off("rtcConnected"), this.connectAndStart(!0).then(function (_ref) {
  5991. var e = _ref.session_id;
  5992. _this5.room.updateCurrentNetworkOptions({
  5993. sessionId: e
  5994. }), reporter.updateBody({
  5995. serverSession: e
  5996. }), logger.info("reconnect success"), _this5.setState("connected"), _this5.reconnectCount = 0, _this5.emit("stateChanged", {
  5997. state: "reconnected"
  5998. });
  5999. }));
  6000. }
  6001. }, {
  6002. key: "prepareReconnect",
  6003. value: function prepareReconnect() {
  6004. this.rtcp.disconnect(), this.socket.prepareReconnect(), this.prepareReconnectOptions();
  6005. }
  6006. }, {
  6007. key: "prepareReconnectOptions",
  6008. value: function prepareReconnectOptions() {
  6009. var _ref2 = this.room.currentClickingState || {},
  6010. e = _ref2.camera,
  6011. t = _ref2.player;
  6012. e && t && this.room.updateCurrentNetworkOptions({
  6013. camera: e,
  6014. player: t
  6015. });
  6016. }
  6017. }, {
  6018. key: "sendRtcData",
  6019. value: function sendRtcData(e) {
  6020. if (this.blockedActions.includes(e.action_type)) {
  6021. logger.info("action: ".concat(Actions[e.action_type], " was blocked"));
  6022. return;
  6023. }
  6024. this.rtcp.sendData(e);
  6025. }
  6026. }, {
  6027. key: "sendSocketData",
  6028. value: function sendSocketData(e) {
  6029. logger.debug("ws send ->", e), this.socket.send(e);
  6030. }
  6031. }, {
  6032. key: "quit",
  6033. value: function quit() {
  6034. var e = uuid$1(),
  6035. t = {
  6036. action_type: Actions.Exit,
  6037. trace_id: e,
  6038. exit_action: {},
  6039. user_id: this.room.options.userId,
  6040. packet_id: e
  6041. };
  6042. this.setState("closed"), this.socket.quit(), this.sendRtcData(t);
  6043. }
  6044. }, {
  6045. key: "checkNetworkQuality",
  6046. value: function checkNetworkQuality(i) {
  6047. var worker = null;
  6048. if (!i) return;
  6049. var e = Date.now();
  6050. if (this.pingOthers("https://www.baidu.com", function (t, r) {
  6051. logger.infoAndReportMeasurement({
  6052. metric: "baiduRtt",
  6053. group: "http",
  6054. value: r,
  6055. startTime: e
  6056. });
  6057. }), !worker) {
  6058. var t = new Blob([workerSourceCode], {
  6059. type: "application/javascript"
  6060. });
  6061. worker = new Worker(URL.createObjectURL(t)), worker.onmessage = function (r) {
  6062. logger.infoAndReportMeasurement({
  6063. metric: "workerRtt",
  6064. group: "http",
  6065. startTime: e,
  6066. value: r.data
  6067. });
  6068. };
  6069. }
  6070. }
  6071. }, {
  6072. key: "pingOthers",
  6073. value: function pingOthers(i, e) {
  6074. var t = !1;
  6075. var r = new Image();
  6076. r.onload = o, r.onerror = a;
  6077. var n = Date.now();
  6078. function o(l) {
  6079. t = !0, s();
  6080. }
  6081. function a(l) {}
  6082. function s() {
  6083. var l = Date.now() - n;
  6084. if (typeof e == "function") return t ? e(null, l) : (console.error("error loading resource"), e("error", l));
  6085. }
  6086. r.src = i + "/favicon.ico?" + +new Date();
  6087. }
  6088. }]);
  6089. return NetworkController;
  6090. }(EventEmitter);
  6091. 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); }; }
  6092. 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; } }
  6093. var InitConfigTimeoutError = /*#__PURE__*/function (_XverseError) {
  6094. _inherits(InitConfigTimeoutError, _XverseError);
  6095. var _super = _createSuper$3(InitConfigTimeoutError);
  6096. function InitConfigTimeoutError(e) {
  6097. _classCallCheck(this, InitConfigTimeoutError);
  6098. return _super.call(this, 1009, e || "\u914D\u7F6E\u521D\u59CB\u5316\u8D85\u65F6");
  6099. }
  6100. return _createClass(InitConfigTimeoutError);
  6101. }(XverseError);
  6102. 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); }; }
  6103. 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; } }
  6104. var Xverse_Room = /*#__PURE__*/function (_EventEmitter) {
  6105. _inherits(Xverse_Room, _EventEmitter);
  6106. var _super = _createSuper$2(Xverse_Room);
  6107. function Xverse_Room(e) {
  6108. var _this;
  6109. _classCallCheck(this, Xverse_Room);
  6110. _this = _super.call(this);
  6111. _this.disableAutoTurn = !1;
  6112. _this._currentNetworkOptions = null;
  6113. _this.lastSkinId = null;
  6114. _this.debug = null;
  6115. _this.isFirstDataUsed = !1;
  6116. _this.userId = null;
  6117. _this.pathManager = new PathManager();
  6118. _this.networkController = null;
  6119. _this._startTime = Date.now();
  6120. _this.canvas = null;
  6121. _this.eventsController = null;
  6122. _this.panorama = null;
  6123. _this.engineProxy = null;
  6124. _this._id = null;
  6125. _this.skinList = [];
  6126. _this.isHost = !1;
  6127. _this.avatarManager = new XverseAvatarManager(_assertThisInitialized(_this));
  6128. _this.effectManager = new XverseAvatarManager(_assertThisInitialized(_this));
  6129. _this.sceneManager = null;
  6130. _this.scene = null;
  6131. _this.breathPointManager = null;
  6132. _this._currentState = null;
  6133. _this.joined = !1;
  6134. _this.disableRotate = !1;
  6135. _this.isPano = !1;
  6136. _this.movingByClick = !0;
  6137. _this.camera = new Camera(_assertThisInitialized(_this));
  6138. _this.stats = new Stats(_assertThisInitialized(_this));
  6139. _this.isUpdatedRawYUVData = !1;
  6140. _this.actionsHandler = new ActionsHandler(_assertThisInitialized(_this));
  6141. _this._currentClickingState = null;
  6142. _this.signal = new Signal(_assertThisInitialized(_this));
  6143. _this.firstFrameTimestamp = null;
  6144. _this.moveToExtra = '';
  6145. _this.options = e;
  6146. _this.options.wsServerUrl || (_this.options.wsServerUrl = SERVER_URLS.DEV);
  6147. _this.modelManager = ModelManager.getInstance(e.appId, e.releaseId), _this.updateReporter();
  6148. var n = e;
  6149. n.canvas;
  6150. var r = Oe(n, ["canvas"]);
  6151. logger.infoAndReportMeasurement({
  6152. metric: "startJoinRoomAt",
  6153. startTime: Date.now(),
  6154. group: "joinRoom",
  6155. extra: r,
  6156. value: 0
  6157. });
  6158. return _this;
  6159. }
  6160. _createClass(Xverse_Room, [{
  6161. key: "receiveRtcData",
  6162. value: function () {
  6163. var _receiveRtcData = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  6164. var _this2 = this;
  6165. var e, t, r, n;
  6166. return regenerator.wrap(function _callee$(_context) {
  6167. while (1) {
  6168. switch (_context.prev = _context.next) {
  6169. case 0:
  6170. logger.info("Invoke receiveRtcData");
  6171. e = !1, t = !1, r = !1, n = !1;
  6172. return _context.abrupt("return", this.viewMode === "serverless" ? (logger.warn("set view mode to serverless"), this.setViewMode("observer").then(function () {
  6173. return _this2;
  6174. }, function () {
  6175. return _this2;
  6176. })) : new Promise(function (o) {
  6177. var a = _this2.networkController.rtcp.workers;
  6178. a.registerFunction("signal", function (s) {
  6179. _this2.signal.handleSignal(s);
  6180. }), a.registerFunction("stream", function (s) {
  6181. var l;
  6182. if (_this2.emit("streamTimestamp", {
  6183. timestamp: Date.now()
  6184. }), t || (t = !0, logger.info("Invoke stream event")), s.stream) {
  6185. r || (r = !0, logger.info("Invoke updateRawYUVData")), _this2.isUpdatedRawYUVData = !1;
  6186. var u = (l = _this2._currentState.skin) == null ? void 0 : l.fov;
  6187. _this2.sceneManager.materialComponent.updateRawYUVData(s.stream, s.width, s.height, u), _this2.isUpdatedRawYUVData = !0;
  6188. }
  6189. e || (logger.info("Invoke isAfterRenderRegistered"), e = !0, _this2.scene.registerAfterRender(function () {
  6190. _this2.engineProxy.frameRenderNumber >= 2 && (n || (n = !0, logger.info("Invoke registerAfterRender")), _this2.isFirstDataUsed || (logger.info("Invoke isStreamAvailable"), _this2.isFirstDataUsed = !0, _this2.firstFrameTimestamp = Date.now(), o(_this2), _this2.afterJoinRoom()));
  6191. }));
  6192. }), _this2.panorama.bindListener(function () {
  6193. o(_this2), _this2.afterJoinRoom();
  6194. }), a.registerFunction("reconnectedFrame", function () {}), logger.info("Invoke decoderWorker.postMessage"), a.decoderWorker.postMessage({
  6195. t: 5
  6196. });
  6197. }));
  6198. case 3:
  6199. case "end":
  6200. return _context.stop();
  6201. }
  6202. }
  6203. }, _callee, this);
  6204. }));
  6205. function receiveRtcData() {
  6206. return _receiveRtcData.apply(this, arguments);
  6207. }
  6208. return receiveRtcData;
  6209. }()
  6210. }, {
  6211. key: "currentNetworkOptions",
  6212. get: function get() {
  6213. return this._currentNetworkOptions;
  6214. }
  6215. }, {
  6216. key: "viewMode",
  6217. get: function get() {
  6218. var e;
  6219. return ((e = this._currentState) == null ? void 0 : e.viewMode) || "full";
  6220. }
  6221. }, {
  6222. key: "id",
  6223. get: function get() {
  6224. return this._id;
  6225. }
  6226. }, {
  6227. key: "skinId",
  6228. get: function get() {
  6229. return this._currentState.skinId;
  6230. }
  6231. }, {
  6232. key: "skin",
  6233. get: function get() {
  6234. return this._currentState.skin;
  6235. }
  6236. }, {
  6237. key: "sessionId",
  6238. get: function get() {
  6239. return this.currentNetworkOptions.sessionId;
  6240. }
  6241. }, {
  6242. key: "pictureQualityLevel",
  6243. get: function get() {
  6244. return this.currentState.pictureQualityLevel;
  6245. }
  6246. }, {
  6247. key: "avatars",
  6248. get: function get() {
  6249. return Array.from(this.avatarManager.avatars.values());
  6250. }
  6251. }, {
  6252. key: "currentState",
  6253. get: function get() {
  6254. var e;
  6255. return le(oe({}, this._currentState), {
  6256. state: (e = this.networkController) == null ? void 0 : e._state
  6257. });
  6258. }
  6259. }, {
  6260. key: "_userAvatar",
  6261. get: function get() {
  6262. var _this3 = this;
  6263. return this.avatars.find(function (e) {
  6264. return e.userId === _this3.userId;
  6265. });
  6266. }
  6267. }, {
  6268. key: "tvs",
  6269. get: function get() {
  6270. return this.engineProxy._tvs;
  6271. }
  6272. }, {
  6273. key: "tv",
  6274. get: function get() {
  6275. return this.tvs[0];
  6276. }
  6277. }, {
  6278. key: "currentClickingState",
  6279. get: function get() {
  6280. return this._currentClickingState;
  6281. }
  6282. }, {
  6283. key: "afterJoinRoomHook",
  6284. value: function afterJoinRoomHook() {}
  6285. }, {
  6286. key: "beforeJoinRoomResolveHook",
  6287. value: function beforeJoinRoomResolveHook() {}
  6288. }, {
  6289. key: "afterReconnectedHook",
  6290. value: function afterReconnectedHook() {}
  6291. }, {
  6292. key: "handleSignalHook",
  6293. value: function handleSignalHook(e) {}
  6294. }, {
  6295. key: "skinChangedHook",
  6296. value: function skinChangedHook() {}
  6297. }, {
  6298. key: "beforeStartGameHook",
  6299. value: function () {
  6300. var _beforeStartGameHook = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  6301. return regenerator.wrap(function _callee2$(_context2) {
  6302. while (1) {
  6303. switch (_context2.prev = _context2.next) {
  6304. case 0:
  6305. case "end":
  6306. return _context2.stop();
  6307. }
  6308. }
  6309. }, _callee2);
  6310. }));
  6311. function beforeStartGameHook(_x) {
  6312. return _beforeStartGameHook.apply(this, arguments);
  6313. }
  6314. return beforeStartGameHook;
  6315. }()
  6316. }, {
  6317. key: "loadAssetsHook",
  6318. value: function loadAssetsHook() {}
  6319. }, {
  6320. key: "afterUserAvatarLoadedHook",
  6321. value: function afterUserAvatarLoadedHook() {}
  6322. }, {
  6323. key: "audienceViewModeHook",
  6324. value: function audienceViewModeHook() {}
  6325. }, {
  6326. key: "setViewModeToObserver",
  6327. value: function setViewModeToObserver() {}
  6328. }, {
  6329. key: "handleVehicleHook",
  6330. value: function handleVehicleHook(e) {}
  6331. }, {
  6332. key: "updateReporter",
  6333. value: function updateReporter() {
  6334. var _this$options = this.options,
  6335. e = _this$options.avatarId,
  6336. t = _this$options.skinId,
  6337. r = _this$options.userId,
  6338. n = _this$options.roomId,
  6339. o = _this$options.role,
  6340. a = _this$options.appId,
  6341. s = _this$options.wsServerUrl;
  6342. reporter$1.updateHeader({
  6343. userId: r
  6344. }), reporter$1.updateBody({
  6345. roomId: n,
  6346. role: o,
  6347. skinId: t,
  6348. avatarId: e,
  6349. appId: a,
  6350. wsServerUrl: s
  6351. });
  6352. }
  6353. }, {
  6354. key: "initRoom",
  6355. value: function () {
  6356. var _initRoom2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  6357. var _this$options$timeout, e;
  6358. return regenerator.wrap(function _callee3$(_context3) {
  6359. while (1) {
  6360. switch (_context3.prev = _context3.next) {
  6361. case 0:
  6362. _this$options$timeout = this.options.timeout, e = _this$options$timeout === void 0 ? DEFAULT_JOINROOM_TIMEOUT : _this$options$timeout;
  6363. if (!util.isSupported()) {
  6364. _context3.next = 5;
  6365. break;
  6366. }
  6367. return _context3.abrupt("return", this._initRoom()._timeout(e, new TimeoutError("initRoom timeout")));
  6368. case 5:
  6369. return _context3.abrupt("return", Promise.reject(new UnsupportedError()));
  6370. case 6:
  6371. case "end":
  6372. return _context3.stop();
  6373. }
  6374. }
  6375. }, _callee3, this);
  6376. }));
  6377. function initRoom() {
  6378. return _initRoom2.apply(this, arguments);
  6379. }
  6380. return initRoom;
  6381. }()
  6382. }, {
  6383. key: "_initRoom",
  6384. value: function () {
  6385. var _initRoom3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  6386. 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;
  6387. return regenerator.wrap(function _callee4$(_context4) {
  6388. while (1) {
  6389. switch (_context4.prev = _context4.next) {
  6390. case 0:
  6391. e = this.validateOptions(this.options);
  6392. if (!e) {
  6393. _context4.next = 3;
  6394. break;
  6395. }
  6396. return _context4.abrupt("return", (logger.error("initRoom param error", e), Promise.reject(e)));
  6397. case 3:
  6398. _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;
  6399. this.setCurrentNetworkOptions({
  6400. avatarId: r,
  6401. skinId: n,
  6402. roomId: R,
  6403. userId: o,
  6404. wsServerUrl: a,
  6405. role: s,
  6406. token: l,
  6407. pageSession: u,
  6408. rotationRenderType: c,
  6409. isAllSync: h,
  6410. appId: f,
  6411. camera: d,
  6412. player: _,
  6413. avatarComponents: g,
  6414. nickname: m,
  6415. avatarScale: v,
  6416. firends: y,
  6417. syncByEvent: b,
  6418. areaName: T,
  6419. attitude: C,
  6420. pathName: A,
  6421. person: P,
  6422. roomTypeId: M,
  6423. hasAvatar: x,
  6424. syncToOthers: I,
  6425. prioritySync: w,
  6426. extra: D,
  6427. removeWhenDisconnected: O
  6428. });
  6429. this.userId = o;
  6430. this.canvas = t;
  6431. T && (this.pathManager.currentArea = T);
  6432. this.networkController = new NetworkController(this);
  6433. this.setCurrentState({
  6434. areaName: T,
  6435. pathName: A,
  6436. attitude: C,
  6437. speed: 0,
  6438. viewMode: S,
  6439. state: this.networkController._state,
  6440. skinId: n
  6441. });
  6442. _context4.prev = 10;
  6443. _context4.next = 13;
  6444. return Promise.all([this.initNetwork(), this.initConfig(), this.initWasm()]);
  6445. case 13:
  6446. logger.info("network config wasm all ready, start to create game");
  6447. _context4.next = 16;
  6448. return this.requestCreateRoom({
  6449. skinId: n
  6450. });
  6451. case 16:
  6452. F = _context4.sent;
  6453. V = F.routeList.find(function (L) {
  6454. return L.areaName === T;
  6455. });
  6456. N = ((V == null ? void 0 : V.step) || 7.5) * 30;
  6457. this.updateCurrentState({
  6458. skin: F,
  6459. skinId: F.id,
  6460. versionId: F.versionId,
  6461. speed: N
  6462. });
  6463. _context4.next = 22;
  6464. return this.initEngine(F);
  6465. case 22:
  6466. _context4.next = 27;
  6467. break;
  6468. case 24:
  6469. _context4.prev = 24;
  6470. _context4.t0 = _context4["catch"](10);
  6471. return _context4.abrupt("return", Promise.reject(_context4.t0));
  6472. case 27:
  6473. return _context4.abrupt("return", (this.beforeJoinRoomResolve(), this.receiveRtcData()));
  6474. case 28:
  6475. case "end":
  6476. return _context4.stop();
  6477. }
  6478. }
  6479. }, _callee4, this, [[10, 24]]);
  6480. }));
  6481. function _initRoom() {
  6482. return _initRoom3.apply(this, arguments);
  6483. }
  6484. return _initRoom;
  6485. }()
  6486. }, {
  6487. key: "beforeJoinRoomResolve",
  6488. value: function beforeJoinRoomResolve() {
  6489. this.setupStats(), this.eventsController = new EventsController(this), this.eventsController.bindEvents(), this.panorama = new Panorama(this), this.beforeJoinRoomResolveHook();
  6490. }
  6491. }, {
  6492. key: "afterJoinRoom",
  6493. value: function afterJoinRoom() {
  6494. this.joined = !0, this.viewMode === "observer" && this.setViewModeToObserver(), logger.infoAndReportMeasurement({
  6495. tag: this.viewMode,
  6496. value: this.firstFrameTimestamp - this._startTime,
  6497. startTime: Date.now(),
  6498. metric: "joinRoom"
  6499. }), this.camera.initialFov = this.sceneManager.cameraComponent.getCameraFov(), this.stats.on("stats", function (_ref) {
  6500. var e = _ref.stats;
  6501. reporter$1.report("stats", oe({}, e));
  6502. }), this.debug = new Debug(this), this.afterJoinRoomHook();
  6503. }
  6504. }, {
  6505. key: "afterReconnected",
  6506. value: function afterReconnected() {
  6507. this.avatarManager.clearOtherUsers(), this.afterReconnectedHook();
  6508. }
  6509. }, {
  6510. key: "leave",
  6511. value: function leave() {
  6512. var e, t;
  6513. return logger.info("Invoke room.leave"), (e = this.eventsController) == null || e.clearEvents(), (t = this.networkController) == null || t.quit(), this;
  6514. }
  6515. }, {
  6516. key: "validateOptions",
  6517. value: function validateOptions(e) {
  6518. var _ref2 = e || {},
  6519. t = _ref2.canvas,
  6520. r = _ref2.avatarId,
  6521. n = _ref2.skinId,
  6522. o = _ref2.userId,
  6523. a = _ref2.role;
  6524. _ref2.roomId;
  6525. var l = _ref2.token,
  6526. u = _ref2.appId;
  6527. _ref2.avatarComponents;
  6528. var h = [];
  6529. t instanceof HTMLCanvasElement || h.push(new ParamError$1("`canvas` must be instanceof of HTMLCanvasElement"));
  6530. (!o || typeof o != "string") && h.push(new ParamError$1("`userId` must be string"));
  6531. (!l || typeof l != "string") && h.push(new ParamError$1("`token` must be string"));
  6532. (!u || typeof u != "string") && h.push(new ParamError$1("`appId` must be string"));
  6533. a == "audience" || (!r || !n) && h.push(new ParamError$1("`avatarId` and `skinId` is required when create room"));
  6534. return h[0];
  6535. }
  6536. }, {
  6537. key: "initNetwork",
  6538. value: function () {
  6539. var _initNetwork = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  6540. var e;
  6541. return regenerator.wrap(function _callee5$(_context5) {
  6542. while (1) {
  6543. switch (_context5.prev = _context5.next) {
  6544. case 0:
  6545. if (!(this.viewMode === "serverless")) {
  6546. _context5.next = 2;
  6547. break;
  6548. }
  6549. return _context5.abrupt("return", Promise.resolve());
  6550. case 2:
  6551. e = Date.now();
  6552. _context5.prev = 3;
  6553. _context5.next = 6;
  6554. return this.networkController.connect()._timeout(8e3, new InitNetworkTimeoutError());
  6555. case 6:
  6556. logger.infoAndReportMeasurement({
  6557. metric: "networkInitAt",
  6558. startTime: this._startTime,
  6559. group: "joinRoom"
  6560. });
  6561. logger.infoAndReportMeasurement({
  6562. metric: "networkInitCost",
  6563. startTime: e,
  6564. group: "joinRoom"
  6565. });
  6566. _context5.next = 13;
  6567. break;
  6568. case 10:
  6569. _context5.prev = 10;
  6570. _context5.t0 = _context5["catch"](3);
  6571. throw logger.infoAndReportMeasurement({
  6572. metric: "networkInitAt",
  6573. startTime: e,
  6574. group: "joinRoom",
  6575. error: _context5.t0
  6576. }), _context5.t0;
  6577. case 13:
  6578. case "end":
  6579. return _context5.stop();
  6580. }
  6581. }
  6582. }, _callee5, this, [[3, 10]]);
  6583. }));
  6584. function initNetwork() {
  6585. return _initNetwork.apply(this, arguments);
  6586. }
  6587. return initNetwork;
  6588. }()
  6589. }, {
  6590. key: "initConfig",
  6591. value: function () {
  6592. var _initConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  6593. var e;
  6594. return regenerator.wrap(function _callee6$(_context6) {
  6595. while (1) {
  6596. switch (_context6.prev = _context6.next) {
  6597. case 0:
  6598. e = Date.now();
  6599. _context6.prev = 1;
  6600. _context6.next = 4;
  6601. return this.modelManager.getApplicationConfig()._timeout(8e3, new InitConfigTimeoutError());
  6602. case 4:
  6603. logger.infoAndReportMeasurement({
  6604. metric: "configInitAt",
  6605. startTime: this._startTime,
  6606. group: "joinRoom"
  6607. });
  6608. logger.infoAndReportMeasurement({
  6609. metric: "configInitCost",
  6610. startTime: e,
  6611. group: "joinRoom"
  6612. });
  6613. _context6.next = 11;
  6614. break;
  6615. case 8:
  6616. _context6.prev = 8;
  6617. _context6.t0 = _context6["catch"](1);
  6618. throw logger.infoAndReportMeasurement({
  6619. metric: "configInitAt",
  6620. startTime: e,
  6621. group: "joinRoom",
  6622. error: _context6.t0
  6623. }), _context6.t0;
  6624. case 11:
  6625. case "end":
  6626. return _context6.stop();
  6627. }
  6628. }
  6629. }, _callee6, this, [[1, 8]]);
  6630. }));
  6631. function initConfig() {
  6632. return _initConfig.apply(this, arguments);
  6633. }
  6634. return initConfig;
  6635. }()
  6636. }, {
  6637. key: "initEngine",
  6638. value: function () {
  6639. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  6640. var t, n;
  6641. return regenerator.wrap(function _callee7$(_context7) {
  6642. while (1) {
  6643. switch (_context7.prev = _context7.next) {
  6644. case 0:
  6645. t = Date.now();
  6646. _context7.prev = 1;
  6647. this.engineProxy = new EngineProxy(this);
  6648. _context7.next = 5;
  6649. return this.engineProxy.initEngine(e);
  6650. case 5:
  6651. logger.infoAndReportMeasurement({
  6652. metric: "webglInitAt",
  6653. startTime: this._startTime,
  6654. group: "joinRoom"
  6655. });
  6656. logger.infoAndReportMeasurement({
  6657. metric: "webglInitCost",
  6658. startTime: t,
  6659. group: "joinRoom"
  6660. });
  6661. return _context7.abrupt("return");
  6662. case 10:
  6663. _context7.prev = 10;
  6664. _context7.t0 = _context7["catch"](1);
  6665. n = _context7.t0;
  6666. return _context7.abrupt("return", (_context7.t0.code !== Codes.InitEngineTimeout && (n = new InitEngineError()), logger.error(_context7.t0), logger.infoAndReportMeasurement({
  6667. metric: "webglInitAt",
  6668. startTime: t,
  6669. group: "joinRoom",
  6670. error: n
  6671. }), Promise.reject(n)));
  6672. case 14:
  6673. case "end":
  6674. return _context7.stop();
  6675. }
  6676. }
  6677. }, _callee7, this, [[1, 10]]);
  6678. }));
  6679. function initEngine(_x2) {
  6680. return _initEngine.apply(this, arguments);
  6681. }
  6682. return initEngine;
  6683. }()
  6684. }, {
  6685. key: "initWasm",
  6686. value: function () {
  6687. var _initWasm = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  6688. var _this4 = this;
  6689. var e;
  6690. return regenerator.wrap(function _callee8$(_context8) {
  6691. while (1) {
  6692. switch (_context8.prev = _context8.next) {
  6693. case 0:
  6694. if (!(this.viewMode === "serverless")) {
  6695. _context8.next = 2;
  6696. break;
  6697. }
  6698. return _context8.abrupt("return", Promise.resolve());
  6699. case 2:
  6700. e = Date.now();
  6701. _context8.prev = 3;
  6702. _context8.next = 6;
  6703. return this.networkController.rtcp.workers.init(this.options.resolution)._timeout(8e3, new InitDecoderTimeoutError());
  6704. case 6:
  6705. this.networkController.rtcp.workers.registerFunction("error", function (t) {
  6706. logger.error("decode error", t);
  6707. var r = t.code,
  6708. n = t.message;
  6709. _this4.emit("error", {
  6710. code: r,
  6711. msg: n
  6712. });
  6713. });
  6714. logger.infoAndReportMeasurement({
  6715. metric: "wasmInitAt",
  6716. group: "joinRoom",
  6717. startTime: this._startTime
  6718. });
  6719. logger.infoAndReportMeasurement({
  6720. metric: "wasmInitCost",
  6721. group: "joinRoom",
  6722. startTime: e
  6723. });
  6724. eventsManager.on("traceId", function (t) {
  6725. _this4.networkController.rtcp.workers.onTraceId(t);
  6726. });
  6727. _context8.next = 15;
  6728. break;
  6729. case 12:
  6730. _context8.prev = 12;
  6731. _context8.t0 = _context8["catch"](3);
  6732. throw logger.infoAndReportMeasurement({
  6733. metric: "wasmInitAt",
  6734. group: "joinRoom",
  6735. startTime: e,
  6736. error: _context8.t0
  6737. }), _context8.t0;
  6738. case 15:
  6739. case "end":
  6740. return _context8.stop();
  6741. }
  6742. }
  6743. }, _callee8, this, [[3, 12]]);
  6744. }));
  6745. function initWasm() {
  6746. return _initWasm.apply(this, arguments);
  6747. }
  6748. return initWasm;
  6749. }()
  6750. }, {
  6751. key: "requestCreateRoom",
  6752. value: function () {
  6753. var _requestCreateRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(_ref3) {
  6754. var e, t, r, _ref4, n, o, _yield$this$networkCo, _r, _n, _o, a, s;
  6755. return regenerator.wrap(function _callee9$(_context9) {
  6756. while (1) {
  6757. switch (_context9.prev = _context9.next) {
  6758. case 0:
  6759. e = _ref3.skinId;
  6760. if (!e) {
  6761. _context9.next = 11;
  6762. break;
  6763. }
  6764. _context9.next = 4;
  6765. return this.getSkin(e);
  6766. case 4:
  6767. t = _context9.sent;
  6768. _context9.next = 7;
  6769. return this.modelManager.findRoute(e, this.options.pathName);
  6770. case 7:
  6771. r = _context9.sent;
  6772. this.updateCurrentNetworkOptions({
  6773. areaName: r.areaName,
  6774. attitude: r.attitude,
  6775. versionId: t.versionId
  6776. });
  6777. _ref4 = getRandomItem(r.birthPointList) || this.options, n = _ref4.camera, o = _ref4.player;
  6778. this.options.camera || this.updateCurrentNetworkOptions({
  6779. camera: n
  6780. }), this.options.player || this.updateCurrentNetworkOptions({
  6781. player: o
  6782. });
  6783. case 11:
  6784. if (!(this.viewMode === "serverless")) {
  6785. _context9.next = 13;
  6786. break;
  6787. }
  6788. return _context9.abrupt("return", t);
  6789. case 13:
  6790. _context9.prev = 13;
  6791. _context9.next = 16;
  6792. return this.beforeStartGameHook(this.options);
  6793. case 16:
  6794. _context9.next = 18;
  6795. return this.networkController.startGame();
  6796. case 18:
  6797. _yield$this$networkCo = _context9.sent;
  6798. _r = _yield$this$networkCo.room_id;
  6799. _n = _yield$this$networkCo.data;
  6800. _o = _yield$this$networkCo.session_id;
  6801. this._id = _r;
  6802. a = JSON.parse(_n);
  6803. this.isHost = a.IsHost, e = a.SkinID || e;
  6804. _context9.next = 27;
  6805. return this.getSkin(e);
  6806. case 27:
  6807. s = _context9.sent;
  6808. return _context9.abrupt("return", (this.updateCurrentNetworkOptions({
  6809. roomId: _r,
  6810. sessionId: _o
  6811. }), reporter$1.updateBody({
  6812. roomId: _r,
  6813. skinId: e,
  6814. serverSession: _o
  6815. }), s));
  6816. case 31:
  6817. _context9.prev = 31;
  6818. _context9.t0 = _context9["catch"](13);
  6819. throw logger.error("Request create room error", _context9.t0), _context9.t0;
  6820. case 34:
  6821. case "end":
  6822. return _context9.stop();
  6823. }
  6824. }
  6825. }, _callee9, this, [[13, 31]]);
  6826. }));
  6827. function requestCreateRoom(_x3) {
  6828. return _requestCreateRoom.apply(this, arguments);
  6829. }
  6830. return requestCreateRoom;
  6831. }()
  6832. }, {
  6833. key: "pause",
  6834. value: function pause() {
  6835. return this.engineProxy.pause();
  6836. }
  6837. }, {
  6838. key: "resume",
  6839. value: function resume() {
  6840. return this.engineProxy.resume();
  6841. }
  6842. }, {
  6843. key: "reconnect",
  6844. value: function reconnect() {
  6845. this.networkController.reconnect();
  6846. }
  6847. }, {
  6848. key: "setViewMode",
  6849. value: function () {
  6850. var _setViewMode = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(e) {
  6851. return regenerator.wrap(function _callee10$(_context10) {
  6852. while (1) {
  6853. switch (_context10.prev = _context10.next) {
  6854. case 0:
  6855. case "end":
  6856. return _context10.stop();
  6857. }
  6858. }
  6859. }, _callee10);
  6860. }));
  6861. function setViewMode(_x4) {
  6862. return _setViewMode.apply(this, arguments);
  6863. }
  6864. return setViewMode;
  6865. }()
  6866. }, {
  6867. key: "handleRepetLogin",
  6868. value: function handleRepetLogin() {
  6869. logger.warn("receive " + Codes.RepeatLogin + " for repeat login"), this.emit("repeatLogin"), reporter$1.disable(), this.networkController.quit();
  6870. }
  6871. }, {
  6872. key: "setPictureQualityLevel",
  6873. value: function setPictureQualityLevel(e) {
  6874. var t = {
  6875. high: EImageQuality.high,
  6876. low: EImageQuality.low,
  6877. average: EImageQuality.mid
  6878. };
  6879. return this.updateCurrentState({
  6880. pictureQualityLevel: e
  6881. }), this.sceneManager.setImageQuality(t[e]);
  6882. }
  6883. }, {
  6884. key: "getSkin",
  6885. value: function () {
  6886. var _getSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  6887. var t, n;
  6888. return regenerator.wrap(function _callee11$(_context11) {
  6889. while (1) {
  6890. switch (_context11.prev = _context11.next) {
  6891. case 0:
  6892. t = null;
  6893. _context11.next = 3;
  6894. return this.modelManager.getSkinsList();
  6895. case 3:
  6896. t = (this.skinList = _context11.sent).find(function (n) {
  6897. return n.id === e || n.id === e;
  6898. });
  6899. if (!t) {
  6900. _context11.next = 6;
  6901. break;
  6902. }
  6903. return _context11.abrupt("return", t);
  6904. case 6:
  6905. n = "skin is invalid: skinId: ".concat(e);
  6906. return _context11.abrupt("return", Promise.reject(new ParamError$1(n)));
  6907. case 8:
  6908. case "end":
  6909. return _context11.stop();
  6910. }
  6911. }
  6912. }, _callee11, this);
  6913. }));
  6914. function getSkin(_x5) {
  6915. return _getSkin.apply(this, arguments);
  6916. }
  6917. return getSkin;
  6918. }()
  6919. }, {
  6920. key: "setupStats",
  6921. value: function setupStats() {
  6922. this.stats.assign({
  6923. roomId: this.id,
  6924. userId: this.userId
  6925. }), setInterval(this.engineProxy.updateStats, 1e3);
  6926. }
  6927. }, {
  6928. key: "proxyEvents",
  6929. value: function proxyEvents(e, t) {
  6930. this.emit(e, t);
  6931. }
  6932. }, {
  6933. key: "setCurrentNetworkOptions",
  6934. value: function setCurrentNetworkOptions(e) {
  6935. this._currentNetworkOptions = e;
  6936. }
  6937. }, {
  6938. key: "updateCurrentNetworkOptions",
  6939. value: function updateCurrentNetworkOptions(e) {
  6940. Object.assign(this._currentNetworkOptions, e), Object.assign(this.options, e);
  6941. }
  6942. }, {
  6943. key: "setCurrentState",
  6944. value: function setCurrentState(e) {
  6945. this._currentState = e;
  6946. }
  6947. }, {
  6948. key: "updateCurrentState",
  6949. value: function updateCurrentState(e) {
  6950. e.skinId && (this.lastSkinId = this.currentState.skinId, this.updateCurrentNetworkOptions({
  6951. skinId: e.skinId
  6952. })), e.versionId && this.updateCurrentNetworkOptions({
  6953. versionId: e.versionId
  6954. }), Object.assign(this._currentState, e);
  6955. }
  6956. }]);
  6957. return Xverse_Room;
  6958. }(EventEmitter);
  6959. 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); }; }
  6960. 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; } }
  6961. var XverseRoom = /*#__PURE__*/function (_Xverse_Room) {
  6962. _inherits(XverseRoom, _Xverse_Room);
  6963. var _super = _createSuper$1(XverseRoom);
  6964. function XverseRoom(e) {
  6965. var _this;
  6966. _classCallCheck(this, XverseRoom);
  6967. _this = _super.call(this, e);
  6968. _this.joyStick = new JoyStick(_assertThisInitialized(_this));
  6969. return _this;
  6970. }
  6971. _createClass(XverseRoom, [{
  6972. key: "afterJoinRoomHook",
  6973. value: function afterJoinRoomHook() {
  6974. this.joyStick.init({});
  6975. }
  6976. }]);
  6977. return XverseRoom;
  6978. }(Xverse_Room);
  6979. var BaseTable = /*#__PURE__*/function () {
  6980. function BaseTable(e, t) {
  6981. _classCallCheck(this, BaseTable);
  6982. this.db = null;
  6983. this.isCreatingTable = !1;
  6984. this.hasCleared = !1;
  6985. this.dbName = e, this.dbVersion = t;
  6986. }
  6987. _createClass(BaseTable, [{
  6988. key: "clearDataBase",
  6989. value: function () {
  6990. var _clearDataBase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  6991. var _this = this;
  6992. return regenerator.wrap(function _callee$(_context) {
  6993. while (1) {
  6994. switch (_context.prev = _context.next) {
  6995. case 0:
  6996. return _context.abrupt("return", this.hasCleared || (e && (this.hasCleared = !0), !window.indexedDB.databases) ? Promise.resolve() : new Promise(function (t, r) {
  6997. var n = window.indexedDB.deleteDatabase(_this.dbName);
  6998. n.onsuccess = function () {
  6999. t();
  7000. }, n.onerror = r;
  7001. }));
  7002. case 1:
  7003. case "end":
  7004. return _context.stop();
  7005. }
  7006. }
  7007. }, _callee, this);
  7008. }));
  7009. function clearDataBase(_x) {
  7010. return _clearDataBase.apply(this, arguments);
  7011. }
  7012. return clearDataBase;
  7013. }()
  7014. }, {
  7015. key: "tableName",
  7016. value: function tableName() {
  7017. throw new Error("Derived class have to override 'tableName', and set a proper table name!");
  7018. }
  7019. }, {
  7020. key: "keyPath",
  7021. value: function keyPath() {
  7022. throw new Error("Derived class have to override 'keyPath', and set a proper index name!");
  7023. }
  7024. }, {
  7025. key: "index",
  7026. value: function index() {
  7027. throw new Error("Derived class have to override 'index', and set a proper index name!");
  7028. }
  7029. }, {
  7030. key: "checkAndOpenDatabase",
  7031. value: function () {
  7032. var _checkAndOpenDatabase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  7033. var _this2 = this;
  7034. return regenerator.wrap(function _callee2$(_context2) {
  7035. while (1) {
  7036. switch (_context2.prev = _context2.next) {
  7037. case 0:
  7038. return _context2.abrupt("return", this.db ? Promise.resolve(this.db) : new Promise(function (e, t) {
  7039. var n = setTimeout(function () {
  7040. logger.info("wait db to open for", 200), _this2.db ? e(_this2.db) : e(_this2.checkAndOpenDatabase()), clearTimeout(n);
  7041. }, 200);
  7042. _this2.openDatabase(_this2.dbName, _this2.dbVersion || 1, function () {
  7043. _this2.db && !_this2.isCreatingTable && e(_this2.db), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable)), clearTimeout(n);
  7044. }, function () {
  7045. t(new Error("Failed to open database!")), clearTimeout(n);
  7046. }, function () {
  7047. _this2.db && e(_this2.db), clearTimeout(n), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable));
  7048. });
  7049. }));
  7050. case 1:
  7051. case "end":
  7052. return _context2.stop();
  7053. }
  7054. }
  7055. }, _callee2, this);
  7056. }));
  7057. function checkAndOpenDatabase() {
  7058. return _checkAndOpenDatabase.apply(this, arguments);
  7059. }
  7060. return checkAndOpenDatabase;
  7061. }()
  7062. }, {
  7063. key: "openDatabase",
  7064. value: function openDatabase(e, t, r, n, o) {
  7065. var _this3 = this;
  7066. if (this.isCreatingTable) return;
  7067. this.isCreatingTable = !0, logger.info(e, t);
  7068. var a = window.indexedDB.open(e, t),
  7069. s = this.tableName();
  7070. a.onsuccess = function (l) {
  7071. _this3.db = a.result, logger.info("IndexedDb ".concat(e, " is opened.")), _this3.db.objectStoreNames.contains(s) && (_this3.isCreatingTable = !1), r && r(l);
  7072. }, a.onerror = function (l) {
  7073. var u;
  7074. logger.error("Failed to open database", (u = l == null ? void 0 : l.srcElement) == null ? void 0 : u.error), _this3.isCreatingTable = !1, n && n(l), _this3.clearDataBase(!0);
  7075. }, a.onupgradeneeded = function (l) {
  7076. var u = l.target.result,
  7077. c = _this3.index();
  7078. logger.info("Creating table ".concat(s, "."));
  7079. var h = u.objectStoreNames.contains(s);
  7080. if (h) h = u.transaction([s], "readwrite").objectStore(s);else {
  7081. var f = _this3.keyPath();
  7082. h = u.createObjectStore(s, {
  7083. keyPath: f
  7084. });
  7085. }
  7086. c.map(function (f) {
  7087. h.createIndex(f, f, {
  7088. unique: !1
  7089. });
  7090. }), _this3.isCreatingTable = !1, logger.info("Table ".concat(s, " opened")), o && o(l);
  7091. };
  7092. }
  7093. }, {
  7094. key: "add",
  7095. value: function () {
  7096. var _add = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  7097. var t, o;
  7098. return regenerator.wrap(function _callee3$(_context3) {
  7099. while (1) {
  7100. switch (_context3.prev = _context3.next) {
  7101. case 0:
  7102. t = this.tableName();
  7103. _context3.next = 3;
  7104. return this.checkAndOpenDatabase();
  7105. case 3:
  7106. o = _context3.sent.transaction([t], "readwrite").objectStore(t).add(e);
  7107. return _context3.abrupt("return", new Promise(function (a, s) {
  7108. o.onsuccess = function (l) {
  7109. a(l);
  7110. }, o.onerror = function (l) {
  7111. var u;
  7112. logger.error((u = l.srcElement) == null ? void 0 : u.error), s(l);
  7113. };
  7114. }));
  7115. case 5:
  7116. case "end":
  7117. return _context3.stop();
  7118. }
  7119. }
  7120. }, _callee3, this);
  7121. }));
  7122. function add(_x2) {
  7123. return _add.apply(this, arguments);
  7124. }
  7125. return add;
  7126. }()
  7127. }, {
  7128. key: "put",
  7129. value: function () {
  7130. var _put = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  7131. var t, o;
  7132. return regenerator.wrap(function _callee4$(_context4) {
  7133. while (1) {
  7134. switch (_context4.prev = _context4.next) {
  7135. case 0:
  7136. t = this.tableName();
  7137. _context4.next = 3;
  7138. return this.checkAndOpenDatabase();
  7139. case 3:
  7140. o = _context4.sent.transaction([t], "readwrite").objectStore(t).put(e);
  7141. return _context4.abrupt("return", new Promise(function (a, s) {
  7142. o.onsuccess = function (l) {
  7143. a(l);
  7144. }, o.onerror = function (l) {
  7145. var u;
  7146. logger.error("db put error", (u = l.srcElement) == null ? void 0 : u.error), s(l);
  7147. };
  7148. }));
  7149. case 5:
  7150. case "end":
  7151. return _context4.stop();
  7152. }
  7153. }
  7154. }, _callee4, this);
  7155. }));
  7156. function put(_x3) {
  7157. return _put.apply(this, arguments);
  7158. }
  7159. return put;
  7160. }()
  7161. }, {
  7162. key: "delete",
  7163. value: function _delete(e, t, r) {
  7164. var n = this.tableName();
  7165. this.checkAndOpenDatabase().then(function (o) {
  7166. var s = o.transaction([n], "readwrite").objectStore(n).delete(e);
  7167. s.onsuccess = t, s.onerror = r;
  7168. });
  7169. }
  7170. }, {
  7171. key: "update",
  7172. value: function update() {
  7173. this.checkAndOpenDatabase().then(function (e) {});
  7174. }
  7175. }, {
  7176. key: "getAllKeys",
  7177. value: function () {
  7178. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  7179. var e, t;
  7180. return regenerator.wrap(function _callee5$(_context5) {
  7181. while (1) {
  7182. switch (_context5.prev = _context5.next) {
  7183. case 0:
  7184. e = this.tableName();
  7185. _context5.next = 3;
  7186. return this.checkAndOpenDatabase();
  7187. case 3:
  7188. t = _context5.sent;
  7189. return _context5.abrupt("return", new Promise(function (r, n) {
  7190. var a = t.transaction([e], "readonly").objectStore(e).getAllKeys();
  7191. a.onsuccess = function (s) {
  7192. r(s.target.result);
  7193. }, a.onerror = function (s) {
  7194. logger.error("db getAllKeys error", s), n(s);
  7195. };
  7196. }));
  7197. case 5:
  7198. case "end":
  7199. return _context5.stop();
  7200. }
  7201. }
  7202. }, _callee5, this);
  7203. }));
  7204. function getAllKeys() {
  7205. return _getAllKeys.apply(this, arguments);
  7206. }
  7207. return getAllKeys;
  7208. }()
  7209. }, {
  7210. key: "query",
  7211. value: function () {
  7212. var _query = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t) {
  7213. var r, n;
  7214. return regenerator.wrap(function _callee6$(_context6) {
  7215. while (1) {
  7216. switch (_context6.prev = _context6.next) {
  7217. case 0:
  7218. r = this.tableName();
  7219. _context6.next = 3;
  7220. return this.checkAndOpenDatabase();
  7221. case 3:
  7222. n = _context6.sent;
  7223. return _context6.abrupt("return", new Promise(function (o, a) {
  7224. var u = n.transaction([r], "readonly").objectStore(r).index(e).get(t);
  7225. u.onsuccess = function (c) {
  7226. var f;
  7227. var h = (f = c == null ? void 0 : c.target) == null ? void 0 : f.result;
  7228. o && o(h);
  7229. }, u.onerror = function (c) {
  7230. logger.error("db query error", c), a(c);
  7231. };
  7232. }));
  7233. case 5:
  7234. case "end":
  7235. return _context6.stop();
  7236. }
  7237. }
  7238. }, _callee6, this);
  7239. }));
  7240. function query(_x4, _x5) {
  7241. return _query.apply(this, arguments);
  7242. }
  7243. return query;
  7244. }()
  7245. }, {
  7246. key: "sleep",
  7247. value: function () {
  7248. var _sleep = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  7249. return regenerator.wrap(function _callee7$(_context7) {
  7250. while (1) {
  7251. switch (_context7.prev = _context7.next) {
  7252. case 0:
  7253. return _context7.abrupt("return", new Promise(function (t) {
  7254. setTimeout(function () {
  7255. t("");
  7256. }, e);
  7257. }));
  7258. case 1:
  7259. case "end":
  7260. return _context7.stop();
  7261. }
  7262. }
  7263. }, _callee7);
  7264. }));
  7265. function sleep(_x6) {
  7266. return _sleep.apply(this, arguments);
  7267. }
  7268. return sleep;
  7269. }()
  7270. }]);
  7271. return BaseTable;
  7272. }();
  7273. 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); }; }
  7274. 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; } }
  7275. var ModelTable = /*#__PURE__*/function (_BaseTable) {
  7276. _inherits(ModelTable, _BaseTable);
  7277. var _super = _createSuper(ModelTable);
  7278. function ModelTable() {
  7279. _classCallCheck(this, ModelTable);
  7280. return _super.call(this, "XverseDatabase", 1);
  7281. }
  7282. _createClass(ModelTable, [{
  7283. key: "tableName",
  7284. value: function tableName() {
  7285. return "models";
  7286. }
  7287. }, {
  7288. key: "index",
  7289. value: function index() {
  7290. return ["url"];
  7291. }
  7292. }, {
  7293. key: "keyPath",
  7294. value: function keyPath() {
  7295. return "url";
  7296. }
  7297. }]);
  7298. return ModelTable;
  7299. }(BaseTable);
  7300. var modelTable = new ModelTable();
  7301. var Preload = /*#__PURE__*/function () {
  7302. function Preload(e) {
  7303. _classCallCheck(this, Preload);
  7304. this.config = null;
  7305. this.allKeys = [];
  7306. this.oldResourcesDeleted = !1;
  7307. this.requests = {
  7308. simple: {
  7309. stopped: !0,
  7310. requests: {}
  7311. },
  7312. observer: {
  7313. stopped: !0,
  7314. requests: {}
  7315. },
  7316. full: {
  7317. stopped: !0,
  7318. requests: {}
  7319. }
  7320. };
  7321. this.modelManager = e, this.init(e.appId);
  7322. }
  7323. _createClass(Preload, [{
  7324. key: "init",
  7325. value: function init(e) {
  7326. reporter$1.updateBody({
  7327. appId: e
  7328. });
  7329. }
  7330. }, {
  7331. key: "getConfig",
  7332. value: function () {
  7333. var _getConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  7334. var _yield$this$modelMana, t;
  7335. return regenerator.wrap(function _callee$(_context) {
  7336. while (1) {
  7337. switch (_context.prev = _context.next) {
  7338. case 0:
  7339. if (!this.config) {
  7340. _context.next = 2;
  7341. break;
  7342. }
  7343. return _context.abrupt("return", this.config);
  7344. case 2:
  7345. _context.next = 4;
  7346. return this.modelManager.requestConfig();
  7347. case 4:
  7348. _yield$this$modelMana = _context.sent;
  7349. t = _yield$this$modelMana.preload;
  7350. return _context.abrupt("return", t ? (this.config = t, Promise.resolve(t)) : Promise.reject("no preload config"));
  7351. case 7:
  7352. case "end":
  7353. return _context.stop();
  7354. }
  7355. }
  7356. }, _callee, this);
  7357. }));
  7358. function getConfig(_x) {
  7359. return _getConfig.apply(this, arguments);
  7360. }
  7361. return getConfig;
  7362. }()
  7363. }, {
  7364. key: "getAllKeys",
  7365. value: function () {
  7366. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  7367. var e, t;
  7368. return regenerator.wrap(function _callee2$(_context2) {
  7369. while (1) {
  7370. switch (_context2.prev = _context2.next) {
  7371. case 0:
  7372. if (!this.allKeys.length) {
  7373. _context2.next = 2;
  7374. break;
  7375. }
  7376. return _context2.abrupt("return", this.allKeys);
  7377. case 2:
  7378. _context2.prev = 2;
  7379. _context2.next = 5;
  7380. return modelTable.getAllKeys();
  7381. case 5:
  7382. e = _context2.sent;
  7383. this.allKeys = e;
  7384. return _context2.abrupt("return", e);
  7385. case 10:
  7386. _context2.prev = 10;
  7387. _context2.t0 = _context2["catch"](2);
  7388. t = "preload getAllKeys error";
  7389. return _context2.abrupt("return", (logger.error(t), Promise.reject(t)));
  7390. case 14:
  7391. case "end":
  7392. return _context2.stop();
  7393. }
  7394. }
  7395. }, _callee2, this, [[2, 10]]);
  7396. }));
  7397. function getAllKeys() {
  7398. return _getAllKeys.apply(this, arguments);
  7399. }
  7400. return getAllKeys;
  7401. }()
  7402. }, {
  7403. key: "stop",
  7404. value: function stop(e) {
  7405. e === "serverless" && (e = "observer"), this.requests[e].stopped = !0;
  7406. var t = this.requests[e].requests;
  7407. Object.keys(t).forEach(function (r) {
  7408. http1.canceler.removePending(r), delete t[r];
  7409. });
  7410. }
  7411. }, {
  7412. key: "clearPreload",
  7413. value: function clearPreload(e) {
  7414. this.requests[e].stopped = !1, this.allKeys = [];
  7415. }
  7416. }, {
  7417. key: "start",
  7418. value: function () {
  7419. var _start = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e, t, r) {
  7420. var n, o, a, s, l, u, h, f, _s;
  7421. return regenerator.wrap(function _callee3$(_context3) {
  7422. while (1) {
  7423. switch (_context3.prev = _context3.next) {
  7424. case 0:
  7425. n = Date.now(), o = 0;
  7426. _context3.prev = 1;
  7427. if (!(e === "serverless" && (e = "observer"), !this.requests[e])) {
  7428. _context3.next = 4;
  7429. break;
  7430. }
  7431. return _context3.abrupt("return", Promise.reject(new ParamError("invalid stage name: " + e)));
  7432. case 4:
  7433. this.clearPreload(e);
  7434. _context3.next = 7;
  7435. return this.getConfig(e);
  7436. case 7:
  7437. a = _context3.sent;
  7438. _context3.next = 10;
  7439. return this.getAllKeys();
  7440. case 10:
  7441. s = _context3.sent;
  7442. _context3.prev = 11;
  7443. _context3.next = 14;
  7444. return this.deleteOldResources(a.assetUrls.map(function (d) {
  7445. return d.url;
  7446. }), s);
  7447. case 14:
  7448. _context3.next = 19;
  7449. break;
  7450. case 16:
  7451. _context3.prev = 16;
  7452. _context3.t0 = _context3["catch"](11);
  7453. logger.error(_context3.t0);
  7454. case 19:
  7455. l = a.baseUrls, u = a.assetUrls;
  7456. _context3.t1 = e;
  7457. _context3.next = _context3.t1 === "simple" ? 23 : _context3.t1 === "observer" ? 25 : _context3.t1 === "full" ? 27 : 29;
  7458. break;
  7459. case 23:
  7460. h = l;
  7461. return _context3.abrupt("break", 30);
  7462. case 25:
  7463. h = u;
  7464. return _context3.abrupt("break", 30);
  7465. case 27:
  7466. h = u;
  7467. return _context3.abrupt("break", 30);
  7468. case 29:
  7469. h = u;
  7470. case 30:
  7471. f = h.filter(function (d) {
  7472. return !s.includes(d.url);
  7473. });
  7474. r && isFunction(r) && (f = f.filter(r));
  7475. o = f.length;
  7476. logger.debug("keysNeedToPreload", f);
  7477. f.length || t && t(h.length, h.length);
  7478. n = Date.now();
  7479. _context3.next = 38;
  7480. return this._preload(e, f, t);
  7481. case 38:
  7482. logger.infoAndReportMeasurement({
  7483. tag: e,
  7484. startTime: n,
  7485. metric: "assetsPreload",
  7486. extra: {
  7487. total: o
  7488. }
  7489. });
  7490. return _context3.abrupt("return");
  7491. case 42:
  7492. _context3.prev = 42;
  7493. _context3.t2 = _context3["catch"](1);
  7494. _s = _context3.t2;
  7495. return _context3.abrupt("return", ((this.requests[e].stopped || axios.isCancel(_context3.t2)) && (_s = new PreloadCanceledError()), logger.infoAndReportMeasurement({
  7496. tag: e,
  7497. startTime: n,
  7498. metric: "assetsPreload",
  7499. extra: {
  7500. total: o
  7501. },
  7502. error: _s,
  7503. reportOptions: {
  7504. immediate: !0
  7505. }
  7506. }), Promise.reject(_s)));
  7507. case 46:
  7508. case "end":
  7509. return _context3.stop();
  7510. }
  7511. }
  7512. }, _callee3, this, [[1, 42], [11, 16]]);
  7513. }));
  7514. function start(_x2, _x3, _x4) {
  7515. return _start.apply(this, arguments);
  7516. }
  7517. return start;
  7518. }()
  7519. }, {
  7520. key: "deleteOldResources",
  7521. value: function deleteOldResources(e, t) {
  7522. if (!this.oldResourcesDeleted) this.oldResourcesDeleted = !0;else return Promise.resolve();
  7523. var r = t.filter(function (n) {
  7524. return !e.includes(n);
  7525. });
  7526. return logger.debug("keysNeedToDelete", r), logger.warn("keysNeedToDelete", r.length), Promise.all(r.map(function (n) {
  7527. return modelTable.delete(n);
  7528. }));
  7529. }
  7530. }, {
  7531. key: "_preload",
  7532. value: function () {
  7533. var _preload2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t, r) {
  7534. var _this = this;
  7535. var n, o, a;
  7536. return regenerator.wrap(function _callee6$(_context6) {
  7537. while (1) {
  7538. switch (_context6.prev = _context6.next) {
  7539. case 0:
  7540. n = t.length;
  7541. if (n) {
  7542. _context6.next = 3;
  7543. break;
  7544. }
  7545. return _context6.abrupt("return", Promise.resolve());
  7546. case 3:
  7547. o = 0;
  7548. a = window.setInterval(function () {
  7549. r && r(o, n), o >= n && window.clearInterval(a);
  7550. }, 1e3);
  7551. return _context6.abrupt("return", util.mapLimit(t, 10, /*#__PURE__*/function () {
  7552. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(s) {
  7553. var l, u;
  7554. return regenerator.wrap(function _callee5$(_context5) {
  7555. while (1) {
  7556. switch (_context5.prev = _context5.next) {
  7557. case 0:
  7558. l = s.size, u = s.url;
  7559. return _context5.abrupt("return", _this.requests[e].stopped ? Promise.reject(new PreloadCanceledError()) : http1.get({
  7560. url: u,
  7561. timeout: Preload.getTimeoutBySize(l),
  7562. responseType: "blob",
  7563. retry: 2,
  7564. beforeRequest: function beforeRequest() {
  7565. _this.requests[e].requests[u] = !0;
  7566. }
  7567. }).then( /*#__PURE__*/function () {
  7568. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(c) {
  7569. var h, f;
  7570. return regenerator.wrap(function _callee4$(_context4) {
  7571. while (1) {
  7572. switch (_context4.prev = _context4.next) {
  7573. case 0:
  7574. h = c.data;
  7575. if (h instanceof Blob) {
  7576. _context4.next = 3;
  7577. break;
  7578. }
  7579. return _context4.abrupt("return", (logger.error("request blob failed, type:", typeof h, u), Promise.reject("request blob failed " + u)));
  7580. case 3:
  7581. _context4.next = 5;
  7582. return blobToDataURI(h);
  7583. case 5:
  7584. f = _context4.sent;
  7585. _context4.prev = 6;
  7586. _context4.next = 9;
  7587. return modelTable.put({
  7588. url: u,
  7589. model: f
  7590. });
  7591. case 9:
  7592. return _context4.abrupt("return");
  7593. case 12:
  7594. _context4.prev = 12;
  7595. _context4.t0 = _context4["catch"](6);
  7596. return _context4.abrupt("return", (logger.error("unable to add data to indexedDB", _context4.t0), Promise.reject(new InternalError("preload db error"))));
  7597. case 15:
  7598. case "end":
  7599. return _context4.stop();
  7600. }
  7601. }
  7602. }, _callee4, null, [[6, 12]]);
  7603. }));
  7604. return function (_x9) {
  7605. return _ref2.apply(this, arguments);
  7606. };
  7607. }()).then(function () {
  7608. o++, delete _this.requests[e].requests[u];
  7609. }, function (c) {
  7610. return delete _this.requests[e].requests[u], window.clearInterval(a), Promise.reject(c);
  7611. }));
  7612. case 2:
  7613. case "end":
  7614. return _context5.stop();
  7615. }
  7616. }
  7617. }, _callee5);
  7618. }));
  7619. return function (_x8) {
  7620. return _ref.apply(this, arguments);
  7621. };
  7622. }()));
  7623. case 6:
  7624. case "end":
  7625. return _context6.stop();
  7626. }
  7627. }
  7628. }, _callee6);
  7629. }));
  7630. function _preload(_x5, _x6, _x7) {
  7631. return _preload2.apply(this, arguments);
  7632. }
  7633. return _preload;
  7634. }()
  7635. }], [{
  7636. key: "getTimeoutBySize",
  7637. value: function getTimeoutBySize(e) {
  7638. return e ? e < 500 * 1e3 ? 30 * 1e3 : e < 1e3 * 1e3 ? 60 * 1e3 : 100 * 1e3 : 100 * 1e3;
  7639. }
  7640. }]);
  7641. return Preload;
  7642. }();
  7643. var RenderType$1 = {
  7644. PathVideo: 0,
  7645. RotationVideo: 1,
  7646. RotationImage: 2,
  7647. PanoramaImage: 3,
  7648. CGVideo: 4,
  7649. ClientRotationPano: 5,
  7650. CloudRotationPano: 6
  7651. };
  7652. var Xverse = /*#__PURE__*/function () {
  7653. function Xverse(e) {
  7654. _classCallCheck(this, Xverse);
  7655. e || (e = {});
  7656. var _e = e,
  7657. t = _e.onLog,
  7658. r = _e.env,
  7659. n = _e.appId,
  7660. o = _e.releaseId,
  7661. a = _e.subPackageVersion;
  7662. this.NO_CACHE = !1, this.env = r || "PROD", this.SUB_PACKAGE_VERSION = a, this.debug && Logger.setLevel(LoggerLevels.Debug);
  7663. var s = this.pageSession = util.uuid();
  7664. reporter$1.updateHeader({
  7665. pageSession: s
  7666. });
  7667. reporter$1.updateReportUrl(REPORT_URL[this.env]);
  7668. a && reporter$1.updateBody({
  7669. sdkVersion: a
  7670. });
  7671. logger.infoAndReportMeasurement({
  7672. metric: "sdkInit",
  7673. startTime: Date.now(),
  7674. extra: {
  7675. version: a,
  7676. enviroment: r,
  7677. pageSession: s
  7678. }
  7679. });
  7680. logger.debug("debug mode:", this.debug);
  7681. reporter$1.on("report", function (l) {
  7682. t && t(l);
  7683. });
  7684. if (n) {
  7685. this.appId = n, this.releaseId = o;
  7686. var l = ModelManager.getInstance(n, o);
  7687. this.preload = new Preload(l);
  7688. }
  7689. }
  7690. _createClass(Xverse, [{
  7691. key: "isSupported",
  7692. get: function get() {
  7693. return isSupported();
  7694. }
  7695. }, {
  7696. key: "disableLogUpload",
  7697. value: function disableLogUpload() {
  7698. reporter$1.disable(), logger.debug("logger upload has been disabled");
  7699. }
  7700. }, {
  7701. key: "getSkinList",
  7702. value: function () {
  7703. var _getSkinList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  7704. return regenerator.wrap(function _callee$(_context) {
  7705. while (1) {
  7706. switch (_context.prev = _context.next) {
  7707. case 0:
  7708. return _context.abrupt("return", []);
  7709. case 1:
  7710. case "end":
  7711. return _context.stop();
  7712. }
  7713. }
  7714. }, _callee);
  7715. }));
  7716. function getSkinList() {
  7717. return _getSkinList.apply(this, arguments);
  7718. }
  7719. return getSkinList;
  7720. }()
  7721. }, {
  7722. key: "getAvatarList",
  7723. value: function () {
  7724. var _getAvatarList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  7725. return regenerator.wrap(function _callee2$(_context2) {
  7726. while (1) {
  7727. switch (_context2.prev = _context2.next) {
  7728. case 0:
  7729. return _context2.abrupt("return", []);
  7730. case 1:
  7731. case "end":
  7732. return _context2.stop();
  7733. }
  7734. }
  7735. }, _callee2);
  7736. }));
  7737. function getAvatarList() {
  7738. return _getAvatarList.apply(this, arguments);
  7739. }
  7740. return getAvatarList;
  7741. }()
  7742. }, {
  7743. key: "getGiftList",
  7744. value: function () {
  7745. var _getGiftList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  7746. return regenerator.wrap(function _callee3$(_context3) {
  7747. while (1) {
  7748. switch (_context3.prev = _context3.next) {
  7749. case 0:
  7750. return _context3.abrupt("return", [{
  7751. id: "hack "
  7752. }]);
  7753. case 1:
  7754. case "end":
  7755. return _context3.stop();
  7756. }
  7757. }
  7758. }, _callee3);
  7759. }));
  7760. function getGiftList() {
  7761. return _getGiftList.apply(this, arguments);
  7762. }
  7763. return getGiftList;
  7764. }()
  7765. }, {
  7766. key: "joinRoom",
  7767. value: function () {
  7768. var _joinRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  7769. var t, r, n, o;
  7770. return regenerator.wrap(function _callee4$(_context4) {
  7771. while (1) {
  7772. switch (_context4.prev = _context4.next) {
  7773. case 0:
  7774. t = e.pathName || "thirdwalk", r = e.rotationRenderType || RenderType$1.RotationVideo, n = e.person || Person$1.Third, o = new XverseRoom(le(oe({}, e), {
  7775. appId: e.appId || this.appId,
  7776. releaseId: e.releaseId || this.releaseId,
  7777. pageSession: this.pageSession,
  7778. isAllSync: !0,
  7779. rotationRenderType: r,
  7780. syncByEvent: !0,
  7781. pathName: t,
  7782. person: n,
  7783. role: e.role || "audience"
  7784. }));
  7785. return _context4.abrupt("return", o.initRoom().then(function () {
  7786. return o;
  7787. }));
  7788. case 2:
  7789. case "end":
  7790. return _context4.stop();
  7791. }
  7792. }
  7793. }, _callee4, this);
  7794. }));
  7795. function joinRoom(_x) {
  7796. return _joinRoom.apply(this, arguments);
  7797. }
  7798. return joinRoom;
  7799. }()
  7800. }]);
  7801. return Xverse;
  7802. }();
  7803. var xverse = new Xverse({
  7804. env: "DEV",
  7805. appId: "10016",
  7806. releaseId: '2203120033_29769e'
  7807. });
  7808. var l = /*#__PURE__*/function () {
  7809. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  7810. var R;
  7811. return regenerator.wrap(function _callee$(_context) {
  7812. while (1) {
  7813. switch (_context.prev = _context.next) {
  7814. case 0:
  7815. _context.prev = 0;
  7816. _context.next = 3;
  7817. return (R = xverse.preload) == null ? void 0 : R.start('full', function (M, x) {
  7818. });
  7819. case 3:
  7820. _context.next = 12;
  7821. break;
  7822. case 5:
  7823. _context.prev = 5;
  7824. _context.t0 = _context["catch"](0);
  7825. if (!(console.error(_context.t0), _context.t0.code === Codes.PreloadCanceled)) {
  7826. _context.next = 10;
  7827. break;
  7828. }
  7829. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88");
  7830. return _context.abrupt("return");
  7831. case 10:
  7832. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5");
  7833. return _context.abrupt("return");
  7834. case 12:
  7835. _context.prev = 12;
  7836. _context.next = 15;
  7837. return xverse.joinRoom({
  7838. canvas: document.getElementById('canvas'),
  7839. skinId: 10092,
  7840. avatarId: 'KGe_Boy',
  7841. roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
  7842. userId: '1f7acca1db9d5',
  7843. wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
  7844. appId: "10016",
  7845. token: " ",
  7846. nickname: '1f7acca1db9d5',
  7847. firends: ["user1"],
  7848. viewMode: "full",
  7849. resolution: {
  7850. width: 1728,
  7851. height: 720
  7852. },
  7853. pathName: 'thirdwalk',
  7854. objectFit: null,
  7855. hasAvatar: !0,
  7856. syncToOthers: !0
  7857. });
  7858. case 15:
  7859. room = _context.sent;
  7860. debugger;
  7861. u();
  7862. c();
  7863. window.room = room;
  7864. e(!1);
  7865. _context.next = 28;
  7866. break;
  7867. case 23:
  7868. _context.prev = 23;
  7869. _context.t1 = _context["catch"](12);
  7870. console.error(_context.t1);
  7871. alert(_context.t1);
  7872. return _context.abrupt("return");
  7873. case 28:
  7874. case "end":
  7875. return _context.stop();
  7876. }
  7877. }
  7878. }, _callee, null, [[0, 5], [12, 23]]);
  7879. }));
  7880. return function l() {
  7881. return _ref.apply(this, arguments);
  7882. };
  7883. }();
  7884. var u = function u() {
  7885. room.on("_coreClick", function (_ref2) {
  7886. var f = _ref2.point;
  7887. room._userAvatar.moveTo({
  7888. point: f
  7889. });
  7890. });
  7891. };
  7892. var c = function c() {
  7893. room.on("repeatLogin", function () {
  7894. toast("\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55", {
  7895. duration: 1e4
  7896. });
  7897. }), room.on("reconnecting", function (_ref3) {
  7898. var f = _ref3.count;
  7899. toast("\u5C1D\u8BD5\u7B2C".concat(f, "\u6B21\u91CD\u8FDE"));
  7900. }), room.on("reconnected", function () {
  7901. toast("\u91CD\u8FDE\u6210\u529F");
  7902. }), room.on("disconnected", function () {
  7903. var f = toast("\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5", {
  7904. duration: 1e5,
  7905. onClick() {
  7906. f.hideToast(), room.reconnect();
  7907. }
  7908. });
  7909. });
  7910. };
  7911. l();
  7912. }));
  7913. //# sourceMappingURL=index.js.map