Skip to content

Commit

Permalink
Merge pull request #5 from betha-plataforma/bugfix-websocket-refresh
Browse files Browse the repository at this point in the history
Bugfix websocket refresh
  • Loading branch information
gdfreitas authored Mar 15, 2021
2 parents 998288a + 345f5a9 commit 9c40ace
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@betha-plataforma/estrutura-componentes",
"version": "1.1.0",
"version": "1.1.1",
"description": "Coleção de Web Components para compor a estrutura de uma aplicação front-end da Betha Sistemas.",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
8 changes: 4 additions & 4 deletions src/components/notificacoes/notificacoes.websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export class NotificationWebSocket {

this.addEventListener('close', async (event: CloseEvent) => {
if (CODES_TO_RECONNECT.includes(event.code) && !this.closed) {

await this.authorization.handleUnauthorizedAccess();

const retryTime = this.refreshTime;
this.refreshTime += RETRY_TIMEOUT_IN_MS;

setTimeout(() => this.refresh(), retryTime);
setTimeout(async () => {
await this.authorization.handleUnauthorizedAccess();
this.refresh();
}, retryTime);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ describe('notificacoes-websocket', () => {

// Act
onCloseCallback({ code: 1001 });
jest.runOnlyPendingTimers();

// Assert
expect(authorization.handleUnauthorizedAccess).toBeCalled();
Expand All @@ -186,6 +187,7 @@ describe('notificacoes-websocket', () => {

// Act
onCloseCallback({ code: 1006 });
jest.runOnlyPendingTimers();

// Assert
expect(authorization.handleUnauthorizedAccess).toBeCalled();
Expand Down

0 comments on commit 9c40ace

Please sign in to comment.