Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

engine.io.js 111KB

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