尝试在发送好友请求后将用户列表发送给特定用户。使用pusher,vuejs 2.6,laravel 5.7,但在我的函数中广播未触发
当我在频道中执行dd时,它将起作用!在构造函数中所以我很困惑广播本身是否被调用,但是我看不到第二个XHR请求列表或其他情况!!
//Boostrap.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
app_id: '7xxxx4',
key: 'xxxxxxxxxxxxxxxxxxx',
secret: 'xxxxxxxxxxxxxxxxxxx',
encrypted: false
});
//Vuejs component
mounted(){ window.Echo.channel("newReq").listen(".newreq-list", e => {
this.getrequestedList();
});
.env
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=7xxxxx4
PUSHER_APP_KEY=xxxxxxxxxxxxxxxxxxx
PUSHER_APP_SECRET=xxxxxxxxxxxxxxxxxxx
PUSHER_APP_CLUSTER=ap2
Broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => false,
],
],
channels.php
Broadcast::channel('newReq', function(){
return true;
});
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
class Friendreq implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $req;
public function __construct($req)
{
$this->req = $req;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('newReq');
}
public function broadcastAs()
{
return 'newreq-list';
}
}
//in friendscontroller.php
broadcast(new \App\Events\Friendreq($requestToadd));
我也没有评论App\Providers\BroadcastServiceProvider
对于结果,它应该调用函数this.getrequestedList();
,这是一个有效的函数,因为它也在created()
中被调用
感谢您的帮助
答案 0 :(得分:0)
2天的调试,搜索非常简单:
PUSHER_APP_CLUSTER=ap2
以上行必须更改为此
PUSHER_APP_CLUSTER=eu
现在它被触发并按照我想要的方式工作