close session db in other tabs when opening

This commit is contained in:
Bruno Windels 2020-10-16 12:50:37 +02:00
parent fc61729cb3
commit 0d622164df

View File

@ -23,7 +23,12 @@ const sessionName = sessionId => `hydrogen_session_${sessionId}`;
const openDatabaseWithSessionId = sessionId => openDatabase(sessionName(sessionId), createStores, schema.length);
export class StorageFactory {
constructor(serviceWorkerHandler) {
this._serviceWorkerHandler = serviceWorkerHandler;
}
async create(sessionId) {
await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId);
const db = await openDatabaseWithSessionId(sessionId);
return new Storage(db);
}