Skip to content

Commit cd74161

Browse files
authored
Merge branch 'main' into dev
2 parents 61ac866 + f4cb1fe commit cd74161

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# Release v3.4.0
1+
# Release v3.5.0
2+
- Support for end-to-end encryption (E2EE) that can be specified by a user when creating an OpenTok session.
23

4+
# Release v3.4.0
35
- Support for Audio Connector API via `connect_audio_to_websocket` method
46

57
# Release v3.3.0

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Import the package at the top of any file where you will use it. At the very lea
4848
Creating Sessions
4949
~~~~~~~~~~~~~~~~~
5050

51-
To create an OpenTok Session, use the ``opentok.create_session()`` method. There are three optional
51+
To create an OpenTok Session, use the ``opentok.create_session()`` method. There are optional
5252
keyword parameters for this method:
5353

5454
* ``location`` which can be set to a string containing an IP address.
@@ -62,6 +62,10 @@ keyword parameters for this method:
6262
* ``archive_mode`` which specifies whether the session will be automatically archived (``always``)
6363
or not (``manual``).
6464

65+
* ``e2ee`` which is a boolean. This specifies whether to enable
66+
`end-to-end encryption <https://tokbox.com/developer/guides/end-to-end-encryption/>`_
67+
for the OpenTok session.
68+
6569
This method returns a ``Session`` object. Its ``session_id`` attribute is useful when saving to a persistent
6670
store (such as a database).
6771

opentok/opentok.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def create_session(
315315
location=None,
316316
media_mode=MediaModes.relayed,
317317
archive_mode=ArchiveModes.manual,
318+
e2ee=False,
318319
):
319320
"""
320321
Creates a new OpenTok session and returns the session ID, which uniquely identifies
@@ -373,6 +374,9 @@ def create_session(
373374
situate the session in its global network. If you do not set a location hint,
374375
the OpenTok servers will be based on the first client connecting to the session.
375376
377+
:param Boolean e2ee: Whether to enable end-to-end encryption for a routed session
378+
(see https://tokbox.com/developer/guides/end-to-end-encryption/).
379+
376380
:rtype: The Session object. The session_id property of the object is the session ID.
377381
"""
378382

@@ -409,6 +413,7 @@ def create_session(
409413
).format(location)
410414
)
411415
options[u("location")] = location
416+
options["e2ee"] = e2ee
412417

413418
try:
414419
logger.debug(
@@ -450,13 +455,14 @@ def create_session(
450455

451456
session_id = (
452457
dom.getElementsByTagName("session_id")[0].childNodes[0].nodeValue
453-
)
458+
)
454459
return Session(
455460
self,
456461
session_id,
457462
location=location,
458463
media_mode=media_mode,
459464
archive_mode=archive_mode,
465+
e2ee=e2ee,
460466
)
461467
except Exception as e:
462468
raise OpenTokException("Failed to generate session: %s" % str(e))

opentok/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# see: http://legacy.python.org/dev/peps/pep-0440/#public-version-identifiers
2-
__version__ = "3.4.0"
2+
__version__ = "3.5.0"
33

tests/test_session_creation.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def test_create_default_session(self):
5555
)
5656
expect(session).to(have_property(u("media_mode"), MediaModes.relayed))
5757
expect(session).to(have_property(u("location"), None))
58+
expect(session).to(have_property(u("e2ee"), False))
5859

5960
@httpretty.activate
6061
def test_create_routed_session(self):
@@ -88,6 +89,7 @@ def test_create_routed_session(self):
8889
)
8990
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
9091
expect(session).to(have_property(u("location"), None))
92+
expect(session).to(have_property(u("e2ee"), False))
9193

9294
@httpretty.activate
9395
def test_failure_create_routed_session(self):
@@ -139,6 +141,7 @@ def test_create_session_with_location_hint(self):
139141
)
140142
expect(session).to(have_property(u("media_mode"), MediaModes.relayed))
141143
expect(session).to(have_property(u("location"), u("12.34.56.78")))
144+
expect(session).to(have_property(u("e2ee"), False))
142145

143146
@httpretty.activate
144147
def test_create_routed_session_with_location_hint(self):
@@ -175,6 +178,7 @@ def test_create_routed_session_with_location_hint(self):
175178
)
176179
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
177180
expect(session).to(have_property(u("location"), u("12.34.56.78")))
181+
expect(session).to(have_property(u("e2ee"), False))
178182

179183
@httpretty.activate
180184
def test_create_manual_archive_mode_session(self):
@@ -210,6 +214,7 @@ def test_create_manual_archive_mode_session(self):
210214
)
211215
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
212216
expect(session).to(have_property(u("archive_mode"), ArchiveModes.manual))
217+
expect(session).to(have_property(u("e2ee"), False))
213218

214219
@httpretty.activate
215220
def test_create_always_archive_mode_session(self):
@@ -245,6 +250,7 @@ def test_create_always_archive_mode_session(self):
245250
)
246251
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
247252
expect(session).to(have_property(u("archive_mode"), ArchiveModes.always))
253+
expect(session).to(have_property(u("e2ee"), False))
248254

249255
@httpretty.activate
250256
def test_complains_about_always_archive_mode_and_relayed_session(self):
@@ -264,5 +270,32 @@ def test_complains_about_always_archive_mode_and_relayed_session(self):
264270
archive_mode=ArchiveModes.always,
265271
)
266272

273+
@httpretty.activate
274+
def test_create_session_with_e2ee(self):
275+
httpretty.register_uri(
276+
httpretty.POST,
277+
u("https://api.opentok.com/session/create"),
278+
body=u(
279+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'
280+
),
281+
status=200,
282+
content_type=u("text/xml"),
283+
)
284+
285+
session = self.opentok.create_session(e2ee=True)
286+
287+
body = parse_qs(httpretty.last_request().body)
288+
expect(body).to(have_key(b("e2ee"), [b'True']))
289+
expect(session).to(be_a(Session))
290+
expect(session).to(
291+
have_property(
292+
u("session_id"),
293+
u(
294+
"1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg"
295+
),
296+
)
297+
)
298+
expect(session).to(have_property(u("e2ee"), True))
299+
267300
# TODO: all the cases that throw exceptions
268301
# TODO: custom api_url requests

0 commit comments

Comments
 (0)