openvidu-components: Fixed bug with captions lang initialization

pull/759/head
Carlos Santos 2022-11-09 13:31:40 +01:00
parent 4be4b9695b
commit 2fa5d05c2b
1 changed files with 11 additions and 9 deletions

View File

@ -9,8 +9,7 @@ import { StorageService } from '../storage/storage.service';
providedIn: 'root' providedIn: 'root'
}) })
export class CaptionService { export class CaptionService {
private langs = [
private langTitles = [
{ name: 'English', ISO: 'en-US' }, { name: 'English', ISO: 'en-US' },
{ name: 'Español', ISO: 'es-ES' }, { name: 'Español', ISO: 'es-ES' },
{ name: 'Deutsch', ISO: 'de-DE' }, { name: 'Deutsch', ISO: 'de-DE' },
@ -21,15 +20,18 @@ export class CaptionService {
{ name: 'やまと', ISO: 'jp-JP' }, { name: 'やまと', ISO: 'jp-JP' },
{ name: 'Português', ISO: 'pt-PT' } { name: 'Português', ISO: 'pt-PT' }
]; ];
captionLangSelected: { name: string; ISO: string }; captionLangSelected: { name: string; ISO: string } = { name: 'English', ISO: 'en-US' };
captionLangObs: Observable<{ name: string; ISO: string }>; captionLangObs: Observable<{ name: string; ISO: string }>;
private _captionLangObs: Subject<{ name: string; ISO: string }> = new Subject(); private _captionLangObs: Subject<{ name: string; ISO: string }> = new Subject();
private captionsEnabled: boolean = false; private captionsEnabled: boolean = false;
constructor(private storageService: StorageService) { constructor(private storageService: StorageService) {
const iso = this.storageService.getCaptionsLang(); const iso = this.storageService.getCaptionsLang();
if (iso) { const lang = this.langs.find((lang) => lang.ISO === iso);
this.captionLangSelected = this.langTitles.find((lang) => lang.ISO === iso) || this.langTitles[0]; if (iso && lang) {
this.captionLangSelected = lang;
} else {
this.captionLangSelected = this.langs[0];
} }
this.captionLangObs = this._captionLangObs.asObservable(); this.captionLangObs = this._captionLangObs.asObservable();
} }
@ -43,7 +45,7 @@ export class CaptionService {
} }
setLanguage(lang: string) { setLanguage(lang: string) {
const newLang = this.langTitles.find((l) => l.ISO === lang); const newLang = this.langs.find((l) => l.ISO === lang);
if (!!newLang && newLang.ISO !== this.captionLangSelected.ISO) { if (!!newLang && newLang.ISO !== this.captionLangSelected.ISO) {
this.captionLangSelected = newLang; this.captionLangSelected = newLang;
this.storageService.setCaptionLang(lang); this.storageService.setCaptionLang(lang);
@ -52,10 +54,10 @@ export class CaptionService {
} }
getLangSelected(): { name: string; ISO: string } { getLangSelected(): { name: string; ISO: string } {
return this.captionLangSelected || this.langTitles[0]; return this.captionLangSelected;
} }
getCaptionLanguages(): { name: string; ISO: string }[] { getCaptionLanguages(): { name: string; ISO: string }[] {
return this.langTitles; return this.langs;
} }
} }