@@ -749,51 +749,82 @@ def list_archives(self, offset=None, count=None, session_id=None):
749
749
"""
750
750
return self .get_archives (offset , count , session_id )
751
751
752
-
753
- def update_archive (
752
+ def add_archive_stream (
754
753
self ,
755
754
archive_id : str ,
756
- add_stream : List [str ],
757
- remove_stream : List [str ],
755
+ stream_id : str ,
758
756
has_audio : bool = True ,
759
757
has_video : bool = True
760
758
) -> requests .Response :
759
+
761
760
"""
762
- New method to update the archive with addStream for new participant or
763
- removeStream to a new participant stream (choosing audio, video or both)
761
+ This method will add streams to the archive with addStream for new participant(choosing audio, video or both).
764
762
765
- :param String archive_id: The ID of the archive that will be updated
766
- :param List of Strings add_stream will add a participant stream (which audio and video) to the archive
767
- :param List of Strings remove_stream will remove a partcipant stream from the archive
763
+ :param String archive_id: the ID of the archive that will be updated
764
+ :param String stream_id: the id of the stream that will get added to the archive
768
765
:param Boolean has_audio: if set to True, an audio track will be inserted to the archive.
769
766
has_audio is an optional parameter that is set to True by default. If you set both
770
- has_audio and has_video to False, the call to the update_archive () method results in
767
+ has_audio and has_video to False, the call to the add_archive_stream () method results in
771
768
an error.
772
769
:param Boolean has_video: if set to True, a video track will be inserted to the archive.
773
770
has_video is an optional parameter that is set to True by default.
774
771
"""
775
- endpoint = self .endpoints .get_archive_stream ()
776
772
777
- stream_list = []
773
+ endpoint = self . endpoints . get_archive_stream ( archive_id )
778
774
779
- payload = {
775
+ streams = {
780
776
"hasAudio" : has_audio ,
781
777
"hasVideo" : has_video ,
778
+ "addStream" : stream_id
782
779
}
783
780
784
- if add_stream :
785
- payload ["addStream" ] = stream_list .append (add_stream )
786
- else :
787
- payload ["addStream" ] = None
788
-
789
- if remove_stream :
790
- payload ["removeStream" ] = stream_list .append (remove_stream )
791
- else :
792
- payload ["removeStream" ] = None
781
+ response = requests .patch (
782
+ endpoint ,
783
+ data = json .dumps (streams ),
784
+ headers = self .get_json_headers (),
785
+ proxies = self .proxies ,
786
+ timeout = self .timeout ,
787
+ )
788
+
789
+ if response :
790
+ return Archive (self , response .json ())
791
+ elif response .status_code == 403 :
792
+ raise AuthError ()
793
+ elif response .status_code == 400 :
794
+ """
795
+ The HTTP response has a 400 status code in the following cases:
796
+ You do not pass in a session ID or you pass in an invalid session ID.
797
+ No clients are actively connected to the OpenTok session.
798
+ You specify an invalid resolution value.
799
+ The outputMode property is set to "individual" and you set the resolution property and (which is not supported in individual stream archives).
800
+ """
801
+ raise RequestError (response .json ().get ("message" ))
802
+ elif response .status_code == 404 :
803
+ raise NotFoundError ("Archive or Stream not found" )
804
+ elif response .status_code == 405 :
805
+ raise ArchiveStreamModeError ("Your archive is configured with a streamMode that does not support stream manipulation." )
806
+ elif response .status_code == 409 :
807
+ raise ArchiveError (response .json ().get ("message" ))
808
+ else :
809
+ raise RequestError ("An unexpected error occurred" , response .status_code )
810
+
811
+ def remove_archive_stream (self , archive_id : str , stream_id : str ) -> requests .Response :
812
+ """
813
+ This method will remove streams from the archive with removeStream.
814
+
815
+ :param String archive_id: the ID of the archive that will be updated
816
+ :param String stream_id: the ID of the stream that will get added to the archive
817
+ """
818
+
819
+ endpoint = self .endpoints .get_archive_stream (archive_id )
820
+
821
+ streams = {
822
+ "removeStream" : stream_id
823
+ }
793
824
794
825
response = requests .patch (
795
826
endpoint ,
796
- data = json .dumps (payload ),
827
+ data = json .dumps (streams ),
797
828
headers = self .get_json_headers (),
798
829
proxies = self .proxies ,
799
830
timeout = self .timeout ,
@@ -822,6 +853,7 @@ def update_archive(
822
853
raise RequestError ("An unexpected error occurred" , response .status_code )
823
854
824
855
856
+
825
857
def send_signal (self , session_id , payload , connection_id = None ):
826
858
"""
827
859
Send signals to all participants in an active OpenTok session or to a specific client
@@ -1320,50 +1352,79 @@ def stop_broadcast(self, broadcast_id):
1320
1352
else :
1321
1353
raise RequestError ("OpenTok server error." , response .status_code )
1322
1354
1323
- def update_broadcast (
1355
+ def add_broadcast_stream (
1324
1356
self ,
1325
1357
broadcast_id : str ,
1326
- add_stream : List [str ],
1327
- remove_stream : List [str ],
1358
+ stream_id : str ,
1328
1359
has_audio : bool = True ,
1329
- has_video : bool = True ,
1360
+ has_video : bool = True
1330
1361
) -> requests .Response :
1362
+
1331
1363
"""
1332
- New method to update the archive with addStream for new participant or
1333
- removeStream to a new participant stream (choosing audio, video or both)
1364
+ This method will add streams to the broadcast with addStream for new participant(choosing audio, video or both).
1334
1365
1335
- :param String broadcast_id: The ID of the broadcast that will be updated
1336
- :param List of Strings add_stream will add a participant stream (which audio and video) to the broadcast
1337
- :param List of Strings remove_stream will remove a partcipant stream from the broadcast
1366
+ :param String broadcast_id: the ID of the broadcast that will be updated
1367
+ :param String stream_id: the id of the stream that will get added to the broadcast
1338
1368
:param Boolean has_audio: if set to True, an audio track will be inserted to the broadcast.
1339
1369
has_audio is an optional parameter that is set to True by default. If you set both
1340
- has_audio and has_video to False, the call to the update_broadcast () method results in
1370
+ has_audio and has_video to False, the call to the add_broadcast_stream () method results in
1341
1371
an error.
1342
1372
:param Boolean has_video: if set to True, a video track will be inserted to the broadcast.
1343
1373
has_video is an optional parameter that is set to True by default.
1344
1374
"""
1345
- endpoint = self .endpoints .get_broadcast_stream ()
1346
1375
1347
- stream_list = []
1376
+ endpoint = self . endpoints . get_broadcast_stream ( broadcast_id )
1348
1377
1349
- payload = {
1378
+ streams = {
1350
1379
"hasAudio" : has_audio ,
1351
1380
"hasVideo" : has_video ,
1381
+ "addStream" : stream_id
1352
1382
}
1353
1383
1354
- if add_stream :
1355
- payload ["addStream" ] = stream_list .append (add_stream )
1356
- else :
1357
- payload ["addStream" ] = None
1358
-
1359
- if remove_stream :
1360
- payload ["removeStream" ] = stream_list .append (remove_stream )
1361
- else :
1362
- payload ["removeStream" ] = None
1384
+ response = requests .patch (
1385
+ endpoint ,
1386
+ data = json .dumps (streams ),
1387
+ headers = self .get_json_headers (),
1388
+ proxies = self .proxies ,
1389
+ timeout = self .timeout ,
1390
+ )
1391
+
1392
+ if response :
1393
+ return Broadcast (response .json ())
1394
+ elif response .status_code == 400 :
1395
+ raise BroadcastError (
1396
+ "Invalid request. This response may indicate that data in your request data is "
1397
+ "invalid JSON. It may also indicate that you passed in invalid layout options. "
1398
+ "Or you have exceeded the limit of five simultaneous RTMP streams for an OpenTok "
1399
+ "session. Or you specified and invalid resolution."
1400
+ )
1401
+ elif response .status_code == 403 :
1402
+ raise AuthError ("Authentication error." )
1403
+ elif response .status_code == 405 :
1404
+ raise BroadcastStreamModeError ("Your broadcast is configured with a streamMode that does not support stream manipulation." )
1405
+ elif response .status_code == 409 :
1406
+ raise BroadcastError ("The broadcast has already started for the session." )
1407
+ else :
1408
+ raise RequestError ("OpenTok server error." , response .status_code )
1409
+
1410
+
1411
+ def remove_broadcast_stream (self , broadcast_id : str , stream_id : str ) -> requests .Response :
1412
+ """
1413
+ This method will remove streams from the broadcast with removeStream.
1414
+
1415
+ :param String broadcast_id: the ID of the broadcast that will be updated
1416
+ :param String stream_id: the id of the stream that will get added to the broadcast
1417
+ """
1418
+
1419
+ endpoint = self .endpoints .get_broadcast_stream (broadcast_id )
1420
+
1421
+ streams = {
1422
+ "removeStream" : stream_id
1423
+ }
1363
1424
1364
1425
response = requests .patch (
1365
1426
endpoint ,
1366
- data = json .dumps (payload ),
1427
+ data = json .dumps (streams ),
1367
1428
headers = self .get_json_headers (),
1368
1429
proxies = self .proxies ,
1369
1430
timeout = self .timeout ,
0 commit comments