added new y-test connector
This commit is contained in:
parent
3eb933400a
commit
e5f16812b3
11
build/README.md
Normal file
11
build/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
# Directories
|
||||||
|
|
||||||
|
### build/browser
|
||||||
|
You find the browserified (not minified) version of yjs here. This is nice for debugging, since it also includes sourcemaps. For production, however, you should use the version that you find in the main directory.
|
||||||
|
|
||||||
|
### build/node
|
||||||
|
Yjs for nodejs is located here. You can only use the submodules, or require 'y' in your node project. Also works with browserify.
|
||||||
|
|
||||||
|
### build/test
|
||||||
|
Start build/test/index.html' in your browser, to perform testing Yjs.
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -58,7 +58,6 @@ adaptConnector = function(connector, engine, HB, execution_listener) {
|
|||||||
connector.getStateVector = getStateVector;
|
connector.getStateVector = getStateVector;
|
||||||
connector.getHB = getHB;
|
connector.getHB = getHB;
|
||||||
connector.applyHB = applyHB;
|
connector.applyHB = applyHB;
|
||||||
connector.receive_handlers = [];
|
|
||||||
return connector.receive_handlers.push(function(sender, op) {
|
return connector.receive_handlers.push(function(sender, op) {
|
||||||
if (op.uid.creator !== HB.getUserId()) {
|
if (op.uid.creator !== HB.getUserId()) {
|
||||||
return engine.applyOp(op);
|
return engine.applyOp(op);
|
||||||
|
@ -19,12 +19,20 @@ module.exports = {
|
|||||||
req("syncMode", ["syncAll", "master-slave"]);
|
req("syncMode", ["syncAll", "master-slave"]);
|
||||||
req("role", ["master", "slave"]);
|
req("role", ["master", "slave"]);
|
||||||
req("user_id");
|
req("user_id");
|
||||||
|
if (typeof this.on_user_id_set === "function") {
|
||||||
this.on_user_id_set(this.user_id);
|
this.on_user_id_set(this.user_id);
|
||||||
|
}
|
||||||
|
if (options.perform_send_again != null) {
|
||||||
|
this.perform_send_again = options.perform_send_again;
|
||||||
|
} else {
|
||||||
|
this.perform_send_again = true;
|
||||||
|
}
|
||||||
if (this.role === "master") {
|
if (this.role === "master") {
|
||||||
this.syncMode = "syncAll";
|
this.syncMode = "syncAll";
|
||||||
}
|
}
|
||||||
this.is_synced = false;
|
this.is_synced = false;
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
|
this.receive_handlers = [];
|
||||||
this.is_bound_to_y = false;
|
this.is_bound_to_y = false;
|
||||||
this.connections = {};
|
this.connections = {};
|
||||||
this.current_sync_target = null;
|
this.current_sync_target = null;
|
||||||
@ -59,12 +67,14 @@ module.exports = {
|
|||||||
return this.findNewSyncTarget();
|
return this.findNewSyncTarget();
|
||||||
},
|
},
|
||||||
userJoined: function(user, role) {
|
userJoined: function(user, role) {
|
||||||
|
var _base;
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
throw new Error("Internal: You must specify the role of the joined user! E.g. userJoined('uid:3939','slave')");
|
throw new Error("Internal: You must specify the role of the joined user! E.g. userJoined('uid:3939','slave')");
|
||||||
}
|
}
|
||||||
this.connections[user] = {
|
if ((_base = this.connections)[user] == null) {
|
||||||
is_synced: false
|
_base[user] = {};
|
||||||
};
|
}
|
||||||
|
this.connections[user].is_synced = false;
|
||||||
if ((!this.is_synced) || this.syncMode === "syncAll") {
|
if ((!this.is_synced) || this.syncMode === "syncAll") {
|
||||||
if (this.syncMode === "syncAll") {
|
if (this.syncMode === "syncAll") {
|
||||||
return this.performSync(user);
|
return this.performSync(user);
|
||||||
@ -164,12 +174,14 @@ module.exports = {
|
|||||||
var f, _i, _len, _ref;
|
var f, _i, _len, _ref;
|
||||||
if (!this.is_synced) {
|
if (!this.is_synced) {
|
||||||
this.is_synced = true;
|
this.is_synced = true;
|
||||||
|
if (this.compute_when_synced != null) {
|
||||||
_ref = this.compute_when_synced;
|
_ref = this.compute_when_synced;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
f = _ref[_i];
|
f = _ref[_i];
|
||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
delete this.compute_when_synced;
|
delete this.compute_when_synced;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -219,7 +231,7 @@ module.exports = {
|
|||||||
sync_step: "applyHB",
|
sync_step: "applyHB",
|
||||||
data: _hb
|
data: _hb
|
||||||
});
|
});
|
||||||
if (res.send_again != null) {
|
if ((res.send_again != null) && this.perform_send_again) {
|
||||||
send_again = (function(_this) {
|
send_again = (function(_this) {
|
||||||
return function(sv) {
|
return function(sv) {
|
||||||
return function() {
|
return function() {
|
||||||
|
@ -186,7 +186,7 @@ module.exports = function(HB) {
|
|||||||
|
|
||||||
ReplaceManager.prototype.callEventDecorator = function(events) {
|
ReplaceManager.prototype.callEventDecorator = function(events) {
|
||||||
var event, name, prop, _i, _len, _ref;
|
var event, name, prop, _i, _len, _ref;
|
||||||
if (!(this.isDeleted() || this.getLastOperation().isDeleted())) {
|
if (!this.isDeleted()) {
|
||||||
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
||||||
event = events[_i];
|
event = events[_i];
|
||||||
_ref = this.event_properties;
|
_ref = this.event_properties;
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,7 +1,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>Test Yatta!</title>
|
<title>Test Yjs!</title>
|
||||||
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
|
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@ -13,9 +13,9 @@
|
|||||||
mocha.ui('bdd');
|
mocha.ui('bdd');
|
||||||
mocha.reporter('html');
|
mocha.reporter('html');
|
||||||
</script>
|
</script>
|
||||||
<script src="TextYatta_test.js"></script>
|
<script src="Text_test.js"></script>
|
||||||
<script src="JsonYatta_test.js"></script>
|
<script src="Json_test.js"></script>
|
||||||
<!--script src="XmlYatta_test_browser.js"></script-->
|
<!--script src="Xml_test_browser.js"></script-->
|
||||||
<script>
|
<script>
|
||||||
//mocha.checkLeaks();
|
//mocha.checkLeaks();
|
||||||
//mocha.run();
|
//mocha.run();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
Here you find some (hopefully) usefull examples on how to use Yatta!
|
Here you find some (hopefully) usefull examples on how to use Yjs!
|
||||||
|
|
||||||
Please note, that the XMPP Connector is the best supported Connector at the moment.
|
Feel free to use the code of the examples in your own project. They include basic examples how to use Yjs.
|
@ -53,7 +53,6 @@ adaptConnector = (connector, engine, HB, execution_listener)->
|
|||||||
connector.getHB = getHB
|
connector.getHB = getHB
|
||||||
connector.applyHB = applyHB
|
connector.applyHB = applyHB
|
||||||
|
|
||||||
connector.receive_handlers = []
|
|
||||||
connector.receive_handlers.push (sender, op)->
|
connector.receive_handlers.push (sender, op)->
|
||||||
if op.uid.creator isnt HB.getUserId()
|
if op.uid.creator isnt HB.getUserId()
|
||||||
engine.applyOp op
|
engine.applyOp op
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
#
|
#
|
||||||
# @params new Connector(syncMode, role)
|
# @params new Connector(options)
|
||||||
# @param syncMode {String} is either "syncAll" or "master-slave".
|
# @param options.syncMode {String} is either "syncAll" or "master-slave".
|
||||||
# @param role {String} The role of this client
|
# @param options.role {String} The role of this client
|
||||||
# (slave or master (only used when syncMode is master-slave))
|
# (slave or master (only used when syncMode is master-slave))
|
||||||
|
# @param options.perform_send_again {Boolean} Whetehr to whether to resend the HB after some time period. This reduces sync errors, but has some overhead (optional)
|
||||||
#
|
#
|
||||||
init: (options)->
|
init: (options)->
|
||||||
req = (name, choices)=>
|
req = (name, choices)=>
|
||||||
@ -19,7 +20,14 @@ module.exports =
|
|||||||
req "syncMode", ["syncAll", "master-slave"]
|
req "syncMode", ["syncAll", "master-slave"]
|
||||||
req "role", ["master", "slave"]
|
req "role", ["master", "slave"]
|
||||||
req "user_id"
|
req "user_id"
|
||||||
@on_user_id_set(@user_id)
|
@on_user_id_set?(@user_id)
|
||||||
|
|
||||||
|
# whether to resend the HB after some time period. This reduces sync errors.
|
||||||
|
# But this is not necessary in the test-connector
|
||||||
|
if options.perform_send_again?
|
||||||
|
@perform_send_again = options.perform_send_again
|
||||||
|
else
|
||||||
|
@perform_send_again = true
|
||||||
|
|
||||||
# A Master should sync with everyone! TODO: really? - for now its safer this way!
|
# A Master should sync with everyone! TODO: really? - for now its safer this way!
|
||||||
if @role is "master"
|
if @role is "master"
|
||||||
@ -30,7 +38,7 @@ module.exports =
|
|||||||
# Peerjs Connections: key: conn-id, value: object
|
# Peerjs Connections: key: conn-id, value: object
|
||||||
@connections = {}
|
@connections = {}
|
||||||
# List of functions that shall process incoming data
|
# List of functions that shall process incoming data
|
||||||
# @receive_handlers = [] # this is already set in the ConnectorAdapter!
|
@receive_handlers = []
|
||||||
|
|
||||||
# whether this instance is bound to any y instance
|
# whether this instance is bound to any y instance
|
||||||
@is_bound_to_y = false
|
@is_bound_to_y = false
|
||||||
@ -63,8 +71,8 @@ module.exports =
|
|||||||
if not role?
|
if not role?
|
||||||
throw new Error "Internal: You must specify the role of the joined user! E.g. userJoined('uid:3939','slave')"
|
throw new Error "Internal: You must specify the role of the joined user! E.g. userJoined('uid:3939','slave')"
|
||||||
# a user joined the room
|
# a user joined the room
|
||||||
@connections[user] =
|
@connections[user] ?= {}
|
||||||
is_synced : false
|
@connections[user].is_synced = false
|
||||||
|
|
||||||
if (not @is_synced) or @syncMode is "syncAll"
|
if (not @is_synced) or @syncMode is "syncAll"
|
||||||
if @syncMode is "syncAll"
|
if @syncMode is "syncAll"
|
||||||
@ -165,6 +173,7 @@ module.exports =
|
|||||||
setStateSynced: ()->
|
setStateSynced: ()->
|
||||||
if not @is_synced
|
if not @is_synced
|
||||||
@is_synced = true
|
@is_synced = true
|
||||||
|
if @compute_when_synced?
|
||||||
for f in @compute_when_synced
|
for f in @compute_when_synced
|
||||||
f()
|
f()
|
||||||
delete @compute_when_synced
|
delete @compute_when_synced
|
||||||
@ -208,7 +217,7 @@ module.exports =
|
|||||||
sync_step : "applyHB"
|
sync_step : "applyHB"
|
||||||
data: _hb
|
data: _hb
|
||||||
|
|
||||||
if res.send_again?
|
if res.send_again? and @perform_send_again
|
||||||
send_again = do (sv = data.state_vector)=>
|
send_again = do (sv = data.state_vector)=>
|
||||||
()=>
|
()=>
|
||||||
hb = @getHB(sv).hb
|
hb = @getHB(sv).hb
|
||||||
|
@ -183,7 +183,7 @@ module.exports = (HB)->
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
callEventDecorator: (events)->
|
callEventDecorator: (events)->
|
||||||
if not (@isDeleted() or @getLastOperation().isDeleted())
|
if not @isDeleted()
|
||||||
for event in events
|
for event in events
|
||||||
for name,prop of @event_properties
|
for name,prop of @event_properties
|
||||||
event[name] = prop
|
event[name] = prop
|
||||||
|
@ -7,7 +7,7 @@ _ = require("underscore")
|
|||||||
|
|
||||||
chai.use(sinonChai)
|
chai.use(sinonChai)
|
||||||
|
|
||||||
Connector = require "../../y-connectors/lib/y-test/y-test.coffee"
|
Connector = require "../../y-test/lib/y-test.coffee"
|
||||||
Y = require "../lib/y.coffee"
|
Y = require "../lib/y.coffee"
|
||||||
|
|
||||||
Test = require "./TestSuite"
|
Test = require "./TestSuite"
|
||||||
|
@ -7,7 +7,7 @@ _ = require("underscore")
|
|||||||
|
|
||||||
chai.use(sinonChai)
|
chai.use(sinonChai)
|
||||||
|
|
||||||
Connector = require "../../y-connectors/lib/y-test/y-test.coffee"
|
Connector = require "../../y-test/lib/y-test.coffee"
|
||||||
|
|
||||||
module.exports = class Test
|
module.exports = class Test
|
||||||
constructor: (@name_suffix = "")->
|
constructor: (@name_suffix = "")->
|
||||||
|
@ -8,7 +8,7 @@ _ = require("underscore")
|
|||||||
chai.use(sinonChai)
|
chai.use(sinonChai)
|
||||||
|
|
||||||
Y = require "../lib/y"
|
Y = require "../lib/y"
|
||||||
Connector = require "../../y-connectors/lib/y-test/y-test.coffee"
|
Connector = require "../../y-test/lib/y-test.coffee"
|
||||||
|
|
||||||
Test = require "./TestSuite"
|
Test = require "./TestSuite"
|
||||||
class TextTest extends Test
|
class TextTest extends Test
|
||||||
|
@ -11,7 +11,7 @@ require 'coffee-errors'
|
|||||||
chai.use(sinonChai)
|
chai.use(sinonChai)
|
||||||
|
|
||||||
Y = require "../lib/index"
|
Y = require "../lib/index"
|
||||||
Connector = require "../../Yatta-Connectors/lib/test-connector/test-connector.coffee"
|
Connector = require "../../y-test/lib/y-test.coffee"
|
||||||
|
|
||||||
Test = require "./TestSuite"
|
Test = require "./TestSuite"
|
||||||
class XmlTest extends Test
|
class XmlTest extends Test
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user