Skip to content

Commit 1911608

Browse files
authored
Capabilities change handler (#3485)
* Added CapabilitiesChangedListener to CallAdapter * Change files * Duplicate change files for beta release * conditional compile fix * Fix condition to turn of camera in capabilitiesChanged handler * fix conditional compilation 2 * mute and stop screenshare when capabilities are lost
1 parent 691d291 commit 1911608

8 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "prerelease",
3+
"area": "feature",
4+
"workstream": "Capabilities",
5+
"comment": "Added CapabilitiesChangedListener to CallAdapter",
6+
"packageName": "@azure/communication-react",
7+
"email": "79475487+mgamis-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": "prerelease",
3+
"area": "feature",
4+
"workstream": "Capabilities",
5+
"comment": "Added CapabilitiesChangedListener to CallAdapter",
6+
"packageName": "@azure/communication-react",
7+
"email": "79475487+mgamis-msft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}

packages/communication-react/review/beta/communication-react.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CallEndReason } from '@azure/communication-calling';
1919
import { CallerInfo } from '@azure/communication-calling';
2020
import { CallKind } from '@azure/communication-calling';
2121
import { CallState as CallState_2 } from '@azure/communication-calling';
22+
import type { CapabilitiesChangeInfo } from '@azure/communication-calling';
2223
import { CaptionsResultType } from '@azure/communication-calling';
2324
import { ChatClient } from '@azure/communication-chat';
2425
import { ChatClientOptions } from '@azure/communication-chat';
@@ -426,6 +427,7 @@ export interface CallAdapterSubscribers {
426427
off(event: 'captionsReceived', listener: CaptionsReceivedListener): void;
427428
off(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
428429
off(event: 'transferRequested', listener: TransferRequestedListener): void;
430+
off(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
429431
on(event: 'participantsJoined', listener: ParticipantsJoinedListener): void;
430432
on(event: 'participantsLeft', listener: ParticipantsLeftListener): void;
431433
on(event: 'isMutedChanged', listener: IsMutedChangedListener): void;
@@ -441,6 +443,7 @@ export interface CallAdapterSubscribers {
441443
on(event: 'captionsReceived', listener: CaptionsReceivedListener): void;
442444
on(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
443445
on(event: 'transferRequested', listener: TransferRequestedListener): void;
446+
on(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
444447
}
445448

446449
// @public
@@ -1303,6 +1306,9 @@ export interface CapabilitiesCallFeature {
13031306
capabilities: ParticipantCapabilities;
13041307
}
13051308

1309+
// @beta
1310+
export type CapabilitiesChangedListener = (data: CapabilitiesChangeInfo) => void;
1311+
13061312
// @beta
13071313
export interface CaptionsAvailableLanguageStrings {
13081314
// (undocumented)

packages/react-composites/review/beta/react-composites.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { BaseCustomStyles } from '@internal/react-components';
1313
import { Call } from '@azure/communication-calling';
1414
import { CallAgent } from '@azure/communication-calling';
1515
import { CallState } from '@internal/calling-stateful-client';
16+
import type { CapabilitiesChangeInfo } from '@azure/communication-calling';
1617
import { CaptionsAvailableLanguageStrings } from '@internal/react-components';
1718
import { CaptionsInfo } from '@internal/calling-stateful-client';
1819
import type { ChatMessage } from '@azure/communication-chat';
@@ -277,6 +278,7 @@ export interface CallAdapterSubscribers {
277278
off(event: 'captionsReceived', listener: CaptionsReceivedListener): void;
278279
off(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
279280
off(event: 'transferRequested', listener: TransferRequestedListener): void;
281+
off(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
280282
on(event: 'participantsJoined', listener: ParticipantsJoinedListener): void;
281283
on(event: 'participantsLeft', listener: ParticipantsLeftListener): void;
282284
on(event: 'isMutedChanged', listener: IsMutedChangedListener): void;
@@ -292,6 +294,7 @@ export interface CallAdapterSubscribers {
292294
on(event: 'captionsReceived', listener: CaptionsReceivedListener): void;
293295
on(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
294296
on(event: 'transferRequested', listener: TransferRequestedListener): void;
297+
on(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
295298
}
296299

297300
// @public
@@ -911,6 +914,9 @@ export interface CallWithChatControlOptions extends CommonCallControlOptions {
911914
// @public
912915
export type CallWithChatEvent = 'callError' | 'chatError' | 'callEnded' | 'isMutedChanged' | 'callIdChanged' | 'isLocalScreenSharingActiveChanged' | 'displayNameChanged' | 'isSpeakingChanged' | 'callParticipantsJoined' | 'callParticipantsLeft' | 'selectedMicrophoneChanged' | 'selectedSpeakerChanged' | /* @conditional-compile-remove(close-captions) */ 'isCaptionsActiveChanged' | /* @conditional-compile-remove(close-captions) */ 'captionsReceived' | 'messageReceived' | 'messageSent' | 'messageRead' | 'chatParticipantsAdded' | 'chatParticipantsRemoved';
913916

917+
// @beta
918+
export type CapabilitiesChangedListener = (data: CapabilitiesChangeInfo) => void;
919+
914920
// @beta
915921
export type CaptionsReceivedListener = (event: {
916922
captionsInfo: CaptionsInfo;

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import { AcceptTransferOptions, LocalVideoStream, TransferRequestedEventArgs } f
4343
import { StartCaptionsOptions, TeamsCaptionsInfo } from '@azure/communication-calling';
4444
/* @conditional-compile-remove(video-background-effects) */
4545
import type { BackgroundBlurConfig, BackgroundReplacementConfig } from '@azure/communication-calling';
46+
/* @conditional-compile-remove(capabilities) */
47+
import type { CapabilitiesChangeHandler, CapabilitiesChangeInfo } from '@azure/communication-calling';
4648
/* @conditional-compile-remove(teams-identity-support)) */
4749
import { TeamsCallAgent } from '@azure/communication-calling';
4850
/* @conditional-compile-remove(rooms) */
@@ -70,6 +72,8 @@ import {
7072
} from './CallAdapter';
7173
/* @conditional-compile-remove(call-transfer) */
7274
import { TransferRequestedListener } from './CallAdapter';
75+
/* @conditional-compile-remove(capabilities) */
76+
import { CapabilitiesChangedListener } from './CallAdapter';
7377
/* @conditional-compile-remove(close-captions) */
7478
import { CaptionsReceivedListener, IsCaptionsActiveChangedListener } from './CallAdapter';
7579
/* @conditional-compile-remove(video-background-effects) */
@@ -1007,6 +1011,8 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | BetaTea
10071011
on(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
10081012
/* @conditional-compile-remove(call-transfer) */
10091013
on(event: 'transferRequested', listener: TransferRequestedListener): void;
1014+
/* @conditional-compile-remove(capabilities) */
1015+
on(event: 'capabilitiesChanged', listener: CapabilitiesChangeHandler): void;
10101016

10111017
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10121018
public on(event: string, listener: (e: any) => void): void {
@@ -1041,6 +1047,8 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | BetaTea
10411047
this.call?.on('stateChanged', this.subscribeToCaptionEvents.bind(this));
10421048
/* @conditional-compile-remove(call-transfer) */
10431049
this.call?.feature(Features.Transfer).on('transferRequested', this.transferRequested.bind(this));
1050+
/* @conditional-compile-remove(capabilities) */
1051+
this.call?.feature(Features.Capabilities).on('capabilitiesChanged', this.capabilitiesChanged.bind(this));
10441052
}
10451053

10461054
private unsubscribeCallEvents(): void {
@@ -1129,6 +1137,20 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | BetaTea
11291137
this.emitter.emit('transferRequested', newArgs);
11301138
}
11311139

1140+
/* @conditional-compile-remove(capabilities) */
1141+
private capabilitiesChanged(data: CapabilitiesChangeInfo): void {
1142+
if (data.newValue.turnVideoOn?.isPresent === false) {
1143+
this.stopCamera();
1144+
}
1145+
if (data.newValue.unmuteMic?.isPresent === false) {
1146+
this.mute();
1147+
}
1148+
if (data.newValue.shareScreen?.isPresent === false) {
1149+
this.stopScreenShare();
1150+
}
1151+
this.emitter.emit('capabilitiesChanged', data);
1152+
}
1153+
11321154
private callIdChanged(): void {
11331155
this.call?.id && this.emitter.emit('callIdChanged', { callId: this.call.id });
11341156
}
@@ -1160,6 +1182,8 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | BetaTea
11601182
off(event: 'isCaptionsActiveChanged', listener: IsCaptionsActiveChangedListener): void;
11611183
/* @conditional-compile-remove(call-transfer) */
11621184
off(event: 'transferRequested', listener: TransferRequestedListener): void;
1185+
/* @conditional-compile-remove(capabilities) */
1186+
off(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
11631187

11641188
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11651189
public off(event: string, listener: (e: any) => void): void {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { CallState, DeviceManagerState } from '@internal/calling-stateful-client
66
import { CaptionsInfo } from '@internal/calling-stateful-client';
77
/* @conditional-compile-remove(video-background-effects) */
88
import type { BackgroundBlurConfig, BackgroundReplacementConfig } from '@azure/communication-calling';
9+
/* @conditional-compile-remove(capabilities) */
10+
import type { CapabilitiesChangeInfo } from '@azure/communication-calling';
911
/* @conditional-compile-remove(teams-identity-support) */
1012
import { TeamsCall } from '@azure/communication-calling';
1113
/* @conditional-compile-remove(call-transfer) */
@@ -317,6 +319,14 @@ export type IsCaptionsActiveChangedListener = (event: { isActive: boolean }) =>
317319
*/
318320
export type TransferRequestedListener = (event: TransferRequestedEventArgs) => void;
319321

322+
/* @conditional-compile-remove(capabilities) */
323+
/**
324+
* Callback for {@link CallAdapterSubscribers} 'capabilitiesChanged' event.
325+
*
326+
* @beta
327+
*/
328+
export type CapabilitiesChangedListener = (data: CapabilitiesChangeInfo) => void;
329+
320330
/* @conditional-compile-remove(video-background-effects) */
321331
/**
322332
* Contains the attibutes of a selected video background effect
@@ -754,6 +764,11 @@ export interface CallAdapterSubscribers {
754764
* Subscribe function for 'transferRequested' event.
755765
*/
756766
on(event: 'transferRequested', listener: TransferRequestedListener): void;
767+
/* @conditional-compile-remove(capabilities) */
768+
/**
769+
* Unsubscribe function for 'capabilitiesChanged' event.
770+
*/
771+
on(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
757772

758773
/**
759774
* Unsubscribe function for 'participantsJoined' event.
@@ -818,6 +833,11 @@ export interface CallAdapterSubscribers {
818833
* Unsubscribe function for 'transferRequested' event.
819834
*/
820835
off(event: 'transferRequested', listener: TransferRequestedListener): void;
836+
/* @conditional-compile-remove(capabilities) */
837+
/**
838+
* Unsubscribe function for 'capabilitiesChanged' event.
839+
*/
840+
off(event: 'capabilitiesChanged', listener: CapabilitiesChangedListener): void;
821841
}
822842

823843
// This type remains for non-breaking change reason

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@ export type { CaptionsReceivedListener, IsCaptionsActiveChangedListener } from '
5858
/* @conditional-compile-remove(call-transfer) */
5959
export type { TransferRequestedListener } from './CallAdapter';
6060

61+
/* @conditional-compile-remove(capabilities) */
62+
export type { CapabilitiesChangedListener } from './CallAdapter';
63+
6164
/* @conditional-compile-remove(teams-identity-support) */
6265
export type { TeamsCallAdapter } from './CallAdapter';

packages/react-composites/src/composites/CallComposite/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,6 @@ export type { CaptionsReceivedListener, IsCaptionsActiveChangedListener } from '
9191

9292
/* @conditional-compile-remove(call-transfer) */
9393
export type { TransferRequestedListener } from './adapter';
94+
95+
/* @conditional-compile-remove(capabilities) */
96+
export type { CapabilitiesChangedListener } from './adapter';

0 commit comments

Comments
 (0)