faye 0.5.2 → 0.5.3
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.
- data/History.txt +11 -0
- data/README.txt +19 -1
- data/lib/faye-browser-min.js +1 -1
- data/lib/faye.rb +1 -1
- data/lib/faye/adapters/rack_adapter.rb +13 -1
- data/lib/faye/protocol/channel.rb +33 -4
- data/lib/faye/protocol/server.rb +11 -10
- data/lib/thin_extensions.rb +2 -1
- data/test/test_channel.rb +8 -0
- data/test/test_server.rb +25 -0
- metadata +5 -15
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
=== 0.5.3 / 2010-10-21
|
2
|
+
|
3
|
+
* Improve detection of wss: requirement for secure WebSocket connections
|
4
|
+
* Correctly use default ports (80,443) for server-side HTTP connections
|
5
|
+
* Support legacy application/x-www-form-urlencoded POST requests
|
6
|
+
* Delete unused Channel objects that have all their subscribers removed
|
7
|
+
* Fix resend/reconnect logic in WebSocket transport
|
8
|
+
* Keep client script in memory rather than reading it from disk every time
|
9
|
+
* Prevent error-adding extensions from breaking the core protocol
|
10
|
+
|
11
|
+
|
1
12
|
=== 0.5.2 / 2010-08-12
|
2
13
|
|
3
14
|
* Support draft-76 of the WebSocket protocol (FF4, Chrome 6)
|
data/README.txt
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
= Faye
|
2
2
|
|
3
3
|
* http://faye.jcoglan.com
|
4
|
+
* http://groups.google.com/group/faye-users
|
4
5
|
* http://github.com/jcoglan/faye
|
5
6
|
|
6
7
|
Faye is a set of tools for dirt-simple publish-subscribe messaging
|
@@ -11,6 +12,16 @@ the server and in the browser.
|
|
11
12
|
See http://faye.jcoglan.com for documentation.
|
12
13
|
|
13
14
|
|
15
|
+
== Questions, issues, ideas
|
16
|
+
|
17
|
+
Please raise questions on the mailing list: http://groups.google.com/group/faye-users,
|
18
|
+
and feel free to announce and share ideas on Faye-related projects here
|
19
|
+
too. I'd appreciate it if we only use the GitHub issue tracker for bona
|
20
|
+
fide bugs; posting a question there will probably not get you a swift
|
21
|
+
answer since I treat it as a to-do list for whenever I have time to work
|
22
|
+
on this.
|
23
|
+
|
24
|
+
|
14
25
|
== Development
|
15
26
|
|
16
27
|
To hack on Faye, you'll need Ruby and Jake, which we use to build
|
@@ -28,8 +39,15 @@ to install:
|
|
28
39
|
|
29
40
|
== To-do
|
30
41
|
|
31
|
-
*
|
42
|
+
* Detect failed WebSocket connection and fall back to polling transports
|
43
|
+
* Add events to Subscriptions to notify the user when they are active
|
44
|
+
* Notify listeners of network drop-out (may be transport dependent)
|
45
|
+
* Provide better API for adding extensions to Rack middleware
|
46
|
+
* Add sugar for authentication extensions for protected subscribe + publish
|
47
|
+
* Optimise channel unsubscription -- currently O(N) where N = clients
|
48
|
+
* Expose the Timeouts module to help users expire clients at the app level
|
32
49
|
* Provide support for user-defined <tt>/service/*</tt> channels
|
50
|
+
* Let local server-side clients listen to <tt>/meta/*</tt> channels
|
33
51
|
* Allow server to scale to multiple nodes
|
34
52
|
|
35
53
|
|
data/lib/faye-browser-min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
if(!this.Faye)Faye={};Faye.extend=function(a,b,c){if(!b)return a;for(var d in b){if(!b.hasOwnProperty(d))continue;if(a.hasOwnProperty(d)&&c===false)continue;if(a[d]!==b[d])a[d]=b[d]}return a};Faye.extend(Faye,{VERSION:'0.5.2',BAYEUX_VERSION:'1.0',ID_LENGTH:128,JSONP_CALLBACK:'jsonpcallback',CONNECTION_TYPES:['long-polling','callback-polling','websocket'],MANDATORY_CONNECTION_TYPES:['long-polling','callback-polling','in-process'],ENV:(function(){return this})(),random:function(a){a=a||this.ID_LENGTH;if(a>32){var b=Math.ceil(a/32),c='';while(b--)c+=this.random(32);return c}var d=Math.pow(2,a);return Math.floor(Math.random()*d).toString(36)},commonElement:function(a,b){for(var c=0,d=a.length;c<d;c++){if(this.indexOf(b,a[c])!==-1)return a[c]}return null},indexOf:function(a,b){for(var c=0,d=a.length;c<d;c++){if(a[c]===b)return c}return-1},each:function(a,b,c){if(a instanceof Array){for(var d=0,f=a.length;d<f;d++){if(a[d]!==undefined)b.call(c||null,a[d],d)}}else{for(var g in a){if(a.hasOwnProperty(g))b.call(c||null,g,a[g])}}},map:function(a,b,c){var d=[];this.each(a,function(){d.push(b.apply(c||null,arguments))});return d},filter:function(a,b,c){var d=[];this.each(a,function(){if(b.apply(c,arguments))d.push(arguments[0])});return d},size:function(a){var b=0;this.each(a,function(){b+=1});return b},enumEqual:function(c,d){if(d instanceof Array){if(!(c instanceof Array))return false;var f=c.length;if(f!==d.length)return false;while(f--){if(c[f]!==d[f])return false}return true}else{if(!(c instanceof Object))return false;if(this.size(d)!==this.size(c))return false;var g=true;this.each(c,function(a,b){g=g&&(d[a]===b)});return g}},toJSON:function(a){if(this.stringify)return this.stringify(a,function(key,value){return(this[key]instanceof Array)?this[key]:value});return JSON.stringify(a)},timestamp:function(){var b=new Date(),c=b.getFullYear(),d=b.getMonth()+1,f=b.getDate(),g=b.getHours(),h=b.getMinutes(),j=b.getSeconds();var i=function(a){return a<10?'0'+a:String(a)};return i(c)+'-'+i(d)+'-'+i(f)+' '+i(g)+':'+i(h)+':'+i(j)}});Faye.Class=function(a,b){if(typeof a!=='function'){b=a;a=Object}var c=function(){if(!this.initialize)return this;return this.initialize.apply(this,arguments)||this};var d=function(){};d.prototype=a.prototype;c.prototype=new d();Faye.extend(c.prototype,b);return c};Faye.Namespace=Faye.Class({initialize:function(){this._u={}},generate:function(){var a=Faye.random();while(this._u.hasOwnProperty(a))a=Faye.random();return this._u[a]=a}});Faye.Deferrable={callback:function(a,b){if(!a)return;if(this._B==='succeeded')return a.apply(b,this._v);this._9=this._9||[];this._9.push([a,b])},setDeferredStatus:function(){var b=Array.prototype.slice.call(arguments),c=b.shift();this._B=c;this._v=b;if(c!=='succeeded')return;if(!this._9)return;Faye.each(this._9,function(a){a[0].apply(a[1],this._v)},this);this._9=[]}};Faye.Publisher={countSubscribers:function(a){if(!this._2||!this._2[a])return 0;return this._2[a].length},addSubscriber:function(a,b,c){this._2=this._2||{};var d=this._2[a]=this._2[a]||[];d.push([b,c])},removeSubscriber:function(a,b,c){if(!this._2||!this._2[a])return;var d=this._2[a],f=d.length;while(f--){if(b&&d[f][0]!==b)continue;if(c&&d[f][1]!==c)continue;d.splice(f,1)}},publishEvent:function(){var b=Array.prototype.slice.call(arguments),c=b.shift();if(!this._2||!this._2[c])return;Faye.each(this._2[c],function(a){a[0].apply(a[1],b)})}};Faye.Timeouts={addTimeout:function(a,b,c,d){this._6=this._6||{};if(this._6.hasOwnProperty(a))return;var f=this;this._6[a]=setTimeout(function(){delete f._6[a];c.call(d)},1000*b)},removeTimeout:function(a){this._6=this._6||{};var b=this._6[a];if(!b)return;clearTimeout(b);delete this._6[a]}};Faye.Logging={LOG_LEVELS:{error:3,warn:2,info:1,debug:0},logLevel:'error',log:function(a,b){if(!Faye.logger)return;var c=Faye.Logging.LOG_LEVELS;if(c[Faye.Logging.logLevel]>c[b])return;var a=Array.prototype.slice.apply(a),d=' ['+b.toUpperCase()+'] [Faye',f=null,g=a.shift().replace(/\?/g,function(){try{return Faye.toJSON(a.shift())}catch(e){return'[Object]'}});for(var h in Faye){if(f)continue;if(typeof Faye[h]!=='function')continue;if(this instanceof Faye[h])f=h}if(f)d+='.'+f;d+='] ';Faye.logger(Faye.timestamp()+d+g)}};Faye.each(Faye.Logging.LOG_LEVELS,function(a,b){Faye.Logging[a]=function(){this.log(arguments,a)}});Faye.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])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/};Faye.Extensible={addExtension:function(a){this._7=this._7||[];this._7.push(a);if(a.added)a.added()},removeExtension:function(a){if(!this._7)return;var b=this._7.length;while(b--){if(this._7[b]!==a)continue;this._7.splice(b,1);if(a.removed)a.removed()}},pipeThroughExtensions:function(c,d,f,g){if(!this._7)return f.call(g,d);var h=this._7.slice();var j=function(a){if(!a)return f.call(g,a);var b=h.shift();if(!b)return f.call(g,a);if(b[c])b[c](a,j);else j(a)};j(d)}};Faye.Channel=Faye.Class({initialize:function(a){this.id=this.name=a},push:function(a){this.publishEvent('message',a)}});Faye.extend(Faye.Channel.prototype,Faye.Publisher);Faye.extend(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 b=this.parse(a);return b?(b[0]===this.META):null},isService:function(a){var b=this.parse(a);return b?(b[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._4=a;this._a={}},eachChild:function(c,d){Faye.each(this._a,function(a,b){c.call(d,a,b)})},each:function(c,d,f){this.eachChild(function(a,b){a=c.concat(a);b.each(a,d,f)});if(this._4!==undefined)d.call(f,c,this._4)},getKeys:function(){return this.map(function(a,b){return'/'+a.join('/')})},map:function(c,d){var f=[];this.each([],function(a,b){f.push(c.call(d,a,b))});return f},get:function(a){var b=this.traverse(a);return b?b._4:null},set:function(a,b){var c=this.traverse(a,true);if(c)c._4=b},traverse:function(a,b){if(typeof a==='string')a=Faye.Channel.parse(a);if(a===null)return null;if(a.length===0)return this;var c=this._a[a[0]];if(!c&&!b)return null;if(!c)c=this._a[a[0]]=new Faye.Channel.Tree();return c.traverse(a.slice(1),b)},findOrCreate:function(a){var b=this.get(a);if(b)return b;b=new Faye.Channel(a);this.set(a,b);return b},glob:function(f){if(typeof f==='string')f=Faye.Channel.parse(f);if(f===null)return[];if(f.length===0)return(this._4===undefined)?[]:[this._4];var g=[];if(Faye.enumEqual(f,['*'])){Faye.each(this._a,function(a,b){if(b._4!==undefined)g.push(b._4)});return g}if(Faye.enumEqual(f,['**'])){g=this.map(function(a,b){return b});if(this._4!==undefined)g.pop();return g}Faye.each(this._a,function(b,c){if(b!==f[0]&&b!=='*')return;var d=c.glob(f.slice(1));Faye.each(d,function(a){g.push(a)})});if(this._a['**'])g.push(this._a['**']._4);return g},subscribe:function(c,d,f){if(!d)return;Faye.each(c,function(a){var b=this.findOrCreate(a);b.addSubscriber('message',d,f)},this)},unsubscribe:function(a,b,c){var d=this.get(a);if(!d)return false;d.removeSubscriber('message',b,c);return d.countSubscribers('message')===0},distributeMessage:function(b){var c=this.glob(b.channel);Faye.each(c,function(a){a.publishEvent('message',b.data)})}})});Faye.Subscription=Faye.Class({initialize:function(a,b,c,d){this._c=a;this._b=b;this._m=c;this._d=d;this._w=false},cancel:function(){if(this._w)return;this._c.unsubscribe(this._b,this._m,this._d);this._w=true},unsubscribe:function(){this.cancel()}});Faye.Client=Faye.Class({UNCONNECTED:1,CONNECTING:2,CONNECTED:3,DISCONNECTED:4,HANDSHAKE:'handshake',RETRY:'retry',NONE:'none',CONNECTION_TIMEOUT:60.0,DEFAULT_ENDPOINT:'/bayeux',MAX_DELAY:0.001,INTERVAL:0.0,initialize:function(a,b){this.info('New client created for ?',a);this._3=a||this.DEFAULT_ENDPOINT;this._x=b||{};this._f=Faye.Transport.get(this,Faye.MANDATORY_CONNECTION_TYPES);this._1=this.UNCONNECTED;this._h=[];this._b=new Faye.Channel.Tree();this._C=new Faye.Namespace();this._n={};this._8={reconnect:this.RETRY,interval:1000*(this._x.interval||this.INTERVAL),timeout:1000*(this._x.timeout||this.CONNECTION_TIMEOUT)};if(Faye.Event)Faye.Event.on(Faye.ENV,'beforeunload',this.disconnect,this)},handshake:function(b,c){if(this._8.reconnect===this.NONE)return;if(this._1!==this.UNCONNECTED)return;this._1=this.CONNECTING;var d=this;this.info('Initiating handshake with ?',this._3);this._e({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:[this._f.connectionType]},function(a){if(a.successful){this._1=this.CONNECTED;this._0=a.clientId;this._f=Faye.Transport.get(this,a.supportedConnectionTypes);this.info('Handshake successful: ?',this._0);this.subscribe(this._b.getKeys());if(b)b.call(c)}else{this.info('Handshake unsuccessful');setTimeout(function(){d.handshake(b,c)},this._8.interval);this._1=this.UNCONNECTED}},this)},connect:function(a,b){if(this._8.reconnect===this.NONE)return;if(this._1===this.DISCONNECTED)return;if(this._1===this.UNCONNECTED)return this.handshake(function(){this.connect(a,b)},this);this.callback(a,b);if(this._1!==this.CONNECTED)return;this.info('Calling deferred actions for ?',this._0);this.setDeferredStatus('succeeded');this.setDeferredStatus('deferred');if(this._o)return;this._o=true;this.info('Initiating connection for ?',this._0);this._e({channel:Faye.Channel.CONNECT,clientId:this._0,connectionType:this._f.connectionType},this._y,this)},disconnect:function(){if(this._1!==this.CONNECTED)return;this._1=this.DISCONNECTED;this.info('Disconnecting ?',this._0);this._e({channel:Faye.Channel.DISCONNECT,clientId:this._0});this.info('Clearing channel listeners for ?',this._0);this._b=new Faye.Channel.Tree()},subscribe:function(c,d,f){if(c instanceof Array)return Faye.each(c,function(channel){this.subscribe(channel,d,f)},this);this._p(c);this.connect(function(){this.info('Client ? attempting to subscribe to ?',this._0,c);this._e({channel:Faye.Channel.SUBSCRIBE,clientId:this._0,subscription:c},function(a){if(!a.successful)return;var b=[].concat(a.subscription);this.info('Subscription acknowledged for ? to ?',this._0,b);this._b.subscribe(b,d,f)},this)},this);return new Faye.Subscription(this,c,d,f)},unsubscribe:function(c,d,f){if(c instanceof Array)return Faye.each(c,function(channel){this.unsubscribe(channel,d,f)},this);this._p(c);var g=this._b.unsubscribe(c,d,f);if(!g)return;this.connect(function(){this.info('Client ? attempting to unsubscribe from ?',this._0,c);this._e({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._0,subscription:c},function(a){if(!a.successful)return;var b=[].concat(a.subscription);this.info('Unsubscription acknowledged for ? from ?',this._0,b)},this)},this)},publish:function(a,b){this._p(a);this.connect(function(){this.info('Client ? queueing published message to ?: ?',this._0,a,b);this._e({channel:a,data:b,clientId:this._0})},this)},receiveMessage:function(c){this.pipeThroughExtensions('incoming',c,function(a){if(!a)return;if(a.advice)this._D(a.advice);var b=this._n[a.id];if(b){delete this._n[a.id];b[0].call(b[1],a)}this._E(a)},this)},_D:function(a){Faye.extend(this._8,a);if(this._8.reconnect===this.HANDSHAKE&&this._1!==this.DISCONNECTED){this._1=this.UNCONNECTED;this._0=null;this._y()}},_E:function(a){if(!a.channel||!a.data)return;this.info('Client ? calling listeners for ? with ?',this._0,a.channel,a.data);this._b.distributeMessage(a)},_F:function(){if(!this._o)return;this._o=null;this.info('Closed connection for ?',this._0)},_y:function(){this._F();var a=this;setTimeout(function(){a.connect()},this._8.interval)},_e:function(b,c,d){b.id=this._C.generate();if(c)this._n[b.id]=[c,d];this.pipeThroughExtensions('outgoing',b,function(a){if(!a)return;if(a.channel===Faye.Channel.HANDSHAKE)return this._f.send(a,this._8.timeout/1000);this._h.push(a);if(a.channel===Faye.Channel.CONNECT)this._q=a;this.addTimeout('publish',this.MAX_DELAY,this._G,this)},this)},_G:function(){this.removeTimeout('publish');if(this._h.length>1&&this._q)this._q.advice={timeout:0};this._q=null;this._f.send(this._h,this._8.timeout/1000);this._h=[]},_p: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+'"';}});Faye.extend(Faye.Client.prototype,Faye.Deferrable);Faye.extend(Faye.Client.prototype,Faye.Timeouts);Faye.extend(Faye.Client.prototype,Faye.Logging);Faye.extend(Faye.Client.prototype,Faye.Extensible);Faye.Transport=Faye.extend(Faye.Class({initialize:function(a,b){this.debug('Created new ? transport for ?',this.connectionType,b);this._c=a;this._3=b},send:function(a,b){a=[].concat(a);this.debug('Client ? sending message to ?: ?',this._c._0,this._3,a);return this.request(a,b)},receive:function(a){this.debug('Client ? received from ?: ?',this._c._0,this._3,a);Faye.each(a,this._c.receiveMessage,this._c)},retry:function(a,b){var c=this;return function(){setTimeout(function(){c.request(a,2*b)},1000*b)}}}),{get:function(d,f){var g=d._3;if(f===undefined)f=this.supportedConnectionTypes();var h=null;Faye.each(this._r,function(a){var b=a[0],c=a[1];if(Faye.indexOf(f,b)<0)return;if(h)return;if(c.isUsable(g))h=c});if(!h)throw'Could not find a usable connection type for '+g;return new h(d,g)},register:function(a,b){this._r.push([a,b]);b.prototype.connectionType=a},_r:[],supportedConnectionTypes:function(){return Faye.map(this._r,function(a){return a[0]})}});Faye.extend(Faye.Transport.prototype,Faye.Logging);Faye.Event={_i:[],on:function(a,b,c,d){var f=function(){c.call(d)};if(a.addEventListener)a.addEventListener(b,f,false);else a.attachEvent('on'+b,f);this._i.push({_j:a,_s:b,_m:c,_d:d,_z:f})},detach:function(a,b,c,d){var f=this._i.length,g;while(f--){g=this._i[f];if((a&&a!==g._j)||(b&&b!==g._s)||(c&&c!==g._m)||(d&&d!==g._d))continue;if(g._j.removeEventListener)g._j.removeEventListener(g._s,g._z,false);else g._j.detachEvent('on'+g._s,g._z);this._i.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 c=[],d;Faye.each(this.params,function(a,b){c.push(encodeURIComponent(a)+'='+encodeURIComponent(b))});return c.join('&')},isLocal:function(){var a=Faye.URI.parse(Faye.ENV.location.href);var b=(a.hostname!==this.hostname)||(a.port!==this.port)||(a.protocol!==this.protocol);return!b},toURL:function(){var a=this.queryString();return this.protocol+this.hostname+':'+this.port+this.pathname+(a?'?'+a:'')}}),{parse:function(d,f){if(typeof d!=='string')return d;var g=new this();var h=function(b,c){d=d.replace(c,function(a){if(a)g[b]=a;return''})};h('protocol',/^https?\:\/+/);h('hostname',/^[^\/\:]+/);h('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 j=d.split('?'),i=j.shift(),l=j.join('?'),n=l?l.split('&'):[],o=n.length,k={};while(o--){j=n[o].split('=');k[decodeURIComponent(j[0]||'')]=decodeURIComponent(j[1]||'')}if(typeof f==='object')Faye.extend(k,f);g.pathname=i;g.params=k;return g}});Faye.XHR={request:function(a,b,c,d,f){var g=new this.Request(a,b,c,d,f);g.send();return g},getXhrObject:function(){return Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},Request:Faye.Class({initialize:function(a,b,c,d,f){this._k=a.toUpperCase();this._3=Faye.URI.parse(b,c);this._H=(typeof c==='string')?c:null;this._9=(typeof d==='function')?{success:d}:d;this._d=f||null;this._5=null},send:function(){if(this._t)return;var a=this._3.pathname,b=this._3.queryString();if(this._k==='GET')a+='?'+b;var c=(this._k==='POST')?(this._H||b):'';this._t=true;this._5=Faye.XHR.getXhrObject();this._5.open(this._k,a,true);if(this._k==='POST')this._5.setRequestHeader('Content-Type','application/json');var d=this,f=function(){if(d._5.readyState!==4)return;if(g){clearInterval(g);g=null}Faye.Event.detach(Faye.ENV,'beforeunload',d.abort,d);d._t=false;d._I();d=null};var g=setInterval(f,10);Faye.Event.on(Faye.ENV,'beforeunload',this.abort,this);this._5.send(c)},abort:function(){this._5.abort()},_I:function(){var a=this._9;if(!a)return;return this.success()?a.success&&a.success.call(this._d,this):a.failure&&a.failure.call(this._d,this)},waiting:function(){return!!this._t},complete:function(){return this._5&&!this.waiting()},success:function(){if(!this.complete())return false;var a=this._5.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._5.responseText},status:function(){if(!this.complete())return null;return this._5.status}})};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,k,p,s={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},m;function r(c){o.lastIndex=0;return o.test(c)?'"'+c.replace(o,function(a){var b=s[a];return typeof b==='string'?b:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+c+'"'}function q(a,b){var c,d,f,g,h=k,j,i=b[a];if(i&&typeof i==='object'&&typeof i.toJSON==='function'){i=i.toJSON(a)}if(typeof m==='function'){i=m.call(b,a,i)}switch(typeof i){case'string':return r(i);case'number':return isFinite(i)?String(i):'null';case'boolean':case'null':return String(i);case'object':if(!i){return'null'}k+=p;j=[];if(Object.prototype.toString.apply(i)==='[object Array]'){g=i.length;for(c=0;c<g;c+=1){j[c]=q(c,i)||'null'}f=j.length===0?'[]':k?'[\n'+k+j.join(',\n'+k)+'\n'+h+']':'['+j.join(',')+']';k=h;return f}if(m&&typeof m==='object'){g=m.length;for(c=0;c<g;c+=1){d=m[c];if(typeof d==='string'){f=q(d,i);if(f){j.push(r(d)+(k?': ':':')+f)}}}}else{for(d in i){if(Object.hasOwnProperty.call(i,d)){f=q(d,i);if(f){j.push(r(d)+(k?': ':':')+f)}}}}f=j.length===0?'{}':k?'{\n'+k+j.join(',\n'+k)+'\n'+h+'}':'{'+j.join(',')+'}';k=h;return f}}Faye.stringify=function(a,b,c){var d;k='';p='';if(typeof c==='number'){for(d=0;d<c;d+=1){p+=' '}}else if(typeof c==='string'){p=c}m=b;if(b&&typeof b!=='function'&&(typeof b!=='object'||typeof b.length!=='number')){throw new Error('JSON.stringify');}return q('',{'':a})};if(typeof JSON.stringify!=='function'){JSON.stringify=Faye.stringify}if(typeof JSON.parse!=='function'){JSON.parse=function(g,h){var j;function i(a,b){var c,d,f=a[b];if(f&&typeof f==='object'){for(c in f){if(Object.hasOwnProperty.call(f,c)){d=i(f,c);if(d!==undefined){f[c]=d}else{delete f[c]}}}}return h.call(a,b,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,''))){j=eval('('+g+')');return typeof h==='function'?i({'':j},''):j}throw new SyntaxError('JSON.parse');}}}());Faye.WebSocketTransport=Faye.Class(Faye.Transport,{UNCONNECTED:1,CONNECTING:2,CONNECTED:3,request:function(b,c){this._l=this._l||{};Faye.each(b,function(a){this._l[a.id]=a},this);this.withSocket(function(a){a.send(Faye.toJSON(b))})},withSocket:function(d,f){this.callback(d,f);this._1=this._1||this.UNCONNECTED;if(this._1!==this.UNCONNECTED)return;this._1=this.CONNECTING;var g=Faye.URI.parse(this._3).toURL().replace(/^https?/ig,'ws');this._g=new WebSocket(g);var h=this;this._g.onopen=function(){h._1=h.CONNECTED;h.setDeferredStatus('succeeded',h._g)};this._g.onmessage=function(b){var c=[].concat(JSON.parse(b.data));Faye.each(c,function(a){delete h._l[a.id]});h.receive(c)};this._g.onclose=function(){h.setDeferredStatus('deferred');h._1=h.UNCONNECTED;h._g=null;h.resend()}},resend:function(){var c=Faye.map(this._l,function(a,b){return b});this.request(c)}});Faye.extend(Faye.WebSocketTransport.prototype,Faye.Deferrable);Faye.WebSocketTransport.isUsable=function(a){return!!Faye.ENV.WebSocket};Faye.Transport.register('websocket',Faye.WebSocketTransport);Faye.XHRTransport=Faye.Class(Faye.Transport,{request:function(b,c){var d=this.retry(b,c);Faye.XHR.request('post',this._3,Faye.toJSON(b),{success:function(a){try{this.receive(JSON.parse(a.text()))}catch(e){d()}},failure:d},this)}});Faye.XHRTransport.isUsable=function(a){return Faye.URI.parse(a).isLocal()};Faye.Transport.register('long-polling',Faye.XHRTransport);Faye.JSONPTransport=Faye.extend(Faye.Class(Faye.Transport,{request:function(b,c){var d={message:Faye.toJSON(b)},f=document.getElementsByTagName('head')[0],g=document.createElement('script'),h=Faye.JSONPTransport.getCallbackName(),j=Faye.URI.parse(this._3,d),i=this;var l=function(){if(!g.parentNode)return false;g.parentNode.removeChild(g);return true};Faye.ENV[h]=function(a){Faye.ENV[h]=undefined;try{delete Faye.ENV[h]}catch(e){}if(!l())return;i.receive(a)};setTimeout(function(){if(!Faye.ENV[h])return;l();i.request(b,2*c)},1000*c);j.params.jsonp=h;g.type='text/javascript';g.src=j.toURL();f.appendChild(g)}}),{_A:0,getCallbackName:function(){this._A+=1;return'__jsonp'+this._A+'__'}});Faye.JSONPTransport.isUsable=function(a){return true};Faye.Transport.register('callback-polling',Faye.JSONPTransport);
|
1
|
+
if(!this.Faye)Faye={};Faye.extend=function(a,b,c){if(!b)return a;for(var d in b){if(!b.hasOwnProperty(d))continue;if(a.hasOwnProperty(d)&&c===false)continue;if(a[d]!==b[d])a[d]=b[d]}return a};Faye.extend(Faye,{VERSION:'0.5.3',BAYEUX_VERSION:'1.0',ID_LENGTH:128,JSONP_CALLBACK:'jsonpcallback',CONNECTION_TYPES:['long-polling','callback-polling','websocket'],MANDATORY_CONNECTION_TYPES:['long-polling','callback-polling','in-process'],ENV:(function(){return this})(),random:function(a){a=a||this.ID_LENGTH;if(a>32){var b=Math.ceil(a/32),c='';while(b--)c+=this.random(32);return c}var d=Math.pow(2,a);return Math.floor(Math.random()*d).toString(36)},commonElement:function(a,b){for(var c=0,d=a.length;c<d;c++){if(this.indexOf(b,a[c])!==-1)return a[c]}return null},indexOf:function(a,b){for(var c=0,d=a.length;c<d;c++){if(a[c]===b)return c}return-1},each:function(a,b,c){if(a instanceof Array){for(var d=0,f=a.length;d<f;d++){if(a[d]!==undefined)b.call(c||null,a[d],d)}}else{for(var g in a){if(a.hasOwnProperty(g))b.call(c||null,g,a[g])}}},map:function(a,b,c){var d=[];this.each(a,function(){d.push(b.apply(c||null,arguments))});return d},filter:function(a,b,c){var d=[];this.each(a,function(){if(b.apply(c,arguments))d.push(arguments[0])});return d},size:function(a){var b=0;this.each(a,function(){b+=1});return b},enumEqual:function(c,d){if(d instanceof Array){if(!(c instanceof Array))return false;var f=c.length;if(f!==d.length)return false;while(f--){if(c[f]!==d[f])return false}return true}else{if(!(c instanceof Object))return false;if(this.size(d)!==this.size(c))return false;var g=true;this.each(c,function(a,b){g=g&&(d[a]===b)});return g}},toJSON:function(a){if(this.stringify)return this.stringify(a,function(key,value){return(this[key]instanceof Array)?this[key]:value});return JSON.stringify(a)},timestamp:function(){var b=new Date(),c=b.getFullYear(),d=b.getMonth()+1,f=b.getDate(),g=b.getHours(),i=b.getMinutes(),j=b.getSeconds();var h=function(a){return a<10?'0'+a:String(a)};return h(c)+'-'+h(d)+'-'+h(f)+' '+h(g)+':'+h(i)+':'+h(j)}});Faye.Class=function(a,b){if(typeof a!=='function'){b=a;a=Object}var c=function(){if(!this.initialize)return this;return this.initialize.apply(this,arguments)||this};var d=function(){};d.prototype=a.prototype;c.prototype=new d();Faye.extend(c.prototype,b);return c};Faye.Namespace=Faye.Class({initialize:function(){this._v={}},generate:function(){var a=Faye.random();while(this._v.hasOwnProperty(a))a=Faye.random();return this._v[a]=a}});Faye.Deferrable={callback:function(a,b){if(!a)return;if(this._C==='succeeded')return a.apply(b,this._w);this._a=this._a||[];this._a.push([a,b])},setDeferredStatus:function(){var b=Array.prototype.slice.call(arguments),c=b.shift();this._C=c;this._w=b;if(c!=='succeeded')return;if(!this._a)return;Faye.each(this._a,function(a){a[0].apply(a[1],this._w)},this);this._a=[]}};Faye.Publisher={countSubscribers:function(a){if(!this._2||!this._2[a])return 0;return this._2[a].length},addSubscriber:function(a,b,c){this._2=this._2||{};var d=this._2[a]=this._2[a]||[];d.push([b,c])},removeSubscriber:function(a,b,c){if(!this._2||!this._2[a])return;var d=this._2[a],f=d.length;while(f--){if(b&&d[f][0]!==b)continue;if(c&&d[f][1]!==c)continue;d.splice(f,1)}},publishEvent:function(){var b=Array.prototype.slice.call(arguments),c=b.shift();if(!this._2||!this._2[c])return;Faye.each(this._2[c],function(a){a[0].apply(a[1],b)})}};Faye.Timeouts={addTimeout:function(a,b,c,d){this._7=this._7||{};if(this._7.hasOwnProperty(a))return;var f=this;this._7[a]=setTimeout(function(){delete f._7[a];c.call(d)},1000*b)},removeTimeout:function(a){this._7=this._7||{};var b=this._7[a];if(!b)return;clearTimeout(b);delete this._7[a]}};Faye.Logging={LOG_LEVELS:{error:3,warn:2,info:1,debug:0},logLevel:'error',log:function(a,b){if(!Faye.logger)return;var c=Faye.Logging.LOG_LEVELS;if(c[Faye.Logging.logLevel]>c[b])return;var a=Array.prototype.slice.apply(a),d=' ['+b.toUpperCase()+'] [Faye',f=null,g=a.shift().replace(/\?/g,function(){try{return Faye.toJSON(a.shift())}catch(e){return'[Object]'}});for(var i in Faye){if(f)continue;if(typeof Faye[i]!=='function')continue;if(this instanceof Faye[i])f=i}if(f)d+='.'+f;d+='] ';Faye.logger(Faye.timestamp()+d+g)}};Faye.each(Faye.Logging.LOG_LEVELS,function(a,b){Faye.Logging[a]=function(){this.log(arguments,a)}});Faye.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])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/};Faye.Extensible={addExtension:function(a){this._8=this._8||[];this._8.push(a);if(a.added)a.added()},removeExtension:function(a){if(!this._8)return;var b=this._8.length;while(b--){if(this._8[b]!==a)continue;this._8.splice(b,1);if(a.removed)a.removed()}},pipeThroughExtensions:function(c,d,f,g){if(!this._8)return f.call(g,d);var i=this._8.slice();var j=function(a){if(!a)return f.call(g,a);var b=i.shift();if(!b)return f.call(g,a);if(b[c])b[c](a,j);else j(a)};j(d)}};Faye.Channel=Faye.Class({initialize:function(a){this.id=this.name=a},push:function(a){this.publishEvent('message',a)},isUnused:function(){return this.countSubscribers('message')===0}});Faye.extend(Faye.Channel.prototype,Faye.Publisher);Faye.extend(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 b=this.parse(a);return b?(b[0]===this.META):null},isService:function(a){var b=this.parse(a);return b?(b[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,b){this._m=a;this._3=b;this._6={}},eachChild:function(c,d){Faye.each(this._6,function(a,b){c.call(d,a,b)})},each:function(c,d,f){this.eachChild(function(a,b){a=c.concat(a);b.each(a,d,f)});if(this._3!==undefined)d.call(f,c,this._3)},getKeys:function(){return this.map(function(a,b){return'/'+a.join('/')})},map:function(c,d){var f=[];this.each([],function(a,b){f.push(c.call(d,a,b))});return f},get:function(a){var b=this.traverse(a);return b?b._3:null},set:function(a,b){var c=this.traverse(a,true);if(c)c._3=b},remove:function(a){if(a){var b=this.traverse(a);if(b)b.remove()}else{if(!this._m)return;this._m.removeChild(this);this._m=this._3=undefined}},removeChild:function(c){this.eachChild(function(a,b){if(b===c)delete this._6[a]},this);if(Faye.size(this._6)===0&&this._3===undefined)this.remove()},traverse:function(a,b){if(typeof a==='string')a=Faye.Channel.parse(a);if(a===null)return null;if(a.length===0)return this;var c=this._6[a[0]];if(!c&&!b)return null;if(!c)c=this._6[a[0]]=new Faye.Channel.Tree(this);return c.traverse(a.slice(1),b)},findOrCreate:function(a){var b=this.get(a);if(b)return b;b=new Faye.Channel(a);this.set(a,b);return b},glob:function(f){if(typeof f==='string')f=Faye.Channel.parse(f);if(f===null)return[];if(f.length===0)return(this._3===undefined)?[]:[this._3];var g=[];if(Faye.enumEqual(f,['*'])){Faye.each(this._6,function(a,b){if(b._3!==undefined)g.push(b._3)});return g}if(Faye.enumEqual(f,['**'])){g=this.map(function(a,b){return b});if(this._3!==undefined)g.pop();return g}Faye.each(this._6,function(b,c){if(b!==f[0]&&b!=='*')return;var d=c.glob(f.slice(1));Faye.each(d,function(a){g.push(a)})});if(this._6['**'])g.push(this._6['**']._3);return g},subscribe:function(c,d,f){if(!d)return;Faye.each(c,function(a){var b=this.findOrCreate(a);b.addSubscriber('message',d,f)},this)},unsubscribe:function(a,b,c){var d=this.get(a);if(!d)return false;d.removeSubscriber('message',b,c);if(d.isUnused()){this.remove(a);return true}else{return false}},distributeMessage:function(b){var c=this.glob(b.channel);Faye.each(c,function(a){a.publishEvent('message',b.data)})}})});Faye.Subscription=Faye.Class({initialize:function(a,b,c,d){this._c=a;this._b=b;this._n=c;this._d=d;this._x=false},cancel:function(){if(this._x)return;this._c.unsubscribe(this._b,this._n,this._d);this._x=true},unsubscribe:function(){this.cancel()}});Faye.Client=Faye.Class({UNCONNECTED:1,CONNECTING:2,CONNECTED:3,DISCONNECTED:4,HANDSHAKE:'handshake',RETRY:'retry',NONE:'none',CONNECTION_TIMEOUT:60.0,DEFAULT_ENDPOINT:'/bayeux',MAX_DELAY:0.001,INTERVAL:0.0,initialize:function(a,b){this.info('New client created for ?',a);this._4=a||this.DEFAULT_ENDPOINT;this._y=b||{};this._f=Faye.Transport.get(this,Faye.MANDATORY_CONNECTION_TYPES);this._1=this.UNCONNECTED;this._h=[];this._b=new Faye.Channel.Tree();this._D=new Faye.Namespace();this._o={};this._9={reconnect:this.RETRY,interval:1000*(this._y.interval||this.INTERVAL),timeout:1000*(this._y.timeout||this.CONNECTION_TIMEOUT)};if(Faye.Event)Faye.Event.on(Faye.ENV,'beforeunload',this.disconnect,this)},handshake:function(b,c){if(this._9.reconnect===this.NONE)return;if(this._1!==this.UNCONNECTED)return;this._1=this.CONNECTING;var d=this;this.info('Initiating handshake with ?',this._4);this._e({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:[this._f.connectionType]},function(a){if(a.successful){this._1=this.CONNECTED;this._0=a.clientId;this._f=Faye.Transport.get(this,a.supportedConnectionTypes);this.info('Handshake successful: ?',this._0);this.subscribe(this._b.getKeys());if(b)b.call(c)}else{this.info('Handshake unsuccessful');setTimeout(function(){d.handshake(b,c)},this._9.interval);this._1=this.UNCONNECTED}},this)},connect:function(a,b){if(this._9.reconnect===this.NONE)return;if(this._1===this.DISCONNECTED)return;if(this._1===this.UNCONNECTED)return this.handshake(function(){this.connect(a,b)},this);this.callback(a,b);if(this._1!==this.CONNECTED)return;this.info('Calling deferred actions for ?',this._0);this.setDeferredStatus('succeeded');this.setDeferredStatus('deferred');if(this._p)return;this._p=true;this.info('Initiating connection for ?',this._0);this._e({channel:Faye.Channel.CONNECT,clientId:this._0,connectionType:this._f.connectionType},this._z,this)},disconnect:function(){if(this._1!==this.CONNECTED)return;this._1=this.DISCONNECTED;this.info('Disconnecting ?',this._0);this._e({channel:Faye.Channel.DISCONNECT,clientId:this._0});this.info('Clearing channel listeners for ?',this._0);this._b=new Faye.Channel.Tree()},subscribe:function(c,d,f){if(c instanceof Array)return Faye.each(c,function(channel){this.subscribe(channel,d,f)},this);this._q(c);this.connect(function(){this.info('Client ? attempting to subscribe to ?',this._0,c);this._e({channel:Faye.Channel.SUBSCRIBE,clientId:this._0,subscription:c},function(a){if(!a.successful)return;var b=[].concat(a.subscription);this.info('Subscription acknowledged for ? to ?',this._0,b);this._b.subscribe(b,d,f)},this)},this);return new Faye.Subscription(this,c,d,f)},unsubscribe:function(c,d,f){if(c instanceof Array)return Faye.each(c,function(channel){this.unsubscribe(channel,d,f)},this);this._q(c);var g=this._b.unsubscribe(c,d,f);if(!g)return;this.connect(function(){this.info('Client ? attempting to unsubscribe from ?',this._0,c);this._e({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._0,subscription:c},function(a){if(!a.successful)return;var b=[].concat(a.subscription);this.info('Unsubscription acknowledged for ? from ?',this._0,b)},this)},this)},publish:function(a,b){this._q(a);this.connect(function(){this.info('Client ? queueing published message to ?: ?',this._0,a,b);this._e({channel:a,data:b,clientId:this._0})},this)},receiveMessage:function(c){this.pipeThroughExtensions('incoming',c,function(a){if(!a)return;if(a.advice)this._E(a.advice);var b=this._o[a.id];if(b){delete this._o[a.id];b[0].call(b[1],a)}this._F(a)},this)},_E:function(a){Faye.extend(this._9,a);if(this._9.reconnect===this.HANDSHAKE&&this._1!==this.DISCONNECTED){this._1=this.UNCONNECTED;this._0=null;this._z()}},_F:function(a){if(!a.channel||!a.data)return;this.info('Client ? calling listeners for ? with ?',this._0,a.channel,a.data);this._b.distributeMessage(a)},_G:function(){if(!this._p)return;this._p=null;this.info('Closed connection for ?',this._0)},_z:function(){this._G();var a=this;setTimeout(function(){a.connect()},this._9.interval)},_e:function(b,c,d){b.id=this._D.generate();if(c)this._o[b.id]=[c,d];this.pipeThroughExtensions('outgoing',b,function(a){if(!a)return;if(a.channel===Faye.Channel.HANDSHAKE)return this._f.send(a,this._9.timeout/1000);this._h.push(a);if(a.channel===Faye.Channel.CONNECT)this._r=a;this.addTimeout('publish',this.MAX_DELAY,this._H,this)},this)},_H:function(){this.removeTimeout('publish');if(this._h.length>1&&this._r)this._r.advice={timeout:0};this._r=null;this._f.send(this._h,this._9.timeout/1000);this._h=[]},_q: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+'"';}});Faye.extend(Faye.Client.prototype,Faye.Deferrable);Faye.extend(Faye.Client.prototype,Faye.Timeouts);Faye.extend(Faye.Client.prototype,Faye.Logging);Faye.extend(Faye.Client.prototype,Faye.Extensible);Faye.Transport=Faye.extend(Faye.Class({initialize:function(a,b){this.debug('Created new ? transport for ?',this.connectionType,b);this._c=a;this._4=b},send:function(a,b){a=[].concat(a);this.debug('Client ? sending message to ?: ?',this._c._0,this._4,a);return this.request(a,b)},receive:function(a){this.debug('Client ? received from ?: ?',this._c._0,this._4,a);Faye.each(a,this._c.receiveMessage,this._c)},retry:function(a,b){var c=this;return function(){setTimeout(function(){c.request(a,2*b)},1000*b)}}}),{get:function(d,f){var g=d._4;if(f===undefined)f=this.supportedConnectionTypes();var i=null;Faye.each(this._s,function(a){var b=a[0],c=a[1];if(Faye.indexOf(f,b)<0)return;if(i)return;if(c.isUsable(g))i=c});if(!i)throw'Could not find a usable connection type for '+g;return new i(d,g)},register:function(a,b){this._s.push([a,b]);b.prototype.connectionType=a},_s:[],supportedConnectionTypes:function(){return Faye.map(this._s,function(a){return a[0]})}});Faye.extend(Faye.Transport.prototype,Faye.Logging);Faye.Event={_i:[],on:function(a,b,c,d){var f=function(){c.call(d)};if(a.addEventListener)a.addEventListener(b,f,false);else a.attachEvent('on'+b,f);this._i.push({_j:a,_t:b,_n:c,_d:d,_A:f})},detach:function(a,b,c,d){var f=this._i.length,g;while(f--){g=this._i[f];if((a&&a!==g._j)||(b&&b!==g._t)||(c&&c!==g._n)||(d&&d!==g._d))continue;if(g._j.removeEventListener)g._j.removeEventListener(g._t,g._A,false);else g._j.detachEvent('on'+g._t,g._A);this._i.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 c=[],d;Faye.each(this.params,function(a,b){c.push(encodeURIComponent(a)+'='+encodeURIComponent(b))});return c.join('&')},isLocal:function(){var a=Faye.URI.parse(Faye.ENV.location.href);var b=(a.hostname!==this.hostname)||(a.port!==this.port)||(a.protocol!==this.protocol);return!b},toURL:function(){var a=this.queryString();return this.protocol+this.hostname+':'+this.port+this.pathname+(a?'?'+a:'')}}),{parse:function(d,f){if(typeof d!=='string')return d;var g=new this();var i=function(b,c){d=d.replace(c,function(a){if(a)g[b]=a;return''})};i('protocol',/^https?\:\/+/);i('hostname',/^[^\/\:]+/);i('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 j=d.split('?'),h=j.shift(),l=j.join('?'),n=l?l.split('&'):[],o=n.length,k={};while(o--){j=n[o].split('=');k[decodeURIComponent(j[0]||'')]=decodeURIComponent(j[1]||'')}if(typeof f==='object')Faye.extend(k,f);g.pathname=h;g.params=k;return g}});Faye.XHR={request:function(a,b,c,d,f){var g=new this.Request(a,b,c,d,f);g.send();return g},getXhrObject:function(){return Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},Request:Faye.Class({initialize:function(a,b,c,d,f){this._k=a.toUpperCase();this._4=Faye.URI.parse(b,c);this._I=(typeof c==='string')?c:null;this._a=(typeof d==='function')?{success:d}:d;this._d=f||null;this._5=null},send:function(){if(this._u)return;var a=this._4.pathname,b=this._4.queryString();if(this._k==='GET')a+='?'+b;var c=(this._k==='POST')?(this._I||b):'';this._u=true;this._5=Faye.XHR.getXhrObject();this._5.open(this._k,a,true);if(this._k==='POST')this._5.setRequestHeader('Content-Type','application/json');var d=this,f=function(){if(d._5.readyState!==4)return;if(g){clearInterval(g);g=null}Faye.Event.detach(Faye.ENV,'beforeunload',d.abort,d);d._u=false;d._J();d=null};var g=setInterval(f,10);Faye.Event.on(Faye.ENV,'beforeunload',this.abort,this);this._5.send(c)},abort:function(){this._5.abort()},_J:function(){var a=this._a;if(!a)return;return this.success()?a.success&&a.success.call(this._d,this):a.failure&&a.failure.call(this._d,this)},waiting:function(){return!!this._u},complete:function(){return this._5&&!this.waiting()},success:function(){if(!this.complete())return false;var a=this._5.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._5.responseText},status:function(){if(!this.complete())return null;return this._5.status}})};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,k,p,s={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},m;function r(c){o.lastIndex=0;return o.test(c)?'"'+c.replace(o,function(a){var b=s[a];return typeof b==='string'?b:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+c+'"'}function q(a,b){var c,d,f,g,i=k,j,h=b[a];if(h&&typeof h==='object'&&typeof h.toJSON==='function'){h=h.toJSON(a)}if(typeof m==='function'){h=m.call(b,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'}k+=p;j=[];if(Object.prototype.toString.apply(h)==='[object Array]'){g=h.length;for(c=0;c<g;c+=1){j[c]=q(c,h)||'null'}f=j.length===0?'[]':k?'[\n'+k+j.join(',\n'+k)+'\n'+i+']':'['+j.join(',')+']';k=i;return f}if(m&&typeof m==='object'){g=m.length;for(c=0;c<g;c+=1){d=m[c];if(typeof d==='string'){f=q(d,h);if(f){j.push(r(d)+(k?': ':':')+f)}}}}else{for(d in h){if(Object.hasOwnProperty.call(h,d)){f=q(d,h);if(f){j.push(r(d)+(k?': ':':')+f)}}}}f=j.length===0?'{}':k?'{\n'+k+j.join(',\n'+k)+'\n'+i+'}':'{'+j.join(',')+'}';k=i;return f}}Faye.stringify=function(a,b,c){var d;k='';p='';if(typeof c==='number'){for(d=0;d<c;d+=1){p+=' '}}else if(typeof c==='string'){p=c}m=b;if(b&&typeof b!=='function'&&(typeof b!=='object'||typeof b.length!=='number')){throw new Error('JSON.stringify');}return q('',{'':a})};if(typeof JSON.stringify!=='function'){JSON.stringify=Faye.stringify}if(typeof JSON.parse!=='function'){JSON.parse=function(g,i){var j;function h(a,b){var c,d,f=a[b];if(f&&typeof f==='object'){for(c in f){if(Object.hasOwnProperty.call(f,c)){d=h(f,c);if(d!==undefined){f[c]=d}else{delete f[c]}}}}return i.call(a,b,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,''))){j=eval('('+g+')');return typeof i==='function'?h({'':j},''):j}throw new SyntaxError('JSON.parse');}}}());Faye.WebSocketTransport=Faye.Class(Faye.Transport,{UNCONNECTED:1,CONNECTING:2,CONNECTED:3,request:function(b,c){this._l=this._l||{};Faye.each(b,function(a){this._l[a.id]=a},this);this.withSocket(function(a){a.send(Faye.toJSON(b))})},withSocket:function(a,b){this.callback(a,b);this.connect()},getSocketUrl:function(){return Faye.URI.parse(this._4).toURL().replace(/^http(s?):/ig,'ws$1:')},connect:function(){this._1=this._1||this.UNCONNECTED;if(this._1!==this.UNCONNECTED)return;this._1=this.CONNECTING;this._g=new WebSocket(this.getSocketUrl());var d=this;this._g.onopen=function(){d._1=d.CONNECTED;d.setDeferredStatus('succeeded',d._g)};this._g.onmessage=function(b){var c=[].concat(JSON.parse(b.data));Faye.each(c,function(a){delete d._l[a.id]});d.receive(c)};this._g.onclose=function(){var a=(d._1===d.CONNECTED);d.setDeferredStatus('deferred');d._1=d.UNCONNECTED;d._g=null;if(a)d.resend();else d.connect()}},resend:function(){var c=Faye.map(this._l,function(a,b){return b});this.request(c)}});Faye.extend(Faye.WebSocketTransport.prototype,Faye.Deferrable);Faye.WebSocketTransport.isUsable=function(a){return!!Faye.ENV.WebSocket};Faye.Transport.register('websocket',Faye.WebSocketTransport);Faye.XHRTransport=Faye.Class(Faye.Transport,{request:function(b,c){var d=this.retry(b,c);Faye.XHR.request('post',this._4,Faye.toJSON(b),{success:function(a){try{this.receive(JSON.parse(a.text()))}catch(e){d()}},failure:d},this)}});Faye.XHRTransport.isUsable=function(a){return Faye.URI.parse(a).isLocal()};Faye.Transport.register('long-polling',Faye.XHRTransport);Faye.JSONPTransport=Faye.extend(Faye.Class(Faye.Transport,{request:function(b,c){var d={message:Faye.toJSON(b)},f=document.getElementsByTagName('head')[0],g=document.createElement('script'),i=Faye.JSONPTransport.getCallbackName(),j=Faye.URI.parse(this._4,d),h=this;var l=function(){if(!g.parentNode)return false;g.parentNode.removeChild(g);return true};Faye.ENV[i]=function(a){Faye.ENV[i]=undefined;try{delete Faye.ENV[i]}catch(e){}if(!l())return;h.receive(a)};setTimeout(function(){if(!Faye.ENV[i])return;l();h.request(b,2*c)},1000*c);j.params.jsonp=i;g.type='text/javascript';g.src=j.toURL();f.appendChild(g)}}),{_B:0,getCallbackName:function(){this._B+=1;return'__jsonp'+this._B+'__'}});Faye.JSONPTransport.isUsable=function(a){return true};Faye.Transport.register('callback-polling',Faye.JSONPTransport);
|
data/lib/faye.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'json'
|
2
3
|
require 'rack'
|
3
4
|
require 'thin'
|
4
5
|
require Faye::ROOT + '/thin_extensions'
|
@@ -61,7 +62,7 @@ module Faye
|
|
61
62
|
end
|
62
63
|
|
63
64
|
begin
|
64
|
-
json_msg = request
|
65
|
+
json_msg = message_from_request(request)
|
65
66
|
message = JSON.parse(json_msg)
|
66
67
|
jsonp = request.params['jsonp'] || JSONP_CALLBACK
|
67
68
|
type = request.get? ? TYPE_SCRIPT : TYPE_JSON
|
@@ -87,6 +88,17 @@ module Faye
|
|
87
88
|
|
88
89
|
private
|
89
90
|
|
91
|
+
def message_from_request(request)
|
92
|
+
if request.post?
|
93
|
+
content_type = request.env['CONTENT_TYPE'].split(';').first
|
94
|
+
content_type == 'application/json' ?
|
95
|
+
request.body.read :
|
96
|
+
request.params['message']
|
97
|
+
else
|
98
|
+
request.params['message']
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
90
102
|
def handle_upgrade(request)
|
91
103
|
socket = Faye::WebSocket.new(request)
|
92
104
|
|
@@ -12,6 +12,10 @@ module Faye
|
|
12
12
|
publish_event(:message, message)
|
13
13
|
end
|
14
14
|
|
15
|
+
def unused?
|
16
|
+
count_subscribers(:message).zero?
|
17
|
+
end
|
18
|
+
|
15
19
|
HANDSHAKE = '/meta/handshake'
|
16
20
|
CONNECT = '/meta/connect'
|
17
21
|
SUBSCRIBE = '/meta/subscribe'
|
@@ -52,8 +56,9 @@ module Faye
|
|
52
56
|
include Enumerable
|
53
57
|
attr_accessor :value
|
54
58
|
|
55
|
-
def initialize(value = nil)
|
56
|
-
@
|
59
|
+
def initialize(parent = nil, value = nil)
|
60
|
+
@parent = parent
|
61
|
+
@value = value
|
57
62
|
@children = {}
|
58
63
|
end
|
59
64
|
|
@@ -80,6 +85,24 @@ module Faye
|
|
80
85
|
subtree.value = value unless subtree.nil?
|
81
86
|
end
|
82
87
|
|
88
|
+
def remove(name = nil)
|
89
|
+
if name
|
90
|
+
subtree = traverse(name)
|
91
|
+
subtree.remove unless subtree.nil?
|
92
|
+
else
|
93
|
+
return unless @parent
|
94
|
+
@parent.remove_child(self)
|
95
|
+
@parent = @value = nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def remove_child(subtree)
|
100
|
+
each_child do |key, child|
|
101
|
+
@children.delete(key) if child == subtree
|
102
|
+
end
|
103
|
+
remove if @children.empty? and @value.nil?
|
104
|
+
end
|
105
|
+
|
83
106
|
def traverse(path, create_if_absent = false)
|
84
107
|
path = Channel.parse(path) if String === path
|
85
108
|
|
@@ -88,7 +111,7 @@ module Faye
|
|
88
111
|
|
89
112
|
subtree = @children[path.first]
|
90
113
|
return nil if subtree.nil? and not create_if_absent
|
91
|
-
subtree = @children[path.first] =
|
114
|
+
subtree = @children[path.first] = Tree.new(self) if subtree.nil?
|
92
115
|
|
93
116
|
subtree.traverse(path[1..-1], create_if_absent)
|
94
117
|
end
|
@@ -132,7 +155,13 @@ module Faye
|
|
132
155
|
channel = self[name]
|
133
156
|
return false unless channel
|
134
157
|
channel.remove_subscriber(:message, callback)
|
135
|
-
|
158
|
+
|
159
|
+
if channel.unused?
|
160
|
+
remove(name)
|
161
|
+
true
|
162
|
+
else
|
163
|
+
false
|
164
|
+
end
|
136
165
|
end
|
137
166
|
|
138
167
|
def distribute_message(message)
|
data/lib/faye/protocol/server.rb
CHANGED
@@ -85,6 +85,7 @@ module Faye
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def distribute_message(message)
|
88
|
+
return if message['error']
|
88
89
|
@channels.glob(message['channel']).each do |channel|
|
89
90
|
channel << message
|
90
91
|
info('Publishing message ? from client ? to ?', message['data'], message['clientId'], channel.name)
|
@@ -93,7 +94,6 @@ module Faye
|
|
93
94
|
|
94
95
|
def handle(message, socket = nil, local = false, &callback)
|
95
96
|
return callback.call([]) if !message
|
96
|
-
return callback.call([make_response(message)]) if message['error']
|
97
97
|
|
98
98
|
distribute_message(message)
|
99
99
|
channel_name = message['channel']
|
@@ -104,7 +104,7 @@ module Faye
|
|
104
104
|
callback.call([])
|
105
105
|
else
|
106
106
|
response = make_response(message)
|
107
|
-
response['successful'] =
|
107
|
+
response['successful'] = !response['error']
|
108
108
|
callback.call([response])
|
109
109
|
end
|
110
110
|
end
|
@@ -248,13 +248,13 @@ module Faye
|
|
248
248
|
|
249
249
|
response['subscription'] = subscription.compact
|
250
250
|
|
251
|
-
subscription.each do |
|
251
|
+
subscription.each do |channel_name|
|
252
252
|
next if response['error']
|
253
|
-
response['error'] = Error.channel_forbidden(
|
254
|
-
response['error'] = Error.channel_invalid(
|
253
|
+
response['error'] = Error.channel_forbidden(channel_name) unless local or Channel.subscribable?(channel_name)
|
254
|
+
response['error'] = Error.channel_invalid(channel_name) unless Channel.valid?(channel_name)
|
255
255
|
|
256
256
|
next if response['error']
|
257
|
-
channel = @channels[
|
257
|
+
channel = @channels[channel_name] ||= Channel.new(channel_name)
|
258
258
|
|
259
259
|
info('Subscribing client ? to ?', client_id, channel.name)
|
260
260
|
connection.subscribe(channel)
|
@@ -281,19 +281,20 @@ module Faye
|
|
281
281
|
|
282
282
|
response['subscription'] = subscription.compact
|
283
283
|
|
284
|
-
subscription.each do |
|
284
|
+
subscription.each do |channel_name|
|
285
285
|
next if response['error']
|
286
286
|
|
287
|
-
unless Channel.valid?(
|
288
|
-
response['error'] = Error.channel_invalid(
|
287
|
+
unless Channel.valid?(channel_name)
|
288
|
+
response['error'] = Error.channel_invalid(channel_name)
|
289
289
|
next
|
290
290
|
end
|
291
291
|
|
292
|
-
channel = @channels[
|
292
|
+
channel = @channels[channel_name]
|
293
293
|
next unless channel
|
294
294
|
|
295
295
|
info('Unsubscribing client ? from ?', client_id, channel.name)
|
296
296
|
connection.unsubscribe(channel)
|
297
|
+
@channels.remove(channel_name) if channel.unused?
|
297
298
|
end
|
298
299
|
|
299
300
|
response['successful'] = response['error'].nil?
|
data/lib/thin_extensions.rb
CHANGED
@@ -59,7 +59,8 @@ class Thin::Request
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def websocket_url
|
62
|
-
@env['
|
62
|
+
scheme = (@env['HTTP_ORIGIN'] =~ /^https:/i) ? 'wss:' : 'ws:'
|
63
|
+
@env['websocket.url'] = "#{ scheme }//#{ @env['HTTP_HOST'] }#{ @env['REQUEST_PATH'] }"
|
63
64
|
end
|
64
65
|
|
65
66
|
def websocket_upgrade_data
|
data/test/test_channel.rb
CHANGED
@@ -21,6 +21,14 @@ class TestChannel < Test::Unit::TestCase
|
|
21
21
|
assert_equal %w[/bar /foo /foo/bar], tree.keys.sort
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_removal
|
25
|
+
tree = Channel::Tree.new
|
26
|
+
tree['/foo'] = tree['/bar'] = tree['/foo/bar'] = true
|
27
|
+
|
28
|
+
tree.remove('/foo/bar')
|
29
|
+
assert_equal %w[/bar /foo], tree.keys.sort
|
30
|
+
end
|
31
|
+
|
24
32
|
def test_globbing
|
25
33
|
tree = Channel::Tree.new
|
26
34
|
tree['/foo/bar'] = 1
|
data/test/test_server.rb
CHANGED
@@ -4,6 +4,13 @@ require File.dirname(__FILE__) + "/../lib/faye"
|
|
4
4
|
class TestServer < Test::Unit::TestCase
|
5
5
|
include Faye
|
6
6
|
|
7
|
+
class ErrorExtension
|
8
|
+
def incoming(message, callback)
|
9
|
+
message['error'] = 'Extension error'
|
10
|
+
callback.call(message)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
def setup
|
8
15
|
@server = Server.new
|
9
16
|
end
|
@@ -460,4 +467,22 @@ class TestServer < Test::Unit::TestCase
|
|
460
467
|
assert_equal 60000, r.first['advice']['timeout']
|
461
468
|
end
|
462
469
|
end
|
470
|
+
|
471
|
+
def test_errors_from_extensions
|
472
|
+
@server.add_extension(ErrorExtension.new)
|
473
|
+
|
474
|
+
id = get_client_id
|
475
|
+
@server.send :process, ['channel' => '/meta/subscribe', 'subscription' => '/foo', 'clientId' => id], false do |r|
|
476
|
+
# MUST
|
477
|
+
assert_equal '/meta/subscribe', r.first['channel']
|
478
|
+
assert_equal false, r.first['successful']
|
479
|
+
assert_equal id, r.first['clientId']
|
480
|
+
assert_equal ['/foo'], r.first['subscription']
|
481
|
+
# MAY
|
482
|
+
assert_equal 'Extension error', r.first['error']
|
483
|
+
assert_equal nil, r.first['id']
|
484
|
+
# MAY include advice, ext, timestamp
|
485
|
+
end
|
486
|
+
end
|
463
487
|
end
|
488
|
+
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faye
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 15
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
8
|
+
- 3
|
9
|
+
version: 0.5.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- James Coglan
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-10-21 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 19
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
- 12
|
@@ -41,7 +39,6 @@ dependencies:
|
|
41
39
|
requirements:
|
42
40
|
- - ">="
|
43
41
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 15
|
45
42
|
segments:
|
46
43
|
- 0
|
47
44
|
- 2
|
@@ -56,7 +53,6 @@ dependencies:
|
|
56
53
|
requirements:
|
57
54
|
- - ">="
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 15
|
60
56
|
segments:
|
61
57
|
- 1
|
62
58
|
- 0
|
@@ -71,7 +67,6 @@ dependencies:
|
|
71
67
|
requirements:
|
72
68
|
- - ">="
|
73
69
|
- !ruby/object:Gem::Version
|
74
|
-
hash: 11
|
75
70
|
segments:
|
76
71
|
- 1
|
77
72
|
- 2
|
@@ -86,7 +81,6 @@ dependencies:
|
|
86
81
|
requirements:
|
87
82
|
- - ">="
|
88
83
|
- !ruby/object:Gem::Version
|
89
|
-
hash: 15
|
90
84
|
segments:
|
91
85
|
- 1
|
92
86
|
- 0
|
@@ -101,7 +95,6 @@ dependencies:
|
|
101
95
|
requirements:
|
102
96
|
- - ">="
|
103
97
|
- !ruby/object:Gem::Version
|
104
|
-
hash: 7
|
105
98
|
segments:
|
106
99
|
- 2
|
107
100
|
- 0
|
@@ -117,12 +110,11 @@ dependencies:
|
|
117
110
|
requirements:
|
118
111
|
- - ">="
|
119
112
|
- !ruby/object:Gem::Version
|
120
|
-
hash: 23
|
121
113
|
segments:
|
122
114
|
- 2
|
123
115
|
- 6
|
124
|
-
-
|
125
|
-
version: 2.6.
|
116
|
+
- 2
|
117
|
+
version: 2.6.2
|
126
118
|
type: :development
|
127
119
|
version_requirements: *id007
|
128
120
|
description: Simple pub/sub messaging for the web
|
@@ -179,7 +171,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
171
|
requirements:
|
180
172
|
- - ">="
|
181
173
|
- !ruby/object:Gem::Version
|
182
|
-
hash: 3
|
183
174
|
segments:
|
184
175
|
- 0
|
185
176
|
version: "0"
|
@@ -188,7 +179,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
179
|
requirements:
|
189
180
|
- - ">="
|
190
181
|
- !ruby/object:Gem::Version
|
191
|
-
hash: 3
|
192
182
|
segments:
|
193
183
|
- 0
|
194
184
|
version: "0"
|