send back response from client to Private Channel
I have a private Channel that dispatch an event and sends data from server to client.
I handle it with laravel echo like a charm.
now I want to send back response from my client to server (to channel).
is this possible?
how can I trigger event in js?
how can I handle that in laravel?
so for the test, I added this code to my Frontend:
Echo.private('chat.2')
.whisper("TestEvent", {
name: 'JohnDou'
});
and now in my WebSockets-dashboard, I have this:
{
"socketId": "615305305.843662160",
"event": "client-TestEvent",
"channel": "private-chat.2",
"data": {
"event": "client-TestEvent",
"data": {
"name": JohnDou
},
"channel": "private-chat.2"
}
}
is there any way that I can get name with laravel and do whatever I want?
for whispering you must use presence channel.
Echo.join("emergency.conversation.{{ $emergencyRequest->id }}").whisper('userStatus.' + status, { user: outUser, status: status });
also for listen to whisper :
`
Echo.join("emergency.conversation.{{ $emergencyRequest->id }}") .joining((user) => { if (myId != user.id) informUserAboutStatus(user, "{{ __('joined the conversation') }}"); }) .leaving((user) => { if (myId != user.id) informUserAboutStatus(user, "{{ __('left the conversation') }}"); }) .listen('ConversationMessageSent', (e) => { console.log(e); if (e.user.id != myId) { stopClearTimer(); removePreviousInformer(); $('.messages').append(prepareIncomeMessage(e.message, e.user)); stopClearTimer(); scrollToBottom(100); } }).listenForWhisper('userStatus.1', (info) => { informUserAboutStatus(info.user, "{{ __('is typing') }}"); }).listenForWhisper('userStatus.2', (info) => { informUserAboutStatus(info.user, "{{ __('is uploading file') }}"); }).listenForWhisper('userStatus.10', (info) => { informUserAboutStatus(info.user, "{{ __('is recording voice') }}"); }).listenForWhisper('userStatus.11', (info) => { informUserAboutStatus(info.user, "{{ __('is recording video') }}"); }).listenForWhisper('userStatus.12', (info) => { informUserAboutStatus(info.user, "{{ __('is uploading voice') }}"); }).listenForWhisper('userStatus.13', (info) => { informUserAboutStatus(info.user, "{{ __('is uploading video') }}"); }); `
any feedback on this i am facing a similar issue. I am able to send events but i am unable to use the data in laravel to perform operations
any update here?