Skip to content

Commit 576e6ea

Browse files
committed
changing audio streamer -> audio connector, fixing typos
1 parent 4065a01 commit 576e6ea

File tree

8 files changed

+49
-51
lines changed

8 files changed

+49
-51
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release v3.4.0
22

3-
- Support for Audio Streamer (lite) API via `stream_audio_to_websocket` method
3+
- Support for Audio Connector API via `connect_audio_to_websocket` method
44

55
# Release v3.3.0
66

README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,18 @@ For more information about OpenTok live streaming broadcasts, see the
551551
`Broadcast developer guide <https://tokbox.com/developer/guides/broadcast/>`_.
552552

553553

554-
Streaming audio to a websocket
554+
Streaming audio to a WebSocket
555555
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
556-
You can stream audio to a websocket with the ``opentok.stream_audio_to_websocket`` method.
556+
You can stream audio to a WebSocket with the ``opentok.connect_audio_to_websocket`` method.
557557
For more information, see the
558-
`Audio Streamer developer guide <https://tokbox.com/developer/guides/audio-streamer/>`_.
558+
`Audio Connector developer guide <https://tokbox.com/developer/guides/audio-streamer/>`_.
559559

560560
.. code:: python
561561
562562
websocket_options = {"uri": "wss://service.com/ws-endpoint"}
563-
websocket_audio_connection = opentok.stream_audio_to_websocket(session_id, opentok_token, websocket_options)
563+
websocket_audio_connection = opentok.connect_audio_to_websocket(session_id, opentok_token, websocket_options)
564564
565-
Additionally, you can list only the specific streams you want to send to the websocket, and/or the additional headers that are sent,
565+
Additionally, you can list only the specific streams you want to send to the WebSocket, and/or the additional headers that are sent,
566566
by adding these fields to the ``websocket_options`` object.
567567

568568
.. code:: python

opentok/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
from .sip_call import SipCall
1616
from .broadcast import Broadcast, BroadcastStreamModes
1717
from .render import Render, RenderList
18-
from .websocket_audio_connection import WebsocketAudioConnection
18+
from .websocket_audio_connection import WebSocketAudioConnection

opentok/endpoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ def get_render_url(self, render_id: str = None):
209209

210210
return url
211211

212-
def get_audio_streamer_url(self):
213-
"""Returns URLs for working with the Audio Streamer (lite) API."""
212+
def get_audio_connector_url(self):
213+
"""Returns URLs for working with the Audio Connector API."""
214214
url = self.api_url + "/v2/project/" + self.api_key + "/connect"
215215

216216
return url

