add option to not filter bc connections and always connect using webrtc

This commit is contained in:
Kevin Jahns 2020-03-20 20:17:00 +01:00
parent 9f73533b5b
commit f18bb75147
3 changed files with 18 additions and 10 deletions

View file

@ -1,4 +1,4 @@
# WebRTC Connector for [Yjs](https://github.com/y-js/yjs) # WebRTC Connector for [Yjs](https://github.com/yjs/yjs)
It propagates document updates directly to all users via WebRTC. It propagates document updates directly to all users via WebRTC.

View file

@ -42,7 +42,7 @@
] ]
}, },
"dependencies": { "dependencies": {
"lib0": "^0.2.12", "lib0": "^0.2.20",
"simple-peer": "^9.6.2", "simple-peer": "^9.6.2",
"y-protocols": "^0.2.0" "y-protocols": "^0.2.0"
}, },
@ -56,7 +56,7 @@
"rollup-plugin-terser": "^5.2.0", "rollup-plugin-terser": "^5.2.0",
"standard": "^12.0.1", "standard": "^12.0.1",
"typescript": "^3.7.5", "typescript": "^3.7.5",
"yjs": "^13.0.0" "yjs": "^13.0.4"
}, },
"peerDependenies": { "peerDependenies": {
"yjs": "^13.0.0" "yjs": "^13.0.0"

View file

@ -270,7 +270,11 @@ const announceSignalingInfo = room => {
}) })
} }
/**
* @param {Room} room
*/
const broadcastBcPeerId = room => { const broadcastBcPeerId = room => {
if (room.provider.filterBcConns) {
// broadcast peerId via broadcastchannel // broadcast peerId via broadcastchannel
const encoderPeerIdBc = encoding.createEncoder() const encoderPeerIdBc = encoding.createEncoder()
encoding.writeVarUint(encoderPeerIdBc, messageBcPeerId) encoding.writeVarUint(encoderPeerIdBc, messageBcPeerId)
@ -278,6 +282,7 @@ const broadcastBcPeerId = room => {
encoding.writeVarString(encoderPeerIdBc, room.peerId) encoding.writeVarString(encoderPeerIdBc, room.peerId)
broadcastBcMessage(room, encoding.toUint8Array(encoderPeerIdBc)) broadcastBcMessage(room, encoding.toUint8Array(encoderPeerIdBc))
} }
}
export class Room { export class Room {
/** /**
@ -525,6 +530,7 @@ export class WebrtcProvider extends Observable {
* @param {string?} [opts.password] * @param {string?} [opts.password]
* @param {awarenessProtocol.Awareness} [opts.awareness] * @param {awarenessProtocol.Awareness} [opts.awareness]
* @param {number} [opts.maxConns] * @param {number} [opts.maxConns]
* @param {boolean} [opts.filterBcConns]
*/ */
constructor ( constructor (
roomName, roomName,
@ -533,12 +539,14 @@ export class WebrtcProvider extends Observable {
signaling = ['wss://signaling.yjs.dev', 'wss://y-webrtc-uchplqjsol.now.sh', 'wss://y-webrtc-signaling-eu.herokuapp.com', 'wss://y-webrtc-signaling-us.herokuapp.com'], signaling = ['wss://signaling.yjs.dev', 'wss://y-webrtc-uchplqjsol.now.sh', 'wss://y-webrtc-signaling-eu.herokuapp.com', 'wss://y-webrtc-signaling-us.herokuapp.com'],
password = null, password = null,
awareness = new awarenessProtocol.Awareness(doc), awareness = new awarenessProtocol.Awareness(doc),
maxConns = 20 + math.floor(random.rand() * 15) // just to prevent that exactly n clients form a cluster maxConns = 20 + math.floor(random.rand() * 15), // just to prevent that exactly n clients form a cluster
filterBcConns = true
} = {} } = {}
) { ) {
super() super()
this.roomName = roomName this.roomName = roomName
this.doc = doc this.doc = doc
this.filterBcConns = filterBcConns
/** /**
* @type {awarenessProtocol.Awareness} * @type {awarenessProtocol.Awareness}
*/ */