你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

适用于 Java 的 Azure 通信会议室服务客户端库 - 版本 1.0.5

Azure 通信室用于在会议室上运行。

源代码 | 包 (Maven) | API 参考文档 | 产品文档

入门

先决条件

添加包

包括直接依赖项

如果要依赖于 BOM 中不存在的特定库版本,请将直接依赖项添加到项目,如下所示。

<dependency>
  <groupId>com.azure</groupId>
  <artifactId>azure-communication-rooms</artifactId>
  <version>1.0.5</version>
</dependency>

验证客户端

Azure Active Directory 令牌身份验证

DefaultAzureCredential对象必须通过 credential () 函数传递到 RoomsClientBuilder 。 还必须分别通过 endpoint () 和 httpClient () 函数设置终结点和 httpClient。

AZURE_CLIENT_SECRET创建 AZURE_CLIENT_ID DefaultAzureCredential 对象需要 和 AZURE_TENANT_ID 环境变量。

或者,可以使用 connectionString () 函数提供整个连接字符串,而不是提供终结点和访问密钥。

// Find your connection string from your resource in the Azure Portal
String connectionString = "https://<resource-name>.communication.azure.com/;<access-key>";

RoomsClient roomsClient = new RoomsClientBuilder().connectionString(connectionString).buildClient();

关键概念

聊天室

  • 创建会议室
  • 更新会议室
  • 获取空间
  • 删除房间
  • 列出所有会议室

参与者

  • 添加或更新参与者
  • 删除参与者
  • 列出所有参与者

示例

创建新房间

createRoom使用 函数创建新房间。

OffsetDateTime validFrom = OffsetDateTime.now();
OffsetDateTime validUntil = validFrom.plusDays(30);
List<RoomParticipant> participants = new ArrayList<>();

// Add two participants
participant1 = new RoomParticipant(new CommunicationUserIdentifier("<ACS User MRI identity 1>")).setRole(ParticipantRole.ATTENDEE);
participant2 = new RoomParticipant(new CommunicationUserIdentifier("<ACS User MRI identity 2>")).setRole(ParticipantRole.CONSUMER);

participants.add(participant1);
participants.add(participant2);

// Create Room options
CreateRoomOptions roomOptions = new CreateRoomOptions()
        .setValidFrom(validFrom)
        .setValidUntil(validUntil)
        .setParticipants(participants);

CommunicationRoom roomResult = roomsClient.createRoom(roomOptions);

更新现有会议室

updateRoom使用 函数更新现有会议室。

OffsetDateTime validFrom = OffsetDateTime.now();
OffsetDateTime validUntil = validFrom.plusDays(30);

// Update Room options
UpdateRoomOptions updateRoomOptions = new UpdateRoomOptions()
        .setValidFrom(validFrom)
        .setValidUntil(validUntil);

try {
    CommunicationRoom roomResult = roomsClient.updateRoom("<Room Id>", updateRoomOptions);
    System.out.println("Room Id: " + roomResult.getRoomId());
} catch (RuntimeException ex) {
    System.out.println(ex);
}

获取现有会议室

getRoom使用 函数获取现有房间。

try {
    CommunicationRoom roomResult = roomsClient.getRoom("<Room Id>");
    System.out.println("Room Id: " + roomResult.getRoomId());
} catch (RuntimeException ex) {
    System.out.println(ex);
}

删除现有会议室

deleteRoom使用 函数删除创建的房间。

try {
    roomsClient.deleteRoom("<Room Id>");
} catch (RuntimeException ex) {
    System.out.println(ex);
}

列出会议室

list rooms使用 函数列出所有活动会议室。

try {
    PagedIterable<CommunicationRoom> rooms = roomsClient.listRooms();

    for (CommunicationRoom room : rooms) {
        System.out.println("Room ID: " + room.getRoomId());
    }
} catch (Exception ex) {
    System.out.println(ex);
}

添加或更新现有聊天室的参与者

addOrUpdateParticipants使用 函数在现有聊天室中添加或更新参与者。

List<RoomParticipant> participantsToaddOrUpdate = new ArrayList<>();

// New participant to add
RoomParticipant participantToAdd = new RoomParticipant(new CommunicationUserIdentifier("<ACS User MRI identity 3>")).setRole(ParticipantRole.ATTENDEE);

// Existing participant to update, assume participant2 is part of the room as a
// consumer
participant2 = new RoomParticipant(new CommunicationUserIdentifier("<ACS User MRI identity 2>")).setRole(ParticipantRole.ATTENDEE);

participantsToaddOrUpdate.add(participantToAdd); // Adding new participant to room
participantsToaddOrUpdate.add(participant2); // Update participant from Consumer -> Attendee

try {
    AddOrUpdateParticipantsResult addOrUpdateResult = roomsClient.addOrUpdateParticipants("<Room Id>", participantsToaddOrUpdate);
} catch (RuntimeException ex) {
    System.out.println(ex);
}

从现有聊天室中删除参与者

removeParticipants使用 函数从现有聊天室中删除参与者。

List<CommunicationIdentifier> participantsToRemove = new ArrayList<>();

participantsToRemove.add(participant1.getCommunicationIdentifier());
participantsToRemove.add(participant2.getCommunicationIdentifier());

try {
    RemoveParticipantsResult removeResult = roomsClient.removeParticipants("<Room Id>", participantsToRemove);
} catch (RuntimeException ex) {
    System.out.println(ex);
}

列出现有聊天室中的所有参与者

listParticipants使用 函数列出现有聊天室中的所有参与者。

try {
    PagedIterable<RoomParticipant> allParticipants = roomsClient.listParticipants("<Room Id>");
    for (RoomParticipant participant : allParticipants) {
        System.out.println(participant.getCommunicationIdentifier().getRawId() + " (" + participant.getRole() + ")");
    }
} catch (RuntimeException ex) {
    System.out.println(ex);
}

疑难解答

  1. 如果创建客户端失败,请验证是否具有正确的身份验证。
  2. 对于聊天室创建失败,在大多数情况下,通信错误应简要说明问题。

后续步骤

贡献

本项目欢迎贡献和建议。 大多数贡献要求你同意贡献者许可协议 (CLA),并声明你有权(并且确实有权)授予我们使用你的贡献的权利。

提交拉取请求时,CLA 机器人将自动确定你是否需要提供 CLA,并相应地修饰 PR(例如标签、注释)。 直接按机器人提供的说明操作。 只需使用 CLA 对所有存储库执行一次这样的操作。

此项目采用了 Microsoft 开放源代码行为准则。 有关详细信息,请参阅行为准则常见问题解答,或如果有任何其他问题或意见,请与 联系。

曝光数