Skip to content

Commit a68d877

Browse files
[Bug Fix] Fix issue where Call with Chat adapter would create multiple clients (#3676)
* remove old logic for open in other tab * fix cwc adapter hook multi create * Change files * Duplicate change files for beta release * remove commented code * remove commented code
1 parent 089bb48 commit a68d877

7 files changed

Lines changed: 26 additions & 89 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": "Bug fix",
5+
"comment": "Fix Call with Chat adapter creation hook to handle multiple invokations.",
6+
"packageName": "@azure/communication-react",
7+
"email": "94866715+dmceachernmsft@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": "Bug fix",
5+
"comment": "Fix Call with Chat adapter creation hook to handle multiple invokations.",
6+
"packageName": "@azure/communication-react",
7+
"email": "94866715+dmceachernmsft@users.noreply.github.com",
8+
"dependentChangeType": "patch"
9+
}

packages/react-composites/src/composites/CallWithChatComposite/adapter/AzureCommunicationCallWithChatAdapter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ export const useAzureCommunicationCallWithChatAdapter = (
849849
const [adapter, setAdapter] = useState<CallWithChatAdapter | undefined>(undefined);
850850
// Ref needed for cleanup to access the old adapter created asynchronously.
851851
const adapterRef = useRef<CallWithChatAdapter | undefined>(undefined);
852+
const creatingAdapterRef = useRef<boolean>(false);
852853

853854
const afterCreateRef = useRef<((adapter: CallWithChatAdapter) => Promise<CallWithChatAdapter>) | undefined>(
854855
undefined
@@ -879,7 +880,13 @@ export const useAzureCommunicationCallWithChatAdapter = (
879880
adapterRef.current.dispose();
880881
adapterRef.current = undefined;
881882
}
882-
883+
if (creatingAdapterRef.current) {
884+
console.warn(
885+
'Adapter is already being created, please see storybook for more information: https://azure.github.io/communication-ui-library/?path=/story/troubleshooting--page'
886+
);
887+
return;
888+
}
889+
creatingAdapterRef.current = true;
883890
let newAdapter = await createAzureCommunicationCallWithChatAdapter({
884891
credential,
885892
displayName,

samples/CallWithChat/src/app/App.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import { joinThread } from './utils/joinThread';
2929
import { getThread } from './utils/getThread';
3030
import { getExistingThreadIdFromURL } from './utils/getThreadId';
3131
import { WEB_APP_TITLE } from './utils/constants';
32-
import { useSecondaryInstanceCheck } from './utils/useSecondaryInstanceCheck';
33-
import { PageOpenInAnotherTab } from './views/PageOpenInAnotherTab';
34-
import { useIsMobile } from './utils/useIsMobile';
3532
/* @conditional-compile-remove(PSTN-calls) */
3633
import { CallParticipantsLocator } from '@azure/communication-react';
3734

@@ -58,12 +55,6 @@ console.log(
5855
const App = (): JSX.Element => {
5956
const [page, setPage] = useState<AppPages>('home');
6057
const [callWithChatArgs, setCallWithChatArgs] = useState<CallWithChatArgs | undefined>(undefined);
61-
const isMobileSession = useIsMobile();
62-
const isAppAlreadyRunningInAnotherTab = useSecondaryInstanceCheck();
63-
64-
if (isMobileSession && isAppAlreadyRunningInAnotherTab) {
65-
return <PageOpenInAnotherTab />;
66-
}
6758

6859
if (isOnIphoneAndNotSafari()) {
6960
return <UnsupportedBrowserPage />;

samples/CallWithChat/src/app/utils/useSecondaryInstanceCheck.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

samples/Calling/src/app/App.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ import { getOutboundParticipants } from './utils/AppUtils';
3131
/* @conditional-compile-remove(rooms) */
3232
import { createRoom, getRoomIdFromUrl, addUserToRoom } from './utils/AppUtils';
3333
import { useIsMobile } from './utils/useIsMobile';
34-
import { useSecondaryInstanceCheck } from './utils/useSecondaryInstanceCheck';
3534
import { CallError } from './views/CallError';
3635
import { CallScreen } from './views/CallScreen';
3736
import { HomeScreen } from './views/HomeScreen';
38-
import { PageOpenInAnotherTab } from './views/PageOpenInAnotherTab';
3937
import { UnsupportedBrowserPage } from './views/UnsupportedBrowserPage';
4038

4139
setLogLevel('verbose');
@@ -84,18 +82,13 @@ const App = (): JSX.Element => {
8482

8583
const isMobileSession = useIsMobile();
8684
const isLandscapeSession = isLandscape();
87-
const isAppAlreadyRunningInAnotherTab = useSecondaryInstanceCheck();
8885

8986
useEffect(() => {
9087
if (isMobileSession && isLandscapeSession) {
9188
console.log('ACS Calling sample: Mobile landscape view is experimental behavior');
9289
}
9390
}, [isMobileSession, isLandscapeSession]);
9491

95-
if (isMobileSession && isAppAlreadyRunningInAnotherTab) {
96-
return <PageOpenInAnotherTab />;
97-
}
98-
9992
const supportedBrowser = !isOnIphoneAndNotSafari();
10093
if (!supportedBrowser) {
10194
return <UnsupportedBrowserPage />;

samples/Calling/src/app/utils/useSecondaryInstanceCheck.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)