2
2
title : include file
3
3
description : include file
4
4
services : azure-communication-services
5
- author : radubulboaca
6
- manager : mariusu
5
+ author : peiliu
6
+ manager : alexokun
7
7
8
8
ms.service : azure-communication-services
9
9
ms.subservice : azure-communication-services
10
- ms.date : 09/08/2022
10
+ ms.date : 04/20/2023
11
11
ms.topic : include
12
12
ms.custom : include file
13
- ms.author : antonsamson
13
+ ms.author : peiliu
14
14
---
15
15
16
16
## Prerequisites
@@ -48,7 +48,7 @@ Install the Azure Communication Rooms client library for .NET with [NuGet][https
48
48
dotnet add package Azure.Communication.Identity
49
49
dotnet add package Azure.Communication.Rooms
50
50
```
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.
52
52
53
53
### Set up the app framework
54
54
@@ -86,11 +86,11 @@ Create a new `RoomsClient` object that will be used to create new `rooms` and ma
86
86
var connectionString = " <connection_string>" ;
87
87
RoomsClient roomsClient = new RoomsClient (connectionString );
88
88
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
+
94
94
```
95
95
96
96
## Create a room
@@ -99,11 +99,24 @@ Create a new `room` with default properties using the code snippet below:
99
99
100
100
``` csharp
101
101
102
- // Create a room
102
+ // Create a room
103
103
List roomParticipants = new List <RoomParticipant >();
104
104
roomParticipants .Add (new RoomParticipant (new CommunicationUserIdentifier (user1 .Value .User .Id ), RoleType .Presenter ));
105
105
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 );
107
120
string roomId = createdRoom .Id ;
108
121
Console .WriteLine (" \n Created room with id: " + roomId );
109
122
@@ -118,8 +131,8 @@ Retrieve the details of an existing `room` by referencing the `roomId`:
118
131
``` csharp
119
132
120
133
// Retrieve the room with corresponding ID
121
- CommunicationRoom getRoomResponse = await roomsClient .GetRoomAsync (roomId );
122
- Console .WriteLine (" \R etrieved room with id: " + getRoomResponse .Id );
134
+ CommunicationRoom room = await roomsClient .GetRoomAsync (roomId );
135
+ Console .WriteLine (" \R etrieved room with id: " + room .Id );
123
136
124
137
```
125
138
@@ -129,30 +142,53 @@ The lifetime of a `room` can be modified by issuing an update request for the `V
129
142
130
143
``` csharp
131
144
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 );
137
149
Console .WriteLine (" \n Updated 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 (" \n First room id in all active rooms: " + room .Id );
165
+ break ;
166
+ }
167
+ }
138
168
139
169
```
140
170
141
- ## Add new participants
171
+ ### Add new participants or update existing participants
142
172
143
173
To add new participants to a ` room ` , use the ` AddParticipantsAsync ` method exposed on the client.
144
174
145
175
``` csharp
146
176
147
- // Add participants
148
177
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 (" \n Added or updated participants to room" );
150
188
151
- var addParticipantsResult = await RoomCollection .AddParticipantsAsync (roomId , participants );
152
- Console .writeLine (" \n Added participants to room" );
153
189
```
154
190
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.
156
192
157
193
## Get list of participants
158
194
@@ -161,8 +197,12 @@ Retrieve the list of participants for an existing `room` by referencing the `roo
161
197
``` csharp
162
198
163
199
// Get list of participants in room
164
- ParticipantsCollection existingParticipants = await RoomCollection .GetParticipantsAsync (roomId );
165
- Console .writeLine (" \n Retrieved participants for room: " , existingParticipants );
200
+ AsyncPageable < RoomParticipant > existingParticipants = await roomsClient .GetParticipantsAsync (roomId );
201
+ Console .WriteLine (" \n Retrieved participants from room: " );
202
+ await foreach (RoomParticipant participant in existingParticipants )
203
+ {
204
+ Console .WriteLine ($" {participant .CommunicationIdentifier .ToString ()}, {participant .Role .ToString ()}" );
205
+ }
166
206
167
207
```
168
208
@@ -171,14 +211,12 @@ Console.writeLine("\nRetrieved participants for room: ", existingParticipants);
171
211
To remove a participant from a ` room ` and revoke their access, use the ` RemoveParticipantsAsync ` method.
172
212
173
213
``` csharp
174
- // Remove user from room
175
- var communicationUser = user2 .Value .User .Id ;
176
214
215
+ // Remove user from room
177
216
List < CommunicationIdentifier > participants = new List <CommunicationIdentifier >();
178
- participants .Add (new CommunicationUserIdentifier ( communicationUser ) );
217
+ participants .Add (user2 );
179
218
180
- var removeParticipantsResult = await RoomCollection .RemoveParticipantsAsync (roomId , participants );
181
- await roomsClient .removeParticipants (roomId , removeParticipantsList );
219
+ Response removeParticipantsResponse = await roomsClient .RemoveParticipantsAsync (roomId , participants );
182
220
Console .WriteLine (" \n Removed participants from room" );
183
221
184
222
```
@@ -189,14 +227,13 @@ If you wish to disband an existing `room`, you may issue an explicit delete requ
189
227
``` csharp
190
228
191
229
// Deletes the specified room
192
- Response deleteRoomResponse = await RoomCollection .DeleteRoomAsync (createdRoomId );
193
- Console .WriteLine (" \n Deleted room with id: " + createdRoomId );
194
-
230
+ Response deleteRoomResponse = await RoomCollection .DeleteRoomAsync (roomId );
231
+ Console .WriteLine (" \n Deleted room with id:" + roomId );
195
232
```
196
233
197
234
## Run the code
198
235
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.
200
237
201
238
``` console
202
239
@@ -210,37 +247,27 @@ The expected output describes each completed action:
210
247
211
248
Azure Communication Services - Rooms Quickstart
212
249
213
- Created a room with id: 99445276259151407
250
+ Created a room with id: 99445276259151407
251
+
252
+ Retrieved room with id: 99445276259151407
214
253
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
216
255
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
218
257
219
- Added participants to room
258
+ Added or updated participants to room
220
259
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
237
264
238
265
Removed participants from room
239
266
240
- Deleted room with id: 99445276259151407
267
+ Deleted room with id: 99445276259151407
241
268
242
269
```
243
270
244
271
## Reference documentation
245
272
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