index.js 327 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013
  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$h(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$i(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  827. function _isNativeReflectConstruct$i() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  828. var Reporter = /*#__PURE__*/function (_EventEmitter) {
  829. _inherits(Reporter, _EventEmitter);
  830. var _super = _createSuper$h(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 = /*#__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();
  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$g(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$h(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1146. function _isNativeReflectConstruct$h() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1147. var Http1 = /*#__PURE__*/function (_EventEmitter) {
  1148. _inherits(Http1, _EventEmitter);
  1149. var _super = _createSuper$g(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$g() {
  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$g()) {
  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$f(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$f(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1936. 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; } }
  1937. var XverseError = /*#__PURE__*/function (_Error) {
  1938. _inherits(XverseError, _Error);
  1939. var _super = _createSuper$f(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$e(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$e(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  1970. function _isNativeReflectConstruct$e() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  1971. var TimeoutError = /*#__PURE__*/function (_XverseError) {
  1972. _inherits(TimeoutError, _XverseError);
  1973. var _super = _createSuper$e(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$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); }; }
  1981. 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; } }
  1982. var XverseAvatarManager = /*#__PURE__*/function (_EventEmitter) {
  1983. _inherits(XverseAvatarManager, _EventEmitter);
  1984. var _super = _createSuper$d(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$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); }; }
  2543. 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; } }
  2544. var Camera = /*#__PURE__*/function (_EventEmitter) {
  2545. _inherits(Camera, _EventEmitter);
  2546. var _super = _createSuper$c(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$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); }; }
  2807. 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; } }
  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$b(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$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); }; }
  4020. 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; } }
  4021. var ParamError$1 = /*#__PURE__*/function (_XverseError) {
  4022. _inherits(ParamError, _XverseError);
  4023. var _super = _createSuper$a(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$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); }; }
  4110. 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; } }
  4111. var InitNetworkTimeoutError = /*#__PURE__*/function (_XverseError) {
  4112. _inherits(InitNetworkTimeoutError, _XverseError);
  4113. var _super = _createSuper$9(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$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); }; }
  4121. 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; } }
  4122. var Socket = /*#__PURE__*/function (_EventEmitter) {
  4123. _inherits(Socket, _EventEmitter);
  4124. var _super = _createSuper$8(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$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); }; }
  5522. 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; } }
  5523. var Rtcp = /*#__PURE__*/function (_EventEmitter) {
  5524. _inherits(Rtcp, _EventEmitter);
  5525. var _super = _createSuper$7(Rtcp);
  5526. function Rtcp(e) {
  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 = e; //this.workers = new Workers(this,new Logger("decode")),
  5543. //this.workers.registerLogger(new Logger("decode")),
  5544. _this.workers = new Workers(_assertThisInitialized(_this), logger);
  5545. _this.workers.registerLogger(logger);
  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. });
  5559. return _this;
  5560. }
  5561. _createClass(Rtcp, [{
  5562. key: "onIcecandidate",
  5563. value: function onIcecandidate(e) {
  5564. if (e.candidate != null) {
  5565. var t = JSON.stringify(e.candidate);
  5566. logger.debug("Got ice candidate: ".concat(t)), this.network.socket.send({
  5567. id: "ice_candidate",
  5568. data: btoa(t)
  5569. });
  5570. }
  5571. }
  5572. }, {
  5573. key: "onIcecandidateerror",
  5574. value: function onIcecandidateerror(e) {
  5575. logger.error("onicecandidateerror", e.errorCode, e.errorText, e);
  5576. }
  5577. }, {
  5578. key: "onIceStateChange",
  5579. value: function onIceStateChange(e) {
  5580. switch (e.target.iceGatheringState) {
  5581. case "gathering":
  5582. logger.info("ice gathering");
  5583. break;
  5584. case "complete":
  5585. logger.info("Ice gathering completed");
  5586. }
  5587. }
  5588. }, {
  5589. key: "onIceConnectionStateChange",
  5590. value: function onIceConnectionStateChange() {
  5591. if (!!this.connection) switch (logger.info("iceConnectionState: ".concat(this.connection.iceConnectionState)), this.connection.iceConnectionState) {
  5592. case "connected":
  5593. {
  5594. this.connected = !0;
  5595. break;
  5596. }
  5597. case "disconnected":
  5598. {
  5599. this.connected = !1, this.emit("rtcDisconnected");
  5600. break;
  5601. }
  5602. case "failed":
  5603. {
  5604. this.emit("rtcDisconnected"), this.connected = !1;
  5605. break;
  5606. }
  5607. }
  5608. }
  5609. }, {
  5610. key: "setRemoteDescription",
  5611. value: function () {
  5612. var _setRemoteDescription = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e, t) {
  5613. var a, s, l, r, n, o, u;
  5614. return regenerator.wrap(function _callee$(_context) {
  5615. while (1) {
  5616. switch (_context.prev = _context.next) {
  5617. case 0:
  5618. if (this.connection) {
  5619. _context.next = 2;
  5620. break;
  5621. }
  5622. return _context.abrupt("return");
  5623. case 2:
  5624. r = JSON.parse(atob(e)), n = new RTCSessionDescription(r);
  5625. _context.next = 5;
  5626. return this.connection.setRemoteDescription(n);
  5627. case 5:
  5628. _context.next = 7;
  5629. return this.connection.createAnswer();
  5630. case 7:
  5631. o = _context.sent;
  5632. 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) {
  5633. u = o.sdp.lastIndexOf("a=mid:1");
  5634. o.sdp = o.sdp.slice(0, u) + "a=mid:2" + o.sdp.slice(u + 7);
  5635. }
  5636. _context.prev = 9;
  5637. _context.next = 12;
  5638. return this.connection.setLocalDescription(o);
  5639. case 12:
  5640. _context.next = 17;
  5641. break;
  5642. case 14:
  5643. _context.prev = 14;
  5644. _context.t0 = _context["catch"](9);
  5645. logger.error("error", _context.t0);
  5646. case 17:
  5647. this.isAnswered = !0, this.network.rtcp.flushCandidate(), this.network.socket.send({
  5648. id: "answer",
  5649. data: btoa(JSON.stringify(o))
  5650. }), t.srcObject = this.mediaStream;
  5651. case 18:
  5652. case "end":
  5653. return _context.stop();
  5654. }
  5655. }
  5656. }, _callee, this, [[9, 14]]);
  5657. }));
  5658. function setRemoteDescription(_x, _x2) {
  5659. return _setRemoteDescription.apply(this, arguments);
  5660. }
  5661. return setRemoteDescription;
  5662. }()
  5663. }, {
  5664. key: "flushCandidate",
  5665. value: function flushCandidate() {
  5666. var _this2 = this;
  5667. this.isFlushing || !this.isAnswered || (this.isFlushing = !0, this.candidates.forEach(function (e) {
  5668. var t = atob(e),
  5669. r = JSON.parse(t);
  5670. if (/172\./.test(r.candidate)) return;
  5671. var n = new RTCIceCandidate(r);
  5672. _this2.connection && _this2.connection.addIceCandidate(n).then(function () {}, function (o) {
  5673. logger.info("add candidate failed", o);
  5674. });
  5675. }), this.isFlushing = !1);
  5676. }
  5677. }, {
  5678. key: "input",
  5679. value: function input(e) {
  5680. var t;
  5681. !this.actived || !this.inputChannel || this.inputChannel.readyState === "open" && ((t = this.inputChannel) == null || t.send(e));
  5682. }
  5683. }, {
  5684. key: "start",
  5685. value: function start() {
  5686. var _this3 = this;
  5687. this.connection = new RTCPeerConnection();
  5688. var e = Date.now();
  5689. this.connection.ondatachannel = function (t) {
  5690. logger.info("ondatachannel: ".concat(t.channel.label)), _this3.inputChannel = t.channel, _this3.inputChannel.onopen = function () {
  5691. var r;
  5692. 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({
  5693. metric: "datachannelOpenedAt",
  5694. startTime: _this3.network.room._startTime,
  5695. group: "joinRoom"
  5696. }), logger.infoAndReportMeasurement({
  5697. metric: "datachannelOpenedCost",
  5698. startTime: e,
  5699. group: "joinRoom"
  5700. }));
  5701. }, _this3.inputChannel.onclose = function () {
  5702. var r;
  5703. return logger.info("The input channel has closed, id:", (r = _this3.inputChannel) == null ? void 0 : r.id);
  5704. }, _this3.inputChannel.onmessage = function (r) {
  5705. _this3.workers.dataHandle(r.data);
  5706. };
  5707. }, this.connection.oniceconnectionstatechange = this.onIceConnectionStateChange, this.connection.onicegatheringstatechange = this.onIceStateChange, this.connection.onicecandidate = this.onIcecandidate, this.connection.onicecandidateerror = this.onIcecandidateerror, this.network.socket.send({
  5708. id: "init_webrtc",
  5709. data: JSON.stringify({
  5710. is_mobile: !0
  5711. })
  5712. });
  5713. }
  5714. }, {
  5715. key: "addCandidate",
  5716. value: function addCandidate(e) {
  5717. e === "" ? this.network.rtcp.flushCandidate() : this.candidates.push(e);
  5718. }
  5719. }, {
  5720. key: "disconnect",
  5721. value: function disconnect() {
  5722. var e, t, r;
  5723. 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;
  5724. }
  5725. }, {
  5726. key: "sendStringData",
  5727. value: function sendStringData(e) {
  5728. this.input(e);
  5729. }
  5730. }, {
  5731. key: "sendData",
  5732. value: function sendData(e) {
  5733. var t = "";
  5734. try {
  5735. t = JSON.stringify(e);
  5736. } catch (r) {
  5737. logger.error(r);
  5738. return;
  5739. }
  5740. this.input(t);
  5741. }
  5742. }]);
  5743. return Rtcp;
  5744. }(EventEmitter);
  5745. var NetworkMonitor = /*#__PURE__*/function () {
  5746. function NetworkMonitor(e) {
  5747. _classCallCheck(this, NetworkMonitor);
  5748. this._listener = e;
  5749. }
  5750. _createClass(NetworkMonitor, [{
  5751. key: "isOnline",
  5752. get: function get() {
  5753. var e = window.navigator;
  5754. return typeof e.onLine == "boolean" ? e.onLine : !0;
  5755. }
  5756. }, {
  5757. key: "start",
  5758. value: function start() {
  5759. window.addEventListener("online", this._listener), window.addEventListener("offline", this._listener);
  5760. }
  5761. }, {
  5762. key: "stop",
  5763. value: function stop() {
  5764. window.removeEventListener("online", this._listener), window.removeEventListener("offline", this._listener);
  5765. }
  5766. }]);
  5767. return NetworkMonitor;
  5768. }();
  5769. var Stream = /*#__PURE__*/function () {
  5770. function Stream(e) {
  5771. _classCallCheck(this, Stream);
  5772. this.el = null;
  5773. this._streamPlayTimer = null;
  5774. if (!e) {
  5775. this.el = this.createVideoElement();
  5776. return;
  5777. }
  5778. this.el = e;
  5779. }
  5780. _createClass(Stream, [{
  5781. key: "play",
  5782. value: function play() {
  5783. var _this = this;
  5784. return new Promise(function (e, t) {
  5785. _this._streamPlayTimer = new Timeout(function () {
  5786. t(new InternalError("Stream play timeout"));
  5787. }, 5e3), _this.el && _this.el.play().then(function () {
  5788. var r;
  5789. e(), logger.info("Media can autoplay"), (r = _this._streamPlayTimer) == null || r.clear();
  5790. }).catch(function (r) {
  5791. var n;
  5792. logger.error("Media Failed to autoplay"), logger.error(r), t(new InternalError("Media Failed to autoplay")), (n = _this._streamPlayTimer) == null || n.clear();
  5793. });
  5794. });
  5795. }
  5796. }, {
  5797. key: "createVideoElement",
  5798. value: function createVideoElement() {
  5799. var e = document.createElement("video");
  5800. 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;
  5801. }
  5802. }]);
  5803. return Stream;
  5804. }();
  5805. 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); }; }
  5806. 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; } }
  5807. var InternalError$1 = /*#__PURE__*/function (_XverseError) {
  5808. _inherits(InternalError, _XverseError);
  5809. var _super = _createSuper$6(InternalError);
  5810. function InternalError(e) {
  5811. _classCallCheck(this, InternalError);
  5812. return _super.call(this, 1002, e || "\u5185\u90E8\u9519\u8BEF");
  5813. }
  5814. return _createClass(InternalError);
  5815. }(XverseError);
  5816. 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); }; }
  5817. 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; } }
  5818. 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 ";
  5819. var NetworkController = /*#__PURE__*/function (_EventEmitter) {
  5820. _inherits(NetworkController, _EventEmitter);
  5821. var _super = _createSuper$5(NetworkController);
  5822. function NetworkController(e) {
  5823. var _this;
  5824. _classCallCheck(this, NetworkController);
  5825. _this = _super.call(this);
  5826. _this.socket = null;
  5827. _this.rtcp = null;
  5828. _this.stream = null;
  5829. _this._state = 'connecting';
  5830. _this._networkMonitor = null;
  5831. _this.blockedActions = [];
  5832. _this.reconnectCount = 0;
  5833. _this.room = e, _this.socket = new Socket(_assertThisInitialized(_this));
  5834. _this.rtcp = new Rtcp(_assertThisInitialized(_this));
  5835. _this.stream = new Stream();
  5836. _this._networkMonitor = new NetworkMonitor(function () {
  5837. 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());
  5838. });
  5839. _this.checkNetworkQuality(_this.room.currentNetworkOptions.wsServerUrl);
  5840. _this._networkMonitor.start();
  5841. new VisibilityChangeHandler().subscribe(function (r) {
  5842. var n, o;
  5843. r ? ((o = _this.room.stats) == null || o.disable(), logger.infoAndReportMeasurement({
  5844. metric: "pageHide",
  5845. startTime: Date.now()
  5846. })) : ((n = _this.room.stats) == null || n.enable(), logger.infoAndReportMeasurement({
  5847. metric: "pageShow",
  5848. startTime: Date.now(),
  5849. extra: {
  5850. state: _this._state
  5851. }
  5852. }), _this._state === "disconnected" && _this.reconnect());
  5853. });
  5854. return _this;
  5855. }
  5856. _createClass(NetworkController, [{
  5857. key: "startGame",
  5858. value: function startGame() {
  5859. var _this2 = this;
  5860. return new Promise(function (e, t) {
  5861. if (!_this2.rtcp.connected) return t(new InternalError$1("Game cannot load. Please refresh"));
  5862. if (!_this2.rtcp.inputReady) return t(new InternalError$1("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. _this3.setState("connected"), t();
  5930. }), _this3.rtcp.on("rtcDisconnected", function () {
  5931. logger.info("rtc disconnected"), _this3._state === "connecting" ? (_this3.setState("disconnected"), r(new InternalError$1("rtc connect failed"))) : (_this3.setState("disconnected"), logger.info("rtc disconnected, start to reconnect"), _this3.reconnect());
  5932. }), _this3.socket.on("socketQuit", function () {
  5933. logger.info("socket quit success"), _this3.setState("closed");
  5934. }), _this3.socket.on("socketClosed", function (n) {
  5935. _this3._state === "connecting" && (_this3.setState("disconnected"), r(n)), r(n);
  5936. }), _this3.socket.start();
  5937. }));
  5938. case 3:
  5939. case "end":
  5940. return _context2.stop();
  5941. }
  5942. }
  5943. }, _callee2, this);
  5944. }));
  5945. function connect() {
  5946. return _connect.apply(this, arguments);
  5947. }
  5948. return connect;
  5949. }()
  5950. }, {
  5951. key: "reconnect",
  5952. value: function reconnect() {
  5953. var _this4 = this;
  5954. if (this.room.viewMode === "observer") return;
  5955. var e = Date.now();
  5956. if (this.reconnectCount++, this.reconnectCount > MAX_RECONNECT_COUNT) {
  5957. logger.error("reconnect failed, reached max reconnect count", MAX_RECONNECT_COUNT), this.reconnectCount = 0, this.emit("stateChanged", {
  5958. state: "disconnected"
  5959. });
  5960. return;
  5961. }
  5962. return logger.info("start reconnect, count:", this.reconnectCount), this._reconnect().then(function () {
  5963. logger.infoAndReportMeasurement({
  5964. startTime: e,
  5965. metric: "reconnect"
  5966. });
  5967. }).catch(function (t) {
  5968. if (logger.infoAndReportMeasurement({
  5969. startTime: e,
  5970. metric: "reconnect",
  5971. error: t
  5972. }), t.code === Codes.RepeatLogin) {
  5973. _this4.room.handleRepetLogin();
  5974. return;
  5975. }
  5976. var r = 1e3;
  5977. logger.info("reconnect failed, wait " + r + " ms for next reconnect"), setTimeout(function () {
  5978. _this4.reconnect();
  5979. }, r);
  5980. });
  5981. }
  5982. }, {
  5983. key: "_reconnect",
  5984. value: function _reconnect() {
  5985. var _this5 = this;
  5986. 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", {
  5987. state: "reconnecting",
  5988. count: this.reconnectCount
  5989. }), this.socket.off("gameRoomAvailable"), this.socket.off("socketClosed"), this.rtcp.off("rtcDisconnected"), this.rtcp.off("rtcConnected"), this.connectAndStart(!0).then(function (_ref) {
  5990. var e = _ref.session_id;
  5991. _this5.room.updateCurrentNetworkOptions({
  5992. sessionId: e
  5993. }), reporter.updateBody({
  5994. serverSession: e
  5995. }), logger.info("reconnect success"), _this5.setState("connected"), _this5.reconnectCount = 0, _this5.emit("stateChanged", {
  5996. state: "reconnected"
  5997. });
  5998. }));
  5999. }
  6000. }, {
  6001. key: "prepareReconnect",
  6002. value: function prepareReconnect() {
  6003. this.rtcp.disconnect(), this.socket.prepareReconnect(), this.prepareReconnectOptions();
  6004. }
  6005. }, {
  6006. key: "prepareReconnectOptions",
  6007. value: function prepareReconnectOptions() {
  6008. var _ref2 = this.room.currentClickingState || {},
  6009. e = _ref2.camera,
  6010. t = _ref2.player;
  6011. e && t && this.room.updateCurrentNetworkOptions({
  6012. camera: e,
  6013. player: t
  6014. });
  6015. }
  6016. }, {
  6017. key: "sendRtcData",
  6018. value: function sendRtcData(e) {
  6019. if (this.blockedActions.includes(e.action_type)) {
  6020. logger.info("action: ".concat(Actions[e.action_type], " was blocked"));
  6021. return;
  6022. }
  6023. this.rtcp.sendData(e);
  6024. }
  6025. }, {
  6026. key: "sendSocketData",
  6027. value: function sendSocketData(e) {
  6028. logger.debug("ws send ->", e), this.socket.send(e);
  6029. }
  6030. }, {
  6031. key: "quit",
  6032. value: function quit() {
  6033. var e = uuid$1(),
  6034. t = {
  6035. action_type: Actions.Exit,
  6036. trace_id: e,
  6037. exit_action: {},
  6038. user_id: this.room.options.userId,
  6039. packet_id: e
  6040. };
  6041. this.setState("closed"), this.socket.quit(), this.sendRtcData(t);
  6042. }
  6043. }, {
  6044. key: "checkNetworkQuality",
  6045. value: function checkNetworkQuality(i) {
  6046. var worker = null;
  6047. if (!i) return;
  6048. var e = Date.now();
  6049. if (this.pingOthers("https://www.baidu.com", function (t, r) {
  6050. logger.infoAndReportMeasurement({
  6051. metric: "baiduRtt",
  6052. group: "http",
  6053. value: r,
  6054. startTime: e
  6055. });
  6056. }), !worker) {
  6057. var t = new Blob([workerSourceCode], {
  6058. type: "application/javascript"
  6059. });
  6060. worker = new Worker(URL.createObjectURL(t)), worker.onmessage = function (r) {
  6061. logger.infoAndReportMeasurement({
  6062. metric: "workerRtt",
  6063. group: "http",
  6064. startTime: e,
  6065. value: r.data
  6066. });
  6067. };
  6068. }
  6069. }
  6070. }, {
  6071. key: "pingOthers",
  6072. value: function pingOthers(i, e) {
  6073. var t = !1;
  6074. var r = new Image();
  6075. r.onload = o, r.onerror = a;
  6076. var n = Date.now();
  6077. function o(l) {
  6078. t = !0, s();
  6079. }
  6080. function a(l) {}
  6081. function s() {
  6082. var l = Date.now() - n;
  6083. if (typeof e == "function") return t ? e(null, l) : (console.error("error loading resource"), e("error", l));
  6084. }
  6085. r.src = i + "/favicon.ico?" + +new Date();
  6086. }
  6087. }]);
  6088. return NetworkController;
  6089. }(EventEmitter);
  6090. 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); }; }
  6091. 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; } }
  6092. var InitConfigTimeoutError = /*#__PURE__*/function (_XverseError) {
  6093. _inherits(InitConfigTimeoutError, _XverseError);
  6094. var _super = _createSuper$4(InitConfigTimeoutError);
  6095. function InitConfigTimeoutError(e) {
  6096. _classCallCheck(this, InitConfigTimeoutError);
  6097. return _super.call(this, 1009, e || "\u914D\u7F6E\u521D\u59CB\u5316\u8D85\u65F6");
  6098. }
  6099. return _createClass(InitConfigTimeoutError);
  6100. }(XverseError);
  6101. 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); }; }
  6102. 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; } }
  6103. var InitDecoderTimeoutError = /*#__PURE__*/function (_XverseError) {
  6104. _inherits(InitDecoderTimeoutError, _XverseError);
  6105. var _super = _createSuper$3(InitDecoderTimeoutError);
  6106. function InitDecoderTimeoutError(e) {
  6107. _classCallCheck(this, InitDecoderTimeoutError);
  6108. return _super.call(this, 1008, e || "Decoder \u521D\u59CB\u5316\u8D85\u65F6");
  6109. }
  6110. return _createClass(InitDecoderTimeoutError);
  6111. }(XverseError);
  6112. 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); }; }
  6113. 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; } }
  6114. var Xverse_Room = /*#__PURE__*/function (_EventEmitter) {
  6115. _inherits(Xverse_Room, _EventEmitter);
  6116. var _super = _createSuper$2(Xverse_Room);
  6117. function Xverse_Room(e) {
  6118. var _this;
  6119. _classCallCheck(this, Xverse_Room);
  6120. _this = _super.call(this);
  6121. _this.disableAutoTurn = !1;
  6122. _this._currentNetworkOptions = null;
  6123. _this.lastSkinId = null;
  6124. _this.debug = null;
  6125. _this.isFirstDataUsed = !1;
  6126. _this.userId = null;
  6127. _this.pathManager = new PathManager();
  6128. _this.networkController = null;
  6129. _this._startTime = Date.now();
  6130. _this.canvas = null;
  6131. _this.eventsController = null;
  6132. _this.panorama = null;
  6133. _this.engineProxy = null;
  6134. _this._id = null;
  6135. _this.skinList = [];
  6136. _this.isHost = !1;
  6137. _this.avatarManager = new XverseAvatarManager(_assertThisInitialized(_this));
  6138. _this.effectManager = new XverseAvatarManager(_assertThisInitialized(_this));
  6139. _this.sceneManager = null;
  6140. _this.scene = null;
  6141. _this.breathPointManager = null;
  6142. _this._currentState = null;
  6143. _this.joined = !1;
  6144. _this.disableRotate = !1;
  6145. _this.isPano = !1;
  6146. _this.movingByClick = !0;
  6147. _this.camera = new Camera(_assertThisInitialized(_this));
  6148. _this.stats = new Stats(_assertThisInitialized(_this));
  6149. _this.isUpdatedRawYUVData = !1;
  6150. _this.actionsHandler = new ActionsHandler(_assertThisInitialized(_this));
  6151. _this._currentClickingState = null;
  6152. _this.signal = new Signal(_assertThisInitialized(_this));
  6153. _this.firstFrameTimestamp = null;
  6154. _this.moveToExtra = '';
  6155. _this.options = e;
  6156. _this.options.wsServerUrl || (_this.options.wsServerUrl = SERVER_URLS.DEV);
  6157. _this.modelManager = ModelManager.getInstance(e.appId, e.releaseId), _this.updateReporter();
  6158. var n = e;
  6159. n.canvas;
  6160. var r = Oe(n, ["canvas"]);
  6161. logger.infoAndReportMeasurement({
  6162. metric: "startJoinRoomAt",
  6163. startTime: Date.now(),
  6164. group: "joinRoom",
  6165. extra: r,
  6166. value: 0
  6167. });
  6168. return _this;
  6169. }
  6170. _createClass(Xverse_Room, [{
  6171. key: "receiveRtcData",
  6172. value: function () {
  6173. var _receiveRtcData = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  6174. var _this2 = this;
  6175. var e, t, r, n;
  6176. return regenerator.wrap(function _callee$(_context) {
  6177. while (1) {
  6178. switch (_context.prev = _context.next) {
  6179. case 0:
  6180. logger.info("Invoke receiveRtcData");
  6181. e = !1, t = !1, r = !1, n = !1;
  6182. return _context.abrupt("return", this.viewMode === "serverless" ? (logger.warn("set view mode to serverless"), this.setViewMode("observer").then(function () {
  6183. return _this2;
  6184. }, function () {
  6185. return _this2;
  6186. })) : new Promise(function (o) {
  6187. var a = _this2.networkController.rtcp.workers;
  6188. a.registerFunction("signal", function (s) {
  6189. _this2.signal.handleSignal(s);
  6190. }), a.registerFunction("stream", function (s) {
  6191. var l;
  6192. if (_this2.emit("streamTimestamp", {
  6193. timestamp: Date.now()
  6194. }), t || (t = !0, logger.info("Invoke stream event")), s.stream) {
  6195. r || (r = !0, logger.info("Invoke updateRawYUVData")), _this2.isUpdatedRawYUVData = !1;
  6196. var u = (l = _this2._currentState.skin) == null ? void 0 : l.fov;
  6197. _this2.sceneManager.materialComponent.updateRawYUVData(s.stream, s.width, s.height, u), _this2.isUpdatedRawYUVData = !0;
  6198. }
  6199. e || (logger.info("Invoke isAfterRenderRegistered"), e = !0, _this2.scene.registerAfterRender(function () {
  6200. _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()));
  6201. }));
  6202. }), _this2.panorama.bindListener(function () {
  6203. o(_this2), _this2.afterJoinRoom();
  6204. }), a.registerFunction("reconnectedFrame", function () {}), logger.info("Invoke decoderWorker.postMessage"), a.decoderWorker.postMessage({
  6205. t: 5
  6206. });
  6207. }));
  6208. case 3:
  6209. case "end":
  6210. return _context.stop();
  6211. }
  6212. }
  6213. }, _callee, this);
  6214. }));
  6215. function receiveRtcData() {
  6216. return _receiveRtcData.apply(this, arguments);
  6217. }
  6218. return receiveRtcData;
  6219. }()
  6220. }, {
  6221. key: "currentNetworkOptions",
  6222. get: function get() {
  6223. return this._currentNetworkOptions;
  6224. }
  6225. }, {
  6226. key: "viewMode",
  6227. get: function get() {
  6228. var e;
  6229. return ((e = this._currentState) == null ? void 0 : e.viewMode) || "full";
  6230. }
  6231. }, {
  6232. key: "id",
  6233. get: function get() {
  6234. return this._id;
  6235. }
  6236. }, {
  6237. key: "skinId",
  6238. get: function get() {
  6239. return this._currentState.skinId;
  6240. }
  6241. }, {
  6242. key: "skin",
  6243. get: function get() {
  6244. return this._currentState.skin;
  6245. }
  6246. }, {
  6247. key: "sessionId",
  6248. get: function get() {
  6249. return this.currentNetworkOptions.sessionId;
  6250. }
  6251. }, {
  6252. key: "pictureQualityLevel",
  6253. get: function get() {
  6254. return this.currentState.pictureQualityLevel;
  6255. }
  6256. }, {
  6257. key: "avatars",
  6258. get: function get() {
  6259. return Array.from(this.avatarManager.avatars.values());
  6260. }
  6261. }, {
  6262. key: "currentState",
  6263. get: function get() {
  6264. var e;
  6265. return le(oe({}, this._currentState), {
  6266. state: (e = this.networkController) == null ? void 0 : e._state
  6267. });
  6268. }
  6269. }, {
  6270. key: "_userAvatar",
  6271. get: function get() {
  6272. var _this3 = this;
  6273. return this.avatars.find(function (e) {
  6274. return e.userId === _this3.userId;
  6275. });
  6276. }
  6277. }, {
  6278. key: "tvs",
  6279. get: function get() {
  6280. return this.engineProxy._tvs;
  6281. }
  6282. }, {
  6283. key: "tv",
  6284. get: function get() {
  6285. return this.tvs[0];
  6286. }
  6287. }, {
  6288. key: "currentClickingState",
  6289. get: function get() {
  6290. return this._currentClickingState;
  6291. }
  6292. }, {
  6293. key: "afterJoinRoomHook",
  6294. value: function afterJoinRoomHook() {}
  6295. }, {
  6296. key: "beforeJoinRoomResolveHook",
  6297. value: function beforeJoinRoomResolveHook() {}
  6298. }, {
  6299. key: "afterReconnectedHook",
  6300. value: function afterReconnectedHook() {}
  6301. }, {
  6302. key: "handleSignalHook",
  6303. value: function handleSignalHook(e) {}
  6304. }, {
  6305. key: "skinChangedHook",
  6306. value: function skinChangedHook() {}
  6307. }, {
  6308. key: "beforeStartGameHook",
  6309. value: function () {
  6310. var _beforeStartGameHook = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2(e) {
  6311. return regenerator.wrap(function _callee2$(_context2) {
  6312. while (1) {
  6313. switch (_context2.prev = _context2.next) {
  6314. case 0:
  6315. case "end":
  6316. return _context2.stop();
  6317. }
  6318. }
  6319. }, _callee2);
  6320. }));
  6321. function beforeStartGameHook(_x) {
  6322. return _beforeStartGameHook.apply(this, arguments);
  6323. }
  6324. return beforeStartGameHook;
  6325. }()
  6326. }, {
  6327. key: "loadAssetsHook",
  6328. value: function loadAssetsHook() {}
  6329. }, {
  6330. key: "afterUserAvatarLoadedHook",
  6331. value: function afterUserAvatarLoadedHook() {}
  6332. }, {
  6333. key: "audienceViewModeHook",
  6334. value: function audienceViewModeHook() {}
  6335. }, {
  6336. key: "setViewModeToObserver",
  6337. value: function setViewModeToObserver() {}
  6338. }, {
  6339. key: "handleVehicleHook",
  6340. value: function handleVehicleHook(e) {}
  6341. }, {
  6342. key: "updateReporter",
  6343. value: function updateReporter() {
  6344. var _this$options = this.options,
  6345. e = _this$options.avatarId,
  6346. t = _this$options.skinId,
  6347. r = _this$options.userId,
  6348. n = _this$options.roomId,
  6349. o = _this$options.role,
  6350. a = _this$options.appId,
  6351. s = _this$options.wsServerUrl;
  6352. reporter$1.updateHeader({
  6353. userId: r
  6354. }), reporter$1.updateBody({
  6355. roomId: n,
  6356. role: o,
  6357. skinId: t,
  6358. avatarId: e,
  6359. appId: a,
  6360. wsServerUrl: s
  6361. });
  6362. }
  6363. }, {
  6364. key: "initRoom",
  6365. value: function () {
  6366. var _initRoom2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  6367. var _this$options$timeout, e;
  6368. return regenerator.wrap(function _callee3$(_context3) {
  6369. while (1) {
  6370. switch (_context3.prev = _context3.next) {
  6371. case 0:
  6372. _this$options$timeout = this.options.timeout, e = _this$options$timeout === void 0 ? DEFAULT_JOINROOM_TIMEOUT : _this$options$timeout;
  6373. if (!util.isSupported()) {
  6374. _context3.next = 5;
  6375. break;
  6376. }
  6377. return _context3.abrupt("return", this._initRoom()._timeout(e, new TimeoutError("initRoom timeout")));
  6378. case 5:
  6379. return _context3.abrupt("return", Promise.reject(new UnsupportedError()));
  6380. case 6:
  6381. case "end":
  6382. return _context3.stop();
  6383. }
  6384. }
  6385. }, _callee3, this);
  6386. }));
  6387. function initRoom() {
  6388. return _initRoom2.apply(this, arguments);
  6389. }
  6390. return initRoom;
  6391. }()
  6392. }, {
  6393. key: "_initRoom",
  6394. value: function () {
  6395. var _initRoom3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4() {
  6396. 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;
  6397. return regenerator.wrap(function _callee4$(_context4) {
  6398. while (1) {
  6399. switch (_context4.prev = _context4.next) {
  6400. case 0:
  6401. e = this.validateOptions(this.options);
  6402. if (!e) {
  6403. _context4.next = 3;
  6404. break;
  6405. }
  6406. return _context4.abrupt("return", (logger.error("initRoom param error", e), Promise.reject(e)));
  6407. case 3:
  6408. _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;
  6409. this.setCurrentNetworkOptions({
  6410. avatarId: r,
  6411. skinId: n,
  6412. roomId: R,
  6413. userId: o,
  6414. wsServerUrl: a,
  6415. role: s,
  6416. token: l,
  6417. pageSession: u,
  6418. rotationRenderType: c,
  6419. isAllSync: h,
  6420. appId: f,
  6421. camera: d,
  6422. player: _,
  6423. avatarComponents: g,
  6424. nickname: m,
  6425. avatarScale: v,
  6426. firends: y,
  6427. syncByEvent: b,
  6428. areaName: T,
  6429. attitude: C,
  6430. pathName: A,
  6431. person: P,
  6432. roomTypeId: M,
  6433. hasAvatar: x,
  6434. syncToOthers: I,
  6435. prioritySync: w,
  6436. extra: D,
  6437. removeWhenDisconnected: O
  6438. });
  6439. this.userId = o;
  6440. this.canvas = t;
  6441. T && (this.pathManager.currentArea = T);
  6442. this.networkController = new NetworkController(this);
  6443. this.setCurrentState({
  6444. areaName: T,
  6445. pathName: A,
  6446. attitude: C,
  6447. speed: 0,
  6448. viewMode: S,
  6449. state: this.networkController._state,
  6450. skinId: n
  6451. });
  6452. _context4.prev = 10;
  6453. _context4.next = 13;
  6454. return Promise.all([this.initNetwork(), this.initConfig(), this.initWasm()]);
  6455. case 13:
  6456. logger.info("network config wasm all ready, start to create game");
  6457. _context4.next = 16;
  6458. return this.requestCreateRoom({
  6459. skinId: n
  6460. });
  6461. case 16:
  6462. F = _context4.sent;
  6463. V = F.routeList.find(function (L) {
  6464. return L.areaName === T;
  6465. });
  6466. N = ((V == null ? void 0 : V.step) || 7.5) * 30;
  6467. this.updateCurrentState({
  6468. skin: F,
  6469. skinId: F.id,
  6470. versionId: F.versionId,
  6471. speed: N
  6472. });
  6473. _context4.next = 22;
  6474. return this.initEngine(F);
  6475. case 22:
  6476. _context4.next = 27;
  6477. break;
  6478. case 24:
  6479. _context4.prev = 24;
  6480. _context4.t0 = _context4["catch"](10);
  6481. return _context4.abrupt("return", Promise.reject(_context4.t0));
  6482. case 27:
  6483. return _context4.abrupt("return", (this.beforeJoinRoomResolve(), this.receiveRtcData()));
  6484. case 28:
  6485. case "end":
  6486. return _context4.stop();
  6487. }
  6488. }
  6489. }, _callee4, this, [[10, 24]]);
  6490. }));
  6491. function _initRoom() {
  6492. return _initRoom3.apply(this, arguments);
  6493. }
  6494. return _initRoom;
  6495. }()
  6496. }, {
  6497. key: "beforeJoinRoomResolve",
  6498. value: function beforeJoinRoomResolve() {
  6499. this.setupStats(), this.eventsController = new EventsController(this), this.eventsController.bindEvents(), this.panorama = new Panorama(this), this.beforeJoinRoomResolveHook();
  6500. }
  6501. }, {
  6502. key: "afterJoinRoom",
  6503. value: function afterJoinRoom() {
  6504. this.joined = !0, this.viewMode === "observer" && this.setViewModeToObserver(), logger.infoAndReportMeasurement({
  6505. tag: this.viewMode,
  6506. value: this.firstFrameTimestamp - this._startTime,
  6507. startTime: Date.now(),
  6508. metric: "joinRoom"
  6509. }), this.camera.initialFov = this.sceneManager.cameraComponent.getCameraFov(), this.stats.on("stats", function (_ref) {
  6510. var e = _ref.stats;
  6511. reporter$1.report("stats", oe({}, e));
  6512. }), this.debug = new Debug(this), this.afterJoinRoomHook();
  6513. }
  6514. }, {
  6515. key: "afterReconnected",
  6516. value: function afterReconnected() {
  6517. this.avatarManager.clearOtherUsers(), this.afterReconnectedHook();
  6518. }
  6519. }, {
  6520. key: "leave",
  6521. value: function leave() {
  6522. var e, t;
  6523. return logger.info("Invoke room.leave"), (e = this.eventsController) == null || e.clearEvents(), (t = this.networkController) == null || t.quit(), this;
  6524. }
  6525. }, {
  6526. key: "validateOptions",
  6527. value: function validateOptions(e) {
  6528. var _ref2 = e || {},
  6529. t = _ref2.canvas,
  6530. r = _ref2.avatarId,
  6531. n = _ref2.skinId,
  6532. o = _ref2.userId,
  6533. a = _ref2.role;
  6534. _ref2.roomId;
  6535. var l = _ref2.token,
  6536. u = _ref2.appId;
  6537. _ref2.avatarComponents;
  6538. var h = [];
  6539. t instanceof HTMLCanvasElement || h.push(new ParamError$1("`canvas` must be instanceof of HTMLCanvasElement"));
  6540. (!o || typeof o != "string") && h.push(new ParamError$1("`userId` must be string"));
  6541. (!l || typeof l != "string") && h.push(new ParamError$1("`token` must be string"));
  6542. (!u || typeof u != "string") && h.push(new ParamError$1("`appId` must be string"));
  6543. a == "audience" || (!r || !n) && h.push(new ParamError$1("`avatarId` and `skinId` is required when create room"));
  6544. return h[0];
  6545. }
  6546. }, {
  6547. key: "initNetwork",
  6548. value: function () {
  6549. var _initNetwork = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  6550. var e;
  6551. return regenerator.wrap(function _callee5$(_context5) {
  6552. while (1) {
  6553. switch (_context5.prev = _context5.next) {
  6554. case 0:
  6555. if (!(this.viewMode === "serverless")) {
  6556. _context5.next = 2;
  6557. break;
  6558. }
  6559. return _context5.abrupt("return", Promise.resolve());
  6560. case 2:
  6561. e = Date.now();
  6562. _context5.prev = 3;
  6563. _context5.next = 6;
  6564. return this.networkController.connect()._timeout(8e3, new InitNetworkTimeoutError());
  6565. case 6:
  6566. logger.infoAndReportMeasurement({
  6567. metric: "networkInitAt",
  6568. startTime: this._startTime,
  6569. group: "joinRoom"
  6570. });
  6571. logger.infoAndReportMeasurement({
  6572. metric: "networkInitCost",
  6573. startTime: e,
  6574. group: "joinRoom"
  6575. });
  6576. _context5.next = 13;
  6577. break;
  6578. case 10:
  6579. _context5.prev = 10;
  6580. _context5.t0 = _context5["catch"](3);
  6581. throw logger.infoAndReportMeasurement({
  6582. metric: "networkInitAt",
  6583. startTime: e,
  6584. group: "joinRoom",
  6585. error: _context5.t0
  6586. }), _context5.t0;
  6587. case 13:
  6588. case "end":
  6589. return _context5.stop();
  6590. }
  6591. }
  6592. }, _callee5, this, [[3, 10]]);
  6593. }));
  6594. function initNetwork() {
  6595. return _initNetwork.apply(this, arguments);
  6596. }
  6597. return initNetwork;
  6598. }()
  6599. }, {
  6600. key: "initConfig",
  6601. value: function () {
  6602. var _initConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6() {
  6603. var e;
  6604. return regenerator.wrap(function _callee6$(_context6) {
  6605. while (1) {
  6606. switch (_context6.prev = _context6.next) {
  6607. case 0:
  6608. e = Date.now();
  6609. _context6.prev = 1;
  6610. _context6.next = 4;
  6611. return this.modelManager.getApplicationConfig()._timeout(8e3, new InitConfigTimeoutError());
  6612. case 4:
  6613. logger.infoAndReportMeasurement({
  6614. metric: "configInitAt",
  6615. startTime: this._startTime,
  6616. group: "joinRoom"
  6617. });
  6618. logger.infoAndReportMeasurement({
  6619. metric: "configInitCost",
  6620. startTime: e,
  6621. group: "joinRoom"
  6622. });
  6623. _context6.next = 11;
  6624. break;
  6625. case 8:
  6626. _context6.prev = 8;
  6627. _context6.t0 = _context6["catch"](1);
  6628. throw logger.infoAndReportMeasurement({
  6629. metric: "configInitAt",
  6630. startTime: e,
  6631. group: "joinRoom",
  6632. error: _context6.t0
  6633. }), _context6.t0;
  6634. case 11:
  6635. case "end":
  6636. return _context6.stop();
  6637. }
  6638. }
  6639. }, _callee6, this, [[1, 8]]);
  6640. }));
  6641. function initConfig() {
  6642. return _initConfig.apply(this, arguments);
  6643. }
  6644. return initConfig;
  6645. }()
  6646. }, {
  6647. key: "initEngine",
  6648. value: function () {
  6649. var _initEngine = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  6650. var t, n;
  6651. return regenerator.wrap(function _callee7$(_context7) {
  6652. while (1) {
  6653. switch (_context7.prev = _context7.next) {
  6654. case 0:
  6655. t = Date.now();
  6656. _context7.prev = 1;
  6657. this.engineProxy = new EngineProxy(this);
  6658. _context7.next = 5;
  6659. return this.engineProxy.initEngine(e);
  6660. case 5:
  6661. logger.infoAndReportMeasurement({
  6662. metric: "webglInitAt",
  6663. startTime: this._startTime,
  6664. group: "joinRoom"
  6665. });
  6666. logger.infoAndReportMeasurement({
  6667. metric: "webglInitCost",
  6668. startTime: t,
  6669. group: "joinRoom"
  6670. });
  6671. return _context7.abrupt("return");
  6672. case 10:
  6673. _context7.prev = 10;
  6674. _context7.t0 = _context7["catch"](1);
  6675. n = _context7.t0;
  6676. return _context7.abrupt("return", (_context7.t0.code !== Codes.InitEngineTimeout && (n = new InitEngineError()), logger.error(_context7.t0), logger.infoAndReportMeasurement({
  6677. metric: "webglInitAt",
  6678. startTime: t,
  6679. group: "joinRoom",
  6680. error: n
  6681. }), Promise.reject(n)));
  6682. case 14:
  6683. case "end":
  6684. return _context7.stop();
  6685. }
  6686. }
  6687. }, _callee7, this, [[1, 10]]);
  6688. }));
  6689. function initEngine(_x2) {
  6690. return _initEngine.apply(this, arguments);
  6691. }
  6692. return initEngine;
  6693. }()
  6694. }, {
  6695. key: "initWasm",
  6696. value: function () {
  6697. var _initWasm = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee8() {
  6698. var _this4 = this;
  6699. var e;
  6700. return regenerator.wrap(function _callee8$(_context8) {
  6701. while (1) {
  6702. switch (_context8.prev = _context8.next) {
  6703. case 0:
  6704. if (!(this.viewMode === "serverless")) {
  6705. _context8.next = 2;
  6706. break;
  6707. }
  6708. return _context8.abrupt("return", Promise.resolve());
  6709. case 2:
  6710. e = Date.now();
  6711. _context8.prev = 3;
  6712. _context8.next = 6;
  6713. return this.networkController.rtcp.workers.init(this.options.resolution)._timeout(8e3, new InitDecoderTimeoutError());
  6714. case 6:
  6715. this.networkController.rtcp.workers.registerFunction("error", function (t) {
  6716. logger.error("decode error", t);
  6717. var r = t.code,
  6718. n = t.message;
  6719. _this4.emit("error", {
  6720. code: r,
  6721. msg: n
  6722. });
  6723. });
  6724. logger.infoAndReportMeasurement({
  6725. metric: "wasmInitAt",
  6726. group: "joinRoom",
  6727. startTime: this._startTime
  6728. });
  6729. logger.infoAndReportMeasurement({
  6730. metric: "wasmInitCost",
  6731. group: "joinRoom",
  6732. startTime: e
  6733. });
  6734. eventsManager.on("traceId", function (t) {
  6735. _this4.networkController.rtcp.workers.onTraceId(t);
  6736. });
  6737. _context8.next = 15;
  6738. break;
  6739. case 12:
  6740. _context8.prev = 12;
  6741. _context8.t0 = _context8["catch"](3);
  6742. throw logger.infoAndReportMeasurement({
  6743. metric: "wasmInitAt",
  6744. group: "joinRoom",
  6745. startTime: e,
  6746. error: _context8.t0
  6747. }), _context8.t0;
  6748. case 15:
  6749. case "end":
  6750. return _context8.stop();
  6751. }
  6752. }
  6753. }, _callee8, this, [[3, 12]]);
  6754. }));
  6755. function initWasm() {
  6756. return _initWasm.apply(this, arguments);
  6757. }
  6758. return initWasm;
  6759. }()
  6760. }, {
  6761. key: "requestCreateRoom",
  6762. value: function () {
  6763. var _requestCreateRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee9(_ref3) {
  6764. var e, t, r, _ref4, n, o, _yield$this$networkCo, _r, _n, _o, a, s;
  6765. return regenerator.wrap(function _callee9$(_context9) {
  6766. while (1) {
  6767. switch (_context9.prev = _context9.next) {
  6768. case 0:
  6769. e = _ref3.skinId;
  6770. if (!e) {
  6771. _context9.next = 11;
  6772. break;
  6773. }
  6774. _context9.next = 4;
  6775. return this.getSkin(e);
  6776. case 4:
  6777. t = _context9.sent;
  6778. _context9.next = 7;
  6779. return this.modelManager.findRoute(e, this.options.pathName);
  6780. case 7:
  6781. r = _context9.sent;
  6782. this.updateCurrentNetworkOptions({
  6783. areaName: r.areaName,
  6784. attitude: r.attitude,
  6785. versionId: t.versionId
  6786. });
  6787. _ref4 = getRandomItem(r.birthPointList) || this.options, n = _ref4.camera, o = _ref4.player;
  6788. this.options.camera || this.updateCurrentNetworkOptions({
  6789. camera: n
  6790. }), this.options.player || this.updateCurrentNetworkOptions({
  6791. player: o
  6792. });
  6793. case 11:
  6794. if (!(this.viewMode === "serverless")) {
  6795. _context9.next = 13;
  6796. break;
  6797. }
  6798. return _context9.abrupt("return", t);
  6799. case 13:
  6800. _context9.prev = 13;
  6801. _context9.next = 16;
  6802. return this.beforeStartGameHook(this.options);
  6803. case 16:
  6804. _context9.next = 18;
  6805. return this.networkController.startGame();
  6806. case 18:
  6807. _yield$this$networkCo = _context9.sent;
  6808. _r = _yield$this$networkCo.room_id;
  6809. _n = _yield$this$networkCo.data;
  6810. _o = _yield$this$networkCo.session_id;
  6811. this._id = _r;
  6812. a = JSON.parse(_n);
  6813. this.isHost = a.IsHost, e = a.SkinID || e;
  6814. _context9.next = 27;
  6815. return this.getSkin(e);
  6816. case 27:
  6817. s = _context9.sent;
  6818. return _context9.abrupt("return", (this.updateCurrentNetworkOptions({
  6819. roomId: _r,
  6820. sessionId: _o
  6821. }), reporter$1.updateBody({
  6822. roomId: _r,
  6823. skinId: e,
  6824. serverSession: _o
  6825. }), s));
  6826. case 31:
  6827. _context9.prev = 31;
  6828. _context9.t0 = _context9["catch"](13);
  6829. throw logger.error("Request create room error", _context9.t0), _context9.t0;
  6830. case 34:
  6831. case "end":
  6832. return _context9.stop();
  6833. }
  6834. }
  6835. }, _callee9, this, [[13, 31]]);
  6836. }));
  6837. function requestCreateRoom(_x3) {
  6838. return _requestCreateRoom.apply(this, arguments);
  6839. }
  6840. return requestCreateRoom;
  6841. }()
  6842. }, {
  6843. key: "pause",
  6844. value: function pause() {
  6845. return this.engineProxy.pause();
  6846. }
  6847. }, {
  6848. key: "resume",
  6849. value: function resume() {
  6850. return this.engineProxy.resume();
  6851. }
  6852. }, {
  6853. key: "reconnect",
  6854. value: function reconnect() {
  6855. this.networkController.reconnect();
  6856. }
  6857. }, {
  6858. key: "setViewMode",
  6859. value: function () {
  6860. var _setViewMode = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee10(e) {
  6861. return regenerator.wrap(function _callee10$(_context10) {
  6862. while (1) {
  6863. switch (_context10.prev = _context10.next) {
  6864. case 0:
  6865. case "end":
  6866. return _context10.stop();
  6867. }
  6868. }
  6869. }, _callee10);
  6870. }));
  6871. function setViewMode(_x4) {
  6872. return _setViewMode.apply(this, arguments);
  6873. }
  6874. return setViewMode;
  6875. }()
  6876. }, {
  6877. key: "handleRepetLogin",
  6878. value: function handleRepetLogin() {
  6879. logger.warn("receive " + Codes.RepeatLogin + " for repeat login"), this.emit("repeatLogin"), reporter$1.disable(), this.networkController.quit();
  6880. }
  6881. }, {
  6882. key: "setPictureQualityLevel",
  6883. value: function setPictureQualityLevel(e) {
  6884. var t = {
  6885. high: EImageQuality.high,
  6886. low: EImageQuality.low,
  6887. average: EImageQuality.mid
  6888. };
  6889. return this.updateCurrentState({
  6890. pictureQualityLevel: e
  6891. }), this.sceneManager.setImageQuality(t[e]);
  6892. }
  6893. }, {
  6894. key: "getSkin",
  6895. value: function () {
  6896. var _getSkin = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee11(e) {
  6897. var t, n;
  6898. return regenerator.wrap(function _callee11$(_context11) {
  6899. while (1) {
  6900. switch (_context11.prev = _context11.next) {
  6901. case 0:
  6902. t = null;
  6903. _context11.next = 3;
  6904. return this.modelManager.getSkinsList();
  6905. case 3:
  6906. t = (this.skinList = _context11.sent).find(function (n) {
  6907. return n.id === e || n.id === e;
  6908. });
  6909. if (!t) {
  6910. _context11.next = 6;
  6911. break;
  6912. }
  6913. return _context11.abrupt("return", t);
  6914. case 6:
  6915. n = "skin is invalid: skinId: ".concat(e);
  6916. return _context11.abrupt("return", Promise.reject(new ParamError$1(n)));
  6917. case 8:
  6918. case "end":
  6919. return _context11.stop();
  6920. }
  6921. }
  6922. }, _callee11, this);
  6923. }));
  6924. function getSkin(_x5) {
  6925. return _getSkin.apply(this, arguments);
  6926. }
  6927. return getSkin;
  6928. }()
  6929. }, {
  6930. key: "setupStats",
  6931. value: function setupStats() {
  6932. this.stats.assign({
  6933. roomId: this.id,
  6934. userId: this.userId
  6935. }), setInterval(this.engineProxy.updateStats, 1e3);
  6936. }
  6937. }, {
  6938. key: "proxyEvents",
  6939. value: function proxyEvents(e, t) {
  6940. this.emit(e, t);
  6941. }
  6942. }, {
  6943. key: "setCurrentNetworkOptions",
  6944. value: function setCurrentNetworkOptions(e) {
  6945. this._currentNetworkOptions = e;
  6946. }
  6947. }, {
  6948. key: "updateCurrentNetworkOptions",
  6949. value: function updateCurrentNetworkOptions(e) {
  6950. Object.assign(this._currentNetworkOptions, e), Object.assign(this.options, e);
  6951. }
  6952. }, {
  6953. key: "setCurrentState",
  6954. value: function setCurrentState(e) {
  6955. this._currentState = e;
  6956. }
  6957. }, {
  6958. key: "updateCurrentState",
  6959. value: function updateCurrentState(e) {
  6960. e.skinId && (this.lastSkinId = this.currentState.skinId, this.updateCurrentNetworkOptions({
  6961. skinId: e.skinId
  6962. })), e.versionId && this.updateCurrentNetworkOptions({
  6963. versionId: e.versionId
  6964. }), Object.assign(this._currentState, e);
  6965. }
  6966. }]);
  6967. return Xverse_Room;
  6968. }(EventEmitter);
  6969. 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); }; }
  6970. 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; } }
  6971. var XverseRoom = /*#__PURE__*/function (_Xverse_Room) {
  6972. _inherits(XverseRoom, _Xverse_Room);
  6973. var _super = _createSuper$1(XverseRoom);
  6974. function XverseRoom(e) {
  6975. var _this;
  6976. _classCallCheck(this, XverseRoom);
  6977. _this = _super.call(this, e);
  6978. _this.joyStick = new JoyStick(_assertThisInitialized(_this));
  6979. return _this;
  6980. }
  6981. _createClass(XverseRoom, [{
  6982. key: "afterJoinRoomHook",
  6983. value: function afterJoinRoomHook() {
  6984. this.joyStick.init({});
  6985. }
  6986. }]);
  6987. return XverseRoom;
  6988. }(Xverse_Room);
  6989. var BaseTable = /*#__PURE__*/function () {
  6990. function BaseTable(e, t) {
  6991. _classCallCheck(this, BaseTable);
  6992. this.db = null;
  6993. this.isCreatingTable = !1;
  6994. this.hasCleared = !1;
  6995. this.dbName = e, this.dbVersion = t;
  6996. }
  6997. _createClass(BaseTable, [{
  6998. key: "clearDataBase",
  6999. value: function () {
  7000. var _clearDataBase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  7001. var _this = this;
  7002. return regenerator.wrap(function _callee$(_context) {
  7003. while (1) {
  7004. switch (_context.prev = _context.next) {
  7005. case 0:
  7006. return _context.abrupt("return", this.hasCleared || (e && (this.hasCleared = !0), !window.indexedDB.databases) ? Promise.resolve() : new Promise(function (t, r) {
  7007. var n = window.indexedDB.deleteDatabase(_this.dbName);
  7008. n.onsuccess = function () {
  7009. t();
  7010. }, n.onerror = r;
  7011. }));
  7012. case 1:
  7013. case "end":
  7014. return _context.stop();
  7015. }
  7016. }
  7017. }, _callee, this);
  7018. }));
  7019. function clearDataBase(_x) {
  7020. return _clearDataBase.apply(this, arguments);
  7021. }
  7022. return clearDataBase;
  7023. }()
  7024. }, {
  7025. key: "tableName",
  7026. value: function tableName() {
  7027. throw new Error("Derived class have to override 'tableName', and set a proper table name!");
  7028. }
  7029. }, {
  7030. key: "keyPath",
  7031. value: function keyPath() {
  7032. throw new Error("Derived class have to override 'keyPath', and set a proper index name!");
  7033. }
  7034. }, {
  7035. key: "index",
  7036. value: function index() {
  7037. throw new Error("Derived class have to override 'index', and set a proper index name!");
  7038. }
  7039. }, {
  7040. key: "checkAndOpenDatabase",
  7041. value: function () {
  7042. var _checkAndOpenDatabase = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  7043. var _this2 = this;
  7044. return regenerator.wrap(function _callee2$(_context2) {
  7045. while (1) {
  7046. switch (_context2.prev = _context2.next) {
  7047. case 0:
  7048. return _context2.abrupt("return", this.db ? Promise.resolve(this.db) : new Promise(function (e, t) {
  7049. var n = setTimeout(function () {
  7050. logger.info("wait db to open for", 200), _this2.db ? e(_this2.db) : e(_this2.checkAndOpenDatabase()), clearTimeout(n);
  7051. }, 200);
  7052. _this2.openDatabase(_this2.dbName, _this2.dbVersion || 1, function () {
  7053. _this2.db && !_this2.isCreatingTable && e(_this2.db), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable)), clearTimeout(n);
  7054. }, function () {
  7055. t(new Error("Failed to open database!")), clearTimeout(n);
  7056. }, function () {
  7057. _this2.db && e(_this2.db), clearTimeout(n), logger.info("successCallback called, this.db: ".concat(!!_this2.db, ", this.isCreatingStore: ").concat(_this2.isCreatingTable));
  7058. });
  7059. }));
  7060. case 1:
  7061. case "end":
  7062. return _context2.stop();
  7063. }
  7064. }
  7065. }, _callee2, this);
  7066. }));
  7067. function checkAndOpenDatabase() {
  7068. return _checkAndOpenDatabase.apply(this, arguments);
  7069. }
  7070. return checkAndOpenDatabase;
  7071. }()
  7072. }, {
  7073. key: "openDatabase",
  7074. value: function openDatabase(e, t, r, n, o) {
  7075. var _this3 = this;
  7076. if (this.isCreatingTable) return;
  7077. this.isCreatingTable = !0, logger.info(e, t);
  7078. var a = window.indexedDB.open(e, t),
  7079. s = this.tableName();
  7080. a.onsuccess = function (l) {
  7081. _this3.db = a.result, logger.info("IndexedDb ".concat(e, " is opened.")), _this3.db.objectStoreNames.contains(s) && (_this3.isCreatingTable = !1), r && r(l);
  7082. }, a.onerror = function (l) {
  7083. var u;
  7084. 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);
  7085. }, a.onupgradeneeded = function (l) {
  7086. var u = l.target.result,
  7087. c = _this3.index();
  7088. logger.info("Creating table ".concat(s, "."));
  7089. var h = u.objectStoreNames.contains(s);
  7090. if (h) h = u.transaction([s], "readwrite").objectStore(s);else {
  7091. var f = _this3.keyPath();
  7092. h = u.createObjectStore(s, {
  7093. keyPath: f
  7094. });
  7095. }
  7096. c.map(function (f) {
  7097. h.createIndex(f, f, {
  7098. unique: !1
  7099. });
  7100. }), _this3.isCreatingTable = !1, logger.info("Table ".concat(s, " opened")), o && o(l);
  7101. };
  7102. }
  7103. }, {
  7104. key: "add",
  7105. value: function () {
  7106. var _add = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e) {
  7107. var t, o;
  7108. return regenerator.wrap(function _callee3$(_context3) {
  7109. while (1) {
  7110. switch (_context3.prev = _context3.next) {
  7111. case 0:
  7112. t = this.tableName();
  7113. _context3.next = 3;
  7114. return this.checkAndOpenDatabase();
  7115. case 3:
  7116. o = _context3.sent.transaction([t], "readwrite").objectStore(t).add(e);
  7117. return _context3.abrupt("return", new Promise(function (a, s) {
  7118. o.onsuccess = function (l) {
  7119. a(l);
  7120. }, o.onerror = function (l) {
  7121. var u;
  7122. logger.error((u = l.srcElement) == null ? void 0 : u.error), s(l);
  7123. };
  7124. }));
  7125. case 5:
  7126. case "end":
  7127. return _context3.stop();
  7128. }
  7129. }
  7130. }, _callee3, this);
  7131. }));
  7132. function add(_x2) {
  7133. return _add.apply(this, arguments);
  7134. }
  7135. return add;
  7136. }()
  7137. }, {
  7138. key: "put",
  7139. value: function () {
  7140. var _put = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  7141. var t, o;
  7142. return regenerator.wrap(function _callee4$(_context4) {
  7143. while (1) {
  7144. switch (_context4.prev = _context4.next) {
  7145. case 0:
  7146. t = this.tableName();
  7147. _context4.next = 3;
  7148. return this.checkAndOpenDatabase();
  7149. case 3:
  7150. o = _context4.sent.transaction([t], "readwrite").objectStore(t).put(e);
  7151. return _context4.abrupt("return", new Promise(function (a, s) {
  7152. o.onsuccess = function (l) {
  7153. a(l);
  7154. }, o.onerror = function (l) {
  7155. var u;
  7156. logger.error("db put error", (u = l.srcElement) == null ? void 0 : u.error), s(l);
  7157. };
  7158. }));
  7159. case 5:
  7160. case "end":
  7161. return _context4.stop();
  7162. }
  7163. }
  7164. }, _callee4, this);
  7165. }));
  7166. function put(_x3) {
  7167. return _put.apply(this, arguments);
  7168. }
  7169. return put;
  7170. }()
  7171. }, {
  7172. key: "delete",
  7173. value: function _delete(e, t, r) {
  7174. var n = this.tableName();
  7175. this.checkAndOpenDatabase().then(function (o) {
  7176. var s = o.transaction([n], "readwrite").objectStore(n).delete(e);
  7177. s.onsuccess = t, s.onerror = r;
  7178. });
  7179. }
  7180. }, {
  7181. key: "update",
  7182. value: function update() {
  7183. this.checkAndOpenDatabase().then(function (e) {});
  7184. }
  7185. }, {
  7186. key: "getAllKeys",
  7187. value: function () {
  7188. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5() {
  7189. var e, t;
  7190. return regenerator.wrap(function _callee5$(_context5) {
  7191. while (1) {
  7192. switch (_context5.prev = _context5.next) {
  7193. case 0:
  7194. e = this.tableName();
  7195. _context5.next = 3;
  7196. return this.checkAndOpenDatabase();
  7197. case 3:
  7198. t = _context5.sent;
  7199. return _context5.abrupt("return", new Promise(function (r, n) {
  7200. var a = t.transaction([e], "readonly").objectStore(e).getAllKeys();
  7201. a.onsuccess = function (s) {
  7202. r(s.target.result);
  7203. }, a.onerror = function (s) {
  7204. logger.error("db getAllKeys error", s), n(s);
  7205. };
  7206. }));
  7207. case 5:
  7208. case "end":
  7209. return _context5.stop();
  7210. }
  7211. }
  7212. }, _callee5, this);
  7213. }));
  7214. function getAllKeys() {
  7215. return _getAllKeys.apply(this, arguments);
  7216. }
  7217. return getAllKeys;
  7218. }()
  7219. }, {
  7220. key: "query",
  7221. value: function () {
  7222. var _query = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t) {
  7223. var r, n;
  7224. return regenerator.wrap(function _callee6$(_context6) {
  7225. while (1) {
  7226. switch (_context6.prev = _context6.next) {
  7227. case 0:
  7228. r = this.tableName();
  7229. _context6.next = 3;
  7230. return this.checkAndOpenDatabase();
  7231. case 3:
  7232. n = _context6.sent;
  7233. return _context6.abrupt("return", new Promise(function (o, a) {
  7234. var u = n.transaction([r], "readonly").objectStore(r).index(e).get(t);
  7235. u.onsuccess = function (c) {
  7236. var f;
  7237. var h = (f = c == null ? void 0 : c.target) == null ? void 0 : f.result;
  7238. o && o(h);
  7239. }, u.onerror = function (c) {
  7240. logger.error("db query error", c), a(c);
  7241. };
  7242. }));
  7243. case 5:
  7244. case "end":
  7245. return _context6.stop();
  7246. }
  7247. }
  7248. }, _callee6, this);
  7249. }));
  7250. function query(_x4, _x5) {
  7251. return _query.apply(this, arguments);
  7252. }
  7253. return query;
  7254. }()
  7255. }, {
  7256. key: "sleep",
  7257. value: function () {
  7258. var _sleep = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee7(e) {
  7259. return regenerator.wrap(function _callee7$(_context7) {
  7260. while (1) {
  7261. switch (_context7.prev = _context7.next) {
  7262. case 0:
  7263. return _context7.abrupt("return", new Promise(function (t) {
  7264. setTimeout(function () {
  7265. t("");
  7266. }, e);
  7267. }));
  7268. case 1:
  7269. case "end":
  7270. return _context7.stop();
  7271. }
  7272. }
  7273. }, _callee7);
  7274. }));
  7275. function sleep(_x6) {
  7276. return _sleep.apply(this, arguments);
  7277. }
  7278. return sleep;
  7279. }()
  7280. }]);
  7281. return BaseTable;
  7282. }();
  7283. 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); }; }
  7284. 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; } }
  7285. var ModelTable = /*#__PURE__*/function (_BaseTable) {
  7286. _inherits(ModelTable, _BaseTable);
  7287. var _super = _createSuper(ModelTable);
  7288. function ModelTable() {
  7289. _classCallCheck(this, ModelTable);
  7290. return _super.call(this, "XverseDatabase", 1);
  7291. }
  7292. _createClass(ModelTable, [{
  7293. key: "tableName",
  7294. value: function tableName() {
  7295. return "models";
  7296. }
  7297. }, {
  7298. key: "index",
  7299. value: function index() {
  7300. return ["url"];
  7301. }
  7302. }, {
  7303. key: "keyPath",
  7304. value: function keyPath() {
  7305. return "url";
  7306. }
  7307. }]);
  7308. return ModelTable;
  7309. }(BaseTable);
  7310. var modelTable = new ModelTable();
  7311. var Preload = /*#__PURE__*/function () {
  7312. function Preload(e) {
  7313. _classCallCheck(this, Preload);
  7314. this.config = null;
  7315. this.allKeys = [];
  7316. this.oldResourcesDeleted = !1;
  7317. this.requests = {
  7318. simple: {
  7319. stopped: !0,
  7320. requests: {}
  7321. },
  7322. observer: {
  7323. stopped: !0,
  7324. requests: {}
  7325. },
  7326. full: {
  7327. stopped: !0,
  7328. requests: {}
  7329. }
  7330. };
  7331. this.modelManager = e, this.init(e.appId);
  7332. }
  7333. _createClass(Preload, [{
  7334. key: "init",
  7335. value: function init(e) {
  7336. reporter$1.updateBody({
  7337. appId: e
  7338. });
  7339. }
  7340. }, {
  7341. key: "getConfig",
  7342. value: function () {
  7343. var _getConfig = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(e) {
  7344. var _yield$this$modelMana, t;
  7345. return regenerator.wrap(function _callee$(_context) {
  7346. while (1) {
  7347. switch (_context.prev = _context.next) {
  7348. case 0:
  7349. if (!this.config) {
  7350. _context.next = 2;
  7351. break;
  7352. }
  7353. return _context.abrupt("return", this.config);
  7354. case 2:
  7355. _context.next = 4;
  7356. return this.modelManager.requestConfig();
  7357. case 4:
  7358. _yield$this$modelMana = _context.sent;
  7359. t = _yield$this$modelMana.preload;
  7360. return _context.abrupt("return", t ? (this.config = t, Promise.resolve(t)) : Promise.reject("no preload config"));
  7361. case 7:
  7362. case "end":
  7363. return _context.stop();
  7364. }
  7365. }
  7366. }, _callee, this);
  7367. }));
  7368. function getConfig(_x) {
  7369. return _getConfig.apply(this, arguments);
  7370. }
  7371. return getConfig;
  7372. }()
  7373. }, {
  7374. key: "getAllKeys",
  7375. value: function () {
  7376. var _getAllKeys = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  7377. var e, t;
  7378. return regenerator.wrap(function _callee2$(_context2) {
  7379. while (1) {
  7380. switch (_context2.prev = _context2.next) {
  7381. case 0:
  7382. if (!this.allKeys.length) {
  7383. _context2.next = 2;
  7384. break;
  7385. }
  7386. return _context2.abrupt("return", this.allKeys);
  7387. case 2:
  7388. _context2.prev = 2;
  7389. _context2.next = 5;
  7390. return modelTable.getAllKeys();
  7391. case 5:
  7392. e = _context2.sent;
  7393. this.allKeys = e;
  7394. return _context2.abrupt("return", e);
  7395. case 10:
  7396. _context2.prev = 10;
  7397. _context2.t0 = _context2["catch"](2);
  7398. t = "preload getAllKeys error";
  7399. return _context2.abrupt("return", (logger.error(t), Promise.reject(t)));
  7400. case 14:
  7401. case "end":
  7402. return _context2.stop();
  7403. }
  7404. }
  7405. }, _callee2, this, [[2, 10]]);
  7406. }));
  7407. function getAllKeys() {
  7408. return _getAllKeys.apply(this, arguments);
  7409. }
  7410. return getAllKeys;
  7411. }()
  7412. }, {
  7413. key: "stop",
  7414. value: function stop(e) {
  7415. e === "serverless" && (e = "observer"), this.requests[e].stopped = !0;
  7416. var t = this.requests[e].requests;
  7417. Object.keys(t).forEach(function (r) {
  7418. http1.canceler.removePending(r), delete t[r];
  7419. });
  7420. }
  7421. }, {
  7422. key: "clearPreload",
  7423. value: function clearPreload(e) {
  7424. this.requests[e].stopped = !1, this.allKeys = [];
  7425. }
  7426. }, {
  7427. key: "start",
  7428. value: function () {
  7429. var _start = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(e, t, r) {
  7430. var n, o, a, s, l, u, h, f, _s;
  7431. return regenerator.wrap(function _callee3$(_context3) {
  7432. while (1) {
  7433. switch (_context3.prev = _context3.next) {
  7434. case 0:
  7435. n = Date.now(), o = 0;
  7436. _context3.prev = 1;
  7437. if (!(e === "serverless" && (e = "observer"), !this.requests[e])) {
  7438. _context3.next = 4;
  7439. break;
  7440. }
  7441. return _context3.abrupt("return", Promise.reject(new ParamError("invalid stage name: " + e)));
  7442. case 4:
  7443. this.clearPreload(e);
  7444. _context3.next = 7;
  7445. return this.getConfig(e);
  7446. case 7:
  7447. a = _context3.sent;
  7448. _context3.next = 10;
  7449. return this.getAllKeys();
  7450. case 10:
  7451. s = _context3.sent;
  7452. _context3.prev = 11;
  7453. _context3.next = 14;
  7454. return this.deleteOldResources(a.assetUrls.map(function (d) {
  7455. return d.url;
  7456. }), s);
  7457. case 14:
  7458. _context3.next = 19;
  7459. break;
  7460. case 16:
  7461. _context3.prev = 16;
  7462. _context3.t0 = _context3["catch"](11);
  7463. logger.error(_context3.t0);
  7464. case 19:
  7465. l = a.baseUrls, u = a.assetUrls;
  7466. _context3.t1 = e;
  7467. _context3.next = _context3.t1 === "simple" ? 23 : _context3.t1 === "observer" ? 25 : _context3.t1 === "full" ? 27 : 29;
  7468. break;
  7469. case 23:
  7470. h = l;
  7471. return _context3.abrupt("break", 30);
  7472. case 25:
  7473. h = u;
  7474. return _context3.abrupt("break", 30);
  7475. case 27:
  7476. h = u;
  7477. return _context3.abrupt("break", 30);
  7478. case 29:
  7479. h = u;
  7480. case 30:
  7481. f = h.filter(function (d) {
  7482. return !s.includes(d.url);
  7483. });
  7484. r && isFunction(r) && (f = f.filter(r));
  7485. o = f.length;
  7486. logger.debug("keysNeedToPreload", f);
  7487. f.length || t && t(h.length, h.length);
  7488. n = Date.now();
  7489. _context3.next = 38;
  7490. return this._preload(e, f, t);
  7491. case 38:
  7492. logger.infoAndReportMeasurement({
  7493. tag: e,
  7494. startTime: n,
  7495. metric: "assetsPreload",
  7496. extra: {
  7497. total: o
  7498. }
  7499. });
  7500. return _context3.abrupt("return");
  7501. case 42:
  7502. _context3.prev = 42;
  7503. _context3.t2 = _context3["catch"](1);
  7504. _s = _context3.t2;
  7505. return _context3.abrupt("return", ((this.requests[e].stopped || axios.isCancel(_context3.t2)) && (_s = new PreloadCanceledError()), logger.infoAndReportMeasurement({
  7506. tag: e,
  7507. startTime: n,
  7508. metric: "assetsPreload",
  7509. extra: {
  7510. total: o
  7511. },
  7512. error: _s,
  7513. reportOptions: {
  7514. immediate: !0
  7515. }
  7516. }), Promise.reject(_s)));
  7517. case 46:
  7518. case "end":
  7519. return _context3.stop();
  7520. }
  7521. }
  7522. }, _callee3, this, [[1, 42], [11, 16]]);
  7523. }));
  7524. function start(_x2, _x3, _x4) {
  7525. return _start.apply(this, arguments);
  7526. }
  7527. return start;
  7528. }()
  7529. }, {
  7530. key: "deleteOldResources",
  7531. value: function deleteOldResources(e, t) {
  7532. if (!this.oldResourcesDeleted) this.oldResourcesDeleted = !0;else return Promise.resolve();
  7533. var r = t.filter(function (n) {
  7534. return !e.includes(n);
  7535. });
  7536. return logger.debug("keysNeedToDelete", r), logger.warn("keysNeedToDelete", r.length), Promise.all(r.map(function (n) {
  7537. return modelTable.delete(n);
  7538. }));
  7539. }
  7540. }, {
  7541. key: "_preload",
  7542. value: function () {
  7543. var _preload2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee6(e, t, r) {
  7544. var _this = this;
  7545. var n, o, a;
  7546. return regenerator.wrap(function _callee6$(_context6) {
  7547. while (1) {
  7548. switch (_context6.prev = _context6.next) {
  7549. case 0:
  7550. n = t.length;
  7551. if (n) {
  7552. _context6.next = 3;
  7553. break;
  7554. }
  7555. return _context6.abrupt("return", Promise.resolve());
  7556. case 3:
  7557. o = 0;
  7558. a = window.setInterval(function () {
  7559. r && r(o, n), o >= n && window.clearInterval(a);
  7560. }, 1e3);
  7561. return _context6.abrupt("return", util.mapLimit(t, 10, /*#__PURE__*/function () {
  7562. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee5(s) {
  7563. var l, u;
  7564. return regenerator.wrap(function _callee5$(_context5) {
  7565. while (1) {
  7566. switch (_context5.prev = _context5.next) {
  7567. case 0:
  7568. l = s.size, u = s.url;
  7569. return _context5.abrupt("return", _this.requests[e].stopped ? Promise.reject(new PreloadCanceledError()) : http1.get({
  7570. url: u,
  7571. timeout: Preload.getTimeoutBySize(l),
  7572. responseType: "blob",
  7573. retry: 2,
  7574. beforeRequest: function beforeRequest() {
  7575. _this.requests[e].requests[u] = !0;
  7576. }
  7577. }).then( /*#__PURE__*/function () {
  7578. var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(c) {
  7579. var h, f;
  7580. return regenerator.wrap(function _callee4$(_context4) {
  7581. while (1) {
  7582. switch (_context4.prev = _context4.next) {
  7583. case 0:
  7584. h = c.data;
  7585. if (h instanceof Blob) {
  7586. _context4.next = 3;
  7587. break;
  7588. }
  7589. return _context4.abrupt("return", (logger.error("request blob failed, type:", typeof h, u), Promise.reject("request blob failed " + u)));
  7590. case 3:
  7591. _context4.next = 5;
  7592. return blobToDataURI(h);
  7593. case 5:
  7594. f = _context4.sent;
  7595. _context4.prev = 6;
  7596. _context4.next = 9;
  7597. return modelTable.put({
  7598. url: u,
  7599. model: f
  7600. });
  7601. case 9:
  7602. return _context4.abrupt("return");
  7603. case 12:
  7604. _context4.prev = 12;
  7605. _context4.t0 = _context4["catch"](6);
  7606. return _context4.abrupt("return", (logger.error("unable to add data to indexedDB", _context4.t0), Promise.reject(new InternalError("preload db error"))));
  7607. case 15:
  7608. case "end":
  7609. return _context4.stop();
  7610. }
  7611. }
  7612. }, _callee4, null, [[6, 12]]);
  7613. }));
  7614. return function (_x9) {
  7615. return _ref2.apply(this, arguments);
  7616. };
  7617. }()).then(function () {
  7618. o++, delete _this.requests[e].requests[u];
  7619. }, function (c) {
  7620. return delete _this.requests[e].requests[u], window.clearInterval(a), Promise.reject(c);
  7621. }));
  7622. case 2:
  7623. case "end":
  7624. return _context5.stop();
  7625. }
  7626. }
  7627. }, _callee5);
  7628. }));
  7629. return function (_x8) {
  7630. return _ref.apply(this, arguments);
  7631. };
  7632. }()));
  7633. case 6:
  7634. case "end":
  7635. return _context6.stop();
  7636. }
  7637. }
  7638. }, _callee6);
  7639. }));
  7640. function _preload(_x5, _x6, _x7) {
  7641. return _preload2.apply(this, arguments);
  7642. }
  7643. return _preload;
  7644. }()
  7645. }], [{
  7646. key: "getTimeoutBySize",
  7647. value: function getTimeoutBySize(e) {
  7648. return e ? e < 500 * 1e3 ? 30 * 1e3 : e < 1e3 * 1e3 ? 60 * 1e3 : 100 * 1e3 : 100 * 1e3;
  7649. }
  7650. }]);
  7651. return Preload;
  7652. }();
  7653. var RenderType$1 = {
  7654. PathVideo: 0,
  7655. RotationVideo: 1,
  7656. RotationImage: 2,
  7657. PanoramaImage: 3,
  7658. CGVideo: 4,
  7659. ClientRotationPano: 5,
  7660. CloudRotationPano: 6
  7661. };
  7662. var Xverse = /*#__PURE__*/function () {
  7663. function Xverse(e) {
  7664. _classCallCheck(this, Xverse);
  7665. e || (e = {});
  7666. var _e = e,
  7667. t = _e.onLog,
  7668. r = _e.env,
  7669. n = _e.appId,
  7670. o = _e.releaseId,
  7671. a = _e.subPackageVersion;
  7672. this.NO_CACHE = !1, this.env = r || "PROD", this.SUB_PACKAGE_VERSION = a, this.debug && logger.setLevel(LoggerLevels.Debug);
  7673. var s = this.pageSession = util.uuid();
  7674. reporter$1.updateHeader({
  7675. pageSession: s
  7676. });
  7677. reporter$1.updateReportUrl(REPORT_URL[this.env]);
  7678. a && reporter$1.updateBody({
  7679. sdkVersion: a
  7680. });
  7681. logger.infoAndReportMeasurement({
  7682. metric: "sdkInit",
  7683. startTime: Date.now(),
  7684. extra: {
  7685. version: a,
  7686. enviroment: r,
  7687. pageSession: s
  7688. }
  7689. });
  7690. logger.debug("debug mode:", this.debug);
  7691. reporter$1.on("report", function (l) {
  7692. t && t(l);
  7693. });
  7694. if (n) {
  7695. this.appId = n, this.releaseId = o;
  7696. var l = ModelManager.getInstance(n, o);
  7697. this.preload = new Preload(l);
  7698. }
  7699. }
  7700. _createClass(Xverse, [{
  7701. key: "isSupported",
  7702. get: function get() {
  7703. return isSupported();
  7704. }
  7705. }, {
  7706. key: "disableLogUpload",
  7707. value: function disableLogUpload() {
  7708. reporter$1.disable(), logger.debug("logger upload has been disabled");
  7709. }
  7710. }, {
  7711. key: "getSkinList",
  7712. value: function () {
  7713. var _getSkinList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  7714. return regenerator.wrap(function _callee$(_context) {
  7715. while (1) {
  7716. switch (_context.prev = _context.next) {
  7717. case 0:
  7718. return _context.abrupt("return", []);
  7719. case 1:
  7720. case "end":
  7721. return _context.stop();
  7722. }
  7723. }
  7724. }, _callee);
  7725. }));
  7726. function getSkinList() {
  7727. return _getSkinList.apply(this, arguments);
  7728. }
  7729. return getSkinList;
  7730. }()
  7731. }, {
  7732. key: "getAvatarList",
  7733. value: function () {
  7734. var _getAvatarList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() {
  7735. return regenerator.wrap(function _callee2$(_context2) {
  7736. while (1) {
  7737. switch (_context2.prev = _context2.next) {
  7738. case 0:
  7739. return _context2.abrupt("return", []);
  7740. case 1:
  7741. case "end":
  7742. return _context2.stop();
  7743. }
  7744. }
  7745. }, _callee2);
  7746. }));
  7747. function getAvatarList() {
  7748. return _getAvatarList.apply(this, arguments);
  7749. }
  7750. return getAvatarList;
  7751. }()
  7752. }, {
  7753. key: "getGiftList",
  7754. value: function () {
  7755. var _getGiftList = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3() {
  7756. return regenerator.wrap(function _callee3$(_context3) {
  7757. while (1) {
  7758. switch (_context3.prev = _context3.next) {
  7759. case 0:
  7760. return _context3.abrupt("return", [{
  7761. id: "hack "
  7762. }]);
  7763. case 1:
  7764. case "end":
  7765. return _context3.stop();
  7766. }
  7767. }
  7768. }, _callee3);
  7769. }));
  7770. function getGiftList() {
  7771. return _getGiftList.apply(this, arguments);
  7772. }
  7773. return getGiftList;
  7774. }()
  7775. }, {
  7776. key: "joinRoom",
  7777. value: function () {
  7778. var _joinRoom = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee4(e) {
  7779. var t, r, n, o;
  7780. return regenerator.wrap(function _callee4$(_context4) {
  7781. while (1) {
  7782. switch (_context4.prev = _context4.next) {
  7783. case 0:
  7784. t = e.pathName || "thirdwalk", r = e.rotationRenderType || RenderType$1.RotationVideo, n = e.person || Person$1.Third, o = new XverseRoom(le(oe({}, e), {
  7785. appId: e.appId || this.appId,
  7786. releaseId: e.releaseId || this.releaseId,
  7787. pageSession: this.pageSession,
  7788. isAllSync: !0,
  7789. rotationRenderType: r,
  7790. syncByEvent: !0,
  7791. pathName: t,
  7792. person: n,
  7793. role: e.role || "audience"
  7794. }));
  7795. return _context4.abrupt("return", o.initRoom().then(function () {
  7796. return o;
  7797. }));
  7798. case 2:
  7799. case "end":
  7800. return _context4.stop();
  7801. }
  7802. }
  7803. }, _callee4, this);
  7804. }));
  7805. function joinRoom(_x) {
  7806. return _joinRoom.apply(this, arguments);
  7807. }
  7808. return joinRoom;
  7809. }()
  7810. }]);
  7811. return Xverse;
  7812. }();
  7813. var xverse = new Xverse({
  7814. env: "DEV",
  7815. appId: "10016",
  7816. releaseId: '2203120033_29769e'
  7817. });
  7818. var l = /*#__PURE__*/function () {
  7819. var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
  7820. var R;
  7821. return regenerator.wrap(function _callee$(_context) {
  7822. while (1) {
  7823. switch (_context.prev = _context.next) {
  7824. case 0:
  7825. _context.prev = 0;
  7826. _context.next = 3;
  7827. return (R = xverse.preload) == null ? void 0 : R.start('full', function (M, x) {
  7828. });
  7829. case 3:
  7830. _context.next = 12;
  7831. break;
  7832. case 5:
  7833. _context.prev = 5;
  7834. _context.t0 = _context["catch"](0);
  7835. if (!(console.error(_context.t0), _context.t0.code === Codes.PreloadCanceled)) {
  7836. _context.next = 10;
  7837. break;
  7838. }
  7839. toast("\u9884\u52A0\u8F7D\u88AB\u53D6\u6D88");
  7840. return _context.abrupt("return");
  7841. case 10:
  7842. toast("\u8FDB\u5165\u5931\u8D25, \u8BF7\u91CD\u8BD5");
  7843. return _context.abrupt("return");
  7844. case 12:
  7845. _context.prev = 12;
  7846. _context.next = 15;
  7847. return xverse.joinRoom({
  7848. canvas: document.getElementById('canvas'),
  7849. skinId: 10092,
  7850. avatarId: 'KGe_Boy',
  7851. roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
  7852. userId: '1f7acca1db9d5',
  7853. wsServerUrl: 'wss://uat-eks.xverse.cn/ws',
  7854. appId: "10016",
  7855. token: " ",
  7856. nickname: '1f7acca1db9d5',
  7857. firends: ["user1"],
  7858. viewMode: "full",
  7859. resolution: {
  7860. width: 1728,
  7861. height: 720
  7862. },
  7863. pathName: 'thirdwalk',
  7864. objectFit: null,
  7865. hasAvatar: !0,
  7866. syncToOthers: !0
  7867. });
  7868. case 15:
  7869. room = _context.sent;
  7870. debugger;
  7871. u();
  7872. c();
  7873. window.room = room;
  7874. e(!1);
  7875. _context.next = 28;
  7876. break;
  7877. case 23:
  7878. _context.prev = 23;
  7879. _context.t1 = _context["catch"](12);
  7880. console.error(_context.t1);
  7881. alert(_context.t1);
  7882. return _context.abrupt("return");
  7883. case 28:
  7884. case "end":
  7885. return _context.stop();
  7886. }
  7887. }
  7888. }, _callee, null, [[0, 5], [12, 23]]);
  7889. }));
  7890. return function l() {
  7891. return _ref.apply(this, arguments);
  7892. };
  7893. }();
  7894. var u = function u() {
  7895. room.on("_coreClick", function (_ref2) {
  7896. var f = _ref2.point;
  7897. room._userAvatar.moveTo({
  7898. point: f
  7899. });
  7900. });
  7901. };
  7902. var c = function c() {
  7903. room.on("repeatLogin", function () {
  7904. toast("\u8BE5\u7528\u6237\u5DF2\u7ECF\u5728\u5176\u4ED6\u5730\u70B9\u767B\u5F55", {
  7905. duration: 1e4
  7906. });
  7907. }), room.on("reconnecting", function (_ref3) {
  7908. var f = _ref3.count;
  7909. toast("\u5C1D\u8BD5\u7B2C".concat(f, "\u6B21\u91CD\u8FDE"));
  7910. }), room.on("reconnected", function () {
  7911. toast("\u91CD\u8FDE\u6210\u529F");
  7912. }), room.on("disconnected", function () {
  7913. var f = toast("\u8FDE\u63A5\u5931\u8D25\uFF0C\u624B\u52A8\u70B9\u51FB\u91CD\u8BD5", {
  7914. duration: 1e5,
  7915. onClick() {
  7916. f.hideToast(), room.reconnect();
  7917. }
  7918. });
  7919. });
  7920. };
  7921. l();
  7922. }));
  7923. //# sourceMappingURL=index.js.map