Skip to content
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

socket.io-client does not work properly in Android(React-Native) with Laravel-echo #5143

Open
Deep-Jani opened this issue Jul 19, 2024 · 4 comments

Comments

@Deep-Jani
Copy link

Deep-Jani commented Jul 19, 2024

When using Socket.io as a broadcaster in Laravel-echo, We are using Socketio from socket.io-client as a client for connecting to the socket ,joining into the channel and listen an event fired within the channel.
While working with React Native v0.71.10, I am facing issue regarded to the listening to the event.
The code works fine in iOS devices, but in Android it is not getting listened.

To Reproduce :-
1. these version of packages in package.json

"react-native": "0.71.10"
"laravel-echo": "^1.16.1"
"socket.io-client": "^4.7.5"

2. Add this in your useEffect

import Socketio from 'socket.io-client';
import Echo from 'laravel-echo/dist/echo';

const echo = new Echo({
 broadcaster: 'socket.io',
 host: SOCKET_URL,
 client: Socketio,
}); 

echo.channel('channel_name')
    .listen('.event', (data) => { console.log("🚀 ~ .listen ~ data:", data)  });

In iOS it works fine. In Android, there is no event log.
We tried many suggestions from the community, seems like none of them works for this scenario.

Things we already tried :-

  1. Adding 'CORS' on the server side
  2. tried using android:usesCleartextTraffic="true"
  3. Also tried suggestions from the closed issue of the Repo
  4. Tried downgrading 'Socket.io-client' package from 4.7.5 (latest as of 19/07/2024) to all the suggested ones in the community
@darrachequesne darrachequesne transferred this issue from socketio/socket.io-client Jul 22, 2024
@darrachequesne
Copy link
Member

Hi! Are you using the Android emulator? Or a real device?

Did you check our React Native guide?

@Deep-Jani
Copy link
Author

Deep-Jani commented Jul 22, 2024

Hi! @darrachequesne, thanks for responding.
We have been trying this in both the real devices and emulators.

Yes, we checked react native guide from official socket.io docs.

@darrachequesne
Copy link
Member

Are you able to create a basic Socket.IO connection with the socket.io-client package? Or does it fail too?

@Deep-Jani
Copy link
Author

It connects and listens to the events of the basic Socket server implemented in Nodejs App.

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

No branches or pull requests

2 participants