function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhinav Sharma.Abhinav Sharma. 

How to use BroadcastChannel to post message using Lightning Component?

Can someone share his/her experience to use BroadcastChannel to post message using Lightning Component?

I'm trying below code snippit but not working.

Component:
<aura:component implements="flexipage:availableForAllPageTypes">
    <lightning:button label="Navigate" onclick="{!c.handleClick}"/>
</aura:component>

JavaScript Controller:
({
    handleClick : function(component, event, helper) {
        console.log('Navigation');
        const channel = new BroadcastChannel("api_softphone_NavigationChange");
        
        channel.postMessage({
            messageType: "onNavigationChange"
        });      
    }
})

BroadcastChannel Error
VinayVinay (Salesforce Developers) 
Hi Abhinav,

You need to access the default property

const BroadcastChannel = require('broadcast-channel').default

https://github.com/pubkey/broadcast-channel/issues/9

Also, Broadcast channel is not supported by Locker service.

https://developer.salesforce.com/docs/component-library/tools/locker-service-viewer

Thanks,
Vinay Kumar