Skip to content

How to use Messaging to sync your Control to Widget

o5faruk edited this page May 2, 2021 · 9 revisions

⚠️⚠️⚠️

This sdk documentation is deprecated and will not be updated. Check out our new docs at https://sdk.buildfire.com/docs/messaging-to-sync-your-control-to-widget/

⚠️⚠️⚠️

Use messaging to communicate messages to and from the widget and control. Use this within the Control Panel Only.

buildfire.messaging.sendMessageToControl(message)

this method allows you to send a message from the widget to the active control (content, design or settings)

arguments

  • message : may be a simple data type or an object. Will be sent to the control and will trigger the callback function buildfire.messaging.onReceivedMessage(message)

example

///on widget when a user in the control panel goes into the details section tell the Control to reflect the same
buildfire.messaging.sendMessageToControl({section:'details',subItem:123123123});

/// on control listen to any messages coming in
buildfire.messaging.onReceivedMessage = function(message){
   switch (message.section){
    case 'details':
        document.getElementById('setailSection').style.display = 'block';
        obj.loadDetails (message.subItem);
        break;
    }
}

buildfire.messaging.sendMessageToWidget(message)

this method allows you to send a message from the control to the widget.

arguments

  • message : may be a simple data type or an object. Will be sent to the widget and will trigger the callback function buildfire.messaging.onReceivedMessage(message)

example

///on Control when a user drills to a section reflect the same on the widget
buildfire.messaging.sendMessageToWidget({section:'details',subItem:123123123});

/// on widget listen to any messages coming in
buildfire.messaging.onReceivedMessage = function(message){
   switch (message.section){
    case 'details':
        document.getElementById('setailSection').style.display = 'block';
        obj.loadDetails (message.subItem);
        break;
    }
}

buildfire.messaging.onReceivedMessage(message)

override this call back function to listen in on any incoming messages

arguments

  • message : the message value sent by the widget or control

example

///on Control when a user drills to a section reflect the same on the widget
buildfire.messaging.sendMessageToWidget({section:'details',subItem:123123123});

/// on widget listen to any messages coming in
buildfire.messaging.onReceivedMessage = function(message){
   switch (message.section){
    case 'details':
        document.getElementById('setailSection').style.display = 'block';
        obj.loadDetails (message.subItem);
        break;
    }
}

buildfire.messaging.sendMessageToService(message)

arguments

  • message : may be a simple data type or an object. Will be sent from the widget ONLY, to the service and will trigger the callback function buildfire.messaging.onReceivedMessage(message)
buildfire.messaging.sendMessageToService(data);

Clone this wiki locally