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 () {
export const writeRelativePosition = (encoder, rpos) => {
const { type, tname, item } = rpos
if (item !== null) {
encoding.writeVarUint(encoder, 0)
writeID(encoder, item)
} else if (tname !== null) {
// case 2: found position at the end of the list and type is stored in y.share
encoding.writeUint8(encoder, 1)
encoding.writeVarString(encoder, tname)
} else if (type !== null) {
// case 3: found position at the end of the list and type is attached to an item
encoding.writeUint8(encoder, 2)
writeID(encoder, type)
} else {
throw error.unexpectedCase()
}
return encoder
}
write (encoder, offset) {
const origin = offset > 0 ? createID(this.id.client, this.id.clock + offset - 1) : this.origin
const rightOrigin = this.rightOrigin
const parentSub = this.parentSub
const info = (this.content.getRef() & binary.BITS5) |
(origin === null ? 0 : binary.BIT8) | // origin is defined
(rightOrigin === null ? 0 : binary.BIT7) | // right origin is defined
(parentSub === null ? 0 : binary.BIT6) // parentSub is non-null
encoding.writeUint8(encoder, info)
if (origin !== null) {
writeID(encoder, origin)
}
if (rightOrigin !== null) {
writeID(encoder, rightOrigin)
}
if (origin === null && rightOrigin === null) {
const parent = this.parent
if (parent._item === null) {
// parent type on y._map
// find the correct key
const ykey = findRootTypeKey(parent)
encoding.writeVarUint(encoder, 1) // write parentYKey
encoding.writeVarString(encoder, ykey)
} else {
encoding.writeVarUint(encoder, 0) // write parent id
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))
}
_toBinary (encoder) {
encoding.writeUint8(encoder, getStructReference(this.constructor))
let info = 0
if (this._origin !== null) {
info += 0b1 // origin is defined
}
// TODO: remove
/* no longer send _left
if (this._left !== this._origin) {
info += 0b10 // do not copy origin to left
}
*/
if (this._right_origin !== null) {
info += 0b100
}
if (this._parentSub !== null) {
info += 0b1000
}
export const writeRelativePosition = (encoder, rpos) => {
const { type, tname, item } = rpos
if (item !== null) {
encoding.writeVarUint(encoder, 0)
ID.writeID(encoder, item)
} else if (tname !== null) {
// case 2: found position at the end of the list and type is stored in y.share
encoding.writeUint8(encoder, 1)
encoding.writeVarString(encoder, tname)
} else if (type !== null) {
// case 3: found position at the end of the list and type is attached to an item
encoding.writeUint8(encoder, 2)
ID.writeID(encoder, type)
} else {
throw error.unexpectedCase()
}
return encoder
}
export const writeRelativePosition = (encoder, rpos) => {
const { type, tname, item } = rpos
if (item !== null) {
encoding.writeVarUint(encoder, 0)
writeID(encoder, item)
} else if (tname !== null) {
// case 2: found position at the end of the list and type is stored in y.share
encoding.writeUint8(encoder, 1)
encoding.writeVarString(encoder, tname)
} else if (type !== null) {
// case 3: found position at the end of the list and type is attached to an item
encoding.writeUint8(encoder, 2)
writeID(encoder, type)
} else {
throw error.unexpectedCase()
}
return encoder
}
_toBinary (encoder) {
encoding.writeUint8(encoder, getStructReference(this.constructor))
this._targetID.encode(encoder)
encoding.writeVarUint(encoder, this._length)
}
write (encoder, offset) {
encoding.writeUint8(encoder, structGCRefNumber)
encoding.writeVarUint(encoder, this.length - offset)
}
}