-
Notifications
You must be signed in to change notification settings - Fork 197
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
Add support for lifecycle callbacks. #304
Conversation
…ser_connect' and 'user_disconnect' which are triggered whenever the user logs in or logs out. These events also trigger when the user navigates to the app with a valid session cookie or closes the window.
@alexandred This looks great, any chance you could add some integration specs for this? (on the kitchen sink app) |
@@ -114,6 +114,10 @@ def login(username, password) | |||
end | |||
|
|||
def logout | |||
# Notify the backend so we can remove the user_id from the user's channel | |||
UserTasks.logout(user_id: Volt.current_app.cookies._user_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the user_id cookie is encrypted and in this case will get passed as metadata since your calling UserTasks.logout before the actual logout. So you can probably just remove the arguments.
@alexandred also, What do you think about doing a 'connect'/'disconnect' events as well? (So ones for when a user connects, and one just for general anyone connects. |
2804772
to
cb2bd2b
Compare
@ryanstout i've written specs for the user_connect/user_disconnect events. i've also added general client_connect/client_disconnect events. |
@@ -85,6 +112,18 @@ def closed | |||
|
|||
begin | |||
@@dispatcher.close_channel(self) | |||
|
|||
# Check for volt_app (@@dispatcher could be an ErrorDispatcher) | |||
if @@dispatcher.respond_to(:volt_app) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be respond_to?
Would you mind updating?
@ryanstout typo fixed! it's a bit late to be fixing up PRs, thought it was weird that the specs regressed :) |
Nice work! Merged! |
Currently the only events are 'user_connect' and 'user_disconnect' which are triggered serverside whenever the user logs in or logs out. These events also trigger when the user navigates to the app with a valid session cookie or closes the window.
These events can trigger a block to run by adding the following code to a volt app: