Muy buenas compañeros, tengo un problema al escuchar eventos con redis y socket io junto con laravel echo
con pusher no tengo ningun problema, pero al intentarlo con socket.io, por algun motivo no escucha los eventos y no logro encontrar el porque, este es el evento que necesito escuchar
statuses
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class StatusCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $status;
/**
* Create a new event instance.
*
* @param $status
*/
public function __construct($status)
{
$this->dontBroadcastToCurrentUser();
$this->status = $status;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('statuses');
}
}
mi configuracion con redis
BROADCAST_DRIVER=redis
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=social.test
REDIS_PASSWORD=null
REDIS_PORT=6379
REDIS_CLIENT=predis
REDIS_PREFIX=null
mi configuracion de laravel echo
{
"authHost": "http://social.test",
"authEndpoint": "/broadcasting/auth",
"clients": [],
"database": "redis",
"databaseConfig": {
"redis": {},
"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": ""
}
}
en el archivo bootrap.js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
import io from 'socket.io-client';
window.io = io;
window.Echo = new Echo({
broadcaster: 'socket.io',
host: 'http://social.test:6001',
// broadcaster: 'pusher',
// key: process.env.MIX_PUSHER_APP_KEY,
// cluster: process.env.MIX_PUSHER_APP_CLUSTER,
// forceTLS: true
});
y en mi componente en el metodo mounted
Echo.channel('statuses').listen('StatusCreated', ({status}) => {
this.statuses.unshift(status); //socket io and pusher
});
Tras ejectuar
laravel-echo-server start
php artisan queue:listen
yarn watch
Los eventos si los registra tanto las queues como el servidor pero no se que pueda estar fallando que en la web no se refleja
este es el output de laravel echo server
C:\laragon\www\social (master)
λ laravel-echo-server start
L A R A V E L E C H O S E R V E R
version 1.6.2
⚠ Starting server in DEV mode...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
Channel: statuses
Event: App\Events\StatusCreated
Channel: statuses
Event: App\Events\StatusCreated
y las queues tambien se procesan de manera correcta
C:\laragon\www\social (master)
λ php artisan queue:listen
[2021-01-30 22:55:18][Hutd2I4aotBTmy3IPXmYi6ZDDFi0wWUS] Processing: App\Events\StatusCreated
[2021-01-30 22:55:18][Hutd2I4aotBTmy3IPXmYi6ZDDFi0wWUS] Processed: App\Events\StatusCreated
[2021-01-30 23:00:26][Qr5VeR50jhX6uZb2yRqq4wxKcajTx3fJ] Processing: App\Events\StatusCreated
[2021-01-30 23:00:26][Qr5VeR50jhX6uZb2yRqq4wxKcajTx3fJ] Processed: App\Events\StatusCreated