Skip to content

Commit b79974c

Browse files
authored
Merge pull request #235326 from minnieliu/peiliu/updateNetRoomsQuickstart
Update the Rooms Quickstart for .Net SDK
2 parents dcf56fa + c078cd6 commit b79974c

File tree

1 file changed

+85
-58
lines changed

1 file changed

+85
-58
lines changed

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

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
title: include file
33
description: include file
44
services: azure-communication-services
5-
author: radubulboaca
6-
manager: mariusu
5+
author: peiliu
6+
manager: alexokun
77

88
ms.service: azure-communication-services
99
ms.subservice: azure-communication-services
10-
ms.date: 09/08/2022
10+
ms.date: 04/20/2023
1111
ms.topic: include
1212
ms.custom: include file
13-
ms.author: antonsamson
13+
ms.author: peiliu
1414
---
1515

1616
## Prerequisites
@@ -48,7 +48,7 @@ Install the Azure Communication Rooms client library for .NET with [NuGet][https
4848
dotnet add package Azure.Communication.Identity
4949
dotnet add package Azure.Communication.Rooms
5050
```
51-
You'll need to use the Azure Communication Rooms client library for .NET [version 1.0.0-beta.1](https://www.nuget.org/packages/Azure.Communication.Rooms/1.0.0-beta.1) or above.
51+
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.
5252

5353
### Set up the app framework
5454

@@ -86,11 +86,11 @@ Create a new `RoomsClient` object that will be used to create new `rooms` and ma
8686
var connectionString = "<connection_string>";
8787
RoomsClient roomsClient = new RoomsClient(connectionString);
8888

89-
// create identities for users
90-
var client = new CommunicationIdentityClient(connectionString);
91-
var user1 = await client.CreateUserAndTokenAsync(scopes: new[] { CommunicationTokenScope.VoIP });
92-
var user2 = await client.CreateUserAndTokenAsync(scopes: new[] { CommunicationTokenScope.VoIP });
93-
89+
// Create identities for users
90+
CommunicationIdentityClient identityClient = new CommunicationIdentityClient(connectionString);
91+
CommunicationUserIdentifier user1 = await identityClient.CreateUser();
92+
CommunicationUserIdentifier user2 = await identityClient.CreateUser();
93+
9494
```
9595

9696
## Create a room
@@ -99,11 +99,24 @@ Create a new `room` with default properties using the code snippet below:
9999

100100
```csharp
101101

102-
//Create a room
102+
// Create a room
103103
List roomParticipants = new List<RoomParticipant>();
104104
roomParticipants.Add(new RoomParticipant(new CommunicationUserIdentifier(user1.Value.User.Id), RoleType.Presenter));
105105

106-
CommunicationRoom createdRoom = await RoomCollection.CreateRoomAsync(validFrom, validUntil, RoomJoinPolicy.InviteOnly, roomParticipants, cancellationToken);
106+
107+
RoomParticipant participant1 = new RoomParticipant(user1) { Role = ParticipantRole.Presenter };
108+
RoomParticipant participant2 = new RoomParticipant(user2) { Role = ParticipantRole.Attendee };
109+
110+
List<RoomParticipant> participants = new List<RoomParticipant>();
111+
112+
participants.Add(participant1);
113+
participants.Add(participant2);
114+
115+
DateTimeOffset validFrom = DateTimeOffset.UtcNow;
116+
DateTimeOffset validUntil = validFrom.AddDays(1);
117+
CancellationToken cancellationToken = new CancellationTokenSource().Token;
118+
119+
CommunicationRoom createdRoom = await roomsClient.CreateRoomAsync(validFrom, validUntil, roomParticipants, cancellationToken);
107120
string roomId = createdRoom.Id;
108121
Console.WriteLine("\nCreated room with id: " + roomId);
109122

@@ -118,8 +131,8 @@ Retrieve the details of an existing `room` by referencing the `roomId`:
118131
```csharp
119132

120133
// Retrieve the room with corresponding ID
121-
CommunicationRoom getRoomResponse = await roomsClient.GetRoomAsync(roomId);
122-
Console.WriteLine("\Retrieved room with id: " + getRoomResponse.Id);
134+
CommunicationRoom room = await roomsClient.GetRoomAsync(roomId);
135+
Console.WriteLine("\Retrieved room with id: " + room.Id);
123136

124137
```
125138

@@ -129,30 +142,53 @@ The lifetime of a `room` can be modified by issuing an update request for the `V
129142

130143
```csharp
131144

132-
//Update room lifetime
133-
DateTimeOffset validFrom = new DateTime(2022, 05, 01, 00, 00, 00, DateTimeKind.Utc);
134-
DateTimeOffset validUntil = validFrom.AddDays(1);
135-
136-
CommunicationRoom updatedRoom = await RoomCollection.UpdateRoomAsync(roomId, validFrom, validUntil, RoomJoinPolicy.InviteOnly, null, cancellationToken);
145+
// Update room lifetime
146+
DateTimeOffset validFrom = DateTimeOffset.UtcNow;
147+
DateTimeOffset validUntil = DateTimeOffset.UtcNow.AddDays(10);
148+
CommunicationRoom updatedRoom = await roomsClient.UpdateRoomAsync(roomId, validFrom, validUntil, cancellationToken);
137149
Console.WriteLine("\nUpdated room with validFrom: " + updatedRoom.ValidFrom + " and validUntil: " + updatedRoom.ValidUntil);
150+
```
151+
152+
### List all active rooms
153+
154+
To retrieve all active rooms, use the `GetRoomsAsync` method exposed on the client.
155+
156+
```csharp
157+
158+
// List all active rooms
159+
AsyncPageable<CommunicationRoom> allRooms = await roomsClient.GetRoomsAsync();
160+
await foreach (CommunicationRoom room in allRooms)
161+
{
162+
if (room is not null)
163+
{
164+
Console.WriteLine("\nFirst room id in all active rooms: " + room.Id);
165+
break;
166+
}
167+
}
138168

139169
```
140170

141-
## Add new participants
171+
### Add new participants or update existing participants
142172

143173
To add new participants to a `room`, use the `AddParticipantsAsync` method exposed on the client.
144174

145175
```csharp
146176

147-
// Add participants
148177
List<RoomParticipant> participants = new List<RoomParticipant>();
149-
participants.Add(new RoomParticipant(new CommunicationUserIdentifier(user2.Value.User.Id), RoleType.Attendee));
178+
// Update participant2 from Attendee to Consumer
179+
RoomParticipant participant2 = new RoomParticipant(user2) { Role = ParticipantRole.Consumer };
180+
// Add participant3
181+
CommunicationUserIdentifier user3 = await identityClient.CreateUser();
182+
RoomParticipant participant3 = new RoomParticipant(user3) { Role = ParticipantRole.Attendee };
183+
participants.Add(participant2);
184+
participants.Add(participant3);
185+
186+
Response addOrUpdateParticipantsResponse = await roomsClient.AddOrUpdateParticipantsAsync(roomId, participants);
187+
Console.WriteLine("\nAdded or updated participants to room");
150188

151-
var addParticipantsResult = await RoomCollection.AddParticipantsAsync(roomId, participants);
152-
Console.writeLine("\nAdded participants to room");
153189
```
154190

155-
Participants that have been added to a `room` become eligible to join calls.
191+
Participants that have been added to a `room` become eligible to join calls. Participants that have been updated will see their new `role` in the call.
156192

157193
## Get list of participants
158194

@@ -161,8 +197,12 @@ Retrieve the list of participants for an existing `room` by referencing the `roo
161197
```csharp
162198

163199
// Get list of participants in room
164-
ParticipantsCollection existingParticipants = await RoomCollection.GetParticipantsAsync(roomId);
165-
Console.writeLine("\nRetrieved participants for room: ", existingParticipants);
200+
AsyncPageable<RoomParticipant> existingParticipants = await roomsClient.GetParticipantsAsync(roomId);
201+
Console.WriteLine("\nRetrieved participants from room: ");
202+
await foreach (RoomParticipant participant in existingParticipants)
203+
{
204+
Console.WriteLine($"{participant.CommunicationIdentifier.ToString()}, {participant.Role.ToString()}");
205+
}
166206

167207
```
168208

@@ -171,14 +211,12 @@ Console.writeLine("\nRetrieved participants for room: ", existingParticipants);
171211
To remove a participant from a `room` and revoke their access, use the `RemoveParticipantsAsync` method.
172212

173213
```csharp
174-
// Remove user from room
175-
var communicationUser = user2.Value.User.Id;
176214

215+
// Remove user from room
177216
List<CommunicationIdentifier> participants = new List<CommunicationIdentifier>();
178-
participants.Add(new CommunicationUserIdentifier(communicationUser));
217+
participants.Add(user2);
179218

180-
var removeParticipantsResult = await RoomCollection.RemoveParticipantsAsync(roomId, participants);
181-
await roomsClient.removeParticipants(roomId, removeParticipantsList);
219+
Response removeParticipantsResponse = await roomsClient.RemoveParticipantsAsync(roomId, participants);
182220
Console.WriteLine("\nRemoved participants from room");
183221

184222
```
@@ -189,14 +227,13 @@ If you wish to disband an existing `room`, you may issue an explicit delete requ
189227
```csharp
190228

191229
// Deletes the specified room
192-
Response deleteRoomResponse = await RoomCollection.DeleteRoomAsync(createdRoomId);
193-
Console.WriteLine("\nDeleted room with id: " + createdRoomId);
194-
230+
Response deleteRoomResponse = await RoomCollection.DeleteRoomAsync(roomId);
231+
Console.WriteLine("\nDeleted room with id:" + roomId);
195232
```
196233

197234
## Run the code
198235

199-
To run the code, make sure you are on the directory where your `Program.cs` file is.
236+
To run the code, make sure you are on the directory where your `Program.cs` file is.
200237

201238
```console
202239

@@ -210,37 +247,27 @@ The expected output describes each completed action:
210247

211248
Azure Communication Services - Rooms Quickstart
212249

213-
Created a room with id: 99445276259151407
250+
Created a room with id: 99445276259151407
251+
252+
Retrieved room with id: 99445276259151407
214253

215-
Retrieved room with id: 99445276259151407
254+
Updated room with validFrom: 2023-05-11T22:11:46.784Z and validUntil: 2023-05-21T22:16:46.784Z
216255

217-
Updated room with validFrom: 2023-05-11T22:11:46.784Z and validUntil: 2023-05-11T22:16:46.784Z
256+
First room id in all active rooms: 99445276259151407
218257

219-
Added participants to room
258+
Added or updated participants to room
220259

221-
Retrieved participants for room: [
222-
{
223-
id: {
224-
kind: 'communicationUser',
225-
communicationUserId: '8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-ac89-7c76-35f3-343a0d00e901'
226-
},
227-
role: 'Attendee'
228-
},
229-
{
230-
id: {
231-
kind: 'communicationUser',
232-
communicationUserId: '8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-ac89-7ccc-35f3-343a0d00e902'
233-
},
234-
role: 'Consumer'
235-
}
236-
]
260+
Retrieved participants from room:
261+
8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-ac89-7c76-35f3-343a0d00e901, Presenter
262+
8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-f00d-aa4b-0cf9-9c3a0d00543e, Consumer
263+
8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-f00d-aaf2-0cf9-9c3a0d00543f, Attendee
237264

238265
Removed participants from room
239266

240-
Deleted room with id: 99445276259151407
267+
Deleted room with id: 99445276259151407
241268

242269
```
243270

244271
## Reference documentation
245272

246-
Read about the full set of capabilities of Azure Communication Services rooms from the [.NET SDK reference](/dotnet/api/azure.communication.rooms) or [REST API reference](/rest/api/communication/rooms).
273+
Read about the full set of capabilities of Azure Communication Services re [.NET SDK reference](/dotnet/api/azure.communication.rooms) or [REST API reference](/rest/api/communication/rooms).

0 commit comments

Comments
 (0)