[DEPRECATED] A Pusher Channels bridge for Laravel

Overview

DEPRECATED

Laravel now has built-in support for Pusher Channels. This is now the recommended approach to integrate Channels into a Laravel project.

Currently, Pusher will continue to review any PRs and solve security vulnerabilities in this SDK, but will not be making any major improvements going forward.

Pusher Channels Laravel Library

A Pusher Channels bridge for Laravel. Formerly vinkla/pusher.

// Triggering events.
$pusher->trigger('my-channel', 'my_event', 'hello world');

// Authenticating Private channels.
$pusher->socket_auth('my-channel', 'socket_id');

// Want to use the facade?
Pusher::get('/channels');

Build Status StyleCI Coverage Status Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require pusher/pusher-http-laravel

Add the service provider to config/app.php in the providers array. If you're using Laravel 5.5 or greater, there's no need to do this.

Pusher\Laravel\PusherServiceProvider::class

If you want you can use the facade. Add the reference in config/app.php to your aliases array.

'Pusher' => Pusher\Laravel\Facades\Pusher::class

Configuration

The Laravel Channels SDK requires connection configuration. To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish --provider="Pusher\Laravel\PusherServiceProvider"

This will create a config/pusher.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

Default Connection Name

This option default is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is main.

Channels Connections

This option connections is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like.

Encrypted Channels

To enable end to end encrypted channels, you need to uncomment a line from the Channels config file

'app_id' => env('APP_ID'),
'options' => [
    'cluster' => env('APP_CLUSTER'),
    'encryption_master_key' => env('ENCRYPTION_MASTER_KEY'),
],
'host' => null,
'port' => null,

Then you need to set an encryption_master_key in your .env file. You should then be able to publish encrypted events to channels prefixed with private-encrypted and you can validate this is working by checking the (dashboard)[https://dashboard.pusher.com] debug console for your app!

Usage

PusherManager

This is the class of most interest. It is bound to the ioc container as pusher and can be accessed using the Facades\Pusher facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of Graham Campbell's Laravel Manager package, so you may want to go and checkout the docs for how to use the manager class over at that repository. Note that the connection class returned will always be an instance of Pusher.

Facades\Pusher

This facade will dynamically pass static method calls to the pusher object in the ioc container which by default is the PusherManager class.

PusherServiceProvider

This class contains no public methods of interest. This class should be added to the providers array in config/app.php. This class will setup ioc bindings.

Examples

Here you can see an example of just how simple this package is to use. Out of the box, the default adapter is main. After you enter your authentication details in the config file, it will just work:

// You can alias this in config/app.php.
use Pusher\Laravel\Facades\Pusher;

Pusher::trigger('my-channel', 'my-event', ['message' => $message]);
// We're done here - how easy was that, it just works!

Pusher::getSettings();
// This example is simple and there are far more methods available.

The PusherManager will behave like it is a Pusher. If you want to call specific connections, you can do that with the connection method:

use Pusher\Laravel\Facades\Pusher;

// Writing this…
Pusher::connection('main')->log('They see me logging…');

// …is identical to writing this
Pusher::log('They hatin…');

// and is also identical to writing this.
Pusher::connection()->log('Tryin to catch me testing dirty…');

// This is because the main connection is configured to be the default.
Pusher::getDefaultConnection(); // This will return main.

// We can change the default connection.
Pusher::setDefaultConnection('alternative'); // The default is now alternative.

If you prefer to use dependency injection over facades like me, then you can inject the manager:

use Pusher\Laravel\PusherManager;

class Foo
{
    protected $pusher;

    public function __construct(PusherManager $pusher)
    {
        $this->pusher = $pusher;
    }

    public function bar()
    {
        $this->pusher->trigger('my-channel', 'my-event', ['message' => $message]);
    }
}

App::make('Foo')->bar();

Documentation

There are other classes in this package that are not documented here. This is because the package is a Laravel wrapper of the official Channels package.

License

MIT © Pusher

Comments
  • Error Using the Facade

    Error Using the Facade

    The error below has been reported by @alexandredes and @mottihoresh. This error occurs when using the Facade. As I've learned, using dependency injection it works.

    call_user_func_array() expects parameter 1 to be a valid callback
    

    I've tried this in my local setup, using Homestead, with both the Facade and dependency injection without any problems. The events gets registered in the console at http://pusher.com. Example code below.

    <?php namespace App\Http\Controllers;
    
    use Vinkla\Pusher\Facades\Pusher;
    
    class PushController extends Controller {
    
        public function index()
        {
            dd(Pusher::trigger('my-channel', 'my-event', ['message' => 'A']));
        }
    
    }
    

    unnamed

    If someone else experience this, please report it here. If you have a solution, please share it!

    bug 
    opened by vinkla 47
  • Class 'Pusher\Pusher' not found

    Class 'Pusher\Pusher' not found

    Since the last update i get this error

    Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Pusher\Pusher' not found in D:\Xampp7\htdocs\cookme\vendor\vinkla\pusher\src\PusherFactory.php:79

    opened by ghost 21
  • Method 'trigger' not found in class \Vinkla\Pusher\PusherManager

    Method 'trigger' not found in class \Vinkla\Pusher\PusherManager

    Well, I decided to give this package another go with Laravel 5.1. Not sure what the issue is. None of the Pusher SDK methods are available when I try your dependency injection method.

    use Vinkla\Pusher\PusherManager;
    
    class Foo
    {
        protected $pusher;
    
        public function __construct(PusherManager $pusher)
        {
            $this->pusher = $pusher;
        }
    
        public function bar()
        {
            $this->pusher->trigger('my-channel', 'my-event', ['message' => $message]);
        }
    }
    

    Anyway to fix this so autocompletion will work?

    opened by Kryptonit3-zz 12
  • Deprecate this SDK

    Deprecate this SDK

    Laravel Broadcasting now includes built-in support for Pusher Channels via the pusher-http-php SDK. This is now the recommended way of using Channels with Laravel. We should deprecate this repository.

    I propose we:

    • Set the Github repository as "archived"
    • Mention the library is deprecated in the README
    • "Abandon" the project on packagist
    • Remove it from https://pusher.com/docs/channels/channels_libraries/libraries
    opened by WillSewell 11
  • Presence channel not return wrong auth string.

    Presence channel not return wrong auth string.

    I'm trying to build a presence channel. But the auth string returned is not correct.

    Here is the back end code:

    class pusherController extends Controller
    {
    
        protected $pusher;
    
        public function __construct(PusherManager $pusher)
        {
            $this->pusher = $pusher;
        }
    
        public function pusherPinyinAuth(Request $request)
        {
            if($request->user()) {
                $user = $request->user();
                $auth= $this->pusher->presence_auth($request->input('channel_name'),$request->input('socket_id'), $user->id, array('h'=>'user_info'));
                return response($auth);
            }
        }
    }
    

    Error message

    Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Auth value for subscription to presence-5 is invalid: should be of format 'key:signature'"}}}

    I guess the the error is caused by the additional ':' added before the auth string. Here is my string output:

    {auth: ":8dacf362f8fe62bae42c33dfe5511d3d1c42144685d5843a6a6a8014490ed0f6",…}

    opened by jinxuanw-clairvoyant 11
  • class 'Vinkla\Pusher\Facades\Pusher' does not have a method 'socket_auth'

    class 'Vinkla\Pusher\Facades\Pusher' does not have a method 'socket_auth'

    Hello,

    I don't arrive to implementing the auth endpoint for a private channel. The response is: class 'Vinkla\Pusher\Facades\Pusher' does not have a method 'socket_auth'

    My code:

    class UserController extends Controller
    {
        protected $pusher;
    
        public function __construct(PusherManager $pusher)
        {
            $this->pusher = $pusher;
        }
    
        public function getAuthPusher()
        {
            $auth = $this->pusher->socket_auth($_POST['channel_name'], $_POST['socket_id']);
        }
    }
    

    Thank you for your help :)

    opened by clementbirkle 10
  • create PusherLogAdapter to forward Pusher log calls to Laravel logger

    create PusherLogAdapter to forward Pusher log calls to Laravel logger

    The official Pusher package contains calls to a "log" method if a logger is provided. In this PR, I have provided a simple adapter class that will forward Pusher's log calls to the Laravel logger.

    Activation of the log adapter is controlled by a true/false setting in config/pusher.php.

    I've added two tests. One covers invocation of the Factory with log enabled. The other tests the single function of the log adapter ("log" method), assuring that it forwards the message to a mock logger.

    opened by michalcarson 10
  • I can not install this package in laravel 5.4

    I can not install this package in laravel 5.4

    c:\xampp\htdocs\mymusic (master) λ composer require vinkla/pusher Using version ^2.4 for vinkla/pusher ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.

    Problem 1 - vinkla/pusher 2.5.0 requires php ^7.0 -> your PHP version (5.6.30) does not satisfy that requirement. - Installation request for vinkla/pusher ^2.4 -> satisfiable by vinkla/pusher[2.4.0, 2.5.0]. - Conclusion: remove laravel/framework v5.4.15 - Conclusion: don't install laravel/framework v5.4.15 - vinkla/pusher 2.4.0 requires illuminate/contracts 5.1.* || 5.2.* || 5.3.* -> satisfiable by illuminate/contracts[v5.1.1, v5.1.13, v5.1.16, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4]. - don't install illuminate/contracts v5.1.1|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.13|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.16|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.20|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.22|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.25|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.28|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.30|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.31|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.41|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.1.8|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.0|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.19|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.21|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.24|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.25|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.26|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.27|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.28|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.31|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.32|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.37|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.43|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.45|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.6|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.2.7|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.3.0|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.3.16|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.3.23|don't install laravel/framework v5.4.15 - don't install illuminate/contracts v5.3.4|don't install laravel/framework v5.4.15 - Installation request for laravel/framework (locked at v5.4.15, required as 5.4.*) -> satisfiable by laravel/framework[v5.4.15].

    Installation failed, reverting ./composer.json to its original content.

    opened by phuongphally 8
  • Support for cluster name

    Support for cluster name

    Hello there !

    Pusher is setting up some clusters on different regions. Since I live in France I would like to use the eu but have no option to set it. Could you please tell me if it is planned or not (yet) ?

    See the doc : https://pusher.com/docs/clusters

    Thank you !

    question 
    opened by RomainSauvaire 6
  • Fix composer.json to use up to date pusher-http-php dep

    Fix composer.json to use up to date pusher-http-php dep

    Currently, users who update the lib without updating its deps might find themselves in a position where e2e should work but can't.

    This pins the Pusher-http-php dep to a version that supports e2e.

    opened by kn100 4
  • Set up the new GitHub Hook for Packagist

    Set up the new GitHub Hook for Packagist

    Pusher-http-laravel composer github integration is going to break in early 2019. Worth fixing now. Error "This package is using the legacy GitHub service and will stop being auto-updated in early 2019. Please set up the new GitHub Hook for Packagist so that it keeps working in the future."

    opened by jameshfisher 4
Releases(v4.2.4)
Owner
Pusher
Pusher makes communication and collaboration APIs that power apps all over the world supported by easy to integrate SDKs for web, mobile, and backend.
Pusher
A GitHub API bridge for Laravel

Laravel GitHub Laravel GitHub was created by, and is maintained by Graham Campbell, and is a PHP GitHub API bridge for Laravel. It utilises my Laravel

Graham Campbell 547 Dec 30, 2022
Laravel ClickHouse adds CH client integration, generation & execution of ClickHouse database migrations to the Laravel application.

Laravel ClickHouse Introduction Laravel ClickHouse database integration. This package includes generation and execution of the ClickHouse database mig

cybercog 11 Dec 20, 2022
A Laravel package to retrieve pageviews and other data from Google Analytics

Retrieve data from Google Analytics Using this package you can easily retrieve data from Google Analytics. Here are a few examples of the provided met

Spatie 2.8k Jan 7, 2023
Manage newsletters in Laravel

Manage newsletters in Laravel This package provides an easy way to integrate MailChimp with Laravel. Should you find that Mailchimp is too expensive f

Spatie 1.5k Jan 2, 2023
A simple API documentation package for Laravel using OpenAPI and Redoc

Laravel Redoc Easily publish your API documentation using your OpenAPI document in your Laravel Application. Installation You can install this package

