Skip to content

Commit 9997d61

Browse files
committed
update java samples
1 parent 3c579ec commit 9997d61

File tree

3 files changed

+313
-132
lines changed

3 files changed

+313
-132
lines changed

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

Lines changed: 1 addition & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@ ms.date: 11/19/2021
1111
ms.topic: quickstart
1212
ms.service: azure-communication-services
1313
ms.custom: mode-other
14-
zone_pivot_groups: acs-js-csharp-java-python
14+
zone_pivot_groups: acs-csharp-java
1515
---
1616
# Quickstart: Create and manage a room resource
1717

1818
[!INCLUDE [Private Preview Disclaimer](../../includes/private-preview-include-section.md)]
1919

2020
This quickstart will help you get started with Azure Communication Services Rooms. A `room` is a server-managed communications space for a known, fixed set of participants to collaborate for a pre-determined duration. The [rooms conceptual documentation](../../concepts/rooms/room-concept.md) covers more details and potential use cases for `rooms`.
2121

22-
## Prerequisites
23-
24-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
25-
- An active Communication Services resource and connection string. [Create a Communication Services resource](../create-communication-resource.md).
26-
27-
## Setting up
28-
29-
3022
::: zone pivot="programming-language-csharp"
3123
[!INCLUDE [Send SMS with .NET SDK](./includes/rooms-quickstart-net.md)]
3224
::: zone-end
@@ -35,127 +27,6 @@ This quickstart will help you get started with Azure Communication Services Room
3527
[!INCLUDE [Send SMS with Java SDK](./includes/rooms-quickstart-java.md)]
3628
::: zone-end
3729

38-
39-
### Create a new C# application
40-
41-
In a console window (such as cmd, PowerShell, or Bash), use the `dotnet new` command to create a new console app with the name `RoomsQuickstart`. This command creates a simple "Hello World" C# project with a single source file: **Program.cs**.
42-
43-
```console
44-
dotnet new console -o RoomsQuickstart
45-
```
46-
47-
Change your directory to the newly created app folder and use the `dotnet build` command to compile your application.
48-
49-
```console
50-
cd RoomsQuickstart
51-
dotnet build
52-
```
53-
54-
### Initialize a room client
55-
56-
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).
57-
58-
```csharp
59-
// Find your Communication Services resource in the Azure portal
60-
var connectionString = "<connection_string>";
61-
RoomsClient roomsClient = new RoomsClient(connectionString);
62-
```
63-
64-
### Create a room
65-
66-
Create a new `room` with default properties using the code snippet below:
67-
68-
```csharp
69-
CreateRoomRequest createRoomRequest = new CreateRoomRequest();
70-
Response<CommunicationRoom> createRoomResponse = await roomsClient.CreateRoomAsync(createRoomRequest);
71-
CommunicationRoom createCommunicationRoom = createRoomResponse.Value;
72-
string roomId = createCommunicationRoom.Id;
73-
```
74-
75-
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.
76-
77-
### Get properties of an existing room
78-
79-
Retrieve the details of an existing `room` by referencing the `roomId`:
80-
81-
```csharp
82-
Response<CommunicationRoom> getRoomResponse = await roomsClient.GetRoomAsync(roomId)
83-
CommunicationRoom getCommunicationRoom = getRoomResponse.Value;
84-
```
85-
86-
### Update the lifetime of a room
87-
88-
The lifetime of a `room` can be modified by issuing an update request for the `ValidFrom` and `ValidUntil` parameters.
89-
90-
```csharp
91-
var validFrom = new DateTime(2022, 05, 01, 00, 00, 00, DateTimeKind.Utc);
92-
var validUntil = validFrom.AddDays(1);
93-
94-
UpdateRoomRequest updateRoomRequest = new UpdateRoomRequest();
95-
updateRoomRequest.ValidFrom = validFrom;
96-
updateRoomRequest.ValidUntil = validUntil;
97-
98-
Response<CommunicationRoom> updateRoomResponse = await roomsClient.UpdateRoomAsync(roomId, updateRoomRequest);
99-
CommunicationRoom updateCommunicationRoom = updateRoomResponse.Value;
100-
```
101-
102-
### Add new participants
103-
104-
To add new participants to a `room`, issue an update request on the room's `Participants`:
105-
106-
```csharp
107-
var communicationUser1 = "<CommunicationUserId1>";
108-
var communicationUser2 = "<CommunicationUserId2>";
109-
var communicationUser3 = "<CommunicationUserId3>";
110-
111-
UpdateRoomRequest updateRoomRequest = new UpdateRoomRequest()
112-
updateRoomRequest.Participants.Add(communicationUser1, new RoomParticipant());
113-
updateRoomRequest.Participants.Add(communicationUser2, new RoomParticipant());
114-
updateRoomRequest.Participants.Add(communicationUser3, new RoomParticipant());
115-
116-
Response<CommunicationRoom> updateRoomResponse = await roomsClient.UpdateRoomAsync(roomId, updateRoomRequest);
117-
CommunicationRoom updateCommunicationRoom = updateRoomResponse.Value;
118-
```
119-
120-
Participants that have been added to a `room` become eligible to join calls.
121-
122-
### Remove participants
123-
124-
To remove a participant from a `room` and revoke their access, update the `Participants` list:
125-
126-
```csharp
127-
var communicationUser1 = "<CommunicationUserId1>";
128-
var communicationUser2 = "<CommunicationUserId2>";
129-
var communicationUser3 = "<CommunicationUserId3>";
130-
131-
UpdateRoomRequest updateRoomRequest = new UpdateRoomRequest()
132-
updateRoomRequest.Participants.Add(communicationUser1, null);
133-
updateRoomRequest.Participants.Add(communicationUser2, null);
134-
updateRoomRequest.Participants.Add(communicationUser3, null);
135-
136-
Response<CommunicationRoom> updateRoomResponse = await roomsClient.UpdateRoomAsync(roomId, updateRoomRequest);
137-
CommunicationRoom updateCommunicationRoom = updateRoomResponse.Value;
138-
```
139-
140-
### Join a room call
141-
142-
To join a room call, set up your web application using the [Add voice calling to your client app](../voice-video-calling/getting-started-with-calling.md) guide. Once you have an initialized and authenticated `callAgent`, you may specify a context object with the `roomId` property as the `room` identifier. To join the call, use the `join` method and pass the context instance.
143-
144-
```js
145-
146-
const context = { roomId: '<RoomId>' }
147-
148-
const call = callAgent.join(context);
149-
150-
```
151-
152-
### Delete room
153-
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.
154-
155-
```csharp
156-
Response deleteRoomResponse = await roomsClient.DeleteRoomAsync(roomId)
157-
```
158-
15930
## Object model
16031

