diff --git a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallAsyncClient.java b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallAsyncClient.java index 2d4b720a6f874..0620dd05c3f1f 100644 --- a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallAsyncClient.java +++ b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/CallAsyncClient.java @@ -352,7 +352,7 @@ Mono> cancelAllMediaOperationsWithResponse } /** - * Cancel Media Operations. + * Invite Participats to a Call. * * @param callId Call id. * @param request Invite participant request. @@ -371,7 +371,7 @@ public Mono inviteParticipants(String callId, InviteParticipantsRequest re } /** - * Cancel Media Operations. + * Invite Participats to a Call. * * @param callId Call id. * @param request Invite participant request. @@ -433,7 +433,7 @@ public Mono> removeParticipantWithResponse(String callId, String } /** - * cancelMediaOperationsWithResponse method for use by sync client + * Remove participant from the call. */ Mono> removeParticipantWithResponse(String callId, String participantId, Context context) { try { diff --git a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationAsyncClient.java b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationAsyncClient.java index 185fa86a00cc9..09c239667b79b 100644 --- a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationAsyncClient.java +++ b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationAsyncClient.java @@ -5,10 +5,15 @@ import com.azure.communication.callingserver.implementation.AzureCommunicationCallingServerServiceImpl; import com.azure.communication.callingserver.implementation.ConversationsImpl; +import com.azure.communication.callingserver.implementation.converters.InviteParticipantsRequestConverter; +import com.azure.communication.callingserver.implementation.converters.JoinCallRequestConverter; import com.azure.communication.callingserver.implementation.models.GetCallRecordingStateResponse; +import com.azure.communication.callingserver.implementation.models.JoinCallResponse; import com.azure.communication.callingserver.implementation.models.StartCallRecordingRequestInternal; import com.azure.communication.callingserver.implementation.models.StartCallRecordingResponse; import com.azure.communication.callingserver.models.GetCallRecordingStateResult; +import com.azure.communication.callingserver.models.InviteParticipantsRequest; +import com.azure.communication.callingserver.models.JoinCallRequest; import com.azure.communication.callingserver.models.StartCallRecordingResult; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; @@ -38,6 +43,155 @@ public final class ConversationAsyncClient { conversationsClient = conversationServiceClient.getConversations(); } + /** + * Join a Call + * + * @param conversationId The conversation id. + * @param request Join Call request. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono joinCall(String conversationId, JoinCallRequest request) { + try { + Objects.requireNonNull(conversationId, "'conversationId' cannot be null."); + Objects.requireNonNull(request, "'request' cannot be null."); + + return this.conversationsClient.joinCallAsync(conversationId, JoinCallRequestConverter.convert(request)); + } catch (RuntimeException ex) { + return monoError(logger, ex); + } + } + + /** + * Join a Call + * + * @param conversationId The conversation id. + * @param request Join Call request. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono>joinCallWithResponse(String conversationId, JoinCallRequest request) { + return joinCallWithResponse(conversationId, request, null); + } + + Mono> joinCallWithResponse( + String conversationId, + JoinCallRequest request, + Context context) { + try { + Objects.requireNonNull(conversationId, "'conversationId' cannot be null."); + Objects.requireNonNull(request, "'request' cannot be null."); + return withContext(contextValue -> { + if (context != null) { + contextValue = context; + } + return this.conversationsClient.joinCallWithResponseAsync(conversationId, + JoinCallRequestConverter.convert(request)); + }); + } catch (RuntimeException ex) { + return monoError(logger, ex); + } + } + + /** + * Invite Participats to a Conversation. + * + * @param conversationId The conversation id. + * @param request Invite participant request. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono inviteParticipants(String conversationId, InviteParticipantsRequest request) { + try { + Objects.requireNonNull(conversationId, "'conversationId' cannot be null."); + Objects.requireNonNull(request, "'request' cannot be null."); + + return this.conversationsClient.inviteParticipantsAsync(conversationId, InviteParticipantsRequestConverter.convert(request)); + } catch (RuntimeException ex) { + return monoError(logger, ex); + } + } + + /** + * Invite Participats to a Conversation. + * + * @param conversationId The conversation id. + * @param request Invite participant request. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> inviteParticipantsWithResponse(String conversationId, InviteParticipantsRequest request) { + return inviteParticipantsWithResponse(conversationId, request, null); + } + + Mono> inviteParticipantsWithResponse( + String conversationId, + InviteParticipantsRequest request, + Context context) { + try { + Objects.requireNonNull(conversationId, "'conversationId' cannot be null."); + Objects.requireNonNull(request, "'request' cannot be null."); + return withContext(contextValue -> { + if (context != null) { + contextValue = context; + } + return this.conversationsClient.inviteParticipantsWithResponseAsync(conversationId, + InviteParticipantsRequestConverter.convert(request)); + }); + } catch (RuntimeException ex) { + return monoError(logger, ex); + } + } + + /** + * Remove participant from the Conversation. + * + * @param conversationId The conversation id. + * @param participantId Participant id. + * @return response for a successful removeParticipant request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono removeParticipant(String conversationId, String participantId) { + try { + Objects.requireNonNull(conversationId, "'conversationId' cannot be null."); + Objects.requireNonNull(participantId, "'participantId' cannot be null."); + + return this.conversationsClient.removeParticipantAsync(conversationId, participantId); + } catch (RuntimeException ex) { + return monoError(logger, ex); + } + } + + /** + * Remove participant from the Conversation. + * + * @param conversationId The conversation id. + * @param participantId Participant id. + * @return response for a successful removeParticipant request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> removeParticipantWithResponse(String conversationId, String participantId) { + return removeParticipantWithResponse(conversationId, participantId, null); + } + + /** + * Remove participant from the Conversation. + */ + Mono> removeParticipantWithResponse(String conversationId, String participantId, Context context) { + try { + Objects.requireNonNull(conversationId, "'conversationId' cannot be null."); + Objects.requireNonNull(participantId, "'participantId' cannot be null."); + return withContext(contextValue -> { + if (context != null) { + contextValue = context; + } + return this.conversationsClient.removeParticipantWithResponseAsync(conversationId, participantId); + }); + } catch (RuntimeException ex) { + return monoError(logger, ex); + } + } + /** * Start recording * diff --git a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationClient.java b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationClient.java index e527381cf4ef5..8f883ee0b829d 100644 --- a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationClient.java +++ b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/ConversationClient.java @@ -3,7 +3,10 @@ package com.azure.communication.callingserver; +import com.azure.communication.callingserver.implementation.models.JoinCallResponse; import com.azure.communication.callingserver.models.GetCallRecordingStateResult; +import com.azure.communication.callingserver.models.InviteParticipantsRequest; +import com.azure.communication.callingserver.models.JoinCallRequest; import com.azure.communication.callingserver.models.StartCallRecordingResult; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; @@ -24,6 +27,81 @@ public final class ConversationClient { this.conversationAsyncClient = conversationAsyncClient; } + /** + * Join a call + * + * @param conversationId The conversation id. + * @param request Join Call request. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public JoinCallResponse joinCall(String conversationId, JoinCallRequest request) { + return conversationAsyncClient.joinCall(conversationId, request).block(); + } + + /** + * Join a call + * + * @param conversationId The conversation id. + * @param request Join Call request. + * @param context A {@link Context} representing the request context. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response inviteParticipantsWithResponse(String conversationId, JoinCallRequest request, Context context) { + return conversationAsyncClient.joinCallWithResponse(conversationId, request, context).block(); + } + + /** + * Invite participants to a Conversation. + * + * @param conversationId The conversation id. + * @param request Invite participant request. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Void inviteParticipants(String conversationId, InviteParticipantsRequest request) { + return conversationAsyncClient.inviteParticipants(conversationId, request).block(); + } + + /** + * Invite participants to a Conversation. + * + * @param conversationId The conversation id. + * @param request Invite participant request. + * @param context A {@link Context} representing the request context. + * @return response for a successful inviteParticipants request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response inviteParticipantsWithResponse(String conversationId, InviteParticipantsRequest request, Context context) { + return conversationAsyncClient.inviteParticipantsWithResponse(conversationId, request, context).block(); + } + + /** + * Remove participant from the Conversation. + * + * @param conversationId The conversation id. + * @param participantId Participant id. + * @return response for a successful removeParticipant request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Void removeParticipant(String conversationId, String participantId) { + return conversationAsyncClient.removeParticipant(conversationId, participantId).block(); + } + + /** + * Remove participant from the Conversation. + * + * @param conversationId The conversation id. + * @param participantId Participant id. + * @param context A {@link Context} representing the request context. + * @return response for a successful removeParticipant request. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response removeParticipantWithResponse(String conversationId, String participantId, Context context) { + return conversationAsyncClient.removeParticipantWithResponse(conversationId, participantId, context).block(); + } + /** * Start recording * diff --git a/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/implementation/converters/JoinCallRequestConverter.java b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/implementation/converters/JoinCallRequestConverter.java new file mode 100644 index 0000000000000..6a5ae90a2b2f2 --- /dev/null +++ b/sdk/communication/azure-communication-callingserver/src/main/java/com/azure/communication/callingserver/implementation/converters/JoinCallRequestConverter.java @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.communication.callingserver.implementation.converters; + +import java.util.ArrayList; +import java.util.List; + +import com.azure.communication.callingserver.implementation.models.CallModality; +import com.azure.communication.callingserver.implementation.models.EventSubscriptionType; +import com.azure.communication.callingserver.implementation.models.JoinCallRequestInternal; + +/** + * A converter between {@link com.azure.communication.callingserver.models.JoinCallRequest} and + * {@link JoinCallRequestInternal}. + */ +public final class JoinCallRequestConverter { + /** + * Maps from {com.azure.communication.callingserver.models.JoinCallRequest} to {@link JoinCallRequestInternal}. + */ + public static JoinCallRequestInternal convert(com.azure.communication.callingserver.models.JoinCallRequest obj) { + if (obj == null) { + return null; + } + + List requestedModalities = new ArrayList<>(); + for (CallModality callModality : obj.getRequestedModalities()) { + requestedModalities.add(callModality); + } + + List requestedCallEvents = new ArrayList<>(); + for (EventSubscriptionType eventSubscription : obj.getRequestedCallEvents()){ + requestedCallEvents.add(eventSubscription); + } + + JoinCallRequestInternal joinCallRequestInternal = new JoinCallRequestInternal() + .setSource(CommunicationIdentifierConverter.convert(obj.getSource())) + .setSubject(obj.getSubject()) + .setCallbackUri(obj.getCallbackUri()) + .setRequestedModalities(requestedModalities) + .setRequestedCallEvents(requestedCallEvents); + + return joinCallRequestInternal; + } + + private JoinCallRequestConverter() { + } +} \ No newline at end of file