Discussions related to Shared Editing, Distributed Apps, and Yjs. Questions about Yjs should go to discuss.yjs.dev. Bug reports to the issue tracker.
wss://demos.yjs.dev
looks like. Is it just a single y-websocket server with LevelDB persistence like from here https://github.com/yjs/y-websocket? It seems very reliable even with tons of demo code pointing to it. I was planning to go the y-websocket + levelDB mounted to k8s persistent volume route for my drawing app but wasn't sure how well that would scale up whenever there's more than one such pod. I'm sure the demo wss takes way more abuse that mine ever will, which is why I ask here.
Hi, I'm running a y-webrtc signalling server that is included in the package. (https://github.com/yjs/y-webrtc). But two different machines are unable to establish webrtc connection b/w each other even when they're connected to the same signalling server. When I open two tabs in either of the machines it works i.e. two tabs in the same machine are running as expected.
Am I doing something wrong?
Hi folks, love this look of this project but need some help understanding some basics. I want to setup a 'middleware' (backend/sever) to verify each yjs change event (update) before writing to leveldb (or whatever gets used for sync).
I have looked at y-socket but can't find a way to do that.
Am I missing something here? Is it even possible?
@jimgoo The websocket server is located here and has been running for two years ^^ https://github.com/yjs/yjs-demos/tree/main/demo-server
There's no backup. From time to time it runs out of memory and restarts - discarding all rooms that are not used anymore. It has overall ~500mb memory.
And yeah, a crazy amount of people use the demo server. Today it restarted every second. I guess somebody is bombarding it with requests again. Seems to work out though because CRDTs are pretty resilient ^^
@dmonad Thanks. By verify, I mean as in checking the JSON schema of the 'data' is still valid. Also, ideally checking at the time of the request so I can "filter" the data before sending it.
Can you explain how I'd decode the data?
I've tried several methods from the docs but keep getting {}
eg: https://github.com/yjs/y-websocket/blob/master/bin/utils.js#L176
My store is simple just:{ todos: [], fragment: "xml" }
(is xml the right thing here?)
Inside todo is an array of: { completed: bool, title: string }
@yarnball You should not filter updates depending on its content. That is an antipattern and prevents buggy clients from ever syncing again. You can undo changes on the backend if a client performs changes that you didn't expect. You can use the UndoManager for this.
You can't decode Yjs updates and read the changes as, for example, a diff. The updates contain CRDT operations that cannot be understood by mere humans (really scliency math stuff).
If you want to read a Yjs document, use the appropriate methods. It's always: ydoc.getText('name').toString()
. The ydoc.toJSON()
is deprecated and should not be used. The server must know what it reads.
Hey there. I'm using webrtc with the default setup and I'm receiving this error:
WebSocket connection to 'wss://y-webrtc-signaling-us.herokuapp.com/' failed:
setupWS @ websocket.js:25
WebsocketClient @ websocket.js:122
SignalingConn @ y-webrtc.js:473
(anonymous) @ y-webrtc.js:610
setIfUndefined @ map.js:49
(anonymous) @ y-webrtc.js:610
connect @ y-webrtc.js:609
WebrtcProvider @ y-webrtc.js:595
loadDoc @ space.js?t=1664184681825:125
Is there anything I'm doing wrong or is the signaling service down?
Thanks, saw your comment @dmonad on y-websocket
.
However, the on('synced', ...
does not 'fire'. You mention in your example it is 'hard to determine'. So how would I "return" the subdocument on my client?
My example: https://dpaste.org/dPPbt
If you need the granularity, use a Y.Map. If not, prefer a simple JSON object (FYI Yjs accepts all kinds of JSON objects, so no need for JSON.stringify).
I'm not sure what the code on dpaste is supposed to do. The synced event only works if you use a provider. Please read the official documentation: https://docs.yjs.dev/api/subdocuments
@dmonad Thanks. I've been through the docs but it still not quite clear
For the relationship between a "subDocs" & "folder"- is it possible to get "subDocs" from multiple folders?
You say "Yjs accepts all kinds of JSON objects" but how in my example would I do that? My attempt is below, which fails saying subDoc.set is not a function
. I tried using const subDoc = new Y.Doc(); subDoc.getText().insert(0, {foo:123})
but that also returns blank unless I "JSON.stringify" it
const folder = rootDoc.getMap()
const subDoc = new Y.Doc()
subDoc.getMap()
subDoc.set(data.id, data)
folder.set(data.id, subDoc)
WebSocket connection to 'wss://signaling.yjs.dev/' failed: Error during WebSocket handshake: Unexpected response code: 503
y-webrtc-signaling-us.herokuapp.com
server is failing because it seems that the y-webrtc client auto retries the server every second even if it can connect to other servers, effectively ddosing the server whenever it is down or client-server round trip latency goes above 1000ms.
Hey. I have a nested Y.Map structure like that:
parentMap<Y.Map> = {
childId1: <Y.Map> { ...childProperties },
childId2: <Y.Map> { ...childProperties }
}
and want to use the Y.UndoManager like that:
const newUndoManager = new Y.UndoManager(parentMap);
Now. I can undo and redo events on the parentMap (e.g., add child, or remove child) but not events on the childs (i.e., property changes). As I understand the docs, this should be possible. Is there somewhere an example on how to do it?
@dmonad Thanks for your responses, I have been trying to figure it out but I'm still stuck. This is an example adapting from y-websocket
- I'm basically trying to only return a subset of the result when it goes to getYDoc
Y.RelativePosition
thing: https://docs.yjs.dev/api/relative-positionsY.Doc()
. Maybe I'm seriously misunderstanding something, though.
Hi @anne_biene_twitter,
They can be used with anything that looks like an Array (Y.Text, Y.Array, Y.XmlElement, Y.XmlFragment) ;)
@MaxNoetzold, the docs that you linked explain how you can add support to your existing provider (it's only a few lines of code).
@jclem
The subdocs documentation seems to imply that creating subdocs does not merge—is this correct? What happens if client A and client B concurrently try and create a subdoc with the same key? This generally seems like it's an issue with maps since their values are last-write-wins. How could one implement something where two users may concurrently create the same text document at the same time, and you want their edits to converge?
I'm not sure how this can happen. I expect that content is usually only created by a single user. I suspect that you are implementing a problematic pattern. In order to have two users create the same(?) content at the same time, you need coordination between these users. Yjs is coordination-free, so you'd need to implement this yourself (it would be better to avoid this problematic pattern).
I think the other questions have been posted on the discussion forum as well (if they haven't they should be). I feel the chat is not a good place to ask complicated questions. It's hard to keep track. It would be better to post to discuss.yjs.dev instead.
Hi everyone,
I am currently trying to setup my own yjs backend. This backend should fulfil the following three requirements:
Is such a thing or a similar one already implemented? If so, could you provide me with such or a nice documentation? 😀