i tried to work with these. but i couldn't get work laravel-echo.
can you tell me what should i listen on laravel echo. this is my example code.
socket.js
var server = require('http').Server();
var io = require('socket.io')(server);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('tester', function (err, count) {
//console.log('done');
});
redis.on('message', function (channel, message) {
console.log(channel, message);
message = JSON.parse(message);
io.emit(message.event, message.data);
});
server.listen(3000);
app.js
import Echo from "laravel-echo";
var echo = window.Echo = new Echo({
broadcaster: 'socket.io',
host: 'http://localhost:3000'
});
echo.channel('tester').listen('UserSignedUp', function (d) {
console.log('data', d);
});
UserSignedUp.php Event
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class UserSignedUp implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $username;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($username)
{
$this->username = $username;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return ['tester'];
}
}
what should i do to get work this..
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire