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) => {
const connectionId = event.stream?.connection?.connectionId;
const data = event.stream?.connection?.data;
const isCameraType: boolean = this.participantService.getTypeConnectionData(data) === VideoType.CAMERA;
const isRemoteConnection: boolean = !this.openviduService.isMyOwnConnection(connectionId);
if (isRemoteConnection) {
const subscriber: Subscriber = this.session.subscribe(event.stream, undefined);
this.participantService.addRemoteConnection(connectionId, data, subscriber);
// 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
try {
await this.session.subscribeToSpeechToText(event.stream, this.captionService.getLangSelected().ISO);
@ -331,12 +332,18 @@ export class SessionComponent implements OnInit, OnDestroy {
private subscribeToStreamDestroyed() {
this.session.on('streamDestroyed', async (event: StreamEvent) => {
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);
if(this.captionService.areCaptionsEnabled()){
try {
await this.session.unsubscribeFromSpeechToText(event.stream);
} catch (error) {
this.log.e('Error unsubscribing from STT: ', error);
if (isRemoteConnection) {
if (this.captionService.areCaptionsEnabled() && isCameraType) {
try {
await this.session.unsubscribeFromSpeechToText(event.stream);
} catch (error) {
this.log.e('Error unsubscribing from STT: ', error);
}
}
}
});