|
| 1 | +--- |
| 2 | +title: include file |
| 3 | +description: include file |
| 4 | +services: azure-communication-services |
| 5 | +author: radubulboaca |
| 6 | +manager: mariusu |
1 | 7 |
|
| 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 | +``` |
2 | 174 |
|
3 |
| -## Test Java |
|
0 commit comments