45
45
SipDialError ,
46
46
SetStreamClassError ,
47
47
BroadcastError ,
48
+ DTMFError
48
49
)
49
50
50
51
@@ -1120,9 +1121,51 @@ def dial(self, session_id, token, sip_uri, options=[]):
1120
1121
Boolean 'secure': A Boolean flag that indicates whether the media must be transmitted
1121
1122
encrypted (true) or not (false, the default)
1122
1123
1123
- :rtype: A SipCall object, which contains data of the SIP call: id, connectionId and streamId
1124
+ Boolean 'observeForceMute': A Boolean flag that determines whether the SIP endpoint should
1125
+ honor the force mute action. The force mute action allows a moderator to force clients to
1126
+ mute audio in streams they publish. It defaults to False if moderator does not want to observe
1127
+ force mute a stream and set to True if the moderator wants to observe force mute a stream.
1128
+
1129
+ Boolean 'video': A Boolean flag that indicates whether the SIP call will include video(true)
1130
+ or not(false, which is the default). With video included, the SIP client's video is included
1131
+ in the OpenTok stream that is sent to the OpenTok session. The SIP client will receive a single
1132
+ composed video of the published streams in the OpenTok session.
1133
+
1134
+ This is an example of what the payload POST data body could look like:
1135
+
1136
+ {
1137
+ "sessionId": "Your OpenTok session ID",
1138
+ "token": "Your valid OpenTok token",
1139
+ "sip": {
1140
+ "uri": "sip:[email protected] ;transport=tls",
1141
+
1142
+ "headers": {
1143
+ "headerKey": "headerValue"
1144
+ },
1145
+ "auth": {
1146
+ "username": "username",
1147
+ "password": "password"
1148
+ },
1149
+ "secure": true|false,
1150
+ "observeForceMute": true|false,
1151
+ "video": true|false
1152
+ }
1153
+ }
1154
+
1155
+ :rtype: A SipCall object, which contains data of the SIP call: id, connectionId and streamId.
1156
+ This is what the response body should look like after returning with a status code of 200:
1157
+
1158
+ {
1159
+ "id": "b0a5a8c7-dc38-459f-a48d-a7f2008da853",
1160
+ "connectionId": "e9f8c166-6c67-440d-994a-04fb6dfed007",
1161
+ "streamId": "482bce73-f882-40fd-8ca5-cb74ff416036",
1162
+ }
1163
+
1164
+ Note: Your response will have a different: id, connectionId and streamId
1124
1165
"""
1125
1166
payload = {"sessionId" : session_id , "token" : token , "sip" : {"uri" : sip_uri }}
1167
+ observeForceMute = False
1168
+ video = False
1126
1169
1127
1170
if "from" in options :
1128
1171
payload ["sip" ]["from" ] = options ["from" ]
@@ -1136,6 +1179,14 @@ def dial(self, session_id, token, sip_uri, options=[]):
1136
1179
if "secure" in options :
1137
1180
payload ["sip" ]["secure" ] = options ["secure" ]
1138
1181
1182
+ if "observeForceMute" in options :
1183
+ observeForceMute = True
1184
+ payload ["sip" ]["observeForceMute" ] = options ["observeForceMute" ]
1185
+
1186
+ if "video" in options :
1187
+ video = True
1188
+ payload ["sip" ]["video" ] = options ["video" ]
1189
+
1139
1190
endpoint = self .endpoints .dial_url ()
1140
1191
1141
1192
logger .debug (
@@ -1588,4 +1639,81 @@ def __init__(
1588
1639
app_version = app_version
1589
1640
)
1590
1641
1642
+
1643
+
1644
+ def mute (self , session_id : str , stream_id : str = "" , options : dict = {}) -> requests .Response :
1645
+ """
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.
1649
+
1650
+ :param session_id gets the session id from another function called get_session()
1651
+
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.
1591
1655
1656
+ """
1657
+
1658
+ try :
1659
+ if not stream_id :
1660
+ url = self .endpoints .get_mute_all_url (session_id )
1661
+ data = {'excludedStream' : stream_id }
1662
+ 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 )
1668
+
1669
+ if response :
1670
+ return response
1671
+ elif response .status_code == 400 :
1672
+ 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
+ elif response .status_code == 403 :
1674
+ raise AuthError ("Failed to create session, invalid credentials" )
1675
+ elif response .status_code == 404 :
1676
+ raise NotFoundError ("Mute not found" )
1677
+ except Exception as e :
1678
+ 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 (
1680
+ session_id , stream_id ))
1681
+
1682
+ def play_dtmf (self , session_id : str , connection_id : str , digits : str , options : dict = {}) -> requests .Response :
1683
+ """
1684
+ Plays a DTMF string into a session or to a specific connection
1685
+
1686
+ :param session_id The ID of the OpenTok session that the participant being called
1687
+ will join
1688
+
1689
+ :param connection_id An optional parameter used to send the DTMF tones to a specific
1690
+ connectoiin in a session.
1691
+
1692
+ :param digits DTMF digits to play
1693
+ Valid DTMF digits are 0-9, p, #, and * digits. 'p' represents a 500ms pause if a delay is
1694
+ needed during the input process.
1695
+
1696
+ """
1697
+
1698
+ try :
1699
+ if not connection_id :
1700
+ url = self .endpoints .get_dtmf_all_url (session_id )
1701
+ payload = {"digits" : digits }
1702
+ else :
1703
+ url = self .endpoints .get_dtmf_specific_url (session_id , connection_id )
1704
+ payload = {"digits" : digits }
1705
+
1706
+ response = requests .post (url , headers = self .get_json_headers (), data = json .dumps (payload ))
1707
+
1708
+ if response .status_code == 200 :
1709
+ return response
1710
+ elif response .status_code == 400 :
1711
+ raise DTMFError ("One of the properties digits, sessionId or connectionId is invalid." )
1712
+ elif response .status_code == 403 :
1713
+ raise AuthError ("Failed to create session, invalid credentials. Please check your OpenTok API Key or JSON web token" )
1714
+ elif response .status_code == 404 :
1715
+ raise NotFoundError ("The session does not exists or the client specified by the connection_id is not connected to the session" )
1716
+ except Exception as e :
1717
+ raise OpenTokException (
1718
+ (f"There was an error thrown by the OpenTok SDK, please check that your session_id: { session_id } , connection_id (if exists): { connection_id } and digits: { digits } are valid" ))
1719
+
0 commit comments