Skip to content

Commit e502713

Browse files
authored
Merge pull request #224 from opentok/fix-streams-methods
Fix streams methods
2 parents 9ddaf26 + 2af883e commit e502713

7 files changed

+227
-290
lines changed

.bumpversion.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.6.0
2+
current_version = 3.6.1
33
commit = True
44
tag = False
55

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Release v3.6.1
2+
- Fixed broken `opentok.Client.add_archive_stream`, `opentok.Client.remove_archive_stream`, `opentok.Client.add_broadcast_stream` and `opentok.Client.remove_broadcast_stream` methods and tests
3+
- Fixed `opentok.Endpoints.get_archive_stream` and `opentok.Endpoints.get_broadcast_stream` methods
4+
15
# Release v3.6.0
26
- Added auto-archive improvements to the `opentok.Client.create_session` method
37
to customize automatically created archives:

opentok/endpoints.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class Endpoints(object):
77
Class that provides the endpoint urls
88
"""
99

10-
1110
def __init__(self, api_url, api_key):
1211
self.api_url = api_url
1312
self.api_key = api_key
@@ -57,7 +56,7 @@ def signaling_url(self, session_id, connection_id=None):
5756
return self.get_signaling_url(session_id, connection_id)
5857

5958
def get_stream_url(self, session_id, stream_id=None):
60-
""" this method returns the url to get streams information """
59+
"""this method returns the url to get streams information"""
6160
url = (
6261
self.api_url
6362
+ "/v2/project/"
@@ -79,7 +78,7 @@ def broadcast_url(self, broadcast_id=None, stop=False, layout=False):
7978
return self.get_broadcast_url(broadcast_id, stop, layout)
8079

8180
def force_disconnect_url(self, session_id, connection_id):
82-
""" this method returns the force disconnect url endpoint """
81+
"""this method returns the force disconnect url endpoint"""
8382
url = (
8483
self.api_url
8584
+ "/v2/project/"
@@ -92,7 +91,7 @@ def force_disconnect_url(self, session_id, connection_id):
9291
return url
9392

9493
def set_archive_layout_url(self, archive_id):
95-
""" this method returns the url to set the archive layout """
94+
"""this method returns the url to set the archive layout"""
9695
url = (
9796
self.api_url
9897
+ "/v2/project/"
@@ -104,12 +103,12 @@ def set_archive_layout_url(self, archive_id):
104103
return url
105104

106105
def dial_url(self):
107-
""" this method returns the url to initialize a SIP call """
106+
"""this method returns the url to initialize a SIP call"""
108107
url = self.api_url + "/v2/project/" + self.api_key + "/dial"
109108
return url
110109

111110
def set_stream_class_lists_url(self, session_id):
112-
""" this method returns the url to set the stream class list """
111+
"""this method returns the url to set the stream class list"""
113112
url = (
114113
self.api_url
115114
+ "/v2/project/"
@@ -121,7 +120,7 @@ def set_stream_class_lists_url(self, session_id):
121120
return url
122121

123122
def get_broadcast_url(self, broadcast_id=None, stop=False, layout=False):
124-
""" this method returns urls for working with broadcast """
123+
"""this method returns urls for working with broadcast"""
125124
url = self.api_url + "/v2/project/" + self.api_key + "/broadcast"
126125

127126
if broadcast_id:
@@ -130,28 +129,27 @@ def get_broadcast_url(self, broadcast_id=None, stop=False, layout=False):
130129
url = url + "/stop"
131130
if layout:
132131
url = url + "/layout"
133-
132+
134133
return url
135134

136135
def get_mute_all_url(self, session_id):
137-
""" this method returns the urls for muting every stream in a session """
136+
"""this method returns the urls for muting every stream in a session"""
138137
url = (
139-
self.api_url
140-
+ "/v2/project/"
138+
self.api_url
139+
+ "/v2/project/"
141140
+ self.api_key
142141
+ "/session/"
143142
+ session_id
144143
+ "/mute"
145-
146144
)
147145

148146
return url
149147

150148
def get_dtmf_all_url(self, session_id):
151-
""" this method returns the url for Play DTMF to all clients in the session """
149+
"""this method returns the url for Play DTMF to all clients in the session"""
152150
url = (
153151
self.api_url
154-
+ "/v2/project/"
152+
+ "/v2/project/"
155153
+ self.api_key
156154
+ "/session/"
157155
+ session_id
@@ -161,7 +159,7 @@ def get_dtmf_all_url(self, session_id):
161159
return url
162160

163161
def get_dtmf_specific_url(self, session_id, connection_id):
164-
""" this method returns the url for Play DTMF to a specific client connection"""
162+
"""this method returns the url for Play DTMF to a specific client connection"""
165163
url = (
166164
self.api_url
167165
+ "/v2/project/"
@@ -176,33 +174,33 @@ def get_dtmf_specific_url(self, session_id, connection_id):
176174
return url
177175

178176
def get_archive_stream(self, archive_id=None):
179-
""" this method returns urls for working with streamModes in archives """
177+
"""this method returns urls for working with streamModes in archives"""
180178
url = (
181179
self.api_url
182180
+ "/v2/project/"
183181
+ self.api_key
184-
+ "archive/"
182+
+ "/archive/"
185183
+ archive_id
186184
+ "/streams"
187185
)
188186

189187
return url
190188

191189
def get_broadcast_stream(self, broadcast_id=None):
192-
""" this method returns urls for working with streamModes in broadcasts """
190+
"""this method returns urls for working with streamModes in broadcasts"""
193191
url = (
194192
self.api_url
195-
+ "/v2/partner/"
193+
+ "/v2/project/"
196194
+ self.api_key
197-
+ "broadcast/"
195+
+ "/broadcast/"
198196
+ broadcast_id
199197
+ "/streams"
200198
)
201199

202200
return url
203201

204202
def get_render_url(self, render_id: str = None):
205-
"Returns URLs for working with the Render API."""
203+
"Returns URLs for working with the Render API." ""
206204
url = self.api_url + "/v2/project/" + self.api_key + "/render"
207205
if render_id:
208206
url += "/" + render_id
@@ -212,5 +210,5 @@ def get_render_url(self, render_id: str = None):
212210
def get_audio_connector_url(self):
213211
"""Returns URLs for working with the Audio Connector API."""
214212
url = self.api_url + "/v2/project/" + self.api_key + "/connect"
215-
213+
216214
return url

