|
5 | 5 | # -------------------------------------------------------------------------- |
6 | 6 |
|
7 | 7 | from typing import TYPE_CHECKING, Any, List, Optional # pylint: disable=unused-import |
8 | | - |
9 | 8 | from azure.core.tracing.decorator import distributed_trace |
10 | | - |
| 9 | +from azure.core.pipeline.transport import HttpResponse |
| 10 | +from .utils._utils import CallingServerUtils |
| 11 | +from ._content_downloader import ContentDownloader |
| 12 | +from ._download import ContentStreamDownloader |
11 | 13 | from ._communication_identifier_serializer import serialize_identifier |
12 | 14 | from ._communication_call_locator_serializer import serialize_call_locator |
13 | 15 | from ._generated._azure_communication_calling_server_service import \ |
|
16 | 18 | CreateCallRequest, |
17 | 19 | PhoneNumberIdentifierModel, |
18 | 20 | PlayAudioResult, |
19 | | - AddParticipantResult |
| 21 | + AddParticipantResult, |
| 22 | + StartCallRecordingResult, |
| 23 | + CallRecordingProperties, |
| 24 | + StartCallRecordingRequest, |
| 25 | + StartCallRecordingWithCallLocatorRequest |
20 | 26 | ) |
21 | 27 | from ._shared.models import CommunicationIdentifier |
22 | | -from ._models import CallLocator |
23 | 28 | from ._call_connection import CallConnection |
24 | 29 | from ._converters import ( |
25 | 30 | JoinCallRequestConverter, |
|
35 | 40 |
|
36 | 41 | if TYPE_CHECKING: |
37 | 42 | from azure.core.credentials import TokenCredential |
38 | | - from ._models import CreateCallOptions, JoinCallOptions, PlayAudioOptions |
| 43 | + from ._models import ( |
| 44 | + CreateCallOptions, |
| 45 | + JoinCallOptions, |
| 46 | + PlayAudioOptions, |
| 47 | + ParallelDownloadOptions, |
| 48 | + CallLocator |
| 49 | + ) |
39 | 50 |
|
40 | 51 | class CallingServerClient(object): |
41 | 52 | """A client to interact with the AzureCommunicationService Calling Server. |
@@ -224,8 +235,12 @@ def play_audio( |
224 | 235 | raise ValueError("call_locator can not be None") |
225 | 236 | if not audio_file_uri: |
226 | 237 | raise ValueError("audio_file_uri can not be None") |
| 238 | + if not CallingServerUtils.is_valid_url(audio_file_uri): |
| 239 | + raise ValueError("audio_file_uri is invalid") |
227 | 240 | if not play_audio_options: |
228 | 241 | raise ValueError("options can not be None") |
| 242 | + if not CallingServerUtils.is_valid_url(play_audio_options.callback_uri): |
| 243 | + raise ValueError("callback_uri is invalid") |
229 | 244 |
|
230 | 245 | play_audio_request = PlayAudioWithCallLocatorRequestConverter.convert( |
231 | 246 | call_locator=serialize_call_locator(call_locator), |
@@ -254,8 +269,12 @@ def play_audio_to_participant( |
254 | 269 | raise ValueError("participant can not be None") |
255 | 270 | if not audio_file_uri: |
256 | 271 | raise ValueError("audio_file_uri can not be None") |
| 272 | + if not CallingServerUtils.is_valid_url(audio_file_uri): |
| 273 | + raise ValueError("audio_file_uri is invalid") |
257 | 274 | if not play_audio_options: |
258 | 275 | raise ValueError("play_audio_options can not be None") |
| 276 | + if not CallingServerUtils.is_valid_url(play_audio_options.callback_uri): |
| 277 | + raise ValueError("callback_uri is invalid") |
259 | 278 |
|
260 | 279 | play_audio_to_participant_request = PlayAudioToParticipantWithCallLocatorRequestConverter.convert( |
261 | 280 | call_locator=serialize_call_locator(call_locator), |
@@ -360,13 +379,141 @@ def cancel_participant_media_operation( |
360 | 379 | raise ValueError("media_operation_id can not be None") |
361 | 380 |
|
362 | 381 | cancel_participant_media_operation_request = \ |
363 | | - CancelParticipantMediaOperationWithCallLocatorRequestConverter.convert( |
364 | | - serialize_call_locator(call_locator), |
365 | | - serialize_identifier(participant), |
366 | | - media_operation_id=media_operation_id |
367 | | - ) |
| 382 | + CancelParticipantMediaOperationWithCallLocatorRequestConverter.convert( |
| 383 | + serialize_call_locator(call_locator), |
| 384 | + serialize_identifier(participant), |
| 385 | + media_operation_id=media_operation_id |
| 386 | + ) |
368 | 387 |
|
369 | 388 | return self._server_call_client.cancel_participant_media_operation( |
370 | 389 | cancel_participant_media_operation_request=cancel_participant_media_operation_request, |
371 | 390 | **kwargs |
372 | 391 | ) |
| 392 | + |
| 393 | + @distributed_trace() |
| 394 | + def start_recording( |
| 395 | + self, |
| 396 | + call_locator, # type: CallLocator |
| 397 | + recording_state_callback_uri, # type: str |
| 398 | + **kwargs # type: Any |
| 399 | + ): # type: (...) -> StartCallRecordingResult |
| 400 | + |
| 401 | + if not call_locator: |
| 402 | + raise ValueError("call_locator cannot be None") |
| 403 | + if not CallingServerUtils.is_valid_url(recording_state_callback_uri): |
| 404 | + raise ValueError("recording_state_callback_uri is invalid") |
| 405 | + |
| 406 | + start_call_recording_request = StartCallRecordingRequest( |
| 407 | + recording_state_callback_uri=recording_state_callback_uri, |
| 408 | + **kwargs |
| 409 | + ) |
| 410 | + |
| 411 | + start_call_recording_with_calllocator_request = StartCallRecordingWithCallLocatorRequest( |
| 412 | + call_locator=serialize_call_locator(call_locator), |
| 413 | + start_call_recording_request=start_call_recording_request |
| 414 | + ) |
| 415 | + |
| 416 | + return self._server_call_client.start_recording( |
| 417 | + start_call_recording_with_call_locator_request=start_call_recording_with_calllocator_request, |
| 418 | + **kwargs |
| 419 | + ) |
| 420 | + |
| 421 | + @distributed_trace() |
| 422 | + def pause_recording( |
| 423 | + self, |
| 424 | + recording_id, # type: str |
| 425 | + **kwargs # type: Any |
| 426 | + ): # type: (...) -> HttpResponse |
| 427 | + |
| 428 | + if not recording_id: |
| 429 | + raise ValueError("recording_id cannot be None") |
| 430 | + |
| 431 | + return self._server_call_client.pause_recording( |
| 432 | + recording_id=recording_id, |
| 433 | + **kwargs |
| 434 | + ) |
| 435 | + |
| 436 | + @distributed_trace() |
| 437 | + def resume_recording( |
| 438 | + self, |
| 439 | + recording_id, # type: str |
| 440 | + **kwargs # type: Any |
| 441 | + ): # type: (...) -> HttpResponse |
| 442 | + |
| 443 | + if not recording_id: |
| 444 | + raise ValueError("recording_id cannot be None") |
| 445 | + |
| 446 | + return self._server_call_client.resume_recording( |
| 447 | + recording_id=recording_id, |
| 448 | + **kwargs |
| 449 | + ) |
| 450 | + |
| 451 | + @distributed_trace() |
| 452 | + def stop_recording( |
| 453 | + self, |
| 454 | + recording_id, # type: str |
| 455 | + **kwargs # type: Any |
| 456 | + ): # type: (...) -> HttpResponse |
| 457 | + |
| 458 | + if not recording_id: |
| 459 | + raise ValueError("recording_id cannot be None") |
| 460 | + |
| 461 | + return self._server_call_client.stop_recording( |
| 462 | + recording_id=recording_id, |
| 463 | + **kwargs |
| 464 | + ) |
| 465 | + |
| 466 | + @distributed_trace() |
| 467 | + def get_recording_properities( |
| 468 | + self, |
| 469 | + recording_id, # type: str |
| 470 | + **kwargs # type: Any |
| 471 | + ): # type: (...) -> CallRecordingProperties |
| 472 | + |
| 473 | + if not recording_id: |
| 474 | + raise ValueError("recording_id cannot be None") |
| 475 | + |
| 476 | + return self._server_call_client.get_recording_properties( |
| 477 | + recording_id=recording_id, |
| 478 | + **kwargs |
| 479 | + ) |
| 480 | + |
| 481 | + @distributed_trace() |
| 482 | + def download( |
| 483 | + self, |
| 484 | + content_url, # type: str |
| 485 | + start_range=None, # type: int |
| 486 | + end_range=None, # type: int |
| 487 | + parallel_download_options=None, # type: ParallelDownloadOptions |
| 488 | + **kwargs # type: Any |
| 489 | + ): # type: (...) -> ContentStreamDownloader |
| 490 | + """Download using content url. |
| 491 | +
|
| 492 | + :param str content_url: |
| 493 | + The content url. |
| 494 | + :returns: ContentStreamDownloader for a successful download request. |
| 495 | + :rtype: ~ContentStreamDownloader |
| 496 | + """ |
| 497 | + if not content_url: |
| 498 | + raise ValueError("content_url can not be None") |
| 499 | + |
| 500 | + if not CallingServerUtils.is_valid_url(content_url): |
| 501 | + raise ValueError("content_url is invalid") |
| 502 | + |
| 503 | + content_downloader = ContentDownloader( |
| 504 | + self._callingserver_service_client._client, # pylint:disable=protected-access |
| 505 | + self._callingserver_service_client._serialize, # pylint:disable=protected-access |
| 506 | + self._callingserver_service_client._deserialize, # pylint:disable=protected-access |
| 507 | + self._callingserver_service_client._config) # pylint:disable=protected-access |
| 508 | + stream_downloader = ContentStreamDownloader( |
| 509 | + content_downloader, |
| 510 | + self._callingserver_service_client._config, # pylint:disable=protected-access |
| 511 | + start_range, |
| 512 | + end_range, |
| 513 | + endpoint=content_url, |
| 514 | + parallel_download_options=parallel_download_options, |
| 515 | + **kwargs |
| 516 | + ) |
| 517 | + stream_downloader._setup() # pylint:disable=protected-access |
| 518 | + |
| 519 | + return stream_downloader |
0 commit comments