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

[TIMOB-25072] Wait for server response without using "while loop" #106

Merged
merged 7 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion build/liveview.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,20 @@
request.open('GET', url);
request.setRequestHeader('x-platform', this.platform);
request.send();

//
// Windows only private API: _waitForResponse() waits for the response from the server.
//
if (this.platform === 'windows' && request._waitForResponse) {
request._waitForResponse();
if (request.readyState === 4 || request.status === 404) {
rsp = request.status === 200 ? request.responseText : false;
} else {
throw new Error('[LiveView] File Server unavailable. Host Unreachable @ ' + Module._url + ':' + Module._port + '\n[LiveView] Please ensure your device and computer are on the same network and the port is not blocked.');
}
done = true;
}

while (!done) {
if (request.readyState === 4 || request.status === 404) {
rsp = request.status === 200 ? request.responseText : false;
Expand Down Expand Up @@ -714,4 +728,4 @@
// Prevent display from sleeping

Titanium.App.idleTimerDisabled = true;
})(undefined);
})(this);
14 changes: 14 additions & 0 deletions lib/platform/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ Module.prototype._getRemoteSource = function (file, timeout) {
request.open('GET', url);
request.setRequestHeader('x-platform', this.platform);
request.send();

//
// Windows only private API: _waitForResponse() waits for the response from the server.
//
if (this.platform === 'windows' && request._waitForResponse) {
request._waitForResponse();
if (request.readyState === 4 || request.status === 404) {
rsp = request.status === 200 ? request.responseText : false;
} else {
throw new Error('[LiveView] File Server unavailable. Host Unreachable @ ' + Module._url + ':' + Module._port + '\n[LiveView] Please ensure your device and computer are on the same network and the port is not blocked.');
}
done = true;
}

while (!done) {
if (request.readyState === 4 || request.status === 404) {
rsp = (request.status === 200) ? request.responseText : false;
Expand Down