engine.io.js 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692
  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["eio"] = factory();
  8. else
  9. root["eio"] = 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. module.exports = __webpack_require__(1);
  47. /**
  48. * Exports parser
  49. *
  50. * @api public
  51. *
  52. */
  53. module.exports.parser = __webpack_require__(8);
  54. /***/ },
  55. /* 1 */
  56. /***/ function(module, exports, __webpack_require__) {
  57. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  58. 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; };
  59. /**
  60. * Module dependencies.
  61. */
  62. var transports = __webpack_require__(2);
  63. var Emitter = __webpack_require__(18);
  64. var debug = __webpack_require__(22)('engine.io-client:socket');
  65. var index = __webpack_require__(29);
  66. var parser = __webpack_require__(8);
  67. var parseuri = __webpack_require__(30);
  68. var parseqs = __webpack_require__(19);
  69. /**
  70. * Module exports.
  71. */
  72. module.exports = Socket;
  73. /**
  74. * Socket constructor.
  75. *
  76. * @param {String|Object} uri or options
  77. * @param {Object} options
  78. * @api public
  79. */
  80. function Socket(uri, opts) {
  81. if (!(this instanceof Socket)) return new Socket(uri, opts);
  82. opts = opts || {};
  83. if (uri && 'object' === (typeof uri === 'undefined' ? 'undefined' : _typeof(uri))) {
  84. opts = uri;
  85. uri = null;
  86. }
  87. if (uri) {
  88. uri = parseuri(uri);
  89. opts.hostname = uri.host;
  90. opts.secure = uri.protocol === 'https' || uri.protocol === 'wss';
  91. opts.port = uri.port;
  92. if (uri.query) opts.query = uri.query;
  93. } else if (opts.host) {
  94. opts.hostname = parseuri(opts.host).host;
  95. }
  96. this.secure = null != opts.secure ? opts.secure : global.location && 'https:' === location.protocol;
  97. if (opts.hostname && !opts.port) {
  98. // if no port is specified manually, use the protocol default
  99. opts.port = this.secure ? '443' : '80';
  100. }
  101. this.agent = opts.agent || false;
  102. this.hostname = opts.hostname || (global.location ? location.hostname : 'localhost');
  103. this.port = opts.port || (global.location && location.port ? location.port : this.secure ? 443 : 80);
  104. this.query = opts.query || {};
  105. if ('string' === typeof this.query) this.query = parseqs.decode(this.query);
  106. this.upgrade = false !== opts.upgrade;
  107. this.path = (opts.path || '/engine.io').replace(/\/$/, '') + '/';
  108. this.forceJSONP = !!opts.forceJSONP;
  109. this.jsonp = false !== opts.jsonp;
  110. this.forceBase64 = !!opts.forceBase64;
  111. this.enablesXDR = !!opts.enablesXDR;
  112. this.timestampParam = opts.timestampParam || 't';
  113. this.timestampRequests = opts.timestampRequests;
  114. this.transports = opts.transports || ['polling', 'websocket'];
  115. this.transportOptions = opts.transportOptions || {};
  116. this.readyState = '';
  117. this.writeBuffer = [];
  118. this.prevBufferLen = 0;
  119. this.policyPort = opts.policyPort || 843;
  120. this.rememberUpgrade = opts.rememberUpgrade || false;
  121. this.binaryType = null;
  122. this.onlyBinaryUpgrades = opts.onlyBinaryUpgrades;
  123. this.perMessageDeflate = false !== opts.perMessageDeflate ? opts.perMessageDeflate || {} : false;
  124. if (true === this.perMessageDeflate) this.perMessageDeflate = {};
  125. if (this.perMessageDeflate && null == this.perMessageDeflate.threshold) {
  126. this.perMessageDeflate.threshold = 1024;
  127. }
  128. // SSL options for Node.js client
  129. this.pfx = opts.pfx || null;
  130. this.key = opts.key || null;
  131. this.passphrase = opts.passphrase || null;
  132. this.cert = opts.cert || null;
  133. this.ca = opts.ca || null;
  134. this.ciphers = opts.ciphers || null;
  135. this.rejectUnauthorized = opts.rejectUnauthorized === undefined ? true : opts.rejectUnauthorized;
  136. this.forceNode = !!opts.forceNode;
  137. // other options for Node.js client
  138. var freeGlobal = (typeof global === 'undefined' ? 'undefined' : _typeof(global)) === 'object' && global;
  139. if (freeGlobal.global === freeGlobal) {
  140. if (opts.extraHeaders && Object.keys(opts.extraHeaders).length > 0) {
  141. this.extraHeaders = opts.extraHeaders;
  142. }
  143. if (opts.localAddress) {
  144. this.localAddress = opts.localAddress;
  145. }
  146. }
  147. // set on handshake
  148. this.id = null;
  149. this.upgrades = null;
  150. this.pingInterval = null;
  151. this.pingTimeout = null;
  152. // set on heartbeat
  153. this.pingIntervalTimer = null;
  154. this.pingTimeoutTimer = null;
  155. this.open();
  156. }
  157. Socket.priorWebsocketSuccess = false;
  158. /**
  159. * Mix in `Emitter`.
  160. */
  161. Emitter(Socket.prototype);
  162. /**
  163. * Protocol version.
  164. *
  165. * @api public
  166. */
  167. Socket.protocol = parser.protocol; // this is an int
  168. /**
  169. * Expose deps for legacy compatibility
  170. * and standalone browser access.
  171. */
  172. Socket.Socket = Socket;
  173. Socket.Transport = __webpack_require__(7);
  174. Socket.transports = __webpack_require__(2);
  175. Socket.parser = __webpack_require__(8);
  176. /**
  177. * Creates transport of the given type.
  178. *
  179. * @param {String} transport name
  180. * @return {Transport}
  181. * @api private
  182. */
  183. Socket.prototype.createTransport = function (name) {
  184. debug('creating transport "%s"', name);
  185. var query = clone(this.query);
  186. // append engine.io protocol identifier
  187. query.EIO = parser.protocol;
  188. // transport name
  189. query.transport = name;
  190. // per-transport options
  191. var options = this.transportOptions[name] || {};
  192. // session id if we already have one
  193. if (this.id) query.sid = this.id;
  194. var transport = new transports[name]({
  195. query: query,
  196. socket: this,
  197. agent: options.agent || this.agent,
  198. hostname: options.hostname || this.hostname,
  199. port: options.port || this.port,
  200. secure: options.secure || this.secure,
  201. path: options.path || this.path,
  202. forceJSONP: options.forceJSONP || this.forceJSONP,
  203. jsonp: options.jsonp || this.jsonp,
  204. forceBase64: options.forceBase64 || this.forceBase64,
  205. enablesXDR: options.enablesXDR || this.enablesXDR,
  206. timestampRequests: options.timestampRequests || this.timestampRequests,
  207. timestampParam: options.timestampParam || this.timestampParam,
  208. policyPort: options.policyPort || this.policyPort,
  209. pfx: options.pfx || this.pfx,
  210. key: options.key || this.key,
  211. passphrase: options.passphrase || this.passphrase,
  212. cert: options.cert || this.cert,
  213. ca: options.ca || this.ca,
  214. ciphers: options.ciphers || this.ciphers,
  215. rejectUnauthorized: options.rejectUnauthorized || this.rejectUnauthorized,
  216. perMessageDeflate: options.perMessageDeflate || this.perMessageDeflate,
  217. extraHeaders: options.extraHeaders || this.extraHeaders,
  218. forceNode: options.forceNode || this.forceNode,
  219. localAddress: options.localAddress || this.localAddress,
  220. requestTimeout: options.requestTimeout || this.requestTimeout,
  221. protocols: options.protocols || void 0
  222. });
  223. return transport;
  224. };
  225. function clone(obj) {
  226. var o = {};
  227. for (var i in obj) {
  228. if (obj.hasOwnProperty(i)) {
  229. o[i] = obj[i];
  230. }
  231. }
  232. return o;
  233. }
  234. /**
  235. * Initializes transport to use and starts probe.
  236. *
  237. * @api private
  238. */
  239. Socket.prototype.open = function () {
  240. var transport;
  241. if (this.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf('websocket') !== -1) {
  242. transport = 'websocket';
  243. } else if (0 === this.transports.length) {
  244. // Emit error on next tick so it can be listened to
  245. var self = this;
  246. setTimeout(function () {
  247. self.emit('error', 'No transports available');
  248. }, 0);
  249. return;
  250. } else {
  251. transport = this.transports[0];
  252. }
  253. this.readyState = 'opening';
  254. // Retry with the next transport if the transport is disabled (jsonp: false)
  255. try {
  256. transport = this.createTransport(transport);
  257. } catch (e) {
  258. this.transports.shift();
  259. this.open();
  260. return;
  261. }
  262. transport.open();
  263. this.setTransport(transport);
  264. };
  265. /**
  266. * Sets the current transport. Disables the existing one (if any).
  267. *
  268. * @api private
  269. */
  270. Socket.prototype.setTransport = function (transport) {
  271. debug('setting transport %s', transport.name);
  272. var self = this;
  273. if (this.transport) {
  274. debug('clearing existing transport %s', this.transport.name);
  275. this.transport.removeAllListeners();
  276. }
  277. // set up transport
  278. this.transport = transport;
  279. // set up transport listeners
  280. transport.on('drain', function () {
  281. self.onDrain();
  282. }).on('packet', function (packet) {
  283. self.onPacket(packet);
  284. }).on('error', function (e) {
  285. self.onError(e);
  286. }).on('close', function () {
  287. self.onClose('transport close');
  288. });
  289. };
  290. /**
  291. * Probes a transport.
  292. *
  293. * @param {String} transport name
  294. * @api private
  295. */
  296. Socket.prototype.probe = function (name) {
  297. debug('probing transport "%s"', name);
  298. var transport = this.createTransport(name, { probe: 1 });
  299. var failed = false;
  300. var self = this;
  301. Socket.priorWebsocketSuccess = false;
  302. function onTransportOpen() {
  303. if (self.onlyBinaryUpgrades) {
  304. var upgradeLosesBinary = !this.supportsBinary && self.transport.supportsBinary;
  305. failed = failed || upgradeLosesBinary;
  306. }
  307. if (failed) return;
  308. debug('probe transport "%s" opened', name);
  309. transport.send([{ type: 'ping', data: 'probe' }]);
  310. transport.once('packet', function (msg) {
  311. if (failed) return;
  312. if ('pong' === msg.type && 'probe' === msg.data) {
  313. debug('probe transport "%s" pong', name);
  314. self.upgrading = true;
  315. self.emit('upgrading', transport);
  316. if (!transport) return;
  317. Socket.priorWebsocketSuccess = 'websocket' === transport.name;
  318. debug('pausing current transport "%s"', self.transport.name);
  319. self.transport.pause(function () {
  320. if (failed) return;
  321. if ('closed' === self.readyState) return;
  322. debug('changing transport and sending upgrade packet');
  323. cleanup();
  324. self.setTransport(transport);
  325. transport.send([{ type: 'upgrade' }]);
  326. self.emit('upgrade', transport);
  327. transport = null;
  328. self.upgrading = false;
  329. self.flush();
  330. });
  331. } else {
  332. debug('probe transport "%s" failed', name);
  333. var err = new Error('probe error');
  334. err.transport = transport.name;
  335. self.emit('upgradeError', err);
  336. }
  337. });
  338. }
  339. function freezeTransport() {
  340. if (failed) return;
  341. // Any callback called by transport should be ignored since now
  342. failed = true;
  343. cleanup();
  344. transport.close();
  345. transport = null;
  346. }
  347. // Handle any error that happens while probing
  348. function onerror(err) {
  349. var error = new Error('probe error: ' + err);
  350. error.transport = transport.name;
  351. freezeTransport();
  352. debug('probe transport "%s" failed because of error: %s', name, err);
  353. self.emit('upgradeError', error);
  354. }
  355. function onTransportClose() {
  356. onerror('transport closed');
  357. }
  358. // When the socket is closed while we're probing
  359. function onclose() {
  360. onerror('socket closed');
  361. }
  362. // When the socket is upgraded while we're probing
  363. function onupgrade(to) {
  364. if (transport && to.name !== transport.name) {
  365. debug('"%s" works - aborting "%s"', to.name, transport.name);
  366. freezeTransport();
  367. }
  368. }
  369. // Remove all listeners on the transport and on self
  370. function cleanup() {
  371. transport.removeListener('open', onTransportOpen);
  372. transport.removeListener('error', onerror);
  373. transport.removeListener('close', onTransportClose);
  374. self.removeListener('close', onclose);
  375. self.removeListener('upgrading', onupgrade);
  376. }
  377. transport.once('open', onTransportOpen);
  378. transport.once('error', onerror);
  379. transport.once('close', onTransportClose);
  380. this.once('close', onclose);
  381. this.once('upgrading', onupgrade);
  382. transport.open();
  383. };
  384. /**
  385. * Called when connection is deemed open.
  386. *
  387. * @api public
  388. */
  389. Socket.prototype.onOpen = function () {
  390. debug('socket open');
  391. this.readyState = 'open';
  392. Socket.priorWebsocketSuccess = 'websocket' === this.transport.name;
  393. this.emit('open');
  394. this.flush();
  395. // we check for `readyState` in case an `open`
  396. // listener already closed the socket
  397. if ('open' === this.readyState && this.upgrade && this.transport.pause) {
  398. debug('starting upgrade probes');
  399. for (var i = 0, l = this.upgrades.length; i < l; i++) {
  400. this.probe(this.upgrades[i]);
  401. }
  402. }
  403. };
  404. /**
  405. * Handles a packet.
  406. *
  407. * @api private
  408. */
  409. Socket.prototype.onPacket = function (packet) {
  410. if ('opening' === this.readyState || 'open' === this.readyState || 'closing' === this.readyState) {
  411. debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
  412. this.emit('packet', packet);
  413. // Socket is live - any packet counts
  414. this.emit('heartbeat');
  415. switch (packet.type) {
  416. case 'open':
  417. this.onHandshake(JSON.parse(packet.data));
  418. break;
  419. case 'pong':
  420. this.setPing();
  421. this.emit('pong');
  422. break;
  423. case 'error':
  424. var err = new Error('server error');
  425. err.code = packet.data;
  426. this.onError(err);
  427. break;
  428. case 'message':
  429. this.emit('data', packet.data);
  430. this.emit('message', packet.data);
  431. break;
  432. }
  433. } else {
  434. debug('packet received with socket readyState "%s"', this.readyState);
  435. }
  436. };
  437. /**
  438. * Called upon handshake completion.
  439. *
  440. * @param {Object} handshake obj
  441. * @api private
  442. */
  443. Socket.prototype.onHandshake = function (data) {
  444. this.emit('handshake', data);
  445. this.id = data.sid;
  446. this.transport.query.sid = data.sid;
  447. this.upgrades = this.filterUpgrades(data.upgrades);
  448. this.pingInterval = data.pingInterval;
  449. this.pingTimeout = data.pingTimeout;
  450. this.onOpen();
  451. // In case open handler closes socket
  452. if ('closed' === this.readyState) return;
  453. this.setPing();
  454. // Prolong liveness of socket on heartbeat
  455. this.removeListener('heartbeat', this.onHeartbeat);
  456. this.on('heartbeat', this.onHeartbeat);
  457. };
  458. /**
  459. * Resets ping timeout.
  460. *
  461. * @api private
  462. */
  463. Socket.prototype.onHeartbeat = function (timeout) {
  464. clearTimeout(this.pingTimeoutTimer);
  465. var self = this;
  466. self.pingTimeoutTimer = setTimeout(function () {
  467. if ('closed' === self.readyState) return;
  468. self.onClose('ping timeout');
  469. }, timeout || self.pingInterval + self.pingTimeout);
  470. };
  471. /**
  472. * Pings server every `this.pingInterval` and expects response
  473. * within `this.pingTimeout` or closes connection.
  474. *
  475. * @api private
  476. */
  477. Socket.prototype.setPing = function () {
  478. var self = this;
  479. clearTimeout(self.pingIntervalTimer);
  480. self.pingIntervalTimer = setTimeout(function () {
  481. debug('writing ping packet - expecting pong within %sms', self.pingTimeout);
  482. self.ping();
  483. self.onHeartbeat(self.pingTimeout);
  484. }, self.pingInterval);
  485. };
  486. /**
  487. * Sends a ping packet.
  488. *
  489. * @api private
  490. */
  491. Socket.prototype.ping = function () {
  492. var self = this;
  493. this.sendPacket('ping', function () {
  494. self.emit('ping');
  495. });
  496. };
  497. /**
  498. * Called on `drain` event
  499. *
  500. * @api private
  501. */
  502. Socket.prototype.onDrain = function () {
  503. this.writeBuffer.splice(0, this.prevBufferLen);
  504. // setting prevBufferLen = 0 is very important
  505. // for example, when upgrading, upgrade packet is sent over,
  506. // and a nonzero prevBufferLen could cause problems on `drain`
  507. this.prevBufferLen = 0;
  508. if (0 === this.writeBuffer.length) {
  509. this.emit('drain');
  510. } else {
  511. this.flush();
  512. }
  513. };
  514. /**
  515. * Flush write buffers.
  516. *
  517. * @api private
  518. */
  519. Socket.prototype.flush = function () {
  520. if ('closed' !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
  521. debug('flushing %d packets in socket', this.writeBuffer.length);
  522. this.transport.send(this.writeBuffer);
  523. // keep track of current length of writeBuffer
  524. // splice writeBuffer and callbackBuffer on `drain`
  525. this.prevBufferLen = this.writeBuffer.length;
  526. this.emit('flush');
  527. }
  528. };
  529. /**
  530. * Sends a message.
  531. *
  532. * @param {String} message.
  533. * @param {Function} callback function.
  534. * @param {Object} options.
  535. * @return {Socket} for chaining.
  536. * @api public
  537. */
  538. Socket.prototype.write = Socket.prototype.send = function (msg, options, fn) {
  539. this.sendPacket('message', msg, options, fn);
  540. return this;
  541. };
  542. /**
  543. * Sends a packet.
  544. *
  545. * @param {String} packet type.
  546. * @param {String} data.
  547. * @param {Object} options.
  548. * @param {Function} callback function.
  549. * @api private
  550. */
  551. Socket.prototype.sendPacket = function (type, data, options, fn) {
  552. if ('function' === typeof data) {
  553. fn = data;
  554. data = undefined;
  555. }
  556. if ('function' === typeof options) {
  557. fn = options;
  558. options = null;
  559. }
  560. if ('closing' === this.readyState || 'closed' === this.readyState) {
  561. return;
  562. }
  563. options = options || {};
  564. options.compress = false !== options.compress;
  565. var packet = {
  566. type: type,
  567. data: data,
  568. options: options
  569. };
  570. this.emit('packetCreate', packet);
  571. this.writeBuffer.push(packet);
  572. if (fn) this.once('flush', fn);
  573. this.flush();
  574. };
  575. /**
  576. * Closes the connection.
  577. *
  578. * @api private
  579. */
  580. Socket.prototype.close = function () {
  581. if ('opening' === this.readyState || 'open' === this.readyState) {
  582. this.readyState = 'closing';
  583. var self = this;
  584. if (this.writeBuffer.length) {
  585. this.once('drain', function () {
  586. if (this.upgrading) {
  587. waitForUpgrade();
  588. } else {
  589. close();
  590. }
  591. });
  592. } else if (this.upgrading) {
  593. waitForUpgrade();
  594. } else {
  595. close();
  596. }
  597. }
  598. function close() {
  599. self.onClose('forced close');
  600. debug('socket closing - telling transport to close');
  601. self.transport.close();
  602. }
  603. function cleanupAndClose() {
  604. self.removeListener('upgrade', cleanupAndClose);
  605. self.removeListener('upgradeError', cleanupAndClose);
  606. close();
  607. }
  608. function waitForUpgrade() {
  609. // wait for upgrade to finish since we can't send packets while pausing a transport
  610. self.once('upgrade', cleanupAndClose);
  611. self.once('upgradeError', cleanupAndClose);
  612. }
  613. return this;
  614. };
  615. /**
  616. * Called upon transport error
  617. *
  618. * @api private
  619. */
  620. Socket.prototype.onError = function (err) {
  621. debug('socket error %j', err);
  622. Socket.priorWebsocketSuccess = false;
  623. this.emit('error', err);
  624. this.onClose('transport error', err);
  625. };
  626. /**
  627. * Called upon transport close.
  628. *
  629. * @api private
  630. */
  631. Socket.prototype.onClose = function (reason, desc) {
  632. if ('opening' === this.readyState || 'open' === this.readyState || 'closing' === this.readyState) {
  633. debug('socket close with reason: "%s"', reason);
  634. var self = this;
  635. // clear timers
  636. clearTimeout(this.pingIntervalTimer);
  637. clearTimeout(this.pingTimeoutTimer);
  638. // stop event from firing again for transport
  639. this.transport.removeAllListeners('close');
  640. // ensure transport won't stay open
  641. this.transport.close();
  642. // ignore further transport communication
  643. this.transport.removeAllListeners();
  644. // set ready state
  645. this.readyState = 'closed';
  646. // clear session id
  647. this.id = null;
  648. // emit close event
  649. this.emit('close', reason, desc);
  650. // clean buffers after, so users can still
  651. // grab the buffers on `close` event
  652. self.writeBuffer = [];
  653. self.prevBufferLen = 0;
  654. }
  655. };
  656. /**
  657. * Filters upgrades, returning only those matching client transports.
  658. *
  659. * @param {Array} server upgrades
  660. * @api private
  661. *
  662. */
  663. Socket.prototype.filterUpgrades = function (upgrades) {
  664. var filteredUpgrades = [];
  665. for (var i = 0, j = upgrades.length; i < j; i++) {
  666. if (~index(this.transports, upgrades[i])) filteredUpgrades.push(upgrades[i]);
  667. }
  668. return filteredUpgrades;
  669. };
  670. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  671. /***/ },
  672. /* 2 */
  673. /***/ function(module, exports, __webpack_require__) {
  674. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  675. /**
  676. * Module dependencies
  677. */
  678. var XMLHttpRequest = __webpack_require__(3);
  679. var XHR = __webpack_require__(5);
  680. var JSONP = __webpack_require__(26);
  681. var websocket = __webpack_require__(27);
  682. /**
  683. * Export transports.
  684. */
  685. exports.polling = polling;
  686. exports.websocket = websocket;
  687. /**
  688. * Polling transport polymorphic constructor.
  689. * Decides on xhr vs jsonp based on feature detection.
  690. *
  691. * @api private
  692. */
  693. function polling(opts) {
  694. var xhr;
  695. var xd = false;
  696. var xs = false;
  697. var jsonp = false !== opts.jsonp;
  698. if (global.location) {
  699. var isSSL = 'https:' === location.protocol;
  700. var port = location.port;
  701. // some user agents have empty `location.port`
  702. if (!port) {
  703. port = isSSL ? 443 : 80;
  704. }
  705. xd = opts.hostname !== location.hostname || port !== opts.port;
  706. xs = opts.secure !== isSSL;
  707. }
  708. opts.xdomain = xd;
  709. opts.xscheme = xs;
  710. xhr = new XMLHttpRequest(opts);
  711. if ('open' in xhr && !opts.forceJSONP) {
  712. return new XHR(opts);
  713. } else {
  714. if (!jsonp) throw new Error('JSONP disabled');
  715. return new JSONP(opts);
  716. }
  717. }
  718. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  719. /***/ },
  720. /* 3 */
  721. /***/ function(module, exports, __webpack_require__) {
  722. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  723. // browser shim for xmlhttprequest module
  724. var hasCORS = __webpack_require__(4);
  725. module.exports = function (opts) {
  726. var xdomain = opts.xdomain;
  727. // scheme must be same when usign XDomainRequest
  728. // http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
  729. var xscheme = opts.xscheme;
  730. // XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default.
  731. // https://github.com/Automattic/engine.io-client/pull/217
  732. var enablesXDR = opts.enablesXDR;
  733. // XMLHttpRequest can be disabled on IE
  734. try {
  735. if ('undefined' !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
  736. return new XMLHttpRequest();
  737. }
  738. } catch (e) {}
  739. // Use XDomainRequest for IE8 if enablesXDR is true
  740. // because loading bar keeps flashing when using jsonp-polling
  741. // https://github.com/yujiosaka/socke.io-ie8-loading-example
  742. try {
  743. if ('undefined' !== typeof XDomainRequest && !xscheme && enablesXDR) {
  744. return new XDomainRequest();
  745. }
  746. } catch (e) {}
  747. if (!xdomain) {
  748. try {
  749. return new global[['Active'].concat('Object').join('X')]('Microsoft.XMLHTTP');
  750. } catch (e) {}
  751. }
  752. };
  753. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  754. /***/ },
  755. /* 4 */
  756. /***/ function(module, exports) {
  757. /**
  758. * Module exports.
  759. *
  760. * Logic borrowed from Modernizr:
  761. *
  762. * - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
  763. */
  764. try {
  765. module.exports = typeof XMLHttpRequest !== 'undefined' &&
  766. 'withCredentials' in new XMLHttpRequest();
  767. } catch (err) {
  768. // if XMLHttp support is disabled in IE then it will throw
  769. // when trying to create
  770. module.exports = false;
  771. }
  772. /***/ },
  773. /* 5 */
  774. /***/ function(module, exports, __webpack_require__) {
  775. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  776. /**
  777. * Module requirements.
  778. */
  779. var XMLHttpRequest = __webpack_require__(3);
  780. var Polling = __webpack_require__(6);
  781. var Emitter = __webpack_require__(18);
  782. var inherit = __webpack_require__(20);
  783. var debug = __webpack_require__(22)('engine.io-client:polling-xhr');
  784. /**
  785. * Module exports.
  786. */
  787. module.exports = XHR;
  788. module.exports.Request = Request;
  789. /**
  790. * Empty function
  791. */
  792. function empty() {}
  793. /**
  794. * XHR Polling constructor.
  795. *
  796. * @param {Object} opts
  797. * @api public
  798. */
  799. function XHR(opts) {
  800. Polling.call(this, opts);
  801. this.requestTimeout = opts.requestTimeout;
  802. this.extraHeaders = opts.extraHeaders;
  803. if (global.location) {
  804. var isSSL = 'https:' === location.protocol;
  805. var port = location.port;
  806. // some user agents have empty `location.port`
  807. if (!port) {
  808. port = isSSL ? 443 : 80;
  809. }
  810. this.xd = opts.hostname !== global.location.hostname || port !== opts.port;
  811. this.xs = opts.secure !== isSSL;
  812. }
  813. }
  814. /**
  815. * Inherits from Polling.
  816. */
  817. inherit(XHR, Polling);
  818. /**
  819. * XHR supports binary
  820. */
  821. XHR.prototype.supportsBinary = true;
  822. /**
  823. * Creates a request.
  824. *
  825. * @param {String} method
  826. * @api private
  827. */
  828. XHR.prototype.request = function (opts) {
  829. opts = opts || {};
  830. opts.uri = this.uri();
  831. opts.xd = this.xd;
  832. opts.xs = this.xs;
  833. opts.agent = this.agent || false;
  834. opts.supportsBinary = this.supportsBinary;
  835. opts.enablesXDR = this.enablesXDR;
  836. // SSL options for Node.js client
  837. opts.pfx = this.pfx;
  838. opts.key = this.key;
  839. opts.passphrase = this.passphrase;
  840. opts.cert = this.cert;
  841. opts.ca = this.ca;
  842. opts.ciphers = this.ciphers;
  843. opts.rejectUnauthorized = this.rejectUnauthorized;
  844. opts.requestTimeout = this.requestTimeout;
  845. // other options for Node.js client
  846. opts.extraHeaders = this.extraHeaders;
  847. return new Request(opts);
  848. };
  849. /**
  850. * Sends data.
  851. *
  852. * @param {String} data to send.
  853. * @param {Function} called upon flush.
  854. * @api private
  855. */
  856. XHR.prototype.doWrite = function (data, fn) {
  857. var isBinary = typeof data !== 'string' && data !== undefined;
  858. var req = this.request({ method: 'POST', data: data, isBinary: isBinary });
  859. var self = this;
  860. req.on('success', fn);
  861. req.on('error', function (err) {
  862. self.onError('xhr post error', err);
  863. });
  864. this.sendXhr = req;
  865. };
  866. /**
  867. * Starts a poll cycle.
  868. *
  869. * @api private
  870. */
  871. XHR.prototype.doPoll = function () {
  872. debug('xhr poll');
  873. var req = this.request();
  874. var self = this;
  875. req.on('data', function (data) {
  876. self.onData(data);
  877. });
  878. req.on('error', function (err) {
  879. self.onError('xhr poll error', err);
  880. });
  881. this.pollXhr = req;
  882. };
  883. /**
  884. * Request constructor
  885. *
  886. * @param {Object} options
  887. * @api public
  888. */
  889. function Request(opts) {
  890. this.method = opts.method || 'GET';
  891. this.uri = opts.uri;
  892. this.xd = !!opts.xd;
  893. this.xs = !!opts.xs;
  894. this.async = false !== opts.async;
  895. this.data = undefined !== opts.data ? opts.data : null;
  896. this.agent = opts.agent;
  897. this.isBinary = opts.isBinary;
  898. this.supportsBinary = opts.supportsBinary;
  899. this.enablesXDR = opts.enablesXDR;
  900. this.requestTimeout = opts.requestTimeout;
  901. // SSL options for Node.js client
  902. this.pfx = opts.pfx;
  903. this.key = opts.key;
  904. this.passphrase = opts.passphrase;
  905. this.cert = opts.cert;
  906. this.ca = opts.ca;
  907. this.ciphers = opts.ciphers;
  908. this.rejectUnauthorized = opts.rejectUnauthorized;
  909. // other options for Node.js client
  910. this.extraHeaders = opts.extraHeaders;
  911. this.create();
  912. }
  913. /**
  914. * Mix in `Emitter`.
  915. */
  916. Emitter(Request.prototype);
  917. /**
  918. * Creates the XHR object and sends the request.
  919. *
  920. * @api private
  921. */
  922. Request.prototype.create = function () {
  923. var opts = { agent: this.agent, xdomain: this.xd, xscheme: this.xs, enablesXDR: this.enablesXDR };
  924. // SSL options for Node.js client
  925. opts.pfx = this.pfx;
  926. opts.key = this.key;
  927. opts.passphrase = this.passphrase;
  928. opts.cert = this.cert;
  929. opts.ca = this.ca;
  930. opts.ciphers = this.ciphers;
  931. opts.rejectUnauthorized = this.rejectUnauthorized;
  932. var xhr = this.xhr = new XMLHttpRequest(opts);
  933. var self = this;
  934. try {
  935. debug('xhr open %s: %s', this.method, this.uri);
  936. xhr.open(this.method, this.uri, this.async);
  937. try {
  938. if (this.extraHeaders) {
  939. xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
  940. for (var i in this.extraHeaders) {
  941. if (this.extraHeaders.hasOwnProperty(i)) {
  942. xhr.setRequestHeader(i, this.extraHeaders[i]);
  943. }
  944. }
  945. }
  946. } catch (e) {}
  947. if ('POST' === this.method) {
  948. try {
  949. if (this.isBinary) {
  950. xhr.setRequestHeader('Content-type', 'application/octet-stream');
  951. } else {
  952. xhr.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
  953. }
  954. } catch (e) {}
  955. }
  956. try {
  957. xhr.setRequestHeader('Accept', '*/*');
  958. } catch (e) {}
  959. // ie6 check
  960. if ('withCredentials' in xhr) {
  961. xhr.withCredentials = true;
  962. }
  963. if (this.requestTimeout) {
  964. xhr.timeout = this.requestTimeout;
  965. }
  966. if (this.hasXDR()) {
  967. xhr.onload = function () {
  968. self.onLoad();
  969. };
  970. xhr.onerror = function () {
  971. self.onError(xhr.responseText);
  972. };
  973. } else {
  974. xhr.onreadystatechange = function () {
  975. if (xhr.readyState === 2) {
  976. try {
  977. var contentType = xhr.getResponseHeader('Content-Type');
  978. if (self.supportsBinary && contentType === 'application/octet-stream') {
  979. xhr.responseType = 'arraybuffer';
  980. }
  981. } catch (e) {}
  982. }
  983. if (4 !== xhr.readyState) return;
  984. if (200 === xhr.status || 1223 === xhr.status) {
  985. self.onLoad();
  986. } else {
  987. // make sure the `error` event handler that's user-set
  988. // does not throw in the same tick and gets caught here
  989. setTimeout(function () {
  990. self.onError(xhr.status);
  991. }, 0);
  992. }
  993. };
  994. }
  995. debug('xhr data %s', this.data);
  996. xhr.send(this.data);
  997. } catch (e) {
  998. // Need to defer since .create() is called directly fhrom the constructor
  999. // and thus the 'error' event can only be only bound *after* this exception
  1000. // occurs. Therefore, also, we cannot throw here at all.
  1001. setTimeout(function () {
  1002. self.onError(e);
  1003. }, 0);
  1004. return;
  1005. }
  1006. if (global.document) {
  1007. this.index = Request.requestsCount++;
  1008. Request.requests[this.index] = this;
  1009. }
  1010. };
  1011. /**
  1012. * Called upon successful response.
  1013. *
  1014. * @api private
  1015. */
  1016. Request.prototype.onSuccess = function () {
  1017. this.emit('success');
  1018. this.cleanup();
  1019. };
  1020. /**
  1021. * Called if we have data.
  1022. *
  1023. * @api private
  1024. */
  1025. Request.prototype.onData = function (data) {
  1026. this.emit('data', data);
  1027. this.onSuccess();
  1028. };
  1029. /**
  1030. * Called upon error.
  1031. *
  1032. * @api private
  1033. */
  1034. Request.prototype.onError = function (err) {
  1035. this.emit('error', err);
  1036. this.cleanup(true);
  1037. };
  1038. /**
  1039. * Cleans up house.
  1040. *
  1041. * @api private
  1042. */
  1043. Request.prototype.cleanup = function (fromError) {
  1044. if ('undefined' === typeof this.xhr || null === this.xhr) {
  1045. return;
  1046. }
  1047. // xmlhttprequest
  1048. if (this.hasXDR()) {
  1049. this.xhr.onload = this.xhr.onerror = empty;
  1050. } else {
  1051. this.xhr.onreadystatechange = empty;
  1052. }
  1053. if (fromError) {
  1054. try {
  1055. this.xhr.abort();
  1056. } catch (e) {}
  1057. }
  1058. if (global.document) {
  1059. delete Request.requests[this.index];
  1060. }
  1061. this.xhr = null;
  1062. };
  1063. /**
  1064. * Called upon load.
  1065. *
  1066. * @api private
  1067. */
  1068. Request.prototype.onLoad = function () {
  1069. var data;
  1070. try {
  1071. var contentType;
  1072. try {
  1073. contentType = this.xhr.getResponseHeader('Content-Type');
  1074. } catch (e) {}
  1075. if (contentType === 'application/octet-stream') {
  1076. data = this.xhr.response || this.xhr.responseText;
  1077. } else {
  1078. data = this.xhr.responseText;
  1079. }
  1080. } catch (e) {
  1081. this.onError(e);
  1082. }
  1083. if (null != data) {
  1084. this.onData(data);
  1085. }
  1086. };
  1087. /**
  1088. * Check if it has XDomainRequest.
  1089. *
  1090. * @api private
  1091. */
  1092. Request.prototype.hasXDR = function () {
  1093. return 'undefined' !== typeof global.XDomainRequest && !this.xs && this.enablesXDR;
  1094. };
  1095. /**
  1096. * Aborts the request.
  1097. *
  1098. * @api public
  1099. */
  1100. Request.prototype.abort = function () {
  1101. this.cleanup();
  1102. };
  1103. /**
  1104. * Aborts pending requests when unloading the window. This is needed to prevent
  1105. * memory leaks (e.g. when using IE) and to ensure that no spurious error is
  1106. * emitted.
  1107. */
  1108. Request.requestsCount = 0;
  1109. Request.requests = {};
  1110. if (global.document) {
  1111. if (global.attachEvent) {
  1112. global.attachEvent('onunload', unloadHandler);
  1113. } else if (global.addEventListener) {
  1114. global.addEventListener('beforeunload', unloadHandler, false);
  1115. }
  1116. }
  1117. function unloadHandler() {
  1118. for (var i in Request.requests) {
  1119. if (Request.requests.hasOwnProperty(i)) {
  1120. Request.requests[i].abort();
  1121. }
  1122. }
  1123. }
  1124. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  1125. /***/ },
  1126. /* 6 */
  1127. /***/ function(module, exports, __webpack_require__) {
  1128. 'use strict';
  1129. /**
  1130. * Module dependencies.
  1131. */
  1132. var Transport = __webpack_require__(7);
  1133. var parseqs = __webpack_require__(19);
  1134. var parser = __webpack_require__(8);
  1135. var inherit = __webpack_require__(20);
  1136. var yeast = __webpack_require__(21);
  1137. var debug = __webpack_require__(22)('engine.io-client:polling');
  1138. /**
  1139. * Module exports.
  1140. */
  1141. module.exports = Polling;
  1142. /**
  1143. * Is XHR2 supported?
  1144. */
  1145. var hasXHR2 = function () {
  1146. var XMLHttpRequest = __webpack_require__(3);
  1147. var xhr = new XMLHttpRequest({ xdomain: false });
  1148. return null != xhr.responseType;
  1149. }();
  1150. /**
  1151. * Polling interface.
  1152. *
  1153. * @param {Object} opts
  1154. * @api private
  1155. */
  1156. function Polling(opts) {
  1157. var forceBase64 = opts && opts.forceBase64;
  1158. if (!hasXHR2 || forceBase64) {
  1159. this.supportsBinary = false;
  1160. }
  1161. Transport.call(this, opts);
  1162. }
  1163. /**
  1164. * Inherits from Transport.
  1165. */
  1166. inherit(Polling, Transport);
  1167. /**
  1168. * Transport name.
  1169. */
  1170. Polling.prototype.name = 'polling';
  1171. /**
  1172. * Opens the socket (triggers polling). We write a PING message to determine
  1173. * when the transport is open.
  1174. *
  1175. * @api private
  1176. */
  1177. Polling.prototype.doOpen = function () {
  1178. this.poll();
  1179. };
  1180. /**
  1181. * Pauses polling.
  1182. *
  1183. * @param {Function} callback upon buffers are flushed and transport is paused
  1184. * @api private
  1185. */
  1186. Polling.prototype.pause = function (onPause) {
  1187. var self = this;
  1188. this.readyState = 'pausing';
  1189. function pause() {
  1190. debug('paused');
  1191. self.readyState = 'paused';
  1192. onPause();
  1193. }
  1194. if (this.polling || !this.writable) {
  1195. var total = 0;
  1196. if (this.polling) {
  1197. debug('we are currently polling - waiting to pause');
  1198. total++;
  1199. this.once('pollComplete', function () {
  1200. debug('pre-pause polling complete');
  1201. --total || pause();
  1202. });
  1203. }
  1204. if (!this.writable) {
  1205. debug('we are currently writing - waiting to pause');
  1206. total++;
  1207. this.once('drain', function () {
  1208. debug('pre-pause writing complete');
  1209. --total || pause();
  1210. });
  1211. }
  1212. } else {
  1213. pause();
  1214. }
  1215. };
  1216. /**
  1217. * Starts polling cycle.
  1218. *
  1219. * @api public
  1220. */
  1221. Polling.prototype.poll = function () {
  1222. debug('polling');
  1223. this.polling = true;
  1224. this.doPoll();
  1225. this.emit('poll');
  1226. };
  1227. /**
  1228. * Overloads onData to detect payloads.
  1229. *
  1230. * @api private
  1231. */
  1232. Polling.prototype.onData = function (data) {
  1233. var self = this;
  1234. debug('polling got data %s', data);
  1235. var callback = function callback(packet, index, total) {
  1236. // if its the first message we consider the transport open
  1237. if ('opening' === self.readyState) {
  1238. self.onOpen();
  1239. }
  1240. // if its a close packet, we close the ongoing requests
  1241. if ('close' === packet.type) {
  1242. self.onClose();
  1243. return false;
  1244. }
  1245. // otherwise bypass onData and handle the message
  1246. self.onPacket(packet);
  1247. };
  1248. // decode payload
  1249. parser.decodePayload(data, this.socket.binaryType, callback);
  1250. // if an event did not trigger closing
  1251. if ('closed' !== this.readyState) {
  1252. // if we got data we're not polling
  1253. this.polling = false;
  1254. this.emit('pollComplete');
  1255. if ('open' === this.readyState) {
  1256. this.poll();
  1257. } else {
  1258. debug('ignoring poll - transport state "%s"', this.readyState);
  1259. }
  1260. }
  1261. };
  1262. /**
  1263. * For polling, send a close packet.
  1264. *
  1265. * @api private
  1266. */
  1267. Polling.prototype.doClose = function () {
  1268. var self = this;
  1269. function close() {
  1270. debug('writing close packet');
  1271. self.write([{ type: 'close' }]);
  1272. }
  1273. if ('open' === this.readyState) {
  1274. debug('transport open - closing');
  1275. close();
  1276. } else {
  1277. // in case we're trying to close while
  1278. // handshaking is in progress (GH-164)
  1279. debug('transport not open - deferring close');
  1280. this.once('open', close);
  1281. }
  1282. };
  1283. /**
  1284. * Writes a packets payload.
  1285. *
  1286. * @param {Array} data packets
  1287. * @param {Function} drain callback
  1288. * @api private
  1289. */
  1290. Polling.prototype.write = function (packets) {
  1291. var self = this;
  1292. this.writable = false;
  1293. var callbackfn = function callbackfn() {
  1294. self.writable = true;
  1295. self.emit('drain');
  1296. };
  1297. parser.encodePayload(packets, this.supportsBinary, function (data) {
  1298. self.doWrite(data, callbackfn);
  1299. });
  1300. };
  1301. /**
  1302. * Generates uri for connection.
  1303. *
  1304. * @api private
  1305. */
  1306. Polling.prototype.uri = function () {
  1307. var query = this.query || {};
  1308. var schema = this.secure ? 'https' : 'http';
  1309. var port = '';
  1310. // cache busting is forced
  1311. if (false !== this.timestampRequests) {
  1312. query[this.timestampParam] = yeast();
  1313. }
  1314. if (!this.supportsBinary && !query.sid) {
  1315. query.b64 = 1;
  1316. }
  1317. query = parseqs.encode(query);
  1318. // avoid port if default for schema
  1319. if (this.port && ('https' === schema && Number(this.port) !== 443 || 'http' === schema && Number(this.port) !== 80)) {
  1320. port = ':' + this.port;
  1321. }
  1322. // prepend ? to query
  1323. if (query.length) {
  1324. query = '?' + query;
  1325. }
  1326. var ipv6 = this.hostname.indexOf(':') !== -1;
  1327. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  1328. };
  1329. /***/ },
  1330. /* 7 */
  1331. /***/ function(module, exports, __webpack_require__) {
  1332. 'use strict';
  1333. /**
  1334. * Module dependencies.
  1335. */
  1336. var parser = __webpack_require__(8);
  1337. var Emitter = __webpack_require__(18);
  1338. /**
  1339. * Module exports.
  1340. */
  1341. module.exports = Transport;
  1342. /**
  1343. * Transport abstract constructor.
  1344. *
  1345. * @param {Object} options.
  1346. * @api private
  1347. */
  1348. function Transport(opts) {
  1349. this.path = opts.path;
  1350. this.hostname = opts.hostname;
  1351. this.port = opts.port;
  1352. this.secure = opts.secure;
  1353. this.query = opts.query;
  1354. this.timestampParam = opts.timestampParam;
  1355. this.timestampRequests = opts.timestampRequests;
  1356. this.readyState = '';
  1357. this.agent = opts.agent || false;
  1358. this.socket = opts.socket;
  1359. this.enablesXDR = opts.enablesXDR;
  1360. // SSL options for Node.js client
  1361. this.pfx = opts.pfx;
  1362. this.key = opts.key;
  1363. this.passphrase = opts.passphrase;
  1364. this.cert = opts.cert;
  1365. this.ca = opts.ca;
  1366. this.ciphers = opts.ciphers;
  1367. this.rejectUnauthorized = opts.rejectUnauthorized;
  1368. this.forceNode = opts.forceNode;
  1369. // other options for Node.js client
  1370. this.extraHeaders = opts.extraHeaders;
  1371. this.localAddress = opts.localAddress;
  1372. }
  1373. /**
  1374. * Mix in `Emitter`.
  1375. */
  1376. Emitter(Transport.prototype);
  1377. /**
  1378. * Emits an error.
  1379. *
  1380. * @param {String} str
  1381. * @return {Transport} for chaining
  1382. * @api public
  1383. */
  1384. Transport.prototype.onError = function (msg, desc) {
  1385. var err = new Error(msg);
  1386. err.type = 'TransportError';
  1387. err.description = desc;
  1388. this.emit('error', err);
  1389. return this;
  1390. };
  1391. /**
  1392. * Opens the transport.
  1393. *
  1394. * @api public
  1395. */
  1396. Transport.prototype.open = function () {
  1397. if ('closed' === this.readyState || '' === this.readyState) {
  1398. this.readyState = 'opening';
  1399. this.doOpen();
  1400. }
  1401. return this;
  1402. };
  1403. /**
  1404. * Closes the transport.
  1405. *
  1406. * @api private
  1407. */
  1408. Transport.prototype.close = function () {
  1409. if ('opening' === this.readyState || 'open' === this.readyState) {
  1410. this.doClose();
  1411. this.onClose();
  1412. }
  1413. return this;
  1414. };
  1415. /**
  1416. * Sends multiple packets.
  1417. *
  1418. * @param {Array} packets
  1419. * @api private
  1420. */
  1421. Transport.prototype.send = function (packets) {
  1422. if ('open' === this.readyState) {
  1423. this.write(packets);
  1424. } else {
  1425. throw new Error('Transport not open');
  1426. }
  1427. };
  1428. /**
  1429. * Called upon open
  1430. *
  1431. * @api private
  1432. */
  1433. Transport.prototype.onOpen = function () {
  1434. this.readyState = 'open';
  1435. this.writable = true;
  1436. this.emit('open');
  1437. };
  1438. /**
  1439. * Called with data.
  1440. *
  1441. * @param {String} data
  1442. * @api private
  1443. */
  1444. Transport.prototype.onData = function (data) {
  1445. var packet = parser.decodePacket(data, this.socket.binaryType);
  1446. this.onPacket(packet);
  1447. };
  1448. /**
  1449. * Called with a decoded packet.
  1450. */
  1451. Transport.prototype.onPacket = function (packet) {
  1452. this.emit('packet', packet);
  1453. };
  1454. /**
  1455. * Called upon close.
  1456. *
  1457. * @api private
  1458. */
  1459. Transport.prototype.onClose = function () {
  1460. this.readyState = 'closed';
  1461. this.emit('close');
  1462. };
  1463. /***/ },
  1464. /* 8 */
  1465. /***/ function(module, exports, __webpack_require__) {
  1466. /* WEBPACK VAR INJECTION */(function(global) {/**
  1467. * Module dependencies.
  1468. */
  1469. var keys = __webpack_require__(9);
  1470. var hasBinary = __webpack_require__(10);
  1471. var sliceBuffer = __webpack_require__(12);
  1472. var after = __webpack_require__(13);
  1473. var utf8 = __webpack_require__(14);
  1474. var base64encoder;
  1475. if (global && global.ArrayBuffer) {
  1476. base64encoder = __webpack_require__(16);
  1477. }
  1478. /**
  1479. * Check if we are running an android browser. That requires us to use
  1480. * ArrayBuffer with polling transports...
  1481. *
  1482. * http://ghinda.net/jpeg-blob-ajax-android/
  1483. */
  1484. var isAndroid = typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
  1485. /**
  1486. * Check if we are running in PhantomJS.
  1487. * Uploading a Blob with PhantomJS does not work correctly, as reported here:
  1488. * https://github.com/ariya/phantomjs/issues/11395
  1489. * @type boolean
  1490. */
  1491. var isPhantomJS = typeof navigator !== 'undefined' && /PhantomJS/i.test(navigator.userAgent);
  1492. /**
  1493. * When true, avoids using Blobs to encode payloads.
  1494. * @type boolean
  1495. */
  1496. var dontSendBlobs = isAndroid || isPhantomJS;
  1497. /**
  1498. * Current protocol version.
  1499. */
  1500. exports.protocol = 3;
  1501. /**
  1502. * Packet types.
  1503. */
  1504. var packets = exports.packets = {
  1505. open: 0 // non-ws
  1506. , close: 1 // non-ws
  1507. , ping: 2
  1508. , pong: 3
  1509. , message: 4
  1510. , upgrade: 5
  1511. , noop: 6
  1512. };
  1513. var packetslist = keys(packets);
  1514. /**
  1515. * Premade error packet.
  1516. */
  1517. var err = { type: 'error', data: 'parser error' };
  1518. /**
  1519. * Create a blob api even for blob builder when vendor prefixes exist
  1520. */
  1521. var Blob = __webpack_require__(17);
  1522. /**
  1523. * Encodes a packet.
  1524. *
  1525. * <packet type id> [ <data> ]
  1526. *
  1527. * Example:
  1528. *
  1529. * 5hello world
  1530. * 3
  1531. * 4
  1532. *
  1533. * Binary is encoded in an identical principle
  1534. *
  1535. * @api private
  1536. */
  1537. exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) {
  1538. if (typeof supportsBinary === 'function') {
  1539. callback = supportsBinary;
  1540. supportsBinary = false;
  1541. }
  1542. if (typeof utf8encode === 'function') {
  1543. callback = utf8encode;
  1544. utf8encode = null;
  1545. }
  1546. var data = (packet.data === undefined)
  1547. ? undefined
  1548. : packet.data.buffer || packet.data;
  1549. if (global.ArrayBuffer && data instanceof ArrayBuffer) {
  1550. return encodeArrayBuffer(packet, supportsBinary, callback);
  1551. } else if (Blob && data instanceof global.Blob) {
  1552. return encodeBlob(packet, supportsBinary, callback);
  1553. }
  1554. // might be an object with { base64: true, data: dataAsBase64String }
  1555. if (data && data.base64) {
  1556. return encodeBase64Object(packet, callback);
  1557. }
  1558. // Sending data as a utf-8 string
  1559. var encoded = packets[packet.type];
  1560. // data fragment is optional
  1561. if (undefined !== packet.data) {
  1562. encoded += utf8encode ? utf8.encode(String(packet.data), { strict: false }) : String(packet.data);
  1563. }
  1564. return callback('' + encoded);
  1565. };
  1566. function encodeBase64Object(packet, callback) {
  1567. // packet data is an object { base64: true, data: dataAsBase64String }
  1568. var message = 'b' + exports.packets[packet.type] + packet.data.data;
  1569. return callback(message);
  1570. }
  1571. /**
  1572. * Encode packet helpers for binary types
  1573. */
  1574. function encodeArrayBuffer(packet, supportsBinary, callback) {
  1575. if (!supportsBinary) {
  1576. return exports.encodeBase64Packet(packet, callback);
  1577. }
  1578. var data = packet.data;
  1579. var contentArray = new Uint8Array(data);
  1580. var resultBuffer = new Uint8Array(1 + data.byteLength);
  1581. resultBuffer[0] = packets[packet.type];
  1582. for (var i = 0; i < contentArray.length; i++) {
  1583. resultBuffer[i+1] = contentArray[i];
  1584. }
  1585. return callback(resultBuffer.buffer);
  1586. }
  1587. function encodeBlobAsArrayBuffer(packet, supportsBinary, callback) {
  1588. if (!supportsBinary) {
  1589. return exports.encodeBase64Packet(packet, callback);
  1590. }
  1591. var fr = new FileReader();
  1592. fr.onload = function() {
  1593. packet.data = fr.result;
  1594. exports.encodePacket(packet, supportsBinary, true, callback);
  1595. };
  1596. return fr.readAsArrayBuffer(packet.data);
  1597. }
  1598. function encodeBlob(packet, supportsBinary, callback) {
  1599. if (!supportsBinary) {
  1600. return exports.encodeBase64Packet(packet, callback);
  1601. }
  1602. if (dontSendBlobs) {
  1603. return encodeBlobAsArrayBuffer(packet, supportsBinary, callback);
  1604. }
  1605. var length = new Uint8Array(1);
  1606. length[0] = packets[packet.type];
  1607. var blob = new Blob([length.buffer, packet.data]);
  1608. return callback(blob);
  1609. }
  1610. /**
  1611. * Encodes a packet with binary data in a base64 string
  1612. *
  1613. * @param {Object} packet, has `type` and `data`
  1614. * @return {String} base64 encoded message
  1615. */
  1616. exports.encodeBase64Packet = function(packet, callback) {
  1617. var message = 'b' + exports.packets[packet.type];
  1618. if (Blob && packet.data instanceof global.Blob) {
  1619. var fr = new FileReader();
  1620. fr.onload = function() {
  1621. var b64 = fr.result.split(',')[1];
  1622. callback(message + b64);
  1623. };
  1624. return fr.readAsDataURL(packet.data);
  1625. }
  1626. var b64data;
  1627. try {
  1628. b64data = String.fromCharCode.apply(null, new Uint8Array(packet.data));
  1629. } catch (e) {
  1630. // iPhone Safari doesn't let you apply with typed arrays
  1631. var typed = new Uint8Array(packet.data);
  1632. var basic = new Array(typed.length);
  1633. for (var i = 0; i < typed.length; i++) {
  1634. basic[i] = typed[i];
  1635. }
  1636. b64data = String.fromCharCode.apply(null, basic);
  1637. }
  1638. message += global.btoa(b64data);
  1639. return callback(message);
  1640. };
  1641. /**
  1642. * Decodes a packet. Changes format to Blob if requested.
  1643. *
  1644. * @return {Object} with `type` and `data` (if any)
  1645. * @api private
  1646. */
  1647. exports.decodePacket = function (data, binaryType, utf8decode) {
  1648. if (data === undefined) {
  1649. return err;
  1650. }
  1651. // String data
  1652. if (typeof data === 'string') {
  1653. if (data.charAt(0) === 'b') {
  1654. return exports.decodeBase64Packet(data.substr(1), binaryType);
  1655. }
  1656. if (utf8decode) {
  1657. data = tryDecode(data);
  1658. if (data === false) {
  1659. return err;
  1660. }
  1661. }
  1662. var type = data.charAt(0);
  1663. if (Number(type) != type || !packetslist[type]) {
  1664. return err;
  1665. }
  1666. if (data.length > 1) {
  1667. return { type: packetslist[type], data: data.substring(1) };
  1668. } else {
  1669. return { type: packetslist[type] };
  1670. }
  1671. }
  1672. var asArray = new Uint8Array(data);
  1673. var type = asArray[0];
  1674. var rest = sliceBuffer(data, 1);
  1675. if (Blob && binaryType === 'blob') {
  1676. rest = new Blob([rest]);
  1677. }
  1678. return { type: packetslist[type], data: rest };
  1679. };
  1680. function tryDecode(data) {
  1681. try {
  1682. data = utf8.decode(data, { strict: false });
  1683. } catch (e) {
  1684. return false;
  1685. }
  1686. return data;
  1687. }
  1688. /**
  1689. * Decodes a packet encoded in a base64 string
  1690. *
  1691. * @param {String} base64 encoded message
  1692. * @return {Object} with `type` and `data` (if any)
  1693. */
  1694. exports.decodeBase64Packet = function(msg, binaryType) {
  1695. var type = packetslist[msg.charAt(0)];
  1696. if (!base64encoder) {
  1697. return { type: type, data: { base64: true, data: msg.substr(1) } };
  1698. }
  1699. var data = base64encoder.decode(msg.substr(1));
  1700. if (binaryType === 'blob' && Blob) {
  1701. data = new Blob([data]);
  1702. }
  1703. return { type: type, data: data };
  1704. };
  1705. /**
  1706. * Encodes multiple messages (payload).
  1707. *
  1708. * <length>:data
  1709. *
  1710. * Example:
  1711. *
  1712. * 11:hello world2:hi
  1713. *
  1714. * If any contents are binary, they will be encoded as base64 strings. Base64
  1715. * encoded strings are marked with a b before the length specifier
  1716. *
  1717. * @param {Array} packets
  1718. * @api private
  1719. */
  1720. exports.encodePayload = function (packets, supportsBinary, callback) {
  1721. if (typeof supportsBinary === 'function') {
  1722. callback = supportsBinary;
  1723. supportsBinary = null;
  1724. }
  1725. var isBinary = hasBinary(packets);
  1726. if (supportsBinary && isBinary) {
  1727. if (Blob && !dontSendBlobs) {
  1728. return exports.encodePayloadAsBlob(packets, callback);
  1729. }
  1730. return exports.encodePayloadAsArrayBuffer(packets, callback);
  1731. }
  1732. if (!packets.length) {
  1733. return callback('0:');
  1734. }
  1735. function setLengthHeader(message) {
  1736. return message.length + ':' + message;
  1737. }
  1738. function encodeOne(packet, doneCallback) {
  1739. exports.encodePacket(packet, !isBinary ? false : supportsBinary, false, function(message) {
  1740. doneCallback(null, setLengthHeader(message));
  1741. });
  1742. }
  1743. map(packets, encodeOne, function(err, results) {
  1744. return callback(results.join(''));
  1745. });
  1746. };
  1747. /**
  1748. * Async array map using after
  1749. */
  1750. function map(ary, each, done) {
  1751. var result = new Array(ary.length);
  1752. var next = after(ary.length, done);
  1753. var eachWithIndex = function(i, el, cb) {
  1754. each(el, function(error, msg) {
  1755. result[i] = msg;
  1756. cb(error, result);
  1757. });
  1758. };
  1759. for (var i = 0; i < ary.length; i++) {
  1760. eachWithIndex(i, ary[i], next);
  1761. }
  1762. }
  1763. /*
  1764. * Decodes data when a payload is maybe expected. Possible binary contents are
  1765. * decoded from their base64 representation
  1766. *
  1767. * @param {String} data, callback method
  1768. * @api public
  1769. */
  1770. exports.decodePayload = function (data, binaryType, callback) {
  1771. if (typeof data !== 'string') {
  1772. return exports.decodePayloadAsBinary(data, binaryType, callback);
  1773. }
  1774. if (typeof binaryType === 'function') {
  1775. callback = binaryType;
  1776. binaryType = null;
  1777. }
  1778. var packet;
  1779. if (data === '') {
  1780. // parser error - ignoring payload
  1781. return callback(err, 0, 1);
  1782. }
  1783. var length = '', n, msg;
  1784. for (var i = 0, l = data.length; i < l; i++) {
  1785. var chr = data.charAt(i);
  1786. if (chr !== ':') {
  1787. length += chr;
  1788. continue;
  1789. }
  1790. if (length === '' || (length != (n = Number(length)))) {
  1791. // parser error - ignoring payload
  1792. return callback(err, 0, 1);
  1793. }
  1794. msg = data.substr(i + 1, n);
  1795. if (length != msg.length) {
  1796. // parser error - ignoring payload
  1797. return callback(err, 0, 1);
  1798. }
  1799. if (msg.length) {
  1800. packet = exports.decodePacket(msg, binaryType, false);
  1801. if (err.type === packet.type && err.data === packet.data) {
  1802. // parser error in individual packet - ignoring payload
  1803. return callback(err, 0, 1);
  1804. }
  1805. var ret = callback(packet, i + n, l);
  1806. if (false === ret) return;
  1807. }
  1808. // advance cursor
  1809. i += n;
  1810. length = '';
  1811. }
  1812. if (length !== '') {
  1813. // parser error - ignoring payload
  1814. return callback(err, 0, 1);
  1815. }
  1816. };
  1817. /**
  1818. * Encodes multiple messages (payload) as binary.
  1819. *
  1820. * <1 = binary, 0 = string><number from 0-9><number from 0-9>[...]<number
  1821. * 255><data>
  1822. *
  1823. * Example:
  1824. * 1 3 255 1 2 3, if the binary contents are interpreted as 8 bit integers
  1825. *
  1826. * @param {Array} packets
  1827. * @return {ArrayBuffer} encoded payload
  1828. * @api private
  1829. */
  1830. exports.encodePayloadAsArrayBuffer = function(packets, callback) {
  1831. if (!packets.length) {
  1832. return callback(new ArrayBuffer(0));
  1833. }
  1834. function encodeOne(packet, doneCallback) {
  1835. exports.encodePacket(packet, true, true, function(data) {
  1836. return doneCallback(null, data);
  1837. });
  1838. }
  1839. map(packets, encodeOne, function(err, encodedPackets) {
  1840. var totalLength = encodedPackets.reduce(function(acc, p) {
  1841. var len;
  1842. if (typeof p === 'string'){
  1843. len = p.length;
  1844. } else {
  1845. len = p.byteLength;
  1846. }
  1847. return acc + len.toString().length + len + 2; // string/binary identifier + separator = 2
  1848. }, 0);
  1849. var resultArray = new Uint8Array(totalLength);
  1850. var bufferIndex = 0;
  1851. encodedPackets.forEach(function(p) {
  1852. var isString = typeof p === 'string';
  1853. var ab = p;
  1854. if (isString) {
  1855. var view = new Uint8Array(p.length);
  1856. for (var i = 0; i < p.length; i++) {
  1857. view[i] = p.charCodeAt(i);
  1858. }
  1859. ab = view.buffer;
  1860. }
  1861. if (isString) { // not true binary
  1862. resultArray[bufferIndex++] = 0;
  1863. } else { // true binary
  1864. resultArray[bufferIndex++] = 1;
  1865. }
  1866. var lenStr = ab.byteLength.toString();
  1867. for (var i = 0; i < lenStr.length; i++) {
  1868. resultArray[bufferIndex++] = parseInt(lenStr[i]);
  1869. }
  1870. resultArray[bufferIndex++] = 255;
  1871. var view = new Uint8Array(ab);
  1872. for (var i = 0; i < view.length; i++) {
  1873. resultArray[bufferIndex++] = view[i];
  1874. }
  1875. });
  1876. return callback(resultArray.buffer);
  1877. });
  1878. };
  1879. /**
  1880. * Encode as Blob
  1881. */
  1882. exports.encodePayloadAsBlob = function(packets, callback) {
  1883. function encodeOne(packet, doneCallback) {
  1884. exports.encodePacket(packet, true, true, function(encoded) {
  1885. var binaryIdentifier = new Uint8Array(1);
  1886. binaryIdentifier[0] = 1;
  1887. if (typeof encoded === 'string') {
  1888. var view = new Uint8Array(encoded.length);
  1889. for (var i = 0; i < encoded.length; i++) {
  1890. view[i] = encoded.charCodeAt(i);
  1891. }
  1892. encoded = view.buffer;
  1893. binaryIdentifier[0] = 0;
  1894. }
  1895. var len = (encoded instanceof ArrayBuffer)
  1896. ? encoded.byteLength
  1897. : encoded.size;
  1898. var lenStr = len.toString();
  1899. var lengthAry = new Uint8Array(lenStr.length + 1);
  1900. for (var i = 0; i < lenStr.length; i++) {
  1901. lengthAry[i] = parseInt(lenStr[i]);
  1902. }
  1903. lengthAry[lenStr.length] = 255;
  1904. if (Blob) {
  1905. var blob = new Blob([binaryIdentifier.buffer, lengthAry.buffer, encoded]);
  1906. doneCallback(null, blob);
  1907. }
  1908. });
  1909. }
  1910. map(packets, encodeOne, function(err, results) {
  1911. return callback(new Blob(results));
  1912. });
  1913. };
  1914. /*
  1915. * Decodes data when a payload is maybe expected. Strings are decoded by
  1916. * interpreting each byte as a key code for entries marked to start with 0. See
  1917. * description of encodePayloadAsBinary
  1918. *
  1919. * @param {ArrayBuffer} data, callback method
  1920. * @api public
  1921. */
  1922. exports.decodePayloadAsBinary = function (data, binaryType, callback) {
  1923. if (typeof binaryType === 'function') {
  1924. callback = binaryType;
  1925. binaryType = null;
  1926. }
  1927. var bufferTail = data;
  1928. var buffers = [];
  1929. while (bufferTail.byteLength > 0) {
  1930. var tailArray = new Uint8Array(bufferTail);
  1931. var isString = tailArray[0] === 0;
  1932. var msgLength = '';
  1933. for (var i = 1; ; i++) {
  1934. if (tailArray[i] === 255) break;
  1935. // 310 = char length of Number.MAX_VALUE
  1936. if (msgLength.length > 310) {
  1937. return callback(err, 0, 1);
  1938. }
  1939. msgLength += tailArray[i];
  1940. }
  1941. bufferTail = sliceBuffer(bufferTail, 2 + msgLength.length);
  1942. msgLength = parseInt(msgLength);
  1943. var msg = sliceBuffer(bufferTail, 0, msgLength);
  1944. if (isString) {
  1945. try {
  1946. msg = String.fromCharCode.apply(null, new Uint8Array(msg));
  1947. } catch (e) {
  1948. // iPhone Safari doesn't let you apply to typed arrays
  1949. var typed = new Uint8Array(msg);
  1950. msg = '';
  1951. for (var i = 0; i < typed.length; i++) {
  1952. msg += String.fromCharCode(typed[i]);
  1953. }
  1954. }
  1955. }
  1956. buffers.push(msg);
  1957. bufferTail = sliceBuffer(bufferTail, msgLength);
  1958. }
  1959. var total = buffers.length;
  1960. buffers.forEach(function(buffer, i) {
  1961. callback(exports.decodePacket(buffer, binaryType, true), i, total);
  1962. });
  1963. };
  1964. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  1965. /***/ },
  1966. /* 9 */
  1967. /***/ function(module, exports) {
  1968. /**
  1969. * Gets the keys for an object.
  1970. *
  1971. * @return {Array} keys
  1972. * @api private
  1973. */
  1974. module.exports = Object.keys || function keys (obj){
  1975. var arr = [];
  1976. var has = Object.prototype.hasOwnProperty;
  1977. for (var i in obj) {
  1978. if (has.call(obj, i)) {
  1979. arr.push(i);
  1980. }
  1981. }
  1982. return arr;
  1983. };
  1984. /***/ },
  1985. /* 10 */
  1986. /***/ function(module, exports, __webpack_require__) {
  1987. /* WEBPACK VAR INJECTION */(function(global) {/* global Blob File */
  1988. /*
  1989. * Module requirements.
  1990. */
  1991. var isArray = __webpack_require__(11);
  1992. var toString = Object.prototype.toString;
  1993. var withNativeBlob = typeof global.Blob === 'function' || toString.call(global.Blob) === '[object BlobConstructor]';
  1994. var withNativeFile = typeof global.File === 'function' || toString.call(global.File) === '[object FileConstructor]';
  1995. /**
  1996. * Module exports.
  1997. */
  1998. module.exports = hasBinary;
  1999. /**
  2000. * Checks for binary data.
  2001. *
  2002. * Supports Buffer, ArrayBuffer, Blob and File.
  2003. *
  2004. * @param {Object} anything
  2005. * @api public
  2006. */
  2007. function hasBinary (obj) {
  2008. if (!obj || typeof obj !== 'object') {
  2009. return false;
  2010. }
  2011. if (isArray(obj)) {
  2012. for (var i = 0, l = obj.length; i < l; i++) {
  2013. if (hasBinary(obj[i])) {
  2014. return true;
  2015. }
  2016. }
  2017. return false;
  2018. }
  2019. if ((typeof global.Buffer === 'function' && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) ||
  2020. (typeof global.ArrayBuffer === 'function' && obj instanceof ArrayBuffer) ||
  2021. (withNativeBlob && obj instanceof Blob) ||
  2022. (withNativeFile && obj instanceof File)
  2023. ) {
  2024. return true;
  2025. }
  2026. // see: https://github.com/Automattic/has-binary/pull/4
  2027. if (obj.toJSON && typeof obj.toJSON === 'function' && arguments.length === 1) {
  2028. return hasBinary(obj.toJSON(), true);
  2029. }
  2030. for (var key in obj) {
  2031. if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
  2032. return true;
  2033. }
  2034. }
  2035. return false;
  2036. }
  2037. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  2038. /***/ },
  2039. /* 11 */
  2040. /***/ function(module, exports) {
  2041. var toString = {}.toString;
  2042. module.exports = Array.isArray || function (arr) {
  2043. return toString.call(arr) == '[object Array]';
  2044. };
  2045. /***/ },
  2046. /* 12 */
  2047. /***/ function(module, exports) {
  2048. /**
  2049. * An abstraction for slicing an arraybuffer even when
  2050. * ArrayBuffer.prototype.slice is not supported
  2051. *
  2052. * @api public
  2053. */
  2054. module.exports = function(arraybuffer, start, end) {
  2055. var bytes = arraybuffer.byteLength;
  2056. start = start || 0;
  2057. end = end || bytes;
  2058. if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
  2059. if (start < 0) { start += bytes; }
  2060. if (end < 0) { end += bytes; }
  2061. if (end > bytes) { end = bytes; }
  2062. if (start >= bytes || start >= end || bytes === 0) {
  2063. return new ArrayBuffer(0);
  2064. }
  2065. var abv = new Uint8Array(arraybuffer);
  2066. var result = new Uint8Array(end - start);
  2067. for (var i = start, ii = 0; i < end; i++, ii++) {
  2068. result[ii] = abv[i];
  2069. }
  2070. return result.buffer;
  2071. };
  2072. /***/ },
  2073. /* 13 */
  2074. /***/ function(module, exports) {
  2075. module.exports = after
  2076. function after(count, callback, err_cb) {
  2077. var bail = false
  2078. err_cb = err_cb || noop
  2079. proxy.count = count
  2080. return (count === 0) ? callback() : proxy
  2081. function proxy(err, result) {
  2082. if (proxy.count <= 0) {
  2083. throw new Error('after called too many times')
  2084. }
  2085. --proxy.count
  2086. // after first error, rest are passed to err_cb
  2087. if (err) {
  2088. bail = true
  2089. callback(err)
  2090. // future error callbacks will go to error handler
  2091. callback = err_cb
  2092. } else if (proxy.count === 0 && !bail) {
  2093. callback(null, result)
  2094. }
  2095. }
  2096. }
  2097. function noop() {}
  2098. /***/ },
  2099. /* 14 */
  2100. /***/ function(module, exports, __webpack_require__) {
  2101. var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module, global) {/*! https://mths.be/utf8js v2.1.2 by @mathias */
  2102. ;(function(root) {
  2103. // Detect free variables `exports`
  2104. var freeExports = typeof exports == 'object' && exports;
  2105. // Detect free variable `module`
  2106. var freeModule = typeof module == 'object' && module &&
  2107. module.exports == freeExports && module;
  2108. // Detect free variable `global`, from Node.js or Browserified code,
  2109. // and use it as `root`
  2110. var freeGlobal = typeof global == 'object' && global;
  2111. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  2112. root = freeGlobal;
  2113. }
  2114. /*--------------------------------------------------------------------------*/
  2115. var stringFromCharCode = String.fromCharCode;
  2116. // Taken from https://mths.be/punycode
  2117. function ucs2decode(string) {
  2118. var output = [];
  2119. var counter = 0;
  2120. var length = string.length;
  2121. var value;
  2122. var extra;
  2123. while (counter < length) {
  2124. value = string.charCodeAt(counter++);
  2125. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  2126. // high surrogate, and there is a next character
  2127. extra = string.charCodeAt(counter++);
  2128. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  2129. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  2130. } else {
  2131. // unmatched surrogate; only append this code unit, in case the next
  2132. // code unit is the high surrogate of a surrogate pair
  2133. output.push(value);
  2134. counter--;
  2135. }
  2136. } else {
  2137. output.push(value);
  2138. }
  2139. }
  2140. return output;
  2141. }
  2142. // Taken from https://mths.be/punycode
  2143. function ucs2encode(array) {
  2144. var length = array.length;
  2145. var index = -1;
  2146. var value;
  2147. var output = '';
  2148. while (++index < length) {
  2149. value = array[index];
  2150. if (value > 0xFFFF) {
  2151. value -= 0x10000;
  2152. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  2153. value = 0xDC00 | value & 0x3FF;
  2154. }
  2155. output += stringFromCharCode(value);
  2156. }
  2157. return output;
  2158. }
  2159. function checkScalarValue(codePoint, strict) {
  2160. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  2161. if (strict) {
  2162. throw Error(
  2163. 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
  2164. ' is not a scalar value'
  2165. );
  2166. }
  2167. return false;
  2168. }
  2169. return true;
  2170. }
  2171. /*--------------------------------------------------------------------------*/
  2172. function createByte(codePoint, shift) {
  2173. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  2174. }
  2175. function encodeCodePoint(codePoint, strict) {
  2176. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  2177. return stringFromCharCode(codePoint);
  2178. }
  2179. var symbol = '';
  2180. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  2181. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  2182. }
  2183. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  2184. if (!checkScalarValue(codePoint, strict)) {
  2185. codePoint = 0xFFFD;
  2186. }
  2187. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  2188. symbol += createByte(codePoint, 6);
  2189. }
  2190. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  2191. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  2192. symbol += createByte(codePoint, 12);
  2193. symbol += createByte(codePoint, 6);
  2194. }
  2195. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  2196. return symbol;
  2197. }
  2198. function utf8encode(string, opts) {
  2199. opts = opts || {};
  2200. var strict = false !== opts.strict;
  2201. var codePoints = ucs2decode(string);
  2202. var length = codePoints.length;
  2203. var index = -1;
  2204. var codePoint;
  2205. var byteString = '';
  2206. while (++index < length) {
  2207. codePoint = codePoints[index];
  2208. byteString += encodeCodePoint(codePoint, strict);
  2209. }
  2210. return byteString;
  2211. }
  2212. /*--------------------------------------------------------------------------*/
  2213. function readContinuationByte() {
  2214. if (byteIndex >= byteCount) {
  2215. throw Error('Invalid byte index');
  2216. }
  2217. var continuationByte = byteArray[byteIndex] & 0xFF;
  2218. byteIndex++;
  2219. if ((continuationByte & 0xC0) == 0x80) {
  2220. return continuationByte & 0x3F;
  2221. }
  2222. // If we end up here, it’s not a continuation byte
  2223. throw Error('Invalid continuation byte');
  2224. }
  2225. function decodeSymbol(strict) {
  2226. var byte1;
  2227. var byte2;
  2228. var byte3;
  2229. var byte4;
  2230. var codePoint;
  2231. if (byteIndex > byteCount) {
  2232. throw Error('Invalid byte index');
  2233. }
  2234. if (byteIndex == byteCount) {
  2235. return false;
  2236. }
  2237. // Read first byte
  2238. byte1 = byteArray[byteIndex] & 0xFF;
  2239. byteIndex++;
  2240. // 1-byte sequence (no continuation bytes)
  2241. if ((byte1 & 0x80) == 0) {
  2242. return byte1;
  2243. }
  2244. // 2-byte sequence
  2245. if ((byte1 & 0xE0) == 0xC0) {
  2246. byte2 = readContinuationByte();
  2247. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  2248. if (codePoint >= 0x80) {
  2249. return codePoint;
  2250. } else {
  2251. throw Error('Invalid continuation byte');
  2252. }
  2253. }
  2254. // 3-byte sequence (may include unpaired surrogates)
  2255. if ((byte1 & 0xF0) == 0xE0) {
  2256. byte2 = readContinuationByte();
  2257. byte3 = readContinuationByte();
  2258. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  2259. if (codePoint >= 0x0800) {
  2260. return checkScalarValue(codePoint, strict) ? codePoint : 0xFFFD;
  2261. } else {
  2262. throw Error('Invalid continuation byte');
  2263. }
  2264. }
  2265. // 4-byte sequence
  2266. if ((byte1 & 0xF8) == 0xF0) {
  2267. byte2 = readContinuationByte();
  2268. byte3 = readContinuationByte();
  2269. byte4 = readContinuationByte();
  2270. codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
  2271. (byte3 << 0x06) | byte4;
  2272. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  2273. return codePoint;
  2274. }
  2275. }
  2276. throw Error('Invalid UTF-8 detected');
  2277. }
  2278. var byteArray;
  2279. var byteCount;
  2280. var byteIndex;
  2281. function utf8decode(byteString, opts) {
  2282. opts = opts || {};
  2283. var strict = false !== opts.strict;
  2284. byteArray = ucs2decode(byteString);
  2285. byteCount = byteArray.length;
  2286. byteIndex = 0;
  2287. var codePoints = [];
  2288. var tmp;
  2289. while ((tmp = decodeSymbol(strict)) !== false) {
  2290. codePoints.push(tmp);
  2291. }
  2292. return ucs2encode(codePoints);
  2293. }
  2294. /*--------------------------------------------------------------------------*/
  2295. var utf8 = {
  2296. 'version': '2.1.2',
  2297. 'encode': utf8encode,
  2298. 'decode': utf8decode
  2299. };
  2300. // Some AMD build optimizers, like r.js, check for specific condition patterns
  2301. // like the following:
  2302. if (
  2303. true
  2304. ) {
  2305. !(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
  2306. return utf8;
  2307. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  2308. } else if (freeExports && !freeExports.nodeType) {
  2309. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  2310. freeModule.exports = utf8;
  2311. } else { // in Narwhal or RingoJS v0.7.0-
  2312. var object = {};
  2313. var hasOwnProperty = object.hasOwnProperty;
  2314. for (var key in utf8) {
  2315. hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]);
  2316. }
  2317. }
  2318. } else { // in Rhino or a web browser
  2319. root.utf8 = utf8;
  2320. }
  2321. }(this));
  2322. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(15)(module), (function() { return this; }())))
  2323. /***/ },
  2324. /* 15 */
  2325. /***/ function(module, exports) {
  2326. module.exports = function(module) {
  2327. if(!module.webpackPolyfill) {
  2328. module.deprecate = function() {};
  2329. module.paths = [];
  2330. // module.parent = undefined by default
  2331. module.children = [];
  2332. module.webpackPolyfill = 1;
  2333. }
  2334. return module;
  2335. }
  2336. /***/ },
  2337. /* 16 */
  2338. /***/ function(module, exports) {
  2339. /*
  2340. * base64-arraybuffer
  2341. * https://github.com/niklasvh/base64-arraybuffer
  2342. *
  2343. * Copyright (c) 2012 Niklas von Hertzen
  2344. * Licensed under the MIT license.
  2345. */
  2346. (function(){
  2347. "use strict";
  2348. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2349. // Use a lookup table to find the index.
  2350. var lookup = new Uint8Array(256);
  2351. for (var i = 0; i < chars.length; i++) {
  2352. lookup[chars.charCodeAt(i)] = i;
  2353. }
  2354. exports.encode = function(arraybuffer) {
  2355. var bytes = new Uint8Array(arraybuffer),
  2356. i, len = bytes.length, base64 = "";
  2357. for (i = 0; i < len; i+=3) {
  2358. base64 += chars[bytes[i] >> 2];
  2359. base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
  2360. base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
  2361. base64 += chars[bytes[i + 2] & 63];
  2362. }
  2363. if ((len % 3) === 2) {
  2364. base64 = base64.substring(0, base64.length - 1) + "=";
  2365. } else if (len % 3 === 1) {
  2366. base64 = base64.substring(0, base64.length - 2) + "==";
  2367. }
  2368. return base64;
  2369. };
  2370. exports.decode = function(base64) {
  2371. var bufferLength = base64.length * 0.75,
  2372. len = base64.length, i, p = 0,
  2373. encoded1, encoded2, encoded3, encoded4;
  2374. if (base64[base64.length - 1] === "=") {
  2375. bufferLength--;
  2376. if (base64[base64.length - 2] === "=") {
  2377. bufferLength--;
  2378. }
  2379. }
  2380. var arraybuffer = new ArrayBuffer(bufferLength),
  2381. bytes = new Uint8Array(arraybuffer);
  2382. for (i = 0; i < len; i+=4) {
  2383. encoded1 = lookup[base64.charCodeAt(i)];
  2384. encoded2 = lookup[base64.charCodeAt(i+1)];
  2385. encoded3 = lookup[base64.charCodeAt(i+2)];
  2386. encoded4 = lookup[base64.charCodeAt(i+3)];
  2387. bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
  2388. bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
  2389. bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
  2390. }
  2391. return arraybuffer;
  2392. };
  2393. })();
  2394. /***/ },
  2395. /* 17 */
  2396. /***/ function(module, exports) {
  2397. /* WEBPACK VAR INJECTION */(function(global) {/**
  2398. * Create a blob builder even when vendor prefixes exist
  2399. */
  2400. var BlobBuilder = global.BlobBuilder
  2401. || global.WebKitBlobBuilder
  2402. || global.MSBlobBuilder
  2403. || global.MozBlobBuilder;
  2404. /**
  2405. * Check if Blob constructor is supported
  2406. */
  2407. var blobSupported = (function() {
  2408. try {
  2409. var a = new Blob(['hi']);
  2410. return a.size === 2;
  2411. } catch(e) {
  2412. return false;
  2413. }
  2414. })();
  2415. /**
  2416. * Check if Blob constructor supports ArrayBufferViews
  2417. * Fails in Safari 6, so we need to map to ArrayBuffers there.
  2418. */
  2419. var blobSupportsArrayBufferView = blobSupported && (function() {
  2420. try {
  2421. var b = new Blob([new Uint8Array([1,2])]);
  2422. return b.size === 2;
  2423. } catch(e) {
  2424. return false;
  2425. }
  2426. })();
  2427. /**
  2428. * Check if BlobBuilder is supported
  2429. */
  2430. var blobBuilderSupported = BlobBuilder
  2431. && BlobBuilder.prototype.append
  2432. && BlobBuilder.prototype.getBlob;
  2433. /**
  2434. * Helper function that maps ArrayBufferViews to ArrayBuffers
  2435. * Used by BlobBuilder constructor and old browsers that didn't
  2436. * support it in the Blob constructor.
  2437. */
  2438. function mapArrayBufferViews(ary) {
  2439. for (var i = 0; i < ary.length; i++) {
  2440. var chunk = ary[i];
  2441. if (chunk.buffer instanceof ArrayBuffer) {
  2442. var buf = chunk.buffer;
  2443. // if this is a subarray, make a copy so we only
  2444. // include the subarray region from the underlying buffer
  2445. if (chunk.byteLength !== buf.byteLength) {
  2446. var copy = new Uint8Array(chunk.byteLength);
  2447. copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength));
  2448. buf = copy.buffer;
  2449. }
  2450. ary[i] = buf;
  2451. }
  2452. }
  2453. }
  2454. function BlobBuilderConstructor(ary, options) {
  2455. options = options || {};
  2456. var bb = new BlobBuilder();
  2457. mapArrayBufferViews(ary);
  2458. for (var i = 0; i < ary.length; i++) {
  2459. bb.append(ary[i]);
  2460. }
  2461. return (options.type) ? bb.getBlob(options.type) : bb.getBlob();
  2462. };
  2463. function BlobConstructor(ary, options) {
  2464. mapArrayBufferViews(ary);
  2465. return new Blob(ary, options || {});
  2466. };
  2467. module.exports = (function() {
  2468. if (blobSupported) {
  2469. return blobSupportsArrayBufferView ? global.Blob : BlobConstructor;
  2470. } else if (blobBuilderSupported) {
  2471. return BlobBuilderConstructor;
  2472. } else {
  2473. return undefined;
  2474. }
  2475. })();
  2476. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  2477. /***/ },
  2478. /* 18 */
  2479. /***/ function(module, exports, __webpack_require__) {
  2480. /**
  2481. * Expose `Emitter`.
  2482. */
  2483. if (true) {
  2484. module.exports = Emitter;
  2485. }
  2486. /**
  2487. * Initialize a new `Emitter`.
  2488. *
  2489. * @api public
  2490. */
  2491. function Emitter(obj) {
  2492. if (obj) return mixin(obj);
  2493. };
  2494. /**
  2495. * Mixin the emitter properties.
  2496. *
  2497. * @param {Object} obj
  2498. * @return {Object}
  2499. * @api private
  2500. */
  2501. function mixin(obj) {
  2502. for (var key in Emitter.prototype) {
  2503. obj[key] = Emitter.prototype[key];
  2504. }
  2505. return obj;
  2506. }
  2507. /**
  2508. * Listen on the given `event` with `fn`.
  2509. *
  2510. * @param {String} event
  2511. * @param {Function} fn
  2512. * @return {Emitter}
  2513. * @api public
  2514. */
  2515. Emitter.prototype.on =
  2516. Emitter.prototype.addEventListener = function(event, fn){
  2517. this._callbacks = this._callbacks || {};
  2518. (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
  2519. .push(fn);
  2520. return this;
  2521. };
  2522. /**
  2523. * Adds an `event` listener that will be invoked a single
  2524. * time then automatically removed.
  2525. *
  2526. * @param {String} event
  2527. * @param {Function} fn
  2528. * @return {Emitter}
  2529. * @api public
  2530. */
  2531. Emitter.prototype.once = function(event, fn){
  2532. function on() {
  2533. this.off(event, on);
  2534. fn.apply(this, arguments);
  2535. }
  2536. on.fn = fn;
  2537. this.on(event, on);
  2538. return this;
  2539. };
  2540. /**
  2541. * Remove the given callback for `event` or all
  2542. * registered callbacks.
  2543. *
  2544. * @param {String} event
  2545. * @param {Function} fn
  2546. * @return {Emitter}
  2547. * @api public
  2548. */
  2549. Emitter.prototype.off =
  2550. Emitter.prototype.removeListener =
  2551. Emitter.prototype.removeAllListeners =
  2552. Emitter.prototype.removeEventListener = function(event, fn){
  2553. this._callbacks = this._callbacks || {};
  2554. // all
  2555. if (0 == arguments.length) {
  2556. this._callbacks = {};
  2557. return this;
  2558. }
  2559. // specific event
  2560. var callbacks = this._callbacks['$' + event];
  2561. if (!callbacks) return this;
  2562. // remove all handlers
  2563. if (1 == arguments.length) {
  2564. delete this._callbacks['$' + event];
  2565. return this;
  2566. }
  2567. // remove specific handler
  2568. var cb;
  2569. for (var i = 0; i < callbacks.length; i++) {
  2570. cb = callbacks[i];
  2571. if (cb === fn || cb.fn === fn) {
  2572. callbacks.splice(i, 1);
  2573. break;
  2574. }
  2575. }
  2576. return this;
  2577. };
  2578. /**
  2579. * Emit `event` with the given args.
  2580. *
  2581. * @param {String} event
  2582. * @param {Mixed} ...
  2583. * @return {Emitter}
  2584. */
  2585. Emitter.prototype.emit = function(event){
  2586. this._callbacks = this._callbacks || {};
  2587. var args = [].slice.call(arguments, 1)
  2588. , callbacks = this._callbacks['$' + event];
  2589. if (callbacks) {
  2590. callbacks = callbacks.slice(0);
  2591. for (var i = 0, len = callbacks.length; i < len; ++i) {
  2592. callbacks[i].apply(this, args);
  2593. }
  2594. }
  2595. return this;
  2596. };
  2597. /**
  2598. * Return array of callbacks for `event`.
  2599. *
  2600. * @param {String} event
  2601. * @return {Array}
  2602. * @api public
  2603. */
  2604. Emitter.prototype.listeners = function(event){
  2605. this._callbacks = this._callbacks || {};
  2606. return this._callbacks['$' + event] || [];
  2607. };
  2608. /**
  2609. * Check if this emitter has `event` handlers.
  2610. *
  2611. * @param {String} event
  2612. * @return {Boolean}
  2613. * @api public
  2614. */
  2615. Emitter.prototype.hasListeners = function(event){
  2616. return !! this.listeners(event).length;
  2617. };
  2618. /***/ },
  2619. /* 19 */
  2620. /***/ function(module, exports) {
  2621. /**
  2622. * Compiles a querystring
  2623. * Returns string representation of the object
  2624. *
  2625. * @param {Object}
  2626. * @api private
  2627. */
  2628. exports.encode = function (obj) {
  2629. var str = '';
  2630. for (var i in obj) {
  2631. if (obj.hasOwnProperty(i)) {
  2632. if (str.length) str += '&';
  2633. str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
  2634. }
  2635. }
  2636. return str;
  2637. };
  2638. /**
  2639. * Parses a simple querystring into an object
  2640. *
  2641. * @param {String} qs
  2642. * @api private
  2643. */
  2644. exports.decode = function(qs){
  2645. var qry = {};
  2646. var pairs = qs.split('&');
  2647. for (var i = 0, l = pairs.length; i < l; i++) {
  2648. var pair = pairs[i].split('=');
  2649. qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  2650. }
  2651. return qry;
  2652. };
  2653. /***/ },
  2654. /* 20 */
  2655. /***/ function(module, exports) {
  2656. module.exports = function(a, b){
  2657. var fn = function(){};
  2658. fn.prototype = b.prototype;
  2659. a.prototype = new fn;
  2660. a.prototype.constructor = a;
  2661. };
  2662. /***/ },
  2663. /* 21 */
  2664. /***/ function(module, exports) {
  2665. 'use strict';
  2666. var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
  2667. , length = 64
  2668. , map = {}
  2669. , seed = 0
  2670. , i = 0
  2671. , prev;
  2672. /**
  2673. * Return a string representing the specified number.
  2674. *
  2675. * @param {Number} num The number to convert.
  2676. * @returns {String} The string representation of the number.
  2677. * @api public
  2678. */
  2679. function encode(num) {
  2680. var encoded = '';
  2681. do {
  2682. encoded = alphabet[num % length] + encoded;
  2683. num = Math.floor(num / length);
  2684. } while (num > 0);
  2685. return encoded;
  2686. }
  2687. /**
  2688. * Return the integer value specified by the given string.
  2689. *
  2690. * @param {String} str The string to convert.
  2691. * @returns {Number} The integer value represented by the string.
  2692. * @api public
  2693. */
  2694. function decode(str) {
  2695. var decoded = 0;
  2696. for (i = 0; i < str.length; i++) {
  2697. decoded = decoded * length + map[str.charAt(i)];
  2698. }
  2699. return decoded;
  2700. }
  2701. /**
  2702. * Yeast: A tiny growing id generator.
  2703. *
  2704. * @returns {String} A unique id.
  2705. * @api public
  2706. */
  2707. function yeast() {
  2708. var now = encode(+new Date());
  2709. if (now !== prev) return seed = 0, prev = now;
  2710. return now +'.'+ encode(seed++);
  2711. }
  2712. //
  2713. // Map each character to its index.
  2714. //
  2715. for (; i < length; i++) map[alphabet[i]] = i;
  2716. //
  2717. // Expose the `yeast`, `encode` and `decode` functions.
  2718. //
  2719. yeast.encode = encode;
  2720. yeast.decode = decode;
  2721. module.exports = yeast;
  2722. /***/ },
  2723. /* 22 */
  2724. /***/ function(module, exports, __webpack_require__) {
  2725. /* WEBPACK VAR INJECTION */(function(process) {/**
  2726. * This is the web browser implementation of `debug()`.
  2727. *
  2728. * Expose `debug()` as the module.
  2729. */
  2730. exports = module.exports = __webpack_require__(24);
  2731. exports.log = log;
  2732. exports.formatArgs = formatArgs;
  2733. exports.save = save;
  2734. exports.load = load;
  2735. exports.useColors = useColors;
  2736. exports.storage = 'undefined' != typeof chrome
  2737. && 'undefined' != typeof chrome.storage
  2738. ? chrome.storage.local
  2739. : localstorage();
  2740. /**
  2741. * Colors.
  2742. */
  2743. exports.colors = [
  2744. '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC',
  2745. '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF',
  2746. '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC',
  2747. '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF',
  2748. '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC',
  2749. '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033',
  2750. '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366',
  2751. '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933',
  2752. '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC',
  2753. '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF',
  2754. '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'
  2755. ];
  2756. /**
  2757. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  2758. * and the Firebug extension (any Firefox version) are known
  2759. * to support "%c" CSS customizations.
  2760. *
  2761. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  2762. */
  2763. function useColors() {
  2764. // NB: In an Electron preload script, document will be defined but not fully
  2765. // initialized. Since we know we're in Chrome, we'll just detect this case
  2766. // explicitly
  2767. if (typeof window !== 'undefined' && window.process && window.process.type === 'renderer') {
  2768. return true;
  2769. }
  2770. // Internet Explorer and Edge do not support colors.
  2771. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  2772. return false;
  2773. }
  2774. // is webkit? http://stackoverflow.com/a/16459606/376773
  2775. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  2776. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  2777. // is firebug? http://stackoverflow.com/a/398120/376773
  2778. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  2779. // is firefox >= v31?
  2780. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  2781. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  2782. // double check webkit in userAgent just in case we are in a worker
  2783. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  2784. }
  2785. /**
  2786. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  2787. */
  2788. exports.formatters.j = function(v) {
  2789. try {
  2790. return JSON.stringify(v);
  2791. } catch (err) {
  2792. return '[UnexpectedJSONParseError]: ' + err.message;
  2793. }
  2794. };
  2795. /**
  2796. * Colorize log arguments if enabled.
  2797. *
  2798. * @api public
  2799. */
  2800. function formatArgs(args) {
  2801. var useColors = this.useColors;
  2802. args[0] = (useColors ? '%c' : '')
  2803. + this.namespace
  2804. + (useColors ? ' %c' : ' ')
  2805. + args[0]
  2806. + (useColors ? '%c ' : ' ')
  2807. + '+' + exports.humanize(this.diff);
  2808. if (!useColors) return;
  2809. var c = 'color: ' + this.color;
  2810. args.splice(1, 0, c, 'color: inherit')
  2811. // the final "%c" is somewhat tricky, because there could be other
  2812. // arguments passed either before or after the %c, so we need to
  2813. // figure out the correct index to insert the CSS into
  2814. var index = 0;
  2815. var lastC = 0;
  2816. args[0].replace(/%[a-zA-Z%]/g, function(match) {
  2817. if ('%%' === match) return;
  2818. index++;
  2819. if ('%c' === match) {
  2820. // we only are interested in the *last* %c
  2821. // (the user may have provided their own)
  2822. lastC = index;
  2823. }
  2824. });
  2825. args.splice(lastC, 0, c);
  2826. }
  2827. /**
  2828. * Invokes `console.log()` when available.
  2829. * No-op when `console.log` is not a "function".
  2830. *
  2831. * @api public
  2832. */
  2833. function log() {
  2834. // this hackery is required for IE8/9, where
  2835. // the `console.log` function doesn't have 'apply'
  2836. return 'object' === typeof console
  2837. && console.log
  2838. && Function.prototype.apply.call(console.log, console, arguments);
  2839. }
  2840. /**
  2841. * Save `namespaces`.
  2842. *
  2843. * @param {String} namespaces
  2844. * @api private
  2845. */
  2846. function save(namespaces) {
  2847. try {
  2848. if (null == namespaces) {
  2849. exports.storage.removeItem('debug');
  2850. } else {
  2851. exports.storage.debug = namespaces;
  2852. }
  2853. } catch(e) {}
  2854. }
  2855. /**
  2856. * Load `namespaces`.
  2857. *
  2858. * @return {String} returns the previously persisted debug modes
  2859. * @api private
  2860. */
  2861. function load() {
  2862. var r;
  2863. try {
  2864. r = exports.storage.debug;
  2865. } catch(e) {}
  2866. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  2867. if (!r && typeof process !== 'undefined' && 'env' in process) {
  2868. r = process.env.DEBUG;
  2869. }
  2870. return r;
  2871. }
  2872. /**
  2873. * Enable namespaces listed in `localStorage.debug` initially.
  2874. */
  2875. exports.enable(load());
  2876. /**
  2877. * Localstorage attempts to return the localstorage.
  2878. *
  2879. * This is necessary because safari throws
  2880. * when a user disables cookies/localstorage
  2881. * and you attempt to access it.
  2882. *
  2883. * @return {LocalStorage}
  2884. * @api private
  2885. */
  2886. function localstorage() {
  2887. try {
  2888. return window.localStorage;
  2889. } catch (e) {}
  2890. }
  2891. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(23)))
  2892. /***/ },
  2893. /* 23 */
  2894. /***/ function(module, exports) {
  2895. // shim for using process in browser
  2896. var process = module.exports = {};
  2897. // cached from whatever global is present so that test runners that stub it
  2898. // don't break things. But we need to wrap it in a try catch in case it is
  2899. // wrapped in strict mode code which doesn't define any globals. It's inside a
  2900. // function because try/catches deoptimize in certain engines.
  2901. var cachedSetTimeout;
  2902. var cachedClearTimeout;
  2903. function defaultSetTimout() {
  2904. throw new Error('setTimeout has not been defined');
  2905. }
  2906. function defaultClearTimeout () {
  2907. throw new Error('clearTimeout has not been defined');
  2908. }
  2909. (function () {
  2910. try {
  2911. if (typeof setTimeout === 'function') {
  2912. cachedSetTimeout = setTimeout;
  2913. } else {
  2914. cachedSetTimeout = defaultSetTimout;
  2915. }
  2916. } catch (e) {
  2917. cachedSetTimeout = defaultSetTimout;
  2918. }
  2919. try {
  2920. if (typeof clearTimeout === 'function') {
  2921. cachedClearTimeout = clearTimeout;
  2922. } else {
  2923. cachedClearTimeout = defaultClearTimeout;
  2924. }
  2925. } catch (e) {
  2926. cachedClearTimeout = defaultClearTimeout;
  2927. }
  2928. } ())
  2929. function runTimeout(fun) {
  2930. if (cachedSetTimeout === setTimeout) {
  2931. //normal enviroments in sane situations
  2932. return setTimeout(fun, 0);
  2933. }
  2934. // if setTimeout wasn't available but was latter defined
  2935. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  2936. cachedSetTimeout = setTimeout;
  2937. return setTimeout(fun, 0);
  2938. }
  2939. try {
  2940. // when when somebody has screwed with setTimeout but no I.E. maddness
  2941. return cachedSetTimeout(fun, 0);
  2942. } catch(e){
  2943. try {
  2944. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2945. return cachedSetTimeout.call(null, fun, 0);
  2946. } catch(e){
  2947. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  2948. return cachedSetTimeout.call(this, fun, 0);
  2949. }
  2950. }
  2951. }
  2952. function runClearTimeout(marker) {
  2953. if (cachedClearTimeout === clearTimeout) {
  2954. //normal enviroments in sane situations
  2955. return clearTimeout(marker);
  2956. }
  2957. // if clearTimeout wasn't available but was latter defined
  2958. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  2959. cachedClearTimeout = clearTimeout;
  2960. return clearTimeout(marker);
  2961. }
  2962. try {
  2963. // when when somebody has screwed with setTimeout but no I.E. maddness
  2964. return cachedClearTimeout(marker);
  2965. } catch (e){
  2966. try {
  2967. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2968. return cachedClearTimeout.call(null, marker);
  2969. } catch (e){
  2970. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  2971. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  2972. return cachedClearTimeout.call(this, marker);
  2973. }
  2974. }
  2975. }
  2976. var queue = [];
  2977. var draining = false;
  2978. var currentQueue;
  2979. var queueIndex = -1;
  2980. function cleanUpNextTick() {
  2981. if (!draining || !currentQueue) {
  2982. return;
  2983. }
  2984. draining = false;
  2985. if (currentQueue.length) {
  2986. queue = currentQueue.concat(queue);
  2987. } else {
  2988. queueIndex = -1;
  2989. }
  2990. if (queue.length) {
  2991. drainQueue();
  2992. }
  2993. }
  2994. function drainQueue() {
  2995. if (draining) {
  2996. return;
  2997. }
  2998. var timeout = runTimeout(cleanUpNextTick);
  2999. draining = true;
  3000. var len = queue.length;
  3001. while(len) {
  3002. currentQueue = queue;
  3003. queue = [];
  3004. while (++queueIndex < len) {
  3005. if (currentQueue) {
  3006. currentQueue[queueIndex].run();
  3007. }
  3008. }
  3009. queueIndex = -1;
  3010. len = queue.length;
  3011. }
  3012. currentQueue = null;
  3013. draining = false;
  3014. runClearTimeout(timeout);
  3015. }
  3016. process.nextTick = function (fun) {
  3017. var args = new Array(arguments.length - 1);
  3018. if (arguments.length > 1) {
  3019. for (var i = 1; i < arguments.length; i++) {
  3020. args[i - 1] = arguments[i];
  3021. }
  3022. }
  3023. queue.push(new Item(fun, args));
  3024. if (queue.length === 1 && !draining) {
  3025. runTimeout(drainQueue);
  3026. }
  3027. };
  3028. // v8 likes predictible objects
  3029. function Item(fun, array) {
  3030. this.fun = fun;
  3031. this.array = array;
  3032. }
  3033. Item.prototype.run = function () {
  3034. this.fun.apply(null, this.array);
  3035. };
  3036. process.title = 'browser';
  3037. process.browser = true;
  3038. process.env = {};
  3039. process.argv = [];
  3040. process.version = ''; // empty string to avoid regexp issues
  3041. process.versions = {};
  3042. function noop() {}
  3043. process.on = noop;
  3044. process.addListener = noop;
  3045. process.once = noop;
  3046. process.off = noop;
  3047. process.removeListener = noop;
  3048. process.removeAllListeners = noop;
  3049. process.emit = noop;
  3050. process.prependListener = noop;
  3051. process.prependOnceListener = noop;
  3052. process.listeners = function (name) { return [] }
  3053. process.binding = function (name) {
  3054. throw new Error('process.binding is not supported');
  3055. };
  3056. process.cwd = function () { return '/' };
  3057. process.chdir = function (dir) {
  3058. throw new Error('process.chdir is not supported');
  3059. };
  3060. process.umask = function() { return 0; };
  3061. /***/ },
  3062. /* 24 */
  3063. /***/ function(module, exports, __webpack_require__) {
  3064. /**
  3065. * This is the common logic for both the Node.js and web browser
  3066. * implementations of `debug()`.
  3067. *
  3068. * Expose `debug()` as the module.
  3069. */
  3070. exports = module.exports = createDebug.debug = createDebug['default'] = createDebug;
  3071. exports.coerce = coerce;
  3072. exports.disable = disable;
  3073. exports.enable = enable;
  3074. exports.enabled = enabled;
  3075. exports.humanize = __webpack_require__(25);
  3076. /**
  3077. * Active `debug` instances.
  3078. */
  3079. exports.instances = [];
  3080. /**
  3081. * The currently active debug mode names, and names to skip.
  3082. */
  3083. exports.names = [];
  3084. exports.skips = [];
  3085. /**
  3086. * Map of special "%n" handling functions, for the debug "format" argument.
  3087. *
  3088. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  3089. */
  3090. exports.formatters = {};
  3091. /**
  3092. * Select a color.
  3093. * @param {String} namespace
  3094. * @return {Number}
  3095. * @api private
  3096. */
  3097. function selectColor(namespace) {
  3098. var hash = 0, i;
  3099. for (i in namespace) {
  3100. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  3101. hash |= 0; // Convert to 32bit integer
  3102. }
  3103. return exports.colors[Math.abs(hash) % exports.colors.length];
  3104. }
  3105. /**
  3106. * Create a debugger with the given `namespace`.
  3107. *
  3108. * @param {String} namespace
  3109. * @return {Function}
  3110. * @api public
  3111. */
  3112. function createDebug(namespace) {
  3113. var prevTime;
  3114. function debug() {
  3115. // disabled?
  3116. if (!debug.enabled) return;
  3117. var self = debug;
  3118. // set `diff` timestamp
  3119. var curr = +new Date();
  3120. var ms = curr - (prevTime || curr);
  3121. self.diff = ms;
  3122. self.prev = prevTime;
  3123. self.curr = curr;
  3124. prevTime = curr;
  3125. // turn the `arguments` into a proper Array
  3126. var args = new Array(arguments.length);
  3127. for (var i = 0; i < args.length; i++) {
  3128. args[i] = arguments[i];
  3129. }
  3130. args[0] = exports.coerce(args[0]);
  3131. if ('string' !== typeof args[0]) {
  3132. // anything else let's inspect with %O
  3133. args.unshift('%O');
  3134. }
  3135. // apply any `formatters` transformations
  3136. var index = 0;
  3137. args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
  3138. // if we encounter an escaped % then don't increase the array index
  3139. if (match === '%%') return match;
  3140. index++;
  3141. var formatter = exports.formatters[format];
  3142. if ('function' === typeof formatter) {
  3143. var val = args[index];
  3144. match = formatter.call(self, val);
  3145. // now we need to remove `args[index]` since it's inlined in the `format`
  3146. args.splice(index, 1);
  3147. index--;
  3148. }
  3149. return match;
  3150. });
  3151. // apply env-specific formatting (colors, etc.)
  3152. exports.formatArgs.call(self, args);
  3153. var logFn = debug.log || exports.log || console.log.bind(console);
  3154. logFn.apply(self, args);
  3155. }
  3156. debug.namespace = namespace;
  3157. debug.enabled = exports.enabled(namespace);
  3158. debug.useColors = exports.useColors();
  3159. debug.color = selectColor(namespace);
  3160. debug.destroy = destroy;
  3161. // env-specific initialization logic for debug instances
  3162. if ('function' === typeof exports.init) {
  3163. exports.init(debug);
  3164. }
  3165. exports.instances.push(debug);
  3166. return debug;
  3167. }
  3168. function destroy () {
  3169. var index = exports.instances.indexOf(this);
  3170. if (index !== -1) {
  3171. exports.instances.splice(index, 1);
  3172. return true;
  3173. } else {
  3174. return false;
  3175. }
  3176. }
  3177. /**
  3178. * Enables a debug mode by namespaces. This can include modes
  3179. * separated by a colon and wildcards.
  3180. *
  3181. * @param {String} namespaces
  3182. * @api public
  3183. */
  3184. function enable(namespaces) {
  3185. exports.save(namespaces);
  3186. exports.names = [];
  3187. exports.skips = [];
  3188. var i;
  3189. var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  3190. var len = split.length;
  3191. for (i = 0; i < len; i++) {
  3192. if (!split[i]) continue; // ignore empty strings
  3193. namespaces = split[i].replace(/\*/g, '.*?');
  3194. if (namespaces[0] === '-') {
  3195. exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  3196. } else {
  3197. exports.names.push(new RegExp('^' + namespaces + '$'));
  3198. }
  3199. }
  3200. for (i = 0; i < exports.instances.length; i++) {
  3201. var instance = exports.instances[i];
  3202. instance.enabled = exports.enabled(instance.namespace);
  3203. }
  3204. }
  3205. /**
  3206. * Disable debug output.
  3207. *
  3208. * @api public
  3209. */
  3210. function disable() {
  3211. exports.enable('');
  3212. }
  3213. /**
  3214. * Returns true if the given mode name is enabled, false otherwise.
  3215. *
  3216. * @param {String} name
  3217. * @return {Boolean}
  3218. * @api public
  3219. */
  3220. function enabled(name) {
  3221. if (name[name.length - 1] === '*') {
  3222. return true;
  3223. }
  3224. var i, len;
  3225. for (i = 0, len = exports.skips.length; i < len; i++) {
  3226. if (exports.skips[i].test(name)) {
  3227. return false;
  3228. }
  3229. }
  3230. for (i = 0, len = exports.names.length; i < len; i++) {
  3231. if (exports.names[i].test(name)) {
  3232. return true;
  3233. }
  3234. }
  3235. return false;
  3236. }
  3237. /**
  3238. * Coerce `val`.
  3239. *
  3240. * @param {Mixed} val
  3241. * @return {Mixed}
  3242. * @api private
  3243. */
  3244. function coerce(val) {
  3245. if (val instanceof Error) return val.stack || val.message;
  3246. return val;
  3247. }
  3248. /***/ },
  3249. /* 25 */
  3250. /***/ function(module, exports) {
  3251. /**
  3252. * Helpers.
  3253. */
  3254. var s = 1000;
  3255. var m = s * 60;
  3256. var h = m * 60;
  3257. var d = h * 24;
  3258. var y = d * 365.25;
  3259. /**
  3260. * Parse or format the given `val`.
  3261. *
  3262. * Options:
  3263. *
  3264. * - `long` verbose formatting [false]
  3265. *
  3266. * @param {String|Number} val
  3267. * @param {Object} [options]
  3268. * @throws {Error} throw an error if val is not a non-empty string or a number
  3269. * @return {String|Number}
  3270. * @api public
  3271. */
  3272. module.exports = function(val, options) {
  3273. options = options || {};
  3274. var type = typeof val;
  3275. if (type === 'string' && val.length > 0) {
  3276. return parse(val);
  3277. } else if (type === 'number' && isNaN(val) === false) {
  3278. return options.long ? fmtLong(val) : fmtShort(val);
  3279. }
  3280. throw new Error(
  3281. 'val is not a non-empty string or a valid number. val=' +
  3282. JSON.stringify(val)
  3283. );
  3284. };
  3285. /**
  3286. * Parse the given `str` and return milliseconds.
  3287. *
  3288. * @param {String} str
  3289. * @return {Number}
  3290. * @api private
  3291. */
  3292. function parse(str) {
  3293. str = String(str);
  3294. if (str.length > 100) {
  3295. return;
  3296. }
  3297. var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
  3298. str
  3299. );
  3300. if (!match) {
  3301. return;
  3302. }
  3303. var n = parseFloat(match[1]);
  3304. var type = (match[2] || 'ms').toLowerCase();
  3305. switch (type) {
  3306. case 'years':
  3307. case 'year':
  3308. case 'yrs':
  3309. case 'yr':
  3310. case 'y':
  3311. return n * y;
  3312. case 'days':
  3313. case 'day':
  3314. case 'd':
  3315. return n * d;
  3316. case 'hours':
  3317. case 'hour':
  3318. case 'hrs':
  3319. case 'hr':
  3320. case 'h':
  3321. return n * h;
  3322. case 'minutes':
  3323. case 'minute':
  3324. case 'mins':
  3325. case 'min':
  3326. case 'm':
  3327. return n * m;
  3328. case 'seconds':
  3329. case 'second':
  3330. case 'secs':
  3331. case 'sec':
  3332. case 's':
  3333. return n * s;
  3334. case 'milliseconds':
  3335. case 'millisecond':
  3336. case 'msecs':
  3337. case 'msec':
  3338. case 'ms':
  3339. return n;
  3340. default:
  3341. return undefined;
  3342. }
  3343. }
  3344. /**
  3345. * Short format for `ms`.
  3346. *
  3347. * @param {Number} ms
  3348. * @return {String}
  3349. * @api private
  3350. */
  3351. function fmtShort(ms) {
  3352. if (ms >= d) {
  3353. return Math.round(ms / d) + 'd';
  3354. }
  3355. if (ms >= h) {
  3356. return Math.round(ms / h) + 'h';
  3357. }
  3358. if (ms >= m) {
  3359. return Math.round(ms / m) + 'm';
  3360. }
  3361. if (ms >= s) {
  3362. return Math.round(ms / s) + 's';
  3363. }
  3364. return ms + 'ms';
  3365. }
  3366. /**
  3367. * Long format for `ms`.
  3368. *
  3369. * @param {Number} ms
  3370. * @return {String}
  3371. * @api private
  3372. */
  3373. function fmtLong(ms) {
  3374. return plural(ms, d, 'day') ||
  3375. plural(ms, h, 'hour') ||
  3376. plural(ms, m, 'minute') ||
  3377. plural(ms, s, 'second') ||
  3378. ms + ' ms';
  3379. }
  3380. /**
  3381. * Pluralization helper.
  3382. */
  3383. function plural(ms, n, name) {
  3384. if (ms < n) {
  3385. return;
  3386. }
  3387. if (ms < n * 1.5) {
  3388. return Math.floor(ms / n) + ' ' + name;
  3389. }
  3390. return Math.ceil(ms / n) + ' ' + name + 's';
  3391. }
  3392. /***/ },
  3393. /* 26 */
  3394. /***/ function(module, exports, __webpack_require__) {
  3395. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  3396. /**
  3397. * Module requirements.
  3398. */
  3399. var Polling = __webpack_require__(6);
  3400. var inherit = __webpack_require__(20);
  3401. /**
  3402. * Module exports.
  3403. */
  3404. module.exports = JSONPPolling;
  3405. /**
  3406. * Cached regular expressions.
  3407. */
  3408. var rNewline = /\n/g;
  3409. var rEscapedNewline = /\\n/g;
  3410. /**
  3411. * Global JSONP callbacks.
  3412. */
  3413. var callbacks;
  3414. /**
  3415. * Noop.
  3416. */
  3417. function empty() {}
  3418. /**
  3419. * JSONP Polling constructor.
  3420. *
  3421. * @param {Object} opts.
  3422. * @api public
  3423. */
  3424. function JSONPPolling(opts) {
  3425. Polling.call(this, opts);
  3426. this.query = this.query || {};
  3427. // define global callbacks array if not present
  3428. // we do this here (lazily) to avoid unneeded global pollution
  3429. if (!callbacks) {
  3430. // we need to consider multiple engines in the same page
  3431. if (!global.___eio) global.___eio = [];
  3432. callbacks = global.___eio;
  3433. }
  3434. // callback identifier
  3435. this.index = callbacks.length;
  3436. // add callback to jsonp global
  3437. var self = this;
  3438. callbacks.push(function (msg) {
  3439. self.onData(msg);
  3440. });
  3441. // append to query string
  3442. this.query.j = this.index;
  3443. // prevent spurious errors from being emitted when the window is unloaded
  3444. if (global.document && global.addEventListener) {
  3445. global.addEventListener('beforeunload', function () {
  3446. if (self.script) self.script.onerror = empty;
  3447. }, false);
  3448. }
  3449. }
  3450. /**
  3451. * Inherits from Polling.
  3452. */
  3453. inherit(JSONPPolling, Polling);
  3454. /*
  3455. * JSONP only supports binary as base64 encoded strings
  3456. */
  3457. JSONPPolling.prototype.supportsBinary = false;
  3458. /**
  3459. * Closes the socket.
  3460. *
  3461. * @api private
  3462. */
  3463. JSONPPolling.prototype.doClose = function () {
  3464. if (this.script) {
  3465. this.script.parentNode.removeChild(this.script);
  3466. this.script = null;
  3467. }
  3468. if (this.form) {
  3469. this.form.parentNode.removeChild(this.form);
  3470. this.form = null;
  3471. this.iframe = null;
  3472. }
  3473. Polling.prototype.doClose.call(this);
  3474. };
  3475. /**
  3476. * Starts a poll cycle.
  3477. *
  3478. * @api private
  3479. */
  3480. JSONPPolling.prototype.doPoll = function () {
  3481. var self = this;
  3482. var script = document.createElement('script');
  3483. if (this.script) {
  3484. this.script.parentNode.removeChild(this.script);
  3485. this.script = null;
  3486. }
  3487. script.async = true;
  3488. script.src = this.uri();
  3489. script.onerror = function (e) {
  3490. self.onError('jsonp poll error', e);
  3491. };
  3492. var insertAt = document.getElementsByTagName('script')[0];
  3493. if (insertAt) {
  3494. insertAt.parentNode.insertBefore(script, insertAt);
  3495. } else {
  3496. (document.head || document.body).appendChild(script);
  3497. }
  3498. this.script = script;
  3499. var isUAgecko = 'undefined' !== typeof navigator && /gecko/i.test(navigator.userAgent);
  3500. if (isUAgecko) {
  3501. setTimeout(function () {
  3502. var iframe = document.createElement('iframe');
  3503. document.body.appendChild(iframe);
  3504. document.body.removeChild(iframe);
  3505. }, 100);
  3506. }
  3507. };
  3508. /**
  3509. * Writes with a hidden iframe.
  3510. *
  3511. * @param {String} data to send
  3512. * @param {Function} called upon flush.
  3513. * @api private
  3514. */
  3515. JSONPPolling.prototype.doWrite = function (data, fn) {
  3516. var self = this;
  3517. if (!this.form) {
  3518. var form = document.createElement('form');
  3519. var area = document.createElement('textarea');
  3520. var id = this.iframeId = 'eio_iframe_' + this.index;
  3521. var iframe;
  3522. form.className = 'socketio';
  3523. form.style.position = 'absolute';
  3524. form.style.top = '-1000px';
  3525. form.style.left = '-1000px';
  3526. form.target = id;
  3527. form.method = 'POST';
  3528. form.setAttribute('accept-charset', 'utf-8');
  3529. area.name = 'd';
  3530. form.appendChild(area);
  3531. document.body.appendChild(form);
  3532. this.form = form;
  3533. this.area = area;
  3534. }
  3535. this.form.action = this.uri();
  3536. function complete() {
  3537. initIframe();
  3538. fn();
  3539. }
  3540. function initIframe() {
  3541. if (self.iframe) {
  3542. try {
  3543. self.form.removeChild(self.iframe);
  3544. } catch (e) {
  3545. self.onError('jsonp polling iframe removal error', e);
  3546. }
  3547. }
  3548. try {
  3549. // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
  3550. var html = '<iframe src="javascript:0" name="' + self.iframeId + '">';
  3551. iframe = document.createElement(html);
  3552. } catch (e) {
  3553. iframe = document.createElement('iframe');
  3554. iframe.name = self.iframeId;
  3555. iframe.src = 'javascript:0';
  3556. }
  3557. iframe.id = self.iframeId;
  3558. self.form.appendChild(iframe);
  3559. self.iframe = iframe;
  3560. }
  3561. initIframe();
  3562. // escape \n to prevent it from being converted into \r\n by some UAs
  3563. // double escaping is required for escaped new lines because unescaping of new lines can be done safely on server-side
  3564. data = data.replace(rEscapedNewline, '\\\n');
  3565. this.area.value = data.replace(rNewline, '\\n');
  3566. try {
  3567. this.form.submit();
  3568. } catch (e) {}
  3569. if (this.iframe.attachEvent) {
  3570. this.iframe.onreadystatechange = function () {
  3571. if (self.iframe.readyState === 'complete') {
  3572. complete();
  3573. }
  3574. };
  3575. } else {
  3576. this.iframe.onload = complete;
  3577. }
  3578. };
  3579. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  3580. /***/ },
  3581. /* 27 */
  3582. /***/ function(module, exports, __webpack_require__) {
  3583. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  3584. /**
  3585. * Module dependencies.
  3586. */
  3587. var Transport = __webpack_require__(7);
  3588. var parser = __webpack_require__(8);
  3589. var parseqs = __webpack_require__(19);
  3590. var inherit = __webpack_require__(20);
  3591. var yeast = __webpack_require__(21);
  3592. var debug = __webpack_require__(22)('engine.io-client:websocket');
  3593. var BrowserWebSocket = global.WebSocket || global.MozWebSocket;
  3594. var NodeWebSocket;
  3595. if (typeof window === 'undefined') {
  3596. try {
  3597. NodeWebSocket = __webpack_require__(28);
  3598. } catch (e) {}
  3599. }
  3600. /**
  3601. * Get either the `WebSocket` or `MozWebSocket` globals
  3602. * in the browser or try to resolve WebSocket-compatible
  3603. * interface exposed by `ws` for Node-like environment.
  3604. */
  3605. var WebSocket = BrowserWebSocket;
  3606. if (!WebSocket && typeof window === 'undefined') {
  3607. WebSocket = NodeWebSocket;
  3608. }
  3609. /**
  3610. * Module exports.
  3611. */
  3612. module.exports = WS;
  3613. /**
  3614. * WebSocket transport constructor.
  3615. *
  3616. * @api {Object} connection options
  3617. * @api public
  3618. */
  3619. function WS(opts) {
  3620. var forceBase64 = opts && opts.forceBase64;
  3621. if (forceBase64) {
  3622. this.supportsBinary = false;
  3623. }
  3624. this.perMessageDeflate = opts.perMessageDeflate;
  3625. this.usingBrowserWebSocket = BrowserWebSocket && !opts.forceNode;
  3626. this.protocols = opts.protocols;
  3627. if (!this.usingBrowserWebSocket) {
  3628. WebSocket = NodeWebSocket;
  3629. }
  3630. Transport.call(this, opts);
  3631. }
  3632. /**
  3633. * Inherits from Transport.
  3634. */
  3635. inherit(WS, Transport);
  3636. /**
  3637. * Transport name.
  3638. *
  3639. * @api public
  3640. */
  3641. WS.prototype.name = 'websocket';
  3642. /*
  3643. * WebSockets support binary
  3644. */
  3645. WS.prototype.supportsBinary = true;
  3646. /**
  3647. * Opens socket.
  3648. *
  3649. * @api private
  3650. */
  3651. WS.prototype.doOpen = function () {
  3652. if (!this.check()) {
  3653. // let probe timeout
  3654. return;
  3655. }
  3656. var uri = this.uri();
  3657. var protocols = this.protocols;
  3658. var opts = {
  3659. agent: this.agent,
  3660. perMessageDeflate: this.perMessageDeflate
  3661. };
  3662. // SSL options for Node.js client
  3663. opts.pfx = this.pfx;
  3664. opts.key = this.key;
  3665. opts.passphrase = this.passphrase;
  3666. opts.cert = this.cert;
  3667. opts.ca = this.ca;
  3668. opts.ciphers = this.ciphers;
  3669. opts.rejectUnauthorized = this.rejectUnauthorized;
  3670. if (this.extraHeaders) {
  3671. opts.headers = this.extraHeaders;
  3672. }
  3673. if (this.localAddress) {
  3674. opts.localAddress = this.localAddress;
  3675. }
  3676. try {
  3677. this.ws = this.usingBrowserWebSocket ? protocols ? new WebSocket(uri, protocols) : new WebSocket(uri) : new WebSocket(uri, protocols, opts);
  3678. } catch (err) {
  3679. return this.emit('error', err);
  3680. }
  3681. if (this.ws.binaryType === undefined) {
  3682. this.supportsBinary = false;
  3683. }
  3684. if (this.ws.supports && this.ws.supports.binary) {
  3685. this.supportsBinary = true;
  3686. this.ws.binaryType = 'nodebuffer';
  3687. } else {
  3688. this.ws.binaryType = 'arraybuffer';
  3689. }
  3690. this.addEventListeners();
  3691. };
  3692. /**
  3693. * Adds event listeners to the socket
  3694. *
  3695. * @api private
  3696. */
  3697. WS.prototype.addEventListeners = function () {
  3698. var self = this;
  3699. this.ws.onopen = function () {
  3700. self.onOpen();
  3701. };
  3702. this.ws.onclose = function () {
  3703. self.onClose();
  3704. };
  3705. this.ws.onmessage = function (ev) {
  3706. self.onData(ev.data);
  3707. };
  3708. this.ws.onerror = function (e) {
  3709. self.onError('websocket error', e);
  3710. };
  3711. };
  3712. /**
  3713. * Writes data to socket.
  3714. *
  3715. * @param {Array} array of packets.
  3716. * @api private
  3717. */
  3718. WS.prototype.write = function (packets) {
  3719. var self = this;
  3720. this.writable = false;
  3721. // encodePacket efficient as it uses WS framing
  3722. // no need for encodePayload
  3723. var total = packets.length;
  3724. for (var i = 0, l = total; i < l; i++) {
  3725. (function (packet) {
  3726. parser.encodePacket(packet, self.supportsBinary, function (data) {
  3727. if (!self.usingBrowserWebSocket) {
  3728. // always create a new object (GH-437)
  3729. var opts = {};
  3730. if (packet.options) {
  3731. opts.compress = packet.options.compress;
  3732. }
  3733. if (self.perMessageDeflate) {
  3734. var len = 'string' === typeof data ? global.Buffer.byteLength(data) : data.length;
  3735. if (len < self.perMessageDeflate.threshold) {
  3736. opts.compress = false;
  3737. }
  3738. }
  3739. }
  3740. // Sometimes the websocket has already been closed but the browser didn't
  3741. // have a chance of informing us about it yet, in that case send will
  3742. // throw an error
  3743. try {
  3744. if (self.usingBrowserWebSocket) {
  3745. // TypeError is thrown when passing the second argument on Safari
  3746. self.ws.send(data);
  3747. } else {
  3748. self.ws.send(data, opts);
  3749. }
  3750. } catch (e) {
  3751. debug('websocket closed before onclose event');
  3752. }
  3753. --total || done();
  3754. });
  3755. })(packets[i]);
  3756. }
  3757. function done() {
  3758. self.emit('flush');
  3759. // fake drain
  3760. // defer to next tick to allow Socket to clear writeBuffer
  3761. setTimeout(function () {
  3762. self.writable = true;
  3763. self.emit('drain');
  3764. }, 0);
  3765. }
  3766. };
  3767. /**
  3768. * Called upon close
  3769. *
  3770. * @api private
  3771. */
  3772. WS.prototype.onClose = function () {
  3773. Transport.prototype.onClose.call(this);
  3774. };
  3775. /**
  3776. * Closes socket.
  3777. *
  3778. * @api private
  3779. */
  3780. WS.prototype.doClose = function () {
  3781. if (typeof this.ws !== 'undefined') {
  3782. this.ws.close();
  3783. }
  3784. };
  3785. /**
  3786. * Generates uri for connection.
  3787. *
  3788. * @api private
  3789. */
  3790. WS.prototype.uri = function () {
  3791. var query = this.query || {};
  3792. var schema = this.secure ? 'wss' : 'ws';
  3793. var port = '';
  3794. // avoid port if default for schema
  3795. if (this.port && ('wss' === schema && Number(this.port) !== 443 || 'ws' === schema && Number(this.port) !== 80)) {
  3796. port = ':' + this.port;
  3797. }
  3798. // append timestamp to URI
  3799. if (this.timestampRequests) {
  3800. query[this.timestampParam] = yeast();
  3801. }
  3802. // communicate binary support capabilities
  3803. if (!this.supportsBinary) {
  3804. query.b64 = 1;
  3805. }
  3806. query = parseqs.encode(query);
  3807. // prepend ? to query
  3808. if (query.length) {
  3809. query = '?' + query;
  3810. }
  3811. var ipv6 = this.hostname.indexOf(':') !== -1;
  3812. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  3813. };
  3814. /**
  3815. * Feature detection for WebSocket.
  3816. *
  3817. * @return {Boolean} whether this transport is available.
  3818. * @api public
  3819. */
  3820. WS.prototype.check = function () {
  3821. return !!WebSocket && !('__initialize' in WebSocket && this.name === WS.prototype.name);
  3822. };
  3823. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  3824. /***/ },
  3825. /* 28 */
  3826. /***/ function(module, exports) {
  3827. /* (ignored) */
  3828. /***/ },
  3829. /* 29 */
  3830. /***/ function(module, exports) {
  3831. var indexOf = [].indexOf;
  3832. module.exports = function(arr, obj){
  3833. if (indexOf) return arr.indexOf(obj);
  3834. for (var i = 0; i < arr.length; ++i) {
  3835. if (arr[i] === obj) return i;
  3836. }
  3837. return -1;
  3838. };
  3839. /***/ },
  3840. /* 30 */
  3841. /***/ function(module, exports) {
  3842. /**
  3843. * Parses an URI
  3844. *
  3845. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  3846. * @api private
  3847. */
  3848. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  3849. var parts = [
  3850. 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
  3851. ];
  3852. module.exports = function parseuri(str) {
  3853. var src = str,
  3854. b = str.indexOf('['),
  3855. e = str.indexOf(']');
  3856. if (b != -1 && e != -1) {
  3857. str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
  3858. }
  3859. var m = re.exec(str || ''),
  3860. uri = {},
  3861. i = 14;
  3862. while (i--) {
  3863. uri[parts[i]] = m[i] || '';
  3864. }
  3865. if (b != -1 && e != -1) {
  3866. uri.source = src;
  3867. uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
  3868. uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
  3869. uri.ipv6uri = true;
  3870. }
  3871. return uri;
  3872. };
  3873. /***/ }
  3874. /******/ ])
  3875. });
  3876. ;