engine.io.js 109 KB

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