[8.x] Enable only-to-others
functionality when using Ably broadcast driver
#40234
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.
TL;DR
This PR enables the
only to others
broadcast functionality when using the Ably broadcast driver and the AblyJs frontend client.Issue
When using the Ably broadcast driver the
only to others
functionality provided by Laravel does not work when using the AblyJs client on the frontend.This is because Laravel includes the socketId in the
payload
array but Ably requires it to be a top-level property calledconnectionKey
.(source: https://faqs.ably.com/is-it-possible-to-prevent-messages-published-being-echoed-back-to-the-publishing-client)
Fix
This PR refactors the Ably broadcaster to pass a fully-formed Ably
Message
object to the Ablypublish
method, where we can also include the socketId as theconnectionKey
.Currently, we pass a string event and an array payload to the
publish
method, and the Ably Rest client builds theMessage
object for us, but there is no way to include theconnectionKey
as a top-level property. (source: https://github.com/ably/ably-php/blob/main/src/Channel.php#L111)To ensure backwards compatibility, the
socket
property will remain in thepayload
array too. It's possible people are working around this missing feature by using that property on the frontend.With this PR merged, to enable the
only to others
functionality with Ably, you then only need to set the broadcast event to include the socket ID as per the Laravel docs, and then setechoMessages=false
on the frontend when using the AblyJs client. This will prevent echoing messages back to originator.Thanks
Lee