Skip to content

Commit

Permalink
refactor: Added more events from places
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Aug 17, 2021
1 parent 0da2bde commit e32cb94
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/scripts/destiny2/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ function DestinyApiClient() {
await db.getItem("destiny-userMembership")
);
}

eventEmitter.emit("destiny-data-loaded");
}

this.loadDestinyContentData = async function () {
Expand Down Expand Up @@ -302,14 +304,17 @@ function DestinyApiClient() {

handleTokenResponse(tokenResponse);
resolve(tokenResponse);
eventEmitter.emit("destiny2-auth-refreshed");
return;
}

reject(tokenRequest.responseText);
eventEmitter.emit("destiny2-auth-refresh-failed");
};

tokenRequest.onerror = function () {
reject(tokenRequest.responseText);
eventEmitter.emit("destiny2-auth-refresh-failed");
};

tokenRequest.send(
Expand Down Expand Up @@ -628,6 +633,8 @@ function DestinyApiClient() {

namedDataObject = self.mapHashesToDefinitionsInObject(namedDataObject);

eventEmitter.emit("destiny2-api-update", namedDataObject);

return namedDataObject;
};

Expand Down Expand Up @@ -816,6 +823,19 @@ function DestinyApiClient() {
return trackableDataItems;
};

this.isAuthenticated = async function () {
try {
await refreshTokenIfExpired();
const isAuthenticated = (await db.getItem("destinyToken")) !== null;
eventEmitter.emit("destiny2-is-authenticated", isAuthenticated);
return isAuthenticated;
} catch (e) {
log("AUTH-FAIL", e);
eventEmitter.emit("destiny2-is-authenticated", false);
return false;
}
};

var self = this;

loadDataFromStorage();
Expand Down

0 comments on commit e32cb94

Please sign in to comment.