PusherBroadcaster.php第106行中的Laravel Echo BroadcastException:未知的auth_key

问题描述 投票:1回答:1

尝试广播事件时,我收到未知的auth_key错误。我尝试更改我的群集,如其他帖子中提到但不起作用。我在app.php中有未注释的广播服务提供商。

.ENV

PUSHER_APP_ID=******
PUSHER_APP_KEY=******
PUSHER_APP_SECRET=******

配置/广播

 'pusher' => [
  'driver' => 'pusher',
  'key' => env('PUSHER_APP_KEY'),
  'secret' => env('PUSHER_APP_SECRET'),
  'app_id' => env('PUSHER_APP_ID'),
  'options' => [
   ],
],

\程序\活动\ MessagePosted.php

public function broadcastOn() {
  return new PresenceChannel('chatroom');
 }

\资源\资产\ JS \ bootstrap.js

window.axios = require('axios');

window.axios.defaults.headers.common = {
    'X-Requested-With': 'XMLHttpRequest'
};

import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '*****',
    cluster: 'ap2',
    encrypted: true
});

\资源\资产\ JS \ app.js

const app = new Vue({
    el: '#app',
    data: {
        messages: [],
        usersInRoom: []
    },
    methods: {
        addMessage(message) {
            // Add to existing messages
            this.messages.push(message);

            // Persist to the database etc
            axios.post('/messages', message).then(response => {
                // Do whatever;
            })
        }
    },
    created() {
        axios.get('/messages').then(response => {
            this.messages = response.data;
        });
        Echo.join('chatroom')
                .here((users) => {
                    this.usersInRoom = users;
                })
                .joining((user) => {
                    this.usersInRoom.push(user);
                })
                .leaving((user) => {
                    this.usersInRoom = this.usersInRoom.filter(u => u != user)
                })
                .listen('MessagePosted', (e) => {
                    this.messages.push({
                        message: e.message.message,
                        user: e.user
                    });
                });
    }
});
php laravel-5.4 pusher laravel-echo
1个回答
2
投票

在config / broadcast中添加'cluster'=>'us2','encrypted'=> true在'options'中

'pusher' => [
  'driver' => 'pusher',
  'key' => env('PUSHER_APP_KEY'),
  'secret' => env('PUSHER_APP_SECRET'),
  'app_id' => env('PUSHER_APP_ID'),
  'options' => [
       'cluster' => 'us2',
       'encrypted' => true
  ],
],
© www.soinside.com 2019 - 2024. All rights reserved.