@@ -87,9 +87,9 @@ var connectionString = "<connection_string>";
87
87
RoomsClient roomsClient = new RoomsClient (connectionString );
88
88
89
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 } );
90
+ CommunicationIdentityClient identityClient = new CommunicationIdentityClient (connectionString );
91
+ CommunicationUserIdentifier user1 = await identityClient . CreateUser ( );
92
+ CommunicationUserIdentifier user2 = await identityClient . CreateUser ( );
93
93
94
94
```
95
95
@@ -104,8 +104,8 @@ List roomParticipants = new List<RoomParticipant>();
104
104
roomParticipants .Add (new RoomParticipant (new CommunicationUserIdentifier (user1 .Value .User .Id ), RoleType .Presenter ));
105
105
106
106
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 };
109
109
110
110
List < RoomParticipant > participants = new List <RoomParticipant >();
111
111
@@ -116,7 +116,7 @@ DateTimeOffset validFrom = DateTimeOffset.UtcNow;
116
116
DateTimeOffset validUntil = validFrom .AddDays (1 );
117
117
CancellationToken cancellationToken = new CancellationTokenSource ().Token ;
118
118
119
- CommunicationRoom createdRoom = await roomsClient .CreateRoomAsync (validFrom , validUntil , participants , cancellationToken );
119
+ CommunicationRoom createdRoom = await roomsClient .CreateRoomAsync (validFrom , validUntil , roomParticipants , cancellationToken );
120
120
string roomId = createdRoom .Id ;
121
121
Console .WriteLine (" \n Created room with id: " + roomId );
122
122
@@ -131,8 +131,8 @@ Retrieve the details of an existing `room` by referencing the `roomId`:
131
131
``` csharp
132
132
133
133
// Retrieve the room with corresponding ID
134
- CommunicationRoom getRoomResponse = await roomsClient .GetRoomAsync (roomId );
135
- 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 );
136
136
137
137
```
138
138
@@ -143,33 +143,47 @@ The lifetime of a `room` can be modified by issuing an update request for the `V
143
143
``` csharp
144
144
145
145
// 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 );
149
148
CommunicationRoom updatedRoom = await roomsClient .UpdateRoomAsync (roomId , validFrom , validUntil , cancellationToken );
150
149
Console .WriteLine (" \n Updated room with validFrom: " + updatedRoom .ValidFrom + " and validUntil: " + updatedRoom .ValidUntil );
151
150
```
152
151
153
- ### List all created rooms
152
+ ### List all valid rooms
154
153
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.
156
155
157
156
``` 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 (" \n First room id in all valid rooms: " + room .Id );
163
+ break ;
164
+ }
165
+ }
166
+
160
167
```
161
168
162
169
### Add new participants or update existing participants
163
170
164
171
To add new participants to a ` room ` , use the ` AddParticipantsAsync ` method exposed on the client.
165
172
166
173
``` csharp
167
- // Add participants
174
+
168
175
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 );
171
183
172
184
Response addOrUpdateParticipantsResponse = await roomsClient .AddOrUpdateParticipantsAsync (roomId , participants );
185
+ Console .WriteLine (" \n Added or updated participants to room" );
186
+
173
187
```
174
188
175
189
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
181
195
``` csharp
182
196
// Get list of participants in room
183
197
AsyncPageable < RoomParticipant > existingParticipants = await roomsClient .GetParticipantsAsync (roomId );
184
- List < RoomParticipant > existingParticipantsList = await allParticipants .ToEnumerableAsync ();
198
+ Console .WriteLine (" \n Retrieved participants from room: " );
199
+ await foreach (RoomParticipant participant in existingParticipants )
200
+ {
201
+ Console .WriteLine ($" {participant .CommunicationIdentifier .ToString ()}, {participant .Role .ToString ()}" );
202
+ }
185
203
```
186
204
187
205
## Remove participants
@@ -190,10 +208,8 @@ To remove a participant from a `room` and revoke their access, use the `RemovePa
190
208
191
209
``` csharp
192
210
// Remove user from room
193
- var communicationUser = user2 .Value .User .Id ;
194
-
195
211
List < CommunicationIdentifier > participants = new List <CommunicationIdentifier >();
196
- participants .Add (new CommunicationUserIdentifier ( communicationUser ) );
212
+ participants .Add (user2 );
197
213
198
214
Response removeParticipantsResponse = await roomsClient .RemoveParticipantsAsync (roomId , participants );
199
215
await roomsClient .removeParticipants (roomId , removeParticipantsList );
@@ -207,7 +223,8 @@ If you wish to disband an existing `room`, you may issue an explicit delete requ
207
223
``` csharp
208
224
209
225
// Deletes the specified room
210
- Response deleteRoomResponse = await RoomCollection .DeleteRoomAsync (createdRoomId );
226
+ Response deleteRoomResponse = await RoomCollection .DeleteRoomAsync (roomId );
227
+ Console .WriteLine (" \n Deleted room with id:" + roomId );
211
228
```
212
229
213
230
## Run the code
@@ -226,38 +243,27 @@ The expected output describes each completed action:
226
243
227
244
Azure Communication Services - Rooms Quickstart
228
245
229
- Created a room with id: 99445276259151407
246
+ Created a room with id: 99445276259151407
247
+
248
+ Retrieved room with id: 99445276259151407
230
249
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
232
251
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
234
253
235
- Added participants to room
254
+ Added or updated participants to room
236
255
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
253
260
254
261
Removed participants from room
255
262
256
- Deleted room with id: 99445276259151407
263
+ Deleted room with id: 99445276259151407
257
264
258
265
```
259
266
260
267
## Reference documentation
261
268
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