Skip to content

Commit f1aca17

Browse files
Merge branch 'main' into devx-9571-add-quantization-parameter
2 parents 6fd8f46 + 723e3a0 commit f1aca17

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

opentok/opentok.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,7 @@ def connect_audio_to_websocket(
20092009
String 'uri': A publicly reachable WebSocket URI to be used for the destination of the audio stream (such as "wss://example.com/ws-endpoint").
20102010
List 'streams' Optional: A list of stream IDs for the OpenTok streams you want to include in the WebSocket audio. If you omit this property, all streams in the session will be included.
20112011
Dictionary 'headers' Optional: An object of key-value pairs of headers to be sent to your WebSocket server with each message, with a maximum length of 512 bytes.
2012+
Boolean 'bidirectional' Optional: If true, enables bidirectional audio streaming over the WebSocket connection.
20122013
"""
20132014
self.validate_websocket_options(websocket_options)
20142015

@@ -2060,6 +2061,10 @@ def validate_websocket_options(self, options):
20602061
if "uri" not in options:
20612062
raise InvalidWebSocketOptionsError("Provide a WebSocket URI.")
20622063

2064+
if "bidirectional" in options:
2065+
if not isinstance(options["bidirectional"], bool):
2066+
raise InvalidWebSocketOptionsError("'bidirectional' must be a boolean if provided.")
2067+
20632068
def start_captions(
20642069
self,
20652070
session_id: str,

opentok/websocket_audio_connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class WebSocketAudioConnection:
77
def __init__(self, kwargs):
88
self.id = kwargs.get("id")
99
self.connectionId = kwargs.get("connectionId")
10+
self.bidirectional = kwargs.get("bidirectional")
1011

1112
def json(self):
1213
"""Returns a JSON representation of the WebSocket audio connection information."""

tests/test_audio_connector.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,38 @@
1212

1313

1414
class OpenTokAudioConnectorLiteTest(unittest.TestCase):
15+
@httpretty.activate
16+
def test_connect_audio_to_websocket_with_bidirectional(self):
17+
httpretty.register_uri(
18+
httpretty.POST,
19+
u(f"https://api.opentok.com/v2/project/{self.api_key}/connect"),
20+
body=self.response_body,
21+
status=200,
22+
content_type=u("application/json"),
23+
)
24+
25+
websocket_options = {"uri": "wss://service.com/ws-endpoint", "bidirectional": True}
26+
27+
websocket_audio_connection = self.opentok.connect_audio_to_websocket(
28+
self.session_id, self.token, websocket_options
29+
)
30+
31+
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
32+
expect(httpretty.last_request().headers[u("user-agent")]).to(contain(u("OpenTok-Python-SDK/") + __version__))
33+
expect(httpretty.last_request().headers[u("content-type")]).to(equal(u("application/json")))
34+
if PY2:
35+
body = json.loads(httpretty.last_request().body)
36+
if PY3:
37+
body = json.loads(httpretty.last_request().body.decode("utf-8"))
38+
39+
expect(body).to(have_key(u("token")))
40+
expect(body["websocket"]).to(have_key("bidirectional"))
41+
expect(body["websocket"]["bidirectional"]).to(be_true)
42+
expect(websocket_audio_connection).to(be_a(WebSocketAudioConnection))
43+
expect(websocket_audio_connection).to(have_property(u("id"), u("b0a5a8c7-dc38-459f-a48d-a7f2008da853")))
44+
expect(websocket_audio_connection).to(have_property(u("connectionId"), u("e9f8c166-6c67-440d-994a-04fb6dfed007")))
45+
# The bidirectional property should be present (None if not in response, True if in response)
46+
expect(hasattr(websocket_audio_connection, "bidirectional")).to(be_true)
1547
def setUp(self):
1648
self.api_key = u("123456")
1749
self.api_secret = u("1234567890abcdef1234567890abcdef1234567890")

0 commit comments

Comments
 (0)