socket.io.dev.js 153 KB

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