Skip to content

Commit f2a748a

Browse files
author
Minnie Liu
committed
Update snippets
1 parent f56b63a commit f2a748a

File tree

1 file changed

+52
-46
lines changed

1 file changed

+52
-46
lines changed

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

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ var connectionString = "<connection_string>";
8787
RoomsClient roomsClient = new RoomsClient(connectionString);
8888

8989
// 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 });
90+
CommunicationIdentityClient identityClient = new CommunicationIdentityClient(connectionString);
91+
CommunicationUserIdentifier user1 = await identityClient.CreateUser();
92+
CommunicationUserIdentifier user2 = await identityClient.CreateUser();
9393

9494
```
9595

@@ -104,8 +104,8 @@ List roomParticipants = new List<RoomParticipant>();
104104
roomParticipants.Add(new RoomParticipant(new CommunicationUserIdentifier(user1.Value.User.Id), RoleType.Presenter));
105105

106106

107-
RoomParticipant participant1 = new RoomParticipant(new CommunicationIdentifier("<CommunicationUserId1>")) { Role = ParticipantRole.Presenter };
108-
RoomParticipant participant2 = new RoomParticipant(new CommunicationIdentifier("<CommunicationUserId2>")) { Role = ParticipantRole.Attendee };
107+
RoomParticipant participant1 = new RoomParticipant(user1) { Role = ParticipantRole.Presenter };
108+
RoomParticipant participant2 = new RoomParticipant(user2) { Role = ParticipantRole.Attendee };
109109

110110
List<RoomParticipant> participants = new List<RoomParticipant>();
111111

@@ -116,7 +116,7 @@ DateTimeOffset validFrom = DateTimeOffset.UtcNow;
116116
DateTimeOffset validUntil = validFrom.AddDays(1);
117117
CancellationToken cancellationToken = new CancellationTokenSource().Token;
118118

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

@@ -131,8 +131,8 @@ Retrieve the details of an existing `room` by referencing the `roomId`:
131131
```csharp
132132

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

137137
```
138138

@@ -143,33 +143,47 @@ The lifetime of a `room` can be modified by issuing an update request for the `V
143143
```csharp
144144

145145
//Update room lifetime
146-
DateTimeOffset validFrom = new DateTime(2022, 05, 01, 00, 00, 00, DateTimeKind.Utc);
147-
DateTimeOffset validUntil = validFrom.AddDays(1);
148-
146+
DateTimeOffset validFrom = DateTimeOffset.UtcNow;
147+
DateTimeOffset validUntil = DateTimeOffset.UtcNow.AddDays(10);
149148
CommunicationRoom updatedRoom = await roomsClient.UpdateRoomAsync(roomId, validFrom, validUntil, cancellationToken);
150149
Console.WriteLine("\nUpdated room with validFrom: " + updatedRoom.ValidFrom + " and validUntil: " + updatedRoom.ValidUntil);
151150
```
152151

153-
### List all created rooms
152+
### List all valid rooms
154153

155-
To retrieve all created rooms, use the `GetRoomsAsync` method exposed on the client.
154+
To retrieve all valid rooms, use the `GetRoomsAsync` method exposed on the client.
156155

157156
```csharp
158-
AsyncPageable<CommunicationRoom> allCreatedRooms = await roomsClient.GetRoomsAsync();
159-
List<CommunicationRoom> allCreatedRoomsList = await allParticipants.ToEnumerableAsync();
157+
AsyncPageable<CommunicationRoom> allRooms = await roomsClient.GetRoomsAsync();
158+
await foreach (CommunicationRoom room in allRooms)
159+
{
160+
if (room is not null)
161+
{
162+
Console.WriteLine("\nFirst room id in all valid rooms: " + room.Id);
163+
break;
164+
}
165+
}
166+
160167
```
161168

162169
### Add new participants or update existing participants
163170

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

