Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
disconnect () {
// signal through all available signaling connections
signalingConns.forEach(conn => {
if (conn.connected) {
conn.send({ type: 'unsubscribe', topics: [this.name] })
}
})
awarenessProtocol.removeAwarenessStates(this.awareness, [this.doc.clientID], 'disconnect')
// broadcast peerId removal via broadcastchannel
const encoderPeerIdBc = encoding.createEncoder()
encoding.writeVarUint(encoderPeerIdBc, messageBcPeerId)
encoding.writeUint8(encoderPeerIdBc, 0) // remove peerId from other bc peers
encoding.writeVarString(encoderPeerIdBc, this.peerId)
broadcastBcMessage(this, encoding.toUint8Array(encoderPeerIdBc))
bc.unsubscribe(this.name, this._bcSubscriber)
this.bcconnected = false
this.doc.off('update', this._docUpdateHandler)
this.awareness.off('change', this._awarenessUpdateHandler)
this.webrtcConns.forEach(conn => conn.destroy())
}
destroy () {
window.addEventListener('beforeunload', () => {
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'window unload')
rooms.forEach(room => {
room.disconnect()
})
})
}