Websockets for Laravel. Done right.

Overview

Laravel WebSockets 🛰

Latest Version on Packagist GitHub Workflow Status Quality Score Total Downloads

Bring the power of WebSockets to your Laravel application. Drop-in Pusher replacement, SSL support, Laravel Echo support and a debug dashboard are just some of its features.

https://phppackagedevelopment.com

If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming PHP Package Development video course.

Documentation

For installation instructions, in-depth usage and deployment details, please take a look at the official documentation.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • [2.x] Major refactoring

    [2.x] Major refactoring

    Rewritten from scratch

    The project got re-written from scratch as stated the reasons in https://github.com/beyondcode/laravel-websockets/pull/519

    The contributors are going to remain the same, including @francislavoie with the awesome starting point to horizontally-scale the running servers.

    Rewrite changelog

    • The migration file suffered a small modification. Run vendor:publish to get the second migration file that changes the fields to plural.
    • The configuration file got itself re-written as well with simplicity in mind (the initial 2.x was still a mess). Get a new copy of it.
    • Interfaces moved to Beyondcode\LaravelWebSockets\Contracts\*. If you extend certain functionalities, makes sure to use the right namespaced interfaces.
    • The replication driver is now called replication mode. Env's WEBSOCKETS_REPLICATION_MODE variable now can be set to local or redis.
    • Replicators got merged into Channel Managers. If you added your own custom replicator, you now should implement the BeyondCode\LaravelWebSockets\Contracts\ChannelManager interface.
    • Statistics Loggers are now called Statistics Collectors. Their job is to temporarily store the data between dumps into the database (by default).
    • Handlers for the WebSocket, as well as the HTTP API Server, got re-written. They are still found in the config, but make sure to check them if you extend one of them.
    • The vast majority functions of the channel managers now use PromiseInterfaces for consistencies. This means that instead of returning int or strings, you may now return a FulfilledPromise($value) to easily get resolved. If you don't implement your own channel manager (or now defunct, replicator), it's totally fine.
    • Presence channels now properly trigger the .here() methods.
    • Dashboard got broadcasting fixes. If you still encounter issues with sending events from the dashboard, open an issue.

    Pre-Rewrite changelog

    • [x] Restructured the config file (https://github.com/beyondcode/laravel-websockets/pull/446)
    • [x] ~Redis PubSub driver support for Horizontally-scaled WebSocket servers (https://github.com/beyondcode/laravel-websockets/pull/140, https://github.com/beyondcode/laravel-websockets/pull/448, https://github.com/beyondcode/laravel-websockets/pull/477, https://github.com/beyondcode/laravel-websockets/commit/5b6bdf49e46eead770d8cbab0ed7db53849561f3)~ Rewritten, Channel Managers now do all the jobs on tracking the channels and connections
    • [x] Rename the AppProvider to AppManager to avoid conflicts with Larave's App Providers (https://github.com/beyondcode/laravel-websockets/pull/451)
    • [x] Remove Laravel 5.8.x (https://github.com/beyondcode/laravel-websockets/pull/452)
    • [x] ~Extendable hooks as in https://github.com/beyondcode/laravel-websockets/issues/80 (https://github.com/beyondcode/laravel-websockets/pull/465, https://github.com/beyondcode/laravel-websockets/commit/3e239a0728bb37f613e5abe7015843cd089669cb)~ The extendable hooks' place in config file got changed. Get a new copy of the config file.
    • [x] Refactor dashboard with Tailwind (https://github.com/beyondcode/laravel-websockets/pull/467)
    • [x] Add per-app CORS settings (https://github.com/beyondcode/laravel-websockets/pull/469)
    • [x] ~Docblocks (https://github.com/beyondcode/laravel-websockets/pull/471)~ Rewritten from scratch.
    • [x] ~Custom statistics loggers (including the already-provided Database using ORM) (https://github.com/beyondcode/laravel-websockets/pull/473, https://github.com/beyondcode/laravel-websockets/pull/482/commits/714cc5b22def3da5f1ef8da23b2c89cd0af42d87, https://github.com/beyondcode/laravel-websockets/pull/482/commits/108a717c0af82f5f04e8164a13211b3c36dcc401)~ Statistics Loggers now are called Statistics Collectors and their job is to store the data temporarily between dumps. When the amount of time in seconds pass, they are dumped into a Statistics Store. Defaults to Database.
    • [x] ~More use cases tests (https://github.com/beyondcode/laravel-websockets/pull/450, https://github.com/beyondcode/laravel-websockets/pull/453, https://github.com/beyondcode/laravel-websockets/pull/464, https://github.com/beyondcode/laravel-websockets/pull/482)~ TDD-ed the entire project while keeping in mind the functionality tests.
    • [x] Update docs to reflect changes (https://github.com/beyondcode/laravel-websockets/pull/468)
      • [x] Using WebSockets with Cloudflare (does not support 6001 as default port)
      • [x] Setting up the websockets broadcaster for the horizontal scaling function
      • [x] Restarting the server with websockets:restart
    opened by rennokki 126
  • Redis as a replication backend for scalability

    Redis as a replication backend for scalability

    This is a continuation of @snellingio's work in #61 and supersedes it.

    Disclaimer: this is still WIP, I still have some work to do here before it's ready to go.

    Things that are done:

    • Some general cleanup I fixed some typos here and there, added some additional type hints to make my IDE happy, added @mixin on Facades, etc.
    • Rewrote RedisClient to use lazy clients (thanks @WyriHaximus for implementing that feature!) and implemented pub/sub.
    • If client push is enabled, that should also work, via publishing to Redis. RedisClient will ignore messages from itself.
    • RedisPusherBroadcaster is implemented. This is a hybrid of the Redis and Pusher broadcasters that are shipped with Laravel. This is needed because we still want to use the Pusher auth logic (signing the broadcasted messages) but we want to broadcast via Redis instead of doing an HTTP request to the websocket server to push out messages.
    • Pub/sub logic is implemented under a feature flag in config, it gets checked at every entry-point into replication logic. This means that nothing should change for users that don't need replication
    • Scope the pub/sub channels on Redis by app ID This is needed so that channels from different apps don't cross-talk when they aren't supposed to. This is done in the Broadcaster and RedisClient. Redis channels are names "$appId:$channel" wherever needed.
    • Implement storing Presence Channel information in Redis This one was tricky, because among other things, it required rewriting some of the HTTP controller logic to support Redis' async IO. The replication feature flag complicates this a bit as well because we end up with two code paths throughout, wherever it's enabled. I'll probably need the most help reviewing this portion due to its complexity.
    • Tests I went the route of extending some of the existing tests, only running the tests with replication enabled as well, to hit the relevant code paths. RedisClient is not covered, a LocalClient mock is used instead.
    • Just a note: I found that it doesn't make sense to put any of the logic in the channel manager (e.g. RedisChannelManager) because it doesn't itself do anything. Channel and PresenceChannel are where the interesting things happen. Maybe these classes could be split up into replicated versions of each, but it doesn't seem entirely necessary yet.

    Things that are still to do:

    • Improve reliability via Redis reconnect logic In case Redis goes down, RedisClient should attempt to reconnect, and if successful, should re-subscribe to all the channels on behalf of the users. This shouldn't be too hard, there's already local storage for the list of channels (see protected $subscribedChannels in RedisClient)
    • Documentation We'll need new sections in the documentation to describe how to set this up. Notably, users will need to add a new driver in broadcasting.php due to the hybrid broadcaster I implemented.
    enhancement help wanted 
    opened by francislavoie 60
  • Multiple App Servers & Load Balancer Help

    Multiple App Servers & Load Balancer Help

    Hello, I'm just after clarification or pointers on how best to approach laravel-websockets with my setup. I run all my servers under Laravel Forge and I use their load balancers which is a Nginx server with a reverse proxy.

    My setup is 1 load balancer, 4 app servers (same codebase), a dedicated MySQL and a dedicated Redis server. Previously I ran Laravel Echo Server on the same server as the Redis DB and the 4 app servers were able to communicate, however my project now needs sockets on mobile which lead me here due to the Pusher SDK implementation.

    I'm wondering how best to deploy laravel-websockets with my app. Should I run a dedicated server instance with only laravel-websockets and proxy all 4 servers there so there's a single websockets server on a subdomain or should each of the 4 app servers be running websockets:serve ?

    I do intend to use Redis once v2 is ready, however I am still wondering which of the 2 solutions would be best?

    bug 
    opened by AugmentBLU 57
  •  WebSocket connection to 'wss://mydomain:6001/app/1234567890?protocol=7&client=js&version=5.0.2&flash=false' failed: Error in connection establishment: net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH

    WebSocket connection to 'wss://mydomain:6001/app/1234567890?protocol=7&client=js&version=5.0.2&flash=false' failed: Error in connection establishment: net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH

    I'm getting this error. Its killing my time. I dig deep and found no proper solution for this issue. in **LOCAL SERVER its working fine **. but in LIVE SERVER this issue arises.

    I put 'local_pk' and 'local_cert' both path inside websockets.php file

    its my app.js file

    window.Echo = new Echo({ broadcaster: 'pusher', key: '1234567890', wsHost: window.location.hostname, wsPort: 6001, encrypted: false, wssPort: 6001, disableStats: true, enabledTransports: ['ws', 'wss'], });

    here is my broadcasing.hp config

    'connections' => [
    
        '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'),
                'host' => '127.0.0.1',
                'encrypted' => false,
                'port' => 6001,
                'scheme' => 'https',
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ]
            ],
        ],
    

    PLEASE HELP ME OUT.

    opened by fahim152 43
  • [Proposal] Change of Websocket implementation

    [Proposal] Change of Websocket implementation

    Hi BeyondCode. Love your stuff.

    Things I don't like is stuff with many issues. Seems that some upstream dependencies are creating a lot of havoc regarding the WebSocket Server.

    There is a pure PHP implementation of WebSockets that uses concurrency, created by the guys of amphp, the same group who figured out Fibers. It seems stable.

    I may create a PR that exchanges the upstream dependencies for that, which may fix a lot of problems thanks to the bloated dependency list.

    opened by DarkGhostHunter 39
  • Crashed in production, supervisord process was still running

    Crashed in production, supervisord process was still running

    So basically it stopped working, even though the process in supervisord was showing up as running (since 60 days). After I restarted the process with supervisord it worked again. What could have happened and how could I avoid this in the future?

    bug help wanted good first issue 
    opened by Hillcow 38
  • Invalid auth signature provided Exception

    Invalid auth signature provided Exception

    So I have a search engine built into my app that fetches results from multiple sources from across the web from different engines and broadcasts the results in real-time as we get a response.

    I was using laravel-echo-server earlier and it was all good. I migrated to this package and have been facing this issue. At first, I thought it could be a third-party issue and tested the APIs and everything else but it seems like everything is fine at that end but when it's broadcasting results in a loop, it shows this error for few broadcasts.

    What you think could be breaking the flow and causing this issue? I'm sending JSON payload of results after we've parsed and transformed as per the format we need on the front-end.

    Exception `Symfony\Component\HttpKernel\Exception\HttpException` thrown: `Invalid auth signature provided.`
    
    opened by irazasyed 37
  • SSL

    SSL

    Hi There, First of all, thank you for a great plugin.

    I have looked at the other questions regarding SSL and none seem to cover my scenario.

    I am having an issue with Self Signed SSL Certificates. I have created them with this command : openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 I then set the broadcasting.php as follows :

    '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' => 'sockets.myDomainHere.com',
                    'port' => 6001,
                    'scheme' => 'https',
                    'curl_options' => [
                        CURLOPT_SSL_VERIFYHOST => 0,
                        CURLOPT_SSL_VERIFYPEER => 0,
                    ]
                ],
            ],
    

    I Then Set the websockets.php as follows ( comment removed for size ):

    'ssl' => [ 
            'local_cert' => '/full/path/to/self/signed/cert.cert',
            'local_pk' => '/full/path/to/self/signed/key.key', 
            'passphrase' => 'ThePassphraseIEnteredWhenCreatingTheCertificate',
            'verify_peer' => false,
        ],
    

    On my client I have it as follows :

    new Echo({ 
            auth:{ headers: { 'Authorization': 'Bearer ' + user.token } },
            broadcaster: 'pusher',
            key: '123456',
            wsHost: 'sockets.myDomainHere.com',
            wsPort: 6001,
            wssPort: 6001,
            disableStats: true, 
            enabledTransports: ['ws', 'wss']
        });
    

    So I have 2 issues :

    1. If I go to the Debug Dashboard I cannot connect to the Server ERROR :

    pusher.min.js:8 WebSocket connection to 'ws://sockets.myDomainHere.com:6001/app/123456?protocol=7&client=js&version=4.3.1&flash=false' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

    1. If I go to my app frontend, I get this :

    WebSocket connection to 'wss://sockets.myDomainHere.com:6001/app/123456?protocol=7&client=js&version=4.3.1&flash=false' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID

    Any feedback will be great, Thanks.

    opened by cbezzy 33
  • Websockets not working with pusher-php-server 7.2

    Websockets not working with pusher-php-server 7.2

    Hello, after pusher-php-server has been updated to version 7.2 websockets stopped working. I'm using Laravel Echo and the initial connection to private channel is successful, but then I'm not getting any events broadcasted on that channel. With pusher-php-server 7.0.2 everything works fine. Is the new version incompatible with Laravel Websockets and should I wait for an update?

    opened by szabrzyski 32
  •  Illuminate \ Broadcasting \ BroadcastException No message

    Illuminate \ Broadcasting \ BroadcastException No message

    First of all thank you for your great work.

    I'm using your package for a few days and after some test, I could connect to my dashboard with connection to websocket.

    In next step I create an event name NewQuestion that have a very simple event for test:

    class NewQuestion implements ShouldBroadcast
    {
        use Dispatchable, InteractsWithSockets, SerializesModels;
    
        public $message;
        /**
         * Create a new event instance.
         *
         * @return void
         */
        public function __construct($message)
        {
            $this->message = $message;
        }
    
        /**
         * Get the channels the event should broadcast on.
         *
         * @return \Illuminate\Broadcasting\Channel|array
         */
        public function broadcastOn()
        {
            return new PrivateChannel('moderator');
        }
    }
    

    When I simply call my event after new question store in QuestionController , laravel says:

    Illuminate \ Broadcasting \ BroadcastException No message

    and this is part of laravel report:

       $response = $this->pusher->trigger(
            $this->formatChannels($channels), $event, $payload, $socket, true
        );
    
        if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
            || $response === true) {
            return;
        }
    
        throw new BroadcastException(
            is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
        );
    }
    
    /**
     * Get the Pusher SDK instance.
     *
     * @return \Pusher\Pusher
     */
    public function getPusher()
    {
        return $this->pusher;
    }
    

    }

    Would you please let me know what wrong in my case?

    my configurations:

    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'
                ],
            ],
    

    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,
            ],
        ],
    .
    .
    .
              'local_cert' => '/home/myDomain/domains/myDomain.com/private_html/local.cert',
    .
    .
    .
            'local_pk' => '/home/myDomain/domains/myDomain.com/private_html/key.cert',
    .
    .
    .
    
    
    opened by sanjarani 31
  • pusher-js did not reconnect after the 2nd offline situation ...

    pusher-js did not reconnect after the 2nd offline situation ...

    First i will thank you very much for this Product. Wow!

    We have a major Problem with our "little" websocket setup. Each time, (or better to say, after the 2nd Energy-Saver time of my Mobile Phone , my vue.js web-app failed to receive websocket events.

    Our old Setup .. with the node.js based laravel-websocket-service / socket-io transport inside the frontend client was working over a year without this effect. So i started to investigate:

    • The laravel-echo javascript library is unchangend .. so there is not the problem.
    • The major change is the pusher-js bridge (instead of the socket-io).

    TLdr .. the pusher-js (version 4.4.x) is only reconnection 1 times on your laravel-websocket server after a (short) offline situation. This is also testable with firefox-dev there is a "offline-switch" ..

    After the first "breakdown" it reconnects very fine ... your server is opening a new connection .. and voila ..

    After the next offline-breakdown , the pusher-js is not re-connecting by websocket (ws or wss) it is preffering a xhr-streaming connection .. (this can be forbidden by:

    disabledTransports: ['sockjs', 'xhr_polling', 'xhr_streaming'],

    but .. if those transports are disabled .. it stops with re-connecting ..

    I tested many variants of pusher-js connection params .. lastly ending with this list of "rules" ..

    encrypted: true, wsHost: process.env.ECHO_SERVER_PUSHER, wssHost: process.env.ECHO_SERVER_PUSHER, httpHost: process.env.ECHO_SERVER_PUSHER, forceTLS: true, httpPort: 443, httpsPort: 443, wsPort: 443, wssPort: 443, // enabledTransports: ['ws', 'wss'], disabledTransports: ['sockjs', 'xhr_polling', 'xhr_streaming'], disableStats: true

    but .. the pusher-js has his own rules (maybe .. because .. your product .. is tooo good ;-) ) ..

    So .. if you want to be "pusher-js" free (it makes also sense, because you are digging with your product against their product) .. maybe you should take a look onto socket-io .. or ..

    Or implement a xhr-streaming fallback possibility ..

    With pusher-js directly on pusher.com it works without any problems, because they have the fallback transport mechanism .. so there is no breakdown ..

    But with this limitation, its a showstopper ..

    opened by ibrainventures 28
  • Laravel 9 & PHP 8

    Laravel 9 & PHP 8

    I've upgraded from Laravel 8 & PHP 7.3 to Laravel 9 & PHP 8. However, WebSocket is not working after the update.

    Below is the version currently installed: "beyondcode/laravel-websockets": "1.13.1", "pusher/pusher-php-server": "7.2.1", "guzzlehttp/guzzle": "7.5.0"

    Pusher Log: Pusher : : ["State changed","connecting -> unavailable"]

    WebSocket request: URL: wss://test.com/app/ABCDEFG?protocol=7&client=js&version=7.0.3&flash=false Message: WebSocket is closed before the connection is established.

    The site has a valid SSL Certificate.

    can you guide me on how can I resolve this issue?

    opened by kailasb10 0
  • auth:api middleware not working for Laravel broadcasting routes

    auth:api middleware not working for Laravel broadcasting routes

    Hi I am using laravel passport to protect my api routes. I am using Beyondcode's laravel websockets package for my socket server. My goal is to access my broadcasting routes for broadcasting only on a token bases.

    Here is my BroadcastServiceProvider

    <?php
    
    namespace App\Providers;
    
    use Illuminate\Support\Facades\Broadcast;
    use Illuminate\Support\ServiceProvider;
    
    class BroadcastServiceProvider extends ServiceProvider
    {
        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot()
        {
            //Broadcast::routes();
            Broadcast::routes(["middleware" => "auth:api"]);
            require base_path('routes/channels.php');
    
    opened by yktibrahim 0
  • Close WebSocket on Server-Side

    Close WebSocket on Server-Side

    Hi there!

    Is it possible to actively close a WebSocket connection from server-side?

    I see that connections are for instance closed in case an error occurs: https://github.com/beyondcode/laravel-websockets/blob/fb958fb851e75fab9b39a11b88bd7c52e1dd80e0/src/API/Controller.php#L137

    The underlying Ratchet lib supports to close connections via $conn->close(); (as can be seen above): https://github.com/ratchetphp/Ratchet/

    I need to terminate the connection in case a user is logged out from the application (e.g. a session timeout occurs) but there is no reload.

    Thank you very much in advance! Best regards, Lauritz

    opened by lauritzh 1
  • Laravel Websocket package issue with the latest Laravel, pusher, and Echo package

    Laravel Websocket package issue with the latest Laravel, pusher, and Echo package

    I am working on Laravel 9 where I install Laravel WebSocket, Laravel Echo, and Pusher PHP server.

    By the way, I didn't use the official Pusher application, just using the package as per Laravel-WebSocket package documentation suggested.

    User case - I want to update the site model value and send a notification (broadcast and mail) to the end user as soon as the user deletes a site.

    Everything is installed and working fine but I found some glitches in the Laravel-WebSocket, Pusher package.

    I have created the following event which will broadcast to the end user.

    SiteDelete.php

    <?php
    
    namespace App\Events;
    
    use App\Models\Site;
    use Illuminate\Broadcasting\Channel;
    use Illuminate\Broadcasting\InteractsWithSockets;
    use Illuminate\Broadcasting\PresenceChannel;
    use Illuminate\Broadcasting\PrivateChannel;
    use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
    use Illuminate\Foundation\Events\Dispatchable;
    use Illuminate\Queue\SerializesModels;
    
    class SiteDeleted implements ShouldBroadcast
    {
        use Dispatchable, InteractsWithSockets, SerializesModels;
    
        /**
         * The site instance.
         *
         * @var \App\Models\Site
         */
        public $site;
    
        /**
         * The name of the queue connection to use when broadcasting the event.
         *
         * @var string
         */
        public $connection = 'database';
        
        /**
         * The name of the queue on which to place the broadcasting job.
         *
         * @var string
         */
        public $queue = 'default';
    
        /**
         * Create a new event instance.
         *
         * @return void
         */
        public function __construct(Site $site)
        {
            $this->site = $site;
        }
    
        /**
         * Get the channels the event should broadcast on.
         *
         * @return \Illuminate\Broadcasting\Channel|array
         */
        public function broadcastOn()
        {
            // return new PrivateChannel('site.delete.'.$this->site->id); // this is not working.
            // return [new PrivateChannel('site.delete.'.$this->site->id)]; // this is not working.
            return [new PrivateChannel('site.delete.'.$this->site->id), new Channel('mock')]; // This will call but I need to pass two channels intentionally.
        }
    
        /**
         * Get the data to broadcast.
         *
         * @return array
         */
        public function broadcastWith()
        {
            return ['id' => $this->site->id];
        }
    }
    

    app.js

    Echo.private("site.delete.1")
    .listen('SiteDeleted', (e) => {
        console.log("SiteDeleted");
        console.log(JSON.stringify(e));
    })
    
    Echo.private('App.Models.User.7')
    .notification((notification) => {
        console.log("App.Models.User");
        console.log(notification);
    });
    

    Problem

    • As you can see comments in my event class's broadcastOn method where I need to pass two channels. One is real and the second one is fake. So ultimately you need to pass at least two channels so the pusher request will have a channels parameter [which will work] but the channel parameter never works[i.e when you pass a single channel].
    • I can able to send custom events from the WebSocket GUI. i.e from http://localhost:8000/laravel-websockets URL. but those events are never caught by the front end unless I do it the dirty way.
    • The notifications are never caught by the front end due to this channel and channels parameter issue.

    Dirty Way[Yes I know we should never touch the vendor folder but just curious to know why the things are not working]

    • I checked the vendor folder very deeply and I come to know, in the vendor/pusher/pusher-php-server/src/Pusher.php under the make_event function if I update the following line then it starts working without passing two channels.

    vendor/pusher/pusher-php-server/src/Pusher.php

    private function make_event(array $channels, string $event, $data, array $params = [], ?string $info = null, bool $already_encoded = false): array
    {
        // if (count($channel_values) == 1) {
        //   $post_params['channel'] = $channel_values[0];
        // } else {
        //   $post_params['channels'] = $channel_values;
        // }
    
        $post_params['channels'] = $channel_values;
    }
    

    My Research

    • As the WebSocket package suggests installing pusher-php-server version 3.0 but I install the latest one i.e 7. Version 3.0 is incompatible with Laravel 9. But I can't and don't want to install the older version.
    • I think the WebSocket package is not able to send the event and data on a single channel with a newer version of pusher-php-server.
    • I can't raise an issue (or blame it) for Pusher SDK because we are just replacing the package and I think the Pusher SDK package is working fine when you use their credentials(ie. you have to create an app on Pusher).
    • Even if you can check on the WebSocket dashboard i.e http://localhost:8000/laravel-websockets when you send the event it will never catch in the front end. But as soon as you update the Pusher.php file it starts catching an event on the front end.
    • due to the above reason, as you know the notification are sent to the user on their private channels, So I can't add a mock channel for notification as I did for my event, so notification will never catch by the frontend application.

    composer.json

    "beyondcode/laravel-websockets": "^1.13",
    "pusher/pusher-php-server": "^7.2",
    "laravel/framework": "^9.19",
    

    package.json

    "pusher-js": "^7.5.0",
    "laravel-echo": "^1.14.2",
    

    I tried the explicit way as well i.e using the pusher SDK's functions[which are giving 200 status code] but not working. As soon as I do it the dirty way it starts working, I mean everything starts working without any issue.

    public function pusherTesting(Request $request)
    {
        $path = "/apps/123456/events";
        $settings = [
            'scheme' => 'http',
            'port' => '6001',
            'path' => '',
            'timeout' => '30',
            'auth_key' => '1b5d6e5b1ab73b',
            'secret' => '3739db6a99c1ba',
            'app_id' => '123456',
            'base_path' => '/apps/123456',
            'host' => '127.0.0.1',
        ];
        $params = [];
        
        $body = '{"name":"Illuminate\\Notifications\\Events\\BroadcastNotificationCreated","data":"{\"site_id\":1,\"domain_url\":\"yucentipede-tuvo.blr3.instawp-testing.xyz\",\"save\":\"socket\",\"id\":\"2f53aac0-8d83-45f4-962d-516c1c8bc97c\",\"type\":\"App\\\\Notifications\\\\SiteDeletedNotification\"}","channels":["private-App.Models.User.7"]}';
    
        $params['body_md5'] = md5($body);
    
        $params_with_signature = \Pusher\Pusher::build_auth_query_params(
            $settings['auth_key'],
            $settings['secret'],
            'POST',
            $path,
            $params
        );
    
        $headers = [
            'Content-Type' => 'application/json',
            'X-Pusher-Library' => 'pusher-http-php 7.2.1'
        ];
    
        $client = new \GuzzleHttp\Client();
    
        try {
            $response = $client->post(ltrim($path, '/'), [
                'query' => $params_with_signature,
                'body' => $body,
                'http_errors' => false,
                'headers' => $headers,
                'base_uri' => 'http://127.0.0.1:6001'
            ]);
        } catch (Exception $e) {
            print_r($e->getMessage());
        }
        $response_body = json_decode($response->getBody(), false, 512, JSON_THROW_ON_ERROR);
    
        echo $status = $response->getStatusCode();
        die;
    
    }
    
    opened by sachinkumar121 5
  • Error 404 with wss -Events Not fired

    Error 404 with wss -Events Not fired

    I have the same issue mentioned in this issue https://github.com/beyondcode/laravel-websockets/issues/847

    In a local environment with HTTP, it works well. but in production client echo connecting and laravel-websockets dashboard loading but events from the server side are not triggering. Getting 404 error in laravel log

    opened by codetestmg 0
Releases(1.13.2)
  • 1.13.2(Dec 14, 2022)

    What's Changed

    • Make TriggerEventController accept both 'channel' and 'channels'. by @madpilot78 in https://github.com/beyondcode/laravel-websockets/pull/1046

    New Contributors

    • @madpilot78 made their first contribution in https://github.com/beyondcode/laravel-websockets/pull/1046

    Full Changelog: https://github.com/beyondcode/laravel-websockets/compare/1.13.1...1.13.2

    Source code(tar.gz)
    Source code(zip)
  • 1.13.1(Mar 3, 2022)

    What's Changed

    • [1.x] fix PHP 8.1 deprecation notice by @afilippov1985 in https://github.com/beyondcode/laravel-websockets/pull/918
    • [1.x] Update pusher/pusher-php-server versions by @joecampo in https://github.com/beyondcode/laravel-websockets/pull/955

    New Contributors

    • @afilippov1985 made their first contribution in https://github.com/beyondcode/laravel-websockets/pull/918

    Full Changelog: https://github.com/beyondcode/laravel-websockets/compare/1.13.0...1.13.1

    Source code(tar.gz)
    Source code(zip)
  • 1.13.0(Feb 14, 2022)

    What's Changed

    • Fix missing wssPort for SSL example by @stayallive in https://github.com/beyondcode/laravel-websockets/pull/776
    • patch: Content-Length header on connection and error responses by @Zortrox in https://github.com/beyondcode/laravel-websockets/pull/866
    • [1.x] Fix call to deprecated JsonResponse::create() by @joecampo in https://github.com/beyondcode/laravel-websockets/pull/947
    • Laravel 9 support by @diegotibi in https://github.com/beyondcode/laravel-websockets/pull/948

    New Contributors

    • @Zortrox made their first contribution in https://github.com/beyondcode/laravel-websockets/pull/866

    Full Changelog: https://github.com/beyondcode/laravel-websockets/compare/1.12.0...1.13.0

    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.37(Feb 14, 2022)

  • 2.0.0-beta.36(Apr 6, 2021)

  • 2.0.0-beta.35(Apr 6, 2021)

  • 1.12.0(Apr 6, 2021)

  • 2.0.0-beta.34(Mar 30, 2021)

    • Removed higher-order messages in favor of callbacks (https://github.com/beyondcode/laravel-websockets/pull/708, https://github.com/beyondcode/laravel-websockets/commit/1bb727f322cac0241b6a405ebc8024416fd5c9a9)
    Source code(tar.gz)
    Source code(zip)
  • 1.11.1(Mar 2, 2021)

  • 1.11.0(Feb 25, 2021)

  • 2.0.0-beta.33(Feb 24, 2021)

    • Support for php-pusher ^5.0 (https://github.com/beyondcode/laravel-websockets/pull/698, https://github.com/beyondcode/laravel-websockets/commit/efb3aa82b9be93fcdabc1c7e089ab6d2d0aa63d5)
    • Fixed a bug that needed force release of the lock for Array manager (https://github.com/beyondcode/laravel-websockets/pull/696)
    Source code(tar.gz)
    Source code(zip)
  • 1.10.0(Feb 24, 2021)

  • 2.0.0-beta.32(Dec 7, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Reverted key typo (https://github.com/beyondcode/laravel-websockets/pull/447/commits/6be62b149dfeb45b0a5dac52cf38d02a9b9f23ee)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.31(Dec 7, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Fix promise fulfillment when the app is not existent (https://github.com/beyondcode/laravel-websockets/commit/dc91eb4db37a33a2aeb220b41e41e287a95282f8)
    • Fixed key typo that lead to wrong statistics after activity stops (https://github.com/beyondcode/laravel-websockets/commit/0e48bb49445572d9d9d2d20b1f8560ffbe0a12a6)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.30(Nov 20, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Reverted deprecation of Laravel 6.x and PHP 7.2
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.28(Nov 20, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Deprecated Laravel 6.x and PHP 7.2
    • Fixed Redis replication configuration issues (https://github.com/beyondcode/laravel-websockets/commit/cafd21a0da29c84faa4e208a4c52c54b74678b42, https://github.com/beyondcode/laravel-websockets/commit/904a97c76fac3cafd9cca1f2697d55324b6b1036)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.27(Nov 16, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Fixed Queue namespacing (https://github.com/beyondcode/laravel-websockets/pull/611)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.26(Oct 18, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Dispatching events on actions. Previously they were thought they caused blocking I/O, but a separate queue driver for async Redis is available from -beta.25 for listeners, if needed (https://github.com/beyondcode/laravel-websockets/pull/556)
    • Added missing DashboardLogger calls (https://github.com/beyondcode/laravel-websockets/commit/a2dd552805e601e3091341c60776ac8d069b885d, https://github.com/beyondcode/laravel-websockets/commit/6a04f9ce4cb4a58772e4242c17e3e1d9cd1fdf77)
    • Fixing typos (https://github.com/beyondcode/laravel-websockets/pull/560, https://github.com/beyondcode/laravel-websockets/pull/563)
    • Removed deprecated buzz-react (https://github.com/beyondcode/laravel-websockets/pull/582)
    Source code(tar.gz)
    Source code(zip)
  • 1.9.0(Oct 18, 2020)

  • 2.0.0-beta.25(Sep 26, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Removing obsolete connections checkups for the Local driver (https://github.com/beyondcode/laravel-websockets/pull/547)
    • Added async-redis queue driver for non-blocking I/O queue processing (https://github.com/beyondcode/laravel-websockets/pull/552)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.24(Sep 19, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Making sure the promises run one after another (https://github.com/beyondcode/laravel-websockets/pull/544)
    Source code(tar.gz)
    Source code(zip)
  • 1.8.1(Sep 19, 2020)

  • 2.0.0-beta.23(Sep 18, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Fixed a bug where broadcastAcrossServers was not called if the needed channel existed locally (https://github.com/beyondcode/laravel-websockets/commit/7519da4a08f062e9983a4e3e1f698b8e4e8ca83d, https://github.com/beyondcode/laravel-websockets/commit/546c4fd0ef362e457b33c1da2e8625a1230cc893)
    • broadcastAcrossServers() now accepts a socketId parameter to know the origin of the event (if possible) (https://github.com/beyondcode/laravel-websockets/commit/30c6635a9159167a9d57117552905b83edcdae3d)
    • Added broadcastLocallyToEveryoneExcept to broadcast only locally, excepting a socket ID (https://github.com/beyondcode/laravel-websockets/commit/9856fb62ed26a29a443974a0e3692d927ecf3f13)
    • Fixed a bug where the mapWithKeys lead to duplicate keys when removing obsolete connections (https://github.com/beyondcode/laravel-websockets/commit/9a6e8e3dc13260d6937e239e259c844eb20d8e19)
    • getForGraph() now accepts a $processCollection closure (https://github.com/beyondcode/laravel-websockets/commit/14a79447f5502a9ef67897b444583b24edd817f4)
    • Fixed HealthHandler that didn't work for HTTP requests (https://github.com/beyondcode/laravel-websockets/commit/7f6b8fa2c8a207ef1bfed8ceb249511346dcbc8a)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.22(Sep 17, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Fixed method typo in the dashboard (https://github.com/beyondcode/laravel-websockets/pull/534)
    • Fixed error regarding exception handling for Pusher JS SDK in the dashboard (https://github.com/beyondcode/laravel-websockets/pull/533)
    • Avoiding emitting too many events when the same user opens multiple connections (tabs, cross-device, etc.) on Presence Channels (https://github.com/beyondcode/laravel-websockets/pull/536, Replicates the changes in 1.x for the current 2.x implementation: https://github.com/beyondcode/laravel-websockets/pull/530)
    • Fixed a bug with same-id users not being properly filtered by uniqueness (https://github.com/beyondcode/laravel-websockets/commit/16ff2aa2b67935566ea2e3fc64e11bd1c5b78b1d)
    • Changed zrange to zrangebyscore to fix obsolete connections detection that caused connections to be imminently closed (https://github.com/beyondcode/laravel-websockets/commit/23e8b3db44b494ba94ef9b6722789411aa690cfd)
    • Fixed a bug that caused obsolete presence channel data to still remain in Redis (https://github.com/beyondcode/laravel-websockets/commit/da7f1ba578e6e96c3ae867c601281546045fa8d1)
    Source code(tar.gz)
    Source code(zip)
  • 1.8.0(Sep 16, 2020)

    • If same user opens multiple connections (for example, in different tabs), the pusher_internal:member_added and pusher_internal:member_removed get triggered only on the first and last connection-only (https://github.com/beyondcode/laravel-websockets/pull/530)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.21(Sep 15, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Fixed dashboard not being able to send test messages (https://github.com/beyondcode/laravel-websockets/pull/532)
    • (Fixed bug from 1.x) Same-id presence connections do not display duplicate users anymore (https://github.com/beyondcode/laravel-websockets/commit/5808a6610cf6521353244c0b9916645547f6ce49)
    • Moved a method out of the promise (improvements might be seen on unsubscribing) (https://github.com/beyondcode/laravel-websockets/commit/630efa2562f4a3c4cd730e413a5da3b25ac0a784)
    Source code(tar.gz)
    Source code(zip)
  • 2.0.0-beta.20(Sep 15, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    • Added /health endpoint for healthchecks (https://github.com/beyondcode/laravel-websockets/pull/524)
    • Using ext-pcntl for soft-shutdown (closing all connections before closing the process) and added 10s timer removing all obsolete data from Redis regarding connections that didn't ping the server back within 120s, as stated in the Pusher Protocol docs (https://github.com/beyondcode/laravel-websockets/pull/523)
    Source code(tar.gz)
    Source code(zip)
  • 1.7.1(Sep 15, 2020)

  • 2.0.0-beta.19(Sep 11, 2020)

    Keep in mind, this release is experimental. Testing and reporting issues are highly appreciated.

    Please check this PR for more details and roadmap: https://github.com/beyondcode/laravel-websockets/pull/447

    The package got re-written from scratch. Ensure to check the PR https://github.com/beyondcode/laravel-websockets/pull/447 to see the main changes. Take special precautions with the migrations & config file.

    Source code(tar.gz)
    Source code(zip)
  • 1.7.0(Sep 10, 2020)

Websockets-Client (Sample) laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Filimantaptius Gulo 1 Mar 8, 2022
Master Websockets Laravel

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Filimantaptius Gulo 1 Mar 8, 2022
A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache.

Laravel OTP Introduction A package for Laravel One Time Password (OTP) generator and validation without Eloquent Model, since it done by Cache. The ca

Lim Teck Wei 52 Sep 6, 2022
Get estimated read time of an article. Similar to medium.com's "x min read". Multilingual including right-to-left written languages. Supports JSON, Array and String output.

Read Time Calculates the read time of an article. Output string e.g: x min read or 5 minutes read. Features Multilingual translations support. Static

Waqar Ahmed 8 Dec 9, 2022
Validate your input data in a simple way, an easy way and right way. no framework required. For simple or large. project.

wepesi_validation this module will help to do your own input validation from http request POST or GET. INTEGRATION The integration is the simple thing

Boss 4 Dec 17, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023
⚡ Laravel Charts — Build charts using laravel. The laravel adapter for Chartisan.

What is laravel charts? Charts is a Laravel library used to create Charts using Chartisan. Chartisan does already have a PHP adapter. However, this li

Erik C. Forés 31 Dec 18, 2022
Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster.

Laravel Kickstart What is Laravel Kickstart? Laravel Kickstart is a Laravel starter configuration that helps you build Laravel websites faster. It com

Sam Rapaport 46 Oct 1, 2022
Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application.

Laravel Segment Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application. Installation You can install the pac

Octohook 13 May 16, 2022
Laravel Sanctum support for Laravel Lighthouse

Lighthouse Sanctum Add Laravel Sanctum support to Lighthouse Requirements Installation Usage Login Logout Register Email Verification Forgot Password

Daniël de Wit 43 Dec 21, 2022
Bring Laravel 8's cursor pagination to Laravel 6, 7

Laravel Cursor Paginate for laravel 6,7 Installation You can install the package via composer: composer require vanthao03596/laravel-cursor-paginate U

Pham Thao 9 Nov 10, 2022
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
Laravel Jetstream is a beautifully designed application scaffolding for Laravel.

Laravel Jetstream is a beautifully designed application scaffolding for Laravel. Jetstream provides the perfect starting point for your next Laravel application and includes login, registration, email verification, two-factor authentication, session management, API support via Laravel Sanctum, and optional team management.

The Laravel Framework 3.5k Jan 8, 2023
Laravel Larex lets you translate your whole Laravel application from a single CSV file.

Laravel Larex Translate Laravel Apps from a CSV File Laravel Larex lets you translate your whole Laravel application from a single CSV file. You can i

Luca Patera 68 Dec 12, 2022
A Laravel package that adds a simple image functionality to any Laravel model

Laraimage A Laravel package that adds a simple image functionality to any Laravel model Introduction Laraimage served four use cases when using images

Hussein Feras 52 Jul 17, 2022
A Laravel extension for using a laravel application on a multi domain setting

Laravel Multi Domain An extension for using Laravel in a multi domain setting Description This package allows a single Laravel installation to work wi

null 658 Jan 6, 2023