tomato-technologies/tomato-pusher-php

Tomato pusher for Laravel project

v1.0.2 2018-08-27 02:08 UTC

This package is not auto-updated.

Last update: 2024-04-28 03:20:05 UTC


README

Installation

composer require tomatotech/tomato_pusher_php

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

Tomato\Pusher\ServiceProvider::class,

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

'TomatoPusher' => Tomato\Pusher\Facade::class,
'TomatoEvent'  => Tomato\Pusher\Events\Event::class,

Usage

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

    "tomato_pusher" => [
        'app_id' => env('TOMATO_PUSHER_APP_ID'),
        'app_secret' => env('TOMATO_PUSHER_APP_SECRET'),
    ],

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

$appId=TomatoPusher::getAppId();
//or $appId=config("services.tomato_pusher.app_id");
$token=TomatoPusher::getToken();

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

var socket = io('http://localhost:37037/{{$appId}}',{
    rememberUpgrade:true,
    query:{
        channel:"{{your-channel-name}}",
        token:"{{$token}}"
    },
});

socket.on('{{your-event-name}}', function(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 TomatoEvent('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