update modules and lint

This commit is contained in:
Kevin Jahns 2020-04-07 14:22:21 +02:00
parent 08d164dc26
commit ea176e2b6a
6 changed files with 860 additions and 520 deletions

View file

@ -1,9 +1,9 @@
# WebRTC Connector for [Yjs](https://github.com/yjs/yjs) # WebRTC connector for [Yjs](https://github.com/yjs/yjs)
It propagates document updates directly to all users via WebRTC. Propagates document updates peer-to-peer to all users using WebRTC.
* Fast message propagation * Fast message propagation
* Encryption and authorization over untrusted signaling server * Encryption and authorization over untrusted signaling servers
* No setup required, public signaling servers are available * No setup required, public signaling servers are available
* Very little server load * Very little server load
* Not suited for a large amount of collaborators on a single document (each peer is connected to each other) * Not suited for a large amount of collaborators on a single document (each peer is connected to each other)
@ -89,7 +89,7 @@ The following default values of `opts` can be overwritten:
} }
``` ```
### Logging ## Logging
`y-webrtc` uses the `lib0/logging.js` logging library. By default this library disables logging. You can enable it by specifying the `log` environment / localStorage variable: `y-webrtc` uses the `lib0/logging.js` logging library. By default this library disables logging. You can enable it by specifying the `log` environment / localStorage variable:

1340
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -44,22 +44,22 @@
] ]
}, },
"dependencies": { "dependencies": {
"lib0": "^0.2.20", "lib0": "^0.2.24",
"simple-peer": "^9.6.2", "simple-peer": "^9.6.2",
"y-protocols": "^0.2.1" "y-protocols": "^0.2.3"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^11.0.1", "@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-node-resolve": "^7.0.0", "@rollup/plugin-node-resolve": "^7.1.1",
"@types/simple-peer": "^9.6.0", "@types/simple-peer": "^9.6.0",
"concurrently": "^5.1.0", "concurrently": "^5.1.0",
"http-server": "^0.12.1", "http-server": "^0.12.1",
"rollup": "^1.30.1", "rollup": "^1.32.1",
"rollup-cli": "^1.0.9", "rollup-cli": "^1.0.9",
"rollup-plugin-terser": "^5.2.0", "rollup-plugin-terser": "^5.3.0",
"standard": "^12.0.1", "standard": "^14.3.3",
"typescript": "^3.8.3", "typescript": "^3.8.3",
"yjs": "^13.0.4" "yjs": "^13.0.5"
}, },
"peerDependenies": { "peerDependenies": {
"yjs": "^13.0.0" "yjs": "^13.0.0"

View file

@ -34,7 +34,7 @@ export const deriveKey = (secret, roomName) => {
length: 256 length: 256
}, },
true, true,
[ 'encrypt', 'decrypt' ] ['encrypt', 'decrypt']
) )
) )
} }

View file

@ -71,7 +71,7 @@ const readMessage = (room, buf, syncedCallback) => {
const doc = room.doc const doc = room.doc
let sendReply = false let sendReply = false
switch (messageType) { switch (messageType) {
case messageSync: case messageSync: {
encoding.writeVarUint(encoder, messageSync) encoding.writeVarUint(encoder, messageSync)
const syncMessageType = syncProtocol.readSyncMessage(decoder, encoder, doc, room) const syncMessageType = syncProtocol.readSyncMessage(decoder, encoder, doc, room)
if (syncMessageType === syncProtocol.messageYjsSyncStep2 && !room.synced) { if (syncMessageType === syncProtocol.messageYjsSyncStep2 && !room.synced) {
@ -81,6 +81,7 @@ const readMessage = (room, buf, syncedCallback) => {
sendReply = true sendReply = true
} }
break break
}
case messageQueryAwareness: case messageQueryAwareness:
encoding.writeVarUint(encoder, messageAwareness) encoding.writeVarUint(encoder, messageAwareness)
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(awareness, Array.from(awareness.getStates().keys()))) encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(awareness, Array.from(awareness.getStates().keys())))
@ -229,6 +230,7 @@ export class WebrtcConn {
} }
}) })
} }
destroy () { destroy () {
this.peer.destroy() this.peer.destroy()
} }
@ -366,6 +368,7 @@ export class Room {
}) })
}) })
} }
connect () { connect () {
// signal through all available signaling connections // signal through all available signaling connections
announceSignalingInfo(this) announceSignalingInfo(this)
@ -394,6 +397,7 @@ export class Room {
encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this.doc.clientID])) encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this.doc.clientID]))
broadcastBcMessage(this, encoding.toUint8Array(encoderAwarenessState)) broadcastBcMessage(this, encoding.toUint8Array(encoderAwarenessState))
} }
disconnect () { disconnect () {
// signal through all available signaling connections // signal through all available signaling connections
signalingConns.forEach(conn => { signalingConns.forEach(conn => {
@ -415,6 +419,7 @@ export class Room {
this.awareness.off('change', this._awarenessUpdateHandler) this.awareness.off('change', this._awarenessUpdateHandler)
this.webrtcConns.forEach(conn => conn.destroy()) this.webrtcConns.forEach(conn => conn.destroy())
} }
destroy () { destroy () {
this.disconnect() this.disconnect()
} }
@ -576,12 +581,14 @@ export class WebrtcProvider extends Observable {
}) })
this.connect() this.connect()
} }
/** /**
* @type {boolean} * @type {boolean}
*/ */
get connected () { get connected () {
return this.room !== null && this.shouldConnect return this.room !== null && this.shouldConnect
} }
connect () { connect () {
this.shouldConnect = true this.shouldConnect = true
this.signalingUrls.forEach(url => { this.signalingUrls.forEach(url => {
@ -593,6 +600,7 @@ export class WebrtcProvider extends Observable {
this.room.connect() this.room.connect()
} }
} }
disconnect () { disconnect () {
this.shouldConnect = false this.shouldConnect = false
this.signalingConns.forEach(conn => { this.signalingConns.forEach(conn => {
@ -606,6 +614,7 @@ export class WebrtcProvider extends Observable {
this.room.disconnect() this.room.disconnect()
} }
} }
destroy () { destroy () {
// need to wait for key before deleting room // need to wait for key before deleting room
this.key.then(() => { this.key.then(() => {

View file

@ -13,8 +13,7 @@
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */ "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"paths": { "paths": {
}, }
"maxNodeModuleJsDepth": 0
}, },
"include": ["./src/y-webrtc.js"], "include": ["./src/y-webrtc.js"],
"exclude": ["./node_modules/simple-peer/*"] "exclude": ["./node_modules/simple-peer/*"]