Lightning Message Service Methods for Lightning Experience

Usage

These three methods allow your CTI implementation to communicate with other Visualforce, Aura, and Lightning components that also use the Lightning Message Service. The subscribe method attaches a listener function to a specified Lightning Message Channel. The publish method lets you send a message on a Lightning Message Channel. The unsubscribe method lets you remove listener functions you added with the subscribe method.

These methods are available in API version 47.0 or later.

note: These methods can be used only with Lightning Experience. They can be used in iFrame and Visualforce components.

Syntax

The subscribe method allows you to attach a listener function to a specified Lightning Message Channel. Lightning Message Service calls your listener function with the message that a component sends.

var SAMPLEMC = "SAMPLEMC__c";
var SAMPLEMC_SUBSCRIPTION = null; 
sforce.opencti.subscribe({channelName: SAMPLEMC, listener: onPublishMessage, callback: subscribeSampleMCCallback}); 

Arguments for subscribe

Name Type Description
channelName string The name of the Message Channel that you can subscribe to.
listener function JavaScript method that’s called when a message is sent on the Message Channel.
callback function JavaScript method that’s executed when the API method call is completed.

Arguments for unsubscribe

Name Type Description
subscription object The subscription from which you can remove the listener function.
callback function JavaScript method that’s executed when the API method call is completed.

Arguments for publish

Name Type Description
channelName string The name of the Message Channel that you can subscribe to.
message object Serializable JSON object that is sent on the Message Channel.
callback function JavaScript method that’s executed when the API method call is completed.