logo
23.2
search
No matching documents found.
list
search
No matching documents found.
logo
Please be aware that there is newer version of documentation available for Webswing. Documentation 24.2

Webswing API

Webswing provides an NPM module for easier integration of Webswing to javascript/typescript projects. This allows easier integration of Webswing into the existing web project. The module provides typescript declarations.

Requirements: This module works with Webswing 22.2 and newer.

Installation

npm install webswing-api

Basic Usage

import { getWebswingApi } from 'webswing-api'

getWebswingApi("http://localhost:8080/webswing-demo").then((api) => {
    const instance = api.bootstrap(document.getElementById('#rootElement'))
    instance.start()
})

ThegetWebswingApi is an async functions that is responsible for loading the actuall Webswing JS client from the Webswing server identified by the connectionUrl parameter. When the JS client is loaded API object is returned, which can be used to bootstrap the Webswing view to a DOM element passed in the first argument.

Usage with Customization and Options

import { getWebswingApi } from 'webswing-api'

const connectionUrl = "http://localhost:8080/webswing-demo"

getWebswingApi(connectionUrl, i18n).then((api) => {
    const instance = api.bootstrap(document.getElementById('#rootElement'), {
            //here define basic bootstrap options like:
            autoStart: false,
            args: 'customArgs sent to Swing app',
            onReady: () => { instance.start()},
            onStart: () => {// ...}
        },
        (injector) => {
            // here define more advanced customizations of Webswing JS client behavior like dialog contents: 
            injector.services.dialog.content.startingDialog.content = `<p>MyApp is being started</p>`
            injector.services.dialog.content.initializingDialog.content = `<p>MyApp is being initialized</p>`
        }
    )
}).catch((e) => {
    console.error(e)
    // ...
})

The getWebswingApi function allows to pass in custom translations logic and with the bootstrap function you can modify the bootstrap options and also define advanced customizations of the Webswing client behavior.

Custom i18n

You can reuse the i18n framework from your project by passing custom translate logic as second parameter of getWebswingApi function. Otherwise will be loaded from server. The translation logic is expecting object with this interface:

 interface ITranslations {
    translate: (key: string, vars?: any) => string;
    getLocale: () => string;
}

Bootstrap Options

These options can be modified in the bootstrap function's second parameter.

Options Description
autoStart tells Webswing to execute the start() function right after the instance is initialized. If it is false, start() function has to be triggered manually
autoReconnect number of milliseconds to wait until re-connection attempt in case of connection to server is terminated
disableLogout removes Logout button from all dialogs
disableLogin completely disables login process
args additional Java application arguments. Value of this option is available in Webswing config using the ${customArgs} variable
syncClipboard enable synchronization of user's local clipboard with Webswing (not yet supported in Firefox)
securityToken parameter passed to security module during authentication.
realm parameter passed to security module during authentication.
recording record this application session (default: false)
connectionUrl base URL for connecting to websocket service (default: current location url)
debugPort integer that specifies on which port should the debugger listen to. See development docs for more information
javaCallTimeout JsLink Java method invocation timeout. If Java method is not returned with a result, an error is logged to the browser console
pingParams setup parameters for checking connection stability
onReady callback after session logs in and is ready to start
onStart callback after session starts
windowsListener set of listener functions called when swing window status changes:

api.bootstrap will return an instance of webswing. Check the reference below.

Webswing Instance API Reference

Methods Description
start This will initiate the connection to Webswing server and start the Swing application. If the autoStart is set to false or not defined in config object, the start function has to be called manually, otherwise the Webswing will call start function automatically.
disconnect Disconnects the current Webswing session, but leaving the swing application running.
configure Configure instance options before start.
kill Disconnects the current Webswing session with stopping the swing application.
setControl Enables/disables the control of application. If set to false, no user events are sent to the Swing application.
repaint Notify webswing server that the application needs repaint.
instanceId Returns current instance id.
getWindows Returns all instance windows (Swing windows, HtmlPanel windows and internal windows).
getRenderedWindows Returns all instance windows (Swing windows, HtmlPanel windows and internal windows) that are rendered in current browser window.
getWindowById Find a window by its id.
performAction Perform an action that triggers server-side listener.
logout Log out currently logged in user.
getConnectionInfo Get information about this instance's connection to server.
isUndocked Returns true if this script is running in an undocked instance
getFilesManager Get extended API for managing files.