NotificationManager

Class

Inheritance: NotificationManagerBaseManager

Methods

MethodReturnsNotes
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 to job notifications for a job.

onDisconnect

Class Method
onDisconnect(callback() => void): void

Adds an event listener to be invoked when the WebSocket connection is disconnected.

Use dark colors for code blocksCopy
1
2
3
4
5
const customEventListener = () => {
 alert('Lost connection with the Workflow Manager server');
}

notificationManager.onDisconnect(customEventListener);
Parameters
ParameterType
callback
() => void
Returns 
void

onReconnect

Class Method
onReconnect(callback() => void): void

Adds an event listener to be invoked when the WebSocket connection is reestablished.

Use dark colors for code blocksCopy
1
2
3
4
5
const customEventListener = () => {
 alert('Established connection with the Workflow Manager server');
}

notificationManager.onReconnect(customEventListener);
Parameters
ParameterType
callback
() => void
Returns 
void

send

Class Method
send(messageany): 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.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
// 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
ParameterTypeNotes
message
any

The message to send to the Workflow Manager Server.

Returns 
void

subscribeToJob

Class Method
subscribeToJob(jobIdstring, callbackNotificationManagerCallback): 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.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 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
ParameterTypeNotes
jobId
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 Method
unsubscribe(callbackIdstring): void

Unsubscribe to 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.

Use dark colors for code blocksCopy
1
2
// Unsubscribe from the job using the callbackId
notificationManager.unsubscribe(callbackId);
Parameters
ParameterTypeNotes
callbackId
string

The callbackId to unsubscribe from. This is the Id returned after subscribing to a job notification.

Returns 
void

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.