All promises are now handled

This commit is contained in:
David Négrier 2022-01-04 16:48:47 +01:00
parent 6e27ffb2d5
commit 24baf5664c
21 changed files with 262 additions and 208 deletions

View file

@ -188,7 +188,7 @@ class ConnectionManager {
//Set last room visited! (connected or nor, must to be saved in localstorage and cache API)
//use href to keep # value
localUserStore.setLastRoomUrl(this._currentRoom.href);
await localUserStore.setLastRoomUrl(this._currentRoom.href);
//todo: add here some kind of warning if authToken has expired.
if (!this.authToken && !this._currentRoom.authenticationMandatory) {
@ -301,7 +301,7 @@ class ConnectionManager {
this.reconnectingTimeout = setTimeout(() => {
//todo: allow a way to break recursion?
//todo: find a way to avoid recursive function. Otherwise, the call stack will grow indefinitely.
this.connectToRoomSocket(roomUrl, name, characterLayers, position, viewport, companion).then(
void this.connectToRoomSocket(roomUrl, name, characterLayers, position, viewport, companion).then(
(connection) => resolve(connection)
);
}, 4000 + Math.floor(Math.random() * 2000));

View file

@ -136,13 +136,12 @@ class LocalUserStore {
return localStorage.getItem(ignoreFollowRequests) === "true";
}
setLastRoomUrl(roomUrl: string): void {
async setLastRoomUrl(roomUrl: string): Promise<void> {
localStorage.setItem(lastRoomUrl, roomUrl.toString());
if ("caches" in window) {
caches.open(cacheAPIIndex).then((cache) => {
const stringResponse = new Response(JSON.stringify({ roomUrl }));
cache.put(`/${lastRoomUrl}`, stringResponse);
});
const cache = await caches.open(cacheAPIIndex);
const stringResponse = new Response(JSON.stringify({ roomUrl }));
await cache.put(`/${lastRoomUrl}`, stringResponse);
}
}
getLastRoomUrl(): string {

View file

@ -352,7 +352,7 @@ export class RoomConnection implements RoomConnection {
break;
}
case "tokenExpiredMessage": {
connectionManager.logout();
connectionManager.logout().catch((e) => console.error(e));
this.closed = true; //technically, this isn't needed since loadOpenIDScreen() will do window.location.assign() but I prefer to leave it for consistency
break;
}