Skip to content

Commit 2fd00fb

Browse files
Merge pull request #239661 from minnieliu/peiliu/quickFixOnDotNetQuickstart
Quick fixes on .Net Rooms Quickstart
2 parents c555261 + f8151da commit 2fd00fb

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

articles/communication-services/quickstarts/rooms/includes/rooms-quickstart-net.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ dotnet build
4545
Install the Azure Communication Rooms client library for .NET with [NuGet][https://www.nuget.org/]:
4646

4747
```console
48-
dotnet add package Azure.Communication.Identity
4948
dotnet add package Azure.Communication.Rooms
5049
```
5150
You'll need to use the Azure Communication Rooms client library for .NET [version 1.0.0-beta.2](https://www.nuget.org/packages/Azure.Communication.Rooms/1.0.0-beta.2) or above.
@@ -59,7 +58,7 @@ In the `Program.cs` file, add the following code to import the required namespac
5958
using System;
6059
using Azure;
6160
using Azure.Core;
62-
using Azure.Communication.Identity;
61+
using Azure.Communication.Rooms;
6362

6463
namespace RoomsQuickstart
6564
{
@@ -86,37 +85,55 @@ Create a new `RoomsClient` object that will be used to create new `rooms` and ma
8685
var connectionString = "<connection_string>";
8786
RoomsClient roomsClient = new RoomsClient(connectionString);
8887

89-
// Create identities for users
90-
CommunicationIdentityClient identityClient = new CommunicationIdentityClient(connectionString);
91-
CommunicationUserIdentifier user1 = await identityClient.CreateUser();
92-
CommunicationUserIdentifier user2 = await identityClient.CreateUser();
93-
9488
```
9589

9690
## Create a room
9791

98-
Create a new `room` with default properties using the code snippet below:
92+
### Set up room participants
9993

100-
```csharp
94+
In order to set up who can join a room, you'll need to have the list of the identities of those users. You can follow the instructions [here](../../identity/access-tokens.md?pivots=programming-language-csharp) for creating users and issuing access tokens. Alternatively, if you want to create the users on demand, you can create them using the `CommunicationIdentityClient`.
10195

102-
// Create a room
103-
List roomParticipants = new List<RoomParticipant>();
104-
roomParticipants.Add(new RoomParticipant(new CommunicationUserIdentifier(user1.Value.User.Id), RoleType.Presenter));
96+
To use the `CommunicationIdentityClient`, install the following package:
10597

98+
```console
99+
dotnet add package Azure.Communication.Identity
100+
```
106101

107-
RoomParticipant participant1 = new RoomParticipant(user1) { Role = ParticipantRole.Presenter };
108-
RoomParticipant participant2 = new RoomParticipant(user2) { Role = ParticipantRole.Attendee };
102+
Also, import the namespace of the package at the top of your `Program.cs` file:
109103

110-
List<RoomParticipant> participants = new List<RoomParticipant>();
104+
``` csharp
105+
using Azure.Communication.Identity;
106+
```
111107

112-
participants.Add(participant1);
113-
participants.Add(participant2);
108+
Now, the `CommunicationIdentityClient` can be initialized and used to create users:
109+
110+
```csharp
111+
// Create identities for users who will join the room
112+
CommunicationIdentityClient identityClient = new CommunicationIdentityClient(connectionString);
113+
CommunicationUserIdentifier user1 = await identityClient.CreateUser();
114+
CommunicationUserIdentifier user2 = await identityClient.CreateUser();
115+
```
116+
117+
Then, create the list of room participants by referencing those users:
118+
119+
```csharp
120+
List<RoomParticipant> participants = new List<RoomParticipant>()
121+
{
122+
new RoomParticipant(user1) { Role = ParticipantRole.Presenter },
123+
new RoomParticipant(user2) // The default participant role is ParticipantRole.Attendee
124+
}
125+
```
126+
127+
### Initialize the room
128+
Create a new `room` using the `participants` defined in the code snippet above:
114129

130+
```csharp
131+
// Create a room
115132
DateTimeOffset validFrom = DateTimeOffset.UtcNow;
116133
DateTimeOffset validUntil = validFrom.AddDays(1);
117134
CancellationToken cancellationToken = new CancellationTokenSource().Token;
118135

119-
CommunicationRoom createdRoom = await roomsClient.CreateRoomAsync(validFrom, validUntil, roomParticipants, cancellationToken);
136+
CommunicationRoom createdRoom = await roomsClient.CreateRoomAsync(validFrom, validUntil, participants, cancellationToken);
120137
string roomId = createdRoom.Id;
121138
Console.WriteLine("\nCreated room with id: " + roomId);
122139

@@ -156,14 +173,11 @@ To retrieve all active rooms, use the `GetRoomsAsync` method exposed on the clie
156173
```csharp
157174

158175
// List all active rooms
159-
AsyncPageable<CommunicationRoom> allRooms = await roomsClient.GetRoomsAsync();
176+
AsyncPageable<CommunicationRoom> allRooms = roomsClient.GetRoomsAsync();
160177
await foreach (CommunicationRoom room in allRooms)
161178
{
162-
if (room is not null)
163-
{
164-
Console.WriteLine("\nFirst room id in all active rooms: " + room.Id);
165-
break;
166-
}
179+
Console.WriteLine("\nFirst room id in all active rooms: " + room.Id);
180+
break;
167181
}
168182

169183
```

articles/communication-services/quickstarts/rooms/join-rooms-call.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ zone_pivot_groups: acs-web-ios-android
2626
- A room resource. [Create and manage rooms](get-started-rooms.md)
2727

2828
## Obtain user access token
29+
If you have already created users and have added them as participants in the room following the "Set up room participants" section in [this page](./get-started-rooms.md), then you can directly use those users to join the room.
2930

30-
You'll need to create a User Access Token for each call participant. [Learn how to create and manage user access tokens](../identity/access-tokens.md). You can also use the Azure CLI and run the command below with your connection string to create a user and an access token.
31+
Otherwise, you'll need to create a User Access Token for each call participant. [Learn how to create and manage user access tokens](../identity/access-tokens.md). You can also use the Azure CLI and run the command below with your connection string to create a user and an access token. After the users have been created, you'll need to add them to the room as participants before they can join the room.
3132

3233
```azurecli-interactive
3334
az communication identity token issue --scope voip --connection-string "yourConnectionString"
@@ -86,7 +87,7 @@ For details, see [Use Azure CLI to Create and Manage Access Tokens](../identity/
8687
[!INCLUDE [Join a room call from Android calling SDK](./includes/rooms-quickstart-call-android.md)]
8788
::: zone-end
8889

89-
## Next steps
90+
## Next steps
9091

9192
In this section you learned how to:
9293
> [!div class="checklist"]

0 commit comments

Comments
 (0)