我正在使用替换 Pusher Laravel Webaockets 包。
在我的应用程序中,Laravel Echo 尝试通过 wss 而不是 ws 连接,所以它失败了。
我的资源/js/bootstrap.js:
import Echo from 'laravel-echo'
window.Pusher = require('pusher-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,
disableStats: true,
encrypted: false,
enabledTransports: ['ws'],
});
config/broadcasting.php 中的广播连接:
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => false,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http',
],
],
我的.env:
BROADCAST_DRIVER=pusher
...
PUSHER_APP_ID=1122334455
PUSHER_APP_KEY=lkjdsofsd9f8sd98f7s9dfuosdff9s87fsuyfsd76f8s7df6
PUSHER_APP_SECRET=secret1122334455fsdf897sd98f7sd88sd7f9s8d7f
PUSHER_APP_CLUSTER=eu
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
MIX_PUERTO_WEBSOCKETS="${LARAVEL_WEBSOCKETS_PORT}"
当我的应用程序页面加载时,检查控制台我可以看到:
获取 wss://localhost/app/lkjdsofsd9f8sd98f7s9dfuosdff9s87fsuyfsd76f8s7df6?protocol=7&client=js&version=6.0.3&flash=false
但是如果我运行http://localhost:8000/laravel-websockets请求是通过 ws 并且它是成功的:
你能帮助我吗?谢谢