Skip to content

Commit

Permalink
Merge pull request #224 from opentok/fix-streams-methods
Browse files Browse the repository at this point in the history
Fix streams methods
  • Loading branch information
maxkahan authored Jul 5, 2023
2 parents 9ddaf26 + 2af883e commit e502713
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 290 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.6.0
current_version = 3.6.1
commit = True
tag = False

Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Release v3.6.1
- 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
- Fixed `opentok.Endpoints.get_archive_stream` and `opentok.Endpoints.get_broadcast_stream` methods

# Release v3.6.0
- Added auto-archive improvements to the `opentok.Client.create_session` method
to customize automatically created archives:
Expand Down
42 changes: 20 additions & 22 deletions opentok/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Endpoints(object):
Class that provides the endpoint urls
"""


def __init__(self, api_url, api_key):
self.api_url = api_url
self.api_key = api_key
Expand Down Expand Up @@ -57,7 +56,7 @@ def signaling_url(self, session_id, connection_id=None):
return self.get_signaling_url(session_id, connection_id)

def get_stream_url(self, session_id, stream_id=None):
""" this method returns the url to get streams information """
"""this method returns the url to get streams information"""
url = (
self.api_url
+ "/v2/project/"
Expand All @@ -79,7 +78,7 @@ def broadcast_url(self, broadcast_id=None, stop=False, layout=False):
return self.get_broadcast_url(broadcast_id, stop, layout)

def force_disconnect_url(self, session_id, connection_id):
""" this method returns the force disconnect url endpoint """
"""this method returns the force disconnect url endpoint"""
url = (
self.api_url
+ "/v2/project/"
Expand All @@ -92,7 +91,7 @@ def force_disconnect_url(self, session_id, connection_id):
return url

def set_archive_layout_url(self, archive_id):
""" this method returns the url to set the archive layout """
"""this method returns the url to set the archive layout"""
url = (
self.api_url
+ "/v2/project/"
Expand All @@ -104,12 +103,12 @@ def set_archive_layout_url(self, archive_id):
return url

def dial_url(self):
""" this method returns the url to initialize a SIP call """
"""this method returns the url to initialize a SIP call"""
url = self.api_url + "/v2/project/" + self.api_key + "/dial"
return url

def set_stream_class_lists_url(self, session_id):
""" this method returns the url to set the stream class list """
"""this method returns the url to set the stream class list"""
url = (
self.api_url
+ "/v2/project/"
Expand All @@ -121,7 +120,7 @@ def set_stream_class_lists_url(self, session_id):
return url

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

if broadcast_id:
Expand All @@ -130,28 +129,27 @@ def get_broadcast_url(self, broadcast_id=None, stop=False, layout=False):
url = url + "/stop"
if layout:
url = url + "/layout"

return url

def get_mute_all_url(self, session_id):
""" this method returns the urls for muting every stream in a session """
"""this method returns the urls for muting every stream in a session"""
url = (
self.api_url
+ "/v2/project/"
self.api_url
+ "/v2/project/"
+ self.api_key
+ "/session/"
+ session_id
+ "/mute"

)

return url

def get_dtmf_all_url(self, session_id):
""" this method returns the url for Play DTMF to all clients in the session """
"""this method returns the url for Play DTMF to all clients in the session"""
url = (
self.api_url
+ "/v2/project/"
+ "/v2/project/"
+ self.api_key
+ "/session/"
+ session_id
Expand All @@ -161,7 +159,7 @@ def get_dtmf_all_url(self, session_id):
return url

def get_dtmf_specific_url(self, session_id, connection_id):
""" this method returns the url for Play DTMF to a specific client connection"""
"""this method returns the url for Play DTMF to a specific client connection"""
url = (
self.api_url
+ "/v2/project/"
Expand All @@ -176,33 +174,33 @@ def get_dtmf_specific_url(self, session_id, connection_id):
return url

def get_archive_stream(self, archive_id=None):
""" this method returns urls for working with streamModes in archives """
"""this method returns urls for working with streamModes in archives"""
url = (
self.api_url
+ "/v2/project/"
+ self.api_key
+ "archive/"
+ "/archive/"
+ archive_id
+ "/streams"
)

return url

def get_broadcast_stream(self, broadcast_id=None):
""" this method returns urls for working with streamModes in broadcasts """
"""this method returns urls for working with streamModes in broadcasts"""
url = (
self.api_url
+ "/v2/partner/"
+ "/v2/project/"
+ self.api_key
+ "broadcast/"
+ "/broadcast/"
+ broadcast_id
+ "/streams"
)

return url

def get_render_url(self, render_id: str = None):
"Returns URLs for working with the Render API."""
"Returns URLs for working with the Render API." ""
url = self.api_url + "/v2/project/" + self.api_key + "/render"
if render_id:
url += "/" + render_id
Expand All @@ -212,5 +210,5 @@ def get_render_url(self, render_id: str = None):
def get_audio_connector_url(self):
"""Returns URLs for working with the Audio Connector API."""
url = self.api_url + "/v2/project/" + self.api_key + "/connect"

