Skip to content

Commit 1c0bea6

Browse files
committed
Fix CallLocator deserialize issue.
1 parent 1cad486 commit 1c0bea6

File tree

7 files changed

+44
-39
lines changed

7 files changed

+44
-39
lines changed

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/_call_connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
RemoveParticipantRequestConverter,
1515
CancelAllMediaOperationsConverter,
1616
TransferCallRequestConverter,
17-
CancelMediaOperationRequestConverter,
1817
CancelParticipantMediaOperationRequestConverter,
1918
PlayAudioRequestConverter,
2019
PlayAudioToParticipantRequestConverter

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/_callingserver_client.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ def join_call(
196196
raise ValueError("call_options can not be None")
197197

198198
join_call_request = JoinCallRequestConverter.convert(
199-
serialize_call_locator(call_locator),
200-
serialize_identifier(source),
201-
call_options
199+
call_locator=serialize_call_locator(call_locator),
200+
source=serialize_identifier(source),
201+
join_call_options=call_options
202202
)
203203

204204
join_call_response = self._server_call_client.join_call(
@@ -228,9 +228,9 @@ def play_audio(
228228
raise ValueError("options can not be None")
229229

230230
play_audio_request = PlayAudioWithCallLocatorRequestConverter.convert(
231-
serialize_call_locator(call_locator),
232-
audio_file_uri,
233-
play_audio_options
231+
call_locator=serialize_call_locator(call_locator),
232+
audio_file_uri=audio_file_uri,
233+
play_audio_options=play_audio_options
234234
)
235235

236236
return self._server_call_client.play_audio(
@@ -258,10 +258,10 @@ def play_audio_to_participant(
258258
raise ValueError("play_audio_options can not be None")
259259

260260
play_audio_to_participant_request = PlayAudioToParticipantWithCallLocatorRequestConverter.convert(
261-
serialize_call_locator(call_locator),
262-
serialize_identifier(participant),
263-
audio_file_uri,
264-
play_audio_options
261+
call_locator=serialize_call_locator(call_locator),
262+
identifier=serialize_identifier(participant),
263+
audio_file_uri=audio_file_uri,
264+
play_audio_options=play_audio_options
265265
)
266266

267267
return self._server_call_client.participant_play_audio(
@@ -359,7 +359,8 @@ def cancel_participant_media_operation(
359359
if not media_operation_id:
360360
raise ValueError("media_operation_id can not be None")
361361

362-
cancel_participant_media_operation_request = CancelParticipantMediaOperationWithCallLocatorRequestConverter.convert(
362+
cancel_participant_media_operation_request = \
363+
CancelParticipantMediaOperationWithCallLocatorRequestConverter.convert(
363364
serialize_call_locator(call_locator),
364365
serialize_identifier(participant),
365366
media_operation_id=media_operation_id
@@ -368,4 +369,4 @@ def cancel_participant_media_operation(
368369
return self._server_call_client.cancel_participant_media_operation(
369370
cancel_participant_media_operation_request=cancel_participant_media_operation_request,
370371
**kwargs
371-
)
372+
)

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/_communication_call_locator_serializer.py

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

88
from ._models import (
99
CallLocator,
10+
CallLocatorKind,
1011
GroupCallLocator,
1112
ServerCallLocator
1213
)
@@ -25,10 +26,12 @@ def serialize_call_locator(call_locator):
2526
:return: CallLocatorModel
2627
"""
2728
try:
28-
request_model = {}
29-
30-
if call_locator.kind:
31-
request_model[call_locator.kind] = dict(call_locator.properties)
29+
if call_locator.kind and call_locator.kind == CallLocatorKind.GROUP_CALL_LOCATOR:
30+
request_model = {'group_call_id': call_locator.id}
31+
request_model['kind'] = call_locator.kind
32+
elif call_locator.kind and call_locator.kind == CallLocatorKind.SERVER_CALL_LOCATOR:
33+
request_model = {'server_call_id': call_locator.id}
34+
request_model['kind'] = call_locator.kind
3235
return request_model
3336
except AttributeError:
3437
raise TypeError("Unsupported call locator type " + call_locator.__class__.__name__)
@@ -44,8 +47,8 @@ def deserialize_call_locator(call_locator_model):
4447
:return: CallLocator
4548
"""
4649

47-
if call_locator_model.group_call_id and call_locator_model.kind == "groupCallLocator":
50+
if call_locator_model.group_call_id and call_locator_model.kind == CallLocatorKind.GROUP_CALL_LOCATOR:
4851
return GroupCallLocator(call_locator_model.group_call_id)
49-
if call_locator_model.server_call_id and call_locator_model.kind == "serverCallLocator":
52+
if call_locator_model.server_call_id and call_locator_model.kind == CallLocatorKind.SERVER_CALL_LOCATOR:
5053
return ServerCallLocator(call_locator_model.server_call_id)
5154
return None

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) Microsoft Corporation.
44
# Licensed under the MIT License.
55
# ------------------------------------
6+
# pylint: skip-file
67

78
from typing import List, Mapping, Optional, Union, Any # pylint: disable=unused-import
89
from enum import Enum, EnumMeta
@@ -27,18 +28,18 @@ class CallLocatorKind(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)):
2728
GROUP_CALL_LOCATOR = "groupCallLocator"
2829
SERVER_CALL_LOCATOR = "serverCallLocator"
2930

30-
class CallLocator(object):
31+
class CallLocator(Protocol):
3132
"""Call Locator.
3233
3334
:ivar kind: The type of locator.
3435
:vartype kind: str or CallLocatorKind
3536
:ivar Mapping[str, Any] properties: The properties of the locator.
3637
"""
37-
id = None # type: Optional[str]
38+
id = str # type: str
3839
kind = None # type: Optional[Union[CallLocatorKind, str]]
3940
properties = {} # type: Mapping[str, Any]
4041

41-
class GroupCallLocator(CallLocator):
42+
class GroupCallLocator(object):
4243
"""The group call locator.
4344
4445
:ivar kind: The type of locator.
@@ -61,7 +62,7 @@ def __init__(self, id):
6162
self.id = id
6263
self.properties = {}
6364

64-
class ServerCallLocator(CallLocator):
65+
class ServerCallLocator(object):
6566
"""The server call locator.
6667
6768
:ivar kind: The type of locator.

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/aio/_call_connection_async.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
RemoveParticipantRequestConverter,
1919
CancelAllMediaOperationsConverter,
2020
TransferCallRequestConverter,
21-
CancelMediaOperationRequestConverter,
2221
CancelParticipantMediaOperationRequestConverter,
2322
PlayAudioRequestConverter,
2423
PlayAudioToParticipantRequestConverter

sdk/communication/azure-communication-callingserver/azure/communication/callingserver/aio/_callingserver_client_async.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async def create_call_connection(
178178
@distributed_trace_async()
179179
async def join_call(
180180
self,
181-
call_locator: 'CallLocator',
181+
call_locator: CallLocator,
182182
source: CommunicationIdentifier,
183183
call_options: 'JoinCallOptions',
184184
**kwargs: Any
@@ -202,9 +202,9 @@ async def join_call(
202202
raise ValueError("call_options can not be None")
203203

204204
join_call_request = JoinCallRequestConverter.convert(
205-
serialize_call_locator(call_locator),
206-
serialize_identifier(source),
207-
call_options
205+
call_locator=serialize_call_locator(call_locator),
206+
source=serialize_identifier(source),
207+
join_call_options=call_options
208208
)
209209

210210
join_call_response = await self._server_call_client.join_call(
@@ -235,9 +235,9 @@ async def play_audio(
235235
raise ValueError("options can not be None")
236236

237237
play_audio_request = PlayAudioWithCallLocatorRequestConverter.convert(
238-
serialize_call_locator(call_locator),
239-
audio_file_uri,
240-
play_audio_options
238+
call_locator=serialize_call_locator(call_locator),
239+
audio_file_uri=audio_file_uri,
240+
play_audio_options=play_audio_options
241241
)
242242

243243
return await self._server_call_client.play_audio(
@@ -265,10 +265,10 @@ async def play_audio_to_participant(
265265
raise ValueError("play_audio_options can not be None")
266266

267267
play_audio_to_participant_request = PlayAudioToParticipantWithCallLocatorRequestConverter.convert(
268-
serialize_call_locator(call_locator),
269-
serialize_identifier(participant),
270-
audio_file_uri,
271-
play_audio_options
268+
call_locator=serialize_call_locator(call_locator),
269+
identifier=serialize_identifier(participant),
270+
audio_file_uri=audio_file_uri,
271+
play_audio_options=play_audio_options
272272
)
273273

274274
return await self._server_call_client.participant_play_audio(
@@ -366,7 +366,8 @@ async def cancel_participant_media_operation(
366366
if not media_operation_id:
367367
raise ValueError("media_operation_id can not be None")
368368

369-
cancel_participant_media_operation_request = CancelParticipantMediaOperationWithCallLocatorRequestConverter.convert(
369+
cancel_participant_media_operation_request = \
370+
CancelParticipantMediaOperationWithCallLocatorRequestConverter.convert(
370371
serialize_call_locator(call_locator),
371372
serialize_identifier(participant),
372373
media_operation_id=media_operation_id

sdk/communication/azure-communication-callingserver/tests/utils/_live_test_utils_async.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
CommunicationUserIdentifier,
1010
CreateCallOptions,
1111
MediaType,
12-
EventSubscriptionType
12+
EventSubscriptionType,
13+
GroupCallLocator
1314
)
1415
from utils._live_test_utils import CallingServerLiveTestUtils
1516

@@ -42,7 +43,7 @@ async def create_group_calls_async(
4243
requested_media_types=[MediaType.AUDIO],
4344
requested_call_events=[EventSubscriptionType.PARTICIPANTS_UPDATED]
4445
)
45-
from_call_connection = await callingserver_client.join_call(group_id, from_participant, from_options)
46+
from_call_connection = await callingserver_client.join_call(GroupCallLocator(group_id), from_participant, from_options)
4647
CallingServerLiveTestUtilsAsync.validate_callconnection_Async(from_call_connection)
4748
CallingServerLiveTestUtils.sleep_if_in_live_mode()
4849

@@ -52,7 +53,7 @@ async def create_group_calls_async(
5253
requested_media_types=[MediaType.AUDIO],
5354
requested_call_events=[EventSubscriptionType.PARTICIPANTS_UPDATED]
5455
)
55-
to_call_connection = await callingserver_client.join_call(group_id, to_participant, to_options)
56+
to_call_connection = await callingserver_client.join_call(GroupCallLocator(group_id), to_participant, to_options)
5657
CallingServerLiveTestUtilsAsync.validate_callconnection_Async(from_call_connection)
5758
CallingServerLiveTestUtils.sleep_if_in_live_mode()
5859

0 commit comments

Comments
 (0)