#laravel
#laravel
Вопрос:
Я пытаюсь транслировать событие, но оно не работает и не выдает ошибок. Я использую https://github.com/beyondcode/laravel-websockets
Я получаю это в laravel.log
[2020-10-18 14:24:46] local.INFO: Broadcasting [AppEventsTestEvent] 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 тоже не срабатывает
config/websckets.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,
],
],
config/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'),
'useTLS' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http'
],
],
AppEventsTestEvent.php :
namespace AppEvents;
use IlluminateBroadcastingChannel;
use IlluminateBroadcastingInteractsWithSockets;
use IlluminateBroadcastingPresenceChannel;
use IlluminateContractsBroadcastingShouldBroadcast;
use IlluminateFoundationEventsDispatchable;
use IlluminateQueueSerializesModels;
use ModulesUserEntitiesUser;
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 IlluminateBroadcastingChannel|array
*/
public function broadcastOn()
{
return new PresenceChannel('TestChannel');
}
}
routes/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));
Ответ №1:
Неважно, я забыл изменить BROADCAST_DRIVER в .env BROADCAST_DRIVER=pusher
Комментарии:
1. Благодарим вас за предоставление решения.