簡體   English   中英

Laravel Websockets 廣播但未顯示在儀表板中

[英]Laravel Websockets Broadcast but not showing in dashboard

我正在嘗試廣播一個事件,但它不起作用並且沒有給出任何錯誤。 我正在使用https://github.com/beyondcode/laravel-websockets

我在 laravel.log 中得到了這個

[2020-10-18 14:24:46] local.INFO: Broadcasting [App\Events\TestEvent] on channels [presence- 
TestChannel] with payload:
{
"message": "123455",
"user": {
    "id": 1,
    "name": "parsa",
    "email": "12parsa@gmail.com",
    "email_verified_at": null,
    "password": "$2y$10$gD6FxFdnzNawrPfzq.cleuXlBN00nKL.ILgQl3pM0dsgBfrOsam0y",
    "remember_token": null,
    "created_at": "2020-10-02T17:50:32.000000Z",
    "updated_at": "2020-10-02T17:50:32.000000Z",
    "banned": 0,
    "last_read_at": "2020-10-16 17:24:21",
    "profile_url": "http:\/\/localhost:8000\/others\/user-profile.png",
    "media": []
    },
    "socket": null
}  

但是在 http://localhost:8000/laravel-websockets 沒有新事件顯示並且 laravel-echo 也不會觸發

配置/webskets.php :

'apps' => [
    [
        'id' => env('PUSHER_APP_ID'),
        'name' => env('APP_NAME'),
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'path' => env('PUSHER_APP_PATH'),
        'capacity' => null,
        'enable_client_messages' => true,
        'enable_statistics' => true,
    ],
],

配置/廣播.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'),
            'useTLS' => true,
            'host' => '127.0.0.1',
            'port' => 6001,
            'scheme' => 'http'
        ],
    ],

App\\Events\\TestEvent.php :

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Modules\User\Entities\User;

class TestEvent implements shouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;
    public $user;

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

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PresenceChannel('TestChannel');
    }
}

路線/Channels.php

Broadcast::channel('TestChannel', function ($user) {
    return $user;
});

.env:

PUSHER_APP_ID=myId
PUSHER_APP_KEY=myKey
PUSHER_APP_SECRET=mySecret
PUSHER_APP_CLUSTER=mt1

我正在執行的行:

broadcast(new TestEvent(User::find(1), $message));

沒關系,我忘了更改 .env BROADCAST_DRIVER=pusher 中的 BROADCAST_DRIVER

暫無
暫無

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

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