Compare commits

..

3 Commits

Author SHA1 Message Date
Kevin Jahns
eed9d78b5a v13.0.0-6 -- distribution files 2017-07-21 23:56:52 +02:00
Kevin Jahns
2c18b9ffad 13.0.0-6 2017-07-21 23:56:13 +02:00
Kevin Jahns
a6b7d76544 bugfix: unable to deliver message. fixes receiving message before authentication 2017-07-21 23:55:11 +02:00
7 changed files with 41 additions and 21 deletions

2
package-lock.json generated
View File

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

View File

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

View File

@@ -141,7 +141,9 @@ export default function extendConnector (Y/* :any */) {
this.log('User joined: %s', user)
this.connections[user] = {
isSynced: false,
role: role
role: role,
waitingMessages: [],
auth: null
}
let defer = {}
defer.promise = new Promise(function (resolve) { defer.resolve = resolve })
@@ -267,11 +269,17 @@ export default function extendConnector (Y/* :any */) {
})
return Promise.reject(new Error('Incompatible protocol version'))
}
if (message.auth != null && this.connections[sender] != null) {
if (message.type === 'sync step 1' && this.connections[sender] != null && this.connections[sender].auth == 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',
@@ -280,9 +288,6 @@ 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) => {
@@ -382,8 +387,13 @@ 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('Unable to deliver message'))
return Promise.reject(new Error('Unknown user - Unable to deliver message'))
}
}
_setSyncedWith (user) {

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-5
* @version v13.0.0-6
* @license MIT
*/
@@ -702,7 +702,9 @@ function extendConnector (Y/* :any */) {
this.log('User joined: %s', user);
this.connections[user] = {
isSynced: false,
role: role
role: role,
waitingMessages: [],
auth: null
};
let defer = {};
defer.promise = new Promise(function (resolve) { defer.resolve = resolve; });
@@ -828,11 +830,17 @@ function extendConnector (Y/* :any */) {
});
return Promise.reject(new Error('Incompatible protocol version'))
}
if (message.auth != null && this.connections[sender] != null) {
if (message.type === 'sync step 1' && this.connections[sender] != null && this.connections[sender].auth == 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',
@@ -841,9 +849,6 @@ 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) => {
@@ -943,8 +948,13 @@ 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('Unable to deliver message'))
return Promise.reject(new Error('Unknown user - Unable to deliver message'))
}
}
_setSyncedWith (user) {

File diff suppressed because one or more lines are too long