Class BrowserService

All Implemented Interfaces:
CtxEventListener, ContextHandleAware, HandleAware, Ready, ReadyListener

public final class BrowserService extends AbstractService
Service that manages browsers connected to this service. In a typical single-node environment that has a screen, there is a single browser instance running on the same node as this service. In more complex devices, other nodes may run browsers that are controlled by the node this service is running on. For example, consider a device with a main control node and one or more display nodes. The display nodes may run just a browser that connects back to the main control node. In this case each browser instance is identified by the nodeId of the node it is running on and the name of the browser.

Typically, a node will run a single browser. In this case the browser has no name (empty string). This service provides several methods for fetching a browser. Use the one the best matches the needs of your device.

A Browser object is a logical browser abstraction and allows navigation commands to be sent to the browser. Browser objects can exist without a corresponding browser instance. For example, the browser may be on another node and that node is powered off. The Browser object is still accessible and can accept commands. When the actual browser instance connects, the last navigation command will be sent to the browser.

Since:
1.0
Version:
2023-03-06
  • Method Details

    • getLocalBrowser

      public Browser getLocalBrowser()
      Returns the default Browser running on the local node. This is a convenience method for a typical single-node device that runs a single browser locally. User code can interact with the Browser object but will have no effect until a corresponding BrowserSession connects to the service. At that point, the current Browser object state is sent to the actual browser instance. This allows URLs to be sent before the browser is actually available.
    • getBrowser

      public Browser getBrowser(NodeId nodeId, String name)
      Returns the named browser on the specified nodeId. If there is no Browser then it is created. User code can interact with the Browser object but will have no effect until a corresponding BrowserSession connects to the service. At that point, the current Browser object state is sent to the actual browser instance. This allows URLs to be sent before the browser is actually available.
      Parameters:
      nodeId - the node to return the browser for.
      name - the name of the browser on the node
    • getBrowser

      public Browser getBrowser(BrowserId browserId)
      Returns the Browser with the specified BrowserId , which is simply the combination of a nodeId and name. If there is no Browser with the specified id then it is created. User code can interact with the Browser object but will have no effect until a corresponding BrowserSession connects to the service. At that point, the current Browser object state is sent to the actual browser instance. This allows URLs to be sent before the browser is actually available.
      Parameters:
      browserId - the id of the browser to return
    • getBrowsers

      public Collection<Browser> getBrowsers()
      Returns a collection of existing Browser objects. These may or may not be connected to a real browser instance.
    • goToUrl

      public void goToUrl(String url)
      Navigates the browser on the current node to the specified URL.
      Parameters:
      url - the URL to navigate to
    • goToUrl

      public void goToUrl(String url, boolean redirect)
      Navigates the browser on the current node to the specified URL with optional redirect.
      Parameters:
      url - the URL to navigate to
      redirect - if true, bounce through a redirect URL
    • goToUrl

      public void goToUrl(NodeId nodeId, String url, boolean redirect)
      Navigates the default browser on the specified node to the specified URL.
      Parameters:
      nodeId - use the default browser on the node, null will use the local node
      url - the URL to navigate to
      redirect - if true, bounce through a redirect URL
    • goToUrl

      public void goToUrl(NodeId nodeId, String name, String url, boolean redirect)
      Navigates the named browser on the specified node to the specified URL.
      Parameters:
      nodeId - use the named browser on the node, null will use the local node
      name - name of the browser instance to use
      url - the URL to navigate to
      redirect - if true, bounce through a redirect URL
    • goToUrl

      public void goToUrl(BrowserUrl request)
      Navigates to the url contained in the navigation request.
      Parameters:
      request - the browser url request
    • goToIntent

      public void goToIntent(String type)
      Navigates the browser on the current node to the specified intent.
      Parameters:
      type - the intent type to navigate to
    • goToIntent

      public void goToIntent(NodeId nodeId, String type)
      Navigates the default browser on the specified node to the specified intent.
      Parameters:
      nodeId - use the default browser on the node, null will use the local node
      type - the intent type to navigate to
    • goToIntent

      public void goToIntent(NodeId nodeId, String name, String type)
      Navigates the named browser on the specified node to the specified intent.
      Parameters:
      nodeId - use the named browser on the node, null will use the local node
      name - name of the browser instance to use
      type - the intent type to navigate to
    • goToIntent

      public boolean goToIntent(BrowserIntent intent)
      Resolve the specified intent and navigate the browser accordingly. Returns true if the intent resolved to a url.
      Parameters:
      intent - the intent of the navigation