Setting Up WebSockets - General Description
WebSockets can be useful in a wide variety of use cases and scenarios. Therefore, this section begins with a general description of the individual steps you need to follow to set up WebSockets in Intrexx. A general understanding of the individual steps should help you implement specific "WebSocket processes" in Intrexx. In the " Examples " section, you'll find specific implementation examples. There, the implementation of each step is demonstrated using specific examples.
To use WebSockets in Intrexx, you must complete the following key steps:
Some of the steps are to be performed in the "Application" module, and others in the "Processes" module.
The steps do not necessarily have to be performed in the order listed. For example, here's how to do step , 3. "Set ad in portal" —also perform this step at the very end. You can also start by creating the process in Intrexx and then create a topic in the desired application later. In some cases, not all of the steps are necessary.
Set the event (trigger) for the message
First, you must decide which external or Intrexx-internal event should trigger the notification or update in the browser. You can find examples of triggers in the " Use Cases" section. If an internal event is to trigger the sending of a message, the first step is omitted. Internal events are defined in Intrexx processes via an event source. For more information, see Step "4." "Select Event Source".
Create a topic
To use WebSockets, you must create (at least) one topic.
A topic receives the message(s) triggered by the event and delivers them to the browser.
You create topics in applications.
Topics: From a technical standpoint, a topic in the context of WebSockets represents the object that delivers or makes messages available. A "consumer" can subscribe to a topic. A topic can be compared to a news feed that you can subscribe to.
In Intrexx, create a topic in the application where you want to display the message. All you need to do is assign a unique name to the topic. Intrexx automatically generates a GUID for the topic. No further steps are required to set up the "News Channel."
Set the display in the portal
You must specify when a user should start subscribing to a topic and where the message should be displayed in the portal.
This is done using JavaScript methods that you integrate into the application. The following JavaScript methods have been implemented in Intrexx 20.03 for subscribing to and unsubscribing from a topic:
ix.websocket.subscribeToTopic
ix.websocket.unsubscribeFromTopic
The "ix.websocket.subscribeToTopic" method is used to subscribe to a topic. The "ix.websocket.unsubscribeFromTopic" method is used to unsubscribe from a topic.
You can use standard JavaScript features in conjunction with these methods. For example, you can call the "ix.websocket.subscribeToTopic" method during the "onload" event of a display or input page. The topic is then subscribed to (automatically) when the corresponding page is loaded. To do this, specify the JavaScript element or Intrexx control in which the message should be displayed.
More Information
For detailed information on JavaScript in the context of WebSockets, see the following sections:
You can find the API documentation at the following link:
-
https://docs.intrexx.com/intrexx/version/11000/steady/api/js/html/modules/IxWebsocket.html
-
Starting with Intrexx version 12.0.0
https://docs.intrexx.com/intrexx/version/steady/api/js/html/modules/api.websocket.html
Select Event Source
For an event to trigger a WebSocket message, you must create a process in Intrexx and set up an event source there (as usual).
Internal Event In the event source, you can specify an internal event that will trigger the WebSocket message.
External Event In the event source, you can also "integrate" external events that are intended to trigger the WebSocket message.
The process of defining events related to WebSockets described here is the same as setting up event sources in other contexts. The only difference lies in the following actions, which control the sending of the WebSocket message.
Select an event handler
You must "assign" an event handler to the event source. There are no specific considerations to keep in mind regarding WebSockets.
Select Groovy Action / Select WebSocket Action
In addition to creating topics and embedding JavaScript in applications, embedding and configuring a WebSocket action or Groovy action is crucial for the proper functioning and setup of WebSockets.
The main functions of both the WebSocket and Groovy actions are to create the message and associate the message or event with a topic. (When linking the message to the topic, Intrexx links the process to the application.)
Should I use a WebSocket or Groovy action?
The main advantage of the WebSocket action is its ease of use. This allows you to use a drop-down menu to select the application and the topic to which the message should be sent. So you don't need to know the topic's GUID. The WebSocket action is suitable for static or simple messages. However, Velocity Script can also be used to create complex messages.
A Groovy action requires a Groovy script to create the message and establish a connection to a topic. You must use the topic's GUID. The Groovy action is suitable for more complex messages.
To enable a Groovy action to send a WebSocket message and establish a connection to a topic, Intrexx provides the following Groovy script class:
de.uplanet.lucy.server.websocket.groovy.GroovyWebSocketTopic
You can use the following functions to send either text or JSON messages:
GroovyWebSocketTopic.sendTextMessage
GroovyWebSocketTopic.sendJsonMessage
More Information
For detailed information about GroovyScript in the context of WebSockets, see the following sections:
You can find the API documentation at the following link:
Note: As usual, you can also use Groovy actions in a process that are not intended for generating WebSocket messages.
So it's possible that Groovy actions and a WebSocket action could occur within the same process.
