Skip to content

Commit

Permalink
Trying to detect protocol http or https for #16 and #19
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioastarita committed Dec 5, 2016
1 parent 387c462 commit 0919e47
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions render/SpotifyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const async = require('async');
const initialPortTest = 4370;

export class SpotifyService {

protected https = false;
protected foundPort = false;
protected port : number;
protected portTries = 15;
Expand All @@ -26,7 +26,8 @@ export class SpotifyService {
}

protected url(u:string) {
return `https://127.0.0.1:${this.port}${u}`;
const protocol = this.https ? 'https' : 'http';
return `${protocol}://127.0.0.1:${this.port}${u}`;
}

public getOAuthToken(cb) {
Expand All @@ -51,11 +52,16 @@ export class SpotifyService {
if (!this.foundPort) {
this.port = initialPortTest;
}
async.retry(this.portTries, (finish) => {
async.retry(this.portTries * 2, (finish) => {
this.getCsrfToken((err, token) => {
if (err) {
console.log('FAILED WITH PORT: ', this.port)
this.port++;
console.log('FAILED WITH PORT: ', this.port, ' and https is ', this.https);
if (this.https) {
this.port++;
this.https = false;
} else {
this.https = true;
}
return finish(err);
}
this.foundPort = true;
Expand Down

0 comments on commit 0919e47

Please sign in to comment.