engine.io.js 108 KB

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