Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

how to make it work with Laravel Valet --secure #8

Closed
vesper8 opened this issue Dec 5, 2018 · 18 comments
Closed

how to make it work with Laravel Valet --secure #8

vesper8 opened this issue Dec 5, 2018 · 18 comments

Comments

@vesper8
Copy link

vesper8 commented Dec 5, 2018

I am trying to get the demo to work and it is not. I figure it must be because by default all my valet sites use the --secure flag

I get this red error

screenshot 2018-12-05 02 20 45

I went into the websockets.php config file and tried to pass it the crt and key files:

    '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' => '/Users/xxx/.valet/Certificates/laravel-websockets-demo.dev.crt',
        // 'local_cert' => null,

        /*
         * Path to local private key file on filesystem in case of separate files for
         * certificate (local_cert) and private key.
         */
        'local_pk' => '/Users/xxx/.valet/Certificates/laravel-websockets-demo.dev.key',
        // 'local_pk' => null,

        /*
         * Passphrase with which your local_cert file was encoded.
         */
        'passphrase' => null
    ],

This changes the error and is no longer red, but it still doesn't work

screenshot 2018-12-05 02 20 29

@mpociot
Copy link
Member

mpociot commented Dec 5, 2018

When using a local certificate - and not a reverse proxy - you need to set the wssPort property when creating your Pusher / Laravel Echo client:

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: window.location.hostname,
    wsPort: 6001,
    wssPort: 6001,
    encrypted: true,
    disableStats: true,
});

I will update the documentation

@mpociot mpociot closed this as completed Dec 5, 2018
@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

@mpociot

I have added these two lines in the bootstrap.js

    wssPort: 6001,
    encrypted: true,

And I then ran npm install && npm run production in the demo project repository

I still get similar errors as before.

With the default null values of websockets.php as well as the values I showed in my first post. In both cases I still get errors and the realtime doesn't work

Any more help would be appreciated to get this working with Laravel Valet using the --secure flag

Thanks

@mpociot
Copy link
Member

mpociot commented Dec 5, 2018

Oh, my bad. You also need to specify the Laravel Valet CA file and disable certificate validation:

This is what my config file looks like:

'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' => '/Users/marcel/.config/valet/Certificates/laravel-websockets-demo.test.crt',

        /*
         * Path to local private key file on filesystem in case of separate files for
         * certificate (local_cert) and private key.
         */
        'local_pk' => '/Users/marcel/.config/valet/Certificates/laravel-websockets-demo.test.key',

        /*
         * Passphrase with which your local_cert file was encoded.
         */
        'passphrase' => null,

        'verify_peer' => false,

        'cafile' => '/Users/marcel/.config/valet/CA/LaravelValetCASelfSigned.pem',
    ],

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

Sorry to bother you again @mpociot but it still isn't working despite following all your instructions.

I updated to the latest version of Valet (2.1.3) because I think the version I was previously on (2.0.12) wasn't generating these /CA/ files (.pem and .key)

I noticed that doing so changed the default location of my .valet folder tom ~/.valet to ~/.config/valet

All good so far.

From a vanilla git clone of your laravel-websockets-demo, I have added the two extra lines to the bootstrap.js followed by npm install and npm run production

Then I modified my websockets.php to look exactly like yours (but with my username of course)

I pass it the site's .crt and site's .key and I pass it the /CA/LaravelValetCASelfSigned.pem (which there is only one of)

Out of curiosity, I looked for the string 'cafile' in both /vendor/react and ./vendor/beyondcode

And there is no instance of the string 'cafile' anywhere which leads me to believe this may be the wrong key?

I continue to get a websocket connection error as well as another error when I try to type in a message. Here's the error stack for that error

{
    "message": "",
    "exception": "Illuminate\\Broadcasting\\BroadcastException",
    "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php",
    "line": 117,
    "trace": [
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php",
            "line": 48,
            "function": "broadcast",
            "class": "Illuminate\\Broadcasting\\Broadcasters\\PusherBroadcaster",
            "type": "->"
        },
        {
            "function": "handle",
            "class": "Illuminate\\Broadcasting\\BroadcastEvent",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",
            "line": 29,
            "function": "call_user_func_array"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",
            "line": 87,
            "function": "Illuminate\\Container\\{closure}",
            "class": "Illuminate\\Container\\BoundMethod",
            "type": "::"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php",
            "line": 31,
            "function": "callBoundMethod",
            "class": "Illuminate\\Container\\BoundMethod",
            "type": "::"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Container/Container.php",
            "line": 572,
            "function": "call",
            "class": "Illuminate\\Container\\BoundMethod",
            "type": "::"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php",
            "line": 94,
            "function": "call",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 116,
            "function": "Illuminate\\Bus\\{closure}",
            "class": "Illuminate\\Bus\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 104,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php",
            "line": 98,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php",
            "line": 49,
            "function": "dispatchNow",
            "class": "Illuminate\\Bus\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php",
            "line": 83,
            "function": "call",
            "class": "Illuminate\\Queue\\CallQueuedHandler",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Queue/SyncQueue.php",
            "line": 42,
            "function": "fire",
            "class": "Illuminate\\Queue\\Jobs\\Job",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Queue/Queue.php",
            "line": 44,
            "function": "push",
            "class": "Illuminate\\Queue\\SyncQueue",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php",
            "line": 128,
            "function": "pushOn",
            "class": "Illuminate\\Queue\\Queue",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php",
            "line": 280,
            "function": "queue",
            "class": "Illuminate\\Broadcasting\\BroadcastManager",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php",
            "line": 203,
            "function": "broadcastEvent",
            "class": "Illuminate\\Events\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Broadcasting/PendingBroadcast.php",
            "line": 57,
            "function": "dispatch",
            "class": "Illuminate\\Events\\Dispatcher",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/app/Http/Controllers/ChatsController.php",
            "line": 32,
            "function": "__destruct",
            "class": "Illuminate\\Broadcasting\\PendingBroadcast",
            "type": "->"
        },
        {
            "function": "sendMessage",
            "class": "App\\Http\\Controllers\\ChatsController",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "call_user_func_array"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 45,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 212,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 169,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 682,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 30,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 41,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
            "line": 43,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Auth\\Middleware\\Authenticate",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php",
            "line": 75,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php",
            "line": 49,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\View\\Middleware\\ShareErrorsFromSession",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php",
            "line": 63,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Session\\Middleware\\StartSession",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php",
            "line": 37,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php",
            "line": 66,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\EncryptCookies",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 104,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 684,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 659,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 625,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 614,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 176,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 30,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 31,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 31,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
            "line": 62,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 151,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php",
            "line": 53,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 104,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 151,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 116,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/DEV/websockets-demo/public/index.php",
            "line": 55,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/Users/vesperknight/.composer/vendor/laravel/valet/server.php",
            "line": 151,
            "function": "require"
        }
    ]
}

Your help is appreciated. Thanks

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

The laravel-websockets dashboard also needs to have its code modified in order to be able to connect to this server.. like so:

        methods: {
            connect() {
                this.pusher = new Pusher(this.app.key, {
                    wsHost: window.location.hostname,
                    wsPort: this.port,
                    wssPort: 6001,
                    encrypted: true,
                    disableStats: true,
                    authEndpoint: '/{{ request()->path() }}/auth',
                    auth: {
                        headers: {
                            'X-CSRF-Token': "{{ csrf_token() }}"
                        }
                    },
                    enabledTransports: ['ws', 'flash']
                });

Same two lines need to be added.. except that this is a vendor file so.. it probably requires a configuration switch

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

Ok so to recap.. at this point this is my bootstrap.js

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    wsHost: window.location.hostname,
    wsPort: 6001,
    wssPort: 6001,
    encrypted: true,    
    disableStats: true,
});

I've rebuilt the app.js

This is in my websockets configuration file

    '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' => '/Users/xxx/.config/valet/Certificates/websockets-demo.dev.crt',

        /*
         * Path to local private key file on filesystem in case of separate files for
         * certificate (local_cert) and private key.
         */
        'local_pk' => '/Users/xxx/.config/valet/Certificates/websockets-demo.dev.key',

        /*
         * Passphrase with which your local_cert file was encoded.
         */
        'passphrase' => null,

        'verify_peer' => false,

        'cafile' => '/Users/xxx/.config/valet/CA/LaravelValetCASelfSigned.pem',
    ],

I am now seeing activity in the console, as well as the dashboard, when I load the page, and also when I'm typing in the message field.. so we're almost there.

I am also now seeing both chat participants, and I can see the typing indicator, on the chat page itself.. so nearly everything works

But when I actually submit a message, I get an error 500 on /messages with the long error I posted above.

@mpociot
Copy link
Member

mpociot commented Dec 5, 2018

Out of curiosity, I looked for the string 'cafile' in both /vendor/react and ./vendor/beyondcode
And there is no instance of the string 'cafile' anywhere which leads me to believe this may be the wrong key?

