add option to not filter bc connections and always connect using webrtc
This commit is contained in:
parent
9f73533b5b
commit
f18bb75147
3 changed files with 18 additions and 10 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -270,7 +270,11 @@ const announceSignalingInfo = room => {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Room} room
|
||||
*/
|
||||
const broadcastBcPeerId = room => {
|
||||
if (room.provider.filterBcConns) {
|
||||
// broadcast peerId via broadcastchannel
|
||||
const encoderPeerIdBc = encoding.createEncoder()
|
||||
encoding.writeVarUint(encoderPeerIdBc, messageBcPeerId)
|
||||
|
@ -278,6 +282,7 @@ const broadcastBcPeerId = room => {
|
|||
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}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue