Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
update onNetworkChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Nov 3, 2018
1 parent 5fb729b commit ef5ce9a
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions apiclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ function replaceAll(originalString, strReplace, strWith) {
return originalString.replace(reg, strWith);
}

function onFetchFail(instance, url, response) {

events.trigger(instance, 'requestfail', [
{
url,
status: response.status,
errorCode: response.headers ? response.headers.get('X-Application-Error-Code') : null
}]);
}

function paramsToString(params) {

const values = [];
Expand Down Expand Up @@ -118,6 +108,24 @@ function clearCurrentUserCacheIfNeeded(apiClient) {
}
}

function onNetworkChanged(instance, resetAddress) {

if (resetAddress) {

const serverInfo = instance.serverInfo();
if (serverInfo.LocalAddress) {
instance._serverAddress = serverInfo.LocalAddress;
}
}

instance.lastDetectedBitrate = 0;
instance.lastDetectedBitrateTime = 0;
setSavedEndpointInfo(instance, null);

redetectBitrate(instance);
refreshWakeOnLanInfoIfNeeded(instance);
}

/**
* Creates a new api client instance
* @param {String} serverAddress
Expand Down Expand Up @@ -221,20 +229,15 @@ class ApiClient {

this._serverAddress = val;

this.onNetworkChange();
onNetworkChanged(this);
}

return this._serverAddress;
}

onNetworkChange() {

this.lastDetectedBitrate = 0;
this.lastDetectedBitrateTime = 0;
setSavedEndpointInfo(this, null);
onNetworkChanged() {

redetectBitrate(this);
refreshWakeOnLanInfoIfNeeded(this);
onNetworkChanged(this, true);
}

/**
Expand Down Expand Up @@ -295,7 +298,6 @@ class ApiClient {
return response;
}
} else {
onFetchFail(instance, request.url, response);
return Promise.reject(response);
}

Expand Down Expand Up @@ -323,15 +325,13 @@ class ApiClient {
}, innerError => {

console.log("Reconnect failed");
onFetchFail(instance, request.url, {});
throw innerError;
});

} else {

console.log("Reporting request failure");

onFetchFail(instance, request.url, {});
throw error;
}
});
Expand Down Expand Up @@ -371,12 +371,10 @@ class ApiClient {
return response;
}
} else {
onFetchFail(instance, request.url, response);
return Promise.reject(response);
}

}, error => {
onFetchFail(instance, request.url, {});
throw error;
});
}
Expand Down Expand Up @@ -1647,22 +1645,22 @@ class ApiClient {
Gets available hardware accelerations
*/
getHardwareAccelerations() {
const url = this.getUrl("Encoding/HardwareAccelerations");
return this.getJSON(url);

const url = this.getUrl("Encoding/HardwareAccelerations");

return this.getJSON(url);
};
/**
Gets available video codecs
*/

/**
Gets available video codecs
*/
getVideoCodecInformation() {
const url = this.getUrl("Encoding/CodecInformation/Video");
return this.getJSON(url);

const url = this.getUrl("Encoding/CodecInformation/Video");

return this.getJSON(url);
};

/**
* Gets the server's scheduled tasks
*/
Expand Down

0 comments on commit ef5ce9a

Please sign in to comment.