]> git.proxmox.com Git - mirror_novnc.git/blobdiff - core/websock.js
Properly detect scrollbar gutter
[mirror_novnc.git] / core / websock.js
index c8d90acb6cf6a0327dbed78f363f06ad647af16e..8fef0b2818b63e39480debaf6644f275a8958e9e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Websock: high-performance binary WebSockets
- * Copyright (C) 2018 The noVNC Authors
+ * Copyright (C) 2019 The noVNC Authors
  * Licensed under MPL 2.0 (see LICENSE.txt)
  *
  * Websock is similar to the standard WebSocket object but with extra
@@ -17,6 +17,8 @@ import * as Log from './util/logging.js';
 // this has performance issues in some versions Chromium, and
 // doesn't gain a tremendous amount of performance increase in Firefox
 // at the moment.  It may be valuable to turn it on in the future.
+// Also copyWithin() for TypedArrays is not supported in IE 11 or
+// Safari 13 (at the moment we want to support Safari 11).
 const ENABLE_COPYWITHIN = false;
 const MAX_RQ_GROW_SIZE = 40 * 1024 * 1024;  // 40 MiB
 
@@ -224,6 +226,11 @@ export default class Websock {
         return new Uint8Array(this._sQ.buffer, 0, this._sQlen);
     }
 
+    // We want to move all the unread data to the start of the queue,
+    // e.g. compacting.
+    // The function also expands the receive que if needed, and for
+    // performance reasons we combine these two actions to avoid
+    // unneccessary copying.
     _expand_compact_rQ(min_fit) {
         // if we're using less than 1/8th of the buffer even with the incoming bytes, compact in place
         // instead of resizing
@@ -260,8 +267,8 @@ export default class Websock {
         this._rQi = 0;
     }
 
+    // push arraybuffer values onto the end of the receive que
     _decode_message(data) {
-        // push arraybuffer values onto the end
         const u8 = new Uint8Array(data);
         if (u8.length > this._rQbufferSize - this._rQlen) {
             this._expand_compact_rQ(u8.length);
@@ -274,8 +281,9 @@ export default class Websock {
         this._decode_message(e.data);
         if (this.rQlen > 0) {
             this._eventHandlers.message();
-            // Compact the receive queue
             if (this._rQlen == this._rQi) {
+                // All data has now been processed, this means we
+                // can reset the receive queue.
                 this._rQlen = 0;
                 this._rQi = 0;
             }