question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stop listening to channel.here(), .joining() and leaving()

See original GitHub issue

Originally commented this in #51, but this deserves its own issue imo.

I want to stop listening to the pusher:member_added and pusher:member_removed events that are registered by channel.joining() and channel.leaving(). I tried channel.stopListening('pusher:member_added', callback); and some other things, but this doesn’t seem to work. I also don’t want to run channel.leave() and channel.join() every time my page rerenders.

It seems like this is being caused by the here, joining and leaving methods not using the actual callback you pass into it (like the listenForWhisper method does), but instead creating one for itself, making it impossible to remove it afterwards from the other side of the library: https://github.com/laravel/echo/blob/b583f2641b51e7b4ab39c5bb03626be8add47722/src/channel/pusher-presence-channel.ts#L22-L28

Can anyone think of a non-breaking fix for this?

I can only think of these (breaking) changes:

This changes the return type from this to a function you can call to remove the event listener:

here(callback: Function): PusherPresenceChannel {
    function removableCallback(data) {
        callback(Object.keys(data.members).map((k) => data.members[k]));
    }

    this.on('pusher:subscription_succeeded', removableCallback);

    return () => this.stopListening('pusher:subscription_succeeded', removableCallback);
}

This moves the burden of formatting the callback’s payload to the user, but it would allow us to run channel.stopListening('pusher:subscription_succeeded', callback) (not taking into consideration the fact that listening and stopListening seem to format the listener keys 👀 ):

here(callback: Function): PusherPresenceChannel {
    this.on('pusher:subscription_succeeded', callback);

    return this;
}

_Originally posted by @AdrianMrn in https://github.com/laravel/echo/issues/51#issuecomment-850483993_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
driesvintscommented, Jun 4, 2021

Going to close this one as it’s best to follow up in the PR. Feel free to send it in when you can.

1reaction
driesvintscommented, Jun 3, 2021

@AdrianMrn so yes feel free to attempt a pr which you feel is best 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Broadcasting - Laravel - The PHP Framework For Web Artisans
The channel method accepts two arguments: the name of the channel and a callback which returns true or false indicating whether the user...
Read more >
Manage channel memberships - YouTube Help
Recent videos that members joined from: Monitor the top performing videos which viewers became members on. Recent comments by members: Easily find the...
Read more >
Zoom Meeting API - Zoom App Marketplace
Meetings The client.join() function is used to start and join Zoom Meetings. On this page Prerequisites Start meeting Join meeting Join… Reference.
Read more >
Gateway - Discord Developer Portal
An app typically sends events when connecting and managing its connection to the ... bytearray() # here you can treat `msg` as either...
Read more >
Game of Thrones | Official Website for the HBO Series
See the full list of the Game of Thrones cast and characters here. Daenerys Targaryen.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found