【问题标题】:Laravel 5.5 BroadcastException in PusherBroadcaster.php (line 106)PusherBroadcaster.php 中的 Laravel 5.5 BroadcastException(第 106 行)
【发布时间】:2018-03-03 19:17:26
【问题描述】:

我不知道为什么会收到 BroadcastException 在 PusherBroadcaster.php (第 106 行) 我使用的是 Laravel 5.5 和 Vue 2.0。我已经尝试了所有可能的方法,但没有运气。急需帮助。我已经完成了:

.env

PUSHER_APP_ID=403348
PUSHER_APP_KEY=691857f3d69337b25cf9
PUSHER_APP_SECRET=f36dc5c5114067449338

broadcasting.php

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

bootstrap.js

import Vue from 'vue';
import VueRouter from 'vue-router';
import VueAutosize from 'vue-autosize';
import axios from 'axios';
import Form from './utilities/Form';
import Echo from "laravel-echo";
import Pusher from 'pusher-js';


window.Vue = Vue;


window.Pusher = require('pusher-js');

Vue.use(VueRouter);
Vue.use(VueAutosize)

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

window.Form = Form;

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '691857f3d69337b25cf9',
    cluster: 'us2',
    encrypted: true,
});

NotificationEvent.php

class NotificationEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public function broadcastOn()
    {
        return new Channel('notifications');
    }
}

app.js

import './bootstrap';
import router from './routes'; 

new Vue({
    el: '#app',
    router,

    created() {
        Echo.channel('notifications')
            .listen('NotificationEvent', (e) => {
                alert('adada');
            });
    }
});

web.php

Route::get('notification', function() {
    event(new NotificationEvent());
});

它在尝试 /notification 时显示:

【问题讨论】:

  • 这是已知问题..检查..github.com/laravel/framework/issues/16478
  • @ZaheerAttar 感谢您的回复。我尝试了他们在此链接上建议的解决方案。不走运。我用 laravel 5.4 下载了另一个 github 项目,该项目正在运行。但是当我申请自己的项目时,我遇到了这个问题。我不知道我做错了什么..
  • 你在routes/channels.php文件中设置了广播路由吗?你看过官方doc关于广播的内容吗?

标签: javascript laravel laravel-5 vue.js pusher


【解决方案1】:

Pusher 需要 SSL 才能工作。将 encrypted => false 放入您的 Broadcasting.php 以进行 localhost 开发并尝试。为我工作...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-01
    • 2021-08-19
    • 1970-01-01
    • 2018-07-07
    • 2018-06-08
    • 2020-08-11
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多