166173
```csharp
167-
// Add participants
174+
168175
List<RoomParticipant> participants = new List<RoomParticipant>();
169-
RoomParticipant participant2 = new RoomParticipant(new CommunicationIdentifier("<CommunicationUserId2>")) { Role = ParticipantRole.Consumer }; // Update participant2 from Attendee to Consumer
170-
RoomParticipant participant3 = new RoomParticipant(new CommunicationIdentifier("<CommunicationUserId3>")) { Role = ParticipantRole.Attendee }; // Add participant3
176+
// Update participant2 from Attendee to Consumer
177+
RoomParticipant participant2 = new RoomParticipant(user2) { Role = ParticipantRole.Consumer };
178+
// Add participant3
179+
CommunicationUserIdentifier user3 = await identityClient.CreateUser();
180+
RoomParticipant participant3 = new RoomParticipant(user3) { Role = ParticipantRole.Attendee };
181+
participants.Add(participant2);
182+
participants.Add(participant3);
171183

172184
Response addOrUpdateParticipantsResponse = await roomsClient.AddOrUpdateParticipantsAsync(roomId, participants);
185+
Console.WriteLine("\nAdded or updated participants to room");
186+
173187
```
174188

175189
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.
@@ -181,7 +195,11 @@ Retrieve the list of participants for an existing `room` by referencing the `roo
181195
```csharp
182196
// Get list of participants in room
183197
AsyncPageable<RoomParticipant> existingParticipants = await roomsClient.GetParticipantsAsync(roomId);
184-
List<RoomParticipant> existingParticipantsList = await allParticipants.ToEnumerableAsync();
198+
Console.WriteLine("\nRetrieved participants from room: ");
199+
await foreach (RoomParticipant participant in existingParticipants)
200+
{
201+
Console.WriteLine($"{participant.CommunicationIdentifier.ToString()}, {participant.Role.ToString()}");
202+
}
185203
```
186204

187205
## Remove participants
@@ -190,10 +208,8 @@ To remove a participant from a `room` and revoke their access, use the `RemovePa
190208

191209
```csharp
192210
// Remove user from room
193-
var communicationUser = user2.Value.User.Id;
194-
195211
List<CommunicationIdentifier> participants = new List<CommunicationIdentifier>();
196-
participants.Add(new CommunicationUserIdentifier(communicationUser));
212+
participants.Add(user2);
197213

198214
Response removeParticipantsResponse = await roomsClient.RemoveParticipantsAsync(roomId, participants);
199215
await roomsClient.removeParticipants(roomId, removeParticipantsList);
@@ -207,7 +223,8 @@ If you wish to disband an existing `room`, you may issue an explicit delete requ
207223
```csharp
208224

209225
// Deletes the specified room
210-
Response deleteRoomResponse = await RoomCollection.DeleteRoomAsync(createdRoomId);
226+
Response deleteRoomResponse = await RoomCollection.DeleteRoomAsync(roomId);
227+
Console.WriteLine("\nDeleted room with id:" + roomId);
211228
```
212229

213230
## Run the code
@@ -226,38 +243,27 @@ The expected output describes each completed action:
226243

227244
Azure Communication Services - Rooms Quickstart
228245

229-
Created a room with id: 99445276259151407
246+
Created a room with id: 99445276259151407
247+
248+
Retrieved room with id: 99445276259151407
230249

231-
Retrieved room with id: 99445276259151407
250+
Updated room with validFrom: 2023-05-11T22:11:46.784Z and validUntil: 2023-05-21T22:16:46.784Z
232251

233-
Updated room with validFrom: 2023-05-11T22:11:46.784Z and validUntil: 2023-05-11T22:16:46.784Z
252+
First room id in all valid rooms: 99445276259151407
234253

235-
Added participants to room
254+
Added or updated participants to room
236255

237-
Retrieved participants for room: [
238-
{
239-
id: {
240-
kind: 'communicationUser',
241-
communicationUserId: '8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-ac89-7c76-35f3-343a0d00e901'
242-
},
243-
role: 'Attendee'
244-
},
245-
{
246-
id: {
247-
kind: 'communicationUser',
248-
communicationUserId: '8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-ac89-7ccc-35f3-343a0d00e902'
249-
},
250-
role: 'Consumer'
251-
}
252-
]
256+
Retrieved participants from room:
257+
8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-ac89-7c76-35f3-343a0d00e901, Presenter
258+
8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-f00d-aa4b-0cf9-9c3a0d00543e, Consumer
259+
8:acs:b6aada1f-0b1d-47ac-866f-91aae00a1d01_00000018-f00d-aaf2-0cf9-9c3a0d00543f, Attendee
253260

254261
Removed participants from room
255262

256-
Deleted room with id: 99445276259151407
263+
Deleted room with id: 99445276259151407
257264

258265
```
259266

260267
## Reference documentation
261268

262-
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).
263-
ooms from th
269+
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)