Skip to content

[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

Notifications You must be signed in to change notification settings

vluzrmos/lumen-socketio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

[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

Resources

Stars

Watchers

Forks

Packages

No packages published