vluzrmos/lumen-socketio

This package is abandoned and no longer maintained. The author suggests using the http://lumen.laravel.com/docs/events#broadcasting-events package instead.

The Laravel Lumen Socketio Broadcasting.

v0.1.5 2016-04-21 15:02 UTC

This package is auto-updated.

Last update: 2020-09-13 15:34:51 UTC


README

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