Added PeerJs error handlers

This commit is contained in:
Kevin Jahns 2014-09-29 11:06:05 +02:00
parent 03d652f70b
commit 8fcd8f6809
42 changed files with 171 additions and 162 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +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 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]),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,s,c,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(c=o.conns,f=[],u=0,s=c.length;s>u;u++)i=c[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,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]);

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

@ -9,6 +9,12 @@
callback = arguments[1];
} else {
peer = new Peer(arguments[0], arguments[1]);
peer.on('error', function(err) {
throw new Error("Peerjs connector: " + err);
});
peer.on('disconnected', function() {
throw new Error("Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either..");
});
callback = arguments[2];
}
PeerJsConnector = (function() {

File diff suppressed because one or more lines are too long

View File

@ -255,8 +255,8 @@
}
});
addPropertyListener = function(event, op) {
repl_manager.parent.callEvent('addProperty', property_name, op);
return repl_manager.deleteListener('addProperty', addPropertyListener);
repl_manager.deleteListener('addProperty', addPropertyListener);
return repl_manager.parent.callEvent('addProperty', property_name, op);
};
this.on('insert', addPropertyListener);
return ReplaceManager.__super__.setParent.call(this, parent);

File diff suppressed because one or more lines are too long

View File

@ -28,17 +28,21 @@
XmlType = (function(_super) {
__extends(XmlType, _super);
function XmlType(uid, tagname, attributes, elements, xml, prev, next, origin) {
var attr, element, i, last, n, word, _i, _j, _len, _ref, _ref1;
function XmlType(uid, tagname, attributes, elements, xml) {
var attr, element, i, n, word, _i, _j, _len, _ref, _ref1;
this.tagname = tagname;
this.xml = xml;
if ((prev != null) && (next == null) && (prev.type != null)) {
while (prev.isDeleted()) {
prev = prev.prev_cl;
}
next = prev.next_cl;
}
XmlType.__super__.constructor.call(this, uid, prev, next, origin);
/* In case you make this instanceof Insert again
if prev? and (not next?) and prev.type?
* adjust what you actually mean. you want to insert after prev, then
* next is not defined. but we only insert after non-deleted elements.
* This is also handled in TextInsert.
while prev.isDeleted()
prev = prev.prev_cl
next = prev.next_cl
*/
XmlType.__super__.constructor.call(this);
if ((attributes != null) && (elements != null)) {
this.saveOperation('attributes', attributes);
this.saveOperation('elements', elements);
@ -66,8 +70,7 @@
word.push(n.textContent);
this.elements.push(word);
} else if (n.nodeType === n.ELEMENT_NODE) {
last = this.elements.end;
element = new XmlType(void 0, void 0, void 0, void 0, n, last.prev_cl, last);
element = new XmlType(void 0, void 0, void 0, void 0, n);
HB.addOperation(element).execute();
this.elements.push(element);
} else {
@ -102,8 +105,9 @@
} else {
prev = this._yatta.elements.end.prev_cl;
}
element = new XmlType(void 0, void 0, void 0, void 0, insertedNode, prev);
return HB.addOperation(element).execute();
element = new XmlType(void 0, void 0, void 0, void 0);
HB.addOperation(element).execute();
return this.elements.insertAfter(prev, element);
});
};
@ -161,19 +165,14 @@
};
XmlType.prototype._encode = function() {
var json, _ref, _ref1, _ref2;
var json;
json = {
'type': this.type,
'attributes': this.attributes.getUid(),
'elements': this.elements.getUid(),
'tagname': this.tagname,
'uid': this.getUid(),
'prev': (_ref = this.prev_cl) != null ? _ref.getUid() : void 0,
'next': (_ref1 = this.next_cl) != null ? _ref1.getUid() : void 0
'uid': this.getUid()
};
if (this.origin !== this.prev_cl) {
json["origin"] = (_ref2 = this.origin) != null ? _ref2.getUid() : void 0;
}
return json;
};
@ -181,9 +180,9 @@
})(types.Insert);
parser['XmlType'] = function(json) {
var attributes, elements, next, origin, prev, tagname, uid;
uid = json['uid'], attributes = json['attributes'], elements = json['elements'], tagname = json['tagname'], prev = json['prev'], next = json['next'], origin = json['origin'];
return new XmlType(uid, tagname, attributes, elements, void 0, prev, next, origin);
var attributes, elements, tagname, uid;
uid = json['uid'], attributes = json['attributes'], elements = json['elements'], tagname = json['tagname'];
return new XmlType(uid, tagname, attributes, elements, void 0);
};
types['XmlType'] = XmlType;
return json_types;

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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -151,7 +151,7 @@ Use it in order to check whether this is an xml-type or something else.</p>
<p class='signature' id='constructor-dynamic'>
#
(void)
<b>constructor</b><span>(uid, tagname, attributes, elements, xml, prev, next, origin)</span>
<b>constructor</b><span>(uid, tagname, attributes, elements, xml)</span>
<br>
</p>
@ -252,7 +252,7 @@ This result can be send to other clients.</p>
</div>
</div>
<div id='footer'>
September 29, 14 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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;&#97;&#105;&#108;&#116;&#x6f;&#58;&#x6b;&#x65;&#118;&#x69;&#110;&#46;&#x6a;&#x61;&#104;&#110;&#x73;&#64;&#114;&#x77;&#116;&#104;&#x2d;&#x61;&#x61;&#x63;&#104;&#x65;&#x6e;&#x2e;&#x64;&#101;">&#x6b;&#x65;&#118;&#x69;&#110;&#46;&#x6a;&#x61;&#104;&#110;&#x73;&#64;&#114;&#x77;&#116;&#104;&#x2d;&#x61;&#x61;&#x63;&#104;&#x65;&#x6e;&#x2e;&#x64;&#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="&#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>
@ -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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 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 09:30:23 by
September 29, 14 11:05:22 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -15,6 +15,10 @@ createPeerJsConnector = ()->
callback = arguments[1]
else
peer = new Peer arguments[0], arguments[1]
peer.on 'error', (err)->
throw new Error "Peerjs connector: #{err}"
peer.on 'disconnected', ()->
throw new Error "Peerjs connector disconnected from signalling server. Cannot accept new connections. Not fatal, but not so good either.."
callback = arguments[2]

