Skip to content

Commit f5d158c

Browse files
authored
Merge pull request #214963 from jowang-msft/jowang-msft/managecallupdate1
Update native call how-to docs
2 parents dcb1191 + 3b4930f commit f5d158c

File tree

4 files changed

+331
-65
lines changed

4 files changed

+331
-65
lines changed

articles/communication-services/how-tos/calling-sdk/includes/install-sdk/install-sdk-windows.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ ms.author: rifox
99

1010
### Creating the Visual Studio project
1111

12-
In Visual Studio 2019, create a new `Blank App (Universal Windows)` project. After entering the project name, feel free to pick any Windows SDK greater than `10.0.17134`.
12+
For UWP app, in Visual Studio 2019, create a new `Blank App (Universal Windows)` project. After entering the project name, feel free to pick any Windows SDK greater than `10.0.17134`.
1313

14+
For WinUI 3 app, create a new project with the `Blank App, Packaged (WinUI 3 in Desktop)` template to set up a single-page WinUI 3 app. [Windows App SDK version 1.2 preview 2](https://learn.microsoft.com/windows/apps/windows-app-sdk/preview-channel#version-12-preview-2-120-preview2) and above is required.
1415
### Install the package and dependencies with NuGet Package Manager
1516

16-
Tha Calling SDK APIs and libraries are publicly available via a NuGet package.
17+
The Calling SDK APIs and libraries are publicly available via a NuGet package.
1718
The following steps exemplify how to find, download, and install the Calling SDK NuGet package.
1819

1920
1. Open NuGet Package Manager (`Tools` -> `NuGet Package Manager` -> `Manage NuGet Packages for Solution`)
2021
2. Click on `Browse` and then type `Azure.Communication.Calling` in the search box.
2122
3. Make sure that `Include prerelease` check box is selected.
22-
4. Click on the `Azure.Communication.Calling` package.
23+
4. Click on the `Azure.Communication.Calling` package, select `Azure.Communication.Calling` [1.0.0-beta.33](https://www.nuget.org/packages/Azure.Communication.Calling/1.0.0-beta.33) or newer version.
2324
5. Select the checkbox corresponding to the CS project on the right-side tab.
2425
6. Click on the `Install` button.

articles/communication-services/how-tos/calling-sdk/includes/manage-calls/manage-calls-windows.md

Lines changed: 35 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: probableprime
33
ms.service: azure-communication-services
44
ms.topic: include
5-
ms.date: 09/08/2021
5+
ms.date: 10/16/2022
66
ms.author: rifox
77
---
88
[!INCLUDE [Install SDK](../install-sdk/install-sdk-windows.md)]
@@ -21,57 +21,42 @@ he following steps exemplify how to achieve that.
2121
This simple sample app will contain two buttons. One for placing the call and another to hang up a placed call.
2222
The following steps exemplify how to add these buttons to the app.
2323

24-
1. In the `Solution Explorer` panel, double click on the file named `MainPage.xaml`.
24+
1. In the `Solution Explorer` panel, double click on the file named `MainPage.xaml` for UWP, or `MainWindows.xaml` for WinUI 3.
2525
2. In the central panel, look for the XAML code under the UI preview.
26-
3. Replace the `<Grid>` to `</Grid>` XAML code by the following excerpt:
26+
3. Modify the XAML code by the following excerpt:
2727
```xml
28-
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
29-
<Button x:Name="callButton" Click="CallHandler" Margin="10,10,10,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">Call</Button>
30-
<Button x:Name="hangupButton" Click="HangupHandler" Margin="10,10,10,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">Hang up</Button>
28+
<TextBox x:Name="CalleeTextBox" Text="Who would you like to call?" TextWrapping="Wrap" VerticalAlignment="Center" Grid.Row="0" Height="40" Margin="10,10,10,10" />
29+
<StackPanel Orientation="Horizontal">
30+
<Button x:Name="CallButton" Content="Start Call" Click="CallButton_Click" VerticalAlignment="Center" Margin="10,0,0,0" Height="40" Width="200"/>
31+
<Button x:Name="HangupButton" Content="Hang Up" Click="HangupButton_Click" VerticalAlignment="Center" Margin="10,0,0,0" Height="40" Width="200"/>
3132
</StackPanel>
3233
```
3334

34-
### Register Video Handler
35-
36-
An UI component, like XAML's MediaElement, will require the app registering a configuration for rendering local and remote video feeds.
37-
Please add the following content between the `Package` tags of the `Package.appxmanifest`:
38-
39-
```xml
40-
<Extensions>
41-
<Extension Category="windows.activatableClass.inProcessServer">
42-
<InProcessServer>
43-
<Path>RtmMvrUap.dll</Path>
44-
<ActivatableClass ActivatableClassId="VideoN.VideoSchemeHandler" ThreadingModel="both" />
45-
</InProcessServer>
46-
</Extension>
47-
</Extensions>
48-
```
49-
5035
### Setting up the app with Calling SDK APIs
5136

5237
The Calling SDK APIs are in two different namespaces.
5338
The following steps inform the C# compiler about these namespaces allowing Visual Studio's Intellisense to assist with code development.
5439

55-
1. In the `Solution Explorer` panel, click on the arrow on the left side of the file named `MainPage.xaml`.
56-
2. Double click on file named `MainPage.xaml.cs` which showed up.
40+
1. In the `Solution Explorer` panel, click on the arrow on the left side of the file named `MainPage.xaml` for UWP, or `MainWindows.xaml` for WinUI 3.
41+
2. Double click on file named `MainPage.xaml.cs` or `MainWindows.xaml.cs`.
5742
3. Add the following commands at the bottom of the current `using` statements.
5843

5944
```csharp
6045
using Azure.Communication;
6146
using Azure.Communication.Calling;
6247
```
6348

64-
Please keep `MainPage.xaml.cs` open. The next steps will add more code to it.
49+
Please keep `MainPage.xaml.cs` or `MainWindows.xaml.cs` open. The next steps will add more code to it.
6550

6651
## Allow app interactions
6752

68-
The UI buttons previously added need to operate on top of a placed `Call`. It means that a `Call` data member should be added to the `MainPage` class.
53+
The UI buttons previously added need to operate on top of a placed `Call`. It means that a `Call` data member should be added to the `MainPage` or `MainWindow` class.
6954
Additionally, to allow the asynchronous operation creating `CallAgent` to succeed, a `CallAgent` data member should also be added to the same class.
7055

71-
Please add the following data members to the `MainPage` class:
56+
Please add the following data members to the `MainPage` pr `MainWindow` class:
7257
```csharp
73-
CallAgent agent_;
74-
Call call_;
58+
CallAgent callAgent;
59+
Call call;
7560
```
7661

7762
## Create button handlers
@@ -80,12 +65,14 @@ Previously, two UI buttons were added to the XAML code. The following code adds
8065
The following code should be added after the data members from the previous section.
8166

8267
```csharp
83-
private void CallHandler(object sender, RoutedEventArgs e)
68+
private async void CallButton_Click(object sender, RoutedEventArgs e)
8469
{
70+
// Start call
8571
}
8672

87-
private void HangupHandler(object sender, RoutedEventArgs e)
73+
private async void HangupButton_Click(object sender, RoutedEventArgs e)
8874
{
75+
// End the current call
8976
}
9077
```
9178

@@ -108,28 +95,22 @@ To create a `CallAgent` instance from `CallClient` you must use `CallClient.Crea
10895

10996
To create `CallAgent`, you must pass a `CommunicationTokenCredential` object and a `CallAgentOptions` object. Keep in mind that `CommunicationTokenCredential` throws if a malformed token is passed.
11097

111-
The following code should be added inside `CallHandler`.
98+
The following code should be added inside and helper function to be called in app initialization.
11299

113100
```csharp
114-
CallClient client = new CallClient();
115-
CommunicationTokenCredential credentials;
101+
var callClient = new CallClient();
102+
this.deviceManager = await callClient.GetDeviceManager();
116103

117-
CallAgentOptions callAgentOptions = new CallAgentOptions
104+
var tokenCredential = new CommunicationTokenCredential("<AUTHENTICATION_TOKEN>");
105+
var callAgentOptions = new CallAgentOptions()
118106
{
119-
DisplayName = "<CALLER NAME>"
107+
DisplayName = "<DISPLAY_NAME>"
120108
};
121109

122-
try
123-
{
124-
credentials = new CommunicationTokenCredential("<CREDENTIAL TOKEN>");
125-
}
126-
catch (Exception)
127-
{
128-
throw new Exception("Invalid credential token");
129-
}
110+
this.callAgent = await callClient.CreateCallAgent(tokenCredential, callAgentOptions);
130111
```
131112

132-
`<USER ACCESS TOKEN>` must be replaced by a valid credential token for your resource. Refer to the [user access token](../../../../quickstarts/access-tokens.md) documentation if a credential token has to be sourced.
113+
`<AUTHENTICATION_TOKEN>` must be replaced by a valid credential token for your resource. Refer to the [user access token](../../../../quickstarts/access-tokens.md) documentation if a credential token has to be sourced.
133114

134115
## Create CallAgent and place a call
135116

@@ -138,34 +119,27 @@ The objects needed for creating a `CallAgent` are now ready. It is time to async
138119
The following code should be added after handling the exception from the previous step.
139120

140121
```csharp
141-
client.CreateCallAgent(creds, callAgentOptions).Completed +=
142-
async (IAsyncOperation<CallAgent> asyncInfo, AsyncStatus asyncStatus) =>
143-
{
144-
agent_ = asyncInfo.GetResults();
122+
var startCallOptions = new StartCallOptions();
145123

146-
CommunicationUserIdentifier target = new CommunicationUserIdentifier("<CALLEE>");
124+
var callees = new ICommunicationIdentifier[1] { new CommunicationUserIdentifier(CalleeTextBox.Text.Trim()) };
147125

148-
StartCallOptions startCallOptions = new StartCallOptions();
149-
call_ = await agent_.StartCallAsync(new List<ICommunicationIdentifier>() { target }, startCallOptions);
150-
};
126+
this.call = await this.callAgent.StartCallAsync(callees, startCallOptions);
127+
this.call.OnStateChanged += Call_OnStateChangedAsync;
151128
```
152129

153-
Replace `<CALLEE>` with any other identity from your tenant. Alternatively, feel free to use `8:echo123` to talk to the Azure Communication Services echo bot.
130+
Feel free to use `8:echo123` to talk to the Azure Communication Services echo bot.
154131

155132
## End a call
156133

157-
Once a call is placed, the `Hangup` method of the `Call` object should be used to hang up the call.
134+
Once a call is placed, the `HangupAsync` method of the `Call` object should be used to hang up the call.
158135

159136
An instance of `HangupOptions` should also be used to inform if the call must be terminated to all its participants.
160137

161-
The following code should be added inside `HangupHandler`.
138+
The following code should be added inside `HangupButton_Click`.
162139

163140
```csharp
164-
HangUpOptions hangupOptions = new HangUpOptions();
165-
call_.HangUpAsync(hangupOptions).Completed += (IAsyncAction asyncInfo, AsyncStatus asyncStatus) =>
166-
{
167-
168-
};
141+
this.call.OnStateChanged -= Call_OnStateChangedAsync;
142+
await this.call.HangUpAsync(new HangUpOptions());
169143
```
170144

171145
## Run the code

0 commit comments

Comments
 (0)