Skip to content

Commit

Permalink
Renaming of polling
Browse files Browse the repository at this point in the history
  • Loading branch information
NVandenBossche committed May 26, 2023
1 parent b33c028 commit 1d9b3f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ app.post('/username-password', function (req, res) {
app.get('/devicePol', async (req, res) => {
authInstance.setActiveCallback(true);

await authInstance.pollContinually();
await authInstance.pollTokenEndpoint();
res.redirect('/launch/device');
});

Expand Down
12 changes: 7 additions & 5 deletions services/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ class DeviceService extends AuthService {
};

// TODO: Add timeout after x minutes
pollContinually = async () => {
pollTokenEndpoint = async () => {
let postRequest = this.generatePollingRequest();
let interval = this.#interval;
let pollResponse;

while (true) {
pollResponse = await this.singlePoll(postRequest);
pollResponse = await this.postToEndpoint(postRequest);
if (!pollResponse.error) {
break;
}
Expand All @@ -81,7 +81,8 @@ class DeviceService extends AuthService {
return pollResponse;
};

singlePoll = async (postRequest) => {
// Post to the token endpoint and return response
postToEndpoint = async (postRequest) => {
// Use fetch to execute the POST request
const response = await fetch(postRequest.url, {
method: postRequest.method,
Expand All @@ -93,9 +94,10 @@ class DeviceService extends AuthService {
return jsonResponse;
};

sleep = async (milliseconds) => {
// Sleep function to wait specified amount of ms
sleep = async (timeInMs) => {
await new Promise((resolve) => {
return setTimeout(resolve, milliseconds);
return setTimeout(resolve, timeInMs);
});
};
}
Expand Down

0 comments on commit 1d9b3f4

Please sign in to comment.