From b9678ea6a678f466a86135f0bb740ee422dab8a5 Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Fri, 21 Mar 2025 10:00:55 -0400 Subject: [PATCH 1/2] SWI-7428 Add `mode` attribute to `StartStream` --- bandwidth/models/bxml/verbs/start_stream.py | 8 +++-- bandwidth/models/streaming_mode_enum.py | 33 +++++++++++++++++++++ test/unit/models/bxml/test_start_stream.py | 6 ++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 bandwidth/models/streaming_mode_enum.py diff --git a/bandwidth/models/bxml/verbs/start_stream.py b/bandwidth/models/bxml/verbs/start_stream.py index a4fd274b..37cecad2 100644 --- a/bandwidth/models/bxml/verbs/start_stream.py +++ b/bandwidth/models/bxml/verbs/start_stream.py @@ -9,21 +9,23 @@ from ..nestable_verb import NestableVerb from ..verbs.stream_param import StreamParam +from ...streaming_mode_enum import StreamingModeEnum class StartStream(NestableVerb): def __init__( self, destination: str, stream_params: List[StreamParam] = [], - name: str=None, tracks: str=None, + name: str=None, mode: StreamingModeEnum=None, tracks: str=None, stream_event_url: str=None, stream_event_method: str=None, username: str=None, password: str=None, ): - """Initialize a verb + """Initialize a verb Args: name (str, optional): A name to refer to this stream by. Used when sending . If not provided, it will default to the generated stream id as sent in the Media Stream Started webhook. + mode (str, optional): The mode to use for the stream. unidirectional or bidirectional. Specifies whether the audio being streamed over the WebSocket is bidirectional (the service can both read and write audio over the WebSocket) or unidirectional (one-way, read-only). Default is unidirectional. tracks (str, optional): The part of the call to send a stream from. inbound, outbound or both. Default is inbound. destination (str, optional): A websocket URI to send the stream to. The audio from the specified tracks will be sent via websocket to this URL as base64-encoded PCMU/G711 audio. See below for more details on the websocket packet format. stream_event_url (str, optional): URL to send the associated Webhook events to during this stream's lifetime. Does not accept BXML. May be a relative URL. @@ -38,6 +40,7 @@ def __init__( self.destination = destination self.stream_params = stream_params self.name = name + self.mode = mode self.tracks = tracks self.stream_event_url = stream_event_url self.stream_event_method = stream_event_method @@ -53,6 +56,7 @@ def _attributes(self): return { "destination": self.destination, "name": self.name, + "mode": self.mode.value if self.mode else None, "tracks": self.tracks, "streamEventUrl": self.stream_event_url, "streamEventMethod": self.stream_event_method, diff --git a/bandwidth/models/streaming_mode_enum.py b/bandwidth/models/streaming_mode_enum.py new file mode 100644 index 00000000..d4f16968 --- /dev/null +++ b/bandwidth/models/streaming_mode_enum.py @@ -0,0 +1,33 @@ +# coding: utf-8 + +""" + Bandwidth + + Bandwidth's Communication APIs + + The version of the OpenAPI document: 1.0.0 + Contact: letstalk@bandwidth.com +""" # noqa: E501 + + +from __future__ import annotations +import json +from enum import Enum +from typing_extensions import Self + + +class StreamingModeEnum(str, Enum): + """ + The Mode to use when streaming audio over the WebSocket. unidirectional or bidirectional. + """ + + """ + allowed enum values + """ + UNIDIRECTIONAL = 'unidirectional' + BIDIRECTIONAL = 'bidirectional' + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of StreamingModeEnum from a JSON string""" + return cls(json.loads(json_str)) diff --git a/test/unit/models/bxml/test_start_stream.py b/test/unit/models/bxml/test_start_stream.py index 8013e916..573213d0 100644 --- a/test/unit/models/bxml/test_start_stream.py +++ b/test/unit/models/bxml/test_start_stream.py @@ -7,6 +7,7 @@ """ import unittest +from bandwidth.models.streaming_mode_enum import StreamingModeEnum from bandwidth.models.bxml import StartStream, StreamParam, Verb, NestableVerb @@ -47,3 +48,8 @@ def test_add_verb(self): expected = '' self.start_stream.add_verb(self.stream_param2) assert expected == self.start_stream.to_bxml() + + def test_bidirectional(self): + self.start_stream.mode = StreamingModeEnum.BIDIRECTIONAL + expected = '' + assert expected == self.start_stream.to_bxml() From c734e0d54d6fc8ed6d7e1451fdd5483751215ed8 Mon Sep 17 00:00:00 2001 From: AJ Rice <53190766+ajrice6713@users.noreply.github.com> Date: Fri, 21 Mar 2025 16:26:07 -0400 Subject: [PATCH 2/2] str instead of enum to remain conssitent --- bandwidth/models/bxml/verbs/start_stream.py | 5 ++-- bandwidth/models/streaming_mode_enum.py | 33 --------------------- test/unit/models/bxml/test_start_stream.py | 11 ++----- 3 files changed, 5 insertions(+), 44 deletions(-) delete mode 100644 bandwidth/models/streaming_mode_enum.py diff --git a/bandwidth/models/bxml/verbs/start_stream.py b/bandwidth/models/bxml/verbs/start_stream.py index 37cecad2..0d8768db 100644 --- a/bandwidth/models/bxml/verbs/start_stream.py +++ b/bandwidth/models/bxml/verbs/start_stream.py @@ -9,14 +9,13 @@ from ..nestable_verb import NestableVerb from ..verbs.stream_param import StreamParam -from ...streaming_mode_enum import StreamingModeEnum class StartStream(NestableVerb): def __init__( self, destination: str, stream_params: List[StreamParam] = [], - name: str=None, mode: StreamingModeEnum=None, tracks: str=None, + name: str=None, mode: str=None, tracks: str=None, stream_event_url: str=None, stream_event_method: str=None, username: str=None, password: str=None, @@ -56,7 +55,7 @@ def _attributes(self): return { "destination": self.destination, "name": self.name, - "mode": self.mode.value if self.mode else None, + "mode": self.mode, "tracks": self.tracks, "streamEventUrl": self.stream_event_url, "streamEventMethod": self.stream_event_method, diff --git a/bandwidth/models/streaming_mode_enum.py b/bandwidth/models/streaming_mode_enum.py deleted file mode 100644 index d4f16968..00000000 --- a/bandwidth/models/streaming_mode_enum.py +++ /dev/null @@ -1,33 +0,0 @@ -# coding: utf-8 - -""" - Bandwidth - - Bandwidth's Communication APIs - - The version of the OpenAPI document: 1.0.0 - Contact: letstalk@bandwidth.com -""" # noqa: E501 - - -from __future__ import annotations -import json -from enum import Enum -from typing_extensions import Self - - -class StreamingModeEnum(str, Enum): - """ - The Mode to use when streaming audio over the WebSocket. unidirectional or bidirectional. - """ - - """ - allowed enum values - """ - UNIDIRECTIONAL = 'unidirectional' - BIDIRECTIONAL = 'bidirectional' - - @classmethod - def from_json(cls, json_str: str) -> Self: - """Create an instance of StreamingModeEnum from a JSON string""" - return cls(json.loads(json_str)) diff --git a/test/unit/models/bxml/test_start_stream.py b/test/unit/models/bxml/test_start_stream.py index 573213d0..a934ce46 100644 --- a/test/unit/models/bxml/test_start_stream.py +++ b/test/unit/models/bxml/test_start_stream.py @@ -7,7 +7,6 @@ """ import unittest -from bandwidth.models.streaming_mode_enum import StreamingModeEnum from bandwidth.models.bxml import StartStream, StreamParam, Verb, NestableVerb @@ -27,6 +26,7 @@ def setUp(self): self.start_stream = StartStream( stream_params=[self.stream_param1], name = "stream1", + mode = "bidirectional", tracks = "inbound", destination = "testurl.com", stream_event_url="eventurl.com", @@ -41,15 +41,10 @@ def test_instance(self): assert isinstance(self.start_stream, Verb) def test_to_bxml(self): - expected = '' + expected = '' assert expected == self.start_stream.to_bxml() def test_add_verb(self): - expected = '' + expected = '' self.start_stream.add_verb(self.stream_param2) assert expected == self.start_stream.to_bxml() - - def test_bidirectional(self): - self.start_stream.mode = StreamingModeEnum.BIDIRECTIONAL - expected = '' - assert expected == self.start_stream.to_bxml()