ably / docs

Ably Realtime API documentation
https://ably.com/docs
Apache License 2.0
20 stars 41 forks source link

Presence best practice / cheat sheet #281

Open mattheworiordan opened 7 years ago

mattheworiordan commented 7 years ago

We should add some additional docs that provide recommendations in terms of how to use presence with a GUI for members. We could perhaps have a single page with a cheat sheet to address:

Updating your GUI

Explain that a blanket subscribe to all presence events includes SYNC events and what they are UPDATE events and what they're used for Perhaps recommend to keep things simple, if you don't care about users with different devices or connetions, you could do something like:

presence.on((presenceMessage) => {
  presence.get({ clientId: presenceMessage.clientId }, (members) => {
    if (members.length > 0) {
      ensureUserIsVisible(presenceMessage.clientId)
    } else {
      hideUser(presenceMessage.clientId)
    }
  })
})

Handling different states

Connection state disconnected, update UI to show reconnecting Connection state suspended, update UI to show connection problem, expect to refresh all state after

Channel state DETACHED because of server-fault, why this happens, and what to do and what not to do such as update UI to notify the user they have lost state, expect complete state synchronisation, load history if necessary

Channel becomes ATTACHED, perhaps wait until sync is complete:

channel.on('attached', () => {
  presence.get((members) => {
    updateUiWithUsers()
  })
})

Channel becomes SUSPENDED, same as connection becoming SUSPENDED, why this happens.

Could be nice to then just have a VERY simple app to demonstrate this

┆Issue is synchronized with this Jira Task by Unito

ably-sync-bot commented 2 years ago

➤ Anna Ivanova commented:

Potentially not part of this Epic. Tony Bedford to review and move appropriately if needed.