【问题标题】:Not receiving pusher message没有收到推送消息
【发布时间】:2020-07-16 04:03:06
【问题描述】:

您好,我正在使用 laravel broadcastingpusher 发送一些信息。
我可以成功向推送者发送消息 无法接收
这是我的代码,请帮帮我:(

App.js

require('./bootstrap');
window.Vue = require('vue');

const app = new Vue({
    el: "#app",
    created() {
        Echo.private('gameRoom')
            .listen('RequestsEvent', (e) => {
                console.log(e);
            });
    }
});

Bootstrap.js

window._ = require('lodash');

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: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    forceTLS: true
});

RequestsEvent.php

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

    public $type;
    public $room_manager;

    /**
     * Create a new event instance.
     *
     * @param $type
     * @param $room_manager
     */
    public function __construct($type, $room_manager)
    {
        $this->type = $type;
        $this->room_manager = $room_manager;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return PrivateChannel
     */
    public function broadcastOn()
    {
        return new PrivateChannel('gameRoom');
    }
}

Channels.php

Broadcast::channel('gameRoom', function () {
    return true;
});

HTML:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Listen</title>
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="{{ asset('css/app.css') }}"/>
</head>
<body>
<div id="app"></div>

<script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
</body>
</html>

我已经安装了pusherlaravel echo,我的console 中有以下内容:

下载 Vue Devtools 扩展以获得更好的开发 经验:https://github.com/vuejs/vue-devtoolsapp.js:38040
您正在开发模式下运行 Vue。确保打开生产模式 部署生产时。查看更多提示 https://vuejs.org/guide/deployment.html

【问题讨论】:

  • 此警告与问题无关。

标签: php laravel vue.js pusher broadcasting


【解决方案1】:

您应该在 config/app.php 文件中取消注释此提供程序。像这样

'providers' => [
    ...
    App\Providers\BroadcastServiceProvider::class,
    ...
]

【讨论】:

    【解决方案2】:

    大约是Vue。我在 cmd 中运行npm install vue,尽管我这样做了,而且一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-27
      • 2023-03-28
      • 2012-10-27
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      相关资源
      最近更新 更多