我正在尝试在larvel-9.0项目上设置websockets。当我尝试打开/laravel-websockets时,我在控制台中得到以下错误。项目安装在Ubuntu 20.04.4上。
push .min.js:8 WebSocket连接到wss://dev.mydomain.in: 6001/app/mywebsocketkey ?协议= 7,客户= js&版本= 4.3.1&闪电= false"失败:
当我试图通过邮差与url
连接时,我得到了一个成功的响应wss://dev.mydomain.in: 6001/app/mywebsocketkey ?协议= 7,客户= js&版本= 4.3.1& flash = false
和我得到以下的响应在邮差。
{
"event": "pusher:connection_established",
"data": "{"socket_id":"371175048.259495464","activity_timeout":30}"
}
我遵循Websockets文档。
broadcast.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'),
'useTLS' => true,
'encrypted' => true,
'host' => 'dev.mydomain.in',
'port' => 6001,
'scheme' => 'https',
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
'client_options' => [
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
],
],
Websockets.php
'apps' => [
[
'host' => env('LARAVEL_WEBSOCKETS_HOST', "127.0.0.1"),
'port' => env('LARAVEL_WEBSOCKETS_PORT', 6001),
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'path' => env('PUSHER_APP_PATH'),
'capacity' => null,
'enable_client_messages' => true,
'enable_statistics' => true,
'encrypted' => true
],
],
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,
forceTLS: true,
disableStats: true,
enabledTransports: ['ws', 'wss'],
});
.env
PUSHER_APP_ID=1234
PUSHER_APP_KEY=mywebsocketkey
PUSHER_APP_SECRET=hjhasjdhajsh
PUSHER_APP_CLUSTER=mt1
LARAVEL_WEBSOCKETS_HOST="dev.mydomain.in"
LARAVEL_WEBSOCKETS_PORT=6001
LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT="/usr/dev/ssl-fullchain.pem"
LARAVEL_WEBSOCKETS_SSL_LOCAL_PK="/usr/dev/ssl.key"
LARAVEL_WEBSOCKETS_SSL_PASSPHRASE=null
尝试为PUSHER_APP_ID
,PUSHER_APP_KEY
和PUSHER_APP_SECRET
in.env
file