sync process

This commit is contained in:
Kevin Jahns 2014-09-29 11:58:30 +02:00
parent 8fcd8f6809
commit c337f37665
40 changed files with 154 additions and 64 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
!function n(e,t,r){function o(u,c){if(!t[u]){if(!e[u]){var s="function"==typeof require&&require;if(!c&&s)return s(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var f=t[u]={exports:{}};e[u][0].call(f.exports,function(n){var t=e[u][1][n];return o(t?t:n)},f,f.exports,n,e,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,e){var t;t=function(){var n,e,t;return t=null,2===arguments.length?(t=new Peer(arguments[0]),e=arguments[1]):(t=new Peer(arguments[0],arguments[1]),t.on("error",function(n){throw new Error("Peerjs connector: "+n)}),t.on("disconnected",function(){throw new Error("Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either..")}),e=arguments[2]),n=function(){function n(n,e,r,o){var i;this.engine=n,this.HB=e,this.execution_listener=r,this.yatta=o,this.peer=t,this.connections={},this.peer.on("connection",function(n){return function(e){return n.addConnection(e)}}(this)),i=function(n){return function(e){var t,r,o,i;if(e.uid.creator===n.HB.getUserId()&&"string"!=typeof e.uid.op_number){o=n.connections,i=[];for(r in o)t=o[r],i.push(t.send({op:e}));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(t.connect(n)):void 0},n.prototype.getAllConnectionIds=function(){var n,e;e=[];for(n in this.connections)e.push(n);return e},n.prototype.addConnection=function(n){var e,t,r;return this.connections[n.peer]=n,t=!1,e=!1,n.on("data",function(r){return function(o){var i,u,c,s,f;if("empty_message"===o);else{if(null!=o.HB)return t=!0,r.engine.applyOpsCheckDouble(o.HB),n.send({conns:r.getAllConnectionIds()});if(null!=o.op)return r.engine.applyOp(o.op);if(null!=o.conns){for(s=o.conns,f=[],u=0,c=s.length;c>u;u++)i=s[u],f.push(r.connectToPeer(i));return f}if(null==o.state_vector)throw new Error("Can't parse this operation");if(!e)return n.send({HB:r.yatta.getHistoryBuffer()._encode(o.state_vector)}),e=!0}}}(this)),r=function(e){return function(){return n.send({state_vector:e.HB.getOperationCounter()}),t?void 0:setTimeout(r,100)}}(this),r()},n}(),t.on("open",function(t){return e(n,t)})},e.exports=t,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=t)},{}]},{},[1]);
!function n(e,t,r){function o(u,s){if(!t[u]){if(!e[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=t[u]={exports:{}};e[u][0].call(a.exports,function(n){var t=e[u][1][n];return o(t?t:n)},a,a.exports,n,e,t,r)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(n,e){var t;t=function(){var n,e,t;return t=null,2===arguments.length?(t=new Peer(arguments[0]),e=arguments[1]):(t=new Peer(arguments[0],arguments[1]),t.on("error",function(n){throw new Error("Peerjs connector: "+n)}),t.on("disconnected",function(){throw new Error("Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either..")}),e=arguments[2]),n=function(){function n(n,e,r,o){var i,u;this.engine=n,this.HB=e,this.execution_listener=r,this.yatta=o,this.peer=t,this.connections={},this.peer.on("connection",function(n){return function(e){return n.addConnection(e)}}(this)),u=function(n){return function(){var e,t,r,o;r=n.connections,o=[];for(t in r)e=r[t],o.push(e.send({sync_state_vector:n.HB.getOperationCounter()}));return o}}(this),setInterval(u,8e3),i=function(n){return function(e){var t,r,o,i;if(e.uid.creator===n.HB.getUserId()&&"string"!=typeof e.uid.op_number){o=n.connections,i=[];for(r in o)t=o[r],i.push(t.send({op:e}));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(t.connect(n)):void 0},n.prototype.getAllConnectionIds=function(){var n,e;e=[];for(n in this.connections)e.push(n);return e},n.prototype.addConnection=function(n){var e,t,r;return this.connections[n.peer]=n,t=!1,e=!1,n.on("data",function(r){return function(o){var i,u,s,c,a;if("empty_message"===o);else if(null!=o.HB){if(t=!0,r.engine.applyOpsCheckDouble(o.HB),!o.initialized)return n.send({conns:r.getAllConnectionIds()})}else{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.sync_state_vector)return console.log("turinae"),n.send({HB:r.yatta.getHistoryBuffer()._encode(o.sync_state_vector),initialized:!0});if(null==o.state_vector)throw new Error("Can't parse this operation");if(!e)return n.send({HB:r.yatta.getHistoryBuffer()._encode(o.state_vector),initialized:!1}),e=!0}}}(this)),r=function(e){return function(){return n.send({state_vector:e.HB.getOperationCounter()}),t?void 0:setTimeout(r,100)}}(this),r()},n}(),t.on("open",function(t){return e(n,t)})},e.exports=t,"undefined"!=typeof window&&null!==window&&(null==window.Y&&(window.Y={}),window.Y.createPeerJsConnector=t)},{}]},{},[1]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,7 +19,7 @@
}
PeerJsConnector = (function() {
function PeerJsConnector(engine, HB, execution_listener, yatta) {
var send_;
var send_, sync_every_collaborator;
this.engine = engine;
this.HB = HB;
this.execution_listener = execution_listener;
@ -31,6 +31,21 @@
return _this.addConnection(conn);
};
})(this));
sync_every_collaborator = (function(_this) {
return function() {
var conn, conn_id, _ref, _results;
_ref = _this.connections;
_results = [];
for (conn_id in _ref) {
conn = _ref[conn_id];
_results.push(conn.send({
sync_state_vector: _this.HB.getOperationCounter()
}));
}
return _results;
};
})(this);
setInterval(sync_every_collaborator, 8000);
send_ = (function(_this) {
return function(o) {
var conn, conn_id, _ref, _results;
@ -78,9 +93,11 @@
} else if (data.HB != null) {
initialized_me = true;
_this.engine.applyOpsCheckDouble(data.HB);
if (!data.initialized) {
return conn.send({
conns: _this.getAllConnectionIds()
});
}
} else if (data.op != null) {
return _this.engine.applyOp(data.op);
} else if (data.conns != null) {
@ -91,10 +108,17 @@
_results.push(_this.connectToPeer(conn_id));
}
return _results;
} else if (data.sync_state_vector != null) {
console.log("turinae");
return conn.send({
HB: _this.yatta.getHistoryBuffer()._encode(data.sync_state_vector),
initialized: true
});
} else if (data.state_vector != null) {
if (!initialized_him) {
conn.send({
HB: _this.yatta.getHistoryBuffer()._encode(data.state_vector)
HB: _this.yatta.getHistoryBuffer()._encode(data.state_vector),
initialized: false
});
return initialized_him = true;
}

File diff suppressed because one or more lines are too long

View File

@ -66,7 +66,9 @@
var o;
o = this.parseOperation(op_json);
this.HB.addToCounter(o);
if (!o.execute()) {
if (this.HB.getOperation(o) != null) {
} else if (!o.execute()) {
this.unprocessed_ops.push(o);
} else {
this.HB.addOperation(o);
@ -83,7 +85,9 @@
_ref = this.unprocessed_ops;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
op = _ref[_i];
if (!op.execute()) {
if (this.HB.getOperation(op) != null) {
} else if (!op.execute()) {
unprocessed.push(op);
} else {
this.HB.addOperation(op);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -271,7 +271,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -302,7 +302,7 @@ data from the received intent.</p>
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -335,7 +335,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -466,7 +466,7 @@ if (x.type === &quot;JsonType&quot;) {
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -139,7 +139,7 @@ console.log(w.newProperty == &quot;Awesome&quot;) # true!</code></pre>
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -222,7 +222,7 @@ on how to do that with urls.</p>
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -356,7 +356,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -455,7 +455,7 @@ yatta.bind(textbox);</code></pre>
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -252,7 +252,7 @@ This result can be send to other clients.</p>
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -38,7 +38,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -70,7 +70,7 @@ But I would become really motivated if you gave me some feedback :) (<a href="ht
<ul>
<li>XML support</li>
</ul>
<h2 id="support">Support</h2><p>Please report any issues to the <a href="https://github.com/DadaMonad/Yatta/issues">Github issue page</a>!</p><h2 id="license">License</h2><p>Yatta! is licensed under the <a href="./LICENSE.txt">MIT License</a>.</p><a href="&#x6d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#58;&#107;&#101;&#118;&#105;&#110;&#x2e;&#106;&#x61;&#x68;&#x6e;&#115;&#64;&#114;&#119;&#116;&#104;&#45;&#97;&#97;&#x63;&#104;&#101;&#110;&#46;&#100;&#101;">&#107;&#101;&#118;&#105;&#110;&#x2e;&#106;&#x61;&#x68;&#x6e;&#115;&#64;&#114;&#119;&#116;&#104;&#45;&#97;&#97;&#x63;&#104;&#101;&#110;&#46;&#100;&#101;</a>
<h2 id="support">Support</h2><p>Please report any issues to the <a href="https://github.com/DadaMonad/Yatta/issues">Github issue page</a>!</p><h2 id="license">License</h2><p>Yatta! is licensed under the <a href="./LICENSE.txt">MIT License</a>.</p><a href="&#109;&#97;&#x69;&#108;&#x74;&#111;&#58;&#107;&#101;&#118;&#x69;&#110;&#46;&#106;&#97;&#x68;&#110;&#115;&#64;&#x72;&#x77;&#116;&#x68;&#45;&#97;&#x61;&#x63;&#104;&#x65;&#110;&#x2e;&#x64;&#101;">&#107;&#101;&#118;&#x69;&#110;&#46;&#106;&#97;&#x68;&#110;&#115;&#64;&#x72;&#x77;&#116;&#x68;&#45;&#97;&#x61;&#x63;&#104;&#x65;&#110;&#x2e;&#x64;&#101;</a>
@ -79,7 +79,7 @@ But I would become really motivated if you gave me some feedback :) (<a href="ht
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -100,7 +100,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -158,7 +158,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -48,7 +48,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -60,7 +60,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -60,7 +60,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -48,7 +48,7 @@
</dl>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -65,7 +65,7 @@
</div>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -37,7 +37,7 @@
</table>
</div>
<div id='footer'>
September 29, 14 11:05:22 by
September 29, 14 11:58:14 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -43,6 +43,12 @@ createPeerJsConnector = ()->
@peer.on 'connection', (conn)=>
@addConnection conn
sync_every_collaborator = ()=>
for conn_id, conn of @connections
conn.send
sync_state_vector: @HB.getOperationCounter()
setInterval sync_every_collaborator, 8000
send_ = (o)=>
if o.uid.creator is @HB.getUserId() and (typeof o.uid.op_number isnt "string")
for conn_id,conn of @connections
@ -50,6 +56,9 @@ createPeerJsConnector = ()->
op: o
@execution_listener.push send_
#
# Connect the Framework to another peer. Therefore you have to receive his
# user_id. If the other peer is connected to other peers, the PeerJsConnector
@ -93,6 +102,7 @@ createPeerJsConnector = ()->
else if data.HB?
initialized_me = true
@engine.applyOpsCheckDouble data.HB
if not data.initialized
conn.send
conns: @getAllConnectionIds()
else if data.op?
@ -100,11 +110,17 @@ createPeerJsConnector = ()->
else if data.conns?
for conn_id in data.conns
@connectToPeer conn_id
else if data.sync_state_vector?
console.log "turinae"
conn.send
HB: @yatta.getHistoryBuffer()._encode(data.sync_state_vector)
initialized: true
else if data.state_vector?
if not initialized_him
# make sure, that it is sent only once
conn.send
HB: @yatta.getHistoryBuffer()._encode(data.state_vector)
initialized: false
initialized_him = true
else
throw new Error "Can't parse this operation"

View File

@ -61,7 +61,8 @@ class Engine
o = @parseOperation op_json
@HB.addToCounter o
# @HB.addOperation o
if not o.execute()
if @HB.getOperation(o)?
else if not o.execute()
@unprocessed_ops.push o
else
@HB.addOperation o
@ -76,7 +77,8 @@ class Engine
old_length = @unprocessed_ops.length
unprocessed = []
for op in @unprocessed_ops
if not op.execute()
if @HB.getOperation(op)?
else if not op.execute()
unprocessed.push op
else
@HB.addOperation op