Split messages that are retrieved from the WS into sep. wonMessages and handle them individually
@@ -367,9 +367,29 @@ export function runMessagingAgent(redux) {
missedHeartbeats = 0;
const data = JSON.parse(receivedMsg.data);
- console.debug("WS MSG RECEIVED: ", data);
- won.wonMessageFromJsonLd(data).then(message => {
- won.addJsonLdData(data);
+
+ const graphArray = data["@graph"];
+ const messages = {};
+
+ graphArray.forEach(graph => {
+ console.debug(graph["@id"], " --> ", graph["@id"].split("#")[0]);
+
+ const msgUri = graph["@id"].split("#")[0];
+ const singleMessage = messages[msgUri];
+
+ if (singleMessage) {
+ singleMessage["@graph"].push(graph);
+ } else {
+ messages[msgUri] = { "@graph": [graph] };
+ }
+ });
+
+ console.debug("messages", messages);
+
+ for (const msgUri in messages) {
+ const msg = messages[msgUri];
+ won.wonMessageFromJsonLd(msg).then(message => {
+ won.addJsonLdData(msg);
let messageProcessed = false;
@@ -391,6 +411,7 @@ export function runMessagingAgent(redux) {
}
});
}
+ }
/* TODOs
* + make it generic?
