Pancake/French Toast/Message API
Contents
- 1 User stories
- 1.1 As a front-end developer, I need a way to tell the native app to open a new layer containing a specific layer state.
- 1.2 As a front-end developer, I need a way to tell the native app to open a URL in the viewer.
- 1.3 As a front-end developer, I need the app to tell me when a layer has received focus so that I can check for updates and refresh data if necessary.
- 1.4 As a front-end developer, I need a way to securely verify that the user is authenticated so that I do not expose confidential information.
- 1.5 As a front-end developer, I need access to a shared store that persists across sessions. All layers should have access to this store.
- 2 Discussion
User stories
As a front-end developer, I need a way to tell the native app to open a new layer containing a specific layer state.
FrenchToast.openAppView(url)
As a front-end developer, I need a way to tell the native app to open a URL in the viewer.
FrenchToast.openWebView(url)
I don't think we need the name parameter. I don't think we want layers to be able to talk directly to each other. Instead, I believe we can stick to a service-oriented architecture based on URLs. -Gbrander
As a front-end developer, I need the app to tell me when a layer has received focus so that I can check for updates and refresh data if necessary.
What about a DOM event?
window.addEventListener('layerFocus', fn)
Focus isn't quite the same as active/visible. On the desktop, focus doesn't happen until an element in the window receives focus. I'm not sure how that plays out on touch devices. I think we want visibility
There is an actual API for this: PageVisibility but we would have to investigate browser support. As I understand it, our "layers" are going to be window object in UiWebViews or their equivalent, so this seems like the right place to start. I would rather polyfill this though than invent our own.
- http://davidwalsh.name/page-visibility
- https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API
- https://github.com/ai/visibility.js
As a front-end developer, I need a way to securely verify that the user is authenticated so that I do not expose confidential information.
// find out if the current session is valid FrenchToast.getSession() // to start browserid FrenchToast.startBrowserId(callback) // to validate the browserid token FrenchToast.validateBrowserIdReceipt(receipt, callback)
Can somebody who worked on the session stuff in the past verify that these could satisfy the user story? - Gbrander
What about the way it works today are we wanting to fix? This functionality currently resides in the misnamed/misplaced lib/signin. ISTM that the modules under service/* could be FrenchToast.*. Lets talk. - Sfoster
Use standard localStorage to serialize/deserialize persisted app data.
window.localStorage JSON.stringify JSON.parse
Can we confirm that the same localStorage is available between UIWebViews - Gbrander
(From mailing list) I found this configuration option: webSettings.setSupportMultipleWindows(true); And now storage events are sent to the other web views that are open in the same app. - St3fan
Discussion
I don't think we need a general message mechanism to talk to the app. I also don't think we need to be able to send messages to specific layers from specific layers. In general, I would like to make the coupling between layers loose, and based on requesting URLs be opened. The layer itself can decide what to do with the URL. -Gbrander
Agreed that urls should be the primary messaging mechanism. We also have storage events which (browser-support willing) should allow us to signal state changes like login/logout across windows/layers. I suspect there's still a need for the native/js messaging though. - Sfoster