Skip to content

Commit 8a48ed1

Browse files
committed
Changed mute function and added disable force mute functionality
- Changed mute_all function to reflect the active flag to always be True - Added disable_force_mute function to disable the mute state with the active flag always set to False
1 parent 374ea62 commit 8a48ed1

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

opentok/opentok.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,18 +1657,16 @@ def mute_all(self,
16571657
This is an optional property. If you omit this property, all streams in the session will be muted.
16581658
16591659
:param active Whether streams published after the call, in addition to the current streams
1660-
in the session, should be muted (True) or not (False).
1660+
in the session, should be muted (True).
16611661
"""
16621662

16631663
options = {}
16641664
url = self.endpoints.get_mute_all_url(session_id)
16651665

16661666
try:
16671667
if excludedStreamIds:
1668-
if active:
1669-
options = {'active': active, 'excludedStreams': excludedStreamIds }
1668+
options = {'active': active, 'excludedStreams': excludedStreamIds }
16701669
else:
1671-
active = False
16721670
options = {'active': active, 'excludedStreams': []}
16731671

16741672
response = requests.post(url, headers=self.get_headers(), data=json.dumps(options))
@@ -1687,6 +1685,35 @@ def mute_all(self,
16871685
session_id, excludedStreamIds))
16881686

16891687

1688+
def disable_force_mute(self, session_id: str, active: bool= False) -> requests.Response:
1689+
"""
1690+
Disables the mute all streams in an OpenTok session.
1691+
1692+
:param session_id The session ID.
1693+
1694+
:param active Whether streams published after the call, in addition to the current streams
1695+
in the session, should not be muted (False).
1696+
"""
1697+
1698+
url = self.endpoints.get_mute_all_url(session_id)
1699+
1700+
response = requests.post(url, headers=self.get_headers())
1701+
1702+
1703+
try:
1704+
if response:
1705+
return response
1706+
elif response.status_code == 400:
1707+
raise GetStreamError("Invalid request. This response may indicate that data in your request data is invalid JSON. Or it may indicate that you do not pass in a session ID or you passed in an invalid stream ID.")
1708+
elif response.status_code == 403:
1709+
raise AuthError("Failed to mute, invalid credentials.")
1710+
elif response.status_code == 404:
1711+
raise NotFoundError("The session or a stream is not found.")
1712+
except Exception as e:
1713+
raise OpenTokException(
1714+
("There was an error thrown by the OpenTok SDK, please check that your session_id {0} is valid").format(
1715+
session_id))
1716+
16901717

16911718
def mute_stream(self, session_id: str, stream_id: str) -> requests.Response:
16921719
"""

tests/test_opentok.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ def test_mute_all_exclude_streams(self):
5252
response.headers["x-opentok-auth"].should.equal(self.jwt_token_string)
5353
response.headers["Content-Type"].should.equal("application/json")
5454

55+
@httpretty.activate
56+
def test_disable_force_mute(self):
57+
self.url = "https://api.opentok.com/v2/project/{0}/session/{1}/mute".format(
58+
self.api_key,
59+
self.session_id)
60+
61+
httpretty.register_uri(httpretty.POST,
62+
self.url,
63+
responses=[
64+
httpretty.Response(body='{}',
65+
content_type="application/json",
66+
adding_headers= {"x-opentok-auth": self.jwt_token_string},
67+
status=201)
68+
])
69+
70+
71+
response = requests.post(self.url)
72+
73+
response.text.should.equal('{}')
74+
response.headers["x-opentok-auth"].should.equal(self.jwt_token_string)
75+
response.headers["Content-Type"].should.equal("application/json")
76+
5577
@httpretty.activate
5678
def test_mute_single_stream(self):
5779
self.url = "https://api.opentok.com/v2/project/{0}/session/{1}/stream/{2}/mute".format(

0 commit comments

Comments
 (0)