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 docquery parameter, use that as the document id.
- If the URL does not contain a docquery parameter, create a new document and redirect to the same URL with thedocquery 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 getOrCreateDocAndTokenhelper function, which optionally takes a document id, creates a new document if one doesn't exist, and returns a clientToken.
- The YDocProvidercomponent has an optionalsetQueryParamprop, which will automatically set thedocquery 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.)