Azure Communication Rooms-Clientbibliothek für .NET – Version 1.0.0

Dieses Paket enthält ein C#-SDK für den Rooms Service von Azure Communication Services. Azure Communication Services -Räume (ACS) ist eine Gruppe von APIs, die von Contoso-Serveranwendungen verwendet werden, um einen serverseitig verwalteten Konversationsbereich mit festen Gruppen von Lebensdauer und Teilnehmern zu erstellen, wobei Regeln von der Serverebene vordefiniert werden, sowohl wer als auch wann kommunizieren kann (z. B. geplante Besprechungserstellung).

Mit der allgemeinen Verfügbarkeit von ACS-Räumen kann Contoso Folgendes ausführen:

- 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

Die Standard Szenarien, in denen Räume am besten verwendet werden können:

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

Quellcode | Produktdokumentation | Proben

Erste Schritte

Installieren des Pakets

Installieren Sie die Azure Communication Rooms-Clientbibliothek für .NET mit NuGet:

dotnet add package Azure.Communication.Rooms

Voraussetzungen

Sie benötigen ein Azure-Abonnement und eine Communication Service-Ressource , um dieses Paket verwenden zu können.

Um einen neuen Communication Service zu erstellen, können Sie das Azure-Portal, die Azure PowerShell oder die .NET-Verwaltungsclientbibliothek verwenden.

Wichtige Begriffe

RoomsClient bietet die Funktionalität zum Erstellen eines Raums, Zum Aktualisieren des Raums, zum Abrufen von Raum, zum Auflisten von Räumen, zum Löschen von Räumen, zum Hinzufügen von Teilnehmern, zum Aktualisieren von Teilnehmern, zum Entfernen von Teilnehmern und zum Auflisten von Teilnehmern.

Verwenden von Anweisungen

using Azure.Communication.Rooms

Authentifizieren des Clients

Räume-Clients können mithilfe der Verbindungszeichenfolge authentifiziert werden, die von einer Azure-Kommunikationsressource im Azure-Portal abgerufen wurde.

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

Beispiele

Erstellen eines Raums

Um einen Raum zu erstellen, rufen Sie die CreateRoom -Funktion oder CreateRoomAsync aus auf RoomsClient. Die validFromArgumente , validUntilund participants sind alle optional. Wenn validFrom und validUntil nicht angegeben werden, ist der Standardwert für validFrom die aktuelle Datumszeit, und der Standardwert für validUntil ist validFrom + 180 days. Wenn sie definieren RoomParticipant, ist die Attendee Rolle nicht angegeben, standardmäßig. Der zurückgegebene Wert enthält Response<CommunicationRoom> erstellte Raumdetails sowie die status und zugeordneten Fehlercodes im Falle eines Fehlers.

// 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;

Aktualisieren eines Raums

Die validFrom Eigenschaften und validUntil eines erstellten Raums können aktualisiert werden, indem die UpdateRoom Funktion oder UpdateRoomAsync von RoomsClientaufgerufen wird.

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

Abrufen eines erstellten Raums

Ein erstellter Raum kann abgerufen werden, indem die GetRoom -Funktion oder GetRoomAsync von RoomsClient aufgerufen und der zugeordnete roomIdübergeben wird.

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

Alle Räume abrufen

Alle gültigen Räume, die unter einer ACS-Ressource erstellt wurden, können abgerufen werden, indem Sie die GetRooms Funktion oder GetRoomsAsync von RoomsClientaufrufen.

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}.");
}

Raum löschen

Um einen Raum zu löschen, rufen Sie die DeleteRoom Funktion oder DeleteRoomAsync über RoomsClient auf.

Response deleteRoomResponse = await roomsClient.DeleteRoomAsync(createdRoomId);

Hinzufügen oder Aktualisieren von Teilnehmern in einem Raum

Um neue Teilnehmer hinzuzufügen oder vorhandene Teilnehmer zu aktualisieren, rufen Sie die AddOrUpdateParticipants Funktion oder AddOrUpdateParticipantsAsync über RoomsClient auf.

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

Entfernen von Teilnehmern in einem Raum

Um Teilnehmer aus einem Raum zu entfernen, rufen Sie die RemoveParticipants Funktion oder RemoveParticipantsAsync von RoomsClient auf.

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

Teilnehmer in einem Raum abrufen

Um alle Teilnehmer aus einem Raum abzurufen, rufen Sie die GetParticipants Funktion oder GetParticipantsAsync über RoomsClient auf. Der zurückgegebene Wert ist Pageable<RoomParticipant> oder AsyncPageable<RoomParticipant> , der die paginierte Teilnehmerliste enthält.

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

Problembehandlung

Dienstantworten

Ein RequestFailedException wird als Dienstantwort für alle nicht erfolgreichen Anforderungen ausgelöst. Die Ausnahme enthält Informationen darüber, welcher Antwortcode vom Dienst zurückgegeben wurde.

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);
}

Nächste Schritte

Mitwirken

Beiträge und Vorschläge für dieses Projekt sind willkommen. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. Weitere Informationen finden Sie unter cla.microsoft.com.

Für dieses Projekt gelten die Microsoft-Verhaltensregeln für Open Source (Microsoft Open Source Code of Conduct). Weitere Informationen finden Sie in den häufig gestellten Fragen zum Verhaltenskodex. Sie können sich auch an opencode@microsoft.com wenden, wenn Sie weitere Fragen oder Anmerkungen haben.

Aktualisieren der Beispielcodelinks nach der Veröffentlichung des SDK