Class Client

java.lang.Object
com.jbstrap.core.messagebus.MessageBus
com.jbstrap.core.websocket.Client

public class Client extends MessageBus

The class representing a client that is connected to the application.

Through this class, certain properties of a connected client can be accessed. Furthermore, connection with the client can be maintained through this class. This is where, for example, messages or JavaScript could be sent between clients. Also, through this class, navigation can be done too.

Certain functions of the class are executed by the class methods. These functions are described (with examples) below.

Since:
4.0
Author:
JBStrap
  • Constructor Details

    • Client

      public Client(javax.websocket.Session session, String baseUrl, String host) throws IllegalAccessException
      Parameters:
      session - The instance of the WebSocket session
      baseUrl - The base URL of the application
      host - The server host name
      Throws:
      IllegalAccessException - If the license is not valid, or if the amount of users exceeds the allowed number.
  • Method Details

    • sendBroadcastMessage

      public final void sendBroadcastMessage(BaseMessage message)
      Parameters:
      message - The message. Must extend from BaseMessage class
    • getClientId

      public final String getClientId()
      Gets the client ID
      Returns:
      The client ID
    • getSession

      public final javax.websocket.Session getSession()
      Gets the client's WebSocket session
      Returns:
      The client's WebSocket session
    • getUserAgent

      public final String getUserAgent()
      Gets the user agent
      Returns:
      The user agent
    • getHost

      public final String getHost()
      Gets the browser host
      Returns:
      The host
    • getBaseURL

      public String getBaseURL()
      Gets the application's baseURL
      Returns:
      The application's baseURL
    • getPlatform

      public final String getPlatform()
      Gets the client's platform
      Returns:
      The platform (in String)
    • getLanguageCode

      public final String getLanguageCode()
      Gets the client's language code, that is set in their browser.
      Returns:
      The user's language code
    • getCurrentUI

      public final UI getCurrentUI()
      Gets the currently displayed UI
      Returns:
      The instance of the currently displayed UI, or null if none are displayed
    • getCurrentPage

      public final BasePage getCurrentPage()
      The page that is currently displayed
      Returns:
      The instance of the currently displayed page. If no page is displayed, returns with null
    • getCurrentUser

      public final CurrentUser getCurrentUser()
      Gets the users who are currently logged in
      Returns:
      The CurrentUser object, containing the user's information, or null, if no user is signed in.
    • registerEvents

      public final void registerEvents(Component<?> component)

      Registers the events of the component (and it's subcomponents) on the client

      This method only needs to be used if developing a custom component. When using JBStrap components, the events are registered automatically.

      Parameters:
      component - The component whose events we want to register.
      Throws:
      NullPointerException - if the specified component is null
    • runInitScripts

      public final void runInitScripts(Component<?> component)

      Runs the init JavaScript(s) of the component and it's subcomponents on the client.

      This method only needs to be used if developing a custom component. When using JBStrap components, the components are initialized automatically.

      Parameters:
      component - The component that will be initialized
    • closePage

      public Client closePage(BasePage page)

      Closes the specified page.

      Only usable if the page cache is used (ie, it is only hidden, but not closed). If we close a page, if the cache isn't used, or has no pages in it, then the user will be navigated to the entry point. This entry point can be set by using the ENTRY_POINT JBStrap parameter

      If a page is closed, and the page cache is used , and it contains a page other than the closed page, then the user will be navigated to previously (before the closed one) opened page. If the cache's first page is closed, then the user will be navigated to the page that is after it in the cache.

      Parameters:
      page - The page to be closed
      Returns:
      The client object
    • setTitle

      public Client setTitle(String title)
      Sets the browser title text
      Parameters:
      title - The title text
      Returns:
      The client object
    • setApplicationIcon

      public Client setApplicationIcon(String iconFile)
      Sets the application icon (favicon)
      Parameters:
      iconFile - The relative (to the application) URL of the image
      Returns:
      The client object
    • runJavaScript

      public final void runJavaScript(String... javaScripts)
      Runs the specified JavaScript on the client
      Parameters:
      javaScripts - The JavaScript to be used
    • runJavaScript

      public final void runJavaScript(List<String> javaScripts)
      Runs the specified JavaScript on the client
      Parameters:
      javaScripts - The list of the JavaScript
    • runBatch

      public final void runBatch()
    • say

      public final void say(String title, String message)
      Shows the specified message to the user
      Parameters:
      title - The message title (header text)
      message - The message text
    • error

      public final void error(String title, String message)
      Shows the specified error message to the user
      Parameters:
      title - The error title (header text)
      message - The error message
    • showNotification

      public void showNotification(NotificationType notificationType, String title)
      Displays the specified notification on the interface.
      Parameters:
      notificationType - The notification type. See the NotificationType enum for applicable values.
      title - The notification title (header text)
      Throws:
      NullPointerException - If the type was specified as null
    • showNotification

      public void showNotification(NotificationType notificationType, String title, String message)
      Displays the specified notification on the interface.
      Parameters:
      notificationType - The notification type. See the NotificationType enum for applicable values.
      title - The notification title (header text)
      message - The message text
      Throws:
      NullPointerException - If the type was specified as null
    • showNotificationImmediate

      public void showNotificationImmediate(NotificationType notificationType, String title)
      Displays the specified notification on the interface, immediately, not waiting for other modifying operations
      Parameters:
      notificationType - The notification type. See the NotificationType enum for applicable values.
      title - The notification title (header text)
      Throws:
      NullPointerException - If the type was specified as null
    • showNotificationImmediate

      public void showNotificationImmediate(NotificationType notificationType, String title, String message)
      Displays the specified notification on the interface, immediately, not waiting for other modifying operations
      Parameters:
      notificationType - The notification type. See the NotificationType enum for applicable values.
      title - The notification title (header text)
      message - The message text
      Throws:
      NullPointerException - If the type was specified as null
    • getSessionProperties

      public Map<String,Object> getSessionProperties()
      Gets the client session properties in a Map
      Returns:
      The properties map. The map key is the name, the value is the property value.
    • setSessionProperty

      public Client setSessionProperty(String name, Object value)
      Adds a property to the client session.
      Parameters:
      name - The property name. If a property with the same name already exists, it will be overwritten.
      value - The property value
      Returns:
      The client object
      Throws:
      NullPointerException - If the property name is specified as null
    • getSessionProperty

      public Object getSessionProperty(String name)
      Gets the specified property (specified by name)
      Parameters:
      name - The property name
      Returns:
      The property value, or null, if not found
      Throws:
      NullPointerException - If the property name was specified as null
    • reload

      public void reload()
      Reloads the user interface
    • getEventQueue

      protected Client.EventQueue getEventQueue()
      Returns:
      The Event Queue
    • close

      protected Client close()
      Returns:
      The client object
    • sendDebugMessage

      public Client sendDebugMessage(String message)
      Sends a debug message to the client. This will appear in the browser console
      Parameters:
      message - The message text
      Returns:
      The client object
    • sendLogMessage

      public Client sendLogMessage(String message)
      Sends a Log message to the client. This will appear in the browser console
      Parameters:
      message - The message text
      Returns:
      The client object
    • sendInfoMessage

      public Client sendInfoMessage(String message)
      Sends an Info message to the client. This will appear in the browser console
      Parameters:
      message - The message text
      Returns:
      The client object
    • sendErrorMessage

      public Client sendErrorMessage(String message)
      Sends an Error message to the client. This will appear in the browser console
      Parameters:
      message - The message text
      Returns:
      The client object
    • sendWarnMessage

      public Client sendWarnMessage(String message)
      Sends a Warn message to the client. This will appear in the browser console
      Parameters:
      message - The message text
      Returns:
      The client object
    • sendTraceMessage

      public Client sendTraceMessage(String message)
      Sends a Trace message to the client. This will appear in the browser console
      Parameters:
      message - The message text
      Returns:
      The client object
    • sendDebugMessage

      public Client sendDebugMessage(String level, String message)
      Sends a Debug message to the client, on the specified level. This will appear in the browser console
      Parameters:
      level - The log level. For the usable levels, see the DebugMessage class constants.
      message - The message text
      Returns:
      The client object
    • runJavaScript

      public Client runJavaScript(String script)
      Runs the specified JavaScript on the client
      Parameters:
      script - The JavaScript. (An anonymous JavaScript block can be used as well.)
      Returns:
      The client object
    • callJavaScriptFunction

      public final <T> T callJavaScriptFunction(String block)
      Calls a JavaScript function, that can have a return value.
      Type Parameters:
      T - The type of the return value
      Parameters:
      block - The JavaScript block
      Returns:
      The JavaScript return value
    • callJavaScriptFunction

      public final <T> T callJavaScriptFunction(String functionName, Object... params)
      Calls a JavaScript function that can have a return value
      Type Parameters:
      T - The return value type
      Parameters:
      functionName - The function name, or JavaScript block that will be executed A
      params - The function parameters
      Returns:
      The return value
    • loadJavaScript

      public Client loadJavaScript(String... files) throws JavaScriptLoadError

      Loads the specified JavaScript to the client.

      If not loaded previously, it will be loaded. If loaded previously, then the specified JavaScript is accessible on the client, so the framework will ignore the load request.

      Parameters:
      files - The URL of the JavaScript
      Returns:
      The client object
      Throws:
      JavaScriptLoadError - If there was an error during the loading process
    • ask

      public final boolean ask(String title, String text)
      Shows the specified question message to the user.
      Parameters:
      title - The message title (header text)
      text - The message text
      Returns:
      Return The user's answer. true, if the user clicked the okButton , otherwise false.
    • input

      public String input(String title, String text)
      Shows an input window to the user
      Parameters:
      title - The message title (header text)
      text - The message text
      Returns:
      The text that the user typed in. If the user didn't write anything, or closed the window, by pressing the cancel button, it will return with null.
    • init

      public final void init(String hardLinkData, String urlParam)
      Parameters:
      hardLinkData - If the user arrived through a HardLink, the HardLink contents
      urlParam - The URL parameters (to be used with a SoftLink)
    • putCookie

      public Client putCookie(String name, String value, int expSec)
      Places a Cookie in the user's browser
      Parameters:
      name - The cookie name. If a cookie with the same name exists, it will be overwritten.
      value - The cookie value
      expSec - The cookie expiration, in seconds
      Returns:
      The client object
      Throws:
      NullPointerException - If the name was specified as null
    • deleteCookie

      public Client deleteCookie(String name)
      Removes a Cookie from the browser
      Parameters:
      name - The cookie name
      Returns:
      The client object
    • getCookie

      public String getCookie(String name)
      Gets the specified Cookie's value.
      Parameters:
      name - The cookie name
      Returns:
      The cookie value, or an empty string if the cookie was not found
      Throws:
      NullPointerException - If the name was specified as null
    • isActive

      public boolean isActive()
      The client is active. The connection between the server and the client is not lost.
    • setTheme

      public Client setTheme(Themes theme)
      Set application theme
      Parameters:
      theme - The theme. For a list of available themes, see Themes enum
      Returns:
      The client object
    • getTheme

      public Themes getTheme()
      Gets the application current theme
      Returns:
      The current theme