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

Recover: implement callback proposal #266

Closed
wants to merge 11 commits into from
Closed

Recover: implement callback proposal #266

wants to merge 11 commits into from

Conversation

SimonWoolf
Copy link
Member

regex failed for connectionKeys with exclamation marks, negative
connection serials, etc. Client lib shouldn't assume anything about the
format of the connection key except that it doesn't contain a colon, so
a simple split(':') is safest
You can't use the same recoveryKey more than once, so unpersist after a
successful recovery.

Also stop persisting on connect: should only be useful in browsers that
don't support beforeunload, but that's a subset of browsers that don't
support sessionstorage, so not much point
as ably-js tests emit beforeunload events to test on-page-refresh
functionality
@SimonWoolf
Copy link
Member Author

Also, just noticed that persistence was set to last for only 15s (connectionPersistTimeout) @paddybyers why was that so low - is there a reason to have it be any lower than the realtime connection ttl? Or did the realtime connection ttl used to be only 15s? (On the assumption it's just out of date, added d86686d to change it to connectionStateTtl)


var recoverFn = self.options.recover,
lastSessionData = getFromSession && getFromSession(sessionRecoveryName);
if(lastSessionData && lastSessionData.host === window.location.host && typeof(recoverFn) === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to check lastSessionData.host == window.location.host, I would have thought the security model in the browser would look after that for us?

Copy link
Member Author

Choose a reason for hiding this comment

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

Er, yep, you're completely right. Not sure why I was thinking. 😣

@paddybyers
Copy link
Member

@paddybyers why was that so low - is there a reason to have it be any lower than the realtime connection ttl? Or did the realtime connection ttl used to be only 15s?

Because it was only intended to cover the time for the refresh to happen; not the time for the connection in the refreshed page to succeed.

However, if there is a loss of connectivity it's equally possible that the page refresh stalls so perhaps it could be the same as the connection ttl.

var eraseCookie = (typeof(Cookie) !== 'undefined' && Cookie.erase);
var connectionKeyCookie = 'ably-connection-key';
var connectionSerialCookie = 'ably-connection-serial';
var getFromSession = (typeof(SessionStorage) !== 'undefined' && SessionStorage.get);
Copy link
Member

Choose a reason for hiding this comment

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

I find this approach a little odd. Why are we creating a SessionStorage object that sometimes has an interface with get, set and remove, and other times without the method. I would prefer we either:

  • Have a method that on SessionStorage such as isSupported() but the interface remains the same.
  • My preference: If sessionStorage is not supported, we should have noop methods in their place that simply don't do anything.

Copy link
Member Author

@SimonWoolf SimonWoolf May 9, 2016

Choose a reason for hiding this comment

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

Sure, happy to do that. Though will still need to do (typeof(SessionStorage) !== 'undefined' && ... because in node, the sessionstorage.js file isn't even loaded, so the SessionStorage object doesn't exist

Copy link
Member

Choose a reason for hiding this comment

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

Why not just load it and have noop methods like unsupported browsers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually on second thoughts I think it'd be simpler to leave it as-is. You still need the sessionStorageSupported checks because of node (eg because window.addEventListener isn't defined in node), so the change doesn't really let you simplify things much, sadly. 285ca82

Copy link
Member

Choose a reason for hiding this comment

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

Why not just load it and have noop methods like unsupported browsers?

Personally I would prefer to test for the existence of the interface, and use it if present.

Copy link
Member Author

@SimonWoolf SimonWoolf May 9, 2016

Choose a reason for hiding this comment

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

@mattheworiordan sorry, github hadn't loaded your comment when I posted my last one.

The library uses a pattern of browser-specific helpers in browser/lib and node ones in node/lib (and each only loading those) for a bunch of things. I guess I wouldn't be against just having both load all files and using tests & noops if you'd prefer that (as long as you can convince Paddy), but doing that just for SessionStorage would make that inconsistent with the other browser-specific/node-specific libs, and doing it for everything would be a major refactor at this stage. So either way, I'm inclined to leave it as-is for now

Copy link
Member

Choose a reason for hiding this comment

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

Ok, fine, leave as-is

@mattheworiordan
Copy link
Member

Nice work, looks great. 👍

mattheworiordan added a commit to ably/docs that referenced this pull request May 7, 2016
mattheworiordan added a commit to ably/docs that referenced this pull request May 7, 2016
@paddybyers paddybyers mentioned this pull request May 8, 2016
@paddybyers
Copy link
Member

Closing in favour of #269

@paddybyers paddybyers closed this May 8, 2016
@SimonWoolf
Copy link
Member Author

Merged as 4c2c0d8

@SimonWoolf SimonWoolf deleted the recover branch May 20, 2016 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants