Skip to content

Commit

Permalink
Added join call, add-remove participant for out-call (#22040)
Browse files Browse the repository at this point in the history
  • Loading branch information
arifsaikat-microsoft authored and chrwhit committed Jun 9, 2021
1 parent aed0e44 commit bed61a0
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Mono<Response<CancelMediaOperationsResult>> cancelAllMediaOperationsWithResponse
}

/**
* Cancel Media Operations.
* Invite Participats to a Call.
*
* @param callId Call id.
* @param request Invite participant request.
Expand All @@ -371,7 +371,7 @@ public Mono<Void> inviteParticipants(String callId, InviteParticipantsRequest re
}

/**
* Cancel Media Operations.
* Invite Participats to a Call.
*
* @param callId Call id.
* @param request Invite participant request.
Expand Down Expand Up @@ -430,7 +430,7 @@ public Mono<Response<Void>> removeParticipantWithResponse(String callId, String
}

/**
* cancelMediaOperationsWithResponse method for use by sync client
* Remove participant from the call.
*/
Mono<Response<Void>> removeParticipantWithResponse(String callId, String participantId, Context context) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<JoinCallResponse> 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<Response<JoinCallResponse>>joinCallWithResponse(String conversationId, JoinCallRequest request) {
return joinCallWithResponse(conversationId, request, null);
}

Mono<Response<JoinCallResponse>> 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<Void> 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<Response<Void>> inviteParticipantsWithResponse(String conversationId, InviteParticipantsRequest request) {
return inviteParticipantsWithResponse(conversationId, request, null);
}

Mono<Response<Void>> 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<Void> 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<Response<Void>> removeParticipantWithResponse(String conversationId, String participantId) {
return removeParticipantWithResponse(conversationId, participantId, null);
}

/**
* Remove participant from the Conversation.
*/
Mono<Response<Void>> 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<JoinCallResponse> 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<Void> 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<Void> removeParticipantWithResponse(String conversationId, String participantId, Context context) {
return conversationAsyncClient.removeParticipantWithResponse(conversationId, participantId, context).block();
}

/**
* Start recording
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CallModality> requestedModalities = new ArrayList<>();
for (CallModality callModality : obj.getRequestedModalities()) {
requestedModalities.add(callModality);
}

List<EventSubscriptionType> 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() {
}
}

0 comments on commit bed61a0

Please sign in to comment.