Git Product home page Git Product logo

Comments (20)

mcblum avatar mcblum commented on June 16, 2024 3

@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.

mcblum avatar mcblum commented on June 16, 2024 3

@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.

maxpaynestory avatar maxpaynestory commented on June 16, 2024 2

@elasticsteve Pull request just got merged. Could you please test it and let me know if it works for you.

from echo.

RusinovAnton avatar RusinovAnton commented on June 16, 2024 1

You can use ".leave()" method which is described in the doc

from echo.

maxpaynestory avatar maxpaynestory commented on June 16, 2024 1

@elasticsteve I have added the disconnect functionality inside my pull request. Hope it helps

from echo.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

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.

RusinovAnton avatar RusinovAnton commented on June 16, 2024

@elasticsteve It would be really useful if you could give your use case as example.

from echo.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

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.

RusinovAnton avatar RusinovAnton commented on June 16, 2024

@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.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

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.

RusinovAnton avatar RusinovAnton commented on June 16, 2024

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.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

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.

RusinovAnton avatar RusinovAnton commented on June 16, 2024

@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.

RusinovAnton avatar RusinovAnton commented on June 16, 2024
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.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

Thanks, I will. How would I re-connect again?

from echo.

RusinovAnton avatar RusinovAnton commented on June 16, 2024

@elasticsteve at this point I guess there is nothing better than call new Echo() again

from echo.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

ok, just wanted to be sure it's the right thing to do.

from echo.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

Great!

from echo.

steve-rhodes avatar steve-rhodes commented on June 16, 2024

@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.

maxpaynestory avatar maxpaynestory commented on June 16, 2024

then i guess this issue can be closed?

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.