【发布时间】:2020-03-31 12:05:17
【问题描述】:
我很难弄清楚如何将我们的 Laravel 应用程序连接到端口 6001 上托管的 websockets 服务器。在我的本地机器上一切正常,但是当我在 Kubernetes 上部署时,我在控制台中收到以下错误:
Pusher : : ["Connecting",{"transport":"ws","url":"wss://localhost:443/app/[redacted]?protocol=7&client=js&version=5.1.1&flash=false"}]
app.js:1 WebSocket connection to 'wss://localhost/app/[redacted]?protocol=7&client=js&version=5.1.1&flash=false' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Pusher 报告的 url 是 wss://localhost:443 对我来说毫无意义,但实际连接是在端口 :80 上的 wss://localhost 尝试。
此外,我已经明确设置了enabledTransports: ['ws'],并没有提供wssHost 或wssPort。
此外,由于此连接是在 Kubernetes pod 中进行的,因此我已采取一切措施禁用 SSL。以下是我的配置:
配置/websockets.php:
...
'apps' => [
[
'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' => false,
'enable_statistics' => true,
],
],
...
资源/js/store/state.js
...
import Echo from 'laravel-echo'
/**
* Echo exposes an expressive API for subscribing to channels and listening
* for events that are broadcast by Laravel. Echo and event broadcasting
* allows your team to easily build robust real-time web applications.
*/
window.Pusher = require('pusher-js');
window.Pusher.logToConsole = true;
let state = {
ads:{},
latestAds: [],
selectedAds: [],
partCodes:[],
carCodes:[],
echo: new Echo({
broadcaster: 'pusher',
key: [redacted],
wsHost: 'localhost',
wsPort: 6001,
disableStats: true,
enabledTransports: ['ws'], // <- added this param
auth: {
headers: {
Authorization: 'Bearer ' + localStorage.getItem('admanager-token'),
'X-CSRF-Token': "CSRF_TOKEN"
}
},
'cluster': 'eu',
})
}
export default state
...
【问题讨论】:
标签: laravel websocket echo pusher