Skip to content

Commit 4797462

Browse files
authored
Merge pull request #210557 from antonsamson-msft/quickstarts
Update sample code in `rooms` quick start documentation
2 parents 4bb2b07 + 111f6f0 commit 4797462

File tree

4 files changed

+93
-111
lines changed

4 files changed

+93
-111
lines changed

articles/communication-services/quickstarts/rooms/get-started-rooms.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ services: azure-communication-services
66
author: radubulboaca
77
manager: mariusu
88

9-
ms.author: radubulboaca
10-
ms.date: 07/27/2022
9+
ms.author: antonsamson
10+
ms.date: 09/01/2022
1111
ms.topic: quickstart
1212
ms.service: azure-communication-services
1313
ms.custom: mode-other
@@ -28,11 +28,11 @@ This quickstart will help you get started with Azure Communication Services Room
2828
::: zone-end
2929

3030
::: zone pivot="programming-language-python"
31-
[!INCLUDE [Use rooms with Java SDK](./includes/rooms-quickstart-python.md)]
31+
[!INCLUDE [Use rooms with Python SDK](./includes/rooms-quickstart-python.md)]
3232
::: zone-end
3333

3434
::: zone pivot="programming-language-javascript"
35-
[!INCLUDE [Use rooms with Java SDK](./includes/rooms-quickstart-javascript.md)]
35+
[!INCLUDE [Use rooms with JavaScript SDK](./includes/rooms-quickstart-javascript.md)]
3636
::: zone-end
3737

3838
## Object model

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

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ manager: mariusu
77

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

1616
## Prerequisites
@@ -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-javascript.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ manager: mariusu
77

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

1616
## Prerequisites
@@ -44,9 +44,8 @@ npm init -y
4444
Use the `npm install` command to install the below Communication Services SDKs for JavaScript.
4545

4646
```console
47-
npm install @azure/communication-common --save
47+
npm install @azure/communication-rooms --save
4848
npm install @azure/communication-identity --save
49-
npm install @azure/communication-signaling --save
5049
```
5150

5251
### Initialize a room client
@@ -71,12 +70,25 @@ const roomsClient = new RoomsClient(connectionString);
7170
Create a new `room` with default properties using the code snippet below:
7271

7372
```javascript
73+
// options payload to create a room
74+
const createRoomOptions = {
75+
validFrom: validFrom,
76+
validUntil: validUntil,
77+
roomJoinPolicy: "InviteOnly",
78+
participants: [
79+
{
80+
id: user1.user,
81+
role: "Attendee",
82+
},
83+
]
84+
};
85+
7486
// create a room with the request payload
75-
const createRoom = await roomsClient.createRoom(createRoomRequest);
87+
const createRoom = await roomsClient.createRoom(createRoomOptions);
7688
const roomId = createRoom.id;
7789
```
7890

79-
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.
91+
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.
8092

8193
### Get properties of an existing room
8294

@@ -85,49 +97,43 @@ Retrieve the details of an existing `room` by referencing the `roomId`:
8597
```javascript
8698
// retrieves the room with corresponding ID
8799
const getRoom = await roomsClient.getRoom(roomId);
88-
console.log(`Retrieved Room with ID ${roomId}`);
89100
```
90101

91102
### Update the lifetime of a room
92103

93-
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.
104+
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.
94105

95106
```javascript
96107
validFrom.setTime(validUntil.getTime());
97108
validUntil.setTime(validFrom.getTime() + 5 * 60 * 1000);
98109

99110
// request payload to update a room
100-
const updateRoomRequest = {
101-
validFrom: validFrom,
102-
validUntil: validUntil,
103-
roomJoinPolicy: "CommunicationServiceUsers",
104-
participants: [
105-
new RoomParticipant(user1.user, "Consumer"),
106-
new RoomParticipant(user2.user, "Presenter"),
107-
],
111+
const updateRoomOptions = {
112+
validFrom: validFrom,
113+
validUntil: validUntil
108114
};
109115

110116
// updates the specified room with the request payload
111-
const updateRoom = await roomsClient.updateRoom(roomId, updateRoomRequest);
112-
```
117+
const updateRoom = await roomsClient.updateRoom(roomId, updateRoomOptions);
118+
```
113119

114-
### Add new participants
120+
### Add new participants
115121

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

118124
```javascript
119125
// request payload to add participants
120-
const addParticipantsRequest = {
126+
const addParticipantsList = {
121127
participants: [
122128
{
123-
id: user1.user,
129+
id: user2.user,
124130
role: "Consumer",
125131
},
126132
],
127133
};
128134

129135
// add user2 to the room with the request payload
130-
const addParticipants = await roomsClient.addParticipants(roomId, addParticipantsRequest);
136+
const addParticipants = await roomsClient.addParticipants(roomId, addParticipantsList);
131137
```
132138

133139
Participants that have been added to a `room` become eligible to join calls.
@@ -146,12 +152,12 @@ To remove a participant from a `room` and revoke their access, use the `removePa
146152

147153
```javascript
148154
// request payload to delete both users from the room
149-
const removeParticipantsRequest = {
155+
const removeParticipantsList = {
150156
participants: [user1.user, user2.user],
151157
};
152158

153159
// remove both users from the room with the request payload
154-
await roomsClient.removeParticipants(roomId, removeParticipantsRequest);
160+
await roomsClient.removeParticipants(roomId, removeParticipantsList);
155161
```
156162

157163
### Delete room

0 commit comments

Comments
 (0)