Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update atmosphere.js #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update atmosphere.js #265

wants to merge 1 commit into from

Conversation

inad9300
Copy link

@inad9300 inad9300 commented Oct 3, 2020

Some findings after exposing the file to the TypeScript compiler...

@@ -38,15 +38,20 @@

"use strict";

var atmosphere = {},
guid,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable and hasOwn below were not used.

Comment on lines +206 to +215
id: undefined,
openId: undefined,
reconnectId: undefined,
firstMessage: undefined,
isOpen: undefined,
isReopen: undefined,
closed: undefined,
ctime: undefined,
heartbeatTimer: undefined,
force: undefined,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these, plus mrequest and webSocketUrl above, were accessed as properties of the _request object (or copies thereof) but never declared. It is not strictly necessary, but helps to have an overview of all the properties that will be used.

@@ -232,7 +249,7 @@
reasonPhrase: "OK",
responseBody: '',
messages: [],
headers: [],
headers: {},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every use of this field was as an object.

*
* @private
*/
var _beforeUnloadState = false;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never accessed. Rather, the nonexistent atmosphere._beforeUnloadState was. I moved this declaration to line 52.

@@ -1372,7 +1381,7 @@

_response.transport = "websocket";

var location = _buildWebSocketUrl(_request.url);
var location = _buildWebSocketUrl();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function takes no arguments.

@@ -1746,7 +1755,7 @@
} else {
atmosphere.util.log(_request.logLevel, ["Websocket reconnect maximum try reached " + _requestCount]);
if (_canLog('warn')) {
atmosphere.util.warn("Websocket error, reason: " + message.reason);
atmosphere.util.warn("Websocket error, reason: " + (message || {}).reason);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message is being accessed here as a global variable, but hasn't been initialized as such. I added a default value to avoid the "NPE", but I expect this log to end with reason: undefined, so further revision is necessary.

@@ -1763,8 +1772,6 @@

if (typeof (_request.onTransportFailure) !== 'undefined') {
_request.onTransportFailure(errorMessage, _request);
} else if (typeof (atmosphere.util.onTransportFailure) !== 'undefined') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atmosphere.util simply does not have a field onTransportFailure, so I don't see the point of having this check.

@@ -1972,7 +1979,7 @@
_response.error = true;
_response.ffTryingReconnect = true;
try {
_response.status = XMLHttpRequest.status;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XMLHttpRequest does not have a status field. I'm assuming we want here the status from ajaxRequest, the instance of XMLHttpRequest.

@@ -2246,7 +2253,7 @@
status = ajaxRequest.status > 1000 ? 0 : ajaxRequest.status;
}
_response.status = status === 0 ? 204 : status;
_response.reason = status === 0 ? "Server resumed the connection or down." : "OK";
_response.reasonPhrase = status === 0 ? "Server resumed the connection or down." : "OK";
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_response has reasonPhrase, but not reason...

@@ -2504,7 +2511,7 @@
res.innerText = "";
var skipCallbackInvocation = _trackMessageSize(text, rq, _response);
if (skipCallbackInvocation) {
return "";
return false;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be equivalent at run time, but it is more clear if the return type is the same across the function.

@@ -2748,8 +2755,6 @@
if (m.id !== guid) {
if (typeof (_request.onLocalMessage) !== 'undefined') {
_request.onLocalMessage(m.event);
} else if (typeof (atmosphere.util.onLocalMessage) !== 'undefined') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to with onTransportFailure, atmosphere.util simply does not have a field onLocalMessage.

@@ -3190,15 +3195,15 @@
return s.join("&").replace(/%20/g, "+");
},

storage: function () {
storage: (function () {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atmosphere.util.storage is being checked as a boolean and is being assigned boolean values. Declaring it as a function looked like a mistake to me.

@@ -3222,46 +3227,24 @@
};
},

each: function (obj, callback, args) {
each: function (obj, callback) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atmosphere.util.each is always called with exactly 2 arguments.

@inad9300 inad9300 mentioned this pull request Oct 3, 2020
@jfarcand
Copy link
Member

jfarcand commented Jul 9, 2021

@SuperPat45 If you have time, do you think you can take a look at this pull request?

@SuperPat45
Copy link
Contributor

SuperPat45 commented Jul 9, 2021

I'm sorry, but I'm going on vacation and I don't plan to work on atmosphere anymore soon, since I was able to fix the last bugs I had.

@jfarcand
Copy link
Member

jfarcand commented Jul 9, 2021

@SuperPat45 Thanks for all!!!!

Copy link
Contributor

@SuperPat45 SuperPat45 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally tested these changes and this seems fine for me.

I not found any regression in WebSocket and Long-polling mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants