php - 无法使用 laravel-websockets 通过 Echo 接收通知
问题描述
当我通过 Channel 而不是 PrivateChannel 连接时,一切都按预期工作。但是当我通过 PrivateChannel 连接时,我突然停止在我的 javascript 中接收事件我的事件出现在 WebSocket 仪表板中。我像这样发送我的事件:
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';
}
}
频道.php
<?php
Broadcast::channel('recipe', function($recipe, $recipeLiftingDate) {
return true;
});
引导程序.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,
});
GLOBAL.appUrl 是来自 .env 文件的 APP_URL(http://localhost/****/public)。这是我用来连接频道的代码
window.Echo.private("recipe").listen(
".recipe.update",
(event) => {
console.log("ok");
}
);
解决方案
推荐阅读
- avro - org.apache.avro.AvroTypeException:未知的联合分支 reventCodifStdId
- javascript - 我们如何在使用中间件中访问 req 和 res
- apache-spark - Spark - Parquet 或 Delta - 文件大小爆炸
- java - 识别 .JAR 之间新添加的 Java 方法?
- php - 来自本地服务器的 nginx getimagesize:403
- prometheus - 为什么普罗米修斯需要这么长时间才能获得统计数据?
- python - Pandas pct_change 仅在数据框中的一列上创建新列
- java - 如何让 Java 程序长时间重复相同的步骤?
- antiforgerytoken - 非浏览器的 ABP 防伪问题
- python - 是否可以通过忽略函数的注释、格式和名称来检查两个函数的源代码是否相等?