|
1 | 1 | from datetime import datetime # generate_token
|
| 2 | +from typing import List, Optional # imports List, Optional type hint |
2 | 3 | import calendar # generate_token
|
3 | 4 | import base64 # generate_token
|
4 | 5 | import random # generate_token
|
@@ -1152,6 +1153,7 @@ def dial(self, session_id, token, sip_uri, options=[]):
|
1152 | 1153 | }
|
1153 | 1154 | }
|
1154 | 1155 |
|
| 1156 | +
|
1155 | 1157 | :rtype: A SipCall object, which contains data of the SIP call: id, connectionId and streamId.
|
1156 | 1158 | This is what the response body should look like after returning with a status code of 200:
|
1157 | 1159 |
|
@@ -1639,46 +1641,82 @@ def __init__(
|
1639 | 1641 | app_version=app_version
|
1640 | 1642 | )
|
1641 | 1643 |
|
| 1644 | + def mute_all(self, |
| 1645 | + session_id: str, |
| 1646 | + excludedStreamIds: Optional[List[str]], |
| 1647 | + active: bool= True) -> requests.Response: |
1642 | 1648 |
|
1643 |
| - |
1644 |
| - def mute(self, session_id: str, stream_id: str= "", options: dict = {}) -> requests.Response: |
1645 | 1649 | """
|
1646 |
| - Use this method so the moderator can mute all streams or a specific stream for OpenTok. |
1647 |
| - Please note that a client is able to unmute themselves. |
1648 |
| - This function stays in the OpenTok class and inherits from the Client class. |
| 1650 | + Mutes all streams in an OpenTok session. |
| 1651 | +
|
| 1652 | + You can include an optional list of streams IDs to exclude from being muted. |
| 1653 | +
|
| 1654 | + :param session_id The session ID |
1649 | 1655 |
|
1650 |
| - :param session_id gets the session id from another function called get_session() |
| 1656 | + :param excludedStreamIds A list of stream IDs for streams that should not be muted. |
| 1657 | + This is an optional property. If you omit this property, all streams in the session will be muted. |
1651 | 1658 |
|
1652 |
| - :param stream_id gets the stream id from another function called get_stream(). Note |
1653 |
| - that this variable is set to an empty string in the function definition as a specific |
1654 |
| - stream may not be chosen. |
1655 |
| - |
| 1659 | + :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). |
1656 | 1661 | """
|
1657 |
| - |
| 1662 | + |
| 1663 | + options = {} |
| 1664 | + url = self.endpoints.get_mute_all_url(session_id) |
| 1665 | + |
1658 | 1666 | try:
|
1659 |
| - if not stream_id: |
1660 |
| - url = self.endpoints.get_mute_all_url(session_id) |
1661 |
| - data = {'excludedStream': stream_id} |
| 1667 | + if excludedStreamIds: |
| 1668 | + if active: |
| 1669 | + options = {'active': active, 'excludedStreams': excludedStreamIds } |
1662 | 1670 | else:
|
1663 |
| - url = self.endpoints.get_stream_url(session_id, stream_id) + "/mute" |
1664 |
| - data = None |
1665 |
| - |
1666 |
| - |
1667 |
| - response = requests.post(url, headers=self.get_headers(), data=data) |
| 1671 | + active = False |
| 1672 | + options = {'active': active, 'excludedStreams': []} |
| 1673 | + |
| 1674 | + response = requests.post(url, headers=self.get_headers(), data=json.dumps(options)) |
1668 | 1675 |
|
1669 | 1676 | if response:
|
1670 | 1677 | return response
|
1671 | 1678 | elif response.status_code == 400:
|
1672 | 1679 | 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.")
|
1673 | 1680 | elif response.status_code == 403:
|
1674 |
| - raise AuthError("Failed to create session, invalid credentials") |
| 1681 | + raise AuthError("Failed to mute, invalid credentials.") |
| 1682 | + elif response.status_code == 404: |
| 1683 | + raise NotFoundError("The session or a stream is not found.") |
| 1684 | + except Exception as e: |
| 1685 | + raise OpenTokException( |
| 1686 | + ("There was an error thrown by the OpenTok SDK, please check that your session_id {0} and excludedStreamIds (if exists) {1} are valid").format( |
| 1687 | + session_id, excludedStreamIds)) |
| 1688 | + |
| 1689 | + |
| 1690 | + |
| 1691 | + def mute_stream(self, session_id: str, stream_id: str) -> requests.Response: |
| 1692 | + """ |
| 1693 | + Mutes a single stream in an OpenTok session. |
| 1694 | +
|
| 1695 | + :param session_id The session ID. |
| 1696 | +
|
| 1697 | + :param stream_id The stream iD. |
| 1698 | + """ |
| 1699 | + |
| 1700 | + try: |
| 1701 | + if stream_id: |
| 1702 | + url = self.endpoints.get_stream_url(session_id, stream_id) + "/mute" |
| 1703 | + |
| 1704 | + response = requests.post(url, headers=self.get_headers()) |
| 1705 | + |
| 1706 | + if response: |
| 1707 | + return response |
| 1708 | + elif response.status_code == 400: |
| 1709 | + 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.") |
| 1710 | + elif response.status_code == 403: |
| 1711 | + raise AuthError("Failed to mute, invalid credentials.") |
1675 | 1712 | elif response.status_code == 404:
|
1676 | 1713 | raise NotFoundError("Mute not found")
|
1677 | 1714 | except Exception as e:
|
1678 | 1715 | raise OpenTokException(
|
1679 |
| - ("There was an error thrown by the OpenTok SDK, please check that your session_id {0} and stream_id (if exists) {1} are valid").format( |
| 1716 | + ("There was an error thrown by the OpenTok SDK, please check that your session_id {0} and stream_id {1} are valid").format( |
1680 | 1717 | session_id, stream_id))
|
1681 | 1718 |
|
| 1719 | + |
1682 | 1720 | def play_dtmf(self, session_id: str, connection_id: str, digits: str, options: dict = {}) -> requests.Response:
|
1683 | 1721 | """
|
1684 | 1722 | Plays a DTMF string into a session or to a specific connection
|
|
0 commit comments