engine.io.js 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643
  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 self === 'undefined') {
  3554. try {
  3555. NodeWebSocket = __webpack_require__(27);
  3556. } catch (e) {}
  3557. } else {
  3558. BrowserWebSocket = self.WebSocket || self.MozWebSocket;
  3559. }
  3560. /**
  3561. * Get either the `WebSocket` or `MozWebSocket` globals
  3562. * in the browser or try to resolve WebSocket-compatible
  3563. * interface exposed by `ws` for Node-like environment.
  3564. */
  3565. var WebSocket = BrowserWebSocket || NodeWebSocket;
  3566. /**
  3567. * Module exports.
  3568. */
  3569. module.exports = WS;
  3570. /**
  3571. * WebSocket transport constructor.
  3572. *
  3573. * @api {Object} connection options
  3574. * @api public
  3575. */
  3576. function WS(opts) {
  3577. var forceBase64 = opts && opts.forceBase64;
  3578. if (forceBase64) {
  3579. this.supportsBinary = false;
  3580. }
  3581. this.perMessageDeflate = opts.perMessageDeflate;
  3582. this.usingBrowserWebSocket = BrowserWebSocket && !opts.forceNode;
  3583. this.protocols = opts.protocols;
  3584. if (!this.usingBrowserWebSocket) {
  3585. WebSocket = NodeWebSocket;
  3586. }
  3587. Transport.call(this, opts);
  3588. }
  3589. /**
  3590. * Inherits from Transport.
  3591. */
  3592. inherit(WS, Transport);
  3593. /**
  3594. * Transport name.
  3595. *
  3596. * @api public
  3597. */
  3598. WS.prototype.name = 'websocket';
  3599. /*
  3600. * WebSockets support binary
  3601. */
  3602. WS.prototype.supportsBinary = true;
  3603. /**
  3604. * Opens socket.
  3605. *
  3606. * @api private
  3607. */
  3608. WS.prototype.doOpen = function () {
  3609. if (!this.check()) {
  3610. // let probe timeout
  3611. return;
  3612. }
  3613. var uri = this.uri();
  3614. var protocols = this.protocols;
  3615. var opts = {
  3616. agent: this.agent,
  3617. perMessageDeflate: this.perMessageDeflate
  3618. };
  3619. // SSL options for Node.js client
  3620. opts.pfx = this.pfx;
  3621. opts.key = this.key;
  3622. opts.passphrase = this.passphrase;
  3623. opts.cert = this.cert;
  3624. opts.ca = this.ca;
  3625. opts.ciphers = this.ciphers;
  3626. opts.rejectUnauthorized = this.rejectUnauthorized;
  3627. if (this.extraHeaders) {
  3628. opts.headers = this.extraHeaders;
  3629. }
  3630. if (this.localAddress) {
  3631. opts.localAddress = this.localAddress;
  3632. }
  3633. try {
  3634. this.ws = this.usingBrowserWebSocket && !this.isReactNative ? protocols ? new WebSocket(uri, protocols) : new WebSocket(uri) : new WebSocket(uri, protocols, opts);
  3635. } catch (err) {
  3636. return this.emit('error', err);
  3637. }
  3638. if (this.ws.binaryType === undefined) {
  3639. this.supportsBinary = false;
  3640. }
  3641. if (this.ws.supports && this.ws.supports.binary) {
  3642. this.supportsBinary = true;
  3643. this.ws.binaryType = 'nodebuffer';
  3644. } else {
  3645. this.ws.binaryType = 'arraybuffer';
  3646. }
  3647. this.addEventListeners();
  3648. };
  3649. /**
  3650. * Adds event listeners to the socket
  3651. *
  3652. * @api private
  3653. */
  3654. WS.prototype.addEventListeners = function () {
  3655. var self = this;
  3656. this.ws.onopen = function () {
  3657. self.onOpen();
  3658. };
  3659. this.ws.onclose = function () {
  3660. self.onClose();
  3661. };
  3662. this.ws.onmessage = function (ev) {
  3663. self.onData(ev.data);
  3664. };
  3665. this.ws.onerror = function (e) {
  3666. self.onError('websocket error', e);
  3667. };
  3668. };
  3669. /**
  3670. * Writes data to socket.
  3671. *
  3672. * @param {Array} array of packets.
  3673. * @api private
  3674. */
  3675. WS.prototype.write = function (packets) {
  3676. var self = this;
  3677. this.writable = false;
  3678. // encodePacket efficient as it uses WS framing
  3679. // no need for encodePayload
  3680. var total = packets.length;
  3681. for (var i = 0, l = total; i < l; i++) {
  3682. (function (packet) {
  3683. parser.encodePacket(packet, self.supportsBinary, function (data) {
  3684. if (!self.usingBrowserWebSocket) {
  3685. // always create a new object (GH-437)
  3686. var opts = {};
  3687. if (packet.options) {
  3688. opts.compress = packet.options.compress;
  3689. }
  3690. if (self.perMessageDeflate) {
  3691. var len = 'string' === typeof data ? Buffer.byteLength(data) : data.length;
  3692. if (len < self.perMessageDeflate.threshold) {
  3693. opts.compress = false;
  3694. }
  3695. }
  3696. }
  3697. // Sometimes the websocket has already been closed but the browser didn't
  3698. // have a chance of informing us about it yet, in that case send will
  3699. // throw an error
  3700. try {
  3701. if (self.usingBrowserWebSocket) {
  3702. // TypeError is thrown when passing the second argument on Safari
  3703. self.ws.send(data);
  3704. } else {
  3705. self.ws.send(data, opts);
  3706. }
  3707. } catch (e) {
  3708. debug('websocket closed before onclose event');
  3709. }
  3710. --total || done();
  3711. });
  3712. })(packets[i]);
  3713. }
  3714. function done() {
  3715. self.emit('flush');
  3716. // fake drain
  3717. // defer to next tick to allow Socket to clear writeBuffer
  3718. setTimeout(function () {
  3719. self.writable = true;
  3720. self.emit('drain');
  3721. }, 0);
  3722. }
  3723. };
  3724. /**
  3725. * Called upon close
  3726. *
  3727. * @api private
  3728. */
  3729. WS.prototype.onClose = function () {
  3730. Transport.prototype.onClose.call(this);
  3731. };
  3732. /**
  3733. * Closes socket.
  3734. *
  3735. * @api private
  3736. */
  3737. WS.prototype.doClose = function () {
  3738. if (typeof this.ws !== 'undefined') {
  3739. this.ws.close();
  3740. }
  3741. };
  3742. /**
  3743. * Generates uri for connection.
  3744. *
  3745. * @api private
  3746. */
  3747. WS.prototype.uri = function () {
  3748. var query = this.query || {};
  3749. var schema = this.secure ? 'wss' : 'ws';
  3750. var port = '';
  3751. // avoid port if default for schema
  3752. if (this.port && ('wss' === schema && Number(this.port) !== 443 || 'ws' === schema && Number(this.port) !== 80)) {
  3753. port = ':' + this.port;
  3754. }
  3755. // append timestamp to URI
  3756. if (this.timestampRequests) {
  3757. query[this.timestampParam] = yeast();
  3758. }
  3759. // communicate binary support capabilities
  3760. if (!this.supportsBinary) {
  3761. query.b64 = 1;
  3762. }
  3763. query = parseqs.encode(query);
  3764. // prepend ? to query
  3765. if (query.length) {
  3766. query = '?' + query;
  3767. }
  3768. var ipv6 = this.hostname.indexOf(':') !== -1;
  3769. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  3770. };
  3771. /**
  3772. * Feature detection for WebSocket.
  3773. *
  3774. * @return {Boolean} whether this transport is available.
  3775. * @api public
  3776. */
  3777. WS.prototype.check = function () {
  3778. return !!WebSocket && !('__initialize' in WebSocket && this.name === WS.prototype.name);
  3779. };
  3780. /***/ },
  3781. /* 27 */
  3782. /***/ function(module, exports) {
  3783. /* (ignored) */
  3784. /***/ },
  3785. /* 28 */
  3786. /***/ function(module, exports) {
  3787. var indexOf = [].indexOf;
  3788. module.exports = function(arr, obj){
  3789. if (indexOf) return arr.indexOf(obj);
  3790. for (var i = 0; i < arr.length; ++i) {
  3791. if (arr[i] === obj) return i;
  3792. }
  3793. return -1;
  3794. };
  3795. /***/ },
  3796. /* 29 */
  3797. /***/ function(module, exports) {
  3798. /**
  3799. * Parses an URI
  3800. *
  3801. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  3802. * @api private
  3803. */
  3804. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  3805. var parts = [
  3806. 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
  3807. ];
  3808. module.exports = function parseuri(str) {
  3809. var src = str,
  3810. b = str.indexOf('['),
  3811. e = str.indexOf(']');
  3812. if (b != -1 && e != -1) {
  3813. str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
  3814. }
  3815. var m = re.exec(str || ''),
  3816. uri = {},
  3817. i = 14;
  3818. while (i--) {
  3819. uri[parts[i]] = m[i] || '';
  3820. }
  3821. if (b != -1 && e != -1) {
  3822. uri.source = src;
  3823. uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
  3824. uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
  3825. uri.ipv6uri = true;
  3826. }
  3827. return uri;
  3828. };
  3829. /***/ }
  3830. /******/ ])
  3831. });
  3832. ;