Dec 4, 2023
0
Level 2
Laravel websockets crash
When using a custom laravel websockets handler, once i dispatch a event within the handler, it crashes the whole websocket server, it doesnt exit nor throw an error, but it doesnt accept messages anymore
class CustomWebsocketHandler extends WebSocketHandler
{
public function onMessage(ConnectionInterface $conn, MessageInterface $msg): void
{
if ($msg->isBinary()) {
$payload = $msg->getPayload();
$path = 'images/'.\Str::random().'.JPEG';
Storage::disk('public')->put($path, $payload);
$image = Image::create(['path' => '/storage/'.$path]);
FileUpload::dispatch($image);
return;
}
parent::onMessage($conn, $msg);
}
}
I've binded the class to the websockethandler in order to overwrite her
class BroadcastServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->bind(WebSocketHandler::class, CustomWebsocketHandler::class);
}
public function boot(): void
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}
Please or to participate in this conversation.