add warning for message type when ArrayBuffer is expected
This commit is contained in:
parent
f31ec9a8b8
commit
aa6edcfd9b
@ -181,10 +181,16 @@ export default function extendConnector (Y/* :any */) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
send (uid, buffer) {
|
send (uid, buffer) {
|
||||||
|
if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {
|
||||||
|
throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - please don\'t use this method to send custom messages')
|
||||||
|
}
|
||||||
this.log('%s: Send \'%y\' to %s', this.userId, buffer, uid)
|
this.log('%s: Send \'%y\' to %s', this.userId, buffer, uid)
|
||||||
this.logMessage('Message: %Y', buffer)
|
this.logMessage('Message: %Y', buffer)
|
||||||
}
|
}
|
||||||
broadcast (buffer) {
|
broadcast (buffer) {
|
||||||
|
if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {
|
||||||
|
throw new Error('Expected Message to be an ArrayBuffer or Uint8Array - please don\'t use this method to send custom messages')
|
||||||
|
}
|
||||||
this.log('%s: Broadcast \'%y\'', this.userId, buffer)
|
this.log('%s: Broadcast \'%y\'', this.userId, buffer)
|
||||||
this.logMessage('Message: %Y', buffer)
|
this.logMessage('Message: %Y', buffer)
|
||||||
}
|
}
|
||||||
@ -223,6 +229,9 @@ export default function extendConnector (Y/* :any */) {
|
|||||||
You received a raw message, and you know that it is intended for Yjs. Then call this function.
|
You received a raw message, and you know that it is intended for Yjs. Then call this function.
|
||||||
*/
|
*/
|
||||||
async receiveMessage (sender, buffer) {
|
async receiveMessage (sender, buffer) {
|
||||||
|
if (!(buffer instanceof ArrayBuffer || buffer instanceof Uint8Array)) {
|
||||||
|
throw new Error('Expected Message to be an ArrayBuffer or Uint8Array!')
|
||||||
|
}
|
||||||
if (sender === this.userId) {
|
if (sender === this.userId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,13 @@ export class BinaryEncoder {
|
|||||||
|
|
||||||
export class BinaryDecoder {
|
export class BinaryDecoder {
|
||||||
constructor (buffer) {
|
constructor (buffer) {
|
||||||
|
if (buffer instanceof ArrayBuffer) {
|
||||||
this.uint8arr = new Uint8Array(buffer)
|
this.uint8arr = new Uint8Array(buffer)
|
||||||
|
} else if (buffer instanceof Uint8Array) {
|
||||||
|
this.uint8arr = buffer
|
||||||
|
} else {
|
||||||
|
throw new Error('Expected an ArrayBuffer or Uint8Array!')
|
||||||
|
}
|
||||||
this.pos = 0
|
this.pos = 0
|
||||||
}
|
}
|
||||||
skip8 () {
|
skip8 () {
|
||||||
|
@ -227,4 +227,3 @@ test('encode/decode Map operations', async function binMap (t) {
|
|||||||
info: 400
|
info: 400
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user