0

SO i am trying to listen to event that create channel dynamically with the the ids of the two users involved. I ma using pusher and echo for this purpose

the event successfully fired from my controller and is being recorded but echo does not listens to that event. I am using guards as the conversation will be between two admins

My channel.php code is

Broadcast::channel('chatchannel.{reciever_id}.{sender_id}', function ($user, $reciever_id, $sender_id) {
    if((int) auth()->guard('admin')->user()->id === (int) $reciever_id || (int) auth()->guard('admin')->user()->id === (int) $sender_id){
        return true;
    }else{
        return false;
    }

});

app.js file looks like this

Echo.private('chatchannel.'+app_sender_id+'.'+app_reciever_id)
    .listen('.chatEvent', (e) => {
        console.log('subscribed');
});

I did this change in my broadcastingerviceprovider.php file according to online soultions but it did not work

Broadcast::routes(['middleware' => 'auth:admin']);

I looked for all the solutions online but could not find anything that is of actual help. Can anyone guide me on how to get it working.

  • Does this issue still exists? I may answer this. I have added related-question you might know. :) https://stackoverflow.com/questions/74484555/how-to-reset-channel-of-window-echo-on-changing-of-route-reactjs – smzapp Nov 22 '22 at 07:26

1 Answers1

0

Your broadcast channel is chatchannel.{reciever_id}.{sender_id}. However your client channel is chatchannel.'+app_sender_id+'.'+app_reciever_id

This means, for a sender of A and receiver of 2 you would have the following channels:

Broadcast - chatchannel.2.A

Client - private-chatchannel.A.2.

Channel names must match for the client to receive the broadcast event. You should ensure the sender and receiver Id are in the same order on both systems and that you are using private channels in both scenarios.

doydoy
  • 4,021
  • 3
  • 20
  • 33
  • Actually i already noticed this thing before posting and tried giving channel static but it did not work – faiza sharif Oct 01 '22 at 04:08
  • When I followed the same steps with Laravel default authentication, the very same worked but now that i have employed it in my project, it is not working ..I think it has something to do with authentication using guards...so i don't know where i am going wrong – faiza sharif Oct 01 '22 at 04:26