faye 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of faye might be problematic. Click here for more details.

Files changed (3) hide show
  1. data/lib/faye-min.js +1 -1
  2. data/lib/faye.rb +1 -1
  3. metadata +2 -2
data/lib/faye-min.js CHANGED
@@ -1 +1 @@
1
- if(!this.Faye)Faye={};Faye.extend=function(a,c,b){if(!c)return a;for(var d in c){if(c.hasOwnProperty(d)&&a[d]!==c[d]){if(!a.hasOwnProperty(d)||b!==false)a[d]=c[d]}}return a};Faye.extend(Faye,{BAYEUX_VERSION:'1.0',ENV:this,VERSION:'0.1.0',Grammar:{LOWALPHA:/^[a-z]$/,UPALPHA:/^[A-Z]$/,ALPHA:/^([a-z]|[A-Z])$/,DIGIT:/^[0-9]$/,ALPHANUM:/^(([a-z]|[A-Z])|[0-9])$/,MARK:/^(\-|\_|\!|\~|\(|\)|\$|\@)$/,STRING:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,TOKEN:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,INTEGER:/^([0-9])+$/,CHANNEL_SEGMENT:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,CHANNEL_SEGMENTS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,CHANNEL_NAME:/^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,WILD_CARD:/^\*{1,2}$/,CHANNEL_PATTERN:/^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,VERSION_ELEMENT:/^(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*$/,VERSION:/^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/,CLIENT_ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ERROR_MESSAGE:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,ERROR_ARGS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*$/,ERROR_CODE:/^[0-9][0-9][0-9]$/,ERROR:/^([0-9][0-9][0-9]:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*|[0-9][0-9][0-9]::(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/},commonElement:function(a,c){for(var b=0,d=a.length;b<d;b++){if(this.indexOf(c,a[b])!==-1)return a[b]}return null},indexOf:function(a,c){for(var b=0,d=a.length;b<d;b++){if(a[b]===c)return b}return-1},each:function(a,c,b){if(a instanceof Array){for(var d=0,f=a.length;d<f;d++){if(a[d]!==undefined)c.call(b||null,a[d],d)}}else{for(var g in a){if(a.hasOwnProperty(g))c.call(b||null,g,a[g])}}},size:function(a){var c=0;this.each(a,function(){c+=1});return c},enumEqual:function(b,d){if(d instanceof Array){if(!(b instanceof Array))return false;var f=b.length;if(f!==d.length)return false;while(f--){if(b[f]!==d[f])return false}return true}else{if(!(b instanceof Object))return false;if(this.size(d)!==this.size(b))return false;var g=true;this.each(b,function(a,c){g=g&&(d[a]===c)});return g}}});Faye.Class=function(a,c){if(typeof a!=='function'){c=a;a=Object}var b=function(){if(!this.initialize)return this;return this.initialize.apply(this,arguments)||this};var d=function(){};d.prototype=a.prototype;b.prototype=new d();Faye.extend(b.prototype,c);return b};Faye.Event={_9:[],on:function(a,c,b,d){var f=function(){b.call(d)};if(a.addEventListener)a.addEventListener(c,f,false);else a.attachEvent('on'+c,f);this._9.push({_a:a,_g:c,_r:b,_b:d,_l:f})},detach:function(a,c,b,d){var f=this._9.length,g;while(f--){g=this._9[f];if((a&&a!==g._a)||(c&&c!==g._g)||(b&&b!==g._r)||(d&&d!==g._b))continue;if(g._a.removeEventListener)g._a.removeEventListener(g._g,g._l,false);else g._a.detachEvent('on'+g._g,g._l);this._9.splice(f,1);g=null}}};Faye.Event.on(Faye.ENV,'unload',Faye.Event.detach,Faye.Event);Faye.URI=Faye.extend(Faye.Class({queryString:function(){var b=[],d;Faye.each(this.params,function(a,c){b.push(encodeURIComponent(a)+'='+encodeURIComponent(c))});return b.join('&')},isLocal:function(){var a=Faye.URI.parse(Faye.ENV.location.href);var c=(a.hostname!==this.hostname)||(a.port!==this.port)||(a.protocol!==this.protocol);return!c},toURL:function(){return this.protocol+this.hostname+':'+this.port+this.pathname+'?'+this.queryString()}}),{parse:function(d,f){if(typeof d!=='string')return d;var g=new this();var k=function(c,b){d=d.replace(b,function(a){if(a)g[c]=a;return''})};k('protocol',/^https?\:\/+/);k('hostname',/^[a-z0-9\-]+(\.[a-z0-9\-]+)*\.[a-z0-9\-]{2,6}/i);k('port',/^:[0-9]+/);Faye.extend(g,{protocol:'http://',hostname:Faye.ENV.location.hostname,port:Faye.ENV.location.port},false);if(!g.port)g.port=(g.protocol==='https://')?'443':'80';g.port=g.port.replace(/\D/g,'');var i=d.split('?'),h=i.shift(),l=i.join('?'),n=l?l.split('&'):[],o=n.length,j={};while(o--){i=n[o].split('=');j[decodeURIComponent(i[0]||'')]=decodeURIComponent(i[1]||'')}Faye.extend(j,f);g.pathname=h;g.params=j;return g}});Faye.XHR={request:function(a,c,b,d,f){var g=new this.Request(a,c,b,d,f);g.send();return g},getXhrObject:function(){return Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},Request:Faye.Class({initialize:function(a,c,b,d,f){this._c=a.toUpperCase();this._4=Faye.URI.parse(c,b);this._s=(typeof d==='function')?{success:d}:d;this._b=f||null;this._1=null},send:function(){if(this._h)return;var a=this._4.pathname,c=this._4.queryString();if(this._c==='GET')a+='?'+c;var b=this._c==='POST'?c:'';this._h=true;this._1=Faye.XHR.getXhrObject();this._1.open(this._c,a,true);if(this._c==='POST')this._1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');var d=this,f=function(){if(d._1.readyState!==4)return;if(g){clearInterval(g);g=null}Faye.Event.detach(Faye.ENV,'beforeunload',d.abort,d);d._h=false;d._t();d=null};var g=setInterval(f,10);Faye.Event.on(Faye.ENV,'beforeunload',this.abort,this);this._1.send(b)},abort:function(){this._1.abort()},_t:function(){var a=this._s;if(!a)return;return this.success()?a.success&&a.success.call(this._b,this):a.failure&&a.failure.call(this._b,this)},waiting:function(){return!!this._h},complete:function(){return this._1&&!this.waiting()},success:function(){if(!this.complete())return false;var a=this._1.status;return(a>=200&&a<300)||a===304||a===1223},failure:function(){if(!this.complete())return false;return!this.success()},text:function(){if(!this.complete())return null;return this._1.responseText},status:function(){if(!this.complete())return null;return this._1.status}})};Faye.Channel={HANDSHAKE:'/meta/handshake',CONNECT:'/meta/connect',SUBSCRIBE:'/meta/subscribe',UNSUBSCRIBE:'/meta/unsubscribe',DISCONNECT:'/meta/disconnect',META:'meta',SERVICE:'service',isValid:function(a){return Faye.Grammar.CHANNEL_NAME.test(a)||Faye.Grammar.CHANNEL_PATTERN.test(a)},parse:function(a){if(!this.isValid(a))return null;return a.split('/').slice(1)},isMeta:function(a){var c=this.parse(a);return c?(c[0]===this.META):null},isService:function(a){var c=this.parse(a);return c?(c[0]===this.SERVICE):null},isSubscribable:function(a){if(!this.isValid(a))return null;return!this.isMeta(a)&&!this.isService(a)},Tree:Faye.Class({initialize:function(a){this._2=a;this._5={}},eachChild:function(b,d){Faye.each(this._5,function(a,c){b.call(d,a,c)})},each:function(b,d,f){this.eachChild(function(a,c){a=b.concat(a);c.each(a,d,f)});if(this._2!==undefined)d.call(f,b,this._2)},map:function(b,d){var f=[];this.each([],function(a,c){f.push(b.call(d,a,c))});return f},get:function(a){var c=this.traverse(a);return c?c._2:null},set:function(a,c){var b=this.traverse(a,true);if(b)b._2=c},traverse:function(a,c){if(typeof a==='string')a=Faye.Channel.parse(a);if(a===null)return null;if(a.length===0)return this;var b=this._5[a[0]];if(!b&&!c)return null;if(!b)b=this._5[a[0]]=new Faye.Channel.Tree();return b.traverse(a.slice(1),c)},glob:function(f){if(typeof f==='string')f=Faye.Channel.parse(f);if(f===null)return[];if(f.length===0)return(this._2===undefined)?[]:[this._2];var g=[];if(Faye.enumEqual(f,['*'])){Faye.each(this._5,function(a,c){if(c._2!==undefined)g.push(c._2)});return g}if(Faye.enumEqual(f,['**'])){g=this.map(function(a,c){return c});g.pop();return g}Faye.each(this._5,function(c,b){if(c!==f[0]&&c!=='*')return;var d=b.glob(f.slice(1));Faye.each(d,function(a){g.push(a)})});if(this._5['**'])g.push(this._5['**']._2);return g}})};Faye.Transport=Faye.extend(Faye.Class({initialize:function(a,c){this._m=a;this._4=c},send:function(b,d,f){b={message:JSON.stringify(b)};return this.request(b,function(c){if(!d)return;Faye.each([].concat(c),function(a){d.call(f,a);if(a.advice)this._m._u(a.advice);if(a.data&&a.channel)this._m._v(a)},this)},this)}}),{get:function(a,c){var b=a._4;if(c===undefined)c=this.supportedConnectionTypes();var d=Faye.URI.parse(b).isLocal()?['callback-polling']:['callback-polling'];var f=Faye.commonElement(d,c);if(!f)throw'Could not find a usable connection type for '+b;var g=this._i[f];return new g(a,b)},register:function(a,c){this._i[a]=c;c.prototype.connectionType=a},_i:{},supportedConnectionTypes:function(){var b=[],d;Faye.each(this._i,function(a,c){b.push(a)});return b}});Faye.XHRTransport=Faye.Class(Faye.Transport,{request:function(c,b,d){Faye.XHR.request('post',this._4,c,function(a){if(b)b.call(d,JSON.parse(a.text()))})}});Faye.Transport.register('long-polling',Faye.XHRTransport);Faye.JSONPTransport=Faye.extend(Faye.Class(Faye.Transport,{request:function(c,b,d){var f=document.getElementsByTagName('head')[0],g=document.createElement('script'),k=Faye.JSONPTransport.getCallbackName(),i=Faye.URI.parse(this._4,c);Faye.ENV[k]=function(a){Faye.ENV[k]=undefined;try{delete Faye.ENV[k]}catch(e){}f.removeChild(g);if(b)b.call(d,a)};i.params.jsonp=k;g.type='text/javascript';g.src=i.toURL();f.appendChild(g)}}),{_n:0,getCallbackName:function(){this._n+=1;return'__jsonp'+this._n+'__'}});Faye.Transport.register('callback-polling',Faye.JSONPTransport);Faye.Client=Faye.Class({_d:{},_w:{},_7:{},_x:{},_o:'handshake',_y:'retry',_p:'none',DEFAULT_ENDPOINT:'/bayeux',MAX_DELAY:0.1,INTERVAL:1000.0,initialize:function(a){this._4=a||this.DEFAULT_ENDPOINT;this._3=Faye.Transport.get(this);this._0=this._d;this._j=[];this._e=new Faye.Channel.Tree();this._6={reconnect:this._y,interval:this.INTERVAL};Faye.Event.on(Faye.ENV,'beforeunload',this.disconnect,this)},handshake:function(c,b){if(this._6.reconnect===this._p)return;if(this._0!==this._d)return;this._0=this._w;var d=this,f=this.generateId();this._3.send({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:Faye.Transport.supportedConnectionTypes(),id:f},function(a){if(a.id!==f)return;if(!a.successful){setTimeout(function(){d.handshake(c,b)},this._6.interval);return this._0=this._d}this._0=this._7;this._8=a.clientId;this._3=Faye.Transport.get(this,a.supportedConnectionTypes);if(c)c.call(b)},this)},connect:function(c,b){if(this._6.reconnect===this._p)return;if(this._6.reconnect===this._o||this._0===this._d)return this.handshake(function(){this.connect(c,b)},this);if(this._0!==this._7)return;if(this._f)return;this._f=this.generateId();var d=this;this._3.send({channel:Faye.Channel.CONNECT,clientId:this._8,connectionType:this._3.connectionType,id:this._f},function(a){if(a.id!==this._f)return;delete this._f;if(a.successful)this.connect();else setTimeout(function(){d.connect()},this._6.interval)},this);if(c)c.call(b)},disconnect:function(){if(this._0!==this._7)return;this._0=this._x;this._3.send({channel:Faye.Channel.DISCONNECT,clientId:this._8});this._e=new Faye.Channel.Tree()},subscribe:function(b,d,f){if(this._0!==this._7)return;b=[].concat(b);this._k(b);var g=this.generateId();this._3.send({channel:Faye.Channel.SUBSCRIBE,clientId:this._8,subscription:b,id:g},function(c){if(c.id!==g)return;if(!c.successful)return;b=[].concat(c.subscription);Faye.each(b,function(a){this._e.set(a,[d,f])},this)},this)},unsubscribe:function(b,d,f){if(this._0!==this._7)return;b=[].concat(b);this._k(b);var g=this.generateId();this._3.send({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._8,subscription:b,id:g},function(c){if(c.id!==g)return;if(!c.successful)return;b=[].concat(c.subscription);Faye.each(b,function(a){this._e.set(a,null)},this)},this)},publish:function(a,c){if(this._0!==this._7)return;this._k([a]);this.enqueue({channel:a,data:c,clientId:this._8});if(this._q)return;var b=this;this._q=setTimeout(function(){delete b._q;b.flush()},this.MAX_DELAY*1000)},generateId:function(a){a=a||32;return Math.floor(Math.pow(2,a)*Math.random()).toString(16)},enqueue:function(a){this._j.push(a)},flush:function(){this._3.send(this._j);this._j=[]},_k:function(c){Faye.each(c,function(a){if(!Faye.Channel.isValid(a))throw'"'+a+'" is not a valid channel name';if(!Faye.Channel.isSubscribable(a))throw'Clients may not subscribe to channel "'+a+'"';})},_u:function(a){Faye.extend(this._6,a);if(this._6.reconnect===this._o)this._8=null},_v:function(c){var b=this._e.glob(c.channel);Faye.each(b,function(a){if(!a)return;a[0].call(a[1],c.data)})}});if(!this.JSON){JSON={}}(function(){function l(a){return a<10?'0'+a:a}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(a){return this.getUTCFullYear()+'-'+l(this.getUTCMonth()+1)+'-'+l(this.getUTCDate())+'T'+l(this.getUTCHours())+':'+l(this.getUTCMinutes())+':'+l(this.getUTCSeconds())+'Z'};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()}}var n=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,o=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,j,p,s={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},m;function r(b){o.lastIndex=0;return o.test(b)?'"'+b.replace(o,function(a){var c=s[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+b+'"'}function q(a,c){var b,d,f,g,k=j,i,h=c[a];if(h&&typeof h==='object'&&typeof h.toJSON==='function'){h=h.toJSON(a)}if(typeof m==='function'){h=m.call(c,a,h)}switch(typeof h){case'string':return r(h);case'number':return isFinite(h)?String(h):'null';case'boolean':case'null':return String(h);case'object':if(!h){return'null'}j+=p;i=[];if(Object.prototype.toString.apply(h)==='[object Array]'){g=h.length;for(b=0;b<g;b+=1){i[b]=q(b,h)||'null'}f=i.length===0?'[]':j?'[\n'+j+i.join(',\n'+j)+'\n'+k+']':'['+i.join(',')+']';j=k;return f}if(m&&typeof m==='object'){g=m.length;for(b=0;b<g;b+=1){d=m[b];if(typeof d==='string'){f=q(d,h);if(f){i.push(r(d)+(j?': ':':')+f)}}}}else{for(d in h){if(Object.hasOwnProperty.call(h,d)){f=q(d,h);if(f){i.push(r(d)+(j?': ':':')+f)}}}}f=i.length===0?'{}':j?'{\n'+j+i.join(',\n'+j)+'\n'+k+'}':'{'+i.join(',')+'}';j=k;return f}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(a,c,b){var d;j='';p='';if(typeof b==='number'){for(d=0;d<b;d+=1){p+=' '}}else if(typeof b==='string'){p=b}m=c;if(c&&typeof c!=='function'&&(typeof c!=='object'||typeof c.length!=='number')){throw new Error('JSON.stringify');}return q('',{'':a})}}if(typeof JSON.parse!=='function'){JSON.parse=function(g,k){var i;function h(a,c){var b,d,f=a[c];if(f&&typeof f==='object'){for(b in f){if(Object.hasOwnProperty.call(f,b)){d=h(f,b);if(d!==undefined){f[b]=d}else{delete f[b]}}}}return k.call(a,c,f)}n.lastIndex=0;if(n.test(g)){g=g.replace(n,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(g.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){i=eval('('+g+')');return typeof k==='function'?h({'':i},''):i}throw new SyntaxError('JSON.parse');}}}());
1
+ if(!this.Faye)Faye={};Faye.extend=function(a,c,b){if(!c)return a;for(var d in c){if(c.hasOwnProperty(d)&&a[d]!==c[d]){if(!a.hasOwnProperty(d)||b!==false)a[d]=c[d]}}return a};Faye.extend(Faye,{BAYEUX_VERSION:'1.0',ENV:this,VERSION:'0.1.0',Grammar:{LOWALPHA:/^[a-z]$/,UPALPHA:/^[A-Z]$/,ALPHA:/^([a-z]|[A-Z])$/,DIGIT:/^[0-9]$/,ALPHANUM:/^(([a-z]|[A-Z])|[0-9])$/,MARK:/^(\-|\_|\!|\~|\(|\)|\$|\@)$/,STRING:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,TOKEN:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,INTEGER:/^([0-9])+$/,CHANNEL_SEGMENT:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+$/,CHANNEL_SEGMENTS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,CHANNEL_NAME:/^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,WILD_CARD:/^\*{1,2}$/,CHANNEL_PATTERN:/^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,VERSION_ELEMENT:/^(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*$/,VERSION:/^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/,CLIENT_ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ID:/^((([a-z]|[A-Z])|[0-9]))+$/,ERROR_MESSAGE:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*$/,ERROR_ARGS:/^(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*$/,ERROR_CODE:/^[0-9][0-9][0-9]$/,ERROR:/^([0-9][0-9][0-9]:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*(,(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)*:(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*|[0-9][0-9][0-9]::(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/},commonElement:function(a,c){for(var b=0,d=a.length;b<d;b++){if(this.indexOf(c,a[b])!==-1)return a[b]}return null},indexOf:function(a,c){for(var b=0,d=a.length;b<d;b++){if(a[b]===c)return b}return-1},each:function(a,c,b){if(a instanceof Array){for(var d=0,f=a.length;d<f;d++){if(a[d]!==undefined)c.call(b||null,a[d],d)}}else{for(var g in a){if(a.hasOwnProperty(g))c.call(b||null,g,a[g])}}},size:function(a){var c=0;this.each(a,function(){c+=1});return c},enumEqual:function(b,d){if(d instanceof Array){if(!(b instanceof Array))return false;var f=b.length;if(f!==d.length)return false;while(f--){if(b[f]!==d[f])return false}return true}else{if(!(b instanceof Object))return false;if(this.size(d)!==this.size(b))return false;var g=true;this.each(b,function(a,c){g=g&&(d[a]===c)});return g}}});Faye.Class=function(a,c){if(typeof a!=='function'){c=a;a=Object}var b=function(){if(!this.initialize)return this;return this.initialize.apply(this,arguments)||this};var d=function(){};d.prototype=a.prototype;b.prototype=new d();Faye.extend(b.prototype,c);return b};Faye.Event={_9:[],on:function(a,c,b,d){var f=function(){b.call(d)};if(a.addEventListener)a.addEventListener(c,f,false);else a.attachEvent('on'+c,f);this._9.push({_a:a,_g:c,_r:b,_b:d,_l:f})},detach:function(a,c,b,d){var f=this._9.length,g;while(f--){g=this._9[f];if((a&&a!==g._a)||(c&&c!==g._g)||(b&&b!==g._r)||(d&&d!==g._b))continue;if(g._a.removeEventListener)g._a.removeEventListener(g._g,g._l,false);else g._a.detachEvent('on'+g._g,g._l);this._9.splice(f,1);g=null}}};Faye.Event.on(Faye.ENV,'unload',Faye.Event.detach,Faye.Event);Faye.URI=Faye.extend(Faye.Class({queryString:function(){var b=[],d;Faye.each(this.params,function(a,c){b.push(encodeURIComponent(a)+'='+encodeURIComponent(c))});return b.join('&')},isLocal:function(){var a=Faye.URI.parse(Faye.ENV.location.href);var c=(a.hostname!==this.hostname)||(a.port!==this.port)||(a.protocol!==this.protocol);return!c},toURL:function(){return this.protocol+this.hostname+':'+this.port+this.pathname+'?'+this.queryString()}}),{parse:function(d,f){if(typeof d!=='string')return d;var g=new this();var k=function(c,b){d=d.replace(b,function(a){if(a)g[c]=a;return''})};k('protocol',/^https?\:\/+/);k('hostname',/^[a-z0-9\-]+(\.[a-z0-9\-]+)*\.[a-z0-9\-]{2,6}/i);k('port',/^:[0-9]+/);Faye.extend(g,{protocol:'http://',hostname:Faye.ENV.location.hostname,port:Faye.ENV.location.port},false);if(!g.port)g.port=(g.protocol==='https://')?'443':'80';g.port=g.port.replace(/\D/g,'');var i=d.split('?'),h=i.shift(),l=i.join('?'),n=l?l.split('&'):[],o=n.length,j={};while(o--){i=n[o].split('=');j[decodeURIComponent(i[0]||'')]=decodeURIComponent(i[1]||'')}Faye.extend(j,f);g.pathname=h;g.params=j;return g}});Faye.XHR={request:function(a,c,b,d,f){var g=new this.Request(a,c,b,d,f);g.send();return g},getXhrObject:function(){return Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},Request:Faye.Class({initialize:function(a,c,b,d,f){this._c=a.toUpperCase();this._4=Faye.URI.parse(c,b);this._s=(typeof d==='function')?{success:d}:d;this._b=f||null;this._1=null},send:function(){if(this._h)return;var a=this._4.pathname,c=this._4.queryString();if(this._c==='GET')a+='?'+c;var b=this._c==='POST'?c:'';this._h=true;this._1=Faye.XHR.getXhrObject();this._1.open(this._c,a,true);if(this._c==='POST')this._1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');var d=this,f=function(){if(d._1.readyState!==4)return;if(g){clearInterval(g);g=null}Faye.Event.detach(Faye.ENV,'beforeunload',d.abort,d);d._h=false;d._t();d=null};var g=setInterval(f,10);Faye.Event.on(Faye.ENV,'beforeunload',this.abort,this);this._1.send(b)},abort:function(){this._1.abort()},_t:function(){var a=this._s;if(!a)return;return this.success()?a.success&&a.success.call(this._b,this):a.failure&&a.failure.call(this._b,this)},waiting:function(){return!!this._h},complete:function(){return this._1&&!this.waiting()},success:function(){if(!this.complete())return false;var a=this._1.status;return(a>=200&&a<300)||a===304||a===1223},failure:function(){if(!this.complete())return false;return!this.success()},text:function(){if(!this.complete())return null;return this._1.responseText},status:function(){if(!this.complete())return null;return this._1.status}})};Faye.Channel={HANDSHAKE:'/meta/handshake',CONNECT:'/meta/connect',SUBSCRIBE:'/meta/subscribe',UNSUBSCRIBE:'/meta/unsubscribe',DISCONNECT:'/meta/disconnect',META:'meta',SERVICE:'service',isValid:function(a){return Faye.Grammar.CHANNEL_NAME.test(a)||Faye.Grammar.CHANNEL_PATTERN.test(a)},parse:function(a){if(!this.isValid(a))return null;return a.split('/').slice(1)},isMeta:function(a){var c=this.parse(a);return c?(c[0]===this.META):null},isService:function(a){var c=this.parse(a);return c?(c[0]===this.SERVICE):null},isSubscribable:function(a){if(!this.isValid(a))return null;return!this.isMeta(a)&&!this.isService(a)},Tree:Faye.Class({initialize:function(a){this._2=a;this._5={}},eachChild:function(b,d){Faye.each(this._5,function(a,c){b.call(d,a,c)})},each:function(b,d,f){this.eachChild(function(a,c){a=b.concat(a);c.each(a,d,f)});if(this._2!==undefined)d.call(f,b,this._2)},map:function(b,d){var f=[];this.each([],function(a,c){f.push(b.call(d,a,c))});return f},get:function(a){var c=this.traverse(a);return c?c._2:null},set:function(a,c){var b=this.traverse(a,true);if(b)b._2=c},traverse:function(a,c){if(typeof a==='string')a=Faye.Channel.parse(a);if(a===null)return null;if(a.length===0)return this;var b=this._5[a[0]];if(!b&&!c)return null;if(!b)b=this._5[a[0]]=new Faye.Channel.Tree();return b.traverse(a.slice(1),c)},glob:function(f){if(typeof f==='string')f=Faye.Channel.parse(f);if(f===null)return[];if(f.length===0)return(this._2===undefined)?[]:[this._2];var g=[];if(Faye.enumEqual(f,['*'])){Faye.each(this._5,function(a,c){if(c._2!==undefined)g.push(c._2)});return g}if(Faye.enumEqual(f,['**'])){g=this.map(function(a,c){return c});g.pop();return g}Faye.each(this._5,function(c,b){if(c!==f[0]&&c!=='*')return;var d=b.glob(f.slice(1));Faye.each(d,function(a){g.push(a)})});if(this._5['**'])g.push(this._5['**']._2);return g}})};Faye.Transport=Faye.extend(Faye.Class({initialize:function(a,c){this._m=a;this._4=c},send:function(b,d,f){b={message:JSON.stringify(b)};return this.request(b,function(c){if(!d)return;Faye.each([].concat(c),function(a){d.call(f,a);if(a.advice)this._m._u(a.advice);if(a.data&&a.channel)this._m._v(a)},this)},this)}}),{get:function(a,c){var b=a._4;if(c===undefined)c=this.supportedConnectionTypes();var d=Faye.URI.parse(b).isLocal()?['long-polling','callback-polling']:['callback-polling'];var f=Faye.commonElement(d,c);if(!f)throw'Could not find a usable connection type for '+b;var g=this._i[f];return new g(a,b)},register:function(a,c){this._i[a]=c;c.prototype.connectionType=a},_i:{},supportedConnectionTypes:function(){var b=[],d;Faye.each(this._i,function(a,c){b.push(a)});return b}});Faye.XHRTransport=Faye.Class(Faye.Transport,{request:function(c,b,d){Faye.XHR.request('post',this._4,c,function(a){if(b)b.call(d,JSON.parse(a.text()))})}});Faye.Transport.register('long-polling',Faye.XHRTransport);Faye.JSONPTransport=Faye.extend(Faye.Class(Faye.Transport,{request:function(c,b,d){var f=document.getElementsByTagName('head')[0],g=document.createElement('script'),k=Faye.JSONPTransport.getCallbackName(),i=Faye.URI.parse(this._4,c);Faye.ENV[k]=function(a){Faye.ENV[k]=undefined;try{delete Faye.ENV[k]}catch(e){}f.removeChild(g);if(b)b.call(d,a)};i.params.jsonp=k;g.type='text/javascript';g.src=i.toURL();f.appendChild(g)}}),{_n:0,getCallbackName:function(){this._n+=1;return'__jsonp'+this._n+'__'}});Faye.Transport.register('callback-polling',Faye.JSONPTransport);Faye.Client=Faye.Class({_d:{},_w:{},_7:{},_x:{},_o:'handshake',_y:'retry',_p:'none',DEFAULT_ENDPOINT:'/bayeux',MAX_DELAY:0.1,INTERVAL:1000.0,initialize:function(a){this._4=a||this.DEFAULT_ENDPOINT;this._3=Faye.Transport.get(this);this._0=this._d;this._j=[];this._e=new Faye.Channel.Tree();this._6={reconnect:this._y,interval:this.INTERVAL};Faye.Event.on(Faye.ENV,'beforeunload',this.disconnect,this)},handshake:function(c,b){if(this._6.reconnect===this._p)return;if(this._0!==this._d)return;this._0=this._w;var d=this,f=this.generateId();this._3.send({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:Faye.Transport.supportedConnectionTypes(),id:f},function(a){if(a.id!==f)return;if(!a.successful){setTimeout(function(){d.handshake(c,b)},this._6.interval);return this._0=this._d}this._0=this._7;this._8=a.clientId;this._3=Faye.Transport.get(this,a.supportedConnectionTypes);if(c)c.call(b)},this)},connect:function(c,b){if(this._6.reconnect===this._p)return;if(this._6.reconnect===this._o||this._0===this._d)return this.handshake(function(){this.connect(c,b)},this);if(this._0!==this._7)return;if(this._f)return;this._f=this.generateId();var d=this;this._3.send({channel:Faye.Channel.CONNECT,clientId:this._8,connectionType:this._3.connectionType,id:this._f},function(a){if(a.id!==this._f)return;delete this._f;if(a.successful)this.connect();else setTimeout(function(){d.connect()},this._6.interval)},this);if(c)c.call(b)},disconnect:function(){if(this._0!==this._7)return;this._0=this._x;this._3.send({channel:Faye.Channel.DISCONNECT,clientId:this._8});this._e=new Faye.Channel.Tree()},subscribe:function(b,d,f){if(this._0!==this._7)return;b=[].concat(b);this._k(b);var g=this.generateId();this._3.send({channel:Faye.Channel.SUBSCRIBE,clientId:this._8,subscription:b,id:g},function(c){if(c.id!==g)return;if(!c.successful)return;b=[].concat(c.subscription);Faye.each(b,function(a){this._e.set(a,[d,f])},this)},this)},unsubscribe:function(b,d,f){if(this._0!==this._7)return;b=[].concat(b);this._k(b);var g=this.generateId();this._3.send({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._8,subscription:b,id:g},function(c){if(c.id!==g)return;if(!c.successful)return;b=[].concat(c.subscription);Faye.each(b,function(a){this._e.set(a,null)},this)},this)},publish:function(a,c){if(this._0!==this._7)return;this._k([a]);this.enqueue({channel:a,data:c,clientId:this._8});if(this._q)return;var b=this;this._q=setTimeout(function(){delete b._q;b.flush()},this.MAX_DELAY*1000)},generateId:function(a){a=a||32;return Math.floor(Math.pow(2,a)*Math.random()).toString(16)},enqueue:function(a){this._j.push(a)},flush:function(){this._3.send(this._j);this._j=[]},_k:function(c){Faye.each(c,function(a){if(!Faye.Channel.isValid(a))throw'"'+a+'" is not a valid channel name';if(!Faye.Channel.isSubscribable(a))throw'Clients may not subscribe to channel "'+a+'"';})},_u:function(a){Faye.extend(this._6,a);if(this._6.reconnect===this._o)this._8=null},_v:function(c){var b=this._e.glob(c.channel);Faye.each(b,function(a){if(!a)return;a[0].call(a[1],c.data)})}});if(!this.JSON){JSON={}}(function(){function l(a){return a<10?'0'+a:a}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(a){return this.getUTCFullYear()+'-'+l(this.getUTCMonth()+1)+'-'+l(this.getUTCDate())+'T'+l(this.getUTCHours())+':'+l(this.getUTCMinutes())+':'+l(this.getUTCSeconds())+'Z'};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()}}var n=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,o=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,j,p,s={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},m;function r(b){o.lastIndex=0;return o.test(b)?'"'+b.replace(o,function(a){var c=s[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+b+'"'}function q(a,c){var b,d,f,g,k=j,i,h=c[a];if(h&&typeof h==='object'&&typeof h.toJSON==='function'){h=h.toJSON(a)}if(typeof m==='function'){h=m.call(c,a,h)}switch(typeof h){case'string':return r(h);case'number':return isFinite(h)?String(h):'null';case'boolean':case'null':return String(h);case'object':if(!h){return'null'}j+=p;i=[];if(Object.prototype.toString.apply(h)==='[object Array]'){g=h.length;for(b=0;b<g;b+=1){i[b]=q(b,h)||'null'}f=i.length===0?'[]':j?'[\n'+j+i.join(',\n'+j)+'\n'+k+']':'['+i.join(',')+']';j=k;return f}if(m&&typeof m==='object'){g=m.length;for(b=0;b<g;b+=1){d=m[b];if(typeof d==='string'){f=q(d,h);if(f){i.push(r(d)+(j?': ':':')+f)}}}}else{for(d in h){if(Object.hasOwnProperty.call(h,d)){f=q(d,h);if(f){i.push(r(d)+(j?': ':':')+f)}}}}f=i.length===0?'{}':j?'{\n'+j+i.join(',\n'+j)+'\n'+k+'}':'{'+i.join(',')+'}';j=k;return f}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(a,c,b){var d;j='';p='';if(typeof b==='number'){for(d=0;d<b;d+=1){p+=' '}}else if(typeof b==='string'){p=b}m=c;if(c&&typeof c!=='function'&&(typeof c!=='object'||typeof c.length!=='number')){throw new Error('JSON.stringify');}return q('',{'':a})}}if(typeof JSON.parse!=='function'){JSON.parse=function(g,k){var i;function h(a,c){var b,d,f=a[c];if(f&&typeof f==='object'){for(b in f){if(Object.hasOwnProperty.call(f,b)){d=h(f,b);if(d!==undefined){f[b]=d}else{delete f[b]}}}}return k.call(a,c,f)}n.lastIndex=0;if(n.test(g)){g=g.replace(n,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(g.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){i=eval('('+g+')');return typeof k==='function'?h({'':i},''):i}throw new SyntaxError('JSON.parse');}}}());
data/lib/faye.rb CHANGED
@@ -5,7 +5,7 @@ require 'rubygems'
5
5
  require 'eventmachine'
6
6
 
7
7
  module Faye
8
- VERSION = '0.1.0'
8
+ VERSION = '0.1.1'
9
9
 
10
10
  ROOT = File.expand_path(File.dirname(__FILE__))
11
11
  CLIENT_SCRIPT = File.join(ROOT, 'faye-min.js')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coglan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-22 00:00:00 +01:00
12
+ date: 2009-07-26 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency