sockjs.js 176 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725
  1. /* sockjs-client v1.1.2 | 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 e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  3. (function (global){
  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,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":56}],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":56}],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":56}],7:[function(require,module,exports){
  161. 'use strict';
  162. var JSON3 = require('json3')
  163. , iframeUtils = require('./utils/iframe')
  164. ;
  165. function FacadeJS(transport) {
  166. this._transport = transport;
  167. transport.on('message', this._transportMessage.bind(this));
  168. transport.on('close', this._transportClose.bind(this));
  169. }
  170. FacadeJS.prototype._transportClose = function(code, reason) {
  171. iframeUtils.postMessage('c', JSON3.stringify([code, reason]));
  172. };
  173. FacadeJS.prototype._transportMessage = function(frame) {
  174. iframeUtils.postMessage('t', frame);
  175. };
  176. FacadeJS.prototype._send = function(data) {
  177. this._transport.send(data);
  178. };
  179. FacadeJS.prototype._close = function() {
  180. this._transport.close();
  181. this._transport.removeAllListeners();
  182. };
  183. module.exports = FacadeJS;
  184. },{"./utils/iframe":47,"json3":57}],8:[function(require,module,exports){
  185. (function (process){
  186. 'use strict';
  187. var urlUtils = require('./utils/url')
  188. , eventUtils = require('./utils/event')
  189. , JSON3 = require('json3')
  190. , FacadeJS = require('./facade')
  191. , InfoIframeReceiver = require('./info-iframe-receiver')
  192. , iframeUtils = require('./utils/iframe')
  193. , loc = require('./location')
  194. ;
  195. var debug = function() {};
  196. if (process.env.NODE_ENV !== 'production') {
  197. debug = require('debug')('sockjs-client:iframe-bootstrap');
  198. }
  199. module.exports = function(SockJS, availableTransports) {
  200. var transportMap = {};
  201. availableTransports.forEach(function(at) {
  202. if (at.facadeTransport) {
  203. transportMap[at.facadeTransport.transportName] = at.facadeTransport;
  204. }
  205. });
  206. // hard-coded for the info iframe
  207. // TODO see if we can make this more dynamic
  208. transportMap[InfoIframeReceiver.transportName] = InfoIframeReceiver;
  209. var parentOrigin;
  210. /* eslint-disable camelcase */
  211. SockJS.bootstrap_iframe = function() {
  212. /* eslint-enable camelcase */
  213. var facade;
  214. iframeUtils.currentWindowId = loc.hash.slice(1);
  215. var onMessage = function(e) {
  216. if (e.source !== parent) {
  217. return;
  218. }
  219. if (typeof parentOrigin === 'undefined') {
  220. parentOrigin = e.origin;
  221. }
  222. if (e.origin !== parentOrigin) {
  223. return;
  224. }
  225. var iframeMessage;
  226. try {
  227. iframeMessage = JSON3.parse(e.data);
  228. } catch (ignored) {
  229. debug('bad json', e.data);
  230. return;
  231. }
  232. if (iframeMessage.windowId !== iframeUtils.currentWindowId) {
  233. return;
  234. }
  235. switch (iframeMessage.type) {
  236. case 's':
  237. var p;
  238. try {
  239. p = JSON3.parse(iframeMessage.data);
  240. } catch (ignored) {
  241. debug('bad json', iframeMessage.data);
  242. break;
  243. }
  244. var version = p[0];
  245. var transport = p[1];
  246. var transUrl = p[2];
  247. var baseUrl = p[3];
  248. debug(version, transport, transUrl, baseUrl);
  249. // change this to semver logic
  250. if (version !== SockJS.version) {
  251. throw new Error('Incompatible SockJS! Main site uses:' +
  252. ' "' + version + '", the iframe:' +
  253. ' "' + SockJS.version + '".');
  254. }
  255. if (!urlUtils.isOriginEqual(transUrl, loc.href) ||
  256. !urlUtils.isOriginEqual(baseUrl, loc.href)) {
  257. throw new Error('Can\'t connect to different domain from within an ' +
  258. 'iframe. (' + loc.href + ', ' + transUrl + ', ' + baseUrl + ')');
  259. }
  260. facade = new FacadeJS(new transportMap[transport](transUrl, baseUrl));
  261. break;
  262. case 'm':
  263. facade._send(iframeMessage.data);
  264. break;
  265. case 'c':
  266. if (facade) {
  267. facade._close();
  268. }
  269. facade = null;
  270. break;
  271. }
  272. };
  273. eventUtils.attachEvent('message', onMessage);
  274. // Start
  275. iframeUtils.postMessage('s');
  276. };
  277. };
  278. }).call(this,{ env: {} })
  279. },{"./facade":7,"./info-iframe-receiver":10,"./location":13,"./utils/event":46,"./utils/iframe":47,"./utils/url":52,"debug":54,"json3":57}],9:[function(require,module,exports){
  280. (function (process){
  281. 'use strict';
  282. var EventEmitter = require('events').EventEmitter
  283. , inherits = require('inherits')
  284. , JSON3 = require('json3')
  285. , objectUtils = require('./utils/object')
  286. ;
  287. var debug = function() {};
  288. if (process.env.NODE_ENV !== 'production') {
  289. debug = require('debug')('sockjs-client:info-ajax');
  290. }
  291. function InfoAjax(url, AjaxObject) {
  292. EventEmitter.call(this);
  293. var self = this;
  294. var t0 = +new Date();
  295. this.xo = new AjaxObject('GET', url);
  296. this.xo.once('finish', function(status, text) {
  297. var info, rtt;
  298. if (status === 200) {
  299. rtt = (+new Date()) - t0;
  300. if (text) {
  301. try {
  302. info = JSON3.parse(text);
  303. } catch (e) {
  304. debug('bad json', text);
  305. }
  306. }
  307. if (!objectUtils.isObject(info)) {
  308. info = {};
  309. }
  310. }
  311. self.emit('finish', info, rtt);
  312. self.removeAllListeners();
  313. });
  314. }
  315. inherits(InfoAjax, EventEmitter);
  316. InfoAjax.prototype.close = function() {
  317. this.removeAllListeners();
  318. this.xo.close();
  319. };
  320. module.exports = InfoAjax;
  321. }).call(this,{ env: {} })
  322. },{"./utils/object":49,"debug":54,"events":3,"inherits":56,"json3":57}],10:[function(require,module,exports){
  323. 'use strict';
  324. var inherits = require('inherits')
  325. , EventEmitter = require('events').EventEmitter
  326. , JSON3 = require('json3')
  327. , XHRLocalObject = require('./transport/sender/xhr-local')
  328. , InfoAjax = require('./info-ajax')
  329. ;
  330. function InfoReceiverIframe(transUrl) {
  331. var self = this;
  332. EventEmitter.call(this);
  333. this.ir = new InfoAjax(transUrl, XHRLocalObject);
  334. this.ir.once('finish', function(info, rtt) {
  335. self.ir = null;
  336. self.emit('message', JSON3.stringify([info, rtt]));
  337. });
  338. }
  339. inherits(InfoReceiverIframe, EventEmitter);
  340. InfoReceiverIframe.transportName = 'iframe-info-receiver';
  341. InfoReceiverIframe.prototype.close = function() {
  342. if (this.ir) {
  343. this.ir.close();
  344. this.ir = null;
  345. }
  346. this.removeAllListeners();
  347. };
  348. module.exports = InfoReceiverIframe;
  349. },{"./info-ajax":9,"./transport/sender/xhr-local":37,"events":3,"inherits":56,"json3":57}],11:[function(require,module,exports){
  350. (function (process,global){
  351. 'use strict';
  352. var EventEmitter = require('events').EventEmitter
  353. , inherits = require('inherits')
  354. , JSON3 = require('json3')
  355. , utils = require('./utils/event')
  356. , IframeTransport = require('./transport/iframe')
  357. , InfoReceiverIframe = require('./info-iframe-receiver')
  358. ;
  359. var debug = function() {};
  360. if (process.env.NODE_ENV !== 'production') {
  361. debug = require('debug')('sockjs-client:info-iframe');
  362. }
  363. function InfoIframe(baseUrl, url) {
  364. var self = this;
  365. EventEmitter.call(this);
  366. var go = function() {
  367. var ifr = self.ifr = new IframeTransport(InfoReceiverIframe.transportName, url, baseUrl);
  368. ifr.once('message', function(msg) {
  369. if (msg) {
  370. var d;
  371. try {
  372. d = JSON3.parse(msg);
  373. } catch (e) {
  374. debug('bad json', msg);
  375. self.emit('finish');
  376. self.close();
  377. return;
  378. }
  379. var info = d[0], rtt = d[1];
  380. self.emit('finish', info, rtt);
  381. }
  382. self.close();
  383. });
  384. ifr.once('close', function() {
  385. self.emit('finish');
  386. self.close();
  387. });
  388. };
  389. // TODO this seems the same as the 'needBody' from transports
  390. if (!global.document.body) {
  391. utils.attachEvent('load', go);
  392. } else {
  393. go();
  394. }
  395. }
  396. inherits(InfoIframe, EventEmitter);
  397. InfoIframe.enabled = function() {
  398. return IframeTransport.enabled();
  399. };
  400. InfoIframe.prototype.close = function() {
  401. if (this.ifr) {
  402. this.ifr.close();
  403. }
  404. this.removeAllListeners();
  405. this.ifr = null;
  406. };
  407. module.exports = InfoIframe;
  408. }).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  409. },{"./info-iframe-receiver":10,"./transport/iframe":22,"./utils/event":46,"debug":54,"events":3,"inherits":56,"json3":57}],12:[function(require,module,exports){
  410. (function (process){
  411. 'use strict';
  412. var EventEmitter = require('events').EventEmitter
  413. , inherits = require('inherits')
  414. , urlUtils = require('./utils/url')
  415. , XDR = require('./transport/sender/xdr')
  416. , XHRCors = require('./transport/sender/xhr-cors')
  417. , XHRLocal = require('./transport/sender/xhr-local')
  418. , XHRFake = require('./transport/sender/xhr-fake')
  419. , InfoIframe = require('./info-iframe')
  420. , InfoAjax = require('./info-ajax')
  421. ;
  422. var debug = function() {};
  423. if (process.env.NODE_ENV !== 'production') {
  424. debug = require('debug')('sockjs-client:info-receiver');
  425. }
  426. function InfoReceiver(baseUrl, urlInfo) {
  427. debug(baseUrl);
  428. var self = this;
  429. EventEmitter.call(this);
  430. setTimeout(function() {
  431. self.doXhr(baseUrl, urlInfo);
  432. }, 0);
  433. }
  434. inherits(InfoReceiver, EventEmitter);
  435. // TODO this is currently ignoring the list of available transports and the whitelist
  436. InfoReceiver._getReceiver = function(baseUrl, url, urlInfo) {
  437. // determine method of CORS support (if needed)
  438. if (urlInfo.sameOrigin) {
  439. return new InfoAjax(url, XHRLocal);
  440. }
  441. if (XHRCors.enabled) {
  442. return new InfoAjax(url, XHRCors);
  443. }
  444. if (XDR.enabled && urlInfo.sameScheme) {
  445. return new InfoAjax(url, XDR);
  446. }
  447. if (InfoIframe.enabled()) {
  448. return new InfoIframe(baseUrl, url);
  449. }
  450. return new InfoAjax(url, XHRFake);
  451. };
  452. InfoReceiver.prototype.doXhr = function(baseUrl, urlInfo) {
  453. var self = this
  454. , url = urlUtils.addPath(baseUrl, '/info')
  455. ;
  456. debug('doXhr', url);
  457. this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo);
  458. this.timeoutRef = setTimeout(function() {
  459. debug('timeout');
  460. self._cleanup(false);
  461. self.emit('finish');
  462. }, InfoReceiver.timeout);
  463. this.xo.once('finish', function(info, rtt) {
  464. debug('finish', info, rtt);
  465. self._cleanup(true);
  466. self.emit('finish', info, rtt);
  467. });
  468. };
  469. InfoReceiver.prototype._cleanup = function(wasClean) {
  470. debug('_cleanup');
  471. clearTimeout(this.timeoutRef);
  472. this.timeoutRef = null;
  473. if (!wasClean && this.xo) {
  474. this.xo.close();
  475. }
  476. this.xo = null;
  477. };
  478. InfoReceiver.prototype.close = function() {
  479. debug('close');
  480. this.removeAllListeners();
  481. this._cleanup(false);
  482. };
  483. InfoReceiver.timeout = 8000;
  484. module.exports = InfoReceiver;
  485. }).call(this,{ env: {} })
  486. },{"./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":54,"events":3,"inherits":56}],13:[function(require,module,exports){
  487. (function (global){
  488. 'use strict';
  489. module.exports = global.location || {
  490. origin: 'http://localhost:80'
  491. , protocol: 'http'
  492. , host: 'localhost'
  493. , port: 80
  494. , href: 'http://localhost/'
  495. , hash: ''
  496. };
  497. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  498. },{}],14:[function(require,module,exports){
  499. (function (process,global){
  500. 'use strict';
  501. require('./shims');
  502. var URL = require('url-parse')
  503. , inherits = require('inherits')
  504. , JSON3 = require('json3')
  505. , random = require('./utils/random')
  506. , escape = require('./utils/escape')
  507. , urlUtils = require('./utils/url')
  508. , eventUtils = require('./utils/event')
  509. , transport = require('./utils/transport')
  510. , objectUtils = require('./utils/object')
  511. , browser = require('./utils/browser')
  512. , log = require('./utils/log')
  513. , Event = require('./event/event')
  514. , EventTarget = require('./event/eventtarget')
  515. , loc = require('./location')
  516. , CloseEvent = require('./event/close')
  517. , TransportMessageEvent = require('./event/trans-message')
  518. , InfoReceiver = require('./info-receiver')
  519. ;
  520. var debug = function() {};
  521. if (process.env.NODE_ENV !== 'production') {
  522. debug = require('debug')('sockjs-client:main');
  523. }
  524. var transports;
  525. // follow constructor steps defined at http://dev.w3.org/html5/websockets/#the-websocket-interface
  526. function SockJS(url, protocols, options) {
  527. if (!(this instanceof SockJS)) {
  528. return new SockJS(url, protocols, options);
  529. }
  530. if (arguments.length < 1) {
  531. throw new TypeError("Failed to construct 'SockJS: 1 argument required, but only 0 present");
  532. }
  533. EventTarget.call(this);
  534. this.readyState = SockJS.CONNECTING;
  535. this.extensions = '';
  536. this.protocol = '';
  537. // non-standard extension
  538. options = options || {};
  539. if (options.protocols_whitelist) {
  540. log.warn("'protocols_whitelist' is DEPRECATED. Use 'transports' instead.");
  541. }
  542. this._transportsWhitelist = options.transports;
  543. this._transportOptions = options.transportOptions || {};
  544. var sessionId = options.sessionId || 8;
  545. if (typeof sessionId === 'function') {
  546. this._generateSessionId = sessionId;
  547. } else if (typeof sessionId === 'number') {
  548. this._generateSessionId = function() {
  549. return random.string(sessionId);
  550. };
  551. } else {
  552. throw new TypeError('If sessionId is used in the options, it needs to be a number or a function.');
  553. }
  554. this._server = options.server || random.numberString(1000);
  555. // Step 1 of WS spec - parse and validate the url. Issue #8
  556. var parsedUrl = new URL(url);
  557. if (!parsedUrl.host || !parsedUrl.protocol) {
  558. throw new SyntaxError("The URL '" + url + "' is invalid");
  559. } else if (parsedUrl.hash) {
  560. throw new SyntaxError('The URL must not contain a fragment');
  561. } else if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
  562. throw new SyntaxError("The URL's scheme must be either 'http:' or 'https:'. '" + parsedUrl.protocol + "' is not allowed.");
  563. }
  564. var secure = parsedUrl.protocol === 'https:';
  565. // Step 2 - don't allow secure origin with an insecure protocol
  566. if (loc.protocol === 'https' && !secure) {
  567. throw new Error('SecurityError: An insecure SockJS connection may not be initiated from a page loaded over HTTPS');
  568. }
  569. // Step 3 - check port access - no need here
  570. // Step 4 - parse protocols argument
  571. if (!protocols) {
  572. protocols = [];
  573. } else if (!Array.isArray(protocols)) {
  574. protocols = [protocols];
  575. }
  576. // Step 5 - check protocols argument
  577. var sortedProtocols = protocols.sort();
  578. sortedProtocols.forEach(function(proto, i) {
  579. if (!proto) {
  580. throw new SyntaxError("The protocols entry '" + proto + "' is invalid.");
  581. }
  582. if (i < (sortedProtocols.length - 1) && proto === sortedProtocols[i + 1]) {
  583. throw new SyntaxError("The protocols entry '" + proto + "' is duplicated.");
  584. }
  585. });
  586. // Step 6 - convert origin
  587. var o = urlUtils.getOrigin(loc.href);
  588. this._origin = o ? o.toLowerCase() : null;
  589. // remove the trailing slash
  590. parsedUrl.set('pathname', parsedUrl.pathname.replace(/\/+$/, ''));
  591. // store the sanitized url
  592. this.url = parsedUrl.href;
  593. debug('using url', this.url);
  594. // Step 7 - start connection in background
  595. // obtain server info
  596. // http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-26
  597. this._urlInfo = {
  598. nullOrigin: !browser.hasDomain()
  599. , sameOrigin: urlUtils.isOriginEqual(this.url, loc.href)
  600. , sameScheme: urlUtils.isSchemeEqual(this.url, loc.href)
  601. };
  602. this._ir = new InfoReceiver(this.url, this._urlInfo);
  603. this._ir.once('finish', this._receiveInfo.bind(this));
  604. }
  605. inherits(SockJS, EventTarget);
  606. function userSetCode(code) {
  607. return code === 1000 || (code >= 3000 && code <= 4999);
  608. }
  609. SockJS.prototype.close = function(code, reason) {
  610. // Step 1
  611. if (code && !userSetCode(code)) {
  612. throw new Error('InvalidAccessError: Invalid code');
  613. }
  614. // Step 2.4 states the max is 123 bytes, but we are just checking length
  615. if (reason && reason.length > 123) {
  616. throw new SyntaxError('reason argument has an invalid length');
  617. }
  618. // Step 3.1
  619. if (this.readyState === SockJS.CLOSING || this.readyState === SockJS.CLOSED) {
  620. return;
  621. }
  622. // TODO look at docs to determine how to set this
  623. var wasClean = true;
  624. this._close(code || 1000, reason || 'Normal closure', wasClean);
  625. };
  626. SockJS.prototype.send = function(data) {
  627. // #13 - convert anything non-string to string
  628. // TODO this currently turns objects into [object Object]
  629. if (typeof data !== 'string') {
  630. data = '' + data;
  631. }
  632. if (this.readyState === SockJS.CONNECTING) {
  633. throw new Error('InvalidStateError: The connection has not been established yet');
  634. }
  635. if (this.readyState !== SockJS.OPEN) {
  636. return;
  637. }
  638. this._transport.send(escape.quote(data));
  639. };
  640. SockJS.version = require('./version');
  641. SockJS.CONNECTING = 0;
  642. SockJS.OPEN = 1;
  643. SockJS.CLOSING = 2;
  644. SockJS.CLOSED = 3;
  645. SockJS.prototype._receiveInfo = function(info, rtt) {
  646. debug('_receiveInfo', rtt);
  647. this._ir = null;
  648. if (!info) {
  649. this._close(1002, 'Cannot connect to server');
  650. return;
  651. }
  652. // establish a round-trip timeout (RTO) based on the
  653. // round-trip time (RTT)
  654. this._rto = this.countRTO(rtt);
  655. // allow server to override url used for the actual transport
  656. this._transUrl = info.base_url ? info.base_url : this.url;
  657. info = objectUtils.extend(info, this._urlInfo);
  658. debug('info', info);
  659. // determine list of desired and supported transports
  660. var enabledTransports = transports.filterToEnabled(this._transportsWhitelist, info);
  661. this._transports = enabledTransports.main;
  662. debug(this._transports.length + ' enabled transports');
  663. this._connect();
  664. };
  665. SockJS.prototype._connect = function() {
  666. for (var Transport = this._transports.shift(); Transport; Transport = this._transports.shift()) {
  667. debug('attempt', Transport.transportName);
  668. if (Transport.needBody) {
  669. if (!global.document.body ||
  670. (typeof global.document.readyState !== 'undefined' &&
  671. global.document.readyState !== 'complete' &&
  672. global.document.readyState !== 'interactive')) {
  673. debug('waiting for body');
  674. this._transports.unshift(Transport);
  675. eventUtils.attachEvent('load', this._connect.bind(this));
  676. return;
  677. }
  678. }
  679. // calculate timeout based on RTO and round trips. Default to 5s
  680. var timeoutMs = (this._rto * Transport.roundTrips) || 5000;
  681. this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs);
  682. debug('using timeout', timeoutMs);
  683. var transportUrl = urlUtils.addPath(this._transUrl, '/' + this._server + '/' + this._generateSessionId());
  684. var options = this._transportOptions[Transport.transportName];
  685. debug('transport url', transportUrl);
  686. var transportObj = new Transport(transportUrl, this._transUrl, options);
  687. transportObj.on('message', this._transportMessage.bind(this));
  688. transportObj.once('close', this._transportClose.bind(this));
  689. transportObj.transportName = Transport.transportName;
  690. this._transport = transportObj;
  691. return;
  692. }
  693. this._close(2000, 'All transports failed', false);
  694. };
  695. SockJS.prototype._transportTimeout = function() {
  696. debug('_transportTimeout');
  697. if (this.readyState === SockJS.CONNECTING) {
  698. this._transportClose(2007, 'Transport timed out');
  699. }
  700. };
  701. SockJS.prototype._transportMessage = function(msg) {
  702. debug('_transportMessage', msg);
  703. var self = this
  704. , type = msg.slice(0, 1)
  705. , content = msg.slice(1)
  706. , payload
  707. ;
  708. // first check for messages that don't need a payload
  709. switch (type) {
  710. case 'o':
  711. this._open();
  712. return;
  713. case 'h':
  714. this.dispatchEvent(new Event('heartbeat'));
  715. debug('heartbeat', this.transport);
  716. return;
  717. }
  718. if (content) {
  719. try {
  720. payload = JSON3.parse(content);
  721. } catch (e) {
  722. debug('bad json', content);
  723. }
  724. }
  725. if (typeof payload === 'undefined') {
  726. debug('empty payload', content);
  727. return;
  728. }
  729. switch (type) {
  730. case 'a':
  731. if (Array.isArray(payload)) {
  732. payload.forEach(function(p) {
  733. debug('message', self.transport, p);
  734. self.dispatchEvent(new TransportMessageEvent(p));
  735. });
  736. }
  737. break;
  738. case 'm':
  739. debug('message', this.transport, payload);
  740. this.dispatchEvent(new TransportMessageEvent(payload));
  741. break;
  742. case 'c':
  743. if (Array.isArray(payload) && payload.length === 2) {
  744. this._close(payload[0], payload[1], true);
  745. }
  746. break;
  747. }
  748. };
  749. SockJS.prototype._transportClose = function(code, reason) {
  750. debug('_transportClose', this.transport, code, reason);
  751. if (this._transport) {
  752. this._transport.removeAllListeners();
  753. this._transport = null;
  754. this.transport = null;
  755. }
  756. if (!userSetCode(code) && code !== 2000 && this.readyState === SockJS.CONNECTING) {
  757. this._connect();
  758. return;
  759. }
  760. this._close(code, reason);
  761. };
  762. SockJS.prototype._open = function() {
  763. debug('_open', this._transport.transportName, this.readyState);
  764. if (this.readyState === SockJS.CONNECTING) {
  765. if (this._transportTimeoutId) {
  766. clearTimeout(this._transportTimeoutId);
  767. this._transportTimeoutId = null;
  768. }
  769. this.readyState = SockJS.OPEN;
  770. this.transport = this._transport.transportName;
  771. this.dispatchEvent(new Event('open'));
  772. debug('connected', this.transport);
  773. } else {
  774. // The server might have been restarted, and lost track of our
  775. // connection.
  776. this._close(1006, 'Server lost session');
  777. }
  778. };
  779. SockJS.prototype._close = function(code, reason, wasClean) {
  780. debug('_close', this.transport, code, reason, wasClean, this.readyState);
  781. var forceFail = false;
  782. if (this._ir) {
  783. forceFail = true;
  784. this._ir.close();
  785. this._ir = null;
  786. }
  787. if (this._transport) {
  788. this._transport.close();
  789. this._transport = null;
  790. this.transport = null;
  791. }
  792. if (this.readyState === SockJS.CLOSED) {
  793. throw new Error('InvalidStateError: SockJS has already been closed');
  794. }
  795. this.readyState = SockJS.CLOSING;
  796. setTimeout(function() {
  797. this.readyState = SockJS.CLOSED;
  798. if (forceFail) {
  799. this.dispatchEvent(new Event('error'));
  800. }
  801. var e = new CloseEvent('close');
  802. e.wasClean = wasClean || false;
  803. e.code = code || 1000;
  804. e.reason = reason;
  805. this.dispatchEvent(e);
  806. this.onmessage = this.onclose = this.onerror = null;
  807. debug('disconnected');
  808. }.bind(this), 0);
  809. };
  810. // See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/
  811. // and RFC 2988.
  812. SockJS.prototype.countRTO = function(rtt) {
  813. // In a local environment, when using IE8/9 and the `jsonp-polling`
  814. // transport the time needed to establish a connection (the time that pass
  815. // from the opening of the transport to the call of `_dispatchOpen`) is
  816. // around 200msec (the lower bound used in the article above) and this
  817. // causes spurious timeouts. For this reason we calculate a value slightly
  818. // larger than that used in the article.
  819. if (rtt > 100) {
  820. return 4 * rtt; // rto > 400msec
  821. }
  822. return 300 + rtt; // 300msec < rto <= 400msec
  823. };
  824. module.exports = function(availableTransports) {
  825. transports = transport(availableTransports);
  826. require('./iframe-bootstrap')(SockJS, availableTransports);
  827. return SockJS;
  828. };
  829. }).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  830. },{"./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":54,"inherits":56,"json3":57,"url-parse":61}],15:[function(require,module,exports){
  831. /* eslint-disable */
  832. /* jscs: disable */
  833. 'use strict';
  834. // pulled specific shims from https://github.com/es-shims/es5-shim
  835. var ArrayPrototype = Array.prototype;
  836. var ObjectPrototype = Object.prototype;
  837. var FunctionPrototype = Function.prototype;
  838. var StringPrototype = String.prototype;
  839. var array_slice = ArrayPrototype.slice;
  840. var _toString = ObjectPrototype.toString;
  841. var isFunction = function (val) {
  842. return ObjectPrototype.toString.call(val) === '[object Function]';
  843. };
  844. var isArray = function isArray(obj) {
  845. return _toString.call(obj) === '[object Array]';
  846. };
  847. var isString = function isString(obj) {
  848. return _toString.call(obj) === '[object String]';
  849. };
  850. var supportsDescriptors = Object.defineProperty && (function () {
  851. try {
  852. Object.defineProperty({}, 'x', {});
  853. return true;
  854. } catch (e) { /* this is ES3 */
  855. return false;
  856. }
  857. }());
  858. // Define configurable, writable and non-enumerable props
  859. // if they don't exist.
  860. var defineProperty;
  861. if (supportsDescriptors) {
  862. defineProperty = function (object, name, method, forceAssign) {
  863. if (!forceAssign && (name in object)) { return; }
  864. Object.defineProperty(object, name, {
  865. configurable: true,
  866. enumerable: false,
  867. writable: true,
  868. value: method
  869. });
  870. };
  871. } else {
  872. defineProperty = function (object, name, method, forceAssign) {
  873. if (!forceAssign && (name in object)) { return; }
  874. object[name] = method;
  875. };
  876. }
  877. var defineProperties = function (object, map, forceAssign) {
  878. for (var name in map) {
  879. if (ObjectPrototype.hasOwnProperty.call(map, name)) {
  880. defineProperty(object, name, map[name], forceAssign);
  881. }
  882. }
  883. };
  884. var toObject = function (o) {
  885. if (o == null) { // this matches both null and undefined
  886. throw new TypeError("can't convert " + o + ' to object');
  887. }
  888. return Object(o);
  889. };
  890. //
  891. // Util
  892. // ======
  893. //
  894. // ES5 9.4
  895. // http://es5.github.com/#x9.4
  896. // http://jsperf.com/to-integer
  897. function toInteger(num) {
  898. var n = +num;
  899. if (n !== n) { // isNaN
  900. n = 0;
  901. } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
  902. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  903. }
  904. return n;
  905. }
  906. function ToUint32(x) {
  907. return x >>> 0;
  908. }
  909. //
  910. // Function
  911. // ========
  912. //
  913. // ES-5 15.3.4.5
  914. // http://es5.github.com/#x15.3.4.5
  915. function Empty() {}
  916. defineProperties(FunctionPrototype, {
  917. bind: function bind(that) { // .length is 1
  918. // 1. Let Target be the this value.
  919. var target = this;
  920. // 2. If IsCallable(Target) is false, throw a TypeError exception.
  921. if (!isFunction(target)) {
  922. throw new TypeError('Function.prototype.bind called on incompatible ' + target);
  923. }
  924. // 3. Let A be a new (possibly empty) internal list of all of the
  925. // argument values provided after thisArg (arg1, arg2 etc), in order.
  926. // XXX slicedArgs will stand in for "A" if used
  927. var args = array_slice.call(arguments, 1); // for normal call
  928. // 4. Let F be a new native ECMAScript object.
  929. // 11. Set the [[Prototype]] internal property of F to the standard
  930. // built-in Function prototype object as specified in 15.3.3.1.
  931. // 12. Set the [[Call]] internal property of F as described in
  932. // 15.3.4.5.1.
  933. // 13. Set the [[Construct]] internal property of F as described in
  934. // 15.3.4.5.2.
  935. // 14. Set the [[HasInstance]] internal property of F as described in
  936. // 15.3.4.5.3.
  937. var binder = function () {
  938. if (this instanceof bound) {
  939. // 15.3.4.5.2 [[Construct]]
  940. // When the [[Construct]] internal method of a function object,
  941. // F that was created using the bind function is called with a
  942. // list of arguments ExtraArgs, the following steps are taken:
  943. // 1. Let target be the value of F's [[TargetFunction]]
  944. // internal property.
  945. // 2. If target has no [[Construct]] internal method, a
  946. // TypeError exception is thrown.
  947. // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
  948. // property.
  949. // 4. Let args be a new list containing the same values as the
  950. // list boundArgs in the same order followed by the same
  951. // values as the list ExtraArgs in the same order.
  952. // 5. Return the result of calling the [[Construct]] internal
  953. // method of target providing args as the arguments.
  954. var result = target.apply(
  955. this,
  956. args.concat(array_slice.call(arguments))
  957. );
  958. if (Object(result) === result) {
  959. return result;
  960. }
  961. return this;
  962. } else {
  963. // 15.3.4.5.1 [[Call]]
  964. // When the [[Call]] internal method of a function object, F,
  965. // which was created using the bind function is called with a
  966. // this value and a list of arguments ExtraArgs, the following
  967. // steps are taken:
  968. // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
  969. // property.
  970. // 2. Let boundThis be the value of F's [[BoundThis]] internal
  971. // property.
  972. // 3. Let target be the value of F's [[TargetFunction]] internal
  973. // property.
  974. // 4. Let args be a new list containing the same values as the
  975. // list boundArgs in the same order followed by the same
  976. // values as the list ExtraArgs in the same order.
  977. // 5. Return the result of calling the [[Call]] internal method
  978. // of target providing boundThis as the this value and
  979. // providing args as the arguments.
  980. // equiv: target.call(this, ...boundArgs, ...args)
  981. return target.apply(
  982. that,
  983. args.concat(array_slice.call(arguments))
  984. );
  985. }
  986. };
  987. // 15. If the [[Class]] internal property of Target is "Function", then
  988. // a. Let L be the length property of Target minus the length of A.
  989. // b. Set the length own property of F to either 0 or L, whichever is
  990. // larger.
  991. // 16. Else set the length own property of F to 0.
  992. var boundLength = Math.max(0, target.length - args.length);
  993. // 17. Set the attributes of the length own property of F to the values
  994. // specified in 15.3.5.1.
  995. var boundArgs = [];
  996. for (var i = 0; i < boundLength; i++) {
  997. boundArgs.push('$' + i);
  998. }
  999. // XXX Build a dynamic function with desired amount of arguments is the only
  1000. // way to set the length property of a function.
  1001. // In environments where Content Security Policies enabled (Chrome extensions,
  1002. // for ex.) all use of eval or Function costructor throws an exception.
  1003. // However in all of these environments Function.prototype.bind exists
  1004. // and so this code will never be executed.
  1005. var bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
  1006. if (target.prototype) {
  1007. Empty.prototype = target.prototype;
  1008. bound.prototype = new Empty();
  1009. // Clean up dangling references.
  1010. Empty.prototype = null;
  1011. }
  1012. // TODO
  1013. // 18. Set the [[Extensible]] internal property of F to true.
  1014. // TODO
  1015. // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
  1016. // 20. Call the [[DefineOwnProperty]] internal method of F with
  1017. // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
  1018. // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
  1019. // false.
  1020. // 21. Call the [[DefineOwnProperty]] internal method of F with
  1021. // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
  1022. // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
  1023. // and false.
  1024. // TODO
  1025. // NOTE Function objects created using Function.prototype.bind do not
  1026. // have a prototype property or the [[Code]], [[FormalParameters]], and
  1027. // [[Scope]] internal properties.
  1028. // XXX can't delete prototype in pure-js.
  1029. // 22. Return F.
  1030. return bound;
  1031. }
  1032. });
  1033. //
  1034. // Array
  1035. // =====
  1036. //
  1037. // ES5 15.4.3.2
  1038. // http://es5.github.com/#x15.4.3.2
  1039. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
  1040. defineProperties(Array, { isArray: isArray });
  1041. var boxedString = Object('a');
  1042. var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
  1043. var properlyBoxesContext = function properlyBoxed(method) {
  1044. // Check node 0.6.21 bug where third parameter is not boxed
  1045. var properlyBoxesNonStrict = true;
  1046. var properlyBoxesStrict = true;
  1047. if (method) {
  1048. method.call('foo', function (_, __, context) {
  1049. if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
  1050. });
  1051. method.call([1], function () {
  1052. 'use strict';
  1053. properlyBoxesStrict = typeof this === 'string';
  1054. }, 'x');
  1055. }
  1056. return !!method && properlyBoxesNonStrict && properlyBoxesStrict;
  1057. };
  1058. defineProperties(ArrayPrototype, {
  1059. forEach: function forEach(fun /*, thisp*/) {
  1060. var object = toObject(this),
  1061. self = splitString && isString(this) ? this.split('') : object,
  1062. thisp = arguments[1],
  1063. i = -1,
  1064. length = self.length >>> 0;
  1065. // If no callback function or if callback is not a callable function
  1066. if (!isFunction(fun)) {
  1067. throw new TypeError(); // TODO message
  1068. }
  1069. while (++i < length) {
  1070. if (i in self) {
  1071. // Invoke the callback function with call, passing arguments:
  1072. // context, property value, property key, thisArg object
  1073. // context
  1074. fun.call(thisp, self[i], i, object);
  1075. }
  1076. }
  1077. }
  1078. }, !properlyBoxesContext(ArrayPrototype.forEach));
  1079. // ES5 15.4.4.14
  1080. // http://es5.github.com/#x15.4.4.14
  1081. // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
  1082. var hasFirefox2IndexOfBug = Array.prototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
  1083. defineProperties(ArrayPrototype, {
  1084. indexOf: function indexOf(sought /*, fromIndex */ ) {
  1085. var self = splitString && isString(this) ? this.split('') : toObject(this),
  1086. length = self.length >>> 0;
  1087. if (!length) {
  1088. return -1;
  1089. }
  1090. var i = 0;
  1091. if (arguments.length > 1) {
  1092. i = toInteger(arguments[1]);
  1093. }
  1094. // handle negative indices
  1095. i = i >= 0 ? i : Math.max(0, length + i);
  1096. for (; i < length; i++) {
  1097. if (i in self && self[i] === sought) {
  1098. return i;
  1099. }
  1100. }
  1101. return -1;
  1102. }
  1103. }, hasFirefox2IndexOfBug);
  1104. //
  1105. // String
  1106. // ======
  1107. //
  1108. // ES5 15.5.4.14
  1109. // http://es5.github.com/#x15.5.4.14
  1110. // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
  1111. // Many browsers do not split properly with regular expressions or they
  1112. // do not perform the split correctly under obscure conditions.
  1113. // See http://blog.stevenlevithan.com/archives/cross-browser-split
  1114. // I've tested in many browsers and this seems to cover the deviant ones:
  1115. // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
  1116. // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
  1117. // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
  1118. // [undefined, "t", undefined, "e", ...]
  1119. // ''.split(/.?/) should be [], not [""]
  1120. // '.'.split(/()()/) should be ["."], not ["", "", "."]
  1121. var string_split = StringPrototype.split;
  1122. if (
  1123. 'ab'.split(/(?:ab)*/).length !== 2 ||
  1124. '.'.split(/(.?)(.?)/).length !== 4 ||
  1125. 'tesst'.split(/(s)*/)[1] === 't' ||
  1126. 'test'.split(/(?:)/, -1).length !== 4 ||
  1127. ''.split(/.?/).length ||
  1128. '.'.split(/()()/).length > 1
  1129. ) {
  1130. (function () {
  1131. var compliantExecNpcg = /()??/.exec('')[1] === void 0; // NPCG: nonparticipating capturing group
  1132. StringPrototype.split = function (separator, limit) {
  1133. var string = this;
  1134. if (separator === void 0 && limit === 0) {
  1135. return [];
  1136. }
  1137. // If `separator` is not a regex, use native split
  1138. if (_toString.call(separator) !== '[object RegExp]') {
  1139. return string_split.call(this, separator, limit);
  1140. }
  1141. var output = [],
  1142. flags = (separator.ignoreCase ? 'i' : '') +
  1143. (separator.multiline ? 'm' : '') +
  1144. (separator.extended ? 'x' : '') + // Proposed for ES6
  1145. (separator.sticky ? 'y' : ''), // Firefox 3+
  1146. lastLastIndex = 0,
  1147. // Make `global` and avoid `lastIndex` issues by working with a copy
  1148. separator2, match, lastIndex, lastLength;
  1149. separator = new RegExp(separator.source, flags + 'g');
  1150. string += ''; // Type-convert
  1151. if (!compliantExecNpcg) {
  1152. // Doesn't need flags gy, but they don't hurt
  1153. separator2 = new RegExp('^' + separator.source + '$(?!\\s)', flags);
  1154. }
  1155. /* Values for `limit`, per the spec:
  1156. * If undefined: 4294967295 // Math.pow(2, 32) - 1
  1157. * If 0, Infinity, or NaN: 0
  1158. * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
  1159. * If negative number: 4294967296 - Math.floor(Math.abs(limit))
  1160. * If other: Type-convert, then use the above rules
  1161. */
  1162. limit = limit === void 0 ?
  1163. -1 >>> 0 : // Math.pow(2, 32) - 1
  1164. ToUint32(limit);
  1165. while (match = separator.exec(string)) {
  1166. // `separator.lastIndex` is not reliable cross-browser
  1167. lastIndex = match.index + match[0].length;
  1168. if (lastIndex > lastLastIndex) {
  1169. output.push(string.slice(lastLastIndex, match.index));
  1170. // Fix browsers whose `exec` methods don't consistently return `undefined` for
  1171. // nonparticipating capturing groups
  1172. if (!compliantExecNpcg && match.length > 1) {
  1173. match[0].replace(separator2, function () {
  1174. for (var i = 1; i < arguments.length - 2; i++) {
  1175. if (arguments[i] === void 0) {
  1176. match[i] = void 0;
  1177. }
  1178. }
  1179. });
  1180. }
  1181. if (match.length > 1 && match.index < string.length) {
  1182. ArrayPrototype.push.apply(output, match.slice(1));
  1183. }
  1184. lastLength = match[0].length;
  1185. lastLastIndex = lastIndex;
  1186. if (output.length >= limit) {
  1187. break;
  1188. }
  1189. }
  1190. if (separator.lastIndex === match.index) {
  1191. separator.lastIndex++; // Avoid an infinite loop
  1192. }
  1193. }
  1194. if (lastLastIndex === string.length) {
  1195. if (lastLength || !separator.test('')) {
  1196. output.push('');
  1197. }
  1198. } else {
  1199. output.push(string.slice(lastLastIndex));
  1200. }
  1201. return output.length > limit ? output.slice(0, limit) : output;
  1202. };
  1203. }());
  1204. // [bugfix, chrome]
  1205. // If separator is undefined, then the result array contains just one String,
  1206. // which is the this value (converted to a String). If limit is not undefined,
  1207. // then the output array is truncated so that it contains no more than limit
  1208. // elements.
  1209. // "0".split(undefined, 0) -> []
  1210. } else if ('0'.split(void 0, 0).length) {
  1211. StringPrototype.split = function split(separator, limit) {
  1212. if (separator === void 0 && limit === 0) { return []; }
  1213. return string_split.call(this, separator, limit);
  1214. };
  1215. }
  1216. // ECMA-262, 3rd B.2.3
  1217. // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
  1218. // non-normative section suggesting uniform semantics and it should be
  1219. // normalized across all browsers
  1220. // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
  1221. var string_substr = StringPrototype.substr;
  1222. var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
  1223. defineProperties(StringPrototype, {
  1224. substr: function substr(start, length) {
  1225. return string_substr.call(
  1226. this,
  1227. start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
  1228. length
  1229. );
  1230. }
  1231. }, hasNegativeSubstrBug);
  1232. },{}],16:[function(require,module,exports){
  1233. 'use strict';
  1234. module.exports = [
  1235. // streaming transports
  1236. require('./transport/websocket')
  1237. , require('./transport/xhr-streaming')
  1238. , require('./transport/xdr-streaming')
  1239. , require('./transport/eventsource')
  1240. , require('./transport/lib/iframe-wrap')(require('./transport/eventsource'))
  1241. // polling transports
  1242. , require('./transport/htmlfile')
  1243. , require('./transport/lib/iframe-wrap')(require('./transport/htmlfile'))
  1244. , require('./transport/xhr-polling')
  1245. , require('./transport/xdr-polling')
  1246. , require('./transport/lib/iframe-wrap')(require('./transport/xhr-polling'))
  1247. , require('./transport/jsonp-polling')
  1248. ];
  1249. },{"./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){
  1250. (function (process,global){
  1251. 'use strict';
  1252. var EventEmitter = require('events').EventEmitter
  1253. , inherits = require('inherits')
  1254. , utils = require('../../utils/event')
  1255. , urlUtils = require('../../utils/url')
  1256. , XHR = global.XMLHttpRequest
  1257. ;
  1258. var debug = function() {};
  1259. if (process.env.NODE_ENV !== 'production') {
  1260. debug = require('debug')('sockjs-client:browser:xhr');
  1261. }
  1262. function AbstractXHRObject(method, url, payload, opts) {
  1263. debug(method, url);
  1264. var self = this;
  1265. EventEmitter.call(this);
  1266. setTimeout(function () {
  1267. self._start(method, url, payload, opts);
  1268. }, 0);
  1269. }
  1270. inherits(AbstractXHRObject, EventEmitter);
  1271. AbstractXHRObject.prototype._start = function(method, url, payload, opts) {
  1272. var self = this;
  1273. try {
  1274. this.xhr = new XHR();
  1275. } catch (x) {
  1276. // intentionally empty
  1277. }
  1278. if (!this.xhr) {
  1279. debug('no xhr');
  1280. this.emit('finish', 0, 'no xhr support');
  1281. this._cleanup();
  1282. return;
  1283. }
  1284. // several browsers cache POSTs
  1285. url = urlUtils.addQuery(url, 't=' + (+new Date()));
  1286. // Explorer tends to keep connection open, even after the
  1287. // tab gets closed: http://bugs.jquery.com/ticket/5280
  1288. this.unloadRef = utils.unloadAdd(function() {
  1289. debug('unload cleanup');
  1290. self._cleanup(true);
  1291. });
  1292. try {
  1293. this.xhr.open(method, url, true);
  1294. if (this.timeout && 'timeout' in this.xhr) {
  1295. this.xhr.timeout = this.timeout;
  1296. this.xhr.ontimeout = function() {
  1297. debug('xhr timeout');
  1298. self.emit('finish', 0, '');
  1299. self._cleanup(false);
  1300. };
  1301. }
  1302. } catch (e) {
  1303. debug('exception', e);
  1304. // IE raises an exception on wrong port.
  1305. this.emit('finish', 0, '');
  1306. this._cleanup(false);
  1307. return;
  1308. }
  1309. if ((!opts || !opts.noCredentials) && AbstractXHRObject.supportsCORS) {
  1310. debug('withCredentials');
  1311. // Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
  1312. // "This never affects same-site requests."
  1313. this.xhr.withCredentials = 'true';
  1314. }
  1315. if (opts && opts.headers) {
  1316. for (var key in opts.headers) {
  1317. this.xhr.setRequestHeader(key, opts.headers[key]);
  1318. }
  1319. }
  1320. this.xhr.onreadystatechange = function() {
  1321. if (self.xhr) {
  1322. var x = self.xhr;
  1323. var text, status;
  1324. debug('readyState', x.readyState);
  1325. switch (x.readyState) {
  1326. case 3:
  1327. // IE doesn't like peeking into responseText or status
  1328. // on Microsoft.XMLHTTP and readystate=3
  1329. try {
  1330. status = x.status;
  1331. text = x.responseText;
  1332. } catch (e) {
  1333. // intentionally empty
  1334. }
  1335. debug('status', status);
  1336. // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
  1337. if (status === 1223) {
  1338. status = 204;
  1339. }
  1340. // IE does return readystate == 3 for 404 answers.
  1341. if (status === 200 && text && text.length > 0) {
  1342. debug('chunk');
  1343. self.emit('chunk', status, text);
  1344. }
  1345. break;
  1346. case 4:
  1347. status = x.status;
  1348. debug('status', status);
  1349. // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
  1350. if (status === 1223) {
  1351. status = 204;
  1352. }
  1353. // IE returns this for a bad port
  1354. // http://msdn.microsoft.com/en-us/library/windows/desktop/aa383770(v=vs.85).aspx
  1355. if (status === 12005 || status === 12029) {
  1356. status = 0;
  1357. }
  1358. debug('finish', status, x.responseText);
  1359. self.emit('finish', status, x.responseText);
  1360. self._cleanup(false);
  1361. break;
  1362. }
  1363. }
  1364. };
  1365. try {
  1366. self.xhr.send(payload);
  1367. } catch (e) {
  1368. self.emit('finish', 0, '');
  1369. self._cleanup(false);
  1370. }
  1371. };
  1372. AbstractXHRObject.prototype._cleanup = function(abort) {
  1373. debug('cleanup');
  1374. if (!this.xhr) {
  1375. return;
  1376. }
  1377. this.removeAllListeners();
  1378. utils.unloadDel(this.unloadRef);
  1379. // IE needs this field to be a function
  1380. this.xhr.onreadystatechange = function() {};
  1381. if (this.xhr.ontimeout) {
  1382. this.xhr.ontimeout = null;
  1383. }
  1384. if (abort) {
  1385. try {
  1386. this.xhr.abort();
  1387. } catch (x) {
  1388. // intentionally empty
  1389. }
  1390. }
  1391. this.unloadRef = this.xhr = null;
  1392. };
  1393. AbstractXHRObject.prototype.close = function() {
  1394. debug('close');
  1395. this._cleanup(true);
  1396. };
  1397. AbstractXHRObject.enabled = !!XHR;
  1398. // override XMLHttpRequest for IE6/7
  1399. // obfuscate to avoid firewalls
  1400. var axo = ['Active'].concat('Object').join('X');
  1401. if (!AbstractXHRObject.enabled && (axo in global)) {
  1402. debug('overriding xmlhttprequest');
  1403. XHR = function() {
  1404. try {
  1405. return new global[axo]('Microsoft.XMLHTTP');
  1406. } catch (e) {
  1407. return null;
  1408. }
  1409. };
  1410. AbstractXHRObject.enabled = !!new XHR();
  1411. }
  1412. var cors = false;
  1413. try {
  1414. cors = 'withCredentials' in new XHR();
  1415. } catch (ignored) {
  1416. // intentionally empty
  1417. }
  1418. AbstractXHRObject.supportsCORS = cors;
  1419. module.exports = AbstractXHRObject;
  1420. }).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1421. },{"../../utils/event":46,"../../utils/url":52,"debug":54,"events":3,"inherits":56}],18:[function(require,module,exports){
  1422. (function (global){
  1423. module.exports = global.EventSource;
  1424. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1425. },{}],19:[function(require,module,exports){
  1426. (function (global){
  1427. 'use strict';
  1428. var Driver = global.WebSocket || global.MozWebSocket;
  1429. if (Driver) {
  1430. module.exports = function WebSocketBrowserDriver(url) {
  1431. return new Driver(url);
  1432. };
  1433. } else {
  1434. module.exports = undefined;
  1435. }
  1436. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1437. },{}],20:[function(require,module,exports){
  1438. 'use strict';
  1439. var inherits = require('inherits')
  1440. , AjaxBasedTransport = require('./lib/ajax-based')
  1441. , EventSourceReceiver = require('./receiver/eventsource')
  1442. , XHRCorsObject = require('./sender/xhr-cors')
  1443. , EventSourceDriver = require('eventsource')
  1444. ;
  1445. function EventSourceTransport(transUrl) {
  1446. if (!EventSourceTransport.enabled()) {
  1447. throw new Error('Transport created when disabled');
  1448. }
  1449. AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRCorsObject);
  1450. }
  1451. inherits(EventSourceTransport, AjaxBasedTransport);
  1452. EventSourceTransport.enabled = function() {
  1453. return !!EventSourceDriver;
  1454. };
  1455. EventSourceTransport.transportName = 'eventsource';
  1456. EventSourceTransport.roundTrips = 2;
  1457. module.exports = EventSourceTransport;
  1458. },{"./lib/ajax-based":24,"./receiver/eventsource":29,"./sender/xhr-cors":35,"eventsource":18,"inherits":56}],21:[function(require,module,exports){
  1459. 'use strict';
  1460. var inherits = require('inherits')
  1461. , HtmlfileReceiver = require('./receiver/htmlfile')
  1462. , XHRLocalObject = require('./sender/xhr-local')
  1463. , AjaxBasedTransport = require('./lib/ajax-based')
  1464. ;
  1465. function HtmlFileTransport(transUrl) {
  1466. if (!HtmlfileReceiver.enabled) {
  1467. throw new Error('Transport created when disabled');
  1468. }
  1469. AjaxBasedTransport.call(this, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);
  1470. }
  1471. inherits(HtmlFileTransport, AjaxBasedTransport);
  1472. HtmlFileTransport.enabled = function(info) {
  1473. return HtmlfileReceiver.enabled && info.sameOrigin;
  1474. };
  1475. HtmlFileTransport.transportName = 'htmlfile';
  1476. HtmlFileTransport.roundTrips = 2;
  1477. module.exports = HtmlFileTransport;
  1478. },{"./lib/ajax-based":24,"./receiver/htmlfile":30,"./sender/xhr-local":37,"inherits":56}],22:[function(require,module,exports){
  1479. (function (process){
  1480. 'use strict';
  1481. // Few cool transports do work only for same-origin. In order to make
  1482. // them work cross-domain we shall use iframe, served from the
  1483. // remote domain. New browsers have capabilities to communicate with
  1484. // cross domain iframe using postMessage(). In IE it was implemented
  1485. // from IE 8+, but of course, IE got some details wrong:
  1486. // http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
  1487. // http://stevesouders.com/misc/test-postmessage.php
  1488. var inherits = require('inherits')
  1489. , JSON3 = require('json3')
  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 = JSON3.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', JSON3.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 = JSON3.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(JSON3.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,{ env: {} })
  1603. },{"../utils/event":46,"../utils/iframe":47,"../utils/random":50,"../utils/url":52,"../version":53,"debug":54,"events":3,"inherits":56,"json3":57}],23:[function(require,module,exports){
  1604. (function (global){
  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,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1633. },{"./lib/sender-receiver":28,"./receiver/jsonp":31,"./sender/jsonp":33,"inherits":56}],24:[function(require,module,exports){
  1634. (function (process){
  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,{ env: {} })
  1677. },{"../../utils/url":52,"./sender-receiver":28,"debug":54,"inherits":56}],25:[function(require,module,exports){
  1678. (function (process){
  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,{ env: {} })
  1757. },{"debug":54,"events":3,"inherits":56}],26:[function(require,module,exports){
  1758. (function (global){
  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,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1784. },{"../../utils/object":49,"../iframe":22,"inherits":56}],27:[function(require,module,exports){
  1785. (function (process){
  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,{ env: {} })
  1834. },{"debug":54,"events":3,"inherits":56}],28:[function(require,module,exports){
  1835. (function (process){
  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,{ env: {} })
  1875. },{"../../utils/url":52,"./buffered-sender":25,"./polling":27,"debug":54,"inherits":56}],29:[function(require,module,exports){
  1876. (function (process){
  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,{ env: {} })
  1932. },{"debug":54,"events":3,"eventsource":18,"inherits":56}],30:[function(require,module,exports){
  1933. (function (process,global){
  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,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2008. },{"../../utils/iframe":47,"../../utils/random":50,"../../utils/url":52,"debug":54,"events":3,"inherits":56}],31:[function(require,module,exports){
  2009. (function (process,global){
  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,{ 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":54,"events":3,"inherits":56}],32:[function(require,module,exports){
  2173. (function (process){
  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,{ env: {} })
  2234. },{"debug":54,"events":3,"inherits":56}],33:[function(require,module,exports){
  2235. (function (process,global){
  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,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2325. },{"../../utils/random":50,"../../utils/url":52,"debug":54}],34:[function(require,module,exports){
  2326. (function (process,global){
  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,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2417. },{"../../utils/browser":44,"../../utils/event":46,"../../utils/url":52,"debug":54,"events":3,"inherits":56}],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":56}],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":56}],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":56}],38:[function(require,module,exports){
  2460. (function (process){
  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,{ env: {} })
  2548. },{"../utils/event":46,"../utils/url":52,"./driver/websocket":19,"debug":54,"events":3,"inherits":56}],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":56}],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":56}],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":56}],42:[function(require,module,exports){
  2621. (function (global){
  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,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":56}],43:[function(require,module,exports){
  2657. (function (global){
  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,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2675. },{}],44:[function(require,module,exports){
  2676. (function (global){
  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,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2701. },{}],45:[function(require,module,exports){
  2702. 'use strict';
  2703. var JSON3 = require('json3');
  2704. // Some extra characters that Chrome gets wrong, and substitutes with
  2705. // something else on the wire.
  2706. // eslint-disable-next-line no-control-regex
  2707. 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
  2708. , extraLookup;
  2709. // This may be quite slow, so let's delay until user actually uses bad
  2710. // characters.
  2711. var unrollLookup = function(escapable) {
  2712. var i;
  2713. var unrolled = {};
  2714. var c = [];
  2715. for (i = 0; i < 65536; i++) {
  2716. c.push( String.fromCharCode(i) );
  2717. }
  2718. escapable.lastIndex = 0;
  2719. c.join('').replace(escapable, function(a) {
  2720. unrolled[ a ] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  2721. return '';
  2722. });
  2723. escapable.lastIndex = 0;
  2724. return unrolled;
  2725. };
  2726. // Quote string, also taking care of unicode characters that browsers
  2727. // often break. Especially, take care of unicode surrogates:
  2728. // http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
  2729. module.exports = {
  2730. quote: function(string) {
  2731. var quoted = JSON3.stringify(string);
  2732. // In most cases this should be very fast and good enough.
  2733. extraEscapable.lastIndex = 0;
  2734. if (!extraEscapable.test(quoted)) {
  2735. return quoted;
  2736. }
  2737. if (!extraLookup) {
  2738. extraLookup = unrollLookup(extraEscapable);
  2739. }
  2740. return quoted.replace(extraEscapable, function(a) {
  2741. return extraLookup[a];
  2742. });
  2743. }
  2744. };
  2745. },{"json3":57}],46:[function(require,module,exports){
  2746. (function (global){
  2747. 'use strict';
  2748. var random = require('./random');
  2749. var onUnload = {}
  2750. , afterUnload = false
  2751. // detect google chrome packaged apps because they don't allow the 'unload' event
  2752. , isChromePackagedApp = global.chrome && global.chrome.app && global.chrome.app.runtime
  2753. ;
  2754. module.exports = {
  2755. attachEvent: function(event, listener) {
  2756. if (typeof global.addEventListener !== 'undefined') {
  2757. global.addEventListener(event, listener, false);
  2758. } else if (global.document && global.attachEvent) {
  2759. // IE quirks.
  2760. // According to: http://stevesouders.com/misc/test-postmessage.php
  2761. // the message gets delivered only to 'document', not 'window'.
  2762. global.document.attachEvent('on' + event, listener);
  2763. // I get 'window' for ie8.
  2764. global.attachEvent('on' + event, listener);
  2765. }
  2766. }
  2767. , detachEvent: function(event, listener) {
  2768. if (typeof global.addEventListener !== 'undefined') {
  2769. global.removeEventListener(event, listener, false);
  2770. } else if (global.document && global.detachEvent) {
  2771. global.document.detachEvent('on' + event, listener);
  2772. global.detachEvent('on' + event, listener);
  2773. }
  2774. }
  2775. , unloadAdd: function(listener) {
  2776. if (isChromePackagedApp) {
  2777. return null;
  2778. }
  2779. var ref = random.string(8);
  2780. onUnload[ref] = listener;
  2781. if (afterUnload) {
  2782. setTimeout(this.triggerUnloadCallbacks, 0);
  2783. }
  2784. return ref;
  2785. }
  2786. , unloadDel: function(ref) {
  2787. if (ref in onUnload) {
  2788. delete onUnload[ref];
  2789. }
  2790. }
  2791. , triggerUnloadCallbacks: function() {
  2792. for (var ref in onUnload) {
  2793. onUnload[ref]();
  2794. delete onUnload[ref];
  2795. }
  2796. }
  2797. };
  2798. var unloadTriggered = function() {
  2799. if (afterUnload) {
  2800. return;
  2801. }
  2802. afterUnload = true;
  2803. module.exports.triggerUnloadCallbacks();
  2804. };
  2805. // 'unload' alone is not reliable in opera within an iframe, but we
  2806. // can't use `beforeunload` as IE fires it on javascript: links.
  2807. if (!isChromePackagedApp) {
  2808. module.exports.attachEvent('unload', unloadTriggered);
  2809. }
  2810. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2811. },{"./random":50}],47:[function(require,module,exports){
  2812. (function (process,global){
  2813. 'use strict';
  2814. var eventUtils = require('./event')
  2815. , JSON3 = require('json3')
  2816. , browser = require('./browser')
  2817. ;
  2818. var debug = function() {};
  2819. if (process.env.NODE_ENV !== 'production') {
  2820. debug = require('debug')('sockjs-client:utils:iframe');
  2821. }
  2822. module.exports = {
  2823. WPrefix: '_jp'
  2824. , currentWindowId: null
  2825. , polluteGlobalNamespace: function() {
  2826. if (!(module.exports.WPrefix in global)) {
  2827. global[module.exports.WPrefix] = {};
  2828. }
  2829. }
  2830. , postMessage: function(type, data) {
  2831. if (global.parent !== global) {
  2832. global.parent.postMessage(JSON3.stringify({
  2833. windowId: module.exports.currentWindowId
  2834. , type: type
  2835. , data: data || ''
  2836. }), '*');
  2837. } else {
  2838. debug('Cannot postMessage, no parent window.', type, data);
  2839. }
  2840. }
  2841. , createIframe: function(iframeUrl, errorCallback) {
  2842. var iframe = global.document.createElement('iframe');
  2843. var tref, unloadRef;
  2844. var unattach = function() {
  2845. debug('unattach');
  2846. clearTimeout(tref);
  2847. // Explorer had problems with that.
  2848. try {
  2849. iframe.onload = null;
  2850. } catch (x) {
  2851. // intentionally empty
  2852. }
  2853. iframe.onerror = null;
  2854. };
  2855. var cleanup = function() {
  2856. debug('cleanup');
  2857. if (iframe) {
  2858. unattach();
  2859. // This timeout makes chrome fire onbeforeunload event
  2860. // within iframe. Without the timeout it goes straight to
  2861. // onunload.
  2862. setTimeout(function() {
  2863. if (iframe) {
  2864. iframe.parentNode.removeChild(iframe);
  2865. }
  2866. iframe = null;
  2867. }, 0);
  2868. eventUtils.unloadDel(unloadRef);
  2869. }
  2870. };
  2871. var onerror = function(err) {
  2872. debug('onerror', err);
  2873. if (iframe) {
  2874. cleanup();
  2875. errorCallback(err);
  2876. }
  2877. };
  2878. var post = function(msg, origin) {
  2879. debug('post', msg, origin);
  2880. try {
  2881. // When the iframe is not loaded, IE raises an exception
  2882. // on 'contentWindow'.
  2883. setTimeout(function() {
  2884. if (iframe && iframe.contentWindow) {
  2885. iframe.contentWindow.postMessage(msg, origin);
  2886. }
  2887. }, 0);
  2888. } catch (x) {
  2889. // intentionally empty
  2890. }
  2891. };
  2892. iframe.src = iframeUrl;
  2893. iframe.style.display = 'none';
  2894. iframe.style.position = 'absolute';
  2895. iframe.onerror = function() {
  2896. onerror('onerror');
  2897. };
  2898. iframe.onload = function() {
  2899. debug('onload');
  2900. // `onload` is triggered before scripts on the iframe are
  2901. // executed. Give it few seconds to actually load stuff.
  2902. clearTimeout(tref);
  2903. tref = setTimeout(function() {
  2904. onerror('onload timeout');
  2905. }, 2000);
  2906. };
  2907. global.document.body.appendChild(iframe);
  2908. tref = setTimeout(function() {
  2909. onerror('timeout');
  2910. }, 15000);
  2911. unloadRef = eventUtils.unloadAdd(cleanup);
  2912. return {
  2913. post: post
  2914. , cleanup: cleanup
  2915. , loaded: unattach
  2916. };
  2917. }
  2918. /* eslint no-undef: "off", new-cap: "off" */
  2919. , createHtmlfile: function(iframeUrl, errorCallback) {
  2920. var axo = ['Active'].concat('Object').join('X');
  2921. var doc = new global[axo]('htmlfile');
  2922. var tref, unloadRef;
  2923. var iframe;
  2924. var unattach = function() {
  2925. clearTimeout(tref);
  2926. iframe.onerror = null;
  2927. };
  2928. var cleanup = function() {
  2929. if (doc) {
  2930. unattach();
  2931. eventUtils.unloadDel(unloadRef);
  2932. iframe.parentNode.removeChild(iframe);
  2933. iframe = doc = null;
  2934. CollectGarbage();
  2935. }
  2936. };
  2937. var onerror = function(r) {
  2938. debug('onerror', r);
  2939. if (doc) {
  2940. cleanup();
  2941. errorCallback(r);
  2942. }
  2943. };
  2944. var post = function(msg, origin) {
  2945. try {
  2946. // When the iframe is not loaded, IE raises an exception
  2947. // on 'contentWindow'.
  2948. setTimeout(function() {
  2949. if (iframe && iframe.contentWindow) {
  2950. iframe.contentWindow.postMessage(msg, origin);
  2951. }
  2952. }, 0);
  2953. } catch (x) {
  2954. // intentionally empty
  2955. }
  2956. };
  2957. doc.open();
  2958. doc.write('<html><s' + 'cript>' +
  2959. 'document.domain="' + global.document.domain + '";' +
  2960. '</s' + 'cript></html>');
  2961. doc.close();
  2962. doc.parentWindow[module.exports.WPrefix] = global[module.exports.WPrefix];
  2963. var c = doc.createElement('div');
  2964. doc.body.appendChild(c);
  2965. iframe = doc.createElement('iframe');
  2966. c.appendChild(iframe);
  2967. iframe.src = iframeUrl;
  2968. iframe.onerror = function() {
  2969. onerror('onerror');
  2970. };
  2971. tref = setTimeout(function() {
  2972. onerror('timeout');
  2973. }, 15000);
  2974. unloadRef = eventUtils.unloadAdd(cleanup);
  2975. return {
  2976. post: post
  2977. , cleanup: cleanup
  2978. , loaded: unattach
  2979. };
  2980. }
  2981. };
  2982. module.exports.iframeEnabled = false;
  2983. if (global.document) {
  2984. // postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
  2985. // huge delay, or not at all.
  2986. module.exports.iframeEnabled = (typeof global.postMessage === 'function' ||
  2987. typeof global.postMessage === 'object') && (!browser.isKonqueror());
  2988. }
  2989. }).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2990. },{"./browser":44,"./event":46,"debug":54,"json3":57}],48:[function(require,module,exports){
  2991. (function (global){
  2992. 'use strict';
  2993. var logObject = {};
  2994. ['log', 'debug', 'warn'].forEach(function (level) {
  2995. var levelExists;
  2996. try {
  2997. levelExists = global.console && global.console[level] && global.console[level].apply;
  2998. } catch(e) {
  2999. // do nothing
  3000. }
  3001. logObject[level] = levelExists ? function () {
  3002. return global.console[level].apply(global.console, arguments);
  3003. } : (level === 'log' ? function () {} : logObject.log);
  3004. });
  3005. module.exports = logObject;
  3006. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3007. },{}],49:[function(require,module,exports){
  3008. 'use strict';
  3009. module.exports = {
  3010. isObject: function(obj) {
  3011. var type = typeof obj;
  3012. return type === 'function' || type === 'object' && !!obj;
  3013. }
  3014. , extend: function(obj) {
  3015. if (!this.isObject(obj)) {
  3016. return obj;
  3017. }
  3018. var source, prop;
  3019. for (var i = 1, length = arguments.length; i < length; i++) {
  3020. source = arguments[i];
  3021. for (prop in source) {
  3022. if (Object.prototype.hasOwnProperty.call(source, prop)) {
  3023. obj[prop] = source[prop];
  3024. }
  3025. }
  3026. }
  3027. return obj;
  3028. }
  3029. };
  3030. },{}],50:[function(require,module,exports){
  3031. 'use strict';
  3032. /* global crypto:true */
  3033. var crypto = require('crypto');
  3034. // This string has length 32, a power of 2, so the modulus doesn't introduce a
  3035. // bias.
  3036. var _randomStringChars = 'abcdefghijklmnopqrstuvwxyz012345';
  3037. module.exports = {
  3038. string: function(length) {
  3039. var max = _randomStringChars.length;
  3040. var bytes = crypto.randomBytes(length);
  3041. var ret = [];
  3042. for (var i = 0; i < length; i++) {
  3043. ret.push(_randomStringChars.substr(bytes[i] % max, 1));
  3044. }
  3045. return ret.join('');
  3046. }
  3047. , number: function(max) {
  3048. return Math.floor(Math.random() * max);
  3049. }
  3050. , numberString: function(max) {
  3051. var t = ('' + (max - 1)).length;
  3052. var p = new Array(t + 1).join('0');
  3053. return (p + this.number(max)).slice(-t);
  3054. }
  3055. };
  3056. },{"crypto":43}],51:[function(require,module,exports){
  3057. (function (process){
  3058. 'use strict';
  3059. var debug = function() {};
  3060. if (process.env.NODE_ENV !== 'production') {
  3061. debug = require('debug')('sockjs-client:utils:transport');
  3062. }
  3063. module.exports = function(availableTransports) {
  3064. return {
  3065. filterToEnabled: function(transportsWhitelist, info) {
  3066. var transports = {
  3067. main: []
  3068. , facade: []
  3069. };
  3070. if (!transportsWhitelist) {
  3071. transportsWhitelist = [];
  3072. } else if (typeof transportsWhitelist === 'string') {
  3073. transportsWhitelist = [transportsWhitelist];
  3074. }
  3075. availableTransports.forEach(function(trans) {
  3076. if (!trans) {
  3077. return;
  3078. }
  3079. if (trans.transportName === 'websocket' && info.websocket === false) {
  3080. debug('disabled from server', 'websocket');
  3081. return;
  3082. }
  3083. if (transportsWhitelist.length &&
  3084. transportsWhitelist.indexOf(trans.transportName) === -1) {
  3085. debug('not in whitelist', trans.transportName);
  3086. return;
  3087. }
  3088. if (trans.enabled(info)) {
  3089. debug('enabled', trans.transportName);
  3090. transports.main.push(trans);
  3091. if (trans.facadeTransport) {
  3092. transports.facade.push(trans.facadeTransport);
  3093. }
  3094. } else {
  3095. debug('disabled', trans.transportName);
  3096. }
  3097. });
  3098. return transports;
  3099. }
  3100. };
  3101. };
  3102. }).call(this,{ env: {} })
  3103. },{"debug":54}],52:[function(require,module,exports){
  3104. (function (process){
  3105. 'use strict';
  3106. var URL = require('url-parse');
  3107. var debug = function() {};
  3108. if (process.env.NODE_ENV !== 'production') {
  3109. debug = require('debug')('sockjs-client:utils:url');
  3110. }
  3111. module.exports = {
  3112. getOrigin: function(url) {
  3113. if (!url) {
  3114. return null;
  3115. }
  3116. var p = new URL(url);
  3117. if (p.protocol === 'file:') {
  3118. return null;
  3119. }
  3120. var port = p.port;
  3121. if (!port) {
  3122. port = (p.protocol === 'https:') ? '443' : '80';
  3123. }
  3124. return p.protocol + '//' + p.hostname + ':' + port;
  3125. }
  3126. , isOriginEqual: function(a, b) {
  3127. var res = this.getOrigin(a) === this.getOrigin(b);
  3128. debug('same', a, b, res);
  3129. return res;
  3130. }
  3131. , isSchemeEqual: function(a, b) {
  3132. return (a.split(':')[0] === b.split(':')[0]);
  3133. }
  3134. , addPath: function (url, path) {
  3135. var qs = url.split('?');
  3136. return qs[0] + path + (qs[1] ? '?' + qs[1] : '');
  3137. }
  3138. , addQuery: function (url, q) {
  3139. return url + (url.indexOf('?') === -1 ? ('?' + q) : ('&' + q));
  3140. }
  3141. };
  3142. }).call(this,{ env: {} })
  3143. },{"debug":54,"url-parse":61}],53:[function(require,module,exports){
  3144. module.exports = '1.1.2';
  3145. },{}],54:[function(require,module,exports){
  3146. (function (process){
  3147. /**
  3148. * This is the web browser implementation of `debug()`.
  3149. *
  3150. * Expose `debug()` as the module.
  3151. */
  3152. exports = module.exports = require('./debug');
  3153. exports.log = log;
  3154. exports.formatArgs = formatArgs;
  3155. exports.save = save;
  3156. exports.load = load;
  3157. exports.useColors = useColors;
  3158. exports.storage = 'undefined' != typeof chrome
  3159. && 'undefined' != typeof chrome.storage
  3160. ? chrome.storage.local
  3161. : localstorage();
  3162. /**
  3163. * Colors.
  3164. */
  3165. exports.colors = [
  3166. 'lightseagreen',
  3167. 'forestgreen',
  3168. 'goldenrod',
  3169. 'dodgerblue',
  3170. 'darkorchid',
  3171. 'crimson'
  3172. ];
  3173. /**
  3174. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  3175. * and the Firebug extension (any Firefox version) are known
  3176. * to support "%c" CSS customizations.
  3177. *
  3178. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  3179. */
  3180. function useColors() {
  3181. // NB: In an Electron preload script, document will be defined but not fully
  3182. // initialized. Since we know we're in Chrome, we'll just detect this case
  3183. // explicitly
  3184. if (typeof window !== 'undefined' && window && typeof window.process !== 'undefined' && window.process.type === 'renderer') {
  3185. return true;
  3186. }
  3187. // is webkit? http://stackoverflow.com/a/16459606/376773
  3188. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  3189. return (typeof document !== 'undefined' && document && 'WebkitAppearance' in document.documentElement.style) ||
  3190. // is firebug? http://stackoverflow.com/a/398120/376773
  3191. (typeof window !== 'undefined' && window && window.console && (console.firebug || (console.exception && console.table))) ||
  3192. // is firefox >= v31?
  3193. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  3194. (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
  3195. // double check webkit in userAgent just in case we are in a worker
  3196. (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
  3197. }
  3198. /**
  3199. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  3200. */
  3201. exports.formatters.j = function(v) {
  3202. try {
  3203. return JSON.stringify(v);
  3204. } catch (err) {
  3205. return '[UnexpectedJSONParseError]: ' + err.message;
  3206. }
  3207. };
  3208. /**
  3209. * Colorize log arguments if enabled.
  3210. *
  3211. * @api public
  3212. */
  3213. function formatArgs(args) {
  3214. var useColors = this.useColors;
  3215. args[0] = (useColors ? '%c' : '')
  3216. + this.namespace
  3217. + (useColors ? ' %c' : ' ')
  3218. + args[0]
  3219. + (useColors ? '%c ' : ' ')
  3220. + '+' + exports.humanize(this.diff);
  3221. if (!useColors) return;
  3222. var c = 'color: ' + this.color;
  3223. args.splice(1, 0, c, 'color: inherit')
  3224. // the final "%c" is somewhat tricky, because there could be other
  3225. // arguments passed either before or after the %c, so we need to
  3226. // figure out the correct index to insert the CSS into
  3227. var index = 0;
  3228. var lastC = 0;
  3229. args[0].replace(/%[a-zA-Z%]/g, function(match) {
  3230. if ('%%' === match) return;
  3231. index++;
  3232. if ('%c' === match) {
  3233. // we only are interested in the *last* %c
  3234. // (the user may have provided their own)
  3235. lastC = index;
  3236. }
  3237. });
  3238. args.splice(lastC, 0, c);
  3239. }
  3240. /**
  3241. * Invokes `console.log()` when available.
  3242. * No-op when `console.log` is not a "function".
  3243. *
  3244. * @api public
  3245. */
  3246. function log() {
  3247. // this hackery is required for IE8/9, where
  3248. // the `console.log` function doesn't have 'apply'
  3249. return 'object' === typeof console
  3250. && console.log
  3251. && Function.prototype.apply.call(console.log, console, arguments);
  3252. }
  3253. /**
  3254. * Save `namespaces`.
  3255. *
  3256. * @param {String} namespaces
  3257. * @api private
  3258. */
  3259. function save(namespaces) {
  3260. try {
  3261. if (null == namespaces) {
  3262. exports.storage.removeItem('debug');
  3263. } else {
  3264. exports.storage.debug = namespaces;
  3265. }
  3266. } catch(e) {}
  3267. }
  3268. /**
  3269. * Load `namespaces`.
  3270. *
  3271. * @return {String} returns the previously persisted debug modes
  3272. * @api private
  3273. */
  3274. function load() {
  3275. try {
  3276. return exports.storage.debug;
  3277. } catch(e) {}
  3278. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  3279. if (typeof process !== 'undefined' && 'env' in process) {
  3280. return process.env.DEBUG;
  3281. }
  3282. }
  3283. /**
  3284. * Enable namespaces listed in `localStorage.debug` initially.
  3285. */
  3286. exports.enable(load());
  3287. /**
  3288. * Localstorage attempts to return the localstorage.
  3289. *
  3290. * This is necessary because safari throws
  3291. * when a user disables cookies/localstorage
  3292. * and you attempt to access it.
  3293. *
  3294. * @return {LocalStorage}
  3295. * @api private
  3296. */
  3297. function localstorage() {
  3298. try {
  3299. return window.localStorage;
  3300. } catch (e) {}
  3301. }
  3302. }).call(this,{ env: {} })
  3303. },{"./debug":55}],55:[function(require,module,exports){
  3304. /**
  3305. * This is the common logic for both the Node.js and web browser
  3306. * implementations of `debug()`.
  3307. *
  3308. * Expose `debug()` as the module.
  3309. */
  3310. exports = module.exports = createDebug.debug = createDebug.default = createDebug;
  3311. exports.coerce = coerce;
  3312. exports.disable = disable;
  3313. exports.enable = enable;
  3314. exports.enabled = enabled;
  3315. exports.humanize = require('ms');
  3316. /**
  3317. * The currently active debug mode names, and names to skip.
  3318. */
  3319. exports.names = [];
  3320. exports.skips = [];
  3321. /**
  3322. * Map of special "%n" handling functions, for the debug "format" argument.
  3323. *
  3324. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  3325. */
  3326. exports.formatters = {};
  3327. /**
  3328. * Previous log timestamp.
  3329. */
  3330. var prevTime;
  3331. /**
  3332. * Select a color.
  3333. * @param {String} namespace
  3334. * @return {Number}
  3335. * @api private
  3336. */
  3337. function selectColor(namespace) {
  3338. var hash = 0, i;
  3339. for (i in namespace) {
  3340. hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
  3341. hash |= 0; // Convert to 32bit integer
  3342. }
  3343. return exports.colors[Math.abs(hash) % exports.colors.length];
  3344. }
  3345. /**
  3346. * Create a debugger with the given `namespace`.
  3347. *
  3348. * @param {String} namespace
  3349. * @return {Function}
  3350. * @api public
  3351. */
  3352. function createDebug(namespace) {
  3353. function debug() {
  3354. // disabled?
  3355. if (!debug.enabled) return;
  3356. var self = debug;
  3357. // set `diff` timestamp
  3358. var curr = +new Date();
  3359. var ms = curr - (prevTime || curr);
  3360. self.diff = ms;
  3361. self.prev = prevTime;
  3362. self.curr = curr;
  3363. prevTime = curr;
  3364. // turn the `arguments` into a proper Array
  3365. var args = new Array(arguments.length);
  3366. for (var i = 0; i < args.length; i++) {
  3367. args[i] = arguments[i];
  3368. }
  3369. args[0] = exports.coerce(args[0]);
  3370. if ('string' !== typeof args[0]) {
  3371. // anything else let's inspect with %O
  3372. args.unshift('%O');
  3373. }
  3374. // apply any `formatters` transformations
  3375. var index = 0;
  3376. args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
  3377. // if we encounter an escaped % then don't increase the array index
  3378. if (match === '%%') return match;
  3379. index++;
  3380. var formatter = exports.formatters[format];
  3381. if ('function' === typeof formatter) {
  3382. var val = args[index];
  3383. match = formatter.call(self, val);
  3384. // now we need to remove `args[index]` since it's inlined in the `format`
  3385. args.splice(index, 1);
  3386. index--;
  3387. }
  3388. return match;
  3389. });
  3390. // apply env-specific formatting (colors, etc.)
  3391. exports.formatArgs.call(self, args);
  3392. var logFn = debug.log || exports.log || console.log.bind(console);
  3393. logFn.apply(self, args);
  3394. }
  3395. debug.namespace = namespace;
  3396. debug.enabled = exports.enabled(namespace);
  3397. debug.useColors = exports.useColors();
  3398. debug.color = selectColor(namespace);
  3399. // env-specific initialization logic for debug instances
  3400. if ('function' === typeof exports.init) {
  3401. exports.init(debug);
  3402. }
  3403. return debug;
  3404. }
  3405. /**
  3406. * Enables a debug mode by namespaces. This can include modes
  3407. * separated by a colon and wildcards.
  3408. *
  3409. * @param {String} namespaces
  3410. * @api public
  3411. */
  3412. function enable(namespaces) {
  3413. exports.save(namespaces);
  3414. var split = (namespaces || '').split(/[\s,]+/);
  3415. var len = split.length;
  3416. for (var i = 0; i < len; i++) {
  3417. if (!split[i]) continue; // ignore empty strings
  3418. namespaces = split[i].replace(/\*/g, '.*?');
  3419. if (namespaces[0] === '-') {
  3420. exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  3421. } else {
  3422. exports.names.push(new RegExp('^' + namespaces + '$'));
  3423. }
  3424. }
  3425. }
  3426. /**
  3427. * Disable debug output.
  3428. *
  3429. * @api public
  3430. */
  3431. function disable() {
  3432. exports.enable('');
  3433. }
  3434. /**
  3435. * Returns true if the given mode name is enabled, false otherwise.
  3436. *
  3437. * @param {String} name
  3438. * @return {Boolean}
  3439. * @api public
  3440. */
  3441. function enabled(name) {
  3442. var i, len;
  3443. for (i = 0, len = exports.skips.length; i < len; i++) {
  3444. if (exports.skips[i].test(name)) {
  3445. return false;
  3446. }
  3447. }
  3448. for (i = 0, len = exports.names.length; i < len; i++) {
  3449. if (exports.names[i].test(name)) {
  3450. return true;
  3451. }
  3452. }
  3453. return false;
  3454. }
  3455. /**
  3456. * Coerce `val`.
  3457. *
  3458. * @param {Mixed} val
  3459. * @return {Mixed}
  3460. * @api private
  3461. */
  3462. function coerce(val) {
  3463. if (val instanceof Error) return val.stack || val.message;
  3464. return val;
  3465. }
  3466. },{"ms":58}],56:[function(require,module,exports){
  3467. if (typeof Object.create === 'function') {
  3468. // implementation from standard node.js 'util' module
  3469. module.exports = function inherits(ctor, superCtor) {
  3470. ctor.super_ = superCtor
  3471. ctor.prototype = Object.create(superCtor.prototype, {
  3472. constructor: {
  3473. value: ctor,
  3474. enumerable: false,
  3475. writable: true,
  3476. configurable: true
  3477. }
  3478. });
  3479. };
  3480. } else {
  3481. // old school shim for old browsers
  3482. module.exports = function inherits(ctor, superCtor) {
  3483. ctor.super_ = superCtor
  3484. var TempCtor = function () {}
  3485. TempCtor.prototype = superCtor.prototype
  3486. ctor.prototype = new TempCtor()
  3487. ctor.prototype.constructor = ctor
  3488. }
  3489. }
  3490. },{}],57:[function(require,module,exports){
  3491. (function (global){
  3492. /*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
  3493. ;(function () {
  3494. // Detect the `define` function exposed by asynchronous module loaders. The
  3495. // strict `define` check is necessary for compatibility with `r.js`.
  3496. var isLoader = typeof define === "function" && define.amd;
  3497. // A set of types used to distinguish objects from primitives.
  3498. var objectTypes = {
  3499. "function": true,
  3500. "object": true
  3501. };
  3502. // Detect the `exports` object exposed by CommonJS implementations.
  3503. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  3504. // Use the `global` object exposed by Node (including Browserify via
  3505. // `insert-module-globals`), Narwhal, and Ringo as the default context,
  3506. // and the `window` object in browsers. Rhino exports a `global` function
  3507. // instead.
  3508. var root = objectTypes[typeof window] && window || this,
  3509. freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
  3510. if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
  3511. root = freeGlobal;
  3512. }
  3513. // Public: Initializes JSON 3 using the given `context` object, attaching the
  3514. // `stringify` and `parse` functions to the specified `exports` object.
  3515. function runInContext(context, exports) {
  3516. context || (context = root["Object"]());
  3517. exports || (exports = root["Object"]());
  3518. // Native constructor aliases.
  3519. var Number = context["Number"] || root["Number"],
  3520. String = context["String"] || root["String"],
  3521. Object = context["Object"] || root["Object"],
  3522. Date = context["Date"] || root["Date"],
  3523. SyntaxError = context["SyntaxError"] || root["SyntaxError"],
  3524. TypeError = context["TypeError"] || root["TypeError"],
  3525. Math = context["Math"] || root["Math"],
  3526. nativeJSON = context["JSON"] || root["JSON"];
  3527. // Delegate to the native `stringify` and `parse` implementations.
  3528. if (typeof nativeJSON == "object" && nativeJSON) {
  3529. exports.stringify = nativeJSON.stringify;
  3530. exports.parse = nativeJSON.parse;
  3531. }
  3532. // Convenience aliases.
  3533. var objectProto = Object.prototype,
  3534. getClass = objectProto.toString,
  3535. isProperty, forEach, undef;
  3536. // Test the `Date#getUTC*` methods. Based on work by @Yaffle.
  3537. var isExtended = new Date(-3509827334573292);
  3538. try {
  3539. // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
  3540. // results for certain dates in Opera >= 10.53.
  3541. isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
  3542. // Safari < 2.0.2 stores the internal millisecond time value correctly,
  3543. // but clips the values returned by the date methods to the range of
  3544. // signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
  3545. isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
  3546. } catch (exception) {}
  3547. // Internal: Determines whether the native `JSON.stringify` and `parse`
  3548. // implementations are spec-compliant. Based on work by Ken Snyder.
  3549. function has(name) {
  3550. if (has[name] !== undef) {
  3551. // Return cached feature test result.
  3552. return has[name];
  3553. }
  3554. var isSupported;
  3555. if (name == "bug-string-char-index") {
  3556. // IE <= 7 doesn't support accessing string characters using square
  3557. // bracket notation. IE 8 only supports this for primitives.
  3558. isSupported = "a"[0] != "a";
  3559. } else if (name == "json") {
  3560. // Indicates whether both `JSON.stringify` and `JSON.parse` are
  3561. // supported.
  3562. isSupported = has("json-stringify") && has("json-parse");
  3563. } else {
  3564. var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
  3565. // Test `JSON.stringify`.
  3566. if (name == "json-stringify") {
  3567. var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
  3568. if (stringifySupported) {
  3569. // A test function object with a custom `toJSON` method.
  3570. (value = function () {
  3571. return 1;
  3572. }).toJSON = value;
  3573. try {
  3574. stringifySupported =
  3575. // Firefox 3.1b1 and b2 serialize string, number, and boolean
  3576. // primitives as object literals.
  3577. stringify(0) === "0" &&
  3578. // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
  3579. // literals.
  3580. stringify(new Number()) === "0" &&
  3581. stringify(new String()) == '""' &&
  3582. // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
  3583. // does not define a canonical JSON representation (this applies to
  3584. // objects with `toJSON` properties as well, *unless* they are nested
  3585. // within an object or array).
  3586. stringify(getClass) === undef &&
  3587. // IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
  3588. // FF 3.1b3 pass this test.
  3589. stringify(undef) === undef &&
  3590. // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
  3591. // respectively, if the value is omitted entirely.
  3592. stringify() === undef &&
  3593. // FF 3.1b1, 2 throw an error if the given value is not a number,
  3594. // string, array, object, Boolean, or `null` literal. This applies to
  3595. // objects with custom `toJSON` methods as well, unless they are nested
  3596. // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
  3597. // methods entirely.
  3598. stringify(value) === "1" &&
  3599. stringify([value]) == "[1]" &&
  3600. // Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
  3601. // `"[null]"`.
  3602. stringify([undef]) == "[null]" &&
  3603. // YUI 3.0.0b1 fails to serialize `null` literals.
  3604. stringify(null) == "null" &&
  3605. // FF 3.1b1, 2 halts serialization if an array contains a function:
  3606. // `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
  3607. // elides non-JSON values from objects and arrays, unless they
  3608. // define custom `toJSON` methods.
  3609. stringify([undef, getClass, null]) == "[null,null,null]" &&
  3610. // Simple serialization test. FF 3.1b1 uses Unicode escape sequences
  3611. // where character escape codes are expected (e.g., `\b` => `\u0008`).
  3612. stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
  3613. // FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
  3614. stringify(null, value) === "1" &&
  3615. stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
  3616. // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
  3617. // serialize extended years.
  3618. stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
  3619. // The milliseconds are optional in ES 5, but required in 5.1.
  3620. stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
  3621. // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
  3622. // four-digit years instead of six-digit years. Credits: @Yaffle.
  3623. stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
  3624. // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
  3625. // values less than 1000. Credits: @Yaffle.
  3626. stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
  3627. } catch (exception) {
  3628. stringifySupported = false;
  3629. }
  3630. }
  3631. isSupported = stringifySupported;
  3632. }
  3633. // Test `JSON.parse`.
  3634. if (name == "json-parse") {
  3635. var parse = exports.parse;
  3636. if (typeof parse == "function") {
  3637. try {
  3638. // FF 3.1b1, b2 will throw an exception if a bare literal is provided.
  3639. // Conforming implementations should also coerce the initial argument to
  3640. // a string prior to parsing.
  3641. if (parse("0") === 0 && !parse(false)) {
  3642. // Simple parsing test.
  3643. value = parse(serialized);
  3644. var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
  3645. if (parseSupported) {
  3646. try {
  3647. // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
  3648. parseSupported = !parse('"\t"');
  3649. } catch (exception) {}
  3650. if (parseSupported) {
  3651. try {
  3652. // FF 4.0 and 4.0.1 allow leading `+` signs and leading
  3653. // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
  3654. // certain octal literals.
  3655. parseSupported = parse("01") !== 1;
  3656. } catch (exception) {}
  3657. }
  3658. if (parseSupported) {
  3659. try {
  3660. // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
  3661. // points. These environments, along with FF 3.1b1 and 2,
  3662. // also allow trailing commas in JSON objects and arrays.
  3663. parseSupported = parse("1.") !== 1;
  3664. } catch (exception) {}
  3665. }
  3666. }
  3667. }
  3668. } catch (exception) {
  3669. parseSupported = false;
  3670. }
  3671. }
  3672. isSupported = parseSupported;
  3673. }
  3674. }
  3675. return has[name] = !!isSupported;
  3676. }
  3677. if (!has("json")) {
  3678. // Common `[[Class]]` name aliases.
  3679. var functionClass = "[object Function]",
  3680. dateClass = "[object Date]",
  3681. numberClass = "[object Number]",
  3682. stringClass = "[object String]",
  3683. arrayClass = "[object Array]",
  3684. booleanClass = "[object Boolean]";
  3685. // Detect incomplete support for accessing string characters by index.
  3686. var charIndexBuggy = has("bug-string-char-index");
  3687. // Define additional utility methods if the `Date` methods are buggy.
  3688. if (!isExtended) {
  3689. var floor = Math.floor;
  3690. // A mapping between the months of the year and the number of days between
  3691. // January 1st and the first of the respective month.
  3692. var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
  3693. // Internal: Calculates the number of days between the Unix epoch and the
  3694. // first day of the given month.
  3695. var getDay = function (year, month) {
  3696. return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
  3697. };
  3698. }
  3699. // Internal: Determines if a property is a direct property of the given
  3700. // object. Delegates to the native `Object#hasOwnProperty` method.
  3701. if (!(isProperty = objectProto.hasOwnProperty)) {
  3702. isProperty = function (property) {
  3703. var members = {}, constructor;
  3704. if ((members.__proto__ = null, members.__proto__ = {
  3705. // The *proto* property cannot be set multiple times in recent
  3706. // versions of Firefox and SeaMonkey.
  3707. "toString": 1
  3708. }, members).toString != getClass) {
  3709. // Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
  3710. // supports the mutable *proto* property.
  3711. isProperty = function (property) {
  3712. // Capture and break the object's prototype chain (see section 8.6.2
  3713. // of the ES 5.1 spec). The parenthesized expression prevents an
  3714. // unsafe transformation by the Closure Compiler.
  3715. var original = this.__proto__, result = property in (this.__proto__ = null, this);
  3716. // Restore the original prototype chain.
  3717. this.__proto__ = original;
  3718. return result;
  3719. };
  3720. } else {
  3721. // Capture a reference to the top-level `Object` constructor.
  3722. constructor = members.constructor;
  3723. // Use the `constructor` property to simulate `Object#hasOwnProperty` in
  3724. // other environments.
  3725. isProperty = function (property) {
  3726. var parent = (this.constructor || constructor).prototype;
  3727. return property in this && !(property in parent && this[property] === parent[property]);
  3728. };
  3729. }
  3730. members = null;
  3731. return isProperty.call(this, property);
  3732. };
  3733. }
  3734. // Internal: Normalizes the `for...in` iteration algorithm across
  3735. // environments. Each enumerated key is yielded to a `callback` function.
  3736. forEach = function (object, callback) {
  3737. var size = 0, Properties, members, property;
  3738. // Tests for bugs in the current environment's `for...in` algorithm. The
  3739. // `valueOf` property inherits the non-enumerable flag from
  3740. // `Object.prototype` in older versions of IE, Netscape, and Mozilla.
  3741. (Properties = function () {
  3742. this.valueOf = 0;
  3743. }).prototype.valueOf = 0;
  3744. // Iterate over a new instance of the `Properties` class.
  3745. members = new Properties();
  3746. for (property in members) {
  3747. // Ignore all properties inherited from `Object.prototype`.
  3748. if (isProperty.call(members, property)) {
  3749. size++;
  3750. }
  3751. }
  3752. Properties = members = null;
  3753. // Normalize the iteration algorithm.
  3754. if (!size) {
  3755. // A list of non-enumerable properties inherited from `Object.prototype`.
  3756. members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
  3757. // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
  3758. // properties.
  3759. forEach = function (object, callback) {
  3760. var isFunction = getClass.call(object) == functionClass, property, length;
  3761. var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
  3762. for (property in object) {
  3763. // Gecko <= 1.0 enumerates the `prototype` property of functions under
  3764. // certain conditions; IE does not.
  3765. if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
  3766. callback(property);
  3767. }
  3768. }
  3769. // Manually invoke the callback for each non-enumerable property.
  3770. for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
  3771. };
  3772. } else if (size == 2) {
  3773. // Safari <= 2.0.4 enumerates shadowed properties twice.
  3774. forEach = function (object, callback) {
  3775. // Create a set of iterated properties.
  3776. var members = {}, isFunction = getClass.call(object) == functionClass, property;
  3777. for (property in object) {
  3778. // Store each property name to prevent double enumeration. The
  3779. // `prototype` property of functions is not enumerated due to cross-
  3780. // environment inconsistencies.
  3781. if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
  3782. callback(property);
  3783. }
  3784. }
  3785. };
  3786. } else {
  3787. // No bugs detected; use the standard `for...in` algorithm.
  3788. forEach = function (object, callback) {
  3789. var isFunction = getClass.call(object) == functionClass, property, isConstructor;
  3790. for (property in object) {
  3791. if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
  3792. callback(property);
  3793. }
  3794. }
  3795. // Manually invoke the callback for the `constructor` property due to
  3796. // cross-environment inconsistencies.
  3797. if (isConstructor || isProperty.call(object, (property = "constructor"))) {
  3798. callback(property);
  3799. }
  3800. };
  3801. }
  3802. return forEach(object, callback);
  3803. };
  3804. // Public: Serializes a JavaScript `value` as a JSON string. The optional
  3805. // `filter` argument may specify either a function that alters how object and
  3806. // array members are serialized, or an array of strings and numbers that
  3807. // indicates which properties should be serialized. The optional `width`
  3808. // argument may be either a string or number that specifies the indentation
  3809. // level of the output.
  3810. if (!has("json-stringify")) {
  3811. // Internal: A map of control characters and their escaped equivalents.
  3812. var Escapes = {
  3813. 92: "\\\\",
  3814. 34: '\\"',
  3815. 8: "\\b",
  3816. 12: "\\f",
  3817. 10: "\\n",
  3818. 13: "\\r",
  3819. 9: "\\t"
  3820. };
  3821. // Internal: Converts `value` into a zero-padded string such that its
  3822. // length is at least equal to `width`. The `width` must be <= 6.
  3823. var leadingZeroes = "000000";
  3824. var toPaddedString = function (width, value) {
  3825. // The `|| 0` expression is necessary to work around a bug in
  3826. // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
  3827. return (leadingZeroes + (value || 0)).slice(-width);
  3828. };
  3829. // Internal: Double-quotes a string `value`, replacing all ASCII control
  3830. // characters (characters with code unit values between 0 and 31) with
  3831. // their escaped equivalents. This is an implementation of the
  3832. // `Quote(value)` operation defined in ES 5.1 section 15.12.3.
  3833. var unicodePrefix = "\\u00";
  3834. var quote = function (value) {
  3835. var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
  3836. var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
  3837. for (; index < length; index++) {
  3838. var charCode = value.charCodeAt(index);
  3839. // If the character is a control character, append its Unicode or
  3840. // shorthand escape sequence; otherwise, append the character as-is.
  3841. switch (charCode) {
  3842. case 8: case 9: case 10: case 12: case 13: case 34: case 92:
  3843. result += Escapes[charCode];
  3844. break;
  3845. default:
  3846. if (charCode < 32) {
  3847. result += unicodePrefix + toPaddedString(2, charCode.toString(16));
  3848. break;
  3849. }
  3850. result += useCharIndex ? symbols[index] : value.charAt(index);
  3851. }
  3852. }
  3853. return result + '"';
  3854. };
  3855. // Internal: Recursively serializes an object. Implements the
  3856. // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
  3857. var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
  3858. var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
  3859. try {
  3860. // Necessary for host object support.
  3861. value = object[property];
  3862. } catch (exception) {}
  3863. if (typeof value == "object" && value) {
  3864. className = getClass.call(value);
  3865. if (className == dateClass && !isProperty.call(value, "toJSON")) {
  3866. if (value > -1 / 0 && value < 1 / 0) {
  3867. // Dates are serialized according to the `Date#toJSON` method
  3868. // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
  3869. // for the ISO 8601 date time string format.
  3870. if (getDay) {
  3871. // Manually compute the year, month, date, hours, minutes,
  3872. // seconds, and milliseconds if the `getUTC*` methods are
  3873. // buggy. Adapted from @Yaffle's `date-shim` project.
  3874. date = floor(value / 864e5);
  3875. for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
  3876. for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
  3877. date = 1 + date - getDay(year, month);
  3878. // The `time` value specifies the time within the day (see ES
  3879. // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
  3880. // to compute `A modulo B`, as the `%` operator does not
  3881. // correspond to the `modulo` operation for negative numbers.
  3882. time = (value % 864e5 + 864e5) % 864e5;
  3883. // The hours, minutes, seconds, and milliseconds are obtained by
  3884. // decomposing the time within the day. See section 15.9.1.10.
  3885. hours = floor(time / 36e5) % 24;
  3886. minutes = floor(time / 6e4) % 60;
  3887. seconds = floor(time / 1e3) % 60;
  3888. milliseconds = time % 1e3;
  3889. } else {
  3890. year = value.getUTCFullYear();
  3891. month = value.getUTCMonth();
  3892. date = value.getUTCDate();
  3893. hours = value.getUTCHours();
  3894. minutes = value.getUTCMinutes();
  3895. seconds = value.getUTCSeconds();
  3896. milliseconds = value.getUTCMilliseconds();
  3897. }
  3898. // Serialize extended years correctly.
  3899. value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
  3900. "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
  3901. // Months, dates, hours, minutes, and seconds should have two
  3902. // digits; milliseconds should have three.
  3903. "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
  3904. // Milliseconds are optional in ES 5.0, but required in 5.1.
  3905. "." + toPaddedString(3, milliseconds) + "Z";
  3906. } else {
  3907. value = null;
  3908. }
  3909. } else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
  3910. // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
  3911. // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
  3912. // ignores all `toJSON` methods on these objects unless they are
  3913. // defined directly on an instance.
  3914. value = value.toJSON(property);
  3915. }
  3916. }
  3917. if (callback) {
  3918. // If a replacement function was provided, call it to obtain the value
  3919. // for serialization.
  3920. value = callback.call(object, property, value);
  3921. }
  3922. if (value === null) {
  3923. return "null";
  3924. }
  3925. className = getClass.call(value);
  3926. if (className == booleanClass) {
  3927. // Booleans are represented literally.
  3928. return "" + value;
  3929. } else if (className == numberClass) {
  3930. // JSON numbers must be finite. `Infinity` and `NaN` are serialized as
  3931. // `"null"`.
  3932. return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
  3933. } else if (className == stringClass) {
  3934. // Strings are double-quoted and escaped.
  3935. return quote("" + value);
  3936. }
  3937. // Recursively serialize objects and arrays.
  3938. if (typeof value == "object") {
  3939. // Check for cyclic structures. This is a linear search; performance
  3940. // is inversely proportional to the number of unique nested objects.
  3941. for (length = stack.length; length--;) {
  3942. if (stack[length] === value) {
  3943. // Cyclic structures cannot be serialized by `JSON.stringify`.
  3944. throw TypeError();
  3945. }
  3946. }
  3947. // Add the object to the stack of traversed objects.
  3948. stack.push(value);
  3949. results = [];
  3950. // Save the current indentation level and indent one additional level.
  3951. prefix = indentation;
  3952. indentation += whitespace;
  3953. if (className == arrayClass) {
  3954. // Recursively serialize array elements.
  3955. for (index = 0, length = value.length; index < length; index++) {
  3956. element = serialize(index, value, callback, properties, whitespace, indentation, stack);
  3957. results.push(element === undef ? "null" : element);
  3958. }
  3959. result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
  3960. } else {
  3961. // Recursively serialize object members. Members are selected from
  3962. // either a user-specified list of property names, or the object
  3963. // itself.
  3964. forEach(properties || value, function (property) {
  3965. var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
  3966. if (element !== undef) {
  3967. // According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
  3968. // is not the empty string, let `member` {quote(property) + ":"}
  3969. // be the concatenation of `member` and the `space` character."
  3970. // The "`space` character" refers to the literal space
  3971. // character, not the `space` {width} argument provided to
  3972. // `JSON.stringify`.
  3973. results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
  3974. }
  3975. });
  3976. result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
  3977. }
  3978. // Remove the object from the traversed object stack.
  3979. stack.pop();
  3980. return result;
  3981. }
  3982. };
  3983. // Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
  3984. exports.stringify = function (source, filter, width) {
  3985. var whitespace, callback, properties, className;
  3986. if (objectTypes[typeof filter] && filter) {
  3987. if ((className = getClass.call(filter)) == functionClass) {
  3988. callback = filter;
  3989. } else if (className == arrayClass) {
  3990. // Convert the property names array into a makeshift set.
  3991. properties = {};
  3992. for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
  3993. }
  3994. }
  3995. if (width) {
  3996. if ((className = getClass.call(width)) == numberClass) {
  3997. // Convert the `width` to an integer and create a string containing
  3998. // `width` number of space characters.
  3999. if ((width -= width % 1) > 0) {
  4000. for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
  4001. }
  4002. } else if (className == stringClass) {
  4003. whitespace = width.length <= 10 ? width : width.slice(0, 10);
  4004. }
  4005. }
  4006. // Opera <= 7.54u2 discards the values associated with empty string keys
  4007. // (`""`) only if they are used directly within an object member list
  4008. // (e.g., `!("" in { "": 1})`).
  4009. return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
  4010. };
  4011. }
  4012. // Public: Parses a JSON source string.
  4013. if (!has("json-parse")) {
  4014. var fromCharCode = String.fromCharCode;
  4015. // Internal: A map of escaped control characters and their unescaped
  4016. // equivalents.
  4017. var Unescapes = {
  4018. 92: "\\",
  4019. 34: '"',
  4020. 47: "/",
  4021. 98: "\b",
  4022. 116: "\t",
  4023. 110: "\n",
  4024. 102: "\f",
  4025. 114: "\r"
  4026. };
  4027. // Internal: Stores the parser state.
  4028. var Index, Source;
  4029. // Internal: Resets the parser state and throws a `SyntaxError`.
  4030. var abort = function () {
  4031. Index = Source = null;
  4032. throw SyntaxError();
  4033. };
  4034. // Internal: Returns the next token, or `"$"` if the parser has reached
  4035. // the end of the source string. A token may be a string, number, `null`
  4036. // literal, or Boolean literal.
  4037. var lex = function () {
  4038. var source = Source, length = source.length, value, begin, position, isSigned, charCode;
  4039. while (Index < length) {
  4040. charCode = source.charCodeAt(Index);
  4041. switch (charCode) {
  4042. case 9: case 10: case 13: case 32:
  4043. // Skip whitespace tokens, including tabs, carriage returns, line
  4044. // feeds, and space characters.
  4045. Index++;
  4046. break;
  4047. case 123: case 125: case 91: case 93: case 58: case 44:
  4048. // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
  4049. // the current position.
  4050. value = charIndexBuggy ? source.charAt(Index) : source[Index];
  4051. Index++;
  4052. return value;
  4053. case 34:
  4054. // `"` delimits a JSON string; advance to the next character and
  4055. // begin parsing the string. String tokens are prefixed with the
  4056. // sentinel `@` character to distinguish them from punctuators and
  4057. // end-of-string tokens.
  4058. for (value = "@", Index++; Index < length;) {
  4059. charCode = source.charCodeAt(Index);
  4060. if (charCode < 32) {
  4061. // Unescaped ASCII control characters (those with a code unit
  4062. // less than the space character) are not permitted.
  4063. abort();
  4064. } else if (charCode == 92) {
  4065. // A reverse solidus (`\`) marks the beginning of an escaped
  4066. // control character (including `"`, `\`, and `/`) or Unicode
  4067. // escape sequence.
  4068. charCode = source.charCodeAt(++Index);
  4069. switch (charCode) {
  4070. case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
  4071. // Revive escaped control characters.
  4072. value += Unescapes[charCode];
  4073. Index++;
  4074. break;
  4075. case 117:
  4076. // `\u` marks the beginning of a Unicode escape sequence.
  4077. // Advance to the first character and validate the
  4078. // four-digit code point.
  4079. begin = ++Index;
  4080. for (position = Index + 4; Index < position; Index++) {
  4081. charCode = source.charCodeAt(Index);
  4082. // A valid sequence comprises four hexdigits (case-
  4083. // insensitive) that form a single hexadecimal value.
  4084. if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
  4085. // Invalid Unicode escape sequence.
  4086. abort();
  4087. }
  4088. }
  4089. // Revive the escaped character.
  4090. value += fromCharCode("0x" + source.slice(begin, Index));
  4091. break;
  4092. default:
  4093. // Invalid escape sequence.
  4094. abort();
  4095. }
  4096. } else {
  4097. if (charCode == 34) {
  4098. // An unescaped double-quote character marks the end of the
  4099. // string.
  4100. break;
  4101. }
  4102. charCode = source.charCodeAt(Index);
  4103. begin = Index;
  4104. // Optimize for the common case where a string is valid.
  4105. while (charCode >= 32 && charCode != 92 && charCode != 34) {
  4106. charCode = source.charCodeAt(++Index);
  4107. }
  4108. // Append the string as-is.
  4109. value += source.slice(begin, Index);
  4110. }
  4111. }
  4112. if (source.charCodeAt(Index) == 34) {
  4113. // Advance to the next character and return the revived string.
  4114. Index++;
  4115. return value;
  4116. }
  4117. // Unterminated string.
  4118. abort();
  4119. default:
  4120. // Parse numbers and literals.
  4121. begin = Index;
  4122. // Advance past the negative sign, if one is specified.
  4123. if (charCode == 45) {
  4124. isSigned = true;
  4125. charCode = source.charCodeAt(++Index);
  4126. }
  4127. // Parse an integer or floating-point value.
  4128. if (charCode >= 48 && charCode <= 57) {
  4129. // Leading zeroes are interpreted as octal literals.
  4130. if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
  4131. // Illegal octal literal.
  4132. abort();
  4133. }
  4134. isSigned = false;
  4135. // Parse the integer component.
  4136. for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
  4137. // Floats cannot contain a leading decimal point; however, this
  4138. // case is already accounted for by the parser.
  4139. if (source.charCodeAt(Index) == 46) {
  4140. position = ++Index;
  4141. // Parse the decimal component.
  4142. for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  4143. if (position == Index) {
  4144. // Illegal trailing decimal.
  4145. abort();
  4146. }
  4147. Index = position;
  4148. }
  4149. // Parse exponents. The `e` denoting the exponent is
  4150. // case-insensitive.
  4151. charCode = source.charCodeAt(Index);
  4152. if (charCode == 101 || charCode == 69) {
  4153. charCode = source.charCodeAt(++Index);
  4154. // Skip past the sign following the exponent, if one is
  4155. // specified.
  4156. if (charCode == 43 || charCode == 45) {
  4157. Index++;
  4158. }
  4159. // Parse the exponential component.
  4160. for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  4161. if (position == Index) {
  4162. // Illegal empty exponent.
  4163. abort();
  4164. }
  4165. Index = position;
  4166. }
  4167. // Coerce the parsed value to a JavaScript number.
  4168. return +source.slice(begin, Index);
  4169. }
  4170. // A negative sign may only precede numbers.
  4171. if (isSigned) {
  4172. abort();
  4173. }
  4174. // `true`, `false`, and `null` literals.
  4175. if (source.slice(Index, Index + 4) == "true") {
  4176. Index += 4;
  4177. return true;
  4178. } else if (source.slice(Index, Index + 5) == "false") {
  4179. Index += 5;
  4180. return false;
  4181. } else if (source.slice(Index, Index + 4) == "null") {
  4182. Index += 4;
  4183. return null;
  4184. }
  4185. // Unrecognized token.
  4186. abort();
  4187. }
  4188. }
  4189. // Return the sentinel `$` character if the parser has reached the end
  4190. // of the source string.
  4191. return "$";
  4192. };
  4193. // Internal: Parses a JSON `value` token.
  4194. var get = function (value) {
  4195. var results, hasMembers;
  4196. if (value == "$") {
  4197. // Unexpected end of input.
  4198. abort();
  4199. }
  4200. if (typeof value == "string") {
  4201. if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
  4202. // Remove the sentinel `@` character.
  4203. return value.slice(1);
  4204. }
  4205. // Parse object and array literals.
  4206. if (value == "[") {
  4207. // Parses a JSON array, returning a new JavaScript array.
  4208. results = [];
  4209. for (;; hasMembers || (hasMembers = true)) {
  4210. value = lex();
  4211. // A closing square bracket marks the end of the array literal.
  4212. if (value == "]") {
  4213. break;
  4214. }
  4215. // If the array literal contains elements, the current token
  4216. // should be a comma separating the previous element from the
  4217. // next.
  4218. if (hasMembers) {
  4219. if (value == ",") {
  4220. value = lex();
  4221. if (value == "]") {
  4222. // Unexpected trailing `,` in array literal.
  4223. abort();
  4224. }
  4225. } else {
  4226. // A `,` must separate each array element.
  4227. abort();
  4228. }
  4229. }
  4230. // Elisions and leading commas are not permitted.
  4231. if (value == ",") {
  4232. abort();
  4233. }
  4234. results.push(get(value));
  4235. }
  4236. return results;
  4237. } else if (value == "{") {
  4238. // Parses a JSON object, returning a new JavaScript object.
  4239. results = {};
  4240. for (;; hasMembers || (hasMembers = true)) {
  4241. value = lex();
  4242. // A closing curly brace marks the end of the object literal.
  4243. if (value == "}") {
  4244. break;
  4245. }
  4246. // If the object literal contains members, the current token
  4247. // should be a comma separator.
  4248. if (hasMembers) {
  4249. if (value == ",") {
  4250. value = lex();
  4251. if (value == "}") {
  4252. // Unexpected trailing `,` in object literal.
  4253. abort();
  4254. }
  4255. } else {
  4256. // A `,` must separate each object member.
  4257. abort();
  4258. }
  4259. }
  4260. // Leading commas are not permitted, object property names must be
  4261. // double-quoted strings, and a `:` must separate each property
  4262. // name and value.
  4263. if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
  4264. abort();
  4265. }
  4266. results[value.slice(1)] = get(lex());
  4267. }
  4268. return results;
  4269. }
  4270. // Unexpected token encountered.
  4271. abort();
  4272. }
  4273. return value;
  4274. };
  4275. // Internal: Updates a traversed object member.
  4276. var update = function (source, property, callback) {
  4277. var element = walk(source, property, callback);
  4278. if (element === undef) {
  4279. delete source[property];
  4280. } else {
  4281. source[property] = element;
  4282. }
  4283. };
  4284. // Internal: Recursively traverses a parsed JSON object, invoking the
  4285. // `callback` function for each value. This is an implementation of the
  4286. // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
  4287. var walk = function (source, property, callback) {
  4288. var value = source[property], length;
  4289. if (typeof value == "object" && value) {
  4290. // `forEach` can't be used to traverse an array in Opera <= 8.54
  4291. // because its `Object#hasOwnProperty` implementation returns `false`
  4292. // for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
  4293. if (getClass.call(value) == arrayClass) {
  4294. for (length = value.length; length--;) {
  4295. update(value, length, callback);
  4296. }
  4297. } else {
  4298. forEach(value, function (property) {
  4299. update(value, property, callback);
  4300. });
  4301. }
  4302. }
  4303. return callback.call(source, property, value);
  4304. };
  4305. // Public: `JSON.parse`. See ES 5.1 section 15.12.2.
  4306. exports.parse = function (source, callback) {
  4307. var result, value;
  4308. Index = 0;
  4309. Source = "" + source;
  4310. result = get(lex());
  4311. // If a JSON string contains multiple tokens, it is invalid.
  4312. if (lex() != "$") {
  4313. abort();
  4314. }
  4315. // Reset the parser state.
  4316. Index = Source = null;
  4317. return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
  4318. };
  4319. }
  4320. }
  4321. exports["runInContext"] = runInContext;
  4322. return exports;
  4323. }
  4324. if (freeExports && !isLoader) {
  4325. // Export for CommonJS environments.
  4326. runInContext(root, freeExports);
  4327. } else {
  4328. // Export for web browsers and JavaScript engines.
  4329. var nativeJSON = root.JSON,
  4330. previousJSON = root["JSON3"],
  4331. isRestored = false;
  4332. var JSON3 = runInContext(root, (root["JSON3"] = {
  4333. // Public: Restores the original value of the global `JSON` object and
  4334. // returns a reference to the `JSON3` object.
  4335. "noConflict": function () {
  4336. if (!isRestored) {
  4337. isRestored = true;
  4338. root.JSON = nativeJSON;
  4339. root["JSON3"] = previousJSON;
  4340. nativeJSON = previousJSON = null;
  4341. }
  4342. return JSON3;
  4343. }
  4344. }));
  4345. root.JSON = {
  4346. "parse": JSON3.parse,
  4347. "stringify": JSON3.stringify
  4348. };
  4349. }
  4350. // Export for asynchronous module loaders.
  4351. if (isLoader) {
  4352. define(function () {
  4353. return JSON3;
  4354. });
  4355. }
  4356. }).call(this);
  4357. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4358. },{}],58:[function(require,module,exports){
  4359. /**
  4360. * Helpers.
  4361. */
  4362. var s = 1000
  4363. var m = s * 60
  4364. var h = m * 60
  4365. var d = h * 24
  4366. var y = d * 365.25
  4367. /**
  4368. * Parse or format the given `val`.
  4369. *
  4370. * Options:
  4371. *
  4372. * - `long` verbose formatting [false]
  4373. *
  4374. * @param {String|Number} val
  4375. * @param {Object} options
  4376. * @throws {Error} throw an error if val is not a non-empty string or a number
  4377. * @return {String|Number}
  4378. * @api public
  4379. */
  4380. module.exports = function (val, options) {
  4381. options = options || {}
  4382. var type = typeof val
  4383. if (type === 'string' && val.length > 0) {
  4384. return parse(val)
  4385. } else if (type === 'number' && isNaN(val) === false) {
  4386. return options.long ?
  4387. fmtLong(val) :
  4388. fmtShort(val)
  4389. }
  4390. throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val))
  4391. }
  4392. /**
  4393. * Parse the given `str` and return milliseconds.
  4394. *
  4395. * @param {String} str
  4396. * @return {Number}
  4397. * @api private
  4398. */
  4399. function parse(str) {
  4400. str = String(str)
  4401. if (str.length > 10000) {
  4402. return
  4403. }
  4404. var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str)
  4405. if (!match) {
  4406. return
  4407. }
  4408. var n = parseFloat(match[1])
  4409. var type = (match[2] || 'ms').toLowerCase()
  4410. switch (type) {
  4411. case 'years':
  4412. case 'year':
  4413. case 'yrs':
  4414. case 'yr':
  4415. case 'y':
  4416. return n * y
  4417. case 'days':
  4418. case 'day':
  4419. case 'd':
  4420. return n * d
  4421. case 'hours':
  4422. case 'hour':
  4423. case 'hrs':
  4424. case 'hr':
  4425. case 'h':
  4426. return n * h
  4427. case 'minutes':
  4428. case 'minute':
  4429. case 'mins':
  4430. case 'min':
  4431. case 'm':
  4432. return n * m
  4433. case 'seconds':
  4434. case 'second':
  4435. case 'secs':
  4436. case 'sec':
  4437. case 's':
  4438. return n * s
  4439. case 'milliseconds':
  4440. case 'millisecond':
  4441. case 'msecs':
  4442. case 'msec':
  4443. case 'ms':
  4444. return n
  4445. default:
  4446. return undefined
  4447. }
  4448. }
  4449. /**
  4450. * Short format for `ms`.
  4451. *
  4452. * @param {Number} ms
  4453. * @return {String}
  4454. * @api private
  4455. */
  4456. function fmtShort(ms) {
  4457. if (ms >= d) {
  4458. return Math.round(ms / d) + 'd'
  4459. }
  4460. if (ms >= h) {
  4461. return Math.round(ms / h) + 'h'
  4462. }
  4463. if (ms >= m) {
  4464. return Math.round(ms / m) + 'm'
  4465. }
  4466. if (ms >= s) {
  4467. return Math.round(ms / s) + 's'
  4468. }
  4469. return ms + 'ms'
  4470. }
  4471. /**
  4472. * Long format for `ms`.
  4473. *
  4474. * @param {Number} ms
  4475. * @return {String}
  4476. * @api private
  4477. */
  4478. function fmtLong(ms) {
  4479. return plural(ms, d, 'day') ||
  4480. plural(ms, h, 'hour') ||
  4481. plural(ms, m, 'minute') ||
  4482. plural(ms, s, 'second') ||
  4483. ms + ' ms'
  4484. }
  4485. /**
  4486. * Pluralization helper.
  4487. */
  4488. function plural(ms, n, name) {
  4489. if (ms < n) {
  4490. return
  4491. }
  4492. if (ms < n * 1.5) {
  4493. return Math.floor(ms / n) + ' ' + name
  4494. }
  4495. return Math.ceil(ms / n) + ' ' + name + 's'
  4496. }
  4497. },{}],59:[function(require,module,exports){
  4498. 'use strict';
  4499. var has = Object.prototype.hasOwnProperty;
  4500. /**
  4501. * Simple query string parser.
  4502. *
  4503. * @param {String} query The query string that needs to be parsed.
  4504. * @returns {Object}
  4505. * @api public
  4506. */
  4507. function querystring(query) {
  4508. var parser = /([^=?&]+)=?([^&]*)/g
  4509. , result = {}
  4510. , part;
  4511. //
  4512. // Little nifty parsing hack, leverage the fact that RegExp.exec increments
  4513. // the lastIndex property so we can continue executing this loop until we've
  4514. // parsed all results.
  4515. //
  4516. for (;
  4517. part = parser.exec(query);
  4518. result[decodeURIComponent(part[1])] = decodeURIComponent(part[2])
  4519. );
  4520. return result;
  4521. }
  4522. /**
  4523. * Transform a query string to an object.
  4524. *
  4525. * @param {Object} obj Object that should be transformed.
  4526. * @param {String} prefix Optional prefix.
  4527. * @returns {String}
  4528. * @api public
  4529. */
  4530. function querystringify(obj, prefix) {
  4531. prefix = prefix || '';
  4532. var pairs = [];
  4533. //
  4534. // Optionally prefix with a '?' if needed
  4535. //
  4536. if ('string' !== typeof prefix) prefix = '?';
  4537. for (var key in obj) {
  4538. if (has.call(obj, key)) {
  4539. pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key]));
  4540. }
  4541. }
  4542. return pairs.length ? prefix + pairs.join('&') : '';
  4543. }
  4544. //
  4545. // Expose the module.
  4546. //
  4547. exports.stringify = querystringify;
  4548. exports.parse = querystring;
  4549. },{}],60:[function(require,module,exports){
  4550. 'use strict';
  4551. /**
  4552. * Check if we're required to add a port number.
  4553. *
  4554. * @see https://url.spec.whatwg.org/#default-port
  4555. * @param {Number|String} port Port number we need to check
  4556. * @param {String} protocol Protocol we need to check against.
  4557. * @returns {Boolean} Is it a default port for the given protocol
  4558. * @api private
  4559. */
  4560. module.exports = function required(port, protocol) {
  4561. protocol = protocol.split(':')[0];
  4562. port = +port;
  4563. if (!port) return false;
  4564. switch (protocol) {
  4565. case 'http':
  4566. case 'ws':
  4567. return port !== 80;
  4568. case 'https':
  4569. case 'wss':
  4570. return port !== 443;
  4571. case 'ftp':
  4572. return port !== 21;
  4573. case 'gopher':
  4574. return port !== 70;
  4575. case 'file':
  4576. return false;
  4577. }
  4578. return port !== 0;
  4579. };
  4580. },{}],61:[function(require,module,exports){
  4581. 'use strict';
  4582. var required = require('requires-port')
  4583. , lolcation = require('./lolcation')
  4584. , qs = require('querystringify')
  4585. , protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i;
  4586. /**
  4587. * These are the parse rules for the URL parser, it informs the parser
  4588. * about:
  4589. *
  4590. * 0. The char it Needs to parse, if it's a string it should be done using
  4591. * indexOf, RegExp using exec and NaN means set as current value.
  4592. * 1. The property we should set when parsing this value.
  4593. * 2. Indication if it's backwards or forward parsing, when set as number it's
  4594. * the value of extra chars that should be split off.
  4595. * 3. Inherit from location if non existing in the parser.
  4596. * 4. `toLowerCase` the resulting value.
  4597. */
  4598. var rules = [
  4599. ['#', 'hash'], // Extract from the back.
  4600. ['?', 'query'], // Extract from the back.
  4601. ['/', 'pathname'], // Extract from the back.
  4602. ['@', 'auth', 1], // Extract from the front.
  4603. [NaN, 'host', undefined, 1, 1], // Set left over value.
  4604. [/:(\d+)$/, 'port', undefined, 1], // RegExp the back.
  4605. [NaN, 'hostname', undefined, 1, 1] // Set left over.
  4606. ];
  4607. /**
  4608. * @typedef ProtocolExtract
  4609. * @type Object
  4610. * @property {String} protocol Protocol matched in the URL, in lowercase.
  4611. * @property {Boolean} slashes `true` if protocol is followed by "//", else `false`.
  4612. * @property {String} rest Rest of the URL that is not part of the protocol.
  4613. */
  4614. /**
  4615. * Extract protocol information from a URL with/without double slash ("//").
  4616. *
  4617. * @param {String} address URL we want to extract from.
  4618. * @return {ProtocolExtract} Extracted information.
  4619. * @api private
  4620. */
  4621. function extractProtocol(address) {
  4622. var match = protocolre.exec(address);
  4623. return {
  4624. protocol: match[1] ? match[1].toLowerCase() : '',
  4625. slashes: !!match[2],
  4626. rest: match[3]
  4627. };
  4628. }
  4629. /**
  4630. * Resolve a relative URL pathname against a base URL pathname.
  4631. *
  4632. * @param {String} relative Pathname of the relative URL.
  4633. * @param {String} base Pathname of the base URL.
  4634. * @return {String} Resolved pathname.
  4635. * @api private
  4636. */
  4637. function resolve(relative, base) {
  4638. var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
  4639. , i = path.length
  4640. , last = path[i - 1]
  4641. , unshift = false
  4642. , up = 0;
  4643. while (i--) {
  4644. if (path[i] === '.') {
  4645. path.splice(i, 1);
  4646. } else if (path[i] === '..') {
  4647. path.splice(i, 1);
  4648. up++;
  4649. } else if (up) {
  4650. if (i === 0) unshift = true;
  4651. path.splice(i, 1);
  4652. up--;
  4653. }
  4654. }
  4655. if (unshift) path.unshift('');
  4656. if (last === '.' || last === '..') path.push('');
  4657. return path.join('/');
  4658. }
  4659. /**
  4660. * The actual URL instance. Instead of returning an object we've opted-in to
  4661. * create an actual constructor as it's much more memory efficient and
  4662. * faster and it pleases my OCD.
  4663. *
  4664. * @constructor
  4665. * @param {String} address URL we want to parse.
  4666. * @param {Object|String} location Location defaults for relative paths.
  4667. * @param {Boolean|Function} parser Parser for the query string.
  4668. * @api public
  4669. */
  4670. function URL(address, location, parser) {
  4671. if (!(this instanceof URL)) {
  4672. return new URL(address, location, parser);
  4673. }
  4674. var relative, extracted, parse, instruction, index, key
  4675. , instructions = rules.slice()
  4676. , type = typeof location
  4677. , url = this
  4678. , i = 0;
  4679. //
  4680. // The following if statements allows this module two have compatibility with
  4681. // 2 different API:
  4682. //
  4683. // 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments
  4684. // where the boolean indicates that the query string should also be parsed.
  4685. //
  4686. // 2. The `URL` interface of the browser which accepts a URL, object as
  4687. // arguments. The supplied object will be used as default values / fall-back
  4688. // for relative paths.
  4689. //
  4690. if ('object' !== type && 'string' !== type) {
  4691. parser = location;
  4692. location = null;
  4693. }
  4694. if (parser && 'function' !== typeof parser) parser = qs.parse;
  4695. location = lolcation(location);
  4696. //
  4697. // Extract protocol information before running the instructions.
  4698. //
  4699. extracted = extractProtocol(address || '');
  4700. relative = !extracted.protocol && !extracted.slashes;
  4701. url.slashes = extracted.slashes || relative && location.slashes;
  4702. url.protocol = extracted.protocol || location.protocol || '';
  4703. address = extracted.rest;
  4704. //
  4705. // When the authority component is absent the URL starts with a path
  4706. // component.
  4707. //
  4708. if (!extracted.slashes) instructions[2] = [/(.*)/, 'pathname'];
  4709. for (; i < instructions.length; i++) {
  4710. instruction = instructions[i];
  4711. parse = instruction[0];
  4712. key = instruction[1];
  4713. if (parse !== parse) {
  4714. url[key] = address;
  4715. } else if ('string' === typeof parse) {
  4716. if (~(index = address.indexOf(parse))) {
  4717. if ('number' === typeof instruction[2]) {
  4718. url[key] = address.slice(0, index);
  4719. address = address.slice(index + instruction[2]);
  4720. } else {
  4721. url[key] = address.slice(index);
  4722. address = address.slice(0, index);
  4723. }
  4724. }
  4725. } else if (index = parse.exec(address)) {
  4726. url[key] = index[1];
  4727. address = address.slice(0, index.index);
  4728. }
  4729. url[key] = url[key] || (
  4730. relative && instruction[3] ? location[key] || '' : ''
  4731. );
  4732. //
  4733. // Hostname, host and protocol should be lowercased so they can be used to
  4734. // create a proper `origin`.
  4735. //
  4736. if (instruction[4]) url[key] = url[key].toLowerCase();
  4737. }
  4738. //
  4739. // Also parse the supplied query string in to an object. If we're supplied
  4740. // with a custom parser as function use that instead of the default build-in
  4741. // parser.
  4742. //
  4743. if (parser) url.query = parser(url.query);
  4744. //
  4745. // If the URL is relative, resolve the pathname against the base URL.
  4746. //
  4747. if (
  4748. relative
  4749. && location.slashes
  4750. && url.pathname.charAt(0) !== '/'
  4751. && (url.pathname !== '' || location.pathname !== '')
  4752. ) {
  4753. url.pathname = resolve(url.pathname, location.pathname);
  4754. }
  4755. //
  4756. // We should not add port numbers if they are already the default port number
  4757. // for a given protocol. As the host also contains the port number we're going
  4758. // override it with the hostname which contains no port number.
  4759. //
  4760. if (!required(url.port, url.protocol)) {
  4761. url.host = url.hostname;
  4762. url.port = '';
  4763. }
  4764. //
  4765. // Parse down the `auth` for the username and password.
  4766. //
  4767. url.username = url.password = '';
  4768. if (url.auth) {
  4769. instruction = url.auth.split(':');
  4770. url.username = instruction[0] || '';
  4771. url.password = instruction[1] || '';
  4772. }
  4773. url.origin = url.protocol && url.host && url.protocol !== 'file:'
  4774. ? url.protocol +'//'+ url.host
  4775. : 'null';
  4776. //
  4777. // The href is just the compiled result.
  4778. //
  4779. url.href = url.toString();
  4780. }
  4781. /**
  4782. * This is convenience method for changing properties in the URL instance to
  4783. * insure that they all propagate correctly.
  4784. *
  4785. * @param {String} part Property we need to adjust.
  4786. * @param {Mixed} value The newly assigned value.
  4787. * @param {Boolean|Function} fn When setting the query, it will be the function
  4788. * used to parse the query.
  4789. * When setting the protocol, double slash will be
  4790. * removed from the final url if it is true.
  4791. * @returns {URL}
  4792. * @api public
  4793. */
  4794. URL.prototype.set = function set(part, value, fn) {
  4795. var url = this;
  4796. switch (part) {
  4797. case 'query':
  4798. if ('string' === typeof value && value.length) {
  4799. value = (fn || qs.parse)(value);
  4800. }
  4801. url[part] = value;
  4802. break;
  4803. case 'port':
  4804. url[part] = value;
  4805. if (!required(value, url.protocol)) {
  4806. url.host = url.hostname;
  4807. url[part] = '';
  4808. } else if (value) {
  4809. url.host = url.hostname +':'+ value;
  4810. }
  4811. break;
  4812. case 'hostname':
  4813. url[part] = value;
  4814. if (url.port) value += ':'+ url.port;
  4815. url.host = value;
  4816. break;
  4817. case 'host':
  4818. url[part] = value;
  4819. if (/:\d+$/.test(value)) {
  4820. value = value.split(':');
  4821. url.port = value.pop();
  4822. url.hostname = value.join(':');
  4823. } else {
  4824. url.hostname = value;
  4825. url.port = '';
  4826. }
  4827. break;
  4828. case 'protocol':
  4829. url.protocol = value.toLowerCase();
  4830. url.slashes = !fn;
  4831. break;
  4832. case 'pathname':
  4833. url.pathname = value.length && value.charAt(0) !== '/' ? '/' + value : value;
  4834. break;
  4835. default:
  4836. url[part] = value;
  4837. }
  4838. for (var i = 0; i < rules.length; i++) {
  4839. var ins = rules[i];
  4840. if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
  4841. }
  4842. url.origin = url.protocol && url.host && url.protocol !== 'file:'
  4843. ? url.protocol +'//'+ url.host
  4844. : 'null';
  4845. url.href = url.toString();
  4846. return url;
  4847. };
  4848. /**
  4849. * Transform the properties back in to a valid and full URL string.
  4850. *
  4851. * @param {Function} stringify Optional query stringify function.
  4852. * @returns {String}
  4853. * @api public
  4854. */
  4855. URL.prototype.toString = function toString(stringify) {
  4856. if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify;
  4857. var query
  4858. , url = this
  4859. , protocol = url.protocol;
  4860. if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
  4861. var result = protocol + (url.slashes ? '//' : '');
  4862. if (url.username) {
  4863. result += url.username;
  4864. if (url.password) result += ':'+ url.password;
  4865. result += '@';
  4866. }
  4867. result += url.host + url.pathname;
  4868. query = 'object' === typeof url.query ? stringify(url.query) : url.query;
  4869. if (query) result += '?' !== query.charAt(0) ? '?'+ query : query;
  4870. if (url.hash) result += url.hash;
  4871. return result;
  4872. };
  4873. //
  4874. // Expose the URL parser and some additional properties that might be useful for
  4875. // others or testing.
  4876. //
  4877. URL.extractProtocol = extractProtocol;
  4878. URL.location = lolcation;
  4879. URL.qs = qs;
  4880. module.exports = URL;
  4881. },{"./lolcation":62,"querystringify":59,"requires-port":60}],62:[function(require,module,exports){
  4882. (function (global){
  4883. 'use strict';
  4884. var slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//;
  4885. /**
  4886. * These properties should not be copied or inherited from. This is only needed
  4887. * for all non blob URL's as a blob URL does not include a hash, only the
  4888. * origin.
  4889. *
  4890. * @type {Object}
  4891. * @private
  4892. */
  4893. var ignore = { hash: 1, query: 1 }
  4894. , URL;
  4895. /**
  4896. * The location object differs when your code is loaded through a normal page,
  4897. * Worker or through a worker using a blob. And with the blobble begins the
  4898. * trouble as the location object will contain the URL of the blob, not the
  4899. * location of the page where our code is loaded in. The actual origin is
  4900. * encoded in the `pathname` so we can thankfully generate a good "default"
  4901. * location from it so we can generate proper relative URL's again.
  4902. *
  4903. * @param {Object|String} loc Optional default location object.
  4904. * @returns {Object} lolcation object.
  4905. * @api public
  4906. */
  4907. module.exports = function lolcation(loc) {
  4908. loc = loc || global.location || {};
  4909. URL = URL || require('./');
  4910. var finaldestination = {}
  4911. , type = typeof loc
  4912. , key;
  4913. if ('blob:' === loc.protocol) {
  4914. finaldestination = new URL(unescape(loc.pathname), {});
  4915. } else if ('string' === type) {
  4916. finaldestination = new URL(loc, {});
  4917. for (key in ignore) delete finaldestination[key];
  4918. } else if ('object' === type) {
  4919. for (key in loc) {
  4920. if (key in ignore) continue;
  4921. finaldestination[key] = loc[key];
  4922. }
  4923. if (finaldestination.slashes === undefined) {
  4924. finaldestination.slashes = slashes.test(loc.href);
  4925. }
  4926. }
  4927. return finaldestination;
  4928. };
  4929. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4930. },{"./":61}]},{},[1])(1)
  4931. });
  4932. //# sourceMappingURL=sockjs.js.map