TypeError on CallComposite i.CallClient is not a constructor
#2616
-
Describe the bug; what happened?
example: import { GroupCallLocator } from '@azure/communication-calling'
import { AzureCommunicationTokenCredential } from '@azure/communication-common'
import {
CallAdapter,
CallComposite,
createStatefulCallClient,
useAzureCommunicationCallAdapter
} from '@azure/communication-react'
import Loading from '@components/common/Loading'
import { mediaQuerySize } from '@constants'
import useResizeHandler from '@hooks/useResizeHandler'
import { log } from '@utils/log'
import { useTranslation } from 'next-i18next'
import { FC, useContext, useEffect, useMemo } from 'react'
import { Context } from 'src/context/ContextProvider'
interface Params {
displayName: string
isClosingAcs: boolean
setIsClosingAcs: Function
setIsModalOpen: Function
communicationUserId: string
credential: AzureCommunicationTokenCredential
locator: GroupCallLocator
}
const AzureCommunications: FC<Params> = ({
displayName,
isClosingAcs,
setIsClosingAcs,
setIsModalOpen,
communicationUserId,
credential,
locator
}) => {
const { setGroupCallId, showCommunications, groupCallId } = useContext(Context)
const { t } = useTranslation(['common'])
const windowWidth = useResizeHandler()
const isMobile = useMemo(() => windowWidth < mediaQuerySize.sm, [windowWidth])
const statefulCallClient = createStatefulCallClient({
userId: { communicationUserId }
})
const callAdaptorArgs = useMemo(
() => ({
userId: { communicationUserId },
displayName,
credential,
locator
}),
[communicationUserId, displayName, credential, locator]
)
const adapter = useAzureCommunicationCallAdapter(
callAdaptorArgs,
async (adapter: CallAdapter): Promise<CallAdapter> => {
console.log('afterCreate', adapter)
return adapter
},
async (adapter: CallAdapter): Promise<void> => {
console.log('beforeDispose', adapter)
await adapter.leaveCall().catch((e) => {
console.error('Failed to leave call', e)
})
}
)
useEffect(() => {
if (adapter) {
console.log(adapter)
log('has callAdapter. add callEnded event')
adapter.on('callEnded', (event) => {
log('callEnded: ', event.callId)
setGroupCallId(null)
})
}
}, [adapter])
useEffect(() => {
if (isClosingAcs) {
log('call disposed')
setGroupCallId(null)
showCommunications(false)
setIsClosingAcs(false)
setIsModalOpen(false)
}
}, [isClosingAcs])
return (
<>
{adapter ? (
<CallComposite adapter={adapter} formFactor={isMobile ? 'mobile' : 'desktop'} />
) : (
<Loading message={t('common:call:initializing_call')} />
)}
</>
)
}
export default AzureCommunications What are the steps to reproduce the issue? What behavior did you expect?
If applicable, provide screenshots: In what environment did you see the issue?
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
I don't know why but the error is gone when I switch swcMinify: true to false in next.config.js |
Beta Was this translation helpful? Give feedback.
-
https://github.com/alkwa-msft/nextjs-communication-react-calling-experiment I created a small project to try to understand more about the nextjs/swc issues with azure communications service. I was wondering if you can check out my repo to see if I missed anything? it appears to work for me but I also am not an expert in nextjs and I might be setting it up incorrectly? I would love to use this repo to better understand the issue so we can either code a better solution into our library or write some documentation to help the next .. nextjs developers |
Beta Was this translation helpful? Give feedback.
-
@dev-bazz I am still currently investigating. The main hurdle I do see is that the javascript SDKs are meant to be running on the browser where we have a window object. By default NextJS makes assumptions that code can be rendered on the server or some combination of incremental server/client side rendering. According to my research it seems like dynamic importing if we know we are on the client or simply returning nothing if we are on the server till we are on the client seems to be the most predominant strategies that I am finding. Ultimately, we are building client-side typescript react code and the underlying Calling SDK takes a dependency on the window object. Still continuing to look further. |
Beta Was this translation helpful? Give feedback.
-
Any update on this one? |
Beta Was this translation helpful? Give feedback.
-
@alkwa-msft I am able to make it work using turbopack |
Beta Was this translation helpful? Give feedback.
I don't know why but the error is gone when I switch swcMinify: true to false in next.config.js
Had similar experience with swcMinify conflicts with ACS before.