Skip to content

Commit 3d491b8

Browse files
Added role to selectors (#2419)
* Added role to selectors * Change files * Avoid duplicate code * remove 'Unknown' from Role type in react-components * Use RemoteParticipantState type from calling * Fix Role type comment Co-authored-by: Anjul Garg <anjulgarg@live.com>
1 parent 7b0e297 commit 3d491b8

11 files changed

Lines changed: 115 additions & 10 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Added role to selectors",
4+
"packageName": "@internal/calling-component-bindings",
5+
"email": "miguelgamis@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Added role to CallParticipantListParticipant type",
4+
"packageName": "@internal/react-components",
5+
"email": "miguelgamis@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Added getRole selector",
4+
"packageName": "@internal/react-composites",
5+
"email": "miguelgamis@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/calling-component-bindings/src/baseSelectors.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33
import { DominantSpeakersInfo } from '@azure/communication-calling';
4+
/* @conditional-compile-remove(rooms) */
5+
import { ParticipantRole } from '@azure/communication-calling';
46
import { toFlatCommunicationIdentifier } from '@internal/acs-ui-common';
57
import {
68
CallClientState,
@@ -25,6 +27,13 @@ export type CallingBaseSelectorProps = {
2527
*/
2628
export const getDeviceManager = (state: CallClientState): DeviceManagerState => state.deviceManager;
2729

30+
/* @conditional-compile-remove(rooms) */
31+
/**
32+
* @private
33+
*/
34+
export const getRole = (state: CallClientState, props: CallingBaseSelectorProps): ParticipantRole | undefined =>
35+
state.calls[props.callId]?.role;
36+
2837
/**
2938
* @private
3039
*/

packages/calling-component-bindings/src/participantListSelector.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ import {
1414
import { CallParticipantListParticipant } from '@internal/react-components';
1515
import { _updateUserDisplayNames } from './utils/callUtils';
1616
import { memoizedConvertAllremoteParticipants } from './utils/participantListSelectorUtils';
17+
/* @conditional-compile-remove(rooms) */
18+
import { memoizedConvertAllremoteParticipantsBeta } from './utils/participantListSelectorUtils';
1719
import { toFlatCommunicationIdentifier } from '@internal/acs-ui-common';
1820

1921
const convertRemoteParticipantsToParticipantListParticipants = (
2022
remoteParticipants: RemoteParticipantState[]
2123
): CallParticipantListParticipant[] => {
22-
return memoizedConvertAllremoteParticipants((memoizeFn) => {
24+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
25+
const conversionCallback = (memoizeFn) => {
2326
return (
2427
remoteParticipants
2528
// temporarily hiding lobby participants in ACS clients till we can admit users through ACS clients
@@ -36,7 +39,8 @@ const convertRemoteParticipantsToParticipantListParticipants = (
3639
participant.state,
3740
participant.isMuted,
3841
isScreenSharing,
39-
participant.isSpeaking
42+
participant.isSpeaking,
43+
/* @conditional-compile-remove(rooms) */ participant.role
4044
);
4145
})
4246
.sort((a, b) => {
@@ -51,7 +55,10 @@ const convertRemoteParticipantsToParticipantListParticipants = (
5155
}
5256
})
5357
);
54-
});
58+
};
59+
/* @conditional-compile-remove(rooms) */
60+
return memoizedConvertAllremoteParticipantsBeta(conversionCallback);
61+
return memoizedConvertAllremoteParticipants(conversionCallback);
5562
};
5663

5764
/**

packages/calling-component-bindings/src/utils/participantListSelectorUtils.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4+
import { RemoteParticipantState } from '@azure/communication-calling';
45
import { getIdentifierKind } from '@azure/communication-common';
56
import { fromFlatCommunicationIdentifier, memoizeFnAll } from '@internal/acs-ui-common';
67
import { CallParticipantListParticipant } from '@internal/react-components';
8+
/* @conditional-compile-remove(rooms) */
9+
import { Role } from '@internal/react-components';
710

811
/**
912
* @private
@@ -12,7 +15,7 @@ export const memoizedConvertAllremoteParticipants = memoizeFnAll(
1215
(
1316
userId: string,
1417
displayName: string | undefined,
15-
state: 'Idle' | 'Connecting' | 'Ringing' | 'Connected' | 'Hold' | 'InLobby' | 'EarlyMedia' | 'Disconnected',
18+
state: RemoteParticipantState,
1619
isMuted: boolean,
1720
isScreenSharing: boolean,
1821
isSpeaking: boolean
@@ -31,7 +34,7 @@ export const memoizedConvertAllremoteParticipants = memoizeFnAll(
3134
const convertRemoteParticipantToParticipantListParticipant = (
3235
userId: string,
3336
displayName: string | undefined,
34-
state: 'Idle' | 'Connecting' | 'Ringing' | 'Connected' | 'Hold' | 'InLobby' | 'EarlyMedia' | 'Disconnected',
37+
state: RemoteParticipantState,
3538
isMuted: boolean,
3639
isScreenSharing: boolean,
3740
isSpeaking: boolean
@@ -50,3 +53,52 @@ const convertRemoteParticipantToParticipantListParticipant = (
5053
getIdentifierKind(identifier).kind === 'communicationUser' || getIdentifierKind(identifier).kind === 'phoneNumber'
5154
};
5255
};
56+
57+
/* @conditional-compile-remove(rooms) */
58+
/**
59+
* @private
60+
*/
61+
export const memoizedConvertAllremoteParticipantsBeta = memoizeFnAll(
62+
(
63+
userId: string,
64+
displayName: string | undefined,
65+
state: RemoteParticipantState,
66+
isMuted: boolean,
67+
isScreenSharing: boolean,
68+
isSpeaking: boolean,
69+
role: Role
70+
): CallParticipantListParticipant => {
71+
return convertRemoteParticipantToParticipantListParticipantBeta(
72+
userId,
73+
displayName,
74+
state,
75+
isMuted,
76+
isScreenSharing,
77+
isSpeaking,
78+
role
79+
);
80+
}
81+
);
82+
83+
/* @conditional-compile-remove(rooms) */
84+
const convertRemoteParticipantToParticipantListParticipantBeta = (
85+
userId: string,
86+
displayName: string | undefined,
87+
state: RemoteParticipantState,
88+
isMuted: boolean,
89+
isScreenSharing: boolean,
90+
isSpeaking: boolean,
91+
role: Role
92+
): CallParticipantListParticipant => {
93+
return {
94+
...convertRemoteParticipantToParticipantListParticipant(
95+
userId,
96+
displayName,
97+
state,
98+
isMuted,
99+
isScreenSharing,
100+
isSpeaking
101+
),
102+
role
103+
};
104+
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ export type CallParticipantListParticipant = ParticipantListParticipant & {
653653
isScreenSharing?: boolean;
654654
isMuted?: boolean;
655655
isSpeaking?: boolean;
656+
role?: Role;
656657
};
657658

658659
// @beta
@@ -2695,8 +2696,8 @@ export interface RemoteVideoStreamState {
26952696
view?: VideoStreamRendererViewState;
26962697
}
26972698

2698-
// @beta (undocumented)
2699-
export type Role = 'Presenter' | 'Attendee' | 'Consumer';
2699+
// @beta
2700+
export type Role = 'Presenter' | 'Attendee' | 'Consumer' | 'Organizer';
27002701

27012702
// @public
27022703
export const ScreenShareButton: (props: ScreenShareButtonProps) => JSX.Element;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export type CallParticipantListParticipant = ParticipantListParticipant & {
133133
isScreenSharing?: boolean;
134134
isMuted?: boolean;
135135
isSpeaking?: boolean;
136+
role?: Role;
136137
};
137138

138139
// @public
@@ -1344,8 +1345,8 @@ export const _RemoteVideoTile: React_2.MemoExoticComponent<(props: {
13441345
participantState?: ParticipantState | undefined;
13451346
}) => JSX.Element>;
13461347

1347-
// @beta (undocumented)
1348-
export type Role = 'Presenter' | 'Attendee' | 'Consumer';
1348+
// @beta
1349+
export type Role = 'Presenter' | 'Attendee' | 'Consumer' | 'Organizer';
13491350

13501351
// @public
13511352
export const ScreenShareButton: (props: ScreenShareButtonProps) => JSX.Element;

packages/react-components/src/permissions/PermissionsProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ export const _usePermissions = (): _Permissions => useContext(PermissionsContext
9090

9191
/**
9292
* @beta
93+
* The role of a call participant.
9394
*/
94-
export type Role = 'Presenter' | 'Attendee' | 'Consumer';
95+
export type Role = 'Presenter' | 'Attendee' | 'Consumer' | 'Organizer';
9596

9697
/**
9798
* @internal

packages/react-components/src/types/ParticipantListParticipant.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4+
/* @conditional-compile-remove(rooms) */
5+
import { Role } from '../permissions';
46
import { CommunicationParticipant } from './CommunicationParticipant';
57

68
/**
@@ -17,6 +19,9 @@ export type CallParticipantListParticipant = ParticipantListParticipant & {
1719
isMuted?: boolean;
1820
/** Whether calling participant is speaking */
1921
isSpeaking?: boolean;
22+
/* @conditional-compile-remove(rooms) */
23+
/** Role of participant in Rooms call */
24+
role?: Role;
2025
};
2126

2227
/**

0 commit comments

Comments
 (0)