Skip to content

Commit 7444bb3

Browse files
Update Java and .NET code samples
1 parent 6d933da commit 7444bb3

File tree

2 files changed

+56
-80
lines changed

2 files changed

+56
-80
lines changed

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

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,36 @@ Create a new `RoomsClient` object that will be used to create new `rooms` and ma
8686
// Find your Communication Services resource in the Azure portal
8787
String connectionString = "<connection string>";
8888
RoomsClient roomsClient = new RoomsClientBuilder().connectionString(connectionString).buildClient();
89+
90+
// Set communication user id
91+
static String USER_ID_1 = "<communication-user-id-1>";
92+
static String USER_ID_2 = "<communication-user-id-2>";
93+
static String USER_ID_3 = "<communication-user-id-3>";
8994
```
9095

9196
### Create a room
9297

9398
Create a new `room` with default properties using the code snippet below:
9499

95100
```java
96-
OffsetDateTime validFrom = OffsetDateTime.of(2022, 8, 1, 5, 30, 20, 10, ZoneOffset.UTC);
97-
OffsetDateTime validUntil = OffsetDateTime.of(2022, 9, 1, 5, 30, 20, 10, ZoneOffset.UTC);
98-
List<RoomParticipant> participants = new ArrayList<>();
101+
OffsetDateTime validFrom = OffsetDateTime.now();
102+
OffsetDateTime validUntil = validFrom.plusDays(30);
103+
RoomJoinPolicy roomJoinPolicy = RoomJoinPolicy.INVITE_ONLY;
104+
105+
List<RoomParticipant> roomParticipants = new ArrayList<RoomParticipant>();
99106

100-
// Add participants
101-
participants.add(new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 1>")).setRole(RoleType.ATTENDEE));
102-
participants.add(new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 2>")).setRole(RoleType.CONSUMER));
103-
participants.add(new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 3>")).setRole(RoleType.ATTENDEE));
107+
roomParticipants.add(new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier(USER_ID_1)).setRole(RoleType.CONSUMER));
108+
roomParticipants.add(new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier(USER_ID_2)).setRole(RoleType.ATTENDEE));
104109

105-
RoomsClient roomsClient = createRoomsClientWithConnectionString();
106-
CommunicationRoom roomResult = roomsClient.createRoom(validFrom, validUntil, RoomJoinPolicy.INVITE_ONLY, participants);
110+
return roomsClient.createRoom(
111+
validFrom,
112+
validUntil,
113+
roomJoinPolicy,
114+
roomParticipants
115+
);
107116
```
108117

109-
Since `rooms` are server-side entities, you may want to keep track of and persist the `roomId` in the storage medium of choice. You can reference the `roomId` to view or update the properties of a `room` object.
118+
Since `rooms` are server-side entities, you may want to keep track of and persist the `roomId` in the storage medium of choice. You can reference the `roomId` to view or update the properties of a `room` object.
110119

111120
### Get properties of an existing room
112121

@@ -118,37 +127,22 @@ CommunicationRoom roomResult = roomsClient.getRoom(roomId);
118127

119128
### Update the lifetime of a room
120129

121-
The lifetime of a `room` can be modified by issuing an update request for the `ValidFrom` and `ValidUntil` parameters. A room can be valid for a maximum of six months.
130+
The lifetime of a `room` can be modified by issuing an update request for the `ValidFrom` and `ValidUntil` parameters. A room can be valid for a maximum of six months.
122131

123132
```java
124-
OffsetDateTime validFrom = OffsetDateTime.of(2022, 2, 1, 5, 30, 20, 10, ZoneOffset.UTC);
125-
OffsetDateTime validUntil = OffsetDateTime.of(2022, 5, 2, 5, 30, 20, 10, ZoneOffset.UTC);
133+
OffsetDateTime validFrom = OffsetDateTime.now().plusDays(1);
134+
OffsetDateTime validUntil = validFrom.plusDays(1);
126135

127-
RoomRequest request = new RoomRequest();
128-
request.setValidFrom(validFrom);
129-
request.setValidUntil(validUntil);
130-
131-
CommunicationRoom roomResult = roomsClient.updateRoom(roomId, request);
136+
CommunicationRoom roomResult = roomsClient.updateRoom(roomId, validFrom, validUntil);
132137
```
133138

134-
### Add new participants
139+
### Add new participants
135140

136141
To add new participants to a `room`, use the `addParticipants` method exposed on the client.
137142

138143
```java
139-
RoomParticipant user1 = new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 1>")).setRole(RoleType.ATTENDEE);
140-
RoomParticipant user2 = new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 2>")).setRole(RoleType.PRESENTER);
141-
RoomParticipant user3 = new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 3>")).setRole(RoleType.CONSUMER);
142-
143-
List<RoomParticipant> participants = new ArrayList<RoomParticipant>(Arrays.asList(user1, user2, user3));
144-
RoomsClient roomsClient = createRoomsClientWithConnectionString();
145-
146-
try {
147-
ParticipantsCollection roomParticipants = roomsClient.addParticipants("<Room Id>", participants);
148-
System.out.println("No. of Participants in Room: " + roomParticipants.getParticipants().size());
149-
} catch (RuntimeException ex) {
150-
System.out.println(ex);
151-
}
144+
RoomParticipant newParticipant = new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier(USER_ID_3)).setRole(RoleType.CONSUMER);
145+
ParticipantsCollection updatedParticipants = roomsClient.addParticipants(roomId, List.of(newParticipant));
152146
```
153147

154148
Participants that have been added to a `room` become eligible to join calls.
@@ -159,8 +153,8 @@ Retrieve the list of participants for an existing `room` by referencing the `roo
159153

