]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Let fake WebSocket handle large sends
authorPierre Ossman <ossman@cendio.se>
Thu, 29 Aug 2024 14:51:16 +0000 (16:51 +0200)
committerPierre Ossman <ossman@cendio.se>
Thu, 29 Aug 2024 14:51:16 +0000 (16:51 +0200)
Dynamically grow the recorded send buffer if the test needs to send a
lot of data.

tests/fake.websocket.js

index d273fe07a94974ce80dd1c8c27095807ded6493a..f1b307136389b8e1d6f2feb5796937aae3446c39 100644 (file)
@@ -37,6 +37,15 @@ export default class FakeWebSocket {
         } else {
             data = new Uint8Array(data);
         }
+        if (this.bufferedAmount + data.length > this._sendQueue.length) {
+            let newlen = this._sendQueue.length;
+            while (this.bufferedAmount + data.length > newlen) {
+                newlen *= 2;
+            }
+            let newbuf = new Uint8Array(newlen);
+            newbuf.set(this._sendQueue);
+            this._sendQueue = newbuf;
+        }
         this._sendQueue.set(data, this.bufferedAmount);
         this.bufferedAmount += data.length;
     }