Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP feat: Terminates realtime on client logout #548

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ptbrowne
Copy link
Contributor

@ptbrowne ptbrowne commented May 8, 2019

The bar inits realtime and attaches handlers on initialization. The realtime does add a "logout" event handler that unsubscribeAll() but I think it is brittle to rely on this fact. When subscribing to something, the code should also clean behind itself. This way, if the realtime library decides to change (and not unsubscribe all events on client logout), the bar code would still work.


To fix this problem, initializeRealtime now returns a function that serves to unsubscribe handlers. When the stack-client calls initializeRealtime, it also attaches a one-time handler to terminate the realtime on logout.

Another potential problem was that the bar, if initialized with a logged out client would never initialize the realtime. To mitigate this problem: if the bar is initialized with a logged out client, it attaches a one-time handler on the "login" event to initialize the realtime. I am still wondering if this is something that is possible (the bar being set up with a logged out client), see #548 (comment). At the moment, Banks inits the bar on client "login" but it puts the burden of instantiating the bar on the app. I think it could be simpler, and the bar could automatically connect/disconnect from the DOM on itself. It could be done in another commit, but I am curious about your thoughts.

@ptbrowne ptbrowne changed the base branch from new_realtime to refactor-terminating-realtime May 8, 2019 09:28
@ptbrowne ptbrowne force-pushed the terminating-realtime branch from 35ab7dd to c53f650 Compare May 8, 2019 09:29
@ptbrowne ptbrowne force-pushed the refactor-terminating-realtime branch from 456019a to 3a0d235 Compare May 8, 2019 09:37
@ptbrowne ptbrowne force-pushed the terminating-realtime branch 2 times, most recently from 5877c87 to a2fce7d Compare May 8, 2019 09:46
@ptbrowne ptbrowne force-pushed the refactor-terminating-realtime branch from 3a0d235 to 22e318c Compare May 8, 2019 09:47
@ptbrowne ptbrowne requested review from edas, Crash-- and kosssi May 8, 2019 09:49
src/lib/stack-client.js Outdated Show resolved Hide resolved
@ptbrowne ptbrowne force-pushed the terminating-realtime branch from a2fce7d to 52b4ecf Compare May 8, 2019 21:36
Copy link
Contributor

@CPatchane CPatchane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that initialize the client and get logged in should be the responsability of the application and the bar should throw an error if it's initialize with a not logged in client, the bar can't work for now if the client is not usable anyway

@ptbrowne ptbrowne force-pushed the refactor-terminating-realtime branch 6 times, most recently from 9ceb2cb to 9b1c4e7 Compare May 9, 2019 09:06
@ptbrowne ptbrowne changed the title feat: Terminates realtime on client logout WIP feat: Terminates realtime on client logout May 27, 2019
@ptbrowne ptbrowne force-pushed the refactor-terminating-realtime branch from 9b1c4e7 to e940330 Compare May 27, 2019 16:12
@ptbrowne ptbrowne force-pushed the terminating-realtime branch from 52b4ecf to f9c4110 Compare May 27, 2019 16:21
@ptbrowne ptbrowne changed the base branch from refactor-terminating-realtime to master May 27, 2019 16:23
ptbrowne added 2 commits May 27, 2019 18:53
Attach on one-time handler to unsubscribe realtime
handlers on client logout
@ptbrowne ptbrowne force-pushed the terminating-realtime branch from f9c4110 to 83d7165 Compare May 27, 2019 16:53
@kosssi kosssi removed the request for review from cedricmessiant July 10, 2019 14:01
@kosssi kosssi removed their request for review July 10, 2019 14:01
}
if (cozyClient.isLogged) {
onLogin()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu ne tentes pas de réagir à l'événement de login s'il arrive plus tard ?

@Crash--
Copy link
Contributor

Crash-- commented Oct 22, 2019

@ptbrowne Les issues dont du parles on clairement besoin d'être fixée. Mais vu qu'un gros boulot a été fait en parallèle sur le realtime et l'intégration dans la bar, est-ce qu'on a encore besoin de cette PR ?

@ptbrowne
Copy link
Contributor Author

Mais vu qu'un gros boulot a été fait en parallèle sur le realtime et l'intégration dans la bar

Tu parles de quoi en particulier ?

@ptbrowne
Copy link
Contributor Author

Ca me dérange pas de rouvrir une issue "Faire de la bar un plugin cozy-client" :)

@Crash--
Copy link
Contributor

Crash-- commented Oct 22, 2019

Tu parles de quoi en particulier ?

De rien en fait, je pensais qu'on avait fait le travail pour AF après cette PR, mais en fait non, elle en découle.

@nono
Copy link
Member

nono commented Feb 4, 2021

@ptbrowne est-ce que tu veux rebaser cette PR?

@ptbrowne
Copy link
Contributor Author

I am leaving this open as it seems important that the bar closes its realtime sockets after logout, I have not checked if the behavior is still happening, cc @Crash--

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants