socket.io.dev.js 152 KB

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