opentok/opentok.py

+99-94
Original file line numberDiff line numberDiff line change
@@ -864,28 +864,29 @@ def add_archive_stream(
864864
)
865865

866866
if response:
867-
return Archive(self, response.json())
868-
elif response.status_code == 403:
869-
raise AuthError()
870-
elif response.status_code == 400:
871-
"""
872-
The HTTP response has a 400 status code in the following cases:
873-
You do not pass in a session ID or you pass in an invalid session ID.
874-
No clients are actively connected to the OpenTok session.
875-
You specify an invalid resolution value.
876-
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
877-
"""
878-
raise RequestError(response.json().get("message"))
879-
elif response.status_code == 404:
880-
raise NotFoundError("Archive or Stream not found")
881-
elif response.status_code == 405:
882-
raise ArchiveStreamModeError(
883-
"Your archive is configured with a streamMode that does not support stream manipulation."
884-
)
885-
elif response.status_code == 409:
886-
raise ArchiveError(response.json().get("message"))
867+
if response.status_code == 204:
868+
return None
869+
elif response.status_code == 403:
870+
raise AuthError()
871+
elif response.status_code == 400:
872+
"""
873+
The HTTP response has a 400 status code in the following cases:
874+
You do not pass in a session ID or you pass in an invalid session ID.
875+
No clients are actively connected to the OpenTok session.
876+
You specify an invalid resolution value.
877+
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
878+
"""
879+
raise RequestError(response.json().get("message"))
880+
elif response.status_code == 404:
881+
raise NotFoundError("Archive or Stream not found")
882+
elif response.status_code == 405:
883+
raise ArchiveStreamModeError(
884+
"Your archive is configured with a streamMode that does not support stream manipulation."
885+
)
886+
elif response.status_code == 409:
887+
raise ArchiveError(response.json().get("message"))
887888
else:
888-
raise RequestError("An unexpected error occurred", response.status_code)
889+
raise RequestError("An unexpected error occurred.", response.status_code)
889890

