faye-ouvrages 1.1.2 → 1.1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faye-browser-min.js +3 -0
- data/lib/faye-browser-min.js.map +1 -0
- data/lib/faye-browser.js +2783 -0
- data/lib/faye/adapters/rack_adapter.rb +1 -1
- data/lib/faye/protocol/client.rb +3 -2
- metadata +5 -5
- data/lib/client/faye-browser-min.js +0 -4
- data/lib/client/faye-browser-min.js.map +0 -1
- data/lib/client/faye-browser.js +0 -2808
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c9923bb77e1aad67d777ec18abc718de6c39de6
|
4
|
+
data.tar.gz: b8a84481221a296d1ec92b726e98ca6aa54afd59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 822ac2c1c49520631dae9737f60eba619340acde65b7eda3705de8d393967ef60019269effd78765907f8bb936d771a2fabd48d4f4c5d2d1883d9ac5d3587cd4
|
7
|
+
data.tar.gz: 27bb41a71d95e452e7ffdb9fa6af7e31d707095d3501ab3e7815b2b0676248d2c3bc315b4db7bbd972e3ad2c55901e08a7b333756abca7e5c7aac310331919d8
|
@@ -0,0 +1,3 @@
|
|
1
|
+
!function(){"use strict";var Faye={VERSION:"1.1.2",BAYEUX_VERSION:"1.0",ID_LENGTH:160,JSONP_CALLBACK:"jsonpcallback",CONNECTION_TYPES:["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],MANDATORY_CONNECTION_TYPES:["long-polling","callback-polling","in-process"],ENV:"undefined"!=typeof window?window:global,extend:function(e,t,n){if(!t)return e;for(var i in t)t.hasOwnProperty(i)&&(e.hasOwnProperty(i)&&n===!1||e[i]!==t[i]&&(e[i]=t[i]));return e},random:function(e){e=e||this.ID_LENGTH;for(var t=Math.ceil(e*Math.log(2)/Math.log(36)),n=csprng(e,36);n.length<t;)n="0"+n;return n},validateOptions:function(e,t){for(var n in e)if(this.indexOf(t,n)<0)throw Error("Unrecognized option: "+n)},clientIdFromMessages:function(e){var t=this.filter([].concat(e),function(e){return"/meta/connect"===e.channel});return t[0]&&t[0].clientId},copyObject:function(e){var t,n,i;if(e instanceof Array){for(t=[],n=e.length;n--;)t[n]=Faye.copyObject(e[n]);return t}if("object"==typeof e){t=null===e?null:{};for(i in e)t[i]=Faye.copyObject(e[i]);return t}return e},commonElement:function(e,t){for(var n=0,i=e.length;i>n;n++)if(-1!==this.indexOf(t,e[n]))return e[n];return null},indexOf:function(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,i=e.length;i>n;n++)if(e[n]===t)return n;return-1},map:function(e,t,n){if(e.map)return e.map(t,n);var i=[];if(e instanceof Array)for(var s=0,r=e.length;r>s;s++)i.push(t.call(n||null,e[s],s));else for(var o in e)e.hasOwnProperty(o)&&i.push(t.call(n||null,o,e[o]));return i},filter:function(e,t,n){if(e.filter)return e.filter(t,n);for(var i=[],s=0,r=e.length;r>s;s++)t.call(n||null,e[s],s)&&i.push(e[s]);return i},asyncEach:function(e,t,n,i){var s=e.length,r=-1,o=0,a=!1,c=function(){return o-=1,r+=1,r===s?n&&n.call(i):void t(e[r],u)},h=function(){if(!a){for(a=!0;o>0;)c();a=!1}},u=function(){o+=1,h()};u()},toJSON:function(e){return this.stringify?this.stringify(e,function(e,t){return this[e]instanceof Array?this[e]:t}):JSON.stringify(e)}};"undefined"!=typeof module?module.exports=Faye:"undefined"!=typeof window&&(window.Faye=Faye),Faye.Class=function(e,t){"function"!=typeof e&&(t=e,e=Object);var n=function(){return this.initialize?this.initialize.apply(this,arguments)||this:this},i=function(){};return i.prototype=e.prototype,n.prototype=new i,Faye.extend(n.prototype,t),n},function(){function e(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;n<e.length;n++)if(t===e[n])return n;return-1}var t=Faye.EventEmitter=function(){},n="function"==typeof Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};t.prototype.emit=function(e){if("error"===e&&(!this._events||!this._events.error||n(this._events.error)&&!this._events.error.length))throw arguments[1]instanceof Error?arguments[1]:Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var t=this._events[e];if(!t)return!1;if("function"==typeof t){switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:var i=Array.prototype.slice.call(arguments,1);t.apply(this,i)}return!0}if(n(t)){for(var i=Array.prototype.slice.call(arguments,1),s=t.slice(),r=0,o=s.length;o>r;r++)s[r].apply(this,i);return!0}return!1},t.prototype.addListener=function(e,t){if("function"!=typeof t)throw Error("addListener only takes instances of Function");return this._events||(this._events={}),this.emit("newListener",e,t),this._events[e]?n(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,this},t.prototype.on=t.prototype.addListener,t.prototype.once=function(e,t){var n=this;return n.on(e,function i(){n.removeListener(e,i),t.apply(this,arguments)}),this},t.prototype.removeListener=function(t,i){if("function"!=typeof i)throw Error("removeListener only takes instances of Function");if(!this._events||!this._events[t])return this;var s=this._events[t];if(n(s)){var r=e(s,i);if(0>r)return this;s.splice(r,1),0==s.length&&delete this._events[t]}else this._events[t]===i&&delete this._events[t];return this},t.prototype.removeAllListeners=function(e){return 0===arguments.length?(this._events={},this):(e&&this._events&&this._events[e]&&(this._events[e]=null),this)},t.prototype.listeners=function(e){return this._events||(this._events={}),this._events[e]||(this._events[e]=[]),n(this._events[e])||(this._events[e]=[this._events[e]]),this._events[e]}}(),Faye.Namespace=Faye.Class({initialize:function(){this._used={}},exists:function(e){return this._used.hasOwnProperty(e)},generate:function(){for(var e=Faye.random();this._used.hasOwnProperty(e);)e=Faye.random();return this._used[e]=e},release:function(e){delete this._used[e]}}),function(){var e,t=setTimeout;e="function"==typeof setImmediate?function(e){setImmediate(e)}:"object"==typeof process&&process.nextTick?function(e){process.nextTick(e)}:function(e){t(e,0)};var n=0,i=1,s=2,r=function(e){return e},o=function(e){throw e},a=function(e){if(this._state=n,this._onFulfilled=[],this._onRejected=[],"function"==typeof e){var t=this;e(function(e){f(t,e)},function(e){d(t,e)})}};a.prototype.then=function(e,t){var n=new a;return c(this,e,n),h(this,t,n),n};var c=function(e,t,s){"function"!=typeof t&&(t=r);var o=function(e){u(t,e,s)};e._state===n?e._onFulfilled.push(o):e._state===i&&o(e._value)},h=function(e,t,i){"function"!=typeof t&&(t=o);var r=function(e){u(t,e,i)};e._state===n?e._onRejected.push(r):e._state===s&&r(e._reason)},u=function(t,n,i){e(function(){l(t,n,i)})},l=function(e,t,n){var i;try{i=e(t)}catch(s){return d(n,s)}i===n?d(n,new TypeError("Recursive promise chain detected")):f(n,i)},f=a.fulfill=a.resolve=function(e,t){var n,i,s=!1;try{if(n=typeof t,i=null!==t&&("function"===n||"object"===n)&&t.then,"function"!=typeof i)return p(e,t);i.call(t,function(t){s^(s=!0)&&f(e,t)},function(t){s^(s=!0)&&d(e,t)})}catch(r){if(!(s^(s=!0)))return;d(e,r)}},p=function(e,t){if(e._state===n){e._state=i,e._value=t,e._onRejected=[];for(var s,r=e._onFulfilled;s=r.shift();)s(t)}},d=a.reject=function(e,t){if(e._state===n){e._state=s,e._reason=t,e._onFulfilled=[];for(var i,r=e._onRejected;i=r.shift();)i(t)}};a.all=function(e){return new a(function(t,n){var i,s=[],r=e.length;if(0===r)return t(s);for(i=0;r>i;i++)(function(e,i){a.fulfilled(e).then(function(e){s[i]=e,0===--r&&t(s)},n)})(e[i],i)})},a.defer=e,a.deferred=a.pending=function(){var e={};return e.promise=new a(function(t,n){e.fulfill=e.resolve=t,e.reject=n}),e},a.fulfilled=a.resolved=function(e){return new a(function(t,n){t(e)})},a.rejected=function(e){return new a(function(t,n){n(e)})},void 0===Faye?module.exports=a:Faye.Promise=a}(),Faye.Set=Faye.Class({initialize:function(){this._index={}},add:function(e){var t=void 0!==e.id?e.id:e;return this._index.hasOwnProperty(t)?!1:(this._index[t]=e,!0)},forEach:function(e,t){for(var n in this._index)this._index.hasOwnProperty(n)&&e.call(t,this._index[n])},isEmpty:function(){for(var e in this._index)if(this._index.hasOwnProperty(e))return!1;return!0},member:function(e){for(var t in this._index)if(this._index[t]===e)return!0;return!1},remove:function(e){var t=void 0!==e.id?e.id:e,n=this._index[t];return delete this._index[t],n},toArray:function(){var e=[];return this.forEach(function(t){e.push(t)}),e}}),Faye.URI={isURI:function(e){return e&&e.protocol&&e.host&&e.path},isSameOrigin:function(e){var t=Faye.ENV.location;return e.protocol===t.protocol&&e.hostname===t.hostname&&e.port===t.port},parse:function(e){if("string"!=typeof e)return e;var t,n,i,s,r,o,a={},c=function(t,n){e=e.replace(n,function(e){return a[t]=e,""}),a[t]=a[t]||""};for(c("protocol",/^[a-z]+\:/i),c("host",/^\/\/[^\/\?#]+/),/^\//.test(e)||a.host||(e=Faye.ENV.location.pathname.replace(/[^\/]*$/,"")+e),c("pathname",/^[^\?#]*/),c("search",/^\?[^#]*/),c("hash",/^#.*/),a.protocol=a.protocol||Faye.ENV.location.protocol,a.host?(a.host=a.host.substr(2),t=a.host.split(":"),a.hostname=t[0],a.port=t[1]||""):(a.host=Faye.ENV.location.host,a.hostname=Faye.ENV.location.hostname,a.port=Faye.ENV.location.port),a.pathname=a.pathname||"/",a.path=a.pathname+a.search,n=a.search.replace(/^\?/,""),i=n?n.split("&"):[],o={},s=0,r=i.length;r>s;s++)t=i[s].split("="),o[decodeURIComponent(t[0]||"")]=decodeURIComponent(t[1]||"");return a.query=o,a.href=this.stringify(a),a},stringify:function(e){var t=e.protocol+"//"+e.hostname;return e.port&&(t+=":"+e.port),t+=e.pathname+this.queryString(e.query)+(e.hash||"")},queryString:function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return 0===t.length?"":"?"+t.join("&")}},Faye.Error=Faye.Class({initialize:function(e,t,n){this.code=e,this.params=Array.prototype.slice.call(t),this.message=n},toString:function(){return this.code+":"+this.params.join(",")+":"+this.message}}),Faye.Error.parse=function(e){if(e=e||"",!Faye.Grammar.ERROR.test(e))return new this(null,[],e);var t=e.split(":"),n=parseInt(t[0]),i=t[1].split(","),e=t[2];return new this(n,i,e)},Faye.Error.versionMismatch=function(){return""+new this(300,arguments,"Version mismatch")},Faye.Error.conntypeMismatch=function(){return""+new this(301,arguments,"Connection types not supported")},Faye.Error.extMismatch=function(){return""+new this(302,arguments,"Extension mismatch")},Faye.Error.badRequest=function(){return""+new this(400,arguments,"Bad request")},Faye.Error.clientUnknown=function(){return""+new this(401,arguments,"Unknown client")},Faye.Error.parameterMissing=function(){return""+new this(402,arguments,"Missing required parameter")},Faye.Error.channelForbidden=function(){return""+new this(403,arguments,"Forbidden channel")},Faye.Error.channelUnknown=function(){return""+new this(404,arguments,"Unknown channel")},Faye.Error.channelInvalid=function(){return""+new this(405,arguments,"Invalid channel")},Faye.Error.extUnknown=function(){return""+new this(406,arguments,"Unknown extension")},Faye.Error.publishFailed=function(){return""+new this(407,arguments,"Failed to publish")},Faye.Error.serverError=function(){return""+new this(500,arguments,"Internal server error")},Faye.Deferrable={then:function(e,t){var n=this;return this._promise||(this._promise=new Faye.Promise(function(e,t){n._fulfill=e,n._reject=t})),0===arguments.length?this._promise:this._promise.then(e,t)},callback:function(e,t){return this.then(function(n){e.call(t,n)})},errback:function(e,t){return this.then(null,function(n){e.call(t,n)})},timeout:function(e,t){this.then();var n=this;this._timer=Faye.ENV.setTimeout(function(){n._reject(t)},1e3*e)},setDeferredStatus:function(e,t){this._timer&&Faye.ENV.clearTimeout(this._timer),this.then(),"succeeded"===e?this._fulfill(t):"failed"===e?this._reject(t):delete this._promise}},Faye.Publisher={countListeners:function(e){return this.listeners(e).length},bind:function(e,t,n){var i=Array.prototype.slice,s=function(){t.apply(n,i.call(arguments))};return this._listeners=this._listeners||[],this._listeners.push([e,t,n,s]),this.on(e,s)},unbind:function(e,t,n){this._listeners=this._listeners||[];for(var i,s=this._listeners.length;s--;)i=this._listeners[s],i[0]===e&&(!t||i[1]===t&&i[2]===n)&&(this._listeners.splice(s,1),this.removeListener(e,i[3]))}},Faye.extend(Faye.Publisher,Faye.EventEmitter.prototype),Faye.Publisher.trigger=Faye.Publisher.emit,Faye.Timeouts={addTimeout:function(e,t,n,i){if(this._timeouts=this._timeouts||{},!this._timeouts.hasOwnProperty(e)){var s=this;this._timeouts[e]=Faye.ENV.setTimeout(function(){delete s._timeouts[e],n.call(i)},1e3*t)}},removeTimeout:function(e){this._timeouts=this._timeouts||{};var t=this._timeouts[e];t&&(Faye.ENV.clearTimeout(t),delete this._timeouts[e])},removeAllTimeouts:function(){this._timeouts=this._timeouts||{};for(var e in this._timeouts)this.removeTimeout(e)}},Faye.Logging={LOG_LEVELS:{fatal:4,error:3,warn:2,info:1,debug:0},writeLog:function(e,t){if(Faye.logger){var n=Array.prototype.slice.apply(e),i="[Faye",s=this.className,r=n.shift().replace(/\?/g,function(){try{return Faye.toJSON(n.shift())}catch(e){return"[Object]"}});for(var o in Faye)s||"function"==typeof Faye[o]&&this instanceof Faye[o]&&(s=o);s&&(i+="."+s),i+="] ","function"==typeof Faye.logger[t]?Faye.logger[t](i+r):"function"==typeof Faye.logger&&Faye.logger(i+r)}}},function(){for(var e in Faye.Logging.LOG_LEVELS)(function(e){Faye.Logging[e]=function(){this.writeLog(arguments,e)}})(e)}(),Faye.Grammar={CHANNEL_NAME:/^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,CHANNEL_PATTERN:/^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,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])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/,VERSION:/^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/},Faye.Extensible={addExtension:function(e){this._extensions=this._extensions||[],this._extensions.push(e),e.added&&e.added(this)},removeExtension:function(e){if(this._extensions)for(var t=this._extensions.length;t--;)this._extensions[t]===e&&(this._extensions.splice(t,1),e.removed&&e.removed(this))},pipeThroughExtensions:function(e,t,n,i,s){if(this.debug("Passing through ? extensions: ?",e,t),!this._extensions)return i.call(s,t);var r=this._extensions.slice(),o=function(t){if(!t)return i.call(s,t);var a=r.shift();if(!a)return i.call(s,t);var c=a[e];return c?void(c.length>=3?a[e](t,n,o):a[e](t,o)):o(t)};o(t)}},Faye.extend(Faye.Extensible,Faye.Logging),Faye.Channel=Faye.Class({initialize:function(e){this.id=this.name=e},push:function(e){this.trigger("message",e)},isUnused:function(){return 0===this.countListeners("message")}}),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",expand:function(e){var t=this.parse(e),n=["/**",e],i=t.slice();i[i.length-1]="*",n.push(this.unparse(i));for(var s=1,r=t.length;r>s;s++)i=t.slice(0,s),i.push("**"),n.push(this.unparse(i));return n},isValid:function(e){return Faye.Grammar.CHANNEL_NAME.test(e)||Faye.Grammar.CHANNEL_PATTERN.test(e)},parse:function(e){return this.isValid(e)?e.split("/").slice(1):null},unparse:function(e){return"/"+e.join("/")},isMeta:function(e){var t=this.parse(e);return t?t[0]===this.META:null},isService:function(e){var t=this.parse(e);return t?t[0]===this.SERVICE:null},isSubscribable:function(e){return this.isValid(e)?!this.isMeta(e)&&!this.isService(e):null},Set:Faye.Class({initialize:function(){this._channels={}},getKeys:function(){var e=[];for(var t in this._channels)e.push(t);return e},remove:function(e){delete this._channels[e]},hasSubscription:function(e){return this._channels.hasOwnProperty(e)},subscribe:function(e,t,n){for(var i,s=0,r=e.length;r>s;s++){i=e[s];var o=this._channels[i]=this._channels[i]||new Faye.Channel(i);t&&o.bind("message",t,n)}},unsubscribe:function(e,t,n){var i=this._channels[e];return i?(i.unbind("message",t,n),i.isUnused()?(this.remove(e),!0):!1):!1},distributeMessage:function(e){for(var t=Faye.Channel.expand(e.channel),n=0,i=t.length;i>n;n++){var s=this._channels[t[n]];s&&s.trigger("message",e.data)}}})}),Faye.Publication=Faye.Class(Faye.Deferrable),Faye.Subscription=Faye.Class({initialize:function(e,t,n,i){this._client=e,this._channels=t,this._callback=n,this._context=i,this._cancelled=!1},cancel:function(){this._cancelled||(this._client.unsubscribe(this._channels,this._callback,this._context),this._cancelled=!0)},unsubscribe:function(){this.cancel()}}),Faye.extend(Faye.Subscription.prototype,Faye.Deferrable),Faye.Client=Faye.Class({UNCONNECTED:1,CONNECTING:2,CONNECTED:3,DISCONNECTED:4,HANDSHAKE:"handshake",RETRY:"retry",NONE:"none",CONNECTION_TIMEOUT:60,DEFAULT_ENDPOINT:"/bayeux",INTERVAL:0,initialize:function(e,t){this.info("New client created for ?",e),t=t||{},Faye.validateOptions(t,["interval","timeout","endpoints","proxy","retry","scheduler","websocketExtensions","tls","ca"]),this._endpoint=e||this.DEFAULT_ENDPOINT,this._channels=new Faye.Channel.Set,this._dispatcher=new Faye.Dispatcher(this,this._endpoint,t),this._messageId=0,this._state=this.UNCONNECTED,this._responseCallbacks={},this._advice={reconnect:this.RETRY,interval:1e3*(t.interval||this.INTERVAL),timeout:1e3*(t.timeout||this.CONNECTION_TIMEOUT)},this._dispatcher.timeout=this._advice.timeout/1e3,this._dispatcher.bind("message",this._receiveMessage,this),Faye.Event&&void 0!==Faye.ENV.onbeforeunload&&Faye.Event.on(Faye.ENV,"beforeunload",function(){Faye.indexOf(this._dispatcher._disabled,"autodisconnect")<0&&this.disconnect()},this)},addWebsocketExtension:function(e){return this._dispatcher.addWebsocketExtension(e)},disable:function(e){return this._dispatcher.disable(e)},setHeader:function(e,t){return this._dispatcher.setHeader(e,t)},handshake:function(e,t){if(this._advice.reconnect!==this.NONE&&this._state===this.UNCONNECTED){this._state=this.CONNECTING;var n=this;this.info("Initiating handshake with ?",Faye.URI.stringify(this._endpoint)),this._dispatcher.selectTransport(Faye.MANDATORY_CONNECTION_TYPES),this._sendMessage({channel:Faye.Channel.HANDSHAKE,version:Faye.BAYEUX_VERSION,supportedConnectionTypes:this._dispatcher.getConnectionTypes()},{},function(i){i.successful?(this._state=this.CONNECTED,this._dispatcher.clientId=i.clientId,this._dispatcher.selectTransport(i.supportedConnectionTypes),this.info("Handshake successful: ?",this._dispatcher.clientId),this.subscribe(this._channels.getKeys(),!0),e&&Faye.Promise.defer(function(){e.call(t)})):(this.info("Handshake unsuccessful"),Faye.ENV.setTimeout(function(){n.handshake(e,t)},1e3*this._dispatcher.retry),this._state=this.UNCONNECTED)},this)}},connect:function(e,t){if(this._advice.reconnect!==this.NONE&&this._state!==this.DISCONNECTED){if(this._state===this.UNCONNECTED)return this.handshake(function(){this.connect(e,t)},this);this.callback(e,t),this._state===this.CONNECTED&&(this.info("Calling deferred actions for ?",this._dispatcher.clientId),this.setDeferredStatus("succeeded"),this.setDeferredStatus("unknown"),this._connectRequest||(this._connectRequest=!0,this.info("Initiating connection for ?",this._dispatcher.clientId),this._sendMessage({channel:Faye.Channel.CONNECT,clientId:this._dispatcher.clientId,connectionType:this._dispatcher.connectionType},{},this._cycleConnection,this)))}},disconnect:function(){if(this._state===this.CONNECTED){this._state=this.DISCONNECTED,this.info("Disconnecting ?",this._dispatcher.clientId);var e=new Faye.Publication;return this._sendMessage({channel:Faye.Channel.DISCONNECT,clientId:this._dispatcher.clientId},{},function(t){t.successful?(this._dispatcher.close(),e.setDeferredStatus("succeeded")):e.setDeferredStatus("failed",Faye.Error.parse(t.error))},this),this.info("Clearing channel listeners for ?",this._dispatcher.clientId),this._channels=new Faye.Channel.Set,e}},subscribe:function(e,t,n){if(e instanceof Array)return Faye.map(e,function(e){return this.subscribe(e,t,n)},this);var i=new Faye.Subscription(this,e,t,n),s=t===!0,r=this._channels.hasSubscription(e);return r&&!s?(this._channels.subscribe([e],t,n),i.setDeferredStatus("succeeded"),i):(this.connect(function(){this.info("Client ? attempting to subscribe to ?",this._dispatcher.clientId,e),s||this._channels.subscribe([e],t,n),this._sendMessage({channel:Faye.Channel.SUBSCRIBE,clientId:this._dispatcher.clientId,subscription:e},{},function(s){if(!s.successful)return i.setDeferredStatus("failed",Faye.Error.parse(s.error)),this._channels.unsubscribe(e,t,n);var r=[].concat(s.subscription);this.info("Subscription acknowledged for ? to ?",this._dispatcher.clientId,r),i.setDeferredStatus("succeeded")},this)},this),i)},unsubscribe:function(e,t,n){if(e instanceof Array)return Faye.map(e,function(e){return this.unsubscribe(e,t,n)},this);var i=this._channels.unsubscribe(e,t,n);i&&this.connect(function(){this.info("Client ? attempting to unsubscribe from ?",this._dispatcher.clientId,e),this._sendMessage({channel:Faye.Channel.UNSUBSCRIBE,clientId:this._dispatcher.clientId,subscription:e},{},function(e){if(e.successful){var t=[].concat(e.subscription);this.info("Unsubscription acknowledged for ? from ?",this._dispatcher.clientId,t)}},this)},this)},publish:function(e,t,n){Faye.validateOptions(n||{},["attempts","deadline"]);var i=new Faye.Publication;return this.connect(function(){this.info("Client ? queueing published message to ?: ?",this._dispatcher.clientId,e,t),this._sendMessage({channel:e,data:t,clientId:this._dispatcher.clientId},n,function(e){e.successful?i.setDeferredStatus("succeeded"):i.setDeferredStatus("failed",Faye.Error.parse(e.error))},this)},this),i},_sendMessage:function(e,t,n,i){e.id=this._generateMessageId();var s=this._advice.timeout?1.2*this._advice.timeout/1e3:1.2*this._dispatcher.retry;this.pipeThroughExtensions("outgoing",e,null,function(e){e&&(n&&(this._responseCallbacks[e.id]=[n,i]),this._dispatcher.sendMessage(e,s,t||{}))},this)},_generateMessageId:function(){return this._messageId+=1,this._messageId>=Math.pow(2,32)&&(this._messageId=0),this._messageId.toString(36)},_receiveMessage:function(e){var t,n=e.id;void 0!==e.successful&&(t=this._responseCallbacks[n],delete this._responseCallbacks[n]),this.pipeThroughExtensions("incoming",e,null,function(e){e&&(e.advice&&this._handleAdvice(e.advice),this._deliverMessage(e),t&&t[0].call(t[1],e))},this)},_handleAdvice:function(e){Faye.extend(this._advice,e),this._dispatcher.timeout=this._advice.timeout/1e3,this._advice.reconnect===this.HANDSHAKE&&this._state!==this.DISCONNECTED&&(this._state=this.UNCONNECTED,this._dispatcher.clientId=null,this._cycleConnection())},_deliverMessage:function(e){e.channel&&void 0!==e.data&&(this.info("Client ? calling listeners for ? with ?",this._dispatcher.clientId,e.channel,e.data),this._channels.distributeMessage(e))},_cycleConnection:function(){this._connectRequest&&(this._connectRequest=null,this.info("Closed connection for ?",this._dispatcher.clientId));var e=this;Faye.ENV.setTimeout(function(){e.connect()},this._advice.interval)}}),Faye.extend(Faye.Client.prototype,Faye.Deferrable),Faye.extend(Faye.Client.prototype,Faye.Publisher),Faye.extend(Faye.Client.prototype,Faye.Logging),Faye.extend(Faye.Client.prototype,Faye.Extensible),Faye.Dispatcher=Faye.Class({MAX_REQUEST_SIZE:2048,DEFAULT_RETRY:5,UP:1,DOWN:2,initialize:function(e,t,n){this._client=e,this.endpoint=Faye.URI.parse(t),this._alternates=n.endpoints||{},this.cookies=Faye.Cookies&&new Faye.Cookies.CookieJar,this._disabled=[],this._envelopes={},this.headers={},this.retry=n.retry||this.DEFAULT_RETRY,this._scheduler=n.scheduler||Faye.Scheduler,this._state=0,this.transports={},this.wsExtensions=[],this.proxy=n.proxy||{},"string"==typeof this._proxy&&(this._proxy={origin:this._proxy});var i=n.websocketExtensions;if(i){i=[].concat(i);for(var s=0,r=i.length;r>s;s++)this.addWebsocketExtension(i[s])}this.tls=n.tls||{},this.tls.ca=this.tls.ca||n.ca;for(var o in this._alternates)this._alternates[o]=Faye.URI.parse(this._alternates[o]);this.maxRequestSize=this.MAX_REQUEST_SIZE},endpointFor:function(e){return this._alternates[e]||this.endpoint},addWebsocketExtension:function(e){this.wsExtensions.push(e)},disable:function(e){this._disabled.push(e)},setHeader:function(e,t){this.headers[e]=t},close:function(){var e=this._transport;delete this._transport,e&&e.close()},getConnectionTypes:function(){return Faye.Transport.getConnectionTypes()},selectTransport:function(e){Faye.Transport.get(this,e,this._disabled,function(e){this.debug("Selected ? transport for ?",e.connectionType,Faye.URI.stringify(e.endpoint)),e!==this._transport&&(this._transport&&this._transport.close(),this._transport=e,this.connectionType=e.connectionType)},this)},sendMessage:function(e,t,n){n=n||{};var i,s=e.id,r=n.attempts,o=n.deadline&&(new Date).getTime()+1e3*n.deadline,a=this._envelopes[s];a||(i=new this._scheduler(e,{timeout:t,interval:this.retry,attempts:r,deadline:o}),a=this._envelopes[s]={message:e,scheduler:i}),this._sendEnvelope(a)},_sendEnvelope:function(e){if(this._transport&&!e.request&&!e.timer){var t=e.message,n=e.scheduler,i=this;if(!n.isDeliverable())return n.abort(),void delete this._envelopes[t.id];e.timer=Faye.ENV.setTimeout(function(){i.handleError(t)},1e3*n.getTimeout()),n.send(),e.request=this._transport.sendMessage(t)}},handleResponse:function(e){var t=this._envelopes[e.id];void 0!==e.successful&&t&&(t.scheduler.succeed(),delete this._envelopes[e.id],Faye.ENV.clearTimeout(t.timer)),this.trigger("message",e),this._state!==this.UP&&(this._state=this.UP,this._client.trigger("transport:up"))},handleError:function(e,t){var n=this._envelopes[e.id],i=n&&n.request,s=this;if(i){i.then(function(e){e&&e.abort&&e.abort()});var r=n.scheduler;r.fail(),Faye.ENV.clearTimeout(n.timer),n.request=n.timer=null,t?this._sendEnvelope(n):n.timer=Faye.ENV.setTimeout(function(){n.timer=null,s._sendEnvelope(n)},1e3*r.getInterval()),this._state!==this.DOWN&&(this._state=this.DOWN,this._client.trigger("transport:down"))}}}),Faye.extend(Faye.Dispatcher.prototype,Faye.Publisher),Faye.extend(Faye.Dispatcher.prototype,Faye.Logging),Faye.Scheduler=function(e,t){this.message=e,this.options=t,this.attempts=0},Faye.extend(Faye.Scheduler.prototype,{getTimeout:function(){return this.options.timeout},getInterval:function(){return this.options.interval},isDeliverable:function(){var e=this.options.attempts,t=this.attempts,n=this.options.deadline,i=(new Date).getTime();return void 0!==e&&t>=e?!1:!(void 0!==n&&i>n)},send:function(){this.attempts+=1},succeed:function(){},fail:function(){},abort:function(){}}),Faye.Transport=Faye.extend(Faye.Class({DEFAULT_PORTS:{"http:":80,"https:":443,"ws:":80,"wss:":443},SECURE_PROTOCOLS:["https:","wss:"],MAX_DELAY:0,batching:!0,initialize:function(e,t){this._dispatcher=e,this.endpoint=t,this._outbox=[],this._proxy=Faye.extend({},this._dispatcher.proxy),!this._proxy.origin&&Faye.NodeAdapter&&(this._proxy.origin=Faye.indexOf(this.SECURE_PROTOCOLS,this.endpoint.protocol)>=0?process.env.HTTPS_PROXY||process.env.https_proxy:process.env.HTTP_PROXY||process.env.http_proxy)},close:function(){},encode:function(e){return""},sendMessage:function(e){return this.debug("Client ? sending message to ?: ?",this._dispatcher.clientId,Faye.URI.stringify(this.endpoint),e),this.batching?(this._outbox.push(e),this._flushLargeBatch(),e.channel===Faye.Channel.HANDSHAKE?this._publish(.01):(e.channel===Faye.Channel.CONNECT&&(this._connectMessage=e),this._publish(this.MAX_DELAY))):Faye.Promise.fulfilled(this.request([e]))},_publish:function(e){return this._promise=this._promise||new Faye.Promise,this.addTimeout("publish",e,function(){this._flush(),delete this._promise},this),this._promise},_flush:function(){this.removeTimeout("publish"),this._outbox.length>1&&this._connectMessage&&(this._connectMessage.advice={timeout:0}),Faye.Promise.fulfill(this._promise,this.request(this._outbox)),this._connectMessage=null,this._outbox=[]},_flushLargeBatch:function(){var e=this.encode(this._outbox);if(!(e.length<this._dispatcher.maxRequestSize)){var t=this._outbox.pop();this._promise=this._promise||new Faye.Promise,this._flush(),t&&this._outbox.push(t)}},_receive:function(e){if(e){e=[].concat(e),this.debug("Client ? received from ? via ?: ?",this._dispatcher.clientId,Faye.URI.stringify(this.endpoint),this.connectionType,e);for(var t=0,n=e.length;n>t;t++)this._dispatcher.handleResponse(e[t])}},_handleError:function(e,t){e=[].concat(e),this.debug("Client ? failed to send to ? via ?: ?",this._dispatcher.clientId,Faye.URI.stringify(this.endpoint),this.connectionType,e);for(var n=0,i=e.length;i>n;n++)this._dispatcher.handleError(e[n])},_getCookies:function(){var e=this._dispatcher.cookies,t=Faye.URI.stringify(this.endpoint);return e?Faye.map(e.getCookiesSync(t),function(e){return e.cookieString()}).join("; "):""},_storeCookies:function(e){var t,n=this._dispatcher.cookies,i=Faye.URI.stringify(this.endpoint);if(e&&n){e=[].concat(e);for(var s=0,r=e.length;r>s;s++)t=Faye.Cookies.Cookie.parse(e[s]),n.setCookieSync(t,i)}}}),{get:function(e,t,n,i,s){var r=e.endpoint;Faye.asyncEach(this._transports,function(r,o){var a=r[0],c=r[1],h=e.endpointFor(a);return Faye.indexOf(n,a)>=0?o():Faye.indexOf(t,a)<0?(c.isUsable(e,h,function(){}),o()):void c.isUsable(e,h,function(t){if(!t)return o();var n=c.hasOwnProperty("create")?c.create(e,h):new c(e,h);i.call(s,n)})},function(){throw Error("Could not find a usable connection type for "+Faye.URI.stringify(r))})},register:function(e,t){this._transports.push([e,t]),t.prototype.connectionType=e},getConnectionTypes:function(){return Faye.map(this._transports,function(e){return e[0]})},_transports:[]}),Faye.extend(Faye.Transport.prototype,Faye.Logging),Faye.extend(Faye.Transport.prototype,Faye.Timeouts),Faye.Event={_registry:[],on:function(e,t,n,i){var s=function(){n.call(i)};e.addEventListener?e.addEventListener(t,s,!1):e.attachEvent("on"+t,s),this._registry.push({_element:e,_type:t,_callback:n,_context:i,_handler:s})},detach:function(e,t,n,i){for(var s,r=this._registry.length;r--;)s=this._registry[r],e&&e!==s._element||t&&t!==s._type||n&&n!==s._callback||i&&i!==s._context||(s._element.removeEventListener?s._element.removeEventListener(s._type,s._handler,!1):s._element.detachEvent("on"+s._type,s._handler),this._registry.splice(r,1),s=null)}},void 0!==Faye.ENV.onunload&&Faye.Event.on(Faye.ENV,"unload",Faye.Event.detach,Faye.Event),"object"!=typeof JSON&&(JSON={}),function(){function f(e){return 10>e?"0"+e:e}function quote(e){return escapable.lastIndex=0,escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var n,i,s,r,o,a=gap,c=t[e];switch(c&&"object"==typeof c&&"function"==typeof c.toJSON&&(c=c.toJSON(e)),"function"==typeof rep&&(c=rep.call(t,e,c)),typeof c){case"string":return quote(c);case"number":return isFinite(c)?c+"":"null";case"boolean":case"null":return c+"";case"object":if(!c)return"null";if(gap+=indent,o=[],"[object Array]"===Object.prototype.toString.apply(c)){for(r=c.length,n=0;r>n;n+=1)o[n]=str(n,c)||"null";return s=0===o.length?"[]":gap?"[\n"+gap+o.join(",\n"+gap)+"\n"+a+"]":"["+o.join(",")+"]",gap=a,s}if(rep&&"object"==typeof rep)for(r=rep.length,n=0;r>n;n+=1)"string"==typeof rep[n]&&(i=rep[n],s=str(i,c),s&&o.push(quote(i)+(gap?": ":":")+s));else for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(s=str(i,c),s&&o.push(quote(i)+(gap?": ":":")+s));return s=0===o.length?"{}":gap?"{\n"+gap+o.join(",\n"+gap)+"\n"+a+"}":"{"+o.join(",")+"}",gap=a,s}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;Faye.stringify=function(e,t,n){var i;if(gap="",indent="","number"==typeof n)for(i=0;n>i;i+=1)indent+=" ";else"string"==typeof n&&(indent=n);if(rep=t,t&&"function"!=typeof t&&("object"!=typeof t||"number"!=typeof t.length))throw Error("JSON.stringify");return str("",{"":e})},"function"!=typeof JSON.stringify&&(JSON.stringify=Faye.stringify),"function"!=typeof JSON.parse&&(JSON.parse=function(text,reviver){function walk(e,t){var n,i,s=e[t];if(s&&"object"==typeof s)for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=walk(s,n),
|
2
|
+
void 0!==i?s[n]=i:delete s[n]);return reviver.call(e,t,s)}var j;if(text+="",cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(),Faye.Transport.WebSocket=Faye.extend(Faye.Class(Faye.Transport,{UNCONNECTED:1,CONNECTING:2,CONNECTED:3,batching:!1,isUsable:function(e,t){this.callback(function(){e.call(t,!0)}),this.errback(function(){e.call(t,!1)}),this.connect()},request:function(e){this._pending=this._pending||new Faye.Set;for(var t=0,n=e.length;n>t;t++)this._pending.add(e[t]);var i=new Faye.Promise;return this.callback(function(t){t&&1===t.readyState&&(t.send(Faye.toJSON(e)),Faye.Promise.fulfill(i,t))},this),this.connect(),{abort:function(){i.then(function(e){e.close()})}}},connect:function(){if(!Faye.Transport.WebSocket._unloaded&&(this._state=this._state||this.UNCONNECTED,this._state===this.UNCONNECTED)){this._state=this.CONNECTING;var e=this._createSocket();if(!e)return this.setDeferredStatus("failed");var t=this;e.onopen=function(){e.headers&&t._storeCookies(e.headers["set-cookie"]),t._socket=e,t._state=t.CONNECTED,t._everConnected=!0,t._ping(),t.setDeferredStatus("succeeded",e)};var n=!1;e.onclose=e.onerror=function(){if(!n){n=!0;var i=t._state===t.CONNECTED;e.onopen=e.onclose=e.onerror=e.onmessage=null,delete t._socket,t._state=t.UNCONNECTED,t.removeTimeout("ping"),t.setDeferredStatus("unknown");var s=t._pending?t._pending.toArray():[];delete t._pending,i?t._handleError(s,!0):t._everConnected?t._handleError(s):t.setDeferredStatus("failed")}},e.onmessage=function(e){var n=JSON.parse(e.data);if(n){n=[].concat(n);for(var i=0,s=n.length;s>i;i++)void 0!==n[i].successful&&t._pending.remove(n[i]);t._receive(n)}}}},close:function(){this._socket&&this._socket.close()},_createSocket:function(){var e=Faye.Transport.WebSocket.getSocketUrl(this.endpoint),t=this._dispatcher.headers,n=this._dispatcher.wsExtensions,i=this._getCookies(),s=this._dispatcher.tls,r={extensions:n,headers:t,proxy:this._proxy,tls:s};return""!==i&&(r.headers.Cookie=i),Faye.WebSocket?new Faye.WebSocket.Client(e,[],r):Faye.ENV.MozWebSocket?new MozWebSocket(e):Faye.ENV.WebSocket?new WebSocket(e):void 0},_ping:function(){this._socket&&(this._socket.send("[]"),this.addTimeout("ping",this._dispatcher.timeout/2,this._ping,this))}}),{PROTOCOLS:{"http:":"ws:","https:":"wss:"},create:function(e,t){var n=e.transports.websocket=e.transports.websocket||{};return n[t.href]=n[t.href]||new this(e,t),n[t.href]},getSocketUrl:function(e){return e=Faye.copyObject(e),e.protocol=this.PROTOCOLS[e.protocol],Faye.URI.stringify(e)},isUsable:function(e,t,n,i){this.create(e,t).isUsable(n,i)}}),Faye.extend(Faye.Transport.WebSocket.prototype,Faye.Deferrable),Faye.Transport.register("websocket",Faye.Transport.WebSocket),Faye.Event&&void 0!==Faye.ENV.onbeforeunload&&Faye.Event.on(Faye.ENV,"beforeunload",function(){Faye.Transport.WebSocket._unloaded=!0}),Faye.Transport.EventSource=Faye.extend(Faye.Class(Faye.Transport,{initialize:function(e,t){if(Faye.Transport.prototype.initialize.call(this,e,t),!Faye.ENV.EventSource)return this.setDeferredStatus("failed");this._xhr=new Faye.Transport.XHR(e,t),t=Faye.copyObject(t),t.pathname+="/"+e.clientId;var n=new EventSource(Faye.URI.stringify(t)),i=this;n.onopen=function(){i._everConnected=!0,i.setDeferredStatus("succeeded")},n.onerror=function(){i._everConnected?i._handleError([]):(i.setDeferredStatus("failed"),n.close())},n.onmessage=function(e){i._receive(JSON.parse(e.data))},this._socket=n},close:function(){this._socket&&(this._socket.onopen=this._socket.onerror=this._socket.onmessage=null,this._socket.close(),delete this._socket)},isUsable:function(e,t){this.callback(function(){e.call(t,!0)}),this.errback(function(){e.call(t,!1)})},encode:function(e){return this._xhr.encode(e)},request:function(e){return this._xhr.request(e)}}),{isUsable:function(e,t,n,i){var s=e.clientId;return s?void Faye.Transport.XHR.isUsable(e,t,function(s){return s?void this.create(e,t).isUsable(n,i):n.call(i,!1)},this):n.call(i,!1)},create:function(e,t){var n=e.transports.eventsource=e.transports.eventsource||{},i=e.clientId,s=Faye.copyObject(t);return s.pathname+="/"+(i||""),s=Faye.URI.stringify(s),n[s]=n[s]||new this(e,t),n[s]}}),Faye.extend(Faye.Transport.EventSource.prototype,Faye.Deferrable),Faye.Transport.register("eventsource",Faye.Transport.EventSource),Faye.Transport.XHR=Faye.extend(Faye.Class(Faye.Transport,{encode:function(e){return Faye.toJSON(e)},request:function(e){var t=this.endpoint.href,n=Faye.ENV.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest,i=this;n.open("POST",t,!0),n.setRequestHeader("Content-Type","application/json"),n.setRequestHeader("Pragma","no-cache"),n.setRequestHeader("X-Requested-With","XMLHttpRequest");var s=this._dispatcher.headers;for(var r in s)s.hasOwnProperty(r)&&n.setRequestHeader(r,s[r]);var o=function(){n.abort()};return void 0!==Faye.ENV.onbeforeunload&&Faye.Event.on(Faye.ENV,"beforeunload",o),n.onreadystatechange=function(){if(n&&4===n.readyState){var t=null,s=n.status,r=n.responseText,a=s>=200&&300>s||304===s||1223===s;if(void 0!==Faye.ENV.onbeforeunload&&Faye.Event.detach(Faye.ENV,"beforeunload",o),n.onreadystatechange=function(){},n=null,!a)return i._handleError(e);try{t=JSON.parse(r)}catch(c){}t?i._receive(t):i._handleError(e)}},n.send(this.encode(e)),n}}),{isUsable:function(e,t,n,i){n.call(i,Faye.URI.isSameOrigin(t))}}),Faye.Transport.register("long-polling",Faye.Transport.XHR),Faye.Transport.CORS=Faye.extend(Faye.Class(Faye.Transport,{encode:function(e){return"message="+encodeURIComponent(Faye.toJSON(e))},request:function(e){var t,n=Faye.ENV.XDomainRequest?XDomainRequest:XMLHttpRequest,i=new n,s=++Faye.Transport.CORS._id,r=this._dispatcher.headers,o=this;if(i.open("POST",Faye.URI.stringify(this.endpoint),!0),i.setRequestHeader){i.setRequestHeader("Pragma","no-cache");for(t in r)r.hasOwnProperty(t)&&i.setRequestHeader(t,r[t])}var a=function(){return i?(Faye.Transport.CORS._pending.remove(s),i.onload=i.onerror=i.ontimeout=i.onprogress=null,void(i=null)):!1};return i.onload=function(){var t=null;try{t=JSON.parse(i.responseText)}catch(n){}a(),t?o._receive(t):o._handleError(e)},i.onerror=i.ontimeout=function(){a(),o._handleError(e)},i.onprogress=function(){},n===Faye.ENV.XDomainRequest&&Faye.Transport.CORS._pending.add({id:s,xhr:i}),i.send(this.encode(e)),i}}),{_id:0,_pending:new Faye.Set,isUsable:function(e,t,n,i){if(Faye.URI.isSameOrigin(t))return n.call(i,!1);if(Faye.ENV.XDomainRequest)return n.call(i,t.protocol===Faye.ENV.location.protocol);if(Faye.ENV.XMLHttpRequest){var s=new Faye.ENV.XMLHttpRequest;return n.call(i,void 0!==s.withCredentials)}return n.call(i,!1)}}),Faye.Transport.register("cross-origin-long-polling",Faye.Transport.CORS),Faye.Transport.JSONP=Faye.extend(Faye.Class(Faye.Transport,{encode:function(e){var t=Faye.copyObject(this.endpoint);return t.query.message=Faye.toJSON(e),t.query.jsonp="__jsonp"+Faye.Transport.JSONP._cbCount+"__",Faye.URI.stringify(t)},request:function(e){var t=document.getElementsByTagName("head")[0],n=document.createElement("script"),i=Faye.Transport.JSONP.getCallbackName(),s=Faye.copyObject(this.endpoint),r=this;s.query.message=Faye.toJSON(e),s.query.jsonp=i;var o=function(){if(!Faye.ENV[i])return!1;Faye.ENV[i]=void 0;try{delete Faye.ENV[i]}catch(e){}n.parentNode.removeChild(n)};return Faye.ENV[i]=function(e){o(),r._receive(e)},n.type="text/javascript",n.src=Faye.URI.stringify(s),t.appendChild(n),n.onerror=function(){o(),r._handleError(e)},{abort:o}}}),{_cbCount:0,getCallbackName:function(){return this._cbCount+=1,"__jsonp"+this._cbCount+"__"},isUsable:function(e,t,n,i){n.call(i,!0)}}),Faye.Transport.register("callback-polling",Faye.Transport.JSONP)}();
|
3
|
+
//# sourceMappingURL=faye-browser-min.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["faye-browser.js"],"names":["Faye","VERSION","BAYEUX_VERSION","ID_LENGTH","JSONP_CALLBACK","CONNECTION_TYPES","MANDATORY_CONNECTION_TYPES","ENV","window","global","extend","dest","source","overwrite","key","hasOwnProperty","random","bitlength","this","maxLength","Math","ceil","log","string","csprng","length","validateOptions","options","validKeys","indexOf","Error","clientIdFromMessages","messages","connect","filter","concat","message","channel","clientId","copyObject","object","clone","i","Array","commonElement","lista","listb","n","list","needle","map","callback","context","result","push","call","array","asyncEach","iterator","calls","looping","iterate","resume","loop","toJSON","stringify","value","JSON","module","exports","Class","parent","methods","Object","klass","initialize","apply","arguments","bridge","prototype","xs","x","EventEmitter","isArray","toString","emit","type","_events","error","handler","args","slice","listeners","l","addListener","listener","on","once","self","g","removeListener","splice","removeAllListeners","Namespace","_used","exists","id","generate","name","release","defer","timeout","setTimeout","setImmediate","fn","process","nextTick","PENDING","FULFILLED","REJECTED","RETURN","THROW","Promise","task","_state","_onFulfilled","_onRejected","fulfill","reason","reject","then","onFulfilled","onRejected","next","registerOnFulfilled","registerOnRejected","promise","invoke","_value","_reason","_invoke","outcome","TypeError","resolve","called","_fulfill","v","r","shift","all","promises","fulfilled","deferred","pending","tuple","resolved","rejected","Set","_index","add","item","undefined","forEach","block","isEmpty","member","remove","removed","toArray","URI","isURI","uri","protocol","host","path","isSameOrigin","location","hostname","port","parse","url","parts","query","pairs","data","consume","pattern","replace","match","test","pathname","substr","split","search","decodeURIComponent","href","queryString","hash","encodeURIComponent","join","code","params","Grammar","ERROR","parseInt","versionMismatch","conntypeMismatch","extMismatch","badRequest","clientUnknown","parameterMissing","channelForbidden","channelUnknown","channelInvalid","extUnknown","publishFailed","serverError","Deferrable","errback","_promise","_reject","seconds","_timer","setDeferredStatus","status","clearTimeout","Publisher","countListeners","eventType","bind","_listeners","unbind","trigger","Timeouts","addTimeout","delay","_timeouts","removeTimeout","removeAllTimeouts","Logging","LOG_LEVELS","fatal","warn","info","debug","writeLog","messageArgs","level","logger","banner","className","e","CHANNEL_NAME","CHANNEL_PATTERN","Extensible","addExtension","extension","_extensions","added","removeExtension","pipeThroughExtensions","stage","request","extensions","pipe","Channel","isUnused","HANDSHAKE","CONNECT","SUBSCRIBE","UNSUBSCRIBE","DISCONNECT","META","SERVICE","expand","segments","channels","copy","unparse","isValid","isMeta","isService","isSubscribable","_channels","getKeys","keys","hasSubscription","subscribe","names","unsubscribe","distributeMessage","Publication","Subscription","client","_client","_callback","_context","_cancelled","cancel","Client","UNCONNECTED","CONNECTING","CONNECTED","DISCONNECTED","RETRY","NONE","CONNECTION_TIMEOUT","DEFAULT_ENDPOINT","INTERVAL","endpoint","_endpoint","_dispatcher","Dispatcher","_messageId","_responseCallbacks","_advice","reconnect","interval","_receiveMessage","Event","onbeforeunload","_disabled","disconnect","addWebsocketExtension","disable","feature","setHeader","handshake","selectTransport","_sendMessage","version","supportedConnectionTypes","getConnectionTypes","response","successful","retry","_connectRequest","connectionType","_cycleConnection","close","c","subscription","force","hasSubscribe","dead","publish","publication","_generateMessageId","sendMessage","pow","advice","_handleAdvice","_deliverMessage","MAX_REQUEST_SIZE","DEFAULT_RETRY","UP","DOWN","_alternates","endpoints","cookies","Cookies","CookieJar","_envelopes","headers","_scheduler","scheduler","Scheduler","transports","wsExtensions","proxy","_proxy","origin","exts","websocketExtensions","tls","ca","maxRequestSize","endpointFor","transport","_transport","Transport","transportTypes","get","attempts","deadline","Date","getTime","envelope","_sendEnvelope","timer","isDeliverable","abort","handleError","getTimeout","send","handleResponse","reply","succeed","immediate","req","fail","getInterval","made","now","DEFAULT_PORTS","http:","https:","ws:","wss:","SECURE_PROTOCOLS","MAX_DELAY","batching","dispatcher","_outbox","NodeAdapter","env","HTTPS_PROXY","https_proxy","HTTP_PROXY","http_proxy","encode","_flushLargeBatch","_publish","_connectMessage","_flush","last","pop","_receive","replies","_handleError","_getCookies","getCookiesSync","cookie","cookieString","_storeCookies","setCookie","Cookie","setCookieSync","allowed","disabled","_transports","pair","connType","connEndpoint","isUsable","create","register","t","_registry","element","eventName","wrapped","addEventListener","attachEvent","_element","_type","_handler","detach","removeEventListener","detachEvent","onunload","f","quote","escapable","lastIndex","a","meta","charCodeAt","str","holder","k","partial","mind","gap","rep","isFinite","String","indent","valueOf","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","Number","Boolean","cx","\b","\t","\n","\f","\r","\"","\\","replacer","space","","text","reviver","walk","j","eval","SyntaxError","WebSocket","_pending","socket","readyState","ws","_unloaded","_createSocket","onopen","_socket","_everConnected","_ping","closed","onclose","onerror","wasConnected","onmessage","event","getSocketUrl","MozWebSocket","PROTOCOLS","sockets","websocket","EventSource","_xhr","XHR","usable","eventsource","xhr","ActiveXObject","XMLHttpRequest","open","setRequestHeader","onreadystatechange","responseText","CORS","xhrClass","XDomainRequest","_id","cleanUp","onload","ontimeout","onprogress","withCredentials","JSONP","jsonp","_cbCount","head","document","getElementsByTagName","script","createElement","callbackName","getCallbackName","cleanup","parentNode","removeChild","src","appendChild"],"mappings":"CAAA,WACA,YAEA,IAAIA,OACFC,QAAkB,QAElBC,eAAkB,MAClBC,UAAkB,IAClBC,eAAkB,gBAClBC,kBAAmB,eAAgB,4BAA6B,mBAAoB,YAAa,cAAe,cAEhHC,4BAA6B,eAAgB,mBAAoB,cAEjEC,IAAwB,mBAAXC,QAA0BA,OAASC,OAEhDC,OAAQ,SAASC,EAAMC,EAAQC,GAC7B,IAAKD,EAAQ,MAAOD,EACpB,KAAK,GAAIG,KAAOF,GACTA,EAAOG,eAAeD,KACvBH,EAAKI,eAAeD,IAAQD,KAAc,GAC1CF,EAAKG,KAASF,EAAOE,KACvBH,EAAKG,GAAOF,EAAOE,IAEvB,OAAOH,IAGTK,OAAQ,SAASC,GACfA,EAAYA,GAAaC,KAAKf,SAG9B,KAFA,GAAIgB,GAAYC,KAAKC,KAAKJ,EAAYG,KAAKE,IAAI,GAAKF,KAAKE,IAAI,KACzDC,EAASC,OAAOP,EAAW,IACxBM,EAAOE,OAASN,GAAWI,EAAS,IAAMA,CACjD,OAAOA,IAGTG,gBAAiB,SAASC,EAASC,GACjC,IAAK,GAAId,KAAOa,GACd,GAAIT,KAAKW,QAAQD,EAAWd,GAAO,EACjC,KAAUgB,OAAM,wBAA0BhB,IAIhDiB,qBAAsB,SAASC,GAC7B,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zB,IAAIE,GAAU,WACZ,IAAK7iB,KAAKO,IAAIoiB,GAAe,OAAO,CACpC3iB,MAAKO,IAAIoiB,GAAgB1Y,MACzB,WAAajK,MAAKO,IAAIoiB,GAAgB,MAAOhT,IAC7C8S,EAAOK,WAAWC,YAAYN,GAiBhC,OAdAziB,MAAKO,IAAIoiB,GAAgB,SAAS/H,GAChCiI,IACA3c,EAAKyU,SAASC,IAGhB6H,EAAOnd,KAAO,kBACdmd,EAAOO,IAAOhjB,KAAKyK,IAAIxG,UAAUoP,GACjCiP,EAAKW,YAAYR,GAEjBA,EAAOpC,QAAU,WACfwC,IACA3c,EAAK2U,aAAa7Y,KAGZuW,MAAOsK,OAGjBR,SAAU,EAEVO,gBAAiB,WAEf,MADA1hB,MAAKmhB,UAAY,EACV,UAAYnhB,KAAKmhB,SAAW,MAGrCzG,SAAU,SAAShC,EAAYvG,EAAUlQ,EAAUC,GACjDD,EAASI,KAAKH,GAAS,MAI3BpD,KAAK4X,UAAUkE,SAAS,mBAAoB9b,KAAK4X,UAAUuK","file":"faye-browser-min.js","sourceRoot":""}
|
data/lib/faye-browser.js
ADDED
@@ -0,0 +1,2783 @@
|
|
1
|
+
(function() {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
var Faye = {
|
5
|
+
VERSION: '1.1.2',
|
6
|
+
|
7
|
+
BAYEUX_VERSION: '1.0',
|
8
|
+
ID_LENGTH: 160,
|
9
|
+
JSONP_CALLBACK: 'jsonpcallback',
|
10
|
+
CONNECTION_TYPES: ['long-polling', 'cross-origin-long-polling', 'callback-polling', 'websocket', 'eventsource', 'in-process'],
|
11
|
+
|
12
|
+
MANDATORY_CONNECTION_TYPES: ['long-polling', 'callback-polling', 'in-process'],
|
13
|
+
|
14
|
+
ENV: (typeof window !== 'undefined') ? window : global,
|
15
|
+
|
16
|
+
extend: function(dest, source, overwrite) {
|
17
|
+
if (!source) return dest;
|
18
|
+
for (var key in source) {
|
19
|
+
if (!source.hasOwnProperty(key)) continue;
|
20
|
+
if (dest.hasOwnProperty(key) && overwrite === false) continue;
|
21
|
+
if (dest[key] !== source[key])
|
22
|
+
dest[key] = source[key];
|
23
|
+
}
|
24
|
+
return dest;
|
25
|
+
},
|
26
|
+
|
27
|
+
random: function(bitlength) {
|
28
|
+
bitlength = bitlength || this.ID_LENGTH;
|
29
|
+
var maxLength = Math.ceil(bitlength * Math.log(2) / Math.log(36));
|
30
|
+
var string = csprng(bitlength, 36);
|
31
|
+
while (string.length < maxLength) string = '0' + string;
|
32
|
+
return string;
|
33
|
+
},
|
34
|
+
|
35
|
+
validateOptions: function(options, validKeys) {
|
36
|
+
for (var key in options) {
|
37
|
+
if (this.indexOf(validKeys, key) < 0)
|
38
|
+
throw new Error('Unrecognized option: ' + key);
|
39
|
+
}
|
40
|
+
},
|
41
|
+
|
42
|
+
clientIdFromMessages: function(messages) {
|
43
|
+
var connect = this.filter([].concat(messages), function(message) {
|
44
|
+
return message.channel === '/meta/connect';
|
45
|
+
});
|
46
|
+
return connect[0] && connect[0].clientId;
|
47
|
+
},
|
48
|
+
|
49
|
+
copyObject: function(object) {
|
50
|
+
var clone, i, key;
|
51
|
+
if (object instanceof Array) {
|
52
|
+
clone = [];
|
53
|
+
i = object.length;
|
54
|
+
while (i--) clone[i] = Faye.copyObject(object[i]);
|
55
|
+
return clone;
|
56
|
+
} else if (typeof object === 'object') {
|
57
|
+
clone = (object === null) ? null : {};
|
58
|
+
for (key in object) clone[key] = Faye.copyObject(object[key]);
|
59
|
+
return clone;
|
60
|
+
} else {
|
61
|
+
return object;
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
commonElement: function(lista, listb) {
|
66
|
+
for (var i = 0, n = lista.length; i < n; i++) {
|
67
|
+
if (this.indexOf(listb, lista[i]) !== -1)
|
68
|
+
return lista[i];
|
69
|
+
}
|
70
|
+
return null;
|
71
|
+
},
|
72
|
+
|
73
|
+
indexOf: function(list, needle) {
|
74
|
+
if (list.indexOf) return list.indexOf(needle);
|
75
|
+
|
76
|
+
for (var i = 0, n = list.length; i < n; i++) {
|
77
|
+
if (list[i] === needle) return i;
|
78
|
+
}
|
79
|
+
return -1;
|
80
|
+
},
|
81
|
+
|
82
|
+
map: function(object, callback, context) {
|
83
|
+
if (object.map) return object.map(callback, context);
|
84
|
+
var result = [];
|
85
|
+
|
86
|
+
if (object instanceof Array) {
|
87
|
+
for (var i = 0, n = object.length; i < n; i++) {
|
88
|
+
result.push(callback.call(context || null, object[i], i));
|
89
|
+
}
|
90
|
+
} else {
|
91
|
+
for (var key in object) {
|
92
|
+
if (!object.hasOwnProperty(key)) continue;
|
93
|
+
result.push(callback.call(context || null, key, object[key]));
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return result;
|
97
|
+
},
|
98
|
+
|
99
|
+
filter: function(array, callback, context) {
|
100
|
+
if (array.filter) return array.filter(callback, context);
|
101
|
+
var result = [];
|
102
|
+
for (var i = 0, n = array.length; i < n; i++) {
|
103
|
+
if (callback.call(context || null, array[i], i))
|
104
|
+
result.push(array[i]);
|
105
|
+
}
|
106
|
+
return result;
|
107
|
+
},
|
108
|
+
|
109
|
+
asyncEach: function(list, iterator, callback, context) {
|
110
|
+
var n = list.length,
|
111
|
+
i = -1,
|
112
|
+
calls = 0,
|
113
|
+
looping = false;
|
114
|
+
|
115
|
+
var iterate = function() {
|
116
|
+
calls -= 1;
|
117
|
+
i += 1;
|
118
|
+
if (i === n) return callback && callback.call(context);
|
119
|
+
iterator(list[i], resume);
|
120
|
+
};
|
121
|
+
|
122
|
+
var loop = function() {
|
123
|
+
if (looping) return;
|
124
|
+
looping = true;
|
125
|
+
while (calls > 0) iterate();
|
126
|
+
looping = false;
|
127
|
+
};
|
128
|
+
|
129
|
+
var resume = function() {
|
130
|
+
calls += 1;
|
131
|
+
loop();
|
132
|
+
};
|
133
|
+
resume();
|
134
|
+
},
|
135
|
+
|
136
|
+
// http://assanka.net/content/tech/2009/09/02/json2-js-vs-prototype/
|
137
|
+
toJSON: function(object) {
|
138
|
+
if (!this.stringify) return JSON.stringify(object);
|
139
|
+
|
140
|
+
return this.stringify(object, function(key, value) {
|
141
|
+
return (this[key] instanceof Array) ? this[key] : value;
|
142
|
+
});
|
143
|
+
}
|
144
|
+
};
|
145
|
+
|
146
|
+
if (typeof module !== 'undefined')
|
147
|
+
module.exports = Faye;
|
148
|
+
else if (typeof window !== 'undefined')
|
149
|
+
window.Faye = Faye;
|
150
|
+
|
151
|
+
Faye.Class = function(parent, methods) {
|
152
|
+
if (typeof parent !== 'function') {
|
153
|
+
methods = parent;
|
154
|
+
parent = Object;
|
155
|
+
}
|
156
|
+
|
157
|
+
var klass = function() {
|
158
|
+
if (!this.initialize) return this;
|
159
|
+
return this.initialize.apply(this, arguments) || this;
|
160
|
+
};
|
161
|
+
|
162
|
+
var bridge = function() {};
|
163
|
+
bridge.prototype = parent.prototype;
|
164
|
+
|
165
|
+
klass.prototype = new bridge();
|
166
|
+
Faye.extend(klass.prototype, methods);
|
167
|
+
|
168
|
+
return klass;
|
169
|
+
};
|
170
|
+
|
171
|
+
(function() {
|
172
|
+
var EventEmitter = Faye.EventEmitter = function() {};
|
173
|
+
|
174
|
+
/*
|
175
|
+
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
176
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
177
|
+
this software and associated documentation files (the "Software"), to deal in
|
178
|
+
the Software without restriction, including without limitation the rights to
|
179
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
180
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
181
|
+
so, subject to the following conditions:
|
182
|
+
|
183
|
+
The above copyright notice and this permission notice shall be included in all
|
184
|
+
copies or substantial portions of the Software.
|
185
|
+
|
186
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
187
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
188
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
189
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
190
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
191
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
192
|
+
SOFTWARE.
|
193
|
+
*/
|
194
|
+
|
195
|
+
var isArray = typeof Array.isArray === 'function'
|
196
|
+
? Array.isArray
|
197
|
+
: function (xs) {
|
198
|
+
return Object.prototype.toString.call(xs) === '[object Array]'
|
199
|
+
}
|
200
|
+
;
|
201
|
+
function indexOf (xs, x) {
|
202
|
+
if (xs.indexOf) return xs.indexOf(x);
|
203
|
+
for (var i = 0; i < xs.length; i++) {
|
204
|
+
if (x === xs[i]) return i;
|
205
|
+
}
|
206
|
+
return -1;
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
EventEmitter.prototype.emit = function(type) {
|
211
|
+
// If there is no 'error' event listener then throw.
|
212
|
+
if (type === 'error') {
|
213
|
+
if (!this._events || !this._events.error ||
|
214
|
+
(isArray(this._events.error) && !this._events.error.length))
|
215
|
+
{
|
216
|
+
if (arguments[1] instanceof Error) {
|
217
|
+
throw arguments[1]; // Unhandled 'error' event
|
218
|
+
} else {
|
219
|
+
throw new Error("Uncaught, unspecified 'error' event.");
|
220
|
+
}
|
221
|
+
return false;
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
if (!this._events) return false;
|
226
|
+
var handler = this._events[type];
|
227
|
+
if (!handler) return false;
|
228
|
+
|
229
|
+
if (typeof handler == 'function') {
|
230
|
+
switch (arguments.length) {
|
231
|
+
// fast cases
|
232
|
+
case 1:
|
233
|
+
handler.call(this);
|
234
|
+
break;
|
235
|
+
case 2:
|
236
|
+
handler.call(this, arguments[1]);
|
237
|
+
break;
|
238
|
+
case 3:
|
239
|
+
handler.call(this, arguments[1], arguments[2]);
|
240
|
+
break;
|
241
|
+
// slower
|
242
|
+
default:
|
243
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
244
|
+
handler.apply(this, args);
|
245
|
+
}
|
246
|
+
return true;
|
247
|
+
|
248
|
+
} else if (isArray(handler)) {
|
249
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
250
|
+
|
251
|
+
var listeners = handler.slice();
|
252
|
+
for (var i = 0, l = listeners.length; i < l; i++) {
|
253
|
+
listeners[i].apply(this, args);
|
254
|
+
}
|
255
|
+
return true;
|
256
|
+
|
257
|
+
} else {
|
258
|
+
return false;
|
259
|
+
}
|
260
|
+
};
|
261
|
+
|
262
|
+
// EventEmitter is defined in src/node_events.cc
|
263
|
+
// EventEmitter.prototype.emit() is also defined there.
|
264
|
+
EventEmitter.prototype.addListener = function(type, listener) {
|
265
|
+
if ('function' !== typeof listener) {
|
266
|
+
throw new Error('addListener only takes instances of Function');
|
267
|
+
}
|
268
|
+
|
269
|
+
if (!this._events) this._events = {};
|
270
|
+
|
271
|
+
// To avoid recursion in the case that type == "newListeners"! Before
|
272
|
+
// adding it to the listeners, first emit "newListeners".
|
273
|
+
this.emit('newListener', type, listener);
|
274
|
+
|
275
|
+
if (!this._events[type]) {
|
276
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
277
|
+
this._events[type] = listener;
|
278
|
+
} else if (isArray(this._events[type])) {
|
279
|
+
// If we've already got an array, just append.
|
280
|
+
this._events[type].push(listener);
|
281
|
+
} else {
|
282
|
+
// Adding the second element, need to change to array.
|
283
|
+
this._events[type] = [this._events[type], listener];
|
284
|
+
}
|
285
|
+
|
286
|
+
return this;
|
287
|
+
};
|
288
|
+
|
289
|
+
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
290
|
+
|
291
|
+
EventEmitter.prototype.once = function(type, listener) {
|
292
|
+
var self = this;
|
293
|
+
self.on(type, function g() {
|
294
|
+
self.removeListener(type, g);
|
295
|
+
listener.apply(this, arguments);
|
296
|
+
});
|
297
|
+
|
298
|
+
return this;
|
299
|
+
};
|
300
|
+
|
301
|
+
EventEmitter.prototype.removeListener = function(type, listener) {
|
302
|
+
if ('function' !== typeof listener) {
|
303
|
+
throw new Error('removeListener only takes instances of Function');
|
304
|
+
}
|
305
|
+
|
306
|
+
// does not use listeners(), so no side effect of creating _events[type]
|
307
|
+
if (!this._events || !this._events[type]) return this;
|
308
|
+
|
309
|
+
var list = this._events[type];
|
310
|
+
|
311
|
+
if (isArray(list)) {
|
312
|
+
var i = indexOf(list, listener);
|
313
|
+
if (i < 0) return this;
|
314
|
+
list.splice(i, 1);
|
315
|
+
if (list.length == 0)
|
316
|
+
delete this._events[type];
|
317
|
+
} else if (this._events[type] === listener) {
|
318
|
+
delete this._events[type];
|
319
|
+
}
|
320
|
+
|
321
|
+
return this;
|
322
|
+
};
|
323
|
+
|
324
|
+
EventEmitter.prototype.removeAllListeners = function(type) {
|
325
|
+
if (arguments.length === 0) {
|
326
|
+
this._events = {};
|
327
|
+
return this;
|
328
|
+
}
|
329
|
+
|
330
|
+
// does not use listeners(), so no side effect of creating _events[type]
|
331
|
+
if (type && this._events && this._events[type]) this._events[type] = null;
|
332
|
+
return this;
|
333
|
+
};
|
334
|
+
|
335
|
+
EventEmitter.prototype.listeners = function(type) {
|
336
|
+
if (!this._events) this._events = {};
|
337
|
+
if (!this._events[type]) this._events[type] = [];
|
338
|
+
if (!isArray(this._events[type])) {
|
339
|
+
this._events[type] = [this._events[type]];
|
340
|
+
}
|
341
|
+
return this._events[type];
|
342
|
+
};
|
343
|
+
|
344
|
+
})();
|
345
|
+
|
346
|
+
Faye.Namespace = Faye.Class({
|
347
|
+
initialize: function() {
|
348
|
+
this._used = {};
|
349
|
+
},
|
350
|
+
|
351
|
+
exists: function(id) {
|
352
|
+
return this._used.hasOwnProperty(id);
|
353
|
+
},
|
354
|
+
|
355
|
+
generate: function() {
|
356
|
+
var name = Faye.random();
|
357
|
+
while (this._used.hasOwnProperty(name))
|
358
|
+
name = Faye.random();
|
359
|
+
return this._used[name] = name;
|
360
|
+
},
|
361
|
+
|
362
|
+
release: function(id) {
|
363
|
+
delete this._used[id];
|
364
|
+
}
|
365
|
+
});
|
366
|
+
|
367
|
+
(function() {
|
368
|
+
'use strict';
|
369
|
+
|
370
|
+
var timeout = setTimeout, defer;
|
371
|
+
|
372
|
+
if (typeof setImmediate === 'function')
|
373
|
+
defer = function(fn) { setImmediate(fn) };
|
374
|
+
else if (typeof process === 'object' && process.nextTick)
|
375
|
+
defer = function(fn) { process.nextTick(fn) };
|
376
|
+
else
|
377
|
+
defer = function(fn) { timeout(fn, 0) };
|
378
|
+
|
379
|
+
var PENDING = 0,
|
380
|
+
FULFILLED = 1,
|
381
|
+
REJECTED = 2;
|
382
|
+
|
383
|
+
var RETURN = function(x) { return x },
|
384
|
+
THROW = function(x) { throw x };
|
385
|
+
|
386
|
+
var Promise = function(task) {
|
387
|
+
this._state = PENDING;
|
388
|
+
this._onFulfilled = [];
|
389
|
+
this._onRejected = [];
|
390
|
+
|
391
|
+
if (typeof task !== 'function') return;
|
392
|
+
var self = this;
|
393
|
+
|
394
|
+
task(function(value) { fulfill(self, value) },
|
395
|
+
function(reason) { reject(self, reason) });
|
396
|
+
};
|
397
|
+
|
398
|
+
Promise.prototype.then = function(onFulfilled, onRejected) {
|
399
|
+
var next = new Promise();
|
400
|
+
registerOnFulfilled(this, onFulfilled, next);
|
401
|
+
registerOnRejected(this, onRejected, next);
|
402
|
+
return next;
|
403
|
+
};
|
404
|
+
|
405
|
+
var registerOnFulfilled = function(promise, onFulfilled, next) {
|
406
|
+
if (typeof onFulfilled !== 'function') onFulfilled = RETURN;
|
407
|
+
var handler = function(value) { invoke(onFulfilled, value, next) };
|
408
|
+
|
409
|
+
if (promise._state === PENDING) {
|
410
|
+
promise._onFulfilled.push(handler);
|
411
|
+
} else if (promise._state === FULFILLED) {
|
412
|
+
handler(promise._value);
|
413
|
+
}
|
414
|
+
};
|
415
|
+
|
416
|
+
var registerOnRejected = function(promise, onRejected, next) {
|
417
|
+
if (typeof onRejected !== 'function') onRejected = THROW;
|
418
|
+
var handler = function(reason) { invoke(onRejected, reason, next) };
|
419
|
+
|
420
|
+
if (promise._state === PENDING) {
|
421
|
+
promise._onRejected.push(handler);
|
422
|
+
} else if (promise._state === REJECTED) {
|
423
|
+
handler(promise._reason);
|
424
|
+
}
|
425
|
+
};
|
426
|
+
|
427
|
+
var invoke = function(fn, value, next) {
|
428
|
+
defer(function() { _invoke(fn, value, next) });
|
429
|
+
};
|
430
|
+
|
431
|
+
var _invoke = function(fn, value, next) {
|
432
|
+
var outcome;
|
433
|
+
|
434
|
+
try {
|
435
|
+
outcome = fn(value);
|
436
|
+
} catch (error) {
|
437
|
+
return reject(next, error);
|
438
|
+
}
|
439
|
+
|
440
|
+
if (outcome === next) {
|
441
|
+
reject(next, new TypeError('Recursive promise chain detected'));
|
442
|
+
} else {
|
443
|
+
fulfill(next, outcome);
|
444
|
+
}
|
445
|
+
};
|
446
|
+
|
447
|
+
var fulfill = Promise.fulfill = Promise.resolve = function(promise, value) {
|
448
|
+
var called = false, type, then;
|
449
|
+
|
450
|
+
try {
|
451
|
+
type = typeof value;
|
452
|
+
then = value !== null && (type === 'function' || type === 'object') && value.then;
|
453
|
+
|
454
|
+
if (typeof then !== 'function') return _fulfill(promise, value);
|
455
|
+
|
456
|
+
then.call(value, function(v) {
|
457
|
+
if (!(called ^ (called = true))) return;
|
458
|
+
fulfill(promise, v);
|
459
|
+
}, function(r) {
|
460
|
+
if (!(called ^ (called = true))) return;
|
461
|
+
reject(promise, r);
|
462
|
+
});
|
463
|
+
} catch (error) {
|
464
|
+
if (!(called ^ (called = true))) return;
|
465
|
+
reject(promise, error);
|
466
|
+
}
|
467
|
+
};
|
468
|
+
|
469
|
+
var _fulfill = function(promise, value) {
|
470
|
+
if (promise._state !== PENDING) return;
|
471
|
+
|
472
|
+
promise._state = FULFILLED;
|
473
|
+
promise._value = value;
|
474
|
+
promise._onRejected = [];
|
475
|
+
|
476
|
+
var onFulfilled = promise._onFulfilled, fn;
|
477
|
+
while (fn = onFulfilled.shift()) fn(value);
|
478
|
+
};
|
479
|
+
|
480
|
+
var reject = Promise.reject = function(promise, reason) {
|
481
|
+
if (promise._state !== PENDING) return;
|
482
|
+
|
483
|
+
promise._state = REJECTED;
|
484
|
+
promise._reason = reason;
|
485
|
+
promise._onFulfilled = [];
|
486
|
+
|
487
|
+
var onRejected = promise._onRejected, fn;
|
488
|
+
while (fn = onRejected.shift()) fn(reason);
|
489
|
+
};
|
490
|
+
|
491
|
+
Promise.all = function(promises) {
|
492
|
+
return new Promise(function(fulfill, reject) {
|
493
|
+
var list = [],
|
494
|
+
n = promises.length,
|
495
|
+
i;
|
496
|
+
|
497
|
+
if (n === 0) return fulfill(list);
|
498
|
+
|
499
|
+
for (i = 0; i < n; i++) (function(promise, i) {
|
500
|
+
Promise.fulfilled(promise).then(function(value) {
|
501
|
+
list[i] = value;
|
502
|
+
if (--n === 0) fulfill(list);
|
503
|
+
}, reject);
|
504
|
+
})(promises[i], i);
|
505
|
+
});
|
506
|
+
};
|
507
|
+
|
508
|
+
Promise.defer = defer;
|
509
|
+
|
510
|
+
Promise.deferred = Promise.pending = function() {
|
511
|
+
var tuple = {};
|
512
|
+
|
513
|
+
tuple.promise = new Promise(function(fulfill, reject) {
|
514
|
+
tuple.fulfill = tuple.resolve = fulfill;
|
515
|
+
tuple.reject = reject;
|
516
|
+
});
|
517
|
+
return tuple;
|
518
|
+
};
|
519
|
+
|
520
|
+
Promise.fulfilled = Promise.resolved = function(value) {
|
521
|
+
return new Promise(function(fulfill, reject) { fulfill(value) });
|
522
|
+
};
|
523
|
+
|
524
|
+
Promise.rejected = function(reason) {
|
525
|
+
return new Promise(function(fulfill, reject) { reject(reason) });
|
526
|
+
};
|
527
|
+
|
528
|
+
if (typeof Faye === 'undefined')
|
529
|
+
module.exports = Promise;
|
530
|
+
else
|
531
|
+
Faye.Promise = Promise;
|
532
|
+
|
533
|
+
})();
|
534
|
+
|
535
|
+
Faye.Set = Faye.Class({
|
536
|
+
initialize: function() {
|
537
|
+
this._index = {};
|
538
|
+
},
|
539
|
+
|
540
|
+
add: function(item) {
|
541
|
+
var key = (item.id !== undefined) ? item.id : item;
|
542
|
+
if (this._index.hasOwnProperty(key)) return false;
|
543
|
+
this._index[key] = item;
|
544
|
+
return true;
|
545
|
+
},
|
546
|
+
|
547
|
+
forEach: function(block, context) {
|
548
|
+
for (var key in this._index) {
|
549
|
+
if (this._index.hasOwnProperty(key))
|
550
|
+
block.call(context, this._index[key]);
|
551
|
+
}
|
552
|
+
},
|
553
|
+
|
554
|
+
isEmpty: function() {
|
555
|
+
for (var key in this._index) {
|
556
|
+
if (this._index.hasOwnProperty(key)) return false;
|
557
|
+
}
|
558
|
+
return true;
|
559
|
+
},
|
560
|
+
|
561
|
+
member: function(item) {
|
562
|
+
for (var key in this._index) {
|
563
|
+
if (this._index[key] === item) return true;
|
564
|
+
}
|
565
|
+
return false;
|
566
|
+
},
|
567
|
+
|
568
|
+
remove: function(item) {
|
569
|
+
var key = (item.id !== undefined) ? item.id : item;
|
570
|
+
var removed = this._index[key];
|
571
|
+
delete this._index[key];
|
572
|
+
return removed;
|
573
|
+
},
|
574
|
+
|
575
|
+
toArray: function() {
|
576
|
+
var array = [];
|
577
|
+
this.forEach(function(item) { array.push(item) });
|
578
|
+
return array;
|
579
|
+
}
|
580
|
+
});
|
581
|
+
|
582
|
+
Faye.URI = {
|
583
|
+
isURI: function(uri) {
|
584
|
+
return uri && uri.protocol && uri.host && uri.path;
|
585
|
+
},
|
586
|
+
|
587
|
+
isSameOrigin: function(uri) {
|
588
|
+
var location = Faye.ENV.location;
|
589
|
+
return uri.protocol === location.protocol &&
|
590
|
+
uri.hostname === location.hostname &&
|
591
|
+
uri.port === location.port;
|
592
|
+
},
|
593
|
+
|
594
|
+
parse: function(url) {
|
595
|
+
if (typeof url !== 'string') return url;
|
596
|
+
var uri = {}, parts, query, pairs, i, n, data;
|
597
|
+
|
598
|
+
var consume = function(name, pattern) {
|
599
|
+
url = url.replace(pattern, function(match) {
|
600
|
+
uri[name] = match;
|
601
|
+
return '';
|
602
|
+
});
|
603
|
+
uri[name] = uri[name] || '';
|
604
|
+
};
|
605
|
+
|
606
|
+
consume('protocol', /^[a-z]+\:/i);
|
607
|
+
consume('host', /^\/\/[^\/\?#]+/);
|
608
|
+
|
609
|
+
if (!/^\//.test(url) && !uri.host)
|
610
|
+
url = Faye.ENV.location.pathname.replace(/[^\/]*$/, '') + url;
|
611
|
+
|
612
|
+
consume('pathname', /^[^\?#]*/);
|
613
|
+
consume('search', /^\?[^#]*/);
|
614
|
+
consume('hash', /^#.*/);
|
615
|
+
|
616
|
+
uri.protocol = uri.protocol || Faye.ENV.location.protocol;
|
617
|
+
|
618
|
+
if (uri.host) {
|
619
|
+
uri.host = uri.host.substr(2);
|
620
|
+
parts = uri.host.split(':');
|
621
|
+
uri.hostname = parts[0];
|
622
|
+
uri.port = parts[1] || '';
|
623
|
+
} else {
|
624
|
+
uri.host = Faye.ENV.location.host;
|
625
|
+
uri.hostname = Faye.ENV.location.hostname;
|
626
|
+
uri.port = Faye.ENV.location.port;
|
627
|
+
}
|
628
|
+
|
629
|
+
uri.pathname = uri.pathname || '/';
|
630
|
+
uri.path = uri.pathname + uri.search;
|
631
|
+
|
632
|
+
query = uri.search.replace(/^\?/, '');
|
633
|
+
pairs = query ? query.split('&') : [];
|
634
|
+
data = {};
|
635
|
+
|
636
|
+
for (i = 0, n = pairs.length; i < n; i++) {
|
637
|
+
parts = pairs[i].split('=');
|
638
|
+
data[decodeURIComponent(parts[0] || '')] = decodeURIComponent(parts[1] || '');
|
639
|
+
}
|
640
|
+
|
641
|
+
uri.query = data;
|
642
|
+
|
643
|
+
uri.href = this.stringify(uri);
|
644
|
+
return uri;
|
645
|
+
},
|
646
|
+
|
647
|
+
stringify: function(uri) {
|
648
|
+
var string = uri.protocol + '//' + uri.hostname;
|
649
|
+
if (uri.port) string += ':' + uri.port;
|
650
|
+
string += uri.pathname + this.queryString(uri.query) + (uri.hash || '');
|
651
|
+
return string;
|
652
|
+
},
|
653
|
+
|
654
|
+
queryString: function(query) {
|
655
|
+
var pairs = [];
|
656
|
+
for (var key in query) {
|
657
|
+
if (!query.hasOwnProperty(key)) continue;
|
658
|
+
pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(query[key]));
|
659
|
+
}
|
660
|
+
if (pairs.length === 0) return '';
|
661
|
+
return '?' + pairs.join('&');
|
662
|
+
}
|
663
|
+
};
|
664
|
+
|
665
|
+
Faye.Error = Faye.Class({
|
666
|
+
initialize: function(code, params, message) {
|
667
|
+
this.code = code;
|
668
|
+
this.params = Array.prototype.slice.call(params);
|
669
|
+
this.message = message;
|
670
|
+
},
|
671
|
+
|
672
|
+
toString: function() {
|
673
|
+
return this.code + ':' +
|
674
|
+
this.params.join(',') + ':' +
|
675
|
+
this.message;
|
676
|
+
}
|
677
|
+
});
|
678
|
+
|
679
|
+
Faye.Error.parse = function(message) {
|
680
|
+
message = message || '';
|
681
|
+
if (!Faye.Grammar.ERROR.test(message)) return new this(null, [], message);
|
682
|
+
|
683
|
+
var parts = message.split(':'),
|
684
|
+
code = parseInt(parts[0]),
|
685
|
+
params = parts[1].split(','),
|
686
|
+
message = parts[2];
|
687
|
+
|
688
|
+
return new this(code, params, message);
|
689
|
+
};
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
|
694
|
+
Faye.Error.versionMismatch = function() {
|
695
|
+
return new this(300, arguments, 'Version mismatch').toString();
|
696
|
+
};
|
697
|
+
|
698
|
+
Faye.Error.conntypeMismatch = function() {
|
699
|
+
return new this(301, arguments, 'Connection types not supported').toString();
|
700
|
+
};
|
701
|
+
|
702
|
+
Faye.Error.extMismatch = function() {
|
703
|
+
return new this(302, arguments, 'Extension mismatch').toString();
|
704
|
+
};
|
705
|
+
|
706
|
+
Faye.Error.badRequest = function() {
|
707
|
+
return new this(400, arguments, 'Bad request').toString();
|
708
|
+
};
|
709
|
+
|
710
|
+
Faye.Error.clientUnknown = function() {
|
711
|
+
return new this(401, arguments, 'Unknown client').toString();
|
712
|
+
};
|
713
|
+
|
714
|
+
Faye.Error.parameterMissing = function() {
|
715
|
+
return new this(402, arguments, 'Missing required parameter').toString();
|
716
|
+
};
|
717
|
+
|
718
|
+
Faye.Error.channelForbidden = function() {
|
719
|
+
return new this(403, arguments, 'Forbidden channel').toString();
|
720
|
+
};
|
721
|
+
|
722
|
+
Faye.Error.channelUnknown = function() {
|
723
|
+
return new this(404, arguments, 'Unknown channel').toString();
|
724
|
+
};
|
725
|
+
|
726
|
+
Faye.Error.channelInvalid = function() {
|
727
|
+
return new this(405, arguments, 'Invalid channel').toString();
|
728
|
+
};
|
729
|
+
|
730
|
+
Faye.Error.extUnknown = function() {
|
731
|
+
return new this(406, arguments, 'Unknown extension').toString();
|
732
|
+
};
|
733
|
+
|
734
|
+
Faye.Error.publishFailed = function() {
|
735
|
+
return new this(407, arguments, 'Failed to publish').toString();
|
736
|
+
};
|
737
|
+
|
738
|
+
Faye.Error.serverError = function() {
|
739
|
+
return new this(500, arguments, 'Internal server error').toString();
|
740
|
+
};
|
741
|
+
|
742
|
+
|
743
|
+
Faye.Deferrable = {
|
744
|
+
then: function(callback, errback) {
|
745
|
+
var self = this;
|
746
|
+
if (!this._promise)
|
747
|
+
this._promise = new Faye.Promise(function(fulfill, reject) {
|
748
|
+
self._fulfill = fulfill;
|
749
|
+
self._reject = reject;
|
750
|
+
});
|
751
|
+
|
752
|
+
if (arguments.length === 0)
|
753
|
+
return this._promise;
|
754
|
+
else
|
755
|
+
return this._promise.then(callback, errback);
|
756
|
+
},
|
757
|
+
|
758
|
+
callback: function(callback, context) {
|
759
|
+
return this.then(function(value) { callback.call(context, value) });
|
760
|
+
},
|
761
|
+
|
762
|
+
errback: function(callback, context) {
|
763
|
+
return this.then(null, function(reason) { callback.call(context, reason) });
|
764
|
+
},
|
765
|
+
|
766
|
+
timeout: function(seconds, message) {
|
767
|
+
this.then();
|
768
|
+
var self = this;
|
769
|
+
this._timer = Faye.ENV.setTimeout(function() {
|
770
|
+
self._reject(message);
|
771
|
+
}, seconds * 1000);
|
772
|
+
},
|
773
|
+
|
774
|
+
setDeferredStatus: function(status, value) {
|
775
|
+
if (this._timer) Faye.ENV.clearTimeout(this._timer);
|
776
|
+
|
777
|
+
this.then();
|
778
|
+
|
779
|
+
if (status === 'succeeded')
|
780
|
+
this._fulfill(value);
|
781
|
+
else if (status === 'failed')
|
782
|
+
this._reject(value);
|
783
|
+
else
|
784
|
+
delete this._promise;
|
785
|
+
}
|
786
|
+
};
|
787
|
+
|
788
|
+
Faye.Publisher = {
|
789
|
+
countListeners: function(eventType) {
|
790
|
+
return this.listeners(eventType).length;
|
791
|
+
},
|
792
|
+
|
793
|
+
bind: function(eventType, listener, context) {
|
794
|
+
var slice = Array.prototype.slice,
|
795
|
+
handler = function() { listener.apply(context, slice.call(arguments)) };
|
796
|
+
|
797
|
+
this._listeners = this._listeners || [];
|
798
|
+
this._listeners.push([eventType, listener, context, handler]);
|
799
|
+
return this.on(eventType, handler);
|
800
|
+
},
|
801
|
+
|
802
|
+
unbind: function(eventType, listener, context) {
|
803
|
+
this._listeners = this._listeners || [];
|
804
|
+
var n = this._listeners.length, tuple;
|
805
|
+
|
806
|
+
while (n--) {
|
807
|
+
tuple = this._listeners[n];
|
808
|
+
if (tuple[0] !== eventType) continue;
|
809
|
+
if (listener && (tuple[1] !== listener || tuple[2] !== context)) continue;
|
810
|
+
this._listeners.splice(n, 1);
|
811
|
+
this.removeListener(eventType, tuple[3]);
|
812
|
+
}
|
813
|
+
}
|
814
|
+
};
|
815
|
+
|
816
|
+
Faye.extend(Faye.Publisher, Faye.EventEmitter.prototype);
|
817
|
+
Faye.Publisher.trigger = Faye.Publisher.emit;
|
818
|
+
|
819
|
+
Faye.Timeouts = {
|
820
|
+
addTimeout: function(name, delay, callback, context) {
|
821
|
+
this._timeouts = this._timeouts || {};
|
822
|
+
if (this._timeouts.hasOwnProperty(name)) return;
|
823
|
+
var self = this;
|
824
|
+
this._timeouts[name] = Faye.ENV.setTimeout(function() {
|
825
|
+
delete self._timeouts[name];
|
826
|
+
callback.call(context);
|
827
|
+
}, 1000 * delay);
|
828
|
+
},
|
829
|
+
|
830
|
+
removeTimeout: function(name) {
|
831
|
+
this._timeouts = this._timeouts || {};
|
832
|
+
var timeout = this._timeouts[name];
|
833
|
+
if (!timeout) return;
|
834
|
+
Faye.ENV.clearTimeout(timeout);
|
835
|
+
delete this._timeouts[name];
|
836
|
+
},
|
837
|
+
|
838
|
+
removeAllTimeouts: function() {
|
839
|
+
this._timeouts = this._timeouts || {};
|
840
|
+
for (var name in this._timeouts) this.removeTimeout(name);
|
841
|
+
}
|
842
|
+
};
|
843
|
+
|
844
|
+
Faye.Logging = {
|
845
|
+
LOG_LEVELS: {
|
846
|
+
fatal: 4,
|
847
|
+
error: 3,
|
848
|
+
warn: 2,
|
849
|
+
info: 1,
|
850
|
+
debug: 0
|
851
|
+
},
|
852
|
+
|
853
|
+
writeLog: function(messageArgs, level) {
|
854
|
+
if (!Faye.logger) return;
|
855
|
+
|
856
|
+
var args = Array.prototype.slice.apply(messageArgs),
|
857
|
+
banner = '[Faye',
|
858
|
+
klass = this.className,
|
859
|
+
|
860
|
+
message = args.shift().replace(/\?/g, function() {
|
861
|
+
try {
|
862
|
+
return Faye.toJSON(args.shift());
|
863
|
+
} catch (e) {
|
864
|
+
return '[Object]';
|
865
|
+
}
|
866
|
+
});
|
867
|
+
|
868
|
+
for (var key in Faye) {
|
869
|
+
if (klass) continue;
|
870
|
+
if (typeof Faye[key] !== 'function') continue;
|
871
|
+
if (this instanceof Faye[key]) klass = key;
|
872
|
+
}
|
873
|
+
if (klass) banner += '.' + klass;
|
874
|
+
banner += '] ';
|
875
|
+
|
876
|
+
if (typeof Faye.logger[level] === 'function')
|
877
|
+
Faye.logger[level](banner + message);
|
878
|
+
else if (typeof Faye.logger === 'function')
|
879
|
+
Faye.logger(banner + message);
|
880
|
+
}
|
881
|
+
};
|
882
|
+
|
883
|
+
(function() {
|
884
|
+
for (var key in Faye.Logging.LOG_LEVELS)
|
885
|
+
(function(level) {
|
886
|
+
Faye.Logging[level] = function() {
|
887
|
+
this.writeLog(arguments, level);
|
888
|
+
};
|
889
|
+
})(key);
|
890
|
+
})();
|
891
|
+
|
892
|
+
Faye.Grammar = {
|
893
|
+
CHANNEL_NAME: /^\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*$/,
|
894
|
+
CHANNEL_PATTERN: /^(\/(((([a-z]|[A-Z])|[0-9])|(\-|\_|\!|\~|\(|\)|\$|\@)))+)*\/\*{1,2}$/,
|
895
|
+
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])|(\-|\_|\!|\~|\(|\)|\$|\@)| |\/|\*|\.))*)$/,
|
896
|
+
VERSION: /^([0-9])+(\.(([a-z]|[A-Z])|[0-9])(((([a-z]|[A-Z])|[0-9])|\-|\_))*)*$/
|
897
|
+
};
|
898
|
+
|
899
|
+
Faye.Extensible = {
|
900
|
+
addExtension: function(extension) {
|
901
|
+
this._extensions = this._extensions || [];
|
902
|
+
this._extensions.push(extension);
|
903
|
+
if (extension.added) extension.added(this);
|
904
|
+
},
|
905
|
+
|
906
|
+
removeExtension: function(extension) {
|
907
|
+
if (!this._extensions) return;
|
908
|
+
var i = this._extensions.length;
|
909
|
+
while (i--) {
|
910
|
+
if (this._extensions[i] !== extension) continue;
|
911
|
+
this._extensions.splice(i,1);
|
912
|
+
if (extension.removed) extension.removed(this);
|
913
|
+
}
|
914
|
+
},
|
915
|
+
|
916
|
+
pipeThroughExtensions: function(stage, message, request, callback, context) {
|
917
|
+
this.debug('Passing through ? extensions: ?', stage, message);
|
918
|
+
|
919
|
+
if (!this._extensions) return callback.call(context, message);
|
920
|
+
var extensions = this._extensions.slice();
|
921
|
+
|
922
|
+
var pipe = function(message) {
|
923
|
+
if (!message) return callback.call(context, message);
|
924
|
+
|
925
|
+
var extension = extensions.shift();
|
926
|
+
if (!extension) return callback.call(context, message);
|
927
|
+
|
928
|
+
var fn = extension[stage];
|
929
|
+
if (!fn) return pipe(message);
|
930
|
+
|
931
|
+
if (fn.length >= 3) extension[stage](message, request, pipe);
|
932
|
+
else extension[stage](message, pipe);
|
933
|
+
};
|
934
|
+
pipe(message);
|
935
|
+
}
|
936
|
+
};
|
937
|
+
|
938
|
+
Faye.extend(Faye.Extensible, Faye.Logging);
|
939
|
+
|
940
|
+
Faye.Channel = Faye.Class({
|
941
|
+
initialize: function(name) {
|
942
|
+
this.id = this.name = name;
|
943
|
+
},
|
944
|
+
|
945
|
+
push: function(message) {
|
946
|
+
this.trigger('message', message);
|
947
|
+
},
|
948
|
+
|
949
|
+
isUnused: function() {
|
950
|
+
return this.countListeners('message') === 0;
|
951
|
+
}
|
952
|
+
});
|
953
|
+
|
954
|
+
Faye.extend(Faye.Channel.prototype, Faye.Publisher);
|
955
|
+
|
956
|
+
Faye.extend(Faye.Channel, {
|
957
|
+
HANDSHAKE: '/meta/handshake',
|
958
|
+
CONNECT: '/meta/connect',
|
959
|
+
SUBSCRIBE: '/meta/subscribe',
|
960
|
+
UNSUBSCRIBE: '/meta/unsubscribe',
|
961
|
+
DISCONNECT: '/meta/disconnect',
|
962
|
+
|
963
|
+
META: 'meta',
|
964
|
+
SERVICE: 'service',
|
965
|
+
|
966
|
+
expand: function(name) {
|
967
|
+
var segments = this.parse(name),
|
968
|
+
channels = ['/**', name];
|
969
|
+
|
970
|
+
var copy = segments.slice();
|
971
|
+
copy[copy.length - 1] = '*';
|
972
|
+
channels.push(this.unparse(copy));
|
973
|
+
|
974
|
+
for (var i = 1, n = segments.length; i < n; i++) {
|
975
|
+
copy = segments.slice(0, i);
|
976
|
+
copy.push('**');
|
977
|
+
channels.push(this.unparse(copy));
|
978
|
+
}
|
979
|
+
|
980
|
+
return channels;
|
981
|
+
},
|
982
|
+
|
983
|
+
isValid: function(name) {
|
984
|
+
return Faye.Grammar.CHANNEL_NAME.test(name) ||
|
985
|
+
Faye.Grammar.CHANNEL_PATTERN.test(name);
|
986
|
+
},
|
987
|
+
|
988
|
+
parse: function(name) {
|
989
|
+
if (!this.isValid(name)) return null;
|
990
|
+
return name.split('/').slice(1);
|
991
|
+
},
|
992
|
+
|
993
|
+
unparse: function(segments) {
|
994
|
+
return '/' + segments.join('/');
|
995
|
+
},
|
996
|
+
|
997
|
+
isMeta: function(name) {
|
998
|
+
var segments = this.parse(name);
|
999
|
+
return segments ? (segments[0] === this.META) : null;
|
1000
|
+
},
|
1001
|
+
|
1002
|
+
isService: function(name) {
|
1003
|
+
var segments = this.parse(name);
|
1004
|
+
return segments ? (segments[0] === this.SERVICE) : null;
|
1005
|
+
},
|
1006
|
+
|
1007
|
+
isSubscribable: function(name) {
|
1008
|
+
if (!this.isValid(name)) return null;
|
1009
|
+
return !this.isMeta(name) && !this.isService(name);
|
1010
|
+
},
|
1011
|
+
|
1012
|
+
Set: Faye.Class({
|
1013
|
+
initialize: function() {
|
1014
|
+
this._channels = {};
|
1015
|
+
},
|
1016
|
+
|
1017
|
+
getKeys: function() {
|
1018
|
+
var keys = [];
|
1019
|
+
for (var key in this._channels) keys.push(key);
|
1020
|
+
return keys;
|
1021
|
+
},
|
1022
|
+
|
1023
|
+
remove: function(name) {
|
1024
|
+
delete this._channels[name];
|
1025
|
+
},
|
1026
|
+
|
1027
|
+
hasSubscription: function(name) {
|
1028
|
+
return this._channels.hasOwnProperty(name);
|
1029
|
+
},
|
1030
|
+
|
1031
|
+
subscribe: function(names, callback, context) {
|
1032
|
+
var name;
|
1033
|
+
for (var i = 0, n = names.length; i < n; i++) {
|
1034
|
+
name = names[i];
|
1035
|
+
var channel = this._channels[name] = this._channels[name] || new Faye.Channel(name);
|
1036
|
+
if (callback) channel.bind('message', callback, context);
|
1037
|
+
}
|
1038
|
+
},
|
1039
|
+
|
1040
|
+
unsubscribe: function(name, callback, context) {
|
1041
|
+
var channel = this._channels[name];
|
1042
|
+
if (!channel) return false;
|
1043
|
+
channel.unbind('message', callback, context);
|
1044
|
+
|
1045
|
+
if (channel.isUnused()) {
|
1046
|
+
this.remove(name);
|
1047
|
+
return true;
|
1048
|
+
} else {
|
1049
|
+
return false;
|
1050
|
+
}
|
1051
|
+
},
|
1052
|
+
|
1053
|
+
distributeMessage: function(message) {
|
1054
|
+
var channels = Faye.Channel.expand(message.channel);
|
1055
|
+
|
1056
|
+
for (var i = 0, n = channels.length; i < n; i++) {
|
1057
|
+
var channel = this._channels[channels[i]];
|
1058
|
+
if (channel) channel.trigger('message', message.data);
|
1059
|
+
}
|
1060
|
+
}
|
1061
|
+
})
|
1062
|
+
});
|
1063
|
+
|
1064
|
+
Faye.Publication = Faye.Class(Faye.Deferrable);
|
1065
|
+
|
1066
|
+
Faye.Subscription = Faye.Class({
|
1067
|
+
initialize: function(client, channels, callback, context) {
|
1068
|
+
this._client = client;
|
1069
|
+
this._channels = channels;
|
1070
|
+
this._callback = callback;
|
1071
|
+
this._context = context;
|
1072
|
+
this._cancelled = false;
|
1073
|
+
},
|
1074
|
+
|
1075
|
+
cancel: function() {
|
1076
|
+
if (this._cancelled) return;
|
1077
|
+
this._client.unsubscribe(this._channels, this._callback, this._context);
|
1078
|
+
this._cancelled = true;
|
1079
|
+
},
|
1080
|
+
|
1081
|
+
unsubscribe: function() {
|
1082
|
+
this.cancel();
|
1083
|
+
}
|
1084
|
+
});
|
1085
|
+
|
1086
|
+
Faye.extend(Faye.Subscription.prototype, Faye.Deferrable);
|
1087
|
+
|
1088
|
+
Faye.Client = Faye.Class({
|
1089
|
+
UNCONNECTED: 1,
|
1090
|
+
CONNECTING: 2,
|
1091
|
+
CONNECTED: 3,
|
1092
|
+
DISCONNECTED: 4,
|
1093
|
+
|
1094
|
+
HANDSHAKE: 'handshake',
|
1095
|
+
RETRY: 'retry',
|
1096
|
+
NONE: 'none',
|
1097
|
+
|
1098
|
+
CONNECTION_TIMEOUT: 60,
|
1099
|
+
|
1100
|
+
DEFAULT_ENDPOINT: '/bayeux',
|
1101
|
+
INTERVAL: 0,
|
1102
|
+
|
1103
|
+
initialize: function(endpoint, options) {
|
1104
|
+
this.info('New client created for ?', endpoint);
|
1105
|
+
options = options || {};
|
1106
|
+
|
1107
|
+
Faye.validateOptions(options, ['interval', 'timeout', 'endpoints', 'proxy', 'retry', 'scheduler', 'websocketExtensions', 'tls', 'ca']);
|
1108
|
+
|
1109
|
+
this._endpoint = endpoint || this.DEFAULT_ENDPOINT;
|
1110
|
+
this._channels = new Faye.Channel.Set();
|
1111
|
+
this._dispatcher = new Faye.Dispatcher(this, this._endpoint, options);
|
1112
|
+
|
1113
|
+
this._messageId = 0;
|
1114
|
+
this._state = this.UNCONNECTED;
|
1115
|
+
|
1116
|
+
this._responseCallbacks = {};
|
1117
|
+
|
1118
|
+
this._advice = {
|
1119
|
+
reconnect: this.RETRY,
|
1120
|
+
interval: 1000 * (options.interval || this.INTERVAL),
|
1121
|
+
timeout: 1000 * (options.timeout || this.CONNECTION_TIMEOUT)
|
1122
|
+
};
|
1123
|
+
this._dispatcher.timeout = this._advice.timeout / 1000;
|
1124
|
+
|
1125
|
+
this._dispatcher.bind('message', this._receiveMessage, this);
|
1126
|
+
|
1127
|
+
if (Faye.Event && Faye.ENV.onbeforeunload !== undefined)
|
1128
|
+
Faye.Event.on(Faye.ENV, 'beforeunload', function() {
|
1129
|
+
if (Faye.indexOf(this._dispatcher._disabled, 'autodisconnect') < 0)
|
1130
|
+
this.disconnect();
|
1131
|
+
}, this);
|
1132
|
+
},
|
1133
|
+
|
1134
|
+
addWebsocketExtension: function(extension) {
|
1135
|
+
return this._dispatcher.addWebsocketExtension(extension);
|
1136
|
+
},
|
1137
|
+
|
1138
|
+
disable: function(feature) {
|
1139
|
+
return this._dispatcher.disable(feature);
|
1140
|
+
},
|
1141
|
+
|
1142
|
+
setHeader: function(name, value) {
|
1143
|
+
return this._dispatcher.setHeader(name, value);
|
1144
|
+
},
|
1145
|
+
|
1146
|
+
// Request
|
1147
|
+
// MUST include: * channel
|
1148
|
+
// * version
|
1149
|
+
// * supportedConnectionTypes
|
1150
|
+
// MAY include: * minimumVersion
|
1151
|
+
// * ext
|
1152
|
+
// * id
|
1153
|
+
//
|
1154
|
+
// Success Response Failed Response
|
1155
|
+
// MUST include: * channel MUST include: * channel
|
1156
|
+
// * version * successful
|
1157
|
+
// * supportedConnectionTypes * error
|
1158
|
+
// * clientId MAY include: * supportedConnectionTypes
|
1159
|
+
// * successful * advice
|
1160
|
+
// MAY include: * minimumVersion * version
|
1161
|
+
// * advice * minimumVersion
|
1162
|
+
// * ext * ext
|
1163
|
+
// * id * id
|
1164
|
+
// * authSuccessful
|
1165
|
+
handshake: function(callback, context) {
|
1166
|
+
if (this._advice.reconnect === this.NONE) return;
|
1167
|
+
if (this._state !== this.UNCONNECTED) return;
|
1168
|
+
|
1169
|
+
this._state = this.CONNECTING;
|
1170
|
+
var self = this;
|
1171
|
+
|
1172
|
+
this.info('Initiating handshake with ?', Faye.URI.stringify(this._endpoint));
|
1173
|
+
this._dispatcher.selectTransport(Faye.MANDATORY_CONNECTION_TYPES);
|
1174
|
+
|
1175
|
+
this._sendMessage({
|
1176
|
+
channel: Faye.Channel.HANDSHAKE,
|
1177
|
+
version: Faye.BAYEUX_VERSION,
|
1178
|
+
supportedConnectionTypes: this._dispatcher.getConnectionTypes()
|
1179
|
+
|
1180
|
+
}, {}, function(response) {
|
1181
|
+
|
1182
|
+
if (response.successful) {
|
1183
|
+
this._state = this.CONNECTED;
|
1184
|
+
this._dispatcher.clientId = response.clientId;
|
1185
|
+
|
1186
|
+
this._dispatcher.selectTransport(response.supportedConnectionTypes);
|
1187
|
+
|
1188
|
+
this.info('Handshake successful: ?', this._dispatcher.clientId);
|
1189
|
+
|
1190
|
+
this.subscribe(this._channels.getKeys(), true);
|
1191
|
+
if (callback) Faye.Promise.defer(function() { callback.call(context) });
|
1192
|
+
|
1193
|
+
} else {
|
1194
|
+
this.info('Handshake unsuccessful');
|
1195
|
+
Faye.ENV.setTimeout(function() { self.handshake(callback, context) }, this._dispatcher.retry * 1000);
|
1196
|
+
this._state = this.UNCONNECTED;
|
1197
|
+
}
|
1198
|
+
}, this);
|
1199
|
+
},
|
1200
|
+
|
1201
|
+
// Request Response
|
1202
|
+
// MUST include: * channel MUST include: * channel
|
1203
|
+
// * clientId * successful
|
1204
|
+
// * connectionType * clientId
|
1205
|
+
// MAY include: * ext MAY include: * error
|
1206
|
+
// * id * advice
|
1207
|
+
// * ext
|
1208
|
+
// * id
|
1209
|
+
// * timestamp
|
1210
|
+
connect: function(callback, context) {
|
1211
|
+
if (this._advice.reconnect === this.NONE) return;
|
1212
|
+
if (this._state === this.DISCONNECTED) return;
|
1213
|
+
|
1214
|
+
if (this._state === this.UNCONNECTED)
|
1215
|
+
return this.handshake(function() { this.connect(callback, context) }, this);
|
1216
|
+
|
1217
|
+
this.callback(callback, context);
|
1218
|
+
if (this._state !== this.CONNECTED) return;
|
1219
|
+
|
1220
|
+
this.info('Calling deferred actions for ?', this._dispatcher.clientId);
|
1221
|
+
this.setDeferredStatus('succeeded');
|
1222
|
+
this.setDeferredStatus('unknown');
|
1223
|
+
|
1224
|
+
if (this._connectRequest) return;
|
1225
|
+
this._connectRequest = true;
|
1226
|
+
|
1227
|
+
this.info('Initiating connection for ?', this._dispatcher.clientId);
|
1228
|
+
|
1229
|
+
this._sendMessage({
|
1230
|
+
channel: Faye.Channel.CONNECT,
|
1231
|
+
clientId: this._dispatcher.clientId,
|
1232
|
+
connectionType: this._dispatcher.connectionType
|
1233
|
+
|
1234
|
+
}, {}, this._cycleConnection, this);
|
1235
|
+
},
|
1236
|
+
|
1237
|
+
// Request Response
|
1238
|
+
// MUST include: * channel MUST include: * channel
|
1239
|
+
// * clientId * successful
|
1240
|
+
// MAY include: * ext * clientId
|
1241
|
+
// * id MAY include: * error
|
1242
|
+
// * ext
|
1243
|
+
// * id
|
1244
|
+
disconnect: function() {
|
1245
|
+
if (this._state !== this.CONNECTED) return;
|
1246
|
+
this._state = this.DISCONNECTED;
|
1247
|
+
|
1248
|
+
this.info('Disconnecting ?', this._dispatcher.clientId);
|
1249
|
+
var promise = new Faye.Publication();
|
1250
|
+
|
1251
|
+
this._sendMessage({
|
1252
|
+
channel: Faye.Channel.DISCONNECT,
|
1253
|
+
clientId: this._dispatcher.clientId
|
1254
|
+
|
1255
|
+
}, {}, function(response) {
|
1256
|
+
if (response.successful) {
|
1257
|
+
this._dispatcher.close();
|
1258
|
+
promise.setDeferredStatus('succeeded');
|
1259
|
+
} else {
|
1260
|
+
promise.setDeferredStatus('failed', Faye.Error.parse(response.error));
|
1261
|
+
}
|
1262
|
+
}, this);
|
1263
|
+
|
1264
|
+
this.info('Clearing channel listeners for ?', this._dispatcher.clientId);
|
1265
|
+
this._channels = new Faye.Channel.Set();
|
1266
|
+
|
1267
|
+
return promise;
|
1268
|
+
},
|
1269
|
+
|
1270
|
+
// Request Response
|
1271
|
+
// MUST include: * channel MUST include: * channel
|
1272
|
+
// * clientId * successful
|
1273
|
+
// * subscription * clientId
|
1274
|
+
// MAY include: * ext * subscription
|
1275
|
+
// * id MAY include: * error
|
1276
|
+
// * advice
|
1277
|
+
// * ext
|
1278
|
+
// * id
|
1279
|
+
// * timestamp
|
1280
|
+
subscribe: function(channel, callback, context) {
|
1281
|
+
if (channel instanceof Array)
|
1282
|
+
return Faye.map(channel, function(c) {
|
1283
|
+
return this.subscribe(c, callback, context);
|
1284
|
+
}, this);
|
1285
|
+
|
1286
|
+
var subscription = new Faye.Subscription(this, channel, callback, context),
|
1287
|
+
force = (callback === true),
|
1288
|
+
hasSubscribe = this._channels.hasSubscription(channel);
|
1289
|
+
|
1290
|
+
if (hasSubscribe && !force) {
|
1291
|
+
this._channels.subscribe([channel], callback, context);
|
1292
|
+
subscription.setDeferredStatus('succeeded');
|
1293
|
+
return subscription;
|
1294
|
+
}
|
1295
|
+
|
1296
|
+
this.connect(function() {
|
1297
|
+
this.info('Client ? attempting to subscribe to ?', this._dispatcher.clientId, channel);
|
1298
|
+
if (!force) this._channels.subscribe([channel], callback, context);
|
1299
|
+
|
1300
|
+
this._sendMessage({
|
1301
|
+
channel: Faye.Channel.SUBSCRIBE,
|
1302
|
+
clientId: this._dispatcher.clientId,
|
1303
|
+
subscription: channel
|
1304
|
+
|
1305
|
+
}, {}, function(response) {
|
1306
|
+
if (!response.successful) {
|
1307
|
+
subscription.setDeferredStatus('failed', Faye.Error.parse(response.error));
|
1308
|
+
return this._channels.unsubscribe(channel, callback, context);
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
var channels = [].concat(response.subscription);
|
1312
|
+
this.info('Subscription acknowledged for ? to ?', this._dispatcher.clientId, channels);
|
1313
|
+
subscription.setDeferredStatus('succeeded');
|
1314
|
+
}, this);
|
1315
|
+
}, this);
|
1316
|
+
|
1317
|
+
return subscription;
|
1318
|
+
},
|
1319
|
+
|
1320
|
+
// Request Response
|
1321
|
+
// MUST include: * channel MUST include: * channel
|
1322
|
+
// * clientId * successful
|
1323
|
+
// * subscription * clientId
|
1324
|
+
// MAY include: * ext * subscription
|
1325
|
+
// * id MAY include: * error
|
1326
|
+
// * advice
|
1327
|
+
// * ext
|
1328
|
+
// * id
|
1329
|
+
// * timestamp
|
1330
|
+
unsubscribe: function(channel, callback, context) {
|
1331
|
+
if (channel instanceof Array)
|
1332
|
+
return Faye.map(channel, function(c) {
|
1333
|
+
return this.unsubscribe(c, callback, context);
|
1334
|
+
}, this);
|
1335
|
+
|
1336
|
+
var dead = this._channels.unsubscribe(channel, callback, context);
|
1337
|
+
if (!dead) return;
|
1338
|
+
|
1339
|
+
this.connect(function() {
|
1340
|
+
this.info('Client ? attempting to unsubscribe from ?', this._dispatcher.clientId, channel);
|
1341
|
+
|
1342
|
+
this._sendMessage({
|
1343
|
+
channel: Faye.Channel.UNSUBSCRIBE,
|
1344
|
+
clientId: this._dispatcher.clientId,
|
1345
|
+
subscription: channel
|
1346
|
+
|
1347
|
+
}, {}, function(response) {
|
1348
|
+
if (!response.successful) return;
|
1349
|
+
|
1350
|
+
var channels = [].concat(response.subscription);
|
1351
|
+
this.info('Unsubscription acknowledged for ? from ?', this._dispatcher.clientId, channels);
|
1352
|
+
}, this);
|
1353
|
+
}, this);
|
1354
|
+
},
|
1355
|
+
|
1356
|
+
// Request Response
|
1357
|
+
// MUST include: * channel MUST include: * channel
|
1358
|
+
// * data * successful
|
1359
|
+
// MAY include: * clientId MAY include: * id
|
1360
|
+
// * id * error
|
1361
|
+
// * ext * ext
|
1362
|
+
publish: function(channel, data, options) {
|
1363
|
+
Faye.validateOptions(options || {}, ['attempts', 'deadline']);
|
1364
|
+
var publication = new Faye.Publication();
|
1365
|
+
|
1366
|
+
this.connect(function() {
|
1367
|
+
this.info('Client ? queueing published message to ?: ?', this._dispatcher.clientId, channel, data);
|
1368
|
+
|
1369
|
+
this._sendMessage({
|
1370
|
+
channel: channel,
|
1371
|
+
data: data,
|
1372
|
+
clientId: this._dispatcher.clientId
|
1373
|
+
|
1374
|
+
}, options, function(response) {
|
1375
|
+
if (response.successful)
|
1376
|
+
publication.setDeferredStatus('succeeded');
|
1377
|
+
else
|
1378
|
+
publication.setDeferredStatus('failed', Faye.Error.parse(response.error));
|
1379
|
+
}, this);
|
1380
|
+
}, this);
|
1381
|
+
|
1382
|
+
return publication;
|
1383
|
+
},
|
1384
|
+
|
1385
|
+
_sendMessage: function(message, options, callback, context) {
|
1386
|
+
message.id = this._generateMessageId();
|
1387
|
+
|
1388
|
+
var timeout = this._advice.timeout
|
1389
|
+
? 1.2 * this._advice.timeout / 1000
|
1390
|
+
: 1.2 * this._dispatcher.retry;
|
1391
|
+
|
1392
|
+
this.pipeThroughExtensions('outgoing', message, null, function(message) {
|
1393
|
+
if (!message) return;
|
1394
|
+
if (callback) this._responseCallbacks[message.id] = [callback, context];
|
1395
|
+
this._dispatcher.sendMessage(message, timeout, options || {});
|
1396
|
+
}, this);
|
1397
|
+
},
|
1398
|
+
|
1399
|
+
_generateMessageId: function() {
|
1400
|
+
this._messageId += 1;
|
1401
|
+
if (this._messageId >= Math.pow(2,32)) this._messageId = 0;
|
1402
|
+
return this._messageId.toString(36);
|
1403
|
+
},
|
1404
|
+
|
1405
|
+
_receiveMessage: function(message) {
|
1406
|
+
var id = message.id, callback;
|
1407
|
+
|
1408
|
+
if (message.successful !== undefined) {
|
1409
|
+
callback = this._responseCallbacks[id];
|
1410
|
+
delete this._responseCallbacks[id];
|
1411
|
+
}
|
1412
|
+
|
1413
|
+
this.pipeThroughExtensions('incoming', message, null, function(message) {
|
1414
|
+
if (!message) return;
|
1415
|
+
if (message.advice) this._handleAdvice(message.advice);
|
1416
|
+
this._deliverMessage(message);
|
1417
|
+
if (callback) callback[0].call(callback[1], message);
|
1418
|
+
}, this);
|
1419
|
+
},
|
1420
|
+
|
1421
|
+
_handleAdvice: function(advice) {
|
1422
|
+
Faye.extend(this._advice, advice);
|
1423
|
+
this._dispatcher.timeout = this._advice.timeout / 1000;
|
1424
|
+
|
1425
|
+
if (this._advice.reconnect === this.HANDSHAKE && this._state !== this.DISCONNECTED) {
|
1426
|
+
this._state = this.UNCONNECTED;
|
1427
|
+
this._dispatcher.clientId = null;
|
1428
|
+
this._cycleConnection();
|
1429
|
+
}
|
1430
|
+
},
|
1431
|
+
|
1432
|
+
_deliverMessage: function(message) {
|
1433
|
+
if (!message.channel || message.data === undefined) return;
|
1434
|
+
this.info('Client ? calling listeners for ? with ?', this._dispatcher.clientId, message.channel, message.data);
|
1435
|
+
this._channels.distributeMessage(message);
|
1436
|
+
},
|
1437
|
+
|
1438
|
+
_cycleConnection: function() {
|
1439
|
+
if (this._connectRequest) {
|
1440
|
+
this._connectRequest = null;
|
1441
|
+
this.info('Closed connection for ?', this._dispatcher.clientId);
|
1442
|
+
}
|
1443
|
+
var self = this;
|
1444
|
+
Faye.ENV.setTimeout(function() { self.connect() }, this._advice.interval);
|
1445
|
+
}
|
1446
|
+
});
|
1447
|
+
|
1448
|
+
Faye.extend(Faye.Client.prototype, Faye.Deferrable);
|
1449
|
+
Faye.extend(Faye.Client.prototype, Faye.Publisher);
|
1450
|
+
Faye.extend(Faye.Client.prototype, Faye.Logging);
|
1451
|
+
Faye.extend(Faye.Client.prototype, Faye.Extensible);
|
1452
|
+
|
1453
|
+
Faye.Dispatcher = Faye.Class({
|
1454
|
+
MAX_REQUEST_SIZE: 2048,
|
1455
|
+
DEFAULT_RETRY: 5,
|
1456
|
+
|
1457
|
+
UP: 1,
|
1458
|
+
DOWN: 2,
|
1459
|
+
|
1460
|
+
initialize: function(client, endpoint, options) {
|
1461
|
+
this._client = client;
|
1462
|
+
this.endpoint = Faye.URI.parse(endpoint);
|
1463
|
+
this._alternates = options.endpoints || {};
|
1464
|
+
|
1465
|
+
this.cookies = Faye.Cookies && new Faye.Cookies.CookieJar();
|
1466
|
+
this._disabled = [];
|
1467
|
+
this._envelopes = {};
|
1468
|
+
this.headers = {};
|
1469
|
+
this.retry = options.retry || this.DEFAULT_RETRY;
|
1470
|
+
this._scheduler = options.scheduler || Faye.Scheduler;
|
1471
|
+
this._state = 0;
|
1472
|
+
this.transports = {};
|
1473
|
+
this.wsExtensions = [];
|
1474
|
+
|
1475
|
+
this.proxy = options.proxy || {};
|
1476
|
+
if (typeof this._proxy === 'string') this._proxy = {origin: this._proxy};
|
1477
|
+
|
1478
|
+
var exts = options.websocketExtensions;
|
1479
|
+
if (exts) {
|
1480
|
+
exts = [].concat(exts);
|
1481
|
+
for (var i = 0, n = exts.length; i < n; i++)
|
1482
|
+
this.addWebsocketExtension(exts[i]);
|
1483
|
+
}
|
1484
|
+
|
1485
|
+
this.tls = options.tls || {};
|
1486
|
+
this.tls.ca = this.tls.ca || options.ca;
|
1487
|
+
|
1488
|
+
for (var type in this._alternates)
|
1489
|
+
this._alternates[type] = Faye.URI.parse(this._alternates[type]);
|
1490
|
+
|
1491
|
+
this.maxRequestSize = this.MAX_REQUEST_SIZE;
|
1492
|
+
},
|
1493
|
+
|
1494
|
+
endpointFor: function(connectionType) {
|
1495
|
+
return this._alternates[connectionType] || this.endpoint;
|
1496
|
+
},
|
1497
|
+
|
1498
|
+
addWebsocketExtension: function(extension) {
|
1499
|
+
this.wsExtensions.push(extension);
|
1500
|
+
},
|
1501
|
+
|
1502
|
+
disable: function(feature) {
|
1503
|
+
this._disabled.push(feature);
|
1504
|
+
},
|
1505
|
+
|
1506
|
+
setHeader: function(name, value) {
|
1507
|
+
this.headers[name] = value;
|
1508
|
+
},
|
1509
|
+
|
1510
|
+
close: function() {
|
1511
|
+
var transport = this._transport;
|
1512
|
+
delete this._transport;
|
1513
|
+
if (transport) transport.close();
|
1514
|
+
},
|
1515
|
+
|
1516
|
+
getConnectionTypes: function() {
|
1517
|
+
return Faye.Transport.getConnectionTypes();
|
1518
|
+
},
|
1519
|
+
|
1520
|
+
selectTransport: function(transportTypes) {
|
1521
|
+
Faye.Transport.get(this, transportTypes, this._disabled, function(transport) {
|
1522
|
+
this.debug('Selected ? transport for ?', transport.connectionType, Faye.URI.stringify(transport.endpoint));
|
1523
|
+
|
1524
|
+
if (transport === this._transport) return;
|
1525
|
+
if (this._transport) this._transport.close();
|
1526
|
+
|
1527
|
+
this._transport = transport;
|
1528
|
+
this.connectionType = transport.connectionType;
|
1529
|
+
}, this);
|
1530
|
+
},
|
1531
|
+
|
1532
|
+
sendMessage: function(message, timeout, options) {
|
1533
|
+
options = options || {};
|
1534
|
+
|
1535
|
+
var id = message.id,
|
1536
|
+
attempts = options.attempts,
|
1537
|
+
deadline = options.deadline && new Date().getTime() + (options.deadline * 1000),
|
1538
|
+
envelope = this._envelopes[id],
|
1539
|
+
scheduler;
|
1540
|
+
|
1541
|
+
if (!envelope) {
|
1542
|
+
scheduler = new this._scheduler(message, {timeout: timeout, interval: this.retry, attempts: attempts, deadline: deadline});
|
1543
|
+
envelope = this._envelopes[id] = {message: message, scheduler: scheduler};
|
1544
|
+
}
|
1545
|
+
|
1546
|
+
this._sendEnvelope(envelope);
|
1547
|
+
},
|
1548
|
+
|
1549
|
+
_sendEnvelope: function(envelope) {
|
1550
|
+
if (!this._transport) return;
|
1551
|
+
if (envelope.request || envelope.timer) return;
|
1552
|
+
|
1553
|
+
var message = envelope.message,
|
1554
|
+
scheduler = envelope.scheduler,
|
1555
|
+
self = this;
|
1556
|
+
|
1557
|
+
if (!scheduler.isDeliverable()) {
|
1558
|
+
scheduler.abort();
|
1559
|
+
delete this._envelopes[message.id];
|
1560
|
+
return;
|
1561
|
+
}
|
1562
|
+
|
1563
|
+
envelope.timer = Faye.ENV.setTimeout(function() {
|
1564
|
+
self.handleError(message);
|
1565
|
+
}, scheduler.getTimeout() * 1000);
|
1566
|
+
|
1567
|
+
scheduler.send();
|
1568
|
+
envelope.request = this._transport.sendMessage(message);
|
1569
|
+
},
|
1570
|
+
|
1571
|
+
handleResponse: function(reply) {
|
1572
|
+
var envelope = this._envelopes[reply.id];
|
1573
|
+
|
1574
|
+
if (reply.successful !== undefined && envelope) {
|
1575
|
+
envelope.scheduler.succeed();
|
1576
|
+
delete this._envelopes[reply.id];
|
1577
|
+
Faye.ENV.clearTimeout(envelope.timer);
|
1578
|
+
}
|
1579
|
+
|
1580
|
+
this.trigger('message', reply);
|
1581
|
+
|
1582
|
+
if (this._state === this.UP) return;
|
1583
|
+
this._state = this.UP;
|
1584
|
+
this._client.trigger('transport:up');
|
1585
|
+
},
|
1586
|
+
|
1587
|
+
handleError: function(message, immediate) {
|
1588
|
+
var envelope = this._envelopes[message.id],
|
1589
|
+
request = envelope && envelope.request,
|
1590
|
+
self = this;
|
1591
|
+
|
1592
|
+
if (!request) return;
|
1593
|
+
|
1594
|
+
request.then(function(req) {
|
1595
|
+
if (req && req.abort) req.abort();
|
1596
|
+
});
|
1597
|
+
|
1598
|
+
var scheduler = envelope.scheduler;
|
1599
|
+
scheduler.fail();
|
1600
|
+
|
1601
|
+
Faye.ENV.clearTimeout(envelope.timer);
|
1602
|
+
envelope.request = envelope.timer = null;
|
1603
|
+
|
1604
|
+
if (immediate) {
|
1605
|
+
this._sendEnvelope(envelope);
|
1606
|
+
} else {
|
1607
|
+
envelope.timer = Faye.ENV.setTimeout(function() {
|
1608
|
+
envelope.timer = null;
|
1609
|
+
self._sendEnvelope(envelope);
|
1610
|
+
}, scheduler.getInterval() * 1000);
|
1611
|
+
}
|
1612
|
+
|
1613
|
+
if (this._state === this.DOWN) return;
|
1614
|
+
this._state = this.DOWN;
|
1615
|
+
this._client.trigger('transport:down');
|
1616
|
+
}
|
1617
|
+
});
|
1618
|
+
|
1619
|
+
Faye.extend(Faye.Dispatcher.prototype, Faye.Publisher);
|
1620
|
+
Faye.extend(Faye.Dispatcher.prototype, Faye.Logging);
|
1621
|
+
|
1622
|
+
Faye.Scheduler = function(message, options) {
|
1623
|
+
this.message = message;
|
1624
|
+
this.options = options;
|
1625
|
+
this.attempts = 0;
|
1626
|
+
};
|
1627
|
+
|
1628
|
+
Faye.extend(Faye.Scheduler.prototype, {
|
1629
|
+
getTimeout: function() {
|
1630
|
+
return this.options.timeout;
|
1631
|
+
},
|
1632
|
+
|
1633
|
+
getInterval: function() {
|
1634
|
+
return this.options.interval;
|
1635
|
+
},
|
1636
|
+
|
1637
|
+
isDeliverable: function() {
|
1638
|
+
var attempts = this.options.attempts,
|
1639
|
+
made = this.attempts,
|
1640
|
+
deadline = this.options.deadline,
|
1641
|
+
now = new Date().getTime();
|
1642
|
+
|
1643
|
+
if (attempts !== undefined && made >= attempts)
|
1644
|
+
return false;
|
1645
|
+
|
1646
|
+
if (deadline !== undefined && now > deadline)
|
1647
|
+
return false;
|
1648
|
+
|
1649
|
+
return true;
|
1650
|
+
},
|
1651
|
+
|
1652
|
+
send: function() {
|
1653
|
+
this.attempts += 1;
|
1654
|
+
},
|
1655
|
+
|
1656
|
+
succeed: function() {},
|
1657
|
+
|
1658
|
+
fail: function() {},
|
1659
|
+
|
1660
|
+
abort: function() {}
|
1661
|
+
});
|
1662
|
+
|
1663
|
+
Faye.Transport = Faye.extend(Faye.Class({
|
1664
|
+
DEFAULT_PORTS: {'http:': 80, 'https:': 443, 'ws:': 80, 'wss:': 443},
|
1665
|
+
SECURE_PROTOCOLS: ['https:', 'wss:'],
|
1666
|
+
MAX_DELAY: 0,
|
1667
|
+
|
1668
|
+
batching: true,
|
1669
|
+
|
1670
|
+
initialize: function(dispatcher, endpoint) {
|
1671
|
+
this._dispatcher = dispatcher;
|
1672
|
+
this.endpoint = endpoint;
|
1673
|
+
this._outbox = [];
|
1674
|
+
this._proxy = Faye.extend({}, this._dispatcher.proxy);
|
1675
|
+
|
1676
|
+
if (!this._proxy.origin && Faye.NodeAdapter) {
|
1677
|
+
this._proxy.origin = Faye.indexOf(this.SECURE_PROTOCOLS, this.endpoint.protocol) >= 0
|
1678
|
+
? (process.env.HTTPS_PROXY || process.env.https_proxy)
|
1679
|
+
: (process.env.HTTP_PROXY || process.env.http_proxy);
|
1680
|
+
}
|
1681
|
+
},
|
1682
|
+
|
1683
|
+
close: function() {},
|
1684
|
+
|
1685
|
+
encode: function(messages) {
|
1686
|
+
return '';
|
1687
|
+
},
|
1688
|
+
|
1689
|
+
sendMessage: function(message) {
|
1690
|
+
this.debug('Client ? sending message to ?: ?',
|
1691
|
+
this._dispatcher.clientId, Faye.URI.stringify(this.endpoint), message);
|
1692
|
+
|
1693
|
+
if (!this.batching) return Faye.Promise.fulfilled(this.request([message]));
|
1694
|
+
|
1695
|
+
this._outbox.push(message);
|
1696
|
+
this._flushLargeBatch();
|
1697
|
+
|
1698
|
+
if (message.channel === Faye.Channel.HANDSHAKE)
|
1699
|
+
return this._publish(0.01);
|
1700
|
+
|
1701
|
+
if (message.channel === Faye.Channel.CONNECT)
|
1702
|
+
this._connectMessage = message;
|
1703
|
+
|
1704
|
+
return this._publish(this.MAX_DELAY);
|
1705
|
+
},
|
1706
|
+
|
1707
|
+
_publish: function(delay) {
|
1708
|
+
this._promise = this._promise || new Faye.Promise();
|
1709
|
+
|
1710
|
+
this.addTimeout('publish', delay, function() {
|
1711
|
+
this._flush();
|
1712
|
+
delete this._promise;
|
1713
|
+
}, this);
|
1714
|
+
|
1715
|
+
return this._promise;
|
1716
|
+
},
|
1717
|
+
|
1718
|
+
_flush: function() {
|
1719
|
+
this.removeTimeout('publish');
|
1720
|
+
|
1721
|
+
if (this._outbox.length > 1 && this._connectMessage)
|
1722
|
+
this._connectMessage.advice = {timeout: 0};
|
1723
|
+
|
1724
|
+
Faye.Promise.fulfill(this._promise, this.request(this._outbox));
|
1725
|
+
|
1726
|
+
this._connectMessage = null;
|
1727
|
+
this._outbox = [];
|
1728
|
+
},
|
1729
|
+
|
1730
|
+
_flushLargeBatch: function() {
|
1731
|
+
var string = this.encode(this._outbox);
|
1732
|
+
if (string.length < this._dispatcher.maxRequestSize) return;
|
1733
|
+
var last = this._outbox.pop();
|
1734
|
+
|
1735
|
+
this._promise = this._promise || new Faye.Promise();
|
1736
|
+
this._flush();
|
1737
|
+
|
1738
|
+
if (last) this._outbox.push(last);
|
1739
|
+
},
|
1740
|
+
|
1741
|
+
_receive: function(replies) {
|
1742
|
+
if (!replies) return;
|
1743
|
+
replies = [].concat(replies);
|
1744
|
+
|
1745
|
+
this.debug('Client ? received from ? via ?: ?',
|
1746
|
+
this._dispatcher.clientId, Faye.URI.stringify(this.endpoint), this.connectionType, replies);
|
1747
|
+
|
1748
|
+
for (var i = 0, n = replies.length; i < n; i++)
|
1749
|
+
this._dispatcher.handleResponse(replies[i]);
|
1750
|
+
},
|
1751
|
+
|
1752
|
+
_handleError: function(messages, immediate) {
|
1753
|
+
messages = [].concat(messages);
|
1754
|
+
|
1755
|
+
this.debug('Client ? failed to send to ? via ?: ?',
|
1756
|
+
this._dispatcher.clientId, Faye.URI.stringify(this.endpoint), this.connectionType, messages);
|
1757
|
+
|
1758
|
+
for (var i = 0, n = messages.length; i < n; i++)
|
1759
|
+
this._dispatcher.handleError(messages[i]);
|
1760
|
+
},
|
1761
|
+
|
1762
|
+
_getCookies: function() {
|
1763
|
+
var cookies = this._dispatcher.cookies,
|
1764
|
+
url = Faye.URI.stringify(this.endpoint);
|
1765
|
+
|
1766
|
+
if (!cookies) return '';
|
1767
|
+
|
1768
|
+
return Faye.map(cookies.getCookiesSync(url), function(cookie) {
|
1769
|
+
return cookie.cookieString();
|
1770
|
+
}).join('; ');
|
1771
|
+
},
|
1772
|
+
|
1773
|
+
_storeCookies: function(setCookie) {
|
1774
|
+
var cookies = this._dispatcher.cookies,
|
1775
|
+
url = Faye.URI.stringify(this.endpoint),
|
1776
|
+
cookie;
|
1777
|
+
|
1778
|
+
if (!setCookie || !cookies) return;
|
1779
|
+
setCookie = [].concat(setCookie);
|
1780
|
+
|
1781
|
+
for (var i = 0, n = setCookie.length; i < n; i++) {
|
1782
|
+
cookie = Faye.Cookies.Cookie.parse(setCookie[i]);
|
1783
|
+
cookies.setCookieSync(cookie, url);
|
1784
|
+
}
|
1785
|
+
}
|
1786
|
+
|
1787
|
+
}), {
|
1788
|
+
get: function(dispatcher, allowed, disabled, callback, context) {
|
1789
|
+
var endpoint = dispatcher.endpoint;
|
1790
|
+
|
1791
|
+
Faye.asyncEach(this._transports, function(pair, resume) {
|
1792
|
+
var connType = pair[0], klass = pair[1],
|
1793
|
+
connEndpoint = dispatcher.endpointFor(connType);
|
1794
|
+
|
1795
|
+
if (Faye.indexOf(disabled, connType) >= 0)
|
1796
|
+
return resume();
|
1797
|
+
|
1798
|
+
if (Faye.indexOf(allowed, connType) < 0) {
|
1799
|
+
klass.isUsable(dispatcher, connEndpoint, function() {});
|
1800
|
+
return resume();
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
klass.isUsable(dispatcher, connEndpoint, function(isUsable) {
|
1804
|
+
if (!isUsable) return resume();
|
1805
|
+
var transport = klass.hasOwnProperty('create') ? klass.create(dispatcher, connEndpoint) : new klass(dispatcher, connEndpoint);
|
1806
|
+
callback.call(context, transport);
|
1807
|
+
});
|
1808
|
+
}, function() {
|
1809
|
+
throw new Error('Could not find a usable connection type for ' + Faye.URI.stringify(endpoint));
|
1810
|
+
});
|
1811
|
+
},
|
1812
|
+
|
1813
|
+
register: function(type, klass) {
|
1814
|
+
this._transports.push([type, klass]);
|
1815
|
+
klass.prototype.connectionType = type;
|
1816
|
+
},
|
1817
|
+
|
1818
|
+
getConnectionTypes: function() {
|
1819
|
+
return Faye.map(this._transports, function(t) { return t[0] });
|
1820
|
+
},
|
1821
|
+
|
1822
|
+
_transports: []
|
1823
|
+
});
|
1824
|
+
|
1825
|
+
Faye.extend(Faye.Transport.prototype, Faye.Logging);
|
1826
|
+
Faye.extend(Faye.Transport.prototype, Faye.Timeouts);
|
1827
|
+
|
1828
|
+
Faye.Event = {
|
1829
|
+
_registry: [],
|
1830
|
+
|
1831
|
+
on: function(element, eventName, callback, context) {
|
1832
|
+
var wrapped = function() { callback.call(context) };
|
1833
|
+
|
1834
|
+
if (element.addEventListener)
|
1835
|
+
element.addEventListener(eventName, wrapped, false);
|
1836
|
+
else
|
1837
|
+
element.attachEvent('on' + eventName, wrapped);
|
1838
|
+
|
1839
|
+
this._registry.push({
|
1840
|
+
_element: element,
|
1841
|
+
_type: eventName,
|
1842
|
+
_callback: callback,
|
1843
|
+
_context: context,
|
1844
|
+
_handler: wrapped
|
1845
|
+
});
|
1846
|
+
},
|
1847
|
+
|
1848
|
+
detach: function(element, eventName, callback, context) {
|
1849
|
+
var i = this._registry.length, register;
|
1850
|
+
while (i--) {
|
1851
|
+
register = this._registry[i];
|
1852
|
+
|
1853
|
+
if ((element && element !== register._element) ||
|
1854
|
+
(eventName && eventName !== register._type) ||
|
1855
|
+
(callback && callback !== register._callback) ||
|
1856
|
+
(context && context !== register._context))
|
1857
|
+
continue;
|
1858
|
+
|
1859
|
+
if (register._element.removeEventListener)
|
1860
|
+
register._element.removeEventListener(register._type, register._handler, false);
|
1861
|
+
else
|
1862
|
+
register._element.detachEvent('on' + register._type, register._handler);
|
1863
|
+
|
1864
|
+
this._registry.splice(i,1);
|
1865
|
+
register = null;
|
1866
|
+
}
|
1867
|
+
}
|
1868
|
+
};
|
1869
|
+
|
1870
|
+
if (Faye.ENV.onunload !== undefined) Faye.Event.on(Faye.ENV, 'unload', Faye.Event.detach, Faye.Event);
|
1871
|
+
|
1872
|
+
/*
|
1873
|
+
json2.js
|
1874
|
+
2013-05-26
|
1875
|
+
|
1876
|
+
Public Domain.
|
1877
|
+
|
1878
|
+
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
1879
|
+
|
1880
|
+
See http://www.JSON.org/js.html
|
1881
|
+
|
1882
|
+
|
1883
|
+
This code should be minified before deployment.
|
1884
|
+
See http://javascript.crockford.com/jsmin.html
|
1885
|
+
|
1886
|
+
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
1887
|
+
NOT CONTROL.
|
1888
|
+
|
1889
|
+
|
1890
|
+
This file creates a global JSON object containing two methods: stringify
|
1891
|
+
and parse.
|
1892
|
+
|
1893
|
+
JSON.stringify(value, replacer, space)
|
1894
|
+
value any JavaScript value, usually an object or array.
|
1895
|
+
|
1896
|
+
replacer an optional parameter that determines how object
|
1897
|
+
values are stringified for objects. It can be a
|
1898
|
+
function or an array of strings.
|
1899
|
+
|
1900
|
+
space an optional parameter that specifies the indentation
|
1901
|
+
of nested structures. If it is omitted, the text will
|
1902
|
+
be packed without extra whitespace. If it is a number,
|
1903
|
+
it will specify the number of spaces to indent at each
|
1904
|
+
level. If it is a string (such as '\t' or ' '),
|
1905
|
+
it contains the characters used to indent at each level.
|
1906
|
+
|
1907
|
+
This method produces a JSON text from a JavaScript value.
|
1908
|
+
|
1909
|
+
When an object value is found, if the object contains a toJSON
|
1910
|
+
method, its toJSON method will be called and the result will be
|
1911
|
+
stringified. A toJSON method does not serialize: it returns the
|
1912
|
+
value represented by the name/value pair that should be serialized,
|
1913
|
+
or undefined if nothing should be serialized. The toJSON method
|
1914
|
+
will be passed the key associated with the value, and this will be
|
1915
|
+
bound to the value
|
1916
|
+
|
1917
|
+
For example, this would serialize Dates as ISO strings.
|
1918
|
+
|
1919
|
+
Date.prototype.toJSON = function (key) {
|
1920
|
+
function f(n) {
|
1921
|
+
// Format integers to have at least two digits.
|
1922
|
+
return n < 10 ? '0' + n : n;
|
1923
|
+
}
|
1924
|
+
|
1925
|
+
return this.getUTCFullYear() + '-' +
|
1926
|
+
f(this.getUTCMonth() + 1) + '-' +
|
1927
|
+
f(this.getUTCDate()) + 'T' +
|
1928
|
+
f(this.getUTCHours()) + ':' +
|
1929
|
+
f(this.getUTCMinutes()) + ':' +
|
1930
|
+
f(this.getUTCSeconds()) + 'Z';
|
1931
|
+
};
|
1932
|
+
|
1933
|
+
You can provide an optional replacer method. It will be passed the
|
1934
|
+
key and value of each member, with this bound to the containing
|
1935
|
+
object. The value that is returned from your method will be
|
1936
|
+
serialized. If your method returns undefined, then the member will
|
1937
|
+
be excluded from the serialization.
|
1938
|
+
|
1939
|
+
If the replacer parameter is an array of strings, then it will be
|
1940
|
+
used to select the members to be serialized. It filters the results
|
1941
|
+
such that only members with keys listed in the replacer array are
|
1942
|
+
stringified.
|
1943
|
+
|
1944
|
+
Values that do not have JSON representations, such as undefined or
|
1945
|
+
functions, will not be serialized. Such values in objects will be
|
1946
|
+
dropped; in arrays they will be replaced with null. You can use
|
1947
|
+
a replacer function to replace those with JSON values.
|
1948
|
+
JSON.stringify(undefined) returns undefined.
|
1949
|
+
|
1950
|
+
The optional space parameter produces a stringification of the
|
1951
|
+
value that is filled with line breaks and indentation to make it
|
1952
|
+
easier to read.
|
1953
|
+
|
1954
|
+
If the space parameter is a non-empty string, then that string will
|
1955
|
+
be used for indentation. If the space parameter is a number, then
|
1956
|
+
the indentation will be that many spaces.
|
1957
|
+
|
1958
|
+
Example:
|
1959
|
+
|
1960
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
1961
|
+
// text is '["e",{"pluribus":"unum"}]'
|
1962
|
+
|
1963
|
+
|
1964
|
+
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
1965
|
+
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
1966
|
+
|
1967
|
+
text = JSON.stringify([new Date()], function (key, value) {
|
1968
|
+
return this[key] instanceof Date ?
|
1969
|
+
'Date(' + this[key] + ')' : value;
|
1970
|
+
});
|
1971
|
+
// text is '["Date(---current time---)"]'
|
1972
|
+
|
1973
|
+
|
1974
|
+
JSON.parse(text, reviver)
|
1975
|
+
This method parses a JSON text to produce an object or array.
|
1976
|
+
It can throw a SyntaxError exception.
|
1977
|
+
|
1978
|
+
The optional reviver parameter is a function that can filter and
|
1979
|
+
transform the results. It receives each of the keys and values,
|
1980
|
+
and its return value is used instead of the original value.
|
1981
|
+
If it returns what it received, then the structure is not modified.
|
1982
|
+
If it returns undefined then the member is deleted.
|
1983
|
+
|
1984
|
+
Example:
|
1985
|
+
|
1986
|
+
// Parse the text. Values that look like ISO date strings will
|
1987
|
+
// be converted to Date objects.
|
1988
|
+
|
1989
|
+
myData = JSON.parse(text, function (key, value) {
|
1990
|
+
var a;
|
1991
|
+
if (typeof value === 'string') {
|
1992
|
+
a =
|
1993
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
1994
|
+
if (a) {
|
1995
|
+
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
1996
|
+
+a[5], +a[6]));
|
1997
|
+
}
|
1998
|
+
}
|
1999
|
+
return value;
|
2000
|
+
});
|
2001
|
+
|
2002
|
+
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
2003
|
+
var d;
|
2004
|
+
if (typeof value === 'string' &&
|
2005
|
+
value.slice(0, 5) === 'Date(' &&
|
2006
|
+
value.slice(-1) === ')') {
|
2007
|
+
d = new Date(value.slice(5, -1));
|
2008
|
+
if (d) {
|
2009
|
+
return d;
|
2010
|
+
}
|
2011
|
+
}
|
2012
|
+
return value;
|
2013
|
+
});
|
2014
|
+
|
2015
|
+
|
2016
|
+
This is a reference implementation. You are free to copy, modify, or
|
2017
|
+
redistribute.
|
2018
|
+
*/
|
2019
|
+
|
2020
|
+
/*jslint evil: true, regexp: true */
|
2021
|
+
|
2022
|
+
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
2023
|
+
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
2024
|
+
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
2025
|
+
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
2026
|
+
test, toJSON, toString, valueOf
|
2027
|
+
*/
|
2028
|
+
|
2029
|
+
|
2030
|
+
// Create a JSON object only if one does not already exist. We create the
|
2031
|
+
// methods in a closure to avoid creating global variables.
|
2032
|
+
|
2033
|
+
if (typeof JSON !== 'object') {
|
2034
|
+
JSON = {};
|
2035
|
+
}
|
2036
|
+
|
2037
|
+
(function () {
|
2038
|
+
'use strict';
|
2039
|
+
|
2040
|
+
function f(n) {
|
2041
|
+
// Format integers to have at least two digits.
|
2042
|
+
return n < 10 ? '0' + n : n;
|
2043
|
+
}
|
2044
|
+
|
2045
|
+
if (typeof Date.prototype.toJSON !== 'function') {
|
2046
|
+
|
2047
|
+
Date.prototype.toJSON = function () {
|
2048
|
+
|
2049
|
+
return isFinite(this.valueOf())
|
2050
|
+
? this.getUTCFullYear() + '-' +
|
2051
|
+
f(this.getUTCMonth() + 1) + '-' +
|
2052
|
+
f(this.getUTCDate()) + 'T' +
|
2053
|
+
f(this.getUTCHours()) + ':' +
|
2054
|
+
f(this.getUTCMinutes()) + ':' +
|
2055
|
+
f(this.getUTCSeconds()) + 'Z'
|
2056
|
+
: null;
|
2057
|
+
};
|
2058
|
+
|
2059
|
+
String.prototype.toJSON =
|
2060
|
+
Number.prototype.toJSON =
|
2061
|
+
Boolean.prototype.toJSON = function () {
|
2062
|
+
return this.valueOf();
|
2063
|
+
};
|
2064
|
+
}
|
2065
|
+
|
2066
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
2067
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
2068
|
+
gap,
|
2069
|
+
indent,
|
2070
|
+
meta = { // table of character substitutions
|
2071
|
+
'\b': '\\b',
|
2072
|
+
'\t': '\\t',
|
2073
|
+
'\n': '\\n',
|
2074
|
+
'\f': '\\f',
|
2075
|
+
'\r': '\\r',
|
2076
|
+
'"' : '\\"',
|
2077
|
+
'\\': '\\\\'
|
2078
|
+
},
|
2079
|
+
rep;
|
2080
|
+
|
2081
|
+
|
2082
|
+
function quote(string) {
|
2083
|
+
|
2084
|
+
// If the string contains no control characters, no quote characters, and no
|
2085
|
+
// backslash characters, then we can safely slap some quotes around it.
|
2086
|
+
// Otherwise we must also replace the offending characters with safe escape
|
2087
|
+
// sequences.
|
2088
|
+
|
2089
|
+
escapable.lastIndex = 0;
|
2090
|
+
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
2091
|
+
var c = meta[a];
|
2092
|
+
return typeof c === 'string'
|
2093
|
+
? c
|
2094
|
+
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
2095
|
+
}) + '"' : '"' + string + '"';
|
2096
|
+
}
|
2097
|
+
|
2098
|
+
|
2099
|
+
function str(key, holder) {
|
2100
|
+
|
2101
|
+
// Produce a string from holder[key].
|
2102
|
+
|
2103
|
+
var i, // The loop counter.
|
2104
|
+
k, // The member key.
|
2105
|
+
v, // The member value.
|
2106
|
+
length,
|
2107
|
+
mind = gap,
|
2108
|
+
partial,
|
2109
|
+
value = holder[key];
|
2110
|
+
|
2111
|
+
// If the value has a toJSON method, call it to obtain a replacement value.
|
2112
|
+
|
2113
|
+
if (value && typeof value === 'object' &&
|
2114
|
+
typeof value.toJSON === 'function') {
|
2115
|
+
value = value.toJSON(key);
|
2116
|
+
}
|
2117
|
+
|
2118
|
+
// If we were called with a replacer function, then call the replacer to
|
2119
|
+
// obtain a replacement value.
|
2120
|
+
|
2121
|
+
if (typeof rep === 'function') {
|
2122
|
+
value = rep.call(holder, key, value);
|
2123
|
+
}
|
2124
|
+
|
2125
|
+
// What happens next depends on the value's type.
|
2126
|
+
|
2127
|
+
switch (typeof value) {
|
2128
|
+
case 'string':
|
2129
|
+
return quote(value);
|
2130
|
+
|
2131
|
+
case 'number':
|
2132
|
+
|
2133
|
+
// JSON numbers must be finite. Encode non-finite numbers as null.
|
2134
|
+
|
2135
|
+
return isFinite(value) ? String(value) : 'null';
|
2136
|
+
|
2137
|
+
case 'boolean':
|
2138
|
+
case 'null':
|
2139
|
+
|
2140
|
+
// If the value is a boolean or null, convert it to a string. Note:
|
2141
|
+
// typeof null does not produce 'null'. The case is included here in
|
2142
|
+
// the remote chance that this gets fixed someday.
|
2143
|
+
|
2144
|
+
return String(value);
|
2145
|
+
|
2146
|
+
// If the type is 'object', we might be dealing with an object or an array or
|
2147
|
+
// null.
|
2148
|
+
|
2149
|
+
case 'object':
|
2150
|
+
|
2151
|
+
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
2152
|
+
// so watch out for that case.
|
2153
|
+
|
2154
|
+
if (!value) {
|
2155
|
+
return 'null';
|
2156
|
+
}
|
2157
|
+
|
2158
|
+
// Make an array to hold the partial results of stringifying this object value.
|
2159
|
+
|
2160
|
+
gap += indent;
|
2161
|
+
partial = [];
|
2162
|
+
|
2163
|
+
// Is the value an array?
|
2164
|
+
|
2165
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
2166
|
+
|
2167
|
+
// The value is an array. Stringify every element. Use null as a placeholder
|
2168
|
+
// for non-JSON values.
|
2169
|
+
|
2170
|
+
length = value.length;
|
2171
|
+
for (i = 0; i < length; i += 1) {
|
2172
|
+
partial[i] = str(i, value) || 'null';
|
2173
|
+
}
|
2174
|
+
|
2175
|
+
// Join all of the elements together, separated with commas, and wrap them in
|
2176
|
+
// brackets.
|
2177
|
+
|
2178
|
+
v = partial.length === 0
|
2179
|
+
? '[]'
|
2180
|
+
: gap
|
2181
|
+
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
2182
|
+
: '[' + partial.join(',') + ']';
|
2183
|
+
gap = mind;
|
2184
|
+
return v;
|
2185
|
+
}
|
2186
|
+
|
2187
|
+
// If the replacer is an array, use it to select the members to be stringified.
|
2188
|
+
|
2189
|
+
if (rep && typeof rep === 'object') {
|
2190
|
+
length = rep.length;
|
2191
|
+
for (i = 0; i < length; i += 1) {
|
2192
|
+
if (typeof rep[i] === 'string') {
|
2193
|
+
k = rep[i];
|
2194
|
+
v = str(k, value);
|
2195
|
+
if (v) {
|
2196
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
2197
|
+
}
|
2198
|
+
}
|
2199
|
+
}
|
2200
|
+
} else {
|
2201
|
+
|
2202
|
+
// Otherwise, iterate through all of the keys in the object.
|
2203
|
+
|
2204
|
+
for (k in value) {
|
2205
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
2206
|
+
v = str(k, value);
|
2207
|
+
if (v) {
|
2208
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
2209
|
+
}
|
2210
|
+
}
|
2211
|
+
}
|
2212
|
+
}
|
2213
|
+
|
2214
|
+
// Join all of the member texts together, separated with commas,
|
2215
|
+
// and wrap them in braces.
|
2216
|
+
|
2217
|
+
v = partial.length === 0
|
2218
|
+
? '{}'
|
2219
|
+
: gap
|
2220
|
+
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
2221
|
+
: '{' + partial.join(',') + '}';
|
2222
|
+
gap = mind;
|
2223
|
+
return v;
|
2224
|
+
}
|
2225
|
+
}
|
2226
|
+
|
2227
|
+
// If the JSON object does not yet have a stringify method, give it one.
|
2228
|
+
|
2229
|
+
Faye.stringify = function (value, replacer, space) {
|
2230
|
+
|
2231
|
+
// The stringify method takes a value and an optional replacer, and an optional
|
2232
|
+
// space parameter, and returns a JSON text. The replacer can be a function
|
2233
|
+
// that can replace values, or an array of strings that will select the keys.
|
2234
|
+
// A default replacer method can be provided. Use of the space parameter can
|
2235
|
+
// produce text that is more easily readable.
|
2236
|
+
|
2237
|
+
var i;
|
2238
|
+
gap = '';
|
2239
|
+
indent = '';
|
2240
|
+
|
2241
|
+
// If the space parameter is a number, make an indent string containing that
|
2242
|
+
// many spaces.
|
2243
|
+
|
2244
|
+
if (typeof space === 'number') {
|
2245
|
+
for (i = 0; i < space; i += 1) {
|
2246
|
+
indent += ' ';
|
2247
|
+
}
|
2248
|
+
|
2249
|
+
// If the space parameter is a string, it will be used as the indent string.
|
2250
|
+
|
2251
|
+
} else if (typeof space === 'string') {
|
2252
|
+
indent = space;
|
2253
|
+
}
|
2254
|
+
|
2255
|
+
// If there is a replacer, it must be a function or an array.
|
2256
|
+
// Otherwise, throw an error.
|
2257
|
+
|
2258
|
+
rep = replacer;
|
2259
|
+
if (replacer && typeof replacer !== 'function' &&
|
2260
|
+
(typeof replacer !== 'object' ||
|
2261
|
+
typeof replacer.length !== 'number')) {
|
2262
|
+
throw new Error('JSON.stringify');
|
2263
|
+
}
|
2264
|
+
|
2265
|
+
// Make a fake root object containing our value under the key of ''.
|
2266
|
+
// Return the result of stringifying the value.
|
2267
|
+
|
2268
|
+
return str('', {'': value});
|
2269
|
+
};
|
2270
|
+
|
2271
|
+
if (typeof JSON.stringify !== 'function') {
|
2272
|
+
JSON.stringify = Faye.stringify;
|
2273
|
+
}
|
2274
|
+
|
2275
|
+
// If the JSON object does not yet have a parse method, give it one.
|
2276
|
+
|
2277
|
+
if (typeof JSON.parse !== 'function') {
|
2278
|
+
JSON.parse = function (text, reviver) {
|
2279
|
+
|
2280
|
+
// The parse method takes a text and an optional reviver function, and returns
|
2281
|
+
// a JavaScript value if the text is a valid JSON text.
|
2282
|
+
|
2283
|
+
var j;
|
2284
|
+
|
2285
|
+
function walk(holder, key) {
|
2286
|
+
|
2287
|
+
// The walk method is used to recursively walk the resulting structure so
|
2288
|
+
// that modifications can be made.
|
2289
|
+
|
2290
|
+
var k, v, value = holder[key];
|
2291
|
+
if (value && typeof value === 'object') {
|
2292
|
+
for (k in value) {
|
2293
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
2294
|
+
v = walk(value, k);
|
2295
|
+
if (v !== undefined) {
|
2296
|
+
value[k] = v;
|
2297
|
+
} else {
|
2298
|
+
delete value[k];
|
2299
|
+
}
|
2300
|
+
}
|
2301
|
+
}
|
2302
|
+
}
|
2303
|
+
return reviver.call(holder, key, value);
|
2304
|
+
}
|
2305
|
+
|
2306
|
+
|
2307
|
+
// Parsing happens in four stages. In the first stage, we replace certain
|
2308
|
+
// Unicode characters with escape sequences. JavaScript handles many characters
|
2309
|
+
// incorrectly, either silently deleting them, or treating them as line endings.
|
2310
|
+
|
2311
|
+
text = String(text);
|
2312
|
+
cx.lastIndex = 0;
|
2313
|
+
if (cx.test(text)) {
|
2314
|
+
text = text.replace(cx, function (a) {
|
2315
|
+
return '\\u' +
|
2316
|
+
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
2317
|
+
});
|
2318
|
+
}
|
2319
|
+
|
2320
|
+
// In the second stage, we run the text against regular expressions that look
|
2321
|
+
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
2322
|
+
// because they can cause invocation, and '=' because it can cause mutation.
|
2323
|
+
// But just to be safe, we want to reject all unexpected forms.
|
2324
|
+
|
2325
|
+
// We split the second stage into 4 regexp operations in order to work around
|
2326
|
+
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
2327
|
+
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
2328
|
+
// replace all simple value tokens with ']' characters. Third, we delete all
|
2329
|
+
// open brackets that follow a colon or comma or that begin the text. Finally,
|
2330
|
+
// we look to see that the remaining characters are only whitespace or ']' or
|
2331
|
+
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
2332
|
+
|
2333
|
+
if (/^[\],:{}\s]*$/
|
2334
|
+
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
2335
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
2336
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
2337
|
+
|
2338
|
+
// In the third stage we use the eval function to compile the text into a
|
2339
|
+
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
2340
|
+
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
2341
|
+
// in parens to eliminate the ambiguity.
|
2342
|
+
|
2343
|
+
j = eval('(' + text + ')');
|
2344
|
+
|
2345
|
+
// In the optional fourth stage, we recursively walk the new structure, passing
|
2346
|
+
// each name/value pair to a reviver function for possible transformation.
|
2347
|
+
|
2348
|
+
return typeof reviver === 'function'
|
2349
|
+
? walk({'': j}, '')
|
2350
|
+
: j;
|
2351
|
+
}
|
2352
|
+
|
2353
|
+
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
2354
|
+
|
2355
|
+
throw new SyntaxError('JSON.parse');
|
2356
|
+
};
|
2357
|
+
}
|
2358
|
+
}());
|
2359
|
+
|
2360
|
+
Faye.Transport.WebSocket = Faye.extend(Faye.Class(Faye.Transport, {
|
2361
|
+
UNCONNECTED: 1,
|
2362
|
+
CONNECTING: 2,
|
2363
|
+
CONNECTED: 3,
|
2364
|
+
|
2365
|
+
batching: false,
|
2366
|
+
|
2367
|
+
isUsable: function(callback, context) {
|
2368
|
+
this.callback(function() { callback.call(context, true) });
|
2369
|
+
this.errback(function() { callback.call(context, false) });
|
2370
|
+
this.connect();
|
2371
|
+
},
|
2372
|
+
|
2373
|
+
request: function(messages) {
|
2374
|
+
this._pending = this._pending || new Faye.Set();
|
2375
|
+
for (var i = 0, n = messages.length; i < n; i++) this._pending.add(messages[i]);
|
2376
|
+
|
2377
|
+
var promise = new Faye.Promise();
|
2378
|
+
|
2379
|
+
this.callback(function(socket) {
|
2380
|
+
if (!socket || socket.readyState !== 1) return;
|
2381
|
+
socket.send(Faye.toJSON(messages));
|
2382
|
+
Faye.Promise.fulfill(promise, socket);
|
2383
|
+
}, this);
|
2384
|
+
|
2385
|
+
this.connect();
|
2386
|
+
|
2387
|
+
return {
|
2388
|
+
abort: function() { promise.then(function(ws) { ws.close() }) }
|
2389
|
+
};
|
2390
|
+
},
|
2391
|
+
|
2392
|
+
connect: function() {
|
2393
|
+
if (Faye.Transport.WebSocket._unloaded) return;
|
2394
|
+
|
2395
|
+
this._state = this._state || this.UNCONNECTED;
|
2396
|
+
if (this._state !== this.UNCONNECTED) return;
|
2397
|
+
this._state = this.CONNECTING;
|
2398
|
+
|
2399
|
+
var socket = this._createSocket();
|
2400
|
+
if (!socket) return this.setDeferredStatus('failed');
|
2401
|
+
|
2402
|
+
var self = this;
|
2403
|
+
|
2404
|
+
socket.onopen = function() {
|
2405
|
+
if (socket.headers) self._storeCookies(socket.headers['set-cookie']);
|
2406
|
+
self._socket = socket;
|
2407
|
+
self._state = self.CONNECTED;
|
2408
|
+
self._everConnected = true;
|
2409
|
+
self._ping();
|
2410
|
+
self.setDeferredStatus('succeeded', socket);
|
2411
|
+
};
|
2412
|
+
|
2413
|
+
var closed = false;
|
2414
|
+
socket.onclose = socket.onerror = function() {
|
2415
|
+
if (closed) return;
|
2416
|
+
closed = true;
|
2417
|
+
|
2418
|
+
var wasConnected = (self._state === self.CONNECTED);
|
2419
|
+
socket.onopen = socket.onclose = socket.onerror = socket.onmessage = null;
|
2420
|
+
|
2421
|
+
delete self._socket;
|
2422
|
+
self._state = self.UNCONNECTED;
|
2423
|
+
self.removeTimeout('ping');
|
2424
|
+
self.setDeferredStatus('unknown');
|
2425
|
+
|
2426
|
+
var pending = self._pending ? self._pending.toArray() : [];
|
2427
|
+
delete self._pending;
|
2428
|
+
|
2429
|
+
if (wasConnected) {
|
2430
|
+
self._handleError(pending, true);
|
2431
|
+
} else if (self._everConnected) {
|
2432
|
+
self._handleError(pending);
|
2433
|
+
} else {
|
2434
|
+
self.setDeferredStatus('failed');
|
2435
|
+
}
|
2436
|
+
};
|
2437
|
+
|
2438
|
+
socket.onmessage = function(event) {
|
2439
|
+
var replies = JSON.parse(event.data);
|
2440
|
+
if (!replies) return;
|
2441
|
+
|
2442
|
+
replies = [].concat(replies);
|
2443
|
+
|
2444
|
+
for (var i = 0, n = replies.length; i < n; i++) {
|
2445
|
+
if (replies[i].successful === undefined) continue;
|
2446
|
+
self._pending.remove(replies[i]);
|
2447
|
+
}
|
2448
|
+
self._receive(replies);
|
2449
|
+
};
|
2450
|
+
},
|
2451
|
+
|
2452
|
+
close: function() {
|
2453
|
+
if (!this._socket) return;
|
2454
|
+
this._socket.close();
|
2455
|
+
},
|
2456
|
+
|
2457
|
+
_createSocket: function() {
|
2458
|
+
var url = Faye.Transport.WebSocket.getSocketUrl(this.endpoint),
|
2459
|
+
headers = this._dispatcher.headers,
|
2460
|
+
extensions = this._dispatcher.wsExtensions,
|
2461
|
+
cookie = this._getCookies(),
|
2462
|
+
tls = this._dispatcher.tls,
|
2463
|
+
options = {extensions: extensions, headers: headers, proxy: this._proxy, tls: tls};
|
2464
|
+
|
2465
|
+
if (cookie !== '') options.headers['Cookie'] = cookie;
|
2466
|
+
|
2467
|
+
if (Faye.WebSocket) return new Faye.WebSocket.Client(url, [], options);
|
2468
|
+
if (Faye.ENV.MozWebSocket) return new MozWebSocket(url);
|
2469
|
+
if (Faye.ENV.WebSocket) return new WebSocket(url);
|
2470
|
+
},
|
2471
|
+
|
2472
|
+
_ping: function() {
|
2473
|
+
if (!this._socket) return;
|
2474
|
+
this._socket.send('[]');
|
2475
|
+
this.addTimeout('ping', this._dispatcher.timeout / 2, this._ping, this);
|
2476
|
+
}
|
2477
|
+
|
2478
|
+
}), {
|
2479
|
+
PROTOCOLS: {
|
2480
|
+
'http:': 'ws:',
|
2481
|
+
'https:': 'wss:'
|
2482
|
+
},
|
2483
|
+
|
2484
|
+
create: function(dispatcher, endpoint) {
|
2485
|
+
var sockets = dispatcher.transports.websocket = dispatcher.transports.websocket || {};
|
2486
|
+
sockets[endpoint.href] = sockets[endpoint.href] || new this(dispatcher, endpoint);
|
2487
|
+
return sockets[endpoint.href];
|
2488
|
+
},
|
2489
|
+
|
2490
|
+
getSocketUrl: function(endpoint) {
|
2491
|
+
endpoint = Faye.copyObject(endpoint);
|
2492
|
+
endpoint.protocol = this.PROTOCOLS[endpoint.protocol];
|
2493
|
+
return Faye.URI.stringify(endpoint);
|
2494
|
+
},
|
2495
|
+
|
2496
|
+
isUsable: function(dispatcher, endpoint, callback, context) {
|
2497
|
+
this.create(dispatcher, endpoint).isUsable(callback, context);
|
2498
|
+
}
|
2499
|
+
});
|
2500
|
+
|
2501
|
+
Faye.extend(Faye.Transport.WebSocket.prototype, Faye.Deferrable);
|
2502
|
+
Faye.Transport.register('websocket', Faye.Transport.WebSocket);
|
2503
|
+
|
2504
|
+
if (Faye.Event && Faye.ENV.onbeforeunload !== undefined)
|
2505
|
+
Faye.Event.on(Faye.ENV, 'beforeunload', function() {
|
2506
|
+
Faye.Transport.WebSocket._unloaded = true;
|
2507
|
+
});
|
2508
|
+
|
2509
|
+
Faye.Transport.EventSource = Faye.extend(Faye.Class(Faye.Transport, {
|
2510
|
+
initialize: function(dispatcher, endpoint) {
|
2511
|
+
Faye.Transport.prototype.initialize.call(this, dispatcher, endpoint);
|
2512
|
+
if (!Faye.ENV.EventSource) return this.setDeferredStatus('failed');
|
2513
|
+
|
2514
|
+
this._xhr = new Faye.Transport.XHR(dispatcher, endpoint);
|
2515
|
+
|
2516
|
+
endpoint = Faye.copyObject(endpoint);
|
2517
|
+
endpoint.pathname += '/' + dispatcher.clientId;
|
2518
|
+
|
2519
|
+
var socket = new EventSource(Faye.URI.stringify(endpoint)),
|
2520
|
+
self = this;
|
2521
|
+
|
2522
|
+
socket.onopen = function() {
|
2523
|
+
self._everConnected = true;
|
2524
|
+
self.setDeferredStatus('succeeded');
|
2525
|
+
};
|
2526
|
+
|
2527
|
+
socket.onerror = function() {
|
2528
|
+
if (self._everConnected) {
|
2529
|
+
self._handleError([]);
|
2530
|
+
} else {
|
2531
|
+
self.setDeferredStatus('failed');
|
2532
|
+
socket.close();
|
2533
|
+
}
|
2534
|
+
};
|
2535
|
+
|
2536
|
+
socket.onmessage = function(event) {
|
2537
|
+
self._receive(JSON.parse(event.data));
|
2538
|
+
};
|
2539
|
+
|
2540
|
+
this._socket = socket;
|
2541
|
+
},
|
2542
|
+
|
2543
|
+
close: function() {
|
2544
|
+
if (!this._socket) return;
|
2545
|
+
this._socket.onopen = this._socket.onerror = this._socket.onmessage = null;
|
2546
|
+
this._socket.close();
|
2547
|
+
delete this._socket;
|
2548
|
+
},
|
2549
|
+
|
2550
|
+
isUsable: function(callback, context) {
|
2551
|
+
this.callback(function() { callback.call(context, true) });
|
2552
|
+
this.errback(function() { callback.call(context, false) });
|
2553
|
+
},
|
2554
|
+
|
2555
|
+
encode: function(messages) {
|
2556
|
+
return this._xhr.encode(messages);
|
2557
|
+
},
|
2558
|
+
|
2559
|
+
request: function(messages) {
|
2560
|
+
return this._xhr.request(messages);
|
2561
|
+
}
|
2562
|
+
|
2563
|
+
}), {
|
2564
|
+
isUsable: function(dispatcher, endpoint, callback, context) {
|
2565
|
+
var id = dispatcher.clientId;
|
2566
|
+
if (!id) return callback.call(context, false);
|
2567
|
+
|
2568
|
+
Faye.Transport.XHR.isUsable(dispatcher, endpoint, function(usable) {
|
2569
|
+
if (!usable) return callback.call(context, false);
|
2570
|
+
this.create(dispatcher, endpoint).isUsable(callback, context);
|
2571
|
+
}, this);
|
2572
|
+
},
|
2573
|
+
|
2574
|
+
create: function(dispatcher, endpoint) {
|
2575
|
+
var sockets = dispatcher.transports.eventsource = dispatcher.transports.eventsource || {},
|
2576
|
+
id = dispatcher.clientId;
|
2577
|
+
|
2578
|
+
var url = Faye.copyObject(endpoint);
|
2579
|
+
url.pathname += '/' + (id || '');
|
2580
|
+
url = Faye.URI.stringify(url);
|
2581
|
+
|
2582
|
+
sockets[url] = sockets[url] || new this(dispatcher, endpoint);
|
2583
|
+
return sockets[url];
|
2584
|
+
}
|
2585
|
+
});
|
2586
|
+
|
2587
|
+
Faye.extend(Faye.Transport.EventSource.prototype, Faye.Deferrable);
|
2588
|
+
Faye.Transport.register('eventsource', Faye.Transport.EventSource);
|
2589
|
+
|
2590
|
+
Faye.Transport.XHR = Faye.extend(Faye.Class(Faye.Transport, {
|
2591
|
+
encode: function(messages) {
|
2592
|
+
return Faye.toJSON(messages);
|
2593
|
+
},
|
2594
|
+
|
2595
|
+
request: function(messages) {
|
2596
|
+
var href = this.endpoint.href,
|
2597
|
+
xhr = Faye.ENV.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest(),
|
2598
|
+
self = this;
|
2599
|
+
|
2600
|
+
xhr.open('POST', href, true);
|
2601
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
2602
|
+
xhr.setRequestHeader('Pragma', 'no-cache');
|
2603
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
2604
|
+
|
2605
|
+
var headers = this._dispatcher.headers;
|
2606
|
+
for (var key in headers) {
|
2607
|
+
if (!headers.hasOwnProperty(key)) continue;
|
2608
|
+
xhr.setRequestHeader(key, headers[key]);
|
2609
|
+
}
|
2610
|
+
|
2611
|
+
var abort = function() { xhr.abort() };
|
2612
|
+
if (Faye.ENV.onbeforeunload !== undefined) Faye.Event.on(Faye.ENV, 'beforeunload', abort);
|
2613
|
+
|
2614
|
+
xhr.onreadystatechange = function() {
|
2615
|
+
if (!xhr || xhr.readyState !== 4) return;
|
2616
|
+
|
2617
|
+
var replies = null,
|
2618
|
+
status = xhr.status,
|
2619
|
+
text = xhr.responseText,
|
2620
|
+
successful = (status >= 200 && status < 300) || status === 304 || status === 1223;
|
2621
|
+
|
2622
|
+
if (Faye.ENV.onbeforeunload !== undefined) Faye.Event.detach(Faye.ENV, 'beforeunload', abort);
|
2623
|
+
xhr.onreadystatechange = function() {};
|
2624
|
+
xhr = null;
|
2625
|
+
|
2626
|
+
if (!successful) return self._handleError(messages);
|
2627
|
+
|
2628
|
+
try {
|
2629
|
+
replies = JSON.parse(text);
|
2630
|
+
} catch (e) {}
|
2631
|
+
|
2632
|
+
if (replies)
|
2633
|
+
self._receive(replies);
|
2634
|
+
else
|
2635
|
+
self._handleError(messages);
|
2636
|
+
};
|
2637
|
+
|
2638
|
+
xhr.send(this.encode(messages));
|
2639
|
+
return xhr;
|
2640
|
+
}
|
2641
|
+
}), {
|
2642
|
+
isUsable: function(dispatcher, endpoint, callback, context) {
|
2643
|
+
callback.call(context, Faye.URI.isSameOrigin(endpoint));
|
2644
|
+
}
|
2645
|
+
});
|
2646
|
+
|
2647
|
+
Faye.Transport.register('long-polling', Faye.Transport.XHR);
|
2648
|
+
|
2649
|
+
Faye.Transport.CORS = Faye.extend(Faye.Class(Faye.Transport, {
|
2650
|
+
encode: function(messages) {
|
2651
|
+
return 'message=' + encodeURIComponent(Faye.toJSON(messages));
|
2652
|
+
},
|
2653
|
+
|
2654
|
+
request: function(messages) {
|
2655
|
+
var xhrClass = Faye.ENV.XDomainRequest ? XDomainRequest : XMLHttpRequest,
|
2656
|
+
xhr = new xhrClass(),
|
2657
|
+
id = ++Faye.Transport.CORS._id,
|
2658
|
+
headers = this._dispatcher.headers,
|
2659
|
+
self = this,
|
2660
|
+
key;
|
2661
|
+
|
2662
|
+
xhr.open('POST', Faye.URI.stringify(this.endpoint), true);
|
2663
|
+
|
2664
|
+
if (xhr.setRequestHeader) {
|
2665
|
+
xhr.setRequestHeader('Pragma', 'no-cache');
|
2666
|
+
for (key in headers) {
|
2667
|
+
if (!headers.hasOwnProperty(key)) continue;
|
2668
|
+
xhr.setRequestHeader(key, headers[key]);
|
2669
|
+
}
|
2670
|
+
}
|
2671
|
+
|
2672
|
+
var cleanUp = function() {
|
2673
|
+
if (!xhr) return false;
|
2674
|
+
Faye.Transport.CORS._pending.remove(id);
|
2675
|
+
xhr.onload = xhr.onerror = xhr.ontimeout = xhr.onprogress = null;
|
2676
|
+
xhr = null;
|
2677
|
+
};
|
2678
|
+
|
2679
|
+
xhr.onload = function() {
|
2680
|
+
var replies = null;
|
2681
|
+
try {
|
2682
|
+
replies = JSON.parse(xhr.responseText);
|
2683
|
+
} catch (e) {}
|
2684
|
+
|
2685
|
+
cleanUp();
|
2686
|
+
|
2687
|
+
if (replies)
|
2688
|
+
self._receive(replies);
|
2689
|
+
else
|
2690
|
+
self._handleError(messages);
|
2691
|
+
};
|
2692
|
+
|
2693
|
+
xhr.onerror = xhr.ontimeout = function() {
|
2694
|
+
cleanUp();
|
2695
|
+
self._handleError(messages);
|
2696
|
+
};
|
2697
|
+
|
2698
|
+
xhr.onprogress = function() {};
|
2699
|
+
|
2700
|
+
if (xhrClass === Faye.ENV.XDomainRequest)
|
2701
|
+
Faye.Transport.CORS._pending.add({id: id, xhr: xhr});
|
2702
|
+
|
2703
|
+
xhr.send(this.encode(messages));
|
2704
|
+
return xhr;
|
2705
|
+
}
|
2706
|
+
}), {
|
2707
|
+
_id: 0,
|
2708
|
+
_pending: new Faye.Set(),
|
2709
|
+
|
2710
|
+
isUsable: function(dispatcher, endpoint, callback, context) {
|
2711
|
+
if (Faye.URI.isSameOrigin(endpoint))
|
2712
|
+
return callback.call(context, false);
|
2713
|
+
|
2714
|
+
if (Faye.ENV.XDomainRequest)
|
2715
|
+
return callback.call(context, endpoint.protocol === Faye.ENV.location.protocol);
|
2716
|
+
|
2717
|
+
if (Faye.ENV.XMLHttpRequest) {
|
2718
|
+
var xhr = new Faye.ENV.XMLHttpRequest();
|
2719
|
+
return callback.call(context, xhr.withCredentials !== undefined);
|
2720
|
+
}
|
2721
|
+
return callback.call(context, false);
|
2722
|
+
}
|
2723
|
+
});
|
2724
|
+
|
2725
|
+
Faye.Transport.register('cross-origin-long-polling', Faye.Transport.CORS);
|
2726
|
+
|
2727
|
+
Faye.Transport.JSONP = Faye.extend(Faye.Class(Faye.Transport, {
|
2728
|
+
encode: function(messages) {
|
2729
|
+
var url = Faye.copyObject(this.endpoint);
|
2730
|
+
url.query.message = Faye.toJSON(messages);
|
2731
|
+
url.query.jsonp = '__jsonp' + Faye.Transport.JSONP._cbCount + '__';
|
2732
|
+
return Faye.URI.stringify(url);
|
2733
|
+
},
|
2734
|
+
|
2735
|
+
request: function(messages) {
|
2736
|
+
var head = document.getElementsByTagName('head')[0],
|
2737
|
+
script = document.createElement('script'),
|
2738
|
+
callbackName = Faye.Transport.JSONP.getCallbackName(),
|
2739
|
+
endpoint = Faye.copyObject(this.endpoint),
|
2740
|
+
self = this;
|
2741
|
+
|
2742
|
+
endpoint.query.message = Faye.toJSON(messages);
|
2743
|
+
endpoint.query.jsonp = callbackName;
|
2744
|
+
|
2745
|
+
var cleanup = function() {
|
2746
|
+
if (!Faye.ENV[callbackName]) return false;
|
2747
|
+
Faye.ENV[callbackName] = undefined;
|
2748
|
+
try { delete Faye.ENV[callbackName] } catch (e) {}
|
2749
|
+
script.parentNode.removeChild(script);
|
2750
|
+
};
|
2751
|
+
|
2752
|
+
Faye.ENV[callbackName] = function(replies) {
|
2753
|
+
cleanup();
|
2754
|
+
self._receive(replies);
|
2755
|
+
};
|
2756
|
+
|
2757
|
+
script.type = 'text/javascript';
|
2758
|
+
script.src = Faye.URI.stringify(endpoint);
|
2759
|
+
head.appendChild(script);
|
2760
|
+
|
2761
|
+
script.onerror = function() {
|
2762
|
+
cleanup();
|
2763
|
+
self._handleError(messages);
|
2764
|
+
};
|
2765
|
+
|
2766
|
+
return {abort: cleanup};
|
2767
|
+
}
|
2768
|
+
}), {
|
2769
|
+
_cbCount: 0,
|
2770
|
+
|
2771
|
+
getCallbackName: function() {
|
2772
|
+
this._cbCount += 1;
|
2773
|
+
return '__jsonp' + this._cbCount + '__';
|
2774
|
+
},
|
2775
|
+
|
2776
|
+
isUsable: function(dispatcher, endpoint, callback, context) {
|
2777
|
+
callback.call(context, true);
|
2778
|
+
}
|
2779
|
+
});
|
2780
|
+
|
2781
|
+
Faye.Transport.register('callback-polling', Faye.Transport.JSONP);
|
2782
|
+
|
2783
|
+
})();
|