In my Node application, I want to subscribe to all of the events being published from my Cores. This is pretty straightforward with the API wrapper, after logging in I just say
But alas, not the case. Here’s a screenshot of what I get
Some times the event and the data comes as one String, sometimes it comes as two, and neither of them is valid JSON. This is a huge pain to do String processing on.
There’s another thread about this and an open GitHub issue, but both of those are a couple months old and haven’t gotten any attention. I’ll keep investigating and am happy to make a pull request, but I can’t figure out why this is happening.
// Spark CLI
if (onDataHandler) {
requestObj.on('data', onDataHandler);
}
Why is the event.toString().replace necessary? And why wouldn’t you check typeof(callback) === 'function' in the same line as if (callback), i.e. if (callback && typeof(callback) === 'function')
The Spark CLI does slightly more work than SparkJS in parsing out the results from the Server-Sent-Events endpoint on the API to turn the messages into something more useful. You can see the javascript that is parsing those results here: