engine.io.js 110 KB

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