That's because internally we just pass the complete ssl configuration array to create the secure socket. The configuration keys available are from PHP itself - see http://php.net/manual/en/context.ssl.php

Okay - so now you got the websocket connection working but when Laravel tries to broadcast messages to the WebSocket server, it is still using http as a protocol - not https.
You can change this by modifying your config/broadcasting.php file - see https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/ssl.html#server-configuration

Specifically you need to change the scheme to https.

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

I was just about to come here and write that after reading the docs, I noticed that I had forgotten this step.. so I did do that, changed the scheme to https.. cleared my config cache and restarted my websockets serve.. unfortunately that does not solve the problem..

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

and yea I read the context options and understood that's why I couldn't find a reference to 'cafile'

I also tried adding a few other options
verify_peer_name => false
and
allow_self_signed => true

unfortunately that didn't help, I have since commented those back out

@mpociot
Copy link
Member

mpociot commented Dec 5, 2018

@vesper8 okay...did some more digging in the Pusher PHP SDK code.

Since the Valet certificate is self-signed we need to tell the Pusher SDK to ignore the certificate checking.

You can do this using these options in your 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' => true,
        'host' => '127.0.0.1',
        'port' => 6001,
        'scheme' => 'https',
        'curl_options' => [
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_SSL_VERIFYPEER => 0,
        ]
    ],
],

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

amazing! victory!! That solved it. Thanks Marcel!

Hope this helps others that use Valet and want to test things under https so there's no surprises when they goto production

So now the docs can be improved with these details.

And the issue of the dashboard needing modification "laravel-websockets/resources/views/dashboard.blade.php" this needs to be addressed.. probably through a configuration switch?

two small things I noticed that could also be improved in regards to the laravel-websockets debug dashboard. The dropdown should select an app by default so the user can just click 'connect' right away, currently it is left blank even if there's only one item

And when events such as App\Events\MessageSent are fired and shown in the debug dashboard.. it would be nice to be able to inspect the payload.. Pusher's dashboard lets you do that

Cheers!! Thanks for this awesome contribution!!

@mpociot
Copy link
Member

mpociot commented Dec 5, 2018

I'm already adding a Valet section for the SSL configuration of the documentation :)

And the issue of the dashboard needing modification "laravel-websockets/resources/views/dashboard.blade.php" this needs to be addressed.. probably through a configuration switch?

I'll just add wssPort: this.port in there. The Pusher client automatically detects if it's running with https and switches to wss then. So it should also work for you if you remove the encrypted settings.

two small things I noticed that could also be improved in regards to the laravel-websockets debug dashboard. The dropdown should select an app by default so the user can just click 'connect' right away, currently it is left blank even if there's only one item

Good catch. Fixed it.

And when events such as App\Events\MessageSent are fired and shown in the debug dashboard.. it would be nice to be able to inspect the payload.. Pusher's dashboard lets you do that

Yeah..still needs to be added :)

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

By the way, now that I have it working, I wanted to see which settings I could remove. And it turns out the 'cafile' => .pem is not needed inside the websockets.php

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

I also noticed that with the demo, the stats don't seem to be working. I even tried setting disableStats to false in case that was related. The websockets_statistics_entries never gets any record added to it and the graph never gets any data, despite having two active connections for many minutes and many messages sent

also.. doesn't the snapshot every 60 second require a scheduled command to be added? similar to how Laravel Horizon does it for snapshots

@mpociot
Copy link
Member

mpociot commented Dec 5, 2018

Is your APP_URL correct?
The 60 second snapshot works internally inside of the WebSocket server. The WebSocket server actually performs a POST request using the APP_URL to the actual Laravel application. See https://github.com/beyondcode/laravel-websockets/blob/master/src/Console/StartWebSocketServer.php#L59-L61

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

My APP_URL was not set correctly in .env

I have set it now too APP_URL=https://websockets-demo.dev which is correct

I've been watching it for over two minutes, with two connected users in the chatroom and many messages sent between the two.. and there hasn't been any stat records added to the table or activity on the graph

do I need to set disabledStats to false in either the dashboard.blade.php or the bootstrap.js ?

@mpociot
Copy link
Member

mpociot commented Dec 5, 2018

Mh no - it's the same issue. The internal POST request from the WebSocket Server to Laravel fails because of the self-signed certificate. You can't modify this right now, so we will have to fix that.

@vesper8
Copy link
Author

vesper8 commented Dec 5, 2018

sweet. thanks! keep up the fine work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants