#305

Product support

Get help in the plugin support forum.

Categories

  • Developer Tools
  • Miscellaneous
  • Utility

OctoberCMS Pusher Integration. This plugin provides a simplistic method of authentication and triggering of events from PHP. All you have to do is create an authentication endpoint page and add this plugins component 'AuthEndpoint' to the page. As well, it only takes one line of PHP to trigger a Pusher event.

The goal of this plugin is so abstract all the complexities of creating an API and figuring out how to authenticate with Pusher. It will work out of the box with public channels, but you must have the RainLab.User plugin and my other plugin called UserExtended installed in order to authenticate private and presence channels.

Installation

  1. You must first install Pusher's PHP library: https://github.com/pusher/pusher-http-php
  2. Fill in the config values included with this plugin with your applicable Pusher credentials. You will need your Pusher Secret, Pusher appid, and Pusher key.
  3. Install the RainLab.User plugin and my plugin UserExtended as they are dependencies for authenticating private and presence channels. This step is optional if you only want to use public channels.
  4. Create an OctoberCMS page (URL: http://yoursite.com/pusher/auth) with a blank layout and only add the AuthEndpoint component included with this plugin onto that page.
  5. Include Pushers javascript library to your theme: https://js.pusher.com/3.2/pusher.min.js

Usage

Auth Endpoint

Use this component to add authentication to a blank OctoberCMS page.

  • You must give the page a URL of http://yoursite.com/pusher/auth
  • You must ensure the page is completely blank (This means no layout!).
  • Simply add the component to the page and this plugin and Pusher will do the rest.
Examples
  • Use this JS to create a Pusher object:

    var pusher = new Pusher('YOUR_PUSHER_KEY_GOES_HERE', {
        encrypted: true
    });
  • Use this JS to connect to a Pusher public channel and bind to an event:

    var channel = pusher.subscribe('PUBLIC_CHANNEL_NAME');
    channel.bind('test', function(data) {
        console.log("Test: " + data);
    });
  • Use this JS to connect and authenticate a Pusher private channel and bind to an event:

    var privateChannel = pusher.subscribe("private-PRIVATE_CHANNEL_NAME");
    privateChannel.bind('test', function(data) {
        console.log("PRIVATE - test: " + data);
    });
  • Use this JS to connect and authenticate a Pusher presence channel and bind to an event:

    var presenceChannel = pusher.subscribe('presence-PRESENCE_CHANNEL_NAME');
    presenceChannel.bind('test', function(data) {
        console.log("PRESENCE - test: " + data);
    });
  • Use this PHP to trigger an event to a pusher channel:

    Pusher::init()->trigger($channel_name, $event_name, $data);
1.0.1

First version of pusher

Nov 15, 2016