Best laravel framework open-source packages.

Lumen socketio

[ABANDONED] A Lumen and Socket.io + Redis Event Broadcasting. Please use the default Lumen 5.1 (illuminate) Broadcasting: http://lumen.laravel.com/docs/events#broadcasting-events
Updated 4 months ago

Lumen + Socket.io e Redis Broadcasting

Latest Stable Version Total Downloads Latest Unstable Version License

THAT PACKAGE IS ABANDONED, PLEASE CONSIDER TO USE LARAVEL|LUMEN NATIVE SOLUTION: https://laravel.com/docs/5.2/events#broadcast-data

Instalation

composer require vluzrmos/lumen-socketio

Add the Services Providers, on bootstrap/app.php:

$app->register('Vluzrmos\Socketio\SocketioServiceProvider');

Configuration

Install NodeJs dependencies:

npm install --save express http-server redis ioredis socket.io

Copy the file vendor/vluzrmos/lumen-socketio/Vluzrmos/Socketio/socket.js to your project root.

Modify it whatever you want, see the code: socket.js

Obs.: Remember to install a Redis Server

On your view, you have to use socket.io.js

<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title> Lumen Socket.IO </title>
    <script src="//cdn.socket.io/socket.io-1.3.5.js"></script>
</head>
<body>

    <script type="text/javascript">
        var socket = io('http://localhost:8080'); //Some host and port configured in socket.js

        socket.on('channel:awesome-event', function (data) {
            console.log(data); 
        });
    </script>
</body>
</html>

Usage

Run your socket.io server:

# that socket.js file is in your project root
node socket.js

On your Lumen App:

$app->get('/publish', function() {
    publish('channel', 'awesome-event', 'An message');
    publish('channel', 'awesome-event', ['message' => 'An message', 'user' => \App\User::first()]);
});


//or, in your controller or some else method (using Dependency Injection)

public function publishSomethingAwesome(\Vluzrmos\Socketio\Contracts\Broadcast $broadcast){
    $broadcast->publish('channel', 'awesome-event', 'An message');
    
    // or just use the helper without inject \Vluzrmos\Socketio\Contracts\Broadcast
    
    publish('channel', 'awesome-event', 'An message');
}

And finish, run your lumen app:

php artisan serve