Skip to content

Commit

Permalink
Update createAzureCommunicationChatAdapter ctor to take an object i…
Browse files Browse the repository at this point in the history
…nstead of many params (#626)
  • Loading branch information
JamesBurnside authored Aug 3, 2021
1 parent f16a14c commit 370cb99
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Update createAzureCommunicationChatAdapter constructor to take in a named object instead of seperate args",
"packageName": "@internal/react-composites",
"email": "[email protected]",
"dependentChangeType": "patch"
}
11 changes: 10 additions & 1 deletion packages/communication-react/review/communication-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ export type AzureCommunicationCallAdapterArgs = {
callClientOptions?: CallClientOptions;
};

// @public (undocumented)
export type AzureCommunicationChatAdapterArgs = {
endpointUrl: string;
userId: CommunicationIdentifierKind;
displayName: string;
credential: CommunicationTokenCredential;
threadId: string;
};

// @public
export interface BaseCustomStylesProps {
root?: IStyle;
Expand Down Expand Up @@ -751,7 +760,7 @@ export interface ControlBarProps {
export const createAzureCommunicationCallAdapter: ({ userId, displayName, credential, locator, callClientOptions }: AzureCommunicationCallAdapterArgs) => Promise<CallAdapter>;

// @public (undocumented)
export const createAzureCommunicationChatAdapter: (endpointUrl: string, userId: CommunicationIdentifierKind, displayName: string, credential: CommunicationTokenCredential, threadId: string) => Promise<ChatAdapter>;
export const createAzureCommunicationChatAdapter: ({ endpointUrl, userId, displayName, credential, threadId }: AzureCommunicationChatAdapterArgs) => Promise<ChatAdapter>;

// @public (undocumented)
export const createDefaultCallingHandlers: (callClient: StatefulCallClient, callAgent: CallAgent | undefined, deviceManager: StatefulDeviceManager | undefined, call: Call | undefined) => {
Expand Down
11 changes: 10 additions & 1 deletion packages/react-composites/review/react-composites.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ export type AzureCommunicationCallAdapterArgs = {
callClientOptions?: CallClientOptions;
};

// @public (undocumented)
export type AzureCommunicationChatAdapterArgs = {
endpointUrl: string;
userId: CommunicationIdentifierKind;
displayName: string;
credential: CommunicationTokenCredential;
threadId: string;
};

// @public (undocumented)
export interface CallAdapter {
// (undocumented)
Expand Down Expand Up @@ -387,7 +396,7 @@ export type ChatUIState = {
export const createAzureCommunicationCallAdapter: ({ userId, displayName, credential, locator, callClientOptions }: AzureCommunicationCallAdapterArgs) => Promise<CallAdapter>;

// @public (undocumented)
export const createAzureCommunicationChatAdapter: (endpointUrl: string, userId: CommunicationIdentifierKind, displayName: string, credential: CommunicationTokenCredential, threadId: string) => Promise<ChatAdapter>;
export const createAzureCommunicationChatAdapter: ({ endpointUrl, userId, displayName, credential, threadId }: AzureCommunicationChatAdapterArgs) => Promise<ChatAdapter>;

// @public (undocumented)
export type DisplayNameChangedListener = (event: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ export const createChatAdapterWithStubs = async (chatClient: StubChatClient): Pr
// Nothing to dispose in the stub.
}
};
return await createAzureCommunicationChatAdapter(
'stubEndointUrl',
{ kind: 'communicationUser', communicationUserId: 'stubUserId' },
'stubDisplayName',
stubCredential,
'stubThreadId'
);
return await createAzureCommunicationChatAdapter({
endpointUrl: 'stubEndpointUrl',
userId: { kind: 'communicationUser', communicationUserId: 'stubUserId' },
displayName: 'stubDisplayName',
credential: stubCredential,
threadId: 'stubThreadId'
});
};

class StateChangeListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,21 @@ const convertEventToChatMessage = (event: ChatMessageReceivedEvent): ChatMessage
};
};

export const createAzureCommunicationChatAdapter = async (
endpointUrl: string,
userId: CommunicationIdentifierKind,
displayName: string,
credential: CommunicationTokenCredential,
threadId: string
): Promise<ChatAdapter> => {
export type AzureCommunicationChatAdapterArgs = {
endpointUrl: string;
userId: CommunicationIdentifierKind;
displayName: string;
credential: CommunicationTokenCredential;
threadId: string;
};

export const createAzureCommunicationChatAdapter = async ({
endpointUrl,
userId,
displayName,
credential,
threadId
}: AzureCommunicationChatAdapterArgs): Promise<ChatAdapter> => {
const chatClient = createStatefulChatClient({
userId: userId,
displayName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT license.

export { createAzureCommunicationChatAdapter } from './adapter/AzureCommunicationChatAdapter';
export type { AzureCommunicationChatAdapterArgs } from './adapter/AzureCommunicationChatAdapter';

export { ChatComposite } from './ChatComposite';

export type { ChatCompositeProps, ChatOptions } from './ChatComposite';

export type {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-composites/tests/browser/chat/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ function App(): JSX.Element {
useEffect(() => {
const initialize = async (): Promise<void> => {
setChatAdapter(
await createAzureCommunicationChatAdapter(
await createAzureCommunicationChatAdapter({
endpointUrl,
{ kind: 'communicationUser', communicationUserId: userId },
userId: { kind: 'communicationUser', communicationUserId: userId },
displayName,
new AzureCommunicationTokenCredential(token),
credential: new AzureCommunicationTokenCredential(token),
threadId
)
})
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export const ContosoChatContainer = (props: ContainerProps): JSX.Element => {
}

const createAdapter = async (): Promise<void> => {
const newAdapter = await createAzureCommunicationChatAdapter(
props.endpointUrl,
getIdentifierKind(props.userId),
props.displayName,
new AzureCommunicationTokenCredential(props.token),
props.threadId
);
const newAdapter = await createAzureCommunicationChatAdapter({
endpointUrl: props.endpointUrl,
userId: getIdentifierKind(props.userId),
displayName: props.displayName,
credential: new AzureCommunicationTokenCredential(props.token),
threadId: props.threadId
});

// Custom behavior: Intercept messages from the local user and convert
// to uppercase before sending to backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export const ContosoChatContainer = (props: ContainerProps): JSX.Element => {
if (!!credential && props) {
const createAdapter = async (credential: AzureCommunicationTokenCredential): Promise<void> => {
setAdapter(
await createAzureCommunicationChatAdapter(
props.endpointUrl,
getIdentifierKind(props.userId),
props.displayName,
await createAzureCommunicationChatAdapter({
endpointUrl: props.endpointUrl,
userId: getIdentifierKind(props.userId),
displayName: props.displayName,
credential,
props.threadId
)
threadId: props.threadId
})
);
};
createAdapter(credential);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export const CustomDataModelExampleContainer = (props: CustomDataModelExampleCon
if (props) {
const createAdapter = async (): Promise<void> => {
setAdapter(
await createAzureCommunicationChatAdapter(
props.endpointUrl,
getIdentifierKind(props.userId),
await createAzureCommunicationChatAdapter({
endpointUrl: props.endpointUrl,
userId: getIdentifierKind(props.userId),
// Data model injection: The display name for the local user comes from Contoso's data model.
props.displayName,
new AzureCommunicationTokenCredential(props.token),
props.threadId
)
displayName: props.displayName,
credential: new AzureCommunicationTokenCredential(props.token),
threadId: props.threadId
})
);
};
createAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export const ContosoChatContainer = (props: ContainerProps): JSX.Element => {
if (!props) return;

const createAdapter = async (): Promise<void> => {
const chatAdapter = await createAzureCommunicationChatAdapter(
props.endpointUrl,
getIdentifierKind(props.userId),
props.displayName,
new AzureCommunicationTokenCredential(props.token),
props.threadId
);
const chatAdapter = await createAzureCommunicationChatAdapter({
endpointUrl: props.endpointUrl,
userId: getIdentifierKind(props.userId),
displayName: props.displayName,
credential: new AzureCommunicationTokenCredential(props.token),
threadId: props.threadId
});

// Custom behavior: Intercept messages from the local user and convert
// to uppercase before sending to backend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ export const MeetingExperience = (props: MeetingExampleProps): JSX.Element => {
);

setChatAdapter(
await createAzureCommunicationChatAdapter(
props.endpointUrl,
{ kind: 'communicationUser', communicationUserId: props.userId.communicationUserId },
props.displayName,
await createAzureCommunicationChatAdapter({
endpointUrl: props.endpointUrl,
userId: { kind: 'communicationUser', communicationUserId: props.userId.communicationUserId },
displayName: props.displayName,
credential,
props.threadId
)
threadId: props.threadId
})
);
};
createAdapters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ function App(): JSX.Element {
if (credential !== undefined) {
const createAdapter = async (credential: AzureCommunicationTokenCredential): Promise<void> => {
setChatAdapter(
await createAzureCommunicationChatAdapter(
await createAzureCommunicationChatAdapter({
endpointUrl,
{ kind: 'communicationUser', communicationUserId: userId },
userId: { kind: 'communicationUser', communicationUserId: userId },
displayName,
credential,
threadId
)
})
);
setCallAdapter(
await createAzureCommunicationCallAdapter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function App(): JSX.Element {
useEffect(() => {
const createAdapter = async (): Promise<void> => {
setChatAdapter(
await createAzureCommunicationChatAdapter(
await createAzureCommunicationChatAdapter({
endpointUrl,
{ kind: 'communicationUser', communicationUserId: userId },
userId: { kind: 'communicationUser', communicationUserId: userId },
displayName,
new AzureCommunicationTokenCredential(token),
credential: new AzureCommunicationTokenCredential(token),
threadId
)
})
);
setCallAdapter(
await createAzureCommunicationCallAdapter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export const ChatAdapterExample = (props: ChatAdapterExampleProps): JSX.Element
if (props) {
const createAdapter = async (): Promise<void> => {
setChatAdapter(
await createAzureCommunicationChatAdapter(
props.endpointUrl,
getIdentifierKind(props.userId),
props.displayName,
new AzureCommunicationTokenCredential(props.accessToken),
props.threadId
)
await createAzureCommunicationChatAdapter({
endpointUrl: props.endpointUrl,
userId: getIdentifierKind(props.userId),
displayName: props.displayName,
credential: new AzureCommunicationTokenCredential(props.accessToken),
threadId: props.threadId
})
);
};
createAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function App(): JSX.Element {
useEffect(() => {
const createAdapter = async (): Promise<void> => {
setChatAdapter(
await createAzureCommunicationChatAdapter(
await createAzureCommunicationChatAdapter({
endpointUrl,
{ kind: 'communicationUser', communicationUserId: userId },
userId: { kind: 'communicationUser', communicationUserId: userId },
displayName,
new AzureCommunicationTokenCredential(token),
credential: new AzureCommunicationTokenCredential(token),
threadId
)
})
);
setCallAdapter(
await createAzureCommunicationCallAdapter({
Expand Down
8 changes: 4 additions & 4 deletions samples/StaticHtmlComposites/src/chatComposite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { ChatComposite, createAzureCommunicationChatAdapter } from '@azure/commu

export const loadChatComposite = async function (args, htmlElement) {
const { userId, token, endpointUrl, threadId, displayName } = args;
const adapter = await createAzureCommunicationChatAdapter(
const adapter = await createAzureCommunicationChatAdapter({
endpointUrl,
userId,
displayName ?? 'anonymous',
new AzureCommunicationTokenCredential(token),
displayName: displayName ?? 'anonymous',
credential: new AzureCommunicationTokenCredential(token),
threadId
);
});
ReactDOM.render(React.createElement(ChatComposite, { adapter }, null), htmlElement);
return adapter;
};

0 comments on commit 370cb99

Please sign in to comment.