Skip to content

Commit 5349177

Browse files
committed
openvidu-components: Updated captionsLangOptions api
Replaced ISO attribute by lang with the aim of matching the openvidu-browser api
1 parent 316b145 commit 5349177

File tree

10 files changed

+56
-55
lines changed

10 files changed

+56
-55
lines changed

openvidu-components-angular/e2e/webcomponent-app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async function joinSession(sessionName, participantName) {
180180
webComponent.lang = LANG;
181181
webComponent.captionsLang = CAPTIONS_LANG;
182182
if (CUSTOM_CAPTIONS_LANG_OPTIONS) {
183-
webComponent.captionsLangOptions = [{ name: 'Esp', ISO: 'es-ES' }, { name: 'Eng', ISO: 'en-US' }];
183+
webComponent.captionsLangOptions = [{ name: 'Esp', lang: 'es-ES' }, { name: 'Eng', lang: 'en-US' }];
184184
}
185185
webComponent.prejoin = PREJOIN;
186186
webComponent.videoMuted = VIDEO_MUTED;

openvidu-components-angular/e2e/webcomponent.pro.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('Testing captions features', () => {
296296
expect(await utils.isPresent('.captions-container')).to.be.true;
297297
});
298298

299-
it('should change the CAPTIONS language', async () => {
299+
it('should change the CAPTIONS language from settings panel', async () => {
300300
await browser.get(`${url}&prejoin=false`);
301301

302302
await utils.checkSessionIsPresent();

openvidu-components-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"webcomponent:e2e-ci": "cross-env LAUNCH_MODE=CI npm run webcomponent:e2e",
7676
"webcomponent:e2e-pro": "tsc --project ./e2e && npx mocha --recursive --timeout 30000 ./e2e/dist/webcomponent.pro.test.js",
7777
"webcomponent:e2e-pro-ci": "cross-env LAUNCH_MODE=CI npm run webcomponent:e2e-pro",
78-
"webcomponent:serve-testapp": "npx http-server ./e2e/webcomponent-app/"
78+
"webcomponent:serve-testapp": "npx http-server ./e2e/webcomponent-app/ && echo http://localhost:8080/?OV_URL=https://localhost:4443&OV_SECRET=MY_SECRET&prejoin=false"
7979
},
8080
"version": "2.24.0"
8181
}

openvidu-components-angular/projects/openvidu-angular/src/lib/components/captions/captions.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PanelEvent, PanelService } from '../../services/panel/panel.service';
44

55
import { animate, style, transition, trigger } from '@angular/animations';
66
import { Session, SpeechToTextEvent } from 'openvidu-browser';
7-
import { CaptionModel } from '../../models/caption.model';
7+
import { CaptionModel, CaptionsLangOption } from '../../models/caption.model';
88
import { PanelSettingsOptions, PanelType } from '../../models/panel.model';
99
import { CaptionService } from '../../services/caption/caption.service';
1010
import { OpenViduService } from '../../services/openvidu/openvidu.service';
@@ -50,7 +50,7 @@ export class CaptionsComponent implements OnInit {
5050
private DELETE_TIMEOUT = 10 * 1000;
5151
private MAX_EVENTS_LIMIT = 3;
5252
private captionLanguageSubscription: Subscription;
53-
private captionLangSelected: { name: string; ISO: string };
53+
private captionLangSelected: CaptionsLangOption;
5454
private screenSizeSub: Subscription;
5555
private panelTogglingSubscription: Subscription;
5656
private sttStatusSubscription: Subscription;
@@ -70,7 +70,7 @@ export class CaptionsComponent implements OnInit {
7070
this.captionLangSelected = this.captionService.getLangSelected();
7171
this.session = this.openviduService.getWebcamSession();
7272

73-
await this.openviduService.subscribeRemotesToSTT(this.captionLangSelected.ISO);
73+
await this.openviduService.subscribeRemotesToSTT(this.captionLangSelected.lang);
7474

7575
this.subscribeToCaptionLanguage();
7676
this.subscribeToPanelToggling();
@@ -196,8 +196,8 @@ export class CaptionsComponent implements OnInit {
196196
}
197197

198198
private subscribeToCaptionLanguage() {
199-
this.captionLanguageSubscription = this.captionService.captionLangObs.subscribe((lang) => {
200-
this.captionLangSelected = lang;
199+
this.captionLanguageSubscription = this.captionService.captionLangObs.subscribe((langOpt) => {
200+
this.captionLangSelected = langOpt;
201201
this.cd.markForCheck();
202202
});
203203
}

openvidu-components-angular/projects/openvidu-angular/src/lib/components/session/session.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export class SessionComponent implements OnInit, OnDestroy {
282282
this.log.w(event.name, event.message);
283283
this.openviduService.setSTTReady(false);
284284
// Try to re-subscribe to STT
285-
await this.openviduService.subscribeRemotesToSTT(this.captionService.getLangSelected().ISO);
285+
await this.openviduService.subscribeRemotesToSTT(this.captionService.getLangSelected().lang);
286286
} else {
287287
this.log.e(event.name, event.message);
288288
}
@@ -326,7 +326,7 @@ export class SessionComponent implements OnInit, OnDestroy {
326326
const data = event.stream?.connection?.data;
327327
const isCameraType: boolean = this.participantService.getTypeConnectionData(data) === VideoType.CAMERA;
328328
const isRemoteConnection: boolean = !this.openviduService.isMyOwnConnection(connectionId);
329-
const lang = this.captionService.getLangSelected().ISO;
329+
const lang = this.captionService.getLangSelected().lang;
330330

331331
if (isRemoteConnection) {
332332
const subscriber: Subscriber = this.session.subscribe(event.stream, undefined);
@@ -368,12 +368,12 @@ export class SessionComponent implements OnInit, OnDestroy {
368368
}
369369

370370
private subscribeToCaptionLanguage() {
371-
this.captionLanguageSubscription = this.captionService.captionLangObs.subscribe(async (lang) => {
371+
this.captionLanguageSubscription = this.captionService.captionLangObs.subscribe(async (langOpt) => {
372372
if (this.captionService.areCaptionsEnabled()) {
373373
// Unsubscribe all streams from speech to text and re-subscribe with new language
374-
this.log.d('Re-subscribe from STT because of language changed to ', lang.ISO);
374+
this.log.d('Re-subscribe from STT because of language changed to ', langOpt.lang);
375375
await this.openviduService.unsubscribeRemotesFromSTT();
376-
await this.openviduService.subscribeRemotesToSTT(lang.ISO);
376+
await this.openviduService.subscribeRemotesToSTT(langOpt.lang);
377377
}
378378
});
379379
}

openvidu-components-angular/projects/openvidu-angular/src/lib/components/settings/captions/captions.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<mat-icon>expand_more</mat-icon>
2121
</button>
2222
<mat-menu #menu="matMenu">
23-
<button *ngFor="let lang of languagesAvailable" mat-menu-item [id]="lang.ISO" (click)="onLangSelected(lang)">
24-
<span>{{ lang.name }}</span>
23+
<button *ngFor="let langOpt of languagesAvailable" mat-menu-item [id]="langOpt.lang" (click)="onLangSelected(langOpt)">
24+
<span>{{ langOpt.name }}</span>
2525
</button>
2626
</mat-menu>
2727
</mat-list-item>

openvidu-components-angular/projects/openvidu-angular/src/lib/components/settings/captions/captions.component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, OnDestroy, OnInit } from '@angular/core';
22
import { Subscription } from 'rxjs';
3+
import { CaptionsLangOption } from '../../../models/caption.model';
34
import { CaptionService } from '../../../services/caption/caption.service';
45
import { LayoutService } from '../../../services/layout/layout.service';
56
import { OpenViduService } from '../../../services/openvidu/openvidu.service';
@@ -15,7 +16,7 @@ import { OpenViduService } from '../../../services/openvidu/openvidu.service';
1516
export class CaptionsSettingComponent implements OnInit, OnDestroy {
1617
isSttReady: boolean = true;
1718
captionsEnabled: boolean;
18-
languagesAvailable: { name: string; ISO: string }[] = [];
19+
languagesAvailable: CaptionsLangOption[] = [];
1920
langSelected: string;
2021
isOpenViduPro: boolean = false;
2122
private captionsStatusSubs: Subscription;
@@ -39,9 +40,9 @@ export class CaptionsSettingComponent implements OnInit, OnDestroy {
3940
if (this.sttStatusSubs) this.sttStatusSubs.unsubscribe();
4041
}
4142

42-
onLangSelected(lang: { name: string; ISO: string }) {
43-
this.langSelected = lang.name;
44-
this.captionService.setLanguage(lang.ISO);
43+
onLangSelected(langOpt: CaptionsLangOption) {
44+
this.langSelected = langOpt.name;
45+
this.captionService.setLanguage(langOpt.lang);
4546
}
4647

4748
toggleCaptions() {

openvidu-components-angular/projects/openvidu-angular/src/lib/directives/api/videoconference.directive.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ export class CaptionsLangDirective implements OnDestroy {
188188
*
189189
* Default: ```
190190
* [
191-
* { name: 'English', ISO: 'en-US' },
192-
* { name: 'Español', ISO: 'es-ES' },
193-
* { name: 'Deutsch', ISO: 'de-DE' },
194-
* { name: 'Français', ISO: 'fr-FR' },
195-
* { name: '中国', ISO: 'zh-CN' },
196-
* { name: 'हिन्दी', ISO: 'hi-IN' },
197-
* { name: 'Italiano', ISO: 'it-IT' },
198-
* { name: 'やまと', ISO: 'jp-JP' },
199-
* { name: 'Português', ISO: 'pt-PT' }
191+
* { name: 'English', lang: 'en-US' },
192+
* { name: 'Español', lang: 'es-ES' },
193+
* { name: 'Deutsch', lang: 'de-DE' },
194+
* { name: 'Français', lang: 'fr-FR' },
195+
* { name: '中国', lang: 'zh-CN' },
196+
* { name: 'हिन्दी', lang: 'hi-IN' },
197+
* { name: 'Italiano', lang: 'it-IT' },
198+
* { name: 'やまと', lang: 'jp-JP' },
199+
* { name: 'Português', lang: 'pt-PT' }
200200
* ]```
201201
*
202202
* @example
203-
* <ov-videoconference [captionsLangOptions]="[{name:'Spanish', ISO: 'es-ES'}]"></ov-videoconference>
203+
* <ov-videoconference [captionsLangOptions]="[{name:'Spanish', lang: 'es-ES'}]"></ov-videoconference>
204204
*/
205205
@Directive({
206206
selector: 'ov-videoconference[captionsLangOptions]'

openvidu-components-angular/projects/openvidu-angular/src/lib/models/caption.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface CaptionModel {
1414
export interface CaptionsLangOption {
1515

1616
name: string;
17-
ISO: string;
17+
lang: string;
1818

1919
}
2020

openvidu-components-angular/projects/openvidu-angular/src/lib/services/caption/caption.service.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import { StorageService } from '../storage/storage.service';
1010
providedIn: 'root'
1111
})
1212
export class CaptionService {
13-
private langs: CaptionsLangOption [] = [
14-
{ name: 'English', ISO: 'en-US' },
15-
{ name: 'Español', ISO: 'es-ES' },
16-
{ name: 'Deutsch', ISO: 'de-DE' },
17-
{ name: 'Français', ISO: 'fr-FR' },
18-
{ name: '中国', ISO: 'zh-CN' },
19-
{ name: 'हिन्दी', ISO: 'hi-IN' },
20-
{ name: 'Italiano', ISO: 'it-IT' },
21-
{ name: 'やまと', ISO: 'jp-JP' },
22-
{ name: 'Português', ISO: 'pt-PT' }
13+
private langsOptions: CaptionsLangOption [] = [
14+
{ name: 'English', lang: 'en-US' },
15+
{ name: 'Español', lang: 'es-ES' },
16+
{ name: 'Deutsch', lang: 'de-DE' },
17+
{ name: 'Français', lang: 'fr-FR' },
18+
{ name: '中国', lang: 'zh-CN' },
19+
{ name: 'हिन्दी', lang: 'hi-IN' },
20+
{ name: 'Italiano', lang: 'it-IT' },
21+
{ name: 'やまと', lang: 'jp-JP' },
22+
{ name: 'Português', lang: 'pt-PT' }
2323
];
24-
captionLangSelected: { name: string; ISO: string };
25-
captionLangObs: Observable<{ name: string; ISO: string }>;
26-
private _captionLang: Subject<{ name: string; ISO: string }> = new Subject();
24+
captionLangSelected: CaptionsLangOption;
25+
captionLangObs: Observable<CaptionsLangOption>;
26+
private _captionLang: Subject<CaptionsLangOption> = new Subject();
2727
private captionsEnabled: boolean = false;
2828

2929
constructor(private storageService: StorageService) {
@@ -34,7 +34,7 @@ export class CaptionService {
3434

3535
setLanguageOptions(options: CaptionsLangOption [] | undefined) {
3636
if(options && options.length > 0) {
37-
this.langs = options;
37+
this.langsOptions = options;
3838
this.updateLangSelected();
3939
}
4040
}
@@ -48,29 +48,29 @@ export class CaptionService {
4848
}
4949

5050
setLanguage(lang: string) {
51-
const newLang = this.langs.find((l) => l.ISO === lang);
52-
if (!!newLang && newLang.ISO !== this.captionLangSelected.ISO) {
53-
this.captionLangSelected = newLang;
51+
const newLangOpt = this.langsOptions.find((opt) => opt.lang === lang);
52+
if (!!newLangOpt && newLangOpt.lang !== this.captionLangSelected.lang) {
53+
this.captionLangSelected = newLangOpt;
5454
this.storageService.setCaptionLang(lang);
5555
this._captionLang.next(this.captionLangSelected);
5656
}
5757
}
5858

59-
getLangSelected(): { name: string; ISO: string } {
59+
getLangSelected(): CaptionsLangOption {
6060
return this.captionLangSelected;
6161
}
6262

63-
getCaptionLanguages(): { name: string; ISO: string }[] {
64-
return this.langs;
63+
getCaptionLanguages(): CaptionsLangOption[] {
64+
return this.langsOptions;
6565
}
6666

6767
private updateLangSelected(): void {
68-
const iso = this.storageService.getCaptionsLang();
69-
const lang = this.langs.find((lang) => lang.ISO === iso);
70-
if (iso && lang) {
71-
this.captionLangSelected = lang;
68+
const storageLang = this.storageService.getCaptionsLang();
69+
const langOpt = this.langsOptions.find((opt) => opt.lang === storageLang);
70+
if (storageLang && langOpt) {
71+
this.captionLangSelected = langOpt;
7272
} else {
73-
this.captionLangSelected = this.langs[0];
73+
this.captionLangSelected = this.langsOptions[0];
7474
}
7575
}
7676
}

0 commit comments

Comments
 (0)