我想在私人频道上使用 Pusher 和 Laravel echo 广播我的通知。
我的 bootstrap.js 文件如下
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: '5c3621c15520b7e2fb02',
cluster: 'ap2'
});
Pusher.log = function(message){
window.console.log(message)
}
和我的 notification.vue 文件如下
<script>
export default {
mounted() {
this.listen()
},
props: ['id'],
methods: {
listen() {
Echo.private('App.User.' + this.id)
.notification( (notification) => {
alert('new notification')
})
}
}
}
</script>
我的 BroadcastServiceProvider.php 如下
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider {
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() {
Broadcast::routes();
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
}
}
在控制台中,它给出如下错误
Pusher : State changed : connecting -> connected with new socket ID 334.3086157
Pusher : No callbacks on private-App.User.1 for pusher:subscription_error
if I changed BROADCAST_DRIVER=driver
它给出了如下错误
Pusher : State changed : connecting -> connected with new socket ID
Pusher : No callbacks on private-App.User.1 for pusher:subscription_error
我怎样才能解决这个问题?