commit 6babf06527f7c819c4c43964a28c7c82c471a9dc
parent c24430254fafb0881c6ad8071bc731bdf9c65394
Author: William Casarin <jb55@jb55.com>
Date: Mon, 21 Mar 2022 08:58:09 -0700
add nodejs fix for read_all
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/dist/node/lnsocket.js b/dist/node/lnsocket.js
@@ -35,7 +35,8 @@ async function lnsocket_init() {
const ws = new WebSocket(host)
ws.ondata = function(fn) {
ws.onmessage = (v) => {
- fn(v.data.arrayBuffer())
+ const data = v.data.arrayBuffer()
+ fn(data)
}
}
return ws
@@ -203,23 +204,21 @@ async function lnsocket_init() {
if (!this.connected)
throw new Error("read_all: not connected")
while (true) {
- const res = await this.queue_recv()
- count += res.byteLength
- if (count > n) {
- //console.log("adding %d to count %d > n %d, queue: %d", res.byteLength, count, n, this.queue.length)
- chunks.push(res.slice(0, n))
- const sliced = res.slice(n)
- //console.log("unshifting %d bytes back to queue", sliced.byteLength)
- this.queue.unshift(sliced)
+ let res = await this.queue_recv()
+
+ const remaining = n - count
+
+ if (res.byteLength > remaining) {
+ chunks.push(res.slice(0, remaining))
+ this.queue.unshift(res.slice(remaining))
break
- } else if (count === n) {
- //console.log("count %d === n %d, queue: %d", count, n, this.queue.length)
+ } else if (res.byteLength === remaining) {
chunks.push(res)
break
- } else {
- //console.log("count %d < n %d, queue: %d", count, n, this.queue.length)
- chunks.push(res)
}
+
+ chunks.push(res)
+ count += res.byteLength
}
return concat_u8_arrays(chunks)
diff --git a/dist/node/lnsocket.wasm b/dist/node/lnsocket.wasm
Binary files differ.
diff --git a/package.json b/package.json
@@ -1,7 +1,7 @@
{
"name": "lnsocket",
"description": "Connect to the lightning network",
- "version": "0.2.4",
+ "version": "0.2.5",
"repository": {
"url": "https://github.com/jb55/lnsocket"
},