openvidu-components: Improved STT unsubscription

Unsubscribed from STT only for remote streams and camera types
pull/759/head
Carlos Santos 2022-11-09 14:03:24 +01:00
parent 2fa5d05c2b
commit 4cd7369ff6
1 changed files with 14 additions and 7 deletions

View File

@ -309,14 +309,15 @@ export class SessionComponent implements OnInit, OnDestroy {
this.session.on('streamCreated', async (event: StreamEvent) => { this.session.on('streamCreated', async (event: StreamEvent) => {
const connectionId = event.stream?.connection?.connectionId; const connectionId = event.stream?.connection?.connectionId;
const data = event.stream?.connection?.data; const data = event.stream?.connection?.data;
const isCameraType: boolean = this.participantService.getTypeConnectionData(data) === VideoType.CAMERA;
const isRemoteConnection: boolean = !this.openviduService.isMyOwnConnection(connectionId); const isRemoteConnection: boolean = !this.openviduService.isMyOwnConnection(connectionId);
if (isRemoteConnection) { if (isRemoteConnection) {
const subscriber: Subscriber = this.session.subscribe(event.stream, undefined); const subscriber: Subscriber = this.session.subscribe(event.stream, undefined);
this.participantService.addRemoteConnection(connectionId, data, subscriber); this.participantService.addRemoteConnection(connectionId, data, subscriber);
// this.oVSessionService.sendNicknameSignal(event.stream.connection); // this.oVSessionService.sendNicknameSignal(event.stream.connection);
if (this.captionService.areCaptionsEnabled() && this.participantService.getTypeConnectionData(data) === VideoType.CAMERA) { if (this.captionService.areCaptionsEnabled() && isCameraType) {
// Only subscribe to STT when stream is CAMERA type and it is a remote stream // Only subscribe to STT when stream is CAMERA type and it is a remote stream
try { try {
await this.session.subscribeToSpeechToText(event.stream, this.captionService.getLangSelected().ISO); await this.session.subscribeToSpeechToText(event.stream, this.captionService.getLangSelected().ISO);
@ -331,14 +332,20 @@ export class SessionComponent implements OnInit, OnDestroy {
private subscribeToStreamDestroyed() { private subscribeToStreamDestroyed() {
this.session.on('streamDestroyed', async (event: StreamEvent) => { this.session.on('streamDestroyed', async (event: StreamEvent) => {
const connectionId = event.stream.connection.connectionId; const connectionId = event.stream.connection.connectionId;
const data = event.stream?.connection?.data;
const isRemoteConnection: boolean = !this.openviduService.isMyOwnConnection(connectionId);
const isCameraType: boolean = this.participantService.getTypeConnectionData(data) === VideoType.CAMERA;
this.participantService.removeConnectionByConnectionId(connectionId); this.participantService.removeConnectionByConnectionId(connectionId);
if(this.captionService.areCaptionsEnabled()){ if (isRemoteConnection) {
if (this.captionService.areCaptionsEnabled() && isCameraType) {
try { try {
await this.session.unsubscribeFromSpeechToText(event.stream); await this.session.unsubscribeFromSpeechToText(event.stream);
} catch (error) { } catch (error) {
this.log.e('Error unsubscribing from STT: ', error); this.log.e('Error unsubscribing from STT: ', error);
} }
} }
}
}); });
} }