From 92cf811921f16f6ee08094778a094e0c9e007505 Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 1 Dec 2020 18:31:54 +0100 Subject: [PATCH] Avoid stream/jitsi cases without information Rewrites the jitsi/stream state management. After every reload and after a stream becomes available (while not currently in a jitsi conference) you will switch to live stream, if available --- .../components/jitsi/jitsi.component.html | 3 +- .../components/jitsi/jitsi.component.ts | 68 +++++++------------ 2 files changed, 27 insertions(+), 44 deletions(-) diff --git a/client/src/app/shared/components/jitsi/jitsi.component.html b/client/src/app/shared/components/jitsi/jitsi.component.html index 175d9a547..411dea375 100644 --- a/client/src/app/shared/components/jitsi/jitsi.component.html +++ b/client/src/app/shared/components/jitsi/jitsi.component.html @@ -200,8 +200,7 @@ *ngIf="(canSeeLiveStream && !streamActiveInAnotherTab) || streamRunning" >
- {{ 'The livestream is already running in your OpenSlides session.' | translate }} -
diff --git a/client/src/app/shared/components/jitsi/jitsi.component.ts b/client/src/app/shared/components/jitsi/jitsi.component.ts index 08cab2f7a..0de9c2efd 100644 --- a/client/src/app/shared/components/jitsi/jitsi.component.ts +++ b/client/src/app/shared/components/jitsi/jitsi.component.ts @@ -81,8 +81,6 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit public enableJitsi: boolean; private autoconnect: boolean; - private startWithMicMuted: boolean; - private startWithVideoMuted: boolean; private roomName: string; private roomPassword: string; private jitsiDomain: string; @@ -95,7 +93,7 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit private isPasswortSet = false; public isJitsiDialogOpen = false; - public showJitsiWindow = false; + public showJitsiWindow = true; public muted = true; @ViewChild('jitsi') @@ -123,7 +121,6 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit private RTC_LOGGED_STORAGE_KEY = 'rtcIsLoggedIn'; private STREAM_RUNNING_STORAGE_KEY = 'streamIsRunning'; - private CONFERENCE_STATE_STORAGE_KEY = 'conferenceState'; // JitsiID to ConferenceMember public members = {}; @@ -245,8 +242,13 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit super(titleService, translate, snackBar); } - public ngOnInit(): void { - this.setUp(); + public async ngOnInit(): Promise { + await this.setUp(); + if (this.canSeeLiveStream && this.videoStreamUrl) { + this.currentState = ConferenceState.stream; + } else { + this.currentState = ConferenceState.jitsi; + } } public async ngOnDestroy(): Promise { @@ -292,8 +294,6 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit .watch(this.RTC_LOGGED_STORAGE_KEY) .pipe(distinctUntilChanged()) .subscribe((inUse: boolean) => { - console.log('RTC_LOGGED_STORAGE_KEY is in use: ', inUse); - this.isJitsiActiveInAnotherTab = inUse; this.lockLoaded.resolve(); if (!inUse && !this.isJitsiActive) { @@ -342,41 +342,20 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit this.nextSpeakerAmount = nextSpeakerAmount; }), this.configService.get('general_system_stream_url').subscribe(url => { - this.videoStreamUrl = url; + this.onLiveStreamAvailable(url); this.configsLoaded.resolve(); }), this.configService.get('general_system_conference_open_microphone').subscribe(open => { - this.startWithMicMuted = !open; - this.configOverwrite.startWithAudioMuted = this.startWithMicMuted; - console.log('this.startWithMicMuted ', this.startWithMicMuted); + this.configOverwrite.startWithAudioMuted = !open; }), this.configService.get('general_system_conference_open_video').subscribe(open => { - this.startWithVideoMuted = !open; - this.configOverwrite.startWithVideoMuted = this.startWithVideoMuted; - console.log('this.startWithVideoMuted ', this.startWithVideoMuted); + this.configOverwrite.startWithVideoMuted = !open; }) ); await this.configsLoaded; this.subscriptions.push( - this.storageMap.watch(this.CONFERENCE_STATE_STORAGE_KEY).subscribe((confState: ConferenceState) => { - if (confState in ConferenceState) { - if (this.enableJitsi && (!this.videoStreamUrl || !this.canSeeLiveStream)) { - this.currentState = ConferenceState.jitsi; - } else if (!this.enableJitsi && this.videoStreamUrl && this.canSeeLiveStream) { - this.currentState = ConferenceState.stream; - } else { - this.currentState = confState; - } - } else { - this.setDefaultConfState(); - } - // show stream window when the state changes to stream - if (this.currentState === ConferenceState.stream && !this.streamActiveInAnotherTab) { - this.showJitsiWindow = true; - } - }), // check if the operator is on the clos, remove from room if not permitted this.closService.currentListOfSpeakersObservable .pipe( @@ -582,9 +561,10 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit this.showJitsiWindow = false; } - public async viewStream(): Promise { + public viewStream(): void { this.stopJitsi(); this.setConferenceState(ConferenceState.stream); + this.showJitsiWindow = true; } public onSteamStarted(): void { @@ -592,6 +572,18 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit this.storageMap.set(this.STREAM_RUNNING_STORAGE_KEY, true).subscribe(() => {}); } + private onLiveStreamAvailable(liveStreamUrl: string): void { + this.videoStreamUrl = liveStreamUrl; + // this is the "dead" state; you would see the jitsi state; but are not connected + // or the connection is prohibited. If this occurs and a live stream + // becomes available, switch to the stream state + if (this.videoStreamUrl && this.currentState === ConferenceState.jitsi && !this.isJitsiActive) { + this.viewStream(); + } else if (!this.videoStreamUrl && this.enableJitsi) { + this.setConferenceState(ConferenceState.jitsi); + } + } + private async deleteJitsiLock(): Promise { await this.storageMap.delete(this.RTC_LOGGED_STORAGE_KEY).toPromise(); } @@ -600,15 +592,7 @@ export class JitsiComponent extends BaseViewComponentDirective implements OnInit await this.storageMap.delete(this.STREAM_RUNNING_STORAGE_KEY).toPromise(); } - private setDefaultConfState(): void { - this.videoStreamUrl && this.canSeeLiveStream - ? this.setConferenceState(ConferenceState.stream) - : this.setConferenceState(ConferenceState.jitsi); - } - private setConferenceState(newState: ConferenceState): void { - if (this.currentState !== newState) { - this.storageMap.set(this.CONFERENCE_STATE_STORAGE_KEY, newState).subscribe(() => {}); - } + this.currentState = newState; } }