35
35
from .websocket_audio_connection import WebSocketAudioConnection
36
36
from .exceptions import (
37
37
ArchiveStreamModeError ,
38
+ BroadcastOptionsError ,
38
39
BroadcastHLSOptionsError ,
39
40
BroadcastStreamModeError ,
40
41
OpenTokException ,
@@ -1170,7 +1171,7 @@ def set_archive_layout(
1170
1171
else :
1171
1172
raise RequestError ("OpenTok server error." , response .status_code )
1172
1173
1173
- def dial (self , session_id , token , sip_uri , options = [] ):
1174
+ def dial (self , session_id , token , sip_uri , options = {} ):
1174
1175
"""
1175
1176
Use this method to connect a SIP platform to an OpenTok session. The audio from the end
1176
1177
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=[]):
1213
1214
in the OpenTok stream that is sent to the OpenTok session. The SIP client will receive a single
1214
1215
composed video of the published streams in the OpenTok session.
1215
1216
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:
1217
1221
1218
1222
{
1219
1223
"sessionId": "Your OpenTok session ID",
1220
1224
"token": "Your valid OpenTok token",
1221
1225
"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
+ },
1227
1231
"auth": {
1228
1232
"username": "username",
1229
1233
"password": "password"
1230
1234
},
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"]
1235
1239
}
1236
-
1240
+ }
1237
1241
1238
1242
:rtype: A SipCall object, which contains data of the SIP call: id, connectionId and streamId.
1239
1243
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=[]):
1246
1250
1247
1251
Note: Your response will have a different: id, connectionId and streamId
1248
1252
"""
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" ]
1258
1253
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 )
1272
1256
1273
1257
endpoint = self .endpoints .dial_url ()
1274
1258
@@ -1367,11 +1351,11 @@ def start_broadcast(
1367
1351
1368
1352
:param String session_id: The session ID of the OpenTok session you want to broadcast
1369
1353
1370
- :param Boolean optional hasAudio: Whether the stream is broadcast with audio.
1354
+ :param Dictionary options, with the following properties:
1371
1355
1372
- :param Boolean optional hasVideo : Whether the stream is broadcast with video .
1356
+ :param Boolean optional hasAudio : Whether the stream is broadcast with audio .
1373
1357
1374
- :param Dictionary options, with the following properties:
1358
+ :param Boolean optional hasVideo: Whether the stream is broadcast with video.
1375
1359
1376
1360
Dictionary 'layout' optional: Specify this to assign the initial layout type for the
1377
1361
broadcast.
@@ -1392,6 +1376,9 @@ def start_broadcast(
1392
1376
set the maximum duration to a value from 60 (60 seconds) to 36000 (10 hours). The
1393
1377
default maximum duration is 4 hours (14,400 seconds)
1394
1378
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
+
1395
1382
Dictionary 'outputs': This object defines the types of broadcast streams you want to
1396
1383
start (both HLS and RTMP). You can include HLS, RTMP, or both as broadcast streams.
1397
1384
If you include RTMP streaming, you can specify up to five target RTMP streams. For
@@ -1448,6 +1435,16 @@ def start_broadcast(
1448
1435
'HLS options "lowLatency" and "dvr" cannot both be set to "True".'
1449
1436
)
1450
1437
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
+
1451
1448
payload = {"sessionId" : session_id , "streamMode" : stream_mode .value }
1452
1449
1453
1450
payload .update (options )
@@ -1578,7 +1575,9 @@ def add_broadcast_stream(
1578
1575
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1579
1576
)
1580
1577
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
+ )
1582
1581
else :
1583
1582
raise RequestError ("An unexpected error occurred." , response .status_code )
1584
1583
@@ -1621,7 +1620,9 @@ def remove_broadcast_stream(
1621
1620
"Your broadcast is configured with a streamMode that does not support stream manipulation."
1622
1621
)
1623
1622
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
+ )
1625
1626
else :
1626
1627
raise RequestError ("OpenTok server error." , response .status_code )
1627
1628
0 commit comments