1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel Echo(BroadCasting)でPrivateChannelsにEventを送信できない場合

Last updated at Posted at 2020-07-19

Laravel EchoをDBにRedisを利用してPrivate ChannelsにBroardCastをしてもうまくいかない!

環境

・ PHP7.3
・ Laravel 6.8系
・ Redis / Socket.io利用

client側のjoinする処理

window.Echo.private("messanger." + $("#room_id").val()).listen("PushEvent", e => {

という設定をしていた場合、チャンネルとの接続は

[12:53:40 AM] - 7mEjV4c00Cc9hVTHAAAA authenticated for: private-messanger.1
[12:53:40 AM] - 7mEjV4c00Cc9hVTHAAAA joined channel: private-messanger.1

という風にprivate-messanger.1にjoinedをします。この時 以下のようなphpでeventを発火させると

    public function broadcastOn()
    {
        return new PrivateChannel('messanger.' . $this->talkRoom->id);
    }

consoleに次のようなログが出力されます。

Channel: xxxxx_database_private-messanger.1
Event: App\Events\PushEvent

ここで問題が、channel名にxxxxx_database_が頭について、先ほどjoinしたルームに届きません!!
ちなみに、window.Echo.privateの引数を変更しても、この名前を設定することはできません(自動的に頭にprivate-がついちゃうので、つけられないのです...)

回答

.envに
REDIS_PREFIX=null
を追加しましょう! このPREFIXが自動的に頭についちゃいます。

(参考)[https://qiita.com/zaburo/items/34289d4573f39113b25a]

以上

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?