yjs/build/node/Connectors/PeerJsConnector.js
2014-08-14 20:33:55 +02:00

2 lines
1.4 KiB
JavaScript

(function(){var n;n=function(n){var t,e;return e=new Peer({key:"h7nlefbgavh1tt9"}),t=function(){function n(n,t,o,i){var r;this.engine=n,this.HB=t,this.execution_listener=o,this.yatta=i,this.peer=e,this.connections=[],this.peer.on("connection",function(n){return function(t){return t.send("hey"),n.addConnection(t)}}(this)),r=function(n){return function(t){return n.send(t)}}(this),this.execution_listener.push(r)}return n.prototype.connectToPeer=function(n){return this.addConnection(e.connect(n))},n.prototype.addConnection=function(n){var t;return this.connections.push(n),n.on("data",function(n){return function(t){if("hey"!==t){if(null!=t.HB)return n.engine.applyOpsCheckDouble(t.HB);if(null!=t.op)return n.engine.applyOp(t.op);throw new Error("Can't parse this operation")}}}(this)),t=function(t){return function(){return n.send({HB:t.yatta.getHistoryBuffer()._encode()})}}(this),setTimeout(t,1e3)},n.prototype.send=function(n){var t,e,o,i,r;if(n.uid.creator===this.HB.getUserId()&&"string"!=typeof n.uid.op_number){for(i=this.connections,r=[],e=0,o=i.length;o>e;e++)t=i[e],r.push(t.send({op:n}));return r}},n.prototype.receive=function(n){return n.uid.creator!==this.HB.getUserId()?this.engine.applyOp(n):void 0},n}(),e.on("open",function(e){return n(t,e)})},module.exports=n,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=n)}).call(this);
//# sourceMappingURL=../Connectors/PeerJsConnector.js.map