Package velox.gui.browser
Class UserTokenBrowserListener
java.lang.Object
velox.gui.browser.UserTokenBrowserListener
- All Implemented Interfaces:
BrowserListener
BrowserListener that exposes a user identification API to the loaded page.
After the page is loaded, it can call getUserToken() to obtain a token identifying the current user,
see UserTokenHelper.generateToken(). The JS function definition injected into the page is in
resources/browser/GetUserToken.js.
Not wired in by default. See BrowserSettings.setListener(BrowserListener).
Extensible. To expose more functions, override handleFunction(velox.gui.browser.Browser, java.lang.String, com.google.gson.JsonObject, java.util.function.Consumer<java.lang.String>) and handle your functions there,
delegating to super.handleFunction for the rest. To inject the JS definitions of those functions,
override onPageLoaded(velox.gui.browser.Browser, java.lang.String, int) and call super.onPageLoaded as well.
Message protocol: the page sends a JSON object with a functionName field plus function-specific
arguments, and receives the result as JSON through the bmMessage callback.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanhandleFunction(Browser browser, String functionName, com.google.gson.JsonObject message, Consumer<String> callback) Override to handle additional functions.voidCalled when the page sends a message by callingbmMessage(message, optional callback).voidonPageLoaded(Browser browser, String url, int statusCode)
-
Field Details
-
GSON
protected static final com.google.gson.Gson GSON
-
-
Constructor Details
-
UserTokenBrowserListener
public UserTokenBrowserListener()
-
-
Method Details
-
onPageLoaded
- Specified by:
onPageLoadedin interfaceBrowserListener
-
onMessage
Description copied from interface:BrowserListenerCalled when the page sends a message by callingbmMessage(message, optional callback).- Specified by:
onMessagein interfaceBrowserListener- Parameters:
callback- used to send the response back to the page if it was set in bmMessage above. Otherwise, calling has no effect. Can be freely called from any thread at any time, but only once.
-
handleFunction
protected boolean handleFunction(Browser browser, String functionName, com.google.gson.JsonObject message, Consumer<String> callback) Override to handle additional functions. The default implementation handlesgetUserToken.
-