How do I make only one editor for one user

What I expect:

Jack opened an editor page first, his username is ‘Jack’, but he still opened another editor page, and there are two cursors displaying name ‘Jack’…

this is useful for testing, but may not good for production env.

so how do I got (or made by myself manually) a notification in the old editor when the user entered into a new editor …

I guess I may need the provider.awareness and awarenessProtocol or something else…

but the docs are a little bit confusing to me …

May you guys offer some code snippets ? …

BTW, broadcastAwarenessMessage this function/method…

Where does it export from…???

I would be very appreciated for your reply and help !!

Exactly, you manage the cursors with Awareness. If you have two active browsers, you could do provider.awareness.setLocalState(null) to unregister the local state. But you want to do provider.awareness.setLocalState({ name: 'Jack' }) once the window is active again.

You can, for example, enforce that a cursor is only rendered when the window is currently focused: https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement. Another approach is to unregister the local cursor when another window registers a cursor. But that would be more difficult implement.

I’m not sure if you saw it, but there is a tutorial on Awareness: https://docs.yjs.dev/getting-started/adding-awareness

Any feedback is appreciated.