Laravel-websockets: Can i use laravel-websockets with reactjs seperate project

Created on 20 Jun 2020  路  4Comments  路  Source: beyondcode/laravel-websockets

i want to use laravel as backend and reactjs as frontend and i am using reactjs seperate project not using inside the laravel project. can i use laravel echo in react js project and call events by calling api. please guide me thank you

Most helpful comment

Make sure the configuration looks somehow like this:

window.Echo = new Echo({
  broadcaster: 'pusher',
  wsHost: window.location.hostname,
  wsPort: 6001,
  wssHost: window.location.hostname,
  wssPort: 6001,
  key: 'client',
  disableStats: true,
  enabledTransports: ['ws', 'wss'],
  forceTLS: false,
});

All 4 comments

Yes you can, laravel echo is a javascript library and absolutely it can be used with reactjs

@BenMstfa I have the same scenario and I'm using laravel-echo to connect to my larave-websocket project. But I can't seem to make it work. I'm facing authetication issues. And if I set authEndpoint variable on my larave-echo app it throws CORS issues. Can you provide any working exmple as to how can I connect and authenticate users from any app? Given the user is providing authentication token?

@junaidrasheed Can you elaborate a bit about the issue?

I have a strange feeling that the issues you're talking about are related to the missing X-CSRF-TOKEN header as it's used in the dashboard: https://github.com/beyondcode/laravel-websockets/blob/master/resources/views/dashboard.blade.php#L124

Make sure the configuration looks somehow like this:

window.Echo = new Echo({
  broadcaster: 'pusher',
  wsHost: window.location.hostname,
  wsPort: 6001,
  wssHost: window.location.hostname,
  wssPort: 6001,
  key: 'client',
  disableStats: true,
  enabledTransports: ['ws', 'wss'],
  forceTLS: false,
});
Was this page helpful?
0 / 5 - 0 ratings