From f16a14c0fb3b272e0388c09711e7dbce5acf6f80 Mon Sep 17 00:00:00 2001 From: James Burnside <2684369+JamesBurnside@users.noreply.github.com> Date: Tue, 3 Aug 2021 14:05:26 -0700 Subject: [PATCH] Update `createAzureCommunicationCallAdapter` ctor to take an object instead of many params (#625) --- ...-5cd5f3a1-0589-4eb6-a434-31ccd4314017.json | 7 ++++++ .../review/communication-react.api.md | 11 +++++++++- .../review/react-composites.api.md | 11 +++++++++- .../adapter/AzureCommunicationCallAdapter.ts | 22 +++++++++++++------ .../tests/browser/call/app/index.tsx | 10 ++++----- .../snippets/Container.snippet.tsx | 10 ++++----- ...ustomDataModelExampleContainer.snippet.tsx | 12 +++++----- .../snippets/Meeting.snippet.tsx | 10 ++++----- .../QuickstartCompositeAdapter.snippet.tsx | 8 +++---- .../QuickstartCompositeComplete.snippet.tsx | 10 ++++----- .../snippets/CallAdapterExample.snippet.tsx | 12 +++++----- .../LocalizedComposites.snippet.tsx | 10 ++++----- samples/Calling/src/app/views/CallScreen.tsx | 12 +++++----- .../StaticHtmlComposites/src/callComposite.js | 10 ++++----- 14 files changed, 94 insertions(+), 61 deletions(-) create mode 100644 change/@internal-react-composites-5cd5f3a1-0589-4eb6-a434-31ccd4314017.json diff --git a/change/@internal-react-composites-5cd5f3a1-0589-4eb6-a434-31ccd4314017.json b/change/@internal-react-composites-5cd5f3a1-0589-4eb6-a434-31ccd4314017.json new file mode 100644 index 00000000000..c0f82b17cbd --- /dev/null +++ b/change/@internal-react-composites-5cd5f3a1-0589-4eb6-a434-31ccd4314017.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Update createAzureCommunicationCallAdapter constructor to take in a named object instead of seperate args", + "packageName": "@internal/react-composites", + "email": "2684369+JamesBurnside@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/communication-react/review/communication-react.api.md b/packages/communication-react/review/communication-react.api.md index 2f4011b5b9d..7275e8e6212 100644 --- a/packages/communication-react/review/communication-react.api.md +++ b/packages/communication-react/review/communication-react.api.md @@ -171,6 +171,15 @@ export class AzureCommunicationCallAdapter implements CallAdapter { unmute(): Promise; } +// @public (undocumented) +export type AzureCommunicationCallAdapterArgs = { + userId: CommunicationUserKind; + displayName: string; + credential: CommunicationTokenCredential; + locator: TeamsMeetingLinkLocator | GroupCallLocator; + callClientOptions?: CallClientOptions; +}; + // @public export interface BaseCustomStylesProps { root?: IStyle; @@ -739,7 +748,7 @@ export interface ControlBarProps { } // @public (undocumented) -export const createAzureCommunicationCallAdapter: (userId: CommunicationUserKind, displayName: string, credential: CommunicationTokenCredential, locator: TeamsMeetingLinkLocator | GroupCallLocator, callClientOptions?: CallClientOptions | undefined) => Promise; +export const createAzureCommunicationCallAdapter: ({ userId, displayName, credential, locator, callClientOptions }: AzureCommunicationCallAdapterArgs) => Promise; // @public (undocumented) export const createAzureCommunicationChatAdapter: (endpointUrl: string, userId: CommunicationIdentifierKind, displayName: string, credential: CommunicationTokenCredential, threadId: string) => Promise; diff --git a/packages/react-composites/review/react-composites.api.md b/packages/react-composites/review/react-composites.api.md index 89047c3dd29..b6dbbe00eef 100644 --- a/packages/react-composites/review/react-composites.api.md +++ b/packages/react-composites/review/react-composites.api.md @@ -132,6 +132,15 @@ export class AzureCommunicationCallAdapter implements CallAdapter { unmute(): Promise; } +// @public (undocumented) +export type AzureCommunicationCallAdapterArgs = { + userId: CommunicationUserKind; + displayName: string; + credential: CommunicationTokenCredential; + locator: TeamsMeetingLinkLocator | GroupCallLocator; + callClientOptions?: CallClientOptions; +}; + // @public (undocumented) export interface CallAdapter { // (undocumented) @@ -375,7 +384,7 @@ export type ChatUIState = { }; // @public (undocumented) -export const createAzureCommunicationCallAdapter: (userId: CommunicationUserKind, displayName: string, credential: CommunicationTokenCredential, locator: TeamsMeetingLinkLocator | GroupCallLocator, callClientOptions?: CallClientOptions | undefined) => Promise; +export const createAzureCommunicationCallAdapter: ({ userId, displayName, credential, locator, callClientOptions }: AzureCommunicationCallAdapterArgs) => Promise; // @public (undocumented) export const createAzureCommunicationChatAdapter: (endpointUrl: string, userId: CommunicationIdentifierKind, displayName: string, credential: CommunicationTokenCredential, threadId: string) => Promise; diff --git a/packages/react-composites/src/composites/CallComposite/adapter/AzureCommunicationCallAdapter.ts b/packages/react-composites/src/composites/CallComposite/adapter/AzureCommunicationCallAdapter.ts index 14a3858ae9a..477a2308081 100644 --- a/packages/react-composites/src/composites/CallComposite/adapter/AzureCommunicationCallAdapter.ts +++ b/packages/react-composites/src/composites/CallComposite/adapter/AzureCommunicationCallAdapter.ts @@ -468,13 +468,21 @@ const isPreviewOn = (deviceManager: DeviceManagerState): boolean => { return deviceManager.unparentedViews.length > 0 && deviceManager.unparentedViews[0].view !== undefined; }; -export const createAzureCommunicationCallAdapter = async ( - userId: CommunicationUserKind, - displayName: string, - credential: CommunicationTokenCredential, - locator: TeamsMeetingLinkLocator | GroupCallLocator, - callClientOptions?: CallClientOptions -): Promise => { +export type AzureCommunicationCallAdapterArgs = { + userId: CommunicationUserKind; + displayName: string; + credential: CommunicationTokenCredential; + locator: TeamsMeetingLinkLocator | GroupCallLocator; + callClientOptions?: CallClientOptions; +}; + +export const createAzureCommunicationCallAdapter = async ({ + userId, + displayName, + credential, + locator, + callClientOptions +}: AzureCommunicationCallAdapterArgs): Promise => { const callClient = createStatefulCallClient({ userId }, { callClientOptions }); const deviceManager = (await callClient.getDeviceManager()) as StatefulDeviceManager; const callAgent = await callClient.createCallAgent(credential, { displayName }); diff --git a/packages/react-composites/tests/browser/call/app/index.tsx b/packages/react-composites/tests/browser/call/app/index.tsx index a5ea3f0e8fb..25efc768bdd 100644 --- a/packages/react-composites/tests/browser/call/app/index.tsx +++ b/packages/react-composites/tests/browser/call/app/index.tsx @@ -23,12 +23,12 @@ function App(): JSX.Element { useEffect(() => { const initialize = async (): Promise => { setCallAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: userId }, + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: userId }, displayName, - new AzureCommunicationTokenCredential(token), - { groupId: groupId } - ) + credential: new AzureCommunicationTokenCredential(token), + locator: { groupId: groupId } + }) ); }; diff --git a/packages/storybook/stories/CallComposite/snippets/Container.snippet.tsx b/packages/storybook/stories/CallComposite/snippets/Container.snippet.tsx index 2ff7e1680f3..40adf0362fd 100644 --- a/packages/storybook/stories/CallComposite/snippets/Container.snippet.tsx +++ b/packages/storybook/stories/CallComposite/snippets/Container.snippet.tsx @@ -34,12 +34,12 @@ export const ContosoCallContainer = (props: ContainerProps): JSX.Element => { : { groupId: props.locator }; const createAdapter = async (credential: AzureCommunicationTokenCredential): Promise => { setAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, - props.displayName, + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, + displayName: props.displayName, credential, - callLocator - ) + locator: callLocator + }) ); }; createAdapter(credential); diff --git a/packages/storybook/stories/CallComposite/snippets/CustomDataModelExampleContainer.snippet.tsx b/packages/storybook/stories/CallComposite/snippets/CustomDataModelExampleContainer.snippet.tsx index dbc6227ae06..a16cbdda327 100644 --- a/packages/storybook/stories/CallComposite/snippets/CustomDataModelExampleContainer.snippet.tsx +++ b/packages/storybook/stories/CallComposite/snippets/CustomDataModelExampleContainer.snippet.tsx @@ -26,12 +26,12 @@ export const CustomDataModelExampleContainer = (props: ContainerProps): JSX.Elem : { groupId: props.locator }; const createAdapter = async (): Promise => { setAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, - props.displayName, - new AzureCommunicationTokenCredential(props.token), - callLocator - ) + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, + displayName: props.displayName, + credential: new AzureCommunicationTokenCredential(props.token), + locator: callLocator + }) ); }; createAdapter(); diff --git a/packages/storybook/stories/MeetingComposite/snippets/Meeting.snippet.tsx b/packages/storybook/stories/MeetingComposite/snippets/Meeting.snippet.tsx index 3dd16966255..ffce2d18593 100644 --- a/packages/storybook/stories/MeetingComposite/snippets/Meeting.snippet.tsx +++ b/packages/storybook/stories/MeetingComposite/snippets/Meeting.snippet.tsx @@ -46,12 +46,12 @@ export const MeetingExperience = (props: MeetingExampleProps): JSX.Element => { ) { const createAdapters = async (): Promise => { setCallAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, - props.displayName, + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, + displayName: props.displayName, credential, - props.locator - ) + locator: props.locator + }) ); setChatAdapter( diff --git a/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeAdapter.snippet.tsx b/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeAdapter.snippet.tsx index dca5b19c49f..681e451a70f 100644 --- a/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeAdapter.snippet.tsx +++ b/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeAdapter.snippet.tsx @@ -45,12 +45,12 @@ function App(): JSX.Element { ) ); setCallAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: userId }, + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: userId }, displayName, credential, - { groupId } - ) + locator: { groupId } + }) ); }; createAdapter(credential); diff --git a/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeComplete.snippet.tsx b/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeComplete.snippet.tsx index 8189251584f..30be20b9739 100644 --- a/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeComplete.snippet.tsx +++ b/packages/storybook/stories/QuickStarts/snippets/QuickstartCompositeComplete.snippet.tsx @@ -46,12 +46,12 @@ function App(): JSX.Element { ) ); setCallAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: userId }, + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: userId }, displayName, - new AzureCommunicationTokenCredential(token), - { groupId } - ) + credential: new AzureCommunicationTokenCredential(token), + locator: { groupId } + }) ); }; createAdapter(); diff --git a/packages/storybook/stories/Stateful Client/snippets/CallAdapterExample.snippet.tsx b/packages/storybook/stories/Stateful Client/snippets/CallAdapterExample.snippet.tsx index 0b3336f8c16..89fbf4a04af 100644 --- a/packages/storybook/stories/Stateful Client/snippets/CallAdapterExample.snippet.tsx +++ b/packages/storybook/stories/Stateful Client/snippets/CallAdapterExample.snippet.tsx @@ -16,12 +16,12 @@ export const CallAdapterExample = (props: CallAdapterExampleProps): JSX.Element if (props) { const createAdapter = async (): Promise => { setCallAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, - props.displayName, - new AzureCommunicationTokenCredential(props.accessToken), - props.callLocator - ) + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId }, + displayName: props.displayName, + credential: new AzureCommunicationTokenCredential(props.accessToken), + locator: props.callLocator + }) ); }; createAdapter(); diff --git a/packages/storybook/stories/snippets/localization/LocalizedComposites.snippet.tsx b/packages/storybook/stories/snippets/localization/LocalizedComposites.snippet.tsx index 3d929f17039..75147047ba4 100644 --- a/packages/storybook/stories/snippets/localization/LocalizedComposites.snippet.tsx +++ b/packages/storybook/stories/snippets/localization/LocalizedComposites.snippet.tsx @@ -47,12 +47,12 @@ function App(): JSX.Element { ) ); setCallAdapter( - await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: userId }, + await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: userId }, displayName, - new AzureCommunicationTokenCredential(token), - { groupId } - ) + credential: new AzureCommunicationTokenCredential(token), + locator: { groupId } + }) ); }; createAdapter(); diff --git a/samples/Calling/src/app/views/CallScreen.tsx b/samples/Calling/src/app/views/CallScreen.tsx index bd92723f051..b475070b744 100644 --- a/samples/Calling/src/app/views/CallScreen.tsx +++ b/samples/Calling/src/app/views/CallScreen.tsx @@ -26,12 +26,12 @@ export const CallScreen = (props: CallScreenProps): JSX.Element => { useEffect(() => { (async () => { - const adapter = await createAzureCommunicationCallAdapter( - { kind: 'communicationUser', communicationUserId: userId.communicationUserId }, - displayName, - createAutoRefreshingCredential(userId.communicationUserId, token), - callLocator - ); + const adapter = await createAzureCommunicationCallAdapter({ + userId: { kind: 'communicationUser', communicationUserId: userId.communicationUserId }, + displayName: displayName, + credential: createAutoRefreshingCredential(userId.communicationUserId, token), + locator: callLocator + }); adapter.on('callEnded', () => { onCallEnded(); }); diff --git a/samples/StaticHtmlComposites/src/callComposite.js b/samples/StaticHtmlComposites/src/callComposite.js index 2105240819c..8d093334d20 100644 --- a/samples/StaticHtmlComposites/src/callComposite.js +++ b/samples/StaticHtmlComposites/src/callComposite.js @@ -8,12 +8,12 @@ import { CallComposite, createAzureCommunicationCallAdapter } from '@azure/commu export const loadCallComposite = async function (args, htmlElement) { const { userId, token, groupId, displayName } = args; - const adapter = await createAzureCommunicationCallAdapter( + const adapter = await createAzureCommunicationCallAdapter({ userId, - displayName ?? 'anonymous', - new AzureCommunicationTokenCredential(token), - { groupId } - ); + displayName: displayName ?? 'anonymous', + credential: new AzureCommunicationTokenCredential(token), + locator: { groupId } + }); ReactDOM.render(React.createElement(CallComposite, { adapter }, null), htmlElement); return adapter; };