Steve McDougall 15 Dec 27, 2022
TeleBot - Easy way to create Telegram-bots in PHP. Rich Laravel support out of the box.

TeleBot is a PHP library for telegram bots development. Rich Laravel support out of the box. Has an easy, clean, and extendable way to handle telegram Updates.

WeStacks 206 Jan 6, 2023
laravel wrapper for dicom images services

laravel wrapper for dicom images services

Laravel Iran Community 4 Jan 18, 2022
A Laravel package to help integrate Shopware PHP SDK much more easier

Shopware 6 Laravel SDK A Laravel package to help integrate Shopware PHP SDK much more easier Installation Install with Composer composer require sas/s

Shape & Shift 16 Nov 3, 2022
laravel package untuk memudahkan penggunaan MCA dengan Telegram Bot USDI di aplikasi Universitas Udayana.

MCA KubeMQ Laravel laravel package untuk memudahkan penggunaan MCA dengan Telegram Bot USDI di aplikasi Universitas Udayana. Motivasi Proyek ini berfu

Ristek USDI 1 Nov 17, 2021
Integrate RajaOngkir API with laravel

Baca ini dalam bahasa: Indonesia This is my package laravel-rajaongkir Installation You can install the package via composer: composer require kodepin

Kode Pintar 6 Aug 11, 2022
A Laravel SQS driver that removes the 256KB payload limit by saving the payloads into S3.

Simple SQS Extended Client Introduction Simple SQS Extended Client is a Laravel queue driver that was designed to work around the AWS SQS 256KB payloa

Simple Software LLC 7 Dec 8, 2022
Google VerifiedSMS Laravel Package

Google VerifiedSMS Laravel Package This is a laravel package developed for google business communication api and verified SMS API. Before we commence

Saju G 2 Nov 22, 2021
A Laravel wrapper for thephpleague's Fractal package

laravel-api-response A Laravel wrapper for thephpleague's Fractal package Install Via Composer composer require lykegenes/laravel-api-response Then, a

Patrick Samson 3 Mar 15, 2021
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax

Fluent-Facebook Docs A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax. Check out how easy it is to

iluminar 47 Dec 8, 2022
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Telegram Bot API - PHP SDK Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box. Telegram Bot API is an

Irfaq Syed 2.5k Jan 6, 2023
Facebook GraphQL for Laravel 5. It supports Relay, eloquent models, validation and GraphiQL.

Laravel GraphQL This package is no longuer maintained. Please use rebing/graphql-laravel or other Laravel GraphQL packages Use Facebook GraphQL with L

Folklore Inc. 1.8k Dec 11, 2022
This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Daniel Henze 3 Aug 29, 2022
Twitch Helix API PHP Wrapper for Laravel

Laravel Twitch PHP Twitch Helix API Wrapper for Laravel 5+ ⚠️ Changes on May 01, 2020 Since May 01, 2020, Twitch requires all requests to contain a va

Roman Zipp 87 Dec 7, 2022
Browser Detection for Laravel by hisorange!

Browser Detection v4.4 by hisorange Easy to use package to identify the visitor's browser details and device type. Magic is not involved the results a

Varga Zsolt 869 Jan 2, 2023