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