Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.peer.on('connect', () => {
log('connected to ', logging.BOLD, remotePeerId)
this.connected = true
// send sync step 1
const provider = room.provider
const doc = provider.doc
const awareness = room.awareness
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, messageSync)
syncProtocol.writeSyncStep1(encoder, doc)
sendWebrtcConn(this, encoder)
const awarenessStates = awareness.getStates()
if (awarenessStates.size > 0) {
const encoder = encoding.createEncoder()
encoding.writeVarUint(encoder, messageAwareness)
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(awareness, Array.from(awarenessStates.keys())))
sendWebrtcConn(this, encoder)
}
})
this.peer.on('close', () => {
encoding.writeVarUint(encoderSync, messageSync)
syncProtocol.writeSyncStep1(encoderSync, this.doc)
broadcastBcMessage(this, encoding.toUint8Array(encoderSync))
// broadcast local state
const encoderState = encoding.createEncoder()
encoding.writeVarUint(encoderState, messageSync)
syncProtocol.writeSyncStep2(encoderState, this.doc)
broadcastBcMessage(this, encoding.toUint8Array(encoderState))
// write queryAwareness
const encoderAwarenessQuery = encoding.createEncoder()
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness)
broadcastBcMessage(this, encoding.toUint8Array(encoderAwarenessQuery))
// broadcast local awareness state
const encoderAwarenessState = encoding.createEncoder()
encoding.writeVarUint(encoderAwarenessState, messageAwareness)
encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this.doc.clientID]))
broadcastBcMessage(this, encoding.toUint8Array(encoderAwarenessState))
}
disconnect () {
).then(cipher => {
const encryptedDataEncoder = encoding.createEncoder()
encoding.writeVarString(encryptedDataEncoder, 'AES-GCM')
encoding.writeVarUint8Array(encryptedDataEncoder, iv)
encoding.writeVarUint8Array(encryptedDataEncoder, new Uint8Array(cipher))
return encoding.toUint8Array(encryptedDataEncoder)
})
}
write (encoder, offset) {
super.write(encoder, offset, structBinaryRefNumber)
encoding.writeVarUint8Array(encoder, this.content)
}
}
).then(cipher => {
const encryptedDataEncoder = encoding.createEncoder()
encoding.writeVarString(encryptedDataEncoder, 'AES-GCM')
encoding.writeVarUint8Array(encryptedDataEncoder, iv)
encoding.writeVarUint8Array(encryptedDataEncoder, new Uint8Array(cipher))
return encoding.toUint8Array(encryptedDataEncoder)
})
}