890891
def remove_archive_stream(
891892
self, archive_id: str, stream_id: str
@@ -910,28 +911,29 @@ def remove_archive_stream(
910911
)
911912

912913
if response:
913-
return Archive(self, response.json())
914-
elif response.status_code == 403:
915-
raise AuthError()
916-
elif response.status_code == 400:
917-
"""
918-
The HTTP response has a 400 status code in the following cases:
919-
You do not pass in a session ID or you pass in an invalid session ID.
920-
No clients are actively connected to the OpenTok session.
921-
You specify an invalid resolution value.
922-
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
923-
"""
924-
raise RequestError(response.json().get("message"))
925-
elif response.status_code == 404:
926-
raise NotFoundError("Archive or Stream not found")
927-
elif response.status_code == 405:
928-
raise ArchiveStreamModeError(
929-
"Your archive is configured with a streamMode that does not support stream manipulation."
930-
)
931-
elif response.status_code == 409:
932-
raise ArchiveError(response.json().get("message"))
914+
if response.status_code == 204:
915+
return None
916+
elif response.status_code == 403:
917+
raise AuthError()
918+
elif response.status_code == 400:
919+
"""
920+
The HTTP response has a 400 status code in the following cases:
921+
You do not pass in a session ID or you pass in an invalid session ID.
922+
No clients are actively connected to the OpenTok session.
923+
You specify an invalid resolution value.
924+
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
925+
"""
926+
raise RequestError(response.json().get("message"))
927+
elif response.status_code == 404:
928+
raise NotFoundError("Archive or Stream not found")
929+
elif response.status_code == 405:
930+
raise ArchiveStreamModeError(
931+
"Your archive is configured with a streamMode that does not support stream manipulation."
932+
)
933+
elif response.status_code == 409:
934+
raise ArchiveError(response.json().get("message"))
933935
else:
934-
raise RequestError("An unexpected error occurred", response.status_code)
936+
raise RequestError("An unexpected error occurred.", response.status_code)
935937

936938
def send_signal(self, session_id, payload, connection_id=None):
937939
"""
@@ -964,26 +966,27 @@ def send_signal(self, session_id, payload, connection_id=None):
964966
timeout=self.timeout,
965967
)
966968

967-
if response.status_code == 204:
968-
pass
969-
elif response.status_code == 400:
970-
raise SignalingError(
971-
"One of the signal properties - data, type, sessionId or connectionId - is invalid."
972-
)
973-
elif response.status_code == 403:
974-
raise AuthError(
975-
"You are not authorized to send the signal. Check your authentication credentials."
976-
)
977-
elif response.status_code == 404:
978-
raise SignalingError(
979-
"The client specified by the connectionId property is not connected to the session."
980-
)
981-
elif response.status_code == 413:
982-
raise SignalingError(
983-
"The type string exceeds the maximum length (128 bytes), or the data string exceeds the maximum size (8 kB)."
984-
)
969+
if response:
970+
if response.status_code == 204:
971+
return None
972+
elif response.status_code == 400:
973+
raise SignalingError(
974+
"One of the signal properties - data, type, sessionId or connectionId - is invalid."
975+
)
976+
elif response.status_code == 403:
977+
raise AuthError(
978+
"You are not authorized to send the signal. Check your authentication credentials."
979+
)
980+
elif response.status_code == 404:
981+
raise SignalingError(
982+
"The client specified by the connectionId property is not connected to the session."
983+
)
984+
elif response.status_code == 413:
985+
raise SignalingError(
986+
"The type string exceeds the maximum length (128 bytes), or the data string exceeds the maximum size (8 kB)."
987+
)
985988
else:
986-
raise RequestError("An unexpected error occurred", response.status_code)
989+
raise RequestError("An unexpected error occurred.", response.status_code)
987990

988991
def signal(self, session_id, payload, connection_id=None):
989992
warnings.warn(
@@ -1559,24 +1562,25 @@ def add_broadcast_stream(
15591562
)
15601563

15611564
if response:
1562-
return Broadcast(response.json())
1563-
elif response.status_code == 400:
1564-
raise BroadcastError(
1565-
"Invalid request. This response may indicate that data in your request data is "
1566-
"invalid JSON. It may also indicate that you passed in invalid layout options. "
1567-
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
1568-
"session. Or you specified and invalid resolution."
1569-
)
1570-
elif response.status_code == 403:
1571-
raise AuthError("Authentication error.")
1572-
elif response.status_code == 405:
1573-
raise BroadcastStreamModeError(
1574-
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1575-
)
1576-
elif response.status_code == 409:
1577-
raise BroadcastError("The broadcast has already started for the session.")
1565+
if response.status_code == 204:
1566+
return None
1567+
elif response.status_code == 400:
1568+
raise BroadcastError(
1569+
"Invalid request. This response may indicate that data in your request data is "
1570+
"invalid JSON. It may also indicate that you passed in invalid layout options. "
1571+
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
1572+
"session. Or you specified and invalid resolution."
1573+
)
1574+
elif response.status_code == 403:
1575+
raise AuthError("Authentication error.")
1576+
elif response.status_code == 405:
1577+
raise BroadcastStreamModeError(
1578+
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1579+
)
1580+
elif response.status_code == 409:
1581+
raise BroadcastError("The broadcast has already started for the session.")
15781582
else:
1579-
raise RequestError("OpenTok server error.", response.status_code)
1583+
raise RequestError("An unexpected error occurred.", response.status_code)
15801584

15811585
def remove_broadcast_stream(
15821586
self, broadcast_id: str, stream_id: str
@@ -1601,22 +1605,23 @@ def remove_broadcast_stream(
16011605
)
16021606

16031607
if response:
1604-
return Broadcast(response.json())
1605-
elif response.status_code == 400:
1606-
raise BroadcastError(
1607-
"Invalid request. This response may indicate that data in your request data is "
1608-
"invalid JSON. It may also indicate that you passed in invalid layout options. "
1609-
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
1610-
"session. Or you specified and invalid resolution."
1611-
)
1612-
elif response.status_code == 403:
1613-
raise AuthError("Authentication error.")
1614-
elif response.status_code == 405:
1615-
raise BroadcastStreamModeError(
1616-
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1617-
)
1618-
elif response.status_code == 409:
1619-
raise BroadcastError("The broadcast has already started for the session.")
1608+
if response.status_code == 204:
1609+
return None
1610+
elif response.status_code == 400:
1611+
raise BroadcastError(
1612+
"Invalid request. This response may indicate that data in your request data is "
1613+
"invalid JSON. It may also indicate that you passed in invalid layout options. "
1614+
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
1615+
"session. Or you specified and invalid resolution."
1616+
)
1617+
elif response.status_code == 403:
1618+
raise AuthError("Authentication error.")
1619+
elif response.status_code == 405:
1620+
raise BroadcastStreamModeError(
1621+
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1622+
)
1623+
elif response.status_code == 409:
1624+
raise BroadcastError("The broadcast has already started for the session.")
16201625
else:
16211626
raise RequestError("OpenTok server error.", response.status_code)
16221627

0 commit comments

Comments
 (0)