Cześć, próbuję ogarnąć prosty prywatny chat w Vue.js Laravel z wykorzystaniem Redis
Po kolei, podczas tworzenia wiadomości:
public function save(array $data, ChatConversationMessage $chatConversationMessage = null): ?ChatConversationMessage
{
$data['sender_id'] = Auth::id();
if ($chatConversationMessage) {
$chatConversationMessage->update($data);
return $chatConversationMessage;
}
$item = ChatConversationMessage::create($data);
broadcast(new MessageEvent($item))->toOthers();
return $item;
}
wywołuję event którego kod wygląda tak
/**
* @var ChatConversationMessage $message
*/
public $message;
/**
* @param ChatConversationMessage $message
*/
public function __construct(ChatConversationMessage $message)
{
$this->message = $message;
}
/**
* @return string
*/
public function broadcastAs()
{
return 'message_event';
}
/**
* @return PrivateChannel
*/
public function broadcastOn()
{
return new PrivateChannel('private-chat-room-' . $this->message->conversation_id);
}
następnie po stronie front end mam skonfigurowane połączenie
import Echo from 'laravel-echo'
window.io = require('socket.io-client')
const echo = new Echo ({
broadcaster: 'socket-io',
host: 'http://localhost:6001'
})
export default ({Vue}) => {
Vue.prototype.$echo = echo
}
i teraz w komponencie próbuję wywołać event
submit() {
this.$echo.private('private-chat-room-'+this.$route.params.id)
.listen('message_event', (e) => {
console.log(e);
})
}
jednak otrzymuję błąd
TypeError: Cannot read property 'privateChannel' of undefined
at Echo._private (echo.js?6fb8:1422)
at VueComponent.submit (Create.vue?56af:32)
at invokeWithErrorHandling (vue.runtime.esm.js?5593:1854)
at VueComponent.invoker (vue.runtime.esm.js?5593:2179)
at invokeWithErrorHandling (vue.runtime.esm.js?5593:1854)
at VueComponent.Vue.$emit (vue.runtime.esm.js?5593:3888)
at VueComponent.click (QBtn.js?9c40:150)
at invokeWithErrorHandling (vue.runtime.esm.js?5593:1854)
at HTMLButtonElement.invoker (vue.runtime.esm.js?5593:2179)
at HTMLButtonElement.original._wrapper (vue.runtime.esm.js?5593:6917)
czy ma ktoś jakieś wskazówki? Z góry dzięki