diff --git a/projects/player/modules/verona/services/verona-post.service.spec.ts b/projects/player/modules/verona/services/verona-post.service.spec.ts index 98677f0648432696f240887a8a0e96d07e362873..a3948410b9c552d1ab98801cb9bafaaef2526a35 100644 --- a/projects/player/modules/verona/services/verona-post.service.spec.ts +++ b/projects/player/modules/verona/services/verona-post.service.spec.ts @@ -11,8 +11,7 @@ describe('VeronaPostService', () => { beforeEach(() => { TestBed.configureTestingModule({}); service = TestBed.inject(VeronaPostService); - service.isStandalone = false; - service.sessionId = 'test'; + service.sessionID = 'test'; service.stateReportPolicy = 'eager'; }); @@ -87,7 +86,7 @@ describe('VeronaPostService', () => { eventSubscription.unsubscribe(); done(); }); - service.sendVopReadyNotification(metadata); + VeronaPostService.sendReadyNotification(metadata); }); it('should post a VopUnitNavigationRequestedNotification', done => { @@ -121,6 +120,6 @@ describe('VeronaPostService', () => { eventSubscription.unsubscribe(); done(); }); - service.sendVopWindowFocusChangedNotification(true); + VeronaPostService.sendVopWindowFocusChangedNotification(true); }); }); diff --git a/projects/player/modules/verona/services/verona-post.service.ts b/projects/player/modules/verona/services/verona-post.service.ts index 2a39aa27a3dc8588e95169969975e157e6e6ddd7..766e4a664ad5283261dc48f852bb5f164b1db6dc 100644 --- a/projects/player/modules/verona/services/verona-post.service.ts +++ b/projects/player/modules/verona/services/verona-post.service.ts @@ -15,8 +15,7 @@ import { providedIn: 'root' }) export class VeronaPostService { - private _isStandalone: boolean = true; - private _sessionId: string = 'unKnown'; + sessionID: string | undefined; private _stateReportPolicy: StateReportPolicy = 'eager'; private cachedVopStateChangedNotificationValues: { unitState?: UnitState, @@ -24,25 +23,12 @@ export class VeronaPostService { log?: LogData[] } = {}; - set sessionId(sessionId: string) { - this._sessionId = sessionId; - } - - set isStandalone(isStandalone: boolean) { - this._isStandalone = isStandalone; - } - set stateReportPolicy(stateReportPolicy: StateReportPolicy) { this._stateReportPolicy = stateReportPolicy; } - private send(message: VopMessage): void { - // prevent posts in local (dev) mode - if (!this._isStandalone) { - window.parent.postMessage(message, '*'); - } else { - LogService.debug('player: no host detected'); - } + private static sendMessage(message: VopMessage): void { + window.parent.postMessage(message, '*'); } sendVopStateChangedNotification(values: { @@ -51,7 +37,7 @@ export class VeronaPostService { log?: LogData[] }, requested: boolean = false): void { if (this._stateReportPolicy === 'eager' || requested) { - this.send(this.createVopStateChangedNotification( + VeronaPostService.sendMessage(this.createVopStateChangedNotification( { ...this.cachedVopStateChangedNotificationValues, ...values } )); } else { @@ -66,16 +52,16 @@ export class VeronaPostService { }): VopStateChangedNotification { return { type: 'vopStateChangedNotification', - sessionId: this._sessionId, + sessionId: this.sessionID as string, timeStamp: Date.now(), ...(values) }; } - sendVopReadyNotification(playerMetadata: VopMetaData): void { + static sendReadyNotification(playerMetadata: VopMetaData): void { if (playerMetadata) { LogService.debug('player: sendVopReadyNotification', playerMetadata); - this.send({ + VeronaPostService.sendMessage({ type: 'vopReadyNotification', metadata: playerMetadata }); @@ -84,19 +70,19 @@ export class VeronaPostService { } } - sendVopUnitNavigationRequestedNotification = (target: NavigationTarget): void => { - this.send({ + sendVopUnitNavigationRequestedNotification(target: NavigationTarget): void { + VeronaPostService.sendMessage({ type: 'vopUnitNavigationRequestedNotification', - sessionId: this._sessionId, + sessionId: this.sessionID as string, target: target }); - }; + } - sendVopWindowFocusChangedNotification = (focused: boolean): void => { - this.send({ + static sendVopWindowFocusChangedNotification(focused: boolean): void { + VeronaPostService.sendMessage({ type: 'vopWindowFocusChangedNotification', timeStamp: Date.now(), hasFocus: focused }); - }; + } } diff --git a/projects/player/src/app/app.component.ts b/projects/player/src/app/app.component.ts index 0f17f519262f8c7b752dccd5bd5ef8f746b353ae..2d90e758baa8bc031ad3ae4510199270c773c2e3 100644 --- a/projects/player/src/app/app.component.ts +++ b/projects/player/src/app/app.component.ts @@ -23,14 +23,9 @@ export class AppComponent implements OnInit { ngOnInit(): void { this.setLocales(); - this.initVeronaPostService(); + VeronaPostService.sendReadyNotification(this.metaDataService.playerMetadata); this.nativeEventService.focus - .subscribe(isFocused => this.veronaPostService.sendVopWindowFocusChangedNotification(isFocused)); - } - - private initVeronaPostService(): void { - this.veronaPostService.isStandalone = this.isStandalone; - this.veronaPostService.sendVopReadyNotification(this.metaDataService.playerMetadata); + .subscribe(isFocused => VeronaPostService.sendVopWindowFocusChangedNotification(isFocused)); } private setLocales(): void { diff --git a/projects/player/src/app/components/unit/unit.component.ts b/projects/player/src/app/components/unit/unit.component.ts index 10eb04c5de0ee00720c160c17068b102395edcd2..92aeaf645ec0d0147431fd97727a9c68e3e506b0 100644 --- a/projects/player/src/app/components/unit/unit.component.ts +++ b/projects/player/src/app/components/unit/unit.component.ts @@ -50,7 +50,7 @@ export class UnitComponent implements OnInit { this.playerConfig = message.playerConfig || {}; LogService.info('player: unitStateElementCodes', this.unitStateService.elementCodes); this.metaDataService.resourceURL = this.playerConfig.directDownloadUrl; - this.veronaPostService.sessionId = message.sessionId; + this.veronaPostService.sessionID = message.sessionId; this.veronaPostService.stateReportPolicy = message.playerConfig?.stateReportPolicy || 'none'; this.unitStateService.elementCodes = message.unitState?.dataParts?.elementCodes ? JSON.parse(message.unitState.dataParts.elementCodes) : [];