]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Standardize on camelCase in Websock
authorSamuel Mannehed <samuel@cendio.se>
Sun, 31 May 2020 21:05:42 +0000 (23:05 +0200)
committerSamuel Mannehed <samuel@cendio.se>
Sun, 31 May 2020 21:21:35 +0000 (23:21 +0200)
core/rfb.js
core/websock.js
tests/test.rfb.js
tests/test.websock.js

index e93be0fddcb930d7ec78c0284b56741999d0675f..106addffb96ec617567a366afa62a9b72082b2eb 100644 (file)
@@ -912,7 +912,7 @@ export default class RFB extends EventTargetMixin {
             while (repeaterID.length < 250) {
                 repeaterID += "\0";
             }
-            this._sock.send_string(repeaterID);
+            this._sock.sendString(repeaterID);
             return true;
         }
 
@@ -922,7 +922,7 @@ export default class RFB extends EventTargetMixin {
 
         const cversion = "00" + parseInt(this._rfbVersion, 10) +
                        ".00" + ((this._rfbVersion * 10) % 10);
-        this._sock.send_string("RFB " + cversion + "\n");
+        this._sock.sendString("RFB " + cversion + "\n");
         Log.Debug('Sent ProtocolVersion: ' + cversion);
 
         this._rfbInitState = 'Security';
@@ -1036,7 +1036,7 @@ export default class RFB extends EventTargetMixin {
                            String.fromCharCode(this._rfbCredentials.target.length) +
                            this._rfbCredentials.username +
                            this._rfbCredentials.target;
-        this._sock.send_string(xvpAuthStr);
+        this._sock.sendString(xvpAuthStr);
         this._rfbAuthScheme = 2;
         return this._negotiateAuthentication();
     }
@@ -1121,8 +1121,8 @@ export default class RFB extends EventTargetMixin {
             // XXX we assume lengths are <= 255 (should not be an issue in the real world)
             this._sock.send([0, 0, 0, user.length]);
             this._sock.send([0, 0, 0, pass.length]);
-            this._sock.send_string(user);
-            this._sock.send_string(pass);
+            this._sock.sendString(user);
+            this._sock.sendString(pass);
 
             this._rfbInitState = "SecurityResult";
             return true;
@@ -1158,8 +1158,8 @@ export default class RFB extends EventTargetMixin {
 
         this._sock.send([0, 0, 0, this._rfbCredentials.username.length]);
         this._sock.send([0, 0, 0, this._rfbCredentials.password.length]);
-        this._sock.send_string(this._rfbCredentials.username);
-        this._sock.send_string(this._rfbCredentials.password);
+        this._sock.sendString(this._rfbCredentials.username);
+        this._sock.sendString(this._rfbCredentials.password);
         this._rfbInitState = "SecurityResult";
         return true;
     }
index 8fef0b2818b63e39480debaf6644f275a8958e9e..3156aed6f5e1ba4d26a19534797c8a5d852f14da 100644 (file)
@@ -144,7 +144,7 @@ export default class Websock {
 
     flush() {
         if (this._sQlen > 0 && this._websocket.readyState === WebSocket.OPEN) {
-            this._websocket.send(this._encode_message());
+            this._websocket.send(this._encodeMessage());
             this._sQlen = 0;
         }
     }
@@ -155,7 +155,7 @@ export default class Websock {
         this.flush();
     }
 
-    send_string(str) {
+    sendString(str) {
         this.send(str.split('').map(chr => chr.charCodeAt(0)));
     }
 
@@ -168,13 +168,13 @@ export default class Websock {
         this._eventHandlers[evt] = handler;
     }
 
-    _allocate_buffers() {
+    _allocateBuffers() {
         this._rQ = new Uint8Array(this._rQbufferSize);
         this._sQ = new Uint8Array(this._sQbufferSize);
     }
 
     init() {
-        this._allocate_buffers();
+        this._allocateBuffers();
         this._rQi = 0;
         this._websocket = null;
     }
@@ -185,7 +185,7 @@ export default class Websock {
         this._websocket = new WebSocket(uri, protocols);
         this._websocket.binaryType = 'arraybuffer';
 
-        this._websocket.onmessage = this._recv_message.bind(this);
+        this._websocket.onmessage = this._recvMessage.bind(this);
         this._websocket.onopen = () => {
             Log.Debug('>> WebSock.onopen');
             if (this._websocket.protocol) {
@@ -220,7 +220,7 @@ export default class Websock {
     }
 
     // private methods
-    _encode_message() {
+    _encodeMessage() {
         // Put in a binary arraybuffer
         // according to the spec, you can send ArrayBufferViews with the send method
         return new Uint8Array(this._sQ.buffer, 0, this._sQlen);
@@ -231,30 +231,30 @@ export default class Websock {
     // 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) {
+    _expandCompactRQ(minFit) {
         // if we're using less than 1/8th of the buffer even with the incoming bytes, compact in place
         // instead of resizing
-        const required_buffer_size =  (this._rQlen - this._rQi + min_fit) * 8;
-        const resizeNeeded = this._rQbufferSize < required_buffer_size;
+        const requiredBufferSize =  (this._rQlen - this._rQi + minFit) * 8;
+        const resizeNeeded = this._rQbufferSize < requiredBufferSize;
 
         if (resizeNeeded) {
             // Make sure we always *at least* double the buffer size, and have at least space for 8x
             // the current amount of data
-            this._rQbufferSize = Math.max(this._rQbufferSize * 2, required_buffer_size);
+            this._rQbufferSize = Math.max(this._rQbufferSize * 2, requiredBufferSize);
         }
 
         // we don't want to grow unboundedly
         if (this._rQbufferSize > MAX_RQ_GROW_SIZE) {
             this._rQbufferSize = MAX_RQ_GROW_SIZE;
-            if (this._rQbufferSize - this.rQlen < min_fit) {
+            if (this._rQbufferSize - this.rQlen < minFit) {
                 throw new Error("Receive Queue buffer exceeded " + MAX_RQ_GROW_SIZE + " bytes, and the new message could not fit");
             }
         }
 
         if (resizeNeeded) {
-            const old_rQbuffer = this._rQ.buffer;
+            const oldRQbuffer = this._rQ.buffer;
             this._rQ = new Uint8Array(this._rQbufferSize);
-            this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi, this._rQlen - this._rQi));
+            this._rQ.set(new Uint8Array(oldRQbuffer, this._rQi, this._rQlen - this._rQi));
         } else {
             if (ENABLE_COPYWITHIN) {
                 this._rQ.copyWithin(0, this._rQi, this._rQlen);
@@ -268,17 +268,17 @@ export default class Websock {
     }
 
     // push arraybuffer values onto the end of the receive que
-    _decode_message(data) {
+    _DecodeMessage(data) {
         const u8 = new Uint8Array(data);
         if (u8.length > this._rQbufferSize - this._rQlen) {
-            this._expand_compact_rQ(u8.length);
+            this._expandCompactRQ(u8.length);
         }
         this._rQ.set(u8, this._rQlen);
         this._rQlen += u8.length;
     }
 
-    _recv_message(e) {
-        this._decode_message(e.data);
+    _recvMessage(e) {
+        this._DecodeMessage(e.data);
         if (this.rQlen > 0) {
             this._eventHandlers.message();
             if (this._rQlen == this._rQi) {
index c19a2c95ded1c91107e92964fe26df5d922414a0..d19590538aee1d2d056d91fc73fa7455035944d0 100644 (file)
@@ -99,8 +99,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
         const _sQ = new Uint8Array(sock._sQbufferSize);
         const rQ = new Uint8Array(sock._rQbufferSize);
 
-        Websock.prototype._old_allocate_buffers = Websock.prototype._allocate_buffers;
-        Websock.prototype._allocate_buffers = function () {
+        Websock.prototype._oldAllocateBuffers = Websock.prototype._allocateBuffers;
+        Websock.prototype._allocateBuffers = function () {
             this._sQ = _sQ;
             this._rQ = rQ;
         };
@@ -108,7 +108,7 @@ describe('Remote Frame Buffer Protocol Client', function () {
     });
 
     after(function () {
-        Websock.prototype._allocate_buffers = Websock.prototype._old_allocate_buffers;
+        Websock.prototype._allocateBuffers = Websock.prototype._oldAllocateBuffers;
         this.clock.restore();
         window.requestAnimationFrame = raf;
     });
index e0bac39e6e0cc4d4839df4f6bb74685d7f0d7f1a..a8e17e6bbe5fb85ff7f17aeec6ac5999a4e6d8d4 100644 (file)
@@ -13,7 +13,7 @@ describe('Websock', function () {
         beforeEach(function () {
             sock = new Websock();
             // skip init
-            sock._allocate_buffers();
+            sock._allocateBuffers();
             sock._rQ.set(RQ_TEMPLATE);
             sock._rQlen = RQ_TEMPLATE.length;
         });
@@ -33,51 +33,51 @@ describe('Websock', function () {
 
         describe('rQpeek8', function () {
             it('should peek at the next byte without poping it off the queue', function () {
-                const bef_len = sock.rQlen;
+                const befLen = sock.rQlen;
                 const peek = sock.rQpeek8();
                 expect(sock.rQpeek8()).to.equal(peek);
-                expect(sock.rQlen).to.equal(bef_len);
+                expect(sock.rQlen).to.equal(befLen);
             });
         });
 
         describe('rQshift8()', function () {
             it('should pop a single byte from the receive queue', function () {
                 const peek = sock.rQpeek8();
-                const bef_len = sock.rQlen;
+                const befLen = sock.rQlen;
                 expect(sock.rQshift8()).to.equal(peek);
-                expect(sock.rQlen).to.equal(bef_len - 1);
+                expect(sock.rQlen).to.equal(befLen - 1);
             });
         });
 
         describe('rQshift16()', function () {
             it('should pop two bytes from the receive queue and return a single number', function () {
-                const bef_len = sock.rQlen;
+                const befLen = sock.rQlen;
                 const expected = (RQ_TEMPLATE[0] << 8) + RQ_TEMPLATE[1];
                 expect(sock.rQshift16()).to.equal(expected);
-                expect(sock.rQlen).to.equal(bef_len - 2);
+                expect(sock.rQlen).to.equal(befLen - 2);
             });
         });
 
         describe('rQshift32()', function () {
             it('should pop four bytes from the receive queue and return a single number', function () {
-                const bef_len = sock.rQlen;
+                const befLen = sock.rQlen;
                 const expected = (RQ_TEMPLATE[0] << 24) +
                                (RQ_TEMPLATE[1] << 16) +
                                (RQ_TEMPLATE[2] << 8) +
                                RQ_TEMPLATE[3];
                 expect(sock.rQshift32()).to.equal(expected);
-                expect(sock.rQlen).to.equal(bef_len - 4);
+                expect(sock.rQlen).to.equal(befLen - 4);
             });
         });
 
         describe('rQshiftStr', function () {
             it('should shift the given number of bytes off of the receive queue and return a string', function () {
-                const bef_len = sock.rQlen;
-                const bef_rQi = sock.rQi;
+                const befLen = sock.rQlen;
+                const befRQi = sock.rQi;
                 const shifted = sock.rQshiftStr(3);
                 expect(shifted).to.be.a('string');
-                expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3))));
-                expect(sock.rQlen).to.equal(bef_len - 3);
+                expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, befRQi, 3))));
+                expect(sock.rQlen).to.equal(befLen - 3);
             });
 
             it('should shift the entire rest of the queue off if no length is given', function () {
@@ -112,12 +112,12 @@ describe('Websock', function () {
 
         describe('rQshiftBytes', function () {
             it('should shift the given number of bytes of the receive queue and return an array', function () {
-                const bef_len = sock.rQlen;
-                const bef_rQi = sock.rQi;
+                const befLen = sock.rQlen;
+                const befRQi = sock.rQi;
                 const shifted = sock.rQshiftBytes(3);
                 expect(shifted).to.be.an.instanceof(Uint8Array);
-                expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3));
-                expect(sock.rQlen).to.equal(bef_len - 3);
+                expect(shifted).to.array.equal(new Uint8Array(RQ_TEMPLATE.buffer, befRQi, 3));
+                expect(sock.rQlen).to.equal(befLen - 3);
             });
 
             it('should shift the entire rest of the queue off if no length is given', function () {
@@ -132,9 +132,9 @@ describe('Websock', function () {
             });
 
             it('should not modify the receive queue', function () {
-                const bef_len = sock.rQlen;
+                const befLen = sock.rQlen;
                 sock.rQslice(0, 2);
-                expect(sock.rQlen).to.equal(bef_len);
+                expect(sock.rQlen).to.equal(befLen);
             });
 
             it('should return an array containing the given slice of the receive queue', function () {
@@ -198,7 +198,7 @@ describe('Websock', function () {
                 sock._websocket.readyState = WebSocket.OPEN;
                 sock._sQ = new Uint8Array([1, 2, 3]);
                 sock._sQlen = 3;
-                const encoded = sock._encode_message();
+                const encoded = sock._encodeMessage();
 
                 sock.flush();
                 expect(sock._websocket.send).to.have.been.calledOnce;
@@ -232,22 +232,22 @@ describe('Websock', function () {
             });
         });
 
-        describe('send_string', function () {
+        describe('sendString', function () {
             beforeEach(function () {
                 sock.send = sinon.spy();
             });
 
             it('should call send after converting the string to an array', function () {
-                sock.send_string("\x01\x02\x03");
+                sock.sendString("\x01\x02\x03");
                 expect(sock.send).to.have.been.calledWith([1, 2, 3]);
             });
         });
     });
 
     describe('lifecycle methods', function () {
-        let old_WS;
+        let oldWS;
         before(function () {
-            old_WS = WebSocket;
+            oldWS = WebSocket;
         });
 
         let sock;
@@ -255,10 +255,10 @@ describe('Websock', function () {
             sock = new Websock();
             // eslint-disable-next-line no-global-assign
             WebSocket = sinon.spy();
-            WebSocket.OPEN = old_WS.OPEN;
-            WebSocket.CONNECTING = old_WS.CONNECTING;
-            WebSocket.CLOSING = old_WS.CLOSING;
-            WebSocket.CLOSED = old_WS.CLOSED;
+            WebSocket.OPEN = oldWS.OPEN;
+            WebSocket.CONNECTING = oldWS.CONNECTING;
+            WebSocket.CLOSING = oldWS.CLOSING;
+            WebSocket.CLOSED = oldWS.CLOSED;
 
             WebSocket.prototype.binaryType = 'arraybuffer';
         });
@@ -306,30 +306,30 @@ describe('Websock', function () {
                 expect(sock._websocket.close).not.to.have.been.called;
             });
 
-            it('should reset onmessage to not call _recv_message', function () {
-                sinon.spy(sock, '_recv_message');
+            it('should reset onmessage to not call _recvMessage', function () {
+                sinon.spy(sock, '_recvMessage');
                 sock.close();
                 sock._websocket.onmessage(null);
                 try {
-                    expect(sock._recv_message).not.to.have.been.called;
+                    expect(sock._recvMessage).not.to.have.been.called;
                 } finally {
-                    sock._recv_message.restore();
+                    sock._recvMessage.restore();
                 }
             });
         });
 
         describe('event handlers', function () {
             beforeEach(function () {
-                sock._recv_message = sinon.spy();
+                sock._recvMessage = sinon.spy();
                 sock.on('open', sinon.spy());
                 sock.on('close', sinon.spy());
                 sock.on('error', sinon.spy());
                 sock.open('ws://');
             });
 
-            it('should call _recv_message on a message', function () {
+            it('should call _recvMessage on a message', function () {
                 sock._websocket.onmessage(null);
-                expect(sock._recv_message).to.have.been.calledOnce;
+                expect(sock._recvMessage).to.have.been.calledOnce;
             });
 
             it('should call the open event handler on opening', function () {
@@ -350,7 +350,7 @@ describe('Websock', function () {
 
         after(function () {
             // eslint-disable-next-line no-global-assign
-            WebSocket = old_WS;
+            WebSocket = oldWS;
         });
     });
 
@@ -358,13 +358,13 @@ describe('Websock', function () {
         let sock;
         beforeEach(function () {
             sock = new Websock();
-            sock._allocate_buffers();
+            sock._allocateBuffers();
         });
 
         it('should support adding binary Uint8Array data to the receive queue', function () {
             const msg = { data: new Uint8Array([1, 2, 3]) };
             sock._mode = 'binary';
-            sock._recv_message(msg);
+            sock._recvMessage(msg);
             expect(sock.rQshiftStr(3)).to.equal('\x01\x02\x03');
         });
 
@@ -372,7 +372,7 @@ describe('Websock', function () {
             sock._eventHandlers.message = sinon.spy();
             const msg = { data: new Uint8Array([1, 2, 3]).buffer };
             sock._mode = 'binary';
-            sock._recv_message(msg);
+            sock._recvMessage(msg);
             expect(sock._eventHandlers.message).to.have.been.calledOnce;
         });
 
@@ -380,7 +380,7 @@ describe('Websock', function () {
             sock._eventHandlers.message = sinon.spy();
             const msg = { data: new Uint8Array([]).buffer };
             sock._mode = 'binary';
-            sock._recv_message(msg);
+            sock._recvMessage(msg);
             expect(sock._eventHandlers.message).not.to.have.been.called;
         });
 
@@ -391,7 +391,7 @@ describe('Websock', function () {
             sock.rQi = 6;
             const msg = { data: new Uint8Array([1, 2, 3]).buffer };
             sock._mode = 'binary';
-            sock._recv_message(msg);
+            sock._recvMessage(msg);
             expect(sock._rQlen).to.equal(0);
             expect(sock.rQi).to.equal(0);
         });
@@ -403,7 +403,7 @@ describe('Websock', function () {
             sock.rQi = 10;
             const msg = { data: new Uint8Array([1, 2]).buffer };
             sock._mode = 'binary';
-            sock._recv_message(msg);
+            sock._recvMessage(msg);
             expect(sock._rQlen).to.equal(12);
             expect(sock.rQi).to.equal(0);
         });
@@ -415,7 +415,7 @@ describe('Websock', function () {
             sock._rQbufferSize = 20;
             const msg = { data: new Uint8Array(30).buffer };
             sock._mode = 'binary';
-            sock._recv_message(msg);
+            sock._recvMessage(msg);
             expect(sock._rQlen).to.equal(30);
             expect(sock.rQi).to.equal(0);
             expect(sock._rQ.length).to.equal(240);  // keep the invariant that rQbufferSize / 8 >= rQlen
@@ -428,7 +428,7 @@ describe('Websock', function () {
             sock._rQbufferSize = 20;
             const msg = { data: new Uint8Array(6).buffer };
             sock._mode = 'binary';
-            sock._recv_message(msg);
+            sock._recvMessage(msg);
             expect(sock._rQlen).to.equal(6);
             expect(sock.rQi).to.equal(0);
             expect(sock._rQ.length).to.equal(48);
@@ -450,7 +450,7 @@ describe('Websock', function () {
             it('should only send the send queue up to the send queue length', function () {
                 sock._sQ = new Uint8Array([1, 2, 3, 4, 5]);
                 sock._sQlen = 3;
-                const res = sock._encode_message();
+                const res = sock._encodeMessage();
                 expect(res).to.array.equal(new Uint8Array([1, 2, 3]));
             });