laravel-websockets icon indicating copy to clipboard operation
laravel-websockets copied to clipboard

send back response from client to Private Channel

Open SirousFakhri opened this issue 4 years ago • 3 comments

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?

SirousFakhri avatar Oct 11 '21 10:10 SirousFakhri

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?

SirousFakhri avatar Oct 12 '21 09:10 SirousFakhri

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') }}"); }); `

SaedyMoz avatar Oct 25 '21 17:10 SaedyMoz

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

varunvarde avatar Dec 26 '21 08:12 varunvarde

any update here?

Dmmoim avatar Jan 24 '24 18:01 Dmmoim