This repository was archived by the owner on Feb 7, 2024. It is now read-only.
Fix presence channels emitting too much events #530
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So after #527 I noticed the counts were still wrong in my app. Dangit I thought this must be my stupid JavaScript code not counting correctly. As it turns out it was not 😄 (that does not happen often).
Pusher only fires
member_added
andmember_removed
events after the first and last socket connection for a user ID. This library would always emit amember_added
event regardless how many times the user was already connected (same formember_removed
). This PR aims to fix that behaviour.Please go over it to make sure it's correct. The tests should prove that it works, but please make sure I've interpreted the Pusher docs correctly and the tests validate the correct behaviour.
This might technically be a breaking change so not sure this could be 1.8 although it would be very nice to still have this in 1.x before the big refactor of 2.x.
There is 1 important consideration for this PR (related to #401). The channel member
user_info
is updated on every new connection, so technically be re-subscribing to the presence channel you can update your user info, I think this is fine, but Pusher handles this differently and it would be trivial to implement that and make the user info "immutable" until all sockets for a user have been disconnected like Pusher... bit torn about this one. Could possibly become a config option?