return url
193 changes: 99 additions & 94 deletions opentok/opentok.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,28 +864,29 @@ def add_archive_stream(
)

if response:
return Archive(self, response.json())
elif response.status_code == 403:
raise AuthError()
elif response.status_code == 400:
"""
The HTTP response has a 400 status code in the following cases:
You do not pass in a session ID or you pass in an invalid session ID.
No clients are actively connected to the OpenTok session.
You specify an invalid resolution value.
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
"""
raise RequestError(response.json().get("message"))
elif response.status_code == 404:
raise NotFoundError("Archive or Stream not found")
elif response.status_code == 405:
raise ArchiveStreamModeError(
"Your archive is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise ArchiveError(response.json().get("message"))
if response.status_code == 204:
return None
elif response.status_code == 403:
raise AuthError()
elif response.status_code == 400:
"""
The HTTP response has a 400 status code in the following cases:
You do not pass in a session ID or you pass in an invalid session ID.
No clients are actively connected to the OpenTok session.
You specify an invalid resolution value.
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
"""
raise RequestError(response.json().get("message"))
elif response.status_code == 404:
raise NotFoundError("Archive or Stream not found")
elif response.status_code == 405:
raise ArchiveStreamModeError(
"Your archive is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise ArchiveError(response.json().get("message"))
else:
raise RequestError("An unexpected error occurred", response.status_code)
raise RequestError("An unexpected error occurred.", response.status_code)

def remove_archive_stream(
self, archive_id: str, stream_id: str
Expand All @@ -910,28 +911,29 @@ def remove_archive_stream(
)

if response:
return Archive(self, response.json())
elif response.status_code == 403:
raise AuthError()
elif response.status_code == 400:
"""
The HTTP response has a 400 status code in the following cases:
You do not pass in a session ID or you pass in an invalid session ID.
No clients are actively connected to the OpenTok session.
You specify an invalid resolution value.
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
"""
raise RequestError(response.json().get("message"))
elif response.status_code == 404:
raise NotFoundError("Archive or Stream not found")
elif response.status_code == 405:
raise ArchiveStreamModeError(
"Your archive is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise ArchiveError(response.json().get("message"))
if response.status_code == 204:
return None
elif response.status_code == 403:
raise AuthError()
elif response.status_code == 400:
"""
The HTTP response has a 400 status code in the following cases:
You do not pass in a session ID or you pass in an invalid session ID.
No clients are actively connected to the OpenTok session.
You specify an invalid resolution value.
The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
"""
raise RequestError(response.json().get("message"))
elif response.status_code == 404:
raise NotFoundError("Archive or Stream not found")
elif response.status_code == 405:
raise ArchiveStreamModeError(
"Your archive is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise ArchiveError(response.json().get("message"))
else:
raise RequestError("An unexpected error occurred", response.status_code)
raise RequestError("An unexpected error occurred.", response.status_code)

def send_signal(self, session_id, payload, connection_id=None):
"""
Expand Down Expand Up @@ -964,26 +966,27 @@ def send_signal(self, session_id, payload, connection_id=None):
timeout=self.timeout,
)

if response.status_code == 204:
pass
elif response.status_code == 400:
raise SignalingError(
"One of the signal properties - data, type, sessionId or connectionId - is invalid."
)
elif response.status_code == 403:
raise AuthError(
"You are not authorized to send the signal. Check your authentication credentials."
)
elif response.status_code == 404:
raise SignalingError(
"The client specified by the connectionId property is not connected to the session."
)
elif response.status_code == 413:
raise SignalingError(
"The type string exceeds the maximum length (128 bytes), or the data string exceeds the maximum size (8 kB)."
)
if response:
if response.status_code == 204:
return None
elif response.status_code == 400:
raise SignalingError(
"One of the signal properties - data, type, sessionId or connectionId - is invalid."
)
elif response.status_code == 403:
raise AuthError(
"You are not authorized to send the signal. Check your authentication credentials."
)
elif response.status_code == 404:
raise SignalingError(
"The client specified by the connectionId property is not connected to the session."
)
elif response.status_code == 413:
raise SignalingError(
"The type string exceeds the maximum length (128 bytes), or the data string exceeds the maximum size (8 kB)."
)
else:
raise RequestError("An unexpected error occurred", response.status_code)
raise RequestError("An unexpected error occurred.", response.status_code)

def signal(self, session_id, payload, connection_id=None):
warnings.warn(
Expand Down Expand Up @@ -1559,24 +1562,25 @@ def add_broadcast_stream(
)

if response:
return Broadcast(response.json())
elif response.status_code == 400:
raise BroadcastError(
"Invalid request. This response may indicate that data in your request data is "
"invalid JSON. It may also indicate that you passed in invalid layout options. "
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
"session. Or you specified and invalid resolution."
)
elif response.status_code == 403:
raise AuthError("Authentication error.")
elif response.status_code == 405:
raise BroadcastStreamModeError(
"Your broadcast is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise BroadcastError("The broadcast has already started for the session.")
if response.status_code == 204:
return None
elif response.status_code == 400:
raise BroadcastError(
"Invalid request. This response may indicate that data in your request data is "
"invalid JSON. It may also indicate that you passed in invalid layout options. "
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
"session. Or you specified and invalid resolution."
)
elif response.status_code == 403:
raise AuthError("Authentication error.")
elif response.status_code == 405:
raise BroadcastStreamModeError(
"Your broadcast is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise BroadcastError("The broadcast has already started for the session.")
else:
raise RequestError("OpenTok server error.", response.status_code)
raise RequestError("An unexpected error occurred.", response.status_code)

def remove_broadcast_stream(
self, broadcast_id: str, stream_id: str
Expand All @@ -1601,22 +1605,23 @@ def remove_broadcast_stream(
)

if response:
return Broadcast(response.json())
elif response.status_code == 400:
raise BroadcastError(
"Invalid request. This response may indicate that data in your request data is "
"invalid JSON. It may also indicate that you passed in invalid layout options. "
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
"session. Or you specified and invalid resolution."
)
elif response.status_code == 403:
raise AuthError("Authentication error.")
elif response.status_code == 405:
raise BroadcastStreamModeError(
"Your broadcast is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise BroadcastError("The broadcast has already started for the session.")
if response.status_code == 204:
return None
elif response.status_code == 400:
raise BroadcastError(
"Invalid request. This response may indicate that data in your request data is "
"invalid JSON. It may also indicate that you passed in invalid layout options. "
"Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
"session. Or you specified and invalid resolution."
)
elif response.status_code == 403:
raise AuthError("Authentication error.")
elif response.status_code == 405:
raise BroadcastStreamModeError(
"Your broadcast is configured with a streamMode that does not support stream manipulation."
)
elif response.status_code == 409:
raise BroadcastError("The broadcast has already started for the session.")
else:
raise RequestError("OpenTok server error.", response.status_code)

Expand Down
Loading

0 comments on commit e502713

Please sign in to comment.