【问题标题】:Laravel echo connects to pusher instead of laravel-websocketsLaravel echo 连接到 pusher 而不是 laravel-websockets
【发布时间】:2021-03-12 07:54:17
【问题描述】:

我将 laravel-websockets 作为 systemctl 服务启动。

一切正常,但在我执行sudo reboot 直到 laravel-websockets 进程开始(我也使用nginx 作为反向代理)之后,应用程序上的客户端连接到推送器而不是我的套接字服务。

如果我清除 cookie 并刷新页面(在机器和所有服务启动后几分钟),客户端将按照应有的方式连接到 laravel-websockets。但前提是我清除了 cookie。如果我不清除 cookie,无论我刷新页面多少次客户端仍然连接到推送器。

在开发工具网络选项卡中: https://sockjs-eu.pusher.com/pusher/app/.... 代替 https://socket.mydomain.com

在我的推送应用程序中,我关闭了客户端事件。但是在 laravel websockets 中我有它们。我确定客户端正在连接到 pusher,因为我在错误控制台中得到了这个: To send client events, you must enable this feature in the Settings page of your dashboard.

我也将 laravel queue worker 作为 systemctl 服务启动。这可能与它有关吗?他们应该按顺序开始吗?

编辑

window.Echo = new Echo({
     broadcaster: 'pusher',
     key: process.env.MIX_PUSHER_APP_KEY,
     cluster: process.env.MIX_PUSHER_APP_CLUSTER,
     wsHost: 'socket.mydomain.com', //this is not the real domain
     wssHost: 'socket.mydomain.com', //this is not the real domain
     wssPort:443,
     forceTLS: true,
     disableStats: true,
 });

【问题讨论】:

  • 您可以添加您的代码new Echo({}) 吗?
  • @Kamlesh Paul 我在编辑中添加了它。我只是更改了不想公开的域。

标签: php laravel websocket pusher


【解决方案1】:

试试这个配置

window.Echo = new Echo({
     broadcaster: 'pusher',
     key: 'broadcasting', // hard code
     wsHost: window.location.hostname,
     wssHost: window.location.hostname, 
     enabledTransports: ['ws', 'wss'],
     wssPort:443,
     forceTLS: true,
     disableStats: true,
 });

在这里key: 'broadcasting' 进行硬编码并尝试一些时间它会产生问题这是我的配置可能对你有帮助

【讨论】:

  • 是的,你正在做某事。我正在使用正确的推送器键,并且在 laravel websockets 启动之前它会尝试连接到推送器。我将 .env 密钥和秘密更改为随机的,现在它可以工作了。谢谢你。他们应该在文档中的某个地方提到您不需要正确的推送者凭据。
猜你喜欢
  • 2021-04-27
  • 2020-09-15
  • 2021-12-30
  • 1970-01-01
  • 2022-01-25
  • 2020-06-14
  • 1970-01-01
  • 2019-09-06
  • 1970-01-01
相关资源
最近更新 更多