Skip to main content

buildfire.messaging

Use messaging to communicate messages to and from the widget and control. This is usefull if you want to sync your cp with widget side emulator on Control Panel.

Methods

sendMessageToControl()

buildfire.messaging.sendMessageToControl(message)

Send a message from the widget to the active control (content, design or settings)

buildfire.messaging.sendMessageToControl({
event: "removed-product-from-widget",
productId: "be7db1fc-a1d4-48b4-8b2b-41c19da4b2e0"
});
NameTypeRequiredDescriptionDefault
messageanyyesMay be a simple data type or an object. Will be sent to the widget and will trigger the callback function buildfire.messaging.onReceivedMessage(message)

sendMessageToWidget()

buildfire.messaging.sendMessageToWidget(message)

Sends a message from the control to the widget emulator.

buildfire.messaging.sendMessageToWidget({
event: "add-product-in-control",
productId: "be7db1fc-a1d4-48b4-8b2b-41c19da4b2e0"
});
NameTypeRequiredDescriptionDefault
messageanyyesMay be a simple data type or an object. Will be sent to the control and will trigger the callback function buildfire.messaging.onReceivedMessage(message)

sendMessageToService()

buildfire.messaging.sendMessageToService(message)

Sends a message from the widget to the widget background service.

buildfire.messaging.sendMessageToService({
action: "content-updated"
});
NameTypeRequiredDescriptionDefault
messageanyyesMay be a simple data type or an object. Will be sent to the control and will trigger the callback function buildfire.messaging.onReceivedMessage(message)

onReceivedMessage()

buildfire.messaging.onReceivedMessage(message)

Override this callback on widget, control or service to listen for any incoming messages

buildfire.messaging.onReceivedMessage = (message) => {
console.log("Message received", message);
};
NameTypeDescription
messageanyMessage sent by widget, control or service depending where the listener is initiated

broadcast()

buildfire.messaging.broadcast(options)

Sends a message from the widget or service to all other plugins in the app. if a plugin has a service, and the widget sends a message the service will also receive the broadcast and vice versa.

broadcast will trigger the callback function buildfire.messaging.onReceivedBroadcast(event).

buildfire.messaging.broadcast({
message: {
action: "user-purchase-complete",
productName: "Shoes"
}
});

options

NameTypeRequiredDescriptionDefault
messageanyyesCan be a simple data type or an object

onReceivedBroadcast()

buildfire.messaging.onReceivedBroadcast(event)

Override this callback on widget, or service to listen for any incoming messages from other plugins in addition to same plugin service to widget or same plugin widget to service.

buildfire.messaging.onReceivedBroadcast = (event) => {
console.log(`Message received from '${event.source.title}' `, event.message);
};

event

NameTypeDescription
sourceobjectAn object identifying the source plugin instance of the broadcast
messageanyMessage sent by widget or service

source

NameTypeDescription
pluginIdstringThe ID of the source plugin type
instanceIdstringThe ID of the source plugin instance
titlestringThe title of the source plugin