From 2cbfc49a2b089dbd96d0b52e9273527379f044a9 Mon Sep 17 00:00:00 2001 From: Max Goodhart Date: Sun, 5 Jul 2020 22:56:00 -0700 Subject: [PATCH] Prevent control page echoing back CRDT updates --- src/web/control.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/web/control.js b/src/web/control.js index c53a5c6..30dfb7a 100644 --- a/src/web/control.js +++ b/src/web/control.js @@ -144,14 +144,17 @@ function useStreamwallConnection(wsEndpoint) { }, []) useEffect(() => { - function sendUpdate(update) { + function sendUpdate(update, origin) { + if (origin === 'server') { + return + } wsRef.current.send(update) } function receiveUpdate(ev) { if (!(ev.data instanceof ArrayBuffer)) { return } - Y.applyUpdate(stateDoc, new Uint8Array(ev.data)) + Y.applyUpdate(stateDoc, new Uint8Array(ev.data), 'server') } stateDoc.on('update', sendUpdate) wsRef.current.addEventListener('message', receiveUpdate)