簡體   English   中英

Laravel 5.3 不向推送器發送事件

[英]Laravel 5.3 not sending Events to pusher

我的網站使用 laravel 5.3。 我需要向我的應用程序添加實時功能,所以我使用了 pusher。 但問題是當事件被觸發時什么也沒有發生,也沒有事件發送到推送器。

我在 broadcast.php 文件中的推送器配置:

 'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_KEY'),
        'secret' => env('PUSHER_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => 'eu',
            'encrypted'=>true
        ],
    ],

我的事件類:

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

 class ChatEvent implements ShouldBroadcast
  {
   use InteractsWithSockets, SerializesModels;

public $data;

/**
 * Create a new event instance.
 *
 * @return void
 */
public function __construct($data)
{
    $this->data = $data;

}

/**
 * Get the channels the event should broadcast on.
 *
 * @return Channel|array
 */
public function broadcastOn()
{

    // return new PrivateChannel('test-channel');
    return ['test-channel'];
}

和我的 pusher javascript 代碼:

 Pusher.logToConsole = true;

var pusher = new Pusher('pusher_id', {
  cluster:'eu',
  encrypted: true
});

var channel = pusher.subscribe('test-channel');
channel.bind('App\\Events\\ChatEvent', function(data) {
    console.log(data);
  alert(data);
});

檢查.env文件中的 Pusher 憑據。

PUSHER_KEY should be PUSHER_APP_KEY
PUSHER_SECRET should be PUSHER_APP_SECRET

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM