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.

View file

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

View file

@ -270,13 +270,18 @@ const announceSignalingInfo = room => {
})
}
/**
* @param {Room} room
*/
const broadcastBcPeerId = room => {
// broadcast peerId via broadcastchannel
const encoderPeerIdBc = encoding.createEncoder()
encoding.writeVarUint(encoderPeerIdBc, messageBcPeerId)
encoding.writeUint8(encoderPeerIdBc, 1)
encoding.writeVarString(encoderPeerIdBc, room.peerId)
broadcastBcMessage(room, encoding.toUint8Array(encoderPeerIdBc))
if (room.provider.filterBcConns) {
// broadcast peerId via broadcastchannel
const encoderPeerIdBc = encoding.createEncoder()
encoding.writeVarUint(encoderPeerIdBc, messageBcPeerId)
encoding.writeUint8(encoderPeerIdBc, 1)
encoding.writeVarString(encoderPeerIdBc, room.peerId)
broadcastBcMessage(room, encoding.toUint8Array(encoderPeerIdBc))
}
}
export class Room {
@ -525,6 +530,7 @@ export class WebrtcProvider extends Observable {
* @param {string?} [opts.password]
* @param {awarenessProtocol.Awareness} [opts.awareness]
* @param {number} [opts.maxConns]
* @param {boolean} [opts.filterBcConns]
*/
constructor (
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'],
password = null,
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()
this.roomName = roomName
this.doc = doc
this.filterBcConns = filterBcConns
/**
* @type {awarenessProtocol.Awareness}
*/