2017 © Pedro Peláez
 

library easy-pusher

A package for sending live push notification with pusher

image

farzin/easy-pusher

A package for sending live push notification with pusher

  • Saturday, October 14, 2017
  • by farzinft
  • Repository
  • 0 Watchers
  • 2 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Easy Pusher

Now It's not hard to broadcast events through public or private channels, you can send notify to specific or collection of users,, (*1)

Installation

  • composer require "farzin/easy-pusher":"dev-master"

Add Service Providers

  • Vinkla\Pusher\PusherServiceProvider::class
  • Farzin\EasyPusher\EasyPusherServiceProvider::class

Add Facade

'EasyPusher' => Farzin\EasyPusher\EasyPusherFacade::class

JS Guide:

first you need add pusher.js to your html file <script src="https://js.pusher.com/4.1/pusher.min.js"></script>, (*2)

//For Private Channels: 

 window.userId = '{{ auth()->check() ? auth()->user()->id : null}}';
    Pusher.logToConsole = true;
    var pusherPrivate = new Pusher('YOUR PUSHER KEY', {
        authEndpoint: '/easy-pusher/auth',
        auth: {
            headers: {
                'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
        },
        cluster: 'us2',
        encrypted: true
    });
    var pusherPublic = new Pusher('YOUR PUSHER KEY', {
        cluster: 'us2',
        encrypted: true
    });
    var channels = {!! json_encode(config('easy-pusher.channels')) !!};
    for(var i = 0; i < channels.length; i++) {
        var channel = channels[i];
        if (channel.match(/^(private).*/)) {
            pusherPrivate.subscribe(channel + '.' + window.userId);
        } else {
            pusherPublic.subscribe(channel);
        }
    }
    pusherPublic.bind('sample-event', function () {
        alert();
    })

Back End Guide:

first you need publish config file: php artisan vendor:publish then in easy-pusher.php config file your need to define your channels, for private channels prefix with 'private';, (*3)

return [
    'channels' => [
        'private-sample-channel', //prefix with public or private
        'public-sample-channel'
    ]
];

for broadcasting events, (*4)

use EasyPusher;

//broadcast event to public channels
EasyPusher::withEvent('sample-event')->withData(array $data)->send();


//for private channels

//collection of users
EasyPusher::withEvent('sample-event')->toUsers(Collection $users)->withData(array $data)->send();

//specific user | user Model
EasyPusher::withEvent('sample-event')->toUser($user)->withData(array $data)->send();

you can pass event name as string or qualified class name., (*5)

The Versions

14/10 2017

dev-master

9999999-dev

A package for sending live push notification with pusher

  Sources   Download

The Requires

 

by farzin fthi

14/10 2017

dev-fix-some-issues

dev-fix-some-issues

A package for sending live push notification with pusher

  Sources   Download

The Requires

 

by farzin fthi

14/10 2017

dev-implement-multiple-channels

dev-implement-multiple-channels

A package for sending live push notification with pusher

  Sources   Download

The Requires

 

by farzin fthi

03/10 2017

dev-develop

dev-develop

a package for sending laravel live push notification with pusher

  Sources   Download

The Requires

 

by farzin fthi