engine.io.js 108 KB

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