diff --git a/src/pricing.js b/src/pricing.js index bb45af9..2237ace 100644 --- a/src/pricing.js +++ b/src/pricing.js @@ -646,8 +646,26 @@ class EntitySpec { function generateStreamParser(streamChunkHandler) { + let chunkCache = ''; return (chunk) => { - let msg = JSON.parse(chunk); + let msg; + let reminder = 0; + try { + if (chunkCache.length){ + chunk = chunkCache + chunk; + } + if (chunk.indexOf('}{') > -1) { + reminder = chunk.substring(chunk.indexOf('}{')+1, chunk.length); + chunk = chunk.substring(0, chunk.indexOf('}{') + 1) + } + msg = JSON.parse(chunk); + chunkCache = ''; + if (reminder) { + chunkCache += reminder; + } + } catch (e) { + chunkCache = chunk; + } if (msg.type == "HEARTBEAT") { diff --git a/src/transaction.js b/src/transaction.js index d39f1e4..53b0a77 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -8170,8 +8170,26 @@ class EntitySpec { function generateStreamParser(streamChunkHandler) { + let chunkCache = ''; return (chunk) => { - let msg = JSON.parse(chunk); + let msg; + let reminder = 0; + try { + if (chunkCache.length){ + chunk = chunkCache + chunk; + } + if (chunk.indexOf('}{') > -1) { + reminder = chunk.substring(chunk.indexOf('}{')+1, chunk.length); + chunk = chunk.substring(0, chunk.indexOf('}{') + 1) + } + msg = JSON.parse(chunk); + chunkCache = ''; + if (reminder) { + chunkCache += reminder; + } + } catch (e) { + chunkCache = chunk; + } if (msg.type == "HEARTBEAT") {