Messaging

This chapter is about custom messaging between selected components

Arena -> Webresults

If there is custom message which needs to be sent to visualization from arena use:

// ...
rapidjson::Document d(rapidjson::kObjectType);
d.AddMember("test", rapidjson::Value(10), d.GetAllocator());
ENGINE_sendCustomMessageToVisualization(d);
// ...

Message on the webresult side can be handled by following:

  • This can be handled in any component, so multiple listeners can exist
// ...
    const receivedCustomData = (data) => {
      console.log({data, from: 1});
    }
    
    React.useEffect(() => {
        const listener = {
          listener: receivedCustomData
        };
        registerCustomDataListener(listener);
        return () => {
          removeCustomDataListener(listener);
        }
    }, []);
// ...

Webresults -> Arena

check following code snippet.

<button 
  onClick={() => sendCustomMessage({test: 11})}>
  Click me I will send message
</button>

In arena plugin following callback handles this event:

void PLUGIN_customMessageFromVisualization(const rapidjson::Value &aValue){
    printf("received custom message from web %d\n", aValue["test"].GetUint());
}

Arena -> Chest

Chest -> Arena