首页 > 解决方案 > 没有收到推送消息

问题描述

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

应用程序.js

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

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

引导程序.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
});

请求事件.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');
    }
}

频道.php

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

网页:

<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-devtools app.js:38040
您正在开发模式下运行 Vue。确保在部署生产时打开生产模式。在https://vuejs.org/guide/deployment.html查看更多提示

标签: phplaravelvue.jspusherbroadcasting

解决方案


大约是Vuenpm install vue尽管我这样做了,但我还是在 cmd 中运行,并且一切正常。


推荐阅读