I finally got the authentication working using the web middleware and my custom auth like this:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes(['middleware' => 'web', 'guards' => 'vcs']);
require base_path('routes/channels.php');
}
}
The problem now: The event is fired correctly, shows up in the queue console (I am using redis queues):
vendor/bin/sail artisan queue:work
INFO Processing jobs from the [default] queue.
2022-11-15 13:28:15 App\Events\ClientStreamStarted .................................................... 25.50ms DONE
2022-11-15 13:30:54 App\Events\ClientStreamStarted ..................................................... 6.87ms DONE
2022-11-15 13:32:09 App\Events\ClientStreamStarted ..................................................... 6.10ms DONE
But never calls the listener and is never sent to the browser... The Event/Listener is registered over here:
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use App\Events\ClientJoinedRoom;
use App\Listeners\ClientStreamListener;
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
ClientJoinedRoom::class => [
ClientStreamListener::class,
]
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
//
}
/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return false;
}
}
My Listener:
<?php
namespace App\Listeners;
use App\Events\ClientStreamStarted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
class ClientStreamListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\ClientStreamStarted $event
* @return void
*/
public function handle(ClientStreamStarted $event)
{
Log::info('Event.ClientStreamStarted.Listener: ' . $event);
}
}
The event gets called like this:
ClientStreamStarted::dispatch($stream, $room);
The event gets logged and everything is working fine. But the listener never gets called and the event never gets broadcasted to the client.
What the hell is going on here?
