Comments (14)
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.
window.Echo.leave('channel-name')
from echo.
this is necessary!
from echo.
+1 Definitely need this method.
from echo.
@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.
it looks like the is an stopListening
call in pusher-channel.ts
from echo.
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.
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.
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.
Any news? It's a really big problem(
from echo.
Any updates?
from echo.
We're open to PRs.
from echo.
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.
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)
- Laravel Echo is not subscribing to private channel HOT 5
- Release 1.14.1 dist doesn't reflect latest source changes HOT 4
- React native: undefined is not an object (evaluating 'this.connector.channel') HOT 1
- #listenToAll for NullConnector HOT 1
- #encryptedPrivate does not work with NullConnector HOT 1
- PresenceChannel interface missing 'Whisper' method HOT 2
- Implement `.listenOnce` and `.isListening` HOT 1
- [Bug] PresenceChannel interface missing 'Whisper' method HOT 2
- Nuxtjs + VUE 2 to update vue 3 + vite not working echo HOT 2
- Always got pusher ouput while using socket.io HOT 1
- Not subscribing to Echo when you open SPA as PWA from Homescreen HOT 4
- All the names of the events must be prefixed with a dot HOT 1
- Uncaught TypeError: event is undefined HOT 2
- Connection fails in Chrome, works just fine in FF HOT 1
- Export connectors and channels alongside with Echo and abstract classes HOT 2
- Laravel Echo with Socket.io HOT 1
- Centrifugo Connector HOT 1
- Fatal error when using channel.listen HOT 3
- Leave channel and disconnect right after HOT 1
- listen method does not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from echo.