The code of this npm package was moved to smartclide-ide-front-end.
This module builds a message according to the protocol established for the communication between the SmartCLIDE IDE frontend and its components, with the following structure:
{
"type": "...",
"content": "..."
}
The current version provides:
Message Type | Direction | Description |
---|---|---|
TOKEN_INFO | Frontend -> Component | Used to send a token to the iframe, in the message's content |
COMPONENT_HELLO | Component -> Frontend | Message used to inform the SmartCLIDE IDE frontend that a new component was loaded |
TOKEN_REVOKE | Frontend -> Component | Message used to inform the components that no further requests will be accepted |
The upcoming features will include:
{
"dependencies": {
"@unparallel/smartclide-frontend-comm": "latest"
}
}
npm install
import {messageTypes, buildMessage} from "@unparallel/smartclide-frontend-comm";
// To send a token to the iframe
let sendTokenMessage = buildMessage(messageTypes.TOKEN_INFO, messageContent);
// To inform the SmartCLIDE IDE frontend that a new component was loaded
let componentLoadedMessage = buildMessage(messageTypes.COMPONENT_HELLO);
// To inform the components that the communication channel will be closed
let cancelCommunicationMessage = buildMessage(messageTypes.TOKEN_REVOKE);
let message = buildMessage(messageTypes.COMPONENT_HELLO);
// Send the message to the parent
window.parent.postMessage(message, "*");
// When the parent receives the message
window.addEventListener("message", ({data}) => {
switch(data.type){
case messageTypes.COMPONENT_HELLO:
// Reply with the token
break;
// ...
}
});