【问题标题】:in Kubernetes pod, can't force Laravel Echo (using Pusher) to connect via ws over port 6001 protocol instead of wss on port 443在 Kubernetes pod 中,不能强制 Laravel Echo(使用 Pusher)通过端口 6001 协议而不是端口 443 上的 wss 连接
【发布时间】: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'],并没有提供wssHostwssPort

此外,由于此连接是在 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


    【解决方案1】:

    在你的 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'),
                    'useTLS' => false,
                    'host' => '127.0.0.1',
                    'port' => 6001,
                    'scheme' => 'http',
                    'encrypted' => false,
                ],
            ],
    

    在前端确保三个组件同步:

    • wsHost
    • wsPort
    • 和 app_key

    【讨论】:

      猜你喜欢
      • 2021-10-18
      • 2018-09-30
      • 1970-01-01
      • 2021-03-12
      • 1970-01-01
      • 2020-05-22
      • 1970-01-01
      • 2011-12-03
      • 2021-04-06
      相关资源
      最近更新 更多