-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Presence docs to discourage building of presence sets #2073
Comments
@paddybyers @SimonWoolf @owenpearson @ttypic I was just looking at that presence code again, and it got me thinking about whether this is a documentation issue, or in fact an SDK / API issue.
If we focus on what the customer would want instead of how this works internally, I would change things as following:
WDYT? |
This seems to be a react example. where they want to update the view when the dataset changes. https://github.com/laravel/echo/blob/master/src/channel/presence-channel.ts#L10 In the Echo.join().here(members => {}) implementation, the callback is called with updated members when a new member joins, updates, or leaves the channel. To expose this we had to update the code in ably laravel echo fork =>
|
Yup, why's that an issue?
Yup, and it just calls |
I think it will be better if we can just expose a method like |
Or do you mean an equivalent |
Almost all of the mobile/web UI frameworks update components based on state change, so we expose a method on
instead of them doing
|
FWIW. My thinking on my comment:
Was that we could introduce a change potentially that is not breaking as follows: channel.presence.subscribe(function(member, allMembers) {
console.log(member.data); // => the user who has entered, left, etc
console.log(allMembers); // => the presence set from `presence.get`
}); |
Yeah, introducing any breaking/non-breaking change that can make it easier for users to subscribe to changed members 👍 |
We do document this: https://ably.com/docs/best-practice-guide#use-existing-presence-set . I know because I wrote most of that entry. The problem is that it's in the best practice guide, which is hard to discover and no-one ever reads. The solution is to move it into the normal presence docs, which is a change that was agreed some time ago.
The main reason the above code is broken is that it assumes the presence set is uniquified by clientId, which it isn't, it's uniquified by clientId+connectionId. This is not a thing we can change just with a client library api change, it would require a completely different presence model, client and serverside. I don't think this is a change it would be sensible to make at this point, to put it mildly.
Sure, no objection to this. Trivial and backwards-compatible change for ably-js. |
That's the main reason, but not the only reason. The former is easy to explain to a developers and they can reason about (users can be present more than once with different connection IDs), but the latter is much harder (enter events don't necessarily mean the user has entered because a leave event can arrive after but with an earlier timestamp). I think we should fix that latter problem in our SDK API because emitting the raw protocol events is not the API a developer would expect to see. We should have an abstraction over our underlying protocol instead of exposing it. That's not a big change (and requires not realtime system changes), but would materially reduce the likelihood of developers mistakenly using this API. WDYT? |
Apologies for the noise in this issue (I made a mistake). I've corrected my first follow on comment Saying all that, I do think we should:
|
Link to internal discussion -> https://ably-real-time.slack.com/archives/CURL4U2FP/p1701711106209279 |
Why not just expose current members into |
They need a callback to be executed everytime it's updated. Just exposing |
A partner of ours has been building an app which has erratic presence behaviour. Upon inspecting the code, we see the same pattern of developers continuing to try and build their own presence sets based on
enter
,leave
,update
events, which is flawed and should never be done, they should instead rely on the presenceget
method to get the complete presence set. We suffered this same issue ourselves with our Spaces SDK development. If our own internal staff are making these mistakes, and partners are making these mistakes, customers will certainly be making these mistakes.Here is the sample code for ref:
We really need to rethink our presence docs to encourage the right behaviours. When I read https://ably.com/docs/presence-occupancy/presence, I see no mention of why users should not handle enter, leave, update events and build their own presence set, and in fact the get method to get the presence set only appears a couple of (virtual) pages down the page.
┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: