Reputation: 1
I am very new laravel broadcasting. I am working with redis, socket.io and laravel echo. When i reflesh the page this is write on console
GET http://localhost:6001/socket.io/?EIO=3&transport=polling&t=MloS95c net::ERR_CONNECTION_REFUSED
My Test Event:
namespace App\Events;
use Illuminate\Broadcasting\Channel; use Illuminate\Queue\SerializesModels; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class TestEvent {
use SerializesModels;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel ('Message');
}
}
My head :
<script src="http://{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>
<meta name="csrf-token" content="{{ csrf_token() }}">
My Controller:
public function dev(){
event(new TestEvent("Hello"));
return view('home');
}
My Js file:
window.Echo.channel(`Message`)
.listen('TestEvent', (data) => {
console.log(data);
});
Upvotes: 0
Views: 2272
Reputation: 912
You are getting this error as the laravel echo server is not started. Inside your package.json file add under script the following line.
"scripts": {
"start": "laravel-echo-server start",
```
},
Now you need to go to the console and run npm start
command into your project root directory. It will start the lavavel echo server and the error will be gone.
Upvotes: 0