Permalink
Browse files

Only cake webclient is needed; updated webclient

  • Loading branch information...
1 parent 7adf7ec commit 23ead4acaf201b73363495af93dc6d2ed385a08c @wmertens wmertens committed Aug 14, 2012
Showing with 29 additions and 12 deletions.
  1. +1 −0 Cakefile
  2. +1 −2 package.json
  3. +1 −1 webclient/share.js
  4. +26 −9 webclient/share.uncompressed.js
View
1 Cakefile
@@ -14,6 +14,7 @@ task 'test', 'Run all tests', ->
exec 'nodeunit tests.coffee', (err, stdout, stderr) ->
throw err if err
+# This is only needed to be able to refer to the line numbers of crashes
task 'build', 'Build the .js files', (options) ->
console.log('Compiling Coffee from src to lib')
exec "coffee --compile --bare --output lib/ src/", (err, stdout, stderr) ->
View
3 package.json
@@ -30,8 +30,7 @@
"scripts": {
"build": "cake build",
"test": "nodeunit tests.coffee",
- "postinstall": "cake build",
- "prepublish": "cake build"
+ "prepublish": "cake webclient"
},
"licenses": [{
"type": "BSD",
View
2 webclient/share.js
@@ -1 +1 @@
-(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m=[].slice,g=function(e,t){return function(){return e.apply(t,arguments)}},y=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};window.sharejs=a={version:"0.5.0"},l=function(e){return setTimeout(e,0)},r=function(){function e(){}return e.prototype.on=function(e,t){var n;return this._events||(this._events={}),(n=this._events)[e]||(n[e]=[]),this._events[e].push(t),this},e.prototype.removeListener=function(e,t){var n,r,i,s=this;this._events||(this._events={}),r=(i=this._events)[e]||(i[e]=[]),n=0;while(n<r.length)r[n]===t&&(r[n]=void 0),n++;return l(function(){var t;return s._events[e]=function(){var n,r,i=this._events[e],s=[];for(n=0,r=i.length;n<r;n++)t=i[n],t&&s.push(t);return s}.call(s)}),this},e.prototype.emit=function(){var e,t,n,r,i,s=arguments[0],o=2<=arguments.length?m.call(arguments,1):[];if((r=this._events)!=null?!r[s]:!void 0)return this;i=this._events[s];for(t=0,n=i.length;t<n;t++)e=i[t],e&&e.apply(this,o);return this},e}(),r.mixin=function(e){var t=e.prototype||e;return t.on=r.prototype.on,t.removeListener=r.prototype.removeListener,t.emit=r.prototype.emit,e},a._bt=s=function(e,t,n,r){var i,s=function(e,n,r,i){return t(r,e,n,"left"),t(i,n,e,"right")};return e.transformX=e.transformX=i=function(e,t){var o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T;n(e),n(t),l=[];for(v=0,b=t.length;v<b;v++){d=t[v],f=[],o=0;while(o<e.length){c=[],s(e[o],d,f,c),o++;if(c.length!==1){if(c.length===0){x=e.slice(o);for(m=0,w=x.length;m<w;m++)u=x[m],r(f,u);d=null;break}T=i(e.slice(o),c),a=T[0],p=T[1];for(g=0,E=a.length;g<E;g++)u=a[g],r(f,u);for(y=0,S=p.length;y<S;y++)h=p[y],r(l,h);d=null;break}d=c[0]}d!=null&&r(l,d),e=f}return[e,l]},e.transform=e.transform=function(e,n,r){var s,o,u,a,f;if(r!=="left"&&r!=="right")throw new Error("type must be 'left' or 'right'");return n.length===0?e:e.length===1&&n.length===1?t([],e[0],n[0],r):r==="left"?(a=i(e,n),s=a[0],u=a[1],s):(f=i(n,e),u=f[0],o=f[1],o)}},h={},h.name="text",h.create=function(){return""},c=function(e,t,n){return e.slice(0,t)+n+e.slice(t)},o=function(e){var t,n;if(typeof e.p!="number")throw new Error("component missing position field");n=typeof e.i,t=typeof e.d;if(!(n==="string"^t==="string"))throw new Error("component needs an i or d field");if(!(e.p>=0))throw new Error("position cannot be negative")},u=function(e){var t,n,r;for(n=0,r=e.length;n<r;n++)t=e[n],o(t);return!0},h.apply=function(e,t){var n,r,i,s;u(t);for(i=0,s=t.length;i<s;i++){n=t[i];if(n.i!=null)e=c(e,n.p,n.i);else{r=e.slice(n.p,n.p+n.d.length);if(n.d!==r)throw new Error("Delete component '"+n.d+"' does not match deleted text '"+r+"'");e=e.slice(0,n.p)+e.slice(n.p+n.d.length)}}return e},h._append=i=function(e,t){var n,r,i;if(t.i===""||t.d==="")return;return e.length===0?e.push(t):(n=e[e.length-1],n.i!=null&&t.i!=null&&n.p<=(r=t.p)&&r<=n.p+n.i.length?e[e.length-1]={i:c(n.i,t.p-n.p,t.i),p:n.p}:n.d!=null&&t.d!=null&&t.p<=(i=n.p)&&i<=t.p+t.d.length?e[e.length-1]={d:c(t.d,n.p-t.p,n.d),p:t.p}:e.push(t))},h.compose=function(e,t){var n,r,s,o;u(e),u(t),r=e.slice();for(s=0,o=t.length;s<o;s++)n=t[s],i(r,n);return r},h.compress=function(e){return h.compose([],e)},h.normalize=function(e){var t,n,r,s,o=[];if(e.i!=null||e.p!=null)e=[e];for(n=0,r=e.length;n<r;n++)t=e[n],(s=t.p)==null&&(t.p=0),i(o,t);return o},d=function(e,t,n){return t.i!=null?t.p<e||t.p===e&&n?e+t.i.length:e:e<=t.p?e:e<=t.p+t.d.length?t.p:e-t.d.length},h.transformCursor=function(e,t,n){var r,i,s,o=n==="right";for(i=0,s=t.length;i<s;i++)r=t[i],e=d(e,r,o);return e},h._tc=p=function(e,t,n,r){var s,o,a,f,l,c;u([t]),u([n]);if(t.i!=null)i(e,{i:t.i,p:d(t.p,n,r==="right")});else if(n.i!=null)c=t.d,t.p<n.p&&(i(e,{d:c.slice(0,n.p-t.p),p:t.p}),c=c.slice(n.p-t.p)),c!==""&&i(e,{d:c,p:t.p+n.i.length});else if(t.p>=n.p+n.d.length)i(e,{d:t.d,p:t.p-n.d.length});else if(t.p+t.d.length<=n.p)i(e,t);else{f={d:"",p:t.p},t.p<n.p&&(f.d=t.d.slice(0,n.p-t.p)),t.p+t.d.length>n.p+n.d.length&&(f.d+=t.d.slice(n.p+n.d.length-t.p)),a=Math.max(t.p,n.p),o=Math.min(t.p+t.d.length,n.p+n.d.length),s=t.d.slice(a-t.p,o-t.p),l=n.d.slice(a-n.p,o-n.p);if(s!==l)throw new Error("Delete ops delete different text in the same region of the document");f.d!==""&&(f.p=d(f.p,n),i(e,f))}return e},f=function(e){return e.i!=null?{d:e.i,p:e.p}:{i:e.d,p:e.p}},h.invert=function(e){var t,n,r,i=e.slice().reverse(),s=[];for(n=0,r=i.length;n<r;n++)t=i[n],s.push(f(t));return s},a.types||(a.types={}),s(h,p,u,i),a.types.text=h,h.api={provides:{text:!0},getLength:function(){return this.snapshot.length},getText:function(){return this.snapshot},insert:function(e,t,n){var r=[{p:e,i:t}];return this.submitOp(r,n),r},del:function(e,t,n){var r=[{p:e,d:this.snapshot.slice(e,e+t)}];return this.submitOp(r,n),r},_register:function(){return this.on("remoteop",function(e){var t,n,r,i=[];for(n=0,r=e.length;n<r;n++)t=e[n],t.i!==void 0?i.push(this.emit("insert",t.p,t.i)):i.push(this.emit("delete",t.p,t.d));return i})}},a.extendDoc=function(e,t){return n.prototype[e]=t},n=function(){function e(e,t,n){this.connection=e,this.name=t,this.shout=g(this.shout,this),this.flush=g(this.flush,this),n||(n={}),this.version=n.v,this.snapshot=n.snaphot,n.type&&this._setType(n.type),this.state="closed",this.autoOpen=!1,this._create=n.create,this.inflightOp=null,this.inflightCallbacks=[],this.inflightSubmittedIds=[],this.pendingOp=null,this.pendingCallbacks=[],this.serverOps={}}return e.prototype._xf=function(e,t){var n,r;return this.type.transformX?this.type.transformX(e,t):(n=this.type.transform(e,t,"left"),r=this.type.transform(t,e,"right"),[n,r])},e.prototype._otApply=function(e,t){var n=this.snapshot;this.snapshot=this.type.apply(this.snapshot,e),this.emit("change",e,n);if(t)return this.emit("remoteop",e,n)},e.prototype._connectionStateChanged=function(e,t){switch(e){case"disconnected":this.state="closed",this.inflightOp&&this.inflightSubmittedIds.push(this.connection.id),this.emit("closed");break;case"ok":this.autoOpen&&this.open();break;case"stopped":typeof this._openCallback=="function"&&this._openCallback(t)}return this.emit(e,t)},e.prototype._setType=function(e){var t,n,r;typeof e=="string"&&(e=v[e]);if(!e||!e.compose)throw new Error("Support for types without compose() is not implemented");this.type=e;if(e.api){r=e.api;for(t in r)n=r[t],this[t]=n;return typeof this._register=="function"?this._register():void 0}return this.provides={}},e.prototype._onMessage=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,b,w,E;if(e.open===!0)return this.state="open",this._create=!1,this.created==null&&(this.created=!!e.create),e.type&&this._setType(e.type),e.create?(this.created=!0,this.snapshot=this.type.create()):(this.created!==!0&&(this.created=!1),e.snapshot!==void 0&&(this.snapshot=e.snapshot)),e.v!=null&&(this.version=e.v),this.inflightOp?(u={doc:this.name,op:this.inflightOp,v:this.version},this.inflightSubmittedIds.length&&(u.dupIfSource=this.inflightSubmittedIds),this.connection.send(u)):this.flush(),this.emit("open"),typeof this._openCallback=="function"?this._openCallback(null):void 0;if(e.open===!1)return e.error&&(typeof console!="undefined"&&console!==null&&console.error("Could not open document: "+e.error),this.emit("error",e.error),typeof this._openCallback=="function"&&this._openCallback(e.error)),this.state="closed",this.emit("closed"),typeof this._closeCallback=="function"&&this._closeCallback(),this._closeCallback=null;if(e.op!==null||r!=="Op already submitted"){if(e.op===void 0&&e.v!==void 0||e.op&&(d=e.meta.source,y.call(this.inflightSubmittedIds,d)>=0)){i=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,r=e.error;if(r){this.type.invert?(a=this.type.invert(i),this.pendingOp&&(v=this._xf(this.pendingOp,a),this.pendingOp=v[0],a=v[1]),this._otApply(a,!0)):this.emit("error","Op apply failed ("+r+") and the op could not be reverted"),m=this.inflightCallbacks;for(l=0,h=m.length;l<h;l++)t=m[l],t(r)}else{if(e.v!==this.version)throw new Error("Invalid version from server");this.serverOps[this.version]=i,this.version++,this.emit("acknowledge",i),g=this.inflightCallbacks;for(c=0,p=g.length;c<p;c++)t=g[c],t(null,i)}return this.flush()}if(e.op){if(e.v<this.version)return;return e.doc!==this.name?this.emit("error","Expected docName '"+this.name+"' but got "+e.doc):e.v!==this.version?this.emit("error","Expected version "+this.version+" but got "+e.v):(s=e.op,this.serverOps[this.version]=s,n=s,this.inflightOp!==null&&(b=this._xf(this.inflightOp,n),this.inflightOp=b[0],n=b[1]),this.pendingOp!==null&&(w=this._xf(this.pendingOp,n),this.pendingOp=w[0],n=w[1]),this.version++,this._otApply(n,!0))}if(!e.meta)return typeof console!="undefined"&&console!==null?console.warn("Unhandled document message:",e):void 0;E=e.meta,o=E.path,f=E.value;switch(o!=null?o[0]:void 0){case"shout":return this.emit("shout",f);default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled meta op:",e):void 0}}},e.prototype.flush=function(){if(this.connection.state!=="ok"||this.inflightOp!==null||this.pendingOp===null)return;return this.inflightOp=this.pendingOp,this.inflightCallbacks=this.pendingCallbacks,this.pendingOp=null,this.pendingCallbacks=[],this.connection.send({doc:this.name,op:this.inflightOp,v:this.version})},e.prototype.submitOp=function(e,t){return this.type.normalize!=null&&(e=this.type.normalize(e)),this.snapshot=this.type.apply(this.snapshot,e),this.pendingOp!==null?this.pendingOp=this.type.compose(this.pendingOp,e):this.pendingOp=e,t&&this.pendingCallbacks.push(t),this.emit("change",e),setTimeout(this.flush,0)},e.prototype.shout=function(e){return this.connection.send({doc:this.name,meta:{path:["shout"],value:e}})},e.prototype.open=function(e){var t,n=this;this.autoOpen=!0;if(this.state!=="closed")return;return t={doc:this.name,open:!0},this.snapshot===void 0&&(t.snapshot=null),this.type&&(t.type=this.type.name),this.version!=null&&(t.v=this.version),this._create&&(t.create=!0),this.connection.send(t),this.state="opening",this._openCallback=function(t){return n._openCallback=null,typeof e=="function"?e(t):void 0}},e.prototype.close=function(e){return this.autoOpen=!1,this.state==="closed"?typeof e=="function"?e():void 0:(this.connection.send({doc:this.name,open:!1}),this.state="closed",this.emit("closing"),this._closeCallback=e)},e}(),r.mixin(n),a.Doc=n,v=a.types;if(!window.BCSocket)throw new Error("Must load browserchannel before this library");e=window.BCSocket,t=function(){function t(t){var n=this;this.docs={},this.state="connecting",this.socket=new e(t,{reconnect:!0}),this.socket.onmessage=function(e){var t;if(e.auth===null)return n.lastError=e.error,n.disconnect(),n.emit("connect failed",e.error);if(e.auth){n.id=e.auth,n.setState("ok");return}return t=e.doc,t!==void 0?n.lastReceivedDoc=t:e.doc=t=n.lastReceivedDoc,n.docs[t]?n.docs[t]._onMessage(e):typeof console!="undefined"&&console!==null?console.error("Unhandled message",e):void 0},this.connected=!1,this.socket.onclose=function(e){n.setState("disconnected",e);if(e==="Closed"||e==="Stopped by server")return n.setState("stopped",n.lastError||e)},this.socket.onerror=function(e){return n.emit("error",e)},this.socket.onopen=function(){return n.lastError=n.lastReceivedDoc=n.lastSentDoc=null,n.setState("handshaking")},this.socket.onconnecting=function(){return n.setState("connecting")}}return t.prototype.setState=function(e,t){var n,r,i,s;if(this.state===e)return;this.state=e,e==="disconnected"&&delete this.id,this.emit(e,t),i=this.docs,s=[];for(r in i)n=i[r],s.push(n._connectionStateChanged(e,t));return s},t.prototype.send=function(e){var t=e.doc;return t===this.lastSentDoc?delete e.doc:this.lastSentDoc=t,this.socket.send(e)},t.prototype.disconnect=function(){return this.socket.close()},t.prototype.makeDoc=function(e,t,r){var i,s=this;if(this.docs[e])throw new Error("Doc "+e+" already open");return i=new n(this,e,t),this.docs[e]=i,i.open(function(t){return t&&delete s.docs[e],r(t,t?void 0:i)})},t.prototype.openExisting=function(e,t){var n;return this.state==="stopped"?t("connection closed"):this.docs[e]?t(null,this.docs[e]):n=this.makeDoc(e,{},t)},t.prototype.open=function(e,t,n){var r;if(this.state==="stopped")return n("connection closed");typeof t=="function"&&(n=t,t="text"),n||(n=function(){}),typeof t=="string"&&(t=v[t]);if(!t)throw new Error("OT code for document type missing");if(e==null)throw new Error("Server-generated random doc names are not currently supported");if(this.docs[e]){r=this.docs[e],r.type===t?n(null,r):n("Type mismatch",r);return}return this.makeDoc(e,{create:!0,type:t.name},n)},t}(),r.mixin(t),a.Connection=t,a.open=function(){var e={},n=function(n){var r,i,s;return s=window.location,n==null&&(n=""+s.protocol+"//"+s.host+"/channel"),e[n]||(r=new t(n),i=function(){return delete e[n]},r.on("disconnecting",i),r.on("connect failed",i),e[n]=r),e[n]},r=function(e){var t,n,r=0,i=e.docs;for(n in i)t=i[n],(t.state!=="closed"||t.autoOpen)&&r++;if(r===0)return e.disconnect()};return function(e,t,i,s){var o;return typeof i=="function"&&(s=i,i=null),o=n(i),o.numDocs++,o.open(e,t,function(e,t){return e?(s(e),r(o)):(t.on("closed",function(){return r(o)}),s(null,t))}),o.on("connect failed"),o}}()}).call(this)
+(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w=[].slice,E=function(e,t){return function(){return e.apply(t,arguments)}},S=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1};window.sharejs=f={version:"0.5.0"},p=function(e){return setTimeout(e,0)},r=function(){function e(){}return e.prototype.on=function(e,t){var n;return this._events||(this._events={}),(n=this._events)[e]||(n[e]=[]),this._events[e].push(t),this},e.prototype.removeListener=function(e,t){var n,r,i,s=this;this._events||(this._events={}),r=(i=this._events)[e]||(i[e]=[]),n=0;while(n<r.length)r[n]===t&&(r[n]=void 0),n++;return p(function(){var t;return s._events[e]=function(){var n,r,i=this._events[e],s=[];for(n=0,r=i.length;n<r;n++)t=i[n],t&&s.push(t);return s}.call(s)}),this},e.prototype.emit=function(){var e,t,n,r,i,s=arguments[0],o=2<=arguments.length?w.call(arguments,1):[];if((r=this._events)!=null?!r[s]:!void 0)return this;i=this._events[s];for(t=0,n=i.length;t<n;t++)e=i[t],e&&e.apply(this,o);return this},e}(),r.mixin=function(e){var t=e.prototype||e;return t.on=r.prototype.on,t.removeListener=r.prototype.removeListener,t.emit=r.prototype.emit,e},f._bt=o=function(e,t,n,r){var i,s=function(e,n,r,i){return t(r,e,n,"left"),t(i,n,e,"right")};return e.transformX=e.transformX=i=function(e,t){var o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T;n(e),n(t),l=[];for(v=0,b=t.length;v<b;v++){d=t[v],f=[],o=0;while(o<e.length){c=[],s(e[o],d,f,c),o++;if(c.length!==1){if(c.length===0){x=e.slice(o);for(m=0,w=x.length;m<w;m++)u=x[m],r(f,u);d=null;break}T=i(e.slice(o),c),a=T[0],p=T[1];for(g=0,E=a.length;g<E;g++)u=a[g],r(f,u);for(y=0,S=p.length;y<S;y++)h=p[y],r(l,h);d=null;break}d=c[0]}d!=null&&r(l,d),e=f}return[e,l]},e.transform=e.transform=function(e,n,r){var s,o,u,a,f;if(r!=="left"&&r!=="right")throw new Error("type must be 'left' or 'right'");return n.length===0?e:e.length===1&&n.length===1?t([],e[0],n[0],r):r==="left"?(a=i(e,n),s=a[0],u=a[1],s):(f=i(n,e),u=f[0],o=f[1],o)}},v={},v.name="text",v.create=function(){return""},d=function(e,t,n){return e.slice(0,t)+n+e.slice(t)},u=function(e){var t,n;if(typeof e.p!="number")throw new Error("component missing position field");n=typeof e.i,t=typeof e.d;if(!(n==="string"^t==="string"))throw new Error("component needs an i or d field");if(!(e.p>=0))throw new Error("position cannot be negative")},a=function(e){var t,n,r;for(n=0,r=e.length;n<r;n++)t=e[n],u(t);return!0},v.apply=function(e,t){var n,r,i,s;a(t);for(i=0,s=t.length;i<s;i++){n=t[i];if(n.i!=null)e=d(e,n.p,n.i);else{r=e.slice(n.p,n.p+n.d.length);if(n.d!==r)throw new Error("Delete component '"+n.d+"' does not match deleted text '"+r+"'");e=e.slice(0,n.p)+e.slice(n.p+n.d.length)}}return e},v._append=s=function(e,t){var n,r,i;if(t.i===""||t.d==="")return;return e.length===0?e.push(t):(n=e[e.length-1],n.i!=null&&t.i!=null&&n.p<=(r=t.p)&&r<=n.p+n.i.length?e[e.length-1]={i:d(n.i,t.p-n.p,t.i),p:n.p}:n.d!=null&&t.d!=null&&t.p<=(i=n.p)&&i<=t.p+t.d.length?e[e.length-1]={d:d(t.d,n.p-t.p,n.d),p:t.p}:e.push(t))},v.compose=function(e,t){var n,r,i,o;a(e),a(t),r=e.slice();for(i=0,o=t.length;i<o;i++)n=t[i],s(r,n);return r},v.compress=function(e){return v.compose([],e)},v.normalize=function(e){var t,n,r,i,o=[];if(e.i!=null||e.p!=null)e=[e];for(n=0,r=e.length;n<r;n++)t=e[n],(i=t.p)==null&&(t.p=0),s(o,t);return o},g=function(e,t,n){return t.i!=null?t.p<e||t.p===e&&n?e+t.i.length:e:e<=t.p?e:e<=t.p+t.d.length?t.p:e-t.d.length},v.transformCursor=function(e,t,n){var r,i,s,o=n==="right";for(i=0,s=t.length;i<s;i++)r=t[i],e=g(e,r,o);return e},v._tc=m=function(e,t,n,r){var i,o,u,f,l,c;a([t]),a([n]);if(t.i!=null)s(e,{i:t.i,p:g(t.p,n,r==="right")});else if(n.i!=null)c=t.d,t.p<n.p&&(s(e,{d:c.slice(0,n.p-t.p),p:t.p}),c=c.slice(n.p-t.p)),c!==""&&s(e,{d:c,p:t.p+n.i.length});else if(t.p>=n.p+n.d.length)s(e,{d:t.d,p:t.p-n.d.length});else if(t.p+t.d.length<=n.p)s(e,t);else{f={d:"",p:t.p},t.p<n.p&&(f.d=t.d.slice(0,n.p-t.p)),t.p+t.d.length>n.p+n.d.length&&(f.d+=t.d.slice(n.p+n.d.length-t.p)),u=Math.max(t.p,n.p),o=Math.min(t.p+t.d.length,n.p+n.d.length),i=t.d.slice(u-t.p,o-t.p),l=n.d.slice(u-n.p,o-n.p);if(i!==l)throw new Error("Delete ops delete different text in the same region of the document");f.d!==""&&(f.p=g(f.p,n),s(e,f))}return e},h=function(e){return e.i!=null?{d:e.i,p:e.p}:{i:e.d,p:e.p}},v.invert=function(e){var t,n,r,i=e.slice().reverse(),s=[];for(n=0,r=i.length;n<r;n++)t=i[n],s.push(h(t));return s},f.types||(f.types={}),o(v,m,a,s),f.types.text=v,v.api={provides:{text:!0},getLength:function(){return this.snapshot.length},getText:function(){return this.snapshot},insert:function(e,t,n){var r=[{p:e,i:t}];return this.submitOp(r,n),r},del:function(e,t,n){var r=[{p:e,d:this.snapshot.slice(e,e+t)}];return this.submitOp(r,n),r},_register:function(){return this.on("remoteop",function(e){var t,n,r,i=[];for(n=0,r=e.length;n<r;n++)t=e[n],t.i!==void 0?i.push(this.emit("insert",t.p,t.i)):i.push(this.emit("delete",t.p,t.d));return i})}},f.extendDoc=function(e,t){return n.prototype[e]=t},n=function(){function e(e,t,n){this.connection=e,this.name=t,this.shout=E(this.shout,this),this.flush=E(this.flush,this),n||(n={}),this.version=n.v,this.snapshot=n.snaphot,n.type&&this._setType(n.type),this.state="closed",this.autoOpen=!1,this._create=n.create,this.inflightOp=null,this.inflightCallbacks=[],this.inflightSubmittedIds=[],this.pendingOp=null,this.pendingCallbacks=[],this.serverOps={}}return e.prototype._xf=function(e,t){var n,r;return this.type.transformX?this.type.transformX(e,t):(n=this.type.transform(e,t,"left"),r=this.type.transform(t,e,"right"),[n,r])},e.prototype._otApply=function(e,t){var n=this.snapshot;this.snapshot=this.type.apply(this.snapshot,e),this.emit("change",e,n);if(t)return this.emit("remoteop",e,n)},e.prototype._connectionStateChanged=function(e,t){switch(e){case"disconnected":this.state="closed",this.inflightOp&&this.inflightSubmittedIds.push(this.connection.id),this.emit("closed");break;case"ok":this.autoOpen&&this.open();break;case"stopped":typeof this._openCallback=="function"&&this._openCallback(t)}return this.emit(e,t)},e.prototype._setType=function(e){var t,n,r;typeof e=="string"&&(e=y[e]);if(!e||!e.compose)throw new Error("Support for types without compose() is not implemented");this.type=e;if(e.api){r=e.api;for(t in r)n=r[t],this[t]=n;return typeof this._register=="function"?this._register():void 0}return this.provides={}},e.prototype._onMessage=function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w;if(e.open===!0)return this.state="open",this._create=!1,this.created==null&&(this.created=!!e.create),e.type&&this._setType(e.type),e.create?(this.created=!0,this.snapshot=this.type.create()):(this.created!==!0&&(this.created=!1),e.snapshot!==void 0&&(this.snapshot=e.snapshot)),e.v!=null&&(this.version=e.v),this.inflightOp?(u={doc:this.name,op:this.inflightOp,v:this.version},this.inflightSubmittedIds.length&&(u.dupIfSource=this.inflightSubmittedIds),this.connection.send(u)):this.flush(),this.emit("open"),typeof this._openCallback=="function"?this._openCallback(null):void 0;if(e.open===!1)return e.error&&(typeof console!="undefined"&&console!==null&&console.error("Could not open document: "+e.error),this.emit("error",e.error),typeof this._openCallback=="function"&&this._openCallback(e.error)),this.state="closed",this.emit("closed"),typeof this._closeCallback=="function"&&this._closeCallback(),this._closeCallback=null;if(e.op!==null||r!=="Op already submitted"){if(e.op===void 0&&e.v!==void 0||e.op&&(d=e.meta.source,S.call(this.inflightSubmittedIds,d)>=0)){i=this.inflightOp,this.inflightOp=null,this.inflightSubmittedIds.length=0,r=e.error;if(r){this.type.invert?(a=this.type.invert(i),this.pendingOp&&(v=this._xf(this.pendingOp,a),this.pendingOp=v[0],a=v[1]),this._otApply(a,!0)):this.emit("error","Op apply failed ("+r+") and the op could not be reverted"),m=this.inflightCallbacks;for(l=0,h=m.length;l<h;l++)t=m[l],t(r)}else{if(e.v!==this.version)throw new Error("Invalid version from server");this.serverOps[this.version]=i,this.version++,this.emit("acknowledge",i),g=this.inflightCallbacks;for(c=0,p=g.length;c<p;c++)t=g[c],t(null,i)}return this.flush()}if(e.op){if(e.v<this.version)return;return e.doc!==this.name?this.emit("error","Expected docName '"+this.name+"' but got "+e.doc):e.v!==this.version?this.emit("error","Expected version "+this.version+" but got "+e.v):(s=e.op,this.serverOps[this.version]=s,n=s,this.inflightOp!==null&&(y=this._xf(this.inflightOp,n),this.inflightOp=y[0],n=y[1]),this.pendingOp!==null&&(b=this._xf(this.pendingOp,n),this.pendingOp=b[0],n=b[1]),this.version++,this._otApply(n,!0))}if(!e.meta)return typeof console!="undefined"&&console!==null?console.warn("Unhandled document message:",e):void 0;w=e.meta,o=w.path,f=w.value;switch(o!=null?o[0]:void 0){case"shout":return this.emit("shout",f);default:return typeof console!="undefined"&&console!==null?console.warn("Unhandled meta op:",e):void 0}}},e.prototype.flush=function(){if(this.connection.state!=="ok"||this.inflightOp!==null||this.pendingOp===null)return;return this.inflightOp=this.pendingOp,this.inflightCallbacks=this.pendingCallbacks,this.pendingOp=null,this.pendingCallbacks=[],this.connection.send({doc:this.name,op:this.inflightOp,v:this.version})},e.prototype.submitOp=function(e,t){return this.type.normalize!=null&&(e=this.type.normalize(e)),this.snapshot=this.type.apply(this.snapshot,e),this.pendingOp!==null?this.pendingOp=this.type.compose(this.pendingOp,e):this.pendingOp=e,t&&this.pendingCallbacks.push(t),this.emit("change",e),setTimeout(this.flush,0)},e.prototype.shout=function(e){return this.connection.send({doc:this.name,meta:{path:["shout"],value:e}})},e.prototype.open=function(e){var t,n=this;this.autoOpen=!0;if(this.state!=="closed")return;return t={doc:this.name,open:!0},this.snapshot===void 0&&(t.snapshot=null),this.type&&(t.type=this.type.name),this.version!=null&&(t.v=this.version),this._create&&(t.create=!0),this.connection.send(t),this.state="opening",this._openCallback=function(t){return n._openCallback=null,typeof e=="function"?e(t):void 0}},e.prototype.close=function(e){return this.autoOpen=!1,this.state==="closed"?typeof e=="function"?e():void 0:(this.connection.send({doc:this.name,open:!1}),this.state="closed",this.emit("closing"),this._closeCallback=e)},e}(),r.mixin(n),f.Doc=n,y=f.types,e=window.BCSocket,i=window.SockJS,t=function(){function t(t){var n=this;this.docs={},this.state="connecting",this.socket=typeof b!="undefined"&&b!==null?new i(t):new e(t,{reconnect:!0}),this.socket.onmessage=function(e){var t;typeof b!="undefined"&&b!==null&&(e=JSON.parse(e.data));if(e.auth===null)return n.lastError=e.error,n.disconnect(),n.emit("connect failed",e.error);if(e.auth){n.id=e.auth,n.setState("ok");return}return t=e.doc,t!==void 0?n.lastReceivedDoc=t:e.doc=t=n.lastReceivedDoc,n.docs[t]?n.docs[t]._onMessage(e):typeof console!="undefined"&&console!==null?console.error("Unhandled message",e):void 0},this.connected=!1,this.socket.onclose=function(e){n.setState("disconnected",e);if(e==="Closed"||e==="Stopped by server")return n.setState("stopped",n.lastError||e)},this.socket.onerror=function(e){return n.emit("error",e)},this.socket.onopen=function(){return n.lastError=n.lastReceivedDoc=n.lastSentDoc=null,n.setState("handshaking")},this.socket.onconnecting=function(){return n.setState("connecting")}}return t.prototype.setState=function(e,t){var n,r,i,s;if(this.state===e)return;this.state=e,e==="disconnected"&&delete this.id,this.emit(e,t),i=this.docs,s=[];for(r in i)n=i[r],s.push(n._connectionStateChanged(e,t));return s},t.prototype.send=function(e){var t=e.doc;return t===this.lastSentDoc?delete e.doc:this.lastSentDoc=t,typeof b!="undefined"&&b!==null&&(e=JSON.stringify(e)),this.socket.send(e)},t.prototype.disconnect=function(){return this.socket.close()},t.prototype.makeDoc=function(e,t,r){var i,s=this;if(this.docs[e])throw new Error("Doc "+e+" already open");return i=new n(this,e,t),this.docs[e]=i,i.open(function(t){return t&&delete s.docs[e],r(t,t?void 0:i)})},t.prototype.openExisting=function(e,t){var n;return this.state==="stopped"?t("connection closed"):this.docs[e]?t(null,this.docs[e]):n=this.makeDoc(e,{},t)},t.prototype.open=function(e,t,n){var r;if(this.state==="stopped")return n("connection closed");if(this.state==="connecting"){this.on("handshaking",function(){return this.open(e,t,n)});return}typeof t=="function"&&(n=t,t="text"),n||(n=function(){}),typeof t=="string"&&(t=y[t]);if(!t)throw new Error("OT code for document type missing");if(e==null)throw new Error("Server-generated random doc names are not currently supported");if(this.docs[e]){r=this.docs[e],r.type===t?n(null,r):n("Type mismatch",r);return}return this.makeDoc(e,{create:!0,type:t.name},n)},t}(),r.mixin(t),f.Connection=t,l=window.BCSocket!==void 0,c=window.SockJS!==void 0;if(!l&&!c)throw new Error("Must load socks or browserchannel before this library");b=c&&!l,f.open=function(){var e={},n=function(n){var r,i,s,o;return s=window.location,o=b?"sockjs":"channel",n==null&&(n=""+s.protocol+"//"+s.host+"/"+o),e[n]||(r=new t(n),i=function(){return delete e[n]},r.on("disconnecting",i),r.on("connect failed",i),e[n]=r),e[n]},r=function(e){var t,n,r=0,i=e.docs;for(n in i)t=i[n],(t.state!=="closed"||t.autoOpen)&&r++;if(r===0)return e.disconnect()};return function(e,t,i,s){var o;return typeof i=="function"&&(s=i,i=null),o=n(i),o.numDocs++,o.open(e,t,function(e,t){return e?(s(e),r(o)):(t.on("closed",function(){return r(o)}),s(null,t))}),o.on("connect failed"),o}}()}).call(this)
View
35 webclient/share.uncompressed.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var BCSocket, Connection, Doc, MicroEvent, append, bootstrapTransform, checkValidComponent, checkValidOp, exports, invertComponent, nextTick, strInject, text, transformComponent, transformPosition, types,
+ var BCSocket, Connection, Doc, MicroEvent, SockJS, append, bootstrapTransform, checkValidComponent, checkValidOp, exports, hasBCSocket, hasSockJS, invertComponent, nextTick, strInject, text, transformComponent, transformPosition, types, useSockJS,
__slice = [].slice,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
@@ -781,10 +781,7 @@
if (typeof WEB !== "undefined" && WEB !== null) {
types = exports.types;
- if (!window.BCSocket) {
- throw new Error('Must load browserchannel before this library');
- }
- BCSocket = window.BCSocket;
+ BCSocket = window.BCSocket, SockJS = window.SockJS;
} else {
types = require('../types');
BCSocket = require('browserchannel').BCSocket;
@@ -797,11 +794,14 @@
var _this = this;
this.docs = {};
this.state = 'connecting';
- this.socket = new BCSocket(host, {
+ this.socket = typeof useSockJS !== "undefined" && useSockJS !== null ? new SockJS(host) : new BCSocket(host, {
reconnect: true
});
this.socket.onmessage = function(msg) {
var docName;
+ if (typeof useSockJS !== "undefined" && useSockJS !== null) {
+ msg = JSON.parse(msg.data);
+ }
if (msg.auth === null) {
_this.lastError = msg.error;
_this.disconnect();
@@ -869,6 +869,9 @@
} else {
this.lastSentDoc = docName;
}
+ if (typeof useSockJS !== "undefined" && useSockJS !== null) {
+ data = JSON.stringify(data);
+ }
return this.socket.send(data);
};
@@ -908,6 +911,12 @@
if (this.state === 'stopped') {
return callback('connection closed');
}
+ if (this.state === 'connecting') {
+ this.on('handshaking', function() {
+ return this.open(docName, type, callback);
+ });
+ return;
+ }
if (typeof type === 'function') {
callback = type;
type = 'text';
@@ -949,19 +958,27 @@
exports.Connection = Connection;
- if (typeof WEB === "undefined" || WEB === null) {
+ if (typeof WEB !== "undefined" && WEB !== null) {
+ hasBCSocket = window.BCSocket !== void 0;
+ hasSockJS = window.SockJS !== void 0;
+ if (!(hasBCSocket || hasSockJS)) {
+ throw new Error('Must load socks or browserchannel before this library');
+ }
+ useSockJS = hasSockJS && !hasBCSocket;
+ } else {
Connection = require('./connection').Connection;
}
exports.open = (function() {
var connections, getConnection, maybeClose;
connections = {};
getConnection = function(origin) {
- var c, del, location;
+ var c, del, location, path;
if (typeof WEB !== "undefined" && WEB !== null) {
location = window.location;
+ path = useSockJS ? 'sockjs' : 'channel';
if (origin == null) {
- origin = "" + location.protocol + "//" + location.host + "/channel";
+ origin = "" + location.protocol + "//" + location.host + "/" + path;
}
}
if (!connections[origin]) {

1 comment on commit 23ead4a

@wmertens

Well this broke the tests :-) Turns out this is because the sockjs pull didn't include an updated webclient (mea culpa). Trying to fix.

Please sign in to comment.