Laravel Beyondcode websockets 无法连接

Kiy*_*ash 9 php websocket laravel

我正在使用这个Laravel websockets 包来拥有我自己的 websocket 服务器。

正如包文档中提到的,我有这个配置:

.env 环境:

PUSHER_APP_ID=761772
PUSHER_APP_KEY=qwerty
PUSHER_APP_SECRET=secret
PUSHER_APP_CLUSTER=ap2
Run Code Online (Sandbox Code Playgroud)

广播.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' => true,
            //'host' => '105.208.174.8', <--I did test this too
            'host' => '127.0.0.1',
            'port' => 6001,
            'scheme' => 'https'//<--Tested with http
        ],
    ],
Run Code Online (Sandbox Code Playgroud)

websockets.php:

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'enable_client_messages' => false,
        'enable_statistics' => true,
    ],
],
Run Code Online (Sandbox Code Playgroud)

引导程序.js:

/**
 * 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.
 */

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'qwerty',
    wsHost: window.location.hostname,
    wsPort: 6001,
    disableStats: true,
    encrypted: true,
    enabledTransports: ['ws', 'wss'] //This was added from issue 86

});
Run Code Online (Sandbox Code Playgroud)

这是包存储库中的第 86 号问题

我正在使用letsencrypt,directadmin control panel这是我SSLwebsockets.php配置部分:

    'ssl' => [
    /*
     * Path to local certificate file on filesystem. It must be a PEM encoded file which
     * contains your certificate and private key. It can optionally contain the
     * certificate chain of issuers. The private key also may be contained
     * in a separate file specified by local_pk.
     */
    //'local_cert' => null,
    'local_cert' => '/home/myDomain/domains/myDomain/public_html/vendor/react/socket/examples/localhost.pem',
      //'local_cert' => '/usr/local/directadmin/data/users/myDomain/domains/myDomain.ir.cert',
    /*
     * Path to local private key file on filesystem in case of separate files for
     * certificate (local_cert) and private key.
     */
    //'local_pk' => null,
    'local_pk' => '/usr/local/directadmin/data/users/myDomain/domains/myDomain.ir.key',

    /*
     * Passphrase for your local_cert file.
     */
    'passphrase' => null,
    ],
Run Code Online (Sandbox Code Playgroud)

但是当我使用时php artisan websockets:serve,似乎连接有问题,myDomain.com/laravel-websockets管理面板说:

频道当前状态不可用

控制台说:

Firefox 无法与 wss://myDomain.ir:6001/app/qwerty?protocol=7&client=js&version=4.3.1&flash=false 上的服务器建立连接。

pusher.min.js:8:6335 与 wss://myDomain.ir:6001/app/qwerty?protocol=7&client=js&version=4.3.1&flash=false 的连接在页面加载时中断。

有谁知道我的问题是什么,我应该如何解决这个问题?

小智 0

我遇到了同样的问题,我正在使用 Homestead,你在 homestead 吗?如果是的话,你应该使用 Supervisor(基于 Debian)或 Supervisord(基于 RedHat)操作系统来运行 laravel 套接字,而无需手动输入命令“php artisan websockets:serve “ 每时每刻。

您可以参考这个文档。https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/starting.html#restricting-the-listening-host

对于 SSL,我还使用 Valet 遵循此文档:https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/ssl.html#usage-with-laravel-valet