Skip to content

Commit 6d933da

Browse files
Update JS code samples
1 parent af51244 commit 6d933da

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

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-msft
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)