1

I'd like to implemente a user experience similar to Google Docs using realtime API. I wonder what is the best approach to track cursors / selections from all collaborators.

It looks as if IndexReference would be the way to go but how can I track if a collaborator adds a IndexReference to a string?

In the realtime API sandbox only cursor movements from the local cursor are tracked. Are IndexReferences broadcasted to all collaborators or are they for local usage only?

Or is the preferred approach to create a collaborativeMap containing all the selections? Is there a way to attach certain fields to a collaborator so that they get cleaned up when a collaborator leaves?

dflorey
  • 1,828
  • 3
  • 19
  • 31

1 Answers1

0

IndexReferences are data model objects just like any other. You can add listeners to them to be informed of changes.

You probably want to have a map from sessionId -> cursor information. How exactly the cursor information is represented depends on what you want to track, but it could be an index reference on a string.

You can listen to collaborator leave events to figure out when to remove a collaborator's cursor.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • Thanks for your reply! Regarding the IndexReferences: If user A creates an IndexReference, will user B be able to see the reference? There is no method to get the registered references. – dflorey Aug 19 '13 at 10:34
  • I think IndexReferences are only local. My plan (that I have not yet implemented) is for each client to maintain their own entry in the sessionId -> cursor information map as Cheryl suggested. The client will update their cursor information on user input and on events from an IndexReference that they registered at their cursor location. Then clients also listen for changes on other sessionId entries and render the remote client cursors. – Christopher Best Aug 29 '13 at 13:55
  • The only problem I foresee is a delay between document changes and remote cursor changes because the chain looks like: local doc change -> remote client receives doc change & index reference change -> remote client updates cursor map -> cursor map change received locally -> cursor rendered. this delay may be resolved by dead-reckoning with an IndexReference registered for remote client cursor locations in the cases where that makes sense. – Christopher Best Aug 29 '13 at 13:55
  • IndexReferences are not only local. You can store them in a map or list within the data model in order to have a reference to them on other clients. – Cheryl Simon Aug 29 '13 at 15:58