Skip to content

Commit 29e78d9

Browse files
add channel affinity property to start recording (#30346)
* add channel affinity property to start recording * update participant name to match other sdks * resolve merge issues with main * pr comments * pr comments * update comment var name * change order of comments
1 parent 5d488cf commit 29e78d9

5 files changed

Lines changed: 74 additions & 6 deletions

File tree

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
AddParticipantResult,
1818
RemoveParticipantResult,
1919
TransferCallResult,
20-
MediaStreamingConfiguration
20+
MediaStreamingConfiguration,
21+
ChannelAffinity
2122
)
2223
from ._shared.models import (
2324
CommunicationIdentifier,
@@ -53,6 +54,7 @@
5354
"ServerCallLocator",
5455
"GroupCallLocator",
5556
"FileSource",
57+
"ChannelAffinity",
5658

5759
# models for output
5860
"CallConnectionProperties",

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_call_automation_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ def start_recording(
401401
recording_format_type: Optional[Union[str, 'RecordingFormat']] = None,
402402
audio_channel_participant_ordering: Optional[List['CommunicationIdentifier']] = None,
403403
recording_storage_type: Optional[Union[str, 'RecordingStorage']] = None,
404+
channel_affinity: Optional[List['ChannelAffinity']] = None,
404405
external_storage_location: Optional[str] = None,
405406
**kwargs
406407
) -> RecordingProperties:
@@ -427,13 +428,25 @@ def start_recording(
427428
:keyword recording_storage_type: Recording storage mode.
428429
``External`` enables bring your own storage.
429430
:paramtype recording_storage_type: str
431+
:keyword channel_affinity: The channel affinity of call recording
432+
When 'recordingChannelType' is set to 'unmixed', if channelAffinity is not specified,
433+
'channel' will be automatically assigned.
434+
Channel-Participant mapping details can be found in the metadata of the recording.
435+
:paramtype channel_affinity: list[~azure.communication.callautomation.ChannelAffinity]
430436
:keyword external_storage_location: The location where recording is stored,
431437
when RecordingStorageType is set to 'BlobStorage'.
432438
:paramtype external_storage_location: str or ~azure.communication.callautomation.RecordingStorage
433439
:return: RecordingProperties
434440
:rtype: ~azure.communication.callautomation.RecordingProperties
435441
:raises ~azure.core.exceptions.HttpResponseError:
436442
"""
443+
channel_affinity_internal = []
444+
445+
if channel_affinity:
446+
for channel in channel_affinity:
447+
channel_affinity_internal.append(channel._to_generated(# pylint:disable=protected-access
448+
))
449+
437450
start_recording_request = StartCallRecordingRequest(
438451
call_locator=call_locator._to_generated(# pylint:disable=protected-access
439452
),
@@ -444,6 +457,7 @@ def start_recording(
444457
audio_channel_participant_ordering = audio_channel_participant_ordering,
445458
recording_storage_type = recording_storage_type,
446459
external_storage_location = external_storage_location,
460+
channel_affinity = channel_affinity_internal,
447461
repeatability_first_sent=get_repeatability_timestamp(),
448462
repeatability_request_id=get_repeatability_guid()
449463
)

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/_models.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
CallLocator,
99
MediaStreamingConfiguration as MediaStreamingConfigurationRest,
1010
FileSource as FileSourceInternal,
11-
PlaySource as PlaySourceInternal
11+
PlaySource as PlaySourceInternal,
12+
ChannelAffinity as ChannelAffinityInternal
1213
)
1314
from ._shared.models import (
1415
CommunicationIdentifier,
@@ -21,7 +22,8 @@
2122
from ._utils import (
2223
deserialize_phone_identifier,
2324
deserialize_identifier,
24-
deserialize_comm_user_identifier
25+
deserialize_comm_user_identifier,
26+
serialize_identifier
2527
)
2628
if TYPE_CHECKING:
2729
from ._generated.models._enums import (
@@ -134,6 +136,41 @@ def _to_generated(self):
134136
return CallLocator(kind=self.kind,
135137
group_call_id=self.id)
136138

139+
class ChannelAffinity(object):
140+
"""Channel affinity for a participant.
141+
142+
All required parameters must be populated in order to send to Azure.
143+
144+
:ivar target_participant: The identifier for the participant whose bitstream will be written to the
145+
channel
146+
represented by the channel number. Required.
147+
:vartype target_participant: ~azure.communication.callautomation.CommunicationIdentifier
148+
:ivar channel: Channel number to which bitstream from a particular participant will be written.
149+
:vartype channel: int
150+
"""
151+
152+
def __init__(
153+
self,
154+
target_participant: CommunicationIdentifier,
155+
channel: int,
156+
**kwargs
157+
):
158+
"""
159+
:keyword target_participant: The identifier for the participant whose bitstream will be written to the
160+
channel
161+
represented by the channel number. Required.
162+
:paramtype target_participant: ~azure.communication.callautomation.CommunicationIdentifier
163+
:keyword channel: Channel number to which bitstream from a particular participant will be
164+
written.
165+
:paramtype channel: int
166+
"""
167+
super().__init__(**kwargs)
168+
self.target_participant = target_participant
169+
self.channel = channel
170+
171+
def _to_generated(self):
172+
return ChannelAffinityInternal(participant= serialize_identifier(self.target_participant), channel=self.channel)
173+
137174
class FileSource(object):
138175
"""Media file source of URL to be played in action such as Play media.
139176

sdk/communication/azure-communication-callautomation/azure/communication/callautomation/aio/_call_automation_client_async.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ async def start_recording(
402402
recording_format_type: Optional[Union[str, 'RecordingFormat']] = None,
403403
audio_channel_participant_ordering: Optional[List['CommunicationIdentifier']] = None,
404404
recording_storage_type: Optional[Union[str, 'RecordingStorage']] = None,
405+
channel_affinity: Optional[List['ChannelAffinity']] = None,
405406
external_storage_location: Optional[str] = None,
406407
**kwargs
407408
) -> RecordingProperties:
@@ -428,13 +429,25 @@ async def start_recording(
428429
:keyword recording_storage_type: Recording storage mode.
429430
``External`` enables bring your own storage.
430431
:paramtype recording_storage_type: str
432+
:keyword channel_affinity: The channel affinity of call recording
433+
When 'recordingChannelType' is set to 'unmixed', if channelAffinity is not specified,
434+
'channel' will be automatically assigned.
435+
Channel-Participant mapping details can be found in the metadata of the recording.
436+
:paramtype channel_affinity: list[~azure.communication.callautomation.ChannelAffinity]
431437
:keyword external_storage_location: The location where recording is stored,
432438
when RecordingStorageType is set to 'BlobStorage'.
433439
:paramtype external_storage_location: str or ~azure.communication.callautomation.RecordingStorage
434440
:return: RecordingProperties
435441
:rtype: ~azure.communication.callautomation.RecordingProperties
436442
:raises ~azure.core.exceptions.HttpResponseError:
437443
"""
444+
channel_affinity_internal = []
445+
446+
if channel_affinity:
447+
for channel in channel_affinity:
448+
channel_affinity_internal.append(channel._to_generated(# pylint:disable=protected-access
449+
))
450+
438451
start_recording_request = StartCallRecordingRequest(
439452
call_locator=call_locator._to_generated(# pylint:disable=protected-access
440453
),
@@ -445,6 +458,7 @@ async def start_recording(
445458
audio_channel_participant_ordering = audio_channel_participant_ordering,
446459
recording_storage_type = recording_storage_type,
447460
external_storage_location = external_storage_location,
461+
channel_affinity = channel_affinity_internal,
448462
repeatability_first_sent=get_repeatability_timestamp(),
449463
repeatability_request_id=get_repeatability_guid()
450464
)

sdk/communication/azure-communication-callautomation/tests/test_call_recording_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from azure.core.credentials import AzureKeyCredential
99
from azure.communication.callautomation import (
10-
CallAutomationClient, ServerCallLocator
10+
CallAutomationClient, ServerCallLocator, ChannelAffinity, CommunicationUserIdentifier
1111
)
1212
from unittest_helpers import mock_response
1313
from unittest.mock import Mock
@@ -27,9 +27,10 @@ def mock_send(*_, **__):
2727
callautomation_client = CallAutomationClient("https://endpoint", AzureKeyCredential("fakeCredential=="), transport=Mock(send=mock_send))
2828

2929
call_locator = ServerCallLocator(server_call_id = "locatorId")
30-
30+
target_participant = CommunicationUserIdentifier("testId")
31+
channel_affinity=ChannelAffinity(target_participant=target_participant, channel=0)
3132
try:
32-
callautomation_client.start_recording(call_locator=call_locator)
33+
callautomation_client.start_recording(call_locator=call_locator, channel_affinity=[channel_affinity])
3334
except:
3435
raised = True
3536
raise

0 commit comments

Comments
 (0)