Skip to content

Commit

Permalink
Improve schema valiation
Browse files Browse the repository at this point in the history
  • Loading branch information
jondubois committed Sep 18, 2023
1 parent 82e26a8 commit 088c63a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
9 changes: 6 additions & 3 deletions lib/clientsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ AGClientSocket.prototype._removeAuthToken = function (data) {

AGClientSocket.prototype._privateDataHandlerMap = {
'#publish': function (data) {
if (typeof data.channel !== 'string') return;
let undecoratedChannelName = this._undecorateChannelName(data.channel);
let isSubscribed = this.isSubscribed(undecoratedChannelName, true);

Expand All @@ -295,6 +296,7 @@ AGClientSocket.prototype._privateDataHandlerMap = {
}
},
'#kickOut': function (data) {
if (typeof data.channel !== 'string') return;
let undecoratedChannelName = this._undecorateChannelName(data.channel);
let channel = this._channelMap[undecoratedChannelName];
if (channel) {
Expand Down Expand Up @@ -482,7 +484,8 @@ AGClientSocket.prototype.encodeBase64 = function (decodedString) {
};

AGClientSocket.prototype._extractAuthTokenData = function (signedAuthToken) {
let tokenParts = (signedAuthToken || '').split('.');
if (typeof signedAuthToken !== 'string') return null;
let tokenParts = signedAuthToken.split('.');
let encodedTokenData = tokenParts[1];
if (encodedTokenData != null) {
let tokenData = encodedTokenData;
Expand Down Expand Up @@ -689,7 +692,7 @@ AGClientSocket.prototype._destroy = function (code, reason, openAbort) {

if (!AGClientSocket.ignoreStatuses[code]) {
let closeMessage;
if (reason) {
if (typeof reason === 'string') {
closeMessage = 'Socket connection closed with status code ' + code + ' and reason: ' + reason;
} else {
closeMessage = 'Socket connection closed with status code ' + code;
Expand Down Expand Up @@ -726,7 +729,7 @@ AGClientSocket.prototype._destroy = function (code, reason, openAbort) {
AGClientSocket.prototype._onInboundTransmit = function (event, data) {
let handler = this._privateDataHandlerMap[event];
if (handler) {
handler.call(this, data);
handler.call(this, data || {});
} else {
this._receiverDemux.write(event, data);
}
Expand Down
14 changes: 7 additions & 7 deletions lib/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ function AGTransport(authEngine, codecEngine, options, wsOptions, handlers) {
if (event.code == null) {
// This is to handle an edge case in React Native whereby
// event.code is undefined when the mobile device is locked.
// TODO: This is not ideal since this condition could also apply to
// an abnormal close (no close control frame) which would be a 1006.
// Note that this condition may also apply to an abnormal close
// (no close control frame) which would normally be a 1006.
code = 1005;
} else {
code = event.code;
Expand Down Expand Up @@ -268,14 +268,14 @@ AGTransport.prototype._destroy = function (code, reason) {
};

AGTransport.prototype._processInboundPacket = function (packet, message) {
if (packet && packet.event != null) {
if (packet.cid == null) {
this._onInboundTransmitHandler({...packet});
} else {
if (packet && typeof packet.event === 'string') {
if (typeof packet.cid === 'number') {
let request = new AGRequest(this, packet.cid, packet.event, packet.data);
this._onInboundInvokeHandler(request);
} else {
this._onInboundTransmitHandler({...packet});
}
} else if (packet && packet.rid != null) {
} else if (packet && typeof packet.rid === 'number') {
let eventObject = this._callbackMap[packet.rid];
if (eventObject) {
clearTimeout(eventObject.timeout);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"dependencies": {
"ag-channel": "^5.0.0",
"ag-request": "^1.0.0",
"ag-request": "^1.0.1",
"async-stream-emitter": "^6.0.1",
"buffer": "^5.2.1",
"clone-deep": "^4.0.1",
Expand All @@ -49,6 +49,6 @@
"localStorage": "^1.0.3",
"mocha": "^10.2.0",
"rollup": "^3.28.1",
"socketcluster-server": "^18.0.1"
"socketcluster-server": "^18.1.0"
}
}

0 comments on commit 088c63a

Please sign in to comment.