Class
Methods
Method | Returns | Notes |
---|---|---|
onDisconnect(callback) | void | Adds an event listener to be invoked when the WebSocket connection is disconnected. |
onReconnect(callback) | void | Adds an event listener to be invoked when the WebSocket connection is reestablished. |
send(message) | void | Send a WebSocket message to the Workflow Manager Server. |
subscribeToJob(jobId, callback) | string | Subscribe to job notifications to get automatic updates for a job. |
unsubscribe(callbackId) | void | Unsubscribe from job notifications for a job. |
void | Unsubscribe from all job notifications. |
onDisconnect
Class MethodonDisconnect(callback: () => void): void
Adds an event listener to be invoked when the WebSocket connection is disconnected.
const customEventListener = () => {
alert('Lost connection with the Workflow Manager server');
}
notificationManager.onDisconnect(customEventListener);
Parameters
Parameter | Type |
---|---|
callback | () => void |
Returns
void
onReconnect
Class MethodonReconnect(callback: () => void): void
Adds an event listener to be invoked when the WebSocket connection is reestablished.
const customEventListener = () => {
alert('Established connection with the Workflow Manager server');
}
notificationManager.onReconnect(customEventListener);
Parameters
Parameter | Type |
---|---|
callback | () => void |
Returns
void
send
Class Methodsend(message: any): void
Send a WebSocket message to the Workflow Manager Server.
Use this method to respond to server messages, such as Step Info Required messages when server needs a response so that it can complete running of a current step.
For initiating / terminating job messages use the subscribeToJob and unsubscribe methods.
Refer to the WebSocket Message API for information on messages that can be sent to server.
// Respond to server after receiving a Step Info Required message for a Question step.
// Construct a server response message
const stepResponse = {
jobId: 'job1',
stepId: 'step4',
questionResponse: 3, // Response value for the question step
comment: 'User selected option 3 from a dropdown'
};
// Send the response to server
notificationManager.send(stepResponse);
Parameters
Parameter | Type | Notes |
---|---|---|
message | any | The message to send to the Workflow Manager Server. |
Returns
void
subscribeToJob
Class MethodsubscribeToJob(jobId: string, callback: NotificationManagerCallback): string
Subscribe to job notifications to get automatic updates for a job.
Register a callback for the specified jobId when subscribing to a job. Whenever messages containing the specified jobId are received, the callback will be invoked with the contents of the job notification message.
Refer to the WebSocket Message API for the list of subscribed job messages.
// Construct a callback handler to receive job messages
async handleJobNotificationMessage(message: NotificationMessage): Promise<void> {
switch (message.msgType) {
case 'StepStarted':
// Message received when a step in a job has started running
this.handleStepStarted(message); // Implement handler for step started messages
break;
case 'StepFinished':
// Message received when a step in a job is completed
this.handleStepFinished(message); // Implement handler for step finished messages
break;
case 'StepError':
// Message received when an error occurs while a step in a job was running
this.handleStepError(message); // Implement handler for step error messages
break;
default:
// Handle other messages
this.handleOtherMessages(message); // Implement handler for other message types
break;
}
}
// Register to receive job notifications for a job
async subscribeToNotifications(jobId: string) {
// Get a handle to the NotificationManager
const notificationManager = await ManagerFactory.getManager(NotificationManager, options);
// Subscribe to job notifications for a particular job. A callbackId is returned to later unsubscribe from the job.
const callbackId = notificationManager.subscribeToJob(jobId, this.handleJobNotificationMessage);
}
Parameters
Parameter | Type | Notes |
---|---|---|
job | string | The jobId to subscribe to. |
callback | NotificationManagerCallback | The callback function that will be invoked when a message containing the specified jobId is received. |
Returns
string
The unique Id used to track the callback. Use the callbackId to unsubscribe from the job notification.
unsubscribe
Class Methodunsubscribe(callbackId: string): void
Unsubscribe from job notifications for a job.
Removes the callback for the corresponding callbackId. If no callbacks remain for a particular jobId, an unsubscribe message will be sent to Workflow Manager Server for that particular jobId.
// Unsubscribe from the job using the callbackId
notificationManager.unsubscribe(callbackId);
Parameters
Parameter | Type | Notes |
---|---|---|
callback | string | The callbackId to unsubscribe from. This is the Id returned after subscribing to a job notification. |
Returns
void
unsubscribeFromAll
Class MethodunsubscribeFromAll(): void
Unsubscribe from all job notifications.
Removes all callbacks. Unsubscribe messages will be sent for the corresponding job IDs.
// Unsubscribe from all job notifications
notificationManager.unsubscribeFromAll();
Returns
void