@@ -91,12 +91,12 @@ class ArchiveModes(Enum):
91
91
92
92
93
93
valid_archive_resolutions = {
94
- ' 640x480' ,
95
- ' 480x640' ,
96
- ' 1280x720' ,
97
- ' 720x1280' ,
98
- ' 1920x1080' ,
99
- ' 1080x1920' ,
94
+ " 640x480" ,
95
+ " 480x640" ,
96
+ " 1280x720" ,
97
+ " 720x1280" ,
98
+ " 1920x1080" ,
99
+ " 1080x1920" ,
100
100
}
101
101
102
102
logger = logging .getLogger ("opentok" )
@@ -125,6 +125,9 @@ def __init__(
125
125
self ._proxies = None
126
126
self .endpoints = Endpoints (api_url , self .api_key )
127
127
self ._app_version = __version__ if app_version == None else app_version
128
+ self ._user_agent = (
129
+ f"OpenTok-Python-SDK/{ self .app_version } python/{ platform .python_version ()} "
130
+ )
128
131
# JWT custom claims - Default values
129
132
self ._jwt_livetime = 3 # In minutes
130
133
@@ -144,6 +147,13 @@ def app_version(self):
144
147
def app_version (self , value ):
145
148
self ._app_version = value
146
149
150
+ @property
151
+ def user_agent (self ):
152
+ return self ._user_agent
153
+
154
+ def append_to_user_agent (self , value ):
155
+ self ._user_agent = self ._user_agent + value
156
+
147
157
@property
148
158
def jwt_livetime (self ):
149
159
return self ._jwt_livetime
@@ -408,7 +418,7 @@ def create_session(
408
418
"A session with always archive mode must also have the routed media mode."
409
419
)
410
420
)
411
-
421
+
412
422
if archive_name is not None :
413
423
if archive_mode == ArchiveModes .manual :
414
424
raise OpenTokException (
@@ -418,7 +428,7 @@ def create_session(
418
428
raise OpenTokException (
419
429
"archive_name must be between 1 and 80 characters in length."
420
430
)
421
-
431
+
422
432
if archive_resolution is not None :
423
433
if archive_mode == ArchiveModes .manual :
424
434
raise OpenTokException (
@@ -631,13 +641,13 @@ def start_archive(
631
641
}
632
642
633
643
if layout is not None :
634
- payload [' layout' ] = layout
644
+ payload [" layout" ] = layout
635
645
636
646
logger .debug (
637
647
"POST to %r with params %r, headers %r, proxies %r" ,
638
648
self .endpoints .archive_url (),
639
649
json .dumps (payload ),
640
- self .json_headers (),
650
+ self .get_json_headers (),
641
651
self .proxies ,
642
652
)
643
653
@@ -683,7 +693,7 @@ def stop_archive(self, archive_id):
683
693
logger .debug (
684
694
"POST to %r with headers %r, proxies %r" ,
685
695
self .endpoints .archive_url (archive_id ) + "/stop" ,
686
- self .json_headers (),
696
+ self .get_json_headers (),
687
697
self .proxies ,
688
698
)
689
699
@@ -718,7 +728,7 @@ def delete_archive(self, archive_id):
718
728
logger .debug (
719
729
"DELETE to %r with headers %r, proxies %r" ,
720
730
self .endpoints .archive_url (archive_id ),
721
- self .json_headers (),
731
+ self .get_json_headers (),
722
732
self .proxies ,
723
733
)
724
734
@@ -748,7 +758,7 @@ def get_archive(self, archive_id):
748
758
logger .debug (
749
759
"GET to %r with headers %r, proxies %r" ,
750
760
self .endpoints .archive_url (archive_id ),
751
- self .json_headers (),
761
+ self .get_json_headers (),
752
762
self .proxies ,
753
763
)
754
764
@@ -794,7 +804,7 @@ def get_archives(self, offset=None, count=None, session_id=None):
794
804
logger .debug (
795
805
"GET to %r with headers %r, proxies %r" ,
796
806
endpoint ,
797
- self .json_headers (),
807
+ self .get_json_headers (),
798
808
self .proxies ,
799
809
)
800
810
@@ -942,7 +952,7 @@ def send_signal(self, session_id, payload, connection_id=None):
942
952
"POST to %r with params %r, headers %r, proxies %r" ,
943
953
self .endpoints .signaling_url (session_id , connection_id ),
944
954
json .dumps (payload ),
945
- self .json_headers (),
955
+ self .get_json_headers (),
946
956
self .proxies ,
947
957
)
948
958
@@ -997,7 +1007,7 @@ def get_stream(self, session_id, stream_id):
997
1007
logger .debug (
998
1008
"GET to %r with headers %r, proxies %r" ,
999
1009
endpoint ,
1000
- self .json_headers (),
1010
+ self .get_json_headers (),
1001
1011
self .proxies ,
1002
1012
)
1003
1013
@@ -1034,7 +1044,7 @@ def list_streams(self, session_id):
1034
1044
logger .debug (
1035
1045
"GET to %r with headers %r, proxies %r" ,
1036
1046
endpoint ,
1037
- self .json_headers (),
1047
+ self .get_json_headers (),
1038
1048
self .proxies ,
1039
1049
)
1040
1050
@@ -1072,7 +1082,7 @@ def force_disconnect(self, session_id, connection_id):
1072
1082
logger .debug (
1073
1083
"DELETE to %r with headers %r, proxies %r" ,
1074
1084
endpoint ,
1075
- self .json_headers (),
1085
+ self .get_json_headers (),
1076
1086
self .proxies ,
1077
1087
)
1078
1088
@@ -1134,7 +1144,7 @@ def set_archive_layout(
1134
1144
"PUT to %r with params %r, headers %r, proxies %r" ,
1135
1145
endpoint ,
1136
1146
json .dumps (payload ),
1137
- self .json_headers (),
1147
+ self .get_json_headers (),
1138
1148
self .proxies ,
1139
1149
)
1140
1150
@@ -1263,7 +1273,7 @@ def dial(self, session_id, token, sip_uri, options=[]):
1263
1273
"POST to %r with params %r, headers %r, proxies %r" ,
1264
1274
endpoint ,
1265
1275
json .dumps (payload ),
1266
- self .json_headers (),
1276
+ self .get_json_headers (),
1267
1277
self .proxies ,
1268
1278
)
1269
1279
@@ -1317,7 +1327,7 @@ class names (Strings) to apply to the stream. For example:
1317
1327
"PUT to %r with params %r, headers %r, proxies %r" ,
1318
1328
endpoint ,
1319
1329
json .dumps (items_payload ),
1320
- self .json_headers (),
1330
+ self .get_json_headers (),
1321
1331
self .proxies ,
1322
1332
)
1323
1333
@@ -1354,6 +1364,10 @@ def start_broadcast(
1354
1364
1355
1365
:param String session_id: The session ID of the OpenTok session you want to broadcast
1356
1366
1367
+ :param Boolean optional hasAudio: Whether the stream is broadcast with audio.
1368
+
1369
+ :param Boolean optional hasVideo: Whether the stream is broadcast with video.
1370
+
1357
1371
:param Dictionary options, with the following properties:
1358
1372
1359
1373
Dictionary 'layout' optional: Specify this to assign the initial layout type for the
@@ -1414,18 +1428,18 @@ def start_broadcast(
1414
1428
BroadcastStreamModes.manual to explicitly select streams to include in the the broadcast, using the
1415
1429
OpenTok.add_broadcast_stream() and OpenTok.remove_broadcast_stream() methods.
1416
1430
1417
- :rtype A Broadcast object, which contains information of the broadcast: id, sessionId
1431
+ :rtype A Broadcast object, which contains information of the broadcast: id, sessionId,
1418
1432
projectId, createdAt, updatedAt, resolution, status and broadcastUrls
1419
1433
"""
1420
1434
1421
- if ' hls' in options [' outputs' ]:
1435
+ if " hls" in options [" outputs" ]:
1422
1436
if (
1423
- ' lowLatency' in options [' outputs' ][ ' hls' ]
1424
- and ' dvr' in options [' outputs' ][ ' hls' ]
1437
+ " lowLatency" in options [" outputs" ][ " hls" ]
1438
+ and " dvr" in options [" outputs" ][ " hls" ]
1425
1439
):
1426
1440
if (
1427
- options [' outputs' ][ ' hls' ][ ' lowLatency' ] == True
1428
- and options [' outputs' ][ ' hls' ][ ' dvr' ] == True
1441
+ options [" outputs" ][ " hls" ][ " lowLatency" ] == True
1442
+ and options [" outputs" ][ " hls" ][ " dvr" ] == True
1429
1443
):
1430
1444
raise BroadcastHLSOptionsError (
1431
1445
'HLS options "lowLatency" and "dvr" cannot both be set to "True".'
@@ -1441,7 +1455,7 @@ def start_broadcast(
1441
1455
"POST to %r with params %r, headers %r, proxies %r" ,
1442
1456
endpoint ,
1443
1457
json .dumps (payload ),
1444
- self .json_headers (),
1458
+ self .get_json_headers (),
1445
1459
self .proxies ,
1446
1460
)
1447
1461
@@ -1484,7 +1498,7 @@ def stop_broadcast(self, broadcast_id):
1484
1498
logger .debug (
1485
1499
"POST to %r with headers %r, proxies %r" ,
1486
1500
endpoint ,
1487
- self .json_headers (),
1501
+ self .get_json_headers (),
1488
1502
self .proxies ,
1489
1503
)
1490
1504
@@ -1621,7 +1635,7 @@ def get_broadcast(self, broadcast_id):
1621
1635
logger .debug (
1622
1636
"GET to %r with headers %r, proxies %r" ,
1623
1637
endpoint ,
1624
- self .json_headers (),
1638
+ self .get_json_headers (),
1625
1639
self .proxies ,
1626
1640
)
1627
1641
@@ -1680,7 +1694,7 @@ def set_broadcast_layout(
1680
1694
"PUT to %r with params %r, headers %r, proxies %r" ,
1681
1695
endpoint ,
1682
1696
json .dumps (payload ),
1683
- self .json_headers (),
1697
+ self .get_json_headers (),
1684
1698
self .proxies ,
1685
1699
)
1686
1700
@@ -1929,10 +1943,10 @@ def connect_audio_to_websocket(
1929
1943
def validate_websocket_options (self , options ):
1930
1944
if type (options ) is not dict :
1931
1945
raise InvalidWebSocketOptionsError (
1932
- ' Must pass WebSocket options as a dictionary.'
1946
+ " Must pass WebSocket options as a dictionary."
1933
1947
)
1934
- if ' uri' not in options :
1935
- raise InvalidWebSocketOptionsError (' Provide a WebSocket URI.' )
1948
+ if " uri" not in options :
1949
+ raise InvalidWebSocketOptionsError (" Provide a WebSocket URI." )
1936
1950
1937
1951
def _sign_string (self , string , secret ):
1938
1952
return hmac .new (
@@ -1974,9 +1988,9 @@ def mute_all(
1974
1988
1975
1989
try :
1976
1990
if excludedStreamIds :
1977
- options = {' active' : True , ' excludedStreams' : excludedStreamIds }
1991
+ options = {" active" : True , " excludedStreams" : excludedStreamIds }
1978
1992
else :
1979
- options = {' active' : True , ' excludedStreams' : []}
1993
+ options = {" active" : True , " excludedStreams" : []}
1980
1994
1981
1995
response = requests .post (
1982
1996
url , headers = self .get_headers (), data = json .dumps (options )
@@ -2012,7 +2026,7 @@ def disable_force_mute(self, session_id: str) -> requests.Response:
2012
2026
:param session_id The session ID.
2013
2027
"""
2014
2028
2015
- options = {' active' : False }
2029
+ options = {" active" : False }
2016
2030
url = self .endpoints .get_mute_all_url (session_id )
2017
2031
2018
2032
response = requests .post (
@@ -2162,9 +2176,9 @@ def mute_all(
2162
2176
2163
2177
try :
2164
2178
if excludedStreamIds :
2165
- options = {' active' : True , ' excludedStreams' : excludedStreamIds }
2179
+ options = {" active" : True , " excludedStreams" : excludedStreamIds }
2166
2180
else :
2167
- options = {' active' : True , ' excludedStreams' : []}
2181
+ options = {" active" : True , " excludedStreams" : []}
2168
2182
2169
2183
response = requests .post (
2170
2184
url , headers = self .get_headers (), data = json .dumps (options )
@@ -2198,7 +2212,7 @@ def disable_force_mute(self, session_id: str) -> requests.Response:
2198
2212
:param session_id The session ID.
2199
2213
"""
2200
2214
2201
- options = {' active' : False }
2215
+ options = {" active" : False }
2202
2216
url = self .endpoints .get_mute_all_url (session_id )
2203
2217
2204
2218
response = requests .post (
0 commit comments