Comments (20)
@maxpaynestory Hey -- just wanted to say he may have not used this but I really appreciate your adding it! We have an app where a user can be part of multiple companies, so when they switch companies we need to completely disconnect them from the other company's pusher channel and resub. This saved the day.
from echo.
@maxpaynestory actually, I may have spoken too soon :) I'm not seeing the disconnect method in the suggestions nor is it disconnecting from Pusher. If you have any ideas, let me know!
Edit: Nope, I did not, it works exactly as expected. Just had some cached code or something. Thank you!
from echo.
@elasticsteve Pull request just got merged. Could you please test it and let me know if it works for you.
from echo.
You can use ".leave()" method which is described in the doc
from echo.
@elasticsteve I have added the disconnect functionality inside my pull request. Hope it helps
from echo.
But that's not the same. You only leave a channel with this, which still keeps the Pusher connection open, I saw. Only pusher.disconnect() will close it, which is not available through Echo.
from echo.
@elasticsteve It would be really useful if you could give your use case as example.
from echo.
I said it in my first comment: to disconnect users keeping their tabs open. It's a common problem with Pusher, because it eats up all your available connections and you max out.
from echo.
@elasticsteve I mean, could you write some pseudo code implementation of that. How would you use .disconnect() if it were implemented. Will you need .reconnect() ?
The approach I'm thinking on right now is to disconnect from Pusher on .leave() call without channel name argument
Echo.leave() // this.pusher.disconnect()
Echo.leave('my-channel') // his.channels[name].unsubscribe()
Whats your opinion on this?
from echo.
You open a connection with new Echo();
At that moment Pusher shows an active connection, even if there is no listener subscribed. We need something to close that connection again, so Pusher releases the connection. On my account I have a max of 200 connections, but if people just leave their tabs open on a computer that is on all day or at work, I run out of connection within hours. Pusher doesn't disconnect. Even worse if one user has my app on tabs, they eat up 4 connections! You can see how soon you run out.
I think Echo. disconnect(); would be brilliant for that, similar to pusher.disconnect()
from echo.
Ok Im going to show you how I use Echo with ReactJS for my app and why I'm concerned about adding .disconnect() wouldn't be that easy as it seems:
// AppEchoInstance.js
import Echo from 'laravel-echo'
export default new Echo({/* my app pusher config */})
-----------------
// NotificationsComponent.js
import AppEchoInstance from 'AppEchoInstance'
...
componentDidMount() {
// Using single instance here I'm having only one connection per page, not multiple if I'm not wrong
AppEchoInstance
.channel('my-channel-1')
.listen('event1', () => {})
.listen('event2', () => {})
.listen('event3', () => {})
AppEchoInstance
.channel('my-channel-2')
.listen('event4', () => {})
.listen('event5', () => {})
}
componentDidUpdate() {
if (subscribeToOneMoreChannel) {
AppEchoInstance
.channel('my-channel-3')
.listen('event6', () => {})
.listen('event7', () => {})
}
}
...
-----------------
// MainComponent.js
import AppEchoInstance from 'AppEchoInstance'
...
// User leaves tab
window.onblur = function() {
AppEchoInstance.disconnect() // ok we did it
}
// User comes back to this tab
window.onfocus = function () {
// What we do here then?
// AppEchoInstance.disconnect()
}
...
So what I have to do with my shared Echo instance when user comes back to the tab? I think I want to call .reconnect() on my instance i guess? Then I need to resubscribe to all channels I have in this instance?
from echo.
I would't use it like this this. It's too extreme. I would use a timer tracking long inactivity.
Of course the problem is that mobile phones just stop javascript when the tab is not active or the browser hidden. I heard there are new way, but I'm not familiar with it. There whole thing became such a nightmare for me that I actually don't use Pusher / Echo now. It's not essential for my app, but it would have been nice for some real time updates and messages. Since they are not essential for my app, it's not worth doing right now, because I would run out of max connections all the time and it would ruin everything. Unless we find a better way of dealing with inactive user tabs or even hidden browsers, I can't really see Pusher going very far in terms of mainstream, where the real time websocket updates are not a "must", but rather an expensive pain in the neck.
from echo.
@elasticsteve thanks for sharing your experience tho. I think that disconnect should be added after all but I want someone from echo team to share their thoughts on its implementation first.
from echo.
var echo = new Echo()
echo.connector.pusher // this is where instance of Pusher is.
I guess you could try to call .disconnect() on it.
from echo.
Thanks, I will. How would I re-connect again?
from echo.
@elasticsteve at this point I guess there is nothing better than call new Echo()
again
from echo.
ok, just wanted to be sure it's the right thing to do.
from echo.
Great!
from echo.
@maxpaynestory Sorry, I'm not using Pusher anymore in the app I'm developing. We will need it later (in a few months again) for new features.
from echo.
then i guess this issue can be closed?
from echo.
Related Issues (20)
- #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
- Dont can get the returns of websocket
- dont cant get returns in console.log of the websocket, HOT 2
- ReferenceError: Property 'Pusher' doesn't exist HOT 4
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.