server.js 345 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory((function webpackLoadOptionalExternalModule() { try { return require("bufferutil"); } catch(e) {} }()), (function webpackLoadOptionalExternalModule() { try { return require("utf-8-validate"); } catch(e) {} }()));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["bufferutil", "utf-8-validate"], factory);
  6. else if(typeof exports === 'object')
  7. exports["Node"] = factory((function webpackLoadOptionalExternalModule() { try { return require("bufferutil"); } catch(e) {} }()), (function webpackLoadOptionalExternalModule() { try { return require("utf-8-validate"); } catch(e) {} }()));
  8. else
  9. root["Node"] = factory(root["bufferutil"], root["utf-8-validate"]);
  10. })(global, function(__WEBPACK_EXTERNAL_MODULE_bufferutil__, __WEBPACK_EXTERNAL_MODULE_utf_8_validate__) {
  11. return /******/ (() => { // webpackBootstrap
  12. /******/ var __webpack_modules__ = ({
  13. /***/ "../ot-core/node_modules/@socket.io/component-emitter/index.js":
  14. /*!*********************************************************************!*\
  15. !*** ../ot-core/node_modules/@socket.io/component-emitter/index.js ***!
  16. \*********************************************************************/
  17. /***/ ((__unused_webpack_module, exports) => {
  18. /**
  19. * Expose `Emitter`.
  20. */
  21. exports.Emitter = Emitter;
  22. /**
  23. * Initialize a new `Emitter`.
  24. *
  25. * @api public
  26. */
  27. function Emitter(obj) {
  28. if (obj) return mixin(obj);
  29. }
  30. /**
  31. * Mixin the emitter properties.
  32. *
  33. * @param {Object} obj
  34. * @return {Object}
  35. * @api private
  36. */
  37. function mixin(obj) {
  38. for (var key in Emitter.prototype) {
  39. obj[key] = Emitter.prototype[key];
  40. }
  41. return obj;
  42. }
  43. /**
  44. * Listen on the given `event` with `fn`.
  45. *
  46. * @param {String} event
  47. * @param {Function} fn
  48. * @return {Emitter}
  49. * @api public
  50. */
  51. Emitter.prototype.on =
  52. Emitter.prototype.addEventListener = function(event, fn){
  53. this._callbacks = this._callbacks || {};
  54. (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
  55. .push(fn);
  56. return this;
  57. };
  58. /**
  59. * Adds an `event` listener that will be invoked a single
  60. * time then automatically removed.
  61. *
  62. * @param {String} event
  63. * @param {Function} fn
  64. * @return {Emitter}
  65. * @api public
  66. */
  67. Emitter.prototype.once = function(event, fn){
  68. function on() {
  69. this.off(event, on);
  70. fn.apply(this, arguments);
  71. }
  72. on.fn = fn;
  73. this.on(event, on);
  74. return this;
  75. };
  76. /**
  77. * Remove the given callback for `event` or all
  78. * registered callbacks.
  79. *
  80. * @param {String} event
  81. * @param {Function} fn
  82. * @return {Emitter}
  83. * @api public
  84. */
  85. Emitter.prototype.off =
  86. Emitter.prototype.removeListener =
  87. Emitter.prototype.removeAllListeners =
  88. Emitter.prototype.removeEventListener = function(event, fn){
  89. this._callbacks = this._callbacks || {};
  90. // all
  91. if (0 == arguments.length) {
  92. this._callbacks = {};
  93. return this;
  94. }
  95. // specific event
  96. var callbacks = this._callbacks['$' + event];
  97. if (!callbacks) return this;
  98. // remove all handlers
  99. if (1 == arguments.length) {
  100. delete this._callbacks['$' + event];
  101. return this;
  102. }
  103. // remove specific handler
  104. var cb;
  105. for (var i = 0; i < callbacks.length; i++) {
  106. cb = callbacks[i];
  107. if (cb === fn || cb.fn === fn) {
  108. callbacks.splice(i, 1);
  109. break;
  110. }
  111. }
  112. // Remove event specific arrays for event types that no
  113. // one is subscribed for to avoid memory leak.
  114. if (callbacks.length === 0) {
  115. delete this._callbacks['$' + event];
  116. }
  117. return this;
  118. };
  119. /**
  120. * Emit `event` with the given args.
  121. *
  122. * @param {String} event
  123. * @param {Mixed} ...
  124. * @return {Emitter}
  125. */
  126. Emitter.prototype.emit = function(event){
  127. this._callbacks = this._callbacks || {};
  128. var args = new Array(arguments.length - 1)
  129. , callbacks = this._callbacks['$' + event];
  130. for (var i = 1; i < arguments.length; i++) {
  131. args[i - 1] = arguments[i];
  132. }
  133. if (callbacks) {
  134. callbacks = callbacks.slice(0);
  135. for (var i = 0, len = callbacks.length; i < len; ++i) {
  136. callbacks[i].apply(this, args);
  137. }
  138. }
  139. return this;
  140. };
  141. // alias used for reserved events (protected method)
  142. Emitter.prototype.emitReserved = Emitter.prototype.emit;
  143. /**
  144. * Return array of callbacks for `event`.
  145. *
  146. * @param {String} event
  147. * @return {Array}
  148. * @api public
  149. */
  150. Emitter.prototype.listeners = function(event){
  151. this._callbacks = this._callbacks || {};
  152. return this._callbacks['$' + event] || [];
  153. };
  154. /**
  155. * Check if this emitter has `event` handlers.
  156. *
  157. * @param {String} event
  158. * @return {Boolean}
  159. * @api public
  160. */
  161. Emitter.prototype.hasListeners = function(event){
  162. return !! this.listeners(event).length;
  163. };
  164. /***/ }),
  165. /***/ "../ot-core/node_modules/backo2/index.js":
  166. /*!***********************************************!*\
  167. !*** ../ot-core/node_modules/backo2/index.js ***!
  168. \***********************************************/
  169. /***/ ((module) => {
  170. /**
  171. * Expose `Backoff`.
  172. */
  173. module.exports = Backoff;
  174. /**
  175. * Initialize backoff timer with `opts`.
  176. *
  177. * - `min` initial timeout in milliseconds [100]
  178. * - `max` max timeout [10000]
  179. * - `jitter` [0]
  180. * - `factor` [2]
  181. *
  182. * @param {Object} opts
  183. * @api public
  184. */
  185. function Backoff(opts) {
  186. opts = opts || {};
  187. this.ms = opts.min || 100;
  188. this.max = opts.max || 10000;
  189. this.factor = opts.factor || 2;
  190. this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
  191. this.attempts = 0;
  192. }
  193. /**
  194. * Return the backoff duration.
  195. *
  196. * @return {Number}
  197. * @api public
  198. */
  199. Backoff.prototype.duration = function(){
  200. var ms = this.ms * Math.pow(this.factor, this.attempts++);
  201. if (this.jitter) {
  202. var rand = Math.random();
  203. var deviation = Math.floor(rand * this.jitter * ms);
  204. ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
  205. }
  206. return Math.min(ms, this.max) | 0;
  207. };
  208. /**
  209. * Reset the number of attempts.
  210. *
  211. * @api public
  212. */
  213. Backoff.prototype.reset = function(){
  214. this.attempts = 0;
  215. };
  216. /**
  217. * Set the minimum duration
  218. *
  219. * @api public
  220. */
  221. Backoff.prototype.setMin = function(min){
  222. this.ms = min;
  223. };
  224. /**
  225. * Set the maximum duration
  226. *
  227. * @api public
  228. */
  229. Backoff.prototype.setMax = function(max){
  230. this.max = max;
  231. };
  232. /**
  233. * Set the jitter
  234. *
  235. * @api public
  236. */
  237. Backoff.prototype.setJitter = function(jitter){
  238. this.jitter = jitter;
  239. };
  240. /***/ }),
  241. /***/ "../ot-core/node_modules/debug/src/browser.js":
  242. /*!****************************************************!*\
  243. !*** ../ot-core/node_modules/debug/src/browser.js ***!
  244. \****************************************************/
  245. /***/ ((module, exports, __webpack_require__) => {
  246. /* eslint-env browser */
  247. /**
  248. * This is the web browser implementation of `debug()`.
  249. */
  250. exports.formatArgs = formatArgs;
  251. exports.save = save;
  252. exports.load = load;
  253. exports.useColors = useColors;
  254. exports.storage = localstorage();
  255. exports.destroy = (() => {
  256. let warned = false;
  257. return () => {
  258. if (!warned) {
  259. warned = true;
  260. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  261. }
  262. };
  263. })();
  264. /**
  265. * Colors.
  266. */
  267. exports.colors = [
  268. '#0000CC',
  269. '#0000FF',
  270. '#0033CC',
  271. '#0033FF',
  272. '#0066CC',
  273. '#0066FF',
  274. '#0099CC',
  275. '#0099FF',
  276. '#00CC00',
  277. '#00CC33',
  278. '#00CC66',
  279. '#00CC99',
  280. '#00CCCC',
  281. '#00CCFF',
  282. '#3300CC',
  283. '#3300FF',
  284. '#3333CC',
  285. '#3333FF',
  286. '#3366CC',
  287. '#3366FF',
  288. '#3399CC',
  289. '#3399FF',
  290. '#33CC00',
  291. '#33CC33',
  292. '#33CC66',
  293. '#33CC99',
  294. '#33CCCC',
  295. '#33CCFF',
  296. '#6600CC',
  297. '#6600FF',
  298. '#6633CC',
  299. '#6633FF',
  300. '#66CC00',
  301. '#66CC33',
  302. '#9900CC',
  303. '#9900FF',
  304. '#9933CC',
  305. '#9933FF',
  306. '#99CC00',
  307. '#99CC33',
  308. '#CC0000',
  309. '#CC0033',
  310. '#CC0066',
  311. '#CC0099',
  312. '#CC00CC',
  313. '#CC00FF',
  314. '#CC3300',
  315. '#CC3333',
  316. '#CC3366',
  317. '#CC3399',
  318. '#CC33CC',
  319. '#CC33FF',
  320. '#CC6600',
  321. '#CC6633',
  322. '#CC9900',
  323. '#CC9933',
  324. '#CCCC00',
  325. '#CCCC33',
  326. '#FF0000',
  327. '#FF0033',
  328. '#FF0066',
  329. '#FF0099',
  330. '#FF00CC',
  331. '#FF00FF',
  332. '#FF3300',
  333. '#FF3333',
  334. '#FF3366',
  335. '#FF3399',
  336. '#FF33CC',
  337. '#FF33FF',
  338. '#FF6600',
  339. '#FF6633',
  340. '#FF9900',
  341. '#FF9933',
  342. '#FFCC00',
  343. '#FFCC33'
  344. ];
  345. /**
  346. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  347. * and the Firebug extension (any Firefox version) are known
  348. * to support "%c" CSS customizations.
  349. *
  350. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  351. */
  352. // eslint-disable-next-line complexity
  353. function useColors() {
  354. // NB: In an Electron preload script, document will be defined but not fully
  355. // initialized. Since we know we're in Chrome, we'll just detect this case
  356. // explicitly
  357. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  358. return true;
  359. }
  360. // Internet Explorer and Edge do not support colors.
  361. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  362. return false;
  363. }
  364. // Is webkit? http://stackoverflow.com/a/16459606/376773
  365. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  366. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  367. // Is firebug? http://stackoverflow.com/a/398120/376773
  368. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  369. // Is firefox >= v31?
  370. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  371. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  372. // Double check webkit in userAgent just in case we are in a worker
  373. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  374. }
  375. /**
  376. * Colorize log arguments if enabled.
  377. *
  378. * @api public
  379. */
  380. function formatArgs(args) {
  381. args[0] = (this.useColors ? '%c' : '') +
  382. this.namespace +
  383. (this.useColors ? ' %c' : ' ') +
  384. args[0] +
  385. (this.useColors ? '%c ' : ' ') +
  386. '+' + module.exports.humanize(this.diff);
  387. if (!this.useColors) {
  388. return;
  389. }
  390. const c = 'color: ' + this.color;
  391. args.splice(1, 0, c, 'color: inherit');
  392. // The final "%c" is somewhat tricky, because there could be other
  393. // arguments passed either before or after the %c, so we need to
  394. // figure out the correct index to insert the CSS into
  395. let index = 0;
  396. let lastC = 0;
  397. args[0].replace(/%[a-zA-Z%]/g, match => {
  398. if (match === '%%') {
  399. return;
  400. }
  401. index++;
  402. if (match === '%c') {
  403. // We only are interested in the *last* %c
  404. // (the user may have provided their own)
  405. lastC = index;
  406. }
  407. });
  408. args.splice(lastC, 0, c);
  409. }
  410. /**
  411. * Invokes `console.debug()` when available.
  412. * No-op when `console.debug` is not a "function".
  413. * If `console.debug` is not available, falls back
  414. * to `console.log`.
  415. *
  416. * @api public
  417. */
  418. exports.log = console.debug || console.log || (() => {});
  419. /**
  420. * Save `namespaces`.
  421. *
  422. * @param {String} namespaces
  423. * @api private
  424. */
  425. function save(namespaces) {
  426. try {
  427. if (namespaces) {
  428. exports.storage.setItem('debug', namespaces);
  429. } else {
  430. exports.storage.removeItem('debug');
  431. }
  432. } catch (error) {
  433. // Swallow
  434. // XXX (@Qix-) should we be logging these?
  435. }
  436. }
  437. /**
  438. * Load `namespaces`.
  439. *
  440. * @return {String} returns the previously persisted debug modes
  441. * @api private
  442. */
  443. function load() {
  444. let r;
  445. try {
  446. r = exports.storage.getItem('debug');
  447. } catch (error) {
  448. // Swallow
  449. // XXX (@Qix-) should we be logging these?
  450. }
  451. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  452. if (!r && typeof process !== 'undefined' && 'env' in process) {
  453. r = process.env.DEBUG;
  454. }
  455. return r;
  456. }
  457. /**
  458. * Localstorage attempts to return the localstorage.
  459. *
  460. * This is necessary because safari throws
  461. * when a user disables cookies/localstorage
  462. * and you attempt to access it.
  463. *
  464. * @return {LocalStorage}
  465. * @api private
  466. */
  467. function localstorage() {
  468. try {
  469. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  470. // The Browser also has localStorage in the global context.
  471. return localStorage;
  472. } catch (error) {
  473. // Swallow
  474. // XXX (@Qix-) should we be logging these?
  475. }
  476. }
  477. module.exports = __webpack_require__(/*! ./common */ "../ot-core/node_modules/debug/src/common.js")(exports);
  478. const {formatters} = module.exports;
  479. /**
  480. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  481. */
  482. formatters.j = function (v) {
  483. try {
  484. return JSON.stringify(v);
  485. } catch (error) {
  486. return '[UnexpectedJSONParseError]: ' + error.message;
  487. }
  488. };
  489. /***/ }),
  490. /***/ "../ot-core/node_modules/debug/src/common.js":
  491. /*!***************************************************!*\
  492. !*** ../ot-core/node_modules/debug/src/common.js ***!
  493. \***************************************************/
  494. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  495. /**
  496. * This is the common logic for both the Node.js and web browser
  497. * implementations of `debug()`.
  498. */
  499. function setup(env) {
  500. createDebug.debug = createDebug;
  501. createDebug.default = createDebug;
  502. createDebug.coerce = coerce;
  503. createDebug.disable = disable;
  504. createDebug.enable = enable;
  505. createDebug.enabled = enabled;
  506. createDebug.humanize = __webpack_require__(/*! ms */ "../ot-core/node_modules/ms/index.js");
  507. createDebug.destroy = destroy;
  508. Object.keys(env).forEach(key => {
  509. createDebug[key] = env[key];
  510. });
  511. /**
  512. * The currently active debug mode names, and names to skip.
  513. */
  514. createDebug.names = [];
  515. createDebug.skips = [];
  516. /**
  517. * Map of special "%n" handling functions, for the debug "format" argument.
  518. *
  519. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  520. */
  521. createDebug.formatters = {};
  522. /**
  523. * Selects a color for a debug namespace
  524. * @param {String} namespace The namespace string for the debug instance to be colored
  525. * @return {Number|String} An ANSI color code for the given namespace
  526. * @api private
  527. */
  528. function selectColor(namespace) {
  529. let hash = 0;
  530. for (let i = 0; i < namespace.length; i++) {
  531. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  532. hash |= 0; // Convert to 32bit integer
  533. }
  534. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  535. }
  536. createDebug.selectColor = selectColor;
  537. /**
  538. * Create a debugger with the given `namespace`.
  539. *
  540. * @param {String} namespace
  541. * @return {Function}
  542. * @api public
  543. */
  544. function createDebug(namespace) {
  545. let prevTime;
  546. let enableOverride = null;
  547. let namespacesCache;
  548. let enabledCache;
  549. function debug(...args) {
  550. // Disabled?
  551. if (!debug.enabled) {
  552. return;
  553. }
  554. const self = debug;
  555. // Set `diff` timestamp
  556. const curr = Number(new Date());
  557. const ms = curr - (prevTime || curr);
  558. self.diff = ms;
  559. self.prev = prevTime;
  560. self.curr = curr;
  561. prevTime = curr;
  562. args[0] = createDebug.coerce(args[0]);
  563. if (typeof args[0] !== 'string') {
  564. // Anything else let's inspect with %O
  565. args.unshift('%O');
  566. }
  567. // Apply any `formatters` transformations
  568. let index = 0;
  569. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
  570. // If we encounter an escaped % then don't increase the array index
  571. if (match === '%%') {
  572. return '%';
  573. }
  574. index++;
  575. const formatter = createDebug.formatters[format];
  576. if (typeof formatter === 'function') {
  577. const val = args[index];
  578. match = formatter.call(self, val);
  579. // Now we need to remove `args[index]` since it's inlined in the `format`
  580. args.splice(index, 1);
  581. index--;
  582. }
  583. return match;
  584. });
  585. // Apply env-specific formatting (colors, etc.)
  586. createDebug.formatArgs.call(self, args);
  587. const logFn = self.log || createDebug.log;
  588. logFn.apply(self, args);
  589. }
  590. debug.namespace = namespace;
  591. debug.useColors = createDebug.useColors();
  592. debug.color = createDebug.selectColor(namespace);
  593. debug.extend = extend;
  594. debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
  595. Object.defineProperty(debug, 'enabled', {
  596. enumerable: true,
  597. configurable: false,
  598. get: () => {
  599. if (enableOverride !== null) {
  600. return enableOverride;
  601. }
  602. if (namespacesCache !== createDebug.namespaces) {
  603. namespacesCache = createDebug.namespaces;
  604. enabledCache = createDebug.enabled(namespace);
  605. }
  606. return enabledCache;
  607. },
  608. set: v => {
  609. enableOverride = v;
  610. }
  611. });
  612. // Env-specific initialization logic for debug instances
  613. if (typeof createDebug.init === 'function') {
  614. createDebug.init(debug);
  615. }
  616. return debug;
  617. }
  618. function extend(namespace, delimiter) {
  619. const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  620. newDebug.log = this.log;
  621. return newDebug;
  622. }
  623. /**
  624. * Enables a debug mode by namespaces. This can include modes
  625. * separated by a colon and wildcards.
  626. *
  627. * @param {String} namespaces
  628. * @api public
  629. */
  630. function enable(namespaces) {
  631. createDebug.save(namespaces);
  632. createDebug.namespaces = namespaces;
  633. createDebug.names = [];
  634. createDebug.skips = [];
  635. let i;
  636. const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  637. const len = split.length;
  638. for (i = 0; i < len; i++) {
  639. if (!split[i]) {
  640. // ignore empty strings
  641. continue;
  642. }
  643. namespaces = split[i].replace(/\*/g, '.*?');
  644. if (namespaces[0] === '-') {
  645. createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  646. } else {
  647. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  648. }
  649. }
  650. }
  651. /**
  652. * Disable debug output.
  653. *
  654. * @return {String} namespaces
  655. * @api public
  656. */
  657. function disable() {
  658. const namespaces = [
  659. ...createDebug.names.map(toNamespace),
  660. ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
  661. ].join(',');
  662. createDebug.enable('');
  663. return namespaces;
  664. }
  665. /**
  666. * Returns true if the given mode name is enabled, false otherwise.
  667. *
  668. * @param {String} name
  669. * @return {Boolean}
  670. * @api public
  671. */
  672. function enabled(name) {
  673. if (name[name.length - 1] === '*') {
  674. return true;
  675. }
  676. let i;
  677. let len;
  678. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  679. if (createDebug.skips[i].test(name)) {
  680. return false;
  681. }
  682. }
  683. for (i = 0, len = createDebug.names.length; i < len; i++) {
  684. if (createDebug.names[i].test(name)) {
  685. return true;
  686. }
  687. }
  688. return false;
  689. }
  690. /**
  691. * Convert regexp to namespace
  692. *
  693. * @param {RegExp} regxep
  694. * @return {String} namespace
  695. * @api private
  696. */
  697. function toNamespace(regexp) {
  698. return regexp.toString()
  699. .substring(2, regexp.toString().length - 2)
  700. .replace(/\.\*\?$/, '*');
  701. }
  702. /**
  703. * Coerce `val`.
  704. *
  705. * @param {Mixed} val
  706. * @return {Mixed}
  707. * @api private
  708. */
  709. function coerce(val) {
  710. if (val instanceof Error) {
  711. return val.stack || val.message;
  712. }
  713. return val;
  714. }
  715. /**
  716. * XXX DO NOT USE. This is a temporary stub function.
  717. * XXX It WILL be removed in the next major release.
  718. */
  719. function destroy() {
  720. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  721. }
  722. createDebug.enable(createDebug.load());
  723. return createDebug;
  724. }
  725. module.exports = setup;
  726. /***/ }),
  727. /***/ "../ot-core/node_modules/debug/src/index.js":
  728. /*!**************************************************!*\
  729. !*** ../ot-core/node_modules/debug/src/index.js ***!
  730. \**************************************************/
  731. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  732. /**
  733. * Detect Electron renderer / nwjs process, which is node, but we should
  734. * treat as a browser.
  735. */
  736. if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
  737. module.exports = __webpack_require__(/*! ./browser.js */ "../ot-core/node_modules/debug/src/browser.js");
  738. } else {
  739. module.exports = __webpack_require__(/*! ./node.js */ "../ot-core/node_modules/debug/src/node.js");
  740. }
  741. /***/ }),
  742. /***/ "../ot-core/node_modules/debug/src/node.js":
  743. /*!*************************************************!*\
  744. !*** ../ot-core/node_modules/debug/src/node.js ***!
  745. \*************************************************/
  746. /***/ ((module, exports, __webpack_require__) => {
  747. /**
  748. * Module dependencies.
  749. */
  750. const tty = __webpack_require__(/*! tty */ "tty");
  751. const util = __webpack_require__(/*! util */ "util");
  752. /**
  753. * This is the Node.js implementation of `debug()`.
  754. */
  755. exports.init = init;
  756. exports.log = log;
  757. exports.formatArgs = formatArgs;
  758. exports.save = save;
  759. exports.load = load;
  760. exports.useColors = useColors;
  761. exports.destroy = util.deprecate(
  762. () => {},
  763. 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
  764. );
  765. /**
  766. * Colors.
  767. */
  768. exports.colors = [6, 2, 3, 4, 5, 1];
  769. try {
  770. // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
  771. // eslint-disable-next-line import/no-extraneous-dependencies
  772. const supportsColor = __webpack_require__(/*! supports-color */ "../ot-core/node_modules/supports-color/index.js");
  773. if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
  774. exports.colors = [
  775. 20,
  776. 21,
  777. 26,
  778. 27,
  779. 32,
  780. 33,
  781. 38,
  782. 39,
  783. 40,
  784. 41,
  785. 42,
  786. 43,
  787. 44,
  788. 45,
  789. 56,
  790. 57,
  791. 62,
  792. 63,
  793. 68,
  794. 69,
  795. 74,
  796. 75,
  797. 76,
  798. 77,
  799. 78,
  800. 79,
  801. 80,
  802. 81,
  803. 92,
  804. 93,
  805. 98,
  806. 99,
  807. 112,
  808. 113,
  809. 128,
  810. 129,
  811. 134,
  812. 135,
  813. 148,
  814. 149,
  815. 160,
  816. 161,
  817. 162,
  818. 163,
  819. 164,
  820. 165,
  821. 166,
  822. 167,
  823. 168,
  824. 169,
  825. 170,
  826. 171,
  827. 172,
  828. 173,
  829. 178,
  830. 179,
  831. 184,
  832. 185,
  833. 196,
  834. 197,
  835. 198,
  836. 199,
  837. 200,
  838. 201,
  839. 202,
  840. 203,
  841. 204,
  842. 205,
  843. 206,
  844. 207,
  845. 208,
  846. 209,
  847. 214,
  848. 215,
  849. 220,
  850. 221
  851. ];
  852. }
  853. } catch (error) {
  854. // Swallow - we only care if `supports-color` is available; it doesn't have to be.
  855. }
  856. /**
  857. * Build up the default `inspectOpts` object from the environment variables.
  858. *
  859. * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
  860. */
  861. exports.inspectOpts = Object.keys(process.env).filter(key => {
  862. return /^debug_/i.test(key);
  863. }).reduce((obj, key) => {
  864. // Camel-case
  865. const prop = key
  866. .substring(6)
  867. .toLowerCase()
  868. .replace(/_([a-z])/g, (_, k) => {
  869. return k.toUpperCase();
  870. });
  871. // Coerce string value into JS value
  872. let val = process.env[key];
  873. if (/^(yes|on|true|enabled)$/i.test(val)) {
  874. val = true;
  875. } else if (/^(no|off|false|disabled)$/i.test(val)) {
  876. val = false;
  877. } else if (val === 'null') {
  878. val = null;
  879. } else {
  880. val = Number(val);
  881. }
  882. obj[prop] = val;
  883. return obj;
  884. }, {});
  885. /**
  886. * Is stdout a TTY? Colored output is enabled when `true`.
  887. */
  888. function useColors() {
  889. return 'colors' in exports.inspectOpts ?
  890. Boolean(exports.inspectOpts.colors) :
  891. tty.isatty(process.stderr.fd);
  892. }
  893. /**
  894. * Adds ANSI color escape codes if enabled.
  895. *
  896. * @api public
  897. */
  898. function formatArgs(args) {
  899. const {namespace: name, useColors} = this;
  900. if (useColors) {
  901. const c = this.color;
  902. const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
  903. const prefix = ` ${colorCode};1m${name} \u001B[0m`;
  904. args[0] = prefix + args[0].split('\n').join('\n' + prefix);
  905. args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
  906. } else {
  907. args[0] = getDate() + name + ' ' + args[0];
  908. }
  909. }
  910. function getDate() {
  911. if (exports.inspectOpts.hideDate) {
  912. return '';
  913. }
  914. return new Date().toISOString() + ' ';
  915. }
  916. /**
  917. * Invokes `util.format()` with the specified arguments and writes to stderr.
  918. */
  919. function log(...args) {
  920. return process.stderr.write(util.format(...args) + '\n');
  921. }
  922. /**
  923. * Save `namespaces`.
  924. *
  925. * @param {String} namespaces
  926. * @api private
  927. */
  928. function save(namespaces) {
  929. if (namespaces) {
  930. process.env.DEBUG = namespaces;
  931. } else {
  932. // If you set a process.env field to null or undefined, it gets cast to the
  933. // string 'null' or 'undefined'. Just delete instead.
  934. delete process.env.DEBUG;
  935. }
  936. }
  937. /**
  938. * Load `namespaces`.
  939. *
  940. * @return {String} returns the previously persisted debug modes
  941. * @api private
  942. */
  943. function load() {
  944. return process.env.DEBUG;
  945. }
  946. /**
  947. * Init logic for `debug` instances.
  948. *
  949. * Create a new `inspectOpts` object in case `useColors` is set
  950. * differently for a particular `debug` instance.
  951. */
  952. function init(debug) {
  953. debug.inspectOpts = {};
  954. const keys = Object.keys(exports.inspectOpts);
  955. for (let i = 0; i < keys.length; i++) {
  956. debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
  957. }
  958. }
  959. module.exports = __webpack_require__(/*! ./common */ "../ot-core/node_modules/debug/src/common.js")(exports);
  960. const {formatters} = module.exports;
  961. /**
  962. * Map %o to `util.inspect()`, all on a single line.
  963. */
  964. formatters.o = function (v) {
  965. this.inspectOpts.colors = this.useColors;
  966. return util.inspect(v, this.inspectOpts)
  967. .split('\n')
  968. .map(str => str.trim())
  969. .join(' ');
  970. };
  971. /**
  972. * Map %O to `util.inspect()`, allowing multiple lines if needed.
  973. */
  974. formatters.O = function (v) {
  975. this.inspectOpts.colors = this.useColors;
  976. return util.inspect(v, this.inspectOpts);
  977. };
  978. /***/ }),
  979. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/index.js":
  980. /*!*************************************************************************!*\
  981. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/index.js ***!
  982. \*************************************************************************/
  983. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  984. "use strict";
  985. const WebSocket = __webpack_require__(/*! ./lib/websocket */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js");
  986. WebSocket.createWebSocketStream = __webpack_require__(/*! ./lib/stream */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/stream.js");
  987. WebSocket.Server = __webpack_require__(/*! ./lib/websocket-server */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js");
  988. WebSocket.Receiver = __webpack_require__(/*! ./lib/receiver */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js");
  989. WebSocket.Sender = __webpack_require__(/*! ./lib/sender */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js");
  990. WebSocket.WebSocket = WebSocket;
  991. WebSocket.WebSocketServer = WebSocket.Server;
  992. module.exports = WebSocket;
  993. /***/ }),
  994. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js":
  995. /*!***********************************************************************************!*\
  996. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js ***!
  997. \***********************************************************************************/
  998. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  999. "use strict";
  1000. const { EMPTY_BUFFER } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
  1001. /**
  1002. * Merges an array of buffers into a new buffer.
  1003. *
  1004. * @param {Buffer[]} list The array of buffers to concat
  1005. * @param {Number} totalLength The total length of buffers in the list
  1006. * @return {Buffer} The resulting buffer
  1007. * @public
  1008. */
  1009. function concat(list, totalLength) {
  1010. if (list.length === 0) return EMPTY_BUFFER;
  1011. if (list.length === 1) return list[0];
  1012. const target = Buffer.allocUnsafe(totalLength);
  1013. let offset = 0;
  1014. for (let i = 0; i < list.length; i++) {
  1015. const buf = list[i];
  1016. target.set(buf, offset);
  1017. offset += buf.length;
  1018. }
  1019. if (offset < totalLength) return target.slice(0, offset);
  1020. return target;
  1021. }
  1022. /**
  1023. * Masks a buffer using the given mask.
  1024. *
  1025. * @param {Buffer} source The buffer to mask
  1026. * @param {Buffer} mask The mask to use
  1027. * @param {Buffer} output The buffer where to store the result
  1028. * @param {Number} offset The offset at which to start writing
  1029. * @param {Number} length The number of bytes to mask.
  1030. * @public
  1031. */
  1032. function _mask(source, mask, output, offset, length) {
  1033. for (let i = 0; i < length; i++) {
  1034. output[offset + i] = source[i] ^ mask[i & 3];
  1035. }
  1036. }
  1037. /**
  1038. * Unmasks a buffer using the given mask.
  1039. *
  1040. * @param {Buffer} buffer The buffer to unmask
  1041. * @param {Buffer} mask The mask to use
  1042. * @public
  1043. */
  1044. function _unmask(buffer, mask) {
  1045. for (let i = 0; i < buffer.length; i++) {
  1046. buffer[i] ^= mask[i & 3];
  1047. }
  1048. }
  1049. /**
  1050. * Converts a buffer to an `ArrayBuffer`.
  1051. *
  1052. * @param {Buffer} buf The buffer to convert
  1053. * @return {ArrayBuffer} Converted buffer
  1054. * @public
  1055. */
  1056. function toArrayBuffer(buf) {
  1057. if (buf.byteLength === buf.buffer.byteLength) {
  1058. return buf.buffer;
  1059. }
  1060. return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
  1061. }
  1062. /**
  1063. * Converts `data` to a `Buffer`.
  1064. *
  1065. * @param {*} data The data to convert
  1066. * @return {Buffer} The buffer
  1067. * @throws {TypeError}
  1068. * @public
  1069. */
  1070. function toBuffer(data) {
  1071. toBuffer.readOnly = true;
  1072. if (Buffer.isBuffer(data)) return data;
  1073. let buf;
  1074. if (data instanceof ArrayBuffer) {
  1075. buf = Buffer.from(data);
  1076. } else if (ArrayBuffer.isView(data)) {
  1077. buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
  1078. } else {
  1079. buf = Buffer.from(data);
  1080. toBuffer.readOnly = false;
  1081. }
  1082. return buf;
  1083. }
  1084. try {
  1085. const bufferUtil = __webpack_require__(/*! bufferutil */ "bufferutil");
  1086. module.exports = {
  1087. concat,
  1088. mask(source, mask, output, offset, length) {
  1089. if (length < 48) _mask(source, mask, output, offset, length);
  1090. else bufferUtil.mask(source, mask, output, offset, length);
  1091. },
  1092. toArrayBuffer,
  1093. toBuffer,
  1094. unmask(buffer, mask) {
  1095. if (buffer.length < 32) _unmask(buffer, mask);
  1096. else bufferUtil.unmask(buffer, mask);
  1097. }
  1098. };
  1099. } catch (e) /* istanbul ignore next */ {
  1100. module.exports = {
  1101. concat,
  1102. mask: _mask,
  1103. toArrayBuffer,
  1104. toBuffer,
  1105. unmask: _unmask
  1106. };
  1107. }
  1108. /***/ }),
  1109. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js":
  1110. /*!*********************************************************************************!*\
  1111. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js ***!
  1112. \*********************************************************************************/
  1113. /***/ ((module) => {
  1114. "use strict";
  1115. module.exports = {
  1116. BINARY_TYPES: ['nodebuffer', 'arraybuffer', 'fragments'],
  1117. EMPTY_BUFFER: Buffer.alloc(0),
  1118. GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
  1119. kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
  1120. kListener: Symbol('kListener'),
  1121. kStatusCode: Symbol('status-code'),
  1122. kWebSocket: Symbol('websocket'),
  1123. NOOP: () => {}
  1124. };
  1125. /***/ }),
  1126. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/event-target.js":
  1127. /*!************************************************************************************!*\
  1128. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/event-target.js ***!
  1129. \************************************************************************************/
  1130. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1131. "use strict";
  1132. const { kForOnEventAttribute, kListener } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
  1133. const kCode = Symbol('kCode');
  1134. const kData = Symbol('kData');
  1135. const kError = Symbol('kError');
  1136. const kMessage = Symbol('kMessage');
  1137. const kReason = Symbol('kReason');
  1138. const kTarget = Symbol('kTarget');
  1139. const kType = Symbol('kType');
  1140. const kWasClean = Symbol('kWasClean');
  1141. /**
  1142. * Class representing an event.
  1143. */
  1144. class Event {
  1145. /**
  1146. * Create a new `Event`.
  1147. *
  1148. * @param {String} type The name of the event
  1149. * @throws {TypeError} If the `type` argument is not specified
  1150. */
  1151. constructor(type) {
  1152. this[kTarget] = null;
  1153. this[kType] = type;
  1154. }
  1155. /**
  1156. * @type {*}
  1157. */
  1158. get target() {
  1159. return this[kTarget];
  1160. }
  1161. /**
  1162. * @type {String}
  1163. */
  1164. get type() {
  1165. return this[kType];
  1166. }
  1167. }
  1168. Object.defineProperty(Event.prototype, 'target', { enumerable: true });
  1169. Object.defineProperty(Event.prototype, 'type', { enumerable: true });
  1170. /**
  1171. * Class representing a close event.
  1172. *
  1173. * @extends Event
  1174. */
  1175. class CloseEvent extends Event {
  1176. /**
  1177. * Create a new `CloseEvent`.
  1178. *
  1179. * @param {String} type The name of the event
  1180. * @param {Object} [options] A dictionary object that allows for setting
  1181. * attributes via object members of the same name
  1182. * @param {Number} [options.code=0] The status code explaining why the
  1183. * connection was closed
  1184. * @param {String} [options.reason=''] A human-readable string explaining why
  1185. * the connection was closed
  1186. * @param {Boolean} [options.wasClean=false] Indicates whether or not the
  1187. * connection was cleanly closed
  1188. */
  1189. constructor(type, options = {}) {
  1190. super(type);
  1191. this[kCode] = options.code === undefined ? 0 : options.code;
  1192. this[kReason] = options.reason === undefined ? '' : options.reason;
  1193. this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
  1194. }
  1195. /**
  1196. * @type {Number}
  1197. */
  1198. get code() {
  1199. return this[kCode];
  1200. }
  1201. /**
  1202. * @type {String}
  1203. */
  1204. get reason() {
  1205. return this[kReason];
  1206. }
  1207. /**
  1208. * @type {Boolean}
  1209. */
  1210. get wasClean() {
  1211. return this[kWasClean];
  1212. }
  1213. }
  1214. Object.defineProperty(CloseEvent.prototype, 'code', { enumerable: true });
  1215. Object.defineProperty(CloseEvent.prototype, 'reason', { enumerable: true });
  1216. Object.defineProperty(CloseEvent.prototype, 'wasClean', { enumerable: true });
  1217. /**
  1218. * Class representing an error event.
  1219. *
  1220. * @extends Event
  1221. */
  1222. class ErrorEvent extends Event {
  1223. /**
  1224. * Create a new `ErrorEvent`.
  1225. *
  1226. * @param {String} type The name of the event
  1227. * @param {Object} [options] A dictionary object that allows for setting
  1228. * attributes via object members of the same name
  1229. * @param {*} [options.error=null] The error that generated this event
  1230. * @param {String} [options.message=''] The error message
  1231. */
  1232. constructor(type, options = {}) {
  1233. super(type);
  1234. this[kError] = options.error === undefined ? null : options.error;
  1235. this[kMessage] = options.message === undefined ? '' : options.message;
  1236. }
  1237. /**
  1238. * @type {*}
  1239. */
  1240. get error() {
  1241. return this[kError];
  1242. }
  1243. /**
  1244. * @type {String}
  1245. */
  1246. get message() {
  1247. return this[kMessage];
  1248. }
  1249. }
  1250. Object.defineProperty(ErrorEvent.prototype, 'error', { enumerable: true });
  1251. Object.defineProperty(ErrorEvent.prototype, 'message', { enumerable: true });
  1252. /**
  1253. * Class representing a message event.
  1254. *
  1255. * @extends Event
  1256. */
  1257. class MessageEvent extends Event {
  1258. /**
  1259. * Create a new `MessageEvent`.
  1260. *
  1261. * @param {String} type The name of the event
  1262. * @param {Object} [options] A dictionary object that allows for setting
  1263. * attributes via object members of the same name
  1264. * @param {*} [options.data=null] The message content
  1265. */
  1266. constructor(type, options = {}) {
  1267. super(type);
  1268. this[kData] = options.data === undefined ? null : options.data;
  1269. }
  1270. /**
  1271. * @type {*}
  1272. */
  1273. get data() {
  1274. return this[kData];
  1275. }
  1276. }
  1277. Object.defineProperty(MessageEvent.prototype, 'data', { enumerable: true });
  1278. /**
  1279. * This provides methods for emulating the `EventTarget` interface. It's not
  1280. * meant to be used directly.
  1281. *
  1282. * @mixin
  1283. */
  1284. const EventTarget = {
  1285. /**
  1286. * Register an event listener.
  1287. *
  1288. * @param {String} type A string representing the event type to listen for
  1289. * @param {Function} listener The listener to add
  1290. * @param {Object} [options] An options object specifies characteristics about
  1291. * the event listener
  1292. * @param {Boolean} [options.once=false] A `Boolean` indicating that the
  1293. * listener should be invoked at most once after being added. If `true`,
  1294. * the listener would be automatically removed when invoked.
  1295. * @public
  1296. */
  1297. addEventListener(type, listener, options = {}) {
  1298. let wrapper;
  1299. if (type === 'message') {
  1300. wrapper = function onMessage(data, isBinary) {
  1301. const event = new MessageEvent('message', {
  1302. data: isBinary ? data : data.toString()
  1303. });
  1304. event[kTarget] = this;
  1305. listener.call(this, event);
  1306. };
  1307. } else if (type === 'close') {
  1308. wrapper = function onClose(code, message) {
  1309. const event = new CloseEvent('close', {
  1310. code,
  1311. reason: message.toString(),
  1312. wasClean: this._closeFrameReceived && this._closeFrameSent
  1313. });
  1314. event[kTarget] = this;
  1315. listener.call(this, event);
  1316. };
  1317. } else if (type === 'error') {
  1318. wrapper = function onError(error) {
  1319. const event = new ErrorEvent('error', {
  1320. error,
  1321. message: error.message
  1322. });
  1323. event[kTarget] = this;
  1324. listener.call(this, event);
  1325. };
  1326. } else if (type === 'open') {
  1327. wrapper = function onOpen() {
  1328. const event = new Event('open');
  1329. event[kTarget] = this;
  1330. listener.call(this, event);
  1331. };
  1332. } else {
  1333. return;
  1334. }
  1335. wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
  1336. wrapper[kListener] = listener;
  1337. if (options.once) {
  1338. this.once(type, wrapper);
  1339. } else {
  1340. this.on(type, wrapper);
  1341. }
  1342. },
  1343. /**
  1344. * Remove an event listener.
  1345. *
  1346. * @param {String} type A string representing the event type to remove
  1347. * @param {Function} handler The listener to remove
  1348. * @public
  1349. */
  1350. removeEventListener(type, handler) {
  1351. for (const listener of this.listeners(type)) {
  1352. if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
  1353. this.removeListener(type, listener);
  1354. break;
  1355. }
  1356. }
  1357. }
  1358. };
  1359. module.exports = {
  1360. CloseEvent,
  1361. ErrorEvent,
  1362. Event,
  1363. EventTarget,
  1364. MessageEvent
  1365. };
  1366. /***/ }),
  1367. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js":
  1368. /*!*********************************************************************************!*\
  1369. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js ***!
  1370. \*********************************************************************************/
  1371. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1372. "use strict";
  1373. const { tokenChars } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
  1374. /**
  1375. * Adds an offer to the map of extension offers or a parameter to the map of
  1376. * parameters.
  1377. *
  1378. * @param {Object} dest The map of extension offers or parameters
  1379. * @param {String} name The extension or parameter name
  1380. * @param {(Object|Boolean|String)} elem The extension parameters or the
  1381. * parameter value
  1382. * @private
  1383. */
  1384. function push(dest, name, elem) {
  1385. if (dest[name] === undefined) dest[name] = [elem];
  1386. else dest[name].push(elem);
  1387. }
  1388. /**
  1389. * Parses the `Sec-WebSocket-Extensions` header into an object.
  1390. *
  1391. * @param {String} header The field value of the header
  1392. * @return {Object} The parsed object
  1393. * @public
  1394. */
  1395. function parse(header) {
  1396. const offers = Object.create(null);
  1397. let params = Object.create(null);
  1398. let mustUnescape = false;
  1399. let isEscaping = false;
  1400. let inQuotes = false;
  1401. let extensionName;
  1402. let paramName;
  1403. let start = -1;
  1404. let code = -1;
  1405. let end = -1;
  1406. let i = 0;
  1407. for (; i < header.length; i++) {
  1408. code = header.charCodeAt(i);
  1409. if (extensionName === undefined) {
  1410. if (end === -1 && tokenChars[code] === 1) {
  1411. if (start === -1) start = i;
  1412. } else if (
  1413. i !== 0 &&
  1414. (code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
  1415. ) {
  1416. if (end === -1 && start !== -1) end = i;
  1417. } else if (code === 0x3b /* ';' */ || code === 0x2c /* ',' */) {
  1418. if (start === -1) {
  1419. throw new SyntaxError(`Unexpected character at index ${i}`);
  1420. }
  1421. if (end === -1) end = i;
  1422. const name = header.slice(start, end);
  1423. if (code === 0x2c) {
  1424. push(offers, name, params);
  1425. params = Object.create(null);
  1426. } else {
  1427. extensionName = name;
  1428. }
  1429. start = end = -1;
  1430. } else {
  1431. throw new SyntaxError(`Unexpected character at index ${i}`);
  1432. }
  1433. } else if (paramName === undefined) {
  1434. if (end === -1 && tokenChars[code] === 1) {
  1435. if (start === -1) start = i;
  1436. } else if (code === 0x20 || code === 0x09) {
  1437. if (end === -1 && start !== -1) end = i;
  1438. } else if (code === 0x3b || code === 0x2c) {
  1439. if (start === -1) {
  1440. throw new SyntaxError(`Unexpected character at index ${i}`);
  1441. }
  1442. if (end === -1) end = i;
  1443. push(params, header.slice(start, end), true);
  1444. if (code === 0x2c) {
  1445. push(offers, extensionName, params);
  1446. params = Object.create(null);
  1447. extensionName = undefined;
  1448. }
  1449. start = end = -1;
  1450. } else if (code === 0x3d /* '=' */ && start !== -1 && end === -1) {
  1451. paramName = header.slice(start, i);
  1452. start = end = -1;
  1453. } else {
  1454. throw new SyntaxError(`Unexpected character at index ${i}`);
  1455. }
  1456. } else {
  1457. //
  1458. // The value of a quoted-string after unescaping must conform to the
  1459. // token ABNF, so only token characters are valid.
  1460. // Ref: https://tools.ietf.org/html/rfc6455#section-9.1
  1461. //
  1462. if (isEscaping) {
  1463. if (tokenChars[code] !== 1) {
  1464. throw new SyntaxError(`Unexpected character at index ${i}`);
  1465. }
  1466. if (start === -1) start = i;
  1467. else if (!mustUnescape) mustUnescape = true;
  1468. isEscaping = false;
  1469. } else if (inQuotes) {
  1470. if (tokenChars[code] === 1) {
  1471. if (start === -1) start = i;
  1472. } else if (code === 0x22 /* '"' */ && start !== -1) {
  1473. inQuotes = false;
  1474. end = i;
  1475. } else if (code === 0x5c /* '\' */) {
  1476. isEscaping = true;
  1477. } else {
  1478. throw new SyntaxError(`Unexpected character at index ${i}`);
  1479. }
  1480. } else if (code === 0x22 && header.charCodeAt(i - 1) === 0x3d) {
  1481. inQuotes = true;
  1482. } else if (end === -1 && tokenChars[code] === 1) {
  1483. if (start === -1) start = i;
  1484. } else if (start !== -1 && (code === 0x20 || code === 0x09)) {
  1485. if (end === -1) end = i;
  1486. } else if (code === 0x3b || code === 0x2c) {
  1487. if (start === -1) {
  1488. throw new SyntaxError(`Unexpected character at index ${i}`);
  1489. }
  1490. if (end === -1) end = i;
  1491. let value = header.slice(start, end);
  1492. if (mustUnescape) {
  1493. value = value.replace(/\\/g, '');
  1494. mustUnescape = false;
  1495. }
  1496. push(params, paramName, value);
  1497. if (code === 0x2c) {
  1498. push(offers, extensionName, params);
  1499. params = Object.create(null);
  1500. extensionName = undefined;
  1501. }
  1502. paramName = undefined;
  1503. start = end = -1;
  1504. } else {
  1505. throw new SyntaxError(`Unexpected character at index ${i}`);
  1506. }
  1507. }
  1508. }
  1509. if (start === -1 || inQuotes || code === 0x20 || code === 0x09) {
  1510. throw new SyntaxError('Unexpected end of input');
  1511. }
  1512. if (end === -1) end = i;
  1513. const token = header.slice(start, end);
  1514. if (extensionName === undefined) {
  1515. push(offers, token, params);
  1516. } else {
  1517. if (paramName === undefined) {
  1518. push(params, token, true);
  1519. } else if (mustUnescape) {
  1520. push(params, paramName, token.replace(/\\/g, ''));
  1521. } else {
  1522. push(params, paramName, token);
  1523. }
  1524. push(offers, extensionName, params);
  1525. }
  1526. return offers;
  1527. }
  1528. /**
  1529. * Builds the `Sec-WebSocket-Extensions` header field value.
  1530. *
  1531. * @param {Object} extensions The map of extensions and parameters to format
  1532. * @return {String} A string representing the given object
  1533. * @public
  1534. */
  1535. function format(extensions) {
  1536. return Object.keys(extensions)
  1537. .map((extension) => {
  1538. let configurations = extensions[extension];
  1539. if (!Array.isArray(configurations)) configurations = [configurations];
  1540. return configurations
  1541. .map((params) => {
  1542. return [extension]
  1543. .concat(
  1544. Object.keys(params).map((k) => {
  1545. let values = params[k];
  1546. if (!Array.isArray(values)) values = [values];
  1547. return values
  1548. .map((v) => (v === true ? k : `${k}=${v}`))
  1549. .join('; ');
  1550. })
  1551. )
  1552. .join('; ');
  1553. })
  1554. .join(', ');
  1555. })
  1556. .join(', ');
  1557. }
  1558. module.exports = { format, parse };
  1559. /***/ }),
  1560. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/limiter.js":
  1561. /*!*******************************************************************************!*\
  1562. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/limiter.js ***!
  1563. \*******************************************************************************/
  1564. /***/ ((module) => {
  1565. "use strict";
  1566. const kDone = Symbol('kDone');
  1567. const kRun = Symbol('kRun');
  1568. /**
  1569. * A very simple job queue with adjustable concurrency. Adapted from
  1570. * https://github.com/STRML/async-limiter
  1571. */
  1572. class Limiter {
  1573. /**
  1574. * Creates a new `Limiter`.
  1575. *
  1576. * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
  1577. * to run concurrently
  1578. */
  1579. constructor(concurrency) {
  1580. this[kDone] = () => {
  1581. this.pending--;
  1582. this[kRun]();
  1583. };
  1584. this.concurrency = concurrency || Infinity;
  1585. this.jobs = [];
  1586. this.pending = 0;
  1587. }
  1588. /**
  1589. * Adds a job to the queue.
  1590. *
  1591. * @param {Function} job The job to run
  1592. * @public
  1593. */
  1594. add(job) {
  1595. this.jobs.push(job);
  1596. this[kRun]();
  1597. }
  1598. /**
  1599. * Removes a job from the queue and runs it if possible.
  1600. *
  1601. * @private
  1602. */
  1603. [kRun]() {
  1604. if (this.pending === this.concurrency) return;
  1605. if (this.jobs.length) {
  1606. const job = this.jobs.shift();
  1607. this.pending++;
  1608. job(this[kDone]);
  1609. }
  1610. }
  1611. }
  1612. module.exports = Limiter;
  1613. /***/ }),
  1614. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js":
  1615. /*!******************************************************************************************!*\
  1616. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js ***!
  1617. \******************************************************************************************/
  1618. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1619. "use strict";
  1620. const zlib = __webpack_require__(/*! zlib */ "zlib");
  1621. const bufferUtil = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
  1622. const Limiter = __webpack_require__(/*! ./limiter */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/limiter.js");
  1623. const { kStatusCode } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
  1624. const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
  1625. const kPerMessageDeflate = Symbol('permessage-deflate');
  1626. const kTotalLength = Symbol('total-length');
  1627. const kCallback = Symbol('callback');
  1628. const kBuffers = Symbol('buffers');
  1629. const kError = Symbol('error');
  1630. //
  1631. // We limit zlib concurrency, which prevents severe memory fragmentation
  1632. // as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
  1633. // and https://github.com/websockets/ws/issues/1202
  1634. //
  1635. // Intentionally global; it's the global thread pool that's an issue.
  1636. //
  1637. let zlibLimiter;
  1638. /**
  1639. * permessage-deflate implementation.
  1640. */
  1641. class PerMessageDeflate {
  1642. /**
  1643. * Creates a PerMessageDeflate instance.
  1644. *
  1645. * @param {Object} [options] Configuration options
  1646. * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
  1647. * for, or request, a custom client window size
  1648. * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
  1649. * acknowledge disabling of client context takeover
  1650. * @param {Number} [options.concurrencyLimit=10] The number of concurrent
  1651. * calls to zlib
  1652. * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
  1653. * use of a custom server window size
  1654. * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
  1655. * disabling of server context takeover
  1656. * @param {Number} [options.threshold=1024] Size (in bytes) below which
  1657. * messages should not be compressed if context takeover is disabled
  1658. * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
  1659. * deflate
  1660. * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
  1661. * inflate
  1662. * @param {Boolean} [isServer=false] Create the instance in either server or
  1663. * client mode
  1664. * @param {Number} [maxPayload=0] The maximum allowed message length
  1665. */
  1666. constructor(options, isServer, maxPayload) {
  1667. this._maxPayload = maxPayload | 0;
  1668. this._options = options || {};
  1669. this._threshold =
  1670. this._options.threshold !== undefined ? this._options.threshold : 1024;
  1671. this._isServer = !!isServer;
  1672. this._deflate = null;
  1673. this._inflate = null;
  1674. this.params = null;
  1675. if (!zlibLimiter) {
  1676. const concurrency =
  1677. this._options.concurrencyLimit !== undefined
  1678. ? this._options.concurrencyLimit
  1679. : 10;
  1680. zlibLimiter = new Limiter(concurrency);
  1681. }
  1682. }
  1683. /**
  1684. * @type {String}
  1685. */
  1686. static get extensionName() {
  1687. return 'permessage-deflate';
  1688. }
  1689. /**
  1690. * Create an extension negotiation offer.
  1691. *
  1692. * @return {Object} Extension parameters
  1693. * @public
  1694. */
  1695. offer() {
  1696. const params = {};
  1697. if (this._options.serverNoContextTakeover) {
  1698. params.server_no_context_takeover = true;
  1699. }
  1700. if (this._options.clientNoContextTakeover) {
  1701. params.client_no_context_takeover = true;
  1702. }
  1703. if (this._options.serverMaxWindowBits) {
  1704. params.server_max_window_bits = this._options.serverMaxWindowBits;
  1705. }
  1706. if (this._options.clientMaxWindowBits) {
  1707. params.client_max_window_bits = this._options.clientMaxWindowBits;
  1708. } else if (this._options.clientMaxWindowBits == null) {
  1709. params.client_max_window_bits = true;
  1710. }
  1711. return params;
  1712. }
  1713. /**
  1714. * Accept an extension negotiation offer/response.
  1715. *
  1716. * @param {Array} configurations The extension negotiation offers/reponse
  1717. * @return {Object} Accepted configuration
  1718. * @public
  1719. */
  1720. accept(configurations) {
  1721. configurations = this.normalizeParams(configurations);
  1722. this.params = this._isServer
  1723. ? this.acceptAsServer(configurations)
  1724. : this.acceptAsClient(configurations);
  1725. return this.params;
  1726. }
  1727. /**
  1728. * Releases all resources used by the extension.
  1729. *
  1730. * @public
  1731. */
  1732. cleanup() {
  1733. if (this._inflate) {
  1734. this._inflate.close();
  1735. this._inflate = null;
  1736. }
  1737. if (this._deflate) {
  1738. const callback = this._deflate[kCallback];
  1739. this._deflate.close();
  1740. this._deflate = null;
  1741. if (callback) {
  1742. callback(
  1743. new Error(
  1744. 'The deflate stream was closed while data was being processed'
  1745. )
  1746. );
  1747. }
  1748. }
  1749. }
  1750. /**
  1751. * Accept an extension negotiation offer.
  1752. *
  1753. * @param {Array} offers The extension negotiation offers
  1754. * @return {Object} Accepted configuration
  1755. * @private
  1756. */
  1757. acceptAsServer(offers) {
  1758. const opts = this._options;
  1759. const accepted = offers.find((params) => {
  1760. if (
  1761. (opts.serverNoContextTakeover === false &&
  1762. params.server_no_context_takeover) ||
  1763. (params.server_max_window_bits &&
  1764. (opts.serverMaxWindowBits === false ||
  1765. (typeof opts.serverMaxWindowBits === 'number' &&
  1766. opts.serverMaxWindowBits > params.server_max_window_bits))) ||
  1767. (typeof opts.clientMaxWindowBits === 'number' &&
  1768. !params.client_max_window_bits)
  1769. ) {
  1770. return false;
  1771. }
  1772. return true;
  1773. });
  1774. if (!accepted) {
  1775. throw new Error('None of the extension offers can be accepted');
  1776. }
  1777. if (opts.serverNoContextTakeover) {
  1778. accepted.server_no_context_takeover = true;
  1779. }
  1780. if (opts.clientNoContextTakeover) {
  1781. accepted.client_no_context_takeover = true;
  1782. }
  1783. if (typeof opts.serverMaxWindowBits === 'number') {
  1784. accepted.server_max_window_bits = opts.serverMaxWindowBits;
  1785. }
  1786. if (typeof opts.clientMaxWindowBits === 'number') {
  1787. accepted.client_max_window_bits = opts.clientMaxWindowBits;
  1788. } else if (
  1789. accepted.client_max_window_bits === true ||
  1790. opts.clientMaxWindowBits === false
  1791. ) {
  1792. delete accepted.client_max_window_bits;
  1793. }
  1794. return accepted;
  1795. }
  1796. /**
  1797. * Accept the extension negotiation response.
  1798. *
  1799. * @param {Array} response The extension negotiation response
  1800. * @return {Object} Accepted configuration
  1801. * @private
  1802. */
  1803. acceptAsClient(response) {
  1804. const params = response[0];
  1805. if (
  1806. this._options.clientNoContextTakeover === false &&
  1807. params.client_no_context_takeover
  1808. ) {
  1809. throw new Error('Unexpected parameter "client_no_context_takeover"');
  1810. }
  1811. if (!params.client_max_window_bits) {
  1812. if (typeof this._options.clientMaxWindowBits === 'number') {
  1813. params.client_max_window_bits = this._options.clientMaxWindowBits;
  1814. }
  1815. } else if (
  1816. this._options.clientMaxWindowBits === false ||
  1817. (typeof this._options.clientMaxWindowBits === 'number' &&
  1818. params.client_max_window_bits > this._options.clientMaxWindowBits)
  1819. ) {
  1820. throw new Error(
  1821. 'Unexpected or invalid parameter "client_max_window_bits"'
  1822. );
  1823. }
  1824. return params;
  1825. }
  1826. /**
  1827. * Normalize parameters.
  1828. *
  1829. * @param {Array} configurations The extension negotiation offers/reponse
  1830. * @return {Array} The offers/response with normalized parameters
  1831. * @private
  1832. */
  1833. normalizeParams(configurations) {
  1834. configurations.forEach((params) => {
  1835. Object.keys(params).forEach((key) => {
  1836. let value = params[key];
  1837. if (value.length > 1) {
  1838. throw new Error(`Parameter "${key}" must have only a single value`);
  1839. }
  1840. value = value[0];
  1841. if (key === 'client_max_window_bits') {
  1842. if (value !== true) {
  1843. const num = +value;
  1844. if (!Number.isInteger(num) || num < 8 || num > 15) {
  1845. throw new TypeError(
  1846. `Invalid value for parameter "${key}": ${value}`
  1847. );
  1848. }
  1849. value = num;
  1850. } else if (!this._isServer) {
  1851. throw new TypeError(
  1852. `Invalid value for parameter "${key}": ${value}`
  1853. );
  1854. }
  1855. } else if (key === 'server_max_window_bits') {
  1856. const num = +value;
  1857. if (!Number.isInteger(num) || num < 8 || num > 15) {
  1858. throw new TypeError(
  1859. `Invalid value for parameter "${key}": ${value}`
  1860. );
  1861. }
  1862. value = num;
  1863. } else if (
  1864. key === 'client_no_context_takeover' ||
  1865. key === 'server_no_context_takeover'
  1866. ) {
  1867. if (value !== true) {
  1868. throw new TypeError(
  1869. `Invalid value for parameter "${key}": ${value}`
  1870. );
  1871. }
  1872. } else {
  1873. throw new Error(`Unknown parameter "${key}"`);
  1874. }
  1875. params[key] = value;
  1876. });
  1877. });
  1878. return configurations;
  1879. }
  1880. /**
  1881. * Decompress data. Concurrency limited.
  1882. *
  1883. * @param {Buffer} data Compressed data
  1884. * @param {Boolean} fin Specifies whether or not this is the last fragment
  1885. * @param {Function} callback Callback
  1886. * @public
  1887. */
  1888. decompress(data, fin, callback) {
  1889. zlibLimiter.add((done) => {
  1890. this._decompress(data, fin, (err, result) => {
  1891. done();
  1892. callback(err, result);
  1893. });
  1894. });
  1895. }
  1896. /**
  1897. * Compress data. Concurrency limited.
  1898. *
  1899. * @param {Buffer} data Data to compress
  1900. * @param {Boolean} fin Specifies whether or not this is the last fragment
  1901. * @param {Function} callback Callback
  1902. * @public
  1903. */
  1904. compress(data, fin, callback) {
  1905. zlibLimiter.add((done) => {
  1906. this._compress(data, fin, (err, result) => {
  1907. done();
  1908. callback(err, result);
  1909. });
  1910. });
  1911. }
  1912. /**
  1913. * Decompress data.
  1914. *
  1915. * @param {Buffer} data Compressed data
  1916. * @param {Boolean} fin Specifies whether or not this is the last fragment
  1917. * @param {Function} callback Callback
  1918. * @private
  1919. */
  1920. _decompress(data, fin, callback) {
  1921. const endpoint = this._isServer ? 'client' : 'server';
  1922. if (!this._inflate) {
  1923. const key = `${endpoint}_max_window_bits`;
  1924. const windowBits =
  1925. typeof this.params[key] !== 'number'
  1926. ? zlib.Z_DEFAULT_WINDOWBITS
  1927. : this.params[key];
  1928. this._inflate = zlib.createInflateRaw({
  1929. ...this._options.zlibInflateOptions,
  1930. windowBits
  1931. });
  1932. this._inflate[kPerMessageDeflate] = this;
  1933. this._inflate[kTotalLength] = 0;
  1934. this._inflate[kBuffers] = [];
  1935. this._inflate.on('error', inflateOnError);
  1936. this._inflate.on('data', inflateOnData);
  1937. }
  1938. this._inflate[kCallback] = callback;
  1939. this._inflate.write(data);
  1940. if (fin) this._inflate.write(TRAILER);
  1941. this._inflate.flush(() => {
  1942. const err = this._inflate[kError];
  1943. if (err) {
  1944. this._inflate.close();
  1945. this._inflate = null;
  1946. callback(err);
  1947. return;
  1948. }
  1949. const data = bufferUtil.concat(
  1950. this._inflate[kBuffers],
  1951. this._inflate[kTotalLength]
  1952. );
  1953. if (this._inflate._readableState.endEmitted) {
  1954. this._inflate.close();
  1955. this._inflate = null;
  1956. } else {
  1957. this._inflate[kTotalLength] = 0;
  1958. this._inflate[kBuffers] = [];
  1959. if (fin && this.params[`${endpoint}_no_context_takeover`]) {
  1960. this._inflate.reset();
  1961. }
  1962. }
  1963. callback(null, data);
  1964. });
  1965. }
  1966. /**
  1967. * Compress data.
  1968. *
  1969. * @param {Buffer} data Data to compress
  1970. * @param {Boolean} fin Specifies whether or not this is the last fragment
  1971. * @param {Function} callback Callback
  1972. * @private
  1973. */
  1974. _compress(data, fin, callback) {
  1975. const endpoint = this._isServer ? 'server' : 'client';
  1976. if (!this._deflate) {
  1977. const key = `${endpoint}_max_window_bits`;
  1978. const windowBits =
  1979. typeof this.params[key] !== 'number'
  1980. ? zlib.Z_DEFAULT_WINDOWBITS
  1981. : this.params[key];
  1982. this._deflate = zlib.createDeflateRaw({
  1983. ...this._options.zlibDeflateOptions,
  1984. windowBits
  1985. });
  1986. this._deflate[kTotalLength] = 0;
  1987. this._deflate[kBuffers] = [];
  1988. this._deflate.on('data', deflateOnData);
  1989. }
  1990. this._deflate[kCallback] = callback;
  1991. this._deflate.write(data);
  1992. this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
  1993. if (!this._deflate) {
  1994. //
  1995. // The deflate stream was closed while data was being processed.
  1996. //
  1997. return;
  1998. }
  1999. let data = bufferUtil.concat(
  2000. this._deflate[kBuffers],
  2001. this._deflate[kTotalLength]
  2002. );
  2003. if (fin) data = data.slice(0, data.length - 4);
  2004. //
  2005. // Ensure that the callback will not be called again in
  2006. // `PerMessageDeflate#cleanup()`.
  2007. //
  2008. this._deflate[kCallback] = null;
  2009. this._deflate[kTotalLength] = 0;
  2010. this._deflate[kBuffers] = [];
  2011. if (fin && this.params[`${endpoint}_no_context_takeover`]) {
  2012. this._deflate.reset();
  2013. }
  2014. callback(null, data);
  2015. });
  2016. }
  2017. }
  2018. module.exports = PerMessageDeflate;
  2019. /**
  2020. * The listener of the `zlib.DeflateRaw` stream `'data'` event.
  2021. *
  2022. * @param {Buffer} chunk A chunk of data
  2023. * @private
  2024. */
  2025. function deflateOnData(chunk) {
  2026. this[kBuffers].push(chunk);
  2027. this[kTotalLength] += chunk.length;
  2028. }
  2029. /**
  2030. * The listener of the `zlib.InflateRaw` stream `'data'` event.
  2031. *
  2032. * @param {Buffer} chunk A chunk of data
  2033. * @private
  2034. */
  2035. function inflateOnData(chunk) {
  2036. this[kTotalLength] += chunk.length;
  2037. if (
  2038. this[kPerMessageDeflate]._maxPayload < 1 ||
  2039. this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
  2040. ) {
  2041. this[kBuffers].push(chunk);
  2042. return;
  2043. }
  2044. this[kError] = new RangeError('Max payload size exceeded');
  2045. this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
  2046. this[kError][kStatusCode] = 1009;
  2047. this.removeListener('data', inflateOnData);
  2048. this.reset();
  2049. }
  2050. /**
  2051. * The listener of the `zlib.InflateRaw` stream `'error'` event.
  2052. *
  2053. * @param {Error} err The emitted error
  2054. * @private
  2055. */
  2056. function inflateOnError(err) {
  2057. //
  2058. // There is no need to call `Zlib#close()` as the handle is automatically
  2059. // closed when an error is emitted.
  2060. //
  2061. this[kPerMessageDeflate]._inflate = null;
  2062. err[kStatusCode] = 1007;
  2063. this[kCallback](err);
  2064. }
  2065. /***/ }),
  2066. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js":
  2067. /*!********************************************************************************!*\
  2068. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js ***!
  2069. \********************************************************************************/
  2070. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2071. "use strict";
  2072. const { Writable } = __webpack_require__(/*! stream */ "stream");
  2073. const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
  2074. const {
  2075. BINARY_TYPES,
  2076. EMPTY_BUFFER,
  2077. kStatusCode,
  2078. kWebSocket
  2079. } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
  2080. const { concat, toArrayBuffer, unmask } = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
  2081. const { isValidStatusCode, isValidUTF8 } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
  2082. const GET_INFO = 0;
  2083. const GET_PAYLOAD_LENGTH_16 = 1;
  2084. const GET_PAYLOAD_LENGTH_64 = 2;
  2085. const GET_MASK = 3;
  2086. const GET_DATA = 4;
  2087. const INFLATING = 5;
  2088. /**
  2089. * HyBi Receiver implementation.
  2090. *
  2091. * @extends Writable
  2092. */
  2093. class Receiver extends Writable {
  2094. /**
  2095. * Creates a Receiver instance.
  2096. *
  2097. * @param {Object} [options] Options object
  2098. * @param {String} [options.binaryType=nodebuffer] The type for binary data
  2099. * @param {Object} [options.extensions] An object containing the negotiated
  2100. * extensions
  2101. * @param {Boolean} [options.isServer=false] Specifies whether to operate in
  2102. * client or server mode
  2103. * @param {Number} [options.maxPayload=0] The maximum allowed message length
  2104. * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
  2105. * not to skip UTF-8 validation for text and close messages
  2106. */
  2107. constructor(options = {}) {
  2108. super();
  2109. this._binaryType = options.binaryType || BINARY_TYPES[0];
  2110. this._extensions = options.extensions || {};
  2111. this._isServer = !!options.isServer;
  2112. this._maxPayload = options.maxPayload | 0;
  2113. this._skipUTF8Validation = !!options.skipUTF8Validation;
  2114. this[kWebSocket] = undefined;
  2115. this._bufferedBytes = 0;
  2116. this._buffers = [];
  2117. this._compressed = false;
  2118. this._payloadLength = 0;
  2119. this._mask = undefined;
  2120. this._fragmented = 0;
  2121. this._masked = false;
  2122. this._fin = false;
  2123. this._opcode = 0;
  2124. this._totalPayloadLength = 0;
  2125. this._messageLength = 0;
  2126. this._fragments = [];
  2127. this._state = GET_INFO;
  2128. this._loop = false;
  2129. }
  2130. /**
  2131. * Implements `Writable.prototype._write()`.
  2132. *
  2133. * @param {Buffer} chunk The chunk of data to write
  2134. * @param {String} encoding The character encoding of `chunk`
  2135. * @param {Function} cb Callback
  2136. * @private
  2137. */
  2138. _write(chunk, encoding, cb) {
  2139. if (this._opcode === 0x08 && this._state == GET_INFO) return cb();
  2140. this._bufferedBytes += chunk.length;
  2141. this._buffers.push(chunk);
  2142. this.startLoop(cb);
  2143. }
  2144. /**
  2145. * Consumes `n` bytes from the buffered data.
  2146. *
  2147. * @param {Number} n The number of bytes to consume
  2148. * @return {Buffer} The consumed bytes
  2149. * @private
  2150. */
  2151. consume(n) {
  2152. this._bufferedBytes -= n;
  2153. if (n === this._buffers[0].length) return this._buffers.shift();
  2154. if (n < this._buffers[0].length) {
  2155. const buf = this._buffers[0];
  2156. this._buffers[0] = buf.slice(n);
  2157. return buf.slice(0, n);
  2158. }
  2159. const dst = Buffer.allocUnsafe(n);
  2160. do {
  2161. const buf = this._buffers[0];
  2162. const offset = dst.length - n;
  2163. if (n >= buf.length) {
  2164. dst.set(this._buffers.shift(), offset);
  2165. } else {
  2166. dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
  2167. this._buffers[0] = buf.slice(n);
  2168. }
  2169. n -= buf.length;
  2170. } while (n > 0);
  2171. return dst;
  2172. }
  2173. /**
  2174. * Starts the parsing loop.
  2175. *
  2176. * @param {Function} cb Callback
  2177. * @private
  2178. */
  2179. startLoop(cb) {
  2180. let err;
  2181. this._loop = true;
  2182. do {
  2183. switch (this._state) {
  2184. case GET_INFO:
  2185. err = this.getInfo();
  2186. break;
  2187. case GET_PAYLOAD_LENGTH_16:
  2188. err = this.getPayloadLength16();
  2189. break;
  2190. case GET_PAYLOAD_LENGTH_64:
  2191. err = this.getPayloadLength64();
  2192. break;
  2193. case GET_MASK:
  2194. this.getMask();
  2195. break;
  2196. case GET_DATA:
  2197. err = this.getData(cb);
  2198. break;
  2199. default:
  2200. // `INFLATING`
  2201. this._loop = false;
  2202. return;
  2203. }
  2204. } while (this._loop);
  2205. cb(err);
  2206. }
  2207. /**
  2208. * Reads the first two bytes of a frame.
  2209. *
  2210. * @return {(RangeError|undefined)} A possible error
  2211. * @private
  2212. */
  2213. getInfo() {
  2214. if (this._bufferedBytes < 2) {
  2215. this._loop = false;
  2216. return;
  2217. }
  2218. const buf = this.consume(2);
  2219. if ((buf[0] & 0x30) !== 0x00) {
  2220. this._loop = false;
  2221. return error(
  2222. RangeError,
  2223. 'RSV2 and RSV3 must be clear',
  2224. true,
  2225. 1002,
  2226. 'WS_ERR_UNEXPECTED_RSV_2_3'
  2227. );
  2228. }
  2229. const compressed = (buf[0] & 0x40) === 0x40;
  2230. if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
  2231. this._loop = false;
  2232. return error(
  2233. RangeError,
  2234. 'RSV1 must be clear',
  2235. true,
  2236. 1002,
  2237. 'WS_ERR_UNEXPECTED_RSV_1'
  2238. );
  2239. }
  2240. this._fin = (buf[0] & 0x80) === 0x80;
  2241. this._opcode = buf[0] & 0x0f;
  2242. this._payloadLength = buf[1] & 0x7f;
  2243. if (this._opcode === 0x00) {
  2244. if (compressed) {
  2245. this._loop = false;
  2246. return error(
  2247. RangeError,
  2248. 'RSV1 must be clear',
  2249. true,
  2250. 1002,
  2251. 'WS_ERR_UNEXPECTED_RSV_1'
  2252. );
  2253. }
  2254. if (!this._fragmented) {
  2255. this._loop = false;
  2256. return error(
  2257. RangeError,
  2258. 'invalid opcode 0',
  2259. true,
  2260. 1002,
  2261. 'WS_ERR_INVALID_OPCODE'
  2262. );
  2263. }
  2264. this._opcode = this._fragmented;
  2265. } else if (this._opcode === 0x01 || this._opcode === 0x02) {
  2266. if (this._fragmented) {
  2267. this._loop = false;
  2268. return error(
  2269. RangeError,
  2270. `invalid opcode ${this._opcode}`,
  2271. true,
  2272. 1002,
  2273. 'WS_ERR_INVALID_OPCODE'
  2274. );
  2275. }
  2276. this._compressed = compressed;
  2277. } else if (this._opcode > 0x07 && this._opcode < 0x0b) {
  2278. if (!this._fin) {
  2279. this._loop = false;
  2280. return error(
  2281. RangeError,
  2282. 'FIN must be set',
  2283. true,
  2284. 1002,
  2285. 'WS_ERR_EXPECTED_FIN'
  2286. );
  2287. }
  2288. if (compressed) {
  2289. this._loop = false;
  2290. return error(
  2291. RangeError,
  2292. 'RSV1 must be clear',
  2293. true,
  2294. 1002,
  2295. 'WS_ERR_UNEXPECTED_RSV_1'
  2296. );
  2297. }
  2298. if (this._payloadLength > 0x7d) {
  2299. this._loop = false;
  2300. return error(
  2301. RangeError,
  2302. `invalid payload length ${this._payloadLength}`,
  2303. true,
  2304. 1002,
  2305. 'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'
  2306. );
  2307. }
  2308. } else {
  2309. this._loop = false;
  2310. return error(
  2311. RangeError,
  2312. `invalid opcode ${this._opcode}`,
  2313. true,
  2314. 1002,
  2315. 'WS_ERR_INVALID_OPCODE'
  2316. );
  2317. }
  2318. if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
  2319. this._masked = (buf[1] & 0x80) === 0x80;
  2320. if (this._isServer) {
  2321. if (!this._masked) {
  2322. this._loop = false;
  2323. return error(
  2324. RangeError,
  2325. 'MASK must be set',
  2326. true,
  2327. 1002,
  2328. 'WS_ERR_EXPECTED_MASK'
  2329. );
  2330. }
  2331. } else if (this._masked) {
  2332. this._loop = false;
  2333. return error(
  2334. RangeError,
  2335. 'MASK must be clear',
  2336. true,
  2337. 1002,
  2338. 'WS_ERR_UNEXPECTED_MASK'
  2339. );
  2340. }
  2341. if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
  2342. else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
  2343. else return this.haveLength();
  2344. }
  2345. /**
  2346. * Gets extended payload length (7+16).
  2347. *
  2348. * @return {(RangeError|undefined)} A possible error
  2349. * @private
  2350. */
  2351. getPayloadLength16() {
  2352. if (this._bufferedBytes < 2) {
  2353. this._loop = false;
  2354. return;
  2355. }
  2356. this._payloadLength = this.consume(2).readUInt16BE(0);
  2357. return this.haveLength();
  2358. }
  2359. /**
  2360. * Gets extended payload length (7+64).
  2361. *
  2362. * @return {(RangeError|undefined)} A possible error
  2363. * @private
  2364. */
  2365. getPayloadLength64() {
  2366. if (this._bufferedBytes < 8) {
  2367. this._loop = false;
  2368. return;
  2369. }
  2370. const buf = this.consume(8);
  2371. const num = buf.readUInt32BE(0);
  2372. //
  2373. // The maximum safe integer in JavaScript is 2^53 - 1. An error is returned
  2374. // if payload length is greater than this number.
  2375. //
  2376. if (num > Math.pow(2, 53 - 32) - 1) {
  2377. this._loop = false;
  2378. return error(
  2379. RangeError,
  2380. 'Unsupported WebSocket frame: payload length > 2^53 - 1',
  2381. false,
  2382. 1009,
  2383. 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
  2384. );
  2385. }
  2386. this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
  2387. return this.haveLength();
  2388. }
  2389. /**
  2390. * Payload length has been read.
  2391. *
  2392. * @return {(RangeError|undefined)} A possible error
  2393. * @private
  2394. */
  2395. haveLength() {
  2396. if (this._payloadLength && this._opcode < 0x08) {
  2397. this._totalPayloadLength += this._payloadLength;
  2398. if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
  2399. this._loop = false;
  2400. return error(
  2401. RangeError,
  2402. 'Max payload size exceeded',
  2403. false,
  2404. 1009,
  2405. 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
  2406. );
  2407. }
  2408. }
  2409. if (this._masked) this._state = GET_MASK;
  2410. else this._state = GET_DATA;
  2411. }
  2412. /**
  2413. * Reads mask bytes.
  2414. *
  2415. * @private
  2416. */
  2417. getMask() {
  2418. if (this._bufferedBytes < 4) {
  2419. this._loop = false;
  2420. return;
  2421. }
  2422. this._mask = this.consume(4);
  2423. this._state = GET_DATA;
  2424. }
  2425. /**
  2426. * Reads data bytes.
  2427. *
  2428. * @param {Function} cb Callback
  2429. * @return {(Error|RangeError|undefined)} A possible error
  2430. * @private
  2431. */
  2432. getData(cb) {
  2433. let data = EMPTY_BUFFER;
  2434. if (this._payloadLength) {
  2435. if (this._bufferedBytes < this._payloadLength) {
  2436. this._loop = false;
  2437. return;
  2438. }
  2439. data = this.consume(this._payloadLength);
  2440. if (this._masked) unmask(data, this._mask);
  2441. }
  2442. if (this._opcode > 0x07) return this.controlMessage(data);
  2443. if (this._compressed) {
  2444. this._state = INFLATING;
  2445. this.decompress(data, cb);
  2446. return;
  2447. }
  2448. if (data.length) {
  2449. //
  2450. // This message is not compressed so its length is the sum of the payload
  2451. // length of all fragments.
  2452. //
  2453. this._messageLength = this._totalPayloadLength;
  2454. this._fragments.push(data);
  2455. }
  2456. return this.dataMessage();
  2457. }
  2458. /**
  2459. * Decompresses data.
  2460. *
  2461. * @param {Buffer} data Compressed data
  2462. * @param {Function} cb Callback
  2463. * @private
  2464. */
  2465. decompress(data, cb) {
  2466. const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
  2467. perMessageDeflate.decompress(data, this._fin, (err, buf) => {
  2468. if (err) return cb(err);
  2469. if (buf.length) {
  2470. this._messageLength += buf.length;
  2471. if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
  2472. return cb(
  2473. error(
  2474. RangeError,
  2475. 'Max payload size exceeded',
  2476. false,
  2477. 1009,
  2478. 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
  2479. )
  2480. );
  2481. }
  2482. this._fragments.push(buf);
  2483. }
  2484. const er = this.dataMessage();
  2485. if (er) return cb(er);
  2486. this.startLoop(cb);
  2487. });
  2488. }
  2489. /**
  2490. * Handles a data message.
  2491. *
  2492. * @return {(Error|undefined)} A possible error
  2493. * @private
  2494. */
  2495. dataMessage() {
  2496. if (this._fin) {
  2497. const messageLength = this._messageLength;
  2498. const fragments = this._fragments;
  2499. this._totalPayloadLength = 0;
  2500. this._messageLength = 0;
  2501. this._fragmented = 0;
  2502. this._fragments = [];
  2503. if (this._opcode === 2) {
  2504. let data;
  2505. if (this._binaryType === 'nodebuffer') {
  2506. data = concat(fragments, messageLength);
  2507. } else if (this._binaryType === 'arraybuffer') {
  2508. data = toArrayBuffer(concat(fragments, messageLength));
  2509. } else {
  2510. data = fragments;
  2511. }
  2512. this.emit('message', data, true);
  2513. } else {
  2514. const buf = concat(fragments, messageLength);
  2515. if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
  2516. this._loop = false;
  2517. return error(
  2518. Error,
  2519. 'invalid UTF-8 sequence',
  2520. true,
  2521. 1007,
  2522. 'WS_ERR_INVALID_UTF8'
  2523. );
  2524. }
  2525. this.emit('message', buf, false);
  2526. }
  2527. }
  2528. this._state = GET_INFO;
  2529. }
  2530. /**
  2531. * Handles a control message.
  2532. *
  2533. * @param {Buffer} data Data to handle
  2534. * @return {(Error|RangeError|undefined)} A possible error
  2535. * @private
  2536. */
  2537. controlMessage(data) {
  2538. if (this._opcode === 0x08) {
  2539. this._loop = false;
  2540. if (data.length === 0) {
  2541. this.emit('conclude', 1005, EMPTY_BUFFER);
  2542. this.end();
  2543. } else if (data.length === 1) {
  2544. return error(
  2545. RangeError,
  2546. 'invalid payload length 1',
  2547. true,
  2548. 1002,
  2549. 'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'
  2550. );
  2551. } else {
  2552. const code = data.readUInt16BE(0);
  2553. if (!isValidStatusCode(code)) {
  2554. return error(
  2555. RangeError,
  2556. `invalid status code ${code}`,
  2557. true,
  2558. 1002,
  2559. 'WS_ERR_INVALID_CLOSE_CODE'
  2560. );
  2561. }
  2562. const buf = data.slice(2);
  2563. if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
  2564. return error(
  2565. Error,
  2566. 'invalid UTF-8 sequence',
  2567. true,
  2568. 1007,
  2569. 'WS_ERR_INVALID_UTF8'
  2570. );
  2571. }
  2572. this.emit('conclude', code, buf);
  2573. this.end();
  2574. }
  2575. } else if (this._opcode === 0x09) {
  2576. this.emit('ping', data);
  2577. } else {
  2578. this.emit('pong', data);
  2579. }
  2580. this._state = GET_INFO;
  2581. }
  2582. }
  2583. module.exports = Receiver;
  2584. /**
  2585. * Builds an error object.
  2586. *
  2587. * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
  2588. * @param {String} message The error message
  2589. * @param {Boolean} prefix Specifies whether or not to add a default prefix to
  2590. * `message`
  2591. * @param {Number} statusCode The status code
  2592. * @param {String} errorCode The exposed error code
  2593. * @return {(Error|RangeError)} The error
  2594. * @private
  2595. */
  2596. function error(ErrorCtor, message, prefix, statusCode, errorCode) {
  2597. const err = new ErrorCtor(
  2598. prefix ? `Invalid WebSocket frame: ${message}` : message
  2599. );
  2600. Error.captureStackTrace(err, error);
  2601. err.code = errorCode;
  2602. err[kStatusCode] = statusCode;
  2603. return err;
  2604. }
  2605. /***/ }),
  2606. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js":
  2607. /*!******************************************************************************!*\
  2608. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js ***!
  2609. \******************************************************************************/
  2610. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2611. "use strict";
  2612. /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls$" }] */
  2613. const net = __webpack_require__(/*! net */ "net");
  2614. const tls = __webpack_require__(/*! tls */ "tls");
  2615. const { randomFillSync } = __webpack_require__(/*! crypto */ "crypto");
  2616. const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
  2617. const { EMPTY_BUFFER } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
  2618. const { isValidStatusCode } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
  2619. const { mask: applyMask, toBuffer } = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
  2620. const mask = Buffer.alloc(4);
  2621. /**
  2622. * HyBi Sender implementation.
  2623. */
  2624. class Sender {
  2625. /**
  2626. * Creates a Sender instance.
  2627. *
  2628. * @param {(net.Socket|tls.Socket)} socket The connection socket
  2629. * @param {Object} [extensions] An object containing the negotiated extensions
  2630. */
  2631. constructor(socket, extensions) {
  2632. this._extensions = extensions || {};
  2633. this._socket = socket;
  2634. this._firstFragment = true;
  2635. this._compress = false;
  2636. this._bufferedBytes = 0;
  2637. this._deflating = false;
  2638. this._queue = [];
  2639. }
  2640. /**
  2641. * Frames a piece of data according to the HyBi WebSocket protocol.
  2642. *
  2643. * @param {Buffer} data The data to frame
  2644. * @param {Object} options Options object
  2645. * @param {Boolean} [options.fin=false] Specifies whether or not to set the
  2646. * FIN bit
  2647. * @param {Boolean} [options.mask=false] Specifies whether or not to mask
  2648. * `data`
  2649. * @param {Number} options.opcode The opcode
  2650. * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
  2651. * modified
  2652. * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
  2653. * RSV1 bit
  2654. * @return {Buffer[]} The framed data as a list of `Buffer` instances
  2655. * @public
  2656. */
  2657. static frame(data, options) {
  2658. const merge = options.mask && options.readOnly;
  2659. let offset = options.mask ? 6 : 2;
  2660. let payloadLength = data.length;
  2661. if (data.length >= 65536) {
  2662. offset += 8;
  2663. payloadLength = 127;
  2664. } else if (data.length > 125) {
  2665. offset += 2;
  2666. payloadLength = 126;
  2667. }
  2668. const target = Buffer.allocUnsafe(merge ? data.length + offset : offset);
  2669. target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
  2670. if (options.rsv1) target[0] |= 0x40;
  2671. target[1] = payloadLength;
  2672. if (payloadLength === 126) {
  2673. target.writeUInt16BE(data.length, 2);
  2674. } else if (payloadLength === 127) {
  2675. target.writeUInt32BE(0, 2);
  2676. target.writeUInt32BE(data.length, 6);
  2677. }
  2678. if (!options.mask) return [target, data];
  2679. randomFillSync(mask, 0, 4);
  2680. target[1] |= 0x80;
  2681. target[offset - 4] = mask[0];
  2682. target[offset - 3] = mask[1];
  2683. target[offset - 2] = mask[2];
  2684. target[offset - 1] = mask[3];
  2685. if (merge) {
  2686. applyMask(data, mask, target, offset, data.length);
  2687. return [target];
  2688. }
  2689. applyMask(data, mask, data, 0, data.length);
  2690. return [target, data];
  2691. }
  2692. /**
  2693. * Sends a close message to the other peer.
  2694. *
  2695. * @param {Number} [code] The status code component of the body
  2696. * @param {(String|Buffer)} [data] The message component of the body
  2697. * @param {Boolean} [mask=false] Specifies whether or not to mask the message
  2698. * @param {Function} [cb] Callback
  2699. * @public
  2700. */
  2701. close(code, data, mask, cb) {
  2702. let buf;
  2703. if (code === undefined) {
  2704. buf = EMPTY_BUFFER;
  2705. } else if (typeof code !== 'number' || !isValidStatusCode(code)) {
  2706. throw new TypeError('First argument must be a valid error code number');
  2707. } else if (data === undefined || !data.length) {
  2708. buf = Buffer.allocUnsafe(2);
  2709. buf.writeUInt16BE(code, 0);
  2710. } else {
  2711. const length = Buffer.byteLength(data);
  2712. if (length > 123) {
  2713. throw new RangeError('The message must not be greater than 123 bytes');
  2714. }
  2715. buf = Buffer.allocUnsafe(2 + length);
  2716. buf.writeUInt16BE(code, 0);
  2717. if (typeof data === 'string') {
  2718. buf.write(data, 2);
  2719. } else {
  2720. buf.set(data, 2);
  2721. }
  2722. }
  2723. if (this._deflating) {
  2724. this.enqueue([this.doClose, buf, mask, cb]);
  2725. } else {
  2726. this.doClose(buf, mask, cb);
  2727. }
  2728. }
  2729. /**
  2730. * Frames and sends a close message.
  2731. *
  2732. * @param {Buffer} data The message to send
  2733. * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
  2734. * @param {Function} [cb] Callback
  2735. * @private
  2736. */
  2737. doClose(data, mask, cb) {
  2738. this.sendFrame(
  2739. Sender.frame(data, {
  2740. fin: true,
  2741. rsv1: false,
  2742. opcode: 0x08,
  2743. mask,
  2744. readOnly: false
  2745. }),
  2746. cb
  2747. );
  2748. }
  2749. /**
  2750. * Sends a ping message to the other peer.
  2751. *
  2752. * @param {*} data The message to send
  2753. * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
  2754. * @param {Function} [cb] Callback
  2755. * @public
  2756. */
  2757. ping(data, mask, cb) {
  2758. const buf = toBuffer(data);
  2759. if (buf.length > 125) {
  2760. throw new RangeError('The data size must not be greater than 125 bytes');
  2761. }
  2762. if (this._deflating) {
  2763. this.enqueue([this.doPing, buf, mask, toBuffer.readOnly, cb]);
  2764. } else {
  2765. this.doPing(buf, mask, toBuffer.readOnly, cb);
  2766. }
  2767. }
  2768. /**
  2769. * Frames and sends a ping message.
  2770. *
  2771. * @param {Buffer} data The message to send
  2772. * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
  2773. * @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
  2774. * @param {Function} [cb] Callback
  2775. * @private
  2776. */
  2777. doPing(data, mask, readOnly, cb) {
  2778. this.sendFrame(
  2779. Sender.frame(data, {
  2780. fin: true,
  2781. rsv1: false,
  2782. opcode: 0x09,
  2783. mask,
  2784. readOnly
  2785. }),
  2786. cb
  2787. );
  2788. }
  2789. /**
  2790. * Sends a pong message to the other peer.
  2791. *
  2792. * @param {*} data The message to send
  2793. * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
  2794. * @param {Function} [cb] Callback
  2795. * @public
  2796. */
  2797. pong(data, mask, cb) {
  2798. const buf = toBuffer(data);
  2799. if (buf.length > 125) {
  2800. throw new RangeError('The data size must not be greater than 125 bytes');
  2801. }
  2802. if (this._deflating) {
  2803. this.enqueue([this.doPong, buf, mask, toBuffer.readOnly, cb]);
  2804. } else {
  2805. this.doPong(buf, mask, toBuffer.readOnly, cb);
  2806. }
  2807. }
  2808. /**
  2809. * Frames and sends a pong message.
  2810. *
  2811. * @param {Buffer} data The message to send
  2812. * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
  2813. * @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
  2814. * @param {Function} [cb] Callback
  2815. * @private
  2816. */
  2817. doPong(data, mask, readOnly, cb) {
  2818. this.sendFrame(
  2819. Sender.frame(data, {
  2820. fin: true,
  2821. rsv1: false,
  2822. opcode: 0x0a,
  2823. mask,
  2824. readOnly
  2825. }),
  2826. cb
  2827. );
  2828. }
  2829. /**
  2830. * Sends a data message to the other peer.
  2831. *
  2832. * @param {*} data The message to send
  2833. * @param {Object} options Options object
  2834. * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
  2835. * or text
  2836. * @param {Boolean} [options.compress=false] Specifies whether or not to
  2837. * compress `data`
  2838. * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
  2839. * last one
  2840. * @param {Boolean} [options.mask=false] Specifies whether or not to mask
  2841. * `data`
  2842. * @param {Function} [cb] Callback
  2843. * @public
  2844. */
  2845. send(data, options, cb) {
  2846. const buf = toBuffer(data);
  2847. const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
  2848. let opcode = options.binary ? 2 : 1;
  2849. let rsv1 = options.compress;
  2850. if (this._firstFragment) {
  2851. this._firstFragment = false;
  2852. if (
  2853. rsv1 &&
  2854. perMessageDeflate &&
  2855. perMessageDeflate.params[
  2856. perMessageDeflate._isServer
  2857. ? 'server_no_context_takeover'
  2858. : 'client_no_context_takeover'
  2859. ]
  2860. ) {
  2861. rsv1 = buf.length >= perMessageDeflate._threshold;
  2862. }
  2863. this._compress = rsv1;
  2864. } else {
  2865. rsv1 = false;
  2866. opcode = 0;
  2867. }
  2868. if (options.fin) this._firstFragment = true;
  2869. if (perMessageDeflate) {
  2870. const opts = {
  2871. fin: options.fin,
  2872. rsv1,
  2873. opcode,
  2874. mask: options.mask,
  2875. readOnly: toBuffer.readOnly
  2876. };
  2877. if (this._deflating) {
  2878. this.enqueue([this.dispatch, buf, this._compress, opts, cb]);
  2879. } else {
  2880. this.dispatch(buf, this._compress, opts, cb);
  2881. }
  2882. } else {
  2883. this.sendFrame(
  2884. Sender.frame(buf, {
  2885. fin: options.fin,
  2886. rsv1: false,
  2887. opcode,
  2888. mask: options.mask,
  2889. readOnly: toBuffer.readOnly
  2890. }),
  2891. cb
  2892. );
  2893. }
  2894. }
  2895. /**
  2896. * Dispatches a data message.
  2897. *
  2898. * @param {Buffer} data The message to send
  2899. * @param {Boolean} [compress=false] Specifies whether or not to compress
  2900. * `data`
  2901. * @param {Object} options Options object
  2902. * @param {Number} options.opcode The opcode
  2903. * @param {Boolean} [options.fin=false] Specifies whether or not to set the
  2904. * FIN bit
  2905. * @param {Boolean} [options.mask=false] Specifies whether or not to mask
  2906. * `data`
  2907. * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
  2908. * modified
  2909. * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
  2910. * RSV1 bit
  2911. * @param {Function} [cb] Callback
  2912. * @private
  2913. */
  2914. dispatch(data, compress, options, cb) {
  2915. if (!compress) {
  2916. this.sendFrame(Sender.frame(data, options), cb);
  2917. return;
  2918. }
  2919. const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
  2920. this._bufferedBytes += data.length;
  2921. this._deflating = true;
  2922. perMessageDeflate.compress(data, options.fin, (_, buf) => {
  2923. if (this._socket.destroyed) {
  2924. const err = new Error(
  2925. 'The socket was closed while data was being compressed'
  2926. );
  2927. if (typeof cb === 'function') cb(err);
  2928. for (let i = 0; i < this._queue.length; i++) {
  2929. const callback = this._queue[i][4];
  2930. if (typeof callback === 'function') callback(err);
  2931. }
  2932. return;
  2933. }
  2934. this._bufferedBytes -= data.length;
  2935. this._deflating = false;
  2936. options.readOnly = false;
  2937. this.sendFrame(Sender.frame(buf, options), cb);
  2938. this.dequeue();
  2939. });
  2940. }
  2941. /**
  2942. * Executes queued send operations.
  2943. *
  2944. * @private
  2945. */
  2946. dequeue() {
  2947. while (!this._deflating && this._queue.length) {
  2948. const params = this._queue.shift();
  2949. this._bufferedBytes -= params[1].length;
  2950. Reflect.apply(params[0], this, params.slice(1));
  2951. }
  2952. }
  2953. /**
  2954. * Enqueues a send operation.
  2955. *
  2956. * @param {Array} params Send operation parameters.
  2957. * @private
  2958. */
  2959. enqueue(params) {
  2960. this._bufferedBytes += params[1].length;
  2961. this._queue.push(params);
  2962. }
  2963. /**
  2964. * Sends a frame.
  2965. *
  2966. * @param {Buffer[]} list The frame to send
  2967. * @param {Function} [cb] Callback
  2968. * @private
  2969. */
  2970. sendFrame(list, cb) {
  2971. if (list.length === 2) {
  2972. this._socket.cork();
  2973. this._socket.write(list[0]);
  2974. this._socket.write(list[1], cb);
  2975. this._socket.uncork();
  2976. } else {
  2977. this._socket.write(list[0], cb);
  2978. }
  2979. }
  2980. }
  2981. module.exports = Sender;
  2982. /***/ }),
  2983. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/stream.js":
  2984. /*!******************************************************************************!*\
  2985. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/stream.js ***!
  2986. \******************************************************************************/
  2987. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2988. "use strict";
  2989. const { Duplex } = __webpack_require__(/*! stream */ "stream");
  2990. /**
  2991. * Emits the `'close'` event on a stream.
  2992. *
  2993. * @param {Duplex} stream The stream.
  2994. * @private
  2995. */
  2996. function emitClose(stream) {
  2997. stream.emit('close');
  2998. }
  2999. /**
  3000. * The listener of the `'end'` event.
  3001. *
  3002. * @private
  3003. */
  3004. function duplexOnEnd() {
  3005. if (!this.destroyed && this._writableState.finished) {
  3006. this.destroy();
  3007. }
  3008. }
  3009. /**
  3010. * The listener of the `'error'` event.
  3011. *
  3012. * @param {Error} err The error
  3013. * @private
  3014. */
  3015. function duplexOnError(err) {
  3016. this.removeListener('error', duplexOnError);
  3017. this.destroy();
  3018. if (this.listenerCount('error') === 0) {
  3019. // Do not suppress the throwing behavior.
  3020. this.emit('error', err);
  3021. }
  3022. }
  3023. /**
  3024. * Wraps a `WebSocket` in a duplex stream.
  3025. *
  3026. * @param {WebSocket} ws The `WebSocket` to wrap
  3027. * @param {Object} [options] The options for the `Duplex` constructor
  3028. * @return {Duplex} The duplex stream
  3029. * @public
  3030. */
  3031. function createWebSocketStream(ws, options) {
  3032. let resumeOnReceiverDrain = true;
  3033. let terminateOnDestroy = true;
  3034. function receiverOnDrain() {
  3035. if (resumeOnReceiverDrain) ws._socket.resume();
  3036. }
  3037. if (ws.readyState === ws.CONNECTING) {
  3038. ws.once('open', function open() {
  3039. ws._receiver.removeAllListeners('drain');
  3040. ws._receiver.on('drain', receiverOnDrain);
  3041. });
  3042. } else {
  3043. ws._receiver.removeAllListeners('drain');
  3044. ws._receiver.on('drain', receiverOnDrain);
  3045. }
  3046. const duplex = new Duplex({
  3047. ...options,
  3048. autoDestroy: false,
  3049. emitClose: false,
  3050. objectMode: false,
  3051. writableObjectMode: false
  3052. });
  3053. ws.on('message', function message(msg, isBinary) {
  3054. const data =
  3055. !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
  3056. if (!duplex.push(data)) {
  3057. resumeOnReceiverDrain = false;
  3058. ws._socket.pause();
  3059. }
  3060. });
  3061. ws.once('error', function error(err) {
  3062. if (duplex.destroyed) return;
  3063. // Prevent `ws.terminate()` from being called by `duplex._destroy()`.
  3064. //
  3065. // - If the `'error'` event is emitted before the `'open'` event, then
  3066. // `ws.terminate()` is a noop as no socket is assigned.
  3067. // - Otherwise, the error is re-emitted by the listener of the `'error'`
  3068. // event of the `Receiver` object. The listener already closes the
  3069. // connection by calling `ws.close()`. This allows a close frame to be
  3070. // sent to the other peer. If `ws.terminate()` is called right after this,
  3071. // then the close frame might not be sent.
  3072. terminateOnDestroy = false;
  3073. duplex.destroy(err);
  3074. });
  3075. ws.once('close', function close() {
  3076. if (duplex.destroyed) return;
  3077. duplex.push(null);
  3078. });
  3079. duplex._destroy = function (err, callback) {
  3080. if (ws.readyState === ws.CLOSED) {
  3081. callback(err);
  3082. process.nextTick(emitClose, duplex);
  3083. return;
  3084. }
  3085. let called = false;
  3086. ws.once('error', function error(err) {
  3087. called = true;
  3088. callback(err);
  3089. });
  3090. ws.once('close', function close() {
  3091. if (!called) callback(err);
  3092. process.nextTick(emitClose, duplex);
  3093. });
  3094. if (terminateOnDestroy) ws.terminate();
  3095. };
  3096. duplex._final = function (callback) {
  3097. if (ws.readyState === ws.CONNECTING) {
  3098. ws.once('open', function open() {
  3099. duplex._final(callback);
  3100. });
  3101. return;
  3102. }
  3103. // If the value of the `_socket` property is `null` it means that `ws` is a
  3104. // client websocket and the handshake failed. In fact, when this happens, a
  3105. // socket is never assigned to the websocket. Wait for the `'error'` event
  3106. // that will be emitted by the websocket.
  3107. if (ws._socket === null) return;
  3108. if (ws._socket._writableState.finished) {
  3109. callback();
  3110. if (duplex._readableState.endEmitted) duplex.destroy();
  3111. } else {
  3112. ws._socket.once('finish', function finish() {
  3113. // `duplex` is not destroyed here because the `'end'` event will be
  3114. // emitted on `duplex` after this `'finish'` event. The EOF signaling
  3115. // `null` chunk is, in fact, pushed when the websocket emits `'close'`.
  3116. callback();
  3117. });
  3118. ws.close();
  3119. }
  3120. };
  3121. duplex._read = function () {
  3122. if (ws.readyState === ws.OPEN && !resumeOnReceiverDrain) {
  3123. resumeOnReceiverDrain = true;
  3124. if (!ws._receiver._writableState.needDrain) ws._socket.resume();
  3125. }
  3126. };
  3127. duplex._write = function (chunk, encoding, callback) {
  3128. if (ws.readyState === ws.CONNECTING) {
  3129. ws.once('open', function open() {
  3130. duplex._write(chunk, encoding, callback);
  3131. });
  3132. return;
  3133. }
  3134. ws.send(chunk, callback);
  3135. };
  3136. duplex.on('end', duplexOnEnd);
  3137. duplex.on('error', duplexOnError);
  3138. return duplex;
  3139. }
  3140. module.exports = createWebSocketStream;
  3141. /***/ }),
  3142. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js":
  3143. /*!***********************************************************************************!*\
  3144. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js ***!
  3145. \***********************************************************************************/
  3146. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3147. "use strict";
  3148. const { tokenChars } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
  3149. /**
  3150. * Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
  3151. *
  3152. * @param {String} header The field value of the header
  3153. * @return {Set} The subprotocol names
  3154. * @public
  3155. */
  3156. function parse(header) {
  3157. const protocols = new Set();
  3158. let start = -1;
  3159. let end = -1;
  3160. let i = 0;
  3161. for (i; i < header.length; i++) {
  3162. const code = header.charCodeAt(i);
  3163. if (end === -1 && tokenChars[code] === 1) {
  3164. if (start === -1) start = i;
  3165. } else if (
  3166. i !== 0 &&
  3167. (code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
  3168. ) {
  3169. if (end === -1 && start !== -1) end = i;
  3170. } else if (code === 0x2c /* ',' */) {
  3171. if (start === -1) {
  3172. throw new SyntaxError(`Unexpected character at index ${i}`);
  3173. }
  3174. if (end === -1) end = i;
  3175. const protocol = header.slice(start, end);
  3176. if (protocols.has(protocol)) {
  3177. throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
  3178. }
  3179. protocols.add(protocol);
  3180. start = end = -1;
  3181. } else {
  3182. throw new SyntaxError(`Unexpected character at index ${i}`);
  3183. }
  3184. }
  3185. if (start === -1 || end !== -1) {
  3186. throw new SyntaxError('Unexpected end of input');
  3187. }
  3188. const protocol = header.slice(start, i);
  3189. if (protocols.has(protocol)) {
  3190. throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
  3191. }
  3192. protocols.add(protocol);
  3193. return protocols;
  3194. }
  3195. module.exports = { parse };
  3196. /***/ }),
  3197. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js":
  3198. /*!**********************************************************************************!*\
  3199. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js ***!
  3200. \**********************************************************************************/
  3201. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3202. "use strict";
  3203. //
  3204. // Allowed token characters:
  3205. //
  3206. // '!', '#', '$', '%', '&', ''', '*', '+', '-',
  3207. // '.', 0-9, A-Z, '^', '_', '`', a-z, '|', '~'
  3208. //
  3209. // tokenChars[32] === 0 // ' '
  3210. // tokenChars[33] === 1 // '!'
  3211. // tokenChars[34] === 0 // '"'
  3212. // ...
  3213. //
  3214. // prettier-ignore
  3215. const tokenChars = [
  3216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
  3217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
  3218. 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 47
  3219. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63
  3220. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79
  3221. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 95
  3222. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
  3223. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 // 112 - 127
  3224. ];
  3225. /**
  3226. * Checks if a status code is allowed in a close frame.
  3227. *
  3228. * @param {Number} code The status code
  3229. * @return {Boolean} `true` if the status code is valid, else `false`
  3230. * @public
  3231. */
  3232. function isValidStatusCode(code) {
  3233. return (
  3234. (code >= 1000 &&
  3235. code <= 1014 &&
  3236. code !== 1004 &&
  3237. code !== 1005 &&
  3238. code !== 1006) ||
  3239. (code >= 3000 && code <= 4999)
  3240. );
  3241. }
  3242. /**
  3243. * Checks if a given buffer contains only correct UTF-8.
  3244. * Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
  3245. * Markus Kuhn.
  3246. *
  3247. * @param {Buffer} buf The buffer to check
  3248. * @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
  3249. * @public
  3250. */
  3251. function _isValidUTF8(buf) {
  3252. const len = buf.length;
  3253. let i = 0;
  3254. while (i < len) {
  3255. if ((buf[i] & 0x80) === 0) {
  3256. // 0xxxxxxx
  3257. i++;
  3258. } else if ((buf[i] & 0xe0) === 0xc0) {
  3259. // 110xxxxx 10xxxxxx
  3260. if (
  3261. i + 1 === len ||
  3262. (buf[i + 1] & 0xc0) !== 0x80 ||
  3263. (buf[i] & 0xfe) === 0xc0 // Overlong
  3264. ) {
  3265. return false;
  3266. }
  3267. i += 2;
  3268. } else if ((buf[i] & 0xf0) === 0xe0) {
  3269. // 1110xxxx 10xxxxxx 10xxxxxx
  3270. if (
  3271. i + 2 >= len ||
  3272. (buf[i + 1] & 0xc0) !== 0x80 ||
  3273. (buf[i + 2] & 0xc0) !== 0x80 ||
  3274. (buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) || // Overlong
  3275. (buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0) // Surrogate (U+D800 - U+DFFF)
  3276. ) {
  3277. return false;
  3278. }
  3279. i += 3;
  3280. } else if ((buf[i] & 0xf8) === 0xf0) {
  3281. // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
  3282. if (
  3283. i + 3 >= len ||
  3284. (buf[i + 1] & 0xc0) !== 0x80 ||
  3285. (buf[i + 2] & 0xc0) !== 0x80 ||
  3286. (buf[i + 3] & 0xc0) !== 0x80 ||
  3287. (buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) || // Overlong
  3288. (buf[i] === 0xf4 && buf[i + 1] > 0x8f) ||
  3289. buf[i] > 0xf4 // > U+10FFFF
  3290. ) {
  3291. return false;
  3292. }
  3293. i += 4;
  3294. } else {
  3295. return false;
  3296. }
  3297. }
  3298. return true;
  3299. }
  3300. try {
  3301. const isValidUTF8 = __webpack_require__(/*! utf-8-validate */ "utf-8-validate");
  3302. module.exports = {
  3303. isValidStatusCode,
  3304. isValidUTF8(buf) {
  3305. return buf.length < 150 ? _isValidUTF8(buf) : isValidUTF8(buf);
  3306. },
  3307. tokenChars
  3308. };
  3309. } catch (e) /* istanbul ignore next */ {
  3310. module.exports = {
  3311. isValidStatusCode,
  3312. isValidUTF8: _isValidUTF8,
  3313. tokenChars
  3314. };
  3315. }
  3316. /***/ }),
  3317. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js":
  3318. /*!****************************************************************************************!*\
  3319. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js ***!
  3320. \****************************************************************************************/
  3321. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3322. "use strict";
  3323. /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls|https$" }] */
  3324. const EventEmitter = __webpack_require__(/*! events */ "events");
  3325. const http = __webpack_require__(/*! http */ "http");
  3326. const https = __webpack_require__(/*! https */ "https");
  3327. const net = __webpack_require__(/*! net */ "net");
  3328. const tls = __webpack_require__(/*! tls */ "tls");
  3329. const { createHash } = __webpack_require__(/*! crypto */ "crypto");
  3330. const extension = __webpack_require__(/*! ./extension */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js");
  3331. const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
  3332. const subprotocol = __webpack_require__(/*! ./subprotocol */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js");
  3333. const WebSocket = __webpack_require__(/*! ./websocket */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js");
  3334. const { GUID, kWebSocket } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
  3335. const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
  3336. const RUNNING = 0;
  3337. const CLOSING = 1;
  3338. const CLOSED = 2;
  3339. /**
  3340. * Class representing a WebSocket server.
  3341. *
  3342. * @extends EventEmitter
  3343. */
  3344. class WebSocketServer extends EventEmitter {
  3345. /**
  3346. * Create a `WebSocketServer` instance.
  3347. *
  3348. * @param {Object} options Configuration options
  3349. * @param {Number} [options.backlog=511] The maximum length of the queue of
  3350. * pending connections
  3351. * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
  3352. * track clients
  3353. * @param {Function} [options.handleProtocols] A hook to handle protocols
  3354. * @param {String} [options.host] The hostname where to bind the server
  3355. * @param {Number} [options.maxPayload=104857600] The maximum allowed message
  3356. * size
  3357. * @param {Boolean} [options.noServer=false] Enable no server mode
  3358. * @param {String} [options.path] Accept only connections matching this path
  3359. * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
  3360. * permessage-deflate
  3361. * @param {Number} [options.port] The port where to bind the server
  3362. * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
  3363. * server to use
  3364. * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
  3365. * not to skip UTF-8 validation for text and close messages
  3366. * @param {Function} [options.verifyClient] A hook to reject connections
  3367. * @param {Function} [callback] A listener for the `listening` event
  3368. */
  3369. constructor(options, callback) {
  3370. super();
  3371. options = {
  3372. maxPayload: 100 * 1024 * 1024,
  3373. skipUTF8Validation: false,
  3374. perMessageDeflate: false,
  3375. handleProtocols: null,
  3376. clientTracking: true,
  3377. verifyClient: null,
  3378. noServer: false,
  3379. backlog: null, // use default (511 as implemented in net.js)
  3380. server: null,
  3381. host: null,
  3382. path: null,
  3383. port: null,
  3384. ...options
  3385. };
  3386. if (
  3387. (options.port == null && !options.server && !options.noServer) ||
  3388. (options.port != null && (options.server || options.noServer)) ||
  3389. (options.server && options.noServer)
  3390. ) {
  3391. throw new TypeError(
  3392. 'One and only one of the "port", "server", or "noServer" options ' +
  3393. 'must be specified'
  3394. );
  3395. }
  3396. if (options.port != null) {
  3397. this._server = http.createServer((req, res) => {
  3398. const body = http.STATUS_CODES[426];
  3399. res.writeHead(426, {
  3400. 'Content-Length': body.length,
  3401. 'Content-Type': 'text/plain'
  3402. });
  3403. res.end(body);
  3404. });
  3405. this._server.listen(
  3406. options.port,
  3407. options.host,
  3408. options.backlog,
  3409. callback
  3410. );
  3411. } else if (options.server) {
  3412. this._server = options.server;
  3413. }
  3414. if (this._server) {
  3415. const emitConnection = this.emit.bind(this, 'connection');
  3416. this._removeListeners = addListeners(this._server, {
  3417. listening: this.emit.bind(this, 'listening'),
  3418. error: this.emit.bind(this, 'error'),
  3419. upgrade: (req, socket, head) => {
  3420. this.handleUpgrade(req, socket, head, emitConnection);
  3421. }
  3422. });
  3423. }
  3424. if (options.perMessageDeflate === true) options.perMessageDeflate = {};
  3425. if (options.clientTracking) {
  3426. this.clients = new Set();
  3427. this._shouldEmitClose = false;
  3428. }
  3429. this.options = options;
  3430. this._state = RUNNING;
  3431. }
  3432. /**
  3433. * Returns the bound address, the address family name, and port of the server
  3434. * as reported by the operating system if listening on an IP socket.
  3435. * If the server is listening on a pipe or UNIX domain socket, the name is
  3436. * returned as a string.
  3437. *
  3438. * @return {(Object|String|null)} The address of the server
  3439. * @public
  3440. */
  3441. address() {
  3442. if (this.options.noServer) {
  3443. throw new Error('The server is operating in "noServer" mode');
  3444. }
  3445. if (!this._server) return null;
  3446. return this._server.address();
  3447. }
  3448. /**
  3449. * Stop the server from accepting new connections and emit the `'close'` event
  3450. * when all existing connections are closed.
  3451. *
  3452. * @param {Function} [cb] A one-time listener for the `'close'` event
  3453. * @public
  3454. */
  3455. close(cb) {
  3456. if (this._state === CLOSED) {
  3457. if (cb) {
  3458. this.once('close', () => {
  3459. cb(new Error('The server is not running'));
  3460. });
  3461. }
  3462. process.nextTick(emitClose, this);
  3463. return;
  3464. }
  3465. if (cb) this.once('close', cb);
  3466. if (this._state === CLOSING) return;
  3467. this._state = CLOSING;
  3468. if (this.options.noServer || this.options.server) {
  3469. if (this._server) {
  3470. this._removeListeners();
  3471. this._removeListeners = this._server = null;
  3472. }
  3473. if (this.clients) {
  3474. if (!this.clients.size) {
  3475. process.nextTick(emitClose, this);
  3476. } else {
  3477. this._shouldEmitClose = true;
  3478. }
  3479. } else {
  3480. process.nextTick(emitClose, this);
  3481. }
  3482. } else {
  3483. const server = this._server;
  3484. this._removeListeners();
  3485. this._removeListeners = this._server = null;
  3486. //
  3487. // The HTTP/S server was created internally. Close it, and rely on its
  3488. // `'close'` event.
  3489. //
  3490. server.close(() => {
  3491. emitClose(this);
  3492. });
  3493. }
  3494. }
  3495. /**
  3496. * See if a given request should be handled by this server instance.
  3497. *
  3498. * @param {http.IncomingMessage} req Request object to inspect
  3499. * @return {Boolean} `true` if the request is valid, else `false`
  3500. * @public
  3501. */
  3502. shouldHandle(req) {
  3503. if (this.options.path) {
  3504. const index = req.url.indexOf('?');
  3505. const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
  3506. if (pathname !== this.options.path) return false;
  3507. }
  3508. return true;
  3509. }
  3510. /**
  3511. * Handle a HTTP Upgrade request.
  3512. *
  3513. * @param {http.IncomingMessage} req The request object
  3514. * @param {(net.Socket|tls.Socket)} socket The network socket between the
  3515. * server and client
  3516. * @param {Buffer} head The first packet of the upgraded stream
  3517. * @param {Function} cb Callback
  3518. * @public
  3519. */
  3520. handleUpgrade(req, socket, head, cb) {
  3521. socket.on('error', socketOnError);
  3522. const key =
  3523. req.headers['sec-websocket-key'] !== undefined
  3524. ? req.headers['sec-websocket-key']
  3525. : false;
  3526. const version = +req.headers['sec-websocket-version'];
  3527. if (
  3528. req.method !== 'GET' ||
  3529. req.headers.upgrade.toLowerCase() !== 'websocket' ||
  3530. !key ||
  3531. !keyRegex.test(key) ||
  3532. (version !== 8 && version !== 13) ||
  3533. !this.shouldHandle(req)
  3534. ) {
  3535. return abortHandshake(socket, 400);
  3536. }
  3537. const secWebSocketProtocol = req.headers['sec-websocket-protocol'];
  3538. let protocols = new Set();
  3539. if (secWebSocketProtocol !== undefined) {
  3540. try {
  3541. protocols = subprotocol.parse(secWebSocketProtocol);
  3542. } catch (err) {
  3543. return abortHandshake(socket, 400);
  3544. }
  3545. }
  3546. const secWebSocketExtensions = req.headers['sec-websocket-extensions'];
  3547. const extensions = {};
  3548. if (
  3549. this.options.perMessageDeflate &&
  3550. secWebSocketExtensions !== undefined
  3551. ) {
  3552. const perMessageDeflate = new PerMessageDeflate(
  3553. this.options.perMessageDeflate,
  3554. true,
  3555. this.options.maxPayload
  3556. );
  3557. try {
  3558. const offers = extension.parse(secWebSocketExtensions);
  3559. if (offers[PerMessageDeflate.extensionName]) {
  3560. perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
  3561. extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
  3562. }
  3563. } catch (err) {
  3564. return abortHandshake(socket, 400);
  3565. }
  3566. }
  3567. //
  3568. // Optionally call external client verification handler.
  3569. //
  3570. if (this.options.verifyClient) {
  3571. const info = {
  3572. origin:
  3573. req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
  3574. secure: !!(req.socket.authorized || req.socket.encrypted),
  3575. req
  3576. };
  3577. if (this.options.verifyClient.length === 2) {
  3578. this.options.verifyClient(info, (verified, code, message, headers) => {
  3579. if (!verified) {
  3580. return abortHandshake(socket, code || 401, message, headers);
  3581. }
  3582. this.completeUpgrade(
  3583. extensions,
  3584. key,
  3585. protocols,
  3586. req,
  3587. socket,
  3588. head,
  3589. cb
  3590. );
  3591. });
  3592. return;
  3593. }
  3594. if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
  3595. }
  3596. this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
  3597. }
  3598. /**
  3599. * Upgrade the connection to WebSocket.
  3600. *
  3601. * @param {Object} extensions The accepted extensions
  3602. * @param {String} key The value of the `Sec-WebSocket-Key` header
  3603. * @param {Set} protocols The subprotocols
  3604. * @param {http.IncomingMessage} req The request object
  3605. * @param {(net.Socket|tls.Socket)} socket The network socket between the
  3606. * server and client
  3607. * @param {Buffer} head The first packet of the upgraded stream
  3608. * @param {Function} cb Callback
  3609. * @throws {Error} If called more than once with the same socket
  3610. * @private
  3611. */
  3612. completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
  3613. //
  3614. // Destroy the socket if the client has already sent a FIN packet.
  3615. //
  3616. if (!socket.readable || !socket.writable) return socket.destroy();
  3617. if (socket[kWebSocket]) {
  3618. throw new Error(
  3619. 'server.handleUpgrade() was called more than once with the same ' +
  3620. 'socket, possibly due to a misconfiguration'
  3621. );
  3622. }
  3623. if (this._state > RUNNING) return abortHandshake(socket, 503);
  3624. const digest = createHash('sha1')
  3625. .update(key + GUID)
  3626. .digest('base64');
  3627. const headers = [
  3628. 'HTTP/1.1 101 Switching Protocols',
  3629. 'Upgrade: websocket',
  3630. 'Connection: Upgrade',
  3631. `Sec-WebSocket-Accept: ${digest}`
  3632. ];
  3633. const ws = new WebSocket(null);
  3634. if (protocols.size) {
  3635. //
  3636. // Optionally call external protocol selection handler.
  3637. //
  3638. const protocol = this.options.handleProtocols
  3639. ? this.options.handleProtocols(protocols, req)
  3640. : protocols.values().next().value;
  3641. if (protocol) {
  3642. headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
  3643. ws._protocol = protocol;
  3644. }
  3645. }
  3646. if (extensions[PerMessageDeflate.extensionName]) {
  3647. const params = extensions[PerMessageDeflate.extensionName].params;
  3648. const value = extension.format({
  3649. [PerMessageDeflate.extensionName]: [params]
  3650. });
  3651. headers.push(`Sec-WebSocket-Extensions: ${value}`);
  3652. ws._extensions = extensions;
  3653. }
  3654. //
  3655. // Allow external modification/inspection of handshake headers.
  3656. //
  3657. this.emit('headers', headers, req);
  3658. socket.write(headers.concat('\r\n').join('\r\n'));
  3659. socket.removeListener('error', socketOnError);
  3660. ws.setSocket(socket, head, {
  3661. maxPayload: this.options.maxPayload,
  3662. skipUTF8Validation: this.options.skipUTF8Validation
  3663. });
  3664. if (this.clients) {
  3665. this.clients.add(ws);
  3666. ws.on('close', () => {
  3667. this.clients.delete(ws);
  3668. if (this._shouldEmitClose && !this.clients.size) {
  3669. process.nextTick(emitClose, this);
  3670. }
  3671. });
  3672. }
  3673. cb(ws, req);
  3674. }
  3675. }
  3676. module.exports = WebSocketServer;
  3677. /**
  3678. * Add event listeners on an `EventEmitter` using a map of <event, listener>
  3679. * pairs.
  3680. *
  3681. * @param {EventEmitter} server The event emitter
  3682. * @param {Object.<String, Function>} map The listeners to add
  3683. * @return {Function} A function that will remove the added listeners when
  3684. * called
  3685. * @private
  3686. */
  3687. function addListeners(server, map) {
  3688. for (const event of Object.keys(map)) server.on(event, map[event]);
  3689. return function removeListeners() {
  3690. for (const event of Object.keys(map)) {
  3691. server.removeListener(event, map[event]);
  3692. }
  3693. };
  3694. }
  3695. /**
  3696. * Emit a `'close'` event on an `EventEmitter`.
  3697. *
  3698. * @param {EventEmitter} server The event emitter
  3699. * @private
  3700. */
  3701. function emitClose(server) {
  3702. server._state = CLOSED;
  3703. server.emit('close');
  3704. }
  3705. /**
  3706. * Handle premature socket errors.
  3707. *
  3708. * @private
  3709. */
  3710. function socketOnError() {
  3711. this.destroy();
  3712. }
  3713. /**
  3714. * Close the connection when preconditions are not fulfilled.
  3715. *
  3716. * @param {(net.Socket|tls.Socket)} socket The socket of the upgrade request
  3717. * @param {Number} code The HTTP response status code
  3718. * @param {String} [message] The HTTP response body
  3719. * @param {Object} [headers] Additional HTTP response headers
  3720. * @private
  3721. */
  3722. function abortHandshake(socket, code, message, headers) {
  3723. if (socket.writable) {
  3724. message = message || http.STATUS_CODES[code];
  3725. headers = {
  3726. Connection: 'close',
  3727. 'Content-Type': 'text/html',
  3728. 'Content-Length': Buffer.byteLength(message),
  3729. ...headers
  3730. };
  3731. socket.write(
  3732. `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
  3733. Object.keys(headers)
  3734. .map((h) => `${h}: ${headers[h]}`)
  3735. .join('\r\n') +
  3736. '\r\n\r\n' +
  3737. message
  3738. );
  3739. }
  3740. socket.removeListener('error', socketOnError);
  3741. socket.destroy();
  3742. }
  3743. /***/ }),
  3744. /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js":
  3745. /*!*********************************************************************************!*\
  3746. !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js ***!
  3747. \*********************************************************************************/
  3748. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  3749. "use strict";
  3750. /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Readable$" }] */
  3751. const EventEmitter = __webpack_require__(/*! events */ "events");
  3752. const https = __webpack_require__(/*! https */ "https");
  3753. const http = __webpack_require__(/*! http */ "http");
  3754. const net = __webpack_require__(/*! net */ "net");
  3755. const tls = __webpack_require__(/*! tls */ "tls");
  3756. const { randomBytes, createHash } = __webpack_require__(/*! crypto */ "crypto");
  3757. const { Readable } = __webpack_require__(/*! stream */ "stream");
  3758. const { URL } = __webpack_require__(/*! url */ "url");
  3759. const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
  3760. const Receiver = __webpack_require__(/*! ./receiver */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js");
  3761. const Sender = __webpack_require__(/*! ./sender */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js");
  3762. const {
  3763. BINARY_TYPES,
  3764. EMPTY_BUFFER,
  3765. GUID,
  3766. kForOnEventAttribute,
  3767. kListener,
  3768. kStatusCode,
  3769. kWebSocket,
  3770. NOOP
  3771. } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
  3772. const {
  3773. EventTarget: { addEventListener, removeEventListener }
  3774. } = __webpack_require__(/*! ./event-target */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/event-target.js");
  3775. const { format, parse } = __webpack_require__(/*! ./extension */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js");
  3776. const { toBuffer } = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
  3777. const readyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
  3778. const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
  3779. const protocolVersions = [8, 13];
  3780. const closeTimeout = 30 * 1000;
  3781. /**
  3782. * Class representing a WebSocket.
  3783. *
  3784. * @extends EventEmitter
  3785. */
  3786. class WebSocket extends EventEmitter {
  3787. /**
  3788. * Create a new `WebSocket`.
  3789. *
  3790. * @param {(String|URL)} address The URL to which to connect
  3791. * @param {(String|String[])} [protocols] The subprotocols
  3792. * @param {Object} [options] Connection options
  3793. */
  3794. constructor(address, protocols, options) {
  3795. super();
  3796. this._binaryType = BINARY_TYPES[0];
  3797. this._closeCode = 1006;
  3798. this._closeFrameReceived = false;
  3799. this._closeFrameSent = false;
  3800. this._closeMessage = EMPTY_BUFFER;
  3801. this._closeTimer = null;
  3802. this._extensions = {};
  3803. this._protocol = '';
  3804. this._readyState = WebSocket.CONNECTING;
  3805. this._receiver = null;
  3806. this._sender = null;
  3807. this._socket = null;
  3808. if (address !== null) {
  3809. this._bufferedAmount = 0;
  3810. this._isServer = false;
  3811. this._redirects = 0;
  3812. if (protocols === undefined) {
  3813. protocols = [];
  3814. } else if (!Array.isArray(protocols)) {
  3815. if (typeof protocols === 'object' && protocols !== null) {
  3816. options = protocols;
  3817. protocols = [];
  3818. } else {
  3819. protocols = [protocols];
  3820. }
  3821. }
  3822. initAsClient(this, address, protocols, options);
  3823. } else {
  3824. this._isServer = true;
  3825. }
  3826. }
  3827. /**
  3828. * This deviates from the WHATWG interface since ws doesn't support the
  3829. * required default "blob" type (instead we define a custom "nodebuffer"
  3830. * type).
  3831. *
  3832. * @type {String}
  3833. */
  3834. get binaryType() {
  3835. return this._binaryType;
  3836. }
  3837. set binaryType(type) {
  3838. if (!BINARY_TYPES.includes(type)) return;
  3839. this._binaryType = type;
  3840. //
  3841. // Allow to change `binaryType` on the fly.
  3842. //
  3843. if (this._receiver) this._receiver._binaryType = type;
  3844. }
  3845. /**
  3846. * @type {Number}
  3847. */
  3848. get bufferedAmount() {
  3849. if (!this._socket) return this._bufferedAmount;
  3850. return this._socket._writableState.length + this._sender._bufferedBytes;
  3851. }
  3852. /**
  3853. * @type {String}
  3854. */
  3855. get extensions() {
  3856. return Object.keys(this._extensions).join();
  3857. }
  3858. /**
  3859. * @type {Function}
  3860. */
  3861. /* istanbul ignore next */
  3862. get onclose() {
  3863. return null;
  3864. }
  3865. /**
  3866. * @type {Function}
  3867. */
  3868. /* istanbul ignore next */
  3869. get onerror() {
  3870. return null;
  3871. }
  3872. /**
  3873. * @type {Function}
  3874. */
  3875. /* istanbul ignore next */
  3876. get onopen() {
  3877. return null;
  3878. }
  3879. /**
  3880. * @type {Function}
  3881. */
  3882. /* istanbul ignore next */
  3883. get onmessage() {
  3884. return null;
  3885. }
  3886. /**
  3887. * @type {String}
  3888. */
  3889. get protocol() {
  3890. return this._protocol;
  3891. }
  3892. /**
  3893. * @type {Number}
  3894. */
  3895. get readyState() {
  3896. return this._readyState;
  3897. }
  3898. /**
  3899. * @type {String}
  3900. */
  3901. get url() {
  3902. return this._url;
  3903. }
  3904. /**
  3905. * Set up the socket and the internal resources.
  3906. *
  3907. * @param {(net.Socket|tls.Socket)} socket The network socket between the
  3908. * server and client
  3909. * @param {Buffer} head The first packet of the upgraded stream
  3910. * @param {Object} options Options object
  3911. * @param {Number} [options.maxPayload=0] The maximum allowed message size
  3912. * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
  3913. * not to skip UTF-8 validation for text and close messages
  3914. * @private
  3915. */
  3916. setSocket(socket, head, options) {
  3917. const receiver = new Receiver({
  3918. binaryType: this.binaryType,
  3919. extensions: this._extensions,
  3920. isServer: this._isServer,
  3921. maxPayload: options.maxPayload,
  3922. skipUTF8Validation: options.skipUTF8Validation
  3923. });
  3924. this._sender = new Sender(socket, this._extensions);
  3925. this._receiver = receiver;
  3926. this._socket = socket;
  3927. receiver[kWebSocket] = this;
  3928. socket[kWebSocket] = this;
  3929. receiver.on('conclude', receiverOnConclude);
  3930. receiver.on('drain', receiverOnDrain);
  3931. receiver.on('error', receiverOnError);
  3932. receiver.on('message', receiverOnMessage);
  3933. receiver.on('ping', receiverOnPing);
  3934. receiver.on('pong', receiverOnPong);
  3935. socket.setTimeout(0);
  3936. socket.setNoDelay();
  3937. if (head.length > 0) socket.unshift(head);
  3938. socket.on('close', socketOnClose);
  3939. socket.on('data', socketOnData);
  3940. socket.on('end', socketOnEnd);
  3941. socket.on('error', socketOnError);
  3942. this._readyState = WebSocket.OPEN;
  3943. this.emit('open');
  3944. }
  3945. /**
  3946. * Emit the `'close'` event.
  3947. *
  3948. * @private
  3949. */
  3950. emitClose() {
  3951. if (!this._socket) {
  3952. this._readyState = WebSocket.CLOSED;
  3953. this.emit('close', this._closeCode, this._closeMessage);
  3954. return;
  3955. }
  3956. if (this._extensions[PerMessageDeflate.extensionName]) {
  3957. this._extensions[PerMessageDeflate.extensionName].cleanup();
  3958. }
  3959. this._receiver.removeAllListeners();
  3960. this._readyState = WebSocket.CLOSED;
  3961. this.emit('close', this._closeCode, this._closeMessage);
  3962. }
  3963. /**
  3964. * Start a closing handshake.
  3965. *
  3966. * +----------+ +-----------+ +----------+
  3967. * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
  3968. * | +----------+ +-----------+ +----------+ |
  3969. * +----------+ +-----------+ |
  3970. * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
  3971. * +----------+ +-----------+ |
  3972. * | | | +---+ |
  3973. * +------------------------+-->|fin| - - - -
  3974. * | +---+ | +---+
  3975. * - - - - -|fin|<---------------------+
  3976. * +---+
  3977. *
  3978. * @param {Number} [code] Status code explaining why the connection is closing
  3979. * @param {(String|Buffer)} [data] The reason why the connection is
  3980. * closing
  3981. * @public
  3982. */
  3983. close(code, data) {
  3984. if (this.readyState === WebSocket.CLOSED) return;
  3985. if (this.readyState === WebSocket.CONNECTING) {
  3986. const msg = 'WebSocket was closed before the connection was established';
  3987. return abortHandshake(this, this._req, msg);
  3988. }
  3989. if (this.readyState === WebSocket.CLOSING) {
  3990. if (
  3991. this._closeFrameSent &&
  3992. (this._closeFrameReceived || this._receiver._writableState.errorEmitted)
  3993. ) {
  3994. this._socket.end();
  3995. }
  3996. return;
  3997. }
  3998. this._readyState = WebSocket.CLOSING;
  3999. this._sender.close(code, data, !this._isServer, (err) => {
  4000. //
  4001. // This error is handled by the `'error'` listener on the socket. We only
  4002. // want to know if the close frame has been sent here.
  4003. //
  4004. if (err) return;
  4005. this._closeFrameSent = true;
  4006. if (
  4007. this._closeFrameReceived ||
  4008. this._receiver._writableState.errorEmitted
  4009. ) {
  4010. this._socket.end();
  4011. }
  4012. });
  4013. //
  4014. // Specify a timeout for the closing handshake to complete.
  4015. //
  4016. this._closeTimer = setTimeout(
  4017. this._socket.destroy.bind(this._socket),
  4018. closeTimeout
  4019. );
  4020. }
  4021. /**
  4022. * Send a ping.
  4023. *
  4024. * @param {*} [data] The data to send
  4025. * @param {Boolean} [mask] Indicates whether or not to mask `data`
  4026. * @param {Function} [cb] Callback which is executed when the ping is sent
  4027. * @public
  4028. */
  4029. ping(data, mask, cb) {
  4030. if (this.readyState === WebSocket.CONNECTING) {
  4031. throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
  4032. }
  4033. if (typeof data === 'function') {
  4034. cb = data;
  4035. data = mask = undefined;
  4036. } else if (typeof mask === 'function') {
  4037. cb = mask;
  4038. mask = undefined;
  4039. }
  4040. if (typeof data === 'number') data = data.toString();
  4041. if (this.readyState !== WebSocket.OPEN) {
  4042. sendAfterClose(this, data, cb);
  4043. return;
  4044. }
  4045. if (mask === undefined) mask = !this._isServer;
  4046. this._sender.ping(data || EMPTY_BUFFER, mask, cb);
  4047. }
  4048. /**
  4049. * Send a pong.
  4050. *
  4051. * @param {*} [data] The data to send
  4052. * @param {Boolean} [mask] Indicates whether or not to mask `data`
  4053. * @param {Function} [cb] Callback which is executed when the pong is sent
  4054. * @public
  4055. */
  4056. pong(data, mask, cb) {
  4057. if (this.readyState === WebSocket.CONNECTING) {
  4058. throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
  4059. }
  4060. if (typeof data === 'function') {
  4061. cb = data;
  4062. data = mask = undefined;
  4063. } else if (typeof mask === 'function') {
  4064. cb = mask;
  4065. mask = undefined;
  4066. }
  4067. if (typeof data === 'number') data = data.toString();
  4068. if (this.readyState !== WebSocket.OPEN) {
  4069. sendAfterClose(this, data, cb);
  4070. return;
  4071. }
  4072. if (mask === undefined) mask = !this._isServer;
  4073. this._sender.pong(data || EMPTY_BUFFER, mask, cb);
  4074. }
  4075. /**
  4076. * Send a data message.
  4077. *
  4078. * @param {*} data The message to send
  4079. * @param {Object} [options] Options object
  4080. * @param {Boolean} [options.binary] Specifies whether `data` is binary or
  4081. * text
  4082. * @param {Boolean} [options.compress] Specifies whether or not to compress
  4083. * `data`
  4084. * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
  4085. * last one
  4086. * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
  4087. * @param {Function} [cb] Callback which is executed when data is written out
  4088. * @public
  4089. */
  4090. send(data, options, cb) {
  4091. if (this.readyState === WebSocket.CONNECTING) {
  4092. throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
  4093. }
  4094. if (typeof options === 'function') {
  4095. cb = options;
  4096. options = {};
  4097. }
  4098. if (typeof data === 'number') data = data.toString();
  4099. if (this.readyState !== WebSocket.OPEN) {
  4100. sendAfterClose(this, data, cb);
  4101. return;
  4102. }
  4103. const opts = {
  4104. binary: typeof data !== 'string',
  4105. mask: !this._isServer,
  4106. compress: true,
  4107. fin: true,
  4108. ...options
  4109. };
  4110. if (!this._extensions[PerMessageDeflate.extensionName]) {
  4111. opts.compress = false;
  4112. }
  4113. this._sender.send(data || EMPTY_BUFFER, opts, cb);
  4114. }
  4115. /**
  4116. * Forcibly close the connection.
  4117. *
  4118. * @public
  4119. */
  4120. terminate() {
  4121. if (this.readyState === WebSocket.CLOSED) return;
  4122. if (this.readyState === WebSocket.CONNECTING) {
  4123. const msg = 'WebSocket was closed before the connection was established';
  4124. return abortHandshake(this, this._req, msg);
  4125. }
  4126. if (this._socket) {
  4127. this._readyState = WebSocket.CLOSING;
  4128. this._socket.destroy();
  4129. }
  4130. }
  4131. }
  4132. /**
  4133. * @constant {Number} CONNECTING
  4134. * @memberof WebSocket
  4135. */
  4136. Object.defineProperty(WebSocket, 'CONNECTING', {
  4137. enumerable: true,
  4138. value: readyStates.indexOf('CONNECTING')
  4139. });
  4140. /**
  4141. * @constant {Number} CONNECTING
  4142. * @memberof WebSocket.prototype
  4143. */
  4144. Object.defineProperty(WebSocket.prototype, 'CONNECTING', {
  4145. enumerable: true,
  4146. value: readyStates.indexOf('CONNECTING')
  4147. });
  4148. /**
  4149. * @constant {Number} OPEN
  4150. * @memberof WebSocket
  4151. */
  4152. Object.defineProperty(WebSocket, 'OPEN', {
  4153. enumerable: true,
  4154. value: readyStates.indexOf('OPEN')
  4155. });
  4156. /**
  4157. * @constant {Number} OPEN
  4158. * @memberof WebSocket.prototype
  4159. */
  4160. Object.defineProperty(WebSocket.prototype, 'OPEN', {
  4161. enumerable: true,
  4162. value: readyStates.indexOf('OPEN')
  4163. });
  4164. /**
  4165. * @constant {Number} CLOSING
  4166. * @memberof WebSocket
  4167. */
  4168. Object.defineProperty(WebSocket, 'CLOSING', {
  4169. enumerable: true,
  4170. value: readyStates.indexOf('CLOSING')
  4171. });
  4172. /**
  4173. * @constant {Number} CLOSING
  4174. * @memberof WebSocket.prototype
  4175. */
  4176. Object.defineProperty(WebSocket.prototype, 'CLOSING', {
  4177. enumerable: true,
  4178. value: readyStates.indexOf('CLOSING')
  4179. });
  4180. /**
  4181. * @constant {Number} CLOSED
  4182. * @memberof WebSocket
  4183. */
  4184. Object.defineProperty(WebSocket, 'CLOSED', {
  4185. enumerable: true,
  4186. value: readyStates.indexOf('CLOSED')
  4187. });
  4188. /**
  4189. * @constant {Number} CLOSED
  4190. * @memberof WebSocket.prototype
  4191. */
  4192. Object.defineProperty(WebSocket.prototype, 'CLOSED', {
  4193. enumerable: true,
  4194. value: readyStates.indexOf('CLOSED')
  4195. });
  4196. [
  4197. 'binaryType',
  4198. 'bufferedAmount',
  4199. 'extensions',
  4200. 'protocol',
  4201. 'readyState',
  4202. 'url'
  4203. ].forEach((property) => {
  4204. Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
  4205. });
  4206. //
  4207. // Add the `onopen`, `onerror`, `onclose`, and `onmessage` attributes.
  4208. // See https://html.spec.whatwg.org/multipage/comms.html#the-websocket-interface
  4209. //
  4210. ['open', 'error', 'close', 'message'].forEach((method) => {
  4211. Object.defineProperty(WebSocket.prototype, `on${method}`, {
  4212. enumerable: true,
  4213. get() {
  4214. for (const listener of this.listeners(method)) {
  4215. if (listener[kForOnEventAttribute]) return listener[kListener];
  4216. }
  4217. return null;
  4218. },
  4219. set(handler) {
  4220. for (const listener of this.listeners(method)) {
  4221. if (listener[kForOnEventAttribute]) {
  4222. this.removeListener(method, listener);
  4223. break;
  4224. }
  4225. }
  4226. if (typeof handler !== 'function') return;
  4227. this.addEventListener(method, handler, {
  4228. [kForOnEventAttribute]: true
  4229. });
  4230. }
  4231. });
  4232. });
  4233. WebSocket.prototype.addEventListener = addEventListener;
  4234. WebSocket.prototype.removeEventListener = removeEventListener;
  4235. module.exports = WebSocket;
  4236. /**
  4237. * Initialize a WebSocket client.
  4238. *
  4239. * @param {WebSocket} websocket The client to initialize
  4240. * @param {(String|URL)} address The URL to which to connect
  4241. * @param {Array} protocols The subprotocols
  4242. * @param {Object} [options] Connection options
  4243. * @param {Boolean} [options.followRedirects=false] Whether or not to follow
  4244. * redirects
  4245. * @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
  4246. * handshake request
  4247. * @param {Number} [options.maxPayload=104857600] The maximum allowed message
  4248. * size
  4249. * @param {Number} [options.maxRedirects=10] The maximum number of redirects
  4250. * allowed
  4251. * @param {String} [options.origin] Value of the `Origin` or
  4252. * `Sec-WebSocket-Origin` header
  4253. * @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
  4254. * permessage-deflate
  4255. * @param {Number} [options.protocolVersion=13] Value of the
  4256. * `Sec-WebSocket-Version` header
  4257. * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
  4258. * not to skip UTF-8 validation for text and close messages
  4259. * @private
  4260. */
  4261. function initAsClient(websocket, address, protocols, options) {
  4262. const opts = {
  4263. protocolVersion: protocolVersions[1],
  4264. maxPayload: 100 * 1024 * 1024,
  4265. skipUTF8Validation: false,
  4266. perMessageDeflate: true,
  4267. followRedirects: false,
  4268. maxRedirects: 10,
  4269. ...options,
  4270. createConnection: undefined,
  4271. socketPath: undefined,
  4272. hostname: undefined,
  4273. protocol: undefined,
  4274. timeout: undefined,
  4275. method: undefined,
  4276. host: undefined,
  4277. path: undefined,
  4278. port: undefined
  4279. };
  4280. if (!protocolVersions.includes(opts.protocolVersion)) {
  4281. throw new RangeError(
  4282. `Unsupported protocol version: ${opts.protocolVersion} ` +
  4283. `(supported versions: ${protocolVersions.join(', ')})`
  4284. );
  4285. }
  4286. let parsedUrl;
  4287. if (address instanceof URL) {
  4288. parsedUrl = address;
  4289. websocket._url = address.href;
  4290. } else {
  4291. try {
  4292. parsedUrl = new URL(address);
  4293. } catch (e) {
  4294. throw new SyntaxError(`Invalid URL: ${address}`);
  4295. }
  4296. websocket._url = address;
  4297. }
  4298. const isSecure = parsedUrl.protocol === 'wss:';
  4299. const isUnixSocket = parsedUrl.protocol === 'ws+unix:';
  4300. if (parsedUrl.protocol !== 'ws:' && !isSecure && !isUnixSocket) {
  4301. throw new SyntaxError(
  4302. 'The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"'
  4303. );
  4304. }
  4305. if (isUnixSocket && !parsedUrl.pathname) {
  4306. throw new SyntaxError("The URL's pathname is empty");
  4307. }
  4308. if (parsedUrl.hash) {
  4309. throw new SyntaxError('The URL contains a fragment identifier');
  4310. }
  4311. const defaultPort = isSecure ? 443 : 80;
  4312. const key = randomBytes(16).toString('base64');
  4313. const get = isSecure ? https.get : http.get;
  4314. const protocolSet = new Set();
  4315. let perMessageDeflate;
  4316. opts.createConnection = isSecure ? tlsConnect : netConnect;
  4317. opts.defaultPort = opts.defaultPort || defaultPort;
  4318. opts.port = parsedUrl.port || defaultPort;
  4319. opts.host = parsedUrl.hostname.startsWith('[')
  4320. ? parsedUrl.hostname.slice(1, -1)
  4321. : parsedUrl.hostname;
  4322. opts.headers = {
  4323. 'Sec-WebSocket-Version': opts.protocolVersion,
  4324. 'Sec-WebSocket-Key': key,
  4325. Connection: 'Upgrade',
  4326. Upgrade: 'websocket',
  4327. ...opts.headers
  4328. };
  4329. opts.path = parsedUrl.pathname + parsedUrl.search;
  4330. opts.timeout = opts.handshakeTimeout;
  4331. if (opts.perMessageDeflate) {
  4332. perMessageDeflate = new PerMessageDeflate(
  4333. opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
  4334. false,
  4335. opts.maxPayload
  4336. );
  4337. opts.headers['Sec-WebSocket-Extensions'] = format({
  4338. [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
  4339. });
  4340. }
  4341. if (protocols.length) {
  4342. for (const protocol of protocols) {
  4343. if (
  4344. typeof protocol !== 'string' ||
  4345. !subprotocolRegex.test(protocol) ||
  4346. protocolSet.has(protocol)
  4347. ) {
  4348. throw new SyntaxError(
  4349. 'An invalid or duplicated subprotocol was specified'
  4350. );
  4351. }
  4352. protocolSet.add(protocol);
  4353. }
  4354. opts.headers['Sec-WebSocket-Protocol'] = protocols.join(',');
  4355. }
  4356. if (opts.origin) {
  4357. if (opts.protocolVersion < 13) {
  4358. opts.headers['Sec-WebSocket-Origin'] = opts.origin;
  4359. } else {
  4360. opts.headers.Origin = opts.origin;
  4361. }
  4362. }
  4363. if (parsedUrl.username || parsedUrl.password) {
  4364. opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
  4365. }
  4366. if (isUnixSocket) {
  4367. const parts = opts.path.split(':');
  4368. opts.socketPath = parts[0];
  4369. opts.path = parts[1];
  4370. }
  4371. let req = (websocket._req = get(opts));
  4372. if (opts.timeout) {
  4373. req.on('timeout', () => {
  4374. abortHandshake(websocket, req, 'Opening handshake has timed out');
  4375. });
  4376. }
  4377. req.on('error', (err) => {
  4378. if (req === null || req.aborted) return;
  4379. req = websocket._req = null;
  4380. websocket._readyState = WebSocket.CLOSING;
  4381. websocket.emit('error', err);
  4382. websocket.emitClose();
  4383. });
  4384. req.on('response', (res) => {
  4385. const location = res.headers.location;
  4386. const statusCode = res.statusCode;
  4387. if (
  4388. location &&
  4389. opts.followRedirects &&
  4390. statusCode >= 300 &&
  4391. statusCode < 400
  4392. ) {
  4393. if (++websocket._redirects > opts.maxRedirects) {
  4394. abortHandshake(websocket, req, 'Maximum redirects exceeded');
  4395. return;
  4396. }
  4397. req.abort();
  4398. const addr = new URL(location, address);
  4399. initAsClient(websocket, addr, protocols, options);
  4400. } else if (!websocket.emit('unexpected-response', req, res)) {
  4401. abortHandshake(
  4402. websocket,
  4403. req,
  4404. `Unexpected server response: ${res.statusCode}`
  4405. );
  4406. }
  4407. });
  4408. req.on('upgrade', (res, socket, head) => {
  4409. websocket.emit('upgrade', res);
  4410. //
  4411. // The user may have closed the connection from a listener of the `upgrade`
  4412. // event.
  4413. //
  4414. if (websocket.readyState !== WebSocket.CONNECTING) return;
  4415. req = websocket._req = null;
  4416. const digest = createHash('sha1')
  4417. .update(key + GUID)
  4418. .digest('base64');
  4419. if (res.headers['sec-websocket-accept'] !== digest) {
  4420. abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
  4421. return;
  4422. }
  4423. const serverProt = res.headers['sec-websocket-protocol'];
  4424. let protError;
  4425. if (serverProt !== undefined) {
  4426. if (!protocolSet.size) {
  4427. protError = 'Server sent a subprotocol but none was requested';
  4428. } else if (!protocolSet.has(serverProt)) {
  4429. protError = 'Server sent an invalid subprotocol';
  4430. }
  4431. } else if (protocolSet.size) {
  4432. protError = 'Server sent no subprotocol';
  4433. }
  4434. if (protError) {
  4435. abortHandshake(websocket, socket, protError);
  4436. return;
  4437. }
  4438. if (serverProt) websocket._protocol = serverProt;
  4439. const secWebSocketExtensions = res.headers['sec-websocket-extensions'];
  4440. if (secWebSocketExtensions !== undefined) {
  4441. if (!perMessageDeflate) {
  4442. const message =
  4443. 'Server sent a Sec-WebSocket-Extensions header but no extension ' +
  4444. 'was requested';
  4445. abortHandshake(websocket, socket, message);
  4446. return;
  4447. }
  4448. let extensions;
  4449. try {
  4450. extensions = parse(secWebSocketExtensions);
  4451. } catch (err) {
  4452. const message = 'Invalid Sec-WebSocket-Extensions header';
  4453. abortHandshake(websocket, socket, message);
  4454. return;
  4455. }
  4456. const extensionNames = Object.keys(extensions);
  4457. if (
  4458. extensionNames.length !== 1 ||
  4459. extensionNames[0] !== PerMessageDeflate.extensionName
  4460. ) {
  4461. const message = 'Server indicated an extension that was not requested';
  4462. abortHandshake(websocket, socket, message);
  4463. return;
  4464. }
  4465. try {
  4466. perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
  4467. } catch (err) {
  4468. const message = 'Invalid Sec-WebSocket-Extensions header';
  4469. abortHandshake(websocket, socket, message);
  4470. return;
  4471. }
  4472. websocket._extensions[PerMessageDeflate.extensionName] =
  4473. perMessageDeflate;
  4474. }
  4475. websocket.setSocket(socket, head, {
  4476. maxPayload: opts.maxPayload,
  4477. skipUTF8Validation: opts.skipUTF8Validation
  4478. });
  4479. });
  4480. }
  4481. /**
  4482. * Create a `net.Socket` and initiate a connection.
  4483. *
  4484. * @param {Object} options Connection options
  4485. * @return {net.Socket} The newly created socket used to start the connection
  4486. * @private
  4487. */
  4488. function netConnect(options) {
  4489. options.path = options.socketPath;
  4490. return net.connect(options);
  4491. }
  4492. /**
  4493. * Create a `tls.TLSSocket` and initiate a connection.
  4494. *
  4495. * @param {Object} options Connection options
  4496. * @return {tls.TLSSocket} The newly created socket used to start the connection
  4497. * @private
  4498. */
  4499. function tlsConnect(options) {
  4500. options.path = undefined;
  4501. if (!options.servername && options.servername !== '') {
  4502. options.servername = net.isIP(options.host) ? '' : options.host;
  4503. }
  4504. return tls.connect(options);
  4505. }
  4506. /**
  4507. * Abort the handshake and emit an error.
  4508. *
  4509. * @param {WebSocket} websocket The WebSocket instance
  4510. * @param {(http.ClientRequest|net.Socket|tls.Socket)} stream The request to
  4511. * abort or the socket to destroy
  4512. * @param {String} message The error message
  4513. * @private
  4514. */
  4515. function abortHandshake(websocket, stream, message) {
  4516. websocket._readyState = WebSocket.CLOSING;
  4517. const err = new Error(message);
  4518. Error.captureStackTrace(err, abortHandshake);
  4519. if (stream.setHeader) {
  4520. stream.abort();
  4521. if (stream.socket && !stream.socket.destroyed) {
  4522. //
  4523. // On Node.js >= 14.3.0 `request.abort()` does not destroy the socket if
  4524. // called after the request completed. See
  4525. // https://github.com/websockets/ws/issues/1869.
  4526. //
  4527. stream.socket.destroy();
  4528. }
  4529. stream.once('abort', websocket.emitClose.bind(websocket));
  4530. websocket.emit('error', err);
  4531. } else {
  4532. stream.destroy(err);
  4533. stream.once('error', websocket.emit.bind(websocket, 'error'));
  4534. stream.once('close', websocket.emitClose.bind(websocket));
  4535. }
  4536. }
  4537. /**
  4538. * Handle cases where the `ping()`, `pong()`, or `send()` methods are called
  4539. * when the `readyState` attribute is `CLOSING` or `CLOSED`.
  4540. *
  4541. * @param {WebSocket} websocket The WebSocket instance
  4542. * @param {*} [data] The data to send
  4543. * @param {Function} [cb] Callback
  4544. * @private
  4545. */
  4546. function sendAfterClose(websocket, data, cb) {
  4547. if (data) {
  4548. const length = toBuffer(data).length;
  4549. //
  4550. // The `_bufferedAmount` property is used only when the peer is a client and
  4551. // the opening handshake fails. Under these circumstances, in fact, the
  4552. // `setSocket()` method is not called, so the `_socket` and `_sender`
  4553. // properties are set to `null`.
  4554. //
  4555. if (websocket._socket) websocket._sender._bufferedBytes += length;
  4556. else websocket._bufferedAmount += length;
  4557. }
  4558. if (cb) {
  4559. const err = new Error(
  4560. `WebSocket is not open: readyState ${websocket.readyState} ` +
  4561. `(${readyStates[websocket.readyState]})`
  4562. );
  4563. cb(err);
  4564. }
  4565. }
  4566. /**
  4567. * The listener of the `Receiver` `'conclude'` event.
  4568. *
  4569. * @param {Number} code The status code
  4570. * @param {Buffer} reason The reason for closing
  4571. * @private
  4572. */
  4573. function receiverOnConclude(code, reason) {
  4574. const websocket = this[kWebSocket];
  4575. websocket._closeFrameReceived = true;
  4576. websocket._closeMessage = reason;
  4577. websocket._closeCode = code;
  4578. if (websocket._socket[kWebSocket] === undefined) return;
  4579. websocket._socket.removeListener('data', socketOnData);
  4580. process.nextTick(resume, websocket._socket);
  4581. if (code === 1005) websocket.close();
  4582. else websocket.close(code, reason);
  4583. }
  4584. /**
  4585. * The listener of the `Receiver` `'drain'` event.
  4586. *
  4587. * @private
  4588. */
  4589. function receiverOnDrain() {
  4590. this[kWebSocket]._socket.resume();
  4591. }
  4592. /**
  4593. * The listener of the `Receiver` `'error'` event.
  4594. *
  4595. * @param {(RangeError|Error)} err The emitted error
  4596. * @private
  4597. */
  4598. function receiverOnError(err) {
  4599. const websocket = this[kWebSocket];
  4600. if (websocket._socket[kWebSocket] !== undefined) {
  4601. websocket._socket.removeListener('data', socketOnData);
  4602. //
  4603. // On Node.js < 14.0.0 the `'error'` event is emitted synchronously. See
  4604. // https://github.com/websockets/ws/issues/1940.
  4605. //
  4606. process.nextTick(resume, websocket._socket);
  4607. websocket.close(err[kStatusCode]);
  4608. }
  4609. websocket.emit('error', err);
  4610. }
  4611. /**
  4612. * The listener of the `Receiver` `'finish'` event.
  4613. *
  4614. * @private
  4615. */
  4616. function receiverOnFinish() {
  4617. this[kWebSocket].emitClose();
  4618. }
  4619. /**
  4620. * The listener of the `Receiver` `'message'` event.
  4621. *
  4622. * @param {Buffer|ArrayBuffer|Buffer[])} data The message
  4623. * @param {Boolean} isBinary Specifies whether the message is binary or not
  4624. * @private
  4625. */
  4626. function receiverOnMessage(data, isBinary) {
  4627. this[kWebSocket].emit('message', data, isBinary);
  4628. }
  4629. /**
  4630. * The listener of the `Receiver` `'ping'` event.
  4631. *
  4632. * @param {Buffer} data The data included in the ping frame
  4633. * @private
  4634. */
  4635. function receiverOnPing(data) {
  4636. const websocket = this[kWebSocket];
  4637. websocket.pong(data, !websocket._isServer, NOOP);
  4638. websocket.emit('ping', data);
  4639. }
  4640. /**
  4641. * The listener of the `Receiver` `'pong'` event.
  4642. *
  4643. * @param {Buffer} data The data included in the pong frame
  4644. * @private
  4645. */
  4646. function receiverOnPong(data) {
  4647. this[kWebSocket].emit('pong', data);
  4648. }
  4649. /**
  4650. * Resume a readable stream
  4651. *
  4652. * @param {Readable} stream The readable stream
  4653. * @private
  4654. */
  4655. function resume(stream) {
  4656. stream.resume();
  4657. }
  4658. /**
  4659. * The listener of the `net.Socket` `'close'` event.
  4660. *
  4661. * @private
  4662. */
  4663. function socketOnClose() {
  4664. const websocket = this[kWebSocket];
  4665. this.removeListener('close', socketOnClose);
  4666. this.removeListener('data', socketOnData);
  4667. this.removeListener('end', socketOnEnd);
  4668. websocket._readyState = WebSocket.CLOSING;
  4669. let chunk;
  4670. //
  4671. // The close frame might not have been received or the `'end'` event emitted,
  4672. // for example, if the socket was destroyed due to an error. Ensure that the
  4673. // `receiver` stream is closed after writing any remaining buffered data to
  4674. // it. If the readable side of the socket is in flowing mode then there is no
  4675. // buffered data as everything has been already written and `readable.read()`
  4676. // will return `null`. If instead, the socket is paused, any possible buffered
  4677. // data will be read as a single chunk.
  4678. //
  4679. if (
  4680. !this._readableState.endEmitted &&
  4681. !websocket._closeFrameReceived &&
  4682. !websocket._receiver._writableState.errorEmitted &&
  4683. (chunk = websocket._socket.read()) !== null
  4684. ) {
  4685. websocket._receiver.write(chunk);
  4686. }
  4687. websocket._receiver.end();
  4688. this[kWebSocket] = undefined;
  4689. clearTimeout(websocket._closeTimer);
  4690. if (
  4691. websocket._receiver._writableState.finished ||
  4692. websocket._receiver._writableState.errorEmitted
  4693. ) {
  4694. websocket.emitClose();
  4695. } else {
  4696. websocket._receiver.on('error', receiverOnFinish);
  4697. websocket._receiver.on('finish', receiverOnFinish);
  4698. }
  4699. }
  4700. /**
  4701. * The listener of the `net.Socket` `'data'` event.
  4702. *
  4703. * @param {Buffer} chunk A chunk of data
  4704. * @private
  4705. */
  4706. function socketOnData(chunk) {
  4707. if (!this[kWebSocket]._receiver.write(chunk)) {
  4708. this.pause();
  4709. }
  4710. }
  4711. /**
  4712. * The listener of the `net.Socket` `'end'` event.
  4713. *
  4714. * @private
  4715. */
  4716. function socketOnEnd() {
  4717. const websocket = this[kWebSocket];
  4718. websocket._readyState = WebSocket.CLOSING;
  4719. websocket._receiver.end();
  4720. this.end();
  4721. }
  4722. /**
  4723. * The listener of the `net.Socket` `'error'` event.
  4724. *
  4725. * @private
  4726. */
  4727. function socketOnError() {
  4728. const websocket = this[kWebSocket];
  4729. this.removeListener('error', socketOnError);
  4730. this.on('error', NOOP);
  4731. if (websocket) {
  4732. websocket._readyState = WebSocket.CLOSING;
  4733. this.destroy();
  4734. }
  4735. }
  4736. /***/ }),
  4737. /***/ "../ot-core/node_modules/has-flag/index.js":
  4738. /*!*************************************************!*\
  4739. !*** ../ot-core/node_modules/has-flag/index.js ***!
  4740. \*************************************************/
  4741. /***/ ((module) => {
  4742. "use strict";
  4743. module.exports = (flag, argv) => {
  4744. argv = argv || process.argv;
  4745. const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
  4746. const pos = argv.indexOf(prefix + flag);
  4747. const terminatorPos = argv.indexOf('--');
  4748. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  4749. };
  4750. /***/ }),
  4751. /***/ "../ot-core/node_modules/ms/index.js":
  4752. /*!*******************************************!*\
  4753. !*** ../ot-core/node_modules/ms/index.js ***!
  4754. \*******************************************/
  4755. /***/ ((module) => {
  4756. /**
  4757. * Helpers.
  4758. */
  4759. var s = 1000;
  4760. var m = s * 60;
  4761. var h = m * 60;
  4762. var d = h * 24;
  4763. var w = d * 7;
  4764. var y = d * 365.25;
  4765. /**
  4766. * Parse or format the given `val`.
  4767. *
  4768. * Options:
  4769. *
  4770. * - `long` verbose formatting [false]
  4771. *
  4772. * @param {String|Number} val
  4773. * @param {Object} [options]
  4774. * @throws {Error} throw an error if val is not a non-empty string or a number
  4775. * @return {String|Number}
  4776. * @api public
  4777. */
  4778. module.exports = function(val, options) {
  4779. options = options || {};
  4780. var type = typeof val;
  4781. if (type === 'string' && val.length > 0) {
  4782. return parse(val);
  4783. } else if (type === 'number' && isFinite(val)) {
  4784. return options.long ? fmtLong(val) : fmtShort(val);
  4785. }
  4786. throw new Error(
  4787. 'val is not a non-empty string or a valid number. val=' +
  4788. JSON.stringify(val)
  4789. );
  4790. };
  4791. /**
  4792. * Parse the given `str` and return milliseconds.
  4793. *
  4794. * @param {String} str
  4795. * @return {Number}
  4796. * @api private
  4797. */
  4798. function parse(str) {
  4799. str = String(str);
  4800. if (str.length > 100) {
  4801. return;
  4802. }
  4803. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
  4804. str
  4805. );
  4806. if (!match) {
  4807. return;
  4808. }
  4809. var n = parseFloat(match[1]);
  4810. var type = (match[2] || 'ms').toLowerCase();
  4811. switch (type) {
  4812. case 'years':
  4813. case 'year':
  4814. case 'yrs':
  4815. case 'yr':
  4816. case 'y':
  4817. return n * y;
  4818. case 'weeks':
  4819. case 'week':
  4820. case 'w':
  4821. return n * w;
  4822. case 'days':
  4823. case 'day':
  4824. case 'd':
  4825. return n * d;
  4826. case 'hours':
  4827. case 'hour':
  4828. case 'hrs':
  4829. case 'hr':
  4830. case 'h':
  4831. return n * h;
  4832. case 'minutes':
  4833. case 'minute':
  4834. case 'mins':
  4835. case 'min':
  4836. case 'm':
  4837. return n * m;
  4838. case 'seconds':
  4839. case 'second':
  4840. case 'secs':
  4841. case 'sec':
  4842. case 's':
  4843. return n * s;
  4844. case 'milliseconds':
  4845. case 'millisecond':
  4846. case 'msecs':
  4847. case 'msec':
  4848. case 'ms':
  4849. return n;
  4850. default:
  4851. return undefined;
  4852. }
  4853. }
  4854. /**
  4855. * Short format for `ms`.
  4856. *
  4857. * @param {Number} ms
  4858. * @return {String}
  4859. * @api private
  4860. */
  4861. function fmtShort(ms) {
  4862. var msAbs = Math.abs(ms);
  4863. if (msAbs >= d) {
  4864. return Math.round(ms / d) + 'd';
  4865. }
  4866. if (msAbs >= h) {
  4867. return Math.round(ms / h) + 'h';
  4868. }
  4869. if (msAbs >= m) {
  4870. return Math.round(ms / m) + 'm';
  4871. }
  4872. if (msAbs >= s) {
  4873. return Math.round(ms / s) + 's';
  4874. }
  4875. return ms + 'ms';
  4876. }
  4877. /**
  4878. * Long format for `ms`.
  4879. *
  4880. * @param {Number} ms
  4881. * @return {String}
  4882. * @api private
  4883. */
  4884. function fmtLong(ms) {
  4885. var msAbs = Math.abs(ms);
  4886. if (msAbs >= d) {
  4887. return plural(ms, msAbs, d, 'day');
  4888. }
  4889. if (msAbs >= h) {
  4890. return plural(ms, msAbs, h, 'hour');
  4891. }
  4892. if (msAbs >= m) {
  4893. return plural(ms, msAbs, m, 'minute');
  4894. }
  4895. if (msAbs >= s) {
  4896. return plural(ms, msAbs, s, 'second');
  4897. }
  4898. return ms + ' ms';
  4899. }
  4900. /**
  4901. * Pluralization helper.
  4902. */
  4903. function plural(ms, msAbs, n, name) {
  4904. var isPlural = msAbs >= n * 1.5;
  4905. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  4906. }
  4907. /***/ }),
  4908. /***/ "../ot-core/node_modules/parseqs/index.js":
  4909. /*!************************************************!*\
  4910. !*** ../ot-core/node_modules/parseqs/index.js ***!
  4911. \************************************************/
  4912. /***/ ((__unused_webpack_module, exports) => {
  4913. /**
  4914. * Compiles a querystring
  4915. * Returns string representation of the object
  4916. *
  4917. * @param {Object}
  4918. * @api private
  4919. */
  4920. exports.encode = function (obj) {
  4921. var str = '';
  4922. for (var i in obj) {
  4923. if (obj.hasOwnProperty(i)) {
  4924. if (str.length) str += '&';
  4925. str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
  4926. }
  4927. }
  4928. return str;
  4929. };
  4930. /**
  4931. * Parses a simple querystring into an object
  4932. *
  4933. * @param {String} qs
  4934. * @api private
  4935. */
  4936. exports.decode = function(qs){
  4937. var qry = {};
  4938. var pairs = qs.split('&');
  4939. for (var i = 0, l = pairs.length; i < l; i++) {
  4940. var pair = pairs[i].split('=');
  4941. qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  4942. }
  4943. return qry;
  4944. };
  4945. /***/ }),
  4946. /***/ "../ot-core/node_modules/parseuri/index.js":
  4947. /*!*************************************************!*\
  4948. !*** ../ot-core/node_modules/parseuri/index.js ***!
  4949. \*************************************************/
  4950. /***/ ((module) => {
  4951. /**
  4952. * Parses an URI
  4953. *
  4954. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  4955. * @api private
  4956. */
  4957. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  4958. var parts = [
  4959. 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
  4960. ];
  4961. module.exports = function parseuri(str) {
  4962. var src = str,
  4963. b = str.indexOf('['),
  4964. e = str.indexOf(']');
  4965. if (b != -1 && e != -1) {
  4966. str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
  4967. }
  4968. var m = re.exec(str || ''),
  4969. uri = {},
  4970. i = 14;
  4971. while (i--) {
  4972. uri[parts[i]] = m[i] || '';
  4973. }
  4974. if (b != -1 && e != -1) {
  4975. uri.source = src;
  4976. uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
  4977. uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
  4978. uri.ipv6uri = true;
  4979. }
  4980. uri.pathNames = pathNames(uri, uri['path']);
  4981. uri.queryKey = queryKey(uri, uri['query']);
  4982. return uri;
  4983. };
  4984. function pathNames(obj, path) {
  4985. var regx = /\/{2,9}/g,
  4986. names = path.replace(regx, "/").split("/");
  4987. if (path.substr(0, 1) == '/' || path.length === 0) {
  4988. names.splice(0, 1);
  4989. }
  4990. if (path.substr(path.length - 1, 1) == '/') {
  4991. names.splice(names.length - 1, 1);
  4992. }
  4993. return names;
  4994. }
  4995. function queryKey(uri, query) {
  4996. var data = {};
  4997. query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
  4998. if ($1) {
  4999. data[$1] = $2;
  5000. }
  5001. });
  5002. return data;
  5003. }
  5004. /***/ }),
  5005. /***/ "../ot-core/node_modules/supports-color/index.js":
  5006. /*!*******************************************************!*\
  5007. !*** ../ot-core/node_modules/supports-color/index.js ***!
  5008. \*******************************************************/
  5009. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5010. "use strict";
  5011. const os = __webpack_require__(/*! os */ "os");
  5012. const hasFlag = __webpack_require__(/*! has-flag */ "../ot-core/node_modules/has-flag/index.js");
  5013. const env = process.env;
  5014. let forceColor;
  5015. if (hasFlag('no-color') ||
  5016. hasFlag('no-colors') ||
  5017. hasFlag('color=false')) {
  5018. forceColor = false;
  5019. } else if (hasFlag('color') ||
  5020. hasFlag('colors') ||
  5021. hasFlag('color=true') ||
  5022. hasFlag('color=always')) {
  5023. forceColor = true;
  5024. }
  5025. if ('FORCE_COLOR' in env) {
  5026. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  5027. }
  5028. function translateLevel(level) {
  5029. if (level === 0) {
  5030. return false;
  5031. }
  5032. return {
  5033. level,
  5034. hasBasic: true,
  5035. has256: level >= 2,
  5036. has16m: level >= 3
  5037. };
  5038. }
  5039. function supportsColor(stream) {
  5040. if (forceColor === false) {
  5041. return 0;
  5042. }
  5043. if (hasFlag('color=16m') ||
  5044. hasFlag('color=full') ||
  5045. hasFlag('color=truecolor')) {
  5046. return 3;
  5047. }
  5048. if (hasFlag('color=256')) {
  5049. return 2;
  5050. }
  5051. if (stream && !stream.isTTY && forceColor !== true) {
  5052. return 0;
  5053. }
  5054. const min = forceColor ? 1 : 0;
  5055. if (process.platform === 'win32') {
  5056. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  5057. // libuv that enables 256 color output on Windows. Anything earlier and it
  5058. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  5059. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  5060. // release that supports 256 colors. Windows 10 build 14931 is the first release
  5061. // that supports 16m/TrueColor.
  5062. const osRelease = os.release().split('.');
  5063. if (
  5064. Number(process.versions.node.split('.')[0]) >= 8 &&
  5065. Number(osRelease[0]) >= 10 &&
  5066. Number(osRelease[2]) >= 10586
  5067. ) {
  5068. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  5069. }
  5070. return 1;
  5071. }
  5072. if ('CI' in env) {
  5073. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
  5074. return 1;
  5075. }
  5076. return min;
  5077. }
  5078. if ('TEAMCITY_VERSION' in env) {
  5079. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  5080. }
  5081. if (env.COLORTERM === 'truecolor') {
  5082. return 3;
  5083. }
  5084. if ('TERM_PROGRAM' in env) {
  5085. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  5086. switch (env.TERM_PROGRAM) {
  5087. case 'iTerm.app':
  5088. return version >= 3 ? 3 : 2;
  5089. case 'Apple_Terminal':
  5090. return 2;
  5091. // No default
  5092. }
  5093. }
  5094. if (/-256(color)?$/i.test(env.TERM)) {
  5095. return 2;
  5096. }
  5097. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  5098. return 1;
  5099. }
  5100. if ('COLORTERM' in env) {
  5101. return 1;
  5102. }
  5103. if (env.TERM === 'dumb') {
  5104. return min;
  5105. }
  5106. return min;
  5107. }
  5108. function getSupportLevel(stream) {
  5109. const level = supportsColor(stream);
  5110. return translateLevel(level);
  5111. }
  5112. module.exports = {
  5113. supportsColor: getSupportLevel,
  5114. stdout: getSupportLevel(process.stdout),
  5115. stderr: getSupportLevel(process.stderr)
  5116. };
  5117. /***/ }),
  5118. /***/ "../ot-core/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js":
  5119. /*!************************************************************************!*\
  5120. !*** ../ot-core/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js ***!
  5121. \************************************************************************/
  5122. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5123. /**
  5124. * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
  5125. *
  5126. * This can be used with JS designed for browsers to improve reuse of code and
  5127. * allow the use of existing libraries.
  5128. *
  5129. * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs.
  5130. *
  5131. * @author Dan DeFelippi <dan@driverdan.com>
  5132. * @contributor David Ellis <d.f.ellis@ieee.org>
  5133. * @license MIT
  5134. */
  5135. var fs = __webpack_require__(/*! fs */ "fs");
  5136. var Url = __webpack_require__(/*! url */ "url");
  5137. var spawn = (__webpack_require__(/*! child_process */ "child_process").spawn);
  5138. /**
  5139. * Module exports.
  5140. */
  5141. module.exports = XMLHttpRequest;
  5142. // backwards-compat
  5143. XMLHttpRequest.XMLHttpRequest = XMLHttpRequest;
  5144. /**
  5145. * `XMLHttpRequest` constructor.
  5146. *
  5147. * Supported options for the `opts` object are:
  5148. *
  5149. * - `agent`: An http.Agent instance; http.globalAgent may be used; if 'undefined', agent usage is disabled
  5150. *
  5151. * @param {Object} opts optional "options" object
  5152. */
  5153. function XMLHttpRequest(opts) {
  5154. "use strict";
  5155. opts = opts || {};
  5156. /**
  5157. * Private variables
  5158. */
  5159. var self = this;
  5160. var http = __webpack_require__(/*! http */ "http");
  5161. var https = __webpack_require__(/*! https */ "https");
  5162. // Holds http.js objects
  5163. var request;
  5164. var response;
  5165. // Request settings
  5166. var settings = {};
  5167. // Disable header blacklist.
  5168. // Not part of XHR specs.
  5169. var disableHeaderCheck = false;
  5170. // Set some default headers
  5171. var defaultHeaders = {
  5172. "User-Agent": "node-XMLHttpRequest",
  5173. "Accept": "*/*"
  5174. };
  5175. var headers = Object.assign({}, defaultHeaders);
  5176. // These headers are not user setable.
  5177. // The following are allowed but banned in the spec:
  5178. // * user-agent
  5179. var forbiddenRequestHeaders = [
  5180. "accept-charset",
  5181. "accept-encoding",
  5182. "access-control-request-headers",
  5183. "access-control-request-method",
  5184. "connection",
  5185. "content-length",
  5186. "content-transfer-encoding",
  5187. "cookie",
  5188. "cookie2",
  5189. "date",
  5190. "expect",
  5191. "host",
  5192. "keep-alive",
  5193. "origin",
  5194. "referer",
  5195. "te",
  5196. "trailer",
  5197. "transfer-encoding",
  5198. "upgrade",
  5199. "via"
  5200. ];
  5201. // These request methods are not allowed
  5202. var forbiddenRequestMethods = [
  5203. "TRACE",
  5204. "TRACK",
  5205. "CONNECT"
  5206. ];
  5207. // Send flag
  5208. var sendFlag = false;
  5209. // Error flag, used when errors occur or abort is called
  5210. var errorFlag = false;
  5211. var abortedFlag = false;
  5212. // Event listeners
  5213. var listeners = {};
  5214. /**
  5215. * Constants
  5216. */
  5217. this.UNSENT = 0;
  5218. this.OPENED = 1;
  5219. this.HEADERS_RECEIVED = 2;
  5220. this.LOADING = 3;
  5221. this.DONE = 4;
  5222. /**
  5223. * Public vars
  5224. */
  5225. // Current state
  5226. this.readyState = this.UNSENT;
  5227. // default ready state change handler in case one is not set or is set late
  5228. this.onreadystatechange = null;
  5229. // Result & response
  5230. this.responseText = "";
  5231. this.responseXML = "";
  5232. this.status = null;
  5233. this.statusText = null;
  5234. /**
  5235. * Private methods
  5236. */
  5237. /**
  5238. * Check if the specified header is allowed.
  5239. *
  5240. * @param string header Header to validate
  5241. * @return boolean False if not allowed, otherwise true
  5242. */
  5243. var isAllowedHttpHeader = function(header) {
  5244. return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1);
  5245. };
  5246. /**
  5247. * Check if the specified method is allowed.
  5248. *
  5249. * @param string method Request method to validate
  5250. * @return boolean False if not allowed, otherwise true
  5251. */
  5252. var isAllowedHttpMethod = function(method) {
  5253. return (method && forbiddenRequestMethods.indexOf(method) === -1);
  5254. };
  5255. /**
  5256. * Public methods
  5257. */
  5258. /**
  5259. * Open the connection. Currently supports local server requests.
  5260. *
  5261. * @param string method Connection method (eg GET, POST)
  5262. * @param string url URL for the connection.
  5263. * @param boolean async Asynchronous connection. Default is true.
  5264. * @param string user Username for basic authentication (optional)
  5265. * @param string password Password for basic authentication (optional)
  5266. */
  5267. this.open = function(method, url, async, user, password) {
  5268. this.abort();
  5269. errorFlag = false;
  5270. abortedFlag = false;
  5271. // Check for valid request method
  5272. if (!isAllowedHttpMethod(method)) {
  5273. throw new Error("SecurityError: Request method not allowed");
  5274. }
  5275. settings = {
  5276. "method": method,
  5277. "url": url.toString(),
  5278. "async": (typeof async !== "boolean" ? true : async),
  5279. "user": user || null,
  5280. "password": password || null
  5281. };
  5282. setState(this.OPENED);
  5283. };
  5284. /**
  5285. * Disables or enables isAllowedHttpHeader() check the request. Enabled by default.
  5286. * This does not conform to the W3C spec.
  5287. *
  5288. * @param boolean state Enable or disable header checking.
  5289. */
  5290. this.setDisableHeaderCheck = function(state) {
  5291. disableHeaderCheck = state;
  5292. };
  5293. /**
  5294. * Sets a header for the request.
  5295. *
  5296. * @param string header Header name
  5297. * @param string value Header value
  5298. * @return boolean Header added
  5299. */
  5300. this.setRequestHeader = function(header, value) {
  5301. if (this.readyState != this.OPENED) {
  5302. throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");
  5303. }
  5304. if (!isAllowedHttpHeader(header)) {
  5305. console.warn('Refused to set unsafe header "' + header + '"');
  5306. return false;
  5307. }
  5308. if (sendFlag) {
  5309. throw new Error("INVALID_STATE_ERR: send flag is true");
  5310. }
  5311. headers[header] = value;
  5312. return true;
  5313. };
  5314. /**
  5315. * Gets a header from the server response.
  5316. *
  5317. * @param string header Name of header to get.
  5318. * @return string Text of the header or null if it doesn't exist.
  5319. */
  5320. this.getResponseHeader = function(header) {
  5321. if (typeof header === "string"
  5322. && this.readyState > this.OPENED
  5323. && response.headers[header.toLowerCase()]
  5324. && !errorFlag
  5325. ) {
  5326. return response.headers[header.toLowerCase()];
  5327. }
  5328. return null;
  5329. };
  5330. /**
  5331. * Gets all the response headers.
  5332. *
  5333. * @return string A string with all response headers separated by CR+LF
  5334. */
  5335. this.getAllResponseHeaders = function() {
  5336. if (this.readyState < this.HEADERS_RECEIVED || errorFlag) {
  5337. return "";
  5338. }
  5339. var result = "";
  5340. for (var i in response.headers) {
  5341. // Cookie headers are excluded
  5342. if (i !== "set-cookie" && i !== "set-cookie2") {
  5343. result += i + ": " + response.headers[i] + "\r\n";
  5344. }
  5345. }
  5346. return result.substr(0, result.length - 2);
  5347. };
  5348. /**
  5349. * Gets a request header
  5350. *
  5351. * @param string name Name of header to get
  5352. * @return string Returns the request header or empty string if not set
  5353. */
  5354. this.getRequestHeader = function(name) {
  5355. // @TODO Make this case insensitive
  5356. if (typeof name === "string" && headers[name]) {
  5357. return headers[name];
  5358. }
  5359. return "";
  5360. };
  5361. /**
  5362. * Sends the request to the server.
  5363. *
  5364. * @param string data Optional data to send as request body.
  5365. */
  5366. this.send = function(data) {
  5367. if (this.readyState != this.OPENED) {
  5368. throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called");
  5369. }
  5370. if (sendFlag) {
  5371. throw new Error("INVALID_STATE_ERR: send has already been called");
  5372. }
  5373. var ssl = false, local = false;
  5374. var url = Url.parse(settings.url);
  5375. var host;
  5376. // Determine the server
  5377. switch (url.protocol) {
  5378. case 'https:':
  5379. ssl = true;
  5380. // SSL & non-SSL both need host, no break here.
  5381. case 'http:':
  5382. host = url.hostname;
  5383. break;
  5384. case 'file:':
  5385. local = true;
  5386. break;
  5387. case undefined:
  5388. case '':
  5389. host = "localhost";
  5390. break;
  5391. default:
  5392. throw new Error("Protocol not supported.");
  5393. }
  5394. // Load files off the local filesystem (file://)
  5395. if (local) {
  5396. if (settings.method !== "GET") {
  5397. throw new Error("XMLHttpRequest: Only GET method is supported");
  5398. }
  5399. if (settings.async) {
  5400. fs.readFile(unescape(url.pathname), 'utf8', function(error, data) {
  5401. if (error) {
  5402. self.handleError(error, error.errno || -1);
  5403. } else {
  5404. self.status = 200;
  5405. self.responseText = data;
  5406. setState(self.DONE);
  5407. }
  5408. });
  5409. } else {
  5410. try {
  5411. this.responseText = fs.readFileSync(unescape(url.pathname), 'utf8');
  5412. this.status = 200;
  5413. setState(self.DONE);
  5414. } catch(e) {
  5415. this.handleError(e, e.errno || -1);
  5416. }
  5417. }
  5418. return;
  5419. }
  5420. // Default to port 80. If accessing localhost on another port be sure
  5421. // to use http://localhost:port/path
  5422. var port = url.port || (ssl ? 443 : 80);
  5423. // Add query string if one is used
  5424. var uri = url.pathname + (url.search ? url.search : '');
  5425. // Set the Host header or the server may reject the request
  5426. headers["Host"] = host;
  5427. if (!((ssl && port === 443) || port === 80)) {
  5428. headers["Host"] += ':' + url.port;
  5429. }
  5430. // Set Basic Auth if necessary
  5431. if (settings.user) {
  5432. if (typeof settings.password == "undefined") {
  5433. settings.password = "";
  5434. }
  5435. var authBuf = new Buffer(settings.user + ":" + settings.password);
  5436. headers["Authorization"] = "Basic " + authBuf.toString("base64");
  5437. }
  5438. // Set content length header
  5439. if (settings.method === "GET" || settings.method === "HEAD") {
  5440. data = null;
  5441. } else if (data) {
  5442. headers["Content-Length"] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data);
  5443. if (!headers["Content-Type"]) {
  5444. headers["Content-Type"] = "text/plain;charset=UTF-8";
  5445. }
  5446. } else if (settings.method === "POST") {
  5447. // For a post with no data set Content-Length: 0.
  5448. // This is required by buggy servers that don't meet the specs.
  5449. headers["Content-Length"] = 0;
  5450. }
  5451. var agent = opts.agent || false;
  5452. var options = {
  5453. host: host,
  5454. port: port,
  5455. path: uri,
  5456. method: settings.method,
  5457. headers: headers,
  5458. agent: agent
  5459. };
  5460. if (ssl) {
  5461. options.pfx = opts.pfx;
  5462. options.key = opts.key;
  5463. options.passphrase = opts.passphrase;
  5464. options.cert = opts.cert;
  5465. options.ca = opts.ca;
  5466. options.ciphers = opts.ciphers;
  5467. options.rejectUnauthorized = opts.rejectUnauthorized === false ? false : true;
  5468. }
  5469. // Reset error flag
  5470. errorFlag = false;
  5471. // Handle async requests
  5472. if (settings.async) {
  5473. // Use the proper protocol
  5474. var doRequest = ssl ? https.request : http.request;
  5475. // Request is being sent, set send flag
  5476. sendFlag = true;
  5477. // As per spec, this is called here for historical reasons.
  5478. self.dispatchEvent("readystatechange");
  5479. // Handler for the response
  5480. var responseHandler = function(resp) {
  5481. // Set response var to the response we got back
  5482. // This is so it remains accessable outside this scope
  5483. response = resp;
  5484. // Check for redirect
  5485. // @TODO Prevent looped redirects
  5486. if (response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) {
  5487. // Change URL to the redirect location
  5488. settings.url = response.headers.location;
  5489. var url = Url.parse(settings.url);
  5490. // Set host var in case it's used later
  5491. host = url.hostname;
  5492. // Options for the new request
  5493. var newOptions = {
  5494. hostname: url.hostname,
  5495. port: url.port,
  5496. path: url.path,
  5497. method: response.statusCode === 303 ? 'GET' : settings.method,
  5498. headers: headers
  5499. };
  5500. if (ssl) {
  5501. newOptions.pfx = opts.pfx;
  5502. newOptions.key = opts.key;
  5503. newOptions.passphrase = opts.passphrase;
  5504. newOptions.cert = opts.cert;
  5505. newOptions.ca = opts.ca;
  5506. newOptions.ciphers = opts.ciphers;
  5507. newOptions.rejectUnauthorized = opts.rejectUnauthorized === false ? false : true;
  5508. }
  5509. // Issue the new request
  5510. request = doRequest(newOptions, responseHandler).on('error', errorHandler);
  5511. request.end();
  5512. // @TODO Check if an XHR event needs to be fired here
  5513. return;
  5514. }
  5515. if (response && response.setEncoding) {
  5516. response.setEncoding("utf8");
  5517. }
  5518. setState(self.HEADERS_RECEIVED);
  5519. self.status = response.statusCode;
  5520. response.on('data', function(chunk) {
  5521. // Make sure there's some data
  5522. if (chunk) {
  5523. self.responseText += chunk;
  5524. }
  5525. // Don't emit state changes if the connection has been aborted.
  5526. if (sendFlag) {
  5527. setState(self.LOADING);
  5528. }
  5529. });
  5530. response.on('end', function() {
  5531. if (sendFlag) {
  5532. // The sendFlag needs to be set before setState is called. Otherwise if we are chaining callbacks
  5533. // there can be a timing issue (the callback is called and a new call is made before the flag is reset).
  5534. sendFlag = false;
  5535. // Discard the 'end' event if the connection has been aborted
  5536. setState(self.DONE);
  5537. }
  5538. });
  5539. response.on('error', function(error) {
  5540. self.handleError(error);
  5541. });
  5542. }
  5543. // Error handler for the request
  5544. var errorHandler = function(error) {
  5545. self.handleError(error);
  5546. }
  5547. // Create the request
  5548. request = doRequest(options, responseHandler).on('error', errorHandler);
  5549. if (opts.autoUnref) {
  5550. request.on('socket', (socket) => {
  5551. socket.unref();
  5552. });
  5553. }
  5554. // Node 0.4 and later won't accept empty data. Make sure it's needed.
  5555. if (data) {
  5556. request.write(data);
  5557. }
  5558. request.end();
  5559. self.dispatchEvent("loadstart");
  5560. } else { // Synchronous
  5561. // Create a temporary file for communication with the other Node process
  5562. var contentFile = ".node-xmlhttprequest-content-" + process.pid;
  5563. var syncFile = ".node-xmlhttprequest-sync-" + process.pid;
  5564. fs.writeFileSync(syncFile, "", "utf8");
  5565. // The async request the other Node process executes
  5566. var execString = "var http = require('http'), https = require('https'), fs = require('fs');"
  5567. + "var doRequest = http" + (ssl ? "s" : "") + ".request;"
  5568. + "var options = " + JSON.stringify(options) + ";"
  5569. + "var responseText = '';"
  5570. + "var req = doRequest(options, function(response) {"
  5571. + "response.setEncoding('utf8');"
  5572. + "response.on('data', function(chunk) {"
  5573. + " responseText += chunk;"
  5574. + "});"
  5575. + "response.on('end', function() {"
  5576. + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
  5577. + "fs.unlinkSync('" + syncFile + "');"
  5578. + "});"
  5579. + "response.on('error', function(error) {"
  5580. + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
  5581. + "fs.unlinkSync('" + syncFile + "');"
  5582. + "});"
  5583. + "}).on('error', function(error) {"
  5584. + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
  5585. + "fs.unlinkSync('" + syncFile + "');"
  5586. + "});"
  5587. + (data ? "req.write('" + JSON.stringify(data).slice(1,-1).replace(/'/g, "\\'") + "');":"")
  5588. + "req.end();";
  5589. // Start the other Node Process, executing this string
  5590. var syncProc = spawn(process.argv[0], ["-e", execString]);
  5591. var statusText;
  5592. while(fs.existsSync(syncFile)) {
  5593. // Wait while the sync file is empty
  5594. }
  5595. self.responseText = fs.readFileSync(contentFile, 'utf8');
  5596. // Kill the child process once the file has data
  5597. syncProc.stdin.end();
  5598. // Remove the temporary file
  5599. fs.unlinkSync(contentFile);
  5600. if (self.responseText.match(/^NODE-XMLHTTPREQUEST-ERROR:/)) {
  5601. // If the file returned an error, handle it
  5602. var errorObj = self.responseText.replace(/^NODE-XMLHTTPREQUEST-ERROR:/, "");
  5603. self.handleError(errorObj, 503);
  5604. } else {
  5605. // If the file returned okay, parse its data and move to the DONE state
  5606. self.status = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:([0-9]*),.*/, "$1");
  5607. self.responseText = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:[0-9]*,(.*)/, "$1");
  5608. setState(self.DONE);
  5609. }
  5610. }
  5611. };
  5612. /**
  5613. * Called when an error is encountered to deal with it.
  5614. * @param status {number} HTTP status code to use rather than the default (0) for XHR errors.
  5615. */
  5616. this.handleError = function(error, status) {
  5617. this.status = status || 0;
  5618. this.statusText = error;
  5619. this.responseText = error.stack;
  5620. errorFlag = true;
  5621. setState(this.DONE);
  5622. };
  5623. /**
  5624. * Aborts a request.
  5625. */
  5626. this.abort = function() {
  5627. if (request) {
  5628. request.abort();
  5629. request = null;
  5630. }
  5631. headers = Object.assign({}, defaultHeaders);
  5632. this.responseText = "";
  5633. this.responseXML = "";
  5634. errorFlag = abortedFlag = true
  5635. if (this.readyState !== this.UNSENT
  5636. && (this.readyState !== this.OPENED || sendFlag)
  5637. && this.readyState !== this.DONE) {
  5638. sendFlag = false;
  5639. setState(this.DONE);
  5640. }
  5641. this.readyState = this.UNSENT;
  5642. };
  5643. /**
  5644. * Adds an event listener. Preferred method of binding to events.
  5645. */
  5646. this.addEventListener = function(event, callback) {
  5647. if (!(event in listeners)) {
  5648. listeners[event] = [];
  5649. }
  5650. // Currently allows duplicate callbacks. Should it?
  5651. listeners[event].push(callback);
  5652. };
  5653. /**
  5654. * Remove an event callback that has already been bound.
  5655. * Only works on the matching funciton, cannot be a copy.
  5656. */
  5657. this.removeEventListener = function(event, callback) {
  5658. if (event in listeners) {
  5659. // Filter will return a new array with the callback removed
  5660. listeners[event] = listeners[event].filter(function(ev) {
  5661. return ev !== callback;
  5662. });
  5663. }
  5664. };
  5665. /**
  5666. * Dispatch any events, including both "on" methods and events attached using addEventListener.
  5667. */
  5668. this.dispatchEvent = function(event) {
  5669. if (typeof self["on" + event] === "function") {
  5670. if (this.readyState === this.DONE)
  5671. setImmediate(function() { self["on" + event]() })
  5672. else
  5673. self["on" + event]()
  5674. }
  5675. if (event in listeners) {
  5676. for (let i = 0, len = listeners[event].length; i < len; i++) {
  5677. if (this.readyState === this.DONE)
  5678. setImmediate(function() { listeners[event][i].call(self) })
  5679. else
  5680. listeners[event][i].call(self)
  5681. }
  5682. }
  5683. };
  5684. /**
  5685. * Changes readyState and calls onreadystatechange.
  5686. *
  5687. * @param int state New state
  5688. */
  5689. var setState = function(state) {
  5690. if ((self.readyState === state) || (self.readyState === self.UNSENT && abortedFlag))
  5691. return
  5692. self.readyState = state;
  5693. if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) {
  5694. self.dispatchEvent("readystatechange");
  5695. }
  5696. if (self.readyState === self.DONE) {
  5697. let fire
  5698. if (abortedFlag)
  5699. fire = "abort"
  5700. else if (errorFlag)
  5701. fire = "error"
  5702. else
  5703. fire = "load"
  5704. self.dispatchEvent(fire)
  5705. // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie)
  5706. self.dispatchEvent("loadend");
  5707. }
  5708. };
  5709. };
  5710. /***/ }),
  5711. /***/ "../ot-core/node_modules/yeast/index.js":
  5712. /*!**********************************************!*\
  5713. !*** ../ot-core/node_modules/yeast/index.js ***!
  5714. \**********************************************/
  5715. /***/ ((module) => {
  5716. "use strict";
  5717. var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
  5718. , length = 64
  5719. , map = {}
  5720. , seed = 0
  5721. , i = 0
  5722. , prev;
  5723. /**
  5724. * Return a string representing the specified number.
  5725. *
  5726. * @param {Number} num The number to convert.
  5727. * @returns {String} The string representation of the number.
  5728. * @api public
  5729. */
  5730. function encode(num) {
  5731. var encoded = '';
  5732. do {
  5733. encoded = alphabet[num % length] + encoded;
  5734. num = Math.floor(num / length);
  5735. } while (num > 0);
  5736. return encoded;
  5737. }
  5738. /**
  5739. * Return the integer value specified by the given string.
  5740. *
  5741. * @param {String} str The string to convert.
  5742. * @returns {Number} The integer value represented by the string.
  5743. * @api public
  5744. */
  5745. function decode(str) {
  5746. var decoded = 0;
  5747. for (i = 0; i < str.length; i++) {
  5748. decoded = decoded * length + map[str.charAt(i)];
  5749. }
  5750. return decoded;
  5751. }
  5752. /**
  5753. * Yeast: A tiny growing id generator.
  5754. *
  5755. * @returns {String} A unique id.
  5756. * @api public
  5757. */
  5758. function yeast() {
  5759. var now = encode(+new Date());
  5760. if (now !== prev) return seed = 0, prev = now;
  5761. return now +'.'+ encode(seed++);
  5762. }
  5763. //
  5764. // Map each character to its index.
  5765. //
  5766. for (; i < length; i++) map[alphabet[i]] = i;
  5767. //
  5768. // Expose the `yeast`, `encode` and `decode` functions.
  5769. //
  5770. yeast.encode = encode;
  5771. yeast.decode = decode;
  5772. module.exports = yeast;
  5773. /***/ }),
  5774. /***/ "../ot-core/src/basics/Command.ts":
  5775. /*!****************************************!*\
  5776. !*** ../ot-core/src/basics/Command.ts ***!
  5777. \****************************************/
  5778. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5779. "use strict";
  5780. Object.defineProperty(exports, "__esModule", ({
  5781. value: true
  5782. }));
  5783. exports.Command = void 0;
  5784. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  5785. class Command {
  5786. constructor(...parameter) {
  5787. this._describe = 'Command';
  5788. if (internal_1.TransformUtils.hasLength(parameter, 0)) {
  5789. this._groupId = 'default';
  5790. this._operation = [];
  5791. return;
  5792. }
  5793. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  5794. if (internal_1.TransformUtils.isString(parameter[0])) {
  5795. const groupId = parameter[0];
  5796. this._operation = [];
  5797. this._groupId = groupId;
  5798. return;
  5799. }
  5800. if (internal_1.TransformUtils.isObject(parameter[0])) {
  5801. const serialize = parameter[0];
  5802. this._groupId = serialize.groupId;
  5803. this._operation = internal_1.Deserialize.getInstance().formArray(serialize.operation);
  5804. return;
  5805. }
  5806. }
  5807. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  5808. const groupId = parameter[0];
  5809. const operation = parameter[1];
  5810. this._groupId = groupId;
  5811. this._operation = operation;
  5812. }
  5813. }
  5814. concat(target) {
  5815. const result = new Command({
  5816. groupId: this._groupId,
  5817. describe: this._describe,
  5818. operation: []
  5819. });
  5820. result._operation = this._operation.concat(target._operation);
  5821. return result;
  5822. }
  5823. apply(resource) {
  5824. const operations = this._operation;
  5825. const sizeof = operations.length;
  5826. for (let i = 0; i < sizeof; i++) {
  5827. const action = operations[i];
  5828. action.apply(resource);
  5829. }
  5830. }
  5831. getOperations() {
  5832. return this._operation;
  5833. }
  5834. getGroupId() {
  5835. return this._groupId;
  5836. }
  5837. addOperation(operation) {
  5838. this._operation.push(operation);
  5839. }
  5840. toJSON() {
  5841. return {
  5842. describe: this._describe,
  5843. groupId: this._groupId,
  5844. operation: this._operation.map(o => o.toJSON())
  5845. };
  5846. }
  5847. }
  5848. exports.Command = Command;
  5849. /***/ }),
  5850. /***/ "../ot-core/src/basics/Conflict.ts":
  5851. /*!*****************************************!*\
  5852. !*** ../ot-core/src/basics/Conflict.ts ***!
  5853. \*****************************************/
  5854. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5855. "use strict";
  5856. Object.defineProperty(exports, "__esModule", ({
  5857. value: true
  5858. }));
  5859. exports.Conflict = void 0;
  5860. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  5861. class Conflict {
  5862. constructor() {
  5863. this._conflict = new Array();
  5864. }
  5865. get(targetOperation, savedOperation) {
  5866. const _conflict = this._conflict;
  5867. const sizeof = _conflict.length;
  5868. for (let i = 0; i < sizeof; i++) {
  5869. const wrapped = _conflict[i];
  5870. const targetFrom = internal_1.TransformUtils.isAssignableFrom(targetOperation, wrapped.targetClass);
  5871. const savedFrom = internal_1.TransformUtils.isAssignableFrom(savedOperation, wrapped.savedClass);
  5872. if (targetFrom && savedFrom) {
  5873. return wrapped;
  5874. }
  5875. }
  5876. return null;
  5877. }
  5878. add(...parameter) {
  5879. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  5880. const wrapped = parameter[0];
  5881. this._conflict.push(wrapped);
  5882. return;
  5883. }
  5884. if (internal_1.TransformUtils.hasLength(parameter, 3)) {
  5885. const targetClass = parameter[0];
  5886. const savedClass = parameter[1];
  5887. const process = parameter[2];
  5888. this._conflict.push({
  5889. targetClass,
  5890. savedClass,
  5891. process
  5892. });
  5893. }
  5894. }
  5895. }
  5896. exports.Conflict = Conflict;
  5897. /***/ }),
  5898. /***/ "../ot-core/src/basics/Deserialize.ts":
  5899. /*!********************************************!*\
  5900. !*** ../ot-core/src/basics/Deserialize.ts ***!
  5901. \********************************************/
  5902. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5903. "use strict";
  5904. Object.defineProperty(exports, "__esModule", ({
  5905. value: true
  5906. }));
  5907. exports.Deserialize = void 0;
  5908. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  5909. let singleton;
  5910. class Deserialize {
  5911. constructor() {
  5912. this._storage = new Map();
  5913. }
  5914. static getInstance() {
  5915. if (!internal_1.TransformUtils.isDefine(singleton)) {
  5916. singleton = new Deserialize();
  5917. singleton.addClass('SwapData', internal_1.SwapData);
  5918. singleton.addClass('Command', internal_1.Command);
  5919. }
  5920. return singleton;
  5921. }
  5922. formArray(...parameter) {
  5923. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  5924. const object = parameter[0];
  5925. const length = object.length;
  5926. const result = new Array();
  5927. for (let i = 0; i < length; i++) {
  5928. result.push(this.convert(object[i]));
  5929. }
  5930. return result;
  5931. }
  5932. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  5933. const object = parameter[0];
  5934. const defaultValue = parameter[1];
  5935. if (internal_1.TransformUtils.isDefine(object)) {
  5936. const length = object.length;
  5937. const result = new Array();
  5938. for (let i = 0; i < length; i++) {
  5939. result.push(this.convert(object[i]));
  5940. }
  5941. return result;
  5942. }
  5943. return defaultValue;
  5944. }
  5945. }
  5946. formObject(...parameter) {
  5947. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  5948. const object = parameter[0];
  5949. return this.convert(object);
  5950. }
  5951. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  5952. const object = parameter[0];
  5953. const defaultValue = parameter[1];
  5954. if (internal_1.TransformUtils.isDefine(object)) {
  5955. return this.convert(object);
  5956. }
  5957. return defaultValue;
  5958. }
  5959. }
  5960. convert(value) {
  5961. if (internal_1.TransformUtils.isDefine(value.describe)) {
  5962. return this.newInstance(value.describe, value);
  5963. }
  5964. return value;
  5965. }
  5966. addClass(...parameter) {
  5967. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  5968. const clazz = parameter[0];
  5969. this._storage.set(clazz.name, clazz);
  5970. return;
  5971. }
  5972. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  5973. const name = parameter[0];
  5974. const clazz = parameter[1];
  5975. this._storage.set(name, clazz);
  5976. }
  5977. }
  5978. newInstance(name, desc) {
  5979. const constructor = this.getClass(name);
  5980. return new constructor(desc);
  5981. }
  5982. getClass(name) {
  5983. const element = this._storage.get(name);
  5984. if (internal_1.TransformUtils.isDefine(element)) {
  5985. return element;
  5986. }
  5987. throw new Error(`not find ${name} Class`);
  5988. }
  5989. }
  5990. exports.Deserialize = Deserialize;
  5991. /***/ }),
  5992. /***/ "../ot-core/src/basics/Operation.ts":
  5993. /*!******************************************!*\
  5994. !*** ../ot-core/src/basics/Operation.ts ***!
  5995. \******************************************/
  5996. /***/ ((__unused_webpack_module, exports) => {
  5997. "use strict";
  5998. Object.defineProperty(exports, "__esModule", ({
  5999. value: true
  6000. }));
  6001. /***/ }),
  6002. /***/ "../ot-core/src/basics/SwapData.ts":
  6003. /*!*****************************************!*\
  6004. !*** ../ot-core/src/basics/SwapData.ts ***!
  6005. \*****************************************/
  6006. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6007. "use strict";
  6008. Object.defineProperty(exports, "__esModule", ({
  6009. value: true
  6010. }));
  6011. exports.SwapData = void 0;
  6012. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6013. class SwapData {
  6014. constructor(...parameter) {
  6015. this._describe = 'SwapData';
  6016. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  6017. this._data = parameter[0].data;
  6018. return;
  6019. }
  6020. if (internal_1.TransformUtils.hasLength(parameter, 0)) {
  6021. this._data = null;
  6022. }
  6023. }
  6024. setData(_data) {
  6025. this._data = _data;
  6026. }
  6027. getData() {
  6028. return this._data;
  6029. }
  6030. clone() {
  6031. return this;
  6032. }
  6033. toJSON() {
  6034. return {
  6035. describe: this._describe,
  6036. data: this._data
  6037. };
  6038. }
  6039. }
  6040. exports.SwapData = SwapData;
  6041. /***/ }),
  6042. /***/ "../ot-core/src/basics/Transform.ts":
  6043. /*!******************************************!*\
  6044. !*** ../ot-core/src/basics/Transform.ts ***!
  6045. \******************************************/
  6046. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6047. "use strict";
  6048. Object.defineProperty(exports, "__esModule", ({
  6049. value: true
  6050. }));
  6051. exports.Transform = void 0;
  6052. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6053. class Transform {
  6054. constructor(_conflict) {
  6055. this._conflict = _conflict;
  6056. }
  6057. transfer(targetCommand, savedCommand) {
  6058. const conflict = this._conflict;
  6059. const targetOperations = targetCommand.getOperations();
  6060. const savedOperations = savedCommand.getOperations();
  6061. const sizeof1 = targetOperations.length;
  6062. const sizeof2 = savedOperations.length;
  6063. const newTargetCommand = new internal_1.Command({
  6064. groupId: targetCommand.getGroupId(),
  6065. operation: [],
  6066. describe: 'Command'
  6067. });
  6068. const newSavedCommand = new internal_1.Command({
  6069. groupId: targetCommand.getGroupId(),
  6070. operation: [],
  6071. describe: 'Command'
  6072. });
  6073. for (let i = 0; i < sizeof1; i++) {
  6074. const targetOperation = targetOperations[i];
  6075. for (let j = 0; j < sizeof2; j++) {
  6076. const savedOperation = savedOperations[j];
  6077. const wrapped = conflict.get(targetOperation, savedOperation);
  6078. if (wrapped != null) {
  6079. const transfer = wrapped.process(newTargetCommand, newSavedCommand);
  6080. transfer(targetOperation.clone(), savedOperation.clone());
  6081. continue;
  6082. }
  6083. throw new Error('not found _conflict process');
  6084. }
  6085. }
  6086. return [newTargetCommand, newSavedCommand];
  6087. }
  6088. }
  6089. exports.Transform = Transform;
  6090. /***/ }),
  6091. /***/ "../ot-core/src/client/AwaitingConfirm.ts":
  6092. /*!************************************************!*\
  6093. !*** ../ot-core/src/client/AwaitingConfirm.ts ***!
  6094. \************************************************/
  6095. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6096. "use strict";
  6097. Object.defineProperty(exports, "__esModule", ({
  6098. value: true
  6099. }));
  6100. exports.AwaitingConfirm = void 0;
  6101. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6102. class AwaitingConfirm {
  6103. constructor(outstanding) {
  6104. this._outstanding = outstanding;
  6105. }
  6106. applyClient(client, command) {
  6107. return new internal_1.AwaitingWithBuffer(this._outstanding, command);
  6108. }
  6109. serverAck(client) {
  6110. return internal_1.Synchronized.DEFAULT;
  6111. }
  6112. applyServer(client, command) {
  6113. const outstanding = this._outstanding;
  6114. const pair = client.getTransform().transfer(outstanding, command);
  6115. client.applyCommand(pair[1]);
  6116. return new AwaitingConfirm(pair[0]);
  6117. }
  6118. resend(client) {
  6119. client.sendCommand(client.getRevision(), this._outstanding);
  6120. }
  6121. }
  6122. exports.AwaitingConfirm = AwaitingConfirm;
  6123. /***/ }),
  6124. /***/ "../ot-core/src/client/AwaitingWithBuffer.ts":
  6125. /*!***************************************************!*\
  6126. !*** ../ot-core/src/client/AwaitingWithBuffer.ts ***!
  6127. \***************************************************/
  6128. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6129. "use strict";
  6130. Object.defineProperty(exports, "__esModule", ({
  6131. value: true
  6132. }));
  6133. exports.AwaitingWithBuffer = void 0;
  6134. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6135. class AwaitingWithBuffer {
  6136. constructor(outstanding, buffer) {
  6137. this._outstanding = outstanding;
  6138. this._buffer = buffer;
  6139. }
  6140. applyClient(client, command) {
  6141. let newBuffer = this._buffer.concat(command);
  6142. return new AwaitingWithBuffer(this._outstanding, newBuffer);
  6143. }
  6144. serverAck(client) {
  6145. client.sendCommand(client.getRevision(), this._buffer);
  6146. return new internal_1.AwaitingConfirm(this._buffer);
  6147. }
  6148. applyServer(client, command) {
  6149. const outstanding = this._outstanding;
  6150. const buffer = this._buffer;
  6151. const pair1 = client.getTransform().transfer(outstanding, command);
  6152. const pair2 = client.getTransform().transfer(buffer, pair1[1]);
  6153. client.applyCommand(pair2[1]);
  6154. return new AwaitingWithBuffer(pair1[0], pair2[0]);
  6155. }
  6156. resend(client) {
  6157. client.sendCommand(client.getRevision(), this._outstanding);
  6158. }
  6159. }
  6160. exports.AwaitingWithBuffer = AwaitingWithBuffer;
  6161. /***/ }),
  6162. /***/ "../ot-core/src/client/Client.ts":
  6163. /*!***************************************!*\
  6164. !*** ../ot-core/src/client/Client.ts ***!
  6165. \***************************************/
  6166. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6167. "use strict";
  6168. Object.defineProperty(exports, "__esModule", ({
  6169. value: true
  6170. }));
  6171. exports.Client = void 0;
  6172. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6173. class Client {
  6174. constructor(conflict) {
  6175. this._revision = 0;
  6176. this._transform = new internal_1.Transform(conflict);
  6177. this._status = internal_1.Synchronized.DEFAULT;
  6178. this._undoManager = new internal_1.UndoManager(this._transform);
  6179. }
  6180. applyClient(command) {
  6181. this._status = this._status.applyClient(this, command);
  6182. }
  6183. serverAck() {
  6184. this._revision++;
  6185. this._status = this._status.serverAck(this);
  6186. }
  6187. applyServer(command) {
  6188. this._revision++;
  6189. this._status = this._status.applyServer(this, command);
  6190. }
  6191. serverReconnect() {
  6192. this._status.resend(this);
  6193. }
  6194. getTransform() {
  6195. return this._transform;
  6196. }
  6197. getRevision() {
  6198. return this._revision;
  6199. }
  6200. getUndoManager() {
  6201. return this._undoManager;
  6202. }
  6203. }
  6204. exports.Client = Client;
  6205. /***/ }),
  6206. /***/ "../ot-core/src/client/ClientSocket.ts":
  6207. /*!*********************************************!*\
  6208. !*** ../ot-core/src/client/ClientSocket.ts ***!
  6209. \*********************************************/
  6210. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6211. "use strict";
  6212. Object.defineProperty(exports, "__esModule", ({
  6213. value: true
  6214. }));
  6215. exports.ClientSocket = void 0;
  6216. const socket_io_client_1 = __webpack_require__(/*! socket.io-client */ "../ot-core/node_modules/socket.io-client/build/cjs/index.js");
  6217. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6218. class ClientSocket extends internal_1.Client {
  6219. constructor(config) {
  6220. super(config.conflict);
  6221. this._config = config;
  6222. this._socket = (0, socket_io_client_1.io)(config.url);
  6223. this._execute = () => {};
  6224. this._initializeListener();
  6225. this._initializeSocket();
  6226. }
  6227. _initializeListener() {
  6228. const observer = this._undoManager.getObserver();
  6229. observer.addOnAddRedoListener({
  6230. onAddRedo: wrapped => {
  6231. wrapped.redo.apply(this._source);
  6232. this.applyClient(wrapped.redo);
  6233. }
  6234. });
  6235. observer.addOnAddUndoListener({
  6236. onAddUndo: wrapped => {
  6237. wrapped.undo.apply(this._source);
  6238. this.applyClient(wrapped.undo);
  6239. }
  6240. });
  6241. }
  6242. _initializeSocket() {
  6243. this._socket.on('open', response => {
  6244. this._revision = response.revision;
  6245. this._users = response.users;
  6246. this._source = response.source;
  6247. this._roomId = response.roomId;
  6248. this._execute();
  6249. });
  6250. this._socket.on('ack', () => {
  6251. this.serverAck();
  6252. });
  6253. this._socket.on('command', (clientId, command) => {
  6254. const deserialize = internal_1.Deserialize.getInstance().formObject(command);
  6255. this.applyServer(deserialize);
  6256. });
  6257. this._socket.on('reconnect', () => {
  6258. this.serverReconnect();
  6259. });
  6260. }
  6261. ready(execute) {
  6262. this._execute = execute;
  6263. }
  6264. sendCommand(revision, command) {
  6265. this._socket.emit('command', revision, command.toJSON());
  6266. }
  6267. applyCommand(command) {
  6268. command.apply(this._source);
  6269. this._undoManager.transform(command);
  6270. }
  6271. }
  6272. exports.ClientSocket = ClientSocket;
  6273. /***/ }),
  6274. /***/ "../ot-core/src/client/Synchronized.ts":
  6275. /*!*********************************************!*\
  6276. !*** ../ot-core/src/client/Synchronized.ts ***!
  6277. \*********************************************/
  6278. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6279. "use strict";
  6280. Object.defineProperty(exports, "__esModule", ({
  6281. value: true
  6282. }));
  6283. exports.Synchronized = void 0;
  6284. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6285. class Synchronized {
  6286. applyClient(client, command) {
  6287. client.sendCommand(client.getRevision(), command);
  6288. return new internal_1.AwaitingConfirm(command);
  6289. }
  6290. serverAck(client) {
  6291. throw new Error("There is no pending operated.");
  6292. }
  6293. applyServer(client, command) {
  6294. client.applyCommand(command);
  6295. return this;
  6296. }
  6297. resend(client) {}
  6298. }
  6299. exports.Synchronized = Synchronized;
  6300. Synchronized.DEFAULT = new Synchronized();
  6301. /***/ }),
  6302. /***/ "../ot-core/src/client/UndoManager.ts":
  6303. /*!********************************************!*\
  6304. !*** ../ot-core/src/client/UndoManager.ts ***!
  6305. \********************************************/
  6306. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6307. "use strict";
  6308. Object.defineProperty(exports, "__esModule", ({
  6309. value: true
  6310. }));
  6311. exports.UndoManager = void 0;
  6312. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6313. class UndoManager {
  6314. constructor(transform) {
  6315. this._redoStack = [];
  6316. this._undoStack = [];
  6317. this._transform = transform;
  6318. this._observer = new internal_1.UndoManagerObserver();
  6319. }
  6320. _transformStack(stack, command) {
  6321. const transform = this._transform;
  6322. const sizeof = stack.length - 1;
  6323. let redoCommand = command;
  6324. let undoCommand = command;
  6325. for (let i = sizeof; i >= 0; i--) {
  6326. const pair1 = transform.transfer(stack[i].redo, redoCommand);
  6327. const pair2 = transform.transfer(stack[i].undo, undoCommand);
  6328. stack[i].redo = pair1[0];
  6329. stack[i].undo = pair2[0];
  6330. redoCommand = pair1[1];
  6331. undoCommand = pair2[1];
  6332. }
  6333. }
  6334. transform(command) {
  6335. this._transformStack(this._undoStack, command);
  6336. this._transformStack(this._redoStack, command);
  6337. }
  6338. canUndo() {
  6339. return this._undoStack.length !== 0;
  6340. }
  6341. canRedo() {
  6342. return this._redoStack.length !== 0;
  6343. }
  6344. addRedo(...parameter) {
  6345. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  6346. const wrapped = parameter[0];
  6347. this._redoStack.push(wrapped);
  6348. this._observer.dispatchOnAddRedo(wrapped);
  6349. return;
  6350. }
  6351. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  6352. const redo = parameter[0];
  6353. const undo = parameter[1];
  6354. const wrapped = {
  6355. redo,
  6356. undo
  6357. };
  6358. this._redoStack.push(wrapped);
  6359. this._observer.dispatchOnAddRedo(wrapped);
  6360. }
  6361. }
  6362. addUndo(...parameter) {
  6363. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  6364. const wrapped = parameter[0];
  6365. this._undoStack.push(wrapped);
  6366. this._observer.dispatchOnAddUndo(wrapped);
  6367. return;
  6368. }
  6369. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  6370. const redo = parameter[0];
  6371. const undo = parameter[1];
  6372. const wrapped = {
  6373. redo,
  6374. undo
  6375. };
  6376. this._undoStack.push(wrapped);
  6377. this._observer.dispatchOnAddUndo(wrapped);
  6378. }
  6379. }
  6380. performCommand(...parameter) {
  6381. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  6382. const wrapped = parameter[0];
  6383. this.addRedo(wrapped);
  6384. return;
  6385. }
  6386. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  6387. const redo = parameter[0];
  6388. const undo = parameter[1];
  6389. const wrapped = {
  6390. redo,
  6391. undo
  6392. };
  6393. this.addRedo(wrapped);
  6394. }
  6395. }
  6396. performRedo() {
  6397. if (this.canRedo()) {
  6398. const wrapped = this._redoStack.pop();
  6399. this.addUndo(wrapped);
  6400. this._observer.dispatchOnRedo(wrapped);
  6401. }
  6402. }
  6403. performUndo() {
  6404. if (this.canUndo()) {
  6405. const wrapped = this._undoStack.pop();
  6406. this.addRedo(wrapped);
  6407. this._observer.dispatchOnUndo(wrapped);
  6408. }
  6409. }
  6410. getObserver() {
  6411. return this._observer;
  6412. }
  6413. }
  6414. exports.UndoManager = UndoManager;
  6415. /***/ }),
  6416. /***/ "../ot-core/src/client/UndoManagerObserver.ts":
  6417. /*!****************************************************!*\
  6418. !*** ../ot-core/src/client/UndoManagerObserver.ts ***!
  6419. \****************************************************/
  6420. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6421. "use strict";
  6422. Object.defineProperty(exports, "__esModule", ({
  6423. value: true
  6424. }));
  6425. exports.UndoManagerObserver = void 0;
  6426. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6427. class UndoManagerObserver {
  6428. dispatchOnAddRedo(wrapped) {
  6429. let listeners = this._onAddRedoListeners;
  6430. if (listeners != null) {
  6431. const sizeof = listeners.sizeof();
  6432. for (let i = 0; i < sizeof; i++) {
  6433. const listener = listeners.get(i);
  6434. listener.onAddRedo(wrapped);
  6435. }
  6436. }
  6437. }
  6438. dispatchOnAddUndo(wrapped) {
  6439. let listeners = this._onAddUndoListeners;
  6440. if (listeners != null) {
  6441. const sizeof = listeners.sizeof();
  6442. for (let i = 0; i < sizeof; i++) {
  6443. const listener = listeners.get(i);
  6444. listener.onAddUndo(wrapped);
  6445. }
  6446. }
  6447. }
  6448. dispatchOnRedo(wrapped) {
  6449. let listeners = this._onRedoListeners;
  6450. if (listeners != null) {
  6451. const sizeof = listeners.sizeof();
  6452. for (let i = 0; i < sizeof; i++) {
  6453. const listener = listeners.get(i);
  6454. listener.onRedo(wrapped);
  6455. }
  6456. }
  6457. }
  6458. dispatchOnUndo(wrapped) {
  6459. let listeners = this._onUndoListeners;
  6460. if (listeners != null) {
  6461. const sizeof = listeners.sizeof();
  6462. for (let i = 0; i < sizeof; i++) {
  6463. const listener = listeners.get(i);
  6464. listener.onUndo(wrapped);
  6465. }
  6466. }
  6467. }
  6468. addOnAddRedoListener(listener) {
  6469. if (this._onAddRedoListeners == null) {
  6470. this._onAddRedoListeners = new internal_1.ArrayList();
  6471. }
  6472. this._onAddRedoListeners.add(listener);
  6473. }
  6474. addOnAddUndoListener(listener) {
  6475. if (this._onAddUndoListeners == null) {
  6476. this._onAddUndoListeners = new internal_1.ArrayList();
  6477. }
  6478. this._onAddUndoListeners.add(listener);
  6479. }
  6480. addOnRedoListener(listener) {
  6481. if (this._onRedoListeners == null) {
  6482. this._onRedoListeners = new internal_1.ArrayList();
  6483. }
  6484. this._onRedoListeners.add(listener);
  6485. }
  6486. addOnUndoListener(listener) {
  6487. if (this._onUndoListeners == null) {
  6488. this._onUndoListeners = new internal_1.ArrayList();
  6489. }
  6490. this._onUndoListeners.add(listener);
  6491. }
  6492. removeOnAddRedoListener(listener) {
  6493. if (this._onAddRedoListeners == null) {
  6494. return;
  6495. }
  6496. this._onAddRedoListeners.remove(listener);
  6497. }
  6498. removeOnAddUndoListener(listener) {
  6499. if (this._onAddUndoListeners == null) {
  6500. return;
  6501. }
  6502. this._onAddUndoListeners.remove(listener);
  6503. }
  6504. removeOnUndoListener(listener) {
  6505. if (this._onUndoListeners == null) {
  6506. return;
  6507. }
  6508. this._onUndoListeners.remove(listener);
  6509. }
  6510. removeOnRedoListener(listener) {
  6511. if (this._onRedoListeners == null) {
  6512. return;
  6513. }
  6514. this._onRedoListeners.remove(listener);
  6515. }
  6516. }
  6517. exports.UndoManagerObserver = UndoManagerObserver;
  6518. /***/ }),
  6519. /***/ "../ot-core/src/config/ClientSocketConfig.ts":
  6520. /*!***************************************************!*\
  6521. !*** ../ot-core/src/config/ClientSocketConfig.ts ***!
  6522. \***************************************************/
  6523. /***/ ((__unused_webpack_module, exports) => {
  6524. "use strict";
  6525. Object.defineProperty(exports, "__esModule", ({
  6526. value: true
  6527. }));
  6528. exports.ClientSocketConfig = void 0;
  6529. class ClientSocketConfig {}
  6530. exports.ClientSocketConfig = ClientSocketConfig;
  6531. /***/ }),
  6532. /***/ "../ot-core/src/index.ts":
  6533. /*!*******************************!*\
  6534. !*** ../ot-core/src/index.ts ***!
  6535. \*******************************/
  6536. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  6537. "use strict";
  6538. var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
  6539. if (k2 === undefined) k2 = k;
  6540. Object.defineProperty(o, k2, {
  6541. enumerable: true,
  6542. get: function () {
  6543. return m[k];
  6544. }
  6545. });
  6546. } : function (o, m, k, k2) {
  6547. if (k2 === undefined) k2 = k;
  6548. o[k2] = m[k];
  6549. });
  6550. var __exportStar = this && this.__exportStar || function (m, exports) {
  6551. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  6552. };
  6553. Object.defineProperty(exports, "__esModule", ({
  6554. value: true
  6555. }));
  6556. __exportStar(__webpack_require__(/*! ./internal */ "../ot-core/src/internal.ts"), exports);
  6557. /***/ }),
  6558. /***/ "../ot-core/src/internal.ts":
  6559. /*!**********************************!*\
  6560. !*** ../ot-core/src/internal.ts ***!
  6561. \**********************************/
  6562. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  6563. "use strict";
  6564. // ================================================= typed
  6565. var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
  6566. if (k2 === undefined) k2 = k;
  6567. Object.defineProperty(o, k2, {
  6568. enumerable: true,
  6569. get: function () {
  6570. return m[k];
  6571. }
  6572. });
  6573. } : function (o, m, k, k2) {
  6574. if (k2 === undefined) k2 = k;
  6575. o[k2] = m[k];
  6576. });
  6577. var __exportStar = this && this.__exportStar || function (m, exports) {
  6578. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  6579. };
  6580. Object.defineProperty(exports, "__esModule", ({
  6581. value: true
  6582. }));
  6583. __exportStar(__webpack_require__(/*! ./typed/GlobalType */ "../ot-core/src/typed/GlobalType.ts"), exports); // ================================================= utils
  6584. __exportStar(__webpack_require__(/*! ./utils/ArrayUtils */ "../ot-core/src/utils/ArrayUtils.ts"), exports);
  6585. __exportStar(__webpack_require__(/*! ./utils/TransformUtils */ "../ot-core/src/utils/TransformUtils.ts"), exports); // ================================================= config
  6586. __exportStar(__webpack_require__(/*! ./config/ClientSocketConfig */ "../ot-core/src/config/ClientSocketConfig.ts"), exports); // ================================================= library
  6587. __exportStar(__webpack_require__(/*! ./library/ArrayList */ "../ot-core/src/library/ArrayList.ts"), exports); // ================================================= basics
  6588. __exportStar(__webpack_require__(/*! ./basics/Command */ "../ot-core/src/basics/Command.ts"), exports);
  6589. __exportStar(__webpack_require__(/*! ./basics/Operation */ "../ot-core/src/basics/Operation.ts"), exports);
  6590. __exportStar(__webpack_require__(/*! ./basics/Conflict */ "../ot-core/src/basics/Conflict.ts"), exports);
  6591. __exportStar(__webpack_require__(/*! ./basics/Transform */ "../ot-core/src/basics/Transform.ts"), exports);
  6592. __exportStar(__webpack_require__(/*! ./basics/SwapData */ "../ot-core/src/basics/SwapData.ts"), exports);
  6593. __exportStar(__webpack_require__(/*! ./basics/Deserialize */ "../ot-core/src/basics/Deserialize.ts"), exports); // ================================================= client
  6594. __exportStar(__webpack_require__(/*! ./client/UndoManager */ "../ot-core/src/client/UndoManager.ts"), exports);
  6595. __exportStar(__webpack_require__(/*! ./client/AwaitingConfirm */ "../ot-core/src/client/AwaitingConfirm.ts"), exports);
  6596. __exportStar(__webpack_require__(/*! ./client/Synchronized */ "../ot-core/src/client/Synchronized.ts"), exports);
  6597. __exportStar(__webpack_require__(/*! ./client/AwaitingWithBuffer */ "../ot-core/src/client/AwaitingWithBuffer.ts"), exports);
  6598. __exportStar(__webpack_require__(/*! ./client/UndoManagerObserver */ "../ot-core/src/client/UndoManagerObserver.ts"), exports);
  6599. __exportStar(__webpack_require__(/*! ./client/Client */ "../ot-core/src/client/Client.ts"), exports);
  6600. __exportStar(__webpack_require__(/*! ./client/ClientSocket */ "../ot-core/src/client/ClientSocket.ts"), exports); // ================================================= server
  6601. __exportStar(__webpack_require__(/*! ./server/Response */ "../ot-core/src/server/Response.ts"), exports);
  6602. __exportStar(__webpack_require__(/*! ./server/User */ "../ot-core/src/server/User.ts"), exports);
  6603. __exportStar(__webpack_require__(/*! ./server/Server */ "../ot-core/src/server/Server.ts"), exports);
  6604. __exportStar(__webpack_require__(/*! ./server/ServerSocket */ "../ot-core/src/server/ServerSocket.ts"), exports);
  6605. /***/ }),
  6606. /***/ "../ot-core/src/library/ArrayList.ts":
  6607. /*!*******************************************!*\
  6608. !*** ../ot-core/src/library/ArrayList.ts ***!
  6609. \*******************************************/
  6610. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6611. "use strict";
  6612. Object.defineProperty(exports, "__esModule", ({
  6613. value: true
  6614. }));
  6615. exports.ArrayList = void 0;
  6616. const TransformUtils_1 = __webpack_require__(/*! ../utils/TransformUtils */ "../ot-core/src/utils/TransformUtils.ts");
  6617. class ArrayList {
  6618. constructor() {
  6619. this._arraylist = new Array();
  6620. }
  6621. get(index) {
  6622. return this._arraylist[index];
  6623. }
  6624. sizeof() {
  6625. return this._arraylist.length;
  6626. }
  6627. add(value) {
  6628. this._arraylist.push(value);
  6629. }
  6630. remove(...parameter) {
  6631. if (TransformUtils_1.TransformUtils.hasLength(parameter, 1)) {
  6632. if (TransformUtils_1.TransformUtils.isNumber(parameter[0])) {
  6633. const index = parameter[0];
  6634. this._arraylist.splice(index, 1);
  6635. return;
  6636. }
  6637. if (TransformUtils_1.TransformUtils.isObject(parameter[0])) {
  6638. const value = parameter[0];
  6639. const arraylist = this._arraylist;
  6640. const sizeof = arraylist.length;
  6641. for (let i = 0; i < sizeof; i++) {
  6642. const item = arraylist[i];
  6643. if (item === value) {
  6644. this._arraylist.splice(i, 1);
  6645. return;
  6646. }
  6647. }
  6648. }
  6649. }
  6650. }
  6651. }
  6652. exports.ArrayList = ArrayList;
  6653. /***/ }),
  6654. /***/ "../ot-core/src/server/Response.ts":
  6655. /*!*****************************************!*\
  6656. !*** ../ot-core/src/server/Response.ts ***!
  6657. \*****************************************/
  6658. /***/ ((__unused_webpack_module, exports) => {
  6659. "use strict";
  6660. Object.defineProperty(exports, "__esModule", ({
  6661. value: true
  6662. }));
  6663. /***/ }),
  6664. /***/ "../ot-core/src/server/Server.ts":
  6665. /*!***************************************!*\
  6666. !*** ../ot-core/src/server/Server.ts ***!
  6667. \***************************************/
  6668. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6669. "use strict";
  6670. Object.defineProperty(exports, "__esModule", ({
  6671. value: true
  6672. }));
  6673. exports.Server = void 0;
  6674. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6675. class Server {
  6676. constructor(conflict) {
  6677. this._chronicle = new Array();
  6678. this._transform = new internal_1.Transform(conflict);
  6679. }
  6680. receiveCommand(revision, command) {
  6681. if (revision < 0 || this._chronicle.length < revision) {
  6682. throw new Error("command revision not in history");
  6683. }
  6684. let history = this._chronicle.slice(revision);
  6685. for (let i = 0; i < history.length; i++) {
  6686. const saved = history[i];
  6687. if (command.getGroupId() === saved.getGroupId()) {
  6688. command = this._transform.transfer(command, saved)[0];
  6689. }
  6690. }
  6691. this._chronicle.push(command);
  6692. }
  6693. getRevision() {
  6694. return this._chronicle.length;
  6695. }
  6696. }
  6697. exports.Server = Server;
  6698. /***/ }),
  6699. /***/ "../ot-core/src/server/ServerSocket.ts":
  6700. /*!*********************************************!*\
  6701. !*** ../ot-core/src/server/ServerSocket.ts ***!
  6702. \*********************************************/
  6703. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6704. "use strict";
  6705. Object.defineProperty(exports, "__esModule", ({
  6706. value: true
  6707. }));
  6708. exports.ServerSocket = void 0;
  6709. const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
  6710. class ServerSocket extends internal_1.Server {
  6711. constructor(...parameter) {
  6712. if (internal_1.TransformUtils.hasLength(parameter, 1)) {
  6713. const conflict = parameter[0];
  6714. super(conflict);
  6715. this._roomId = 'empty';
  6716. this._users = [];
  6717. this._source = null;
  6718. return;
  6719. }
  6720. if (internal_1.TransformUtils.hasLength(parameter, 2)) {
  6721. const conflict = parameter[0];
  6722. const source = parameter[1];
  6723. super(conflict);
  6724. this._roomId = 'empty';
  6725. this._users = [];
  6726. this._source = source;
  6727. }
  6728. }
  6729. receiveCommand(revision, command) {
  6730. super.receiveCommand(revision, command);
  6731. command.apply(this._source);
  6732. }
  6733. addSocketClient(client) {
  6734. client.join(this._roomId);
  6735. client.on('command', (revision, command) => {
  6736. this.onCommand(client, revision, command);
  6737. });
  6738. client.on('disconnect', () => {
  6739. this.onDisconnect(client);
  6740. });
  6741. client.emit('open', {
  6742. revision: this.getRevision(),
  6743. clients: this._users,
  6744. roomId: this._roomId,
  6745. source: this._source
  6746. });
  6747. }
  6748. onCommand(client, revision, command) {
  6749. const deserialize = internal_1.Deserialize.getInstance().formObject(command);
  6750. let clientId = client.id;
  6751. this.receiveCommand(revision, deserialize);
  6752. client.emit('ack');
  6753. client.broadcast.in(this._roomId).emit('command', clientId, deserialize.toJSON());
  6754. }
  6755. onDisconnect(client) {
  6756. console.log('Disconnect');
  6757. }
  6758. }
  6759. exports.ServerSocket = ServerSocket;
  6760. /***/ }),
  6761. /***/ "../ot-core/src/server/User.ts":
  6762. /*!*************************************!*\
  6763. !*** ../ot-core/src/server/User.ts ***!
  6764. \*************************************/
  6765. /***/ ((__unused_webpack_module, exports) => {
  6766. "use strict";
  6767. Object.defineProperty(exports, "__esModule", ({
  6768. value: true
  6769. }));
  6770. exports.User = void 0;
  6771. class User {}
  6772. exports.User = User;
  6773. /***/ }),
  6774. /***/ "../ot-core/src/typed/GlobalType.ts":
  6775. /*!******************************************!*\
  6776. !*** ../ot-core/src/typed/GlobalType.ts ***!
  6777. \******************************************/
  6778. /***/ ((__unused_webpack_module, exports) => {
  6779. "use strict";
  6780. Object.defineProperty(exports, "__esModule", ({
  6781. value: true
  6782. }));
  6783. /***/ }),
  6784. /***/ "../ot-core/src/utils/ArrayUtils.ts":
  6785. /*!******************************************!*\
  6786. !*** ../ot-core/src/utils/ArrayUtils.ts ***!
  6787. \******************************************/
  6788. /***/ ((__unused_webpack_module, exports) => {
  6789. "use strict";
  6790. Object.defineProperty(exports, "__esModule", ({
  6791. value: true
  6792. }));
  6793. exports.ArrayUtils = void 0;
  6794. class ArrayUtils {}
  6795. exports.ArrayUtils = ArrayUtils;
  6796. /***/ }),
  6797. /***/ "../ot-core/src/utils/TransformUtils.ts":
  6798. /*!**********************************************!*\
  6799. !*** ../ot-core/src/utils/TransformUtils.ts ***!
  6800. \**********************************************/
  6801. /***/ ((__unused_webpack_module, exports) => {
  6802. "use strict";
  6803. Object.defineProperty(exports, "__esModule", ({
  6804. value: true
  6805. }));
  6806. exports.TransformUtils = void 0;
  6807. class TransformUtils {
  6808. static getValueType(value) {
  6809. return Object.prototype.toString.apply(value);
  6810. }
  6811. static isBoolean(value) {
  6812. return this.getValueType(value) === '[object Boolean]';
  6813. }
  6814. static isString(value) {
  6815. return this.getValueType(value) === '[object String]';
  6816. }
  6817. static isFunction(value) {
  6818. return this.getValueType(value) === '[object Function]';
  6819. }
  6820. static isNumber(value) {
  6821. return this.getValueType(value) === '[object Number]';
  6822. }
  6823. static isDefine(value) {
  6824. return value !== undefined && value !== null;
  6825. }
  6826. static unDefine(value) {
  6827. return value === undefined || value === null;
  6828. }
  6829. static isBlank(value) {
  6830. if (!this.isDefine(value)) {
  6831. return true;
  6832. }
  6833. if (this.isString(value)) {
  6834. return value.trim() === '';
  6835. }
  6836. return false;
  6837. }
  6838. static isConstructor(clazz) {
  6839. return clazz.prototype.constructor === clazz;
  6840. }
  6841. static isAssignableFrom(object, clazz) {
  6842. return object instanceof clazz;
  6843. }
  6844. static isObject(value) {
  6845. return this.getValueType(value) === '[object Object]';
  6846. }
  6847. static isPlainObject(value) {
  6848. if (!this.isDefine(value)) {
  6849. return false;
  6850. }
  6851. return Object.getPrototypeOf(value) === Object.getPrototypeOf({});
  6852. }
  6853. static isArray(value, clazz) {
  6854. let type = this.getValueType(value) === '[object Array]';
  6855. if (type) {
  6856. if (TransformUtils.isDefine(clazz)) {
  6857. value = value;
  6858. if (value.length) {
  6859. return value[0] instanceof clazz;
  6860. }
  6861. }
  6862. return true;
  6863. }
  6864. return false;
  6865. }
  6866. static copy(src, target) {
  6867. Object.assign(src, target);
  6868. }
  6869. static hasLength(target, length) {
  6870. return target.length === length;
  6871. }
  6872. }
  6873. exports.TransformUtils = TransformUtils;
  6874. /***/ }),
  6875. /***/ "./src/basics/Bootstrap.ts":
  6876. /*!*********************************!*\
  6877. !*** ./src/basics/Bootstrap.ts ***!
  6878. \*********************************/
  6879. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6880. "use strict";
  6881. Object.defineProperty(exports, "__esModule", ({
  6882. value: true
  6883. }));
  6884. var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
  6885. var internal_1 = __webpack_require__(/*! ../internal */ "./src/internal.ts");
  6886. var deserialize = ot_core_1.Deserialize.getInstance();
  6887. deserialize.addClass('InsertColumn', internal_1.InsertColumn);
  6888. deserialize.addClass('InsertRow', internal_1.InsertRow);
  6889. deserialize.addClass('RemoveColumn', internal_1.RemoveColumn);
  6890. deserialize.addClass('RemoveRow', internal_1.RemoveRow);
  6891. /***/ }),
  6892. /***/ "./src/basics/CreateConflict.ts":
  6893. /*!**************************************!*\
  6894. !*** ./src/basics/CreateConflict.ts ***!
  6895. \**************************************/
  6896. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6897. "use strict";
  6898. Object.defineProperty(exports, "__esModule", ({
  6899. value: true
  6900. }));
  6901. exports.CreateConflict = void 0;
  6902. var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
  6903. var internal_1 = __webpack_require__(/*! ../internal */ "./src/internal.ts");
  6904. function CreateConflict() {
  6905. var conflict = new ot_core_1.Conflict();
  6906. conflict.add(internal_1.InsertRow, internal_1.InsertRow, function (targetCommand, savedCommand) {
  6907. return function (targetOperation, savedOperation) {
  6908. /**
  6909. * 服务端插入的行在当前行的下方
  6910. */
  6911. if (targetOperation.getHeight() <= savedOperation.getIndex()) {
  6912. var offset = savedOperation.getIndex() + targetOperation.getCount();
  6913. savedOperation.setIndex(savedOperation.getIndex() + offset);
  6914. targetCommand.addOperation(targetOperation);
  6915. savedCommand.addOperation(savedOperation);
  6916. }
  6917. /**
  6918. * 服务端插入的行在当前行的上方
  6919. */
  6920. if (targetOperation.getIndex() >= savedOperation.getHeight()) {
  6921. var _offset = targetOperation.getIndex() + savedOperation.getCount();
  6922. targetOperation.setIndex(targetOperation.getIndex() + _offset);
  6923. targetCommand.addOperation(targetOperation);
  6924. savedCommand.addOperation(savedOperation);
  6925. }
  6926. /**
  6927. * 服务端插入的行被当前行包含
  6928. */
  6929. if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
  6930. var spliceCursor = savedOperation.getIndex() - targetOperation.getIndex();
  6931. var prevDataBuffer = targetOperation.getBuffer().getData().splice(0, spliceCursor);
  6932. var nextDataBuffer = targetOperation.getBuffer().getData().splice(spliceCursor);
  6933. var prevOperation = new internal_1.InsertRow({
  6934. describe: 'InsertRowOperation',
  6935. buffer: new ot_core_1.SwapData({
  6936. data: prevDataBuffer,
  6937. describe: 'DataBuffer'
  6938. }),
  6939. index: targetOperation.getIndex(),
  6940. count: savedOperation.getIndex() - targetOperation.getIndex()
  6941. });
  6942. var nextOperation = new internal_1.InsertRow({
  6943. describe: 'InsertRowOperation',
  6944. buffer: new ot_core_1.SwapData({
  6945. data: nextDataBuffer,
  6946. describe: 'DataBuffer'
  6947. }),
  6948. index: savedOperation.getCount(),
  6949. count: targetOperation.getHeight() - savedOperation.getIndex()
  6950. });
  6951. targetCommand.addOperation(prevOperation);
  6952. targetCommand.addOperation(nextOperation);
  6953. }
  6954. /**
  6955. * 服务端插入的行包含当前行
  6956. */
  6957. if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {// TODO ....
  6958. }
  6959. /**
  6960. * 服务端插入的行和当前行上交叉
  6961. */
  6962. if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {// TODO ..
  6963. // ...
  6964. }
  6965. /**
  6966. * 服务端插入的行和当前行下交叉
  6967. */
  6968. if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {// TODO ...
  6969. //
  6970. }
  6971. };
  6972. });
  6973. return conflict;
  6974. }
  6975. exports.CreateConflict = CreateConflict;
  6976. /***/ }),
  6977. /***/ "./src/internal.ts":
  6978. /*!*************************!*\
  6979. !*** ./src/internal.ts ***!
  6980. \*************************/
  6981. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  6982. "use strict";
  6983. var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
  6984. if (k2 === undefined) k2 = k;
  6985. Object.defineProperty(o, k2, {
  6986. enumerable: true,
  6987. get: function get() {
  6988. return m[k];
  6989. }
  6990. });
  6991. } : function (o, m, k, k2) {
  6992. if (k2 === undefined) k2 = k;
  6993. o[k2] = m[k];
  6994. });
  6995. var __exportStar = this && this.__exportStar || function (m, exports) {
  6996. for (var p in m) {
  6997. if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  6998. }
  6999. };
  7000. Object.defineProperty(exports, "__esModule", ({
  7001. value: true
  7002. }));
  7003. __exportStar(__webpack_require__(/*! ./operated/InsertColumn */ "./src/operated/InsertColumn.ts"), exports);
  7004. __exportStar(__webpack_require__(/*! ./operated/InsertRow */ "./src/operated/InsertRow.ts"), exports);
  7005. __exportStar(__webpack_require__(/*! ./operated/RemoveColumn */ "./src/operated/RemoveColumn.ts"), exports);
  7006. __exportStar(__webpack_require__(/*! ./operated/RemoveRow */ "./src/operated/RemoveRow.ts"), exports);
  7007. __exportStar(__webpack_require__(/*! ./basics/CreateConflict */ "./src/basics/CreateConflict.ts"), exports);
  7008. /***/ }),
  7009. /***/ "./src/operated/InsertColumn.ts":
  7010. /*!**************************************!*\
  7011. !*** ./src/operated/InsertColumn.ts ***!
  7012. \**************************************/
  7013. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7014. "use strict";
  7015. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7016. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7017. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  7018. Object.defineProperty(exports, "__esModule", ({
  7019. value: true
  7020. }));
  7021. exports.InsertColumn = void 0;
  7022. var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
  7023. var InsertColumn = /*#__PURE__*/function () {
  7024. function InsertColumn() {
  7025. _classCallCheck(this, InsertColumn);
  7026. this._describe = 'InsertColumn';
  7027. for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
  7028. parameter[_key] = arguments[_key];
  7029. }
  7030. if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
  7031. this._index = 0;
  7032. this._count = 0;
  7033. this._buffer = new ot_core_1.SwapData();
  7034. return;
  7035. }
  7036. if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
  7037. var serialize = parameter[0];
  7038. this._index = serialize.index;
  7039. this._count = serialize.count;
  7040. this._buffer = ot_core_1.Deserialize.getInstance().formObject(serialize.buffer, new ot_core_1.SwapData());
  7041. }
  7042. }
  7043. _createClass(InsertColumn, [{
  7044. key: "apply",
  7045. value: function apply(resource) {}
  7046. }, {
  7047. key: "setIndex",
  7048. value: function setIndex(index) {
  7049. this._index = index;
  7050. }
  7051. }, {
  7052. key: "setCount",
  7053. value: function setCount(count) {
  7054. this._count = count;
  7055. }
  7056. }, {
  7057. key: "getIndex",
  7058. value: function getIndex() {
  7059. return this._index;
  7060. }
  7061. }, {
  7062. key: "getCount",
  7063. value: function getCount() {
  7064. return this._count;
  7065. }
  7066. }, {
  7067. key: "clone",
  7068. value: function clone() {
  7069. var clone = new InsertColumn();
  7070. clone._index = this._index;
  7071. clone._count = this._count;
  7072. clone._buffer = this._buffer.clone();
  7073. return clone;
  7074. }
  7075. }, {
  7076. key: "toJSON",
  7077. value: function toJSON() {
  7078. return {
  7079. describe: this._describe,
  7080. index: this._index,
  7081. count: this._count,
  7082. buffer: this._buffer
  7083. };
  7084. }
  7085. }]);
  7086. return InsertColumn;
  7087. }();
  7088. exports.InsertColumn = InsertColumn;
  7089. /***/ }),
  7090. /***/ "./src/operated/InsertRow.ts":
  7091. /*!***********************************!*\
  7092. !*** ./src/operated/InsertRow.ts ***!
  7093. \***********************************/
  7094. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7095. "use strict";
  7096. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  7097. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  7098. 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); }
  7099. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
  7100. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  7101. 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; }
  7102. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7103. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7104. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  7105. Object.defineProperty(exports, "__esModule", ({
  7106. value: true
  7107. }));
  7108. exports.InsertRow = void 0;
  7109. var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
  7110. var InsertRow = /*#__PURE__*/function () {
  7111. function InsertRow() {
  7112. _classCallCheck(this, InsertRow);
  7113. this._describe = 'InsertRow';
  7114. for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
  7115. parameter[_key] = arguments[_key];
  7116. }
  7117. if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
  7118. this._index = 0;
  7119. this._count = 0;
  7120. this._buffer = new ot_core_1.SwapData();
  7121. return;
  7122. }
  7123. if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
  7124. var serialize = parameter[0];
  7125. this._index = serialize.index;
  7126. this._count = serialize.count;
  7127. this._buffer = ot_core_1.Deserialize.getInstance().formObject(serialize.buffer, new ot_core_1.SwapData());
  7128. }
  7129. }
  7130. _createClass(InsertRow, [{
  7131. key: "apply",
  7132. value: function apply(resource) {
  7133. var data = this._buffer.getData();
  7134. var index = this._index;
  7135. var count = this._count;
  7136. if (data) {
  7137. resource.splice.apply(resource, [index, 0].concat(_toConsumableArray(data)));
  7138. } else {
  7139. var empty = new Array(count).fill([]);
  7140. resource.splice.apply(resource, [index, 0].concat(_toConsumableArray(empty)));
  7141. }
  7142. }
  7143. }, {
  7144. key: "setIndex",
  7145. value: function setIndex(index) {
  7146. this._index = index;
  7147. }
  7148. }, {
  7149. key: "setCount",
  7150. value: function setCount(count) {
  7151. this._count = count;
  7152. }
  7153. }, {
  7154. key: "getIndex",
  7155. value: function getIndex() {
  7156. return this._index;
  7157. }
  7158. }, {
  7159. key: "getCount",
  7160. value: function getCount() {
  7161. return this._count;
  7162. }
  7163. }, {
  7164. key: "getHeight",
  7165. value: function getHeight() {
  7166. return this._index + this._count;
  7167. }
  7168. }, {
  7169. key: "getBuffer",
  7170. value: function getBuffer() {
  7171. return this._buffer;
  7172. }
  7173. }, {
  7174. key: "clone",
  7175. value: function clone() {
  7176. var clone = new InsertRow();
  7177. clone._index = this._index;
  7178. clone._count = this._count;
  7179. clone._buffer = this._buffer.clone();
  7180. return clone;
  7181. }
  7182. }, {
  7183. key: "toJSON",
  7184. value: function toJSON() {
  7185. return {
  7186. describe: this._describe,
  7187. index: this._index,
  7188. count: this._count,
  7189. buffer: this._buffer
  7190. };
  7191. }
  7192. }]);
  7193. return InsertRow;
  7194. }();
  7195. exports.InsertRow = InsertRow;
  7196. /***/ }),
  7197. /***/ "./src/operated/RemoveColumn.ts":
  7198. /*!**************************************!*\
  7199. !*** ./src/operated/RemoveColumn.ts ***!
  7200. \**************************************/
  7201. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7202. "use strict";
  7203. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7204. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7205. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  7206. Object.defineProperty(exports, "__esModule", ({
  7207. value: true
  7208. }));
  7209. exports.RemoveColumn = void 0;
  7210. var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
  7211. var RemoveColumn = /*#__PURE__*/function () {
  7212. function RemoveColumn() {
  7213. _classCallCheck(this, RemoveColumn);
  7214. this._describe = 'RemoveColumn';
  7215. for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
  7216. parameter[_key] = arguments[_key];
  7217. }
  7218. if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
  7219. this._index = 0;
  7220. this._count = 0;
  7221. this._buffer = new ot_core_1.SwapData();
  7222. return;
  7223. }
  7224. if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
  7225. var serialize = parameter[0];
  7226. this._index = serialize.index;
  7227. this._count = serialize.count;
  7228. return;
  7229. }
  7230. if (ot_core_1.TransformUtils.hasLength(parameter, 2)) {
  7231. var _serialize = parameter[0];
  7232. var buffer = parameter[1];
  7233. this._index = _serialize.index;
  7234. this._count = _serialize.count;
  7235. this._buffer = buffer;
  7236. }
  7237. }
  7238. _createClass(RemoveColumn, [{
  7239. key: "apply",
  7240. value: function apply(resource) {}
  7241. }, {
  7242. key: "setIndex",
  7243. value: function setIndex(index) {
  7244. this._index = index;
  7245. }
  7246. }, {
  7247. key: "setCount",
  7248. value: function setCount(count) {
  7249. this._count = count;
  7250. }
  7251. }, {
  7252. key: "getIndex",
  7253. value: function getIndex() {
  7254. return this._index;
  7255. }
  7256. }, {
  7257. key: "getCount",
  7258. value: function getCount() {
  7259. return this._count;
  7260. }
  7261. }, {
  7262. key: "clone",
  7263. value: function clone() {
  7264. var clone = new RemoveColumn();
  7265. clone._index = this._index;
  7266. clone._count = this._count;
  7267. clone._buffer = this._buffer.clone();
  7268. return clone;
  7269. }
  7270. }, {
  7271. key: "toJSON",
  7272. value: function toJSON() {
  7273. return {
  7274. describe: this._describe,
  7275. index: this._index,
  7276. count: this._count
  7277. };
  7278. }
  7279. }]);
  7280. return RemoveColumn;
  7281. }();
  7282. exports.RemoveColumn = RemoveColumn;
  7283. /***/ }),
  7284. /***/ "./src/operated/RemoveRow.ts":
  7285. /*!***********************************!*\
  7286. !*** ./src/operated/RemoveRow.ts ***!
  7287. \***********************************/
  7288. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7289. "use strict";
  7290. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7291. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7292. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  7293. Object.defineProperty(exports, "__esModule", ({
  7294. value: true
  7295. }));
  7296. exports.RemoveRow = void 0;
  7297. var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
  7298. var RemoveRow = /*#__PURE__*/function () {
  7299. function RemoveRow() {
  7300. _classCallCheck(this, RemoveRow);
  7301. this._describe = 'RemoveRow';
  7302. for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
  7303. parameter[_key] = arguments[_key];
  7304. }
  7305. if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
  7306. this._index = 0;
  7307. this._count = 0;
  7308. this._buffer = new ot_core_1.SwapData();
  7309. return;
  7310. }
  7311. if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
  7312. var serialize = parameter[0];
  7313. this._index = serialize.index;
  7314. this._count = serialize.count;
  7315. return;
  7316. }
  7317. if (ot_core_1.TransformUtils.hasLength(parameter, 2)) {
  7318. var _serialize = parameter[0];
  7319. var buffer = parameter[1];
  7320. this._index = _serialize.index;
  7321. this._count = _serialize.count;
  7322. this._buffer = buffer;
  7323. }
  7324. }
  7325. _createClass(RemoveRow, [{
  7326. key: "apply",
  7327. value: function apply(resource) {}
  7328. }, {
  7329. key: "setIndex",
  7330. value: function setIndex(index) {
  7331. this._index = index;
  7332. }
  7333. }, {
  7334. key: "setCount",
  7335. value: function setCount(count) {
  7336. this._count = count;
  7337. }
  7338. }, {
  7339. key: "getIndex",
  7340. value: function getIndex() {
  7341. return this._index;
  7342. }
  7343. }, {
  7344. key: "getCount",
  7345. value: function getCount() {
  7346. return this._count;
  7347. }
  7348. }, {
  7349. key: "clone",
  7350. value: function clone() {
  7351. var clone = new RemoveRow();
  7352. clone._index = this._index;
  7353. clone._count = this._count;
  7354. clone._buffer = this._buffer.clone();
  7355. return clone;
  7356. }
  7357. }, {
  7358. key: "toJSON",
  7359. value: function toJSON() {
  7360. return {
  7361. describe: this._describe,
  7362. index: this._index,
  7363. count: this._count
  7364. };
  7365. }
  7366. }]);
  7367. return RemoveRow;
  7368. }();
  7369. exports.RemoveRow = RemoveRow;
  7370. /***/ }),
  7371. /***/ "./src/server.ts":
  7372. /*!***********************!*\
  7373. !*** ./src/server.ts ***!
  7374. \***********************/
  7375. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  7376. "use strict";
  7377. var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
  7378. if (k2 === undefined) k2 = k;
  7379. Object.defineProperty(o, k2, {
  7380. enumerable: true,
  7381. get: function get() {
  7382. return m[k];
  7383. }
  7384. });
  7385. } : function (o, m, k, k2) {
  7386. if (k2 === undefined) k2 = k;
  7387. o[k2] = m[k];
  7388. });
  7389. var __exportStar = this && this.__exportStar || function (m, exports) {
  7390. for (var p in m) {
  7391. if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
  7392. }
  7393. };
  7394. Object.defineProperty(exports, "__esModule", ({
  7395. value: true
  7396. }));
  7397. __exportStar(__webpack_require__(/*! ./server/Server */ "./src/server/Server.ts"), exports);
  7398. /***/ }),
  7399. /***/ "./src/server/Server.ts":
  7400. /*!******************************!*\
  7401. !*** ./src/server/Server.ts ***!
  7402. \******************************/
  7403. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7404. "use strict";
  7405. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7406. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7407. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7408. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  7409. function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
  7410. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  7411. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7412. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  7413. 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); }; }
  7414. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  7415. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  7416. 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; } }
  7417. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  7418. Object.defineProperty(exports, "__esModule", ({
  7419. value: true
  7420. }));
  7421. exports.Server = void 0;
  7422. var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
  7423. var internal_1 = __webpack_require__(/*! ../internal */ "./src/internal.ts");
  7424. __webpack_require__(/*! ../basics/Bootstrap */ "./src/basics/Bootstrap.ts");
  7425. var Server = /*#__PURE__*/function (_ot_core_1$ServerSock) {
  7426. _inherits(Server, _ot_core_1$ServerSock);
  7427. var _super = _createSuper(Server);
  7428. function Server() {
  7429. _classCallCheck(this, Server);
  7430. return _super.call(this, (0, internal_1.CreateConflict)(), []);
  7431. }
  7432. _createClass(Server, [{
  7433. key: "onCommand",
  7434. value: function onCommand(client, revision, command) {
  7435. _get(_getPrototypeOf(Server.prototype), "onCommand", this).call(this, client, revision, command);
  7436. console.log(this._source);
  7437. }
  7438. }]);
  7439. return Server;
  7440. }(ot_core_1.ServerSocket);
  7441. exports.Server = Server;
  7442. /***/ }),
  7443. /***/ "child_process":
  7444. /*!********************************!*\
  7445. !*** external "child_process" ***!
  7446. \********************************/
  7447. /***/ ((module) => {
  7448. "use strict";
  7449. module.exports = require("child_process");
  7450. /***/ }),
  7451. /***/ "crypto":
  7452. /*!*************************!*\
  7453. !*** external "crypto" ***!
  7454. \*************************/
  7455. /***/ ((module) => {
  7456. "use strict";
  7457. module.exports = require("crypto");
  7458. /***/ }),
  7459. /***/ "events":
  7460. /*!*************************!*\
  7461. !*** external "events" ***!
  7462. \*************************/
  7463. /***/ ((module) => {
  7464. "use strict";
  7465. module.exports = require("events");
  7466. /***/ }),
  7467. /***/ "fs":
  7468. /*!*********************!*\
  7469. !*** external "fs" ***!
  7470. \*********************/
  7471. /***/ ((module) => {
  7472. "use strict";
  7473. module.exports = require("fs");
  7474. /***/ }),
  7475. /***/ "http":
  7476. /*!***********************!*\
  7477. !*** external "http" ***!
  7478. \***********************/
  7479. /***/ ((module) => {
  7480. "use strict";
  7481. module.exports = require("http");
  7482. /***/ }),
  7483. /***/ "https":
  7484. /*!************************!*\
  7485. !*** external "https" ***!
  7486. \************************/
  7487. /***/ ((module) => {
  7488. "use strict";
  7489. module.exports = require("https");
  7490. /***/ }),
  7491. /***/ "net":
  7492. /*!**********************!*\
  7493. !*** external "net" ***!
  7494. \**********************/
  7495. /***/ ((module) => {
  7496. "use strict";
  7497. module.exports = require("net");
  7498. /***/ }),
  7499. /***/ "os":
  7500. /*!*********************!*\
  7501. !*** external "os" ***!
  7502. \*********************/
  7503. /***/ ((module) => {
  7504. "use strict";
  7505. module.exports = require("os");
  7506. /***/ }),
  7507. /***/ "stream":
  7508. /*!*************************!*\
  7509. !*** external "stream" ***!
  7510. \*************************/
  7511. /***/ ((module) => {
  7512. "use strict";
  7513. module.exports = require("stream");
  7514. /***/ }),
  7515. /***/ "tls":
  7516. /*!**********************!*\
  7517. !*** external "tls" ***!
  7518. \**********************/
  7519. /***/ ((module) => {
  7520. "use strict";
  7521. module.exports = require("tls");
  7522. /***/ }),
  7523. /***/ "tty":
  7524. /*!**********************!*\
  7525. !*** external "tty" ***!
  7526. \**********************/
  7527. /***/ ((module) => {
  7528. "use strict";
  7529. module.exports = require("tty");
  7530. /***/ }),
  7531. /***/ "url":
  7532. /*!**********************!*\
  7533. !*** external "url" ***!
  7534. \**********************/
  7535. /***/ ((module) => {
  7536. "use strict";
  7537. module.exports = require("url");
  7538. /***/ }),
  7539. /***/ "util":
  7540. /*!***********************!*\
  7541. !*** external "util" ***!
  7542. \***********************/
  7543. /***/ ((module) => {
  7544. "use strict";
  7545. module.exports = require("util");
  7546. /***/ }),
  7547. /***/ "zlib":
  7548. /*!***********************!*\
  7549. !*** external "zlib" ***!
  7550. \***********************/
  7551. /***/ ((module) => {
  7552. "use strict";
  7553. module.exports = require("zlib");
  7554. /***/ }),
  7555. /***/ "bufferutil":
  7556. /*!*****************************!*\
  7557. !*** external "bufferutil" ***!
  7558. \*****************************/
  7559. /***/ ((module) => {
  7560. "use strict";
  7561. if(typeof __WEBPACK_EXTERNAL_MODULE_bufferutil__ === 'undefined') { var e = new Error("Cannot find module 'bufferutil'"); e.code = 'MODULE_NOT_FOUND'; throw e; }
  7562. module.exports = __WEBPACK_EXTERNAL_MODULE_bufferutil__;
  7563. /***/ }),
  7564. /***/ "utf-8-validate":
  7565. /*!*********************************!*\
  7566. !*** external "utf-8-validate" ***!
  7567. \*********************************/
  7568. /***/ ((module) => {
  7569. "use strict";
  7570. if(typeof __WEBPACK_EXTERNAL_MODULE_utf_8_validate__ === 'undefined') { var e = new Error("Cannot find module 'utf-8-validate'"); e.code = 'MODULE_NOT_FOUND'; throw e; }
  7571. module.exports = __WEBPACK_EXTERNAL_MODULE_utf_8_validate__;
  7572. /***/ }),
  7573. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js":
  7574. /*!************************************************************************!*\
  7575. !*** ../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js ***!
  7576. \************************************************************************/
  7577. /***/ ((__unused_webpack_module, exports) => {
  7578. "use strict";
  7579. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7580. exports["default"] = global;
  7581. /***/ }),
  7582. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/index.js":
  7583. /*!*******************************************************************!*\
  7584. !*** ../ot-core/node_modules/engine.io-client/build/cjs/index.js ***!
  7585. \*******************************************************************/
  7586. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7587. "use strict";
  7588. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7589. exports.installTimerFunctions = exports.transports = exports.Transport = exports.protocol = exports.Socket = void 0;
  7590. const socket_js_1 = __webpack_require__(/*! ./socket.js */ "../ot-core/node_modules/engine.io-client/build/cjs/socket.js");
  7591. Object.defineProperty(exports, "Socket", ({ enumerable: true, get: function () { return socket_js_1.Socket; } }));
  7592. exports.protocol = socket_js_1.Socket.protocol;
  7593. var transport_js_1 = __webpack_require__(/*! ./transport.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js");
  7594. Object.defineProperty(exports, "Transport", ({ enumerable: true, get: function () { return transport_js_1.Transport; } }));
  7595. var index_js_1 = __webpack_require__(/*! ./transports/index.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js");
  7596. Object.defineProperty(exports, "transports", ({ enumerable: true, get: function () { return index_js_1.transports; } }));
  7597. var util_js_1 = __webpack_require__(/*! ./util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
  7598. Object.defineProperty(exports, "installTimerFunctions", ({ enumerable: true, get: function () { return util_js_1.installTimerFunctions; } }));
  7599. /***/ }),
  7600. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/socket.js":
  7601. /*!********************************************************************!*\
  7602. !*** ../ot-core/node_modules/engine.io-client/build/cjs/socket.js ***!
  7603. \********************************************************************/
  7604. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  7605. "use strict";
  7606. var __importDefault = (this && this.__importDefault) || function (mod) {
  7607. return (mod && mod.__esModule) ? mod : { "default": mod };
  7608. };
  7609. Object.defineProperty(exports, "__esModule", ({ value: true }));
  7610. exports.Socket = void 0;
  7611. const index_js_1 = __webpack_require__(/*! ./transports/index.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js");
  7612. const util_js_1 = __webpack_require__(/*! ./util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
  7613. const parseqs_1 = __importDefault(__webpack_require__(/*! parseqs */ "../ot-core/node_modules/parseqs/index.js"));
  7614. const parseuri_1 = __importDefault(__webpack_require__(/*! parseuri */ "../ot-core/node_modules/parseuri/index.js"));
  7615. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  7616. const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
  7617. const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
  7618. const debug = (0, debug_1.default)("engine.io-client:socket"); // debug()
  7619. class Socket extends component_emitter_1.Emitter {
  7620. /**
  7621. * Socket constructor.
  7622. *
  7623. * @param {String|Object} uri or options
  7624. * @param {Object} opts - options
  7625. * @api public
  7626. */
  7627. constructor(uri, opts = {}) {
  7628. super();
  7629. if (uri && "object" === typeof uri) {
  7630. opts = uri;
  7631. uri = null;
  7632. }
  7633. if (uri) {
  7634. uri = (0, parseuri_1.default)(uri);
  7635. opts.hostname = uri.host;
  7636. opts.secure = uri.protocol === "https" || uri.protocol === "wss";
  7637. opts.port = uri.port;
  7638. if (uri.query)
  7639. opts.query = uri.query;
  7640. }
  7641. else if (opts.host) {
  7642. opts.hostname = (0, parseuri_1.default)(opts.host).host;
  7643. }
  7644. (0, util_js_1.installTimerFunctions)(this, opts);
  7645. this.secure =
  7646. null != opts.secure
  7647. ? opts.secure
  7648. : typeof location !== "undefined" && "https:" === location.protocol;
  7649. if (opts.hostname && !opts.port) {
  7650. // if no port is specified manually, use the protocol default
  7651. opts.port = this.secure ? "443" : "80";
  7652. }
  7653. this.hostname =
  7654. opts.hostname ||
  7655. (typeof location !== "undefined" ? location.hostname : "localhost");
  7656. this.port =
  7657. opts.port ||
  7658. (typeof location !== "undefined" && location.port
  7659. ? location.port
  7660. : this.secure
  7661. ? "443"
  7662. : "80");
  7663. this.transports = opts.transports || ["polling", "websocket"];
  7664. this.readyState = "";
  7665. this.writeBuffer = [];
  7666. this.prevBufferLen = 0;
  7667. this.opts = Object.assign({
  7668. path: "/engine.io",
  7669. agent: false,
  7670. withCredentials: false,
  7671. upgrade: true,
  7672. timestampParam: "t",
  7673. rememberUpgrade: false,
  7674. rejectUnauthorized: true,
  7675. perMessageDeflate: {
  7676. threshold: 1024
  7677. },
  7678. transportOptions: {},
  7679. closeOnBeforeunload: true
  7680. }, opts);
  7681. this.opts.path = this.opts.path.replace(/\/$/, "") + "/";
  7682. if (typeof this.opts.query === "string") {
  7683. this.opts.query = parseqs_1.default.decode(this.opts.query);
  7684. }
  7685. // set on handshake
  7686. this.id = null;
  7687. this.upgrades = null;
  7688. this.pingInterval = null;
  7689. this.pingTimeout = null;
  7690. // set on heartbeat
  7691. this.pingTimeoutTimer = null;
  7692. if (typeof addEventListener === "function") {
  7693. if (this.opts.closeOnBeforeunload) {
  7694. // Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
  7695. // ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
  7696. // closed/reloaded)
  7697. addEventListener("beforeunload", () => {
  7698. if (this.transport) {
  7699. // silently close the transport
  7700. this.transport.removeAllListeners();
  7701. this.transport.close();
  7702. }
  7703. }, false);
  7704. }
  7705. if (this.hostname !== "localhost") {
  7706. this.offlineEventListener = () => {
  7707. this.onClose("transport close");
  7708. };
  7709. addEventListener("offline", this.offlineEventListener, false);
  7710. }
  7711. }
  7712. this.open();
  7713. }
  7714. /**
  7715. * Creates transport of the given type.
  7716. *
  7717. * @param {String} transport name
  7718. * @return {Transport}
  7719. * @api private
  7720. */
  7721. createTransport(name) {
  7722. debug('creating transport "%s"', name);
  7723. const query = clone(this.opts.query);
  7724. // append engine.io protocol identifier
  7725. query.EIO = engine_io_parser_1.protocol;
  7726. // transport name
  7727. query.transport = name;
  7728. // session id if we already have one
  7729. if (this.id)
  7730. query.sid = this.id;
  7731. const opts = Object.assign({}, this.opts.transportOptions[name], this.opts, {
  7732. query,
  7733. socket: this,
  7734. hostname: this.hostname,
  7735. secure: this.secure,
  7736. port: this.port
  7737. });
  7738. debug("options: %j", opts);
  7739. return new index_js_1.transports[name](opts);
  7740. }
  7741. /**
  7742. * Initializes transport to use and starts probe.
  7743. *
  7744. * @api private
  7745. */
  7746. open() {
  7747. let transport;
  7748. if (this.opts.rememberUpgrade &&
  7749. Socket.priorWebsocketSuccess &&
  7750. this.transports.indexOf("websocket") !== -1) {
  7751. transport = "websocket";
  7752. }
  7753. else if (0 === this.transports.length) {
  7754. // Emit error on next tick so it can be listened to
  7755. this.setTimeoutFn(() => {
  7756. this.emitReserved("error", "No transports available");
  7757. }, 0);
  7758. return;
  7759. }
  7760. else {
  7761. transport = this.transports[0];
  7762. }
  7763. this.readyState = "opening";
  7764. // Retry with the next transport if the transport is disabled (jsonp: false)
  7765. try {
  7766. transport = this.createTransport(transport);
  7767. }
  7768. catch (e) {
  7769. debug("error while creating transport: %s", e);
  7770. this.transports.shift();
  7771. this.open();
  7772. return;
  7773. }
  7774. transport.open();
  7775. this.setTransport(transport);
  7776. }
  7777. /**
  7778. * Sets the current transport. Disables the existing one (if any).
  7779. *
  7780. * @api private
  7781. */
  7782. setTransport(transport) {
  7783. debug("setting transport %s", transport.name);
  7784. if (this.transport) {
  7785. debug("clearing existing transport %s", this.transport.name);
  7786. this.transport.removeAllListeners();
  7787. }
  7788. // set up transport
  7789. this.transport = transport;
  7790. // set up transport listeners
  7791. transport
  7792. .on("drain", this.onDrain.bind(this))
  7793. .on("packet", this.onPacket.bind(this))
  7794. .on("error", this.onError.bind(this))
  7795. .on("close", () => {
  7796. this.onClose("transport close");
  7797. });
  7798. }
  7799. /**
  7800. * Probes a transport.
  7801. *
  7802. * @param {String} transport name
  7803. * @api private
  7804. */
  7805. probe(name) {
  7806. debug('probing transport "%s"', name);
  7807. let transport = this.createTransport(name);
  7808. let failed = false;
  7809. Socket.priorWebsocketSuccess = false;
  7810. const onTransportOpen = () => {
  7811. if (failed)
  7812. return;
  7813. debug('probe transport "%s" opened', name);
  7814. transport.send([{ type: "ping", data: "probe" }]);
  7815. transport.once("packet", msg => {
  7816. if (failed)
  7817. return;
  7818. if ("pong" === msg.type && "probe" === msg.data) {
  7819. debug('probe transport "%s" pong', name);
  7820. this.upgrading = true;
  7821. this.emitReserved("upgrading", transport);
  7822. if (!transport)
  7823. return;
  7824. Socket.priorWebsocketSuccess = "websocket" === transport.name;
  7825. debug('pausing current transport "%s"', this.transport.name);
  7826. this.transport.pause(() => {
  7827. if (failed)
  7828. return;
  7829. if ("closed" === this.readyState)
  7830. return;
  7831. debug("changing transport and sending upgrade packet");
  7832. cleanup();
  7833. this.setTransport(transport);
  7834. transport.send([{ type: "upgrade" }]);
  7835. this.emitReserved("upgrade", transport);
  7836. transport = null;
  7837. this.upgrading = false;
  7838. this.flush();
  7839. });
  7840. }
  7841. else {
  7842. debug('probe transport "%s" failed', name);
  7843. const err = new Error("probe error");
  7844. // @ts-ignore
  7845. err.transport = transport.name;
  7846. this.emitReserved("upgradeError", err);
  7847. }
  7848. });
  7849. };
  7850. function freezeTransport() {
  7851. if (failed)
  7852. return;
  7853. // Any callback called by transport should be ignored since now
  7854. failed = true;
  7855. cleanup();
  7856. transport.close();
  7857. transport = null;
  7858. }
  7859. // Handle any error that happens while probing
  7860. const onerror = err => {
  7861. const error = new Error("probe error: " + err);
  7862. // @ts-ignore
  7863. error.transport = transport.name;
  7864. freezeTransport();
  7865. debug('probe transport "%s" failed because of error: %s', name, err);
  7866. this.emitReserved("upgradeError", error);
  7867. };
  7868. function onTransportClose() {
  7869. onerror("transport closed");
  7870. }
  7871. // When the socket is closed while we're probing
  7872. function onclose() {
  7873. onerror("socket closed");
  7874. }
  7875. // When the socket is upgraded while we're probing
  7876. function onupgrade(to) {
  7877. if (transport && to.name !== transport.name) {
  7878. debug('"%s" works - aborting "%s"', to.name, transport.name);
  7879. freezeTransport();
  7880. }
  7881. }
  7882. // Remove all listeners on the transport and on self
  7883. const cleanup = () => {
  7884. transport.removeListener("open", onTransportOpen);
  7885. transport.removeListener("error", onerror);
  7886. transport.removeListener("close", onTransportClose);
  7887. this.off("close", onclose);
  7888. this.off("upgrading", onupgrade);
  7889. };
  7890. transport.once("open", onTransportOpen);
  7891. transport.once("error", onerror);
  7892. transport.once("close", onTransportClose);
  7893. this.once("close", onclose);
  7894. this.once("upgrading", onupgrade);
  7895. transport.open();
  7896. }
  7897. /**
  7898. * Called when connection is deemed open.
  7899. *
  7900. * @api private
  7901. */
  7902. onOpen() {
  7903. debug("socket open");
  7904. this.readyState = "open";
  7905. Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
  7906. this.emitReserved("open");
  7907. this.flush();
  7908. // we check for `readyState` in case an `open`
  7909. // listener already closed the socket
  7910. if ("open" === this.readyState &&
  7911. this.opts.upgrade &&
  7912. this.transport.pause) {
  7913. debug("starting upgrade probes");
  7914. let i = 0;
  7915. const l = this.upgrades.length;
  7916. for (; i < l; i++) {
  7917. this.probe(this.upgrades[i]);
  7918. }
  7919. }
  7920. }
  7921. /**
  7922. * Handles a packet.
  7923. *
  7924. * @api private
  7925. */
  7926. onPacket(packet) {
  7927. if ("opening" === this.readyState ||
  7928. "open" === this.readyState ||
  7929. "closing" === this.readyState) {
  7930. debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
  7931. this.emitReserved("packet", packet);
  7932. // Socket is live - any packet counts
  7933. this.emitReserved("heartbeat");
  7934. switch (packet.type) {
  7935. case "open":
  7936. this.onHandshake(JSON.parse(packet.data));
  7937. break;
  7938. case "ping":
  7939. this.resetPingTimeout();
  7940. this.sendPacket("pong");
  7941. this.emitReserved("ping");
  7942. this.emitReserved("pong");
  7943. break;
  7944. case "error":
  7945. const err = new Error("server error");
  7946. // @ts-ignore
  7947. err.code = packet.data;
  7948. this.onError(err);
  7949. break;
  7950. case "message":
  7951. this.emitReserved("data", packet.data);
  7952. this.emitReserved("message", packet.data);
  7953. break;
  7954. }
  7955. }
  7956. else {
  7957. debug('packet received with socket readyState "%s"', this.readyState);
  7958. }
  7959. }
  7960. /**
  7961. * Called upon handshake completion.
  7962. *
  7963. * @param {Object} data - handshake obj
  7964. * @api private
  7965. */
  7966. onHandshake(data) {
  7967. this.emitReserved("handshake", data);
  7968. this.id = data.sid;
  7969. this.transport.query.sid = data.sid;
  7970. this.upgrades = this.filterUpgrades(data.upgrades);
  7971. this.pingInterval = data.pingInterval;
  7972. this.pingTimeout = data.pingTimeout;
  7973. this.onOpen();
  7974. // In case open handler closes socket
  7975. if ("closed" === this.readyState)
  7976. return;
  7977. this.resetPingTimeout();
  7978. }
  7979. /**
  7980. * Sets and resets ping timeout timer based on server pings.
  7981. *
  7982. * @api private
  7983. */
  7984. resetPingTimeout() {
  7985. this.clearTimeoutFn(this.pingTimeoutTimer);
  7986. this.pingTimeoutTimer = this.setTimeoutFn(() => {
  7987. this.onClose("ping timeout");
  7988. }, this.pingInterval + this.pingTimeout);
  7989. if (this.opts.autoUnref) {
  7990. this.pingTimeoutTimer.unref();
  7991. }
  7992. }
  7993. /**
  7994. * Called on `drain` event
  7995. *
  7996. * @api private
  7997. */
  7998. onDrain() {
  7999. this.writeBuffer.splice(0, this.prevBufferLen);
  8000. // setting prevBufferLen = 0 is very important
  8001. // for example, when upgrading, upgrade packet is sent over,
  8002. // and a nonzero prevBufferLen could cause problems on `drain`
  8003. this.prevBufferLen = 0;
  8004. if (0 === this.writeBuffer.length) {
  8005. this.emitReserved("drain");
  8006. }
  8007. else {
  8008. this.flush();
  8009. }
  8010. }
  8011. /**
  8012. * Flush write buffers.
  8013. *
  8014. * @api private
  8015. */
  8016. flush() {
  8017. if ("closed" !== this.readyState &&
  8018. this.transport.writable &&
  8019. !this.upgrading &&
  8020. this.writeBuffer.length) {
  8021. debug("flushing %d packets in socket", this.writeBuffer.length);
  8022. this.transport.send(this.writeBuffer);
  8023. // keep track of current length of writeBuffer
  8024. // splice writeBuffer and callbackBuffer on `drain`
  8025. this.prevBufferLen = this.writeBuffer.length;
  8026. this.emitReserved("flush");
  8027. }
  8028. }
  8029. /**
  8030. * Sends a message.
  8031. *
  8032. * @param {String} message.
  8033. * @param {Function} callback function.
  8034. * @param {Object} options.
  8035. * @return {Socket} for chaining.
  8036. * @api public
  8037. */
  8038. write(msg, options, fn) {
  8039. this.sendPacket("message", msg, options, fn);
  8040. return this;
  8041. }
  8042. send(msg, options, fn) {
  8043. this.sendPacket("message", msg, options, fn);
  8044. return this;
  8045. }
  8046. /**
  8047. * Sends a packet.
  8048. *
  8049. * @param {String} packet type.
  8050. * @param {String} data.
  8051. * @param {Object} options.
  8052. * @param {Function} callback function.
  8053. * @api private
  8054. */
  8055. sendPacket(type, data, options, fn) {
  8056. if ("function" === typeof data) {
  8057. fn = data;
  8058. data = undefined;
  8059. }
  8060. if ("function" === typeof options) {
  8061. fn = options;
  8062. options = null;
  8063. }
  8064. if ("closing" === this.readyState || "closed" === this.readyState) {
  8065. return;
  8066. }
  8067. options = options || {};
  8068. options.compress = false !== options.compress;
  8069. const packet = {
  8070. type: type,
  8071. data: data,
  8072. options: options
  8073. };
  8074. this.emitReserved("packetCreate", packet);
  8075. this.writeBuffer.push(packet);
  8076. if (fn)
  8077. this.once("flush", fn);
  8078. this.flush();
  8079. }
  8080. /**
  8081. * Closes the connection.
  8082. *
  8083. * @api public
  8084. */
  8085. close() {
  8086. const close = () => {
  8087. this.onClose("forced close");
  8088. debug("socket closing - telling transport to close");
  8089. this.transport.close();
  8090. };
  8091. const cleanupAndClose = () => {
  8092. this.off("upgrade", cleanupAndClose);
  8093. this.off("upgradeError", cleanupAndClose);
  8094. close();
  8095. };
  8096. const waitForUpgrade = () => {
  8097. // wait for upgrade to finish since we can't send packets while pausing a transport
  8098. this.once("upgrade", cleanupAndClose);
  8099. this.once("upgradeError", cleanupAndClose);
  8100. };
  8101. if ("opening" === this.readyState || "open" === this.readyState) {
  8102. this.readyState = "closing";
  8103. if (this.writeBuffer.length) {
  8104. this.once("drain", () => {
  8105. if (this.upgrading) {
  8106. waitForUpgrade();
  8107. }
  8108. else {
  8109. close();
  8110. }
  8111. });
  8112. }
  8113. else if (this.upgrading) {
  8114. waitForUpgrade();
  8115. }
  8116. else {
  8117. close();
  8118. }
  8119. }
  8120. return this;
  8121. }
  8122. /**
  8123. * Called upon transport error
  8124. *
  8125. * @api private
  8126. */
  8127. onError(err) {
  8128. debug("socket error %j", err);
  8129. Socket.priorWebsocketSuccess = false;
  8130. this.emitReserved("error", err);
  8131. this.onClose("transport error", err);
  8132. }
  8133. /**
  8134. * Called upon transport close.
  8135. *
  8136. * @api private
  8137. */
  8138. onClose(reason, desc) {
  8139. if ("opening" === this.readyState ||
  8140. "open" === this.readyState ||
  8141. "closing" === this.readyState) {
  8142. debug('socket close with reason: "%s"', reason);
  8143. // clear timers
  8144. this.clearTimeoutFn(this.pingTimeoutTimer);
  8145. // stop event from firing again for transport
  8146. this.transport.removeAllListeners("close");
  8147. // ensure transport won't stay open
  8148. this.transport.close();
  8149. // ignore further transport communication
  8150. this.transport.removeAllListeners();
  8151. if (typeof removeEventListener === "function") {
  8152. removeEventListener("offline", this.offlineEventListener, false);
  8153. }
  8154. // set ready state
  8155. this.readyState = "closed";
  8156. // clear session id
  8157. this.id = null;
  8158. // emit close event
  8159. this.emitReserved("close", reason, desc);
  8160. // clean buffers after, so users can still
  8161. // grab the buffers on `close` event
  8162. this.writeBuffer = [];
  8163. this.prevBufferLen = 0;
  8164. }
  8165. }
  8166. /**
  8167. * Filters upgrades, returning only those matching client transports.
  8168. *
  8169. * @param {Array} server upgrades
  8170. * @api private
  8171. *
  8172. */
  8173. filterUpgrades(upgrades) {
  8174. const filteredUpgrades = [];
  8175. let i = 0;
  8176. const j = upgrades.length;
  8177. for (; i < j; i++) {
  8178. if (~this.transports.indexOf(upgrades[i]))
  8179. filteredUpgrades.push(upgrades[i]);
  8180. }
  8181. return filteredUpgrades;
  8182. }
  8183. }
  8184. exports.Socket = Socket;
  8185. Socket.protocol = engine_io_parser_1.protocol;
  8186. function clone(obj) {
  8187. const o = {};
  8188. for (let i in obj) {
  8189. if (obj.hasOwnProperty(i)) {
  8190. o[i] = obj[i];
  8191. }
  8192. }
  8193. return o;
  8194. }
  8195. /***/ }),
  8196. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js":
  8197. /*!***********************************************************************!*\
  8198. !*** ../ot-core/node_modules/engine.io-client/build/cjs/transport.js ***!
  8199. \***********************************************************************/
  8200. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  8201. "use strict";
  8202. var __importDefault = (this && this.__importDefault) || function (mod) {
  8203. return (mod && mod.__esModule) ? mod : { "default": mod };
  8204. };
  8205. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8206. exports.Transport = void 0;
  8207. const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
  8208. const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
  8209. const util_js_1 = __webpack_require__(/*! ./util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
  8210. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  8211. const debug = (0, debug_1.default)("engine.io-client:transport"); // debug()
  8212. class Transport extends component_emitter_1.Emitter {
  8213. /**
  8214. * Transport abstract constructor.
  8215. *
  8216. * @param {Object} options.
  8217. * @api private
  8218. */
  8219. constructor(opts) {
  8220. super();
  8221. this.writable = false;
  8222. (0, util_js_1.installTimerFunctions)(this, opts);
  8223. this.opts = opts;
  8224. this.query = opts.query;
  8225. this.readyState = "";
  8226. this.socket = opts.socket;
  8227. }
  8228. /**
  8229. * Emits an error.
  8230. *
  8231. * @param {String} str
  8232. * @return {Transport} for chaining
  8233. * @api protected
  8234. */
  8235. onError(msg, desc) {
  8236. const err = new Error(msg);
  8237. // @ts-ignore
  8238. err.type = "TransportError";
  8239. // @ts-ignore
  8240. err.description = desc;
  8241. super.emit("error", err);
  8242. return this;
  8243. }
  8244. /**
  8245. * Opens the transport.
  8246. *
  8247. * @api public
  8248. */
  8249. open() {
  8250. if ("closed" === this.readyState || "" === this.readyState) {
  8251. this.readyState = "opening";
  8252. this.doOpen();
  8253. }
  8254. return this;
  8255. }
  8256. /**
  8257. * Closes the transport.
  8258. *
  8259. * @api public
  8260. */
  8261. close() {
  8262. if ("opening" === this.readyState || "open" === this.readyState) {
  8263. this.doClose();
  8264. this.onClose();
  8265. }
  8266. return this;
  8267. }
  8268. /**
  8269. * Sends multiple packets.
  8270. *
  8271. * @param {Array} packets
  8272. * @api public
  8273. */
  8274. send(packets) {
  8275. if ("open" === this.readyState) {
  8276. this.write(packets);
  8277. }
  8278. else {
  8279. // this might happen if the transport was silently closed in the beforeunload event handler
  8280. debug("transport is not open, discarding packets");
  8281. }
  8282. }
  8283. /**
  8284. * Called upon open
  8285. *
  8286. * @api protected
  8287. */
  8288. onOpen() {
  8289. this.readyState = "open";
  8290. this.writable = true;
  8291. super.emit("open");
  8292. }
  8293. /**
  8294. * Called with data.
  8295. *
  8296. * @param {String} data
  8297. * @api protected
  8298. */
  8299. onData(data) {
  8300. const packet = (0, engine_io_parser_1.decodePacket)(data, this.socket.binaryType);
  8301. this.onPacket(packet);
  8302. }
  8303. /**
  8304. * Called with a decoded packet.
  8305. *
  8306. * @api protected
  8307. */
  8308. onPacket(packet) {
  8309. super.emit("packet", packet);
  8310. }
  8311. /**
  8312. * Called upon close.
  8313. *
  8314. * @api protected
  8315. */
  8316. onClose() {
  8317. this.readyState = "closed";
  8318. super.emit("close");
  8319. }
  8320. }
  8321. exports.Transport = Transport;
  8322. /***/ }),
  8323. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js":
  8324. /*!******************************************************************************!*\
  8325. !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js ***!
  8326. \******************************************************************************/
  8327. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8328. "use strict";
  8329. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8330. exports.transports = void 0;
  8331. const polling_xhr_js_1 = __webpack_require__(/*! ./polling-xhr.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js");
  8332. const websocket_js_1 = __webpack_require__(/*! ./websocket.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket.js");
  8333. exports.transports = {
  8334. websocket: websocket_js_1.WS,
  8335. polling: polling_xhr_js_1.XHR
  8336. };
  8337. /***/ }),
  8338. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js":
  8339. /*!************************************************************************************!*\
  8340. !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js ***!
  8341. \************************************************************************************/
  8342. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  8343. "use strict";
  8344. /* global attachEvent */
  8345. var __importDefault = (this && this.__importDefault) || function (mod) {
  8346. return (mod && mod.__esModule) ? mod : { "default": mod };
  8347. };
  8348. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8349. exports.Request = exports.XHR = void 0;
  8350. const xmlhttprequest_js_1 = __importDefault(__webpack_require__(/*! ./xmlhttprequest.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/xmlhttprequest.js"));
  8351. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  8352. const globalThis_js_1 = __importDefault(__webpack_require__(/*! ../globalThis.js */ "../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js"));
  8353. const util_js_1 = __webpack_require__(/*! ../util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
  8354. const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
  8355. const polling_js_1 = __webpack_require__(/*! ./polling.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling.js");
  8356. const debug = (0, debug_1.default)("engine.io-client:polling-xhr"); // debug()
  8357. /**
  8358. * Empty function
  8359. */
  8360. function empty() { }
  8361. const hasXHR2 = (function () {
  8362. const xhr = new xmlhttprequest_js_1.default({
  8363. xdomain: false
  8364. });
  8365. return null != xhr.responseType;
  8366. })();
  8367. class XHR extends polling_js_1.Polling {
  8368. /**
  8369. * XHR Polling constructor.
  8370. *
  8371. * @param {Object} opts
  8372. * @api public
  8373. */
  8374. constructor(opts) {
  8375. super(opts);
  8376. if (typeof location !== "undefined") {
  8377. const isSSL = "https:" === location.protocol;
  8378. let port = location.port;
  8379. // some user agents have empty `location.port`
  8380. if (!port) {
  8381. port = isSSL ? "443" : "80";
  8382. }
  8383. this.xd =
  8384. (typeof location !== "undefined" &&
  8385. opts.hostname !== location.hostname) ||
  8386. port !== opts.port;
  8387. this.xs = opts.secure !== isSSL;
  8388. }
  8389. /**
  8390. * XHR supports binary
  8391. */
  8392. const forceBase64 = opts && opts.forceBase64;
  8393. this.supportsBinary = hasXHR2 && !forceBase64;
  8394. }
  8395. /**
  8396. * Creates a request.
  8397. *
  8398. * @param {String} method
  8399. * @api private
  8400. */
  8401. request(opts = {}) {
  8402. Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);
  8403. return new Request(this.uri(), opts);
  8404. }
  8405. /**
  8406. * Sends data.
  8407. *
  8408. * @param {String} data to send.
  8409. * @param {Function} called upon flush.
  8410. * @api private
  8411. */
  8412. doWrite(data, fn) {
  8413. const req = this.request({
  8414. method: "POST",
  8415. data: data
  8416. });
  8417. req.on("success", fn);
  8418. req.on("error", err => {
  8419. this.onError("xhr post error", err);
  8420. });
  8421. }
  8422. /**
  8423. * Starts a poll cycle.
  8424. *
  8425. * @api private
  8426. */
  8427. doPoll() {
  8428. debug("xhr poll");
  8429. const req = this.request();
  8430. req.on("data", this.onData.bind(this));
  8431. req.on("error", err => {
  8432. this.onError("xhr poll error", err);
  8433. });
  8434. this.pollXhr = req;
  8435. }
  8436. }
  8437. exports.XHR = XHR;
  8438. class Request extends component_emitter_1.Emitter {
  8439. /**
  8440. * Request constructor
  8441. *
  8442. * @param {Object} options
  8443. * @api public
  8444. */
  8445. constructor(uri, opts) {
  8446. super();
  8447. (0, util_js_1.installTimerFunctions)(this, opts);
  8448. this.opts = opts;
  8449. this.method = opts.method || "GET";
  8450. this.uri = uri;
  8451. this.async = false !== opts.async;
  8452. this.data = undefined !== opts.data ? opts.data : null;
  8453. this.create();
  8454. }
  8455. /**
  8456. * Creates the XHR object and sends the request.
  8457. *
  8458. * @api private
  8459. */
  8460. create() {
  8461. const opts = (0, util_js_1.pick)(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
  8462. opts.xdomain = !!this.opts.xd;
  8463. opts.xscheme = !!this.opts.xs;
  8464. const xhr = (this.xhr = new xmlhttprequest_js_1.default(opts));
  8465. try {
  8466. debug("xhr open %s: %s", this.method, this.uri);
  8467. xhr.open(this.method, this.uri, this.async);
  8468. try {
  8469. if (this.opts.extraHeaders) {
  8470. xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
  8471. for (let i in this.opts.extraHeaders) {
  8472. if (this.opts.extraHeaders.hasOwnProperty(i)) {
  8473. xhr.setRequestHeader(i, this.opts.extraHeaders[i]);
  8474. }
  8475. }
  8476. }
  8477. }
  8478. catch (e) { }
  8479. if ("POST" === this.method) {
  8480. try {
  8481. xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
  8482. }
  8483. catch (e) { }
  8484. }
  8485. try {
  8486. xhr.setRequestHeader("Accept", "*/*");
  8487. }
  8488. catch (e) { }
  8489. // ie6 check
  8490. if ("withCredentials" in xhr) {
  8491. xhr.withCredentials = this.opts.withCredentials;
  8492. }
  8493. if (this.opts.requestTimeout) {
  8494. xhr.timeout = this.opts.requestTimeout;
  8495. }
  8496. xhr.onreadystatechange = () => {
  8497. if (4 !== xhr.readyState)
  8498. return;
  8499. if (200 === xhr.status || 1223 === xhr.status) {
  8500. this.onLoad();
  8501. }
  8502. else {
  8503. // make sure the `error` event handler that's user-set
  8504. // does not throw in the same tick and gets caught here
  8505. this.setTimeoutFn(() => {
  8506. this.onError(typeof xhr.status === "number" ? xhr.status : 0);
  8507. }, 0);
  8508. }
  8509. };
  8510. debug("xhr data %s", this.data);
  8511. xhr.send(this.data);
  8512. }
  8513. catch (e) {
  8514. // Need to defer since .create() is called directly from the constructor
  8515. // and thus the 'error' event can only be only bound *after* this exception
  8516. // occurs. Therefore, also, we cannot throw here at all.
  8517. this.setTimeoutFn(() => {
  8518. this.onError(e);
  8519. }, 0);
  8520. return;
  8521. }
  8522. if (typeof document !== "undefined") {
  8523. this.index = Request.requestsCount++;
  8524. Request.requests[this.index] = this;
  8525. }
  8526. }
  8527. /**
  8528. * Called upon successful response.
  8529. *
  8530. * @api private
  8531. */
  8532. onSuccess() {
  8533. this.emit("success");
  8534. this.cleanup();
  8535. }
  8536. /**
  8537. * Called if we have data.
  8538. *
  8539. * @api private
  8540. */
  8541. onData(data) {
  8542. this.emit("data", data);
  8543. this.onSuccess();
  8544. }
  8545. /**
  8546. * Called upon error.
  8547. *
  8548. * @api private
  8549. */
  8550. onError(err) {
  8551. this.emit("error", err);
  8552. this.cleanup(true);
  8553. }
  8554. /**
  8555. * Cleans up house.
  8556. *
  8557. * @api private
  8558. */
  8559. cleanup(fromError) {
  8560. if ("undefined" === typeof this.xhr || null === this.xhr) {
  8561. return;
  8562. }
  8563. this.xhr.onreadystatechange = empty;
  8564. if (fromError) {
  8565. try {
  8566. this.xhr.abort();
  8567. }
  8568. catch (e) { }
  8569. }
  8570. if (typeof document !== "undefined") {
  8571. delete Request.requests[this.index];
  8572. }
  8573. this.xhr = null;
  8574. }
  8575. /**
  8576. * Called upon load.
  8577. *
  8578. * @api private
  8579. */
  8580. onLoad() {
  8581. const data = this.xhr.responseText;
  8582. if (data !== null) {
  8583. this.onData(data);
  8584. }
  8585. }
  8586. /**
  8587. * Aborts the request.
  8588. *
  8589. * @api public
  8590. */
  8591. abort() {
  8592. this.cleanup();
  8593. }
  8594. }
  8595. exports.Request = Request;
  8596. Request.requestsCount = 0;
  8597. Request.requests = {};
  8598. /**
  8599. * Aborts pending requests when unloading the window. This is needed to prevent
  8600. * memory leaks (e.g. when using IE) and to ensure that no spurious error is
  8601. * emitted.
  8602. */
  8603. if (typeof document !== "undefined") {
  8604. // @ts-ignore
  8605. if (typeof attachEvent === "function") {
  8606. // @ts-ignore
  8607. attachEvent("onunload", unloadHandler);
  8608. }
  8609. else if (typeof addEventListener === "function") {
  8610. const terminationEvent = "onpagehide" in globalThis_js_1.default ? "pagehide" : "unload";
  8611. addEventListener(terminationEvent, unloadHandler, false);
  8612. }
  8613. }
  8614. function unloadHandler() {
  8615. for (let i in Request.requests) {
  8616. if (Request.requests.hasOwnProperty(i)) {
  8617. Request.requests[i].abort();
  8618. }
  8619. }
  8620. }
  8621. /***/ }),
  8622. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling.js":
  8623. /*!********************************************************************************!*\
  8624. !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/polling.js ***!
  8625. \********************************************************************************/
  8626. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  8627. "use strict";
  8628. var __importDefault = (this && this.__importDefault) || function (mod) {
  8629. return (mod && mod.__esModule) ? mod : { "default": mod };
  8630. };
  8631. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8632. exports.Polling = void 0;
  8633. const transport_js_1 = __webpack_require__(/*! ../transport.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js");
  8634. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  8635. const yeast_1 = __importDefault(__webpack_require__(/*! yeast */ "../ot-core/node_modules/yeast/index.js"));
  8636. const parseqs_1 = __importDefault(__webpack_require__(/*! parseqs */ "../ot-core/node_modules/parseqs/index.js"));
  8637. const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
  8638. const debug = (0, debug_1.default)("engine.io-client:polling"); // debug()
  8639. class Polling extends transport_js_1.Transport {
  8640. constructor() {
  8641. super(...arguments);
  8642. this.polling = false;
  8643. }
  8644. /**
  8645. * Transport name.
  8646. */
  8647. get name() {
  8648. return "polling";
  8649. }
  8650. /**
  8651. * Opens the socket (triggers polling). We write a PING message to determine
  8652. * when the transport is open.
  8653. *
  8654. * @api private
  8655. */
  8656. doOpen() {
  8657. this.poll();
  8658. }
  8659. /**
  8660. * Pauses polling.
  8661. *
  8662. * @param {Function} callback upon buffers are flushed and transport is paused
  8663. * @api private
  8664. */
  8665. pause(onPause) {
  8666. this.readyState = "pausing";
  8667. const pause = () => {
  8668. debug("paused");
  8669. this.readyState = "paused";
  8670. onPause();
  8671. };
  8672. if (this.polling || !this.writable) {
  8673. let total = 0;
  8674. if (this.polling) {
  8675. debug("we are currently polling - waiting to pause");
  8676. total++;
  8677. this.once("pollComplete", function () {
  8678. debug("pre-pause polling complete");
  8679. --total || pause();
  8680. });
  8681. }
  8682. if (!this.writable) {
  8683. debug("we are currently writing - waiting to pause");
  8684. total++;
  8685. this.once("drain", function () {
  8686. debug("pre-pause writing complete");
  8687. --total || pause();
  8688. });
  8689. }
  8690. }
  8691. else {
  8692. pause();
  8693. }
  8694. }
  8695. /**
  8696. * Starts polling cycle.
  8697. *
  8698. * @api public
  8699. */
  8700. poll() {
  8701. debug("polling");
  8702. this.polling = true;
  8703. this.doPoll();
  8704. this.emit("poll");
  8705. }
  8706. /**
  8707. * Overloads onData to detect payloads.
  8708. *
  8709. * @api private
  8710. */
  8711. onData(data) {
  8712. debug("polling got data %s", data);
  8713. const callback = packet => {
  8714. // if its the first message we consider the transport open
  8715. if ("opening" === this.readyState && packet.type === "open") {
  8716. this.onOpen();
  8717. }
  8718. // if its a close packet, we close the ongoing requests
  8719. if ("close" === packet.type) {
  8720. this.onClose();
  8721. return false;
  8722. }
  8723. // otherwise bypass onData and handle the message
  8724. this.onPacket(packet);
  8725. };
  8726. // decode payload
  8727. (0, engine_io_parser_1.decodePayload)(data, this.socket.binaryType).forEach(callback);
  8728. // if an event did not trigger closing
  8729. if ("closed" !== this.readyState) {
  8730. // if we got data we're not polling
  8731. this.polling = false;
  8732. this.emit("pollComplete");
  8733. if ("open" === this.readyState) {
  8734. this.poll();
  8735. }
  8736. else {
  8737. debug('ignoring poll - transport state "%s"', this.readyState);
  8738. }
  8739. }
  8740. }
  8741. /**
  8742. * For polling, send a close packet.
  8743. *
  8744. * @api private
  8745. */
  8746. doClose() {
  8747. const close = () => {
  8748. debug("writing close packet");
  8749. this.write([{ type: "close" }]);
  8750. };
  8751. if ("open" === this.readyState) {
  8752. debug("transport open - closing");
  8753. close();
  8754. }
  8755. else {
  8756. // in case we're trying to close while
  8757. // handshaking is in progress (GH-164)
  8758. debug("transport not open - deferring close");
  8759. this.once("open", close);
  8760. }
  8761. }
  8762. /**
  8763. * Writes a packets payload.
  8764. *
  8765. * @param {Array} data packets
  8766. * @param {Function} drain callback
  8767. * @api private
  8768. */
  8769. write(packets) {
  8770. this.writable = false;
  8771. (0, engine_io_parser_1.encodePayload)(packets, data => {
  8772. this.doWrite(data, () => {
  8773. this.writable = true;
  8774. this.emit("drain");
  8775. });
  8776. });
  8777. }
  8778. /**
  8779. * Generates uri for connection.
  8780. *
  8781. * @api private
  8782. */
  8783. uri() {
  8784. let query = this.query || {};
  8785. const schema = this.opts.secure ? "https" : "http";
  8786. let port = "";
  8787. // cache busting is forced
  8788. if (false !== this.opts.timestampRequests) {
  8789. query[this.opts.timestampParam] = (0, yeast_1.default)();
  8790. }
  8791. if (!this.supportsBinary && !query.sid) {
  8792. query.b64 = 1;
  8793. }
  8794. // avoid port if default for schema
  8795. if (this.opts.port &&
  8796. (("https" === schema && Number(this.opts.port) !== 443) ||
  8797. ("http" === schema && Number(this.opts.port) !== 80))) {
  8798. port = ":" + this.opts.port;
  8799. }
  8800. const encodedQuery = parseqs_1.default.encode(query);
  8801. const ipv6 = this.opts.hostname.indexOf(":") !== -1;
  8802. return (schema +
  8803. "://" +
  8804. (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) +
  8805. port +
  8806. this.opts.path +
  8807. (encodedQuery.length ? "?" + encodedQuery : ""));
  8808. }
  8809. }
  8810. exports.Polling = Polling;
  8811. /***/ }),
  8812. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket-constructor.js":
  8813. /*!**********************************************************************************************!*\
  8814. !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket-constructor.js ***!
  8815. \**********************************************************************************************/
  8816. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  8817. "use strict";
  8818. var __importDefault = (this && this.__importDefault) || function (mod) {
  8819. return (mod && mod.__esModule) ? mod : { "default": mod };
  8820. };
  8821. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8822. exports.nextTick = exports.defaultBinaryType = exports.usingBrowserWebSocket = exports.WebSocket = void 0;
  8823. const ws_1 = __importDefault(__webpack_require__(/*! ws */ "../ot-core/node_modules/engine.io-client/node_modules/ws/index.js"));
  8824. exports.WebSocket = ws_1.default;
  8825. exports.usingBrowserWebSocket = false;
  8826. exports.defaultBinaryType = "nodebuffer";
  8827. exports.nextTick = process.nextTick;
  8828. /***/ }),
  8829. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket.js":
  8830. /*!**********************************************************************************!*\
  8831. !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket.js ***!
  8832. \**********************************************************************************/
  8833. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  8834. "use strict";
  8835. var __importDefault = (this && this.__importDefault) || function (mod) {
  8836. return (mod && mod.__esModule) ? mod : { "default": mod };
  8837. };
  8838. Object.defineProperty(exports, "__esModule", ({ value: true }));
  8839. exports.WS = void 0;
  8840. const transport_js_1 = __webpack_require__(/*! ../transport.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js");
  8841. const parseqs_1 = __importDefault(__webpack_require__(/*! parseqs */ "../ot-core/node_modules/parseqs/index.js"));
  8842. const yeast_1 = __importDefault(__webpack_require__(/*! yeast */ "../ot-core/node_modules/yeast/index.js"));
  8843. const util_js_1 = __webpack_require__(/*! ../util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
  8844. const websocket_constructor_js_1 = __webpack_require__(/*! ./websocket-constructor.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket-constructor.js");
  8845. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  8846. const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
  8847. const debug = (0, debug_1.default)("engine.io-client:websocket"); // debug()
  8848. // detect ReactNative environment
  8849. const isReactNative = typeof navigator !== "undefined" &&
  8850. typeof navigator.product === "string" &&
  8851. navigator.product.toLowerCase() === "reactnative";
  8852. class WS extends transport_js_1.Transport {
  8853. /**
  8854. * WebSocket transport constructor.
  8855. *
  8856. * @api {Object} connection options
  8857. * @api public
  8858. */
  8859. constructor(opts) {
  8860. super(opts);
  8861. this.supportsBinary = !opts.forceBase64;
  8862. }
  8863. /**
  8864. * Transport name.
  8865. *
  8866. * @api public
  8867. */
  8868. get name() {
  8869. return "websocket";
  8870. }
  8871. /**
  8872. * Opens socket.
  8873. *
  8874. * @api private
  8875. */
  8876. doOpen() {
  8877. if (!this.check()) {
  8878. // let probe timeout
  8879. return;
  8880. }
  8881. const uri = this.uri();
  8882. const protocols = this.opts.protocols;
  8883. // React Native only supports the 'headers' option, and will print a warning if anything else is passed
  8884. const opts = isReactNative
  8885. ? {}
  8886. : (0, util_js_1.pick)(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
  8887. if (this.opts.extraHeaders) {
  8888. opts.headers = this.opts.extraHeaders;
  8889. }
  8890. try {
  8891. this.ws =
  8892. websocket_constructor_js_1.usingBrowserWebSocket && !isReactNative
  8893. ? protocols
  8894. ? new websocket_constructor_js_1.WebSocket(uri, protocols)
  8895. : new websocket_constructor_js_1.WebSocket(uri)
  8896. : new websocket_constructor_js_1.WebSocket(uri, protocols, opts);
  8897. }
  8898. catch (err) {
  8899. return this.emit("error", err);
  8900. }
  8901. this.ws.binaryType = this.socket.binaryType || websocket_constructor_js_1.defaultBinaryType;
  8902. this.addEventListeners();
  8903. }
  8904. /**
  8905. * Adds event listeners to the socket
  8906. *
  8907. * @api private
  8908. */
  8909. addEventListeners() {
  8910. this.ws.onopen = () => {
  8911. if (this.opts.autoUnref) {
  8912. this.ws._socket.unref();
  8913. }
  8914. this.onOpen();
  8915. };
  8916. this.ws.onclose = this.onClose.bind(this);
  8917. this.ws.onmessage = ev => this.onData(ev.data);
  8918. this.ws.onerror = e => this.onError("websocket error", e);
  8919. }
  8920. /**
  8921. * Writes data to socket.
  8922. *
  8923. * @param {Array} array of packets.
  8924. * @api private
  8925. */
  8926. write(packets) {
  8927. this.writable = false;
  8928. // encodePacket efficient as it uses WS framing
  8929. // no need for encodePayload
  8930. for (let i = 0; i < packets.length; i++) {
  8931. const packet = packets[i];
  8932. const lastPacket = i === packets.length - 1;
  8933. (0, engine_io_parser_1.encodePacket)(packet, this.supportsBinary, data => {
  8934. // always create a new object (GH-437)
  8935. const opts = {};
  8936. if (!websocket_constructor_js_1.usingBrowserWebSocket) {
  8937. if (packet.options) {
  8938. opts.compress = packet.options.compress;
  8939. }
  8940. if (this.opts.perMessageDeflate) {
  8941. const len = "string" === typeof data ? Buffer.byteLength(data) : data.length;
  8942. if (len < this.opts.perMessageDeflate.threshold) {
  8943. opts.compress = false;
  8944. }
  8945. }
  8946. }
  8947. // Sometimes the websocket has already been closed but the browser didn't
  8948. // have a chance of informing us about it yet, in that case send will
  8949. // throw an error
  8950. try {
  8951. if (websocket_constructor_js_1.usingBrowserWebSocket) {
  8952. // TypeError is thrown when passing the second argument on Safari
  8953. this.ws.send(data);
  8954. }
  8955. else {
  8956. this.ws.send(data, opts);
  8957. }
  8958. }
  8959. catch (e) {
  8960. debug("websocket closed before onclose event");
  8961. }
  8962. if (lastPacket) {
  8963. // fake drain
  8964. // defer to next tick to allow Socket to clear writeBuffer
  8965. (0, websocket_constructor_js_1.nextTick)(() => {
  8966. this.writable = true;
  8967. this.emit("drain");
  8968. }, this.setTimeoutFn);
  8969. }
  8970. });
  8971. }
  8972. }
  8973. /**
  8974. * Closes socket.
  8975. *
  8976. * @api private
  8977. */
  8978. doClose() {
  8979. if (typeof this.ws !== "undefined") {
  8980. this.ws.close();
  8981. this.ws = null;
  8982. }
  8983. }
  8984. /**
  8985. * Generates uri for connection.
  8986. *
  8987. * @api private
  8988. */
  8989. uri() {
  8990. let query = this.query || {};
  8991. const schema = this.opts.secure ? "wss" : "ws";
  8992. let port = "";
  8993. // avoid port if default for schema
  8994. if (this.opts.port &&
  8995. (("wss" === schema && Number(this.opts.port) !== 443) ||
  8996. ("ws" === schema && Number(this.opts.port) !== 80))) {
  8997. port = ":" + this.opts.port;
  8998. }
  8999. // append timestamp to URI
  9000. if (this.opts.timestampRequests) {
  9001. query[this.opts.timestampParam] = (0, yeast_1.default)();
  9002. }
  9003. // communicate binary support capabilities
  9004. if (!this.supportsBinary) {
  9005. query.b64 = 1;
  9006. }
  9007. const encodedQuery = parseqs_1.default.encode(query);
  9008. const ipv6 = this.opts.hostname.indexOf(":") !== -1;
  9009. return (schema +
  9010. "://" +
  9011. (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) +
  9012. port +
  9013. this.opts.path +
  9014. (encodedQuery.length ? "?" + encodedQuery : ""));
  9015. }
  9016. /**
  9017. * Feature detection for WebSocket.
  9018. *
  9019. * @return {Boolean} whether this transport is available.
  9020. * @api public
  9021. */
  9022. check() {
  9023. return (!!websocket_constructor_js_1.WebSocket &&
  9024. !("__initialize" in websocket_constructor_js_1.WebSocket && this.name === WS.prototype.name));
  9025. }
  9026. }
  9027. exports.WS = WS;
  9028. /***/ }),
  9029. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/xmlhttprequest.js":
  9030. /*!***************************************************************************************!*\
  9031. !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/xmlhttprequest.js ***!
  9032. \***************************************************************************************/
  9033. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  9034. "use strict";
  9035. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  9036. if (k2 === undefined) k2 = k;
  9037. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  9038. }) : (function(o, m, k, k2) {
  9039. if (k2 === undefined) k2 = k;
  9040. o[k2] = m[k];
  9041. }));
  9042. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  9043. Object.defineProperty(o, "default", { enumerable: true, value: v });
  9044. }) : function(o, v) {
  9045. o["default"] = v;
  9046. });
  9047. var __importStar = (this && this.__importStar) || function (mod) {
  9048. if (mod && mod.__esModule) return mod;
  9049. var result = {};
  9050. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  9051. __setModuleDefault(result, mod);
  9052. return result;
  9053. };
  9054. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9055. const XMLHttpRequestModule = __importStar(__webpack_require__(/*! xmlhttprequest-ssl */ "../ot-core/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js"));
  9056. const XMLHttpRequest = XMLHttpRequestModule.default || XMLHttpRequestModule;
  9057. exports["default"] = XMLHttpRequest;
  9058. /***/ }),
  9059. /***/ "../ot-core/node_modules/engine.io-client/build/cjs/util.js":
  9060. /*!******************************************************************!*\
  9061. !*** ../ot-core/node_modules/engine.io-client/build/cjs/util.js ***!
  9062. \******************************************************************/
  9063. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  9064. "use strict";
  9065. var __importDefault = (this && this.__importDefault) || function (mod) {
  9066. return (mod && mod.__esModule) ? mod : { "default": mod };
  9067. };
  9068. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9069. exports.installTimerFunctions = exports.pick = void 0;
  9070. const globalThis_js_1 = __importDefault(__webpack_require__(/*! ./globalThis.js */ "../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js"));
  9071. function pick(obj, ...attr) {
  9072. return attr.reduce((acc, k) => {
  9073. if (obj.hasOwnProperty(k)) {
  9074. acc[k] = obj[k];
  9075. }
  9076. return acc;
  9077. }, {});
  9078. }
  9079. exports.pick = pick;
  9080. // Keep a reference to the real timeout functions so they can be used when overridden
  9081. const NATIVE_SET_TIMEOUT = setTimeout;
  9082. const NATIVE_CLEAR_TIMEOUT = clearTimeout;
  9083. function installTimerFunctions(obj, opts) {
  9084. if (opts.useNativeTimers) {
  9085. obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis_js_1.default);
  9086. obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis_js_1.default);
  9087. }
  9088. else {
  9089. obj.setTimeoutFn = setTimeout.bind(globalThis_js_1.default);
  9090. obj.clearTimeoutFn = clearTimeout.bind(globalThis_js_1.default);
  9091. }
  9092. }
  9093. exports.installTimerFunctions = installTimerFunctions;
  9094. /***/ }),
  9095. /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/commons.js":
  9096. /*!*********************************************************************!*\
  9097. !*** ../ot-core/node_modules/engine.io-parser/build/cjs/commons.js ***!
  9098. \*********************************************************************/
  9099. /***/ ((__unused_webpack_module, exports) => {
  9100. "use strict";
  9101. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9102. exports.ERROR_PACKET = exports.PACKET_TYPES_REVERSE = exports.PACKET_TYPES = void 0;
  9103. const PACKET_TYPES = Object.create(null); // no Map = no polyfill
  9104. exports.PACKET_TYPES = PACKET_TYPES;
  9105. PACKET_TYPES["open"] = "0";
  9106. PACKET_TYPES["close"] = "1";
  9107. PACKET_TYPES["ping"] = "2";
  9108. PACKET_TYPES["pong"] = "3";
  9109. PACKET_TYPES["message"] = "4";
  9110. PACKET_TYPES["upgrade"] = "5";
  9111. PACKET_TYPES["noop"] = "6";
  9112. const PACKET_TYPES_REVERSE = Object.create(null);
  9113. exports.PACKET_TYPES_REVERSE = PACKET_TYPES_REVERSE;
  9114. Object.keys(PACKET_TYPES).forEach(key => {
  9115. PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
  9116. });
  9117. const ERROR_PACKET = { type: "error", data: "parser error" };
  9118. exports.ERROR_PACKET = ERROR_PACKET;
  9119. /***/ }),
  9120. /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/decodePacket.js":
  9121. /*!**************************************************************************!*\
  9122. !*** ../ot-core/node_modules/engine.io-parser/build/cjs/decodePacket.js ***!
  9123. \**************************************************************************/
  9124. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9125. "use strict";
  9126. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9127. const commons_js_1 = __webpack_require__(/*! ./commons.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/commons.js");
  9128. const decodePacket = (encodedPacket, binaryType) => {
  9129. if (typeof encodedPacket !== "string") {
  9130. return {
  9131. type: "message",
  9132. data: mapBinary(encodedPacket, binaryType)
  9133. };
  9134. }
  9135. const type = encodedPacket.charAt(0);
  9136. if (type === "b") {
  9137. const buffer = Buffer.from(encodedPacket.substring(1), "base64");
  9138. return {
  9139. type: "message",
  9140. data: mapBinary(buffer, binaryType)
  9141. };
  9142. }
  9143. if (!commons_js_1.PACKET_TYPES_REVERSE[type]) {
  9144. return commons_js_1.ERROR_PACKET;
  9145. }
  9146. return encodedPacket.length > 1
  9147. ? {
  9148. type: commons_js_1.PACKET_TYPES_REVERSE[type],
  9149. data: encodedPacket.substring(1)
  9150. }
  9151. : {
  9152. type: commons_js_1.PACKET_TYPES_REVERSE[type]
  9153. };
  9154. };
  9155. const mapBinary = (data, binaryType) => {
  9156. const isBuffer = Buffer.isBuffer(data);
  9157. switch (binaryType) {
  9158. case "arraybuffer":
  9159. return isBuffer ? toArrayBuffer(data) : data;
  9160. case "nodebuffer":
  9161. default:
  9162. return data; // assuming the data is already a Buffer
  9163. }
  9164. };
  9165. const toArrayBuffer = (buffer) => {
  9166. const arrayBuffer = new ArrayBuffer(buffer.length);
  9167. const view = new Uint8Array(arrayBuffer);
  9168. for (let i = 0; i < buffer.length; i++) {
  9169. view[i] = buffer[i];
  9170. }
  9171. return arrayBuffer;
  9172. };
  9173. exports["default"] = decodePacket;
  9174. /***/ }),
  9175. /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/encodePacket.js":
  9176. /*!**************************************************************************!*\
  9177. !*** ../ot-core/node_modules/engine.io-parser/build/cjs/encodePacket.js ***!
  9178. \**************************************************************************/
  9179. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9180. "use strict";
  9181. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9182. const commons_js_1 = __webpack_require__(/*! ./commons.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/commons.js");
  9183. const encodePacket = ({ type, data }, supportsBinary, callback) => {
  9184. if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
  9185. const buffer = toBuffer(data);
  9186. return callback(encodeBuffer(buffer, supportsBinary));
  9187. }
  9188. // plain string
  9189. return callback(commons_js_1.PACKET_TYPES[type] + (data || ""));
  9190. };
  9191. const toBuffer = data => {
  9192. if (Buffer.isBuffer(data)) {
  9193. return data;
  9194. }
  9195. else if (data instanceof ArrayBuffer) {
  9196. return Buffer.from(data);
  9197. }
  9198. else {
  9199. return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
  9200. }
  9201. };
  9202. // only 'message' packets can contain binary, so the type prefix is not needed
  9203. const encodeBuffer = (data, supportsBinary) => {
  9204. return supportsBinary ? data : "b" + data.toString("base64");
  9205. };
  9206. exports["default"] = encodePacket;
  9207. /***/ }),
  9208. /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js":
  9209. /*!*******************************************************************!*\
  9210. !*** ../ot-core/node_modules/engine.io-parser/build/cjs/index.js ***!
  9211. \*******************************************************************/
  9212. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9213. "use strict";
  9214. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9215. exports.decodePayload = exports.decodePacket = exports.encodePayload = exports.encodePacket = exports.protocol = void 0;
  9216. const encodePacket_js_1 = __webpack_require__(/*! ./encodePacket.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/encodePacket.js");
  9217. exports.encodePacket = encodePacket_js_1.default;
  9218. const decodePacket_js_1 = __webpack_require__(/*! ./decodePacket.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/decodePacket.js");
  9219. exports.decodePacket = decodePacket_js_1.default;
  9220. const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
  9221. const encodePayload = (packets, callback) => {
  9222. // some packets may be added to the array while encoding, so the initial length must be saved
  9223. const length = packets.length;
  9224. const encodedPackets = new Array(length);
  9225. let count = 0;
  9226. packets.forEach((packet, i) => {
  9227. // force base64 encoding for binary packets
  9228. (0, encodePacket_js_1.default)(packet, false, encodedPacket => {
  9229. encodedPackets[i] = encodedPacket;
  9230. if (++count === length) {
  9231. callback(encodedPackets.join(SEPARATOR));
  9232. }
  9233. });
  9234. });
  9235. };
  9236. exports.encodePayload = encodePayload;
  9237. const decodePayload = (encodedPayload, binaryType) => {
  9238. const encodedPackets = encodedPayload.split(SEPARATOR);
  9239. const packets = [];
  9240. for (let i = 0; i < encodedPackets.length; i++) {
  9241. const decodedPacket = (0, decodePacket_js_1.default)(encodedPackets[i], binaryType);
  9242. packets.push(decodedPacket);
  9243. if (decodedPacket.type === "error") {
  9244. break;
  9245. }
  9246. }
  9247. return packets;
  9248. };
  9249. exports.decodePayload = decodePayload;
  9250. exports.protocol = 4;
  9251. /***/ }),
  9252. /***/ "../ot-core/node_modules/socket.io-client/build/cjs/index.js":
  9253. /*!*******************************************************************!*\
  9254. !*** ../ot-core/node_modules/socket.io-client/build/cjs/index.js ***!
  9255. \*******************************************************************/
  9256. /***/ (function(module, exports, __webpack_require__) {
  9257. "use strict";
  9258. var __importDefault = (this && this.__importDefault) || function (mod) {
  9259. return (mod && mod.__esModule) ? mod : { "default": mod };
  9260. };
  9261. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9262. exports["default"] = exports.connect = exports.io = exports.Socket = exports.Manager = exports.protocol = void 0;
  9263. const url_js_1 = __webpack_require__(/*! ./url.js */ "../ot-core/node_modules/socket.io-client/build/cjs/url.js");
  9264. const manager_js_1 = __webpack_require__(/*! ./manager.js */ "../ot-core/node_modules/socket.io-client/build/cjs/manager.js");
  9265. Object.defineProperty(exports, "Manager", ({ enumerable: true, get: function () { return manager_js_1.Manager; } }));
  9266. const socket_js_1 = __webpack_require__(/*! ./socket.js */ "../ot-core/node_modules/socket.io-client/build/cjs/socket.js");
  9267. Object.defineProperty(exports, "Socket", ({ enumerable: true, get: function () { return socket_js_1.Socket; } }));
  9268. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  9269. const debug = debug_1.default("socket.io-client"); // debug()
  9270. /**
  9271. * Managers cache.
  9272. */
  9273. const cache = {};
  9274. function lookup(uri, opts) {
  9275. if (typeof uri === "object") {
  9276. opts = uri;
  9277. uri = undefined;
  9278. }
  9279. opts = opts || {};
  9280. const parsed = url_js_1.url(uri, opts.path || "/socket.io");
  9281. const source = parsed.source;
  9282. const id = parsed.id;
  9283. const path = parsed.path;
  9284. const sameNamespace = cache[id] && path in cache[id]["nsps"];
  9285. const newConnection = opts.forceNew ||
  9286. opts["force new connection"] ||
  9287. false === opts.multiplex ||
  9288. sameNamespace;
  9289. let io;
  9290. if (newConnection) {
  9291. debug("ignoring socket cache for %s", source);
  9292. io = new manager_js_1.Manager(source, opts);
  9293. }
  9294. else {
  9295. if (!cache[id]) {
  9296. debug("new io instance for %s", source);
  9297. cache[id] = new manager_js_1.Manager(source, opts);
  9298. }
  9299. io = cache[id];
  9300. }
  9301. if (parsed.query && !opts.query) {
  9302. opts.query = parsed.queryKey;
  9303. }
  9304. return io.socket(parsed.path, opts);
  9305. }
  9306. exports.io = lookup;
  9307. exports.connect = lookup;
  9308. exports["default"] = lookup;
  9309. // so that "lookup" can be used both as a function (e.g. `io(...)`) and as a
  9310. // namespace (e.g. `io.connect(...)`), for backward compatibility
  9311. Object.assign(lookup, {
  9312. Manager: manager_js_1.Manager,
  9313. Socket: socket_js_1.Socket,
  9314. io: lookup,
  9315. connect: lookup,
  9316. });
  9317. /**
  9318. * Protocol version.
  9319. *
  9320. * @public
  9321. */
  9322. var socket_io_parser_1 = __webpack_require__(/*! socket.io-parser */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js");
  9323. Object.defineProperty(exports, "protocol", ({ enumerable: true, get: function () { return socket_io_parser_1.protocol; } }));
  9324. module.exports = lookup;
  9325. /***/ }),
  9326. /***/ "../ot-core/node_modules/socket.io-client/build/cjs/manager.js":
  9327. /*!*********************************************************************!*\
  9328. !*** ../ot-core/node_modules/socket.io-client/build/cjs/manager.js ***!
  9329. \*********************************************************************/
  9330. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  9331. "use strict";
  9332. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  9333. if (k2 === undefined) k2 = k;
  9334. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  9335. }) : (function(o, m, k, k2) {
  9336. if (k2 === undefined) k2 = k;
  9337. o[k2] = m[k];
  9338. }));
  9339. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  9340. Object.defineProperty(o, "default", { enumerable: true, value: v });
  9341. }) : function(o, v) {
  9342. o["default"] = v;
  9343. });
  9344. var __importStar = (this && this.__importStar) || function (mod) {
  9345. if (mod && mod.__esModule) return mod;
  9346. var result = {};
  9347. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  9348. __setModuleDefault(result, mod);
  9349. return result;
  9350. };
  9351. var __importDefault = (this && this.__importDefault) || function (mod) {
  9352. return (mod && mod.__esModule) ? mod : { "default": mod };
  9353. };
  9354. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9355. exports.Manager = void 0;
  9356. const engine_io_client_1 = __webpack_require__(/*! engine.io-client */ "../ot-core/node_modules/engine.io-client/build/cjs/index.js");
  9357. const socket_js_1 = __webpack_require__(/*! ./socket.js */ "../ot-core/node_modules/socket.io-client/build/cjs/socket.js");
  9358. const parser = __importStar(__webpack_require__(/*! socket.io-parser */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js"));
  9359. const on_js_1 = __webpack_require__(/*! ./on.js */ "../ot-core/node_modules/socket.io-client/build/cjs/on.js");
  9360. const backo2_1 = __importDefault(__webpack_require__(/*! backo2 */ "../ot-core/node_modules/backo2/index.js"));
  9361. const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
  9362. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  9363. const debug = debug_1.default("socket.io-client:manager"); // debug()
  9364. class Manager extends component_emitter_1.Emitter {
  9365. constructor(uri, opts) {
  9366. var _a;
  9367. super();
  9368. this.nsps = {};
  9369. this.subs = [];
  9370. if (uri && "object" === typeof uri) {
  9371. opts = uri;
  9372. uri = undefined;
  9373. }
  9374. opts = opts || {};
  9375. opts.path = opts.path || "/socket.io";
  9376. this.opts = opts;
  9377. engine_io_client_1.installTimerFunctions(this, opts);
  9378. this.reconnection(opts.reconnection !== false);
  9379. this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
  9380. this.reconnectionDelay(opts.reconnectionDelay || 1000);
  9381. this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
  9382. this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
  9383. this.backoff = new backo2_1.default({
  9384. min: this.reconnectionDelay(),
  9385. max: this.reconnectionDelayMax(),
  9386. jitter: this.randomizationFactor(),
  9387. });
  9388. this.timeout(null == opts.timeout ? 20000 : opts.timeout);
  9389. this._readyState = "closed";
  9390. this.uri = uri;
  9391. const _parser = opts.parser || parser;
  9392. this.encoder = new _parser.Encoder();
  9393. this.decoder = new _parser.Decoder();
  9394. this._autoConnect = opts.autoConnect !== false;
  9395. if (this._autoConnect)
  9396. this.open();
  9397. }
  9398. reconnection(v) {
  9399. if (!arguments.length)
  9400. return this._reconnection;
  9401. this._reconnection = !!v;
  9402. return this;
  9403. }
  9404. reconnectionAttempts(v) {
  9405. if (v === undefined)
  9406. return this._reconnectionAttempts;
  9407. this._reconnectionAttempts = v;
  9408. return this;
  9409. }
  9410. reconnectionDelay(v) {
  9411. var _a;
  9412. if (v === undefined)
  9413. return this._reconnectionDelay;
  9414. this._reconnectionDelay = v;
  9415. (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);
  9416. return this;
  9417. }
  9418. randomizationFactor(v) {
  9419. var _a;
  9420. if (v === undefined)
  9421. return this._randomizationFactor;
  9422. this._randomizationFactor = v;
  9423. (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);
  9424. return this;
  9425. }
  9426. reconnectionDelayMax(v) {
  9427. var _a;
  9428. if (v === undefined)
  9429. return this._reconnectionDelayMax;
  9430. this._reconnectionDelayMax = v;
  9431. (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);
  9432. return this;
  9433. }
  9434. timeout(v) {
  9435. if (!arguments.length)
  9436. return this._timeout;
  9437. this._timeout = v;
  9438. return this;
  9439. }
  9440. /**
  9441. * Starts trying to reconnect if reconnection is enabled and we have not
  9442. * started reconnecting yet
  9443. *
  9444. * @private
  9445. */
  9446. maybeReconnectOnOpen() {
  9447. // Only try to reconnect if it's the first time we're connecting
  9448. if (!this._reconnecting &&
  9449. this._reconnection &&
  9450. this.backoff.attempts === 0) {
  9451. // keeps reconnection from firing twice for the same reconnection loop
  9452. this.reconnect();
  9453. }
  9454. }
  9455. /**
  9456. * Sets the current transport `socket`.
  9457. *
  9458. * @param {Function} fn - optional, callback
  9459. * @return self
  9460. * @public
  9461. */
  9462. open(fn) {
  9463. debug("readyState %s", this._readyState);
  9464. if (~this._readyState.indexOf("open"))
  9465. return this;
  9466. debug("opening %s", this.uri);
  9467. this.engine = new engine_io_client_1.Socket(this.uri, this.opts);
  9468. const socket = this.engine;
  9469. const self = this;
  9470. this._readyState = "opening";
  9471. this.skipReconnect = false;
  9472. // emit `open`
  9473. const openSubDestroy = on_js_1.on(socket, "open", function () {
  9474. self.onopen();
  9475. fn && fn();
  9476. });
  9477. // emit `error`
  9478. const errorSub = on_js_1.on(socket, "error", (err) => {
  9479. debug("error");
  9480. self.cleanup();
  9481. self._readyState = "closed";
  9482. this.emitReserved("error", err);
  9483. if (fn) {
  9484. fn(err);
  9485. }
  9486. else {
  9487. // Only do this if there is no fn to handle the error
  9488. self.maybeReconnectOnOpen();
  9489. }
  9490. });
  9491. if (false !== this._timeout) {
  9492. const timeout = this._timeout;
  9493. debug("connect attempt will timeout after %d", timeout);
  9494. if (timeout === 0) {
  9495. openSubDestroy(); // prevents a race condition with the 'open' event
  9496. }
  9497. // set timer
  9498. const timer = this.setTimeoutFn(() => {
  9499. debug("connect attempt timed out after %d", timeout);
  9500. openSubDestroy();
  9501. socket.close();
  9502. // @ts-ignore
  9503. socket.emit("error", new Error("timeout"));
  9504. }, timeout);
  9505. if (this.opts.autoUnref) {
  9506. timer.unref();
  9507. }
  9508. this.subs.push(function subDestroy() {
  9509. clearTimeout(timer);
  9510. });
  9511. }
  9512. this.subs.push(openSubDestroy);
  9513. this.subs.push(errorSub);
  9514. return this;
  9515. }
  9516. /**
  9517. * Alias for open()
  9518. *
  9519. * @return self
  9520. * @public
  9521. */
  9522. connect(fn) {
  9523. return this.open(fn);
  9524. }
  9525. /**
  9526. * Called upon transport open.
  9527. *
  9528. * @private
  9529. */
  9530. onopen() {
  9531. debug("open");
  9532. // clear old subs
  9533. this.cleanup();
  9534. // mark as open
  9535. this._readyState = "open";
  9536. this.emitReserved("open");
  9537. // add new subs
  9538. const socket = this.engine;
  9539. this.subs.push(on_js_1.on(socket, "ping", this.onping.bind(this)), on_js_1.on(socket, "data", this.ondata.bind(this)), on_js_1.on(socket, "error", this.onerror.bind(this)), on_js_1.on(socket, "close", this.onclose.bind(this)), on_js_1.on(this.decoder, "decoded", this.ondecoded.bind(this)));
  9540. }
  9541. /**
  9542. * Called upon a ping.
  9543. *
  9544. * @private
  9545. */
  9546. onping() {
  9547. this.emitReserved("ping");
  9548. }
  9549. /**
  9550. * Called with data.
  9551. *
  9552. * @private
  9553. */
  9554. ondata(data) {
  9555. this.decoder.add(data);
  9556. }
  9557. /**
  9558. * Called when parser fully decodes a packet.
  9559. *
  9560. * @private
  9561. */
  9562. ondecoded(packet) {
  9563. this.emitReserved("packet", packet);
  9564. }
  9565. /**
  9566. * Called upon socket error.
  9567. *
  9568. * @private
  9569. */
  9570. onerror(err) {
  9571. debug("error", err);
  9572. this.emitReserved("error", err);
  9573. }
  9574. /**
  9575. * Creates a new socket for the given `nsp`.
  9576. *
  9577. * @return {Socket}
  9578. * @public
  9579. */
  9580. socket(nsp, opts) {
  9581. let socket = this.nsps[nsp];
  9582. if (!socket) {
  9583. socket = new socket_js_1.Socket(this, nsp, opts);
  9584. this.nsps[nsp] = socket;
  9585. }
  9586. return socket;
  9587. }
  9588. /**
  9589. * Called upon a socket close.
  9590. *
  9591. * @param socket
  9592. * @private
  9593. */
  9594. _destroy(socket) {
  9595. const nsps = Object.keys(this.nsps);
  9596. for (const nsp of nsps) {
  9597. const socket = this.nsps[nsp];
  9598. if (socket.active) {
  9599. debug("socket %s is still active, skipping close", nsp);
  9600. return;
  9601. }
  9602. }
  9603. this._close();
  9604. }
  9605. /**
  9606. * Writes a packet.
  9607. *
  9608. * @param packet
  9609. * @private
  9610. */
  9611. _packet(packet) {
  9612. debug("writing packet %j", packet);
  9613. const encodedPackets = this.encoder.encode(packet);
  9614. for (let i = 0; i < encodedPackets.length; i++) {
  9615. this.engine.write(encodedPackets[i], packet.options);
  9616. }
  9617. }
  9618. /**
  9619. * Clean up transport subscriptions and packet buffer.
  9620. *
  9621. * @private
  9622. */
  9623. cleanup() {
  9624. debug("cleanup");
  9625. this.subs.forEach((subDestroy) => subDestroy());
  9626. this.subs.length = 0;
  9627. this.decoder.destroy();
  9628. }
  9629. /**
  9630. * Close the current socket.
  9631. *
  9632. * @private
  9633. */
  9634. _close() {
  9635. debug("disconnect");
  9636. this.skipReconnect = true;
  9637. this._reconnecting = false;
  9638. if ("opening" === this._readyState) {
  9639. // `onclose` will not fire because
  9640. // an open event never happened
  9641. this.cleanup();
  9642. }
  9643. this.backoff.reset();
  9644. this._readyState = "closed";
  9645. if (this.engine)
  9646. this.engine.close();
  9647. }
  9648. /**
  9649. * Alias for close()
  9650. *
  9651. * @private
  9652. */
  9653. disconnect() {
  9654. return this._close();
  9655. }
  9656. /**
  9657. * Called upon engine close.
  9658. *
  9659. * @private
  9660. */
  9661. onclose(reason) {
  9662. debug("onclose");
  9663. this.cleanup();
  9664. this.backoff.reset();
  9665. this._readyState = "closed";
  9666. this.emitReserved("close", reason);
  9667. if (this._reconnection && !this.skipReconnect) {
  9668. this.reconnect();
  9669. }
  9670. }
  9671. /**
  9672. * Attempt a reconnection.
  9673. *
  9674. * @private
  9675. */
  9676. reconnect() {
  9677. if (this._reconnecting || this.skipReconnect)
  9678. return this;
  9679. const self = this;
  9680. if (this.backoff.attempts >= this._reconnectionAttempts) {
  9681. debug("reconnect failed");
  9682. this.backoff.reset();
  9683. this.emitReserved("reconnect_failed");
  9684. this._reconnecting = false;
  9685. }
  9686. else {
  9687. const delay = this.backoff.duration();
  9688. debug("will wait %dms before reconnect attempt", delay);
  9689. this._reconnecting = true;
  9690. const timer = this.setTimeoutFn(() => {
  9691. if (self.skipReconnect)
  9692. return;
  9693. debug("attempting reconnect");
  9694. this.emitReserved("reconnect_attempt", self.backoff.attempts);
  9695. // check again for the case socket closed in above events
  9696. if (self.skipReconnect)
  9697. return;
  9698. self.open((err) => {
  9699. if (err) {
  9700. debug("reconnect attempt error");
  9701. self._reconnecting = false;
  9702. self.reconnect();
  9703. this.emitReserved("reconnect_error", err);
  9704. }
  9705. else {
  9706. debug("reconnect success");
  9707. self.onreconnect();
  9708. }
  9709. });
  9710. }, delay);
  9711. if (this.opts.autoUnref) {
  9712. timer.unref();
  9713. }
  9714. this.subs.push(function subDestroy() {
  9715. clearTimeout(timer);
  9716. });
  9717. }
  9718. }
  9719. /**
  9720. * Called upon successful reconnect.
  9721. *
  9722. * @private
  9723. */
  9724. onreconnect() {
  9725. const attempt = this.backoff.attempts;
  9726. this._reconnecting = false;
  9727. this.backoff.reset();
  9728. this.emitReserved("reconnect", attempt);
  9729. }
  9730. }
  9731. exports.Manager = Manager;
  9732. /***/ }),
  9733. /***/ "../ot-core/node_modules/socket.io-client/build/cjs/on.js":
  9734. /*!****************************************************************!*\
  9735. !*** ../ot-core/node_modules/socket.io-client/build/cjs/on.js ***!
  9736. \****************************************************************/
  9737. /***/ ((__unused_webpack_module, exports) => {
  9738. "use strict";
  9739. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9740. exports.on = void 0;
  9741. function on(obj, ev, fn) {
  9742. obj.on(ev, fn);
  9743. return function subDestroy() {
  9744. obj.off(ev, fn);
  9745. };
  9746. }
  9747. exports.on = on;
  9748. /***/ }),
  9749. /***/ "../ot-core/node_modules/socket.io-client/build/cjs/socket.js":
  9750. /*!********************************************************************!*\
  9751. !*** ../ot-core/node_modules/socket.io-client/build/cjs/socket.js ***!
  9752. \********************************************************************/
  9753. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  9754. "use strict";
  9755. var __importDefault = (this && this.__importDefault) || function (mod) {
  9756. return (mod && mod.__esModule) ? mod : { "default": mod };
  9757. };
  9758. Object.defineProperty(exports, "__esModule", ({ value: true }));
  9759. exports.Socket = void 0;
  9760. const socket_io_parser_1 = __webpack_require__(/*! socket.io-parser */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js");
  9761. const on_js_1 = __webpack_require__(/*! ./on.js */ "../ot-core/node_modules/socket.io-client/build/cjs/on.js");
  9762. const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
  9763. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  9764. const debug = debug_1.default("socket.io-client:socket"); // debug()
  9765. /**
  9766. * Internal events.
  9767. * These events can't be emitted by the user.
  9768. */
  9769. const RESERVED_EVENTS = Object.freeze({
  9770. connect: 1,
  9771. connect_error: 1,
  9772. disconnect: 1,
  9773. disconnecting: 1,
  9774. // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
  9775. newListener: 1,
  9776. removeListener: 1,
  9777. });
  9778. class Socket extends component_emitter_1.Emitter {
  9779. /**
  9780. * `Socket` constructor.
  9781. *
  9782. * @public
  9783. */
  9784. constructor(io, nsp, opts) {
  9785. super();
  9786. this.connected = false;
  9787. this.disconnected = true;
  9788. this.receiveBuffer = [];
  9789. this.sendBuffer = [];
  9790. this.ids = 0;
  9791. this.acks = {};
  9792. this.flags = {};
  9793. this.io = io;
  9794. this.nsp = nsp;
  9795. if (opts && opts.auth) {
  9796. this.auth = opts.auth;
  9797. }
  9798. if (this.io._autoConnect)
  9799. this.open();
  9800. }
  9801. /**
  9802. * Subscribe to open, close and packet events
  9803. *
  9804. * @private
  9805. */
  9806. subEvents() {
  9807. if (this.subs)
  9808. return;
  9809. const io = this.io;
  9810. this.subs = [
  9811. on_js_1.on(io, "open", this.onopen.bind(this)),
  9812. on_js_1.on(io, "packet", this.onpacket.bind(this)),
  9813. on_js_1.on(io, "error", this.onerror.bind(this)),
  9814. on_js_1.on(io, "close", this.onclose.bind(this)),
  9815. ];
  9816. }
  9817. /**
  9818. * Whether the Socket will try to reconnect when its Manager connects or reconnects
  9819. */
  9820. get active() {
  9821. return !!this.subs;
  9822. }
  9823. /**
  9824. * "Opens" the socket.
  9825. *
  9826. * @public
  9827. */
  9828. connect() {
  9829. if (this.connected)
  9830. return this;
  9831. this.subEvents();
  9832. if (!this.io["_reconnecting"])
  9833. this.io.open(); // ensure open
  9834. if ("open" === this.io._readyState)
  9835. this.onopen();
  9836. return this;
  9837. }
  9838. /**
  9839. * Alias for connect()
  9840. */
  9841. open() {
  9842. return this.connect();
  9843. }
  9844. /**
  9845. * Sends a `message` event.
  9846. *
  9847. * @return self
  9848. * @public
  9849. */
  9850. send(...args) {
  9851. args.unshift("message");
  9852. this.emit.apply(this, args);
  9853. return this;
  9854. }
  9855. /**
  9856. * Override `emit`.
  9857. * If the event is in `events`, it's emitted normally.
  9858. *
  9859. * @return self
  9860. * @public
  9861. */
  9862. emit(ev, ...args) {
  9863. if (RESERVED_EVENTS.hasOwnProperty(ev)) {
  9864. throw new Error('"' + ev + '" is a reserved event name');
  9865. }
  9866. args.unshift(ev);
  9867. const packet = {
  9868. type: socket_io_parser_1.PacketType.EVENT,
  9869. data: args,
  9870. };
  9871. packet.options = {};
  9872. packet.options.compress = this.flags.compress !== false;
  9873. // event ack callback
  9874. if ("function" === typeof args[args.length - 1]) {
  9875. debug("emitting packet with ack id %d", this.ids);
  9876. this.acks[this.ids] = args.pop();
  9877. packet.id = this.ids++;
  9878. }
  9879. const isTransportWritable = this.io.engine &&
  9880. this.io.engine.transport &&
  9881. this.io.engine.transport.writable;
  9882. const discardPacket = this.flags.volatile && (!isTransportWritable || !this.connected);
  9883. if (discardPacket) {
  9884. debug("discard packet as the transport is not currently writable");
  9885. }
  9886. else if (this.connected) {
  9887. this.packet(packet);
  9888. }
  9889. else {
  9890. this.sendBuffer.push(packet);
  9891. }
  9892. this.flags = {};
  9893. return this;
  9894. }
  9895. /**
  9896. * Sends a packet.
  9897. *
  9898. * @param packet
  9899. * @private
  9900. */
  9901. packet(packet) {
  9902. packet.nsp = this.nsp;
  9903. this.io._packet(packet);
  9904. }
  9905. /**
  9906. * Called upon engine `open`.
  9907. *
  9908. * @private
  9909. */
  9910. onopen() {
  9911. debug("transport is open - connecting");
  9912. if (typeof this.auth == "function") {
  9913. this.auth((data) => {
  9914. this.packet({ type: socket_io_parser_1.PacketType.CONNECT, data });
  9915. });
  9916. }
  9917. else {
  9918. this.packet({ type: socket_io_parser_1.PacketType.CONNECT, data: this.auth });
  9919. }
  9920. }
  9921. /**
  9922. * Called upon engine or manager `error`.
  9923. *
  9924. * @param err
  9925. * @private
  9926. */
  9927. onerror(err) {
  9928. if (!this.connected) {
  9929. this.emitReserved("connect_error", err);
  9930. }
  9931. }
  9932. /**
  9933. * Called upon engine `close`.
  9934. *
  9935. * @param reason
  9936. * @private
  9937. */
  9938. onclose(reason) {
  9939. debug("close (%s)", reason);
  9940. this.connected = false;
  9941. this.disconnected = true;
  9942. delete this.id;
  9943. this.emitReserved("disconnect", reason);
  9944. }
  9945. /**
  9946. * Called with socket packet.
  9947. *
  9948. * @param packet
  9949. * @private
  9950. */
  9951. onpacket(packet) {
  9952. const sameNamespace = packet.nsp === this.nsp;
  9953. if (!sameNamespace)
  9954. return;
  9955. switch (packet.type) {
  9956. case socket_io_parser_1.PacketType.CONNECT:
  9957. if (packet.data && packet.data.sid) {
  9958. const id = packet.data.sid;
  9959. this.onconnect(id);
  9960. }
  9961. else {
  9962. this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
  9963. }
  9964. break;
  9965. case socket_io_parser_1.PacketType.EVENT:
  9966. this.onevent(packet);
  9967. break;
  9968. case socket_io_parser_1.PacketType.BINARY_EVENT:
  9969. this.onevent(packet);
  9970. break;
  9971. case socket_io_parser_1.PacketType.ACK:
  9972. this.onack(packet);
  9973. break;
  9974. case socket_io_parser_1.PacketType.BINARY_ACK:
  9975. this.onack(packet);
  9976. break;
  9977. case socket_io_parser_1.PacketType.DISCONNECT:
  9978. this.ondisconnect();
  9979. break;
  9980. case socket_io_parser_1.PacketType.CONNECT_ERROR:
  9981. const err = new Error(packet.data.message);
  9982. // @ts-ignore
  9983. err.data = packet.data.data;
  9984. this.emitReserved("connect_error", err);
  9985. break;
  9986. }
  9987. }
  9988. /**
  9989. * Called upon a server event.
  9990. *
  9991. * @param packet
  9992. * @private
  9993. */
  9994. onevent(packet) {
  9995. const args = packet.data || [];
  9996. debug("emitting event %j", args);
  9997. if (null != packet.id) {
  9998. debug("attaching ack callback to event");
  9999. args.push(this.ack(packet.id));
  10000. }
  10001. if (this.connected) {
  10002. this.emitEvent(args);
  10003. }
  10004. else {
  10005. this.receiveBuffer.push(Object.freeze(args));
  10006. }
  10007. }
  10008. emitEvent(args) {
  10009. if (this._anyListeners && this._anyListeners.length) {
  10010. const listeners = this._anyListeners.slice();
  10011. for (const listener of listeners) {
  10012. listener.apply(this, args);
  10013. }
  10014. }
  10015. super.emit.apply(this, args);
  10016. }
  10017. /**
  10018. * Produces an ack callback to emit with an event.
  10019. *
  10020. * @private
  10021. */
  10022. ack(id) {
  10023. const self = this;
  10024. let sent = false;
  10025. return function (...args) {
  10026. // prevent double callbacks
  10027. if (sent)
  10028. return;
  10029. sent = true;
  10030. debug("sending ack %j", args);
  10031. self.packet({
  10032. type: socket_io_parser_1.PacketType.ACK,
  10033. id: id,
  10034. data: args,
  10035. });
  10036. };
  10037. }
  10038. /**
  10039. * Called upon a server acknowlegement.
  10040. *
  10041. * @param packet
  10042. * @private
  10043. */
  10044. onack(packet) {
  10045. const ack = this.acks[packet.id];
  10046. if ("function" === typeof ack) {
  10047. debug("calling ack %s with %j", packet.id, packet.data);
  10048. ack.apply(this, packet.data);
  10049. delete this.acks[packet.id];
  10050. }
  10051. else {
  10052. debug("bad ack %s", packet.id);
  10053. }
  10054. }
  10055. /**
  10056. * Called upon server connect.
  10057. *
  10058. * @private
  10059. */
  10060. onconnect(id) {
  10061. debug("socket connected with id %s", id);
  10062. this.id = id;
  10063. this.connected = true;
  10064. this.disconnected = false;
  10065. this.emitBuffered();
  10066. this.emitReserved("connect");
  10067. }
  10068. /**
  10069. * Emit buffered events (received and emitted).
  10070. *
  10071. * @private
  10072. */
  10073. emitBuffered() {
  10074. this.receiveBuffer.forEach((args) => this.emitEvent(args));
  10075. this.receiveBuffer = [];
  10076. this.sendBuffer.forEach((packet) => this.packet(packet));
  10077. this.sendBuffer = [];
  10078. }
  10079. /**
  10080. * Called upon server disconnect.
  10081. *
  10082. * @private
  10083. */
  10084. ondisconnect() {
  10085. debug("server disconnect (%s)", this.nsp);
  10086. this.destroy();
  10087. this.onclose("io server disconnect");
  10088. }
  10089. /**
  10090. * Called upon forced client/server side disconnections,
  10091. * this method ensures the manager stops tracking us and
  10092. * that reconnections don't get triggered for this.
  10093. *
  10094. * @private
  10095. */
  10096. destroy() {
  10097. if (this.subs) {
  10098. // clean subscriptions to avoid reconnections
  10099. this.subs.forEach((subDestroy) => subDestroy());
  10100. this.subs = undefined;
  10101. }
  10102. this.io["_destroy"](this);
  10103. }
  10104. /**
  10105. * Disconnects the socket manually.
  10106. *
  10107. * @return self
  10108. * @public
  10109. */
  10110. disconnect() {
  10111. if (this.connected) {
  10112. debug("performing disconnect (%s)", this.nsp);
  10113. this.packet({ type: socket_io_parser_1.PacketType.DISCONNECT });
  10114. }
  10115. // remove socket from pool
  10116. this.destroy();
  10117. if (this.connected) {
  10118. // fire events
  10119. this.onclose("io client disconnect");
  10120. }
  10121. return this;
  10122. }
  10123. /**
  10124. * Alias for disconnect()
  10125. *
  10126. * @return self
  10127. * @public
  10128. */
  10129. close() {
  10130. return this.disconnect();
  10131. }
  10132. /**
  10133. * Sets the compress flag.
  10134. *
  10135. * @param compress - if `true`, compresses the sending data
  10136. * @return self
  10137. * @public
  10138. */
  10139. compress(compress) {
  10140. this.flags.compress = compress;
  10141. return this;
  10142. }
  10143. /**
  10144. * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
  10145. * ready to send messages.
  10146. *
  10147. * @returns self
  10148. * @public
  10149. */
  10150. get volatile() {
  10151. this.flags.volatile = true;
  10152. return this;
  10153. }
  10154. /**
  10155. * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
  10156. * callback.
  10157. *
  10158. * @param listener
  10159. * @public
  10160. */
  10161. onAny(listener) {
  10162. this._anyListeners = this._anyListeners || [];
  10163. this._anyListeners.push(listener);
  10164. return this;
  10165. }
  10166. /**
  10167. * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
  10168. * callback. The listener is added to the beginning of the listeners array.
  10169. *
  10170. * @param listener
  10171. * @public
  10172. */
  10173. prependAny(listener) {
  10174. this._anyListeners = this._anyListeners || [];
  10175. this._anyListeners.unshift(listener);
  10176. return this;
  10177. }
  10178. /**
  10179. * Removes the listener that will be fired when any event is emitted.
  10180. *
  10181. * @param listener
  10182. * @public
  10183. */
  10184. offAny(listener) {
  10185. if (!this._anyListeners) {
  10186. return this;
  10187. }
  10188. if (listener) {
  10189. const listeners = this._anyListeners;
  10190. for (let i = 0; i < listeners.length; i++) {
  10191. if (listener === listeners[i]) {
  10192. listeners.splice(i, 1);
  10193. return this;
  10194. }
  10195. }
  10196. }
  10197. else {
  10198. this._anyListeners = [];
  10199. }
  10200. return this;
  10201. }
  10202. /**
  10203. * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
  10204. * e.g. to remove listeners.
  10205. *
  10206. * @public
  10207. */
  10208. listenersAny() {
  10209. return this._anyListeners || [];
  10210. }
  10211. }
  10212. exports.Socket = Socket;
  10213. /***/ }),
  10214. /***/ "../ot-core/node_modules/socket.io-client/build/cjs/url.js":
  10215. /*!*****************************************************************!*\
  10216. !*** ../ot-core/node_modules/socket.io-client/build/cjs/url.js ***!
  10217. \*****************************************************************/
  10218. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  10219. "use strict";
  10220. var __importDefault = (this && this.__importDefault) || function (mod) {
  10221. return (mod && mod.__esModule) ? mod : { "default": mod };
  10222. };
  10223. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10224. exports.url = void 0;
  10225. const parseuri_1 = __importDefault(__webpack_require__(/*! parseuri */ "../ot-core/node_modules/parseuri/index.js"));
  10226. const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
  10227. const debug = debug_1.default("socket.io-client:url"); // debug()
  10228. /**
  10229. * URL parser.
  10230. *
  10231. * @param uri - url
  10232. * @param path - the request path of the connection
  10233. * @param loc - An object meant to mimic window.location.
  10234. * Defaults to window.location.
  10235. * @public
  10236. */
  10237. function url(uri, path = "", loc) {
  10238. let obj = uri;
  10239. // default to window.location
  10240. loc = loc || (typeof location !== "undefined" && location);
  10241. if (null == uri)
  10242. uri = loc.protocol + "//" + loc.host;
  10243. // relative path support
  10244. if (typeof uri === "string") {
  10245. if ("/" === uri.charAt(0)) {
  10246. if ("/" === uri.charAt(1)) {
  10247. uri = loc.protocol + uri;
  10248. }
  10249. else {
  10250. uri = loc.host + uri;
  10251. }
  10252. }
  10253. if (!/^(https?|wss?):\/\//.test(uri)) {
  10254. debug("protocol-less url %s", uri);
  10255. if ("undefined" !== typeof loc) {
  10256. uri = loc.protocol + "//" + uri;
  10257. }
  10258. else {
  10259. uri = "https://" + uri;
  10260. }
  10261. }
  10262. // parse
  10263. debug("parse %s", uri);
  10264. obj = parseuri_1.default(uri);
  10265. }
  10266. // make sure we treat `localhost:80` and `localhost` equally
  10267. if (!obj.port) {
  10268. if (/^(http|ws)$/.test(obj.protocol)) {
  10269. obj.port = "80";
  10270. }
  10271. else if (/^(http|ws)s$/.test(obj.protocol)) {
  10272. obj.port = "443";
  10273. }
  10274. }
  10275. obj.path = obj.path || "/";
  10276. const ipv6 = obj.host.indexOf(":") !== -1;
  10277. const host = ipv6 ? "[" + obj.host + "]" : obj.host;
  10278. // define unique id
  10279. obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
  10280. // define href
  10281. obj.href =
  10282. obj.protocol +
  10283. "://" +
  10284. host +
  10285. (loc && loc.port === obj.port ? "" : ":" + obj.port);
  10286. return obj;
  10287. }
  10288. exports.url = url;
  10289. /***/ }),
  10290. /***/ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/binary.js":
  10291. /*!**************************************************************************************************!*\
  10292. !*** ../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/binary.js ***!
  10293. \**************************************************************************************************/
  10294. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10295. "use strict";
  10296. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10297. exports.reconstructPacket = exports.deconstructPacket = void 0;
  10298. const is_binary_js_1 = __webpack_require__(/*! ./is-binary.js */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/is-binary.js");
  10299. /**
  10300. * Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
  10301. *
  10302. * @param {Object} packet - socket.io event packet
  10303. * @return {Object} with deconstructed packet and list of buffers
  10304. * @public
  10305. */
  10306. function deconstructPacket(packet) {
  10307. const buffers = [];
  10308. const packetData = packet.data;
  10309. const pack = packet;
  10310. pack.data = _deconstructPacket(packetData, buffers);
  10311. pack.attachments = buffers.length; // number of binary 'attachments'
  10312. return { packet: pack, buffers: buffers };
  10313. }
  10314. exports.deconstructPacket = deconstructPacket;
  10315. function _deconstructPacket(data, buffers) {
  10316. if (!data)
  10317. return data;
  10318. if (is_binary_js_1.isBinary(data)) {
  10319. const placeholder = { _placeholder: true, num: buffers.length };
  10320. buffers.push(data);
  10321. return placeholder;
  10322. }
  10323. else if (Array.isArray(data)) {
  10324. const newData = new Array(data.length);
  10325. for (let i = 0; i < data.length; i++) {
  10326. newData[i] = _deconstructPacket(data[i], buffers);
  10327. }
  10328. return newData;
  10329. }
  10330. else if (typeof data === "object" && !(data instanceof Date)) {
  10331. const newData = {};
  10332. for (const key in data) {
  10333. if (Object.prototype.hasOwnProperty.call(data, key)) {
  10334. newData[key] = _deconstructPacket(data[key], buffers);
  10335. }
  10336. }
  10337. return newData;
  10338. }
  10339. return data;
  10340. }
  10341. /**
  10342. * Reconstructs a binary packet from its placeholder packet and buffers
  10343. *
  10344. * @param {Object} packet - event packet with placeholders
  10345. * @param {Array} buffers - binary buffers to put in placeholder positions
  10346. * @return {Object} reconstructed packet
  10347. * @public
  10348. */
  10349. function reconstructPacket(packet, buffers) {
  10350. packet.data = _reconstructPacket(packet.data, buffers);
  10351. packet.attachments = undefined; // no longer useful
  10352. return packet;
  10353. }
  10354. exports.reconstructPacket = reconstructPacket;
  10355. function _reconstructPacket(data, buffers) {
  10356. if (!data)
  10357. return data;
  10358. if (data && data._placeholder) {
  10359. return buffers[data.num]; // appropriate buffer (should be natural order anyway)
  10360. }
  10361. else if (Array.isArray(data)) {
  10362. for (let i = 0; i < data.length; i++) {
  10363. data[i] = _reconstructPacket(data[i], buffers);
  10364. }
  10365. }
  10366. else if (typeof data === "object") {
  10367. for (const key in data) {
  10368. if (Object.prototype.hasOwnProperty.call(data, key)) {
  10369. data[key] = _reconstructPacket(data[key], buffers);
  10370. }
  10371. }
  10372. }
  10373. return data;
  10374. }
  10375. /***/ }),
  10376. /***/ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js":
  10377. /*!*************************************************************************************************!*\
  10378. !*** ../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js ***!
  10379. \*************************************************************************************************/
  10380. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10381. "use strict";
  10382. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10383. exports.Decoder = exports.Encoder = exports.PacketType = exports.protocol = void 0;
  10384. const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
  10385. const binary_js_1 = __webpack_require__(/*! ./binary.js */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/binary.js");
  10386. const is_binary_js_1 = __webpack_require__(/*! ./is-binary.js */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/is-binary.js");
  10387. const debug_1 = __webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js"); // debug()
  10388. const debug = debug_1.default("socket.io-parser"); // debug()
  10389. /**
  10390. * Protocol version.
  10391. *
  10392. * @public
  10393. */
  10394. exports.protocol = 5;
  10395. var PacketType;
  10396. (function (PacketType) {
  10397. PacketType[PacketType["CONNECT"] = 0] = "CONNECT";
  10398. PacketType[PacketType["DISCONNECT"] = 1] = "DISCONNECT";
  10399. PacketType[PacketType["EVENT"] = 2] = "EVENT";
  10400. PacketType[PacketType["ACK"] = 3] = "ACK";
  10401. PacketType[PacketType["CONNECT_ERROR"] = 4] = "CONNECT_ERROR";
  10402. PacketType[PacketType["BINARY_EVENT"] = 5] = "BINARY_EVENT";
  10403. PacketType[PacketType["BINARY_ACK"] = 6] = "BINARY_ACK";
  10404. })(PacketType = exports.PacketType || (exports.PacketType = {}));
  10405. /**
  10406. * A socket.io Encoder instance
  10407. */
  10408. class Encoder {
  10409. /**
  10410. * Encode a packet as a single string if non-binary, or as a
  10411. * buffer sequence, depending on packet type.
  10412. *
  10413. * @param {Object} obj - packet object
  10414. */
  10415. encode(obj) {
  10416. debug("encoding packet %j", obj);
  10417. if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
  10418. if (is_binary_js_1.hasBinary(obj)) {
  10419. obj.type =
  10420. obj.type === PacketType.EVENT
  10421. ? PacketType.BINARY_EVENT
  10422. : PacketType.BINARY_ACK;
  10423. return this.encodeAsBinary(obj);
  10424. }
  10425. }
  10426. return [this.encodeAsString(obj)];
  10427. }
  10428. /**
  10429. * Encode packet as string.
  10430. */
  10431. encodeAsString(obj) {
  10432. // first is type
  10433. let str = "" + obj.type;
  10434. // attachments if we have them
  10435. if (obj.type === PacketType.BINARY_EVENT ||
  10436. obj.type === PacketType.BINARY_ACK) {
  10437. str += obj.attachments + "-";
  10438. }
  10439. // if we have a namespace other than `/`
  10440. // we append it followed by a comma `,`
  10441. if (obj.nsp && "/" !== obj.nsp) {
  10442. str += obj.nsp + ",";
  10443. }
  10444. // immediately followed by the id
  10445. if (null != obj.id) {
  10446. str += obj.id;
  10447. }
  10448. // json data
  10449. if (null != obj.data) {
  10450. str += JSON.stringify(obj.data);
  10451. }
  10452. debug("encoded %j as %s", obj, str);
  10453. return str;
  10454. }
  10455. /**
  10456. * Encode packet as 'buffer sequence' by removing blobs, and
  10457. * deconstructing packet into object with placeholders and
  10458. * a list of buffers.
  10459. */
  10460. encodeAsBinary(obj) {
  10461. const deconstruction = binary_js_1.deconstructPacket(obj);
  10462. const pack = this.encodeAsString(deconstruction.packet);
  10463. const buffers = deconstruction.buffers;
  10464. buffers.unshift(pack); // add packet info to beginning of data list
  10465. return buffers; // write all the buffers
  10466. }
  10467. }
  10468. exports.Encoder = Encoder;
  10469. /**
  10470. * A socket.io Decoder instance
  10471. *
  10472. * @return {Object} decoder
  10473. */
  10474. class Decoder extends component_emitter_1.Emitter {
  10475. constructor() {
  10476. super();
  10477. }
  10478. /**
  10479. * Decodes an encoded packet string into packet JSON.
  10480. *
  10481. * @param {String} obj - encoded packet
  10482. */
  10483. add(obj) {
  10484. let packet;
  10485. if (typeof obj === "string") {
  10486. packet = this.decodeString(obj);
  10487. if (packet.type === PacketType.BINARY_EVENT ||
  10488. packet.type === PacketType.BINARY_ACK) {
  10489. // binary packet's json
  10490. this.reconstructor = new BinaryReconstructor(packet);
  10491. // no attachments, labeled binary but no binary data to follow
  10492. if (packet.attachments === 0) {
  10493. super.emitReserved("decoded", packet);
  10494. }
  10495. }
  10496. else {
  10497. // non-binary full packet
  10498. super.emitReserved("decoded", packet);
  10499. }
  10500. }
  10501. else if (is_binary_js_1.isBinary(obj) || obj.base64) {
  10502. // raw binary data
  10503. if (!this.reconstructor) {
  10504. throw new Error("got binary data when not reconstructing a packet");
  10505. }
  10506. else {
  10507. packet = this.reconstructor.takeBinaryData(obj);
  10508. if (packet) {
  10509. // received final buffer
  10510. this.reconstructor = null;
  10511. super.emitReserved("decoded", packet);
  10512. }
  10513. }
  10514. }
  10515. else {
  10516. throw new Error("Unknown type: " + obj);
  10517. }
  10518. }
  10519. /**
  10520. * Decode a packet String (JSON data)
  10521. *
  10522. * @param {String} str
  10523. * @return {Object} packet
  10524. */
  10525. decodeString(str) {
  10526. let i = 0;
  10527. // look up type
  10528. const p = {
  10529. type: Number(str.charAt(0)),
  10530. };
  10531. if (PacketType[p.type] === undefined) {
  10532. throw new Error("unknown packet type " + p.type);
  10533. }
  10534. // look up attachments if type binary
  10535. if (p.type === PacketType.BINARY_EVENT ||
  10536. p.type === PacketType.BINARY_ACK) {
  10537. const start = i + 1;
  10538. while (str.charAt(++i) !== "-" && i != str.length) { }
  10539. const buf = str.substring(start, i);
  10540. if (buf != Number(buf) || str.charAt(i) !== "-") {
  10541. throw new Error("Illegal attachments");
  10542. }
  10543. p.attachments = Number(buf);
  10544. }
  10545. // look up namespace (if any)
  10546. if ("/" === str.charAt(i + 1)) {
  10547. const start = i + 1;
  10548. while (++i) {
  10549. const c = str.charAt(i);
  10550. if ("," === c)
  10551. break;
  10552. if (i === str.length)
  10553. break;
  10554. }
  10555. p.nsp = str.substring(start, i);
  10556. }
  10557. else {
  10558. p.nsp = "/";
  10559. }
  10560. // look up id
  10561. const next = str.charAt(i + 1);
  10562. if ("" !== next && Number(next) == next) {
  10563. const start = i + 1;
  10564. while (++i) {
  10565. const c = str.charAt(i);
  10566. if (null == c || Number(c) != c) {
  10567. --i;
  10568. break;
  10569. }
  10570. if (i === str.length)
  10571. break;
  10572. }
  10573. p.id = Number(str.substring(start, i + 1));
  10574. }
  10575. // look up json data
  10576. if (str.charAt(++i)) {
  10577. const payload = tryParse(str.substr(i));
  10578. if (Decoder.isPayloadValid(p.type, payload)) {
  10579. p.data = payload;
  10580. }
  10581. else {
  10582. throw new Error("invalid payload");
  10583. }
  10584. }
  10585. debug("decoded %s as %j", str, p);
  10586. return p;
  10587. }
  10588. static isPayloadValid(type, payload) {
  10589. switch (type) {
  10590. case PacketType.CONNECT:
  10591. return typeof payload === "object";
  10592. case PacketType.DISCONNECT:
  10593. return payload === undefined;
  10594. case PacketType.CONNECT_ERROR:
  10595. return typeof payload === "string" || typeof payload === "object";
  10596. case PacketType.EVENT:
  10597. case PacketType.BINARY_EVENT:
  10598. return Array.isArray(payload) && payload.length > 0;
  10599. case PacketType.ACK:
  10600. case PacketType.BINARY_ACK:
  10601. return Array.isArray(payload);
  10602. }
  10603. }
  10604. /**
  10605. * Deallocates a parser's resources
  10606. */
  10607. destroy() {
  10608. if (this.reconstructor) {
  10609. this.reconstructor.finishedReconstruction();
  10610. }
  10611. }
  10612. }
  10613. exports.Decoder = Decoder;
  10614. function tryParse(str) {
  10615. try {
  10616. return JSON.parse(str);
  10617. }
  10618. catch (e) {
  10619. return false;
  10620. }
  10621. }
  10622. /**
  10623. * A manager of a binary event's 'buffer sequence'. Should
  10624. * be constructed whenever a packet of type BINARY_EVENT is
  10625. * decoded.
  10626. *
  10627. * @param {Object} packet
  10628. * @return {BinaryReconstructor} initialized reconstructor
  10629. */
  10630. class BinaryReconstructor {
  10631. constructor(packet) {
  10632. this.packet = packet;
  10633. this.buffers = [];
  10634. this.reconPack = packet;
  10635. }
  10636. /**
  10637. * Method to be called when binary data received from connection
  10638. * after a BINARY_EVENT packet.
  10639. *
  10640. * @param {Buffer | ArrayBuffer} binData - the raw binary data received
  10641. * @return {null | Object} returns null if more binary data is expected or
  10642. * a reconstructed packet object if all buffers have been received.
  10643. */
  10644. takeBinaryData(binData) {
  10645. this.buffers.push(binData);
  10646. if (this.buffers.length === this.reconPack.attachments) {
  10647. // done with buffer list
  10648. const packet = binary_js_1.reconstructPacket(this.reconPack, this.buffers);
  10649. this.finishedReconstruction();
  10650. return packet;
  10651. }
  10652. return null;
  10653. }
  10654. /**
  10655. * Cleans up binary packet reconstruction variables.
  10656. */
  10657. finishedReconstruction() {
  10658. this.reconPack = null;
  10659. this.buffers = [];
  10660. }
  10661. }
  10662. /***/ }),
  10663. /***/ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/is-binary.js":
  10664. /*!*****************************************************************************************************!*\
  10665. !*** ../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/is-binary.js ***!
  10666. \*****************************************************************************************************/
  10667. /***/ ((__unused_webpack_module, exports) => {
  10668. "use strict";
  10669. Object.defineProperty(exports, "__esModule", ({ value: true }));
  10670. exports.hasBinary = exports.isBinary = void 0;
  10671. const withNativeArrayBuffer = typeof ArrayBuffer === "function";
  10672. const isView = (obj) => {
  10673. return typeof ArrayBuffer.isView === "function"
  10674. ? ArrayBuffer.isView(obj)
  10675. : obj.buffer instanceof ArrayBuffer;
  10676. };
  10677. const toString = Object.prototype.toString;
  10678. const withNativeBlob = typeof Blob === "function" ||
  10679. (typeof Blob !== "undefined" &&
  10680. toString.call(Blob) === "[object BlobConstructor]");
  10681. const withNativeFile = typeof File === "function" ||
  10682. (typeof File !== "undefined" &&
  10683. toString.call(File) === "[object FileConstructor]");
  10684. /**
  10685. * Returns true if obj is a Buffer, an ArrayBuffer, a Blob or a File.
  10686. *
  10687. * @private
  10688. */
  10689. function isBinary(obj) {
  10690. return ((withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj))) ||
  10691. (withNativeBlob && obj instanceof Blob) ||
  10692. (withNativeFile && obj instanceof File));
  10693. }
  10694. exports.isBinary = isBinary;
  10695. function hasBinary(obj, toJSON) {
  10696. if (!obj || typeof obj !== "object") {
  10697. return false;
  10698. }
  10699. if (Array.isArray(obj)) {
  10700. for (let i = 0, l = obj.length; i < l; i++) {
  10701. if (hasBinary(obj[i])) {
  10702. return true;
  10703. }
  10704. }
  10705. return false;
  10706. }
  10707. if (isBinary(obj)) {
  10708. return true;
  10709. }
  10710. if (obj.toJSON &&
  10711. typeof obj.toJSON === "function" &&
  10712. arguments.length === 1) {
  10713. return hasBinary(obj.toJSON(), true);
  10714. }
  10715. for (const key in obj) {
  10716. if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
  10717. return true;
  10718. }
  10719. }
  10720. return false;
  10721. }
  10722. exports.hasBinary = hasBinary;
  10723. /***/ })
  10724. /******/ });
  10725. /************************************************************************/
  10726. /******/ // The module cache
  10727. /******/ var __webpack_module_cache__ = {};
  10728. /******/
  10729. /******/ // The require function
  10730. /******/ function __webpack_require__(moduleId) {
  10731. /******/ // Check if module is in cache
  10732. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  10733. /******/ if (cachedModule !== undefined) {
  10734. /******/ return cachedModule.exports;
  10735. /******/ }
  10736. /******/ // Create a new module (and put it into the cache)
  10737. /******/ var module = __webpack_module_cache__[moduleId] = {
  10738. /******/ // no module.id needed
  10739. /******/ // no module.loaded needed
  10740. /******/ exports: {}
  10741. /******/ };
  10742. /******/
  10743. /******/ // Execute the module function
  10744. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  10745. /******/
  10746. /******/ // Return the exports of the module
  10747. /******/ return module.exports;
  10748. /******/ }
  10749. /******/
  10750. /************************************************************************/
  10751. /******/
  10752. /******/ // startup
  10753. /******/ // Load entry module and return exports
  10754. /******/ // This entry module is referenced by other modules so it can't be inlined
  10755. /******/ var __webpack_exports__ = __webpack_require__("./src/server.ts");
  10756. /******/
  10757. /******/ return __webpack_exports__;
  10758. /******/ })()
  10759. ;
  10760. });
  10761. //# sourceMappingURL=server.js.map