diff --git a/examples/server/public_simplechat/datautils.mjs b/examples/server/public_simplechat/datautils.mjs index 9ac1b76e8..75159d6b1 100644 --- a/examples/server/public_simplechat/datautils.mjs +++ b/examples/server/public_simplechat/datautils.mjs @@ -247,17 +247,17 @@ export class NewLines { } /** - * Shift the oldest/0th line in the array. - * Optionally control whether only full lines will be returned - * or will a partial line (last line) be returned. - * @param {boolean} bFullOnly + * Shift the oldest/earliest/0th line in the array. [Old-New|Earliest-Latest] + * Optionally control whether only full lines (ie those with newline at end) will be returned + * or will a partial line without a newline at end (can only be the last line) be returned. + * @param {boolean} bFullWithNewLineOnly */ - shift(bFullOnly=true) { + shift(bFullWithNewLineOnly=true) { let line = this.lines[0]; if (line == undefined) { return undefined; } - if ((line[line.length-1] != "\n") && bFullOnly){ + if ((line[line.length-1] != "\n") && bFullWithNewLineOnly){ return undefined; } return this.lines.shift(); diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index bcbb8f5c0..c9ff2898d 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -330,11 +330,13 @@ class SimpleChat { let xLines = new du.NewLines(); while(true) { let { value: cur, done: done } = await rr.read(); - let curBody = tdUtf8.decode(cur); - console.debug("DBUG:SC:PART:Str:", curBody); - xLines.add_append(curBody); + if (cur) { + let curBody = tdUtf8.decode(cur, {stream: true}); + console.debug("DBUG:SC:PART:Str:", curBody); + xLines.add_append(curBody); + } while(true) { - let curLine = xLines.shift(); + let curLine = xLines.shift(!done); if (curLine == undefined) { break; }