Share via


.NET 用 Azure Communication Rooms クライアント ライブラリ - バージョン 1.0.0

このパッケージには、Azure Communication Servicesの Rooms サービス用の C# SDK が含まれています。 Azure Communication Services (ACS) Rooms は、Contoso サーバー アプリケーションが一連の API を使用して、一定の有効期間と参加者のセットを持つサーバー管理の会話空間を作成し、(スケジュールされた会議の作成など) 通信できるユーザーとタイミングの両方のサーバー層からルールを事前に定義します。

ACS Rooms の一般提供リリースにより、Contoso は次のことが可能になります。

- Create a meeting space with known time coordinates (validFrom/validUntil)
- Join voice/video calls within that meeting space using the ACS web calling SDK or native mobile calling SDKs
- Add participants to a room
- Assign pre-defined roles to room participants

会議室を最適に使用できるメインシナリオ:

- Virtual Visits (e.g., telemedicine, remote financial advisor, virtual classroom, etc...)
- Virtual Events (e.g., live event, company all-hands, live concert, etc...)

ソースコード | 製品ドキュメント | サンプル

作業の開始

パッケージをインストールする

NuGet を使用して .NET 用の Azure Communication Rooms クライアント ライブラリをインストールします。

dotnet add package Azure.Communication.Rooms

前提条件

このパッケージを使用するには、 Azure サブスクリプションCommunication Service リソース が必要です。

新しい Communication Service を作成するには、Azure PortalAzure PowerShell、または .NET 管理クライアント ライブラリを使用できます。

主要な概念

RoomsClient には、会議室の作成、会議室の更新、会議室の取得、会議室の一覧表示、会議室の削除、参加者の追加、参加者の更新、参加者の削除、参加者の一覧表示を行う機能が用意されています。

ステートメントの使用

using Azure.Communication.Rooms

クライアントを認証する

会議室クライアントは、 Azure Portal の Azure Communication Resource から取得した接続文字列を使用して認証できます。

var connectionString = Environment.GetEnvironmentVariable("connection_string") // Find your Communication Services resource in the Azure portal
RoomsClient client = new RoomsClient(connectionString);

ルームを作成する

ルームを作成するには、 から RoomsClientまたは CreateRoomAsync 関数をCreateRoom呼び出します。 、validFromvalidUntil、および participants の各引数はすべて省略可能です。 と が指定されていない場合validFrom、 の既定値validFromは現在の日付時刻で、 の既定値validUntilは ですvalidFrom + 180 daysvalidUntil を定義するときに RoomParticipant、role が指定されていない場合 Attendee は、既定でになります。 返される値には、 Response<CommunicationRoom> 作成された会議室の詳細と、エラーが発生した場合の状態と関連するエラー コードが含まれます。

// Create communication users using the CommunicationIdentityClient
Response<CommunicationUserIdentifier> communicationUser1 = await communicationIdentityClient.CreateUserAsync();
Response<CommunicationUserIdentifier> communicationUser2 = await communicationIdentityClient.CreateUserAsync();

DateTimeOffset validFrom = DateTimeOffset.UtcNow;
DateTimeOffset validUntil = validFrom.AddDays(1);
RoomParticipant participant1 = new RoomParticipant(communicationUser1.Value); // If role is not provided, then it is set as Attendee by default
RoomParticipant participant2 = new RoomParticipant(communicationUser2.Value) { Role = ParticipantRole.Presenter};
List<RoomParticipant> invitedParticipants = new List<RoomParticipant>
{
    participant1,
    participant2
};

Response<CommunicationRoom> createRoomResponse = await roomsClient.CreateRoomAsync(validFrom, validUntil, invitedParticipants);
CommunicationRoom createCommunicationRoom = createRoomResponse.Value;

会議室を更新する

作成されたルームの プロパティと プロパティはvalidFrom、 から RoomsClientまたは UpdateRoomAsync 関数をUpdateRoom呼び出すことによって更新validUntilできます。

validUntil = validFrom.AddDays(30);
Response<CommunicationRoom> updateRoomResponse = await roomsClient.UpdateRoomAsync(createdRoomId, validFrom, validUntil);
CommunicationRoom updateCommunicationRoom = updateRoomResponse.Value;

作成された会議室を取得する

作成されたルームは、 から または GetRoomAsync 関数RoomsClientGetRoom呼び出し、関連付けられた roomIdを渡すことによって取得できます。

Response<CommunicationRoom> getRoomResponse = await roomsClient.GetRoomAsync(createdRoomId);
CommunicationRoom getCommunicationRoom = getRoomResponse.Value;

すべての部屋を取得する

ACS リソースの下に作成されたすべての有効な会議室は、 または GetRoomsAsync 関数を GetRooms からRoomsClient呼び出すことによって取得できます。

AsyncPageable<CommunicationRoom> allRooms = roomsClient.GetRoomsAsync();
await foreach (CommunicationRoom room in allRooms)
{
    Console.WriteLine($"Room with id {room.Id} is valid from {room.ValidFrom} to {room.ValidUntil}.");
}

[ルームを削除]

会議室を削除するには、RoomsClient から または DeleteRoomAsync 関数をDeleteRoom呼び出します。

Response deleteRoomResponse = await roomsClient.DeleteRoomAsync(createdRoomId);

会議室の参加者を追加または更新する

新しい参加者を追加したり、既存の参加者を更新したりするには、RoomsClient から または AddOrUpdateParticipantsAsync 関数をAddOrUpdateParticipants呼び出します。

Response<CommunicationUserIdentifier> communicationUser3 = await communicationIdentityClient.CreateUserAsync();
RoomParticipant newParticipant = new RoomParticipant(communicationUser3.Value) { Role = ParticipantRole.Consumer };

// Previous snippet for create room added participant2 as Presenter
participant2 = new RoomParticipant(communicationUser2) { Role = ParticipantRole.Attendee };

List<RoomParticipant> participantsToAddOrUpdate = new List<RoomParticipant>
{
    participant2,   // participant2 updated from Presenter to Attendee
    newParticipant, // newParticipant added to the room
};

Response addOrUpdateParticipantResponse = await roomsClient.AddOrUpdateParticipantsAsync(createdRoomId, participantsToAddOrUpdate);

会議室の参加者を削除する

会議室から参加者を削除するには、RoomsClient から または RemoveParticipantsAsync 関数をRemoveParticipants呼び出します。

List<CommunicationIdentifier> participantsToRemove = new List<CommunicationIdentifier>
{
   communicationUser1,
   communicationUser2
};
Response removeParticipantResponse = await roomsClient.RemoveParticipantsAsync(createdRoomId, participantsToRemove);

会議室の参加者を取得する

会議室からすべての参加者を取得するには、RoomsClient から または GetParticipantsAsync 関数をGetParticipants呼び出します。 戻り値は または Pageable<RoomParticipant>AsyncPageable<RoomParticipant> で、参加者のページ分割されたリストが含まれます。

AsyncPageable<RoomParticipant> allParticipants = roomsClient.GetParticipantsAsync(createdRoomId);
await foreach (RoomParticipant participant in allParticipants)
{
    Console.WriteLine($" Participant with id {participant.CommunicationIdentifier.RawId} is a {participant.Role}");
}

トラブルシューティング

サービス応答

RequestFailedExceptionは、失敗した要求に対するサービス応答としてスローされます。 例外には、サービスから返された応答コードに関する情報が含まれています。

try
{
    CommunicationIdentityClient communicationIdentityClient = CreateInstrumentedCommunicationIdentityClient();
    Response<CommunicationUserIdentifier> communicationUser1 = await communicationIdentityClient.CreateUserAsync();
    Response<CommunicationUserIdentifier> communicationUser2 = await communicationIdentityClient.CreateUserAsync();
    DateTimeOffset validFrom = DateTimeOffset.UtcNow;
    DateTimeOffset validUntil = validFrom.AddDays(1);
    List<RoomParticipant> createRoomParticipants = new List<RoomParticipant>();
    RoomParticipant participant1 = new RoomParticipant(communicationUser1.Value) { Role = ParticipantRole.Presenter };
    RoomParticipant participant2 = new RoomParticipant(communicationUser2.Value) { Role = ParticipantRole.Attendee };
    Response<CommunicationRoom> createRoomResponse = await roomsClient.CreateRoomAsync(validFrom, validUntil, createRoomParticipants);
    CommunicationRoom createRoomResult = createRoomResponse.Value;
}
catch (RequestFailedException ex)
{
    Console.WriteLine(ex.Message);
}

次のステップ

共同作成

このプロジェクトでは、共同作成と提案を歓迎しています。 ほとんどの共同作成では、共同作成者使用許諾契約書 (CLA) にご同意いただき、ご自身の共同作成内容を使用する権利を Microsoft に供与する権利をお持ちであり、かつ実際に供与することを宣言していただく必要があります。 詳細については、「 cla.microsoft.com」を参照してください。

このプロジェクトでは、Microsoft オープン ソースの倫理規定を採用しています。 詳しくは、「Code of Conduct FAQ (倫理規定についてよくある質問)」を参照するか、opencode@microsoft.com 宛てに質問またはコメントをお送りください。

SDK の発行後にサンプル コード リンクを更新する