socket.io.js 192 KB

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