Set up WebSockets in Intrexx

Create topic

Topics are created in the "Applications" module.

Step-by-step guide

To create a topic in an application, please proceed as follows:
  1. Open the properties dialog of the application that you would like to create the topic in.
  2. Switch to the "Topics" tab.



  3. Click on the icon.
    The fields "GUID of the topic" and "Name of the topic" will appear on the right:



    Field Description
    GUID of the topic The GUID of the topic is shown in the right area of the dialog. Intrexx assigns the GUID automatically, it cannot be changed. You need the GUID if you want to refer to this topic in a Groovy action or JavaScript.
    Name of the topic Provide the topic with a name here. This name must be unique, it may only be used in Intrexx once. You can use the topic name if you want to refer to the topic in WebSocket actions.
  4. (Optional) Click on the icon again to create additional topics.
    You can add any number of topics to an application.
    You have now created a topic in an application.

Write JavaScript for WebSockets in the application


Step-by-step guide

To write JavaScript for WebSockets in an application, please proceed as follows:
  1. Open the application that you would like to display the WebSocket message in.
    (This is also the application that contains the topic that you would like to subscribe to via JavaScript.)
  2. Open the JavaScript editor (Ctrl + F12).
  3. Write the JavaScript code.
    a. Write the function for subscribing to the topic and for displaying the message in the portal.
    b. (Optional) Write the function for unsubscribing from the topic.
  4. Define a (JavaScript) event that will
    a. start the subscription (e.g. onload, onclick) and
    b. (Optional) end the subscription.

Configure WebSocket action

WebSocket actions are configured in the "Processes" module.

Requirements/preparations
In the normal manner, add a WebSocket action to the corresponding process.

Step-by-step guide

To configure a WebSocket action, please proceed as follows:
  1. Open the properties dialog of the WebSocket action.



  2. Provide the WebSocket action with a title and (if required) a description.
  3. Go to the "Topic" tab.



  4. Select the application that the message should be sent to from the "Application" drop-down list.
  5. Select the topic that the message should be sent to from the "Topic" drop-down list.
    The topic can be subscribed to in the browser. Compare sections 2. Create topic and 3. Define appearance in the portal for more information.
    Please note: If you are using a WebSocket action, you only need the name of a topic to be able to refer to it. If you are using a Groovy script action, you need the GUID of a topic to be able to refer to it.
  6. Go to the "Content" tab.



  7. Create the content for the message.
    You can choose from one of the following options here:

    Name Description
    Static text You can write a static text here. This is suitable if the message is always the same, i.e. you do not require changing message elements.
    Text from data field To display dynamic text, you can select a data field that provides the values. This option is only available if the process contains a data group event handler.
    Text from system value You can generate texts from system values here. For example, you can apply user values or variables from the sharedState.
    Generate from Velocity You can generate texts via Velocity script here.
  8. Go to the "Error handling" tab.



    Define how Intrexx should behave if no (message) content can be found to continue processing.
    You can choose from the following options here:

    Name Description
    Cancel transaction (default) If you select this option, the transaction will be canceled meaning that the process will no longer be executed if the WebSocket action does not have any content. In this case, a message is not sent to the selected topic.
    Continue transaction If you select this option, the transaction is continued.
    Select this option if subsequent process actions should still be executed even if the WebSocket action does not have any content.
    This option can also be useful if the data record that triggered the event should be saved.
  9. Click on "OK".
    You have configured a WebSocket action.

Configure Groovy action

Groovy actions are configured in the "Processes" module.

Requirements/preparations
In the normal manner, add a Groovy action to the corresponding process.

Step-by-step guide

To configure a Groovy action with WebSocket functions, please proceed as follows:
  1. Open the properties dialog of the Groovy action.
  2. Go to the "Script" tab.



  3. Click on "Open Intrexx editor".
    This will launch the Intrexx Groovy editor.
  4. Enter the Groovy script.
    You can create the WebSocket message and the link to the topic using Groovy script.
  5. Import the Groovy script class:
    de.uplanet.lucy.server.websocket.groovy.GroovyWebSocketTopic
    				
  6. Use the following Groovy function to send text or JSON messages, respectively:
    GroovyWebSocketTopic.sendTextMessage
    GroovyWebSocketTopic.sendJsonMessage