Skip to content

No official way to access socketId when using Reverb + toOthers() with @laravel/echo-react #474

@tranvantruongktech

Description

@tranvantruongktech

Echo Version

2.2.7

Laravel Version

12

PHP Version

8.4

NPM Version

11.4.2

Database Driver & Version

No response

Description

I am using Laravel 12, Laravel Reverb, and @laravel/echo-react to build a real-time chat feature.

Broadcasting itself works correctly, however I am running into a limitation when using broadcast()->toOthers().

Laravel requires the client to send the X-Socket-Id header so the broadcaster can exclude the sender socket.
With classic Echo usage (window.Echo), this is straightforward via Echo.socketId().

However, when using @laravel/echo-react:

configureEcho() does not expose Echo globally

window.Echo is always undefined

There is no documented or supported way to retrieve socketId outside of React hooks

There is no helper like getEcho() or similar to access the Echo instance

As a result, users must rely on workarounds (e.g. storing socketId in a global variable from a component) to make toOthers() function correctly.

Steps To Reproduce

Expected behavior

One of the following (or similar) would make integration much easier:

An official API to access the Echo instance or socketId

e.g. getEcho()

or getSocketId()

Optional exposure of the Echo instance (configurable)

Official documentation describing how toOthers() should be handled when using @laravel/echo-react with Reverb

Actual behavior

window.Echo is undefined

No supported way to access socketId

broadcast()->toOthers() cannot work correctly without custom hacks

Environment

Laravel: 12.x

Broadcasting driver: Reverb

Frontend: React + Inertia

Package: @laravel/echo-react

Realtime use case: chat messaging

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions