Skip to content

Commit

Permalink
fix: ability to parse messages split into more than 2 parts
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkpunkd committed Oct 21, 2019
1 parent 3ce6496 commit bef09b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/mse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function createMSE (hostname: string, restPort?: number, wsPort?: number)

async function run () {
let mse = createMSE('mse_ws.ngrok.io', 80, 80)
console.dir(await mse.getPlaylist('5A58448C-3CBE-4146-B3DF-EFC918D16266'), { depth: 10 })
console.dir(await mse.getShow('66E45216-9476-4BDC-9556-C3DB487ED9DF'), { depth: 10 })
// console.log('Pre close')
await mse.close()
// console.log('After close.')
Expand Down
7 changes: 4 additions & 3 deletions src/peptalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ class PepTalk extends EventEmitter implements PepTalkClient, PepTalkJS {
while (reres !== null) {
let lastBytes = Buffer.byteLength(last, 'utf8')
if (lastBytes - (reres.index + reres[0].length + (+reres[1])) < 0) {
leftovers = { previous: last, remaining: +reres[1] - lastBytes }
leftovers = {
previous: last,
remaining: +reres[1] - lastBytes + reres[0].length + reres.index }
split = split.slice(0, -1)
break
}
Expand All @@ -390,15 +392,14 @@ class PepTalk extends EventEmitter implements PepTalkClient, PepTalkJS {
}
if (split.length > 1) {
for (let sm of split) {
console.log('smsm >>>', sm)
// console.log('smsm >>>', sm)
if (sm.length > 0) this.processMessage(sm)
}
return
}
this.leftovers = leftovers ? leftovers : this.leftovers
if (split.length === 0) return
m = split[0]
console.log('LEN', m.length)
let firstSpace = m.indexOf(' ')
if (firstSpace <= 0) return
let c = +m.slice(0, firstSpace)
Expand Down

0 comments on commit bef09b5

Please sign in to comment.