When I connect via Channel instead of PrivateChannel, everything works as expected. But when I connect via PrivateChannel, I suddenly stop receiving events inside my javascript My events appear inside the WebSocket dashboard. I dispatch my event like this:
FullRecipeSaved::dispatch($recipe, $rld);
FullRecipeSaved.php
class FullRecipeSaved implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $recipe;
public $recipeLiftingDate;
public function __construct(Recipe $recipe, RecipeLiftingDate $recipeLiftingDate)
{
$this->recipe = $recipe;
$this->recipe = $recipeLiftingDate;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('recipe');
}
/**
* The event's broadcast name.
*
* @return string
*/
public function broadcastAs()
{
return 'recipe.update';
}
}
channels.php
<?php
Broadcast::channel('recipe', function($recipe, $recipeLiftingDate) {
return true;
});
bootstrap.js
window.Echo = new Echo({
broadcaster: "pusher",
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
wsHost: window.location.hostname,
wsPort: 6001,
forceTLS: false,
disableStats: false,
authEndpoint: GLOBAL.appUrl,
});
The GLOBAL.appUrl is the APP_URL from .env filehttp://localhost/****/public). And this is the code I am using to connect to the channel
window.Echo.private("recipe").listen(
".recipe.update",
(event) => {
console.log("ok");
}
);