160154
```java
161155
try {
162-
ParticipantsCollection participants = roomsClient.listParticipants(roomId);
163-
System.out.println("Participants: \n" + participants.getParticipants());
156+
ParticipantsCollection participants = roomsClient.getParticipants(roomId);
157+
System.out.println("Participants: \n" + listParticipantsAsString(participants.getParticipants()));
164158
} catch (Exception ex) {
165159
System.out.println(ex);
166160
}
@@ -171,22 +165,13 @@ try {
171165
To remove a participant from a `room` and revoke their access, use the `removeParticipants` method.
172166

173167
```java
174-
RoomParticipant user1 = new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 1>")).setRole(RoleType.ATTENDEE);
175-
RoomParticipant user2 = new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier("<ACS User MRI identity 2>")).setRole(RoleType.PRESENTER);
176-
177-
List<RoomParticipant> participants = new ArrayList<RoomParticipant>(Arrays.asList(user1, user2));
178-
RoomsClient roomsClient = createRoomsClientWithConnectionString();
179-
180-
try {
181-
ParticipantsCollection roomParticipants = roomsClient.removeParticipants("<Room Id>", participants);
182-
System.out.println("Room Id: " + roomParticipants.getParticipants().size());
183-
} catch (RuntimeException ex) {
184-
System.out.println(ex);
185-
}
168+
RoomParticipant existingParticipant = new RoomParticipant().setCommunicationIdentifier(new CommunicationUserIdentifier(USER_ID_1));
169+
ParticipantsCollection updatedParticipants = roomsClient.removeParticipants(roomId, List.of(existingParticipant));
186170
```
187171

188172
### Delete room
189-
If you wish to disband an existing `room`, you may issue an explicit delete request. All `rooms` and their associated resources are automatically deleted at the end of their validity plus a grace period.
173+
174+
If you wish to disband an existing `room`, you may issue an explicit delete request. All `rooms` and their associated resources are automatically deleted at the end of their validity plus a grace period.
190175

191176
```java
192177
roomsClient.deleteRoomWithResponse(roomId, Context.NONE);

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

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,56 +47,50 @@ Install the Azure Communication Rooms client library for .NET with [NuGet][https
4747

4848
```console
4949
dotnet add package Azure.Communication.Rooms
50-
```
50+
```
5151

5252
### Initialize a room client
5353

5454
Create a new `RoomsClient` object that will be used to create new `rooms` and manage their properties and lifecycle. The connection string of your `Communications Service` will be used to authenticate the request. For more information on connection strings, see [this page](../../create-communication-resource.md#access-your-connection-strings-and-service-endpoints).
5555

5656
```csharp
5757
// Find your Communication Services resource in the Azure portal
58-
var connectionString = "<connection_string>";
59-
RoomsClient roomsClient = new RoomsClient(connectionString);
58+
var connectionString = "<connection_string>";
59+
RoomsClient roomsCollection = new RoomsClient(connectionString);
6060
```
6161

6262
### Create a room
6363

6464
Create a new `room` with default properties using the code snippet below:
6565

6666
```csharp
67-
RoomRequest request = new RoomRequest();
68-
Response<RoomModel> createRoomResponse = await roomsClient.CreateRoomAsync(validFrom, validUntil, RoomJoinPolicy.InviteOnly, participants);
69-
RoomModel createCommunicationRoom = createRoomResponse.Value;
67+
CommunicationRoom createdRoom = await RoomCollection.CreateRoomAsync(validFrom, validUntil, RoomJoinPolicy.InviteOnly, roomParticipants, cancellationToken);
68+
string roomId = createdRoom.Id;
7069
```
7170

72-
Since `rooms` are server-side entities, you may want to keep track of and persist the `roomId` in the storage medium of choice. You can reference the `roomId` to view or update the properties of a `room` object.
71+
Since `rooms` are server-side entities, you may want to keep track of and persist the `roomId` in the storage medium of choice. You can reference the `roomId` to view or update the properties of a `room` object.
7372

7473
### Get properties of an existing room
7574

7675
Retrieve the details of an existing `room` by referencing the `roomId`:
7776

7877
```csharp
79-
Response<RoomModel> getRoomResponse = await roomsClient.GetRoomAsync(createdRoomId)
80-
RoomModel getCommunicationRoom = getRoomResponse.Value;
78+
CommunicationRoom getRoomResponse = await roomsClient.GetRoomAsync(roomId);
8179
```
8280

8381
### Update the lifetime of a room
8482

85-
The lifetime of a `room` can be modified by issuing an update request for the `ValidFrom` and `ValidUntil` parameters. A room can be valid for a maximum of six months.
83+
The lifetime of a `room` can be modified by issuing an update request for the `ValidFrom` and `ValidUntil` parameters. A room can be valid for a maximum of six months.
8684

8785
```csharp
88-
var validFrom = new DateTime(2022, 05, 01, 00, 00, 00, DateTimeKind.Utc);
89-
var validUntil = validFrom.AddDays(1);
86+
DateTimeOffset validFrom = new DateTime(2022, 05, 01, 00, 00, 00, DateTimeKind.Utc);
87+
DateTimeOffset validUntil = validFrom.AddDays(1);
9088

91-
UpdateRoomRequest updateRoomRequest = new UpdateRoomRequest();
92-
updateRoomRequest.ValidFrom = validFrom;
93-
updateRoomRequest.ValidUntil = validUntil;
89+
CommunicationRoom updatedRoom = await RoomCollection.UpdateRoomAsync(roomId, validFrom, validUntil, RoomJoinPolicy.InviteOnly, null, cancellationToken);
9490

95-
Response<CommunicationRoom> updateRoomResponse = await roomsClient.UpdateRoomAsync(roomId, updateRoomRequest);
96-
CommunicationRoom updateCommunicationRoom = updateRoomResponse.Value;
97-
```
91+
```
9892

99-
### Add new participants
93+
### Add new participants
10094

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

@@ -105,13 +99,12 @@ var communicationUser1 = "<CommunicationUserId1>";
10599
var communicationUser2 = "<CommunicationUserId2>";
106100
var communicationUser3 = "<CommunicationUserId3>";
107101

108-
List<RoomParticipant> toAddCommunicationUsers = new List<RoomParticipant>();
109-
toAddCommunicationUsers.Add(new RoomParticipant(new CommunicationUserIdentifier(communicationUser1), "Presenter"));
110-
toAddCommunicationUsers.Add(new RoomParticipant(new CommunicationUserIdentifier(communicationUser2), "Attendee"));
111-
toAddCommunicationUsers.Add(new RoomParticipant(new CommunicationUserIdentifier(communicationUser3), "Attendee"));
102+
List<RoomParticipant> participants = new List<RoomParticipant>();
103+
participants.Add(new RoomParticipant(new CommunicationUserIdentifier(communicationUser1), "Presenter"));
104+
participants.Add(new RoomParticipant(new CommunicationUserIdentifier(communicationUser2), "Attendee"));
105+
participants.Add(new RoomParticipant(new CommunicationUserIdentifier(communicationUser3), "Attendee"));
112106

113-
Response<RoomModel> addParticipantResponse = await roomsClient.AddParticipantsAsync(createdRoomId, toAddCommunicationUsers);
114-
ParticipantsCollection addedParticipantsRoom = addParticipantResponse.Value;
107+
var addParticipantsResult = await RoomCollection.AddParticipantsAsync(roomId, participants);
115108
```
116109

117110
Participants that have been added to a `room` become eligible to join calls.
@@ -121,8 +114,7 @@ Participants that have been added to a `room` become eligible to join calls.
121114
Retrieve the list of participants for an existing `room` by referencing the `roomId`:
122115

123116
```csharp
124-
Response<ParticipantsCollection> getParticipantsResponse = await roomsClient.GetParticipantsAsync(roomId);
125-
ParticipantsCollection roomParticipants = getParticipantsResponse.Value;
117+
ParticipantsCollection existingParticipants = await RoomCollection.GetParticipantsAsync(roomId);
126118
```
127119

128120
### Remove participants
@@ -132,18 +124,17 @@ To remove a participant from a `room` and revoke their access, use the `RemovePa
132124
```csharp
133125
var communicationUser = "<CommunicationUserId1>";
134126

135-
List<CommunicationIdentifier> toRemoveCommunicationUsers = new List<CommunicationIdentifier>();
136-
toRemoveCommunicationUsers.Add(new CommunicationUserIdentifier(communicationUser));
127+
List<CommunicationIdentifier> participants = new List<CommunicationIdentifier>();
128+
participants.Add(new CommunicationUserIdentifier(communicationUser));
137129

138-
Response<RoomModel> removeParticipantResponse = await roomsClient.RemoveParticipantsAsync(createdRoomId, toRemoveCommunicationUsers);
139-
ParticipantsCollection removeParticipantsRoom = removeParticipantResponse.Value;
130+
var removeParticipantsResult = await RoomCollection.RemoveParticipantsAsync(roomId, participants);
140131
```
141132

142133
### Delete room
143-
If you wish to disband an existing `room`, you may issue an explicit delete request. All `rooms` and their associated resources are automatically deleted at the end of their validity plus a grace period.
134+
If you wish to disband an existing `room`, you may issue an explicit delete request. All `rooms` and their associated resources are automatically deleted at the end of their validity plus a grace period.
144135

145136
```csharp
146-
Response deleteRoomResponse = await roomsClient.DeleteRoomAsync(createdRoomId);
137+
Response deleteRoomResponse = await RoomCollection.DeleteRoomAsync(createdRoomId);
147138
```
148139

149140
## Reference documentation

0 commit comments

Comments
 (0)