Laravel livewire 更改频道以动态收听

时间:2021-04-12 16:25:18

标签: php laravel websocket laravel-livewire

我正在尝试动态更改应用程序的侦听频道。我正在使用 livewire 为我的用户创建一个简单的聊天区域,这个想法是每当用户单击对话 (div) 时,就会出现该对话的消息,并且频道应该相应地更改以仅收听该对话的消息对话。

我的组件侦听器如下所示:

...
class Messenger extends Component{

public $conversations;
public $user;
public $conversation_id;
public $conversation_title;
public $message;
public $sender_id;
public $showChatArea = false;
public $isFirstTime = true;

public function render()
{
    return view('livewire.dashboard.messenger');
}

public function getListeners()
{
    return [
        "echo-private:chat.{$this->conversation_id},ChatMessage" => 'scrollChatToBottom',
    ];
}

/**
 * Set conversation to show
 * @param $id
 */
public function setConversation($id){
    $this->conversation_id = $id;
...

0 个答案:

没有答案