Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions opentok/opentok.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,7 @@ def connect_audio_to_websocket(
String 'uri': A publicly reachable WebSocket URI to be used for the destination of the audio stream (such as "wss://example.com/ws-endpoint").
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.
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.
Boolean 'bidirectional' Optional: If true, enables bidirectional audio streaming over the WebSocket connection.
"""
self.validate_websocket_options(websocket_options)

Expand Down Expand Up @@ -2044,6 +2045,10 @@ def validate_websocket_options(self, options):
if "uri" not in options:
raise InvalidWebSocketOptionsError("Provide a WebSocket URI.")

if "bidirectional" in options:
if not isinstance(options["bidirectional"], bool):
raise InvalidWebSocketOptionsError("'bidirectional' must be a boolean if provided.")

def start_captions(
self,
session_id: str,
Expand Down
2 changes: 1 addition & 1 deletion opentok/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# see: http://legacy.python.org/dev/peps/pep-0440/#public-version-identifiers
__version__ = "3.11.1"
__version__ = "3.12.0"

1 change: 1 addition & 0 deletions opentok/websocket_audio_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WebSocketAudioConnection:
def __init__(self, kwargs):
self.id = kwargs.get("id")
self.connectionId = kwargs.get("connectionId")
self.bidirectional = kwargs.get("bidirectional")

def json(self):
"""Returns a JSON representation of the WebSocket audio connection information."""
Expand Down
32 changes: 32 additions & 0 deletions tests/test_audio_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@


class OpenTokAudioConnectorLiteTest(unittest.TestCase):
@httpretty.activate
def test_connect_audio_to_websocket_with_bidirectional(self):
httpretty.register_uri(
httpretty.POST,
u(f"https://api.opentok.com/v2/project/{self.api_key}/connect"),
body=self.response_body,
status=200,
content_type=u("application/json"),
)

websocket_options = {"uri": "wss://service.com/ws-endpoint", "bidirectional": True}

websocket_audio_connection = self.opentok.connect_audio_to_websocket(
self.session_id, self.token, websocket_options
)

validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
expect(httpretty.last_request().headers[u("user-agent")]).to(contain(u("OpenTok-Python-SDK/") + __version__))
expect(httpretty.last_request().headers[u("content-type")]).to(equal(u("application/json")))
if PY2:
body = json.loads(httpretty.last_request().body)
if PY3:
body = json.loads(httpretty.last_request().body.decode("utf-8"))

expect(body).to(have_key(u("token")))
expect(body["websocket"]).to(have_key("bidirectional"))
expect(body["websocket"]["bidirectional"]).to(be_true)
expect(websocket_audio_connection).to(be_a(WebSocketAudioConnection))
expect(websocket_audio_connection).to(have_property(u("id"), u("b0a5a8c7-dc38-459f-a48d-a7f2008da853")))
expect(websocket_audio_connection).to(have_property(u("connectionId"), u("e9f8c166-6c67-440d-994a-04fb6dfed007")))
# The bidirectional property should be present (None if not in response, True if in response)
expect(hasattr(websocket_audio_connection, "bidirectional")).to(be_true)
def setUp(self):
self.api_key = u("123456")
self.api_secret = u("1234567890abcdef1234567890abcdef1234567890")
Expand Down