"I am working on a project using Laravel Broadcast and the package beyondcode/laravel-websockets
. When I use Pusher.js directly, the connection and operations are successful, but when I use Laravel Echo, there is no connection established with the socket server."
in file js:
pusher code:
Pusher.logToConsole = true;
var pusher = new Pusher('a12bc34', {
cluster: 'mt1',
encrypted: false,
forceTLS: false,
wsHost: '127.0.0.1',
wsPort: 6001,
});
var channel = pusher.subscribe('internal-transfer-forms');
channel.bind('eventInternalTransferForm', function (data) {
});
laravel echo code:
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Pusher.logToConsole = true;
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'a12bc34',
cluster: 'mt1',
encrypted: false,
wsHost: '127.0.0.1',
wsPort: 6001,
forceTLS: false,
});
Echo.channel(`internal-transfer-forms`)
.listen('eventInternalTransferFormd', (e) => {
});
"Based on the research I conducted and the question I asked in Telegram groups, unfortunately, I couldn’t find the solution myself. It seems that the issue is more related to data transmission than connection, as I’m not even able to establish a connection. However, with Pusher.js, the connection and operations are successful."
2
Answers
Please check below status
Step 1 :
Step 2 :
Step 3 :
You need to publish the WebSocket configuration file:
Step 4
Step 5
Http
If you are using https then change below thing in .env
Https
In this if Two way Setup if you are using http then socket work on ws and if you are using https
Wss
1)If You are using Http then below change in your config/broadcasting.php file
Reference site : https://beyondco.de/docs/laravel-websockets/basic-usage/pusher
2)If You are using Https then below change in your config/broadcasting.php file
Step 6
config/websockets.php
In ssl part you have to add below three parameter
1)verify_peer
2)verify_peer_name
3)allow_self_signed
Step 7
routes/web.php
Step 8
config/app.php
Step 9
Step 10
Change in resources/js/bootstrap.js
Please checked how to install supervioser and virtulhost in laravel websocket Please check link.
laravel websocket setup and example how to use it
For message or change sent to laravel websocket
add name space :
in your controller