Skip to content

Commit

Permalink
in-call transfer apis (#20745)
Browse files Browse the repository at this point in the history
* add cancelmediaoperation and cancelparticipantmediaoperation

* in-call transfer apis

* address style comments

* fix styling error
  • Loading branch information
satyakonmsft authored Sep 17, 2021
1 parent 7728f19 commit 236ea34
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from ._communication_identifier_serializer import serialize_identifier
from ._converters import (AddParticipantRequestConverter,
TransferCallRequestConverter,
CancelMediaOperationRequestConverter,
PlayAudioRequestConverter)
from ._generated.models import (AddParticipantResult,
Expand Down Expand Up @@ -148,3 +149,25 @@ def cancel_participant_media_operation(
cancel_media_operation_request=cancel_media_operation_request,
**kwargs
)

@distributed_trace()
def transfer_call(
self,
target_participant, # type: CommunicationIdentifier
user_to_user_information, # type: str
**kwargs # type: Any
): # type: (...) -> None

if not target_participant:
raise ValueError("target_participant can not be None")

transfer_call_request = TransferCallRequestConverter.convert(
target_participant=serialize_identifier(target_participant),
user_to_user_information=user_to_user_information
)

return self._call_connection_client.transfer(
call_connection_id=self.call_connection_id,
transfer_call_request=transfer_call_request,
**kwargs
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from ._converter import \
JoinCallRequestConverter, PlayAudioRequestConverter, AddParticipantRequestConverter, \
CancelMediaOperationRequestConverter
CancelMediaOperationRequestConverter, TransferCallRequestConverter
__all__ = [
'JoinCallRequestConverter',
'PlayAudioRequestConverter',
"AddParticipantRequestConverter",
"CancelMediaOperationRequestConverter"
"CancelMediaOperationRequestConverter",
"TransferCallRequestConverter"
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .._generated.models import (
JoinCallRequest,
PlayAudioRequest,
TransferCallRequest,
CommunicationIdentifierModel,
AddParticipantRequest,
CancelMediaOperationRequest,
Expand Down Expand Up @@ -87,4 +88,18 @@ def convert(
return CancelMediaOperationRequest(
media_operation_id=media_operation_id
)


class TransferCallRequestConverter(object):
@staticmethod
def convert(
target_participant, # type: CommunicationIdentifierModel
user_to_user_information=None, # type: str
): # type: (...) -> TransferCallRequest

if not target_participant:
raise ValueError("target_participant can not be None")

return TransferCallRequest(
target_participant=target_participant,
user_to_user_information=user_to_user_information
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from .._communication_identifier_serializer import serialize_identifier
from .._converters import (AddParticipantRequestConverter,
TransferCallRequestConverter,
CancelMediaOperationRequestConverter,
PlayAudioRequestConverter)
from .._generated.models import (AddParticipantResult,
Expand Down Expand Up @@ -130,9 +131,9 @@ async def remove_participant(
@distributed_trace_async()
async def cancel_participant_media_operation(
self,
participant_id, # type: str
media_operation_id, # type: str
**kwargs # type: Any
participant_id: str,
media_operation_id: str,
**kwargs: Any
)-> None:

if not participant_id:
Expand All @@ -152,6 +153,28 @@ async def cancel_participant_media_operation(
**kwargs
)

@distributed_trace_async()
async def transfer_call(
self,
target_participant: CommunicationIdentifier,
user_to_user_information: Optional[str],
**kwargs: Any
)-> None:

if not target_participant:
raise ValueError("target_participant can not be None")

transfer_call_request = TransferCallRequestConverter.convert(
target_participant=serialize_identifier(target_participant),
user_to_user_information=user_to_user_information
)

return await self._call_connection_client.transfer(
call_connection_id=self.call_connection_id,
transfer_call_request=transfer_call_request,
**kwargs
)

async def close(self) -> None:
"""Close the :class:
`~azure.communication.callingserver.aio.CallConnection` session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ async def remove_participant(
@distributed_trace_async()
async def cancel_media_operation(
self,
media_operation_id, # type: str
**kwargs # type: Any
media_operation_id: str,
**kwargs: Any
) -> None:

if not media_operation_id:
Expand All @@ -123,9 +123,9 @@ async def cancel_media_operation(
@distributed_trace_async()
async def cancel_participant_media_operation(
self,
participant_id, # type: str
media_operation_id, # type: str
**kwargs # type: Any
participant_id: str,
media_operation_id: str,
**kwargs: Any
) -> None:

if not participant_id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
CONNECTION_STRING = "endpoint=https://REDACTED.communication.azure.com/;accesskey=eyJhbG=="
PARTICIPANT_ID = "dummyParticipantId"
MEDIA_OPERATION_ID = "dummyMediaOperationId"
USER_TO_USER_INFORMATION = "dummyUserToUserInformation"

# CancelAllMediaOperaions
CancelAllMediaOperaionsResponsePayload = {
Expand Down Expand Up @@ -61,3 +62,4 @@
AddParticipantResultPayload = {
"participantId": PARTICIPANT_ID
}

Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ def data_source_test_add_participant():

return parameters

def data_source_test_transfer_call():

parameters = []
parameters.append((
_test_constants.ClientType_ConnectionString,
_test_constants.CALL_ID,
CommunicationUserIdentifier(_test_constants.RESOURCE_SOURCE),
_test_constants.USER_TO_USER_INFORMATION,
))

parameters.append((
_test_constants.ClientType_ManagedIdentity,
_test_constants.CALL_ID,
CommunicationUserIdentifier(_test_constants.RESOURCE_SOURCE),
_test_constants.USER_TO_USER_INFORMATION,
True,
))

return parameters

def data_source_test_remove_participant():

parameters = []
Expand Down Expand Up @@ -441,4 +461,54 @@ def test_cancel_participant_media_operation_failed(
)
except:
raised = True
assert raised == True

@parameterized.expand(data_source_test_transfer_call())
def test_transfer_call_succeed(
self,
test_name, # type: str
call_connection_id, # type: str
participant, # type: CommunicationIdentifier
user_to_user_information, # type: str
use_managed_identity = False # type: bool
):

call_connection = _test_utils.create_mock_call_connection(
call_connection_id,
status_code=202,
payload=None,
use_managed_identity=use_managed_identity
)

call_connection.transfer_call(
target_participant = participant,
user_to_user_information = user_to_user_information
)
assert call_connection.call_connection_id == _test_constants.CALL_ID

@parameterized.expand(data_source_test_transfer_call())
def test_transfer_call_failed(
self,
test_name, # type: str
call_connection_id, # type: str
participant, # type: CommunicationIdentifier
user_to_user_information, # type: str
use_managed_identity = False # type: bool
):

call_connection = _test_utils.create_mock_call_connection(
call_connection_id,
status_code=404,
payload=None,
use_managed_identity = use_managed_identity
)

raised = False
try:
call_connection.transfer_call(
target_participant = participant,
user_to_user_information = user_to_user_information
)
except:
raised = True
assert raised == True
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ def data_source_test_add_participant():

return parameters

def data_source_test_transfer_call():

parameters = []
parameters.append((
_test_constants.ClientType_ConnectionString,
_test_constants.CALL_ID,
CommunicationUserIdentifier(_test_constants.RESOURCE_SOURCE),
_test_constants.USER_TO_USER_INFORMATION,
))

parameters.append((
_test_constants.ClientType_ManagedIdentity,
_test_constants.CALL_ID,
CommunicationUserIdentifier(_test_constants.RESOURCE_SOURCE),
_test_constants.USER_TO_USER_INFORMATION,
True,
))

return parameters

def data_source_test_remove_participant():

parameters = []
Expand Down Expand Up @@ -438,4 +458,54 @@ async def test_cancel_participant_media_operation_failed(
)
except:
raised = True
assert raised == True

@parameterized.expand(data_source_test_transfer_call())
@pytest.mark.asyncio
async def test_transfer_call_succeed(
test_name, # type: str
call_connection_id, # type: str
participant, # type: CommunicationIdentifier
user_to_user_information, # type: str
use_managed_identity = False # type: bool
):

call_connection = _test_utils_async.create_mock_call_connection(
call_connection_id,
status_code=202,
payload=None,
use_managed_identity=use_managed_identity
)

await call_connection.transfer_call(
target_participant = participant,
user_to_user_information = user_to_user_information
)
assert call_connection.call_connection_id == _test_constants.CALL_ID

@parameterized.expand(data_source_test_transfer_call())
@pytest.mark.asyncio
async def test_transfer_call_failed(
test_name, # type: str
call_connection_id, # type: str
participant, # type: CommunicationIdentifier
user_to_user_information, # type: str
use_managed_identity = False # type: bool
):

call_connection = _test_utils_async.create_mock_call_connection(
call_connection_id,
status_code=404,
payload=None,
use_managed_identity = use_managed_identity
)

raised = False
try:
await call_connection.transfer_call(
target_participant = participant,
user_to_user_information = user_to_user_information
)
except:
raised = True
assert raised == True

0 comments on commit 236ea34

Please sign in to comment.