Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[13.x] Fix duplicated socket value in Redis broadcast payload#60238

Open
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:fix/redis-broadcast-socket-payload
Open

[13.x] Fix duplicated socket value in Redis broadcast payload#60238
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:fix/redis-broadcast-socket-payload

Conversation

@LucasCavalheri
Copy link
Copy Markdown
Contributor

Summary

This PR fixes an inconsistency in RedisBroadcaster where the socket
value was being included twice in Redis broadcast payloads.

Previously, the payload was constructed like this:

'data' => $payload,
'socket' => Arr::pull($payload, 'socket'),

Because the socket was only removed after assigning $payload to data,
the resulting payload could contain the socket in both places:

[
    'data' => [
        'id' => 1,
        'socket' => '123.456',
    ],
    'socket' => '123.456',
]

This behavior diverged from PusherBroadcaster, which removes the socket
from the payload data before broadcasting.

Changes

Updated RedisBroadcaster to remove the socket before building the final payload:

$socket = Arr::pull($payload, 'socket');

$payload = json_encode([
    'event' => $event,
    'data' => $payload,
    'socket' => $socket,
]);

Tests

Added testBroadcastDoesNotIncludeSocketInPayloadData to verify that:

  • the socket remains available at the top level of the payload
  • the socket is not included inside data
  • the expected channel, event, and payload are sent to Redis

Files Changed

  • src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php
  • tests/Broadcasting/RedisBroadcasterTest.php

Validation

./vendor/bin/phpunit tests/Broadcasting/RedisBroadcasterTest.php tests/Broadcasting

Result:

OK (172 tests, 167 assertions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant