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

Add support for lifecycle callbacks. #304

Merged
merged 8 commits into from
Sep 20, 2015

Conversation

alexandred
Copy link
Contributor

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:

Volt.current_app.on("user_connect") do |user_id|
# fetch user
end

Volt.current_app.on("user_disconnect") do |user_id|
# fetch user
end

…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.
@ryanstout
Copy link
Member

@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)
Copy link
Member

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.

@ryanstout
Copy link
Member

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

@alexandred
Copy link
Contributor Author

@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)
Copy link
Member

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?

@alexandred
Copy link
Contributor Author

@ryanstout typo fixed! it's a bit late to be fixing up PRs, thought it was weird that the specs regressed :)

@ryanstout ryanstout merged commit 4f6aa09 into voltrb:master Sep 20, 2015
@ryanstout
Copy link
Member

Nice work! Merged!

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.

None yet

2 participants