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>/MicrosoftCloud
Open 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-react
Double-check that you have npm 10 or higher installed by opening a terminal window and running the following command:
npm --version
Tip
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 install
command 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
CallComposite
component 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
App
component and perform the following tasks:- Take a moment to examine the
useState
definitions in the component. - Replace the
userId
useState
function's empty quotes with the ACS user identity value you copied in the previous exercise. - Replace the
token
useState
function's empty quotes with the ACS token value you copied in the previous exercise. - Replace the
teamsMeetingLink
useState
function'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
, andteamsMeetingLink
values dynamically.- Take a moment to examine the
Take a moment to explore the
useMemo
functions in theApp
component.- The
credential
useMemo
function creates a newAzureCommunicationTokenCredential
instance once the token has a value. - The
callAdapterArgs
useMemo
function returns an object that has the arguments that are used to make an audio/video call. Notice that is uses theuserId
,credential
, andteamsMeetingLink
values 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
useMemo
is used in this scenario because we only want theAzureCommunicationTokenCredential
object 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
credentials
andcallAdapterArgs
are ready, the following line handles creating an ACS call adapter using theuseAzureCommunicationCallAdapter
React hook provided by ACS. ThecallAdapter
object will be used later in the UI calling composite component.const callAdapter = useAzureCommunicationCallAdapter(callAdapterArgs);
Note
Because
useAzureCommunicationCallAdapter
is a React hook, it won't assign a value tocallAdapter
until thecallAdapterArgs
value is valid.Earlier you assigned the user identity, token, and Teams meeting link to state values in the
App
component. 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 theuseEffect
function 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
CallComposite
symbol you saw imported to render the user interface used to make an audio/video call from the React app into a Teams meeting. ThecallAdapter
you explored earlier is passed to itsadapter
property 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 start
in 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.