Call laravel event within socket.io
<p>Is possible call a laravel event and send a variable in socket.io ?</p>

<p>This is the line that I want to know if is possible implement in socket sending the socket id: </p>

<p><code>socket.emit('App\\Events\\ClosePlaySession', socket.id);</code></p>

<p><strong>Socket.js</strong></p>

<pre><code>var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server, {'pingInterval': 2000, 'pingTimeout': 5000});
var Redis = require('ioredis');
var redis = new Redis();

io.set('heartbeat timeout', 10);
io.set('heartbeat interval', 4);

server.listen(3000);

io.on('connection', function (socket) {
    console.log("new client connected " + socket.id);

    socket.on('disconnect', function() {
        socket.emit('App\\Events\\ClosePlaySession', socket.id); // This is possible?
        console.log('client disconnected');
    });
});
</code></pre>

<p><strong>event ClosePlaySession.php</strong></p>

<pre><code>&lt;?php

namespace App\Events;

use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

// Repositories
use wtv\Repositories\PlaySessionRepository;

class ClosePlaySession extends Event implements ShouldBroadcast
{
    use SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($socket_id)
    {
        $playSessionRepository = new PlaySessionRepository;
        $playSessionRepository-&gt;closeSession($socket_id);
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['closePlaySession'];
    }
}
</code></pre>

<p>Or what is the best way to send the socket id in order to update a record in the database.</p>

<p>Thanks</p>