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.

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

Note

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.

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

Arguments for subscribe 

NameTypeDescription
channelNamestringThe name of the Message Channel that you can subscribe to.
listenerfunctionJavaScript method that’s called when a message is sent on the Message Channel.
callbackfunctionJavaScript method that’s executed when the API method call is completed.

Arguments for unsubscribe 

NameTypeDescription
subscriptionobjectThe subscription from which you can remove the listener function.
callbackfunctionJavaScript method that’s executed when the API method call is completed.

Arguments for publish 

NameTypeDescription
channelNamestringThe name of the Message Channel that you can subscribe to.
messageobjectSerializable JSON object that is sent on the Message Channel.
callbackfunctionJavaScript method that’s executed when the API method call is completed.