Giter VIP home page Giter VIP logo

Comments (14)

IfnotFr avatar IfnotFr commented on July 20, 2024 4

The stopListening method will only work with pusher driver.

With SocketIO there is no way to remove a previously added listener through Echo. The only way is to use the SocketIO API directly.

Adding a listener :

Echo.connector.socket.on('blah', listener)

Removing the listener :

Echo.connector.socket.removeListener('blah', listener)

But with this method you may verify the channel provenance as it will listen all subscriptions.

If we want a straightforward native solution we may need to add a way for reverting the on method :

  • Allow unbind to be specific instead of global
  • Save on the fly listener for reusing him for the removal
  • Create a unlisten with :
this.socket.removeListener(event, previousListener); // With our previous on the fly listener
this.unbind(event, listener); // With our new specific unbinder

from echo.

GovarJabbar avatar GovarJabbar commented on July 20, 2024 4

window.Echo.leave('channel-name')

from echo.

indigoram89old avatar indigoram89old commented on July 20, 2024 3

this is necessary!

from echo.

erinalahorlbeck avatar erinalahorlbeck commented on July 20, 2024 3

+1 Definitely need this method.

from echo.

itsmill3rtime avatar itsmill3rtime commented on July 20, 2024 3

@shorlbeck @indigoram89 @vexii @deiucanta

i did some searching around the web an was unable to find a posted solution but with some tinkering i found a temporary solution until they implement something in echo

in my vue component i wanted to only stop listening to events and not unsub from the channel when i went to a different page (component). so i put this within destroyed function but you could use it wherever you see fit

destroyed: function () {
            let self = this;
            Echo.private('projects.' + self.$route.params.project)
                .stopListening('DeploymentStepCommandAddedEvent')
                .stopListening('DeploymentStepCommandMovedEvent')
                .stopListening('DeploymentStepCommandRemovedEvent')
                .stopListening('DeploymentStepCommandUpdatedEvent');
        },

and these match up to the events i listened for

Echo.private('projects.' + self.$route.params.project)
                .listen('DeploymentStepCommandAddedEvent)
           ...... 

Thanks @vexii for setting me on the right path

from echo.

vexii avatar vexii commented on July 20, 2024 2

it looks like the is an stopListening call in pusher-channel.ts

from echo.

IfnotFr avatar IfnotFr commented on July 20, 2024 2

With provenance i mean the channel name where the message comes from. In the message payload you have this information. If this is not important for you or if you have only one channel you can use this solution as is :)

If I have the time i will make a PR for this, but actually is am quite busy, thats why I draft a simple how to, maybe someone else have the time for this :/

from echo.

pschaub avatar pschaub commented on July 20, 2024 1

We really need this. 👍 @ifnot Do you know a workaround how to only listen on specific channels and still be able to remove the listener? We are looking for a workaround to remove the listening again. We use SocketIO.

from echo.

erinalahorlbeck avatar erinalahorlbeck commented on July 20, 2024

But with this method you may verify the channel provenance as it will listen all subscriptions.

@ifnot Can you please explain what this means? I can't find anything about "provenance" in the docs.

from echo.

an4ger avatar an4ger commented on July 20, 2024

Any news? It's a really big problem(

from echo.

cnk789 avatar cnk789 commented on July 20, 2024

Any updates?

from echo.

driesvints avatar driesvints commented on July 20, 2024

We're open to PRs.

from echo.

skollro avatar skollro commented on July 20, 2024

Found a workaround to unbind a specific listener from an underlying Pusher channel subscription that I'd like to share with you. 👍🏻

const listener = (e) => { ... }
const channel = Echo.private('channel-name').listen('MyEvent', listener)

channel.subscription.unbind(channel.eventFormatter.format('MyEvent'), listener)

from echo.

AdrianMrn avatar AdrianMrn commented on July 20, 2024

Is there a way 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.

EDIT:
cont in #312

from echo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.