2017 © Pedro Peláez
 

library notifier

NO LIBRARIES socket per page bridge for your Laravel application.

image

matviib/notifier

NO LIBRARIES socket per page bridge for your Laravel application.

  • Wednesday, July 25, 2018
  • by MatviiB
  • Repository
  • 9 Watchers
  • 53 Stars
  • 75 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 13 Versions
  • 257 % Grown

The README.md

build passed code-intelligence license downloads , (*1)

Base concepts

You don't need socket.io, pusher.js, jQuery, bootstrap, node.js, vue.js to start using this package., (*2)

This package can be used for sending data synchronously to each user., (*3)

This package sends data ONLY to named routes declared as GET., (*4)

You will get your own socket server on back-end and your clients will connect to it directly, without any third-party requests to be send., (*5)

You will have pretty notifications from scratch., (*6)

To view available routes you can run php artisan notifier:init show command. It will display available routes in the table and initiate the socket server., (*7)

Code Description
event(new Notify($data)); - send to all routes.
event(new Notify($data, $routes)); - send to routes in $routes array.
event(new Notify($data, $routes, $users)); - send to routes in $routes and only to users in $users.

Installation

composer require matviib/notifier

For Laravel < 5.5 add provider to config/app.php, (*8)

MatviiB\Notifier\NotifierServiceProvider::class,

For publish notifier config file and js file for notifications out of the box:, (*9)

php artisan vendor:publish

and choose "Provider: MatviiB\Notifier\NotifierServiceProvider" if requested., (*10)

Starting server

Add worker daemon for php artisan notifier:init process with Supervisor,, (*11)

OR, (*12)

Just run php artisan notifier:init in terminal., (*13)

If you use SSL you need add to your nginx configuration file to server block:, (*14)

    location /websocket {
        proxy_pass http://<your-domain>:<port>; #server host and port
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        # Timeout configuration.
        proxy_redirect off;
        proxy_connect_timeout  300;
        proxy_send_timeout     300;
        proxy_read_timeout     300;
   }

Usage

At first you need to add @include('notifier::connect') before using socket.addEventListener() in your view or main layout to use it on ALL pages., (*15)

If you want use notifications from the scratch you need to add @include('notifier::connect_and_show') to the view., (*16)

Anywhere in your back-end add next event:, (*17)

event(new Notify($data));, (*18)

On front-end part add event listener, (*19)

<script>
    socket.addEventListener('message', function (event) {
        console.log('Message from server', event.data);
    });
</script>

Use built-in notifications.

Built-in notifications is a vue.js with vue-notifications plugin. If you already use vue.js in application you can just add this plugin yourself., (*20)

Mapping $data parameter.
Parameter Description
'note' => 1, - use notes true
`'type' => 'warn success|error|info',` | - type of note
'title' => 'TEXT' - title of the note
'text' => 'Lorem ipsum' - note's body
Positioning.

In config/notifier.php you can modify position where notifications will be shown., (*21)

// Horizontal options: left, center, right
// Vertical options: top, bottom
'position' => [
        'vertical' => 'bottom',
        'horizontal' => 'right'
    ]

Security

This package allows one way messages - only from server to client., (*22)

All messages from client after connecting will be ignored., (*23)

From server side messages protected with socket_pass parameter from notifier config., (*24)

Channels to users protected with unique hash., (*25)

Example with charts

After installation add to web.php, (*26)

Route::get('chart', function () {
    return view('chart');
})->name('chart');

create view /resources/views/chart.blade.php, (*27)

<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Chart</title>
</head>
<body>
<canvas id="myChart"></canvas>
@include('notifier::connect')






</body>
</html>

In .env fix your APP_URL APP_URL=http://<<U APP URL>>, (*28)

Create test command php artisan make:command Test, (*29)

use MatviiB\Notifier\Events\Notify; 

...

protected $signature = 'test';

public function handle()
    {
        while ($i < 100) {
            $value = random_int(10, 100);
            $data['value'] = $value;
            event(new Notify($data, ['chart']));
            usleep(rand(100000, 500000));
        }
}

Run: php artisan notifier:init, (*30)

Run in another shell: php artisan test, (*31)

Open /chart page., (*32)

Usage Example

Send new values to chart on some page synchronously to each user:, (*33)

event(new Notify($data, ['chart']));, (*34)

Or to users with id 3 and 5: event(new Notify($data, ['chart'], [3, 5]));, (*35)

laravel socket server, (*36)

The Versions

25/07 2018

dev-master

9999999-dev https://matviib.com/notifier

NO LIBRARIES socket per page bridge for your Laravel application.

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real time real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

25/07 2018

v1.3.1

1.3.1.0 https://matviib.com/notifier

NO LIBRARIES socket per page bridge for your Laravel application.

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

04/07 2018

v1.3.0

1.3.0.0

NO LIBRARIES socket per page bridge for your Laravel application.

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

04/07 2018

dev-develop

dev-develop

NO LIBRARIES socket per page bridge for your Laravel application.

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

07/06 2018

v1.2.1

1.2.1.0

NO LIBRARIES socket per page bridge for your Laravel application.

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

12/05 2018

v1.2.0

1.2.0.0

NO LIBRARIES socket per page bridge for your Laravel application.

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

04/05 2018

v1.1.0

1.1.0.0

NO LIBRARIES socket per page bridge for your Laravel application.

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

27/04 2018

dev-add-license-1

dev-add-license-1

NO LIBRARIES socket per page bridge for your Laravel application..

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

26/04 2018

v1.0.1

1.0.1.0

NO LIBRARIES socket per page bridge for your Laravel application..

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

18/04 2018

v1.0.0

1.0.0.0

NO LIBRARIES socket per page bridge for your Laravel application..

  Sources   Download

MIT

The Requires

 

by Matvii Bondar

laravel laravel5 laravel-5 notifier socket notifications sockets laravel-application real-time laravel-5-package socket-server socket-client composer-library laravel55 socket-communication composer-package socket-programming socketserver sockets-easy socketstream

30/01 2018

v0.0.4.1

0.0.4.1

Real time NO LIBRARIES socket based messages (data) for your Laravel application.

  Sources   Download

MIT

by Matvii Bondar

laravel notifier socket real time

25/01 2018

v0.0.4

0.0.4.0

Easy Notifier.

  Sources   Download

MIT

by Matvii Bondar

laravel notifier socket

25/01 2018

v0.0.3

0.0.3.0

Easy Notifier.

  Sources   Download

MIT

by Matvii Bondar

laravel notifier socket