Skip to content

Commit dd0ffb8

Browse files
authored
Merge pull request #237 from opentok/add-publisher-only-role
add publisher_only role for token generation
2 parents 9dea938 + a0a8632 commit dd0ffb8

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

.bumpversion.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.8.1
2+
current_version = 3.9.0
33
commit = True
44
tag = False
55

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Release v3.9.0
2+
- Add `publisher_only` role that can be specified when generating a token.
3+
14
# Release v3.8.1
25
- Fixed an issue with the `opentok.create_session` method
36

opentok/opentok.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class Roles(Enum):
6464
"""A subscriber can only subscribe to streams."""
6565
publisher = u("publisher")
6666
"""A publisher can publish streams, subscribe to streams, and signal"""
67+
publisher_only = "publisheronly"
68+
"""A client with the `publisher_only` role can only publish streams. It cannot subscribe to
69+
other clients' streams or send signals."""
6770
moderator = u("moderator")
6871
"""In addition to the privileges granted to a publisher, a moderator can perform
6972
moderation functions, such as forcing clients to disconnect, to stop publishing streams,
@@ -106,7 +109,6 @@ class ArchiveModes(Enum):
106109

107110

108111
class Client(object):
109-
110112
"""Use this SDK to create tokens and interface with the server-side portion
111113
of the Opentok API.
112114
"""
@@ -187,6 +189,9 @@ def generate_token(
187189
* `Roles.publisher` -- A publisher can publish streams, subscribe to
188190
streams, and signal. (This is the default value if you do not specify a role.)
189191
192+
* `Roles.publisher_only` -- A client with the `publisher_only` role can only publish streams.
193+
It cannot subscribe to other clients' streams or send signals.
194+
190195
* `Roles.moderator` -- In addition to the privileges granted to a
191196
publisher, in clients using the OpenTok.js 2.2 library, a moderator can call the
192197
`forceUnpublish()` and `forceDisconnect()` method of the
@@ -499,9 +504,7 @@ def create_session(
499504
)
500505
)
501506

502-
session_id = (
503-
dom.getElementsByTagName("session_id")[0].childNodes[0].nodeValue
504-
)
507+
session_id = dom.getElementsByTagName("session_id")[0].childNodes[0].nodeValue
505508
return Session(
506509
self,
507510
session_id,
@@ -890,9 +893,7 @@ def add_archive_stream(
890893
else:
891894
raise RequestError("An unexpected error occurred.", response.status_code)
892895

893-
def remove_archive_stream(
894-
self, archive_id: str, stream_id: str
895-
) -> requests.Response:
896+
def remove_archive_stream(self, archive_id: str, stream_id: str) -> requests.Response:
896897
"""
897898
This method will remove streams from the archive with removeStream.
898899
@@ -1339,9 +1340,7 @@ class names (Strings) to apply to the stream. For example:
13391340
else:
13401341
raise RequestError("OpenTok server error.", response.status_code)
13411342

1342-
def start_broadcast(
1343-
self, session_id, options, stream_mode=BroadcastStreamModes.auto
1344-
):
1343+
def start_broadcast(self, session_id, options, stream_mode=BroadcastStreamModes.auto):
13451344
"""
13461345
Use this method to start a live streaming broadcast for an OpenTok session. This broadcasts
13471346
the session to an HLS (HTTP live streaming) or to RTMP streams. To successfully start
@@ -1576,9 +1575,7 @@ def add_broadcast_stream(
15761575
"Your broadcast is configured with a streamMode that does not support stream manipulation."
15771576
)
15781577
elif response.status_code == 409:
1579-
raise BroadcastError(
1580-
"The broadcast has already started for the session."
1581-
)
1578+
raise BroadcastError("The broadcast has already started for the session.")
15821579
else:
15831580
raise RequestError("An unexpected error occurred.", response.status_code)
15841581

@@ -1621,9 +1618,7 @@ def remove_broadcast_stream(
16211618
"Your broadcast is configured with a streamMode that does not support stream manipulation."
16221619
)
16231620
elif response.status_code == 409:
1624-
raise BroadcastError(
1625-
"The broadcast has already started for the session."
1626-
)
1621+
raise BroadcastError("The broadcast has already started for the session.")
16271622
else:
16281623
raise RequestError("OpenTok server error.", response.status_code)
16291624

opentok/version.py

+1-1
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.8.1"
2+
__version__ = "3.9.0"
33

tests/test_token_generation.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ def test_generate_role_token(self):
3131
assert isinstance(token, text_type)
3232
assert token_decoder(token)[u("role")] == Roles.moderator.value
3333
assert token_signature_validator(token, self.api_secret)
34+
3435
token = self.opentok.generate_token(self.session_id, role=Roles.moderator)
3536
assert isinstance(token, text_type)
3637
assert token_decoder(token)[u("role")] == Roles.moderator.value
3738
assert token_signature_validator(token, self.api_secret)
3839

40+
token = self.opentok.generate_token(self.session_id, Roles.publisher_only)
41+
assert token_decoder(token)["role"] == Roles.publisher_only.value
42+
assert token_signature_validator(token, self.api_secret)
43+
3944
def test_generate_expires_token(self):
4045
# an integer is a valid argument
4146
expire_time = int(time.time()) + 100
@@ -91,22 +96,20 @@ def test_generate_no_data_token(self):
9196

9297
@raises(TypeError)
9398
def test_does_not_generate_token_without_params(self):
94-
token = self.opentok.generate_token()
99+
self.opentok.generate_token()
95100

96101
@raises(TypeError)
97102
def test_does_not_generate_token_without_session(self):
98-
token = self.opentok.generate_token(role=Roles.subscriber)
103+
self.opentok.generate_token(role=Roles.subscriber)
99104

100105
@raises(OpenTokException)
101106
def test_does_not_generate_token_invalid_session(self):
102-
token = self.opentok.generate_token(u("NOT A REAL SESSIONID"))
107+
self.opentok.generate_token(u("NOT A REAL SESSIONID"))
103108

104109
@raises(OpenTokException)
105110
def test_does_not_generate_token_without_api_key_match(self):
106111
# this session_id has the wrong api_key
107112
session_id = u(
108113
"1_MX42NTQzMjF-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4"
109114
)
110-
token = self.opentok.generate_token(session_id)
111-
112-
# TODO: all the things that raise OpenTokException
115+
self.opentok.generate_token(session_id)

0 commit comments

Comments
 (0)