Skip to content

Instantly share code, notes, and snippets.

@shripadk
Created November 21, 2011 02:36
Show Gist options
  • Save shripadk/1381446 to your computer and use it in GitHub Desktop.
Save shripadk/1381446 to your computer and use it in GitHub Desktop.
secret. do not fork it!
/* SockJS client, version 0.1.1, http://sockjs.org, MIT License
Copyright (C) 2011 VMware, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// JSON2 by Douglas Crockford (minified).
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")})}()
SockJS=function(){var a=document,b=window,c=function(){};c.prototype.addEventListener=function(a,b){this._listeners||(this._listeners={}),a in this._listeners||(this._listeners[a]=[]);var c=this._listeners[a];e.arrIndexOf(c,b)===-1&&c.push(b);return},c.prototype.removeEventListener=function(a,b){if(!!(this._listeners&&a in this._listeners)){var c=this._listeners[a],d=e.arrIndexOf(c,b);if(d!==-1){c.length>1?this._listeners[a]=c.slice(0,d).concat(c.slice(d+1)):delete this._listeners[a];return}return}},c.prototype.dispatchEvent=function(a){var b=a.type,c=Array.prototype.slice.call(arguments,0);this["on"+b]&&this["on"+b].apply(this,c);if(this._listeners&&b in this._listeners)for(var d=0;d<this._listeners[b].length;d++)this._listeners[b][d].apply(this,c)};var d=function(a,b){this.type=a;if(typeof b!="undefined")for(var c in b){if(!b.hasOwnProperty(c))continue;this[c]=b[c]}};d.prototype.toString=function(){var a=[];for(var b in this){if(!this.hasOwnProperty(b))continue;var c=this[b];typeof c=="function"&&(c="[function]"),a.push(b+"="+c)}return"SimpleEvent("+a.join(", ")+")"};var e={},f=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","_"];e.random_string=function(a,b){b=b||f.length;var c,d=[];for(c=0;c<a;c++)d.push(f[Math.floor(Math.random()*b)]);return d.join("")},e.random_number=function(a){return Math.floor(Math.random()*a)},e.random_number_string=function(a){var b=""+e.random_number(a),c=(""+(a-1)).length;while(b.length<c)b="0"+b;return b},e.attachMessage=function(a){e.attachEvent("message",a)},e.attachEvent=function(c,d){typeof b.addEventListener!="undefined"?b.addEventListener(c,d,!1):(a.attachEvent("on"+c,d),b.attachEvent("on"+c,d))},e.detachMessage=function(a){e.detachEvent("message",a)},e.detachEvent=function(c,d){typeof b.addEventListener!="undefined"?b.removeEventListener(c,d,!1):(a.detachEvent("on"+c,d),b.detachEvent("on"+c,d))},e.getOrigin=function(a){a+="/";var b=a.split("/").slice(0,3);return b.join("/")},e.objectExtend=function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a};var g={"User-Agent":"",Accept:"","Accept-Language":"","Content-Type":"text/plain;charset=UTF-8"};navigator&&(navigator.userAgent.indexOf("Chrome")!=-1||navigator.userAgent.indexOf("Safari")!=-1)&&delete g["User-Agent"],e.createXDR=function(a,b,c,d){var f={status:null,responseText:"",readyState:1},g=new XDomainRequest();g.timeout=25000;b+=(b.indexOf("?")===-1?"?":"&")+"t="+e.random_string(8);var h=function(){if(g){i=g.onerror=g.ontimeout=g.onprogress=g.onload=null;try{g.abort()}catch(a){}g=d=null}},i=g.ontimeout=g.onerror=function(){f.status=500,f.readyState=4,d(f),h()};g.onload=function(){f.status=200,f.readyState=4,f.responseText=g.responseText,d(f),h()},g.onprogress=function(){f.status=200,f.readyState=3,f.responseText=g.responseText,d(f)};try{g.open(a,b),g.send(c)}catch(j){e.delay(i)}return function(a){d&&(d(f,null,a),h())}},e.createXHR=function(a,c,d,f){var h;if(b.ActiveXObject){c+=(c.indexOf("?")===-1?"?":"&")+"t="+ +(new Date);try{h=new ActiveXObject("Microsoft.XMLHTTP")}catch(i){}}h||(h=new XMLHttpRequest),h.open(a,c,!0);for(var j in g)try{h.setRequestHeader(j,g[j])}catch(i){delete g[j]}"withCredentials"in h&&(h.withCredentials="true");var k=function(){if(h){try{h.onreadystatechange=null}catch(a){h.onreadystatechange=function(){}}try{h.abort()}catch(b){}e.detachEvent("unload",k)}f=h=null};h.onreadystatechange=function(a){h&&f&&(f(h,a),h&&h.readyState===4&&k())},h.send(d),e.attachEvent("unload",k);return function(a){f&&(f(h,null,a),k())}};var h="_jp";e.polluteGlobalNamespace=function(){h in b||(b[h]={})},e.createIframe=function(b,c){var d=a.createElement("iframe"),f,g=function(){clearTimeout(f);try{d.onload=null}catch(a){}d.onerror=null},h=function(){d&&(g(),d.parentNode.removeChild(d),d.src="about:blank",d=null,e.detachEvent("unload",h))},i=function(a){d&&(h(),c(a))};d.src=b,d.style.display="none",d.style.position="absolute",d.onerror=function(){i("onerror")},d.onload=function(){clearTimeout(f),f=setTimeout(function(){i("onload timeout")},2e3)},a.body.appendChild(d),f=setTimeout(function(){i("timeout")},5e3),e.attachEvent("unload",h);return{iframe:d,cleanup:h,loaded:g}},e.createHtmlfile=function(a,c){var d=new ActiveXObject("htmlfile"),f,g,i=function(){clearTimeout(f)},j=function(){if(d){i(),e.detachEvent("unload",j);try{g.src="about:blank"}catch(a){}g.parentNode.removeChild(g),g=d=null,CollectGarbage()}},k=function(a){d&&(j(),c(a))};d.open(),d.write('<html><script>document.domain="'+document.domain+'";'+"</script></html>"),d.close(),d.parentWindow[h]=b[h];var l=d.createElement("div");d.body.appendChild(l),g=d.createElement("iframe"),l.appendChild(g),g.src=a,f=setTimeout(function(){k("timeout")},5e3),e.attachEvent("unload",j);return{iframe:g,cleanup:j,loaded:i}},e.closeFrame=function(a,b){return"c"+JSON.stringify([a,b])},e.userSetCode=function(a){return a===1e3||a>=3e3&&a<=4999},e.log=function(){b.console&&console.log&&console.log.apply&&console.log.apply(console,arguments)},e.bind=function(a,b){return a.bind?a.bind(b):function(){return a.apply(b,arguments)}},e.amendUrl=function(b){var c=a.location;if(!b)throw new Error("Wrong url for SockJS");b.indexOf("//")===0&&(b=c.protocol+b),b.indexOf("/")===0&&(b=c.protocol+"//"+c.host+b),b=b.replace(/[/]+$/,"");return b},e.arrIndexOf=function(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return c;return-1},e.delay=function(a,b){typeof a=="function"&&(b=a,a=0);return setTimeout(b,a)};var i=function(a,b,c){var d=this;d._options={devel:!1,debug:!1,chunking:undefined},c&&e.objectExtend(d._options,c),d._base_url=e.amendUrl(a),d._server=d._options.server||e.random_number_string(1e3),d._connid=e.random_string(8),d._trans_url=d._base_url+"/"+d._server+"/"+d._connid,d._protocols=["websocket","xhr-streaming","iframe-eventsource","iframe-htmlfile","xhr-polling","iframe-xhr-polling","jsonp-polling"];switch(typeof b){case"undefined":break;case"string":d._protocols=[b];break;default:d._protocols=b}d.protocol=null,d.readyState=i.CONNECTING,d._didClose()};i.prototype=new c,i.version="0.1.1.dirty",i.CONNECTING=0,i.OPEN=1,i.CLOSING=2,i.CLOSED=3,i.prototype._debug=function(){this._options.debug&&e.log.apply(e,arguments)},i.prototype._dispatchOpen=function(){var a=this;a.readyState===i.CONNECTING?(a._transport_tref&&(clearTimeout(a._transport_tref),a._transport_tref=null),a.readyState=i.OPEN,a.dispatchEvent(new d("open"))):a._didClose(1006,"Server lost session")},i.prototype._dispatchMessage=function(a){var b=this;b.readyState===i.OPEN&&b.dispatchEvent(new d("message",{data:a}))},i.prototype._dispatchHeartbeat=function(a){var b=this;b.readyState===i.OPEN&&b.dispatchEvent(new d("heartbeat",{}))},i.prototype._didClose=function(a,b){var c=this;if(c.readyState!==i.CONNECTING&&c.readyState!==i.OPEN&&c.readyState!==i.CLOSING)throw new Error("INVALID_STATE_ERR");c._transport&&c._transport.doCleanup(),c._transport=null,c._transport_tref&&(clearTimeout(c._transport_tref),c._transport_tref=null);var f=new d("close",{code:a,reason:b,wasClean:e.userSetCode(a)});if(!e.userSetCode(a)&&c.readyState===i.CONNECTING){if(c._try_next_protocol(f)){c._transport_tref=setTimeout(function(){c.readyState===i.CONNECTING&&c._didClose(2007,"Transport timeouted")},5001);return}f=new d("close",{code:2e3,reason:"All transports failed",wasClean:!1,last_event:f})}c.readyState=i.CLOSED,e.delay(function(){c.dispatchEvent(f)})},i.prototype._didMessage=function(a){var b=this,c=a.slice(0,1);switch(c){case"o":b._dispatchOpen();break;case"a":var d=JSON.parse(a.slice(1)||"[]");for(var e=0;e<d.length;e++)b._dispatchMessage(d[e]);break;case"m":var d=JSON.parse(a.slice(1)||"null");b._dispatchMessage(d);break;case"c":var d=JSON.parse(a.slice(1)||"[]");b._didClose(d[0],d[1]);break;case"h":b._dispatchHeartbeat()}},i.prototype._try_next_protocol=function(a){var b=this;b.protocol&&(b._debug("Closed transport:",b.protocol,""+a),b.protocol=null);for(;;){var c=b.protocol=b._protocols.shift();if(!c)return!1;if(i[c]&&i[c].need_chunking===!0&&b._options.chunking===undefined){b._protocols.unshift(c),b.protocol="chunking-test",b._options.chunking=!1,A(b._base_url,function(a){b._options.chunking=a,b._try_next_protocol()},b._options);return!0}if(!i[c]||i[c].need_chunking===!0&&b._options.chunking!==!0||!i[c].enabled(b._options))b._debug("Skipping transport:",c);else{b._debug("Opening transport:",c),b._transport=new i[c](b,b._trans_url,b._base_url);return!0}}},i.prototype.close=function(a,b){var c=this;if(a&&!e.userSetCode(a))throw new Error("INVALID_ACCESS_ERR");if(c.readyState!==i.CONNECTING&&c.readyState!==i.OPEN)return!1;c.readyState=i.CLOSING,c._didClose(a||1e3,b||"Normal closure");return!0},i.prototype.send=function(a){var b=this;if(b.readyState===i.CONNECTING)throw new Error("INVALID_STATE_ERR");b.readyState===i.OPEN&&b._transport.doSend(JSON.stringify(""+a));return!0};var j=i.websocket=function(a,b){var c=this,d=b+"/websocket";d.slice(0,5)==="https"?d="wss"+d.slice(5):d="ws"+d.slice(4),c.ri=a,c.url=d;var f=window.WebSocket||window.MozWebSocket;c.ws=new f(c.url),c.ws.onmessage=function(a){c.ri._didMessage(a.data)},c.ws.onclose=function(){c.ri._didMessage(e.closeFrame(1006,"WebSocket connection broken"))}};j.prototype.doSend=function(a){this.ws.send(a)},j.prototype.doCleanup=function(){var a=this,b=a.ws;b&&(b.onmessage=b.onclose=null,b.close(),a.ri=a.ws=null)},j.enabled=function(){return!!window.WebSocket||!!window.MozWebSocket};var k=function(){};k.prototype.send_constructor=function(a){var b=this;b.send_buffer=[],b.sender=a},k.prototype.doSend=function(a){var b=this;b.send_buffer.push(a),b.send_stop||b.send_schedule()},k.prototype.send_schedule_wait=function(){var a=this,b;a.send_stop=function(){a.send_stop=null,clearTimeout(b)},b=e.delay(25,function(){a.send_stop=null,a.send_schedule()})},k.prototype.send_schedule=function(){var a=this;if(a.send_buffer.length>0){var b="["+a.send_buffer.join(",")+"]";a.send_stop=a.sender(a.trans_url,b,function(){a.send_stop=null,a.send_schedule_wait()}),a.send_buffer=[]}},k.prototype.send_destructor=function(){var a=this;a._send_stop&&a._send_stop(),a._send_stop=null};var l=function(b,c,d){var f=this;if(!("_send_form"in f)){var g=f._send_form=a.createElement("form"),h=f._send_area=a.createElement("textarea");h.name="d",g.style.display="none",g.style.position="absolute",g.method="POST",g.enctype="application/x-www-form-urlencoded",g.acceptCharset="UTF-8",g.appendChild(h),a.body.appendChild(g)}var g=f._send_form,h=f._send_area,i="a"+e.random_string(8);g.target=i,g.action=b+"/jsonp_send?i="+i;var j;try{j=a.createElement('<iframe name="'+i+'">')}catch(k){j=a.createElement("iframe"),j.name=i}j.id=i,g.appendChild(j),j.style.display="none",h.value=c,g.submit();var l=function(a){!j.onerror||(j.onreadystatechange=j.onerror=j.onload=null,e.delay(500,function(){j.parentNode.removeChild(j),j=null}),h.value=null,d())};j.onerror=j.onload=l,j.onreadystatechange=function(a){j.readyState=="complete"&&l()};return l},m=function(a,b,c){var d=function(a,b,d){(a.readyState===4||d)&&c(a.status,d)};return e.createXHR("POST",a+"/xhr_send",b,d)},n=function(a,b,c){var d=function(a,b,d){(a.readyState===4||d)&&c(a.status,d)},f=window.XDomainRequest?e.createXDR:e.createXHR;return f("POST",a+"/xhr_send",b,d)},o=function(b,c){var d,f=a.createElement("script"),g,h=function(a){g&&(g.parentNode.removeChild(g),g=null),f&&(clearTimeout(d),f.parentNode.removeChild(f),f.onreadystatechange=f.onerror=f.onload=f.onclick=null,f=null,c(a),c=null)},i=!1,j=null;f.id="a"+e.random_string(8),f.src=b,f.type="text/javascript",f.charset="UTF-8",f.onerror=function(a){j||(j=setTimeout(function(){i||h(e.closeFrame(1006,"JSONP script loaded abnormally (onerror)"))},1e3))},f.onload=function(a){h(e.closeFrame(1006,"JSONP script loaded abnormally (onload)"))},f.onreadystatechange=function(a){if(/loaded|closed/.test(f.readyState)){if(f&&f.htmlFor&&f.onclick){i=!0;try{f.onclick()}catch(b){}}f&&h(e.closeFrame(1006,"JSONP script loaded abnormally (onreadystatechange)"))}};if(typeof f.async=="undefined"&&a.attachEvent)if(!/opera/i.test(navigator.userAgent)){try{f.htmlFor=f.id,f.event="onclick"}catch(k){}f.async=!0}else g=a.createElement("script"),g.text="try{var a = document.getElementById('"+f.id+"'); if(a)a.onerror();}catch(x){};",f.async=g.async=!1;typeof f.async!="undefined"&&(f.async=!0),d=setTimeout(function(){h(e.closeFrame(1006,"JSONP script loaded abnormally (timeout)"))},35e3);var l=a.getElementsByTagName("head")[0];l.insertBefore(f,l.firstChild),g&&l.insertBefore(g,l.firstChild);return h},p=i["jsonp-polling"]=function(a,b){e.polluteGlobalNamespace();var c=this;c.ri=a,c.trans_url=b,c.send_constructor(l),c._schedule_recv()};p.prototype=new k,p.prototype._schedule_recv=function(){var a=this,b=function(b){a._recv_stop=null,b&&(a._is_closing||a.ri._didMessage(b)),a._is_closing||a._schedule_recv()};a._recv_stop=q(a.trans_url+"/jsonp",o,b)},p.enabled=function(){return!0},p.prototype.doCleanup=function(){var a=this;a._is_closing=!0,a._recv_stop&&a._recv_stop(),a.ri=a._recv_stop=null,a.send_destructor()};var q=function(a,c,d){var f="a"+e.random_string(6),g=a+"?c="+escape(h+"."+f),i=function(a){delete b[h][f],d(a)},j=c(g,i);b[h][f]=j;var k=function(){b[h][f]&&b[h][f](e.closeFrame(1e3,"JSONP user aborted read"))};return k},r=i["xhr-streaming"]=function(a,b){var c=this;c.ri=a,c.trans_url=b,c.send_constructor(n),c.poll=new H(a,M,b+"/xhr_streaming",{cors:!0})};r.prototype=new k,r.prototype.doCleanup=function(){var a=this;a.poll&&(a.poll.abort(),a.poll=null)},r.enabled=function(a){return a.cookie!==!0&&window.XDomainRequest?!0:window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?!0:!1},r.need_chunking=!0;var s=i["xhr-polling"]=function(a,b){var c=this;c.ri=a,c.trans_url=b,c.send_constructor(n),c.poll=new H(a,M,b+"/xhr",{cors:!0})};s.prototype=new k,s.prototype.doCleanup=function(){var a=this;a.poll&&(a.poll.abort(),a.poll=null)},s.enabled=r.enabled;var t=function(){};t.prototype.i_constructor=function(a,b,c){var d=this;d.ri=a,d.origin=e.getOrigin(c),d.base_url=c,d.trans_url=b;var f=c+"/iframe.html";d.ri._options.devel&&(f+="?t="+ +(new Date)),d.window_id=e.random_string(8),f+="#"+d.window_id,d.iframeObj=e.createIframe(f,function(a){d.ri._didClose(1006,"Unable to load an iframe ("+a+")")}),d.onmessage_cb=e.bind(d.onmessage,d),e.attachMessage(d.onmessage_cb)},t.prototype.doCleanup=function(){var a=this;if(a.iframeObj){e.detachMessage(a.onmessage_cb);try{a.iframeObj.iframe.contentWindow&&a.postMessage("c")}catch(b){}a.iframeObj.cleanup(),a.iframeObj=null,a.onmessage_cb=a.iframeObj=null}},t.prototype.onmessage=function(a){var b=this;if(a.origin===b.origin){var c=a.data.slice(0,8),d=a.data.slice(8,9),e=a.data.slice(9);if(c!==b.window_id)return;switch(d){case"s":b.iframeObj.loaded(),b.postMessage("s",JSON.stringify([i.version,b.protocol,b.trans_url,b.base_url]));break;case"t":b.ri._didMessage(e)}}},t.prototype.postMessage=function(a,b){var c=this;c.iframeObj.iframe.contentWindow.postMessage(c.window_id+a+(b||""),c.origin)},t.prototype.doSend=function(a){this.postMessage("m",a)},t.enabled=function(){var a=navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Konqueror")!==-1;return(typeof b.postMessage=="function"||typeof b.postMessage=="object")&&!a};var u,v=function(a,c){parent!==b?parent.postMessage(u+a+(c||""),"*"):e.log("Can't postMessage, no parent window.",a,c)},w=function(){};w.prototype._didClose=function(a,b){v("t",e.closeFrame(a,b))},w.prototype._didMessage=function(a){v("t",a)},w.prototype._doSend=function(a){this._transport.doSend(a)},w.prototype._doCleanup=function(){this._transport.doCleanup()},i.bootstrap_iframe=function(){var b;u=a.location.hash.slice(1);var c=function(a){if(a.source===parent){var c=a.data.slice(0,8),d=a.data.slice(8,9),f=a.data.slice(9);if(c!==u)return;switch(d){case"s":var g=JSON.parse(f),h=g[0],j=g[1],k=g[2],l=g[3];h!==i.version&&e.log('Incompatibile SockJS! Main site uses: "'+h+'", the iframe:'+' "'+i.version+'".'),b=new w,b._transport=new w[j](b,k,l);break;case"m":b._doSend(f);break;case"c":b._doCleanup(),b=null}}};e.attachMessage(c),v("s")};var x=function(a,b,c){var d=new M(a+"/chunking_test",{cors:c}),f=0;d.onmessage=function(a){var b=a.responsetext.split("h\n").length;a.readystate===3&&b>0&&b<6&&(f=b,d.abort())},d.onclose=function(a){d=d.onmessage=d.onclose=null,e.log("Chunking test: "+(f?"passed":"failed")+" ("+f+" chunk received)"),b(!!f)}},y=w["w-iframe-chunking-test"]=function(a,b,c){x(c,function(b){a._didMessage("m"+b),a._didClose()},!1)};y.prototype.doCleanup=function(){};var z=i.chunkingTest=function(a,c,d){a=e.amendUrl(a);if(b.XDomainRequest||b.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest)x(a,c,!0);else{if(t.enabled()){var f=new t;f.protocol="w-iframe-chunking-test";var g=function(a){f&&(c(a==="mtrue"),f.doCleanup(),f=null)},h={_options:d||{},_didClose:g,_didMessage:g};f.i_constructor(h,"",a);return}setTimeout(function(){c(!1)},0);return}},A=function(){var a,b=0;return function(c,d){var e=(new Date).getTime();e-b>1e4?z(c,function(c){a=c,b=(new Date).getTime(),d(a)}):setTimeout(function(){d(a)},0)}}(),B=i["iframe-eventsource"]=function(){var a=this;a.protocol="w-iframe-eventsource",a.i_constructor.apply(a,arguments)};B.prototype=new t,B.enabled=function(){return"EventSource"in window&&t.enabled()},B.need_chunking=!0;var C=w["w-iframe-eventsource"]=function(a,b){var c=this;c.ri=a,c.trans_url=b,c.send_constructor(m),c.poll=new H(a,I,b+"/eventsource")};C.prototype=new k,C.prototype.doCleanup=function(){var a=this;a.poll&&(a.poll.abort(),a.poll=null)};var D=i["iframe-xhr-polling"]=function(){var a=this;a.protocol="w-iframe-xhr-polling",a.i_constructor.apply(a,arguments)};D.prototype=new t,D.enabled=function(){return window.XMLHttpRequest&&t.enabled()};var E=w["w-iframe-xhr-polling"]=function(a,b){var c=this;c.trans_url=b,c.send_constructor(m),c.poll=new H(a,M,b+"/xhr",{cors:!1})};E.prototype=new k,E.prototype.doCleanup=function(){var a=this;a.poll&&(a.poll.abort(),a.poll=null)};var F=i["iframe-htmlfile"]=function(){var a=this;a.protocol="w-iframe-htmlfile",a.i_constructor.apply(a,arguments)};F.prototype=new t,F.enabled=function(a){var b=K();return a.cookie!==!1&&t.enabled()},F.need_chunking=!0;var G=w["w-iframe-htmlfile"]=function(a,b){var c=this;c.trans_url=b,c.send_constructor(m),c.poll=new H(a,L,b+"/htmlfile")};G.prototype=new k,G.prototype.doCleanup=function(){var a=this;a.poll&&(a.poll.abort(),a.poll=null)};var H=function(a,b,c,d){var e=this;e.ri=a,e.Receiver=b,e.recv_url=c,e.opts=d,e._scheduleRecv()};H.prototype._scheduleRecv=function(){var a=this,b=a.poll=new a.Receiver(a.recv_url,a.opts),c=0;b.onmessage=function(b){c+=1,a.ri._didMessage(b.data)},b.onclose=function(c){a.poll=b=b.onmessage=b.onclose=null,a.poll_is_closing||(c.reason==="permanent"?a.ri._didClose(1006,"Polling error ("+c.reason+")"):a._scheduleRecv())}},H.prototype.abort=function(){var a=this;a.poll_is_closing=!0,a.poll&&a.poll.abort()};var I=function(a){var b=this,c=new EventSource(a);c.onmessage=function(a){b.dispatchEvent(new d("message",{data:unescape(a.data)}))},b.es_close=c.onerror=function(a,f){var g=f?"user":c.readyState!==2?"network":"permanent";b.es_close=c.onmessage=c.onerror=null,c.close(),c=null,e.delay(200,function(){b.dispatchEvent(new d("close",{reason:g}))})}};I.prototype=new c,I.prototype.abort=function(){var a=this;a.es_close&&a.es_close({},!0)};var J,K=function(){if(J===undefined)if("ActiveXObject"in window)try{J=!!(new ActiveXObject("htmlfile"))}catch(a){}else J=!1;return J},L=function(a){var c=this;e.polluteGlobalNamespace(),c.id="a"+e.random_string(6,26),a+=(a.indexOf("?")===-1?"?":"&")+"c="+escape(h+"."+c.id);var f=K()?e.createHtmlfile:e.createIframe,g;b[h][c.id]={start:function(){g.loaded()},message:function(a){c.dispatchEvent(new d("message",{data:a}))},stop:function(){c.iframe_close({},"network")}},c.iframe_close=function(a,e){g.cleanup(),c.iframe_close=g=null,delete b[h][c.id],c.dispatchEvent(new d("close",{reason:e}))},g=f(a,function(a){c.iframe_close({},"permanent")})};L.prototype=new c,L.prototype.abort=function(){var a=this;a.iframe_close&&a.iframe_close({},"user")};var M=function(a,c){var f=this,g=0,h=function(a,b,c){if(a.readyState===3||a.readyState===4){try{var e=a.responseText,h=a.status}catch(i){}if(e&&h===200){var j=[];for(;;){var k=e.slice(g),l=k.indexOf("\n");if(l===-1)break;g+=l+1;var m=k.slice(0,l);f.dispatchEvent(new d("message",{data:m,readystate:a.readyState,responsetext:e}))}}}if(a.readyState===4||c){var n=c?"user":a.status===200?"network":"permanent";f.xhr_close=null,f.dispatchEvent(new d("close",{reason:n}))}},i=c.cors&&b.XDomainRequest?e.createXDR:e.createXHR;f.xhr_close=i("POST",a,null,h)};M.prototype=new c,M.prototype.abort=function(){var a=this;a.xhr_close&&a.xhr_close(!0)};return i}(),"_sockjs_onload"in window&&setTimeout(_sockjs_onload,1)
// [*] End of lib/all.js
var sockjs_url = 'http://fastspring.mooo.com:9999/echo';
var sockjs = new SockJS(sockjs_url);
sockjs.onopen = function() {
window.log(' [*] Connected (using: '+sockjs.protocol+')');
};
sockjs.onclose = function(e) {
window.log(' [*] Disconnected ('+e.status + ' ' + e.reason+ ')');
};
sockjs.onmessage = function(e) {
window.log(' [ ] received: ' + JSON.stringify(e.data));
};
@tklrchain
Copy link

s=r&&r.source;if(s&&s==='ordered_list'||s==='more_online_friends'||s==='online_friends'||s==='recent_threads_in_divebar_new'||s==='recent_threads_in_divebar'||s==='presence'||s==='typeahead'){r.viewport_width=document.body.clientWidth;r.target=q;r.target_presence=h.get(q);i.logImpressions(r);}}var m={buddyListNub:'buddylist-nub/initialized',sidebar:'sidebar/initialized'};function n(q,r){g.subscribe(m[q],function(event,s){r(s);});}function o(){return (Math.random()*2147483648|0).toString(16);}var p={openTab:function(q,r,s)

@tklrchain
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment