yjs/build/browser/Connectors/PeerJsConnector.min.js
2014-09-25 19:38:33 +02:00

1 line
2.2 KiB
JavaScript

!function n(t,e,r){function o(u,s){if(!e[u]){if(!t[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var a=e[u]={exports:{}};t[u][0].call(a.exports,function(n){var e=t[u][1][n];return o(e?e:n)},a,a.exports,n,t,e,r)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,t){var e;e=function(){var n,t,e;return e=null,2===arguments.length?(e=new Peer(arguments[0]),t=arguments[1]):(e=new Peer(arguments[0],arguments[1]),t=arguments[2]),n=function(){function n(n,t,r,o){var i;this.engine=n,this.HB=t,this.execution_listener=r,this.yatta=o,this.peer=e,this.connections={},this.peer.on("connection",function(n){return function(t){return n.addConnection(t)}}(this)),i=function(n){return function(t){var e,r,o,i;if(t.creator===n.HB.getUserId()&&"string"!=typeof t.uid.op_number&&t.uid.sync){o=n.connections,i=[];for(r in o)e=o[r],i.push(e.send({op:t}));return i}}}(this),this.execution_listener.push(i)}return n.prototype.connectToPeer=function(n){return null==this.connections[n]&&n!==this.yatta.getUserId()?this.addConnection(e.connect(n)):void 0},n.prototype.getAllConnectionIds=function(){var n,t;t=[];for(n in this.connections)t.push(n);return t},n.prototype.addConnection=function(n){var t,e,r;return this.connections[n.peer]=n,e=!1,t=!1,n.on("data",function(r){return function(o){var i,u,s,c,a;if("empty_message"===o);else{if(null!=o.HB)return e=!0,r.engine.applyOpsCheckDouble(o.HB,o.state_vector),n.send({conns:r.getAllConnectionIds()});if(null!=o.op)return r.engine.applyOp(o.op);if(null!=o.conns){for(c=o.conns,a=[],u=0,s=c.length;s>u;u++)i=c[u],a.push(r.connectToPeer(i));return a}if(null==o.state_vector)throw new Error("Can't parse this operation");if(!t)return n.send({HB:r.yatta.getHistoryBuffer()._encode(o.state_vector),state_vector:r.yatta.HB.getOperationCounter()}),t=!0}}}(this)),r=function(t){return function(){return n.send({state_vector:t.HB.getOperationCounter()}),e?void 0:setTimeout(r,100)}}(this),r()},n}(),e.on("open",function(e){return t(n,e)})},t.exports=e,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=e)},{}]},{},[1]);