Answer the question
In order to leave comments, you need to log in
Why is laravel-echo-server not connecting to web socket?
I'm trying to connect laravel echo.
laravel-echo-server
{
"authHost": "http://want_can.lc",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {
"port": 6379,
"host":"127.0.0.1",
"keyPrefix":null
},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
if (typeof io !== 'undefined') {
window.Echo = new Echo({
broadcaster: 'socket.io',
host:window.location.hostname +":"+ '6001',
//transports: ['websocket', 'polling', 'flashsocket'],
});
}else{
console.log('AAA!')
}
<?php
namespace App\Events;
class PrivateChat implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
public $user;
public function __construct($data,User $user)
{
$this->data=$data;
$this->user=$user;
$this->dontBroadcastToCurrentUser();
}
public function broadcastOn()
{
Message::create($this->data,$this->user);
return new PrivateChannel('room.'.$this->data['room_id']);
}
}
<?php
class MessageController
{
public $service;
public function __construct(ChatroomService $service)
{
$this->service=$service;
}
public function message(ChatRequest $request,User $user)
{
event ( new PrivateChat($request->all(), $user));
}
}
Broadcast::channel('room.{room_id}', function ( $user, $room_id) {
return $user->chatroomsCustomer->contains($room_id)||$user->chatroomsExecutor->contains($room_id);
});
Channel: private-room.1
Event: App\Events\PrivateChat
[2021-02-01 06:50:25][RXvfnlILeDt6J2MTWAXPA9EStl1Cgi5X] Processing: App\Events\PrivateChat
[2021-02-01 06:50:25][RXvfnlILeDt6J2MTWAXPA9EStl1Cgi5X] Processed: App\Events\PrivateChat
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question