View File

@ -21,7 +21,8 @@ module.exports = (HB)->
#
class XmlType extends types.Insert
constructor: (uid, @tagname, attributes, elements, @xml, prev, next, origin)->
constructor: (uid, @tagname, attributes, elements, @xml)->
### In case you make this instanceof Insert again
if prev? and (not next?) and prev.type?
# adjust what you actually mean. you want to insert after prev, then
# next is not defined. but we only insert after non-deleted elements.
@ -29,8 +30,9 @@ module.exports = (HB)->
while prev.isDeleted()
prev = prev.prev_cl
next = prev.next_cl
###
super uid, prev, next, origin
super()
if attributes? and elements?
@saveOperation 'attributes', attributes
@ -56,8 +58,7 @@ module.exports = (HB)->
word.push n.textContent
@elements.push word
else if n.nodeType is n.ELEMENT_NODE
last = @elements.end
element = new XmlType undefined, undefined, undefined, undefined, n, last.prev_cl, last
element = new XmlType undefined, undefined, undefined, undefined, n
HB.addOperation(element).execute()
@elements.push element
else
@ -88,8 +89,9 @@ module.exports = (HB)->
prev = next.prev_cl
else
prev = @_yatta.elements.end.prev_cl
element = new XmlType undefined, undefined, undefined, undefined, insertedNode, prev
element = new XmlType undefined, undefined, undefined, undefined
HB.addOperation(element).execute()
@elements.insertAfter prev, element
val: (enforce = false)->
if document?
@ -104,11 +106,12 @@ module.exports = (HB)->
e = @elements.beginning.next_cl
while e.type isnt "Delimiter"
if not e.isDeleted()
if e.type is "XmlType"
@xml.appendChild e.val(enforce)
else if e.type is "WordType"
text_node = document.createTextNode e.val()
n = e.content
if not n.isDeleted()
if n.type is "XmlType"
@xml.appendChild n.val(enforce)
else if n.type is "WordType"
text_node = document.createTextNode n.val()
@xml.appendChild text_node
else
throw new Error "Internal structure cannot be transformed to dom"
@ -153,11 +156,8 @@ module.exports = (HB)->
'elements' : @elements.getUid()
'tagname' : @tagname
'uid' : @getUid()
'prev': @prev_cl?.getUid()
'next': @next_cl?.getUid()
}
if @origin isnt @prev_cl
json["origin"] = @origin?.getUid()
json
parser['XmlType'] = (json)->
@ -166,12 +166,9 @@ module.exports = (HB)->
'attributes' : attributes
'elements' : elements
'tagname' : tagname
'prev': prev
'next': next
'origin' : origin
} = json
new XmlType uid, tagname, attributes, elements, undefined, prev, next, origin
new XmlType uid, tagname, attributes, elements, undefined
types['XmlType'] = XmlType