| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464 |
- (function webpackUniversalModuleDefinition(root, factory) {
- if(typeof exports === 'object' && typeof module === 'object')
- module.exports = factory((function webpackLoadOptionalExternalModule() { try { return require("bufferutil"); } catch(e) {} }()), (function webpackLoadOptionalExternalModule() { try { return require("utf-8-validate"); } catch(e) {} }()));
- else if(typeof define === 'function' && define.amd)
- define(["bufferutil", "utf-8-validate"], factory);
- else if(typeof exports === 'object')
- exports["Node"] = factory((function webpackLoadOptionalExternalModule() { try { return require("bufferutil"); } catch(e) {} }()), (function webpackLoadOptionalExternalModule() { try { return require("utf-8-validate"); } catch(e) {} }()));
- else
- root["Node"] = factory(root["bufferutil"], root["utf-8-validate"]);
- })(global, function(__WEBPACK_EXTERNAL_MODULE_bufferutil__, __WEBPACK_EXTERNAL_MODULE_utf_8_validate__) {
- return /******/ (() => { // webpackBootstrap
- /******/ var __webpack_modules__ = ({
- /***/ "../ot-core/node_modules/@socket.io/component-emitter/index.js":
- /*!*********************************************************************!*\
- !*** ../ot-core/node_modules/@socket.io/component-emitter/index.js ***!
- \*********************************************************************/
- /***/ ((__unused_webpack_module, exports) => {
- /**
- * Expose `Emitter`.
- */
- exports.Emitter = Emitter;
- /**
- * Initialize a new `Emitter`.
- *
- * @api public
- */
- function Emitter(obj) {
- if (obj) return mixin(obj);
- }
- /**
- * Mixin the emitter properties.
- *
- * @param {Object} obj
- * @return {Object}
- * @api private
- */
- function mixin(obj) {
- for (var key in Emitter.prototype) {
- obj[key] = Emitter.prototype[key];
- }
- return obj;
- }
- /**
- * Listen on the given `event` with `fn`.
- *
- * @param {String} event
- * @param {Function} fn
- * @return {Emitter}
- * @api public
- */
- Emitter.prototype.on =
- Emitter.prototype.addEventListener = function(event, fn){
- this._callbacks = this._callbacks || {};
- (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
- .push(fn);
- return this;
- };
- /**
- * Adds an `event` listener that will be invoked a single
- * time then automatically removed.
- *
- * @param {String} event
- * @param {Function} fn
- * @return {Emitter}
- * @api public
- */
- Emitter.prototype.once = function(event, fn){
- function on() {
- this.off(event, on);
- fn.apply(this, arguments);
- }
- on.fn = fn;
- this.on(event, on);
- return this;
- };
- /**
- * Remove the given callback for `event` or all
- * registered callbacks.
- *
- * @param {String} event
- * @param {Function} fn
- * @return {Emitter}
- * @api public
- */
- Emitter.prototype.off =
- Emitter.prototype.removeListener =
- Emitter.prototype.removeAllListeners =
- Emitter.prototype.removeEventListener = function(event, fn){
- this._callbacks = this._callbacks || {};
- // all
- if (0 == arguments.length) {
- this._callbacks = {};
- return this;
- }
- // specific event
- var callbacks = this._callbacks['$' + event];
- if (!callbacks) return this;
- // remove all handlers
- if (1 == arguments.length) {
- delete this._callbacks['$' + event];
- return this;
- }
- // remove specific handler
- var cb;
- for (var i = 0; i < callbacks.length; i++) {
- cb = callbacks[i];
- if (cb === fn || cb.fn === fn) {
- callbacks.splice(i, 1);
- break;
- }
- }
- // Remove event specific arrays for event types that no
- // one is subscribed for to avoid memory leak.
- if (callbacks.length === 0) {
- delete this._callbacks['$' + event];
- }
- return this;
- };
- /**
- * Emit `event` with the given args.
- *
- * @param {String} event
- * @param {Mixed} ...
- * @return {Emitter}
- */
- Emitter.prototype.emit = function(event){
- this._callbacks = this._callbacks || {};
- var args = new Array(arguments.length - 1)
- , callbacks = this._callbacks['$' + event];
- for (var i = 1; i < arguments.length; i++) {
- args[i - 1] = arguments[i];
- }
- if (callbacks) {
- callbacks = callbacks.slice(0);
- for (var i = 0, len = callbacks.length; i < len; ++i) {
- callbacks[i].apply(this, args);
- }
- }
- return this;
- };
- // alias used for reserved events (protected method)
- Emitter.prototype.emitReserved = Emitter.prototype.emit;
- /**
- * Return array of callbacks for `event`.
- *
- * @param {String} event
- * @return {Array}
- * @api public
- */
- Emitter.prototype.listeners = function(event){
- this._callbacks = this._callbacks || {};
- return this._callbacks['$' + event] || [];
- };
- /**
- * Check if this emitter has `event` handlers.
- *
- * @param {String} event
- * @return {Boolean}
- * @api public
- */
- Emitter.prototype.hasListeners = function(event){
- return !! this.listeners(event).length;
- };
- /***/ }),
- /***/ "../ot-core/node_modules/backo2/index.js":
- /*!***********************************************!*\
- !*** ../ot-core/node_modules/backo2/index.js ***!
- \***********************************************/
- /***/ ((module) => {
- /**
- * Expose `Backoff`.
- */
- module.exports = Backoff;
- /**
- * Initialize backoff timer with `opts`.
- *
- * - `min` initial timeout in milliseconds [100]
- * - `max` max timeout [10000]
- * - `jitter` [0]
- * - `factor` [2]
- *
- * @param {Object} opts
- * @api public
- */
- function Backoff(opts) {
- opts = opts || {};
- this.ms = opts.min || 100;
- this.max = opts.max || 10000;
- this.factor = opts.factor || 2;
- this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
- this.attempts = 0;
- }
- /**
- * Return the backoff duration.
- *
- * @return {Number}
- * @api public
- */
- Backoff.prototype.duration = function(){
- var ms = this.ms * Math.pow(this.factor, this.attempts++);
- if (this.jitter) {
- var rand = Math.random();
- var deviation = Math.floor(rand * this.jitter * ms);
- ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
- }
- return Math.min(ms, this.max) | 0;
- };
- /**
- * Reset the number of attempts.
- *
- * @api public
- */
- Backoff.prototype.reset = function(){
- this.attempts = 0;
- };
- /**
- * Set the minimum duration
- *
- * @api public
- */
- Backoff.prototype.setMin = function(min){
- this.ms = min;
- };
- /**
- * Set the maximum duration
- *
- * @api public
- */
- Backoff.prototype.setMax = function(max){
- this.max = max;
- };
- /**
- * Set the jitter
- *
- * @api public
- */
- Backoff.prototype.setJitter = function(jitter){
- this.jitter = jitter;
- };
- /***/ }),
- /***/ "../ot-core/node_modules/debug/src/browser.js":
- /*!****************************************************!*\
- !*** ../ot-core/node_modules/debug/src/browser.js ***!
- \****************************************************/
- /***/ ((module, exports, __webpack_require__) => {
- /* eslint-env browser */
- /**
- * This is the web browser implementation of `debug()`.
- */
- exports.formatArgs = formatArgs;
- exports.save = save;
- exports.load = load;
- exports.useColors = useColors;
- exports.storage = localstorage();
- exports.destroy = (() => {
- let warned = false;
- return () => {
- if (!warned) {
- warned = true;
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
- }
- };
- })();
- /**
- * Colors.
- */
- exports.colors = [
- '#0000CC',
- '#0000FF',
- '#0033CC',
- '#0033FF',
- '#0066CC',
- '#0066FF',
- '#0099CC',
- '#0099FF',
- '#00CC00',
- '#00CC33',
- '#00CC66',
- '#00CC99',
- '#00CCCC',
- '#00CCFF',
- '#3300CC',
- '#3300FF',
- '#3333CC',
- '#3333FF',
- '#3366CC',
- '#3366FF',
- '#3399CC',
- '#3399FF',
- '#33CC00',
- '#33CC33',
- '#33CC66',
- '#33CC99',
- '#33CCCC',
- '#33CCFF',
- '#6600CC',
- '#6600FF',
- '#6633CC',
- '#6633FF',
- '#66CC00',
- '#66CC33',
- '#9900CC',
- '#9900FF',
- '#9933CC',
- '#9933FF',
- '#99CC00',
- '#99CC33',
- '#CC0000',
- '#CC0033',
- '#CC0066',
- '#CC0099',
- '#CC00CC',
- '#CC00FF',
- '#CC3300',
- '#CC3333',
- '#CC3366',
- '#CC3399',
- '#CC33CC',
- '#CC33FF',
- '#CC6600',
- '#CC6633',
- '#CC9900',
- '#CC9933',
- '#CCCC00',
- '#CCCC33',
- '#FF0000',
- '#FF0033',
- '#FF0066',
- '#FF0099',
- '#FF00CC',
- '#FF00FF',
- '#FF3300',
- '#FF3333',
- '#FF3366',
- '#FF3399',
- '#FF33CC',
- '#FF33FF',
- '#FF6600',
- '#FF6633',
- '#FF9900',
- '#FF9933',
- '#FFCC00',
- '#FFCC33'
- ];
- /**
- * Currently only WebKit-based Web Inspectors, Firefox >= v31,
- * and the Firebug extension (any Firefox version) are known
- * to support "%c" CSS customizations.
- *
- * TODO: add a `localStorage` variable to explicitly enable/disable colors
- */
- // eslint-disable-next-line complexity
- function useColors() {
- // NB: In an Electron preload script, document will be defined but not fully
- // initialized. Since we know we're in Chrome, we'll just detect this case
- // explicitly
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
- return true;
- }
- // Internet Explorer and Edge do not support colors.
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
- return false;
- }
- // Is webkit? http://stackoverflow.com/a/16459606/376773
- // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
- return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
- // Is firebug? http://stackoverflow.com/a/398120/376773
- (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
- // Is firefox >= v31?
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
- // Double check webkit in userAgent just in case we are in a worker
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
- }
- /**
- * Colorize log arguments if enabled.
- *
- * @api public
- */
- function formatArgs(args) {
- args[0] = (this.useColors ? '%c' : '') +
- this.namespace +
- (this.useColors ? ' %c' : ' ') +
- args[0] +
- (this.useColors ? '%c ' : ' ') +
- '+' + module.exports.humanize(this.diff);
- if (!this.useColors) {
- return;
- }
- const c = 'color: ' + this.color;
- args.splice(1, 0, c, 'color: inherit');
- // The final "%c" is somewhat tricky, because there could be other
- // arguments passed either before or after the %c, so we need to
- // figure out the correct index to insert the CSS into
- let index = 0;
- let lastC = 0;
- args[0].replace(/%[a-zA-Z%]/g, match => {
- if (match === '%%') {
- return;
- }
- index++;
- if (match === '%c') {
- // We only are interested in the *last* %c
- // (the user may have provided their own)
- lastC = index;
- }
- });
- args.splice(lastC, 0, c);
- }
- /**
- * Invokes `console.debug()` when available.
- * No-op when `console.debug` is not a "function".
- * If `console.debug` is not available, falls back
- * to `console.log`.
- *
- * @api public
- */
- exports.log = console.debug || console.log || (() => {});
- /**
- * Save `namespaces`.
- *
- * @param {String} namespaces
- * @api private
- */
- function save(namespaces) {
- try {
- if (namespaces) {
- exports.storage.setItem('debug', namespaces);
- } else {
- exports.storage.removeItem('debug');
- }
- } catch (error) {
- // Swallow
- // XXX (@Qix-) should we be logging these?
- }
- }
- /**
- * Load `namespaces`.
- *
- * @return {String} returns the previously persisted debug modes
- * @api private
- */
- function load() {
- let r;
- try {
- r = exports.storage.getItem('debug');
- } catch (error) {
- // Swallow
- // XXX (@Qix-) should we be logging these?
- }
- // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
- if (!r && typeof process !== 'undefined' && 'env' in process) {
- r = process.env.DEBUG;
- }
- return r;
- }
- /**
- * Localstorage attempts to return the localstorage.
- *
- * This is necessary because safari throws
- * when a user disables cookies/localstorage
- * and you attempt to access it.
- *
- * @return {LocalStorage}
- * @api private
- */
- function localstorage() {
- try {
- // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
- // The Browser also has localStorage in the global context.
- return localStorage;
- } catch (error) {
- // Swallow
- // XXX (@Qix-) should we be logging these?
- }
- }
- module.exports = __webpack_require__(/*! ./common */ "../ot-core/node_modules/debug/src/common.js")(exports);
- const {formatters} = module.exports;
- /**
- * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
- */
- formatters.j = function (v) {
- try {
- return JSON.stringify(v);
- } catch (error) {
- return '[UnexpectedJSONParseError]: ' + error.message;
- }
- };
- /***/ }),
- /***/ "../ot-core/node_modules/debug/src/common.js":
- /*!***************************************************!*\
- !*** ../ot-core/node_modules/debug/src/common.js ***!
- \***************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- /**
- * This is the common logic for both the Node.js and web browser
- * implementations of `debug()`.
- */
- function setup(env) {
- createDebug.debug = createDebug;
- createDebug.default = createDebug;
- createDebug.coerce = coerce;
- createDebug.disable = disable;
- createDebug.enable = enable;
- createDebug.enabled = enabled;
- createDebug.humanize = __webpack_require__(/*! ms */ "../ot-core/node_modules/ms/index.js");
- createDebug.destroy = destroy;
- Object.keys(env).forEach(key => {
- createDebug[key] = env[key];
- });
- /**
- * The currently active debug mode names, and names to skip.
- */
- createDebug.names = [];
- createDebug.skips = [];
- /**
- * Map of special "%n" handling functions, for the debug "format" argument.
- *
- * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
- */
- createDebug.formatters = {};
- /**
- * Selects a color for a debug namespace
- * @param {String} namespace The namespace string for the debug instance to be colored
- * @return {Number|String} An ANSI color code for the given namespace
- * @api private
- */
- function selectColor(namespace) {
- let hash = 0;
- for (let i = 0; i < namespace.length; i++) {
- hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
- hash |= 0; // Convert to 32bit integer
- }
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
- }
- createDebug.selectColor = selectColor;
- /**
- * Create a debugger with the given `namespace`.
- *
- * @param {String} namespace
- * @return {Function}
- * @api public
- */
- function createDebug(namespace) {
- let prevTime;
- let enableOverride = null;
- let namespacesCache;
- let enabledCache;
- function debug(...args) {
- // Disabled?
- if (!debug.enabled) {
- return;
- }
- const self = debug;
- // Set `diff` timestamp
- const curr = Number(new Date());
- const ms = curr - (prevTime || curr);
- self.diff = ms;
- self.prev = prevTime;
- self.curr = curr;
- prevTime = curr;
- args[0] = createDebug.coerce(args[0]);
- if (typeof args[0] !== 'string') {
- // Anything else let's inspect with %O
- args.unshift('%O');
- }
- // Apply any `formatters` transformations
- let index = 0;
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
- // If we encounter an escaped % then don't increase the array index
- if (match === '%%') {
- return '%';
- }
- index++;
- const formatter = createDebug.formatters[format];
- if (typeof formatter === 'function') {
- const val = args[index];
- match = formatter.call(self, val);
- // Now we need to remove `args[index]` since it's inlined in the `format`
- args.splice(index, 1);
- index--;
- }
- return match;
- });
- // Apply env-specific formatting (colors, etc.)
- createDebug.formatArgs.call(self, args);
- const logFn = self.log || createDebug.log;
- logFn.apply(self, args);
- }
- debug.namespace = namespace;
- debug.useColors = createDebug.useColors();
- debug.color = createDebug.selectColor(namespace);
- debug.extend = extend;
- debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
- Object.defineProperty(debug, 'enabled', {
- enumerable: true,
- configurable: false,
- get: () => {
- if (enableOverride !== null) {
- return enableOverride;
- }
- if (namespacesCache !== createDebug.namespaces) {
- namespacesCache = createDebug.namespaces;
- enabledCache = createDebug.enabled(namespace);
- }
- return enabledCache;
- },
- set: v => {
- enableOverride = v;
- }
- });
- // Env-specific initialization logic for debug instances
- if (typeof createDebug.init === 'function') {
- createDebug.init(debug);
- }
- return debug;
- }
- function extend(namespace, delimiter) {
- const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
- newDebug.log = this.log;
- return newDebug;
- }
- /**
- * Enables a debug mode by namespaces. This can include modes
- * separated by a colon and wildcards.
- *
- * @param {String} namespaces
- * @api public
- */
- function enable(namespaces) {
- createDebug.save(namespaces);
- createDebug.namespaces = namespaces;
- createDebug.names = [];
- createDebug.skips = [];
- let i;
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
- const len = split.length;
- for (i = 0; i < len; i++) {
- if (!split[i]) {
- // ignore empty strings
- continue;
- }
- namespaces = split[i].replace(/\*/g, '.*?');
- if (namespaces[0] === '-') {
- createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
- } else {
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
- }
- }
- }
- /**
- * Disable debug output.
- *
- * @return {String} namespaces
- * @api public
- */
- function disable() {
- const namespaces = [
- ...createDebug.names.map(toNamespace),
- ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
- ].join(',');
- createDebug.enable('');
- return namespaces;
- }
- /**
- * Returns true if the given mode name is enabled, false otherwise.
- *
- * @param {String} name
- * @return {Boolean}
- * @api public
- */
- function enabled(name) {
- if (name[name.length - 1] === '*') {
- return true;
- }
- let i;
- let len;
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
- if (createDebug.skips[i].test(name)) {
- return false;
- }
- }
- for (i = 0, len = createDebug.names.length; i < len; i++) {
- if (createDebug.names[i].test(name)) {
- return true;
- }
- }
- return false;
- }
- /**
- * Convert regexp to namespace
- *
- * @param {RegExp} regxep
- * @return {String} namespace
- * @api private
- */
- function toNamespace(regexp) {
- return regexp.toString()
- .substring(2, regexp.toString().length - 2)
- .replace(/\.\*\?$/, '*');
- }
- /**
- * Coerce `val`.
- *
- * @param {Mixed} val
- * @return {Mixed}
- * @api private
- */
- function coerce(val) {
- if (val instanceof Error) {
- return val.stack || val.message;
- }
- return val;
- }
- /**
- * XXX DO NOT USE. This is a temporary stub function.
- * XXX It WILL be removed in the next major release.
- */
- function destroy() {
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
- }
- createDebug.enable(createDebug.load());
- return createDebug;
- }
- module.exports = setup;
- /***/ }),
- /***/ "../ot-core/node_modules/debug/src/index.js":
- /*!**************************************************!*\
- !*** ../ot-core/node_modules/debug/src/index.js ***!
- \**************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- /**
- * Detect Electron renderer / nwjs process, which is node, but we should
- * treat as a browser.
- */
- if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
- module.exports = __webpack_require__(/*! ./browser.js */ "../ot-core/node_modules/debug/src/browser.js");
- } else {
- module.exports = __webpack_require__(/*! ./node.js */ "../ot-core/node_modules/debug/src/node.js");
- }
- /***/ }),
- /***/ "../ot-core/node_modules/debug/src/node.js":
- /*!*************************************************!*\
- !*** ../ot-core/node_modules/debug/src/node.js ***!
- \*************************************************/
- /***/ ((module, exports, __webpack_require__) => {
- /**
- * Module dependencies.
- */
- const tty = __webpack_require__(/*! tty */ "tty");
- const util = __webpack_require__(/*! util */ "util");
- /**
- * This is the Node.js implementation of `debug()`.
- */
- exports.init = init;
- exports.log = log;
- exports.formatArgs = formatArgs;
- exports.save = save;
- exports.load = load;
- exports.useColors = useColors;
- exports.destroy = util.deprecate(
- () => {},
- 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
- );
- /**
- * Colors.
- */
- exports.colors = [6, 2, 3, 4, 5, 1];
- try {
- // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
- // eslint-disable-next-line import/no-extraneous-dependencies
- const supportsColor = __webpack_require__(/*! supports-color */ "../ot-core/node_modules/supports-color/index.js");
- if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
- exports.colors = [
- 20,
- 21,
- 26,
- 27,
- 32,
- 33,
- 38,
- 39,
- 40,
- 41,
- 42,
- 43,
- 44,
- 45,
- 56,
- 57,
- 62,
- 63,
- 68,
- 69,
- 74,
- 75,
- 76,
- 77,
- 78,
- 79,
- 80,
- 81,
- 92,
- 93,
- 98,
- 99,
- 112,
- 113,
- 128,
- 129,
- 134,
- 135,
- 148,
- 149,
- 160,
- 161,
- 162,
- 163,
- 164,
- 165,
- 166,
- 167,
- 168,
- 169,
- 170,
- 171,
- 172,
- 173,
- 178,
- 179,
- 184,
- 185,
- 196,
- 197,
- 198,
- 199,
- 200,
- 201,
- 202,
- 203,
- 204,
- 205,
- 206,
- 207,
- 208,
- 209,
- 214,
- 215,
- 220,
- 221
- ];
- }
- } catch (error) {
- // Swallow - we only care if `supports-color` is available; it doesn't have to be.
- }
- /**
- * Build up the default `inspectOpts` object from the environment variables.
- *
- * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
- */
- exports.inspectOpts = Object.keys(process.env).filter(key => {
- return /^debug_/i.test(key);
- }).reduce((obj, key) => {
- // Camel-case
- const prop = key
- .substring(6)
- .toLowerCase()
- .replace(/_([a-z])/g, (_, k) => {
- return k.toUpperCase();
- });
- // Coerce string value into JS value
- let val = process.env[key];
- if (/^(yes|on|true|enabled)$/i.test(val)) {
- val = true;
- } else if (/^(no|off|false|disabled)$/i.test(val)) {
- val = false;
- } else if (val === 'null') {
- val = null;
- } else {
- val = Number(val);
- }
- obj[prop] = val;
- return obj;
- }, {});
- /**
- * Is stdout a TTY? Colored output is enabled when `true`.
- */
- function useColors() {
- return 'colors' in exports.inspectOpts ?
- Boolean(exports.inspectOpts.colors) :
- tty.isatty(process.stderr.fd);
- }
- /**
- * Adds ANSI color escape codes if enabled.
- *
- * @api public
- */
- function formatArgs(args) {
- const {namespace: name, useColors} = this;
- if (useColors) {
- const c = this.color;
- const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
- const prefix = ` ${colorCode};1m${name} \u001B[0m`;
- args[0] = prefix + args[0].split('\n').join('\n' + prefix);
- args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
- } else {
- args[0] = getDate() + name + ' ' + args[0];
- }
- }
- function getDate() {
- if (exports.inspectOpts.hideDate) {
- return '';
- }
- return new Date().toISOString() + ' ';
- }
- /**
- * Invokes `util.format()` with the specified arguments and writes to stderr.
- */
- function log(...args) {
- return process.stderr.write(util.format(...args) + '\n');
- }
- /**
- * Save `namespaces`.
- *
- * @param {String} namespaces
- * @api private
- */
- function save(namespaces) {
- if (namespaces) {
- process.env.DEBUG = namespaces;
- } else {
- // If you set a process.env field to null or undefined, it gets cast to the
- // string 'null' or 'undefined'. Just delete instead.
- delete process.env.DEBUG;
- }
- }
- /**
- * Load `namespaces`.
- *
- * @return {String} returns the previously persisted debug modes
- * @api private
- */
- function load() {
- return process.env.DEBUG;
- }
- /**
- * Init logic for `debug` instances.
- *
- * Create a new `inspectOpts` object in case `useColors` is set
- * differently for a particular `debug` instance.
- */
- function init(debug) {
- debug.inspectOpts = {};
- const keys = Object.keys(exports.inspectOpts);
- for (let i = 0; i < keys.length; i++) {
- debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
- }
- }
- module.exports = __webpack_require__(/*! ./common */ "../ot-core/node_modules/debug/src/common.js")(exports);
- const {formatters} = module.exports;
- /**
- * Map %o to `util.inspect()`, all on a single line.
- */
- formatters.o = function (v) {
- this.inspectOpts.colors = this.useColors;
- return util.inspect(v, this.inspectOpts)
- .split('\n')
- .map(str => str.trim())
- .join(' ');
- };
- /**
- * Map %O to `util.inspect()`, allowing multiple lines if needed.
- */
- formatters.O = function (v) {
- this.inspectOpts.colors = this.useColors;
- return util.inspect(v, this.inspectOpts);
- };
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/index.js":
- /*!*************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/index.js ***!
- \*************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const WebSocket = __webpack_require__(/*! ./lib/websocket */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js");
- WebSocket.createWebSocketStream = __webpack_require__(/*! ./lib/stream */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/stream.js");
- WebSocket.Server = __webpack_require__(/*! ./lib/websocket-server */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js");
- WebSocket.Receiver = __webpack_require__(/*! ./lib/receiver */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js");
- WebSocket.Sender = __webpack_require__(/*! ./lib/sender */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js");
- WebSocket.WebSocket = WebSocket;
- WebSocket.WebSocketServer = WebSocket.Server;
- module.exports = WebSocket;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js":
- /*!***********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js ***!
- \***********************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const { EMPTY_BUFFER } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
- /**
- * Merges an array of buffers into a new buffer.
- *
- * @param {Buffer[]} list The array of buffers to concat
- * @param {Number} totalLength The total length of buffers in the list
- * @return {Buffer} The resulting buffer
- * @public
- */
- function concat(list, totalLength) {
- if (list.length === 0) return EMPTY_BUFFER;
- if (list.length === 1) return list[0];
- const target = Buffer.allocUnsafe(totalLength);
- let offset = 0;
- for (let i = 0; i < list.length; i++) {
- const buf = list[i];
- target.set(buf, offset);
- offset += buf.length;
- }
- if (offset < totalLength) return target.slice(0, offset);
- return target;
- }
- /**
- * Masks a buffer using the given mask.
- *
- * @param {Buffer} source The buffer to mask
- * @param {Buffer} mask The mask to use
- * @param {Buffer} output The buffer where to store the result
- * @param {Number} offset The offset at which to start writing
- * @param {Number} length The number of bytes to mask.
- * @public
- */
- function _mask(source, mask, output, offset, length) {
- for (let i = 0; i < length; i++) {
- output[offset + i] = source[i] ^ mask[i & 3];
- }
- }
- /**
- * Unmasks a buffer using the given mask.
- *
- * @param {Buffer} buffer The buffer to unmask
- * @param {Buffer} mask The mask to use
- * @public
- */
- function _unmask(buffer, mask) {
- for (let i = 0; i < buffer.length; i++) {
- buffer[i] ^= mask[i & 3];
- }
- }
- /**
- * Converts a buffer to an `ArrayBuffer`.
- *
- * @param {Buffer} buf The buffer to convert
- * @return {ArrayBuffer} Converted buffer
- * @public
- */
- function toArrayBuffer(buf) {
- if (buf.byteLength === buf.buffer.byteLength) {
- return buf.buffer;
- }
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
- }
- /**
- * Converts `data` to a `Buffer`.
- *
- * @param {*} data The data to convert
- * @return {Buffer} The buffer
- * @throws {TypeError}
- * @public
- */
- function toBuffer(data) {
- toBuffer.readOnly = true;
- if (Buffer.isBuffer(data)) return data;
- let buf;
- if (data instanceof ArrayBuffer) {
- buf = Buffer.from(data);
- } else if (ArrayBuffer.isView(data)) {
- buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
- } else {
- buf = Buffer.from(data);
- toBuffer.readOnly = false;
- }
- return buf;
- }
- try {
- const bufferUtil = __webpack_require__(/*! bufferutil */ "bufferutil");
- module.exports = {
- concat,
- mask(source, mask, output, offset, length) {
- if (length < 48) _mask(source, mask, output, offset, length);
- else bufferUtil.mask(source, mask, output, offset, length);
- },
- toArrayBuffer,
- toBuffer,
- unmask(buffer, mask) {
- if (buffer.length < 32) _unmask(buffer, mask);
- else bufferUtil.unmask(buffer, mask);
- }
- };
- } catch (e) /* istanbul ignore next */ {
- module.exports = {
- concat,
- mask: _mask,
- toArrayBuffer,
- toBuffer,
- unmask: _unmask
- };
- }
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js":
- /*!*********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js ***!
- \*********************************************************************************/
- /***/ ((module) => {
- "use strict";
- module.exports = {
- BINARY_TYPES: ['nodebuffer', 'arraybuffer', 'fragments'],
- EMPTY_BUFFER: Buffer.alloc(0),
- GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
- kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
- kListener: Symbol('kListener'),
- kStatusCode: Symbol('status-code'),
- kWebSocket: Symbol('websocket'),
- NOOP: () => {}
- };
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/event-target.js":
- /*!************************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/event-target.js ***!
- \************************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const { kForOnEventAttribute, kListener } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
- const kCode = Symbol('kCode');
- const kData = Symbol('kData');
- const kError = Symbol('kError');
- const kMessage = Symbol('kMessage');
- const kReason = Symbol('kReason');
- const kTarget = Symbol('kTarget');
- const kType = Symbol('kType');
- const kWasClean = Symbol('kWasClean');
- /**
- * Class representing an event.
- */
- class Event {
- /**
- * Create a new `Event`.
- *
- * @param {String} type The name of the event
- * @throws {TypeError} If the `type` argument is not specified
- */
- constructor(type) {
- this[kTarget] = null;
- this[kType] = type;
- }
- /**
- * @type {*}
- */
- get target() {
- return this[kTarget];
- }
- /**
- * @type {String}
- */
- get type() {
- return this[kType];
- }
- }
- Object.defineProperty(Event.prototype, 'target', { enumerable: true });
- Object.defineProperty(Event.prototype, 'type', { enumerable: true });
- /**
- * Class representing a close event.
- *
- * @extends Event
- */
- class CloseEvent extends Event {
- /**
- * Create a new `CloseEvent`.
- *
- * @param {String} type The name of the event
- * @param {Object} [options] A dictionary object that allows for setting
- * attributes via object members of the same name
- * @param {Number} [options.code=0] The status code explaining why the
- * connection was closed
- * @param {String} [options.reason=''] A human-readable string explaining why
- * the connection was closed
- * @param {Boolean} [options.wasClean=false] Indicates whether or not the
- * connection was cleanly closed
- */
- constructor(type, options = {}) {
- super(type);
- this[kCode] = options.code === undefined ? 0 : options.code;
- this[kReason] = options.reason === undefined ? '' : options.reason;
- this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
- }
- /**
- * @type {Number}
- */
- get code() {
- return this[kCode];
- }
- /**
- * @type {String}
- */
- get reason() {
- return this[kReason];
- }
- /**
- * @type {Boolean}
- */
- get wasClean() {
- return this[kWasClean];
- }
- }
- Object.defineProperty(CloseEvent.prototype, 'code', { enumerable: true });
- Object.defineProperty(CloseEvent.prototype, 'reason', { enumerable: true });
- Object.defineProperty(CloseEvent.prototype, 'wasClean', { enumerable: true });
- /**
- * Class representing an error event.
- *
- * @extends Event
- */
- class ErrorEvent extends Event {
- /**
- * Create a new `ErrorEvent`.
- *
- * @param {String} type The name of the event
- * @param {Object} [options] A dictionary object that allows for setting
- * attributes via object members of the same name
- * @param {*} [options.error=null] The error that generated this event
- * @param {String} [options.message=''] The error message
- */
- constructor(type, options = {}) {
- super(type);
- this[kError] = options.error === undefined ? null : options.error;
- this[kMessage] = options.message === undefined ? '' : options.message;
- }
- /**
- * @type {*}
- */
- get error() {
- return this[kError];
- }
- /**
- * @type {String}
- */
- get message() {
- return this[kMessage];
- }
- }
- Object.defineProperty(ErrorEvent.prototype, 'error', { enumerable: true });
- Object.defineProperty(ErrorEvent.prototype, 'message', { enumerable: true });
- /**
- * Class representing a message event.
- *
- * @extends Event
- */
- class MessageEvent extends Event {
- /**
- * Create a new `MessageEvent`.
- *
- * @param {String} type The name of the event
- * @param {Object} [options] A dictionary object that allows for setting
- * attributes via object members of the same name
- * @param {*} [options.data=null] The message content
- */
- constructor(type, options = {}) {
- super(type);
- this[kData] = options.data === undefined ? null : options.data;
- }
- /**
- * @type {*}
- */
- get data() {
- return this[kData];
- }
- }
- Object.defineProperty(MessageEvent.prototype, 'data', { enumerable: true });
- /**
- * This provides methods for emulating the `EventTarget` interface. It's not
- * meant to be used directly.
- *
- * @mixin
- */
- const EventTarget = {
- /**
- * Register an event listener.
- *
- * @param {String} type A string representing the event type to listen for
- * @param {Function} listener The listener to add
- * @param {Object} [options] An options object specifies characteristics about
- * the event listener
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
- * listener should be invoked at most once after being added. If `true`,
- * the listener would be automatically removed when invoked.
- * @public
- */
- addEventListener(type, listener, options = {}) {
- let wrapper;
- if (type === 'message') {
- wrapper = function onMessage(data, isBinary) {
- const event = new MessageEvent('message', {
- data: isBinary ? data : data.toString()
- });
- event[kTarget] = this;
- listener.call(this, event);
- };
- } else if (type === 'close') {
- wrapper = function onClose(code, message) {
- const event = new CloseEvent('close', {
- code,
- reason: message.toString(),
- wasClean: this._closeFrameReceived && this._closeFrameSent
- });
- event[kTarget] = this;
- listener.call(this, event);
- };
- } else if (type === 'error') {
- wrapper = function onError(error) {
- const event = new ErrorEvent('error', {
- error,
- message: error.message
- });
- event[kTarget] = this;
- listener.call(this, event);
- };
- } else if (type === 'open') {
- wrapper = function onOpen() {
- const event = new Event('open');
- event[kTarget] = this;
- listener.call(this, event);
- };
- } else {
- return;
- }
- wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
- wrapper[kListener] = listener;
- if (options.once) {
- this.once(type, wrapper);
- } else {
- this.on(type, wrapper);
- }
- },
- /**
- * Remove an event listener.
- *
- * @param {String} type A string representing the event type to remove
- * @param {Function} handler The listener to remove
- * @public
- */
- removeEventListener(type, handler) {
- for (const listener of this.listeners(type)) {
- if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
- this.removeListener(type, listener);
- break;
- }
- }
- }
- };
- module.exports = {
- CloseEvent,
- ErrorEvent,
- Event,
- EventTarget,
- MessageEvent
- };
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js":
- /*!*********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js ***!
- \*********************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const { tokenChars } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
- /**
- * Adds an offer to the map of extension offers or a parameter to the map of
- * parameters.
- *
- * @param {Object} dest The map of extension offers or parameters
- * @param {String} name The extension or parameter name
- * @param {(Object|Boolean|String)} elem The extension parameters or the
- * parameter value
- * @private
- */
- function push(dest, name, elem) {
- if (dest[name] === undefined) dest[name] = [elem];
- else dest[name].push(elem);
- }
- /**
- * Parses the `Sec-WebSocket-Extensions` header into an object.
- *
- * @param {String} header The field value of the header
- * @return {Object} The parsed object
- * @public
- */
- function parse(header) {
- const offers = Object.create(null);
- let params = Object.create(null);
- let mustUnescape = false;
- let isEscaping = false;
- let inQuotes = false;
- let extensionName;
- let paramName;
- let start = -1;
- let code = -1;
- let end = -1;
- let i = 0;
- for (; i < header.length; i++) {
- code = header.charCodeAt(i);
- if (extensionName === undefined) {
- if (end === -1 && tokenChars[code] === 1) {
- if (start === -1) start = i;
- } else if (
- i !== 0 &&
- (code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
- ) {
- if (end === -1 && start !== -1) end = i;
- } else if (code === 0x3b /* ';' */ || code === 0x2c /* ',' */) {
- if (start === -1) {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- if (end === -1) end = i;
- const name = header.slice(start, end);
- if (code === 0x2c) {
- push(offers, name, params);
- params = Object.create(null);
- } else {
- extensionName = name;
- }
- start = end = -1;
- } else {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- } else if (paramName === undefined) {
- if (end === -1 && tokenChars[code] === 1) {
- if (start === -1) start = i;
- } else if (code === 0x20 || code === 0x09) {
- if (end === -1 && start !== -1) end = i;
- } else if (code === 0x3b || code === 0x2c) {
- if (start === -1) {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- if (end === -1) end = i;
- push(params, header.slice(start, end), true);
- if (code === 0x2c) {
- push(offers, extensionName, params);
- params = Object.create(null);
- extensionName = undefined;
- }
- start = end = -1;
- } else if (code === 0x3d /* '=' */ && start !== -1 && end === -1) {
- paramName = header.slice(start, i);
- start = end = -1;
- } else {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- } else {
- //
- // The value of a quoted-string after unescaping must conform to the
- // token ABNF, so only token characters are valid.
- // Ref: https://tools.ietf.org/html/rfc6455#section-9.1
- //
- if (isEscaping) {
- if (tokenChars[code] !== 1) {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- if (start === -1) start = i;
- else if (!mustUnescape) mustUnescape = true;
- isEscaping = false;
- } else if (inQuotes) {
- if (tokenChars[code] === 1) {
- if (start === -1) start = i;
- } else if (code === 0x22 /* '"' */ && start !== -1) {
- inQuotes = false;
- end = i;
- } else if (code === 0x5c /* '\' */) {
- isEscaping = true;
- } else {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- } else if (code === 0x22 && header.charCodeAt(i - 1) === 0x3d) {
- inQuotes = true;
- } else if (end === -1 && tokenChars[code] === 1) {
- if (start === -1) start = i;
- } else if (start !== -1 && (code === 0x20 || code === 0x09)) {
- if (end === -1) end = i;
- } else if (code === 0x3b || code === 0x2c) {
- if (start === -1) {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- if (end === -1) end = i;
- let value = header.slice(start, end);
- if (mustUnescape) {
- value = value.replace(/\\/g, '');
- mustUnescape = false;
- }
- push(params, paramName, value);
- if (code === 0x2c) {
- push(offers, extensionName, params);
- params = Object.create(null);
- extensionName = undefined;
- }
- paramName = undefined;
- start = end = -1;
- } else {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- }
- }
- if (start === -1 || inQuotes || code === 0x20 || code === 0x09) {
- throw new SyntaxError('Unexpected end of input');
- }
- if (end === -1) end = i;
- const token = header.slice(start, end);
- if (extensionName === undefined) {
- push(offers, token, params);
- } else {
- if (paramName === undefined) {
- push(params, token, true);
- } else if (mustUnescape) {
- push(params, paramName, token.replace(/\\/g, ''));
- } else {
- push(params, paramName, token);
- }
- push(offers, extensionName, params);
- }
- return offers;
- }
- /**
- * Builds the `Sec-WebSocket-Extensions` header field value.
- *
- * @param {Object} extensions The map of extensions and parameters to format
- * @return {String} A string representing the given object
- * @public
- */
- function format(extensions) {
- return Object.keys(extensions)
- .map((extension) => {
- let configurations = extensions[extension];
- if (!Array.isArray(configurations)) configurations = [configurations];
- return configurations
- .map((params) => {
- return [extension]
- .concat(
- Object.keys(params).map((k) => {
- let values = params[k];
- if (!Array.isArray(values)) values = [values];
- return values
- .map((v) => (v === true ? k : `${k}=${v}`))
- .join('; ');
- })
- )
- .join('; ');
- })
- .join(', ');
- })
- .join(', ');
- }
- module.exports = { format, parse };
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/limiter.js":
- /*!*******************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/limiter.js ***!
- \*******************************************************************************/
- /***/ ((module) => {
- "use strict";
- const kDone = Symbol('kDone');
- const kRun = Symbol('kRun');
- /**
- * A very simple job queue with adjustable concurrency. Adapted from
- * https://github.com/STRML/async-limiter
- */
- class Limiter {
- /**
- * Creates a new `Limiter`.
- *
- * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
- * to run concurrently
- */
- constructor(concurrency) {
- this[kDone] = () => {
- this.pending--;
- this[kRun]();
- };
- this.concurrency = concurrency || Infinity;
- this.jobs = [];
- this.pending = 0;
- }
- /**
- * Adds a job to the queue.
- *
- * @param {Function} job The job to run
- * @public
- */
- add(job) {
- this.jobs.push(job);
- this[kRun]();
- }
- /**
- * Removes a job from the queue and runs it if possible.
- *
- * @private
- */
- [kRun]() {
- if (this.pending === this.concurrency) return;
- if (this.jobs.length) {
- const job = this.jobs.shift();
- this.pending++;
- job(this[kDone]);
- }
- }
- }
- module.exports = Limiter;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js":
- /*!******************************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js ***!
- \******************************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const zlib = __webpack_require__(/*! zlib */ "zlib");
- const bufferUtil = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
- const Limiter = __webpack_require__(/*! ./limiter */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/limiter.js");
- const { kStatusCode } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
- const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
- const kPerMessageDeflate = Symbol('permessage-deflate');
- const kTotalLength = Symbol('total-length');
- const kCallback = Symbol('callback');
- const kBuffers = Symbol('buffers');
- const kError = Symbol('error');
- //
- // We limit zlib concurrency, which prevents severe memory fragmentation
- // as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
- // and https://github.com/websockets/ws/issues/1202
- //
- // Intentionally global; it's the global thread pool that's an issue.
- //
- let zlibLimiter;
- /**
- * permessage-deflate implementation.
- */
- class PerMessageDeflate {
- /**
- * Creates a PerMessageDeflate instance.
- *
- * @param {Object} [options] Configuration options
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
- * for, or request, a custom client window size
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
- * acknowledge disabling of client context takeover
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
- * calls to zlib
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
- * use of a custom server window size
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
- * disabling of server context takeover
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
- * messages should not be compressed if context takeover is disabled
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
- * deflate
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
- * inflate
- * @param {Boolean} [isServer=false] Create the instance in either server or
- * client mode
- * @param {Number} [maxPayload=0] The maximum allowed message length
- */
- constructor(options, isServer, maxPayload) {
- this._maxPayload = maxPayload | 0;
- this._options = options || {};
- this._threshold =
- this._options.threshold !== undefined ? this._options.threshold : 1024;
- this._isServer = !!isServer;
- this._deflate = null;
- this._inflate = null;
- this.params = null;
- if (!zlibLimiter) {
- const concurrency =
- this._options.concurrencyLimit !== undefined
- ? this._options.concurrencyLimit
- : 10;
- zlibLimiter = new Limiter(concurrency);
- }
- }
- /**
- * @type {String}
- */
- static get extensionName() {
- return 'permessage-deflate';
- }
- /**
- * Create an extension negotiation offer.
- *
- * @return {Object} Extension parameters
- * @public
- */
- offer() {
- const params = {};
- if (this._options.serverNoContextTakeover) {
- params.server_no_context_takeover = true;
- }
- if (this._options.clientNoContextTakeover) {
- params.client_no_context_takeover = true;
- }
- if (this._options.serverMaxWindowBits) {
- params.server_max_window_bits = this._options.serverMaxWindowBits;
- }
- if (this._options.clientMaxWindowBits) {
- params.client_max_window_bits = this._options.clientMaxWindowBits;
- } else if (this._options.clientMaxWindowBits == null) {
- params.client_max_window_bits = true;
- }
- return params;
- }
- /**
- * Accept an extension negotiation offer/response.
- *
- * @param {Array} configurations The extension negotiation offers/reponse
- * @return {Object} Accepted configuration
- * @public
- */
- accept(configurations) {
- configurations = this.normalizeParams(configurations);
- this.params = this._isServer
- ? this.acceptAsServer(configurations)
- : this.acceptAsClient(configurations);
- return this.params;
- }
- /**
- * Releases all resources used by the extension.
- *
- * @public
- */
- cleanup() {
- if (this._inflate) {
- this._inflate.close();
- this._inflate = null;
- }
- if (this._deflate) {
- const callback = this._deflate[kCallback];
- this._deflate.close();
- this._deflate = null;
- if (callback) {
- callback(
- new Error(
- 'The deflate stream was closed while data was being processed'
- )
- );
- }
- }
- }
- /**
- * Accept an extension negotiation offer.
- *
- * @param {Array} offers The extension negotiation offers
- * @return {Object} Accepted configuration
- * @private
- */
- acceptAsServer(offers) {
- const opts = this._options;
- const accepted = offers.find((params) => {
- if (
- (opts.serverNoContextTakeover === false &&
- params.server_no_context_takeover) ||
- (params.server_max_window_bits &&
- (opts.serverMaxWindowBits === false ||
- (typeof opts.serverMaxWindowBits === 'number' &&
- opts.serverMaxWindowBits > params.server_max_window_bits))) ||
- (typeof opts.clientMaxWindowBits === 'number' &&
- !params.client_max_window_bits)
- ) {
- return false;
- }
- return true;
- });
- if (!accepted) {
- throw new Error('None of the extension offers can be accepted');
- }
- if (opts.serverNoContextTakeover) {
- accepted.server_no_context_takeover = true;
- }
- if (opts.clientNoContextTakeover) {
- accepted.client_no_context_takeover = true;
- }
- if (typeof opts.serverMaxWindowBits === 'number') {
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
- }
- if (typeof opts.clientMaxWindowBits === 'number') {
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
- } else if (
- accepted.client_max_window_bits === true ||
- opts.clientMaxWindowBits === false
- ) {
- delete accepted.client_max_window_bits;
- }
- return accepted;
- }
- /**
- * Accept the extension negotiation response.
- *
- * @param {Array} response The extension negotiation response
- * @return {Object} Accepted configuration
- * @private
- */
- acceptAsClient(response) {
- const params = response[0];
- if (
- this._options.clientNoContextTakeover === false &&
- params.client_no_context_takeover
- ) {
- throw new Error('Unexpected parameter "client_no_context_takeover"');
- }
- if (!params.client_max_window_bits) {
- if (typeof this._options.clientMaxWindowBits === 'number') {
- params.client_max_window_bits = this._options.clientMaxWindowBits;
- }
- } else if (
- this._options.clientMaxWindowBits === false ||
- (typeof this._options.clientMaxWindowBits === 'number' &&
- params.client_max_window_bits > this._options.clientMaxWindowBits)
- ) {
- throw new Error(
- 'Unexpected or invalid parameter "client_max_window_bits"'
- );
- }
- return params;
- }
- /**
- * Normalize parameters.
- *
- * @param {Array} configurations The extension negotiation offers/reponse
- * @return {Array} The offers/response with normalized parameters
- * @private
- */
- normalizeParams(configurations) {
- configurations.forEach((params) => {
- Object.keys(params).forEach((key) => {
- let value = params[key];
- if (value.length > 1) {
- throw new Error(`Parameter "${key}" must have only a single value`);
- }
- value = value[0];
- if (key === 'client_max_window_bits') {
- if (value !== true) {
- const num = +value;
- if (!Number.isInteger(num) || num < 8 || num > 15) {
- throw new TypeError(
- `Invalid value for parameter "${key}": ${value}`
- );
- }
- value = num;
- } else if (!this._isServer) {
- throw new TypeError(
- `Invalid value for parameter "${key}": ${value}`
- );
- }
- } else if (key === 'server_max_window_bits') {
- const num = +value;
- if (!Number.isInteger(num) || num < 8 || num > 15) {
- throw new TypeError(
- `Invalid value for parameter "${key}": ${value}`
- );
- }
- value = num;
- } else if (
- key === 'client_no_context_takeover' ||
- key === 'server_no_context_takeover'
- ) {
- if (value !== true) {
- throw new TypeError(
- `Invalid value for parameter "${key}": ${value}`
- );
- }
- } else {
- throw new Error(`Unknown parameter "${key}"`);
- }
- params[key] = value;
- });
- });
- return configurations;
- }
- /**
- * Decompress data. Concurrency limited.
- *
- * @param {Buffer} data Compressed data
- * @param {Boolean} fin Specifies whether or not this is the last fragment
- * @param {Function} callback Callback
- * @public
- */
- decompress(data, fin, callback) {
- zlibLimiter.add((done) => {
- this._decompress(data, fin, (err, result) => {
- done();
- callback(err, result);
- });
- });
- }
- /**
- * Compress data. Concurrency limited.
- *
- * @param {Buffer} data Data to compress
- * @param {Boolean} fin Specifies whether or not this is the last fragment
- * @param {Function} callback Callback
- * @public
- */
- compress(data, fin, callback) {
- zlibLimiter.add((done) => {
- this._compress(data, fin, (err, result) => {
- done();
- callback(err, result);
- });
- });
- }
- /**
- * Decompress data.
- *
- * @param {Buffer} data Compressed data
- * @param {Boolean} fin Specifies whether or not this is the last fragment
- * @param {Function} callback Callback
- * @private
- */
- _decompress(data, fin, callback) {
- const endpoint = this._isServer ? 'client' : 'server';
- if (!this._inflate) {
- const key = `${endpoint}_max_window_bits`;
- const windowBits =
- typeof this.params[key] !== 'number'
- ? zlib.Z_DEFAULT_WINDOWBITS
- : this.params[key];
- this._inflate = zlib.createInflateRaw({
- ...this._options.zlibInflateOptions,
- windowBits
- });
- this._inflate[kPerMessageDeflate] = this;
- this._inflate[kTotalLength] = 0;
- this._inflate[kBuffers] = [];
- this._inflate.on('error', inflateOnError);
- this._inflate.on('data', inflateOnData);
- }
- this._inflate[kCallback] = callback;
- this._inflate.write(data);
- if (fin) this._inflate.write(TRAILER);
- this._inflate.flush(() => {
- const err = this._inflate[kError];
- if (err) {
- this._inflate.close();
- this._inflate = null;
- callback(err);
- return;
- }
- const data = bufferUtil.concat(
- this._inflate[kBuffers],
- this._inflate[kTotalLength]
- );
- if (this._inflate._readableState.endEmitted) {
- this._inflate.close();
- this._inflate = null;
- } else {
- this._inflate[kTotalLength] = 0;
- this._inflate[kBuffers] = [];
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
- this._inflate.reset();
- }
- }
- callback(null, data);
- });
- }
- /**
- * Compress data.
- *
- * @param {Buffer} data Data to compress
- * @param {Boolean} fin Specifies whether or not this is the last fragment
- * @param {Function} callback Callback
- * @private
- */
- _compress(data, fin, callback) {
- const endpoint = this._isServer ? 'server' : 'client';
- if (!this._deflate) {
- const key = `${endpoint}_max_window_bits`;
- const windowBits =
- typeof this.params[key] !== 'number'
- ? zlib.Z_DEFAULT_WINDOWBITS
- : this.params[key];
- this._deflate = zlib.createDeflateRaw({
- ...this._options.zlibDeflateOptions,
- windowBits
- });
- this._deflate[kTotalLength] = 0;
- this._deflate[kBuffers] = [];
- this._deflate.on('data', deflateOnData);
- }
- this._deflate[kCallback] = callback;
- this._deflate.write(data);
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
- if (!this._deflate) {
- //
- // The deflate stream was closed while data was being processed.
- //
- return;
- }
- let data = bufferUtil.concat(
- this._deflate[kBuffers],
- this._deflate[kTotalLength]
- );
- if (fin) data = data.slice(0, data.length - 4);
- //
- // Ensure that the callback will not be called again in
- // `PerMessageDeflate#cleanup()`.
- //
- this._deflate[kCallback] = null;
- this._deflate[kTotalLength] = 0;
- this._deflate[kBuffers] = [];
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
- this._deflate.reset();
- }
- callback(null, data);
- });
- }
- }
- module.exports = PerMessageDeflate;
- /**
- * The listener of the `zlib.DeflateRaw` stream `'data'` event.
- *
- * @param {Buffer} chunk A chunk of data
- * @private
- */
- function deflateOnData(chunk) {
- this[kBuffers].push(chunk);
- this[kTotalLength] += chunk.length;
- }
- /**
- * The listener of the `zlib.InflateRaw` stream `'data'` event.
- *
- * @param {Buffer} chunk A chunk of data
- * @private
- */
- function inflateOnData(chunk) {
- this[kTotalLength] += chunk.length;
- if (
- this[kPerMessageDeflate]._maxPayload < 1 ||
- this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
- ) {
- this[kBuffers].push(chunk);
- return;
- }
- this[kError] = new RangeError('Max payload size exceeded');
- this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
- this[kError][kStatusCode] = 1009;
- this.removeListener('data', inflateOnData);
- this.reset();
- }
- /**
- * The listener of the `zlib.InflateRaw` stream `'error'` event.
- *
- * @param {Error} err The emitted error
- * @private
- */
- function inflateOnError(err) {
- //
- // There is no need to call `Zlib#close()` as the handle is automatically
- // closed when an error is emitted.
- //
- this[kPerMessageDeflate]._inflate = null;
- err[kStatusCode] = 1007;
- this[kCallback](err);
- }
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js":
- /*!********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js ***!
- \********************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const { Writable } = __webpack_require__(/*! stream */ "stream");
- const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
- const {
- BINARY_TYPES,
- EMPTY_BUFFER,
- kStatusCode,
- kWebSocket
- } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
- const { concat, toArrayBuffer, unmask } = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
- const { isValidStatusCode, isValidUTF8 } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
- const GET_INFO = 0;
- const GET_PAYLOAD_LENGTH_16 = 1;
- const GET_PAYLOAD_LENGTH_64 = 2;
- const GET_MASK = 3;
- const GET_DATA = 4;
- const INFLATING = 5;
- /**
- * HyBi Receiver implementation.
- *
- * @extends Writable
- */
- class Receiver extends Writable {
- /**
- * Creates a Receiver instance.
- *
- * @param {Object} [options] Options object
- * @param {String} [options.binaryType=nodebuffer] The type for binary data
- * @param {Object} [options.extensions] An object containing the negotiated
- * extensions
- * @param {Boolean} [options.isServer=false] Specifies whether to operate in
- * client or server mode
- * @param {Number} [options.maxPayload=0] The maximum allowed message length
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
- * not to skip UTF-8 validation for text and close messages
- */
- constructor(options = {}) {
- super();
- this._binaryType = options.binaryType || BINARY_TYPES[0];
- this._extensions = options.extensions || {};
- this._isServer = !!options.isServer;
- this._maxPayload = options.maxPayload | 0;
- this._skipUTF8Validation = !!options.skipUTF8Validation;
- this[kWebSocket] = undefined;
- this._bufferedBytes = 0;
- this._buffers = [];
- this._compressed = false;
- this._payloadLength = 0;
- this._mask = undefined;
- this._fragmented = 0;
- this._masked = false;
- this._fin = false;
- this._opcode = 0;
- this._totalPayloadLength = 0;
- this._messageLength = 0;
- this._fragments = [];
- this._state = GET_INFO;
- this._loop = false;
- }
- /**
- * Implements `Writable.prototype._write()`.
- *
- * @param {Buffer} chunk The chunk of data to write
- * @param {String} encoding The character encoding of `chunk`
- * @param {Function} cb Callback
- * @private
- */
- _write(chunk, encoding, cb) {
- if (this._opcode === 0x08 && this._state == GET_INFO) return cb();
- this._bufferedBytes += chunk.length;
- this._buffers.push(chunk);
- this.startLoop(cb);
- }
- /**
- * Consumes `n` bytes from the buffered data.
- *
- * @param {Number} n The number of bytes to consume
- * @return {Buffer} The consumed bytes
- * @private
- */
- consume(n) {
- this._bufferedBytes -= n;
- if (n === this._buffers[0].length) return this._buffers.shift();
- if (n < this._buffers[0].length) {
- const buf = this._buffers[0];
- this._buffers[0] = buf.slice(n);
- return buf.slice(0, n);
- }
- const dst = Buffer.allocUnsafe(n);
- do {
- const buf = this._buffers[0];
- const offset = dst.length - n;
- if (n >= buf.length) {
- dst.set(this._buffers.shift(), offset);
- } else {
- dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
- this._buffers[0] = buf.slice(n);
- }
- n -= buf.length;
- } while (n > 0);
- return dst;
- }
- /**
- * Starts the parsing loop.
- *
- * @param {Function} cb Callback
- * @private
- */
- startLoop(cb) {
- let err;
- this._loop = true;
- do {
- switch (this._state) {
- case GET_INFO:
- err = this.getInfo();
- break;
- case GET_PAYLOAD_LENGTH_16:
- err = this.getPayloadLength16();
- break;
- case GET_PAYLOAD_LENGTH_64:
- err = this.getPayloadLength64();
- break;
- case GET_MASK:
- this.getMask();
- break;
- case GET_DATA:
- err = this.getData(cb);
- break;
- default:
- // `INFLATING`
- this._loop = false;
- return;
- }
- } while (this._loop);
- cb(err);
- }
- /**
- * Reads the first two bytes of a frame.
- *
- * @return {(RangeError|undefined)} A possible error
- * @private
- */
- getInfo() {
- if (this._bufferedBytes < 2) {
- this._loop = false;
- return;
- }
- const buf = this.consume(2);
- if ((buf[0] & 0x30) !== 0x00) {
- this._loop = false;
- return error(
- RangeError,
- 'RSV2 and RSV3 must be clear',
- true,
- 1002,
- 'WS_ERR_UNEXPECTED_RSV_2_3'
- );
- }
- const compressed = (buf[0] & 0x40) === 0x40;
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
- this._loop = false;
- return error(
- RangeError,
- 'RSV1 must be clear',
- true,
- 1002,
- 'WS_ERR_UNEXPECTED_RSV_1'
- );
- }
- this._fin = (buf[0] & 0x80) === 0x80;
- this._opcode = buf[0] & 0x0f;
- this._payloadLength = buf[1] & 0x7f;
- if (this._opcode === 0x00) {
- if (compressed) {
- this._loop = false;
- return error(
- RangeError,
- 'RSV1 must be clear',
- true,
- 1002,
- 'WS_ERR_UNEXPECTED_RSV_1'
- );
- }
- if (!this._fragmented) {
- this._loop = false;
- return error(
- RangeError,
- 'invalid opcode 0',
- true,
- 1002,
- 'WS_ERR_INVALID_OPCODE'
- );
- }
- this._opcode = this._fragmented;
- } else if (this._opcode === 0x01 || this._opcode === 0x02) {
- if (this._fragmented) {
- this._loop = false;
- return error(
- RangeError,
- `invalid opcode ${this._opcode}`,
- true,
- 1002,
- 'WS_ERR_INVALID_OPCODE'
- );
- }
- this._compressed = compressed;
- } else if (this._opcode > 0x07 && this._opcode < 0x0b) {
- if (!this._fin) {
- this._loop = false;
- return error(
- RangeError,
- 'FIN must be set',
- true,
- 1002,
- 'WS_ERR_EXPECTED_FIN'
- );
- }
- if (compressed) {
- this._loop = false;
- return error(
- RangeError,
- 'RSV1 must be clear',
- true,
- 1002,
- 'WS_ERR_UNEXPECTED_RSV_1'
- );
- }
- if (this._payloadLength > 0x7d) {
- this._loop = false;
- return error(
- RangeError,
- `invalid payload length ${this._payloadLength}`,
- true,
- 1002,
- 'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'
- );
- }
- } else {
- this._loop = false;
- return error(
- RangeError,
- `invalid opcode ${this._opcode}`,
- true,
- 1002,
- 'WS_ERR_INVALID_OPCODE'
- );
- }
- if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
- this._masked = (buf[1] & 0x80) === 0x80;
- if (this._isServer) {
- if (!this._masked) {
- this._loop = false;
- return error(
- RangeError,
- 'MASK must be set',
- true,
- 1002,
- 'WS_ERR_EXPECTED_MASK'
- );
- }
- } else if (this._masked) {
- this._loop = false;
- return error(
- RangeError,
- 'MASK must be clear',
- true,
- 1002,
- 'WS_ERR_UNEXPECTED_MASK'
- );
- }
- if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
- else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
- else return this.haveLength();
- }
- /**
- * Gets extended payload length (7+16).
- *
- * @return {(RangeError|undefined)} A possible error
- * @private
- */
- getPayloadLength16() {
- if (this._bufferedBytes < 2) {
- this._loop = false;
- return;
- }
- this._payloadLength = this.consume(2).readUInt16BE(0);
- return this.haveLength();
- }
- /**
- * Gets extended payload length (7+64).
- *
- * @return {(RangeError|undefined)} A possible error
- * @private
- */
- getPayloadLength64() {
- if (this._bufferedBytes < 8) {
- this._loop = false;
- return;
- }
- const buf = this.consume(8);
- const num = buf.readUInt32BE(0);
- //
- // The maximum safe integer in JavaScript is 2^53 - 1. An error is returned
- // if payload length is greater than this number.
- //
- if (num > Math.pow(2, 53 - 32) - 1) {
- this._loop = false;
- return error(
- RangeError,
- 'Unsupported WebSocket frame: payload length > 2^53 - 1',
- false,
- 1009,
- 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
- );
- }
- this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
- return this.haveLength();
- }
- /**
- * Payload length has been read.
- *
- * @return {(RangeError|undefined)} A possible error
- * @private
- */
- haveLength() {
- if (this._payloadLength && this._opcode < 0x08) {
- this._totalPayloadLength += this._payloadLength;
- if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
- this._loop = false;
- return error(
- RangeError,
- 'Max payload size exceeded',
- false,
- 1009,
- 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
- );
- }
- }
- if (this._masked) this._state = GET_MASK;
- else this._state = GET_DATA;
- }
- /**
- * Reads mask bytes.
- *
- * @private
- */
- getMask() {
- if (this._bufferedBytes < 4) {
- this._loop = false;
- return;
- }
- this._mask = this.consume(4);
- this._state = GET_DATA;
- }
- /**
- * Reads data bytes.
- *
- * @param {Function} cb Callback
- * @return {(Error|RangeError|undefined)} A possible error
- * @private
- */
- getData(cb) {
- let data = EMPTY_BUFFER;
- if (this._payloadLength) {
- if (this._bufferedBytes < this._payloadLength) {
- this._loop = false;
- return;
- }
- data = this.consume(this._payloadLength);
- if (this._masked) unmask(data, this._mask);
- }
- if (this._opcode > 0x07) return this.controlMessage(data);
- if (this._compressed) {
- this._state = INFLATING;
- this.decompress(data, cb);
- return;
- }
- if (data.length) {
- //
- // This message is not compressed so its length is the sum of the payload
- // length of all fragments.
- //
- this._messageLength = this._totalPayloadLength;
- this._fragments.push(data);
- }
- return this.dataMessage();
- }
- /**
- * Decompresses data.
- *
- * @param {Buffer} data Compressed data
- * @param {Function} cb Callback
- * @private
- */
- decompress(data, cb) {
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
- perMessageDeflate.decompress(data, this._fin, (err, buf) => {
- if (err) return cb(err);
- if (buf.length) {
- this._messageLength += buf.length;
- if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
- return cb(
- error(
- RangeError,
- 'Max payload size exceeded',
- false,
- 1009,
- 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
- )
- );
- }
- this._fragments.push(buf);
- }
- const er = this.dataMessage();
- if (er) return cb(er);
- this.startLoop(cb);
- });
- }
- /**
- * Handles a data message.
- *
- * @return {(Error|undefined)} A possible error
- * @private
- */
- dataMessage() {
- if (this._fin) {
- const messageLength = this._messageLength;
- const fragments = this._fragments;
- this._totalPayloadLength = 0;
- this._messageLength = 0;
- this._fragmented = 0;
- this._fragments = [];
- if (this._opcode === 2) {
- let data;
- if (this._binaryType === 'nodebuffer') {
- data = concat(fragments, messageLength);
- } else if (this._binaryType === 'arraybuffer') {
- data = toArrayBuffer(concat(fragments, messageLength));
- } else {
- data = fragments;
- }
- this.emit('message', data, true);
- } else {
- const buf = concat(fragments, messageLength);
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
- this._loop = false;
- return error(
- Error,
- 'invalid UTF-8 sequence',
- true,
- 1007,
- 'WS_ERR_INVALID_UTF8'
- );
- }
- this.emit('message', buf, false);
- }
- }
- this._state = GET_INFO;
- }
- /**
- * Handles a control message.
- *
- * @param {Buffer} data Data to handle
- * @return {(Error|RangeError|undefined)} A possible error
- * @private
- */
- controlMessage(data) {
- if (this._opcode === 0x08) {
- this._loop = false;
- if (data.length === 0) {
- this.emit('conclude', 1005, EMPTY_BUFFER);
- this.end();
- } else if (data.length === 1) {
- return error(
- RangeError,
- 'invalid payload length 1',
- true,
- 1002,
- 'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'
- );
- } else {
- const code = data.readUInt16BE(0);
- if (!isValidStatusCode(code)) {
- return error(
- RangeError,
- `invalid status code ${code}`,
- true,
- 1002,
- 'WS_ERR_INVALID_CLOSE_CODE'
- );
- }
- const buf = data.slice(2);
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
- return error(
- Error,
- 'invalid UTF-8 sequence',
- true,
- 1007,
- 'WS_ERR_INVALID_UTF8'
- );
- }
- this.emit('conclude', code, buf);
- this.end();
- }
- } else if (this._opcode === 0x09) {
- this.emit('ping', data);
- } else {
- this.emit('pong', data);
- }
- this._state = GET_INFO;
- }
- }
- module.exports = Receiver;
- /**
- * Builds an error object.
- *
- * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
- * @param {String} message The error message
- * @param {Boolean} prefix Specifies whether or not to add a default prefix to
- * `message`
- * @param {Number} statusCode The status code
- * @param {String} errorCode The exposed error code
- * @return {(Error|RangeError)} The error
- * @private
- */
- function error(ErrorCtor, message, prefix, statusCode, errorCode) {
- const err = new ErrorCtor(
- prefix ? `Invalid WebSocket frame: ${message}` : message
- );
- Error.captureStackTrace(err, error);
- err.code = errorCode;
- err[kStatusCode] = statusCode;
- return err;
- }
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js":
- /*!******************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js ***!
- \******************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls$" }] */
- const net = __webpack_require__(/*! net */ "net");
- const tls = __webpack_require__(/*! tls */ "tls");
- const { randomFillSync } = __webpack_require__(/*! crypto */ "crypto");
- const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
- const { EMPTY_BUFFER } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
- const { isValidStatusCode } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
- const { mask: applyMask, toBuffer } = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
- const mask = Buffer.alloc(4);
- /**
- * HyBi Sender implementation.
- */
- class Sender {
- /**
- * Creates a Sender instance.
- *
- * @param {(net.Socket|tls.Socket)} socket The connection socket
- * @param {Object} [extensions] An object containing the negotiated extensions
- */
- constructor(socket, extensions) {
- this._extensions = extensions || {};
- this._socket = socket;
- this._firstFragment = true;
- this._compress = false;
- this._bufferedBytes = 0;
- this._deflating = false;
- this._queue = [];
- }
- /**
- * Frames a piece of data according to the HyBi WebSocket protocol.
- *
- * @param {Buffer} data The data to frame
- * @param {Object} options Options object
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
- * FIN bit
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
- * `data`
- * @param {Number} options.opcode The opcode
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
- * modified
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
- * RSV1 bit
- * @return {Buffer[]} The framed data as a list of `Buffer` instances
- * @public
- */
- static frame(data, options) {
- const merge = options.mask && options.readOnly;
- let offset = options.mask ? 6 : 2;
- let payloadLength = data.length;
- if (data.length >= 65536) {
- offset += 8;
- payloadLength = 127;
- } else if (data.length > 125) {
- offset += 2;
- payloadLength = 126;
- }
- const target = Buffer.allocUnsafe(merge ? data.length + offset : offset);
- target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
- if (options.rsv1) target[0] |= 0x40;
- target[1] = payloadLength;
- if (payloadLength === 126) {
- target.writeUInt16BE(data.length, 2);
- } else if (payloadLength === 127) {
- target.writeUInt32BE(0, 2);
- target.writeUInt32BE(data.length, 6);
- }
- if (!options.mask) return [target, data];
- randomFillSync(mask, 0, 4);
- target[1] |= 0x80;
- target[offset - 4] = mask[0];
- target[offset - 3] = mask[1];
- target[offset - 2] = mask[2];
- target[offset - 1] = mask[3];
- if (merge) {
- applyMask(data, mask, target, offset, data.length);
- return [target];
- }
- applyMask(data, mask, data, 0, data.length);
- return [target, data];
- }
- /**
- * Sends a close message to the other peer.
- *
- * @param {Number} [code] The status code component of the body
- * @param {(String|Buffer)} [data] The message component of the body
- * @param {Boolean} [mask=false] Specifies whether or not to mask the message
- * @param {Function} [cb] Callback
- * @public
- */
- close(code, data, mask, cb) {
- let buf;
- if (code === undefined) {
- buf = EMPTY_BUFFER;
- } else if (typeof code !== 'number' || !isValidStatusCode(code)) {
- throw new TypeError('First argument must be a valid error code number');
- } else if (data === undefined || !data.length) {
- buf = Buffer.allocUnsafe(2);
- buf.writeUInt16BE(code, 0);
- } else {
- const length = Buffer.byteLength(data);
- if (length > 123) {
- throw new RangeError('The message must not be greater than 123 bytes');
- }
- buf = Buffer.allocUnsafe(2 + length);
- buf.writeUInt16BE(code, 0);
- if (typeof data === 'string') {
- buf.write(data, 2);
- } else {
- buf.set(data, 2);
- }
- }
- if (this._deflating) {
- this.enqueue([this.doClose, buf, mask, cb]);
- } else {
- this.doClose(buf, mask, cb);
- }
- }
- /**
- * Frames and sends a close message.
- *
- * @param {Buffer} data The message to send
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
- * @param {Function} [cb] Callback
- * @private
- */
- doClose(data, mask, cb) {
- this.sendFrame(
- Sender.frame(data, {
- fin: true,
- rsv1: false,
- opcode: 0x08,
- mask,
- readOnly: false
- }),
- cb
- );
- }
- /**
- * Sends a ping message to the other peer.
- *
- * @param {*} data The message to send
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
- * @param {Function} [cb] Callback
- * @public
- */
- ping(data, mask, cb) {
- const buf = toBuffer(data);
- if (buf.length > 125) {
- throw new RangeError('The data size must not be greater than 125 bytes');
- }
- if (this._deflating) {
- this.enqueue([this.doPing, buf, mask, toBuffer.readOnly, cb]);
- } else {
- this.doPing(buf, mask, toBuffer.readOnly, cb);
- }
- }
- /**
- * Frames and sends a ping message.
- *
- * @param {Buffer} data The message to send
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
- * @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
- * @param {Function} [cb] Callback
- * @private
- */
- doPing(data, mask, readOnly, cb) {
- this.sendFrame(
- Sender.frame(data, {
- fin: true,
- rsv1: false,
- opcode: 0x09,
- mask,
- readOnly
- }),
- cb
- );
- }
- /**
- * Sends a pong message to the other peer.
- *
- * @param {*} data The message to send
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
- * @param {Function} [cb] Callback
- * @public
- */
- pong(data, mask, cb) {
- const buf = toBuffer(data);
- if (buf.length > 125) {
- throw new RangeError('The data size must not be greater than 125 bytes');
- }
- if (this._deflating) {
- this.enqueue([this.doPong, buf, mask, toBuffer.readOnly, cb]);
- } else {
- this.doPong(buf, mask, toBuffer.readOnly, cb);
- }
- }
- /**
- * Frames and sends a pong message.
- *
- * @param {Buffer} data The message to send
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
- * @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
- * @param {Function} [cb] Callback
- * @private
- */
- doPong(data, mask, readOnly, cb) {
- this.sendFrame(
- Sender.frame(data, {
- fin: true,
- rsv1: false,
- opcode: 0x0a,
- mask,
- readOnly
- }),
- cb
- );
- }
- /**
- * Sends a data message to the other peer.
- *
- * @param {*} data The message to send
- * @param {Object} options Options object
- * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
- * or text
- * @param {Boolean} [options.compress=false] Specifies whether or not to
- * compress `data`
- * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
- * last one
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
- * `data`
- * @param {Function} [cb] Callback
- * @public
- */
- send(data, options, cb) {
- const buf = toBuffer(data);
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
- let opcode = options.binary ? 2 : 1;
- let rsv1 = options.compress;
- if (this._firstFragment) {
- this._firstFragment = false;
- if (
- rsv1 &&
- perMessageDeflate &&
- perMessageDeflate.params[
- perMessageDeflate._isServer
- ? 'server_no_context_takeover'
- : 'client_no_context_takeover'
- ]
- ) {
- rsv1 = buf.length >= perMessageDeflate._threshold;
- }
- this._compress = rsv1;
- } else {
- rsv1 = false;
- opcode = 0;
- }
- if (options.fin) this._firstFragment = true;
- if (perMessageDeflate) {
- const opts = {
- fin: options.fin,
- rsv1,
- opcode,
- mask: options.mask,
- readOnly: toBuffer.readOnly
- };
- if (this._deflating) {
- this.enqueue([this.dispatch, buf, this._compress, opts, cb]);
- } else {
- this.dispatch(buf, this._compress, opts, cb);
- }
- } else {
- this.sendFrame(
- Sender.frame(buf, {
- fin: options.fin,
- rsv1: false,
- opcode,
- mask: options.mask,
- readOnly: toBuffer.readOnly
- }),
- cb
- );
- }
- }
- /**
- * Dispatches a data message.
- *
- * @param {Buffer} data The message to send
- * @param {Boolean} [compress=false] Specifies whether or not to compress
- * `data`
- * @param {Object} options Options object
- * @param {Number} options.opcode The opcode
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
- * FIN bit
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
- * `data`
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
- * modified
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
- * RSV1 bit
- * @param {Function} [cb] Callback
- * @private
- */
- dispatch(data, compress, options, cb) {
- if (!compress) {
- this.sendFrame(Sender.frame(data, options), cb);
- return;
- }
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
- this._bufferedBytes += data.length;
- this._deflating = true;
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
- if (this._socket.destroyed) {
- const err = new Error(
- 'The socket was closed while data was being compressed'
- );
- if (typeof cb === 'function') cb(err);
- for (let i = 0; i < this._queue.length; i++) {
- const callback = this._queue[i][4];
- if (typeof callback === 'function') callback(err);
- }
- return;
- }
- this._bufferedBytes -= data.length;
- this._deflating = false;
- options.readOnly = false;
- this.sendFrame(Sender.frame(buf, options), cb);
- this.dequeue();
- });
- }
- /**
- * Executes queued send operations.
- *
- * @private
- */
- dequeue() {
- while (!this._deflating && this._queue.length) {
- const params = this._queue.shift();
- this._bufferedBytes -= params[1].length;
- Reflect.apply(params[0], this, params.slice(1));
- }
- }
- /**
- * Enqueues a send operation.
- *
- * @param {Array} params Send operation parameters.
- * @private
- */
- enqueue(params) {
- this._bufferedBytes += params[1].length;
- this._queue.push(params);
- }
- /**
- * Sends a frame.
- *
- * @param {Buffer[]} list The frame to send
- * @param {Function} [cb] Callback
- * @private
- */
- sendFrame(list, cb) {
- if (list.length === 2) {
- this._socket.cork();
- this._socket.write(list[0]);
- this._socket.write(list[1], cb);
- this._socket.uncork();
- } else {
- this._socket.write(list[0], cb);
- }
- }
- }
- module.exports = Sender;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/stream.js":
- /*!******************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/stream.js ***!
- \******************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const { Duplex } = __webpack_require__(/*! stream */ "stream");
- /**
- * Emits the `'close'` event on a stream.
- *
- * @param {Duplex} stream The stream.
- * @private
- */
- function emitClose(stream) {
- stream.emit('close');
- }
- /**
- * The listener of the `'end'` event.
- *
- * @private
- */
- function duplexOnEnd() {
- if (!this.destroyed && this._writableState.finished) {
- this.destroy();
- }
- }
- /**
- * The listener of the `'error'` event.
- *
- * @param {Error} err The error
- * @private
- */
- function duplexOnError(err) {
- this.removeListener('error', duplexOnError);
- this.destroy();
- if (this.listenerCount('error') === 0) {
- // Do not suppress the throwing behavior.
- this.emit('error', err);
- }
- }
- /**
- * Wraps a `WebSocket` in a duplex stream.
- *
- * @param {WebSocket} ws The `WebSocket` to wrap
- * @param {Object} [options] The options for the `Duplex` constructor
- * @return {Duplex} The duplex stream
- * @public
- */
- function createWebSocketStream(ws, options) {
- let resumeOnReceiverDrain = true;
- let terminateOnDestroy = true;
- function receiverOnDrain() {
- if (resumeOnReceiverDrain) ws._socket.resume();
- }
- if (ws.readyState === ws.CONNECTING) {
- ws.once('open', function open() {
- ws._receiver.removeAllListeners('drain');
- ws._receiver.on('drain', receiverOnDrain);
- });
- } else {
- ws._receiver.removeAllListeners('drain');
- ws._receiver.on('drain', receiverOnDrain);
- }
- const duplex = new Duplex({
- ...options,
- autoDestroy: false,
- emitClose: false,
- objectMode: false,
- writableObjectMode: false
- });
- ws.on('message', function message(msg, isBinary) {
- const data =
- !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
- if (!duplex.push(data)) {
- resumeOnReceiverDrain = false;
- ws._socket.pause();
- }
- });
- ws.once('error', function error(err) {
- if (duplex.destroyed) return;
- // Prevent `ws.terminate()` from being called by `duplex._destroy()`.
- //
- // - If the `'error'` event is emitted before the `'open'` event, then
- // `ws.terminate()` is a noop as no socket is assigned.
- // - Otherwise, the error is re-emitted by the listener of the `'error'`
- // event of the `Receiver` object. The listener already closes the
- // connection by calling `ws.close()`. This allows a close frame to be
- // sent to the other peer. If `ws.terminate()` is called right after this,
- // then the close frame might not be sent.
- terminateOnDestroy = false;
- duplex.destroy(err);
- });
- ws.once('close', function close() {
- if (duplex.destroyed) return;
- duplex.push(null);
- });
- duplex._destroy = function (err, callback) {
- if (ws.readyState === ws.CLOSED) {
- callback(err);
- process.nextTick(emitClose, duplex);
- return;
- }
- let called = false;
- ws.once('error', function error(err) {
- called = true;
- callback(err);
- });
- ws.once('close', function close() {
- if (!called) callback(err);
- process.nextTick(emitClose, duplex);
- });
- if (terminateOnDestroy) ws.terminate();
- };
- duplex._final = function (callback) {
- if (ws.readyState === ws.CONNECTING) {
- ws.once('open', function open() {
- duplex._final(callback);
- });
- return;
- }
- // If the value of the `_socket` property is `null` it means that `ws` is a
- // client websocket and the handshake failed. In fact, when this happens, a
- // socket is never assigned to the websocket. Wait for the `'error'` event
- // that will be emitted by the websocket.
- if (ws._socket === null) return;
- if (ws._socket._writableState.finished) {
- callback();
- if (duplex._readableState.endEmitted) duplex.destroy();
- } else {
- ws._socket.once('finish', function finish() {
- // `duplex` is not destroyed here because the `'end'` event will be
- // emitted on `duplex` after this `'finish'` event. The EOF signaling
- // `null` chunk is, in fact, pushed when the websocket emits `'close'`.
- callback();
- });
- ws.close();
- }
- };
- duplex._read = function () {
- if (ws.readyState === ws.OPEN && !resumeOnReceiverDrain) {
- resumeOnReceiverDrain = true;
- if (!ws._receiver._writableState.needDrain) ws._socket.resume();
- }
- };
- duplex._write = function (chunk, encoding, callback) {
- if (ws.readyState === ws.CONNECTING) {
- ws.once('open', function open() {
- duplex._write(chunk, encoding, callback);
- });
- return;
- }
- ws.send(chunk, callback);
- };
- duplex.on('end', duplexOnEnd);
- duplex.on('error', duplexOnError);
- return duplex;
- }
- module.exports = createWebSocketStream;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js":
- /*!***********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js ***!
- \***********************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const { tokenChars } = __webpack_require__(/*! ./validation */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js");
- /**
- * Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
- *
- * @param {String} header The field value of the header
- * @return {Set} The subprotocol names
- * @public
- */
- function parse(header) {
- const protocols = new Set();
- let start = -1;
- let end = -1;
- let i = 0;
- for (i; i < header.length; i++) {
- const code = header.charCodeAt(i);
- if (end === -1 && tokenChars[code] === 1) {
- if (start === -1) start = i;
- } else if (
- i !== 0 &&
- (code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
- ) {
- if (end === -1 && start !== -1) end = i;
- } else if (code === 0x2c /* ',' */) {
- if (start === -1) {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- if (end === -1) end = i;
- const protocol = header.slice(start, end);
- if (protocols.has(protocol)) {
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
- }
- protocols.add(protocol);
- start = end = -1;
- } else {
- throw new SyntaxError(`Unexpected character at index ${i}`);
- }
- }
- if (start === -1 || end !== -1) {
- throw new SyntaxError('Unexpected end of input');
- }
- const protocol = header.slice(start, i);
- if (protocols.has(protocol)) {
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
- }
- protocols.add(protocol);
- return protocols;
- }
- module.exports = { parse };
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js":
- /*!**********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/validation.js ***!
- \**********************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- //
- // Allowed token characters:
- //
- // '!', '#', '$', '%', '&', ''', '*', '+', '-',
- // '.', 0-9, A-Z, '^', '_', '`', a-z, '|', '~'
- //
- // tokenChars[32] === 0 // ' '
- // tokenChars[33] === 1 // '!'
- // tokenChars[34] === 0 // '"'
- // ...
- //
- // prettier-ignore
- const tokenChars = [
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
- 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 47
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 95
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 // 112 - 127
- ];
- /**
- * Checks if a status code is allowed in a close frame.
- *
- * @param {Number} code The status code
- * @return {Boolean} `true` if the status code is valid, else `false`
- * @public
- */
- function isValidStatusCode(code) {
- return (
- (code >= 1000 &&
- code <= 1014 &&
- code !== 1004 &&
- code !== 1005 &&
- code !== 1006) ||
- (code >= 3000 && code <= 4999)
- );
- }
- /**
- * Checks if a given buffer contains only correct UTF-8.
- * Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
- * Markus Kuhn.
- *
- * @param {Buffer} buf The buffer to check
- * @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
- * @public
- */
- function _isValidUTF8(buf) {
- const len = buf.length;
- let i = 0;
- while (i < len) {
- if ((buf[i] & 0x80) === 0) {
- // 0xxxxxxx
- i++;
- } else if ((buf[i] & 0xe0) === 0xc0) {
- // 110xxxxx 10xxxxxx
- if (
- i + 1 === len ||
- (buf[i + 1] & 0xc0) !== 0x80 ||
- (buf[i] & 0xfe) === 0xc0 // Overlong
- ) {
- return false;
- }
- i += 2;
- } else if ((buf[i] & 0xf0) === 0xe0) {
- // 1110xxxx 10xxxxxx 10xxxxxx
- if (
- i + 2 >= len ||
- (buf[i + 1] & 0xc0) !== 0x80 ||
- (buf[i + 2] & 0xc0) !== 0x80 ||
- (buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) || // Overlong
- (buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0) // Surrogate (U+D800 - U+DFFF)
- ) {
- return false;
- }
- i += 3;
- } else if ((buf[i] & 0xf8) === 0xf0) {
- // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
- if (
- i + 3 >= len ||
- (buf[i + 1] & 0xc0) !== 0x80 ||
- (buf[i + 2] & 0xc0) !== 0x80 ||
- (buf[i + 3] & 0xc0) !== 0x80 ||
- (buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) || // Overlong
- (buf[i] === 0xf4 && buf[i + 1] > 0x8f) ||
- buf[i] > 0xf4 // > U+10FFFF
- ) {
- return false;
- }
- i += 4;
- } else {
- return false;
- }
- }
- return true;
- }
- try {
- const isValidUTF8 = __webpack_require__(/*! utf-8-validate */ "utf-8-validate");
- module.exports = {
- isValidStatusCode,
- isValidUTF8(buf) {
- return buf.length < 150 ? _isValidUTF8(buf) : isValidUTF8(buf);
- },
- tokenChars
- };
- } catch (e) /* istanbul ignore next */ {
- module.exports = {
- isValidStatusCode,
- isValidUTF8: _isValidUTF8,
- tokenChars
- };
- }
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js":
- /*!****************************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js ***!
- \****************************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls|https$" }] */
- const EventEmitter = __webpack_require__(/*! events */ "events");
- const http = __webpack_require__(/*! http */ "http");
- const https = __webpack_require__(/*! https */ "https");
- const net = __webpack_require__(/*! net */ "net");
- const tls = __webpack_require__(/*! tls */ "tls");
- const { createHash } = __webpack_require__(/*! crypto */ "crypto");
- const extension = __webpack_require__(/*! ./extension */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js");
- const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
- const subprotocol = __webpack_require__(/*! ./subprotocol */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js");
- const WebSocket = __webpack_require__(/*! ./websocket */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js");
- const { GUID, kWebSocket } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
- const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
- const RUNNING = 0;
- const CLOSING = 1;
- const CLOSED = 2;
- /**
- * Class representing a WebSocket server.
- *
- * @extends EventEmitter
- */
- class WebSocketServer extends EventEmitter {
- /**
- * Create a `WebSocketServer` instance.
- *
- * @param {Object} options Configuration options
- * @param {Number} [options.backlog=511] The maximum length of the queue of
- * pending connections
- * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
- * track clients
- * @param {Function} [options.handleProtocols] A hook to handle protocols
- * @param {String} [options.host] The hostname where to bind the server
- * @param {Number} [options.maxPayload=104857600] The maximum allowed message
- * size
- * @param {Boolean} [options.noServer=false] Enable no server mode
- * @param {String} [options.path] Accept only connections matching this path
- * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
- * permessage-deflate
- * @param {Number} [options.port] The port where to bind the server
- * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
- * server to use
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
- * not to skip UTF-8 validation for text and close messages
- * @param {Function} [options.verifyClient] A hook to reject connections
- * @param {Function} [callback] A listener for the `listening` event
- */
- constructor(options, callback) {
- super();
- options = {
- maxPayload: 100 * 1024 * 1024,
- skipUTF8Validation: false,
- perMessageDeflate: false,
- handleProtocols: null,
- clientTracking: true,
- verifyClient: null,
- noServer: false,
- backlog: null, // use default (511 as implemented in net.js)
- server: null,
- host: null,
- path: null,
- port: null,
- ...options
- };
- if (
- (options.port == null && !options.server && !options.noServer) ||
- (options.port != null && (options.server || options.noServer)) ||
- (options.server && options.noServer)
- ) {
- throw new TypeError(
- 'One and only one of the "port", "server", or "noServer" options ' +
- 'must be specified'
- );
- }
- if (options.port != null) {
- this._server = http.createServer((req, res) => {
- const body = http.STATUS_CODES[426];
- res.writeHead(426, {
- 'Content-Length': body.length,
- 'Content-Type': 'text/plain'
- });
- res.end(body);
- });
- this._server.listen(
- options.port,
- options.host,
- options.backlog,
- callback
- );
- } else if (options.server) {
- this._server = options.server;
- }
- if (this._server) {
- const emitConnection = this.emit.bind(this, 'connection');
- this._removeListeners = addListeners(this._server, {
- listening: this.emit.bind(this, 'listening'),
- error: this.emit.bind(this, 'error'),
- upgrade: (req, socket, head) => {
- this.handleUpgrade(req, socket, head, emitConnection);
- }
- });
- }
- if (options.perMessageDeflate === true) options.perMessageDeflate = {};
- if (options.clientTracking) {
- this.clients = new Set();
- this._shouldEmitClose = false;
- }
- this.options = options;
- this._state = RUNNING;
- }
- /**
- * Returns the bound address, the address family name, and port of the server
- * as reported by the operating system if listening on an IP socket.
- * If the server is listening on a pipe or UNIX domain socket, the name is
- * returned as a string.
- *
- * @return {(Object|String|null)} The address of the server
- * @public
- */
- address() {
- if (this.options.noServer) {
- throw new Error('The server is operating in "noServer" mode');
- }
- if (!this._server) return null;
- return this._server.address();
- }
- /**
- * Stop the server from accepting new connections and emit the `'close'` event
- * when all existing connections are closed.
- *
- * @param {Function} [cb] A one-time listener for the `'close'` event
- * @public
- */
- close(cb) {
- if (this._state === CLOSED) {
- if (cb) {
- this.once('close', () => {
- cb(new Error('The server is not running'));
- });
- }
- process.nextTick(emitClose, this);
- return;
- }
- if (cb) this.once('close', cb);
- if (this._state === CLOSING) return;
- this._state = CLOSING;
- if (this.options.noServer || this.options.server) {
- if (this._server) {
- this._removeListeners();
- this._removeListeners = this._server = null;
- }
- if (this.clients) {
- if (!this.clients.size) {
- process.nextTick(emitClose, this);
- } else {
- this._shouldEmitClose = true;
- }
- } else {
- process.nextTick(emitClose, this);
- }
- } else {
- const server = this._server;
- this._removeListeners();
- this._removeListeners = this._server = null;
- //
- // The HTTP/S server was created internally. Close it, and rely on its
- // `'close'` event.
- //
- server.close(() => {
- emitClose(this);
- });
- }
- }
- /**
- * See if a given request should be handled by this server instance.
- *
- * @param {http.IncomingMessage} req Request object to inspect
- * @return {Boolean} `true` if the request is valid, else `false`
- * @public
- */
- shouldHandle(req) {
- if (this.options.path) {
- const index = req.url.indexOf('?');
- const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
- if (pathname !== this.options.path) return false;
- }
- return true;
- }
- /**
- * Handle a HTTP Upgrade request.
- *
- * @param {http.IncomingMessage} req The request object
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
- * server and client
- * @param {Buffer} head The first packet of the upgraded stream
- * @param {Function} cb Callback
- * @public
- */
- handleUpgrade(req, socket, head, cb) {
- socket.on('error', socketOnError);
- const key =
- req.headers['sec-websocket-key'] !== undefined
- ? req.headers['sec-websocket-key']
- : false;
- const version = +req.headers['sec-websocket-version'];
- if (
- req.method !== 'GET' ||
- req.headers.upgrade.toLowerCase() !== 'websocket' ||
- !key ||
- !keyRegex.test(key) ||
- (version !== 8 && version !== 13) ||
- !this.shouldHandle(req)
- ) {
- return abortHandshake(socket, 400);
- }
- const secWebSocketProtocol = req.headers['sec-websocket-protocol'];
- let protocols = new Set();
- if (secWebSocketProtocol !== undefined) {
- try {
- protocols = subprotocol.parse(secWebSocketProtocol);
- } catch (err) {
- return abortHandshake(socket, 400);
- }
- }
- const secWebSocketExtensions = req.headers['sec-websocket-extensions'];
- const extensions = {};
- if (
- this.options.perMessageDeflate &&
- secWebSocketExtensions !== undefined
- ) {
- const perMessageDeflate = new PerMessageDeflate(
- this.options.perMessageDeflate,
- true,
- this.options.maxPayload
- );
- try {
- const offers = extension.parse(secWebSocketExtensions);
- if (offers[PerMessageDeflate.extensionName]) {
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
- }
- } catch (err) {
- return abortHandshake(socket, 400);
- }
- }
- //
- // Optionally call external client verification handler.
- //
- if (this.options.verifyClient) {
- const info = {
- origin:
- req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
- secure: !!(req.socket.authorized || req.socket.encrypted),
- req
- };
- if (this.options.verifyClient.length === 2) {
- this.options.verifyClient(info, (verified, code, message, headers) => {
- if (!verified) {
- return abortHandshake(socket, code || 401, message, headers);
- }
- this.completeUpgrade(
- extensions,
- key,
- protocols,
- req,
- socket,
- head,
- cb
- );
- });
- return;
- }
- if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
- }
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
- }
- /**
- * Upgrade the connection to WebSocket.
- *
- * @param {Object} extensions The accepted extensions
- * @param {String} key The value of the `Sec-WebSocket-Key` header
- * @param {Set} protocols The subprotocols
- * @param {http.IncomingMessage} req The request object
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
- * server and client
- * @param {Buffer} head The first packet of the upgraded stream
- * @param {Function} cb Callback
- * @throws {Error} If called more than once with the same socket
- * @private
- */
- completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
- //
- // Destroy the socket if the client has already sent a FIN packet.
- //
- if (!socket.readable || !socket.writable) return socket.destroy();
- if (socket[kWebSocket]) {
- throw new Error(
- 'server.handleUpgrade() was called more than once with the same ' +
- 'socket, possibly due to a misconfiguration'
- );
- }
- if (this._state > RUNNING) return abortHandshake(socket, 503);
- const digest = createHash('sha1')
- .update(key + GUID)
- .digest('base64');
- const headers = [
- 'HTTP/1.1 101 Switching Protocols',
- 'Upgrade: websocket',
- 'Connection: Upgrade',
- `Sec-WebSocket-Accept: ${digest}`
- ];
- const ws = new WebSocket(null);
- if (protocols.size) {
- //
- // Optionally call external protocol selection handler.
- //
- const protocol = this.options.handleProtocols
- ? this.options.handleProtocols(protocols, req)
- : protocols.values().next().value;
- if (protocol) {
- headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
- ws._protocol = protocol;
- }
- }
- if (extensions[PerMessageDeflate.extensionName]) {
- const params = extensions[PerMessageDeflate.extensionName].params;
- const value = extension.format({
- [PerMessageDeflate.extensionName]: [params]
- });
- headers.push(`Sec-WebSocket-Extensions: ${value}`);
- ws._extensions = extensions;
- }
- //
- // Allow external modification/inspection of handshake headers.
- //
- this.emit('headers', headers, req);
- socket.write(headers.concat('\r\n').join('\r\n'));
- socket.removeListener('error', socketOnError);
- ws.setSocket(socket, head, {
- maxPayload: this.options.maxPayload,
- skipUTF8Validation: this.options.skipUTF8Validation
- });
- if (this.clients) {
- this.clients.add(ws);
- ws.on('close', () => {
- this.clients.delete(ws);
- if (this._shouldEmitClose && !this.clients.size) {
- process.nextTick(emitClose, this);
- }
- });
- }
- cb(ws, req);
- }
- }
- module.exports = WebSocketServer;
- /**
- * Add event listeners on an `EventEmitter` using a map of <event, listener>
- * pairs.
- *
- * @param {EventEmitter} server The event emitter
- * @param {Object.<String, Function>} map The listeners to add
- * @return {Function} A function that will remove the added listeners when
- * called
- * @private
- */
- function addListeners(server, map) {
- for (const event of Object.keys(map)) server.on(event, map[event]);
- return function removeListeners() {
- for (const event of Object.keys(map)) {
- server.removeListener(event, map[event]);
- }
- };
- }
- /**
- * Emit a `'close'` event on an `EventEmitter`.
- *
- * @param {EventEmitter} server The event emitter
- * @private
- */
- function emitClose(server) {
- server._state = CLOSED;
- server.emit('close');
- }
- /**
- * Handle premature socket errors.
- *
- * @private
- */
- function socketOnError() {
- this.destroy();
- }
- /**
- * Close the connection when preconditions are not fulfilled.
- *
- * @param {(net.Socket|tls.Socket)} socket The socket of the upgrade request
- * @param {Number} code The HTTP response status code
- * @param {String} [message] The HTTP response body
- * @param {Object} [headers] Additional HTTP response headers
- * @private
- */
- function abortHandshake(socket, code, message, headers) {
- if (socket.writable) {
- message = message || http.STATUS_CODES[code];
- headers = {
- Connection: 'close',
- 'Content-Type': 'text/html',
- 'Content-Length': Buffer.byteLength(message),
- ...headers
- };
- socket.write(
- `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
- Object.keys(headers)
- .map((h) => `${h}: ${headers[h]}`)
- .join('\r\n') +
- '\r\n\r\n' +
- message
- );
- }
- socket.removeListener('error', socketOnError);
- socket.destroy();
- }
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js":
- /*!*********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/node_modules/ws/lib/websocket.js ***!
- \*********************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Readable$" }] */
- const EventEmitter = __webpack_require__(/*! events */ "events");
- const https = __webpack_require__(/*! https */ "https");
- const http = __webpack_require__(/*! http */ "http");
- const net = __webpack_require__(/*! net */ "net");
- const tls = __webpack_require__(/*! tls */ "tls");
- const { randomBytes, createHash } = __webpack_require__(/*! crypto */ "crypto");
- const { Readable } = __webpack_require__(/*! stream */ "stream");
- const { URL } = __webpack_require__(/*! url */ "url");
- const PerMessageDeflate = __webpack_require__(/*! ./permessage-deflate */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js");
- const Receiver = __webpack_require__(/*! ./receiver */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/receiver.js");
- const Sender = __webpack_require__(/*! ./sender */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/sender.js");
- const {
- BINARY_TYPES,
- EMPTY_BUFFER,
- GUID,
- kForOnEventAttribute,
- kListener,
- kStatusCode,
- kWebSocket,
- NOOP
- } = __webpack_require__(/*! ./constants */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/constants.js");
- const {
- EventTarget: { addEventListener, removeEventListener }
- } = __webpack_require__(/*! ./event-target */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/event-target.js");
- const { format, parse } = __webpack_require__(/*! ./extension */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/extension.js");
- const { toBuffer } = __webpack_require__(/*! ./buffer-util */ "../ot-core/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js");
- const readyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
- const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
- const protocolVersions = [8, 13];
- const closeTimeout = 30 * 1000;
- /**
- * Class representing a WebSocket.
- *
- * @extends EventEmitter
- */
- class WebSocket extends EventEmitter {
- /**
- * Create a new `WebSocket`.
- *
- * @param {(String|URL)} address The URL to which to connect
- * @param {(String|String[])} [protocols] The subprotocols
- * @param {Object} [options] Connection options
- */
- constructor(address, protocols, options) {
- super();
- this._binaryType = BINARY_TYPES[0];
- this._closeCode = 1006;
- this._closeFrameReceived = false;
- this._closeFrameSent = false;
- this._closeMessage = EMPTY_BUFFER;
- this._closeTimer = null;
- this._extensions = {};
- this._protocol = '';
- this._readyState = WebSocket.CONNECTING;
- this._receiver = null;
- this._sender = null;
- this._socket = null;
- if (address !== null) {
- this._bufferedAmount = 0;
- this._isServer = false;
- this._redirects = 0;
- if (protocols === undefined) {
- protocols = [];
- } else if (!Array.isArray(protocols)) {
- if (typeof protocols === 'object' && protocols !== null) {
- options = protocols;
- protocols = [];
- } else {
- protocols = [protocols];
- }
- }
- initAsClient(this, address, protocols, options);
- } else {
- this._isServer = true;
- }
- }
- /**
- * This deviates from the WHATWG interface since ws doesn't support the
- * required default "blob" type (instead we define a custom "nodebuffer"
- * type).
- *
- * @type {String}
- */
- get binaryType() {
- return this._binaryType;
- }
- set binaryType(type) {
- if (!BINARY_TYPES.includes(type)) return;
- this._binaryType = type;
- //
- // Allow to change `binaryType` on the fly.
- //
- if (this._receiver) this._receiver._binaryType = type;
- }
- /**
- * @type {Number}
- */
- get bufferedAmount() {
- if (!this._socket) return this._bufferedAmount;
- return this._socket._writableState.length + this._sender._bufferedBytes;
- }
- /**
- * @type {String}
- */
- get extensions() {
- return Object.keys(this._extensions).join();
- }
- /**
- * @type {Function}
- */
- /* istanbul ignore next */
- get onclose() {
- return null;
- }
- /**
- * @type {Function}
- */
- /* istanbul ignore next */
- get onerror() {
- return null;
- }
- /**
- * @type {Function}
- */
- /* istanbul ignore next */
- get onopen() {
- return null;
- }
- /**
- * @type {Function}
- */
- /* istanbul ignore next */
- get onmessage() {
- return null;
- }
- /**
- * @type {String}
- */
- get protocol() {
- return this._protocol;
- }
- /**
- * @type {Number}
- */
- get readyState() {
- return this._readyState;
- }
- /**
- * @type {String}
- */
- get url() {
- return this._url;
- }
- /**
- * Set up the socket and the internal resources.
- *
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
- * server and client
- * @param {Buffer} head The first packet of the upgraded stream
- * @param {Object} options Options object
- * @param {Number} [options.maxPayload=0] The maximum allowed message size
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
- * not to skip UTF-8 validation for text and close messages
- * @private
- */
- setSocket(socket, head, options) {
- const receiver = new Receiver({
- binaryType: this.binaryType,
- extensions: this._extensions,
- isServer: this._isServer,
- maxPayload: options.maxPayload,
- skipUTF8Validation: options.skipUTF8Validation
- });
- this._sender = new Sender(socket, this._extensions);
- this._receiver = receiver;
- this._socket = socket;
- receiver[kWebSocket] = this;
- socket[kWebSocket] = this;
- receiver.on('conclude', receiverOnConclude);
- receiver.on('drain', receiverOnDrain);
- receiver.on('error', receiverOnError);
- receiver.on('message', receiverOnMessage);
- receiver.on('ping', receiverOnPing);
- receiver.on('pong', receiverOnPong);
- socket.setTimeout(0);
- socket.setNoDelay();
- if (head.length > 0) socket.unshift(head);
- socket.on('close', socketOnClose);
- socket.on('data', socketOnData);
- socket.on('end', socketOnEnd);
- socket.on('error', socketOnError);
- this._readyState = WebSocket.OPEN;
- this.emit('open');
- }
- /**
- * Emit the `'close'` event.
- *
- * @private
- */
- emitClose() {
- if (!this._socket) {
- this._readyState = WebSocket.CLOSED;
- this.emit('close', this._closeCode, this._closeMessage);
- return;
- }
- if (this._extensions[PerMessageDeflate.extensionName]) {
- this._extensions[PerMessageDeflate.extensionName].cleanup();
- }
- this._receiver.removeAllListeners();
- this._readyState = WebSocket.CLOSED;
- this.emit('close', this._closeCode, this._closeMessage);
- }
- /**
- * Start a closing handshake.
- *
- * +----------+ +-----------+ +----------+
- * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
- * | +----------+ +-----------+ +----------+ |
- * +----------+ +-----------+ |
- * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
- * +----------+ +-----------+ |
- * | | | +---+ |
- * +------------------------+-->|fin| - - - -
- * | +---+ | +---+
- * - - - - -|fin|<---------------------+
- * +---+
- *
- * @param {Number} [code] Status code explaining why the connection is closing
- * @param {(String|Buffer)} [data] The reason why the connection is
- * closing
- * @public
- */
- close(code, data) {
- if (this.readyState === WebSocket.CLOSED) return;
- if (this.readyState === WebSocket.CONNECTING) {
- const msg = 'WebSocket was closed before the connection was established';
- return abortHandshake(this, this._req, msg);
- }
- if (this.readyState === WebSocket.CLOSING) {
- if (
- this._closeFrameSent &&
- (this._closeFrameReceived || this._receiver._writableState.errorEmitted)
- ) {
- this._socket.end();
- }
- return;
- }
- this._readyState = WebSocket.CLOSING;
- this._sender.close(code, data, !this._isServer, (err) => {
- //
- // This error is handled by the `'error'` listener on the socket. We only
- // want to know if the close frame has been sent here.
- //
- if (err) return;
- this._closeFrameSent = true;
- if (
- this._closeFrameReceived ||
- this._receiver._writableState.errorEmitted
- ) {
- this._socket.end();
- }
- });
- //
- // Specify a timeout for the closing handshake to complete.
- //
- this._closeTimer = setTimeout(
- this._socket.destroy.bind(this._socket),
- closeTimeout
- );
- }
- /**
- * Send a ping.
- *
- * @param {*} [data] The data to send
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
- * @param {Function} [cb] Callback which is executed when the ping is sent
- * @public
- */
- ping(data, mask, cb) {
- if (this.readyState === WebSocket.CONNECTING) {
- throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
- }
- if (typeof data === 'function') {
- cb = data;
- data = mask = undefined;
- } else if (typeof mask === 'function') {
- cb = mask;
- mask = undefined;
- }
- if (typeof data === 'number') data = data.toString();
- if (this.readyState !== WebSocket.OPEN) {
- sendAfterClose(this, data, cb);
- return;
- }
- if (mask === undefined) mask = !this._isServer;
- this._sender.ping(data || EMPTY_BUFFER, mask, cb);
- }
- /**
- * Send a pong.
- *
- * @param {*} [data] The data to send
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
- * @param {Function} [cb] Callback which is executed when the pong is sent
- * @public
- */
- pong(data, mask, cb) {
- if (this.readyState === WebSocket.CONNECTING) {
- throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
- }
- if (typeof data === 'function') {
- cb = data;
- data = mask = undefined;
- } else if (typeof mask === 'function') {
- cb = mask;
- mask = undefined;
- }
- if (typeof data === 'number') data = data.toString();
- if (this.readyState !== WebSocket.OPEN) {
- sendAfterClose(this, data, cb);
- return;
- }
- if (mask === undefined) mask = !this._isServer;
- this._sender.pong(data || EMPTY_BUFFER, mask, cb);
- }
- /**
- * Send a data message.
- *
- * @param {*} data The message to send
- * @param {Object} [options] Options object
- * @param {Boolean} [options.binary] Specifies whether `data` is binary or
- * text
- * @param {Boolean} [options.compress] Specifies whether or not to compress
- * `data`
- * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
- * last one
- * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
- * @param {Function} [cb] Callback which is executed when data is written out
- * @public
- */
- send(data, options, cb) {
- if (this.readyState === WebSocket.CONNECTING) {
- throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
- }
- if (typeof options === 'function') {
- cb = options;
- options = {};
- }
- if (typeof data === 'number') data = data.toString();
- if (this.readyState !== WebSocket.OPEN) {
- sendAfterClose(this, data, cb);
- return;
- }
- const opts = {
- binary: typeof data !== 'string',
- mask: !this._isServer,
- compress: true,
- fin: true,
- ...options
- };
- if (!this._extensions[PerMessageDeflate.extensionName]) {
- opts.compress = false;
- }
- this._sender.send(data || EMPTY_BUFFER, opts, cb);
- }
- /**
- * Forcibly close the connection.
- *
- * @public
- */
- terminate() {
- if (this.readyState === WebSocket.CLOSED) return;
- if (this.readyState === WebSocket.CONNECTING) {
- const msg = 'WebSocket was closed before the connection was established';
- return abortHandshake(this, this._req, msg);
- }
- if (this._socket) {
- this._readyState = WebSocket.CLOSING;
- this._socket.destroy();
- }
- }
- }
- /**
- * @constant {Number} CONNECTING
- * @memberof WebSocket
- */
- Object.defineProperty(WebSocket, 'CONNECTING', {
- enumerable: true,
- value: readyStates.indexOf('CONNECTING')
- });
- /**
- * @constant {Number} CONNECTING
- * @memberof WebSocket.prototype
- */
- Object.defineProperty(WebSocket.prototype, 'CONNECTING', {
- enumerable: true,
- value: readyStates.indexOf('CONNECTING')
- });
- /**
- * @constant {Number} OPEN
- * @memberof WebSocket
- */
- Object.defineProperty(WebSocket, 'OPEN', {
- enumerable: true,
- value: readyStates.indexOf('OPEN')
- });
- /**
- * @constant {Number} OPEN
- * @memberof WebSocket.prototype
- */
- Object.defineProperty(WebSocket.prototype, 'OPEN', {
- enumerable: true,
- value: readyStates.indexOf('OPEN')
- });
- /**
- * @constant {Number} CLOSING
- * @memberof WebSocket
- */
- Object.defineProperty(WebSocket, 'CLOSING', {
- enumerable: true,
- value: readyStates.indexOf('CLOSING')
- });
- /**
- * @constant {Number} CLOSING
- * @memberof WebSocket.prototype
- */
- Object.defineProperty(WebSocket.prototype, 'CLOSING', {
- enumerable: true,
- value: readyStates.indexOf('CLOSING')
- });
- /**
- * @constant {Number} CLOSED
- * @memberof WebSocket
- */
- Object.defineProperty(WebSocket, 'CLOSED', {
- enumerable: true,
- value: readyStates.indexOf('CLOSED')
- });
- /**
- * @constant {Number} CLOSED
- * @memberof WebSocket.prototype
- */
- Object.defineProperty(WebSocket.prototype, 'CLOSED', {
- enumerable: true,
- value: readyStates.indexOf('CLOSED')
- });
- [
- 'binaryType',
- 'bufferedAmount',
- 'extensions',
- 'protocol',
- 'readyState',
- 'url'
- ].forEach((property) => {
- Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
- });
- //
- // Add the `onopen`, `onerror`, `onclose`, and `onmessage` attributes.
- // See https://html.spec.whatwg.org/multipage/comms.html#the-websocket-interface
- //
- ['open', 'error', 'close', 'message'].forEach((method) => {
- Object.defineProperty(WebSocket.prototype, `on${method}`, {
- enumerable: true,
- get() {
- for (const listener of this.listeners(method)) {
- if (listener[kForOnEventAttribute]) return listener[kListener];
- }
- return null;
- },
- set(handler) {
- for (const listener of this.listeners(method)) {
- if (listener[kForOnEventAttribute]) {
- this.removeListener(method, listener);
- break;
- }
- }
- if (typeof handler !== 'function') return;
- this.addEventListener(method, handler, {
- [kForOnEventAttribute]: true
- });
- }
- });
- });
- WebSocket.prototype.addEventListener = addEventListener;
- WebSocket.prototype.removeEventListener = removeEventListener;
- module.exports = WebSocket;
- /**
- * Initialize a WebSocket client.
- *
- * @param {WebSocket} websocket The client to initialize
- * @param {(String|URL)} address The URL to which to connect
- * @param {Array} protocols The subprotocols
- * @param {Object} [options] Connection options
- * @param {Boolean} [options.followRedirects=false] Whether or not to follow
- * redirects
- * @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
- * handshake request
- * @param {Number} [options.maxPayload=104857600] The maximum allowed message
- * size
- * @param {Number} [options.maxRedirects=10] The maximum number of redirects
- * allowed
- * @param {String} [options.origin] Value of the `Origin` or
- * `Sec-WebSocket-Origin` header
- * @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
- * permessage-deflate
- * @param {Number} [options.protocolVersion=13] Value of the
- * `Sec-WebSocket-Version` header
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
- * not to skip UTF-8 validation for text and close messages
- * @private
- */
- function initAsClient(websocket, address, protocols, options) {
- const opts = {
- protocolVersion: protocolVersions[1],
- maxPayload: 100 * 1024 * 1024,
- skipUTF8Validation: false,
- perMessageDeflate: true,
- followRedirects: false,
- maxRedirects: 10,
- ...options,
- createConnection: undefined,
- socketPath: undefined,
- hostname: undefined,
- protocol: undefined,
- timeout: undefined,
- method: undefined,
- host: undefined,
- path: undefined,
- port: undefined
- };
- if (!protocolVersions.includes(opts.protocolVersion)) {
- throw new RangeError(
- `Unsupported protocol version: ${opts.protocolVersion} ` +
- `(supported versions: ${protocolVersions.join(', ')})`
- );
- }
- let parsedUrl;
- if (address instanceof URL) {
- parsedUrl = address;
- websocket._url = address.href;
- } else {
- try {
- parsedUrl = new URL(address);
- } catch (e) {
- throw new SyntaxError(`Invalid URL: ${address}`);
- }
- websocket._url = address;
- }
- const isSecure = parsedUrl.protocol === 'wss:';
- const isUnixSocket = parsedUrl.protocol === 'ws+unix:';
- if (parsedUrl.protocol !== 'ws:' && !isSecure && !isUnixSocket) {
- throw new SyntaxError(
- 'The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"'
- );
- }
- if (isUnixSocket && !parsedUrl.pathname) {
- throw new SyntaxError("The URL's pathname is empty");
- }
- if (parsedUrl.hash) {
- throw new SyntaxError('The URL contains a fragment identifier');
- }
- const defaultPort = isSecure ? 443 : 80;
- const key = randomBytes(16).toString('base64');
- const get = isSecure ? https.get : http.get;
- const protocolSet = new Set();
- let perMessageDeflate;
- opts.createConnection = isSecure ? tlsConnect : netConnect;
- opts.defaultPort = opts.defaultPort || defaultPort;
- opts.port = parsedUrl.port || defaultPort;
- opts.host = parsedUrl.hostname.startsWith('[')
- ? parsedUrl.hostname.slice(1, -1)
- : parsedUrl.hostname;
- opts.headers = {
- 'Sec-WebSocket-Version': opts.protocolVersion,
- 'Sec-WebSocket-Key': key,
- Connection: 'Upgrade',
- Upgrade: 'websocket',
- ...opts.headers
- };
- opts.path = parsedUrl.pathname + parsedUrl.search;
- opts.timeout = opts.handshakeTimeout;
- if (opts.perMessageDeflate) {
- perMessageDeflate = new PerMessageDeflate(
- opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
- false,
- opts.maxPayload
- );
- opts.headers['Sec-WebSocket-Extensions'] = format({
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
- });
- }
- if (protocols.length) {
- for (const protocol of protocols) {
- if (
- typeof protocol !== 'string' ||
- !subprotocolRegex.test(protocol) ||
- protocolSet.has(protocol)
- ) {
- throw new SyntaxError(
- 'An invalid or duplicated subprotocol was specified'
- );
- }
- protocolSet.add(protocol);
- }
- opts.headers['Sec-WebSocket-Protocol'] = protocols.join(',');
- }
- if (opts.origin) {
- if (opts.protocolVersion < 13) {
- opts.headers['Sec-WebSocket-Origin'] = opts.origin;
- } else {
- opts.headers.Origin = opts.origin;
- }
- }
- if (parsedUrl.username || parsedUrl.password) {
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
- }
- if (isUnixSocket) {
- const parts = opts.path.split(':');
- opts.socketPath = parts[0];
- opts.path = parts[1];
- }
- let req = (websocket._req = get(opts));
- if (opts.timeout) {
- req.on('timeout', () => {
- abortHandshake(websocket, req, 'Opening handshake has timed out');
- });
- }
- req.on('error', (err) => {
- if (req === null || req.aborted) return;
- req = websocket._req = null;
- websocket._readyState = WebSocket.CLOSING;
- websocket.emit('error', err);
- websocket.emitClose();
- });
- req.on('response', (res) => {
- const location = res.headers.location;
- const statusCode = res.statusCode;
- if (
- location &&
- opts.followRedirects &&
- statusCode >= 300 &&
- statusCode < 400
- ) {
- if (++websocket._redirects > opts.maxRedirects) {
- abortHandshake(websocket, req, 'Maximum redirects exceeded');
- return;
- }
- req.abort();
- const addr = new URL(location, address);
- initAsClient(websocket, addr, protocols, options);
- } else if (!websocket.emit('unexpected-response', req, res)) {
- abortHandshake(
- websocket,
- req,
- `Unexpected server response: ${res.statusCode}`
- );
- }
- });
- req.on('upgrade', (res, socket, head) => {
- websocket.emit('upgrade', res);
- //
- // The user may have closed the connection from a listener of the `upgrade`
- // event.
- //
- if (websocket.readyState !== WebSocket.CONNECTING) return;
- req = websocket._req = null;
- const digest = createHash('sha1')
- .update(key + GUID)
- .digest('base64');
- if (res.headers['sec-websocket-accept'] !== digest) {
- abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
- return;
- }
- const serverProt = res.headers['sec-websocket-protocol'];
- let protError;
- if (serverProt !== undefined) {
- if (!protocolSet.size) {
- protError = 'Server sent a subprotocol but none was requested';
- } else if (!protocolSet.has(serverProt)) {
- protError = 'Server sent an invalid subprotocol';
- }
- } else if (protocolSet.size) {
- protError = 'Server sent no subprotocol';
- }
- if (protError) {
- abortHandshake(websocket, socket, protError);
- return;
- }
- if (serverProt) websocket._protocol = serverProt;
- const secWebSocketExtensions = res.headers['sec-websocket-extensions'];
- if (secWebSocketExtensions !== undefined) {
- if (!perMessageDeflate) {
- const message =
- 'Server sent a Sec-WebSocket-Extensions header but no extension ' +
- 'was requested';
- abortHandshake(websocket, socket, message);
- return;
- }
- let extensions;
- try {
- extensions = parse(secWebSocketExtensions);
- } catch (err) {
- const message = 'Invalid Sec-WebSocket-Extensions header';
- abortHandshake(websocket, socket, message);
- return;
- }
- const extensionNames = Object.keys(extensions);
- if (
- extensionNames.length !== 1 ||
- extensionNames[0] !== PerMessageDeflate.extensionName
- ) {
- const message = 'Server indicated an extension that was not requested';
- abortHandshake(websocket, socket, message);
- return;
- }
- try {
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
- } catch (err) {
- const message = 'Invalid Sec-WebSocket-Extensions header';
- abortHandshake(websocket, socket, message);
- return;
- }
- websocket._extensions[PerMessageDeflate.extensionName] =
- perMessageDeflate;
- }
- websocket.setSocket(socket, head, {
- maxPayload: opts.maxPayload,
- skipUTF8Validation: opts.skipUTF8Validation
- });
- });
- }
- /**
- * Create a `net.Socket` and initiate a connection.
- *
- * @param {Object} options Connection options
- * @return {net.Socket} The newly created socket used to start the connection
- * @private
- */
- function netConnect(options) {
- options.path = options.socketPath;
- return net.connect(options);
- }
- /**
- * Create a `tls.TLSSocket` and initiate a connection.
- *
- * @param {Object} options Connection options
- * @return {tls.TLSSocket} The newly created socket used to start the connection
- * @private
- */
- function tlsConnect(options) {
- options.path = undefined;
- if (!options.servername && options.servername !== '') {
- options.servername = net.isIP(options.host) ? '' : options.host;
- }
- return tls.connect(options);
- }
- /**
- * Abort the handshake and emit an error.
- *
- * @param {WebSocket} websocket The WebSocket instance
- * @param {(http.ClientRequest|net.Socket|tls.Socket)} stream The request to
- * abort or the socket to destroy
- * @param {String} message The error message
- * @private
- */
- function abortHandshake(websocket, stream, message) {
- websocket._readyState = WebSocket.CLOSING;
- const err = new Error(message);
- Error.captureStackTrace(err, abortHandshake);
- if (stream.setHeader) {
- stream.abort();
- if (stream.socket && !stream.socket.destroyed) {
- //
- // On Node.js >= 14.3.0 `request.abort()` does not destroy the socket if
- // called after the request completed. See
- // https://github.com/websockets/ws/issues/1869.
- //
- stream.socket.destroy();
- }
- stream.once('abort', websocket.emitClose.bind(websocket));
- websocket.emit('error', err);
- } else {
- stream.destroy(err);
- stream.once('error', websocket.emit.bind(websocket, 'error'));
- stream.once('close', websocket.emitClose.bind(websocket));
- }
- }
- /**
- * Handle cases where the `ping()`, `pong()`, or `send()` methods are called
- * when the `readyState` attribute is `CLOSING` or `CLOSED`.
- *
- * @param {WebSocket} websocket The WebSocket instance
- * @param {*} [data] The data to send
- * @param {Function} [cb] Callback
- * @private
- */
- function sendAfterClose(websocket, data, cb) {
- if (data) {
- const length = toBuffer(data).length;
- //
- // The `_bufferedAmount` property is used only when the peer is a client and
- // the opening handshake fails. Under these circumstances, in fact, the
- // `setSocket()` method is not called, so the `_socket` and `_sender`
- // properties are set to `null`.
- //
- if (websocket._socket) websocket._sender._bufferedBytes += length;
- else websocket._bufferedAmount += length;
- }
- if (cb) {
- const err = new Error(
- `WebSocket is not open: readyState ${websocket.readyState} ` +
- `(${readyStates[websocket.readyState]})`
- );
- cb(err);
- }
- }
- /**
- * The listener of the `Receiver` `'conclude'` event.
- *
- * @param {Number} code The status code
- * @param {Buffer} reason The reason for closing
- * @private
- */
- function receiverOnConclude(code, reason) {
- const websocket = this[kWebSocket];
- websocket._closeFrameReceived = true;
- websocket._closeMessage = reason;
- websocket._closeCode = code;
- if (websocket._socket[kWebSocket] === undefined) return;
- websocket._socket.removeListener('data', socketOnData);
- process.nextTick(resume, websocket._socket);
- if (code === 1005) websocket.close();
- else websocket.close(code, reason);
- }
- /**
- * The listener of the `Receiver` `'drain'` event.
- *
- * @private
- */
- function receiverOnDrain() {
- this[kWebSocket]._socket.resume();
- }
- /**
- * The listener of the `Receiver` `'error'` event.
- *
- * @param {(RangeError|Error)} err The emitted error
- * @private
- */
- function receiverOnError(err) {
- const websocket = this[kWebSocket];
- if (websocket._socket[kWebSocket] !== undefined) {
- websocket._socket.removeListener('data', socketOnData);
- //
- // On Node.js < 14.0.0 the `'error'` event is emitted synchronously. See
- // https://github.com/websockets/ws/issues/1940.
- //
- process.nextTick(resume, websocket._socket);
- websocket.close(err[kStatusCode]);
- }
- websocket.emit('error', err);
- }
- /**
- * The listener of the `Receiver` `'finish'` event.
- *
- * @private
- */
- function receiverOnFinish() {
- this[kWebSocket].emitClose();
- }
- /**
- * The listener of the `Receiver` `'message'` event.
- *
- * @param {Buffer|ArrayBuffer|Buffer[])} data The message
- * @param {Boolean} isBinary Specifies whether the message is binary or not
- * @private
- */
- function receiverOnMessage(data, isBinary) {
- this[kWebSocket].emit('message', data, isBinary);
- }
- /**
- * The listener of the `Receiver` `'ping'` event.
- *
- * @param {Buffer} data The data included in the ping frame
- * @private
- */
- function receiverOnPing(data) {
- const websocket = this[kWebSocket];
- websocket.pong(data, !websocket._isServer, NOOP);
- websocket.emit('ping', data);
- }
- /**
- * The listener of the `Receiver` `'pong'` event.
- *
- * @param {Buffer} data The data included in the pong frame
- * @private
- */
- function receiverOnPong(data) {
- this[kWebSocket].emit('pong', data);
- }
- /**
- * Resume a readable stream
- *
- * @param {Readable} stream The readable stream
- * @private
- */
- function resume(stream) {
- stream.resume();
- }
- /**
- * The listener of the `net.Socket` `'close'` event.
- *
- * @private
- */
- function socketOnClose() {
- const websocket = this[kWebSocket];
- this.removeListener('close', socketOnClose);
- this.removeListener('data', socketOnData);
- this.removeListener('end', socketOnEnd);
- websocket._readyState = WebSocket.CLOSING;
- let chunk;
- //
- // The close frame might not have been received or the `'end'` event emitted,
- // for example, if the socket was destroyed due to an error. Ensure that the
- // `receiver` stream is closed after writing any remaining buffered data to
- // it. If the readable side of the socket is in flowing mode then there is no
- // buffered data as everything has been already written and `readable.read()`
- // will return `null`. If instead, the socket is paused, any possible buffered
- // data will be read as a single chunk.
- //
- if (
- !this._readableState.endEmitted &&
- !websocket._closeFrameReceived &&
- !websocket._receiver._writableState.errorEmitted &&
- (chunk = websocket._socket.read()) !== null
- ) {
- websocket._receiver.write(chunk);
- }
- websocket._receiver.end();
- this[kWebSocket] = undefined;
- clearTimeout(websocket._closeTimer);
- if (
- websocket._receiver._writableState.finished ||
- websocket._receiver._writableState.errorEmitted
- ) {
- websocket.emitClose();
- } else {
- websocket._receiver.on('error', receiverOnFinish);
- websocket._receiver.on('finish', receiverOnFinish);
- }
- }
- /**
- * The listener of the `net.Socket` `'data'` event.
- *
- * @param {Buffer} chunk A chunk of data
- * @private
- */
- function socketOnData(chunk) {
- if (!this[kWebSocket]._receiver.write(chunk)) {
- this.pause();
- }
- }
- /**
- * The listener of the `net.Socket` `'end'` event.
- *
- * @private
- */
- function socketOnEnd() {
- const websocket = this[kWebSocket];
- websocket._readyState = WebSocket.CLOSING;
- websocket._receiver.end();
- this.end();
- }
- /**
- * The listener of the `net.Socket` `'error'` event.
- *
- * @private
- */
- function socketOnError() {
- const websocket = this[kWebSocket];
- this.removeListener('error', socketOnError);
- this.on('error', NOOP);
- if (websocket) {
- websocket._readyState = WebSocket.CLOSING;
- this.destroy();
- }
- }
- /***/ }),
- /***/ "../ot-core/node_modules/has-flag/index.js":
- /*!*************************************************!*\
- !*** ../ot-core/node_modules/has-flag/index.js ***!
- \*************************************************/
- /***/ ((module) => {
- "use strict";
- module.exports = (flag, argv) => {
- argv = argv || process.argv;
- const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
- const pos = argv.indexOf(prefix + flag);
- const terminatorPos = argv.indexOf('--');
- return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
- };
- /***/ }),
- /***/ "../ot-core/node_modules/ms/index.js":
- /*!*******************************************!*\
- !*** ../ot-core/node_modules/ms/index.js ***!
- \*******************************************/
- /***/ ((module) => {
- /**
- * Helpers.
- */
- var s = 1000;
- var m = s * 60;
- var h = m * 60;
- var d = h * 24;
- var w = d * 7;
- var y = d * 365.25;
- /**
- * Parse or format the given `val`.
- *
- * Options:
- *
- * - `long` verbose formatting [false]
- *
- * @param {String|Number} val
- * @param {Object} [options]
- * @throws {Error} throw an error if val is not a non-empty string or a number
- * @return {String|Number}
- * @api public
- */
- module.exports = function(val, options) {
- options = options || {};
- var type = typeof val;
- if (type === 'string' && val.length > 0) {
- return parse(val);
- } else if (type === 'number' && isFinite(val)) {
- return options.long ? fmtLong(val) : fmtShort(val);
- }
- throw new Error(
- 'val is not a non-empty string or a valid number. val=' +
- JSON.stringify(val)
- );
- };
- /**
- * Parse the given `str` and return milliseconds.
- *
- * @param {String} str
- * @return {Number}
- * @api private
- */
- function parse(str) {
- str = String(str);
- if (str.length > 100) {
- return;
- }
- 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(
- str
- );
- if (!match) {
- return;
- }
- var n = parseFloat(match[1]);
- var type = (match[2] || 'ms').toLowerCase();
- switch (type) {
- case 'years':
- case 'year':
- case 'yrs':
- case 'yr':
- case 'y':
- return n * y;
- case 'weeks':
- case 'week':
- case 'w':
- return n * w;
- case 'days':
- case 'day':
- case 'd':
- return n * d;
- case 'hours':
- case 'hour':
- case 'hrs':
- case 'hr':
- case 'h':
- return n * h;
- case 'minutes':
- case 'minute':
- case 'mins':
- case 'min':
- case 'm':
- return n * m;
- case 'seconds':
- case 'second':
- case 'secs':
- case 'sec':
- case 's':
- return n * s;
- case 'milliseconds':
- case 'millisecond':
- case 'msecs':
- case 'msec':
- case 'ms':
- return n;
- default:
- return undefined;
- }
- }
- /**
- * Short format for `ms`.
- *
- * @param {Number} ms
- * @return {String}
- * @api private
- */
- function fmtShort(ms) {
- var msAbs = Math.abs(ms);
- if (msAbs >= d) {
- return Math.round(ms / d) + 'd';
- }
- if (msAbs >= h) {
- return Math.round(ms / h) + 'h';
- }
- if (msAbs >= m) {
- return Math.round(ms / m) + 'm';
- }
- if (msAbs >= s) {
- return Math.round(ms / s) + 's';
- }
- return ms + 'ms';
- }
- /**
- * Long format for `ms`.
- *
- * @param {Number} ms
- * @return {String}
- * @api private
- */
- function fmtLong(ms) {
- var msAbs = Math.abs(ms);
- if (msAbs >= d) {
- return plural(ms, msAbs, d, 'day');
- }
- if (msAbs >= h) {
- return plural(ms, msAbs, h, 'hour');
- }
- if (msAbs >= m) {
- return plural(ms, msAbs, m, 'minute');
- }
- if (msAbs >= s) {
- return plural(ms, msAbs, s, 'second');
- }
- return ms + ' ms';
- }
- /**
- * Pluralization helper.
- */
- function plural(ms, msAbs, n, name) {
- var isPlural = msAbs >= n * 1.5;
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
- }
- /***/ }),
- /***/ "../ot-core/node_modules/parseqs/index.js":
- /*!************************************************!*\
- !*** ../ot-core/node_modules/parseqs/index.js ***!
- \************************************************/
- /***/ ((__unused_webpack_module, exports) => {
- /**
- * Compiles a querystring
- * Returns string representation of the object
- *
- * @param {Object}
- * @api private
- */
- exports.encode = function (obj) {
- var str = '';
- for (var i in obj) {
- if (obj.hasOwnProperty(i)) {
- if (str.length) str += '&';
- str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
- }
- }
- return str;
- };
- /**
- * Parses a simple querystring into an object
- *
- * @param {String} qs
- * @api private
- */
- exports.decode = function(qs){
- var qry = {};
- var pairs = qs.split('&');
- for (var i = 0, l = pairs.length; i < l; i++) {
- var pair = pairs[i].split('=');
- qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
- }
- return qry;
- };
- /***/ }),
- /***/ "../ot-core/node_modules/parseuri/index.js":
- /*!*************************************************!*\
- !*** ../ot-core/node_modules/parseuri/index.js ***!
- \*************************************************/
- /***/ ((module) => {
- /**
- * Parses an URI
- *
- * @author Steven Levithan <stevenlevithan.com> (MIT license)
- * @api private
- */
- var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
- var parts = [
- 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
- ];
- module.exports = function parseuri(str) {
- var src = str,
- b = str.indexOf('['),
- e = str.indexOf(']');
- if (b != -1 && e != -1) {
- str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
- }
- var m = re.exec(str || ''),
- uri = {},
- i = 14;
- while (i--) {
- uri[parts[i]] = m[i] || '';
- }
- if (b != -1 && e != -1) {
- uri.source = src;
- uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
- uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
- uri.ipv6uri = true;
- }
- uri.pathNames = pathNames(uri, uri['path']);
- uri.queryKey = queryKey(uri, uri['query']);
- return uri;
- };
- function pathNames(obj, path) {
- var regx = /\/{2,9}/g,
- names = path.replace(regx, "/").split("/");
- if (path.substr(0, 1) == '/' || path.length === 0) {
- names.splice(0, 1);
- }
- if (path.substr(path.length - 1, 1) == '/') {
- names.splice(names.length - 1, 1);
- }
- return names;
- }
- function queryKey(uri, query) {
- var data = {};
- query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
- if ($1) {
- data[$1] = $2;
- }
- });
- return data;
- }
- /***/ }),
- /***/ "../ot-core/node_modules/supports-color/index.js":
- /*!*******************************************************!*\
- !*** ../ot-core/node_modules/supports-color/index.js ***!
- \*******************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- "use strict";
- const os = __webpack_require__(/*! os */ "os");
- const hasFlag = __webpack_require__(/*! has-flag */ "../ot-core/node_modules/has-flag/index.js");
- const env = process.env;
- let forceColor;
- if (hasFlag('no-color') ||
- hasFlag('no-colors') ||
- hasFlag('color=false')) {
- forceColor = false;
- } else if (hasFlag('color') ||
- hasFlag('colors') ||
- hasFlag('color=true') ||
- hasFlag('color=always')) {
- forceColor = true;
- }
- if ('FORCE_COLOR' in env) {
- forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
- }
- function translateLevel(level) {
- if (level === 0) {
- return false;
- }
- return {
- level,
- hasBasic: true,
- has256: level >= 2,
- has16m: level >= 3
- };
- }
- function supportsColor(stream) {
- if (forceColor === false) {
- return 0;
- }
- if (hasFlag('color=16m') ||
- hasFlag('color=full') ||
- hasFlag('color=truecolor')) {
- return 3;
- }
- if (hasFlag('color=256')) {
- return 2;
- }
- if (stream && !stream.isTTY && forceColor !== true) {
- return 0;
- }
- const min = forceColor ? 1 : 0;
- if (process.platform === 'win32') {
- // Node.js 7.5.0 is the first version of Node.js to include a patch to
- // libuv that enables 256 color output on Windows. Anything earlier and it
- // won't work. However, here we target Node.js 8 at minimum as it is an LTS
- // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
- // release that supports 256 colors. Windows 10 build 14931 is the first release
- // that supports 16m/TrueColor.
- const osRelease = os.release().split('.');
- if (
- Number(process.versions.node.split('.')[0]) >= 8 &&
- Number(osRelease[0]) >= 10 &&
- Number(osRelease[2]) >= 10586
- ) {
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
- }
- return 1;
- }
- if ('CI' in env) {
- if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
- return 1;
- }
- return min;
- }
- if ('TEAMCITY_VERSION' in env) {
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
- }
- if (env.COLORTERM === 'truecolor') {
- return 3;
- }
- if ('TERM_PROGRAM' in env) {
- const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
- switch (env.TERM_PROGRAM) {
- case 'iTerm.app':
- return version >= 3 ? 3 : 2;
- case 'Apple_Terminal':
- return 2;
- // No default
- }
- }
- if (/-256(color)?$/i.test(env.TERM)) {
- return 2;
- }
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
- return 1;
- }
- if ('COLORTERM' in env) {
- return 1;
- }
- if (env.TERM === 'dumb') {
- return min;
- }
- return min;
- }
- function getSupportLevel(stream) {
- const level = supportsColor(stream);
- return translateLevel(level);
- }
- module.exports = {
- supportsColor: getSupportLevel,
- stdout: getSupportLevel(process.stdout),
- stderr: getSupportLevel(process.stderr)
- };
- /***/ }),
- /***/ "../ot-core/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js":
- /*!************************************************************************!*\
- !*** ../ot-core/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js ***!
- \************************************************************************/
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
- /**
- * Wrapper for built-in http.js to emulate the browser XMLHttpRequest object.
- *
- * This can be used with JS designed for browsers to improve reuse of code and
- * allow the use of existing libraries.
- *
- * Usage: include("XMLHttpRequest.js") and use XMLHttpRequest per W3C specs.
- *
- * @author Dan DeFelippi <dan@driverdan.com>
- * @contributor David Ellis <d.f.ellis@ieee.org>
- * @license MIT
- */
- var fs = __webpack_require__(/*! fs */ "fs");
- var Url = __webpack_require__(/*! url */ "url");
- var spawn = (__webpack_require__(/*! child_process */ "child_process").spawn);
- /**
- * Module exports.
- */
- module.exports = XMLHttpRequest;
- // backwards-compat
- XMLHttpRequest.XMLHttpRequest = XMLHttpRequest;
- /**
- * `XMLHttpRequest` constructor.
- *
- * Supported options for the `opts` object are:
- *
- * - `agent`: An http.Agent instance; http.globalAgent may be used; if 'undefined', agent usage is disabled
- *
- * @param {Object} opts optional "options" object
- */
- function XMLHttpRequest(opts) {
- "use strict";
- opts = opts || {};
- /**
- * Private variables
- */
- var self = this;
- var http = __webpack_require__(/*! http */ "http");
- var https = __webpack_require__(/*! https */ "https");
- // Holds http.js objects
- var request;
- var response;
- // Request settings
- var settings = {};
- // Disable header blacklist.
- // Not part of XHR specs.
- var disableHeaderCheck = false;
- // Set some default headers
- var defaultHeaders = {
- "User-Agent": "node-XMLHttpRequest",
- "Accept": "*/*"
- };
- var headers = Object.assign({}, defaultHeaders);
- // These headers are not user setable.
- // The following are allowed but banned in the spec:
- // * user-agent
- var forbiddenRequestHeaders = [
- "accept-charset",
- "accept-encoding",
- "access-control-request-headers",
- "access-control-request-method",
- "connection",
- "content-length",
- "content-transfer-encoding",
- "cookie",
- "cookie2",
- "date",
- "expect",
- "host",
- "keep-alive",
- "origin",
- "referer",
- "te",
- "trailer",
- "transfer-encoding",
- "upgrade",
- "via"
- ];
- // These request methods are not allowed
- var forbiddenRequestMethods = [
- "TRACE",
- "TRACK",
- "CONNECT"
- ];
- // Send flag
- var sendFlag = false;
- // Error flag, used when errors occur or abort is called
- var errorFlag = false;
- var abortedFlag = false;
- // Event listeners
- var listeners = {};
- /**
- * Constants
- */
- this.UNSENT = 0;
- this.OPENED = 1;
- this.HEADERS_RECEIVED = 2;
- this.LOADING = 3;
- this.DONE = 4;
- /**
- * Public vars
- */
- // Current state
- this.readyState = this.UNSENT;
- // default ready state change handler in case one is not set or is set late
- this.onreadystatechange = null;
- // Result & response
- this.responseText = "";
- this.responseXML = "";
- this.status = null;
- this.statusText = null;
- /**
- * Private methods
- */
- /**
- * Check if the specified header is allowed.
- *
- * @param string header Header to validate
- * @return boolean False if not allowed, otherwise true
- */
- var isAllowedHttpHeader = function(header) {
- return disableHeaderCheck || (header && forbiddenRequestHeaders.indexOf(header.toLowerCase()) === -1);
- };
- /**
- * Check if the specified method is allowed.
- *
- * @param string method Request method to validate
- * @return boolean False if not allowed, otherwise true
- */
- var isAllowedHttpMethod = function(method) {
- return (method && forbiddenRequestMethods.indexOf(method) === -1);
- };
- /**
- * Public methods
- */
- /**
- * Open the connection. Currently supports local server requests.
- *
- * @param string method Connection method (eg GET, POST)
- * @param string url URL for the connection.
- * @param boolean async Asynchronous connection. Default is true.
- * @param string user Username for basic authentication (optional)
- * @param string password Password for basic authentication (optional)
- */
- this.open = function(method, url, async, user, password) {
- this.abort();
- errorFlag = false;
- abortedFlag = false;
- // Check for valid request method
- if (!isAllowedHttpMethod(method)) {
- throw new Error("SecurityError: Request method not allowed");
- }
- settings = {
- "method": method,
- "url": url.toString(),
- "async": (typeof async !== "boolean" ? true : async),
- "user": user || null,
- "password": password || null
- };
- setState(this.OPENED);
- };
- /**
- * Disables or enables isAllowedHttpHeader() check the request. Enabled by default.
- * This does not conform to the W3C spec.
- *
- * @param boolean state Enable or disable header checking.
- */
- this.setDisableHeaderCheck = function(state) {
- disableHeaderCheck = state;
- };
- /**
- * Sets a header for the request.
- *
- * @param string header Header name
- * @param string value Header value
- * @return boolean Header added
- */
- this.setRequestHeader = function(header, value) {
- if (this.readyState != this.OPENED) {
- throw new Error("INVALID_STATE_ERR: setRequestHeader can only be called when state is OPEN");
- }
- if (!isAllowedHttpHeader(header)) {
- console.warn('Refused to set unsafe header "' + header + '"');
- return false;
- }
- if (sendFlag) {
- throw new Error("INVALID_STATE_ERR: send flag is true");
- }
- headers[header] = value;
- return true;
- };
- /**
- * Gets a header from the server response.
- *
- * @param string header Name of header to get.
- * @return string Text of the header or null if it doesn't exist.
- */
- this.getResponseHeader = function(header) {
- if (typeof header === "string"
- && this.readyState > this.OPENED
- && response.headers[header.toLowerCase()]
- && !errorFlag
- ) {
- return response.headers[header.toLowerCase()];
- }
- return null;
- };
- /**
- * Gets all the response headers.
- *
- * @return string A string with all response headers separated by CR+LF
- */
- this.getAllResponseHeaders = function() {
- if (this.readyState < this.HEADERS_RECEIVED || errorFlag) {
- return "";
- }
- var result = "";
- for (var i in response.headers) {
- // Cookie headers are excluded
- if (i !== "set-cookie" && i !== "set-cookie2") {
- result += i + ": " + response.headers[i] + "\r\n";
- }
- }
- return result.substr(0, result.length - 2);
- };
- /**
- * Gets a request header
- *
- * @param string name Name of header to get
- * @return string Returns the request header or empty string if not set
- */
- this.getRequestHeader = function(name) {
- // @TODO Make this case insensitive
- if (typeof name === "string" && headers[name]) {
- return headers[name];
- }
- return "";
- };
- /**
- * Sends the request to the server.
- *
- * @param string data Optional data to send as request body.
- */
- this.send = function(data) {
- if (this.readyState != this.OPENED) {
- throw new Error("INVALID_STATE_ERR: connection must be opened before send() is called");
- }
- if (sendFlag) {
- throw new Error("INVALID_STATE_ERR: send has already been called");
- }
- var ssl = false, local = false;
- var url = Url.parse(settings.url);
- var host;
- // Determine the server
- switch (url.protocol) {
- case 'https:':
- ssl = true;
- // SSL & non-SSL both need host, no break here.
- case 'http:':
- host = url.hostname;
- break;
- case 'file:':
- local = true;
- break;
- case undefined:
- case '':
- host = "localhost";
- break;
- default:
- throw new Error("Protocol not supported.");
- }
- // Load files off the local filesystem (file://)
- if (local) {
- if (settings.method !== "GET") {
- throw new Error("XMLHttpRequest: Only GET method is supported");
- }
- if (settings.async) {
- fs.readFile(unescape(url.pathname), 'utf8', function(error, data) {
- if (error) {
- self.handleError(error, error.errno || -1);
- } else {
- self.status = 200;
- self.responseText = data;
- setState(self.DONE);
- }
- });
- } else {
- try {
- this.responseText = fs.readFileSync(unescape(url.pathname), 'utf8');
- this.status = 200;
- setState(self.DONE);
- } catch(e) {
- this.handleError(e, e.errno || -1);
- }
- }
- return;
- }
- // Default to port 80. If accessing localhost on another port be sure
- // to use http://localhost:port/path
- var port = url.port || (ssl ? 443 : 80);
- // Add query string if one is used
- var uri = url.pathname + (url.search ? url.search : '');
- // Set the Host header or the server may reject the request
- headers["Host"] = host;
- if (!((ssl && port === 443) || port === 80)) {
- headers["Host"] += ':' + url.port;
- }
- // Set Basic Auth if necessary
- if (settings.user) {
- if (typeof settings.password == "undefined") {
- settings.password = "";
- }
- var authBuf = new Buffer(settings.user + ":" + settings.password);
- headers["Authorization"] = "Basic " + authBuf.toString("base64");
- }
- // Set content length header
- if (settings.method === "GET" || settings.method === "HEAD") {
- data = null;
- } else if (data) {
- headers["Content-Length"] = Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data);
- if (!headers["Content-Type"]) {
- headers["Content-Type"] = "text/plain;charset=UTF-8";
- }
- } else if (settings.method === "POST") {
- // For a post with no data set Content-Length: 0.
- // This is required by buggy servers that don't meet the specs.
- headers["Content-Length"] = 0;
- }
- var agent = opts.agent || false;
- var options = {
- host: host,
- port: port,
- path: uri,
- method: settings.method,
- headers: headers,
- agent: agent
- };
- if (ssl) {
- options.pfx = opts.pfx;
- options.key = opts.key;
- options.passphrase = opts.passphrase;
- options.cert = opts.cert;
- options.ca = opts.ca;
- options.ciphers = opts.ciphers;
- options.rejectUnauthorized = opts.rejectUnauthorized === false ? false : true;
- }
- // Reset error flag
- errorFlag = false;
- // Handle async requests
- if (settings.async) {
- // Use the proper protocol
- var doRequest = ssl ? https.request : http.request;
- // Request is being sent, set send flag
- sendFlag = true;
- // As per spec, this is called here for historical reasons.
- self.dispatchEvent("readystatechange");
- // Handler for the response
- var responseHandler = function(resp) {
- // Set response var to the response we got back
- // This is so it remains accessable outside this scope
- response = resp;
- // Check for redirect
- // @TODO Prevent looped redirects
- if (response.statusCode === 302 || response.statusCode === 303 || response.statusCode === 307) {
- // Change URL to the redirect location
- settings.url = response.headers.location;
- var url = Url.parse(settings.url);
- // Set host var in case it's used later
- host = url.hostname;
- // Options for the new request
- var newOptions = {
- hostname: url.hostname,
- port: url.port,
- path: url.path,
- method: response.statusCode === 303 ? 'GET' : settings.method,
- headers: headers
- };
- if (ssl) {
- newOptions.pfx = opts.pfx;
- newOptions.key = opts.key;
- newOptions.passphrase = opts.passphrase;
- newOptions.cert = opts.cert;
- newOptions.ca = opts.ca;
- newOptions.ciphers = opts.ciphers;
- newOptions.rejectUnauthorized = opts.rejectUnauthorized === false ? false : true;
- }
- // Issue the new request
- request = doRequest(newOptions, responseHandler).on('error', errorHandler);
- request.end();
- // @TODO Check if an XHR event needs to be fired here
- return;
- }
- if (response && response.setEncoding) {
- response.setEncoding("utf8");
- }
- setState(self.HEADERS_RECEIVED);
- self.status = response.statusCode;
- response.on('data', function(chunk) {
- // Make sure there's some data
- if (chunk) {
- self.responseText += chunk;
- }
- // Don't emit state changes if the connection has been aborted.
- if (sendFlag) {
- setState(self.LOADING);
- }
- });
- response.on('end', function() {
- if (sendFlag) {
- // The sendFlag needs to be set before setState is called. Otherwise if we are chaining callbacks
- // there can be a timing issue (the callback is called and a new call is made before the flag is reset).
- sendFlag = false;
- // Discard the 'end' event if the connection has been aborted
- setState(self.DONE);
- }
- });
- response.on('error', function(error) {
- self.handleError(error);
- });
- }
- // Error handler for the request
- var errorHandler = function(error) {
- self.handleError(error);
- }
- // Create the request
- request = doRequest(options, responseHandler).on('error', errorHandler);
- if (opts.autoUnref) {
- request.on('socket', (socket) => {
- socket.unref();
- });
- }
- // Node 0.4 and later won't accept empty data. Make sure it's needed.
- if (data) {
- request.write(data);
- }
- request.end();
- self.dispatchEvent("loadstart");
- } else { // Synchronous
- // Create a temporary file for communication with the other Node process
- var contentFile = ".node-xmlhttprequest-content-" + process.pid;
- var syncFile = ".node-xmlhttprequest-sync-" + process.pid;
- fs.writeFileSync(syncFile, "", "utf8");
- // The async request the other Node process executes
- var execString = "var http = require('http'), https = require('https'), fs = require('fs');"
- + "var doRequest = http" + (ssl ? "s" : "") + ".request;"
- + "var options = " + JSON.stringify(options) + ";"
- + "var responseText = '';"
- + "var req = doRequest(options, function(response) {"
- + "response.setEncoding('utf8');"
- + "response.on('data', function(chunk) {"
- + " responseText += chunk;"
- + "});"
- + "response.on('end', function() {"
- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-STATUS:' + response.statusCode + ',' + responseText, 'utf8');"
- + "fs.unlinkSync('" + syncFile + "');"
- + "});"
- + "response.on('error', function(error) {"
- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
- + "fs.unlinkSync('" + syncFile + "');"
- + "});"
- + "}).on('error', function(error) {"
- + "fs.writeFileSync('" + contentFile + "', 'NODE-XMLHTTPREQUEST-ERROR:' + JSON.stringify(error), 'utf8');"
- + "fs.unlinkSync('" + syncFile + "');"
- + "});"
- + (data ? "req.write('" + JSON.stringify(data).slice(1,-1).replace(/'/g, "\\'") + "');":"")
- + "req.end();";
- // Start the other Node Process, executing this string
- var syncProc = spawn(process.argv[0], ["-e", execString]);
- var statusText;
- while(fs.existsSync(syncFile)) {
- // Wait while the sync file is empty
- }
- self.responseText = fs.readFileSync(contentFile, 'utf8');
- // Kill the child process once the file has data
- syncProc.stdin.end();
- // Remove the temporary file
- fs.unlinkSync(contentFile);
- if (self.responseText.match(/^NODE-XMLHTTPREQUEST-ERROR:/)) {
- // If the file returned an error, handle it
- var errorObj = self.responseText.replace(/^NODE-XMLHTTPREQUEST-ERROR:/, "");
- self.handleError(errorObj, 503);
- } else {
- // If the file returned okay, parse its data and move to the DONE state
- self.status = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:([0-9]*),.*/, "$1");
- self.responseText = self.responseText.replace(/^NODE-XMLHTTPREQUEST-STATUS:[0-9]*,(.*)/, "$1");
- setState(self.DONE);
- }
- }
- };
- /**
- * Called when an error is encountered to deal with it.
- * @param status {number} HTTP status code to use rather than the default (0) for XHR errors.
- */
- this.handleError = function(error, status) {
- this.status = status || 0;
- this.statusText = error;
- this.responseText = error.stack;
- errorFlag = true;
- setState(this.DONE);
- };
- /**
- * Aborts a request.
- */
- this.abort = function() {
- if (request) {
- request.abort();
- request = null;
- }
- headers = Object.assign({}, defaultHeaders);
- this.responseText = "";
- this.responseXML = "";
- errorFlag = abortedFlag = true
- if (this.readyState !== this.UNSENT
- && (this.readyState !== this.OPENED || sendFlag)
- && this.readyState !== this.DONE) {
- sendFlag = false;
- setState(this.DONE);
- }
- this.readyState = this.UNSENT;
- };
- /**
- * Adds an event listener. Preferred method of binding to events.
- */
- this.addEventListener = function(event, callback) {
- if (!(event in listeners)) {
- listeners[event] = [];
- }
- // Currently allows duplicate callbacks. Should it?
- listeners[event].push(callback);
- };
- /**
- * Remove an event callback that has already been bound.
- * Only works on the matching funciton, cannot be a copy.
- */
- this.removeEventListener = function(event, callback) {
- if (event in listeners) {
- // Filter will return a new array with the callback removed
- listeners[event] = listeners[event].filter(function(ev) {
- return ev !== callback;
- });
- }
- };
- /**
- * Dispatch any events, including both "on" methods and events attached using addEventListener.
- */
- this.dispatchEvent = function(event) {
- if (typeof self["on" + event] === "function") {
- if (this.readyState === this.DONE)
- setImmediate(function() { self["on" + event]() })
- else
- self["on" + event]()
- }
- if (event in listeners) {
- for (let i = 0, len = listeners[event].length; i < len; i++) {
- if (this.readyState === this.DONE)
- setImmediate(function() { listeners[event][i].call(self) })
- else
- listeners[event][i].call(self)
- }
- }
- };
- /**
- * Changes readyState and calls onreadystatechange.
- *
- * @param int state New state
- */
- var setState = function(state) {
- if ((self.readyState === state) || (self.readyState === self.UNSENT && abortedFlag))
- return
- self.readyState = state;
- if (settings.async || self.readyState < self.OPENED || self.readyState === self.DONE) {
- self.dispatchEvent("readystatechange");
- }
- if (self.readyState === self.DONE) {
- let fire
- if (abortedFlag)
- fire = "abort"
- else if (errorFlag)
- fire = "error"
- else
- fire = "load"
- self.dispatchEvent(fire)
- // @TODO figure out InspectorInstrumentation::didLoadXHR(cookie)
- self.dispatchEvent("loadend");
- }
- };
- };
- /***/ }),
- /***/ "../ot-core/node_modules/yeast/index.js":
- /*!**********************************************!*\
- !*** ../ot-core/node_modules/yeast/index.js ***!
- \**********************************************/
- /***/ ((module) => {
- "use strict";
- var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
- , length = 64
- , map = {}
- , seed = 0
- , i = 0
- , prev;
- /**
- * Return a string representing the specified number.
- *
- * @param {Number} num The number to convert.
- * @returns {String} The string representation of the number.
- * @api public
- */
- function encode(num) {
- var encoded = '';
- do {
- encoded = alphabet[num % length] + encoded;
- num = Math.floor(num / length);
- } while (num > 0);
- return encoded;
- }
- /**
- * Return the integer value specified by the given string.
- *
- * @param {String} str The string to convert.
- * @returns {Number} The integer value represented by the string.
- * @api public
- */
- function decode(str) {
- var decoded = 0;
- for (i = 0; i < str.length; i++) {
- decoded = decoded * length + map[str.charAt(i)];
- }
- return decoded;
- }
- /**
- * Yeast: A tiny growing id generator.
- *
- * @returns {String} A unique id.
- * @api public
- */
- function yeast() {
- var now = encode(+new Date());
- if (now !== prev) return seed = 0, prev = now;
- return now +'.'+ encode(seed++);
- }
- //
- // Map each character to its index.
- //
- for (; i < length; i++) map[alphabet[i]] = i;
- //
- // Expose the `yeast`, `encode` and `decode` functions.
- //
- yeast.encode = encode;
- yeast.decode = decode;
- module.exports = yeast;
- /***/ }),
- /***/ "../ot-core/src/basics/Command.ts":
- /*!****************************************!*\
- !*** ../ot-core/src/basics/Command.ts ***!
- \****************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Command = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class Command {
- constructor(...parameter) {
- this._describe = 'Command';
- if (internal_1.TransformUtils.hasLength(parameter, 0)) {
- this._groupId = 'default';
- this._operation = [];
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- if (internal_1.TransformUtils.isString(parameter[0])) {
- const groupId = parameter[0];
- this._operation = [];
- this._groupId = groupId;
- return;
- }
- if (internal_1.TransformUtils.isObject(parameter[0])) {
- const serialize = parameter[0];
- this._groupId = serialize.groupId;
- this._operation = internal_1.Deserialize.getInstance().formArray(serialize.operation);
- return;
- }
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const groupId = parameter[0];
- const operation = parameter[1];
- this._groupId = groupId;
- this._operation = operation;
- }
- }
- concat(target) {
- const result = new Command({
- groupId: this._groupId,
- describe: this._describe,
- operation: []
- });
- result._operation = this._operation.concat(target._operation);
- return result;
- }
- apply(resource) {
- const operations = this._operation;
- const sizeof = operations.length;
- for (let i = 0; i < sizeof; i++) {
- const action = operations[i];
- action.apply(resource);
- }
- }
- getOperations() {
- return this._operation;
- }
- getGroupId() {
- return this._groupId;
- }
- addOperation(operation) {
- this._operation.push(operation);
- }
- toJSON() {
- return {
- describe: this._describe,
- groupId: this._groupId,
- operation: this._operation.map(o => o.toJSON())
- };
- }
- }
- exports.Command = Command;
- /***/ }),
- /***/ "../ot-core/src/basics/Conflict.ts":
- /*!*****************************************!*\
- !*** ../ot-core/src/basics/Conflict.ts ***!
- \*****************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Conflict = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class Conflict {
- constructor() {
- this._conflict = new Array();
- }
- get(targetOperation, savedOperation) {
- const _conflict = this._conflict;
- const sizeof = _conflict.length;
- for (let i = 0; i < sizeof; i++) {
- const wrapped = _conflict[i];
- const targetFrom = internal_1.TransformUtils.isAssignableFrom(targetOperation, wrapped.targetClass);
- const savedFrom = internal_1.TransformUtils.isAssignableFrom(savedOperation, wrapped.savedClass);
- if (targetFrom && savedFrom) {
- return wrapped;
- }
- }
- return null;
- }
- add(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const wrapped = parameter[0];
- this._conflict.push(wrapped);
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 3)) {
- const targetClass = parameter[0];
- const savedClass = parameter[1];
- const process = parameter[2];
- this._conflict.push({
- targetClass,
- savedClass,
- process
- });
- }
- }
- }
- exports.Conflict = Conflict;
- /***/ }),
- /***/ "../ot-core/src/basics/Deserialize.ts":
- /*!********************************************!*\
- !*** ../ot-core/src/basics/Deserialize.ts ***!
- \********************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Deserialize = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- let singleton;
- class Deserialize {
- constructor() {
- this._storage = new Map();
- }
- static getInstance() {
- if (!internal_1.TransformUtils.isDefine(singleton)) {
- singleton = new Deserialize();
- singleton.addClass('SwapData', internal_1.SwapData);
- singleton.addClass('Command', internal_1.Command);
- }
- return singleton;
- }
- formArray(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const object = parameter[0];
- const length = object.length;
- const result = new Array();
- for (let i = 0; i < length; i++) {
- result.push(this.convert(object[i]));
- }
- return result;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const object = parameter[0];
- const defaultValue = parameter[1];
- if (internal_1.TransformUtils.isDefine(object)) {
- const length = object.length;
- const result = new Array();
- for (let i = 0; i < length; i++) {
- result.push(this.convert(object[i]));
- }
- return result;
- }
- return defaultValue;
- }
- }
- formObject(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const object = parameter[0];
- return this.convert(object);
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const object = parameter[0];
- const defaultValue = parameter[1];
- if (internal_1.TransformUtils.isDefine(object)) {
- return this.convert(object);
- }
- return defaultValue;
- }
- }
- convert(value) {
- if (internal_1.TransformUtils.isDefine(value.describe)) {
- return this.newInstance(value.describe, value);
- }
- return value;
- }
- addClass(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const clazz = parameter[0];
- this._storage.set(clazz.name, clazz);
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const name = parameter[0];
- const clazz = parameter[1];
- this._storage.set(name, clazz);
- }
- }
- newInstance(name, desc) {
- const constructor = this.getClass(name);
- return new constructor(desc);
- }
- getClass(name) {
- const element = this._storage.get(name);
- if (internal_1.TransformUtils.isDefine(element)) {
- return element;
- }
- throw new Error(`not find ${name} Class`);
- }
- }
- exports.Deserialize = Deserialize;
- /***/ }),
- /***/ "../ot-core/src/basics/Operation.ts":
- /*!******************************************!*\
- !*** ../ot-core/src/basics/Operation.ts ***!
- \******************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- /***/ }),
- /***/ "../ot-core/src/basics/SwapData.ts":
- /*!*****************************************!*\
- !*** ../ot-core/src/basics/SwapData.ts ***!
- \*****************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.SwapData = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class SwapData {
- constructor(...parameter) {
- this._describe = 'SwapData';
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- this._data = parameter[0].data;
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 0)) {
- this._data = null;
- }
- }
- setData(_data) {
- this._data = _data;
- }
- getData() {
- return this._data;
- }
- clone() {
- return this;
- }
- toJSON() {
- return {
- describe: this._describe,
- data: this._data
- };
- }
- }
- exports.SwapData = SwapData;
- /***/ }),
- /***/ "../ot-core/src/basics/Transform.ts":
- /*!******************************************!*\
- !*** ../ot-core/src/basics/Transform.ts ***!
- \******************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Transform = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class Transform {
- constructor(_conflict) {
- this._conflict = _conflict;
- }
- transfer(targetCommand, savedCommand) {
- const conflict = this._conflict;
- const targetOperations = targetCommand.getOperations();
- const savedOperations = savedCommand.getOperations();
- const sizeof1 = targetOperations.length;
- const sizeof2 = savedOperations.length;
- const newTargetCommand = new internal_1.Command({
- groupId: targetCommand.getGroupId(),
- operation: [],
- describe: 'Command'
- });
- const newSavedCommand = new internal_1.Command({
- groupId: targetCommand.getGroupId(),
- operation: [],
- describe: 'Command'
- });
- for (let i = 0; i < sizeof1; i++) {
- const targetOperation = targetOperations[i];
- for (let j = 0; j < sizeof2; j++) {
- const savedOperation = savedOperations[j];
- const wrapped = conflict.get(targetOperation, savedOperation);
- if (wrapped != null) {
- const transfer = wrapped.process(newTargetCommand, newSavedCommand);
- transfer(targetOperation.clone(), savedOperation.clone());
- continue;
- }
- throw new Error('not found _conflict process');
- }
- }
- return [newTargetCommand, newSavedCommand];
- }
- }
- exports.Transform = Transform;
- /***/ }),
- /***/ "../ot-core/src/client/AwaitingConfirm.ts":
- /*!************************************************!*\
- !*** ../ot-core/src/client/AwaitingConfirm.ts ***!
- \************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.AwaitingConfirm = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class AwaitingConfirm {
- constructor(outstanding) {
- this._outstanding = outstanding;
- }
- applyClient(client, command) {
- return new internal_1.AwaitingWithBuffer(this._outstanding, command);
- }
- serverAck(client) {
- return internal_1.Synchronized.DEFAULT;
- }
- applyServer(client, command) {
- const outstanding = this._outstanding;
- const pair = client.getTransform().transfer(outstanding, command);
- client.applyCommand(pair[1]);
- return new AwaitingConfirm(pair[0]);
- }
- resend(client) {
- client.sendCommand(client.getRevision(), this._outstanding);
- }
- }
- exports.AwaitingConfirm = AwaitingConfirm;
- /***/ }),
- /***/ "../ot-core/src/client/AwaitingWithBuffer.ts":
- /*!***************************************************!*\
- !*** ../ot-core/src/client/AwaitingWithBuffer.ts ***!
- \***************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.AwaitingWithBuffer = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class AwaitingWithBuffer {
- constructor(outstanding, buffer) {
- this._outstanding = outstanding;
- this._buffer = buffer;
- }
- applyClient(client, command) {
- let newBuffer = this._buffer.concat(command);
- return new AwaitingWithBuffer(this._outstanding, newBuffer);
- }
- serverAck(client) {
- client.sendCommand(client.getRevision(), this._buffer);
- return new internal_1.AwaitingConfirm(this._buffer);
- }
- applyServer(client, command) {
- const outstanding = this._outstanding;
- const buffer = this._buffer;
- const pair1 = client.getTransform().transfer(outstanding, command);
- const pair2 = client.getTransform().transfer(buffer, pair1[1]);
- client.applyCommand(pair2[1]);
- return new AwaitingWithBuffer(pair1[0], pair2[0]);
- }
- resend(client) {
- client.sendCommand(client.getRevision(), this._outstanding);
- }
- }
- exports.AwaitingWithBuffer = AwaitingWithBuffer;
- /***/ }),
- /***/ "../ot-core/src/client/Client.ts":
- /*!***************************************!*\
- !*** ../ot-core/src/client/Client.ts ***!
- \***************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Client = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class Client {
- constructor(conflict) {
- this._revision = 0;
- this._transform = new internal_1.Transform(conflict);
- this._status = internal_1.Synchronized.DEFAULT;
- this._undoManager = new internal_1.UndoManager(this._transform);
- }
- applyClient(command) {
- this._status = this._status.applyClient(this, command);
- }
- serverAck() {
- this._revision++;
- this._status = this._status.serverAck(this);
- }
- applyServer(command) {
- this._revision++;
- this._status = this._status.applyServer(this, command);
- }
- serverReconnect() {
- this._status.resend(this);
- }
- getTransform() {
- return this._transform;
- }
- getRevision() {
- return this._revision;
- }
- getUndoManager() {
- return this._undoManager;
- }
- }
- exports.Client = Client;
- /***/ }),
- /***/ "../ot-core/src/client/ClientSocket.ts":
- /*!*********************************************!*\
- !*** ../ot-core/src/client/ClientSocket.ts ***!
- \*********************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.ClientSocket = void 0;
- const socket_io_client_1 = __webpack_require__(/*! socket.io-client */ "../ot-core/node_modules/socket.io-client/build/cjs/index.js");
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class ClientSocket extends internal_1.Client {
- constructor(config) {
- super(config.conflict);
- this._config = config;
- this._socket = (0, socket_io_client_1.io)(config.url);
- this._execute = () => {};
- this._initializeListener();
- this._initializeSocket();
- }
- _initializeListener() {
- const observer = this._undoManager.getObserver();
- observer.addOnAddRedoListener({
- onAddRedo: wrapped => {
- wrapped.redo.apply(this._source);
- this.applyClient(wrapped.redo);
- }
- });
- observer.addOnAddUndoListener({
- onAddUndo: wrapped => {
- wrapped.undo.apply(this._source);
- this.applyClient(wrapped.undo);
- }
- });
- }
- _initializeSocket() {
- this._socket.on('open', response => {
- this._revision = response.revision;
- this._users = response.users;
- this._source = response.source;
- this._roomId = response.roomId;
- this._execute();
- });
- this._socket.on('ack', () => {
- this.serverAck();
- });
- this._socket.on('command', (clientId, command) => {
- const deserialize = internal_1.Deserialize.getInstance().formObject(command);
- this.applyServer(deserialize);
- });
- this._socket.on('reconnect', () => {
- this.serverReconnect();
- });
- }
- ready(execute) {
- this._execute = execute;
- }
- sendCommand(revision, command) {
- this._socket.emit('command', revision, command.toJSON());
- }
- applyCommand(command) {
- command.apply(this._source);
- this._undoManager.transform(command);
- }
- }
- exports.ClientSocket = ClientSocket;
- /***/ }),
- /***/ "../ot-core/src/client/Synchronized.ts":
- /*!*********************************************!*\
- !*** ../ot-core/src/client/Synchronized.ts ***!
- \*********************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Synchronized = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class Synchronized {
- applyClient(client, command) {
- client.sendCommand(client.getRevision(), command);
- return new internal_1.AwaitingConfirm(command);
- }
- serverAck(client) {
- throw new Error("There is no pending operated.");
- }
- applyServer(client, command) {
- client.applyCommand(command);
- return this;
- }
- resend(client) {}
- }
- exports.Synchronized = Synchronized;
- Synchronized.DEFAULT = new Synchronized();
- /***/ }),
- /***/ "../ot-core/src/client/UndoManager.ts":
- /*!********************************************!*\
- !*** ../ot-core/src/client/UndoManager.ts ***!
- \********************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.UndoManager = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class UndoManager {
- constructor(transform) {
- this._redoStack = [];
- this._undoStack = [];
- this._transform = transform;
- this._observer = new internal_1.UndoManagerObserver();
- }
- _transformStack(stack, command) {
- const transform = this._transform;
- const sizeof = stack.length - 1;
- let redoCommand = command;
- let undoCommand = command;
- for (let i = sizeof; i >= 0; i--) {
- const pair1 = transform.transfer(stack[i].redo, redoCommand);
- const pair2 = transform.transfer(stack[i].undo, undoCommand);
- stack[i].redo = pair1[0];
- stack[i].undo = pair2[0];
- redoCommand = pair1[1];
- undoCommand = pair2[1];
- }
- }
- transform(command) {
- this._transformStack(this._undoStack, command);
- this._transformStack(this._redoStack, command);
- }
- canUndo() {
- return this._undoStack.length !== 0;
- }
- canRedo() {
- return this._redoStack.length !== 0;
- }
- addRedo(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const wrapped = parameter[0];
- this._redoStack.push(wrapped);
- this._observer.dispatchOnAddRedo(wrapped);
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const redo = parameter[0];
- const undo = parameter[1];
- const wrapped = {
- redo,
- undo
- };
- this._redoStack.push(wrapped);
- this._observer.dispatchOnAddRedo(wrapped);
- }
- }
- addUndo(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const wrapped = parameter[0];
- this._undoStack.push(wrapped);
- this._observer.dispatchOnAddUndo(wrapped);
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const redo = parameter[0];
- const undo = parameter[1];
- const wrapped = {
- redo,
- undo
- };
- this._undoStack.push(wrapped);
- this._observer.dispatchOnAddUndo(wrapped);
- }
- }
- performCommand(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const wrapped = parameter[0];
- this.addRedo(wrapped);
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const redo = parameter[0];
- const undo = parameter[1];
- const wrapped = {
- redo,
- undo
- };
- this.addRedo(wrapped);
- }
- }
- performRedo() {
- if (this.canRedo()) {
- const wrapped = this._redoStack.pop();
- this.addUndo(wrapped);
- this._observer.dispatchOnRedo(wrapped);
- }
- }
- performUndo() {
- if (this.canUndo()) {
- const wrapped = this._undoStack.pop();
- this.addRedo(wrapped);
- this._observer.dispatchOnUndo(wrapped);
- }
- }
- getObserver() {
- return this._observer;
- }
- }
- exports.UndoManager = UndoManager;
- /***/ }),
- /***/ "../ot-core/src/client/UndoManagerObserver.ts":
- /*!****************************************************!*\
- !*** ../ot-core/src/client/UndoManagerObserver.ts ***!
- \****************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.UndoManagerObserver = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class UndoManagerObserver {
- dispatchOnAddRedo(wrapped) {
- let listeners = this._onAddRedoListeners;
- if (listeners != null) {
- const sizeof = listeners.sizeof();
- for (let i = 0; i < sizeof; i++) {
- const listener = listeners.get(i);
- listener.onAddRedo(wrapped);
- }
- }
- }
- dispatchOnAddUndo(wrapped) {
- let listeners = this._onAddUndoListeners;
- if (listeners != null) {
- const sizeof = listeners.sizeof();
- for (let i = 0; i < sizeof; i++) {
- const listener = listeners.get(i);
- listener.onAddUndo(wrapped);
- }
- }
- }
- dispatchOnRedo(wrapped) {
- let listeners = this._onRedoListeners;
- if (listeners != null) {
- const sizeof = listeners.sizeof();
- for (let i = 0; i < sizeof; i++) {
- const listener = listeners.get(i);
- listener.onRedo(wrapped);
- }
- }
- }
- dispatchOnUndo(wrapped) {
- let listeners = this._onUndoListeners;
- if (listeners != null) {
- const sizeof = listeners.sizeof();
- for (let i = 0; i < sizeof; i++) {
- const listener = listeners.get(i);
- listener.onUndo(wrapped);
- }
- }
- }
- addOnAddRedoListener(listener) {
- if (this._onAddRedoListeners == null) {
- this._onAddRedoListeners = new internal_1.ArrayList();
- }
- this._onAddRedoListeners.add(listener);
- }
- addOnAddUndoListener(listener) {
- if (this._onAddUndoListeners == null) {
- this._onAddUndoListeners = new internal_1.ArrayList();
- }
- this._onAddUndoListeners.add(listener);
- }
- addOnRedoListener(listener) {
- if (this._onRedoListeners == null) {
- this._onRedoListeners = new internal_1.ArrayList();
- }
- this._onRedoListeners.add(listener);
- }
- addOnUndoListener(listener) {
- if (this._onUndoListeners == null) {
- this._onUndoListeners = new internal_1.ArrayList();
- }
- this._onUndoListeners.add(listener);
- }
- removeOnAddRedoListener(listener) {
- if (this._onAddRedoListeners == null) {
- return;
- }
- this._onAddRedoListeners.remove(listener);
- }
- removeOnAddUndoListener(listener) {
- if (this._onAddUndoListeners == null) {
- return;
- }
- this._onAddUndoListeners.remove(listener);
- }
- removeOnUndoListener(listener) {
- if (this._onUndoListeners == null) {
- return;
- }
- this._onUndoListeners.remove(listener);
- }
- removeOnRedoListener(listener) {
- if (this._onRedoListeners == null) {
- return;
- }
- this._onRedoListeners.remove(listener);
- }
- }
- exports.UndoManagerObserver = UndoManagerObserver;
- /***/ }),
- /***/ "../ot-core/src/config/ClientSocketConfig.ts":
- /*!***************************************************!*\
- !*** ../ot-core/src/config/ClientSocketConfig.ts ***!
- \***************************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.ClientSocketConfig = void 0;
- class ClientSocketConfig {}
- exports.ClientSocketConfig = ClientSocketConfig;
- /***/ }),
- /***/ "../ot-core/src/index.ts":
- /*!*******************************!*\
- !*** ../ot-core/src/index.ts ***!
- \*******************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, {
- enumerable: true,
- get: function () {
- return m[k];
- }
- });
- } : function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- });
- var __exportStar = this && this.__exportStar || function (m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- };
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- __exportStar(__webpack_require__(/*! ./internal */ "../ot-core/src/internal.ts"), exports);
- /***/ }),
- /***/ "../ot-core/src/internal.ts":
- /*!**********************************!*\
- !*** ../ot-core/src/internal.ts ***!
- \**********************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- // ================================================= typed
- var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, {
- enumerable: true,
- get: function () {
- return m[k];
- }
- });
- } : function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- });
- var __exportStar = this && this.__exportStar || function (m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- };
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- __exportStar(__webpack_require__(/*! ./typed/GlobalType */ "../ot-core/src/typed/GlobalType.ts"), exports); // ================================================= utils
- __exportStar(__webpack_require__(/*! ./utils/ArrayUtils */ "../ot-core/src/utils/ArrayUtils.ts"), exports);
- __exportStar(__webpack_require__(/*! ./utils/TransformUtils */ "../ot-core/src/utils/TransformUtils.ts"), exports); // ================================================= config
- __exportStar(__webpack_require__(/*! ./config/ClientSocketConfig */ "../ot-core/src/config/ClientSocketConfig.ts"), exports); // ================================================= library
- __exportStar(__webpack_require__(/*! ./library/ArrayList */ "../ot-core/src/library/ArrayList.ts"), exports); // ================================================= basics
- __exportStar(__webpack_require__(/*! ./basics/Command */ "../ot-core/src/basics/Command.ts"), exports);
- __exportStar(__webpack_require__(/*! ./basics/Operation */ "../ot-core/src/basics/Operation.ts"), exports);
- __exportStar(__webpack_require__(/*! ./basics/Conflict */ "../ot-core/src/basics/Conflict.ts"), exports);
- __exportStar(__webpack_require__(/*! ./basics/Transform */ "../ot-core/src/basics/Transform.ts"), exports);
- __exportStar(__webpack_require__(/*! ./basics/SwapData */ "../ot-core/src/basics/SwapData.ts"), exports);
- __exportStar(__webpack_require__(/*! ./basics/Deserialize */ "../ot-core/src/basics/Deserialize.ts"), exports); // ================================================= client
- __exportStar(__webpack_require__(/*! ./client/UndoManager */ "../ot-core/src/client/UndoManager.ts"), exports);
- __exportStar(__webpack_require__(/*! ./client/AwaitingConfirm */ "../ot-core/src/client/AwaitingConfirm.ts"), exports);
- __exportStar(__webpack_require__(/*! ./client/Synchronized */ "../ot-core/src/client/Synchronized.ts"), exports);
- __exportStar(__webpack_require__(/*! ./client/AwaitingWithBuffer */ "../ot-core/src/client/AwaitingWithBuffer.ts"), exports);
- __exportStar(__webpack_require__(/*! ./client/UndoManagerObserver */ "../ot-core/src/client/UndoManagerObserver.ts"), exports);
- __exportStar(__webpack_require__(/*! ./client/Client */ "../ot-core/src/client/Client.ts"), exports);
- __exportStar(__webpack_require__(/*! ./client/ClientSocket */ "../ot-core/src/client/ClientSocket.ts"), exports); // ================================================= server
- __exportStar(__webpack_require__(/*! ./server/Response */ "../ot-core/src/server/Response.ts"), exports);
- __exportStar(__webpack_require__(/*! ./server/User */ "../ot-core/src/server/User.ts"), exports);
- __exportStar(__webpack_require__(/*! ./server/Server */ "../ot-core/src/server/Server.ts"), exports);
- __exportStar(__webpack_require__(/*! ./server/ServerSocket */ "../ot-core/src/server/ServerSocket.ts"), exports);
- /***/ }),
- /***/ "../ot-core/src/library/ArrayList.ts":
- /*!*******************************************!*\
- !*** ../ot-core/src/library/ArrayList.ts ***!
- \*******************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.ArrayList = void 0;
- const TransformUtils_1 = __webpack_require__(/*! ../utils/TransformUtils */ "../ot-core/src/utils/TransformUtils.ts");
- class ArrayList {
- constructor() {
- this._arraylist = new Array();
- }
- get(index) {
- return this._arraylist[index];
- }
- sizeof() {
- return this._arraylist.length;
- }
- add(value) {
- this._arraylist.push(value);
- }
- remove(...parameter) {
- if (TransformUtils_1.TransformUtils.hasLength(parameter, 1)) {
- if (TransformUtils_1.TransformUtils.isNumber(parameter[0])) {
- const index = parameter[0];
- this._arraylist.splice(index, 1);
- return;
- }
- if (TransformUtils_1.TransformUtils.isObject(parameter[0])) {
- const value = parameter[0];
- const arraylist = this._arraylist;
- const sizeof = arraylist.length;
- for (let i = 0; i < sizeof; i++) {
- const item = arraylist[i];
- if (item === value) {
- this._arraylist.splice(i, 1);
- return;
- }
- }
- }
- }
- }
- }
- exports.ArrayList = ArrayList;
- /***/ }),
- /***/ "../ot-core/src/server/Response.ts":
- /*!*****************************************!*\
- !*** ../ot-core/src/server/Response.ts ***!
- \*****************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- /***/ }),
- /***/ "../ot-core/src/server/Server.ts":
- /*!***************************************!*\
- !*** ../ot-core/src/server/Server.ts ***!
- \***************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Server = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class Server {
- constructor(conflict) {
- this._chronicle = new Array();
- this._transform = new internal_1.Transform(conflict);
- }
- receiveCommand(revision, command) {
- if (revision < 0 || this._chronicle.length < revision) {
- throw new Error("command revision not in history");
- }
- let history = this._chronicle.slice(revision);
- for (let i = 0; i < history.length; i++) {
- const saved = history[i];
- if (command.getGroupId() === saved.getGroupId()) {
- command = this._transform.transfer(command, saved)[0];
- }
- }
- this._chronicle.push(command);
- }
- getRevision() {
- return this._chronicle.length;
- }
- }
- exports.Server = Server;
- /***/ }),
- /***/ "../ot-core/src/server/ServerSocket.ts":
- /*!*********************************************!*\
- !*** ../ot-core/src/server/ServerSocket.ts ***!
- \*********************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.ServerSocket = void 0;
- const internal_1 = __webpack_require__(/*! ../internal */ "../ot-core/src/internal.ts");
- class ServerSocket extends internal_1.Server {
- constructor(...parameter) {
- if (internal_1.TransformUtils.hasLength(parameter, 1)) {
- const conflict = parameter[0];
- super(conflict);
- this._roomId = 'empty';
- this._users = [];
- this._source = null;
- return;
- }
- if (internal_1.TransformUtils.hasLength(parameter, 2)) {
- const conflict = parameter[0];
- const source = parameter[1];
- super(conflict);
- this._roomId = 'empty';
- this._users = [];
- this._source = source;
- }
- }
- receiveCommand(revision, command) {
- super.receiveCommand(revision, command);
- command.apply(this._source);
- }
- addSocketClient(client) {
- client.join(this._roomId);
- client.on('command', (revision, command) => {
- this.onCommand(client, revision, command);
- });
- client.on('disconnect', () => {
- this.onDisconnect(client);
- });
- client.emit('open', {
- revision: this.getRevision(),
- clients: this._users,
- roomId: this._roomId,
- source: this._source
- });
- }
- onCommand(client, revision, command) {
- const deserialize = internal_1.Deserialize.getInstance().formObject(command);
- let clientId = client.id;
- this.receiveCommand(revision, deserialize);
- client.emit('ack');
- client.broadcast.in(this._roomId).emit('command', clientId, deserialize.toJSON());
- }
- onDisconnect(client) {
- console.log('Disconnect');
- }
- }
- exports.ServerSocket = ServerSocket;
- /***/ }),
- /***/ "../ot-core/src/server/User.ts":
- /*!*************************************!*\
- !*** ../ot-core/src/server/User.ts ***!
- \*************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.User = void 0;
- class User {}
- exports.User = User;
- /***/ }),
- /***/ "../ot-core/src/typed/GlobalType.ts":
- /*!******************************************!*\
- !*** ../ot-core/src/typed/GlobalType.ts ***!
- \******************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- /***/ }),
- /***/ "../ot-core/src/utils/ArrayUtils.ts":
- /*!******************************************!*\
- !*** ../ot-core/src/utils/ArrayUtils.ts ***!
- \******************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.ArrayUtils = void 0;
- class ArrayUtils {}
- exports.ArrayUtils = ArrayUtils;
- /***/ }),
- /***/ "../ot-core/src/utils/TransformUtils.ts":
- /*!**********************************************!*\
- !*** ../ot-core/src/utils/TransformUtils.ts ***!
- \**********************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.TransformUtils = void 0;
- class TransformUtils {
- static getValueType(value) {
- return Object.prototype.toString.apply(value);
- }
- static isBoolean(value) {
- return this.getValueType(value) === '[object Boolean]';
- }
- static isString(value) {
- return this.getValueType(value) === '[object String]';
- }
- static isFunction(value) {
- return this.getValueType(value) === '[object Function]';
- }
- static isNumber(value) {
- return this.getValueType(value) === '[object Number]';
- }
- static isDefine(value) {
- return value !== undefined && value !== null;
- }
- static unDefine(value) {
- return value === undefined || value === null;
- }
- static isBlank(value) {
- if (!this.isDefine(value)) {
- return true;
- }
- if (this.isString(value)) {
- return value.trim() === '';
- }
- return false;
- }
- static isConstructor(clazz) {
- return clazz.prototype.constructor === clazz;
- }
- static isAssignableFrom(object, clazz) {
- return object instanceof clazz;
- }
- static isObject(value) {
- return this.getValueType(value) === '[object Object]';
- }
- static isPlainObject(value) {
- if (!this.isDefine(value)) {
- return false;
- }
- return Object.getPrototypeOf(value) === Object.getPrototypeOf({});
- }
- static isArray(value, clazz) {
- let type = this.getValueType(value) === '[object Array]';
- if (type) {
- if (TransformUtils.isDefine(clazz)) {
- value = value;
- if (value.length) {
- return value[0] instanceof clazz;
- }
- }
- return true;
- }
- return false;
- }
- static copy(src, target) {
- Object.assign(src, target);
- }
- static hasLength(target, length) {
- return target.length === length;
- }
- }
- exports.TransformUtils = TransformUtils;
- /***/ }),
- /***/ "./src/basics/Bootstrap.ts":
- /*!*********************************!*\
- !*** ./src/basics/Bootstrap.ts ***!
- \*********************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
- var internal_1 = __webpack_require__(/*! ../internal */ "./src/internal.ts");
- var deserialize = ot_core_1.Deserialize.getInstance();
- deserialize.addClass('InsertColumn', internal_1.InsertColumn);
- deserialize.addClass('InsertRow', internal_1.InsertRow);
- deserialize.addClass('RemoveColumn', internal_1.RemoveColumn);
- deserialize.addClass('RemoveRow', internal_1.RemoveRow);
- /***/ }),
- /***/ "./src/basics/CreateConflict.ts":
- /*!**************************************!*\
- !*** ./src/basics/CreateConflict.ts ***!
- \**************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.CreateConflict = void 0;
- var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
- var internal_1 = __webpack_require__(/*! ../internal */ "./src/internal.ts");
- function CreateConflict() {
- var conflict = new ot_core_1.Conflict();
- conflict.add(internal_1.InsertRow, internal_1.InsertRow, function (targetCommand, savedCommand) {
- return function (targetOperation, savedOperation) {
- /**
- * 服务端插入的行在当前行的下方
- */
- if (targetOperation.getHeight() <= savedOperation.getIndex()) {
- var offset = savedOperation.getIndex() + targetOperation.getCount();
- savedOperation.setIndex(savedOperation.getIndex() + offset);
- targetCommand.addOperation(targetOperation);
- savedCommand.addOperation(savedOperation);
- }
- /**
- * 服务端插入的行在当前行的上方
- */
- if (targetOperation.getIndex() >= savedOperation.getHeight()) {
- var _offset = targetOperation.getIndex() + savedOperation.getCount();
- targetOperation.setIndex(targetOperation.getIndex() + _offset);
- targetCommand.addOperation(targetOperation);
- savedCommand.addOperation(savedOperation);
- }
- /**
- * 服务端插入的行被当前行包含
- */
- if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() >= savedOperation.getHeight()) {
- var spliceCursor = savedOperation.getIndex() - targetOperation.getIndex();
- var prevDataBuffer = targetOperation.getBuffer().getData().splice(0, spliceCursor);
- var nextDataBuffer = targetOperation.getBuffer().getData().splice(spliceCursor);
- var prevOperation = new internal_1.InsertRow({
- describe: 'InsertRowOperation',
- buffer: new ot_core_1.SwapData({
- data: prevDataBuffer,
- describe: 'DataBuffer'
- }),
- index: targetOperation.getIndex(),
- count: savedOperation.getIndex() - targetOperation.getIndex()
- });
- var nextOperation = new internal_1.InsertRow({
- describe: 'InsertRowOperation',
- buffer: new ot_core_1.SwapData({
- data: nextDataBuffer,
- describe: 'DataBuffer'
- }),
- index: savedOperation.getCount(),
- count: targetOperation.getHeight() - savedOperation.getIndex()
- });
- targetCommand.addOperation(prevOperation);
- targetCommand.addOperation(nextOperation);
- }
- /**
- * 服务端插入的行包含当前行
- */
- if (targetOperation.getIndex() >= savedOperation.getIndex() && targetOperation.getHeight() <= savedOperation.getHeight()) {// TODO ....
- }
- /**
- * 服务端插入的行和当前行上交叉
- */
- if (targetOperation.getIndex() > savedOperation.getIndex() && targetOperation.getIndex() < savedOperation.getHeight() && targetOperation.getHeight() >= savedOperation.getHeight()) {// TODO ..
- // ...
- }
- /**
- * 服务端插入的行和当前行下交叉
- */
- if (targetOperation.getIndex() <= savedOperation.getIndex() && targetOperation.getHeight() > savedOperation.getIndex() && targetOperation.getHeight() < savedOperation.getHeight()) {// TODO ...
- //
- }
- };
- });
- return conflict;
- }
- exports.CreateConflict = CreateConflict;
- /***/ }),
- /***/ "./src/internal.ts":
- /*!*************************!*\
- !*** ./src/internal.ts ***!
- \*************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, {
- enumerable: true,
- get: function get() {
- return m[k];
- }
- });
- } : function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- });
- var __exportStar = this && this.__exportStar || function (m, exports) {
- for (var p in m) {
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- }
- };
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- __exportStar(__webpack_require__(/*! ./operated/InsertColumn */ "./src/operated/InsertColumn.ts"), exports);
- __exportStar(__webpack_require__(/*! ./operated/InsertRow */ "./src/operated/InsertRow.ts"), exports);
- __exportStar(__webpack_require__(/*! ./operated/RemoveColumn */ "./src/operated/RemoveColumn.ts"), exports);
- __exportStar(__webpack_require__(/*! ./operated/RemoveRow */ "./src/operated/RemoveRow.ts"), exports);
- __exportStar(__webpack_require__(/*! ./basics/CreateConflict */ "./src/basics/CreateConflict.ts"), exports);
- /***/ }),
- /***/ "./src/operated/InsertColumn.ts":
- /*!**************************************!*\
- !*** ./src/operated/InsertColumn.ts ***!
- \**************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.InsertColumn = void 0;
- var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
- var InsertColumn = /*#__PURE__*/function () {
- function InsertColumn() {
- _classCallCheck(this, InsertColumn);
- this._describe = 'InsertColumn';
- for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
- parameter[_key] = arguments[_key];
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
- this._index = 0;
- this._count = 0;
- this._buffer = new ot_core_1.SwapData();
- return;
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
- var serialize = parameter[0];
- this._index = serialize.index;
- this._count = serialize.count;
- this._buffer = ot_core_1.Deserialize.getInstance().formObject(serialize.buffer, new ot_core_1.SwapData());
- }
- }
- _createClass(InsertColumn, [{
- key: "apply",
- value: function apply(resource) {}
- }, {
- key: "setIndex",
- value: function setIndex(index) {
- this._index = index;
- }
- }, {
- key: "setCount",
- value: function setCount(count) {
- this._count = count;
- }
- }, {
- key: "getIndex",
- value: function getIndex() {
- return this._index;
- }
- }, {
- key: "getCount",
- value: function getCount() {
- return this._count;
- }
- }, {
- key: "clone",
- value: function clone() {
- var clone = new InsertColumn();
- clone._index = this._index;
- clone._count = this._count;
- clone._buffer = this._buffer.clone();
- return clone;
- }
- }, {
- key: "toJSON",
- value: function toJSON() {
- return {
- describe: this._describe,
- index: this._index,
- count: this._count,
- buffer: this._buffer
- };
- }
- }]);
- return InsertColumn;
- }();
- exports.InsertColumn = InsertColumn;
- /***/ }),
- /***/ "./src/operated/InsertRow.ts":
- /*!***********************************!*\
- !*** ./src/operated/InsertRow.ts ***!
- \***********************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
- 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."); }
- 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); }
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
- 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; }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.InsertRow = void 0;
- var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
- var InsertRow = /*#__PURE__*/function () {
- function InsertRow() {
- _classCallCheck(this, InsertRow);
- this._describe = 'InsertRow';
- for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
- parameter[_key] = arguments[_key];
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
- this._index = 0;
- this._count = 0;
- this._buffer = new ot_core_1.SwapData();
- return;
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
- var serialize = parameter[0];
- this._index = serialize.index;
- this._count = serialize.count;
- this._buffer = ot_core_1.Deserialize.getInstance().formObject(serialize.buffer, new ot_core_1.SwapData());
- }
- }
- _createClass(InsertRow, [{
- key: "apply",
- value: function apply(resource) {
- var data = this._buffer.getData();
- var index = this._index;
- var count = this._count;
- if (data) {
- resource.splice.apply(resource, [index, 0].concat(_toConsumableArray(data)));
- } else {
- var empty = new Array(count).fill([]);
- resource.splice.apply(resource, [index, 0].concat(_toConsumableArray(empty)));
- }
- }
- }, {
- key: "setIndex",
- value: function setIndex(index) {
- this._index = index;
- }
- }, {
- key: "setCount",
- value: function setCount(count) {
- this._count = count;
- }
- }, {
- key: "getIndex",
- value: function getIndex() {
- return this._index;
- }
- }, {
- key: "getCount",
- value: function getCount() {
- return this._count;
- }
- }, {
- key: "getHeight",
- value: function getHeight() {
- return this._index + this._count;
- }
- }, {
- key: "getBuffer",
- value: function getBuffer() {
- return this._buffer;
- }
- }, {
- key: "clone",
- value: function clone() {
- var clone = new InsertRow();
- clone._index = this._index;
- clone._count = this._count;
- clone._buffer = this._buffer.clone();
- return clone;
- }
- }, {
- key: "toJSON",
- value: function toJSON() {
- return {
- describe: this._describe,
- index: this._index,
- count: this._count,
- buffer: this._buffer
- };
- }
- }]);
- return InsertRow;
- }();
- exports.InsertRow = InsertRow;
- /***/ }),
- /***/ "./src/operated/RemoveColumn.ts":
- /*!**************************************!*\
- !*** ./src/operated/RemoveColumn.ts ***!
- \**************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.RemoveColumn = void 0;
- var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
- var RemoveColumn = /*#__PURE__*/function () {
- function RemoveColumn() {
- _classCallCheck(this, RemoveColumn);
- this._describe = 'RemoveColumn';
- for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
- parameter[_key] = arguments[_key];
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
- this._index = 0;
- this._count = 0;
- this._buffer = new ot_core_1.SwapData();
- return;
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
- var serialize = parameter[0];
- this._index = serialize.index;
- this._count = serialize.count;
- return;
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 2)) {
- var _serialize = parameter[0];
- var buffer = parameter[1];
- this._index = _serialize.index;
- this._count = _serialize.count;
- this._buffer = buffer;
- }
- }
- _createClass(RemoveColumn, [{
- key: "apply",
- value: function apply(resource) {}
- }, {
- key: "setIndex",
- value: function setIndex(index) {
- this._index = index;
- }
- }, {
- key: "setCount",
- value: function setCount(count) {
- this._count = count;
- }
- }, {
- key: "getIndex",
- value: function getIndex() {
- return this._index;
- }
- }, {
- key: "getCount",
- value: function getCount() {
- return this._count;
- }
- }, {
- key: "clone",
- value: function clone() {
- var clone = new RemoveColumn();
- clone._index = this._index;
- clone._count = this._count;
- clone._buffer = this._buffer.clone();
- return clone;
- }
- }, {
- key: "toJSON",
- value: function toJSON() {
- return {
- describe: this._describe,
- index: this._index,
- count: this._count
- };
- }
- }]);
- return RemoveColumn;
- }();
- exports.RemoveColumn = RemoveColumn;
- /***/ }),
- /***/ "./src/operated/RemoveRow.ts":
- /*!***********************************!*\
- !*** ./src/operated/RemoveRow.ts ***!
- \***********************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.RemoveRow = void 0;
- var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
- var RemoveRow = /*#__PURE__*/function () {
- function RemoveRow() {
- _classCallCheck(this, RemoveRow);
- this._describe = 'RemoveRow';
- for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) {
- parameter[_key] = arguments[_key];
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 0)) {
- this._index = 0;
- this._count = 0;
- this._buffer = new ot_core_1.SwapData();
- return;
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 1)) {
- var serialize = parameter[0];
- this._index = serialize.index;
- this._count = serialize.count;
- return;
- }
- if (ot_core_1.TransformUtils.hasLength(parameter, 2)) {
- var _serialize = parameter[0];
- var buffer = parameter[1];
- this._index = _serialize.index;
- this._count = _serialize.count;
- this._buffer = buffer;
- }
- }
- _createClass(RemoveRow, [{
- key: "apply",
- value: function apply(resource) {}
- }, {
- key: "setIndex",
- value: function setIndex(index) {
- this._index = index;
- }
- }, {
- key: "setCount",
- value: function setCount(count) {
- this._count = count;
- }
- }, {
- key: "getIndex",
- value: function getIndex() {
- return this._index;
- }
- }, {
- key: "getCount",
- value: function getCount() {
- return this._count;
- }
- }, {
- key: "clone",
- value: function clone() {
- var clone = new RemoveRow();
- clone._index = this._index;
- clone._count = this._count;
- clone._buffer = this._buffer.clone();
- return clone;
- }
- }, {
- key: "toJSON",
- value: function toJSON() {
- return {
- describe: this._describe,
- index: this._index,
- count: this._count
- };
- }
- }]);
- return RemoveRow;
- }();
- exports.RemoveRow = RemoveRow;
- /***/ }),
- /***/ "./src/server.ts":
- /*!***********************!*\
- !*** ./src/server.ts ***!
- \***********************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, {
- enumerable: true,
- get: function get() {
- return m[k];
- }
- });
- } : function (o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- });
- var __exportStar = this && this.__exportStar || function (m, exports) {
- for (var p in m) {
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- }
- };
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- __exportStar(__webpack_require__(/*! ./server/Server */ "./src/server/Server.ts"), exports);
- /***/ }),
- /***/ "./src/server/Server.ts":
- /*!******************************!*\
- !*** ./src/server/Server.ts ***!
- \******************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- 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); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
- 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); }
- function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
- 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); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- 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); }; }
- 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); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- 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; } }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- Object.defineProperty(exports, "__esModule", ({
- value: true
- }));
- exports.Server = void 0;
- var ot_core_1 = __webpack_require__(/*! ot-core */ "../ot-core/src/index.ts");
- var internal_1 = __webpack_require__(/*! ../internal */ "./src/internal.ts");
- __webpack_require__(/*! ../basics/Bootstrap */ "./src/basics/Bootstrap.ts");
- var Server = /*#__PURE__*/function (_ot_core_1$ServerSock) {
- _inherits(Server, _ot_core_1$ServerSock);
- var _super = _createSuper(Server);
- function Server() {
- _classCallCheck(this, Server);
- return _super.call(this, (0, internal_1.CreateConflict)(), []);
- }
- _createClass(Server, [{
- key: "onCommand",
- value: function onCommand(client, revision, command) {
- _get(_getPrototypeOf(Server.prototype), "onCommand", this).call(this, client, revision, command);
- console.log(this._source);
- }
- }]);
- return Server;
- }(ot_core_1.ServerSocket);
- exports.Server = Server;
- /***/ }),
- /***/ "child_process":
- /*!********************************!*\
- !*** external "child_process" ***!
- \********************************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("child_process");
- /***/ }),
- /***/ "crypto":
- /*!*************************!*\
- !*** external "crypto" ***!
- \*************************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("crypto");
- /***/ }),
- /***/ "events":
- /*!*************************!*\
- !*** external "events" ***!
- \*************************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("events");
- /***/ }),
- /***/ "fs":
- /*!*********************!*\
- !*** external "fs" ***!
- \*********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("fs");
- /***/ }),
- /***/ "http":
- /*!***********************!*\
- !*** external "http" ***!
- \***********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("http");
- /***/ }),
- /***/ "https":
- /*!************************!*\
- !*** external "https" ***!
- \************************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("https");
- /***/ }),
- /***/ "net":
- /*!**********************!*\
- !*** external "net" ***!
- \**********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("net");
- /***/ }),
- /***/ "os":
- /*!*********************!*\
- !*** external "os" ***!
- \*********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("os");
- /***/ }),
- /***/ "stream":
- /*!*************************!*\
- !*** external "stream" ***!
- \*************************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("stream");
- /***/ }),
- /***/ "tls":
- /*!**********************!*\
- !*** external "tls" ***!
- \**********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("tls");
- /***/ }),
- /***/ "tty":
- /*!**********************!*\
- !*** external "tty" ***!
- \**********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("tty");
- /***/ }),
- /***/ "url":
- /*!**********************!*\
- !*** external "url" ***!
- \**********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("url");
- /***/ }),
- /***/ "util":
- /*!***********************!*\
- !*** external "util" ***!
- \***********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("util");
- /***/ }),
- /***/ "zlib":
- /*!***********************!*\
- !*** external "zlib" ***!
- \***********************/
- /***/ ((module) => {
- "use strict";
- module.exports = require("zlib");
- /***/ }),
- /***/ "bufferutil":
- /*!*****************************!*\
- !*** external "bufferutil" ***!
- \*****************************/
- /***/ ((module) => {
- "use strict";
- if(typeof __WEBPACK_EXTERNAL_MODULE_bufferutil__ === 'undefined') { var e = new Error("Cannot find module 'bufferutil'"); e.code = 'MODULE_NOT_FOUND'; throw e; }
- module.exports = __WEBPACK_EXTERNAL_MODULE_bufferutil__;
- /***/ }),
- /***/ "utf-8-validate":
- /*!*********************************!*\
- !*** external "utf-8-validate" ***!
- \*********************************/
- /***/ ((module) => {
- "use strict";
- 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; }
- module.exports = __WEBPACK_EXTERNAL_MODULE_utf_8_validate__;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js":
- /*!************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js ***!
- \************************************************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports["default"] = global;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/index.js":
- /*!*******************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/index.js ***!
- \*******************************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.installTimerFunctions = exports.transports = exports.Transport = exports.protocol = exports.Socket = void 0;
- const socket_js_1 = __webpack_require__(/*! ./socket.js */ "../ot-core/node_modules/engine.io-client/build/cjs/socket.js");
- Object.defineProperty(exports, "Socket", ({ enumerable: true, get: function () { return socket_js_1.Socket; } }));
- exports.protocol = socket_js_1.Socket.protocol;
- var transport_js_1 = __webpack_require__(/*! ./transport.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js");
- Object.defineProperty(exports, "Transport", ({ enumerable: true, get: function () { return transport_js_1.Transport; } }));
- var index_js_1 = __webpack_require__(/*! ./transports/index.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js");
- Object.defineProperty(exports, "transports", ({ enumerable: true, get: function () { return index_js_1.transports; } }));
- var util_js_1 = __webpack_require__(/*! ./util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
- Object.defineProperty(exports, "installTimerFunctions", ({ enumerable: true, get: function () { return util_js_1.installTimerFunctions; } }));
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/socket.js":
- /*!********************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/socket.js ***!
- \********************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.Socket = void 0;
- const index_js_1 = __webpack_require__(/*! ./transports/index.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js");
- const util_js_1 = __webpack_require__(/*! ./util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
- const parseqs_1 = __importDefault(__webpack_require__(/*! parseqs */ "../ot-core/node_modules/parseqs/index.js"));
- const parseuri_1 = __importDefault(__webpack_require__(/*! parseuri */ "../ot-core/node_modules/parseuri/index.js"));
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
- const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
- const debug = (0, debug_1.default)("engine.io-client:socket"); // debug()
- class Socket extends component_emitter_1.Emitter {
- /**
- * Socket constructor.
- *
- * @param {String|Object} uri or options
- * @param {Object} opts - options
- * @api public
- */
- constructor(uri, opts = {}) {
- super();
- if (uri && "object" === typeof uri) {
- opts = uri;
- uri = null;
- }
- if (uri) {
- uri = (0, parseuri_1.default)(uri);
- opts.hostname = uri.host;
- opts.secure = uri.protocol === "https" || uri.protocol === "wss";
- opts.port = uri.port;
- if (uri.query)
- opts.query = uri.query;
- }
- else if (opts.host) {
- opts.hostname = (0, parseuri_1.default)(opts.host).host;
- }
- (0, util_js_1.installTimerFunctions)(this, opts);
- this.secure =
- null != opts.secure
- ? opts.secure
- : typeof location !== "undefined" && "https:" === location.protocol;
- if (opts.hostname && !opts.port) {
- // if no port is specified manually, use the protocol default
- opts.port = this.secure ? "443" : "80";
- }
- this.hostname =
- opts.hostname ||
- (typeof location !== "undefined" ? location.hostname : "localhost");
- this.port =
- opts.port ||
- (typeof location !== "undefined" && location.port
- ? location.port
- : this.secure
- ? "443"
- : "80");
- this.transports = opts.transports || ["polling", "websocket"];
- this.readyState = "";
- this.writeBuffer = [];
- this.prevBufferLen = 0;
- this.opts = Object.assign({
- path: "/engine.io",
- agent: false,
- withCredentials: false,
- upgrade: true,
- timestampParam: "t",
- rememberUpgrade: false,
- rejectUnauthorized: true,
- perMessageDeflate: {
- threshold: 1024
- },
- transportOptions: {},
- closeOnBeforeunload: true
- }, opts);
- this.opts.path = this.opts.path.replace(/\/$/, "") + "/";
- if (typeof this.opts.query === "string") {
- this.opts.query = parseqs_1.default.decode(this.opts.query);
- }
- // set on handshake
- this.id = null;
- this.upgrades = null;
- this.pingInterval = null;
- this.pingTimeout = null;
- // set on heartbeat
- this.pingTimeoutTimer = null;
- if (typeof addEventListener === "function") {
- if (this.opts.closeOnBeforeunload) {
- // Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
- // ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
- // closed/reloaded)
- addEventListener("beforeunload", () => {
- if (this.transport) {
- // silently close the transport
- this.transport.removeAllListeners();
- this.transport.close();
- }
- }, false);
- }
- if (this.hostname !== "localhost") {
- this.offlineEventListener = () => {
- this.onClose("transport close");
- };
- addEventListener("offline", this.offlineEventListener, false);
- }
- }
- this.open();
- }
- /**
- * Creates transport of the given type.
- *
- * @param {String} transport name
- * @return {Transport}
- * @api private
- */
- createTransport(name) {
- debug('creating transport "%s"', name);
- const query = clone(this.opts.query);
- // append engine.io protocol identifier
- query.EIO = engine_io_parser_1.protocol;
- // transport name
- query.transport = name;
- // session id if we already have one
- if (this.id)
- query.sid = this.id;
- const opts = Object.assign({}, this.opts.transportOptions[name], this.opts, {
- query,
- socket: this,
- hostname: this.hostname,
- secure: this.secure,
- port: this.port
- });
- debug("options: %j", opts);
- return new index_js_1.transports[name](opts);
- }
- /**
- * Initializes transport to use and starts probe.
- *
- * @api private
- */
- open() {
- let transport;
- if (this.opts.rememberUpgrade &&
- Socket.priorWebsocketSuccess &&
- this.transports.indexOf("websocket") !== -1) {
- transport = "websocket";
- }
- else if (0 === this.transports.length) {
- // Emit error on next tick so it can be listened to
- this.setTimeoutFn(() => {
- this.emitReserved("error", "No transports available");
- }, 0);
- return;
- }
- else {
- transport = this.transports[0];
- }
- this.readyState = "opening";
- // Retry with the next transport if the transport is disabled (jsonp: false)
- try {
- transport = this.createTransport(transport);
- }
- catch (e) {
- debug("error while creating transport: %s", e);
- this.transports.shift();
- this.open();
- return;
- }
- transport.open();
- this.setTransport(transport);
- }
- /**
- * Sets the current transport. Disables the existing one (if any).
- *
- * @api private
- */
- setTransport(transport) {
- debug("setting transport %s", transport.name);
- if (this.transport) {
- debug("clearing existing transport %s", this.transport.name);
- this.transport.removeAllListeners();
- }
- // set up transport
- this.transport = transport;
- // set up transport listeners
- transport
- .on("drain", this.onDrain.bind(this))
- .on("packet", this.onPacket.bind(this))
- .on("error", this.onError.bind(this))
- .on("close", () => {
- this.onClose("transport close");
- });
- }
- /**
- * Probes a transport.
- *
- * @param {String} transport name
- * @api private
- */
- probe(name) {
- debug('probing transport "%s"', name);
- let transport = this.createTransport(name);
- let failed = false;
- Socket.priorWebsocketSuccess = false;
- const onTransportOpen = () => {
- if (failed)
- return;
- debug('probe transport "%s" opened', name);
- transport.send([{ type: "ping", data: "probe" }]);
- transport.once("packet", msg => {
- if (failed)
- return;
- if ("pong" === msg.type && "probe" === msg.data) {
- debug('probe transport "%s" pong', name);
- this.upgrading = true;
- this.emitReserved("upgrading", transport);
- if (!transport)
- return;
- Socket.priorWebsocketSuccess = "websocket" === transport.name;
- debug('pausing current transport "%s"', this.transport.name);
- this.transport.pause(() => {
- if (failed)
- return;
- if ("closed" === this.readyState)
- return;
- debug("changing transport and sending upgrade packet");
- cleanup();
- this.setTransport(transport);
- transport.send([{ type: "upgrade" }]);
- this.emitReserved("upgrade", transport);
- transport = null;
- this.upgrading = false;
- this.flush();
- });
- }
- else {
- debug('probe transport "%s" failed', name);
- const err = new Error("probe error");
- // @ts-ignore
- err.transport = transport.name;
- this.emitReserved("upgradeError", err);
- }
- });
- };
- function freezeTransport() {
- if (failed)
- return;
- // Any callback called by transport should be ignored since now
- failed = true;
- cleanup();
- transport.close();
- transport = null;
- }
- // Handle any error that happens while probing
- const onerror = err => {
- const error = new Error("probe error: " + err);
- // @ts-ignore
- error.transport = transport.name;
- freezeTransport();
- debug('probe transport "%s" failed because of error: %s', name, err);
- this.emitReserved("upgradeError", error);
- };
- function onTransportClose() {
- onerror("transport closed");
- }
- // When the socket is closed while we're probing
- function onclose() {
- onerror("socket closed");
- }
- // When the socket is upgraded while we're probing
- function onupgrade(to) {
- if (transport && to.name !== transport.name) {
- debug('"%s" works - aborting "%s"', to.name, transport.name);
- freezeTransport();
- }
- }
- // Remove all listeners on the transport and on self
- const cleanup = () => {
- transport.removeListener("open", onTransportOpen);
- transport.removeListener("error", onerror);
- transport.removeListener("close", onTransportClose);
- this.off("close", onclose);
- this.off("upgrading", onupgrade);
- };
- transport.once("open", onTransportOpen);
- transport.once("error", onerror);
- transport.once("close", onTransportClose);
- this.once("close", onclose);
- this.once("upgrading", onupgrade);
- transport.open();
- }
- /**
- * Called when connection is deemed open.
- *
- * @api private
- */
- onOpen() {
- debug("socket open");
- this.readyState = "open";
- Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
- this.emitReserved("open");
- this.flush();
- // we check for `readyState` in case an `open`
- // listener already closed the socket
- if ("open" === this.readyState &&
- this.opts.upgrade &&
- this.transport.pause) {
- debug("starting upgrade probes");
- let i = 0;
- const l = this.upgrades.length;
- for (; i < l; i++) {
- this.probe(this.upgrades[i]);
- }
- }
- }
- /**
- * Handles a packet.
- *
- * @api private
- */
- onPacket(packet) {
- if ("opening" === this.readyState ||
- "open" === this.readyState ||
- "closing" === this.readyState) {
- debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
- this.emitReserved("packet", packet);
- // Socket is live - any packet counts
- this.emitReserved("heartbeat");
- switch (packet.type) {
- case "open":
- this.onHandshake(JSON.parse(packet.data));
- break;
- case "ping":
- this.resetPingTimeout();
- this.sendPacket("pong");
- this.emitReserved("ping");
- this.emitReserved("pong");
- break;
- case "error":
- const err = new Error("server error");
- // @ts-ignore
- err.code = packet.data;
- this.onError(err);
- break;
- case "message":
- this.emitReserved("data", packet.data);
- this.emitReserved("message", packet.data);
- break;
- }
- }
- else {
- debug('packet received with socket readyState "%s"', this.readyState);
- }
- }
- /**
- * Called upon handshake completion.
- *
- * @param {Object} data - handshake obj
- * @api private
- */
- onHandshake(data) {
- this.emitReserved("handshake", data);
- this.id = data.sid;
- this.transport.query.sid = data.sid;
- this.upgrades = this.filterUpgrades(data.upgrades);
- this.pingInterval = data.pingInterval;
- this.pingTimeout = data.pingTimeout;
- this.onOpen();
- // In case open handler closes socket
- if ("closed" === this.readyState)
- return;
- this.resetPingTimeout();
- }
- /**
- * Sets and resets ping timeout timer based on server pings.
- *
- * @api private
- */
- resetPingTimeout() {
- this.clearTimeoutFn(this.pingTimeoutTimer);
- this.pingTimeoutTimer = this.setTimeoutFn(() => {
- this.onClose("ping timeout");
- }, this.pingInterval + this.pingTimeout);
- if (this.opts.autoUnref) {
- this.pingTimeoutTimer.unref();
- }
- }
- /**
- * Called on `drain` event
- *
- * @api private
- */
- onDrain() {
- this.writeBuffer.splice(0, this.prevBufferLen);
- // setting prevBufferLen = 0 is very important
- // for example, when upgrading, upgrade packet is sent over,
- // and a nonzero prevBufferLen could cause problems on `drain`
- this.prevBufferLen = 0;
- if (0 === this.writeBuffer.length) {
- this.emitReserved("drain");
- }
- else {
- this.flush();
- }
- }
- /**
- * Flush write buffers.
- *
- * @api private
- */
- flush() {
- if ("closed" !== this.readyState &&
- this.transport.writable &&
- !this.upgrading &&
- this.writeBuffer.length) {
- debug("flushing %d packets in socket", this.writeBuffer.length);
- this.transport.send(this.writeBuffer);
- // keep track of current length of writeBuffer
- // splice writeBuffer and callbackBuffer on `drain`
- this.prevBufferLen = this.writeBuffer.length;
- this.emitReserved("flush");
- }
- }
- /**
- * Sends a message.
- *
- * @param {String} message.
- * @param {Function} callback function.
- * @param {Object} options.
- * @return {Socket} for chaining.
- * @api public
- */
- write(msg, options, fn) {
- this.sendPacket("message", msg, options, fn);
- return this;
- }
- send(msg, options, fn) {
- this.sendPacket("message", msg, options, fn);
- return this;
- }
- /**
- * Sends a packet.
- *
- * @param {String} packet type.
- * @param {String} data.
- * @param {Object} options.
- * @param {Function} callback function.
- * @api private
- */
- sendPacket(type, data, options, fn) {
- if ("function" === typeof data) {
- fn = data;
- data = undefined;
- }
- if ("function" === typeof options) {
- fn = options;
- options = null;
- }
- if ("closing" === this.readyState || "closed" === this.readyState) {
- return;
- }
- options = options || {};
- options.compress = false !== options.compress;
- const packet = {
- type: type,
- data: data,
- options: options
- };
- this.emitReserved("packetCreate", packet);
- this.writeBuffer.push(packet);
- if (fn)
- this.once("flush", fn);
- this.flush();
- }
- /**
- * Closes the connection.
- *
- * @api public
- */
- close() {
- const close = () => {
- this.onClose("forced close");
- debug("socket closing - telling transport to close");
- this.transport.close();
- };
- const cleanupAndClose = () => {
- this.off("upgrade", cleanupAndClose);
- this.off("upgradeError", cleanupAndClose);
- close();
- };
- const waitForUpgrade = () => {
- // wait for upgrade to finish since we can't send packets while pausing a transport
- this.once("upgrade", cleanupAndClose);
- this.once("upgradeError", cleanupAndClose);
- };
- if ("opening" === this.readyState || "open" === this.readyState) {
- this.readyState = "closing";
- if (this.writeBuffer.length) {
- this.once("drain", () => {
- if (this.upgrading) {
- waitForUpgrade();
- }
- else {
- close();
- }
- });
- }
- else if (this.upgrading) {
- waitForUpgrade();
- }
- else {
- close();
- }
- }
- return this;
- }
- /**
- * Called upon transport error
- *
- * @api private
- */
- onError(err) {
- debug("socket error %j", err);
- Socket.priorWebsocketSuccess = false;
- this.emitReserved("error", err);
- this.onClose("transport error", err);
- }
- /**
- * Called upon transport close.
- *
- * @api private
- */
- onClose(reason, desc) {
- if ("opening" === this.readyState ||
- "open" === this.readyState ||
- "closing" === this.readyState) {
- debug('socket close with reason: "%s"', reason);
- // clear timers
- this.clearTimeoutFn(this.pingTimeoutTimer);
- // stop event from firing again for transport
- this.transport.removeAllListeners("close");
- // ensure transport won't stay open
- this.transport.close();
- // ignore further transport communication
- this.transport.removeAllListeners();
- if (typeof removeEventListener === "function") {
- removeEventListener("offline", this.offlineEventListener, false);
- }
- // set ready state
- this.readyState = "closed";
- // clear session id
- this.id = null;
- // emit close event
- this.emitReserved("close", reason, desc);
- // clean buffers after, so users can still
- // grab the buffers on `close` event
- this.writeBuffer = [];
- this.prevBufferLen = 0;
- }
- }
- /**
- * Filters upgrades, returning only those matching client transports.
- *
- * @param {Array} server upgrades
- * @api private
- *
- */
- filterUpgrades(upgrades) {
- const filteredUpgrades = [];
- let i = 0;
- const j = upgrades.length;
- for (; i < j; i++) {
- if (~this.transports.indexOf(upgrades[i]))
- filteredUpgrades.push(upgrades[i]);
- }
- return filteredUpgrades;
- }
- }
- exports.Socket = Socket;
- Socket.protocol = engine_io_parser_1.protocol;
- function clone(obj) {
- const o = {};
- for (let i in obj) {
- if (obj.hasOwnProperty(i)) {
- o[i] = obj[i];
- }
- }
- return o;
- }
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js":
- /*!***********************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/transport.js ***!
- \***********************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.Transport = void 0;
- const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
- const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
- const util_js_1 = __webpack_require__(/*! ./util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const debug = (0, debug_1.default)("engine.io-client:transport"); // debug()
- class Transport extends component_emitter_1.Emitter {
- /**
- * Transport abstract constructor.
- *
- * @param {Object} options.
- * @api private
- */
- constructor(opts) {
- super();
- this.writable = false;
- (0, util_js_1.installTimerFunctions)(this, opts);
- this.opts = opts;
- this.query = opts.query;
- this.readyState = "";
- this.socket = opts.socket;
- }
- /**
- * Emits an error.
- *
- * @param {String} str
- * @return {Transport} for chaining
- * @api protected
- */
- onError(msg, desc) {
- const err = new Error(msg);
- // @ts-ignore
- err.type = "TransportError";
- // @ts-ignore
- err.description = desc;
- super.emit("error", err);
- return this;
- }
- /**
- * Opens the transport.
- *
- * @api public
- */
- open() {
- if ("closed" === this.readyState || "" === this.readyState) {
- this.readyState = "opening";
- this.doOpen();
- }
- return this;
- }
- /**
- * Closes the transport.
- *
- * @api public
- */
- close() {
- if ("opening" === this.readyState || "open" === this.readyState) {
- this.doClose();
- this.onClose();
- }
- return this;
- }
- /**
- * Sends multiple packets.
- *
- * @param {Array} packets
- * @api public
- */
- send(packets) {
- if ("open" === this.readyState) {
- this.write(packets);
- }
- else {
- // this might happen if the transport was silently closed in the beforeunload event handler
- debug("transport is not open, discarding packets");
- }
- }
- /**
- * Called upon open
- *
- * @api protected
- */
- onOpen() {
- this.readyState = "open";
- this.writable = true;
- super.emit("open");
- }
- /**
- * Called with data.
- *
- * @param {String} data
- * @api protected
- */
- onData(data) {
- const packet = (0, engine_io_parser_1.decodePacket)(data, this.socket.binaryType);
- this.onPacket(packet);
- }
- /**
- * Called with a decoded packet.
- *
- * @api protected
- */
- onPacket(packet) {
- super.emit("packet", packet);
- }
- /**
- * Called upon close.
- *
- * @api protected
- */
- onClose() {
- this.readyState = "closed";
- super.emit("close");
- }
- }
- exports.Transport = Transport;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js":
- /*!******************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/index.js ***!
- \******************************************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.transports = void 0;
- const polling_xhr_js_1 = __webpack_require__(/*! ./polling-xhr.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js");
- const websocket_js_1 = __webpack_require__(/*! ./websocket.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket.js");
- exports.transports = {
- websocket: websocket_js_1.WS,
- polling: polling_xhr_js_1.XHR
- };
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js":
- /*!************************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js ***!
- \************************************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- /* global attachEvent */
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.Request = exports.XHR = void 0;
- const xmlhttprequest_js_1 = __importDefault(__webpack_require__(/*! ./xmlhttprequest.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/xmlhttprequest.js"));
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const globalThis_js_1 = __importDefault(__webpack_require__(/*! ../globalThis.js */ "../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js"));
- const util_js_1 = __webpack_require__(/*! ../util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
- const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
- const polling_js_1 = __webpack_require__(/*! ./polling.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling.js");
- const debug = (0, debug_1.default)("engine.io-client:polling-xhr"); // debug()
- /**
- * Empty function
- */
- function empty() { }
- const hasXHR2 = (function () {
- const xhr = new xmlhttprequest_js_1.default({
- xdomain: false
- });
- return null != xhr.responseType;
- })();
- class XHR extends polling_js_1.Polling {
- /**
- * XHR Polling constructor.
- *
- * @param {Object} opts
- * @api public
- */
- constructor(opts) {
- super(opts);
- if (typeof location !== "undefined") {
- const isSSL = "https:" === location.protocol;
- let port = location.port;
- // some user agents have empty `location.port`
- if (!port) {
- port = isSSL ? "443" : "80";
- }
- this.xd =
- (typeof location !== "undefined" &&
- opts.hostname !== location.hostname) ||
- port !== opts.port;
- this.xs = opts.secure !== isSSL;
- }
- /**
- * XHR supports binary
- */
- const forceBase64 = opts && opts.forceBase64;
- this.supportsBinary = hasXHR2 && !forceBase64;
- }
- /**
- * Creates a request.
- *
- * @param {String} method
- * @api private
- */
- request(opts = {}) {
- Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);
- return new Request(this.uri(), opts);
- }
- /**
- * Sends data.
- *
- * @param {String} data to send.
- * @param {Function} called upon flush.
- * @api private
- */
- doWrite(data, fn) {
- const req = this.request({
- method: "POST",
- data: data
- });
- req.on("success", fn);
- req.on("error", err => {
- this.onError("xhr post error", err);
- });
- }
- /**
- * Starts a poll cycle.
- *
- * @api private
- */
- doPoll() {
- debug("xhr poll");
- const req = this.request();
- req.on("data", this.onData.bind(this));
- req.on("error", err => {
- this.onError("xhr poll error", err);
- });
- this.pollXhr = req;
- }
- }
- exports.XHR = XHR;
- class Request extends component_emitter_1.Emitter {
- /**
- * Request constructor
- *
- * @param {Object} options
- * @api public
- */
- constructor(uri, opts) {
- super();
- (0, util_js_1.installTimerFunctions)(this, opts);
- this.opts = opts;
- this.method = opts.method || "GET";
- this.uri = uri;
- this.async = false !== opts.async;
- this.data = undefined !== opts.data ? opts.data : null;
- this.create();
- }
- /**
- * Creates the XHR object and sends the request.
- *
- * @api private
- */
- create() {
- const opts = (0, util_js_1.pick)(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
- opts.xdomain = !!this.opts.xd;
- opts.xscheme = !!this.opts.xs;
- const xhr = (this.xhr = new xmlhttprequest_js_1.default(opts));
- try {
- debug("xhr open %s: %s", this.method, this.uri);
- xhr.open(this.method, this.uri, this.async);
- try {
- if (this.opts.extraHeaders) {
- xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
- for (let i in this.opts.extraHeaders) {
- if (this.opts.extraHeaders.hasOwnProperty(i)) {
- xhr.setRequestHeader(i, this.opts.extraHeaders[i]);
- }
- }
- }
- }
- catch (e) { }
- if ("POST" === this.method) {
- try {
- xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
- }
- catch (e) { }
- }
- try {
- xhr.setRequestHeader("Accept", "*/*");
- }
- catch (e) { }
- // ie6 check
- if ("withCredentials" in xhr) {
- xhr.withCredentials = this.opts.withCredentials;
- }
- if (this.opts.requestTimeout) {
- xhr.timeout = this.opts.requestTimeout;
- }
- xhr.onreadystatechange = () => {
- if (4 !== xhr.readyState)
- return;
- if (200 === xhr.status || 1223 === xhr.status) {
- this.onLoad();
- }
- else {
- // make sure the `error` event handler that's user-set
- // does not throw in the same tick and gets caught here
- this.setTimeoutFn(() => {
- this.onError(typeof xhr.status === "number" ? xhr.status : 0);
- }, 0);
- }
- };
- debug("xhr data %s", this.data);
- xhr.send(this.data);
- }
- catch (e) {
- // Need to defer since .create() is called directly from the constructor
- // and thus the 'error' event can only be only bound *after* this exception
- // occurs. Therefore, also, we cannot throw here at all.
- this.setTimeoutFn(() => {
- this.onError(e);
- }, 0);
- return;
- }
- if (typeof document !== "undefined") {
- this.index = Request.requestsCount++;
- Request.requests[this.index] = this;
- }
- }
- /**
- * Called upon successful response.
- *
- * @api private
- */
- onSuccess() {
- this.emit("success");
- this.cleanup();
- }
- /**
- * Called if we have data.
- *
- * @api private
- */
- onData(data) {
- this.emit("data", data);
- this.onSuccess();
- }
- /**
- * Called upon error.
- *
- * @api private
- */
- onError(err) {
- this.emit("error", err);
- this.cleanup(true);
- }
- /**
- * Cleans up house.
- *
- * @api private
- */
- cleanup(fromError) {
- if ("undefined" === typeof this.xhr || null === this.xhr) {
- return;
- }
- this.xhr.onreadystatechange = empty;
- if (fromError) {
- try {
- this.xhr.abort();
- }
- catch (e) { }
- }
- if (typeof document !== "undefined") {
- delete Request.requests[this.index];
- }
- this.xhr = null;
- }
- /**
- * Called upon load.
- *
- * @api private
- */
- onLoad() {
- const data = this.xhr.responseText;
- if (data !== null) {
- this.onData(data);
- }
- }
- /**
- * Aborts the request.
- *
- * @api public
- */
- abort() {
- this.cleanup();
- }
- }
- exports.Request = Request;
- Request.requestsCount = 0;
- Request.requests = {};
- /**
- * Aborts pending requests when unloading the window. This is needed to prevent
- * memory leaks (e.g. when using IE) and to ensure that no spurious error is
- * emitted.
- */
- if (typeof document !== "undefined") {
- // @ts-ignore
- if (typeof attachEvent === "function") {
- // @ts-ignore
- attachEvent("onunload", unloadHandler);
- }
- else if (typeof addEventListener === "function") {
- const terminationEvent = "onpagehide" in globalThis_js_1.default ? "pagehide" : "unload";
- addEventListener(terminationEvent, unloadHandler, false);
- }
- }
- function unloadHandler() {
- for (let i in Request.requests) {
- if (Request.requests.hasOwnProperty(i)) {
- Request.requests[i].abort();
- }
- }
- }
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/polling.js":
- /*!********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/polling.js ***!
- \********************************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.Polling = void 0;
- const transport_js_1 = __webpack_require__(/*! ../transport.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js");
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const yeast_1 = __importDefault(__webpack_require__(/*! yeast */ "../ot-core/node_modules/yeast/index.js"));
- const parseqs_1 = __importDefault(__webpack_require__(/*! parseqs */ "../ot-core/node_modules/parseqs/index.js"));
- const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
- const debug = (0, debug_1.default)("engine.io-client:polling"); // debug()
- class Polling extends transport_js_1.Transport {
- constructor() {
- super(...arguments);
- this.polling = false;
- }
- /**
- * Transport name.
- */
- get name() {
- return "polling";
- }
- /**
- * Opens the socket (triggers polling). We write a PING message to determine
- * when the transport is open.
- *
- * @api private
- */
- doOpen() {
- this.poll();
- }
- /**
- * Pauses polling.
- *
- * @param {Function} callback upon buffers are flushed and transport is paused
- * @api private
- */
- pause(onPause) {
- this.readyState = "pausing";
- const pause = () => {
- debug("paused");
- this.readyState = "paused";
- onPause();
- };
- if (this.polling || !this.writable) {
- let total = 0;
- if (this.polling) {
- debug("we are currently polling - waiting to pause");
- total++;
- this.once("pollComplete", function () {
- debug("pre-pause polling complete");
- --total || pause();
- });
- }
- if (!this.writable) {
- debug("we are currently writing - waiting to pause");
- total++;
- this.once("drain", function () {
- debug("pre-pause writing complete");
- --total || pause();
- });
- }
- }
- else {
- pause();
- }
- }
- /**
- * Starts polling cycle.
- *
- * @api public
- */
- poll() {
- debug("polling");
- this.polling = true;
- this.doPoll();
- this.emit("poll");
- }
- /**
- * Overloads onData to detect payloads.
- *
- * @api private
- */
- onData(data) {
- debug("polling got data %s", data);
- const callback = packet => {
- // if its the first message we consider the transport open
- if ("opening" === this.readyState && packet.type === "open") {
- this.onOpen();
- }
- // if its a close packet, we close the ongoing requests
- if ("close" === packet.type) {
- this.onClose();
- return false;
- }
- // otherwise bypass onData and handle the message
- this.onPacket(packet);
- };
- // decode payload
- (0, engine_io_parser_1.decodePayload)(data, this.socket.binaryType).forEach(callback);
- // if an event did not trigger closing
- if ("closed" !== this.readyState) {
- // if we got data we're not polling
- this.polling = false;
- this.emit("pollComplete");
- if ("open" === this.readyState) {
- this.poll();
- }
- else {
- debug('ignoring poll - transport state "%s"', this.readyState);
- }
- }
- }
- /**
- * For polling, send a close packet.
- *
- * @api private
- */
- doClose() {
- const close = () => {
- debug("writing close packet");
- this.write([{ type: "close" }]);
- };
- if ("open" === this.readyState) {
- debug("transport open - closing");
- close();
- }
- else {
- // in case we're trying to close while
- // handshaking is in progress (GH-164)
- debug("transport not open - deferring close");
- this.once("open", close);
- }
- }
- /**
- * Writes a packets payload.
- *
- * @param {Array} data packets
- * @param {Function} drain callback
- * @api private
- */
- write(packets) {
- this.writable = false;
- (0, engine_io_parser_1.encodePayload)(packets, data => {
- this.doWrite(data, () => {
- this.writable = true;
- this.emit("drain");
- });
- });
- }
- /**
- * Generates uri for connection.
- *
- * @api private
- */
- uri() {
- let query = this.query || {};
- const schema = this.opts.secure ? "https" : "http";
- let port = "";
- // cache busting is forced
- if (false !== this.opts.timestampRequests) {
- query[this.opts.timestampParam] = (0, yeast_1.default)();
- }
- if (!this.supportsBinary && !query.sid) {
- query.b64 = 1;
- }
- // avoid port if default for schema
- if (this.opts.port &&
- (("https" === schema && Number(this.opts.port) !== 443) ||
- ("http" === schema && Number(this.opts.port) !== 80))) {
- port = ":" + this.opts.port;
- }
- const encodedQuery = parseqs_1.default.encode(query);
- const ipv6 = this.opts.hostname.indexOf(":") !== -1;
- return (schema +
- "://" +
- (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) +
- port +
- this.opts.path +
- (encodedQuery.length ? "?" + encodedQuery : ""));
- }
- }
- exports.Polling = Polling;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket-constructor.js":
- /*!**********************************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket-constructor.js ***!
- \**********************************************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.nextTick = exports.defaultBinaryType = exports.usingBrowserWebSocket = exports.WebSocket = void 0;
- const ws_1 = __importDefault(__webpack_require__(/*! ws */ "../ot-core/node_modules/engine.io-client/node_modules/ws/index.js"));
- exports.WebSocket = ws_1.default;
- exports.usingBrowserWebSocket = false;
- exports.defaultBinaryType = "nodebuffer";
- exports.nextTick = process.nextTick;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket.js":
- /*!**********************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket.js ***!
- \**********************************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.WS = void 0;
- const transport_js_1 = __webpack_require__(/*! ../transport.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transport.js");
- const parseqs_1 = __importDefault(__webpack_require__(/*! parseqs */ "../ot-core/node_modules/parseqs/index.js"));
- const yeast_1 = __importDefault(__webpack_require__(/*! yeast */ "../ot-core/node_modules/yeast/index.js"));
- const util_js_1 = __webpack_require__(/*! ../util.js */ "../ot-core/node_modules/engine.io-client/build/cjs/util.js");
- const websocket_constructor_js_1 = __webpack_require__(/*! ./websocket-constructor.js */ "../ot-core/node_modules/engine.io-client/build/cjs/transports/websocket-constructor.js");
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const engine_io_parser_1 = __webpack_require__(/*! engine.io-parser */ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js");
- const debug = (0, debug_1.default)("engine.io-client:websocket"); // debug()
- // detect ReactNative environment
- const isReactNative = typeof navigator !== "undefined" &&
- typeof navigator.product === "string" &&
- navigator.product.toLowerCase() === "reactnative";
- class WS extends transport_js_1.Transport {
- /**
- * WebSocket transport constructor.
- *
- * @api {Object} connection options
- * @api public
- */
- constructor(opts) {
- super(opts);
- this.supportsBinary = !opts.forceBase64;
- }
- /**
- * Transport name.
- *
- * @api public
- */
- get name() {
- return "websocket";
- }
- /**
- * Opens socket.
- *
- * @api private
- */
- doOpen() {
- if (!this.check()) {
- // let probe timeout
- return;
- }
- const uri = this.uri();
- const protocols = this.opts.protocols;
- // React Native only supports the 'headers' option, and will print a warning if anything else is passed
- const opts = isReactNative
- ? {}
- : (0, util_js_1.pick)(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
- if (this.opts.extraHeaders) {
- opts.headers = this.opts.extraHeaders;
- }
- try {
- this.ws =
- websocket_constructor_js_1.usingBrowserWebSocket && !isReactNative
- ? protocols
- ? new websocket_constructor_js_1.WebSocket(uri, protocols)
- : new websocket_constructor_js_1.WebSocket(uri)
- : new websocket_constructor_js_1.WebSocket(uri, protocols, opts);
- }
- catch (err) {
- return this.emit("error", err);
- }
- this.ws.binaryType = this.socket.binaryType || websocket_constructor_js_1.defaultBinaryType;
- this.addEventListeners();
- }
- /**
- * Adds event listeners to the socket
- *
- * @api private
- */
- addEventListeners() {
- this.ws.onopen = () => {
- if (this.opts.autoUnref) {
- this.ws._socket.unref();
- }
- this.onOpen();
- };
- this.ws.onclose = this.onClose.bind(this);
- this.ws.onmessage = ev => this.onData(ev.data);
- this.ws.onerror = e => this.onError("websocket error", e);
- }
- /**
- * Writes data to socket.
- *
- * @param {Array} array of packets.
- * @api private
- */
- write(packets) {
- this.writable = false;
- // encodePacket efficient as it uses WS framing
- // no need for encodePayload
- for (let i = 0; i < packets.length; i++) {
- const packet = packets[i];
- const lastPacket = i === packets.length - 1;
- (0, engine_io_parser_1.encodePacket)(packet, this.supportsBinary, data => {
- // always create a new object (GH-437)
- const opts = {};
- if (!websocket_constructor_js_1.usingBrowserWebSocket) {
- if (packet.options) {
- opts.compress = packet.options.compress;
- }
- if (this.opts.perMessageDeflate) {
- const len = "string" === typeof data ? Buffer.byteLength(data) : data.length;
- if (len < this.opts.perMessageDeflate.threshold) {
- opts.compress = false;
- }
- }
- }
- // Sometimes the websocket has already been closed but the browser didn't
- // have a chance of informing us about it yet, in that case send will
- // throw an error
- try {
- if (websocket_constructor_js_1.usingBrowserWebSocket) {
- // TypeError is thrown when passing the second argument on Safari
- this.ws.send(data);
- }
- else {
- this.ws.send(data, opts);
- }
- }
- catch (e) {
- debug("websocket closed before onclose event");
- }
- if (lastPacket) {
- // fake drain
- // defer to next tick to allow Socket to clear writeBuffer
- (0, websocket_constructor_js_1.nextTick)(() => {
- this.writable = true;
- this.emit("drain");
- }, this.setTimeoutFn);
- }
- });
- }
- }
- /**
- * Closes socket.
- *
- * @api private
- */
- doClose() {
- if (typeof this.ws !== "undefined") {
- this.ws.close();
- this.ws = null;
- }
- }
- /**
- * Generates uri for connection.
- *
- * @api private
- */
- uri() {
- let query = this.query || {};
- const schema = this.opts.secure ? "wss" : "ws";
- let port = "";
- // avoid port if default for schema
- if (this.opts.port &&
- (("wss" === schema && Number(this.opts.port) !== 443) ||
- ("ws" === schema && Number(this.opts.port) !== 80))) {
- port = ":" + this.opts.port;
- }
- // append timestamp to URI
- if (this.opts.timestampRequests) {
- query[this.opts.timestampParam] = (0, yeast_1.default)();
- }
- // communicate binary support capabilities
- if (!this.supportsBinary) {
- query.b64 = 1;
- }
- const encodedQuery = parseqs_1.default.encode(query);
- const ipv6 = this.opts.hostname.indexOf(":") !== -1;
- return (schema +
- "://" +
- (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) +
- port +
- this.opts.path +
- (encodedQuery.length ? "?" + encodedQuery : ""));
- }
- /**
- * Feature detection for WebSocket.
- *
- * @return {Boolean} whether this transport is available.
- * @api public
- */
- check() {
- return (!!websocket_constructor_js_1.WebSocket &&
- !("__initialize" in websocket_constructor_js_1.WebSocket && this.name === WS.prototype.name));
- }
- }
- exports.WS = WS;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/transports/xmlhttprequest.js":
- /*!***************************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/transports/xmlhttprequest.js ***!
- \***************************************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
- }) : function(o, v) {
- o["default"] = v;
- });
- var __importStar = (this && this.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
- __setModuleDefault(result, mod);
- return result;
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- const XMLHttpRequestModule = __importStar(__webpack_require__(/*! xmlhttprequest-ssl */ "../ot-core/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js"));
- const XMLHttpRequest = XMLHttpRequestModule.default || XMLHttpRequestModule;
- exports["default"] = XMLHttpRequest;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-client/build/cjs/util.js":
- /*!******************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-client/build/cjs/util.js ***!
- \******************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.installTimerFunctions = exports.pick = void 0;
- const globalThis_js_1 = __importDefault(__webpack_require__(/*! ./globalThis.js */ "../ot-core/node_modules/engine.io-client/build/cjs/globalThis.js"));
- function pick(obj, ...attr) {
- return attr.reduce((acc, k) => {
- if (obj.hasOwnProperty(k)) {
- acc[k] = obj[k];
- }
- return acc;
- }, {});
- }
- exports.pick = pick;
- // Keep a reference to the real timeout functions so they can be used when overridden
- const NATIVE_SET_TIMEOUT = setTimeout;
- const NATIVE_CLEAR_TIMEOUT = clearTimeout;
- function installTimerFunctions(obj, opts) {
- if (opts.useNativeTimers) {
- obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis_js_1.default);
- obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis_js_1.default);
- }
- else {
- obj.setTimeoutFn = setTimeout.bind(globalThis_js_1.default);
- obj.clearTimeoutFn = clearTimeout.bind(globalThis_js_1.default);
- }
- }
- exports.installTimerFunctions = installTimerFunctions;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/commons.js":
- /*!*********************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-parser/build/cjs/commons.js ***!
- \*********************************************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.ERROR_PACKET = exports.PACKET_TYPES_REVERSE = exports.PACKET_TYPES = void 0;
- const PACKET_TYPES = Object.create(null); // no Map = no polyfill
- exports.PACKET_TYPES = PACKET_TYPES;
- PACKET_TYPES["open"] = "0";
- PACKET_TYPES["close"] = "1";
- PACKET_TYPES["ping"] = "2";
- PACKET_TYPES["pong"] = "3";
- PACKET_TYPES["message"] = "4";
- PACKET_TYPES["upgrade"] = "5";
- PACKET_TYPES["noop"] = "6";
- const PACKET_TYPES_REVERSE = Object.create(null);
- exports.PACKET_TYPES_REVERSE = PACKET_TYPES_REVERSE;
- Object.keys(PACKET_TYPES).forEach(key => {
- PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
- });
- const ERROR_PACKET = { type: "error", data: "parser error" };
- exports.ERROR_PACKET = ERROR_PACKET;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/decodePacket.js":
- /*!**************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-parser/build/cjs/decodePacket.js ***!
- \**************************************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- const commons_js_1 = __webpack_require__(/*! ./commons.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/commons.js");
- const decodePacket = (encodedPacket, binaryType) => {
- if (typeof encodedPacket !== "string") {
- return {
- type: "message",
- data: mapBinary(encodedPacket, binaryType)
- };
- }
- const type = encodedPacket.charAt(0);
- if (type === "b") {
- const buffer = Buffer.from(encodedPacket.substring(1), "base64");
- return {
- type: "message",
- data: mapBinary(buffer, binaryType)
- };
- }
- if (!commons_js_1.PACKET_TYPES_REVERSE[type]) {
- return commons_js_1.ERROR_PACKET;
- }
- return encodedPacket.length > 1
- ? {
- type: commons_js_1.PACKET_TYPES_REVERSE[type],
- data: encodedPacket.substring(1)
- }
- : {
- type: commons_js_1.PACKET_TYPES_REVERSE[type]
- };
- };
- const mapBinary = (data, binaryType) => {
- const isBuffer = Buffer.isBuffer(data);
- switch (binaryType) {
- case "arraybuffer":
- return isBuffer ? toArrayBuffer(data) : data;
- case "nodebuffer":
- default:
- return data; // assuming the data is already a Buffer
- }
- };
- const toArrayBuffer = (buffer) => {
- const arrayBuffer = new ArrayBuffer(buffer.length);
- const view = new Uint8Array(arrayBuffer);
- for (let i = 0; i < buffer.length; i++) {
- view[i] = buffer[i];
- }
- return arrayBuffer;
- };
- exports["default"] = decodePacket;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/encodePacket.js":
- /*!**************************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-parser/build/cjs/encodePacket.js ***!
- \**************************************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- const commons_js_1 = __webpack_require__(/*! ./commons.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/commons.js");
- const encodePacket = ({ type, data }, supportsBinary, callback) => {
- if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
- const buffer = toBuffer(data);
- return callback(encodeBuffer(buffer, supportsBinary));
- }
- // plain string
- return callback(commons_js_1.PACKET_TYPES[type] + (data || ""));
- };
- const toBuffer = data => {
- if (Buffer.isBuffer(data)) {
- return data;
- }
- else if (data instanceof ArrayBuffer) {
- return Buffer.from(data);
- }
- else {
- return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
- }
- };
- // only 'message' packets can contain binary, so the type prefix is not needed
- const encodeBuffer = (data, supportsBinary) => {
- return supportsBinary ? data : "b" + data.toString("base64");
- };
- exports["default"] = encodePacket;
- /***/ }),
- /***/ "../ot-core/node_modules/engine.io-parser/build/cjs/index.js":
- /*!*******************************************************************!*\
- !*** ../ot-core/node_modules/engine.io-parser/build/cjs/index.js ***!
- \*******************************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.decodePayload = exports.decodePacket = exports.encodePayload = exports.encodePacket = exports.protocol = void 0;
- const encodePacket_js_1 = __webpack_require__(/*! ./encodePacket.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/encodePacket.js");
- exports.encodePacket = encodePacket_js_1.default;
- const decodePacket_js_1 = __webpack_require__(/*! ./decodePacket.js */ "../ot-core/node_modules/engine.io-parser/build/cjs/decodePacket.js");
- exports.decodePacket = decodePacket_js_1.default;
- const SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
- const encodePayload = (packets, callback) => {
- // some packets may be added to the array while encoding, so the initial length must be saved
- const length = packets.length;
- const encodedPackets = new Array(length);
- let count = 0;
- packets.forEach((packet, i) => {
- // force base64 encoding for binary packets
- (0, encodePacket_js_1.default)(packet, false, encodedPacket => {
- encodedPackets[i] = encodedPacket;
- if (++count === length) {
- callback(encodedPackets.join(SEPARATOR));
- }
- });
- });
- };
- exports.encodePayload = encodePayload;
- const decodePayload = (encodedPayload, binaryType) => {
- const encodedPackets = encodedPayload.split(SEPARATOR);
- const packets = [];
- for (let i = 0; i < encodedPackets.length; i++) {
- const decodedPacket = (0, decodePacket_js_1.default)(encodedPackets[i], binaryType);
- packets.push(decodedPacket);
- if (decodedPacket.type === "error") {
- break;
- }
- }
- return packets;
- };
- exports.decodePayload = decodePayload;
- exports.protocol = 4;
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/build/cjs/index.js":
- /*!*******************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/build/cjs/index.js ***!
- \*******************************************************************/
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports["default"] = exports.connect = exports.io = exports.Socket = exports.Manager = exports.protocol = void 0;
- const url_js_1 = __webpack_require__(/*! ./url.js */ "../ot-core/node_modules/socket.io-client/build/cjs/url.js");
- const manager_js_1 = __webpack_require__(/*! ./manager.js */ "../ot-core/node_modules/socket.io-client/build/cjs/manager.js");
- Object.defineProperty(exports, "Manager", ({ enumerable: true, get: function () { return manager_js_1.Manager; } }));
- const socket_js_1 = __webpack_require__(/*! ./socket.js */ "../ot-core/node_modules/socket.io-client/build/cjs/socket.js");
- Object.defineProperty(exports, "Socket", ({ enumerable: true, get: function () { return socket_js_1.Socket; } }));
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const debug = debug_1.default("socket.io-client"); // debug()
- /**
- * Managers cache.
- */
- const cache = {};
- function lookup(uri, opts) {
- if (typeof uri === "object") {
- opts = uri;
- uri = undefined;
- }
- opts = opts || {};
- const parsed = url_js_1.url(uri, opts.path || "/socket.io");
- const source = parsed.source;
- const id = parsed.id;
- const path = parsed.path;
- const sameNamespace = cache[id] && path in cache[id]["nsps"];
- const newConnection = opts.forceNew ||
- opts["force new connection"] ||
- false === opts.multiplex ||
- sameNamespace;
- let io;
- if (newConnection) {
- debug("ignoring socket cache for %s", source);
- io = new manager_js_1.Manager(source, opts);
- }
- else {
- if (!cache[id]) {
- debug("new io instance for %s", source);
- cache[id] = new manager_js_1.Manager(source, opts);
- }
- io = cache[id];
- }
- if (parsed.query && !opts.query) {
- opts.query = parsed.queryKey;
- }
- return io.socket(parsed.path, opts);
- }
- exports.io = lookup;
- exports.connect = lookup;
- exports["default"] = lookup;
- // so that "lookup" can be used both as a function (e.g. `io(...)`) and as a
- // namespace (e.g. `io.connect(...)`), for backward compatibility
- Object.assign(lookup, {
- Manager: manager_js_1.Manager,
- Socket: socket_js_1.Socket,
- io: lookup,
- connect: lookup,
- });
- /**
- * Protocol version.
- *
- * @public
- */
- 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");
- Object.defineProperty(exports, "protocol", ({ enumerable: true, get: function () { return socket_io_parser_1.protocol; } }));
- module.exports = lookup;
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/build/cjs/manager.js":
- /*!*********************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/build/cjs/manager.js ***!
- \*********************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
- }) : function(o, v) {
- o["default"] = v;
- });
- var __importStar = (this && this.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
- __setModuleDefault(result, mod);
- return result;
- };
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.Manager = void 0;
- const engine_io_client_1 = __webpack_require__(/*! engine.io-client */ "../ot-core/node_modules/engine.io-client/build/cjs/index.js");
- const socket_js_1 = __webpack_require__(/*! ./socket.js */ "../ot-core/node_modules/socket.io-client/build/cjs/socket.js");
- const parser = __importStar(__webpack_require__(/*! socket.io-parser */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js"));
- const on_js_1 = __webpack_require__(/*! ./on.js */ "../ot-core/node_modules/socket.io-client/build/cjs/on.js");
- const backo2_1 = __importDefault(__webpack_require__(/*! backo2 */ "../ot-core/node_modules/backo2/index.js"));
- const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const debug = debug_1.default("socket.io-client:manager"); // debug()
- class Manager extends component_emitter_1.Emitter {
- constructor(uri, opts) {
- var _a;
- super();
- this.nsps = {};
- this.subs = [];
- if (uri && "object" === typeof uri) {
- opts = uri;
- uri = undefined;
- }
- opts = opts || {};
- opts.path = opts.path || "/socket.io";
- this.opts = opts;
- engine_io_client_1.installTimerFunctions(this, opts);
- this.reconnection(opts.reconnection !== false);
- this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
- this.reconnectionDelay(opts.reconnectionDelay || 1000);
- this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
- this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
- this.backoff = new backo2_1.default({
- min: this.reconnectionDelay(),
- max: this.reconnectionDelayMax(),
- jitter: this.randomizationFactor(),
- });
- this.timeout(null == opts.timeout ? 20000 : opts.timeout);
- this._readyState = "closed";
- this.uri = uri;
- const _parser = opts.parser || parser;
- this.encoder = new _parser.Encoder();
- this.decoder = new _parser.Decoder();
- this._autoConnect = opts.autoConnect !== false;
- if (this._autoConnect)
- this.open();
- }
- reconnection(v) {
- if (!arguments.length)
- return this._reconnection;
- this._reconnection = !!v;
- return this;
- }
- reconnectionAttempts(v) {
- if (v === undefined)
- return this._reconnectionAttempts;
- this._reconnectionAttempts = v;
- return this;
- }
- reconnectionDelay(v) {
- var _a;
- if (v === undefined)
- return this._reconnectionDelay;
- this._reconnectionDelay = v;
- (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);
- return this;
- }
- randomizationFactor(v) {
- var _a;
- if (v === undefined)
- return this._randomizationFactor;
- this._randomizationFactor = v;
- (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);
- return this;
- }
- reconnectionDelayMax(v) {
- var _a;
- if (v === undefined)
- return this._reconnectionDelayMax;
- this._reconnectionDelayMax = v;
- (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);
- return this;
- }
- timeout(v) {
- if (!arguments.length)
- return this._timeout;
- this._timeout = v;
- return this;
- }
- /**
- * Starts trying to reconnect if reconnection is enabled and we have not
- * started reconnecting yet
- *
- * @private
- */
- maybeReconnectOnOpen() {
- // Only try to reconnect if it's the first time we're connecting
- if (!this._reconnecting &&
- this._reconnection &&
- this.backoff.attempts === 0) {
- // keeps reconnection from firing twice for the same reconnection loop
- this.reconnect();
- }
- }
- /**
- * Sets the current transport `socket`.
- *
- * @param {Function} fn - optional, callback
- * @return self
- * @public
- */
- open(fn) {
- debug("readyState %s", this._readyState);
- if (~this._readyState.indexOf("open"))
- return this;
- debug("opening %s", this.uri);
- this.engine = new engine_io_client_1.Socket(this.uri, this.opts);
- const socket = this.engine;
- const self = this;
- this._readyState = "opening";
- this.skipReconnect = false;
- // emit `open`
- const openSubDestroy = on_js_1.on(socket, "open", function () {
- self.onopen();
- fn && fn();
- });
- // emit `error`
- const errorSub = on_js_1.on(socket, "error", (err) => {
- debug("error");
- self.cleanup();
- self._readyState = "closed";
- this.emitReserved("error", err);
- if (fn) {
- fn(err);
- }
- else {
- // Only do this if there is no fn to handle the error
- self.maybeReconnectOnOpen();
- }
- });
- if (false !== this._timeout) {
- const timeout = this._timeout;
- debug("connect attempt will timeout after %d", timeout);
- if (timeout === 0) {
- openSubDestroy(); // prevents a race condition with the 'open' event
- }
- // set timer
- const timer = this.setTimeoutFn(() => {
- debug("connect attempt timed out after %d", timeout);
- openSubDestroy();
- socket.close();
- // @ts-ignore
- socket.emit("error", new Error("timeout"));
- }, timeout);
- if (this.opts.autoUnref) {
- timer.unref();
- }
- this.subs.push(function subDestroy() {
- clearTimeout(timer);
- });
- }
- this.subs.push(openSubDestroy);
- this.subs.push(errorSub);
- return this;
- }
- /**
- * Alias for open()
- *
- * @return self
- * @public
- */
- connect(fn) {
- return this.open(fn);
- }
- /**
- * Called upon transport open.
- *
- * @private
- */
- onopen() {
- debug("open");
- // clear old subs
- this.cleanup();
- // mark as open
- this._readyState = "open";
- this.emitReserved("open");
- // add new subs
- const socket = this.engine;
- 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)));
- }
- /**
- * Called upon a ping.
- *
- * @private
- */
- onping() {
- this.emitReserved("ping");
- }
- /**
- * Called with data.
- *
- * @private
- */
- ondata(data) {
- this.decoder.add(data);
- }
- /**
- * Called when parser fully decodes a packet.
- *
- * @private
- */
- ondecoded(packet) {
- this.emitReserved("packet", packet);
- }
- /**
- * Called upon socket error.
- *
- * @private
- */
- onerror(err) {
- debug("error", err);
- this.emitReserved("error", err);
- }
- /**
- * Creates a new socket for the given `nsp`.
- *
- * @return {Socket}
- * @public
- */
- socket(nsp, opts) {
- let socket = this.nsps[nsp];
- if (!socket) {
- socket = new socket_js_1.Socket(this, nsp, opts);
- this.nsps[nsp] = socket;
- }
- return socket;
- }
- /**
- * Called upon a socket close.
- *
- * @param socket
- * @private
- */
- _destroy(socket) {
- const nsps = Object.keys(this.nsps);
- for (const nsp of nsps) {
- const socket = this.nsps[nsp];
- if (socket.active) {
- debug("socket %s is still active, skipping close", nsp);
- return;
- }
- }
- this._close();
- }
- /**
- * Writes a packet.
- *
- * @param packet
- * @private
- */
- _packet(packet) {
- debug("writing packet %j", packet);
- const encodedPackets = this.encoder.encode(packet);
- for (let i = 0; i < encodedPackets.length; i++) {
- this.engine.write(encodedPackets[i], packet.options);
- }
- }
- /**
- * Clean up transport subscriptions and packet buffer.
- *
- * @private
- */
- cleanup() {
- debug("cleanup");
- this.subs.forEach((subDestroy) => subDestroy());
- this.subs.length = 0;
- this.decoder.destroy();
- }
- /**
- * Close the current socket.
- *
- * @private
- */
- _close() {
- debug("disconnect");
- this.skipReconnect = true;
- this._reconnecting = false;
- if ("opening" === this._readyState) {
- // `onclose` will not fire because
- // an open event never happened
- this.cleanup();
- }
- this.backoff.reset();
- this._readyState = "closed";
- if (this.engine)
- this.engine.close();
- }
- /**
- * Alias for close()
- *
- * @private
- */
- disconnect() {
- return this._close();
- }
- /**
- * Called upon engine close.
- *
- * @private
- */
- onclose(reason) {
- debug("onclose");
- this.cleanup();
- this.backoff.reset();
- this._readyState = "closed";
- this.emitReserved("close", reason);
- if (this._reconnection && !this.skipReconnect) {
- this.reconnect();
- }
- }
- /**
- * Attempt a reconnection.
- *
- * @private
- */
- reconnect() {
- if (this._reconnecting || this.skipReconnect)
- return this;
- const self = this;
- if (this.backoff.attempts >= this._reconnectionAttempts) {
- debug("reconnect failed");
- this.backoff.reset();
- this.emitReserved("reconnect_failed");
- this._reconnecting = false;
- }
- else {
- const delay = this.backoff.duration();
- debug("will wait %dms before reconnect attempt", delay);
- this._reconnecting = true;
- const timer = this.setTimeoutFn(() => {
- if (self.skipReconnect)
- return;
- debug("attempting reconnect");
- this.emitReserved("reconnect_attempt", self.backoff.attempts);
- // check again for the case socket closed in above events
- if (self.skipReconnect)
- return;
- self.open((err) => {
- if (err) {
- debug("reconnect attempt error");
- self._reconnecting = false;
- self.reconnect();
- this.emitReserved("reconnect_error", err);
- }
- else {
- debug("reconnect success");
- self.onreconnect();
- }
- });
- }, delay);
- if (this.opts.autoUnref) {
- timer.unref();
- }
- this.subs.push(function subDestroy() {
- clearTimeout(timer);
- });
- }
- }
- /**
- * Called upon successful reconnect.
- *
- * @private
- */
- onreconnect() {
- const attempt = this.backoff.attempts;
- this._reconnecting = false;
- this.backoff.reset();
- this.emitReserved("reconnect", attempt);
- }
- }
- exports.Manager = Manager;
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/build/cjs/on.js":
- /*!****************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/build/cjs/on.js ***!
- \****************************************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.on = void 0;
- function on(obj, ev, fn) {
- obj.on(ev, fn);
- return function subDestroy() {
- obj.off(ev, fn);
- };
- }
- exports.on = on;
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/build/cjs/socket.js":
- /*!********************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/build/cjs/socket.js ***!
- \********************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.Socket = void 0;
- 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");
- const on_js_1 = __webpack_require__(/*! ./on.js */ "../ot-core/node_modules/socket.io-client/build/cjs/on.js");
- const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const debug = debug_1.default("socket.io-client:socket"); // debug()
- /**
- * Internal events.
- * These events can't be emitted by the user.
- */
- const RESERVED_EVENTS = Object.freeze({
- connect: 1,
- connect_error: 1,
- disconnect: 1,
- disconnecting: 1,
- // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
- newListener: 1,
- removeListener: 1,
- });
- class Socket extends component_emitter_1.Emitter {
- /**
- * `Socket` constructor.
- *
- * @public
- */
- constructor(io, nsp, opts) {
- super();
- this.connected = false;
- this.disconnected = true;
- this.receiveBuffer = [];
- this.sendBuffer = [];
- this.ids = 0;
- this.acks = {};
- this.flags = {};
- this.io = io;
- this.nsp = nsp;
- if (opts && opts.auth) {
- this.auth = opts.auth;
- }
- if (this.io._autoConnect)
- this.open();
- }
- /**
- * Subscribe to open, close and packet events
- *
- * @private
- */
- subEvents() {
- if (this.subs)
- return;
- const io = this.io;
- this.subs = [
- on_js_1.on(io, "open", this.onopen.bind(this)),
- on_js_1.on(io, "packet", this.onpacket.bind(this)),
- on_js_1.on(io, "error", this.onerror.bind(this)),
- on_js_1.on(io, "close", this.onclose.bind(this)),
- ];
- }
- /**
- * Whether the Socket will try to reconnect when its Manager connects or reconnects
- */
- get active() {
- return !!this.subs;
- }
- /**
- * "Opens" the socket.
- *
- * @public
- */
- connect() {
- if (this.connected)
- return this;
- this.subEvents();
- if (!this.io["_reconnecting"])
- this.io.open(); // ensure open
- if ("open" === this.io._readyState)
- this.onopen();
- return this;
- }
- /**
- * Alias for connect()
- */
- open() {
- return this.connect();
- }
- /**
- * Sends a `message` event.
- *
- * @return self
- * @public
- */
- send(...args) {
- args.unshift("message");
- this.emit.apply(this, args);
- return this;
- }
- /**
- * Override `emit`.
- * If the event is in `events`, it's emitted normally.
- *
- * @return self
- * @public
- */
- emit(ev, ...args) {
- if (RESERVED_EVENTS.hasOwnProperty(ev)) {
- throw new Error('"' + ev + '" is a reserved event name');
- }
- args.unshift(ev);
- const packet = {
- type: socket_io_parser_1.PacketType.EVENT,
- data: args,
- };
- packet.options = {};
- packet.options.compress = this.flags.compress !== false;
- // event ack callback
- if ("function" === typeof args[args.length - 1]) {
- debug("emitting packet with ack id %d", this.ids);
- this.acks[this.ids] = args.pop();
- packet.id = this.ids++;
- }
- const isTransportWritable = this.io.engine &&
- this.io.engine.transport &&
- this.io.engine.transport.writable;
- const discardPacket = this.flags.volatile && (!isTransportWritable || !this.connected);
- if (discardPacket) {
- debug("discard packet as the transport is not currently writable");
- }
- else if (this.connected) {
- this.packet(packet);
- }
- else {
- this.sendBuffer.push(packet);
- }
- this.flags = {};
- return this;
- }
- /**
- * Sends a packet.
- *
- * @param packet
- * @private
- */
- packet(packet) {
- packet.nsp = this.nsp;
- this.io._packet(packet);
- }
- /**
- * Called upon engine `open`.
- *
- * @private
- */
- onopen() {
- debug("transport is open - connecting");
- if (typeof this.auth == "function") {
- this.auth((data) => {
- this.packet({ type: socket_io_parser_1.PacketType.CONNECT, data });
- });
- }
- else {
- this.packet({ type: socket_io_parser_1.PacketType.CONNECT, data: this.auth });
- }
- }
- /**
- * Called upon engine or manager `error`.
- *
- * @param err
- * @private
- */
- onerror(err) {
- if (!this.connected) {
- this.emitReserved("connect_error", err);
- }
- }
- /**
- * Called upon engine `close`.
- *
- * @param reason
- * @private
- */
- onclose(reason) {
- debug("close (%s)", reason);
- this.connected = false;
- this.disconnected = true;
- delete this.id;
- this.emitReserved("disconnect", reason);
- }
- /**
- * Called with socket packet.
- *
- * @param packet
- * @private
- */
- onpacket(packet) {
- const sameNamespace = packet.nsp === this.nsp;
- if (!sameNamespace)
- return;
- switch (packet.type) {
- case socket_io_parser_1.PacketType.CONNECT:
- if (packet.data && packet.data.sid) {
- const id = packet.data.sid;
- this.onconnect(id);
- }
- else {
- 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/)"));
- }
- break;
- case socket_io_parser_1.PacketType.EVENT:
- this.onevent(packet);
- break;
- case socket_io_parser_1.PacketType.BINARY_EVENT:
- this.onevent(packet);
- break;
- case socket_io_parser_1.PacketType.ACK:
- this.onack(packet);
- break;
- case socket_io_parser_1.PacketType.BINARY_ACK:
- this.onack(packet);
- break;
- case socket_io_parser_1.PacketType.DISCONNECT:
- this.ondisconnect();
- break;
- case socket_io_parser_1.PacketType.CONNECT_ERROR:
- const err = new Error(packet.data.message);
- // @ts-ignore
- err.data = packet.data.data;
- this.emitReserved("connect_error", err);
- break;
- }
- }
- /**
- * Called upon a server event.
- *
- * @param packet
- * @private
- */
- onevent(packet) {
- const args = packet.data || [];
- debug("emitting event %j", args);
- if (null != packet.id) {
- debug("attaching ack callback to event");
- args.push(this.ack(packet.id));
- }
- if (this.connected) {
- this.emitEvent(args);
- }
- else {
- this.receiveBuffer.push(Object.freeze(args));
- }
- }
- emitEvent(args) {
- if (this._anyListeners && this._anyListeners.length) {
- const listeners = this._anyListeners.slice();
- for (const listener of listeners) {
- listener.apply(this, args);
- }
- }
- super.emit.apply(this, args);
- }
- /**
- * Produces an ack callback to emit with an event.
- *
- * @private
- */
- ack(id) {
- const self = this;
- let sent = false;
- return function (...args) {
- // prevent double callbacks
- if (sent)
- return;
- sent = true;
- debug("sending ack %j", args);
- self.packet({
- type: socket_io_parser_1.PacketType.ACK,
- id: id,
- data: args,
- });
- };
- }
- /**
- * Called upon a server acknowlegement.
- *
- * @param packet
- * @private
- */
- onack(packet) {
- const ack = this.acks[packet.id];
- if ("function" === typeof ack) {
- debug("calling ack %s with %j", packet.id, packet.data);
- ack.apply(this, packet.data);
- delete this.acks[packet.id];
- }
- else {
- debug("bad ack %s", packet.id);
- }
- }
- /**
- * Called upon server connect.
- *
- * @private
- */
- onconnect(id) {
- debug("socket connected with id %s", id);
- this.id = id;
- this.connected = true;
- this.disconnected = false;
- this.emitBuffered();
- this.emitReserved("connect");
- }
- /**
- * Emit buffered events (received and emitted).
- *
- * @private
- */
- emitBuffered() {
- this.receiveBuffer.forEach((args) => this.emitEvent(args));
- this.receiveBuffer = [];
- this.sendBuffer.forEach((packet) => this.packet(packet));
- this.sendBuffer = [];
- }
- /**
- * Called upon server disconnect.
- *
- * @private
- */
- ondisconnect() {
- debug("server disconnect (%s)", this.nsp);
- this.destroy();
- this.onclose("io server disconnect");
- }
- /**
- * Called upon forced client/server side disconnections,
- * this method ensures the manager stops tracking us and
- * that reconnections don't get triggered for this.
- *
- * @private
- */
- destroy() {
- if (this.subs) {
- // clean subscriptions to avoid reconnections
- this.subs.forEach((subDestroy) => subDestroy());
- this.subs = undefined;
- }
- this.io["_destroy"](this);
- }
- /**
- * Disconnects the socket manually.
- *
- * @return self
- * @public
- */
- disconnect() {
- if (this.connected) {
- debug("performing disconnect (%s)", this.nsp);
- this.packet({ type: socket_io_parser_1.PacketType.DISCONNECT });
- }
- // remove socket from pool
- this.destroy();
- if (this.connected) {
- // fire events
- this.onclose("io client disconnect");
- }
- return this;
- }
- /**
- * Alias for disconnect()
- *
- * @return self
- * @public
- */
- close() {
- return this.disconnect();
- }
- /**
- * Sets the compress flag.
- *
- * @param compress - if `true`, compresses the sending data
- * @return self
- * @public
- */
- compress(compress) {
- this.flags.compress = compress;
- return this;
- }
- /**
- * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
- * ready to send messages.
- *
- * @returns self
- * @public
- */
- get volatile() {
- this.flags.volatile = true;
- return this;
- }
- /**
- * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
- * callback.
- *
- * @param listener
- * @public
- */
- onAny(listener) {
- this._anyListeners = this._anyListeners || [];
- this._anyListeners.push(listener);
- return this;
- }
- /**
- * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
- * callback. The listener is added to the beginning of the listeners array.
- *
- * @param listener
- * @public
- */
- prependAny(listener) {
- this._anyListeners = this._anyListeners || [];
- this._anyListeners.unshift(listener);
- return this;
- }
- /**
- * Removes the listener that will be fired when any event is emitted.
- *
- * @param listener
- * @public
- */
- offAny(listener) {
- if (!this._anyListeners) {
- return this;
- }
- if (listener) {
- const listeners = this._anyListeners;
- for (let i = 0; i < listeners.length; i++) {
- if (listener === listeners[i]) {
- listeners.splice(i, 1);
- return this;
- }
- }
- }
- else {
- this._anyListeners = [];
- }
- return this;
- }
- /**
- * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
- * e.g. to remove listeners.
- *
- * @public
- */
- listenersAny() {
- return this._anyListeners || [];
- }
- }
- exports.Socket = Socket;
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/build/cjs/url.js":
- /*!*****************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/build/cjs/url.js ***!
- \*****************************************************************/
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.url = void 0;
- const parseuri_1 = __importDefault(__webpack_require__(/*! parseuri */ "../ot-core/node_modules/parseuri/index.js"));
- const debug_1 = __importDefault(__webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js")); // debug()
- const debug = debug_1.default("socket.io-client:url"); // debug()
- /**
- * URL parser.
- *
- * @param uri - url
- * @param path - the request path of the connection
- * @param loc - An object meant to mimic window.location.
- * Defaults to window.location.
- * @public
- */
- function url(uri, path = "", loc) {
- let obj = uri;
- // default to window.location
- loc = loc || (typeof location !== "undefined" && location);
- if (null == uri)
- uri = loc.protocol + "//" + loc.host;
- // relative path support
- if (typeof uri === "string") {
- if ("/" === uri.charAt(0)) {
- if ("/" === uri.charAt(1)) {
- uri = loc.protocol + uri;
- }
- else {
- uri = loc.host + uri;
- }
- }
- if (!/^(https?|wss?):\/\//.test(uri)) {
- debug("protocol-less url %s", uri);
- if ("undefined" !== typeof loc) {
- uri = loc.protocol + "//" + uri;
- }
- else {
- uri = "https://" + uri;
- }
- }
- // parse
- debug("parse %s", uri);
- obj = parseuri_1.default(uri);
- }
- // make sure we treat `localhost:80` and `localhost` equally
- if (!obj.port) {
- if (/^(http|ws)$/.test(obj.protocol)) {
- obj.port = "80";
- }
- else if (/^(http|ws)s$/.test(obj.protocol)) {
- obj.port = "443";
- }
- }
- obj.path = obj.path || "/";
- const ipv6 = obj.host.indexOf(":") !== -1;
- const host = ipv6 ? "[" + obj.host + "]" : obj.host;
- // define unique id
- obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
- // define href
- obj.href =
- obj.protocol +
- "://" +
- host +
- (loc && loc.port === obj.port ? "" : ":" + obj.port);
- return obj;
- }
- exports.url = url;
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/binary.js":
- /*!**************************************************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/binary.js ***!
- \**************************************************************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.reconstructPacket = exports.deconstructPacket = void 0;
- 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");
- /**
- * Replaces every Buffer | ArrayBuffer | Blob | File in packet with a numbered placeholder.
- *
- * @param {Object} packet - socket.io event packet
- * @return {Object} with deconstructed packet and list of buffers
- * @public
- */
- function deconstructPacket(packet) {
- const buffers = [];
- const packetData = packet.data;
- const pack = packet;
- pack.data = _deconstructPacket(packetData, buffers);
- pack.attachments = buffers.length; // number of binary 'attachments'
- return { packet: pack, buffers: buffers };
- }
- exports.deconstructPacket = deconstructPacket;
- function _deconstructPacket(data, buffers) {
- if (!data)
- return data;
- if (is_binary_js_1.isBinary(data)) {
- const placeholder = { _placeholder: true, num: buffers.length };
- buffers.push(data);
- return placeholder;
- }
- else if (Array.isArray(data)) {
- const newData = new Array(data.length);
- for (let i = 0; i < data.length; i++) {
- newData[i] = _deconstructPacket(data[i], buffers);
- }
- return newData;
- }
- else if (typeof data === "object" && !(data instanceof Date)) {
- const newData = {};
- for (const key in data) {
- if (Object.prototype.hasOwnProperty.call(data, key)) {
- newData[key] = _deconstructPacket(data[key], buffers);
- }
- }
- return newData;
- }
- return data;
- }
- /**
- * Reconstructs a binary packet from its placeholder packet and buffers
- *
- * @param {Object} packet - event packet with placeholders
- * @param {Array} buffers - binary buffers to put in placeholder positions
- * @return {Object} reconstructed packet
- * @public
- */
- function reconstructPacket(packet, buffers) {
- packet.data = _reconstructPacket(packet.data, buffers);
- packet.attachments = undefined; // no longer useful
- return packet;
- }
- exports.reconstructPacket = reconstructPacket;
- function _reconstructPacket(data, buffers) {
- if (!data)
- return data;
- if (data && data._placeholder) {
- return buffers[data.num]; // appropriate buffer (should be natural order anyway)
- }
- else if (Array.isArray(data)) {
- for (let i = 0; i < data.length; i++) {
- data[i] = _reconstructPacket(data[i], buffers);
- }
- }
- else if (typeof data === "object") {
- for (const key in data) {
- if (Object.prototype.hasOwnProperty.call(data, key)) {
- data[key] = _reconstructPacket(data[key], buffers);
- }
- }
- }
- return data;
- }
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js":
- /*!*************************************************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/index.js ***!
- \*************************************************************************************************/
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.Decoder = exports.Encoder = exports.PacketType = exports.protocol = void 0;
- const component_emitter_1 = __webpack_require__(/*! @socket.io/component-emitter */ "../ot-core/node_modules/@socket.io/component-emitter/index.js");
- const binary_js_1 = __webpack_require__(/*! ./binary.js */ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/binary.js");
- 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");
- const debug_1 = __webpack_require__(/*! debug */ "../ot-core/node_modules/debug/src/index.js"); // debug()
- const debug = debug_1.default("socket.io-parser"); // debug()
- /**
- * Protocol version.
- *
- * @public
- */
- exports.protocol = 5;
- var PacketType;
- (function (PacketType) {
- PacketType[PacketType["CONNECT"] = 0] = "CONNECT";
- PacketType[PacketType["DISCONNECT"] = 1] = "DISCONNECT";
- PacketType[PacketType["EVENT"] = 2] = "EVENT";
- PacketType[PacketType["ACK"] = 3] = "ACK";
- PacketType[PacketType["CONNECT_ERROR"] = 4] = "CONNECT_ERROR";
- PacketType[PacketType["BINARY_EVENT"] = 5] = "BINARY_EVENT";
- PacketType[PacketType["BINARY_ACK"] = 6] = "BINARY_ACK";
- })(PacketType = exports.PacketType || (exports.PacketType = {}));
- /**
- * A socket.io Encoder instance
- */
- class Encoder {
- /**
- * Encode a packet as a single string if non-binary, or as a
- * buffer sequence, depending on packet type.
- *
- * @param {Object} obj - packet object
- */
- encode(obj) {
- debug("encoding packet %j", obj);
- if (obj.type === PacketType.EVENT || obj.type === PacketType.ACK) {
- if (is_binary_js_1.hasBinary(obj)) {
- obj.type =
- obj.type === PacketType.EVENT
- ? PacketType.BINARY_EVENT
- : PacketType.BINARY_ACK;
- return this.encodeAsBinary(obj);
- }
- }
- return [this.encodeAsString(obj)];
- }
- /**
- * Encode packet as string.
- */
- encodeAsString(obj) {
- // first is type
- let str = "" + obj.type;
- // attachments if we have them
- if (obj.type === PacketType.BINARY_EVENT ||
- obj.type === PacketType.BINARY_ACK) {
- str += obj.attachments + "-";
- }
- // if we have a namespace other than `/`
- // we append it followed by a comma `,`
- if (obj.nsp && "/" !== obj.nsp) {
- str += obj.nsp + ",";
- }
- // immediately followed by the id
- if (null != obj.id) {
- str += obj.id;
- }
- // json data
- if (null != obj.data) {
- str += JSON.stringify(obj.data);
- }
- debug("encoded %j as %s", obj, str);
- return str;
- }
- /**
- * Encode packet as 'buffer sequence' by removing blobs, and
- * deconstructing packet into object with placeholders and
- * a list of buffers.
- */
- encodeAsBinary(obj) {
- const deconstruction = binary_js_1.deconstructPacket(obj);
- const pack = this.encodeAsString(deconstruction.packet);
- const buffers = deconstruction.buffers;
- buffers.unshift(pack); // add packet info to beginning of data list
- return buffers; // write all the buffers
- }
- }
- exports.Encoder = Encoder;
- /**
- * A socket.io Decoder instance
- *
- * @return {Object} decoder
- */
- class Decoder extends component_emitter_1.Emitter {
- constructor() {
- super();
- }
- /**
- * Decodes an encoded packet string into packet JSON.
- *
- * @param {String} obj - encoded packet
- */
- add(obj) {
- let packet;
- if (typeof obj === "string") {
- packet = this.decodeString(obj);
- if (packet.type === PacketType.BINARY_EVENT ||
- packet.type === PacketType.BINARY_ACK) {
- // binary packet's json
- this.reconstructor = new BinaryReconstructor(packet);
- // no attachments, labeled binary but no binary data to follow
- if (packet.attachments === 0) {
- super.emitReserved("decoded", packet);
- }
- }
- else {
- // non-binary full packet
- super.emitReserved("decoded", packet);
- }
- }
- else if (is_binary_js_1.isBinary(obj) || obj.base64) {
- // raw binary data
- if (!this.reconstructor) {
- throw new Error("got binary data when not reconstructing a packet");
- }
- else {
- packet = this.reconstructor.takeBinaryData(obj);
- if (packet) {
- // received final buffer
- this.reconstructor = null;
- super.emitReserved("decoded", packet);
- }
- }
- }
- else {
- throw new Error("Unknown type: " + obj);
- }
- }
- /**
- * Decode a packet String (JSON data)
- *
- * @param {String} str
- * @return {Object} packet
- */
- decodeString(str) {
- let i = 0;
- // look up type
- const p = {
- type: Number(str.charAt(0)),
- };
- if (PacketType[p.type] === undefined) {
- throw new Error("unknown packet type " + p.type);
- }
- // look up attachments if type binary
- if (p.type === PacketType.BINARY_EVENT ||
- p.type === PacketType.BINARY_ACK) {
- const start = i + 1;
- while (str.charAt(++i) !== "-" && i != str.length) { }
- const buf = str.substring(start, i);
- if (buf != Number(buf) || str.charAt(i) !== "-") {
- throw new Error("Illegal attachments");
- }
- p.attachments = Number(buf);
- }
- // look up namespace (if any)
- if ("/" === str.charAt(i + 1)) {
- const start = i + 1;
- while (++i) {
- const c = str.charAt(i);
- if ("," === c)
- break;
- if (i === str.length)
- break;
- }
- p.nsp = str.substring(start, i);
- }
- else {
- p.nsp = "/";
- }
- // look up id
- const next = str.charAt(i + 1);
- if ("" !== next && Number(next) == next) {
- const start = i + 1;
- while (++i) {
- const c = str.charAt(i);
- if (null == c || Number(c) != c) {
- --i;
- break;
- }
- if (i === str.length)
- break;
- }
- p.id = Number(str.substring(start, i + 1));
- }
- // look up json data
- if (str.charAt(++i)) {
- const payload = tryParse(str.substr(i));
- if (Decoder.isPayloadValid(p.type, payload)) {
- p.data = payload;
- }
- else {
- throw new Error("invalid payload");
- }
- }
- debug("decoded %s as %j", str, p);
- return p;
- }
- static isPayloadValid(type, payload) {
- switch (type) {
- case PacketType.CONNECT:
- return typeof payload === "object";
- case PacketType.DISCONNECT:
- return payload === undefined;
- case PacketType.CONNECT_ERROR:
- return typeof payload === "string" || typeof payload === "object";
- case PacketType.EVENT:
- case PacketType.BINARY_EVENT:
- return Array.isArray(payload) && payload.length > 0;
- case PacketType.ACK:
- case PacketType.BINARY_ACK:
- return Array.isArray(payload);
- }
- }
- /**
- * Deallocates a parser's resources
- */
- destroy() {
- if (this.reconstructor) {
- this.reconstructor.finishedReconstruction();
- }
- }
- }
- exports.Decoder = Decoder;
- function tryParse(str) {
- try {
- return JSON.parse(str);
- }
- catch (e) {
- return false;
- }
- }
- /**
- * A manager of a binary event's 'buffer sequence'. Should
- * be constructed whenever a packet of type BINARY_EVENT is
- * decoded.
- *
- * @param {Object} packet
- * @return {BinaryReconstructor} initialized reconstructor
- */
- class BinaryReconstructor {
- constructor(packet) {
- this.packet = packet;
- this.buffers = [];
- this.reconPack = packet;
- }
- /**
- * Method to be called when binary data received from connection
- * after a BINARY_EVENT packet.
- *
- * @param {Buffer | ArrayBuffer} binData - the raw binary data received
- * @return {null | Object} returns null if more binary data is expected or
- * a reconstructed packet object if all buffers have been received.
- */
- takeBinaryData(binData) {
- this.buffers.push(binData);
- if (this.buffers.length === this.reconPack.attachments) {
- // done with buffer list
- const packet = binary_js_1.reconstructPacket(this.reconPack, this.buffers);
- this.finishedReconstruction();
- return packet;
- }
- return null;
- }
- /**
- * Cleans up binary packet reconstruction variables.
- */
- finishedReconstruction() {
- this.reconPack = null;
- this.buffers = [];
- }
- }
- /***/ }),
- /***/ "../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/is-binary.js":
- /*!*****************************************************************************************************!*\
- !*** ../ot-core/node_modules/socket.io-client/node_modules/socket.io-parser/build/cjs/is-binary.js ***!
- \*****************************************************************************************************/
- /***/ ((__unused_webpack_module, exports) => {
- "use strict";
- Object.defineProperty(exports, "__esModule", ({ value: true }));
- exports.hasBinary = exports.isBinary = void 0;
- const withNativeArrayBuffer = typeof ArrayBuffer === "function";
- const isView = (obj) => {
- return typeof ArrayBuffer.isView === "function"
- ? ArrayBuffer.isView(obj)
- : obj.buffer instanceof ArrayBuffer;
- };
- const toString = Object.prototype.toString;
- const withNativeBlob = typeof Blob === "function" ||
- (typeof Blob !== "undefined" &&
- toString.call(Blob) === "[object BlobConstructor]");
- const withNativeFile = typeof File === "function" ||
- (typeof File !== "undefined" &&
- toString.call(File) === "[object FileConstructor]");
- /**
- * Returns true if obj is a Buffer, an ArrayBuffer, a Blob or a File.
- *
- * @private
- */
- function isBinary(obj) {
- return ((withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj))) ||
- (withNativeBlob && obj instanceof Blob) ||
- (withNativeFile && obj instanceof File));
- }
- exports.isBinary = isBinary;
- function hasBinary(obj, toJSON) {
- if (!obj || typeof obj !== "object") {
- return false;
- }
- if (Array.isArray(obj)) {
- for (let i = 0, l = obj.length; i < l; i++) {
- if (hasBinary(obj[i])) {
- return true;
- }
- }
- return false;
- }
- if (isBinary(obj)) {
- return true;
- }
- if (obj.toJSON &&
- typeof obj.toJSON === "function" &&
- arguments.length === 1) {
- return hasBinary(obj.toJSON(), true);
- }
- for (const key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
- return true;
- }
- }
- return false;
- }
- exports.hasBinary = hasBinary;
- /***/ })
- /******/ });
- /************************************************************************/
- /******/ // The module cache
- /******/ var __webpack_module_cache__ = {};
- /******/
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/ // Check if module is in cache
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
- /******/ if (cachedModule !== undefined) {
- /******/ return cachedModule.exports;
- /******/ }
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = __webpack_module_cache__[moduleId] = {
- /******/ // no module.id needed
- /******/ // no module.loaded needed
- /******/ exports: {}
- /******/ };
- /******/
- /******/ // Execute the module function
- /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
- /******/
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/
- /************************************************************************/
- /******/
- /******/ // startup
- /******/ // Load entry module and return exports
- /******/ // This entry module is referenced by other modules so it can't be inlined
- /******/ var __webpack_exports__ = __webpack_require__("./src/server.ts");
- /******/
- /******/ return __webpack_exports__;
- /******/ })()
- ;
- });
- //# sourceMappingURL=server.js.map
|