我想用 laravel echo 和 redis 开发实时应用程序,但它不起作用,即:当我触发事件时没有发生任何事情,我检查 redis 是否正常,但我不知道如何解决这个问题
事件:
class testevent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
$this->data="sdf";
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return ['testCh'];
}
}
火:
Route::get('test',function ()
{
event(new testevent());
return 1;
});
⚠ Starting server in DEV mode...
✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...
Server ready!
.js 文件:
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
console.log("sdfsdffdnpm")
window.Echo.channel('testCh')
.listen('.testevent', () => {
console.log("sooooooooooooooooo");
});