16132
The table below lists the main properties of `room` objects:

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

Lines changed: 172 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,174 @@
1+
---
2+
title: include file
3+
description: include file
4+
services: azure-communication-services
5+
author: radubulboaca
6+
manager: mariusu
17

8+
ms.service: azure-communication-services
9+
ms.subservice: azure-communication-services
10+
ms.date: 01/26/2022
11+
ms.topic: include
12+
ms.custom: include file
13+
ms.author: radubulboaca
14+
---
15+
16+
## Prerequisites
17+
18+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
19+
- An active Communication Services resource and connection string. [Create a Communication Services resource](../../create-communication-resource.md).
20+
- Two or more Communication User Identities. [Create and manage access tokens](../../access-tokens.md?pivots=programming-language-csharp) or [Quick-create identities for testing](../../identity/quick-create-identity.md).
21+
- [Java Development Kit (JDK)](https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable) version 8 or above.
22+
- [Apache Maven](https://maven.apache.org/download.cgi)
23+
24+
## Setting up
25+
26+
### Create a new Java application
27+
28+
In a console window (such as cmd, PowerShell, or Bash), use the `mvn` command bellow to create a new console app with the name `rooms-quickstart`. This command creates a simple "Hello World" Java project with a single source file: **App.java**.
29+
30+
```console
31+
mvn archetype:generate -DgroupId=com.contoso.app -DartifactId=rooms-quickstart -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
32+
```
33+
34+
### Include the package
35+
#### Include the BOM file
36+
37+
Include the `azure-sdk-bom` to your project to take dependency on the General Availability (GA) version of the library. In the following snippet, replace the {bom_version_to_target} placeholder with the version number.
38+
To learn more about the BOM, see the [Azure SDK BOM readme](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/boms/azure-sdk-bom/README.md).
39+
40+
```xml
41+
<dependencyManagement>
42+
<dependencies>
43+
<dependency>
44+
<groupId>com.azure</groupId>
45+
<artifactId>azure-sdk-bom</artifactId>
46+
<version>{bom_version_to_target}</version>
47+
<type>pom</type>
48+
<scope>import</scope>
49+
</dependency>
50+
</dependencies>
51+
</dependencyManagement>
52+
```
53+
and then include the direct dependency in the dependencies section without the version tag.
54+
55+
```xml
56+
<dependencies>
57+
<dependency>
58+
<groupId>com.azure</groupId>
59+
<artifactId>azure-communication-rooms</artifactId>
60+
</dependency>
61+
</dependencies>
62+
```
63+
64+
#### Include direct dependency
65+
If you want to take dependency on a particular version of the library that is not present in the BOM,
66+
add the direct dependency to your project as follows.
67+
68+
[//]: # ({x-version-update-start;com.azure:azure-communication-rooms;current})
69+
```xml
70+
<dependency>
71+
<groupId>com.azure</groupId>
72+
<artifactId>azure-communication-rooms</artifactId>
73+
<version>1.0.0-alpha.1</version>
74+
</dependency>
75+
```
76+
77+
### Initialize a room client
78+
79+
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).
80+
81+
```java
82+
// Find your Communication Services resource in the Azure portal
83+
String connectionString = "<connection string>";
84+
RoomsClient roomsClient = new RoomsClientBuilder().connectionString(connectionString).buildClient();
85+
```
86+
87+
### Create a room
88+
89+
Create a new `room` with default properties using the code snippet below:
90+
91+
```java
92+
RoomRequest request = new RoomRequest();
93+
CommunicationRoom createCommunicationRoom = roomsClient.createRoom(request);
94+
String roomId = createCommunicationRoom.getRoomId()
95+
```
96+
97+
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.
98+
99+
### Get properties of an existing room
100+
101+
Retrieve the details of an existing `room` by referencing the `roomId`:
102+
103+
```java
104+
CommunicationRoom roomResult = roomsClient.getRoom(roomId);
105+
```
106+
107+
### Update the lifetime of a room
108+
109+
The lifetime of a `room` can be modified by issuing an update request for the `ValidFrom` and `ValidUntil` parameters.
110+
111+
```java
112+
OffsetDateTime validFrom = OffsetDateTime.of(2022, 2, 1, 5, 30, 20, 10, ZoneOffset.UTC);
113+
OffsetDateTime validUntil = OffsetDateTime.of(2022, 5, 2, 5, 30, 20, 10, ZoneOffset.UTC);
114+
115+
RoomRequest request = new RoomRequest();
116+
request.setValidFrom(validFrom);
117+
request.setValidUntil(validUntil);
118+
119+
CommunicationRoom roomResult = roomsClient.updateRoom(roomId, request);
120+
```
121+
122+
### Add new participants
123+
124+
To add new participants to a `room`, issue an update request on the room's `Participants`:
125+
126+
```java
127+
Map<String, Object> participants = new HashMap<>();
128+
participants.put("<CommunicationUserIdentifier.Id1>", new RoomParticipant());
129+
participants.put("<CommunicationUserIdentifier.Id2>", new RoomParticipant());
130+
participants.put("<CommunicationUserIdentifier.Id3>", new RoomParticipant());
131+
132+
RoomRequest request = new RoomRequest();
133+
request.setParticipants(participants);
134+
135+
CommunicationRoom roomResult = roomsClient.updateRoom(roomId, request);
136+
```
137+
138+
Participants that have been added to a `room` become eligible to join calls.
139+
140+
### Remove participants
141+
142+
To remove a participant from a `room` and revoke their access, update the `Participants` list:
143+
144+
```java
145+
Map<String, Object> participants = new HashMap<>();
146+
participants.put("<CommunicationUserIdentifier.Id1>", null);
147+
participants.put("<CommunicationUserIdentifier.Id2>", null);
148+
participants.put("<CommunicationUserIdentifier.Id3>", null);
149+
150+
RoomRequest request = new RoomRequest();
151+
request.setParticipants(participants);
152+
153+
CommunicationRoom roomResult = roomsClient.updateRoom(roomId, request);
154+
```
155+
156+
### Join a room call
157+
158+
To join a room call, set up your web application using the [Add voice calling to your client app](../../voice-video-calling/getting-started-with-calling.md) guide. Once you have an initialized and authenticated `callAgent`, you may specify a context object with the `roomId` property as the `room` identifier. To join the call, use the `join` method and pass the context instance.
159+
160+
```js
161+
162+
const context = { roomId: '<RoomId>' }
163+
164+
const call = callAgent.join(context);
165+
166+
```
167+
168+
### Delete room
169+
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.
170+
171+
```java
172+
roomsClient.deleteRoomWithResponse(roomId, Context.NONE);
173+
```
2174

3-
## Test Java

0 commit comments

Comments
 (0)