Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this exercise you'll add the ACS UI calling composite into a React app to enable making audio/video calls from a custom app into a Microsoft Teams meeting.
Visit GitHub and sign in. If you don't already have a GitHub account, you can select the Sign up option to create one.
Visit the Microsoft Cloud GitHub Repository.
Select the Fork option to add the repository to your desired GitHub organization/account.
Run the following command to clone this repository to your machine. Replace <YOUR_ORG_NAME> with your GitHub organization/account name.
git clone https://github.com/<YOUR_ORG_NAME>/MicrosoftCloudOpen the samples/acs-to-teams-meeting project folder in Visual Studio Code.
Expand the client/react folder.
Open the package.json file in VS Code and note the following ACS packages are included:
@azure/communication-common @azure/communication-reactDouble-check that you have npm 10 or higher installed by opening a terminal window and running the following command:
npm --versionTip
If you don't have npm 10 or higher installed you can update npm to the latest version by running
npm install -g npm.Open a terminal window and run the
npm installcommand in the react folder to install the application dependencies.Open App.tsx and take a moment to explore the imports at the top of the file. These handle importing ACS security and audio/video calling symbols that will be used in the app.
import { AzureCommunicationTokenCredential, CommunicationUserIdentifier } from '@azure/communication-common'; import { CallComposite, fromFlatCommunicationIdentifier, useAzureCommunicationCallAdapter } from '@azure/communication-react'; import React, { useState, useMemo, useEffect } from 'react'; import './App.css';Note
You'll see how the
CallCompositecomponent is used later in this exercise. It provides the core UI functionality for Azure Communication Services to enable making an audio/video call from the app into a Microsoft Teams meeting.Locate the
Appcomponent and perform the following tasks:- Take a moment to examine the
useStatedefinitions in the component. - Replace the
userIduseStatefunction's empty quotes with the ACS user identity value you copied in the previous exercise. - Replace the
tokenuseStatefunction's empty quotes with the ACS token value you copied in the previous exercise. - Replace the
teamsMeetingLinkuseStatefunction's empty quotes with the Teams meeting link value you copied in the previous exercise.
// Replace '' with the ACS user identity value const [userId, setUserId] = useState<string>(''); // Replace '' with the ACS token value const [token, setToken] = useState<string>(''); // Replace '' with the Teams meeting link value const [teamsMeetingLink, setTeamsMeetingLink] = useState<string>('');Note
Later in this tutorial you'll see how to retrieve the
userId,token, andteamsMeetingLinkvalues dynamically.- Take a moment to examine the
Take a moment to explore the
useMemofunctions in theAppcomponent.- The
credentialuseMemofunction creates a newAzureCommunicationTokenCredentialinstance once the token has a value. - The
callAdapterArgsuseMemofunction returns an object that has the arguments that are used to make an audio/video call. Notice that is uses theuserId,credential, andteamsMeetingLinkvalues in the ACS call arguments.
const credential = useMemo(() => { if (token) { return new AzureCommunicationTokenCredential(token) } return; }, [token]); const callAdapterArgs = useMemo(() => { if (userId && credential && displayName && teamsMeetingLink) { return { userId: fromFlatCommunicationIdentifier(userId) as CommunicationUserIdentifier, displayName, credential, locator: { meetingLink: teamsMeetingLink }, } } return {}; }, [userId, credential, displayName, teamsMeetingLink]);Note
useMemois used in this scenario because we only want theAzureCommunicationTokenCredentialobject and the call adapter args to be created once as the necessary parameters are passed in. View additional details about useMemo here.- The
Once the
credentialsandcallAdapterArgsare ready, the following line handles creating an ACS call adapter using theuseAzureCommunicationCallAdapterReact hook provided by ACS. ThecallAdapterobject will be used later in the UI calling composite component.const callAdapter = useAzureCommunicationCallAdapter(callAdapterArgs);Note
Because
useAzureCommunicationCallAdapteris a React hook, it won't assign a value tocallAdapteruntil thecallAdapterArgsvalue is valid.Earlier you assigned the user identity, token, and Teams meeting link to state values in the
Appcomponent. That works fine for now, but in a later exercise you'll see how to dynamically retrieve those values. Since you set the values earlier, comment out the code in theuseEffectfunction as shown next. Once you get the Azure Functions running in the next exercises, you'll revisit this code.useEffect(() => { /* Commenting out for now const init = async () => { setMessage('Getting ACS user'); //Call Azure Function to get the ACS user identity and token let res = await fetch(process.env.REACT_APP_ACS_USER_FUNCTION as string); let user = await res.json(); setUserId(user.userId); setToken(user.token); setMessage('Getting Teams meeting link...'); //Call Azure Function to get the meeting link res = await fetch(process.env.REACT_APP_TEAMS_MEETING_FUNCTION as string); let link = await res.text(); setTeamsMeetingLink(link); setMessage(''); console.log('Teams meeting link', link); } init(); */ }, []);Locate the following JSX code. It uses the
CallCompositesymbol you saw imported to render the user interface used to make an audio/video call from the React app into a Teams meeting. ThecallAdapteryou explored earlier is passed to itsadapterproperty to provide the required arguments.if (callAdapter) { return ( <div> <h1>Contact Customer Service</h1> <div className="wrapper"> <CallComposite adapter={callAdapter} /> </div> </div> ); }Save the file before continuing.
Run
npm startin your terminal window to run the application. Ensure you run the command within the react folder.After the applications builds you should see a calling UI displayed. Enable selecting your microphone and camera and initiate the call. You should see that you're placed in a waiting room. If you join the meeting you setup earlier in Microsoft Teams, you can allow the guest to enter the meeting.
Press Ctrl + C to stop the application. Now that you've successfully run it, let's explore how you can dynamically get the ACS user identity and token and automatically create a Microsoft Teams meeting and return the join URL using Microsoft Graph.