0

我想在私人频道上使用 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

我怎样才能解决这个问题?

4

2 回答 2

0

如果不查看整个代码库,很难确切地知道问题出在哪里,但是我可以在 Pusher 博客上推荐以下博客文章,它将带您了解过去对我有用的整个过程。

https://blog.pusher.com/how-to-build-a-laravel-chat-app-with-pusher/

希望这会有所帮助!

于 2017-10-23T14:48:05.477 回答
0

您应该在文件中更改BROADCAST_DRIVER=driver为。BROADCAST_DRIVER=pusher.env

于 2018-11-16T18:50:49.160 回答