没有收到推送消息
Not receiving pusher message
您好,我正在使用 laravel broadcasting
和 pusher
发送一些信息。
我可以成功向推送器发送消息 但是 无法接收.
这是我的代码,请大家帮帮我:(
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>
我已经安装了 pusher
和 laravel echo
,我的 console
中有以下内容:
Download the Vue Devtools extension for a better development
experience: https://github.com/vuejs/vue-devtools app.js:38040
You are running Vue in development mode. Make sure to turn on production mode
when deploying for production. See more tips at
https://vuejs.org/guide/deployment.html
您应该在 config/app.php 文件中取消注释此提供程序。像这样
'providers' => [
...
App\Providers\BroadcastServiceProvider::class,
...
]
大约 Vue
。我 运行 npm install vue
在 cmd 中,尽管我这样做了并且一切正常。
您好,我正在使用 laravel broadcasting
和 pusher
发送一些信息。
我可以成功向推送器发送消息 但是 无法接收.
这是我的代码,请大家帮帮我:(
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>
我已经安装了 pusher
和 laravel echo
,我的 console
中有以下内容:
Download the Vue Devtools extension for a better development experience: https://github.com/vuejs/vue-devtools app.js:38040
You are running Vue in development mode. Make sure to turn on production mode when deploying for production. See more tips at https://vuejs.org/guide/deployment.html
您应该在 config/app.php 文件中取消注释此提供程序。像这样
'providers' => [
...
App\Providers\BroadcastServiceProvider::class,
...
]
大约 Vue
。我 运行 npm install vue
在 cmd 中,尽管我这样做了并且一切正常。