commit 80cbf975fc3d283eaf700abff4758751b47ac1ae
parent d3b9705c5200f40772fb2a883ff9daff4c20d68c
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 21 Mar 2022 07:19:59 -0700
semi-fix streaming on larger requests
still an issue where concurrent random messages throw a wrench in
things, but will fix that next.
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/examples/websockets.html b/examples/websockets.html
@@ -0,0 +1,16 @@
+
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1">
+
+        <title>Hello World</title>
+    </head>
+    <body>
+        <h1>Hello World</h1>
+    <script src="lnsocket.js"></script>
+    <script src="websockets.js?v=2"></script>
+    </body>
+</html>
+
diff --git a/examples/websockets.js b/examples/websockets.js
@@ -5,9 +5,9 @@ async function go() {
 
 	ln.genkey()
 	//const their_init = await ln.connect_and_init("03f3c108ccd536b8526841f0a5c58212bb9e6584a1eb493080e7c1cc34f82dad71", "cln.jb55.com:443")
-	await ln.connect_and_init("03f3c108ccd536b8526841f0a5c58212bb9e6584a1eb493080e7c1cc34f82dad71", "24.84.152.187:8324")
+	await ln.connect_and_init("03f3c108ccd536b8526841f0a5c58212bb9e6584a1eb493080e7c1cc34f82dad71", "ws://24.84.152.187:8324")
 
-	const rune = "CVFjq11ZtQ-V14SOeQyV4V2AicYZnHfbBNY8lqYvf8c9NjcmbWV0aG9kPWdldGluZm8mdGltZTwxNjQ2ODc2MTU2"
+	const rune = "APaeUhcGPAMQwgV1Kn-hRRs5Bi4-D1nrfsHfCoTLl749MTAmbWV0aG9kPWdldGluZm8="
 	const res = await ln.rpc({ method: "getinfo", rune })
 
 	document.body.innerHTML = `<pre>${JSON.stringify(res.result, undefined, 2)}</pre>`
diff --git a/lnsocket_lib.js b/lnsocket_lib.js
@@ -185,9 +185,11 @@ async function lnsocket_init() {
 			const res = await this.queue_recv()
 			count += res.byteLength
 			if (count > n) {
-				//console.log("count %d > n %d, queue: %d", count, n, this.queue.length)
+				//console.log("adding %d to count %d > n %d, queue: %d", res.byteLength, count, n, this.queue.length)
 				chunks.push(res.slice(0, n))
-				this.queue.unshift(res.slice(n))
+				const sliced = res.slice(n)
+				//console.log("unshifting %d bytes back to queue", sliced.byteLength)
+				this.queue.unshift(sliced)
 				break
 			} else if (count === n) {
 				//console.log("count %d === n %d, queue: %d", count, n, this.queue.length)