socket.io.dev.js 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254
  1. /*!
  2. * Socket.IO v2.3.0
  3. * (c) 2014-2019 Guillermo Rauch
  4. * Released under the MIT License.
  5. */
  6. (function webpackUniversalModuleDefinition(root, factory) {
  7. if(typeof exports === 'object' && typeof module === 'object')
  8. module.exports = factory();
  9. else if(typeof define === 'function' && define.amd)
  10. define([], factory);
  11. else if(typeof exports === 'object')
  12. exports["io"] = factory();
  13. else
  14. root["io"] = factory();
  15. })(this, function() {
  16. return /******/ (function(modules) { // webpackBootstrap
  17. /******/ // The module cache
  18. /******/ var installedModules = {};
  19. /******/
  20. /******/ // The require function
  21. /******/ function __webpack_require__(moduleId) {
  22. /******/
  23. /******/ // Check if module is in cache
  24. /******/ if(installedModules[moduleId])
  25. /******/ return installedModules[moduleId].exports;
  26. /******/
  27. /******/ // Create a new module (and put it into the cache)
  28. /******/ var module = installedModules[moduleId] = {
  29. /******/ exports: {},
  30. /******/ id: moduleId,
  31. /******/ loaded: false
  32. /******/ };
  33. /******/
  34. /******/ // Execute the module function
  35. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  36. /******/
  37. /******/ // Flag the module as loaded
  38. /******/ module.loaded = true;
  39. /******/
  40. /******/ // Return the exports of the module
  41. /******/ return module.exports;
  42. /******/ }
  43. /******/
  44. /******/
  45. /******/ // expose the modules object (__webpack_modules__)
  46. /******/ __webpack_require__.m = modules;
  47. /******/
  48. /******/ // expose the module cache
  49. /******/ __webpack_require__.c = installedModules;
  50. /******/
  51. /******/ // __webpack_public_path__
  52. /******/ __webpack_require__.p = "";
  53. /******/
  54. /******/ // Load entry module and return exports
  55. /******/ return __webpack_require__(0);
  56. /******/ })
  57. /************************************************************************/
  58. /******/ ([
  59. /* 0 */
  60. /***/ (function(module, exports, __webpack_require__) {
  61. /**
  62. * Module dependencies.
  63. */
  64. var url = __webpack_require__(1);
  65. var parser = __webpack_require__(7);
  66. var Manager = __webpack_require__(15);
  67. var debug = __webpack_require__(3)('socket.io-client');
  68. /**
  69. * Module exports.
  70. */
  71. module.exports = exports = lookup;
  72. /**
  73. * Managers cache.
  74. */
  75. var cache = exports.managers = {};
  76. /**
  77. * Looks up an existing `Manager` for multiplexing.
  78. * If the user summons:
  79. *
  80. * `io('http://localhost/a');`
  81. * `io('http://localhost/b');`
  82. *
  83. * We reuse the existing instance based on same scheme/port/host,
  84. * and we initialize sockets for each namespace.
  85. *
  86. * @api public
  87. */
  88. function lookup (uri, opts) {
  89. if (typeof uri === 'object') {
  90. opts = uri;
  91. uri = undefined;
  92. }
  93. opts = opts || {};
  94. var parsed = url(uri);
  95. var source = parsed.source;
  96. var id = parsed.id;
  97. var path = parsed.path;
  98. var sameNamespace = cache[id] && path in cache[id].nsps;
  99. var newConnection = opts.forceNew || opts['force new connection'] ||
  100. false === opts.multiplex || sameNamespace;
  101. var io;
  102. if (newConnection) {
  103. debug('ignoring socket cache for %s', source);
  104. io = Manager(source, opts);
  105. } else {
  106. if (!cache[id]) {
  107. debug('new io instance for %s', source);
  108. cache[id] = Manager(source, opts);
  109. }
  110. io = cache[id];
  111. }
  112. if (parsed.query && !opts.query) {
  113. opts.query = parsed.query;
  114. }
  115. return io.socket(parsed.path, opts);
  116. }
  117. /**
  118. * Protocol version.
  119. *
  120. * @api public
  121. */
  122. exports.protocol = parser.protocol;
  123. /**
  124. * `connect`.
  125. *
  126. * @param {String} uri
  127. * @api public
  128. */
  129. exports.connect = lookup;
  130. /**
  131. * Expose constructors for standalone build.
  132. *
  133. * @api public
  134. */
  135. exports.Manager = __webpack_require__(15);
  136. exports.Socket = __webpack_require__(39);
  137. /***/ }),
  138. /* 1 */
  139. /***/ (function(module, exports, __webpack_require__) {
  140. /**
  141. * Module dependencies.
  142. */
  143. var parseuri = __webpack_require__(2);
  144. var debug = __webpack_require__(3)('socket.io-client:url');
  145. /**
  146. * Module exports.
  147. */
  148. module.exports = url;
  149. /**
  150. * URL parser.
  151. *
  152. * @param {String} url
  153. * @param {Object} An object meant to mimic window.location.
  154. * Defaults to window.location.
  155. * @api public
  156. */
  157. function url (uri, loc) {
  158. var obj = uri;
  159. // default to window.location
  160. loc = loc || (typeof location !== 'undefined' && location);
  161. if (null == uri) uri = loc.protocol + '//' + loc.host;
  162. // relative path support
  163. if ('string' === typeof uri) {
  164. if ('/' === uri.charAt(0)) {
  165. if ('/' === uri.charAt(1)) {
  166. uri = loc.protocol + uri;
  167. } else {
  168. uri = loc.host + uri;
  169. }
  170. }
  171. if (!/^(https?|wss?):\/\//.test(uri)) {
  172. debug('protocol-less url %s', uri);
  173. if ('undefined' !== typeof loc) {
  174. uri = loc.protocol + '//' + uri;
  175. } else {
  176. uri = 'https://' + uri;
  177. }
  178. }
  179. // parse
  180. debug('parse %s', uri);
  181. obj = parseuri(uri);
  182. }
  183. // make sure we treat `localhost:80` and `localhost` equally
  184. if (!obj.port) {
  185. if (/^(http|ws)$/.test(obj.protocol)) {
  186. obj.port = '80';
  187. } else if (/^(http|ws)s$/.test(obj.protocol)) {
  188. obj.port = '443';
  189. }
  190. }
  191. obj.path = obj.path || '/';
  192. var ipv6 = obj.host.indexOf(':') !== -1;
  193. var host = ipv6 ? '[' + obj.host + ']' : obj.host;
  194. // define unique id
  195. obj.id = obj.protocol + '://' + host + ':' + obj.port;
  196. // define href
  197. obj.href = obj.protocol + '://' + host + (loc && loc.port === obj.port ? '' : (':' + obj.port));
  198. return obj;
  199. }
  200. /***/ }),
  201. /* 2 */
  202. /***/ (function(module, exports) {
  203. /**
  204. * Parses an URI
  205. *
  206. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  207. * @api private
  208. */
  209. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  210. var parts = [
  211. 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
  212. ];
  213. module.exports = function parseuri(str) {
  214. var src = str,
  215. b = str.indexOf('['),
  216. e = str.indexOf(']');
  217. if (b != -1 && e != -1) {
  218. str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
  219. }
  220. var m = re.exec(str || ''),
  221. uri = {},
  222. i = 14;
  223. while (i--) {
  224. uri[parts[i]] = m[i] || '';
  225. }
  226. if (b != -1 && e != -1) {
  227. uri.source = src;
  228. uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
  229. uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
  230. uri.ipv6uri = true;
  231. }
  232. return uri;
  233. };
  234. /***/ }),
  235. /* 3 */
  236. /***/ (function(module, exports, __webpack_require__) {
  237. /* WEBPACK VAR INJECTION */(function(process) {'use strict';
  238. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  239. /* eslint-env browser */
  240. /**
  241. * This is the web browser implementation of `debug()`.
  242. */
  243. exports.log = log;
  244. exports.formatArgs = formatArgs;
  245. exports.save = save;
  246. exports.load = load;
  247. exports.useColors = useColors;
  248. exports.storage = localstorage();
  249. /**
  250. * Colors.
  251. */
  252. 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'];
  253. /**
  254. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  255. * and the Firebug extension (any Firefox version) are known
  256. * to support "%c" CSS customizations.
  257. *
  258. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  259. */
  260. // eslint-disable-next-line complexity
  261. function useColors() {
  262. // NB: In an Electron preload script, document will be defined but not fully
  263. // initialized. Since we know we're in Chrome, we'll just detect this case
  264. // explicitly
  265. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  266. return true;
  267. }
  268. // Internet Explorer and Edge do not support colors.
  269. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  270. return false;
  271. }
  272. // Is webkit? http://stackoverflow.com/a/16459606/376773
  273. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  274. return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance ||
  275. // Is firebug? http://stackoverflow.com/a/398120/376773
  276. typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) ||
  277. // Is firefox >= v31?
  278. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  279. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 ||
  280. // Double check webkit in userAgent just in case we are in a worker
  281. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
  282. }
  283. /**
  284. * Colorize log arguments if enabled.
  285. *
  286. * @api public
  287. */
  288. function formatArgs(args) {
  289. args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
  290. if (!this.useColors) {
  291. return;
  292. }
  293. var c = 'color: ' + this.color;
  294. args.splice(1, 0, c, 'color: inherit');
  295. // The final "%c" is somewhat tricky, because there could be other
  296. // arguments passed either before or after the %c, so we need to
  297. // figure out the correct index to insert the CSS into
  298. var index = 0;
  299. var lastC = 0;
  300. args[0].replace(/%[a-zA-Z%]/g, function (match) {
  301. if (match === '%%') {
  302. return;
  303. }
  304. index++;
  305. if (match === '%c') {
  306. // We only are interested in the *last* %c
  307. // (the user may have provided their own)
  308. lastC = index;
  309. }
  310. });
  311. args.splice(lastC, 0, c);
  312. }
  313. /**
  314. * Invokes `console.log()` when available.
  315. * No-op when `console.log` is not a "function".
  316. *
  317. * @api public
  318. */
  319. function log() {
  320. var _console;
  321. // This hackery is required for IE8/9, where
  322. // the `console.log` function doesn't have 'apply'
  323. return (typeof console === 'undefined' ? 'undefined' : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
  324. }
  325. /**
  326. * Save `namespaces`.
  327. *
  328. * @param {String} namespaces
  329. * @api private
  330. */
  331. function save(namespaces) {
  332. try {
  333. if (namespaces) {
  334. exports.storage.setItem('debug', namespaces);
  335. } else {
  336. exports.storage.removeItem('debug');
  337. }
  338. } catch (error) {
  339. // Swallow
  340. // XXX (@Qix-) should we be logging these?
  341. }
  342. }
  343. /**
  344. * Load `namespaces`.
  345. *
  346. * @return {String} returns the previously persisted debug modes
  347. * @api private
  348. */
  349. function load() {
  350. var r = void 0;
  351. try {
  352. r = exports.storage.getItem('debug');
  353. } catch (error) {}
  354. // Swallow
  355. // XXX (@Qix-) should we be logging these?
  356. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  357. if (!r && typeof process !== 'undefined' && 'env' in process) {
  358. r = process.env.DEBUG;
  359. }
  360. return r;
  361. }
  362. /**
  363. * Localstorage attempts to return the localstorage.
  364. *
  365. * This is necessary because safari throws
  366. * when a user disables cookies/localstorage
  367. * and you attempt to access it.
  368. *
  369. * @return {LocalStorage}
  370. * @api private
  371. */
  372. function localstorage() {
  373. try {
  374. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  375. // The Browser also has localStorage in the global context.
  376. return localStorage;
  377. } catch (error) {
  378. // Swallow
  379. // XXX (@Qix-) should we be logging these?
  380. }
  381. }
  382. module.exports = __webpack_require__(5)(exports);
  383. var formatters = module.exports.formatters;
  384. /**
  385. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  386. */
  387. formatters.j = function (v) {
  388. try {
  389. return JSON.stringify(v);
  390. } catch (error) {
  391. return '[UnexpectedJSONParseError]: ' + error.message;
  392. }
  393. };
  394. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
  395. /***/ }),
  396. /* 4 */
  397. /***/ (function(module, exports) {
  398. // shim for using process in browser
  399. var process = module.exports = {};
  400. // cached from whatever global is present so that test runners that stub it
  401. // don't break things. But we need to wrap it in a try catch in case it is
  402. // wrapped in strict mode code which doesn't define any globals. It's inside a
  403. // function because try/catches deoptimize in certain engines.
  404. var cachedSetTimeout;
  405. var cachedClearTimeout;
  406. function defaultSetTimout() {
  407. throw new Error('setTimeout has not been defined');
  408. }
  409. function defaultClearTimeout () {
  410. throw new Error('clearTimeout has not been defined');
  411. }
  412. (function () {
  413. try {
  414. if (typeof setTimeout === 'function') {
  415. cachedSetTimeout = setTimeout;
  416. } else {
  417. cachedSetTimeout = defaultSetTimout;
  418. }
  419. } catch (e) {
  420. cachedSetTimeout = defaultSetTimout;
  421. }
  422. try {
  423. if (typeof clearTimeout === 'function') {
  424. cachedClearTimeout = clearTimeout;
  425. } else {
  426. cachedClearTimeout = defaultClearTimeout;
  427. }
  428. } catch (e) {
  429. cachedClearTimeout = defaultClearTimeout;
  430. }
  431. } ())
  432. function runTimeout(fun) {
  433. if (cachedSetTimeout === setTimeout) {
  434. //normal enviroments in sane situations
  435. return setTimeout(fun, 0);
  436. }
  437. // if setTimeout wasn't available but was latter defined
  438. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  439. cachedSetTimeout = setTimeout;
  440. return setTimeout(fun, 0);
  441. }
  442. try {
  443. // when when somebody has screwed with setTimeout but no I.E. maddness
  444. return cachedSetTimeout(fun, 0);
  445. } catch(e){
  446. try {
  447. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  448. return cachedSetTimeout.call(null, fun, 0);
  449. } catch(e){
  450. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  451. return cachedSetTimeout.call(this, fun, 0);
  452. }
  453. }
  454. }
  455. function runClearTimeout(marker) {
  456. if (cachedClearTimeout === clearTimeout) {
  457. //normal enviroments in sane situations
  458. return clearTimeout(marker);
  459. }
  460. // if clearTimeout wasn't available but was latter defined
  461. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  462. cachedClearTimeout = clearTimeout;
  463. return clearTimeout(marker);
  464. }
  465. try {
  466. // when when somebody has screwed with setTimeout but no I.E. maddness
  467. return cachedClearTimeout(marker);
  468. } catch (e){
  469. try {
  470. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  471. return cachedClearTimeout.call(null, marker);
  472. } catch (e){
  473. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  474. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  475. return cachedClearTimeout.call(this, marker);
  476. }
  477. }
  478. }
  479. var queue = [];
  480. var draining = false;
  481. var currentQueue;
  482. var queueIndex = -1;
  483. function cleanUpNextTick() {
  484. if (!draining || !currentQueue) {
  485. return;
  486. }
  487. draining = false;
  488. if (currentQueue.length) {
  489. queue = currentQueue.concat(queue);
  490. } else {
  491. queueIndex = -1;
  492. }
  493. if (queue.length) {
  494. drainQueue();
  495. }
  496. }
  497. function drainQueue() {
  498. if (draining) {
  499. return;
  500. }
  501. var timeout = runTimeout(cleanUpNextTick);
  502. draining = true;
  503. var len = queue.length;
  504. while(len) {
  505. currentQueue = queue;
  506. queue = [];
  507. while (++queueIndex < len) {
  508. if (currentQueue) {
  509. currentQueue[queueIndex].run();
  510. }
  511. }
  512. queueIndex = -1;
  513. len = queue.length;
  514. }
  515. currentQueue = null;
  516. draining = false;
  517. runClearTimeout(timeout);
  518. }
  519. process.nextTick = function (fun) {
  520. var args = new Array(arguments.length - 1);
  521. if (arguments.length > 1) {
  522. for (var i = 1; i < arguments.length; i++) {
  523. args[i - 1] = arguments[i];
  524. }
  525. }
  526. queue.push(new Item(fun, args));
  527. if (queue.length === 1 && !draining) {
  528. runTimeout(drainQueue);
  529. }
  530. };
  531. // v8 likes predictible objects
  532. function Item(fun, array) {
  533. this.fun = fun;
  534. this.array = array;
  535. }
  536. Item.prototype.run = function () {
  537. this.fun.apply(null, this.array);
  538. };
  539. process.title = 'browser';
  540. process.browser = true;
  541. process.env = {};
  542. process.argv = [];
  543. process.version = ''; // empty string to avoid regexp issues
  544. process.versions = {};
  545. function noop() {}
  546. process.on = noop;
  547. process.addListener = noop;
  548. process.once = noop;
  549. process.off = noop;
  550. process.removeListener = noop;
  551. process.removeAllListeners = noop;
  552. process.emit = noop;
  553. process.prependListener = noop;
  554. process.prependOnceListener = noop;
  555. process.listeners = function (name) { return [] }
  556. process.binding = function (name) {
  557. throw new Error('process.binding is not supported');
  558. };
  559. process.cwd = function () { return '/' };
  560. process.chdir = function (dir) {
  561. throw new Error('process.chdir is not supported');
  562. };
  563. process.umask = function() { return 0; };
  564. /***/ }),
  565. /* 5 */
  566. /***/ (function(module, exports, __webpack_require__) {
  567. 'use strict';
  568. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  569. /**
  570. * This is the common logic for both the Node.js and web browser
  571. * implementations of `debug()`.
  572. */
  573. function setup(env) {
  574. createDebug.debug = createDebug;
  575. createDebug.default = createDebug;
  576. createDebug.coerce = coerce;
  577. createDebug.disable = disable;
  578. createDebug.enable = enable;
  579. createDebug.enabled = enabled;
  580. createDebug.humanize = __webpack_require__(6);
  581. Object.keys(env).forEach(function (key) {
  582. createDebug[key] = env[key];
  583. });
  584. /**
  585. * Active `debug` instances.
  586. */
  587. createDebug.instances = [];
  588. /**
  589. * The currently active debug mode names, and names to skip.
  590. */
  591. createDebug.names = [];
  592. createDebug.skips = [];
  593. /**
  594. * Map of special "%n" handling functions, for the debug "format" argument.
  595. *
  596. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  597. */
  598. createDebug.formatters = {};
  599. /**
  600. * Selects a color for a debug namespace
  601. * @param {String} namespace The namespace string for the for the debug instance to be colored
  602. * @return {Number|String} An ANSI color code for the given namespace
  603. * @api private
  604. */
  605. function selectColor(namespace) {
  606. var hash = 0;
  607. for (var i = 0; i < namespace.length; i++) {
  608. hash = (hash << 5) - hash + namespace.charCodeAt(i);
  609. hash |= 0; // Convert to 32bit integer
  610. }
  611. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  612. }
  613. createDebug.selectColor = selectColor;
  614. /**
  615. * Create a debugger with the given `namespace`.
  616. *
  617. * @param {String} namespace
  618. * @return {Function}
  619. * @api public
  620. */
  621. function createDebug(namespace) {
  622. var prevTime = void 0;
  623. function debug() {
  624. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  625. args[_key] = arguments[_key];
  626. }
  627. // Disabled?
  628. if (!debug.enabled) {
  629. return;
  630. }
  631. var self = debug;
  632. // Set `diff` timestamp
  633. var curr = Number(new Date());
  634. var ms = curr - (prevTime || curr);
  635. self.diff = ms;
  636. self.prev = prevTime;
  637. self.curr = curr;
  638. prevTime = curr;
  639. args[0] = createDebug.coerce(args[0]);
  640. if (typeof args[0] !== 'string') {
  641. // Anything else let's inspect with %O
  642. args.unshift('%O');
  643. }
  644. // Apply any `formatters` transformations
  645. var index = 0;
  646. args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
  647. // If we encounter an escaped % then don't increase the array index
  648. if (match === '%%') {
  649. return match;
  650. }
  651. index++;
  652. var formatter = createDebug.formatters[format];
  653. if (typeof formatter === 'function') {
  654. var val = args[index];
  655. match = formatter.call(self, val);
  656. // Now we need to remove `args[index]` since it's inlined in the `format`
  657. args.splice(index, 1);
  658. index--;
  659. }
  660. return match;
  661. });
  662. // Apply env-specific formatting (colors, etc.)
  663. createDebug.formatArgs.call(self, args);
  664. var logFn = self.log || createDebug.log;
  665. logFn.apply(self, args);
  666. }
  667. debug.namespace = namespace;
  668. debug.enabled = createDebug.enabled(namespace);
  669. debug.useColors = createDebug.useColors();
  670. debug.color = selectColor(namespace);
  671. debug.destroy = destroy;
  672. debug.extend = extend;
  673. // Debug.formatArgs = formatArgs;
  674. // debug.rawLog = rawLog;
  675. // env-specific initialization logic for debug instances
  676. if (typeof createDebug.init === 'function') {
  677. createDebug.init(debug);
  678. }
  679. createDebug.instances.push(debug);
  680. return debug;
  681. }
  682. function destroy() {
  683. var index = createDebug.instances.indexOf(this);
  684. if (index !== -1) {
  685. createDebug.instances.splice(index, 1);
  686. return true;
  687. }
  688. return false;
  689. }
  690. function extend(namespace, delimiter) {
  691. var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  692. newDebug.log = this.log;
  693. return newDebug;
  694. }
  695. /**
  696. * Enables a debug mode by namespaces. This can include modes
  697. * separated by a colon and wildcards.
  698. *
  699. * @param {String} namespaces
  700. * @api public
  701. */
  702. function enable(namespaces) {
  703. createDebug.save(namespaces);
  704. createDebug.names = [];
  705. createDebug.skips = [];
  706. var i = void 0;
  707. var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  708. var len = split.length;
  709. for (i = 0; i < len; i++) {
  710. if (!split[i]) {
  711. // ignore empty strings
  712. continue;
  713. }
  714. namespaces = split[i].replace(/\*/g, '.*?');
  715. if (namespaces[0] === '-') {
  716. createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  717. } else {
  718. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  719. }
  720. }
  721. for (i = 0; i < createDebug.instances.length; i++) {
  722. var instance = createDebug.instances[i];
  723. instance.enabled = createDebug.enabled(instance.namespace);
  724. }
  725. }
  726. /**
  727. * Disable debug output.
  728. *
  729. * @return {String} namespaces
  730. * @api public
  731. */
  732. function disable() {
  733. var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
  734. return '-' + namespace;
  735. }))).join(',');
  736. createDebug.enable('');
  737. return namespaces;
  738. }
  739. /**
  740. * Returns true if the given mode name is enabled, false otherwise.
  741. *
  742. * @param {String} name
  743. * @return {Boolean}
  744. * @api public
  745. */
  746. function enabled(name) {
  747. if (name[name.length - 1] === '*') {
  748. return true;
  749. }
  750. var i = void 0;
  751. var len = void 0;
  752. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  753. if (createDebug.skips[i].test(name)) {
  754. return false;
  755. }
  756. }
  757. for (i = 0, len = createDebug.names.length; i < len; i++) {
  758. if (createDebug.names[i].test(name)) {
  759. return true;
  760. }
  761. }
  762. return false;
  763. }
  764. /**
  765. * Convert regexp to namespace
  766. *
  767. * @param {RegExp} regxep
  768. * @return {String} namespace
  769. * @api private
  770. */
  771. function toNamespace(regexp) {
  772. return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
  773. }
  774. /**
  775. * Coerce `val`.
  776. *
  777. * @param {Mixed} val
  778. * @return {Mixed}
  779. * @api private
  780. */
  781. function coerce(val) {
  782. if (val instanceof Error) {
  783. return val.stack || val.message;
  784. }
  785. return val;
  786. }
  787. createDebug.enable(createDebug.load());
  788. return createDebug;
  789. }
  790. module.exports = setup;
  791. /***/ }),
  792. /* 6 */
  793. /***/ (function(module, exports) {
  794. /**
  795. * Helpers.
  796. */
  797. var s = 1000;
  798. var m = s * 60;
  799. var h = m * 60;
  800. var d = h * 24;
  801. var w = d * 7;
  802. var y = d * 365.25;
  803. /**
  804. * Parse or format the given `val`.
  805. *
  806. * Options:
  807. *
  808. * - `long` verbose formatting [false]
  809. *
  810. * @param {String|Number} val
  811. * @param {Object} [options]
  812. * @throws {Error} throw an error if val is not a non-empty string or a number
  813. * @return {String|Number}
  814. * @api public
  815. */
  816. module.exports = function(val, options) {
  817. options = options || {};
  818. var type = typeof val;
  819. if (type === 'string' && val.length > 0) {
  820. return parse(val);
  821. } else if (type === 'number' && isFinite(val)) {
  822. return options.long ? fmtLong(val) : fmtShort(val);
  823. }
  824. throw new Error(
  825. 'val is not a non-empty string or a valid number. val=' +
  826. JSON.stringify(val)
  827. );
  828. };
  829. /**
  830. * Parse the given `str` and return milliseconds.
  831. *
  832. * @param {String} str
  833. * @return {Number}
  834. * @api private
  835. */
  836. function parse(str) {
  837. str = String(str);
  838. if (str.length > 100) {
  839. return;
  840. }
  841. 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(
  842. str
  843. );
  844. if (!match) {
  845. return;
  846. }
  847. var n = parseFloat(match[1]);
  848. var type = (match[2] || 'ms').toLowerCase();
  849. switch (type) {
  850. case 'years':
  851. case 'year':
  852. case 'yrs':
  853. case 'yr':
  854. case 'y':
  855. return n * y;
  856. case 'weeks':
  857. case 'week':
  858. case 'w':
  859. return n * w;
  860. case 'days':
  861. case 'day':
  862. case 'd':
  863. return n * d;
  864. case 'hours':
  865. case 'hour':
  866. case 'hrs':
  867. case 'hr':
  868. case 'h':
  869. return n * h;
  870. case 'minutes':
  871. case 'minute':
  872. case 'mins':
  873. case 'min':
  874. case 'm':
  875. return n * m;
  876. case 'seconds':
  877. case 'second':
  878. case 'secs':
  879. case 'sec':
  880. case 's':
  881. return n * s;
  882. case 'milliseconds':
  883. case 'millisecond':
  884. case 'msecs':
  885. case 'msec':
  886. case 'ms':
  887. return n;
  888. default:
  889. return undefined;
  890. }
  891. }
  892. /**
  893. * Short format for `ms`.
  894. *
  895. * @param {Number} ms
  896. * @return {String}
  897. * @api private
  898. */
  899. function fmtShort(ms) {
  900. var msAbs = Math.abs(ms);
  901. if (msAbs >= d) {
  902. return Math.round(ms / d) + 'd';
  903. }
  904. if (msAbs >= h) {
  905. return Math.round(ms / h) + 'h';
  906. }
  907. if (msAbs >= m) {
  908. return Math.round(ms / m) + 'm';
  909. }
  910. if (msAbs >= s) {
  911. return Math.round(ms / s) + 's';
  912. }
  913. return ms + 'ms';
  914. }
  915. /**
  916. * Long format for `ms`.
  917. *
  918. * @param {Number} ms
  919. * @return {String}
  920. * @api private
  921. */
  922. function fmtLong(ms) {
  923. var msAbs = Math.abs(ms);
  924. if (msAbs >= d) {
  925. return plural(ms, msAbs, d, 'day');
  926. }
  927. if (msAbs >= h) {
  928. return plural(ms, msAbs, h, 'hour');
  929. }
  930. if (msAbs >= m) {
  931. return plural(ms, msAbs, m, 'minute');
  932. }
  933. if (msAbs >= s) {
  934. return plural(ms, msAbs, s, 'second');
  935. }
  936. return ms + ' ms';
  937. }
  938. /**
  939. * Pluralization helper.
  940. */
  941. function plural(ms, msAbs, n, name) {
  942. var isPlural = msAbs >= n * 1.5;
  943. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  944. }
  945. /***/ }),
  946. /* 7 */
  947. /***/ (function(module, exports, __webpack_require__) {
  948. /**
  949. * Module dependencies.
  950. */
  951. var debug = __webpack_require__(8)('socket.io-parser');
  952. var Emitter = __webpack_require__(11);
  953. var binary = __webpack_require__(12);
  954. var isArray = __webpack_require__(13);
  955. var isBuf = __webpack_require__(14);
  956. /**
  957. * Protocol version.
  958. *
  959. * @api public
  960. */
  961. exports.protocol = 4;
  962. /**
  963. * Packet types.
  964. *
  965. * @api public
  966. */
  967. exports.types = [
  968. 'CONNECT',
  969. 'DISCONNECT',
  970. 'EVENT',
  971. 'ACK',
  972. 'ERROR',
  973. 'BINARY_EVENT',
  974. 'BINARY_ACK'
  975. ];
  976. /**
  977. * Packet type `connect`.
  978. *
  979. * @api public
  980. */
  981. exports.CONNECT = 0;
  982. /**
  983. * Packet type `disconnect`.
  984. *
  985. * @api public
  986. */
  987. exports.DISCONNECT = 1;
  988. /**
  989. * Packet type `event`.
  990. *
  991. * @api public
  992. */
  993. exports.EVENT = 2;
  994. /**
  995. * Packet type `ack`.
  996. *
  997. * @api public
  998. */
  999. exports.ACK = 3;
  1000. /**
  1001. * Packet type `error`.
  1002. *
  1003. * @api public
  1004. */
  1005. exports.ERROR = 4;
  1006. /**
  1007. * Packet type 'binary event'
  1008. *
  1009. * @api public
  1010. */
  1011. exports.BINARY_EVENT = 5;
  1012. /**
  1013. * Packet type `binary ack`. For acks with binary arguments.
  1014. *
  1015. * @api public
  1016. */
  1017. exports.BINARY_ACK = 6;
  1018. /**
  1019. * Encoder constructor.
  1020. *
  1021. * @api public
  1022. */
  1023. exports.Encoder = Encoder;
  1024. /**
  1025. * Decoder constructor.
  1026. *
  1027. * @api public
  1028. */
  1029. exports.Decoder = Decoder;
  1030. /**
  1031. * A socket.io Encoder instance
  1032. *
  1033. * @api public
  1034. */
  1035. function Encoder() {}
  1036. var ERROR_PACKET = exports.ERROR + '"encode error"';
  1037. /**
  1038. * Encode a packet as a single string if non-binary, or as a
  1039. * buffer sequence, depending on packet type.
  1040. *
  1041. * @param {Object} obj - packet object
  1042. * @param {Function} callback - function to handle encodings (likely engine.write)
  1043. * @return Calls callback with Array of encodings
  1044. * @api public
  1045. */
  1046. Encoder.prototype.encode = function(obj, callback){
  1047. debug('encoding packet %j', obj);
  1048. if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
  1049. encodeAsBinary(obj, callback);
  1050. } else {
  1051. var encoding = encodeAsString(obj);
  1052. callback([encoding]);
  1053. }
  1054. };
  1055. /**
  1056. * Encode packet as string.
  1057. *
  1058. * @param {Object} packet
  1059. * @return {String} encoded
  1060. * @api private
  1061. */
  1062. function encodeAsString(obj) {
  1063. // first is type
  1064. var str = '' + obj.type;
  1065. // attachments if we have them
  1066. if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
  1067. str += obj.attachments + '-';
  1068. }
  1069. // if we have a namespace other than `/`
  1070. // we append it followed by a comma `,`
  1071. if (obj.nsp && '/' !== obj.nsp) {
  1072. str += obj.nsp + ',';
  1073. }
  1074. // immediately followed by the id
  1075. if (null != obj.id) {
  1076. str += obj.id;
  1077. }
  1078. // json data
  1079. if (null != obj.data) {
  1080. var payload = tryStringify(obj.data);
  1081. if (payload !== false) {
  1082. str += payload;
  1083. } else {
  1084. return ERROR_PACKET;
  1085. }
  1086. }
  1087. debug('encoded %j as %s', obj, str);
  1088. return str;
  1089. }
  1090. function tryStringify(str) {
  1091. try {
  1092. return JSON.stringify(str);
  1093. } catch(e){
  1094. return false;
  1095. }
  1096. }
  1097. /**
  1098. * Encode packet as 'buffer sequence' by removing blobs, and
  1099. * deconstructing packet into object with placeholders and
  1100. * a list of buffers.
  1101. *
  1102. * @param {Object} packet
  1103. * @return {Buffer} encoded
  1104. * @api private
  1105. */
  1106. function encodeAsBinary(obj, callback) {
  1107. function writeEncoding(bloblessData) {
  1108. var deconstruction = binary.deconstructPacket(bloblessData);
  1109. var pack = encodeAsString(deconstruction.packet);
  1110. var buffers = deconstruction.buffers;
  1111. buffers.unshift(pack); // add packet info to beginning of data list
  1112. callback(buffers); // write all the buffers
  1113. }
  1114. binary.removeBlobs(obj, writeEncoding);
  1115. }
  1116. /**
  1117. * A socket.io Decoder instance
  1118. *
  1119. * @return {Object} decoder
  1120. * @api public
  1121. */
  1122. function Decoder() {
  1123. this.reconstructor = null;
  1124. }
  1125. /**
  1126. * Mix in `Emitter` with Decoder.
  1127. */
  1128. Emitter(Decoder.prototype);
  1129. /**
  1130. * Decodes an encoded packet string into packet JSON.
  1131. *
  1132. * @param {String} obj - encoded packet
  1133. * @return {Object} packet
  1134. * @api public
  1135. */
  1136. Decoder.prototype.add = function(obj) {
  1137. var packet;
  1138. if (typeof obj === 'string') {
  1139. packet = decodeString(obj);
  1140. if (exports.BINARY_EVENT === packet.type || exports.BINARY_ACK === packet.type) { // binary packet's json
  1141. this.reconstructor = new BinaryReconstructor(packet);
  1142. // no attachments, labeled binary but no binary data to follow
  1143. if (this.reconstructor.reconPack.attachments === 0) {
  1144. this.emit('decoded', packet);
  1145. }
  1146. } else { // non-binary full packet
  1147. this.emit('decoded', packet);
  1148. }
  1149. } else if (isBuf(obj) || obj.base64) { // raw binary data
  1150. if (!this.reconstructor) {
  1151. throw new Error('got binary data when not reconstructing a packet');
  1152. } else {
  1153. packet = this.reconstructor.takeBinaryData(obj);
  1154. if (packet) { // received final buffer
  1155. this.reconstructor = null;
  1156. this.emit('decoded', packet);
  1157. }
  1158. }
  1159. } else {
  1160. throw new Error('Unknown type: ' + obj);
  1161. }
  1162. };
  1163. /**
  1164. * Decode a packet String (JSON data)
  1165. *
  1166. * @param {String} str
  1167. * @return {Object} packet
  1168. * @api private
  1169. */
  1170. function decodeString(str) {
  1171. var i = 0;
  1172. // look up type
  1173. var p = {
  1174. type: Number(str.charAt(0))
  1175. };
  1176. if (null == exports.types[p.type]) {
  1177. return error('unknown packet type ' + p.type);
  1178. }
  1179. // look up attachments if type binary
  1180. if (exports.BINARY_EVENT === p.type || exports.BINARY_ACK === p.type) {
  1181. var buf = '';
  1182. while (str.charAt(++i) !== '-') {
  1183. buf += str.charAt(i);
  1184. if (i == str.length) break;
  1185. }
  1186. if (buf != Number(buf) || str.charAt(i) !== '-') {
  1187. throw new Error('Illegal attachments');
  1188. }
  1189. p.attachments = Number(buf);
  1190. }
  1191. // look up namespace (if any)
  1192. if ('/' === str.charAt(i + 1)) {
  1193. p.nsp = '';
  1194. while (++i) {
  1195. var c = str.charAt(i);
  1196. if (',' === c) break;
  1197. p.nsp += c;
  1198. if (i === str.length) break;
  1199. }
  1200. } else {
  1201. p.nsp = '/';
  1202. }
  1203. // look up id
  1204. var next = str.charAt(i + 1);
  1205. if ('' !== next && Number(next) == next) {
  1206. p.id = '';
  1207. while (++i) {
  1208. var c = str.charAt(i);
  1209. if (null == c || Number(c) != c) {
  1210. --i;
  1211. break;
  1212. }
  1213. p.id += str.charAt(i);
  1214. if (i === str.length) break;
  1215. }
  1216. p.id = Number(p.id);
  1217. }
  1218. // look up json data
  1219. if (str.charAt(++i)) {
  1220. var payload = tryParse(str.substr(i));
  1221. var isPayloadValid = payload !== false && (p.type === exports.ERROR || isArray(payload));
  1222. if (isPayloadValid) {
  1223. p.data = payload;
  1224. } else {
  1225. return error('invalid payload');
  1226. }
  1227. }
  1228. debug('decoded %s as %j', str, p);
  1229. return p;
  1230. }
  1231. function tryParse(str) {
  1232. try {
  1233. return JSON.parse(str);
  1234. } catch(e){
  1235. return false;
  1236. }
  1237. }
  1238. /**
  1239. * Deallocates a parser's resources
  1240. *
  1241. * @api public
  1242. */
  1243. Decoder.prototype.destroy = function() {
  1244. if (this.reconstructor) {
  1245. this.reconstructor.finishedReconstruction();
  1246. }
  1247. };
  1248. /**
  1249. * A manager of a binary event's 'buffer sequence'. Should
  1250. * be constructed whenever a packet of type BINARY_EVENT is
  1251. * decoded.
  1252. *
  1253. * @param {Object} packet
  1254. * @return {BinaryReconstructor} initialized reconstructor
  1255. * @api private
  1256. */
  1257. function BinaryReconstructor(packet) {
  1258. this.reconPack = packet;
  1259. this.buffers = [];
  1260. }
  1261. /**
  1262. * Method to be called when binary data received from connection
  1263. * after a BINARY_EVENT packet.
  1264. *
  1265. * @param {Buffer | ArrayBuffer} binData - the raw binary data received
  1266. * @return {null | Object} returns null if more binary data is expected or
  1267. * a reconstructed packet object if all buffers have been received.
  1268. * @api private
  1269. */
  1270. BinaryReconstructor.prototype.takeBinaryData = function(binData) {
  1271. this.buffers.push(binData);
  1272. if (this.buffers.length === this.reconPack.attachments) { // done with buffer list
  1273. var packet = binary.reconstructPacket(this.reconPack, this.buffers);
  1274. this.finishedReconstruction();
  1275. return packet;
  1276. }
  1277. return null;
  1278. };
  1279. /**
  1280. * Cleans up binary packet reconstruction variables.
  1281. *
  1282. * @api private
  1283. */
  1284. BinaryReconstructor.prototype.finishedReconstruction = function() {
  1285. this.reconPack = null;
  1286. this.buffers = [];
  1287. };
  1288. function error(msg) {
  1289. return {
  1290. type: exports.ERROR,
  1291. data: 'parser error: ' + msg
  1292. };
  1293. }
  1294. /***/ }),
  1295. /* 8 */
  1296. /***/ (function(module, exports, __webpack_require__) {
  1297. /* WEBPACK VAR INJECTION */(function(process) {'use strict';
  1298. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  1299. /**
  1300. * This is the web browser implementation of `debug()`.
  1301. *
  1302. * Expose `debug()` as the module.
  1303. */
  1304. exports = module.exports = __webpack_require__(9);
  1305. exports.log = log;
  1306. exports.formatArgs = formatArgs;
  1307. exports.save = save;
  1308. exports.load = load;
  1309. exports.useColors = useColors;
  1310. exports.storage = 'undefined' != typeof chrome && 'undefined' != typeof chrome.storage ? chrome.storage.local : localstorage();
  1311. /**
  1312. * Colors.
  1313. */
  1314. 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'];
  1315. /**
  1316. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  1317. * and the Firebug extension (any Firefox version) are known
  1318. * to support "%c" CSS customizations.
  1319. *
  1320. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  1321. */
  1322. function useColors() {
  1323. // NB: In an Electron preload script, document will be defined but not fully
  1324. // initialized. Since we know we're in Chrome, we'll just detect this case
  1325. // explicitly
  1326. if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
  1327. return true;
  1328. }
  1329. // Internet Explorer and Edge do not support colors.
  1330. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  1331. return false;
  1332. }
  1333. // is webkit? http://stackoverflow.com/a/16459606/376773
  1334. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  1335. return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance ||
  1336. // is firebug? http://stackoverflow.com/a/398120/376773
  1337. typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) ||
  1338. // is firefox >= v31?
  1339. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  1340. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 ||
  1341. // double check webkit in userAgent just in case we are in a worker
  1342. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
  1343. }
  1344. /**
  1345. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  1346. */
  1347. exports.formatters.j = function (v) {
  1348. try {
  1349. return JSON.stringify(v);
  1350. } catch (err) {
  1351. return '[UnexpectedJSONParseError]: ' + err.message;
  1352. }
  1353. };
  1354. /**
  1355. * Colorize log arguments if enabled.
  1356. *
  1357. * @api public
  1358. */
  1359. function formatArgs(args) {
  1360. var useColors = this.useColors;
  1361. args[0] = (useColors ? '%c' : '') + this.namespace + (useColors ? ' %c' : ' ') + args[0] + (useColors ? '%c ' : ' ') + '+' + exports.humanize(this.diff);
  1362. if (!useColors) return;
  1363. var c = 'color: ' + this.color;
  1364. args.splice(1, 0, c, 'color: inherit');
  1365. // the final "%c" is somewhat tricky, because there could be other
  1366. // arguments passed either before or after the %c, so we need to
  1367. // figure out the correct index to insert the CSS into
  1368. var index = 0;
  1369. var lastC = 0;
  1370. args[0].replace(/%[a-zA-Z%]/g, function (match) {
  1371. if ('%%' === match) return;
  1372. index++;
  1373. if ('%c' === match) {
  1374. // we only are interested in the *last* %c
  1375. // (the user may have provided their own)
  1376. lastC = index;
  1377. }
  1378. });
  1379. args.splice(lastC, 0, c);
  1380. }
  1381. /**
  1382. * Invokes `console.log()` when available.
  1383. * No-op when `console.log` is not a "function".
  1384. *
  1385. * @api public
  1386. */
  1387. function log() {
  1388. // this hackery is required for IE8/9, where
  1389. // the `console.log` function doesn't have 'apply'
  1390. return 'object' === (typeof console === 'undefined' ? 'undefined' : _typeof(console)) && console.log && Function.prototype.apply.call(console.log, console, arguments);
  1391. }
  1392. /**
  1393. * Save `namespaces`.
  1394. *
  1395. * @param {String} namespaces
  1396. * @api private
  1397. */
  1398. function save(namespaces) {
  1399. try {
  1400. if (null == namespaces) {
  1401. exports.storage.removeItem('debug');
  1402. } else {
  1403. exports.storage.debug = namespaces;
  1404. }
  1405. } catch (e) {}
  1406. }
  1407. /**
  1408. * Load `namespaces`.
  1409. *
  1410. * @return {String} returns the previously persisted debug modes
  1411. * @api private
  1412. */
  1413. function load() {
  1414. var r;
  1415. try {
  1416. r = exports.storage.debug;
  1417. } catch (e) {}
  1418. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  1419. if (!r && typeof process !== 'undefined' && 'env' in process) {
  1420. r = process.env.DEBUG;
  1421. }
  1422. return r;
  1423. }
  1424. /**
  1425. * Enable namespaces listed in `localStorage.debug` initially.
  1426. */
  1427. exports.enable(load());
  1428. /**
  1429. * Localstorage attempts to return the localstorage.
  1430. *
  1431. * This is necessary because safari throws
  1432. * when a user disables cookies/localstorage
  1433. * and you attempt to access it.
  1434. *
  1435. * @return {LocalStorage}
  1436. * @api private
  1437. */
  1438. function localstorage() {
  1439. try {
  1440. return window.localStorage;
  1441. } catch (e) {}
  1442. }
  1443. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
  1444. /***/ }),
  1445. /* 9 */
  1446. /***/ (function(module, exports, __webpack_require__) {
  1447. 'use strict';
  1448. /**
  1449. * This is the common logic for both the Node.js and web browser
  1450. * implementations of `debug()`.
  1451. *
  1452. * Expose `debug()` as the module.
  1453. */
  1454. exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
  1455. exports.coerce = coerce;
  1456. exports.disable = disable;
  1457. exports.enable = enable;
  1458. exports.enabled = enabled;
  1459. exports.humanize = __webpack_require__(10);
  1460. /**
  1461. * Active `debug` instances.
  1462. */
  1463. exports.instances = [];
  1464. /**
  1465. * The currently active debug mode names, and names to skip.
  1466. */
  1467. exports.names = [];
  1468. exports.skips = [];
  1469. /**
  1470. * Map of special "%n" handling functions, for the debug "format" argument.
  1471. *
  1472. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  1473. */
  1474. exports.formatters = {};
  1475. /**
  1476. * Select a color.
  1477. * @param {String} namespace
  1478. * @return {Number}
  1479. * @api private
  1480. */
  1481. function selectColor(namespace) {
  1482. var hash = 0,
  1483. i;
  1484. for (i in namespace) {
  1485. hash = (hash << 5) - hash + namespace.charCodeAt(i);
  1486. hash |= 0; // Convert to 32bit integer
  1487. }
  1488. return exports.colors[Math.abs(hash) % exports.colors.length];
  1489. }
  1490. /**
  1491. * Create a debugger with the given `namespace`.
  1492. *
  1493. * @param {String} namespace
  1494. * @return {Function}
  1495. * @api public
  1496. */
  1497. function createDebug(namespace) {
  1498. var prevTime;
  1499. function debug() {
  1500. // disabled?
  1501. if (!debug.enabled) return;
  1502. var self = debug;
  1503. // set `diff` timestamp
  1504. var curr = +new Date();
  1505. var ms = curr - (prevTime || curr);
  1506. self.diff = ms;
  1507. self.prev = prevTime;
  1508. self.curr = curr;
  1509. prevTime = curr;
  1510. // turn the `arguments` into a proper Array
  1511. var args = new Array(arguments.length);
  1512. for (var i = 0; i < args.length; i++) {
  1513. args[i] = arguments[i];
  1514. }
  1515. args[0] = exports.coerce(args[0]);
  1516. if ('string' !== typeof args[0]) {
  1517. // anything else let's inspect with %O
  1518. args.unshift('%O');
  1519. }
  1520. // apply any `formatters` transformations
  1521. var index = 0;
  1522. args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
  1523. // if we encounter an escaped % then don't increase the array index
  1524. if (match === '%%') return match;
  1525. index++;
  1526. var formatter = exports.formatters[format];
  1527. if ('function' === typeof formatter) {
  1528. var val = args[index];
  1529. match = formatter.call(self, val);
  1530. // now we need to remove `args[index]` since it's inlined in the `format`
  1531. args.splice(index, 1);
  1532. index--;
  1533. }
  1534. return match;
  1535. });
  1536. // apply env-specific formatting (colors, etc.)
  1537. exports.formatArgs.call(self, args);
  1538. var logFn = debug.log || exports.log || console.log.bind(console);
  1539. logFn.apply(self, args);
  1540. }
  1541. debug.namespace = namespace;
  1542. debug.enabled = exports.enabled(namespace);
  1543. debug.useColors = exports.useColors();
  1544. debug.color = selectColor(namespace);
  1545. debug.destroy = destroy;
  1546. // env-specific initialization logic for debug instances
  1547. if ('function' === typeof exports.init) {
  1548. exports.init(debug);
  1549. }
  1550. exports.instances.push(debug);
  1551. return debug;
  1552. }
  1553. function destroy() {
  1554. var index = exports.instances.indexOf(this);
  1555. if (index !== -1) {
  1556. exports.instances.splice(index, 1);
  1557. return true;
  1558. } else {
  1559. return false;
  1560. }
  1561. }
  1562. /**
  1563. * Enables a debug mode by namespaces. This can include modes
  1564. * separated by a colon and wildcards.
  1565. *
  1566. * @param {String} namespaces
  1567. * @api public
  1568. */
  1569. function enable(namespaces) {
  1570. exports.save(namespaces);
  1571. exports.names = [];
  1572. exports.skips = [];
  1573. var i;
  1574. var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  1575. var len = split.length;
  1576. for (i = 0; i < len; i++) {
  1577. if (!split[i]) continue; // ignore empty strings
  1578. namespaces = split[i].replace(/\*/g, '.*?');
  1579. if (namespaces[0] === '-') {
  1580. exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  1581. } else {
  1582. exports.names.push(new RegExp('^' + namespaces + '$'));
  1583. }
  1584. }
  1585. for (i = 0; i < exports.instances.length; i++) {
  1586. var instance = exports.instances[i];
  1587. instance.enabled = exports.enabled(instance.namespace);
  1588. }
  1589. }
  1590. /**
  1591. * Disable debug output.
  1592. *
  1593. * @api public
  1594. */
  1595. function disable() {
  1596. exports.enable('');
  1597. }
  1598. /**
  1599. * Returns true if the given mode name is enabled, false otherwise.
  1600. *
  1601. * @param {String} name
  1602. * @return {Boolean}
  1603. * @api public
  1604. */
  1605. function enabled(name) {
  1606. if (name[name.length - 1] === '*') {
  1607. return true;
  1608. }
  1609. var i, len;
  1610. for (i = 0, len = exports.skips.length; i < len; i++) {
  1611. if (exports.skips[i].test(name)) {
  1612. return false;
  1613. }
  1614. }
  1615. for (i = 0, len = exports.names.length; i < len; i++) {
  1616. if (exports.names[i].test(name)) {
  1617. return true;
  1618. }
  1619. }
  1620. return false;
  1621. }
  1622. /**
  1623. * Coerce `val`.
  1624. *
  1625. * @param {Mixed} val
  1626. * @return {Mixed}
  1627. * @api private
  1628. */
  1629. function coerce(val) {
  1630. if (val instanceof Error) return val.stack || val.message;
  1631. return val;
  1632. }
  1633. /***/ }),
  1634. /* 10 */
  1635. /***/ (function(module, exports) {
  1636. /**
  1637. * Helpers.
  1638. */
  1639. var s = 1000;
  1640. var m = s * 60;
  1641. var h = m * 60;
  1642. var d = h * 24;
  1643. var y = d * 365.25;
  1644. /**
  1645. * Parse or format the given `val`.
  1646. *
  1647. * Options:
  1648. *
  1649. * - `long` verbose formatting [false]
  1650. *
  1651. * @param {String|Number} val
  1652. * @param {Object} [options]
  1653. * @throws {Error} throw an error if val is not a non-empty string or a number
  1654. * @return {String|Number}
  1655. * @api public
  1656. */
  1657. module.exports = function(val, options) {
  1658. options = options || {};
  1659. var type = typeof val;
  1660. if (type === 'string' && val.length > 0) {
  1661. return parse(val);
  1662. } else if (type === 'number' && isNaN(val) === false) {
  1663. return options.long ? fmtLong(val) : fmtShort(val);
  1664. }
  1665. throw new Error(
  1666. 'val is not a non-empty string or a valid number. val=' +
  1667. JSON.stringify(val)
  1668. );
  1669. };
  1670. /**
  1671. * Parse the given `str` and return milliseconds.
  1672. *
  1673. * @param {String} str
  1674. * @return {Number}
  1675. * @api private
  1676. */
  1677. function parse(str) {
  1678. str = String(str);
  1679. if (str.length > 100) {
  1680. return;
  1681. }
  1682. var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
  1683. str
  1684. );
  1685. if (!match) {
  1686. return;
  1687. }
  1688. var n = parseFloat(match[1]);
  1689. var type = (match[2] || 'ms').toLowerCase();
  1690. switch (type) {
  1691. case 'years':
  1692. case 'year':
  1693. case 'yrs':
  1694. case 'yr':
  1695. case 'y':
  1696. return n * y;
  1697. case 'days':
  1698. case 'day':
  1699. case 'd':
  1700. return n * d;
  1701. case 'hours':
  1702. case 'hour':
  1703. case 'hrs':
  1704. case 'hr':
  1705. case 'h':
  1706. return n * h;
  1707. case 'minutes':
  1708. case 'minute':
  1709. case 'mins':
  1710. case 'min':
  1711. case 'm':
  1712. return n * m;
  1713. case 'seconds':
  1714. case 'second':
  1715. case 'secs':
  1716. case 'sec':
  1717. case 's':
  1718. return n * s;
  1719. case 'milliseconds':
  1720. case 'millisecond':
  1721. case 'msecs':
  1722. case 'msec':
  1723. case 'ms':
  1724. return n;
  1725. default:
  1726. return undefined;
  1727. }
  1728. }
  1729. /**
  1730. * Short format for `ms`.
  1731. *
  1732. * @param {Number} ms
  1733. * @return {String}
  1734. * @api private
  1735. */
  1736. function fmtShort(ms) {
  1737. if (ms >= d) {
  1738. return Math.round(ms / d) + 'd';
  1739. }
  1740. if (ms >= h) {
  1741. return Math.round(ms / h) + 'h';
  1742. }
  1743. if (ms >= m) {
  1744. return Math.round(ms / m) + 'm';
  1745. }
  1746. if (ms >= s) {
  1747. return Math.round(ms / s) + 's';
  1748. }
  1749. return ms + 'ms';
  1750. }
  1751. /**
  1752. * Long format for `ms`.
  1753. *
  1754. * @param {Number} ms
  1755. * @return {String}
  1756. * @api private
  1757. */
  1758. function fmtLong(ms) {
  1759. return plural(ms, d, 'day') ||
  1760. plural(ms, h, 'hour') ||
  1761. plural(ms, m, 'minute') ||
  1762. plural(ms, s, 'second') ||
  1763. ms + ' ms';
  1764. }
  1765. /**
  1766. * Pluralization helper.
  1767. */
  1768. function plural(ms, n, name) {
  1769. if (ms < n) {
  1770. return;
  1771. }
  1772. if (ms < n * 1.5) {
  1773. return Math.floor(ms / n) + ' ' + name;
  1774. }
  1775. return Math.ceil(ms / n) + ' ' + name + 's';
  1776. }
  1777. /***/ }),
  1778. /* 11 */
  1779. /***/ (function(module, exports, __webpack_require__) {
  1780. /**
  1781. * Expose `Emitter`.
  1782. */
  1783. if (true) {
  1784. module.exports = Emitter;
  1785. }
  1786. /**
  1787. * Initialize a new `Emitter`.
  1788. *
  1789. * @api public
  1790. */
  1791. function Emitter(obj) {
  1792. if (obj) return mixin(obj);
  1793. };
  1794. /**
  1795. * Mixin the emitter properties.
  1796. *
  1797. * @param {Object} obj
  1798. * @return {Object}
  1799. * @api private
  1800. */
  1801. function mixin(obj) {
  1802. for (var key in Emitter.prototype) {
  1803. obj[key] = Emitter.prototype[key];
  1804. }
  1805. return obj;
  1806. }
  1807. /**
  1808. * Listen on the given `event` with `fn`.
  1809. *
  1810. * @param {String} event
  1811. * @param {Function} fn
  1812. * @return {Emitter}
  1813. * @api public
  1814. */
  1815. Emitter.prototype.on =
  1816. Emitter.prototype.addEventListener = function(event, fn){
  1817. this._callbacks = this._callbacks || {};
  1818. (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
  1819. .push(fn);
  1820. return this;
  1821. };
  1822. /**
  1823. * Adds an `event` listener that will be invoked a single
  1824. * time then automatically removed.
  1825. *
  1826. * @param {String} event
  1827. * @param {Function} fn
  1828. * @return {Emitter}
  1829. * @api public
  1830. */
  1831. Emitter.prototype.once = function(event, fn){
  1832. function on() {
  1833. this.off(event, on);
  1834. fn.apply(this, arguments);
  1835. }
  1836. on.fn = fn;
  1837. this.on(event, on);
  1838. return this;
  1839. };
  1840. /**
  1841. * Remove the given callback for `event` or all
  1842. * registered callbacks.
  1843. *
  1844. * @param {String} event
  1845. * @param {Function} fn
  1846. * @return {Emitter}
  1847. * @api public
  1848. */
  1849. Emitter.prototype.off =
  1850. Emitter.prototype.removeListener =
  1851. Emitter.prototype.removeAllListeners =
  1852. Emitter.prototype.removeEventListener = function(event, fn){
  1853. this._callbacks = this._callbacks || {};
  1854. // all
  1855. if (0 == arguments.length) {
  1856. this._callbacks = {};
  1857. return this;
  1858. }
  1859. // specific event
  1860. var callbacks = this._callbacks['$' + event];
  1861. if (!callbacks) return this;
  1862. // remove all handlers
  1863. if (1 == arguments.length) {
  1864. delete this._callbacks['$' + event];
  1865. return this;
  1866. }
  1867. // remove specific handler
  1868. var cb;
  1869. for (var i = 0; i < callbacks.length; i++) {
  1870. cb = callbacks[i];
  1871. if (cb === fn || cb.fn === fn) {
  1872. callbacks.splice(i, 1);
  1873. break;
  1874. }
  1875. }
  1876. return this;
  1877. };
  1878. /**
  1879. * Emit `event` with the given args.
  1880. *
  1881. * @param {String} event
  1882. * @param {Mixed} ...
  1883. * @return {Emitter}
  1884. */
  1885. Emitter.prototype.emit = function(event){
  1886. this._callbacks = this._callbacks || {};
  1887. var args = [].slice.call(arguments, 1)
  1888. , callbacks = this._callbacks['$' + event];
  1889. if (callbacks) {
  1890. callbacks = callbacks.slice(0);
  1891. for (var i = 0, len = callbacks.length; i < len; ++i) {
  1892. callbacks[i].apply(this, args);
  1893. }
  1894. }
  1895. return this;
  1896. };
  1897. /**
  1898. * Return array of callbacks for `event`.
  1899. *
  1900. * @param {String} event
  1901. * @return {Array}
  1902. * @api public
  1903. */
  1904. Emitter.prototype.listeners = function(event){
  1905. this._callbacks = this._callbacks || {};
  1906. return this._callbacks['$' + event] || [];
  1907. };
  1908. /**
  1909. * Check if this emitter has `event` handlers.
  1910. *
  1911. * @param {String} event
  1912. * @return {Boolean}
  1913. * @api public
  1914. */
  1915. Emitter.prototype.hasListeners = function(event){
  1916. return !! this.listeners(event).length;
  1917. };
  1918. /***/ }),
  1919. /* 12 */
  1920. /***/ (function(module, exports, __webpack_require__) {
  1921. /*global Blob,File*/
  1922. /**
  1923. * Module requirements
  1924. */
  1925. var isArray = __webpack_require__(13);
  1926. var isBuf = __webpack_require__(14);
  1927. var toString = Object.prototype.toString;
  1928. var withNativeBlob = typeof Blob === 'function' || (typeof Blob !== 'undefined' && toString.call(Blob) === '[object BlobConstructor]');
  1929. var withNativeFile = typeof File === 'function' || (typeof File !== 'undefined' && toString.call(File) === '[object FileConstructor]');
  1930. /**
  1931. * Replaces every Buffer | ArrayBuffer in packet with a numbered placeholder.
  1932. * Anything with blobs or files should be fed through removeBlobs before coming
  1933. * here.
  1934. *
  1935. * @param {Object} packet - socket.io event packet
  1936. * @return {Object} with deconstructed packet and list of buffers
  1937. * @api public
  1938. */
  1939. exports.deconstructPacket = function(packet) {
  1940. var buffers = [];
  1941. var packetData = packet.data;
  1942. var pack = packet;
  1943. pack.data = _deconstructPacket(packetData, buffers);
  1944. pack.attachments = buffers.length; // number of binary 'attachments'
  1945. return {packet: pack, buffers: buffers};
  1946. };
  1947. function _deconstructPacket(data, buffers) {
  1948. if (!data) return data;
  1949. if (isBuf(data)) {
  1950. var placeholder = { _placeholder: true, num: buffers.length };
  1951. buffers.push(data);
  1952. return placeholder;
  1953. } else if (isArray(data)) {
  1954. var newData = new Array(data.length);
  1955. for (var i = 0; i < data.length; i++) {
  1956. newData[i] = _deconstructPacket(data[i], buffers);
  1957. }
  1958. return newData;
  1959. } else if (typeof data === 'object' && !(data instanceof Date)) {
  1960. var newData = {};
  1961. for (var key in data) {
  1962. newData[key] = _deconstructPacket(data[key], buffers);
  1963. }
  1964. return newData;
  1965. }
  1966. return data;
  1967. }
  1968. /**
  1969. * Reconstructs a binary packet from its placeholder packet and buffers
  1970. *
  1971. * @param {Object} packet - event packet with placeholders
  1972. * @param {Array} buffers - binary buffers to put in placeholder positions
  1973. * @return {Object} reconstructed packet
  1974. * @api public
  1975. */
  1976. exports.reconstructPacket = function(packet, buffers) {
  1977. packet.data = _reconstructPacket(packet.data, buffers);
  1978. packet.attachments = undefined; // no longer useful
  1979. return packet;
  1980. };
  1981. function _reconstructPacket(data, buffers) {
  1982. if (!data) return data;
  1983. if (data && data._placeholder) {
  1984. return buffers[data.num]; // appropriate buffer (should be natural order anyway)
  1985. } else if (isArray(data)) {
  1986. for (var i = 0; i < data.length; i++) {
  1987. data[i] = _reconstructPacket(data[i], buffers);
  1988. }
  1989. } else if (typeof data === 'object') {
  1990. for (var key in data) {
  1991. data[key] = _reconstructPacket(data[key], buffers);
  1992. }
  1993. }
  1994. return data;
  1995. }
  1996. /**
  1997. * Asynchronously removes Blobs or Files from data via
  1998. * FileReader's readAsArrayBuffer method. Used before encoding
  1999. * data as msgpack. Calls callback with the blobless data.
  2000. *
  2001. * @param {Object} data
  2002. * @param {Function} callback
  2003. * @api private
  2004. */
  2005. exports.removeBlobs = function(data, callback) {
  2006. function _removeBlobs(obj, curKey, containingObject) {
  2007. if (!obj) return obj;
  2008. // convert any blob
  2009. if ((withNativeBlob && obj instanceof Blob) ||
  2010. (withNativeFile && obj instanceof File)) {
  2011. pendingBlobs++;
  2012. // async filereader
  2013. var fileReader = new FileReader();
  2014. fileReader.onload = function() { // this.result == arraybuffer
  2015. if (containingObject) {
  2016. containingObject[curKey] = this.result;
  2017. }
  2018. else {
  2019. bloblessData = this.result;
  2020. }
  2021. // if nothing pending its callback time
  2022. if(! --pendingBlobs) {
  2023. callback(bloblessData);
  2024. }
  2025. };
  2026. fileReader.readAsArrayBuffer(obj); // blob -> arraybuffer
  2027. } else if (isArray(obj)) { // handle array
  2028. for (var i = 0; i < obj.length; i++) {
  2029. _removeBlobs(obj[i], i, obj);
  2030. }
  2031. } else if (typeof obj === 'object' && !isBuf(obj)) { // and object
  2032. for (var key in obj) {
  2033. _removeBlobs(obj[key], key, obj);
  2034. }
  2035. }
  2036. }
  2037. var pendingBlobs = 0;
  2038. var bloblessData = data;
  2039. _removeBlobs(bloblessData);
  2040. if (!pendingBlobs) {
  2041. callback(bloblessData);
  2042. }
  2043. };
  2044. /***/ }),
  2045. /* 13 */
  2046. /***/ (function(module, exports) {
  2047. var toString = {}.toString;
  2048. module.exports = Array.isArray || function (arr) {
  2049. return toString.call(arr) == '[object Array]';
  2050. };
  2051. /***/ }),
  2052. /* 14 */
  2053. /***/ (function(module, exports) {
  2054. module.exports = isBuf;
  2055. var withNativeBuffer = typeof Buffer === 'function' && typeof Buffer.isBuffer === 'function';
  2056. var withNativeArrayBuffer = typeof ArrayBuffer === 'function';
  2057. var isView = function (obj) {
  2058. return typeof ArrayBuffer.isView === 'function' ? ArrayBuffer.isView(obj) : (obj.buffer instanceof ArrayBuffer);
  2059. };
  2060. /**
  2061. * Returns true if obj is a buffer or an arraybuffer.
  2062. *
  2063. * @api private
  2064. */
  2065. function isBuf(obj) {
  2066. return (withNativeBuffer && Buffer.isBuffer(obj)) ||
  2067. (withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)));
  2068. }
  2069. /***/ }),
  2070. /* 15 */
  2071. /***/ (function(module, exports, __webpack_require__) {
  2072. /**
  2073. * Module dependencies.
  2074. */
  2075. var eio = __webpack_require__(16);
  2076. var Socket = __webpack_require__(39);
  2077. var Emitter = __webpack_require__(11);
  2078. var parser = __webpack_require__(7);
  2079. var on = __webpack_require__(41);
  2080. var bind = __webpack_require__(42);
  2081. var debug = __webpack_require__(3)('socket.io-client:manager');
  2082. var indexOf = __webpack_require__(38);
  2083. var Backoff = __webpack_require__(43);
  2084. /**
  2085. * IE6+ hasOwnProperty
  2086. */
  2087. var has = Object.prototype.hasOwnProperty;
  2088. /**
  2089. * Module exports
  2090. */
  2091. module.exports = Manager;
  2092. /**
  2093. * `Manager` constructor.
  2094. *
  2095. * @param {String} engine instance or engine uri/opts
  2096. * @param {Object} options
  2097. * @api public
  2098. */
  2099. function Manager (uri, opts) {
  2100. if (!(this instanceof Manager)) return new Manager(uri, opts);
  2101. if (uri && ('object' === typeof uri)) {
  2102. opts = uri;
  2103. uri = undefined;
  2104. }
  2105. opts = opts || {};
  2106. opts.path = opts.path || '/socket.io';
  2107. this.nsps = {};
  2108. this.subs = [];
  2109. this.opts = opts;
  2110. this.reconnection(opts.reconnection !== false);
  2111. this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
  2112. this.reconnectionDelay(opts.reconnectionDelay || 1000);
  2113. this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
  2114. this.randomizationFactor(opts.randomizationFactor || 0.5);
  2115. this.backoff = new Backoff({
  2116. min: this.reconnectionDelay(),
  2117. max: this.reconnectionDelayMax(),
  2118. jitter: this.randomizationFactor()
  2119. });
  2120. this.timeout(null == opts.timeout ? 20000 : opts.timeout);
  2121. this.readyState = 'closed';
  2122. this.uri = uri;
  2123. this.connecting = [];
  2124. this.lastPing = null;
  2125. this.encoding = false;
  2126. this.packetBuffer = [];
  2127. var _parser = opts.parser || parser;
  2128. this.encoder = new _parser.Encoder();
  2129. this.decoder = new _parser.Decoder();
  2130. this.autoConnect = opts.autoConnect !== false;
  2131. if (this.autoConnect) this.open();
  2132. }
  2133. /**
  2134. * Propagate given event to sockets and emit on `this`
  2135. *
  2136. * @api private
  2137. */
  2138. Manager.prototype.emitAll = function () {
  2139. this.emit.apply(this, arguments);
  2140. for (var nsp in this.nsps) {
  2141. if (has.call(this.nsps, nsp)) {
  2142. this.nsps[nsp].emit.apply(this.nsps[nsp], arguments);
  2143. }
  2144. }
  2145. };
  2146. /**
  2147. * Update `socket.id` of all sockets
  2148. *
  2149. * @api private
  2150. */
  2151. Manager.prototype.updateSocketIds = function () {
  2152. for (var nsp in this.nsps) {
  2153. if (has.call(this.nsps, nsp)) {
  2154. this.nsps[nsp].id = this.generateId(nsp);
  2155. }
  2156. }
  2157. };
  2158. /**
  2159. * generate `socket.id` for the given `nsp`
  2160. *
  2161. * @param {String} nsp
  2162. * @return {String}
  2163. * @api private
  2164. */
  2165. Manager.prototype.generateId = function (nsp) {
  2166. return (nsp === '/' ? '' : (nsp + '#')) + this.engine.id;
  2167. };
  2168. /**
  2169. * Mix in `Emitter`.
  2170. */
  2171. Emitter(Manager.prototype);
  2172. /**
  2173. * Sets the `reconnection` config.
  2174. *
  2175. * @param {Boolean} true/false if it should automatically reconnect
  2176. * @return {Manager} self or value
  2177. * @api public
  2178. */
  2179. Manager.prototype.reconnection = function (v) {
  2180. if (!arguments.length) return this._reconnection;
  2181. this._reconnection = !!v;
  2182. return this;
  2183. };
  2184. /**
  2185. * Sets the reconnection attempts config.
  2186. *
  2187. * @param {Number} max reconnection attempts before giving up
  2188. * @return {Manager} self or value
  2189. * @api public
  2190. */
  2191. Manager.prototype.reconnectionAttempts = function (v) {
  2192. if (!arguments.length) return this._reconnectionAttempts;
  2193. this._reconnectionAttempts = v;
  2194. return this;
  2195. };
  2196. /**
  2197. * Sets the delay between reconnections.
  2198. *
  2199. * @param {Number} delay
  2200. * @return {Manager} self or value
  2201. * @api public
  2202. */
  2203. Manager.prototype.reconnectionDelay = function (v) {
  2204. if (!arguments.length) return this._reconnectionDelay;
  2205. this._reconnectionDelay = v;
  2206. this.backoff && this.backoff.setMin(v);
  2207. return this;
  2208. };
  2209. Manager.prototype.randomizationFactor = function (v) {
  2210. if (!arguments.length) return this._randomizationFactor;
  2211. this._randomizationFactor = v;
  2212. this.backoff && this.backoff.setJitter(v);
  2213. return this;
  2214. };
  2215. /**
  2216. * Sets the maximum delay between reconnections.
  2217. *
  2218. * @param {Number} delay
  2219. * @return {Manager} self or value
  2220. * @api public
  2221. */
  2222. Manager.prototype.reconnectionDelayMax = function (v) {
  2223. if (!arguments.length) return this._reconnectionDelayMax;
  2224. this._reconnectionDelayMax = v;
  2225. this.backoff && this.backoff.setMax(v);
  2226. return this;
  2227. };
  2228. /**
  2229. * Sets the connection timeout. `false` to disable
  2230. *
  2231. * @return {Manager} self or value
  2232. * @api public
  2233. */
  2234. Manager.prototype.timeout = function (v) {
  2235. if (!arguments.length) return this._timeout;
  2236. this._timeout = v;
  2237. return this;
  2238. };
  2239. /**
  2240. * Starts trying to reconnect if reconnection is enabled and we have not
  2241. * started reconnecting yet
  2242. *
  2243. * @api private
  2244. */
  2245. Manager.prototype.maybeReconnectOnOpen = function () {
  2246. // Only try to reconnect if it's the first time we're connecting
  2247. if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) {
  2248. // keeps reconnection from firing twice for the same reconnection loop
  2249. this.reconnect();
  2250. }
  2251. };
  2252. /**
  2253. * Sets the current transport `socket`.
  2254. *
  2255. * @param {Function} optional, callback
  2256. * @return {Manager} self
  2257. * @api public
  2258. */
  2259. Manager.prototype.open =
  2260. Manager.prototype.connect = function (fn, opts) {
  2261. debug('readyState %s', this.readyState);
  2262. if (~this.readyState.indexOf('open')) return this;
  2263. debug('opening %s', this.uri);
  2264. this.engine = eio(this.uri, this.opts);
  2265. var socket = this.engine;
  2266. var self = this;
  2267. this.readyState = 'opening';
  2268. this.skipReconnect = false;
  2269. // emit `open`
  2270. var openSub = on(socket, 'open', function () {
  2271. self.onopen();
  2272. fn && fn();
  2273. });
  2274. // emit `connect_error`
  2275. var errorSub = on(socket, 'error', function (data) {
  2276. debug('connect_error');
  2277. self.cleanup();
  2278. self.readyState = 'closed';
  2279. self.emitAll('connect_error', data);
  2280. if (fn) {
  2281. var err = new Error('Connection error');
  2282. err.data = data;
  2283. fn(err);
  2284. } else {
  2285. // Only do this if there is no fn to handle the error
  2286. self.maybeReconnectOnOpen();
  2287. }
  2288. });
  2289. // emit `connect_timeout`
  2290. if (false !== this._timeout) {
  2291. var timeout = this._timeout;
  2292. debug('connect attempt will timeout after %d', timeout);
  2293. // set timer
  2294. var timer = setTimeout(function () {
  2295. debug('connect attempt timed out after %d', timeout);
  2296. openSub.destroy();
  2297. socket.close();
  2298. socket.emit('error', 'timeout');
  2299. self.emitAll('connect_timeout', timeout);
  2300. }, timeout);
  2301. this.subs.push({
  2302. destroy: function () {
  2303. clearTimeout(timer);
  2304. }
  2305. });
  2306. }
  2307. this.subs.push(openSub);
  2308. this.subs.push(errorSub);
  2309. return this;
  2310. };
  2311. /**
  2312. * Called upon transport open.
  2313. *
  2314. * @api private
  2315. */
  2316. Manager.prototype.onopen = function () {
  2317. debug('open');
  2318. // clear old subs
  2319. this.cleanup();
  2320. // mark as open
  2321. this.readyState = 'open';
  2322. this.emit('open');
  2323. // add new subs
  2324. var socket = this.engine;
  2325. this.subs.push(on(socket, 'data', bind(this, 'ondata')));
  2326. this.subs.push(on(socket, 'ping', bind(this, 'onping')));
  2327. this.subs.push(on(socket, 'pong', bind(this, 'onpong')));
  2328. this.subs.push(on(socket, 'error', bind(this, 'onerror')));
  2329. this.subs.push(on(socket, 'close', bind(this, 'onclose')));
  2330. this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded')));
  2331. };
  2332. /**
  2333. * Called upon a ping.
  2334. *
  2335. * @api private
  2336. */
  2337. Manager.prototype.onping = function () {
  2338. this.lastPing = new Date();
  2339. this.emitAll('ping');
  2340. };
  2341. /**
  2342. * Called upon a packet.
  2343. *
  2344. * @api private
  2345. */
  2346. Manager.prototype.onpong = function () {
  2347. this.emitAll('pong', new Date() - this.lastPing);
  2348. };
  2349. /**
  2350. * Called with data.
  2351. *
  2352. * @api private
  2353. */
  2354. Manager.prototype.ondata = function (data) {
  2355. this.decoder.add(data);
  2356. };
  2357. /**
  2358. * Called when parser fully decodes a packet.
  2359. *
  2360. * @api private
  2361. */
  2362. Manager.prototype.ondecoded = function (packet) {
  2363. this.emit('packet', packet);
  2364. };
  2365. /**
  2366. * Called upon socket error.
  2367. *
  2368. * @api private
  2369. */
  2370. Manager.prototype.onerror = function (err) {
  2371. debug('error', err);
  2372. this.emitAll('error', err);
  2373. };
  2374. /**
  2375. * Creates a new socket for the given `nsp`.
  2376. *
  2377. * @return {Socket}
  2378. * @api public
  2379. */
  2380. Manager.prototype.socket = function (nsp, opts) {
  2381. var socket = this.nsps[nsp];
  2382. if (!socket) {
  2383. socket = new Socket(this, nsp, opts);
  2384. this.nsps[nsp] = socket;
  2385. var self = this;
  2386. socket.on('connecting', onConnecting);
  2387. socket.on('connect', function () {
  2388. socket.id = self.generateId(nsp);
  2389. });
  2390. if (this.autoConnect) {
  2391. // manually call here since connecting event is fired before listening
  2392. onConnecting();
  2393. }
  2394. }
  2395. function onConnecting () {
  2396. if (!~indexOf(self.connecting, socket)) {
  2397. self.connecting.push(socket);
  2398. }
  2399. }
  2400. return socket;
  2401. };
  2402. /**
  2403. * Called upon a socket close.
  2404. *
  2405. * @param {Socket} socket
  2406. */
  2407. Manager.prototype.destroy = function (socket) {
  2408. var index = indexOf(this.connecting, socket);
  2409. if (~index) this.connecting.splice(index, 1);
  2410. if (this.connecting.length) return;
  2411. this.close();
  2412. };
  2413. /**
  2414. * Writes a packet.
  2415. *
  2416. * @param {Object} packet
  2417. * @api private
  2418. */
  2419. Manager.prototype.packet = function (packet) {
  2420. debug('writing packet %j', packet);
  2421. var self = this;
  2422. if (packet.query && packet.type === 0) packet.nsp += '?' + packet.query;
  2423. if (!self.encoding) {
  2424. // encode, then write to engine with result
  2425. self.encoding = true;
  2426. this.encoder.encode(packet, function (encodedPackets) {
  2427. for (var i = 0; i < encodedPackets.length; i++) {
  2428. self.engine.write(encodedPackets[i], packet.options);
  2429. }
  2430. self.encoding = false;
  2431. self.processPacketQueue();
  2432. });
  2433. } else { // add packet to the queue
  2434. self.packetBuffer.push(packet);
  2435. }
  2436. };
  2437. /**
  2438. * If packet buffer is non-empty, begins encoding the
  2439. * next packet in line.
  2440. *
  2441. * @api private
  2442. */
  2443. Manager.prototype.processPacketQueue = function () {
  2444. if (this.packetBuffer.length > 0 && !this.encoding) {
  2445. var pack = this.packetBuffer.shift();
  2446. this.packet(pack);
  2447. }
  2448. };
  2449. /**
  2450. * Clean up transport subscriptions and packet buffer.
  2451. *
  2452. * @api private
  2453. */
  2454. Manager.prototype.cleanup = function () {
  2455. debug('cleanup');
  2456. var subsLength = this.subs.length;
  2457. for (var i = 0; i < subsLength; i++) {
  2458. var sub = this.subs.shift();
  2459. sub.destroy();
  2460. }
  2461. this.packetBuffer = [];
  2462. this.encoding = false;
  2463. this.lastPing = null;
  2464. this.decoder.destroy();
  2465. };
  2466. /**
  2467. * Close the current socket.
  2468. *
  2469. * @api private
  2470. */
  2471. Manager.prototype.close =
  2472. Manager.prototype.disconnect = function () {
  2473. debug('disconnect');
  2474. this.skipReconnect = true;
  2475. this.reconnecting = false;
  2476. if ('opening' === this.readyState) {
  2477. // `onclose` will not fire because
  2478. // an open event never happened
  2479. this.cleanup();
  2480. }
  2481. this.backoff.reset();
  2482. this.readyState = 'closed';
  2483. if (this.engine) this.engine.close();
  2484. };
  2485. /**
  2486. * Called upon engine close.
  2487. *
  2488. * @api private
  2489. */
  2490. Manager.prototype.onclose = function (reason) {
  2491. debug('onclose');
  2492. this.cleanup();
  2493. this.backoff.reset();
  2494. this.readyState = 'closed';
  2495. this.emit('close', reason);
  2496. if (this._reconnection && !this.skipReconnect) {
  2497. this.reconnect();
  2498. }
  2499. };
  2500. /**
  2501. * Attempt a reconnection.
  2502. *
  2503. * @api private
  2504. */
  2505. Manager.prototype.reconnect = function () {
  2506. if (this.reconnecting || this.skipReconnect) return this;
  2507. var self = this;
  2508. if (this.backoff.attempts >= this._reconnectionAttempts) {
  2509. debug('reconnect failed');
  2510. this.backoff.reset();
  2511. this.emitAll('reconnect_failed');
  2512. this.reconnecting = false;
  2513. } else {
  2514. var delay = this.backoff.duration();
  2515. debug('will wait %dms before reconnect attempt', delay);
  2516. this.reconnecting = true;
  2517. var timer = setTimeout(function () {
  2518. if (self.skipReconnect) return;
  2519. debug('attempting reconnect');
  2520. self.emitAll('reconnect_attempt', self.backoff.attempts);
  2521. self.emitAll('reconnecting', self.backoff.attempts);
  2522. // check again for the case socket closed in above events
  2523. if (self.skipReconnect) return;
  2524. self.open(function (err) {
  2525. if (err) {
  2526. debug('reconnect attempt error');
  2527. self.reconnecting = false;
  2528. self.reconnect();
  2529. self.emitAll('reconnect_error', err.data);
  2530. } else {
  2531. debug('reconnect success');
  2532. self.onreconnect();
  2533. }
  2534. });
  2535. }, delay);
  2536. this.subs.push({
  2537. destroy: function () {
  2538. clearTimeout(timer);
  2539. }
  2540. });
  2541. }
  2542. };
  2543. /**
  2544. * Called upon successful reconnect.
  2545. *
  2546. * @api private
  2547. */
  2548. Manager.prototype.onreconnect = function () {
  2549. var attempt = this.backoff.attempts;
  2550. this.reconnecting = false;
  2551. this.backoff.reset();
  2552. this.updateSocketIds();
  2553. this.emitAll('reconnect', attempt);
  2554. };
  2555. /***/ }),
  2556. /* 16 */
  2557. /***/ (function(module, exports, __webpack_require__) {
  2558. module.exports = __webpack_require__(17);
  2559. /**
  2560. * Exports parser
  2561. *
  2562. * @api public
  2563. *
  2564. */
  2565. module.exports.parser = __webpack_require__(24);
  2566. /***/ }),
  2567. /* 17 */
  2568. /***/ (function(module, exports, __webpack_require__) {
  2569. /**
  2570. * Module dependencies.
  2571. */
  2572. var transports = __webpack_require__(18);
  2573. var Emitter = __webpack_require__(11);
  2574. var debug = __webpack_require__(3)('engine.io-client:socket');
  2575. var index = __webpack_require__(38);
  2576. var parser = __webpack_require__(24);
  2577. var parseuri = __webpack_require__(2);
  2578. var parseqs = __webpack_require__(32);
  2579. /**
  2580. * Module exports.
  2581. */
  2582. module.exports = Socket;
  2583. /**
  2584. * Socket constructor.
  2585. *
  2586. * @param {String|Object} uri or options
  2587. * @param {Object} options
  2588. * @api public
  2589. */
  2590. function Socket (uri, opts) {
  2591. if (!(this instanceof Socket)) return new Socket(uri, opts);
  2592. opts = opts || {};
  2593. if (uri && 'object' === typeof uri) {
  2594. opts = uri;
  2595. uri = null;
  2596. }
  2597. if (uri) {
  2598. uri = parseuri(uri);
  2599. opts.hostname = uri.host;
  2600. opts.secure = uri.protocol === 'https' || uri.protocol === 'wss';
  2601. opts.port = uri.port;
  2602. if (uri.query) opts.query = uri.query;
  2603. } else if (opts.host) {
  2604. opts.hostname = parseuri(opts.host).host;
  2605. }
  2606. this.secure = null != opts.secure ? opts.secure
  2607. : (typeof location !== 'undefined' && 'https:' === location.protocol);
  2608. if (opts.hostname && !opts.port) {
  2609. // if no port is specified manually, use the protocol default
  2610. opts.port = this.secure ? '443' : '80';
  2611. }
  2612. this.agent = opts.agent || false;
  2613. this.hostname = opts.hostname ||
  2614. (typeof location !== 'undefined' ? location.hostname : 'localhost');
  2615. this.port = opts.port || (typeof location !== 'undefined' && location.port
  2616. ? location.port
  2617. : (this.secure ? 443 : 80));
  2618. this.query = opts.query || {};
  2619. if ('string' === typeof this.query) this.query = parseqs.decode(this.query);
  2620. this.upgrade = false !== opts.upgrade;
  2621. this.path = (opts.path || '/engine.io').replace(/\/$/, '') + '/';
  2622. this.forceJSONP = !!opts.forceJSONP;
  2623. this.jsonp = false !== opts.jsonp;
  2624. this.forceBase64 = !!opts.forceBase64;
  2625. this.enablesXDR = !!opts.enablesXDR;
  2626. this.withCredentials = false !== opts.withCredentials;
  2627. this.timestampParam = opts.timestampParam || 't';
  2628. this.timestampRequests = opts.timestampRequests;
  2629. this.transports = opts.transports || ['polling', 'websocket'];
  2630. this.transportOptions = opts.transportOptions || {};
  2631. this.readyState = '';
  2632. this.writeBuffer = [];
  2633. this.prevBufferLen = 0;
  2634. this.policyPort = opts.policyPort || 843;
  2635. this.rememberUpgrade = opts.rememberUpgrade || false;
  2636. this.binaryType = null;
  2637. this.onlyBinaryUpgrades = opts.onlyBinaryUpgrades;
  2638. this.perMessageDeflate = false !== opts.perMessageDeflate ? (opts.perMessageDeflate || {}) : false;
  2639. if (true === this.perMessageDeflate) this.perMessageDeflate = {};
  2640. if (this.perMessageDeflate && null == this.perMessageDeflate.threshold) {
  2641. this.perMessageDeflate.threshold = 1024;
  2642. }
  2643. // SSL options for Node.js client
  2644. this.pfx = opts.pfx || null;
  2645. this.key = opts.key || null;
  2646. this.passphrase = opts.passphrase || null;
  2647. this.cert = opts.cert || null;
  2648. this.ca = opts.ca || null;
  2649. this.ciphers = opts.ciphers || null;
  2650. this.rejectUnauthorized = opts.rejectUnauthorized === undefined ? true : opts.rejectUnauthorized;
  2651. this.forceNode = !!opts.forceNode;
  2652. // detect ReactNative environment
  2653. this.isReactNative = (typeof navigator !== 'undefined' && typeof navigator.product === 'string' && navigator.product.toLowerCase() === 'reactnative');
  2654. // other options for Node.js or ReactNative client
  2655. if (typeof self === 'undefined' || this.isReactNative) {
  2656. if (opts.extraHeaders && Object.keys(opts.extraHeaders).length > 0) {
  2657. this.extraHeaders = opts.extraHeaders;
  2658. }
  2659. if (opts.localAddress) {
  2660. this.localAddress = opts.localAddress;
  2661. }
  2662. }
  2663. // set on handshake
  2664. this.id = null;
  2665. this.upgrades = null;
  2666. this.pingInterval = null;
  2667. this.pingTimeout = null;
  2668. // set on heartbeat
  2669. this.pingIntervalTimer = null;
  2670. this.pingTimeoutTimer = null;
  2671. this.open();
  2672. }
  2673. Socket.priorWebsocketSuccess = false;
  2674. /**
  2675. * Mix in `Emitter`.
  2676. */
  2677. Emitter(Socket.prototype);
  2678. /**
  2679. * Protocol version.
  2680. *
  2681. * @api public
  2682. */
  2683. Socket.protocol = parser.protocol; // this is an int
  2684. /**
  2685. * Expose deps for legacy compatibility
  2686. * and standalone browser access.
  2687. */
  2688. Socket.Socket = Socket;
  2689. Socket.Transport = __webpack_require__(23);
  2690. Socket.transports = __webpack_require__(18);
  2691. Socket.parser = __webpack_require__(24);
  2692. /**
  2693. * Creates transport of the given type.
  2694. *
  2695. * @param {String} transport name
  2696. * @return {Transport}
  2697. * @api private
  2698. */
  2699. Socket.prototype.createTransport = function (name) {
  2700. debug('creating transport "%s"', name);
  2701. var query = clone(this.query);
  2702. // append engine.io protocol identifier
  2703. query.EIO = parser.protocol;
  2704. // transport name
  2705. query.transport = name;
  2706. // per-transport options
  2707. var options = this.transportOptions[name] || {};
  2708. // session id if we already have one
  2709. if (this.id) query.sid = this.id;
  2710. var transport = new transports[name]({
  2711. query: query,
  2712. socket: this,
  2713. agent: options.agent || this.agent,
  2714. hostname: options.hostname || this.hostname,
  2715. port: options.port || this.port,
  2716. secure: options.secure || this.secure,
  2717. path: options.path || this.path,
  2718. forceJSONP: options.forceJSONP || this.forceJSONP,
  2719. jsonp: options.jsonp || this.jsonp,
  2720. forceBase64: options.forceBase64 || this.forceBase64,
  2721. enablesXDR: options.enablesXDR || this.enablesXDR,
  2722. withCredentials: options.withCredentials || this.withCredentials,
  2723. timestampRequests: options.timestampRequests || this.timestampRequests,
  2724. timestampParam: options.timestampParam || this.timestampParam,
  2725. policyPort: options.policyPort || this.policyPort,
  2726. pfx: options.pfx || this.pfx,
  2727. key: options.key || this.key,
  2728. passphrase: options.passphrase || this.passphrase,
  2729. cert: options.cert || this.cert,
  2730. ca: options.ca || this.ca,
  2731. ciphers: options.ciphers || this.ciphers,
  2732. rejectUnauthorized: options.rejectUnauthorized || this.rejectUnauthorized,
  2733. perMessageDeflate: options.perMessageDeflate || this.perMessageDeflate,
  2734. extraHeaders: options.extraHeaders || this.extraHeaders,
  2735. forceNode: options.forceNode || this.forceNode,
  2736. localAddress: options.localAddress || this.localAddress,
  2737. requestTimeout: options.requestTimeout || this.requestTimeout,
  2738. protocols: options.protocols || void (0),
  2739. isReactNative: this.isReactNative
  2740. });
  2741. return transport;
  2742. };
  2743. function clone (obj) {
  2744. var o = {};
  2745. for (var i in obj) {
  2746. if (obj.hasOwnProperty(i)) {
  2747. o[i] = obj[i];
  2748. }
  2749. }
  2750. return o;
  2751. }
  2752. /**
  2753. * Initializes transport to use and starts probe.
  2754. *
  2755. * @api private
  2756. */
  2757. Socket.prototype.open = function () {
  2758. var transport;
  2759. if (this.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf('websocket') !== -1) {
  2760. transport = 'websocket';
  2761. } else if (0 === this.transports.length) {
  2762. // Emit error on next tick so it can be listened to
  2763. var self = this;
  2764. setTimeout(function () {
  2765. self.emit('error', 'No transports available');
  2766. }, 0);
  2767. return;
  2768. } else {
  2769. transport = this.transports[0];
  2770. }
  2771. this.readyState = 'opening';
  2772. // Retry with the next transport if the transport is disabled (jsonp: false)
  2773. try {
  2774. transport = this.createTransport(transport);
  2775. } catch (e) {
  2776. this.transports.shift();
  2777. this.open();
  2778. return;
  2779. }
  2780. transport.open();
  2781. this.setTransport(transport);
  2782. };
  2783. /**
  2784. * Sets the current transport. Disables the existing one (if any).
  2785. *
  2786. * @api private
  2787. */
  2788. Socket.prototype.setTransport = function (transport) {
  2789. debug('setting transport %s', transport.name);
  2790. var self = this;
  2791. if (this.transport) {
  2792. debug('clearing existing transport %s', this.transport.name);
  2793. this.transport.removeAllListeners();
  2794. }
  2795. // set up transport
  2796. this.transport = transport;
  2797. // set up transport listeners
  2798. transport
  2799. .on('drain', function () {
  2800. self.onDrain();
  2801. })
  2802. .on('packet', function (packet) {
  2803. self.onPacket(packet);
  2804. })
  2805. .on('error', function (e) {
  2806. self.onError(e);
  2807. })
  2808. .on('close', function () {
  2809. self.onClose('transport close');
  2810. });
  2811. };
  2812. /**
  2813. * Probes a transport.
  2814. *
  2815. * @param {String} transport name
  2816. * @api private
  2817. */
  2818. Socket.prototype.probe = function (name) {
  2819. debug('probing transport "%s"', name);
  2820. var transport = this.createTransport(name, { probe: 1 });
  2821. var failed = false;
  2822. var self = this;
  2823. Socket.priorWebsocketSuccess = false;
  2824. function onTransportOpen () {
  2825. if (self.onlyBinaryUpgrades) {
  2826. var upgradeLosesBinary = !this.supportsBinary && self.transport.supportsBinary;
  2827. failed = failed || upgradeLosesBinary;
  2828. }
  2829. if (failed) return;
  2830. debug('probe transport "%s" opened', name);
  2831. transport.send([{ type: 'ping', data: 'probe' }]);
  2832. transport.once('packet', function (msg) {
  2833. if (failed) return;
  2834. if ('pong' === msg.type && 'probe' === msg.data) {
  2835. debug('probe transport "%s" pong', name);
  2836. self.upgrading = true;
  2837. self.emit('upgrading', transport);
  2838. if (!transport) return;
  2839. Socket.priorWebsocketSuccess = 'websocket' === transport.name;
  2840. debug('pausing current transport "%s"', self.transport.name);
  2841. self.transport.pause(function () {
  2842. if (failed) return;
  2843. if ('closed' === self.readyState) return;
  2844. debug('changing transport and sending upgrade packet');
  2845. cleanup();
  2846. self.setTransport(transport);
  2847. transport.send([{ type: 'upgrade' }]);
  2848. self.emit('upgrade', transport);
  2849. transport = null;
  2850. self.upgrading = false;
  2851. self.flush();
  2852. });
  2853. } else {
  2854. debug('probe transport "%s" failed', name);
  2855. var err = new Error('probe error');
  2856. err.transport = transport.name;
  2857. self.emit('upgradeError', err);
  2858. }
  2859. });
  2860. }
  2861. function freezeTransport () {
  2862. if (failed) return;
  2863. // Any callback called by transport should be ignored since now
  2864. failed = true;
  2865. cleanup();
  2866. transport.close();
  2867. transport = null;
  2868. }
  2869. // Handle any error that happens while probing
  2870. function onerror (err) {
  2871. var error = new Error('probe error: ' + err);
  2872. error.transport = transport.name;
  2873. freezeTransport();
  2874. debug('probe transport "%s" failed because of error: %s', name, err);
  2875. self.emit('upgradeError', error);
  2876. }
  2877. function onTransportClose () {
  2878. onerror('transport closed');
  2879. }
  2880. // When the socket is closed while we're probing
  2881. function onclose () {
  2882. onerror('socket closed');
  2883. }
  2884. // When the socket is upgraded while we're probing
  2885. function onupgrade (to) {
  2886. if (transport && to.name !== transport.name) {
  2887. debug('"%s" works - aborting "%s"', to.name, transport.name);
  2888. freezeTransport();
  2889. }
  2890. }
  2891. // Remove all listeners on the transport and on self
  2892. function cleanup () {
  2893. transport.removeListener('open', onTransportOpen);
  2894. transport.removeListener('error', onerror);
  2895. transport.removeListener('close', onTransportClose);
  2896. self.removeListener('close', onclose);
  2897. self.removeListener('upgrading', onupgrade);
  2898. }
  2899. transport.once('open', onTransportOpen);
  2900. transport.once('error', onerror);
  2901. transport.once('close', onTransportClose);
  2902. this.once('close', onclose);
  2903. this.once('upgrading', onupgrade);
  2904. transport.open();
  2905. };
  2906. /**
  2907. * Called when connection is deemed open.
  2908. *
  2909. * @api public
  2910. */
  2911. Socket.prototype.onOpen = function () {
  2912. debug('socket open');
  2913. this.readyState = 'open';
  2914. Socket.priorWebsocketSuccess = 'websocket' === this.transport.name;
  2915. this.emit('open');
  2916. this.flush();
  2917. // we check for `readyState` in case an `open`
  2918. // listener already closed the socket
  2919. if ('open' === this.readyState && this.upgrade && this.transport.pause) {
  2920. debug('starting upgrade probes');
  2921. for (var i = 0, l = this.upgrades.length; i < l; i++) {
  2922. this.probe(this.upgrades[i]);
  2923. }
  2924. }
  2925. };
  2926. /**
  2927. * Handles a packet.
  2928. *
  2929. * @api private
  2930. */
  2931. Socket.prototype.onPacket = function (packet) {
  2932. if ('opening' === this.readyState || 'open' === this.readyState ||
  2933. 'closing' === this.readyState) {
  2934. debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
  2935. this.emit('packet', packet);
  2936. // Socket is live - any packet counts
  2937. this.emit('heartbeat');
  2938. switch (packet.type) {
  2939. case 'open':
  2940. this.onHandshake(JSON.parse(packet.data));
  2941. break;
  2942. case 'pong':
  2943. this.setPing();
  2944. this.emit('pong');
  2945. break;
  2946. case 'error':
  2947. var err = new Error('server error');
  2948. err.code = packet.data;
  2949. this.onError(err);
  2950. break;
  2951. case 'message':
  2952. this.emit('data', packet.data);
  2953. this.emit('message', packet.data);
  2954. break;
  2955. }
  2956. } else {
  2957. debug('packet received with socket readyState "%s"', this.readyState);
  2958. }
  2959. };
  2960. /**
  2961. * Called upon handshake completion.
  2962. *
  2963. * @param {Object} handshake obj
  2964. * @api private
  2965. */
  2966. Socket.prototype.onHandshake = function (data) {
  2967. this.emit('handshake', data);
  2968. this.id = data.sid;
  2969. this.transport.query.sid = data.sid;
  2970. this.upgrades = this.filterUpgrades(data.upgrades);
  2971. this.pingInterval = data.pingInterval;
  2972. this.pingTimeout = data.pingTimeout;
  2973. this.onOpen();
  2974. // In case open handler closes socket
  2975. if ('closed' === this.readyState) return;
  2976. this.setPing();
  2977. // Prolong liveness of socket on heartbeat
  2978. this.removeListener('heartbeat', this.onHeartbeat);
  2979. this.on('heartbeat', this.onHeartbeat);
  2980. };
  2981. /**
  2982. * Resets ping timeout.
  2983. *
  2984. * @api private
  2985. */
  2986. Socket.prototype.onHeartbeat = function (timeout) {
  2987. clearTimeout(this.pingTimeoutTimer);
  2988. var self = this;
  2989. self.pingTimeoutTimer = setTimeout(function () {
  2990. if ('closed' === self.readyState) return;
  2991. self.onClose('ping timeout');
  2992. }, timeout || (self.pingInterval + self.pingTimeout));
  2993. };
  2994. /**
  2995. * Pings server every `this.pingInterval` and expects response
  2996. * within `this.pingTimeout` or closes connection.
  2997. *
  2998. * @api private
  2999. */
  3000. Socket.prototype.setPing = function () {
  3001. var self = this;
  3002. clearTimeout(self.pingIntervalTimer);
  3003. self.pingIntervalTimer = setTimeout(function () {
  3004. debug('writing ping packet - expecting pong within %sms', self.pingTimeout);
  3005. self.ping();
  3006. self.onHeartbeat(self.pingTimeout);
  3007. }, self.pingInterval);
  3008. };
  3009. /**
  3010. * Sends a ping packet.
  3011. *
  3012. * @api private
  3013. */
  3014. Socket.prototype.ping = function () {
  3015. var self = this;
  3016. this.sendPacket('ping', function () {
  3017. self.emit('ping');
  3018. });
  3019. };
  3020. /**
  3021. * Called on `drain` event
  3022. *
  3023. * @api private
  3024. */
  3025. Socket.prototype.onDrain = function () {
  3026. this.writeBuffer.splice(0, this.prevBufferLen);
  3027. // setting prevBufferLen = 0 is very important
  3028. // for example, when upgrading, upgrade packet is sent over,
  3029. // and a nonzero prevBufferLen could cause problems on `drain`
  3030. this.prevBufferLen = 0;
  3031. if (0 === this.writeBuffer.length) {
  3032. this.emit('drain');
  3033. } else {
  3034. this.flush();
  3035. }
  3036. };
  3037. /**
  3038. * Flush write buffers.
  3039. *
  3040. * @api private
  3041. */
  3042. Socket.prototype.flush = function () {
  3043. if ('closed' !== this.readyState && this.transport.writable &&
  3044. !this.upgrading && this.writeBuffer.length) {
  3045. debug('flushing %d packets in socket', this.writeBuffer.length);
  3046. this.transport.send(this.writeBuffer);
  3047. // keep track of current length of writeBuffer
  3048. // splice writeBuffer and callbackBuffer on `drain`
  3049. this.prevBufferLen = this.writeBuffer.length;
  3050. this.emit('flush');
  3051. }
  3052. };
  3053. /**
  3054. * Sends a message.
  3055. *
  3056. * @param {String} message.
  3057. * @param {Function} callback function.
  3058. * @param {Object} options.
  3059. * @return {Socket} for chaining.
  3060. * @api public
  3061. */
  3062. Socket.prototype.write =
  3063. Socket.prototype.send = function (msg, options, fn) {
  3064. this.sendPacket('message', msg, options, fn);
  3065. return this;
  3066. };
  3067. /**
  3068. * Sends a packet.
  3069. *
  3070. * @param {String} packet type.
  3071. * @param {String} data.
  3072. * @param {Object} options.
  3073. * @param {Function} callback function.
  3074. * @api private
  3075. */
  3076. Socket.prototype.sendPacket = function (type, data, options, fn) {
  3077. if ('function' === typeof data) {
  3078. fn = data;
  3079. data = undefined;
  3080. }
  3081. if ('function' === typeof options) {
  3082. fn = options;
  3083. options = null;
  3084. }
  3085. if ('closing' === this.readyState || 'closed' === this.readyState) {
  3086. return;
  3087. }
  3088. options = options || {};
  3089. options.compress = false !== options.compress;
  3090. var packet = {
  3091. type: type,
  3092. data: data,
  3093. options: options
  3094. };
  3095. this.emit('packetCreate', packet);
  3096. this.writeBuffer.push(packet);
  3097. if (fn) this.once('flush', fn);
  3098. this.flush();
  3099. };
  3100. /**
  3101. * Closes the connection.
  3102. *
  3103. * @api private
  3104. */
  3105. Socket.prototype.close = function () {
  3106. if ('opening' === this.readyState || 'open' === this.readyState) {
  3107. this.readyState = 'closing';
  3108. var self = this;
  3109. if (this.writeBuffer.length) {
  3110. this.once('drain', function () {
  3111. if (this.upgrading) {
  3112. waitForUpgrade();
  3113. } else {
  3114. close();
  3115. }
  3116. });
  3117. } else if (this.upgrading) {
  3118. waitForUpgrade();
  3119. } else {
  3120. close();
  3121. }
  3122. }
  3123. function close () {
  3124. self.onClose('forced close');
  3125. debug('socket closing - telling transport to close');
  3126. self.transport.close();
  3127. }
  3128. function cleanupAndClose () {
  3129. self.removeListener('upgrade', cleanupAndClose);
  3130. self.removeListener('upgradeError', cleanupAndClose);
  3131. close();
  3132. }
  3133. function waitForUpgrade () {
  3134. // wait for upgrade to finish since we can't send packets while pausing a transport
  3135. self.once('upgrade', cleanupAndClose);
  3136. self.once('upgradeError', cleanupAndClose);
  3137. }
  3138. return this;
  3139. };
  3140. /**
  3141. * Called upon transport error
  3142. *
  3143. * @api private
  3144. */
  3145. Socket.prototype.onError = function (err) {
  3146. debug('socket error %j', err);
  3147. Socket.priorWebsocketSuccess = false;
  3148. this.emit('error', err);
  3149. this.onClose('transport error', err);
  3150. };
  3151. /**
  3152. * Called upon transport close.
  3153. *
  3154. * @api private
  3155. */
  3156. Socket.prototype.onClose = function (reason, desc) {
  3157. if ('opening' === this.readyState || 'open' === this.readyState || 'closing' === this.readyState) {
  3158. debug('socket close with reason: "%s"', reason);
  3159. var self = this;
  3160. // clear timers
  3161. clearTimeout(this.pingIntervalTimer);
  3162. clearTimeout(this.pingTimeoutTimer);
  3163. // stop event from firing again for transport
  3164. this.transport.removeAllListeners('close');
  3165. // ensure transport won't stay open
  3166. this.transport.close();
  3167. // ignore further transport communication
  3168. this.transport.removeAllListeners();
  3169. // set ready state
  3170. this.readyState = 'closed';
  3171. // clear session id
  3172. this.id = null;
  3173. // emit close event
  3174. this.emit('close', reason, desc);
  3175. // clean buffers after, so users can still
  3176. // grab the buffers on `close` event
  3177. self.writeBuffer = [];
  3178. self.prevBufferLen = 0;
  3179. }
  3180. };
  3181. /**
  3182. * Filters upgrades, returning only those matching client transports.
  3183. *
  3184. * @param {Array} server upgrades
  3185. * @api private
  3186. *
  3187. */
  3188. Socket.prototype.filterUpgrades = function (upgrades) {
  3189. var filteredUpgrades = [];
  3190. for (var i = 0, j = upgrades.length; i < j; i++) {
  3191. if (~index(this.transports, upgrades[i])) filteredUpgrades.push(upgrades[i]);
  3192. }
  3193. return filteredUpgrades;
  3194. };
  3195. /***/ }),
  3196. /* 18 */
  3197. /***/ (function(module, exports, __webpack_require__) {
  3198. /**
  3199. * Module dependencies
  3200. */
  3201. var XMLHttpRequest = __webpack_require__(19);
  3202. var XHR = __webpack_require__(21);
  3203. var JSONP = __webpack_require__(35);
  3204. var websocket = __webpack_require__(36);
  3205. /**
  3206. * Export transports.
  3207. */
  3208. exports.polling = polling;
  3209. exports.websocket = websocket;
  3210. /**
  3211. * Polling transport polymorphic constructor.
  3212. * Decides on xhr vs jsonp based on feature detection.
  3213. *
  3214. * @api private
  3215. */
  3216. function polling (opts) {
  3217. var xhr;
  3218. var xd = false;
  3219. var xs = false;
  3220. var jsonp = false !== opts.jsonp;
  3221. if (typeof location !== 'undefined') {
  3222. var isSSL = 'https:' === location.protocol;
  3223. var port = location.port;
  3224. // some user agents have empty `location.port`
  3225. if (!port) {
  3226. port = isSSL ? 443 : 80;
  3227. }
  3228. xd = opts.hostname !== location.hostname || port !== opts.port;
  3229. xs = opts.secure !== isSSL;
  3230. }
  3231. opts.xdomain = xd;
  3232. opts.xscheme = xs;
  3233. xhr = new XMLHttpRequest(opts);
  3234. if ('open' in xhr && !opts.forceJSONP) {
  3235. return new XHR(opts);
  3236. } else {
  3237. if (!jsonp) throw new Error('JSONP disabled');
  3238. return new JSONP(opts);
  3239. }
  3240. }
  3241. /***/ }),
  3242. /* 19 */
  3243. /***/ (function(module, exports, __webpack_require__) {
  3244. // browser shim for xmlhttprequest module
  3245. var hasCORS = __webpack_require__(20);
  3246. module.exports = function (opts) {
  3247. var xdomain = opts.xdomain;
  3248. // scheme must be same when usign XDomainRequest
  3249. // http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
  3250. var xscheme = opts.xscheme;
  3251. // XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default.
  3252. // https://github.com/Automattic/engine.io-client/pull/217
  3253. var enablesXDR = opts.enablesXDR;
  3254. // XMLHttpRequest can be disabled on IE
  3255. try {
  3256. if ('undefined' !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
  3257. return new XMLHttpRequest();
  3258. }
  3259. } catch (e) { }
  3260. // Use XDomainRequest for IE8 if enablesXDR is true
  3261. // because loading bar keeps flashing when using jsonp-polling
  3262. // https://github.com/yujiosaka/socke.io-ie8-loading-example
  3263. try {
  3264. if ('undefined' !== typeof XDomainRequest && !xscheme && enablesXDR) {
  3265. return new XDomainRequest();
  3266. }
  3267. } catch (e) { }
  3268. if (!xdomain) {
  3269. try {
  3270. return new self[['Active'].concat('Object').join('X')]('Microsoft.XMLHTTP');
  3271. } catch (e) { }
  3272. }
  3273. };
  3274. /***/ }),
  3275. /* 20 */
  3276. /***/ (function(module, exports) {
  3277. /**
  3278. * Module exports.
  3279. *
  3280. * Logic borrowed from Modernizr:
  3281. *
  3282. * - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
  3283. */
  3284. try {
  3285. module.exports = typeof XMLHttpRequest !== 'undefined' &&
  3286. 'withCredentials' in new XMLHttpRequest();
  3287. } catch (err) {
  3288. // if XMLHttp support is disabled in IE then it will throw
  3289. // when trying to create
  3290. module.exports = false;
  3291. }
  3292. /***/ }),
  3293. /* 21 */
  3294. /***/ (function(module, exports, __webpack_require__) {
  3295. /* global attachEvent */
  3296. /**
  3297. * Module requirements.
  3298. */
  3299. var XMLHttpRequest = __webpack_require__(19);
  3300. var Polling = __webpack_require__(22);
  3301. var Emitter = __webpack_require__(11);
  3302. var inherit = __webpack_require__(33);
  3303. var debug = __webpack_require__(3)('engine.io-client:polling-xhr');
  3304. /**
  3305. * Module exports.
  3306. */
  3307. module.exports = XHR;
  3308. module.exports.Request = Request;
  3309. /**
  3310. * Empty function
  3311. */
  3312. function empty () {}
  3313. /**
  3314. * XHR Polling constructor.
  3315. *
  3316. * @param {Object} opts
  3317. * @api public
  3318. */
  3319. function XHR (opts) {
  3320. Polling.call(this, opts);
  3321. this.requestTimeout = opts.requestTimeout;
  3322. this.extraHeaders = opts.extraHeaders;
  3323. if (typeof location !== 'undefined') {
  3324. var isSSL = 'https:' === location.protocol;
  3325. var port = location.port;
  3326. // some user agents have empty `location.port`
  3327. if (!port) {
  3328. port = isSSL ? 443 : 80;
  3329. }
  3330. this.xd = (typeof location !== 'undefined' && opts.hostname !== location.hostname) ||
  3331. port !== opts.port;
  3332. this.xs = opts.secure !== isSSL;
  3333. }
  3334. }
  3335. /**
  3336. * Inherits from Polling.
  3337. */
  3338. inherit(XHR, Polling);
  3339. /**
  3340. * XHR supports binary
  3341. */
  3342. XHR.prototype.supportsBinary = true;
  3343. /**
  3344. * Creates a request.
  3345. *
  3346. * @param {String} method
  3347. * @api private
  3348. */
  3349. XHR.prototype.request = function (opts) {
  3350. opts = opts || {};
  3351. opts.uri = this.uri();
  3352. opts.xd = this.xd;
  3353. opts.xs = this.xs;
  3354. opts.agent = this.agent || false;
  3355. opts.supportsBinary = this.supportsBinary;
  3356. opts.enablesXDR = this.enablesXDR;
  3357. opts.withCredentials = this.withCredentials;
  3358. // SSL options for Node.js client
  3359. opts.pfx = this.pfx;
  3360. opts.key = this.key;
  3361. opts.passphrase = this.passphrase;
  3362. opts.cert = this.cert;
  3363. opts.ca = this.ca;
  3364. opts.ciphers = this.ciphers;
  3365. opts.rejectUnauthorized = this.rejectUnauthorized;
  3366. opts.requestTimeout = this.requestTimeout;
  3367. // other options for Node.js client
  3368. opts.extraHeaders = this.extraHeaders;
  3369. return new Request(opts);
  3370. };
  3371. /**
  3372. * Sends data.
  3373. *
  3374. * @param {String} data to send.
  3375. * @param {Function} called upon flush.
  3376. * @api private
  3377. */
  3378. XHR.prototype.doWrite = function (data, fn) {
  3379. var isBinary = typeof data !== 'string' && data !== undefined;
  3380. var req = this.request({ method: 'POST', data: data, isBinary: isBinary });
  3381. var self = this;
  3382. req.on('success', fn);
  3383. req.on('error', function (err) {
  3384. self.onError('xhr post error', err);
  3385. });
  3386. this.sendXhr = req;
  3387. };
  3388. /**
  3389. * Starts a poll cycle.
  3390. *
  3391. * @api private
  3392. */
  3393. XHR.prototype.doPoll = function () {
  3394. debug('xhr poll');
  3395. var req = this.request();
  3396. var self = this;
  3397. req.on('data', function (data) {
  3398. self.onData(data);
  3399. });
  3400. req.on('error', function (err) {
  3401. self.onError('xhr poll error', err);
  3402. });
  3403. this.pollXhr = req;
  3404. };
  3405. /**
  3406. * Request constructor
  3407. *
  3408. * @param {Object} options
  3409. * @api public
  3410. */
  3411. function Request (opts) {
  3412. this.method = opts.method || 'GET';
  3413. this.uri = opts.uri;
  3414. this.xd = !!opts.xd;
  3415. this.xs = !!opts.xs;
  3416. this.async = false !== opts.async;
  3417. this.data = undefined !== opts.data ? opts.data : null;
  3418. this.agent = opts.agent;
  3419. this.isBinary = opts.isBinary;
  3420. this.supportsBinary = opts.supportsBinary;
  3421. this.enablesXDR = opts.enablesXDR;
  3422. this.withCredentials = opts.withCredentials;
  3423. this.requestTimeout = opts.requestTimeout;
  3424. // SSL options for Node.js client
  3425. this.pfx = opts.pfx;
  3426. this.key = opts.key;
  3427. this.passphrase = opts.passphrase;
  3428. this.cert = opts.cert;
  3429. this.ca = opts.ca;
  3430. this.ciphers = opts.ciphers;
  3431. this.rejectUnauthorized = opts.rejectUnauthorized;
  3432. // other options for Node.js client
  3433. this.extraHeaders = opts.extraHeaders;
  3434. this.create();
  3435. }
  3436. /**
  3437. * Mix in `Emitter`.
  3438. */
  3439. Emitter(Request.prototype);
  3440. /**
  3441. * Creates the XHR object and sends the request.
  3442. *
  3443. * @api private
  3444. */
  3445. Request.prototype.create = function () {
  3446. var opts = { agent: this.agent, xdomain: this.xd, xscheme: this.xs, enablesXDR: this.enablesXDR };
  3447. // SSL options for Node.js client
  3448. opts.pfx = this.pfx;
  3449. opts.key = this.key;
  3450. opts.passphrase = this.passphrase;
  3451. opts.cert = this.cert;
  3452. opts.ca = this.ca;
  3453. opts.ciphers = this.ciphers;
  3454. opts.rejectUnauthorized = this.rejectUnauthorized;
  3455. var xhr = this.xhr = new XMLHttpRequest(opts);
  3456. var self = this;
  3457. try {
  3458. debug('xhr open %s: %s', this.method, this.uri);
  3459. xhr.open(this.method, this.uri, this.async);
  3460. try {
  3461. if (this.extraHeaders) {
  3462. xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
  3463. for (var i in this.extraHeaders) {
  3464. if (this.extraHeaders.hasOwnProperty(i)) {
  3465. xhr.setRequestHeader(i, this.extraHeaders[i]);
  3466. }
  3467. }
  3468. }
  3469. } catch (e) {}
  3470. if ('POST' === this.method) {
  3471. try {
  3472. if (this.isBinary) {
  3473. xhr.setRequestHeader('Content-type', 'application/octet-stream');
  3474. } else {
  3475. xhr.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
  3476. }
  3477. } catch (e) {}
  3478. }
  3479. try {
  3480. xhr.setRequestHeader('Accept', '*/*');
  3481. } catch (e) {}
  3482. // ie6 check
  3483. if ('withCredentials' in xhr) {
  3484. xhr.withCredentials = this.withCredentials;
  3485. }
  3486. if (this.requestTimeout) {
  3487. xhr.timeout = this.requestTimeout;
  3488. }
  3489. if (this.hasXDR()) {
  3490. xhr.onload = function () {
  3491. self.onLoad();
  3492. };
  3493. xhr.onerror = function () {
  3494. self.onError(xhr.responseText);
  3495. };
  3496. } else {
  3497. xhr.onreadystatechange = function () {
  3498. if (xhr.readyState === 2) {
  3499. try {
  3500. var contentType = xhr.getResponseHeader('Content-Type');
  3501. if (self.supportsBinary && contentType === 'application/octet-stream' || contentType === 'application/octet-stream; charset=UTF-8') {
  3502. xhr.responseType = 'arraybuffer';
  3503. }
  3504. } catch (e) {}
  3505. }
  3506. if (4 !== xhr.readyState) return;
  3507. if (200 === xhr.status || 1223 === xhr.status) {
  3508. self.onLoad();
  3509. } else {
  3510. // make sure the `error` event handler that's user-set
  3511. // does not throw in the same tick and gets caught here
  3512. setTimeout(function () {
  3513. self.onError(typeof xhr.status === 'number' ? xhr.status : 0);
  3514. }, 0);
  3515. }
  3516. };
  3517. }
  3518. debug('xhr data %s', this.data);
  3519. xhr.send(this.data);
  3520. } catch (e) {
  3521. // Need to defer since .create() is called directly fhrom the constructor
  3522. // and thus the 'error' event can only be only bound *after* this exception
  3523. // occurs. Therefore, also, we cannot throw here at all.
  3524. setTimeout(function () {
  3525. self.onError(e);
  3526. }, 0);
  3527. return;
  3528. }
  3529. if (typeof document !== 'undefined') {
  3530. this.index = Request.requestsCount++;
  3531. Request.requests[this.index] = this;
  3532. }
  3533. };
  3534. /**
  3535. * Called upon successful response.
  3536. *
  3537. * @api private
  3538. */
  3539. Request.prototype.onSuccess = function () {
  3540. this.emit('success');
  3541. this.cleanup();
  3542. };
  3543. /**
  3544. * Called if we have data.
  3545. *
  3546. * @api private
  3547. */
  3548. Request.prototype.onData = function (data) {
  3549. this.emit('data', data);
  3550. this.onSuccess();
  3551. };
  3552. /**
  3553. * Called upon error.
  3554. *
  3555. * @api private
  3556. */
  3557. Request.prototype.onError = function (err) {
  3558. this.emit('error', err);
  3559. this.cleanup(true);
  3560. };
  3561. /**
  3562. * Cleans up house.
  3563. *
  3564. * @api private
  3565. */
  3566. Request.prototype.cleanup = function (fromError) {
  3567. if ('undefined' === typeof this.xhr || null === this.xhr) {
  3568. return;
  3569. }
  3570. // xmlhttprequest
  3571. if (this.hasXDR()) {
  3572. this.xhr.onload = this.xhr.onerror = empty;
  3573. } else {
  3574. this.xhr.onreadystatechange = empty;
  3575. }
  3576. if (fromError) {
  3577. try {
  3578. this.xhr.abort();
  3579. } catch (e) {}
  3580. }
  3581. if (typeof document !== 'undefined') {
  3582. delete Request.requests[this.index];
  3583. }
  3584. this.xhr = null;
  3585. };
  3586. /**
  3587. * Called upon load.
  3588. *
  3589. * @api private
  3590. */
  3591. Request.prototype.onLoad = function () {
  3592. var data;
  3593. try {
  3594. var contentType;
  3595. try {
  3596. contentType = this.xhr.getResponseHeader('Content-Type');
  3597. } catch (e) {}
  3598. if (contentType === 'application/octet-stream' || contentType === 'application/octet-stream; charset=UTF-8') {
  3599. data = this.xhr.response || this.xhr.responseText;
  3600. } else {
  3601. data = this.xhr.responseText;
  3602. }
  3603. } catch (e) {
  3604. this.onError(e);
  3605. }
  3606. if (null != data) {
  3607. this.onData(data);
  3608. }
  3609. };
  3610. /**
  3611. * Check if it has XDomainRequest.
  3612. *
  3613. * @api private
  3614. */
  3615. Request.prototype.hasXDR = function () {
  3616. return typeof XDomainRequest !== 'undefined' && !this.xs && this.enablesXDR;
  3617. };
  3618. /**
  3619. * Aborts the request.
  3620. *
  3621. * @api public
  3622. */
  3623. Request.prototype.abort = function () {
  3624. this.cleanup();
  3625. };
  3626. /**
  3627. * Aborts pending requests when unloading the window. This is needed to prevent
  3628. * memory leaks (e.g. when using IE) and to ensure that no spurious error is
  3629. * emitted.
  3630. */
  3631. Request.requestsCount = 0;
  3632. Request.requests = {};
  3633. if (typeof document !== 'undefined') {
  3634. if (typeof attachEvent === 'function') {
  3635. attachEvent('onunload', unloadHandler);
  3636. } else if (typeof addEventListener === 'function') {
  3637. var terminationEvent = 'onpagehide' in self ? 'pagehide' : 'unload';
  3638. addEventListener(terminationEvent, unloadHandler, false);
  3639. }
  3640. }
  3641. function unloadHandler () {
  3642. for (var i in Request.requests) {
  3643. if (Request.requests.hasOwnProperty(i)) {
  3644. Request.requests[i].abort();
  3645. }
  3646. }
  3647. }
  3648. /***/ }),
  3649. /* 22 */
  3650. /***/ (function(module, exports, __webpack_require__) {
  3651. /**
  3652. * Module dependencies.
  3653. */
  3654. var Transport = __webpack_require__(23);
  3655. var parseqs = __webpack_require__(32);
  3656. var parser = __webpack_require__(24);
  3657. var inherit = __webpack_require__(33);
  3658. var yeast = __webpack_require__(34);
  3659. var debug = __webpack_require__(3)('engine.io-client:polling');
  3660. /**
  3661. * Module exports.
  3662. */
  3663. module.exports = Polling;
  3664. /**
  3665. * Is XHR2 supported?
  3666. */
  3667. var hasXHR2 = (function () {
  3668. var XMLHttpRequest = __webpack_require__(19);
  3669. var xhr = new XMLHttpRequest({ xdomain: false });
  3670. return null != xhr.responseType;
  3671. })();
  3672. /**
  3673. * Polling interface.
  3674. *
  3675. * @param {Object} opts
  3676. * @api private
  3677. */
  3678. function Polling (opts) {
  3679. var forceBase64 = (opts && opts.forceBase64);
  3680. if (!hasXHR2 || forceBase64) {
  3681. this.supportsBinary = false;
  3682. }
  3683. Transport.call(this, opts);
  3684. }
  3685. /**
  3686. * Inherits from Transport.
  3687. */
  3688. inherit(Polling, Transport);
  3689. /**
  3690. * Transport name.
  3691. */
  3692. Polling.prototype.name = 'polling';
  3693. /**
  3694. * Opens the socket (triggers polling). We write a PING message to determine
  3695. * when the transport is open.
  3696. *
  3697. * @api private
  3698. */
  3699. Polling.prototype.doOpen = function () {
  3700. this.poll();
  3701. };
  3702. /**
  3703. * Pauses polling.
  3704. *
  3705. * @param {Function} callback upon buffers are flushed and transport is paused
  3706. * @api private
  3707. */
  3708. Polling.prototype.pause = function (onPause) {
  3709. var self = this;
  3710. this.readyState = 'pausing';
  3711. function pause () {
  3712. debug('paused');
  3713. self.readyState = 'paused';
  3714. onPause();
  3715. }
  3716. if (this.polling || !this.writable) {
  3717. var total = 0;
  3718. if (this.polling) {
  3719. debug('we are currently polling - waiting to pause');
  3720. total++;
  3721. this.once('pollComplete', function () {
  3722. debug('pre-pause polling complete');
  3723. --total || pause();
  3724. });
  3725. }
  3726. if (!this.writable) {
  3727. debug('we are currently writing - waiting to pause');
  3728. total++;
  3729. this.once('drain', function () {
  3730. debug('pre-pause writing complete');
  3731. --total || pause();
  3732. });
  3733. }
  3734. } else {
  3735. pause();
  3736. }
  3737. };
  3738. /**
  3739. * Starts polling cycle.
  3740. *
  3741. * @api public
  3742. */
  3743. Polling.prototype.poll = function () {
  3744. debug('polling');
  3745. this.polling = true;
  3746. this.doPoll();
  3747. this.emit('poll');
  3748. };
  3749. /**
  3750. * Overloads onData to detect payloads.
  3751. *
  3752. * @api private
  3753. */
  3754. Polling.prototype.onData = function (data) {
  3755. var self = this;
  3756. debug('polling got data %s', data);
  3757. var callback = function (packet, index, total) {
  3758. // if its the first message we consider the transport open
  3759. if ('opening' === self.readyState) {
  3760. self.onOpen();
  3761. }
  3762. // if its a close packet, we close the ongoing requests
  3763. if ('close' === packet.type) {
  3764. self.onClose();
  3765. return false;
  3766. }
  3767. // otherwise bypass onData and handle the message
  3768. self.onPacket(packet);
  3769. };
  3770. // decode payload
  3771. parser.decodePayload(data, this.socket.binaryType, callback);
  3772. // if an event did not trigger closing
  3773. if ('closed' !== this.readyState) {
  3774. // if we got data we're not polling
  3775. this.polling = false;
  3776. this.emit('pollComplete');
  3777. if ('open' === this.readyState) {
  3778. this.poll();
  3779. } else {
  3780. debug('ignoring poll - transport state "%s"', this.readyState);
  3781. }
  3782. }
  3783. };
  3784. /**
  3785. * For polling, send a close packet.
  3786. *
  3787. * @api private
  3788. */
  3789. Polling.prototype.doClose = function () {
  3790. var self = this;
  3791. function close () {
  3792. debug('writing close packet');
  3793. self.write([{ type: 'close' }]);
  3794. }
  3795. if ('open' === this.readyState) {
  3796. debug('transport open - closing');
  3797. close();
  3798. } else {
  3799. // in case we're trying to close while
  3800. // handshaking is in progress (GH-164)
  3801. debug('transport not open - deferring close');
  3802. this.once('open', close);
  3803. }
  3804. };
  3805. /**
  3806. * Writes a packets payload.
  3807. *
  3808. * @param {Array} data packets
  3809. * @param {Function} drain callback
  3810. * @api private
  3811. */
  3812. Polling.prototype.write = function (packets) {
  3813. var self = this;
  3814. this.writable = false;
  3815. var callbackfn = function () {
  3816. self.writable = true;
  3817. self.emit('drain');
  3818. };
  3819. parser.encodePayload(packets, this.supportsBinary, function (data) {
  3820. self.doWrite(data, callbackfn);
  3821. });
  3822. };
  3823. /**
  3824. * Generates uri for connection.
  3825. *
  3826. * @api private
  3827. */
  3828. Polling.prototype.uri = function () {
  3829. var query = this.query || {};
  3830. var schema = this.secure ? 'https' : 'http';
  3831. var port = '';
  3832. // cache busting is forced
  3833. if (false !== this.timestampRequests) {
  3834. query[this.timestampParam] = yeast();
  3835. }
  3836. if (!this.supportsBinary && !query.sid) {
  3837. query.b64 = 1;
  3838. }
  3839. query = parseqs.encode(query);
  3840. // avoid port if default for schema
  3841. if (this.port && (('https' === schema && Number(this.port) !== 443) ||
  3842. ('http' === schema && Number(this.port) !== 80))) {
  3843. port = ':' + this.port;
  3844. }
  3845. // prepend ? to query
  3846. if (query.length) {
  3847. query = '?' + query;
  3848. }
  3849. var ipv6 = this.hostname.indexOf(':') !== -1;
  3850. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  3851. };
  3852. /***/ }),
  3853. /* 23 */
  3854. /***/ (function(module, exports, __webpack_require__) {
  3855. /**
  3856. * Module dependencies.
  3857. */
  3858. var parser = __webpack_require__(24);
  3859. var Emitter = __webpack_require__(11);
  3860. /**
  3861. * Module exports.
  3862. */
  3863. module.exports = Transport;
  3864. /**
  3865. * Transport abstract constructor.
  3866. *
  3867. * @param {Object} options.
  3868. * @api private
  3869. */
  3870. function Transport (opts) {
  3871. this.path = opts.path;
  3872. this.hostname = opts.hostname;
  3873. this.port = opts.port;
  3874. this.secure = opts.secure;
  3875. this.query = opts.query;
  3876. this.timestampParam = opts.timestampParam;
  3877. this.timestampRequests = opts.timestampRequests;
  3878. this.readyState = '';
  3879. this.agent = opts.agent || false;
  3880. this.socket = opts.socket;
  3881. this.enablesXDR = opts.enablesXDR;
  3882. this.withCredentials = opts.withCredentials;
  3883. // SSL options for Node.js client
  3884. this.pfx = opts.pfx;
  3885. this.key = opts.key;
  3886. this.passphrase = opts.passphrase;
  3887. this.cert = opts.cert;
  3888. this.ca = opts.ca;
  3889. this.ciphers = opts.ciphers;
  3890. this.rejectUnauthorized = opts.rejectUnauthorized;
  3891. this.forceNode = opts.forceNode;
  3892. // results of ReactNative environment detection
  3893. this.isReactNative = opts.isReactNative;
  3894. // other options for Node.js client
  3895. this.extraHeaders = opts.extraHeaders;
  3896. this.localAddress = opts.localAddress;
  3897. }
  3898. /**
  3899. * Mix in `Emitter`.
  3900. */
  3901. Emitter(Transport.prototype);
  3902. /**
  3903. * Emits an error.
  3904. *
  3905. * @param {String} str
  3906. * @return {Transport} for chaining
  3907. * @api public
  3908. */
  3909. Transport.prototype.onError = function (msg, desc) {
  3910. var err = new Error(msg);
  3911. err.type = 'TransportError';
  3912. err.description = desc;
  3913. this.emit('error', err);
  3914. return this;
  3915. };
  3916. /**
  3917. * Opens the transport.
  3918. *
  3919. * @api public
  3920. */
  3921. Transport.prototype.open = function () {
  3922. if ('closed' === this.readyState || '' === this.readyState) {
  3923. this.readyState = 'opening';
  3924. this.doOpen();
  3925. }
  3926. return this;
  3927. };
  3928. /**
  3929. * Closes the transport.
  3930. *
  3931. * @api private
  3932. */
  3933. Transport.prototype.close = function () {
  3934. if ('opening' === this.readyState || 'open' === this.readyState) {
  3935. this.doClose();
  3936. this.onClose();
  3937. }
  3938. return this;
  3939. };
  3940. /**
  3941. * Sends multiple packets.
  3942. *
  3943. * @param {Array} packets
  3944. * @api private
  3945. */
  3946. Transport.prototype.send = function (packets) {
  3947. if ('open' === this.readyState) {
  3948. this.write(packets);
  3949. } else {
  3950. throw new Error('Transport not open');
  3951. }
  3952. };
  3953. /**
  3954. * Called upon open
  3955. *
  3956. * @api private
  3957. */
  3958. Transport.prototype.onOpen = function () {
  3959. this.readyState = 'open';
  3960. this.writable = true;
  3961. this.emit('open');
  3962. };
  3963. /**
  3964. * Called with data.
  3965. *
  3966. * @param {String} data
  3967. * @api private
  3968. */
  3969. Transport.prototype.onData = function (data) {
  3970. var packet = parser.decodePacket(data, this.socket.binaryType);
  3971. this.onPacket(packet);
  3972. };
  3973. /**
  3974. * Called with a decoded packet.
  3975. */
  3976. Transport.prototype.onPacket = function (packet) {
  3977. this.emit('packet', packet);
  3978. };
  3979. /**
  3980. * Called upon close.
  3981. *
  3982. * @api private
  3983. */
  3984. Transport.prototype.onClose = function () {
  3985. this.readyState = 'closed';
  3986. this.emit('close');
  3987. };
  3988. /***/ }),
  3989. /* 24 */
  3990. /***/ (function(module, exports, __webpack_require__) {
  3991. /**
  3992. * Module dependencies.
  3993. */
  3994. var keys = __webpack_require__(25);
  3995. var hasBinary = __webpack_require__(26);
  3996. var sliceBuffer = __webpack_require__(27);
  3997. var after = __webpack_require__(28);
  3998. var utf8 = __webpack_require__(29);
  3999. var base64encoder;
  4000. if (typeof ArrayBuffer !== 'undefined') {
  4001. base64encoder = __webpack_require__(30);
  4002. }
  4003. /**
  4004. * Check if we are running an android browser. That requires us to use
  4005. * ArrayBuffer with polling transports...
  4006. *
  4007. * http://ghinda.net/jpeg-blob-ajax-android/
  4008. */
  4009. var isAndroid = typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
  4010. /**
  4011. * Check if we are running in PhantomJS.
  4012. * Uploading a Blob with PhantomJS does not work correctly, as reported here:
  4013. * https://github.com/ariya/phantomjs/issues/11395
  4014. * @type boolean
  4015. */
  4016. var isPhantomJS = typeof navigator !== 'undefined' && /PhantomJS/i.test(navigator.userAgent);
  4017. /**
  4018. * When true, avoids using Blobs to encode payloads.
  4019. * @type boolean
  4020. */
  4021. var dontSendBlobs = isAndroid || isPhantomJS;
  4022. /**
  4023. * Current protocol version.
  4024. */
  4025. exports.protocol = 3;
  4026. /**
  4027. * Packet types.
  4028. */
  4029. var packets = exports.packets = {
  4030. open: 0 // non-ws
  4031. , close: 1 // non-ws
  4032. , ping: 2
  4033. , pong: 3
  4034. , message: 4
  4035. , upgrade: 5
  4036. , noop: 6
  4037. };
  4038. var packetslist = keys(packets);
  4039. /**
  4040. * Premade error packet.
  4041. */
  4042. var err = { type: 'error', data: 'parser error' };
  4043. /**
  4044. * Create a blob api even for blob builder when vendor prefixes exist
  4045. */
  4046. var Blob = __webpack_require__(31);
  4047. /**
  4048. * Encodes a packet.
  4049. *
  4050. * <packet type id> [ <data> ]
  4051. *
  4052. * Example:
  4053. *
  4054. * 5hello world
  4055. * 3
  4056. * 4
  4057. *
  4058. * Binary is encoded in an identical principle
  4059. *
  4060. * @api private
  4061. */
  4062. exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) {
  4063. if (typeof supportsBinary === 'function') {
  4064. callback = supportsBinary;
  4065. supportsBinary = false;
  4066. }
  4067. if (typeof utf8encode === 'function') {
  4068. callback = utf8encode;
  4069. utf8encode = null;
  4070. }
  4071. var data = (packet.data === undefined)
  4072. ? undefined
  4073. : packet.data.buffer || packet.data;
  4074. if (typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) {
  4075. return encodeArrayBuffer(packet, supportsBinary, callback);
  4076. } else if (typeof Blob !== 'undefined' && data instanceof Blob) {
  4077. return encodeBlob(packet, supportsBinary, callback);
  4078. }
  4079. // might be an object with { base64: true, data: dataAsBase64String }
  4080. if (data && data.base64) {
  4081. return encodeBase64Object(packet, callback);
  4082. }
  4083. // Sending data as a utf-8 string
  4084. var encoded = packets[packet.type];
  4085. // data fragment is optional
  4086. if (undefined !== packet.data) {
  4087. encoded += utf8encode ? utf8.encode(String(packet.data), { strict: false }) : String(packet.data);
  4088. }
  4089. return callback('' + encoded);
  4090. };
  4091. function encodeBase64Object(packet, callback) {
  4092. // packet data is an object { base64: true, data: dataAsBase64String }
  4093. var message = 'b' + exports.packets[packet.type] + packet.data.data;
  4094. return callback(message);
  4095. }
  4096. /**
  4097. * Encode packet helpers for binary types
  4098. */
  4099. function encodeArrayBuffer(packet, supportsBinary, callback) {
  4100. if (!supportsBinary) {
  4101. return exports.encodeBase64Packet(packet, callback);
  4102. }
  4103. var data = packet.data;
  4104. var contentArray = new Uint8Array(data);
  4105. var resultBuffer = new Uint8Array(1 + data.byteLength);
  4106. resultBuffer[0] = packets[packet.type];
  4107. for (var i = 0; i < contentArray.length; i++) {
  4108. resultBuffer[i+1] = contentArray[i];
  4109. }
  4110. return callback(resultBuffer.buffer);
  4111. }
  4112. function encodeBlobAsArrayBuffer(packet, supportsBinary, callback) {
  4113. if (!supportsBinary) {
  4114. return exports.encodeBase64Packet(packet, callback);
  4115. }
  4116. var fr = new FileReader();
  4117. fr.onload = function() {
  4118. exports.encodePacket({ type: packet.type, data: fr.result }, supportsBinary, true, callback);
  4119. };
  4120. return fr.readAsArrayBuffer(packet.data);
  4121. }
  4122. function encodeBlob(packet, supportsBinary, callback) {
  4123. if (!supportsBinary) {
  4124. return exports.encodeBase64Packet(packet, callback);
  4125. }
  4126. if (dontSendBlobs) {
  4127. return encodeBlobAsArrayBuffer(packet, supportsBinary, callback);
  4128. }
  4129. var length = new Uint8Array(1);
  4130. length[0] = packets[packet.type];
  4131. var blob = new Blob([length.buffer, packet.data]);
  4132. return callback(blob);
  4133. }
  4134. /**
  4135. * Encodes a packet with binary data in a base64 string
  4136. *
  4137. * @param {Object} packet, has `type` and `data`
  4138. * @return {String} base64 encoded message
  4139. */
  4140. exports.encodeBase64Packet = function(packet, callback) {
  4141. var message = 'b' + exports.packets[packet.type];
  4142. if (typeof Blob !== 'undefined' && packet.data instanceof Blob) {
  4143. var fr = new FileReader();
  4144. fr.onload = function() {
  4145. var b64 = fr.result.split(',')[1];
  4146. callback(message + b64);
  4147. };
  4148. return fr.readAsDataURL(packet.data);
  4149. }
  4150. var b64data;
  4151. try {
  4152. b64data = String.fromCharCode.apply(null, new Uint8Array(packet.data));
  4153. } catch (e) {
  4154. // iPhone Safari doesn't let you apply with typed arrays
  4155. var typed = new Uint8Array(packet.data);
  4156. var basic = new Array(typed.length);
  4157. for (var i = 0; i < typed.length; i++) {
  4158. basic[i] = typed[i];
  4159. }
  4160. b64data = String.fromCharCode.apply(null, basic);
  4161. }
  4162. message += btoa(b64data);
  4163. return callback(message);
  4164. };
  4165. /**
  4166. * Decodes a packet. Changes format to Blob if requested.
  4167. *
  4168. * @return {Object} with `type` and `data` (if any)
  4169. * @api private
  4170. */
  4171. exports.decodePacket = function (data, binaryType, utf8decode) {
  4172. if (data === undefined) {
  4173. return err;
  4174. }
  4175. // String data
  4176. if (typeof data === 'string') {
  4177. if (data.charAt(0) === 'b') {
  4178. return exports.decodeBase64Packet(data.substr(1), binaryType);
  4179. }
  4180. if (utf8decode) {
  4181. data = tryDecode(data);
  4182. if (data === false) {
  4183. return err;
  4184. }
  4185. }
  4186. var type = data.charAt(0);
  4187. if (Number(type) != type || !packetslist[type]) {
  4188. return err;
  4189. }
  4190. if (data.length > 1) {
  4191. return { type: packetslist[type], data: data.substring(1) };
  4192. } else {
  4193. return { type: packetslist[type] };
  4194. }
  4195. }
  4196. var asArray = new Uint8Array(data);
  4197. var type = asArray[0];
  4198. var rest = sliceBuffer(data, 1);
  4199. if (Blob && binaryType === 'blob') {
  4200. rest = new Blob([rest]);
  4201. }
  4202. return { type: packetslist[type], data: rest };
  4203. };
  4204. function tryDecode(data) {
  4205. try {
  4206. data = utf8.decode(data, { strict: false });
  4207. } catch (e) {
  4208. return false;
  4209. }
  4210. return data;
  4211. }
  4212. /**
  4213. * Decodes a packet encoded in a base64 string
  4214. *
  4215. * @param {String} base64 encoded message
  4216. * @return {Object} with `type` and `data` (if any)
  4217. */
  4218. exports.decodeBase64Packet = function(msg, binaryType) {
  4219. var type = packetslist[msg.charAt(0)];
  4220. if (!base64encoder) {
  4221. return { type: type, data: { base64: true, data: msg.substr(1) } };
  4222. }
  4223. var data = base64encoder.decode(msg.substr(1));
  4224. if (binaryType === 'blob' && Blob) {
  4225. data = new Blob([data]);
  4226. }
  4227. return { type: type, data: data };
  4228. };
  4229. /**
  4230. * Encodes multiple messages (payload).
  4231. *
  4232. * <length>:data
  4233. *
  4234. * Example:
  4235. *
  4236. * 11:hello world2:hi
  4237. *
  4238. * If any contents are binary, they will be encoded as base64 strings. Base64
  4239. * encoded strings are marked with a b before the length specifier
  4240. *
  4241. * @param {Array} packets
  4242. * @api private
  4243. */
  4244. exports.encodePayload = function (packets, supportsBinary, callback) {
  4245. if (typeof supportsBinary === 'function') {
  4246. callback = supportsBinary;
  4247. supportsBinary = null;
  4248. }
  4249. var isBinary = hasBinary(packets);
  4250. if (supportsBinary && isBinary) {
  4251. if (Blob && !dontSendBlobs) {
  4252. return exports.encodePayloadAsBlob(packets, callback);
  4253. }
  4254. return exports.encodePayloadAsArrayBuffer(packets, callback);
  4255. }
  4256. if (!packets.length) {
  4257. return callback('0:');
  4258. }
  4259. function setLengthHeader(message) {
  4260. return message.length + ':' + message;
  4261. }
  4262. function encodeOne(packet, doneCallback) {
  4263. exports.encodePacket(packet, !isBinary ? false : supportsBinary, false, function(message) {
  4264. doneCallback(null, setLengthHeader(message));
  4265. });
  4266. }
  4267. map(packets, encodeOne, function(err, results) {
  4268. return callback(results.join(''));
  4269. });
  4270. };
  4271. /**
  4272. * Async array map using after
  4273. */
  4274. function map(ary, each, done) {
  4275. var result = new Array(ary.length);
  4276. var next = after(ary.length, done);
  4277. var eachWithIndex = function(i, el, cb) {
  4278. each(el, function(error, msg) {
  4279. result[i] = msg;
  4280. cb(error, result);
  4281. });
  4282. };
  4283. for (var i = 0; i < ary.length; i++) {
  4284. eachWithIndex(i, ary[i], next);
  4285. }
  4286. }
  4287. /*
  4288. * Decodes data when a payload is maybe expected. Possible binary contents are
  4289. * decoded from their base64 representation
  4290. *
  4291. * @param {String} data, callback method
  4292. * @api public
  4293. */
  4294. exports.decodePayload = function (data, binaryType, callback) {
  4295. if (typeof data !== 'string') {
  4296. return exports.decodePayloadAsBinary(data, binaryType, callback);
  4297. }
  4298. if (typeof binaryType === 'function') {
  4299. callback = binaryType;
  4300. binaryType = null;
  4301. }
  4302. var packet;
  4303. if (data === '') {
  4304. // parser error - ignoring payload
  4305. return callback(err, 0, 1);
  4306. }
  4307. var length = '', n, msg;
  4308. for (var i = 0, l = data.length; i < l; i++) {
  4309. var chr = data.charAt(i);
  4310. if (chr !== ':') {
  4311. length += chr;
  4312. continue;
  4313. }
  4314. if (length === '' || (length != (n = Number(length)))) {
  4315. // parser error - ignoring payload
  4316. return callback(err, 0, 1);
  4317. }
  4318. msg = data.substr(i + 1, n);
  4319. if (length != msg.length) {
  4320. // parser error - ignoring payload
  4321. return callback(err, 0, 1);
  4322. }
  4323. if (msg.length) {
  4324. packet = exports.decodePacket(msg, binaryType, false);
  4325. if (err.type === packet.type && err.data === packet.data) {
  4326. // parser error in individual packet - ignoring payload
  4327. return callback(err, 0, 1);
  4328. }
  4329. var ret = callback(packet, i + n, l);
  4330. if (false === ret) return;
  4331. }
  4332. // advance cursor
  4333. i += n;
  4334. length = '';
  4335. }
  4336. if (length !== '') {
  4337. // parser error - ignoring payload
  4338. return callback(err, 0, 1);
  4339. }
  4340. };
  4341. /**
  4342. * Encodes multiple messages (payload) as binary.
  4343. *
  4344. * <1 = binary, 0 = string><number from 0-9><number from 0-9>[...]<number
  4345. * 255><data>
  4346. *
  4347. * Example:
  4348. * 1 3 255 1 2 3, if the binary contents are interpreted as 8 bit integers
  4349. *
  4350. * @param {Array} packets
  4351. * @return {ArrayBuffer} encoded payload
  4352. * @api private
  4353. */
  4354. exports.encodePayloadAsArrayBuffer = function(packets, callback) {
  4355. if (!packets.length) {
  4356. return callback(new ArrayBuffer(0));
  4357. }
  4358. function encodeOne(packet, doneCallback) {
  4359. exports.encodePacket(packet, true, true, function(data) {
  4360. return doneCallback(null, data);
  4361. });
  4362. }
  4363. map(packets, encodeOne, function(err, encodedPackets) {
  4364. var totalLength = encodedPackets.reduce(function(acc, p) {
  4365. var len;
  4366. if (typeof p === 'string'){
  4367. len = p.length;
  4368. } else {
  4369. len = p.byteLength;
  4370. }
  4371. return acc + len.toString().length + len + 2; // string/binary identifier + separator = 2
  4372. }, 0);
  4373. var resultArray = new Uint8Array(totalLength);
  4374. var bufferIndex = 0;
  4375. encodedPackets.forEach(function(p) {
  4376. var isString = typeof p === 'string';
  4377. var ab = p;
  4378. if (isString) {
  4379. var view = new Uint8Array(p.length);
  4380. for (var i = 0; i < p.length; i++) {
  4381. view[i] = p.charCodeAt(i);
  4382. }
  4383. ab = view.buffer;
  4384. }
  4385. if (isString) { // not true binary
  4386. resultArray[bufferIndex++] = 0;
  4387. } else { // true binary
  4388. resultArray[bufferIndex++] = 1;
  4389. }
  4390. var lenStr = ab.byteLength.toString();
  4391. for (var i = 0; i < lenStr.length; i++) {
  4392. resultArray[bufferIndex++] = parseInt(lenStr[i]);
  4393. }
  4394. resultArray[bufferIndex++] = 255;
  4395. var view = new Uint8Array(ab);
  4396. for (var i = 0; i < view.length; i++) {
  4397. resultArray[bufferIndex++] = view[i];
  4398. }
  4399. });
  4400. return callback(resultArray.buffer);
  4401. });
  4402. };
  4403. /**
  4404. * Encode as Blob
  4405. */
  4406. exports.encodePayloadAsBlob = function(packets, callback) {
  4407. function encodeOne(packet, doneCallback) {
  4408. exports.encodePacket(packet, true, true, function(encoded) {
  4409. var binaryIdentifier = new Uint8Array(1);
  4410. binaryIdentifier[0] = 1;
  4411. if (typeof encoded === 'string') {
  4412. var view = new Uint8Array(encoded.length);
  4413. for (var i = 0; i < encoded.length; i++) {
  4414. view[i] = encoded.charCodeAt(i);
  4415. }
  4416. encoded = view.buffer;
  4417. binaryIdentifier[0] = 0;
  4418. }
  4419. var len = (encoded instanceof ArrayBuffer)
  4420. ? encoded.byteLength
  4421. : encoded.size;
  4422. var lenStr = len.toString();
  4423. var lengthAry = new Uint8Array(lenStr.length + 1);
  4424. for (var i = 0; i < lenStr.length; i++) {
  4425. lengthAry[i] = parseInt(lenStr[i]);
  4426. }
  4427. lengthAry[lenStr.length] = 255;
  4428. if (Blob) {
  4429. var blob = new Blob([binaryIdentifier.buffer, lengthAry.buffer, encoded]);
  4430. doneCallback(null, blob);
  4431. }
  4432. });
  4433. }
  4434. map(packets, encodeOne, function(err, results) {
  4435. return callback(new Blob(results));
  4436. });
  4437. };
  4438. /*
  4439. * Decodes data when a payload is maybe expected. Strings are decoded by
  4440. * interpreting each byte as a key code for entries marked to start with 0. See
  4441. * description of encodePayloadAsBinary
  4442. *
  4443. * @param {ArrayBuffer} data, callback method
  4444. * @api public
  4445. */
  4446. exports.decodePayloadAsBinary = function (data, binaryType, callback) {
  4447. if (typeof binaryType === 'function') {
  4448. callback = binaryType;
  4449. binaryType = null;
  4450. }
  4451. var bufferTail = data;
  4452. var buffers = [];
  4453. while (bufferTail.byteLength > 0) {
  4454. var tailArray = new Uint8Array(bufferTail);
  4455. var isString = tailArray[0] === 0;
  4456. var msgLength = '';
  4457. for (var i = 1; ; i++) {
  4458. if (tailArray[i] === 255) break;
  4459. // 310 = char length of Number.MAX_VALUE
  4460. if (msgLength.length > 310) {
  4461. return callback(err, 0, 1);
  4462. }
  4463. msgLength += tailArray[i];
  4464. }
  4465. bufferTail = sliceBuffer(bufferTail, 2 + msgLength.length);
  4466. msgLength = parseInt(msgLength);
  4467. var msg = sliceBuffer(bufferTail, 0, msgLength);
  4468. if (isString) {
  4469. try {
  4470. msg = String.fromCharCode.apply(null, new Uint8Array(msg));
  4471. } catch (e) {
  4472. // iPhone Safari doesn't let you apply to typed arrays
  4473. var typed = new Uint8Array(msg);
  4474. msg = '';
  4475. for (var i = 0; i < typed.length; i++) {
  4476. msg += String.fromCharCode(typed[i]);
  4477. }
  4478. }
  4479. }
  4480. buffers.push(msg);
  4481. bufferTail = sliceBuffer(bufferTail, msgLength);
  4482. }
  4483. var total = buffers.length;
  4484. buffers.forEach(function(buffer, i) {
  4485. callback(exports.decodePacket(buffer, binaryType, true), i, total);
  4486. });
  4487. };
  4488. /***/ }),
  4489. /* 25 */
  4490. /***/ (function(module, exports) {
  4491. /**
  4492. * Gets the keys for an object.
  4493. *
  4494. * @return {Array} keys
  4495. * @api private
  4496. */
  4497. module.exports = Object.keys || function keys (obj){
  4498. var arr = [];
  4499. var has = Object.prototype.hasOwnProperty;
  4500. for (var i in obj) {
  4501. if (has.call(obj, i)) {
  4502. arr.push(i);
  4503. }
  4504. }
  4505. return arr;
  4506. };
  4507. /***/ }),
  4508. /* 26 */
  4509. /***/ (function(module, exports, __webpack_require__) {
  4510. /* global Blob File */
  4511. /*
  4512. * Module requirements.
  4513. */
  4514. var isArray = __webpack_require__(13);
  4515. var toString = Object.prototype.toString;
  4516. var withNativeBlob = typeof Blob === 'function' ||
  4517. typeof Blob !== 'undefined' && toString.call(Blob) === '[object BlobConstructor]';
  4518. var withNativeFile = typeof File === 'function' ||
  4519. typeof File !== 'undefined' && toString.call(File) === '[object FileConstructor]';
  4520. /**
  4521. * Module exports.
  4522. */
  4523. module.exports = hasBinary;
  4524. /**
  4525. * Checks for binary data.
  4526. *
  4527. * Supports Buffer, ArrayBuffer, Blob and File.
  4528. *
  4529. * @param {Object} anything
  4530. * @api public
  4531. */
  4532. function hasBinary (obj) {
  4533. if (!obj || typeof obj !== 'object') {
  4534. return false;
  4535. }
  4536. if (isArray(obj)) {
  4537. for (var i = 0, l = obj.length; i < l; i++) {
  4538. if (hasBinary(obj[i])) {
  4539. return true;
  4540. }
  4541. }
  4542. return false;
  4543. }
  4544. if ((typeof Buffer === 'function' && Buffer.isBuffer && Buffer.isBuffer(obj)) ||
  4545. (typeof ArrayBuffer === 'function' && obj instanceof ArrayBuffer) ||
  4546. (withNativeBlob && obj instanceof Blob) ||
  4547. (withNativeFile && obj instanceof File)
  4548. ) {
  4549. return true;
  4550. }
  4551. // see: https://github.com/Automattic/has-binary/pull/4
  4552. if (obj.toJSON && typeof obj.toJSON === 'function' && arguments.length === 1) {
  4553. return hasBinary(obj.toJSON(), true);
  4554. }
  4555. for (var key in obj) {
  4556. if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
  4557. return true;
  4558. }
  4559. }
  4560. return false;
  4561. }
  4562. /***/ }),
  4563. /* 27 */
  4564. /***/ (function(module, exports) {
  4565. /**
  4566. * An abstraction for slicing an arraybuffer even when
  4567. * ArrayBuffer.prototype.slice is not supported
  4568. *
  4569. * @api public
  4570. */
  4571. module.exports = function(arraybuffer, start, end) {
  4572. var bytes = arraybuffer.byteLength;
  4573. start = start || 0;
  4574. end = end || bytes;
  4575. if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
  4576. if (start < 0) { start += bytes; }
  4577. if (end < 0) { end += bytes; }
  4578. if (end > bytes) { end = bytes; }
  4579. if (start >= bytes || start >= end || bytes === 0) {
  4580. return new ArrayBuffer(0);
  4581. }
  4582. var abv = new Uint8Array(arraybuffer);
  4583. var result = new Uint8Array(end - start);
  4584. for (var i = start, ii = 0; i < end; i++, ii++) {
  4585. result[ii] = abv[i];
  4586. }
  4587. return result.buffer;
  4588. };
  4589. /***/ }),
  4590. /* 28 */
  4591. /***/ (function(module, exports) {
  4592. module.exports = after
  4593. function after(count, callback, err_cb) {
  4594. var bail = false
  4595. err_cb = err_cb || noop
  4596. proxy.count = count
  4597. return (count === 0) ? callback() : proxy
  4598. function proxy(err, result) {
  4599. if (proxy.count <= 0) {
  4600. throw new Error('after called too many times')
  4601. }
  4602. --proxy.count
  4603. // after first error, rest are passed to err_cb
  4604. if (err) {
  4605. bail = true
  4606. callback(err)
  4607. // future error callbacks will go to error handler
  4608. callback = err_cb
  4609. } else if (proxy.count === 0 && !bail) {
  4610. callback(null, result)
  4611. }
  4612. }
  4613. }
  4614. function noop() {}
  4615. /***/ }),
  4616. /* 29 */
  4617. /***/ (function(module, exports) {
  4618. /*! https://mths.be/utf8js v2.1.2 by @mathias */
  4619. var stringFromCharCode = String.fromCharCode;
  4620. // Taken from https://mths.be/punycode
  4621. function ucs2decode(string) {
  4622. var output = [];
  4623. var counter = 0;
  4624. var length = string.length;
  4625. var value;
  4626. var extra;
  4627. while (counter < length) {
  4628. value = string.charCodeAt(counter++);
  4629. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  4630. // high surrogate, and there is a next character
  4631. extra = string.charCodeAt(counter++);
  4632. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  4633. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  4634. } else {
  4635. // unmatched surrogate; only append this code unit, in case the next
  4636. // code unit is the high surrogate of a surrogate pair
  4637. output.push(value);
  4638. counter--;
  4639. }
  4640. } else {
  4641. output.push(value);
  4642. }
  4643. }
  4644. return output;
  4645. }
  4646. // Taken from https://mths.be/punycode
  4647. function ucs2encode(array) {
  4648. var length = array.length;
  4649. var index = -1;
  4650. var value;
  4651. var output = '';
  4652. while (++index < length) {
  4653. value = array[index];
  4654. if (value > 0xFFFF) {
  4655. value -= 0x10000;
  4656. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  4657. value = 0xDC00 | value & 0x3FF;
  4658. }
  4659. output += stringFromCharCode(value);
  4660. }
  4661. return output;
  4662. }
  4663. function checkScalarValue(codePoint, strict) {
  4664. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  4665. if (strict) {
  4666. throw Error(
  4667. 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
  4668. ' is not a scalar value'
  4669. );
  4670. }
  4671. return false;
  4672. }
  4673. return true;
  4674. }
  4675. /*--------------------------------------------------------------------------*/
  4676. function createByte(codePoint, shift) {
  4677. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  4678. }
  4679. function encodeCodePoint(codePoint, strict) {
  4680. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  4681. return stringFromCharCode(codePoint);
  4682. }
  4683. var symbol = '';
  4684. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  4685. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  4686. }
  4687. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  4688. if (!checkScalarValue(codePoint, strict)) {
  4689. codePoint = 0xFFFD;
  4690. }
  4691. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  4692. symbol += createByte(codePoint, 6);
  4693. }
  4694. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  4695. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  4696. symbol += createByte(codePoint, 12);
  4697. symbol += createByte(codePoint, 6);
  4698. }
  4699. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  4700. return symbol;
  4701. }
  4702. function utf8encode(string, opts) {
  4703. opts = opts || {};
  4704. var strict = false !== opts.strict;
  4705. var codePoints = ucs2decode(string);
  4706. var length = codePoints.length;
  4707. var index = -1;
  4708. var codePoint;
  4709. var byteString = '';
  4710. while (++index < length) {
  4711. codePoint = codePoints[index];
  4712. byteString += encodeCodePoint(codePoint, strict);
  4713. }
  4714. return byteString;
  4715. }
  4716. /*--------------------------------------------------------------------------*/
  4717. function readContinuationByte() {
  4718. if (byteIndex >= byteCount) {
  4719. throw Error('Invalid byte index');
  4720. }
  4721. var continuationByte = byteArray[byteIndex] & 0xFF;
  4722. byteIndex++;
  4723. if ((continuationByte & 0xC0) == 0x80) {
  4724. return continuationByte & 0x3F;
  4725. }
  4726. // If we end up here, it’s not a continuation byte
  4727. throw Error('Invalid continuation byte');
  4728. }
  4729. function decodeSymbol(strict) {
  4730. var byte1;
  4731. var byte2;
  4732. var byte3;
  4733. var byte4;
  4734. var codePoint;
  4735. if (byteIndex > byteCount) {
  4736. throw Error('Invalid byte index');
  4737. }
  4738. if (byteIndex == byteCount) {
  4739. return false;
  4740. }
  4741. // Read first byte
  4742. byte1 = byteArray[byteIndex] & 0xFF;
  4743. byteIndex++;
  4744. // 1-byte sequence (no continuation bytes)
  4745. if ((byte1 & 0x80) == 0) {
  4746. return byte1;
  4747. }
  4748. // 2-byte sequence
  4749. if ((byte1 & 0xE0) == 0xC0) {
  4750. byte2 = readContinuationByte();
  4751. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  4752. if (codePoint >= 0x80) {
  4753. return codePoint;
  4754. } else {
  4755. throw Error('Invalid continuation byte');
  4756. }
  4757. }
  4758. // 3-byte sequence (may include unpaired surrogates)
  4759. if ((byte1 & 0xF0) == 0xE0) {
  4760. byte2 = readContinuationByte();
  4761. byte3 = readContinuationByte();
  4762. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  4763. if (codePoint >= 0x0800) {
  4764. return checkScalarValue(codePoint, strict) ? codePoint : 0xFFFD;
  4765. } else {
  4766. throw Error('Invalid continuation byte');
  4767. }
  4768. }
  4769. // 4-byte sequence
  4770. if ((byte1 & 0xF8) == 0xF0) {
  4771. byte2 = readContinuationByte();
  4772. byte3 = readContinuationByte();
  4773. byte4 = readContinuationByte();
  4774. codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
  4775. (byte3 << 0x06) | byte4;
  4776. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  4777. return codePoint;
  4778. }
  4779. }
  4780. throw Error('Invalid UTF-8 detected');
  4781. }
  4782. var byteArray;
  4783. var byteCount;
  4784. var byteIndex;
  4785. function utf8decode(byteString, opts) {
  4786. opts = opts || {};
  4787. var strict = false !== opts.strict;
  4788. byteArray = ucs2decode(byteString);
  4789. byteCount = byteArray.length;
  4790. byteIndex = 0;
  4791. var codePoints = [];
  4792. var tmp;
  4793. while ((tmp = decodeSymbol(strict)) !== false) {
  4794. codePoints.push(tmp);
  4795. }
  4796. return ucs2encode(codePoints);
  4797. }
  4798. module.exports = {
  4799. version: '2.1.2',
  4800. encode: utf8encode,
  4801. decode: utf8decode
  4802. };
  4803. /***/ }),
  4804. /* 30 */
  4805. /***/ (function(module, exports) {
  4806. /*
  4807. * base64-arraybuffer
  4808. * https://github.com/niklasvh/base64-arraybuffer
  4809. *
  4810. * Copyright (c) 2012 Niklas von Hertzen
  4811. * Licensed under the MIT license.
  4812. */
  4813. (function(){
  4814. "use strict";
  4815. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  4816. // Use a lookup table to find the index.
  4817. var lookup = new Uint8Array(256);
  4818. for (var i = 0; i < chars.length; i++) {
  4819. lookup[chars.charCodeAt(i)] = i;
  4820. }
  4821. exports.encode = function(arraybuffer) {
  4822. var bytes = new Uint8Array(arraybuffer),
  4823. i, len = bytes.length, base64 = "";
  4824. for (i = 0; i < len; i+=3) {
  4825. base64 += chars[bytes[i] >> 2];
  4826. base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
  4827. base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
  4828. base64 += chars[bytes[i + 2] & 63];
  4829. }
  4830. if ((len % 3) === 2) {
  4831. base64 = base64.substring(0, base64.length - 1) + "=";
  4832. } else if (len % 3 === 1) {
  4833. base64 = base64.substring(0, base64.length - 2) + "==";
  4834. }
  4835. return base64;
  4836. };
  4837. exports.decode = function(base64) {
  4838. var bufferLength = base64.length * 0.75,
  4839. len = base64.length, i, p = 0,
  4840. encoded1, encoded2, encoded3, encoded4;
  4841. if (base64[base64.length - 1] === "=") {
  4842. bufferLength--;
  4843. if (base64[base64.length - 2] === "=") {
  4844. bufferLength--;
  4845. }
  4846. }
  4847. var arraybuffer = new ArrayBuffer(bufferLength),
  4848. bytes = new Uint8Array(arraybuffer);
  4849. for (i = 0; i < len; i+=4) {
  4850. encoded1 = lookup[base64.charCodeAt(i)];
  4851. encoded2 = lookup[base64.charCodeAt(i+1)];
  4852. encoded3 = lookup[base64.charCodeAt(i+2)];
  4853. encoded4 = lookup[base64.charCodeAt(i+3)];
  4854. bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
  4855. bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
  4856. bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
  4857. }
  4858. return arraybuffer;
  4859. };
  4860. })();
  4861. /***/ }),
  4862. /* 31 */
  4863. /***/ (function(module, exports) {
  4864. /**
  4865. * Create a blob builder even when vendor prefixes exist
  4866. */
  4867. var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
  4868. typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder :
  4869. typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
  4870. typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
  4871. false;
  4872. /**
  4873. * Check if Blob constructor is supported
  4874. */
  4875. var blobSupported = (function() {
  4876. try {
  4877. var a = new Blob(['hi']);
  4878. return a.size === 2;
  4879. } catch(e) {
  4880. return false;
  4881. }
  4882. })();
  4883. /**
  4884. * Check if Blob constructor supports ArrayBufferViews
  4885. * Fails in Safari 6, so we need to map to ArrayBuffers there.
  4886. */
  4887. var blobSupportsArrayBufferView = blobSupported && (function() {
  4888. try {
  4889. var b = new Blob([new Uint8Array([1,2])]);
  4890. return b.size === 2;
  4891. } catch(e) {
  4892. return false;
  4893. }
  4894. })();
  4895. /**
  4896. * Check if BlobBuilder is supported
  4897. */
  4898. var blobBuilderSupported = BlobBuilder
  4899. && BlobBuilder.prototype.append
  4900. && BlobBuilder.prototype.getBlob;
  4901. /**
  4902. * Helper function that maps ArrayBufferViews to ArrayBuffers
  4903. * Used by BlobBuilder constructor and old browsers that didn't
  4904. * support it in the Blob constructor.
  4905. */
  4906. function mapArrayBufferViews(ary) {
  4907. return ary.map(function(chunk) {
  4908. if (chunk.buffer instanceof ArrayBuffer) {
  4909. var buf = chunk.buffer;
  4910. // if this is a subarray, make a copy so we only
  4911. // include the subarray region from the underlying buffer
  4912. if (chunk.byteLength !== buf.byteLength) {
  4913. var copy = new Uint8Array(chunk.byteLength);
  4914. copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength));
  4915. buf = copy.buffer;
  4916. }
  4917. return buf;
  4918. }
  4919. return chunk;
  4920. });
  4921. }
  4922. function BlobBuilderConstructor(ary, options) {
  4923. options = options || {};
  4924. var bb = new BlobBuilder();
  4925. mapArrayBufferViews(ary).forEach(function(part) {
  4926. bb.append(part);
  4927. });
  4928. return (options.type) ? bb.getBlob(options.type) : bb.getBlob();
  4929. };
  4930. function BlobConstructor(ary, options) {
  4931. return new Blob(mapArrayBufferViews(ary), options || {});
  4932. };
  4933. if (typeof Blob !== 'undefined') {
  4934. BlobBuilderConstructor.prototype = Blob.prototype;
  4935. BlobConstructor.prototype = Blob.prototype;
  4936. }
  4937. module.exports = (function() {
  4938. if (blobSupported) {
  4939. return blobSupportsArrayBufferView ? Blob : BlobConstructor;
  4940. } else if (blobBuilderSupported) {
  4941. return BlobBuilderConstructor;
  4942. } else {
  4943. return undefined;
  4944. }
  4945. })();
  4946. /***/ }),
  4947. /* 32 */
  4948. /***/ (function(module, exports) {
  4949. /**
  4950. * Compiles a querystring
  4951. * Returns string representation of the object
  4952. *
  4953. * @param {Object}
  4954. * @api private
  4955. */
  4956. exports.encode = function (obj) {
  4957. var str = '';
  4958. for (var i in obj) {
  4959. if (obj.hasOwnProperty(i)) {
  4960. if (str.length) str += '&';
  4961. str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
  4962. }
  4963. }
  4964. return str;
  4965. };
  4966. /**
  4967. * Parses a simple querystring into an object
  4968. *
  4969. * @param {String} qs
  4970. * @api private
  4971. */
  4972. exports.decode = function(qs){
  4973. var qry = {};
  4974. var pairs = qs.split('&');
  4975. for (var i = 0, l = pairs.length; i < l; i++) {
  4976. var pair = pairs[i].split('=');
  4977. qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  4978. }
  4979. return qry;
  4980. };
  4981. /***/ }),
  4982. /* 33 */
  4983. /***/ (function(module, exports) {
  4984. module.exports = function(a, b){
  4985. var fn = function(){};
  4986. fn.prototype = b.prototype;
  4987. a.prototype = new fn;
  4988. a.prototype.constructor = a;
  4989. };
  4990. /***/ }),
  4991. /* 34 */
  4992. /***/ (function(module, exports) {
  4993. 'use strict';
  4994. var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
  4995. , length = 64
  4996. , map = {}
  4997. , seed = 0
  4998. , i = 0
  4999. , prev;
  5000. /**
  5001. * Return a string representing the specified number.
  5002. *
  5003. * @param {Number} num The number to convert.
  5004. * @returns {String} The string representation of the number.
  5005. * @api public
  5006. */
  5007. function encode(num) {
  5008. var encoded = '';
  5009. do {
  5010. encoded = alphabet[num % length] + encoded;
  5011. num = Math.floor(num / length);
  5012. } while (num > 0);
  5013. return encoded;
  5014. }
  5015. /**
  5016. * Return the integer value specified by the given string.
  5017. *
  5018. * @param {String} str The string to convert.
  5019. * @returns {Number} The integer value represented by the string.
  5020. * @api public
  5021. */
  5022. function decode(str) {
  5023. var decoded = 0;
  5024. for (i = 0; i < str.length; i++) {
  5025. decoded = decoded * length + map[str.charAt(i)];
  5026. }
  5027. return decoded;
  5028. }
  5029. /**
  5030. * Yeast: A tiny growing id generator.
  5031. *
  5032. * @returns {String} A unique id.
  5033. * @api public
  5034. */
  5035. function yeast() {
  5036. var now = encode(+new Date());
  5037. if (now !== prev) return seed = 0, prev = now;
  5038. return now +'.'+ encode(seed++);
  5039. }
  5040. //
  5041. // Map each character to its index.
  5042. //
  5043. for (; i < length; i++) map[alphabet[i]] = i;
  5044. //
  5045. // Expose the `yeast`, `encode` and `decode` functions.
  5046. //
  5047. yeast.encode = encode;
  5048. yeast.decode = decode;
  5049. module.exports = yeast;
  5050. /***/ }),
  5051. /* 35 */
  5052. /***/ (function(module, exports, __webpack_require__) {
  5053. /* WEBPACK VAR INJECTION */(function(global) {/**
  5054. * Module requirements.
  5055. */
  5056. var Polling = __webpack_require__(22);
  5057. var inherit = __webpack_require__(33);
  5058. /**
  5059. * Module exports.
  5060. */
  5061. module.exports = JSONPPolling;
  5062. /**
  5063. * Cached regular expressions.
  5064. */
  5065. var rNewline = /\n/g;
  5066. var rEscapedNewline = /\\n/g;
  5067. /**
  5068. * Global JSONP callbacks.
  5069. */
  5070. var callbacks;
  5071. /**
  5072. * Noop.
  5073. */
  5074. function empty () { }
  5075. /**
  5076. * Until https://github.com/tc39/proposal-global is shipped.
  5077. */
  5078. function glob () {
  5079. return typeof self !== 'undefined' ? self
  5080. : typeof window !== 'undefined' ? window
  5081. : typeof global !== 'undefined' ? global : {};
  5082. }
  5083. /**
  5084. * JSONP Polling constructor.
  5085. *
  5086. * @param {Object} opts.
  5087. * @api public
  5088. */
  5089. function JSONPPolling (opts) {
  5090. Polling.call(this, opts);
  5091. this.query = this.query || {};
  5092. // define global callbacks array if not present
  5093. // we do this here (lazily) to avoid unneeded global pollution
  5094. if (!callbacks) {
  5095. // we need to consider multiple engines in the same page
  5096. var global = glob();
  5097. callbacks = global.___eio = (global.___eio || []);
  5098. }
  5099. // callback identifier
  5100. this.index = callbacks.length;
  5101. // add callback to jsonp global
  5102. var self = this;
  5103. callbacks.push(function (msg) {
  5104. self.onData(msg);
  5105. });
  5106. // append to query string
  5107. this.query.j = this.index;
  5108. // prevent spurious errors from being emitted when the window is unloaded
  5109. if (typeof addEventListener === 'function') {
  5110. addEventListener('beforeunload', function () {
  5111. if (self.script) self.script.onerror = empty;
  5112. }, false);
  5113. }
  5114. }
  5115. /**
  5116. * Inherits from Polling.
  5117. */
  5118. inherit(JSONPPolling, Polling);
  5119. /*
  5120. * JSONP only supports binary as base64 encoded strings
  5121. */
  5122. JSONPPolling.prototype.supportsBinary = false;
  5123. /**
  5124. * Closes the socket.
  5125. *
  5126. * @api private
  5127. */
  5128. JSONPPolling.prototype.doClose = function () {
  5129. if (this.script) {
  5130. this.script.parentNode.removeChild(this.script);
  5131. this.script = null;
  5132. }
  5133. if (this.form) {
  5134. this.form.parentNode.removeChild(this.form);
  5135. this.form = null;
  5136. this.iframe = null;
  5137. }
  5138. Polling.prototype.doClose.call(this);
  5139. };
  5140. /**
  5141. * Starts a poll cycle.
  5142. *
  5143. * @api private
  5144. */
  5145. JSONPPolling.prototype.doPoll = function () {
  5146. var self = this;
  5147. var script = document.createElement('script');
  5148. if (this.script) {
  5149. this.script.parentNode.removeChild(this.script);
  5150. this.script = null;
  5151. }
  5152. script.async = true;
  5153. script.src = this.uri();
  5154. script.onerror = function (e) {
  5155. self.onError('jsonp poll error', e);
  5156. };
  5157. var insertAt = document.getElementsByTagName('script')[0];
  5158. if (insertAt) {
  5159. insertAt.parentNode.insertBefore(script, insertAt);
  5160. } else {
  5161. (document.head || document.body).appendChild(script);
  5162. }
  5163. this.script = script;
  5164. var isUAgecko = 'undefined' !== typeof navigator && /gecko/i.test(navigator.userAgent);
  5165. if (isUAgecko) {
  5166. setTimeout(function () {
  5167. var iframe = document.createElement('iframe');
  5168. document.body.appendChild(iframe);
  5169. document.body.removeChild(iframe);
  5170. }, 100);
  5171. }
  5172. };
  5173. /**
  5174. * Writes with a hidden iframe.
  5175. *
  5176. * @param {String} data to send
  5177. * @param {Function} called upon flush.
  5178. * @api private
  5179. */
  5180. JSONPPolling.prototype.doWrite = function (data, fn) {
  5181. var self = this;
  5182. if (!this.form) {
  5183. var form = document.createElement('form');
  5184. var area = document.createElement('textarea');
  5185. var id = this.iframeId = 'eio_iframe_' + this.index;
  5186. var iframe;
  5187. form.className = 'socketio';
  5188. form.style.position = 'absolute';
  5189. form.style.top = '-1000px';
  5190. form.style.left = '-1000px';
  5191. form.target = id;
  5192. form.method = 'POST';
  5193. form.setAttribute('accept-charset', 'utf-8');
  5194. area.name = 'd';
  5195. form.appendChild(area);
  5196. document.body.appendChild(form);
  5197. this.form = form;
  5198. this.area = area;
  5199. }
  5200. this.form.action = this.uri();
  5201. function complete () {
  5202. initIframe();
  5203. fn();
  5204. }
  5205. function initIframe () {
  5206. if (self.iframe) {
  5207. try {
  5208. self.form.removeChild(self.iframe);
  5209. } catch (e) {
  5210. self.onError('jsonp polling iframe removal error', e);
  5211. }
  5212. }
  5213. try {
  5214. // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
  5215. var html = '<iframe src="javascript:0" name="' + self.iframeId + '">';
  5216. iframe = document.createElement(html);
  5217. } catch (e) {
  5218. iframe = document.createElement('iframe');
  5219. iframe.name = self.iframeId;
  5220. iframe.src = 'javascript:0';
  5221. }
  5222. iframe.id = self.iframeId;
  5223. self.form.appendChild(iframe);
  5224. self.iframe = iframe;
  5225. }
  5226. initIframe();
  5227. // escape \n to prevent it from being converted into \r\n by some UAs
  5228. // double escaping is required for escaped new lines because unescaping of new lines can be done safely on server-side
  5229. data = data.replace(rEscapedNewline, '\\\n');
  5230. this.area.value = data.replace(rNewline, '\\n');
  5231. try {
  5232. this.form.submit();
  5233. } catch (e) {}
  5234. if (this.iframe.attachEvent) {
  5235. this.iframe.onreadystatechange = function () {
  5236. if (self.iframe.readyState === 'complete') {
  5237. complete();
  5238. }
  5239. };
  5240. } else {
  5241. this.iframe.onload = complete;
  5242. }
  5243. };
  5244. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  5245. /***/ }),
  5246. /* 36 */
  5247. /***/ (function(module, exports, __webpack_require__) {
  5248. /**
  5249. * Module dependencies.
  5250. */
  5251. var Transport = __webpack_require__(23);
  5252. var parser = __webpack_require__(24);
  5253. var parseqs = __webpack_require__(32);
  5254. var inherit = __webpack_require__(33);
  5255. var yeast = __webpack_require__(34);
  5256. var debug = __webpack_require__(3)('engine.io-client:websocket');
  5257. var BrowserWebSocket, NodeWebSocket;
  5258. if (typeof WebSocket !== 'undefined') {
  5259. BrowserWebSocket = WebSocket;
  5260. } else if (typeof self !== 'undefined') {
  5261. BrowserWebSocket = self.WebSocket || self.MozWebSocket;
  5262. }
  5263. if (typeof window === 'undefined') {
  5264. try {
  5265. NodeWebSocket = __webpack_require__(37);
  5266. } catch (e) { }
  5267. }
  5268. /**
  5269. * Get either the `WebSocket` or `MozWebSocket` globals
  5270. * in the browser or try to resolve WebSocket-compatible
  5271. * interface exposed by `ws` for Node-like environment.
  5272. */
  5273. var WebSocketImpl = BrowserWebSocket || NodeWebSocket;
  5274. /**
  5275. * Module exports.
  5276. */
  5277. module.exports = WS;
  5278. /**
  5279. * WebSocket transport constructor.
  5280. *
  5281. * @api {Object} connection options
  5282. * @api public
  5283. */
  5284. function WS (opts) {
  5285. var forceBase64 = (opts && opts.forceBase64);
  5286. if (forceBase64) {
  5287. this.supportsBinary = false;
  5288. }
  5289. this.perMessageDeflate = opts.perMessageDeflate;
  5290. this.usingBrowserWebSocket = BrowserWebSocket && !opts.forceNode;
  5291. this.protocols = opts.protocols;
  5292. if (!this.usingBrowserWebSocket) {
  5293. WebSocketImpl = NodeWebSocket;
  5294. }
  5295. Transport.call(this, opts);
  5296. }
  5297. /**
  5298. * Inherits from Transport.
  5299. */
  5300. inherit(WS, Transport);
  5301. /**
  5302. * Transport name.
  5303. *
  5304. * @api public
  5305. */
  5306. WS.prototype.name = 'websocket';
  5307. /*
  5308. * WebSockets support binary
  5309. */
  5310. WS.prototype.supportsBinary = true;
  5311. /**
  5312. * Opens socket.
  5313. *
  5314. * @api private
  5315. */
  5316. WS.prototype.doOpen = function () {
  5317. if (!this.check()) {
  5318. // let probe timeout
  5319. return;
  5320. }
  5321. var uri = this.uri();
  5322. var protocols = this.protocols;
  5323. var opts = {
  5324. agent: this.agent,
  5325. perMessageDeflate: this.perMessageDeflate
  5326. };
  5327. // SSL options for Node.js client
  5328. opts.pfx = this.pfx;
  5329. opts.key = this.key;
  5330. opts.passphrase = this.passphrase;
  5331. opts.cert = this.cert;
  5332. opts.ca = this.ca;
  5333. opts.ciphers = this.ciphers;
  5334. opts.rejectUnauthorized = this.rejectUnauthorized;
  5335. if (this.extraHeaders) {
  5336. opts.headers = this.extraHeaders;
  5337. }
  5338. if (this.localAddress) {
  5339. opts.localAddress = this.localAddress;
  5340. }
  5341. try {
  5342. this.ws =
  5343. this.usingBrowserWebSocket && !this.isReactNative
  5344. ? protocols
  5345. ? new WebSocketImpl(uri, protocols)
  5346. : new WebSocketImpl(uri)
  5347. : new WebSocketImpl(uri, protocols, opts);
  5348. } catch (err) {
  5349. return this.emit('error', err);
  5350. }
  5351. if (this.ws.binaryType === undefined) {
  5352. this.supportsBinary = false;
  5353. }
  5354. if (this.ws.supports && this.ws.supports.binary) {
  5355. this.supportsBinary = true;
  5356. this.ws.binaryType = 'nodebuffer';
  5357. } else {
  5358. this.ws.binaryType = 'arraybuffer';
  5359. }
  5360. this.addEventListeners();
  5361. };
  5362. /**
  5363. * Adds event listeners to the socket
  5364. *
  5365. * @api private
  5366. */
  5367. WS.prototype.addEventListeners = function () {
  5368. var self = this;
  5369. this.ws.onopen = function () {
  5370. self.onOpen();
  5371. };
  5372. this.ws.onclose = function () {
  5373. self.onClose();
  5374. };
  5375. this.ws.onmessage = function (ev) {
  5376. self.onData(ev.data);
  5377. };
  5378. this.ws.onerror = function (e) {
  5379. self.onError('websocket error', e);
  5380. };
  5381. };
  5382. /**
  5383. * Writes data to socket.
  5384. *
  5385. * @param {Array} array of packets.
  5386. * @api private
  5387. */
  5388. WS.prototype.write = function (packets) {
  5389. var self = this;
  5390. this.writable = false;
  5391. // encodePacket efficient as it uses WS framing
  5392. // no need for encodePayload
  5393. var total = packets.length;
  5394. for (var i = 0, l = total; i < l; i++) {
  5395. (function (packet) {
  5396. parser.encodePacket(packet, self.supportsBinary, function (data) {
  5397. if (!self.usingBrowserWebSocket) {
  5398. // always create a new object (GH-437)
  5399. var opts = {};
  5400. if (packet.options) {
  5401. opts.compress = packet.options.compress;
  5402. }
  5403. if (self.perMessageDeflate) {
  5404. var len = 'string' === typeof data ? Buffer.byteLength(data) : data.length;
  5405. if (len < self.perMessageDeflate.threshold) {
  5406. opts.compress = false;
  5407. }
  5408. }
  5409. }
  5410. // Sometimes the websocket has already been closed but the browser didn't
  5411. // have a chance of informing us about it yet, in that case send will
  5412. // throw an error
  5413. try {
  5414. if (self.usingBrowserWebSocket) {
  5415. // TypeError is thrown when passing the second argument on Safari
  5416. self.ws.send(data);
  5417. } else {
  5418. self.ws.send(data, opts);
  5419. }
  5420. } catch (e) {
  5421. debug('websocket closed before onclose event');
  5422. }
  5423. --total || done();
  5424. });
  5425. })(packets[i]);
  5426. }
  5427. function done () {
  5428. self.emit('flush');
  5429. // fake drain
  5430. // defer to next tick to allow Socket to clear writeBuffer
  5431. setTimeout(function () {
  5432. self.writable = true;
  5433. self.emit('drain');
  5434. }, 0);
  5435. }
  5436. };
  5437. /**
  5438. * Called upon close
  5439. *
  5440. * @api private
  5441. */
  5442. WS.prototype.onClose = function () {
  5443. Transport.prototype.onClose.call(this);
  5444. };
  5445. /**
  5446. * Closes socket.
  5447. *
  5448. * @api private
  5449. */
  5450. WS.prototype.doClose = function () {
  5451. if (typeof this.ws !== 'undefined') {
  5452. this.ws.close();
  5453. }
  5454. };
  5455. /**
  5456. * Generates uri for connection.
  5457. *
  5458. * @api private
  5459. */
  5460. WS.prototype.uri = function () {
  5461. var query = this.query || {};
  5462. var schema = this.secure ? 'wss' : 'ws';
  5463. var port = '';
  5464. // avoid port if default for schema
  5465. if (this.port && (('wss' === schema && Number(this.port) !== 443) ||
  5466. ('ws' === schema && Number(this.port) !== 80))) {
  5467. port = ':' + this.port;
  5468. }
  5469. // append timestamp to URI
  5470. if (this.timestampRequests) {
  5471. query[this.timestampParam] = yeast();
  5472. }
  5473. // communicate binary support capabilities
  5474. if (!this.supportsBinary) {
  5475. query.b64 = 1;
  5476. }
  5477. query = parseqs.encode(query);
  5478. // prepend ? to query
  5479. if (query.length) {
  5480. query = '?' + query;
  5481. }
  5482. var ipv6 = this.hostname.indexOf(':') !== -1;
  5483. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  5484. };
  5485. /**
  5486. * Feature detection for WebSocket.
  5487. *
  5488. * @return {Boolean} whether this transport is available.
  5489. * @api public
  5490. */
  5491. WS.prototype.check = function () {
  5492. return !!WebSocketImpl && !('__initialize' in WebSocketImpl && this.name === WS.prototype.name);
  5493. };
  5494. /***/ }),
  5495. /* 37 */
  5496. /***/ (function(module, exports) {
  5497. /* (ignored) */
  5498. /***/ }),
  5499. /* 38 */
  5500. /***/ (function(module, exports) {
  5501. var indexOf = [].indexOf;
  5502. module.exports = function(arr, obj){
  5503. if (indexOf) return arr.indexOf(obj);
  5504. for (var i = 0; i < arr.length; ++i) {
  5505. if (arr[i] === obj) return i;
  5506. }
  5507. return -1;
  5508. };
  5509. /***/ }),
  5510. /* 39 */
  5511. /***/ (function(module, exports, __webpack_require__) {
  5512. /**
  5513. * Module dependencies.
  5514. */
  5515. var parser = __webpack_require__(7);
  5516. var Emitter = __webpack_require__(11);
  5517. var toArray = __webpack_require__(40);
  5518. var on = __webpack_require__(41);
  5519. var bind = __webpack_require__(42);
  5520. var debug = __webpack_require__(3)('socket.io-client:socket');
  5521. var parseqs = __webpack_require__(32);
  5522. var hasBin = __webpack_require__(26);
  5523. /**
  5524. * Module exports.
  5525. */
  5526. module.exports = exports = Socket;
  5527. /**
  5528. * Internal events (blacklisted).
  5529. * These events can't be emitted by the user.
  5530. *
  5531. * @api private
  5532. */
  5533. var events = {
  5534. connect: 1,
  5535. connect_error: 1,
  5536. connect_timeout: 1,
  5537. connecting: 1,
  5538. disconnect: 1,
  5539. error: 1,
  5540. reconnect: 1,
  5541. reconnect_attempt: 1,
  5542. reconnect_failed: 1,
  5543. reconnect_error: 1,
  5544. reconnecting: 1,
  5545. ping: 1,
  5546. pong: 1
  5547. };
  5548. /**
  5549. * Shortcut to `Emitter#emit`.
  5550. */
  5551. var emit = Emitter.prototype.emit;
  5552. /**
  5553. * `Socket` constructor.
  5554. *
  5555. * @api public
  5556. */
  5557. function Socket (io, nsp, opts) {
  5558. this.io = io;
  5559. this.nsp = nsp;
  5560. this.json = this; // compat
  5561. this.ids = 0;
  5562. this.acks = {};
  5563. this.receiveBuffer = [];
  5564. this.sendBuffer = [];
  5565. this.connected = false;
  5566. this.disconnected = true;
  5567. this.flags = {};
  5568. if (opts && opts.query) {
  5569. this.query = opts.query;
  5570. }
  5571. if (this.io.autoConnect) this.open();
  5572. }
  5573. /**
  5574. * Mix in `Emitter`.
  5575. */
  5576. Emitter(Socket.prototype);
  5577. /**
  5578. * Subscribe to open, close and packet events
  5579. *
  5580. * @api private
  5581. */
  5582. Socket.prototype.subEvents = function () {
  5583. if (this.subs) return;
  5584. var io = this.io;
  5585. this.subs = [
  5586. on(io, 'open', bind(this, 'onopen')),
  5587. on(io, 'packet', bind(this, 'onpacket')),
  5588. on(io, 'close', bind(this, 'onclose'))
  5589. ];
  5590. };
  5591. /**
  5592. * "Opens" the socket.
  5593. *
  5594. * @api public
  5595. */
  5596. Socket.prototype.open =
  5597. Socket.prototype.connect = function () {
  5598. if (this.connected) return this;
  5599. this.subEvents();
  5600. this.io.open(); // ensure open
  5601. if ('open' === this.io.readyState) this.onopen();
  5602. this.emit('connecting');
  5603. return this;
  5604. };
  5605. /**
  5606. * Sends a `message` event.
  5607. *
  5608. * @return {Socket} self
  5609. * @api public
  5610. */
  5611. Socket.prototype.send = function () {
  5612. var args = toArray(arguments);
  5613. args.unshift('message');
  5614. this.emit.apply(this, args);
  5615. return this;
  5616. };
  5617. /**
  5618. * Override `emit`.
  5619. * If the event is in `events`, it's emitted normally.
  5620. *
  5621. * @param {String} event name
  5622. * @return {Socket} self
  5623. * @api public
  5624. */
  5625. Socket.prototype.emit = function (ev) {
  5626. if (events.hasOwnProperty(ev)) {
  5627. emit.apply(this, arguments);
  5628. return this;
  5629. }
  5630. var args = toArray(arguments);
  5631. var packet = {
  5632. type: (this.flags.binary !== undefined ? this.flags.binary : hasBin(args)) ? parser.BINARY_EVENT : parser.EVENT,
  5633. data: args
  5634. };
  5635. packet.options = {};
  5636. packet.options.compress = !this.flags || false !== this.flags.compress;
  5637. // event ack callback
  5638. if ('function' === typeof args[args.length - 1]) {
  5639. debug('emitting packet with ack id %d', this.ids);
  5640. this.acks[this.ids] = args.pop();
  5641. packet.id = this.ids++;
  5642. }
  5643. if (this.connected) {
  5644. this.packet(packet);
  5645. } else {
  5646. this.sendBuffer.push(packet);
  5647. }
  5648. this.flags = {};
  5649. return this;
  5650. };
  5651. /**
  5652. * Sends a packet.
  5653. *
  5654. * @param {Object} packet
  5655. * @api private
  5656. */
  5657. Socket.prototype.packet = function (packet) {
  5658. packet.nsp = this.nsp;
  5659. this.io.packet(packet);
  5660. };
  5661. /**
  5662. * Called upon engine `open`.
  5663. *
  5664. * @api private
  5665. */
  5666. Socket.prototype.onopen = function () {
  5667. debug('transport is open - connecting');
  5668. // write connect packet if necessary
  5669. if ('/' !== this.nsp) {
  5670. if (this.query) {
  5671. var query = typeof this.query === 'object' ? parseqs.encode(this.query) : this.query;
  5672. debug('sending connect packet with query %s', query);
  5673. this.packet({type: parser.CONNECT, query: query});
  5674. } else {
  5675. this.packet({type: parser.CONNECT});
  5676. }
  5677. }
  5678. };
  5679. /**
  5680. * Called upon engine `close`.
  5681. *
  5682. * @param {String} reason
  5683. * @api private
  5684. */
  5685. Socket.prototype.onclose = function (reason) {
  5686. debug('close (%s)', reason);
  5687. this.connected = false;
  5688. this.disconnected = true;
  5689. delete this.id;
  5690. this.emit('disconnect', reason);
  5691. };
  5692. /**
  5693. * Called with socket packet.
  5694. *
  5695. * @param {Object} packet
  5696. * @api private
  5697. */
  5698. Socket.prototype.onpacket = function (packet) {
  5699. var sameNamespace = packet.nsp === this.nsp;
  5700. var rootNamespaceError = packet.type === parser.ERROR && packet.nsp === '/';
  5701. if (!sameNamespace && !rootNamespaceError) return;
  5702. switch (packet.type) {
  5703. case parser.CONNECT:
  5704. this.onconnect();
  5705. break;
  5706. case parser.EVENT:
  5707. this.onevent(packet);
  5708. break;
  5709. case parser.BINARY_EVENT:
  5710. this.onevent(packet);
  5711. break;
  5712. case parser.ACK:
  5713. this.onack(packet);
  5714. break;
  5715. case parser.BINARY_ACK:
  5716. this.onack(packet);
  5717. break;
  5718. case parser.DISCONNECT:
  5719. this.ondisconnect();
  5720. break;
  5721. case parser.ERROR:
  5722. this.emit('error', packet.data);
  5723. break;
  5724. }
  5725. };
  5726. /**
  5727. * Called upon a server event.
  5728. *
  5729. * @param {Object} packet
  5730. * @api private
  5731. */
  5732. Socket.prototype.onevent = function (packet) {
  5733. var args = packet.data || [];
  5734. debug('emitting event %j', args);
  5735. if (null != packet.id) {
  5736. debug('attaching ack callback to event');
  5737. args.push(this.ack(packet.id));
  5738. }
  5739. if (this.connected) {
  5740. emit.apply(this, args);
  5741. } else {
  5742. this.receiveBuffer.push(args);
  5743. }
  5744. };
  5745. /**
  5746. * Produces an ack callback to emit with an event.
  5747. *
  5748. * @api private
  5749. */
  5750. Socket.prototype.ack = function (id) {
  5751. var self = this;
  5752. var sent = false;
  5753. return function () {
  5754. // prevent double callbacks
  5755. if (sent) return;
  5756. sent = true;
  5757. var args = toArray(arguments);
  5758. debug('sending ack %j', args);
  5759. self.packet({
  5760. type: hasBin(args) ? parser.BINARY_ACK : parser.ACK,
  5761. id: id,
  5762. data: args
  5763. });
  5764. };
  5765. };
  5766. /**
  5767. * Called upon a server acknowlegement.
  5768. *
  5769. * @param {Object} packet
  5770. * @api private
  5771. */
  5772. Socket.prototype.onack = function (packet) {
  5773. var ack = this.acks[packet.id];
  5774. if ('function' === typeof ack) {
  5775. debug('calling ack %s with %j', packet.id, packet.data);
  5776. ack.apply(this, packet.data);
  5777. delete this.acks[packet.id];
  5778. } else {
  5779. debug('bad ack %s', packet.id);
  5780. }
  5781. };
  5782. /**
  5783. * Called upon server connect.
  5784. *
  5785. * @api private
  5786. */
  5787. Socket.prototype.onconnect = function () {
  5788. this.connected = true;
  5789. this.disconnected = false;
  5790. this.emit('connect');
  5791. this.emitBuffered();
  5792. };
  5793. /**
  5794. * Emit buffered events (received and emitted).
  5795. *
  5796. * @api private
  5797. */
  5798. Socket.prototype.emitBuffered = function () {
  5799. var i;
  5800. for (i = 0; i < this.receiveBuffer.length; i++) {
  5801. emit.apply(this, this.receiveBuffer[i]);
  5802. }
  5803. this.receiveBuffer = [];
  5804. for (i = 0; i < this.sendBuffer.length; i++) {
  5805. this.packet(this.sendBuffer[i]);
  5806. }
  5807. this.sendBuffer = [];
  5808. };
  5809. /**
  5810. * Called upon server disconnect.
  5811. *
  5812. * @api private
  5813. */
  5814. Socket.prototype.ondisconnect = function () {
  5815. debug('server disconnect (%s)', this.nsp);
  5816. this.destroy();
  5817. this.onclose('io server disconnect');
  5818. };
  5819. /**
  5820. * Called upon forced client/server side disconnections,
  5821. * this method ensures the manager stops tracking us and
  5822. * that reconnections don't get triggered for this.
  5823. *
  5824. * @api private.
  5825. */
  5826. Socket.prototype.destroy = function () {
  5827. if (this.subs) {
  5828. // clean subscriptions to avoid reconnections
  5829. for (var i = 0; i < this.subs.length; i++) {
  5830. this.subs[i].destroy();
  5831. }
  5832. this.subs = null;
  5833. }
  5834. this.io.destroy(this);
  5835. };
  5836. /**
  5837. * Disconnects the socket manually.
  5838. *
  5839. * @return {Socket} self
  5840. * @api public
  5841. */
  5842. Socket.prototype.close =
  5843. Socket.prototype.disconnect = function () {
  5844. if (this.connected) {
  5845. debug('performing disconnect (%s)', this.nsp);
  5846. this.packet({ type: parser.DISCONNECT });
  5847. }
  5848. // remove socket from pool
  5849. this.destroy();
  5850. if (this.connected) {
  5851. // fire events
  5852. this.onclose('io client disconnect');
  5853. }
  5854. return this;
  5855. };
  5856. /**
  5857. * Sets the compress flag.
  5858. *
  5859. * @param {Boolean} if `true`, compresses the sending data
  5860. * @return {Socket} self
  5861. * @api public
  5862. */
  5863. Socket.prototype.compress = function (compress) {
  5864. this.flags.compress = compress;
  5865. return this;
  5866. };
  5867. /**
  5868. * Sets the binary flag
  5869. *
  5870. * @param {Boolean} whether the emitted data contains binary
  5871. * @return {Socket} self
  5872. * @api public
  5873. */
  5874. Socket.prototype.binary = function (binary) {
  5875. this.flags.binary = binary;
  5876. return this;
  5877. };
  5878. /***/ }),
  5879. /* 40 */
  5880. /***/ (function(module, exports) {
  5881. module.exports = toArray
  5882. function toArray(list, index) {
  5883. var array = []
  5884. index = index || 0
  5885. for (var i = index || 0; i < list.length; i++) {
  5886. array[i - index] = list[i]
  5887. }
  5888. return array
  5889. }
  5890. /***/ }),
  5891. /* 41 */
  5892. /***/ (function(module, exports) {
  5893. /**
  5894. * Module exports.
  5895. */
  5896. module.exports = on;
  5897. /**
  5898. * Helper for subscriptions.
  5899. *
  5900. * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter`
  5901. * @param {String} event name
  5902. * @param {Function} callback
  5903. * @api public
  5904. */
  5905. function on (obj, ev, fn) {
  5906. obj.on(ev, fn);
  5907. return {
  5908. destroy: function () {
  5909. obj.removeListener(ev, fn);
  5910. }
  5911. };
  5912. }
  5913. /***/ }),
  5914. /* 42 */
  5915. /***/ (function(module, exports) {
  5916. /**
  5917. * Slice reference.
  5918. */
  5919. var slice = [].slice;
  5920. /**
  5921. * Bind `obj` to `fn`.
  5922. *
  5923. * @param {Object} obj
  5924. * @param {Function|String} fn or string
  5925. * @return {Function}
  5926. * @api public
  5927. */
  5928. module.exports = function(obj, fn){
  5929. if ('string' == typeof fn) fn = obj[fn];
  5930. if ('function' != typeof fn) throw new Error('bind() requires a function');
  5931. var args = slice.call(arguments, 2);
  5932. return function(){
  5933. return fn.apply(obj, args.concat(slice.call(arguments)));
  5934. }
  5935. };
  5936. /***/ }),
  5937. /* 43 */
  5938. /***/ (function(module, exports) {
  5939. /**
  5940. * Expose `Backoff`.
  5941. */
  5942. module.exports = Backoff;
  5943. /**
  5944. * Initialize backoff timer with `opts`.
  5945. *
  5946. * - `min` initial timeout in milliseconds [100]
  5947. * - `max` max timeout [10000]
  5948. * - `jitter` [0]
  5949. * - `factor` [2]
  5950. *
  5951. * @param {Object} opts
  5952. * @api public
  5953. */
  5954. function Backoff(opts) {
  5955. opts = opts || {};
  5956. this.ms = opts.min || 100;
  5957. this.max = opts.max || 10000;
  5958. this.factor = opts.factor || 2;
  5959. this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
  5960. this.attempts = 0;
  5961. }
  5962. /**
  5963. * Return the backoff duration.
  5964. *
  5965. * @return {Number}
  5966. * @api public
  5967. */
  5968. Backoff.prototype.duration = function(){
  5969. var ms = this.ms * Math.pow(this.factor, this.attempts++);
  5970. if (this.jitter) {
  5971. var rand = Math.random();
  5972. var deviation = Math.floor(rand * this.jitter * ms);
  5973. ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
  5974. }
  5975. return Math.min(ms, this.max) | 0;
  5976. };
  5977. /**
  5978. * Reset the number of attempts.
  5979. *
  5980. * @api public
  5981. */
  5982. Backoff.prototype.reset = function(){
  5983. this.attempts = 0;
  5984. };
  5985. /**
  5986. * Set the minimum duration
  5987. *
  5988. * @api public
  5989. */
  5990. Backoff.prototype.setMin = function(min){
  5991. this.ms = min;
  5992. };
  5993. /**
  5994. * Set the maximum duration
  5995. *
  5996. * @api public
  5997. */
  5998. Backoff.prototype.setMax = function(max){
  5999. this.max = max;
  6000. };
  6001. /**
  6002. * Set the jitter
  6003. *
  6004. * @api public
  6005. */
  6006. Backoff.prototype.setJitter = function(jitter){
  6007. this.jitter = jitter;
  6008. };
  6009. /***/ })
  6010. /******/ ])
  6011. });
  6012. ;
  6013. //# sourceMappingURL=socket.io.dev.js.map