cavaon-wayne/pusher-php-client

Cavaon pusher for Laravel project

v2.0.0 2019-08-22 09:15 UTC

This package is not auto-updated.

Last update: 2022-01-07 19:11:12 UTC


README

Installation

composer require cavaon-wayne/pusher-php-client

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

Laravel 5.5+:

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

Cavaon\Pusher\ServiceProvider::class,

If you want to make it easier to access Pusher or Event class, add this to your facades in app.php:

'CavaonPusher' => Cavaon\Pusher\Facade::class,
'CavaonEvent'  => Cavaon\Pusher\Events\Event::class,

Usage

Before usage, please remember to set your App Id and App secret in config/broadcasting.php, They are assigned to you via cavano-pusher-server's .env file

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_KEY'), //ANY DUMMPY STRING WILL DO
            'secret' => env('PUSHER_SECRET'), //YOUR SECRET HERE
            'app_id' => env('PUSHER_APP_ID'), //YOUR APP ID HERE
            'options' => [
                "host"=>env('PUSHER_HOST'), // YOUR PUSHER SERVER HERE, eg 'http://192.168.1.1'
                "port"=>env('PUSHER_HOST_PORT'), //YOUR PUSHER SERVER PORT HERE, eg '37037'
            ],
        ],

You need to get the JWT token generated by this pusher and the APP Id and pass them to your socket.io client:

$wsHostURL=CavaonPusher::getHostURL();
$token=CavaonPusher::getToken();

Here is a example how your will use them in your socket.io client:

var socket = io('{{$wsHostURL}}',{
    rememberUpgrade:true,
    query:{
        channel:"[your-channel-name]",
        token:"{{$token}}"
    },
});

socket.on('[your-event-name]', function(data){
    //use JSON.parse to decode the json string of data.
    console.log(data);
});

Broadcasting

To broadcast event to you socket.io client:

$data=["id"=>1,"name"=>"Sydney day tour","price"=>100.5];
event(new CavaonEvent('your-channnel-name','your-event-name',$data));

Please remember to run make queue listening if you don't using the sync drive for queue

php artisan queue:listen