Compare commits

..

1 Commits

Author SHA1 Message Date
Kevin Jahns
7aa4cd2c42 v13.0.0-4 -- distribution files 2017-07-06 15:17:48 +02:00
12 changed files with 30 additions and 17645 deletions

View File

@@ -6,7 +6,7 @@
<script src="../../../y-array/y-array.js"></script>
<script src="../../../y-text/dist/y-text.js"></script>
<script src="../../../y-memory/y-memory.js"></script>
<script src="../../../y-websockets-client/y-websockets-client.js"></script>
<script src="../../../y-websockets-client/dist/y-websockets-client.js"></script>
<script src="./index.js"></script>
</body>
</html>

View File

@@ -7,7 +7,7 @@ Y({
},
connector: {
name: 'websockets-client',
room: 'Textarea-example-dev'
room: 'Textarea-example'
// url: '127.0.0.1:1234'
},
sourceDir: '/bower_components',

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.0.0-6",
"version": "13.0.0-4",
"lockfileVersion": 1,
"dependencies": {
"acorn": {

View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "13.0.0-6",
"version": "13.0.0-4",
"description": "A framework for real-time p2p shared editing on any data",
"main": "./y.node.js",
"browser": "./y.js",

View File

@@ -1,3 +1,5 @@
/* @flow */
'use strict'
function canRead (auth) { return auth === 'read' || auth === 'write' }
function canWrite (auth) { return auth === 'write' }
@@ -141,9 +143,7 @@ export default function extendConnector (Y/* :any */) {
this.log('User joined: %s', user)
this.connections[user] = {
isSynced: false,
role: role,
waitingMessages: [],
auth: null
role: role
}
let defer = {}
defer.promise = new Promise(function (resolve) { defer.resolve = resolve })
@@ -269,17 +269,11 @@ export default function extendConnector (Y/* :any */) {
})
return Promise.reject(new Error('Incompatible protocol version'))
}
if (message.type === 'sync step 1' && this.connections[sender] != null && this.connections[sender].auth == null) {
if (message.auth != null && this.connections[sender] != null) {
// authenticate using auth in message
var auth = this.checkAuth(message.auth, this.y)
this.connections[sender].auth = auth
auth.then(auth => {
// in case operations were received before sender was received
// we apply the messages after authentication
this.connections[sender].waitingMessages.forEach(msg => {
this.receiveMessage(sender, msg)
})
this.connections[sender].waitingMessages = null
for (var f of this.userEventListeners) {
f({
action: 'userAuthenticated',
@@ -288,6 +282,9 @@ export default function extendConnector (Y/* :any */) {
})
}
})
} else if (this.connections[sender] != null && this.connections[sender].auth == null) {
// authenticate without otherwise
this.connections[sender].auth = this.checkAuth(null, this.y)
}
if (this.connections[sender] != null && this.connections[sender].auth != null) {
return this.connections[sender].auth.then((auth) => {
@@ -387,13 +384,8 @@ export default function extendConnector (Y/* :any */) {
this.y.db.apply(message.ops)
}
})
} else if (this.connections[sender] != null) {
// wait for authentication
let senderConn = this.connection[sender]
senderConn.waitingMessages = senderConn.waitingMessages || []
senderConn.waitingMessages.push(message)
} else {
return Promise.reject(new Error('Unknown user - Unable to deliver message'))
return Promise.reject(new Error('Unable to deliver message'))
}
}
_setSyncedWith (user) {

View File

@@ -96,7 +96,7 @@ export default function extendTransaction (Y) {
send.push(Y.Struct[op.struct].encode(op))
}
}
if (send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
if (this.store.y.connector.isSynced && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
// is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcastOps(send)
}
@@ -712,7 +712,7 @@ export default function extendTransaction (Y) {
}
* addOperation (op) {
yield * this.os.put(op)
if (this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') {
if (this.store.y.connector.isSynced && this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') {
// is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcastOps([op])
}

8
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
/**
* yjs - A framework for real-time p2p shared editing on any data
* @version v13.0.0-6
* @version v13.0.0-4
* @license MIT
*/
@@ -560,6 +560,7 @@ function localstorage() {
}
});
/* @flow */
function canRead (auth) { return auth === 'read' || auth === 'write' }
function canWrite (auth) { return auth === 'write' }
@@ -702,9 +703,7 @@ function extendConnector (Y/* :any */) {
this.log('User joined: %s', user);
this.connections[user] = {
isSynced: false,
role: role,
waitingMessages: [],
auth: null
role: role
};
let defer = {};
defer.promise = new Promise(function (resolve) { defer.resolve = resolve; });
@@ -830,17 +829,11 @@ function extendConnector (Y/* :any */) {
});
return Promise.reject(new Error('Incompatible protocol version'))
}
if (message.type === 'sync step 1' && this.connections[sender] != null && this.connections[sender].auth == null) {
if (message.auth != null && this.connections[sender] != null) {
// authenticate using auth in message
var auth = this.checkAuth(message.auth, this.y);
this.connections[sender].auth = auth;
auth.then(auth => {
// in case operations were received before sender was received
// we apply the messages after authentication
this.connections[sender].waitingMessages.forEach(msg => {
this.receiveMessage(sender, msg);
});
this.connections[sender].waitingMessages = null;
for (var f of this.userEventListeners) {
f({
action: 'userAuthenticated',
@@ -849,6 +842,9 @@ function extendConnector (Y/* :any */) {
});
}
});
} else if (this.connections[sender] != null && this.connections[sender].auth == null) {
// authenticate without otherwise
this.connections[sender].auth = this.checkAuth(null, this.y);
}
if (this.connections[sender] != null && this.connections[sender].auth != null) {
return this.connections[sender].auth.then((auth) => {
@@ -948,13 +944,8 @@ function extendConnector (Y/* :any */) {
this.y.db.apply(message.ops);
}
})
} else if (this.connections[sender] != null) {
// wait for authentication
let senderConn = this.connection[sender];
senderConn.waitingMessages = senderConn.waitingMessages || [];
senderConn.waitingMessages.push(message);
} else {
return Promise.reject(new Error('Unknown user - Unable to deliver message'))
return Promise.reject(new Error('Unable to deliver message'))
}
}
_setSyncedWith (user) {
@@ -1761,7 +1752,7 @@ function extendTransaction (Y) {
send.push(Y.Struct[op.struct].encode(op));
}
}
if (send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
if (this.store.y.connector.isSynced && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
// is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcastOps(send);
}
@@ -2377,7 +2368,7 @@ function extendTransaction (Y) {
}
* addOperation (op) {
yield * this.os.put(op);
if (this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') {
if (this.store.y.connector.isSynced && this.store.forwardAppliedOperations && typeof op.id[1] !== 'string') {
// is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcastOps([op]);
}

File diff suppressed because one or more lines are too long

17597
y.test.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long