sockjs.js 145 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232
  1. /* sockjs-client v1.6.1 | http://sockjs.org | MIT license */
  2. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SockJS = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  3. (function (global){(function (){
  4. 'use strict';
  5. var transportList = require('./transport-list');
  6. module.exports = require('./main')(transportList);
  7. // TODO can't get rid of this until all servers do
  8. if ('_sockjs_onload' in global) {
  9. setTimeout(global._sockjs_onload, 1);
  10. }
  11. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12. },{"./main":14,"./transport-list":16}],2:[function(require,module,exports){
  13. 'use strict';
  14. var inherits = require('inherits')
  15. , Event = require('./event')
  16. ;
  17. function CloseEvent() {
  18. Event.call(this);
  19. this.initEvent('close', false, false);
  20. this.wasClean = false;
  21. this.code = 0;
  22. this.reason = '';
  23. }
  24. inherits(CloseEvent, Event);
  25. module.exports = CloseEvent;
  26. },{"./event":4,"inherits":57}],3:[function(require,module,exports){
  27. 'use strict';
  28. var inherits = require('inherits')
  29. , EventTarget = require('./eventtarget')
  30. ;
  31. function EventEmitter() {
  32. EventTarget.call(this);
  33. }
  34. inherits(EventEmitter, EventTarget);
  35. EventEmitter.prototype.removeAllListeners = function(type) {
  36. if (type) {
  37. delete this._listeners[type];
  38. } else {
  39. this._listeners = {};
  40. }
  41. };
  42. EventEmitter.prototype.once = function(type, listener) {
  43. var self = this
  44. , fired = false;
  45. function g() {
  46. self.removeListener(type, g);
  47. if (!fired) {
  48. fired = true;
  49. listener.apply(this, arguments);
  50. }
  51. }
  52. this.on(type, g);
  53. };
  54. EventEmitter.prototype.emit = function() {
  55. var type = arguments[0];
  56. var listeners = this._listeners[type];
  57. if (!listeners) {
  58. return;
  59. }
  60. // equivalent of Array.prototype.slice.call(arguments, 1);
  61. var l = arguments.length;
  62. var args = new Array(l - 1);
  63. for (var ai = 1; ai < l; ai++) {
  64. args[ai - 1] = arguments[ai];
  65. }
  66. for (var i = 0; i < listeners.length; i++) {
  67. listeners[i].apply(this, args);
  68. }
  69. };
  70. EventEmitter.prototype.on = EventEmitter.prototype.addListener = EventTarget.prototype.addEventListener;
  71. EventEmitter.prototype.removeListener = EventTarget.prototype.removeEventListener;
  72. module.exports.EventEmitter = EventEmitter;
  73. },{"./eventtarget":5,"inherits":57}],4:[function(require,module,exports){
  74. 'use strict';
  75. function Event(eventType) {
  76. this.type = eventType;
  77. }
  78. Event.prototype.initEvent = function(eventType, canBubble, cancelable) {
  79. this.type = eventType;
  80. this.bubbles = canBubble;
  81. this.cancelable = cancelable;
  82. this.timeStamp = +new Date();
  83. return this;
  84. };
  85. Event.prototype.stopPropagation = function() {};
  86. Event.prototype.preventDefault = function() {};
  87. Event.CAPTURING_PHASE = 1;
  88. Event.AT_TARGET = 2;
  89. Event.BUBBLING_PHASE = 3;
  90. module.exports = Event;
  91. },{}],5:[function(require,module,exports){
  92. 'use strict';
  93. /* Simplified implementation of DOM2 EventTarget.
  94. * http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget
  95. */
  96. function EventTarget() {
  97. this._listeners = {};
  98. }
  99. EventTarget.prototype.addEventListener = function(eventType, listener) {
  100. if (!(eventType in this._listeners)) {
  101. this._listeners[eventType] = [];
  102. }
  103. var arr = this._listeners[eventType];
  104. // #4
  105. if (arr.indexOf(listener) === -1) {
  106. // Make a copy so as not to interfere with a current dispatchEvent.
  107. arr = arr.concat([listener]);
  108. }
  109. this._listeners[eventType] = arr;
  110. };
  111. EventTarget.prototype.removeEventListener = function(eventType, listener) {
  112. var arr = this._listeners[eventType];
  113. if (!arr) {
  114. return;
  115. }
  116. var idx = arr.indexOf(listener);
  117. if (idx !== -1) {
  118. if (arr.length > 1) {
  119. // Make a copy so as not to interfere with a current dispatchEvent.
  120. this._listeners[eventType] = arr.slice(0, idx).concat(arr.slice(idx + 1));
  121. } else {
  122. delete this._listeners[eventType];
  123. }
  124. return;
  125. }
  126. };
  127. EventTarget.prototype.dispatchEvent = function() {
  128. var event = arguments[0];
  129. var t = event.type;
  130. // equivalent of Array.prototype.slice.call(arguments, 0);
  131. var args = arguments.length === 1 ? [event] : Array.apply(null, arguments);
  132. // TODO: This doesn't match the real behavior; per spec, onfoo get
  133. // their place in line from the /first/ time they're set from
  134. // non-null. Although WebKit bumps it to the end every time it's
  135. // set.
  136. if (this['on' + t]) {
  137. this['on' + t].apply(this, args);
  138. }
  139. if (t in this._listeners) {
  140. // Grab a reference to the listeners list. removeEventListener may alter the list.
  141. var listeners = this._listeners[t];
  142. for (var i = 0; i < listeners.length; i++) {
  143. listeners[i].apply(this, args);
  144. }
  145. }
  146. };
  147. module.exports = EventTarget;
  148. },{}],6:[function(require,module,exports){
  149. 'use strict';
  150. var inherits = require('inherits')
  151. , Event = require('./event')
  152. ;
  153. function TransportMessageEvent(data) {
  154. Event.call(this);
  155. this.initEvent('message', false, false);
  156. this.data = data;
  157. }
  158. inherits(TransportMessageEvent, Event);
  159. module.exports = TransportMessageEvent;
  160. },{"./event":4,"inherits":57}],7:[function(require,module,exports){
  161. 'use strict';
  162. var iframeUtils = require('./utils/iframe')
  163. ;
  164. function FacadeJS(transport) {
  165. this._transport = transport;
  166. transport.on('message', this._transportMessage.bind(this));
  167. transport.on('close', this._transportClose.bind(this));
  168. }
  169. FacadeJS.prototype._transportClose = function(code, reason) {
  170. iframeUtils.postMessage('c', JSON.stringify([code, reason]));
  171. };
  172. FacadeJS.prototype._transportMessage = function(frame) {
  173. iframeUtils.postMessage('t', frame);
  174. };
  175. FacadeJS.prototype._send = function(data) {
  176. this._transport.send(data);
  177. };
  178. FacadeJS.prototype._close = function() {
  179. this._transport.close();
  180. this._transport.removeAllListeners();
  181. };
  182. module.exports = FacadeJS;
  183. },{"./utils/iframe":47}],8:[function(require,module,exports){
  184. (function (process){(function (){
  185. 'use strict';
  186. var urlUtils = require('./utils/url')
  187. , eventUtils = require('./utils/event')
  188. , FacadeJS = require('./facade')
  189. , InfoIframeReceiver = require('./info-iframe-receiver')
  190. , iframeUtils = require('./utils/iframe')
  191. , loc = require('./location')
  192. ;
  193. var debug = function() {};
  194. if (process.env.NODE_ENV !== 'production') {
  195. debug = require('debug')('sockjs-client:iframe-bootstrap');
  196. }
  197. module.exports = function(SockJS, availableTransports) {
  198. var transportMap = {};
  199. availableTransports.forEach(function(at) {
  200. if (at.facadeTransport) {
  201. transportMap[at.facadeTransport.transportName] = at.facadeTransport;
  202. }
  203. });
  204. // hard-coded for the info iframe
  205. // TODO see if we can make this more dynamic
  206. transportMap[InfoIframeReceiver.transportName] = InfoIframeReceiver;
  207. var parentOrigin;
  208. /* eslint-disable camelcase */
  209. SockJS.bootstrap_iframe = function() {
  210. /* eslint-enable camelcase */
  211. var facade;
  212. iframeUtils.currentWindowId = loc.hash.slice(1);
  213. var onMessage = function(e) {
  214. if (e.source !== parent) {
  215. return;
  216. }
  217. if (typeof parentOrigin === 'undefined') {
  218. parentOrigin = e.origin;
  219. }
  220. if (e.origin !== parentOrigin) {
  221. return;
  222. }
  223. var iframeMessage;
  224. try {
  225. iframeMessage = JSON.parse(e.data);
  226. } catch (ignored) {
  227. debug('bad json', e.data);
  228. return;
  229. }
  230. if (iframeMessage.windowId !== iframeUtils.currentWindowId) {
  231. return;
  232. }
  233. switch (iframeMessage.type) {
  234. case 's':
  235. var p;
  236. try {
  237. p = JSON.parse(iframeMessage.data);
  238. } catch (ignored) {
  239. debug('bad json', iframeMessage.data);
  240. break;
  241. }
  242. var version = p[0];
  243. var transport = p[1];
  244. var transUrl = p[2];
  245. var baseUrl = p[3];
  246. debug(version, transport, transUrl, baseUrl);
  247. // change this to semver logic
  248. if (version !== SockJS.version) {
  249. throw new Error('Incompatible SockJS! Main site uses:' +
  250. ' "' + version + '", the iframe:' +
  251. ' "' + SockJS.version + '".');
  252. }
  253. if (!urlUtils.isOriginEqual(transUrl, loc.href) ||
  254. !urlUtils.isOriginEqual(baseUrl, loc.href)) {
  255. throw new Error('Can\'t connect to different domain from within an ' +
  256. 'iframe. (' + loc.href + ', ' + transUrl + ', ' + baseUrl + ')');
  257. }
  258. facade = new FacadeJS(new transportMap[transport](transUrl, baseUrl));
  259. break;
  260. case 'm':
  261. facade._send(iframeMessage.data);
  262. break;
  263. case 'c':
  264. if (facade) {
  265. facade._close();
  266. }
  267. facade = null;
  268. break;
  269. }
  270. };
  271. eventUtils.attachEvent('message', onMessage);
  272. // Start
  273. iframeUtils.postMessage('s');
  274. };
  275. };
  276. }).call(this)}).call(this,{ env: {} })
  277. },{"./facade":7,"./info-iframe-receiver":10,"./location":13,"./utils/event":46,"./utils/iframe":47,"./utils/url":52,"debug":55}],9:[function(require,module,exports){
  278. (function (process){(function (){
  279. 'use strict';
  280. var EventEmitter = require('events').EventEmitter
  281. , inherits = require('inherits')
  282. , objectUtils = require('./utils/object')
  283. ;
  284. var debug = function() {};
  285. if (process.env.NODE_ENV !== 'production') {
  286. debug = require('debug')('sockjs-client:info-ajax');
  287. }
  288. function InfoAjax(url, AjaxObject) {
  289. EventEmitter.call(this);
  290. var self = this;
  291. var t0 = +new Date();
  292. this.xo = new AjaxObject('GET', url);
  293. this.xo.once('finish', function(status, text) {
  294. var info, rtt;
  295. if (status === 200) {
  296. rtt = (+new Date()) - t0;
  297. if (text) {
  298. try {
  299. info = JSON.parse(text);
  300. } catch (e) {
  301. debug('bad json', text);
  302. }
  303. }
  304. if (!objectUtils.isObject(info)) {
  305. info = {};
  306. }
  307. }
  308. self.emit('finish', info, rtt);
  309. self.removeAllListeners();
  310. });
  311. }
  312. inherits(InfoAjax, EventEmitter);
  313. InfoAjax.prototype.close = function() {
  314. this.removeAllListeners();
  315. this.xo.close();
  316. };
  317. module.exports = InfoAjax;
  318. }).call(this)}).call(this,{ env: {} })
  319. },{"./utils/object":49,"debug":55,"events":3,"inherits":57}],10:[function(require,module,exports){
  320. 'use strict';
  321. var inherits = require('inherits')
  322. , EventEmitter = require('events').EventEmitter
  323. , XHRLocalObject = require('./transport/sender/xhr-local')
  324. , InfoAjax = require('./info-ajax')
  325. ;
  326. function InfoReceiverIframe(transUrl) {
  327. var self = this;
  328. EventEmitter.call(this);
  329. this.ir = new InfoAjax(transUrl, XHRLocalObject);
  330. this.ir.once('finish', function(info, rtt) {
  331. self.ir = null;
  332. self.emit('message', JSON.stringify([info, rtt]));
  333. });
  334. }
  335. inherits(InfoReceiverIframe, EventEmitter);
  336. InfoReceiverIframe.transportName = 'iframe-info-receiver';
  337. InfoReceiverIframe.prototype.close = function() {
  338. if (this.ir) {
  339. this.ir.close();
  340. this.ir = null;
  341. }
  342. this.removeAllListeners();
  343. };
  344. module.exports = InfoReceiverIframe;
  345. },{"./info-ajax":9,"./transport/sender/xhr-local":37,"events":3,"inherits":57}],11:[function(require,module,exports){
  346. (function (process,global){(function (){
  347. 'use strict';
  348. var EventEmitter = require('events').EventEmitter
  349. , inherits = require('inherits')
  350. , utils = require('./utils/event')
  351. , IframeTransport = require('./transport/iframe')
  352. , InfoReceiverIframe = require('./info-iframe-receiver')
  353. ;
  354. var debug = function() {};
  355. if (process.env.NODE_ENV !== 'production') {
  356. debug = require('debug')('sockjs-client:info-iframe');
  357. }
  358. function InfoIframe(baseUrl, url) {
  359. var self = this;
  360. EventEmitter.call(this);
  361. var go = function() {
  362. var ifr = self.ifr = new IframeTransport(InfoReceiverIframe.transportName, url, baseUrl);
  363. ifr.once('message', function(msg) {
  364. if (msg) {
  365. var d;
  366. try {
  367. d = JSON.parse(msg);
  368. } catch (e) {
  369. debug('bad json', msg);
  370. self.emit('finish');
  371. self.close();
  372. return;
  373. }
  374. var info = d[0], rtt = d[1];
  375. self.emit('finish', info, rtt);
  376. }
  377. self.close();
  378. });
  379. ifr.once('close', function() {
  380. self.emit('finish');
  381. self.close();
  382. });
  383. };
  384. // TODO this seems the same as the 'needBody' from transports
  385. if (!global.document.body) {
  386. utils.attachEvent('load', go);
  387. } else {
  388. go();
  389. }
  390. }
  391. inherits(InfoIframe, EventEmitter);
  392. InfoIframe.enabled = function() {
  393. return IframeTransport.enabled();
  394. };
  395. InfoIframe.prototype.close = function() {
  396. if (this.ifr) {
  397. this.ifr.close();
  398. }
  399. this.removeAllListeners();
  400. this.ifr = null;
  401. };
  402. module.exports = InfoIframe;
  403. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  404. },{"./info-iframe-receiver":10,"./transport/iframe":22,"./utils/event":46,"debug":55,"events":3,"inherits":57}],12:[function(require,module,exports){
  405. (function (process){(function (){
  406. 'use strict';
  407. var EventEmitter = require('events').EventEmitter
  408. , inherits = require('inherits')
  409. , urlUtils = require('./utils/url')
  410. , XDR = require('./transport/sender/xdr')
  411. , XHRCors = require('./transport/sender/xhr-cors')
  412. , XHRLocal = require('./transport/sender/xhr-local')
  413. , XHRFake = require('./transport/sender/xhr-fake')
  414. , InfoIframe = require('./info-iframe')
  415. , InfoAjax = require('./info-ajax')
  416. ;
  417. var debug = function() {};
  418. if (process.env.NODE_ENV !== 'production') {
  419. debug = require('debug')('sockjs-client:info-receiver');
  420. }
  421. function InfoReceiver(baseUrl, urlInfo) {
  422. debug(baseUrl);
  423. var self = this;
  424. EventEmitter.call(this);
  425. setTimeout(function() {
  426. self.doXhr(baseUrl, urlInfo);
  427. }, 0);
  428. }
  429. inherits(InfoReceiver, EventEmitter);
  430. // TODO this is currently ignoring the list of available transports and the whitelist
  431. InfoReceiver._getReceiver = function(baseUrl, url, urlInfo) {
  432. // determine method of CORS support (if needed)
  433. if (urlInfo.sameOrigin) {
  434. return new InfoAjax(url, XHRLocal);
  435. }
  436. if (XHRCors.enabled) {
  437. return new InfoAjax(url, XHRCors);
  438. }
  439. if (XDR.enabled && urlInfo.sameScheme) {
  440. return new InfoAjax(url, XDR);
  441. }
  442. if (InfoIframe.enabled()) {
  443. return new InfoIframe(baseUrl, url);
  444. }
  445. return new InfoAjax(url, XHRFake);
  446. };
  447. InfoReceiver.prototype.doXhr = function(baseUrl, urlInfo) {
  448. var self = this
  449. , url = urlUtils.addPath(baseUrl, '/info')
  450. ;
  451. debug('doXhr', url);
  452. this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo);
  453. this.timeoutRef = setTimeout(function() {
  454. debug('timeout');
  455. self._cleanup(false);
  456. self.emit('finish');
  457. }, InfoReceiver.timeout);
  458. this.xo.once('finish', function(info, rtt) {
  459. debug('finish', info, rtt);
  460. self._cleanup(true);
  461. self.emit('finish', info, rtt);
  462. });
  463. };
  464. InfoReceiver.prototype._cleanup = function(wasClean) {
  465. debug('_cleanup');
  466. clearTimeout(this.timeoutRef);
  467. this.timeoutRef = null;
  468. if (!wasClean && this.xo) {
  469. this.xo.close();
  470. }
  471. this.xo = null;
  472. };
  473. InfoReceiver.prototype.close = function() {
  474. debug('close');
  475. this.removeAllListeners();
  476. this._cleanup(false);
  477. };
  478. InfoReceiver.timeout = 8000;
  479. module.exports = InfoReceiver;
  480. }).call(this)}).call(this,{ env: {} })
  481. },{"./info-ajax":9,"./info-iframe":11,"./transport/sender/xdr":34,"./transport/sender/xhr-cors":35,"./transport/sender/xhr-fake":36,"./transport/sender/xhr-local":37,"./utils/url":52,"debug":55,"events":3,"inherits":57}],13:[function(require,module,exports){
  482. (function (global){(function (){
  483. 'use strict';
  484. module.exports = global.location || {
  485. origin: 'http://localhost:80'
  486. , protocol: 'http:'
  487. , host: 'localhost'
  488. , port: 80
  489. , href: 'http://localhost/'
  490. , hash: ''
  491. };
  492. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  493. },{}],14:[function(require,module,exports){
  494. (function (process,global){(function (){
  495. 'use strict';
  496. require('./shims');
  497. var URL = require('url-parse')
  498. , inherits = require('inherits')
  499. , random = require('./utils/random')
  500. , escape = require('./utils/escape')
  501. , urlUtils = require('./utils/url')
  502. , eventUtils = require('./utils/event')
  503. , transport = require('./utils/transport')
  504. , objectUtils = require('./utils/object')
  505. , browser = require('./utils/browser')
  506. , log = require('./utils/log')
  507. , Event = require('./event/event')
  508. , EventTarget = require('./event/eventtarget')
  509. , loc = require('./location')
  510. , CloseEvent = require('./event/close')
  511. , TransportMessageEvent = require('./event/trans-message')
  512. , InfoReceiver = require('./info-receiver')
  513. ;
  514. var debug = function() {};
  515. if (process.env.NODE_ENV !== 'production') {
  516. debug = require('debug')('sockjs-client:main');
  517. }
  518. var transports;
  519. // follow constructor steps defined at http://dev.w3.org/html5/websockets/#the-websocket-interface
  520. function SockJS(url, protocols, options) {
  521. if (!(this instanceof SockJS)) {
  522. return new SockJS(url, protocols, options);
  523. }
  524. if (arguments.length < 1) {
  525. throw new TypeError("Failed to construct 'SockJS: 1 argument required, but only 0 present");
  526. }
  527. EventTarget.call(this);
  528. this.readyState = SockJS.CONNECTING;
  529. this.extensions = '';
  530. this.protocol = '';
  531. // non-standard extension
  532. options = options || {};
  533. if (options.protocols_whitelist) {
  534. log.warn("'protocols_whitelist' is DEPRECATED. Use 'transports' instead.");
  535. }
  536. this._transportsWhitelist = options.transports;
  537. this._transportOptions = options.transportOptions || {};
  538. this._timeout = options.timeout || 0;
  539. var sessionId = options.sessionId || 8;
  540. if (typeof sessionId === 'function') {
  541. this._generateSessionId = sessionId;
  542. } else if (typeof sessionId === 'number') {
  543. this._generateSessionId = function() {
  544. return random.string(sessionId);
  545. };
  546. } else {
  547. throw new TypeError('If sessionId is used in the options, it needs to be a number or a function.');
  548. }
  549. this._server = options.server || random.numberString(1000);
  550. // Step 1 of WS spec - parse and validate the url. Issue #8
  551. var parsedUrl = new URL(url);
  552. if (!parsedUrl.host || !parsedUrl.protocol) {
  553. throw new SyntaxError("The URL '" + url + "' is invalid");
  554. } else if (parsedUrl.hash) {
  555. throw new SyntaxError('The URL must not contain a fragment');
  556. } else if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
  557. throw new SyntaxError("The URL's scheme must be either 'http:' or 'https:'. '" + parsedUrl.protocol + "' is not allowed.");
  558. }
  559. var secure = parsedUrl.protocol === 'https:';
  560. // Step 2 - don't allow secure origin with an insecure protocol
  561. if (loc.protocol === 'https:' && !secure) {
  562. // exception is 127.0.0.0/8 and ::1 urls
  563. if (!urlUtils.isLoopbackAddr(parsedUrl.hostname)) {
  564. throw new Error('SecurityError: An insecure SockJS connection may not be initiated from a page loaded over HTTPS');
  565. }
  566. }
  567. // Step 3 - check port access - no need here
  568. // Step 4 - parse protocols argument
  569. if (!protocols) {
  570. protocols = [];
  571. } else if (!Array.isArray(protocols)) {
  572. protocols = [protocols];
  573. }
  574. // Step 5 - check protocols argument
  575. var sortedProtocols = protocols.sort();
  576. sortedProtocols.forEach(function(proto, i) {
  577. if (!proto) {
  578. throw new SyntaxError("The protocols entry '" + proto + "' is invalid.");
  579. }
  580. if (i < (sortedProtocols.length - 1) && proto === sortedProtocols[i + 1]) {
  581. throw new SyntaxError("The protocols entry '" + proto + "' is duplicated.");
  582. }
  583. });
  584. // Step 6 - convert origin
  585. var o = urlUtils.getOrigin(loc.href);
  586. this._origin = o ? o.toLowerCase() : null;
  587. // remove the trailing slash
  588. parsedUrl.set('pathname', parsedUrl.pathname.replace(/\/+$/, ''));
  589. // store the sanitized url
  590. this.url = parsedUrl.href;
  591. debug('using url', this.url);
  592. // Step 7 - start connection in background
  593. // obtain server info
  594. // http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-26
  595. this._urlInfo = {
  596. nullOrigin: !browser.hasDomain()
  597. , sameOrigin: urlUtils.isOriginEqual(this.url, loc.href)
  598. , sameScheme: urlUtils.isSchemeEqual(this.url, loc.href)
  599. };
  600. this._ir = new InfoReceiver(this.url, this._urlInfo);
  601. this._ir.once('finish', this._receiveInfo.bind(this));
  602. }
  603. inherits(SockJS, EventTarget);
  604. function userSetCode(code) {
  605. return code === 1000 || (code >= 3000 && code <= 4999);
  606. }
  607. SockJS.prototype.close = function(code, reason) {
  608. // Step 1
  609. if (code && !userSetCode(code)) {
  610. throw new Error('InvalidAccessError: Invalid code');
  611. }
  612. // Step 2.4 states the max is 123 bytes, but we are just checking length
  613. if (reason && reason.length > 123) {
  614. throw new SyntaxError('reason argument has an invalid length');
  615. }
  616. // Step 3.1
  617. if (this.readyState === SockJS.CLOSING || this.readyState === SockJS.CLOSED) {
  618. return;
  619. }
  620. // TODO look at docs to determine how to set this
  621. var wasClean = true;
  622. this._close(code || 1000, reason || 'Normal closure', wasClean);
  623. };
  624. SockJS.prototype.send = function(data) {
  625. // #13 - convert anything non-string to string
  626. // TODO this currently turns objects into [object Object]
  627. if (typeof data !== 'string') {
  628. data = '' + data;
  629. }
  630. if (this.readyState === SockJS.CONNECTING) {
  631. throw new Error('InvalidStateError: The connection has not been established yet');
  632. }
  633. if (this.readyState !== SockJS.OPEN) {
  634. return;
  635. }
  636. this._transport.send(escape.quote(data));
  637. };
  638. SockJS.version = require('./version');
  639. SockJS.CONNECTING = 0;
  640. SockJS.OPEN = 1;
  641. SockJS.CLOSING = 2;
  642. SockJS.CLOSED = 3;
  643. SockJS.prototype._receiveInfo = function(info, rtt) {
  644. debug('_receiveInfo', rtt);
  645. this._ir = null;
  646. if (!info) {
  647. this._close(1002, 'Cannot connect to server');
  648. return;
  649. }
  650. // establish a round-trip timeout (RTO) based on the
  651. // round-trip time (RTT)
  652. this._rto = this.countRTO(rtt);
  653. // allow server to override url used for the actual transport
  654. this._transUrl = info.base_url ? info.base_url : this.url;
  655. info = objectUtils.extend(info, this._urlInfo);
  656. debug('info', info);
  657. // determine list of desired and supported transports
  658. var enabledTransports = transports.filterToEnabled(this._transportsWhitelist, info);
  659. this._transports = enabledTransports.main;
  660. debug(this._transports.length + ' enabled transports');
  661. this._connect();
  662. };
  663. SockJS.prototype._connect = function() {
  664. for (var Transport = this._transports.shift(); Transport; Transport = this._transports.shift()) {
  665. debug('attempt', Transport.transportName);
  666. if (Transport.needBody) {
  667. if (!global.document.body ||
  668. (typeof global.document.readyState !== 'undefined' &&
  669. global.document.readyState !== 'complete' &&
  670. global.document.readyState !== 'interactive')) {
  671. debug('waiting for body');
  672. this._transports.unshift(Transport);
  673. eventUtils.attachEvent('load', this._connect.bind(this));
  674. return;
  675. }
  676. }
  677. // calculate timeout based on RTO and round trips. Default to 5s
  678. var timeoutMs = Math.max(this._timeout, (this._rto * Transport.roundTrips) || 5000);
  679. this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs);
  680. debug('using timeout', timeoutMs);
  681. var transportUrl = urlUtils.addPath(this._transUrl, '/' + this._server + '/' + this._generateSessionId());
  682. var options = this._transportOptions[Transport.transportName];
  683. debug('transport url', transportUrl);
  684. var transportObj = new Transport(transportUrl, this._transUrl, options);
  685. transportObj.on('message', this._transportMessage.bind(this));
  686. transportObj.once('close', this._transportClose.bind(this));
  687. transportObj.transportName = Transport.transportName;
  688. this._transport = transportObj;
  689. return;
  690. }
  691. this._close(2000, 'All transports failed', false);
  692. };
  693. SockJS.prototype._transportTimeout = function() {
  694. debug('_transportTimeout');
  695. if (this.readyState === SockJS.CONNECTING) {
  696. if (this._transport) {
  697. this._transport.close();
  698. }
  699. this._transportClose(2007, 'Transport timed out');
  700. }
  701. };
  702. SockJS.prototype._transportMessage = function(msg) {
  703. debug('_transportMessage', msg);
  704. var self = this
  705. , type = msg.slice(0, 1)
  706. , content = msg.slice(1)
  707. , payload
  708. ;
  709. // first check for messages that don't need a payload
  710. switch (type) {
  711. case 'o':
  712. this._open();
  713. return;
  714. case 'h':
  715. this.dispatchEvent(new Event('heartbeat'));
  716. debug('heartbeat', this.transport);
  717. return;
  718. }
  719. if (content) {
  720. try {
  721. payload = JSON.parse(content);
  722. } catch (e) {
  723. debug('bad json', content);
  724. }
  725. }
  726. if (typeof payload === 'undefined') {
  727. debug('empty payload', content);
  728. return;
  729. }
  730. switch (type) {
  731. case 'a':
  732. if (Array.isArray(payload)) {
  733. payload.forEach(function(p) {
  734. debug('message', self.transport, p);
  735. self.dispatchEvent(new TransportMessageEvent(p));
  736. });
  737. }
  738. break;
  739. case 'm':
  740. debug('message', this.transport, payload);
  741. this.dispatchEvent(new TransportMessageEvent(payload));
  742. break;
  743. case 'c':
  744. if (Array.isArray(payload) && payload.length === 2) {
  745. this._close(payload[0], payload[1], true);
  746. }
  747. break;
  748. }
  749. };
  750. SockJS.prototype._transportClose = function(code, reason) {
  751. debug('_transportClose', this.transport, code, reason);
  752. if (this._transport) {
  753. this._transport.removeAllListeners();
  754. this._transport = null;
  755. this.transport = null;
  756. }
  757. if (!userSetCode(code) && code !== 2000 && this.readyState === SockJS.CONNECTING) {
  758. this._connect();
  759. return;
  760. }
  761. this._close(code, reason);
  762. };
  763. SockJS.prototype._open = function() {
  764. debug('_open', this._transport && this._transport.transportName, this.readyState);
  765. if (this.readyState === SockJS.CONNECTING) {
  766. if (this._transportTimeoutId) {
  767. clearTimeout(this._transportTimeoutId);
  768. this._transportTimeoutId = null;
  769. }
  770. this.readyState = SockJS.OPEN;
  771. this.transport = this._transport.transportName;
  772. this.dispatchEvent(new Event('open'));
  773. debug('connected', this.transport);
  774. } else {
  775. // The server might have been restarted, and lost track of our
  776. // connection.
  777. this._close(1006, 'Server lost session');
  778. }
  779. };
  780. SockJS.prototype._close = function(code, reason, wasClean) {
  781. debug('_close', this.transport, code, reason, wasClean, this.readyState);
  782. var forceFail = false;
  783. if (this._ir) {
  784. forceFail = true;
  785. this._ir.close();
  786. this._ir = null;
  787. }
  788. if (this._transport) {
  789. this._transport.close();
  790. this._transport = null;
  791. this.transport = null;
  792. }
  793. if (this.readyState === SockJS.CLOSED) {
  794. throw new Error('InvalidStateError: SockJS has already been closed');
  795. }
  796. this.readyState = SockJS.CLOSING;
  797. setTimeout(function() {
  798. this.readyState = SockJS.CLOSED;
  799. if (forceFail) {
  800. this.dispatchEvent(new Event('error'));
  801. }
  802. var e = new CloseEvent('close');
  803. e.wasClean = wasClean || false;
  804. e.code = code || 1000;
  805. e.reason = reason;
  806. this.dispatchEvent(e);
  807. this.onmessage = this.onclose = this.onerror = null;
  808. debug('disconnected');
  809. }.bind(this), 0);
  810. };
  811. // See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/
  812. // and RFC 2988.
  813. SockJS.prototype.countRTO = function(rtt) {
  814. // In a local environment, when using IE8/9 and the `jsonp-polling`
  815. // transport the time needed to establish a connection (the time that pass
  816. // from the opening of the transport to the call of `_dispatchOpen`) is
  817. // around 200msec (the lower bound used in the article above) and this
  818. // causes spurious timeouts. For this reason we calculate a value slightly
  819. // larger than that used in the article.
  820. if (rtt > 100) {
  821. return 4 * rtt; // rto > 400msec
  822. }
  823. return 300 + rtt; // 300msec < rto <= 400msec
  824. };
  825. module.exports = function(availableTransports) {
  826. transports = transport(availableTransports);
  827. require('./iframe-bootstrap')(SockJS, availableTransports);
  828. return SockJS;
  829. };
  830. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  831. },{"./event/close":2,"./event/event":4,"./event/eventtarget":5,"./event/trans-message":6,"./iframe-bootstrap":8,"./info-receiver":12,"./location":13,"./shims":15,"./utils/browser":44,"./utils/escape":45,"./utils/event":46,"./utils/log":48,"./utils/object":49,"./utils/random":50,"./utils/transport":51,"./utils/url":52,"./version":53,"debug":55,"inherits":57,"url-parse":60}],15:[function(require,module,exports){
  832. /* eslint-disable */
  833. /* jscs: disable */
  834. 'use strict';
  835. // pulled specific shims from https://github.com/es-shims/es5-shim
  836. var ArrayPrototype = Array.prototype;
  837. var ObjectPrototype = Object.prototype;
  838. var FunctionPrototype = Function.prototype;
  839. var StringPrototype = String.prototype;
  840. var array_slice = ArrayPrototype.slice;
  841. var _toString = ObjectPrototype.toString;
  842. var isFunction = function (val) {
  843. return ObjectPrototype.toString.call(val) === '[object Function]';
  844. };
  845. var isArray = function isArray(obj) {
  846. return _toString.call(obj) === '[object Array]';
  847. };
  848. var isString = function isString(obj) {
  849. return _toString.call(obj) === '[object String]';
  850. };
  851. var supportsDescriptors = Object.defineProperty && (function () {
  852. try {
  853. Object.defineProperty({}, 'x', {});
  854. return true;
  855. } catch (e) { /* this is ES3 */
  856. return false;
  857. }
  858. }());
  859. // Define configurable, writable and non-enumerable props
  860. // if they don't exist.
  861. var defineProperty;
  862. if (supportsDescriptors) {
  863. defineProperty = function (object, name, method, forceAssign) {
  864. if (!forceAssign && (name in object)) { return; }
  865. Object.defineProperty(object, name, {
  866. configurable: true,
  867. enumerable: false,
  868. writable: true,
  869. value: method
  870. });
  871. };
  872. } else {
  873. defineProperty = function (object, name, method, forceAssign) {
  874. if (!forceAssign && (name in object)) { return; }
  875. object[name] = method;
  876. };
  877. }
  878. var defineProperties = function (object, map, forceAssign) {
  879. for (var name in map) {
  880. if (ObjectPrototype.hasOwnProperty.call(map, name)) {
  881. defineProperty(object, name, map[name], forceAssign);
  882. }
  883. }
  884. };
  885. var toObject = function (o) {
  886. if (o == null) { // this matches both null and undefined
  887. throw new TypeError("can't convert " + o + ' to object');
  888. }
  889. return Object(o);
  890. };
  891. //
  892. // Util
  893. // ======
  894. //
  895. // ES5 9.4
  896. // http://es5.github.com/#x9.4
  897. // http://jsperf.com/to-integer
  898. function toInteger(num) {
  899. var n = +num;
  900. if (n !== n) { // isNaN
  901. n = 0;
  902. } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
  903. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  904. }
  905. return n;
  906. }
  907. function ToUint32(x) {
  908. return x >>> 0;
  909. }
  910. //
  911. // Function
  912. // ========
  913. //
  914. // ES-5 15.3.4.5
  915. // http://es5.github.com/#x15.3.4.5
  916. function Empty() {}
  917. defineProperties(FunctionPrototype, {
  918. bind: function bind(that) { // .length is 1
  919. // 1. Let Target be the this value.
  920. var target = this;
  921. // 2. If IsCallable(Target) is false, throw a TypeError exception.
  922. if (!isFunction(target)) {
  923. throw new TypeError('Function.prototype.bind called on incompatible ' + target);
  924. }
  925. // 3. Let A be a new (possibly empty) internal list of all of the
  926. // argument values provided after thisArg (arg1, arg2 etc), in order.
  927. // XXX slicedArgs will stand in for "A" if used
  928. var args = array_slice.call(arguments, 1); // for normal call
  929. // 4. Let F be a new native ECMAScript object.
  930. // 11. Set the [[Prototype]] internal property of F to the standard
  931. // built-in Function prototype object as specified in 15.3.3.1.
  932. // 12. Set the [[Call]] internal property of F as described in
  933. // 15.3.4.5.1.
  934. // 13. Set the [[Construct]] internal property of F as described in
  935. // 15.3.4.5.2.
  936. // 14. Set the [[HasInstance]] internal property of F as described in
  937. // 15.3.4.5.3.
  938. var binder = function () {
  939. if (this instanceof bound) {
  940. // 15.3.4.5.2 [[Construct]]
  941. // When the [[Construct]] internal method of a function object,
  942. // F that was created using the bind function is called with a
  943. // list of arguments ExtraArgs, the following steps are taken:
  944. // 1. Let target be the value of F's [[TargetFunction]]
  945. // internal property.
  946. // 2. If target has no [[Construct]] internal method, a
  947. // TypeError exception is thrown.
  948. // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
  949. // property.
  950. // 4. Let args be a new list containing the same values as the
  951. // list boundArgs in the same order followed by the same
  952. // values as the list ExtraArgs in the same order.
  953. // 5. Return the result of calling the [[Construct]] internal
  954. // method of target providing args as the arguments.
  955. var result = target.apply(
  956. this,
  957. args.concat(array_slice.call(arguments))
  958. );
  959. if (Object(result) === result) {
  960. return result;
  961. }
  962. return this;
  963. } else {
  964. // 15.3.4.5.1 [[Call]]
  965. // When the [[Call]] internal method of a function object, F,
  966. // which was created using the bind function is called with a
  967. // this value and a list of arguments ExtraArgs, the following
  968. // steps are taken:
  969. // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
  970. // property.
  971. // 2. Let boundThis be the value of F's [[BoundThis]] internal
  972. // property.
  973. // 3. Let target be the value of F's [[TargetFunction]] internal
  974. // property.
  975. // 4. Let args be a new list containing the same values as the
  976. // list boundArgs in the same order followed by the same
  977. // values as the list ExtraArgs in the same order.
  978. // 5. Return the result of calling the [[Call]] internal method
  979. // of target providing boundThis as the this value and
  980. // providing args as the arguments.
  981. // equiv: target.call(this, ...boundArgs, ...args)
  982. return target.apply(
  983. that,
  984. args.concat(array_slice.call(arguments))
  985. );
  986. }
  987. };
  988. // 15. If the [[Class]] internal property of Target is "Function", then
  989. // a. Let L be the length property of Target minus the length of A.
  990. // b. Set the length own property of F to either 0 or L, whichever is
  991. // larger.
  992. // 16. Else set the length own property of F to 0.
  993. var boundLength = Math.max(0, target.length - args.length);
  994. // 17. Set the attributes of the length own property of F to the values
  995. // specified in 15.3.5.1.
  996. var boundArgs = [];
  997. for (var i = 0; i < boundLength; i++) {
  998. boundArgs.push('$' + i);
  999. }
  1000. // XXX Build a dynamic function with desired amount of arguments is the only
  1001. // way to set the length property of a function.
  1002. // In environments where Content Security Policies enabled (Chrome extensions,
  1003. // for ex.) all use of eval or Function costructor throws an exception.
  1004. // However in all of these environments Function.prototype.bind exists
  1005. // and so this code will never be executed.
  1006. var bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
  1007. if (target.prototype) {
  1008. Empty.prototype = target.prototype;
  1009. bound.prototype = new Empty();
  1010. // Clean up dangling references.
  1011. Empty.prototype = null;
  1012. }
  1013. // TODO
  1014. // 18. Set the [[Extensible]] internal property of F to true.
  1015. // TODO
  1016. // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
  1017. // 20. Call the [[DefineOwnProperty]] internal method of F with
  1018. // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
  1019. // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
  1020. // false.
  1021. // 21. Call the [[DefineOwnProperty]] internal method of F with
  1022. // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
  1023. // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
  1024. // and false.
  1025. // TODO
  1026. // NOTE Function objects created using Function.prototype.bind do not
  1027. // have a prototype property or the [[Code]], [[FormalParameters]], and
  1028. // [[Scope]] internal properties.
  1029. // XXX can't delete prototype in pure-js.
  1030. // 22. Return F.
  1031. return bound;
  1032. }
  1033. });
  1034. //
  1035. // Array
  1036. // =====
  1037. //
  1038. // ES5 15.4.3.2
  1039. // http://es5.github.com/#x15.4.3.2
  1040. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
  1041. defineProperties(Array, { isArray: isArray });
  1042. var boxedString = Object('a');
  1043. var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
  1044. var properlyBoxesContext = function properlyBoxed(method) {
  1045. // Check node 0.6.21 bug where third parameter is not boxed
  1046. var properlyBoxesNonStrict = true;
  1047. var properlyBoxesStrict = true;
  1048. if (method) {
  1049. method.call('foo', function (_, __, context) {
  1050. if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
  1051. });
  1052. method.call([1], function () {
  1053. 'use strict';
  1054. properlyBoxesStrict = typeof this === 'string';
  1055. }, 'x');
  1056. }
  1057. return !!method && properlyBoxesNonStrict && properlyBoxesStrict;
  1058. };
  1059. defineProperties(ArrayPrototype, {
  1060. forEach: function forEach(fun /*, thisp*/) {
  1061. var object = toObject(this),
  1062. self = splitString && isString(this) ? this.split('') : object,
  1063. thisp = arguments[1],
  1064. i = -1,
  1065. length = self.length >>> 0;
  1066. // If no callback function or if callback is not a callable function
  1067. if (!isFunction(fun)) {
  1068. throw new TypeError(); // TODO message
  1069. }
  1070. while (++i < length) {
  1071. if (i in self) {
  1072. // Invoke the callback function with call, passing arguments:
  1073. // context, property value, property key, thisArg object
  1074. // context
  1075. fun.call(thisp, self[i], i, object);
  1076. }
  1077. }
  1078. }
  1079. }, !properlyBoxesContext(ArrayPrototype.forEach));
  1080. // ES5 15.4.4.14
  1081. // http://es5.github.com/#x15.4.4.14
  1082. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
  1083. var hasFirefox2IndexOfBug = Array.prototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
  1084. defineProperties(ArrayPrototype, {
  1085. indexOf: function indexOf(sought /*, fromIndex */ ) {
  1086. var self = splitString && isString(this) ? this.split('') : toObject(this),
  1087. length = self.length >>> 0;
  1088. if (!length) {
  1089. return -1;
  1090. }
  1091. var i = 0;
  1092. if (arguments.length > 1) {
  1093. i = toInteger(arguments[1]);
  1094. }
  1095. // handle negative indices
  1096. i = i >= 0 ? i : Math.max(0, length + i);
  1097. for (; i < length; i++) {
  1098. if (i in self && self[i] === sought) {
  1099. return i;
  1100. }
  1101. }
  1102. return -1;
  1103. }
  1104. }, hasFirefox2IndexOfBug);
  1105. //
  1106. // String
  1107. // ======
  1108. //
  1109. // ES5 15.5.4.14
  1110. // http://es5.github.com/#x15.5.4.14
  1111. // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
  1112. // Many browsers do not split properly with regular expressions or they
  1113. // do not perform the split correctly under obscure conditions.
  1114. // See http://blog.stevenlevithan.com/archives/cross-browser-split
  1115. // I've tested in many browsers and this seems to cover the deviant ones:
  1116. // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
  1117. // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
  1118. // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
  1119. // [undefined, "t", undefined, "e", ...]
  1120. // ''.split(/.?/) should be [], not [""]
  1121. // '.'.split(/()()/) should be ["."], not ["", "", "."]
  1122. var string_split = StringPrototype.split;
  1123. if (
  1124. 'ab'.split(/(?:ab)*/).length !== 2 ||
  1125. '.'.split(/(.?)(.?)/).length !== 4 ||
  1126. 'tesst'.split(/(s)*/)[1] === 't' ||
  1127. 'test'.split(/(?:)/, -1).length !== 4 ||
  1128. ''.split(/.?/).length ||
  1129. '.'.split(/()()/).length > 1
  1130. ) {
  1131. (function () {
  1132. var compliantExecNpcg = /()??/.exec('')[1] === void 0; // NPCG: nonparticipating capturing group
  1133. StringPrototype.split = function (separator, limit) {
  1134. var string = this;
  1135. if (separator === void 0 && limit === 0) {
  1136. return [];
  1137. }
  1138. // If `separator` is not a regex, use native split
  1139. if (_toString.call(separator) !== '[object RegExp]') {
  1140. return string_split.call(this, separator, limit);
  1141. }
  1142. var output = [],
  1143. flags = (separator.ignoreCase ? 'i' : '') +
  1144. (separator.multiline ? 'm' : '') +
  1145. (separator.extended ? 'x' : '') + // Proposed for ES6
  1146. (separator.sticky ? 'y' : ''), // Firefox 3+
  1147. lastLastIndex = 0,
  1148. // Make `global` and avoid `lastIndex` issues by working with a copy
  1149. separator2, match, lastIndex, lastLength;
  1150. separator = new RegExp(separator.source, flags + 'g');
  1151. string += ''; // Type-convert
  1152. if (!compliantExecNpcg) {
  1153. // Doesn't need flags gy, but they don't hurt
  1154. separator2 = new RegExp('^' + separator.source + '$(?!\\s)', flags);
  1155. }
  1156. /* Values for `limit`, per the spec:
  1157. * If undefined: 4294967295 // Math.pow(2, 32) - 1
  1158. * If 0, Infinity, or NaN: 0
  1159. * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
  1160. * If negative number: 4294967296 - Math.floor(Math.abs(limit))
  1161. * If other: Type-convert, then use the above rules
  1162. */
  1163. limit = limit === void 0 ?
  1164. -1 >>> 0 : // Math.pow(2, 32) - 1
  1165. ToUint32(limit);
  1166. while (match = separator.exec(string)) {
  1167. // `separator.lastIndex` is not reliable cross-browser
  1168. lastIndex = match.index + match[0].length;
  1169. if (lastIndex > lastLastIndex) {
  1170. output.push(string.slice(lastLastIndex, match.index));
  1171. // Fix browsers whose `exec` methods don't consistently return `undefined` for
  1172. // nonparticipating capturing groups
  1173. if (!compliantExecNpcg && match.length > 1) {
  1174. match[0].replace(separator2, function () {
  1175. for (var i = 1; i < arguments.length - 2; i++) {
  1176. if (arguments[i] === void 0) {
  1177. match[i] = void 0;
  1178. }
  1179. }
  1180. });
  1181. }
  1182. if (match.length > 1 && match.index < string.length) {
  1183. ArrayPrototype.push.apply(output, match.slice(1));
  1184. }
  1185. lastLength = match[0].length;
  1186. lastLastIndex = lastIndex;
  1187. if (output.length >= limit) {
  1188. break;
  1189. }
  1190. }
  1191. if (separator.lastIndex === match.index) {
  1192. separator.lastIndex++; // Avoid an infinite loop
  1193. }
  1194. }
  1195. if (lastLastIndex === string.length) {
  1196. if (lastLength || !separator.test('')) {
  1197. output.push('');
  1198. }
  1199. } else {
  1200. output.push(string.slice(lastLastIndex));
  1201. }
  1202. return output.length > limit ? output.slice(0, limit) : output;
  1203. };
  1204. }());
  1205. // [bugfix, chrome]
  1206. // If separator is undefined, then the result array contains just one String,
  1207. // which is the this value (converted to a String). If limit is not undefined,
  1208. // then the output array is truncated so that it contains no more than limit
  1209. // elements.
  1210. // "0".split(undefined, 0) -> []
  1211. } else if ('0'.split(void 0, 0).length) {
  1212. StringPrototype.split = function split(separator, limit) {
  1213. if (separator === void 0 && limit === 0) { return []; }
  1214. return string_split.call(this, separator, limit);
  1215. };
  1216. }
  1217. // ECMA-262, 3rd B.2.3
  1218. // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
  1219. // non-normative section suggesting uniform semantics and it should be
  1220. // normalized across all browsers
  1221. // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
  1222. var string_substr = StringPrototype.substr;
  1223. var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
  1224. defineProperties(StringPrototype, {
  1225. substr: function substr(start, length) {
  1226. return string_substr.call(
  1227. this,
  1228. start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
  1229. length
  1230. );
  1231. }
  1232. }, hasNegativeSubstrBug);
  1233. },{}],16:[function(require,module,exports){
  1234. 'use strict';
  1235. module.exports = [
  1236. // streaming transports
  1237. require('./transport/websocket')
  1238. , require('./transport/xhr-streaming')
  1239. , require('./transport/xdr-streaming')
  1240. , require('./transport/eventsource')
  1241. , require('./transport/lib/iframe-wrap')(require('./transport/eventsource'))
  1242. // polling transports
  1243. , require('./transport/htmlfile')
  1244. , require('./transport/lib/iframe-wrap')(require('./transport/htmlfile'))
  1245. , require('./transport/xhr-polling')
  1246. , require('./transport/xdr-polling')
  1247. , require('./transport/lib/iframe-wrap')(require('./transport/xhr-polling'))
  1248. , require('./transport/jsonp-polling')
  1249. ];
  1250. },{"./transport/eventsource":20,"./transport/htmlfile":21,"./transport/jsonp-polling":23,"./transport/lib/iframe-wrap":26,"./transport/websocket":38,"./transport/xdr-polling":39,"./transport/xdr-streaming":40,"./transport/xhr-polling":41,"./transport/xhr-streaming":42}],17:[function(require,module,exports){
  1251. (function (process,global){(function (){
  1252. 'use strict';
  1253. var EventEmitter = require('events').EventEmitter
  1254. , inherits = require('inherits')
  1255. , utils = require('../../utils/event')
  1256. , urlUtils = require('../../utils/url')
  1257. , XHR = global.XMLHttpRequest
  1258. ;
  1259. var debug = function() {};
  1260. if (process.env.NODE_ENV !== 'production') {
  1261. debug = require('debug')('sockjs-client:browser:xhr');
  1262. }
  1263. function AbstractXHRObject(method, url, payload, opts) {
  1264. debug(method, url);
  1265. var self = this;
  1266. EventEmitter.call(this);
  1267. setTimeout(function () {
  1268. self._start(method, url, payload, opts);
  1269. }, 0);
  1270. }
  1271. inherits(AbstractXHRObject, EventEmitter);
  1272. AbstractXHRObject.prototype._start = function(method, url, payload, opts) {
  1273. var self = this;
  1274. try {
  1275. this.xhr = new XHR();
  1276. } catch (x) {
  1277. // intentionally empty
  1278. }
  1279. if (!this.xhr) {
  1280. debug('no xhr');
  1281. this.emit('finish', 0, 'no xhr support');
  1282. this._cleanup();
  1283. return;
  1284. }
  1285. // several browsers cache POSTs
  1286. url = urlUtils.addQuery(url, 't=' + (+new Date()));
  1287. // Explorer tends to keep connection open, even after the
  1288. // tab gets closed: http://bugs.jquery.com/ticket/5280
  1289. this.unloadRef = utils.unloadAdd(function() {
  1290. debug('unload cleanup');
  1291. self._cleanup(true);
  1292. });
  1293. try {
  1294. this.xhr.open(method, url, true);
  1295. if (this.timeout && 'timeout' in this.xhr) {
  1296. this.xhr.timeout = this.timeout;
  1297. this.xhr.ontimeout = function() {
  1298. debug('xhr timeout');
  1299. self.emit('finish', 0, '');
  1300. self._cleanup(false);
  1301. };
  1302. }
  1303. } catch (e) {
  1304. debug('exception', e);
  1305. // IE raises an exception on wrong port.
  1306. this.emit('finish', 0, '');
  1307. this._cleanup(false);
  1308. return;
  1309. }
  1310. if ((!opts || !opts.noCredentials) && AbstractXHRObject.supportsCORS) {
  1311. debug('withCredentials');
  1312. // Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
  1313. // "This never affects same-site requests."
  1314. this.xhr.withCredentials = true;
  1315. }
  1316. if (opts && opts.headers) {
  1317. for (var key in opts.headers) {
  1318. this.xhr.setRequestHeader(key, opts.headers[key]);
  1319. }
  1320. }
  1321. this.xhr.onreadystatechange = function() {
  1322. if (self.xhr) {
  1323. var x = self.xhr;
  1324. var text, status;
  1325. debug('readyState', x.readyState);
  1326. switch (x.readyState) {
  1327. case 3:
  1328. // IE doesn't like peeking into responseText or status
  1329. // on Microsoft.XMLHTTP and readystate=3
  1330. try {
  1331. status = x.status;
  1332. text = x.responseText;
  1333. } catch (e) {
  1334. // intentionally empty
  1335. }
  1336. debug('status', status);
  1337. // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
  1338. if (status === 1223) {
  1339. status = 204;
  1340. }
  1341. // IE does return readystate == 3 for 404 answers.
  1342. if (status === 200 && text && text.length > 0) {
  1343. debug('chunk');
  1344. self.emit('chunk', status, text);
  1345. }
  1346. break;
  1347. case 4:
  1348. status = x.status;
  1349. debug('status', status);
  1350. // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
  1351. if (status === 1223) {
  1352. status = 204;
  1353. }
  1354. // IE returns this for a bad port
  1355. // http://msdn.microsoft.com/en-us/library/windows/desktop/aa383770(v=vs.85).aspx
  1356. if (status === 12005 || status === 12029) {
  1357. status = 0;
  1358. }
  1359. debug('finish', status, x.responseText);
  1360. self.emit('finish', status, x.responseText);
  1361. self._cleanup(false);
  1362. break;
  1363. }
  1364. }
  1365. };
  1366. try {
  1367. self.xhr.send(payload);
  1368. } catch (e) {
  1369. self.emit('finish', 0, '');
  1370. self._cleanup(false);
  1371. }
  1372. };
  1373. AbstractXHRObject.prototype._cleanup = function(abort) {
  1374. debug('cleanup');
  1375. if (!this.xhr) {
  1376. return;
  1377. }
  1378. this.removeAllListeners();
  1379. utils.unloadDel(this.unloadRef);
  1380. // IE needs this field to be a function
  1381. this.xhr.onreadystatechange = function() {};
  1382. if (this.xhr.ontimeout) {
  1383. this.xhr.ontimeout = null;
  1384. }
  1385. if (abort) {
  1386. try {
  1387. this.xhr.abort();
  1388. } catch (x) {
  1389. // intentionally empty
  1390. }
  1391. }
  1392. this.unloadRef = this.xhr = null;
  1393. };
  1394. AbstractXHRObject.prototype.close = function() {
  1395. debug('close');
  1396. this._cleanup(true);
  1397. };
  1398. AbstractXHRObject.enabled = !!XHR;
  1399. // override XMLHttpRequest for IE6/7
  1400. // obfuscate to avoid firewalls
  1401. var axo = ['Active'].concat('Object').join('X');
  1402. if (!AbstractXHRObject.enabled && (axo in global)) {
  1403. debug('overriding xmlhttprequest');
  1404. XHR = function() {
  1405. try {
  1406. return new global[axo]('Microsoft.XMLHTTP');
  1407. } catch (e) {
  1408. return null;
  1409. }
  1410. };
  1411. AbstractXHRObject.enabled = !!new XHR();
  1412. }
  1413. var cors = false;
  1414. try {
  1415. cors = 'withCredentials' in new XHR();
  1416. } catch (ignored) {
  1417. // intentionally empty
  1418. }
  1419. AbstractXHRObject.supportsCORS = cors;
  1420. module.exports = AbstractXHRObject;
  1421. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1422. },{"../../utils/event":46,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],18:[function(require,module,exports){
  1423. (function (global){(function (){
  1424. module.exports = global.EventSource;
  1425. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1426. },{}],19:[function(require,module,exports){
  1427. (function (global){(function (){
  1428. 'use strict';
  1429. var Driver = global.WebSocket || global.MozWebSocket;
  1430. if (Driver) {
  1431. module.exports = function WebSocketBrowserDriver(url) {
  1432. return new Driver(url);
  1433. };
  1434. } else {
  1435. module.exports = undefined;
  1436. }
  1437. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1438. },{}],20:[function(require,module,exports){
  1439. 'use strict';
  1440. var inherits = require('inherits')
  1441. , AjaxBasedTransport = require('./lib/ajax-based')
  1442. , EventSourceReceiver = require('./receiver/eventsource')
  1443. , XHRCorsObject = require('./sender/xhr-cors')
  1444. , EventSourceDriver = require('eventsource')
  1445. ;
  1446. function EventSourceTransport(transUrl) {
  1447. if (!EventSourceTransport.enabled()) {
  1448. throw new Error('Transport created when disabled');
  1449. }
  1450. AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRCorsObject);
  1451. }
  1452. inherits(EventSourceTransport, AjaxBasedTransport);
  1453. EventSourceTransport.enabled = function() {
  1454. return !!EventSourceDriver;
  1455. };
  1456. EventSourceTransport.transportName = 'eventsource';
  1457. EventSourceTransport.roundTrips = 2;
  1458. module.exports = EventSourceTransport;
  1459. },{"./lib/ajax-based":24,"./receiver/eventsource":29,"./sender/xhr-cors":35,"eventsource":18,"inherits":57}],21:[function(require,module,exports){
  1460. 'use strict';
  1461. var inherits = require('inherits')
  1462. , HtmlfileReceiver = require('./receiver/htmlfile')
  1463. , XHRLocalObject = require('./sender/xhr-local')
  1464. , AjaxBasedTransport = require('./lib/ajax-based')
  1465. ;
  1466. function HtmlFileTransport(transUrl) {
  1467. if (!HtmlfileReceiver.enabled) {
  1468. throw new Error('Transport created when disabled');
  1469. }
  1470. AjaxBasedTransport.call(this, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);
  1471. }
  1472. inherits(HtmlFileTransport, AjaxBasedTransport);
  1473. HtmlFileTransport.enabled = function(info) {
  1474. return HtmlfileReceiver.enabled && info.sameOrigin;
  1475. };
  1476. HtmlFileTransport.transportName = 'htmlfile';
  1477. HtmlFileTransport.roundTrips = 2;
  1478. module.exports = HtmlFileTransport;
  1479. },{"./lib/ajax-based":24,"./receiver/htmlfile":30,"./sender/xhr-local":37,"inherits":57}],22:[function(require,module,exports){
  1480. (function (process){(function (){
  1481. 'use strict';
  1482. // Few cool transports do work only for same-origin. In order to make
  1483. // them work cross-domain we shall use iframe, served from the
  1484. // remote domain. New browsers have capabilities to communicate with
  1485. // cross domain iframe using postMessage(). In IE it was implemented
  1486. // from IE 8+, but of course, IE got some details wrong:
  1487. // http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
  1488. // http://stevesouders.com/misc/test-postmessage.php
  1489. var inherits = require('inherits')
  1490. , EventEmitter = require('events').EventEmitter
  1491. , version = require('../version')
  1492. , urlUtils = require('../utils/url')
  1493. , iframeUtils = require('../utils/iframe')
  1494. , eventUtils = require('../utils/event')
  1495. , random = require('../utils/random')
  1496. ;
  1497. var debug = function() {};
  1498. if (process.env.NODE_ENV !== 'production') {
  1499. debug = require('debug')('sockjs-client:transport:iframe');
  1500. }
  1501. function IframeTransport(transport, transUrl, baseUrl) {
  1502. if (!IframeTransport.enabled()) {
  1503. throw new Error('Transport created when disabled');
  1504. }
  1505. EventEmitter.call(this);
  1506. var self = this;
  1507. this.origin = urlUtils.getOrigin(baseUrl);
  1508. this.baseUrl = baseUrl;
  1509. this.transUrl = transUrl;
  1510. this.transport = transport;
  1511. this.windowId = random.string(8);
  1512. var iframeUrl = urlUtils.addPath(baseUrl, '/iframe.html') + '#' + this.windowId;
  1513. debug(transport, transUrl, iframeUrl);
  1514. this.iframeObj = iframeUtils.createIframe(iframeUrl, function(r) {
  1515. debug('err callback');
  1516. self.emit('close', 1006, 'Unable to load an iframe (' + r + ')');
  1517. self.close();
  1518. });
  1519. this.onmessageCallback = this._message.bind(this);
  1520. eventUtils.attachEvent('message', this.onmessageCallback);
  1521. }
  1522. inherits(IframeTransport, EventEmitter);
  1523. IframeTransport.prototype.close = function() {
  1524. debug('close');
  1525. this.removeAllListeners();
  1526. if (this.iframeObj) {
  1527. eventUtils.detachEvent('message', this.onmessageCallback);
  1528. try {
  1529. // When the iframe is not loaded, IE raises an exception
  1530. // on 'contentWindow'.
  1531. this.postMessage('c');
  1532. } catch (x) {
  1533. // intentionally empty
  1534. }
  1535. this.iframeObj.cleanup();
  1536. this.iframeObj = null;
  1537. this.onmessageCallback = this.iframeObj = null;
  1538. }
  1539. };
  1540. IframeTransport.prototype._message = function(e) {
  1541. debug('message', e.data);
  1542. if (!urlUtils.isOriginEqual(e.origin, this.origin)) {
  1543. debug('not same origin', e.origin, this.origin);
  1544. return;
  1545. }
  1546. var iframeMessage;
  1547. try {
  1548. iframeMessage = JSON.parse(e.data);
  1549. } catch (ignored) {
  1550. debug('bad json', e.data);
  1551. return;
  1552. }
  1553. if (iframeMessage.windowId !== this.windowId) {
  1554. debug('mismatched window id', iframeMessage.windowId, this.windowId);
  1555. return;
  1556. }
  1557. switch (iframeMessage.type) {
  1558. case 's':
  1559. this.iframeObj.loaded();
  1560. // window global dependency
  1561. this.postMessage('s', JSON.stringify([
  1562. version
  1563. , this.transport
  1564. , this.transUrl
  1565. , this.baseUrl
  1566. ]));
  1567. break;
  1568. case 't':
  1569. this.emit('message', iframeMessage.data);
  1570. break;
  1571. case 'c':
  1572. var cdata;
  1573. try {
  1574. cdata = JSON.parse(iframeMessage.data);
  1575. } catch (ignored) {
  1576. debug('bad json', iframeMessage.data);
  1577. return;
  1578. }
  1579. this.emit('close', cdata[0], cdata[1]);
  1580. this.close();
  1581. break;
  1582. }
  1583. };
  1584. IframeTransport.prototype.postMessage = function(type, data) {
  1585. debug('postMessage', type, data);
  1586. this.iframeObj.post(JSON.stringify({
  1587. windowId: this.windowId
  1588. , type: type
  1589. , data: data || ''
  1590. }), this.origin);
  1591. };
  1592. IframeTransport.prototype.send = function(message) {
  1593. debug('send', message);
  1594. this.postMessage('m', message);
  1595. };
  1596. IframeTransport.enabled = function() {
  1597. return iframeUtils.iframeEnabled;
  1598. };
  1599. IframeTransport.transportName = 'iframe';
  1600. IframeTransport.roundTrips = 2;
  1601. module.exports = IframeTransport;
  1602. }).call(this)}).call(this,{ env: {} })
  1603. },{"../utils/event":46,"../utils/iframe":47,"../utils/random":50,"../utils/url":52,"../version":53,"debug":55,"events":3,"inherits":57}],23:[function(require,module,exports){
  1604. (function (global){(function (){
  1605. 'use strict';
  1606. // The simplest and most robust transport, using the well-know cross
  1607. // domain hack - JSONP. This transport is quite inefficient - one
  1608. // message could use up to one http request. But at least it works almost
  1609. // everywhere.
  1610. // Known limitations:
  1611. // o you will get a spinning cursor
  1612. // o for Konqueror a dumb timer is needed to detect errors
  1613. var inherits = require('inherits')
  1614. , SenderReceiver = require('./lib/sender-receiver')
  1615. , JsonpReceiver = require('./receiver/jsonp')
  1616. , jsonpSender = require('./sender/jsonp')
  1617. ;
  1618. function JsonPTransport(transUrl) {
  1619. if (!JsonPTransport.enabled()) {
  1620. throw new Error('Transport created when disabled');
  1621. }
  1622. SenderReceiver.call(this, transUrl, '/jsonp', jsonpSender, JsonpReceiver);
  1623. }
  1624. inherits(JsonPTransport, SenderReceiver);
  1625. JsonPTransport.enabled = function() {
  1626. return !!global.document;
  1627. };
  1628. JsonPTransport.transportName = 'jsonp-polling';
  1629. JsonPTransport.roundTrips = 1;
  1630. JsonPTransport.needBody = true;
  1631. module.exports = JsonPTransport;
  1632. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1633. },{"./lib/sender-receiver":28,"./receiver/jsonp":31,"./sender/jsonp":33,"inherits":57}],24:[function(require,module,exports){
  1634. (function (process){(function (){
  1635. 'use strict';
  1636. var inherits = require('inherits')
  1637. , urlUtils = require('../../utils/url')
  1638. , SenderReceiver = require('./sender-receiver')
  1639. ;
  1640. var debug = function() {};
  1641. if (process.env.NODE_ENV !== 'production') {
  1642. debug = require('debug')('sockjs-client:ajax-based');
  1643. }
  1644. function createAjaxSender(AjaxObject) {
  1645. return function(url, payload, callback) {
  1646. debug('create ajax sender', url, payload);
  1647. var opt = {};
  1648. if (typeof payload === 'string') {
  1649. opt.headers = {'Content-type': 'text/plain'};
  1650. }
  1651. var ajaxUrl = urlUtils.addPath(url, '/xhr_send');
  1652. var xo = new AjaxObject('POST', ajaxUrl, payload, opt);
  1653. xo.once('finish', function(status) {
  1654. debug('finish', status);
  1655. xo = null;
  1656. if (status !== 200 && status !== 204) {
  1657. return callback(new Error('http status ' + status));
  1658. }
  1659. callback();
  1660. });
  1661. return function() {
  1662. debug('abort');
  1663. xo.close();
  1664. xo = null;
  1665. var err = new Error('Aborted');
  1666. err.code = 1000;
  1667. callback(err);
  1668. };
  1669. };
  1670. }
  1671. function AjaxBasedTransport(transUrl, urlSuffix, Receiver, AjaxObject) {
  1672. SenderReceiver.call(this, transUrl, urlSuffix, createAjaxSender(AjaxObject), Receiver, AjaxObject);
  1673. }
  1674. inherits(AjaxBasedTransport, SenderReceiver);
  1675. module.exports = AjaxBasedTransport;
  1676. }).call(this)}).call(this,{ env: {} })
  1677. },{"../../utils/url":52,"./sender-receiver":28,"debug":55,"inherits":57}],25:[function(require,module,exports){
  1678. (function (process){(function (){
  1679. 'use strict';
  1680. var inherits = require('inherits')
  1681. , EventEmitter = require('events').EventEmitter
  1682. ;
  1683. var debug = function() {};
  1684. if (process.env.NODE_ENV !== 'production') {
  1685. debug = require('debug')('sockjs-client:buffered-sender');
  1686. }
  1687. function BufferedSender(url, sender) {
  1688. debug(url);
  1689. EventEmitter.call(this);
  1690. this.sendBuffer = [];
  1691. this.sender = sender;
  1692. this.url = url;
  1693. }
  1694. inherits(BufferedSender, EventEmitter);
  1695. BufferedSender.prototype.send = function(message) {
  1696. debug('send', message);
  1697. this.sendBuffer.push(message);
  1698. if (!this.sendStop) {
  1699. this.sendSchedule();
  1700. }
  1701. };
  1702. // For polling transports in a situation when in the message callback,
  1703. // new message is being send. If the sending connection was started
  1704. // before receiving one, it is possible to saturate the network and
  1705. // timeout due to the lack of receiving socket. To avoid that we delay
  1706. // sending messages by some small time, in order to let receiving
  1707. // connection be started beforehand. This is only a halfmeasure and
  1708. // does not fix the big problem, but it does make the tests go more
  1709. // stable on slow networks.
  1710. BufferedSender.prototype.sendScheduleWait = function() {
  1711. debug('sendScheduleWait');
  1712. var self = this;
  1713. var tref;
  1714. this.sendStop = function() {
  1715. debug('sendStop');
  1716. self.sendStop = null;
  1717. clearTimeout(tref);
  1718. };
  1719. tref = setTimeout(function() {
  1720. debug('timeout');
  1721. self.sendStop = null;
  1722. self.sendSchedule();
  1723. }, 25);
  1724. };
  1725. BufferedSender.prototype.sendSchedule = function() {
  1726. debug('sendSchedule', this.sendBuffer.length);
  1727. var self = this;
  1728. if (this.sendBuffer.length > 0) {
  1729. var payload = '[' + this.sendBuffer.join(',') + ']';
  1730. this.sendStop = this.sender(this.url, payload, function(err) {
  1731. self.sendStop = null;
  1732. if (err) {
  1733. debug('error', err);
  1734. self.emit('close', err.code || 1006, 'Sending error: ' + err);
  1735. self.close();
  1736. } else {
  1737. self.sendScheduleWait();
  1738. }
  1739. });
  1740. this.sendBuffer = [];
  1741. }
  1742. };
  1743. BufferedSender.prototype._cleanup = function() {
  1744. debug('_cleanup');
  1745. this.removeAllListeners();
  1746. };
  1747. BufferedSender.prototype.close = function() {
  1748. debug('close');
  1749. this._cleanup();
  1750. if (this.sendStop) {
  1751. this.sendStop();
  1752. this.sendStop = null;
  1753. }
  1754. };
  1755. module.exports = BufferedSender;
  1756. }).call(this)}).call(this,{ env: {} })
  1757. },{"debug":55,"events":3,"inherits":57}],26:[function(require,module,exports){
  1758. (function (global){(function (){
  1759. 'use strict';
  1760. var inherits = require('inherits')
  1761. , IframeTransport = require('../iframe')
  1762. , objectUtils = require('../../utils/object')
  1763. ;
  1764. module.exports = function(transport) {
  1765. function IframeWrapTransport(transUrl, baseUrl) {
  1766. IframeTransport.call(this, transport.transportName, transUrl, baseUrl);
  1767. }
  1768. inherits(IframeWrapTransport, IframeTransport);
  1769. IframeWrapTransport.enabled = function(url, info) {
  1770. if (!global.document) {
  1771. return false;
  1772. }
  1773. var iframeInfo = objectUtils.extend({}, info);
  1774. iframeInfo.sameOrigin = true;
  1775. return transport.enabled(iframeInfo) && IframeTransport.enabled();
  1776. };
  1777. IframeWrapTransport.transportName = 'iframe-' + transport.transportName;
  1778. IframeWrapTransport.needBody = true;
  1779. IframeWrapTransport.roundTrips = IframeTransport.roundTrips + transport.roundTrips - 1; // html, javascript (2) + transport - no CORS (1)
  1780. IframeWrapTransport.facadeTransport = transport;
  1781. return IframeWrapTransport;
  1782. };
  1783. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1784. },{"../../utils/object":49,"../iframe":22,"inherits":57}],27:[function(require,module,exports){
  1785. (function (process){(function (){
  1786. 'use strict';
  1787. var inherits = require('inherits')
  1788. , EventEmitter = require('events').EventEmitter
  1789. ;
  1790. var debug = function() {};
  1791. if (process.env.NODE_ENV !== 'production') {
  1792. debug = require('debug')('sockjs-client:polling');
  1793. }
  1794. function Polling(Receiver, receiveUrl, AjaxObject) {
  1795. debug(receiveUrl);
  1796. EventEmitter.call(this);
  1797. this.Receiver = Receiver;
  1798. this.receiveUrl = receiveUrl;
  1799. this.AjaxObject = AjaxObject;
  1800. this._scheduleReceiver();
  1801. }
  1802. inherits(Polling, EventEmitter);
  1803. Polling.prototype._scheduleReceiver = function() {
  1804. debug('_scheduleReceiver');
  1805. var self = this;
  1806. var poll = this.poll = new this.Receiver(this.receiveUrl, this.AjaxObject);
  1807. poll.on('message', function(msg) {
  1808. debug('message', msg);
  1809. self.emit('message', msg);
  1810. });
  1811. poll.once('close', function(code, reason) {
  1812. debug('close', code, reason, self.pollIsClosing);
  1813. self.poll = poll = null;
  1814. if (!self.pollIsClosing) {
  1815. if (reason === 'network') {
  1816. self._scheduleReceiver();
  1817. } else {
  1818. self.emit('close', code || 1006, reason);
  1819. self.removeAllListeners();
  1820. }
  1821. }
  1822. });
  1823. };
  1824. Polling.prototype.abort = function() {
  1825. debug('abort');
  1826. this.removeAllListeners();
  1827. this.pollIsClosing = true;
  1828. if (this.poll) {
  1829. this.poll.abort();
  1830. }
  1831. };
  1832. module.exports = Polling;
  1833. }).call(this)}).call(this,{ env: {} })
  1834. },{"debug":55,"events":3,"inherits":57}],28:[function(require,module,exports){
  1835. (function (process){(function (){
  1836. 'use strict';
  1837. var inherits = require('inherits')
  1838. , urlUtils = require('../../utils/url')
  1839. , BufferedSender = require('./buffered-sender')
  1840. , Polling = require('./polling')
  1841. ;
  1842. var debug = function() {};
  1843. if (process.env.NODE_ENV !== 'production') {
  1844. debug = require('debug')('sockjs-client:sender-receiver');
  1845. }
  1846. function SenderReceiver(transUrl, urlSuffix, senderFunc, Receiver, AjaxObject) {
  1847. var pollUrl = urlUtils.addPath(transUrl, urlSuffix);
  1848. debug(pollUrl);
  1849. var self = this;
  1850. BufferedSender.call(this, transUrl, senderFunc);
  1851. this.poll = new Polling(Receiver, pollUrl, AjaxObject);
  1852. this.poll.on('message', function(msg) {
  1853. debug('poll message', msg);
  1854. self.emit('message', msg);
  1855. });
  1856. this.poll.once('close', function(code, reason) {
  1857. debug('poll close', code, reason);
  1858. self.poll = null;
  1859. self.emit('close', code, reason);
  1860. self.close();
  1861. });
  1862. }
  1863. inherits(SenderReceiver, BufferedSender);
  1864. SenderReceiver.prototype.close = function() {
  1865. BufferedSender.prototype.close.call(this);
  1866. debug('close');
  1867. this.removeAllListeners();
  1868. if (this.poll) {
  1869. this.poll.abort();
  1870. this.poll = null;
  1871. }
  1872. };
  1873. module.exports = SenderReceiver;
  1874. }).call(this)}).call(this,{ env: {} })
  1875. },{"../../utils/url":52,"./buffered-sender":25,"./polling":27,"debug":55,"inherits":57}],29:[function(require,module,exports){
  1876. (function (process){(function (){
  1877. 'use strict';
  1878. var inherits = require('inherits')
  1879. , EventEmitter = require('events').EventEmitter
  1880. , EventSourceDriver = require('eventsource')
  1881. ;
  1882. var debug = function() {};
  1883. if (process.env.NODE_ENV !== 'production') {
  1884. debug = require('debug')('sockjs-client:receiver:eventsource');
  1885. }
  1886. function EventSourceReceiver(url) {
  1887. debug(url);
  1888. EventEmitter.call(this);
  1889. var self = this;
  1890. var es = this.es = new EventSourceDriver(url);
  1891. es.onmessage = function(e) {
  1892. debug('message', e.data);
  1893. self.emit('message', decodeURI(e.data));
  1894. };
  1895. es.onerror = function(e) {
  1896. debug('error', es.readyState, e);
  1897. // ES on reconnection has readyState = 0 or 1.
  1898. // on network error it's CLOSED = 2
  1899. var reason = (es.readyState !== 2 ? 'network' : 'permanent');
  1900. self._cleanup();
  1901. self._close(reason);
  1902. };
  1903. }
  1904. inherits(EventSourceReceiver, EventEmitter);
  1905. EventSourceReceiver.prototype.abort = function() {
  1906. debug('abort');
  1907. this._cleanup();
  1908. this._close('user');
  1909. };
  1910. EventSourceReceiver.prototype._cleanup = function() {
  1911. debug('cleanup');
  1912. var es = this.es;
  1913. if (es) {
  1914. es.onmessage = es.onerror = null;
  1915. es.close();
  1916. this.es = null;
  1917. }
  1918. };
  1919. EventSourceReceiver.prototype._close = function(reason) {
  1920. debug('close', reason);
  1921. var self = this;
  1922. // Safari and chrome < 15 crash if we close window before
  1923. // waiting for ES cleanup. See:
  1924. // https://code.google.com/p/chromium/issues/detail?id=89155
  1925. setTimeout(function() {
  1926. self.emit('close', null, reason);
  1927. self.removeAllListeners();
  1928. }, 200);
  1929. };
  1930. module.exports = EventSourceReceiver;
  1931. }).call(this)}).call(this,{ env: {} })
  1932. },{"debug":55,"events":3,"eventsource":18,"inherits":57}],30:[function(require,module,exports){
  1933. (function (process,global){(function (){
  1934. 'use strict';
  1935. var inherits = require('inherits')
  1936. , iframeUtils = require('../../utils/iframe')
  1937. , urlUtils = require('../../utils/url')
  1938. , EventEmitter = require('events').EventEmitter
  1939. , random = require('../../utils/random')
  1940. ;
  1941. var debug = function() {};
  1942. if (process.env.NODE_ENV !== 'production') {
  1943. debug = require('debug')('sockjs-client:receiver:htmlfile');
  1944. }
  1945. function HtmlfileReceiver(url) {
  1946. debug(url);
  1947. EventEmitter.call(this);
  1948. var self = this;
  1949. iframeUtils.polluteGlobalNamespace();
  1950. this.id = 'a' + random.string(6);
  1951. url = urlUtils.addQuery(url, 'c=' + decodeURIComponent(iframeUtils.WPrefix + '.' + this.id));
  1952. debug('using htmlfile', HtmlfileReceiver.htmlfileEnabled);
  1953. var constructFunc = HtmlfileReceiver.htmlfileEnabled ?
  1954. iframeUtils.createHtmlfile : iframeUtils.createIframe;
  1955. global[iframeUtils.WPrefix][this.id] = {
  1956. start: function() {
  1957. debug('start');
  1958. self.iframeObj.loaded();
  1959. }
  1960. , message: function(data) {
  1961. debug('message', data);
  1962. self.emit('message', data);
  1963. }
  1964. , stop: function() {
  1965. debug('stop');
  1966. self._cleanup();
  1967. self._close('network');
  1968. }
  1969. };
  1970. this.iframeObj = constructFunc(url, function() {
  1971. debug('callback');
  1972. self._cleanup();
  1973. self._close('permanent');
  1974. });
  1975. }
  1976. inherits(HtmlfileReceiver, EventEmitter);
  1977. HtmlfileReceiver.prototype.abort = function() {
  1978. debug('abort');
  1979. this._cleanup();
  1980. this._close('user');
  1981. };
  1982. HtmlfileReceiver.prototype._cleanup = function() {
  1983. debug('_cleanup');
  1984. if (this.iframeObj) {
  1985. this.iframeObj.cleanup();
  1986. this.iframeObj = null;
  1987. }
  1988. delete global[iframeUtils.WPrefix][this.id];
  1989. };
  1990. HtmlfileReceiver.prototype._close = function(reason) {
  1991. debug('_close', reason);
  1992. this.emit('close', null, reason);
  1993. this.removeAllListeners();
  1994. };
  1995. HtmlfileReceiver.htmlfileEnabled = false;
  1996. // obfuscate to avoid firewalls
  1997. var axo = ['Active'].concat('Object').join('X');
  1998. if (axo in global) {
  1999. try {
  2000. HtmlfileReceiver.htmlfileEnabled = !!new global[axo]('htmlfile');
  2001. } catch (x) {
  2002. // intentionally empty
  2003. }
  2004. }
  2005. HtmlfileReceiver.enabled = HtmlfileReceiver.htmlfileEnabled || iframeUtils.iframeEnabled;
  2006. module.exports = HtmlfileReceiver;
  2007. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2008. },{"../../utils/iframe":47,"../../utils/random":50,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],31:[function(require,module,exports){
  2009. (function (process,global){(function (){
  2010. 'use strict';
  2011. var utils = require('../../utils/iframe')
  2012. , random = require('../../utils/random')
  2013. , browser = require('../../utils/browser')
  2014. , urlUtils = require('../../utils/url')
  2015. , inherits = require('inherits')
  2016. , EventEmitter = require('events').EventEmitter
  2017. ;
  2018. var debug = function() {};
  2019. if (process.env.NODE_ENV !== 'production') {
  2020. debug = require('debug')('sockjs-client:receiver:jsonp');
  2021. }
  2022. function JsonpReceiver(url) {
  2023. debug(url);
  2024. var self = this;
  2025. EventEmitter.call(this);
  2026. utils.polluteGlobalNamespace();
  2027. this.id = 'a' + random.string(6);
  2028. var urlWithId = urlUtils.addQuery(url, 'c=' + encodeURIComponent(utils.WPrefix + '.' + this.id));
  2029. global[utils.WPrefix][this.id] = this._callback.bind(this);
  2030. this._createScript(urlWithId);
  2031. // Fallback mostly for Konqueror - stupid timer, 35 seconds shall be plenty.
  2032. this.timeoutId = setTimeout(function() {
  2033. debug('timeout');
  2034. self._abort(new Error('JSONP script loaded abnormally (timeout)'));
  2035. }, JsonpReceiver.timeout);
  2036. }
  2037. inherits(JsonpReceiver, EventEmitter);
  2038. JsonpReceiver.prototype.abort = function() {
  2039. debug('abort');
  2040. if (global[utils.WPrefix][this.id]) {
  2041. var err = new Error('JSONP user aborted read');
  2042. err.code = 1000;
  2043. this._abort(err);
  2044. }
  2045. };
  2046. JsonpReceiver.timeout = 35000;
  2047. JsonpReceiver.scriptErrorTimeout = 1000;
  2048. JsonpReceiver.prototype._callback = function(data) {
  2049. debug('_callback', data);
  2050. this._cleanup();
  2051. if (this.aborting) {
  2052. return;
  2053. }
  2054. if (data) {
  2055. debug('message', data);
  2056. this.emit('message', data);
  2057. }
  2058. this.emit('close', null, 'network');
  2059. this.removeAllListeners();
  2060. };
  2061. JsonpReceiver.prototype._abort = function(err) {
  2062. debug('_abort', err);
  2063. this._cleanup();
  2064. this.aborting = true;
  2065. this.emit('close', err.code, err.message);
  2066. this.removeAllListeners();
  2067. };
  2068. JsonpReceiver.prototype._cleanup = function() {
  2069. debug('_cleanup');
  2070. clearTimeout(this.timeoutId);
  2071. if (this.script2) {
  2072. this.script2.parentNode.removeChild(this.script2);
  2073. this.script2 = null;
  2074. }
  2075. if (this.script) {
  2076. var script = this.script;
  2077. // Unfortunately, you can't really abort script loading of
  2078. // the script.
  2079. script.parentNode.removeChild(script);
  2080. script.onreadystatechange = script.onerror =
  2081. script.onload = script.onclick = null;
  2082. this.script = null;
  2083. }
  2084. delete global[utils.WPrefix][this.id];
  2085. };
  2086. JsonpReceiver.prototype._scriptError = function() {
  2087. debug('_scriptError');
  2088. var self = this;
  2089. if (this.errorTimer) {
  2090. return;
  2091. }
  2092. this.errorTimer = setTimeout(function() {
  2093. if (!self.loadedOkay) {
  2094. self._abort(new Error('JSONP script loaded abnormally (onerror)'));
  2095. }
  2096. }, JsonpReceiver.scriptErrorTimeout);
  2097. };
  2098. JsonpReceiver.prototype._createScript = function(url) {
  2099. debug('_createScript', url);
  2100. var self = this;
  2101. var script = this.script = global.document.createElement('script');
  2102. var script2; // Opera synchronous load trick.
  2103. script.id = 'a' + random.string(8);
  2104. script.src = url;
  2105. script.type = 'text/javascript';
  2106. script.charset = 'UTF-8';
  2107. script.onerror = this._scriptError.bind(this);
  2108. script.onload = function() {
  2109. debug('onload');
  2110. self._abort(new Error('JSONP script loaded abnormally (onload)'));
  2111. };
  2112. // IE9 fires 'error' event after onreadystatechange or before, in random order.
  2113. // Use loadedOkay to determine if actually errored
  2114. script.onreadystatechange = function() {
  2115. debug('onreadystatechange', script.readyState);
  2116. if (/loaded|closed/.test(script.readyState)) {
  2117. if (script && script.htmlFor && script.onclick) {
  2118. self.loadedOkay = true;
  2119. try {
  2120. // In IE, actually execute the script.
  2121. script.onclick();
  2122. } catch (x) {
  2123. // intentionally empty
  2124. }
  2125. }
  2126. if (script) {
  2127. self._abort(new Error('JSONP script loaded abnormally (onreadystatechange)'));
  2128. }
  2129. }
  2130. };
  2131. // IE: event/htmlFor/onclick trick.
  2132. // One can't rely on proper order for onreadystatechange. In order to
  2133. // make sure, set a 'htmlFor' and 'event' properties, so that
  2134. // script code will be installed as 'onclick' handler for the
  2135. // script object. Later, onreadystatechange, manually execute this
  2136. // code. FF and Chrome doesn't work with 'event' and 'htmlFor'
  2137. // set. For reference see:
  2138. // http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
  2139. // Also, read on that about script ordering:
  2140. // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
  2141. if (typeof script.async === 'undefined' && global.document.attachEvent) {
  2142. // According to mozilla docs, in recent browsers script.async defaults
  2143. // to 'true', so we may use it to detect a good browser:
  2144. // https://developer.mozilla.org/en/HTML/Element/script
  2145. if (!browser.isOpera()) {
  2146. // Naively assume we're in IE
  2147. try {
  2148. script.htmlFor = script.id;
  2149. script.event = 'onclick';
  2150. } catch (x) {
  2151. // intentionally empty
  2152. }
  2153. script.async = true;
  2154. } else {
  2155. // Opera, second sync script hack
  2156. script2 = this.script2 = global.document.createElement('script');
  2157. script2.text = "try{var a = document.getElementById('" + script.id + "'); if(a)a.onerror();}catch(x){};";
  2158. script.async = script2.async = false;
  2159. }
  2160. }
  2161. if (typeof script.async !== 'undefined') {
  2162. script.async = true;
  2163. }
  2164. var head = global.document.getElementsByTagName('head')[0];
  2165. head.insertBefore(script, head.firstChild);
  2166. if (script2) {
  2167. head.insertBefore(script2, head.firstChild);
  2168. }
  2169. };
  2170. module.exports = JsonpReceiver;
  2171. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2172. },{"../../utils/browser":44,"../../utils/iframe":47,"../../utils/random":50,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],32:[function(require,module,exports){
  2173. (function (process){(function (){
  2174. 'use strict';
  2175. var inherits = require('inherits')
  2176. , EventEmitter = require('events').EventEmitter
  2177. ;
  2178. var debug = function() {};
  2179. if (process.env.NODE_ENV !== 'production') {
  2180. debug = require('debug')('sockjs-client:receiver:xhr');
  2181. }
  2182. function XhrReceiver(url, AjaxObject) {
  2183. debug(url);
  2184. EventEmitter.call(this);
  2185. var self = this;
  2186. this.bufferPosition = 0;
  2187. this.xo = new AjaxObject('POST', url, null);
  2188. this.xo.on('chunk', this._chunkHandler.bind(this));
  2189. this.xo.once('finish', function(status, text) {
  2190. debug('finish', status, text);
  2191. self._chunkHandler(status, text);
  2192. self.xo = null;
  2193. var reason = status === 200 ? 'network' : 'permanent';
  2194. debug('close', reason);
  2195. self.emit('close', null, reason);
  2196. self._cleanup();
  2197. });
  2198. }
  2199. inherits(XhrReceiver, EventEmitter);
  2200. XhrReceiver.prototype._chunkHandler = function(status, text) {
  2201. debug('_chunkHandler', status);
  2202. if (status !== 200 || !text) {
  2203. return;
  2204. }
  2205. for (var idx = -1; ; this.bufferPosition += idx + 1) {
  2206. var buf = text.slice(this.bufferPosition);
  2207. idx = buf.indexOf('\n');
  2208. if (idx === -1) {
  2209. break;
  2210. }
  2211. var msg = buf.slice(0, idx);
  2212. if (msg) {
  2213. debug('message', msg);
  2214. this.emit('message', msg);
  2215. }
  2216. }
  2217. };
  2218. XhrReceiver.prototype._cleanup = function() {
  2219. debug('_cleanup');
  2220. this.removeAllListeners();
  2221. };
  2222. XhrReceiver.prototype.abort = function() {
  2223. debug('abort');
  2224. if (this.xo) {
  2225. this.xo.close();
  2226. debug('close');
  2227. this.emit('close', null, 'user');
  2228. this.xo = null;
  2229. }
  2230. this._cleanup();
  2231. };
  2232. module.exports = XhrReceiver;
  2233. }).call(this)}).call(this,{ env: {} })
  2234. },{"debug":55,"events":3,"inherits":57}],33:[function(require,module,exports){
  2235. (function (process,global){(function (){
  2236. 'use strict';
  2237. var random = require('../../utils/random')
  2238. , urlUtils = require('../../utils/url')
  2239. ;
  2240. var debug = function() {};
  2241. if (process.env.NODE_ENV !== 'production') {
  2242. debug = require('debug')('sockjs-client:sender:jsonp');
  2243. }
  2244. var form, area;
  2245. function createIframe(id) {
  2246. debug('createIframe', id);
  2247. try {
  2248. // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
  2249. return global.document.createElement('<iframe name="' + id + '">');
  2250. } catch (x) {
  2251. var iframe = global.document.createElement('iframe');
  2252. iframe.name = id;
  2253. return iframe;
  2254. }
  2255. }
  2256. function createForm() {
  2257. debug('createForm');
  2258. form = global.document.createElement('form');
  2259. form.style.display = 'none';
  2260. form.style.position = 'absolute';
  2261. form.method = 'POST';
  2262. form.enctype = 'application/x-www-form-urlencoded';
  2263. form.acceptCharset = 'UTF-8';
  2264. area = global.document.createElement('textarea');
  2265. area.name = 'd';
  2266. form.appendChild(area);
  2267. global.document.body.appendChild(form);
  2268. }
  2269. module.exports = function(url, payload, callback) {
  2270. debug(url, payload);
  2271. if (!form) {
  2272. createForm();
  2273. }
  2274. var id = 'a' + random.string(8);
  2275. form.target = id;
  2276. form.action = urlUtils.addQuery(urlUtils.addPath(url, '/jsonp_send'), 'i=' + id);
  2277. var iframe = createIframe(id);
  2278. iframe.id = id;
  2279. iframe.style.display = 'none';
  2280. form.appendChild(iframe);
  2281. try {
  2282. area.value = payload;
  2283. } catch (e) {
  2284. // seriously broken browsers get here
  2285. }
  2286. form.submit();
  2287. var completed = function(err) {
  2288. debug('completed', id, err);
  2289. if (!iframe.onerror) {
  2290. return;
  2291. }
  2292. iframe.onreadystatechange = iframe.onerror = iframe.onload = null;
  2293. // Opera mini doesn't like if we GC iframe
  2294. // immediately, thus this timeout.
  2295. setTimeout(function() {
  2296. debug('cleaning up', id);
  2297. iframe.parentNode.removeChild(iframe);
  2298. iframe = null;
  2299. }, 500);
  2300. area.value = '';
  2301. // It is not possible to detect if the iframe succeeded or
  2302. // failed to submit our form.
  2303. callback(err);
  2304. };
  2305. iframe.onerror = function() {
  2306. debug('onerror', id);
  2307. completed();
  2308. };
  2309. iframe.onload = function() {
  2310. debug('onload', id);
  2311. completed();
  2312. };
  2313. iframe.onreadystatechange = function(e) {
  2314. debug('onreadystatechange', id, iframe.readyState, e);
  2315. if (iframe.readyState === 'complete') {
  2316. completed();
  2317. }
  2318. };
  2319. return function() {
  2320. debug('aborted', id);
  2321. completed(new Error('Aborted'));
  2322. };
  2323. };
  2324. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2325. },{"../../utils/random":50,"../../utils/url":52,"debug":55}],34:[function(require,module,exports){
  2326. (function (process,global){(function (){
  2327. 'use strict';
  2328. var EventEmitter = require('events').EventEmitter
  2329. , inherits = require('inherits')
  2330. , eventUtils = require('../../utils/event')
  2331. , browser = require('../../utils/browser')
  2332. , urlUtils = require('../../utils/url')
  2333. ;
  2334. var debug = function() {};
  2335. if (process.env.NODE_ENV !== 'production') {
  2336. debug = require('debug')('sockjs-client:sender:xdr');
  2337. }
  2338. // References:
  2339. // http://ajaxian.com/archives/100-line-ajax-wrapper
  2340. // http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx
  2341. function XDRObject(method, url, payload) {
  2342. debug(method, url);
  2343. var self = this;
  2344. EventEmitter.call(this);
  2345. setTimeout(function() {
  2346. self._start(method, url, payload);
  2347. }, 0);
  2348. }
  2349. inherits(XDRObject, EventEmitter);
  2350. XDRObject.prototype._start = function(method, url, payload) {
  2351. debug('_start');
  2352. var self = this;
  2353. var xdr = new global.XDomainRequest();
  2354. // IE caches even POSTs
  2355. url = urlUtils.addQuery(url, 't=' + (+new Date()));
  2356. xdr.onerror = function() {
  2357. debug('onerror');
  2358. self._error();
  2359. };
  2360. xdr.ontimeout = function() {
  2361. debug('ontimeout');
  2362. self._error();
  2363. };
  2364. xdr.onprogress = function() {
  2365. debug('progress', xdr.responseText);
  2366. self.emit('chunk', 200, xdr.responseText);
  2367. };
  2368. xdr.onload = function() {
  2369. debug('load');
  2370. self.emit('finish', 200, xdr.responseText);
  2371. self._cleanup(false);
  2372. };
  2373. this.xdr = xdr;
  2374. this.unloadRef = eventUtils.unloadAdd(function() {
  2375. self._cleanup(true);
  2376. });
  2377. try {
  2378. // Fails with AccessDenied if port number is bogus
  2379. this.xdr.open(method, url);
  2380. if (this.timeout) {
  2381. this.xdr.timeout = this.timeout;
  2382. }
  2383. this.xdr.send(payload);
  2384. } catch (x) {
  2385. this._error();
  2386. }
  2387. };
  2388. XDRObject.prototype._error = function() {
  2389. this.emit('finish', 0, '');
  2390. this._cleanup(false);
  2391. };
  2392. XDRObject.prototype._cleanup = function(abort) {
  2393. debug('cleanup', abort);
  2394. if (!this.xdr) {
  2395. return;
  2396. }
  2397. this.removeAllListeners();
  2398. eventUtils.unloadDel(this.unloadRef);
  2399. this.xdr.ontimeout = this.xdr.onerror = this.xdr.onprogress = this.xdr.onload = null;
  2400. if (abort) {
  2401. try {
  2402. this.xdr.abort();
  2403. } catch (x) {
  2404. // intentionally empty
  2405. }
  2406. }
  2407. this.unloadRef = this.xdr = null;
  2408. };
  2409. XDRObject.prototype.close = function() {
  2410. debug('close');
  2411. this._cleanup(true);
  2412. };
  2413. // IE 8/9 if the request target uses the same scheme - #79
  2414. XDRObject.enabled = !!(global.XDomainRequest && browser.hasDomain());
  2415. module.exports = XDRObject;
  2416. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2417. },{"../../utils/browser":44,"../../utils/event":46,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],35:[function(require,module,exports){
  2418. 'use strict';
  2419. var inherits = require('inherits')
  2420. , XhrDriver = require('../driver/xhr')
  2421. ;
  2422. function XHRCorsObject(method, url, payload, opts) {
  2423. XhrDriver.call(this, method, url, payload, opts);
  2424. }
  2425. inherits(XHRCorsObject, XhrDriver);
  2426. XHRCorsObject.enabled = XhrDriver.enabled && XhrDriver.supportsCORS;
  2427. module.exports = XHRCorsObject;
  2428. },{"../driver/xhr":17,"inherits":57}],36:[function(require,module,exports){
  2429. 'use strict';
  2430. var EventEmitter = require('events').EventEmitter
  2431. , inherits = require('inherits')
  2432. ;
  2433. function XHRFake(/* method, url, payload, opts */) {
  2434. var self = this;
  2435. EventEmitter.call(this);
  2436. this.to = setTimeout(function() {
  2437. self.emit('finish', 200, '{}');
  2438. }, XHRFake.timeout);
  2439. }
  2440. inherits(XHRFake, EventEmitter);
  2441. XHRFake.prototype.close = function() {
  2442. clearTimeout(this.to);
  2443. };
  2444. XHRFake.timeout = 2000;
  2445. module.exports = XHRFake;
  2446. },{"events":3,"inherits":57}],37:[function(require,module,exports){
  2447. 'use strict';
  2448. var inherits = require('inherits')
  2449. , XhrDriver = require('../driver/xhr')
  2450. ;
  2451. function XHRLocalObject(method, url, payload /*, opts */) {
  2452. XhrDriver.call(this, method, url, payload, {
  2453. noCredentials: true
  2454. });
  2455. }
  2456. inherits(XHRLocalObject, XhrDriver);
  2457. XHRLocalObject.enabled = XhrDriver.enabled;
  2458. module.exports = XHRLocalObject;
  2459. },{"../driver/xhr":17,"inherits":57}],38:[function(require,module,exports){
  2460. (function (process){(function (){
  2461. 'use strict';
  2462. var utils = require('../utils/event')
  2463. , urlUtils = require('../utils/url')
  2464. , inherits = require('inherits')
  2465. , EventEmitter = require('events').EventEmitter
  2466. , WebsocketDriver = require('./driver/websocket')
  2467. ;
  2468. var debug = function() {};
  2469. if (process.env.NODE_ENV !== 'production') {
  2470. debug = require('debug')('sockjs-client:websocket');
  2471. }
  2472. function WebSocketTransport(transUrl, ignore, options) {
  2473. if (!WebSocketTransport.enabled()) {
  2474. throw new Error('Transport created when disabled');
  2475. }
  2476. EventEmitter.call(this);
  2477. debug('constructor', transUrl);
  2478. var self = this;
  2479. var url = urlUtils.addPath(transUrl, '/websocket');
  2480. if (url.slice(0, 5) === 'https') {
  2481. url = 'wss' + url.slice(5);
  2482. } else {
  2483. url = 'ws' + url.slice(4);
  2484. }
  2485. this.url = url;
  2486. this.ws = new WebsocketDriver(this.url, [], options);
  2487. this.ws.onmessage = function(e) {
  2488. debug('message event', e.data);
  2489. self.emit('message', e.data);
  2490. };
  2491. // Firefox has an interesting bug. If a websocket connection is
  2492. // created after onunload, it stays alive even when user
  2493. // navigates away from the page. In such situation let's lie -
  2494. // let's not open the ws connection at all. See:
  2495. // https://github.com/sockjs/sockjs-client/issues/28
  2496. // https://bugzilla.mozilla.org/show_bug.cgi?id=696085
  2497. this.unloadRef = utils.unloadAdd(function() {
  2498. debug('unload');
  2499. self.ws.close();
  2500. });
  2501. this.ws.onclose = function(e) {
  2502. debug('close event', e.code, e.reason);
  2503. self.emit('close', e.code, e.reason);
  2504. self._cleanup();
  2505. };
  2506. this.ws.onerror = function(e) {
  2507. debug('error event', e);
  2508. self.emit('close', 1006, 'WebSocket connection broken');
  2509. self._cleanup();
  2510. };
  2511. }
  2512. inherits(WebSocketTransport, EventEmitter);
  2513. WebSocketTransport.prototype.send = function(data) {
  2514. var msg = '[' + data + ']';
  2515. debug('send', msg);
  2516. this.ws.send(msg);
  2517. };
  2518. WebSocketTransport.prototype.close = function() {
  2519. debug('close');
  2520. var ws = this.ws;
  2521. this._cleanup();
  2522. if (ws) {
  2523. ws.close();
  2524. }
  2525. };
  2526. WebSocketTransport.prototype._cleanup = function() {
  2527. debug('_cleanup');
  2528. var ws = this.ws;
  2529. if (ws) {
  2530. ws.onmessage = ws.onclose = ws.onerror = null;
  2531. }
  2532. utils.unloadDel(this.unloadRef);
  2533. this.unloadRef = this.ws = null;
  2534. this.removeAllListeners();
  2535. };
  2536. WebSocketTransport.enabled = function() {
  2537. debug('enabled');
  2538. return !!WebsocketDriver;
  2539. };
  2540. WebSocketTransport.transportName = 'websocket';
  2541. // In theory, ws should require 1 round trip. But in chrome, this is
  2542. // not very stable over SSL. Most likely a ws connection requires a
  2543. // separate SSL connection, in which case 2 round trips are an
  2544. // absolute minumum.
  2545. WebSocketTransport.roundTrips = 2;
  2546. module.exports = WebSocketTransport;
  2547. }).call(this)}).call(this,{ env: {} })
  2548. },{"../utils/event":46,"../utils/url":52,"./driver/websocket":19,"debug":55,"events":3,"inherits":57}],39:[function(require,module,exports){
  2549. 'use strict';
  2550. var inherits = require('inherits')
  2551. , AjaxBasedTransport = require('./lib/ajax-based')
  2552. , XdrStreamingTransport = require('./xdr-streaming')
  2553. , XhrReceiver = require('./receiver/xhr')
  2554. , XDRObject = require('./sender/xdr')
  2555. ;
  2556. function XdrPollingTransport(transUrl) {
  2557. if (!XDRObject.enabled) {
  2558. throw new Error('Transport created when disabled');
  2559. }
  2560. AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XDRObject);
  2561. }
  2562. inherits(XdrPollingTransport, AjaxBasedTransport);
  2563. XdrPollingTransport.enabled = XdrStreamingTransport.enabled;
  2564. XdrPollingTransport.transportName = 'xdr-polling';
  2565. XdrPollingTransport.roundTrips = 2; // preflight, ajax
  2566. module.exports = XdrPollingTransport;
  2567. },{"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xdr":34,"./xdr-streaming":40,"inherits":57}],40:[function(require,module,exports){
  2568. 'use strict';
  2569. var inherits = require('inherits')
  2570. , AjaxBasedTransport = require('./lib/ajax-based')
  2571. , XhrReceiver = require('./receiver/xhr')
  2572. , XDRObject = require('./sender/xdr')
  2573. ;
  2574. // According to:
  2575. // http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
  2576. // http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
  2577. function XdrStreamingTransport(transUrl) {
  2578. if (!XDRObject.enabled) {
  2579. throw new Error('Transport created when disabled');
  2580. }
  2581. AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XDRObject);
  2582. }
  2583. inherits(XdrStreamingTransport, AjaxBasedTransport);
  2584. XdrStreamingTransport.enabled = function(info) {
  2585. if (info.cookie_needed || info.nullOrigin) {
  2586. return false;
  2587. }
  2588. return XDRObject.enabled && info.sameScheme;
  2589. };
  2590. XdrStreamingTransport.transportName = 'xdr-streaming';
  2591. XdrStreamingTransport.roundTrips = 2; // preflight, ajax
  2592. module.exports = XdrStreamingTransport;
  2593. },{"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xdr":34,"inherits":57}],41:[function(require,module,exports){
  2594. 'use strict';
  2595. var inherits = require('inherits')
  2596. , AjaxBasedTransport = require('./lib/ajax-based')
  2597. , XhrReceiver = require('./receiver/xhr')
  2598. , XHRCorsObject = require('./sender/xhr-cors')
  2599. , XHRLocalObject = require('./sender/xhr-local')
  2600. ;
  2601. function XhrPollingTransport(transUrl) {
  2602. if (!XHRLocalObject.enabled && !XHRCorsObject.enabled) {
  2603. throw new Error('Transport created when disabled');
  2604. }
  2605. AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XHRCorsObject);
  2606. }
  2607. inherits(XhrPollingTransport, AjaxBasedTransport);
  2608. XhrPollingTransport.enabled = function(info) {
  2609. if (info.nullOrigin) {
  2610. return false;
  2611. }
  2612. if (XHRLocalObject.enabled && info.sameOrigin) {
  2613. return true;
  2614. }
  2615. return XHRCorsObject.enabled;
  2616. };
  2617. XhrPollingTransport.transportName = 'xhr-polling';
  2618. XhrPollingTransport.roundTrips = 2; // preflight, ajax
  2619. module.exports = XhrPollingTransport;
  2620. },{"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xhr-cors":35,"./sender/xhr-local":37,"inherits":57}],42:[function(require,module,exports){
  2621. (function (global){(function (){
  2622. 'use strict';
  2623. var inherits = require('inherits')
  2624. , AjaxBasedTransport = require('./lib/ajax-based')
  2625. , XhrReceiver = require('./receiver/xhr')
  2626. , XHRCorsObject = require('./sender/xhr-cors')
  2627. , XHRLocalObject = require('./sender/xhr-local')
  2628. , browser = require('../utils/browser')
  2629. ;
  2630. function XhrStreamingTransport(transUrl) {
  2631. if (!XHRLocalObject.enabled && !XHRCorsObject.enabled) {
  2632. throw new Error('Transport created when disabled');
  2633. }
  2634. AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XHRCorsObject);
  2635. }
  2636. inherits(XhrStreamingTransport, AjaxBasedTransport);
  2637. XhrStreamingTransport.enabled = function(info) {
  2638. if (info.nullOrigin) {
  2639. return false;
  2640. }
  2641. // Opera doesn't support xhr-streaming #60
  2642. // But it might be able to #92
  2643. if (browser.isOpera()) {
  2644. return false;
  2645. }
  2646. return XHRCorsObject.enabled;
  2647. };
  2648. XhrStreamingTransport.transportName = 'xhr-streaming';
  2649. XhrStreamingTransport.roundTrips = 2; // preflight, ajax
  2650. // Safari gets confused when a streaming ajax request is started
  2651. // before onload. This causes the load indicator to spin indefinetely.
  2652. // Only require body when used in a browser
  2653. XhrStreamingTransport.needBody = !!global.document;
  2654. module.exports = XhrStreamingTransport;
  2655. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2656. },{"../utils/browser":44,"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xhr-cors":35,"./sender/xhr-local":37,"inherits":57}],43:[function(require,module,exports){
  2657. (function (global){(function (){
  2658. 'use strict';
  2659. if (global.crypto && global.crypto.getRandomValues) {
  2660. module.exports.randomBytes = function(length) {
  2661. var bytes = new Uint8Array(length);
  2662. global.crypto.getRandomValues(bytes);
  2663. return bytes;
  2664. };
  2665. } else {
  2666. module.exports.randomBytes = function(length) {
  2667. var bytes = new Array(length);
  2668. for (var i = 0; i < length; i++) {
  2669. bytes[i] = Math.floor(Math.random() * 256);
  2670. }
  2671. return bytes;
  2672. };
  2673. }
  2674. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2675. },{}],44:[function(require,module,exports){
  2676. (function (global){(function (){
  2677. 'use strict';
  2678. module.exports = {
  2679. isOpera: function() {
  2680. return global.navigator &&
  2681. /opera/i.test(global.navigator.userAgent);
  2682. }
  2683. , isKonqueror: function() {
  2684. return global.navigator &&
  2685. /konqueror/i.test(global.navigator.userAgent);
  2686. }
  2687. // #187 wrap document.domain in try/catch because of WP8 from file:///
  2688. , hasDomain: function () {
  2689. // non-browser client always has a domain
  2690. if (!global.document) {
  2691. return true;
  2692. }
  2693. try {
  2694. return !!global.document.domain;
  2695. } catch (e) {
  2696. return false;
  2697. }
  2698. }
  2699. };
  2700. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2701. },{}],45:[function(require,module,exports){
  2702. 'use strict';
  2703. // Some extra characters that Chrome gets wrong, and substitutes with
  2704. // something else on the wire.
  2705. // eslint-disable-next-line no-control-regex, no-misleading-character-class
  2706. var extraEscapable = /[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g
  2707. , extraLookup;
  2708. // This may be quite slow, so let's delay until user actually uses bad
  2709. // characters.
  2710. var unrollLookup = function(escapable) {
  2711. var i;
  2712. var unrolled = {};
  2713. var c = [];
  2714. for (i = 0; i < 65536; i++) {
  2715. c.push( String.fromCharCode(i) );
  2716. }
  2717. escapable.lastIndex = 0;
  2718. c.join('').replace(escapable, function(a) {
  2719. unrolled[ a ] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  2720. return '';
  2721. });
  2722. escapable.lastIndex = 0;
  2723. return unrolled;
  2724. };
  2725. // Quote string, also taking care of unicode characters that browsers
  2726. // often break. Especially, take care of unicode surrogates:
  2727. // http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
  2728. module.exports = {
  2729. quote: function(string) {
  2730. var quoted = JSON.stringify(string);
  2731. // In most cases this should be very fast and good enough.
  2732. extraEscapable.lastIndex = 0;
  2733. if (!extraEscapable.test(quoted)) {
  2734. return quoted;
  2735. }
  2736. if (!extraLookup) {
  2737. extraLookup = unrollLookup(extraEscapable);
  2738. }
  2739. return quoted.replace(extraEscapable, function(a) {
  2740. return extraLookup[a];
  2741. });
  2742. }
  2743. };
  2744. },{}],46:[function(require,module,exports){
  2745. (function (global){(function (){
  2746. 'use strict';
  2747. var random = require('./random');
  2748. var onUnload = {}
  2749. , afterUnload = false
  2750. // detect google chrome packaged apps because they don't allow the 'unload' event
  2751. , isChromePackagedApp = global.chrome && global.chrome.app && global.chrome.app.runtime
  2752. ;
  2753. module.exports = {
  2754. attachEvent: function(event, listener) {
  2755. if (typeof global.addEventListener !== 'undefined') {
  2756. global.addEventListener(event, listener, false);
  2757. } else if (global.document && global.attachEvent) {
  2758. // IE quirks.
  2759. // According to: http://stevesouders.com/misc/test-postmessage.php
  2760. // the message gets delivered only to 'document', not 'window'.
  2761. global.document.attachEvent('on' + event, listener);
  2762. // I get 'window' for ie8.
  2763. global.attachEvent('on' + event, listener);
  2764. }
  2765. }
  2766. , detachEvent: function(event, listener) {
  2767. if (typeof global.addEventListener !== 'undefined') {
  2768. global.removeEventListener(event, listener, false);
  2769. } else if (global.document && global.detachEvent) {
  2770. global.document.detachEvent('on' + event, listener);
  2771. global.detachEvent('on' + event, listener);
  2772. }
  2773. }
  2774. , unloadAdd: function(listener) {
  2775. if (isChromePackagedApp) {
  2776. return null;
  2777. }
  2778. var ref = random.string(8);
  2779. onUnload[ref] = listener;
  2780. if (afterUnload) {
  2781. setTimeout(this.triggerUnloadCallbacks, 0);
  2782. }
  2783. return ref;
  2784. }
  2785. , unloadDel: function(ref) {
  2786. if (ref in onUnload) {
  2787. delete onUnload[ref];
  2788. }
  2789. }
  2790. , triggerUnloadCallbacks: function() {
  2791. for (var ref in onUnload) {
  2792. onUnload[ref]();
  2793. delete onUnload[ref];
  2794. }
  2795. }
  2796. };
  2797. var unloadTriggered = function() {
  2798. if (afterUnload) {
  2799. return;
  2800. }
  2801. afterUnload = true;
  2802. module.exports.triggerUnloadCallbacks();
  2803. };
  2804. // 'unload' alone is not reliable in opera within an iframe, but we
  2805. // can't use `beforeunload` as IE fires it on javascript: links.
  2806. if (!isChromePackagedApp) {
  2807. module.exports.attachEvent('unload', unloadTriggered);
  2808. }
  2809. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2810. },{"./random":50}],47:[function(require,module,exports){
  2811. (function (process,global){(function (){
  2812. 'use strict';
  2813. var eventUtils = require('./event')
  2814. , browser = require('./browser')
  2815. ;
  2816. var debug = function() {};
  2817. if (process.env.NODE_ENV !== 'production') {
  2818. debug = require('debug')('sockjs-client:utils:iframe');
  2819. }
  2820. module.exports = {
  2821. WPrefix: '_jp'
  2822. , currentWindowId: null
  2823. , polluteGlobalNamespace: function() {
  2824. if (!(module.exports.WPrefix in global)) {
  2825. global[module.exports.WPrefix] = {};
  2826. }
  2827. }
  2828. , postMessage: function(type, data) {
  2829. if (global.parent !== global) {
  2830. global.parent.postMessage(JSON.stringify({
  2831. windowId: module.exports.currentWindowId
  2832. , type: type
  2833. , data: data || ''
  2834. }), '*');
  2835. } else {
  2836. debug('Cannot postMessage, no parent window.', type, data);
  2837. }
  2838. }
  2839. , createIframe: function(iframeUrl, errorCallback) {
  2840. var iframe = global.document.createElement('iframe');
  2841. var tref, unloadRef;
  2842. var unattach = function() {
  2843. debug('unattach');
  2844. clearTimeout(tref);
  2845. // Explorer had problems with that.
  2846. try {
  2847. iframe.onload = null;
  2848. } catch (x) {
  2849. // intentionally empty
  2850. }
  2851. iframe.onerror = null;
  2852. };
  2853. var cleanup = function() {
  2854. debug('cleanup');
  2855. if (iframe) {
  2856. unattach();
  2857. // This timeout makes chrome fire onbeforeunload event
  2858. // within iframe. Without the timeout it goes straight to
  2859. // onunload.
  2860. setTimeout(function() {
  2861. if (iframe) {
  2862. iframe.parentNode.removeChild(iframe);
  2863. }
  2864. iframe = null;
  2865. }, 0);
  2866. eventUtils.unloadDel(unloadRef);
  2867. }
  2868. };
  2869. var onerror = function(err) {
  2870. debug('onerror', err);
  2871. if (iframe) {
  2872. cleanup();
  2873. errorCallback(err);
  2874. }
  2875. };
  2876. var post = function(msg, origin) {
  2877. debug('post', msg, origin);
  2878. setTimeout(function() {
  2879. try {
  2880. // When the iframe is not loaded, IE raises an exception
  2881. // on 'contentWindow'.
  2882. if (iframe && iframe.contentWindow) {
  2883. iframe.contentWindow.postMessage(msg, origin);
  2884. }
  2885. } catch (x) {
  2886. // intentionally empty
  2887. }
  2888. }, 0);
  2889. };
  2890. iframe.src = iframeUrl;
  2891. iframe.style.display = 'none';
  2892. iframe.style.position = 'absolute';
  2893. iframe.onerror = function() {
  2894. onerror('onerror');
  2895. };
  2896. iframe.onload = function() {
  2897. debug('onload');
  2898. // `onload` is triggered before scripts on the iframe are
  2899. // executed. Give it few seconds to actually load stuff.
  2900. clearTimeout(tref);
  2901. tref = setTimeout(function() {
  2902. onerror('onload timeout');
  2903. }, 2000);
  2904. };
  2905. global.document.body.appendChild(iframe);
  2906. tref = setTimeout(function() {
  2907. onerror('timeout');
  2908. }, 15000);
  2909. unloadRef = eventUtils.unloadAdd(cleanup);
  2910. return {
  2911. post: post
  2912. , cleanup: cleanup
  2913. , loaded: unattach
  2914. };
  2915. }
  2916. /* eslint no-undef: "off", new-cap: "off" */
  2917. , createHtmlfile: function(iframeUrl, errorCallback) {
  2918. var axo = ['Active'].concat('Object').join('X');
  2919. var doc = new global[axo]('htmlfile');
  2920. var tref, unloadRef;
  2921. var iframe;
  2922. var unattach = function() {
  2923. clearTimeout(tref);
  2924. iframe.onerror = null;
  2925. };
  2926. var cleanup = function() {
  2927. if (doc) {
  2928. unattach();
  2929. eventUtils.unloadDel(unloadRef);
  2930. iframe.parentNode.removeChild(iframe);
  2931. iframe = doc = null;
  2932. CollectGarbage();
  2933. }
  2934. };
  2935. var onerror = function(r) {
  2936. debug('onerror', r);
  2937. if (doc) {
  2938. cleanup();
  2939. errorCallback(r);
  2940. }
  2941. };
  2942. var post = function(msg, origin) {
  2943. try {
  2944. // When the iframe is not loaded, IE raises an exception
  2945. // on 'contentWindow'.
  2946. setTimeout(function() {
  2947. if (iframe && iframe.contentWindow) {
  2948. iframe.contentWindow.postMessage(msg, origin);
  2949. }
  2950. }, 0);
  2951. } catch (x) {
  2952. // intentionally empty
  2953. }
  2954. };
  2955. doc.open();
  2956. doc.write('<html><s' + 'cript>' +
  2957. 'document.domain="' + global.document.domain + '";' +
  2958. '</s' + 'cript></html>');
  2959. doc.close();
  2960. doc.parentWindow[module.exports.WPrefix] = global[module.exports.WPrefix];
  2961. var c = doc.createElement('div');
  2962. doc.body.appendChild(c);
  2963. iframe = doc.createElement('iframe');
  2964. c.appendChild(iframe);
  2965. iframe.src = iframeUrl;
  2966. iframe.onerror = function() {
  2967. onerror('onerror');
  2968. };
  2969. tref = setTimeout(function() {
  2970. onerror('timeout');
  2971. }, 15000);
  2972. unloadRef = eventUtils.unloadAdd(cleanup);
  2973. return {
  2974. post: post
  2975. , cleanup: cleanup
  2976. , loaded: unattach
  2977. };
  2978. }
  2979. };
  2980. module.exports.iframeEnabled = false;
  2981. if (global.document) {
  2982. // postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
  2983. // huge delay, or not at all.
  2984. module.exports.iframeEnabled = (typeof global.postMessage === 'function' ||
  2985. typeof global.postMessage === 'object') && (!browser.isKonqueror());
  2986. }
  2987. }).call(this)}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2988. },{"./browser":44,"./event":46,"debug":55}],48:[function(require,module,exports){
  2989. (function (global){(function (){
  2990. 'use strict';
  2991. var logObject = {};
  2992. ['log', 'debug', 'warn'].forEach(function (level) {
  2993. var levelExists;
  2994. try {
  2995. levelExists = global.console && global.console[level] && global.console[level].apply;
  2996. } catch(e) {
  2997. // do nothing
  2998. }
  2999. logObject[level] = levelExists ? function () {
  3000. return global.console[level].apply(global.console, arguments);
  3001. } : (level === 'log' ? function () {} : logObject.log);
  3002. });
  3003. module.exports = logObject;
  3004. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3005. },{}],49:[function(require,module,exports){
  3006. 'use strict';
  3007. module.exports = {
  3008. isObject: function(obj) {
  3009. var type = typeof obj;
  3010. return type === 'function' || type === 'object' && !!obj;
  3011. }
  3012. , extend: function(obj) {
  3013. if (!this.isObject(obj)) {
  3014. return obj;
  3015. }
  3016. var source, prop;
  3017. for (var i = 1, length = arguments.length; i < length; i++) {
  3018. source = arguments[i];
  3019. for (prop in source) {
  3020. if (Object.prototype.hasOwnProperty.call(source, prop)) {
  3021. obj[prop] = source[prop];
  3022. }
  3023. }
  3024. }
  3025. return obj;
  3026. }
  3027. };
  3028. },{}],50:[function(require,module,exports){
  3029. 'use strict';
  3030. var crypto = require('crypto');
  3031. // This string has length 32, a power of 2, so the modulus doesn't introduce a
  3032. // bias.
  3033. var _randomStringChars = 'abcdefghijklmnopqrstuvwxyz012345';
  3034. module.exports = {
  3035. string: function(length) {
  3036. var max = _randomStringChars.length;
  3037. var bytes = crypto.randomBytes(length);
  3038. var ret = [];
  3039. for (var i = 0; i < length; i++) {
  3040. ret.push(_randomStringChars.substr(bytes[i] % max, 1));
  3041. }
  3042. return ret.join('');
  3043. }
  3044. , number: function(max) {
  3045. return Math.floor(Math.random() * max);
  3046. }
  3047. , numberString: function(max) {
  3048. var t = ('' + (max - 1)).length;
  3049. var p = new Array(t + 1).join('0');
  3050. return (p + this.number(max)).slice(-t);
  3051. }
  3052. };
  3053. },{"crypto":43}],51:[function(require,module,exports){
  3054. (function (process){(function (){
  3055. 'use strict';
  3056. var debug = function() {};
  3057. if (process.env.NODE_ENV !== 'production') {
  3058. debug = require('debug')('sockjs-client:utils:transport');
  3059. }
  3060. module.exports = function(availableTransports) {
  3061. return {
  3062. filterToEnabled: function(transportsWhitelist, info) {
  3063. var transports = {
  3064. main: []
  3065. , facade: []
  3066. };
  3067. if (!transportsWhitelist) {
  3068. transportsWhitelist = [];
  3069. } else if (typeof transportsWhitelist === 'string') {
  3070. transportsWhitelist = [transportsWhitelist];
  3071. }
  3072. availableTransports.forEach(function(trans) {
  3073. if (!trans) {
  3074. return;
  3075. }
  3076. if (trans.transportName === 'websocket' && info.websocket === false) {
  3077. debug('disabled from server', 'websocket');
  3078. return;
  3079. }
  3080. if (transportsWhitelist.length &&
  3081. transportsWhitelist.indexOf(trans.transportName) === -1) {
  3082. debug('not in whitelist', trans.transportName);
  3083. return;
  3084. }
  3085. if (trans.enabled(info)) {
  3086. debug('enabled', trans.transportName);
  3087. transports.main.push(trans);
  3088. if (trans.facadeTransport) {
  3089. transports.facade.push(trans.facadeTransport);
  3090. }
  3091. } else {
  3092. debug('disabled', trans.transportName);
  3093. }
  3094. });
  3095. return transports;
  3096. }
  3097. };
  3098. };
  3099. }).call(this)}).call(this,{ env: {} })
  3100. },{"debug":55}],52:[function(require,module,exports){
  3101. (function (process){(function (){
  3102. 'use strict';
  3103. var URL = require('url-parse');
  3104. var debug = function() {};
  3105. if (process.env.NODE_ENV !== 'production') {
  3106. debug = require('debug')('sockjs-client:utils:url');
  3107. }
  3108. module.exports = {
  3109. getOrigin: function(url) {
  3110. if (!url) {
  3111. return null;
  3112. }
  3113. var p = new URL(url);
  3114. if (p.protocol === 'file:') {
  3115. return null;
  3116. }
  3117. var port = p.port;
  3118. if (!port) {
  3119. port = (p.protocol === 'https:') ? '443' : '80';
  3120. }
  3121. return p.protocol + '//' + p.hostname + ':' + port;
  3122. }
  3123. , isOriginEqual: function(a, b) {
  3124. var res = this.getOrigin(a) === this.getOrigin(b);
  3125. debug('same', a, b, res);
  3126. return res;
  3127. }
  3128. , isSchemeEqual: function(a, b) {
  3129. return (a.split(':')[0] === b.split(':')[0]);
  3130. }
  3131. , addPath: function (url, path) {
  3132. var qs = url.split('?');
  3133. return qs[0] + path + (qs[1] ? '?' + qs[1] : '');
  3134. }
  3135. , addQuery: function (url, q) {
  3136. return url + (url.indexOf('?') === -1 ? ('?' + q) : ('&' + q));
  3137. }
  3138. , isLoopbackAddr: function (addr) {
  3139. return /^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(addr) || /^\[::1\]$/.test(addr);
  3140. }
  3141. };
  3142. }).call(this)}).call(this,{ env: {} })
  3143. },{"debug":55,"url-parse":60}],53:[function(require,module,exports){
  3144. module.exports = '1.6.1';
  3145. },{}],54:[function(require,module,exports){
  3146. /**
  3147. * Helpers.
  3148. */
  3149. var s = 1000;
  3150. var m = s * 60;
  3151. var h = m * 60;
  3152. var d = h * 24;
  3153. var w = d * 7;
  3154. var y = d * 365.25;
  3155. /**
  3156. * Parse or format the given `val`.
  3157. *
  3158. * Options:
  3159. *
  3160. * - `long` verbose formatting [false]
  3161. *
  3162. * @param {String|Number} val
  3163. * @param {Object} [options]
  3164. * @throws {Error} throw an error if val is not a non-empty string or a number
  3165. * @return {String|Number}
  3166. * @api public
  3167. */
  3168. module.exports = function(val, options) {
  3169. options = options || {};
  3170. var type = typeof val;
  3171. if (type === 'string' && val.length > 0) {
  3172. return parse(val);
  3173. } else if (type === 'number' && isFinite(val)) {
  3174. return options.long ? fmtLong(val) : fmtShort(val);
  3175. }
  3176. throw new Error(
  3177. 'val is not a non-empty string or a valid number. val=' +
  3178. JSON.stringify(val)
  3179. );
  3180. };
  3181. /**
  3182. * Parse the given `str` and return milliseconds.
  3183. *
  3184. * @param {String} str
  3185. * @return {Number}
  3186. * @api private
  3187. */
  3188. function parse(str) {
  3189. str = String(str);
  3190. if (str.length > 100) {
  3191. return;
  3192. }
  3193. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
  3194. str
  3195. );
  3196. if (!match) {
  3197. return;
  3198. }
  3199. var n = parseFloat(match[1]);
  3200. var type = (match[2] || 'ms').toLowerCase();
  3201. switch (type) {
  3202. case 'years':
  3203. case 'year':
  3204. case 'yrs':
  3205. case 'yr':
  3206. case 'y':
  3207. return n * y;
  3208. case 'weeks':
  3209. case 'week':
  3210. case 'w':
  3211. return n * w;
  3212. case 'days':
  3213. case 'day':
  3214. case 'd':
  3215. return n * d;
  3216. case 'hours':
  3217. case 'hour':
  3218. case 'hrs':
  3219. case 'hr':
  3220. case 'h':
  3221. return n * h;
  3222. case 'minutes':
  3223. case 'minute':
  3224. case 'mins':
  3225. case 'min':
  3226. case 'm':
  3227. return n * m;
  3228. case 'seconds':
  3229. case 'second':
  3230. case 'secs':
  3231. case 'sec':
  3232. case 's':
  3233. return n * s;
  3234. case 'milliseconds':
  3235. case 'millisecond':
  3236. case 'msecs':
  3237. case 'msec':
  3238. case 'ms':
  3239. return n;
  3240. default:
  3241. return undefined;
  3242. }
  3243. }
  3244. /**
  3245. * Short format for `ms`.
  3246. *
  3247. * @param {Number} ms
  3248. * @return {String}
  3249. * @api private
  3250. */
  3251. function fmtShort(ms) {
  3252. var msAbs = Math.abs(ms);
  3253. if (msAbs >= d) {
  3254. return Math.round(ms / d) + 'd';
  3255. }
  3256. if (msAbs >= h) {
  3257. return Math.round(ms / h) + 'h';
  3258. }
  3259. if (msAbs >= m) {
  3260. return Math.round(ms / m) + 'm';
  3261. }
  3262. if (msAbs >= s) {
  3263. return Math.round(ms / s) + 's';
  3264. }
  3265. return ms + 'ms';
  3266. }
  3267. /**
  3268. * Long format for `ms`.
  3269. *
  3270. * @param {Number} ms
  3271. * @return {String}
  3272. * @api private
  3273. */
  3274. function fmtLong(ms) {
  3275. var msAbs = Math.abs(ms);
  3276. if (msAbs >= d) {
  3277. return plural(ms, msAbs, d, 'day');
  3278. }
  3279. if (msAbs >= h) {
  3280. return plural(ms, msAbs, h, 'hour');
  3281. }
  3282. if (msAbs >= m) {
  3283. return plural(ms, msAbs, m, 'minute');
  3284. }
  3285. if (msAbs >= s) {
  3286. return plural(ms, msAbs, s, 'second');
  3287. }
  3288. return ms + ' ms';
  3289. }
  3290. /**
  3291. * Pluralization helper.
  3292. */
  3293. function plural(ms, msAbs, n, name) {
  3294. var isPlural = msAbs >= n * 1.5;
  3295. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  3296. }
  3297. },{}],55:[function(require,module,exports){
  3298. (function (process){(function (){
  3299. /* eslint-env browser */
  3300. /**
  3301. * This is the web browser implementation of `debug()`.
  3302. */
  3303. exports.formatArgs = formatArgs;
  3304. exports.save = save;
  3305. exports.load = load;
  3306. exports.useColors = useColors;
  3307. exports.storage = localstorage();
  3308. exports.destroy = (() => {
  3309. let warned = false;
  3310. return () => {
  3311. if (!warned) {
  3312. warned = true;
  3313. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  3314. }
  3315. };
  3316. })();
  3317. /**
  3318. * Colors.
  3319. */
  3320. exports.colors = [
  3321. '#0000CC',
  3322. '#0000FF',
  3323. '#0033CC',
  3324. '#0033FF',
  3325. '#0066CC',
  3326. '#0066FF',
  3327. '#0099CC',
  3328. '#0099FF',
  3329. '#00CC00',
  3330. '#00CC33',
  3331. '#00CC66',
  3332. '#00CC99',
  3333. '#00CCCC',
  3334. '#00CCFF',
  3335. '#3300CC',
  3336. '#3300FF',
  3337. '#3333CC',
  3338. '#3333FF',
  3339. '#3366CC',
  3340. '#3366FF',
  3341. '#3399CC',
  3342. '#3399FF',
  3343. '#33CC00',
  3344. '#33CC33',
  3345. '#33CC66',
  3346. '#33CC99',
  3347. '#33CCCC',
  3348. '#33CCFF',
  3349. '#6600CC',
  3350. '#6600FF',
  3351. '#6633CC',
  3352. '#6633FF',
  3353. '#66CC00',
  3354. '#66CC33',
  3355. '#9900CC',
  3356. '#9900FF',
  3357. '#9933CC',
  3358. '#9933FF',
  3359. '#99CC00',
  3360. '#99CC33',
  3361. '#CC0000',
  3362. '#CC0033',
  3363. '#CC0066',
  3364. '#CC0099',
  3365. '#CC00CC',
  3366. '#CC00FF',
  3367. '#CC3300',
  3368. '#CC3333',
  3369. '#CC3366',
  3370. '#CC3399',
  3371. '#CC33CC',
  3372. '#CC33FF',
  3373. '#CC6600',
  3374. '#CC6633',
  3375. '#CC9900',
  3376. '#CC9933',
  3377. '#CCCC00',
  3378. '#CCCC33',
  3379. '#FF0000',
  3380. '#FF0033',
  3381. '#FF0066',
  3382. '#FF0099',
  3383. '#FF00CC',
  3384. '#FF00FF',
  3385. '#FF3300',
  3386. '#FF3333',
  3387. '#FF3366',
  3388. '#FF3399',
  3389. '#FF33CC',
  3390. '#FF33FF',
  3391. '#FF6600',
  3392. '#FF6633',
  3393. '#FF9900',
  3394. '#FF9933',
  3395. '#FFCC00',
  3396. '#FFCC33'
  3397. ];
  3398. /**
  3399. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  3400. * and the Firebug extension (any Firefox version) are known
  3401. * to support "%c" CSS customizations.
  3402. *
  3403. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  3404. */
  3405. // eslint-disable-next-line complexity
  3406. function useColors() {
  3407. // NB: In an Electron preload script, document will be defined but not fully
  3408. // initialized. Since we know we're in Chrome, we'll just detect this case
  3409. // explicitly
  3410. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  3411. return true;
  3412. }
  3413. // Internet Explorer and Edge do not support colors.
  3414. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  3415. return false;
  3416. }
  3417. // Is webkit? http://stackoverflow.com/a/16459606/376773
  3418. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  3419. return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
  3420. // Is firebug? http://stackoverflow.com/a/398120/376773
  3421. (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
  3422. // Is firefox >= v31?
  3423. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  3424. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  3425. // Double check webkit in userAgent just in case we are in a worker
  3426. (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  3427. }
  3428. /**
  3429. * Colorize log arguments if enabled.
  3430. *
  3431. * @api public
  3432. */
  3433. function formatArgs(args) {
  3434. args[0] = (this.useColors ? '%c' : '') +
  3435. this.namespace +
  3436. (this.useColors ? ' %c' : ' ') +
  3437. args[0] +
  3438. (this.useColors ? '%c ' : ' ') +
  3439. '+' + module.exports.humanize(this.diff);
  3440. if (!this.useColors) {
  3441. return;
  3442. }
  3443. const c = 'color: ' + this.color;
  3444. args.splice(1, 0, c, 'color: inherit');
  3445. // The final "%c" is somewhat tricky, because there could be other
  3446. // arguments passed either before or after the %c, so we need to
  3447. // figure out the correct index to insert the CSS into
  3448. let index = 0;
  3449. let lastC = 0;
  3450. args[0].replace(/%[a-zA-Z%]/g, match => {
  3451. if (match === '%%') {
  3452. return;
  3453. }
  3454. index++;
  3455. if (match === '%c') {
  3456. // We only are interested in the *last* %c
  3457. // (the user may have provided their own)
  3458. lastC = index;
  3459. }
  3460. });
  3461. args.splice(lastC, 0, c);
  3462. }
  3463. /**
  3464. * Invokes `console.debug()` when available.
  3465. * No-op when `console.debug` is not a "function".
  3466. * If `console.debug` is not available, falls back
  3467. * to `console.log`.
  3468. *
  3469. * @api public
  3470. */
  3471. exports.log = console.debug || console.log || (() => {});
  3472. /**
  3473. * Save `namespaces`.
  3474. *
  3475. * @param {String} namespaces
  3476. * @api private
  3477. */
  3478. function save(namespaces) {
  3479. try {
  3480. if (namespaces) {
  3481. exports.storage.setItem('debug', namespaces);
  3482. } else {
  3483. exports.storage.removeItem('debug');
  3484. }
  3485. } catch (error) {
  3486. // Swallow
  3487. // XXX (@Qix-) should we be logging these?
  3488. }
  3489. }
  3490. /**
  3491. * Load `namespaces`.
  3492. *
  3493. * @return {String} returns the previously persisted debug modes
  3494. * @api private
  3495. */
  3496. function load() {
  3497. let r;
  3498. try {
  3499. r = exports.storage.getItem('debug');
  3500. } catch (error) {
  3501. // Swallow
  3502. // XXX (@Qix-) should we be logging these?
  3503. }
  3504. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  3505. if (!r && typeof process !== 'undefined' && 'env' in process) {
  3506. r = process.env.DEBUG;
  3507. }
  3508. return r;
  3509. }
  3510. /**
  3511. * Localstorage attempts to return the localstorage.
  3512. *
  3513. * This is necessary because safari throws
  3514. * when a user disables cookies/localstorage
  3515. * and you attempt to access it.
  3516. *
  3517. * @return {LocalStorage}
  3518. * @api private
  3519. */
  3520. function localstorage() {
  3521. try {
  3522. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  3523. // The Browser also has localStorage in the global context.
  3524. return localStorage;
  3525. } catch (error) {
  3526. // Swallow
  3527. // XXX (@Qix-) should we be logging these?
  3528. }
  3529. }
  3530. module.exports = require('./common')(exports);
  3531. const {formatters} = module.exports;
  3532. /**
  3533. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  3534. */
  3535. formatters.j = function (v) {
  3536. try {
  3537. return JSON.stringify(v);
  3538. } catch (error) {
  3539. return '[UnexpectedJSONParseError]: ' + error.message;
  3540. }
  3541. };
  3542. }).call(this)}).call(this,{ env: {} })
  3543. },{"./common":56}],56:[function(require,module,exports){
  3544. /**
  3545. * This is the common logic for both the Node.js and web browser
  3546. * implementations of `debug()`.
  3547. */
  3548. function setup(env) {
  3549. createDebug.debug = createDebug;
  3550. createDebug.default = createDebug;
  3551. createDebug.coerce = coerce;
  3552. createDebug.disable = disable;
  3553. createDebug.enable = enable;
  3554. createDebug.enabled = enabled;
  3555. createDebug.humanize = require('ms');
  3556. createDebug.destroy = destroy;
  3557. Object.keys(env).forEach(key => {
  3558. createDebug[key] = env[key];
  3559. });
  3560. /**
  3561. * The currently active debug mode names, and names to skip.
  3562. */
  3563. createDebug.names = [];
  3564. createDebug.skips = [];
  3565. /**
  3566. * Map of special "%n" handling functions, for the debug "format" argument.
  3567. *
  3568. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  3569. */
  3570. createDebug.formatters = {};
  3571. /**
  3572. * Selects a color for a debug namespace
  3573. * @param {String} namespace The namespace string for the debug instance to be colored
  3574. * @return {Number|String} An ANSI color code for the given namespace
  3575. * @api private
  3576. */
  3577. function selectColor(namespace) {
  3578. let hash = 0;
  3579. for (let i = 0; i < namespace.length; i++) {
  3580. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  3581. hash |= 0; // Convert to 32bit integer
  3582. }
  3583. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  3584. }
  3585. createDebug.selectColor = selectColor;
  3586. /**
  3587. * Create a debugger with the given `namespace`.
  3588. *
  3589. * @param {String} namespace
  3590. * @return {Function}
  3591. * @api public
  3592. */
  3593. function createDebug(namespace) {
  3594. let prevTime;
  3595. let enableOverride = null;
  3596. let namespacesCache;
  3597. let enabledCache;
  3598. function debug(...args) {
  3599. // Disabled?
  3600. if (!debug.enabled) {
  3601. return;
  3602. }
  3603. const self = debug;
  3604. // Set `diff` timestamp
  3605. const curr = Number(new Date());
  3606. const ms = curr - (prevTime || curr);
  3607. self.diff = ms;
  3608. self.prev = prevTime;
  3609. self.curr = curr;
  3610. prevTime = curr;
  3611. args[0] = createDebug.coerce(args[0]);
  3612. if (typeof args[0] !== 'string') {
  3613. // Anything else let's inspect with %O
  3614. args.unshift('%O');
  3615. }
  3616. // Apply any `formatters` transformations
  3617. let index = 0;
  3618. args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
  3619. // If we encounter an escaped % then don't increase the array index
  3620. if (match === '%%') {
  3621. return '%';
  3622. }
  3623. index++;
  3624. const formatter = createDebug.formatters[format];
  3625. if (typeof formatter === 'function') {
  3626. const val = args[index];
  3627. match = formatter.call(self, val);
  3628. // Now we need to remove `args[index]` since it's inlined in the `format`
  3629. args.splice(index, 1);
  3630. index--;
  3631. }
  3632. return match;
  3633. });
  3634. // Apply env-specific formatting (colors, etc.)
  3635. createDebug.formatArgs.call(self, args);
  3636. const logFn = self.log || createDebug.log;
  3637. logFn.apply(self, args);
  3638. }
  3639. debug.namespace = namespace;
  3640. debug.useColors = createDebug.useColors();
  3641. debug.color = createDebug.selectColor(namespace);
  3642. debug.extend = extend;
  3643. debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
  3644. Object.defineProperty(debug, 'enabled', {
  3645. enumerable: true,
  3646. configurable: false,
  3647. get: () => {
  3648. if (enableOverride !== null) {
  3649. return enableOverride;
  3650. }
  3651. if (namespacesCache !== createDebug.namespaces) {
  3652. namespacesCache = createDebug.namespaces;
  3653. enabledCache = createDebug.enabled(namespace);
  3654. }
  3655. return enabledCache;
  3656. },
  3657. set: v => {
  3658. enableOverride = v;
  3659. }
  3660. });
  3661. // Env-specific initialization logic for debug instances
  3662. if (typeof createDebug.init === 'function') {
  3663. createDebug.init(debug);
  3664. }
  3665. return debug;
  3666. }
  3667. function extend(namespace, delimiter) {
  3668. const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  3669. newDebug.log = this.log;
  3670. return newDebug;
  3671. }
  3672. /**
  3673. * Enables a debug mode by namespaces. This can include modes
  3674. * separated by a colon and wildcards.
  3675. *
  3676. * @param {String} namespaces
  3677. * @api public
  3678. */
  3679. function enable(namespaces) {
  3680. createDebug.save(namespaces);
  3681. createDebug.namespaces = namespaces;
  3682. createDebug.names = [];
  3683. createDebug.skips = [];
  3684. let i;
  3685. const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  3686. const len = split.length;
  3687. for (i = 0; i < len; i++) {
  3688. if (!split[i]) {
  3689. // ignore empty strings
  3690. continue;
  3691. }
  3692. namespaces = split[i].replace(/\*/g, '.*?');
  3693. if (namespaces[0] === '-') {
  3694. createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  3695. } else {
  3696. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  3697. }
  3698. }
  3699. }
  3700. /**
  3701. * Disable debug output.
  3702. *
  3703. * @return {String} namespaces
  3704. * @api public
  3705. */
  3706. function disable() {
  3707. const namespaces = [
  3708. ...createDebug.names.map(toNamespace),
  3709. ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
  3710. ].join(',');
  3711. createDebug.enable('');
  3712. return namespaces;
  3713. }
  3714. /**
  3715. * Returns true if the given mode name is enabled, false otherwise.
  3716. *
  3717. * @param {String} name
  3718. * @return {Boolean}
  3719. * @api public
  3720. */
  3721. function enabled(name) {
  3722. if (name[name.length - 1] === '*') {
  3723. return true;
  3724. }
  3725. let i;
  3726. let len;
  3727. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  3728. if (createDebug.skips[i].test(name)) {
  3729. return false;
  3730. }
  3731. }
  3732. for (i = 0, len = createDebug.names.length; i < len; i++) {
  3733. if (createDebug.names[i].test(name)) {
  3734. return true;
  3735. }
  3736. }
  3737. return false;
  3738. }
  3739. /**
  3740. * Convert regexp to namespace
  3741. *
  3742. * @param {RegExp} regxep
  3743. * @return {String} namespace
  3744. * @api private
  3745. */
  3746. function toNamespace(regexp) {
  3747. return regexp.toString()
  3748. .substring(2, regexp.toString().length - 2)
  3749. .replace(/\.\*\?$/, '*');
  3750. }
  3751. /**
  3752. * Coerce `val`.
  3753. *
  3754. * @param {Mixed} val
  3755. * @return {Mixed}
  3756. * @api private
  3757. */
  3758. function coerce(val) {
  3759. if (val instanceof Error) {
  3760. return val.stack || val.message;
  3761. }
  3762. return val;
  3763. }
  3764. /**
  3765. * XXX DO NOT USE. This is a temporary stub function.
  3766. * XXX It WILL be removed in the next major release.
  3767. */
  3768. function destroy() {
  3769. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  3770. }
  3771. createDebug.enable(createDebug.load());
  3772. return createDebug;
  3773. }
  3774. module.exports = setup;
  3775. },{"ms":54}],57:[function(require,module,exports){
  3776. if (typeof Object.create === 'function') {
  3777. // implementation from standard node.js 'util' module
  3778. module.exports = function inherits(ctor, superCtor) {
  3779. if (superCtor) {
  3780. ctor.super_ = superCtor
  3781. ctor.prototype = Object.create(superCtor.prototype, {
  3782. constructor: {
  3783. value: ctor,
  3784. enumerable: false,
  3785. writable: true,
  3786. configurable: true
  3787. }
  3788. })
  3789. }
  3790. };
  3791. } else {
  3792. // old school shim for old browsers
  3793. module.exports = function inherits(ctor, superCtor) {
  3794. if (superCtor) {
  3795. ctor.super_ = superCtor
  3796. var TempCtor = function () {}
  3797. TempCtor.prototype = superCtor.prototype
  3798. ctor.prototype = new TempCtor()
  3799. ctor.prototype.constructor = ctor
  3800. }
  3801. }
  3802. }
  3803. },{}],58:[function(require,module,exports){
  3804. 'use strict';
  3805. var has = Object.prototype.hasOwnProperty
  3806. , undef;
  3807. /**
  3808. * Decode a URI encoded string.
  3809. *
  3810. * @param {String} input The URI encoded string.
  3811. * @returns {String|Null} The decoded string.
  3812. * @api private
  3813. */
  3814. function decode(input) {
  3815. try {
  3816. return decodeURIComponent(input.replace(/\+/g, ' '));
  3817. } catch (e) {
  3818. return null;
  3819. }
  3820. }
  3821. /**
  3822. * Attempts to encode a given input.
  3823. *
  3824. * @param {String} input The string that needs to be encoded.
  3825. * @returns {String|Null} The encoded string.
  3826. * @api private
  3827. */
  3828. function encode(input) {
  3829. try {
  3830. return encodeURIComponent(input);
  3831. } catch (e) {
  3832. return null;
  3833. }
  3834. }
  3835. /**
  3836. * Simple query string parser.
  3837. *
  3838. * @param {String} query The query string that needs to be parsed.
  3839. * @returns {Object}
  3840. * @api public
  3841. */
  3842. function querystring(query) {
  3843. var parser = /([^=?&]+)=?([^&]*)/g
  3844. , result = {}
  3845. , part;
  3846. while (part = parser.exec(query)) {
  3847. var key = decode(part[1])
  3848. , value = decode(part[2]);
  3849. //
  3850. // Prevent overriding of existing properties. This ensures that build-in
  3851. // methods like `toString` or __proto__ are not overriden by malicious
  3852. // querystrings.
  3853. //
  3854. // In the case if failed decoding, we want to omit the key/value pairs
  3855. // from the result.
  3856. //
  3857. if (key === null || value === null || key in result) continue;
  3858. result[key] = value;
  3859. }
  3860. return result;
  3861. }
  3862. /**
  3863. * Transform a query string to an object.
  3864. *
  3865. * @param {Object} obj Object that should be transformed.
  3866. * @param {String} prefix Optional prefix.
  3867. * @returns {String}
  3868. * @api public
  3869. */
  3870. function querystringify(obj, prefix) {
  3871. prefix = prefix || '';
  3872. var pairs = []
  3873. , value
  3874. , key;
  3875. //
  3876. // Optionally prefix with a '?' if needed
  3877. //
  3878. if ('string' !== typeof prefix) prefix = '?';
  3879. for (key in obj) {
  3880. if (has.call(obj, key)) {
  3881. value = obj[key];
  3882. //
  3883. // Edge cases where we actually want to encode the value to an empty
  3884. // string instead of the stringified value.
  3885. //
  3886. if (!value && (value === null || value === undef || isNaN(value))) {
  3887. value = '';
  3888. }
  3889. key = encodeURIComponent(key);
  3890. value = encodeURIComponent(value);
  3891. //
  3892. // If we failed to encode the strings, we should bail out as we don't
  3893. // want to add invalid strings to the query.
  3894. //
  3895. if (key === null || value === null) continue;
  3896. pairs.push(key +'='+ value);
  3897. }
  3898. }
  3899. return pairs.length ? prefix + pairs.join('&') : '';
  3900. }
  3901. //
  3902. // Expose the module.
  3903. //
  3904. exports.stringify = querystringify;
  3905. exports.parse = querystring;
  3906. },{}],59:[function(require,module,exports){
  3907. 'use strict';
  3908. /**
  3909. * Check if we're required to add a port number.
  3910. *
  3911. * @see https://url.spec.whatwg.org/#default-port
  3912. * @param {Number|String} port Port number we need to check
  3913. * @param {String} protocol Protocol we need to check against.
  3914. * @returns {Boolean} Is it a default port for the given protocol
  3915. * @api private
  3916. */
  3917. module.exports = function required(port, protocol) {
  3918. protocol = protocol.split(':')[0];
  3919. port = +port;
  3920. if (!port) return false;
  3921. switch (protocol) {
  3922. case 'http':
  3923. case 'ws':
  3924. return port !== 80;
  3925. case 'https':
  3926. case 'wss':
  3927. return port !== 443;
  3928. case 'ftp':
  3929. return port !== 21;
  3930. case 'gopher':
  3931. return port !== 70;
  3932. case 'file':
  3933. return false;
  3934. }
  3935. return port !== 0;
  3936. };
  3937. },{}],60:[function(require,module,exports){
  3938. (function (global){(function (){
  3939. 'use strict';
  3940. var required = require('requires-port')
  3941. , qs = require('querystringify')
  3942. , controlOrWhitespace = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/
  3943. , CRHTLF = /[\n\r\t]/g
  3944. , slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//
  3945. , port = /:\d+$/
  3946. , protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i
  3947. , windowsDriveLetter = /^[a-zA-Z]:/;
  3948. /**
  3949. * Remove control characters and whitespace from the beginning of a string.
  3950. *
  3951. * @param {Object|String} str String to trim.
  3952. * @returns {String} A new string representing `str` stripped of control
  3953. * characters and whitespace from its beginning.
  3954. * @public
  3955. */
  3956. function trimLeft(str) {
  3957. return (str ? str : '').toString().replace(controlOrWhitespace, '');
  3958. }
  3959. /**
  3960. * These are the parse rules for the URL parser, it informs the parser
  3961. * about:
  3962. *
  3963. * 0. The char it Needs to parse, if it's a string it should be done using
  3964. * indexOf, RegExp using exec and NaN means set as current value.
  3965. * 1. The property we should set when parsing this value.
  3966. * 2. Indication if it's backwards or forward parsing, when set as number it's
  3967. * the value of extra chars that should be split off.
  3968. * 3. Inherit from location if non existing in the parser.
  3969. * 4. `toLowerCase` the resulting value.
  3970. */
  3971. var rules = [
  3972. ['#', 'hash'], // Extract from the back.
  3973. ['?', 'query'], // Extract from the back.
  3974. function sanitize(address, url) { // Sanitize what is left of the address
  3975. return isSpecial(url.protocol) ? address.replace(/\\/g, '/') : address;
  3976. },
  3977. ['/', 'pathname'], // Extract from the back.
  3978. ['@', 'auth', 1], // Extract from the front.
  3979. [NaN, 'host', undefined, 1, 1], // Set left over value.
  3980. [/:(\d*)$/, 'port', undefined, 1], // RegExp the back.
  3981. [NaN, 'hostname', undefined, 1, 1] // Set left over.
  3982. ];
  3983. /**
  3984. * These properties should not be copied or inherited from. This is only needed
  3985. * for all non blob URL's as a blob URL does not include a hash, only the
  3986. * origin.
  3987. *
  3988. * @type {Object}
  3989. * @private
  3990. */
  3991. var ignore = { hash: 1, query: 1 };
  3992. /**
  3993. * The location object differs when your code is loaded through a normal page,
  3994. * Worker or through a worker using a blob. And with the blobble begins the
  3995. * trouble as the location object will contain the URL of the blob, not the
  3996. * location of the page where our code is loaded in. The actual origin is
  3997. * encoded in the `pathname` so we can thankfully generate a good "default"
  3998. * location from it so we can generate proper relative URL's again.
  3999. *
  4000. * @param {Object|String} loc Optional default location object.
  4001. * @returns {Object} lolcation object.
  4002. * @public
  4003. */
  4004. function lolcation(loc) {
  4005. var globalVar;
  4006. if (typeof window !== 'undefined') globalVar = window;
  4007. else if (typeof global !== 'undefined') globalVar = global;
  4008. else if (typeof self !== 'undefined') globalVar = self;
  4009. else globalVar = {};
  4010. var location = globalVar.location || {};
  4011. loc = loc || location;
  4012. var finaldestination = {}
  4013. , type = typeof loc
  4014. , key;
  4015. if ('blob:' === loc.protocol) {
  4016. finaldestination = new Url(unescape(loc.pathname), {});
  4017. } else if ('string' === type) {
  4018. finaldestination = new Url(loc, {});
  4019. for (key in ignore) delete finaldestination[key];
  4020. } else if ('object' === type) {
  4021. for (key in loc) {
  4022. if (key in ignore) continue;
  4023. finaldestination[key] = loc[key];
  4024. }
  4025. if (finaldestination.slashes === undefined) {
  4026. finaldestination.slashes = slashes.test(loc.href);
  4027. }
  4028. }
  4029. return finaldestination;
  4030. }
  4031. /**
  4032. * Check whether a protocol scheme is special.
  4033. *
  4034. * @param {String} The protocol scheme of the URL
  4035. * @return {Boolean} `true` if the protocol scheme is special, else `false`
  4036. * @private
  4037. */
  4038. function isSpecial(scheme) {
  4039. return (
  4040. scheme === 'file:' ||
  4041. scheme === 'ftp:' ||
  4042. scheme === 'http:' ||
  4043. scheme === 'https:' ||
  4044. scheme === 'ws:' ||
  4045. scheme === 'wss:'
  4046. );
  4047. }
  4048. /**
  4049. * @typedef ProtocolExtract
  4050. * @type Object
  4051. * @property {String} protocol Protocol matched in the URL, in lowercase.
  4052. * @property {Boolean} slashes `true` if protocol is followed by "//", else `false`.
  4053. * @property {String} rest Rest of the URL that is not part of the protocol.
  4054. */
  4055. /**
  4056. * Extract protocol information from a URL with/without double slash ("//").
  4057. *
  4058. * @param {String} address URL we want to extract from.
  4059. * @param {Object} location
  4060. * @return {ProtocolExtract} Extracted information.
  4061. * @private
  4062. */
  4063. function extractProtocol(address, location) {
  4064. address = trimLeft(address);
  4065. address = address.replace(CRHTLF, '');
  4066. location = location || {};
  4067. var match = protocolre.exec(address);
  4068. var protocol = match[1] ? match[1].toLowerCase() : '';
  4069. var forwardSlashes = !!match[2];
  4070. var otherSlashes = !!match[3];
  4071. var slashesCount = 0;
  4072. var rest;
  4073. if (forwardSlashes) {
  4074. if (otherSlashes) {
  4075. rest = match[2] + match[3] + match[4];
  4076. slashesCount = match[2].length + match[3].length;
  4077. } else {
  4078. rest = match[2] + match[4];
  4079. slashesCount = match[2].length;
  4080. }
  4081. } else {
  4082. if (otherSlashes) {
  4083. rest = match[3] + match[4];
  4084. slashesCount = match[3].length;
  4085. } else {
  4086. rest = match[4]
  4087. }
  4088. }
  4089. if (protocol === 'file:') {
  4090. if (slashesCount >= 2) {
  4091. rest = rest.slice(2);
  4092. }
  4093. } else if (isSpecial(protocol)) {
  4094. rest = match[4];
  4095. } else if (protocol) {
  4096. if (forwardSlashes) {
  4097. rest = rest.slice(2);
  4098. }
  4099. } else if (slashesCount >= 2 && isSpecial(location.protocol)) {
  4100. rest = match[4];
  4101. }
  4102. return {
  4103. protocol: protocol,
  4104. slashes: forwardSlashes || isSpecial(protocol),
  4105. slashesCount: slashesCount,
  4106. rest: rest
  4107. };
  4108. }
  4109. /**
  4110. * Resolve a relative URL pathname against a base URL pathname.
  4111. *
  4112. * @param {String} relative Pathname of the relative URL.
  4113. * @param {String} base Pathname of the base URL.
  4114. * @return {String} Resolved pathname.
  4115. * @private
  4116. */
  4117. function resolve(relative, base) {
  4118. if (relative === '') return base;
  4119. var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
  4120. , i = path.length
  4121. , last = path[i - 1]
  4122. , unshift = false
  4123. , up = 0;
  4124. while (i--) {
  4125. if (path[i] === '.') {
  4126. path.splice(i, 1);
  4127. } else if (path[i] === '..') {
  4128. path.splice(i, 1);
  4129. up++;
  4130. } else if (up) {
  4131. if (i === 0) unshift = true;
  4132. path.splice(i, 1);
  4133. up--;
  4134. }
  4135. }
  4136. if (unshift) path.unshift('');
  4137. if (last === '.' || last === '..') path.push('');
  4138. return path.join('/');
  4139. }
  4140. /**
  4141. * The actual URL instance. Instead of returning an object we've opted-in to
  4142. * create an actual constructor as it's much more memory efficient and
  4143. * faster and it pleases my OCD.
  4144. *
  4145. * It is worth noting that we should not use `URL` as class name to prevent
  4146. * clashes with the global URL instance that got introduced in browsers.
  4147. *
  4148. * @constructor
  4149. * @param {String} address URL we want to parse.
  4150. * @param {Object|String} [location] Location defaults for relative paths.
  4151. * @param {Boolean|Function} [parser] Parser for the query string.
  4152. * @private
  4153. */
  4154. function Url(address, location, parser) {
  4155. address = trimLeft(address);
  4156. address = address.replace(CRHTLF, '');
  4157. if (!(this instanceof Url)) {
  4158. return new Url(address, location, parser);
  4159. }
  4160. var relative, extracted, parse, instruction, index, key
  4161. , instructions = rules.slice()
  4162. , type = typeof location
  4163. , url = this
  4164. , i = 0;
  4165. //
  4166. // The following if statements allows this module two have compatibility with
  4167. // 2 different API:
  4168. //
  4169. // 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments
  4170. // where the boolean indicates that the query string should also be parsed.
  4171. //
  4172. // 2. The `URL` interface of the browser which accepts a URL, object as
  4173. // arguments. The supplied object will be used as default values / fall-back
  4174. // for relative paths.
  4175. //
  4176. if ('object' !== type && 'string' !== type) {
  4177. parser = location;
  4178. location = null;
  4179. }
  4180. if (parser && 'function' !== typeof parser) parser = qs.parse;
  4181. location = lolcation(location);
  4182. //
  4183. // Extract protocol information before running the instructions.
  4184. //
  4185. extracted = extractProtocol(address || '', location);
  4186. relative = !extracted.protocol && !extracted.slashes;
  4187. url.slashes = extracted.slashes || relative && location.slashes;
  4188. url.protocol = extracted.protocol || location.protocol || '';
  4189. address = extracted.rest;
  4190. //
  4191. // When the authority component is absent the URL starts with a path
  4192. // component.
  4193. //
  4194. if (
  4195. extracted.protocol === 'file:' && (
  4196. extracted.slashesCount !== 2 || windowsDriveLetter.test(address)) ||
  4197. (!extracted.slashes &&
  4198. (extracted.protocol ||
  4199. extracted.slashesCount < 2 ||
  4200. !isSpecial(url.protocol)))
  4201. ) {
  4202. instructions[3] = [/(.*)/, 'pathname'];
  4203. }
  4204. for (; i < instructions.length; i++) {
  4205. instruction = instructions[i];
  4206. if (typeof instruction === 'function') {
  4207. address = instruction(address, url);
  4208. continue;
  4209. }
  4210. parse = instruction[0];
  4211. key = instruction[1];
  4212. if (parse !== parse) {
  4213. url[key] = address;
  4214. } else if ('string' === typeof parse) {
  4215. index = parse === '@'
  4216. ? address.lastIndexOf(parse)
  4217. : address.indexOf(parse);
  4218. if (~index) {
  4219. if ('number' === typeof instruction[2]) {
  4220. url[key] = address.slice(0, index);
  4221. address = address.slice(index + instruction[2]);
  4222. } else {
  4223. url[key] = address.slice(index);
  4224. address = address.slice(0, index);
  4225. }
  4226. }
  4227. } else if ((index = parse.exec(address))) {
  4228. url[key] = index[1];
  4229. address = address.slice(0, index.index);
  4230. }
  4231. url[key] = url[key] || (
  4232. relative && instruction[3] ? location[key] || '' : ''
  4233. );
  4234. //
  4235. // Hostname, host and protocol should be lowercased so they can be used to
  4236. // create a proper `origin`.
  4237. //
  4238. if (instruction[4]) url[key] = url[key].toLowerCase();
  4239. }
  4240. //
  4241. // Also parse the supplied query string in to an object. If we're supplied
  4242. // with a custom parser as function use that instead of the default build-in
  4243. // parser.
  4244. //
  4245. if (parser) url.query = parser(url.query);
  4246. //
  4247. // If the URL is relative, resolve the pathname against the base URL.
  4248. //
  4249. if (
  4250. relative
  4251. && location.slashes
  4252. && url.pathname.charAt(0) !== '/'
  4253. && (url.pathname !== '' || location.pathname !== '')
  4254. ) {
  4255. url.pathname = resolve(url.pathname, location.pathname);
  4256. }
  4257. //
  4258. // Default to a / for pathname if none exists. This normalizes the URL
  4259. // to always have a /
  4260. //
  4261. if (url.pathname.charAt(0) !== '/' && isSpecial(url.protocol)) {
  4262. url.pathname = '/' + url.pathname;
  4263. }
  4264. //
  4265. // We should not add port numbers if they are already the default port number
  4266. // for a given protocol. As the host also contains the port number we're going
  4267. // override it with the hostname which contains no port number.
  4268. //
  4269. if (!required(url.port, url.protocol)) {
  4270. url.host = url.hostname;
  4271. url.port = '';
  4272. }
  4273. //
  4274. // Parse down the `auth` for the username and password.
  4275. //
  4276. url.username = url.password = '';
  4277. if (url.auth) {
  4278. index = url.auth.indexOf(':');
  4279. if (~index) {
  4280. url.username = url.auth.slice(0, index);
  4281. url.username = encodeURIComponent(decodeURIComponent(url.username));
  4282. url.password = url.auth.slice(index + 1);
  4283. url.password = encodeURIComponent(decodeURIComponent(url.password))
  4284. } else {
  4285. url.username = encodeURIComponent(decodeURIComponent(url.auth));
  4286. }
  4287. url.auth = url.password ? url.username +':'+ url.password : url.username;
  4288. }
  4289. url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
  4290. ? url.protocol +'//'+ url.host
  4291. : 'null';
  4292. //
  4293. // The href is just the compiled result.
  4294. //
  4295. url.href = url.toString();
  4296. }
  4297. /**
  4298. * This is convenience method for changing properties in the URL instance to
  4299. * insure that they all propagate correctly.
  4300. *
  4301. * @param {String} part Property we need to adjust.
  4302. * @param {Mixed} value The newly assigned value.
  4303. * @param {Boolean|Function} fn When setting the query, it will be the function
  4304. * used to parse the query.
  4305. * When setting the protocol, double slash will be
  4306. * removed from the final url if it is true.
  4307. * @returns {URL} URL instance for chaining.
  4308. * @public
  4309. */
  4310. function set(part, value, fn) {
  4311. var url = this;
  4312. switch (part) {
  4313. case 'query':
  4314. if ('string' === typeof value && value.length) {
  4315. value = (fn || qs.parse)(value);
  4316. }
  4317. url[part] = value;
  4318. break;
  4319. case 'port':
  4320. url[part] = value;
  4321. if (!required(value, url.protocol)) {
  4322. url.host = url.hostname;
  4323. url[part] = '';
  4324. } else if (value) {
  4325. url.host = url.hostname +':'+ value;
  4326. }
  4327. break;
  4328. case 'hostname':
  4329. url[part] = value;
  4330. if (url.port) value += ':'+ url.port;
  4331. url.host = value;
  4332. break;
  4333. case 'host':
  4334. url[part] = value;
  4335. if (port.test(value)) {
  4336. value = value.split(':');
  4337. url.port = value.pop();
  4338. url.hostname = value.join(':');
  4339. } else {
  4340. url.hostname = value;
  4341. url.port = '';
  4342. }
  4343. break;
  4344. case 'protocol':
  4345. url.protocol = value.toLowerCase();
  4346. url.slashes = !fn;
  4347. break;
  4348. case 'pathname':
  4349. case 'hash':
  4350. if (value) {
  4351. var char = part === 'pathname' ? '/' : '#';
  4352. url[part] = value.charAt(0) !== char ? char + value : value;
  4353. } else {
  4354. url[part] = value;
  4355. }
  4356. break;
  4357. case 'username':
  4358. case 'password':
  4359. url[part] = encodeURIComponent(value);
  4360. break;
  4361. case 'auth':
  4362. var index = value.indexOf(':');
  4363. if (~index) {
  4364. url.username = value.slice(0, index);
  4365. url.username = encodeURIComponent(decodeURIComponent(url.username));
  4366. url.password = value.slice(index + 1);
  4367. url.password = encodeURIComponent(decodeURIComponent(url.password));
  4368. } else {
  4369. url.username = encodeURIComponent(decodeURIComponent(value));
  4370. }
  4371. }
  4372. for (var i = 0; i < rules.length; i++) {
  4373. var ins = rules[i];
  4374. if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
  4375. }
  4376. url.auth = url.password ? url.username +':'+ url.password : url.username;
  4377. url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host
  4378. ? url.protocol +'//'+ url.host
  4379. : 'null';
  4380. url.href = url.toString();
  4381. return url;
  4382. }
  4383. /**
  4384. * Transform the properties back in to a valid and full URL string.
  4385. *
  4386. * @param {Function} stringify Optional query stringify function.
  4387. * @returns {String} Compiled version of the URL.
  4388. * @public
  4389. */
  4390. function toString(stringify) {
  4391. if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify;
  4392. var query
  4393. , url = this
  4394. , host = url.host
  4395. , protocol = url.protocol;
  4396. if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
  4397. var result =
  4398. protocol +
  4399. ((url.protocol && url.slashes) || isSpecial(url.protocol) ? '//' : '');
  4400. if (url.username) {
  4401. result += url.username;
  4402. if (url.password) result += ':'+ url.password;
  4403. result += '@';
  4404. } else if (url.password) {
  4405. result += ':'+ url.password;
  4406. result += '@';
  4407. } else if (
  4408. url.protocol !== 'file:' &&
  4409. isSpecial(url.protocol) &&
  4410. !host &&
  4411. url.pathname !== '/'
  4412. ) {
  4413. //
  4414. // Add back the empty userinfo, otherwise the original invalid URL
  4415. // might be transformed into a valid one with `url.pathname` as host.
  4416. //
  4417. result += '@';
  4418. }
  4419. //
  4420. // Trailing colon is removed from `url.host` when it is parsed. If it still
  4421. // ends with a colon, then add back the trailing colon that was removed. This
  4422. // prevents an invalid URL from being transformed into a valid one.
  4423. //
  4424. if (host[host.length - 1] === ':' || (port.test(url.hostname) && !url.port)) {
  4425. host += ':';
  4426. }
  4427. result += host + url.pathname;
  4428. query = 'object' === typeof url.query ? stringify(url.query) : url.query;
  4429. if (query) result += '?' !== query.charAt(0) ? '?'+ query : query;
  4430. if (url.hash) result += url.hash;
  4431. return result;
  4432. }
  4433. Url.prototype = { set: set, toString: toString };
  4434. //
  4435. // Expose the URL parser and some additional properties that might be useful for
  4436. // others or testing.
  4437. //
  4438. Url.extractProtocol = extractProtocol;
  4439. Url.location = lolcation;
  4440. Url.trimLeft = trimLeft;
  4441. Url.qs = qs;
  4442. module.exports = Url;
  4443. }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4444. },{"querystringify":58,"requires-port":59}]},{},[1])(1)
  4445. });
  4446. //# sourceMappingURL=sockjs.js.map