Skip to content

Commit 9a4358a

Browse files
authored
Fix bug where adapter captions event is not firing (#5065)
* fix bug * Change files * fix build
1 parent 41bed59 commit 9a4358a

3 files changed

Lines changed: 61 additions & 50 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "patch",
3+
"area": "fix",
4+
"workstream": "captions",
5+
"comment": "Fix bug when adapter caption events are not firing",
6+
"packageName": "@azure/communication-react",
7+
"email": "96077406+carocao-msft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "patch",
3+
"area": "fix",
4+
"workstream": "captions",
5+
"comment": "Fix bug when adapter caption events are not firing",
6+
"packageName": "@azure/communication-react",
7+
"email": "96077406+carocao-msft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}

packages/react-composites/src/composites/CallComposite/adapter/AzureCommunicationCallAdapter.ts

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,55 +1130,52 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
11301130
}
11311131

11321132
private subscribeToCaptionEvents(): void {
1133-
if (this.call && this.call.state === 'Connected') {
1134-
const captionsFeature = this.call?.feature(Features.Captions);
1135-
if (
1136-
captionsFeature.captions.kind === 'TeamsCaptions' &&
1137-
(this.context.getState().isTeamsCall || this.context.getState().isTeamsMeeting)
1138-
) {
1139-
const teamsCaptionsFeature = captionsFeature.captions as TeamsCaptions;
1140-
teamsCaptionsFeature.on('CaptionsReceived', this.teamsCaptionsReceived.bind(this));
1141-
teamsCaptionsFeature.on('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1142-
teamsCaptionsFeature.on('CaptionLanguageChanged', this.isCaptionLanguageChanged.bind(this));
1143-
teamsCaptionsFeature.on('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1144-
} else {
1145-
/* @conditional-compile-remove(acs-close-captions) */
1146-
const acsCaptionsFeature = captionsFeature.captions as Captions;
1147-
/* @conditional-compile-remove(acs-close-captions) */
1148-
acsCaptionsFeature.on('CaptionsReceived', this.captionsReceived.bind(this));
1149-
/* @conditional-compile-remove(acs-close-captions) */
1150-
acsCaptionsFeature.on('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1151-
/* @conditional-compile-remove(acs-close-captions) */
1152-
acsCaptionsFeature.on('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1153-
/* @conditional-compile-remove(acs-close-captions) */
1154-
captionsFeature.on('CaptionsKindChanged', this.captionsKindChanged.bind(this));
1155-
}
1133+
const captionsFeature = this.call?.feature(Features.Captions);
1134+
if (
1135+
captionsFeature?.captions.kind === 'TeamsCaptions' &&
1136+
(this.context.getState().isTeamsCall || this.context.getState().isTeamsMeeting)
1137+
) {
1138+
const teamsCaptionsFeature = captionsFeature.captions as TeamsCaptions;
1139+
teamsCaptionsFeature.on('CaptionsReceived', this.teamsCaptionsReceived.bind(this));
1140+
teamsCaptionsFeature.on('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1141+
teamsCaptionsFeature.on('CaptionLanguageChanged', this.isCaptionLanguageChanged.bind(this));
1142+
teamsCaptionsFeature.on('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1143+
} else {
1144+
/* @conditional-compile-remove(acs-close-captions) */
1145+
const acsCaptionsFeature = captionsFeature?.captions as Captions;
1146+
/* @conditional-compile-remove(acs-close-captions) */
1147+
acsCaptionsFeature.on('CaptionsReceived', this.captionsReceived.bind(this));
1148+
/* @conditional-compile-remove(acs-close-captions) */
1149+
acsCaptionsFeature.on('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1150+
/* @conditional-compile-remove(acs-close-captions) */
1151+
acsCaptionsFeature.on('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1152+
/* @conditional-compile-remove(acs-close-captions) */
1153+
captionsFeature?.on('CaptionsKindChanged', this.captionsKindChanged.bind(this));
11561154
}
11571155
}
11581156

11591157
private unsubscribeFromCaptionEvents(): void {
1160-
if (this.call && this.call.state === 'Connected') {
1161-
const captionsFeature = this.call?.feature(Features.Captions);
1162-
if (
1163-
captionsFeature.captions.kind === 'TeamsCaptions' &&
1164-
(this.context.getState().isTeamsCall || this.context.getState().isTeamsMeeting)
1165-
) {
1166-
const teamsCaptionsFeature = captionsFeature.captions as TeamsCaptions;
1167-
teamsCaptionsFeature.off('CaptionsReceived', this.teamsCaptionsReceived.bind(this));
1168-
teamsCaptionsFeature.off('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1169-
teamsCaptionsFeature.off('CaptionLanguageChanged', this.isCaptionLanguageChanged.bind(this));
1170-
teamsCaptionsFeature.off('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1171-
} else {
1172-
/* @conditional-compile-remove(acs-close-captions) */
1173-
const acsCaptionsFeature = captionsFeature.captions as Captions;
1174-
/* @conditional-compile-remove(acs-close-captions) */
1175-
acsCaptionsFeature.off('CaptionsReceived', this.captionsReceived.bind(this));
1176-
/* @conditional-compile-remove(acs-close-captions) */
1177-
acsCaptionsFeature.off('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1178-
/* @conditional-compile-remove(acs-close-captions) */
1179-
acsCaptionsFeature.off('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1180-
}
1181-
this.call?.off('stateChanged', this.subscribeToCaptionEvents.bind(this));
1158+
const captionsFeature = this.call?.feature(Features.Captions);
1159+
if (
1160+
captionsFeature?.captions.kind === 'TeamsCaptions' &&
1161+
(this.context.getState().isTeamsCall || this.context.getState().isTeamsMeeting)
1162+
) {
1163+
const teamsCaptionsFeature = captionsFeature.captions as TeamsCaptions;
1164+
teamsCaptionsFeature.off('CaptionsReceived', this.teamsCaptionsReceived.bind(this));
1165+
teamsCaptionsFeature.off('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1166+
teamsCaptionsFeature.off('CaptionLanguageChanged', this.isCaptionLanguageChanged.bind(this));
1167+
teamsCaptionsFeature.off('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1168+
} else {
1169+
/* @conditional-compile-remove(acs-close-captions) */
1170+
const acsCaptionsFeature = captionsFeature?.captions as Captions;
1171+
/* @conditional-compile-remove(acs-close-captions) */
1172+
acsCaptionsFeature.off('CaptionsReceived', this.captionsReceived.bind(this));
1173+
/* @conditional-compile-remove(acs-close-captions) */
1174+
acsCaptionsFeature.off('CaptionsActiveChanged', this.isCaptionsActiveChanged.bind(this));
1175+
/* @conditional-compile-remove(acs-close-captions) */
1176+
acsCaptionsFeature.off('SpokenLanguageChanged', this.isSpokenLanguageChanged.bind(this));
1177+
/* @conditional-compile-remove(acs-close-captions) */
1178+
captionsFeature?.off('CaptionsKindChanged', this.captionsKindChanged.bind(this));
11821179
}
11831180
}
11841181

@@ -1194,9 +1191,9 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
11941191
this.call?.on('isMutedChanged', this.isMyMutedChanged.bind(this));
11951192
this.call?.on('isScreenSharingOnChanged', this.isScreenSharingOnChanged.bind(this));
11961193
this.call?.on('idChanged', this.callIdChanged.bind(this));
1197-
this.call?.on('stateChanged', this.subscribeToCaptionEvents.bind(this));
11981194
this.call?.on('roleChanged', this.roleChanged.bind(this));
11991195

1196+
this.subscribeToCaptionEvents();
12001197
this.call?.feature(Features.Transfer).on('transferAccepted', this.transferAccepted.bind(this));
12011198
this.call?.feature(Features.Capabilities).on('capabilitiesChanged', this.capabilitiesChanged.bind(this));
12021199
this.call?.feature(Features.Spotlight).on('spotlightChanged', this.spotlightChanged.bind(this));
@@ -1218,10 +1215,6 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
12181215
this.call?.off('isScreenSharingOnChanged', this.isScreenSharingOnChanged.bind(this));
12191216
this.call?.off('idChanged', this.callIdChanged.bind(this));
12201217
this.call?.off('roleChanged', this.roleChanged.bind(this));
1221-
/* @conditional-compile-remove(acs-close-captions) */
1222-
if (this.call?.feature(Features.Captions).captions.kind === 'Captions') {
1223-
this.call?.feature(Features.Captions).off('CaptionsKindChanged', this.unsubscribeFromCaptionEvents.bind(this));
1224-
}
12251218

12261219
this.unsubscribeFromCaptionEvents();
12271220
if (this.callingSoundSubscriber) {

0 commit comments

Comments
 (0)