广播系统

广播系统就是在事件系统的基础上添加广播的功能,事件被触发后将消息广播出来。
有两种实现方式,一种是 pusher + laravel echo,另一种是 Redis + socket.io

引入

配置laravel 项目文件bootstrap.js中注释掉的部分并改为,

/**
 * Echo exposes an expressive API for subscribing to channels and listening
 * for events that are broadcast by Laravel. Echo and event broadcasting
 * allows your team to easily build robust real-time web applications.
 */

import Echo from "laravel-echo"

window.Echo = new Echo({
  broadcaster: 'pusher',
  key: 'your-pusher-key',
  cluster: 'your-pusher-cluster',
  encrypted: true
});

.env文件中修改如下代码

PUSHER_APP_ID="your-pusher-app_id"
PUSHER_APP_KEY="your-pusher-key"
PUSHER_APP_SECRET="your-pusher-secret"

这些参数都需要注册pusher的账号,都可以在后台查看到。

POST http://www.example.com/broadcasting/auth 404 (Not Found)

config/app.php 取消注释 App\Providers\BroadcastServiceProvider::class,

POST http://www.example.com/broadcasting/auth 403 (Forbidden)

你可能感兴趣的:(广播系统)