File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -3,20 +3,31 @@ import { SettingsStorage } from "hydrogen-web/src/platform/web/dom/SettingsStora
33import { Platform as BasePlatform } from "hydrogen-web/src/platform/web/Platform" ;
44import { History } from "./History" ;
55import { Navigation } from "./Navigation" ;
6+ import { ServiceWorkerHandler } from "./ServiceWorkerHandler" ;
67import { StorageFactory } from "./StorageFactory" ;
78
89export class Platform extends BasePlatform {
910 private settingsStorage : SettingsStorage ;
1011 private sessionInfoStorage : SessionInfoStorage ;
1112 private storageFactory : StorageFactory ;
13+ private _serviceWorkerHandler : ServiceWorkerHandler ;
1214
1315 constructor ( options ) {
16+ const assetPaths = structuredClone ( options . assetPaths ) ;
17+
18+ // Unset serviceWorker path so that the base constructor doesn't register the service worker handler.
19+ delete options . assetPaths . serviceWorker ;
1420 super ( options ) ;
21+
22+ // Register our own service worker handler.
23+ if ( assetPaths . serviceWorker && "serviceWorker" in navigator ) {
24+ this . _serviceWorkerHandler = new ServiceWorkerHandler ( ) ;
25+ this . _serviceWorkerHandler . registerAndStart ( assetPaths . serviceWorker ) ;
26+ }
27+
1528 this . settingsStorage = new SettingsStorage ( "chatrix_setting_v1_" ) ;
1629 this . sessionInfoStorage = new SessionInfoStorage ( "chatrix_sessions_v1" ) ;
17- // @ts -ignore
1830 this . storageFactory = new StorageFactory ( this . _serviceWorkerHandler ) ;
19- // @ts -ignore
2031 this . history = new History ( ) ;
2132 }
2233
Original file line number Diff line number Diff line change 1+ import { ServiceWorkerHandler as BaseHandler } from "hydrogen-web/src/platform/web/dom/ServiceWorkerHandler.js" ;
2+
3+ export class ServiceWorkerHandler extends BaseHandler {
4+ public registerAndStart ( path : string ) {
5+ super . registerAndStart ( path ) ;
6+ }
7+
8+ public async preventConcurrentSessionAccess ( sessionId : string ) {
9+ return super . _sendAndWaitForReply ( "closeSession" , { sessionId } ) ;
10+ }
11+ }
You can’t perform that action at this time.
0 commit comments