Skip to content

Commit b9678ea

Browse files
committed
SWI-7428 Add mode attribute to StartStream
1 parent 1ed3484 commit b9678ea

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

bandwidth/models/bxml/verbs/start_stream.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@
99

1010
from ..nestable_verb import NestableVerb
1111
from ..verbs.stream_param import StreamParam
12+
from ...streaming_mode_enum import StreamingModeEnum
1213

1314

1415
class StartStream(NestableVerb):
1516

1617
def __init__(
1718
self, destination: str, stream_params: List[StreamParam] = [],
18-
name: str=None, tracks: str=None,
19+
name: str=None, mode: StreamingModeEnum=None, tracks: str=None,
1920
stream_event_url: str=None,
2021
stream_event_method: str=None,
2122
username: str=None, password: str=None,
2223
):
23-
"""Initialize a <Transfer> verb
24+
"""Initialize a <StartStream> verb
2425
2526
Args:
2627
name (str, optional): A name to refer to this stream by. Used when sending <StopStream>. If not provided, it will default to the generated stream id as sent in the Media Stream Started webhook.
28+
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.
2729
tracks (str, optional): The part of the call to send a stream from. inbound, outbound or both. Default is inbound.
2830
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.
2931
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__(
3840
self.destination = destination
3941
self.stream_params = stream_params
4042
self.name = name
43+
self.mode = mode
4144
self.tracks = tracks
4245
self.stream_event_url = stream_event_url
4346
self.stream_event_method = stream_event_method
@@ -53,6 +56,7 @@ def _attributes(self):
5356
return {
5457
"destination": self.destination,
5558
"name": self.name,
59+
"mode": self.mode.value if self.mode else None,
5660
"tracks": self.tracks,
5761
"streamEventUrl": self.stream_event_url,
5862
"streamEventMethod": self.stream_event_method,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# coding: utf-8
2+
3+
"""
4+
Bandwidth
5+
6+
Bandwidth's Communication APIs
7+
8+
The version of the OpenAPI document: 1.0.0
9+
10+
""" # noqa: E501
11+
12+
13+
from __future__ import annotations
14+
import json
15+
from enum import Enum
16+
from typing_extensions import Self
17+
18+
19+
class StreamingModeEnum(str, Enum):
20+
"""
21+
The Mode to use when streaming audio over the WebSocket. unidirectional or bidirectional.
22+
"""
23+
24+
"""
25+
allowed enum values
26+
"""
27+
UNIDIRECTIONAL = 'unidirectional'
28+
BIDIRECTIONAL = 'bidirectional'
29+
30+
@classmethod
31+
def from_json(cls, json_str: str) -> Self:
32+
"""Create an instance of StreamingModeEnum from a JSON string"""
33+
return cls(json.loads(json_str))

test/unit/models/bxml/test_start_stream.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
import unittest
99

10+
from bandwidth.models.streaming_mode_enum import StreamingModeEnum
1011
from bandwidth.models.bxml import StartStream, StreamParam, Verb, NestableVerb
1112

1213

@@ -47,3 +48,8 @@ def test_add_verb(self):
4748
expected = '<StartStream destination="testurl.com" name="stream1" tracks="inbound" streamEventUrl="eventurl.com" streamEventMethod="POST" username="user" password="pass"><StreamParam name="name1" value="value1" /><StreamParam name="name2" value="value2" /></StartStream>'
4849
self.start_stream.add_verb(self.stream_param2)
4950
assert expected == self.start_stream.to_bxml()
51+
52+
def test_bidirectional(self):
53+
self.start_stream.mode = StreamingModeEnum.BIDIRECTIONAL
54+
expected = '<StartStream destination="testurl.com" name="stream1" mode="bidirectional" tracks="inbound" streamEventUrl="eventurl.com" streamEventMethod="POST" username="user" password="pass"><StreamParam name="name1" value="value1" /></StartStream>'
55+
assert expected == self.start_stream.to_bxml()

0 commit comments

Comments
 (0)