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.getHB = getHB;
|
||||
connector.applyHB = applyHB;
|
||||
connector.receive_handlers = [];
|
||||
return connector.receive_handlers.push(function(sender, op) {
|
||||
if (op.uid.creator !== HB.getUserId()) {
|
||||
return engine.applyOp(op);
|
||||
|
@ -19,12 +19,20 @@ module.exports = {
|
||||
req("syncMode", ["syncAll", "master-slave"]);
|
||||
req("role", ["master", "slave"]);
|
||||
req("user_id");
|
||||
this.on_user_id_set(this.user_id);
|
||||
if (typeof this.on_user_id_set === "function") {
|
||||
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") {
|
||||
this.syncMode = "syncAll";
|
||||
}
|
||||
this.is_synced = false;
|
||||
this.connections = {};
|
||||
this.receive_handlers = [];
|
||||
this.is_bound_to_y = false;
|
||||
this.connections = {};
|
||||
this.current_sync_target = null;
|
||||
@ -59,12 +67,14 @@ module.exports = {
|
||||
return this.findNewSyncTarget();
|
||||
},
|
||||
userJoined: function(user, role) {
|
||||
var _base;
|
||||
if (role == null) {
|
||||
throw new Error("Internal: You must specify the role of the joined user! E.g. userJoined('uid:3939','slave')");
|
||||
}
|
||||
this.connections[user] = {
|
||||
is_synced: false
|
||||
};
|
||||
if ((_base = this.connections)[user] == null) {
|
||||
_base[user] = {};
|
||||
}
|
||||
this.connections[user].is_synced = false;
|
||||
if ((!this.is_synced) || this.syncMode === "syncAll") {
|
||||
if (this.syncMode === "syncAll") {
|
||||
return this.performSync(user);
|
||||
@ -164,12 +174,14 @@ module.exports = {
|
||||
var f, _i, _len, _ref;
|
||||
if (!this.is_synced) {
|
||||
this.is_synced = true;
|
||||
_ref = this.compute_when_synced;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
f = _ref[_i];
|
||||
f();
|
||||
if (this.compute_when_synced != null) {
|
||||
_ref = this.compute_when_synced;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
f = _ref[_i];
|
||||
f();
|
||||
}
|
||||
delete this.compute_when_synced;
|
||||
}
|
||||
delete this.compute_when_synced;
|
||||
return null;
|
||||
}
|
||||
},
|
||||
@ -219,7 +231,7 @@ module.exports = {
|
||||
sync_step: "applyHB",
|
||||
data: _hb
|
||||
});
|
||||
if (res.send_again != null) {
|
||||
if ((res.send_again != null) && this.perform_send_again) {
|
||||
send_again = (function(_this) {
|
||||
return function(sv) {
|
||||
return function() {
|
||||
|
@ -186,7 +186,7 @@ module.exports = function(HB) {
|
||||
|
||||
ReplaceManager.prototype.callEventDecorator = function(events) {
|
||||
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++) {
|
||||
event = events[_i];
|
||||
_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>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Yatta!</title>
|
||||
<title>Test Yjs!</title>
|
||||
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
@ -13,9 +13,9 @@
|
||||
mocha.ui('bdd');
|
||||
mocha.reporter('html');
|
||||
</script>
|
||||
<script src="TextYatta_test.js"></script>
|
||||
<script src="JsonYatta_test.js"></script>
|
||||
<!--script src="XmlYatta_test_browser.js"></script-->
|
||||
<script src="Text_test.js"></script>
|
||||
<script src="Json_test.js"></script>
|
||||
<!--script src="Xml_test_browser.js"></script-->
|
||||
<script>
|
||||
//mocha.checkLeaks();
|
||||
//mocha.run();
|
||||
|
@ -1,5 +1,5 @@
|
||||
# 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.applyHB = applyHB
|
||||
|
||||
connector.receive_handlers = []
|
||||
connector.receive_handlers.push (sender, op)->
|
||||
if op.uid.creator isnt HB.getUserId()
|
||||
engine.applyOp op
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
module.exports =
|
||||
#
|
||||
# @params new Connector(syncMode, role)
|
||||
# @param syncMode {String} is either "syncAll" or "master-slave".
|
||||
# @param role {String} The role of this client
|
||||
# @params new Connector(options)
|
||||
# @param options.syncMode {String} is either "syncAll" or "master-slave".
|
||||
# @param options.role {String} The role of this client
|
||||
# (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)->
|
||||
req = (name, choices)=>
|
||||
@ -19,7 +20,14 @@ module.exports =
|
||||
req "syncMode", ["syncAll", "master-slave"]
|
||||
req "role", ["master", "slave"]
|
||||
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!
|
||||
if @role is "master"
|
||||
@ -30,7 +38,7 @@ module.exports =
|
||||
# Peerjs Connections: key: conn-id, value: object
|
||||
@connections = {}
|
||||
# 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
|
||||
@is_bound_to_y = false
|
||||
@ -63,8 +71,8 @@ module.exports =
|
||||
if not role?
|
||||
throw new Error "Internal: You must specify the role of the joined user! E.g. userJoined('uid:3939','slave')"
|
||||
# a user joined the room
|
||||
@connections[user] =
|
||||
is_synced : false
|
||||
@connections[user] ?= {}
|
||||
@connections[user].is_synced = false
|
||||
|
||||
if (not @is_synced) or @syncMode is "syncAll"
|
||||
if @syncMode is "syncAll"
|
||||
@ -165,9 +173,10 @@ module.exports =
|
||||
setStateSynced: ()->
|
||||
if not @is_synced
|
||||
@is_synced = true
|
||||
for f in @compute_when_synced
|
||||
f()
|
||||
delete @compute_when_synced
|
||||
if @compute_when_synced?
|
||||
for f in @compute_when_synced
|
||||
f()
|
||||
delete @compute_when_synced
|
||||
null
|
||||
|
||||
#
|
||||
@ -208,7 +217,7 @@ module.exports =
|
||||
sync_step : "applyHB"
|
||||
data: _hb
|
||||
|
||||
if res.send_again?
|
||||
if res.send_again? and @perform_send_again
|
||||
send_again = do (sv = data.state_vector)=>
|
||||
()=>
|
||||
hb = @getHB(sv).hb
|
||||
|
@ -183,7 +183,7 @@ module.exports = (HB)->
|
||||
#
|
||||
#
|
||||
callEventDecorator: (events)->
|
||||
if not (@isDeleted() or @getLastOperation().isDeleted())
|
||||
if not @isDeleted()
|
||||
for event in events
|
||||
for name,prop of @event_properties
|
||||
event[name] = prop
|
||||
|
@ -7,7 +7,7 @@ _ = require("underscore")
|
||||
|
||||
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"
|
||||
|
||||
Test = require "./TestSuite"
|
||||
|
@ -7,7 +7,7 @@ _ = require("underscore")
|
||||
|
||||
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
|
||||
constructor: (@name_suffix = "")->
|
||||
|
@ -8,7 +8,7 @@ _ = require("underscore")
|
||||
chai.use(sinonChai)
|
||||
|
||||
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"
|
||||
class TextTest extends Test
|
||||
|
@ -11,7 +11,7 @@ require 'coffee-errors'
|
||||
chai.use(sinonChai)
|
||||
|
||||
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"
|
||||
class XmlTest extends Test
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user