Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0600197977 |
14
.gitignore
vendored
14
.gitignore
vendored
@@ -1,3 +1,15 @@
|
|||||||
node_modules
|
node_modules
|
||||||
bower_components
|
bower_components
|
||||||
/y.*
|
build
|
||||||
|
build_test
|
||||||
|
.directory
|
||||||
|
.codio
|
||||||
|
.settings
|
||||||
|
.jshintignore
|
||||||
|
.jshintrc
|
||||||
|
.validate.json
|
||||||
|
/y.js
|
||||||
|
/y.js.map
|
||||||
|
/y-*
|
||||||
|
.vscode
|
||||||
|
jsconfig.json
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<script src="../../../y-array/y-array.js"></script>
|
<script src="../../../y-array/y-array.js"></script>
|
||||||
<script src="../../../y-text/dist/y-text.js"></script>
|
<script src="../../../y-text/dist/y-text.js"></script>
|
||||||
<script src="../../../y-memory/y-memory.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>
|
<script src="./index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Y({
|
|||||||
},
|
},
|
||||||
connector: {
|
connector: {
|
||||||
name: 'websockets-client',
|
name: 'websockets-client',
|
||||||
room: 'Textarea-example-dev'
|
room: 'Textarea-example'
|
||||||
// url: '127.0.0.1:1234'
|
// url: '127.0.0.1:1234'
|
||||||
},
|
},
|
||||||
sourceDir: '/bower_components',
|
sourceDir: '/bower_components',
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.0.0-7",
|
"version": "13.0.0-2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"acorn": {
|
"acorn": {
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "13.0.0-7",
|
"version": "13.0.0-2",
|
||||||
"description": "A framework for real-time p2p shared editing on any data",
|
"description": "A framework for real-time p2p shared editing on any data",
|
||||||
"main": "./y.node.js",
|
"main": "./src/y.js",
|
||||||
"browser": "./y.js",
|
|
||||||
"module": "./src/y.js",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run lint",
|
"test": "npm run lint",
|
||||||
"lint": "standard",
|
"lint": "standard",
|
||||||
"dist": "rollup -c rollup.browser.js; rollup -c rollup.node.js",
|
"dist": "rollup -c rollup.dist.js",
|
||||||
|
"serve": "concurrently 'serve ..' 'rollup -wc rollup.dist.js -o examples/bower_components/yjs/y.js'",
|
||||||
"postversion": "npm run dist",
|
"postversion": "npm run dist",
|
||||||
"postpublish": "tag-dist-files --overwrite-existing-tag"
|
"postpublish": "tag-dist-files --overwrite-existing-tag"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
import nodeResolve from 'rollup-plugin-node-resolve'
|
|
||||||
import commonjs from 'rollup-plugin-commonjs'
|
|
||||||
var pkg = require('./package.json')
|
|
||||||
|
|
||||||
export default {
|
|
||||||
entry: 'src/y.js',
|
|
||||||
moduleName: 'Y',
|
|
||||||
format: 'umd',
|
|
||||||
plugins: [
|
|
||||||
nodeResolve({
|
|
||||||
main: true,
|
|
||||||
module: true,
|
|
||||||
browser: true
|
|
||||||
}),
|
|
||||||
commonjs()
|
|
||||||
],
|
|
||||||
dest: 'y.node.js',
|
|
||||||
sourceMap: true,
|
|
||||||
banner: `
|
|
||||||
/**
|
|
||||||
* ${pkg.name} - ${pkg.description}
|
|
||||||
* @version v${pkg.version}
|
|
||||||
* @license ${pkg.license}
|
|
||||||
*/
|
|
||||||
`
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
/* @flow */
|
||||||
|
'use strict'
|
||||||
|
|
||||||
function canRead (auth) { return auth === 'read' || auth === 'write' }
|
function canRead (auth) { return auth === 'read' || auth === 'write' }
|
||||||
function canWrite (auth) { return 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.log('User joined: %s', user)
|
||||||
this.connections[user] = {
|
this.connections[user] = {
|
||||||
isSynced: false,
|
isSynced: false,
|
||||||
role: role,
|
role: role
|
||||||
waitingMessages: [],
|
|
||||||
auth: null
|
|
||||||
}
|
}
|
||||||
let defer = {}
|
let defer = {}
|
||||||
defer.promise = new Promise(function (resolve) { defer.resolve = resolve })
|
defer.promise = new Promise(function (resolve) { defer.resolve = resolve })
|
||||||
@@ -269,20 +269,11 @@ export default function extendConnector (Y/* :any */) {
|
|||||||
})
|
})
|
||||||
return Promise.reject(new Error('Incompatible protocol version'))
|
return Promise.reject(new Error('Incompatible protocol version'))
|
||||||
}
|
}
|
||||||
if ((message.type === 'sync step 1' || message.type === 'sync step 2') && this.connections[sender] != null && this.connections[sender].auth == null) {
|
if (message.auth != null && this.connections[sender] != null) {
|
||||||
// authenticate using auth in message
|
// authenticate using auth in message
|
||||||
var auth = this.checkAuth(message.auth, this.y)
|
var auth = this.checkAuth(message.auth, this.y)
|
||||||
this.connections[sender].auth = auth
|
this.connections[sender].auth = auth
|
||||||
auth.then(auth => {
|
auth.then(auth => {
|
||||||
// in case operations were received before sender was received
|
|
||||||
// we apply the messages after authentication
|
|
||||||
this.connections[sender].syncStep2.promise.then(() => {
|
|
||||||
// we do it after sync step 1
|
|
||||||
this.connections[sender].waitingMessages.forEach(msg => {
|
|
||||||
this.receiveMessage(sender, msg)
|
|
||||||
})
|
|
||||||
this.connections[sender].waitingMessages = null
|
|
||||||
})
|
|
||||||
for (var f of this.userEventListeners) {
|
for (var f of this.userEventListeners) {
|
||||||
f({
|
f({
|
||||||
action: 'userAuthenticated',
|
action: 'userAuthenticated',
|
||||||
@@ -291,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) {
|
if (this.connections[sender] != null && this.connections[sender].auth != null) {
|
||||||
return this.connections[sender].auth.then((auth) => {
|
return this.connections[sender].auth.then((auth) => {
|
||||||
@@ -390,13 +384,8 @@ export default function extendConnector (Y/* :any */) {
|
|||||||
this.y.db.apply(message.ops)
|
this.y.db.apply(message.ops)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (this.connections[sender] != null) {
|
|
||||||
// wait for authentication
|
|
||||||
let senderConn = this.connections[sender]
|
|
||||||
senderConn.waitingMessages = senderConn.waitingMessages || []
|
|
||||||
senderConn.waitingMessages.push(message)
|
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(new Error('Unknown user - Unable to deliver message'))
|
return Promise.reject(new Error('Unable to deliver message'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_setSyncedWith (user) {
|
_setSyncedWith (user) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export default function extendTransaction (Y) {
|
|||||||
send.push(Y.Struct[op.struct].encode(op))
|
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
|
// is connected, and this is not going to be send in addOperation
|
||||||
this.store.y.connector.broadcastOps(send)
|
this.store.y.connector.broadcastOps(send)
|
||||||
}
|
}
|
||||||
@@ -712,7 +712,7 @@ export default function extendTransaction (Y) {
|
|||||||
}
|
}
|
||||||
* addOperation (op) {
|
* addOperation (op) {
|
||||||
yield * this.os.put(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
|
// is connected, and this is not going to be send in addOperation
|
||||||
this.store.y.connector.broadcastOps([op])
|
this.store.y.connector.broadcastOps([op])
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user