Git Product home page Git Product logo

laravel-http-pushstream-broadcaster's Introduction

HTTP Push-Stream Nginx Module Laravel Broadcast Driver

Thank your for your interest in the HTTP Push-stream Nginx broadcast driver for Laravel. If you are here, it is because you are trying to leverage the latest feature within the Laravel 5.1 broadcasts events for websockets. The HTTP Pushstream Module for Nginx is a powerful Websocket system.

Why use HTTP Pushstream?

If you want to really absorb the power of the capabilities of this module then check out what the dev-ops from Disqus thought in this link:

http://highscalability.com/blog/2014/4/28/how-disqus-went-realtime-with-165k-messages-per-second-and-l.html

How does this driver work?

Once you setup all your routes for the pub/sub requests to the HTTP routes in the location directives for Nginx, then you'll be able to quickly open a socket on your client use the pushstream.js and push your broadcasts out using websocket or long-polling.

The pub/sub requests are internally called by the GuzzleHttp package. The broadcasting.php config file will use the pushstream driver where you can control the HTTP requests to the to your pub/sub endpoints.

You can lock down your pub/sub nginx endpoints using the Access Key Module. Here you can configure the key.

Requirements

Installation

  1. Do a composer require get this package: composer require cmosguy/laravel-http-pushstream-broadcaster

  2. Next, go into your config/broadcasting.php file and add the following lines accordingly. base_url refers to websocket root for your HTTP requests pub/sub routes:

     'default' => 'pushstream',
    
     'pushstream' => [
         'driver' => 'pushstream',
         'base_url' => 'http://localhost',
         'access_key' => md5('foo'),
         'cert' => null
         // or 'cert' => 'path/to/server.crt' for self-signed certificate
     ]
    
  3. In your config/app.php add the following line to your providers array:

    'Cmosguy\Broadcasting\PushStreamBroadcastManagerProvider'
    

Sample Nginx Configuration

  1. In your /etc/nginx/nginx.conf file add:

    push_stream_shared_memory_size 32M;
    
  2. Edit your config file for your routes in the server { section. Obviously, you need to understand and modify the items below. The following config information is just meant to get you started. If you want a more thorough config check out this:

    location /channels-stats {
        # activate channels statistics mode for this location
        push_stream_channels_statistics;
    
        # query string based channel id
        push_stream_channels_path               $arg_id;
    }
    
    location /pub {
       # activate publisher (admin) mode for this location
       push_stream_publisher admin;
    
        # query string based channel id
        push_stream_channels_path               $arg_id;
    }
    
    location ~ /sub/(.*) {
        # activate subscriber (streaming) mode for this location
        push_stream_subscriber;
    
        # positional channel path
        push_stream_channels_path                   $1;
    }
    
    location ~ /ws/(.*) {
        # activate websocket mode for this location
        push_stream_subscriber websocket;
    
    
        # positional channel path
        push_stream_channels_path                   $1;
        if ($arg_tests = "on") {
          push_stream_channels_path                 "test_$1";
        }
    
        # store messages in memory
        push_stream_store_messages              on;
    
        push_stream_websocket_allow_publish     on;
    
        if ($arg_qs = "on") {
          push_stream_last_received_message_time "$arg_time";
          push_stream_last_received_message_tag  "$arg_tag";
          push_stream_last_event_id              "$arg_eventid";
        }
    }
    

Locking down the pub/sub endpoint

    location /pub {
       # activate publisher (admin) mode for this location
       push_stream_publisher admin;
       accesskey                on;
       accesskey_hashmethod     md5;
       accesskey_arg            "access_key";
       accesskey_signature      "foo"

        # query string based channel id
        push_stream_channels_path               $arg_id;
    }

Usage in your app

So, once you are finally ready to trigger an event, you can do this easily now by just extending this broadcastOn in your event handler:

<?php namespace App\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class SomeEvent implements ShouldBroadcast
{
    use SerializesModels;
    /**
     * @var Foo
     */
    public $foo;

    public function __construct(Foo $foo)
    {
        //
        $this->foo = $foo;
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['foochannel-'.$this->foo->uuid];
    }
}

The Client

Please download the pushstream.js from either following locations:

Study the Push Stream Module

At this time the only way to get more information from about the module and the capabilities is directly from the github repository, so do some reading here:

Disclaimer

This is by no means the only way to go about how this should work. You need to understand what all the options do and there is definitely a a

Help

Please help me with updating this documentation. If it does not make sense or if you see something stupid let me know. Also, if there is a way to make this extend further and make it more flexible for others, please submit a PR to improve upon these.

laravel-http-pushstream-broadcaster's People

Contributors

easmith avatar fer-ri avatar jartaud avatar juukie avatar msurguy avatar nekufa avatar vladrusu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-http-pushstream-broadcaster's Issues

Driver [pushstream] is not supported.

Using Laravel 5.4.*.

NGINX is compiled with the latest push stream module (NGINX 1.10.3) and testet with the CURL samples. All Fine!

I follow the configuration instructions for this laravel package. But my application is throwing the following error:

[InvalidArgumentException]
Driver [pushstream] is not supported.

What i'm doing wrong?

Add config option for server's port

It seems that there is no way to set a port on which the server is receiving connections. The module could work on any arbitrary port, so it would be useful to make that as an option for this package as well.

NginxPushStreamBundle

I wrote a similar package (for Symfony2) almost 2 years ago and it still has some advantages e.g.:

  1. filters for namespacing channel names (using prefixes) and for obscuring channel names from other users.
  2. id generators which are the must for polling and long polling strategies in order to not lose messages.
  3. flexible configuration, template urls.
    So you may want to take a look.
    https://github.com/AlexeyKupershtokh/nginx_push_stream_bundle

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.