Created
November 30, 2022 03:54
-
-
Save ehatricksmith/85ff2ae3023f8fc75b1644347889513b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Y from "yjs"; | |
import { WebsocketProvider } from "y-websocket"; | |
const doc = new Y.Doc(); | |
// The provider takes care of broadcasting and receiving sync and awareness | |
const provider = new WebsocketProvider( | |
"wss://dovetailapp.com/api/yjs", | |
"00000000-0000-0000-0000-000000000000", // docId | |
doc | |
); | |
// Listens for awareness changes from other clients | |
provider.awareness.on('change', changes => { | |
// The new awareness state changes | |
changes; | |
// Complete map of awareness states, in the form of `clientId => JSON` | |
provider.awareness.getStates(); | |
}) | |
// Sets the awareness state of the current client, which provider will send to the server | |
provider.awareness.setLocalState({ | |
userId: "00000000-0000-0000-0000-000000000000", | |
cursorPosition: { x: 100, y: 200 }, | |
selectedNoteIds: [ | |
"00000000-0000-0000-0000-000000000000", | |
"11111111-1111-1111-1111-111111111111", | |
"22222222-2222-2222-2222-222222222222", | |
], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment