sockjs-0.3.4.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
  1. /* SockJS client, version 0.3.4, http://sockjs.org, MIT License
  2. Copyright (c) 2011-2012 VMware, Inc.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. // JSON2 by Douglas Crockford (minified).
  20. var JSON;JSON||(JSON={}),function(){function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c<f;c+=1)h[c]=str(c,i)||"null";e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g;return e}if(rep&&typeof rep=="object"){f=rep.length;for(c=0;c<f;c+=1)typeof rep[c]=="string"&&(d=rep[c],e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e))}else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g;return e}}function quote(a){escapable.lastIndex=0;return escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function f(a){return a<10?"0"+a:a}"use strict",typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(a){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON.stringify!="function"&&(JSON.stringify=function(a,b,c){var d;gap="",indent="";if(typeof c=="number")for(d=0;d<c;d+=1)indent+=" ";else typeof c=="string"&&(indent=c);rep=b;if(!b||typeof b=="function"||typeof b=="object"&&typeof b.length=="number")return str("",{"":a});throw new Error("JSON.stringify")}),typeof JSON.parse!="function"&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&typeof e=="object")for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),d!==undefined?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver=="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")})}()
  21. // [*] Including lib/index.js
  22. // Public object
  23. SockJS = (function(){
  24. var _document = document;
  25. var _window = window;
  26. var utils = {};
  27. // [*] Including lib/reventtarget.js
  28. /*
  29. * ***** BEGIN LICENSE BLOCK *****
  30. * Copyright (c) 2011-2012 VMware, Inc.
  31. *
  32. * For the license see COPYING.
  33. * ***** END LICENSE BLOCK *****
  34. */
  35. /* Simplified implementation of DOM2 EventTarget.
  36. * http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget
  37. */
  38. var REventTarget = function() {};
  39. REventTarget.prototype.addEventListener = function (eventType, listener) {
  40. if(!this._listeners) {
  41. this._listeners = {};
  42. }
  43. if(!(eventType in this._listeners)) {
  44. this._listeners[eventType] = [];
  45. }
  46. var arr = this._listeners[eventType];
  47. if(utils.arrIndexOf(arr, listener) === -1) {
  48. arr.push(listener);
  49. }
  50. return;
  51. };
  52. REventTarget.prototype.removeEventListener = function (eventType, listener) {
  53. if(!(this._listeners && (eventType in this._listeners))) {
  54. return;
  55. }
  56. var arr = this._listeners[eventType];
  57. var idx = utils.arrIndexOf(arr, listener);
  58. if (idx !== -1) {
  59. if(arr.length > 1) {
  60. this._listeners[eventType] = arr.slice(0, idx).concat( arr.slice(idx+1) );
  61. } else {
  62. delete this._listeners[eventType];
  63. }
  64. return;
  65. }
  66. return;
  67. };
  68. REventTarget.prototype.dispatchEvent = function (event) {
  69. var t = event.type;
  70. var args = Array.prototype.slice.call(arguments, 0);
  71. if (this['on'+t]) {
  72. this['on'+t].apply(this, args);
  73. }
  74. if (this._listeners && t in this._listeners) {
  75. for(var i=0; i < this._listeners[t].length; i++) {
  76. this._listeners[t][i].apply(this, args);
  77. }
  78. }
  79. };
  80. // [*] End of lib/reventtarget.js
  81. // [*] Including lib/simpleevent.js
  82. /*
  83. * ***** BEGIN LICENSE BLOCK *****
  84. * Copyright (c) 2011-2012 VMware, Inc.
  85. *
  86. * For the license see COPYING.
  87. * ***** END LICENSE BLOCK *****
  88. */
  89. var SimpleEvent = function(type, obj) {
  90. this.type = type;
  91. if (typeof obj !== 'undefined') {
  92. for(var k in obj) {
  93. if (!obj.hasOwnProperty(k)) continue;
  94. this[k] = obj[k];
  95. }
  96. }
  97. };
  98. SimpleEvent.prototype.toString = function() {
  99. var r = [];
  100. for(var k in this) {
  101. if (!this.hasOwnProperty(k)) continue;
  102. var v = this[k];
  103. if (typeof v === 'function') v = '[function]';
  104. r.push(k + '=' + v);
  105. }
  106. return 'SimpleEvent(' + r.join(', ') + ')';
  107. };
  108. // [*] End of lib/simpleevent.js
  109. // [*] Including lib/eventemitter.js
  110. /*
  111. * ***** BEGIN LICENSE BLOCK *****
  112. * Copyright (c) 2011-2012 VMware, Inc.
  113. *
  114. * For the license see COPYING.
  115. * ***** END LICENSE BLOCK *****
  116. */
  117. var EventEmitter = function(events) {
  118. var that = this;
  119. that._events = events || [];
  120. that._listeners = {};
  121. };
  122. EventEmitter.prototype.emit = function(type) {
  123. var that = this;
  124. that._verifyType(type);
  125. if (that._nuked) return;
  126. var args = Array.prototype.slice.call(arguments, 1);
  127. if (that['on'+type]) {
  128. that['on'+type].apply(that, args);
  129. }
  130. if (type in that._listeners) {
  131. for(var i = 0; i < that._listeners[type].length; i++) {
  132. that._listeners[type][i].apply(that, args);
  133. }
  134. }
  135. };
  136. EventEmitter.prototype.on = function(type, callback) {
  137. var that = this;
  138. that._verifyType(type);
  139. if (that._nuked) return;
  140. if (!(type in that._listeners)) {
  141. that._listeners[type] = [];
  142. }
  143. that._listeners[type].push(callback);
  144. };
  145. EventEmitter.prototype._verifyType = function(type) {
  146. var that = this;
  147. if (utils.arrIndexOf(that._events, type) === -1) {
  148. utils.log('Event ' + JSON.stringify(type) +
  149. ' not listed ' + JSON.stringify(that._events) +
  150. ' in ' + that);
  151. }
  152. };
  153. EventEmitter.prototype.nuke = function() {
  154. var that = this;
  155. that._nuked = true;
  156. for(var i=0; i<that._events.length; i++) {
  157. delete that[that._events[i]];
  158. }
  159. that._listeners = {};
  160. };
  161. // [*] End of lib/eventemitter.js
  162. // [*] Including lib/utils.js
  163. /*
  164. * ***** BEGIN LICENSE BLOCK *****
  165. * Copyright (c) 2011-2012 VMware, Inc.
  166. *
  167. * For the license see COPYING.
  168. * ***** END LICENSE BLOCK *****
  169. */
  170. var random_string_chars = 'abcdefghijklmnopqrstuvwxyz0123456789_';
  171. utils.random_string = function(length, max) {
  172. max = max || random_string_chars.length;
  173. var i, ret = [];
  174. for(i=0; i < length; i++) {
  175. ret.push( random_string_chars.substr(Math.floor(Math.random() * max),1) );
  176. }
  177. return ret.join('');
  178. };
  179. utils.random_number = function(max) {
  180. return Math.floor(Math.random() * max);
  181. };
  182. utils.random_number_string = function(max) {
  183. var t = (''+(max - 1)).length;
  184. var p = Array(t+1).join('0');
  185. return (p + utils.random_number(max)).slice(-t);
  186. };
  187. // Assuming that url looks like: http://asdasd:111/asd
  188. utils.getOrigin = function(url) {
  189. url += '/';
  190. var parts = url.split('/').slice(0, 3);
  191. return parts.join('/');
  192. };
  193. utils.isSameOriginUrl = function(url_a, url_b) {
  194. // location.origin would do, but it's not always available.
  195. if (!url_b) url_b = _window.location.href;
  196. return (url_a.split('/').slice(0,3).join('/')
  197. ===
  198. url_b.split('/').slice(0,3).join('/'));
  199. };
  200. utils.getParentDomain = function(url) {
  201. // ipv4 ip address
  202. if (/^[0-9.]*$/.test(url)) return url;
  203. // ipv6 ip address
  204. if (/^\[/.test(url)) return url;
  205. // no dots
  206. if (!(/[.]/.test(url))) return url;
  207. var parts = url.split('.').slice(1);
  208. return parts.join('.');
  209. };
  210. utils.objectExtend = function(dst, src) {
  211. for(var k in src) {
  212. if (src.hasOwnProperty(k)) {
  213. dst[k] = src[k];
  214. }
  215. }
  216. return dst;
  217. };
  218. var WPrefix = '_jp';
  219. utils.polluteGlobalNamespace = function() {
  220. if (!(WPrefix in _window)) {
  221. _window[WPrefix] = {};
  222. }
  223. };
  224. utils.closeFrame = function (code, reason) {
  225. return 'c'+JSON.stringify([code, reason]);
  226. };
  227. utils.userSetCode = function (code) {
  228. return code === 1000 || (code >= 3000 && code <= 4999);
  229. };
  230. // See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/
  231. // and RFC 2988.
  232. utils.countRTO = function (rtt) {
  233. var rto;
  234. if (rtt > 100) {
  235. rto = 3 * rtt; // rto > 300msec
  236. } else {
  237. rto = rtt + 200; // 200msec < rto <= 300msec
  238. }
  239. return rto;
  240. }
  241. utils.log = function() {
  242. if (_window.console && console.log && console.log.apply) {
  243. console.log.apply(console, arguments);
  244. }
  245. };
  246. utils.bind = function(fun, that) {
  247. if (fun.bind) {
  248. return fun.bind(that);
  249. } else {
  250. return function() {
  251. return fun.apply(that, arguments);
  252. };
  253. }
  254. };
  255. utils.flatUrl = function(url) {
  256. return url.indexOf('?') === -1 && url.indexOf('#') === -1;
  257. };
  258. utils.amendUrl = function(url) {
  259. var dl = _document.location;
  260. if (!url) {
  261. throw new Error('Wrong url for SockJS');
  262. }
  263. if (!utils.flatUrl(url)) {
  264. throw new Error('Only basic urls are supported in SockJS');
  265. }
  266. // '//abc' --> 'http://abc'
  267. if (url.indexOf('//') === 0) {
  268. url = dl.protocol + url;
  269. }
  270. // '/abc' --> 'http://localhost:80/abc'
  271. if (url.indexOf('/') === 0) {
  272. url = dl.protocol + '//' + dl.host + url;
  273. }
  274. // strip trailing slashes
  275. url = url.replace(/[/]+$/,'');
  276. return url;
  277. };
  278. // IE doesn't support [].indexOf.
  279. utils.arrIndexOf = function(arr, obj){
  280. for(var i=0; i < arr.length; i++){
  281. if(arr[i] === obj){
  282. return i;
  283. }
  284. }
  285. return -1;
  286. };
  287. utils.arrSkip = function(arr, obj) {
  288. var idx = utils.arrIndexOf(arr, obj);
  289. if (idx === -1) {
  290. return arr.slice();
  291. } else {
  292. var dst = arr.slice(0, idx);
  293. return dst.concat(arr.slice(idx+1));
  294. }
  295. };
  296. // Via: https://gist.github.com/1133122/2121c601c5549155483f50be3da5305e83b8c5df
  297. utils.isArray = Array.isArray || function(value) {
  298. return {}.toString.call(value).indexOf('Array') >= 0
  299. };
  300. utils.delay = function(t, fun) {
  301. if(typeof t === 'function') {
  302. fun = t;
  303. t = 0;
  304. }
  305. return setTimeout(fun, t);
  306. };
  307. // Chars worth escaping, as defined by Douglas Crockford:
  308. // https://github.com/douglascrockford/JSON-js/blob/47a9882cddeb1e8529e07af9736218075372b8ac/json2.js#L196
  309. var json_escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  310. json_lookup = {
  311. "\u0000":"\\u0000","\u0001":"\\u0001","\u0002":"\\u0002","\u0003":"\\u0003",
  312. "\u0004":"\\u0004","\u0005":"\\u0005","\u0006":"\\u0006","\u0007":"\\u0007",
  313. "\b":"\\b","\t":"\\t","\n":"\\n","\u000b":"\\u000b","\f":"\\f","\r":"\\r",
  314. "\u000e":"\\u000e","\u000f":"\\u000f","\u0010":"\\u0010","\u0011":"\\u0011",
  315. "\u0012":"\\u0012","\u0013":"\\u0013","\u0014":"\\u0014","\u0015":"\\u0015",
  316. "\u0016":"\\u0016","\u0017":"\\u0017","\u0018":"\\u0018","\u0019":"\\u0019",
  317. "\u001a":"\\u001a","\u001b":"\\u001b","\u001c":"\\u001c","\u001d":"\\u001d",
  318. "\u001e":"\\u001e","\u001f":"\\u001f","\"":"\\\"","\\":"\\\\",
  319. "\u007f":"\\u007f","\u0080":"\\u0080","\u0081":"\\u0081","\u0082":"\\u0082",
  320. "\u0083":"\\u0083","\u0084":"\\u0084","\u0085":"\\u0085","\u0086":"\\u0086",
  321. "\u0087":"\\u0087","\u0088":"\\u0088","\u0089":"\\u0089","\u008a":"\\u008a",
  322. "\u008b":"\\u008b","\u008c":"\\u008c","\u008d":"\\u008d","\u008e":"\\u008e",
  323. "\u008f":"\\u008f","\u0090":"\\u0090","\u0091":"\\u0091","\u0092":"\\u0092",
  324. "\u0093":"\\u0093","\u0094":"\\u0094","\u0095":"\\u0095","\u0096":"\\u0096",
  325. "\u0097":"\\u0097","\u0098":"\\u0098","\u0099":"\\u0099","\u009a":"\\u009a",
  326. "\u009b":"\\u009b","\u009c":"\\u009c","\u009d":"\\u009d","\u009e":"\\u009e",
  327. "\u009f":"\\u009f","\u00ad":"\\u00ad","\u0600":"\\u0600","\u0601":"\\u0601",
  328. "\u0602":"\\u0602","\u0603":"\\u0603","\u0604":"\\u0604","\u070f":"\\u070f",
  329. "\u17b4":"\\u17b4","\u17b5":"\\u17b5","\u200c":"\\u200c","\u200d":"\\u200d",
  330. "\u200e":"\\u200e","\u200f":"\\u200f","\u2028":"\\u2028","\u2029":"\\u2029",
  331. "\u202a":"\\u202a","\u202b":"\\u202b","\u202c":"\\u202c","\u202d":"\\u202d",
  332. "\u202e":"\\u202e","\u202f":"\\u202f","\u2060":"\\u2060","\u2061":"\\u2061",
  333. "\u2062":"\\u2062","\u2063":"\\u2063","\u2064":"\\u2064","\u2065":"\\u2065",
  334. "\u2066":"\\u2066","\u2067":"\\u2067","\u2068":"\\u2068","\u2069":"\\u2069",
  335. "\u206a":"\\u206a","\u206b":"\\u206b","\u206c":"\\u206c","\u206d":"\\u206d",
  336. "\u206e":"\\u206e","\u206f":"\\u206f","\ufeff":"\\ufeff","\ufff0":"\\ufff0",
  337. "\ufff1":"\\ufff1","\ufff2":"\\ufff2","\ufff3":"\\ufff3","\ufff4":"\\ufff4",
  338. "\ufff5":"\\ufff5","\ufff6":"\\ufff6","\ufff7":"\\ufff7","\ufff8":"\\ufff8",
  339. "\ufff9":"\\ufff9","\ufffa":"\\ufffa","\ufffb":"\\ufffb","\ufffc":"\\ufffc",
  340. "\ufffd":"\\ufffd","\ufffe":"\\ufffe","\uffff":"\\uffff"};
  341. // Some extra characters that Chrome gets wrong, and substitutes with
  342. // something else on the wire.
  343. var extra_escapable = /[\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,
  344. extra_lookup;
  345. // JSON Quote string. Use native implementation when possible.
  346. var JSONQuote = (JSON && JSON.stringify) || function(string) {
  347. json_escapable.lastIndex = 0;
  348. if (json_escapable.test(string)) {
  349. string = string.replace(json_escapable, function(a) {
  350. return json_lookup[a];
  351. });
  352. }
  353. return '"' + string + '"';
  354. };
  355. // This may be quite slow, so let's delay until user actually uses bad
  356. // characters.
  357. var unroll_lookup = function(escapable) {
  358. var i;
  359. var unrolled = {}
  360. var c = []
  361. for(i=0; i<65536; i++) {
  362. c.push( String.fromCharCode(i) );
  363. }
  364. escapable.lastIndex = 0;
  365. c.join('').replace(escapable, function (a) {
  366. unrolled[ a ] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  367. return '';
  368. });
  369. escapable.lastIndex = 0;
  370. return unrolled;
  371. };
  372. // Quote string, also taking care of unicode characters that browsers
  373. // often break. Especially, take care of unicode surrogates:
  374. // http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
  375. utils.quote = function(string) {
  376. var quoted = JSONQuote(string);
  377. // In most cases this should be very fast and good enough.
  378. extra_escapable.lastIndex = 0;
  379. if(!extra_escapable.test(quoted)) {
  380. return quoted;
  381. }
  382. if(!extra_lookup) extra_lookup = unroll_lookup(extra_escapable);
  383. return quoted.replace(extra_escapable, function(a) {
  384. return extra_lookup[a];
  385. });
  386. }
  387. var _all_protocols = ['websocket',
  388. 'xdr-streaming',
  389. 'xhr-streaming',
  390. 'iframe-eventsource',
  391. 'iframe-htmlfile',
  392. 'xdr-polling',
  393. 'xhr-polling',
  394. 'iframe-xhr-polling',
  395. 'jsonp-polling'];
  396. utils.probeProtocols = function() {
  397. var probed = {};
  398. for(var i=0; i<_all_protocols.length; i++) {
  399. var protocol = _all_protocols[i];
  400. // User can have a typo in protocol name.
  401. probed[protocol] = SockJS[protocol] &&
  402. SockJS[protocol].enabled();
  403. }
  404. return probed;
  405. };
  406. utils.detectProtocols = function(probed, protocols_whitelist, info) {
  407. var pe = {},
  408. protocols = [];
  409. if (!protocols_whitelist) protocols_whitelist = _all_protocols;
  410. for(var i=0; i<protocols_whitelist.length; i++) {
  411. var protocol = protocols_whitelist[i];
  412. pe[protocol] = probed[protocol];
  413. }
  414. var maybe_push = function(protos) {
  415. var proto = protos.shift();
  416. if (pe[proto]) {
  417. protocols.push(proto);
  418. } else {
  419. if (protos.length > 0) {
  420. maybe_push(protos);
  421. }
  422. }
  423. }
  424. // 1. Websocket
  425. if (info.websocket !== false) {
  426. maybe_push(['websocket']);
  427. }
  428. // 2. Streaming
  429. if (pe['xhr-streaming'] && !info.null_origin) {
  430. protocols.push('xhr-streaming');
  431. } else {
  432. if (pe['xdr-streaming'] && !info.cookie_needed && !info.null_origin) {
  433. protocols.push('xdr-streaming');
  434. } else {
  435. maybe_push(['iframe-eventsource',
  436. 'iframe-htmlfile']);
  437. }
  438. }
  439. // 3. Polling
  440. if (pe['xhr-polling'] && !info.null_origin) {
  441. protocols.push('xhr-polling');
  442. } else {
  443. if (pe['xdr-polling'] && !info.cookie_needed && !info.null_origin) {
  444. protocols.push('xdr-polling');
  445. } else {
  446. maybe_push(['iframe-xhr-polling',
  447. 'jsonp-polling']);
  448. }
  449. }
  450. return protocols;
  451. }
  452. // [*] End of lib/utils.js
  453. // [*] Including lib/dom.js
  454. /*
  455. * ***** BEGIN LICENSE BLOCK *****
  456. * Copyright (c) 2011-2012 VMware, Inc.
  457. *
  458. * For the license see COPYING.
  459. * ***** END LICENSE BLOCK *****
  460. */
  461. // May be used by htmlfile jsonp and transports.
  462. var MPrefix = '_sockjs_global';
  463. utils.createHook = function() {
  464. var window_id = 'a' + utils.random_string(8);
  465. if (!(MPrefix in _window)) {
  466. var map = {};
  467. _window[MPrefix] = function(window_id) {
  468. if (!(window_id in map)) {
  469. map[window_id] = {
  470. id: window_id,
  471. del: function() {delete map[window_id];}
  472. };
  473. }
  474. return map[window_id];
  475. }
  476. }
  477. return _window[MPrefix](window_id);
  478. };
  479. utils.attachMessage = function(listener) {
  480. utils.attachEvent('message', listener);
  481. };
  482. utils.attachEvent = function(event, listener) {
  483. if (typeof _window.addEventListener !== 'undefined') {
  484. _window.addEventListener(event, listener, false);
  485. } else {
  486. // IE quirks.
  487. // According to: http://stevesouders.com/misc/test-postmessage.php
  488. // the message gets delivered only to 'document', not 'window'.
  489. _document.attachEvent("on" + event, listener);
  490. // I get 'window' for ie8.
  491. _window.attachEvent("on" + event, listener);
  492. }
  493. };
  494. utils.detachMessage = function(listener) {
  495. utils.detachEvent('message', listener);
  496. };
  497. utils.detachEvent = function(event, listener) {
  498. if (typeof _window.addEventListener !== 'undefined') {
  499. _window.removeEventListener(event, listener, false);
  500. } else {
  501. _document.detachEvent("on" + event, listener);
  502. _window.detachEvent("on" + event, listener);
  503. }
  504. };
  505. var on_unload = {};
  506. // Things registered after beforeunload are to be called immediately.
  507. var after_unload = false;
  508. var trigger_unload_callbacks = function() {
  509. for(var ref in on_unload) {
  510. on_unload[ref]();
  511. delete on_unload[ref];
  512. };
  513. };
  514. var unload_triggered = function() {
  515. if(after_unload) return;
  516. after_unload = true;
  517. trigger_unload_callbacks();
  518. };
  519. // 'unload' alone is not reliable in opera within an iframe, but we
  520. // can't use `beforeunload` as IE fires it on javascript: links.
  521. utils.attachEvent('unload', unload_triggered);
  522. utils.unload_add = function(listener) {
  523. var ref = utils.random_string(8);
  524. on_unload[ref] = listener;
  525. if (after_unload) {
  526. utils.delay(trigger_unload_callbacks);
  527. }
  528. return ref;
  529. };
  530. utils.unload_del = function(ref) {
  531. if (ref in on_unload)
  532. delete on_unload[ref];
  533. };
  534. utils.createIframe = function (iframe_url, error_callback) {
  535. var iframe = _document.createElement('iframe');
  536. var tref, unload_ref;
  537. var unattach = function() {
  538. clearTimeout(tref);
  539. // Explorer had problems with that.
  540. try {iframe.onload = null;} catch (x) {}
  541. iframe.onerror = null;
  542. };
  543. var cleanup = function() {
  544. if (iframe) {
  545. unattach();
  546. // This timeout makes chrome fire onbeforeunload event
  547. // within iframe. Without the timeout it goes straight to
  548. // onunload.
  549. setTimeout(function() {
  550. if(iframe) {
  551. iframe.parentNode.removeChild(iframe);
  552. }
  553. iframe = null;
  554. }, 0);
  555. utils.unload_del(unload_ref);
  556. }
  557. };
  558. var onerror = function(r) {
  559. if (iframe) {
  560. cleanup();
  561. error_callback(r);
  562. }
  563. };
  564. var post = function(msg, origin) {
  565. try {
  566. // When the iframe is not loaded, IE raises an exception
  567. // on 'contentWindow'.
  568. if (iframe && iframe.contentWindow) {
  569. iframe.contentWindow.postMessage(msg, origin);
  570. }
  571. } catch (x) {};
  572. };
  573. iframe.src = iframe_url;
  574. iframe.style.display = 'none';
  575. iframe.style.position = 'absolute';
  576. iframe.onerror = function(){onerror('onerror');};
  577. iframe.onload = function() {
  578. // `onload` is triggered before scripts on the iframe are
  579. // executed. Give it few seconds to actually load stuff.
  580. clearTimeout(tref);
  581. tref = setTimeout(function(){onerror('onload timeout');}, 2000);
  582. };
  583. _document.body.appendChild(iframe);
  584. tref = setTimeout(function(){onerror('timeout');}, 15000);
  585. unload_ref = utils.unload_add(cleanup);
  586. return {
  587. post: post,
  588. cleanup: cleanup,
  589. loaded: unattach
  590. };
  591. };
  592. utils.createHtmlfile = function (iframe_url, error_callback) {
  593. var doc = new ActiveXObject('htmlfile');
  594. var tref, unload_ref;
  595. var iframe;
  596. var unattach = function() {
  597. clearTimeout(tref);
  598. };
  599. var cleanup = function() {
  600. if (doc) {
  601. unattach();
  602. utils.unload_del(unload_ref);
  603. iframe.parentNode.removeChild(iframe);
  604. iframe = doc = null;
  605. CollectGarbage();
  606. }
  607. };
  608. var onerror = function(r) {
  609. if (doc) {
  610. cleanup();
  611. error_callback(r);
  612. }
  613. };
  614. var post = function(msg, origin) {
  615. try {
  616. // When the iframe is not loaded, IE raises an exception
  617. // on 'contentWindow'.
  618. if (iframe && iframe.contentWindow) {
  619. iframe.contentWindow.postMessage(msg, origin);
  620. }
  621. } catch (x) {};
  622. };
  623. doc.open();
  624. doc.write('<html><s' + 'cript>' +
  625. 'document.domain="' + document.domain + '";' +
  626. '</s' + 'cript></html>');
  627. doc.close();
  628. doc.parentWindow[WPrefix] = _window[WPrefix];
  629. var c = doc.createElement('div');
  630. doc.body.appendChild(c);
  631. iframe = doc.createElement('iframe');
  632. c.appendChild(iframe);
  633. iframe.src = iframe_url;
  634. tref = setTimeout(function(){onerror('timeout');}, 15000);
  635. unload_ref = utils.unload_add(cleanup);
  636. return {
  637. post: post,
  638. cleanup: cleanup,
  639. loaded: unattach
  640. };
  641. };
  642. // [*] End of lib/dom.js
  643. // [*] Including lib/dom2.js
  644. /*
  645. * ***** BEGIN LICENSE BLOCK *****
  646. * Copyright (c) 2011-2012 VMware, Inc.
  647. *
  648. * For the license see COPYING.
  649. * ***** END LICENSE BLOCK *****
  650. */
  651. var AbstractXHRObject = function(){};
  652. AbstractXHRObject.prototype = new EventEmitter(['chunk', 'finish']);
  653. AbstractXHRObject.prototype._start = function(method, url, payload, opts) {
  654. var that = this;
  655. try {
  656. that.xhr = new XMLHttpRequest();
  657. } catch(x) {};
  658. if (!that.xhr) {
  659. try {
  660. that.xhr = new _window.ActiveXObject('Microsoft.XMLHTTP');
  661. } catch(x) {};
  662. }
  663. if (_window.ActiveXObject || _window.XDomainRequest) {
  664. // IE8 caches even POSTs
  665. url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
  666. }
  667. // Explorer tends to keep connection open, even after the
  668. // tab gets closed: http://bugs.jquery.com/ticket/5280
  669. that.unload_ref = utils.unload_add(function(){that._cleanup(true);});
  670. try {
  671. that.xhr.open(method, url, true);
  672. } catch(e) {
  673. // IE raises an exception on wrong port.
  674. that.emit('finish', 0, '');
  675. that._cleanup();
  676. return;
  677. };
  678. if (!opts || !opts.no_credentials) {
  679. // Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
  680. // "This never affects same-site requests."
  681. that.xhr.withCredentials = 'true';
  682. }
  683. if (opts && opts.headers) {
  684. for(var key in opts.headers) {
  685. that.xhr.setRequestHeader(key, opts.headers[key]);
  686. }
  687. }
  688. that.xhr.onreadystatechange = function() {
  689. if (that.xhr) {
  690. var x = that.xhr;
  691. switch (x.readyState) {
  692. case 3:
  693. // IE doesn't like peeking into responseText or status
  694. // on Microsoft.XMLHTTP and readystate=3
  695. try {
  696. var status = x.status;
  697. var text = x.responseText;
  698. } catch (x) {};
  699. // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
  700. if (status === 1223) status = 204;
  701. // IE does return readystate == 3 for 404 answers.
  702. if (text && text.length > 0) {
  703. that.emit('chunk', status, text);
  704. }
  705. break;
  706. case 4:
  707. var status = x.status;
  708. // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
  709. if (status === 1223) status = 204;
  710. that.emit('finish', status, x.responseText);
  711. that._cleanup(false);
  712. break;
  713. }
  714. }
  715. };
  716. that.xhr.send(payload);
  717. };
  718. AbstractXHRObject.prototype._cleanup = function(abort) {
  719. var that = this;
  720. if (!that.xhr) return;
  721. utils.unload_del(that.unload_ref);
  722. // IE needs this field to be a function
  723. that.xhr.onreadystatechange = function(){};
  724. if (abort) {
  725. try {
  726. that.xhr.abort();
  727. } catch(x) {};
  728. }
  729. that.unload_ref = that.xhr = null;
  730. };
  731. AbstractXHRObject.prototype.close = function() {
  732. var that = this;
  733. that.nuke();
  734. that._cleanup(true);
  735. };
  736. var XHRCorsObject = utils.XHRCorsObject = function() {
  737. var that = this, args = arguments;
  738. utils.delay(function(){that._start.apply(that, args);});
  739. };
  740. XHRCorsObject.prototype = new AbstractXHRObject();
  741. var XHRLocalObject = utils.XHRLocalObject = function(method, url, payload) {
  742. var that = this;
  743. utils.delay(function(){
  744. that._start(method, url, payload, {
  745. no_credentials: true
  746. });
  747. });
  748. };
  749. XHRLocalObject.prototype = new AbstractXHRObject();
  750. // References:
  751. // http://ajaxian.com/archives/100-line-ajax-wrapper
  752. // http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx
  753. var XDRObject = utils.XDRObject = function(method, url, payload) {
  754. var that = this;
  755. utils.delay(function(){that._start(method, url, payload);});
  756. };
  757. XDRObject.prototype = new EventEmitter(['chunk', 'finish']);
  758. XDRObject.prototype._start = function(method, url, payload) {
  759. var that = this;
  760. var xdr = new XDomainRequest();
  761. // IE caches even POSTs
  762. url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
  763. var onerror = xdr.ontimeout = xdr.onerror = function() {
  764. that.emit('finish', 0, '');
  765. that._cleanup(false);
  766. };
  767. xdr.onprogress = function() {
  768. that.emit('chunk', 200, xdr.responseText);
  769. };
  770. xdr.onload = function() {
  771. that.emit('finish', 200, xdr.responseText);
  772. that._cleanup(false);
  773. };
  774. that.xdr = xdr;
  775. that.unload_ref = utils.unload_add(function(){that._cleanup(true);});
  776. try {
  777. // Fails with AccessDenied if port number is bogus
  778. that.xdr.open(method, url);
  779. that.xdr.send(payload);
  780. } catch(x) {
  781. onerror();
  782. }
  783. };
  784. XDRObject.prototype._cleanup = function(abort) {
  785. var that = this;
  786. if (!that.xdr) return;
  787. utils.unload_del(that.unload_ref);
  788. that.xdr.ontimeout = that.xdr.onerror = that.xdr.onprogress =
  789. that.xdr.onload = null;
  790. if (abort) {
  791. try {
  792. that.xdr.abort();
  793. } catch(x) {};
  794. }
  795. that.unload_ref = that.xdr = null;
  796. };
  797. XDRObject.prototype.close = function() {
  798. var that = this;
  799. that.nuke();
  800. that._cleanup(true);
  801. };
  802. // 1. Is natively via XHR
  803. // 2. Is natively via XDR
  804. // 3. Nope, but postMessage is there so it should work via the Iframe.
  805. // 4. Nope, sorry.
  806. utils.isXHRCorsCapable = function() {
  807. if (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()) {
  808. return 1;
  809. }
  810. // XDomainRequest doesn't work if page is served from file://
  811. if (_window.XDomainRequest && _document.domain) {
  812. return 2;
  813. }
  814. if (IframeTransport.enabled()) {
  815. return 3;
  816. }
  817. return 4;
  818. };
  819. // [*] End of lib/dom2.js
  820. // [*] Including lib/sockjs.js
  821. /*
  822. * ***** BEGIN LICENSE BLOCK *****
  823. * Copyright (c) 2011-2012 VMware, Inc.
  824. *
  825. * For the license see COPYING.
  826. * ***** END LICENSE BLOCK *****
  827. */
  828. var SockJS = function(url, dep_protocols_whitelist, options) {
  829. if (this === _window) {
  830. // makes `new` optional
  831. return new SockJS(url, dep_protocols_whitelist, options);
  832. }
  833. var that = this, protocols_whitelist;
  834. that._options = {devel: false, debug: false, protocols_whitelist: [],
  835. info: undefined, rtt: undefined};
  836. if (options) {
  837. utils.objectExtend(that._options, options);
  838. }
  839. that._base_url = utils.amendUrl(url);
  840. that._server = that._options.server || utils.random_number_string(1000);
  841. if (that._options.protocols_whitelist &&
  842. that._options.protocols_whitelist.length) {
  843. protocols_whitelist = that._options.protocols_whitelist;
  844. } else {
  845. // Deprecated API
  846. if (typeof dep_protocols_whitelist === 'string' &&
  847. dep_protocols_whitelist.length > 0) {
  848. protocols_whitelist = [dep_protocols_whitelist];
  849. } else if (utils.isArray(dep_protocols_whitelist)) {
  850. protocols_whitelist = dep_protocols_whitelist
  851. } else {
  852. protocols_whitelist = null;
  853. }
  854. if (protocols_whitelist) {
  855. that._debug('Deprecated API: Use "protocols_whitelist" option ' +
  856. 'instead of supplying protocol list as a second ' +
  857. 'parameter to SockJS constructor.');
  858. }
  859. }
  860. that._protocols = [];
  861. that.protocol = null;
  862. that.readyState = SockJS.CONNECTING;
  863. that._ir = createInfoReceiver(that._base_url);
  864. that._ir.onfinish = function(info, rtt) {
  865. that._ir = null;
  866. if (info) {
  867. if (that._options.info) {
  868. // Override if user supplies the option
  869. info = utils.objectExtend(info, that._options.info);
  870. }
  871. if (that._options.rtt) {
  872. rtt = that._options.rtt;
  873. }
  874. that._applyInfo(info, rtt, protocols_whitelist);
  875. that._didClose();
  876. } else {
  877. that._didClose(1002, 'Can\'t connect to server', true);
  878. }
  879. };
  880. };
  881. // Inheritance
  882. SockJS.prototype = new REventTarget();
  883. SockJS.version = "0.3.4";
  884. SockJS.CONNECTING = 0;
  885. SockJS.OPEN = 1;
  886. SockJS.CLOSING = 2;
  887. SockJS.CLOSED = 3;
  888. SockJS.prototype._debug = function() {
  889. if (this._options.debug)
  890. utils.log.apply(utils, arguments);
  891. };
  892. SockJS.prototype._dispatchOpen = function() {
  893. var that = this;
  894. if (that.readyState === SockJS.CONNECTING) {
  895. if (that._transport_tref) {
  896. clearTimeout(that._transport_tref);
  897. that._transport_tref = null;
  898. }
  899. that.readyState = SockJS.OPEN;
  900. that.dispatchEvent(new SimpleEvent("open"));
  901. } else {
  902. // The server might have been restarted, and lost track of our
  903. // connection.
  904. that._didClose(1006, "Server lost session");
  905. }
  906. };
  907. SockJS.prototype._dispatchMessage = function(data) {
  908. var that = this;
  909. if (that.readyState !== SockJS.OPEN)
  910. return;
  911. that.dispatchEvent(new SimpleEvent("message", {data: data}));
  912. };
  913. SockJS.prototype._dispatchHeartbeat = function(data) {
  914. var that = this;
  915. if (that.readyState !== SockJS.OPEN)
  916. return;
  917. that.dispatchEvent(new SimpleEvent('heartbeat', {}));
  918. };
  919. SockJS.prototype._didClose = function(code, reason, force) {
  920. var that = this;
  921. if (that.readyState !== SockJS.CONNECTING &&
  922. that.readyState !== SockJS.OPEN &&
  923. that.readyState !== SockJS.CLOSING)
  924. throw new Error('INVALID_STATE_ERR');
  925. if (that._ir) {
  926. that._ir.nuke();
  927. that._ir = null;
  928. }
  929. if (that._transport) {
  930. that._transport.doCleanup();
  931. that._transport = null;
  932. }
  933. var close_event = new SimpleEvent("close", {
  934. code: code,
  935. reason: reason,
  936. wasClean: utils.userSetCode(code)});
  937. if (!utils.userSetCode(code) &&
  938. that.readyState === SockJS.CONNECTING && !force) {
  939. if (that._try_next_protocol(close_event)) {
  940. return;
  941. }
  942. close_event = new SimpleEvent("close", {code: 2000,
  943. reason: "All transports failed",
  944. wasClean: false,
  945. last_event: close_event});
  946. }
  947. that.readyState = SockJS.CLOSED;
  948. utils.delay(function() {
  949. that.dispatchEvent(close_event);
  950. });
  951. };
  952. SockJS.prototype._didMessage = function(data) {
  953. var that = this;
  954. var type = data.slice(0, 1);
  955. switch(type) {
  956. case 'o':
  957. that._dispatchOpen();
  958. break;
  959. case 'a':
  960. var payload = JSON.parse(data.slice(1) || '[]');
  961. for(var i=0; i < payload.length; i++){
  962. that._dispatchMessage(payload[i]);
  963. }
  964. break;
  965. case 'm':
  966. var payload = JSON.parse(data.slice(1) || 'null');
  967. that._dispatchMessage(payload);
  968. break;
  969. case 'c':
  970. var payload = JSON.parse(data.slice(1) || '[]');
  971. that._didClose(payload[0], payload[1]);
  972. break;
  973. case 'h':
  974. that._dispatchHeartbeat();
  975. break;
  976. }
  977. };
  978. SockJS.prototype._try_next_protocol = function(close_event) {
  979. var that = this;
  980. if (that.protocol) {
  981. that._debug('Closed transport:', that.protocol, ''+close_event);
  982. that.protocol = null;
  983. }
  984. if (that._transport_tref) {
  985. clearTimeout(that._transport_tref);
  986. that._transport_tref = null;
  987. }
  988. while(1) {
  989. var protocol = that.protocol = that._protocols.shift();
  990. if (!protocol) {
  991. return false;
  992. }
  993. // Some protocols require access to `body`, what if were in
  994. // the `head`?
  995. if (SockJS[protocol] &&
  996. SockJS[protocol].need_body === true &&
  997. (!_document.body ||
  998. (typeof _document.readyState !== 'undefined'
  999. && _document.readyState !== 'complete'))) {
  1000. that._protocols.unshift(protocol);
  1001. that.protocol = 'waiting-for-load';
  1002. utils.attachEvent('load', function(){
  1003. that._try_next_protocol();
  1004. });
  1005. return true;
  1006. }
  1007. if (!SockJS[protocol] ||
  1008. !SockJS[protocol].enabled(that._options)) {
  1009. that._debug('Skipping transport:', protocol);
  1010. } else {
  1011. var roundTrips = SockJS[protocol].roundTrips || 1;
  1012. var to = ((that._options.rto || 0) * roundTrips) || 5000;
  1013. that._transport_tref = utils.delay(to, function() {
  1014. if (that.readyState === SockJS.CONNECTING) {
  1015. // I can't understand how it is possible to run
  1016. // this timer, when the state is CLOSED, but
  1017. // apparently in IE everythin is possible.
  1018. that._didClose(2007, "Transport timeouted");
  1019. }
  1020. });
  1021. var connid = utils.random_string(8);
  1022. var trans_url = that._base_url + '/' + that._server + '/' + connid;
  1023. that._debug('Opening transport:', protocol, ' url:'+trans_url,
  1024. ' RTO:'+that._options.rto);
  1025. that._transport = new SockJS[protocol](that, trans_url,
  1026. that._base_url);
  1027. return true;
  1028. }
  1029. }
  1030. };
  1031. SockJS.prototype.close = function(code, reason) {
  1032. var that = this;
  1033. if (code && !utils.userSetCode(code))
  1034. throw new Error("INVALID_ACCESS_ERR");
  1035. if(that.readyState !== SockJS.CONNECTING &&
  1036. that.readyState !== SockJS.OPEN) {
  1037. return false;
  1038. }
  1039. that.readyState = SockJS.CLOSING;
  1040. that._didClose(code || 1000, reason || "Normal closure");
  1041. return true;
  1042. };
  1043. SockJS.prototype.send = function(data) {
  1044. var that = this;
  1045. if (that.readyState === SockJS.CONNECTING)
  1046. throw new Error('INVALID_STATE_ERR');
  1047. if (that.readyState === SockJS.OPEN) {
  1048. that._transport.doSend(utils.quote('' + data));
  1049. }
  1050. return true;
  1051. };
  1052. SockJS.prototype._applyInfo = function(info, rtt, protocols_whitelist) {
  1053. var that = this;
  1054. that._options.info = info;
  1055. that._options.rtt = rtt;
  1056. that._options.rto = utils.countRTO(rtt);
  1057. that._options.info.null_origin = !_document.domain;
  1058. var probed = utils.probeProtocols();
  1059. that._protocols = utils.detectProtocols(probed, protocols_whitelist, info);
  1060. };
  1061. // [*] End of lib/sockjs.js
  1062. // [*] Including lib/trans-websocket.js
  1063. /*
  1064. * ***** BEGIN LICENSE BLOCK *****
  1065. * Copyright (c) 2011-2012 VMware, Inc.
  1066. *
  1067. * For the license see COPYING.
  1068. * ***** END LICENSE BLOCK *****
  1069. */
  1070. var WebSocketTransport = SockJS.websocket = function(ri, trans_url) {
  1071. var that = this;
  1072. var url = trans_url + '/websocket';
  1073. if (url.slice(0, 5) === 'https') {
  1074. url = 'wss' + url.slice(5);
  1075. } else {
  1076. url = 'ws' + url.slice(4);
  1077. }
  1078. that.ri = ri;
  1079. that.url = url;
  1080. var Constructor = _window.WebSocket || _window.MozWebSocket;
  1081. that.ws = new Constructor(that.url);
  1082. that.ws.onmessage = function(e) {
  1083. that.ri._didMessage(e.data);
  1084. };
  1085. // Firefox has an interesting bug. If a websocket connection is
  1086. // created after onunload, it stays alive even when user
  1087. // navigates away from the page. In such situation let's lie -
  1088. // let's not open the ws connection at all. See:
  1089. // https://github.com/sockjs/sockjs-client/issues/28
  1090. // https://bugzilla.mozilla.org/show_bug.cgi?id=696085
  1091. that.unload_ref = utils.unload_add(function(){that.ws.close()});
  1092. that.ws.onclose = function() {
  1093. that.ri._didMessage(utils.closeFrame(1006, "WebSocket connection broken"));
  1094. };
  1095. };
  1096. WebSocketTransport.prototype.doSend = function(data) {
  1097. this.ws.send('[' + data + ']');
  1098. };
  1099. WebSocketTransport.prototype.doCleanup = function() {
  1100. var that = this;
  1101. var ws = that.ws;
  1102. if (ws) {
  1103. ws.onmessage = ws.onclose = null;
  1104. ws.close();
  1105. utils.unload_del(that.unload_ref);
  1106. that.unload_ref = that.ri = that.ws = null;
  1107. }
  1108. };
  1109. WebSocketTransport.enabled = function() {
  1110. return !!(_window.WebSocket || _window.MozWebSocket);
  1111. };
  1112. // In theory, ws should require 1 round trip. But in chrome, this is
  1113. // not very stable over SSL. Most likely a ws connection requires a
  1114. // separate SSL connection, in which case 2 round trips are an
  1115. // absolute minumum.
  1116. WebSocketTransport.roundTrips = 2;
  1117. // [*] End of lib/trans-websocket.js
  1118. // [*] Including lib/trans-sender.js
  1119. /*
  1120. * ***** BEGIN LICENSE BLOCK *****
  1121. * Copyright (c) 2011-2012 VMware, Inc.
  1122. *
  1123. * For the license see COPYING.
  1124. * ***** END LICENSE BLOCK *****
  1125. */
  1126. var BufferedSender = function() {};
  1127. BufferedSender.prototype.send_constructor = function(sender) {
  1128. var that = this;
  1129. that.send_buffer = [];
  1130. that.sender = sender;
  1131. };
  1132. BufferedSender.prototype.doSend = function(message) {
  1133. var that = this;
  1134. that.send_buffer.push(message);
  1135. if (!that.send_stop) {
  1136. that.send_schedule();
  1137. }
  1138. };
  1139. // For polling transports in a situation when in the message callback,
  1140. // new message is being send. If the sending connection was started
  1141. // before receiving one, it is possible to saturate the network and
  1142. // timeout due to the lack of receiving socket. To avoid that we delay
  1143. // sending messages by some small time, in order to let receiving
  1144. // connection be started beforehand. This is only a halfmeasure and
  1145. // does not fix the big problem, but it does make the tests go more
  1146. // stable on slow networks.
  1147. BufferedSender.prototype.send_schedule_wait = function() {
  1148. var that = this;
  1149. var tref;
  1150. that.send_stop = function() {
  1151. that.send_stop = null;
  1152. clearTimeout(tref);
  1153. };
  1154. tref = utils.delay(25, function() {
  1155. that.send_stop = null;
  1156. that.send_schedule();
  1157. });
  1158. };
  1159. BufferedSender.prototype.send_schedule = function() {
  1160. var that = this;
  1161. if (that.send_buffer.length > 0) {
  1162. var payload = '[' + that.send_buffer.join(',') + ']';
  1163. that.send_stop = that.sender(that.trans_url, payload, function(success, abort_reason) {
  1164. that.send_stop = null;
  1165. if (success === false) {
  1166. that.ri._didClose(1006, 'Sending error ' + abort_reason);
  1167. } else {
  1168. that.send_schedule_wait();
  1169. }
  1170. });
  1171. that.send_buffer = [];
  1172. }
  1173. };
  1174. BufferedSender.prototype.send_destructor = function() {
  1175. var that = this;
  1176. if (that._send_stop) {
  1177. that._send_stop();
  1178. }
  1179. that._send_stop = null;
  1180. };
  1181. var jsonPGenericSender = function(url, payload, callback) {
  1182. var that = this;
  1183. if (!('_send_form' in that)) {
  1184. var form = that._send_form = _document.createElement('form');
  1185. var area = that._send_area = _document.createElement('textarea');
  1186. area.name = 'd';
  1187. form.style.display = 'none';
  1188. form.style.position = 'absolute';
  1189. form.method = 'POST';
  1190. form.enctype = 'application/x-www-form-urlencoded';
  1191. form.acceptCharset = "UTF-8";
  1192. form.appendChild(area);
  1193. _document.body.appendChild(form);
  1194. }
  1195. var form = that._send_form;
  1196. var area = that._send_area;
  1197. var id = 'a' + utils.random_string(8);
  1198. form.target = id;
  1199. form.action = url + '/jsonp_send?i=' + id;
  1200. var iframe;
  1201. try {
  1202. // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
  1203. iframe = _document.createElement('<iframe name="'+ id +'">');
  1204. } catch(x) {
  1205. iframe = _document.createElement('iframe');
  1206. iframe.name = id;
  1207. }
  1208. iframe.id = id;
  1209. form.appendChild(iframe);
  1210. iframe.style.display = 'none';
  1211. try {
  1212. area.value = payload;
  1213. } catch(e) {
  1214. utils.log('Your browser is seriously broken. Go home! ' + e.message);
  1215. }
  1216. form.submit();
  1217. var completed = function(e) {
  1218. if (!iframe.onerror) return;
  1219. iframe.onreadystatechange = iframe.onerror = iframe.onload = null;
  1220. // Opera mini doesn't like if we GC iframe
  1221. // immediately, thus this timeout.
  1222. utils.delay(500, function() {
  1223. iframe.parentNode.removeChild(iframe);
  1224. iframe = null;
  1225. });
  1226. area.value = '';
  1227. // It is not possible to detect if the iframe succeeded or
  1228. // failed to submit our form.
  1229. callback(true);
  1230. };
  1231. iframe.onerror = iframe.onload = completed;
  1232. iframe.onreadystatechange = function(e) {
  1233. if (iframe.readyState == 'complete') completed();
  1234. };
  1235. return completed;
  1236. };
  1237. var createAjaxSender = function(AjaxObject) {
  1238. return function(url, payload, callback) {
  1239. var xo = new AjaxObject('POST', url + '/xhr_send', payload);
  1240. xo.onfinish = function(status, text) {
  1241. callback(status === 200 || status === 204,
  1242. 'http status ' + status);
  1243. };
  1244. return function(abort_reason) {
  1245. callback(false, abort_reason);
  1246. };
  1247. };
  1248. };
  1249. // [*] End of lib/trans-sender.js
  1250. // [*] Including lib/trans-jsonp-receiver.js
  1251. /*
  1252. * ***** BEGIN LICENSE BLOCK *****
  1253. * Copyright (c) 2011-2012 VMware, Inc.
  1254. *
  1255. * For the license see COPYING.
  1256. * ***** END LICENSE BLOCK *****
  1257. */
  1258. // Parts derived from Socket.io:
  1259. // https://github.com/LearnBoost/socket.io/blob/0.6.17/lib/socket.io/transports/jsonp-polling.js
  1260. // and jQuery-JSONP:
  1261. // https://code.google.com/p/jquery-jsonp/source/browse/trunk/core/jquery.jsonp.js
  1262. var jsonPGenericReceiver = function(url, callback) {
  1263. var tref;
  1264. var script = _document.createElement('script');
  1265. var script2; // Opera synchronous load trick.
  1266. var close_script = function(frame) {
  1267. if (script2) {
  1268. script2.parentNode.removeChild(script2);
  1269. script2 = null;
  1270. }
  1271. if (script) {
  1272. clearTimeout(tref);
  1273. // Unfortunately, you can't really abort script loading of
  1274. // the script.
  1275. script.parentNode.removeChild(script);
  1276. script.onreadystatechange = script.onerror =
  1277. script.onload = script.onclick = null;
  1278. script = null;
  1279. callback(frame);
  1280. callback = null;
  1281. }
  1282. };
  1283. // IE9 fires 'error' event after orsc or before, in random order.
  1284. var loaded_okay = false;
  1285. var error_timer = null;
  1286. script.id = 'a' + utils.random_string(8);
  1287. script.src = url;
  1288. script.type = 'text/javascript';
  1289. script.charset = 'UTF-8';
  1290. script.onerror = function(e) {
  1291. if (!error_timer) {
  1292. // Delay firing close_script.
  1293. error_timer = setTimeout(function() {
  1294. if (!loaded_okay) {
  1295. close_script(utils.closeFrame(
  1296. 1006,
  1297. "JSONP script loaded abnormally (onerror)"));
  1298. }
  1299. }, 1000);
  1300. }
  1301. };
  1302. script.onload = function(e) {
  1303. close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onload)"));
  1304. };
  1305. script.onreadystatechange = function(e) {
  1306. if (/loaded|closed/.test(script.readyState)) {
  1307. if (script && script.htmlFor && script.onclick) {
  1308. loaded_okay = true;
  1309. try {
  1310. // In IE, actually execute the script.
  1311. script.onclick();
  1312. } catch (x) {}
  1313. }
  1314. if (script) {
  1315. close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onreadystatechange)"));
  1316. }
  1317. }
  1318. };
  1319. // IE: event/htmlFor/onclick trick.
  1320. // One can't rely on proper order for onreadystatechange. In order to
  1321. // make sure, set a 'htmlFor' and 'event' properties, so that
  1322. // script code will be installed as 'onclick' handler for the
  1323. // script object. Later, onreadystatechange, manually execute this
  1324. // code. FF and Chrome doesn't work with 'event' and 'htmlFor'
  1325. // set. For reference see:
  1326. // http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
  1327. // Also, read on that about script ordering:
  1328. // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
  1329. if (typeof script.async === 'undefined' && _document.attachEvent) {
  1330. // According to mozilla docs, in recent browsers script.async defaults
  1331. // to 'true', so we may use it to detect a good browser:
  1332. // https://developer.mozilla.org/en/HTML/Element/script
  1333. if (!/opera/i.test(navigator.userAgent)) {
  1334. // Naively assume we're in IE
  1335. try {
  1336. script.htmlFor = script.id;
  1337. script.event = "onclick";
  1338. } catch (x) {}
  1339. script.async = true;
  1340. } else {
  1341. // Opera, second sync script hack
  1342. script2 = _document.createElement('script');
  1343. script2.text = "try{var a = document.getElementById('"+script.id+"'); if(a)a.onerror();}catch(x){};";
  1344. script.async = script2.async = false;
  1345. }
  1346. }
  1347. if (typeof script.async !== 'undefined') {
  1348. script.async = true;
  1349. }
  1350. // Fallback mostly for Konqueror - stupid timer, 35 seconds shall be plenty.
  1351. tref = setTimeout(function() {
  1352. close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (timeout)"));
  1353. }, 35000);
  1354. var head = _document.getElementsByTagName('head')[0];
  1355. head.insertBefore(script, head.firstChild);
  1356. if (script2) {
  1357. head.insertBefore(script2, head.firstChild);
  1358. }
  1359. return close_script;
  1360. };
  1361. // [*] End of lib/trans-jsonp-receiver.js
  1362. // [*] Including lib/trans-jsonp-polling.js
  1363. /*
  1364. * ***** BEGIN LICENSE BLOCK *****
  1365. * Copyright (c) 2011-2012 VMware, Inc.
  1366. *
  1367. * For the license see COPYING.
  1368. * ***** END LICENSE BLOCK *****
  1369. */
  1370. // The simplest and most robust transport, using the well-know cross
  1371. // domain hack - JSONP. This transport is quite inefficient - one
  1372. // mssage could use up to one http request. But at least it works almost
  1373. // everywhere.
  1374. // Known limitations:
  1375. // o you will get a spinning cursor
  1376. // o for Konqueror a dumb timer is needed to detect errors
  1377. var JsonPTransport = SockJS['jsonp-polling'] = function(ri, trans_url) {
  1378. utils.polluteGlobalNamespace();
  1379. var that = this;
  1380. that.ri = ri;
  1381. that.trans_url = trans_url;
  1382. that.send_constructor(jsonPGenericSender);
  1383. that._schedule_recv();
  1384. };
  1385. // Inheritnace
  1386. JsonPTransport.prototype = new BufferedSender();
  1387. JsonPTransport.prototype._schedule_recv = function() {
  1388. var that = this;
  1389. var callback = function(data) {
  1390. that._recv_stop = null;
  1391. if (data) {
  1392. // no data - heartbeat;
  1393. if (!that._is_closing) {
  1394. that.ri._didMessage(data);
  1395. }
  1396. }
  1397. // The message can be a close message, and change is_closing state.
  1398. if (!that._is_closing) {
  1399. that._schedule_recv();
  1400. }
  1401. };
  1402. that._recv_stop = jsonPReceiverWrapper(that.trans_url + '/jsonp',
  1403. jsonPGenericReceiver, callback);
  1404. };
  1405. JsonPTransport.enabled = function() {
  1406. return true;
  1407. };
  1408. JsonPTransport.need_body = true;
  1409. JsonPTransport.prototype.doCleanup = function() {
  1410. var that = this;
  1411. that._is_closing = true;
  1412. if (that._recv_stop) {
  1413. that._recv_stop();
  1414. }
  1415. that.ri = that._recv_stop = null;
  1416. that.send_destructor();
  1417. };
  1418. // Abstract away code that handles global namespace pollution.
  1419. var jsonPReceiverWrapper = function(url, constructReceiver, user_callback) {
  1420. var id = 'a' + utils.random_string(6);
  1421. var url_id = url + '?c=' + escape(WPrefix + '.' + id);
  1422. // Unfortunately it is not possible to abort loading of the
  1423. // script. We need to keep track of frake close frames.
  1424. var aborting = 0;
  1425. // Callback will be called exactly once.
  1426. var callback = function(frame) {
  1427. switch(aborting) {
  1428. case 0:
  1429. // Normal behaviour - delete hook _and_ emit message.
  1430. delete _window[WPrefix][id];
  1431. user_callback(frame);
  1432. break;
  1433. case 1:
  1434. // Fake close frame - emit but don't delete hook.
  1435. user_callback(frame);
  1436. aborting = 2;
  1437. break;
  1438. case 2:
  1439. // Got frame after connection was closed, delete hook, don't emit.
  1440. delete _window[WPrefix][id];
  1441. break;
  1442. }
  1443. };
  1444. var close_script = constructReceiver(url_id, callback);
  1445. _window[WPrefix][id] = close_script;
  1446. var stop = function() {
  1447. if (_window[WPrefix][id]) {
  1448. aborting = 1;
  1449. _window[WPrefix][id](utils.closeFrame(1000, "JSONP user aborted read"));
  1450. }
  1451. };
  1452. return stop;
  1453. };
  1454. // [*] End of lib/trans-jsonp-polling.js
  1455. // [*] Including lib/trans-xhr.js
  1456. /*
  1457. * ***** BEGIN LICENSE BLOCK *****
  1458. * Copyright (c) 2011-2012 VMware, Inc.
  1459. *
  1460. * For the license see COPYING.
  1461. * ***** END LICENSE BLOCK *****
  1462. */
  1463. var AjaxBasedTransport = function() {};
  1464. AjaxBasedTransport.prototype = new BufferedSender();
  1465. AjaxBasedTransport.prototype.run = function(ri, trans_url,
  1466. url_suffix, Receiver, AjaxObject) {
  1467. var that = this;
  1468. that.ri = ri;
  1469. that.trans_url = trans_url;
  1470. that.send_constructor(createAjaxSender(AjaxObject));
  1471. that.poll = new Polling(ri, Receiver,
  1472. trans_url + url_suffix, AjaxObject);
  1473. };
  1474. AjaxBasedTransport.prototype.doCleanup = function() {
  1475. var that = this;
  1476. if (that.poll) {
  1477. that.poll.abort();
  1478. that.poll = null;
  1479. }
  1480. };
  1481. // xhr-streaming
  1482. var XhrStreamingTransport = SockJS['xhr-streaming'] = function(ri, trans_url) {
  1483. this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XHRCorsObject);
  1484. };
  1485. XhrStreamingTransport.prototype = new AjaxBasedTransport();
  1486. XhrStreamingTransport.enabled = function() {
  1487. // Support for CORS Ajax aka Ajax2? Opera 12 claims CORS but
  1488. // doesn't do streaming.
  1489. return (_window.XMLHttpRequest &&
  1490. 'withCredentials' in new XMLHttpRequest() &&
  1491. (!/opera/i.test(navigator.userAgent)));
  1492. };
  1493. XhrStreamingTransport.roundTrips = 2; // preflight, ajax
  1494. // Safari gets confused when a streaming ajax request is started
  1495. // before onload. This causes the load indicator to spin indefinetely.
  1496. XhrStreamingTransport.need_body = true;
  1497. // According to:
  1498. // http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
  1499. // http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
  1500. // xdr-streaming
  1501. var XdrStreamingTransport = SockJS['xdr-streaming'] = function(ri, trans_url) {
  1502. this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XDRObject);
  1503. };
  1504. XdrStreamingTransport.prototype = new AjaxBasedTransport();
  1505. XdrStreamingTransport.enabled = function() {
  1506. return !!_window.XDomainRequest;
  1507. };
  1508. XdrStreamingTransport.roundTrips = 2; // preflight, ajax
  1509. // xhr-polling
  1510. var XhrPollingTransport = SockJS['xhr-polling'] = function(ri, trans_url) {
  1511. this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRCorsObject);
  1512. };
  1513. XhrPollingTransport.prototype = new AjaxBasedTransport();
  1514. XhrPollingTransport.enabled = XhrStreamingTransport.enabled;
  1515. XhrPollingTransport.roundTrips = 2; // preflight, ajax
  1516. // xdr-polling
  1517. var XdrPollingTransport = SockJS['xdr-polling'] = function(ri, trans_url) {
  1518. this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XDRObject);
  1519. };
  1520. XdrPollingTransport.prototype = new AjaxBasedTransport();
  1521. XdrPollingTransport.enabled = XdrStreamingTransport.enabled;
  1522. XdrPollingTransport.roundTrips = 2; // preflight, ajax
  1523. // [*] End of lib/trans-xhr.js
  1524. // [*] Including lib/trans-iframe.js
  1525. /*
  1526. * ***** BEGIN LICENSE BLOCK *****
  1527. * Copyright (c) 2011-2012 VMware, Inc.
  1528. *
  1529. * For the license see COPYING.
  1530. * ***** END LICENSE BLOCK *****
  1531. */
  1532. // Few cool transports do work only for same-origin. In order to make
  1533. // them working cross-domain we shall use iframe, served form the
  1534. // remote domain. New browsers, have capabilities to communicate with
  1535. // cross domain iframe, using postMessage(). In IE it was implemented
  1536. // from IE 8+, but of course, IE got some details wrong:
  1537. // http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
  1538. // http://stevesouders.com/misc/test-postmessage.php
  1539. var IframeTransport = function() {};
  1540. IframeTransport.prototype.i_constructor = function(ri, trans_url, base_url) {
  1541. var that = this;
  1542. that.ri = ri;
  1543. that.origin = utils.getOrigin(base_url);
  1544. that.base_url = base_url;
  1545. that.trans_url = trans_url;
  1546. var iframe_url = base_url + '/iframe.html';
  1547. if (that.ri._options.devel) {
  1548. iframe_url += '?t=' + (+new Date);
  1549. }
  1550. that.window_id = utils.random_string(8);
  1551. iframe_url += '#' + that.window_id;
  1552. that.iframeObj = utils.createIframe(iframe_url, function(r) {
  1553. that.ri._didClose(1006, "Unable to load an iframe (" + r + ")");
  1554. });
  1555. that.onmessage_cb = utils.bind(that.onmessage, that);
  1556. utils.attachMessage(that.onmessage_cb);
  1557. };
  1558. IframeTransport.prototype.doCleanup = function() {
  1559. var that = this;
  1560. if (that.iframeObj) {
  1561. utils.detachMessage(that.onmessage_cb);
  1562. try {
  1563. // When the iframe is not loaded, IE raises an exception
  1564. // on 'contentWindow'.
  1565. if (that.iframeObj.iframe.contentWindow) {
  1566. that.postMessage('c');
  1567. }
  1568. } catch (x) {}
  1569. that.iframeObj.cleanup();
  1570. that.iframeObj = null;
  1571. that.onmessage_cb = that.iframeObj = null;
  1572. }
  1573. };
  1574. IframeTransport.prototype.onmessage = function(e) {
  1575. var that = this;
  1576. if (e.origin !== that.origin) return;
  1577. var window_id = e.data.slice(0, 8);
  1578. var type = e.data.slice(8, 9);
  1579. var data = e.data.slice(9);
  1580. if (window_id !== that.window_id) return;
  1581. switch(type) {
  1582. case 's':
  1583. that.iframeObj.loaded();
  1584. that.postMessage('s', JSON.stringify([SockJS.version, that.protocol, that.trans_url, that.base_url]));
  1585. break;
  1586. case 't':
  1587. that.ri._didMessage(data);
  1588. break;
  1589. }
  1590. };
  1591. IframeTransport.prototype.postMessage = function(type, data) {
  1592. var that = this;
  1593. that.iframeObj.post(that.window_id + type + (data || ''), that.origin);
  1594. };
  1595. IframeTransport.prototype.doSend = function (message) {
  1596. this.postMessage('m', message);
  1597. };
  1598. IframeTransport.enabled = function() {
  1599. // postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
  1600. // huge delay, or not at all.
  1601. var konqueror = navigator && navigator.userAgent && navigator.userAgent.indexOf('Konqueror') !== -1;
  1602. return ((typeof _window.postMessage === 'function' ||
  1603. typeof _window.postMessage === 'object') && (!konqueror));
  1604. };
  1605. // [*] End of lib/trans-iframe.js
  1606. // [*] Including lib/trans-iframe-within.js
  1607. /*
  1608. * ***** BEGIN LICENSE BLOCK *****
  1609. * Copyright (c) 2011-2012 VMware, Inc.
  1610. *
  1611. * For the license see COPYING.
  1612. * ***** END LICENSE BLOCK *****
  1613. */
  1614. var curr_window_id;
  1615. var postMessage = function (type, data) {
  1616. if(parent !== _window) {
  1617. parent.postMessage(curr_window_id + type + (data || ''), '*');
  1618. } else {
  1619. utils.log("Can't postMessage, no parent window.", type, data);
  1620. }
  1621. };
  1622. var FacadeJS = function() {};
  1623. FacadeJS.prototype._didClose = function (code, reason) {
  1624. postMessage('t', utils.closeFrame(code, reason));
  1625. };
  1626. FacadeJS.prototype._didMessage = function (frame) {
  1627. postMessage('t', frame);
  1628. };
  1629. FacadeJS.prototype._doSend = function (data) {
  1630. this._transport.doSend(data);
  1631. };
  1632. FacadeJS.prototype._doCleanup = function () {
  1633. this._transport.doCleanup();
  1634. };
  1635. utils.parent_origin = undefined;
  1636. SockJS.bootstrap_iframe = function() {
  1637. var facade;
  1638. curr_window_id = _document.location.hash.slice(1);
  1639. var onMessage = function(e) {
  1640. if(e.source !== parent) return;
  1641. if(typeof utils.parent_origin === 'undefined')
  1642. utils.parent_origin = e.origin;
  1643. if (e.origin !== utils.parent_origin) return;
  1644. var window_id = e.data.slice(0, 8);
  1645. var type = e.data.slice(8, 9);
  1646. var data = e.data.slice(9);
  1647. if (window_id !== curr_window_id) return;
  1648. switch(type) {
  1649. case 's':
  1650. var p = JSON.parse(data);
  1651. var version = p[0];
  1652. var protocol = p[1];
  1653. var trans_url = p[2];
  1654. var base_url = p[3];
  1655. if (version !== SockJS.version) {
  1656. utils.log("Incompatibile SockJS! Main site uses:" +
  1657. " \"" + version + "\", the iframe:" +
  1658. " \"" + SockJS.version + "\".");
  1659. }
  1660. if (!utils.flatUrl(trans_url) || !utils.flatUrl(base_url)) {
  1661. utils.log("Only basic urls are supported in SockJS");
  1662. return;
  1663. }
  1664. if (!utils.isSameOriginUrl(trans_url) ||
  1665. !utils.isSameOriginUrl(base_url)) {
  1666. utils.log("Can't connect to different domain from within an " +
  1667. "iframe. (" + JSON.stringify([_window.location.href, trans_url, base_url]) +
  1668. ")");
  1669. return;
  1670. }
  1671. facade = new FacadeJS();
  1672. facade._transport = new FacadeJS[protocol](facade, trans_url, base_url);
  1673. break;
  1674. case 'm':
  1675. facade._doSend(data);
  1676. break;
  1677. case 'c':
  1678. if (facade)
  1679. facade._doCleanup();
  1680. facade = null;
  1681. break;
  1682. }
  1683. };
  1684. // alert('test ticker');
  1685. // facade = new FacadeJS();
  1686. // facade._transport = new FacadeJS['w-iframe-xhr-polling'](facade, 'http://host.com:9999/ticker/12/basd');
  1687. utils.attachMessage(onMessage);
  1688. // Start
  1689. postMessage('s');
  1690. };
  1691. // [*] End of lib/trans-iframe-within.js
  1692. // [*] Including lib/info.js
  1693. /*
  1694. * ***** BEGIN LICENSE BLOCK *****
  1695. * Copyright (c) 2011-2012 VMware, Inc.
  1696. *
  1697. * For the license see COPYING.
  1698. * ***** END LICENSE BLOCK *****
  1699. */
  1700. var InfoReceiver = function(base_url, AjaxObject) {
  1701. var that = this;
  1702. utils.delay(function(){that.doXhr(base_url, AjaxObject);});
  1703. };
  1704. InfoReceiver.prototype = new EventEmitter(['finish']);
  1705. InfoReceiver.prototype.doXhr = function(base_url, AjaxObject) {
  1706. var that = this;
  1707. var t0 = (new Date()).getTime();
  1708. var xo = new AjaxObject('GET', base_url + '/info');
  1709. var tref = utils.delay(8000,
  1710. function(){xo.ontimeout();});
  1711. xo.onfinish = function(status, text) {
  1712. clearTimeout(tref);
  1713. tref = null;
  1714. if (status === 200) {
  1715. var rtt = (new Date()).getTime() - t0;
  1716. var info = JSON.parse(text);
  1717. if (typeof info !== 'object') info = {};
  1718. that.emit('finish', info, rtt);
  1719. } else {
  1720. that.emit('finish');
  1721. }
  1722. };
  1723. xo.ontimeout = function() {
  1724. xo.close();
  1725. that.emit('finish');
  1726. };
  1727. };
  1728. var InfoReceiverIframe = function(base_url) {
  1729. var that = this;
  1730. var go = function() {
  1731. var ifr = new IframeTransport();
  1732. ifr.protocol = 'w-iframe-info-receiver';
  1733. var fun = function(r) {
  1734. if (typeof r === 'string' && r.substr(0,1) === 'm') {
  1735. var d = JSON.parse(r.substr(1));
  1736. var info = d[0], rtt = d[1];
  1737. that.emit('finish', info, rtt);
  1738. } else {
  1739. that.emit('finish');
  1740. }
  1741. ifr.doCleanup();
  1742. ifr = null;
  1743. };
  1744. var mock_ri = {
  1745. _options: {},
  1746. _didClose: fun,
  1747. _didMessage: fun
  1748. };
  1749. ifr.i_constructor(mock_ri, base_url, base_url);
  1750. }
  1751. if(!_document.body) {
  1752. utils.attachEvent('load', go);
  1753. } else {
  1754. go();
  1755. }
  1756. };
  1757. InfoReceiverIframe.prototype = new EventEmitter(['finish']);
  1758. var InfoReceiverFake = function() {
  1759. // It may not be possible to do cross domain AJAX to get the info
  1760. // data, for example for IE7. But we want to run JSONP, so let's
  1761. // fake the response, with rtt=2s (rto=6s).
  1762. var that = this;
  1763. utils.delay(function() {
  1764. that.emit('finish', {}, 2000);
  1765. });
  1766. };
  1767. InfoReceiverFake.prototype = new EventEmitter(['finish']);
  1768. var createInfoReceiver = function(base_url) {
  1769. if (utils.isSameOriginUrl(base_url)) {
  1770. // If, for some reason, we have SockJS locally - there's no
  1771. // need to start up the complex machinery. Just use ajax.
  1772. return new InfoReceiver(base_url, utils.XHRLocalObject);
  1773. }
  1774. switch (utils.isXHRCorsCapable()) {
  1775. case 1:
  1776. // XHRLocalObject -> no_credentials=true
  1777. return new InfoReceiver(base_url, utils.XHRLocalObject);
  1778. case 2:
  1779. return new InfoReceiver(base_url, utils.XDRObject);
  1780. case 3:
  1781. // Opera
  1782. return new InfoReceiverIframe(base_url);
  1783. default:
  1784. // IE 7
  1785. return new InfoReceiverFake();
  1786. };
  1787. };
  1788. var WInfoReceiverIframe = FacadeJS['w-iframe-info-receiver'] = function(ri, _trans_url, base_url) {
  1789. var ir = new InfoReceiver(base_url, utils.XHRLocalObject);
  1790. ir.onfinish = function(info, rtt) {
  1791. ri._didMessage('m'+JSON.stringify([info, rtt]));
  1792. ri._didClose();
  1793. }
  1794. };
  1795. WInfoReceiverIframe.prototype.doCleanup = function() {};
  1796. // [*] End of lib/info.js
  1797. // [*] Including lib/trans-iframe-eventsource.js
  1798. /*
  1799. * ***** BEGIN LICENSE BLOCK *****
  1800. * Copyright (c) 2011-2012 VMware, Inc.
  1801. *
  1802. * For the license see COPYING.
  1803. * ***** END LICENSE BLOCK *****
  1804. */
  1805. var EventSourceIframeTransport = SockJS['iframe-eventsource'] = function () {
  1806. var that = this;
  1807. that.protocol = 'w-iframe-eventsource';
  1808. that.i_constructor.apply(that, arguments);
  1809. };
  1810. EventSourceIframeTransport.prototype = new IframeTransport();
  1811. EventSourceIframeTransport.enabled = function () {
  1812. return ('EventSource' in _window) && IframeTransport.enabled();
  1813. };
  1814. EventSourceIframeTransport.need_body = true;
  1815. EventSourceIframeTransport.roundTrips = 3; // html, javascript, eventsource
  1816. // w-iframe-eventsource
  1817. var EventSourceTransport = FacadeJS['w-iframe-eventsource'] = function(ri, trans_url) {
  1818. this.run(ri, trans_url, '/eventsource', EventSourceReceiver, utils.XHRLocalObject);
  1819. }
  1820. EventSourceTransport.prototype = new AjaxBasedTransport();
  1821. // [*] End of lib/trans-iframe-eventsource.js
  1822. // [*] Including lib/trans-iframe-xhr-polling.js
  1823. /*
  1824. * ***** BEGIN LICENSE BLOCK *****
  1825. * Copyright (c) 2011-2012 VMware, Inc.
  1826. *
  1827. * For the license see COPYING.
  1828. * ***** END LICENSE BLOCK *****
  1829. */
  1830. var XhrPollingIframeTransport = SockJS['iframe-xhr-polling'] = function () {
  1831. var that = this;
  1832. that.protocol = 'w-iframe-xhr-polling';
  1833. that.i_constructor.apply(that, arguments);
  1834. };
  1835. XhrPollingIframeTransport.prototype = new IframeTransport();
  1836. XhrPollingIframeTransport.enabled = function () {
  1837. return _window.XMLHttpRequest && IframeTransport.enabled();
  1838. };
  1839. XhrPollingIframeTransport.need_body = true;
  1840. XhrPollingIframeTransport.roundTrips = 3; // html, javascript, xhr
  1841. // w-iframe-xhr-polling
  1842. var XhrPollingITransport = FacadeJS['w-iframe-xhr-polling'] = function(ri, trans_url) {
  1843. this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRLocalObject);
  1844. };
  1845. XhrPollingITransport.prototype = new AjaxBasedTransport();
  1846. // [*] End of lib/trans-iframe-xhr-polling.js
  1847. // [*] Including lib/trans-iframe-htmlfile.js
  1848. /*
  1849. * ***** BEGIN LICENSE BLOCK *****
  1850. * Copyright (c) 2011-2012 VMware, Inc.
  1851. *
  1852. * For the license see COPYING.
  1853. * ***** END LICENSE BLOCK *****
  1854. */
  1855. // This transport generally works in any browser, but will cause a
  1856. // spinning cursor to appear in any browser other than IE.
  1857. // We may test this transport in all browsers - why not, but in
  1858. // production it should be only run in IE.
  1859. var HtmlFileIframeTransport = SockJS['iframe-htmlfile'] = function () {
  1860. var that = this;
  1861. that.protocol = 'w-iframe-htmlfile';
  1862. that.i_constructor.apply(that, arguments);
  1863. };
  1864. // Inheritance.
  1865. HtmlFileIframeTransport.prototype = new IframeTransport();
  1866. HtmlFileIframeTransport.enabled = function() {
  1867. return IframeTransport.enabled();
  1868. };
  1869. HtmlFileIframeTransport.need_body = true;
  1870. HtmlFileIframeTransport.roundTrips = 3; // html, javascript, htmlfile
  1871. // w-iframe-htmlfile
  1872. var HtmlFileTransport = FacadeJS['w-iframe-htmlfile'] = function(ri, trans_url) {
  1873. this.run(ri, trans_url, '/htmlfile', HtmlfileReceiver, utils.XHRLocalObject);
  1874. };
  1875. HtmlFileTransport.prototype = new AjaxBasedTransport();
  1876. // [*] End of lib/trans-iframe-htmlfile.js
  1877. // [*] Including lib/trans-polling.js
  1878. /*
  1879. * ***** BEGIN LICENSE BLOCK *****
  1880. * Copyright (c) 2011-2012 VMware, Inc.
  1881. *
  1882. * For the license see COPYING.
  1883. * ***** END LICENSE BLOCK *****
  1884. */
  1885. var Polling = function(ri, Receiver, recv_url, AjaxObject) {
  1886. var that = this;
  1887. that.ri = ri;
  1888. that.Receiver = Receiver;
  1889. that.recv_url = recv_url;
  1890. that.AjaxObject = AjaxObject;
  1891. that._scheduleRecv();
  1892. };
  1893. Polling.prototype._scheduleRecv = function() {
  1894. var that = this;
  1895. var poll = that.poll = new that.Receiver(that.recv_url, that.AjaxObject);
  1896. var msg_counter = 0;
  1897. poll.onmessage = function(e) {
  1898. msg_counter += 1;
  1899. that.ri._didMessage(e.data);
  1900. };
  1901. poll.onclose = function(e) {
  1902. that.poll = poll = poll.onmessage = poll.onclose = null;
  1903. if (!that.poll_is_closing) {
  1904. if (e.reason === 'permanent') {
  1905. that.ri._didClose(1006, 'Polling error (' + e.reason + ')');
  1906. } else {
  1907. that._scheduleRecv();
  1908. }
  1909. }
  1910. };
  1911. };
  1912. Polling.prototype.abort = function() {
  1913. var that = this;
  1914. that.poll_is_closing = true;
  1915. if (that.poll) {
  1916. that.poll.abort();
  1917. }
  1918. };
  1919. // [*] End of lib/trans-polling.js
  1920. // [*] Including lib/trans-receiver-eventsource.js
  1921. /*
  1922. * ***** BEGIN LICENSE BLOCK *****
  1923. * Copyright (c) 2011-2012 VMware, Inc.
  1924. *
  1925. * For the license see COPYING.
  1926. * ***** END LICENSE BLOCK *****
  1927. */
  1928. var EventSourceReceiver = function(url) {
  1929. var that = this;
  1930. var es = new EventSource(url);
  1931. es.onmessage = function(e) {
  1932. that.dispatchEvent(new SimpleEvent('message',
  1933. {'data': unescape(e.data)}));
  1934. };
  1935. that.es_close = es.onerror = function(e, abort_reason) {
  1936. // ES on reconnection has readyState = 0 or 1.
  1937. // on network error it's CLOSED = 2
  1938. var reason = abort_reason ? 'user' :
  1939. (es.readyState !== 2 ? 'network' : 'permanent');
  1940. that.es_close = es.onmessage = es.onerror = null;
  1941. // EventSource reconnects automatically.
  1942. es.close();
  1943. es = null;
  1944. // Safari and chrome < 15 crash if we close window before
  1945. // waiting for ES cleanup. See:
  1946. // https://code.google.com/p/chromium/issues/detail?id=89155
  1947. utils.delay(200, function() {
  1948. that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
  1949. });
  1950. };
  1951. };
  1952. EventSourceReceiver.prototype = new REventTarget();
  1953. EventSourceReceiver.prototype.abort = function() {
  1954. var that = this;
  1955. if (that.es_close) {
  1956. that.es_close({}, true);
  1957. }
  1958. };
  1959. // [*] End of lib/trans-receiver-eventsource.js
  1960. // [*] Including lib/trans-receiver-htmlfile.js
  1961. /*
  1962. * ***** BEGIN LICENSE BLOCK *****
  1963. * Copyright (c) 2011-2012 VMware, Inc.
  1964. *
  1965. * For the license see COPYING.
  1966. * ***** END LICENSE BLOCK *****
  1967. */
  1968. var _is_ie_htmlfile_capable;
  1969. var isIeHtmlfileCapable = function() {
  1970. if (_is_ie_htmlfile_capable === undefined) {
  1971. if ('ActiveXObject' in _window) {
  1972. try {
  1973. _is_ie_htmlfile_capable = !!new ActiveXObject('htmlfile');
  1974. } catch (x) {}
  1975. } else {
  1976. _is_ie_htmlfile_capable = false;
  1977. }
  1978. }
  1979. return _is_ie_htmlfile_capable;
  1980. };
  1981. var HtmlfileReceiver = function(url) {
  1982. var that = this;
  1983. utils.polluteGlobalNamespace();
  1984. that.id = 'a' + utils.random_string(6, 26);
  1985. url += ((url.indexOf('?') === -1) ? '?' : '&') +
  1986. 'c=' + escape(WPrefix + '.' + that.id);
  1987. var constructor = isIeHtmlfileCapable() ?
  1988. utils.createHtmlfile : utils.createIframe;
  1989. var iframeObj;
  1990. _window[WPrefix][that.id] = {
  1991. start: function () {
  1992. iframeObj.loaded();
  1993. },
  1994. message: function (data) {
  1995. that.dispatchEvent(new SimpleEvent('message', {'data': data}));
  1996. },
  1997. stop: function () {
  1998. that.iframe_close({}, 'network');
  1999. }
  2000. };
  2001. that.iframe_close = function(e, abort_reason) {
  2002. iframeObj.cleanup();
  2003. that.iframe_close = iframeObj = null;
  2004. delete _window[WPrefix][that.id];
  2005. that.dispatchEvent(new SimpleEvent('close', {reason: abort_reason}));
  2006. };
  2007. iframeObj = constructor(url, function(e) {
  2008. that.iframe_close({}, 'permanent');
  2009. });
  2010. };
  2011. HtmlfileReceiver.prototype = new REventTarget();
  2012. HtmlfileReceiver.prototype.abort = function() {
  2013. var that = this;
  2014. if (that.iframe_close) {
  2015. that.iframe_close({}, 'user');
  2016. }
  2017. };
  2018. // [*] End of lib/trans-receiver-htmlfile.js
  2019. // [*] Including lib/trans-receiver-xhr.js
  2020. /*
  2021. * ***** BEGIN LICENSE BLOCK *****
  2022. * Copyright (c) 2011-2012 VMware, Inc.
  2023. *
  2024. * For the license see COPYING.
  2025. * ***** END LICENSE BLOCK *****
  2026. */
  2027. var XhrReceiver = function(url, AjaxObject) {
  2028. var that = this;
  2029. var buf_pos = 0;
  2030. that.xo = new AjaxObject('POST', url, null);
  2031. that.xo.onchunk = function(status, text) {
  2032. if (status !== 200) return;
  2033. while (1) {
  2034. var buf = text.slice(buf_pos);
  2035. var p = buf.indexOf('\n');
  2036. if (p === -1) break;
  2037. buf_pos += p+1;
  2038. var msg = buf.slice(0, p);
  2039. that.dispatchEvent(new SimpleEvent('message', {data: msg}));
  2040. }
  2041. };
  2042. that.xo.onfinish = function(status, text) {
  2043. that.xo.onchunk(status, text);
  2044. that.xo = null;
  2045. var reason = status === 200 ? 'network' : 'permanent';
  2046. that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
  2047. }
  2048. };
  2049. XhrReceiver.prototype = new REventTarget();
  2050. XhrReceiver.prototype.abort = function() {
  2051. var that = this;
  2052. if (that.xo) {
  2053. that.xo.close();
  2054. that.dispatchEvent(new SimpleEvent('close', {reason: 'user'}));
  2055. that.xo = null;
  2056. }
  2057. };
  2058. // [*] End of lib/trans-receiver-xhr.js
  2059. // [*] Including lib/test-hooks.js
  2060. /*
  2061. * ***** BEGIN LICENSE BLOCK *****
  2062. * Copyright (c) 2011-2012 VMware, Inc.
  2063. *
  2064. * For the license see COPYING.
  2065. * ***** END LICENSE BLOCK *****
  2066. */
  2067. // For testing
  2068. SockJS.getUtils = function(){
  2069. return utils;
  2070. };
  2071. SockJS.getIframeTransport = function(){
  2072. return IframeTransport;
  2073. };
  2074. // [*] End of lib/test-hooks.js
  2075. return SockJS;
  2076. })();
  2077. if ('_sockjs_onload' in window) setTimeout(_sockjs_onload, 1);
  2078. // AMD compliance
  2079. if (typeof define === 'function' && define.amd) {
  2080. define('sockjs', [], function(){return SockJS;});
  2081. }
  2082. // [*] End of lib/index.js
  2083. // [*] End of lib/all.js