我想通过私人频道播放Pusher和Laravel的通知。
我的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
我该如何解决这个问题?
答案 0 :(得分:0)
如果没有看到整个代码库,很难确切地知道问题的位置,但是我可以在Pusher博客上推荐以下博客文章,它将引导您完成过去对我有用的整个过程。
https://blog.pusher.com/how-to-build-a-laravel-chat-app-with-pusher/
希望这有帮助!
答案 1 :(得分:0)
您应将BROADCAST_DRIVER=driver
文件中的BROADCAST_DRIVER=pusher
更改为.env
。