目的
LarevelでDM機能を実装したく、メッセージのやり取りをリアルタイムで行いたい。
現象
PusherのDebug consoleを見ると、ConnectionとSubscribeは行えているように見える。
Laravelからイベント通知を行うとエラーが出て、イベント通知を行うことができません。
エラーログから引数がnullになっているのはわかるのですが対策方法がわかりません。
試したこと
- queueをdatabaseとsyncで実行
- pusher/puhser-php-serverのバージョン変更
- 4.0以下だとphpのバージョンの問題で入らなかったので、^5.0を試しました
環境
laravel
Laravel Framework 6.20.44
php
PHP 8.0.18 (cli) (built: Apr 19 2022 00:24:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.18, Copyright (c) Zend Technologies
pusher/pusher-php-server
versions : * 7.0.2
npm
6.13.4
コード
イベント
MessageCreated.php
1<?php 2 3namespace App\Events; 4 5use Illuminate\Broadcasting\Channel; 6use Illuminate\Broadcasting\InteractsWithSockets; 7use Illuminate\Broadcasting\PresenceChannel; 8use Illuminate\Broadcasting\PrivateChannel; 9use Illuminate\Contracts\Broadcasting\ShouldBroadcast; 10use Illuminate\Foundation\Events\Dispatchable; 11use Illuminate\Queue\SerializesModels; 12 13use App\Models\DmRoomMessage; 14 15class MessageCreated implements ShouldBroadcast 16{ 17 use Dispatchable, InteractsWithSockets, SerializesModels; 18 19 public $message; 20 21 public function __construct() 22 { 23 } 24 25 public function broadcastOn() 26 { 27 return new Channel('hello'); 28 } 29} 30
環境変数
BROADCAST_DRIVER=pusher QUEUE_CONNECTION=sync PUSHER_APP_ID=app_id PUSHER_APP_KEY=app_key PUSHER_APP_SECRET=app_secret PUSHER_APP_CLUSTER=app_cluster
コントローラ
DmController.php
1... 2 public function post_dm() 3{ 4 event(new MessageCreated()); 5} 6
フロントエンド
index.php
1{{-- echoテスト --}} 2<script> 3 window.Echo.channel('hello') 4 .listen('MessageCreated', (e) => { 5 console.log(e) 6 console.log('接続テスト'); 7 }); 8</script>
エラーログ
failed_jobs
1 id: 38 2connection: database 3 queue: default 4 payload: {"displayName":"App\\Events\\MessageCreated","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries":null,"delay":null,"timeout":null,"timeoutAt":null,"data":{"commandName":"Illuminate\\Broadcasting\\BroadcastEvent","command":"O:38:\"Illuminate\\Broadcasting\\BroadcastEvent\":10:{s:5:\"event\";O:25:\"App\\Events\\MessageCreated\":2:{s:7:\"message\";N;s:6:\"socket\";N;}s:5:\"tries\";N;s:7:\"timeout\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"}} 5 exception: Symfony\Component\Debug\Exception\FatalThrowableError: Pusher\Pusher::trigger(): Argument #4 ($params) must be of type array, null given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php on line 113 in /var/www/html/vendor/pusher/pusher-php-server/src/Pusher.php:432 6Stack trace: 7#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php(113): Pusher\Pusher->trigger(Array, 'App\\Events\\Mess...', Array, NULL, true) 8#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(64): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'App\\Events\\Mess...', Array) 9#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\PusherBroadcaster)) 10#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(37): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() 11#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure)) 12... 以下略

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。