composer require tomatotech/tomato_pusher_php
Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
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,
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);
});
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