opentok/exceptions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ class BroadcastStreamModeError(OpenTokException):
107107
Indicates that the broadcast is configured with a streamMode that does not support stream manipulation.
108108
"""
109109

110-
pass
111-
112110

113111
class BroadcastHLSOptionsError(OpenTokException):
114112
"""
@@ -118,9 +116,9 @@ class BroadcastHLSOptionsError(OpenTokException):
118116
"""
119117

120118

121-
class InvalidWebsocketOptionsError(OpenTokException):
119+
class InvalidWebSocketOptionsError(OpenTokException):
122120
"""
123-
Indicates that the websocket options selected are invalid.
121+
Indicates that the WebSocket options selected are invalid.
124122
"""
125123

126124

opentok/opentok.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .streamlist import StreamList
3333
from .sip_call import SipCall
3434
from .broadcast import Broadcast, BroadcastStreamModes
35-
from .websocket_audio_connection import WebsocketAudioConnection
35+
from .websocket_audio_connection import WebSocketAudioConnection
3636
from .exceptions import (
3737
ArchiveStreamModeError,
3838
BroadcastHLSOptionsError,
@@ -49,7 +49,7 @@
4949
SetStreamClassError,
5050
BroadcastError,
5151
DTMFError,
52-
InvalidWebsocketOptionsError,
52+
InvalidWebSocketOptionsError,
5353
InvalidMediaModeError
5454
)
5555

@@ -1804,14 +1804,14 @@ def list_renders(self, offset=0, count=50):
18041804
else:
18051805
raise RequestError("An unexpected error occurred", response.status_code)
18061806

1807-
def stream_audio_to_websocket(self, session_id: str, opentok_token: str, websocket_options: dict):
1807+
def connect_audio_to_websocket(self, session_id: str, opentok_token: str, websocket_options: dict):
18081808
"""
1809-
Connects audio streams to a specified websocket URI.
1810-
For more information, see the `Audio Streamer developer guide <https://tokbox.com/developer/guides/audio-streamer/>`.
1809+
Connects audio streams to a specified WebSocket URI.
1810+
For more information, see the `Audio Connector developer guide <https://tokbox.com/developer/guides/audio-streamer/>`.
18111811
1812-
:param String 'session_id': The OpenTok session ID that includes the OpenTok streams you want to include in the WebSocket stream. The Audio Streamer feature is only supported in routed sessions (sessions that use the OpenTok Media Router).
1813-
:param String 'opentok_token': The OpenTok token to be used for the Audio Streamer connection to the OpenTok session.
1814-
:param Dictionary 'websocket_options': Included options for the websocket.
1812+
:param String 'session_id': The OpenTok session ID that includes the OpenTok streams you want to include in the WebSocket stream. The Audio Connector feature is only supported in routed sessions (sessions that use the OpenTok Media Router).
1813+
:param String 'opentok_token': The OpenTok token to be used for the Audio Connector connection to the OpenTok session.
1814+
:param Dictionary 'websocket_options': Included options for the WebSocket.
18151815
String 'uri': A publicly reachable WebSocket URI to be used for the destination of the audio stream (such as "wss://example.com/ws-endpoint").
18161816
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.
18171817
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.
@@ -1826,22 +1826,22 @@ def stream_audio_to_websocket(self, session_id: str, opentok_token: str, websock
18261826

18271827
logger.debug(
18281828
"POST to %r with params %r, headers %r, proxies %r",
1829-
self.endpoints.get_audio_streamer_url(),
1829+
self.endpoints.get_audio_connector_url(),
18301830
json.dumps(payload),
18311831
self.get_json_headers(),
18321832
self.proxies,
18331833
)
18341834

18351835
response = requests.post(
1836-
self.endpoints.get_audio_streamer_url(),
1836+
self.endpoints.get_audio_connector_url(),
18371837
json=payload,
18381838
headers=self.get_json_headers(),
18391839
proxies=self.proxies,
18401840
timeout=self.timeout,
18411841
)
18421842

18431843
if response and response.status_code == 200:
1844-
return WebsocketAudioConnection(response.json())
1844+
return WebSocketAudioConnection(response.json())
18451845
elif response.status_code == 400:
18461846
"""
18471847
The HTTP response has a 400 status code in the following cases:
@@ -1852,15 +1852,15 @@ def stream_audio_to_websocket(self, session_id: str, opentok_token: str, websock
18521852
elif response.status_code == 403:
18531853
raise AuthError("You passed in an invalid OpenTok API key or JWT token.")
18541854
elif response.status_code == 409:
1855-
raise InvalidMediaModeError("Only routed sessions are allowed to initiate Audio Streamer WebSocket connections.")
1855+
raise InvalidMediaModeError("Only routed sessions are allowed to initiate Audio Connector WebSocket connections.")
18561856
else:
18571857
raise RequestError("An unexpected error occurred", response.status_code)
18581858

18591859
def validate_websocket_options(self, options):
18601860
if type(options) is not dict:
1861-
raise InvalidWebsocketOptionsError('Must pass websocket options as a dictionary.')
1861+
raise InvalidWebSocketOptionsError('Must pass WebSocket options as a dictionary.')
18621862
if 'uri' not in options:
1863-
raise InvalidWebsocketOptionsError('Provide a websocket URI.')
1863+
raise InvalidWebSocketOptionsError('Provide a WebSocket URI.')
18641864

18651865
def _sign_string(self, string, secret):
18661866
return hmac.new(

opentok/websocket_audio_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import json
22
from six import iteritems
33

4-
class WebsocketAudioConnection:
5-
"""Represents information about the audio streaming of an OpenTok session to a websocket."""
4+
class WebSocketAudioConnection:
5+
"""Represents information about the audio connection of an OpenTok session to a WebSocket."""
66

77
def __init__(self, kwargs):
88
self.id = kwargs.get("id")
99
self.connectionId = kwargs.get("connectionId")
1010

1111
def json(self):
12-
"""Returns a JSON representation of the websocket audio connection information."""
12+
"""Returns a JSON representation of the WebSocket audio connection information."""
1313
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
1414

1515
def attrs(self):
1616
"""
17-
Returns a dictionary of the websocket audio connection's attributes.
17+
Returns a dictionary of the WebSocket audio connection's attributes.
1818
"""
1919
return dict((k, v) for k, v in iteritems(self.__dict__))

tests/test_audio_streamer.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from six import u, PY2, PY3
88
from expects import *
9-
from opentok import Client, WebsocketAudioConnection, __version__
10-
from opentok.exceptions import InvalidWebsocketOptionsError, InvalidMediaModeError
9+
from opentok import Client, WebSocketAudioConnection, __version__
10+
from opentok.exceptions import InvalidWebSocketOptionsError, InvalidMediaModeError
1111
from .validate_jwt import validate_jwt_header
1212

1313

@@ -30,7 +30,7 @@ def setUp(self):
3030
)
3131

3232
@httpretty.activate
33-
def test_stream_audio_to_websocket(self):
33+
def test_connect_audio_to_websocket(self):
3434
httpretty.register_uri(
3535
httpretty.POST,
3636
u(f"https://api.opentok.com/v2/project/{self.api_key}/connect"),
@@ -43,7 +43,7 @@ def test_stream_audio_to_websocket(self):
4343
"uri": "wss://service.com/ws-endpoint"
4444
}
4545

46-
websocket_audio_connection = self.opentok.stream_audio_to_websocket(self.session_id, self.token, websocket_options)
46+
websocket_audio_connection = self.opentok.connect_audio_to_websocket(self.session_id, self.token, websocket_options)
4747

4848
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
4949
expect(httpretty.last_request().headers[u("user-agent")]).to(
@@ -60,7 +60,7 @@ def test_stream_audio_to_websocket(self):
6060
body = json.loads(httpretty.last_request().body.decode("utf-8"))
6161

6262
expect(body).to(have_key(u("token")))
63-
expect(websocket_audio_connection).to(be_a(WebsocketAudioConnection))
63+
expect(websocket_audio_connection).to(be_a(WebSocketAudioConnection))
6464
expect(websocket_audio_connection).to(
6565
have_property(u("id"), u("b0a5a8c7-dc38-459f-a48d-a7f2008da853"))
6666
)
@@ -69,7 +69,7 @@ def test_stream_audio_to_websocket(self):
6969
)
7070

7171
@httpretty.activate
72-
def test_stream_audio_to_websocket_custom_options(self):
72+
def test_connect_audio_to_websocket_custom_options(self):
7373
httpretty.register_uri(
7474
httpretty.POST,
7575
u(f"https://api.opentok.com/v2/project/{self.api_key}/connect"),
@@ -82,11 +82,11 @@ def test_stream_audio_to_websocket_custom_options(self):
8282
"uri": "wss://service.com/ws-endpoint",
8383
"streams": ["stream-id-1", "stream-id-2"],
8484
"headers": {
85-
"websocketHeader": "Sent via Audio Streamer API"
85+
"WebSocketHeader": "Sent via Audio Connector API"
8686
}
8787
}
8888

89-
websocket_audio_connection = self.opentok.stream_audio_to_websocket(self.session_id, self.token, websocket_options)
89+
websocket_audio_connection = self.opentok.connect_audio_to_websocket(self.session_id, self.token, websocket_options)
9090

9191
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
9292
expect(httpretty.last_request().headers[u("user-agent")]).to(
@@ -103,7 +103,7 @@ def test_stream_audio_to_websocket_custom_options(self):
103103
body = json.loads(httpretty.last_request().body.decode("utf-8"))
104104

105105
expect(body).to(have_key(u("token")))
106-
expect(websocket_audio_connection).to(be_a(WebsocketAudioConnection))
106+
expect(websocket_audio_connection).to(be_a(WebSocketAudioConnection))
107107
expect(websocket_audio_connection).to(
108108
have_property(u("id"), u("b0a5a8c7-dc38-459f-a48d-a7f2008da853"))
109109
)
@@ -112,7 +112,7 @@ def test_stream_audio_to_websocket_custom_options(self):
112112
)
113113

114114
@httpretty.activate
115-
def test_stream_audio_to_websocket_media_mode_error(self):
115+
def test_connect_audio_to_websocket_media_mode_error(self):
116116
httpretty.register_uri(
117117
httpretty.POST,
118118
u(f"https://api.opentok.com/v2/project/{self.api_key}/connect"),
@@ -128,8 +128,8 @@ def test_stream_audio_to_websocket_media_mode_error(self):
128128
session_id = "session-where-mediaMode=relayed-was-selected"
129129

130130
with self.assertRaises(InvalidMediaModeError) as context:
131-
self.opentok.stream_audio_to_websocket(session_id, self.token, websocket_options)
132-
self.assertTrue("Only routed sessions are allowed to initiate Audio Streamer WebSocket connections." in str(context.exception))
131+
self.opentok.connect_audio_to_websocket(session_id, self.token, websocket_options)
132+
self.assertTrue("Only routed sessions are allowed to initiate Audio Connector WebSocket connections." in str(context.exception))
133133

134134
validate_jwt_header(self, httpretty.last_request().headers[u("x-opentok-auth")])
135135
expect(httpretty.last_request().headers[u("user-agent")]).to(
@@ -139,14 +139,14 @@ def test_stream_audio_to_websocket_media_mode_error(self):
139139
equal(u("application/json"))
140140
)
141141

142-
def test_stream_audio_to_websocket_invalid_options_type_error(self):
142+
def test_connect_audio_to_websocket_invalid_options_type_error(self):
143143
websocket_options = "wss://service.com/ws-endpoint"
144-
with self.assertRaises(InvalidWebsocketOptionsError) as context:
145-
self.opentok.stream_audio_to_websocket(self.session_id, self.token, websocket_options)
146-
self.assertTrue("Must pass websocket options as a dictionary." in str(context.exception))
144+
with self.assertRaises(InvalidWebSocketOptionsError) as context:
145+
self.opentok.connect_audio_to_websocket(self.session_id, self.token, websocket_options)
146+
self.assertTrue("Must pass WebSocket options as a dictionary." in str(context.exception))
147147

148-
def test_stream_audio_to_websocket_missing_uri_error(self):
148+
def test_connect_audio_to_websocket_missing_uri_error(self):
149149
websocket_options = {}
150-
with self.assertRaises(InvalidWebsocketOptionsError) as context:
151-
self.opentok.stream_audio_to_websocket(self.session_id, self.token, websocket_options)
152-
self.assertTrue("Provide a websocket URI." in str(context.exception))
150+
with self.assertRaises(InvalidWebSocketOptionsError) as context:
151+
self.opentok.connect_audio_to_websocket(self.session_id, self.token, websocket_options)
152+
self.assertTrue("Provide a WebSocket URI." in str(context.exception))

0 commit comments

Comments
 (0)