0
私はイベントブロードキャストにlaravel 5.4とプッシャーを使用しています。プライベートチャンネルの "chatroom"を作成します。取得エラーLaravel Echo.join Echo.channelとEcho.privateが動作していない
私はイベントブロードキャストにlaravel 5.4とプッシャーを使用しています。プライベートチャンネルの "chatroom"を作成します。取得エラーLaravel Echo.join Echo.channelとEcho.privateが動作していない
次
Echo.join('chatroom') /// Work Well
.listen('MessagePosted', (e) => {
this.messages.push({
body: e.message.body
});
});
しかし、これは、チャネルおよびプライベートで動作していない...
Echo.channel('chatroom') OR
Echo.private('chatroom') //// Not Working
あなたがmounted()
メソッドの内部でこれを配置する必要があります。エラーが.here
が
mounted(){
Echo.private('chat')
.listen('ChatEvent', (e) => {
console.log(e);
});
//Make function for joining and leaving for any users
Echo.join('chat')
.here((users) => {
console.log(users)
})
.joining((user) => {
console.log(user.name)
})
.leaving((user) => {
console.log(user.name)
});
}
関数ではありませんそして、あなたがプライベートチャットを行う場合は、routes/channels.php
に、あなたがきたチャンネルを登録/定義すると答えているので、このようなchat
の名前 -
Broadcast::channel('chat', function($user){
return ['name' => $user->name]; //Return data as your need
});
ホープそれは誰かを助けるでしょう。