3535from .websocket_audio_connection import WebSocketAudioConnection
3636from .exceptions import (
3737 ArchiveStreamModeError ,
38+ BroadcastOptionsError ,
3839 BroadcastHLSOptionsError ,
3940 BroadcastStreamModeError ,
4041 OpenTokException ,
@@ -1170,7 +1171,7 @@ def set_archive_layout(
11701171 else :
11711172 raise RequestError ("OpenTok server error." , response .status_code )
11721173
1173- def dial (self , session_id , token , sip_uri , options = [] ):
1174+ def dial (self , session_id , token , sip_uri , options = {} ):
11741175 """
11751176 Use this method to connect a SIP platform to an OpenTok session. The audio from the end
11761177 of the SIP call is added to the OpenTok session as an audio-only stream. The OpenTok Media
@@ -1213,27 +1214,30 @@ def dial(self, session_id, token, sip_uri, options=[]):
12131214 in the OpenTok stream that is sent to the OpenTok session. The SIP client will receive a single
12141215 composed video of the published streams in the OpenTok session.
12151216
1216- This is an example of what the payload POST data body could look like:
1217+ List 'streams': An array of stream IDs for streams to include in the SIP call.
1218+ If you do not set this property, all streams in the session are included in the call.
1219+
1220+ This is an example of what the payload POST data dictionary could look like:
12171221
12181222 {
12191223 "sessionId": "Your OpenTok session ID",
12201224 "token": "Your valid OpenTok token",
12211225 "sip": {
1222- "uri": "sip:[email protected] ;transport=tls", 1223- 1224- "headers": {
1225- "headerKey": "headerValue"
1226- },
1226+ "uri": "sip:[email protected] ;transport=tls", 1227+ 1228+ "headers": {
1229+ "headerKey": "headerValue"
1230+ },
12271231 "auth": {
12281232 "username": "username",
12291233 "password": "password"
12301234 },
1231- "secure": true|false ,
1232- "observeForceMute ": true|false ,
1233- "video ": true|false
1234- }
1235+ "secure": True ,
1236+ "video ": True ,
1237+ "observeForceMute ": True,
1238+ "streams": ["stream-id-1", "stream-id-2"]
12351239 }
1236-
1240+ }
12371241
12381242 :rtype: A SipCall object, which contains data of the SIP call: id, connectionId and streamId.
12391243 This is what the response body should look like after returning with a status code of 200:
@@ -1246,29 +1250,9 @@ def dial(self, session_id, token, sip_uri, options=[]):
12461250
12471251 Note: Your response will have a different: id, connectionId and streamId
12481252 """
1249- payload = {"sessionId" : session_id , "token" : token , "sip" : {"uri" : sip_uri }}
1250- observeForceMute = False
1251- video = False
1252-
1253- if "from" in options :
1254- payload ["sip" ]["from" ] = options ["from" ]
1255-
1256- if "headers" in options :
1257- payload ["sip" ]["headers" ] = options ["headers" ]
12581253
1259- if "auth" in options :
1260- payload ["sip" ]["auth" ] = options ["auth" ]
1261-
1262- if "secure" in options :
1263- payload ["sip" ]["secure" ] = options ["secure" ]
1264-
1265- if "observeForceMute" in options :
1266- observeForceMute = True
1267- payload ["sip" ]["observeForceMute" ] = options ["observeForceMute" ]
1268-
1269- if "video" in options :
1270- video = True
1271- payload ["sip" ]["video" ] = options ["video" ]
1254+ payload = {"sessionId" : session_id , "token" : token , "sip" : {"uri" : sip_uri }}
1255+ payload .update (options )
12721256
12731257 endpoint = self .endpoints .dial_url ()
12741258
@@ -1367,11 +1351,11 @@ def start_broadcast(
13671351
13681352 :param String session_id: The session ID of the OpenTok session you want to broadcast
13691353
1370- :param Boolean optional hasAudio: Whether the stream is broadcast with audio.
1354+ :param Dictionary options, with the following properties:
13711355
1372- :param Boolean optional hasVideo : Whether the stream is broadcast with video .
1356+ :param Boolean optional hasAudio : Whether the stream is broadcast with audio .
13731357
1374- :param Dictionary options, with the following properties:
1358+ :param Boolean optional hasVideo: Whether the stream is broadcast with video.
13751359
13761360 Dictionary 'layout' optional: Specify this to assign the initial layout type for the
13771361 broadcast.
@@ -1392,6 +1376,9 @@ def start_broadcast(
13921376 set the maximum duration to a value from 60 (60 seconds) to 36000 (10 hours). The
13931377 default maximum duration is 4 hours (14,400 seconds)
13941378
1379+ Integer 'maxBitrate' optional: The maximum bitrate (bits per second) used by the broadcast.
1380+ Value must be between 100_000 and 6_000_000.
1381+
13951382 Dictionary 'outputs': This object defines the types of broadcast streams you want to
13961383 start (both HLS and RTMP). You can include HLS, RTMP, or both as broadcast streams.
13971384 If you include RTMP streaming, you can specify up to five target RTMP streams. For
@@ -1448,6 +1435,16 @@ def start_broadcast(
14481435 'HLS options "lowLatency" and "dvr" cannot both be set to "True".'
14491436 )
14501437
1438+ if "maxBitrate" in options :
1439+ if (
1440+ type (options ["maxBitrate" ]) != int
1441+ or options ["maxBitrate" ] < 100000
1442+ or options ["maxBitrate" ] > 6000000
1443+ ):
1444+ raise BroadcastOptionsError (
1445+ "maxBitrate must be an integer between 100000 and 6000000."
1446+ )
1447+
14511448 payload = {"sessionId" : session_id , "streamMode" : stream_mode .value }
14521449
14531450 payload .update (options )
@@ -1578,7 +1575,9 @@ def add_broadcast_stream(
15781575 "Your broadcast is configured with a streamMode that does not support stream manipulation."
15791576 )
15801577 elif response .status_code == 409 :
1581- raise BroadcastError ("The broadcast has already started for the session." )
1578+ raise BroadcastError (
1579+ "The broadcast has already started for the session."
1580+ )
15821581 else :
15831582 raise RequestError ("An unexpected error occurred." , response .status_code )
15841583
@@ -1621,7 +1620,9 @@ def remove_broadcast_stream(
16211620 "Your broadcast is configured with a streamMode that does not support stream manipulation."
16221621 )
16231622 elif response .status_code == 409 :
1624- raise BroadcastError ("The broadcast has already started for the session." )
1623+ raise BroadcastError (
1624+ "The broadcast has already started for the session."
1625+ )
16251626 else :
16261627 raise RequestError ("OpenTok server error." , response .status_code )
16271628
0 commit comments