Advanced
Documents and DocIds

Documents and DocId's

Y-Sweet uses the term documents to describe the asset users collaborate on. This can be a whiteboard, text document, etc. To create a realtime experience, multiple users must be connected to the same document id.

It’s up to you how documents are created and authorized. For demos, we like to use a pattern that works like this:

  • If the URL contains a doc query parameter, use that as the document id.
  • If the URL does not contain a doc query parameter, create a new document and redirect to the same URL with the doc query parameter set.

Because this is a common pattern for applications where documents are not private, like shared whiteboards, Y-Sweet provides two features that make it easier:

  • The getOrCreateDocAndToken helper function, which optionally takes a document id, creates a new document if one doesn't exist, and returns a clientToken.
  • The YDocProvider component has an optional setQueryParam prop, which will automatically set the doc query parameter in the URL bar when a new document is created. (This way, if the URL is copied and pasted, the user will end up in the same document.)
y-sweet was created by Jamsocket.