Skip to content

Commit

Permalink
Merge 3b76a65 into de25bde
Browse files Browse the repository at this point in the history
  • Loading branch information
vartanbeno committed Apr 1, 2020
2 parents de25bde + 3b76a65 commit 789bdca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
10 changes: 8 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function (playerOptions, ensureAuthHeaders, self) {
playerOptions.secure;

if (settings.secure) {
protocol = 'https'
protocol = 'https';
} else {
protocol = 'http';
}
Expand All @@ -62,6 +62,11 @@ module.exports = function (playerOptions, ensureAuthHeaders, self) {
throw new Error('socketEventSubscriber must be an instance of event.EventEmitter');
}

let socketOptions = options.socket;
if (validation.isEmpty(options.socket)) {
socketOptions = {};
}

let
authHeaders = yield ensureAuthHeaders(),
authToken,
Expand All @@ -75,7 +80,8 @@ module.exports = function (playerOptions, ensureAuthHeaders, self) {
url = [protocol, '://', options.host || settings.host].join('');
query = ['clientId=', clientId, '&token=', authToken].join('');

socket = new io(url, { 'query' : query});
socketOptions.query = query;
socket = new io(url, socketOptions);

// fired after a successful connection
socket.on('connect', () => {
Expand Down
16 changes: 11 additions & 5 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,16 @@ module.exports = (function (self) {
}

function isRetry(options, startTime, tryCount) {
if (tryCount > options.maxRetries) {
return false;
}

if (options.totalTimeout) {
const timeElapsed = (new Date()) - startTime;
return timeElapsed < options.totalTimeout;
}

return tryCount <= options.maxRetries;
return true;
}

function Request (settings) {
Expand Down Expand Up @@ -370,9 +374,11 @@ module.exports = (function (self) {
// handle retry if error code is above threshhold
if (retry) {
tryCount += 1;
retryWait = retryWait * EXPONENT;
return delay(retryWait)
.then(makeRequest);
.then(makeRequest)
.then(() => {
retryWait *= EXPONENT;
});
}

// attempt to parse the body
Expand Down Expand Up @@ -412,10 +418,10 @@ module.exports = (function (self) {
// retry if below retry count threshhold
if (isRetry(options, startTime, tryCount)) {
tryCount += 1;
retryWait = retryWait * EXPONENT;
return delay(retryWait)
.then(makeRequest)
.then(() => {
return makeRequest();
retryWait *= EXPONENT;
});
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playnetwork-sdk",
"version": "1.4.9",
"version": "1.4.10",
"contributors": [
{
"name": "Joshua Thomas",
Expand Down

0 comments on commit 789bdca

Please sign in to comment.